Search is not available for this dataset
text
string
meta
dict
-- Andreas, 2016-02-01, reported on 2014-12-08 module Issue1388 where indented = Set not-indented = Set -- This should be a parse error.
{ "alphanum_fraction": 0.7062937063, "avg_line_length": 17.875, "ext": "agda", "hexsha": "8a0735798a938ffe693ed2095081571624820ecb", "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/Issue1388.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/Issue1388.agda", "max_line_length": 52, "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/Issue1388.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": 47, "size": 143 }
module Languages.ILL.AgdaInterface where open import nat open import Utils.HaskellTypes open import Utils.HaskellFunctions open import Utils.Exception open import Languages.ILL.Intermediate open import Languages.ILL.Syntax open import Languages.ILL.TypeSyntax open import Languages.ILL.TypeCheck {-# TERMINATING #-} translate : ITerm → Either Exception Term translate Triv = right Triv translate (Var x) = right (FVar x) translate (TTensor t₁ t₂) = (translate t₁) >>=E (λ e₁ → (translate t₂) >>=E (λ e₂ → right (Tensor e₁ e₂))) translate (Lam x a t) = (translate t) >>=E (λ e → right (Lam x a (close-t 0 x BV x e))) translate (Let t₁ a PTriv t₂) = (translate t₁) >>=E (λ e₁ → (translate t₂) >>=E (λ e₂ → right (Let e₁ a PTriv e₂))) translate (Let t₁ a (PTensor (PVar x) (PVar y)) t₂) = (translate t₁) >>=E (λ e₁ → (translate t₂) >>=E (λ e₂ → right (Let e₁ a (PTensor x y) (close-t 0 x LLPV x (close-t 0 y RLPV y e₂))))) translate (Let _ _ _ _) = error IllformedLetPattern translate (App t₁ t₂) = (translate t₁) >>=E (λ e₁ → (translate t₂) >>=E (λ e₂ → right (App e₁ e₂))) translate (Promote ts t) = tts >>=E (λ ttts → (translate t) >>=E (λ tt → right (Promote ttts (foldr aux tt ts)) )) where tts = commExpList (map (λ x → commExpTriple (fstMapT translate x)) ts) aux = (λ (x : Triple ITerm String Type) (v : Term) → close-t 0 (sndT x) PBV (sndT x) v) translate (Copy t₁ x y t₂) = (translate t₁) >>=E (λ tt₁ → (translate t₂) >>=E (λ tt₂ → right (Copy tt₁ (x , y) (close-t 0 x LCPV x (close-t 0 y RCPV y tt₂))))) translate (Discard t₁ t₂) = (translate t₁) >>=E (λ tt₁ → translate t₂ >>=E (λ tt₂ → right (Discard tt₁ tt₂))) translate (Derelict t) = (translate t) >>=E (λ tt → right (Derelict tt)) {-# TERMINATING #-} untranslate : Term → ITerm untranslate Triv = Triv untranslate (FVar x) = Var x untranslate (BVar _ x _) = Var x untranslate (Let t₁ a PTriv t₂) = Let (untranslate t₁) a PTriv (untranslate t₂) untranslate (Let t₁ a (PTensor xs ys) t₂) = Let (untranslate t₁) a (PTensor (PVar xs) (PVar ys)) (untranslate t₂) untranslate (Lam x a t) = Lam x a (untranslate t) untranslate (App t₁ t₂) = App (untranslate t₁) (untranslate t₂) untranslate (Tensor t₁ t₂) = TTensor (untranslate t₁) (untranslate t₂) untranslate (Promote ts t) = Promote uts (untranslate t) where uts = map (fstMapT untranslate) ts untranslate (Copy t₁ p t₂) = Copy (untranslate t₁) (fst p) (snd p) (untranslate t₂) untranslate (Discard t₁ t₂) = Discard (untranslate t₁) (untranslate t₂) untranslate (Derelict t) = Derelict (untranslate t) runTypeCheck : ITerm → Either Exception Type runTypeCheck it = (translate it) >>=E (λ t → typeCheck t) {-# COMPILED_EXPORT runTypeCheck runTypeCheck #-}
{ "alphanum_fraction": 0.6599496222, "avg_line_length": 37.0533333333, "ext": "agda", "hexsha": "2887a814bf73613b50293843d58c8e598510a61f", "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": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "heades/Agda-LLS", "max_forks_repo_path": "Source/ALL/Languages/ILL/AgdaInterface.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z", "max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "heades/Agda-LLS", "max_issues_repo_path": "Source/ALL/Languages/ILL/AgdaInterface.agda", "max_line_length": 113, "max_stars_count": 3, "max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "heades/Agda-LLS", "max_stars_repo_path": "Source/ALL/Languages/ILL/AgdaInterface.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z", "num_tokens": 961, "size": 2779 }
open import Nat open import Prelude open import dynamics-core open import contexts open import binders-disjoint-checks open import exchange open import lemmas-consistency open import lemmas-disjointness open import lemmas-subst-ta open import type-assignment-unicity open import weakening module preservation where -- if d and d' both result from filling the hole in ε with terms of the -- same type, they too have the same type. wt-different-fill : ∀{Δ Γ d ε d1 d2 d' τ τ1} → d == ε ⟦ d1 ⟧ → Δ , Γ ⊢ d :: τ → Δ , Γ ⊢ d1 :: τ1 → Δ , Γ ⊢ d2 :: τ1 → d' == ε ⟦ d2 ⟧ → Δ , Γ ⊢ d' :: τ wt-different-fill FHOuter D1 D2 D3 FHOuter with type-assignment-unicity D1 D2 ... | refl = D3 wt-different-fill (FHPlus1 eps1) (TAPlus D1 D2) D3 D4 (FHPlus1 eps2) = TAPlus (wt-different-fill eps1 D1 D3 D4 eps2) D2 wt-different-fill (FHPlus2 eps1) (TAPlus D1 D2) D3 D4 (FHPlus2 eps2) = TAPlus D1 (wt-different-fill eps1 D2 D3 D4 eps2) wt-different-fill (FHAp1 eps) (TAAp D1 D2) D3 D4 (FHAp1 D5) = TAAp (wt-different-fill eps D1 D3 D4 D5) D2 wt-different-fill (FHAp2 eps) (TAAp D1 D2) D3 D4 (FHAp2 D5) = TAAp D1 (wt-different-fill eps D2 D3 D4 D5) wt-different-fill (FHInl eps1) (TAInl D) D1 D2 (FHInl eps2) = TAInl (wt-different-fill eps1 D D1 D2 eps2) wt-different-fill (FHInr eps1) (TAInr D) D1 D2 (FHInr eps2) = TAInr (wt-different-fill eps1 D D1 D2 eps2) wt-different-fill (FHCase eps1) (TACase D x D₁ x₁ D₂) D1 D2 (FHCase eps2) = TACase (wt-different-fill eps1 D D1 D2 eps2) x D₁ x₁ D₂ wt-different-fill (FHPair1 eps1) (TAPair D D₁) D1 D2 (FHPair1 eps2) = TAPair (wt-different-fill eps1 D D1 D2 eps2) D₁ wt-different-fill (FHPair2 eps1) (TAPair D D₁) D1 D2 (FHPair2 eps2) = TAPair D (wt-different-fill eps1 D₁ D1 D2 eps2) wt-different-fill (FHFst eps1) (TAFst D) D1 D2 (FHFst eps2) = TAFst (wt-different-fill eps1 D D1 D2 eps2) wt-different-fill (FHSnd eps1) (TASnd D) D1 D2 (FHSnd eps2) = TASnd (wt-different-fill eps1 D D1 D2 eps2) wt-different-fill (FHNEHole eps) (TANEHole x D1 x₁) D2 D3 (FHNEHole D4) = TANEHole x (wt-different-fill eps D1 D2 D3 D4) x₁ wt-different-fill (FHCast eps) (TACast D1 x) D2 D3 (FHCast D4) = TACast (wt-different-fill eps D1 D2 D3 D4) x wt-different-fill (FHFailedCast x) (TAFailedCast y x₁ x₂ x₃) D3 D4 (FHFailedCast eps) = TAFailedCast (wt-different-fill x y D3 D4 eps) x₁ x₂ x₃ -- if a well typed term results from filling the hole in ε, then the term -- that filled the hole is also well typed wt-filling : ∀{ε Δ Γ d τ d'} → Δ , Γ ⊢ d :: τ → d == ε ⟦ d' ⟧ → Σ[ τ' ∈ htyp ] (Δ , Γ ⊢ d' :: τ') wt-filling TANum FHOuter = _ , TANum wt-filling (TAPlus ta ta₁) FHOuter = num , TAPlus ta ta₁ wt-filling (TAPlus ta ta₁) (FHPlus1 eps) = wt-filling ta eps wt-filling (TAPlus ta ta₁) (FHPlus2 eps) = wt-filling ta₁ eps wt-filling (TAVar x₁) FHOuter = _ , TAVar x₁ wt-filling (TALam f ta) FHOuter = _ , TALam f ta wt-filling (TAAp ta ta₁) FHOuter = _ , TAAp ta ta₁ wt-filling (TAAp ta ta₁) (FHAp1 eps) = wt-filling ta eps wt-filling (TAAp ta ta₁) (FHAp2 eps) = wt-filling ta₁ eps wt-filling (TAInl ta) FHOuter = _ , TAInl ta wt-filling (TAInl ta) (FHInl eps) = wt-filling ta eps wt-filling (TAInr ta) FHOuter = _ , TAInr ta wt-filling (TAInr ta) (FHInr eps) = wt-filling ta eps wt-filling (TACase ta x ta₁ x₁ ta₂) FHOuter = _ , TACase ta x ta₁ x₁ ta₂ wt-filling (TACase ta x ta₁ x₁ ta₂) (FHCase eps) = wt-filling ta eps wt-filling (TAPair ta ta₁) FHOuter = _ , TAPair ta ta₁ wt-filling (TAPair ta ta₁) (FHPair1 eps) = wt-filling ta eps wt-filling (TAPair ta ta₁) (FHPair2 eps) = wt-filling ta₁ eps wt-filling (TAFst ta) FHOuter = _ , TAFst ta wt-filling (TAFst ta) (FHFst eps) = wt-filling ta eps wt-filling (TASnd ta) FHOuter = _ , TASnd ta wt-filling (TASnd ta) (FHSnd eps) = wt-filling ta eps wt-filling (TAEHole x x₁) FHOuter = _ , TAEHole x x₁ wt-filling (TANEHole x ta x₁) FHOuter = _ , TANEHole x ta x₁ wt-filling (TANEHole x ta x₁) (FHNEHole eps) = wt-filling ta eps wt-filling (TACast ta x) FHOuter = _ , TACast ta x wt-filling (TACast ta x) (FHCast eps) = wt-filling ta eps wt-filling (TAFailedCast x y z w) FHOuter = _ , TAFailedCast x y z w wt-filling (TAFailedCast x x₁ x₂ x₃) (FHFailedCast y) = wt-filling x y -- instruction transitions preserve type preserve-trans : ∀{Δ Γ d τ d'} → binders-unique d → Δ , Γ ⊢ d :: τ → d →> d' → Δ , Γ ⊢ d' :: τ preserve-trans bd TANum () preserve-trans bd (TAPlus ta TANum) (ITPlus x) = TANum preserve-trans bd (TAVar x₁) () preserve-trans bd (TALam _ ta) () preserve-trans (BUAp (BULam bd x₁) bd₁ (BDLam x₂ x₃)) (TAAp (TALam apt ta) ta₁) ITLam = lem-subst apt x₂ bd₁ ta ta₁ preserve-trans bd (TAAp (TACast ta TCRefl) ta₁) ITApCast = TACast (TAAp ta (TACast ta₁ TCRefl)) TCRefl preserve-trans bd (TAAp (TACast ta (TCArr x x₁)) ta₁) ITApCast = TACast (TAAp ta (TACast ta₁ (~sym x))) x₁ preserve-trans bd (TAEHole x x₁) () preserve-trans bd (TANEHole x ta x₁) () preserve-trans bd (TACast ta x) (ITCastID) = ta preserve-trans bd (TACast (TACast ta x) x₁) (ITCastSucceed x₂) = ta preserve-trans bd (TACast ta x) (ITGround (MGArr x₁)) = TACast (TACast ta (TCArr TCHole1 TCHole1)) TCHole1 preserve-trans bd (TACast ta TCHole2) (ITExpand (MGArr x₁)) = TACast (TACast ta TCHole2) (TCArr TCHole2 TCHole2) preserve-trans bd (TACast (TACast ta x) x₁) (ITCastFail w y z) = TAFailedCast ta w y z preserve-trans bd (TAFailedCast x y z q) () preserve-trans bd (TAInl ta) () preserve-trans bd (TAInr ta) () preserve-trans (BUCase (BUInl bd) bd₁ bd₂ (BDInl x₂) x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) (TACase (TAInl ta) x ta₁ x₁ ta₂) ITCaseInl = lem-subst x (binders-disjoint-sym x₂) bd ta₁ ta preserve-trans (BUCase (BUInr bd) bd₁ bd₂ (BDInr x₂) (BDInr x₃) x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) (TACase (TAInr ta) x ta₁ x₁ ta₂) ITCaseInr = lem-subst x₁ (binders-disjoint-sym x₃) bd ta₂ ta preserve-trans (BUCase (BUCast bd) bd₁ bd₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀ x₁₁) (TACase {Γ = Γ} (TACast ta x₂) x ta₁ x₁ ta₂) ITCaseCast with ~sum x₂ ... | τ1~τ2 , τ3~τ4 = TACase ta x (lem-subst-cast-ta {Γ = Γ} x bd₁ τ1~τ2 ta₁) x₁ (lem-subst-cast-ta {Γ = Γ} x₁ bd₂ τ3~τ4 ta₂) preserve-trans bd (TAPair ta ta₁) () preserve-trans bd (TAFst (TAPair ta ta₁)) ITFstPair = ta preserve-trans bd (TAFst (TACast ta x)) ITFstCast with ~prod x ... | τ1~τ2 , τ3~τ4 = TACast (TAFst ta) τ1~τ2 preserve-trans bd (TASnd (TAPair ta ta₁)) ITSndPair = ta₁ preserve-trans bd (TASnd (TACast ta x)) ITSndCast with ~prod x ... | τ1~τ2 , τ3~τ4 = TACast (TASnd ta) τ3~τ4 preserve-trans bd (TACast ta TCRefl) (ITExpand ()) preserve-trans bd (TACast ta TCHole1) (ITGround (MGSum x₁)) = TACast (TACast ta (TCSum TCHole1 TCHole1)) TCHole1 preserve-trans bd (TACast ta TCHole1) (ITExpand ()) preserve-trans bd (TACast ta TCHole2) (ITExpand (MGSum x₁)) = TACast (TACast ta TCHole2) (TCSum TCHole2 TCHole2) preserve-trans bd (TACast ta TCHole1) (ITGround (MGProd x₁)) = TACast (TACast ta (TCProd TCHole1 TCHole1)) TCHole1 preserve-trans bd (TACast ta TCHole2) (ITExpand (MGProd x)) = TACast (TACast ta TCHole2) (TCProd TCHole2 TCHole2) lem-bd-ε1 : ∀{d ε d0} → d == ε ⟦ d0 ⟧ → binders-unique d → binders-unique d0 lem-bd-ε1 FHOuter bd = bd lem-bd-ε1 (FHPlus1 eps) (BUPlus bd bd₁ x) = lem-bd-ε1 eps bd lem-bd-ε1 (FHPlus2 eps) (BUPlus bd bd₁ x) = lem-bd-ε1 eps bd₁ lem-bd-ε1 (FHAp1 eps) (BUAp bd bd₁ x) = lem-bd-ε1 eps bd lem-bd-ε1 (FHAp2 eps) (BUAp bd bd₁ x) = lem-bd-ε1 eps bd₁ lem-bd-ε1 (FHInl eps) (BUInl bd) = lem-bd-ε1 eps bd lem-bd-ε1 (FHInr eps) (BUInr bd) = lem-bd-ε1 eps bd lem-bd-ε1 (FHCase eps) (BUCase bd bd₁ bd₂ x x₁ x₂ x₃ x₄ x₅ x₆ x₇ x₈) = lem-bd-ε1 eps bd lem-bd-ε1 (FHPair1 eps) (BUPair bd bd₁ x) = lem-bd-ε1 eps bd lem-bd-ε1 (FHPair2 eps) (BUPair bd bd₁ x) = lem-bd-ε1 eps bd₁ lem-bd-ε1 (FHFst eps) (BUFst bd) = lem-bd-ε1 eps bd lem-bd-ε1 (FHSnd eps) (BUSnd bd) = lem-bd-ε1 eps bd lem-bd-ε1 (FHNEHole eps) (BUNEHole bd x) = lem-bd-ε1 eps bd lem-bd-ε1 (FHCast eps) (BUCast bd) = lem-bd-ε1 eps bd lem-bd-ε1 (FHFailedCast eps) (BUFailedCast bd) = lem-bd-ε1 eps bd -- this is the main preservation theorem, gluing together the above preservation : {Δ : hctx} {d d' : ihexp} {τ : htyp} {Γ : tctx} → binders-unique d → Δ , Γ ⊢ d :: τ → d ↦ d' → Δ , Γ ⊢ d' :: τ preservation bd D (Step x x₁ x₂) with wt-filling D x ... | (_ , wt) = wt-different-fill x D wt (preserve-trans (lem-bd-ε1 x bd) wt x₁) x₂ -- note that the exact statement of preservation in the paper, where Γ is -- empty indicating that the terms are closed, is an immediate corrolary -- of the slightly more general statement above. preservation' : {Δ : hctx} {d d' : ihexp} {τ : htyp} → binders-unique d → Δ , ∅ ⊢ d :: τ → d ↦ d' → Δ , ∅ ⊢ d' :: τ preservation' = preservation
{ "alphanum_fraction": 0.6428493747, "avg_line_length": 56.4110429448, "ext": "agda", "hexsha": "f45f612a80da2a42e7660c32eda60b380fb7672b", "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": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_path": "preservation.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "hazelgrove/hazelnut-agda", "max_issues_repo_path": "preservation.agda", "max_line_length": 182, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_path": "preservation.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3790, "size": 9195 }
------------------------------------------------------------------------------ -- The relation of divisibility on partial natural numbers ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOTC.Data.Nat.Divisibility.NotBy0 where open import FOTC.Base open import FOTC.Data.Nat infix 4 _∣_ ------------------------------------------------------------------------------ -- The relation of divisibility (the symbol is '\mid' not '|') -- -- (See documentation in FOTC.Data.Nat.Divisibility.By0) -- -- In our definition 0∤0, which is used to prove properties of the gcd -- as it is in GHC ≤ 7.0.4, where gcd 0 0 = undefined (see -- http://hackage.haskell.org/trac/ghc/ticket/3304). -- Note that @k@ should be a total natural number. _∣_ : D → D → Set m ∣ n = (m ≢ zero) ∧ (∃[ k ] N k ∧ n ≡ k * m) {-# ATP definition _∣_ #-}
{ "alphanum_fraction": 0.4830590513, "avg_line_length": 34.4333333333, "ext": "agda", "hexsha": "1ddd0d61d0e0cbda35f7aed838ce4f4cdb4759a9", "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/Data/Nat/Divisibility/NotBy0.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/Data/Nat/Divisibility/NotBy0.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/FOTC/Data/Nat/Divisibility/NotBy0.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": 1033 }
module Relation.Ternary.Separation.Monad where open import Level open import Data.Product open import Function using (_∘_; case_of_) open import Relation.Unary open import Relation.Unary.PredicateTransformer hiding (_⊔_) open import Relation.Binary.PropositionalEquality open import Relation.Ternary.Separation open import Relation.Ternary.Separation.Morphisms module Monads {a b} {A : Set a} {B : Set b} {{r}} {u} {{as : IsUnitalSep {C = A} r u}} {{rb : RawSep B}} {{jm : Morphism A B}} {{bs : IsUnitalSep rb (Morphism.j jm u)}} where open Morphism jm RawMonad : ∀ {i} (I : Set i) → (ℓ : Level) → Set _ RawMonad I ℓ = (i j : I) → PT A B ℓ ℓ {- strong indexed monads on predicates over PRSAs, relative to the functor induced by the PRSA morphism j -} record Monad {i} (I : Set i) ℓ (M : RawMonad I ℓ) : Set (a ⊔ b ⊔ suc ℓ ⊔ i) where field return : ∀ {P i₁} → ∀[ P ⇒ⱼ M i₁ i₁ P ] bind : ∀ {P i₁ i₂ i₃ Q} → ∀[ (P ─✴ⱼ M i₂ i₃ Q) ⇒ (M i₁ i₂ P ─✴ M i₁ i₃ Q) ] _=<<_ : ∀ {P Q i₁ i₂ i₃} → ∀[ P ⇒ⱼ M i₂ i₃ Q ] → ∀[ M i₁ i₂ P ⇒ M i₁ i₃ Q ] f =<< mp = app (bind (wand λ where px σ → case ⊎-id⁻ˡ σ of λ where refl → f px)) mp ⊎-idˡ _>>=_ : ∀ {Φ} {P Q i₁ i₂ i₃} → M i₁ i₂ P Φ → ∀[ P ⇒ⱼ M i₂ i₃ Q ] → M i₁ i₃ Q Φ mp >>= f = f =<< mp mapM′ : ∀ {P Q i₁ i₂} → ∀[ (P ─✴ Q) ⇒ⱼ (M i₁ i₂ P ─✴ M i₁ i₂ Q) ] mapM′ f = bind (wand λ where px σ → case j-⊎⁻ σ of λ where (_ , refl , σ') → return (app f px σ')) mapM : ∀ {Φ} {P Q i₁ i₂} → M i₁ i₂ P Φ → ∀[ P ⇒ Q ] → M i₁ i₂ Q Φ mapM mp f = mp >>= (return ∘ f) open Monad ⦃...⦄ public -- having the internal bind is enough to get strength module _ {i} {I : Set i} {i₁ i₂} {P} {M} {{ _ : Monad I a M }} where str : ∀ {Q : Pred A a} → M i₁ i₂ P Φ₁ → Φ₁ ⊎ j Φ₂ ≣ Φ → Q Φ₂ → M i₁ i₂ (P ✴ Q) Φ str mp σ qx = app (bind (wand λ where px σ' → case j-⊎⁻ σ' of λ where (_ , refl , σ'') → return (px ×⟨ ⊎-comm σ'' ⟩ qx)) ) mp (⊎-comm σ) typed-str : ∀ {Φ₁ Φ₂ Φ} (Q) → M i₁ i₂ P Φ₁ → Φ₁ ⊎ j Φ₂ ≣ Φ → Q Φ₂ → M i₁ i₂ (P ✴ Q) Φ typed-str Q mp σ qx = str {Q = Q} mp σ qx syntax str mp σ qx = mp &⟨ σ ⟩ qx syntax typed-str Q mp σ qx = mp &⟨ Q ∥ σ ⟩ qx _&_ : ∀ {Q} → M i₁ i₂ P ε → ∀[ Q ⇒ⱼ M i₁ i₂ (P ✴ Q) ] mp & q = mp &⟨ ⊎-idˡ ⟩ q
{ "alphanum_fraction": 0.5259067358, "avg_line_length": 35.6307692308, "ext": "agda", "hexsha": "7d438700cb8642538ba91f70c230736f61b79efc", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Relation/Ternary/Separation/Monad.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Relation/Ternary/Separation/Monad.agda", "max_line_length": 110, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Relation/Ternary/Separation/Monad.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 1035, "size": 2316 }
{-# OPTIONS --cumulativity #-} open import Agda.Builtin.Equality mutual _X : (Set → Set) → Set₁ → Set _X f x = _ test : (f : Set₁ → Set) (x : Set₁) → _X f x ≡ f x test f x = refl Set' : Set Set' = _X (λ X → X) Set
{ "alphanum_fraction": 0.5462555066, "avg_line_length": 15.1333333333, "ext": "agda", "hexsha": "9327d17019ea90a981bdf60b0a74ff85657cc973", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "shlevy/agda", "max_forks_repo_path": "test/Fail/Issue4401.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/Issue4401.agda", "max_line_length": 51, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/Issue4401.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": 93, "size": 227 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.types.Paths open import lib.types.Pi open import lib.types.Unit open import lib.types.Nat open import lib.types.TLevel open import lib.types.Pointed open import lib.types.Sigma open import lib.NType2 open import lib.PathGroupoid open import nicolai.pseudotruncations.Preliminary-definitions open import nicolai.pseudotruncations.Liblemmas module nicolai.pseudotruncations.SeqColim where Sequence : ∀ {i} → Type (lsucc i) Sequence {i} = Σ (ℕ → Type i) (λ A → (n : ℕ) → A n → A (S n)) module _ {i} where private data #SeqCo-aux (C : Sequence {i}) : Type i where #ins : (n : ℕ) → (fst C n) → #SeqCo-aux C data #SeqCo (C : Sequence {i}) : Type i where #trick-aux : #SeqCo-aux C → (Unit → Unit) → #SeqCo C SeqCo : (C : Sequence {i}) → Type i SeqCo = #SeqCo ins : {C : Sequence {i}} → (n : ℕ) → (fst C n) → SeqCo C ins {C} n a = #trick-aux (#ins n a) _ postulate glue : {C : Sequence {i}} → (n : ℕ) → (a : fst C n) → (ins {C} n a) == (ins (S n) (snd C n a)) module SeqCoInduction {C : Sequence {i}} {j} {P : SeqCo C → Type j} (Ins : (n : ℕ) → (a : fst C n) → P (ins n a)) (Glue : (n : ℕ) → (a : fst C n) → (Ins n a) == (Ins (S n) (snd C n a)) [ P ↓ (glue n a) ]) where f : Π (SeqCo C) P f = f-aux phantom where f-aux : Phantom Glue → Π (SeqCo C) P f-aux phantom (#trick-aux (#ins n a) _) = Ins n a postulate pathβ : (n : ℕ) → (a : fst C n) → apd f (glue n a) == (Glue n a) open SeqCoInduction public renaming (f to SeqCo-ind ; pathβ to SeqCo-ind-pathβ) {- we now have the induction principle [SeqCo-ind] with judgmental computation on points and 'homotopy' computation [SeqCo-ind-pathβ] on paths. -} module SeqCoRec {i j} {C : Sequence {i}} {B : Type j} (Ins : (n : ℕ) → (fst C n) → B) (Glue : (n : ℕ) → (a : fst C n) → (Ins n a) == (Ins (S n) (snd C n a))) where private module M = SeqCoInduction {C = C} {P = λ _ → B} Ins (λ n a → ↓-cst-in (Glue n a)) f : SeqCo C → B f = M.f pathβ : (n : ℕ) → (a : fst C n) → ap f (glue n a) == (Glue n a) pathβ n a = apd=cst-in {f = f} (M.pathβ n a) open SeqCoRec public renaming (f to SeqCo-rec ; pathβ to SeqCo-rec-pathβ) {- we now further have the recursion principle [SeqCo-rec], which of course is just a special case of [SeqCo-ind] -} {- remove the first segment of a sequence -} removeFst : ∀ {i} → Sequence {i} → Sequence {i} removeFst (A , f) = (λ n → A (S n)) , (λ n → f (S n)) {- removing the first segment does not change the colimit -} module ignoreFst {i} (C : Sequence {i}) where A = fst C f = snd C SC = SeqCo C C' = removeFst C A' = fst C' f' = snd C' SC' = SeqCo C' k-ins : (n : ℕ) → A n → SC' k-ins O a = ins O (f O a) k-ins (S n) a = ins n a k-glue : (n : ℕ) (a : A n) → k-ins n a == k-ins (S n) (f n a) k-glue O a = idp k-glue (S n) a = glue n a -- the first map k : SC → SC' k = SeqCo-rec {C = C} {B = SC'} k-ins k-glue m-ins : (n : ℕ) → A' n → SC m-ins n a' = ins (S n) a' m-glue : (n : ℕ) (a' : A' n) → m-ins n a' == m-ins (S n) (f' n a') m-glue n a' = glue (S n) a' -- the second map m : SC' → SC m = SeqCo-rec {C = C'} {B = SC} m-ins m-glue -- aux km-glue-comp : (n : ℕ) (a' : A' n) → ap (k ∘ m) (glue n a') == glue n a' km-glue-comp n a' = ap (k ∘ m) (glue n a') =⟨ ap-∘ _ _ _ ⟩ ap k (ap m (glue n a')) =⟨ ap (λ p → ap k p) (SeqCo-rec-pathβ m-ins m-glue _ _) ⟩ ap k (glue (S n) a') =⟨ SeqCo-rec-pathβ k-ins k-glue _ _ ⟩ glue n a' ∎ -- one direction, preparation km-ins : (n : ℕ) → (a' : A' n) → k (m (ins n a')) == ins n a' km-ins n a' = idp km-glue : (n : ℕ) → (a' : A' n) → (km-ins n a') == (km-ins (S n) (f' n a')) [(λ x' → k (m x') == x') ↓ (glue n a')] km-glue n a' = from-transp (λ x' → k (m x') == x') (glue n a') (transport (λ x' → k (m x') == x') (glue n a') (km-ins n a') =⟨ trans-ap {A = SC'} {B = SC'} (k ∘ m) (idf SC') (glue n a') (km-ins n a') ⟩ ! (ap (k ∘ m) (glue n a')) ∙ ap (idf SC') (glue n a') =⟨ ap (λ p → (! (ap (k ∘ m) (glue n a'))) ∙ p) (ap-idf _) ⟩ ! (ap (k ∘ m) (glue n a')) ∙ (glue n a') =⟨ ap (λ p → ! p ∙ (glue n a')) (km-glue-comp n a') ⟩ ! (glue n a') ∙ (glue n a') =⟨ !-inv-l (glue n a') ⟩ km-ins (S n) (f' n a') ∎ ) -- one direction km : (x' : SC') → k (m x') == x' km = SeqCo-ind {P = λ x' → k (m x') == x'} km-ins km-glue -- other direction, preparation mk-ins : (n : ℕ) → (a : A n) → m (k (ins n a)) == ins n a mk-ins O a = ! (glue 0 a) mk-ins (S n) a = idp -- auxiliary calculation mk-glue-comp : (n : ℕ) → (a : A n) → mk-ins n a ∙ glue n a == ap (m ∘ k) (glue n a) mk-glue-comp O a = mk-ins O a ∙ glue O a =⟨ !-inv-l (glue O a) ⟩ idp =⟨ idp ⟩ ap m (idp {a = ins O (f O a)}) =⟨ ap (λ p → ap m p) (! (SeqCo-rec-pathβ k-ins k-glue O a)) ⟩ ap m (ap k (glue O a)) =⟨ ! (ap-∘ m k _) ⟩ ap (m ∘ k) (glue O a) ∎ mk-glue-comp (S n) a = mk-ins (S n) a ∙ glue (S n) a =⟨ idp ⟩ glue (S n) a =⟨ ! (SeqCo-rec-pathβ m-ins m-glue n a) ⟩ ap m (glue n a) =⟨ ap (λ p → ap m p) (! (SeqCo-rec-pathβ k-ins k-glue (S n) a)) ⟩ ap m (ap k (glue (S n) a)) =⟨ ! (ap-∘ m k _) ⟩ ap (m ∘ k) (glue (S n) a) ∎ mk-glue : (n : ℕ) → (a : A n) → (mk-ins n a) == (mk-ins (S n) (f n a)) [(λ x → m (k x) == x) ↓ (glue n a)] mk-glue n a = from-transp (λ x → m (k x) == x) (glue n a) (transport (λ x → m (k x) == x) (glue n a) (mk-ins n a) =⟨ trans-ap (m ∘ k) (idf _) (glue n a) (mk-ins n a) ⟩ ! (ap (m ∘ k) (glue n a)) ∙ mk-ins n a ∙ ap (idf SC) (glue n a) =⟨ ap (λ p → ! (ap (m ∘ k) (glue n a)) ∙ (mk-ins n a) ∙ p) (ap-idf (glue n a)) ⟩ ! (ap (m ∘ k) (glue n a)) ∙ mk-ins n a ∙ (glue n a) =⟨ ap (λ p → (! (ap (m ∘ k) (glue n a))) ∙ p) (mk-glue-comp n a) ⟩ ! (ap (m ∘ k) (glue n a)) ∙ ap (m ∘ k) (glue n a) =⟨ !-inv-l (ap (m ∘ k) (glue n a)) ⟩ idp =⟨ idp ⟩ mk-ins (S n) (f n a) ∎) -- other direction mk : (x : SC) → m (k x) == x mk = SeqCo-ind {P = λ x → m (k x) == x} mk-ins mk-glue remove : SC ≃ SC' remove = equiv k m km mk {- summarized -} ignore-fst : ∀ {i} → (C : Sequence {i}) → (SeqCo C) ≃ (SeqCo (removeFst C)) ignore-fst C = ignoreFst.remove C {- Now, we do this n times instead of once ...-} removeInit : ∀ {i} → (C : Sequence {i}) → (n : ℕ) → Sequence {i} removeInit C O = C removeInit C (S n) = removeInit (removeFst C) n ignore-init-aux : ∀ {i} → (C C' : Sequence {i}) → (SeqCo C) ≃ (SeqCo C') → (n : ℕ) → (SeqCo C) ≃ (SeqCo (removeInit C' n)) ignore-init-aux C C' e O = e ignore-init-aux C C' e (S n) = ignore-init-aux C (removeFst C') (ignore-fst C' ∘e e) n {- Result: the sequential colimit of a sequence stays the same if we remove an initial finite segment of the sequence. -} ignore-init : ∀ {i} → (C : Sequence {i}) → (n : ℕ) → (SeqCo C) ≃ (SeqCo (removeInit C n)) ignore-init C = ignore-init-aux C C (ide _) -- TODO do we need this? {- if we have a sequence and a point of the first type, we get a point of the type after removing some initial segment -} new-initial : ∀ {i} (C : Sequence {i}) (n : ℕ) → (fst C n) → fst (removeInit C n) O new-initial C O a₀ = a₀ new-initial C (S n) a₀ = new-initial (removeFst C) n a₀ module _ {i} (C : Sequence {i}) (a₀ : fst C O) where {- nearly the same as above: lift the 'starting point' a₀ to any later type -} lift-point : (n : ℕ) → fst C n lift-point O = a₀ lift-point (S n) = snd C n (lift-point n) {- this is more special than in the text, as we only consider (0,n), not (k,n) -} {- In the colimit, the lifted point is equal to the 'starting point' -} lift-point-= : (n : ℕ) → ins {C = C} O a₀ == ins n (lift-point n) lift-point-= O = idp lift-point-= (S n) = (lift-point-= n) ∙ glue n _ {- Finally, an important definition: We say that a sequence is weakly constant if each map is weakly constant. -} wconst-chain : ∀ {i} → Sequence {i} → Type i wconst-chain (A , f) = (n : ℕ) → wconst (f n)
{ "alphanum_fraction": 0.4889867841, "avg_line_length": 33.0498084291, "ext": "agda", "hexsha": "47e20dbd8c8980538d50a03743e393493e49a60f", "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": "nicolai/pseudotruncations/SeqColim.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": "nicolai/pseudotruncations/SeqColim.agda", "max_line_length": 122, "max_stars_count": 1, "max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nicolaikraus/HoTT-Agda", "max_stars_repo_path": "nicolai/pseudotruncations/SeqColim.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": 3378, "size": 8626 }
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9. Copyright (c) 2020, 2021, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl -} open import LibraBFT.Lemmas open import LibraBFT.Prelude open import LibraBFT.Base.Encode open import LibraBFT.Base.ByteString -- This module contains a model of cryptographic signatures on -- certain data structures, and creation and verification -- thereof. These data structures, defined by the WithVerSig -- type, can be optionally signed, and if they are signed, the -- signature covers a ByteString derived from the data structure, -- enabling support for signature that cover only (functions of) -- specific parts of the data structure. The module also -- contains some properties we have found useful in other -- contexts, though they are not yet used in this repo. module LibraBFT.Base.PKCS where postulate -- valid assumption signature-size : ℕ Signature : Set Signature = Σ ByteString (λ s → length s ≡ signature-size) postulate -- valid assumptions PK : Set SK : Set IsKeyPair : PK → SK → Set _≟PK_ : (pk1 pk2 : PK) → Dec (pk1 ≡ pk2) instance enc-PK : Encoder PK enc-SigMB : Encoder (Maybe Signature) sign-raw : ByteString → SK → Signature verify : ByteString → Signature → PK → Bool -- We assume no "signature collisions", as represented by verify-pk-inj verify-pk-inj : ∀{bs sig pk pk'} → verify bs sig pk ≡ true → verify bs sig pk' ≡ true → pk ≡ pk' verify-bs-inj : ∀{bs bs' sig pk} → verify bs sig pk ≡ true → verify bs' sig pk ≡ true → bs ≡ bs' verify-sign : ∀{bs pk sk} → IsKeyPair pk sk → verify bs (sign-raw bs sk) pk ≡ true verify-fail : ∀{bs pk sk} → ¬ IsKeyPair pk sk → verify bs (sign-raw bs sk) pk ≡ false -- We consider a PK to be (permanently) either honest or not, -- respresented by the following postulate. This is relevant -- in reasoning about possible behaviours of a modeled system. -- Specifically, the secret key corresponding to an honest PK -- is assumed not to be leaked, ensuring that cheaters cannot -- forge new signatures for honest PKs. Furthermore, if a peer -- is assigned we use possession -- of an honest PK in a given epoch to modelWe will postulate that, among -- the PKs chosen for a particular epoch, the number of them -- that are dishonest is at most the number of faults to be -- tolerated for that epoch. This definition is /meta/: the -- information about which PKs are (dis)honest should never be -- used by the implementation -- it is only for modeling and -- proofs. Meta-Dishonest-PK : PK → Set Meta-DishonestPK? : (pk : PK) → Dec (Meta-Dishonest-PK pk) verify-pi : ∀{bs sig pk} → (v1 : verify bs sig pk ≡ true) → (v2 : verify bs sig pk ≡ true) → v1 ≡ v2 verify-pi {bs} {sig} {pk} _ _ with verify bs sig pk verify-pi {bs} {sig} {pk} refl refl | .true = refl Meta-Honest-PK : PK → Set Meta-Honest-PK = ¬_ ∘ Meta-Dishonest-PK -- A datatype C might that might carry values with -- signatures should be an instance of 'WithSig' below. record WithSig (C : Set) : Set₁ where field -- A decidable predicate indicates whether values have -- been signed Signed : C → Set Signed-pi : ∀ (c : C) → (is1 : Signed c) → (is2 : Signed c) → is1 ≡ is2 isSigned? : (c : C) → Dec (Signed c) -- Signed values must have a signature signature : (c : C)(hasSig : Signed c) → Signature -- All values must be /encoded/ into a ByteString that -- is supposed to be verified against a signature. signableFields : C → ByteString open WithSig {{...}} public sign : {C : Set} ⦃ ws : WithSig C ⦄ → C → SK → Signature sign c = sign-raw (signableFields c) Signature≡ : {C : Set} ⦃ ws : WithSig C ⦄ → C → Signature → Set Signature≡ c sig = Σ (Signed c) (λ s → signature c s ≡ sig) -- A value of a datatype C can have its signature -- verified; A value of type WithVerSig c is a proof of that. -- Hence; the set (Σ C WithVerSig) is the set of values of -- type C with verified signatures. record WithVerSig {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where constructor mkWithVerSig field isSigned : Signed c verified : verify (signableFields c) (signature c isSigned) pk ≡ true open WithVerSig public ver-signature : ∀{C pk}⦃ ws : WithSig C ⦄{c : C} → WithVerSig pk c → Signature ver-signature {c = c} wvs = signature c (isSigned wvs) verCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {is1 is2 : Signed c} {pk1 pk2 : PK} → verify (signableFields c) (signature c is1) pk1 ≡ true → pk1 ≡ pk2 → is1 ≡ is2 → verify (signableFields c) (signature c is2) pk2 ≡ true verCast prf refl refl = prf wvsCast : {C : Set} ⦃ ws : WithSig C ⦄ {c : C} {pk1 pk2 : PK} → WithVerSig pk1 c → pk2 ≡ pk1 → WithVerSig pk2 c wvsCast {c = c} wvs refl = wvs withVerSig-≡ : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C} → {wvs1 : WithVerSig pk c} → {wvs2 : WithVerSig pk c} → isSigned wvs1 ≡ isSigned wvs2 → wvs1 ≡ wvs2 withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} refl with verified wvs2 | inspect verified wvs2 | verCast (verified wvs1) refl refl ...| vwvs2 | [ R ] | vwvs1 rewrite verify-pi vwvs1 vwvs2 | sym R = refl withVerSig-pi : {C : Set} {pk : PK} {c : C} ⦃ ws : WithSig C ⦄ → (wvs1 : WithVerSig pk c) → (wvs2 : WithVerSig pk c) → wvs2 ≡ wvs1 withVerSig-pi {C} {pk} {c} ⦃ ws ⦄ wvs2 wvs1 with isSigned? c ...| no ¬Signed = ⊥-elim (¬Signed (isSigned wvs1)) ...| yes sc = withVerSig-≡ {wvs1 = wvs1} {wvs2 = wvs2} (Signed-pi c (isSigned wvs1) (isSigned wvs2)) data SigCheckResult {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) : Set where notSigned : ¬ Signed c → SigCheckResult pk c checkFailed : (sc : Signed c) → verify (signableFields c) (signature c sc) pk ≡ false → SigCheckResult pk c sigVerified : WithVerSig pk c → SigCheckResult pk c checkFailed≢sigVerified : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C} {wvs : WithVerSig ⦃ ws ⦄ pk c} {sc : Signed c} {v : verify (signableFields c) (signature c sc) pk ≡ false} → checkFailed sc v ≡ sigVerified wvs → ⊥ checkFailed≢sigVerified () data SigCheckOutcome : Set where notSigned : SigCheckOutcome checkFailed : SigCheckOutcome sigVerified : SigCheckOutcome data SigCheckFailed : Set where notSigned : SigCheckFailed checkFailed : SigCheckFailed check-signature : {C : Set} ⦃ ws : WithSig C ⦄ → (pk : PK) → (c : C) → SigCheckResult pk c check-signature pk c with isSigned? c ...| no ns = notSigned ns ...| yes sc with verify (signableFields c) (signature c sc) pk | inspect (verify (signableFields c) (signature c sc)) pk ...| false | [ nv ] = checkFailed sc nv ...| true | [ v ] = sigVerified (record { isSigned = sc ; verified = v }) sigCheckOutcomeFor : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) → SigCheckOutcome sigCheckOutcomeFor pk c with check-signature pk c ...| notSigned _ = notSigned ...| checkFailed _ _ = checkFailed ...| sigVerified _ = sigVerified sigVerifiedVerSigCS : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C} → sigCheckOutcomeFor pk c ≡ sigVerified → ∃[ wvs ] (check-signature ⦃ ws ⦄ pk c ≡ sigVerified wvs) sigVerifiedVerSigCS {pk = pk} {c = c} prf with check-signature pk c | inspect (check-signature pk) c ...| sigVerified verSig | [ R ] rewrite R = verSig , refl sigVerifiedVerSig : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C} → sigCheckOutcomeFor pk c ≡ sigVerified → WithVerSig pk c sigVerifiedVerSig = proj₁ ∘ sigVerifiedVerSigCS sigVerifiedSCO : {C : Set} ⦃ ws : WithSig C ⦄ {pk : PK} {c : C} → (wvs : WithVerSig pk c) → sigCheckOutcomeFor pk c ≡ sigVerified sigVerifiedSCO {pk = pk} {c = c} wvs with check-signature pk c ...| notSigned ns = ⊥-elim (ns (isSigned wvs)) ...| checkFailed xx xxs rewrite Signed-pi c xx (isSigned wvs) = ⊥-elim (false≢true (trans (sym xxs) (verified wvs))) ...| sigVerified wvs' = refl failedSigCheckOutcome : {C : Set} ⦃ ws : WithSig C ⦄ (pk : PK) (c : C) → sigCheckOutcomeFor pk c ≢ sigVerified → SigCheckFailed failedSigCheckOutcome pk c prf with sigCheckOutcomeFor pk c ...| notSigned = notSigned ...| checkFailed = checkFailed ...| sigVerified = ⊥-elim (prf refl)
{ "alphanum_fraction": 0.6059536935, "avg_line_length": 39.9559471366, "ext": "agda", "hexsha": "ffec4d27f580f89dd3cb616017f70bf993d8e0e7", "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": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_forks_repo_licenses": [ "UPL-1.0" ], "max_forks_repo_name": "cwjnkins/bft-consensus-agda", "max_forks_repo_path": "LibraBFT/Base/PKCS.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "UPL-1.0" ], "max_issues_repo_name": "cwjnkins/bft-consensus-agda", "max_issues_repo_path": "LibraBFT/Base/PKCS.agda", "max_line_length": 117, "max_stars_count": null, "max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084", "max_stars_repo_licenses": [ "UPL-1.0" ], "max_stars_repo_name": "cwjnkins/bft-consensus-agda", "max_stars_repo_path": "LibraBFT/Base/PKCS.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2796, "size": 9070 }
{-# OPTIONS --without-K --safe #-} module Dodo.Binary.Identity where -- Stdlib imports import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; subst; sym) open import Level using (Level; _⊔_) open import Function.Base using (flip) open import Data.Product using (_×_; _,_; ∃; ∃-syntax; proj₁; proj₂) open import Data.Sum using (inj₁; inj₂) open import Relation.Unary using (Pred) open import Relation.Binary using (Rel) open import Relation.Binary using (Symmetric; Transitive; IsStrictTotalOrder) -- Local imports open import Dodo.Binary.Equality open import Dodo.Binary.Composition open import Dodo.Binary.Intersection open import Dodo.Binary.Union open import Dodo.Unary.Equality open import Dodo.Unary.Intersection open import Dodo.Unary.Union -- # Definitions -- | Identity relation over some set -- -- Iff `P x` holds then `⦗ P ⦘ x x` holds. ⦗_⦘ : ∀ {a ℓ : Level} {A : Set a} → Pred A ℓ ------------- → Rel A (a ⊔ ℓ) ⦗ p ⦘ x y = x ≡ y × p x -- # Properties module _ {a ℓ : Level} {A : Set a} {p : Pred A ℓ} where ⦗⦘-sym : Symmetric ⦗ p ⦘ ⦗⦘-sym (refl , px) = (refl , px) ⦗⦘-trans : Transitive ⦗ p ⦘ ⦗⦘-trans (refl , pi) (refl , _) = (refl , pi) ⦗⦘-flip : ⦗ p ⦘ ⇔₂ flip ⦗ p ⦘ ⦗⦘-flip = ⇔: (λ{_ _ → ⦗⦘-sym}) (λ{_ _ → ⦗⦘-sym}) -- # Operations module _ {a ℓ : Level} {A : Set a} {p : Pred A ℓ} where ⦗⦘-combine-⨾ : ⦗ p ⦘ ⨾ ⦗ p ⦘ ⇔₂ ⦗ p ⦘ ⦗⦘-combine-⨾ = ⇔: ⊆-proof ⊇-proof where ⊆-proof : ⦗ p ⦘ ⨾ ⦗ p ⦘ ⊆₂' ⦗ p ⦘ ⊆-proof _ _ ((refl , Px) ⨾[ x ]⨾ (refl , _)) = (refl , Px) ⊇-proof : ⦗ p ⦘ ⊆₂' ⦗ p ⦘ ⨾ ⦗ p ⦘ ⊇-proof x _ (refl , Px) = (refl , Px) ⨾[ _ ]⨾ (refl , Px) module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {p : Pred A ℓ₁} {q : Pred A ℓ₂} where ⦗⦘-lift-⊆₂ : p ⊆₁ q → ⦗ p ⦘ ⊆₂ ⦗ q ⦘ ⦗⦘-lift-⊆₂ (⊆: p⊆q) = ⊆: lemma where lemma : ⦗ p ⦘ ⊆₂' ⦗ q ⦘ lemma x .x (refl , px) = (refl , p⊆q x px) ⦗⦘-unlift-⊆₂ : ⦗ p ⦘ ⊆₂ ⦗ q ⦘ → p ⊆₁ q ⦗⦘-unlift-⊆₂ (⊆: ⦗p⦘⊆⦗q⦘) = ⊆: lemma where lemma : p ⊆₁' q lemma x px = proj₂ (⦗p⦘⊆⦗q⦘ x x (refl , px)) module _ {a ℓ₁ ℓ₂ : Level} {A : Set a} {p : Pred A ℓ₁} {q : Pred A ℓ₂} where ⦗⦘-lift : p ⇔₁ q → ⦗ p ⦘ ⇔₂ ⦗ q ⦘ ⦗⦘-lift = ⇔₂-compose-⇔₁ ⦗⦘-lift-⊆₂ ⦗⦘-lift-⊆₂ ⦗⦘-unlift : ⦗ p ⦘ ⇔₂ ⦗ q ⦘ → p ⇔₁ q ⦗⦘-unlift = ⇔₁-compose-⇔₂ ⦗⦘-unlift-⊆₂ ⦗⦘-unlift-⊆₂ ⦗⦘-dist-∪ : ⦗ p ∪₁ q ⦘ ⇔₂ ⦗ p ⦘ ∪₂ ⦗ q ⦘ ⦗⦘-dist-∪ = ⇔: ⊆-proof ⊇-proof where ⊆-proof : ⦗ p ∪₁ q ⦘ ⊆₂' ⦗ p ⦘ ∪₂ ⦗ q ⦘ ⊆-proof _ _ (refl , inj₁ px) = inj₁ (refl , px) ⊆-proof _ _ (refl , inj₂ qx) = inj₂ (refl , qx) ⊇-proof : ⦗ p ⦘ ∪₂ ⦗ q ⦘ ⊆₂' ⦗ p ∪₁ q ⦘ ⊇-proof _ _ (inj₁ (refl , px)) = (refl , inj₁ px) ⊇-proof _ _ (inj₂ (refl , qx)) = (refl , inj₂ qx) ⦗⦘-dist-∩ : ⦗ p ∩₁ q ⦘ ⇔₂ ⦗ p ⦘ ∩₂ ⦗ q ⦘ ⦗⦘-dist-∩ = ⇔: ⊆-proof ⊇-proof where ⊆-proof : ⦗ p ∩₁ q ⦘ ⊆₂' ⦗ p ⦘ ∩₂ ⦗ q ⦘ ⊆-proof x .x (refl , Px , Qx) = (refl , Px) , (refl , Qx) ⊇-proof : ⦗ p ⦘ ∩₂ ⦗ q ⦘ ⊆₂' ⦗ p ∩₁ q ⦘ ⊇-proof x .x ((refl , Px) , (_ , Qx)) = refl , (Px , Qx)
{ "alphanum_fraction": 0.5098827471, "avg_line_length": 28.4285714286, "ext": "agda", "hexsha": "5bf925fd6f49baa3aaa7ef7821f89cd811489b6a", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "sourcedennis/agda-dodo", "max_forks_repo_path": "src/Dodo/Binary/Identity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "sourcedennis/agda-dodo", "max_issues_repo_path": "src/Dodo/Binary/Identity.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "sourcedennis/agda-dodo", "max_stars_repo_path": "src/Dodo/Binary/Identity.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1675, "size": 2985 }
primitive primLevelZero : _
{ "alphanum_fraction": 0.7666666667, "avg_line_length": 10, "ext": "agda", "hexsha": "2b29df98848bbb11d3ce5b4a5cd0394759e4b864", "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/Issue3318-1.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/Issue3318-1.agda", "max_line_length": 19, "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/Issue3318-1.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": 8, "size": 30 }
module Text.Printf where open import Prelude hiding (parseNat) open import Builtin.Float private data Padding : Set where noPad : Padding lPad rPad : Nat → Padding record Flags : Set where field padding : Padding padChar : Char alternate : Bool precision : Maybe Nat defaultFlags : Flags Flags.padding defaultFlags = noPad Flags.padChar defaultFlags = ' ' Flags.alternate defaultFlags = false Flags.precision defaultFlags = nothing data Format : Set where natArg : Flags → Format strArg : Flags → Format ustrArg : Flags → Format floatArg : Flags → Format charArg : Format hexArg : Bool → Flags → Format litString : String → Format badFormat : String → Format data BadFormat (s : String) : Set where private BadFormat′ : String → Set BadFormat′ "" = ⊥ BadFormat′ s = BadFormat s private consLit : String → List Format → List Format consLit s (litString s′ ∷ fmt) = litString (s & s′) ∷ fmt consLit s fmt = litString s ∷ fmt private parseFormat : List Char → List Format parseFormatWithFlags : Flags → List Char → List Format parseNat′ : (Nat → Flags) → Nat → List Char → List Format parseNat′ flags n [] = parseFormatWithFlags (flags n) [] parseNat′ flags n (c ∷ s) = if isDigit c then parseNat′ flags (n * 10 + charToNat c - charToNat '0') s else parseFormatWithFlags (flags n) (c ∷ s) parseNat : (Nat → Flags) → List Char → List Format parseNat p s = parseNat′ p 0 s parsePadding : Flags → List Char → List Format parsePadding f [] = parseFormatWithFlags f [] parsePadding f ('-' ∷ c ∷ s) = if isDigit c then parseNat (λ n → record f { padding = rPad n }) (c ∷ s) else badFormat (packString ('-' ∷ c ∷ [])) ∷ parseFormat s parsePadding f ('0' ∷ s) = parsePadding (record f { padChar = '0' }) s parsePadding f ('.' ∷ c ∷ s) = if isDigit c then parseNat (λ n → record f { precision = just n }) (c ∷ s) else badFormat (packString ('.' ∷ c ∷ [])) ∷ parseFormat s parsePadding f (c ∷ s) = if isDigit c then parseNat (λ n → record f { padding = lPad n }) (c ∷ s) else parseFormatWithFlags f (c ∷ s) parseFlags : Flags → List Char → List Format parseFlags f ('#' ∷ s) = parseFlags (record f { alternate = true }) s parseFlags f s = parsePadding f s parseFormatWithFlags f [] = badFormat "" ∷ [] parseFormatWithFlags f ('d' ∷ s) = natArg f ∷ parseFormat s parseFormatWithFlags f ('x' ∷ s) = hexArg false f ∷ parseFormat s parseFormatWithFlags f ('X' ∷ s) = hexArg true f ∷ parseFormat s parseFormatWithFlags f ('c' ∷ s) = charArg ∷ parseFormat s parseFormatWithFlags f ('s' ∷ s) = strArg f ∷ parseFormat s parseFormatWithFlags f ('S' ∷ s) = ustrArg f ∷ parseFormat s parseFormatWithFlags f ('f' ∷ s) = floatArg f ∷ parseFormat s parseFormatWithFlags f ('%' ∷ s) = consLit "%" $ parseFormat s parseFormatWithFlags f ( c ∷ s) = badFormat (packString ('%' ∷ c ∷ [])) ∷ parseFormat s parseFormat [] = [] parseFormat ('%' ∷ fmt) = parseFlags defaultFlags fmt parseFormat (c ∷ fmt) = consLit (packString [ c ]) $ parseFormat fmt private pad : (String → String → String) → Char → Nat → String → String pad _+_ c n s = case n - length (unpackString s) of λ { 0 → s ; d → packString (replicate d c) + s} padLeft padRight : Char → Nat → String → String padLeft = pad _&_ padRight = pad (flip _&_) hexDigit : Char → Nat → String hexDigit a n = if n <? 10 then packString [ natToChar (n + charToNat '0') ] else packString [ natToChar (n - 10 + charToNat a) ] {-# TERMINATING #-} showHex′ : Char → Nat → String showHex′ _ 0 = "" showHex′ a n = showHex′ a (n div 16) & hexDigit a (n mod 16) add0x : Flags → String → String add0x flags s = if Flags.alternate flags then "0x" & s else s pad0 : Flags → String → String pad0 flags s = let c = Flags.padChar flags in ifYes c == ' ' then s else case Flags.padding flags of λ { noPad → s ; (lPad n) → padLeft c (n - 2) s ; (rPad _) → s } showHex : Flags → Bool → Nat → String showHex f _ 0 = add0x f $ pad0 f $ "0" showHex f u n = add0x f $ pad0 f $ showHex′ (if u then 'A' else 'a') n showFrac : Nat → Float → String showFrac 0 _ = "" showFrac 1 x = show (round (10 * x)) showFrac (suc p) x = show n & showFrac p (x′ - intToFloat n) where x′ = 10 * x n = floor x′ showPosFloat : Flags → Float → String showPosFloat f x = case Flags.precision f of λ { nothing → show x ; (just 0) → show (floor x) ; (just p) → show (floor x) & "." & showFrac p (x - intToFloat (floor x)) } showFloat : Flags → Float → String showFloat f x with x <? 0.0 ... | true = "-" & showPosFloat f (negate x) ... | false = showPosFloat f x withPad : Flags → String → ShowS withPad flags s = let c = Flags.padChar flags in case Flags.padding flags of λ { noPad → showString s ; (lPad n) → showString (padLeft c n s) ; (rPad n) → showString (padRight c n s) } private Printf′ : List Format → Set Printf′ [] = String Printf′ (natArg _ ∷ fmt) = Nat → Printf′ fmt Printf′ (hexArg _ _ ∷ fmt) = Nat → Printf′ fmt Printf′ (strArg _ ∷ fmt) = String → Printf′ fmt Printf′ (ustrArg _ ∷ fmt) = List Char → Printf′ fmt Printf′ (charArg ∷ fmt) = Char → Printf′ fmt Printf′ (floatArg _ ∷ fmt) = Float → Printf′ fmt Printf′ (litString _ ∷ fmt) = Printf′ fmt Printf′ (badFormat e ∷ fmt) = BadFormat′ e → Printf′ fmt printf′ : (fmt : List Format) → ShowS → Printf′ fmt printf′ [] acc = acc "" printf′ (natArg p ∷ fmt) acc n = printf′ fmt (acc ∘ withPad p (show n)) printf′ (hexArg u p ∷ fmt) acc n = printf′ fmt (acc ∘ withPad p (showHex p u n)) printf′ (strArg p ∷ fmt) acc s = printf′ fmt (acc ∘ withPad p s) printf′ (ustrArg p ∷ fmt) acc s = printf′ fmt (acc ∘ withPad p (packString s)) printf′ (floatArg p ∷ fmt) acc x = printf′ fmt (acc ∘ withPad p (showFloat p x)) printf′ (charArg ∷ fmt) acc c = printf′ fmt (acc ∘ showString (packString [ c ])) printf′ (litString s ∷ fmt) acc = printf′ fmt (acc ∘ showString s) printf′ (badFormat _ ∷ fmt) acc _ = printf′ fmt acc Printf : String → Set Printf = Printf′ ∘ parseFormat ∘ unpackString printf : (fmt : String) → Printf fmt printf fmt = printf′ (parseFormat $ unpackString fmt) id
{ "alphanum_fraction": 0.609432799, "avg_line_length": 35.6483516484, "ext": "agda", "hexsha": "d9cc0b1d9af5b0cc971ff76581119ae776b18fdf", "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": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "lclem/agda-prelude", "max_forks_repo_path": "src/Text/Printf.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "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": "lclem/agda-prelude", "max_issues_repo_path": "src/Text/Printf.agda", "max_line_length": 90, "max_stars_count": null, "max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "lclem/agda-prelude", "max_stars_repo_path": "src/Text/Printf.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2137, "size": 6488 }
------------------------------------------------------------------------------ -- Arithmetic properties (using induction on the FOTC natural numbers type) ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} -- Usually our proofs use pattern matching instead of the induction -- principle associated with the FOTC natural numbers. The following -- examples show some proofs using it. module FOTC.Data.Nat.PropertiesByInductionI where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.PropertiesI open import FOTC.Data.Nat open import FOTC.Data.Nat.UnaryNumbers ------------------------------------------------------------------------------ -- Congruence properties +-leftCong : ∀ {a b c} → a ≡ b → a + c ≡ b + c +-leftCong refl = refl +-rightCong : ∀ {a b c} → b ≡ c → a + b ≡ a + c +-rightCong refl = refl ------------------------------------------------------------------------------ N→0∨S : ∀ {n} → N n → n ≡ zero ∨ (∃[ n' ] n ≡ succ₁ n' ∧ N n') N→0∨S = N-ind A A0 is where A : D → Set A i = i ≡ zero ∨ (∃[ i' ] i ≡ succ₁ i' ∧ N i') A0 : A zero A0 = inj₁ refl is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = case prf₁ prf₂ Ai where prf₁ : i ≡ zero → succ₁ i ≡ zero ∨ (∃[ i' ] succ₁ i ≡ succ₁ i' ∧ N i') prf₁ h' = inj₂ (i , refl , (subst N (sym h') nzero)) prf₂ : ∃[ i' ] i ≡ succ₁ i' ∧ N i' → succ₁ i ≡ zero ∨ (∃[ i' ] succ₁ i ≡ succ₁ i' ∧ N i') prf₂ (i' , prf , Ni') = inj₂ (i , refl , subst N (sym prf) (nsucc Ni')) Sx≢x : ∀ {n} → N n → succ₁ n ≢ n Sx≢x = N-ind A A0 is where A : D → Set A i = succ₁ i ≢ i A0 : A zero A0 = S≢0 is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = →-trans succInjective Ai +-leftIdentity : ∀ n → zero + n ≡ n +-leftIdentity n = +-0x n +-rightIdentity : ∀ {n} → N n → n + zero ≡ n +-rightIdentity = N-ind A A0 is where A : D → Set A i = i + zero ≡ i A0 : A zero A0 = +-leftIdentity zero is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = trans (+-Sx i zero) (succCong Ai) pred-N : ∀ {n} → N n → N (pred₁ n) pred-N {n} Nn = case h₁ h₂ (N→0∨S Nn) where h₁ : n ≡ zero → N (pred₁ n) h₁ n≡0 = subst N (sym (trans (predCong n≡0) pred-0)) nzero h₂ : ∃[ n' ] n ≡ succ₁ n' ∧ N n' → N (pred₁ n) h₂ (n' , prf , Nn') = subst N (sym (trans (predCong prf) (pred-S n'))) Nn' +-N : ∀ {m n} → N m → N n → N (m + n) +-N {n = n} Nm Nn = N-ind A A0 is Nm where A : D → Set A i = N (i + n) A0 : A zero A0 = subst N (sym (+-leftIdentity n)) Nn is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = subst N (sym (+-Sx i n)) (nsucc Ai) ∸-N : ∀ {m n} → N m → N n → N (m ∸ n) ∸-N {m} Nm Nn = N-ind A A0 is Nn where A : D → Set A i = N (m ∸ i) A0 : A zero A0 = subst N (sym (∸-x0 m)) Nm is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = subst N (sym (∸-xS m i)) (pred-N Ai) +-assoc : ∀ {m} → N m → ∀ n o → m + n + o ≡ m + (n + o) +-assoc Nm n o = N-ind A A0 is Nm where A : D → Set A i = i + n + o ≡ i + (n + o) A0 : A zero A0 = zero + n + o ≡⟨ +-leftCong (+-leftIdentity n) ⟩ n + o ≡⟨ sym (+-leftIdentity (n + o)) ⟩ zero + (n + o) ∎ is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = succ₁ i + n + o ≡⟨ +-leftCong (+-Sx i n) ⟩ succ₁ (i + n) + o ≡⟨ +-Sx (i + n) o ⟩ succ₁ (i + n + o) ≡⟨ succCong Ai ⟩ succ₁ (i + (n + o)) ≡⟨ sym (+-Sx i (n + o)) ⟩ succ₁ i + (n + o) ∎ x+Sy≡S[x+y] : ∀ {m} → N m → ∀ n → m + succ₁ n ≡ succ₁ (m + n) x+Sy≡S[x+y] Nm n = N-ind A A0 is Nm where A : D → Set A i = i + succ₁ n ≡ succ₁ (i + n) A0 : A zero A0 = zero + succ₁ n ≡⟨ +-leftIdentity (succ₁ n) ⟩ succ₁ n ≡⟨ succCong (sym (+-leftIdentity n)) ⟩ succ₁ (zero + n) ∎ is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = succ₁ i + succ₁ n ≡⟨ +-Sx i (succ₁ n) ⟩ succ₁ (i + succ₁ n) ≡⟨ succCong Ai ⟩ succ₁ (succ₁ (i + n)) ≡⟨ succCong (sym (+-Sx i n)) ⟩ succ₁ (succ₁ i + n) ∎ +-comm : ∀ {m n} → N m → N n → m + n ≡ n + m +-comm {n = n} Nm Nn = N-ind A A0 is Nm where A : D → Set A i = i + n ≡ n + i A0 : A zero A0 = zero + n ≡⟨ +-leftIdentity n ⟩ n ≡⟨ sym (+-rightIdentity Nn) ⟩ n + zero ∎ is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = succ₁ i + n ≡⟨ +-Sx i n ⟩ succ₁ (i + n) ≡⟨ succCong Ai ⟩ succ₁ (n + i) ≡⟨ sym (x+Sy≡S[x+y] Nn i) ⟩ n + succ₁ i ∎ 0∸x : ∀ {n} → N n → zero ∸ n ≡ zero 0∸x = N-ind A A0 is where A : D → Set A i = zero ∸ i ≡ zero A0 : A zero A0 = ∸-x0 zero is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = zero ∸ succ₁ i ≡⟨ ∸-xS zero i ⟩ pred₁ (zero ∸ i) ≡⟨ predCong Ai ⟩ pred₁ zero ≡⟨ pred-0 ⟩ zero ∎ S∸S : ∀ {m n} → N m → N n → succ₁ m ∸ succ₁ n ≡ m ∸ n S∸S {m} Nm = N-ind A A0 is where A : D → Set A i = succ₁ m ∸ succ₁ i ≡ m ∸ i A0 : A zero A0 = succ₁ m ∸ succ₁ zero ≡⟨ ∸-xS (succ₁ m) zero ⟩ pred₁ (succ₁ m ∸ zero) ≡⟨ predCong (∸-x0 (succ₁ m)) ⟩ pred₁ (succ₁ m) ≡⟨ pred-S m ⟩ m ≡⟨ sym (∸-x0 m) ⟩ m ∸ zero ∎ is : ∀ {i} → A i → A (succ₁ i) is {i} Ai = succ₁ m ∸ succ₁ (succ₁ i) ≡⟨ ∸-xS (succ₁ m) (succ₁ i) ⟩ pred₁ (succ₁ m ∸ succ₁ i) ≡⟨ predCong Ai ⟩ pred₁ (m ∸ i) ≡⟨ sym (∸-xS m i) ⟩ m ∸ succ₁ i ∎
{ "alphanum_fraction": 0.4349759829, "avg_line_length": 28.3888888889, "ext": "agda", "hexsha": "cfabc97a1ed89df80fd320c473ce6faa60f9d6f4", "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/Data/Nat/PropertiesByInductionI.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/Data/Nat/PropertiesByInductionI.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/FOTC/Data/Nat/PropertiesByInductionI.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": 2373, "size": 5621 }
{- This file exports the primitives of cubical Id types -} {-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Core.Id where open import Cubical.Core.Primitives hiding ( _≡_ ) open import Agda.Builtin.Cubical.Id public renaming ( conid to ⟨_,_⟩ -- TODO: should the user really be able to access these two? ; primIdFace to faceId -- ∀ {ℓ} {A : Type ℓ} {x y : A} → Id x y → I ; primIdPath to pathId -- ∀ {ℓ} {A : Type ℓ} {x y : A} → Id x y → Path A x y ; primIdElim to elimId -- ∀ {ℓ ℓ'} {A : Type ℓ} {x : A} -- (P : ∀ (y : A) → x ≡ y → Type ℓ') -- (h : ∀ (φ : I) (y : A [ φ ↦ (λ _ → x) ]) -- (w : (Path _ x (outS y)) [ φ ↦ (λ { (φ = i1) → λ _ → x}) ] ) → -- P (outS y) ⟨ φ , outS w ⟩) → -- {y : A} (w' : x ≡ y) → P y w' ) hiding ( primIdJ ) -- this should not be used as it is using compCCHM {- BUILTIN ID Id -} _≡_ : ∀ {ℓ} {A : Type ℓ} → A → A → Type ℓ _≡_ = Id
{ "alphanum_fraction": 0.4217506631, "avg_line_length": 45.24, "ext": "agda", "hexsha": "952514dd4d02008e459d5c63e1dbbd8f86f5b11c", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z", "max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "dan-iel-lee/cubical", "max_forks_repo_path": "Cubical/Core/Id.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/Core/Id.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/Core/Id.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 378, "size": 1131 }
open import Prelude open import dynamics-core module grounding where grounding : ∀{τ1 τ2} → τ1 ▸gnd τ2 → ((τ2 ground) × (τ1 ~ τ2) × (τ1 ≠ τ2)) grounding (MGArr x) = GArrHole , TCArr TCHole1 TCHole1 , x grounding (MGSum x) = GSumHole , TCSum TCHole1 TCHole1 , x grounding (MGProd x) = GProdHole , TCProd TCHole1 TCHole1 , x
{ "alphanum_fraction": 0.6305555556, "avg_line_length": 32.7272727273, "ext": "agda", "hexsha": "33ac0b145ad2322aab12931dc3cabfbe2f84c46a", "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": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "hazelgrove/hazelnut-agda", "max_forks_repo_path": "grounding.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "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": "hazelgrove/hazelnut-agda", "max_issues_repo_path": "grounding.agda", "max_line_length": 63, "max_stars_count": null, "max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "hazelgrove/hazelnut-agda", "max_stars_repo_path": "grounding.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 138, "size": 360 }
module Selective.EnvironmentOperations where open import Selective.ActorMonad open import Selective.SimulationEnvironment open import Prelude open import Data.List.All.Properties using (++⁺ ; drop⁺) open import Data.List.Properties using (map-++-commute) open import Data.Nat.Properties using (≤-reflexive) open import Data.Product using (Σ ; _,_ ; _×_ ; Σ-syntax) open Actor open ValidActor open Env open NamedInbox open NameSupplyStream -- We can create a new Actor from an ActorM if we know its name. -- This is used when spawning an actor. new-actor : ∀ {IS A post} → ActorM ∞ IS A [] post → Name → Actor new-actor {IS} {A} {post} m name = record { inbox-shape = IS ; A = A ; references = [] ; pre = [] ; pre-eq-refs = refl ; post = post ; computation = m ⟶ [] ; name = name } -- An actor can be lifted to run sub-programs that need less references lift-actor : (actor : Actor) → {pre : TypingContext} → (references : Store) → (pre-eq-refs : (map shape references) ≡ pre) → ActorState ∞ (inbox-shape actor) (A actor) pre (post actor) → Actor lift-actor actor {pre} references pre-eq-refs m = record { inbox-shape = inbox-shape actor ; A = actor .A ; references = references ; pre = pre ; pre-eq-refs = pre-eq-refs ; post = actor .post ; computation = m ; name = actor .name } -- Replace the monadic part of an actor -- Many of the bind-operations don't change anything except what the next step should be. replace-actorM : (actor : Actor) → ActorState ∞ (inbox-shape actor) (A actor) (pre actor) (post actor) → Actor replace-actorM actor m = record { inbox-shape = inbox-shape actor ; A = A actor ; references = references actor ; pre = pre actor ; pre-eq-refs = pre-eq-refs actor ; post = post actor ; computation = m ; name = name actor } -- Add one reference to an actor. -- Used when receiving a reference, spawn, or self. -- The precondition and references are equal via the congruence relation on consing the shape of the reference. add-reference : (actor : Actor) → (nm : NamedInbox) → ActorState ∞ (inbox-shape actor) (A actor) (shape nm ∷ pre actor) (post actor) → Actor add-reference actor nm m = record { inbox-shape = inbox-shape actor ; A = A actor ; references = nm ∷ references actor ; pre = shape nm ∷ pre actor ; pre-eq-refs = cong (_∷_ (shape nm)) (pre-eq-refs actor) ; post = post actor ; computation = m ; name = name actor } add-references-to-actor : (actor : Actor) → (nms : List NamedInbox) → ActorState ∞ (inbox-shape actor) (A actor) ((map shape nms) ++ pre actor) (post actor) → Actor add-references-to-actor actor nms m = record { inbox-shape = inbox-shape actor ; A = A actor ; references = nms ++ references actor ; pre = map shape nms ++ pre actor ; pre-eq-refs = trans (map-++-commute shape nms (references actor)) (cong (_++_ (map shape nms)) (pre-eq-refs actor)) ; post = post actor ; computation = m ; name = name actor } add-references-rewrite : (actor : Actor) → (nms : List NamedInbox) → {x : Message (inbox-shape actor)} → map shape nms ++ pre actor ≡ add-references (pre actor) x → ActorState ∞ (inbox-shape actor) (A actor) (add-references (pre actor) x) (post actor) → Actor add-references-rewrite actor nms {x} p m = record { inbox-shape = inbox-shape actor ; A = A actor ; references = nms ++ references actor ; pre = add-references (pre actor) x ; pre-eq-refs = trans (trans (map-++-commute shape nms (references actor)) (cong (_++_ (map shape nms)) (pre-eq-refs actor))) p ; post = post actor ; computation = m ; name = name actor } data SameValidityProof : Actor → Actor → Set₁ where AreSame : ∀ {A A' pre pre' post post'} {IS name references} {per per'} {computation computation'} → SameValidityProof (record { inbox-shape = IS ; A = A ; references = references ; pre = pre ; pre-eq-refs = per ; post = post ; computation = computation ; name = name }) (record { inbox-shape = IS ; A = A' ; references = references ; pre = pre' ; pre-eq-refs = per' ; post = post' ; computation = computation' ; name = name }) -- A proof of an actor being valid is also valid for another actor if -- * they have the same name -- * they have the same references -- * they have the same inbox type rewrap-valid-actor : {store : Store} → {actorPre : Actor} → {actorPost : Actor} → SameValidityProof actorPre actorPost → ValidActor store actorPre → ValidActor store actorPost rewrap-valid-actor AreSame va = record { actor-has-inbox = va .actor-has-inbox ; references-have-pointer = va .references-have-pointer } data ReferenceAdded (ref : NamedInbox) : Actor → Actor → Set₁ where RefAdded : ∀ {A A' pre pre' post post'} {IS name references} {per per'} {computation computation'} → ReferenceAdded ref (record { inbox-shape = IS ; A = A ; references = references ; pre = pre ; pre-eq-refs = per ; post = post ; computation = computation ; name = name }) (record { inbox-shape = IS ; A = A' ; references = ref ∷ references ; pre = pre' ; pre-eq-refs = per' ; post = post' ; computation = computation' ; name = name }) add-reference-valid : {store : Store} → {actorPre : Actor} → {actorPost : Actor} → {ref : NamedInbox} → ReferenceAdded ref actorPre actorPost → ValidActor store actorPre → reference-has-pointer store ref → ValidActor store actorPost add-reference-valid RefAdded va p = record { actor-has-inbox = va .actor-has-inbox ; references-have-pointer = p ∷ (va .references-have-pointer) } record ValidMessageList (store : Store) (S : InboxShape) : Set₁ where field inbox : Inbox S valid : All (message-valid store) inbox InboxUpdater : (store : Store) (IS : InboxShape) → Set₁ InboxUpdater store IS = ValidMessageList store IS → ValidMessageList store IS record UpdatedInbox (store : Store) {store' : Store} (original : Inboxes store') (name : Name) : Set₂ where field updated-inboxes : Inboxes store' inboxes-valid : InboxesValid store updated-inboxes others-unaffected : ∀ {name' IS' inb} → ¬ name ≡ name' → {p' : name' ↦ IS' ∈ store'} → InboxForPointer inb store' original p' → InboxForPointer inb store' updated-inboxes p' open ValidMessageList open UpdatedInbox open NameSupply -- Update one of the inboxes in a list of inboxes. -- All the inboxes have been proven to be valid in the context of a store, -- and the goal is to return a new list of inboxes which are also valid for the same store. -- We know what inbox to update via an index using the inbox name into the list. -- The update function receives both a list of messages from the inbox we pointed out, -- and a proof that all the messages are valid for the store. -- The update function returns a new list of the same type, -- and has to provide a proof that this list is also valid for the store update-inbox : {name : Name} → {IS : InboxShape} → (store : Store) → {store' : Store} → (inboxes : Inboxes store') → (InboxesValid store inboxes) → (name ↦ IS ∈ store') → (f : InboxUpdater store IS) → UpdatedInbox store inboxes name update-inbox _ _ [] () _ update-inbox {name} store {store'} (x ∷ inboxes) (px ∷ proofs) zero f = record { updated-inboxes = inbox updated ∷ inboxes ; inboxes-valid = (valid updated) ∷ proofs ; others-unaffected = unaffected } where updated = (f (record { inbox = x ; valid = px })) unaffected : ∀ {name' IS' inb} → ¬ name ≡ name' → {p' : name' ↦ IS' ∈ store'} → InboxForPointer inb store' (x ∷ inboxes) p' → InboxForPointer inb store' (inbox updated ∷ inboxes) p' unaffected pr zero = ⊥-elim (pr refl) unaffected pr (suc ifp) = suc ifp update-inbox {name} store {store'} (x ∷ inboxes) (px ∷ proofs) (suc p) f = record { updated-inboxes = x ∷ updated-inboxes updated ; inboxes-valid = px ∷ inboxes-valid updated ; others-unaffected = unaffected } where updated = (update-inbox store inboxes proofs p f) unaffected : ∀ {name' IS' inb} → ¬ name ≡ name' → {p' : name' ↦ IS' ∈ store'} → InboxForPointer inb store' (x ∷ inboxes) p' → InboxForPointer inb store' (x ∷ updated-inboxes updated) p' unaffected pr zero = zero unaffected pr (suc ifp) = suc (others-unaffected updated pr ifp) -- Move the actor that is at the top of the list, to the back of the list -- This is done to create a round-robin system for the actors, since run-env always picks the actor at the top -- Uses the insight that the order of the inboxes soes not correspond to the order of the Actors, -- and that moving an actor to the back doesn't change any of the proofs about actors being valid. top-actor-to-back : Env → Env top-actor-to-back env with (acts env) | (actors-valid env) top-actor-to-back env | [] | _ = env top-actor-to-back env | x ∷ acts | (y ∷ prfs) = record { acts = acts ++ [ x ]ˡ ; blocked = blocked env ; env-inboxes = env-inboxes env ; store = store env ; actors-valid = ++⁺ prfs [ y ]ᵃ ; blocked-valid = blocked-valid env ; messages-valid = messages-valid env ; name-supply = name-supply env ; blocked-no-progress = blocked-no-progress env } -- An actor is still valid if we add a new inbox to the store, as long as that name is not used in the store before valid-actor-suc : ∀ {store actor IS} → (ns : NameSupply store) → ValidActor store actor → ValidActor (inbox# ns .name [ IS ] ∷ store) actor valid-actor-suc ns va = let open ValidActor open _comp↦_∈_ in record { actor-has-inbox = suc {pr = ns .name-is-fresh (actor-has-inbox va)} (actor-has-inbox va) ; references-have-pointer = ∀map (λ p → suc-p (ns .name-is-fresh (actual-has-pointer p)) p) (references-have-pointer va) } valid-references-suc : ∀ {store references IS} → (ns : NameSupply store) → All (reference-has-pointer store) references → All (reference-has-pointer (inbox# (ns .name) [ IS ] ∷ store)) references valid-references-suc ns pointers = let open _comp↦_∈_ in ∀map (λ p → suc-p (ns .name-is-fresh (actual-has-pointer p)) p) pointers -- All the messages in an inbox are still valid if we add a new inbox to the store, as long as that name is not used in the store before messages-valid-suc : ∀ {store IS x} {inb : Inbox IS} → (ns : NameSupply store) → all-messages-valid store inb → all-messages-valid (inbox# ns .name [ x ] ∷ store) inb messages-valid-suc {store} {IS} {x} ns [] = [] messages-valid-suc {store} {IS} {x} {nx ∷ _} ns (px ∷ vi) = message-valid-suc nx px ∷ (messages-valid-suc ns vi) where open _comp↦_∈_ fields-valid-suc : ∀ {MT} {fields : All named-field-content MT} → FieldsHavePointer store fields → FieldsHavePointer (inbox# ns .name [ x ] ∷ store) fields fields-valid-suc [] = [] fields-valid-suc (FhpV ∷ valid) = FhpV ∷ fields-valid-suc valid fields-valid-suc (FhpR x ∷ valid) = FhpR (suc-p (ns .name-is-fresh (actual-has-pointer x)) x) ∷ (fields-valid-suc valid) message-valid-suc : (nx : NamedMessage IS) → message-valid store nx → message-valid (inbox# ns .name [ x ] ∷ store) nx message-valid-suc (NamedM x₁ x₂) px = fields-valid-suc px is-blocked-suc : ∀ {store actor IS} {inbs : Inboxes store} {inb : Inbox IS} → (ns : NameSupply store) → IsBlocked store inbs actor → IsBlocked (inbox# ns .name [ IS ] ∷ store) (inb ∷ inbs) actor is-blocked-suc ns (BlockedReturn at-return no-cont) = BlockedReturn at-return no-cont is-blocked-suc ns (BlockedReceive at-receive p inbox-for-pointer) = BlockedReceive at-receive (suc {pr = ns .name-is-fresh p} p) (suc inbox-for-pointer) is-blocked-suc ns (BlockedSelective at-selective p inb inbox-for-pointer filter-empty) = BlockedSelective at-selective (suc {pr = ns .name-is-fresh p} p) inb (suc inbox-for-pointer) filter-empty -- Add a new actor to the environment. -- The actor is added to the top of the list of actors. add-top : ∀ {IS A post} → ActorState ∞ IS A [] post → Env → Env add-top {IS} {A} {post} m env = record { acts = record { inbox-shape = IS ; A = A ; references = [] ; pre = [] ; pre-eq-refs = refl ; post = post ; computation = m ; name = env .name-supply .supply .name } ∷ acts env ; blocked = blocked env ; env-inboxes = [] ∷ env-inboxes env ; store = inbox# env .name-supply .supply .name [ IS ] ∷ store env ; actors-valid = record { actor-has-inbox = zero ; references-have-pointer = [] } ∷ ∀map (valid-actor-suc (env .name-supply .supply)) (actors-valid env) ; blocked-valid = ∀map (valid-actor-suc (env .name-supply .supply)) (blocked-valid env) ; messages-valid = [] ∷ map-suc (store env) (messages-valid env) (env .name-supply .supply) ; name-supply = env .name-supply .next IS ; blocked-no-progress = ∀map (is-blocked-suc (env .name-supply .supply)) (env .blocked-no-progress) } where -- ad-hoc ∀map, because we are not using All here map-suc : (store : Store) → {store' : Store} → {inbs : Inboxes store'} → InboxesValid store inbs → (ns : NameSupply store) → InboxesValid (inbox# ns .name [ IS ] ∷ store) inbs map-suc store [] _ = [] map-suc store (x ∷ valid) ns = messages-valid-suc ns x ∷ (map-suc store valid ns) record GetInbox (store : Store) {store' : Store} (inboxes : Inboxes store') {name : Name} {S : InboxShape} (p : name ↦ S ∈ store') : Set₂ where field messages : Inbox S valid : all-messages-valid store messages right-inbox : InboxForPointer messages store' inboxes p -- Get the messages of an inbox pointed to in the environment. -- This is just a simple lookup into the list of inboxes. get-inbox : ∀ {name IS} → (env : Env) → (p : name ↦ IS ∈ (store env)) → GetInbox (env .store) (env .env-inboxes) p get-inbox env point = loop (env-inboxes env) (messages-valid env) point where loop : {store store' : Store} → (inbs : Inboxes store') → InboxesValid store inbs → ∀ {name IS} → (p : name ↦ IS ∈ store') → GetInbox store inbs p loop _ [] () loop (x ∷ _) (px ∷ _) zero = record { messages = x ; valid = px ; right-inbox = zero } loop (_ ∷ inbs) (_ ∷ inb-valid) (suc point) = let rec = loop inbs inb-valid point open GetInbox in record { messages = rec .messages ; valid = rec .valid ; right-inbox = suc (rec .right-inbox) } open GetInbox record UnblockedActors {store store' : Store} {original : Inboxes store'} {n : Name} (updated : UpdatedInbox store original n) : Set₂ where field unblocked : List Actor unblocked-updated : All (λ act → n ≡ name act) unblocked unblocked-valid : All (ValidActor store) unblocked still-blocked : List Actor blocked-no-prog : All (IsBlocked store' (updated-inboxes updated)) still-blocked blocked-valid : All (ValidActor store) still-blocked open UnblockedActors unblock-actors : {store : Store} → {original : Inboxes store} → {n : Name} → (updated : UpdatedInbox store original n) → (blocked : List Actor) → All (ValidActor store) blocked → All (IsBlocked store original) blocked → UnblockedActors updated unblock-actors updated [] [] [] = record { unblocked = [] ; unblocked-updated = [] ; unblocked-valid = [] ; still-blocked = [] ; blocked-no-prog = [] ; blocked-valid = [] } unblock-actors {store} {original} {n} updated (x ∷ blckd) (v ∷ blckd-valid) (ib ∷ is-blocked) with (n ≟ (name x)) ... | yes p = let rec = unblock-actors updated blckd blckd-valid is-blocked in record { unblocked = x ∷ rec .unblocked ; unblocked-updated = p ∷ rec .unblocked-updated ; unblocked-valid = v ∷ rec .unblocked-valid ; still-blocked = rec .still-blocked ; blocked-no-prog = rec .blocked-no-prog ; blocked-valid = rec .blocked-valid } ... | no ¬p = let rec = unblock-actors updated blckd blckd-valid is-blocked in record { unblocked = rec .unblocked ; unblocked-updated = rec .unblocked-updated ; unblocked-valid = rec .unblocked-valid ; still-blocked = x ∷ rec .still-blocked ; blocked-no-prog = blocked-unaffected ib ∷ rec .blocked-no-prog ; blocked-valid = v ∷ rec .blocked-valid } where blocked-unaffected : IsBlocked store original x → IsBlocked store (updated-inboxes updated) x blocked-unaffected (BlockedReturn x y) = BlockedReturn x y blocked-unaffected (BlockedReceive x p y) = BlockedReceive x p (others-unaffected updated ¬p y) blocked-unaffected (BlockedSelective x p a b c) = BlockedSelective x p a (others-unaffected updated ¬p b) c update-inbox-env : ∀ {name IS} → (env : Env) → name ↦ IS ∈ (store env) → (f : ValidMessageList (store env) IS → ValidMessageList (store env) IS) → Env update-inbox-env {name} {IS} env p f = let updated = update-inbox (store env) (env-inboxes env) (messages-valid env) p f unblock-split = unblock-actors updated (blocked env) (blocked-valid env) (blocked-no-progress env) in record { acts = (unblocked unblock-split) ++ acts env ; blocked = still-blocked unblock-split ; env-inboxes = updated-inboxes updated ; store = store env ; actors-valid = ++⁺ (unblock-split .unblocked-valid) (env .actors-valid) ; blocked-valid = unblock-split .blocked-valid ; messages-valid = inboxes-valid updated ; name-supply = env .name-supply ; blocked-no-progress = unblock-split .blocked-no-prog } record FoundReference (store : Store) (S : InboxShape) : Set₂ where field name : Name reference : name comp↦ S ∈ store lookup-reference : ∀ {store ToIS} → (pre : TypingContext) → (refs : List NamedInbox) → All (reference-has-pointer store) refs → map shape refs ≡ pre → ToIS ∈ pre → FoundReference store ToIS lookup-reference [] refs prfs eq () lookup-reference (x ∷ pre₁) [] prfs () Z lookup-reference (x ∷ pre₁) [] prfs () (S px) lookup-reference _ (inbox# name [ shape ] ∷ refs) (reference ∷ prfs) refl Z = record { name = name ; reference = reference } lookup-reference _ (_ ∷ refs) (_ ∷ prfs) refl (S px) = lookup-reference _ refs prfs refl px -- looks up the pointer for one of the references known by an actor lookup-reference-act : ∀ {store actor ToIS} → ValidActor store actor → ToIS ∈ (pre actor) → FoundReference store ToIS lookup-reference-act {store} {actor} {ToIS} va ref = lookup-reference (pre actor) (Actor.references actor) (ValidActor.references-have-pointer va) (pre-eq-refs actor) ref open _comp↦_∈_ open FoundReference -- Extract the found pointer underlying-pointer : ∀ {IS store} → (ref : FoundReference store IS) → (name ref ↦ actual (reference ref) ∈ store ) underlying-pointer ref = actual-has-pointer (reference ref) translate-message-pointer : ∀ {ToIS A store} → (w : FoundReference store ToIS) → A ∈ ToIS → A ∈ (actual (reference w)) translate-message-pointer w x = translate-⊆ (actual-handles-wanted (reference w)) x record LiftedReferences (lss gss : TypingContext) (references : List NamedInbox) : Set₂ where field subset-inbox : lss ⊆ gss contained : List NamedInbox subset : contained ⊆ references contained-eq-inboxes : map shape contained ≡ lss open LiftedReferences -- Convert a subset for preconditions to a subset for references lift-references : ∀ {lss gss} → lss ⊆ gss → (references : List NamedInbox) → map shape references ≡ gss → LiftedReferences lss gss references lift-references [] refs refl = record { subset-inbox = [] ; contained = [] ; subset = [] ; contained-eq-inboxes = refl } lift-references (_∷_ {y} {xs} x₁ subs) refs refl with (lift-references subs refs refl) ... | q = record { subset-inbox = x₁ ∷ subs ; contained = contained-el ∷ contained q ; subset = (translate-∈ x₁ refs shape refl) ∷ (subset q) ; contained-eq-inboxes = combine contained-el-shape y (map shape (contained q)) xs (sym contained-el-ok) (contained-eq-inboxes q) } where contained-el : NamedInbox contained-el = lookup-parallel x₁ refs shape refl contained-el-shape = shape contained-el contained-el-ok : y ≡ contained-el-shape contained-el-ok = lookup-parallel-≡ x₁ refs shape refl combine : (a b : InboxShape) → (as bs : TypingContext) → (a ≡ b) → (as ≡ bs) → (a ∷ as ≡ b ∷ bs) combine a .a as .as refl refl = refl data LiftActor : Actor → Actor → Set₂ where CanBeLifted : ∀ {A A' post post'} {IS name references} {lss gss} {per} {computation computation'} → (lr : LiftedReferences lss gss references) → LiftActor (record { inbox-shape = IS ; A = A ; references = references ; pre = gss ; pre-eq-refs = per ; post = post ; computation = computation ; name = name }) (record { inbox-shape = IS ; A = A' ; references = lr .contained ; pre = lss ; pre-eq-refs = lr .contained-eq-inboxes ; post = post' ; computation = computation' ; name = name }) lift-valid-actor : ∀ {store} {act act' : Actor} → LiftActor act act' → ValidActor store act → ValidActor store act' lift-valid-actor (CanBeLifted lr) va = record { actor-has-inbox = va .actor-has-inbox ; references-have-pointer = All-⊆ (lr .subset) (va .references-have-pointer) } -- We can replace the actors in an environment if they all are valid for the current store. replace-actors : (env : Env) → (actors : List Actor) → All (ValidActor (store env)) actors → Env replace-actors env actors actorsValid = record { acts = actors ; blocked = env .blocked ; env-inboxes = env .env-inboxes ; store = env .store ; actors-valid = actorsValid ; blocked-valid = env .blocked-valid ; messages-valid = env .messages-valid ; name-supply = env .name-supply ; blocked-no-progress = env .blocked-no-progress } replace-focused : {act : Actor} → (env : Env) → Focus act env → (act' : Actor) → (valid' : ValidActor (env .store) act') → Env replace-focused env@record { acts = _ ∷ rest ; actors-valid = _ ∷ rest-valid } Focused act' valid' = replace-actors env (act' ∷ rest) (valid' ∷ rest-valid) block-focused : {act : Actor} → (env : Env) → Focus act env → IsBlocked (env .store) (env .env-inboxes) act → Env block-focused env@record { acts = actor ∷ rest ; blocked = blocked ; actors-valid = actor-valid ∷ rest-valid ; blocked-valid = blocked-valid } Focused blckd = record { acts = rest ; blocked = actor ∷ blocked ; store = env .store ; env-inboxes = env .env-inboxes ; name-supply = env .name-supply ; actors-valid = rest-valid ; blocked-valid = actor-valid ∷ blocked-valid ; messages-valid = env .messages-valid ; blocked-no-progress = blckd ∷ env .blocked-no-progress } -- Takes a named message and a proof that the named message is valid for the store. -- Values are valid for any store and references need a proof that the pointer is valid. add-message : {S : InboxShape} → {store : Store} → (message : NamedMessage S) → message-valid store message → (ValidMessageList store S → ValidMessageList store S) add-message message valid vml = record { inbox = inbox vml ++ [ message ]ˡ ; valid = ++⁺ (ValidMessageList.valid vml) [ valid ]ᵃ } -- Removes the next message from an inbox. -- This is a no-op if there are no messages in the inbox. remove-message : {S : InboxShape} → {store : Store} → (ValidMessageList store S → ValidMessageList store S) remove-message vml = record { inbox = drop 1 (inbox vml) ; valid = drop⁺ 1 (ValidMessageList.valid vml) } name-fields : ∀ {MT store} → (pre : TypingContext) → (refs : List NamedInbox) → All (reference-has-pointer store) refs → All (send-field-content pre) MT → map shape refs ≡ pre → All named-field-content MT name-fields pre refs rhp [] eq = [] name-fields _ refs rhp (_∷_ {ValueType x} (lift lower) sfc) refl = lower ∷ (name-fields _ refs rhp sfc refl) name-fields {store = store} _ refs rhp (_∷_ {ReferenceType x} px sfc) refl = name (lookup-reference _ refs rhp refl (_⊢>:_.actual-is-sendable px)) ∷ (name-fields _ refs rhp sfc refl) name-fields-act : ∀ {MT} store → ∀ actor → All (send-field-content (pre actor)) MT → ValidActor store actor → All named-field-content MT name-fields-act store actor sfc valid = name-fields (pre actor) (Actor.references actor) (references-have-pointer valid) sfc (pre-eq-refs actor) unname-field : ∀ {x} → named-field-content x → receive-field-content x unname-field {ValueType x₁} nfc = nfc unname-field {ReferenceType x₁} nfc = _ extract-inboxes : ∀ {MT} → All named-field-content MT → List NamedInbox extract-inboxes [] = [] extract-inboxes (_∷_ {ValueType _} _ ps) = extract-inboxes ps extract-inboxes (_∷_ {ReferenceType x} name ps) = inbox# name [ x ] ∷ extract-inboxes ps named-inboxes : ∀ {S} → (nm : NamedMessage S) → List NamedInbox named-inboxes (NamedM x x₁) = extract-inboxes x₁ reference-names : {MT : MessageType} → All named-field-content MT → List Name reference-names [] = [] reference-names (_∷_ {ValueType x} px ps) = reference-names ps reference-names (_∷_ {ReferenceType x} name ps) = name ∷ reference-names ps ++-diff : (a b c : List InboxShape) → a ≡ b → a ++ c ≡ b ++ c ++-diff [] .[] c refl = refl ++-diff (x ∷ a) .(x ∷ a) c refl = refl add-fields++ : ∀ MT → (x₁ : All named-field-content MT) → map shape (extract-inboxes x₁) ≡ extract-references MT add-fields++ [] [] = refl add-fields++ (ValueType x ∷ MT) (px ∷ x₁) = add-fields++ MT x₁ add-fields++ (ReferenceType x ∷ MT) (px ∷ x₁) = cong (_∷_ x) (add-fields++ MT x₁) add-references++ : ∀ {S store} → (nm : NamedMessage S) → message-valid store nm → ∀ w → map shape (named-inboxes nm) ++ w ≡ add-references w (unname-message nm) add-references++ msg@(NamedM {MT} x x₁) p w = halp (add-fields++ MT x₁) where halp : map shape (extract-inboxes x₁) ≡ extract-references MT → map shape (extract-inboxes x₁) ++ w ≡ extract-references MT ++ w halp p = ++-diff (map shape (extract-inboxes x₁)) (extract-references MT) w p valid++ : ∀ {S store} → (nm : NamedMessage S) → message-valid store nm → ∀ {w} → All (reference-has-pointer store) w → All (reference-has-pointer store) (named-inboxes nm ++ w) valid++ (NamedM x x₁) v = valid-fields v where valid-fields : ∀ {MT store} → {fields : All named-field-content MT} → FieldsHavePointer store fields → ∀ {p} → All (reference-has-pointer store) p → All (reference-has-pointer store) (extract-inboxes fields ++ p) valid-fields [] ps = ps valid-fields (FhpV ∷ fhp) ps = valid-fields fhp ps valid-fields (FhpR px ∷ fhp) ps = px ∷ (valid-fields fhp ps) open _⊢>:_ compatible-handles : ∀ store x refs (px : (map shape refs) ⊢>: x) (w : FoundReference store (actual px)) → x ⊆ actual (reference w) compatible-handles store x refs px w = let a = actual-handles-requested px b = actual-handles-wanted (reference w) in ⊆-trans a b make-pointer-compatible : ∀ store x refs (px : (map shape refs) ⊢>: x) → (All (reference-has-pointer store) refs) → (w : FoundReference store (actual px)) → name w comp↦ x ∈ store make-pointer-compatible store x refs px rhp w = [p: actual-has-pointer (reference w) ][handles: compatible-handles store x refs px w ] open FieldsHavePointer make-pointers-compatible : ∀ {MT} store pre refs (eq : map shape refs ≡ pre) (fields : All (send-field-content pre) MT) (rhp : All (reference-has-pointer store) refs) → FieldsHavePointer store (name-fields pre refs rhp fields eq) make-pointers-compatible store pre refs eq [] rhp = [] make-pointers-compatible store _ refs refl (_∷_ {ValueType x} px fields) rhp = FhpV ∷ make-pointers-compatible store _ refs refl fields rhp make-pointers-compatible store _ refs refl (_∷_ {ReferenceType x} px fields) rhp = let foundFw = lookup-reference _ refs rhp refl (actual-is-sendable px) in FhpR (make-pointer-compatible store x refs px rhp foundFw) ∷ (make-pointers-compatible store _ refs refl fields rhp) -- Removes the next message from an inbox. -- This is a no-op if there are no messages in the inbox. remove-found-message : {S : InboxShape} → {store : Store} → (filter : MessageFilter S) → (ValidMessageList store S → ValidMessageList store S) remove-found-message f record { inbox = [] ; valid = [] } = record { inbox = [] ; valid = [] } remove-found-message {s} {store} f record { inbox = (x ∷ inbox₁) ; valid = vx ∷ valid₁ } with (f (unname-message x)) ... | false = let vml = remove-found-message f (record { inbox = inbox₁ ; valid = valid₁ }) open ValidMessageList in record { inbox = x ∷ vml .inbox ; valid = vx ∷ vml .valid } ... | true = record { inbox = inbox₁ ; valid = valid₁ }
{ "alphanum_fraction": 0.5941185672, "avg_line_length": 47.3555555556, "ext": "agda", "hexsha": "320e1aaf078995cdd5bddd38d5e397b0d12d41ae", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Zalastax/singly-typed-actors", "max_forks_repo_path": "src/Selective/EnvironmentOperations.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Zalastax/singly-typed-actors", "max_issues_repo_path": "src/Selective/EnvironmentOperations.agda", "max_line_length": 194, "max_stars_count": 1, "max_stars_repo_head_hexsha": "ae541df13d069df4eb1464f29fbaa9804aad439f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Zalastax/thesis", "max_stars_repo_path": "src/Selective/EnvironmentOperations.agda", "max_stars_repo_stars_event_max_datetime": "2018-02-02T16:44:43.000Z", "max_stars_repo_stars_event_min_datetime": "2018-02-02T16:44:43.000Z", "num_tokens": 8521, "size": 31965 }
{-# OPTIONS --cubical --safe #-} module Harmony where open import Data.Bool using (Bool; true; false; if_then_else_; _∨_; not; _∧_) open import Data.Fin using (#_; toℕ) renaming (zero to fz; suc to fs) open import Data.List using (List; map; []; _∷_; concatMap; foldr; head; zip; null) open import Data.Maybe using (fromMaybe; is-nothing; Maybe; just; nothing) open import Data.Nat using (ℕ; suc; _∸_; _<ᵇ_) open import Data.Nat.DivMod using (_mod_; _div_) open import Data.Product using (_×_; _,_; proj₁; proj₂; uncurry) open import Data.Vec using (Vec; toList; []; _∷_) open import Function using (_∘_) open import BitVec using (BitVec; empty; insert; elements; _∩_; _∈_) open import Counterpoint open import Diatonic using (DiatonicDegree; thirdUp; _≡ᵈ_; degree→PC; major; pitch→DegreeCMajor) open import Interval open import Music open import Note open import Pitch hiding (I) open import Util using (filter; concatMaybe) -- either 0 or 1 pitch class pointToPC : Point → List PC pointToPC (tone p) = pitchToClass p ∷ [] pointToPC (hold p) = pitchToClass p ∷ [] pointToPC rest = [] chordToPCes : {n : ℕ} → Chord n → List PC chordToPCes (chord ps) = concatMap pointToPC (toList ps) pitchClassListToSet : List PC → PCSet pitchClassListToSet = foldr insert empty pitchClassSetToList : PCSet → List PC pitchClassSetToList ps = fn 0 (toList ps) where fn : ℕ → List Bool → List PC fn i [] = [] fn i (false ∷ bs) = fn (suc i) bs fn i (true ∷ bs) = i mod s12 ∷ fn (suc i) bs -- Primary chords, assuming the tonic is pitch class 0. I-maj I-min IV-maj V-maj : PCSet I-maj = pitchClassListToSet (# 0 ∷ # 4 ∷ # 7 ∷ []) I-min = pitchClassListToSet (# 0 ∷ # 3 ∷ # 7 ∷ []) IV-maj = pitchClassListToSet (# 0 ∷ # 5 ∷ # 9 ∷ []) V-maj = pitchClassListToSet (# 2 ∷ # 7 ∷ # 11 ∷ []) -- Triads, without quality data Triad : Set where I : Triad II : Triad III : Triad IV : Triad V : Triad VI : Triad VII : Triad --data Triad : Set where -- I : Triad; II : Triad; III : Triad; IV : Triad; V : Triad; VI : Triad; VII : Triad allTriads : List Triad allTriads = I ∷ II ∷ III ∷ IV ∷ V ∷ VI ∷ VII ∷ [] triadRoot : Triad → DiatonicDegree triadRoot I = (# 0) triadRoot II = (# 1) triadRoot III = (# 2) triadRoot IV = (# 3) triadRoot V = (# 4) triadRoot VI = (# 5) triadRoot VII = (# 6) rootTriad : DiatonicDegree → Triad rootTriad fz = I rootTriad ((fs fz)) = II rootTriad ((fs (fs fz))) = III rootTriad ((fs (fs (fs fz)))) = IV rootTriad ((fs (fs (fs (fs fz))))) = V rootTriad ((fs (fs (fs (fs (fs fz)))))) = VI rootTriad ((fs (fs (fs (fs (fs (fs fz))))))) = VII triadDegrees : Triad → Vec DiatonicDegree 3 triadDegrees t = let root = triadRoot t third = thirdUp root fifth = thirdUp third in root ∷ third ∷ fifth ∷ [] infix 4 _≡ᵗ_ _≡ᵗ_ : Triad → Triad → Bool t ≡ᵗ u = triadRoot t ≡ᵈ triadRoot u TriadSet : Set TriadSet = BitVec s7 triadListToSet : List Triad → TriadSet triadListToSet [] = empty triadListToSet (t ∷ ts) = insert (triadRoot t) (triadListToSet ts) triadSetToList : TriadSet → List Triad triadSetToList ts = map rootTriad (elements ts) containingTriads : DiatonicDegree → List Triad containingTriads fz = I ∷ IV ∷ VI ∷ [] containingTriads ((fs fz)) = II ∷ V ∷ VII ∷ [] containingTriads ((fs (fs fz))) = III ∷ VI ∷ I ∷ [] containingTriads ((fs (fs (fs fz)))) = IV ∷ VII ∷ II ∷ [] containingTriads ((fs (fs (fs (fs fz))))) = V ∷ I ∷ III ∷ [] containingTriads ((fs (fs (fs (fs (fs fz)))))) = VI ∷ II ∷ IV ∷ [] containingTriads ((fs (fs (fs (fs (fs (fs fz))))))) = VII ∷ III ∷ V ∷ [] -- from Table of Usual Root Progressions (Major Mode), Harmony (Piston 5e), page 23 record NextTriad : Set where constructor nextTriad field usual : List Triad sometimes : List Triad rare : List Triad open NextTriad rootProgression : Triad → NextTriad rootProgression I = nextTriad (IV ∷ V ∷ []) (VI ∷ []) (II ∷ III ∷ []) rootProgression II = nextTriad (V ∷ []) (IV ∷ VI ∷ []) (I ∷ III ∷ []) rootProgression III = nextTriad (VI ∷ []) (IV ∷ []) (I ∷ II ∷ V ∷ []) rootProgression IV = nextTriad (V ∷ []) (I ∷ II ∷ []) (III ∷ VI ∷ []) rootProgression V = nextTriad (I ∷ []) (IV ∷ VI ∷ []) (II ∷ III ∷ []) rootProgression VI = nextTriad (II ∷ V ∷ []) (III ∷ IV ∷ []) (I ∷ []) rootProgression VII = nextTriad (I ∷ III ∷ []) (VI ∷ []) (II ∷ IV ∷ V ∷ []) previousTriads : Triad → List Triad previousTriads I = V ∷ IV ∷ VII ∷ [] previousTriads II = VI ∷ IV ∷ [] previousTriads III = VI ∷ VII ∷ [] previousTriads IV = I ∷ V ∷ II ∷ III ∷ [] previousTriads V = I ∷ IV ∷ II ∷ VI ∷ [] previousTriads VI = IV ∷ I ∷ II ∷ V ∷ VII ∷ [] previousTriads VII = [] harmonizations : {n : ℕ} → Vec DiatonicDegree n → List (Vec Triad n) harmonizations [] = [] harmonizations (d ∷ []) = map (_∷ []) (containingTriads d) harmonizations (d ∷ d' ∷ ds) = let tss = harmonizations (d' ∷ ds) dTriads = containingTriads d in concatMap (λ t → concatMaybe (map (prependTriad t) tss)) dTriads where prevOk : Triad → Triad → Bool prevOk t x = (triadRoot t) ∈ triadListToSet (previousTriads x) prependTriad : {n : ℕ} → Triad → Vec Triad (suc n) → Maybe (Vec Triad (suc (suc n))) prependTriad t ts = if prevOk t (Data.Vec.head ts) then just (t ∷ ts) else nothing halfCadence : {n : ℕ} → Vec Triad n → Bool halfCadence [] = false halfCadence (t ∷ []) = t ≡ᵗ V halfCadence (_ ∷ t ∷ ts) = halfCadence (t ∷ ts) -- Given a pitch p and a diatontic degree d, return a pitch that -- has degree d and is 1-2 octaves lower than p. pitchLower : Pitch → DiatonicDegree → Pitch pitchLower p d = let (c , o) = absoluteToRelative p c' = degree→PC major d in relativeToAbsolute (c' , o ∸ 2) -- Given a soporano voice s a pitch and the other voices -- as diatonic degrees of a major scale, voice the -- accompaniment in close position. voiceChord : Pitch → Vec DiatonicDegree 3 → Vec Pitch 3 voiceChord s (a ∷ t ∷ b ∷ []) = let (s' , o) = absoluteToRelative s a' = degree→PC major a t' = degree→PC major t b' = degree→PC major b ao = downOctave a' s' o to = downOctave t' a' ao bo = downOctave b' t' to in relativeToAbsolute (a' , ao) ∷ relativeToAbsolute (t' , to) ∷ relativeToAbsolute (b' , bo) ∷ [] where downOctave : PC → PC → Octave → Octave downOctave pc₁ pc₂ o = if toℕ pc₁ <ᵇ toℕ pc₂ then o else (o ∸ 1) -- Given a soprano pitch p and a triad harmonization t, -- generate a list of possible bass notes. -- Assumes p is in t. Only the root of the triad is -- allowed to be doubled. -- Each bass note is pitched 1-2 octaves below p. bassNotes : Pitch → Triad → List Pitch bassNotes p t = let sop = pitch→DegreeCMajor p root = triadRoot t ds = toList (triadDegrees t) ds' = filter (λ d → (sop ≡ᵈ root) ∨ not (sop ≡ᵈ d)) ds in map (pitchLower p) ds' -- Given a soprano pitch p and a triad harmonization t, -- generate a harmonizing chord in root position. -- Assumes p is in t. Only the root of the triad is -- allowed to be doubled. -- Each bass note is pitched 1-2 octaves below p. -- Alto and Tenor fit inside. -- Currently root or third is preferred for alto. harmonizingChord : Pitch → Triad → Vec Pitch 3 harmonizingChord p t = let sop = pitch→DegreeCMajor p root = triadRoot t third = thirdUp root fifth = thirdUp third alto = if sop ≡ᵈ root then third else root tenor = if sop ≡ᵈ fifth then third else fifth in voiceChord p (alto ∷ tenor ∷ root ∷ []) where remove : DiatonicDegree → Vec DiatonicDegree 3 → Vec DiatonicDegree 2 remove sop (d ∷ d₁ ∷ d₂ ∷ []) = if d ≡ᵈ sop then d₁ ∷ d₂ ∷ [] else (if d₁ ≡ᵈ sop then d ∷ d₂ ∷ [] else d ∷ d₁ ∷ []) -- Create 4 part harmonizations ending in V for a melody in C major. voicedHarmonizations : {n : ℕ} → Vec Pitch n → List (Vec (Vec Pitch 4) n) voicedHarmonizations {n} ps = let ds = Data.Vec.map pitch→DegreeCMajor ps hs : List (Vec Triad n) hs = filter halfCadence (harmonizations ds) in map (λ ts → Data.Vec.map (λ pt → proj₁ pt ∷ harmonizingChord (proj₁ pt) (proj₂ pt)) (Data.Vec.zip ps ts)) hs -- Check interval between each pair of voices. intervalsOkFilter : Vec Pitch 4 → Bool intervalsOkFilter (s ∷ a ∷ t ∷ b ∷ []) = null (concatMaybe (map (intervalCheck ∘ toPitchInterval) -- ((s , a) ∷ (s , t) ∷ (s , b) ∷ (a , t) ∷ (a , b) ∷ (t , b) ∷ []))) ((s , a) ∷ (s , b) ∷ (s , t) ∷ []))) filterIntervalsOk : {n : ℕ} → List (Vec (Vec Pitch 4) n) → List (Vec (Vec Pitch 4) n) filterIntervalsOk xs = let f : List (Vec Pitch 4) → Bool f xs = foldr _∧_ true (map intervalsOkFilter xs) in filter (f ∘ toList) xs motionErrors : {n : ℕ} → Vec (Vec Pitch 4) n → List MotionError motionErrors xs = let ss = Data.Vec.map (Data.Vec.head) xs as = Data.Vec.map (Data.Vec.head ∘ Data.Vec.tail) xs ts = Data.Vec.map (Data.Vec.head ∘ Data.Vec.tail ∘ Data.Vec.tail) xs bs = Data.Vec.map (Data.Vec.head ∘ Data.Vec.tail ∘ Data.Vec.tail ∘ Data.Vec.tail) xs sas = map toPitchInterval (toList (Data.Vec.zip as ss)) sts = map toPitchInterval (toList (Data.Vec.zip ts ss)) sbs = map toPitchInterval (toList (Data.Vec.zip bs ss)) ats = map toPitchInterval (toList (Data.Vec.zip ts as)) abs = map toPitchInterval (toList (Data.Vec.zip bs as)) tbs = map toPitchInterval (toList (Data.Vec.zip bs ts)) in concatMap checkMotion (sas ∷ sts ∷ sbs ∷ ats ∷ abs ∷ tbs ∷ []) --filterSBMotionOk : {n : ℕ} → List (Vec (Vec Pitch 4) n) → List (Vec (Vec Pitch 4) n) --filterSBMotionOk = filter motionOkFilter -- Given a soprano line with harmonization, generate -- a list of possible bass lines 1-1 with soprano notes. -- The SB counterpoint must satisfy 1st species -- interval and motion rules. bassLines : List (Pitch × Triad) → List (List Pitch) -- We need to make the base case a singleton list of an empty list for -- the general case to work. Possibly look into modifying the general -- case to handle a base case of an empty list. bassLines [] = [] ∷ [] bassLines ((sop , triad) ∷ pts) = let pss = bassLines pts basses = bassNotes sop triad intervalOkSBs : List PitchInterval -- list of bass notes with interval (to sop) that pass intervalCheck intervalOkSBs = filter (is-nothing ∘ intervalCheck) (map (toPitchInterval ∘ (_, sop)) basses) intervalOkBs = map proj₁ intervalOkSBs intervalOkBassLines = concatMap (λ ps → (map (_∷ ps) intervalOkBs)) pss in filter (mCheck sop (Data.Maybe.map proj₁ (head pts))) intervalOkBassLines where -- Given a soprano pitch, possibly a second soprano pitch and a list of -- bass pitches, if the second soprano pitch exists and there are at -- least two bass pitches, check that the motion from the first SB pair to -- the second is allowed. If there aren't two SB pairs, return true. mCheck : Pitch → Maybe Pitch → List Pitch → Bool mCheck _ nothing _ = true mCheck _ (just _) [] = true mCheck _ (just _) (_ ∷ []) = true mCheck s₁ (just s₂) (b₁ ∷ b₂ ∷ _) = let sb₁ = toPitchInterval (b₁ , s₁) sb₂ = toPitchInterval (b₂ , s₂) in (is-nothing ∘ uncurry motionCheck) (sb₁ , sb₂) -- Given a soprano line with harmonization, generate -- a list of possible triads 1-1 with soprano notes. -- All pairwise counterpoint must satisfy 1st species -- interval and motion rules. chordProg : List (Pitch × Triad) → List (List Pitch) -- We need to make the base case a singleton list of an empty list for -- the general case to work. Possibly look into modifying the general -- case to handle a base case of an empty list. chordProg [] = [] ∷ [] chordProg ((sop , triad) ∷ pts) = let pss = chordProg pts basses = bassNotes sop triad intervalOkSBs : List PitchInterval -- list of bass notes with interval (to sop) that pass intervalCheck intervalOkSBs = filter (is-nothing ∘ intervalCheck) (map (toPitchInterval ∘ (_, sop)) basses) intervalOkBs = map proj₁ intervalOkSBs intervalOkBassLines = concatMap (λ ps → (map (_∷ ps) intervalOkBs)) pss in filter (mCheck sop (Data.Maybe.map proj₁ (head pts))) intervalOkBassLines where -- Given a soprano pitch, possibly a second soprano pitch and a list of -- bass pitches, if the second soprano pitch exists and there are at -- least two bass pitches, check that the motion from the first SB pair to -- the second is allowed. If there aren't two SB pairs, return true. mCheck : Pitch → Maybe Pitch → List Pitch → Bool mCheck _ nothing _ = true mCheck _ (just _) [] = true mCheck _ (just _) (_ ∷ []) = true mCheck s₁ (just s₂) (b₁ ∷ b₂ ∷ _) = let sb₁ = toPitchInterval (b₁ , s₁) sb₂ = toPitchInterval (b₂ , s₂) in (is-nothing ∘ uncurry motionCheck) (sb₁ , sb₂)
{ "alphanum_fraction": 0.6145825575, "avg_line_length": 41.3138461538, "ext": "agda", "hexsha": "a91bbd7a3e261c2dd8a1acfbcd4350ee9d7fd891", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z", "max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z", "max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "halfaya/MusicTools", "max_forks_repo_path": "agda/Harmony.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z", "max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "halfaya/MusicTools", "max_issues_repo_path": "agda/Harmony.agda", "max_line_length": 109, "max_stars_count": 28, "max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "halfaya/MusicTools", "max_stars_repo_path": "agda/Harmony.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z", "max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z", "num_tokens": 4449, "size": 13427 }
{-# OPTIONS --verbose=10 #-} module lemmas where open import Data.Nat import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; trans; sym; cong; cong-app; subst) +-suc : (n₁ n₂ : ℕ) -> (n₁ + (1 + n₂)) ≡ (1 + (n₁ + n₂)) +-suc zero n2 = refl +-suc (suc n1) n2 rewrite +-suc n1 n2 = refl
{ "alphanum_fraction": 0.6055900621, "avg_line_length": 26.8333333333, "ext": "agda", "hexsha": "65fd10c7d9defdca94b6c56046c1073e05fe2817", "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": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b", "max_forks_repo_licenses": [ "Apache-2.0" ], "max_forks_repo_name": "hablapps/safeoptics", "max_forks_repo_path": "src/main/agda/lemmas.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b", "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": "hablapps/safeoptics", "max_issues_repo_path": "src/main/agda/lemmas.agda", "max_line_length": 62, "max_stars_count": null, "max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "hablapps/safeoptics", "max_stars_repo_path": "src/main/agda/lemmas.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 121, "size": 322 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.FunctionOver open import cohomology.Theory {- Cohomology groups are independent of basepoint, and the action of - the cohomology is independent of the basepoint-preservation path -} module cohomology.BaseIndependence {i} (CT : CohomologyTheory i) where open CohomologyTheory CT C-base-indep : (n : ℤ) {A : Type i} (a₀ a₁ : A) → C n (A , a₀) ≃ᴳ C n (A , a₁) C-base-indep n a₀ a₁ = C-Susp n (_ , a₁) ∘eᴳ (C-Susp n (_ , a₀))⁻¹ᴳ CF-base-indep : (n : ℤ) {X Y : Ptd i} (f : fst X → fst Y) (p₁ p₂ : f (snd X) == snd Y) → CF-hom n (f , p₁) == CF-hom n (f , p₂) CF-base-indep n {X} {Y} f p₁ p₂ = transport (λ q → CF-hom n (f , p₁) == CF-hom n (f , p₂) [ uncurry _→ᴳ_ ↓ q ]) (!-inv-l (pair×= (group-ua (C-Susp n Y)) (group-ua (C-Susp n X)))) (!ᵈ (C-Susp-↓ n (f , p₁)) ∙ᵈ C-Susp-↓ n (f , p₂)) CF-λ= : (n : ℤ) {X Y : Ptd i} {f g : fst (X ⊙→ Y)} → (∀ x → fst f x == fst g x) → CF-hom n f == CF-hom n g CF-λ= n h = CF-base-indep n _ _ _ ∙ ap (CF-hom n) (⊙λ= h idp) CF-↓dom= : (n : ℤ) {X Y Z : Ptd i} {f : fst (X ⊙→ Y)} {g : fst (X ⊙→ Z)} {p : Y == Z} → fst f == fst g [ (λ V → fst X → fst V) ↓ p ] → CF-hom n f == CF-hom n g [ (λ G → G →ᴳ C n X) ↓ ap (C n) p ] CF-↓dom= n {p = idp} r = CF-base-indep n _ _ _ ∙ ap (CF-hom n) (pair= r (from-transp! _ _ idp)) CF-↓cod= : (n : ℤ) {X Y Z : Ptd i} {f : fst (X ⊙→ Z)} {g : fst (Y ⊙→ Z)} {p : X == Y} → fst f == fst g [ (λ U → fst U → fst Z) ↓ p ] → CF-hom n f == CF-hom n g [ (λ G → C n Z →ᴳ G) ↓ ap (C n) p ] CF-↓cod= n {p = idp} r = CF-base-indep n _ _ _ ∙ ap (CF-hom n) (pair= r (from-transp! _ _ idp))
{ "alphanum_fraction": 0.5185185185, "avg_line_length": 36.6, "ext": "agda", "hexsha": "40f3f6bd15acc0e32002c6022779be5833332d7c", "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": "cohomology/BaseIndependence.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": "cohomology/BaseIndependence.agda", "max_line_length": 72, "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": "cohomology/BaseIndependence.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": 768, "size": 1647 }
module PatternSynonymOverapplied2 where data Nat : Set where zero : Nat suc : Nat -> Nat pattern suc' x = suc x f : Nat -> Nat f zero = zero f (suc' m n) = n
{ "alphanum_fraction": 0.6198830409, "avg_line_length": 15.5454545455, "ext": "agda", "hexsha": "89e7b3e43a9d4f57b90c16195a8d7755781f8a06", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/PatternSynonymOverapplied2.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/PatternSynonymOverapplied2.agda", "max_line_length": 39, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/PatternSynonymOverapplied2.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": 59, "size": 171 }
module Structure.Function.Linear where import Lvl open import Logic open import Logic.Propositional open import Relator.Equals open import Relator.Equals.Proofs open import Type -- TODO: Remove this module _ {ℓ₁}{ℓ₂}{ℓ₃} {V₁ : Type{ℓ₁}} {V₂ : Type{ℓ₂}} {S : Type{ℓ₃}} where record LinearMap (_+₁_ : V₁ → V₁ → V₁) (_⋅₁_ : S → V₁ → V₁) (_+₂_ : V₂ → V₂ → V₂) (_⋅₂_ : S → V₂ → V₂) (f : V₁ → V₂) : Stmt{ℓ₁ Lvl.⊔ ℓ₂ Lvl.⊔ ℓ₃} where field additivity : ∀{v₁ v₂ : V₁} → (f(v₁ +₁ v₂) ≡ f(v₁) +₂ f(v₂)) homogeneity1 : ∀{s : S} → ∀{v : V₁} → (f(s ⋅₁ v) ≡ s ⋅₂ f(v))
{ "alphanum_fraction": 0.5849056604, "avg_line_length": 36.4375, "ext": "agda", "hexsha": "f6b6bcad0cdc98ba9b7c7402158293bccd0aea73", "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/Function/Linear.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/Function/Linear.agda", "max_line_length": 155, "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/Function/Linear.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": 274, "size": 583 }
module Relation.Ternary.Separation.Monad.Identity where open import Level open import Function open import Function using (_∘_; case_of_) open import Relation.Binary.PropositionalEquality open import Relation.Unary open import Relation.Unary.PredicateTransformer hiding (_⊔_) open import Relation.Ternary.Separation open import Relation.Ternary.Separation.Monad open import Relation.Ternary.Separation.Morphisms open import Data.Unit open Monads module Identity {ℓ} {C : Set ℓ} {u} {{r : RawSep C}} {{us : IsUnitalSep r u}} where Id : ∀ {ℓ} → Pt C ℓ Id P = P instance id-monad : Monad ⊤ ℓ (λ _ _ → Id) Monad.return id-monad = id app (Monad.bind id-monad f) px = app f px
{ "alphanum_fraction": 0.7336182336, "avg_line_length": 23.4, "ext": "agda", "hexsha": "353ff6eef8911ff6e9a0f8dd6ff5c0582e60f477", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z", "max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z", "max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "laMudri/linear.agda", "max_forks_repo_path": "src/Relation/Ternary/Separation/Monad/Identity.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "laMudri/linear.agda", "max_issues_repo_path": "src/Relation/Ternary/Separation/Monad/Identity.agda", "max_line_length": 60, "max_stars_count": 34, "max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "laMudri/linear.agda", "max_stars_repo_path": "src/Relation/Ternary/Separation/Monad/Identity.agda", "max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z", "max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z", "num_tokens": 205, "size": 702 }
module Data.Nat where import Prelude import Data.Bool as Bool open Prelude open Bool data Nat : Set where zero : Nat suc : Nat -> Nat {-# BUILTIN NATURAL Nat #-} {-# BUILTIN SUC suc #-} {-# BUILTIN ZERO zero #-} infix 40 _==_ _<_ _≤_ _>_ _≥_ infixl 60 _+_ _-_ infixl 70 _*_ infixr 80 _^_ infix 100 _! _+_ : Nat -> Nat -> Nat zero + m = m suc n + m = suc (n + m) _-_ : Nat -> Nat -> Nat zero - m = zero suc n - zero = suc n suc n - suc m = n - m _*_ : Nat -> Nat -> Nat zero * m = zero suc n * m = m + n * m _^_ : Nat -> Nat -> Nat n ^ zero = 1 n ^ suc m = n * n ^ m _! : Nat -> Nat zero ! = 1 suc n ! = suc n * n ! {-# BUILTIN NATPLUS _+_ #-} {-# BUILTIN NATMINUS _-_ #-} {-# BUILTIN NATTIMES _*_ #-} _==_ : Nat -> Nat -> Bool zero == zero = true zero == suc _ = false suc _ == zero = false suc n == suc m = n == m _<_ : Nat -> Nat -> Bool n < zero = false zero < suc m = true suc n < suc m = n < m _≤_ : Nat -> Nat -> Bool n ≤ m = n < suc m _>_ = flip _<_ _≥_ = flip _≤_ {-# BUILTIN NATEQUALS _==_ #-} {-# BUILTIN NATLESS _<_ #-} divSuc : Nat -> Nat -> Nat divSuc zero _ = zero divSuc (suc n) m = 1 + divSuc (n - m) m modSuc : Nat -> Nat -> Nat modSuc zero _ = zero modSuc (suc n) m = ! n ≤ m => suc n ! otherwise modSuc (n - m) m {-# BUILTIN NATDIVSUC divSuc #-} -- {-# BUILTIN NATMODSUC modSuc #-} div : Nat -> Nat -> Nat div n zero = zero div n (suc m) = divSuc n m mod : Nat -> Nat -> Nat mod n zero = zero mod n (suc m) = modSuc n m gcd : Nat -> Nat -> Nat gcd a 0 = a gcd a b = gcd b (mod a b) lcm : Nat -> Nat -> Nat lcm a b = div (a * b) (gcd a b) even : Nat -> Bool even n = mod n 2 == 0 odd : Nat -> Bool odd n = mod n 2 == 1
{ "alphanum_fraction": 0.5330602692, "avg_line_length": 16.5922330097, "ext": "agda", "hexsha": "4e920f84871f3e8832a094fb38fd3045fb1ce2bc", "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": "20596e9dd9867166a64470dd24ea68925ff380ce", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "np/agda-git-experiment", "max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Nat.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce", "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": "np/agda-git-experiment", "max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Nat.agda", "max_line_length": 39, "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/AIM6/Cat/lib/Data/Nat.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": 676, "size": 1709 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Lists with fast append ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Data.DifferenceList where open import Data.List.Base as L using (List) open import Function open import Data.Nat.Base infixr 5 _∷_ _++_ DiffList : ∀ {ℓ} → Set ℓ → Set ℓ DiffList A = List A → List A lift : ∀ {a} {A : Set a} → (List A → List A) → (DiffList A → DiffList A) lift f xs = λ k → f (xs k) [] : ∀ {a} {A : Set a} → DiffList A [] = λ k → k _∷_ : ∀ {a} {A : Set a} → A → DiffList A → DiffList A _∷_ x = lift (L._∷_ x) [_] : ∀ {a} {A : Set a} → A → DiffList A [ x ] = x ∷ [] _++_ : ∀ {a} {A : Set a} → DiffList A → DiffList A → DiffList A xs ++ ys = λ k → xs (ys k) toList : ∀ {a} {A : Set a} → DiffList A → List A toList xs = xs L.[] -- fromList xs is linear in the length of xs. fromList : ∀ {a} {A : Set a} → List A → DiffList A fromList xs = λ k → xs ⟨ L._++_ ⟩ k -- It is OK to use L._++_ here, since map is linear in the length of -- the list anyway. map : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → DiffList A → DiffList B map f xs = λ k → L.map f (toList xs) ⟨ L._++_ ⟩ k -- concat is linear in the length of the outer list. concat : ∀ {a} {A : Set a} → DiffList (DiffList A) → DiffList A concat xs = concat' (toList xs) where concat' : ∀ {a} {A : Set a} → List (DiffList A) → DiffList A concat' = L.foldr _++_ [] take : ∀ {a} {A : Set a} → ℕ → DiffList A → DiffList A take n = lift (L.take n) drop : ∀ {a} {A : Set a} → ℕ → DiffList A → DiffList A drop n = lift (L.drop n)
{ "alphanum_fraction": 0.5125598086, "avg_line_length": 26.125, "ext": "agda", "hexsha": "81476b1339dc6c1b3a9db91769863ba65b47bb82", "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/DifferenceList.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/DifferenceList.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/DifferenceList.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 583, "size": 1672 }
module Issue665 where postulate A : Set record I : Set where constructor i field f : A data Wrap : (j : I) → Set where con : ∀ {j} → Wrap j postulate C : Set anything : C works1 : ∀ {X} -> Wrap X -> C works1 (con {i _}) with anything ... | z = z works2 : ∀ {X} -> Wrap X -> C works2 (con {_}) with anything ... | z = z bugged : ∀ {X} -> Wrap X -> C bugged con with anything ... | z = z
{ "alphanum_fraction": 0.5525672372, "avg_line_length": 14.1034482759, "ext": "agda", "hexsha": "41c16140220f0a87307b1a0f128bc4bf62e48aa5", "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/Issue665.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/Issue665.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/Succeed/Issue665.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 150, "size": 409 }
{-# OPTIONS --without-K #-} module F1 where open import Data.Unit open import Data.Sum hiding (map) open import Data.Product hiding (map) open import Data.List open import Data.Nat open import Data.Bool {-- infixr 90 _⊗_ infixr 80 _⊕_ infixr 60 _∘_ infix 30 _⟷_ --} --------------------------------------------------------------------------- -- Paths -- Path relation should be an equivalence data Path (A : Set) : Set where _↝_ : (a : A) → (b : A) → Path A id↝ : {A : Set} → (a : A) → Path A id↝ a = a ↝ a ap : {A B : Set} → (f : A → B) → Path A → Path B ap f (a ↝ a') = f a ↝ f a' pathProd : {A B : Set} → Path A → Path B → Path (A × B) pathProd (a ↝ a') (b ↝ b') = (a , b) ↝ (a' , b') pathProdL : {A B : Set} → List (Path A) → List (Path B) → List (Path (A × B)) pathProdL pas pbs = concatMap (λ pa → map (pathProd pa) pbs) pas -- pi types with exactly one level of reciprocals data B0 : Set where ONE : B0 PLUS0 : B0 → B0 → B0 TIMES0 : B0 → B0 → B0 data B1 : Set where LIFT0 : B0 → B1 PLUS1 : B1 → B1 → B1 TIMES1 : B1 → B1 → B1 RECIP1 : B0 → B1 -- interpretation of B0 as discrete groupoids record 0-type : Set₁ where constructor G₀ field ∣_∣₀ : Set open 0-type public plus : 0-type → 0-type → 0-type plus t₁ t₂ = G₀ (∣ t₁ ∣₀ ⊎ ∣ t₂ ∣₀) times : 0-type → 0-type → 0-type times t₁ t₂ = G₀ (∣ t₁ ∣₀ × ∣ t₂ ∣₀) ⟦_⟧₀ : B0 → 0-type ⟦ ONE ⟧₀ = G₀ ⊤ ⟦ PLUS0 b₁ b₂ ⟧₀ = plus ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀ ⟦ TIMES0 b₁ b₂ ⟧₀ = times ⟦ b₁ ⟧₀ ⟦ b₂ ⟧₀ elems0 : (b : B0) → List ∣ ⟦ b ⟧₀ ∣₀ elems0 ONE = [ tt ] elems0 (PLUS0 b b') = map inj₁ (elems0 b) ++ map inj₂ (elems0 b') elems0 (TIMES0 b b') = concatMap (λ a → map (λ b → (a , b)) (elems0 b')) (elems0 b) -- interpretation of B1 types as 2-types record 2-type : Set₁ where constructor G₂ field ∣_∣₁ : Set 1-paths : List (Path ∣_∣₁) 2-paths : List (Path (Path ∣_∣₁)) open 2-type public _⊎↝_ : {A B : Set} → List (Path A) → List (Path B) → List (Path (A ⊎ B)) p₁ ⊎↝ p₂ = map (ap inj₁) p₁ ++ map (ap inj₂) p₂ ⟦_⟧₁ : B1 → 2-type ⟦ LIFT0 b0 ⟧₁ = G₂ ∣ ⟦ b0 ⟧₀ ∣₀ (map id↝ (elems0 b0)) [] ⟦ PLUS1 b₁ b₂ ⟧₁ with ⟦ b₁ ⟧₁ | ⟦ b₂ ⟧₁ ... | G₂ 0p₁ 1p₁ 2p₁ | G₂ 0p₂ 1p₂ 2p₂ = G₂ (0p₁ ⊎ 0p₂) (1p₁ ⊎↝ 1p₂) [] ⟦ TIMES1 b₁ b₂ ⟧₁ = G₂ {!!} {!!} [] ⟦ RECIP1 b0 ⟧₁ = G₂ ⊤ (map (λ _ → tt ↝ tt) (elems0 b0)) [] test10 = ⟦ LIFT0 ONE ⟧₁ test11 = ⟦ LIFT0 (PLUS0 ONE ONE) ⟧₁ test12 = ⟦ RECIP1 (PLUS0 ONE ONE) ⟧₁ {-- -- isos data _⟷_ : B → B → Set where -- + swap₊ : { b₁ b₂ : B } → PLUS b₁ b₂ ⟷ PLUS b₂ b₁ assocl₊ : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃ assocr₊ : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃) -- * unite⋆ : { b : B } → TIMES ONE b ⟷ b uniti⋆ : { b : B } → b ⟷ TIMES ONE b swap⋆ : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷ TIMES b₂ b₁ assocl⋆ : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷ TIMES (TIMES b₁ b₂) b₃ assocr⋆ : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷ TIMES b₁ (TIMES b₂ b₃) -- * distributes over + dist : { b₁ b₂ b₃ : B } → TIMES (PLUS b₁ b₂) b₃ ⟷ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) factor : { b₁ b₂ b₃ : B } → PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷ TIMES (PLUS b₁ b₂) b₃ -- congruence id⟷ : { b : B } → b ⟷ b sym : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁) _∘_ : { b₁ b₂ b₃ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃) _⊕_ : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS b₁ b₂ ⟷ PLUS b₃ b₄) _⊗_ : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES b₁ b₂ ⟷ TIMES b₃ b₄) -- interpret isos as functors record 0-functor (A B : 0-type) : Set where constructor F₀ field fobj : ∣ A ∣ → ∣ B ∣ fmor : {a b : ∣ A ∣} → (a ≡ b) → (fobj a ≡ fobj b) fmor {a} {.a} (refl .a) = refl (fobj a) open 0-functor public swap⊎ : {A B : Set} → A ⊎ B → B ⊎ A swap⊎ (inj₁ a) = inj₂ a swap⊎ (inj₂ b) = inj₁ b eval : {b₁ b₂ : B} → (b₁ ⟷ b₂) → 0-functor ⟦ b₁ ⟧ ⟦ b₂ ⟧ eval swap₊ = F₀ swap⊎ eval assocl₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS b₁ (PLUS b₂ b₃) ⟷ PLUS (PLUS b₁ b₂) b₃ eval assocr₊ = ? -- : { b₁ b₂ b₃ : B } → PLUS (PLUS b₁ b₂) b₃ ⟷ PLUS b₁ (PLUS b₂ b₃) eval unite⋆ = ? -- : { b : B } → TIMES ONE b ⟷ b eval uniti⋆ = ? -- : { b : B } → b ⟷ TIMES ONE b eval swap⋆ = ? -- : { b₁ b₂ : B } → TIMES b₁ b₂ ⟷ TIMES b₂ b₁ eval assocl⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES b₁ (TIMES b₂ b₃) ⟷ TIMES (TIMES b₁ b₂) b₃ eval assocr⋆ = ? -- : { b₁ b₂ b₃ : B } → TIMES (TIMES b₁ b₂) b₃ ⟷ TIMES b₁ (TIMES b₂ b₃) eval dist = ? -- : { b₁ b₂ b₃ : B } → TIMES (PLUS b₁ b₂) b₃ ⟷ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) eval factor = ? -- : { b₁ b₂ b₃ : B } → PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ⟷ TIMES (PLUS b₁ b₂) b₃ eval id⟷ = ? -- : { b : B } → b ⟷ b eval (sym c) = ? -- : { b₁ b₂ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₁) eval (c₁ ∘ c₂) = ? -- : { b₁ b₂ b₃ : B } → (b₁ ⟷ b₂) → (b₂ ⟷ b₃) → (b₁ ⟷ b₃) eval (c₁ ⊕ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (PLUS b₁ b₂ ⟷ PLUS b₃ b₄) eval (c₁ ⊗ c₂) = ? -- : { b₁ b₂ b₃ b₄ : B } → (b₁ ⟷ b₃) → (b₂ ⟷ b₄) → (TIMES b₁ b₂ ⟷ TIMES b₃ b₄) --------------------------------------------------------------------------- --}
{ "alphanum_fraction": 0.4984282908, "avg_line_length": 30.4790419162, "ext": "agda", "hexsha": "eed7d6b5dbea8a5c5ea3455be3b548fc11d2f3b6", "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": "F1.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": "F1.agda", "max_line_length": 97, "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": "F1.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": 2550, "size": 5090 }
module Generic.Reflection.ReadData where open import Generic.Core open import Generic.Function.FoldMono ‵π : ArgInfo -> String -> Term -> Term -> Term ‵π i s a b = sate π (reify i) (sate refl) ∘ sate coerce ∘ sate _,_ a $ appDef (quote appRel) (implRelArg (reify (relevance i)) ∷ explRelArg (explLam s b) ∷ []) quoteHyp : Name -> ℕ -> Type -> Maybe (Maybe Term) quoteHyp d p (pi s (arg i a) b) = quoteHyp d p a >>= maybe (const nothing) (fmap (‵π i s a) <$> quoteHyp d p b) quoteHyp d p t@(appDef n is) = just $ d == n ?> sate var (toTuple ∘ map argVal $ drop p is) quoteHyp d p t = just nothing quoteDesc : Name -> ℕ -> Type -> Maybe Term quoteDesc d p (pi s (arg i a) b) = (λ ma' b' -> maybe (λ a' -> sate _⊛_ a' (unshift′ b')) (‵π i s a b') ma') <$> quoteHyp d p a <*> quoteDesc d p b quoteDesc d p t = join $ quoteHyp d p t -- We didn't need that `β` previously. Why do we need it now? -- Or, perhaps, why didn't we need it earlier? It kinda makes sense. quoteData : Data Type -> TC Term quoteData (packData d a b cs ns) = case termLevelOf (monoLastType b) ⊗ mapM (quoteDesc d (countPis a)) cs of λ { nothing -> throw "can't read a data type" ; (just (β , cs′)) -> (λ qa qb -> explLamsBy a ∘ curryBy b ∘ appDef (quote μ) $ implRelArg unknown ∷ implRelArg β ∷ explRelArg (sate packData (reify d) qa qb (reify cs′) (reify ns)) ∷ []) <$> quoteTC a <*> quoteTC b } onFinalMu : ∀ {α} {A : Set α} -> (∀ {ι β} {I : Set ι} -> Data (Desc I β) -> TC A) -> Type -> TC A onFinalMu k = monoLastType >>> λ { (appDef (quote μ) (implRelArg qι ∷ implRelArg qβ ∷ implRelArg qI ∷ explRelArg qD ∷ _)) -> bindTC (unquoteTC qι) λ ι -> bindTC (unquoteTC qβ) λ β -> bindTC (unquoteTC qI) λ I -> bindTC (unquoteTC qD) λ D -> k {ι} {β} {I} D ; _ -> throw "the return type must be μ" } guncoercePure : Data Type -> Term guncoercePure (packData d a b cs ns) = explLam "x" ∘ vis appDef (quote curryFoldMono) $ explUncurryBy b (vis appDef d (replicate (countExplPis a) unknown)) ∷ pureVar 0 ∷ unmap pureCon ns macro readData : Name -> Term -> TC _ readData d ?r = getData d >>= quoteData >>= unify ?r gcoerce : Name -> Term -> TC _ gcoerce fd ?r = inferNormType ?r >>= onFinalMu λ{ D@(packData _ _ b _ _) -> quoteTC (μ D) >>= λ μD -> traverseAll quoteTC (allCons D) >>= λ cs′ -> unify ?r $ vis appDef fd (curryBy b μD ∷ allToList cs′) } guncoerce : ∀ {ι β} {I : Set ι} {D : Data (Desc I β)} {j} -> μ D j -> Term -> TC _ guncoerce {D = packData d a b cs ns} e ?r = quoteTC e >>= λ qe -> unify ?r ∘ vis appDef (quote curryFoldMono) $ explUncurryBy b (vis appDef d (replicate (countExplPis a) unknown)) ∷ qe ∷ unmap pureCon ns
{ "alphanum_fraction": 0.5658119658, "avg_line_length": 41.7857142857, "ext": "agda", "hexsha": "86ad5737f3613c0e702c050f2b7e051f3d81b693", "lang": "Agda", "max_forks_count": 4, "max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z", "max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z", "max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "turion/Generic", "max_forks_repo_path": "src/Generic/Reflection/ReadData.agda", "max_issues_count": 9, "max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z", "max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "turion/Generic", "max_issues_repo_path": "src/Generic/Reflection/ReadData.agda", "max_line_length": 97, "max_stars_count": 30, "max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "turion/Generic", "max_stars_repo_path": "src/Generic/Reflection/ReadData.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z", "max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z", "num_tokens": 1012, "size": 2925 }
-- Context extension of presheaves module SOAS.Families.Delta {T : Set} where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Sorting open import SOAS.Construction.Structure open import SOAS.Families.Core {T} -- | General context extension by a context Θ module Unsorted where -- Concatenate Θ to the context of a family δ : Ctx → Family → Family δ Θ X Γ = X (Θ ∔ Γ) δF : Ctx → Functor 𝔽amilies 𝔽amilies δF Θ = record { F₀ = δ Θ ; F₁ = λ f → f ; identity = refl ; homomorphism = refl ; F-resp-≈ = λ z → z } -- | Context extension by a single type τ, a special case of δ with ⌊ τ ⌋ δ₁ : T → Family → Family δ₁ τ = δ ⌈ τ ⌋ δ₁F_ : T → Functor 𝔽amilies 𝔽amilies δ₁F τ = δF ⌈ τ ⌋ private variable Γ Δ : Ctx α : T module Sorted where -- Concatenate Θ to the context of a family δ : Ctx → Familyₛ → Familyₛ δ Θ 𝒳 α Γ = 𝒳 α (Θ ∔ Γ) δF : Ctx → Functor 𝔽amiliesₛ 𝔽amiliesₛ δF Θ = record { F₀ = δ Θ ; F₁ = λ f → f ; identity = refl ; homomorphism = refl ; F-resp-≈ = λ z → z } -- | Context extension by a single type τ, a special case of δ with ⌊ τ ⌋ δ₁ : T → Familyₛ → Familyₛ δ₁ τ = δ ⌈ τ ⌋ δ₁F_ : T → Functor 𝔽amiliesₛ 𝔽amiliesₛ δ₁F τ = δF ⌈ τ ⌋
{ "alphanum_fraction": 0.6198282592, "avg_line_length": 24.1698113208, "ext": "agda", "hexsha": "e0646633413cd51c4ea580ed7873f6b91d27889e", "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/Families/Delta.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/Families/Delta.agda", "max_line_length": 75, "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/Families/Delta.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": 496, "size": 1281 }
module CombinatoryLogic.Syntax where open import Data.String using (String; _++_) open import Relation.Binary.PropositionalEquality using (_≡_; refl) -- Kapitel 1, Abschnitt C, §4 (Symbolische Festsetzungen), Def. 1 infixl 6 _∙_ data Combinator : Set where -- Kapitel 1, Abschnitt C, §3 (Die formalen Grundbegriffe) B C W K Q Π P ∧ : Combinator -- Kapitel 1, Abschnitt C, §2, c (Anwendung) _∙_ : (X Y : Combinator) → Combinator -- NOTE: for the (intensional) equality defined by Kapitel 1, Abschnitt C, §4 -- (Symbolische Festsetzungen), Festsetzung 2, we use the propositional equality -- _≡_. toString : Combinator → String toString (X ∙ Y@(_ ∙ _)) = toString X ++ "(" ++ toString Y ++ ")" toString (X ∙ Y) = toString X ++ toString Y toString B = "B" toString C = "C" toString W = "W" toString K = "K" toString Q = "Q" toString Π = "Π" toString P = "P" toString ∧ = "∧" _ : toString (K ∙ Q ∙ (W ∙ C)) ≡ "KQ(WC)" _ = refl _ : toString (K ∙ ∧ ∙ (Q ∙ Π) ∙ (W ∙ C)) ≡ "K∧(QΠ)(WC)" _ = refl _ : toString (K ∙ ∧ ∙ ((Q ∙ Π) ∙ (W ∙ C))) ≡ "K∧(QΠ(WC))" _ = refl _ : toString (K ∙ K ∙ K) ≡ "KKK" _ = refl infix 5 _==_ -- Kapitel 1, Abschnitt C, §4 (Symbolische Festsetzungen), Def. 2 _==_ : (X Y : Combinator) → Combinator X == Y = Q ∙ X ∙ Y -- Kapitel 1, Abschnitt C, §4 (Symbolische Festsetzungen), Def. 3 I : Combinator I = W ∙ K
{ "alphanum_fraction": 0.6185873606, "avg_line_length": 25.8653846154, "ext": "agda", "hexsha": "8dce32712a56c14c701d5f8be99a61cf8973445c", "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": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "splintah/combinatory-logic", "max_forks_repo_path": "CombinatoryLogic/Syntax.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "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": "splintah/combinatory-logic", "max_issues_repo_path": "CombinatoryLogic/Syntax.agda", "max_line_length": 80, "max_stars_count": 1, "max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "splintah/combinatory-logic", "max_stars_repo_path": "CombinatoryLogic/Syntax.agda", "max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z", "max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z", "num_tokens": 532, "size": 1345 }
open import Sec4 data ℕ : Set where Z : ℕ S : ℕ → ℕ -- Now ≥ relation _≥_ : ∀ (m : ℕ) → ∀ (n : ℕ) → Prop Z ≥ Z = ⊤ S m ≥ Z = ⊤ Z ≥ S n = ⊥ S m ≥ S n = m ≥ n -- Example proof -- eqqr : ((S (S (S Z))) ≥ (S (S Z))) → ((S (S Z)) ≥ (S (S (S Z)))) -- eqqr () -- -- Now is ≥ equivalence relation? -- relfexivity reflexivity : ∀ (m : ℕ) → (m ≥ m) reflexivity Z = ⋆ reflexivity (S m) = reflexivity m -- -- -- Now symmetry -- sym : ∀ (m : ℕ) → ∀ (n : ℕ) → m ≥ n → n ≥ m -- sym Z Z p = ⋆ -- sym Z (S n) p = ⋆ -- sym (S m) Z ⋆ = {!!} -- sym (S m) (S n) p = sym m n p -- -- -- Now transitivity trans'' : ∀ (m : ℕ) → ∀ (n : ℕ) → ∀ (p : ℕ) → m ≥ n → n ≥ p → m ≥ p trans'' Z Z p p0 p1 = p1 trans'' Z (S n) p () p1 trans'' (S m) n Z p0 p1 = ⋆ trans'' (S m) Z (S p) p0 () trans'' (S m) (S n) (S p) p0 p1 = trans'' m n p p0 p1 -- Given the above three are satisfied, we know that it is an -- equivalence relation! -- Now let us try strictly greater than (>) -- Definition of > _>_ : ∀ (m : ℕ) → ∀ (n : ℕ) → Prop Z > Z = ⊥ Z > S n = ⊥ S m > Z = ⊤ S m > S n = m > n -- Now let us see of > is an equivalence relation -- reflixvity of > not possible! -- refl-> : ∀ (m : ℕ) → m > m -- refl-> Z = {!!} -- refl-> (S m) = refl-> m -- equality _==_ : ∀ (m : ℕ) → ∀ (n : ℕ) → Prop Z == Z = ⊤ Z == S n = ⊥ S m == Z = ⊥ S m == S n = m == n -- Is equiality an equivalence relation? -- reflexivity refl-≡ : ∀ (m : ℕ) → m == m refl-≡ Z = ⋆ refl-≡ (S m) = refl-≡ m -- Symmetry sym-≡ : ∀ (m : ℕ) → ∀ (n : ℕ) → m == n → n == m sym-≡ Z Z h = ⋆ sym-≡ Z (S n) () sym-≡ (S m) Z () sym-≡ (S m) (S n) h = sym-≡ m n h -- Transitivity trans-≡ : ∀ (m n p : ℕ) → m == n → n == p → m == p trans-≡ Z n Z h0 h1 = ⋆ trans-≡ Z Z (S p) h0 h1 = h1 trans-≡ Z (S n) (S p) () h1 trans-≡ (S m) Z Z () h1 trans-≡ (S m) (S n) Z h0 () trans-≡ (S m) Z (S p) () h1 trans-≡ (S m) (S n) (S p) h0 h1 = trans-≡ m n p h0 h1 -- Homework ≤ on natural numbers -- Addition of natural numbers _+_ : ∀ (m n : ℕ) → ℕ Z + n = n S m + n = S (m + n) -- Use equality, 2 + 3 == 3 + 2 eqq : ((S (S Z)) + (S ( S ( S Z)))) == ((S ( S ( S Z))) + (S (S Z))) eqq = ⋆ infix 4 _≡_ data _≡_ {a} {A : Set a} (x : A) : A → Set a where refl : x ≡ x {-# BUILTIN EQUALITY _≡_ #-} {-# BUILTIN REFL refl #-} eqq2 : ((S (S Z)) + (S ( S ( S Z)))) ≡ ((S ( S ( S Z))) + (S (S Z))) eqq2 = refl cong : ∀ (n m : ℕ) → n ≡ m → S n ≡ S m cong n .n refl = refl -lemma-+ : ∀ (n : ℕ) → n ≡ (n + Z) -lemma-+ Z = refl -lemma-+ (S n) with -lemma-+ n -lemma-+ (S n) | h = cong n (n + Z) h lem2 : ∀ (m n : ℕ) → (m + S n) ≡ S (m + n) lem2 Z n = refl lem2 (S m) n = cong (m + S n) (S (m + n)) (lem2 m n) -- Now prove commutativity of addition commute-+ : ∀ (m n : ℕ) → (m + n) ≡ (n + m) commute-+ Z n = -lemma-+ n commute-+ (S m) n with (n + S m) | (lem2 n m) commute-+ (S m) n | .(S (n + m)) | refl = cong (m + n) (n + m) (commute-+ m n) _<_ : ∀ (m n : ℕ) → Prop Z < Z = ⊥ Z < S n = ⊥ S m < Z = ⊤ S m < S n = m < n -- refl-< : ∀ (m : ℕ) → m < m -- refl-< Z = !! -- refl-< (S m) = !! -- Define booleans data 𝔹 : Set where True : 𝔹 False : 𝔹 -- Define && _&&_ : ∀ (A B : 𝔹) → 𝔹 True && True = True True && False = False False && B = False -- Define || _||_ : ∀ (A B : 𝔹) → 𝔹 True || B = True False || True = True False || False = False -- Prove equivalence of two hardware functions g and f g : ∀ (A B C : 𝔹) → 𝔹 g A B C = B && (A || C) ff : ∀ (A B C : 𝔹) → 𝔹 ff A B C = (A && B) || ((B && C) && (B || C)) -- Equality of booleans _==̰_ : ∀ (A B : 𝔹) → Prop True ==̰ True = ⊤ True ==̰ False = ⊥ False ==̰ True = ⊥ False ==̰ False = ⊤ -- Now prove that for any input A B C, g ≡ ff g≃ff : ∀ (A B C : 𝔹) → (g A B C) ==̰ (ff A B C) g≃ff True True True = ⋆ g≃ff True True False = ⋆ g≃ff True False C = ⋆ g≃ff False True True = ⋆ g≃ff False True False = ⋆ g≃ff False False C = ⋆ _≤_ : ∀ (m n : ℕ) → Prop Z ≤ n = ⊤ S m ≤ Z = ⊥ S m ≤ S n = m ≤ n -- Symmetry on ≤ -- sym-≤ : ∀ (m n : ℕ) → (m ≤ n) → (n ≤ m) -- sym-≤ Z Z ⋆ = ⋆ -- sym-≤ Z (S n) ⋆ = {!!} -- sym-≤ (S m) Z () -- sym-≤ (S m) (S n) p = sym-≤ m n p -- ≠ _≠_ : ∀ (m n : ℕ) → Prop Z ≠ Z = ⊥ Z ≠ S n = ⊤ S m ≠ Z = ⊤ S m ≠ S n = m ≠ n -- -- Is ≠ an equivalence relation? -- ≠-refl -- ≠-relf : ∀ (m : ℕ) → (m ≠ m) -- ≠-relf Z = {!!} -- ≠-relf (S m) = ≠-relf m -- -- Symmetry ≠-sym : ∀ (m n : ℕ) → (m ≠ n) → (n ≠ m) ≠-sym Z Z () ≠-sym Z (S n) p = ⋆ ≠-sym (S m) Z p = ⋆ ≠-sym (S m) (S n) p = ≠-sym m n p -- -- Transitivity -- ≠-trans : ∀ (m n p : ℕ) → (m ≠ n) → (n ≠ p) → (m ≠ p) -- ≠-trans Z Z Z h0 () -- ≠-trans Z (S n) Z ⋆ ⋆ = {!!} -- ≠-trans Z n (S p) h0 h1 = ⋆ -- ≠-trans (S m) n Z h0 h1 = ⋆ -- ≠-trans (S m) Z (S p) ⋆ ⋆ = {!!} -- ≠-trans (S m) (S n) (S p) h0 h1 = ≠-trans m n p h0 h1 de1 : {A B : Prop} → ((¬ A) ∨ (¬ B)) ⇒ ¬ (A ∧ B) de1 = impl (λ x → neg (impl (λ x₁ → let y = elim1-∧ x₁ z = elim2-∧ x₁ in elim-∨ x (λ x₃ → elim-neg y x₃) (λ x₂ → elim-neg z x₂)))) de2 : {A B : Prop} → ((¬ A) ∧ (¬ B)) ⇒ (¬ (A ∨ B)) de2 = impl (λ x → neg (impl (λ x₁ → elim-∨ x₁ (λ x₂ → elim-neg x₂ (elim1-∧ x)) (λ x₂ → elim-neg x₂ (elim2-∧ x))))) -- Multiplication of naturals _*_ : ∀ (m n : ℕ) → ℕ Z * n = Z S m * n = n + (m * n) -- Square relation on two naturals _r²_ : ∀ (m n : ℕ) → Prop m r² n = (m * m) ≡ (n * n) -- reflexivity of r² refl-r² : ∀ (m : ℕ) → (m r² m) refl-r² Z = refl refl-r² (S m) = refl sym-r² : ∀ (m n : ℕ) → (m r² n) → (n r² m) sym-r² Z Z p = refl sym-r² Z (S n) () sym-r² (S m) Z () sym-r² (S m) (S n) p rewrite p = refl trans-r² : ∀ (m n p : ℕ) → (m r² n) → (n r² p) → (m r² p) trans-r² Z n Z h0 h1 = refl trans-r² Z Z (S p) refl () trans-r² Z (S n) (S p) () h1 trans-r² (S m) Z Z () h1 trans-r² (S m) (S n) Z h0 () trans-r² (S m) Z (S p) () h1 trans-r² (S m) (S n) (S p) h0 h1 rewrite h0 | h1 = refl
{ "alphanum_fraction": 0.4285232068, "avg_line_length": 22.6145038168, "ext": "agda", "hexsha": "f84c7ee00534108f5ae2344363c012e368105577", "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": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "amal029/agda-tutorial-dybjer", "max_forks_repo_path": "lecture.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166", "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": "amal029/agda-tutorial-dybjer", "max_issues_repo_path": "lecture.agda", "max_line_length": 88, "max_stars_count": 1, "max_stars_repo_head_hexsha": "7128bb419cd4aa3eeacae1fae1a9eb2e57ee8166", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "amal029/agda-tutorial-dybjer", "max_stars_repo_path": "lecture.agda", "max_stars_repo_stars_event_max_datetime": "2019-08-08T12:52:30.000Z", "max_stars_repo_stars_event_min_datetime": "2019-08-08T12:52:30.000Z", "num_tokens": 2816, "size": 5925 }
module Schedule where open import Data.Bool open import Data.Fin open import Data.Empty open import Data.List open import Data.List.All open import Data.Maybe open import Data.Nat open import Data.Product open import Data.Sum open import Data.Unit open import Function using (_$_) open import Relation.Nullary open import Relation.Binary.PropositionalEquality open import Typing open import Syntax open import Global open import Channel open import Values open import Session -- outcomes of step data Event : Set where Terminated Forked Restarted Halted New Closed NotClosed WaitSkipped : Event SendSkipped Received NotReceived : Event Stuck : Event Selected NotSelected : Event NSelected NotNSelected BranchSkipped NBranchSkipped : Event data NextPool : Set where _,_ : ∀ {G} → Event → ThreadPool G → NextPool module Alternative where step : ∀ {Gtop G1 G2} → SSplit Gtop G1 G2 → ThreadPool G1 → ThreadPool G2 → NextPool step ss-top (tnil ina) tp2@(tnil _) = Terminated , tp2 step ss-top (tnil ina) tp2 = Stuck , tp2 step ss-top (tcons ss (Fork{G₁ = G₁}{G₂ = G₂} ss₁ κ₁ κ₂) tp) tp2 with ssplit-compose ss ss₁ ... | Gi , ss₁₃ , ss₂₄ with ssplit-refl-right G₁ | ssplit-refl-right G₂ ... | Gunit , ss-G1GunitG1 | G2unit , ss-G2GuG2 = Forked , (tappend ss-top ((tcons ss₁₃ (apply-cont ss-G1GunitG1 κ₁ (VUnit (ssplit-inactive-right ss-G1GunitG1))) (tcons ss₂₄ (Ready ss-G2GuG2 (VUnit (ssplit-inactive-right ss-G2GuG2)) κ₂) tp))) tp2) step ss-top (tcons ss (Ready ss₁ v κ) tp) tp2 = Restarted , (tappend ss-top (tsnoc ss tp (apply-cont ss₁ κ v)) tp2) step ss-top (tcons ss (Halt inaG x₁ x₂) tp) tp2 rewrite inactive-left-ssplit ss inaG = Halted , (tappend ss-top tp tp2) step ss-top (tcons{G₁} ss (New s κ) tp) tp2 with ssplit-refl-right G₁ ... | Gi , ss-GiG1 with ssplit-inactive-right ss-GiG1 ... | ina-Gi = New , (tappend (ss-left ss-top) ((tcons (ss-left ss) (Ready (ss-left ss-GiG1) (VPair (ss-posneg (inactive-ssplit-trivial ina-Gi)) (VChan POS (here-pos ina-Gi (subF-refl _))) (VChan NEG (here-neg ina-Gi (subF-refl _)))) (lift-cont κ)) (lift-threadpool tp))) (lift-threadpool tp2)) step ss-top (tcons{G₁}{G₂} ss cmd@(Close ss-vκ v κ) tp) tp2 with ssplit-compose ss-top ss ... | Gi , ss-top1 , ss-top2 with ssplit-refl-left-inactive Gi ... | G' , ina-G' , ss-GG' with matchWaitAndGo ss-top1 (ss-vκ , v , κ) ss-GG' (tappend ss-top2 tp tp2) (tnil ina-G') ... | just (Gnext , tpnext) = Closed , tpnext ... | nothing with ssplit-compose5 ss-top ss ... | Gi' , ss-top1' , ss-top2' = step ss-top1' tp (tsnoc ss-top2' tp2 cmd) step ss-top (tcons ss cmd@(Wait ss₁ v κ) tp) tp2 with ssplit-compose5 ss-top ss ... | Gi , ss-top1 , ss-top2 = step ss-top1 tp (tsnoc ss-top2 tp2 cmd) step ss-top (tcons ss cmd@(Send ss₁ ss-args vch v κ) tp) tp2 with ssplit-compose5 ss-top ss ... | Gi , ss-top1 , ss-top2 = step ss-top1 tp (tsnoc ss-top2 tp2 cmd) step ss-top (tcons{G₁}{G₂} ss cmd@(Recv ss-vκ vch κ) tp) tp2 with ssplit-compose ss-top ss ... | Gi , ss-top1 , ss-top2 with ssplit-refl-left-inactive Gi ... | G' , ina-G' , ss-GG' with matchSendAndGo ss-top1 (ss-vκ , vch , κ) ss-GG' (tappend ss-top2 tp tp2) (tnil ina-G') ... | just (G-next , tp-next) = Received , tp-next ... | nothing with ssplit-compose5 ss-top ss ... | Gi' , ss-top1' , ss-top2' = step ss-top1' tp (tsnoc ss-top2' tp2 cmd) step ss-top (tcons{G₁}{G₂} ss cmd@(Select ss-vκ lab vch κ) tp) tp2 with ssplit-compose ss-top ss ... | Gi , ss-top1 , ss-top2 with ssplit-refl-left-inactive Gi ... | G' , ina-G' , ss-GG' with matchBranchAndGo ss-top1 (ss-vκ , lab , vch , κ) ss-GG' (tappend ss-top2 tp tp2) (tnil ina-G') ... | just (G-next , tp-next) = Selected , tp-next ... | nothing with ssplit-compose5 ss-top ss ... | Gi' , ss-top1' , ss-top2' = step ss-top1' tp (tsnoc ss-top2' tp2 cmd) step ss-top (tcons ss cmd@(Branch ss₁ vch dcont) tp) tp2 with ssplit-compose5 ss-top ss ... | Gi , ss-top1 , ss-top2 = step ss-top1 tp (tsnoc ss-top2 tp2 cmd) step ss-top (tcons{G₁}{G₂} ss cmd@(NSelect ss-vκ lab vch κ) tp) tp2 with ssplit-compose ss-top ss ... | Gi , ss-top1 , ss-top2 with ssplit-refl-left-inactive Gi ... | G' , ina-G' , ss-GG' with matchNBranchAndGo ss-top1 (ss-vκ , lab , vch , κ) ss-GG' (tappend ss-top2 tp tp2) (tnil ina-G') ... | just (G-next , tp-next) = NSelected , tp-next ... | nothing with ssplit-compose5 ss-top ss ... | Gi' , ss-top1' , ss-top2' = step ss-top1' tp (tsnoc ss-top2' tp2 cmd) step ss-top (tcons ss cmd@(NBranch ss₁ vch dcont) tp) tp2 with ssplit-compose5 ss-top ss ... | Gi , ss-top1 , ss-top2 = step ss-top1 tp (tsnoc ss-top2 tp2 cmd) module Original where step : ∀ {G} → ThreadPool G → NextPool step (tnil ina) = Terminated , tnil ina step (tcons ss (Fork{G₁ = G₁}{G₂ = G₂} ss₁ κ₁ κ₂) tp) with ssplit-compose ss ss₁ ... | Gi , ss₁₃ , ss₂₄ with ssplit-refl-right G₁ | ssplit-refl-right G₂ ... | Gunit , ss-G1GunitG1 | G2unit , ss-G2GuG2 = Forked , (tcons ss₁₃ (apply-cont ss-G1GunitG1 κ₁ (VUnit (ssplit-inactive-right ss-G1GunitG1))) (tcons ss₂₄ (apply-cont ss-G2GuG2 κ₂ (VUnit (ssplit-inactive-right ss-G2GuG2))) tp)) step (tcons ss (Ready ss₁ v κ) tp) = Restarted , (tsnoc ss tp (apply-cont ss₁ κ v)) step (tcons ss (Halt inaG x₁ x₂) tp) rewrite inactive-left-ssplit ss inaG = Halted , tp step (tcons{G₁} ss (New s κ) tp) with ssplit-refl-right G₁ ... | Gi , ss-GiG1 with ssplit-inactive-right ss-GiG1 ... | ina-Gi = New , (tcons (ss-left ss) (apply-cont (ss-left ss-GiG1) (lift-cont κ) (VPair (ss-posneg (inactive-ssplit-trivial ina-Gi)) (VChan POS (here-pos ina-Gi (subF-refl _))) (VChan NEG (here-neg ina-Gi (subF-refl _))))) (lift-threadpool tp)) step (tcons{G₁}{G₂} ss cmd@(Close ss-vκ v κ) tp) with ssplit-refl-left-inactive G₂ ... | G' , ina-G' , ss-GG' with matchWaitAndGo ss (ss-vκ , v , κ) ss-GG' tp (tnil ina-G') ... | just (Gnext , tpnext) = Closed , tpnext ... | nothing = NotClosed , (tsnoc ss tp cmd) step (tcons ss cmd@(Wait ss₁ v κ) tp) = WaitSkipped , (tsnoc ss tp cmd) step (tcons ss cmd@(Send ss₁ ss-args vch v κ) tp) = SendSkipped , (tsnoc ss tp cmd) step (tcons{G₁}{G₂} ss cmd@(Recv ss-vκ vch κ) tp) with ssplit-refl-left-inactive G₂ ... | G' , ina-G' , ss-GG' with matchSendAndGo ss (ss-vκ , vch , κ) ss-GG' tp (tnil ina-G') ... | just (G-next , tp-next) = Received , tp-next ... | nothing = NotReceived , (tsnoc ss tp cmd) step (tcons{G₁}{G₂} ss cmd@(Select ss-vκ lab vch κ) tp) with ssplit-refl-left-inactive G₂ ... | G' , ina-G' , ss-GG' with matchBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp (tnil ina-G') ... | just (G-next , tp-next) = Selected , tp-next ... | nothing = NotSelected , (tsnoc ss tp cmd) step (tcons ss cmd@(Branch ss-vκ vch dcont) tp) = BranchSkipped , (tsnoc ss tp cmd) step (tcons{G₁}{G₂} ss cmd@(NSelect ss-vκ lab vch κ) tp) with ssplit-refl-left-inactive G₂ ... | G' , ina-G' , ss-GG' with matchNBranchAndGo ss (ss-vκ , lab , vch , κ) ss-GG' tp (tnil ina-G') ... | just (G-next , tp-next) = NSelected , tp-next ... | nothing = NotNSelected , (tsnoc ss tp cmd) step (tcons ss cmd@(NBranch ss-vκ vch dcont) tp) = NBranchSkipped , (tsnoc ss tp cmd) open Alternative single-step : (∃ λ G → ThreadPool G) → Event × (∃ λ G → ThreadPool G) single-step (G , tp) with ssplit-refl-left-inactive G ... | G' , ina-G' , ss-GG' with step ss-GG' tp (tnil ina-G') ... | ev , tp' = ev , ( _ , tp') -- stuff to run ... data Gas : Set where Empty : Gas More : Gas → Gas -- outcomes of scheduling data Outcome : Set where Terminated : Outcome _,_ : Event → Outcome → Outcome OutOfGas : ∀ {G} → ThreadPool G → Outcome -- thread scheduling schedule : {G : SCtx} → Gas → ThreadPool G → Outcome schedule Empty tp = OutOfGas tp schedule{G} (More gas) tp with single-step (_ , tp) ... | Terminated , _ , tp' = Terminated ... | ev , _ , tp' = ev , (schedule gas tp') -- start main thread start : Gas → Expr [] TUnit → Outcome start f e = schedule f (tcons ss-[] (run [] ss-[] e (vnil []-inactive) (halt []-inactive UUnit)) (tnil []-inactive))
{ "alphanum_fraction": 0.6325257856, "avg_line_length": 40.2801932367, "ext": "agda", "hexsha": "b475f6b1e0831f101e46b97e44b673f25a0cb939", "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": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "peterthiemann/definitional-session", "max_forks_repo_path": "src/Schedule.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "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": "peterthiemann/definitional-session", "max_issues_repo_path": "src/Schedule.agda", "max_line_length": 198, "max_stars_count": 9, "max_stars_repo_head_hexsha": "c2213909c8a308fb1c1c1e4e789d65ba36f6042c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "peterthiemann/definitional-session", "max_stars_repo_path": "src/Schedule.agda", "max_stars_repo_stars_event_max_datetime": "2021-01-18T08:10:14.000Z", "max_stars_repo_stars_event_min_datetime": "2019-01-19T16:33:27.000Z", "num_tokens": 3016, "size": 8338 }
{-# OPTIONS --without-K --safe #-} module Dodo.Unary.Empty where -- Stdlib imports open import Level using (Level; _⊔_) open import Data.Product using (∃-syntax) open import Relation.Nullary using (¬_) open import Relation.Unary using (Pred) -- # Definitions Empty₁ : ∀ {a ℓ : Level} {A : Set a} → Pred A ℓ → Set (a ⊔ ℓ) Empty₁ {A = A} P = ∀ (x : A) → ¬ P x NonEmpty₁ : ∀ {a ℓ : Level} {A : Set a} → Pred A ℓ → Set (a ⊔ ℓ) NonEmpty₁ P = ∃[ x ] P x ¬₁_ : ∀ {a ℓ : Level} {A : Set a} → Pred A ℓ → Pred A ℓ ¬₁_ P x = ¬ P x
{ "alphanum_fraction": 0.5863377609, "avg_line_length": 23.9545454545, "ext": "agda", "hexsha": "f8bf84c7de5efcc3d254eb8cb7d8081406d91feb", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "sourcedennis/agda-dodo", "max_forks_repo_path": "src/Dodo/Unary/Empty.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "sourcedennis/agda-dodo", "max_issues_repo_path": "src/Dodo/Unary/Empty.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "sourcedennis/agda-dodo", "max_stars_repo_path": "src/Dodo/Unary/Empty.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 200, "size": 527 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.HITs.Ints.BiInvInt.Properties where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Data.Nat hiding (_+_; +-comm) open import Cubical.Data.Int open import Cubical.Data.Bool open import Cubical.HITs.Ints.BiInvInt.Base -- addition _+ᴮ_ : BiInvInt → BiInvInt → BiInvInt m +ᴮ zero = m m +ᴮ suc n = suc (m +ᴮ n) m +ᴮ predr n = predr (m +ᴮ n) m +ᴮ predl n = predl (m +ᴮ n) m +ᴮ suc-predr n i = suc-predr (m +ᴮ n) i m +ᴮ predl-suc n i = predl-suc (m +ᴮ n) i -- properties of addition +ᴮ-assoc : ∀ l m n → (l +ᴮ m) +ᴮ n ≡ l +ᴮ (m +ᴮ n) +ᴮ-assoc l m zero i = l +ᴮ m +ᴮ-assoc l m (suc n) i = suc (+ᴮ-assoc l m n i) +ᴮ-assoc l m (predr n) i = predr (+ᴮ-assoc l m n i) +ᴮ-assoc l m (predl n) i = predl (+ᴮ-assoc l m n i) +ᴮ-assoc l m (suc-predr n i) j = suc-predr (+ᴮ-assoc l m n j) i +ᴮ-assoc l m (predl-suc n i) j = predl-suc (+ᴮ-assoc l m n j) i +ᴮ-unitʳ : ∀ n → n +ᴮ zero ≡ n +ᴮ-unitʳ n i = n +ᴮ-unitˡ : ∀ n → zero +ᴮ n ≡ n +ᴮ-unitˡ zero i = zero +ᴮ-unitˡ (suc n) i = suc (+ᴮ-unitˡ n i) +ᴮ-unitˡ (predr n) i = predr (+ᴮ-unitˡ n i) +ᴮ-unitˡ (predl n) i = predl (+ᴮ-unitˡ n i) +ᴮ-unitˡ (suc-predr n i) j = suc-predr (+ᴮ-unitˡ n j) i +ᴮ-unitˡ (predl-suc n i) j = predl-suc (+ᴮ-unitˡ n j) i -- TODO: a direct proof of commutatitivty -- (for now, we use Data.Int) fwd-+≡+ᴮ : ∀ m n → fwd (m + n) ≡ (fwd m) +ᴮ (fwd n) fwd-+≡+ᴮ m (pos zero) = refl fwd-+≡+ᴮ m (pos (suc n)) = fwd-sucInt (m +pos n) ∙ cong suc (fwd-+≡+ᴮ m (pos n)) fwd-+≡+ᴮ m (negsuc zero) = fwd-predInt m fwd-+≡+ᴮ m (negsuc (suc n)) = fwd-predInt (m +negsuc n) ∙ cong pred (fwd-+≡+ᴮ m (negsuc n)) +ᴮ≡+ : ∀ m n → m +ᴮ n ≡ fwd ((bwd m) + (bwd n)) +ᴮ≡+ m n = sym (fwd-+≡+ᴮ (bwd m) (bwd n) ∙ (λ i → (fwd-bwd m i) +ᴮ (fwd-bwd n i))) +ᴮ-comm : ∀ m n → m +ᴮ n ≡ n +ᴮ m +ᴮ-comm m n = +ᴮ≡+ m n ∙ cong fwd (+-comm (bwd m) (bwd n)) ∙ sym (+ᴮ≡+ n m) -- some of the lemmas needed for a direct proof +ᴮ-comm are corollaries of +ᴮ-comm suc-+ᴮ : ∀ m n → (suc m) +ᴮ n ≡ suc (m +ᴮ n) suc-+ᴮ m n = +ᴮ-comm (suc m) n ∙ (λ i → suc (+ᴮ-comm n m i)) -- suc-+ᴮ m zero i = suc m -- suc-+ᴮ m (suc n) i = suc (suc-+ᴮ m n i) -- suc-+ᴮ m (predr n) = cong predr (suc-+ᴮ m n) ∙ predr-suc (m +ᴮ n) ∙ sym (suc-predr (m +ᴮ n)) -- suc-+ᴮ m (predl n) = cong predl (suc-+ᴮ m n) ∙ predl-suc (m +ᴮ n) ∙ sym (suc-predl (m +ᴮ n)) -- suc-+ᴮ m (suc-predr n i) j = {!!} -- suc-+ᴮ m (predl-suc n i) j = {!!} predr-+ᴮ : ∀ m n → (predr m) +ᴮ n ≡ predr (m +ᴮ n) predr-+ᴮ m n = +ᴮ-comm (predr m) n ∙ (λ i → predr (+ᴮ-comm n m i)) predl-+ᴮ : ∀ m n → (predl m) +ᴮ n ≡ predl (m +ᴮ n) predl-+ᴮ m n = +ᴮ-comm (predl m) n ∙ (λ i → predl (+ᴮ-comm n m i)) -- +ᴮ-comm : ∀ m n → n +ᴮ m ≡ m +ᴮ n -- +ᴮ-comm m zero = +ᴮ-unitˡ m -- +ᴮ-comm m (suc n) = suc-+ᴮ n m ∙ cong suc (+ᴮ-comm m n) -- +ᴮ-comm m (predr n) = predr-+ᴮ n m ∙ cong predr (+ᴮ-comm m n) -- +ᴮ-comm m (predl n) = predl-+ᴮ n m ∙ cong predl (+ᴮ-comm m n) -- +ᴮ-comm m (suc-predr n i) j = {!!} -- +ᴮ-comm m (predl-suc n i) j = {!!} -- negation / subtraction -ᴮ_ : BiInvInt → BiInvInt -ᴮ zero = zero -ᴮ suc n = predl (-ᴮ n) -ᴮ predr n = suc (-ᴮ n) -ᴮ predl n = suc (-ᴮ n) -ᴮ suc-predr n i = predl-suc (-ᴮ n) i -ᴮ predl-suc n i = suc-predl (-ᴮ n) i _-ᴮ_ : BiInvInt → BiInvInt → BiInvInt m -ᴮ n = m +ᴮ (-ᴮ n) -- TODO: properties of negation -- +ᴮ-invˡ : ∀ n → (-ᴮ n) +ᴮ n ≡ zero -- +ᴮ-invˡ zero = refl -- +ᴮ-invˡ (suc n) = (λ i → suc (predl-+ᴮ (-ᴮ n) n i)) ∙ (λ i → suc-pred (+ᴮ-invˡ n i) i) -- +ᴮ-invˡ (predr n) = (λ i → predr (suc-+ᴮ (-ᴮ n) n i)) ∙ (λ i → predr-suc (+ᴮ-invˡ n i) i) -- +ᴮ-invˡ (predl n) = (λ i → predl (suc-+ᴮ (-ᴮ n) n i)) ∙ (λ i → predl-suc (+ᴮ-invˡ n i) i) -- +ᴮ-invˡ (suc-predr n i) j = {!!} -- +ᴮ-invˡ (predl-suc n i) j = {!!} -- +ᴮ-invʳ : ∀ n → n +ᴮ (-ᴮ n) ≡ zero -- +ᴮ-invʳ n = {!!} -- natural injections from ℕ posᴮ : ℕ → BiInvInt posᴮ zero = zero posᴮ (suc n) = suc (posᴮ n) negᴮ : ℕ → BiInvInt negᴮ zero = zero negᴮ (suc n) = pred (negᴮ n) -- absolute value and sign -- (Note that there doesn't appear to be any way around using -- bwd here! Any direct proof ends up doing the same work...) absᴮ : BiInvInt → ℕ absᴮ n = abs (bwd n) sgnᴮ : BiInvInt → Bool sgnᴮ n = sgn (bwd n) -- TODO: a direct definition of multiplication using +ᴮ-invˡ/ʳ -- (for now we use abs and sgn, as in agda's stdlib) _*ᴮ_ : BiInvInt → BiInvInt → BiInvInt m *ᴮ n = caseBool posᴮ negᴮ (sgnᴮ m and sgnᴮ n) (absᴮ m * absᴮ n) -- m *ᴮ zero = zero -- m *ᴮ suc n = (m *ᴮ n) +ᴮ m -- m *ᴮ predr n = (m *ᴮ n) -ᴮ m -- m *ᴮ predl n = (m *ᴮ n) -ᴮ m -- m *ᴮ suc-predr n i = ( +ᴮ-assoc (m *ᴮ n) (-ᴮ m) m -- ∙ cong ((m *ᴮ n) +ᴮ_) (+ᴮ-invˡ m) -- ∙ +ᴮ-unitʳ (m *ᴮ n)) i -- m *ᴮ predl-suc n i = ( +ᴮ-assoc (m *ᴮ n) m (-ᴮ m) -- ∙ cong ((m *ᴮ n) +ᴮ_) (+ᴮ-invʳ m) -- ∙ +ᴮ-unitʳ (m *ᴮ n)) i
{ "alphanum_fraction": 0.5197316496, "avg_line_length": 34.0134228188, "ext": "agda", "hexsha": "35ff518bfcd7f10384bfba898b08740ea4528aa5", "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/HITs/Ints/BiInvInt/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d13941587a58895b65f714f1ccc9c1f5986b109c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "RobertHarper/cubical", "max_issues_repo_path": "Cubical/HITs/Ints/BiInvInt/Properties.agda", "max_line_length": 100, "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/HITs/Ints/BiInvInt/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2656, "size": 5068 }
-- Useless abstract module Issue476b where abstract data A : Set data A where
{ "alphanum_fraction": 0.743902439, "avg_line_length": 10.25, "ext": "agda", "hexsha": "78c7ce5d56974e4d02c38de7c8c4b83ed650d9e5", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z", "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/Issue476b.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/Issue476b.agda", "max_line_length": 22, "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/Issue476b.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": 23, "size": 82 }
------------------------------------------------------------------------ -- Compiler correctness ------------------------------------------------------------------------ {-# OPTIONS --cubical --safe #-} module Lambda.Simplified.Partiality-monad.Inductive.Compiler-correctness where open import Equality.Propositional.Cubical open import Prelude hiding (⊥) open import Monad equality-with-J open import Vec.Function equality-with-J open import Partiality-monad.Inductive open import Partiality-monad.Inductive.Fixpoints hiding (comp; app) open import Partiality-monad.Inductive.Monad open import Lambda.Simplified.Compiler open import Lambda.Simplified.Partiality-monad.Inductive.Interpreter open import Lambda.Simplified.Partiality-monad.Inductive.Virtual-machine open import Lambda.Simplified.Syntax open import Lambda.Simplified.Virtual-machine private module C = Closure Code module T = Closure Tm open Partial open Trans-⊑ -- Some abbreviations. evalⁿ : ∀ {n} → Tm n → T.Env n → ℕ → T.Value ⊥ evalⁿ t ρ n = app→ eval n (_ , t , ρ) _∙ⁿ_ : T.Value → T.Value → ℕ → T.Value ⊥ (v₁ ∙ⁿ v₂) n = function (v₁ ∙ v₂) (app→ eval n) execⁿ : State → ℕ → Maybe C.Value ⊥ execⁿ s n = app→ (transformer execP) n s -- Compiler correctness. mutual ⟦⟧-correct : ∀ {n} t {ρ : T.Env n} {c s} {k : ℕ → T.Value → Maybe C.Value ⊥} {n} → (∀ v → execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳[ n ] λ n → k n v) → execⁿ ⟨ comp t c , s , comp-env ρ ⟩ ≳[ n ] λ n → evalⁿ t ρ (suc n) >>= k n ⟦⟧-correct (var x) {ρ} {c} {s} {k} hyp = execⁿ ⟨ var x ∷ c , s , comp-env ρ ⟩ ≳⟨ step⇓ ⟩ execⁿ ⟨ c , val (comp-val (ρ x)) ∷ s , comp-env ρ ⟩ ≳⟨ hyp (ρ x) ⟩ (λ n → k n (ρ x)) ≡⟨ sym now->>= ⟩≳ (λ n → evalⁿ (var x) ρ (suc n) >>= k n) ∎≳ ⟦⟧-correct (ƛ t) {ρ} {c} {s} {k} hyp = execⁿ ⟨ clo (comp t (ret ∷ [])) ∷ c , s , comp-env ρ ⟩ ≳⟨ step⇓ ⟩ execⁿ ⟨ c , val (comp-val (T.ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≳⟨ hyp (T.ƛ t ρ) ⟩ (λ n → k n (T.ƛ t ρ)) ≡⟨ sym now->>= ⟩≳ (λ n → evalⁿ (ƛ t) ρ (suc n) >>= k n) ∎≳ ⟦⟧-correct (t₁ · t₂) {ρ} {c} {s} {k} {n} hyp = execⁿ ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≳⟨ (⟦⟧-correct t₁ {n = n} λ v₁ → ⟦⟧-correct t₂ λ v₂ → ∙-correct v₁ v₂ hyp) ⟩ (λ n → evalⁿ t₁ ρ (suc n) >>=′ λ v₁ → evalⁿ t₂ ρ (suc n) >>=′ λ v₂ → (v₁ ∙ⁿ v₂) n >>= k n) ≡⟨ cong (evalⁿ t₁ ρ (suc n) >>=′_) (⟨ext⟩ λ _ → associativity (evalⁿ t₂ ρ (suc n)) _ _) ⟩≳ (λ n → evalⁿ t₁ ρ (suc n) >>=′ λ v₁ → (evalⁿ t₂ ρ (suc n) >>=′ λ v₂ → (v₁ ∙ⁿ v₂) n) >>= k n) ≡⟨ associativity (evalⁿ t₁ ρ (suc n)) _ _ ⟩≳ (λ n → evalⁿ (t₁ · t₂) ρ (suc n) >>= k n) ∎≳ ∙-correct : ∀ {n} v₁ v₂ {ρ : T.Env n} {c s} {k : ℕ → T.Value → Maybe C.Value ⊥} {n} → (∀ v → execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳[ n ] λ n → k n v) → execⁿ ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≳[ n ] λ n → (v₁ ∙ⁿ v₂) n >>= k n ∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} {zero} hyp = execⁿ ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≡⟨ refl ⟩≳ const never ≡⟨ sym never->>= ⟩≳ (λ n → (T.ƛ t₁ ρ₁ ∙ⁿ v₂) n >>= k n) ∎≳ ∙-correct (T.ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} {suc n} hyp = later ( execⁿ ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (T.ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ∘ suc ≳⟨⟩ execⁿ ⟨ comp t₁ (ret ∷ []) , ret c (comp-env ρ) ∷ s , cons (comp-val v₂) (comp-env ρ₁) ⟩ ∀≡⟨ (λ n → cong (λ ρ′ → execⁿ ⟨ comp t₁ (ret ∷ []) , ret c (comp-env ρ) ∷ s , ρ′ ⟩ n) (sym comp-cons)) ⟩≳ execⁿ ⟨ comp t₁ (ret ∷ []) , ret c (comp-env ρ) ∷ s , comp-env (cons v₂ ρ₁) ⟩ ≳⟨ (⟦⟧-correct t₁ {n = n} λ v → execⁿ ⟨ ret ∷ [] , val (comp-val v) ∷ ret c (comp-env ρ) ∷ s , comp-env (cons v₂ ρ₁) ⟩ ≳⟨ step⇓ ⟩ execⁿ ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≳⟨ hyp v ⟩ (λ n → k n v) ≳⟨ step⇓ ⟩ (λ n → k (suc n) v) ∎≳) ⟩ (λ n → evalⁿ t₁ (cons v₂ ρ₁) (suc n) >>= k (suc n)) ≳⟨⟩ (λ n → (T.ƛ t₁ ρ₁ ∙ⁿ v₂) (suc n) >>= k (suc n)) ∎≳) -- Note that the equality that is used here is syntactic. correct : ∀ t → exec ⟨ comp t [] , [] , nil ⟩ ≡ (⟦ t ⟧ nil >>= λ v → return (just (comp-val v))) correct t = exec ⟨ comp t [] , [] , nil ⟩ ≡⟨ cong (λ ρ → exec ⟨ comp t [] , [] , ρ ⟩) $ sym comp-nil ⟩ exec ⟨ comp t [] , [] , comp-env nil ⟩ ≡⟨⟩ ⨆ ( execⁿ ⟨ comp t [] , [] , comp-env nil ⟩ , _ ) ≡⟨ ≳→⨆≡⨆ 1 (⟦⟧-correct t $ λ v → execⁿ ⟨ [] , val (comp-val v) ∷ [] , comp-env nil ⟩ ≳⟨ step⇓ ⟩ const (return (just (comp-val v))) ∎≳) ⟩ ⨆ ( (λ n → evalⁿ t nil n >>= λ v → return (just (comp-val v))) , _ ) ≡⟨ sym ⨆->>= ⟩ (⟦ t ⟧ nil >>= λ v → return (just (comp-val v))) ∎
{ "alphanum_fraction": 0.3895036888, "avg_line_length": 37.9872611465, "ext": "agda", "hexsha": "7affb5f368bcccd14158a9d109c1cf8f92472165", "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": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/partiality-monad", "max_issues_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_line_length": 149, "max_stars_count": 2, "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_path": "src/Lambda/Simplified/Partiality-monad/Inductive/Compiler-correctness.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "num_tokens": 2198, "size": 5964 }
{-# OPTIONS --without-K --safe #-} -- In this module, we define F<:⁻, F<:ᵈ (F<: deterministic defined in Pierce92) and -- show that F<:⁻ subtyping is undecidable. module FsubMinus where open import Data.List as List open import Data.Nat open import Data.Maybe as Maybe open import Data.Product open import Data.Vec as Vec renaming (_∷_ to _‼_ ; [] to nil) hiding (_++_) open import Function open import Data.Empty renaming (⊥ to False) open import Relation.Nullary open import Relation.Unary using () renaming (Decidable to UDecidable) open import Relation.Binary using () renaming (Decidable to BDecidable) open import Relation.Binary.PropositionalEquality as ≡ open import Data.Nat.Properties as ℕₚ open import Data.Maybe.Properties as Maybeₚ open import Utils -- Definition of F<:⁻ -- -- F<:⁻ is defined by removing function types (_⟶_ in the paper) from F<:. module FsubMinus where infix 6 var_ infixr 6 Π<:_∙_ -- Types -- -- * ⊤ is a supertype of all types. -- * (var n) represents a type variable. -- * (Π<: S ∙ U) represent a universal type (∀ X <: S . U). data Ftyp : Set where ⊤ : Ftyp var_ : ℕ → Ftyp Π<:_∙_ : Ftyp → Ftyp → Ftyp -- typing context Env : Set Env = List Ftyp -- shifting operation of de Bruijn indices infixl 7 _↑_ _↑_ : Ftyp → ℕ → Ftyp ⊤ ↑ n = ⊤ (var x) ↑ n with n ≤? x ... | yes p = var (suc x) ... | no ¬p = var x (Π<: S ∙ U) ↑ n = Π<: S ↑ n ∙ U ↑ suc n infix 4 _<:_∈_ data _<:_∈_ : ℕ → Ftyp → Env → Set where hd : ∀ {T Γ} → 0 <: T ↑ 0 ∈ T ∷ Γ tl : ∀ {n T T′ Γ} → n <: T ∈ Γ → suc n <: T ↑ 0 ∈ T′ ∷ Γ -- subtyping judgment of F<:⁻ -- The statement of the rules should be self-explanatory. infix 4 _⊢F_<:_ data _⊢F_<:_ : Env → Ftyp → Ftyp → Set where ftop : ∀ {Γ T} → Γ ⊢F T <: ⊤ fvrefl : ∀ {Γ n} → Γ ⊢F var n <: var n fbinds : ∀ {Γ n T U} → n <: T ∈ Γ → Γ ⊢F T <: U → Γ ⊢F var n <: U fall : ∀ {Γ S₁ S₂ U₁ U₂} → Γ ⊢F S₂ <: S₁ → Γ ‣ S₂ ! ⊢F U₁ <: U₂ → Γ ⊢F Π<: S₁ ∙ U₁ <: Π<: S₂ ∙ U₂ -- The remaining are some technical setup. env-lookup : Env → ℕ → Maybe Ftyp env-lookup [] n = nothing env-lookup (T ∷ Γ) zero = just $ T ↑ 0 env-lookup (T ∷ Γ) (suc n) = Maybe.map (_↑ 0) $ env-lookup Γ n lookup⇒<:∈ : ∀ {Γ n T} → env-lookup Γ n ≡ just T → n <: T ∈ Γ lookup⇒<:∈ {[]} {n} () lookup⇒<:∈ {T ∷ Γ} {zero} refl = hd lookup⇒<:∈ {T ∷ Γ} {suc n} eq with env-lookup Γ n | lookup⇒<:∈ {Γ} {n} ... | nothing | rec with eq ... | () lookup⇒<:∈ {T ∷ Γ} {suc n} refl | just T′ | rec = tl (rec refl) <:∈⇒lookup : ∀ {Γ n T} → n <: T ∈ Γ → env-lookup Γ n ≡ just T <:∈⇒lookup hd = refl <:∈⇒lookup (tl <:∈) rewrite <:∈⇒lookup <:∈ = refl env-lookup′ : Env → ℕ → Maybe Ftyp env-lookup′ Γ n = Maybe.map (repeat (suc n) (_↑ 0)) (lookupOpt Γ n) env-lookup-same : ∀ Γ n → env-lookup Γ n ≡ env-lookup′ Γ n env-lookup-same [] n = refl env-lookup-same (T ∷ Γ) zero = refl env-lookup-same (T ∷ Γ) (suc n) rewrite env-lookup-same Γ n = sym $ Maybeₚ.map-compose (lookupOpt Γ n) <:∈-map : ∀ {a} {A : Set a} {n T} {f : A → Ftyp} {_↑′_ : A → ℕ → A} Γ → (∀ a n → f a ↑ n ≡ f (a ↑′ n)) → n <: T ∈ List.map f Γ → ∃ λ a → T ≡ f a <:∈-map {f = f} Γ comm d = aux _ d refl where aux : ∀ {n T Γ*} Γ → n <: T ∈ Γ* → Γ* ≡ List.map f Γ → ∃ λ a → T ≡ f a aux [] hd () aux (T ∷ Γ) hd refl = -, comm _ _ aux [] (tl <:∈) () aux (T ∷ Γ) (tl <:∈) refl with aux Γ <:∈ refl ... | a , refl = -, comm _ _ <:∈-func : ∀ {x T T′ Γ} → x <: T ∈ Γ → x <: T′ ∈ Γ → T ≡ T′ <:∈-func hd hd = refl <:∈-func (tl T∈Γ) (tl T′∈Γ) = cong (_↑ 0) (<:∈-func T∈Γ T′∈Γ) Ftyp-measure : Ftyp → ℕ Ftyp-measure ⊤ = 1 Ftyp-measure (var x) = 1 Ftyp-measure (Π<: S ∙ U) = Ftyp-measure S + Ftyp-measure U Ftyp-measure≥1 : ∀ T → Ftyp-measure T ≥ 1 Ftyp-measure≥1 ⊤ = s≤s z≤n Ftyp-measure≥1 (var _) = s≤s z≤n Ftyp-measure≥1 (Π<: S ∙ U) = ≤-trans (Ftyp-measure≥1 S) (≤-stepsʳ _ ≤-refl) ↑-idx : ℕ → ℕ → ℕ ↑-idx x n with n ≤? x ... | yes p = suc x ... | no ¬p = x ↑-var : ∀ x n → (var x) ↑ n ≡ var (↑-idx x n) ↑-var x n with n ≤? x ... | yes p = refl ... | no ¬p = refl Ftyp-measure-↑ : ∀ T m → Ftyp-measure (T ↑ m) ≡ Ftyp-measure T Ftyp-measure-↑ ⊤ m = refl Ftyp-measure-↑ (var x) m rewrite ↑-var x m = refl Ftyp-measure-↑ (Π<: S ∙ U) m rewrite Ftyp-measure-↑ S m | Ftyp-measure-↑ U (suc m) = refl F-measure : ∀ {Γ S U} → Γ ⊢F S <: U → ℕ F-measure ftop = 1 F-measure fvrefl = 1 F-measure (fbinds _ D) = 1 + F-measure D F-measure (fall D₁ D₂) = 1 + F-measure D₁ + F-measure D₂ F-deriv = Σ (Env × Ftyp × Ftyp) λ { (Γ , S , U) → Γ ⊢F S <: U } env : F-deriv → Env env ((Γ , _) , _) = Γ typ₁ : F-deriv → Ftyp typ₁ ((_ , S , U) , _) = S typ₂ : F-deriv → Ftyp typ₂ ((_ , S , U) , _) = U F-measure-packed : F-deriv → ℕ F-measure-packed (_ , D) = F-measure D ≡⊤-dec : UDecidable (_≡ ⊤) ≡⊤-dec ⊤ = yes refl ≡⊤-dec (var _) = no (λ ()) ≡⊤-dec (Π<: _ ∙ _) = no (λ ()) Π<:-injective : ∀ {S U S′ U′} → Π<: S ∙ U ≡ Π<: S′ ∙ U′ → S ≡ S′ × U ≡ U′ Π<:-injective refl = refl , refl Ftyp-≡-dec : BDecidable (_≡_ {A = Ftyp}) Ftyp-≡-dec ⊤ ⊤ = yes refl Ftyp-≡-dec ⊤ (var _) = no (λ ()) Ftyp-≡-dec ⊤ (Π<: _ ∙ _) = no (λ ()) Ftyp-≡-dec (var _) ⊤ = no (λ ()) Ftyp-≡-dec (var x) (var y) with x ≟ y ... | yes x≡y = yes (cong var_ x≡y) ... | no x≢y = no (λ { refl → x≢y refl }) Ftyp-≡-dec (var _) (Π<: _ ∙ _) = no (λ ()) Ftyp-≡-dec (Π<: _ ∙ _) ⊤ = no (λ ()) Ftyp-≡-dec (Π<: _ ∙ _) (var _) = no (λ ()) Ftyp-≡-dec (Π<: S ∙ U) (Π<: S′ ∙ U′) with Ftyp-≡-dec S S′ | Ftyp-≡-dec U U′ ... | yes S≡S′ | yes U≡U′ = yes (cong₂ Π<:_∙_ S≡S′ U≡U′) ... | yes S≡S′ | no U≢U′ = no λ Π<:≡ → U≢U′ (proj₂ (Π<:-injective Π<:≡)) ... | no S≢S′ | yes U≡U′ = no (λ Π<:≡ → S≢S′ (proj₁ (Π<:-injective Π<:≡))) ... | no S≢S′ | no U≢U′ = no (λ Π<:≡ → S≢S′ (proj₁ (Π<:-injective Π<:≡))) -- Definition of F<: -- -- Here we also define full F<:. We do not use it anywhere. module Full where infix 6 var_ infixr 6 _⇒_ Π<:_∙_ -- Types -- -- * ⊤ is a supertype of all types. -- * (var n) represent a type variable. -- * (S ⇒ U) represents a function type (S ⟶ U). -- * (Π<: S ∙ U) represents a universal type (∀ X <: S . U). data Ftyp : Set where ⊤ : Ftyp var_ : ℕ → Ftyp _⇒_ : Ftyp → Ftyp → Ftyp Π<:_∙_ : Ftyp → Ftyp → Ftyp Env : Set Env = List Ftyp infixl 7 _↑_ _↑_ : Ftyp → ℕ → Ftyp ⊤ ↑ n = ⊤ (var x) ↑ n with n ≤? x ... | yes p = var (suc x) ... | no ¬p = var x (S ⇒ U) ↑ n = S ↑ n ⇒ U ↑ n (Π<: S ∙ U) ↑ n = Π<: S ↑ n ∙ U ↑ suc n infix 4 _<:_∈_ data _<:_∈_ : ℕ → Ftyp → Env → Set where hd : ∀ {T Γ} → 0 <: T ↑ 0 ∈ T ∷ Γ tl : ∀ {n T T′ Γ} → n <: T ∈ Γ → suc n <: T ↑ 0 ∈ T′ ∷ Γ infix 4 _⊢F_<:_ data _⊢F_<:_ : Env → Ftyp → Ftyp → Set where ftop : ∀ {Γ T} → Γ ⊢F T <: ⊤ fvrefl : ∀ {Γ n} → Γ ⊢F var n <: var n fbinds : ∀ {Γ n T U} → n <: T ∈ Γ → Γ ⊢F T <: U → Γ ⊢F var n <: U ffun : ∀ {Γ S₁ S₂ U₁ U₂} → Γ ⊢F S₂ <: S₁ → Γ ⊢F U₁ <: U₂ → Γ ⊢F S₁ ⇒ U₁ <: S₂ ⇒ U₂ fall : ∀ {Γ S₁ S₂ U₁ U₂} → Γ ⊢F S₂ <: S₁ → S₂ ∷ Γ ⊢F U₁ <: U₂ → Γ ⊢F Π<: S₁ ∙ U₁ <: Π<: S₂ ∙ U₂ env-lookup : Env → ℕ → Maybe Ftyp env-lookup [] n = nothing env-lookup (T ∷ Γ) zero = just $ T ↑ 0 env-lookup (T ∷ Γ) (suc n) = Maybe.map (_↑ 0) $ env-lookup Γ n lookup⇒<:∈ : ∀ {Γ n T} → env-lookup Γ n ≡ just T → n <: T ∈ Γ lookup⇒<:∈ {[]} {n} () lookup⇒<:∈ {T ∷ Γ} {zero} refl = hd lookup⇒<:∈ {T ∷ Γ} {suc n} eq with env-lookup Γ n | lookup⇒<:∈ {Γ} {n} ... | nothing | rec with eq ... | () lookup⇒<:∈ {T ∷ Γ} {suc n} refl | just T′ | rec = tl (rec refl) <:∈⇒lookup : ∀ {Γ n T} → n <: T ∈ Γ → env-lookup Γ n ≡ just T <:∈⇒lookup hd = refl <:∈⇒lookup (tl <:∈) rewrite <:∈⇒lookup <:∈ = refl env-lookup′ : Env → ℕ → Maybe Ftyp env-lookup′ Γ n = Maybe.map (repeat (suc n) (_↑ 0)) (lookupOpt Γ n) env-lookup-same : ∀ Γ n → env-lookup Γ n ≡ env-lookup′ Γ n env-lookup-same [] n = refl env-lookup-same (T ∷ Γ) zero = refl env-lookup-same (T ∷ Γ) (suc n) rewrite env-lookup-same Γ n = sym $ Maybeₚ.map-compose (lookupOpt Γ n) open FsubMinus -- Undecidability of F<: -- -- Here we show a reduction proof from F<:⁻ to F<:. Assuming F<:⁻ subtyping being -- undecidable (which is about to be shown below), we formalize that F<: subtyping is -- undecidable. module FsubUndec where -- the interpretation function of types from F<:⁻ to F<: infixl 5 _* _* : Ftyp → Full.Ftyp ⊤ * = Full.⊤ var x * = Full.var x Π<: T₁ ∙ T₂ * = Full.Π<: T₁ * ∙ (T₂ *) *-↑-comm : ∀ (T : Ftyp) n → (T *) Full.↑ n ≡ (T ↑ n) * *-↑-comm ⊤ n = refl *-↑-comm (var x) n with n ≤? x ... | yes p = refl ... | no ¬p = refl *-↑-comm (Π<: S ∙ U) n rewrite *-↑-comm S n | *-↑-comm U (suc n) = refl repeat*-↑-comm : ∀ T n m → repeat n (Full._↑ m) (T *) ≡ (repeat n (_↑ m) T) * repeat*-↑-comm T zero m = refl repeat*-↑-comm T (suc n) m rewrite repeat*-↑-comm T n m = *-↑-comm (repeat n (_↑ m) T) m *-injective : ∀ {S U} → S * ≡ U * → S ≡ U *-injective {⊤} {⊤} refl = refl *-injective {⊤} {var x} () *-injective {⊤} {Π<: _ ∙ _} () *-injective {var x} {⊤} () *-injective {var x} {var .x} refl = refl *-injective {var _} {Π<: _ ∙ _} () *-injective {Π<: S ∙ S₁} {⊤} () *-injective {Π<: _ ∙ _} {var x} () *-injective {Π<: S ∙ S₁} {Π<: U ∙ U₁} eq with S * | U * | *-injective {S} {U} | S₁ * | U₁ * | *-injective {S₁} {U₁} ... | S* | U* | r | S₁* | U₁* | r₁ with eq ... | refl rewrite r refl | r₁ refl = refl Full<:∈⇒<:∈ : ∀ {Γ n T} → n Full.<: T * ∈ List.map _* Γ → n <: T ∈ Γ Full<:∈⇒<:∈ {Γ} {n} <:∈ with Full.<:∈⇒lookup <:∈ ... | eq rewrite Full.env-lookup-same (List.map _* Γ) n with lookupOpt (List.map _* Γ) n | lookupOpt-map-inv {f = _*} Γ {n} ... | just T | inv with inv refl ... | T′ , refl , lk with just-injective eq ... | eq′ rewrite repeat*-↑-comm T′ n 0 | *-↑-comm (repeat n (_↑ 0) T′) 0 with *-injective eq′ ... | refl = lookup⇒<:∈ (trans (env-lookup-same Γ n) aux) where aux : env-lookup′ Γ n ≡ just (repeat n (_↑ 0) T′ ↑ 0) aux rewrite lk = refl Full<:∈⇒<:∈ {Γ} {n} <:∈ | () | nothing | _ <:∈⇒Full<:∈ : ∀ {Γ n T} → n <: T ∈ Γ → n Full.<: T * ∈ List.map _* Γ <:∈⇒Full<:∈ (hd {T}) rewrite sym $ *-↑-comm T 0 = Full.hd <:∈⇒Full<:∈ (tl {T = T} <:∈) rewrite sym $ *-↑-comm T 0 = Full.tl (<:∈⇒Full<:∈ <:∈) full⇒minus-gen : ∀ {Γ* S* U*} → Γ* Full.⊢F S* <: U* → ∀ {Γ S U} → Γ* ≡ List.map _* Γ → S* ≡ (S *) → U* ≡ (U *) → Γ ⊢F S <: U full⇒minus-gen Full.ftop {Γ} {S} {⊤} eqΓ eqS refl = ftop full⇒minus-gen Full.ftop {Γ} {S} {var x} eqΓ eqS () full⇒minus-gen Full.ftop {Γ} {S} {Π<: U ∙ U₁} eqΓ eqS () full⇒minus-gen Full.fvrefl {Γ} {⊤} {⊤} eqΓ () eqU full⇒minus-gen Full.fvrefl {Γ} {var x} {⊤} eqΓ refl () full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {⊤} eqΓ () eqU full⇒minus-gen Full.fvrefl {Γ} {⊤} {var x} eqΓ () eqU full⇒minus-gen Full.fvrefl {Γ} {var x} {var .x} eqΓ refl refl = fvrefl full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {var x} eqΓ () eqU full⇒minus-gen Full.fvrefl {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU full⇒minus-gen Full.fvrefl {Γ} {var x} {Π<: U ∙ U₁} eqΓ refl () full⇒minus-gen Full.fvrefl {Γ} {Π<: S ∙ S₁} {Π<: U ∙ U₁} eqΓ () eqU full⇒minus-gen (Full.fbinds T∈Γ* Dfull) {Γ} {⊤} {U} eqΓ () eqU full⇒minus-gen (Full.fbinds {n = n} T∈Γ* Dfull) {Γ} {var x} {U} eqΓ refl eqU = aux where T′∈Γ : ∀ {Γ* T} → n Full.<: T ∈ Γ* → Γ* ≡ List.map _* Γ → ∃[ T′ ] (T ≡ T′ *) T′∈Γ <:∈ refl with Full.<:∈⇒lookup <:∈ ... | eq rewrite Full.env-lookup-same (List.map _* Γ) n with lookupOpt (List.map _* Γ) n | inspect (lookupOpt (List.map _* Γ)) n ... | just T | [ lk ] with lookupOpt-map-inv Γ lk | just-injective eq ... | T′ , refl , lkeq | eq′ rewrite repeat*-↑-comm T′ n 0 | *-↑-comm (repeat n (_↑ 0) T′) 0 = -, sym eq′ T′∈Γ <:∈ refl | () | nothing | _ aux : Γ ⊢F var n <: U aux with T′∈Γ T∈Γ* eqΓ ... | T′ , refl rewrite eqΓ = fbinds (Full<:∈⇒<:∈ T∈Γ*) (full⇒minus-gen Dfull refl refl eqU) full⇒minus-gen (Full.fbinds T∈Γ* Dfull) {Γ} {Π<: S ∙ S₁} {U} eqΓ () eqU full⇒minus-gen (Full.ffun _ _) {Γ} {⊤} {U} eqΓ () eqU full⇒minus-gen (Full.ffun _ _) {Γ} {var x₂} {U} eqΓ () eqU full⇒minus-gen (Full.ffun _ _) {Γ} {Π<: S ∙ S₁} {U} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {⊤} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {var x} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {⊤} {Π<: U ∙ U₁} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {⊤} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {var x₁} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {var x} {Π<: U ∙ U₁} eqΓ () eqU full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S ∙ S₁} {⊤} eqΓ refl () full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S ∙ S₁} {var x} eqΓ refl () full⇒minus-gen (Full.fall Dp Dbody) {Γ} {Π<: S₁ ∙ U₁} {Π<: S₂ ∙ U₂} eqΓ refl refl = fall (full⇒minus-gen Dp eqΓ refl refl) (full⇒minus-gen Dbody (aux eqΓ) refl refl) where aux : ∀ {Γ*} → Γ* ≡ List.map _* Γ → (S₂ *) ∷ Γ* ≡ (S₂ *) ∷ List.map _* Γ aux refl = refl -- The following two functions accomplish the reduction proof. full⇒minus : ∀ {Γ S U} → List.map _* Γ Full.⊢F S * <: U * → Γ ⊢F S <: U full⇒minus Dfull = full⇒minus-gen Dfull refl refl refl minus⇒full : ∀ {Γ S U} → Γ ⊢F S <: U → List.map _* Γ Full.⊢F S * <: U * minus⇒full ftop = Full.ftop minus⇒full fvrefl = Full.fvrefl minus⇒full {Γ} (fbinds T∈Γ Dminus) = Full.fbinds (<:∈⇒Full<:∈ T∈Γ) (minus⇒full Dminus) minus⇒full (fall Dp Db) = Full.fall (minus⇒full Dp) (minus⇒full Db) -- Definition of F<:ᵈ -- -- Definition of F<:ᵈ F<:ᵈ (F<: deterministic) is an intermediate construction in -- Pierce92 towards the undecidability proof of F<: subtyping. This intermediate -- construction is also shown undecidable and we directly use that result here. module DeterministicFsubSized where open import Induction.Nat import Relation.Binary.EqReasoning as Eq infix 6 var⁻_ infixr 6 Π⁺<:_∙¬_ Π⁻<:⊤∙¬_ -- Types -- -- Types in F<:ᵈ are divided into two parts and the two parts are mutually defined. -- The two parts are positive types [Ftyp⁺] and negative types [Ftyp⁻] and defined -- as follows. mutual -- Positive types -- * ⊤⁺ corresponds to ⊤ in F<:⁻. -- * (Π⁺<: Ts ∙¬ U) represents a universal type where all types involved are negative types (∀ X₁ <: T₁ ... ∀ Xₙ <: Tₙ . ∀ X <: U . X). data Ftyp⁺ (n : ℕ) : Set where ⊤⁺ : Ftyp⁺ n Π⁺<:_∙¬_ : Vec (Ftyp⁻ n) n → Ftyp⁻ n → Ftyp⁺ n -- Negative types -- * (var⁻ n) corresponds to a type variable in F<:⁻. -- * (Π⁻<:⊤∙¬_ T) represents a universal type where all parameter types are ⊤ and T is positive (∀ X₁ <: ⊤ ... ∀ Xₙ <: ⊤ . ∀ X <: T . X). data Ftyp⁻ (n : ℕ) : Set where var⁻_ : ℕ → Ftyp⁻ n Π⁻<:⊤∙¬_ : Ftyp⁺ n → Ftyp⁻ n -- shifting operation for both positive and negative types infixl 7 _↑⁺_ _↑⁺_ ⟦_↑⁻_⟧ mutual _↑⁺_ : ∀ {n} → Ftyp⁺ n → ℕ → Ftyp⁺ n ⊤⁺ ↑⁺ n = ⊤⁺ _↑⁺_ {m} (Π⁺<: S ∙¬ U) n = Π⁺<: ⟦ S ↑⁻ n ⟧ ∙¬ (U ↑⁻ (m + n)) _↑⁻_ : ∀ {n} → Ftyp⁻ n → ℕ → Ftyp⁻ n (var⁻ x) ↑⁻ n with n ≤? x ... | yes p = var⁻ (suc x) ... | no ¬p = var⁻ x _↑⁻_ {m} (Π⁻<:⊤∙¬ T) n = Π⁻<:⊤∙¬ (T ↑⁺ (m + n)) ⟦_↑⁻_⟧ : ∀ {n m} → Vec (Ftyp⁻ n) m → ℕ → Vec (Ftyp⁻ n) m ⟦ nil ↑⁻ n ⟧ = nil ⟦ T ‼ S ↑⁻ n ⟧ = T ↑⁻ n ‼ ⟦ S ↑⁻ suc n ⟧ -- In F<:ᵈ, typing contexts consist only of negative types. NEnv : ℕ → Set NEnv n = List (Ftyp⁻ n) nenv-lookup : ∀ {n} → NEnv n → ℕ → Maybe (Ftyp⁻ n) nenv-lookup Γ n = Maybe.map (repeat (suc n) (_↑⁻ 0)) (lookupOpt Γ n) -- subtyping judgment of F<:ᵈ -- -- For a fixed n, a subtyping judgment of F<:ᵈ is a ternary predicate, among a -- typing context (consisting of negative types), a negative type and a positive -- type. A subtyping judgment in F<:ᵈ asserts that a negative type is a subtype of -- a positive type in the given context. Notice that there is no subtyping relation -- between two negative types or two positive types. infix 4 [_]_⊢FD_<:_ data [_]_⊢FD_<:_ (n : ℕ) : NEnv n → Ftyp⁻ n → Ftyp⁺ n → Set where fdtop : ∀ {Γ T} → [ n ] Γ ⊢FD T <: ⊤⁺ fdvar : ∀ {Γ m T S U} → nenv-lookup Γ m ≡ just T → [ n ] Γ ⊢FD T <: Π⁺<: S ∙¬ U → [ n ] Γ ⊢FD var⁻ m <: Π⁺<: S ∙¬ U fdall : ∀ {Γ T S U} → [ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ S ⊢FD U <: T → [ n ] Γ ⊢FD Π⁻<:⊤∙¬ T <: Π⁺<: S ∙¬ U infix 5 _*⁺ _*⁻ infix 6 Π⁻[_]∙_ Π⁺_∙_ -- the interpretation function of types from F<:ᵈ to F<:⁻ mutual _*⁺ : ∀ {n} → Ftyp⁺ n → Ftyp ⊤⁺ *⁺ = ⊤ Π⁺<: S ∙¬ U *⁺ = Π⁻[ S ]∙ U Π⁻[_]∙_ : ∀ {n m} → Vec (Ftyp⁻ n) m → Ftyp⁻ n → Ftyp Π⁻[ nil ]∙ U = Π<: U *⁻ ∙ var zero Π⁻[ S ‼ Ss ]∙ U = Π<: S *⁻ ∙ Π⁻[ Ss ]∙ U _*⁻ : ∀ {n} → Ftyp⁻ n → Ftyp var⁻ n *⁻ = var n _*⁻ {n} (Π⁻<:⊤∙¬ T) = Π⁺ n ∙ T Π⁺_∙_ : ∀ {n} → ℕ → Ftyp⁺ n → Ftyp Π⁺ zero ∙ T = Π<: T *⁺ ∙ var zero Π⁺ suc n ∙ T = Π<: ⊤ ∙ Π⁺ n ∙ T module _ where open Eq (setoid ℕ) mutual *-↑-comm⁺ : ∀ {m} (T : Ftyp⁺ m) n → (T *⁺) ↑ n ≡ (T ↑⁺ n) *⁺ *-↑-comm⁺ ⊤⁺ n = refl *-↑-comm⁺ (Π⁺<: S ∙¬ U) n = Π-↑-comm⁻ S U n Π-↑-comm⁻ : ∀ {i j} (S : Vec (Ftyp⁻ i) j) (U : Ftyp⁻ i) n → (Π⁻[ S ]∙ U) ↑ n ≡ Π⁻[ ⟦ S ↑⁻ n ⟧ ]∙ (U ↑⁻ (j + n)) Π-↑-comm⁻ nil U n rewrite *-↑-comm⁻ U n = refl Π-↑-comm⁻ {j = suc j} (T ‼ S) U n rewrite *-↑-comm⁻ T n | Π-↑-comm⁻ S U (suc n) | +-suc j n = refl *-↑-comm⁻ : ∀ {m} (T : Ftyp⁻ m) n → (T *⁻) ↑ n ≡ (T ↑⁻ n) *⁻ *-↑-comm⁻ (var⁻ x) n with n ≤? x ... | yes p = refl ... | no ¬p = refl *-↑-comm⁻ (Π⁻<:⊤∙¬ T) n = Π-↑-comm⁺ _ T n Π-↑-comm⁺ : ∀ {i} j (T : Ftyp⁺ i) n → (Π⁺ j ∙ T) ↑ n ≡ Π⁺ j ∙ (T ↑⁺ (j + n)) Π-↑-comm⁺ zero T n rewrite *-↑-comm⁺ T n = refl Π-↑-comm⁺ (suc j) T n rewrite Π-↑-comm⁺ j T (suc n) | +-suc j n = refl repeat*-↑-comm⁻ : ∀ {i} (T : Ftyp⁻ i) n m → repeat n (_↑ m) (T *⁻) ≡ (repeat n (_↑⁻ m) T) *⁻ repeat*-↑-comm⁻ T zero m = refl repeat*-↑-comm⁻ T (suc n) m rewrite repeat*-↑-comm⁻ T n m = *-↑-comm⁻ (repeat n (_↑⁻ m) T) m mutual *-injective⁺ : ∀ {n} {S U : Ftyp⁺ n} → S *⁺ ≡ U *⁺ → S ≡ U *-injective⁺ {n} {⊤⁺} {⊤⁺} eq = refl *-injective⁺ {.0} {⊤⁺} {Π⁺<: nil ∙¬ _} () *-injective⁺ {.(suc _)} {⊤⁺} {Π⁺<: _ ‼ _ ∙¬ _} () *-injective⁺ {n} {Π⁺<: S ∙¬ U} {⊤⁺} eq = ⊥-elim $ aux eq where aux : ∀ {n m} {S : Vec (Ftyp⁻ n) m} {U} → ¬ Π⁻[ S ]∙ U ≡ ⊤ aux {S = nil} () aux {S = _ ‼ S} () *-injective⁺ {n} {Π⁺<: S₁ ∙¬ U₁} {Π⁺<: S₂ ∙¬ U₂} eq with Π-injective⁻ eq ... | refl , refl = refl Π-injective⁻ : ∀ {n m} {S₁ S₂ : Vec (Ftyp⁻ n) m} {U₁ U₂ : Ftyp⁻ n} → Π⁻[ S₁ ]∙ U₁ ≡ Π⁻[ S₂ ]∙ U₂ → S₁ ≡ S₂ × U₁ ≡ U₂ Π-injective⁻ {S₁ = nil} {nil} {U₁} {U₂} eq with U₁ *⁻ | U₂ *⁻ | *-injective⁻ {S = U₁} {U₂} ... | U₁* | U₂* | rec with eq ... | refl = refl , rec refl Π-injective⁻ {S₁ = S ‼ S₁} {S′ ‼ S₂} {U₁} {U₂} eq with S *⁻ | S′ *⁻ | Π⁻[ S₁ ]∙ U₁ | Π⁻[ S₂ ]∙ U₂ | *-injective⁻ {S = S} {S′} | Π-injective⁻ {S₁ = S₁} {S₂} {U₁} {U₂} ... | S* | S′* | Π₁ | Π₂ | recS | rec with eq ... | refl with recS refl | rec refl ... | refl | refl , eqU = refl , eqU *-injective⁻ : ∀ {n} {S U : Ftyp⁻ n} → S *⁻ ≡ U *⁻ → S ≡ U *-injective⁻ {n} {var⁻ x} {var⁻ .x} refl = refl *-injective⁻ {zero} {var⁻ _} {Π⁻<:⊤∙¬ _} () *-injective⁻ {suc n} {var⁻ _} {Π⁻<:⊤∙¬ _} () *-injective⁻ {n} {Π⁻<:⊤∙¬ T} {var⁻ x} eq = ⊥-elim $ aux _ eq where aux : ∀ {n x} {T : Ftyp⁺ n} m → ¬ Π⁺ m ∙ T ≡ var x aux zero () aux (suc m) () *-injective⁻ {n} {Π⁻<:⊤∙¬ T₁} {Π⁻<:⊤∙¬ T₂} eq with Π-injective⁺ n eq ... | refl = refl Π-injective⁺ : ∀ {n} {T₁ T₂ : Ftyp⁺ n} m → Π⁺ m ∙ T₁ ≡ Π⁺ m ∙ T₂ → T₁ ≡ T₂ Π-injective⁺ {T₁ = T₁} {T₂} zero eq with T₁ *⁺ | T₂ *⁺ | *-injective⁺ {S = T₁} {T₂} ... | T₁* | T₂* | rec with eq ... | refl = rec refl Π-injective⁺ {T₁ = T₁} {T₂} (suc m) eq with Π⁺ m ∙ T₁ | Π⁺ m ∙ T₂ | Π-injective⁺ {T₁ = T₁} {T₂} m ... | Π₁ | Π₂ | rec with eq ... | refl = rec refl data Pi (P Q : Ftyp → Set) : ℕ → Ftyp → Set where pzero : ∀ {U} → Q U → Pi P Q zero (Π<: U ∙ var zero) psuc : ∀ {n S T} → P S → Pi P Q n T -> Pi P Q (suc n) (Π<: S ∙ T) -- two predicates that capture the images of the interpretation functions mutual -- Covar captures the image of the interpretation function from positive types to F<:. data Covar (n : ℕ) : Ftyp → Set where cvtop : Covar n ⊤ cvΠ : ∀ {T} → Pi (Contra n) (Contra n) n T → Covar n T -- Contra captures the image of the interpretation function from negative types to F<:. data Contra (n : ℕ) : Ftyp → Set where cnvar : ∀ m → Contra n (var m) cnΠ : ∀ {T} → Pi (⊤ ≡_) (Covar n) n T → Contra n T infix 5 ⟦_⟧⁺ ⟦_⟧⁻ -- the inverse functions of the interpretation functions mutual ⟦_⟧⁺ : ∀ {n T} → Covar n T → Ftyp⁺ n ⟦ cvtop ⟧⁺ = ⊤⁺ ⟦ cvΠ P ⟧⁺ = Π⁺<: ∥ P ∥⁺₁ ∙¬ ∥ P ∥⁺₂ ∥_∥⁺₁ : ∀ {n m T} → Pi (Contra n) (Contra n) m T → Vec (Ftyp⁻ n) m ∥ pzero U ∥⁺₁ = nil ∥ psuc S P ∥⁺₁ = ⟦ S ⟧⁻ ‼ ∥ P ∥⁺₁ ∥_∥⁺₂ : ∀ {n m T} → Pi (Contra n) (Contra n) m T → Ftyp⁻ n ∥ pzero U ∥⁺₂ = ⟦ U ⟧⁻ ∥ psuc S P ∥⁺₂ = ∥ P ∥⁺₂ ⟦_⟧⁻ : ∀ {n T} → Contra n T → Ftyp⁻ n ⟦ cnvar m ⟧⁻ = var⁻ m ⟦ cnΠ P ⟧⁻ = Π⁻<:⊤∙¬ ∥ P ∥⁻ ∥_∥⁻ : ∀ {n m T} → Pi (⊤ ≡_) (Covar n) m T → Ftyp⁺ n ∥ pzero T ∥⁻ = ⟦ T ⟧⁺ ∥ psuc S P ∥⁻ = ∥ P ∥⁻ mutual ⟦⟧⁺*⁺⇒id : ∀ {n T} (cT : Covar n T) → (⟦ cT ⟧⁺ *⁺) ≡ T ⟦⟧⁺*⁺⇒id cvtop = refl ⟦⟧⁺*⁺⇒id (cvΠ P) = ∥∥⁻Π⇒id P ∥∥⁻Π⇒id : ∀ {n m T} (P : Pi (Contra n) (Contra n) m T) → Π⁻[ ∥ P ∥⁺₁ ]∙ ∥ P ∥⁺₂ ≡ T ∥∥⁻Π⇒id (pzero U) rewrite ⟦⟧⁻*⁻⇒id U = refl ∥∥⁻Π⇒id (psuc S P) rewrite ⟦⟧⁻*⁻⇒id S | ∥∥⁻Π⇒id P = refl ⟦⟧⁻*⁻⇒id : ∀ {n T} (cT : Contra n T) → (⟦ cT ⟧⁻ *⁻) ≡ T ⟦⟧⁻*⁻⇒id (cnvar m) = refl ⟦⟧⁻*⁻⇒id (cnΠ P) = ∥∥⁺Π⇒id P ∥∥⁺Π⇒id : ∀ {n m T} (P : Pi (⊤ ≡_) (Covar n) m T) → Π⁺ m ∙ ∥ P ∥⁻ ≡ T ∥∥⁺Π⇒id (pzero U) rewrite ⟦⟧⁺*⁺⇒id U = refl ∥∥⁺Π⇒id (psuc refl P) rewrite ∥∥⁺Π⇒id P = refl infix 5 *⟦_⟧⁺ *⟦_⟧⁻ *∥_,_∥⁺ mutual *⟦_⟧⁺ : ∀ {n} (T : Ftyp⁺ n) → Covar n (T *⁺) *⟦ ⊤⁺ ⟧⁺ = cvtop *⟦ Π⁺<: S ∙¬ U ⟧⁺ = cvΠ *∥ S , U ∥⁺ *∥_,_∥⁺ : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) → Pi (Contra n) (Contra n) m (Π⁻[ S ]∙ U) *∥ nil , U ∥⁺ = pzero *⟦ U ⟧⁻ *∥ S ‼ Ss , U ∥⁺ = psuc *⟦ S ⟧⁻ *∥ Ss , U ∥⁺ *⟦_⟧⁻ : ∀ {n} (T : Ftyp⁻ n) → Contra n (T *⁻) *⟦ var⁻ x ⟧⁻ = cnvar x *⟦ Π⁻<:⊤∙¬ T ⟧⁻ = cnΠ *∥ _ , T ∥⁻ *∥_,_∥⁻ : ∀ {n} m (T : Ftyp⁺ n) → Pi (⊤ ≡_) (Covar n) m (Π⁺ m ∙ T) *∥ zero , T ∥⁻ = pzero *⟦ T ⟧⁺ *∥ suc m , T ∥⁻ = psuc refl *∥ m , T ∥⁻ mutual *⁺⟦⟧⁺⇒id : ∀ {n} (T : Ftyp⁺ n) → ⟦ *⟦ T ⟧⁺ ⟧⁺ ≡ T *⁺⟦⟧⁺⇒id ⊤⁺ = refl *⁺⟦⟧⁺⇒id (Π⁺<: S ∙¬ U) rewrite *∥∥⁺₁⇒id S U | *∥∥⁺₂⇒id S U = refl *∥∥⁺₁⇒id : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) → ∥ *∥ S , U ∥⁺ ∥⁺₁ ≡ S *∥∥⁺₁⇒id nil U = refl *∥∥⁺₁⇒id (S ‼ Ss) U rewrite *⁻⟦⟧⁻⇒id S | *∥∥⁺₁⇒id Ss U = refl *∥∥⁺₂⇒id : ∀ {n m} (S : Vec (Ftyp⁻ n) m) (U : Ftyp⁻ n) → ∥ *∥ S , U ∥⁺ ∥⁺₂ ≡ U *∥∥⁺₂⇒id nil U = *⁻⟦⟧⁻⇒id U *∥∥⁺₂⇒id (S ‼ Ss) U = *∥∥⁺₂⇒id Ss U *⁻⟦⟧⁻⇒id : ∀ {n} (T : Ftyp⁻ n) → ⟦ *⟦ T ⟧⁻ ⟧⁻ ≡ T *⁻⟦⟧⁻⇒id (var⁻ x) = refl *⁻⟦⟧⁻⇒id {n} (Π⁻<:⊤∙¬ T) rewrite *∥∥⁻⇒id n T = refl *∥∥⁻⇒id : ∀ {n} m (T : Ftyp⁺ n) → ∥ *∥ m , T ∥⁻ ∥⁻ ≡ T *∥∥⁻⇒id zero T = *⁺⟦⟧⁺⇒id T *∥∥⁻⇒id (suc m) T = *∥∥⁻⇒id m T open Measure <-wellFounded F-measure-packed renaming (wfRec to F-rec) minus⇒deterministic-gen : ∀ (D : F-deriv) → ∀ n {Γ} (S : Contra n (typ₁ D)) (U : Covar n (typ₂ D)) → env D ≡ List.map _*⁻ Γ → [ n ] Γ ⊢FD ⟦ S ⟧⁻ <: ⟦ U ⟧⁺ minus⇒deterministic-gen D = F-rec (λ D → prop D) pf D where prop : F-deriv → Set prop D = ∀ n {Γ} (S : Contra n (typ₁ D)) (U : Covar n (typ₂ D)) → env D ≡ List.map _*⁻ Γ → [ n ] Γ ⊢FD ⟦ S ⟧⁻ <: ⟦ U ⟧⁺ open ≤-Reasoning pf : ∀ (D : F-deriv) → (∀ D′ → F-measure-packed D′ < F-measure-packed D → prop D′) → prop D pf ((Γ , S* , .⊤) , ftop) rec n S cvtop eq = fdtop pf ((Γ , S* , .⊤) , ftop) rec n S (cvΠ ()) eq pf ((Γ , .(var _) , .(var _)) , fvrefl) rec n S (cvΠ ()) eq pf ((Γ , .(var m) , .⊤) , fbinds T∈Γ D) rec n (cnvar m) cvtop eq = fdtop pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl with trans (sym $ env-lookup-same (List.map _*⁻ Γ′) m) $ <:∈⇒lookup T∈Γ ... | eq with lookupOpt (List.map _*⁻ Γ′) m | inspect (lookupOpt (List.map _*⁻ Γ′)) m pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl | refl | just T | [ lk ] with lookupOpt-map-inv Γ′ lk ... | T′ , refl , lk′ rewrite repeat*-↑-comm⁻ T′ m 0 | *-↑-comm⁻ (repeat m (_↑⁻ 0) T′) 0 with rec (-, D) ≤-refl n *⟦ repeat m (_↑⁻ 0) T′ ↑⁻ 0 ⟧⁻ (cvΠ P) refl ... | Drec rewrite *⁻⟦⟧⁻⇒id (repeat m (_↑⁻ 0) T′ ↑⁻ 0) = fdvar (cong (Maybe.map (repeat (suc m) (_↑⁻ 0))) lk′) Drec pf ((Γ , .(var m) , U*) , fbinds T∈Γ D) rec n {Γ′} (cnvar m) (cvΠ P) refl | () | nothing | [ lk ] pf ((Γ , .(var _) , U*) , fbinds T∈Γ D) rec n (cnΠ ()) U eq pf ((Γ , .(Π<: _ ∙ _) , .(Π<: _ ∙ _)) , Dtop@(fall S₂<:S₁ U₁<:U₂)) rec n (cnΠ Ps) (cvΠ Pu) refl = fdall (aux _ n (fall S₂<:S₁ U₁<:U₂) Ps Pu ≤-refl) where transport : ∀ {Γ T₁ T₂ S*} (S : Contra n S*) (D : S* ∷ Γ ⊢F T₁ <: T₂) → Σ ((⟦ S ⟧⁻ *⁻) ∷ Γ ⊢F T₁ <: T₂) (λ D′ → F-measure D′ ≡ F-measure D) transport {Γ} {T₁} {T₂} S D = subst (λ S → Σ (S ∷ Γ ⊢F T₁ <: T₂) (λ D′ → F-measure D′ ≡ F-measure D)) (sym $ ⟦⟧⁻*⁻⇒id S) (D , refl) aux : ∀ {T₁ T₂} Γ m (D : List.map _*⁻ Γ ⊢F T₁ <: T₂) (Ps : Pi (_≡_ ⊤) (Covar n) m T₁) (Pu : Pi (Contra n) (Contra n) m T₂) → F-measure D ≤ F-measure Dtop → [ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ ∥ Pu ∥⁺₁ ⊢FD ∥ Pu ∥⁺₂ <: ∥ Ps ∥⁻ aux Γ zero (fall <:₁ <:₂) (pzero S₁) (pzero S₂) ≤ = rec (-, <:₁) (≤-trans shrinks ≤) n S₂ S₁ refl where shrinks : (F-measure <:₁) < suc (F-measure <:₁ + F-measure <:₂) shrinks = begin-strict F-measure <:₁ ≤⟨ ≤-stepsʳ (F-measure <:₂) ≤-refl ⟩ F-measure <:₁ + F-measure <:₂ <⟨ ≤-refl ⟩ suc (F-measure <:₁ + F-measure <:₂) ∎ aux Γ (suc m) (fall <:₁ <:₂) (psuc refl Ps) (psuc S₂ Pu) ≤ with transport S₂ <:₂ ... | <:₂′ , eq = aux (⟦ S₂ ⟧⁻ ∷ Γ) m <:₂′ Ps Pu $ begin F-measure <:₂′ ≡⟨ eq ⟩ F-measure <:₂ ≤⟨ ≤-stepsˡ (F-measure <:₁) ≤-refl ⟩ F-measure <:₁ + F-measure <:₂ <⟨ ≤ ⟩ suc (F-measure S₂<:S₁ + F-measure U₁<:U₂) ∎ -- The following two functions conclude the reduction proof from F<:ᵈ to F<:⁻. minus⇒deterministic : ∀ n {Γ : NEnv n} {S U} → List.map _*⁻ Γ ⊢F S *⁻ <: U *⁺ → [ n ] Γ ⊢FD S <: U minus⇒deterministic n {Γ} {S} {U} D with minus⇒deterministic-gen (-, D) n *⟦ S ⟧⁻ *⟦ U ⟧⁺ refl ... | D′ rewrite *⁻⟦⟧⁻⇒id S | *⁺⟦⟧⁺⇒id U = D′ deterministic⇒minus : ∀ n {Γ : NEnv n} {S U} → [ n ] Γ ⊢FD S <: U → List.map _*⁻ Γ ⊢F S *⁻ <: U *⁺ deterministic⇒minus n fdtop = ftop deterministic⇒minus n {Γ} (fdvar {m = m} T∈Γ D) with lookupOpt Γ m | inspect (lookupOpt Γ) m deterministic⇒minus n {Γ} (fdvar {m = m} refl D) | just T | [ eq ] = fbinds (lookup⇒<:∈ $ begin env-lookup (List.map _*⁻ Γ) m ≡⟨ env-lookup-same (List.map _*⁻ Γ) m ⟩ env-lookup′ (List.map _*⁻ Γ) m ≡⟨ cong (Maybe.map (repeat (suc m) (_↑ 0))) (lookupOpt-map Γ _*⁻ eq) ⟩ just (repeat m (_↑ 0) (T *⁻) ↑ 0) ≡⟨ cong (just ∘ (_↑ 0)) (repeat*-↑-comm⁻ T m 0) ⟩ just ((repeat m (_↑⁻ 0) T *⁻) ↑ 0) ≡⟨ cong just $ *-↑-comm⁻ (repeat m (_↑⁻ 0) T) 0 ⟩ just ((repeat m (_↑⁻ 0) T ↑⁻ 0) *⁻) ∎) (deterministic⇒minus n D) where open Eq (setoid (Maybe Ftyp)) deterministic⇒minus n {Γ} (fdvar {m = m} () D) | nothing | _ deterministic⇒minus n {Γ} (fdall D) = aux n _ _ _ D where aux : ∀ {n} m {Γ} (S : Vec (Ftyp⁻ n) m) U T → [ n ] Vec.foldl (λ _ → _) (flip _∷_) Γ S ⊢FD U <: T → List.map _*⁻ Γ ⊢F Π⁺ m ∙ T <: Π⁻[ S ]∙ U aux .0 nil U T D = fall (deterministic⇒minus _ D) fvrefl aux .(suc _) (x ‼ S) U T D = fall ftop (aux _ S U T D)
{ "alphanum_fraction": 0.439826363, "avg_line_length": 39.6264441592, "ext": "agda", "hexsha": "4aafcf4749a34ebb46473069bd29f34af434055d", "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": "48214a55ebb484fd06307df4320813d4a002535b", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "HuStmpHrrr/popl20-artifact", "max_forks_repo_path": "agda/FsubMinus.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "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": "HuStmpHrrr/popl20-artifact", "max_issues_repo_path": "agda/FsubMinus.agda", "max_line_length": 139, "max_stars_count": 1, "max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "HuStmpHrrr/popl20-artifact", "max_stars_repo_path": "agda/FsubMinus.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z", "max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z", "num_tokens": 14648, "size": 30869 }
{-# OPTIONS --without-K --safe #-} open import Categories.Category -- The core of a category. -- See https://ncatlab.org/nlab/show/core module Categories.Category.Construction.Core {o ℓ e} (𝒞 : Category o ℓ e) where open import Level using (_⊔_) open import Function using (flip) open import Categories.Category.Groupoid using (Groupoid; IsGroupoid) open import Categories.Morphism 𝒞 open import Categories.Morphism.IsoEquiv 𝒞 open Category 𝒞 open _≃_ Core : Category o (ℓ ⊔ e) e Core = record { Obj = Obj ; _⇒_ = _≅_ ; _≈_ = _≃_ ; id = ≅.refl ; _∘_ = flip ≅.trans ; assoc = ⌞ assoc ⌟ ; sym-assoc = ⌞ sym-assoc ⌟ ; identityˡ = ⌞ identityˡ ⌟ ; identityʳ = ⌞ identityʳ ⌟ ; identity² = ⌞ identity² ⌟ ; equiv = ≃-isEquivalence ; ∘-resp-≈ = λ where ⌞ eq₁ ⌟ ⌞ eq₂ ⌟ → ⌞ ∘-resp-≈ eq₁ eq₂ ⌟ } Core-isGroupoid : IsGroupoid Core Core-isGroupoid = record { _⁻¹ = ≅.sym ; iso = λ {_ _ f} → record { isoˡ = ⌞ isoˡ f ⌟ ; isoʳ = ⌞ isoʳ f ⌟ } } where open _≅_ CoreGroupoid : Groupoid o (ℓ ⊔ e) e CoreGroupoid = record { category = Core; isGroupoid = Core-isGroupoid }
{ "alphanum_fraction": 0.6163301141, "avg_line_length": 25.3111111111, "ext": "agda", "hexsha": "e7cdf188e4674c690cc0e291125db13dfa80d1f7", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bblfish/agda-categories", "max_forks_repo_path": "src/Categories/Category/Construction/Core.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bblfish/agda-categories", "max_issues_repo_path": "src/Categories/Category/Construction/Core.agda", "max_line_length": 79, "max_stars_count": 5, "max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bblfish/agda-categories", "max_stars_repo_path": "src/Categories/Category/Construction/Core.agda", "max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z", "max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z", "num_tokens": 449, "size": 1139 }
open import Issue2229Reexport2 B = A
{ "alphanum_fraction": 0.7894736842, "avg_line_length": 9.5, "ext": "agda", "hexsha": "c3d17eb25fb0c29c6515c5741850860669978db8", "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/Issue2229-2.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "shlevy/agda", "max_issues_repo_path": "test/Succeed/Issue2229-2.agda", "max_line_length": 30, "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/Issue2229-2.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 13, "size": 38 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Algebra.Properties where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Function open import Cubical.Foundations.Isomorphism open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.GroupoidLaws open import Cubical.Foundations.Path open import Cubical.Foundations.Transport open import Cubical.Foundations.Univalence open import Cubical.Foundations.SIP open import Cubical.Data.Sigma open import Cubical.Structures.Axioms open import Cubical.Structures.Auto open import Cubical.Structures.Macro open import Cubical.Algebra.Monoid open import Cubical.Algebra.Group open import Cubical.Algebra.AbGroup open import Cubical.Algebra.Ring open import Cubical.Algebra.Module open import Cubical.Algebra.Algebra.Base open Iso private variable ℓ ℓ' ℓ'' ℓ''' : Level module AlgebraTheory (R : Ring ℓ) (A : Algebra R ℓ') where open RingStr (snd R) renaming (_+_ to _+r_ ; _·_ to _·r_) open AlgebraStr (A .snd) 0-actsNullifying : (x : ⟨ A ⟩) → 0r ⋆ x ≡ 0a 0-actsNullifying x = let idempotent-+ = 0r ⋆ x ≡⟨ cong (λ u → u ⋆ x) (sym (RingTheory.0Idempotent R)) ⟩ (0r +r 0r) ⋆ x ≡⟨ ⋆DistL+ 0r 0r x ⟩ (0r ⋆ x) + (0r ⋆ x) ∎ in RingTheory.+Idempotency→0 (Algebra→Ring A) (0r ⋆ x) idempotent-+ ⋆Dist· : (x y : ⟨ R ⟩) (a b : ⟨ A ⟩) → (x ·r y) ⋆ (a · b) ≡ (x ⋆ a) · (y ⋆ b) ⋆Dist· x y a b = (x ·r y) ⋆ (a · b) ≡⟨ ⋆AssocR _ _ _ ⟩ a · ((x ·r y) ⋆ b) ≡⟨ cong (a ·_) (⋆Assoc _ _ _) ⟩ a · (x ⋆ (y ⋆ b)) ≡⟨ sym (⋆AssocR _ _ _) ⟩ x ⋆ (a · (y ⋆ b)) ≡⟨ sym (⋆AssocL _ _ _) ⟩ (x ⋆ a) · (y ⋆ b) ∎ module AlgebraHoms {R : Ring ℓ} where open IsAlgebraHom idAlgebraHom : (A : Algebra R ℓ') → AlgebraHom A A fst (idAlgebraHom A) x = x pres0 (snd (idAlgebraHom A)) = refl pres1 (snd (idAlgebraHom A)) = refl pres+ (snd (idAlgebraHom A)) x y = refl pres· (snd (idAlgebraHom A)) x y = refl pres- (snd (idAlgebraHom A)) x = refl pres⋆ (snd (idAlgebraHom A)) r x = refl compIsAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''} {g : ⟨ B ⟩ → ⟨ C ⟩} {f : ⟨ A ⟩ → ⟨ B ⟩} → IsAlgebraHom (B .snd) g (C .snd) → IsAlgebraHom (A .snd) f (B .snd) → IsAlgebraHom (A .snd) (g ∘ f) (C .snd) compIsAlgebraHom {g = g} {f} gh fh .pres0 = cong g (fh .pres0) ∙ gh .pres0 compIsAlgebraHom {g = g} {f} gh fh .pres1 = cong g (fh .pres1) ∙ gh .pres1 compIsAlgebraHom {g = g} {f} gh fh .pres+ x y = cong g (fh .pres+ x y) ∙ gh .pres+ (f x) (f y) compIsAlgebraHom {g = g} {f} gh fh .pres· x y = cong g (fh .pres· x y) ∙ gh .pres· (f x) (f y) compIsAlgebraHom {g = g} {f} gh fh .pres- x = cong g (fh .pres- x) ∙ gh .pres- (f x) compIsAlgebraHom {g = g} {f} gh fh .pres⋆ r x = cong g (fh .pres⋆ r x) ∙ gh .pres⋆ r (f x) _∘≃a_ : {A B C : Algebra R ℓ'} → AlgebraEquiv B C → AlgebraEquiv A B → AlgebraEquiv A C _∘≃a_ g f .fst = compEquiv (fst f) (fst g) _∘≃a_ g f .snd = compIsAlgebraHom (g .snd) (f .snd) compAlgebraHom : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''} → AlgebraHom A B → AlgebraHom B C → AlgebraHom A C compAlgebraHom f g .fst = g .fst ∘ f .fst compAlgebraHom f g .snd = compIsAlgebraHom (g .snd) (f .snd) syntax compAlgebraHom f g = g ∘a f compIdAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom (idAlgebraHom A) φ ≡ φ compIdAlgebraHom φ = AlgebraHom≡ refl idCompAlgebraHom : {A B : Algebra R ℓ'} (φ : AlgebraHom A B) → compAlgebraHom φ (idAlgebraHom B) ≡ φ idCompAlgebraHom φ = AlgebraHom≡ refl compAssocAlgebraHom : {A B C D : Algebra R ℓ'} (φ : AlgebraHom A B) (ψ : AlgebraHom B C) (χ : AlgebraHom C D) → compAlgebraHom (compAlgebraHom φ ψ) χ ≡ compAlgebraHom φ (compAlgebraHom ψ χ) compAssocAlgebraHom _ _ _ = AlgebraHom≡ refl module AlgebraEquivs {R : Ring ℓ} where open IsAlgebraHom open AlgebraHoms compIsAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''} {g : ⟨ B ⟩ ≃ ⟨ C ⟩} {f : ⟨ A ⟩ ≃ ⟨ B ⟩} → IsAlgebraEquiv (B .snd) g (C .snd) → IsAlgebraEquiv (A .snd) f (B .snd) → IsAlgebraEquiv (A .snd) (compEquiv f g) (C .snd) compIsAlgebraEquiv {g = g} {f} gh fh = compIsAlgebraHom {g = g .fst} {f .fst} gh fh compAlgebraEquiv : {A : Algebra R ℓ'} {B : Algebra R ℓ''} {C : Algebra R ℓ'''} → AlgebraEquiv A B → AlgebraEquiv B C → AlgebraEquiv A C fst (compAlgebraEquiv f g) = compEquiv (f .fst) (g .fst) snd (compAlgebraEquiv f g) = compIsAlgebraEquiv {g = g .fst} {f = f .fst} (g .snd) (f .snd) -- the Algebra version of uaCompEquiv module AlgebraUAFunctoriality {R : Ring ℓ} where open AlgebraStr open AlgebraEquivs Algebra≡ : (A B : Algebra R ℓ') → ( Σ[ p ∈ ⟨ A ⟩ ≡ ⟨ B ⟩ ] Σ[ q0 ∈ PathP (λ i → p i) (0a (snd A)) (0a (snd B)) ] Σ[ q1 ∈ PathP (λ i → p i) (1a (snd A)) (1a (snd B)) ] Σ[ r+ ∈ PathP (λ i → p i → p i → p i) (_+_ (snd A)) (_+_ (snd B)) ] Σ[ r· ∈ PathP (λ i → p i → p i → p i) (_·_ (snd A)) (_·_ (snd B)) ] Σ[ s- ∈ PathP (λ i → p i → p i) (-_ (snd A)) (-_ (snd B)) ] Σ[ s⋆ ∈ PathP (λ i → ⟨ R ⟩ → p i → p i) (_⋆_ (snd A)) (_⋆_ (snd B)) ] PathP (λ i → IsAlgebra R (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i)) (isAlgebra (snd A)) (isAlgebra (snd B))) ≃ (A ≡ B) Algebra≡ A B = isoToEquiv theIso where open Iso theIso : Iso _ _ fun theIso (p , q0 , q1 , r+ , r· , s- , s⋆ , t) i = p i , algebrastr (q0 i) (q1 i) (r+ i) (r· i) (s- i) (s⋆ i) (t i) inv theIso x = cong ⟨_⟩ x , cong (0a ∘ snd) x , cong (1a ∘ snd) x , cong (_+_ ∘ snd) x , cong (_·_ ∘ snd) x , cong (-_ ∘ snd) x , cong (_⋆_ ∘ snd) x , cong (isAlgebra ∘ snd) x rightInv theIso _ = refl leftInv theIso _ = refl caracAlgebra≡ : {A B : Algebra R ℓ'} (p q : A ≡ B) → cong ⟨_⟩ p ≡ cong ⟨_⟩ q → p ≡ q caracAlgebra≡ {A = A} {B = B} p q P = sym (transportTransport⁻ (ua (Algebra≡ A B)) p) ∙∙ cong (transport (ua (Algebra≡ A B))) helper ∙∙ transportTransport⁻ (ua (Algebra≡ A B)) q where helper : transport (sym (ua (Algebra≡ A B))) p ≡ transport (sym (ua (Algebra≡ A B))) q helper = Σ≡Prop (λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (is-set (snd B)) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ λ _ → is-set (snd B)) _ _) λ _ → isPropΣ (isOfHLevelPathP' 1 (isSetΠ2 λ _ _ → is-set (snd B)) _ _) λ _ → isOfHLevelPathP 1 (isPropIsAlgebra _ _ _ _ _ _ _) _ _) (transportRefl (cong ⟨_⟩ p) ∙ P ∙ sym (transportRefl (cong ⟨_⟩ q))) uaCompAlgebraEquiv : {A B C : Algebra R ℓ'} (f : AlgebraEquiv A B) (g : AlgebraEquiv B C) → uaAlgebra (compAlgebraEquiv f g) ≡ uaAlgebra f ∙ uaAlgebra g uaCompAlgebraEquiv f g = caracAlgebra≡ _ _ ( cong ⟨_⟩ (uaAlgebra (compAlgebraEquiv f g)) ≡⟨ uaCompEquiv _ _ ⟩ cong ⟨_⟩ (uaAlgebra f) ∙ cong ⟨_⟩ (uaAlgebra g) ≡⟨ sym (cong-∙ ⟨_⟩ (uaAlgebra f) (uaAlgebra g)) ⟩ cong ⟨_⟩ (uaAlgebra f ∙ uaAlgebra g) ∎)
{ "alphanum_fraction": 0.5544346915, "avg_line_length": 43.867816092, "ext": "agda", "hexsha": "d03089c2677278dff2a710b2d90124ad2f5ba972", "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/Algebra/Properties.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/Algebra/Properties.agda", "max_line_length": 102, "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/Algebra/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3072, "size": 7633 }
{-# OPTIONS --rewriting --prop #-} open import Agda.Primitive public open import Agda.Builtin.Nat public renaming (Nat to ℕ) hiding (_==_; _+_) open import Agda.Builtin.Bool public {- Basic datatypes and propositions -} record ⊤ : Prop where instance constructor tt record Unit : Set where instance constructor tt data ⊥ : Prop where data Empty : Set where record _×_ (A B : Set) : Set where constructor _,_ field fst : A snd : B open _×_ public infixr 42 _×_ infixl 4 _,_ record ΣP (A : Prop) (B : A → Prop) : Prop where constructor _,_ field fst : A snd : B fst open ΣP public instance pairP : {A : Prop} {B : A → Prop} {{a : A}} {{b : B a}} → ΣP A B pairP {{a}} {{b}} = a , b record ΣS (A : Set) (B : A → Set) : Set where constructor _,_ field fst : A snd : B fst open ΣS public {- Literal notation for natural numbers and similar things. Later on we will use notation with literal natural numbers for things that are not always defined, so we need to use [fromNat] and a constraint. The idea is that if we have an instance of [Number A], that means that we can potentially use literals to denote elements of [A], as long as instance search can figure out that the constraint is satisfied. We need the constraint to be a set as we will pattern match on it. -} record Number (A : Set) : Set₁ where field Constraint : ℕ → Set fromNat : (n : ℕ) {{_ : Constraint n}} → A open Number {{...}} public {-# BUILTIN FROMNAT fromNat #-} instance NumNat : Number ℕ Number.Constraint NumNat _ = Unit Number.fromNat NumNat n = n {- Equality -} data _≡_ {l} {A : Set l} (x : A) : A → Prop l where instance refl : x ≡ x --{-# BUILTIN EQUALITY _≡_ #-} {-# BUILTIN REWRITE _≡_ #-} infix 4 _≡_ ap : {A B : Set} (f : A → B) {a b : A} → a ≡ b → f a ≡ f b ap f refl = refl ap2 : {A B C : Set} (f : A → B → C) {a a' : A} {b b' : B} → a ≡ a' → b ≡ b' → f a b ≡ f a' b' ap2 f refl refl = refl ap3 : {A B C D : Set} (f : A → B → C → D) {a a' : A} {b b' : B} {c c' : C} → a ≡ a' → b ≡ b' → c ≡ c' → f a b c ≡ f a' b' c' ap3 f refl refl refl = refl ap4 : {A B C D E : Set} (f : A → B → C → D → E) {a a' : A} {b b' : B} {c c' : C} {d d' : D} → a ≡ a' → b ≡ b' → c ≡ c' → d ≡ d' → f a b c d ≡ f a' b' c' d' ap4 f refl refl refl refl = refl _∙_ : {A : Set} {a b c : A} → a ≡ b → b ≡ c → a ≡ c refl ∙ refl = refl infixr 4 _∙_ ! : {A : Set} {a b : A} → a ≡ b → b ≡ a ! refl = refl {- Lifting from Prop/Set to Set₁ -} record Box (P : Prop) : Set where constructor box field unbox : P open Box public {- Monads -} record Monad {ℓ ℓ'} (M : Set ℓ → Set ℓ') : Set (lsuc ℓ ⊔ ℓ') where field return : {A : Set ℓ} → A → M A _>>=_ : {A B : Set ℓ} → M A → (A → M B) → M B _>>_ : {A B : Set ℓ} → M A → M B → M B a >> b = a >>= (λ _ → b) infixr 20 _>>_ open Monad {{…}} public -- {- For the partiality monad, we use (dependent) lists of propositions in order to get rid of useless ⊤s -} -- data ListProp : Set₁ -- pf : ListProp → Prop -- data ListProp where -- [] : ListProp -- [_] : Prop → ListProp -- _,_ : (l : ListProp) → (pf l → ListProp) → ListProp -- pf [] = ⊤ -- pf [ p ] = p -- pf ([] , p) = pf (p tt) -- pf (l , q) = ΣP (pf l) (λ x → pf (q x)) -- lemma : {l : ListProp} {p : pf l → ListProp} → pf (l , p) → ΣP (pf l) (λ x → pf (p x)) -- lemma {[]} q = tt , q -- lemma {[ p ]} q = q -- lemma {l , p} {r} q = (fst q , snd q) {- The partiality monad -} record Partial (A : Set) : Set₁ where field isDefined : Prop _$_ : isDefined → A infix 5 _$_ open Partial public instance PartialityMonad : Monad Partial isDefined (Monad.return PartialityMonad x) = ⊤ Monad.return PartialityMonad x Partial.$ tt = x isDefined (Monad._>>=_ PartialityMonad a f) = ΣP (isDefined a) (λ x → isDefined (f (a $ x))) Monad._>>=_ PartialityMonad a f Partial.$ x = f (a $ fst x) $ snd x assume : (P : Prop) → Partial (Box P) isDefined (assume P) = P assume P $ x = box x fail : {A : Set} → Partial A isDefined fail = ⊥ {- Properties of the natural numbers -} data _≤_ : (n m : ℕ) → Set where instance ≤r : {n : ℕ} → n ≤ n ≤S : {n m : ℕ} → n ≤ m → n ≤ suc m ≤P : {n m : ℕ} → suc n ≤ suc m → n ≤ m ≤P ≤r = ≤r ≤P {n} {suc m} (≤S p) = ≤S (≤P p) _+_ : ℕ → ℕ → ℕ n + zero = n n + suc m = suc (n + m) infixl 20 _+_ instance ≤-+ : {n m : ℕ} → n ≤ (n + m) ≤-+ {m = zero} = ≤r ≤-+ {m = suc m} = ≤S (≤-+ {m = m}) -- ≤-+S : {m : ℕ} (n : ℕ) → m ≤ (m + suc n) -- ≤-+S _ = ≤S ≤-+ instance -- ≤S0 : {n : ℕ} → n ≤ suc n -- ≤S0 = ≤S ≤r 0≤ : {n : ℕ} → 0 ≤ n 0≤ {zero} = ≤r 0≤ {suc n} = ≤S (0≤ {n}) ≤SS : {n m : ℕ} {{_ : n ≤ m}} → suc n ≤ suc m ≤SS ⦃ ≤r ⦄ = ≤r ≤SS ⦃ ≤S p ⦄ = ≤S (≤SS {{p}}) ≤+ : (l : ℕ) {n m : ℕ} {{_ : n ≤ m}} → (n + l) ≤ (m + l) -- ≤+ l {{≤r}} = ≤r -- ≤+ zero {{ ≤S p }} = ≤S p -- ≤+ (suc l) {{ ≤S p }} = ≤SS {{≤+ l {{≤S p}}}} ≤+ zero {{p}} = p ≤+ (suc l) = ≤SS {{≤+ l}} ≤tr : {n m k : ℕ} {{_ : n ≤ m}} {{_ : m ≤ k}} → n ≤ k ≤tr ⦃ ≤r ⦄ ⦃ q ⦄ = q ≤tr ⦃ ≤S p ⦄ ⦃ ≤r ⦄ = ≤S p ≤tr ⦃ ≤S p ⦄ ⦃ ≤S q ⦄ = ≤S (≤tr {{≤S p}} {{q}}) {- Rewrite rules for the natural numbers (!!!) -} +O-rewrite : {n : ℕ} → 0 + n ≡ n +O-rewrite {zero} = refl +O-rewrite {suc n} = ap suc +O-rewrite -- {-# REWRITE +O-rewrite #-} +S-rewrite : {n m : ℕ} → suc m + n ≡ suc (m + n) +S-rewrite {zero} = refl +S-rewrite {suc n} {m} = ap suc (+S-rewrite {n} {m}) -- {-# REWRITE +S-rewrite #-} assoc : {n m k : ℕ} → (n + m) + k ≡ n + (m + k) assoc {k = zero} = refl assoc {n} {m} {k = suc k} = ap suc (assoc {n} {m} {k = k}) -- {-# REWRITE assoc #-} data _===_ {l} {A : Set l} (x : A) : A → Set l where instance refl : x === x {-# BUILTIN EQUALITY _===_ #-} infix 4 _===_ -- transport : {A : Set} {P : A → Set} {a b : A} → a === b → P a → P b -- transport refl u = u -- transport! : {A : Set} {P : A → Set} {a b : A} → a === b → P b → P a -- transport! refl u = u {- Instance arguments -} ⟨⟩ : {A : Prop} {{a : A}} → A ⟨⟩ {{a}} = a {- This is the sorts that we use for the syntax, two sorts: types and terms -} data SyntaxSort : Set where Ty : SyntaxSort Tm : SyntaxSort {- Positions of variables in a context -} data VarPos : ℕ → Set where last : {n : ℕ} → VarPos (suc n) prev : {n : ℕ} → VarPos n → VarPos (suc n) -- Size of the context before (and excluding) that variable _-VarPos'_ : (n : ℕ) → VarPos n → ℕ (suc n) -VarPos' last = n (suc n) -VarPos' prev k = n -VarPos' k -- Size of the context before (and including) that variable _-VarPos_ : (n : ℕ) → VarPos n → ℕ n -VarPos k = suc (n -VarPos' k) --instance suc-VarPos'≤ : {n : ℕ} {p : VarPos (suc n)} → (suc n -VarPos' p) ≤ n suc-VarPos'≤ {n} {last} = ≤r suc-VarPos'≤ {suc n} {prev p} = ≤tr {{suc-VarPos'≤ {n} {p}}} {{≤S ≤r}} {- Positions of weakening spots in a context -} data WeakPos : ℕ → Set where last : {n : ℕ} → WeakPos n prev : {n : ℕ} → WeakPos n → WeakPos (suc n) weakenPos : {n m : ℕ} → n ≤ m → WeakPos n → WeakPos m weakenPos ≤r k = k weakenPos (≤S p) k = prev (weakenPos p k) {- Weakening by a group of variable in the middle of a context -} weakenV : {n m : ℕ} {{_ : n ≤ m}} (p : WeakPos n) → VarPos n → VarPos m weakenV {m = suc m} ⦃ r ⦄ (prev p) last = last weakenV ⦃ ≤r ⦄ p x = x weakenV ⦃ ≤S r ⦄ last x = prev (weakenV {{r}} last x) weakenV ⦃ ≤S r ⦄ (prev p) (prev x) = prev (weakenV {{≤P (≤S r)}} p x) weakenV≤r : {n : ℕ} {p : WeakPos n} {v : VarPos n} → weakenV {{≤r}} p v ≡ v weakenV≤r {p = last} {last} = refl weakenV≤r {p = prev p} {last} = refl weakenV≤r {p = last} {prev v} = refl weakenV≤r {p = prev p} {prev v} = refl
{ "alphanum_fraction": 0.5272992314, "avg_line_length": 24.7409836066, "ext": "agda", "hexsha": "673d559c6ceb3c8694fb901107aa89558986ac73", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "guillaumebrunerie/general-type-theories", "max_forks_repo_path": "common.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "guillaumebrunerie/general-type-theories", "max_issues_repo_path": "common.agda", "max_line_length": 155, "max_stars_count": null, "max_stars_repo_head_hexsha": "f9bfefd0a70ae5bdc3906829ee1165c731882bca", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "guillaumebrunerie/general-type-theories", "max_stars_repo_path": "common.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3153, "size": 7546 }
{-# OPTIONS --without-K #-} module Univalence where open import Equivalence open import Types postulate ua : ∀ {ℓ} {A : Set ℓ} {B : Set ℓ} → (A ≡ B) ≃ (A ≃ B)
{ "alphanum_fraction": 0.6012269939, "avg_line_length": 18.1111111111, "ext": "agda", "hexsha": "85133e544278f63e2f161ed71dc37a666d69d1fe", "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": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "vituscze/HoTT-lectures", "max_forks_repo_path": "src/Univalence.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "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": "vituscze/HoTT-lectures", "max_issues_repo_path": "src/Univalence.agda", "max_line_length": 56, "max_stars_count": null, "max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "vituscze/HoTT-lectures", "max_stars_repo_path": "src/Univalence.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 60, "size": 163 }
{-# OPTIONS --without-K --rewriting #-} open import HoTT {- This file contains three proofs of Ω(S¹) = ℤ and the fact that the circle is a 1-type: - Something closely related to Mike’s original proof - Dan’s encode-decode proof - Guillaume’s proof using the flattening lemma. This file is divided in a lot of different parts so that common parts can be factored: 1. Definition of the universal cover and the encoding map (this part is common to all three proofs) 2. Proof that [encode (loop^ n) == n] (this part is common to Mike’s proof and the encode-decode proof) 3. Dan’s encode-decode proof that [Ω S¹ ≃ ℤ] 4. Mike’s proof that [Σ S¹ Cover] is contractible 5. Proof with the flattening lemma that [Σ S¹ S¹Cover] is contractible 6. Proof of [Ω S¹ ≃ ℤ] using the fact that [Σ S¹ S¹Cover] is contractible (common to Mike’s proof and the flattening lemma proof) 7. Encode-decode proof of the whole equivalence 8. Proof that the circle is a 1-type (common to all three proofs) Keep - 1, 2, 3 for the encode-decode proof (+ 7, 8 for S¹ is a 1-type) - 1, 2, 4, 6 for Mike’s proof (+ 8) - 1, 5, 6 for the flattening lemma proof (+ 8) -} {- 2017/02/09 favonia: 1. [loop^] is defined in terms of [Group.exp], and the lemma [encode'-decode] is changed accordingly. Although the original [encode-decode] can be proved without the generalized [encode'], [encode'] seems useful in proving the isomorphism (not just type equivalence) without flipping the two sides [Ω S¹] and [ℤ]. 2. Part 9 is added for further results. -} module homotopy.LoopSpaceCircle where {- 1. Universal cover and encoding map (common to all three proofs) -} module S¹Cover = S¹RecType ℤ succ-equiv S¹Cover : S¹ → Type₀ S¹Cover = S¹Cover.f encode' : {x₁ x₂ : S¹} (p : x₁ == x₂) → S¹Cover x₁ → S¹Cover x₂ encode' p n = transport S¹Cover p n encode : {x : S¹} (p : base == x) → S¹Cover x encode p = encode' p 0 {- 2. Encoding [loop^ n] (common to Mike’s proof and the encode-decode proof) -} ΩS¹-group-structure : GroupStructure (base == base) ΩS¹-group-structure = Ω^S-group-structure 0 ⊙S¹ module ΩS¹GroupStruct = GroupStructure ΩS¹-group-structure -- We define the element of [Ω S¹] which is supposed to correspond to an -- integer [n], this is the loop winding around the circle [n] times. loop^ : (n : ℤ) → base == base loop^ = ΩS¹GroupStruct.exp loop -- Compatibility of [loop^] with the addition function abstract loop^+ : (n₁ n₂ : ℤ) → loop^ (n₁ ℤ+ n₂) == loop^ n₁ ∙ loop^ n₂ loop^+ = ΩS¹GroupStruct.exp-+ loop -- Now we check that encoding [loop^ n] gives indeed [n], again by induction -- on [n] abstract encode'-∙ : ∀ {x₀ x₁ x₂} (p₀ : x₀ == x₁) (p₁ : x₁ == x₂) n → encode' (p₀ ∙ p₁) n == encode' p₁ (encode' p₀ n) encode'-∙ idp _ _ = idp encode'-loop : ∀ n → encode' loop n == succ n encode'-loop = S¹Cover.coe-loop-β encode'-!loop : ∀ n → encode' (! loop) n == pred n encode'-!loop n = coe-ap-! S¹Cover loop n ∙ S¹Cover.coe!-loop-β n abstract encode'-loop^ : (n₁ n₂ : ℤ) → encode' (loop^ n₁) n₂ == n₁ ℤ+ n₂ encode'-loop^ (pos 0) n₂ = idp encode'-loop^ (pos 1) n₂ = encode'-loop n₂ encode'-loop^ (pos (S (S n₁))) n₂ = encode' (loop ∙ loop^ (pos (S n₁))) n₂ =⟨ encode'-∙ loop (loop^ (pos (S n₁))) n₂ ⟩ encode' (loop^ (pos (S n₁))) (encode' loop n₂) =⟨ encode'-loop n₂ |in-ctx encode' (loop^ (pos (S n₁))) ⟩ encode' (loop^ (pos (S n₁))) (succ n₂) =⟨ encode'-loop^ (pos (S n₁)) (succ n₂) ⟩ pos (S n₁) ℤ+ succ n₂ =⟨ ℤ+-succ (pos (S n₁)) n₂ ⟩ pos (S (S n₁)) ℤ+ n₂ =∎ encode'-loop^ (negsucc 0) n₂ = encode'-!loop n₂ encode'-loop^ (negsucc (S n₁)) n₂ = encode' (! loop ∙ loop^ (negsucc n₁)) n₂ =⟨ encode'-∙ (! loop) (loop^ (negsucc n₁)) n₂ ⟩ encode' (loop^ (negsucc n₁)) (encode' (! loop) n₂) =⟨ encode'-!loop n₂ |in-ctx encode' (loop^ (negsucc n₁)) ⟩ encode' (loop^ (negsucc n₁)) (pred n₂) =⟨ encode'-loop^ (negsucc n₁) (pred n₂) ⟩ negsucc n₁ ℤ+ pred n₂ =⟨ ℤ+-pred (negsucc n₁) n₂ ⟩ negsucc (S n₁) ℤ+ n₂ =∎ encode-loop^ : (n : ℤ) → encode (loop^ n) == n encode-loop^ n = encode'-loop^ n 0 ∙ ℤ+-unit-r n {- 3. Dan’s encode-decode proof -} -- The decoding function at [base] is [loop^], but we extend it to the whole -- of [S¹] so that [decode-encode] becomes easier (and we need [loop^+] to -- be able to extend it) decode : (x : S¹) → (S¹Cover x → base == x) decode = S¹-elim loop^ (↓-→-in λ {n} q → ↓-cst=idf-in' $ ! (loop^+ n 1) ∙ ap loop^ (ℤ+-comm n 1 ∙ S¹Cover.↓-loop-out q)) abstract decode-encode : (x : S¹) (p : base == x) → decode x (encode p) == p decode-encode _ idp = idp -- Magic! -- And we get the theorem ΩS¹≃ℤ : (base == base) ≃ ℤ ΩS¹≃ℤ = equiv encode (decode base) encode-loop^ (decode-encode base) {- 4. Mike’s proof that [Σ S¹ Cover] is contractible -} -- We want to prove that every point of [Σ S¹ S¹Cover] is equal to [(base , O)] paths-mike : (xt : Σ S¹ S¹Cover) → (base , 0) == xt paths-mike (x , t) = paths-mike-c x t where abstract -- We do it by circle-induction on the first component. When it’s [base], -- we use the [↓-loop^] below (which is essentially [encode-loop^]) and -- for [loop] we use [loop^+] and the fact that [ℤ] is a set. paths-mike-c : (x : S¹) (t : S¹Cover x) → (base , 0) == (x , t) :> Σ S¹ S¹Cover paths-mike-c = S¹-elim (λ n → pair= (loop^ n) (↓-loop^ n)) (↓-Π-in (λ {n} {n'} q → ↓-cst=idf-in' (pair= (loop^ n) (↓-loop^ n) ∙ pair= loop q =⟨ Σ-∙ (↓-loop^ n) q ⟩ pair= (loop^ n ∙ loop) (↓-loop^ n ∙ᵈ q) =⟨ pair== (! (loop^+ n 1) ∙ ap loop^ (ℤ+-comm n 1 ∙ S¹Cover.↓-loop-out q)) (set-↓-has-all-paths-↓ ℤ-is-set) ⟩ pair= (loop^ n') (↓-loop^ n') ∎))) where ↓-loop^ : (n : ℤ) → 0 == n [ S¹Cover ↓ loop^ n ] ↓-loop^ n = from-transp _ _ (encode-loop^ n) abstract contr-mike : is-contr (Σ S¹ S¹Cover) contr-mike = ((base , 0) , paths-mike) {- 5. Flattening lemma proof that [Σ S¹ Cover] is contractible -} --We import the flattening lemma for the universal cover of the circle --open FlatteningS¹ ℤ succ-equiv open S¹Cover using (module Wt; Wt; cct; ppt; flattening-S¹) -- We prove that the flattened HIT corresponding to the universal cover of the -- circle (the real line) is contractible Wt-is-contr : is-contr Wt Wt-is-contr = (cct tt 0 , Wt.elim (base* ∘ snd) (loop* ∘ snd)) where -- This is basically [loop^] using a different composition order base* : (n : ℤ) → cct tt 0 == cct tt n base* (pos 0) = idp base* (pos 1) = ppt tt 0 base* (pos (S (S n))) = base* (pos (S n)) ∙ ppt tt (pos (S n)) base* (negsucc 0) = ! (ppt tt (negsucc O)) base* (negsucc (S n)) = base* (negsucc n) ∙ ! (ppt tt (negsucc (S n))) abstract loop* : (n : ℤ) → base* n == base* (succ n) [ (λ x → cct tt 0 == x) ↓ ppt tt n ] loop* n = ↓-cst=idf-in' (aux n) where -- This is basically [loop^+ 1 n] aux : (n : ℤ) → base* n ∙ ppt tt n == base* (succ n) aux (pos 0) = idp aux (pos (S n)) = idp aux (negsucc 0) = !-inv-l (ppt tt (negsucc O)) aux (negsucc (S n)) = base* (negsucc (S n)) ∙ ppt tt (negsucc (S n)) =⟨ idp ⟩ (base* (negsucc n) ∙ ! (ppt tt (negsucc (S n)))) ∙ ppt tt (negsucc (S n)) =⟨ ∙-assoc (base* (negsucc n)) _ _ ⟩ base* (negsucc n) ∙ (! (ppt tt (negsucc (S n))) ∙ ppt tt (negsucc (S n))) =⟨ !-inv-l (ppt tt (negsucc (S n))) |in-ctx (λ u → base* (negsucc n) ∙ u) ⟩ base* (negsucc n) ∙ idp =⟨ ∙-unit-r _ ⟩ base* (negsucc n) ∎ -- Then, using the flattening lemma we get that the total space of [Cover] is -- contractible abstract contr-flattening : is-contr (Σ S¹ S¹Cover) contr-flattening = transport! is-contr flattening-S¹ Wt-is-contr {- 6. Proof that [Ω S¹ ≃ ℤ] using the fact that [Σ S¹ Cover] is contractible -} tot-encode : Σ S¹ (λ x → base == x) → Σ S¹ S¹Cover tot-encode (x , y) = (x , encode y) -- The previous map induces an equivalence on the total spaces, because both -- total spaces are contractible abstract total-is-equiv : is-equiv tot-encode total-is-equiv = contr-to-contr-is-equiv _ (pathfrom-is-contr base) contr-flattening -- Hence it’s an equivalence fiberwise abstract encode-is-equiv : (x : S¹) → is-equiv (encode {x}) encode-is-equiv = total-equiv-is-fiber-equiv (λ _ → encode) total-is-equiv -- We can then conclude that the loop space of the circle is equivalent to [ℤ] ΩS¹≃ℤ' : (base == base) ≃ ℤ ΩS¹≃ℤ' = (encode {base} , encode-is-equiv base) {- 7. Encode-decode proof of the whole fiberwise equivalence -} -- This is quite similar to [paths-mike], we’re doing it by circle-induction, -- the base case is [encode-loop^] and the loop case is using the fact that [ℤ] -- is a set (and [loop^+] is already used in [decode]) encode-decode : (x : S¹) (t : S¹Cover x) → encode (decode x t) == t encode-decode = S¹-elim {P = λ x → (t : S¹Cover x) → encode (decode x t) == t} encode-loop^ (↓-Π-in (λ q → prop-has-all-paths-↓ (ℤ-is-set _ _))) encode-is-equiv' : (x : S¹) → is-equiv (encode {x}) encode-is-equiv' x = is-eq encode (decode x) (encode-decode x) (decode-encode x) {- 8. Proof that the circle is a 1-type -} abstract S¹Cover-is-set : {y : S¹} → is-set (S¹Cover y) S¹Cover-is-set {y} = S¹-elim {P = λ y → is-set (S¹Cover y)} ℤ-is-set (prop-has-all-paths-↓ is-set-is-prop) y ΩS¹-is-set : {y : S¹} → is-set (base == y) ΩS¹-is-set {y} = equiv-preserves-level ((encode {y} , encode-is-equiv y) ⁻¹) (S¹Cover-is-set {y}) S¹-level : has-level 1 S¹ S¹-level = S¹-elim (λ _ → ΩS¹-is-set) (prop-has-all-paths-↓ (Π-level (λ x → is-set-is-prop))) {- 9. More stuff -} ΩS¹-iso-ℤ : Ω^S-group 0 ⊙S¹ S¹-level ≃ᴳ ℤ-group ΩS¹-iso-ℤ = ≃-to-≃ᴳ ΩS¹≃ℤ encode-pres-∙ where abstract encode-∙ : ∀ {x₁ x₂} (loop₁ : base == x₁) (loop₂ : x₁ == x₂) → encode (loop₁ ∙ loop₂) == encode' loop₂ (encode loop₁) encode-∙ idp _ = idp encode-pres-∙ : ∀ (loop₁ loop₂ : base == base) → encode (loop₁ ∙ loop₂) == encode loop₁ ℤ+ encode loop₂ encode-pres-∙ loop₁ loop₂ = encode (loop₁ ∙ loop₂) =⟨ encode'-∙ loop₁ loop₂ 0 ⟩ encode' loop₂ (encode loop₁) =⟨ ! $ decode-encode _ loop₂ |in-ctx (λ loop₂ → encode' loop₂ (encode loop₁)) ⟩ encode' (loop^ (encode loop₂)) (encode loop₁) =⟨ encode'-loop^ (encode loop₂) (encode loop₁) ⟩ encode loop₂ ℤ+ encode loop₁ =⟨ ℤ+-comm (encode loop₂) (encode loop₁) ⟩ encode loop₁ ℤ+ encode loop₂ =∎ abstract ΩS¹-is-abelian : is-abelian (Ω^S-group 0 ⊙S¹ S¹-level) ΩS¹-is-abelian = iso-preserves-abelian (ΩS¹-iso-ℤ ⁻¹ᴳ) ℤ-group-is-abelian
{ "alphanum_fraction": 0.5936984796, "avg_line_length": 38.0418118467, "ext": "agda", "hexsha": "f032ca56bfedeb32622ce52615f1ed0e0383d95e", "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/homotopy/LoopSpaceCircle.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/homotopy/LoopSpaceCircle.agda", "max_line_length": 94, "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/homotopy/LoopSpaceCircle.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4040, "size": 10918 }
------------------------------------------------------------------------ -- Normalization/simplification of kinding in Fω with interval kinds ------------------------------------------------------------------------ {-# OPTIONS --safe --without-K #-} module FOmegaInt.Kinding.Simple.Normalization where open import Data.Fin using (Fin; zero; suc; raise; lift) open import Data.Fin.Substitution using (module VarSubst) open import Data.Fin.Substitution.Lemmas open import Data.Fin.Substitution.ExtraLemmas open import Data.List using ([]; _∷_; _∷ʳ_; map) open import Data.Nat using (ℕ; zero; suc; _+_) open import Data.Product as Prod using (_,_) open import Data.Vec as Vec using ([]; _∷_) import Data.Vec.Properties as VecProp open import Function using (flip; _∘_) open import Relation.Binary.PropositionalEquality hiding ([_]) open import FOmegaInt.Syntax open import FOmegaInt.Syntax.SingleVariableSubstitution renaming (sub to hsub; _↑ to _H↑) open import FOmegaInt.Syntax.HereditarySubstitution open import FOmegaInt.Syntax.Normalization open import FOmegaInt.Syntax.WeakEquality open import FOmegaInt.Kinding.Simple as Simple open import FOmegaInt.Kinding.Simple.EtaExpansion open import FOmegaInt.Kinding.Declarative as Declarative ------------------------------------------------------------------------ -- Normalization/simplification of kinded types to simply kinded -- types. -- -- TODO: explain the point of this and how "simple" kinding differs -- from "canonical" kinding. open Syntax open TermCtx open SimpleCtx using (kd; tp; ⌊_⌋Asc; kd-inj′) open Substitution hiding (subst) open ContextConversions open RenamingCommutesNorm open WeakHereditarySubstitutionEquality open WeakEqEtaExpansion open WeakEqNormalization open KindedHereditarySubstitution open Simple.Kinding open Declarative.Kinding private module S where open Simple.Kinding public open SimpleCtx public open SimplyWfCtx public module D where open Declarative.Kinding public open TermCtx public module E = ElimCtx mutual -- Normalization and simultaneous simplification of kinding: -- well-kinded types normalize to simply kinded normal forms. nf-Tp∈ : ∀ {n} {Γ : Ctx n} {a k} → let Γ′ = nfCtx Γ in Γ ⊢Tp a ∈ k → ⌊ Γ′ ⌋Ctx ⊢Nf nf Γ′ a ∈ ⌊ k ⌋ nf-Tp∈ {_} {Γ} (∈-var {j} x Γ-ctx Γ[x]≡kd-k) with E.lookup (nfCtx Γ) x | nfCtx-lookup-kd x Γ Γ[x]≡kd-k nf-Tp∈ {_} {Γ} (∈-var {j} x Γ-ctx Γ[x]≡kd-j) | kd ._ | refl = subst (_ ⊢Nf η-exp (nfKind _ j) (var∙ x) ∈_) (⌊⌋-nf _) (η-exp-Var∈ (lookup-kd x (nf-ctx Γ-ctx) nf-Γ[x]≡kd-nf-j) (∈-var x (⌊⌋-lookup (nfCtx Γ) x nf-Γ[x]≡kd-nf-j))) where open WfsCtxOps using (lookup-kd) nf-Γ[x]≡kd-nf-j = nfCtx-lookup-kd x Γ Γ[x]≡kd-j nf-Tp∈ (∈-var x Γ-ctx Γ[x]≡kd-k) | tp _ | () nf-Tp∈ (∈-⊥-f Γ-ctx) = ∈-⊥-f nf-Tp∈ (∈-⊤-f Γ-ctx) = ∈-⊤-f nf-Tp∈ (∈-∀-f k-kd a∈*) = ∈-∀-f (nf-kd k-kd) (nf-Tp∈ a∈*) nf-Tp∈ (∈-→-f a∈* b∈*) = ∈-→-f (nf-Tp∈ a∈*) (nf-Tp∈ b∈*) nf-Tp∈ (∈-Π-i {j} {a} j-kd a∈k k-kd) = let j′ = nfKind _ j in subst (λ l → _ ⊢Nf Λ∙ j′ (nf (kd j′ ∷ _) a) ∈ l ⇒ _) (⌊⌋-nf j) (∈-Π-i (nf-kd j-kd) (nf-Tp∈ a∈k)) nf-Tp∈ (∈-Π-e {a} {b} a∈Πjk b∈j _ _) = subst (_ ⊢Nf nf _ a ↓⌜·⌝ nf _ b ∈_) (sym (⌊⌋-Kind/ _)) (Nf∈-Π-e′ (nf-Tp∈ a∈Πjk) (nf-Tp∈ b∈j)) nf-Tp∈ (∈-s-i a∈a⋯b) = nf-Tp∈ a∈a⋯b nf-Tp∈ (∈-⇑ a∈j j<∷k) = subst (_ ⊢Nf _ ∈_) (<∷-⌊⌋ j<∷k) (nf-Tp∈ a∈j) -- Normalization and simultaneous simplification of kind -- well-formedness: well-formed kinds normalize to simply -- well-formed kinds. nf-kd : ∀ {n} {Γ : Ctx n} {k} → let Γ′ = nfCtx Γ in Γ ⊢ k kd → ⌊ Γ′ ⌋Ctx ⊢ nfKind Γ′ k kds nf-kd (kd-⋯ a∈* b∈*) = kds-⋯ (nf-Tp∈ a∈*) (nf-Tp∈ b∈*) nf-kd (kd-Π j-kd k-kd) = kds-Π (nf-kd j-kd) (nf-kd k-kd) -- Normalization and simultaneous simplification of contexts: -- well-formed contexts normalize to simply well-formed simple -- contexts. nf-wf : ∀ {n} {Γ : Ctx n} {a} → let Γ′ = nfCtx Γ in Γ ⊢ a wf → ⌊ Γ′ ⌋Ctx ⊢ nfAsc Γ′ a wfs nf-wf (wf-kd k-kds) = wfs-kd (nf-kd k-kds) nf-wf (wf-tp a∈*) = wfs-tp (nf-Tp∈ a∈*) nf-ctx : ∀ {n} {Γ : Ctx n} → Γ ctx → nfCtx Γ ctxs nf-ctx D.[] = S.[] nf-ctx (a-wf D.∷ Γ-ctx) = nf-wf a-wf S.∷ nf-ctx Γ-ctx -- Normal forms of type operators are η-long. ≈-η-nf : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢Tp a ∈ Π j k → let nf-Γ = nfCtx Γ in nf nf-Γ (Λ j (weaken a · var zero)) ≈ nf nf-Γ a ≈-η-nf a∈Πjk with Nf∈-⇒-inv (nf-Tp∈ a∈Πjk) ≈-η-nf {_} {Γ} {a} {j} {k} a∈Πjk | l , b , l-kds , b∈⌊k⌋ , ⌊l⌋≡⌊j⌋ , nf-a≡Λlb = begin nf nf-Γ (Λ j (weaken a · var zero)) ≈⟨ ≈-Λ∙ ⌊nf-j⌋≡⌊l⌋ (begin nf-a′ ↓⌜·⌝ η-exp (weakenKind′ nf-j) (var∙ zero) ≡⟨ cong (_↓⌜·⌝ η-exp (weakenKind′ nf-j) (var∙ zero)) (trans (sym (nf-weaken (kd nf-j) a)) (cong weakenElim nf-a≡Λlb)) ⟩ weakenElim (Λ∙ l b) ↓⌜·⌝ η-exp (weakenKind′ nf-j) (var∙ zero) ≡⟨⟩ b Elim/Var (VarSubst.wk VarSubst.↑) /⟨ ⌊ weakenKind′ l ⌋ ⟩ hsub (η-exp (weakenKind′ nf-j) (var∙ zero)) ≈⟨ ≈-[∈] (≈-refl (b Elim/Var (VarSubst.wk VarSubst.↑))) (≈-η-exp ⌊nf-j/wk⌋≡⌊l/wk⌋ (≈-var∙ zero)) ⟩ b Elim/Var (VarSubst.wk VarSubst.↑) /⟨ ⌊ weakenKind′ l ⌋ ⟩ hsub (η-exp (weakenKind′ l) (var∙ zero)) ≈⟨ Nf∈-[]-η-var [] l-kds (subst (λ l → kd l ∷ _ ⊢Nf b ∈ _) (sym ⌊l⌋≡⌊j⌋) b∈⌊k⌋) ⟩ b ∎) ⟩ Λ∙ l b ≡⟨ sym nf-a≡Λlb ⟩ nf nf-Γ a ∎ where nf-Γ = nfCtx Γ nf-j = nfKind nf-Γ j nf-j∷Γ = kd nf-j ∷ nf-Γ nf-a′ = nf nf-j∷Γ (weaken a) ⌊nf-j⌋≡⌊l⌋ = begin ⌊ nf-j ⌋ ≡⟨ ⌊⌋-nf j ⟩ ⌊ j ⌋ ≡⟨ sym ⌊l⌋≡⌊j⌋ ⟩ ⌊ l ⌋ ∎ where open ≡-Reasoning ⌊nf-j/wk⌋≡⌊l/wk⌋ = begin ⌊ weakenKind′ nf-j ⌋ ≡⟨ ⌊⌋-Kind′/Var nf-j ⟩ ⌊ nf-j ⌋ ≡⟨ ⌊nf-j⌋≡⌊l⌋ ⟩ ⌊ l ⌋ ≡⟨ sym (⌊⌋-Kind′/Var l) ⟩ ⌊ weakenKind′ l ⌋ ∎ where open ≡-Reasoning open ≈-Reasoning -- Well-kinded hereditary substitions. infix 4 _⊢/Tp⟨_⟩_∈_ data _⊢/Tp⟨_⟩_∈_ : ∀ {m n} → Ctx n → SKind → SVSub m n → Ctx m → Set where ∈-hsub : ∀ {n} {Γ : Ctx n} {k a} → Γ ⊢Tp a ∈ k → Γ ⊢/Tp⟨ ⌊ k ⌋ ⟩ hsub ⌜ a ⌝ ∈ kd k ∷ Γ ∈-H↑ : ∀ {m n Δ k Γ} {σ : SVSub m n} {a} → Δ ⊢/Tp⟨ k ⟩ σ ∈ Γ → (a TermAsc/ toSub σ) ∷ Δ ⊢/Tp⟨ k ⟩ σ H↑ ∈ a ∷ Γ -- Normalize and simplify a well-kinded hereditary substitution. nf-/⟨⟩∈ : ∀ {m n k Δ} {σ : SVSub m n} {Γ} → Δ ⊢/Tp⟨ k ⟩ σ ∈ Γ → ⌊ nfCtx Δ ⌋Ctx ⊢/⟨ k ⟩ nfSVSub (nfCtx Δ) σ ∈ ⌊ nfCtx Γ ⌋Ctx nf-/⟨⟩∈ (∈-hsub {Γ = Γ} {k} {a} a∈k) = subst₂ (⌊ nfCtx Γ ⌋Ctx ⊢/⟨ ⌊ k ⌋ ⟩_∈_) (cong (hsub ∘ nf (nfCtx Γ)) (sym (⌞⌟∘⌜⌝-id a))) (cong (λ j → kd j ∷ ⌊ nfCtx Γ ⌋Ctx) (sym (⌊⌋-nf k))) (∈-hsub (nf-Tp∈ a∈k)) nf-/⟨⟩∈ (∈-H↑ {Δ = Δ} {k} {Γ} {σ} {a} σ∈Γ) = subst (_⊢/⟨ k ⟩ nfSVSub (nfCtx (a/σ ∷ Δ)) (σ H↑) ∈ ⌊ nfCtx (a ∷ Γ) ⌋Ctx) (cong (_∷ ⌊ nfCtx Δ ⌋Ctx) (begin ⌊ nfAsc (nfCtx Γ) a ⌋Asc ≡⟨ ⌊⌋Asc-nf a ⟩ ⌊ a ⌋Asc ≡˘⟨ S.⌊⌋-TermAsc/ a ⟩ ⌊ a TermAsc/ toSub σ ⌋Asc ≡˘⟨ ⌊⌋Asc-nf _ ⟩ ⌊ nfAsc (nfCtx Δ) (a TermAsc/ toSub σ) ⌋Asc ∎)) (∈-H↑ (nf-/⟨⟩∈ σ∈Γ)) where open ≡-Reasoning a/σ = a TermAsc/ toSub σ open ≈-Reasoning private module P = ≡-Reasoning mutual -- Substitution (weakly) commutes with normalization. nf-/⟨⟩ : ∀ {m n Δ k Γ} {σ : SVSub m n} {a j} → Γ ⊢Tp a ∈ j → Δ ⊢/Tp⟨ k ⟩ σ ∈ Γ → nf (nfCtx Δ) (a / toSub σ) ≈ nf (nfCtx Γ) a /⟨ k ⟩ nfSVSub (nfCtx Δ) σ nf-/⟨⟩ {Γ = Γ} (∈-var x Γ-ctx Γ[x]≡kd-j) σ∈Γ with E.lookup (nfCtx Γ) x | nfCtx-lookup-kd x Γ Γ[x]≡kd-j nf-/⟨⟩ {Δ = Δ} {k} {Γ} {σ} {_} {j} (∈-var x Γ-ctx Γ[x]≡kd-j) σ∈Γ | kd nf-j | refl with hit? σ x ... | hit a hitP = let open WfsCtxOps using (lookup-kd) nf-Γ-ctxs = nf-ctx Γ-ctx nf-Γ[x]≡kd-nf-j = nfCtx-lookup-kd x Γ Γ[x]≡kd-j nf-j-kds = lookup-kd x nf-Γ-ctxs nf-Γ[x]≡kd-nf-j hitP-nf-σ = nf-Hit (nfCtx Δ) hitP x∈⌊j⌋ = ∈-var x (⌊⌋-lookup (nfCtx Γ) x nf-Γ[x]≡kd-nf-j) in begin nf (nfCtx Δ) (Vec.lookup (toSub σ) x) ≡⟨ cong (nf (nfCtx Δ)) (lookup-toSub σ x) ⟩ nf (nfCtx Δ) (⌞ toElim (lookupSV σ x) ⌟) ≡⟨ cong (nf (nfCtx Δ) ∘ ⌞_⌟ ∘ toElim) (lookup-Hit hitP) ⟩ nf (nfCtx Δ) ⌞ a ⌟ ≡˘⟨ cong (_?∙∙⟨ k ⟩ []) (lookup-Hit hitP-nf-σ) ⟩ var∙ x /⟨ k ⟩ nfSVSub (nfCtx Δ) σ ≈˘⟨ η-exp-var-Hit-/⟨⟩ hitP-nf-σ nf-j-kds x∈⌊j⌋ (nf-/⟨⟩∈ σ∈Γ) ⟩ η-exp (nfKind (nfCtx Γ) j) (var∙ x) /⟨ k ⟩ nfSVSub (nfCtx Δ) σ ∎ ... | miss y missP = let open WfsCtxOps using (lookup-kd) nf-Γ-ctxs = nf-ctx Γ-ctx nf-Γ[x]≡kd-nf-j = nfCtx-lookup-kd x Γ Γ[x]≡kd-j nf-j-kds = lookup-kd x nf-Γ-ctxs nf-Γ[x]≡kd-nf-j missP-nf-σ = nf-Miss (nfCtx Δ) missP x∈⌊j⌋ = ∈-var x (⌊⌋-lookup (nfCtx Γ) x nf-Γ[x]≡kd-nf-j) in begin nf (nfCtx Δ) (Vec.lookup (toSub σ) x) ≡⟨ cong (nf (nfCtx Δ)) (lookup-toSub σ x) ⟩ nf (nfCtx Δ) ⌞ toElim (lookupSV σ x) ⌟ ≡⟨ cong (nf (nfCtx Δ) ∘ ⌞_⌟ ∘ toElim) (lookup-Miss missP) ⟩ nf (nfCtx Δ) (var y) ≈⟨ nf-var-kd-⌊⌋ (nfCtx Δ) y (P.begin ⌊ E.lookup (nfCtx Δ) y ⌋Asc P.≡˘⟨ ⌊⌋Asc-lookup (nfCtx Δ) y ⟩ S.lookup ⌊ nfCtx Δ ⌋Ctx y P.≡⟨ lookup-/⟨⟩∈-Miss (nf-/⟨⟩∈ σ∈Γ) x∈⌊j⌋ missP-nf-σ ⟩ S.lookup ⌊ nfCtx Γ ⌋Ctx x P.≡⟨ ⌊⌋-lookup (nfCtx Γ) x nf-Γ[x]≡kd-nf-j ⟩ kd ⌊ nfKind (nfCtx Γ) j ⌋ P.≡˘⟨ cong kd (⌊⌋-Kind/⟨⟩ (nfKind (nfCtx Γ) j)) ⟩ kd ⌊ nfKind (nfCtx Γ) j Kind/⟨ k ⟩ nfSVSub (nfCtx Δ) σ ⌋ P.∎) ⟩ η-exp (nfKind (nfCtx Γ) j Kind/⟨ k ⟩ nfSVSub (nfCtx Δ) σ) (var∙ y) ≡˘⟨ η-exp-ne-Miss-/⟨⟩ x y [] (nfKind (nfCtx Γ) j) missP-nf-σ ⟩ η-exp (nfKind (nfCtx Γ) j) (var∙ x) /⟨ k ⟩ nfSVSub (nfCtx Δ) σ ∎ nf-/⟨⟩ (∈-var _ _ _) σ∈Γ | tp a | () nf-/⟨⟩ (∈-⊥-f Γ-ctx) σ∈Γ = ≈-refl _ nf-/⟨⟩ (∈-⊤-f Γ-ctx) σ∈Γ = ≈-refl _ nf-/⟨⟩ (∈-∀-f {j} j-kd a∈*) σ∈Γ = ≈-∀∙ (nfKind-/⟨⟩ j-kd σ∈Γ) (nf-/⟨⟩ a∈* (∈-H↑ σ∈Γ)) nf-/⟨⟩ (∈-→-f a∈* b∈*) σ∈Γ = ≈-⇒∙ (nf-/⟨⟩ a∈* σ∈Γ) (nf-/⟨⟩ b∈* σ∈Γ) nf-/⟨⟩ (∈-Π-i j-kd a∈k k-kd) σ∈Γ = ≈-Λ∙ (≋-⌊⌋ (nfKind-/⟨⟩ j-kd σ∈Γ)) (nf-/⟨⟩ a∈k (∈-H↑ σ∈Γ)) nf-/⟨⟩ {Δ = Δ} {k} {Γ} {σ} {a · b} (∈-Π-e a∈Πjk b∈j _ _) σ∈Γ = begin nf (nfCtx Δ) (a / toSub σ) ↓⌜·⌝ nf (nfCtx Δ) (b / toSub σ) ≈⟨ ≈-↓⌜·⌝ (nf-/⟨⟩ a∈Πjk σ∈Γ) (nf-/⟨⟩ b∈j σ∈Γ) ⟩ (nf (nfCtx Γ) a /⟨ k ⟩ nfSVSub (nfCtx Δ) σ) ↓⌜·⌝ (nf (nfCtx Γ) b /⟨ k ⟩ nfSVSub (nfCtx Δ) σ) ≡⟨ sym (Nf∈-Π-e-/⟨⟩′ (nf-Tp∈ a∈Πjk) (nf-Tp∈ b∈j) (nf-/⟨⟩∈ σ∈Γ)) ⟩ nf (nfCtx Γ) a ↓⌜·⌝ nf (nfCtx Γ) b /⟨ k ⟩ nfSVSub (nfCtx Δ) σ ∎ nf-/⟨⟩ (∈-s-i a∈c⋯d) σ∈Γ = nf-/⟨⟩ a∈c⋯d σ∈Γ nf-/⟨⟩ (∈-⇑ a∈j j<∷k) σ∈Γ = nf-/⟨⟩ a∈j σ∈Γ nfKind-/⟨⟩ : ∀ {m n Δ k Γ} {σ : SVSub m n} {j} → Γ ⊢ j kd → Δ ⊢/Tp⟨ k ⟩ σ ∈ Γ → nfKind (nfCtx Δ) (j Kind/ toSub σ) ≋ nfKind (nfCtx Γ) j Kind/⟨ k ⟩ nfSVSub (nfCtx Δ) σ nfKind-/⟨⟩ (kd-⋯ a∈* b∈*) σ∈Γ = ≋-⋯ (nf-/⟨⟩ a∈* σ∈Γ) (nf-/⟨⟩ b∈* σ∈Γ) nfKind-/⟨⟩ (kd-Π j-kd k-kd) σ∈Γ = ≋-Π (nfKind-/⟨⟩ j-kd σ∈Γ) (nfKind-/⟨⟩ k-kd (∈-H↑ σ∈Γ)) -- Shorthands. nf-[] : ∀ {n} {Γ : Ctx n} {k a j b} → kd k ∷ Γ ⊢Tp a ∈ j → Γ ⊢Tp b ∈ k → nf (nfCtx Γ) (a [ b ]) ≈ nf (nfCtx (kd k ∷ Γ)) a [ nf (nfCtx Γ) b ∈ ⌊ k ⌋ ] nf-[] {_} {Γ} {k} {a} a∈j b∈k = subst (λ c → nf (nfCtx Γ) (a [ c ]) ≈ (nf (nfCtx (kd k ∷ Γ)) a [ nf (nfCtx Γ) c ∈ ⌊ k ⌋ ])) (⌞⌟∘⌜⌝-id _) (nf-/⟨⟩ a∈j (∈-hsub b∈k)) nfKind-[] : ∀ {n} {Γ : Ctx n} {k j b} → kd k ∷ Γ ⊢ j kd → Γ ⊢Tp b ∈ k → nfKind (nfCtx Γ) (j Kind[ b ]) ≋ nfKind (nfCtx (kd k ∷ Γ)) j Kind[ nf (nfCtx Γ) b ∈ ⌊ k ⌋ ] nfKind-[] {_} {Γ} {k} {j} j-kd b∈k = subst (λ c → nfKind (nfCtx Γ) (j Kind[ c ]) ≋ (nfKind (nfCtx (kd k ∷ Γ)) j Kind[ nf (nfCtx Γ) c ∈ ⌊ k ⌋ ])) (⌞⌟∘⌜⌝-id _) (nfKind-/⟨⟩ j-kd (∈-hsub b∈k))
{ "alphanum_fraction": 0.4846845347, "avg_line_length": 40.3154362416, "ext": "agda", "hexsha": "6cba79abce30af9c592c0fef5dac7c88d72841d1", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z", "max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z", "max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Blaisorblade/f-omega-int-agda", "max_forks_repo_path": "src/FOmegaInt/Kinding/Simple/Normalization.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z", "max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "Blaisorblade/f-omega-int-agda", "max_issues_repo_path": "src/FOmegaInt/Kinding/Simple/Normalization.agda", "max_line_length": 80, "max_stars_count": 12, "max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Blaisorblade/f-omega-int-agda", "max_stars_repo_path": "src/FOmegaInt/Kinding/Simple/Normalization.agda", "max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z", "max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z", "num_tokens": 6129, "size": 12014 }
module Pat (BaseType : Set) where data Ty : Set where ι : BaseType -> Ty _⟶_ : Ty -> Ty -> Ty data Bwd (A : Set) : Set where • : Bwd A _◄_ : Bwd A -> A -> Bwd A infixl 30 _◄_ Ctx = Bwd Ty data Take {A : Set} : Bwd A -> A -> Bwd A -> Set where hd : forall {x xs} -> Take (xs ◄ x) x xs tl : forall {x y xs ys} -> Take xs x ys -> Take (xs ◄ y) x (ys ◄ y) data Pat : Ctx -> Ctx -> Ty -> Ctx -> Set data Pats : Ctx -> Ty -> Ctx -> Ty -> Set where ε : forall {Θ τ} -> Pats Θ τ Θ τ _,_ : forall {Θ₁ Θ₂ Θ₃ ρ σ τ} -> Pat • Θ₁ ρ Θ₂ -> Pats Θ₂ σ Θ₃ τ -> Pats Θ₁ (ρ ⟶ σ) Θ₃ τ data Pat where ƛ : forall {Δ Θ Θ' σ τ} -> Pat (Δ ◄ σ) Θ τ Θ' -> Pat Δ Θ (σ ⟶ τ) Θ' _[_] : forall {Θ Θ' Δ σ τ} -> Take Θ σ Θ' -> Pats Δ σ • τ -> Pat Δ Θ τ Θ'
{ "alphanum_fraction": 0.4772727273, "avg_line_length": 23.2941176471, "ext": "agda", "hexsha": "8dcaa6aeab872b35410e62c4b4d4775a47bbd083", "lang": "Agda", "max_forks_count": 371, "max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z", "max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z", "max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cruhland/agda", "max_forks_repo_path": "examples/Miller/Pat.agda", "max_issues_count": 4066, "max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de", "max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z", "max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cruhland/agda", "max_issues_repo_path": "examples/Miller/Pat.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": "examples/Miller/Pat.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": 368, "size": 792 }
-- Andreas, 2012-03-08 module NoNoTerminationCheck where {-# NON_TERMINATING #-} f : Set f = f -- the pragma should not extend to the following definition g : Set g = g -- error: non-termination
{ "alphanum_fraction": 0.7, "avg_line_length": 13.3333333333, "ext": "agda", "hexsha": "ce13b1a18a5c21d89bc6d3d9bee39d2e994fe41f", "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/NoNoTerminationCheck.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/NoNoTerminationCheck.agda", "max_line_length": 59, "max_stars_count": 1989, "max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "shlevy/agda", "max_stars_repo_path": "test/Fail/NoNoTerminationCheck.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": 58, "size": 200 }
open import Common.Prelude open import Common.Reflection open import Common.Equality data Dec {a} (A : Set a) : Set a where yes : A → Dec A no : Dec A record Eq {a} (A : Set a) : Set a where constructor eqDict field _==_ : (x y : A) → Dec (x ≡ y) module M {a} {A : Set a} {{EqA : Eq A}} where _==_ : (x y : A) → Dec (x ≡ y) _==_ = Eq._==_ EqA open Eq {{...}} private eqNat : (x y : Nat) → Dec (x ≡ y) eqNat zero zero = yes refl eqNat zero (suc y) = no eqNat (suc x) zero = no eqNat (suc x) (suc y) with eqNat x y eqNat (suc x) (suc .x) | yes refl = yes refl ... | no = no eqBool : (x y : Bool) → Dec (x ≡ y) eqBool true true = yes refl eqBool true false = no eqBool false true = no eqBool false false = yes refl unquoteDecl EqNat = define (iArg EqNat) (funDef (def (quote Eq) (vArg (def (quote Nat) []) ∷ [])) (clause [] (con (quote eqDict) (vArg (def (quote eqNat) []) ∷ [])) ∷ [])) instance EqBool : Eq Bool unquoteDef EqBool = defineFun EqBool (clause [] (con (quote eqDict) (vArg (def (quote eqBool) []) ∷ [])) ∷ []) id : {A : Set} → A → A id x = x tm : QName → Term tm eq = def (quote id) (vArg (def eq (vArg (lit (nat 0)) ∷ vArg (lit (nat 1)) ∷ [])) ∷ []) tm₂ : QName → Term tm₂ eq = def eq (iArg (def (quote EqNat) []) ∷ vArg (lit (nat 0)) ∷ vArg (lit (nat 1)) ∷ []) _==′_ : ∀ {a} {A : Set a} {{EqA : Eq A}} (x y : A) → Dec (x ≡ y) _==′_ = _==_ ok₁ : Dec (0 ≡ 1) ok₁ = unquote (give (tm (quote _==′_))) ok₂ : Dec (0 ≡ 1) ok₂ = unquote (give (tm₂ (quote _==_))) ok₃ : Dec (0 ≡ 1) ok₃ = unquote (give (tm (quote M._==_))) ok₄ : Dec (true ≡ false) ok₄ = true == false ok₅ : Dec (2 ≡ 2) ok₅ = 2 == 2 -- Was bad. bad : Dec (0 ≡ 1) bad = unquote (give (tm (quote _==_)))
{ "alphanum_fraction": 0.5410022779, "avg_line_length": 23.4133333333, "ext": "agda", "hexsha": "a69662f04eaf9c28d277bcce6270f90699fcaf08", "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/UnquoteInstance.agda", "max_issues_count": 3, "max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z", "max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z", "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "hborum/agda", "max_issues_repo_path": "test/Succeed/UnquoteInstance.agda", "max_line_length": 94, "max_stars_count": 3, "max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "hborum/agda", "max_stars_repo_path": "test/Succeed/UnquoteInstance.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": 727, "size": 1756 }
{-# OPTIONS --without-K #-} module well-typed-syntax-eq-dec where open import well-typed-syntax open import common context-pick-if : ∀ {ℓ} {P : Context → Set ℓ} {Γ : Context} (dummy : P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’)) (val : P Γ) → P (ε ▻ ‘Σ’ ‘Context’ ‘Typ’) context-pick-if {P = P} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} dummy val = val context-pick-if {P = P} {Γ} dummy val = dummy context-pick-if-refl : ∀ {ℓ P dummy val} → context-pick-if {ℓ} {P} {ε ▻ ‘Σ’ ‘Context’ ‘Typ’} dummy val ≡ val context-pick-if-refl {P = P} = refl
{ "alphanum_fraction": 0.4913385827, "avg_line_length": 37.3529411765, "ext": "agda", "hexsha": "653cb7853efeccba23abc1187f950235bc0da1a4", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_forks_event_min_datetime": "2015-07-17T18:53:37.000Z", "max_forks_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "JasonGross/lob", "max_forks_repo_path": "internal/well-typed-syntax-eq-dec.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_issues_repo_issues_event_max_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-17T20:20:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "JasonGross/lob", "max_issues_repo_path": "internal/well-typed-syntax-eq-dec.agda", "max_line_length": 92, "max_stars_count": 19, "max_stars_repo_head_hexsha": "716129208eaf4fe3b5f629f95dde4254805942b3", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "JasonGross/lob", "max_stars_repo_path": "internal/well-typed-syntax-eq-dec.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-17T14:04:53.000Z", "max_stars_repo_stars_event_min_datetime": "2015-07-17T17:53:30.000Z", "num_tokens": 211, "size": 635 }
module Test.NFTest where open import Data.Nat open import Data.List open import Data.Product open import Test.Factorial open import NF open import NF.Nat open import NF.List open import NF.Product l : List (ℕ × ℕ) l = nf ((1 , factorial 1) ∷ (1 + 1 , factorial (1 + 1)) ∷ [] ++ (5 , factorial 5) ∷ [])
{ "alphanum_fraction": 0.6634615385, "avg_line_length": 22.2857142857, "ext": "agda", "hexsha": "95d4c871d7bf5ead12ca3e8807d8c98fd79aedd2", "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": "4f037dad109a5d080023557f0869418ed9fc11c1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yanok/normalize-via-instances", "max_forks_repo_path": "test/Test/NFTest.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1", "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": "yanok/normalize-via-instances", "max_issues_repo_path": "test/Test/NFTest.agda", "max_line_length": 64, "max_stars_count": null, "max_stars_repo_head_hexsha": "4f037dad109a5d080023557f0869418ed9fc11c1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yanok/normalize-via-instances", "max_stars_repo_path": "test/Test/NFTest.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 100, "size": 312 }
module Naturals where data ℕ : Set where zero : ℕ suc : ℕ → ℕ -- suc (suc (suc (suc (suc (suc (suc zero)))))) {-# BUILTIN NATURAL ℕ #-} import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _∎) _+_ : ℕ → ℕ → ℕ zero + n = n -- 0 + n ≡ n suc m + n = suc (m + n) -- (1 + m) + n ≡ 1 + (m + n) _ : 1 + 1 ≡ 2 _ = refl _ : 3 + 4 ≡ 7 _ = begin 3 + 4 ≡⟨⟩ suc 1 + 4 ∎
{ "alphanum_fraction": 0.491416309, "avg_line_length": 16.0689655172, "ext": "agda", "hexsha": "af5b1436ff5734b6f4b2874aa8341530ea7b74b1", "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": "9f23862b35c00b810e20f2e1e661142c024baa33", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "xiongxin/playground", "max_forks_repo_path": "plfa/src/Naturals.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "9f23862b35c00b810e20f2e1e661142c024baa33", "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": "xiongxin/playground", "max_issues_repo_path": "plfa/src/Naturals.agda", "max_line_length": 52, "max_stars_count": null, "max_stars_repo_head_hexsha": "9f23862b35c00b810e20f2e1e661142c024baa33", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "xiongxin/playground", "max_stars_repo_path": "plfa/src/Naturals.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 210, "size": 466 }
------------------------------------------------------------------------------ -- Filter ------------------------------------------------------------------------------ {-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Data.List.Filter where open import Common.FOL.Relation.Binary.EqReasoning open import FOTC.Base open import FOTC.Base.PropertiesI open import FOTC.Base.List open import FOTC.Data.Bool.Type open import FOTC.Data.Nat.Inequalities open import FOTC.Data.Nat.Inequalities.PropertiesI open import FOTC.Data.Nat.Type open import FOTC.Data.List open import FOTC.Data.List.PropertiesI ------------------------------------------------------------------------------ postulate filter : D → D → D filter-[] : ∀ p → filter p [] ≡ [] filter-∷ : ∀ p x xs → filter p (x ∷ xs) ≡ (if p · x then x ∷ filter p xs else filter p xs) postulate filter-List : ∀ p {xs} → List xs → List (filter p xs) from-Bool : ∀ {b} → Bool b → b ≡ true ∨ b ≡ false from-Bool btrue = inj₁ refl from-Bool bfalse = inj₂ refl -- lenght-filter : ∀ p {xs} → (∀ x → Bool (p · x)) → List xs → -- length (filter p xs) ≤ length xs -- lenght-filter p hp lnil = -- le (length (filter p [])) (length []) -- ≡⟨ ltLeftCong (lengthCong (filter-[] p)) ⟩ -- le (length []) (length []) -- ≡⟨ ltCong length-[] (succCong length-[]) ⟩ -- le zero zero -- ≡⟨ x≤x nzero ⟩ -- true ∎ -- lenght-filter p hp (lcons x {xs} Lxs) = case prf₁ prf₂ (from-Bool (hp x)) -- where -- prf₁ : p · x ≡ true → -- le (length (filter p (x ∷ xs))) (length (x ∷ xs)) ≡ true -- prf₁ h = {!!} -- prf₂ : p · x ≡ false → -- le (length (filter p (x ∷ xs))) (length (x ∷ xs)) ≡ true -- prf₂ h = -- le (length (filter p (x ∷ xs))) (length (x ∷ xs)) -- ≡⟨ ltLeftCong (lengthCong {!!}) ⟩ -- le (length (filter p xs)) (length (x ∷ xs)) -- ≡⟨ ≤-trans (lengthList-N (filter-List p Lxs)) -- (lengthList-N Lxs) -- (lengthList-N (lcons x Lxs)) -- (lenght-filter p hp Lxs) -- (x<y→x≤y (lengthList-N Lxs) (lengthList-N (lcons x Lxs)) -- (lg-x<lg-x∷xs x Lxs)) ⟩ -- true ∎
{ "alphanum_fraction": 0.4873985476, "avg_line_length": 34.4264705882, "ext": "agda", "hexsha": "8d89d66df7235eec187d97d874be1b6c9f6bf788", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z", "max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z", "max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "asr/fotc", "max_forks_repo_path": "notes/FOT/FOTC/Data/List/Filter.agda", "max_issues_count": 2, "max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z", "max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "asr/fotc", "max_issues_repo_path": "notes/FOT/FOTC/Data/List/Filter.agda", "max_line_length": 78, "max_stars_count": 11, "max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/fotc", "max_stars_repo_path": "notes/FOT/FOTC/Data/List/Filter.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": 714, "size": 2341 }
open import Oscar.Prelude open import Oscar.Class module Oscar.Class.Symmetry where module Symmetry' {𝔬} {𝔒 : Ø 𝔬} {𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯) x y = ℭLASS (x ,, y ,, _∼_) (x ∼ y → y ∼ x) module Symmetry {𝔬} {𝔒 : Ø 𝔬} {𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯) where class = ∀ {x y} → Symmetry'.class _∼_ x y type = ∀ {x y} → Symmetry'.type _∼_ x y method : ⦃ _ : class ⦄ → type method {x = x} {y} = Symmetry'.method _∼_ x y module _ {𝔬} {𝔒 : Ø 𝔬} {𝔯} {_∼_ : 𝔒 → 𝔒 → Ø 𝔯} where symmetry = Symmetry.method _∼_ syntax symmetry {x} {y} x∼y = x ⟨∼ x∼y ∼⟩ y module _ {𝔬} {𝔒 : Ø 𝔬} {𝔯} (_∼_ : 𝔒 → 𝔒 → Ø 𝔯) ⦃ _ : Symmetry.class _∼_ ⦄ where symmetry[_] = λ {x y} (x∼y : x ∼ y) → Symmetry.method _∼_ x∼y
{ "alphanum_fraction": 0.5173852573, "avg_line_length": 20.5428571429, "ext": "agda", "hexsha": "80bba44ec7dd8e6429b8bb5a0357973306bee958", "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/Symmetry.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/Symmetry.agda", "max_line_length": 63, "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/Symmetry.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 396, "size": 719 }
module UniDB.Subst.Shifts where open import UniDB.Subst.Core open import UniDB.Morph.Shifts module _ {T : STX} {{vrT : Vr T}} {{apTT : Ap T T}} {{apVrT : ApVr T}} where instance iLkCompApShifts : LkCompAp T Shifts lk-⊙-ap {{iLkCompApShifts}} ξ₁ ξ₂ i = begin vr (lk (ξ₁ ⊙ ξ₂) i) ≡⟨ cong vr (shiftIx-⊙ ξ₁ ξ₂ i) ⟩ vr (lk ξ₂ (lk ξ₁ i)) ≡⟨ sym (ap-vr {T} ξ₂ (lk ξ₁ i)) ⟩ ap {T} ξ₂ (vr (lk ξ₁ i)) ∎
{ "alphanum_fraction": 0.5750577367, "avg_line_length": 28.8666666667, "ext": "agda", "hexsha": "ad1d893482ddcf1faa1bf95d07bbf8c1898c3fef", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "skeuchel/unidb-agda", "max_forks_repo_path": "UniDB/Subst/Shifts.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "skeuchel/unidb-agda", "max_issues_repo_path": "UniDB/Subst/Shifts.agda", "max_line_length": 76, "max_stars_count": null, "max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "skeuchel/unidb-agda", "max_stars_repo_path": "UniDB/Subst/Shifts.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 214, "size": 433 }
{-# OPTIONS --without-K --safe #-} module Categories.Functor.Profunctor where open import Level open import Data.Product open import Relation.Binary.Bundles open import Categories.Category open import Categories.Category.Instance.Setoids open import Categories.Functor hiding (id) open import Categories.Functor.Bifunctor open import Categories.Functor.Hom open import Categories.NaturalTransformation open import Categories.NaturalTransformation.Equivalence open import Function.Equality using (Π; _⟨$⟩_; cong) Profunctor : ∀ {o ℓ e} {o′ ℓ′ e′} → Category o ℓ e → Category o′ ℓ′ e′ → Set _ Profunctor {ℓ = ℓ} {e} {ℓ′ = ℓ′} {e′} C D = Bifunctor (Category.op D) C (Setoids (ℓ ⊔ ℓ′) (e ⊔ e′)) -- Calling the profunctor identity "id" is a bad idea proid : ∀ {o ℓ e} → {C : Category o ℓ e} → Profunctor C C proid {C = C} = Hom[ C ][-,-] module Profunctor {o ℓ e} {o′} (C : Category o ℓ e) (D : Category o′ ℓ e) where module C = Category C open module D = Category D hiding (id) open D.HomReasoning open import Categories.Morphism.Reasoning D using (assoc²''; elimˡ; elimʳ) -- representable profunctors -- hom(f,1) repˡ : ∀ (F : Functor C D) → Profunctor D C repˡ F = record { F₀ = λ (c , d) → record { Carrier = D [ F₀ c , d ] ; _≈_ = D._≈_ ; isEquivalence = D.equiv } ; F₁ = λ (f , g) → record { _⟨$⟩_ = λ x → g ∘ x ∘ F₁ f ; cong = λ x → begin _ ≈⟨ refl⟩∘⟨ x ⟩∘⟨refl ⟩ _ ∎ } ; identity = λ {x} {y} {y'} y≈y' → begin D.id ∘ y ∘ F₁ C.id ≈⟨ D.identityˡ ⟩ y ∘ F₁ C.id ≈⟨ elimʳ identity ⟩ y ≈⟨ y≈y' ⟩ y' ∎ ; homomorphism = λ { {f = f0 , f1} {g = g0 , g1} {x} {y} x≈y → begin (g1 ∘ f1) ∘ x ∘ F₁ (f0 C.∘ g0) ≈⟨ refl⟩∘⟨ x≈y ⟩∘⟨ F.homomorphism ⟩ (g1 ∘ f1) ∘ y ∘ F₁ f0 ∘ F₁ g0 ≈⟨ refl⟩∘⟨ D.sym-assoc ⟩ (g1 ∘ f1) ∘ (y ∘ F₁ f0) ∘ F₁ g0 ≈⟨ Equiv.sym assoc²'' ⟩ g1 ∘ (f1 ∘ y ∘ F₁ f0) ∘ F₁ g0 ∎ } ; F-resp-≈ = λ { {f = f0 , f1} {g = g0 , g1} (f0≈g0 , f1≈g1) {x} {y} x≈y → begin f1 ∘ x ∘ F₁ f0 ≈⟨ f1≈g1 ⟩∘⟨ x≈y ⟩∘⟨ F-resp-≈ f0≈g0 ⟩ g1 ∘ y ∘ F₁ g0 ∎ } } where open module F = Functor F -- hom(1,f) repʳ : (F : Functor C D) → Profunctor C D repʳ F = record { F₀ = λ (c , d) → record { Carrier = D [ c , F₀ d ] ; _≈_ = D._≈_ ; isEquivalence = D.equiv } ; F₁ = λ (f , g) → record { _⟨$⟩_ = λ x → F₁ g ∘ x ∘ f ; cong = λ x → begin _ ≈⟨ refl⟩∘⟨ x ⟩∘⟨refl ⟩ _ ∎ } ; identity = λ {x} {y} {y'} y≈y' → begin F₁ C.id ∘ y ∘ D.id ≈⟨ elimˡ identity ⟩ y ∘ D.id ≈⟨ D.identityʳ ⟩ y ≈⟨ y≈y' ⟩ y' ∎ ; homomorphism = λ { {f = f0 , f1} {g = g0 , g1} {x} {y} x≈y → begin F₁ (g1 C.∘ f1) ∘ x ∘ f0 ∘ g0 ≈⟨ F.homomorphism ⟩∘⟨ x≈y ⟩∘⟨refl ⟩ (F₁ g1 ∘ F₁ f1) ∘ y ∘ f0 ∘ g0 ≈⟨ refl⟩∘⟨ D.sym-assoc ⟩ (F₁ g1 ∘ F₁ f1) ∘ (y ∘ f0) ∘ g0 ≈⟨ Equiv.sym assoc²'' ⟩ F₁ g1 ∘ (F₁ f1 ∘ y ∘ f0) ∘ g0 ∎ } ; F-resp-≈ = λ { {f = f0 , f1} {g = g0 , g1} (f0≈g0 , f1≈g1) {x} {y} x≈y → begin F₁ f1 ∘ x ∘ f0 ≈⟨ F-resp-≈ f1≈g1 ⟩∘⟨ x≈y ⟩∘⟨ f0≈g0 ⟩ F₁ g1 ∘ y ∘ g0 ∎ } } where open module F = Functor F -- each Prof(C,D) is a category homProf : {o o′ ℓ e : Level} → (C : Category o ℓ e) → (D : Category o′ ℓ e) → Category _ _ _ homProf C D = record { Obj = Profunctor C D ; _⇒_ = NaturalTransformation ; _≈_ = _≃_ ; id = id ; _∘_ = _∘ᵥ_ ; assoc = λ { {f = f} {g} {h} → assoc-lemma {f = f} {g} {h}} ; sym-assoc = λ { {f = f} {g} {h} → sym-assoc-lemma {f = f} {g} {h}} ; identityˡ = λ { {f = f} → id-lemmaˡ {f = f} } ; identityʳ = λ { {f = f} → id-lemmaʳ {f = f} } ; identity² = λ z → z ; equiv = ≃-isEquivalence ; ∘-resp-≈ = λ { {f = f} {h} {g} {i} eq eq' → ∘ᵥ-resp-≃ {f = f} {h} {g} {i} eq eq' } } where id-lemmaˡ : ∀ {o o′ ℓ ℓ′ e e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {P K : Functor C D} {f : NaturalTransformation P K} → id ∘ᵥ f ≃ f id-lemmaˡ {D = D} = Category.identityˡ D id-lemmaʳ : ∀ {o o′ ℓ ℓ′ e e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {P K : Functor C D} {f : NaturalTransformation P K} → f ∘ᵥ id ≃ f id-lemmaʳ {D = D} = Category.identityʳ D assoc-lemma : ∀ {o o′ ℓ ℓ′ e e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {E F G H : Functor C D} {f : NaturalTransformation E F} {g : NaturalTransformation F G} {h : NaturalTransformation G H} → (h ∘ᵥ g) ∘ᵥ f ≃ h ∘ᵥ g ∘ᵥ f assoc-lemma {D = D} = Category.assoc D sym-assoc-lemma : ∀ {o o′ ℓ ℓ′ e e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {E F G H : Functor C D} {f : NaturalTransformation E F} {g : NaturalTransformation F G} {h : NaturalTransformation G H} → h ∘ᵥ g ∘ᵥ f ≃ (h ∘ᵥ g) ∘ᵥ f sym-assoc-lemma {D = D} = Category.sym-assoc D ∘ᵥ-resp-≃ : ∀ {o o′ ℓ ℓ′ e e′} {C : Category o ℓ e} {D : Category o′ ℓ′ e′} {R P K : Functor C D} {f h : NaturalTransformation P K} {g i : NaturalTransformation R P} → f ≃ h → g ≃ i → f ∘ᵥ g ≃ h ∘ᵥ i ∘ᵥ-resp-≃ {D = D} fh gi = Category.∘-resp-≈ D fh gi
{ "alphanum_fraction": 0.4889309366, "avg_line_length": 38.8602941176, "ext": "agda", "hexsha": "e061fd8d7887c34fd2cd24d0c95e808fd4b8c662", "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": "d9e4f578b126313058d105c61707d8c8ae987fa8", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Code-distancing/agda-categories", "max_forks_repo_path": "src/Categories/Functor/Profunctor.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8", "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": "Code-distancing/agda-categories", "max_issues_repo_path": "src/Categories/Functor/Profunctor.agda", "max_line_length": 109, "max_stars_count": 5, "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/Functor/Profunctor.agda", "max_stars_repo_stars_event_max_datetime": "2019-05-22T03:54:24.000Z", "max_stars_repo_stars_event_min_datetime": "2019-05-21T17:07:19.000Z", "num_tokens": 2412, "size": 5285 }
{-# OPTIONS --cubical --safe #-} open import Cubical.Core.Everything open import Cubical.Foundations.Everything open import Agda.Primitive using (lzero) module Cubical.Data.DescendingList.Strict.Properties (A : Type₀) (_>_ : A → A → Type₀) where open import Cubical.Data.DescendingList.Strict A _>_ open import Cubical.HITs.ListedFiniteSet renaming (_∈_ to _∈ʰ_) import Cubical.Data.Empty as Empty open Empty using (⊥-elim) open import Cubical.Relation.Nullary.DecidableEq open import Cubical.Relation.Nullary using (Dec; Discrete) renaming (¬_ to Type¬_) unsort : SDL → LFSet A unsort [] = [] unsort (cons x xs x>xs) = x ∷ unsort xs module _ where open import Cubical.Relation.Nullary data Tri (A B C : Set) : Set where tri-< : A → ¬ B → ¬ C → Tri A B C tri-≡ : ¬ A → B → ¬ C → Tri A B C tri-> : ¬ A → ¬ B → C → Tri A B C module IsoToLFSet (A-discrete : Discrete A) (>-isProp : ∀ {x y} → isProp (x > y)) (tri : ∀ x y → Tri (y > x) (x ≡ y) (x > y)) (>-trans : ∀ {x y z} → x > y → y > z → x > z) (>-irreflexive : ∀ {x} → Type¬ x > x) where Tri' : A → A → Set Tri' x y = Tri (y > x) (x ≡ y) (x > y) open import Cubical.Foundations.Logic open import Cubical.HITs.PropositionalTruncation -- Membership is defined via `LFSet`. -- This computes just as well as a direct inductive definition, -- and additionally lets us use the extra `comm` and `dup` paths to prove -- things about membership. _∈ˡ_ : A → SDL → hProp lzero a ∈ˡ l = a ∈ʰ unsort l Memˡ : SDL → A → hProp lzero Memˡ l a = a ∈ˡ l Memʰ : LFSet A → A → hProp lzero Memʰ l a = a ∈ʰ l >ᴴ-trans : ∀ x y zs → x > y → y >ᴴ zs → x >ᴴ zs >ᴴ-trans x y [] x>y y>zs = >ᴴ[] >ᴴ-trans x y (cons z zs _) x>y (>ᴴcons y>z) = >ᴴcons (>-trans x>y y>z) ≡ₚ-sym : ∀ {A : Set} {x y : A} → [ x ≡ₚ y ] → [ y ≡ₚ x ] ≡ₚ-sym p = recPropTrunc squash (λ p → ∣ sym p ∣) p >-all : ∀ x l → x >ᴴ l → ∀ a → [ a ∈ˡ l ] → x > a >-all x (cons y zs y>zs) (>ᴴcons x>y) a a∈l = ⊔-elim (a ≡ₚ y) (a ∈ˡ zs) (λ _ → (x > a) , >-isProp {x} {a}) (λ a≡ₚy → substₚ (λ q → x > q , >-isProp) (≡ₚ-sym a≡ₚy) x>y) (λ a∈zs → >-all x zs (>ᴴ-trans x y zs x>y y>zs) a a∈zs) a∈l >-absent : ∀ x l → x >ᴴ l → [ ¬ (x ∈ˡ l) ] >-absent x l x>l x∈l = ⊥-elim (>-irreflexive (>-all x l x>l x x∈l)) >ᴴ-isProp : ∀ x xs → isProp (x >ᴴ xs) >ᴴ-isProp x _ >ᴴ[] >ᴴ[] = refl >ᴴ-isProp x _ (>ᴴcons p) (>ᴴcons q) = cong >ᴴcons (>-isProp p q) SDL-isSet : isSet SDL SDL-isSet = isSetDL.isSetDL A _>_ >-isProp A-discrete where open import Cubical.Data.DescendingList.Properties insert : A → SDL → SDL >ᴴinsert : {x y : A} {u : SDL} → y >ᴴ u → (y > x) → y >ᴴ insert x u insert x [] = cons x [] >ᴴ[] insert x (cons y zs good) with tri x y insert x (cons y zs good) | tri-< x<y _ _ = cons y (insert x zs) (>ᴴinsert good x<y) insert x (cons y zs good) | tri-≡ _ x≡y _ = cons y zs good insert x (cons y zs good) | tri-> _ _ x>y = cons x (cons y zs good) (>ᴴcons x>y) >ᴴinsert >ᴴ[] y>x = >ᴴcons y>x >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x with tri x y >ᴴinsert {x} {y} (>ᴴcons {z} z>zs) y>x | tri-< _ _ e = >ᴴcons z>zs >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-≡ _ _ e = >ᴴcons y>ys >ᴴinsert {x} (>ᴴcons {y} y>ys) y>x | tri-> _ _ _ = >ᴴcons y>x insert-correct : ∀ x ys → unsort (insert x ys) ≡ (x ∷ unsort ys) insert-correct x [] = refl insert-correct x (cons y zs y>zs) with tri x y ... | tri-< _ _ _ = y ∷ unsort (insert x zs) ≡⟨ (λ i → y ∷ (insert-correct x zs i)) ⟩ y ∷ x ∷ unsort zs ≡⟨ comm _ _ _ ⟩ x ∷ y ∷ unsort zs ∎ ... | tri-≡ _ x≡y _ = sym (dup y (unsort zs)) ∙ (λ i → (x≡y (~ i)) ∷ y ∷ unsort zs) ... | tri-> _ _ _ = refl insert-correct₂ : ∀ x y zs → unsort (insert x (insert y zs)) ≡ (x ∷ y ∷ unsort zs) insert-correct₂ x y zs = insert-correct x (insert y zs) ∙ cong (λ q → x ∷ q) (insert-correct y zs) abstract -- for some reason, making [exclude] non-abstract makes -- typechecking noticeably slower exclude : A → (A → hProp lzero) → (A → hProp lzero) exclude x h a = ¬ a ≡ₚ x ⊓ h a >-excluded : ∀ x xs → x >ᴴ xs → exclude x (Memʰ (x ∷ unsort xs)) ≡ Memˡ xs >-excluded x xs x>xs = funExt (λ a → ⇔toPath (to a) (from a)) where import Cubical.Data.Prod as D import Cubical.Data.Sum as D from : ∀ a → [ a ∈ˡ xs ] → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ] from a a∈xs = (recPropTrunc (snd ⊥) a≢x) D., inr a∈xs where a≢x : Type¬ (a ≡ x) a≢x = λ a≡x → (>-absent x xs x>xs (transport (λ i → [ a≡x i ∈ˡ xs ]) a∈xs )) to : ∀ a → [ ¬ a ≡ₚ x ⊓ (a ≡ₚ x ⊔ a ∈ˡ xs) ] → [ a ∈ˡ xs ] to a (a≢x D., x) = recPropTrunc (snd (a ∈ˡ xs)) (λ { (D.inl a≡x) → ⊥-elim (a≢x a≡x); (D.inr x) → x }) x cons-eq : ∀ x xs x>xs y ys y>ys → x ≡ y → xs ≡ ys → cons x xs x>xs ≡ cons y ys y>ys cons-eq x xs x>xs y ys y>ys x≡y xs≡ys i = cons (x≡y i) (xs≡ys i) (>ᴴ-isProp (x≡y i) (xs≡ys i) (transp (λ j → (x≡y (i ∧ j)) >ᴴ (xs≡ys) (i ∧ j)) (~ i) x>xs) (transp (λ j → (x≡y (i ∨ ~ j)) >ᴴ (xs≡ys) (i ∨ ~ j)) i y>ys) i) Memˡ-inj-cons : ∀ x xs x>xs y ys y>ys → x ≡ y → Memˡ (cons x xs x>xs) ≡ Memˡ (cons y ys y>ys) → Memˡ xs ≡ Memˡ ys Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e = Memˡ xs ≡⟨ sym (>-excluded x xs x>xs) ⟩ exclude x (Memʰ (x ∷ unsort xs)) ≡⟨ (λ i → exclude (x≡y i) (e i)) ⟩ exclude y (Memʰ (y ∷ unsort ys)) ≡⟨ (>-excluded y ys y>ys) ⟩ Memˡ ys ∎ Memˡ-inj : ∀ l₁ l₂ → Memˡ l₁ ≡ Memˡ l₂ → l₁ ≡ l₂ Memˡ-inj [] [] eq = refl Memˡ-inj [] (cons y ys y>ys) eq = ⊥-elim (transport (λ i → [ eq (~ i) y ]) (inl ∣ refl ∣)) Memˡ-inj (cons y ys y>ys) [] eq = ⊥-elim (transport (λ i → [ eq i y ]) (inl ∣ refl ∣)) Memˡ-inj (cons x xs x>xs) (cons y ys y>ys) e = ⊔-elim (x ≡ₚ y) (x ∈ʰ unsort ys) (λ _ → ((cons x xs x>xs) ≡ (cons y ys y>ys)) , SDL-isSet _ _) (recPropTrunc (SDL-isSet _ _) with-x≡y) (⊥-elim ∘ x∉ys) (transport (λ i → [ e i x ]) (inl ∣ refl ∣)) where xxs = cons x xs x>xs x∉ys : [ ¬ x ∈ˡ ys ] x∉ys x∈ys = ⊥-elim (>-irreflexive y>y) where y>x : y > x y>x = (>-all y ys y>ys x x∈ys) y∈xxs : [ y ∈ˡ (cons x xs x>xs) ] y∈xxs = (transport (λ i → [ e (~ i) y ]) (inl ∣ refl ∣)) y>y : y > y y>y = >-all y xxs (>ᴴcons y>x) y y∈xxs with-x≡y : x ≡ y → (cons x xs x>xs) ≡ (cons y ys y>ys) with-x≡y x≡y = cons-eq x xs x>xs y ys y>ys x≡y r where r : xs ≡ ys r = Memˡ-inj _ _ (Memˡ-inj-cons x xs x>xs y ys y>ys x≡y e) unsort-inj : ∀ x y → unsort x ≡ unsort y → x ≡ y unsort-inj x y e = Memˡ-inj x y λ i a → a ∈ʰ (e i) insert-swap : (x y : A) (zs : SDL) → insert x (insert y zs) ≡ insert y (insert x zs) insert-swap x y zs = unsort-inj (insert x (insert y zs)) (insert y (insert x zs)) (unsort (insert x (insert y zs)) ≡⟨ (λ i → insert-correct₂ x y zs i) ⟩ x ∷ y ∷ unsort zs ≡⟨ (λ i → comm x y (unsort zs) i) ⟩ y ∷ x ∷ unsort zs ≡⟨ (λ i → insert-correct₂ y x zs (~ i)) ⟩ unsort (insert y (insert x zs)) ∎) insert-dup : (x : A) (ys : SDL) → insert x (insert x ys) ≡ insert x ys insert-dup x ys = unsort-inj (insert x (insert x ys)) (insert x ys) ( unsort (insert x (insert x ys)) ≡⟨ (λ i → insert-correct₂ x x ys i) ⟩ x ∷ x ∷ unsort ys ≡⟨ dup x (unsort ys) ⟩ x ∷ unsort ys ≡⟨ (λ i → insert-correct x ys (~ i)) ⟩ unsort (insert x ys) ∎ ) sort : LFSet A → SDL sort = LFSetRec.f [] insert insert-swap insert-dup SDL-isSet unsort∘sort : ∀ x → unsort (sort x) ≡ x unsort∘sort = LFPropElim.f (λ x → unsort (sort x) ≡ x) refl (λ x {ys} ys-hyp → insert-correct x (sort ys) ∙ cong (λ q → x ∷ q) ys-hyp) (λ xs → trunc (unsort (sort xs)) xs) sort∘unsort : ∀ x → sort (unsort x) ≡ x sort∘unsort x = unsort-inj (sort (unsort x)) x (unsort∘sort (unsort x)) SDL-LFSet-iso : Iso SDL (LFSet A) SDL-LFSet-iso = (iso unsort sort unsort∘sort sort∘unsort) SDL≡LFSet : SDL ≡ LFSet A SDL≡LFSet = ua (isoToEquiv SDL-LFSet-iso)
{ "alphanum_fraction": 0.5263093189, "avg_line_length": 36.1511111111, "ext": "agda", "hexsha": "14a11f2496af691122eeac5c57b0300abe89b3d3", "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": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "limemloh/cubical", "max_forks_repo_path": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "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": "limemloh/cubical", "max_issues_repo_path": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_line_length": 115, "max_stars_count": null, "max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "limemloh/cubical", "max_stars_repo_path": "Cubical/Data/DescendingList/Strict/Properties.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3620, "size": 8134 }
{-# OPTIONS --without-K --safe #-} -- Various operations and proofs on morphisms between products -- Perhaps a bit of overkill? There is so much here that it's impossible to remember -- it all open import Categories.Category module Categories.Object.Product.Morphisms {o ℓ e} (𝒞 : Category o ℓ e) where open import Function using (flip) open import Level open import Categories.Object.Product.Core 𝒞 open Category 𝒞 open HomReasoning private variable A B C D E F : Obj f f′ g g′ h i : A ⇒ B infix 10 [_]⟨_,_⟩ [_⇒_]_×_ infix 12 [[_]] [_]π₁ [_]π₂ [[_]] : Product A B → Obj [[ p ]] = Product.A×B p [_]⟨_,_⟩ : ∀ (p : Product B C) → A ⇒ B → A ⇒ C → A ⇒ [[ p ]] [ p ]⟨ f , g ⟩ = Product.⟨_,_⟩ p f g [_]π₁ : ∀ (p : Product A B) → [[ p ]] ⇒ A [_]π₁ = Product.π₁ [_]π₂ : ∀ (p : Product A B) → [[ p ]] ⇒ B [_]π₂ = Product.π₂ [_⇒_]_×_ : ∀ (p₁ : Product A C) (p₂ : Product B D) → (A ⇒ B) → (C ⇒ D) → ([[ p₁ ]] ⇒ [[ p₂ ]]) [ p₁ ⇒ p₂ ] f × g = [ p₂ ]⟨ f ∘ p₁.π₁ , g ∘ p₁.π₂ ⟩ where module p₁ = Product p₁ module p₂ = Product p₂ id×id : ∀ (p : Product A B) → [ p ⇒ p ] id × id ≈ id id×id p = begin ⟨ id ∘ π₁ , id ∘ π₂ ⟩ ≈⟨ ⟨⟩-cong₂ identityˡ identityˡ ⟩ ⟨ π₁ , π₂ ⟩ ≈⟨ η ⟩ id ∎ where open Product p repack≡id×id : ∀ (p₁ p₂ : Product A B) → repack p₁ p₂ ≈ [ p₁ ⇒ p₂ ] id × id repack≡id×id p₁ p₂ = sym (Product.⟨⟩-cong₂ p₂ identityˡ identityˡ) [_⇒_]π₁∘× : ∀ (p₁ : Product A C)(p₂ : Product B D) → Product.π₁ p₂ ∘ [ p₁ ⇒ p₂ ] f × g ≈ f ∘ Product.π₁ p₁ [_⇒_]π₁∘× _ p₂ = Product.project₁ p₂ [_⇒_]π₂∘× : ∀ (p₁ : Product A C) (p₂ : Product B D) → Product.π₂ p₂ ∘ [ p₁ ⇒ p₂ ] f × g ≈ g ∘ Product.π₂ p₁ [_⇒_]π₂∘× _ p₂ = Product.project₂ p₂ [_⇒_]×-cong₂ : ∀ (p₁ : Product A B) (p₂ : Product C D) → f ≈ g → h ≈ i → [ p₁ ⇒ p₂ ] f × h ≈ [ p₁ ⇒ p₂ ] g × i [_⇒_]×-cong₂ p₁ p₂ f≈g h≈i = Product.⟨⟩-cong₂ p₂ (∘-resp-≈ f≈g refl) (∘-resp-≈ h≈i refl) [_⇒_]×∘⟨⟩ : ∀ (p₁ : Product A B) (p₂ : Product C D) → ([ p₁ ⇒ p₂ ] f × g) ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈ [ p₂ ]⟨ f ∘ f′ , g ∘ g′ ⟩ [_⇒_]×∘⟨⟩ {f = f} {g = g} {f′ = f′} {g′ = g′} p₁ p₂ = begin [ p₂ ]⟨ f ∘ p₁.π₁ , g ∘ p₁.π₂ ⟩ ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈⟨ p₂.∘-distribʳ-⟨⟩ ⟩ [ p₂ ]⟨ (f ∘ p₁.π₁) ∘ p₁.⟨_,_⟩ f′ g′ , (g ∘ p₁.π₂) ∘ p₁.⟨_,_⟩ f′ g′ ⟩ ≈⟨ p₂.⟨⟩-cong₂ assoc assoc ⟩ [ p₂ ]⟨ f ∘ p₁.π₁ ∘ p₁.⟨_,_⟩ f′ g′ , g ∘ p₁.π₂ ∘ p₁.⟨_,_⟩ f′ g′ ⟩ ≈⟨ p₂.⟨⟩-cong₂ (∘-resp-≈ refl p₁.project₁) (∘-resp-≈ refl p₁.project₂) ⟩ [ p₂ ]⟨ f ∘ f′ , g ∘ g′ ⟩ ∎ where module p₁ = Product p₁ module p₂ = Product p₂ [_]⟨⟩∘ : ∀ (p : Product A B) → [ p ]⟨ f , g ⟩ ∘ h ≈ [ p ]⟨ f ∘ h , g ∘ h ⟩ [ p ]⟨⟩∘ = ⟺ (unique (⟺ assoc ○ ∘-resp-≈ˡ project₁) (⟺ assoc ○ ∘-resp-≈ˡ project₂)) where open Product p repack∘repack≈id : ∀ (p₁ p₂ : Product A B) → repack p₁ p₂ ∘ repack p₂ p₁ ≈ id repack∘repack≈id p₁ p₂ = [ p₂ ]⟨⟩∘ ○ p₂.⟨⟩-cong₂ p₁.project₁ p₁.project₂ ○ p₂.η where module p₁ = Product p₁ module p₂ = Product p₂ [_⇒_⇒_]×∘× : ∀ (p₁ : Product A B) (p₂ : Product C D) (p₃ : Product E F) → ([ p₂ ⇒ p₃ ] g × i) ∘ ([ p₁ ⇒ p₂ ] f × h) ≈ [ p₁ ⇒ p₃ ] (g ∘ f) × (i ∘ h) [_⇒_⇒_]×∘× {g = g} {i = i} {f = f} {h = h} p₁ p₂ p₃ = begin [ p₃ ]⟨ g ∘ p₂.π₁ , i ∘ p₂.π₂ ⟩ ∘ [ p₂ ]⟨ f ∘ p₁.π₁ , h ∘ p₁.π₂ ⟩ ≈⟨ [ p₂ ⇒ p₃ ]×∘⟨⟩ ⟩ [ p₃ ]⟨ g ∘ f ∘ p₁.π₁ , i ∘ h ∘ p₁.π₂ ⟩ ≈˘⟨ p₃.⟨⟩-cong₂ assoc assoc ⟩ [ p₃ ]⟨ (g ∘ f) ∘ p₁.π₁ , (i ∘ h) ∘ p₁.π₂ ⟩ ∎ where module p₁ = Product p₁ module p₂ = Product p₂ module p₃ = Product p₃ [_⇒_⇒_]repack∘× : ∀ (p₁ : Product A B) (p₂ : Product C D) (p₃ : Product C D) → repack p₂ p₃ ∘ [ p₁ ⇒ p₂ ] f × g ≈ [ p₁ ⇒ p₃ ] f × g [_⇒_⇒_]repack∘× {f = f} {g = g} p₁ p₂ p₃ = begin repack p₂ p₃ ∘ [ p₁ ⇒ p₂ ] f × g ≈⟨ repack≡id×id p₂ p₃ ⟩∘⟨ refl ⟩ ([ p₂ ⇒ p₃ ] id × id) ∘ ([ p₁ ⇒ p₂ ] f × g) ≈⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]×∘× ⟩ [ p₁ ⇒ p₃ ] (id ∘ f) × (id ∘ g) ≈⟨ [ p₁ ⇒ p₃ ]×-cong₂ identityˡ identityˡ ⟩ [ p₁ ⇒ p₃ ] f × g ∎ [_⇒_⇒_]repack∘repack : ∀ (p₁ p₂ p₃ : Product A B) → repack p₂ p₃ ∘ repack p₁ p₂ ≈ repack p₁ p₃ [_⇒_⇒_]repack∘repack = repack∘ [_⇒_]_×id : ∀ (p₁ : Product A C) (p₂ : Product B C) → A ⇒ B → [[ p₁ ]] ⇒ [[ p₂ ]] [ p₁ ⇒ p₂ ] f ×id = [ p₁ ⇒ p₂ ] f × id [_⇒_]id× : ∀ (p₁ : Product A B) (p₂ : Product A C) → B ⇒ C → [[ p₁ ]] ⇒ [[ p₂ ]] [ p₁ ⇒ p₂ ]id× g = [ p₁ ⇒ p₂ ] id × g first-id : ∀ (p : Product A B) → [ p ⇒ p ] id ×id ≈ id first-id = id×id second-id : ∀ (p : Product A B) → [ p ⇒ p ]id× id ≈ id second-id = id×id [_⇒_]×id∘⟨⟩ : ∀ (p₁ : Product B D) (p₂ : Product C D) → [ p₁ ⇒ p₂ ] f ×id ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈ [ p₂ ]⟨ f ∘ f′ , g′ ⟩ [_⇒_]×id∘⟨⟩ {f = f} {f′ = f′} {g′ = g′} p₁ p₂ = begin [ p₁ ⇒ p₂ ] f ×id ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈⟨ [ p₁ ⇒ p₂ ]×∘⟨⟩ ⟩ [ p₂ ]⟨ f ∘ f′ , id ∘ g′ ⟩ ≈⟨ p₂.⟨⟩-cong₂ refl identityˡ ⟩ [ p₂ ]⟨ f ∘ f′ , g′ ⟩ ∎ where module p₂ = Product p₂ [_⇒_]id×∘⟨⟩ : ∀ (p₁ : Product B D) (p₂ : Product B E) → [ p₁ ⇒ p₂ ]id× g ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈ [ p₂ ]⟨ f′ , g ∘ g′ ⟩ [_⇒_]id×∘⟨⟩ {g = g} {f′ = f′} {g′ = g′} p₁ p₂ = begin [ p₁ ⇒ p₂ ]id× g ∘ [ p₁ ]⟨ f′ , g′ ⟩ ≈⟨ [ p₁ ⇒ p₂ ]×∘⟨⟩ ⟩ [ p₂ ]⟨ id ∘ f′ , g ∘ g′ ⟩ ≈⟨ p₂.⟨⟩-cong₂ identityˡ refl ⟩ [ p₂ ]⟨ f′ , g ∘ g′ ⟩ ∎ where module p₂ = Product p₂ [_⇒_⇒_]×id∘×id : ∀ (p₁ : Product A D) (p₂ : Product B D) (p₃ : Product C D) → [ p₂ ⇒ p₃ ] f ×id ∘ [ p₁ ⇒ p₂ ] g ×id ≈ [ p₁ ⇒ p₃ ] f ∘ g ×id [_⇒_⇒_]×id∘×id {f = f} {g = g} p₁ p₂ p₃ = begin [ p₂ ⇒ p₃ ] f ×id ∘ [ p₁ ⇒ p₂ ] g ×id ≈⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]×∘× ⟩ [ p₁ ⇒ p₃ ] (f ∘ g) × (id ∘ id) ≈⟨ [ p₁ ⇒ p₃ ]×-cong₂ refl identityˡ ⟩ [ p₁ ⇒ p₃ ] f ∘ g ×id ∎ [_⇒_⇒_]id×∘id× : ∀ (p₁ : Product A B) (p₂ : Product A C) (p₃ : Product A D) → [ p₂ ⇒ p₃ ]id× f ∘ [ p₁ ⇒ p₂ ]id× g ≈ [ p₁ ⇒ p₃ ]id×(f ∘ g) [_⇒_⇒_]id×∘id× {f = f} {g = g} p₁ p₂ p₃ = begin [ p₂ ⇒ p₃ ]id× f ∘ [ p₁ ⇒ p₂ ]id× g ≈⟨ [ p₁ ⇒ p₂ ⇒ p₃ ]×∘× ⟩ [ p₁ ⇒ p₃ ] (id ∘ id) × (f ∘ g) ≈⟨ [ p₁ ⇒ p₃ ]×-cong₂ identityˡ refl ⟩ [ p₁ ⇒ p₃ ]id× (f ∘ g) ∎ [_⇒_,_⇒_]first↔second : ∀ (p₁ : Product A D) (p₂ : Product B D) (p₃ : Product A C) (p₄ : Product B C) → [ p₁ ⇒ p₂ ] f ×id ∘ [ p₃ ⇒ p₁ ]id× g ≈ [ p₄ ⇒ p₂ ]id× g ∘ [ p₃ ⇒ p₄ ] f ×id [_⇒_,_⇒_]first↔second {f = f} {g = g} p₁ p₂ p₃ p₄ = begin [ p₁ ⇒ p₂ ] f ×id ∘ [ p₃ ⇒ p₁ ]id× g ≈⟨ [ p₃ ⇒ p₁ ⇒ p₂ ]×∘× ⟩ [ p₃ ⇒ p₂ ] (f ∘ id) × (id ∘ g) ≈⟨ [ p₃ ⇒ p₂ ]×-cong₂ identityʳ identityˡ ⟩ [ p₃ ⇒ p₂ ] f × g ≈⟨ sym ([ p₃ ⇒ p₂ ]×-cong₂ identityˡ identityʳ) ⟩ [ p₃ ⇒ p₂ ] (id ∘ f) × (g ∘ id) ≈⟨ sym ([ p₃ ⇒ p₄ ⇒ p₂ ]×∘×) ⟩ [ p₄ ⇒ p₂ ]id× g ∘ [ p₃ ⇒ p₄ ] f ×id ∎
{ "alphanum_fraction": 0.4255288111, "avg_line_length": 42.5776397516, "ext": "agda", "hexsha": "d893e2ea0ec4cd42d60d9aadcf76a49ac4131eef", "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": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "Taneb/agda-categories", "max_forks_repo_path": "Categories/Object/Product/Morphisms.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "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": "Taneb/agda-categories", "max_issues_repo_path": "Categories/Object/Product/Morphisms.agda", "max_line_length": 126, "max_stars_count": null, "max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "Taneb/agda-categories", "max_stars_repo_path": "Categories/Object/Product/Morphisms.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 3649, "size": 6855 }
module LineEndings.Mac where postulate ThisWorks : Set
{ "alphanum_fraction": 0.8214285714, "avg_line_length": 56, "ext": "agda", "hexsha": "1507f60534091f003ca0a155369949b61489a63e", "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/LineEndings/Mac.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/LineEndings/Mac.agda", "max_line_length": 56, "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/LineEndings/Mac.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": 16, "size": 56 }
{-# OPTIONS --type-in-type #-} module TypeInTypeAndUnivPoly where open import UniversePolymorphism -- The level metas should be solved with 0 when we have --type-in-type fst′ : ∀ {A B} → Σ A B → A fst′ x = fst x
{ "alphanum_fraction": 0.688372093, "avg_line_length": 21.5, "ext": "agda", "hexsha": "6580093639975af1a3f57ccd3181b6559d23893d", "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/TypeInTypeAndUnivPoly.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/TypeInTypeAndUnivPoly.agda", "max_line_length": 70, "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/TypeInTypeAndUnivPoly.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": 66, "size": 215 }
module Structure.Relator.Proofs where import Data.Either as Either import Data.Tuple as Tuple open import Functional open import Function.Proofs open import Logic open import Logic.Propositional.Proofs.Structures open import Logic.Propositional open import Logic.Predicate import Lvl open import Structure.Function open import Structure.Operator open import Structure.Setoid open import Structure.Relator.Properties open import Structure.Relator open import Syntax.Transitivity open import Type private variable ℓ ℓ₁ ℓ₂ ℓ₃ ℓₗ ℓₗ₁ ℓₗ₂ ℓₗ₃ ℓₗ₄ ℓₑ ℓₑ₁ ℓₑ₂ ℓₑ₃ ℓₑ₄ : Lvl.Level private variable A B A₁ A₂ B₁ B₂ : Type{ℓ} [≡]-binaryRelator : ∀ ⦃ equiv : Equiv{ℓₗ}(A) ⦄ → BinaryRelator ⦃ equiv ⦄ (_≡_) BinaryRelator.substitution [≡]-binaryRelator {x₁} {y₁} {x₂} {y₂} xy1 xy2 x1x2 = y₁ 🝖-[ xy1 ]-sym x₁ 🝖-[ x1x2 ] x₂ 🝖-[ xy2 ] y₂ 🝖-end reflexive-binaryRelator-sub : ∀ ⦃ equiv : Equiv{ℓₗ}(A) ⦄ {_▫_ : A → A → Type{ℓ}} ⦃ refl : Reflexivity(_▫_) ⦄ ⦃ rel : BinaryRelator ⦃ equiv ⦄ (_▫_) ⦄ → ((_≡_) ⊆₂ (_▫_)) _⊆₂_.proof (reflexive-binaryRelator-sub {_▫_ = _▫_}) xy = substitute₂ᵣ(_▫_) xy (reflexivity(_▫_)) module _ ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ {f : A → B} ⦃ func : Function(f) ⦄ {P : B → Stmt{ℓₗ₃}} ⦃ rel : UnaryRelator(P) ⦄ where [∘]-unaryRelator : UnaryRelator(P ∘ f) [∘]-unaryRelator = [↔]-to-[←] relator-function₁ ([∘]-function ⦃ equiv-c = [↔]-equiv ⦄ ⦃ func-f = [↔]-to-[→] relator-function₁ rel ⦄) module _ ⦃ equiv-A₁ : Equiv{ℓₑ₁}(A₁) ⦄ ⦃ equiv-B₁ : Equiv{ℓₑ₂}(B₁) ⦄ ⦃ equiv-A₂ : Equiv{ℓₑ₃}(A₂) ⦄ ⦃ equiv-B₂ : Equiv{ℓₑ₄}(B₂) ⦄ {f : A₁ → A₂} ⦃ func-f : Function(f) ⦄ {g : B₁ → B₂} ⦃ func-g : Function(g) ⦄ {_▫_ : A₂ → B₂ → Stmt{ℓₗ}} ⦃ rel : BinaryRelator(_▫_) ⦄ where [∘]-binaryRelator : BinaryRelator(x ↦ y ↦ f(x) ▫ g(y)) BinaryRelator.substitution [∘]-binaryRelator xy1 xy2 = substitute₂(_▫_) (congruence₁(f) xy1) (congruence₁(g) xy2) module _ ⦃ equiv-A : Equiv{ℓₑ}(A) ⦄ {P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄ {▫ : Stmt{ℓₗ₁} → Stmt{ℓₗ₂}} ⦃ rel : Function ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ ▫ ⦄ where unaryRelator-sub : UnaryRelator(▫ ∘ P) unaryRelator-sub = [∘]-unaryRelator ⦃ equiv-B = [↔]-equiv ⦄ ⦃ func = [↔]-to-[→] relator-function₁ rel-P ⦄ ⦃ rel = [↔]-to-[←] (relator-function₁ ⦃ [↔]-equiv ⦄) rel ⦄ module _ ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ {P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄ {Q : B → Stmt{ℓₗ₂}} ⦃ rel-Q : UnaryRelator(Q) ⦄ {_▫_ : Stmt{ℓₗ₁} → Stmt{ℓₗ₂} → Stmt{ℓₗ₃}} ⦃ rel : BinaryOperator ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄ (_▫_) ⦄ where binaryRelator-sub : BinaryRelator(x ↦ y ↦ P(x) ▫ Q(y)) binaryRelator-sub = [∘]-binaryRelator ⦃ equiv-A₂ = [↔]-equiv ⦄ ⦃ equiv-B₂ = [↔]-equiv ⦄ ⦃ func-f = [↔]-to-[→] relator-function₁ rel-P ⦄ ⦃ func-g = [↔]-to-[→] relator-function₁ rel-Q ⦄ ⦃ rel = [↔]-to-[←] (relator-function₂ ⦃ [↔]-equiv ⦄ ⦃ [↔]-equiv ⦄) rel ⦄ module _ ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ {P : A → Stmt{ℓₗ₁}} ⦃ rel-P : UnaryRelator(P) ⦄ {Q : B → Stmt{ℓₗ₂}} ⦃ rel-Q : UnaryRelator(Q) ⦄ where [→]-binaryRelator : BinaryRelator(x ↦ y ↦ (P(x) → Q(y))) [→]-binaryRelator = binaryRelator-sub{_▫_ = _→ᶠ_} [↔]-binaryRelator : BinaryRelator(x ↦ y ↦ (P(x) ↔ Q(y))) [↔]-binaryRelator = binaryRelator-sub{_▫_ = _↔_} [→]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(\x → P(x) → Q(x)) UnaryRelator.substitution ([→]-unaryRelator {P = P}{Q = Q}) xy pxqx py = substitute₁(Q) xy (pxqx(substitute₁(P) (symmetry(_≡_) xy) py)) [∀]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : B → A → Stmt{ℓₗ₁}} → ⦃ rel-P : ∀{x} → UnaryRelator(P(x)) ⦄ → UnaryRelator(\y → ∀{x} → P(x)(y)) UnaryRelator.substitution ([∀]-unaryRelator {P = P}) {x} {a} xy px {b} = substitute₁ (P b) xy px [∃]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : B → A → Stmt{ℓₗ₁}} → ⦃ rel-P : ∀{x} → UnaryRelator(P(x)) ⦄ → UnaryRelator(\y → ∃(x ↦ P(x)(y))) UnaryRelator.substitution ([∃]-unaryRelator {P = P}) xy = [∃]-map-proof (substitute₁(P _) xy) instance const-unaryRelator : ∀{P : Stmt{ℓₗ₁}} → ⦃ _ : Equiv{ℓₗ}(A) ⦄ → UnaryRelator{A = A}(const P) UnaryRelator.substitution const-unaryRelator = const id [¬]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {P : A → Stmt{ℓₗ₁}} → ⦃ rel-P : UnaryRelator(P) ⦄ → UnaryRelator(\x → ¬ P(x)) [¬]-unaryRelator {P = P} = [→]-unaryRelator [∧]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(x ↦ P(x) ∧ Q(x)) UnaryRelator.substitution [∧]-unaryRelator xy = Tuple.map (substitute₁(_) xy) (substitute₁(_) xy) [∨]-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₃}(A) ⦄ {P : A → Stmt{ℓₗ₁}}{Q : A → Stmt{ℓₗ₂}} → ⦃ rel-P : UnaryRelator(P) ⦄ → ⦃ rel-Q : UnaryRelator(Q) ⦄ → UnaryRelator(x ↦ P(x) ∨ Q(x)) UnaryRelator.substitution [∨]-unaryRelator xy = Either.map (substitute₁(_) xy) (substitute₁(_) xy) binary-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {P : A → A → Stmt{ℓₗ₁}} → ⦃ rel-P : BinaryRelator(P) ⦄ → UnaryRelator(P $₂_) UnaryRelator.substitution (binary-unaryRelator {P = P}) xy pxx = substitute₂(P) xy xy pxx binary-unaryRelatorₗ : ∀ ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {_▫_ : A → B → Stmt{ℓₗ₃}} → ⦃ rel-P : BinaryRelator(_▫_) ⦄ → ∀{x} → UnaryRelator(x ▫_) UnaryRelator.substitution binary-unaryRelatorₗ xy x1x2 = substitute₂ _ (reflexivity(_≡_)) xy x1x2 binary-unaryRelatorᵣ : ∀ ⦃ _ : Equiv{ℓₗ₁}(A) ⦄ ⦃ _ : Equiv{ℓₗ₂}(B) ⦄ {_▫_ : A → B → Stmt{ℓₗ₃}} → ⦃ rel-P : BinaryRelator(_▫_) ⦄ → ∀{x} → UnaryRelator(_▫ x) UnaryRelator.substitution binary-unaryRelatorᵣ xy x1x2 = substitute₂ _ xy (reflexivity(_≡_)) x1x2 binaryRelator-from-unaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ {_▫_ : A → A → Stmt{ℓₗ₁}} → ⦃ relₗ : ∀{x} → UnaryRelator(_▫ x) ⦄ → ⦃ relᵣ : ∀{x} → UnaryRelator(x ▫_) ⦄ → BinaryRelator(_▫_) BinaryRelator.substitution binaryRelator-from-unaryRelator xy1 xy2 = substitute₁ _ xy1 ∘ substitute₁ _ xy2 instance const-binaryRelator : ∀{P : Stmt{ℓₗ}} → ⦃ equiv-A : Equiv{ℓₗ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₗ₂}(B) ⦄ → BinaryRelator{A = A}{B = B}((const ∘ const) P) BinaryRelator.substitution const-binaryRelator = (const ∘ const) id -- TODO: Temporary until substitution is a specialization of congruence [¬]-binaryRelator : ∀ ⦃ _ : Equiv{ℓₗ₂}(A) ⦄ ⦃ _ : Equiv{ℓₗ₃}(B) ⦄ {P : A → B → Stmt{ℓₗ₁}} → ⦃ rel-P : BinaryRelator(P) ⦄ → BinaryRelator(\x y → ¬ P(x)(y)) BinaryRelator.substitution ([¬]-binaryRelator {P = P}) xy₁ xy₂ npx py = npx(substitute₂(P) (symmetry(_≡_) xy₁) (symmetry(_≡_) xy₂) py)
{ "alphanum_fraction": 0.6075203866, "avg_line_length": 47.9855072464, "ext": "agda", "hexsha": "a0a77a822f43c297c91b6a5aa411f14a0ea49922", "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/Relator/Proofs.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/Relator/Proofs.agda", "max_line_length": 182, "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/Relator/Proofs.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": 3224, "size": 6622 }
module SecondOrder.VContext {ℓ} (sort : Set ℓ) where -- a context is a binary tree whose leaves are labeled with sorts data VContext : Set ℓ where ctx-empty : VContext ctx-slot : sort → VContext _,,_ : VContext → VContext → VContext infixl 5 _,,_ infix 4 _∈_ -- the variables of a given type in a context data _∈_ (A : sort) : VContext → Set ℓ where var-slot : A ∈ ctx-slot A var-inl : ∀ {Γ Δ} (x : A ∈ Γ) → A ∈ Γ ,, Δ var-inr : ∀ {Γ Δ} (y : A ∈ Δ) → A ∈ Γ ,, Δ
{ "alphanum_fraction": 0.5864811133, "avg_line_length": 27.9444444444, "ext": "agda", "hexsha": "0c2803940337bd6f735d6b447d788d869644476c", "lang": "Agda", "max_forks_count": 6, "max_forks_repo_forks_event_max_datetime": "2021-05-24T02:51:43.000Z", "max_forks_repo_forks_event_min_datetime": "2021-02-16T13:43:07.000Z", "max_forks_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "andrejbauer/formaltt", "max_forks_repo_path": "src/SecondOrder/VContext.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "2aaf850bb1a262681c5a232cdefae312f921b9d4", "max_issues_repo_issues_event_max_datetime": "2021-05-14T16:15:17.000Z", "max_issues_repo_issues_event_min_datetime": "2021-04-30T14:18:25.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "andrejbauer/formaltt", "max_issues_repo_path": "src/SecondOrder/VContext.agda", "max_line_length": 67, "max_stars_count": 21, "max_stars_repo_head_hexsha": "0a9d25e6e3965913d9b49a47c88cdfb94b55ffeb", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cilinder/formaltt", "max_stars_repo_path": "src/SecondOrder/VContext.agda", "max_stars_repo_stars_event_max_datetime": "2021-11-19T15:50:08.000Z", "max_stars_repo_stars_event_min_datetime": "2021-02-16T14:07:06.000Z", "num_tokens": 181, "size": 503 }
{-# OPTIONS --without-K #-} open import lib.Basics open import lib.NType2 open import lib.types.Sigma open import lib.types.Pi open import lib.types.Group open import lib.types.Int open import lib.types.List open import lib.types.SetQuotient module lib.groups.FormalSum {i} where PreFormalSum : Type i → Type i PreFormalSum A = List (ℤ × A) module _ {A : Type i} (dec : has-dec-eq A) where coef-pre : PreFormalSum A → (A → ℤ) coef-pre l a = ℤsum $ map fst $ filter (λ{(_ , a') → dec a' a}) l -- Extensional equality FormalSum-rel : Rel (PreFormalSum A) i FormalSum-rel l₁ l₂ = ∀ a → coef-pre l₁ a == coef-pre l₂ a -- The quotient FormalSum : Type i FormalSum = SetQuotient FormalSum-rel -- Properties of [coef-pre] coef-pre-++ : ∀ l₁ l₂ a → coef-pre (l₁ ++ l₂) a == coef-pre l₁ a ℤ+ coef-pre l₂ a coef-pre-++ nil l₂ a = idp coef-pre-++ ((z , a') :: l₁) l₂ a with dec a' a ... | inl _ = ap (z ℤ+_) (coef-pre-++ l₁ l₂ a) ∙ ! (ℤ+-assoc z (coef-pre l₁ a) (coef-pre l₂ a)) ... | inr _ = coef-pre-++ l₁ l₂ a flip-pre : PreFormalSum A → PreFormalSum A flip-pre = map λ{(z , a) → (ℤ~ z , a)} coef-pre-flip-pre : ∀ l a → coef-pre (flip-pre l) a == ℤ~ (coef-pre l a) coef-pre-flip-pre nil a = idp coef-pre-flip-pre ((z , a') :: l) a with dec a' a ... | inl _ = ap (ℤ~ z ℤ+_) (coef-pre-flip-pre l a) ∙ ! (ℤ~-ℤ+ z (coef-pre l a)) ... | inr _ = coef-pre-flip-pre l a module _ {A : Type i} {dec : has-dec-eq A} where coef : FormalSum dec → (A → ℤ) coef = SetQuot-rec (→-is-set ℤ-is-set) (coef-pre dec) λ= -- extensionality of formal sums. coef-ext : ∀ {fs₁ fs₂} → (∀ a → coef fs₁ a == coef fs₂ a) → fs₁ == fs₂ coef-ext {fs₁} {fs₂} = ext' fs₁ fs₂ where ext' : ∀ fs₁ fs₂ → (∀ a → coef fs₁ a == coef fs₂ a) → fs₁ == fs₂ ext' = SetQuot-elim (λ _ → Π-is-set λ _ → →-is-set $ =-preserves-set SetQuotient-is-set) (λ l₁ → SetQuot-elim (λ _ → →-is-set $ =-preserves-set SetQuotient-is-set) (λ l₂ r → quot-rel r) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → SetQuotient-is-set _ _))) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → Π-is-prop λ _ → SetQuotient-is-set _ _)) -- TODO Use abstract [FormalSum]. infixl 80 _⊞_ _⊞_ : FormalSum dec → FormalSum dec → FormalSum dec _⊞_ = SetQuot-rec (→-is-set SetQuotient-is-set) (λ l₁ → SetQuot-rec SetQuotient-is-set (q[_] ∘ (l₁ ++_)) (λ {l₂} {l₂'} r → quot-rel λ a → coef-pre-++ dec l₁ l₂ a ∙ ap (coef-pre dec l₁ a ℤ+_) (r a) ∙ ! (coef-pre-++ dec l₁ l₂' a))) (λ {l₁} {l₁'} r → λ= $ SetQuot-elim (λ _ → =-preserves-set SetQuotient-is-set) (λ l₂ → quot-rel λ a → coef-pre-++ dec l₁ l₂ a ∙ ap (_ℤ+ coef-pre dec l₂ a) (r a) ∙ ! (coef-pre-++ dec l₁' l₂ a)) (λ _ → prop-has-all-paths-↓ (SetQuotient-is-set _ _))) coef-⊞ : ∀ fs₁ fs₂ a → coef (fs₁ ⊞ fs₂) a == coef fs₁ a ℤ+ coef fs₂ a coef-⊞ = SetQuot-elim (λ _ → Π-is-set λ _ → Π-is-set λ _ → =-preserves-set ℤ-is-set) (λ l₁ → SetQuot-elim (λ _ → Π-is-set λ _ → =-preserves-set ℤ-is-set) (λ l₂ → coef-pre-++ dec l₁ l₂) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → ℤ-is-set _ _))) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → Π-is-prop λ _ → ℤ-is-set _ _)) ⊟ : FormalSum dec → FormalSum dec ⊟ = SetQuot-rec SetQuotient-is-set (q[_] ∘ flip-pre dec) λ {l₁} {l₂} r → quot-rel λ a → coef-pre-flip-pre dec l₁ a ∙ ap ℤ~ (r a) ∙ ! (coef-pre-flip-pre dec l₂ a) coef-⊟ : ∀ fs a → coef (⊟ fs) a == ℤ~ (coef fs a) coef-⊟ = SetQuot-elim (λ _ → Π-is-set λ _ → =-preserves-set ℤ-is-set) (λ l a → coef-pre-flip-pre dec l a) (λ _ → prop-has-all-paths-↓ (Π-is-prop λ _ → ℤ-is-set _ _)) ⊞-unit : FormalSum dec ⊞-unit = q[ nil ] coef-⊞-unit : ∀ a → coef ⊞-unit a == 0 coef-⊞-unit a = idp {- -- Favonia: These commented-out proofs are valid, but I want to promote -- the usage of [coef-ext]. ⊞-unit-l : ∀ fs → ⊞-unit ⊞ fs == fs ⊞-unit-l = SetQuot-elim (λ _ → =-preserves-set SetQuotient-is-set) (λ l → idp) (λ _ → prop-has-all-paths-↓ (SetQuotient-is-set _ _)) ⊞-unit-r : ∀ fs → fs ⊞ ⊞-unit == fs ⊞-unit-r = SetQuot-elim (λ _ → =-preserves-set SetQuotient-is-set) (λ l → ap q[_] $ ++-nil-r l) (λ _ → prop-has-all-paths-↓ (SetQuotient-is-set _ _)) -} ⊞-unit-l : ∀ fs → ⊞-unit ⊞ fs == fs ⊞-unit-l fs = coef-ext λ a → coef-⊞ ⊞-unit fs a ⊞-unit-r : ∀ fs → fs ⊞ ⊞-unit == fs ⊞-unit-r fs = coef-ext λ a → coef-⊞ fs ⊞-unit a ∙ ℤ+-unit-r _ ⊞-assoc : ∀ fs₁ fs₂ fs₃ → (fs₁ ⊞ fs₂) ⊞ fs₃ == fs₁ ⊞ (fs₂ ⊞ fs₃) ⊞-assoc fs₁ fs₂ fs₃ = coef-ext λ a → coef ((fs₁ ⊞ fs₂) ⊞ fs₃) a =⟨ coef-⊞ (fs₁ ⊞ fs₂) fs₃ a ⟩ coef (fs₁ ⊞ fs₂) a ℤ+ coef fs₃ a =⟨ coef-⊞ fs₁ fs₂ a |in-ctx _ℤ+ coef fs₃ a ⟩ (coef fs₁ a ℤ+ coef fs₂ a) ℤ+ coef fs₃ a =⟨ ℤ+-assoc (coef fs₁ a) (coef fs₂ a) (coef fs₃ a) ⟩ coef fs₁ a ℤ+ (coef fs₂ a ℤ+ coef fs₃ a) =⟨ ! $ coef-⊞ fs₂ fs₃ a |in-ctx coef fs₁ a ℤ+_ ⟩ coef fs₁ a ℤ+ coef (fs₂ ⊞ fs₃) a =⟨ ! $ coef-⊞ fs₁ (fs₂ ⊞ fs₃) a ⟩ coef (fs₁ ⊞ (fs₂ ⊞ fs₃)) a ∎ ⊟-inv-r : ∀ fs → fs ⊞ (⊟ fs) == ⊞-unit ⊟-inv-r fs = coef-ext λ a → coef-⊞ fs (⊟ fs) a ∙ ap (coef fs a ℤ+_) (coef-⊟ fs a) ∙ ℤ~-inv-r (coef fs a) ⊟-inv-l : ∀ fs → (⊟ fs) ⊞ fs == ⊞-unit ⊟-inv-l fs = coef-ext λ a → coef-⊞ (⊟ fs) fs a ∙ ap (_ℤ+ coef fs a) (coef-⊟ fs a) ∙ ℤ~-inv-l (coef fs a) FormalSum-group-structure : GroupStructure (FormalSum dec) FormalSum-group-structure = record { ident = ⊞-unit ; inv = ⊟ ; comp = _⊞_ ; unitl = ⊞-unit-l ; unitr = ⊞-unit-r ; assoc = ⊞-assoc ; invr = ⊟-inv-r ; invl = ⊟-inv-l } FormalSum-group : Group i FormalSum-group = group _ SetQuotient-is-set FormalSum-group-structure has-finite-supports : (A → ℤ) → Type i has-finite-supports f = Σ (FormalSum dec) λ fs → ∀ a → f a == coef fs a has-finite-supports-is-prop : ∀ f → is-prop (has-finite-supports f) has-finite-supports-is-prop f = all-paths-is-prop λ{(fs₁ , match₁) (fs₂ , match₂) → pair= (coef-ext λ a → ! (match₁ a) ∙ match₂ a) (prop-has-all-paths-↓ $ Π-is-prop λ _ → ℤ-is-set _ _)}
{ "alphanum_fraction": 0.5373276272, "avg_line_length": 34.4754098361, "ext": "agda", "hexsha": "f6dc19a210964f79fd300f11e5167eae407a48d9", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "core/lib/groups/FormalSum.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_path": "core/lib/groups/FormalSum.agda", "max_line_length": 91, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "core/lib/groups/FormalSum.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2627, "size": 6309 }
-- Andreas, 2013-10-20 'with' only abstracts at base type module WithOfFunctionType where postulate A B : Set P : B → Set mkP : (x : B) → P x f : A → B a : A test : P (f a) test with f ... | g = mkP (g a)
{ "alphanum_fraction": 0.5688073394, "avg_line_length": 14.5333333333, "ext": "agda", "hexsha": "5e18c95deca5430452347d8324b160a0d818b2f1", "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/WithOfFunctionType.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/WithOfFunctionType.agda", "max_line_length": 57, "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/WithOfFunctionType.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": 89, "size": 218 }
module _ where open import Agda.Builtin.Nat open import Agda.Builtin.Bool open import Agda.Builtin.Equality open import Agda.Builtin.TrustMe record _×_ (A B : Set) : Set where constructor _,_ field fst : A snd : B open _×_ -- Nested pattern prevents record pattern translation. f : Nat × Nat → Nat f (zero , b) = b f (suc a , b) = a + b -- With catch-all case g : Nat × Nat → Nat g (zero , b) = b g p = fst p + snd p -- Definition by copatterns. p : Nat × Nat p .fst = 2 p .snd = 2 test-f : f p ≡ 3 test-f = refl test-g : g p ≡ 4 test-g = refl -- Slow reduce. primTrustMe doesn't use fast-reduce is-refl : ∀ {A : Set} (x y : A) → x ≡ y → Bool is-refl x y refl = true test-slow-f : is-refl (f p) 3 primTrustMe ≡ true test-slow-f = refl test-slow-g : is-refl (g p) 4 primTrustMe ≡ true test-slow-g = refl
{ "alphanum_fraction": 0.6252983294, "avg_line_length": 17.4583333333, "ext": "agda", "hexsha": "6a53ad4c213703687d9d4a866054cb2169c4f3c9", "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/Issue2974.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/Issue2974.agda", "max_line_length": 54, "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/Issue2974.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": 308, "size": 838 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.CofiberSequence open import cohomology.Exactness open import cohomology.FunctionOver open import cohomology.SplitExactRight open import cohomology.Theory module cohomology.Sigma {i} (CT : CohomologyTheory i) where open CohomologyTheory CT open import cohomology.Functor CT open import cohomology.BaseIndependence CT {- Cⁿ(Σx:X.Y) = Cⁿ(⋁x:X.Y) × Cⁿ(X). The proof is by constructing a - splitting exact sequence 0 → Cⁿ(⋁x:X.Y) → Cⁿ(Σx:X.Y) → Cⁿ(X) - by observing that the map [select : x ↦ (x, snd Yₓ)] has a left inverse - and satisfies [Cofiber select == ⋁x:X.Y. -} module CofSelect (X : Ptd i) (Y : fst X → Ptd i) where select : fst X → fst (⊙Σ X Y) select x = (x , snd (Y x)) ⊙select : fst (X ⊙→ ⊙Σ X Y) ⊙select = (select , idp) ⊙Σbwin : fst (⊙Σ X Y ⊙→ ⊙BigWedge Y) ⊙Σbwin = (uncurry bwin , ! (bwglue (snd X))) eq : Cofiber select ≃ BigWedge Y eq = equiv Into.f Out.f into-out out-into where module Into = CofiberRec select {C = BigWedge Y} bwbase (uncurry bwin) bwglue module Out = BigWedgeRec {X = Y} {C = Cofiber select} (cfbase _) (curry (cfcod _)) (cfglue _) into-out : ∀ w → Into.f (Out.f w) == w into-out = BigWedge-elim idp (λ _ _ → idp) (↓-∘=idf-in Into.f Out.f ∘ λ x → ap (ap Into.f) (Out.glue-β x) ∙ Into.glue-β x) out-into : ∀ c → Out.f (Into.f c) == c out-into = Cofiber-elim select idp (λ _ → idp) (↓-∘=idf-in Out.f Into.f ∘ λ x → ap (ap Out.f) (Into.glue-β x) ∙ Out.glue-β x) ⊙path : ⊙Cof ⊙select == ⊙BigWedge Y ⊙path = ⊙ua eq idp cfcod-over : cfcod _ == uncurry bwin [ (λ U → fst (⊙Σ X Y) → fst U) ↓ ⊙path ] cfcod-over = ↓-cst2-in _ _ $ codomain-over-equiv _ _ ext-glue-cst : ext-glue {s = cofiber-span select} == cst (north _) ext-glue-cst = λ= $ Cofiber-elim _ idp (λ {(x , y) → ! (merid _ x)}) (↓-='-from-square ∘ λ x → ExtGlue.glue-β x ∙v⊡ tr-square (merid _ x) ⊡v∙ ! (ap-cst (north _) (cfglue _ x))) ext-over : ext-glue == cst (north _) [ (λ U → fst U → fst (⊙Susp X)) ↓ ⊙path ] ext-over = ↓-cst2-in _ _ $ ext-glue-cst ◃ domain-over-equiv _ _ module CΣ (n : ℤ) (X : Ptd i) (Y : fst X → Ptd i) where open CofSelect X Y private seq : HomSequence _ _ seq = C n (⊙Susp X) ⟨ cst-hom ⟩→ C n (⊙BigWedge Y) ⟨ CF-hom n ⊙Σbwin ⟩→ C n (⊙Σ X Y) ⟨ CF-hom n ⊙select ⟩→ C n X ⊣| eseq : is-exact-seq seq eseq = exact-build seq (transport (λ {(φ , ψ) → is-exact ψ φ}) (pair×= (CF-base-indep n _ _ _) (CF-base-indep n _ _ _ ∙ CF-cst n)) (transport {A = Σ _ (λ {(U , g , h) → (g (snd (⊙Σ X Y)) == snd U) × (h (snd U) == north _)})} (λ {((_ , g , h) , (p , q)) → is-exact (CF-hom n (h , q)) (CF-hom n (g , p))}) (pair= (pair= ⊙path (↓-×-in cfcod-over ext-over)) (↓-×-in (from-transp _ _ idp) (from-transp _ _ idp))) (transport {A = Σ _ (λ {(U , g) → g (cfbase _) == snd U})} (λ {((_ , g) , p) → is-exact (CF-hom n (g , p)) (CF-hom n (⊙cfcod ⊙select))}) (pair= (pair= (Cof².space-path ⊙select) (Cof².cfcod²-over ⊙select)) (from-transp _ _ idp)) (C-exact n (⊙cfcod ⊙select))))) (transport (λ φ → is-exact φ (CF-hom n ⊙select)) (CF-base-indep n _ _ _) (transport {A = Σ _ (λ {(U , g) → g (snd (⊙Σ X Y)) == snd U})} (λ {((_ , g) , p) → is-exact (CF-hom n (g , p)) (CF-hom n ⊙select)}) (pair= (pair= ⊙path cfcod-over) (from-transp _ _ idp)) (C-exact n ⊙select))) module SER = SplitExactRight (C-abelian n _) (CF-hom n ⊙Σbwin) (CF-hom n ⊙select) eseq (CF-hom n (⊙dfst Y)) (app= $ ap GroupHom.f $ CF-inverse n ⊙select (⊙dfst Y) (λ _ → idp)) path : C n (⊙Σ X Y) == C n (⊙BigWedge Y) ×ᴳ C n X path = SER.iso ⊙Σbwin-over : CF-hom n ⊙Σbwin == ×ᴳ-inl [ (λ G → GroupHom (C n (⊙BigWedge Y)) G) ↓ path ] ⊙Σbwin-over = SER.φ-over-iso ⊙select-over : CF-hom n ⊙select == ×ᴳ-snd {G = C n (⊙BigWedge Y)} [ (λ G → GroupHom G (C n X)) ↓ path ] ⊙select-over = SER.ψ-over-iso open CofSelect public using (select; ⊙select; ⊙Σbwin) module C⊔ (n : ℤ) (X Y : Ptd i) where private T : Sphere {i} 0 → Ptd i T (lift true) = X T (lift false) = Y path : C n (X ⊙⊔ Y) == C n (X ⊙∨ Y) ×ᴳ C n (⊙Sphere 0) path = ap (C n) (! (⊙ua (ΣBool-equiv-⊔ (fst ∘ T)) idp)) ∙ CΣ.path n (⊙Sphere 0) T ∙ ap (λ Z → C n Z ×ᴳ C n (⊙Sphere 0)) (BigWedge-Bool-⊙path T)
{ "alphanum_fraction": 0.5200850159, "avg_line_length": 33.1338028169, "ext": "agda", "hexsha": "7cbc08283d4584e3c25a7b17e604da55b091fdfd", "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": "cohomology/Sigma.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": "cohomology/Sigma.agda", "max_line_length": 79, "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": "cohomology/Sigma.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": 1945, "size": 4705 }
open import Data.Bool using (Bool; true; false; _∧_) import Relation.Binary.PropositionalEquality as Eq open Eq using (_≡_; refl; sym; subst) open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎) open import Data.Unit using (⊤; tt) open import Data.Nat using (ℕ; zero; suc; _≤_; _≥_; _>_) open import Data.Product using (_×_; _,_; proj₁; proj₂; Σ-syntax; ∃; ∃-syntax) open import Data.Sum using (_⊎_; inj₁; inj₂) open import Data.List using (List; []; [_]; _∷_; _∷ʳ_; _++_) open import Data.List.Reverse using (Reverse; reverseView) open import Function using (_$_) module SnapshotConsistency (Addr : Set) (_≟_ : Addr → Addr → Bool) (_≤?MAXADDR : Addr → Bool) (_≤?MAXWCNT : ℕ → Bool) (Data : Set) (defaultData : Data) where infixl 20 _•_ infixl 20 _⊙_ infixl 20 _++RTC_ infixl 20 _<≐>_ variable addr : Addr dat : Data _≐_ : {A B : Set} → (A → B) → (A → B) → Set s ≐ t = ∀ a → s a ≡ t a sym-≐ : {A B : Set} {s t : A → B} → s ≐ t → t ≐ s sym-≐ eq = λ{x → sym (eq x)} _<≐>_ : {A B : Set} {s t u : A → B} → s ≐ t → t ≐ u → s ≐ u _<≐>_ {A} {B} {s} {t} {u} e q = λ{x → begin s x ≡⟨ e x ⟩ t x ≡⟨ q x ⟩ u x ∎} data SnocList (A : Set) : Set where [] : SnocList A _•_ : (as : SnocList A) → (a : A) → SnocList A _⊙_ : {A : Set} → SnocList A → SnocList A → SnocList A xs ⊙ [] = xs xs ⊙ (ys • y) = (xs ⊙ ys) • y data All {A : Set} (P : A → Set) : SnocList A → Set where [] : All P [] _∷_ : ∀ {xs : SnocList A} {x : A} → All P xs → P x → All P (xs • x) _++All_ : {A : Set} {P : A → Set} {xs ys : SnocList A} → All P xs → All P ys → All P (xs ⊙ ys) all₁ ++All [] = all₁ all₁ ++All (all₂ ∷ x) = all₁ ++All all₂ ∷ x mapAll : {A : Set} {P Q : A → Set} {xs : SnocList A} → ({x : A} → P x → Q x) → All P xs → All Q xs mapAll pq [] = [] mapAll pq (all ∷ x) = (mapAll pq all) ∷ (pq x) data Action : Set where w[_↦_] : (addr : Addr) (dat : Data) → Action f : Action r : Action wᶜ[_↦_] : (addr : Addr) (dat : Data) → Action fᶜ : Action rᶜ : Action cp : Action er : Action cpᶜ : Action erᶜ : Action variable ac : Action data Regular : Action → Set where w : Regular w[ addr ↦ dat ] cp : Regular cp er : Regular er data Write : Action → Set where w : Write w[ addr ↦ dat ] data Snapshot : Action → Set where f : Snapshot f data RecoveryCrash : Action → Set where rᶜ : RecoveryCrash rᶜ data RegularSuccess : Action → Set where w : RegularSuccess w[ addr ↦ dat ] f : RegularSuccess f data Regular×Snapshot : Action → Set where w : Regular×Snapshot w[ addr ↦ dat ] cp : Regular×Snapshot cp er : Regular×Snapshot er f : Regular×Snapshot f data Regular×SnapshotCrash : Action → Set where wᶜ : Regular×SnapshotCrash wᶜ[ addr ↦ dat ] fᶜ : Regular×SnapshotCrash fᶜ cpᶜ : Regular×SnapshotCrash cpᶜ erᶜ : Regular×SnapshotCrash erᶜ Trace = SnocList Action variable ef : Trace ef₁ : Trace ef₂ : Trace ef₃ : Trace frag : Trace frag-w : Trace frag-rᶜ : Trace flist : SnocList Action flist-w : SnocList Action flist-rᶜ : SnocList Action --Reflexive Transitive Closure data RTC {A S : Set} (R : S → A → S → Set) : S → SnocList A → S → Set where ∅ : ∀ {s : S} → RTC R s [] s _•_ : ∀ {s t u : S} {acs : SnocList A} {ac : A} → RTC R s acs t → R t ac u → RTC R s (acs • ac) u _++RTC_ : {A S : Set} {R : S → A → S → Set} {s t u : S} {ef₁ ef₂ : SnocList A} → RTC R s ef₁ t → RTC R t ef₂ u → RTC R s (ef₁ ⊙ ef₂) u tc-s-t ++RTC ∅ = tc-s-t tc-s-t ++RTC (tc-t-u • rr) = (tc-s-t ++RTC tc-t-u) • rr splitRTC : {A S : Set} {R : S → A → S → Set} {s s' : S} → (splitOn : SnocList A) → {rest : SnocList A} → ( fr : RTC R s (splitOn ⊙ rest) s') → Σ[ s'' ∈ S ] Σ[ fr₁ ∈ RTC R s splitOn s'' ] Σ[ fr₂ ∈ RTC R s'' rest s' ] (fr ≡ (fr₁ ++RTC fr₂)) splitRTC ef₁ {rest = []} t = (_ , t , ∅ , refl) splitRTC ef₁ {rest = (ef₂ • ac)} (t • rr) with splitRTC ef₁ t ... | s'' , t₁ , t₂ , refl = s'' , t₁ , t₂ • rr , refl data OneRecovery : Trace → Set where wᶜ : {tr₁ tr₂ tr₃ : Trace} → All Regular×Snapshot tr₁ → All Regular tr₂ → All RecoveryCrash tr₃ → OneRecovery (tr₁ ⊙ ([] • f ⊙ tr₂) ⊙ ([] • wᶜ[ addr ↦ dat ] ⊙ tr₃ • r)) fᶜ : {tr₁ tr₂ tr₃ : Trace} → All Regular×Snapshot tr₁ → All Regular tr₂ → All RecoveryCrash tr₃ → OneRecovery (tr₁ ⊙ ([] • f ⊙ tr₂) ⊙ ([] • fᶜ ⊙ tr₃ • r)) wᶜ-nof : {tr₂ tr₃ : Trace} → All Regular tr₂ → All RecoveryCrash tr₃ → OneRecovery (tr₂ ⊙ ([] • wᶜ[ addr ↦ dat ] ⊙ tr₃ • r)) fᶜ-nof : {tr₂ tr₃ : Trace} → All Regular tr₂ → All RecoveryCrash tr₃ → OneRecovery (tr₂ ⊙ ([] • fᶜ ⊙ tr₃ • r)) data MultiRecovery : Trace → Set where init : {tr : Trace} → All RecoveryCrash tr → MultiRecovery (tr • r) one : {tr₁ tr₂ : Trace} → MultiRecovery tr₁ → OneRecovery tr₂ → MultiRecovery (tr₁ ⊙ tr₂) data 1RFrags {S : Set} {R : S → Action → S → Set} : {s s' : S} {tr : Trace} → OneRecovery tr → RTC R s tr s' → Set where wᶜ : {tr₁ tr₂ tr₃ : Trace} {all₁ : All Regular×Snapshot tr₁} {all₂ : All Regular tr₂} {all₃ : All RecoveryCrash tr₃} → {s₁ s₂ s₃ s₄ : S} (fr₁ : RTC R s₁ tr₁ s₂) (fr₂ : RTC R s₂ ([] • f ⊙ tr₂) s₃) (fr₃ : RTC R s₃ ([] • wᶜ[ addr ↦ dat ] ⊙ tr₃ • r) s₄) → 1RFrags (wᶜ all₁ all₂ all₃) (fr₁ ++RTC fr₂ ++RTC fr₃) fᶜ : {tr₁ tr₂ tr₃ : Trace} {all₁ : All Regular×Snapshot tr₁} {all₂ : All Regular tr₂} {all₃ : All RecoveryCrash tr₃} → {s₁ s₂ s₃ s₄ : S} (fr₁ : RTC R s₁ tr₁ s₂) (fr₂ : RTC R s₂ ([] • f ⊙ tr₂) s₃) (fr₃ : RTC R s₃ ([] • fᶜ ⊙ tr₃ • r) s₄) → 1RFrags (fᶜ all₁ all₂ all₃) (fr₁ ++RTC fr₂ ++RTC fr₃) wᶜ-nof : {tr₂ tr₃ : Trace} {all₂ : All Regular tr₂} {all₃ : All RecoveryCrash tr₃} → {s₂ s₃ s₄ : S} (fr₂ : RTC R s₂ tr₂ s₃) (fr₃ : RTC R s₃ ([] • wᶜ[ addr ↦ dat ] ⊙ tr₃ • r) s₄) → 1RFrags (wᶜ-nof all₂ all₃) (fr₂ ++RTC fr₃) fᶜ-nof : {tr₂ tr₃ : Trace} {all₂ : All Regular tr₂} {all₃ : All RecoveryCrash tr₃} → {s₂ s₃ s₄ : S} (fr₂ : RTC R s₂ tr₂ s₃) (fr₃ : RTC R s₃ ([] • fᶜ ⊙ tr₃ • r) s₄) → 1RFrags (fᶜ-nof all₂ all₃) (fr₂ ++RTC fr₃) view1R : {tr : Trace} (1r : OneRecovery tr) {S : Set} {R : S → Action → S → Set} {s s' : S} (fr : RTC R s tr s') → 1RFrags 1r fr view1R (wᶜ {tr₁ = tr₁} {tr₂ = tr₂} {tr₃ = tr₃} all₁ all₂ all₃) {s = s₁} {s' = s₄} fr with splitRTC (tr₁ ⊙ ([] • f ⊙ tr₂)) {rest = [] • wᶜ[ _ ↦ _ ] ⊙ tr₃ • r} fr ... | s₃ , fr-l , fr₃ , refl with splitRTC tr₁ {rest = [] • f ⊙ tr₂} fr-l ... | s₂ , fr₁ , fr₂ , refl = wᶜ fr₁ fr₂ fr₃ view1R (fᶜ {tr₁ = tr₁} {tr₂ = tr₂} {tr₃ = tr₃} all₁ all₂ all₃) {s = s₁} {s' = s₄} fr with splitRTC (tr₁ ⊙ ([] • f ⊙ tr₂)) {rest = [] • fᶜ ⊙ tr₃ • r} fr ... | s₃ , fr-l , fr₃ , refl with splitRTC tr₁ {rest = [] • f ⊙ tr₂} fr-l ... | s₂ , fr₁ , fr₂ , refl = fᶜ fr₁ fr₂ fr₃ view1R (wᶜ-nof {tr₂ = tr₂} {tr₃ = tr₃} all₂ all₃) fr with splitRTC tr₂ fr ... | _ , fr₁ , fr₂ , refl = wᶜ-nof fr₁ fr₂ view1R (fᶜ-nof {tr₂ = tr₂} {tr₃ = tr₃} all₂ all₃) fr with splitRTC tr₂ fr ... | _ , fr₁ , fr₂ , refl = fᶜ-nof fr₁ fr₂ data MRFrags {S : Set} {R : S → Action → S → Set} : {s s' : S} {tr : Trace} → MultiRecovery tr → RTC R s tr s' → Set where init : {tr : Trace} {all : All RecoveryCrash tr} {s s' : S} (fr : RTC R s (tr • r) s') → MRFrags (init all) fr one : {tr₁ : Trace} {mr : MultiRecovery tr₁} {s₁ s₂ : S} {fr₁ : RTC R s₁ tr₁ s₂} → MRFrags mr fr₁ → {tr₂ : Trace} {1r : OneRecovery tr₂} {s₃ : S} (fr₂ : RTC R s₂ tr₂ s₃) → 1RFrags 1r fr₂ → MRFrags (one mr 1r) (fr₁ ++RTC fr₂) viewMR : {tr : Trace} (mr : MultiRecovery tr) {S : Set} {R : S → Action → S → Set} {s s' : S} (fr : RTC R s tr s') → MRFrags mr fr viewMR (init all) fr = init fr viewMR (one {tr₁ = tr₁} mr all) fr with splitRTC tr₁ fr ... | _ , fr-l , fr-r , refl = one (viewMR mr fr-l) fr-r (view1R all fr-r) lastr : {S : Set} {s s' : S} {R : S → Action → S → Set} {tr : Trace} (mr : MultiRecovery tr) → (fr : RTC R s tr s') → (frs : MRFrags mr fr) → Σ[ s'' ∈ S ] (R s'' r s') lastr .(init _) .fr (init fr) with fr ... | _ • x = _ , x lastr ._ ._ (one _ ._ (wᶜ _ _ (fr₃ • x))) = _ , x lastr ._ ._ (one _ ._ (fᶜ _ _ (fr₃ • x))) = _ , x lastr ._ ._ (one _ ._ (wᶜ-nof _ (fr₃ • x))) = _ , x lastr ._ ._ (one _ ._ (fᶜ-nof _ (fr₃ • x))) = _ , x SnapshotConsistency : {S : Set} {s s' : S} {R : S → Action → S → Set} (ER : S → S → Set) {tr : Trace} → (1r : OneRecovery tr) → (fr : RTC R s tr s') → 1RFrags 1r fr → Set SnapshotConsistency ER ._ ._ (wᶜ {s₂ = s₂} {s₄ = s₄} _ _ _) = ER s₂ s₄ SnapshotConsistency ER ._ ._ (fᶜ {s₂ = s₂} {s₃} {s₄} _ _ _) = ER s₃ s₄ ⊎ ER s₂ s₄ SnapshotConsistency ER ._ ._ (wᶜ-nof {s₂ = s₂} {s₄ = s₄} _ _) = ER s₂ s₄ SnapshotConsistency ER ._ ._ (fᶜ-nof {s₂ = s₂} {s₃} {s₄} _ _) = ER s₃ s₄ ⊎ ER s₂ s₄ module Spec where record State : Set where field volatile : Addr → Data stable : Addr → Data w-count : ℕ Init : State → Set Init s = (addr : Addr) → (State.stable s addr ≡ defaultData) variable t : State t' : State update : (Addr → Data) → ℕ → Addr → Data → (Addr → Data) update s wcnt addr dat i with (addr ≤?MAXADDR) ∧ (wcnt ≤?MAXWCNT) update s wcnt addr dat i | false = s i update s wcnt addr dat i | true with addr ≟ i update s wcnt addr dat i | true | true = dat update s wcnt addr dat i | true | false = s i data Step (s s' : State) : Action → Set where w : update (State.volatile s) (State.w-count s) addr dat ≐ State.volatile s' → State.stable s ≐ State.stable s' → suc (State.w-count s) ≡ State.w-count s' → Step s s' w[ addr ↦ dat ] f : State.volatile s ≐ State.volatile s' → State.volatile s ≐ State.stable s' → State.w-count s' ≡ zero → Step s s' f r : State.stable s ≐ State.volatile s' → State.stable s ≐ State.stable s' → State.w-count s' ≡ zero → Step s s' r wᶜ : State.stable s ≐ State.stable s' → Step s s' (wᶜ[ addr ↦ dat ]) fᶜ : State.volatile s ≐ State.stable s' ⊎ State.stable s ≐ State.stable s' → Step s s' fᶜ rᶜ : State.stable s ≐ State.stable s' → Step s s' rᶜ cp : State.volatile s ≐ State.volatile s' → State.stable s ≐ State.stable s' → State.w-count s ≡ State.w-count s' → Step s s' cp er : State.volatile s ≐ State.volatile s' → State.stable s ≐ State.stable s' → State.w-count s ≡ State.w-count s' → Step s s' er cpᶜ : State.stable s ≐ State.stable s' → Step s s' cpᶜ erᶜ : State.stable s ≐ State.stable s' → Step s s' erᶜ _⟦_⟧▸_ : State → Action → State → Set s ⟦ ac ⟧▸ s' = Step s s' ac _⟦_⟧*▸_ = RTC _⟦_⟧▸_ record StbP (ac : Action) : Set where --Stability Reserving Actions field preserve : {s s' : State} → s ⟦ ac ⟧▸ s' → (State.stable s ≐ State.stable s') instance stb-r : StbP r stb-r = record { preserve = λ{(r _ ss _) → ss} } stb-w : StbP w[ addr ↦ dat ] stb-w = record { preserve = λ{(w _ ss _ ) → ss} } stb-wᶜ : StbP wᶜ[ addr ↦ dat ] stb-wᶜ = record { preserve = λ{(wᶜ ss) → ss} } stb-rᶜ : StbP rᶜ stb-rᶜ = record { preserve = λ{(rᶜ ss) → ss} } stb-cp : StbP cp stb-cp = record { preserve = λ{(cp _ ss _) → ss}} stb-er : StbP er stb-er = record { preserve = λ{(er _ ss _) → ss}} stb-cpᶜ : StbP cpᶜ stb-cpᶜ = record { preserve = λ{(cpᶜ ss) → ss}} stb-erᶜ : StbP erᶜ stb-erᶜ = record { preserve = λ{(erᶜ ss) → ss}} idemₛ : {tr : Trace} → All StbP tr → ∀ {s s' : State} → s ⟦ tr ⟧*▸ s' → State.stable s ≐ State.stable s' idemₛ [] ∅ = λ{_ → refl} idemₛ (all ∷ x) (s2s'' • s''2s') = idemₛ all s2s'' <≐> StbP.preserve x s''2s' r→rs : Regular ac → Regular×Snapshot ac r→rs w = w r→rs cp = cp r→rs er = er n→sp : Regular ac → StbP ac n→sp w = stb-w n→sp cp = stb-cp n→sp er = stb-er rᶜ→sp : RecoveryCrash ac → StbP ac rᶜ→sp rᶜ = stb-rᶜ SpecSC-wᶜ : ∀ {s₂ s₃ s₄ : State} {tr-w tr-rᶜ} → {{_ : All Regular tr-w}} {{_ : All RecoveryCrash tr-rᶜ}} → s₂ ⟦ [] • f ⊙ tr-w ⟧*▸ s₃ → s₃ ⟦ [] • wᶜ[ addr ↦ dat ] ⊙ tr-rᶜ • r ⟧*▸ s₄ → State.volatile s₂ ≐ State.volatile s₄ SpecSC-wᶜ {{ all₂ }} {{ all₃ }} s₂▸s₃ (s₃▹ • r sv _ _) with splitRTC ([] • f) s₂▸s₃ | splitRTC ([] • wᶜ[ _ ↦ _ ]) s₃▹ ... | s₂' , ∅ • (f vv vs _) , s₂'▸s₃ , _ | s₃' , ∅ • (wᶜ ss) , s₃'▸s₄▹ , _ = vs <≐> idemₛ (mapAll n→sp all₂) s₂'▸s₃ <≐> ss <≐> idemₛ (mapAll rᶜ→sp all₃) s₃'▸s₄▹ <≐> sv SpecSC-wᶜ-nof : ∀ {s₁ s₂ s₃ s₄ : State} {tr-w tr-rᶜ} → {{_ : All Regular tr-w}} {{_ : All RecoveryCrash tr-rᶜ}} → s₁ ⟦ r ⟧▸ s₂ → s₂ ⟦ tr-w ⟧*▸ s₃ → s₃ ⟦ [] • wᶜ[ addr ↦ dat ] ⊙ tr-rᶜ • r ⟧*▸ s₄ → State.volatile s₂ ≐ State.volatile s₄ SpecSC-wᶜ-nof {{ all₂ }} {{ all₃ }} (r sv' ss' _) s₂▸s₃ (s₃▹ • r sv _ _) with splitRTC ([] • wᶜ[ _ ↦ _ ]) s₃▹ ... | s₃' , ∅ • (wᶜ ss) , s₃'▸s₄▹ , _ = sym-≐ sv' <≐> ss' <≐> idemₛ (mapAll n→sp all₂) s₂▸s₃ <≐> ss <≐> idemₛ (mapAll rᶜ→sp all₃) s₃'▸s₄▹ <≐> sv SpecSC-fᶜ : ∀ {s₂ s₃ s : State} {tr-w tr-rᶜ} → {{_ : All Regular tr-w}} {{_ : All RecoveryCrash tr-rᶜ}} → s₂ ⟦ ([] • f) ⊙ tr-w ⟧*▸ s₃ → s₃ ⟦ ([] • fᶜ) ⊙ tr-rᶜ • r ⟧*▸ s → State.volatile s₃ ≐ State.volatile s ⊎ State.volatile s₂ ≐ State.volatile s SpecSC-fᶜ {{all₁}} {{all₂}} s₂▸s₃ (s₃▸s • r sv ss _) with splitRTC ([] • f) s₂▸s₃ | splitRTC ([] • fᶜ) s₃▸s ... | _ , ∅ • f vv vs _ , ▸s₃ , _ | s₃' , ∅ • fᶜ (inj₁ vsᶜ) , s₃'▸s , _ = inj₁ $ vsᶜ <≐> idemₛ (mapAll rᶜ→sp all₂) s₃'▸s <≐> sv ... | _ , ∅ • f vv vs _ , ▸s₃ , _ | s₃' , ∅ • fᶜ (inj₂ ssᶜ) , s₃'▸s , _ = inj₂ $ vs <≐> idemₛ (mapAll n→sp all₁) ▸s₃ <≐> ssᶜ <≐> idemₛ (mapAll rᶜ→sp all₂) s₃'▸s <≐> sv SpecSC-fᶜ-nof : ∀ {s₁ s₂ s₃ s₄ : State} {tr-w tr-rᶜ} → {{_ : All Regular tr-w}} {{_ : All RecoveryCrash tr-rᶜ}} → s₁ ⟦ r ⟧▸ s₂ → s₂ ⟦ tr-w ⟧*▸ s₃ → s₃ ⟦ [] • fᶜ ⊙ tr-rᶜ • r ⟧*▸ s₄ → State.volatile s₃ ≐ State.volatile s₄ ⊎ State.volatile s₂ ≐ State.volatile s₄ SpecSC-fᶜ-nof {{ all₂ }} {{ all₃ }} (r sv' ss' _) s₂▸s₃ (s₃▹ • r sv _ _) with splitRTC ([] • fᶜ) s₃▹ ... | s₃' , ∅ • fᶜ (inj₁ vsᶜ) , s₃'▸s , _ = inj₁ $ vsᶜ <≐> idemₛ (mapAll rᶜ→sp all₃) s₃'▸s <≐> sv ... | s₃' , ∅ • fᶜ (inj₂ ssᶜ) , s₃'▸s , _ = inj₂ $ sym-≐ sv' <≐> ss' <≐> idemₛ (mapAll n→sp all₂) s₂▸s₃ <≐> ssᶜ <≐> idemₛ (mapAll rᶜ→sp all₃) s₃'▸s <≐> sv SC : {t₀ t t' : State} {tr₀ tr : Trace} → (mr : MultiRecovery tr₀) → (1r : OneRecovery tr) → Init t₀ → (fr₀ : t₀ ⟦ tr₀ ⟧*▸ t) → MRFrags mr fr₀ → (fr : t ⟦ tr ⟧*▸ t') → (frs : 1RFrags 1r fr) → SnapshotConsistency (λ t t' → State.volatile t ≐ State.volatile t') 1r fr frs SC mr _ init-t₀ fr₀ frs₀ ._ (wᶜ {all₂ = all₂} {all₃} fr₁ fr₂ fr₃) = SpecSC-wᶜ {{all₂}} {{all₃}} fr₂ fr₃ SC mr _ init-t₀ fr₀ frs₀ ._ (fᶜ {all₂ = all₂} {all₃} fr₁ fr₂ fr₃) = SpecSC-fᶜ {{all₂}} {{all₃}} fr₂ fr₃ SC mr _ init-t₀ fr₀ frs₀ ._ (wᶜ-nof {all₂ = all₂} {all₃} fr₂ fr₃) = SpecSC-wᶜ-nof {{all₂}} {{all₃}} (proj₂ (lastr mr fr₀ frs₀)) fr₂ fr₃ SC mr _ init-t₀ fr₀ frs₀ ._ (fᶜ-nof {all₂ = all₂} {all₃} fr₂ fr₃) = SpecSC-fᶜ-nof {{all₂}} {{all₃}} (proj₂ (lastr mr fr₀ frs₀)) fr₂ fr₃ open Spec hiding (SC) module Prog (runSpec : (t : State) (ac : Action) → ∃[ t' ] (t ⟦ ac ⟧▸ t')) (RawStateᴾ : Set) (_⟦_⟧ᴿ▸_ : RawStateᴾ → Action → RawStateᴾ → Set) (RI CI : RawStateᴾ → Set) (AR CR : RawStateᴾ → State → Set) (RIRI : {s s' : RawStateᴾ} {ac : Action} → Regular×Snapshot ac → s ⟦ ac ⟧ᴿ▸ s' → RI s → RI s') (ARAR : {s s' : RawStateᴾ} {t t' : State} {ac : Action} → Regular×Snapshot ac → s ⟦ ac ⟧ᴿ▸ s' → t ⟦ ac ⟧▸ t' → RI s × AR s t → AR s' t') (RICI : {s s' : RawStateᴾ} {ac : Action} → Regular×SnapshotCrash ac → s ⟦ ac ⟧ᴿ▸ s' → RI s → CI s') (ARCR : {s s' : RawStateᴾ} {t t' : State} {ac : Action} → Regular×SnapshotCrash ac → s ⟦ ac ⟧ᴿ▸ s' → t ⟦ ac ⟧▸ t' → RI s × AR s t → CR s' t') (CIRI : {s s' : RawStateᴾ} → s ⟦ r ⟧ᴿ▸ s' → CI s → RI s') (CRAR : {s s' : RawStateᴾ} {t t' : State} → s ⟦ r ⟧ᴿ▸ s' → t ⟦ r ⟧▸ t' → CI s × CR s t → AR s' t') (CICI : {s s' : RawStateᴾ} → s ⟦ rᶜ ⟧ᴿ▸ s' → CI s → CI s') (CRCR : {s s' : RawStateᴾ} {t t' : State} → s ⟦ rᶜ ⟧ᴿ▸ s' → t ⟦ rᶜ ⟧▸ t' → CI s × CR s t → CR s' t') (read : RawStateᴾ → Addr → Data) (AR⇒ObsEquiv : {s : RawStateᴾ} {t : State} → RI s × AR s t → read s ≐ State.volatile t) (Initᴿ : RawStateᴾ → Set) (initᴿ-CI : (s : RawStateᴾ) → Initᴿ s → CI s) (initᴿ-CR : (s : RawStateᴾ) → Initᴿ s → (t : State) → Init t → CR s t) (t-init : Σ[ t ∈ State ] Init t) where variable rs : RawStateᴾ rs₁ : RawStateᴾ rinv : RI rs cinv : CI rs rs' : RawStateᴾ rs'' : RawStateᴾ rs''' : RawStateᴾ rinv' : RI rs' cinv' : CI rs' _⟦_⟧ᴿ*▸_ = RTC _⟦_⟧ᴿ▸_ data Inv (rs : RawStateᴾ) : Set where normal : RI rs → Inv rs crash : CI rs → Inv rs Stateᴾ : Set Stateᴾ = Σ[ rs ∈ RawStateᴾ ] Inv rs data Initᴾ : Stateᴾ → Set where init : Initᴿ rs → Initᴾ (rs , crash cinv) variable s : Stateᴾ s' : Stateᴾ s'' : Stateᴾ s''' : Stateᴾ data _⟦_⟧ᴾ▸_ : Stateᴾ → Action → Stateᴾ → Set where w : rs ⟦ w[ addr ↦ dat ] ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ w[ addr ↦ dat ] ⟧ᴾ▸ (rs' , normal rinv') f : rs ⟦ f ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ f ⟧ᴾ▸ (rs' , normal rinv') wᶜ : rs ⟦ wᶜ[ addr ↦ dat ] ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ wᶜ[ addr ↦ dat ] ⟧ᴾ▸ (rs' , crash cinv') fᶜ : rs ⟦ fᶜ ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ fᶜ ⟧ᴾ▸ (rs' , crash cinv') rᶜ : rs ⟦ rᶜ ⟧ᴿ▸ rs' → (rs , crash cinv) ⟦ rᶜ ⟧ᴾ▸ (rs' , crash cinv') r : rs ⟦ r ⟧ᴿ▸ rs' → (rs , crash cinv) ⟦ r ⟧ᴾ▸ (rs' , normal rinv') cp : rs ⟦ cp ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ cp ⟧ᴾ▸ (rs' , normal rinv') er : rs ⟦ er ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ er ⟧ᴾ▸ (rs' , normal rinv') cpᶜ : rs ⟦ cpᶜ ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ cpᶜ ⟧ᴾ▸ (rs' , crash cinv') erᶜ : rs ⟦ erᶜ ⟧ᴿ▸ rs' → (rs , normal rinv) ⟦ erᶜ ⟧ᴾ▸ (rs' , crash cinv') _⟦_⟧ᴾ*▸_ = RTC _⟦_⟧ᴾ▸_ lift-n×s : {tr : Trace} {{_ : All Regular×Snapshot tr}} → rs ⟦ tr ⟧ᴿ*▸ rs' → ∃[ rinv' ] ((rs , normal rinv) ⟦ tr ⟧ᴾ*▸ (rs' , normal rinv')) lift-n×s ∅ = _ , ∅ lift-n×s {{all ∷ w}} (rs*▸rs'' • rs''▸rs') = let (rinv'' , s*▸s'') = lift-n×s {{all}} rs*▸rs'' in RIRI w rs''▸rs' rinv'' , s*▸s'' • w rs''▸rs' lift-n×s {{all ∷ f}} (rs*▸rs'' • rs''▸rs') = let (rinv'' , s*▸s'') = lift-n×s {{all}} rs*▸rs'' in RIRI f rs''▸rs' rinv'' , s*▸s'' • f rs''▸rs' lift-n×s {{all ∷ cp}} (rs*▸rs'' • rs''▸rs') = let (rinv'' , s*▸s'') = lift-n×s {{all}} rs*▸rs'' in RIRI cp rs''▸rs' rinv'' , s*▸s'' • cp rs''▸rs' lift-n×s {{all ∷ er}} (rs*▸rs'' • rs''▸rs') = let (rinv'' , s*▸s'') = lift-n×s {{all}} rs*▸rs'' in RIRI er rs''▸rs' rinv'' , s*▸s'' • er rs''▸rs' lift-n : {tr : Trace} {{_ : All Regular tr}} → rs ⟦ tr ⟧ᴿ*▸ rs' → ∃[ rinv' ] ((rs , normal rinv) ⟦ tr ⟧ᴾ*▸ (rs' , normal rinv')) lift-n {{all}} rs*▸rs' = lift-n×s {{(mapAll (λ{w → w; cp → cp; er → er}) all)}} rs*▸rs' lift-rᶜ : {tr : Trace} {{_ : All RecoveryCrash tr}} → rs ⟦ tr ⟧ᴿ*▸ rs' → ∃[ cinv' ] ((rs , crash cinv) ⟦ tr ⟧ᴾ*▸ (rs' , crash cinv')) lift-rᶜ ∅ = _ , ∅ lift-rᶜ {{all ∷ rᶜ}} (rs*▸rs'' • rs''▸rs') = let (cinv'' , s*▸s'') = lift-rᶜ {{all}} rs*▸rs'' in CICI rs''▸rs' cinv'' , s*▸s'' • rᶜ rs''▸rs' lift-mr : {tr : Trace} (mr : MultiRecovery tr) (fr : rs ⟦ tr ⟧ᴿ*▸ rs') → MRFrags mr fr → Initᴿ rs → ∃[ cinv ] ∃[ rinv' ] let s = (rs , crash cinv) in (s ⟦ tr ⟧ᴾ*▸ (rs' , normal rinv')) × Initᴾ s lift-mr ._ ._ (init {all = all} fr) init-rs with fr ... | fr₀ • rr with lift-rᶜ {cinv = initᴿ-CI _ init-rs} {{all}} fr₀ ... | cinv₀ , fr₀ᴾ = _ , CIRI rr cinv₀ , fr₀ᴾ • r rr , init init-rs lift-mr ._ ._ (one frs₀ fr frs) init-rs with lift-mr _ _ frs₀ init-rs lift-mr ._ ._ (one frs₀ ._ (wᶜ {tr₃ = tr₃} {all₁ = all₁} {all₂} {all₃} fr₁ fr₂ fr₃)) init-rs | cinv₀ , rinv₀ , fr₀ᴾ , init-s with splitRTC ([] • (wᶜ[ _ ↦ _ ])) {rest = (tr₃ • r)} fr₃ ... | rs'' , ∅ • s₃▸s₃' , s₃'▸r • r▸rs' , eq with lift-n×s {rinv = rinv₀} {{all₁}} fr₁ ... | rinv₁ , frP₁ with lift-n×s {rinv = rinv₁} {{ ([] ∷ f) ++All mapAll r→rs all₂ }} fr₂ ... | rinv₂ , frP₂ with RICI wᶜ s₃▸s₃' rinv₂ ... | cinv₂' with lift-rᶜ {cinv = cinv₂'} {{all₃}} s₃'▸r ... | cinv₃ , frP₃ with CIRI r▸rs' cinv₃ ... | rinv₄ = cinv₀ , rinv₄ , fr₀ᴾ ++RTC (frP₁ ++RTC frP₂ ++RTC ((∅ • wᶜ s₃▸s₃') ++RTC (frP₃ • r r▸rs'))), init-s lift-mr ._ ._ (one frs₀ ._ (fᶜ {tr₃ = tr₃} {all₁ = all₁} {all₂} {all₃} fr₁ fr₂ fr₃)) init-rs | cinv₀ , rinv₀ , fr₀ᴾ , init-s with splitRTC ([] • fᶜ) {rest = (tr₃ • r)} fr₃ ... | rs'' , ∅ • s₃▸s₃' , s₃'▸r • r▸rs' , eq with lift-n×s {rinv = rinv₀} {{all₁}} fr₁ ... | rinv₁ , frP₁ with lift-n×s {rinv = rinv₁} {{ ([] ∷ f) ++All mapAll r→rs all₂ }} fr₂ ... | rinv₂ , frP₂ with RICI fᶜ s₃▸s₃' rinv₂ ... | cinv₂' with lift-rᶜ {cinv = cinv₂'} {{all₃}} s₃'▸r ... | cinv₃ , frP₃ with CIRI r▸rs' cinv₃ ... | rinv₄ = cinv₀ , rinv₄ , fr₀ᴾ ++RTC (frP₁ ++RTC frP₂ ++RTC ((∅ • fᶜ s₃▸s₃') ++RTC (frP₃ • r r▸rs'))), init-s lift-mr ._ ._ (one frs₀ ._ (wᶜ-nof {tr₃ = tr₃} {all₂ = all₂} {all₃} fr₂ fr₃)) init-rs | cinv₀ , rinv₀ , fr₀ᴾ , init-s with splitRTC ([] • wᶜ[ _ ↦ _ ]) {rest = (tr₃ • r)} fr₃ ... | rs'' , ∅ • s₃▸s₃' , s₃'▸r • r▸rs' , eq with lift-n×s {rinv = rinv₀} {{ mapAll r→rs all₂ }} fr₂ ... | rinv₂ , frP₂ with RICI wᶜ s₃▸s₃' rinv₂ ... | cinv₂' with lift-rᶜ {cinv = cinv₂'} {{all₃}} s₃'▸r ... | cinv₃ , frP₃ with CIRI r▸rs' cinv₃ ... | rinv₄ = cinv₀ , rinv₄ , fr₀ᴾ ++RTC (frP₂ ++RTC ((∅ • wᶜ s₃▸s₃') ++RTC (frP₃ • r r▸rs'))), init-s lift-mr ._ ._ (one frs₀ ._ (fᶜ-nof {tr₃ = tr₃} {all₂ = all₂} {all₃} fr₂ fr₃)) init-rs | cinv₀ , rinv₀ , fr₀ᴾ , init-s with splitRTC ([] • fᶜ) {rest = (tr₃ • r)} fr₃ ... | rs'' , ∅ • s₃▸s₃' , s₃'▸r • r▸rs' , eq with lift-n×s {rinv = rinv₀} {{ mapAll r→rs all₂ }} fr₂ ... | rinv₂ , frP₂ with RICI fᶜ s₃▸s₃' rinv₂ ... | cinv₂' with lift-rᶜ {cinv = cinv₂'} {{all₃}} s₃'▸r ... | cinv₃ , frP₃ with CIRI r▸rs' cinv₃ ... | rinv₄ = cinv₀ , rinv₄ , fr₀ᴾ ++RTC (frP₂ ++RTC ((∅ • fᶜ s₃▸s₃') ++RTC (frP₃ • r r▸rs'))), init-s ObsEquiv : Stateᴾ → State → Set ObsEquiv (rs , _) t = read rs ≐ State.volatile t data SR : Stateᴾ → State → Set where ar : AR rs t → SR (rs , normal rinv) t cr : CR rs t → SR (rs , crash cinv) t simSR : SR s t → s ⟦ ac ⟧ᴾ▸ s' → ∃[ t' ] (t ⟦ ac ⟧▸ t' × SR s' t') simSR {s , normal rinv} {t} (ar AR-rs-t) (w {addr = addr} {dat = dat} rs▸rs') = let (t' , t▸t') = runSpec t w[ addr ↦ dat ] in t' , t▸t' , ar (ARAR w rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (f rs▸rs') = let (t' , t▸t') = runSpec t f in t' , t▸t' , ar (ARAR f rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (wᶜ {addr = addr} {dat = dat} rs▸rs') = let (t' , t▸t') = runSpec t wᶜ[ addr ↦ dat ] in t' , t▸t' , cr (ARCR wᶜ rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (fᶜ rs▸rs') = let (t' , t▸t') = runSpec t fᶜ in t' , t▸t' , cr (ARCR fᶜ rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , crash cinv} {t} (cr CR-rs-t) (rᶜ rs▸rs') = let (t' , t▸t') = runSpec t rᶜ in t' , t▸t' , cr (CRCR rs▸rs' t▸t' (cinv , CR-rs-t)) simSR {s , crash cinv} {t} (cr CR-rs-t) (r rs▸rs') = let (t' , t▸t') = runSpec t r in t' , t▸t' , ar (CRAR rs▸rs' t▸t' (cinv , CR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (cp rs▸rs') = let (t' , t▸t') = runSpec t cp in t' , t▸t' , ar (ARAR cp rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (er rs▸rs') = let (t' , t▸t') = runSpec t er in t' , t▸t' , ar (ARAR er rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (cpᶜ rs▸rs') = let (t' , t▸t') = runSpec t cpᶜ in t' , t▸t' , cr (ARCR cpᶜ rs▸rs' t▸t' (rinv , AR-rs-t)) simSR {s , normal rinv} {t} (ar AR-rs-t) (erᶜ rs▸rs') = let (t' , t▸t') = runSpec t erᶜ in t' , t▸t' , cr (ARCR erᶜ rs▸rs' t▸t' (rinv , AR-rs-t)) runSimSR : SR s t → s ⟦ ef ⟧ᴾ*▸ s' → ∃[ t' ] (t ⟦ ef ⟧*▸ t' × SR s' t') runSimSR SR-s-t ∅ = _ , ∅ , SR-s-t runSimSR SR-s-t (s*▸s'' • s''▸s') = let (t'' , t*▸t'' , SR-s''-t'') = runSimSR SR-s-t s*▸s'' (t' , t''▸t' , SR-s'-t' ) = simSR SR-s''-t'' s''▸s' in _ , (t*▸t'' • t''▸t') , SR-s'-t' Conformant-all : {tr : Trace} {s s' : Stateᴾ} → s ⟦ tr ⟧ᴾ*▸ s' → {t t' : State} → t ⟦ tr ⟧*▸ t' → Set Conformant-all {s' = s'} ∅ {t' = t'} ∅ = ⊤ Conformant-all {s' = s'} (frP • _) {t' = t'} (frS • _) = Conformant-all frP frS × ObsEquiv s' t' Conformant-1R : {tr : Trace} (1r : OneRecovery tr) → {s s' : Stateᴾ} (frP : s ⟦ tr ⟧ᴾ*▸ s') → 1RFrags 1r frP → {t t' : State } (frS : t ⟦ tr ⟧*▸ t') → 1RFrags 1r frS → Set Conformant-1R ._ {s' = s'} ._ (wᶜ frP₁ frP₂ frP₃) {t' = t'} ._ (wᶜ frS₁ frS₂ frS₃) = Conformant-all (frP₁ ++RTC frP₂) (frS₁ ++RTC frS₂) × ObsEquiv s' t' Conformant-1R ._ {s' = s'} ._ (fᶜ frP₁ frP₂ frP₃) {t' = t'} ._ (fᶜ frS₁ frS₂ frS₃) = Conformant-all (frP₁ ++RTC frP₂) (frS₁ ++RTC frS₂) × ObsEquiv s' t' Conformant-1R ._ {s' = s'} ._ (wᶜ-nof frP₂ frP₃) {t' = t'} ._ (wᶜ-nof frS₂ frS₃) = Conformant-all frP₂ frS₂ × ObsEquiv s' t' Conformant-1R ._ {s' = s'} ._ (fᶜ-nof frP₂ frP₃) {t' = t'} ._ (fᶜ-nof frS₂ frS₃) = Conformant-all frP₂ frS₂ × ObsEquiv s' t' Conformant-all-intermediate : {s₁ s₂ s₃ : Stateᴾ} {t₁ t₂ t₃ : State} {tr tr' : Trace} (frP : s₁ ⟦ tr ⟧ᴾ*▸ s₂) (frS : t₁ ⟦ tr ⟧*▸ t₂) (frP' : s₂ ⟦ tr' ⟧ᴾ*▸ s₃) (frS' : t₂ ⟦ tr' ⟧*▸ t₃) → Conformant-all (frP ++RTC frP') (frS ++RTC frS') → ObsEquiv s₁ t₁ → ObsEquiv s₂ t₂ Conformant-all-intermediate ∅ ∅ _ _ conf oe = oe Conformant-all-intermediate (frP • sP) (frS • sS) ∅ ∅ conf oe = proj₂ conf Conformant-all-intermediate (frP • sP) (frS • sS) (frP' • sP') (frS' • sS') conf oe = Conformant-all-intermediate (frP • sP) (frS • sS) frP' frS' (proj₁ conf) oe conf-all++ : {s₁ s₂ s₃ : Stateᴾ} {t₁ t₂ t₃ : State} {tr tr' : Trace} (frP : s₁ ⟦ tr ⟧ᴾ*▸ s₂) (frS : t₁ ⟦ tr ⟧*▸ t₂) (frP' : s₂ ⟦ tr' ⟧ᴾ*▸ s₃) (frS' : t₂ ⟦ tr' ⟧*▸ t₃) → Conformant-all frP frS → Conformant-all frP' frS' → Conformant-all (frP ++RTC frP') (frS ++RTC frS') conf-all++ frP frS ∅ ∅ conf conf' = conf conf-all++ frP frS (frP' • p) (frS' • s) conf (conf' , oe) = conf-all++ frP frS frP' frS' conf conf' , oe Conformant : {tr : Trace} (mr : MultiRecovery tr) {s s' : Stateᴾ} (frP : s ⟦ tr ⟧ᴾ*▸ s') → MRFrags mr frP → {t t' : State } (frS : t ⟦ tr ⟧*▸ t') → MRFrags mr frS → Set Conformant (init _) {s' = s'} _ _ {t' = t'} _ _ = ObsEquiv s' t' Conformant (one mr 1r) .(_ ++RTC frP₂) (one {s₂ = s''} frPs frP₂ frPs₂) .(_ ++RTC frS₂) (one {s₂ = t''} frSs frS₂ frSs₂) = Conformant mr _ frPs _ frSs × ObsEquiv s'' t'' × Conformant-1R 1r frP₂ frPs₂ frS₂ frSs₂ BC-all : {tr : Trace} → All Regular×Snapshot tr → {s s' : Stateᴾ} {t : State} → SR s t → ObsEquiv s t → (frP : s ⟦ tr ⟧ᴾ*▸ s') → Σ[ t' ∈ State ] Σ[ frS ∈ t ⟦ tr ⟧*▸ t' ] SR s' t' × ObsEquiv s' t' × Conformant-all frP frS BC-all [] sr oe-s-t ∅ = _ , ∅ , sr , oe-s-t , tt BC-all (all ∷ _) sr oe-s-t (frP • _) with BC-all all sr oe-s-t frP BC-all (all ∷ _) sr oe-s-t (frP • s''▸s') | t'' , frS'' , sr'' , oe'' , conf'' with simSR sr'' s''▸s' BC-all (all ∷ w) sr oe-s-t (frP • w {rinv' = rinv'} rs''▸s') | t'' , frS'' , sr'' , oe'' , conf'' | t' , t''▸t' , ar ar' = let oe' = AR⇒ObsEquiv (rinv' , ar') in t' , frS'' • t''▸t' , ar ar' , oe' , conf'' , oe' BC-all (all ∷ cp) sr oe-s-t (frP • cp {rinv' = rinv'} rs''▸s') | t'' , frS'' , sr'' , oe'' , conf'' | t' , t''▸t' , ar ar' = let oe' = AR⇒ObsEquiv (rinv' , ar') in t' , frS'' • t''▸t' , ar ar' , oe' , conf'' , oe' BC-all (all ∷ er) sr oe-s-t (frP • er {rinv' = rinv'} rs''▸s') | t'' , frS'' , sr'' , oe'' , conf'' | t' , t''▸t' , ar ar' = let oe' = AR⇒ObsEquiv (rinv' , ar') in t' , frS'' • t''▸t' , ar ar' , oe' , conf'' , oe' BC-all (all ∷ f) sr oe-s-t (frP • f {rinv' = rinv'} rs''▸s') | t'' , frS'' , sr'' , oe'' , conf'' | t' , t''▸t' , ar ar' = let oe' = AR⇒ObsEquiv (rinv' , ar') in t' , frS'' • t''▸t' , ar ar' , oe' , conf'' , oe' BC-1R : {tr : Trace} → (1r : OneRecovery tr) → {s s' : Stateᴾ} {t : State} → SR s t → ObsEquiv s t → (frP : s ⟦ tr ⟧ᴾ*▸ s') (frPs : 1RFrags 1r frP) → Σ[ t' ∈ State ] Σ[ frS ∈ t ⟦ tr ⟧*▸ t' ] Σ[ frSs ∈ 1RFrags 1r frS ] SR s' t' × ObsEquiv s' t' × Conformant-1R 1r frP frPs frS frSs BC-1R 1r sr s=t frP (wᶜ {all₁ = all₁} {all₂ = all₂} fr₁ fr₂ fr₃@(fr₃' • r {rinv' = rinv'} _)) with BC-all all₁ sr s=t fr₁ ... | t₁ , frS₁ , sr-s₁-t₁ , s₁=t₁ , conf₁ with BC-all (([] ∷ f) ++All mapAll r→rs all₂) sr-s₁-t₁ s₁=t₁ fr₂ ... | t₂ , frS₂ , sr-s₂-t₂ , s₂=t₂ , conf₂ with runSimSR sr-s₂-t₂ fr₃ ... | t' , frS' , ar ar-s'-t' = let oe' = AR⇒ObsEquiv (rinv' , ar-s'-t') in t' , frS₁ ++RTC frS₂ ++RTC frS' , wᶜ frS₁ frS₂ frS' , ar ar-s'-t' , oe' , conf-all++ fr₁ frS₁ fr₂ frS₂ conf₁ conf₂ , oe' BC-1R 1r sr s=t frP (fᶜ {all₁ = all₁} {all₂ = all₂} fr₁ fr₂ fr₃@(fr₃' • r {rinv' = rinv'} _)) with BC-all all₁ sr s=t fr₁ ... | t₁ , frS₁ , sr-s₁-t₁ , s₁=t₁ , conf₁ with BC-all (([] ∷ f) ++All mapAll r→rs all₂) sr-s₁-t₁ s₁=t₁ fr₂ ... | t₂ , frS₂ , sr-s₂-t₂ , s₂=t₂ , conf₂ with runSimSR sr-s₂-t₂ fr₃ ... | t' , frS' , ar ar-s'-t' = let oe' = AR⇒ObsEquiv (rinv' , ar-s'-t') in t' , frS₁ ++RTC frS₂ ++RTC frS' , fᶜ frS₁ frS₂ frS' , ar ar-s'-t' , oe' , conf-all++ fr₁ frS₁ fr₂ frS₂ conf₁ conf₂ , oe' BC-1R 1r sr s=t frP (wᶜ-nof {all₂ = all₂} fr₂ fr₃@(fr₃' • r {rinv' = rinv'} _)) with BC-all (mapAll r→rs all₂) sr s=t fr₂ ... | _ , frS₂ , sr-s₂-t₂ , s₂=t₂ , conf₂ with runSimSR sr-s₂-t₂ fr₃ ... | t' , frS' , ar ar-s'-t' = let oe' = AR⇒ObsEquiv (rinv' , ar-s'-t') in t' , frS₂ ++RTC frS' , wᶜ-nof frS₂ frS' , ar ar-s'-t' , oe' , conf₂ , oe' BC-1R 1r sr s=t frP (fᶜ-nof {all₂ = all₂} fr₂ fr₃@(fr₃' • r {rinv' = rinv'} _)) with BC-all (mapAll r→rs all₂) sr s=t fr₂ ... | _ , frS₂ , sr-s₂-t₂ , s₂=t₂ , conf₂ with runSimSR sr-s₂-t₂ fr₃ ... | t' , frS' , ar ar-s'-t' = let oe' = AR⇒ObsEquiv (rinv' , ar-s'-t') in t' , frS₂ ++RTC frS' , fᶜ-nof frS₂ frS' , ar ar-s'-t' , oe' , conf₂ , oe' BC-ind : {tr : Trace} (mr : MultiRecovery tr) {s s' : Stateᴾ} → Initᴾ s → (frP : s ⟦ tr ⟧ᴾ*▸ s') (frPs : MRFrags mr frP) → Σ[ t ∈ State ] Init t × Σ[ t' ∈ State ] SR s' t' × ObsEquiv s' t' × Σ[ frS ∈ t ⟦ tr ⟧*▸ t' ] Σ[ frSs ∈ MRFrags mr frS ] Conformant mr frP frPs frS frSs BC-ind (init all) {s = s₀} (init rs₀) (frP • rP@(r {rinv' = rinv'} rs)) frPs with runSimSR (cr (initᴿ-CR (proj₁ s₀) rs₀ (proj₁ t-init) (proj₂ t-init))) frP ... | t'' , frS , sr' with simSR sr' rP ... | t' , rS , (ar ar-rs'-t') = let eq = AR⇒ObsEquiv (rinv' , ar-rs'-t') in proj₁ t-init , proj₂ t-init , t' , ar ar-rs'-t' , eq , frS • rS , init (frS • rS) , eq BC-ind (one mr x) init-s _ (one {mr = mr₁} {fr₁ = frP₁} frPs₁ {1r = 1r} frP₂ frPs₂) with BC-ind mr init-s _ frPs₁ ... | t , init-t , t'' , sr'' , oe'' , frS₁ , frSs₁ , conf₁ with BC-1R 1r sr'' oe'' frP₂ frPs₂ ... | t' , frS₂ , frSs₂ , sr' , oe' , conf₂ = t , init-t , t' , sr' , oe' , frS₁ ++RTC frS₂ , one frSs₁ frS₂ frSs₂ , conf₁ , oe'' , conf₂ BC-mr : {tr : Trace} (mr : MultiRecovery tr) {s s' : Stateᴾ} → Initᴾ s → (frP : s ⟦ tr ⟧ᴾ*▸ s') → (frPs : MRFrags mr frP) → Σ[ t ∈ State ] Init t × Σ[ t' ∈ State ] Σ[ frS ∈ t ⟦ tr ⟧*▸ t' ] Σ[ frSs ∈ MRFrags mr frS ] Conformant mr frP frPs frS frSs BC-mr mr init-s frP frPs = let (t , init-t , t' , _ , _ , frS , frSs , conf) = BC-ind mr init-s frP frPs in (t , init-t , t' , frS , frSs , conf) BC : {tr : Trace} (mr : MultiRecovery tr) {s s' : Stateᴾ} → Initᴾ s → (frP : s ⟦ tr ⟧ᴾ*▸ s') (frPs : MRFrags mr frP) → {tr' : Trace} {s'' : Stateᴾ} → All Regular×Snapshot tr' → (frP' : s' ⟦ tr' ⟧ᴾ*▸ s'') → Σ[ t ∈ State ] Init t × Σ[ t' ∈ State ] Σ[ frS ∈ t ⟦ tr ⟧*▸ t' ] Σ[ frSs ∈ MRFrags mr frS ] Σ[ t'' ∈ State ] Σ[ frS' ∈ t' ⟦ tr' ⟧*▸ t'' ] Conformant mr frP frPs frS frSs × Conformant-all frP' frS' BC mr init-s frP frPs all frP' = let (t , init-t , t' , sr' , oe' , frS , frSs , conf) = BC-ind mr init-s frP frPs (t'' , frS' , _ , _ , conf') = BC-all all sr' oe' frP' in (t , init-t , t' , frS , frSs , t'' , frS' , conf , conf') SC : {s₀ s s' : Stateᴾ} {tr₀ tr : Trace} → (mr : MultiRecovery tr₀) → (1r : OneRecovery tr) → Initᴾ s₀ → (fr₀ : s₀ ⟦ tr₀ ⟧ᴾ*▸ s) → MRFrags mr fr₀ → (frP : s ⟦ tr ⟧ᴾ*▸ s') → (frPs : 1RFrags 1r frP) → SnapshotConsistency (λ{(rs , _) (rs' , _) → read rs ≐ read rs'}) 1r frP frPs SC mr 1r init-s₀ frP₀ frPs₀ frP frPs with BC-mr (one mr 1r) init-s₀ (frP₀ ++RTC frP) (one frPs₀ frP frPs) SC mr ._ init-s₀ frP₀ frPs₀ ._ (wᶜ frP₁ frP₂ frP₃) | t₀ , init-t₀ , t' , ._ , one frSs ._ (wᶜ {all₁ = all₁} {all₂ = all₂} {all₃ = all₃} frS₁ frS₂ frS₃) , (_ , oe-s-t , conf , oe-s'-t') = Conformant-all-intermediate frP₁ frS₁ frP₂ frS₂ conf oe-s-t <≐> SpecSC-wᶜ ⦃ all₂ ⦄ ⦃ all₃ ⦄ frS₂ frS₃ <≐> sym-≐ oe-s'-t' SC mr ._ init-s₀ frP₀ frPs₀ ._ (fᶜ frP₁ frP₂ frP₃) | t₀ , init-t₀ , t' , ._ , one frSs ._ (fᶜ {all₁ = all₁} {all₂ = all₂} {all₃ = all₃} frS₁ frS₂ frS₃) , (_ , oe-s-t , conf , oe-s'-t') with SpecSC-fᶜ {{all₂}} {{all₃}} frS₂ frS₃ ... | inj₁ req = inj₁ $ Conformant-all-intermediate (frP₁ ++RTC frP₂) (frS₁ ++RTC frS₂) ∅ ∅ conf oe-s-t <≐> req <≐> sym-≐ oe-s'-t' ... | inj₂ req = inj₂ $ Conformant-all-intermediate frP₁ frS₁ frP₂ frS₂ conf oe-s-t <≐> req <≐> sym-≐ oe-s'-t' SC mr ._ init-s₀ frP₀ frPs₀ ._ (wᶜ-nof frP₂ frP₃) | t₀ , init-t₀ , t' , ._ , one {fr₁ = frS₀} frSs ._ (wᶜ-nof {all₂ = all₂} {all₃ = all₃} frS₂ frS₃) , (_ , oe-s-t , conf , oe-s'-t') = oe-s-t <≐> SpecSC-wᶜ-nof ⦃ all₂ ⦄ ⦃ all₃ ⦄ (proj₂ (lastr mr frS₀ frSs)) frS₂ frS₃ <≐> sym-≐ oe-s'-t' SC mr ._ init-s₀ frP₀ frPs₀ ._ (fᶜ-nof frP₂ frP₃) | t₀ , init-t₀ , t' , ._ , one frSs ._ (fᶜ-nof {all₂ = all₂} {all₃ = all₃} frS₂ frS₃) , (_ , oe-s-t , conf , oe-s'-t') with SpecSC-fᶜ-nof {{all₂}} {{all₃}} (proj₂ (lastr mr _ frSs)) frS₂ frS₃ ... | inj₁ req = inj₁ $ Conformant-all-intermediate frP₂ frS₂ ∅ ∅ conf oe-s-t <≐> req <≐> sym-≐ oe-s'-t' ... | inj₂ req = inj₂ $ oe-s-t <≐> req <≐> sym-≐ oe-s'-t'
{ "alphanum_fraction": 0.5047473287, "avg_line_length": 54.0321592649, "ext": "agda", "hexsha": "46cb5ae5eb20b27f8da99b0ff7286fa5bb331e23", "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": "c3ea3347071461241e3799e2cac46859e0bb64da", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yunshengtw/scftl", "max_forks_repo_path": "agda/SnapshotConsistency.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c3ea3347071461241e3799e2cac46859e0bb64da", "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": "yunshengtw/scftl", "max_issues_repo_path": "agda/SnapshotConsistency.agda", "max_line_length": 184, "max_stars_count": 2, "max_stars_repo_head_hexsha": "c3ea3347071461241e3799e2cac46859e0bb64da", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yunshengtw/scftl", "max_stars_repo_path": "agda/SnapshotConsistency.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-05T11:46:03.000Z", "max_stars_repo_stars_event_min_datetime": "2020-12-06T16:09:29.000Z", "num_tokens": 17149, "size": 35283 }
module IrrelevantModuleParameter .(A : Set) where postulate a : A -- cannot declare something of type A, since A is irrelevant
{ "alphanum_fraction": 0.7538461538, "avg_line_length": 26, "ext": "agda", "hexsha": "16442dc4106c0485e22f0945e4e16ca46a4b9851", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "masondesu/agda", "max_forks_repo_path": "test/fail/IrrelevantModuleParameter.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "masondesu/agda", "max_issues_repo_path": "test/fail/IrrelevantModuleParameter.agda", "max_line_length": 60, "max_stars_count": 1, "max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "asr/agda-kanso", "max_stars_repo_path": "test/fail/IrrelevantModuleParameter.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": 33, "size": 130 }
{-# OPTIONS --rewriting --prop --confluence-check --cumulativity #-} open import Agda.Primitive open import Agda.Builtin.Bool open import Agda.Builtin.Nat open import Agda.Builtin.List open import Agda.Builtin.Equality open import Agda.Builtin.Equality.Rewrite open import Agda.Builtin.Sigma open import Agda.Builtin.Unit open import Data.Vec.Base open import Data.Bool open import Data.Sum open import ett-rr {- Axiomatisation of the Cast calculus -} {- diagonal cases -} postulate cast : (A : Set ℓ) (B : Set ℓ₁) → A → B postulate cast-set : (A : Set ℓ) → cast (Set ℓ) (Set ℓ) A ≡ A {-# REWRITE cast-set #-} postulate cast-prop : (A : Prop ℓ) → cast (Prop ℓ) (Prop ℓ) A ≡ A {-# REWRITE cast-prop #-} postulate cast-Pi : (A : Set ℓ) (B : A → Set ℓ₁) (A' : Set ℓ₂) (B' : A' → Set ℓ₃) (f : (a : A) → B a) → cast ((a : A) → B a) ((a' : A') → B' a') f ≡ λ (a' : A') → cast _ _ (f (cast A' A a')) {-# REWRITE cast-Pi #-} postulate cast-Sigma : (A : Set ℓ) (B : A → Set ℓ₁) (A' : Set ℓ₂) (B' : A' → Set ℓ₃) (x : A) (y : B x) → cast (Σ A B) (Σ A' B') (x , y) ≡ (cast {ℓ = ℓ} {ℓ₁ = ℓ₂} A A' x , cast (B x) (B' (cast A A' x)) y) {-# REWRITE cast-Sigma #-} postulate cast-Sum-inj₁ : (A A' : Set ℓ) (B B' : Set ℓ₁) (a : A) → cast (A ⊎ B) (A' ⊎ B') (inj₁ a) ≡ inj₁ (cast A A' a) postulate cast-Sum-inj₂ : (A A' : Set ℓ) (B B' : Set ℓ₁) (b : B) → cast (A ⊎ B) (A' ⊎ B') (inj₂ b) ≡ inj₂ (cast B B' b) {-# REWRITE cast-Sum-inj₁ #-} {-# REWRITE cast-Sum-inj₂ #-} postulate cast-List-nil : (A A' : Set ℓ) → cast (List A) (List A') [] ≡ [] postulate cast-List-cons : (A A' : Set ℓ) (a : A) (l : List {a = ℓ} A) → cast (List A) (List {a = ℓ} A') (a ∷ l) ≡ cast A A' a ∷ cast (List A) (List A') l {-# REWRITE cast-List-nil #-} {-# REWRITE cast-List-cons #-} postulate cast-Nat-zero : cast Nat Nat 0 ≡ 0 postulate cast-Nat-suc : (n : Nat ) → cast Nat Nat (suc n) ≡ suc (cast _ _ n) {-# REWRITE cast-Nat-zero #-} {-# REWRITE cast-Nat-suc #-} postulate cast-Bool-true : cast Bool Bool true ≡ true {-# REWRITE cast-Bool-true #-} postulate cast-Bool-false : cast Bool Bool false ≡ false {-# REWRITE cast-Bool-false #-} postulate cast-Unit : cast ⊤ ⊤ tt ≡ tt {-# REWRITE cast-Unit #-} {- non-diagonal cases -} postulate cast-Set-bad : (A : Set (lsuc ℓ)) → cast (Set (lsuc ℓ)) (Set ℓ) A ≡ raise _ {-# REWRITE cast-Set-bad #-} postulate cast-raise : ∀ ℓ ℓ₁ → (A : Set ℓ₁) → cast (raise {ℓ = lsuc ℓ} (Set ℓ)) A (raise _) ≡ raise _ {-# REWRITE cast-raise #-} postulate cast-Pi-Sigma : (A A' : Set ℓ) (B : A → Set ℓ₁) (B' : A' → Set ℓ₁) (f : (a : A) → B a) → cast ((a : A) → B a) (Σ {a = ℓ} {b = ℓ₁} A' B') f ≡ raise (Σ A' B') {-# REWRITE cast-Pi-Sigma #-} postulate cast-Pi-Nat : (A : Set ℓ) (B : A → Set ℓ₁) (f : (a : A) → B a) → cast ((a : A) → B a) Nat f ≡ raise Nat {-# REWRITE cast-Pi-Nat #-} {- Rules specific to Unk -} postulate cast-Pi-Unk : (A : Set ℓ) (B : A → Set ℓ₁) (f : ((a : A) → B a)) → cast ((a : A) → B a) (Unk (ℓ ⊔ ℓ₁)) f ≡ box ((a : A) → B a) f postulate cast-Unk : (A : Set ℓ) (B : Set ℓ₁) (f : A) → cast (Unk ℓ) B (box A f) ≡ cast A B f postulate cast-Pi-Unk-bad : (f : Unk ℓ → Unk ℓ₁) → cast (Unk ℓ → Unk ℓ₁) (Unk (ℓ ⊔ ℓ₁)) f ≡ raise _ {-# REWRITE cast-Pi-Unk cast-Unk cast-Pi-Unk-bad #-} postulate cast-Sigma-Unk : (A : Set ℓ) (B : A → Set ℓ₁) (x : Σ {a = ℓ} {b = ℓ₁} A B) → cast (Σ A B) (Unk _) x ≡ box (Σ A B) x {-# REWRITE cast-Sigma-Unk #-} proj : {A : Set ℓ₁} → Unk ℓ → A proj {ℓ₁} {ℓ} {A} (box A' a') = cast {ℓ = ℓ} {ℓ₁ = ℓ₁} A' A a' delta : Unk ℓ → Unk ℓ delta {ℓ} x = proj {A = Unk ℓ → Unk ℓ} x x omega : Unk (lsuc ℓ) omega {ℓ} = delta {ℓ = lsuc ℓ} (box (Unk ℓ → Unk ℓ) (delta {ℓ = ℓ}))
{ "alphanum_fraction": 0.5095766129, "avg_line_length": 30.7596899225, "ext": "agda", "hexsha": "5bb261a50a201f2559261ddcd678a32bf27e7f28", "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": "77e54713836af48f5f8091373ae888feadc3d077", "max_forks_repo_licenses": [ "WTFPL" ], "max_forks_repo_name": "kyoDralliam/exceptional-tt", "max_forks_repo_path": "agda-rr/cast-cic.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "77e54713836af48f5f8091373ae888feadc3d077", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "WTFPL" ], "max_issues_repo_name": "kyoDralliam/exceptional-tt", "max_issues_repo_path": "agda-rr/cast-cic.agda", "max_line_length": 121, "max_stars_count": null, "max_stars_repo_head_hexsha": "77e54713836af48f5f8091373ae888feadc3d077", "max_stars_repo_licenses": [ "WTFPL" ], "max_stars_repo_name": "kyoDralliam/exceptional-tt", "max_stars_repo_path": "agda-rr/cast-cic.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1597, "size": 3968 }
module Issue293b where module M₁ (_ : Set₁) where postulate P : Set module M₂ (_ : Set) where open M₁ Set p : P p = {!!} -- Previous agda2-goal-and-context: -- ------------------------ -- Goal: M₁.P Set -- Current agda2-goal-and-context: -- ------------------------ -- Goal: P
{ "alphanum_fraction": 0.4836601307, "avg_line_length": 13.3043478261, "ext": "agda", "hexsha": "d4b84fb52504af09a90af3cfdf95496984d3676b", "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/Issue293b.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/Issue293b.agda", "max_line_length": 37, "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/Issue293b.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": 91, "size": 306 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Order morphisms ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} open import Relation.Binary.Core module Relation.Binary.Morphism where ------------------------------------------------------------------------ -- Re-export contents of morphisms open import Relation.Binary.Morphism.Definitions public open import Relation.Binary.Morphism.Structures public
{ "alphanum_fraction": 0.4554079696, "avg_line_length": 29.2777777778, "ext": "agda", "hexsha": "fbc6e85e277c088e7ee01846e78967a2bd4dac7b", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z", "max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "DreamLinuxer/popl21-artifact", "max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Morphism.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "DreamLinuxer/popl21-artifact", "max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Morphism.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/Relation/Binary/Morphism.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": 69, "size": 527 }
{- This second-order term syntax was created from the following second-order syntax description: syntax Monad | M type T : 1-ary term ret : α -> T α bind : T α α.(T β) -> T β | _>>=_ r10 theory (LU) a : α b : α.(T β) |> bind (ret(a), x. b[x]) = b[a] (RU) t : T α |> bind (t, x. ret(x)) = t (AS) t : T α b : α.(T β) c : β.(T γ) |> bind (bind (t, x.b[x]), y.c[y]) = bind (t, x. bind (b[x], y.c[y])) -} module Monad.Syntax where open import SOAS.Common open import SOAS.Context open import SOAS.Variable open import SOAS.Families.Core open import SOAS.Construction.Structure open import SOAS.ContextMaps.Inductive open import SOAS.Metatheory.Syntax open import Monad.Signature private variable Γ Δ Π : Ctx α β : MT 𝔛 : Familyₛ -- Inductive term declaration module M:Terms (𝔛 : Familyₛ) where data M : Familyₛ where var : ℐ ⇾̣ M mvar : 𝔛 α Π → Sub M Π Γ → M α Γ ret : M α Γ → M (T α) Γ _>>=_ : M (T α) Γ → M (T β) (α ∙ Γ) → M (T β) Γ infixr 10 _>>=_ open import SOAS.Metatheory.MetaAlgebra ⅀F 𝔛 Mᵃ : MetaAlg M Mᵃ = record { 𝑎𝑙𝑔 = λ where (retₒ ⋮ a) → ret a (bindₒ ⋮ a , b) → _>>=_ a b ; 𝑣𝑎𝑟 = var ; 𝑚𝑣𝑎𝑟 = λ 𝔪 mε → mvar 𝔪 (tabulate mε) } module Mᵃ = MetaAlg Mᵃ module _ {𝒜 : Familyₛ}(𝒜ᵃ : MetaAlg 𝒜) where open MetaAlg 𝒜ᵃ 𝕤𝕖𝕞 : M ⇾̣ 𝒜 𝕊 : Sub M Π Γ → Π ~[ 𝒜 ]↝ Γ 𝕊 (t ◂ σ) new = 𝕤𝕖𝕞 t 𝕊 (t ◂ σ) (old v) = 𝕊 σ v 𝕤𝕖𝕞 (mvar 𝔪 mε) = 𝑚𝑣𝑎𝑟 𝔪 (𝕊 mε) 𝕤𝕖𝕞 (var v) = 𝑣𝑎𝑟 v 𝕤𝕖𝕞 (ret a) = 𝑎𝑙𝑔 (retₒ ⋮ 𝕤𝕖𝕞 a) 𝕤𝕖𝕞 (_>>=_ a b) = 𝑎𝑙𝑔 (bindₒ ⋮ 𝕤𝕖𝕞 a , 𝕤𝕖𝕞 b) 𝕤𝕖𝕞ᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ 𝕤𝕖𝕞 𝕤𝕖𝕞ᵃ⇒ = record { ⟨𝑎𝑙𝑔⟩ = λ{ {t = t} → ⟨𝑎𝑙𝑔⟩ t } ; ⟨𝑣𝑎𝑟⟩ = refl ; ⟨𝑚𝑣𝑎𝑟⟩ = λ{ {𝔪 = 𝔪}{mε} → cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-tab mε)) } } where open ≡-Reasoning ⟨𝑎𝑙𝑔⟩ : (t : ⅀ M α Γ) → 𝕤𝕖𝕞 (Mᵃ.𝑎𝑙𝑔 t) ≡ 𝑎𝑙𝑔 (⅀₁ 𝕤𝕖𝕞 t) ⟨𝑎𝑙𝑔⟩ (retₒ ⋮ _) = refl ⟨𝑎𝑙𝑔⟩ (bindₒ ⋮ _) = refl 𝕊-tab : (mε : Π ~[ M ]↝ Γ)(v : ℐ α Π) → 𝕊 (tabulate mε) v ≡ 𝕤𝕖𝕞 (mε v) 𝕊-tab mε new = refl 𝕊-tab mε (old v) = 𝕊-tab (mε ∘ old) v module _ (g : M ⇾̣ 𝒜)(gᵃ⇒ : MetaAlg⇒ Mᵃ 𝒜ᵃ g) where open MetaAlg⇒ gᵃ⇒ 𝕤𝕖𝕞! : (t : M α Γ) → 𝕤𝕖𝕞 t ≡ g t 𝕊-ix : (mε : Sub M Π Γ)(v : ℐ α Π) → 𝕊 mε v ≡ g (index mε v) 𝕊-ix (x ◂ mε) new = 𝕤𝕖𝕞! x 𝕊-ix (x ◂ mε) (old v) = 𝕊-ix mε v 𝕤𝕖𝕞! (mvar 𝔪 mε) rewrite cong (𝑚𝑣𝑎𝑟 𝔪) (dext (𝕊-ix mε)) = trans (sym ⟨𝑚𝑣𝑎𝑟⟩) (cong (g ∘ mvar 𝔪) (tab∘ix≈id mε)) 𝕤𝕖𝕞! (var v) = sym ⟨𝑣𝑎𝑟⟩ 𝕤𝕖𝕞! (ret a) rewrite 𝕤𝕖𝕞! a = sym ⟨𝑎𝑙𝑔⟩ 𝕤𝕖𝕞! (_>>=_ a b) rewrite 𝕤𝕖𝕞! a | 𝕤𝕖𝕞! b = sym ⟨𝑎𝑙𝑔⟩ -- Syntax instance for the signature M:Syn : Syntax M:Syn = record { ⅀F = ⅀F ; ⅀:CS = ⅀:CompatStr ; mvarᵢ = M:Terms.mvar ; 𝕋:Init = λ 𝔛 → let open M:Terms 𝔛 in record { ⊥ = M ⋉ Mᵃ ; ⊥-is-initial = record { ! = λ{ {𝒜 ⋉ 𝒜ᵃ} → 𝕤𝕖𝕞 𝒜ᵃ ⋉ 𝕤𝕖𝕞ᵃ⇒ 𝒜ᵃ } ; !-unique = λ{ {𝒜 ⋉ 𝒜ᵃ} (f ⋉ fᵃ⇒) {x = t} → 𝕤𝕖𝕞! 𝒜ᵃ f fᵃ⇒ t } } } } -- Instantiation of the syntax and metatheory open Syntax M:Syn public open M:Terms public open import SOAS.Families.Build public open import SOAS.Syntax.Shorthands Mᵃ public open import SOAS.Metatheory M:Syn public
{ "alphanum_fraction": 0.5270312994, "avg_line_length": 25.5080645161, "ext": "agda", "hexsha": "2058e722fdc8e34f529787309d8d6b1e90c4fbfb", "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": "out/Monad/Syntax.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": "out/Monad/Syntax.agda", "max_line_length": 110, "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": "out/Monad/Syntax.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": 1939, "size": 3163 }
------------------------------------------------------------------------ -- The Agda standard library -- -- A type for expressions over a raw ring. ------------------------------------------------------------------------ {-# OPTIONS --without-K --safe #-} module Tactic.RingSolver.Core.Expression where open import Data.Nat.Base using (ℕ) open import Data.Fin.Base using (Fin) open import Data.Vec.Base as Vec using (Vec) open import Algebra infixl 6 _⊕_ infixl 7 _⊗_ infixr 8 _⊛_ data Expr {a} (A : Set a) (n : ℕ) : Set a where Κ : A → Expr A n -- Constant Ι : Fin n → Expr A n -- Variable _⊕_ : Expr A n → Expr A n → Expr A n -- Addition _⊗_ : Expr A n → Expr A n → Expr A n -- Multiplication _⊛_ : Expr A n → ℕ → Expr A n -- Exponentiation ⊝_ : Expr A n → Expr A n -- Negation module Eval {ℓ₁ ℓ₂} (rawRing : RawRing ℓ₁ ℓ₂) (let open RawRing rawRing) {a} {A : Set a} (⟦_⟧ᵣ : A → Carrier) where open import Algebra.Operations.Ring rawRing ⟦_⟧ : ∀ {n} → Expr A n → Vec Carrier n → Carrier ⟦ Κ x ⟧ ρ = ⟦ x ⟧ᵣ ⟦ Ι x ⟧ ρ = Vec.lookup ρ x ⟦ x ⊕ y ⟧ ρ = ⟦ x ⟧ ρ + ⟦ y ⟧ ρ ⟦ x ⊗ y ⟧ ρ = ⟦ x ⟧ ρ * ⟦ y ⟧ ρ ⟦ ⊝ x ⟧ ρ = - ⟦ x ⟧ ρ ⟦ x ⊛ i ⟧ ρ = ⟦ x ⟧ ρ ^ i
{ "alphanum_fraction": 0.4792332268, "avg_line_length": 28.4545454545, "ext": "agda", "hexsha": "a4dc817a1667939368a697fc417a9b216370b37b", "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/Tactic/RingSolver/Core/Expression.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/Tactic/RingSolver/Core/Expression.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/Tactic/RingSolver/Core/Expression.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": 471, "size": 1252 }
{-# OPTIONS --cubical #-} module Exercises where open import Part2 open import Part3 open import Part4 open import Part5
{ "alphanum_fraction": 0.7704918033, "avg_line_length": 15.25, "ext": "agda", "hexsha": "18592afb355e366aded400b98ebf16b5bf5e8b24", "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": "54b18e4adf890b3533bbefda373912423be7f490", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "tomdjong/EPIT-2020", "max_forks_repo_path": "04-cubical-type-theory/material/ExerciseSession3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "54b18e4adf890b3533bbefda373912423be7f490", "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": "tomdjong/EPIT-2020", "max_issues_repo_path": "04-cubical-type-theory/material/ExerciseSession3.agda", "max_line_length": 25, "max_stars_count": null, "max_stars_repo_head_hexsha": "54b18e4adf890b3533bbefda373912423be7f490", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "tomdjong/EPIT-2020", "max_stars_repo_path": "04-cubical-type-theory/material/ExerciseSession3.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 31, "size": 122 }
-- Some basic structures and operations for dealing -- with non-deterministic values. -- -- @author Sergio Antoy, Michael Hanus, Steven Libby module nondet where open import bool open import nat open import list infixr 8 _??_ ---------------------------------------------------------------------- -- A tree datatype to represent a non-deterministic value of some type. -- It is either a value or a choice between non-deterministic values. ---------------------------------------------------------------------- data ND (A : Set) : Set where Val : A → ND A _??_ : ND A → ND A → ND A ---------------------------------------------------------------------- -- Some operations to define functions working this the ND datatype: -- Apply a (deterministic) function to a non-deterministic argument. -- This corresponds to a functor on the ND structure. _$*_ : {A B : Set} → (A → B) → ND A → ND B f $* (Val xs) = Val (f xs) f $* (t1 ?? t2) = f $* t1 ?? f $* t2 -- Apply a non-deterministic function to a non-deterministic argument. -- If ND would be an instance of the monad class, this is a monadic bind -- with swapped arguments. _*$*_ : {A B : Set} → (A → ND B) → ND A → ND B f *$* (Val x) = f x f *$* (t1 ?? t2) = f *$* t1 ?? f *$* t2 -- Apply a binary non-deterministic function to non-deterministic arguments. apply-nd2 : {A B C : Set} → (A → B → ND C) → ND A → ND B → ND C apply-nd2 f a b = (λ x -> (λ y -> f x y) *$* b) *$* a -- Apply a ternary non-deterministic function to non-deterministic arguments. apply-nd3 : {A B C D : Set} → (A → B → C → ND D) → ND A → ND B → ND C → ND D apply-nd3 f a b c = (λ x -> (λ y -> (λ z → f x y z) *$* c) *$* b) *$* a -- Extend a deterministic function to one with non-deterministic result: toND : {A B : Set} → (A → B) → A → ND B toND f x = Val (f x) ---------------------------------------------------------------------- -- Some operations to define properties of non-deterministic values: -- Count the number of values: #vals : {A : Set} → ND A → ℕ #vals (Val _) = 1 #vals (t1 ?? t2) = #vals t1 + #vals t2 -- Extract the list of all values: vals-of : {A : Set} → ND A → 𝕃 A vals-of (Val v) = v :: [] vals-of (t1 ?? t2) = vals-of t1 ++ vals-of t2 -- All values in a Boolean tree are true: always : ND 𝔹 → 𝔹 always (Val b) = b always (t1 ?? t2) = always t1 && always t2 -- There exists some true value in a Boolean tree: eventually : ND 𝔹 → 𝔹 eventually (Val b) = b eventually (t1 ?? t2) = eventually t1 || eventually t2 -- All non-deterministic values satisfy a given predicate: _satisfy_ : {A : Set} → ND A → (A → 𝔹) → 𝔹 (Val n) satisfy p = p n (t1 ?? t2) satisfy p = t1 satisfy p && t2 satisfy p -- Every value in a tree is equal to the second argument w.r.t. a -- comparison function provided as the first argument: every : {A : Set} → (eq : A → A → 𝔹) → A → ND A → 𝔹 every eq x xs = xs satisfy (eq x) ----------------------------------------------------------------------
{ "alphanum_fraction": 0.5474576271, "avg_line_length": 34.7058823529, "ext": "agda", "hexsha": "f20a7bb494c37a901276600a0524dfec470260a9", "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": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "mihanus/curry-agda", "max_forks_repo_path": "nondet/nondet.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "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": "mihanus/curry-agda", "max_issues_repo_path": "nondet/nondet.agda", "max_line_length": 77, "max_stars_count": null, "max_stars_repo_head_hexsha": "b7cfdda11cdadeba882b6b72d75448acd8b0a294", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "mihanus/curry-agda", "max_stars_repo_path": "nondet/nondet.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 901, "size": 2950 }
open import Agda.Builtin.Equality module _ (A : Set) where data Wrap (X : Set) : Set where wrap : X → Wrap X data D (x : A) : ∀ y → Wrap (x ≡ y) → Set where c : ∀ y (x≡y : x ≡ y) → D x y (wrap x≡y) test : ∀ x y (x≡y x≡y' : Wrap (x ≡ y)) → D x y x≡y → D x y x≡y' → Set test y .y (wrap refl) .(wrap refl) (c .y .refl) (c .y refl) = A
{ "alphanum_fraction": 0.5176470588, "avg_line_length": 26.1538461538, "ext": "agda", "hexsha": "7d85ccc2ea8d32a51210307571b495b206b0b90c", "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/Issue4081.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/Issue4081.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/Succeed/Issue4081.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": 159, "size": 340 }
------------------------------------------------------------------------ -- INCREMENTAL λ-CALCULUS -- -- Environments -- -- This module defines the meaning of contexts, that is, -- the type of environments that fit a context, together -- with operations and properties of these operations. -- -- This module is parametric in the syntax and semantics -- of types, so it can be reused for different calculi -- and models. ------------------------------------------------------------------------ module Base.Denotation.Environment (Type : Set) {ℓ} (⟦_⟧Type : Type → Set ℓ) where open import Relation.Binary.PropositionalEquality open import Base.Syntax.Context Type open import Base.Denotation.Notation open import Base.Data.DependentList as DependentList private instance meaningOfType : Meaning Type meaningOfType = meaning ⟦_⟧Type ⟦_⟧Context : Context → Set ℓ ⟦_⟧Context = DependentList ⟦_⟧Type instance meaningOfContext : Meaning Context meaningOfContext = meaning ⟦_⟧Context -- VARIABLES -- Denotational Semantics ⟦_⟧Var : ∀ {Γ τ} → Var Γ τ → ⟦ Γ ⟧ → ⟦ τ ⟧ ⟦ this ⟧Var (v • ρ) = v ⟦ that x ⟧Var (v • ρ) = ⟦ x ⟧Var ρ instance meaningOfVar : ∀ {Γ τ} → Meaning (Var Γ τ) meaningOfVar = meaning ⟦_⟧Var -- WEAKENING -- Remove a variable from an environment ⟦_⟧≼ : ∀ {Γ₁ Γ₂} → (Γ′ : Γ₁ ≼ Γ₂) → ⟦ Γ₂ ⟧ → ⟦ Γ₁ ⟧ ⟦ ∅ ⟧≼ ∅ = ∅ ⟦ keep τ • Γ′ ⟧≼ (v • ρ) = v • ⟦ Γ′ ⟧≼ ρ ⟦ drop τ • Γ′ ⟧≼ (v • ρ) = ⟦ Γ′ ⟧≼ ρ instance meaningOf≼ : ∀ {Γ₁ Γ₂} → Meaning (Γ₁ ≼ Γ₂) meaningOf≼ = meaning ⟦_⟧≼ -- Properties ⟦∅≼Γ⟧-∅ : ∀ {Γ} ρ → ⟦ ∅≼Γ {Γ = Γ} ⟧≼ ρ ≡ ∅ ⟦∅≼Γ⟧-∅ {∅} ∅ = refl ⟦∅≼Γ⟧-∅ {x • Γ} (v • ρ) = ⟦∅≼Γ⟧-∅ ρ ⟦⟧-≼-trans : ∀ {Γ₃ Γ₁ Γ₂} → (Γ′ : Γ₁ ≼ Γ₂) (Γ″ : Γ₂ ≼ Γ₃) → ∀ (ρ : ⟦ Γ₃ ⟧) → ⟦_⟧ {{meaningOf≼}} (≼-trans Γ′ Γ″) ρ ≡ ⟦_⟧ {{meaningOf≼}} Γ′ (⟦_⟧ {{meaningOf≼}} Γ″ ρ) ⟦⟧-≼-trans Γ′ ∅ ∅ = refl ⟦⟧-≼-trans (keep τ • Γ′) (keep .τ • Γ″) (v • ρ) = cong₂ _•_ refl (⟦⟧-≼-trans Γ′ Γ″ ρ) ⟦⟧-≼-trans (drop τ • Γ′) (keep .τ • Γ″) (v • ρ) = ⟦⟧-≼-trans Γ′ Γ″ ρ ⟦⟧-≼-trans Γ′ (drop τ • Γ″) (v • ρ) = ⟦⟧-≼-trans Γ′ Γ″ ρ ⟦⟧-≼-refl : ∀ {Γ : Context} → ∀ (ρ : ⟦ Γ ⟧) → ⟦_⟧ {{meaningOf≼}} ≼-refl ρ ≡ ρ ⟦⟧-≼-refl {∅} ∅ = refl ⟦⟧-≼-refl {τ • Γ} (v • ρ) = cong₂ _•_ refl (⟦⟧-≼-refl ρ) -- SOUNDNESS of variable lifting weaken-var-sound : ∀ {Γ₁ Γ₂ τ} (Γ′ : Γ₁ ≼ Γ₂) (x : Var Γ₁ τ) → ∀ (ρ : ⟦ Γ₂ ⟧) → ⟦_⟧ {{meaningOfVar}} (weaken-var Γ′ x) ρ ≡ ⟦_⟧ {{meaningOfVar}} x ( ⟦_⟧ {{meaningOf≼}} Γ′ ρ) weaken-var-sound ∅ () ρ weaken-var-sound (keep τ • Γ′) this (v • ρ) = refl weaken-var-sound (keep τ • Γ′) (that x) (v • ρ) = weaken-var-sound Γ′ x ρ weaken-var-sound (drop τ • Γ′) this (v • ρ) = weaken-var-sound Γ′ this ρ weaken-var-sound (drop τ • Γ′) (that x) (v • ρ) = weaken-var-sound Γ′ (that x) ρ
{ "alphanum_fraction": 0.5306872473, "avg_line_length": 29.9010989011, "ext": "agda", "hexsha": "d82fa6a5da108d08a4d7ddf09597bd3301803cfe", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z", "max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "inc-lc/ilc-agda", "max_forks_repo_path": "Base/Denotation/Environment.agda", "max_issues_count": 6, "max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z", "max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "inc-lc/ilc-agda", "max_issues_repo_path": "Base/Denotation/Environment.agda", "max_line_length": 112, "max_stars_count": 10, "max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "inc-lc/ilc-agda", "max_stars_repo_path": "Base/Denotation/Environment.agda", "max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z", "max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z", "num_tokens": 1268, "size": 2721 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Comonads ------------------------------------------------------------------------ -- Note that currently the monad laws are not included here. {-# OPTIONS --without-K --safe #-} module Category.Comonad where open import Level open import Function private variable a b c f : Level A : Set a B : Set b C : Set c record RawComonad (W : Set f → Set f) : Set (suc f) where infixl 1 _=>>_ _=>=_ infixr 1 _<<=_ _=<=_ field extract : W A → A extend : (W A → B) → (W A → W B) duplicate : W A → W (W A) duplicate = extend id liftW : (A → B) → W A → W B liftW f = extend (f ∘′ extract) _=>>_ : W A → (W A → B) → W B _=>>_ = flip extend _=>=_ : (W A → B) → (W B → C) → W A → C f =>= g = g ∘′ extend f _<<=_ : (W A → B) → W A → W B _<<=_ = extend _=<=_ : (W B → C) → (W A → B) → W A → C _=<=_ = flip _=>=_
{ "alphanum_fraction": 0.433127572, "avg_line_length": 19.8367346939, "ext": "agda", "hexsha": "077ff043d05a33f27f7a4bb747330f5e04af4183", "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/Category/Comonad.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/Category/Comonad.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/Category/Comonad.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": 330, "size": 972 }
------------------------------------------------------------------------ -- Alternative definitions of weak bisimilarity ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} open import Prelude module Delay-monad.Bisimilarity.Alternative {a} {A : Type a} where open import Equality.Propositional as E open import Logical-equivalence using (_⇔_) open import Prelude.Size open import Function-universe equality-with-J hiding (_∘_) open import H-level equality-with-J open import H-level.Closure equality-with-J open import Delay-monad open import Delay-monad.Bisimilarity open import Delay-monad.Termination -- An alternative definition of weak bisimilarity (discussed by -- Capretta in "General Recursion via Coinductive Types", and -- basically the one used in the paper "Partiality, Revisited: The -- Partiality Monad as a Quotient Inductive-Inductive Type" by -- Altenkirch, Danielsson and Kraus). -- -- This definition is pointwise logically equivalent to the one above, -- see Delay-monad.Partial-order.≈⇔≈₂. infix 4 _≈₂_ _≈₂_ : Delay A ∞ → Delay A ∞ → Type a x ≈₂ y = ∀ z → x ⇓ z ⇔ y ⇓ z -- If A is a set, then this alternative definition of weak -- bisimilarity is propositional (assuming extensionality), unlike _≈_ -- (see Delay-monad.Bisimilarity.¬-≳≈-propositional). ≈₂-propositional : E.Extensionality a a → Is-set A → ∀ {x y} → Is-proposition (x ≈₂ y) ≈₂-propositional ext A-set = Π-closure ext 1 λ _ → ⇔-closure ext 1 (Terminates-propositional A-set) (Terminates-propositional A-set) -- Another alternative definition of weak bisimilarity, basically the -- one given by Capretta in "General Recursion via Coinductive Types". infix 4 [_]_≈₃_ [_]_≈₃′_ _≈₃_ mutual data [_]_≈₃_ (i : Size) : Delay A ∞ → Delay A ∞ → Type a where both-terminate : ∀ {x y v} → x ⇓ v → y ⇓ v → [ i ] x ≈₃ y later : ∀ {x y} → [ i ] force x ≈₃′ force y → [ i ] later x ≈₃ later y record [_]_≈₃′_ (i : Size) (x y : Delay A ∞) : Type a where coinductive field force : {j : Size< i} → [ j ] x ≈₃ y open [_]_≈₃′_ public _≈₃_ : Delay A ∞ → Delay A ∞ → Type a _≈₃_ = [ ∞ ]_≈₃_ -- If A is inhabited, then this definition is not propositional. ¬-≈₃-propositional : A → ¬ (∀ {x y} → Is-proposition (x ≈₃ y)) ¬-≈₃-propositional x = (∀ {x y} → Is-proposition (x ≈₃ y)) ↝⟨ (λ prop → prop) ⟩ Is-proposition (y ≈₃ y) ↝⟨ (_$ _) ∘ (_$ _) ⟩ proof₁ ≡ proof₂ ↝⟨ (λ ()) ⟩□ ⊥ □ where y : Delay A ∞ y = later λ { .force → now x } proof₁ : y ≈₃ y proof₁ = both-terminate (laterʳ now) (laterʳ now) proof₂ : y ≈₃ y proof₂ = later λ { .force → both-terminate now now } -- The last definition of weak bisimilarity given above is pointwise -- logically equivalent to _≈_. Note that the proof is -- size-preserving. -- -- (Given suitable notions of extensionality the two definitions are -- not pointwise isomorphic, because given such assumptions there is -- only one proof of never ≈₃ never, but multiple proofs of -- never ≈ never. However, there is no Agda proof of this claim in -- this module.) ≈⇔≈₃ : ∀ {i x y} → [ i ] x ≈ y ⇔ [ i ] x ≈₃ y ≈⇔≈₃ = record { to = to; from = from } where mutual laterˡ′ : ∀ {i x x′ y} → x′ ≡ force x → [ i ] x′ ≈₃ y → [ i ] later x ≈₃ y laterˡ′ eq (both-terminate x⇓ y⇓) = both-terminate (laterʳ (subst (_⇓ _) eq x⇓)) y⇓ laterˡ′ eq (later p) = later (laterˡ″ eq p) laterˡ″ : ∀ {i x x′ y} → later x′ ≡ x → [ i ] force x′ ≈₃′ y → [ i ] x ≈₃′ y force (laterˡ″ refl p) = laterˡ′ refl (force p) mutual laterʳ′ : ∀ {i x y y′} → y′ ≡ force y → [ i ] x ≈₃ y′ → [ i ] x ≈₃ later y laterʳ′ eq (both-terminate x⇓ y⇓) = both-terminate x⇓ (laterʳ (subst (_⇓ _) eq y⇓)) laterʳ′ eq (later p) = later (laterʳ″ eq p) laterʳ″ : ∀ {i x y y′} → later y′ ≡ y → [ i ] x ≈₃′ force y′ → [ i ] x ≈₃′ y force (laterʳ″ refl p) = laterʳ′ refl (force p) to : ∀ {i x y} → [ i ] x ≈ y → [ i ] x ≈₃ y to now = both-terminate now now to (later p) = later λ { .force → to (force p) } to (laterˡ p) = laterˡ′ refl (to p) to (laterʳ p) = laterʳ′ refl (to p) from⇓ : ∀ {i x y v} → x ⇓ v → y ⇓ v → [ i ] x ≈ y from⇓ now now = now from⇓ p (laterʳ q) = laterʳ (from⇓ p q) from⇓ (laterʳ p) q = laterˡ (from⇓ p q) from : ∀ {i x y} → [ i ] x ≈₃ y → [ i ] x ≈ y from (both-terminate x⇓v y⇓v) = from⇓ x⇓v y⇓v from (later p) = later λ { .force → from (force p) }
{ "alphanum_fraction": 0.5289637202, "avg_line_length": 33.0397350993, "ext": "agda", "hexsha": "62934c294ec999a6f0ccfba6384c2a9a86b287d8", "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": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/delay-monad", "max_forks_repo_path": "src/Delay-monad/Bisimilarity/Alternative.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/delay-monad", "max_issues_repo_path": "src/Delay-monad/Bisimilarity/Alternative.agda", "max_line_length": 72, "max_stars_count": null, "max_stars_repo_head_hexsha": "495f9996673d0f1f34ce202902daaa6c39f8925e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/delay-monad", "max_stars_repo_path": "src/Delay-monad/Bisimilarity/Alternative.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1745, "size": 4989 }
open import prelude -- Copied pretty much verbatim data Term : Set where true : Term false : Term if_then_else_end : Term → Term → Term → Term data Value : Term → Set where true : Value true false : Value false data _⟶_ : Term → Term → Set where E─IfTrue : ∀ {t₂ t₃} → ----------------------------------- if true then t₂ else t₃ end ⟶ t₂ E─IfFalse : ∀ {t₂ t₃} → ----------------------------------- if false then t₂ else t₃ end ⟶ t₃ E─IfCong : ∀ {t₁ t₁′ t₂ t₃} → (t₁ ⟶ t₁′) → ---------------------------------------------------------- (if t₁ then t₂ else t₃ end ⟶ if t₁′ then t₂ else t₃ end) data Redex : Term → Set where redex : ∀ {t t′} → t ⟶ t′ → -------- Redex(t) -- Proving that every term is a value or a redex data ValueOrRedex : Term → Set where value : ∀ {t} → (Value(t)) → --------------- ValueOrRedex(t) redex : ∀ {t t′} → t ⟶ t′ → --------------- ValueOrRedex(t) valueOrRedex : (t : Term) → ValueOrRedex(t) valueOrRedex true = value true valueOrRedex false = value false valueOrRedex if t₀ then t₁ else t₂ end = helper (valueOrRedex t₀) where helper : ∀ {t₀ t₁ t₂} → ValueOrRedex(t₀) → ValueOrRedex(if t₀ then t₁ else t₂ end) helper (value true) = redex E─IfTrue helper (value false) = redex E─IfFalse helper (redex r) = redex (E─IfCong r) -- From which we get some of the theorems in the book NormalForm : Term → Set NormalForm(t) = Redex(t) → FALSE thm357 : ∀ {t} → Value(t) → NormalForm(t) thm357 true (redex ()) thm357 false (redex ()) thm358 : ∀ {t} → NormalForm(t) → Value(t) thm358 {t} nf = helper (valueOrRedex t) nf where helper : ∀ {t} → ValueOrRedex(t) → NormalForm(t) → Value(t) helper (value v) nf = v helper (redex r) nf = CONTRADICTION (nf (redex r)) -- But also we can buid an interpreter. data _⟶*_ : Term → Term → Set where done : ∀ {t} → -------- t ⟶* t redex : ∀ {t t′ t″} → t ⟶ t′ → t′ ⟶* t″ → ---------- t ⟶* t″ -- An interpreter result data Result : Term → Set where result : ∀ {t t′} → t ⟶* t′ → Value(t′) → --------- Result(t) -- The interpreter just calls `valueOrRedex` until it is a value. -- This might bot terminate! {-# NON_TERMINATING #-} interp : (t : Term) → Result(t) interp t = helper₂ (valueOrRedex t) where helper₁ : ∀ {t t′} → (t ⟶ t′) → Result(t′) → Result(t) helper₁ r (result s v) = result (redex r s) v helper₂ : ∀ {t} → ValueOrRedex(t) → Result(t) helper₂ (value v) = result done v helper₂ (redex {t} {t′} r) = helper₁ r (interp t′) -- Examples not : Term → Term not(t) = if t then false else true end _and_ : Term → Term → Term s and t = if s then t else false end _or_ : Term → Term → Term s or t = if s then true else t end ex : Term ex = (true and false) or (not true) -- Try normalizing (CTRL-C CTRL-N) `interp ex` -- you get told the result but also the derivation tree for every step! -- ``` -- result -- (redex (E─IfCong E─IfTrue) -- (redex E─IfFalse -- (redex E─IfTrue -- done))) -- false -- ```
{ "alphanum_fraction": 0.5556274256, "avg_line_length": 21.0340136054, "ext": "agda", "hexsha": "74e9cbc96437610b7410c82cdf2da149e896b37a", "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": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_forks_repo_licenses": [ "CC0-1.0" ], "max_forks_repo_name": "asajeffrey/tapl", "max_forks_repo_path": "ch3.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "CC0-1.0" ], "max_issues_repo_name": "asajeffrey/tapl", "max_issues_repo_path": "ch3.agda", "max_line_length": 84, "max_stars_count": 3, "max_stars_repo_head_hexsha": "de2ae6c24d001b85a5032c9e06cc731557dbc5e5", "max_stars_repo_licenses": [ "CC0-1.0" ], "max_stars_repo_name": "asajeffrey/tapl", "max_stars_repo_path": "ch3.agda", "max_stars_repo_stars_event_max_datetime": "2021-03-15T12:09:59.000Z", "max_stars_repo_stars_event_min_datetime": "2021-03-12T22:44:19.000Z", "num_tokens": 1071, "size": 3092 }
{-# OPTIONS --safe #-} module Cubical.Algebra.Polynomials.Multivariate.Base where open import Cubical.Algebra.CommRing.Instances.Polynomials.MultivariatePoly public {- The Multivariate Polynomials of size n over a CommRing A is a CommRing. This version is define as an instance of the more general constructions of gradedRing. This done by defing Poly A n = ⊕HIT_{Vec A n} A where ⊕HIT is the HIT direct sum. Then raising the _·_ to Poly A n. See : -} open import Cubical.Algebra.GradedRing.DirectSumHIT {- This is define very shortly as a CommRing Instances calling a general makeGradedRing functions. And by proving the additional properties that the _·_ is commutative. Hence the absence of real Base and Properties files. Some more properties that are comming from the definition using the ⊕HIT can be found in the DirectSumHIT file such as eliminator. -} open import Cubical.Algebra.DirectSum.DirectSumHIT.Base
{ "alphanum_fraction": 0.7926565875, "avg_line_length": 30.8666666667, "ext": "agda", "hexsha": "c098db6940f9ffdb6bbdac8662831e046a87e985", "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/Polynomials/Multivariate/Base.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/Polynomials/Multivariate/Base.agda", "max_line_length": 95, "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/Polynomials/Multivariate/Base.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 228, "size": 926 }
{-# OPTIONS --without-K #-} open import HoTT open import cohomology.Exactness open import cohomology.Theory module cohomology.Sn {i} (OT : OrdinaryTheory i) where open OrdinaryTheory OT C-Sphere-≠ : (n : ℤ) (m : ℕ) → (n ≠ ℕ-to-ℤ m) → C n (⊙Lift (⊙Sphere m)) == Lift-Unit-group C-Sphere-≠ n O neq = C-dimension n neq C-Sphere-≠ n (S m) neq = C n (⊙Lift (⊙Sphere (S m))) =⟨ ! $ ⊙Susp-⊙Lift (⊙Sphere m) |in-ctx C n ⟩ C n (⊙Susp (⊙Lift (⊙Sphere m))) =⟨ ! (succ-pred n) |in-ctx (λ k → C k (⊙Susp (⊙Lift (⊙Sphere m)))) ⟩ C (succ (pred n)) (⊙Susp (⊙Lift (⊙Sphere m))) =⟨ group-ua (C-Susp (pred n) (⊙Lift (⊙Sphere m))) ⟩ C (pred n) (⊙Lift (⊙Sphere m)) =⟨ C-Sphere-≠ (pred n) m (λ p → neq (pred-injective n (ℕ-to-ℤ (S m)) p)) ⟩ Lift-Unit-group ∎ C-Sphere-diag : (m : ℕ) → C (ℕ-to-ℤ m) (⊙Lift (⊙Sphere m)) == C 0 (⊙Lift ⊙S⁰) C-Sphere-diag O = idp C-Sphere-diag (S m) = C (ℕ-to-ℤ (S m)) (⊙Lift (⊙Sphere (S m))) =⟨ ! $ ⊙Susp-⊙Lift (⊙Sphere m) |in-ctx C (ℕ-to-ℤ (S m)) ⟩ C (ℕ-to-ℤ (S m)) (⊙Susp (⊙Lift (⊙Sphere m))) =⟨ group-ua (C-Susp (ℕ-to-ℤ m) (⊙Lift (⊙Sphere m))) ⟩ C (ℕ-to-ℤ m) (⊙Lift (⊙Sphere m)) =⟨ C-Sphere-diag m ⟩ C 0 (⊙Lift ⊙S⁰) ∎
{ "alphanum_fraction": 0.5327731092, "avg_line_length": 32.1621621622, "ext": "agda", "hexsha": "76fcca1a137dc97cf374e063f3af451cbb254c66", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "theorems/cohomology/Sn.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_path": "theorems/cohomology/Sn.agda", "max_line_length": 78, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "theorems/cohomology/Sn.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 638, "size": 1190 }
------------------------------------------------------------------------ -- The Agda standard library -- -- Vectors ------------------------------------------------------------------------ module Data.Vec where open import Category.Applicative open import Data.Nat open import Data.Fin using (Fin; zero; suc) open import Data.List as List using (List) open import Data.Product as Prod using (∃; ∃₂; _×_; _,_) open import Function open import Relation.Binary.PropositionalEquality using (_≡_; refl) ------------------------------------------------------------------------ -- Types infixr 5 _∷_ data Vec {a} (A : Set a) : ℕ → Set a where [] : Vec A zero _∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (suc n) infix 4 _∈_ data _∈_ {a} {A : Set a} : A → {n : ℕ} → Vec A n → Set a where here : ∀ {n} {x} {xs : Vec A n} → x ∈ x ∷ xs there : ∀ {n} {x y} {xs : Vec A n} (x∈xs : x ∈ xs) → x ∈ y ∷ xs infix 4 _[_]=_ data _[_]=_ {a} {A : Set a} : {n : ℕ} → Vec A n → Fin n → A → Set a where here : ∀ {n} {x} {xs : Vec A n} → x ∷ xs [ zero ]= x there : ∀ {n} {i} {x y} {xs : Vec A n} (xs[i]=x : xs [ i ]= x) → y ∷ xs [ suc i ]= x ------------------------------------------------------------------------ -- Some operations head : ∀ {a n} {A : Set a} → Vec A (1 + n) → A head (x ∷ xs) = x tail : ∀ {a n} {A : Set a} → Vec A (1 + n) → Vec A n tail (x ∷ xs) = xs [_] : ∀ {a} {A : Set a} → A → Vec A 1 [ x ] = x ∷ [] infixr 5 _++_ _++_ : ∀ {a m n} {A : Set a} → Vec A m → Vec A n → Vec A (m + n) [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) infixl 4 _⊛_ _⊛_ : ∀ {a b n} {A : Set a} {B : Set b} → Vec (A → B) n → Vec A n → Vec B n [] ⊛ _ = [] (f ∷ fs) ⊛ (x ∷ xs) = f x ∷ (fs ⊛ xs) replicate : ∀ {a n} {A : Set a} → A → Vec A n replicate {n = zero} x = [] replicate {n = suc n} x = x ∷ replicate x applicative : ∀ {a n} → RawApplicative (λ (A : Set a) → Vec A n) applicative = record { pure = replicate ; _⊛_ = _⊛_ } map : ∀ {a b n} {A : Set a} {B : Set b} → (A → B) → Vec A n → Vec B n map f xs = replicate f ⊛ xs zipWith : ∀ {a b c n} {A : Set a} {B : Set b} {C : Set c} → (A → B → C) → Vec A n → Vec B n → Vec C n zipWith _⊕_ xs ys = replicate _⊕_ ⊛ xs ⊛ ys zip : ∀ {a b n} {A : Set a} {B : Set b} → Vec A n → Vec B n → Vec (A × B) n zip = zipWith _,_ unzip : ∀ {a b n} {A : Set a} {B : Set b} → Vec (A × B) n → Vec A n × Vec B n unzip [] = [] , [] unzip ((x , y) ∷ xys) = Prod.map (_∷_ x) (_∷_ y) (unzip xys) foldr : ∀ {a b} {A : Set a} (B : ℕ → Set b) {m} → (∀ {n} → A → B n → B (suc n)) → B zero → Vec A m → B m foldr b _⊕_ n [] = n foldr b _⊕_ n (x ∷ xs) = x ⊕ foldr b _⊕_ n xs foldr₁ : ∀ {a} {A : Set a} {m} → (A → A → A) → Vec A (suc m) → A foldr₁ _⊕_ (x ∷ []) = x foldr₁ _⊕_ (x ∷ y ∷ ys) = x ⊕ foldr₁ _⊕_ (y ∷ ys) foldl : ∀ {a b} {A : Set a} (B : ℕ → Set b) {m} → (∀ {n} → B n → A → B (suc n)) → B zero → Vec A m → B m foldl b _⊕_ n [] = n foldl b _⊕_ n (x ∷ xs) = foldl (λ n → b (suc n)) _⊕_ (n ⊕ x) xs foldl₁ : ∀ {a} {A : Set a} {m} → (A → A → A) → Vec A (suc m) → A foldl₁ _⊕_ (x ∷ xs) = foldl _ _⊕_ x xs concat : ∀ {a m n} {A : Set a} → Vec (Vec A m) n → Vec A (n * m) concat [] = [] concat (xs ∷ xss) = xs ++ concat xss splitAt : ∀ {a} {A : Set a} m {n} (xs : Vec A (m + n)) → ∃₂ λ (ys : Vec A m) (zs : Vec A n) → xs ≡ ys ++ zs splitAt zero xs = ([] , xs , refl) splitAt (suc m) (x ∷ xs) with splitAt m xs splitAt (suc m) (x ∷ .(ys ++ zs)) | (ys , zs , refl) = ((x ∷ ys) , zs , refl) take : ∀ {a} {A : Set a} m {n} → Vec A (m + n) → Vec A m take m xs with splitAt m xs take m .(ys ++ zs) | (ys , zs , refl) = ys drop : ∀ {a} {A : Set a} m {n} → Vec A (m + n) → Vec A n drop m xs with splitAt m xs drop m .(ys ++ zs) | (ys , zs , refl) = zs group : ∀ {a} {A : Set a} n k (xs : Vec A (n * k)) → ∃ λ (xss : Vec (Vec A k) n) → xs ≡ concat xss group zero k [] = ([] , refl) group (suc n) k xs with splitAt k xs group (suc n) k .(ys ++ zs) | (ys , zs , refl) with group n k zs group (suc n) k .(ys ++ concat zss) | (ys , ._ , refl) | (zss , refl) = ((ys ∷ zss) , refl) -- Splits a vector into two "halves". split : ∀ {a n} {A : Set a} → Vec A n → Vec A ⌈ n /2⌉ × Vec A ⌊ n /2⌋ split [] = ([] , []) split (x ∷ []) = (x ∷ [] , []) split (x ∷ y ∷ xs) = Prod.map (_∷_ x) (_∷_ y) (split xs) reverse : ∀ {a n} {A : Set a} → Vec A n → Vec A n reverse {A = A} = foldl (Vec A) (λ rev x → x ∷ rev) [] sum : ∀ {n} → Vec ℕ n → ℕ sum = foldr _ _+_ 0 toList : ∀ {a n} {A : Set a} → Vec A n → List A toList [] = List.[] toList (x ∷ xs) = List._∷_ x (toList xs) fromList : ∀ {a} {A : Set a} → (xs : List A) → Vec A (List.length xs) fromList List.[] = [] fromList (List._∷_ x xs) = x ∷ fromList xs -- Snoc. infixl 5 _∷ʳ_ _∷ʳ_ : ∀ {a n} {A : Set a} → Vec A n → A → Vec A (1 + n) [] ∷ʳ y = [ y ] (x ∷ xs) ∷ʳ y = x ∷ (xs ∷ʳ y) initLast : ∀ {a n} {A : Set a} (xs : Vec A (1 + n)) → ∃₂ λ (ys : Vec A n) (y : A) → xs ≡ ys ∷ʳ y initLast {n = zero} (x ∷ []) = ([] , x , refl) initLast {n = suc n} (x ∷ xs) with initLast xs initLast {n = suc n} (x ∷ .(ys ∷ʳ y)) | (ys , y , refl) = ((x ∷ ys) , y , refl) init : ∀ {a n} {A : Set a} → Vec A (1 + n) → Vec A n init xs with initLast xs init .(ys ∷ʳ y) | (ys , y , refl) = ys last : ∀ {a n} {A : Set a} → Vec A (1 + n) → A last xs with initLast xs last .(ys ∷ʳ y) | (ys , y , refl) = y infixl 1 _>>=_ _>>=_ : ∀ {a b m n} {A : Set a} {B : Set b} → Vec A m → (A → Vec B n) → Vec B (m * n) xs >>= f = concat (map f xs) infixl 4 _⊛*_ _⊛*_ : ∀ {a b m n} {A : Set a} {B : Set b} → Vec (A → B) m → Vec A n → Vec B (m * n) fs ⊛* xs = fs >>= λ f → map f xs -- Interleaves the two vectors. infixr 5 _⋎_ _⋎_ : ∀ {a m n} {A : Set a} → Vec A m → Vec A n → Vec A (m +⋎ n) [] ⋎ ys = ys (x ∷ xs) ⋎ ys = x ∷ (ys ⋎ xs) -- A lookup function. lookup : ∀ {a n} {A : Set a} → Fin n → Vec A n → A lookup zero (x ∷ xs) = x lookup (suc i) (x ∷ xs) = lookup i xs -- An inverse of flip lookup. tabulate : ∀ {n a} {A : Set a} → (Fin n → A) → Vec A n tabulate {zero} f = [] tabulate {suc n} f = f zero ∷ tabulate (f ∘ suc) -- Update. infixl 6 _[_]≔_ _[_]≔_ : ∀ {a n} {A : Set a} → Vec A n → Fin n → A → Vec A n [] [ () ]≔ y (x ∷ xs) [ zero ]≔ y = y ∷ xs (x ∷ xs) [ suc i ]≔ y = x ∷ xs [ i ]≔ y -- Generates a vector containing all elements in Fin n. This function -- is not placed in Data.Fin because Data.Vec depends on Data.Fin. -- -- The implementation was suggested by Conor McBride ("Fwd: how to -- count 0..n-1", http://thread.gmane.org/gmane.comp.lang.agda/2554). allFin : ∀ n → Vec (Fin n) n allFin _ = tabulate id
{ "alphanum_fraction": 0.4384848923, "avg_line_length": 29.1856540084, "ext": "agda", "hexsha": "923ed2c82ddbcccd292833380e357282c01b5bb9", "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/Data/Vec.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/Data/Vec.agda", "max_line_length": 72, "max_stars_count": 1, "max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882", "max_stars_repo_licenses": [ "Apache-2.0" ], "max_stars_repo_name": "qwe2/try-agda", "max_stars_repo_path": "agda-stdlib-0.9/src/Data/Vec.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": 2940, "size": 6917 }
module Data.Union.Relation.Binary.Subtype where open import Data.List using (List) open import Data.List.Relation.Unary.Any using (here; there) open import Data.List.Relation.Binary.Subset.Propositional using (_⊆_) open import Data.Union using (Union; here; there; inj) open import Function using (_∘_; id) open import Relation.Binary.PropositionalEquality using () renaming (refl to refl≡) open import Level using (Level; _⊔_) -- ---------------------------------------------------------------------- -- Subtyping private variable a b c d f : Level A : Set a B : Set b C : Set c D : Set d F : A → Set f ts ts′ : List A infix 4 _≼_ _,_⊢_≼_ _≼_ : Set a → Set b → Set (a ⊔ b) A ≼ B = A → B _,_⊢_≼_ : (A : Set a) → (F : A → Set b) → List A → List A → Set (a ⊔ b) A , F ⊢ ts ≼ ts′ = Union A F ts ≼ Union A F ts′ refl : A ≼ A refl = id trans : A ≼ B → B ≼ C → A ≼ C trans A≼B B≼C = B≼C ∘ A≼B generalize : ts ⊆ ts′ → A , F ⊢ ts ≼ ts′ generalize ts⊆ts′ (here x) = inj (ts⊆ts′ (here refl≡)) x generalize ts⊆ts′ (there x) = generalize (ts⊆ts′ ∘ there) x function : C ≼ A → B ≼ D → (A → B) ≼ (C → D) function C≼A B≼D f = B≼D ∘ f ∘ C≼A coerce : A ≼ B → A → B coerce = id
{ "alphanum_fraction": 0.5584092792, "avg_line_length": 23.2115384615, "ext": "agda", "hexsha": "62c22ad3afd8149d4378a494e86fc50d69007c20", "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": "921a0dc44a69a74391031ca61568c624ab7f9c94", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "johnyob/agda-union", "max_forks_repo_path": "src/Data/Union/Relation/Binary/Subtype.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94", "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": "johnyob/agda-union", "max_issues_repo_path": "src/Data/Union/Relation/Binary/Subtype.agda", "max_line_length": 83, "max_stars_count": null, "max_stars_repo_head_hexsha": "921a0dc44a69a74391031ca61568c624ab7f9c94", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "johnyob/agda-union", "max_stars_repo_path": "src/Data/Union/Relation/Binary/Subtype.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 469, "size": 1207 }
{-# OPTIONS --without-K --rewriting #-} module lib.types.Suspension.Trunc where open import lib.Basics open import lib.NType2 open import lib.types.Paths open import lib.types.Pointed open import lib.types.Truncation open import lib.types.Suspension.Core module _ {i} (A : Type i) (m : ℕ₋₂) where module SuspTruncSwap = SuspRec {C = Trunc (S m) (Susp A)} [ north ] [ south ] (Trunc-rec {B = [ north ] == [ south ]} {{has-level-apply (Trunc-level {n = S m}) [ north ] [ south ]}} (λ x → ap [_] (merid x))) Susp-Trunc-swap : Susp (Trunc m A) → Trunc (S m) (Susp A) Susp-Trunc-swap = SuspTruncSwap.f Susp-Trunc-swap-Susp-fmap-trunc : ∀ (s : Susp A) → Susp-Trunc-swap (Susp-fmap [_] s) == [ s ] Susp-Trunc-swap-Susp-fmap-trunc = Susp-elim idp idp $ λ a → ↓-='-in' $ ! $ ap (Susp-Trunc-swap ∘ Susp-fmap [_]) (merid a) =⟨ ap-∘ Susp-Trunc-swap (Susp-fmap [_]) (merid a) ⟩ ap Susp-Trunc-swap (ap (Susp-fmap [_]) (merid a)) =⟨ ap (ap Susp-Trunc-swap) (SuspFmap.merid-β [_] a) ⟩ ap Susp-Trunc-swap (merid [ a ]) =⟨ SuspTruncSwap.merid-β [ a ] ⟩ ap [_] (merid a) =∎ abstract Susp-Trunc-swap-natural : ∀ {i} {j} {A : Type i} {B : Type j} (f : A → B) (m : ℕ₋₂) → Susp-Trunc-swap B m ∘ Susp-fmap (Trunc-fmap f) ∼ Trunc-fmap (Susp-fmap f) ∘ Susp-Trunc-swap A m Susp-Trunc-swap-natural {A = A} {B} f m = Susp-elim idp idp $ Trunc-elim {{λ t → ↓-level (=-preserves-level Trunc-level)}} $ λ s → ↓-='-in' $ ap (Trunc-fmap (Susp-fmap f) ∘ Susp-Trunc-swap A m) (merid [ s ]) =⟨ ap-∘ (Trunc-fmap (Susp-fmap f)) (Susp-Trunc-swap A m) (merid [ s ]) ⟩ ap (Trunc-fmap (Susp-fmap f)) (ap (Susp-Trunc-swap A m) (merid [ s ])) =⟨ ap (ap (Trunc-fmap (Susp-fmap f))) (SuspTruncSwap.merid-β A m [ s ]) ⟩ ap (Trunc-fmap (Susp-fmap f)) (ap [_] (merid s)) =⟨ ∘-ap (Trunc-fmap (Susp-fmap f)) [_] (merid s) ⟩ ap ([_] ∘ Susp-fmap f) (merid s) =⟨ ap-∘ [_] (Susp-fmap f) (merid s) ⟩ ap [_] (ap (Susp-fmap f) (merid s)) =⟨ ap (ap [_]) (SuspFmap.merid-β f s) ⟩ ap [_] (merid (f s)) =⟨ ! (SuspTruncSwap.merid-β B m [ f s ]) ⟩ ap (Susp-Trunc-swap B m) (merid [ f s ]) =⟨ ap (ap (Susp-Trunc-swap B m)) (! (SuspFmap.merid-β (Trunc-fmap f) [ s ])) ⟩ ap (Susp-Trunc-swap B m) (ap (Susp-fmap (Trunc-fmap f)) (merid [ s ])) =⟨ ∘-ap (Susp-Trunc-swap B m) (Susp-fmap (Trunc-fmap f)) (merid [ s ]) ⟩ ap (Susp-Trunc-swap B m ∘ Susp-fmap (Trunc-fmap f)) (merid [ s ]) =∎ ⊙Susp-Trunc-swap : ∀ {i} (A : Type i) (m : ℕ₋₂) → ⊙Susp (Trunc m A) ⊙→ ⊙Trunc (S m) (⊙Susp A) ⊙Susp-Trunc-swap A m = Susp-Trunc-swap A m , idp abstract ⊙Susp-Trunc-swap-natural : ∀ {i} {j} {A : Type i} {B : Type j} (f : A → B) (m : ℕ₋₂) → ⊙Susp-Trunc-swap B m ⊙∘ ⊙Susp-fmap (Trunc-fmap f) == ⊙Trunc-fmap (⊙Susp-fmap f) ⊙∘ ⊙Susp-Trunc-swap A m ⊙Susp-Trunc-swap-natural f m = ⊙λ=' (Susp-Trunc-swap-natural f m) idp
{ "alphanum_fraction": 0.5488822155, "avg_line_length": 37.4625, "ext": "agda", "hexsha": "779596ca80ea7802567ac12fd193c910150a6b69", "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": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "AntoineAllioux/HoTT-Agda", "max_forks_repo_path": "core/lib/types/Suspension/Trunc.agda", "max_issues_count": 31, "max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "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": "AntoineAllioux/HoTT-Agda", "max_issues_repo_path": "core/lib/types/Suspension/Trunc.agda", "max_line_length": 86, "max_stars_count": 294, "max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "AntoineAllioux/HoTT-Agda", "max_stars_repo_path": "core/lib/types/Suspension/Trunc.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": 1253, "size": 2997 }
{-# OPTIONS --without-K --safe #-} open import Definition.Typed.EqualityRelation module Definition.LogicalRelation.Substitution.Weakening {{eqrel : EqRelSet}} where open EqRelSet {{...}} open import Definition.Untyped open import Definition.Untyped.Properties open import Definition.LogicalRelation open import Definition.LogicalRelation.Irrelevance open import Definition.LogicalRelation.Substitution open import Tools.Product import Tools.PropositionalEquality as PE -- Weakening of valid types by one. wk1ᵛ : ∀ {A F Γ l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) → Γ ⊩ᵛ⟨ l ⟩ A / [Γ] → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A / (VPack _ _ (V∙ [Γ] [F])) wk1ᵛ {A} [Γ] [F] [A] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA] in [σA]′ , (λ [σ′] [σ≡σ′] → irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk A)) [σA] [σA]′ (proj₂ ([A] ⊢Δ (proj₁ [σ])) (proj₁ [σ′]) (proj₁ [σ≡σ′]))) -- Weakening of valid type equality by one. wk1Eqᵛ : ∀ {A B F Γ l} ([Γ] : ⊩ᵛ Γ) ([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ]) ([A] : Γ ⊩ᵛ⟨ l ⟩ A / [Γ]) ([A≡B] : Γ ⊩ᵛ⟨ l ⟩ A ≡ B / [Γ] / [A]) → Γ ∙ F ⊩ᵛ⟨ l ⟩ wk1 A ≡ wk1 B / (VPack _ _ (V∙ [Γ] [F])) / wk1ᵛ {A} {F} [Γ] [F] [A] wk1Eqᵛ {A} {B} [Γ] [F] [A] [A≡B] ⊢Δ [σ] = let [σA] = proj₁ ([A] ⊢Δ (proj₁ [σ])) [σA]′ = irrelevance′ (PE.sym (subst-wk A)) [σA] in irrelevanceEq″ (PE.sym (subst-wk A)) (PE.sym (subst-wk B)) [σA] [σA]′ ([A≡B] ⊢Δ (proj₁ [σ]))
{ "alphanum_fraction": 0.4963008631, "avg_line_length": 33.7916666667, "ext": "agda", "hexsha": "cdab625c87b79e61f47a7a3c7514a4bea954f486", "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": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "loic-p/logrel-mltt", "max_forks_repo_path": "Definition/LogicalRelation/Substitution/Weakening.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "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": "loic-p/logrel-mltt", "max_issues_repo_path": "Definition/LogicalRelation/Substitution/Weakening.agda", "max_line_length": 90, "max_stars_count": null, "max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "loic-p/logrel-mltt", "max_stars_repo_path": "Definition/LogicalRelation/Substitution/Weakening.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 690, "size": 1622 }
{-# OPTIONS --without-K #-} open import HoTT {- Move (parts of) faces of a cube around -} module lib.cubical.elims.CubeMove where square-push-rb : ∀ {i} {A : Type i} {a₀₀ a₀₁ a₁₀ a₁₁ b : A} {p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀} {p₋₁ : a₀₁ == a₁₁} (p₁₋ : a₁₀ == b) (q : b == a₁₁) → Square p₀₋ p₋₀ p₋₁ (p₁₋ ∙ q) → Square p₀₋ p₋₀ (p₋₁ ∙' ! q) p₁₋ square-push-rb idp idp sq = sq private right-from-front-lemma : ∀ {i} {A : Type i} {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A} {p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀} {p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀} {sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left {p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁} {p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁} (sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁) -- right {p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁} {p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁} {sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back {sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ (p₋₀₁ ∙ idp)} -- top {sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ (p₋₁₁ ∙ idp)} -- bottom {sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ (square-push-rb p₋₀₁ idp sq₋₀₋) (square-push-rb p₋₁₁ idp sq₋₁₋) (sq₁₋₋ ⊡h' !□h hid-square) → Cube sq₋₋₀ (sq₋₋₁ ⊡h hid-square) sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋ right-from-front-lemma ids cu = cu cube-right-from-front : ∀ {i} {A : Type i} {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ b₀ b₁ : A} {p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀} {p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀} {sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left {p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == b₀} {q₋₀₁ : b₀ == a₁₀₁} {r : b₀ == b₁} {p₋₁₁ : a₀₁₁ == b₁} {q₋₁₁ : b₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁} (sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ r) -- right {p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁} {p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁} {sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back {sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ (p₋₀₁ ∙ q₋₀₁)} -- top {sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ (p₋₁₁ ∙ q₋₁₁)} -- bottom {sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front (sq' : Square r q₋₀₁ q₋₁₁ p₁₋₁) → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ (square-push-rb p₋₀₁ q₋₀₁ sq₋₀₋) (square-push-rb p₋₁₁ q₋₁₁ sq₋₁₋) (sq₁₋₋ ⊡h' !□h sq') → Cube sq₋₋₀ (sq₋₋₁ ⊡h sq') sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋ cube-right-from-front sq₋₋₁ ids cu = right-from-front-lemma sq₋₋₁ cu
{ "alphanum_fraction": 0.5222412318, "avg_line_length": 37.7096774194, "ext": "agda", "hexsha": "61c180876d7d7b1145f8febb60974b215cee2776", "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": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "danbornside/HoTT-Agda", "max_forks_repo_path": "lib/cubical/elims/CubeMove.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "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": "danbornside/HoTT-Agda", "max_issues_repo_path": "lib/cubical/elims/CubeMove.agda", "max_line_length": 69, "max_stars_count": null, "max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "danbornside/HoTT-Agda", "max_stars_repo_path": "lib/cubical/elims/CubeMove.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1510, "size": 2338 }
-- test termination using structured orders module TerminationTupledAckermann where data Nat : Set where zero : Nat succ : Nat -> Nat data _×_ (A B : Set) : Set where _,_ : A -> B -> A × B -- addition in tupled form add : Nat × Nat -> Nat add (zero , m) = m add (succ n , m) = succ (add (n , m)) -- ackermann in tupled form ack : Nat × Nat -> Nat ack (zero , y) = succ y ack (succ x , zero) = ack (x , succ zero) ack (succ x , succ y) = ack (x , ack (succ x , y))
{ "alphanum_fraction": 0.5769230769, "avg_line_length": 20.5833333333, "ext": "agda", "hexsha": "2c4f87ae9ec6b9b33acf690541637a5b5d73f619", "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/features/matrixShapedTerminationOrder/TerminationTupledAckermann.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/features/matrixShapedTerminationOrder/TerminationTupledAckermann.agda", "max_line_length": 50, "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/features/matrixShapedTerminationOrder/TerminationTupledAckermann.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": 166, "size": 494 }
{-# OPTIONS --without-K #-} open import HoTT open import homotopy.HSpace renaming (HSpaceStructure to HSS) open import homotopy.Freudenthal open import homotopy.IterSuspensionStable open import homotopy.Pi2HSusp open import homotopy.EM1HSpace module homotopy.EilenbergMacLane where -- EM(G,n) when G is π₁(A,a₀) module EMImplicit {i} (A : Type i) (cA : is-connected 0 A) (gA : has-level 1 A) (A-H : HSS A) where private a₀ = HSS.e A-H X = ⊙[ A , a₀ ] ⊙EM : (n : ℕ) → Ptd i ⊙EM O = ⊙Ω X ⊙EM (S n) = ⊙Trunc ⟨ S n ⟩ (⊙Susp^ n X) module _ (n : ℕ) where EM = fst (⊙EM n) embase = snd (⊙EM n) EM-level : (n : ℕ) → has-level ⟨ n ⟩ (fst (⊙EM n)) EM-level O = gA a₀ a₀ EM-level (S n) = Trunc-level EM-conn : (n : ℕ) → is-connected ⟨ n ⟩ (EM (S n)) EM-conn n = Trunc-preserves-conn ⟨ S n ⟩ (transport (λ t → is-connected t (fst (⊙Susp^ n X))) (+2+0 ⟨ n ⟩₋₂) (⊙Susp^-conn n cA)) {- π (S k) (EM (S n)) (embase (S n)) == π k (EM n) (embase n) where k > 0 and n = S (S n') -} module Stable (k n : ℕ) (indexing : S k ≤ S (S n)) where private SSn : ℕ SSn = S (S n) lte : ⟨ S k ⟩ ≤T ⟨ SSn ⟩ lte = ⟨⟩-monotone-≤ $ indexing Skle : S k ≤ (S n) *2 Skle = ≤-trans indexing (lemma n) where lemma : (n' : ℕ) → S (S n') ≤ (S n') *2 lemma O = inl idp lemma (S n') = ≤-trans (≤-ap-S (lemma n')) (inr ltS) private module SS = Susp^StableSucc X cA k (S n) Skle abstract stable : πS (S k) (⊙EM (S SSn)) == πS k (⊙EM SSn) stable = πS (S k) (⊙EM (S SSn)) =⟨ πS-below-trunc _ _ _ (≤T-ap-S lte) ⟩ πS (S k) (⊙Susp^ SSn X) =⟨ SS.stable ⟩ πS k (⊙Susp^ (S n) X) =⟨ ! (πS-below-trunc _ _ _ lte) ⟩ πS k (⊙EM SSn) ∎ module BelowDiagonal where π₁ : (n : ℕ) → πS 0 (⊙EM (S (S n))) == Lift-Unit-group π₁ n = contr-is-0ᴳ (πS 0 (⊙EM (S (S n)))) (connected-at-level-is-contr (raise-level-≤T (≤T-ap-S (≤T-ap-S (-2≤T ⟨ n ⟩₋₂))) (Trunc-level {n = 0})) (Trunc-preserves-conn 0 (path-conn (EM-conn (S n))))) -- some clutter here arises from the definition of <; -- any simple way to avoid this? πS-below : (k n : ℕ) → (S k < n) → πS k (⊙EM n) == Lift-Unit-group πS-below 0 .2 ltS = π₁ 0 πS-below 0 .3 (ltSR ltS) = π₁ 1 πS-below 0 (S (S n)) (ltSR (ltSR _)) = π₁ n πS-below (S k) ._ ltS = Stable.stable k k (inr ltS) ∙ πS-below k _ ltS πS-below (S k) ._ (ltSR ltS) = Stable.stable k (S k) (inr (ltSR ltS)) ∙ πS-below k _ (ltSR ltS) πS-below (S k) ._ (ltSR (ltSR ltS)) = Stable.stable k (S (S k)) (inr (ltSR (ltSR ltS))) ∙ πS-below k _ (ltSR (ltSR ltS)) πS-below (S k) (S (S (S n))) (ltSR (ltSR (ltSR lt))) = Stable.stable k n (inr (<-cancel-S (ltSR (ltSR (ltSR lt))))) ∙ πS-below k _ (<-cancel-S (ltSR (ltSR (ltSR lt)))) module OnDiagonal where π₁ : πS 0 (⊙EM 1) == πS 0 X π₁ = πS-below-trunc 0 1 X ≤T-refl private module Π₂ = Pi2HSusp A gA cA A-H π₂ : πS 1 (⊙EM 2) == πS 0 X π₂ = πS-below-trunc 1 2 (⊙Susp X) ≤T-refl ∙ Π₂.π₂-Suspension πS-diag : (n : ℕ) → πS n (⊙EM (S n)) == πS 0 X πS-diag 0 = π₁ πS-diag 1 = π₂ πS-diag (S (S n)) = Stable.stable (S n) n ≤-refl ∙ πS-diag (S n) module AboveDiagonal where πS-above : (k n : ℕ) → (n < S k) → πS k (⊙EM n) == Lift-Unit-group πS-above k n lt = contr-is-0ᴳ (πS k (⊙EM n)) (inhab-prop-is-contr [ idp^ (S k) ] (Trunc-preserves-level 0 (Ω^-level-in -1 (S k) _ (raise-level-≤T (lemma lt) (EM-level n))))) where lemma : {k n : ℕ} → n < k → ⟨ n ⟩ ≤T (⟨ k ⟩₋₂ +2+ -1) lemma ltS = inl (! (+2+-comm _ -1)) lemma (ltSR lt) = ≤T-trans (lemma lt) (inr ltS) module Spectrum where private module Π₂ = Pi2HSusp A gA cA A-H spectrum0 : ⊙Ω (⊙EM 1) == ⊙EM 0 spectrum0 = ⊙Ω (⊙EM 1) =⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩ ⊙Trunc 0 (⊙Ω X) =⟨ ⊙ua (⊙≃-in (unTrunc-equiv _ (gA a₀ a₀)) idp) ⟩ ⊙Ω X ∎ spectrum1 : ⊙Ω (⊙EM 2) == ⊙EM 1 spectrum1 = ⊙Ω (⊙EM 2) =⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩ ⊙Trunc 1 (⊙Ω (⊙Susp X)) =⟨ Π₂.⊙main-lemma ⟩ X =⟨ ! (⊙ua (⊙≃-in (unTrunc-equiv _ gA) idp)) ⟩ ⊙EM 1 ∎ private sconn : (n : ℕ) → is-connected ⟨ S n ⟩ (fst (⊙Susp^ (S n) X)) sconn n = transport (λ t → is-connected t (fst (⊙Susp^ (S n) X))) (+2+0 ⟨ n ⟩₋₁) (⊙Susp^-conn (S n) cA) kle : (n : ℕ) → ⟨ S (S n) ⟩ ≤T ⟨ n ⟩ +2+ ⟨ n ⟩ kle O = inl idp kle (S n) = ≤T-trans (≤T-ap-S (kle n)) (≤T-trans (inl (! (+2+-βr ⟨ n ⟩ ⟨ n ⟩))) (inr ltS)) module FS (n : ℕ) = FreudenthalEquiv ⟨ n ⟩₋₁ ⟨ S (S n) ⟩ (kle n) (fst (⊙Susp^ (S n) X)) (snd (⊙Susp^ (S n) X)) (sconn n) spectrumSS : (n : ℕ) → ⊙Ω (⊙EM (S (S (S n)))) == ⊙EM (S (S n)) spectrumSS n = ⊙Ω (⊙EM (S (S (S n)))) =⟨ ⊙ua (⊙≃-in (Trunc=-equiv _ _) idp) ⟩ ⊙Trunc ⟨ S (S n) ⟩ (⊙Ω (⊙Susp^ (S (S n)) X)) =⟨ ! (FS.⊙path n) ⟩ ⊙EM (S (S n)) ∎ abstract spectrum : (n : ℕ) → ⊙Ω (⊙EM (S n)) == ⊙EM n spectrum 0 = spectrum0 spectrum 1 = spectrum1 spectrum (S (S n)) = spectrumSS n module EMExplicit {i} (G : Group i) (G-abelian : is-abelian G) where module K₁ = EM₁ G module HSpace = EM₁HSpace G G-abelian open EMImplicit K₁.EM₁ K₁.EM₁-conn K₁.emlevel HSpace.H-EM₁ public open BelowDiagonal public using (πS-below) πS-diag : (n : ℕ) → πS n (⊙EM (S n)) == G πS-diag n = OnDiagonal.πS-diag n ∙ K₁.π₁.π₁-iso open AboveDiagonal public using (πS-above) open Spectrum public using (spectrum)
{ "alphanum_fraction": 0.4804910864, "avg_line_length": 29.2906403941, "ext": "agda", "hexsha": "36609349a3661c103f3845a2a6e4b0626c35b386", "lang": "Agda", "max_forks_count": null, "max_forks_repo_forks_event_max_datetime": null, "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmknapp/HoTT-Agda", "max_forks_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "cmknapp/HoTT-Agda", "max_issues_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_line_length": 71, "max_stars_count": null, "max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmknapp/HoTT-Agda", "max_stars_repo_path": "theorems/homotopy/EilenbergMacLane.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 2633, "size": 5946 }
-- Andreas, 2015-07-13 Better parse errors for illegal type signatures A : Set where B = C
{ "alphanum_fraction": 0.7204301075, "avg_line_length": 23.25, "ext": "agda", "hexsha": "7c09b81b28b224d88102a9b2bf07bd39038dbc7d", "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/Issue1609a.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/Issue1609a.agda", "max_line_length": 71, "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/Issue1609a.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": 27, "size": 93 }
-- Andreas, 2019-08-10, weird error for naked ellipsis ... -- Error (weird): -- Missing type signature for left hand side ... -- when scope checking the declaration -- ... -- When following the suggestion to give a type signature, -- -- ... : Set -- -- Agda says: -- The ellipsis ... cannot have a type signature -- <EOF><ERROR>
{ "alphanum_fraction": 0.6458333333, "avg_line_length": 19.7647058824, "ext": "agda", "hexsha": "c91b956e35c17898d92a3abb85faf4a2bcdc1a43", "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/Bugs/NakedEllipsisWeirdError.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/Bugs/NakedEllipsisWeirdError.agda", "max_line_length": 58, "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/Bugs/NakedEllipsisWeirdError.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": 85, "size": 336 }
{-# OPTIONS --safe #-} module Cubical.Relation.Binary.Extensionality where open import Cubical.Foundations.Prelude open import Cubical.Foundations.Equiv open import Cubical.Foundations.HLevels open import Cubical.Foundations.Transport open import Cubical.Data.Sigma open import Cubical.Relation.Binary.Base module _ {ℓ ℓ'} {A : Type ℓ} (_≺_ : Rel A A ℓ') where ≡→≺Equiv : (x y : A) → x ≡ y → ∀ z → (z ≺ x) ≃ (z ≺ y) ≡→≺Equiv _ _ p z = substEquiv (z ≺_) p isWeaklyExtensional : Type _ isWeaklyExtensional = ∀ {x y} → isEquiv (≡→≺Equiv x y) isPropIsWeaklyExtensional : isProp isWeaklyExtensional isPropIsWeaklyExtensional = isPropImplicitΠ2 λ _ _ → isPropIsEquiv _
{ "alphanum_fraction": 0.7195301028, "avg_line_length": 30.9545454545, "ext": "agda", "hexsha": "41b789887feee6fbad928da4d01c205857d5a291", "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/Relation/Binary/Extensionality.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/Relation/Binary/Extensionality.agda", "max_line_length": 70, "max_stars_count": 1, "max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "thomas-lamiaux/cubical", "max_stars_repo_path": "Cubical/Relation/Binary/Extensionality.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-31T17:32:49.000Z", "max_stars_repo_stars_event_min_datetime": "2021-10-31T17:32:49.000Z", "num_tokens": 238, "size": 681 }
{-# OPTIONS --cubical --no-import-sorts --safe #-} module Cubical.Algebra.Magma.Submagma where open import Cubical.Core.Everything open import Cubical.Foundations.Prelude open import Cubical.Foundations.HLevels open import Cubical.Algebra open import Cubical.Algebra.Magma.Morphism open import Cubical.Relation.Unary open import Cubical.Relation.Unary.Subtype record IsSubmagma {c ℓ} (M : Magma c) (Member : Pred ⟨ M ⟩ ℓ) : Type (ℓ-max c ℓ) where constructor issubmagma private module M = Magma M field closed : M._•_ Preserves₂ Member Carrier : Type _ Carrier = Subtype Member _•_ : Op₂ Carrier (x , subx) • (y , suby) = x M.• y , closed subx suby is-set : isSet Carrier is-set = isSetSubtype Member M.is-set isMagma : IsMagma Carrier _•_ isMagma = record { is-set = is-set } magma : Magma _ magma = record { isMagma = isMagma } open Magma magma using (set) public record Submagma {c} (M : Magma c) ℓ : Type (ℓ-max c (ℓ-suc ℓ)) where constructor mksubmagma field Member : Pred ⟨ M ⟩ ℓ isSubmagma : IsSubmagma M Member open IsSubmagma isSubmagma public instance SubmagmaCarrier : ∀ {c ℓ} {M : Magma c} → HasCarrier (Submagma M ℓ) _ SubmagmaCarrier = record { ⟨_⟩ = Submagma.Carrier } module _ {ℓ} (M : Magma ℓ) where open Magma M ∅-isSubmagma : IsSubmagma M ∅ ∅-isSubmagma = record { closed = λ () } ∅-submagma : Submagma M _ ∅-submagma = record { isSubmagma = ∅-isSubmagma } U-isSubmagma : IsSubmagma M U U-isSubmagma = record {} -- trivial U-submagma : Submagma M _ U-submagma = record { isSubmagma = U-isSubmagma } isPropIsSubmagma : ∀ {c ℓ} {M : Magma c} {Member : Pred ⟨ M ⟩ ℓ} → isProp (IsSubmagma M Member) isPropIsSubmagma {Member = Member} (issubmagma a) (issubmagma b) = cong issubmagma ((isPropImplicitΠ λ _ → isPropImplicitΠ λ _ → isPropΠ2 λ _ _ → isProp[ Member ] _) a b)
{ "alphanum_fraction": 0.6831210191, "avg_line_length": 24.4675324675, "ext": "agda", "hexsha": "2a4c00eab45f6b964d0d1120ed4f87983af6c9db", "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": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "bijan2005/univalent-foundations", "max_forks_repo_path": "Cubical/Algebra/Magma/Submagma.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "bijan2005/univalent-foundations", "max_issues_repo_path": "Cubical/Algebra/Magma/Submagma.agda", "max_line_length": 105, "max_stars_count": null, "max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "bijan2005/univalent-foundations", "max_stars_repo_path": "Cubical/Algebra/Magma/Submagma.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 673, "size": 1884 }
-- Andreas, 2016-09-09 issue #2168 reported by Nisse -- {-# OPTIONS -v tc.cover.splittree:30 -v tc.cc:40 #-} open import Common.Equality data Unit : Set where unit : Unit data Bool : Set where true false : Bool f : Unit → Bool → Bool f unit true = false f = λ _ _ → true -- Testing definitional equality: f-1 : f unit true ≡ false f-1 = refl f-2 : f unit false ≡ true f-2 = refl
{ "alphanum_fraction": 0.6538461538, "avg_line_length": 16.9565217391, "ext": "agda", "hexsha": "f40b86a7648aa4f0cf4aa933bff44099cb07a75f", "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/Issue2168.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/Issue2168.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/Issue2168.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 131, "size": 390 }
{-# OPTIONS --without-K #-} open import Relation.Binary.PropositionalEquality as P data Phantom {i} {A : Set i} (a : A) : Set where phantom : Phantom a module _ where private data #Σ-aux (A : Set) (B : A → Set) : Set where #pair : (x : A) → B x → #Σ-aux A B Σ : (A : Set) → (A → Set) → Set Σ A B = #Σ-aux A B pair : ∀ {A : Set} {B : A → Set} (x : A) → B x → Σ A B pair = #pair module ΣElim {A} {B} {S : Σ A B → Set} (pair* : ∀(a : A) (b : B a) → S (pair a b)) where f-aux : Phantom pair* → (x : Σ A B) → S x f-aux x (#pair a b) = pair* a b f : (x : Σ A B) → S x f = f-aux phantom open ΣElim public renaming (f to Σ-elim) Σ-rec : ∀ {A} {B} {S : Set} → ((x : A) → B x → S) → Σ A B → S Σ-rec f = Σ-elim f isΣ-hom : ∀ {A B} {S : Set} (α : (a : A) → B a → S) → (Σ A B → S) → Set isΣ-hom α f = ∀ a b → f (pair a b) ≡ α a b Σ-rec-unique : ∀ {A B S} {α : (a : A) → B a → S} {f : Σ A B → S} → isΣ-hom α f → ∀ x → f x ≡ Σ-rec α x Σ-rec-unique f-hom = Σ-elim f-hom π₁ : ∀ {A B} → Σ A B → A π₁ = Σ-rec (λ a _ → a) π₂ : ∀ {A B} → (x : Σ A B) → B (π₁ x) π₂ = Σ-elim (λ a b → b) record ΣRecStruct (A : Set) (B : A → Set) : Set₁ where field Carrier : Set inj : (a : A) → B a → Carrier rec : ∀{S : Set} → ((a : A) → B a → S) → Carrier → S rec-hom : ∀ {S : Set} (α : (a : A) → B a → S) → (∀ a b → rec α (inj a b) ≡ α a b) rec-unique : ∀ {S : Set} {α : (a : A) → B a → S} {f : Carrier → S} → (∀ a b → f (inj a b) ≡ α a b) → ∀ x → f x ≡ rec α x -- open ΣRecStruct public Σ-ΣRecStruct : ∀ A B → ΣRecStruct A B Σ-ΣRecStruct A B = record { Carrier = Σ A B ; inj = pair ; rec = Σ-rec ; rec-hom = λ α a b → refl ; rec-unique = Σ-rec-unique } ΣRecStruct-HasInduction : ∀{A B} → ΣRecStruct A B → Set₁ ΣRecStruct-HasInduction {A} {B} R = ∀ {S : Carrier → Set} (inj* : ∀(a : A) (b : B a) → S (inj a b)) → (x : Carrier) → S x where open ΣRecStruct R -- I don't think that this is provable without resorting to π₂. -- But I also conjecture that internally the negation is neither -- provable. ∀ΣRecStruct-haveInduction : ∀{A B} (R : ΣRecStruct A B) → ΣRecStruct-HasInduction R ∀ΣRecStruct-haveInduction R {S} inj* x = {!!} where open ΣRecStruct R S-aux : Set S-aux = Σ Carrier S f : Carrier → S-aux f = rec (λ a b → pair (inj a b) (inj* a b))
{ "alphanum_fraction": 0.4861450693, "avg_line_length": 27.5730337079, "ext": "agda", "hexsha": "b8a9ecd9b2e7e2a58d01ea8dca5ff00360117580", "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": "TypeTheory/Sigma-Induction.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": "TypeTheory/Sigma-Induction.agda", "max_line_length": 80, "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": "TypeTheory/Sigma-Induction.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 1064, "size": 2454 }
{-# OPTIONS --without-K --exact-split --safe #-} open import Fragment.Equational.Theory module Fragment.Equational.FreeExtension.Synthetic (Θ : Theory) where open import Fragment.Algebra.Signature open import Fragment.Algebra.Algebra (Σ Θ) using (Algebra) open import Fragment.Equational.Model Θ open import Fragment.Equational.Coproduct Θ open import Fragment.Equational.FreeExtension.Base Θ open import Fragment.Algebra.Free (Σ Θ) hiding (_~_) open import Fragment.Algebra.Homomorphism (Σ Θ) open import Fragment.Algebra.Quotient (Σ Θ) open import Fragment.Setoid.Morphism using (_↝_) open import Level using (Level; _⊔_) open import Function using (_∘_) open import Data.Nat using (ℕ) open import Data.Fin using (Fin) open import Data.Product using (proj₁; proj₂) open import Data.Vec using (Vec; []; _∷_; map) open import Data.Vec.Relation.Binary.Pointwise.Inductive as PW using (Pointwise; []; _∷_) open import Relation.Binary using (Setoid; IsEquivalence) import Relation.Binary.Reasoning.Setoid as Reasoning import Relation.Binary.PropositionalEquality as PE private variable a b ℓ₁ ℓ₂ ℓ₃ : Level module _ (A : Model {a} {ℓ₁}) (n : ℕ) where Terms : Algebra Terms = Free (Atoms ∥ A ∥/≈ n) open module T = Setoid Algebra.∥ Terms ∥/≈ renaming (_≈_ to _~_) using () ∣inl∣ : ∥ A ∥ → T.Carrier ∣inl∣ x = atom (sta x) infix 4 _≈_ data _≈_ : T.Carrier → T.Carrier → Set (a ⊔ ℓ₁) where refl : ∀ {x} → x ≈ x sym : ∀ {x y} → x ≈ y → y ≈ x trans : ∀ {x y z} → x ≈ y → y ≈ z → x ≈ z inherit : ∀ {x y} → x ~ y → x ≈ y evaluate : ∀ {n xs} → (f : ops (Σ Θ) n) → term f (map ∣inl∣ xs) ≈ ∣inl∣ (A ⟦ f ⟧ xs) cong : ∀ {n} → (f : ops (Σ Θ) n) → ∀ {xs ys} → Pointwise _≈_ xs ys → term f xs ≈ term f ys axiom : ∀ {n} → (eq : eqs Θ n) → (θ : Env Terms n) → ∣ inst Terms θ ∣ (proj₁ (Θ ⟦ eq ⟧ₑ)) ≈ ∣ inst Terms θ ∣ (proj₂ (Θ ⟦ eq ⟧ₑ)) ≈-isEquivalence : IsEquivalence _≈_ ≈-isEquivalence = record { refl = refl ; sym = sym ; trans = trans } instance ≈-isDenom : IsDenominator Terms _≈_ ≈-isDenom = record { isEquivalence = ≈-isEquivalence ; isCompatible = cong ; isCoarser = inherit } module N = Setoid (∥ Terms ∥/ _≈_) Syn-models : Models (Terms / _≈_) Syn-models eq θ = begin ∣ inst (Terms / _≈_) θ ∣ lhs ≈⟨ N.sym (lemma {x = lhs}) ⟩ ∣ inst Terms θ ∣ lhs ≈⟨ axiom eq θ ⟩ ∣ inst Terms θ ∣ rhs ≈⟨ lemma {x = rhs} ⟩ ∣ inst (Terms / _≈_) θ ∣ rhs ∎ where open Reasoning (∥ Terms ∥/ _≈_) lhs = proj₁ (Θ ⟦ eq ⟧ₑ) rhs = proj₂ (Θ ⟦ eq ⟧ₑ) lemma = inst-universal (Terms / _≈_) θ {h = (inc Terms _≈_) ⊙ (inst Terms θ) } (λ x → PE.refl) Syn-isModel : IsModel (∥ Terms ∥/ _≈_) Syn-isModel = record { isAlgebra = Terms / _≈_ -isAlgebra ; models = Syn-models } Syn : Model Syn = record { ∥_∥/≈ = ∥ Terms ∥/ _≈_ ; isModel = Syn-isModel } ∣inl∣-cong : Congruent ≈[ A ] _≈_ ∣inl∣ ∣inl∣-cong p = inherit (atom (sta p)) ∣inl∣-hom : Homomorphic ∥ A ∥ₐ ∥ Syn ∥ₐ ∣inl∣ ∣inl∣-hom f xs = evaluate f ∣inl∣⃗ : ∥ A ∥/≈ ↝ ∥ Syn ∥/≈ ∣inl∣⃗ = record { ∣_∣ = ∣inl∣ ; ∣_∣-cong = ∣inl∣-cong } inl : ∥ A ∥ₐ ⟿ ∥ Syn ∥ₐ inl = record { ∣_∣⃗ = ∣inl∣⃗ ; ∣_∣-hom = ∣inl∣-hom } inr : ∥ J n ∥ₐ ⟿ ∥ Syn ∥ₐ inr = interp Syn (λ n → atom (dyn n)) module _ (X : Model {b} {ℓ₂}) (f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ) (g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ) where private module X = Setoid ∥ X ∥/≈ open Reasoning ∥ X ∥/≈ resid : Terms ⟿ ∥ X ∥ₐ resid = subst ∥ X ∥ₐ ∣ f ∣⃗ (λ n → ∣ g ∣ (atom (dyn n))) ∣resid∣-map-∣inl∣ : ∀ {m} {xs : Vec ∥ A ∥ m} → Pointwise ≈[ X ] (map ∣ resid ∣ (map ∣inl∣ xs)) (map ∣ f ∣ xs) ∣resid∣-map-∣inl∣ {xs = []} = [] ∣resid∣-map-∣inl∣ {xs = x ∷ xs} = X.refl ∷ ∣resid∣-map-∣inl∣ mutual ∣resid∣-args-cong : ∀ {m} {xs ys : Vec ∥ Syn ∥ m} → Pointwise _≈_ xs ys → Pointwise ≈[ X ] (map ∣ resid ∣ xs) (map ∣ resid ∣ ys) ∣resid∣-args-cong [] = [] ∣resid∣-args-cong (p ∷ ps) = ∣resid∣-cong p ∷ ∣resid∣-args-cong ps ∣resid∣-cong : Congruent _≈_ ≈[ X ] ∣ resid ∣ ∣resid∣-cong refl = X.refl ∣resid∣-cong (sym p) = X.sym (∣resid∣-cong p) ∣resid∣-cong (trans p q) = X.trans (∣resid∣-cong p) (∣resid∣-cong q) ∣resid∣-cong (inherit p) = ∣ resid ∣-cong p ∣resid∣-cong (evaluate {xs = xs} op) = begin ∣ resid ∣ (term op (map ∣inl∣ xs)) ≈⟨ X.sym (∣ resid ∣-hom op (map ∣inl∣ xs)) ⟩ X ⟦ op ⟧ (map ∣ resid ∣ (map ∣inl∣ xs)) ≈⟨ (X ⟦ op ⟧-cong) ∣resid∣-map-∣inl∣ ⟩ X ⟦ op ⟧ (map ∣ f ∣ xs) ≈⟨ ∣ f ∣-hom op xs ⟩ ∣ f ∣ (A ⟦ op ⟧ xs) ∎ ∣resid∣-cong (cong f {xs = xs} {ys = ys} ps) = begin ∣ resid ∣ (term f xs) ≈⟨ X.sym (∣ resid ∣-hom f xs) ⟩ X ⟦ f ⟧ (map ∣ resid ∣ xs) ≈⟨ (X ⟦ f ⟧-cong) (∣resid∣-args-cong ps) ⟩ X ⟦ f ⟧ (map ∣ resid ∣ ys) ≈⟨ ∣ resid ∣-hom f ys ⟩ ∣ resid ∣ (term f ys) ∎ ∣resid∣-cong (axiom eq θ) = begin ∣ resid ∣ (∣ inst Terms θ ∣ lhs) ≈⟨ inst-assoc Terms θ resid {lhs} ⟩ ∣ inst ∥ X ∥ₐ (∣ resid ∣ ∘ θ) ∣ lhs ≈⟨ ∥ X ∥ₐ-models eq (∣ resid ∣ ∘ θ) ⟩ ∣ inst ∥ X ∥ₐ (∣ resid ∣ ∘ θ) ∣ rhs ≈⟨ X.sym (inst-assoc Terms θ resid {rhs}) ⟩ ∣ resid ∣ (∣ inst Terms θ ∣ rhs) ∎ where lhs = proj₁ (Θ ⟦ eq ⟧ₑ) rhs = proj₂ (Θ ⟦ eq ⟧ₑ) _[_,_] : ∥ Syn ∥ₐ ⟿ ∥ X ∥ₐ _[_,_] = factor Terms _≈_ resid ∣resid∣-cong module _ {X : Model {b} {ℓ₂}} {f : ∥ A ∥ₐ ⟿ ∥ X ∥ₐ} {g : ∥ J n ∥ₐ ⟿ ∥ X ∥ₐ} where private module X = Setoid ∥ X ∥/≈ open Reasoning ∥ X ∥/≈ commute₁ : X [ f , g ] ⊙ inl ≗ f commute₁ = X.refl mutual map-commute₂ : ∀ {m} {xs : Vec ∥ J n ∥ m} → Pointwise ≈[ X ] (map ∣ X [ f , g ] ⊙ inr ∣ xs) (map ∣ g ∣ xs) map-commute₂ {xs = []} = [] map-commute₂ {xs = x ∷ xs} = commute₂ ∷ map-commute₂ commute₂ : X [ f , g ] ⊙ inr ≗ g commute₂ {atom (dyn _)} = X.refl commute₂ {term op xs} = begin ∣ X [ f , g ] ⊙ inr ∣ (term op xs) ≈⟨ X.sym (∣ X [ f , g ] ⊙ inr ∣-hom op xs) ⟩ X ⟦ op ⟧ (map ∣ X [ f , g ] ⊙ inr ∣ xs) ≈⟨ (X ⟦ op ⟧-cong) map-commute₂ ⟩ X ⟦ op ⟧ (map ∣ g ∣ xs) ≈⟨ ∣ g ∣-hom op xs ⟩ ∣ g ∣ (term op xs) ∎ module _ {h : ∥ Syn ∥ₐ ⟿ ∥ X ∥ₐ} (c₁ : h ⊙ inl ≗ f) (c₂ : h ⊙ inr ≗ g) where mutual map-universal : ∀ {m} {xs : Vec ∥ Syn ∥ m} → Pointwise ≈[ X ] (map ∣ X [ f , g ] ∣ xs) (map ∣ h ∣ xs) map-universal {xs = []} = [] map-universal {xs = x ∷ xs} = universal ∷ map-universal universal : X [ f , g ] ≗ h universal {atom (sta x)} = X.sym c₁ universal {atom (dyn x)} = begin ∣ X [ f , g ] ∣ (atom (dyn x)) ≈⟨ commute₂ ⟩ ∣ g ∣ (atom (dyn x)) ≈⟨ X.sym c₂ ⟩ ∣ h ∣ (atom (dyn x)) ∎ universal {term op xs} = begin ∣ X [ f , g ] ∣ (term op xs) ≈⟨ X.sym (∣ X [ f , g ] ∣-hom op xs) ⟩ X ⟦ op ⟧ (map ∣ X [ f , g ] ∣ xs) ≈⟨ (X ⟦ op ⟧-cong) map-universal ⟩ X ⟦ op ⟧ (map ∣ h ∣ xs) ≈⟨ ∣ h ∣-hom op xs ⟩ ∣ h ∣ (term op xs) ∎ isFrex : IsCoproduct A (J n) Syn isFrex = record { inl = inl ; inr = inr ; _[_,_] = _[_,_] ; commute₁ = λ {_ _ X f g} → commute₁ {X = X} {f} {g} ; commute₂ = λ {_ _ X f g} → commute₂ {X = X} {f} {g} ; universal = λ {_ _ X f g h} → universal {X = X} {f} {g} {h} } SynFrex : FreeExtension SynFrex = record { _[_] = Syn ; _[_]-isFrex = isFrex }
{ "alphanum_fraction": 0.4189069096, "avg_line_length": 33.5895522388, "ext": "agda", "hexsha": "26cec06f3b669bf85aa3b9c2d68874090da26a1f", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Equational/FreeExtension/Synthetic.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Equational/FreeExtension/Synthetic.agda", "max_line_length": 77, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Equational/FreeExtension/Synthetic.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 3513, "size": 9002 }
{-# OPTIONS -v tc.with.display:30 #-} -- {-# OPTIONS -v tc.with.strip:30 #-} open import Common.Product open import Common.Prelude open import Common.Equality postulate p : Nat → Nat -- g : Nat → Nat × Nat -- g x .proj₁ with p x -- g x .proj₁ | 0 = 1 -- g x .proj₁ | suc y = 0 -- g x .proj₂ = suc x -- h : Nat → Nat × Nat -- h x .proj₁ with p x -- h x .proj₁ | 0 = 1 -- proj₁ (h x) | suc y = 0 -- h x .proj₂ = suc x f : Nat → Nat × Nat f x .proj₁ with p x ... | 0 = 1 ... | suc y = 0 f x .proj₂ = suc x test : f 0 ≡ (0 , 1) test = refl -- EXPECTED ERROR: -- f 0 .proj₁ | p 0 != zero of type Nat -- when checking that the expression refl has type f 0 ≡ (0 , 1)
{ "alphanum_fraction": 0.5620328849, "avg_line_length": 19.1142857143, "ext": "agda", "hexsha": "127ba4fc7736066f4b1a1911313312d610e0a9fe", "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/Issue1963DisplayWithPostfixCopattern.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/Issue1963DisplayWithPostfixCopattern.agda", "max_line_length": 64, "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/Issue1963DisplayWithPostfixCopattern.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 261, "size": 669 }
{-# OPTIONS --rewriting --without-K #-} open import Prelude open import GSeTT.Syntax open import GSeTT.Rules open import Sets ℕ eqdecℕ {- PS-contexts -} module CaTT.Ps-contexts where {- Rules for PS-contexts -} data _⊢ps_#_ : Pre-Ctx → ℕ → Pre-Ty → Set₁ where pss : (nil :: (O , ∗)) ⊢ps O # ∗ psd : ∀ {Γ f A x y} → Γ ⊢ps f # (⇒ A (Var x) (Var y)) → Γ ⊢ps y # A pse : ∀ {Γ x A y z C t Tt} → Γ ⊢ps x # A → y == length Γ → z == S (length Γ) → C == ⇒ A (Var x) (Var y) → z == t → C == Tt → ((Γ :: (y , A)) :: (z , C)) ⊢ps t # Tt data _⊢ps : Pre-Ctx → Set₁ where ps : ∀ {Γ x} → Γ ⊢ps x # ∗ → Γ ⊢ps psd↓ : ∀ {Γ f A x y z} → (Γ⊢ps₁ : Γ ⊢ps f # (⇒ A (Var x) (Var z))) → (Γ⊢ps₂ : Γ ⊢ps f # (⇒ A (Var y) (Var z))) → (p : x == y) → transport p Γ⊢ps₁ == Γ⊢ps₂ → psd Γ⊢ps₁ == psd Γ⊢ps₂ psd↓ Γ⊢ps₁ .Γ⊢ps₁ idp idp = idp pse↓ : ∀ {Γ A B C x y a f z} → (Γ⊢ps₁ : Γ ⊢ps x # A) (a= : a == length Γ) (f= : f == S (length Γ)) (B= : B == ⇒ A (Var x) (Var a)) (z= : f == z) (C= : B == C) → (Γ⊢ps₂ : Γ ⊢ps y # A) (a=' : a == length Γ) (f=' : f == S (length Γ)) (B=' : B == ⇒ A (Var y) (Var a)) (z=' : f == z) (C=' : B == C) → (p : x == y) → transport p Γ⊢ps₁ == Γ⊢ps₂ → (pse Γ⊢ps₁ a= f= B= z= C=) == (pse Γ⊢ps₂ a=' f=' B=' z=' C=') pse↓ _ _ _ _ _ _ _ _ _ _ _ _ idp idp = ap⁶ pse idp (is-prop-has-all-paths (is-setℕ _ _) _ _) (is-prop-has-all-paths (is-setℕ _ _) _ _) (is-prop-has-all-paths (eqdec-is-set eqdec-PreTy _ _) _ _) (is-prop-has-all-paths (is-setℕ _ _) _ _) (is-prop-has-all-paths (eqdec-is-set eqdec-PreTy _ _) _ _) ps↓ : ∀ {Γ x y} → (Γ⊢ps₁ : Γ ⊢ps x # ∗) → (Γ⊢ps₂ : Γ ⊢ps y # ∗) → (p : x == y) → transport {B = λ z → Γ ⊢ps z # ∗} p Γ⊢ps₁ == Γ⊢ps₂ → (ps Γ⊢ps₁) == (ps Γ⊢ps₂) ps↓ _ _ idp idp = idp {- PS-contexts define valid contexts -} Γ⊢ps→Γ⊢ : ∀ {Γ} → Γ ⊢ps → Γ ⊢C Γ⊢psx:A→Γ⊢x:A : ∀ {Γ x A} → Γ ⊢ps x # A → Γ ⊢t (Var x) # A Γ⊢ps→Γ⊢ (ps Γ⊢psx) = Γ⊢t:A→Γ⊢ (Γ⊢psx:A→Γ⊢x:A Γ⊢psx) Γ⊢psx:A→Γ⊢x:A pss = var (cc ec (ob ec) idp) (inr (idp , idp)) Γ⊢psx:A→Γ⊢x:A (psd Γ⊢psf:x⇒y) with Γ⊢t:A→Γ⊢A (Γ⊢psx:A→Γ⊢x:A Γ⊢psf:x⇒y) Γ⊢psx:A→Γ⊢x:A (psd Γ⊢psf:x⇒y) | ar _ Γ⊢y:A = Γ⊢y:A Γ⊢psx:A→Γ⊢x:A (pse Γ⊢psx:A idp idp idp idp idp) with (cc (Γ⊢t:A→Γ⊢ (Γ⊢psx:A→Γ⊢x:A Γ⊢psx:A)) (Γ⊢t:A→Γ⊢A (Γ⊢psx:A→Γ⊢x:A Γ⊢psx:A)) idp) ... | Γ,y:A⊢ = var (cc Γ,y:A⊢ (ar (wkt (Γ⊢psx:A→Γ⊢x:A Γ⊢psx:A) Γ,y:A⊢) (var Γ,y:A⊢ (inr (idp , idp)))) idp) (inr (idp , idp)) Γ⊢psx:A→Γ⊢ : ∀ {Γ x A} → Γ ⊢ps x # A → Γ ⊢C Γ⊢psx:A→Γ⊢ Γ⊢psx:A = Γ⊢t:A→Γ⊢ (Γ⊢psx:A→Γ⊢x:A Γ⊢psx:A) -- some renamings so that useful lemmas are faster to write -- TODO restrict these as local names psv : ∀ {Γ x A} → Γ ⊢ps x # A → Γ ⊢C --psvalid psv Γ⊢ps = Γ⊢psx:A→Γ⊢ Γ⊢ps psvar : ∀ {Γ x A} → Γ ⊢ps x # A → Γ ⊢t (Var x) # A psvar Γ⊢psx = Γ⊢psx:A→Γ⊢x:A Γ⊢psx ps-ctx : Set₁ ps-ctx = Σ Pre-Ctx (λ Γ → Γ ⊢ps) {- Eric's trick : is a src-var -} srcᵢ-var : ∀ {Γ x A} → ℕ → Γ ⊢ps x # A → list ℕ srcᵢ-var i pss = if i ≡ 0 then nil else (nil :: 0) srcᵢ-var i (psd Γ⊢psx) = srcᵢ-var i Γ⊢psx srcᵢ-var i (pse {Γ = Γ} {A = A} Γ⊢psx idp idp idp idp idp) with dec-≤ i (S (dim A)) ... | inl i≤SdimA = srcᵢ-var i Γ⊢psx ... | inr SdimA<i = (srcᵢ-var i Γ⊢psx :: length Γ) :: (S (length Γ)) drop : ∀ {i} {A : Set i} → list A → list A drop nil = nil drop (l :: a) = l tgtᵢ-var : ∀ {Γ x A} → ℕ → Γ ⊢ps x # A → list ℕ tgtᵢ-var i pss = if i ≡ 0 then nil else (nil :: 0) tgtᵢ-var i (psd Γ⊢psx) = tgtᵢ-var i Γ⊢psx tgtᵢ-var i (pse {Γ = Γ} {A = A} Γ⊢psx idp idp idp idp idp) with dec-≤ i (S (dim A)) ... | inl i≤SdimA = if i ≡ S (dim A) then drop(tgtᵢ-var i Γ⊢psx) :: length Γ else tgtᵢ-var i Γ⊢psx ... | inr SdimA<i = (tgtᵢ-var i Γ⊢psx :: length Γ) :: (S (length Γ)) src-var : (Γ : ps-ctx) → set src-var (Γ , ps Γ⊢psx) = set-of-list (srcᵢ-var (dimC Γ) Γ⊢psx) tgt-var : (Γ : ps-ctx) → set tgt-var (Γ , ps Γ⊢psx) = set-of-list (tgtᵢ-var (dimC Γ) Γ⊢psx) dim-psx-not-𝔻0 : ∀ {Γ x A} → (Γ⊢ps : Γ ⊢ps x # A) → (Γ ≠ (nil :: (0 , ∗))) → 0 < dimC Γ dim-psx-not-𝔻0 {.(nil :: (0 , ∗))} {.0} {.∗} pss Γ≠𝔻0 = ⊥-elim (Γ≠𝔻0 idp) dim-psx-not-𝔻0 {Γ} {x} {A} (psd Γ⊢psx) Γ≠𝔻0 = dim-psx-not-𝔻0 Γ⊢psx Γ≠𝔻0 dim-psx-not-𝔻0 {_} {x} {A} (pse {Γ = Γ} Γ⊢psx idp idp idp idp idp) Γ+≠𝔻0 = ≤T (S≤ (0≤ _)) (m≤max (max (dimC Γ) _) (dim A)) dim-ps-not-𝔻0 : ∀ {Γ} → (Γ⊢ps : Γ ⊢ps) → (Γ ≠ (nil :: (0 , ∗))) → 0 < dimC Γ dim-ps-not-𝔻0 (ps Γ⊢psx) Γ≠𝔻0 = dim-psx-not-𝔻0 Γ⊢psx Γ≠𝔻0 dim-dangling : ∀ {Γ x A} → Γ ⊢ps x # A → dim A ≤ dimC Γ dim-dangling pss = 0≤ _ dim-dangling (psd Γ⊢psf) = Sn≤m→n≤m (dim-dangling Γ⊢psf) dim-dangling (pse {Γ = Γ} Γ⊢psx idp idp idp idp idp) = m≤max (max (dimC Γ) _) _ {- Definition of a few ps-contexts and their source and target in the theory CaTT -} -- It is not necessary to define the pre contexts, as they can be infered with the derivation tree. We do it just as a sanity check Pre-Γc : Pre-Ctx Pre-Γc = ((((nil :: (0 , ∗)) :: (1 , ∗)) :: (2 , ⇒ ∗ (Var 0) (Var 1))) :: (3 , ∗)) :: (4 , ⇒ ∗ (Var 1) (Var 3)) Pre-Γw : Pre-Ctx Pre-Γw = ((((((nil :: (0 , ∗)) :: (1 , ∗)) :: (2 , ⇒ ∗ (Var 0) (Var 1))) :: (3 , ⇒ ∗ (Var 0) (Var 1))) :: (4 , ⇒ (⇒ ∗ (Var 0) (Var 1)) (Var 2) (Var 3))) :: (5 , ∗)) :: (6 , ⇒ ∗ (Var 1) (Var 5)) Pre-Γ₁ : Pre-Ctx Pre-Γ₁ = ((nil :: (0 , ∗)) :: (1 , ∗)) :: (2 , ⇒ ∗ (Var 0) (Var 1)) Pre-Γ₂ : Pre-Ctx Pre-Γ₂ = ((((nil :: (0 , ∗)) :: (1 , ∗)) :: (2 , ⇒ ∗ (Var 0) (Var 1))) :: (3 , ⇒ ∗ (Var 0) (Var 1))) :: (4 , ⇒ (⇒ ∗ (Var 0) (Var 1)) (Var 2) (Var 3)) Γc⊢ps : Pre-Γc ⊢ps Γc⊢ps = ps (psd (pse (psd (pse pss idp idp idp idp idp)) idp idp idp idp idp)) Γw⊢ps : Pre-Γw ⊢ps Γw⊢ps = ps (psd (pse (psd (psd (pse (pse pss idp idp idp idp idp) idp idp idp idp idp))) idp idp idp idp idp)) Γ₁⊢ps : Pre-Γ₁ ⊢ps Γ₁⊢ps = ps (psd (pse pss idp idp idp idp idp)) Γ₂⊢ps : Pre-Γ₂ ⊢ps Γ₂⊢ps = ps (psd (psd (pse (pse pss idp idp idp idp idp) idp idp idp idp idp))) Γc : ps-ctx Γc = _ , Γc⊢ps Γw : ps-ctx Γw = _ , Γw⊢ps Γ₁ : ps-ctx Γ₁ = _ , Γ₁⊢ps Γ₂ : ps-ctx Γ₂ = _ , Γ₂⊢ps src-Γc : src-var Γc ≗ singleton 0 src-Γc = (λ _ x → x) , λ _ x → x tgt-Γc : tgt-var Γc ≗ singleton 3 tgt-Γc = (λ _ x → x) , λ _ x → x src-Γ₁ : src-var Γ₁ ≗ singleton 0 src-Γ₁ = (λ _ x → x) , λ _ x → x tgt-Γ₁ : tgt-var Γ₁ ≗ singleton 1 tgt-Γ₁ = (λ _ x → x) , λ _ x → x src-Γ₂ : src-var Γ₂ ≗ set-of-list (((nil :: 0) :: 1) :: 2) src-Γ₂ = (λ _ x → x) , λ _ x → x tgt-Γ₂ : tgt-var Γ₂ ≗ set-of-list (((nil :: 0) :: 1) :: 3) tgt-Γ₂ = (λ _ x → x) , λ _ x → x src-Γw : src-var Γw ≗ set-of-list (((((nil :: 0) :: 1) :: 2) :: 5) :: 6) src-Γw = (λ _ x → x) , λ _ x → x tgt-Γw : tgt-var Γw ≗ set-of-list (((((nil :: 0) :: 1) :: 3) :: 5) :: 6) tgt-Γw = (λ _ x → x) , λ _ x → x -- TODO : cleanup and unite these two lemmas x∉ : ∀ {Γ x} → Γ ⊢C → length Γ ≤ x → (∀ {A} → ¬ (Γ ⊢t (Var x) # A)) x∉ (cc Γ⊢ _ idp) l≤x (var _ (inl x∈Γ)) = x∉ Γ⊢ (Sn≤m→n≤m l≤x) (var Γ⊢ x∈Γ) x∉ (cc Γ⊢ _ idp) l≤x (var _ (inr (idp , idp))) = Sn≰n _ l≤x l∉ : ∀ {Γ x} → Γ ⊢C → length Γ ≤ x → ¬ (x ∈ Γ) l∉ (cc Γ⊢ _ idp) l≤x (inl x∈Γ) = l∉ Γ⊢ (Sn≤m→n≤m l≤x) x∈Γ l∉ (cc Γ⊢ _ idp) l≤x (inr idp) = Sn≰n _ l≤x
{ "alphanum_fraction": 0.4659290244, "avg_line_length": 42.3485714286, "ext": "agda", "hexsha": "5be4328ee30901e3c96e13444d788d0ee38eb99a", "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": "CaTT/Ps-contexts.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": "CaTT/Ps-contexts.agda", "max_line_length": 195, "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": "CaTT/Ps-contexts.agda", "max_stars_repo_stars_event_max_datetime": null, "max_stars_repo_stars_event_min_datetime": null, "num_tokens": 4101, "size": 7411 }
{-# OPTIONS --without-K --safe #-} module Fragment.Tactic.Fragment where open import Reflection hiding (name; Type; _≟_) open import Reflection.Term using (_≟_) open import Level using (_⊔_) open import Relation.Binary using (Setoid) open import Data.Bool using (Bool; _∨_; true; false; if_then_else_) open import Data.Nat using (ℕ) open import Data.List using (List; []; _∷_; map; sum; length) open import Data.Vec using (fromList) open import Data.Product using (_×_; _,_) open import Data.Unit using (⊤; tt) open import Data.String using (String; _++_) open import Data.Maybe using (Maybe; just; nothing) open import Fragment.Tactic.Utils open import Fragment.Equational.Theory open import Fragment.Equational.Model open import Fragment.Equational.FreeExtension hiding (reduce) open import Fragment.Algebra.Signature import Fragment.Algebra.Free as Free read-goal : List (Arg Term) → TC (Term × List (Arg Term)) read-goal (vArg x ∷ xs) = return (x , xs) read-goal (_ ∷ xs) = read-goal xs read-goal [] = typeError (strErr "failed to read goal" ∷ []) read-goals : List (Arg Term) → TC (Term × Term) read-goals xs = do (fst , xs) ← read-goal xs (snd , _) ← read-goal xs return (fst , snd) extract-goals : Term → TC (Term × Term) extract-goals (var _ args) = read-goals args extract-goals (con _ args) = read-goals args extract-goals (def _ args) = read-goals args extract-goals (meta _ args) = read-goals args extract-goals t = typeError (strErr "can't read goals from" ∷ termErr t ∷ []) record Operator : Set where constructor operator field name : Name normalised : Term arity : ℕ open Operator record CoreCtx : Set where field signature : Term theory : Term model : Term carrier : Term frex : Term record GlobalCtx : Set where field core : CoreCtx operators : List Operator telescope : List (Arg String) lhs : Term rhs : Term open CoreCtx core public pattern modelType Θ a ℓ = def (quote Model) (vArg Θ ∷ hArg a ∷ hArg ℓ ∷ []) ctx : Name → Term → Term → TC GlobalCtx ctx frex model goal = do τ ← inferType model γ ← inferType goal signature ← extract-Σ τ theory ← extract-Θ τ carrier ← normalise (def (quote ∥_∥) (vra theory ∷ vra model ∷ [])) let core = record { signature = signature ; theory = theory ; model = model ; carrier = carrier ; frex = def frex [] } operators ← extract-ops core (inner , telescope) ← strip-telescope γ (lhs , rhs) ← extract-goals inner return (record { core = core ; operators = operators ; telescope = telescope ; lhs = lhs ; rhs = rhs }) where modelErr : ∀ {a} {A : Set a} → Term → String → TC A modelErr t err = typeError ( termErr t ∷ strErr "isn't a" ∷ nameErr (quote Model) ∷ strErr ("(" ++ err ++ ")") ∷ [] ) extract-Σ : Term → TC Term extract-Σ (modelType Θ _ _) = normalise (def (quote Theory.Σ) (vra Θ ∷ [])) extract-Σ t = modelErr t "when extracting the signature" extract-Θ : Term → TC Term extract-Θ (modelType Θ _ _) = normalise Θ extract-Θ t = modelErr t "when extracting the theory" extract-arity : CoreCtx → Name → TC ℕ extract-arity ctx op = do τ ← inferType (def (quote _⟦_⟧_) ( vra (CoreCtx.theory ctx) ∷ vra (CoreCtx.model ctx) ∷ vra (con op []) ∷ [] )) α ← extract-type-arg τ vec-len α extract-interp : CoreCtx → Name → ℕ → TC Term extract-interp ctx op arity = do let t = def (quote _⟦_⟧_) ( vra (CoreCtx.theory ctx) ∷ vra (CoreCtx.model ctx) ∷ vra (con op []) ∷ [] ) normalise (n-ary arity (apply t (vra (vec (debrujin arity)) ∷ []))) extract-ops : CoreCtx → TC (List Operator) extract-ops ctx = do ops ← normalise (def (quote ops) (vra (CoreCtx.signature ctx) ∷ [])) symbols ← extract-constructors ops arities ← listTC (map (extract-arity ctx) symbols) interps ← listTC (mapList (map (extract-interp ctx) symbols) arities) return (mapList (mapList (map operator symbols) interps) arities) record FoldCtx {a b} (A : Set a) (B : Set b) : Set (a ⊔ b) where constructor foldCtx field global : GlobalCtx f : Term → B → A × B g : Operator → List A → A ε : B open GlobalCtx global public mutual map-fold : ∀ {a b} {A : Set a} {B : Set b} → FoldCtx A B → List (Arg Term) → B → TC (List A × B) map-fold ctx [] acc = return ([] , acc) map-fold ctx (vArg x ∷ xs) acc = do (x , acc) ← fold-acc ctx x acc (xs , acc) ← map-fold ctx xs acc return (x ∷ xs , acc) map-fold ctx (_ ∷ xs) acc = map-fold ctx xs acc fold-inner : ∀ {a b} {A : Set a} {B : Set b} → FoldCtx A B → Operator → Term → B → TC (List A × B) fold-inner ctx op (var _ args) acc = map-fold ctx (ekat (arity op) args) acc fold-inner ctx op (con _ args) acc = map-fold ctx (ekat (arity op) args) acc fold-inner ctx op (def _ args) acc = map-fold ctx (ekat (arity op) args) acc fold-inner ctx op (meta _ args) acc = map-fold ctx (ekat (arity op) args) acc fold-inner ctx op (pat-lam _ args) acc = map-fold ctx (ekat (arity op) args) acc fold-inner _ _ t _ = typeError (termErr t ∷ strErr "has no arguments" ∷ []) fold-acc : ∀ {a b} {A : Set a} {B : Set b} → FoldCtx A B → Term → B → TC (A × B) fold-acc ctx t acc = do op? ← find (λ x → prefix (arity x) (normalised x) t) (FoldCtx.operators ctx) resolve op? where resolve : Maybe Operator → TC _ resolve (just op) = do (args , acc) ← fold-inner ctx op t acc return ((FoldCtx.g ctx) op args , acc) resolve nothing = return ((FoldCtx.f ctx) t acc) fold : ∀ {a b} {A : Set a} {B : Set b} → FoldCtx A B → Term → TC (A × B) fold ctx t = fold-acc ctx t (FoldCtx.ε ctx) fold-⊤ : ∀ {a} {A : Set a} → GlobalCtx → (Term → A) → (Operator → List A → A) → Term → TC A fold-⊤ ctx f g t = do (x , _) ← fold (foldCtx ctx (λ x _ → (f x , tt)) g tt) t return x accumulate : ∀ {a} {A : Set a} → GlobalCtx → (Term → A → A) → A → Term → TC A accumulate ctx f ε t = do (_ , acc) ← fold (foldCtx ctx (λ x acc → (tt , f x acc)) (λ _ _ → tt) ε) t return acc leaves : GlobalCtx → Term → TC ℕ leaves ctx = fold-⊤ ctx (λ _ → 1) (λ _ → sum) mutual argsOpen : Term → List (Arg Term) → TC Bool argsOpen τ [] = return false argsOpen τ (vArg x ∷ xs) = do head ← isOpen τ x tail ← argsOpen τ xs return (head ∨ tail) argsOpen τ (_ ∷ xs) = argsOpen τ xs isOpen : Term → Term → TC Bool isOpen τ t@(var _ _) = hasType τ t isOpen τ t@(meta _ _) = hasType τ t isOpen τ (con c args) = argsOpen τ args isOpen τ (def f args) = argsOpen τ args isOpen τ unknown = return true isOpen τ _ = return false findOpen : GlobalCtx → List Term → Term → TC (List Term) findOpen ctx ε t = flatten (accumulate ctx binding (return ε) t) where binding : Term → TC (List Term) → TC (List Term) binding t env = do env ← env let τ = CoreCtx.carrier (GlobalCtx.core ctx) open? ← isOpen τ t if open? then return (insert env t) else return env buildSyntax : GlobalCtx → List Term → Term → TC Term buildSyntax ctx env t = fold-⊤ ctx buildInj buildTerm t where bt : Term bt = def (quote Free.BT) ( vra (GlobalCtx.signature ctx) ∷ vra (GlobalCtx.carrier ctx) ∷ vra (lit (nat (length env))) ∷ [] ) buildAtom : Term → Term buildAtom t = con (quote Free.Term.atom) ( hra (GlobalCtx.signature ctx) ∷ hra unknown ∷ hra bt ∷ vra t ∷ [] ) buildDyn : ℕ → Term buildDyn n = con (quote Free.BT.dyn) ( hra (GlobalCtx.signature ctx) ∷ hra unknown ∷ hra (GlobalCtx.carrier ctx) ∷ hra (lit (nat (length env))) ∷ vra (fin n) ∷ [] ) buildSta : Term → Term buildSta t = con (quote Free.BT.sta) ( hra (GlobalCtx.signature ctx) ∷ hra unknown ∷ hra (GlobalCtx.carrier ctx) ∷ hra (lit (nat (length env))) ∷ vra t ∷ [] ) buildInj : Term → Term buildInj t with indexOf env t ... | just n = buildAtom (buildDyn n) ... | nothing = buildAtom (buildSta t) buildTerm : Operator → List Term → Term buildTerm op xs = con (quote Free.Term.term) ( hra (GlobalCtx.signature ctx) ∷ hra unknown ∷ hra bt ∷ hra (lit (nat (arity op))) ∷ vra (con (name op) []) ∷ vra (vec (fromList xs)) ∷ [] ) environment : List Term → Term environment env = vec (fromList env) macro fragment : Name → Term → Term → TC ⊤ fragment frex model goal = do ctx ← ctx frex model goal env ← findOpen ctx [] (GlobalCtx.lhs ctx) env ← findOpen ctx env (GlobalCtx.rhs ctx) lhs ← buildSyntax ctx env (GlobalCtx.lhs ctx) rhs ← buildSyntax ctx env (GlobalCtx.rhs ctx) let n = length env let frex = def (quote FreeExtension._[_]) ( hra (GlobalCtx.theory ctx) ∷ vra (GlobalCtx.frex ctx) ∷ vra (GlobalCtx.model ctx) ∷ vra (lit (nat n)) ∷ [] ) let setoid = def (quote ∥_∥/≈) ( hra (GlobalCtx.theory ctx) ∷ vra frex ∷ [] ) let p = def (quote Setoid.refl) (vra setoid ∷ []) let frexify = def (quote frexify) ( vra (GlobalCtx.theory ctx) ∷ vra (GlobalCtx.frex ctx) ∷ vra (GlobalCtx.model ctx) ∷ vra (vec (fromList env)) ∷ hra lhs ∷ hra rhs ∷ vra p ∷ [] ) frexify ← restore-telescope (GlobalCtx.telescope ctx) frexify unify frexify goal
{ "alphanum_fraction": 0.50249759, "avg_line_length": 34.3704819277, "ext": "agda", "hexsha": "12744016e01bd9a8a2af7221dbdc1425cedd567a", "lang": "Agda", "max_forks_count": 3, "max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z", "max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z", "max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "yallop/agda-fragment", "max_forks_repo_path": "src/Fragment/Tactic/Fragment.agda", "max_issues_count": 1, "max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z", "max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "yallop/agda-fragment", "max_issues_repo_path": "src/Fragment/Tactic/Fragment.agda", "max_line_length": 85, "max_stars_count": 18, "max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "yallop/agda-fragment", "max_stars_repo_path": "src/Fragment/Tactic/Fragment.agda", "max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z", "max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z", "num_tokens": 3091, "size": 11411 }
module Issue580 where record Bad : Set₁ where private field A : Set
{ "alphanum_fraction": 0.7361111111, "avg_line_length": 12, "ext": "agda", "hexsha": "86544d812ae4c467a9379e87600fce3b7d3dd16c", "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/Issue580.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/Issue580.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/Fail/Issue580.agda", "max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z", "max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z", "num_tokens": 20, "size": 72 }
postulate Wrap : Set → Set instance wrap : {A : Set} → A → Wrap A postulate I : Set P : I → Set HO = ∀ {i} {{p : P i}} → P i postulate X : {{ho : HO}} → Set Y : {{ho : Wrap HO}} → Set Works : Set Works = X -- Debug output shows messed up deBruijn indices in unwrapped target: P p instead of P i Fails : Set Fails = Y
{ "alphanum_fraction": 0.576119403, "avg_line_length": 15.2272727273, "ext": "agda", "hexsha": "aab215f0ebcabace8e9f9c6c9869ce774f226a58", "lang": "Agda", "max_forks_count": 1, "max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z", "max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_forks_repo_licenses": [ "BSD-3-Clause" ], "max_forks_repo_name": "alhassy/agda", "max_forks_repo_path": "test/Succeed/Issue2577.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "BSD-3-Clause" ], "max_issues_repo_name": "alhassy/agda", "max_issues_repo_path": "test/Succeed/Issue2577.agda", "max_line_length": 88, "max_stars_count": 1, "max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c", "max_stars_repo_licenses": [ "BSD-3-Clause" ], "max_stars_repo_name": "alhassy/agda", "max_stars_repo_path": "test/Succeed/Issue2577.agda", "max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z", "max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z", "num_tokens": 124, "size": 335 }
------------------------------------------------------------------------ -- Most of a virtual machine ------------------------------------------------------------------------ {-# OPTIONS --sized-types #-} module Lambda.Virtual-machine where open import Equality.Propositional open import Prelude open import Vec.Function equality-with-J open import Lambda.Syntax ------------------------------------------------------------------------ -- Instruction set mutual -- Instructions. data Instr (n : ℕ) : Type where var : (x : Fin n) → Instr n con : (i : ℕ) → Instr n clo : (c : Code (suc n)) → Instr n app : Instr n ret : Instr n -- Code. Code : ℕ → Type Code n = List (Instr n) -- Environments and values. open Closure Code ------------------------------------------------------------------------ -- Stacks and states -- Stacks. data StackElement : Type where val : (v : Value) → StackElement ret : ∀ {n} (c : Code n) (ρ : Env n) → StackElement Stack : Type Stack = List StackElement -- States. data State : Type where ⟨_,_,_⟩ : ∀ {n} (c : Code n) (s : Stack) (ρ : Env n) → State pattern ⟨_∣_,_,_⟩ n c s ρ = ⟨_,_,_⟩ {n} c s ρ ------------------------------------------------------------------------ -- A kind of small-step semantics for the virtual machine -- The result of running the VM one step. data Result : Type where continue : (s : State) → Result done : (v : Value) → Result crash : Result -- A single step of the computation. step : State → Result step ⟨ var x ∷ c , s , ρ ⟩ = continue ⟨ c , val (ρ x) ∷ s , ρ ⟩ step ⟨ con i ∷ c , s , ρ ⟩ = continue ⟨ c , val (con i) ∷ s , ρ ⟩ step ⟨ clo c′ ∷ c , s , ρ ⟩ = continue ⟨ c , val (ƛ c′ ρ) ∷ s , ρ ⟩ step ⟨ app ∷ c , val v ∷ val (ƛ c′ ρ′) ∷ s , ρ ⟩ = continue ⟨ c′ , ret c ρ ∷ s , cons v ρ′ ⟩ step ⟨ ret ∷ c , val v ∷ ret c′ ρ′ ∷ s , ρ ⟩ = continue ⟨ c′ , val v ∷ s , ρ′ ⟩ step ⟨ zero ∣ [] , val v ∷ [] , ρ ⟩ = done v step _ = crash
{ "alphanum_fraction": 0.4236817761, "avg_line_length": 27.7179487179, "ext": "agda", "hexsha": "56cbfb16b67e3860f2fb661cefdd47aa0e9b3090", "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": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "nad/partiality-monad", "max_forks_repo_path": "src/Lambda/Virtual-machine.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_issues_repo_issues_event_max_datetime": null, "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "nad/partiality-monad", "max_issues_repo_path": "src/Lambda/Virtual-machine.agda", "max_line_length": 101, "max_stars_count": 2, "max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "nad/partiality-monad", "max_stars_repo_path": "src/Lambda/Virtual-machine.agda", "max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z", "max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z", "num_tokens": 618, "size": 2162 }
module Class.Equality where open import Data.Bool using (Bool; if_then_else_) open import Data.List open import Data.Product open import Relation.Nullary open import Relation.Nullary.Decidable open import Relation.Binary.PropositionalEquality record Eq (A : Set) : Set where field _≟_ : (x y : A) -> Dec (x ≡ y) open Eq {{...}} public record EqB (A : Set) : Set where field _≣_ : (x y : A) -> Bool decCase_of_default_ : ∀ {b} {B : Set b} -> A -> List (A × B) -> B -> B decCase a of [] default d = d decCase a of x ∷ xs default d = if a ≣ proj₁ x then proj₂ x else (decCase a of xs default d) open EqB {{...}} public Eq→EqB : ∀ {A} -> {{_ : Eq A}} -> EqB A Eq→EqB = record { _≣_ = λ x y -> ⌊ x ≟ y ⌋ }
{ "alphanum_fraction": 0.6212121212, "avg_line_length": 25.9285714286, "ext": "agda", "hexsha": "63dcc46b069c2eee28f1e7f7053b3dfc4752eb28", "lang": "Agda", "max_forks_count": 2, "max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z", "max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z", "max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "WhatisRT/meta-cedille", "max_forks_repo_path": "stdlib-exts/Class/Equality.agda", "max_issues_count": 10, "max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z", "max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z", "max_issues_repo_licenses": [ "MIT" ], "max_issues_repo_name": "WhatisRT/meta-cedille", "max_issues_repo_path": "stdlib-exts/Class/Equality.agda", "max_line_length": 94, "max_stars_count": 35, "max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "WhatisRT/meta-cedille", "max_stars_repo_path": "stdlib-exts/Class/Equality.agda", "max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z", "max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z", "num_tokens": 253, "size": 726 }
{-# OPTIONS --cubical --safe #-} module Cubical.HITs.RPn where open import Cubical.HITs.RPn.Base public
{ "alphanum_fraction": 0.7333333333, "avg_line_length": 21, "ext": "agda", "hexsha": "8a5ee85489605146abb0d1d637bfff20cc5e92e9", "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": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_forks_repo_licenses": [ "MIT" ], "max_forks_repo_name": "cmester0/cubical", "max_forks_repo_path": "Cubical/HITs/RPn.agda", "max_issues_count": null, "max_issues_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "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": "cmester0/cubical", "max_issues_repo_path": "Cubical/HITs/RPn.agda", "max_line_length": 40, "max_stars_count": 1, "max_stars_repo_head_hexsha": "c67854d2e11aafa5677e25a09087e176fafd3e43", "max_stars_repo_licenses": [ "MIT" ], "max_stars_repo_name": "cmester0/cubical", "max_stars_repo_path": "Cubical/HITs/RPn.agda", "max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z", "max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z", "num_tokens": 33, "size": 105 }