Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# POLARITY F #-}
| {
"alphanum_fraction": 0.4736842105,
"avg_line_length": 9.5,
"ext": "agda",
"hexsha": "3a721b24232f5379c71dbf74c7f4c9445936333c",
"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": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Fail/Unknown-name-in-polarity-pragma.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"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": "pthariensflame/agda",
"max_issues_repo_path": "test/Fail/Unknown-name-in-polarity-pragma.agda",
"max_line_length": 18,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Fail/Unknown-name-in-polarity-pragma.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": 6,
"size": 19
} |
module Imports.Issue1913-M where
data D : Set where
d : D
| {
"alphanum_fraction": 0.7049180328,
"avg_line_length": 12.2,
"ext": "agda",
"hexsha": "9e24000036980d1e259e94e233ddbacb9f6d764b",
"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/Imports/Issue1913-M.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/Imports/Issue1913-M.agda",
"max_line_length": 32,
"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/Imports/Issue1913-M.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": 61
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021 Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Base.PKCS
open import LibraBFT.Base.Types
import LibraBFT.Yasm.Base as LYB
-- This module provides a single import for all Yasm modules
module LibraBFT.Yasm.Yasm
(ℓ-EC : Level)
(EpochConfig : Set ℓ-EC)
(epochId : EpochConfig → EpochId)
(authorsN : EpochConfig → ℕ)
(parms : LYB.SystemParameters ℓ-EC EpochConfig epochId authorsN)
(senderPKOK : (ec : EpochConfig) → PK → LYB.SystemParameters.PeerId parms → Set)
where
open LYB.SystemParameters parms
open import LibraBFT.Yasm.AvailableEpochs PeerId ℓ-EC EpochConfig epochId authorsN
using (AvailableEpochs) renaming (lookup' to EC-lookup; lookup'' to EC-lookup') public
open import LibraBFT.Yasm.Base ℓ-EC EpochConfig epochId authorsN public
open import LibraBFT.Yasm.System ℓ-EC EpochConfig epochId authorsN parms public
open import LibraBFT.Yasm.Properties ℓ-EC EpochConfig epochId authorsN parms senderPKOK public
open import Util.FunctionOverride PeerId _≟PeerId_ public
| {
"alphanum_fraction": 0.7086671522,
"avg_line_length": 49.0357142857,
"ext": "agda",
"hexsha": "dc910eb4db889c24ee89fe92aa902bab5e02cf1d",
"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": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"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": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Yasm/Yasm.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 367,
"size": 1373
} |
module Vehicle.Data.Tensor where
open import Level using (Level)
open import Data.Empty.Polymorphic using (⊥)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.List.Base using (List; []; _∷_)
open import Data.Vec.Functional using (Vector)
private
variable
a : Level
A : Set a
n : ℕ
Tensor : Set a → List ℕ → Set a
Tensor A [] = ⊥
Tensor A (n ∷ []) = Vector A n
Tensor A (m ∷ n ∷ ns) = Vector (Tensor A (n ∷ ns)) m | {
"alphanum_fraction": 0.6339869281,
"avg_line_length": 24.1578947368,
"ext": "agda",
"hexsha": "a37ee9979fb3fd8f0d0bdfb8d0275018a1b8328f",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-11-16T14:30:47.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-03-15T15:22:31.000Z",
"max_forks_repo_head_hexsha": "25842faea65b4f7f0f7b1bb11ea6e4bf3f4a59b0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vehicle-lang/vehicle",
"max_forks_repo_path": "src/agda/Vehicle/Data/Tensor.agda",
"max_issues_count": 53,
"max_issues_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_issues_repo_issues_event_max_datetime": "2021-12-15T22:42:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-04-16T07:26:42.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "wenkokke/vehicle",
"max_issues_repo_path": "src/agda/Vehicle/Data/Tensor.agda",
"max_line_length": 52,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "41d8653d7e48a716f5085ec53171b29094669674",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "wenkokke/vehicle",
"max_stars_repo_path": "src/agda/Vehicle/Data/Tensor.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T01:35:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-24T05:55:15.000Z",
"num_tokens": 144,
"size": 459
} |
postulate
X A : Set
module Foo {{x : X}} where
postulate
B C : Set
foo : A → B → C → Set
module Bar {{x : X}} where
open Foo
postulate
-- The following fails to infer the instance argument if we do not either:
-- * apply {{x}} explicitly to foo
-- * apply {{x}} explicitly when opening module Foo
-- * define fail1 in module Foo
fail1 : ∀ {a b b' c c'} → foo a b c → foo a b' c'
-- However, the following works
work1 : ∀ {a b c} → foo a b c → foo a b c
work2 : ∀ {a a' b c} → foo a b c → foo a' b c
work3 : ∀ {a b b' c} → foo a b c → foo a b' c
work4 : ∀ {a a' b b' c} → foo a b c → foo a' b' c
work5 : ∀ {a b c c'} → foo a b c → foo a b c'
work6 : ∀ {a a' b c c'} → foo a b c → foo a' b c'
work7 : ∀ {a a' b b' c c'} → foo a b c → foo a' b' c'
data Nat : Set where
suc : Nat → Nat
instance
zero : Nat
instance
one = suc zero
data IsSuc : Nat → Set where
isSuc : ∀{n} → IsSuc (suc n)
postulate
F : {{x : Nat}} (p : IsSuc x) → Set
test = F isSuc -- yellow, but should not be
| {
"alphanum_fraction": 0.5251396648,
"avg_line_length": 23.8666666667,
"ext": "agda",
"hexsha": "763f9feab2a2a1e13e32b44f0764959e493a0703",
"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/Issue2325.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/Issue2325.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2325.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": 403,
"size": 1074
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.WedgeExtension
import homotopy.SuspAdjointLoop as SAL
module homotopy.Freudenthal where
{- lemma (move this where?) -}
private
move1-left-on-left : ∀ {i} {A : Type i} {x y : A} (p : x == y) (q : x == y)
→ ((! q) ∙ p == idp → p == q)
move1-left-on-left p idp h = h
module FreudenthalEquiv
{i} (n k : ℕ₋₂) (kle : k ≤T S n +2+ S n)
(X : Ptd i) {{cX : is-connected (S (S n)) (de⊙ X)}} where
Q : Susp (de⊙ X) → Type i
Q x = Trunc k (north == x)
⊙up : X ⊙→ ⊙Ω (⊙Susp (de⊙ X))
⊙up = SAL.η _
up = fst ⊙up
Codes-mer-args : args {a₀ = pt X} {b₀ = [_] {n = k} (pt X)}
Codes-mer-args = record {n = S n; m = S n;
P = λ _ _ → (Trunc k (de⊙ X) , raise-level-≤T kle Trunc-level);
f = [_]; g = idf _; p = idp}
module CodesExt =
WedgeExt {a₀ = pt X} {b₀ = [_] {n = k} (pt X)} Codes-mer-args
Codes-mer : de⊙ X → Trunc k (de⊙ X) → Trunc k (de⊙ X)
Codes-mer = CodesExt.ext
Codes-mer-β-l : (λ a → Codes-mer a [ pt X ]) == [_]
Codes-mer-β-l = λ= CodesExt.β-l
Codes-mer-β-r : (λ b → Codes-mer (pt X) b) == idf _
Codes-mer-β-r = λ= $ CodesExt.β-r
Codes-mer-coh : app= Codes-mer-β-l (pt X) == app= Codes-mer-β-r [ pt X ]
Codes-mer-coh =
app= Codes-mer-β-l (pt X)
=⟨ app=-β CodesExt.β-l (pt X) ⟩
CodesExt.β-l (pt X)
=⟨ ! (move1-left-on-left _ _ CodesExt.coh) ⟩
CodesExt.β-r [ pt X ]
=⟨ ! (app=-β CodesExt.β-r [ pt X ]) ⟩
app= Codes-mer-β-r [ pt X ] ∎
Codes-mer-is-equiv : (x : de⊙ X) → is-equiv (Codes-mer x)
Codes-mer-is-equiv =
conn-extend (pointed-conn-out {n = S n} (de⊙ X) (pt X))
(λ x' → (is-equiv (Codes-mer x') , is-equiv-level))
(λ tt → transport is-equiv (! (Codes-mer-β-r)) (idf-is-equiv _))
Codes-mer-equiv : (x : de⊙ X) → Trunc k (de⊙ X) ≃ Trunc k (de⊙ X)
Codes-mer-equiv x = (Codes-mer x , Codes-mer-is-equiv x)
Codes-mer-inv-x₀ : <– (Codes-mer-equiv (pt X)) == idf _
Codes-mer-inv-x₀ =
ap is-equiv.g (conn-extend-β
(pointed-conn-out (de⊙ X) (pt X))
(λ x' → (is-equiv (Codes-mer x') , is-equiv-level))
_ unit)
∙ lemma (! (Codes-mer-β-r)) (snd $ ide _)
where lemma : ∀ {i j} {A : Type i} {B : Type j} {f g : A → B}
(α : f == g) (e : is-equiv f)
→ is-equiv.g (transport is-equiv α e) == is-equiv.g e
lemma idp e = idp
module CodesRec = SuspRec (Trunc k (de⊙ X)) (Trunc k (de⊙ X)) (ua ∘ Codes-mer-equiv)
Codes : Susp (de⊙ X) → Type i
Codes = CodesRec.f
Codes-has-level : (x : Susp (de⊙ X)) → has-level k (Codes x)
Codes-has-level = Susp-elim Trunc-level Trunc-level
(λ _ → prop-has-all-paths-↓)
{-
favonia:
This equation should be true: [⊙Trunc-fmap ⊙up = (decodeN , decodeN-pt)].
Maybe there is a way to refactor the following code so that
pointedness is handled more elegantly.
-}
decodeN : Codes north → Trunc k (north' (de⊙ X) == north)
decodeN = Trunc-fmap up
decodeN-pt : decodeN [ pt X ] == [ idp ]
decodeN-pt = snd (⊙Trunc-fmap ⊙up)
decodeS : Codes south → Q south
decodeS = Trunc-fmap merid
encode₀ : {x : Susp (de⊙ X)} → north == x → Codes x
encode₀ α = transport Codes α [ pt X ]
encode : {x : Susp (de⊙ X)} → Trunc k (north == x) → Codes x
encode {x} tα = Trunc-rec {{Codes-has-level x}} encode₀ tα
⊙decodeN : ⊙Trunc k X ⊙→ ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))
⊙decodeN = decodeN , ap [_] (!-inv-r (merid (pt X)))
⊙encodeN : ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X))) ⊙→ ⊙Trunc k X
⊙encodeN = encode , idp
abstract
encode-decodeN : (c : Codes north) → encode (decodeN c) == c
encode-decodeN = Trunc-elim
{{λ _ → =-preserves-level Trunc-level}}
(λ x →
encode (decodeN [ x ])
=⟨ idp ⟩
coe (ap Codes (merid x ∙ ! (merid (pt X)))) [ pt X ]
=⟨ ap-∙ Codes (merid x) (! (merid (pt X))) |in-ctx (λ w → coe w [ pt X ]) ⟩
coe (ap Codes (merid x) ∙ ap Codes (! (merid (pt X)))) [ pt X ]
=⟨ coe-∙ (ap Codes (merid x)) (ap Codes (! (merid (pt X)))) [ pt X ] ⟩
coe (ap Codes (! (merid (pt X)))) (coe (ap Codes (merid x)) [ pt X ])
=⟨ SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) x
|in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) (coe w [ pt X ])) ⟩
coe (ap Codes (! (merid (pt X)))) (coe (ua (Codes-mer-equiv x)) [ pt X ])
=⟨ coe-β (Codes-mer-equiv x) [ pt X ]
|in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) w) ⟩
coe (ap Codes (! (merid (pt X)))) (Codes-mer x [ pt X ])
=⟨ app= Codes-mer-β-l x
|in-ctx (λ w → coe (ap Codes (! (merid (pt X)))) w) ⟩
coe (ap Codes (! (merid (pt X)))) [ x ]
=⟨ coe-ap-! Codes (merid (pt X)) [ x ] ⟩
coe! (ap Codes (merid (pt X))) [ x ]
=⟨ SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X)
|in-ctx (λ w → coe! w [ x ]) ⟩
coe! (ua (Codes-mer-equiv (pt X))) [ x ]
=⟨ coe!-β (Codes-mer-equiv (pt X)) [ x ] ⟩
<– (Codes-mer-equiv (pt X)) [ x ]
=⟨ app= Codes-mer-inv-x₀ [ x ] ⟩
[ x ] ∎)
decode : {x : Susp (de⊙ X)} → Codes x → Q x
decode {x} = Susp-elim
{P = λ y → Codes y → Q y}
decodeN decodeS
(λ x' → ↓-→-from-transp (λ= (STS x')))
x
where
abstract
coh : {s₁ s₂ : Susp (de⊙ X)} (p : s₁ == s₂)
→ (ap (λ s → s ∙ p) (!-inv-r p))
== ∙-assoc p (! p) p ∙ ap (λ s → p ∙ s) (!-inv-l p) ∙ ∙-unit-r p
coh idp = idp
P : de⊙ X → de⊙ X → (S (n +2+ (S n))) -Type (lmax i i)
P = λ x₁ x₂ →
((transport Q (merid x₁) (Trunc-fmap up [ x₂ ])
== Trunc-fmap merid (transport Codes (merid x₁) [ x₂ ])),
=-preserves-level (raise-level-≤T kle Trunc-level))
f : (a : de⊙ X) → fst (P a (pt X))
f a =
transport Q (merid a) [ up (pt X) ]
=⟨ transport-Trunc' (north ==_) (merid a) (up (pt X)) ⟩
[ transport (north ==_) (merid a) (up (pt X)) ]
=⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid a) (up (pt X)) ⟩
[ (merid (pt X) ∙ ! (merid (pt X))) ∙ merid a ]
=⟨ ap [_] $ ap (λ s → s ∙ merid a) (!-inv-r (merid (pt X))) ⟩
[ merid a ]
=⟨ idp ⟩
Trunc-fmap merid [ a ]
=⟨ ap (Trunc-fmap merid) (! (app= Codes-mer-β-l a)) ⟩
Trunc-fmap merid (Codes-mer a [ pt X ])
=⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv a) [ pt X ])) ⟩
Trunc-fmap merid (coe (ua (Codes-mer-equiv a)) [ pt X ])
=⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) a)
|in-ctx (λ w → Trunc-fmap merid (coe w [ pt X ])) ⟩
Trunc-fmap merid (transport Codes (merid a) [ pt X ]) ∎
g : (b : de⊙ X) → fst (P (pt X) b)
g b =
transport Q (merid (pt X)) [ up b ]
=⟨ transport-Trunc' (north ==_) (merid (pt X)) (up b) ⟩
[ transport (north ==_) (merid (pt X)) (up b) ]
=⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid (pt X)) (up b) ⟩
[ (merid b ∙ ! (merid (pt X))) ∙ merid (pt X) ]
=⟨ ap [_] $ ∙-assoc (merid b) (! (merid (pt X))) (merid (pt X))
∙ ap (λ s → merid b ∙ s) (!-inv-l (merid (pt X)))
∙ ∙-unit-r (merid b) ⟩
[ merid b ]
=⟨ idp ⟩
Trunc-fmap merid [ b ]
=⟨ ap (Trunc-fmap merid) (! (app= Codes-mer-β-r [ b ])) ⟩
Trunc-fmap merid (Codes-mer (pt X) [ b ])
=⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv (pt X)) [ b ])) ⟩
Trunc-fmap merid (coe (ua (Codes-mer-equiv (pt X))) [ b ])
=⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X))
|in-ctx (λ w → Trunc-fmap merid (coe w [ b ])) ⟩
Trunc-fmap merid (transport Codes (merid (pt X)) [ b ]) ∎
p : f (pt X) == g (pt X)
p = ap2
(λ p₁ p₂ →
transport Q (merid (pt X)) [ up (pt X) ]
=⟨ transport-Trunc' (north ==_) (merid (pt X)) (up (pt X)) ⟩
[ transport (north ==_) (merid (pt X)) (up (pt X)) ]
=⟨ ap [_] $ transp-cst=idf {A = Susp (de⊙ X)} (merid (pt X)) (up (pt X)) ⟩
[ (merid (pt X) ∙ ! (merid (pt X))) ∙ merid (pt X) ]
=⟨ ap [_] p₁ ⟩
[ merid (pt X) ]
=⟨ idp ⟩
Trunc-fmap merid [ pt X ]
=⟨ ap (Trunc-fmap merid) (! p₂) ⟩
Trunc-fmap merid (Codes-mer (pt X) [ pt X ])
=⟨ ap (Trunc-fmap merid) (! (coe-β (Codes-mer-equiv (pt X)) [ pt X ])) ⟩
Trunc-fmap merid (coe (ua (Codes-mer-equiv (pt X))) [ pt X ])
=⟨ ! (SuspRec.merid-β _ _ (ua ∘ Codes-mer-equiv) (pt X))
|in-ctx (λ w → Trunc-fmap merid (coe w [ pt X ])) ⟩
Trunc-fmap merid (transport Codes (merid (pt X)) [ pt X ]) ∎)
(coh (merid (pt X))) Codes-mer-coh
STS-args : args {a₀ = pt X} {b₀ = pt X}
STS-args =
record {n = S n; m = S n; P = P; f = f; g = g; p = p}
STS : (x' : de⊙ X) (c : Codes north) →
transport Q (merid x') (Trunc-fmap up c)
== Trunc-fmap merid (transport Codes (merid x') c)
STS x' = Trunc-elim {{λ _ → =-preserves-level Trunc-level}}
(WedgeExt.ext STS-args x')
abstract
decode-encode : {x : Susp (de⊙ X)} (tα : Q x)
→ decode {x} (encode {x} tα) == tα
decode-encode {x} = Trunc-elim
{P = λ tα → decode {x} (encode {x} tα) == tα}
{{λ _ → =-preserves-level Trunc-level}}
(J (λ y p → decode {y} (encode {y} [ p ]) == [ p ])
(ap [_] (!-inv-r (merid (pt X)))))
eq : Trunc k (de⊙ X) ≃ Trunc k (north' (de⊙ X) == north)
eq = equiv decodeN encode decode-encode encode-decodeN
⊙eq : ⊙Trunc k X ⊙≃ ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))
⊙eq = ≃-to-⊙≃ eq (snd ⊙decodeN)
abstract
⊙decodeN-⊙encodeN : ⊙decodeN ⊙∘ ⊙encodeN == ⊙idf _
⊙decodeN-⊙encodeN =
⊙λ=' {X = ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))}
{Y = ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))}
decode-encode $
↓-idf=cst-in $
! (∙-unit-r (ap [_] (!-inv-r (merid (pt X)))))
⊙<–-⊙eq : ⊙<– ⊙eq == ⊙encodeN
⊙<–-⊙eq =
–>-is-inj (post⊙∘-equiv {Z = ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))} ⊙eq) (⊙<– ⊙eq) ⊙encodeN $
⊙decodeN ⊙∘ ⊙<– ⊙eq
=⟨ ⊙<–-inv-r ⊙eq ⟩
⊙idf _
=⟨ ! ⊙decodeN-⊙encodeN ⟩
⊙decodeN ⊙∘ ⊙encodeN =∎
path : Trunc k (de⊙ X) == Trunc k (north' (de⊙ X) == north)
path = ua eq
⊙path : ⊙Trunc k X == ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))
⊙path = ⊙ua ⊙eq
{- timjb: it is probably easier to show the naturality of ⊙decodeN
and deduce the naturality of ⊙encodeN from that than to show
the naturality of ⊙encodeN directly (as done below) -}
module FreudenthalEquivNatural
{i} (n k : ℕ₋₂) (kle : k ≤T S n +2+ S n)
{X Y : Ptd i} (f : X ⊙→ Y)
{{cX : is-connected (S (S n)) (de⊙ X)}}
{{cY : is-connected (S (S n)) (de⊙ Y)}} where
private
module FX = FreudenthalEquiv n k kle X {{cX}}
module FY = FreudenthalEquiv n k kle Y {{cY}}
Codes-mer-map : ∀ (x : de⊙ X) (tx : Trunc k (de⊙ X))
→ Trunc-fmap (fst f) (FX.Codes-mer x tx) ==
FY.Codes-mer (fst f x) (Trunc-fmap (fst f) tx)
Codes-mer-map =
WedgeExt.ext {A = de⊙ X} {a₀ = pt X} {B = Trunc k (de⊙ X)} {b₀ = [ pt X ]} $
record
{ n = S n; m = S n
; P = λ x tx → (P x tx , P-level x tx)
; f = λ x → ↯ (f-seq x)
; g = λ tx → ↯ (g-seq tx)
; p = =ₛ-out p
}
where
P : de⊙ X → Trunc k (de⊙ X) → Type i
P x tx =
Trunc-fmap (fst f) (FX.Codes-mer x tx) ==
FY.Codes-mer (fst f x) (Trunc-fmap (fst f) tx)
P-level : ∀ x tx → has-level (S n +2+ S n) (P x tx)
P-level x tx = =-preserves-level (raise-level-≤T kle Trunc-level)
f-seq : ∀ x → Trunc-fmap (fst f) (FX.Codes-mer x [ pt X ]) =-=
FY.Codes-mer (fst f x) (Trunc-fmap (fst f) [ pt X ])
f-seq x =
Trunc-fmap (fst f) (FX.Codes-mer x [ pt X ])
=⟪ ap (Trunc-fmap (fst f)) (FX.CodesExt.β-l x) ⟫
[ fst f x ]
=⟪ ! (FY.CodesExt.β-l (fst f x)) ⟫
FY.Codes-mer (fst f x) [ pt Y ]
=⟪ ap (FY.Codes-mer (fst f x) ∘ [_]) (! (snd f)) ⟫
FY.Codes-mer (fst f x) [ fst f (pt X) ] ∎∎
g-seq : ∀ tx → Trunc-fmap (fst f) (FX.Codes-mer (pt X) tx) =-=
FY.Codes-mer (fst f (pt X)) (Trunc-fmap (fst f) tx)
g-seq tx =
Trunc-fmap (fst f) (FX.Codes-mer (pt X) tx)
=⟪ ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r tx) ⟫
Trunc-fmap (fst f) tx
=⟪ ! (FY.CodesExt.β-r (Trunc-fmap (fst f) tx)) ⟫
FY.Codes-mer (pt Y) (Trunc-fmap (fst f) tx)
=⟪ ap (λ y → FY.Codes-mer y (Trunc-fmap (fst f) tx)) (! (snd f)) ⟫
FY.Codes-mer (fst f (pt X)) (Trunc-fmap (fst f) tx) ∎∎
p : f-seq (pt X) =ₛ g-seq [ pt X ]
p =
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-l (pt X)) ◃∙
! (FY.CodesExt.β-l (fst f (pt X))) ◃∙
ap (FY.Codes-mer (fst f (pt X)) ∘ [_]) (! (snd f)) ◃∎
=ₛ⟨ 0 & 1 & ap-seq-=ₛ (Trunc-fmap (fst f)) $
pre-rotate-out {p = FX.CodesExt.β-l (pt X)} {q = []} {r = FX.CodesExt.β-r [ pt X ] ◃∎} $
=ₛ-in $ ! $ FX.CodesExt.coh ⟩
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r [ pt X ]) ◃∙
! (FY.CodesExt.β-l (fst f (pt X))) ◃∙
ap (FY.Codes-mer (fst f (pt X)) ∘ [_]) (! (snd f)) ◃∎
=ₛ⟨ 1 & 1 & pre-rotate-in $
homotopy-naturality
[_]
(λ y → FY.Codes-mer y [ pt Y ])
(! ∘ FY.CodesExt.β-l)
(! (snd f)) ⟩
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r [ pt X ]) ◃∙
! (ap [_] (! (snd f))) ◃∙
! (FY.CodesExt.β-l (pt Y)) ◃∙
ap (λ y → FY.Codes-mer y [ pt Y ]) (! (snd f)) ◃∙
ap (FY.Codes-mer (fst f (pt X)) ∘ [_]) (! (snd f)) ◃∎
=ₛ⟨ 3 & 2 & ap-comm-=ₛ (λ y y' → FY.Codes-mer y [ y' ]) (! (snd f)) (! (snd f)) ⟩
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r [ pt X ]) ◃∙
! (ap [_] (! (snd f))) ◃∙
! (FY.CodesExt.β-l (pt Y)) ◃∙
ap (λ y → FY.Codes-mer (pt Y) [ y ]) (! (snd f)) ◃∙
ap (λ y → FY.Codes-mer y [ fst f (pt X) ]) (! (snd f)) ◃∎
=ₛ⟨ 2 & 1 & !-=ₛ $
pre-rotate-out {p = FY.CodesExt.β-l (pt Y)} {q = []} {r = FY.CodesExt.β-r [ pt Y ] ◃∎} $
=ₛ-in $ ! $ FY.CodesExt.coh ⟩
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r [ pt X ]) ◃∙
! (ap [_] (! (snd f))) ◃∙
! (FY.CodesExt.β-r [ pt Y ]) ◃∙
ap (λ y → FY.Codes-mer (pt Y) [ y ]) (! (snd f)) ◃∙
ap (λ y → FY.Codes-mer y [ fst f (pt X) ]) (! (snd f)) ◃∎
=ₛ⟨ 1 & 3 & !ₛ $ pre-rotate-in $
homotopy-naturality
[_]
(FY.Codes-mer (pt Y) ∘ [_])
(! ∘ FY.CodesExt.β-r ∘ [_])
(! (snd f)) ⟩
ap (Trunc-fmap (fst f)) (FX.CodesExt.β-r [ pt X ]) ◃∙
! (FY.CodesExt.β-r (Trunc-fmap (fst f) [ pt X ])) ◃∙
ap (λ y → FY.Codes-mer y [ fst f (pt X) ]) (! (snd f)) ◃∎ ∎ₛ
Codes-fmap : ∀ {x : Susp (de⊙ X)}
→ FX.Codes x
→ FY.Codes (Susp-fmap (fst f) x)
Codes-fmap {x} =
Susp-elim
{P = λ x → FX.Codes x → FY.Codes (Susp-fmap (fst f) x)}
(Trunc-fmap (fst f))
(Trunc-fmap (fst f))
(λ x → ↓-→-from-transp $ λ= $
Trunc-elim {{λ tx → =-preserves-level Trunc-level}} $ λ x' →
transport (FY.Codes ∘ Susp-fmap (fst f)) (merid x) [ fst f x' ]
=⟨ ap (λ q → coe q [ fst f x' ]) (ap-∘ FY.Codes (Susp-fmap (fst f)) (merid x)) ⟩
transport FY.Codes (ap (Susp-fmap (fst f)) (merid x)) [ fst f x' ]
=⟨ ap (λ p → transport FY.Codes p [ fst f x' ]) $
SuspFmap.merid-β (fst f) x ⟩
transport FY.Codes (merid (fst f x)) [ fst f x' ]
=⟨ ap (λ p → coe p [ fst f x' ]) (FY.CodesRec.merid-β (fst f x)) ⟩
coe (ua (FY.Codes-mer-equiv (fst f x))) [ fst f x' ]
=⟨ coe-β (FY.Codes-mer-equiv (fst f x)) [ fst f x' ] ⟩
FY.Codes-mer (fst f x) [ fst f x' ]
=⟨ ! (Codes-mer-map x [ x' ]) ⟩
Trunc-fmap (fst f) (FX.Codes-mer x [ x' ])
=⟨ ap (Trunc-fmap (fst f)) (! (coe-β (FX.Codes-mer-equiv x) [ x' ])) ⟩
Trunc-fmap (fst f) (coe (ua (FX.Codes-mer-equiv x)) [ x' ])
=⟨ ap (λ p → Trunc-fmap (fst f) (coe p [ x' ])) (! (FX.CodesRec.merid-β x)) ⟩
Trunc-fmap (fst f) (transport FX.Codes (merid x) [ x' ]) =∎)
x
encode-natural : ∀ {x : Susp (de⊙ X)}
(tα : Trunc k (north == x))
→ FY.encode (Trunc-fmap (ap (Susp-fmap (fst f))) tα)
==
Codes-fmap {x} (FX.encode tα)
encode-natural {x} =
Trunc-elim {{λ tα → =-preserves-level (FY.Codes-has-level (Susp-fmap (fst f) x))}} $
J (λ x p → FY.encode (Trunc-fmap (ap (Susp-fmap (fst f))) [ p ]) == Codes-fmap {x} (FX.encode [ p ])) $
! (ap [_] (snd f))
⊙encodeN-natural :
FY.⊙encodeN ◃⊙∘
⊙Trunc-fmap (⊙Ω-fmap (⊙Susp-fmap (fst f))) ◃⊙idf
=⊙∘
⊙Trunc-fmap f ◃⊙∘
FX.⊙encodeN ◃⊙idf
⊙encodeN-natural =
=⊙∘-in $
⊙λ=' {X = ⊙Trunc k (⊙Ω (⊙Susp (de⊙ X)))} {Y = ⊙Trunc k Y} (encode-natural {north}) $
↓-idf=cst-in {p = ! (ap [_] (snd f))} $
! $ !-inv-l (ap [_] (snd f))
{- Used to prove stability in iterated suspensions -}
module FreudenthalIso
{i} (n : ℕ₋₂) (k : ℕ) (kle : ⟨ S k ⟩ ≤T S n +2+ S n)
(X : Ptd i) {{_ : is-connected (S (S n)) (de⊙ X)}} where
open FreudenthalEquiv n ⟨ S k ⟩ kle X public
hom : Ω^S-group k (⊙Trunc ⟨ S k ⟩ X)
→ᴳ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Ω (⊙Susp (de⊙ X))))
hom = Ω^S-group-fmap k (decodeN , decodeN-pt)
iso : Ω^S-group k (⊙Trunc ⟨ S k ⟩ X)
≃ᴳ Ω^S-group k (⊙Trunc ⟨ S k ⟩ (⊙Ω (⊙Susp (de⊙ X))))
iso = Ω^S-group-emap k ⊙eq
| {
"alphanum_fraction": 0.4734616923,
"avg_line_length": 40.2367816092,
"ext": "agda",
"hexsha": "078cbbccd5e27f73c853c702e01853f8ed590536",
"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": "theorems/homotopy/Freudenthal.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": "theorems/homotopy/Freudenthal.agda",
"max_line_length": 108,
"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": "theorems/homotopy/Freudenthal.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": 7416,
"size": 17503
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.List.Relation.Binary.Equality.Setoid directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Setoid)
module Data.List.Relation.Equality.Setoid {a ℓ} (S : Setoid a ℓ) where
open import Data.List.Relation.Binary.Equality.Setoid S public
{-# WARNING_ON_IMPORT
"Data.List.Relation.Equality.Setoid was deprecated in v1.0.
Use Data.List.Relation.Binary.Equality.Setoid instead."
#-}
| {
"alphanum_fraction": 0.579778831,
"avg_line_length": 31.65,
"ext": "agda",
"hexsha": "ee14f6cb799af6e8507634839d3308f747bc3238",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Equality/Setoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Equality/Setoid.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Equality/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-10T21:41:32.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T12:07:53.000Z",
"num_tokens": 127,
"size": 633
} |
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
data ⊥ : Set where
postulate
T : Set
t0 : T
t1 : T
postulate
foo : ⊥ → t0 ≡ t1
{-# REWRITE foo #-}
test : t0 ≡ t1
test = refl
| {
"alphanum_fraction": 0.6285714286,
"avg_line_length": 12.8947368421,
"ext": "agda",
"hexsha": "39e3e950bcf0c59bb227ee8f23da272657f64490",
"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/Issue5238.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/Issue5238.agda",
"max_line_length": 41,
"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/Issue5238.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": 90,
"size": 245
} |
open import Common.Prelude
open import Common.Reflection
data D (A : Set) : Nat → Set where
d : ∀ {n} → A → D A n
term : Term
term = con (quote d) (hArg (def (quote Nat) []) ∷ vArg (con (quote zero) []) ∷ [])
-- There was a bug where extra implicit arguments were inserted for the parameters, resulting in
-- the unquoted value 'd {_} {Nat} zero' instead of 'd {Nat} zero'.
value : D Nat zero
value = unquote (give term)
| {
"alphanum_fraction": 0.6557377049,
"avg_line_length": 28.4666666667,
"ext": "agda",
"hexsha": "fa8a4221ef63b052e467797bbdd228b078cc3df5",
"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/Issue1237.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/Issue1237.agda",
"max_line_length": 96,
"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/Issue1237.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": 129,
"size": 427
} |
{-# OPTIONS --cubical --safe #-}
module Data.Empty.Base where
open import Cubical.Data.Empty using (⊥; ⊥-elim; isProp⊥) public
open import Level
infix 4.5 ¬_
¬_ : Type a → Type a
¬ A = A → ⊥
| {
"alphanum_fraction": 0.6443298969,
"avg_line_length": 17.6363636364,
"ext": "agda",
"hexsha": "3f3223ca434efd65f9808da438ddbc50140fee0b",
"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": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Empty/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Empty/Base.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Empty/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 69,
"size": 194
} |
-- Andreas, 2016-06-20
-- Issue #1653 reported by Jesper
-- Fixed by Ulf's AIM XXIII code sprint "instantiating module parameters"
open import Common.Equality
module _ (A : Set₁) where
-- Matching on refl works with new instantiateable module parameters.
test : A ≡ Set → Set₁
test refl = A
-- Case splitting thus should also work.
foo : A ≡ Set → Set₁
foo e = {!e!} -- C-c C-c
| {
"alphanum_fraction": 0.6767676768,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "36611a2443d2629871665523a8cbc633459fc9ba",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue1653.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue1653.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1653.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": 118,
"size": 396
} |
open import Algebra.Apartness using (HeytingField)
module Data.Real.Abstract.Bundles
c ℓ₁ ℓ₂ r
where
open import Relation.Binary using (Rel)
open import Data.Real.Abstract.Structures
open import Level using (_⊔_; suc)
record OrderedHeytingField : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂ ⊔ r)) where
field
f : HeytingField c ℓ₁ ℓ₂
open HeytingField f public
field
_<_ : Rel Carrier r
isOrderedHeytingField : IsOrderedHeytingField f _<_
record ArchimedanHeytingField : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂ ⊔ r)) where
field
f : HeytingField c ℓ₁ ℓ₂
open HeytingField f public
field
_<_ : Rel Carrier r
isArchimedanHeytingField : IsArchimedanHeytingField f _<_
| {
"alphanum_fraction": 0.7193500739,
"avg_line_length": 22.5666666667,
"ext": "agda",
"hexsha": "d93e3e6c46cfddbb05026d3d477ee73c3b07e2b4",
"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": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "cspollard/reals",
"max_forks_repo_path": "src/Data/Real/Abstract/Bundles.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"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": "cspollard/reals",
"max_issues_repo_path": "src/Data/Real/Abstract/Bundles.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a193aeebf1326f960975b19d3e31b46fddbbfaa2",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "cspollard/reals",
"max_stars_repo_path": "src/Data/Real/Abstract/Bundles.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 225,
"size": 677
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Rationals.QuoQ.Properties where
open import Cubical.Foundations.Everything hiding (_⁻¹)
open import Cubical.HITs.Ints.QuoInt as ℤ using (ℤ; Sign; signed; pos; neg; posneg; sign)
open import Cubical.HITs.SetQuotients as SetQuotient using () renaming (_/_ to _//_)
open import Cubical.Data.Nat as ℕ using (ℕ; zero; suc)
open import Cubical.Data.NatPlusOne
open import Cubical.Data.Sigma
open import Cubical.Data.Sum
open import Cubical.Relation.Nullary
open import Cubical.HITs.Rationals.QuoQ.Base
ℚ-cancelˡ : ∀ {a b} (c : ℕ₊₁) → [ ℕ₊₁→ℤ c ℤ.· a / c ·₊₁ b ] ≡ [ a / b ]
ℚ-cancelˡ {a} {b} c = eq/ _ _
(cong (ℤ._· ℕ₊₁→ℤ b) (ℤ.·-comm (ℕ₊₁→ℤ c) a) ∙ sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))
ℚ-cancelʳ : ∀ {a b} (c : ℕ₊₁) → [ a ℤ.· ℕ₊₁→ℤ c / b ·₊₁ c ] ≡ [ a / b ]
ℚ-cancelʳ {a} {b} c = eq/ _ _
(sym (ℤ.·-assoc a (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)) ∙ cong (a ℤ.·_) (ℤ.·-comm (ℕ₊₁→ℤ c) (ℕ₊₁→ℤ b)))
-- useful functions for defining operations on ℚ
onCommonDenom :
(g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)
(g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))
(g-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d)
→ ℚ → ℚ → ℚ
onCommonDenom g g-eql g-eqr = SetQuotient.rec2 isSetℚ
(λ { (a , b) (c , d) → [ g (a , b) (c , d) / b ·₊₁ d ] })
(λ { (a , b) (c , d) (e , f) p → eql (a , b) (c , d) (e , f) p })
(λ { (a , b) (c , d) (e , f) p → eqr (a , b) (c , d) (e , f) p })
where eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ [ g (a , b) (e , f) / b ·₊₁ f ] ≡ [ g (c , d) (e , f) / d ·₊₁ f ]
eql (a , b) (c , d) (e , f) p =
[ g (a , b) (e , f) / b ·₊₁ f ]
≡⟨ sym (ℚ-cancelˡ d) ⟩
[ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / d ·₊₁ (b ·₊₁ f) ]
≡[ i ]⟨ [ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / ·₊₁-assoc d b f i ] ⟩
[ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) / (d ·₊₁ b) ·₊₁ f ]
≡[ i ]⟨ [ g-eql (a , b) (c , d) (e , f) p i / ·₊₁-comm d b i ·₊₁ f ] ⟩
[ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / (b ·₊₁ d) ·₊₁ f ]
≡[ i ]⟨ [ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / ·₊₁-assoc b d f (~ i) ] ⟩
[ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)) / b ·₊₁ (d ·₊₁ f) ]
≡⟨ ℚ-cancelˡ b ⟩
[ g (c , d) (e , f) / d ·₊₁ f ] ∎
eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ [ g (a , b) (c , d) / b ·₊₁ d ] ≡ [ g (a , b) (e , f) / b ·₊₁ f ]
eqr (a , b) (c , d) (e , f) p =
[ g (a , b) (c , d) / b ·₊₁ d ]
≡⟨ sym (ℚ-cancelʳ f) ⟩
[ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / (b ·₊₁ d) ·₊₁ f ]
≡[ i ]⟨ [ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / ·₊₁-assoc b d f (~ i) ] ⟩
[ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f / b ·₊₁ (d ·₊₁ f) ]
≡[ i ]⟨ [ g-eqr (a , b) (c , d) (e , f) p i / b ·₊₁ ·₊₁-comm d f i ] ⟩
[ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / b ·₊₁ (f ·₊₁ d) ]
≡[ i ]⟨ [ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / ·₊₁-assoc b f d i ] ⟩
[ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d / (b ·₊₁ f) ·₊₁ d ]
≡⟨ ℚ-cancelʳ d ⟩
[ g (a , b) (e , f) / b ·₊₁ f ] ∎
onCommonDenomSym :
(g : ℤ × ℕ₊₁ → ℤ × ℕ₊₁ → ℤ)
(g-sym : ∀ x y → g x y ≡ g y x)
(g-eql : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : a ℤ.· ℕ₊₁→ℤ d ≡ c ℤ.· ℕ₊₁→ℤ b)
→ ℕ₊₁→ℤ d ℤ.· (g (a , b) (e , f)) ≡ ℕ₊₁→ℤ b ℤ.· (g (c , d) (e , f)))
→ ℚ → ℚ → ℚ
onCommonDenomSym g g-sym g-eql = onCommonDenom g g-eql q-eqr
where q-eqr : ∀ ((a , b) (c , d) (e , f) : ℤ × ℕ₊₁) (p : c ℤ.· ℕ₊₁→ℤ f ≡ e ℤ.· ℕ₊₁→ℤ d)
→ (g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡ (g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d
q-eqr (a , b) (c , d) (e , f) p =
(g (a , b) (c , d)) ℤ.· ℕ₊₁→ℤ f ≡[ i ]⟨ ℤ.·-comm (g-sym (a , b) (c , d) i) (ℕ₊₁→ℤ f) i ⟩
ℕ₊₁→ℤ f ℤ.· (g (c , d) (a , b)) ≡⟨ g-eql (c , d) (e , f) (a , b) p ⟩
ℕ₊₁→ℤ d ℤ.· (g (e , f) (a , b)) ≡[ i ]⟨ ℤ.·-comm (ℕ₊₁→ℤ d) (g-sym (e , f) (a , b) i) i ⟩
(g (a , b) (e , f)) ℤ.· ℕ₊₁→ℤ d ∎
onCommonDenomSym-comm : ∀ {g} g-sym {g-eql} (x y : ℚ)
→ onCommonDenomSym g g-sym g-eql x y ≡
onCommonDenomSym g g-sym g-eql y x
onCommonDenomSym-comm g-sym = SetQuotient.elimProp2 (λ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) i → [ g-sym (a , b) (c , d) i / ·₊₁-comm b d i ] })
-- basic arithmetic operations on ℚ
infixl 6 _+_
infixl 7 _·_
private
lem₁ : ∀ a b c d e (p : a ℤ.· b ≡ c ℤ.· d) → b ℤ.· (a ℤ.· e) ≡ d ℤ.· (c ℤ.· e)
lem₁ a b c d e p = ℤ.·-assoc b a e
∙ cong (ℤ._· e) (ℤ.·-comm b a ∙ p ∙ ℤ.·-comm c d)
∙ sym (ℤ.·-assoc d c e)
lem₂ : ∀ a b c → a ℤ.· (b ℤ.· c) ≡ c ℤ.· (b ℤ.· a)
lem₂ a b c = cong (a ℤ.·_) (ℤ.·-comm b c) ∙ ℤ.·-assoc a c b
∙ cong (ℤ._· b) (ℤ.·-comm a c) ∙ sym (ℤ.·-assoc c a b)
∙ cong (c ℤ.·_) (ℤ.·-comm a b)
_+_ : ℚ → ℚ → ℚ
_+_ = onCommonDenomSym
(λ { (a , b) (c , d) → a ℤ.· (ℕ₊₁→ℤ d) ℤ.+ c ℤ.· (ℕ₊₁→ℤ b) })
(λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })
(λ { (a , b) (c , d) (e , f) p →
ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ b)
≡⟨ sym (ℤ.·-distribˡ (ℕ₊₁→ℤ d) (a ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ b)) ⟩
ℕ₊₁→ℤ d ℤ.· (a ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ d ℤ.· (e ℤ.· ℕ₊₁→ℤ b)
≡[ i ]⟨ lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) p i ℤ.+ lem₂ (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ b) i ⟩
ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ ℕ₊₁→ℤ b ℤ.· (e ℤ.· ℕ₊₁→ℤ d)
≡⟨ ℤ.·-distribˡ (ℕ₊₁→ℤ b) (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) ⟩
ℕ₊₁→ℤ b ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d) ∎ })
+-comm : ∀ x y → x + y ≡ y + x
+-comm = onCommonDenomSym-comm
(λ { (a , b) (c , d) → ℤ.+-comm (a ℤ.· (ℕ₊₁→ℤ d)) (c ℤ.· (ℕ₊₁→ℤ b)) })
+-identityˡ : ∀ x → 0 + x ≡ x
+-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityˡ b i ] })
+-identityʳ : ∀ x → x + 0 ≡ x
+-identityʳ x = +-comm x _ ∙ +-identityˡ x
+-assoc : ∀ x y z → x + (y + z) ≡ (x + y) + z
+-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) i → [ eq a (ℕ₊₁→ℤ b) c (ℕ₊₁→ℤ d) e (ℕ₊₁→ℤ f) i / ·₊₁-assoc b d f i ] })
where eq₁ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ a ℤ.· (c ℤ.· b)
eq₁ a b c = sym (ℤ.·-assoc a b c) ∙ cong (a ℤ.·_) (ℤ.·-comm b c)
eq₂ : ∀ a b c → (a ℤ.· b) ℤ.· c ≡ (a ℤ.· c) ℤ.· b
eq₂ a b c = eq₁ a b c ∙ ℤ.·-assoc a c b
eq : ∀ a b c d e f → Path ℤ _ _
eq a b c d e f =
a ℤ.· (d ℤ.· f) ℤ.+ (c ℤ.· f ℤ.+ e ℤ.· d) ℤ.· b
≡[ i ]⟨ a ℤ.· (d ℤ.· f) ℤ.+ ℤ.·-distribʳ (c ℤ.· f) (e ℤ.· d) b (~ i) ⟩
a ℤ.· (d ℤ.· f) ℤ.+ ((c ℤ.· f) ℤ.· b ℤ.+ (e ℤ.· d) ℤ.· b)
≡[ i ]⟨ ℤ.+-assoc (ℤ.·-assoc a d f i) (eq₂ c f b i) (eq₁ e d b i) i ⟩
((a ℤ.· d) ℤ.· f ℤ.+ (c ℤ.· b) ℤ.· f) ℤ.+ e ℤ.· (b ℤ.· d)
≡[ i ]⟨ ℤ.·-distribʳ (a ℤ.· d) (c ℤ.· b) f i ℤ.+ e ℤ.· (b ℤ.· d) ⟩
(a ℤ.· d ℤ.+ c ℤ.· b) ℤ.· f ℤ.+ e ℤ.· (b ℤ.· d) ∎
_·_ : ℚ → ℚ → ℚ
_·_ = onCommonDenomSym
(λ { (a , _) (c , _) → a ℤ.· c })
(λ { (a , _) (c , _) → ℤ.·-comm a c })
(λ { (a , b) (c , d) (e , _) p → lem₁ a (ℕ₊₁→ℤ d) c (ℕ₊₁→ℤ b) e p })
·-comm : ∀ x y → x · y ≡ y · x
·-comm = onCommonDenomSym-comm (λ { (a , _) (c , _) → ℤ.·-comm a c })
·-identityˡ : ∀ x → 1 · x ≡ x
·-identityˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityˡ a i / ·₊₁-identityˡ b i ] })
·-identityʳ : ∀ x → x · 1 ≡ x
·-identityʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) i → [ ℤ.·-identityʳ a i / ·₊₁-identityʳ b i ] })
·-zeroˡ : ∀ x → 0 · x ≡ 0
·-zeroˡ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) → (λ i → [ p a b i / 1 ·₊₁ b ]) ∙ ℚ-cancelʳ b })
where p : ∀ a b → 0 ℤ.· a ≡ 0 ℤ.· ℕ₊₁→ℤ b
p a b = ℤ.·-zeroˡ {ℤ.spos} a ∙ sym (ℤ.·-zeroˡ {ℤ.spos} (ℕ₊₁→ℤ b))
·-zeroʳ : ∀ x → x · 0 ≡ 0
·-zeroʳ = SetQuotient.elimProp (λ _ → isSetℚ _ _)
(λ { (a , b) → (λ i → [ p a b i / b ·₊₁ 1 ]) ∙ ℚ-cancelˡ b })
where p : ∀ a b → a ℤ.· 0 ≡ ℕ₊₁→ℤ b ℤ.· 0
p a b = ℤ.·-zeroʳ {ℤ.spos} a ∙ sym (ℤ.·-zeroʳ {ℤ.spos} (ℕ₊₁→ℤ b))
·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z
·-assoc = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) i → [ ℤ.·-assoc a c e i / ·₊₁-assoc b d f i ] })
·-distribˡ : ∀ x y z → (x · y) + (x · z) ≡ x · (y + z)
·-distribˡ = SetQuotient.elimProp3 (λ _ _ _ → isSetℚ _ _)
(λ { (a , b) (c , d) (e , f) → eq a b c d e f })
where lem : ∀ {ℓ} {A : Type ℓ} (_·_ : A → A → A)
(·-comm : ∀ x y → x · y ≡ y · x)
(·-assoc : ∀ x y z → x · (y · z) ≡ (x · y) · z)
a c b d
→ (a · c) · (b · d) ≡ (a · (c · d)) · b
lem _·_ ·-comm ·-assoc a c b d =
(a · c) · (b · d) ≡[ i ]⟨ (a · c) · ·-comm b d i ⟩
(a · c) · (d · b) ≡⟨ ·-assoc (a · c) d b ⟩
((a · c) · d) · b ≡[ i ]⟨ ·-assoc a c d (~ i) · b ⟩
(a · (c · d)) · b ∎
lemℤ = lem ℤ._·_ ℤ.·-comm ℤ.·-assoc
lemℕ₊₁ = lem _·₊₁_ ·₊₁-comm ·₊₁-assoc
eq : ∀ a b c d e f →
[ (a ℤ.· c) ℤ.· ℕ₊₁→ℤ (b ·₊₁ f) ℤ.+ (a ℤ.· e) ℤ.· ℕ₊₁→ℤ (b ·₊₁ d)
/ (b ·₊₁ d) ·₊₁ (b ·₊₁ f) ]
≡ [ a ℤ.· (c ℤ.· ℕ₊₁→ℤ f ℤ.+ e ℤ.· ℕ₊₁→ℤ d)
/ b ·₊₁ (d ·₊₁ f) ]
eq a b c d e f =
(λ i → [ lemℤ a c (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ f) i ℤ.+ lemℤ a e (ℕ₊₁→ℤ b) (ℕ₊₁→ℤ d) i
/ lemℕ₊₁ b d b f i ]) ∙
(λ i → [ ℤ.·-distribʳ (a ℤ.· (c ℤ.· ℕ₊₁→ℤ f)) (a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)) (ℕ₊₁→ℤ b) i
/ (b ·₊₁ (d ·₊₁ f)) ·₊₁ b ]) ∙
ℚ-cancelʳ {a ℤ.· (c ℤ.· ℕ₊₁→ℤ f) ℤ.+ a ℤ.· (e ℤ.· ℕ₊₁→ℤ d)} {b ·₊₁ (d ·₊₁ f)} b ∙
(λ i → [ ℤ.·-distribˡ a (c ℤ.· ℕ₊₁→ℤ f) (e ℤ.· ℕ₊₁→ℤ d) i
/ b ·₊₁ (d ·₊₁ f) ])
·-distribʳ : ∀ x y z → (x · z) + (y · z) ≡ (x + y) · z
·-distribʳ x y z = (λ i → ·-comm x z i + ·-comm y z i) ∙ ·-distribˡ z x y ∙ ·-comm z (x + y)
-_ : ℚ → ℚ
- x = -1 · x
negate-invol : ∀ x → - - x ≡ x
negate-invol x = ·-assoc -1 -1 x ∙ ·-identityˡ x
negateEquiv : ℚ ≃ ℚ
negateEquiv = isoToEquiv (iso -_ -_ negate-invol negate-invol)
negateEq : ℚ ≡ ℚ
negateEq = ua negateEquiv
+-inverseˡ : ∀ x → (- x) + x ≡ 0
+-inverseˡ x = (λ i → (-1 · x) + ·-identityˡ x (~ i)) ∙ ·-distribʳ -1 1 x ∙ ·-zeroˡ x
_-_ : ℚ → ℚ → ℚ
x - y = x + (- y)
+-inverseʳ : ∀ x → x - x ≡ 0
+-inverseʳ x = +-comm x (- x) ∙ +-inverseˡ x
+-injˡ : ∀ x y z → x + y ≡ x + z → y ≡ z
+-injˡ x y z p = sym (q y) ∙ cong ((- x) +_) p ∙ q z
where q : ∀ y → (- x) + (x + y) ≡ y
q y = +-assoc (- x) x y ∙ cong (_+ y) (+-inverseˡ x) ∙ +-identityˡ y
+-injʳ : ∀ x y z → x + y ≡ z + y → x ≡ z
+-injʳ x y z p = +-injˡ y x z (+-comm y x ∙ p ∙ +-comm z y)
| {
"alphanum_fraction": 0.3828060142,
"avg_line_length": 44.0691056911,
"ext": "agda",
"hexsha": "7095a27720c8c3202c831cbb7f9f161630773ad8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/HITs/Rationals/QuoQ/Properties.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/HITs/Rationals/QuoQ/Properties.agda",
"max_line_length": 102,
"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/HITs/Rationals/QuoQ/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 6259,
"size": 10841
} |
{-# OPTIONS --copatterns #-}
module CopatternCheckingNYI where
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream
data Nat : Set where
zero : Nat
suc : Nat -> Nat
alternate : Stream Nat
( (head alternate)) = zero
(head (tail alternate)) = suc zero
(tail (tail alternate)) = tail alternate
-- does not yet termination-check
| {
"alphanum_fraction": 0.6701030928,
"avg_line_length": 18.4761904762,
"ext": "agda",
"hexsha": "cf0bfa5780b16e640706a249ca395010efe0d8c6",
"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": "test/fail/CopatternCheckingNYI.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": "test/fail/CopatternCheckingNYI.agda",
"max_line_length": 40,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "np/agda-git-experiment",
"max_stars_repo_path": "test/fail/CopatternCheckingNYI.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": 107,
"size": 388
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
module Cubical.Relation.Binary.Reasoning.Base.Partial
{a ℓ} {A : Type a} (_∼_ : RawRel A ℓ) (transitive : Transitive _∼_)
where
open import Cubical.Foundations.Prelude
infix 4 _IsRelatedTo_
infix 2 _∎⟨_⟩
infixr 1 _∼⟨_⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_
infixr 1 _≡⟨⟩_
infix 0 begin_
------------------------------------------------------------------------
-- Definition of "related to"
-- This seemingly unnecessary type is used to make it possible to
-- infer arguments even if the underlying equality evaluates.
data _IsRelatedTo_ (x y : A) : Type ℓ where
relTo : (x∼y : x ∼ y) → x IsRelatedTo y
------------------------------------------------------------------------
-- Reasoning combinators
-- Beginning of a proof
begin_ : ∀ {x y} → x IsRelatedTo y → x ∼ y
begin relTo x∼y = x∼y
-- Standard step with the relation
_∼⟨_⟩_ : ∀ x {y z} → x ∼ y → y IsRelatedTo z → x IsRelatedTo z
_ ∼⟨ x∼y ⟩ relTo y∼z = relTo (transitive x∼y y∼z)
-- Step with a non-trivial propositional equality
_≡⟨_⟩_ : ∀ x {y z} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_≡⟨_⟩_ x {_} {z} x≡y y∼z = J (λ w _ → w IsRelatedTo z) y∼z (sym x≡y)
-- Step with a flipped non-trivial propositional equality
_≡˘⟨_⟩_ : ∀ x {y z} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z
x ≡˘⟨ y≡x ⟩ y∼z = x ≡⟨ sym y≡x ⟩ y∼z
-- Step with a trivial propositional equality
_≡⟨⟩_ : ∀ x {y} → x IsRelatedTo y → x IsRelatedTo y
_ ≡⟨⟩ x∼y = x∼y
-- Syntax for path definition
≡⟨⟩-syntax : ∀ x {y z : A} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 1 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡˘⟨⟩-syntax : ∀ x {y z : A} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z
≡˘⟨⟩-syntax = _≡˘⟨_⟩_
infixr 1 ≡˘⟨⟩-syntax
syntax ≡˘⟨⟩-syntax x (λ i → B) y = x ≡˘[ i ]⟨ B ⟩ y
-- Termination step
_∎⟨_⟩ : ∀ x → x ∼ x → x IsRelatedTo x
_ ∎⟨ x∼x ⟩ = relTo x∼x
| {
"alphanum_fraction": 0.5728796343,
"avg_line_length": 27.3472222222,
"ext": "agda",
"hexsha": "1346890d19c2a86dd9930481857de606f990501f",
"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/Relation/Binary/Reasoning/Base/Partial.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/Relation/Binary/Reasoning/Base/Partial.agda",
"max_line_length": 72,
"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/Relation/Binary/Reasoning/Base/Partial.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 828,
"size": 1969
} |
------------------------------------------------------------------------
-- Squashing
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --prop --safe #-}
import Equality.Path as P
module Squash {e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude
open import Bijection equality-with-J using (_↔_)
open import Equality.Decidable-UIP equality-with-J
open import Double-negation equality-with-J as DN using (¬¬_)
open import Embedding equality-with-J using (Embedding; Is-embedding)
open import Equality.Decision-procedures equality-with-J
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased equality-with-J using (_≃ᴱ_)
open import For-iterated-equality equality-with-J
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc using (∥_∥)
open import Injection equality-with-J using (_↣_)
open import Monad equality-with-J
open import Surjection equality-with-J using (_↠_; Split-surjective)
private
variable
a b ℓ p : Level
A B : Type a
P : A → Type p
k x y : A
n : ℕ
------------------------------------------------------------------------
-- The squash type
-- Any two elements of type Squash′ A are definitionally equal.
data Squash′ (A : Type a) : Prop a where
squash′ : A → Squash′ A
-- However, Squash′ A does not have type Type a. The following wrapper
-- makes it possible to use squashed types in, say, lists.
record Squash (A : Type a) : Type a where
constructor squash
field
squashed : Squash′ A
pattern [_] x = squash (squash′ x)
private
-- A unit test.
test : [ 4 ] ∷ [ 5 ] ∷ [] ≡ [ 3 ] ∷ [ 9 ] ∷ []
test = refl _
-- Squashed types are propositions.
Squash-propositional : Is-proposition (Squash A)
Squash-propositional = λ _ _ → refl _
------------------------------------------------------------------------
-- Squash is a monad
-- A universe-polymorphic variant of bind.
infixl 5 _>>=′_
_>>=′_ : Squash A → (A → Squash B) → Squash B
_>>=′_ {A = A} {B = B} (squash x) f = squash (lemma x)
where
lemma : Squash′ A → Squash′ B
lemma (squash′ x) = Squash.squashed (f x)
instance
-- Squash is a monad.
raw-monad : Raw-monad {c = ℓ} Squash
Raw-monad.return raw-monad = [_]
Raw-monad._>>=_ raw-monad = _>>=′_
monad : Monad {c = ℓ} Squash
Monad.raw-monad monad = raw-monad
Monad.left-identity monad = λ _ _ → refl _
Monad.right-identity monad = λ _ → refl _
Monad.associativity monad = λ _ _ _ → refl _
------------------------------------------------------------------------
-- Squash preserves all kinds of functions
private
-- Squash preserves functions.
Squash-cong-→ : (A → B) → Squash A → Squash B
Squash-cong-→ A→B x = x >>=′ return ∘ A→B
-- If A and B are logically equivalent, then Squash A and Squash B are
-- equivalent.
Squash-cong-⇔ : A ⇔ B → Squash A ≃ Squash B
Squash-cong-⇔ A⇔B = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = Squash-cong-→ (_⇔_.to A⇔B)
; from = Squash-cong-→ (_⇔_.from A⇔B)
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
})
-- If there is a split surjection from A to B, then Squash A and
-- Squash B are equivalent.
Squash-cong-↠ : A ↠ B → Squash A ≃ Squash B
Squash-cong-↠ = Squash-cong-⇔ ∘ _↠_.logical-equivalence
private
-- Some lemmas used in Squash-cong.
Squash-cong-↔ : A ↔ B → Squash A ↔ Squash B
Squash-cong-↔ =
from-isomorphism ∘ Squash-cong-⇔ ∘ _↔_.logical-equivalence
Squash-cong-≃ : A ≃ B → Squash A ≃ Squash B
Squash-cong-≃ = Squash-cong-⇔ ∘ _≃_.logical-equivalence
Squash-cong-≃ᴱ : A ≃ᴱ B → Squash A ≃ᴱ Squash B
Squash-cong-≃ᴱ =
from-isomorphism ∘ Squash-cong-⇔ ∘ _≃ᴱ_.logical-equivalence
Squash-cong-↣ : A ↣ B → Squash A ↣ Squash B
Squash-cong-↣ A↣B = record
{ to = Squash-cong-→ (_↣_.to A↣B)
; injective = λ _ → refl _
}
Squash-cong-Embedding :
Embedding A B → Embedding (Squash A) (Squash B)
Squash-cong-Embedding A↣B = record
{ to = Squash-cong-→ (Embedding.to A↣B)
; is-embedding = λ x y →
_≃_.is-equivalence $
_↠_.from (Eq.≃↠⇔ (⇒≡ 1 Squash-propositional)
(⇒≡ 1 Squash-propositional))
(record { from = λ _ → refl _ })
}
Squash-cong : A ↝[ k ] B → Squash A ↝[ k ] Squash B
Squash-cong {k = implication} = Squash-cong-→
Squash-cong {k = logical-equivalence} = from-isomorphism ∘ Squash-cong-⇔
Squash-cong {k = injection} = Squash-cong-↣
Squash-cong {k = embedding} = Squash-cong-Embedding
Squash-cong {k = surjection} = from-isomorphism ∘ Squash-cong-↠
Squash-cong {k = bijection} = Squash-cong-↔
Squash-cong {k = equivalence} = Squash-cong-≃
Squash-cong {k = equivalenceᴱ} = Squash-cong-≃ᴱ
------------------------------------------------------------------------
-- Some isomorphisms
-- Squash ⊤ is isomorphic to ⊤.
Squash-⊤↔⊤ : Squash ⊤ ↔ ⊤
Squash-⊤↔⊤ = record
{ surjection = record
{ logical-equivalence = record
{ from = λ _ → [ _ ]
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
-- Squash ⊥ is isomorphic to ⊥.
Squash-⊥↔⊥ : Squash (⊥ {ℓ = ℓ}) ↔ ⊥ {ℓ = ℓ}
Squash-⊥↔⊥ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ x → ⊥-in-prop→⊥ (Squash-⊥→⊥-in-prop x)
; from = λ ()
}
; right-inverse-of = λ ()
}
; left-inverse-of = λ _ → refl _
}
where
-- An empty type in Prop.
data ⊥-in-prop : Prop where
-- Squash ⊥ implies ⊥-in-prop.
Squash-⊥→⊥-in-prop : Squash (⊥ {ℓ = ℓ}) → ⊥-in-prop
Squash-⊥→⊥-in-prop [ () ]
-- ⊥-in-prop implies ⊥.
⊥-in-prop→⊥ : ⊥-in-prop → ⊥ {ℓ = ℓ}
⊥-in-prop→⊥ ()
-- Squash commutes with _×_.
--
-- This lemma was suggested by Jesper Cockx.
Squash-×↔× : Squash (A × B) ↔ Squash A × Squash B
Squash-×↔× = record
{ surjection = record
{ logical-equivalence = record
{ to = λ p → Squash-cong proj₁ p , Squash-cong proj₂ p
; from = λ (x , y) → x >>=′ λ x → y >>=′ λ y → return (x , y)
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
-- Squash commutes with ↑ ℓ.
Squash-↑↔↑ : Squash (↑ ℓ A) ↔ ↑ ℓ (Squash A)
Squash-↑↔↑ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { x .lower → Squash-cong lower x }
; from = λ (lift x) → Squash-cong lift x
}
; right-inverse-of = λ _ → refl _
}
; left-inverse-of = λ _ → refl _
}
------------------------------------------------------------------------
-- Some properties
-- ∥ A ∥ implies Squash A.
∥∥→Squash : ∥ A ∥ → Squash A
∥∥→Squash = Trunc.rec Squash-propositional [_]
-- Squash A implies ¬ ¬ A.
Squash→¬¬ : Squash A → ¬ ¬ A
Squash→¬¬ {A = A} = curry (
Squash A × ¬ A ↝⟨ uncurry (flip Squash-cong) ⟩
Squash ⊥ ↔⟨ Squash-⊥↔⊥ ⟩□
⊥ □)
-- It is not in general the case that [ x ] ≡ [ y ] implies
-- Squash (x ≡ y).
¬-[]≡[]→Squash-≡ :
¬ ({A : Type a} {x y : A} → [ x ] ≡ [ y ] → Squash (x ≡ y))
¬-[]≡[]→Squash-≡ {a = a} =
({A : Type a} {x y : A} → [ x ] ≡ [ y ] → Squash (x ≡ y)) ↝⟨ _$ refl _ ⟩
Squash (lift true ≡ lift false) ↝⟨ Squash-cong (cong lower) ⟩
Squash (true ≡ false) ↝⟨ Squash-cong Bool.true≢false ⟩
Squash ⊥ ↔⟨ Squash-⊥↔⊥ ⟩□
⊥ □
-- [_] is split surjective for decided types.
Split-surjective-[] : Dec A → Split-surjective {A = A} [_]
Split-surjective-[] (yes x) _ = x , refl _
Split-surjective-[] (no ¬x) x =
⊥-elim (_↔_.to Squash-⊥↔⊥ (Squash-cong ¬x x))
------------------------------------------------------------------------
-- Stability
-- A type A is stable if Squash A implies A.
Stable : Type a → Type a
Stable A = Squash A → A
-- A type A is very stable if Squash A is equivalent to A.
Very-stable : Type a → Type a
Very-stable A = Squash A ≃ A
-- Variants of the definitions above for equality.
Stable-≡ : Type a → Type a
Stable-≡ = For-iterated-equality 1 Stable
Very-stable-≡ : Type a → Type a
Very-stable-≡ = For-iterated-equality 1 Very-stable
------------------------------------------------------------------------
-- Some lemmas related to stability
-- Very stable types are stable.
Very-stable→Stable :
∀ n →
For-iterated-equality n Very-stable A →
For-iterated-equality n Stable A
Very-stable→Stable n =
For-iterated-equality-cong₁ _ n _≃_.to
-- Very-stable is propositional (assuming extensionality).
Very-stable-propositional :
{A : Type a} →
Extensionality a a →
Is-proposition (Very-stable A)
Very-stable-propositional ext =
Eq.left-closure ext 0 Squash-propositional
private
-- The previous result can be generalised.
For-iterated-equality-Very-stable-propositional :
{A : Type a} →
Extensionality a a →
∀ n → Is-proposition (For-iterated-equality n Very-stable A)
For-iterated-equality-Very-stable-propositional ext n =
H-level-For-iterated-equality ext 1 n
(Very-stable-propositional ext)
-- A type is very stable if and only if [_] is an equivalence for that
-- type.
Very-stable↔Is-equivalence-[] :
{A : Type a} →
Very-stable A ↝[ a ∣ a ] Is-equivalence {A = A} [_]
Very-stable↔Is-equivalence-[] =
generalise-ext?-prop
(record { from = inverse ∘ Eq.⟨ _ ,_⟩
; to = λ s →
_≃_.is-equivalence $
Eq.with-other-function
(inverse s)
[_]
(λ _ → refl _)
})
Very-stable-propositional
(λ ext → Eq.propositional ext _)
-- A type is very stable if and only if it is a stable proposition.
Very-stable↔Stable×Is-proposition :
{A : Type a} →
Very-stable A ↝[ a ∣ a ] Stable A × Is-proposition A
Very-stable↔Stable×Is-proposition =
generalise-ext?-prop
(record { to = λ s → _≃_.to s
, H-level-cong _ 1 s Squash-propositional
; from = λ (s , prop) →
_↠_.from (Eq.≃↠⇔ Squash-propositional prop)
(record { to = s; from = [_] })
})
Very-stable-propositional
(λ ext →
[inhabited⇒+]⇒+ 0 λ (_ , prop) →
×-closure 1
(Π-closure ext 1 (λ _ → prop))
(H-level-propositional ext 1))
-- If A has h-level 1 + n and is stable "n levels up", then A is very
-- stable "n levels up".
Stable→H-level-suc→Very-stable :
∀ n →
For-iterated-equality n Stable A → H-level (suc n) A →
For-iterated-equality n Very-stable A
Stable→H-level-suc→Very-stable {A = A} n = curry (
For-iterated-equality n Stable A × H-level (suc n) A ↝⟨ (∃-cong λ _ → lemma) ⟩
For-iterated-equality n Stable A ×
For-iterated-equality n Is-proposition A ↝⟨ For-iterated-equality-commutes-× n _ ⟩
For-iterated-equality n (λ A → Stable A × Is-proposition A) A ↝⟨ For-iterated-equality-cong₁ _ n $
uncurry (curry $ _⇔_.from (Very-stable↔Stable×Is-proposition _)) ⟩
For-iterated-equality n Very-stable A □)
where
lemma =
H-level (suc n) A ↝⟨ _⇔_.to H-level⇔H-level′ ⟩
H-level′ (suc n) A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩
For-iterated-equality n (H-level′ 1) A ↝⟨ For-iterated-equality-cong₁ _ n $
_⇔_.from (H-level⇔H-level′ {n = 1}) ⟩□
For-iterated-equality n Is-proposition A □
-- Types with h-level n are very stable "n levels up".
H-level→Very-stable :
∀ n → H-level n A → For-iterated-equality n Very-stable A
H-level→Very-stable {A = A} n =
H-level n A ↝⟨ _⇔_.to H-level⇔H-level′ ⟩
H-level′ n A ↝⟨ For-iterated-equality-cong₁ _ n Contractible→Very-stable ⟩□
For-iterated-equality n Very-stable A □
where
Contractible→Very-stable :
∀ {A} → Contractible A → Very-stable A
Contractible→Very-stable c =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( (λ _ → proj₁ c)
, mono₁ 0 c
)
-- If A is very stable, then [_] {A = A} is an embedding.
Very-stable→Is-embedding-[] :
Very-stable A → Is-embedding {A = A} [_]
Very-stable→Is-embedding-[] s x y =
_≃_.is-equivalence (
x ≡ y ↝⟨ inverse $ Eq.≃-≡ $ Eq.⟨ _ , Very-stable↔Is-equivalence-[] _ s ⟩ ⟩□
[ x ] ≡ [ y ] □)
-- If A is very stable, then [_] {A = A} is split surjective.
Very-stable→Split-surjective-[] :
Very-stable A → Split-surjective {A = A} [_]
Very-stable→Split-surjective-[] {A = A} =
Very-stable A ↝⟨ Very-stable↔Is-equivalence-[] _ ⟩
Is-equivalence [_] ↝⟨ (λ hyp → _↠_.split-surjective $ _≃_.surjection $ Eq.⟨ _ , hyp ⟩) ⟩
Split-surjective [_] □
-- Types that are stable for double negation are stable for Squash.
¬¬-Stable→Stable : (¬ ¬ A → A) → Stable A
¬¬-Stable→Stable ¬¬-Stable x = ¬¬-Stable (Squash→¬¬ x)
-- Types for which it is known whether or not they are inhabited are
-- stable.
Dec→Stable : Dec A → Stable A
Dec→Stable (yes x) _ = x
Dec→Stable (no ¬x) x with () ← Squash→¬¬ x ¬x
-- Every type is stable in the double negation monad.
¬¬-Stable : ¬¬ Stable A
¬¬-Stable = DN.map′ Dec→Stable DN.excluded-middle
-- Bool is not very stable. (But it is stable, see Dec→Stable above.)
¬-Very-stable-Bool : ¬ Very-stable Bool
¬-Very-stable-Bool =
Very-stable Bool ↝⟨ proj₂ ∘ Very-stable↔Stable×Is-proposition _ ⟩
Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□
⊥ □
-- If equality is decidable for A, then equality is very stable for A.
Decidable-equality→Very-stable-≡ :
Decidable-equality A → Very-stable-≡ A
Decidable-equality→Very-stable-≡ dec _ _ =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( Dec→Stable (dec _ _)
, decidable⇒set dec
)
----------------------------------------------------------------------
-- Preservation lemmas
-- Stable preserves some kinds of functions (those that are
-- "symmetric"), possibly assuming extensionality.
Stable-cong :
{A : Type a} {B : Type b} →
Extensionality? ⌊ k ⌋-sym (a ⊔ b) (a ⊔ b) →
A ↝[ ⌊ k ⌋-sym ] B → Stable A ↝[ ⌊ k ⌋-sym ] Stable B
Stable-cong {k = k} {A = A} {B = B} ext A↝B =
Stable A ↔⟨⟩
(Squash A → A) ↝⟨ →-cong ext (Squash-cong A↝B) A↝B ⟩
(Squash B → B) ↔⟨⟩
Stable B □
-- A kind of map function for Stable.
Stable-map : A ⇔ B → Stable A → Stable B
Stable-map = _⇔_.to ∘ Stable-cong _
-- A kind of map function for Very-stable.
Very-stable-map :
A ↠ B → Very-stable A → Very-stable B
Very-stable-map {A = A} {B = B} A↠B s =
_↠_.from (Eq.≃↠⇔ Squash-propositional B-prop)
(record { from = [_]
; to = Squash B ↝⟨ Squash-cong (_↠_.from A↠B) ⟩
Squash A ↔⟨ s ⟩
A ↝⟨ _↠_.to A↠B ⟩□
B □
})
where
A-prop : Is-proposition A
A-prop = proj₂ $ Very-stable↔Stable×Is-proposition _ s
B-prop : Is-proposition B
B-prop = H-level.respects-surjection A↠B 1 A-prop
-- Very-stable preserves equivalences (assuming extensionality).
Very-stable-cong :
{A : Type a} {B : Type b} →
Extensionality? k (a ⊔ b) (a ⊔ b) →
A ≃ B → Very-stable A ↝[ k ] Very-stable B
Very-stable-cong {A = A} {B = B} ext A≃B =
Very-stable A ↔⟨⟩
Squash A ≃ A ↝⟨ generalise-ext?
(Eq.≃-preserves-⇔ (Squash-cong A≃B) A≃B)
(λ ext →
let eq = Eq.≃-preserves ext (Squash-cong-≃ A≃B) A≃B in
_≃_.right-inverse-of eq , _≃_.left-inverse-of eq)
ext ⟩
Squash B ≃ B ↔⟨⟩
Very-stable B □
------------------------------------------------------------------------
-- Closure properties
-- Squash A is very stable.
Very-stable-Squash : Very-stable (Squash A)
Very-stable-Squash =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( _>>= id
, Squash-propositional
)
-- ⊤ is very stable.
Very-stable-⊤ : Very-stable ⊤
Very-stable-⊤ = Eq.↔⇒≃ Squash-⊤↔⊤
-- ⊥ is very stable.
Very-stable-⊥ : Very-stable (⊥ {ℓ = ℓ})
Very-stable-⊥ = Eq.↔⇒≃ Squash-⊥↔⊥
-- Stable is closed under Π A.
Stable-Π :
(∀ x → Stable (P x)) →
Stable ((x : A) → P x)
Stable-Π {P = P} s =
Squash (∀ x → P x) ↝⟨ (λ s x → Squash-cong (_$ x) s) ⟩
(∀ x → Squash (P x)) ↝⟨ ∀-cong _ s ⟩□
(∀ x → P x) □
-- Very-stable is closed under Π A (assuming extensionality).
Very-stable-Π :
{A : Type a} {P : A → Type p} →
Extensionality a p →
(∀ x → Very-stable (P x)) →
Very-stable ((x : A) → P x)
Very-stable-Π {P = P} ext s =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( Stable-Π (Very-stable→Stable 0 ∘ s)
, (Π-closure ext 1 λ x →
H-level-cong _ 1 (s x) Squash-propositional)
)
-- Stable is closed under _×_.
Stable-× : Stable A → Stable B → Stable (A × B)
Stable-× {A = A} {B = B} s₁ s₂ =
Squash (A × B) ↔⟨ Squash-×↔× ⟩
Squash A × Squash B ↝⟨ s₁ ×-cong s₂ ⟩□
A × B □
-- Very-stable is closed under _×_.
Very-stable-× : Very-stable A → Very-stable B → Very-stable (A × B)
Very-stable-× s₁ s₂ =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( Stable-× (Very-stable→Stable 0 s₁) (Very-stable→Stable 0 s₂)
, ×-closure 1 (H-level-cong _ 1 s₁ Squash-propositional)
(H-level-cong _ 1 s₂ Squash-propositional)
)
-- Stable is closed under ↑ ℓ.
Stable-↑ : Stable A → Stable (↑ ℓ A)
Stable-↑ {A = A} s =
Squash (↑ _ A) ↔⟨ Squash-↑↔↑ ⟩
↑ _ (Squash A) ↝⟨ ↑-cong s ⟩□
↑ _ A □
-- Very-stable is closed under ↑ ℓ.
Very-stable-↑ : Very-stable A → Very-stable (↑ ℓ A)
Very-stable-↑ {A = A} s =
Squash (↑ _ A) ↔⟨ Squash-↑↔↑ ⟩
↑ _ (Squash A) ↝⟨ ↑-cong s ⟩□
↑ _ A □
-- If A is very stable, then equality is very stable for A.
Very-stable→Very-stable-≡ :
∀ n →
For-iterated-equality n Very-stable A →
For-iterated-equality (suc n) Very-stable A
Very-stable→Very-stable-≡ {A = A} n =
For-iterated-equality n Very-stable A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩
For-iterated-equality n Very-stable-≡ A ↝⟨ For-iterated-equality-For-iterated-equality n 1 _ ⟩□
For-iterated-equality (suc n) Very-stable A □
where
lemma : ∀ {A} → Very-stable A → Very-stable-≡ A
lemma {A = A} s x y =
_⇔_.from (Very-stable↔Stable×Is-proposition _)
( (Squash (x ≡ y) ↝⟨ const prop ⟩
Is-proposition A ↝⟨ +⇒≡ ⟩
Contractible (x ≡ y) ↝⟨ proj₁ ⟩□
x ≡ y □)
, ⇒≡ 1 prop
)
where
prop : Is-proposition A
prop = proj₂ $ _⇔_.to (Very-stable↔Stable×Is-proposition _) s
private
-- Some examples showing how Very-stable→Very-stable-≡ can be
-- used.
-- Equalities between erased values are very stable.
Very-stable-≡₀ : Very-stable-≡ (Squash A)
Very-stable-≡₀ = Very-stable→Very-stable-≡ 0 Very-stable-Squash
-- Equalities between equalities between erased values are very
-- stable.
Very-stable-≡₁ : For-iterated-equality 2 Very-stable (Squash A)
Very-stable-≡₁ = Very-stable→Very-stable-≡ 1 Very-stable-≡₀
-- And so on…
private
-- A lemma.
For-iterated-equality-Is-proposition↔H-level′-suc :
{A : Type a} →
∀ n →
For-iterated-equality n Is-proposition A ↝[ a ∣ a ]
H-level′ (suc n) A
For-iterated-equality-Is-proposition↔H-level′-suc {A = A} n ext =
For-iterated-equality n Is-proposition A ↝⟨ For-iterated-equality-cong₁ ext n (H-level↔H-level′ {n = 1} ext) ⟩
For-iterated-equality n (H-level′ 1) A ↝⟨ For-iterated-equality-For-iterated-equality n 1 ext ⟩□
H-level′ (suc n) A □
-- If A is "stable 1 + n levels up", then H-level′ (suc n) A is
-- stable.
Stable-H-level′ :
∀ n →
For-iterated-equality (suc n) Stable A →
Stable (H-level′ (suc n) A)
Stable-H-level′ {A = A} n =
For-iterated-equality (suc n) Stable A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩
For-iterated-equality n Stable-≡ A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩
For-iterated-equality n (Stable ∘ Is-proposition) A ↝⟨ For-iterated-equality-commutes-← _ Stable n Stable-Π ⟩
Stable (For-iterated-equality n Is-proposition A) ↝⟨ Stable-map (For-iterated-equality-Is-proposition↔H-level′-suc n _) ⟩□
Stable (H-level′ (suc n) A) □
where
lemma : ∀ {A} → Stable-≡ A → Stable (Is-proposition A)
lemma s =
Stable-Π λ _ →
Stable-Π λ _ →
s _ _
-- If A is "stable 1 + n levels up", then H-level (suc n) A is
-- stable.
Stable-H-level :
∀ n →
For-iterated-equality (suc n) Stable A →
Stable (H-level (suc n) A)
Stable-H-level {A = A} n =
For-iterated-equality (suc n) Stable A ↝⟨ Stable-H-level′ n ⟩
Stable (H-level′ (suc n) A) ↝⟨ Stable-map (record { to = inverse-ext? H-level↔H-level′ _; from = H-level↔H-level′ _ }) ⟩□
Stable (H-level (suc n) A) □
-- If A is "very stable 1 + n levels up", then H-level′ (suc n) A is
-- very stable (assuming extensionality).
Very-stable-H-level′ :
{A : Type a} →
Extensionality a a →
∀ n →
For-iterated-equality (suc n) Very-stable A →
Very-stable (H-level′ (suc n) A)
Very-stable-H-level′ {A = A} ext n =
For-iterated-equality (suc n) Very-stable A ↝⟨ inverse-ext? (For-iterated-equality-For-iterated-equality n 1) _ ⟩
For-iterated-equality n Very-stable-≡ A ↝⟨ For-iterated-equality-cong₁ _ n lemma ⟩
For-iterated-equality n (Very-stable ∘ Is-proposition) A ↝⟨ For-iterated-equality-commutes-← _ Very-stable n (Very-stable-Π ext) ⟩
Very-stable (For-iterated-equality n Is-proposition A) ↝⟨ Very-stable-map (For-iterated-equality-Is-proposition↔H-level′-suc n ext) ⟩□
Very-stable (H-level′ (suc n) A) □
where
lemma : ∀ {A} → Very-stable-≡ A → Very-stable (Is-proposition A)
lemma s =
Very-stable-Π ext λ _ →
Very-stable-Π ext λ _ →
s _ _
-- If A is "very stable 1 + n levels up", then H-level (suc n) A is
-- very stable (assuming extensionality).
Very-stable-H-level :
{A : Type a} →
Extensionality a a →
∀ n →
For-iterated-equality (suc n) Very-stable A →
Very-stable (H-level (suc n) A)
Very-stable-H-level {A = A} ext n =
For-iterated-equality (suc n) Very-stable A ↝⟨ Very-stable-H-level′ ext n ⟩
Very-stable (H-level′ (suc n) A) ↝⟨ Very-stable-cong _ (inverse $ H-level↔H-level′ ext) ⟩□
Very-stable (H-level (suc n) A) □
-- If equality is stable for A and B, then it is stable for A ⊎ B.
Stable-≡-⊎ :
∀ n →
For-iterated-equality (suc n) Stable A →
For-iterated-equality (suc n) Stable B →
For-iterated-equality (suc n) Stable (A ⊎ B)
Stable-≡-⊎ n sA sB =
For-iterated-equality-⊎-suc
n
(Stable-map ∘ from-isomorphism)
(Very-stable→Stable 0 Very-stable-⊥)
(For-iterated-equality-↑ _ (suc n) (Stable-map ∘ from-isomorphism) sA)
(For-iterated-equality-↑ _ (suc n) (Stable-map ∘ from-isomorphism) sB)
-- If equality is very stable for A and B, then it is very stable
-- for A ⊎ B.
Very-stable-≡-⊎ :
∀ n →
For-iterated-equality (suc n) Very-stable A →
For-iterated-equality (suc n) Very-stable B →
For-iterated-equality (suc n) Very-stable (A ⊎ B)
Very-stable-≡-⊎ n sA sB =
For-iterated-equality-⊎-suc
n
lemma
Very-stable-⊥
(For-iterated-equality-↑ _ (suc n) lemma sA)
(For-iterated-equality-↑ _ (suc n) lemma sB)
where
lemma : A ↔ B → Very-stable A → Very-stable B
lemma = Very-stable-cong _ ∘ from-isomorphism
-- If equality is stable for A, then it is stable for List A.
Stable-≡-List :
∀ n →
For-iterated-equality (suc n) Stable A →
For-iterated-equality (suc n) Stable (List A)
Stable-≡-List n =
For-iterated-equality-List-suc
n
(Stable-map ∘ from-isomorphism)
(Very-stable→Stable 0 $ Very-stable-↑ Very-stable-⊤)
(Very-stable→Stable 0 Very-stable-⊥)
Stable-×
-- If equality is very stable for A, then it is very stable for
-- List A.
Very-stable-≡-List :
∀ n →
For-iterated-equality (suc n) Very-stable A →
For-iterated-equality (suc n) Very-stable (List A)
Very-stable-≡-List n =
For-iterated-equality-List-suc
n
(Very-stable-cong _ ∘ from-isomorphism)
(Very-stable-↑ Very-stable-⊤)
Very-stable-⊥
Very-stable-×
----------------------------------------------------------------------
-- Simple corollaries or variants of results above
-- A generalisation of Stable-Π.
Stable-Πⁿ :
{A : Type a} {P : A → Type p} →
Extensionality a p →
∀ n →
(∀ x → For-iterated-equality n Stable (P x)) →
For-iterated-equality n Stable ((x : A) → P x)
Stable-Πⁿ ext n =
For-iterated-equality-Π
ext
n
(Stable-map ∘ from-isomorphism)
Stable-Π
-- A generalisation of Very-stable-Π.
Very-stable-Πⁿ :
{A : Type a} {P : A → Type p} →
Extensionality a p →
∀ n →
(∀ x → For-iterated-equality n Very-stable (P x)) →
For-iterated-equality n Very-stable ((x : A) → P x)
Very-stable-Πⁿ ext n =
For-iterated-equality-Π
ext
n
(Very-stable-cong _ ∘ from-isomorphism)
(Very-stable-Π ext)
-- A generalisation of Stable-×.
Stable-×ⁿ :
∀ n →
For-iterated-equality n Stable A →
For-iterated-equality n Stable B →
For-iterated-equality n Stable (A × B)
Stable-×ⁿ n =
For-iterated-equality-×
n
(Stable-map ∘ from-isomorphism)
Stable-×
-- A generalisation of Very-stable-×.
Very-stable-×ⁿ :
∀ n →
For-iterated-equality n Very-stable A →
For-iterated-equality n Very-stable B →
For-iterated-equality n Very-stable (A × B)
Very-stable-×ⁿ n =
For-iterated-equality-×
n
(Very-stable-cong _ ∘ from-isomorphism)
Very-stable-×
-- A generalisation of Stable-↑.
Stable-↑ⁿ :
∀ n →
For-iterated-equality n Stable A →
For-iterated-equality n Stable (↑ ℓ A)
Stable-↑ⁿ n =
For-iterated-equality-↑ _ n (Stable-map ∘ from-isomorphism)
-- A generalisation of Very-stable-↑.
Very-stable-↑ⁿ :
∀ n →
For-iterated-equality n Very-stable A →
For-iterated-equality n Very-stable (↑ ℓ A)
Very-stable-↑ⁿ n =
For-iterated-equality-↑
_
n
(Very-stable-cong _ ∘ from-isomorphism)
| {
"alphanum_fraction": 0.5733488529,
"avg_line_length": 30.5774971297,
"ext": "agda",
"hexsha": "cd95c1f8532dea65fdda7c6255ebd441916396a1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Squash.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Squash.agda",
"max_line_length": 139,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Squash.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 9560,
"size": 26633
} |
module RenamingAndSubstitution where
open import Library
open import Syntax
open ≡-Reasoning
infixr 4 _,_
------------------------------------------------------------------------
-- Renaming
------------------------------------------------------------------------
-- Renamings from Γ to Δ are snoc-lists of variables living in Δ,
-- one for each entry in Γ.
data Ren (Δ : Cxt) : (Γ : Cxt) → Set where
ε : Ren Δ ε
_,_ : ∀ {Γ a} (ρ : Ren Δ Γ) (x : Var Δ a) → Ren Δ (Γ , a)
-- A renaming in Ren Δ Γ is a code for a
-- renaming function in Var Γ ∙→ Var Δ.
lookr : ∀{Γ Δ} → Ren Δ Γ → ∀ {σ} → Var Γ σ → Var Δ σ
lookr (xs , x) zero = x
lookr (xs , x) (suc i) = lookr xs i
-- Weaking a renaming by increasing all variables by 1.
-- This lets them live in the extended context Γ , σ.
wkr : ∀{Γ Δ σ} → Ren Γ Δ → Ren (Γ , σ) Δ
wkr ε = ε
wkr (xs , x) = wkr xs , suc x
-- Lifting a renaming to go under a binder.
liftr : ∀{Γ Δ σ} → Ren Γ Δ → Ren (Γ , σ) (Δ , σ)
liftr xs = wkr xs , zero
-- The category of renamings (operations only).
------------------------------------------------------------------------
-- The identity renaming.
renId : ∀{Γ} → Ren Γ Γ
renId {ε} = ε
renId {Γ , _} = liftr (renId {Γ})
-- Forward composition of renamings.
renComp : ∀{Φ Γ Δ} → Ren Δ Γ → Ren Γ Φ → Ren Δ Φ
renComp xs ε = ε
renComp xs (ys , y) = renComp xs ys , lookr xs y
-- Various combinations of renamings.
------------------------------------------------------------------------
-- Weakening a renaming acts behaves like
-- post-composing the renaming function with successor.
lookrwkr : ∀{Γ Δ σ τ}(xs : Ren Δ Γ)(i : Var Γ σ) →
lookr (wkr {σ = τ} xs) i ≡ suc (lookr xs i)
lookrwkr (xs , _) zero = refl
lookrwkr (xs , _) (suc i) = lookrwkr xs i
-- A weakning cancels a renaming extension.
lemrr : ∀{Φ Γ Δ σ}(xs : Ren Φ Γ)(x : Var Φ σ)(ys : Ren Γ Δ) →
renComp (xs , x) (wkr ys) ≡ renComp xs ys
lemrr xs x ε = refl
lemrr xs x (ys , y) = cong (_, lookr xs y) (lemrr xs x ys)
-- Associativity of renaming composition in case the first
-- renaming is a weakening.
wkrcomp : ∀{Φ Γ Δ σ}(xs : Ren Φ Γ)(ys : Ren Γ Δ) →
renComp (wkr {σ = σ} xs) ys ≡ wkr {σ = σ} (renComp xs ys)
wkrcomp xs ε = refl
wkrcomp xs (ys , y) = cong₂ _,_ (wkrcomp xs ys) (lookrwkr xs y)
-- Composition of liftings is a lifting.
liftrcomp : ∀{Φ Γ Δ σ}(xs : Ren Φ Γ)(ys : Ren Γ Δ) →
renComp (liftr {σ = σ} xs) (liftr {σ = σ} ys) ≡ liftr {σ = σ} (renComp xs ys)
liftrcomp xs ys = begin
renComp (wkr xs , zero) (wkr ys) , zero ≡⟨ cong (_, zero) (lemrr (wkr xs) zero ys) ⟩
renComp (wkr xs) ys , zero ≡⟨ cong (_, zero) (wkrcomp xs ys) ⟩
wkr (renComp xs ys) , zero ∎
-- lookr is a morphism from the category Ren
-- to the category of the corresponding renaming functions on variables.
------------------------------------------------------------------------
-- The identity renaming corresponds to the identity function.
lookrid : ∀{Γ σ}(x : Var Γ σ) → lookr renId x ≡ x
lookrid zero = refl
lookrid (suc x) = begin
lookr (wkr renId) x ≡⟨ lookrwkr renId x ⟩
suc (lookr renId x) ≡⟨ cong suc (lookrid x) ⟩
suc x ∎
-- A composition of renamings corresponds to the composition
-- of the corresponding renaming functions.
lookrcomp : ∀{Φ Γ Δ}(f : Ren Δ Γ)(g : Ren Γ Φ){σ}(i : Var Φ σ) →
lookr (renComp f g) i ≡ (lookr f ∘ lookr g) i
lookrcomp f (g , v) zero = refl
lookrcomp f (g , v) (suc i) = lookrcomp f g i
-- Laws for the category of renamings.
------------------------------------------------------------------------
-- Left identity of forward composition
lidr : ∀{Φ Γ}(xs : Ren Φ Γ) → renComp renId xs ≡ xs
lidr ε = refl
lidr (xs , x) = cong₂ _,_ (lidr xs) (lookrid x)
-- Right identity of forward composition
ridr : ∀{Φ Γ}(xs : Ren Φ Γ) → renComp xs renId ≡ xs
ridr {Γ = ε} ε = refl
ridr {Γ = Γ , σ} (xs , x) = begin
renComp (xs , x) (wkr renId) , x ≡⟨ cong (_, x) (lemrr xs x renId) ⟩
renComp xs renId , x ≡⟨ cong (_, x) (ridr xs) ⟩
xs , x ∎
-- Renaming of terms.
------------------------------------------------------------------------
-- Renaming in a term.
ren : ∀{Γ Δ} → Ren Δ Γ → ∀ {σ} → Tm Γ σ → Tm Δ σ
ren xs (var x) = var (lookr xs x)
ren xs (abs t) = abs (ren (liftr xs) t)
ren xs (app t u) = app (ren xs t) (ren xs u)
-- ren is a morphism from Ren
-- to the corresponding category of renaming functions on terms.
renid : ∀{Γ σ}(t : Tm Γ σ) → ren renId t ≡ t
renid (var x) = cong var (lookrid x)
renid (abs t) = cong abs (renid t)
renid (app t u) = cong₂ app (renid t) (renid u)
rencomp : ∀ {Φ Γ Δ}(f : Ren Δ Γ)(g : Ren Γ Φ){σ}(t : Tm Φ σ) →
ren (renComp f g) t ≡ (ren f ∘ ren g) t
rencomp f g (var x) = cong var (lookrcomp f g x)
rencomp f g (abs t) = begin
abs (ren (liftr (renComp f g)) t) ≡⟨ cong (λ xs → abs $ ren xs t) (sym $ liftrcomp f g) ⟩
abs (ren (renComp (liftr f) (liftr g)) t) ≡⟨ cong abs (rencomp (liftr f) (liftr g) t) ⟩
abs (ren (liftr f) (ren (liftr g) t)) ∎
rencomp f g (app t u) = cong₂ app (rencomp f g t) (rencomp f g u)
-- Weakening a term.
weak : ∀{Γ b} a → Tm Γ b → Tm (Γ , a) b
weak a = ren (wkr renId)
-- Renaming of normal forms.
------------------------------------------------------------------------
mutual
rennf : ∀{Γ Δ} → Ren Γ Δ → ∀{a} → Nf Δ a → Nf Γ a
rennf α (ne t) = ne (rennen α t)
rennf α (abs t) = abs (rennf (liftr α) t)
rennen : ∀{Γ Δ} → Ren Γ Δ → ∀{a} → Ne Δ a → Ne Γ a
rennen α (var x) = var (lookr α x)
rennen α (app n x) = app (rennen α n) (rennf α x)
------------------------------------------------------------------------
-- Substitution
------------------------------------------------------------------------
data Sub (Δ : Cxt) : (Γ : Cxt) → Set where
ε : Sub Δ ε
_,_ : ∀ {Γ a} (ρ : Sub Δ Γ) (v : Tm Δ a) → Sub Δ (Γ , a)
ren2sub : ∀{Γ Δ} → Ren Γ Δ → Sub Γ Δ
ren2sub ε = ε
ren2sub (xs , x) = ren2sub xs , var x
looks : ∀{Γ Δ} → Sub Δ Γ → ∀ {σ} → Var Γ σ → Tm Δ σ
looks (xs , x) zero = x
looks (xs , x) (suc i) = looks xs i
wks : ∀{Γ Δ σ} → Sub Γ Δ → Sub (Γ , σ) Δ
wks ε = ε
wks (xs , x) = wks xs , ren (wkr renId) x
lifts : ∀{Γ Δ σ} → Sub Γ Δ → Sub (Γ , σ) (Δ , σ)
lifts xs = wks xs , var zero
sub : ∀{Γ Δ} → Sub Δ Γ → ∀{σ} → Tm Γ σ → Tm Δ σ
sub xs (var x) = looks xs x
sub xs (abs t) = abs (sub (lifts xs) t)
sub xs (app t u) = app (sub xs t) (sub xs u)
subId : ∀{Γ} → Sub Γ Γ
subId {ε} = ε
subId {Γ , _} = lifts (subId {Γ})
subComp : ∀{Φ Γ Δ} → Sub Δ Γ → Sub Γ Φ → Sub Δ Φ
subComp xs ε = ε
subComp xs (ys , y) = subComp xs ys , sub xs y
-- Substitute the last variable
sub0 : ∀{Γ a b} → Tm (Γ , a) b → Tm Γ a → Tm Γ b
sub0 t u = sub (subId , u) t
-- Substitution laws
lookswks : ∀{Γ Δ σ τ}(i : Var Γ σ)(xs : Sub Δ Γ) →
looks (wks {σ = τ} xs) i ≡ ren (wkr {σ = τ} renId) (looks xs i)
lookswks zero (xs , _) = refl
lookswks (suc i) (xs , _) = lookswks i xs
lemsr : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(x : Tm Φ σ)(ys : Ren Γ Δ) →
subComp (xs , x) (ren2sub (wkr ys)) ≡ subComp xs (ren2sub ys)
lemsr xs x ε = refl
lemsr xs x (ys , y) = cong (λ zs → zs , looks xs y) (lemsr xs x ys)
lookslookr : ∀{Φ Γ Δ}(f : Sub Δ Γ)(g : Ren Γ Φ){σ}(x : Var Φ σ) →
looks (subComp f (ren2sub g)) x ≡ looks f (lookr g x)
lookslookr f (g , _) zero = refl
lookslookr f (g , _) (suc x) = lookslookr f g x
wksrcomp : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(ys : Ren Γ Δ) →
subComp (wks {σ = σ} xs) (ren2sub ys) ≡ wks {σ = σ} (subComp xs (ren2sub ys))
wksrcomp xs ε = refl
wksrcomp xs (ys , y) = cong₂ Sub._,_ (wksrcomp xs ys) (lookswks y xs)
liftsrcomp : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(ys : Ren Γ Δ) →
subComp (lifts {σ = σ} xs) (ren2sub (liftr ys)) ≡ lifts {σ = σ} (subComp xs (ren2sub ys))
liftsrcomp xs ys = begin
subComp (wks xs , var zero) (ren2sub (wkr ys)) , var zero ≡⟨ cong (_, var zero) (lemsr (wks xs) (var zero) ys) ⟩
subComp (wks xs) (ren2sub ys) , var zero ≡⟨ cong (_, var zero) (wksrcomp xs ys) ⟩
wks (subComp xs (ren2sub ys)) , var zero ∎
subren : ∀{Φ Γ Δ}(f : Sub Δ Γ)(g : Ren Γ Φ){σ}(t : Tm Φ σ) →
(sub f ∘ ren g) t ≡ sub (subComp f (ren2sub g)) t
subren f g (var x) = sym $ lookslookr f g x
subren f g (abs t) = begin
abs (sub (lifts f) (ren (liftr g) t)) ≡⟨ cong abs $ subren (lifts f) (liftr g) t ⟩
abs (sub (subComp (lifts f) (ren2sub (liftr g))) t) ≡⟨ cong (λ f → abs (sub f t)) $ liftsrcomp f g ⟩
abs (sub (lifts (subComp f (ren2sub g))) t) ∎
subren f g (app t u) = cong₂ app (subren f g t) (subren f g u)
looksid : ∀{Γ σ}(x : Var Γ σ) → looks subId x ≡ var x
looksid zero = refl
looksid (suc x) = begin
looks (wks subId) x ≡⟨ lookswks x subId ⟩
ren (wkr renId) (looks subId x) ≡⟨ cong (ren (wkr renId)) (looksid x) ⟩
ren (wkr renId) (var x) ≡⟨⟩
var (lookr (wkr renId) x) ≡⟨ cong var $ lookrwkr renId x ⟩
var (suc (lookr renId x)) ≡⟨ cong (λ x → var (suc x)) (lookrid x) ⟩ -- using ∘ makes it go yellow
var (suc x) ∎
subid : ∀{Γ σ}(t : Tm Γ σ) → sub subId t ≡ t
subid (var x) = looksid x
subid (abs t) = cong abs (subid t)
subid (app t u) = cong₂ app (subid t) (subid u)
sidl : ∀{Φ Γ}(xs : Sub Φ Γ) → subComp subId xs ≡ xs
sidl ε = refl
sidl (xs , t) = cong₂ _,_ (sidl xs) (subid t)
sidr2 : ∀{Φ Γ}(xs : Sub Φ Γ) → subComp xs (ren2sub renId) ≡ xs
sidr2 {Γ = ε} ε = refl
sidr2 {Γ = Γ , a} (xs , x) = begin
subComp (xs , x) (ren2sub (wkr renId)) , x ≡⟨ cong (_, x) (lemsr xs x renId) ⟩
subComp xs (ren2sub renId) , x ≡⟨ cong (_, x) (sidr2 xs) ⟩
xs , x ∎
liftSubRen : ∀{Γ Δ a b} (f : Sub Δ Γ) (t : Tm Γ b)
→ sub (lifts f) (weak a t) ≡ sub (wks f) t
liftSubRen {a = a} f t = begin
sub (lifts f) (weak a t) ≡⟨ subren (lifts f) (wkr renId) t ⟩
sub (subComp (lifts f) (ren2sub (wkr renId))) t ≡⟨ cong (λ f' → sub f' t) (lemsr (wks f) (var zero) renId) ⟩
sub (subComp (wks f) (ren2sub renId)) t ≡⟨ cong (λ f' → sub f' t) (sidr2 (wks f)) ⟩
sub (wks f) t ∎
lemss : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(x : Tm Φ σ)(ys : Sub Γ Δ) →
subComp (xs , x) (wks ys) ≡ subComp xs ys
lemss xs x ε = refl
lemss xs x (ys , y) = begin
subComp (xs , x) (wks ys) , sub (xs , x) (ren (wkr renId) y) ≡⟨ cong₂ _,_ (lemss xs x ys) (subren (xs , x) (wkr renId) y) ⟩
subComp xs ys , sub (subComp (xs , x) (ren2sub (wkr renId))) y ≡⟨ cong (λ g → subComp xs ys , sub g y) (lemsr xs x renId) ⟩
subComp xs ys , sub (subComp xs (ren2sub renId)) y ≡⟨ cong (λ g → subComp xs ys , sub g y) (sidr2 xs) ⟩
subComp xs ys , sub xs y ∎
ren2sublook : ∀{Γ Δ σ}(f : Ren Δ Γ)(i : Var Γ σ) →
var (lookr f i) ≡ looks (ren2sub f) i
ren2sublook (f , _) zero = refl
ren2sublook (f , _) (suc i) = ren2sublook f i
ren2subwk : ∀{Γ Δ σ}(g : Ren Δ Γ) →
ren2sub (wkr {σ = σ} g) ≡ wks {σ = σ} (ren2sub g)
ren2subwk ε = refl
ren2subwk (g , x) = begin
(ren2sub (wkr g) , var (suc x)) ≡⟨ cong₂ (λ xs x → xs , var (suc x)) (ren2subwk g) (sym $ lookrid x) ⟩
(wks (ren2sub g) , var (suc (lookr renId x))) ≡⟨ cong (λ x → wks (ren2sub g) , var x) (sym $ lookrwkr renId x) ⟩
(wks (ren2sub g) , var (lookr (wkr renId) x)) ∎
ren2sublift : ∀{Γ Δ σ}(g : Ren Δ Γ) →
ren2sub (liftr {σ = σ} g) ≡ lifts {σ = σ} (ren2sub g)
ren2sublift g = cong (_, var zero) (ren2subwk g)
ren2subren : ∀{Γ Δ σ}(f : Ren Δ Γ)(t : Tm Γ σ) → ren f t ≡ sub (ren2sub f) t
ren2subren f (var x) = ren2sublook f x
ren2subren f (abs t) = begin
abs (ren (liftr f) t) ≡⟨ cong abs (ren2subren (liftr f) t) ⟩
abs (sub (ren2sub (liftr f)) t) ≡⟨ cong (λ f → abs (sub f t)) (ren2sublift f) ⟩
abs (sub (lifts (ren2sub f)) t) ∎
ren2subren f (app t u) = cong₂ app (ren2subren f t) (ren2subren f u)
wkrscomp : ∀{Φ Γ Δ σ}(xs : Ren Φ Γ)(ys : Sub Γ Δ) →
subComp (ren2sub (wkr {σ = σ} xs)) ys ≡ wks {σ = σ} (subComp (ren2sub xs) ys)
wkrscomp xs ε = refl
wkrscomp xs (ys , y) = begin
subComp (ren2sub (wkr xs)) ys , sub (ren2sub (wkr xs)) y ≡⟨ cong₂ _,_ (wkrscomp xs ys) (sym $ ren2subren (wkr xs) y) ⟩
wks (subComp (ren2sub xs) ys) , ren (wkr xs) y ≡⟨ cong (λ f → wks (subComp (ren2sub xs) ys) , ren (wkr f) y) (sym $ lidr xs) ⟩
wks (subComp (ren2sub xs) ys) , ren (wkr (renComp renId xs)) y ≡⟨ cong (λ f → wks (subComp (ren2sub xs) ys) , ren f y) (sym $ wkrcomp renId xs) ⟩
wks (subComp (ren2sub xs) ys) , ren (renComp (wkr renId) xs) y ≡⟨ cong (wks (subComp (ren2sub xs) ys) ,_) (rencomp (wkr renId) xs y) ⟩
wks (subComp (ren2sub xs) ys) , ren (wkr renId) (ren xs y) ≡⟨ cong (λ t → wks (subComp (ren2sub xs) ys) , ren (wkr renId) t) (ren2subren xs y) ⟩
wks (subComp (ren2sub xs) ys) , ren (wkr renId) (sub (ren2sub xs) y) ∎
liftrscomp : ∀{Φ Γ Δ σ}(xs : Ren Φ Γ)(ys : Sub Γ Δ) →
subComp (ren2sub (liftr {σ = σ} xs)) (lifts ys) ≡ lifts {σ = σ} (subComp (ren2sub xs) ys)
liftrscomp xs ys = begin
(subComp (ren2sub (wkr xs) , var zero) (wks ys) , var zero) ≡⟨ cong (_, var zero) (lemss (ren2sub (wkr xs)) (var zero) ys) ⟩
(subComp (ren2sub (wkr xs)) ys , var zero) ≡⟨ cong (_, var zero) (wkrscomp xs ys) ⟩
(wks (subComp (ren2sub xs) ys) , var zero) ∎
renlooks : ∀{Φ Γ Δ}(f : Ren Δ Γ)(g : Sub Γ Φ){σ}(x : Var Φ σ) →
(ren f ∘ looks g) x ≡ looks (subComp (ren2sub f) g) x
renlooks f (_ , v) zero = ren2subren f v
renlooks f (g , _) (suc x) = renlooks f g x
rensub : ∀{Φ Γ Δ}(f : Ren Δ Γ)(g : Sub Γ Φ){σ}(t : Tm Φ σ) →
(ren f ∘ sub g) t ≡ sub (subComp (ren2sub f) g) t
rensub f g (var x) = renlooks f g x
rensub f g (abs t) = begin
abs (ren (liftr f) (sub (lifts g) t)) ≡⟨ cong abs $ rensub (liftr f) (lifts g) t ⟩
abs (sub (subComp (ren2sub (liftr f)) (lifts g)) t) ≡⟨ cong (λ f → abs (sub f t)) (liftrscomp f g) ⟩
abs (sub (lifts (subComp (ren2sub f) g)) t) ∎
rensub f g (app t u) = cong₂ app (rensub f g t) (rensub f g u)
lookscomp : ∀{Φ Γ Δ}(f : Sub Δ Γ)(g : Sub Γ Φ){σ}(x : Var Φ σ) →
looks (subComp f g) x ≡ sub f (looks g x)
lookscomp f (g , _) zero = refl
lookscomp f (g , _) (suc x) = lookscomp f g x
ren2subid : ∀{Γ} → subId {Γ} ≡ ren2sub renId
ren2subid {ε} = refl
ren2subid {Γ , a} = begin
(wks subId , var zero) ≡⟨ cong (λ f → wks f , var zero) (ren2subid {Γ}) ⟩
(wks (ren2sub renId) , var zero) ≡⟨ cong (_, var zero) (sym $ ren2subwk renId) ⟩
(ren2sub (wkr renId) , var zero) ∎
wksscomp : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(ys : Sub Γ Δ) →
subComp (wks {σ = σ} xs) ys ≡ wks {σ = σ} (subComp xs ys)
wksscomp xs ε = refl
wksscomp xs (ys , y) = begin
subComp (wks xs) ys , sub (wks xs) y ≡⟨ cong (λ f → subComp (wks xs) ys , sub (wks f) y) (sym $ sidl xs) ⟩
subComp (wks xs) ys , sub (wks (subComp subId xs)) y ≡⟨ cong₂ _,_ (wksscomp xs ys) (cong (λ f → sub (wks (subComp f xs)) y) ren2subid) ⟩
wks (subComp xs ys) , sub (wks (subComp (ren2sub renId) xs)) y ≡⟨ cong (λ f → wks (subComp xs ys) , sub f y) (sym $ wkrscomp renId xs) ⟩
wks (subComp xs ys) , sub (subComp (ren2sub (wkr renId)) xs) y ≡⟨ cong (wks (subComp xs ys) ,_) (sym $ rensub (wkr renId) xs y) ⟩
wks (subComp xs ys) , ren (wkr renId) (sub xs y) ∎
sidr : ∀{Φ Γ}(xs : Sub Φ Γ) → subComp xs subId ≡ xs
sidr xs = begin
subComp xs subId ≡⟨ cong (subComp xs) ren2subid ⟩
subComp xs (ren2sub renId) ≡⟨ sidr2 xs ⟩
xs ∎
liftscomp : ∀{Φ Γ Δ σ}(xs : Sub Φ Γ)(ys : Sub Γ Δ) →
subComp (lifts {σ = σ} xs) (lifts ys) ≡ lifts {σ = σ} (subComp xs ys)
liftscomp xs ys = begin
subComp (wks xs , var zero) (wks ys) , var zero ≡⟨ cong (_, var zero) (lemss (wks xs) (var zero) ys) ⟩
subComp (wks xs) ys , var zero ≡⟨ cong (_, var zero) (wksscomp xs ys) ⟩
wks (subComp xs ys) , var zero ∎
subcomp : ∀{Φ Γ Δ}(f : Sub Δ Γ)(g : Sub Γ Φ){σ}(t : Tm Φ σ) →
sub (subComp f g) t ≡ (sub f ∘ sub g) t
subcomp f g (var x) = lookscomp f g x
subcomp f g (abs t) = begin
abs (sub (lifts (subComp f g)) t) ≡⟨ cong (λ f → abs (sub f t)) (sym $ liftscomp f g) ⟩
abs (sub (subComp (lifts f) (lifts g)) t) ≡⟨ cong abs (subcomp (lifts f) (lifts g) t) ⟩
abs (sub (lifts f) (sub (lifts g) t)) ∎
subcomp f g (app t u) = cong₂ app (subcomp f g t) (subcomp f g u)
--
mutual
renembNe : ∀{Γ Δ a}(u : Ne Γ a)(σ : Ren Δ Γ) →
ren σ (embNe u) ≡ embNe (rennen σ u)
renembNe (var x) σ = refl
renembNe (app u n) σ = cong₂ app (renembNe u σ) (renembNf n σ)
renembNf : ∀{Γ Δ a}(n : Nf Γ a)(σ : Ren Δ Γ) →
ren σ (embNf n) ≡ embNf (rennf σ n)
renembNf (abs n) σ = cong abs (renembNf n (liftr σ))
renembNf (ne n) σ = renembNe n σ
-- -}
| {
"alphanum_fraction": 0.5230823446,
"avg_line_length": 41.5268292683,
"ext": "agda",
"hexsha": "ee03be0db93b994f21e4baa1660e5c6d037e98a2",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2018-02-23T18:22:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-11-10T16:44:52.000Z",
"max_forks_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "ryanakca/strong-normalization",
"max_forks_repo_path": "agda/RenamingAndSubstitution.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_issues_repo_issues_event_max_datetime": "2018-02-20T14:54:18.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-02-14T16:42:36.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "ryanakca/strong-normalization",
"max_issues_repo_path": "agda/RenamingAndSubstitution.agda",
"max_line_length": 161,
"max_stars_count": 32,
"max_stars_repo_head_hexsha": "79d97481f3312c2d30a823c3b1bcb8ae871c2fe2",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "ryanakca/strong-normalization",
"max_stars_repo_path": "agda/RenamingAndSubstitution.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-05T12:12:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-05-22T14:33:27.000Z",
"num_tokens": 6983,
"size": 17026
} |
module Issue127 where
data C : Set where
c : C
d : C
F : C → Set → Set
F c = λ A → A
F d = λ A → A
data D : C → Set where
d : (x : C) → F x (D x) → D x
-- .-< no longer
-- The following non-well-founded definition is / seemingly accepted by
-- Agda:
∞ : (x : C) → D x
∞ x = d x (d x (∞ x))
| {
"alphanum_fraction": 0.4482758621,
"avg_line_length": 16.5714285714,
"ext": "agda",
"hexsha": "92bcae54f37cdf249c4ea2aa3b560829c4de9958",
"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/Issue127.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/Issue127.agda",
"max_line_length": 71,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue127.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": 124,
"size": 348
} |
module test.StringLiteral where
open import Type
open import Declarative
open import Builtin
open import Builtin.Constant.Type
open import Builtin.Constant.Term Ctx⋆ Kind * # _⊢⋆_ con size⋆
-- zerepoch/zerepoch-core/test/data/stringLiteral.plc
postulate str1 : ByteString
{-# FOREIGN GHC import qualified Data.ByteString.Char8 as BS #-}
{-# COMPILE GHC str1 = BS.pack "4321758fabce1aa4780193f" #-}
open import Relation.Binary.PropositionalEquality
open import Agda.Builtin.TrustMe
lemma1 : length str1 ≡ 23
lemma1 = primTrustMe
open import Data.Nat
lemma1' : BoundedB 100 str1
lemma1' rewrite lemma1 = gen _ _ _
stringLit : ∀{Γ} → Γ ⊢ con bytestring (size⋆ 100)
stringLit = con (bytestring 100 str1 lemma1')
| {
"alphanum_fraction": 0.7656903766,
"avg_line_length": 25.6071428571,
"ext": "agda",
"hexsha": "231c0b0aa33747333e0b4c3386547f35f72e9e5c",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-21T16:38:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-13T21:25:19.000Z",
"max_forks_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "Quantum-One-DLT/zerepoch",
"max_forks_repo_path": "zerepoch-metatheory/test/StringLiteral.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"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": "Quantum-One-DLT/zerepoch",
"max_issues_repo_path": "zerepoch-metatheory/test/StringLiteral.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c8cf4619e6e496930c9092cf6d64493eff300177",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "Quantum-One-DLT/zerepoch",
"max_stars_repo_path": "zerepoch-metatheory/test/StringLiteral.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 221,
"size": 717
} |
------------------------------------------------------------------------
-- Simplification of parsers
------------------------------------------------------------------------
module TotalParserCombinators.Simplification where
open import Algebra
open import Codata.Musical.Notation
open import Data.List using (List; [])
import Data.List.Relation.Binary.BagAndSetEquality as BSEq
open import Data.Maybe using (Maybe); open Data.Maybe.Maybe
open import Data.Nat
open import Data.Product
open import Data.Vec.Recursive hiding ([])
open import Function
open import Relation.Binary.PropositionalEquality as P
using (_≡_; refl; [_])
open import Relation.Binary.HeterogeneousEquality
using (refl) renaming (_≅_ to _≅H_)
private
module BSMonoid {k} {A : Set} =
CommutativeMonoid (BSEq.commutativeMonoid k A)
open import TotalParserCombinators.Congruence
hiding (return; fail; token) renaming (_∣_ to _∣′_)
import TotalParserCombinators.Congruence.Sound as C
import TotalParserCombinators.InitialBag as I
open import TotalParserCombinators.Laws
open import TotalParserCombinators.Parser
------------------------------------------------------------------------
-- Simplification of a single "layer"
-- The result type used for single-layer simplification.
record Simplify₁ {Tok R xs} (p : Parser Tok R xs) : Set₁ where
constructor result
field
{bag} : List R
parser : Parser Tok R bag
correct : p ≅P parser
-- The function simplify₁ simplifies the first "layer" of a parser,
-- down to the first occurrences of ♯_. The following simplifications
-- are applied in a bottom-up manner (in relevant cases also for
-- delayed arguments):
--
-- f <$> fail → fail
-- f <$> return x → return (f x)
-- fail ∣ p → p
-- p ∣ fail → p
-- token >>= p₁ ∣ token >>= p₂ → token >>= λ t →
-- ♯ (♭? (p₁ t) ∣ ♭? (p₂ t))
-- fail ⊛ p → fail
-- p ⊛ fail → fail
-- return f ⊛ return x → return (f x)
-- fail >>= p → fail
-- return x >>= p → p x
-- nonempty fail → fail
-- nonempty (return x) → fail
-- cast eq p → p
--
-- Some ♯_'s may be removed, but care is taken to ensure that
-- non-simplified parsers in the result are delayed.
mutual
simplify₁ : ∀ {Tok R xs} (p : Parser Tok R xs) → Simplify₁ p
-- • return:
simplify₁ (return x) = result _ (return x ∎)
-- • fail:
simplify₁ fail = result _ (fail ∎)
-- • token:
simplify₁ token = result _ (token ∎)
-- • _<$>_:
simplify₁ (f <$> p) with simplify₁ p
... | result fail p≅∅ = result _ (
f <$> p ≅⟨ (λ _ → refl) <$> p≅∅ ⟩
f <$> fail ≅⟨ <$>.zero ⟩
fail ∎)
... | result (return x) p≅ε = result _ (
f <$> p ≅⟨ (λ x → refl {x = f x}) <$> p≅ε ⟩
f <$> return x ≅⟨ <$>.homomorphism f ⟩
return (f x) ∎)
... | result p′ p≅p′ = result _ (
f <$> p ≅⟨ (λ _ → refl) <$> p≅p′ ⟩
f <$> p′ ∎)
-- • _∣_:
simplify₁ (p₁ ∣ p₂) with simplify₁ p₁ | simplify₁ p₂
... | result fail p₁≅∅
| result p₂′ p₂≅p₂′ = result _ (
p₁ ∣ p₂ ≅⟨ p₁≅∅ ∣′ p₂≅p₂′ ⟩
fail ∣ p₂′ ≅⟨ AdditiveMonoid.left-identity p₂′ ⟩
p₂′ ∎)
... | result p₁′ p₁≅p₁′
| result fail p₂≅∅ = result _ (
p₁ ∣ p₂ ≅⟨ p₁≅p₁′ ∣′ p₂≅∅ ⟩
p₁′ ∣ fail ≅⟨ AdditiveMonoid.right-identity p₁′ ⟩
p₁′ ∎)
... | result (p₁₁ >>= p₁₂) p₁≅…
| result (p₂₁ >>= p₂₂) p₂≅… = let h = helper p₁₁ refl p₁₂ p₂₁ refl p₂₂ in
result _ (
p₁ ∣ p₂ ≅⟨ p₁≅… ∣′ p₂≅… ⟩
p₁₁ >>= p₁₂ ∣ p₂₁ >>= p₂₂ ≅⟨ Simplify₁.correct h ⟩
Simplify₁.parser h ∎)
where
helper : ∀ {Tok R₁ R₂ R xs₁ xs₁′ xs₂ xs₂′ f₁ f₂}
(p₁₁ : ∞⟨ f₁ ⟩Parser Tok R₁ xs₁′)
(eq₁ : xs₁′ ≡ flatten xs₁)
(p₁₂ : (x : R₁) → ∞⟨ xs₁ ⟩Parser Tok R (apply f₁ x))
(p₂₁ : ∞⟨ f₂ ⟩Parser Tok R₂ xs₂′)
(eq₂ : xs₂′ ≡ flatten xs₂)
(p₂₂ : (x : R₂) → ∞⟨ xs₂ ⟩Parser Tok R (apply f₂ x)) →
Simplify₁ (P.subst (∞⟨ f₁ ⟩Parser Tok R₁) eq₁ p₁₁ >>= p₁₂ ∣
P.subst (∞⟨ f₂ ⟩Parser Tok R₂) eq₂ p₂₁ >>= p₂₂)
helper p₁₁ eq₁ p₁₂ p₂₁ eq₂ p₂₂
with ♭? p₁₁ | P.inspect ♭? p₁₁ | ♭? p₂₁ | P.inspect ♭? p₂₁
helper {Tok} {f₁ = f₁} {f₂} p₁₁ eq₁ p₁₂ p₂₁ eq₂ p₂₂
| token | [ eq₁′ ] | token | [ eq₂′ ] = result _ (
cast₁ p₁₁ >>= p₁₂ ∣ cast₂ p₂₁ >>= p₂₂ ≅⟨ [ forced? p₁₁ - ○ - forced?′ p₁₂ - ○ ] Subst.correct∞ eq₁ p₁₁ >>=
(λ t → ♭? (p₁₂ t) ∎) ∣′
[ forced? p₂₁ - ○ - forced?′ p₂₂ - ○ ] Subst.correct∞ eq₂ p₂₁ >>=
(λ t → ♭? (p₂₂ t) ∎) ⟩
♭? p₁₁ >>= (♭? ∘ p₁₂) ∣ ♭? p₂₁ >>= (♭? ∘ p₂₂) ≅⟨ [ ○ - ○ - ○ - ○ ]
P.subst (λ p → p ≅P token) (P.sym eq₁′) (token ∎) >>= (λ t → ♭? (p₁₂ t) ∎) ∣′
[ ○ - ○ - ○ - ○ ]
P.subst (λ p → p ≅P token) (P.sym eq₂′) (token ∎) >>= (λ t → ♭? (p₂₂ t) ∎) ⟩
token >>= (♭? ∘ p₁₂) ∣ token >>= (♭? ∘ p₂₂) ≅⟨ sym $ Monad.left-distributive token (♭? ∘ p₁₂) (♭? ∘ p₂₂) ⟩
token >>= (λ t → ♭? (p₁₂ t) ∣ ♭? (p₂₂ t)) ≅⟨ [ ○ - ○ - ○ - ◌ ] token ∎ >>= (λ t → ♭? (p₁₂ t) ∣ ♭? (p₂₂ t) ∎) ⟩
token >>= (λ t → ♯ (♭? (p₁₂ t) ∣ ♭? (p₂₂ t))) ∎)
where
cast₁ = P.subst (∞⟨ f₁ ⟩Parser Tok Tok) eq₁
cast₂ = P.subst (∞⟨ f₂ ⟩Parser Tok Tok) eq₂
helper _ _ _ _ _ _ | _ | _ | _ | _ = result _ (_ ∎)
simplify₁ (p₁ ∣ p₂) | result p₁′ p₁≅p₁′ | result p₂′ p₂≅p₂′ =
result _ (
p₁ ∣ p₂ ≅⟨ p₁≅p₁′ ∣′ p₂≅p₂′ ⟩
p₁′ ∣ p₂′ ∎)
-- • _⊛_:
simplify₁ (p₁ ⊛ p₂) =
helper _ _ p₁ p₂ (simplify₁∞ p₁) (simplify₁∞ p₂) refl refl
where
-- token ⊛ token is never type correct, but Agda's case-splitting
-- machinery cannot see this, so instead of a with clause the
-- following ugly machinery is used.
cast₁ : ∀ {Tok R R₁ R₁′ xs xs′} {ys : Maybe (List R)} →
(R≡ : R₁ ≡ R₁′) → xs ≅H xs′ →
∞⟨ ys ⟩Parser Tok R₁′ (flatten xs′) →
∞⟨ ys ⟩Parser Tok R₁ (flatten xs)
cast₁ refl refl p = p
helper : ∀ {Tok R₁ R₁′ R₂} fs xs {xs′}
(p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs))
(p₂ : ∞⟨ fs ⟩Parser Tok R₁′ (flatten xs′)) →
Simplify₁ (♭? p₁) → Simplify₁ (♭? p₂) →
(R≡ : R₁ ≡ R₁′) (xs≅ : xs ≅H xs′) →
Simplify₁ (p₁ ⊛ cast₁ R≡ xs≅ p₂)
helper fs xs p₁ p₂ (result fail p₁≅∅) _ refl refl = result _ (
p₁ ⊛ p₂ ≅⟨ [ xs - ○ - fs - ○ ] p₁≅∅ ⊛ (♭? p₂ ∎) ⟩
fail ⊛ ♭? p₂ ≅⟨ ApplicativeFunctor.left-zero (♭? p₂) ⟩
fail ∎)
helper fs xs p₁ p₂ _ (result fail p₂≅∅) refl refl = result _ (
p₁ ⊛ p₂ ≅⟨ [ xs - ○ - fs - ○ ] ♭? p₁ ∎ ⊛ p₂≅∅ ⟩
♭? p₁ ⊛ fail ≅⟨ ApplicativeFunctor.right-zero (♭? p₁) ⟩
fail ∎)
helper fs xs p₁ p₂ (result (return f) p₁≅ε) (result (return x) p₂≅ε)
refl refl = result _ (
p₁ ⊛ p₂ ≅⟨ [ xs - ○ - fs - ○ ] p₁≅ε ⊛ p₂≅ε ⟩
return f ⊛ return x ≅⟨ ApplicativeFunctor.homomorphism f x ⟩
return (f x) ∎)
helper fs xs p₁ p₂ p₁′ p₂′ R≡ xs≅ =
helper′ fs xs p₁ p₂ p₁′ p₂′ R≡ xs≅
where
helper′ :
∀ {Tok R₁ R₁′ R₂} fs xs {xs′}
(p₁ : ∞⟨ xs ⟩Parser Tok (R₁ → R₂) (flatten fs))
(p₂ : ∞⟨ fs ⟩Parser Tok R₁′ (flatten xs′)) →
Simplify₁ (♭? p₁) → Simplify₁ (♭? p₂) →
(R≡ : R₁ ≡ R₁′) (xs≅ : xs ≅H xs′) →
Simplify₁ (p₁ ⊛ cast₁ R≡ xs≅ p₂)
helper′ nothing nothing p₁ p₂ _ _ refl refl = result _ (
p₁ ⊛ p₂ ∎)
helper′ (just fs) nothing p₁ p₂ _ (result p₂′ p₂≅p₂′) refl refl
with BSEq.empty-unique $ I.cong $ C.sound $ sym p₂≅p₂′
helper′ (just fs) nothing p₁ p₂ _ (result p₂′ p₂≅p₂′) refl refl
| refl = result _ (
p₁ ⊛ p₂ ≅⟨ [ ◌ - ◌ - ○ - ○ ] ♭ p₁ ∎ ⊛ p₂≅p₂′ ⟩
p₁ ⊛ p₂′ ∎)
helper′ nothing (just xs) p₁ p₂ (result p₁′ p₁≅p₁′) _ refl refl
with BSEq.empty-unique $ I.cong $ C.sound $ sym p₁≅p₁′
helper′ nothing (just xs) p₁ p₂ (result p₁′ p₁≅p₁′) _ refl refl
| refl = result _ (
p₁ ⊛ p₂ ≅⟨ [ ○ - ○ - ◌ - ◌ ] p₁≅p₁′ ⊛ (♭ p₂ ∎) ⟩
p₁′ ⊛ p₂ ∎)
helper′ (just fs) (just xs)
p₁ p₂ (result p₁′ p₁≅p₁′) (result p₂′ p₂≅p₂′) refl refl =
result _ (
p₁ ⊛ p₂ ≅⟨ [ ○ - ○ - ○ - ○ ] p₁≅p₁′ ⊛ p₂≅p₂′ ⟩
p₁′ ⊛ p₂′ ∎)
-- • _>>=_:
simplify₁ (_>>=_ {xs = xs} {f = f} p₁ p₂) with simplify₁∞ p₁
... | result fail p₁≅∅ = result _ (
p₁ >>= p₂ ≅⟨ [ f - ○ - xs - ○ ] p₁≅∅ >>= (λ x → ♭? (p₂ x) ∎) ⟩
fail >>= (♭? ∘ p₂) ≅⟨ Monad.left-zero (♭? ∘ p₂) ⟩
fail ∎)
... | result (return x) p₁≅ε with simplify₁∞ (p₂ x)
... | result p₂x′ p₂x≅p₂x′ = result _ (
p₁ >>= p₂ ≅⟨ [ f - ○ - xs - ○ ] p₁≅ε >>= (λ x → ♭? (p₂ x) ∎) ⟩
return x >>= (♭? ∘ p₂) ≅⟨ Monad.left-identity x (♭? ∘ p₂) ⟩
♭? (p₂ x) ≅⟨ p₂x≅p₂x′ ⟩
p₂x′ ∎)
simplify₁ (p₁ >>= p₂) | result p₁′ p₁≅p₁′
with forced? p₁ | forced?′ p₂
... | nothing | just xs = result _ (
p₁ >>= p₂ ≅⟨ [ ◌ - ◌ - ○ - ○ ] ♭ p₁ ∎ >>= (λ x → simplify₁-[]-correct (p₂ x)) ⟩
p₁ >>= (λ x → simplify₁-[] (p₂ x)) ∎)
... | just f | just xs = result _ (
p₁ >>= p₂ ≅⟨ [ ○ - ○ - ○ - ○ ] p₁≅p₁′ >>=
(λ x → Simplify₁.correct (simplify₁ (p₂ x))) ⟩
p₁′ >>= (λ x → Simplify₁.parser $
simplify₁ (p₂ x)) ∎)
... | nothing | nothing = result _ (
p₁ >>= p₂ ∎)
... | just f | nothing = result _ (
p₁ >>= p₂ ≅⟨ [ ○ - ○ - ◌ - ○ ] p₁≅p₁′ >>= (λ x → ♭ (p₂ x) ∎) ⟩
p₁′ >>= (♭ ∘ p₂) ≅⟨ [ ○ - ○ - ○ - ◌ ] sym (Subst.correct lemma) >>= (λ x → ♭ (p₂ x) ∎) ⟩
cast-[] p₁′ >>= p₂ ∎)
where
lemma = BSEq.empty-unique $ I.cong $ C.sound $ sym p₁≅p₁′
cast-[] = P.subst (Parser _ _) lemma
-- • nonempty:
simplify₁ (nonempty p) with simplify₁ p
... | result fail p≅∅ = result _ (
nonempty p ≅⟨ nonempty p≅∅ ⟩
nonempty fail ≅⟨ Nonempty.zero ⟩
fail ∎)
... | result (return x) p≅ε = result _ (
nonempty p ≅⟨ nonempty p≅ε ⟩
nonempty (return x) ≅⟨ Nonempty.nonempty-return ⟩
fail ∎)
... | result p′ p≅p′ = result _ (
nonempty p ≅⟨ nonempty p≅p′ ⟩
nonempty p′ ∎)
-- • cast:
simplify₁ (cast xs₁≈xs₂ p) with simplify₁ p
... | result p′ p≅p′ = result _ (
cast xs₁≈xs₂ p ≅⟨ Cast.correct ⟩
p ≅⟨ p≅p′ ⟩
p′ ∎)
private
-- Note that if an argument parser is delayed, then simplification
-- is not applied recursively (because this could lead to
-- non-termination).
simplify₁∞ : ∀ {Tok R R′ xs} {m : Maybe R′}
(p : ∞⟨ m ⟩Parser Tok R xs) → Simplify₁ (♭? p)
simplify₁∞ {m = nothing} p = result _ (♭ p ∎)
simplify₁∞ {m = just _} p = simplify₁ p
simplify₁-[] : ∀ {Tok R} → Parser Tok R [] → Parser Tok R []
simplify₁-[] p = P.subst (Parser _ _) ([]-lemma p) $
Simplify₁.parser $ simplify₁ p
simplify₁-[]-correct : ∀ {Tok R} (p : Parser Tok R []) →
p ≅P simplify₁-[] p
simplify₁-[]-correct p =
p ≅⟨ Simplify₁.correct (simplify₁ p) ⟩
Simplify₁.parser (simplify₁ p) ≅⟨ sym $ Subst.correct ([]-lemma p) ⟩
simplify₁-[] p ∎
[]-lemma : ∀ {Tok R} (p : Parser Tok R []) →
Simplify₁.bag (simplify₁ p) ≡ []
[]-lemma p = BSEq.empty-unique $ I.cong $ C.sound $
sym $ Simplify₁.correct $ simplify₁ p
------------------------------------------------------------------------
-- Deep simplification
-- The function simplify simplifies the first layer, then it traverses
-- the result and simplifies the following layers, and so on. The
-- extra traversals have been implemented to satisfy Agda's
-- termination checker; they could perhaps be avoided.
--
-- Note that simplifications in an upper layer do not get to take
-- advantage of simplifications performed in lower layers. Consider
-- ♯ p ⊛ token, for instance. If p can be simplified to fail, then one
-- might believe that ♯ p ⊛ token is simplified to fail as well.
-- However, this is only the case if p actually /computes/ to fail.
--
-- If simplification of the upper layer were dependent on complete
-- simplification of lower layers, then simplification could fail to
-- terminate. This does not mean that one cannot propagate /any/
-- information from lower layers to upper layers, though: one could
-- for instance perform partial simplification of lower layers, up to
-- a certain depth, before an upper layer is simplified.
mutual
simplify : ∀ {Tok R xs} (p : Parser Tok R xs) →
Parser Tok R (Simplify₁.bag $ simplify₁ p)
simplify p = simplify↓ (Simplify₁.parser (simplify₁ p))
private
simplify↓ : ∀ {Tok R xs} → Parser Tok R xs → Parser Tok R xs
simplify↓ (return x) = return x
simplify↓ fail = fail
simplify↓ token = token
simplify↓ (p₁ ∣ p₂) = simplify↓ p₁ ∣ simplify↓ p₂
simplify↓ (f <$> p) = f <$> simplify↓ p
simplify↓ (nonempty p) = nonempty (simplify↓ p)
simplify↓ (cast xs₁≈xs₂ p) = cast xs₁≈xs₂ (simplify↓ p)
simplify↓ (p₁ ⊛ p₂) with forced? p₁ | forced? p₂
... | just xs | just fs = simplify↓ p₁ ⊛ simplify↓ p₂
... | just xs | nothing = simplify↓ p₁ ⊛ ♯ simplify (♭ p₂)
... | nothing | just fs = ♯ simplify (♭ p₁) ⊛ simplify↓ p₂
... | nothing | nothing = ♯ simplify-[] (♭ p₁) ⊛ ♯ simplify-[] (♭ p₂)
simplify↓ (p₁ >>= p₂) with forced? p₁ | forced?′ p₂
... | just f | just xs = simplify↓ p₁ >>= λ x → simplify↓ (p₂ x)
... | just f | nothing = simplify↓ p₁ >>= λ x → ♯ simplify (♭ (p₂ x))
... | nothing | just xs = ♯ simplify (♭ p₁) >>= λ x → simplify↓ (p₂ x)
... | nothing | nothing = ♯ simplify-[] (♭ p₁) >>= λ x → ♯ simplify-[] (♭ (p₂ x))
simplify-[] : ∀ {Tok R} → Parser Tok R [] → Parser Tok R []
simplify-[] p = simplify↓ (simplify₁-[] p)
-- The simplifier is correct.
mutual
correct : ∀ {Tok R xs} (p : Parser Tok R xs) → simplify p ≅P p
correct p =
simplify↓ (Simplify₁.parser $ simplify₁ p) ≅⟨ correct↓ (Simplify₁.parser $ simplify₁ p) ⟩
Simplify₁.parser (simplify₁ p) ≅⟨ sym $ Simplify₁.correct $ simplify₁ p ⟩
p ∎
private
correct↓ : ∀ {Tok R xs} (p : Parser Tok R xs) → simplify↓ p ≅P p
correct↓ (return x) = return x ∎
correct↓ fail = fail ∎
correct↓ token = token ∎
correct↓ (p₁ ∣ p₂) = correct↓ p₁ ∣′ correct↓ p₂
correct↓ (f <$> p) = (λ _ → refl) <$> correct↓ p
correct↓ (nonempty p) = nonempty (correct↓ p)
correct↓ (cast xs₁≈xs₂ p) = cast (correct↓ p)
correct↓ (p₁ ⊛ p₂) with forced? p₁ | forced? p₂
... | just xs | just fs = [ just (○ , ○) - just (○ , ○) ] correct↓ p₁ ⊛ correct↓ p₂
... | just xs | nothing = [ just (○ , ○) - nothing ] correct↓ p₁ ⊛ ♯ correct (♭ p₂)
... | nothing | just fs = [ nothing - just (○ , ○) ] ♯ correct (♭ p₁) ⊛ correct↓ p₂
... | nothing | nothing = [ nothing - nothing ] ♯ correct-[] (♭ p₁) ⊛ ♯ correct-[] (♭ p₂)
correct↓ (p₁ >>= p₂) with forced? p₁ | forced?′ p₂
... | just f | just xs = [ just (○ , ○) - just (○ , ○) ] correct↓ p₁ >>= λ x → correct↓ (p₂ x)
... | just f | nothing = [ just (○ , ○) - nothing ] correct↓ p₁ >>= λ x → ♯ correct (♭ (p₂ x))
... | nothing | just xs = [ nothing - just (○ , ○) ] ♯ correct (♭ p₁) >>= λ x → correct↓ (p₂ x)
... | nothing | nothing = [ nothing - nothing ] ♯ correct-[] (♭ p₁) >>= λ x → ♯ correct-[] (♭ (p₂ x))
correct-[] : ∀ {Tok R} (p : Parser Tok R []) → simplify-[] p ≅P p
correct-[] p =
simplify-[] p ≅⟨ correct↓ (simplify₁-[] p) ⟩
simplify₁-[] p ≅⟨ sym $ simplify₁-[]-correct p ⟩
p ∎
| {
"alphanum_fraction": 0.4361508309,
"avg_line_length": 46.9248704663,
"ext": "agda",
"hexsha": "fc30b0dfcb1c2b9cdde03b6c76108edc8471134e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "TotalParserCombinators/Simplification.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"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/parser-combinators",
"max_issues_repo_path": "TotalParserCombinators/Simplification.agda",
"max_line_length": 135,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/parser-combinators",
"max_stars_repo_path": "TotalParserCombinators/Simplification.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-03T08:56:13.000Z",
"num_tokens": 6232,
"size": 18113
} |
import MJ.Classtable.Core as Core
module MJ.Classtable.Membership {c}(Ct : Core.Classtable c) where
open Core c
open Classtable Ct
open import Prelude
open import Data.Star
open import Data.Product hiding (Σ)
open import Data.List
open import Data.List.Relation.Unary.Any
open import Data.List.Relation.Unary.Any.Properties
open import Data.List.First.Membership
open import Data.Product.Relation.Binary.Pointwise.NonDependent
open import Relation.Nullary.Decidable
open import Data.Maybe
open import Data.String as Str
open import Function.Equality using (Π)
open import Function.Inverse using (Inverse)
open import MJ.Types as Types
{-
We can observe that a class declares a member in a particular namespace using a
predicate Declares.
-}
Declares : Cid c → (ns : NS) → String → typing ns → Set
Declares cid ns m ty = let cl = Σ cid in (m , ty) ∈ (Class.decls cl ns)
{-
We define a notion of *declarative membership* of C as the product
of a witness that C inherits from P and a declaration in P.
-}
IsMember : Cid c → (ns : NS) → String → typing ns → Set
IsMember cid ns m ty = let C = Σ cid in ∃ λ P → Σ ⊢ cid <: P × Declares P ns m ty
{-
We can prove that Object has no members.
-}
∉Object : ∀ {ns m a} → ¬ IsMember Object ns m a
∉Object (.Object , ε , mem) rewrite Σ-Object = ¬x∈[] mem
∉Object (._ , () ◅ _ , _)
{-
And we can show that Declares and IsMember are decidable relations
-}
find-declaration : ∀ cid ns n ty → Dec (Declares cid ns n ty)
find-declaration cid ns m ty = find (Str._≟_ ×-≟ _typing-≟_) (m , ty) (Class.decls (Σ cid) ns)
find-member : ∀ cid ns n ty → Dec (IsMember cid ns n ty)
find-member cid ns n ty = helper cid ns n ty (rooted cid)
where
helper : ∀ cid ns n ty → Σ ⊢ cid <: Object → Dec (IsMember cid ns n ty)
helper cid ns n ty ε = no (⊥-elim ∘ ∉Object)
helper cid ns n ty (super ◅ p) with find-declaration cid ns n ty
... | yes q = yes (cid , ε , q)
... | no ¬q with helper _ ns n ty p
... | yes (pid , s , d) = yes (pid , super ◅ s , d)
... | no ¬r = no impossible
where
impossible : ¬ (IsMember cid ns n ty)
impossible (_ , ε , d) = ¬q d
impossible (pid , Core.super ◅ s , d) = ¬r (pid , s , d)
{-
Using said decision procedures we can formalize a notion of accessible members.
-}
AccMember : Cid c → (ns : NS) → String → typing ns → Set
AccMember cid ns n ty = True (find-member cid ns n ty)
{-
All accessible members are also declarative members, but not vice versa,
because overrides make their super inaccessible.
-}
sound : ∀ {cid ns n ty} → AccMember cid ns n ty → IsMember cid ns n ty
sound p = toWitness p
{-
Declarative members are inherited:
-}
inherit' : ∀ {C P ns m a} → Σ ⊢ C <: P → IsMember P ns m a → IsMember C ns m a
inherit' S (_ , S' , def) = -, S ◅◅ S' , def
{-
Accessible members are inherited (but may point to different definitions thanks to overrides):
-}
inherit : ∀ {m ns ty pid} cid → Σ ⊢ cid <: pid → AccMember pid ns m ty → AccMember cid ns m ty
inherit {m}{ns}{ty} cid s mb with find-member cid ns m ty
... | yes mb' = tt
... | no ¬mb = ⊥-elim (¬mb (inherit' s (sound mb)))
| {
"alphanum_fraction": 0.6646321876,
"avg_line_length": 33.4731182796,
"ext": "agda",
"hexsha": "f0ad55dc0c4499ca7ae82f2ff06bfc8854b1b304",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Classtable/Membership.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Classtable/Membership.agda",
"max_line_length": 94,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Classtable/Membership.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 953,
"size": 3113
} |
{-# OPTIONS --without-K --exact-split #-}
module rings-with-properties where
import rings
open rings public
--------------------------------------------------------------------------------
{- Commutative rings -}
is-commutative-Ring :
{ l : Level} → Ring l → UU l
is-commutative-Ring R =
(x y : type-Ring R) → Id (mul-Ring R x y) (mul-Ring R y x)
is-prop-is-commutative-Ring :
{ l : Level} (R : Ring l) → is-prop (is-commutative-Ring R)
is-prop-is-commutative-Ring R =
is-prop-Π
( λ x →
is-prop-Π
( λ y →
is-set-type-Ring R (mul-Ring R x y) (mul-Ring R y x)))
Comm-Ring :
( l : Level) → UU (lsuc l)
Comm-Ring l = Σ (Ring l) is-commutative-Ring
ring-Comm-Ring :
{ l : Level} → Comm-Ring l → Ring l
ring-Comm-Ring = pr1
is-commutative-Comm-Ring :
{ l : Level} (R : Comm-Ring l) → is-commutative-Ring (ring-Comm-Ring R)
is-commutative-Comm-Ring = pr2
hom-Comm-Ring :
{ l1 l2 : Level} → Comm-Ring l1 → Comm-Ring l2 → UU (l1 ⊔ l2)
hom-Comm-Ring R1 R2 = hom-Ring (ring-Comm-Ring R1) (ring-Comm-Ring R2)
iso-Comm-Ring :
{ l1 l2 : Level} → Comm-Ring l1 → Comm-Ring l2 → UU (l1 ⊔ l2)
iso-Comm-Ring R1 R2 = iso-Ring (ring-Comm-Ring R1) (ring-Comm-Ring R2)
is-contr-total-iso-Comm-Ring :
{ l1 : Level} (R1 : Comm-Ring l1) →
is-contr (Σ (Comm-Ring l1) (iso-Comm-Ring R1))
is-contr-total-iso-Comm-Ring R1 =
is-contr-total-Eq-substructure
( is-contr-total-iso-Ring (ring-Comm-Ring R1))
( is-prop-is-commutative-Ring)
( ring-Comm-Ring R1)
( id-iso-Ring (ring-Comm-Ring R1))
( is-commutative-Comm-Ring R1)
--------------------------------------------------------------------------------
{- Division rings -}
zero-neq-one-Ring :
{ l : Level} → Ring l → UU l
zero-neq-one-Ring R = ¬ (Id (zero-Ring R) (unit-Ring R))
has-left-inverse-Ring :
{ l : Level} (R : Ring l) → type-Ring R → UU l
has-left-inverse-Ring R x =
Σ (type-Ring R) (λ y → Id (mul-Ring R y x) (unit-Ring R))
has-right-inverse-Ring :
{l : Level} (R : Ring l) → type-Ring R → UU l
has-right-inverse-Ring R x =
Σ (type-Ring R) (λ y → Id (mul-Ring R x y) (unit-Ring R))
has-two-sided-inverse-Ring :
{l : Level} (R : Ring l) → type-Ring R → UU l
has-two-sided-inverse-Ring R x =
( has-left-inverse-Ring R x) × (has-right-inverse-Ring R x)
is-invertible-Ring :
{l : Level} (R : Ring l) → type-Ring R → UU l
is-invertible-Ring R x =
Σ ( type-Ring R)
( λ y →
Id (mul-Ring R y x) (unit-Ring R) ×
Id (mul-Ring R x y) (unit-Ring R))
is-division-Ring :
{ l : Level} → Ring l → UU l
is-division-Ring R =
(zero-neq-one-Ring R) ×
((x : type-Ring R) → ¬ (Id (zero-Ring R) x) → is-invertible-Ring R x)
--------------------------------------------------------------------------------
{- Fields -}
is-field-Comm-Ring :
{ l : Level} → Comm-Ring l → UU l
is-field-Comm-Ring R = is-division-Ring (ring-Comm-Ring R)
| {
"alphanum_fraction": 0.5593043478,
"avg_line_length": 28.4653465347,
"ext": "agda",
"hexsha": "3face78a0305a7c727a5716fa9ce9138d3be8be3",
"lang": "Agda",
"max_forks_count": 30,
"max_forks_repo_forks_event_max_datetime": "2022-03-16T00:33:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-26T09:08:57.000Z",
"max_forks_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_forks_repo_path": "Agda/rings-with-properties.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_issues_repo_issues_event_max_datetime": "2020-10-16T15:27:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-18T04:16:04.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_issues_repo_path": "Agda/rings-with-properties.agda",
"max_line_length": 80,
"max_stars_count": 333,
"max_stars_repo_head_hexsha": "1e1f8def50f9359928e52ebb2ee53ed1166487d9",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Intro",
"max_stars_repo_path": "Agda/rings-with-properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:50:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-26T08:33:30.000Z",
"num_tokens": 1024,
"size": 2875
} |
-- Andreas, 2017-01-12, issue #2386
-- Should be rejected:
data Eq (A : Set) : (x y : A) → Set where
refl : (x y : A) → Eq A x y
{-# BUILTIN EQUALITY Eq #-}
-- Expected error:
-- Wrong type of constructor of BUILTIN EQUALITY
-- when checking the pragma BUILTIN EQUALITY Eq
| {
"alphanum_fraction": 0.6474820144,
"avg_line_length": 23.1666666667,
"ext": "agda",
"hexsha": "4aa23e0fbe94e4d76482277d911dd5de26031376",
"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/Issue2386-b.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/Issue2386-b.agda",
"max_line_length": 48,
"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/Issue2386-b.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": 87,
"size": 278
} |
------------------------------------------------------------------------
-- Reasoning about _⇔_
--
-- NOTE: we don’t use Relation.Binary.IsEquivalence here, since we’re reasoning
-- about a heterogeneous equivalence relation (i.e., the types of the operands
-- of _⇔_, which are themselves types, can be of different levels). In the proof
-- of Chapter₁₅.problem₁, the fact that _⇔_ is heterogeneous is actually used,
-- so we cannot use a homogeneous version of _⇔_.
------------------------------------------------------------------------
module Function.Equivalence.Reasoning where
open import Function using (_⇔_)
open import Function.Construct.Composition using (_∘-⇔_) public
open import Function.Construct.Identity using (id-⇔) public
open import Function.Construct.Symmetry using (sym-⇔) public
open import Level using (Level)
private
variable
a b c : Level
infix 1 begin_
infixr 2 _⇔⟨⟩_ step-⇔ step-⇔˘
infix 3 _∎
begin_ : {A : Set a} {B : Set b} → A ⇔ B → A ⇔ B
begin A⇔B = A⇔B
_∎ : (A : Set a) → A ⇔ A
_∎ = id-⇔
_⇔⟨⟩_ : (A : Set a) {B : Set b} → A ⇔ B → A ⇔ B
A ⇔⟨⟩ A⇔B = A⇔B
step-⇔ : (A : Set a) {B : Set b} {C : Set c} → A ⇔ B → B ⇔ C → A ⇔ C
step-⇔ A = _∘-⇔_
syntax step-⇔ A A⇔B B⇔C = A ⇔⟨ A⇔B ⟩ B⇔C
step-⇔˘ : (A : Set a) {B : Set b} {C : Set c} → B ⇔ A → B ⇔ C → A ⇔ C
step-⇔˘ A B⇔A B⇔C = A ⇔⟨ sym-⇔ B⇔A ⟩ B⇔C
syntax step-⇔˘ A B⇔A B⇔C = A ⇔˘⟨ B⇔A ⟩ B⇔C
| {
"alphanum_fraction": 0.5526695527,
"avg_line_length": 30.8,
"ext": "agda",
"hexsha": "2b87ade51ba6406dfab2aa6c02926dc0685232ad",
"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": "Function/Equivalence/Reasoning.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": "Function/Equivalence/Reasoning.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": "Function/Equivalence/Reasoning.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": 571,
"size": 1386
} |
{-# OPTIONS --rewriting #-}
module Properties.StrictMode where
import Agda.Builtin.Equality.Rewrite
open import Agda.Builtin.Equality using (_≡_; refl)
open import FFI.Data.Either using (Either; Left; Right; mapL; mapR; mapLR; swapLR; cond)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Luau.Heap using (Heap; Object; function_is_end; defn; alloc; ok; next; lookup-not-allocated) renaming (_≡_⊕_↦_ to _≡ᴴ_⊕_↦_; _[_] to _[_]ᴴ; ∅ to ∅ᴴ)
open import Luau.StrictMode using (Warningᴱ; Warningᴮ; Warningᴼ; Warningᴴ; UnallocatedAddress; UnboundVariable; FunctionCallMismatch; app₁; app₂; BinOpMismatch₁; BinOpMismatch₂; bin₁; bin₂; BlockMismatch; block₁; return; LocalVarMismatch; local₁; local₂; FunctionDefnMismatch; function₁; function₂; heap; expr; block; addr)
open import Luau.Substitution using (_[_/_]ᴮ; _[_/_]ᴱ; _[_/_]ᴮunless_; var_[_/_]ᴱwhenever_)
open import Luau.Subtyping using (_≮:_; witness; unknown; never; scalar; function; scalar-function; scalar-function-ok; scalar-function-err; scalar-scalar; function-scalar; function-ok; function-err; left; right; _,_; Tree; Language; ¬Language)
open import Luau.Syntax using (Expr; yes; var; val; var_∈_; _⟨_⟩∈_; _$_; addr; number; bool; string; binexp; nil; function_is_end; block_is_end; done; return; local_←_; _∙_; fun; arg; name; ==; ~=)
open import Luau.Type using (Type; nil; number; boolean; string; _⇒_; never; unknown; _∩_; _∪_; src; tgt; _≡ᵀ_; _≡ᴹᵀ_)
open import Luau.TypeCheck using (_⊢ᴮ_∈_; _⊢ᴱ_∈_; _⊢ᴴᴮ_▷_∈_; _⊢ᴴᴱ_▷_∈_; nil; var; addr; app; function; block; done; return; local; orUnknown; srcBinOp; tgtBinOp)
open import Luau.Var using (_≡ⱽ_)
open import Luau.Addr using (_≡ᴬ_)
open import Luau.VarCtxt using (VarCtxt; ∅; _⋒_; _↦_; _⊕_↦_; _⊝_; ⊕-lookup-miss; ⊕-swap; ⊕-over) renaming (_[_] to _[_]ⱽ)
open import Luau.VarCtxt using (VarCtxt; ∅)
open import Properties.Remember using (remember; _,_)
open import Properties.Equality using (_≢_; sym; cong; trans; subst₁)
open import Properties.Dec using (Dec; yes; no)
open import Properties.Contradiction using (CONTRADICTION; ¬)
open import Properties.Functions using (_∘_)
open import Properties.Subtyping using (unknown-≮:; ≡-trans-≮:; ≮:-trans-≡; never-tgt-≮:; tgt-never-≮:; src-unknown-≮:; unknown-src-≮:; ≮:-trans; ≮:-refl; scalar-≢-impl-≮:; function-≮:-scalar; scalar-≮:-function; function-≮:-never; unknown-≮:-scalar; scalar-≮:-never; unknown-≮:-never)
open import Properties.TypeCheck using (typeOfᴼ; typeOfᴹᴼ; typeOfⱽ; typeOfᴱ; typeOfᴮ; typeCheckᴱ; typeCheckᴮ; typeCheckᴼ; typeCheckᴴ)
open import Luau.OpSem using (_⟦_⟧_⟶_; _⊢_⟶*_⊣_; _⊢_⟶ᴮ_⊣_; _⊢_⟶ᴱ_⊣_; app₁; app₂; function; beta; return; block; done; local; subst; binOp₀; binOp₁; binOp₂; refl; step; +; -; *; /; <; >; ==; ~=; <=; >=; ··)
open import Luau.RuntimeError using (BinOpError; RuntimeErrorᴱ; RuntimeErrorᴮ; FunctionMismatch; BinOpMismatch₁; BinOpMismatch₂; UnboundVariable; SEGV; app₁; app₂; bin₁; bin₂; block; local; return; +; -; *; /; <; >; <=; >=; ··)
open import Luau.RuntimeType using (RuntimeType; valueType; number; string; boolean; nil; function)
data _⊑_ (H : Heap yes) : Heap yes → Set where
refl : (H ⊑ H)
snoc : ∀ {H′ a O} → (H′ ≡ᴴ H ⊕ a ↦ O) → (H ⊑ H′)
rednᴱ⊑ : ∀ {H H′ M M′} → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → (H ⊑ H′)
rednᴮ⊑ : ∀ {H H′ B B′} → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → (H ⊑ H′)
rednᴱ⊑ (function a p) = snoc p
rednᴱ⊑ (app₁ s) = rednᴱ⊑ s
rednᴱ⊑ (app₂ p s) = rednᴱ⊑ s
rednᴱ⊑ (beta O v p q) = refl
rednᴱ⊑ (block s) = rednᴮ⊑ s
rednᴱ⊑ (return v) = refl
rednᴱ⊑ done = refl
rednᴱ⊑ (binOp₀ p) = refl
rednᴱ⊑ (binOp₁ s) = rednᴱ⊑ s
rednᴱ⊑ (binOp₂ s) = rednᴱ⊑ s
rednᴮ⊑ (local s) = rednᴱ⊑ s
rednᴮ⊑ (subst v) = refl
rednᴮ⊑ (function a p) = snoc p
rednᴮ⊑ (return s) = rednᴱ⊑ s
data LookupResult (H : Heap yes) a V : Set where
just : (H [ a ]ᴴ ≡ just V) → LookupResult H a V
nothing : (H [ a ]ᴴ ≡ nothing) → LookupResult H a V
lookup-⊑-nothing : ∀ {H H′} a → (H ⊑ H′) → (H′ [ a ]ᴴ ≡ nothing) → (H [ a ]ᴴ ≡ nothing)
lookup-⊑-nothing {H} a refl p = p
lookup-⊑-nothing {H} a (snoc defn) p with a ≡ᴬ next H
lookup-⊑-nothing {H} a (snoc defn) p | yes refl = refl
lookup-⊑-nothing {H} a (snoc o) p | no q = trans (lookup-not-allocated o q) p
heap-weakeningᴱ : ∀ Γ H M {H′ U} → (H ⊑ H′) → (typeOfᴱ H′ Γ M ≮: U) → (typeOfᴱ H Γ M ≮: U)
heap-weakeningᴱ Γ H (var x) h p = p
heap-weakeningᴱ Γ H (val nil) h p = p
heap-weakeningᴱ Γ H (val (addr a)) refl p = p
heap-weakeningᴱ Γ H (val (addr a)) (snoc {a = b} q) p with a ≡ᴬ b
heap-weakeningᴱ Γ H (val (addr a)) (snoc {a = a} defn) p | yes refl = unknown-≮: p
heap-weakeningᴱ Γ H (val (addr a)) (snoc {a = b} q) p | no r = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ (lookup-not-allocated q r))) p
heap-weakeningᴱ Γ H (val (number x)) h p = p
heap-weakeningᴱ Γ H (val (bool x)) h p = p
heap-weakeningᴱ Γ H (val (string x)) h p = p
heap-weakeningᴱ Γ H (M $ N) h p = never-tgt-≮: (heap-weakeningᴱ Γ H M h (tgt-never-≮: p))
heap-weakeningᴱ Γ H (function f ⟨ var x ∈ T ⟩∈ U is B end) h p = p
heap-weakeningᴱ Γ H (block var b ∈ T is B end) h p = p
heap-weakeningᴱ Γ H (binexp M op N) h p = p
heap-weakeningᴮ : ∀ Γ H B {H′ U} → (H ⊑ H′) → (typeOfᴮ H′ Γ B ≮: U) → (typeOfᴮ H Γ B ≮: U)
heap-weakeningᴮ Γ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) h p = heap-weakeningᴮ (Γ ⊕ f ↦ (T ⇒ U)) H B h p
heap-weakeningᴮ Γ H (local var x ∈ T ← M ∙ B) h p = heap-weakeningᴮ (Γ ⊕ x ↦ T) H B h p
heap-weakeningᴮ Γ H (return M ∙ B) h p = heap-weakeningᴱ Γ H M h p
heap-weakeningᴮ Γ H done h p = p
substitutivityᴱ : ∀ {Γ T U} H M v x → (typeOfᴱ H Γ (M [ v / x ]ᴱ) ≮: U) → Either (typeOfᴱ H (Γ ⊕ x ↦ T) M ≮: U) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴱ-whenever : ∀ {Γ T U} H v x y (r : Dec(x ≡ y)) → (typeOfᴱ H Γ (var y [ v / x ]ᴱwhenever r) ≮: U) → Either (typeOfᴱ H (Γ ⊕ x ↦ T) (var y) ≮: U) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴮ : ∀ {Γ T U} H B v x → (typeOfᴮ H Γ (B [ v / x ]ᴮ) ≮: U) → Either (typeOfᴮ H (Γ ⊕ x ↦ T) B ≮: U) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴮ-unless : ∀ {Γ T U V} H B v x y (r : Dec(x ≡ y)) → (typeOfᴮ H (Γ ⊕ y ↦ U) (B [ v / x ]ᴮunless r) ≮: V) → Either (typeOfᴮ H ((Γ ⊕ x ↦ T) ⊕ y ↦ U) B ≮: V) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴮ-unless-yes : ∀ {Γ Γ′ T V} H B v x y (r : x ≡ y) → (Γ′ ≡ Γ) → (typeOfᴮ H Γ (B [ v / x ]ᴮunless yes r) ≮: V) → Either (typeOfᴮ H Γ′ B ≮: V) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴮ-unless-no : ∀ {Γ Γ′ T V} H B v x y (r : x ≢ y) → (Γ′ ≡ Γ ⊕ x ↦ T) → (typeOfᴮ H Γ (B [ v / x ]ᴮunless no r) ≮: V) → Either (typeOfᴮ H Γ′ B ≮: V) (typeOfᴱ H ∅ (val v) ≮: T)
substitutivityᴱ H (var y) v x p = substitutivityᴱ-whenever H v x y (x ≡ⱽ y) p
substitutivityᴱ H (val w) v x p = Left p
substitutivityᴱ H (binexp M op N) v x p = Left p
substitutivityᴱ H (M $ N) v x p = mapL never-tgt-≮: (substitutivityᴱ H M v x (tgt-never-≮: p))
substitutivityᴱ H (function f ⟨ var y ∈ T ⟩∈ U is B end) v x p = Left p
substitutivityᴱ H (block var b ∈ T is B end) v x p = Left p
substitutivityᴱ-whenever H v x x (yes refl) q = swapLR (≮:-trans q)
substitutivityᴱ-whenever H v x y (no p) q = Left (≡-trans-≮: (cong orUnknown (sym (⊕-lookup-miss x y _ _ p))) q)
substitutivityᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) v x p = substitutivityᴮ-unless H B v x f (x ≡ⱽ f) p
substitutivityᴮ H (local var y ∈ T ← M ∙ B) v x p = substitutivityᴮ-unless H B v x y (x ≡ⱽ y) p
substitutivityᴮ H (return M ∙ B) v x p = substitutivityᴱ H M v x p
substitutivityᴮ H done v x p = Left p
substitutivityᴮ-unless H B v x y (yes p) q = substitutivityᴮ-unless-yes H B v x y p (⊕-over p) q
substitutivityᴮ-unless H B v x y (no p) q = substitutivityᴮ-unless-no H B v x y p (⊕-swap p) q
substitutivityᴮ-unless-yes H B v x y refl refl p = Left p
substitutivityᴮ-unless-no H B v x y p refl q = substitutivityᴮ H B v x q
binOpPreservation : ∀ H {op v w x} → (v ⟦ op ⟧ w ⟶ x) → (tgtBinOp op ≡ typeOfᴱ H ∅ (val x))
binOpPreservation H (+ m n) = refl
binOpPreservation H (- m n) = refl
binOpPreservation H (/ m n) = refl
binOpPreservation H (* m n) = refl
binOpPreservation H (< m n) = refl
binOpPreservation H (> m n) = refl
binOpPreservation H (<= m n) = refl
binOpPreservation H (>= m n) = refl
binOpPreservation H (== v w) = refl
binOpPreservation H (~= v w) = refl
binOpPreservation H (·· v w) = refl
reflect-subtypingᴱ : ∀ H M {H′ M′ T} → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → (typeOfᴱ H′ ∅ M′ ≮: T) → Either (typeOfᴱ H ∅ M ≮: T) (Warningᴱ H (typeCheckᴱ H ∅ M))
reflect-subtypingᴮ : ∀ H B {H′ B′ T} → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → (typeOfᴮ H′ ∅ B′ ≮: T) → Either (typeOfᴮ H ∅ B ≮: T) (Warningᴮ H (typeCheckᴮ H ∅ B))
reflect-subtypingᴱ H (M $ N) (app₁ s) p = mapLR never-tgt-≮: app₁ (reflect-subtypingᴱ H M s (tgt-never-≮: p))
reflect-subtypingᴱ H (M $ N) (app₂ v s) p = Left (never-tgt-≮: (heap-weakeningᴱ ∅ H M (rednᴱ⊑ s) (tgt-never-≮: p)))
reflect-subtypingᴱ H (M $ N) (beta (function f ⟨ var y ∈ T ⟩∈ U is B end) v refl q) p = Left (≡-trans-≮: (cong tgt (cong orUnknown (cong typeOfᴹᴼ q))) p)
reflect-subtypingᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a defn) p = Left p
reflect-subtypingᴱ H (block var b ∈ T is B end) (block s) p = Left p
reflect-subtypingᴱ H (block var b ∈ T is return (val v) ∙ B end) (return v) p = mapR BlockMismatch (swapLR (≮:-trans p))
reflect-subtypingᴱ H (block var b ∈ T is done end) done p = mapR BlockMismatch (swapLR (≮:-trans p))
reflect-subtypingᴱ H (binexp M op N) (binOp₀ s) p = Left (≡-trans-≮: (binOpPreservation H s) p)
reflect-subtypingᴱ H (binexp M op N) (binOp₁ s) p = Left p
reflect-subtypingᴱ H (binexp M op N) (binOp₂ s) p = Left p
reflect-subtypingᴮ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function a defn) p = mapLR (heap-weakeningᴮ _ _ B (snoc defn)) (CONTRADICTION ∘ ≮:-refl) (substitutivityᴮ _ B (addr a) f p)
reflect-subtypingᴮ H (local var x ∈ T ← M ∙ B) (local s) p = Left (heap-weakeningᴮ (x ↦ T) H B (rednᴱ⊑ s) p)
reflect-subtypingᴮ H (local var x ∈ T ← M ∙ B) (subst v) p = mapR LocalVarMismatch (substitutivityᴮ H B v x p)
reflect-subtypingᴮ H (return M ∙ B) (return s) p = mapR return (reflect-subtypingᴱ H M s p)
reflect-substitutionᴱ : ∀ {Γ T} H M v x → Warningᴱ H (typeCheckᴱ H Γ (M [ v / x ]ᴱ)) → Either (Warningᴱ H (typeCheckᴱ H (Γ ⊕ x ↦ T) M)) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴱ-whenever : ∀ {Γ T} H v x y (p : Dec(x ≡ y)) → Warningᴱ H (typeCheckᴱ H Γ (var y [ v / x ]ᴱwhenever p)) → Either (Warningᴱ H (typeCheckᴱ H (Γ ⊕ x ↦ T) (var y))) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴮ : ∀ {Γ T} H B v x → Warningᴮ H (typeCheckᴮ H Γ (B [ v / x ]ᴮ)) → Either (Warningᴮ H (typeCheckᴮ H (Γ ⊕ x ↦ T) B)) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴮ-unless : ∀ {Γ T U} H B v x y (r : Dec(x ≡ y)) → Warningᴮ H (typeCheckᴮ H (Γ ⊕ y ↦ U) (B [ v / x ]ᴮunless r)) → Either (Warningᴮ H (typeCheckᴮ H ((Γ ⊕ x ↦ T) ⊕ y ↦ U) B)) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴮ-unless-yes : ∀ {Γ Γ′ T} H B v x y (r : x ≡ y) → (Γ′ ≡ Γ) → Warningᴮ H (typeCheckᴮ H Γ (B [ v / x ]ᴮunless yes r)) → Either (Warningᴮ H (typeCheckᴮ H Γ′ B)) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴮ-unless-no : ∀ {Γ Γ′ T} H B v x y (r : x ≢ y) → (Γ′ ≡ Γ ⊕ x ↦ T) → Warningᴮ H (typeCheckᴮ H Γ (B [ v / x ]ᴮunless no r)) → Either (Warningᴮ H (typeCheckᴮ H Γ′ B)) (Either (Warningᴱ H (typeCheckᴱ H ∅ (val v))) (typeOfᴱ H ∅ (val v) ≮: T))
reflect-substitutionᴱ H (var y) v x W = reflect-substitutionᴱ-whenever H v x y (x ≡ⱽ y) W
reflect-substitutionᴱ H (val (addr a)) v x (UnallocatedAddress r) = Left (UnallocatedAddress r)
reflect-substitutionᴱ H (M $ N) v x (FunctionCallMismatch p) with substitutivityᴱ H N v x p
reflect-substitutionᴱ H (M $ N) v x (FunctionCallMismatch p) | Right W = Right (Right W)
reflect-substitutionᴱ H (M $ N) v x (FunctionCallMismatch p) | Left q with substitutivityᴱ H M v x (src-unknown-≮: q)
reflect-substitutionᴱ H (M $ N) v x (FunctionCallMismatch p) | Left q | Left r = Left ((FunctionCallMismatch ∘ unknown-src-≮: q) r)
reflect-substitutionᴱ H (M $ N) v x (FunctionCallMismatch p) | Left q | Right W = Right (Right W)
reflect-substitutionᴱ H (M $ N) v x (app₁ W) = mapL app₁ (reflect-substitutionᴱ H M v x W)
reflect-substitutionᴱ H (M $ N) v x (app₂ W) = mapL app₂ (reflect-substitutionᴱ H N v x W)
reflect-substitutionᴱ H (function f ⟨ var y ∈ T ⟩∈ U is B end) v x (FunctionDefnMismatch q) = mapLR FunctionDefnMismatch Right (substitutivityᴮ-unless H B v x y (x ≡ⱽ y) q)
reflect-substitutionᴱ H (function f ⟨ var y ∈ T ⟩∈ U is B end) v x (function₁ W) = mapL function₁ (reflect-substitutionᴮ-unless H B v x y (x ≡ⱽ y) W)
reflect-substitutionᴱ H (block var b ∈ T is B end) v x (BlockMismatch q) = mapLR BlockMismatch Right (substitutivityᴮ H B v x q)
reflect-substitutionᴱ H (block var b ∈ T is B end) v x (block₁ W′) = mapL block₁ (reflect-substitutionᴮ H B v x W′)
reflect-substitutionᴱ H (binexp M op N) v x (BinOpMismatch₁ q) = mapLR BinOpMismatch₁ Right (substitutivityᴱ H M v x q)
reflect-substitutionᴱ H (binexp M op N) v x (BinOpMismatch₂ q) = mapLR BinOpMismatch₂ Right (substitutivityᴱ H N v x q)
reflect-substitutionᴱ H (binexp M op N) v x (bin₁ W) = mapL bin₁ (reflect-substitutionᴱ H M v x W)
reflect-substitutionᴱ H (binexp M op N) v x (bin₂ W) = mapL bin₂ (reflect-substitutionᴱ H N v x W)
reflect-substitutionᴱ-whenever H a x x (yes refl) (UnallocatedAddress p) = Right (Left (UnallocatedAddress p))
reflect-substitutionᴱ-whenever H v x y (no p) (UnboundVariable q) = Left (UnboundVariable (trans (sym (⊕-lookup-miss x y _ _ p)) q))
reflect-substitutionᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) v x (FunctionDefnMismatch q) = mapLR FunctionDefnMismatch Right (substitutivityᴮ-unless H C v x y (x ≡ⱽ y) q)
reflect-substitutionᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) v x (function₁ W) = mapL function₁ (reflect-substitutionᴮ-unless H C v x y (x ≡ⱽ y) W)
reflect-substitutionᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) v x (function₂ W) = mapL function₂ (reflect-substitutionᴮ-unless H B v x f (x ≡ⱽ f) W)
reflect-substitutionᴮ H (local var y ∈ T ← M ∙ B) v x (LocalVarMismatch q) = mapLR LocalVarMismatch Right (substitutivityᴱ H M v x q)
reflect-substitutionᴮ H (local var y ∈ T ← M ∙ B) v x (local₁ W) = mapL local₁ (reflect-substitutionᴱ H M v x W)
reflect-substitutionᴮ H (local var y ∈ T ← M ∙ B) v x (local₂ W) = mapL local₂ (reflect-substitutionᴮ-unless H B v x y (x ≡ⱽ y) W)
reflect-substitutionᴮ H (return M ∙ B) v x (return W) = mapL return (reflect-substitutionᴱ H M v x W)
reflect-substitutionᴮ-unless H B v x y (yes p) W = reflect-substitutionᴮ-unless-yes H B v x y p (⊕-over p) W
reflect-substitutionᴮ-unless H B v x y (no p) W = reflect-substitutionᴮ-unless-no H B v x y p (⊕-swap p) W
reflect-substitutionᴮ-unless-yes H B v x x refl refl W = Left W
reflect-substitutionᴮ-unless-no H B v x y p refl W = reflect-substitutionᴮ H B v x W
reflect-weakeningᴱ : ∀ Γ H M {H′} → (H ⊑ H′) → Warningᴱ H′ (typeCheckᴱ H′ Γ M) → Warningᴱ H (typeCheckᴱ H Γ M)
reflect-weakeningᴮ : ∀ Γ H B {H′} → (H ⊑ H′) → Warningᴮ H′ (typeCheckᴮ H′ Γ B) → Warningᴮ H (typeCheckᴮ H Γ B)
reflect-weakeningᴱ Γ H (var x) h (UnboundVariable p) = (UnboundVariable p)
reflect-weakeningᴱ Γ H (val (addr a)) h (UnallocatedAddress p) = UnallocatedAddress (lookup-⊑-nothing a h p)
reflect-weakeningᴱ Γ H (M $ N) h (FunctionCallMismatch p) = FunctionCallMismatch (heap-weakeningᴱ Γ H N h (unknown-src-≮: p (heap-weakeningᴱ Γ H M h (src-unknown-≮: p))))
reflect-weakeningᴱ Γ H (M $ N) h (app₁ W) = app₁ (reflect-weakeningᴱ Γ H M h W)
reflect-weakeningᴱ Γ H (M $ N) h (app₂ W) = app₂ (reflect-weakeningᴱ Γ H N h W)
reflect-weakeningᴱ Γ H (binexp M op N) h (BinOpMismatch₁ p) = BinOpMismatch₁ (heap-weakeningᴱ Γ H M h p)
reflect-weakeningᴱ Γ H (binexp M op N) h (BinOpMismatch₂ p) = BinOpMismatch₂ (heap-weakeningᴱ Γ H N h p)
reflect-weakeningᴱ Γ H (binexp M op N) h (bin₁ W′) = bin₁ (reflect-weakeningᴱ Γ H M h W′)
reflect-weakeningᴱ Γ H (binexp M op N) h (bin₂ W′) = bin₂ (reflect-weakeningᴱ Γ H N h W′)
reflect-weakeningᴱ Γ H (function f ⟨ var y ∈ T ⟩∈ U is B end) h (FunctionDefnMismatch p) = FunctionDefnMismatch (heap-weakeningᴮ (Γ ⊕ y ↦ T) H B h p)
reflect-weakeningᴱ Γ H (function f ⟨ var y ∈ T ⟩∈ U is B end) h (function₁ W) = function₁ (reflect-weakeningᴮ (Γ ⊕ y ↦ T) H B h W)
reflect-weakeningᴱ Γ H (block var b ∈ T is B end) h (BlockMismatch p) = BlockMismatch (heap-weakeningᴮ Γ H B h p)
reflect-weakeningᴱ Γ H (block var b ∈ T is B end) h (block₁ W) = block₁ (reflect-weakeningᴮ Γ H B h W)
reflect-weakeningᴮ Γ H (return M ∙ B) h (return W) = return (reflect-weakeningᴱ Γ H M h W)
reflect-weakeningᴮ Γ H (local var y ∈ T ← M ∙ B) h (LocalVarMismatch p) = LocalVarMismatch (heap-weakeningᴱ Γ H M h p)
reflect-weakeningᴮ Γ H (local var y ∈ T ← M ∙ B) h (local₁ W) = local₁ (reflect-weakeningᴱ Γ H M h W)
reflect-weakeningᴮ Γ H (local var y ∈ T ← M ∙ B) h (local₂ W) = local₂ (reflect-weakeningᴮ (Γ ⊕ y ↦ T) H B h W)
reflect-weakeningᴮ Γ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) h (FunctionDefnMismatch p) = FunctionDefnMismatch (heap-weakeningᴮ (Γ ⊕ x ↦ T) H C h p)
reflect-weakeningᴮ Γ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) h (function₁ W) = function₁ (reflect-weakeningᴮ (Γ ⊕ x ↦ T) H C h W)
reflect-weakeningᴮ Γ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) h (function₂ W) = function₂ (reflect-weakeningᴮ (Γ ⊕ f ↦ (T ⇒ U)) H B h W)
reflect-weakeningᴼ : ∀ H O {H′} → (H ⊑ H′) → Warningᴼ H′ (typeCheckᴼ H′ O) → Warningᴼ H (typeCheckᴼ H O)
reflect-weakeningᴼ H (just function f ⟨ var x ∈ T ⟩∈ U is B end) h (FunctionDefnMismatch p) = FunctionDefnMismatch (heap-weakeningᴮ (x ↦ T) H B h p)
reflect-weakeningᴼ H (just function f ⟨ var x ∈ T ⟩∈ U is B end) h (function₁ W) = function₁ (reflect-weakeningᴮ (x ↦ T) H B h W)
reflectᴱ : ∀ H M {H′ M′} → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → Warningᴱ H′ (typeCheckᴱ H′ ∅ M′) → Either (Warningᴱ H (typeCheckᴱ H ∅ M)) (Warningᴴ H (typeCheckᴴ H))
reflectᴮ : ∀ H B {H′ B′} → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → Warningᴮ H′ (typeCheckᴮ H′ ∅ B′) → Either (Warningᴮ H (typeCheckᴮ H ∅ B)) (Warningᴴ H (typeCheckᴴ H))
reflectᴱ H (M $ N) (app₁ s) (FunctionCallMismatch p) = cond (Left ∘ FunctionCallMismatch ∘ heap-weakeningᴱ ∅ H N (rednᴱ⊑ s) ∘ unknown-src-≮: p) (Left ∘ app₁) (reflect-subtypingᴱ H M s (src-unknown-≮: p))
reflectᴱ H (M $ N) (app₁ s) (app₁ W′) = mapL app₁ (reflectᴱ H M s W′)
reflectᴱ H (M $ N) (app₁ s) (app₂ W′) = Left (app₂ (reflect-weakeningᴱ ∅ H N (rednᴱ⊑ s) W′))
reflectᴱ H (M $ N) (app₂ p s) (FunctionCallMismatch q) = cond (λ r → Left (FunctionCallMismatch (unknown-src-≮: r (heap-weakeningᴱ ∅ H M (rednᴱ⊑ s) (src-unknown-≮: r))))) (Left ∘ app₂) (reflect-subtypingᴱ H N s q)
reflectᴱ H (M $ N) (app₂ p s) (app₁ W′) = Left (app₁ (reflect-weakeningᴱ ∅ H M (rednᴱ⊑ s) W′))
reflectᴱ H (M $ N) (app₂ p s) (app₂ W′) = mapL app₂ (reflectᴱ H N s W′)
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (BlockMismatch q) with substitutivityᴮ H B v x q
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (BlockMismatch q) | Left r = Right (addr a p (FunctionDefnMismatch r))
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (BlockMismatch q) | Right r = Left (FunctionCallMismatch (≮:-trans-≡ r ((cong src (cong orUnknown (cong typeOfᴹᴼ (sym p)))))))
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (block₁ W′) with reflect-substitutionᴮ _ B v x W′
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (block₁ W′) | Left W = Right (addr a p (function₁ W))
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (block₁ W′) | Right (Left W) = Left (app₂ W)
reflectᴱ H (val (addr a) $ N) (beta (function f ⟨ var x ∈ T ⟩∈ U is B end) v refl p) (block₁ W′) | Right (Right q) = Left (FunctionCallMismatch (≮:-trans-≡ q (cong src (cong orUnknown (cong typeOfᴹᴼ (sym p))))))
reflectᴱ H (block var b ∈ T is B end) (block s) (BlockMismatch p) = Left (cond BlockMismatch block₁ (reflect-subtypingᴮ H B s p))
reflectᴱ H (block var b ∈ T is B end) (block s) (block₁ W′) = mapL block₁ (reflectᴮ H B s W′)
reflectᴱ H (block var b ∈ T is B end) (return v) W′ = Left (block₁ (return W′))
reflectᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a defn) (UnallocatedAddress ())
reflectᴱ H (binexp M op N) (binOp₀ ()) (UnallocatedAddress p)
reflectᴱ H (binexp M op N) (binOp₁ s) (BinOpMismatch₁ p) = Left (cond BinOpMismatch₁ bin₁ (reflect-subtypingᴱ H M s p))
reflectᴱ H (binexp M op N) (binOp₁ s) (BinOpMismatch₂ p) = Left (BinOpMismatch₂ (heap-weakeningᴱ ∅ H N (rednᴱ⊑ s) p))
reflectᴱ H (binexp M op N) (binOp₁ s) (bin₁ W′) = mapL bin₁ (reflectᴱ H M s W′)
reflectᴱ H (binexp M op N) (binOp₁ s) (bin₂ W′) = Left (bin₂ (reflect-weakeningᴱ ∅ H N (rednᴱ⊑ s) W′))
reflectᴱ H (binexp M op N) (binOp₂ s) (BinOpMismatch₁ p) = Left (BinOpMismatch₁ (heap-weakeningᴱ ∅ H M (rednᴱ⊑ s) p))
reflectᴱ H (binexp M op N) (binOp₂ s) (BinOpMismatch₂ p) = Left (cond BinOpMismatch₂ bin₂ (reflect-subtypingᴱ H N s p))
reflectᴱ H (binexp M op N) (binOp₂ s) (bin₁ W′) = Left (bin₁ (reflect-weakeningᴱ ∅ H M (rednᴱ⊑ s) W′))
reflectᴱ H (binexp M op N) (binOp₂ s) (bin₂ W′) = mapL bin₂ (reflectᴱ H N s W′)
reflectᴮ H (local var x ∈ T ← M ∙ B) (local s) (LocalVarMismatch p) = Left (cond LocalVarMismatch local₁ (reflect-subtypingᴱ H M s p))
reflectᴮ H (local var x ∈ T ← M ∙ B) (local s) (local₁ W′) = mapL local₁ (reflectᴱ H M s W′)
reflectᴮ H (local var x ∈ T ← M ∙ B) (local s) (local₂ W′) = Left (local₂ (reflect-weakeningᴮ (x ↦ T) H B (rednᴱ⊑ s) W′))
reflectᴮ H (local var x ∈ T ← M ∙ B) (subst v) W′ = Left (cond local₂ (cond local₁ LocalVarMismatch) (reflect-substitutionᴮ H B v x W′))
reflectᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) (function a defn) W′ with reflect-substitutionᴮ _ B (addr a) f W′
reflectᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) (function a defn) W′ | Left W = Left (function₂ (reflect-weakeningᴮ (f ↦ (T ⇒ U)) H B (snoc defn) W))
reflectᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) (function a defn) W′ | Right (Left (UnallocatedAddress ()))
reflectᴮ H (function f ⟨ var y ∈ T ⟩∈ U is C end ∙ B) (function a defn) W′ | Right (Right p) = CONTRADICTION (≮:-refl p)
reflectᴮ H (return M ∙ B) (return s) (return W′) = mapL return (reflectᴱ H M s W′)
reflectᴴᴱ : ∀ H M {H′ M′} → (H ⊢ M ⟶ᴱ M′ ⊣ H′) → Warningᴴ H′ (typeCheckᴴ H′) → Either (Warningᴱ H (typeCheckᴱ H ∅ M)) (Warningᴴ H (typeCheckᴴ H))
reflectᴴᴮ : ∀ H B {H′ B′} → (H ⊢ B ⟶ᴮ B′ ⊣ H′) → Warningᴴ H′ (typeCheckᴴ H′) → Either (Warningᴮ H (typeCheckᴮ H ∅ B)) (Warningᴴ H (typeCheckᴴ H))
reflectᴴᴱ H (M $ N) (app₁ s) W = mapL app₁ (reflectᴴᴱ H M s W)
reflectᴴᴱ H (M $ N) (app₂ v s) W = mapL app₂ (reflectᴴᴱ H N s W)
reflectᴴᴱ H (M $ N) (beta O v refl p) W = Right W
reflectᴴᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a p) (addr b refl W) with b ≡ᴬ a
reflectᴴᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a defn) (addr b refl (FunctionDefnMismatch p)) | yes refl = Left (FunctionDefnMismatch (heap-weakeningᴮ (x ↦ T) H B (snoc defn) p))
reflectᴴᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a defn) (addr b refl (function₁ W)) | yes refl = Left (function₁ (reflect-weakeningᴮ (x ↦ T) H B (snoc defn) W))
reflectᴴᴱ H (function f ⟨ var x ∈ T ⟩∈ U is B end) (function a p) (addr b refl W) | no q = Right (addr b (lookup-not-allocated p q) (reflect-weakeningᴼ H _ (snoc p) W))
reflectᴴᴱ H (block var b ∈ T is B end) (block s) W = mapL block₁ (reflectᴴᴮ H B s W)
reflectᴴᴱ H (block var b ∈ T is return (val v) ∙ B end) (return v) W = Right W
reflectᴴᴱ H (block var b ∈ T is done end) done W = Right W
reflectᴴᴱ H (binexp M op N) (binOp₀ s) W = Right W
reflectᴴᴱ H (binexp M op N) (binOp₁ s) W = mapL bin₁ (reflectᴴᴱ H M s W)
reflectᴴᴱ H (binexp M op N) (binOp₂ s) W = mapL bin₂ (reflectᴴᴱ H N s W)
reflectᴴᴮ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function a p) (addr b refl W) with b ≡ᴬ a
reflectᴴᴮ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function a defn) (addr b refl (FunctionDefnMismatch p)) | yes refl = Left (FunctionDefnMismatch (heap-weakeningᴮ (x ↦ T) H C (snoc defn) p))
reflectᴴᴮ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function a defn) (addr b refl (function₁ W)) | yes refl = Left (function₁ (reflect-weakeningᴮ (x ↦ T) H C (snoc defn) W))
reflectᴴᴮ H (function f ⟨ var x ∈ T ⟩∈ U is C end ∙ B) (function a p) (addr b refl W) | no q = Right (addr b (lookup-not-allocated p q) (reflect-weakeningᴼ H _ (snoc p) W))
reflectᴴᴮ H (local var x ∈ T ← M ∙ B) (local s) W = mapL local₁ (reflectᴴᴱ H M s W)
reflectᴴᴮ H (local var x ∈ T ← M ∙ B) (subst v) W = Right W
reflectᴴᴮ H (return M ∙ B) (return s) W = mapL return (reflectᴴᴱ H M s W)
reflect* : ∀ H B {H′ B′} → (H ⊢ B ⟶* B′ ⊣ H′) → Either (Warningᴮ H′ (typeCheckᴮ H′ ∅ B′)) (Warningᴴ H′ (typeCheckᴴ H′)) → Either (Warningᴮ H (typeCheckᴮ H ∅ B)) (Warningᴴ H (typeCheckᴴ H))
reflect* H B refl W = W
reflect* H B (step s t) W = cond (reflectᴮ H B s) (reflectᴴᴮ H B s) (reflect* _ _ t W)
isntNumber : ∀ H v → (valueType v ≢ number) → (typeOfᴱ H ∅ (val v) ≮: number)
isntNumber H nil p = scalar-≢-impl-≮: nil number (λ ())
isntNumber H (addr a) p with remember (H [ a ]ᴴ)
isntNumber H (addr a) p | (just (function f ⟨ var x ∈ T ⟩∈ U is B end) , q) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ q)) (function-≮:-scalar number)
isntNumber H (addr a) p | (nothing , q) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ q)) (unknown-≮:-scalar number)
isntNumber H (number x) p = CONTRADICTION (p refl)
isntNumber H (bool x) p = scalar-≢-impl-≮: boolean number (λ ())
isntNumber H (string x) p = scalar-≢-impl-≮: string number (λ ())
isntString : ∀ H v → (valueType v ≢ string) → (typeOfᴱ H ∅ (val v) ≮: string)
isntString H nil p = scalar-≢-impl-≮: nil string (λ ())
isntString H (addr a) p with remember (H [ a ]ᴴ)
isntString H (addr a) p | (just (function f ⟨ var x ∈ T ⟩∈ U is B end) , q) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ q)) (function-≮:-scalar string)
isntString H (addr a) p | (nothing , q) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ q)) (unknown-≮:-scalar string)
isntString H (number x) p = scalar-≢-impl-≮: number string (λ ())
isntString H (bool x) p = scalar-≢-impl-≮: boolean string (λ ())
isntString H (string x) p = CONTRADICTION (p refl)
isntFunction : ∀ H v {T U} → (valueType v ≢ function) → (typeOfᴱ H ∅ (val v) ≮: (T ⇒ U))
isntFunction H nil p = scalar-≮:-function nil
isntFunction H (addr a) p = CONTRADICTION (p refl)
isntFunction H (number x) p = scalar-≮:-function number
isntFunction H (bool x) p = scalar-≮:-function boolean
isntFunction H (string x) p = scalar-≮:-function string
isntEmpty : ∀ H v → (typeOfᴱ H ∅ (val v) ≮: never)
isntEmpty H nil = scalar-≮:-never nil
isntEmpty H (addr a) with remember (H [ a ]ᴴ)
isntEmpty H (addr a) | (just (function f ⟨ var x ∈ T ⟩∈ U is B end) , p) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ p)) function-≮:-never
isntEmpty H (addr a) | (nothing , p) = ≡-trans-≮: (cong orUnknown (cong typeOfᴹᴼ p)) unknown-≮:-never
isntEmpty H (number x) = scalar-≮:-never number
isntEmpty H (bool x) = scalar-≮:-never boolean
isntEmpty H (string x) = scalar-≮:-never string
runtimeBinOpWarning : ∀ H {op} v → BinOpError op (valueType v) → (typeOfᴱ H ∅ (val v) ≮: srcBinOp op)
runtimeBinOpWarning H v (+ p) = isntNumber H v p
runtimeBinOpWarning H v (- p) = isntNumber H v p
runtimeBinOpWarning H v (* p) = isntNumber H v p
runtimeBinOpWarning H v (/ p) = isntNumber H v p
runtimeBinOpWarning H v (< p) = isntNumber H v p
runtimeBinOpWarning H v (> p) = isntNumber H v p
runtimeBinOpWarning H v (<= p) = isntNumber H v p
runtimeBinOpWarning H v (>= p) = isntNumber H v p
runtimeBinOpWarning H v (·· p) = isntString H v p
runtimeWarningᴱ : ∀ H M → RuntimeErrorᴱ H M → Warningᴱ H (typeCheckᴱ H ∅ M)
runtimeWarningᴮ : ∀ H B → RuntimeErrorᴮ H B → Warningᴮ H (typeCheckᴮ H ∅ B)
runtimeWarningᴱ H (var x) UnboundVariable = UnboundVariable refl
runtimeWarningᴱ H (val (addr a)) (SEGV p) = UnallocatedAddress p
runtimeWarningᴱ H (M $ N) (FunctionMismatch v w p) = FunctionCallMismatch (unknown-src-≮: (isntEmpty H w) (isntFunction H v p))
runtimeWarningᴱ H (M $ N) (app₁ err) = app₁ (runtimeWarningᴱ H M err)
runtimeWarningᴱ H (M $ N) (app₂ err) = app₂ (runtimeWarningᴱ H N err)
runtimeWarningᴱ H (block var b ∈ T is B end) (block err) = block₁ (runtimeWarningᴮ H B err)
runtimeWarningᴱ H (binexp M op N) (BinOpMismatch₁ v w p) = BinOpMismatch₁ (runtimeBinOpWarning H v p)
runtimeWarningᴱ H (binexp M op N) (BinOpMismatch₂ v w p) = BinOpMismatch₂ (runtimeBinOpWarning H w p)
runtimeWarningᴱ H (binexp M op N) (bin₁ err) = bin₁ (runtimeWarningᴱ H M err)
runtimeWarningᴱ H (binexp M op N) (bin₂ err) = bin₂ (runtimeWarningᴱ H N err)
runtimeWarningᴮ H (local var x ∈ T ← M ∙ B) (local err) = local₁ (runtimeWarningᴱ H M err)
runtimeWarningᴮ H (return M ∙ B) (return err) = return (runtimeWarningᴱ H M err)
wellTypedProgramsDontGoWrong : ∀ H′ B B′ → (∅ᴴ ⊢ B ⟶* B′ ⊣ H′) → (RuntimeErrorᴮ H′ B′) → Warningᴮ ∅ᴴ (typeCheckᴮ ∅ᴴ ∅ B)
wellTypedProgramsDontGoWrong H′ B B′ t err with reflect* ∅ᴴ B t (Left (runtimeWarningᴮ H′ B′ err))
wellTypedProgramsDontGoWrong H′ B B′ t err | Right (addr a refl ())
wellTypedProgramsDontGoWrong H′ B B′ t err | Left W = W
| {
"alphanum_fraction": 0.6530206405,
"avg_line_length": 84.0518731988,
"ext": "agda",
"hexsha": "fd2cf2f2f8e017fdd4a7db289691b45b1e18e363",
"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": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MeltzDev/luau",
"max_forks_repo_path": "prototyping/Properties/StrictMode.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"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": "MeltzDev/luau",
"max_issues_repo_path": "prototyping/Properties/StrictMode.agda",
"max_line_length": 323,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5bb9f379b07e378db0a170e7c4030e3a943b2f14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MeltzDev/luau",
"max_stars_repo_path": "prototyping/Properties/StrictMode.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 12751,
"size": 29166
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the heterogeneous suffix relation
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Suffix.Heterogeneous where
open import Level
open import Relation.Binary using (REL; _⇒_)
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Binary.Pointwise as Pointwise
using (Pointwise; []; _∷_)
module _ {a b r} {A : Set a} {B : Set b} (R : REL A B r) where
data Suffix : REL (List A) (List B) (a ⊔ b ⊔ r) where
here : ∀ {as bs} → Pointwise R as bs → Suffix as bs
there : ∀ {b as bs} → Suffix as bs → Suffix as (b ∷ bs)
data SuffixView (as : List A) : List B → Set (a ⊔ b ⊔ r) where
_++_ : ∀ cs {ds} → Pointwise R as ds → SuffixView as (cs List.++ ds)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
tail : ∀ {a as bs} → Suffix R (a ∷ as) bs → Suffix R as bs
tail (here (_ ∷ rs)) = there (here rs)
tail (there x) = there (tail x)
module _ {a b r s} {A : Set a} {B : Set b} {R : REL A B r} {S : REL A B s} where
map : R ⇒ S → Suffix R ⇒ Suffix S
map R⇒S (here rs) = here (Pointwise.map R⇒S rs)
map R⇒S (there suf) = there (map R⇒S suf)
module _ {a b r} {A : Set a} {B : Set b} {R : REL A B r} where
toView : ∀ {as bs} → Suffix R as bs → SuffixView R as bs
toView (here rs) = [] ++ rs
toView (there {c} suf) with toView suf
... | cs ++ rs = (c ∷ cs) ++ rs
fromView : ∀ {as bs} → SuffixView R as bs → Suffix R as bs
fromView ([] ++ rs) = here rs
fromView ((c ∷ cs) ++ rs) = there (fromView (cs ++ rs))
| {
"alphanum_fraction": 0.5375722543,
"avg_line_length": 36.0416666667,
"ext": "agda",
"hexsha": "4e8fc920b271e7aa581d36c35bdc387b50fbac9d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.agda",
"max_line_length": 80,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Suffix/Heterogeneous.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": 591,
"size": 1730
} |
module PredicateName where
open import OscarPrelude
record PredicateName : Set
where
constructor ⟨_⟩
field
name : Nat
open PredicateName public
instance EqPredicateName : Eq PredicateName
Eq._==_ EqPredicateName _ = decEq₁ (cong name) ∘ (_≟_ on name $ _)
| {
"alphanum_fraction": 0.7472118959,
"avg_line_length": 16.8125,
"ext": "agda",
"hexsha": "4a213ae0825e64637c78b95b88109a1bfb08ea1f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/PredicateName.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/PredicateName.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/PredicateName.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 76,
"size": 269
} |
{-# OPTIONS --copatterns --sized-types #-}
open import Size
open import Function
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P
open ≡-Reasoning
open import Algebra.Structures using (IsCommutativeSemiring; IsCommutativeMonoid)
open import Data.Nat
open import Data.Nat.Properties using (isCommutativeSemiring)
open import Stream
open ∼ˢ∞-Reasoning
⟦_⟧ : ℕ → Str ℕ
hd (⟦ n ⟧) = n
tl (⟦ n ⟧) = ⟦ 0 ⟧
_⊕_ : ∀{i} → Str {i} ℕ → Str {i} ℕ → Str {i} ℕ
hd (s ⊕ t) = (hd s) + (hd t)
tl (s ⊕ t) = (tl s) ⊕ (tl t)
_×_ : ∀{i} → Str {i} ℕ → Str {i} ℕ → Str {i} ℕ
hd (s × t) = hd s * hd t
tl (s × t)= ((tl s) × t) ⊕ (⟦ hd s ⟧ × (tl t))
comm-* : ∀ m n → m * n ≡ n * m
comm-* = IsCommutativeMonoid.comm
(IsCommutativeSemiring.*-isCommutativeMonoid isCommutativeSemiring)
comm-+ : ∀ m n → m + n ≡ n + m
comm-+ = IsCommutativeMonoid.comm
(IsCommutativeSemiring.+-isCommutativeMonoid isCommutativeSemiring)
Bisim = _∼ˢ_
{-
mutual
comm-× : ∀{i} →
(s t : Str {i} ℕ) → Bisim {ℕ} {i} (s × t) (t × s)
hd≡ (comm-× s t) = comm-* (hd s) (hd t)
tl∼ (comm-× s t) = lem-comm-× s t
lem-comm-× : ∀{i} → ∀{j : Size< i} →
(s t : Str {i} ℕ) →
Bisim {ℕ} {j}
((tl s × t) ⊕ (⟦ hd s ⟧ × tl t))
((tl t × s) ⊕ (⟦ hd t ⟧ × tl s))
hd≡ (lem-comm-× {i} {j} s t) =
begin
hd s' * hd t + hd s * hd t'
≡⟨ comm-+ (hd s' * hd t) (hd s * hd t') ⟩
hd s * hd t' + hd s' * hd t
≡⟨ cong (λ x → x + hd s' * hd t) (comm-* (hd s) (hd t')) ⟩
hd t' * hd s + hd s' * hd t
≡⟨ cong (λ x → hd t' * hd s + x) (comm-* (hd s') (hd t)) ⟩
hd t' * hd s + hd t * hd s'
∎
where
s' = tl s {j}
t' = tl t {j}
tl∼ (lem-comm-× {i} {j} s t) {k} = lem {k}
where
s' = tl s {j}
t' = tl t {j}
lem : ∀{k : Size< j} → Bisim {ℕ} {k}
(((tl s' × t) ⊕ (⟦ hd s' ⟧ × t')) ⊕ ((⟦ 0 ⟧ × t') ⊕ (⟦ hd s ⟧ × tl t')))
(((tl t' × s) ⊕ (⟦ hd t' ⟧ × s')) ⊕ ((⟦ 0 ⟧ × s') ⊕ (⟦ hd t ⟧ × tl s')))
lem = {!!}
where
s'' = tl s' {k}
t'' = tl t' {k}
-}
zero-⊕-unit-l : (s : Str ℕ) → (⟦ 0 ⟧ ⊕ s) ∼ˢ∞ s
hd≡∞ (zero-⊕-unit-l s) = refl
tl∼∞ (zero-⊕-unit-l s) = zero-⊕-unit-l (tl s)
zero-⊕-unit-r : (s : Str ℕ) → (s ⊕ ⟦ 0 ⟧) ∼ˢ∞ s
hd≡∞ (zero-⊕-unit-r s) = comm-+ (hd s) 0
tl∼∞ (zero-⊕-unit-r s) = zero-⊕-unit-r (tl s)
zero-×-annihil-l : (s : Str ℕ) → (⟦ 0 ⟧ × s) ∼ˢ∞ ⟦ 0 ⟧
hd≡∞ (zero-×-annihil-l s) = refl
tl∼∞ (zero-×-annihil-l s) =
beginˢ∞
tl (⟦ 0 ⟧ × s)
∼ˢ∞⟨ s-bisim∞-refl ⟩
(⟦ 0 ⟧ × s) ⊕ (⟦ 0 ⟧ × tl s)
∼ˢ∞⟨ {!!} ⟩
tl (⟦ 0 ⟧)
∎ˢ∞
mutual
comm-× : (s t : Str ℕ) → (s × t) ∼ˢ∞ (t × s)
hd≡∞ (comm-× s t) = comm-* (hd s) (hd t)
tl∼∞ (comm-× s t) = lem-comm-× s t
lem-comm-× : (s t : Str ℕ) →
((tl s × t) ⊕ (⟦ hd s ⟧ × tl t))
∼ˢ∞ ((tl t × s) ⊕ (⟦ hd t ⟧ × tl s))
hd≡∞ (lem-comm-× s t) =
begin
hd s' * hd t + hd s * hd t'
≡⟨ comm-+ (hd s' * hd t) (hd s * hd t') ⟩
hd s * hd t' + hd s' * hd t
≡⟨ cong (λ x → x + hd s' * hd t) (comm-* (hd s) (hd t')) ⟩
hd t' * hd s + hd s' * hd t
≡⟨ cong (λ x → hd t' * hd s + x) (comm-* (hd s') (hd t)) ⟩
hd t' * hd s + hd t * hd s'
∎
where
s' = tl s
t' = tl t
tl∼∞ (lem-comm-× s t) = lem
where
s' = tl s
t' = tl t
lem :
(((tl s' × t) ⊕ (⟦ hd s' ⟧ × t')) ⊕ ((⟦ 0 ⟧ × t') ⊕ (⟦ hd s ⟧ × tl t')))
∼ˢ∞ (((tl t' × s) ⊕ (⟦ hd t' ⟧ × s')) ⊕ ((⟦ 0 ⟧ × s') ⊕ (⟦ hd t ⟧ × tl s')))
lem = {!!}
where
s'' = tl s'
t'' = tl t'
| {
"alphanum_fraction": 0.4102351314,
"avg_line_length": 27.5954198473,
"ext": "agda",
"hexsha": "59b44d99837bdbe86131fac7298e6c56609323f8",
"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": "Languages/SDE.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": "Languages/SDE.agda",
"max_line_length": 84,
"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": "Languages/SDE.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1765,
"size": 3615
} |
module _ where
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
variable
A : Set
super-tac : Term → TC ⊤
super-tac hole = unify hole (lit (nat 101))
solver : Nat → Term → TC ⊤
solver n hole = unify hole (lit (nat (n + 1)))
foo : {@(tactic super-tac) n : Nat}
{@(tactic solver n) x : A} → A
foo {n = n} {x = x} = x
number : Nat
number = foo
check : number ≡ 102
check = refl
| {
"alphanum_fraction": 0.6483050847,
"avg_line_length": 17.4814814815,
"ext": "agda",
"hexsha": "35628935d383ea19a87a9dabba496d144b554fe4",
"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/TacticModality.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/TacticModality.agda",
"max_line_length": 46,
"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/TacticModality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 161,
"size": 472
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.NatSolver.HornerForms where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat hiding (isZero)
open import Cubical.Data.FinData
open import Cubical.Data.Vec
open import Cubical.Data.Bool using (Bool; true; false; if_then_else_)
private
variable
ℓ : Level
{-
This defines the type of multivariate Polynomials over ℕ.
The construction is based on the algebraic fact
ℕ[X₀][X₁]⋯[Xₙ] ≅ ℕ[X₀,⋯,Xₙ]
BUT: Contrary to algebraic convetions, we will give 'Xₙ' the lowest index
in the definition of 'Variable' below. So if 'Variable n k' is identified
with 'Xₖ', what we construct should rather be denoted with
ℕ[Xₙ][Xₙ₋₁]⋯[X₀]
or, to be precise about the evaluation order:
(⋯((ℕ[Xₙ])[Xₙ₋₁])⋯)[X₀]
-}
data IteratedHornerForms : ℕ → Type ℓ-zero where
const : ℕ → IteratedHornerForms ℕ.zero
0H : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
_·X+_ : {n : ℕ} → IteratedHornerForms (ℕ.suc n) → IteratedHornerForms n
→ IteratedHornerForms (ℕ.suc n)
eval : {n : ℕ} (P : IteratedHornerForms n)
→ Vec ℕ n → ℕ
eval (const r) [] = r
eval 0H (_ ∷ _) = 0
eval (P ·X+ Q) (x ∷ xs) =
(eval P (x ∷ xs)) · x + eval Q xs
module IteratedHornerOperations where
private
1H' : (n : ℕ) → IteratedHornerForms n
1H' ℕ.zero = const 1
1H' (ℕ.suc n) = 0H ·X+ 1H' n
0H' : (n : ℕ) → IteratedHornerForms n
0H' ℕ.zero = const 0
0H' (ℕ.suc n) = 0H
1ₕ : {n : ℕ} → IteratedHornerForms n
1ₕ {n = n} = 1H' n
0ₕ : {n : ℕ} → IteratedHornerForms n
0ₕ {n = n} = 0H' n
X : (n : ℕ) (k : Fin n) → IteratedHornerForms n
X (ℕ.suc m) zero = 1ₕ ·X+ 0ₕ
X (ℕ.suc m) (suc k) = 0ₕ ·X+ X m k
_+ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
(const r) +ₕ (const s) = const (r + s)
0H +ₕ Q = Q
(P ·X+ r) +ₕ 0H = P ·X+ r
(P ·X+ r) +ₕ (Q ·X+ s) = (P +ₕ Q) ·X+ (r +ₕ s)
isZero : {n : ℕ} → IteratedHornerForms (ℕ.suc n)
→ Bool
isZero 0H = true
isZero (P ·X+ P₁) = false
_⋆_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms (ℕ.suc n)
→ IteratedHornerForms (ℕ.suc n)
_·ₕ_ : {n : ℕ} → IteratedHornerForms n → IteratedHornerForms n
→ IteratedHornerForms n
r ⋆ 0H = 0H
r ⋆ (P ·X+ Q) = (r ⋆ P) ·X+ (r ·ₕ Q)
const x ·ₕ const y = const (x · y)
0H ·ₕ Q = 0H
(P ·X+ Q) ·ₕ S =
let
z = (P ·ₕ S)
in if (isZero z)
then (Q ⋆ S)
else (z ·X+ 0ₕ) +ₕ (Q ⋆ S)
Variable : (n : ℕ) (k : Fin n) → IteratedHornerForms n
Variable n k = IteratedHornerOperations.X n k
Constant : (n : ℕ) (r : ℕ) → IteratedHornerForms n
Constant ℕ.zero r = const r
Constant (ℕ.suc n) r = IteratedHornerOperations.0ₕ ·X+ Constant n r
| {
"alphanum_fraction": 0.5920057616,
"avg_line_length": 27.495049505,
"ext": "agda",
"hexsha": "1c63ca1bc8905f7ebedb9bb852c31905aeca7a32",
"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/NatSolver/HornerForms.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/NatSolver/HornerForms.agda",
"max_line_length": 75,
"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/Algebra/NatSolver/HornerForms.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": 1175,
"size": 2777
} |
module Basic.Compiler.SplitCode where
open import Basic.Compiler.Code
open import Basic.AST
open import Basic.BigStep
open import Utils.Monoid
open import Data.Vec hiding (_++_; [_]; _∷ʳ_)
open import Data.Bool renaming (if_then_else_ to ifBool_then_else_)
open import Data.Nat
open import Data.List hiding ([_])
open import Relation.Binary.PropositionalEquality
open import Function
open import Data.Product
open import Algebra
import Level as L
private
module LM {a}{A : Set a} = Algebra.Monoid (Data.List.monoid A)
{-
Exercise 3.5
This code logically belongs to either Compiler.Code or Compiler.CorrectFrom.
It has its own module solely because it slows down typechecking for the module
it's in, which is rather annoying.
-}
▷*-split :
∀ {n}{s s' : State n}{e e'} c₁ {c₂}
→ (p : ⟨ c₁ <> c₂ , e , s ⟩▷*⟨ [] , e' , s' ⟩)
→ ∃₂ λ s'' e''
→ ∃₂ λ (p1 : ⟨ c₁ , e , s ⟩▷*⟨ [] , e'' , s'' ⟩)
(p2 : ⟨ c₂ , e'' , s'' ⟩▷*⟨ [] , e' , s' ⟩)
→ ▷*-length p1 + ▷*-length p2 ≡ ▷*-length p
▷*-split [] p = _ , _ , done , p , refl
▷*-split (.ADD ∷ cs) (ADD a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , ADD a b ∷ p1 , p2 , cong suc eqn
▷*-split (.MUL ∷ cs) (MUL a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , MUL a b ∷ p1 , p2 , cong suc eqn
▷*-split (.SUB ∷ cs) (SUB a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , SUB a b ∷ p1 , p2 , cong suc eqn
▷*-split (.EQ ∷ cs) (EQ a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , EQ a b ∷ p1 , p2 , cong suc eqn
▷*-split (.LT ∷ cs) (LT a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LT a b ∷ p1 , p2 , cong suc eqn
▷*-split (.LTE ∷ cs) (LTE a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LTE a b ∷ p1 , p2 , cong suc eqn
▷*-split (.AND ∷ cs) (AND a b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , AND a b ∷ p1 , p2 , cong suc eqn
▷*-split (.(PUSH n₁) ∷ cs) (PUSH n₁ ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , PUSH n₁ ∷ p1 , p2 , cong suc eqn
▷*-split (.TRUE ∷ cs) (TRUE ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , TRUE ∷ p1 , p2 , cong suc eqn
▷*-split (.FALSE ∷ cs) (FALSE ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , FALSE ∷ p1 , p2 , cong suc eqn
▷*-split (.NOT ∷ cs) (NOT b ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , NOT b ∷ p1 , p2 , cong suc eqn
▷*-split (.(FETCH x) ∷ cs) (FETCH x ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , FETCH x ∷ p1 , p2 , cong suc eqn
▷*-split (.(STORE x) ∷ cs) (STORE x ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , STORE x ∷ p1 , p2 , cong suc eqn
▷*-split (.NOOP ∷ cs) (NOOP ∷ p) with ▷*-split cs p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , NOOP ∷ p1 , p2 , cong suc eqn
▷*-split (._ ∷ cs){c₂} (BRANCH{ca}{cb}{._}{t}{e} ∷ p)
rewrite sym $ LM.assoc (ifBool t then ca else cb) cs c₂
with ▷*-split ((ifBool t then ca else cb) <> cs) p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , BRANCH ∷ p1 , p2 , cong suc eqn
▷*-split (._ ∷ cs){c₁} (LOOP{ca}{cb}{._}{e}{s} ∷ p)
rewrite sym $ LM.assoc ca (BRANCH (cb ∷ʳ LOOP ca cb) (NOOP ∷ []) ∷ cs) c₁
with ▷*-split (ca <> (BRANCH (cb ∷ʳ LOOP ca cb) (NOOP ∷ []) ∷ cs)) p
... | s'' , e'' , p1 , p2 , eqn = s'' , e'' , LOOP ∷ p1 , p2 , cong suc eqn
| {
"alphanum_fraction": 0.5080011638,
"avg_line_length": 45.8266666667,
"ext": "agda",
"hexsha": "4161353f8f6296cdc723e6706eeda3cddbcfd5b2",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_forks_repo_path": "Basic/Compiler/SplitCode.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_issues_repo_path": "Basic/Compiler/SplitCode.agda",
"max_line_length": 78,
"max_stars_count": 8,
"max_stars_repo_head_hexsha": "05200d60b4a4b2c6fa37806ced9247055d24db94",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AndrasKovacs/SemanticsWithApplications",
"max_stars_repo_path": "Basic/Compiler/SplitCode.agda",
"max_stars_repo_stars_event_max_datetime": "2020-02-02T10:01:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-09-12T04:25:39.000Z",
"num_tokens": 1514,
"size": 3437
} |
-- Andreas, 2016-05-13 Issue 1973 reported by Nisse
-- Problems with parameters to overloaded projections
-- {-# OPTIONS -v tc.proj.amb:100 #-}
-- {-# OPTIONS -v tc.deftype:100 #-}
record R₁ : Set₁ where
field
f : Set
open R₁ public
postulate
F : ∀ {a} → Set a → Set a
module M (_ : Set₁) where
record R₂ a (G : Set a → Set a) (A : Set a) : Set a where
field
f : G A
open R₂ public
open module N = M Set using (f)
works : ∀ a (A : Set a) → N.R₂ a F A → F A
works a A x = N.R₂.f x
-- WAS:
-- a F !=< F A of type Set
-- when checking that the expression f x has type F A
ill-formed-term-in-error-message : ∀ a (A : Set a) → N.R₂ a F A → F A
ill-formed-term-in-error-message a A x = f x
-- What Agda did here is to copy parameters from the reduced record type
-- M.R₂ Set a F A
-- to the unreduced projection
-- N.R₂.f
-- The number of projections (3) was queried from N.R₂.f, but the projections
-- were taken from M.R₂ Set a F A.
-- Now, take the original version of the projection,
-- M.R₂.f
-- which accepts 4 parameters, and these are the ones provided by M.R₂ Set a F A.
-- WAS:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Substitute.hs:93
internal-error : (A : Set) → N.R₂ _ F A → F A
internal-error A x = f x
-- should work now.
| {
"alphanum_fraction": 0.6442307692,
"avg_line_length": 25.037037037,
"ext": "agda",
"hexsha": "117de5680fdffc4475c4f8f1d4c23e2ea0bb893a",
"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/Issue1973.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/Issue1973.agda",
"max_line_length": 82,
"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/Issue1973.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": 430,
"size": 1352
} |
module Category.Monad.Reader {i}{I : Set i} where
open import Category.Applicative.Indexed
open import Category.Monad
open import Category.Monad.Predicate
open import Relation.Unary
open import Relation.Unary.PredicateTransformer
open import Data.Product
open import Data.Unit
open import Function
open import Level
ReaderT : Set i → Pt I i → Pt I i
ReaderT E M P = λ i → E → M P i
module ReaderT (E : Set i){M : Pt I i}(Mon : RawPMonad {ℓ = i} M) where
module Mon = RawPMonad Mon
open RawPMonad
reader : RawPMonad {ℓ = i} (ReaderT E M)
return? reader x e = Mon.return? x
_=<?_ reader f m e = (λ x → f x e) Mon.=<? m e
-- operations
ask : ∀ {i : I} → ReaderT E M (λ _ → E) i
ask E = return? Mon E
asks : ∀ {A}{i : I} → (E → A i) → ReaderT E M A i
asks f E = return? Mon (f E)
local : ∀ {E'}{A}{i : I} → E' → ReaderT E' M A i → ReaderT E M A i
local e' m = λ _ → m e'
| {
"alphanum_fraction": 0.6344444444,
"avg_line_length": 26.4705882353,
"ext": "agda",
"hexsha": "b748145aab13e7a9e2da8c66bc580f95af722a09",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/Category/Monad/Reader.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/Category/Monad/Reader.agda",
"max_line_length": 71,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/Category/Monad/Reader.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 315,
"size": 900
} |
-- Andreas, 2019-03-25, issue #3647, reported and bisected by nad.
-- Regression introduced in refactoring a78d7f54e447cadf039da81b50ff40c81aa93909.
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS -v 90 #-}
postulate
A : Set
P : A → Set
Q : A → A → Set
Q _ x = P x
record R (P : A → Set) : Set where
field f : (x : A) → P x → P x
open R ⦃ … ⦄
module M {x : A} where
instance
postulate
r₁ r₂ : R (Q x)
postulate
q₁ : (x : A) → P x
q₂ : (x : A) → P x
q₂ x = f _ (q₁ x)
-- WAS: internal error.
-- Should succeed with unsolved metas.
| {
"alphanum_fraction": 0.5897887324,
"avg_line_length": 16.2285714286,
"ext": "agda",
"hexsha": "5b2040ade622ac2850049121f91f0a02484383b6",
"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/Issue3647.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/Issue3647.agda",
"max_line_length": 81,
"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/Issue3647.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": 221,
"size": 568
} |
module Test where
open import IO using (run; putStrLn)
import IO.Primitive as Prim using (IO)
open import Data.Nat.Show as Nat using (show)
open import Data.Unit using (⊤)
open import Vector
main : Prim.IO ⊤
main = run (putStrLn (Nat.show (length gravity₂)))
| {
"alphanum_fraction": 0.7366412214,
"avg_line_length": 21.8333333333,
"ext": "agda",
"hexsha": "87f31af8a3fc83b23f1616248a46e08e292d814b",
"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": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "neosimsim/merkdas",
"max_forks_repo_path": "hello-agda/src/Test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"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": "neosimsim/merkdas",
"max_issues_repo_path": "hello-agda/src/Test.agda",
"max_line_length": 50,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "112a706f266941d6ec8cb107d18476f9d7ffbbc6",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "neosimsim/merkdas",
"max_stars_repo_path": "hello-agda/src/Test.agda",
"max_stars_repo_stars_event_max_datetime": "2020-05-26T08:08:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-26T08:08:13.000Z",
"num_tokens": 70,
"size": 262
} |
module Logic.Linear where
open import Data.Nat using (ℕ; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec using (Vec; []; _∷_; _++_; map)
open import Data.Empty using (⊥)
-- Operator precedences.
infix 10 _^⊥ e?_ e!_
infixl 9 _⊗_ _&_
infixl 8 _⊕_ _⅋_
infixl 7 _⊸_
infixl 6 _≡_
-- Primitive linear propositions.
data LinearProp {a} (A : Set a) : Set a where
atom : A → LinearProp A
atom^⊥ : A → LinearProp A
_⊗_ : LinearProp A → LinearProp A → LinearProp A
_⊕_ : LinearProp A → LinearProp A → LinearProp A
_&_ : LinearProp A → LinearProp A → LinearProp A
_⅋_ : LinearProp A → LinearProp A → LinearProp A
u0 : LinearProp A
u1 : LinearProp A
u⊥ : LinearProp A
u⊤ : LinearProp A
e!_ : LinearProp A → LinearProp A
e?_ : LinearProp A → LinearProp A
-- The equivalent of the propositional negation, called "dual".
_^⊥ : ∀ {a} {A : Set a} → LinearProp A → LinearProp A
(atom p) ^⊥ = atom^⊥ p
(atom^⊥ p) ^⊥ = atom p
(p ⊗ q) ^⊥ = (p ^⊥) ⅋ (q ^⊥)
(p ⊕ q) ^⊥ = (p ^⊥) & (q ^⊥)
(p ⅋ q) ^⊥ = (p ^⊥) ⊗ (q ^⊥)
(p & q) ^⊥ = (p ^⊥) ⊕ (q ^⊥)
u1 ^⊥ = u⊥
u0 ^⊥ = u⊤
u⊥ ^⊥ = u1
u⊤ ^⊥ = u0
(e! p) ^⊥ = e? (p ^⊥)
(e? p) ^⊥ = e! (p ^⊥)
-- The linear implication, also called "lollipop operator".
_⊸_ : ∀ {a} {A : Set a} → LinearProp A → LinearProp A → LinearProp A
p ⊸ q = p ^⊥ ⅋ q
-- The equivalent of the propositional equivalence (lmao).
_≡_ : ∀ {a} {A : Set a} → LinearProp A → LinearProp A → LinearProp A
p ≡ q = (p ⊸ q) & (q ⊸ p)
-- Swaps two elements with two given positions. Just a helper of `swap`.
swap-vec : ∀ {a} {A : Set a}
{n : ℕ} →
Fin n →
Fin n →
Vec A n →
Vec A n
swap-vec = do-swap where
insert : ∀ {a} {A : Set a}
{n : ℕ} →
A →
Vec A (suc n) →
Vec A (suc (suc n))
insert y (x ∷ xs) = x ∷ y ∷ xs
swap-first : ∀ {a} {A : Set a}
{n : ℕ} →
Fin n →
Vec A n →
Vec A n
swap-first zero xs = xs
swap-first (suc zero) (x ∷ y ∷ xs) = y ∷ x ∷ xs
swap-first (suc m) (x ∷ y ∷ xs) = insert y (swap-first m (x ∷ xs))
do-swap : ∀ {a} {A : Set a}
{n : ℕ} →
Fin n →
Fin n →
Vec A n →
Vec A n
do-swap zero zero xs = xs
do-swap zero (suc m) xs = swap-first (suc m) xs
do-swap (suc m) zero xs = swap-first (suc m) xs
do-swap (suc k) (suc m) (x ∷ xs) = x ∷ do-swap k m xs
-- List of inference rules.
-- The S parameter is an axiom scheme.
-- To prove somthing, it must be the only proposition in the sequent.
data _⊢_ {a}
{A : Set a}
(S : LinearProp A → Set a) :
{n : ℕ} →
Vec (LinearProp A) n
→ Set a
where
empty : S ⊢ []
axiom : {p : LinearProp A} → S p → S ⊢ (p ∷ [])
swap : {n : ℕ}
{ps : Vec (LinearProp A) n} →
(i j : Fin n) →
S ⊢ ps →
S ⊢ (swap-vec i j ps)
^⊥-i : (p : LinearProp A) → S ⊢ (p ∷ p ^⊥ ∷ [])
^⊥-e : {p : LinearProp A}
{m n : ℕ}
{ps : Vec (LinearProp A) m} →
{qs : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (p ^⊥ ∷ qs) →
S ⊢ (ps ++ qs)
⊗-i : {p q : LinearProp A}
{m n : ℕ}
{ps : Vec (LinearProp A) m} →
{qs : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (q ∷ qs) →
S ⊢ (p ⊗ q ∷ ps ++ qs)
⅋-i : {p q : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ q ∷ ps) →
S ⊢ (p ⅋ q ∷ ps)
u1-i : S ⊢ (u1 ∷ [])
u⊥-i : {n : ℕ} {ps : Vec (LinearProp A) n} → S ⊢ ps → S ⊢ (u⊥ ∷ ps)
&-i : {p q : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (q ∷ ps) →
S ⊢ (p & q ∷ ps)
⊕-i₁ : {p q : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (p ⊕ q ∷ ps)
⊕-i₂ : {p q : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (q ⊕ p ∷ ps)
u⊤-i : {n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (u⊤ ∷ ps)
e?-i₁ : {p : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ ps →
S ⊢ (e? p ∷ ps)
e?-i₂ : {p : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ ps) →
S ⊢ (e? p ∷ ps)
e?-e : {p : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (e? p ∷ e? p ∷ ps) →
S ⊢ (e? p ∷ ps)
e!-i : {p : LinearProp A}
{n : ℕ}
{ps : Vec (LinearProp A) n} →
S ⊢ (p ∷ map e?_ ps) →
S ⊢ (e! p ∷ map e?_ ps)
-- Empty axiom scheme.
data NoAxioms {a} {A : Set a} : LinearProp A → Set a where
-- Just a helper to hint something has been proven.
Proof : ∀ {a} {A : Set a} → (LinearProp A → Set a) → LinearProp A → Set a
Proof S p = S ⊢ (p ∷ [])
| {
"alphanum_fraction": 0.4437005478,
"avg_line_length": 26.2180851064,
"ext": "agda",
"hexsha": "c0f60c95981c204237a6860fbce3d92f3177937e",
"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": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "brunoczim/linear-logic",
"max_forks_repo_path": "src/Logic/Linear.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"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": "brunoczim/linear-logic",
"max_issues_repo_path": "src/Logic/Linear.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "brunoczim/linear-logic",
"max_stars_repo_path": "src/Logic/Linear.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2079,
"size": 4929
} |
{-# OPTIONS --without-K #-}
module well-typed-syntax-interpreter where
open import common public
open import well-typed-syntax
import well-typed-syntax-pre-interpreter
open import well-typed-syntax-eq-dec
max-level : Level
max-level = well-typed-syntax-pre-interpreter.max-level
Context⇓ : (Γ : Context) → Set (lsuc max-level)
Context⇓ = well-typed-syntax-pre-interpreter.inner.Context⇓
(λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)
(λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})
Typ⇓ : {Γ : Context} → Typ Γ → Context⇓ Γ → Set max-level
Typ⇓ = well-typed-syntax-pre-interpreter.inner.Typ⇓
(λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)
(λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})
Term⇓ : ∀ {Γ : Context} {T : Typ Γ} → Term T → (Γ⇓ : Context⇓ Γ) → Typ⇓ T Γ⇓
Term⇓ = well-typed-syntax-pre-interpreter.inner.Term⇓
(λ ℓ P Γ' dummy val → context-pick-if {P = P} dummy val)
(λ ℓ P dummy val → context-pick-if-refl {P = P} {dummy})
| {
"alphanum_fraction": 0.6452241715,
"avg_line_length": 41.04,
"ext": "agda",
"hexsha": "c3a75f751cbe09b1b72411e3d71f323899f5467b",
"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-interpreter.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-interpreter.agda",
"max_line_length": 76,
"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-interpreter.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": 348,
"size": 1026
} |
{-# OPTIONS --without-K #-}
module ForAmr where
open import Level using (Level)
open import Relation.Nullary.Core
open import Data.Vec
using (Vec; tabulate; []; _∷_; lookup; allFin)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Data.Vec.Properties
using (lookup-++-≥; lookup∘tabulate; tabulate-∘; tabulate∘lookup; map-cong)
open import Function using (id;_∘_)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; cong; cong₂; subst; proof-irrelevance;
_≗_; module ≡-Reasoning)
open import Data.Nat using (ℕ; zero; suc; _+_; z≤n; _≟_)
open import Data.Nat.Properties.Simple using (+-comm)
open import Data.Nat.Properties using (m≤m+n)
open import Data.Fin using (Fin; zero; suc; inject+; raise; reduce≥; toℕ; fromℕ≤)
open import Data.Fin.Properties using (toℕ-injective; toℕ-raise; toℕ-fromℕ≤)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (proj₁)
open import Function using (flip)
open import Proofs
open import Equiv
open import FinEquiv
open import Cauchy
open import TypeEquiv using (swap₊; swapswap₊)
----------------------------------------------------
-- and now this is completely obvious. But not actually needed!
swap+-idemp : {A B : Set} → {m n : ℕ} → (v : Vec (A ⊎ B) (m + n)) →
swap+ {m} (swap+ {m} v) ≡ v
swap+-idemp v =
begin (
tabulate (λ i → swap₊ (tabulate (λ j → swap₊ (v !! j)) !! i))
≡⟨ denest-tab-!! swap₊ swap₊ v ⟩
mapV (swap₊ ∘ swap₊) v
≡⟨ map-cong swapswap₊ v ⟩
mapV id v
≡⟨ map-id v ⟩
v ∎)
where open ≡-Reasoning
-- because this is 'pointwise', no need for swap+-idemp.
pointwise-swap+v-idemp : {m n : ℕ} → ∀ i →
lookup (lookup i (swap+v m n)) (swap+v n m) ≡ i
pointwise-swap+v-idemp {m} {n} i =
let fnm = swapper n m in
let fmn = swapper m n in
begin (
lookup (lookup i (swap+v m n)) (swap+v n m)
≡⟨ cong (λ x → lookup x (swap+v n m)) (lookup∘tabulate fmn i) ⟩
lookup (fmn i) (swap+v n m)
≡⟨ lookup∘tabulate fnm (fmn i) ⟩
fnm (fmn i) -- bingo!
≡⟨ cong (fwd ∘ swap₊) (bwd∘fwd~id (swap₊ (bwd {m} i))) ⟩
fwd (swap₊ (swap₊ (bwd {m} i)))
≡⟨ cong fwd (swapswap₊ (bwd {m} i)) ⟩
fwd (bwd {m} i)
≡⟨ fwd∘bwd~id {m} i ⟩
i ∎ )
where open ≡-Reasoning
-- this is true, but the above is what is used in practice.
swap+v-idemp : {m n : ℕ} →
tabulate (λ i → lookup (lookup i (swap+v m n)) (swap+v n m)) ≡ tabulate id
swap+v-idemp {m} = finext (pointwise-swap+v-idemp {m})
---------------------------------------------------------------
-- Everything below here is based on Cauchy as Vec (Fin n) n
-- and might get tossed. Comment it out for now.
{-
-- the Cauchy version.
swap+c : (m n : ℕ) → Cauchy (m + n)
swap+c m n = subst (λ x → Vec (Fin x) (m + n)) (+-comm n m) (swap+v m n)
-- the action of subst on swap+, pointwise
switch-swap+ : {m n : ℕ} → (i : Fin (m + n)) →
subst Fin (+-comm n m) (swapper m n i) ≡
swapper n m (subst Fin (+-comm m n) i)
switch-swap+ {m} {n} i with m ≟ n
switch-swap+ i | yes p = {!!}
switch-swap+ i | no ¬p = {!!}
{-
switch-swap+ {m} {n} i with (toℕ i <? m) | (toℕ (subst Fin (+-comm m n) i) <? n)
switch-swap+ {m} {n} i | yes p | yes q = {!!} {- toℕ-injective (
begin (
toℕ (subst Fin (+-comm n m) (raise n (fromℕ≤ p)))
≡⟨ toℕ-invariance (raise n (fromℕ≤ p)) (+-comm n m) ⟩
toℕ (raise n (fromℕ≤ p))
≡⟨ toℕ-raise n (fromℕ≤ p) ⟩
n + toℕ (fromℕ≤ p)
≡⟨ cong (_+_ n) (toℕ-fromℕ≤ p) ⟩
n + toℕ i
≡⟨ {!!} ⟩
m + toℕ (subst Fin (+-comm m n) i)
≡⟨ sym (cong (_+_ m) (toℕ-fromℕ≤ q)) ⟩
m + toℕ (fromℕ≤ q)
≡⟨ sym (toℕ-raise m (fromℕ≤ q)) ⟩
toℕ (raise m (fromℕ≤ q)) ∎))
where open ≡-Reasoning -}
switch-swap+ i | yes p | no ¬q = {!!}
switch-swap+ i | no ¬p | yes q = {!!}
switch-swap+ i | no ¬p | no ¬q = {!!}
-}
-- the Cauchy version:
pcomp' : ∀ {m n} → Cauchy m → Cauchy n → Cauchy (m + n)
pcomp' α β = mapV fwd (pcomp α β)
-- the action of subst on swap+v
switch-swap : {m n : ℕ} → (i : Fin (m + n)) →
subst Fin (+-comm n m) ((swap+v m n) !! i) ≡
(swap+v n m) !! subst Fin (+-comm m n) i
switch-swap {m} {n} i =
let fnm = swapper n m in
let fmn = swapper m n in
begin (
subst Fin (+-comm n m) ((tabulate fmn) !! i)
≡⟨ cong (subst Fin (+-comm n m)) (lookup∘tabulate fmn i) ⟩
subst Fin (+-comm n m) (fmn i)
≡⟨ switch-swap+ {m} i ⟩
fnm (subst Fin (+-comm m n) i)
≡⟨ sym (lookup∘tabulate fnm (subst Fin (+-comm m n) i)) ⟩
tabulate (fnm) !! subst Fin (+-comm m n) i ∎)
where open ≡-Reasoning
-- the crucial part for the next theorem:
swap+-idemp' : {m n : ℕ} → ∀ (i : Fin (m + n)) → lookup
(subst (λ x → Vec (Fin x) (m + n)) (+-comm n m) (swap+v m n) !! i)
(subst (λ x → Vec (Fin x) (m + n)) (+-comm n m) (swap+v m n))
≡ i
swap+-idemp' {m} {n} i =
let j = subst (λ x → Vec (Fin x) (m + n)) (+-comm n m) (swap+v m n) !! i in
begin (
lookup j (subst (λ x → Vec (Fin x) (m + n)) (+-comm n m) (swap+v m n))
≡⟨ lookup-subst j (swap+v m n) (+-comm n m) ⟩
subst Fin (+-comm n m) ((swap+v m n) !! j)
≡⟨ cong (λ x → subst Fin (+-comm n m) ((swap+v m n) !! x))
(lookup-subst i (swap+v m n) (+-comm n m)) ⟩
subst Fin (+-comm n m) ((swap+v m n) !! subst Fin (+-comm n m) (swap+v m n !! i))
≡⟨ cong (λ x → subst Fin (+-comm n m) ((swap+v m n) !! x))
(switch-swap {m} i) ⟩
subst Fin (+-comm n m) ((swap+v m n) !! (swap+v n m !! subst Fin (+-comm m n) i))
≡⟨ cong (subst Fin (+-comm n m)) (pointwise-swap+v-idemp {n} (subst Fin (+-comm m n) i)) ⟩
subst Fin (+-comm n m) (subst Fin (+-comm m n) i)
≡⟨ subst-subst (+-comm n m) (+-comm m n)
(proof-irrelevance (sym (+-comm n m)) (+-comm m n)) i ⟩
i ∎)
where open ≡-Reasoning
-- and let's see what that does to the Cauchy version:
swap+c-idemp : {m n : ℕ} → scompcauchy (swap+c m n) (swap+c m n) ≡ allFin (m + n)
swap+c-idemp {m} {n} = finext (swap+-idemp' {m} {n})
-}
| {
"alphanum_fraction": 0.5278137128,
"avg_line_length": 38.4099378882,
"ext": "agda",
"hexsha": "255cd4d6edc91fba58be5287e4e852dc3d721b71",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/ForAmr.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/ForAmr.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": "Univalence/Obsolete/ForAmr.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": 2396,
"size": 6184
} |
------------------------------------------------------------------------
-- Parser indices
------------------------------------------------------------------------
module StructurallyRecursiveDescentParsing.Index where
open import Data.Bool
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Function
------------------------------------------------------------------------
-- Indices to the parser type
-- Does the parser accept empty strings?
Empty : Set
Empty = Bool
-- The proper left corners of the parser, represented as a tree. See
-- StructurallyRecursiveDescentParsing.Grammar.
infix 5 _∪_
data Corners : Set where
ε : Corners
_∪_ : (c₁ c₂ : Corners) → Corners
-- The index type.
infix 4 _◇_
record Index : Set where
constructor _◇_
field
empty : Empty
corners : Corners
open Index public
-- Type signature for non-terminals. The second argument is the result
-- type.
NonTerminalType : Set2
NonTerminalType = Index → Set → Set1
------------------------------------------------------------------------
-- Operations on indices
infixr 50 _·_
infixr 40 _∥_
0I : Index
0I = false ◇ ε
1I : Index
1I = true ◇ ε
_∥_ : Index → Index → Index
i₁ ∥ i₂ = empty i₁ ∨ empty i₂ ◇ corners i₁ ∪ corners i₂
_·_ : Index → Index → Index
i₁ · i₂ = (empty i₁ ∧ empty i₂)
◇
(if empty i₁ then corners i₁ ∪ corners i₂
else corners i₁)
------------------------------------------------------------------------
-- Testing indices for equality
infix 15 _Index-≟_ _Corners-≟_
private
drop-∪₁ : ∀ {c₁ c₂ c₃ c₄} → c₁ ∪ c₂ ≡ c₃ ∪ c₄ → c₁ ≡ c₃
drop-∪₁ refl = refl
drop-∪₂ : ∀ {c₁ c₂ c₃ c₄} → c₁ ∪ c₂ ≡ c₃ ∪ c₄ → c₂ ≡ c₄
drop-∪₂ refl = refl
_Corners-≟_ : Decidable {A = Corners} _≡_
ε Corners-≟ ε = yes refl
(c₁ ∪ c₂) Corners-≟ ( c₃ ∪ c₄) with c₁ Corners-≟ c₃ | c₂ Corners-≟ c₄
(c₁ ∪ c₂) Corners-≟ (.c₁ ∪ .c₂) | yes refl | yes refl = yes refl
(c₁ ∪ c₂) Corners-≟ ( c₃ ∪ c₄) | no ¬c₁≡c₂ | _ = no (¬c₁≡c₂ ∘ drop-∪₁)
(c₁ ∪ c₂) Corners-≟ ( c₃ ∪ c₄) | _ | no ¬c₁≡c₂ = no (¬c₁≡c₂ ∘ drop-∪₂)
ε Corners-≟ (_ ∪ _) = no λ()
(_ ∪ _) Corners-≟ ε = no λ()
_Index-≟_ : Decidable {A = Index} _≡_
i₁ Index-≟ i₂ with empty i₁ ≟ empty i₂
| corners i₁ Corners-≟ corners i₂
... | yes e₁≡e₂ | yes c₁≡c₂ = yes (cong₂ _◇_ e₁≡e₂ c₁≡c₂)
... | no ¬e₁≡e₂ | _ = no (¬e₁≡e₂ ∘ cong empty)
... | _ | no ¬c₁≡c₂ = no (¬c₁≡c₂ ∘ cong corners)
| {
"alphanum_fraction": 0.5155084413,
"avg_line_length": 26.2577319588,
"ext": "agda",
"hexsha": "d92f27247a53da99c86f6a55bae468cb58404748",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/parser-combinators",
"max_forks_repo_path": "StructurallyRecursiveDescentParsing/Index.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "76774f54f466cfe943debf2da731074fe0c33644",
"max_issues_repo_issues_event_max_datetime": "2018-01-24T16:39:37.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-01-22T22:21:41.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/parser-combinators",
"max_issues_repo_path": "StructurallyRecursiveDescentParsing/Index.agda",
"max_line_length": 81,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "b396d35cc2cb7e8aea50b982429ee385f001aa88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yurrriq/parser-combinators",
"max_stars_repo_path": "StructurallyRecursiveDescentParsing/Index.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-22T05:35:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-13T05:23:14.000Z",
"num_tokens": 891,
"size": 2547
} |
module LF where
data Zero : Set where
record One : Set where
★ : One
★ = record {}
One-elim : (C : One -> Set) -> C ★ -> (a : One) -> C a
One-elim C h _ = h
One-elim₁ : (C : One -> Set1) -> C ★ -> (a : One) -> C a
One-elim₁ C h _ = h
-- data One' : Set1 where
-- ★' : One'
data Two : Set where
★₀ : Two
★₁ : Two
case₂ : {A : Set1} -> Two -> A -> A -> A
case₂ ★₀ x y = x
case₂ ★₁ x y = y
data _+_ (A : Set)(B : Set) : Set where
inl : A -> A + B
inr : B -> A + B
record _×_ (A : Set)(B : A -> Set) : Set where
field
π₀ : A
π₁ : B π₀
open _×_ public
_,_ : {A : Set}{B : A -> Set}(a : A) -> B a -> A × B
x , y = record { π₀ = x; π₁ = y }
_*_ : (A B : Set) -> Set
A * B = A × \_ -> B
-- data _×'_ (A : Set)(B : A -> Set1) : Set1 where
-- _,'_ : (a : A) -> B a -> A ×' B
--
-- π₀' : {A : Set}{B : A -> Set1} -> A ×' B -> A
-- π₀' (a ,' b) = a
--
-- π₁' : {A : Set}{B : A -> Set1}(p : A ×' B) -> B (π₀' p)
-- π₁' (a ,' b) = b
| {
"alphanum_fraction": 0.421875,
"avg_line_length": 17.4545454545,
"ext": "agda",
"hexsha": "53554ef70076219cc29b6231e2e881c014b712a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/iird/LF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/iird/LF.agda",
"max_line_length": 58,
"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/iird/LF.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": 434,
"size": 960
} |
-- We show by allowing the reminder of integer division to be
-- negative, we can get more precise estimation of the rank of the
-- remainder: rank reminder ≤ (rank divisor) / 2.
{-# OPTIONS --without-K --safe #-}
module Integer.EucDomain2 where
-- ----------------------------------------------------------------------
-- ℕ is an "Euclidean SemiRing".
module NatESR where
-- ℕ satisfy the euc-eq and euc-rank property with the usual div and
-- mod function. Still we need to do the translation from non-equality
-- to NonZero predicate.
-- imports form stdlib.
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Data.Nat as Nat using (ℕ ; zero ; suc)
import Data.Nat.DivMod as NDM
import Data.Nat.Properties as NatP
-- imports from local.
open import Instances
-- We already make ℕ an instance of Rank. For convinence we restate it
-- here.
rank' : ℕ -> ℕ
rank' x = x
-- Division with the annoying translation from ¬ d ≡ 0 to NonZero
-- predicate.
div : ∀ (n d : ℕ) -> ¬ d ≡ 0 -> ℕ
div n zero n0 with n0 refl
... | ()
div n (suc d) n0 = NDM._/_ n (suc d)
-- Reminder.
mod : ∀ (n d : ℕ) -> ¬ d ≡ 0 -> ℕ
mod n zero n0 with n0 refl
... | ()
mod n (suc d) n0 = NDM._%_ n (suc d)
-- Dividend = reminder + quotient * divisor.
euc-eq : ∀ (n d : ℕ) (n0 : ¬ d ≡ 0) ->
let r = mod n d n0 in let q = div n d n0 in
n ≡ r + q * d
euc-eq n zero n0 with n0 refl
... | ()
euc-eq n (suc d) n0 = NDM.m≡m%n+[m/n]*n n (suc d)
-- rank reminder < rank divisor.
euc-rank : ∀ (n d : ℕ) (n0 : ¬ d ≡ 0) ->
let r = mod n d n0 in let q = div n d n0 in
rank r < rank d
euc-rank n zero n0 with n0 refl
... | ()
euc-rank n (suc d) n0 = NDM.m%n<n n (suc d)
-- ----------------------------------------------------------------------
-- Allow Integer division to have negative reminder
-- Let n, d be integers and d nonzero, by the usual divison with
-- reminder we have q, r such that n = r + q * d and ∣ r ∣ < ∣ d ∣.
-- What we want is q' and r' such that n = r' + q' * d and ∣ r' ∣ ≤ ∣
-- d ∣ / 2. Asssume d > 0, an easy calculation shows if ∣ r ∣ ≤ ∣ d ∣
-- / 2, we let q' = q and r' = r, and if ∣ r ∣ > ∣ d ∣ / 2, we let q'
-- = q + 1 and r' = r - d. The case when d < 0 is similar.
-- imports from stdlib.
open import Relation.Nullary using (yes ; no ; ¬_)
open import Relation.Binary.PropositionalEquality as PE
using (_≡_ ; refl ; sym ; cong ; trans)
open import Data.Empty using (⊥-elim)
open import Data.Sum using (_⊎_ ; inj₁ ; inj₂)
open import Data.Bool using (T ; not)
open import Data.Nat as Nat using (ℕ ; suc ; s≤s ; zero ; z≤n)
import Data.Nat.DivMod as NDM
import Data.Nat.Properties as NatP
open import Data.Integer as Int
using (ℤ ; ∣_∣ ; +_ ; +[1+_] ; -[1+_] ; 1ℤ ; _◃_ ; +<+ ; -<- ; -≤- ; -<+ ; -≤+ ; +≤+ ; 0ℤ)
import Data.Integer.Properties as IntP
open import Data.Integer.DivMod
using (_div_ ; _mod_ ; a≡a%n+[a/n]*n ; n%d<d)
open import Data.Integer.Solver
-- imports from local.
open import Instances
-- Aother integer division allowing negative reminder.
div' : ∀ (n d : ℤ) -> ¬ d ≡ 0ℤ -> ℤ
div' n (+_ zero) n0 with n0 refl
... | ()
div' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = n div d
... | no np = 1ℤ + n div d
div' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = n div d
... | no np = - 1ℤ + n div d
-- Another integer mod allowing negative reminder.
mod' : ∀ (n d : ℤ) -> ¬ d ≡ 0ℤ -> ℤ
mod' n (+_ zero) n0 with n0 refl
... | ()
mod' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = + (n mod d)
... | no np = + (n mod d) - d
mod' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = + (n mod d)
... | no np = + (n mod d) + d
-- Dividend = reminder + quotient * divisor.
euc-eq' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
n ≡ r + q * d
euc-eq' n (+_ zero) n0 with n0 refl
... | ()
euc-eq' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = a≡a%n+[a/n]*n n d
... | no np = claim
where
claim : n ≡ (+ (n mod d) - d) + (1ℤ + n div d) * d
claim = begin
n ≡⟨ a≡a%n+[a/n]*n n d ⟩
+ (n mod d) + (n div d) * d ≡⟨ solve 3 (\ x y z -> x :+ y :* z := x :- z :+ (con 1ℤ :+ y) :* z) refl (+ (n mod d)) (n div d) d ⟩
(+ (n mod d) - d) + (1ℤ + n div d) * d ∎
where
open +-*-Solver
open PE.≡-Reasoning
euc-eq' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = a≡a%n+[a/n]*n n d
... | no np = claim
where
claim : n ≡ (+ (n mod d) + d) + (- 1ℤ + n div d) * d
claim = begin
n ≡⟨ a≡a%n+[a/n]*n n d ⟩
+ (n mod d) + (n div d) * d ≡⟨ solve 3 (\ x y z -> x :+ y :* z := x :+ z :+ (con (- 1ℤ) :+ y) :* z) refl (+ (n mod d)) (n div d) d ⟩
(+ (n mod d) + d) + (- 1ℤ + n div d) * d ∎
where
open +-*-Solver
open PE.≡-Reasoning
-- rank reminder ≤ (rank divisor) / 2.
euc-rank' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
∣ r ∣ ≤ ∣ d ∣ / 2
euc-rank' n (+_ zero) n0 with n0 refl
... | ()
euc-rank' n d@(+[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2
... | yes pr = pr
... | no ¬p = claim
where
r = + (n mod d) - d
d≠0 : ¬ ∣ d ∣ ≡ 0
d≠0 = λ ()
-- We follow the steps to show ∣ r ∣ ≤ ∣ d ∣ / 2, in the current case, i.e. ∣
-- n % d - d ∣ ≤ d / 2. We follows the steps below:
-- 1) d / 2 < n % d
-- 2) d / 2 - d < n % d - d
-- 3) n % d - d < 0, hence d / 2 - d < n % d - d < 0
-- 4) ∣ d / 2 - d ∣ > ∣ n % d - d ∣
-- 5) d / 2 - d ≡ - d / 2 or d / 2 - d ≡ - (d / 2 + 1)
-- 6) ∣ d / 2 - d ∣ ≡ d / 2 or ∣ d / 2 - d ∣ ≡ d / 2 + 1
-- 7) d / 2 > ∣ n % d - d ∣ or d / 2 + 1 > ∣ n % d - d ∣
-- 8) d / 2 ≥ ∣ n % d - d ∣
-- By negate ¬p, we can show ∣ d ∣ / 2 < n mod d.
-- By negation of ¬p (we are using the decidable order).
open import Relation.Binary using (tri< ; tri≈ ; tri>)
step1 : ∣ d ∣ / 2 < n mod d
step1 with NatP.<-cmp (n mod d) (∣ d ∣ / 2)
... | tri< a ¬b ¬c = ⊥-elim (¬p (NatP.<⇒≤ a))
... | tri≈ ¬a b ¬c = ⊥-elim (¬p (NatP.≤-reflexive b))
... | tri> ¬a ¬b c = c
where
notle : ¬ (n mod d ≤ ∣ d ∣ / 2)
notle = ¬p
-- Step 2. ∣ d ∣ / 2 - ∣ d ∣ < n mod d - ∣ d ∣. Subtracting ∣ d ∣
-- from both sides of step1 preserves the inequality.
step2 : + (∣ d ∣ / 2) - + ∣ d ∣ < + (n mod d) - + ∣ d ∣
step2 = IntP.+-monoʳ-< (- (+ ∣ d ∣)) (+<+ step1)
-- Step 3. n mod d - ∣ d ∣ < 0
-- Some auxillary.
n-n=0 : ∀ {n} -> n - n ≡ 0ℤ
n-n=0 {n} = IntP.+-inverseʳ n
step3 : + (n mod d) - (+ ∣ d ∣) < 0ℤ
step3 rewrite (sym (n-n=0 {+ ∣ d ∣})) = r-d<d-d
where
-- n mod d < ∣ d ∣, by Euclidean property of integers.
r<∣d∣ : + (n mod d) < + ∣ d ∣
r<∣d∣ = +<+ (n%d<d n d)
-- Substract ∣ d ∣ on both sides of n mod d < ∣ d ∣.
r-d<d-d : + (n mod d) - (+ ∣ d ∣) < (+ ∣ d ∣) - (+ ∣ d ∣)
r-d<d-d = IntP.+-monoʳ-< (- + ∣ d ∣) r<∣d∣
-- Step 4. ∣ d / 2 - d ∣ > ∣ n % d - d ∣. By 2, we have
-- d / 2 - d < n % d - d < 0. By taking absolute values, we show
-- ∣ d / 2 - d ∣ > ∣ n % d - d ∣.
-- Some lemmas about take absolute value of negative and nonpositive
-- numbers.
lemma-∣neg∣ : ∀ {a : ℤ} -> a < 0ℤ -> + ∣ a ∣ ≡ - a
lemma-∣neg∣ -<+ = refl
lemma-∣non-pos∣ : ∀ {a : ℤ} -> a ≤ 0ℤ -> + ∣ a ∣ ≡ - a
lemma-∣non-pos∣ {.(-[1+ _ ])} -≤+ = refl
lemma-∣non-pos∣ {.(+ zero)} (+≤+ z≤n) = refl
-- The injection of natural numbers into integers reflect order.
lemma-inj-reflect-ord : ∀ {a b} -> + a < + b -> a < b
lemma-inj-reflect-ord (+<+ m<n) = m<n
lemma-inj-reflect-ord' : ∀ {a b} -> + a ≤ + b -> a ≤ b
lemma-inj-reflect-ord' (+≤+ m<n) = m<n
-- Taking absolute value on both sides of a strict inequality of
-- negative numbers (can relax this to non-positive numbers)
-- reverses the order.
lemma-∣neg<neg∣ : ∀ {a b} -> a < 0ℤ -> b < a -> ∣ a ∣ < ∣ b ∣
lemma-∣neg<neg∣ {a} {b} a<0 b<a = lemma-inj-reflect-ord claim where
0<b : b < 0ℤ
0<b = IntP.<-trans b<a a<0
claim : (+ ∣ a ∣) < (+ ∣ b ∣)
claim = begin-strict
+ ∣ a ∣ ≡⟨ lemma-∣neg∣ {a} a<0 ⟩
- a <⟨ IntP.neg-mono-< b<a ⟩
- b ≡⟨ sym (lemma-∣neg∣ 0<b) ⟩
+ ∣ b ∣ ∎
where open IntP.≤-Reasoning
-- Goal step4 achieved.
step4 : ∣ + (n mod d) - d ∣ < ∣ + (∣ d ∣ / 2) - d ∣
step4 = lemma-∣neg<neg∣ step3 step2
-- Step 5. d / 2 - d ≡ - d / 2 or d / 2 - d ≡ - (d / 2 + 1)
-- Natural number version of Step 5.
step5-nat : ∣ d ∣ / 2 + ∣ d ∣ / 2 ≡ ∣ d ∣ ⊎ suc (∣ d ∣ / 2 + ∣ d ∣ / 2) ≡ ∣ d ∣
step5-nat = lemma-div-by-2 ∣ d ∣
where
-- An easy and useful fact.
*2+ : ∀ {a} -> a * 2 ≡ a + a
*2+ {zero} = refl
*2+ {suc a} rewrite *2+ {a} | NatP.+-comm a (suc a) = refl
-- Either d / 2 + d / 2 ≡ d or d / 2 + d / 2 + 1 ≡ d.
lemma-div-by-2 : ∀ d -> let hd = d / 2 in
hd + hd ≡ d ⊎ suc (hd + hd) ≡ d
lemma-div-by-2 d with d / 2 | d % 2 | NatESR.euc-eq d 2 (λ { ()}) | NatESR.euc-rank d 2 (λ { ()})
... | hd | zero | proj₁₁ | pr rewrite *2+ {hd} = inj₁ (sym proj₁₁)
... | hd | suc zero | proj₁₁ | pr rewrite *2+ {hd} = inj₂ (sym proj₁₁)
... | hd | suc (suc r₁) | proj₁₁ | pr = ⊥-elim ((c1 r₁) pr )
where
c1 : ∀ a -> ¬ (suc (suc (suc a)) ≤ 2)
c1 a = λ { (s≤s (s≤s ()))}
-- Next we need inject naturals to integers. We do the two
-- identities separately.
-- Step 5a. If (d / 2) + (d / 2) ≡ d, we show d / 2 - d ≡ - d / 2.
step5a : ∀ d -> (d / 2) + (d / 2) ≡ d -> let -_ = λ x -> - (+ x) in
+ (d / 2) - (+ d) ≡ - (d / 2)
step5a d hyp = sym claim4
where
open PE.≡-Reasoning
claim : + (d / 2 + d / 2) ≡ + d
claim = cong +_ hyp
claim2 : + (d / 2) + + (d / 2) ≡ + d
claim2 = begin
+ (d / 2) + + (d / 2) ≡⟨ IntP.pos-+-commute (d / 2) (d / 2) ⟩
+ (d / 2 + d / 2) ≡⟨ cong +_ hyp ⟩
+ d ∎
claim3 : + (d / 2) ≡ + d - + (d / 2)
claim3 = begin
+ (d / 2) ≡⟨ (solve 1 (λ a -> a := a :+ a :- a) refl) (+ (d / 2)) ⟩
+ (d / 2) + + (d / 2) - + (d / 2) ≡⟨ cong (_- + (d / 2)) claim2 ⟩
+ d - + (d / 2) ∎
where open +-*-Solver
claim4 : let -_ = λ x -> - (+ x) in
- (d / 2) ≡ + (d / 2) - + d
claim4 = begin
- (+ (d / 2)) ≡⟨ cong -_ claim3 ⟩
- (+ d - + (d / 2)) ≡⟨ (solve 2 (λ a b -> :- (a :- b) := b :- a) refl) (+ d) (+ (d / 2)) ⟩
+ (d / 2) - + d ∎
where open +-*-Solver
-- Step 5b. If (d / 2) + (d / 2) + 1 ≡ d, we show d / 2 - d ≡ - (d
-- / 2 + 1). (Note that we change the sign of the equality)
step5b : ∀ d -> suc ((d / 2) + (d / 2)) ≡ d -> let -_ = λ x -> - (+ x) in
(+ d) - + (d / 2) ≡ + (d / 2) + 1ℤ
step5b d hyp = begin
+ d - + (d / 2) ≡⟨ cong (λ x → + x - + (d / 2)) (sym hyp) ⟩
+ (suc (d / 2 + d / 2)) - + (d / 2) ≡⟨ refl ⟩
+ (1 + (d / 2 + d / 2)) - + (d / 2) ≡⟨ cong (_- + (d / 2)) (IntP.pos-+-commute 1 (d / 2 + d / 2)) ⟩
+ 1 + + (d / 2 + d / 2) - + (d / 2) ≡⟨ cong (λ x → + 1 + x - + (d / 2)) (IntP.pos-+-commute (d / 2) (d / 2)) ⟩
+ 1 + + (d / 2) + + (d / 2) - + (d / 2) ≡⟨ solve 1 (λ x → (con 1ℤ) :+ (x :+ x) :- x := x :+ con 1ℤ) refl (+ (d / 2)) ⟩
+ (d / 2) + 1ℤ ∎
where
open +-*-Solver
open PE.≡-Reasoning
-- Goal 5.
step5 : let -_ = λ x -> - (+ x) in
+ (∣ d ∣ / 2) - d ≡ - (∣ d ∣ / 2) ⊎ d - + (∣ d ∣ / 2) ≡ + (∣ d ∣ / 2) + 1ℤ
step5 with step5-nat
... | inj₁ x = inj₁ (step5a ∣ d ∣ x)
... | inj₂ y = inj₂ (step5b ∣ d ∣ y)
-- Step 6. ∣ d / 2 - d ∣ ≡ d / 2 or ∣ d / 2 - d ∣ ≡ d / 2 + 1
step6 : let -_ = λ x -> - (+ x) in
∣ + (∣ d ∣ / 2) - d ∣ ≡ ∣ d ∣ / 2 ⊎ ∣ d - + (∣ d ∣ / 2) ∣ ≡ ∣ d ∣ / 2 + 1
step6 with step5
... | inj₁ x rewrite x = inj₁ (trans ∣-d/2∣≡∣d/2∣ ∣d/2∣≡d/2)
where
∣-d/2∣≡∣d/2∣ : ∣ - (+ (∣ d ∣ / 2)) ∣ ≡ ∣ + (∣ d ∣ / 2) ∣
∣-d/2∣≡∣d/2∣ = IntP.∣-i∣≡∣i∣ (+ (∣ d ∣ / 2))
∣d/2∣≡d/2 : ∣ + (∣ d ∣ / 2) ∣ ≡ (∣ d ∣ / 2)
∣d/2∣≡d/2 = refl
... | inj₂ y rewrite y = inj₂ claim
where
claim : ∣ + (∣ d ∣ / 2) + 1ℤ ∣ ≡ ∣ d ∣ / 2 + 1
claim = begin
∣ + (∣ d ∣ / 2) + 1ℤ ∣ ≡⟨ refl ⟩
∣ + ((∣ d ∣ / 2) + 1) ∣ ≡⟨ refl ⟩
∣ d ∣ / 2 + 1 ∎
where
open PE.≡-Reasoning
-- Step 7. d / 2 > ∣ n % d - d ∣ or d / 2 + 1 > ∣ n % d - d ∣
step7 : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 ⊎ ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 + 1
step7 with step6
... | inj₁ x = inj₁ claim
where
claim : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ step4 ⟩
∣ + (∣ d ∣ / 2) - d ∣ ≡⟨ x ⟩
∣ d ∣ / 2 ∎
where
open NatP.≤-Reasoning
... | inj₂ y = inj₂ claim
where
claim : ∣ + (n mod d) - d ∣ < ∣ d ∣ / 2 + 1
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ step4 ⟩
∣ + (∣ d ∣ / 2) - d ∣ ≡⟨ IntP.∣i-j∣≡∣j-i∣ (+ (∣ d ∣ / 2)) d ⟩
∣ d - + (∣ d ∣ / 2) ∣ ≡⟨ y ⟩
∣ d ∣ / 2 + 1 ∎
where
open NatP.≤-Reasoning
-- Step 8. d / 2 ≥ ∣ n % d - d ∣
step8 : ∣ + (n mod d) - d ∣ ≤ ∣ d ∣ / 2
step8 with step7
... | inj₁ x = NatP.<⇒≤ x
... | inj₂ y = m<sucn⇒m≤n claim
where
m<sucn⇒m≤n : ∀ {m n : ℕ} → m < suc n → m ≤ n
m<sucn⇒m≤n (s≤s le) = le
lemma-+1 : ∀ {a : ℕ} -> a + 1 ≡ suc a
lemma-+1 {zero} = refl
lemma-+1 {suc a} = cong suc (lemma-+1 {a})
claim : ∣ + (n mod d) - d ∣ < suc (∣ d ∣ / 2)
claim = begin-strict
∣ + (n mod d) - d ∣ <⟨ y ⟩
∣ d ∣ / 2 + 1 ≡⟨ lemma-+1 ⟩
suc (∣ d ∣ / 2) ∎
where
open NatP.≤-Reasoning
claim : ∣ r ∣ ≤ ∣ d ∣ / 2
claim = step8
-- This case is solved by recursive call with argument n and - d.
euc-rank' n d@(-[1+ e ]) n0 with n mod d ≤? ∣ d ∣ / 2 | euc-rank' n (+[1+ e ]) (λ {()})
... | yes pr | hyp = pr
... | no ¬p | hyp = hyp
-- We can relax the estimation.
euc-rank'' : ∀ (n d : ℤ) (n0 : ¬ d ≡ 0ℤ) ->
let r = mod' n d n0 in let q = div' n d n0 in
∣ r ∣ < ∣ d ∣
euc-rank'' n d n0 = let r = mod' n d n0 in let q = div' n d n0 in
begin-strict
∣ r ∣ ≤⟨ euc-rank' n d n0 ⟩
∣ d ∣ / 2 <⟨ aux ∣ d ∣ ∣d∣≠0 ⟩
∣ d ∣ ∎
where
open NatP.≤-Reasoning
aux : ∀ n -> ¬ n ≡ 0 -> n / 2 < n
aux zero n0 with n0 refl
... | ()
aux (suc n) n0 = NDM.m/n<m (suc n) 2 (s≤s (s≤s z≤n))
∣d∣≠0 : ¬ ∣ d ∣ ≡ 0
∣d∣≠0 x = n0 (IntP.∣i∣≡0⇒i≡0 x)
-- ----------------------------------------------------------------------
-- Alternative Euclidean Structure
-- The newly defined div' and mod' together with euc-eq' and
-- euc-rank'' make ℤ an Euclidean Domain with more precise estimate on
-- the rank of the reminder.
open import Integer.EucDomain
using (+-*-isEuclideanDomain ; +-*-euclideanDomain)
import EuclideanDomain
open EuclideanDomain.Bundles
-- We update the old Euclidean structure in EucDomain.
+-*-isEuclideanDomain' = record +-*-isEuclideanDomain
{ div = div'
; mod = mod'
; euc-eq = euc-eq'
; euc-rank = euc-rank''
}
-- Bundle.
+-*-euclideanDomain' : EuclideanDomainBundle _ _
+-*-euclideanDomain' = record
{ isEuclideanDomain = +-*-isEuclideanDomain'
}
-- ----------------------------------------------------------------------
-- Make a new instance for DivMod ℤ
-- Translation between two nonzeros.
nz : ∀ (x : ℤ) -> .{{NonZero x}} -> ¬ x ≡ 0#
nz +[1+ n ] ()
-- We use the newly defined div and mod function.
instance
new-DMℤ : DivMod ℤ
new-DMℤ .NZT = NZTℤ
new-DMℤ ._/_ n d = div' n d (nz d)
new-DMℤ ._%_ n d = mod' n d (nz d)
| {
"alphanum_fraction": 0.4171656687,
"avg_line_length": 36.0196078431,
"ext": "agda",
"hexsha": "34678a23735c93bcd85c0bc75be53012962f5a4d",
"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": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "onestruggler/EucDomain",
"max_forks_repo_path": "Integer/EucDomain2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"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": "onestruggler/EucDomain",
"max_issues_repo_path": "Integer/EucDomain2.agda",
"max_line_length": 139,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7e268e8354065fde734c9c2d9998d2cfd4a21f71",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "onestruggler/EucDomain",
"max_stars_repo_path": "Integer/EucDomain2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7131,
"size": 16533
} |
module _ where
data Nat : Set where
postulate
C Q : Set → Set
unQ : ∀ {A} → Q A → A
instance
CQ : C (Q Nat)
theC : {A : Set} {{_ : C A}} → A
-- We shouldn't solve this based on CQ being the only instance available for Q _.
dont-solve : _
dont-solve = unQ theC
| {
"alphanum_fraction": 0.5992779783,
"avg_line_length": 16.2941176471,
"ext": "agda",
"hexsha": "89730068ca93e9a18f713e35b0df9d09b6810b40",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/NonRigidlyConstrained.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/NonRigidlyConstrained.agda",
"max_line_length": 81,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/NonRigidlyConstrained.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": 99,
"size": 277
} |
{-
Holey congruence where congruence is limited to specific functions.
To use, open the module `AutoCong` with a database that maps function names to
congruences for those functions.
-}
module Holes.Cong.Limited where
open import Holes.Prelude
open import Holes.Term
open Holes.Prelude public using (quote-term)
private
find : ∀ {a} {A : Set a} → (A → Bool) → List A → Maybe A
find p [] = nothing
find p (x ∷ xs) = if p x then just x else find p xs
last2 : ∀ {ℓ} {A : Set ℓ} → List A → Maybe (A × A)
last2 (x ∷ y ∷ []) = just (x , y)
last2 (x ∷ xs) = last2 xs
last2 _ = nothing
getArgs : Term → Maybe (List (Arg Term))
getArgs (con _ args) = just args
getArgs (def _ args) = just args
getArgs (var _ args) = just args
getArgs _ = nothing
decomposeEquiv : Term → Maybe (Term × Term)
decomposeEquiv tm =
getArgs tm >>= λ args →
last2 args >>=² λ x y →
return (getArg x , getArg y)
Congruence = Name
ArgPlace = ℕ
private
data CongErr : Set where
termsDontMatch : ℕ → Term → HoleyTerm → CongErr
typeNotEquivalence noHole : CongErr
appliedVar : (varIdx : ℕ) (goalLhs : Term) → CongErr
metaOnPath piOnPath lamOnPath sortOnPath : CongErr
noCongAvailable : Name → ArgPlace → CongErr
holeyErr : (goalLhs : Term) (holeyErr : HoleyErr) → CongErr
fillErrLhs : Term → CongErr → CongErr
fillErrLhs lhs (appliedVar v _) = appliedVar v lhs
fillErrLhs lhs e = e
natToTerm : ℕ → Term
natToTerm zero = con (quote zero) []
natToTerm (suc n) = con (quote suc) (basicArg (natToTerm n) ∷ [])
fillHoleyHole : HoleyTerm → Term
fillHoleyHole = fillHoley′ (λ _ → quote-term ⌞_⌟)
printCongErr : CongErr → List ErrorPart
printCongErr (termsDontMatch depth original holey)
= strErr "There was an attempt to create a path based on non-matching terms"
∷ termErr original
∷ strErr "and"
∷ termErr (fillHoleyHole holey)
∷ strErr "at depth"
∷ termErr (natToTerm depth)
∷ strErr "This is a bug in the holes library!"
∷ []
printCongErr typeNotEquivalence = strErr "The goal type does not appear to be a binary relation." ∷ []
printCongErr noHole = strErr "There is no hole the goal LHS." ∷ []
printCongErr (appliedVar v goalLhs)
= strErr "Variable applications on the path to the hole are not supported. The applied variable was"
∷ termErr (var v [])
∷ strErr "and the goal LHS was:"
∷ termErr goalLhs
∷ []
printCongErr metaOnPath = strErr "Metavariables in the goal LHS are not supported." ∷ []
printCongErr piOnPath = strErr "Pi types in the goal LHS are not supported." ∷ []
printCongErr lamOnPath = strErr "Lambdas in the goal LHS are not supported." ∷ []
printCongErr sortOnPath = strErr "Sorts in the goal LHS are not supported." ∷ []
printCongErr (noCongAvailable nm argPlace)
= strErr "No congruence available for function"
∷ nameErr nm
∷ strErr "at required argument place, index"
∷ termErr (natToTerm argPlace)
∷ []
printCongErr (holeyErr goalLhs h) = printHoleyErr goalLhs h
printCongErrs : List CongErr → List ErrorPart
printCongErrs (e ∷ []) = printCongErr e
printCongErrs es = strErr "One of these errors happened:\n" ∷ (intercalate (strErr ";\n" ∷ []) ∘ map printCongErr) es
data HolePath : Set where
hole : HolePath
app : (nm : Name) (index : ℕ) (allArgs : List (Arg Term)) → HolePath → HolePath
module AutoCong (database : List (Name × ArgPlace × Congruence)) where
private
findCong : Name → ArgPlace → Maybe Congruence
findCong nm argPlace =
proj₂ ∘ proj₂ <$>
find ((λ { (nm′ , argPlace′ , _) →
(nm =Name? nm′) ∧
(argPlace =ℕ? argPlace′) }))
database
-- Tries to apply the given function to each element of the list, and
-- returns the first successful result. If none of the results are
-- successful, accumulates the errors using the error monoid.
findOk : ∀ {a e r} {A : Set a} {E : Set e} {{errMonoid : RawMonoid E}} {R : Set r} → (ℕ → A → Result E R) → List A → Result E R
findOk {A = A}{E}{R} = go 0
where
go : ℕ → (ℕ → A → Result E R) → List A → Result E R
go i f [] = err mempty
go i f (x ∷ xs) with f i x
... | ok y = ok y
... | err e₁ with go (1 + i) f xs
... | ok y = ok y
... | err e₂ = err (e₁ <> e₂)
zipArglists : ∀ {A B : Set} → List (Arg A) → List (Arg B) → List (Arg (A × B))
zipArglists xs ys = map (λ { (arg i x , arg _ y) → arg i (x , y)}) (zip xs ys)
mutual
findHole : ℕ → List (Arg (Term × HoleyTerm)) → Result (List CongErr) (ℕ × HolePath)
findHole depth = findOk (λ { n (arg i (t , h)) → (n ,_) <$> buildPath depth t h })
{-# TERMINATING #-}
buildPath : ℕ → Term → HoleyTerm → Result (List CongErr) HolePath
buildPath depth original (hole _) = return hole
buildPath depth (lit _) (lit l) = err (noHole ∷ [])
buildPath depth unknown unknown = err (noHole ∷ [])
buildPath depth (var _ _) (var x _) = err (appliedVar x unknown ∷ [])
buildPath depth (con _ originalArgs) (con nm args) =
findHole (suc depth) (zipArglists originalArgs args) >>=² λ argPlace nextPath →
return (app nm argPlace originalArgs nextPath)
buildPath depth (def _ originalArgs) (def nm args) =
findHole (suc depth) (zipArglists originalArgs args) >>=² λ argPlace nextPath →
return (app nm argPlace originalArgs nextPath)
buildPath depth (lam _ _) (lam _ _) = err (lamOnPath ∷ [])
buildPath depth (lam _ _) (pi _ _) = err (piOnPath ∷ [])
buildPath depth (lam _ _) (meta _ _) = err (metaOnPath ∷ [])
buildPath depth (agda-sort _) (agda-sort _) = err (sortOnPath ∷ [])
buildPath depth original holey = err (termsDontMatch depth original holey ∷ [])
pathToCong : HolePath → Term → Result (List CongErr) Term
pathToCong hole eq = return eq
pathToCong (app nm argPlace allArgs hp) eq =
liftMaybe (noCongAvailable nm argPlace ∷ []) (findCong nm argPlace) >>= λ cong →
pathToCong hp eq >>= λ rec →
return (def cong (allArgs ++ (basicArg rec ∷ [])))
fillErrHoley : HoleyTerm → CongErr → CongErr
fillErrHoley = fillErrLhs ∘ fillHoleyHole
autoCong : Term → Term → RTC (List CongErr) ⊤
autoCong equiv goal =
-- Infer the type of the goal
liftTC (inferType goal) >>= λ goalType →
-- Try to decompose the goal type into a left and right hand side.
liftMaybe (typeNotEquivalence ∷ []) (decomposeEquiv goalType) >>=² λ goalLhs goalRhs →
-- Try to convert the goal LHS to a holey term.
liftResult′ (singleton ∘ holeyErr goalLhs) (termToHoley goalLhs) >>= λ holeyLhs →
-- Try to build a path to a hole in the LHS.
liftResult′ (map (fillErrHoley holeyLhs)) (buildPath 0 goalLhs holeyLhs) >>= λ lhsPath →
-- Try to convert the path to a chain of congruence applications.
liftResult (pathToCong lhsPath equiv) >>= λ congTerm →
-- Try to unify the result with the goal to complete the proof.
liftTC (unify congTerm goal)
autoCongDebug : Term → Term → RTC (List CongErr) ⊤
autoCongDebug equiv goal =
liftTC (inferType goal) >>= λ goalType →
liftMaybe (singleton typeNotEquivalence) (decomposeEquiv goalType) >>=² λ goalLhs goalRhs →
liftResult′ (singleton ∘ holeyErr goalLhs) (termToHoley goalLhs) >>= λ holeyLhs →
let showArgs = map (termErr ∘ getArg) ∘ getArglist
in typeError′ (showArgs goalLhs ++ (strErr "and" ∷ showArgs (fillHoleyHole holeyLhs))) >>= λ (_ : ⊤) →
liftResult′ (map (fillErrHoley holeyLhs)) (buildPath 0 goalLhs holeyLhs) >>= λ lhsPath →
liftResult (pathToCong lhsPath equiv) >>= λ congTerm →
liftTC (unify congTerm goal)
macro
cong! : Term → Term → TC ⊤
cong! equiv = runRtcOrTypeError printCongErrs ∘ autoCong equiv
-- debug version
cong!Debug : Term → Term → TC ⊤
cong!Debug equiv = runRtcOrTypeError printCongErrs ∘ autoCongDebug equiv
| {
"alphanum_fraction": 0.6413165441,
"avg_line_length": 41.1333333333,
"ext": "agda",
"hexsha": "c9f15bf5f6c80a9669e26b02bb7dcbe71ce34f28",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-02-02T18:57:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-01-27T14:57:39.000Z",
"max_forks_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-holes",
"max_forks_repo_path": "src/Holes/Cong/Limited.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_issues_repo_issues_event_max_datetime": "2020-08-31T20:58:33.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-16T10:47:58.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-holes",
"max_issues_repo_path": "src/Holes/Cong/Limited.agda",
"max_line_length": 131,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "b5537c29e69febd7e89580398fac38d619aab3b4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-holes",
"max_stars_repo_path": "src/Holes/Cong/Limited.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-03T15:02:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-01-28T10:56:46.000Z",
"num_tokens": 2536,
"size": 8021
} |
open import Prelude
open import Nat
open import dynamics-core
open import contexts
open import contraction
open import weakening
open import exchange
open import lemmas-disjointness
open import binders-disjoint-checks
module lemmas-subst-ta where
-- this is what makes the binders-unique assumption below good enough: it
-- tells us that we can pick fresh variables
mutual
binders-envfresh : ∀{Δ Γ Γ' y σ} →
Δ , Γ ⊢ σ :s: Γ' →
y # Γ →
unbound-in-σ y σ →
binders-unique-σ σ →
envfresh y σ
binders-envfresh {Γ' = Γ'} {y = y} (STAId x) apt unbound unique with ctxindirect Γ' y
binders-envfresh {Γ' = Γ'} {y = y} (STAId x₁) apt unbound unique | Inl x = abort (somenotnone (! (x₁ y (π1 x) (π2 x)) · apt))
binders-envfresh (STAId x₁) apt unbound unique | Inr x = EFId x
binders-envfresh {Γ = Γ} {y = y} (STASubst {y = z} subst x₁) apt (UBσSubst x₂ unbound neq) (BUσSubst zz x₃ x₄) =
EFSubst (binders-fresh {y = y} x₁ zz x₂ apt)
(binders-envfresh subst (apart-extend1 Γ neq apt) unbound x₃)
neq
binders-fresh : ∀{Δ Γ d2 τ y} →
Δ , Γ ⊢ d2 :: τ →
binders-unique d2 →
unbound-in y d2 →
Γ y == None →
fresh y d2
binders-fresh TANum BUHole UBNum apt = FNum
binders-fresh {y = y} (TAVar {x = x} x₁) BUVar UBVar apt with natEQ y x
binders-fresh (TAVar x₂) BUVar UBVar apt | Inl refl = abort (somenotnone (! x₂ · apt))
binders-fresh (TAVar x₂) BUVar UBVar apt | Inr x₁ = FVar x₁
binders-fresh {y = y} (TALam {x = x} x₁ wt) bu2 ub apt with natEQ y x
binders-fresh (TALam x₂ wt) bu2 (UBLam2 x₁ ub) apt | Inl refl = abort (x₁ refl)
binders-fresh {Γ = Γ} (TALam {x = x} x₂ wt) (BULam bu2 x₃) (UBLam2 x₄ ub) apt | Inr x₁ = FLam x₁ (binders-fresh wt bu2 ub (apart-extend1 Γ x₄ apt))
binders-fresh (TAAp wt wt₁) (BUAp bu2 bu3 x) (UBAp ub ub₁) apt = FAp (binders-fresh wt bu2 ub apt) (binders-fresh wt₁ bu3 ub₁ apt)
binders-fresh (TAEHole x₁ x₂) (BUEHole x) (UBHole x₃) apt = FHole (binders-envfresh x₂ apt x₃ x )
binders-fresh (TANEHole x₁ wt x₂) (BUNEHole bu2 x) (UBNEHole x₃ ub) apt = FNEHole (binders-envfresh x₂ apt x₃ x) (binders-fresh wt bu2 ub apt)
binders-fresh (TACast wt x₁) (BUCast bu2) (UBCast ub) apt = FCast (binders-fresh wt bu2 ub apt)
binders-fresh (TAFailedCast wt x x₁ x₂) (BUFailedCast bu2) (UBFailedCast ub) apt = FFailedCast (binders-fresh wt bu2 ub apt)
binders-fresh (TAInl wt) (BUInl bu) (UBInl ub) apt = FInl (binders-fresh wt bu ub apt)
binders-fresh (TAInr wt) (BUInr bu) (UBInr ub) apt = FInr (binders-fresh wt bu ub apt)
binders-fresh {Γ = Γ} (TACase wt x wt₁ x₁ wt₂) (BUCase bu bu₁ bu₂ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) (UBCase ub x₁₁ ub₁ x₁₂ ub₂) apt = FCase (binders-fresh wt bu ub apt) x₁₁ (binders-fresh wt₁ bu₁ ub₁ (apart-extend1 Γ x₁₁ apt)) x₁₂ (binders-fresh wt₂ bu₂ ub₂ (apart-extend1 Γ x₁₂ apt))
binders-fresh (TAPlus wt wt₁) (BUPlus bu bu₁ x) (UBPlus ub ub₁) apt = FPlus (binders-fresh wt bu ub apt) (binders-fresh wt₁ bu₁ ub₁ apt)
binders-fresh (TAPair wt wt₁) (BUPair bu bu₁ x) (UBPair ub ub₁) apt = FPair (binders-fresh wt bu ub apt) (binders-fresh wt₁ bu₁ ub₁ apt)
binders-fresh (TAFst wt) (BUFst bu) (UBFst ub) apt = FFst (binders-fresh wt bu ub apt)
binders-fresh (TASnd wt) (BUSnd bu) (UBSnd ub) apt = FSnd (binders-fresh wt bu ub apt)
-- the substition lemma for preservation
lem-subst : ∀{Δ Γ x τ1 d1 τ d2} →
x # Γ →
binders-disjoint d1 d2 →
binders-unique d2 →
Δ , Γ ,, (x , τ1) ⊢ d1 :: τ →
Δ , Γ ⊢ d2 :: τ1 →
Δ , Γ ⊢ [ d2 / x ] d1 :: τ
lem-subst apt bd bu2 (TANum) wt = TANum
lem-subst apt (BDPlus bd bd₁) bu2 (TAPlus wt1 wt2) wt3 = TAPlus (lem-subst apt bd bu2 wt1 wt3) (lem-subst apt bd₁ bu2 wt2 wt3)
lem-subst {x = x} apt bd bu2 (TAVar {x = x'} x₂) wt2 with natEQ x' x
... | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl with someinj x₂
... | refl = wt2
lem-subst {x = x} apt bd bu2 (TAVar {x = x'} x₂) wt2 | Inr x'≠x with natEQ x x'
... | Inl refl = abort (x'≠x refl)
... | Inr x'≠x = TAVar x₂
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d2 = d2} x#Γ (BDLam bd bd') bu2 (TALam {x = y} {τ1 = τ1} {d = d} {τ2 = τ2} x₂ wt1) wt2 with natEQ y x
... | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone x₂)
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d2 = d2} x#Γ (BDLam bd bd') bu2 (TALam {x = y} {τ1 = τ1} {d = d} {τ2 = τ2} x₂ wt1) wt2 | Inr y≠x with natEQ x y
... | Inl refl = abort (y≠x refl)
... | Inr x≠y = TALam x₂ (lem-subst (apart-extend1 Γ x≠y x#Γ) bd bu2 (exchange-ta-Γ x≠y wt1) (weaken-ta (binders-fresh wt2 bu2 bd' x₂) wt2))
lem-subst apt (BDAp bd bd₁) bu3 (TAAp wt1 wt2) wt3 = TAAp (lem-subst apt bd bu3 wt1 wt3) (lem-subst apt bd₁ bu3 wt2 wt3)
lem-subst apt bd bu2 (TAEHole inΔ sub) wt2 = TAEHole inΔ (STASubst sub wt2)
lem-subst apt (BDNEHole x₁ bd) bu2 (TANEHole x₃ wt1 x₄) wt2 = TANEHole x₃ (lem-subst apt bd bu2 wt1 wt2) (STASubst x₄ wt2)
lem-subst apt (BDCast bd) bu2 (TACast wt1 x₁) wt2 = TACast (lem-subst apt bd bu2 wt1 wt2) x₁
lem-subst apt (BDFailedCast bd) bu2 (TAFailedCast wt1 x₁ x₂ x₃) wt2 = TAFailedCast (lem-subst apt bd bu2 wt1 wt2) x₁ x₂ x₃
lem-subst apt (BDInl bd) bu (TAInl wt1) wt2 = TAInl (lem-subst apt bd bu wt1 wt2)
lem-subst apt (BDInr bd) bu (TAInr wt1) wt2 = TAInr (lem-subst apt bd bu wt1 wt2)
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d1 = .(case _ _ _ _ _)} {d2 = d2} apt (BDCase bd x₁ bd₁ x₂ bd₂) bu (TACase {d = d} {τ1 = τ1} {τ2 = τ2} {x = y} {y = z} wt1 x₃ wt3 x₄ wt4) wt2
with natEQ y x | natEQ z x
... | Inl refl | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone x₄)
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d1 = .(case _ _ _ _ _)} {d2 = d2} apt (BDCase bd x₁ bd₁ x₂ bd₂) bu (TACase {d = d} {τ1 = τ1} {τ2 = τ2} {x = y} {y = z} wt1 x₃ wt3 x₄ wt4) wt2 | Inl refl | Inr z≠x with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone x₃)
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d1 = .(case _ _ _ _ _)} {d2 = d2} apt (BDCase bd x₁ bd₁ x₂ bd₂) bu (TACase {d = d} {τ1 = τ1} {τ2 = τ2} {x = y} {y = z} wt1 x₃ wt3 x₄ wt4) wt2 | Inr y≠x | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone x₄)
lem-subst {Δ = Δ} {Γ = Γ} {x = x} {d1 = .(case _ _ _ _ _)} {d2 = d2} apt (BDCase bd x₁ bd₁ x₂ bd₂) bu (TACase {d = d} {τ1 = τ1} {τ2 = τ2} {x = y} {y = z} wt1 x₃ wt3 x₄ wt4) wt2 | Inr y≠x | Inr z≠x with natEQ x z
... | Inl refl = abort (z≠x refl)
... | Inr x≠z with natEQ x y
... | Inl refl = abort (y≠x refl)
... | Inr x≠y = TACase (lem-subst apt bd bu wt1 wt2) x₃ (lem-subst (apart-extend1 Γ x≠y apt) bd₁ bu (exchange-ta-Γ x≠y wt3) (weaken-ta (binders-fresh wt2 bu x₁ x₃) wt2)) x₄ (lem-subst (apart-extend1 Γ x≠z apt) bd₂ bu (exchange-ta-Γ x≠z wt4) (weaken-ta (binders-fresh wt2 bu x₂ x₄) wt2))
lem-subst apt (BDPair bd bd₁) bu (TAPair wt1 wt3) wt2 = TAPair (lem-subst apt bd bu wt1 wt2) (lem-subst apt bd₁ bu wt3 wt2)
lem-subst apt (BDFst bd) bu (TAFst wt1) wt2 = TAFst (lem-subst apt bd bu wt1 wt2)
lem-subst apt (BDSnd bd) bu (TASnd wt1) wt2 = TASnd (lem-subst apt bd bu wt1 wt2)
lem-subst-cast-sta : ∀{Δ Γ x τ1 τ2 σ Γ'} →
x # Γ →
τ1 ~ τ2 →
Δ , Γ ,, (x , τ2) ⊢ σ :s: Γ' →
Δ , Γ ,, (x , τ1) ⊢ Subst (X x ⟨ τ1 ⇒ τ2 ⟩) x σ :s: Γ'
lem-subst-cast-sta {Γ = Γ} {x = x} {τ1 = τ1} {τ2 = τ2} {Γ' = Γ'} x#Γ con (STAId sub) = STASubst (STAId Γ'⊆) (TACast (TAVar (ctx-top Γ x τ1 x#Γ)) con)
where
Γ'⊆ : (y : Nat) (τ : htyp) → (y , τ) ∈ Γ' → (y , τ) ∈ (Γ ,, (x , τ1) ,, (x , τ2))
Γ'⊆ y τ y∈Γ' with lem-dom-union {Δ1 = ■(x , τ2)} {Δ2 = Γ} (sub y τ y∈Γ')
... | Inl y∈x with natEQ x y
... | Inr x≠y = abort (somenotnone (! y∈x))
... | Inl refl = y∈x
Γ'⊆ y τ y∈Γ' | Inr y∈Γ with natEQ x y
... | Inl refl = abort (somenotnone ((! y∈Γ) · x#Γ))
... | Inr x≠y with natEQ x y
... | Inl refl = abort (x≠y refl)
... | Inr x≠y' = y∈Γ
lem-subst-cast-sta {Δ = Δ} {Γ = Γ} {x = x} {τ1 = τ1} {τ2 = τ2} {Γ' = Γ'} x#Γ con (STASubst {σ = σ} {y = y} {d = d} {τ = τ} wsta wt) = STASubst (STASubst (tr (λ c → Δ , c ,, (y , τ) ⊢ σ :s: Γ') (! (update Γ x τ1 τ2)) wsta) (tr (λ c → Δ , c ⊢ d :: τ) (! (update Γ x τ1 τ2)) wt)) (TACast (TAVar (ctx-top Γ x τ1 x#Γ)) con)
lem-subst-cast-ta : ∀{Δ Γ d x τ1 τ2 τ} →
x # Γ →
binders-unique d →
τ1 ~ τ2 →
Δ , Γ ,, (x , τ2) ⊢ d :: τ →
Δ , Γ ,, (x , τ1) ⊢ [ (X x ⟨ τ1 ⇒ τ2 ⟩) / x ] d :: τ
lem-subst-cast-ta apt bu con TANum = TANum
lem-subst-cast-ta apt (BUPlus bu bu₁ x) con (TAPlus wt wt₁) = TAPlus (lem-subst-cast-ta apt bu con wt) (lem-subst-cast-ta apt bu₁ con wt₁)
lem-subst-cast-ta {Γ = Γ} {x = x} {τ1 = τ1} {τ2 = τ2} apt bu con (TAVar {x = x'} x₁)
with natEQ x x'
... | Inl refl with natEQ x' x
... | Inr x'≠x = abort (x'≠x refl)
... | Inl refl with Γ x
... | None with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl with someinj x₁
... | refl = TACast (TAVar (x∈∪l (■ (x , τ1)) Γ x τ1 (x∈■ x τ1))) con
lem-subst-cast-ta {Γ = Γ} {x = x} {τ1 = τ1} {τ2 = τ2} apt bu con (TAVar {x = x} x₁) | Inl refl | Inl refl | Some t with someinj x₁
... | refl = abort (somenotnone apt)
lem-subst-cast-ta {Γ = Γ} {x = x} {τ1 = τ1} {τ2 = τ2} {τ = τ} apt bu con (TAVar {x = x'} x₁) | Inr x≠x' with natEQ x' x
... | Inl refl = abort (x≠x' refl)
... | Inr x'≠x = TAVar (x∈∪r (■(x , τ1)) Γ x' τ x₁ (apart-singleton (λ refl → abort (x'≠x refl))))
lem-subst-cast-ta {Δ = Δ} {Γ = Γ} {x = x} {τ = τ1 ==> τ3} apt (BULam bu x₁) con (TALam {x = y} x₂ wt)
with natEQ x y
... | Inl refl = abort (somenotnone x₂)
... | Inr x≠y with natEQ y x
... | Inl refl = abort (x≠y refl)
... | Inr y≠x = TALam (apart-extend1 Γ y≠x x₂) (exchange-ta-Γ y≠x (lem-subst-cast-ta (apart-extend1 Γ x≠y apt) bu con (exchange-ta-Γ x≠y wt)))
lem-subst-cast-ta {Γ = Γ} apt (BUAp bu bu₁ x) con (TAAp wt wt₁) = TAAp (lem-subst-cast-ta {Γ = Γ} apt bu con wt) (lem-subst-cast-ta {Γ = Γ} apt bu₁ con wt₁)
lem-subst-cast-ta {Γ = Γ} apt (BUInl bu) con (TAInl wt) = TAInl (lem-subst-cast-ta {Γ = Γ} apt bu con wt)
lem-subst-cast-ta {Γ = Γ} apt (BUInr bu) con (TAInr wt) = TAInr (lem-subst-cast-ta {Γ = Γ} apt bu con wt)
lem-subst-cast-ta {x = x} apt (BUCase bu bu₁ bu₂ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) con (TACase {x = y} {y = z} wt apty wt₁ aptz wt₂) with natEQ y x | natEQ z x
... | Inl refl | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone aptz)
lem-subst-cast-ta {x = x} apt (BUCase bu bu₁ bu₂ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) con (TACase {x = y} {y = z} wt apty wt₁ aptz wt₂) | Inl refl | Inr z≠x with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone apty)
lem-subst-cast-ta {x = x} apt (BUCase bu bu₁ bu₂ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) con (TACase {x = y} {y = z} wt apty wt₁ aptz wt₂) | Inr y≠x | Inl refl with natEQ x x
... | Inr x≠x = abort (x≠x refl)
... | Inl refl = abort (somenotnone aptz)
lem-subst-cast-ta {Γ = Γ} {x = x} apt (BUCase bu bu₁ bu₂ x₂ x₃ x₄ x₅ x₆ x₇ x₈ x₉ x₁₀) con (TACase {x = y} {y = z} wt apty wt₁ aptz wt₂) | Inr y≠x | Inr z≠x with natEQ x z
... | Inl refl = abort (z≠x refl)
... | Inr x≠z with natEQ x y
... | Inl refl = abort (y≠x refl)
... | Inr x≠y = TACase (lem-subst-cast-ta apt bu con wt) (apart-extend1 Γ y≠x apty) (exchange-ta-Γ y≠x (lem-subst-cast-ta (apart-extend1 Γ x≠y apt) bu₁ con (exchange-ta-Γ x≠y wt₁))) (apart-extend1 Γ z≠x aptz) (exchange-ta-Γ z≠x (lem-subst-cast-ta (apart-extend1 Γ x≠z apt) bu₂ con (exchange-ta-Γ x≠z wt₂)))
lem-subst-cast-ta apt (BUEHole x₂) con (TAEHole x x₁) = TAEHole x (lem-subst-cast-sta apt con x₁)
lem-subst-cast-ta apt (BUNEHole bu x₂) con (TANEHole x wt x₁) = TANEHole x (lem-subst-cast-ta apt bu con wt) (lem-subst-cast-sta apt con x₁)
lem-subst-cast-ta apt (BUCast bu) con (TACast wt x) = TACast (lem-subst-cast-ta apt bu con wt) x
lem-subst-cast-ta apt (BUFailedCast bu) con (TAFailedCast wt x x₁ x₂) = TAFailedCast (lem-subst-cast-ta apt bu con wt) x x₁ x₂
lem-subst-cast-ta apt (BUPair bu bu₁ x) con (TAPair wt wt₁) = TAPair (lem-subst-cast-ta apt bu con wt) (lem-subst-cast-ta apt bu₁ con wt₁)
lem-subst-cast-ta apt (BUFst bu) con (TAFst wt) = TAFst (lem-subst-cast-ta apt bu con wt)
lem-subst-cast-ta apt (BUSnd bu) con (TASnd wt) = TASnd (lem-subst-cast-ta apt bu con wt)
| {
"alphanum_fraction": 0.5657129743,
"avg_line_length": 73.0279329609,
"ext": "agda",
"hexsha": "6af44759371c2b1ba889cf209fb97157d29fb092",
"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": "lemmas-subst-ta.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": "lemmas-subst-ta.agda",
"max_line_length": 320,
"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": "lemmas-subst-ta.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5793,
"size": 13072
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.LoopSpaceCircle
open import homotopy.PinSn
open import homotopy.SphereEndomorphism
open import homotopy.SuspAdjointLoop
open import groups.FromSusp
open import groups.Int
open import groups.Pointed
open import groups.SuspAdjointLoop
open import groups.ToOmega
module groups.SphereEndomorphism where
⊙SphereS-endo-group-structure : ∀ n → GroupStructure (⊙Sphere-endo (S n))
⊙SphereS-endo-group-structure n = Susp⊙→-group-structure (⊙Sphere n) (⊙Sphere (S n))
{-
⊙LiftSphereS-endo-group-structure : ∀ {i} n → GroupStructure (⊙LiftSphere-endo {i} (S n))
⊙LiftSphereS-endo-group-structure {i} n =
LiftSusp⊙→-group-structure {j = i} (⊙Sphere n) (⊙Lift {j = i} (⊙Sphere (S n)))
⊙SphereS-endo-siso-⊙LiftSphereS-endo : ∀ {i} n →
⊙SphereS-endo-group-structure n ≃ᴳˢ ⊙LiftSphereS-endo-group-structure {i} n
⊙SphereS-endo-siso-⊙LiftSphereS-endo {i} n = ≃-to-≃ᴳˢ
⊙Lift-fmap-equiv
(λ f g → ap (_⊙∘ ⊙pinch (⊙Sphere n) ⊙∘ ⊙lower {j = i}) $ ! $
⊙∨-rec (⊙Lift-fmap f) (⊙Lift-fmap g) ⊙∘ ⊙∨-fmap ⊙lift ⊙lift
=⟨ ⊙λ= $ ⊙∨-rec-fmap (⊙Lift-fmap f) (⊙Lift-fmap g) ⊙lift ⊙lift ⟩
⊙∨-rec (⊙lift ⊙∘ f) (⊙lift ⊙∘ g)
=⟨ ! $ ⊙λ= $ ⊙∨-rec-post∘ ⊙lift f g ⟩
⊙lift ⊙∘ ⊙∨-rec f g
=∎)
-}
Trunc-⊙SphereS-endo-group : ∀ n → Group₀
Trunc-⊙SphereS-endo-group n = Trunc-Susp⊙→-group (⊙Sphere n) (⊙Sphere (S n))
{-
Trunc-⊙LiftSphereS-endo-group : ∀ {i} n → Group i
Trunc-⊙LiftSphereS-endo-group {i} n = Trunc-LiftSusp⊙→-group {j = i} (⊙Sphere n) (⊙Lift {j = i} (⊙Sphere (S n)))
-}
Trunc-⊙SphereS-endo-⊙group : ∀ n → ⊙Group₀
Trunc-⊙SphereS-endo-⊙group n = ⊙[ Trunc-⊙SphereS-endo-group n , [ ⊙idf _ ] ]ᴳ
{-
Trunc-⊙LiftSphereS-endo-⊙group : ∀ {i} n → ⊙Group i
Trunc-⊙LiftSphereS-endo-⊙group {i} n = ⊙[ Trunc-⊙LiftSphereS-endo-group {i = i} n , [ ⊙idf _ ] ]ᴳ
-}
Trunc-⊙S¹-endo-group-iso-ℤ : Trunc-⊙SphereS-endo-group 0 ≃ᴳ ℤ-group
Trunc-⊙S¹-endo-group-iso-ℤ =
Trunc-⊙SphereS-endo-group 0
≃ᴳ⟨ Trunc-Susp⊙→-iso-Trunc-⊙→Ω ⊙Bool ⊙S¹ ⟩
Trunc-⊙→Ω-group ⊙Bool ⊙S¹
≃ᴳ⟨ Trunc-⊙Bool→Ω-iso-π₁ ⊙S¹ ⟩
πS 0 ⊙S¹
≃ᴳ⟨ πS-SphereS-iso-ℤ 0 ⟩
ℤ-group
≃ᴳ∎
Trunc-⊙S¹-endo-⊙group-iso-⊙ℤ : Trunc-⊙SphereS-endo-⊙group 0 ⊙≃ᴳ ℤ-⊙group
Trunc-⊙S¹-endo-⊙group-iso-⊙ℤ = Trunc-⊙S¹-endo-group-iso-ℤ ,
equiv-adj' ΩS¹-equiv-ℤ {a = ap (idf _) loop} {b = 1} (ap-idf loop)
Trunc-⊙S¹-endo-⊙group-is-infinite-cyclic : is-infinite-cyclic (Trunc-⊙SphereS-endo-⊙group 0)
Trunc-⊙S¹-endo-⊙group-is-infinite-cyclic =
isomorphism-preserves'-infinite-cyclic Trunc-⊙S¹-endo-⊙group-iso-⊙ℤ ℤ-is-infinite-cyclic
Trunc-⊙SphereS-endo-Susp-fmap-iso :
∀ n → Trunc-⊙SphereS-endo-group n ≃ᴳ Trunc-⊙SphereS-endo-group (S n)
Trunc-⊙SphereS-endo-Susp-fmap-iso n =
Trunc-group-fmap (Susp⊙→-Susp-fmap-shom (⊙Sphere n) (⊙Sphere (S n))) ,
Trunc-⊙SphereS-endo-Susp-is-equiv n
Trunc-⊙SphereS-endo-Susp-fmap-⊙iso :
∀ n → Trunc-⊙SphereS-endo-⊙group n ⊙≃ᴳ Trunc-⊙SphereS-endo-⊙group (S n)
Trunc-⊙SphereS-endo-Susp-fmap-⊙iso n =
Trunc-⊙SphereS-endo-Susp-fmap-iso n , ap [_] (⊙Susp-fmap-idf (⊙Sphere (S n)))
Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic : ∀ n → is-infinite-cyclic (Trunc-⊙SphereS-endo-⊙group n)
Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic O = Trunc-⊙S¹-endo-⊙group-is-infinite-cyclic
Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic (S n) =
isomorphism-preserves-infinite-cyclic
(Trunc-⊙SphereS-endo-Susp-fmap-⊙iso n)
(Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic n)
{-
Trunc-⊙SphereS-endo-iso-Trunc-⊙LiftSphereS-endo : ∀ {i} n →
Trunc-⊙SphereS-endo-group n ≃ᴳ Trunc-⊙LiftSphereS-endo-group {i} n
Trunc-⊙SphereS-endo-iso-Trunc-⊙LiftSphereS-endo {i} n =
Trunc-group-emap (⊙SphereS-endo-siso-⊙LiftSphereS-endo {i} n)
Trunc-⊙SphereS-endo-⊙iso-Trunc-⊙LiftSphereS-endo : ∀ {i} n →
Trunc-⊙SphereS-endo-⊙group n ⊙≃ᴳ Trunc-⊙LiftSphereS-endo-⊙group {i} n
Trunc-⊙SphereS-endo-⊙iso-Trunc-⊙LiftSphereS-endo {i} n =
Trunc-⊙SphereS-endo-iso-Trunc-⊙LiftSphereS-endo {i} n , idp
Trunc-⊙LiftSphereS-endo-⊙group-is-infinite-cyclic : ∀ {i} n → is-infinite-cyclic (Trunc-⊙LiftSphereS-endo-⊙group {i} n)
Trunc-⊙LiftSphereS-endo-⊙group-is-infinite-cyclic {i} n =
isomorphism-preserves-infinite-cyclic
(Trunc-⊙SphereS-endo-⊙iso-Trunc-⊙LiftSphereS-endo {i} n)
(Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic n)
-}
{- definition of degree -}
Trunc-⊙SphereS-endo-degree : ∀ n → Trunc-⊙Sphere-endo (S n) → ℤ
Trunc-⊙SphereS-endo-degree n = is-equiv.g (Trunc-⊙SphereS-endo-⊙group-is-infinite-cyclic n)
abstract
Trunc-⊙SphereS-endo-degree-Susp : ∀ n f
→ Trunc-⊙SphereS-endo-degree (S n) (Trunc-fmap ⊙Susp-fmap f)
== Trunc-⊙SphereS-endo-degree n f
Trunc-⊙SphereS-endo-degree-Susp n f =
ap (Trunc-⊙SphereS-endo-degree n) (GroupIso.g-f (Trunc-⊙SphereS-endo-Susp-fmap-iso n) f)
⊙SphereS-endo-degree : ∀ n → ⊙Sphere-endo (S n) → ℤ
⊙SphereS-endo-degree n = Trunc-⊙SphereS-endo-degree n ∘ [_]
abstract
⊙SphereS-endo-degree-Susp : ∀ n f
→ ⊙SphereS-endo-degree (S n) (⊙Susp-fmap f)
== ⊙SphereS-endo-degree n f
⊙SphereS-endo-degree-Susp n f = Trunc-⊙SphereS-endo-degree-Susp n [ f ]
⊙SphereS-endo-degree-Susp' : ∀ n f
→ ⊙SphereS-endo-degree (S n) (Susp-fmap f , idp)
== Trunc-⊙SphereS-endo-degree n (Trunc-⊙SphereS-endo-in n [ f ])
⊙SphereS-endo-degree-Susp' n f =
⊙SphereS-endo-degree (S n) (Susp-fmap f , idp)
=⟨ ap
(Trunc-⊙SphereS-endo-degree (S n) ∘ Trunc-fmap (λ f → Susp-fmap f , idp))
(! $ is-equiv.f-g (Trunc-⊙SphereS-endo-out-is-equiv n) [ f ]) ⟩
Trunc-⊙SphereS-endo-degree (S n) (Trunc-fmap (λ f → Susp-fmap f , idp) (Trunc-fmap fst (Trunc-⊙SphereS-endo-in n [ f ])))
=⟨ ap (Trunc-⊙SphereS-endo-degree (S n))
(Trunc-fmap-∘ (λ f → Susp-fmap f , idp) fst (Trunc-⊙SphereS-endo-in n [ f ])) ⟩
Trunc-⊙SphereS-endo-degree (S n) (Trunc-fmap ⊙Susp-fmap (Trunc-⊙SphereS-endo-in n [ f ]))
=⟨ Trunc-⊙SphereS-endo-degree-Susp n (Trunc-⊙SphereS-endo-in n [ f ]) ⟩
Trunc-⊙SphereS-endo-degree n (Trunc-⊙SphereS-endo-in n [ f ])
=∎
⊙SphereS-endo-degree-base-indep : ∀ n {f g}
→ fst f ∼ fst g
→ ⊙SphereS-endo-degree n f == ⊙SphereS-endo-degree n g
⊙SphereS-endo-degree-base-indep n {f} {g} f∼g =
! (⊙SphereS-endo-degree-Susp n f)
∙ ap (λ f → ⊙SphereS-endo-degree (S n) (Susp-fmap f , idp)) (λ= f∼g)
∙ ⊙SphereS-endo-degree-Susp n g
{-
Trunc-⊙LiftSphereS-endo-degree : ∀ {i} n → Trunc-⊙LiftSphere-endo {i} (S n) → ℤ
Trunc-⊙LiftSphereS-endo-degree {i} n = is-equiv.g (Trunc-⊙LiftSphereS-endo-⊙group-is-infinite-cyclic {i} n)
abstract
Trunc-⊙LiftSphereS-endo-degree-Susp : ∀ {i} n f
→ Trunc-⊙LiftSphereS-endo-degree {i} (S n) (Trunc-fmap (λ f → ⊙Lift-fmap (⊙Susp-fmap (⊙lower ⊙∘ f ⊙∘ ⊙lift))) f)
== Trunc-⊙LiftSphereS-endo-degree {i} n f
Trunc-⊙LiftSphereS-endo-degree-Susp {i} n =
Trunc-elim
{{λ _ → =-preserves-level ℤ-is-set}}
(λ f → ⊙SphereS-endo-degree-Susp n (⊙lower ⊙∘ f ⊙∘ ⊙lift))
⊙LiftSphereS-endo-degree : ∀ {i} n → ⊙LiftSphere-endo {i} (S n) → ℤ
⊙LiftSphereS-endo-degree {i} n = Trunc-⊙LiftSphereS-endo-degree {i} n ∘ [_]
abstract
⊙LiftSphereS-endo-degree-Susp : ∀ {i} n f
→ ⊙LiftSphereS-endo-degree {i} (S n) (⊙Lift-fmap (⊙Susp-fmap (⊙lower ⊙∘ f ⊙∘ ⊙lift)))
== ⊙LiftSphereS-endo-degree {i} n f
⊙LiftSphereS-endo-degree-Susp {i} n f =
Trunc-⊙LiftSphereS-endo-degree-Susp {i} n [ f ]
⊙LiftSphereS-endo-degree-base-indep : ∀ {i} n {f g}
→ fst f ∼ fst g
→ ⊙LiftSphereS-endo-degree {i} n f == ⊙LiftSphereS-endo-degree {i} n g
⊙LiftSphereS-endo-degree-base-indep {i} n {f} {g} f∼g =
! (⊙LiftSphereS-endo-degree-Susp {i} n f)
∙ ap (λ f → ⊙LiftSphereS-endo-degree {i} (S n) (⊙Lift-fmap (Susp-fmap (lower ∘ f ∘ lift) , idp))) (λ= f∼g)
∙ ⊙LiftSphereS-endo-degree-Susp {i} n g
-}
| {
"alphanum_fraction": 0.6238291495,
"avg_line_length": 43.5163043478,
"ext": "agda",
"hexsha": "e4819710d3952542f061c9170886000a118d0858",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/groups/SphereEndomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/groups/SphereEndomorphism.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/groups/SphereEndomorphism.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3768,
"size": 8007
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
open import Algebra
module Algebra.Properties.AbelianGroup
{g₁ g₂} (G : AbelianGroup g₁ g₂) where
import Algebra.Properties.Group as GP
open import Data.Product
open import Function
import Relation.Binary.EqReasoning as EqR
open AbelianGroup G
open EqR setoid
open GP group public
private
lemma : ∀ x y → x ∙ y ∙ x ⁻¹ ≈ y
lemma x y = begin
x ∙ y ∙ x ⁻¹ ≈⟨ comm _ _ ⟨ ∙-cong ⟩ refl ⟩
y ∙ x ∙ x ⁻¹ ≈⟨ assoc _ _ _ ⟩
y ∙ (x ∙ x ⁻¹) ≈⟨ refl ⟨ ∙-cong ⟩ proj₂ inverse _ ⟩
y ∙ ε ≈⟨ proj₂ identity _ ⟩
y ∎
⁻¹-∙-comm : ∀ x y → x ⁻¹ ∙ y ⁻¹ ≈ (x ∙ y) ⁻¹
⁻¹-∙-comm x y = begin
x ⁻¹ ∙ y ⁻¹ ≈⟨ comm _ _ ⟩
y ⁻¹ ∙ x ⁻¹ ≈⟨ sym $ lem ⟨ ∙-cong ⟩ refl ⟩
x ∙ (y ∙ (x ∙ y) ⁻¹ ∙ y ⁻¹) ∙ x ⁻¹ ≈⟨ lemma _ _ ⟩
y ∙ (x ∙ y) ⁻¹ ∙ y ⁻¹ ≈⟨ lemma _ _ ⟩
(x ∙ y) ⁻¹ ∎
where
lem = begin
x ∙ (y ∙ (x ∙ y) ⁻¹ ∙ y ⁻¹) ≈⟨ sym $ assoc _ _ _ ⟩
x ∙ (y ∙ (x ∙ y) ⁻¹) ∙ y ⁻¹ ≈⟨ sym $ assoc _ _ _ ⟨ ∙-cong ⟩ refl ⟩
x ∙ y ∙ (x ∙ y) ⁻¹ ∙ y ⁻¹ ≈⟨ proj₂ inverse _ ⟨ ∙-cong ⟩ refl ⟩
ε ∙ y ⁻¹ ≈⟨ proj₁ identity _ ⟩
y ⁻¹ ∎
| {
"alphanum_fraction": 0.4016913319,
"avg_line_length": 31.5333333333,
"ext": "agda",
"hexsha": "244cf76db9fa4cb9c1c275fff2763c48b70cb078",
"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/Algebra/Properties/AbelianGroup.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/Algebra/Properties/AbelianGroup.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/Algebra/Properties/AbelianGroup.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": 586,
"size": 1419
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.Block as Block
import LibraBFT.Impl.Consensus.ConsensusTypes.TimeoutCertificate as TimeoutCertificate
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.Hash
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.Consensus.ConsensusTypes.ProposalMsg where
verifyWellFormed : ProposalMsg → Either ErrLog Unit
verifyWellFormed self = do
lcheck (not (Block.isNilBlock (self ^∙ pmProposal)))
(here' ("Proposal for a NIL block" ∷ []))
withErrCtx' ("Failed to verify ProposalMsg's block" ∷ [])
(Block.verifyWellFormed (self ^∙ pmProposal))
lcheck (self ^∙ pmProposal ∙ bRound >? 0)
(here' ("Proposal for has round <= 0" ∷ []))
lcheck (self ^∙ pmProposal ∙ bEpoch == self ^∙ pmSyncInfo ∙ siEpoch)
(here' ("ProposalMsg has different epoch than SyncInfo" ∷ [])) -- lsSI (self ^∙ pmSyncInfo)
lcheck (self ^∙ pmProposal ∙ bParentId == self ^∙ pmSyncInfo ∙ siHighestQuorumCert ∙ qcCertifiedBlock ∙ biId)
(here' ( "Proposal SyncInfo HQC CertifiedBlock id not eq to block parent id" ∷ []))
-- lsSI (self ^∙ pmSyncInfo)
let previousRound = self ^∙ pmProposal ∙ bRound ∸ 1 -- NOTE: monus usage
let highestCertifiedRound =
max (self ^∙ pmProposal ∙ bQuorumCert ∙ qcCertifiedBlock ∙ biRound)
(maybe 0 (_^∙ tcRound) (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert))
lcheck (previousRound == highestCertifiedRound)
(here' ("Proposal does not have a certified round" ∷ []))
-- lsMTC (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert)
lcheck (is-just (self ^∙ pmProposal ∙ bAuthor))
(here' ("Proposal does not have an author" ∷ []))
-- LBFT-DIFF : this check used to live in EventProcessor ∙ processProposedBlockM
-- TODO: is it needed?
-- Safety invariant: For any valid proposed block
-- , its parent block == the block pointed to by its QC.
lcheck (self ^∙ pmProposal ∙ bParentId == self ^∙ pmProposal ∙ bQuorumCert ∙ qcCertifiedBlock ∙ biId)
(here' ("parent id /= qcCB" ∷ [])) -- show (self ^∙ pmProposal)
where
here' : List String → List String
here' t = "ProposalMsg" ∷ "verifyWellFormed" {-∷ lsPM self-} ∷ t
verify : ProposalMsg → ValidatorVerifier → Either ErrLog Unit
verify self validator = do
Block.validateSignature (self ^∙ pmProposal) validator
TimeoutCertificate.verify' (self ^∙ pmSyncInfo ∙ siHighestTimeoutCert) validator
verifyWellFormed self
| {
"alphanum_fraction": 0.6624057686,
"avg_line_length": 50.0163934426,
"ext": "agda",
"hexsha": "0d7df635d46c8cce0d46316206a62f825ebff5f9",
"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": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"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": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/ProposalMsg.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 845,
"size": 3051
} |
module Issue2487 where
open import Issue2487.b
| {
"alphanum_fraction": 0.8333333333,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "56575d140b8adc52f9f5d97ef6319f9d1167802c",
"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/Issue2487.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/Issue2487.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/Issue2487.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": 48
} |
module nodcap.Base where
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Pos as ℕ⁺ using (ℕ⁺; suc; _+_)
open import Data.List as L using (List; []; _∷_; _++_)
open import Data.List.Any using (Any; here; there)
open import Data.List.Any.Membership.Propositional using (_∈_; _∼[_]_; bag)
open import Data.Product using (_×_; _,_; uncurry; map)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (id; _$_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
-- Types.
data Type : Set where
𝟏 : Type
⊥ : Type
𝟎 : Type
⊤ : Type
_⊗_ : (A B : Type) → Type
_⅋_ : (A B : Type) → Type
_⊕_ : (A B : Type) → Type
_&_ : (A B : Type) → Type
![_]_ : (n : ℕ⁺) (A : Type) → Type
?[_]_ : (n : ℕ⁺) (A : Type) → Type
-- Duality.
_^ : Type → Type
𝟏 ^ = ⊥
⊥ ^ = 𝟏
𝟎 ^ = ⊤
⊤ ^ = 𝟎
(A ⊗ B) ^ = (A ^) ⅋ (B ^)
(A ⅋ B) ^ = (A ^) ⊗ (B ^)
(A ⊕ B) ^ = (A ^) & (B ^)
(A & B) ^ = (A ^) ⊕ (B ^)
(![ n ] A) ^ = ?[ n ] (A ^)
(?[ n ] A) ^ = ![ n ] (A ^)
^-inv : (A : Type) → A ^ ^ ≡ A
^-inv 𝟏 = P.refl
^-inv ⊥ = P.refl
^-inv 𝟎 = P.refl
^-inv ⊤ = P.refl
^-inv (A ⊗ B) = P.cong₂ _⊗_ (^-inv A) (^-inv B)
^-inv (A ⅋ B) = P.cong₂ _⅋_ (^-inv A) (^-inv B)
^-inv (A ⊕ B) = P.cong₂ _⊕_ (^-inv A) (^-inv B)
^-inv (A & B) = P.cong₂ _&_ (^-inv A) (^-inv B)
^-inv (![ n ] A) = P.cong ![ n ]_ (^-inv A)
^-inv (?[ n ] A) = P.cong ?[ n ]_ (^-inv A)
-- Lollipop.
_⊸_ : (A B : Type) → Type
A ⊸ B = (A ^) ⅋ B
-- Polarity.
data Pos : (A : Type) → Set where
𝟎 : Pos 𝟎
𝟏 : Pos 𝟏
_⊗_ : (A B : Type) → Pos (A ⊗ B)
_⊕_ : (A B : Type) → Pos (A ⊕ B)
![_]_ : (n : ℕ⁺) (A : Type) → Pos (![ n ] A)
data Neg : (A : Type) → Set where
⊥ : Neg ⊥
⊤ : Neg ⊤
_⅋_ : (A B : Type) → Neg (A ⅋ B)
_&_ : (A B : Type) → Neg (A & B)
?[_]_ : (n : ℕ⁺) (A : Type) → Neg (?[ n ] A)
pol? : (A : Type) → Pos A ⊎ Neg A
pol? 𝟏 = inj₁ 𝟏
pol? ⊥ = inj₂ ⊥
pol? 𝟎 = inj₁ 𝟎
pol? ⊤ = inj₂ ⊤
pol? (A ⊗ B) = inj₁ (A ⊗ B)
pol? (A ⅋ B) = inj₂ (A ⅋ B)
pol? (A ⊕ B) = inj₁ (A ⊕ B)
pol? (A & B) = inj₂ (A & B)
pol? (![ n ] A) = inj₁ (![ n ] A)
pol? (?[ n ] A) = inj₂ (?[ n ] A)
^-posneg : {A : Type} (P : Pos A) → Neg (A ^)
^-posneg 𝟎 = ⊤
^-posneg 𝟏 = ⊥
^-posneg (A ⊗ B) = (A ^) ⅋ (B ^)
^-posneg (A ⊕ B) = (A ^) & (B ^)
^-posneg (![ n ] A) = ?[ n ] (A ^)
^-negpos : {A : Type} (N : Neg A) → Pos (A ^)
^-negpos ⊥ = 𝟏
^-negpos ⊤ = 𝟎
^-negpos (A ⅋ B) = (A ^) ⊗ (B ^)
^-negpos (A & B) = (A ^) ⊕ (B ^)
^-negpos (?[ n ] A) = ![ n ] (A ^)
-- Environments.
Environment : Set
Environment = List Type
-- Injectivity.
private
infix 10 _≈_
_≈_ : Type → Type → Set
A ≈ B = A ≡ B
⊗-inj : {A B C D : Type} → A ⊗ B ≈ C ⊗ D → A ≈ C × B ≈ D
⊗-inj P.refl = P.refl , P.refl
⅋-inj : {A B C D : Type} → A ⅋ B ≈ C ⅋ D → A ≈ C × B ≈ D
⅋-inj P.refl = P.refl , P.refl
⊕-inj : {A B C D : Type} → A ⊕ B ≈ C ⊕ D → A ≈ C × B ≈ D
⊕-inj P.refl = P.refl , P.refl
&-inj : {A B C D : Type} → A & B ≈ C & D → A ≈ C × B ≈ D
&-inj P.refl = P.refl , P.refl
!-inj : {A B : Type} {m n : ℕ⁺} → ![ m ] A ≈ ![ n ] B → m ≡ n × A ≈ B
!-inj P.refl = P.refl , P.refl
?-inj : {A B : Type} {m n : ℕ⁺} → ?[ m ] A ≈ ?[ n ] B → m ≡ n × A ≈ B
?-inj P.refl = P.refl , P.refl
-- This is one of those proofs for which I wish Agda had tactics.
^-inj : {A B : Type} → A ^ ≈ B ^ → A ≈ B
^-inj {A = 𝟏} {B = 𝟏} p = P.refl
^-inj {A = 𝟏} {B = ⊥} ()
^-inj {A = 𝟏} {B = 𝟎} ()
^-inj {A = 𝟏} {B = ⊤} ()
^-inj {A = 𝟏} {B = C ⊗ D} ()
^-inj {A = 𝟏} {B = C ⅋ D} ()
^-inj {A = 𝟏} {B = C ⊕ D} ()
^-inj {A = 𝟏} {B = C & D} ()
^-inj {A = 𝟏} {B = ![ n ] C} ()
^-inj {A = 𝟏} {B = ?[ n ] C} ()
^-inj {A = ⊥} {B = 𝟏} ()
^-inj {A = ⊥} {B = ⊥} p = P.refl
^-inj {A = ⊥} {B = 𝟎} ()
^-inj {A = ⊥} {B = ⊤} ()
^-inj {A = ⊥} {B = C ⊗ D} ()
^-inj {A = ⊥} {B = C ⅋ D} ()
^-inj {A = ⊥} {B = C ⊕ D} ()
^-inj {A = ⊥} {B = C & D} ()
^-inj {A = ⊥} {B = ![ n ] C} ()
^-inj {A = ⊥} {B = ?[ n ] C} ()
^-inj {A = 𝟎} {B = 𝟏} ()
^-inj {A = 𝟎} {B = ⊥} ()
^-inj {A = 𝟎} {B = 𝟎} p = P.refl
^-inj {A = 𝟎} {B = ⊤} ()
^-inj {A = 𝟎} {B = C ⊗ D} ()
^-inj {A = 𝟎} {B = C ⅋ D} ()
^-inj {A = 𝟎} {B = C ⊕ D} ()
^-inj {A = 𝟎} {B = C & D} ()
^-inj {A = 𝟎} {B = ![ n ] C} ()
^-inj {A = 𝟎} {B = ?[ n ] C} ()
^-inj {A = ⊤} {B = 𝟏} ()
^-inj {A = ⊤} {B = ⊥} ()
^-inj {A = ⊤} {B = 𝟎} ()
^-inj {A = ⊤} {B = ⊤} p = P.refl
^-inj {A = ⊤} {B = C ⊗ D} ()
^-inj {A = ⊤} {B = C ⅋ D} ()
^-inj {A = ⊤} {B = C ⊕ D} ()
^-inj {A = ⊤} {B = C & D} ()
^-inj {A = ⊤} {B = ![ n ] C} ()
^-inj {A = ⊤} {B = ?[ n ] C} ()
^-inj {A = A ⊗ B} {B = 𝟏} ()
^-inj {A = A ⊗ B} {B = ⊥} ()
^-inj {A = A ⊗ B} {B = 𝟎} ()
^-inj {A = A ⊗ B} {B = ⊤} ()
^-inj {A = A ⊗ B} {B = C ⊗ D} p = uncurry (P.cong₂ _⊗_) (map ^-inj ^-inj (⅋-inj p))
^-inj {A = A ⊗ B} {B = C ⅋ D} ()
^-inj {A = A ⊗ B} {B = C ⊕ D} ()
^-inj {A = A ⊗ B} {B = C & D} ()
^-inj {A = A ⊗ B} {B = ![ n ] C} ()
^-inj {A = A ⊗ B} {B = ?[ n ] C} ()
^-inj {A = A ⅋ B} {B = 𝟏} ()
^-inj {A = A ⅋ B} {B = ⊥} ()
^-inj {A = A ⅋ B} {B = 𝟎} ()
^-inj {A = A ⅋ B} {B = ⊤} ()
^-inj {A = A ⅋ B} {B = C ⊗ D} ()
^-inj {A = A ⅋ B} {B = C ⅋ D} p = uncurry (P.cong₂ _⅋_) (map ^-inj ^-inj (⊗-inj p))
^-inj {A = A ⅋ B} {B = C ⊕ D} ()
^-inj {A = A ⅋ B} {B = C & D} ()
^-inj {A = A ⅋ B} {B = ![ n ] C} ()
^-inj {A = A ⅋ B} {B = ?[ n ] C} ()
^-inj {A = A ⊕ B} {B = 𝟏} ()
^-inj {A = A ⊕ B} {B = ⊥} ()
^-inj {A = A ⊕ B} {B = 𝟎} ()
^-inj {A = A ⊕ B} {B = ⊤} ()
^-inj {A = A ⊕ B} {B = C ⊗ D} ()
^-inj {A = A ⊕ B} {B = C ⅋ D} ()
^-inj {A = A ⊕ B} {B = C ⊕ D} p = uncurry (P.cong₂ _⊕_) (map ^-inj ^-inj (&-inj p))
^-inj {A = A ⊕ B} {B = C & D} ()
^-inj {A = A ⊕ B} {B = ![ n ] C} ()
^-inj {A = A ⊕ B} {B = ?[ n ] C} ()
^-inj {A = A & B} {B = 𝟏} ()
^-inj {A = A & B} {B = ⊥} ()
^-inj {A = A & B} {B = 𝟎} ()
^-inj {A = A & B} {B = ⊤} ()
^-inj {A = A & B} {B = C ⊗ D} ()
^-inj {A = A & B} {B = C ⅋ D} ()
^-inj {A = A & B} {B = C ⊕ D} ()
^-inj {A = A & B} {B = C & D} p = uncurry (P.cong₂ _&_) (map ^-inj ^-inj (⊕-inj p))
^-inj {A = A & B} {B = ![ n ] C} ()
^-inj {A = A & B} {B = ?[ n ] C} ()
^-inj {A = ![ m ] A} {B = 𝟏} ()
^-inj {A = ![ m ] A} {B = ⊥} ()
^-inj {A = ![ m ] A} {B = 𝟎} ()
^-inj {A = ![ m ] A} {B = ⊤} ()
^-inj {A = ![ m ] A} {B = C ⊗ D} ()
^-inj {A = ![ m ] A} {B = C ⅋ D} ()
^-inj {A = ![ m ] A} {B = C ⊕ D} ()
^-inj {A = ![ m ] A} {B = C & D} ()
^-inj {A = ![ m ] A} {B = ![ n ] C} p = uncurry (P.cong₂ ![_]_) (map id ^-inj (?-inj p))
^-inj {A = ![ m ] A} {B = ?[ n ] C} ()
^-inj {A = ?[ m ] A} {B = 𝟏} ()
^-inj {A = ?[ m ] A} {B = ⊥} ()
^-inj {A = ?[ m ] A} {B = 𝟎} ()
^-inj {A = ?[ m ] A} {B = ⊤} ()
^-inj {A = ?[ m ] A} {B = C ⊗ D} ()
^-inj {A = ?[ m ] A} {B = C ⅋ D} ()
^-inj {A = ?[ m ] A} {B = C ⊕ D} ()
^-inj {A = ?[ m ] A} {B = C & D} ()
^-inj {A = ?[ m ] A} {B = ![ n ] C} ()
^-inj {A = ?[ m ] A} {B = ?[ n ] C} p = uncurry (P.cong₂ ?[_]_) (map id ^-inj (!-inj p))
| {
"alphanum_fraction": 0.3223510807,
"avg_line_length": 32.0168776371,
"ext": "agda",
"hexsha": "dac1bd6e59c53b7a21b7783a55448d9a928843a4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/nodcap/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"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": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/nodcap/Base.agda",
"max_line_length": 90,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/nodcap/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 3974,
"size": 7588
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Coproduct
open import lib.types.Sigma
{- Some miscellaneous lemmas for types with decidable equality. -}
module Util.DecEq where
×-has-dec-eq : {i j : ULevel} {A : Type i} {B : Type j} → (has-dec-eq A) → (has-dec-eq B) →
(has-dec-eq (A × B))
×-has-dec-eq Adec Bdec (a , b) (a' , b') =
⊔-rec (⊔-rec (λ p q → inl (pair×= q p)) (λ f _ → inr (λ p → f (ap snd p))) (Bdec b b'))
(λ f → inr (λ p → f (ap fst p))) (Adec a a')
equiv-preserves-dec-eq : {i j : ULevel} {A : Type i} {B : Type j} → (A ≃ B) → (has-dec-eq B) →
has-dec-eq A
equiv-preserves-dec-eq e Adec a a' = ⊔-rec (λ p → inl (–>-is-inj e a a' p))
(λ f → inr (λ p → f (ap (–> e) p))) (Adec (–> e a) (–> e a'))
| {
"alphanum_fraction": 0.5434210526,
"avg_line_length": 33.0434782609,
"ext": "agda",
"hexsha": "3757ac8691d8fc5c1b3eab625bf0594c25f518b5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "awswan/nielsenschreier-hott",
"max_forks_repo_path": "main/Util/DecEq.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "awswan/nielsenschreier-hott",
"max_issues_repo_path": "main/Util/DecEq.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "84be713b8a8e41ea6f01f8ccf7251ebbbd73ad5d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "awswan/nielsenschreier-hott",
"max_stars_repo_path": "main/Util/DecEq.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 325,
"size": 760
} |
module Category.Core where
open import Level
open import Data.Product
-- open import Relation.Binary as B using ()
open import Relation.Binary as B using ()
open import Relation.Binary.Indexed
open import Relation.Binary.PropositionalEquality as PropEq using (_≡_; refl)
record IsMorphism {𝒸 ℓ : Level}
{Object : Set 𝒸}
{Carrier : (Object × Object) → Set 𝒸}
(_≈_ : Rel Carrier ℓ)
(_∘_ : ∀ {a b c} → Carrier (b , c) → Carrier (a , b) → Carrier (a , c))
(id : (a : Object) → Carrier (a , a))
: Set (suc (𝒸 ⊔ ℓ)) where
_⇒_ = curry Carrier
field
assoc : ∀ {a b c d : Object}
→ (f : a ⇒ b) → (g : b ⇒ c) → (h : c ⇒ d)
→ ((h ∘ g) ∘ f) ≈ (h ∘ (g ∘ f))
left-identity : ∀ {a b : Object}
→ (f : a ⇒ b)
→ (id b ∘ f) ≈ f
right-identity : ∀ {a b : Object}
→ (f : a ⇒ b)
→ (f ∘ id a) ≈ f
cong : ∀ {a b c a' b' c' : Object}
{x : Carrier (b , c)} {y : Carrier (b' , c')}
{u : Carrier (a , b)} {v : Carrier (a' , b')}
→ x ≈ y → u ≈ v → (x ∘ u) ≈ (y ∘ v)
record MorphismStructure (𝒸 ℓ : Level) (Object : Set 𝒸) : Set (suc (𝒸 ⊔ ℓ)) where
infixr 9 _∘_
infix 4 _≈_
field
Carrier : (Object × Object) → Set 𝒸
_≈_ : Rel Carrier ℓ
isEquivalence : IsEquivalence Carrier _≈_
setoid : Setoid (Object × Object) _ _
setoid = record { isEquivalence = isEquivalence }
-- Arrows
_⇒_ : Object → Object → Set 𝒸
_⇒_ = curry Carrier
field
_∘_ : ∀ {a b c : Object}
→ b ⇒ c
→ a ⇒ b
→ a ⇒ c
id : (a : Object) → a ⇒ a
isMorphism : IsMorphism _≈_ _∘_ id
record Category (𝒸 ℓ : Level) : Set (suc (𝒸 ⊔ ℓ)) where
field
Objects : B.Setoid 𝒸 ℓ
Object : Set 𝒸
Object = B.Setoid.Carrier Objects
_≈o_ : Object → Object → Set ℓ
_≈o_ = B.Setoid._≈_ Objects
field
Morphisms : MorphismStructure 𝒸 ℓ Object
open MorphismStructure Morphisms public
hom[-,_] : Object → Set 𝒸
hom[-, b ] = Σ[ a ∈ Object ] a ⇒ b
-- hom[_,_] : Object → Object → Set 𝒸
-- hom[ a , b ] = a ⇒ b
record IsFunctor {𝒸₀ ℓ₀ 𝒸₁ ℓ₁ : Level}
{C : Category 𝒸₀ ℓ₀} {D : Category 𝒸₁ ℓ₁}
(mapObject : Category.Object C → Category.Object D)
(mapMorphism : ∀ {a b}
→ (Category._⇒_ C) a b
→ (Category._⇒_ D) (mapObject a) (mapObject b))
: Set (𝒸₀ ⊔ ℓ₀ ⊔ 𝒸₁ ⊔ ℓ₁) where
module C = Category C
open Category D
field
preserve-id : (a : C.Object)
→ mapMorphism (C.id a) ≈ id (mapObject a)
preserve-∘ : {a b c : C.Object} (f : a C.⇒ b) (g : b C.⇒ c)
→ mapMorphism (C._∘_ g f) ≈ mapMorphism g ∘ mapMorphism f
record Functor {𝒸₀ ℓ₀ 𝒸₁ ℓ₁ : Level}
(C : Category 𝒸₀ ℓ₀) (D : Category 𝒸₁ ℓ₁) : Set (𝒸₀ ⊔ ℓ₀ ⊔ 𝒸₁ ⊔ ℓ₁) where
module C = Category C
module D = Category D
field
mapObject : C.Object → D.Object
mapMorphism : ∀ {a b} → a C.⇒ b → mapObject a D.⇒ mapObject b
isFunctor : IsFunctor {𝒸₀} {ℓ₀} {𝒸₁} {ℓ₁} {C} {D} mapObject mapMorphism
| {
"alphanum_fraction": 0.4963054187,
"avg_line_length": 30.9333333333,
"ext": "agda",
"hexsha": "1509c4baa38e5341910d3ba95e6708dafa18d056",
"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": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/categories",
"max_forks_repo_path": "src/Category/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/categories",
"max_issues_repo_path": "src/Category/Core.agda",
"max_line_length": 91,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9f6d933b227aecab338ecaef1d86566a54fdac68",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/categories",
"max_stars_repo_path": "src/Category/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2018-01-04T23:19:30.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-01-04T23:19:30.000Z",
"num_tokens": 1203,
"size": 3248
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Monads on indexed sets (predicates)
------------------------------------------------------------------------
-- Note that currently the monad laws are not included here.
{-# OPTIONS --without-K --safe #-}
module Category.Monad.Predicate where
open import Category.Applicative.Indexed
open import Category.Monad
open import Category.Monad.Indexed
open import Data.Unit
open import Data.Product
open import Function
open import Level
open import Relation.Binary.PropositionalEquality
open import Relation.Unary
open import Relation.Unary.PredicateTransformer using (Pt)
------------------------------------------------------------------------
record RawPMonad {i ℓ} {I : Set i} (M : Pt I (i ⊔ ℓ)) :
Set (suc i ⊔ suc ℓ) where
infixl 1 _?>=_ _?>_ _>?>_
infixr 1 _=<?_ _<?<_
-- ``Demonic'' operations (the opponent chooses the state).
field
return? : ∀ {P} → P ⊆ M P
_=<?_ : ∀ {P Q} → P ⊆ M Q → M P ⊆ M Q
_?>=_ : ∀ {P Q} → M P ⊆ const (P ⊆ M Q) ⇒ M Q
m ?>= f = f =<? m
_?>=′_ : ∀ {P Q} → M P ⊆ const (∀ j → {_ : P j} → j ∈ M Q) ⇒ M Q
m ?>=′ f = m ?>= λ {j} p → f j {p}
_?>_ : ∀ {P Q} → M P ⊆ const (∀ {j} → j ∈ M Q) ⇒ M Q
m₁ ?> m₂ = m₁ ?>= λ _ → m₂
join? : ∀ {P} → M (M P) ⊆ M P
join? m = m ?>= id
_>?>_ : {P Q R : _} → P ⊆ M Q → Q ⊆ M R → P ⊆ M R
f >?> g = _=<?_ g ∘ f
_<?<_ : ∀ {P Q R} → Q ⊆ M R → P ⊆ M Q → P ⊆ M R
g <?< f = f >?> g
-- ``Angelic'' operations (the player knows the state).
rawIMonad : RawIMonad (λ i j A → i ∈ M (const A ∩ { j }))
rawIMonad = record
{ return = λ x → return? (x , refl)
; _>>=_ = λ m k → m ?>= λ { {._} (x , refl) → k x }
}
open RawIMonad rawIMonad public
| {
"alphanum_fraction": 0.4720982143,
"avg_line_length": 27.5692307692,
"ext": "agda",
"hexsha": "38b039eb647dd9d278e31e23431503ccbeda4809",
"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/Category/Monad/Predicate.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/Category/Monad/Predicate.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/Category/Monad/Predicate.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 612,
"size": 1792
} |
module CoinductiveCK where
open import Data.Product
open import Data.Sum
open import Data.Empty
open import Data.Nat
open import Data.Bool using (Bool; if_then_else_; true; false)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; sym; cong; subst)
open PropEq.≡-Reasoning
open import Relation.Nullary
open import Relation.Nullary.Negation using (¬∃⟶∀¬; Excluded-Middle)
open import Function using (_$_; _∘_)
open import Relation.Binary.Core using (IsEquivalence) renaming (Rel to RelL)
open import Level as L using () renaming (_⊔_ to _⊔L_)
-- to be classical, we need the law of excluded middle
-- the following defns. were adapted from:
-- http://stackoverflow.com/questions/36669072/law-of-excluded-middle-in-agda
postulate LEM : ∀ {ℓ} (A : Set ℓ) → Dec A
¬¬A⇒A : ∀ {ℓ} {A : Set ℓ} → ¬ (¬ A) → A
¬¬A⇒A {_} {A} ¬¬p with LEM A
... | yes p = p
... | no ¬p = ⊥-elim (¬¬p ¬p)
¬∀⟶∃¬ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : A → Set ℓ'} → ¬ (∀ a → B a) → ∃ λ a → ¬ (B a)
¬∀⟶∃¬ {A = A} {B} ¬∀ with LEM (∃ λ a → ¬ B a)
... | (yes p) = p
... | (no ¬p) = ⊥-elim $ ¬∀ (¬¬A⇒A ∘ ¬∃⟶∀¬ ¬p)
postulate State : Set
Event : ∀ {ℓ} → Set (L.suc ℓ)
Event {ℓ} = State → Set ℓ
_∧_ : ∀ {ℓ ℓ'} → Event {ℓ} → Event {ℓ'} → Event
e1 ∧ e2 = λ w → e1 w × e2 w
_∨_ : ∀ {ℓ ℓ'} → Event {ℓ} → Event {ℓ'} → Event
e1 ∨ e2 = λ w → e1 w ⊎ e2 w
_⟶_ : ∀ {ℓ ℓ'} → Event {ℓ} → Event {ℓ'} → Event
e1 ⟶ e2 = λ w → e1 w → e2 w
_⇒_ : ∀ {ℓ ℓ'} → Event {ℓ} → Event {ℓ'} → Set _
e1 ⇒ e2 = ∀ w → e1 w → e2 w
~_ : ∀ {ℓ} → Event {ℓ} → Event
~ e = λ w → e w → ⊥
All : ∀ {ℓ} → Event {ℓ} → Set _
All e = ∀ w → e w
⇒All⟶ : ∀ {ℓ ℓ'} (e1 : Event {ℓ}) (e2 : Event {ℓ'}) → e1 ⇒ e2 → All (e1 ⟶ e2)
⇒All⟶ e1 e2 e1⇒e2 w e1w = e1⇒e2 w e1w
mapE : ∀ {ℓ ℓ' ℓ''} {X : Set ℓ} → (Event {ℓ'} → Event {ℓ''}) → (X → Event) → X → Event {ℓ''}
mapE K E = λ n → K (E n)
_⊂_ : ∀ {ℓ ℓ' ℓ''} {X : Set ℓ} → (X → Event {ℓ'}) → Event {ℓ''} → Set (ℓ ⊔L ℓ' ⊔L ℓ'')
_⊂_ {X = X} E e = ∀ w → (∀ (x : X) → E x w) → e w
⇒Trans : ∀ {ℓ ℓ' ℓ''} {e1 : Event {ℓ}} {e2 : Event {ℓ'}} {e3 : Event {ℓ''}} → e1 ⇒ e2 → e2 ⇒ e3 → e1 ⇒ e3
⇒Trans e1⇒e2 e2⇒e3 w e1w = e2⇒e3 w (e1⇒e2 w e1w)
⊂Trans : ∀ {ℓ ℓ' ℓ'' ℓ'''} {X : Set ℓ} {E : X → Event {ℓ'}} {e1 : Event {ℓ''}} {e2 : Event {ℓ'''}} →
E ⊂ e1 → e1 ⇒ e2 → E ⊂ e2
⊂Trans E⊂e1 e1⇒e2 w ∀xExw = e1⇒e2 w (E⊂e1 w ∀xExw)
-- Definition of preservation of semantic implication.
Sem⊂ : ∀ {ℓ ℓ' ℓ''} → (Event {ℓ'} → Event {ℓ''}) → Set (L.suc (ℓ ⊔L ℓ') ⊔L ℓ'')
Sem⊂ {ℓ} {ℓ'} {ℓ''} K = ∀ {X : Set ℓ} {E : X → Event {ℓ'}} {e : Event {ℓ'}} → _⊂_ {ℓ} {ℓ'} {ℓ'} E e → (mapE K E) ⊂ K e
-- Knowledge Operators
record KOp {ℓ ℓ'} (K : Event {ℓ} → Event {ℓ}) : Set (L.suc (ℓ ⊔L ℓ')) where
field
axiomN : ∀ {e} → All e → All (K e)
axiomK : ∀ {e1 e2} → K (e1 ⟶ e2) ⇒ (K e1 ⟶ K e2)
axiomT : ∀ {e} → K e ⇒ e
axiom4 : ∀ {e} → K e ⇒ K (K e)
axiom5 : ∀ {e} → (~ K e) ⇒ K (~ K e)
-- Infinitary deduction
axiomInf : Sem⊂ {ℓ'} K
-- axiomN follows from axiomInf, using the empty family
emptyFam : ∀ {ℓ} → ⊥ → Event {ℓ}
emptyFam ()
All_emptyFam : ∀ {ℓ ℓ'} (e : Event {ℓ}) → All e → (emptyFam {ℓ'}) ⊂ e
All_emptyFam e Alle w ∀xExw = Alle w
emptyFam_All : ∀ {ℓ ℓ'} (e : Event {ℓ}) → (emptyFam {ℓ'}) ⊂ e → All e
emptyFam_All e emptyFam⊂e w = emptyFam⊂e w (λ x → ⊥-elim x)
infN : ∀ {ℓ ℓ'} → (K : Event {ℓ} → Event {ℓ'}) → Sem⊂ K → ∀ e → All e → All (K e)
infN {ℓ} K Sem⊂K e Alle = emptyFam_All (K e) aux
where
aux : (emptyFam {ℓ}) ⊂ (K e)
aux w _ = Sem⊂K (All_emptyFam e Alle) w (λ x → ⊥-elim x)
-- Similarly, axiomK follows from axiomInf using a family with two members:
-- A "modus ponens" family.
mpFam : ∀ {ℓ ℓ'} (e1 : Event {ℓ ⊔L ℓ'}) (e2 : Event {ℓ'}) → Bool → Event {ℓ ⊔L ℓ'}
mpFam e1 e2 = λ b → if b then (e1 ⟶ e2) else e1
infK : ∀ {ℓ} → (K : Event {ℓ} → Event {ℓ}) → Sem⊂ K →
∀ (e1 : Event {ℓ}) (e2 : Event {ℓ}) → K (e1 ⟶ e2) ⇒ (K e1 ⟶ K e2)
infK {ℓ} K Sem⊂K e1 e2 w Ke1⟶e2w Ke1w = Sem⊂K {E = mpFam {ℓ} e1 e2} aux₁ w aux₂
where
aux₁ : mpFam {ℓ} e1 e2 ⊂ e2
aux₁ w ∀x⦃e1⟶e2,e1⦄xw = ∀x⦃e1⟶e2,e1⦄xw true (∀x⦃e1⟶e2,e1⦄xw false)
aux₂ : (x : Bool) → mapE K (mpFam {ℓ} e1 e2) x w
aux₂ true = Ke1⟶e2w
aux₂ false = Ke1w
natK : ∀ {ℓ ℓ'} {X : Set ℓ'} {K : Event {ℓ} → Event {ℓ}} → KOp {ℓ} {ℓ'} K →
∀ {E : X → Event} {e} → E ⊂ e → (mapE K E) ⊂ (K e)
natK KOpK E⊂e = KOp.axiomInf KOpK E⊂e
K⇒ : ∀ {ℓ ℓ'} {K : Event {ℓ} → Event {ℓ}} → KOp {ℓ} {ℓ'} K →
∀ {e1 e2} → e1 ⇒ e2 → (K e1) ⇒ (K e2)
K⇒ KOpK {e1} {e2} e1⇒e2 w Ke1w = KOp.axiomK KOpK {e1} {e2} w (KOp.axiomN KOpK e1⇒e2 w) Ke1w
~e⇒K~Ke : ∀ {ℓ ℓ'} {K : Event {ℓ} → Event {ℓ}} → KOp {ℓ} {ℓ'} K →
∀ {e} → (~ e) ⇒ K (~ K e)
~e⇒K~Ke KOpK {e} w ~ew = KOp.axiom5 KOpK w (λ Kew → ~ew (KOp.axiomT KOpK {e} w Kew))
-- COINDUCTIVE DEFINITION OF COMMON KNOWLEDGE
postulate Agent : Set
postulate an_agent : Agent
postulate 𝕂 : ∀ {ℓ} → Agent → Event {ℓ} → Event {ℓ}
postulate 𝕂KOp : ∀ {ℓ ℓ'} a → KOp {ℓ} {ℓ'} (𝕂 a)
𝕂⇒ : ∀ {ℓ} {e1 : Event {ℓ}} {e2 : Event {ℓ}} {i : Agent} → e1 ⇒ e2 → 𝕂 i e1 ⇒ 𝕂 i e2
𝕂⇒ {ℓ} {e1} {e2} {i} e1⇒e2 w 𝕂ie1w =
KOp.axiomK (𝕂KOp {ℓ} {ℓ} i) {e1} {e2} w (KOp.axiomN (𝕂KOp {ℓ} {ℓ} i) e1⇒e2 w) 𝕂ie1w
-- Everybody Knows
EK : ∀ {ℓ ℓ'} {K : Agent → Event {ℓ} → Event {ℓ'}} → Event → Event
EK {ℓ} {ℓ'} {K} e = λ w → ∀ {i : Agent} → K i e w
E𝕂 : ∀ {ℓ} → Event {ℓ} → Event {ℓ}
E𝕂 = EK {K = 𝕂}
-- Common Knowledge
-- Coinductive Definition
record cCK {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} (e : Event {ℓ}) (w : State) : Set ℓ where
coinductive
field
intro : (EK {ℓ} {ℓ} {K} e ∧ cCK {ℓ} {K} (EK {ℓ} {ℓ} {K} e)) w
cC𝕂 : ∀ {ℓ} → Event {ℓ} → Event {ℓ}
cC𝕂 = cCK {K = 𝕂}
cCK⇒EK : ∀ {ℓ} {e : Event {ℓ}} {K : Agent → Event {ℓ} → Event {ℓ}} →
cCK {K = K} e ⇒ EK {K = K} e
cCK⇒EK w cCKe = proj₁ (cCK.intro cCKe)
cCK⇒cCKEK : ∀ {ℓ} {e : Event {ℓ}} {K : Agent → Event {ℓ} → Event {ℓ}} →
cCK {K = K} e ⇒ cCK {K = K} (EK {K = K} e)
cCK⇒cCKEK w cCKe = proj₂ (cCK.intro cCKe)
-- knowledge operator properties of E𝕂
E𝕂axiomInf : ∀ {ℓ ℓ'} → Sem⊂ {ℓ'} (E𝕂 {ℓ})
E𝕂axiomInf {X = X} {E} {e} E⊂e w ∀xEKExw {i} =
KOp.axiomInf (𝕂KOp i) {X} {E} {e} E⊂e w (λ x → ∀xEKExw x)
E𝕂axiomN : ∀ {ℓ} {e : Event {ℓ}} →
All e → All (E𝕂 e)
E𝕂axiomN {ℓ} Alle w {i} = KOp.axiomN (𝕂KOp {ℓ} {ℓ} i) Alle w
E𝕂axiomK : ∀ {ℓ} {e1 e2 : Event {ℓ}} →
E𝕂 (e1 ⟶ e2) ⇒ (E𝕂 e1 ⟶ E𝕂 e2)
E𝕂axiomK {ℓ} {e1 = e1} {e2} w E𝕂e1⟶e2w E𝕂e1w {i} =
KOp.axiomK (𝕂KOp {ℓ} {ℓ} i) {e1} w E𝕂e1⟶e2w E𝕂e1w
E𝕂axiomT : ∀ {ℓ} {e : Event {ℓ}} → E𝕂 e ⇒ e
E𝕂axiomT {ℓ} w E𝕂ew = KOp.axiomT (𝕂KOp {ℓ} {ℓ} an_agent) w E𝕂ew
E𝕂⇒ : ∀ {ℓ} {e1 e2 : Event {ℓ}} → e1 ⇒ e2 → E𝕂 e1 ⇒ E𝕂 e2
E𝕂⇒ e1⇒e2 w E𝕂e1w = 𝕂⇒ e1⇒e2 w E𝕂e1w
-- EK_axiom4 doesn't hold - if it did, (EK e) would imply (EK (EK e)),
-- and applying this ad infinitum would imply (cCK e)
E𝕂cC𝕂 : ∀ {ℓ} {e : Event {ℓ}} → e ⇒ E𝕂 e → e ⇒ cC𝕂 e
cCK.intro (E𝕂cC𝕂 {e} e⇒E𝕂e w ew) = e⇒E𝕂e w ew , E𝕂cC𝕂 (E𝕂⇒ e⇒E𝕂e) w (e⇒E𝕂e w ew)
~K⇒~EK : ∀ {ℓ} {e : Event {ℓ}} {K : Agent → Event {ℓ} → Event {ℓ}} {a} →
(~ K a e) ⇒ (~ EK {K = K} e)
~K⇒~EK w ~Kae EKew = ~Kae EKew
𝕂~𝕂⇒𝕂~E𝕂 : ∀ {ℓ} {e : Event {ℓ}} {a} → 𝕂 a (~ 𝕂 a e) ⇒ 𝕂 a (~ E𝕂 e)
𝕂~𝕂⇒𝕂~E𝕂 = 𝕂⇒ (~K⇒~EK {K = 𝕂})
~e⇒E𝕂~E𝕂 : ∀ {ℓ} {e : Event {ℓ}} → (~ e) ⇒ E𝕂 (~ E𝕂 e)
~e⇒E𝕂~E𝕂 {ℓ} w ~ew {i} = 𝕂~𝕂⇒𝕂~E𝕂 w (~e⇒K~Ke (𝕂KOp {ℓ} {ℓ} i) w ~ew)
-- cCK equivalent of recursive EK
recEK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} → Event {ℓ} → ℕ → Event {ℓ}
recEK {K = K} e zero = EK {K = K} e
recEK {K = K} e (suc n) = EK {K = K} (recEK {K = K} e n)
recE𝕂 : ∀ {ℓ} → Event {ℓ} → ℕ → Event {ℓ}
recE𝕂 = recEK {K = 𝕂}
recEK-EK≡EK-recEK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} (e : Event {ℓ}) n →
recEK {K = K} (EK {K = K} e) n ≡ EK {K = K} (recEK {K = K} e n)
recEK-EK≡EK-recEK _ zero = refl
recEK-EK≡EK-recEK {K = K} e (suc n) = cong (EK {K = K}) (recEK-EK≡EK-recEK {K = K} e n)
cCK⇒recEK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} (e : Event {ℓ}) n →
cCK {K = K} e ⇒ recEK {K = K} e n
cCK⇒recEK e zero w cCKew {i} = proj₁ (cCK.intro cCKew)
cCK⇒recEK {K = K} e (suc n) =
⇒Trans {e2 = cCK {K = K} (EK {K = K} e)} cCK⇒cCKEK
(⇒Trans {e2 = recEK {K = K} (EK {K = K} e) n} ih aux)
where
ih : cCK {K = K} (EK {K = K} e) ⇒ recEK {K = K} (EK {K = K} e) n
ih = cCK⇒recEK (EK {K = K} e) n
aux : recEK {K = K} (EK {K = K} e) n ⇒ recEK {K = K} e (suc n)
aux rewrite recEK-EK≡EK-recEK {K = K} e n = λ w EKrecEKenw {i} → EKrecEKenw
recEK⊂cCK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} (e : Event {ℓ}) →
(recEK {K = K} e) ⊂ (cCK {K = K} e)
cCK.intro (recEK⊂cCK {K = K} e w ∀xrecEKexw) =
∀xrecEKexw zero , ih w (λ n → subst (λ P → P) (aux n) (∀xrecEKexw (suc n)))
where
ih : (recEK {K = K} (EK {K = K} e)) ⊂ (cCK {K = K} (EK {K = K} e))
ih = recEK⊂cCK (EK {K = K} e)
aux : ∀ n → (EK {K = K} (recEK {K = K} e n)) w ≡ (recEK {K = K} (EK {K = K} e) n) w
aux n = cong (λ P → P w) {EK {K = K} (recEK {K = K} e n)} {recEK {K = K} (EK {K = K} e) n}
(sym (recEK-EK≡EK-recEK e n))
-- knowledge operator properties of cCK
E𝕂cC𝕂⇒cC𝕂E𝕂 : ∀ {ℓ} (e : Event {ℓ}) → E𝕂 (cC𝕂 e) ⇒ cC𝕂 (E𝕂 e)
E𝕂cC𝕂⇒cC𝕂E𝕂 e w E𝕂cC𝕂ew = cCK⇒cCKEK w (E𝕂axiomT w E𝕂cC𝕂ew)
cCKEK⇒EKcCK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} {KOpK : ∀ a -> KOp {ℓ} {L.zero} (K a)} (e : Event {ℓ}) →
cCK {K = K} (EK {K = K} e) ⇒ EK {K = K} (cCK {K = K} e)
cCKEK⇒EKcCK {K = K} {KOpK} e w cCKEKew {i} =
natK {X = ℕ} (KOpK i) (recEK⊂cCK e) w
(λ n → aux n w (subst (λ P → P w)
{recEK {K = K} (EK {K = K} e) n}
{EK {K = K} (recEK {K = K} e n)}
(recEK-EK≡EK-recEK e n)
(cCK⇒recEK (EK {K = K} e) n w cCKEKew)))
where
aux : ∀ n → EK {K = K} (recEK {K = K} e n) ⇒ mapE (K i) (recEK {K = K} e) n
aux n w EKrecEKen = EKrecEKen
cCK⇒EKcCK : ∀ {ℓ} {K : Agent → Event {ℓ} → Event {ℓ}} (KOpK : ∀ a -> KOp {ℓ} {L.zero} (K a)) (e : Event {ℓ}) →
cCK {K = K} e ⇒ EK {K = K} (cCK {K = K} e)
cCK⇒EKcCK {K = K} KOpK e = ⇒Trans {e2 = cCK {K = K} (EK {K = K} e)} cCK⇒cCKEK (cCKEK⇒EKcCK {K = K} {KOpK} e)
E𝕂recE𝕂 : ∀ {ℓ} (e1 e2 : Event {ℓ}) n → e1 ⇒ E𝕂 e2 → recE𝕂 e1 n ⇒ recE𝕂 e2 (suc n)
E𝕂recE𝕂 e1 e2 zero e1⇒E𝕂e2 w recE𝕂e1nw {i} = E𝕂⇒ {e1 = e1} e1⇒E𝕂e2 w recE𝕂e1nw
E𝕂recE𝕂 e1 e2 (suc n) e1⇒E𝕂e2 w recE𝕂e1nw {i} = E𝕂⇒ {e1 = recEK e1 n} ih w recE𝕂e1nw
where
ih : recE𝕂 e1 n ⇒ recE𝕂 e2 (suc n)
ih = E𝕂recE𝕂 e1 e2 n e1⇒E𝕂e2
cC𝕂⇒recE𝕂cC𝕂 : ∀ {ℓ} (e : Event {ℓ}) n → cC𝕂 e ⇒ recE𝕂 (cC𝕂 e) n
cC𝕂⇒recE𝕂cC𝕂 e zero = cCK⇒EKcCK 𝕂KOp e
cC𝕂⇒recE𝕂cC𝕂 e (suc n) = ⇒Trans {e2 = E𝕂 (cC𝕂 e)} (cCK⇒EKcCK 𝕂KOp e) ih
where
ih : E𝕂 (cC𝕂 e) ⇒ E𝕂 (recE𝕂 (cC𝕂 e) n)
ih = E𝕂⇒ (cC𝕂⇒recE𝕂cC𝕂 e n)
cC𝕂axiomInf : ∀ {ℓ ℓ'} → Sem⊂ {ℓ} {ℓ'} {ℓ'} cC𝕂
cCK.intro (cC𝕂axiomInf {X = X} {E} {e} E⊂e w mapEcC𝕂E) =
E𝕂axiomInf {X = X} {E} E⊂e w (λ x → cCK⇒EK w (mapEcC𝕂E x)) ,
cC𝕂axiomInf {E = λ x → E𝕂 (E x)} (E𝕂axiomInf {X = X} {E} E⊂e) w (λ x → cCK⇒cCKEK w (mapEcC𝕂E x))
cC𝕂axiom4 : ∀ {ℓ} {e : Event {ℓ}} → cC𝕂 e ⇒ cC𝕂 (cC𝕂 e)
cC𝕂axiom4 {e = e} w cC𝕂e = recEK⊂cCK (cC𝕂 e) w ((λ n → cC𝕂⇒recE𝕂cC𝕂 e n w cC𝕂e))
cC𝕂axiomN : ∀ {ℓ} {e : Event {ℓ}} → All e → All (cC𝕂 e)
cC𝕂axiomN {e = e} = infN cC𝕂 cC𝕂axiomInf e
cC𝕂axiomT : ∀ {ℓ} {e : Event {ℓ}} → cC𝕂 e ⇒ e
cC𝕂axiomT w cC𝕂ew = E𝕂axiomT w (proj₁ (cCK.intro cC𝕂ew))
cC𝕂axiomK : ∀ {ℓ} {e1 e2 : Event {ℓ}} → cC𝕂 (e1 ⟶ e2) ⇒ (cC𝕂 e1 ⟶ cC𝕂 e2)
cC𝕂axiomK {_} {e1} {e2} = infK cC𝕂 cC𝕂axiomInf e1 e2
~cC𝕂⇒E𝕂~cC𝕂 : ∀ {ℓ} {e : Event {ℓ}} → (~ cC𝕂 e) ⇒ E𝕂 (~ cC𝕂 e)
~cC𝕂⇒E𝕂~cC𝕂 {e = e} w ~cC𝕂ew = cut (λ ∀nrecE𝕂enw → ~cC𝕂ew (recEK⊂cCK e w ∀nrecE𝕂enw))
where
cut : (¬(∀ n → recE𝕂 e n w)) → E𝕂 (~ cC𝕂 e) w
cut ¬∀nrecE𝕂enw = E𝕂⇒ {e1 = ~ recE𝕂 e (suc n)}
(λ w ~recE𝕂eSn cC𝕂ew → ~recE𝕂eSn (cCK⇒recEK e (suc n) w cC𝕂ew))
w
(~e⇒E𝕂~E𝕂 w ¬recE𝕂enw)
where
neg : ∃ (λ n → ¬ (recE𝕂 e n w))
neg = ¬∀⟶∃¬ ¬∀nrecE𝕂enw
n = proj₁ neg
¬recE𝕂enw = proj₂ neg
cC𝕂axiom5 : ∀ {ℓ} {e : Event {ℓ}} → (~ cC𝕂 e) ⇒ cC𝕂 (~ cC𝕂 e)
cC𝕂axiom5 = E𝕂cC𝕂 ~cC𝕂⇒E𝕂~cC𝕂
cC𝕂KOp : ∀ {ℓ ℓ'} → KOp {ℓ} {ℓ'} cC𝕂
cC𝕂KOp = record {
axiomN = cC𝕂axiomN
; axiomK = cC𝕂axiomK
; axiomT = cC𝕂axiomT
; axiom4 = cC𝕂axiom4
; axiom5 = cC𝕂axiom5
; axiomInf = cC𝕂axiomInf
}
-- Equivalence Relations
RelToK : ∀ {ℓ ℓ'} → RelL State ℓ → Event {ℓ'} → Event {ℓ ⊔L ℓ'}
RelToK R e w = ∀ v → R w v → e v
KtoRel : ∀ {ℓ} → (Event → Event {ℓ}) → RelL State (L.suc ℓ)
KtoRel K w v = ∀ e → K e w → K e v
-- Proof that RelToK on an equivalence relation yields a K satisfying S5 *)
axiomN' : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R →
∀ {e : Event {ℓ'}} → All e → All ((RelToK R) e)
axiomN' _ _ Alle _ v _ = Alle v
axiomK' : ∀ {ℓ ℓ' ℓ''} → (R : RelL State ℓ) → IsEquivalence R →
∀ {e1 : Event {ℓ'}} {e2 : Event {ℓ''}} → (RelToK R) (e1 ⟶ e2) ⇒ ((RelToK R) e1 ⟶ (RelToK R) e2)
axiomK' R _ {e1} {e2} w Ke1⟶e2 Ke1w = λ v Rwv → Ke1⟶e2 v Rwv (Ke1w v Rwv)
axiomT' : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R →
∀ {e : Event {ℓ'}} → (RelToK R) e ⇒ e
axiomT' R IsEqR {e} w Kew = Kew w (IsEquivalence.refl IsEqR)
axiom4' : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R →
∀ {e : Event {ℓ'}} → (RelToK R) e ⇒ (RelToK R) ((RelToK R) e)
axiom4' R IsEqR {e} w Kew v Rwv u Rvu = Kew u (IsEquivalence.trans IsEqR Rwv Rvu)
axiom5' : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R →
∀ {e : Event {ℓ'}} → (~ (RelToK R) e) ⇒ (RelToK R) (~ ((RelToK R) e))
axiom5' R IsEqR {e} w ~Kew v Rwv Kev =
~Kew (λ u Rwu → Kev u (IsEquivalence.trans IsEqR (IsEquivalence.sym IsEqR Rwv) Rwu))
axiomInf' : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R → Sem⊂ {ℓ'} {ℓ} (RelToK R)
axiomInf' R IsEqR E⊂e w ∀x v Rwv = E⊂e v (λ x → ∀x x v Rwv)
KOpRelToK : ∀ {ℓ ℓ'} → (R : RelL State ℓ) → IsEquivalence R → KOp {ℓ} {ℓ'} (RelToK R)
KOpRelToK R IsEqR = record {
axiomN = axiomN' R IsEqR
; axiomK = axiomK' R IsEqR
; axiomT = axiomT' R IsEqR
; axiom4 = axiom4' R IsEqR
; axiom5 = axiom5' R IsEqR
; axiomInf = axiomInf' R IsEqR
}
-- Proof that K_to_Rel on a K satisfying S5 yields an equivalence relation
eqRefl' : ∀ {ℓ ℓ'} → (K : Event {ℓ} → Event) → KOp {ℓ} {ℓ'} K →
∀ {w : State} → (KtoRel K) w w
eqRefl' K KopK = λ e Kew → Kew
eqSym' : ∀ {ℓ ℓ'} → (K : Event {ℓ} → Event) → KOp {ℓ} {ℓ'} K →
∀ {w v : State} → (KtoRel K) w v → (KtoRel K) v w
eqSym' K KOpK {w} {v} Rwv e Kev = ¬¬A⇒A (λ ¬Kew →
KOp.axiomT KOpK {~ K e} v (Rwv (~ K e) (KOp.axiom5 KOpK {e} w ¬Kew)) Kev)
eqTrans' : ∀ {ℓ ℓ'} → (K : Event {ℓ} → Event) → KOp {ℓ} {ℓ'} K →
∀ {w v u : State} → (KtoRel K) w v → (KtoRel K) v u → (KtoRel K) w u
eqTrans' K _ {w} {v} {u} Rwv Rvu e Kew = Rvu e (Rwv e Kew)
EqRelKtoRel : ∀ {ℓ ℓ'} → (K : Event {ℓ} → Event) → KOp {ℓ} {ℓ'} K → IsEquivalence (KtoRel K)
EqRelKtoRel K KOpK = record { refl = eqRefl' K KOpK ; sym = eqSym' K KOpK ; trans = eqTrans' K KOpK }
-- The two transformations are an isomorphism
EqRelKIso1 : ∀ {ℓ ℓ'} → {K : Event → Event {ℓ}} → KOp {ℓ} {ℓ'} K →
∀ (e : Event {ℓ}) → (K e) ⇒ (RelToK (KtoRel K) e)
EqRelKIso1 {K = K} KOpK e w Kew v Rwv = KOp.axiomT KOpK v (Rwv e Kew)
data Indexed {ℓ ℓ'} (K : Event {ℓ} → Event {ℓ'}) (w : State) : Set (L.suc (ℓ ⊔L ℓ')) where
index : ∀ (e : Event) → K e w → Indexed K w
KFam : ∀ {ℓ} {K : Event {ℓ} → Event {ℓ}} {w : State} → Indexed K w → Event {ℓ}
KFam {K = K} (index e Kew) = K e
Rew→KFam⊂e : ∀ {ℓ} → {K : Event → Event {ℓ}} →
∀ (e : Event {ℓ}) w → RelToK (KtoRel K) e w → (KFam {K = K} {w}) ⊂ e
Rew→KFam⊂e {ℓ} {K} e w R2K-K2Rew v ∀xKFamxv =
R2K-K2Rew v (λ e' Ke'w → ∀xKFamxv (index e' Ke'w))
EqRelKIso2 : ∀ {ℓ} → {K : Event → Event {ℓ}} → KOp {ℓ} {L.suc ℓ} K →
∀ (e : Event {ℓ}) → (RelToK (KtoRel K) e) ⇒ (K e)
EqRelKIso2 {ℓ} {K} KOpK e w R2K-K2Rew = KOp.axiomInf KOpK aux w aux₁
where
aux : _⊂_ {L.suc ℓ} {ℓ} {ℓ} (KFam {ℓ} {K} {w}) e
aux = Rew→KFam⊂e e w R2K-K2Rew
aux₁ : (x : Indexed K w) → K (KFam x) w
aux₁ (index e Kew) = KOp.axiom4 KOpK w Kew
KeqRelIso1 : ∀ {ℓ} → (R : RelL State ℓ) → IsEquivalence R →
∀ w v → R w v → KtoRel {ℓ} (RelToK R) w v
KeqRelIso1 R IsEqR w v Rwv e R2Kew u Rvu = R2Kew u (IsEquivalence.trans IsEqR Rwv Rvu)
KeqRelIso2 : ∀ {ℓ} → (R : RelL State ℓ) → IsEquivalence R →
∀ w v → KtoRel {ℓ} (RelToK R) w v → R w v
KeqRelIso2 R IsEqR w v K2R-R2Kwv = K2R-R2Kwv (R w) (λ v₁ z → z) v (IsEquivalence.refl IsEqR)
-- RELATIONAL DEFINITION OF COMMON KNOWLEDGE
postulate 𝕂R : ∀ {ℓ} → Agent → RelL State ℓ
postulate IsEq𝕂R : ∀ {ℓ} a → IsEquivalence (𝕂R {ℓ} a)
𝕂ᵣ : ∀ {ℓ} (i : Agent) → Event {ℓ} → Event {ℓ}
𝕂ᵣ {ℓ} i = RelToK (𝕂R {ℓ} i)
𝕂ᵣKOp : ∀ {ℓ ℓ'} i -> KOp {ℓ} {ℓ'} (𝕂ᵣ i)
𝕂ᵣKOp i = KOpRelToK (𝕂R i) (IsEq𝕂R i)
𝕂ᵣe→e : ∀ {ℓ} i (e : Event {ℓ}) w → 𝕂ᵣ i e w → e w
𝕂ᵣe→e i e w 𝕂ᵣiew = 𝕂ᵣiew w (IsEquivalence.refl (IsEq𝕂R i))
𝕂ᵣe→𝕂ᵣ𝕂ᵣe : ∀ {ℓ} i (e : Event {ℓ}) w → 𝕂ᵣ i e w → 𝕂ᵣ i (𝕂ᵣ i e) w
𝕂ᵣe→𝕂ᵣ𝕂ᵣe i e w 𝕂ᵣiew v 𝕂Riwv u 𝕂Rivu =
𝕂ᵣiew u (IsEquivalence.trans (IsEq𝕂R i) 𝕂Riwv 𝕂Rivu)
E𝕂ᵣ : ∀ {ℓ} → Event {ℓ} → Event {ℓ}
E𝕂ᵣ = EK {K = 𝕂ᵣ}
cC𝕂ᵣ : ∀ {ℓ} → Event {ℓ} → Event {ℓ}
cC𝕂ᵣ = cCK {K = 𝕂ᵣ}
cC𝕂ᵣ→E𝕂ᵣcC𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → cC𝕂ᵣ e w -> E𝕂ᵣ (cC𝕂ᵣ e) w
cC𝕂ᵣ→E𝕂ᵣcC𝕂ᵣ {ℓ} {e} {w} = cCK⇒EKcCK {K = 𝕂ᵣ} 𝕂ᵣKOp e w
data C𝕂R {ℓ} : RelL State ℓ where
base : ∀ i w v -> 𝕂R {ℓ} i w v -> C𝕂R w v
trans : ∀ {w v u} -> C𝕂R {ℓ} w v -> C𝕂R {ℓ} v u -> C𝕂R {ℓ} w u
C𝕂Rrefl : ∀ {ℓ} → Relation.Binary.Core.Reflexive (C𝕂R {ℓ})
C𝕂Rrefl {x = w} = base an_agent w w (IsEquivalence.refl (IsEq𝕂R an_agent))
C𝕂Rsym : ∀ {ℓ} → Relation.Binary.Core.Symmetric (C𝕂R {ℓ})
C𝕂Rsym (base i w v 𝕂Riwv) = base i v w (IsEquivalence.sym (IsEq𝕂R i) 𝕂Riwv)
C𝕂Rsym (trans C𝕂Rwv C𝕂Rvu) = trans (C𝕂Rsym C𝕂Rvu) (C𝕂Rsym C𝕂Rwv)
EqRelC𝕂R : ∀ {ℓ} → IsEquivalence (C𝕂R {ℓ})
EqRelC𝕂R = record { refl = C𝕂Rrefl ; sym = C𝕂Rsym ; trans = trans }
C𝕂ᵣ : ∀ {ℓ} → Event {ℓ} → Event {ℓ}
C𝕂ᵣ {ℓ} = RelToK (C𝕂R {ℓ})
C𝕂ᵣ→E𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → C𝕂ᵣ e w -> E𝕂ᵣ e w
C𝕂ᵣ→E𝕂ᵣ {_} {e} {w} C𝕂ᵣew {i} v 𝕂Riwv = C𝕂ᵣew v (base i w v 𝕂Riwv)
C𝕂ᵣ→E𝕂ᵣC𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → C𝕂ᵣ e w -> E𝕂ᵣ (C𝕂ᵣ e) w
C𝕂ᵣ→E𝕂ᵣC𝕂ᵣ {_} {e} {w} C𝕂ᵣew {i} v 𝕂Riwv u C𝕂Rvu =
C𝕂ᵣew u (trans (base i w v 𝕂Riwv) C𝕂Rvu)
C𝕂ᵣ→C𝕂ᵣE𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → C𝕂ᵣ e w -> C𝕂ᵣ (E𝕂ᵣ e) w
C𝕂ᵣ→C𝕂ᵣE𝕂ᵣ {_} {e} {w} C𝕂ᵣew v C𝕂Rwv {i} u 𝕂Rivu =
C𝕂ᵣew u (trans C𝕂Rwv (base i v u 𝕂Rivu))
C𝕂ᵣ→cC𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → C𝕂ᵣ e w -> cC𝕂ᵣ e w
cCK.intro (C𝕂ᵣ→cC𝕂ᵣ {ℓ} {e} {w} C𝕂ᵣew) = C𝕂ᵣ→E𝕂ᵣ C𝕂ᵣew , C𝕂ᵣ→cC𝕂ᵣ (C𝕂ᵣ→C𝕂ᵣE𝕂ᵣ C𝕂ᵣew)
C𝕂transport : ∀ {ℓ} {e : Event {ℓ}} {w v : State} → cC𝕂ᵣ e w -> C𝕂R {ℓ} w v -> cC𝕂ᵣ e v
C𝕂transport {_} {e} cC𝕂ᵣew (base i w v 𝕂Riwv) = record { intro =
proj₁ (cCK.intro (proj₂ (cCK.intro cC𝕂ᵣew))) v 𝕂Riwv ,
aux v 𝕂Riwv
}
where
aux : E𝕂ᵣ (cC𝕂ᵣ (E𝕂ᵣ e)) w
aux = cC𝕂ᵣ→E𝕂ᵣcC𝕂ᵣ (record { intro = cCK.intro (proj₂ (cCK.intro cC𝕂ᵣew)) })
C𝕂transport cC𝕂ᵣew (trans C𝕂Rwv C𝕂Rvu) =
C𝕂transport (C𝕂transport cC𝕂ᵣew C𝕂Rwv) C𝕂Rvu
cC𝕂ᵣ→C𝕂ᵣ : ∀ {ℓ} {e : Event {ℓ}} {w : State} → cC𝕂ᵣ e w -> C𝕂ᵣ e w
cC𝕂ᵣ→C𝕂ᵣ {ℓ} {e} cC𝕂ᵣew v (base i w .v x) = proj₁ (cCK.intro cC𝕂ᵣew) v x
cC𝕂ᵣ→C𝕂ᵣ {ℓ} {e} {w} cC𝕂ᵣew v (trans {v = v'} C𝕂Rwv' C𝕂Rv'v) =
cC𝕂ᵣ→C𝕂ᵣ (C𝕂transport cC𝕂ᵣew C𝕂Rwv') v C𝕂Rv'v
| {
"alphanum_fraction": 0.5322982354,
"avg_line_length": 37.0019607843,
"ext": "agda",
"hexsha": "ba3c60b46bc5f02bf199f135fa1d3a2e1f40d95d",
"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": "81242e3362683c3f100fdc3c310cf64e65e43b96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "goodlyrottenapple/coinductiveCK",
"max_forks_repo_path": "CoinductiveCK.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "81242e3362683c3f100fdc3c310cf64e65e43b96",
"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": "goodlyrottenapple/coinductiveCK",
"max_issues_repo_path": "CoinductiveCK.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "81242e3362683c3f100fdc3c310cf64e65e43b96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "goodlyrottenapple/coinductiveCK",
"max_stars_repo_path": "CoinductiveCK.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 11308,
"size": 18871
} |
{-# OPTIONS --safe #-}
module Cubical.HITs.Wedge.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.HITs.Pushout.Base
open import Cubical.Data.Sigma
open import Cubical.Data.Unit
_⋁_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Type (ℓ-max ℓ ℓ')
_⋁_ (A , ptA) (B , ptB) = Pushout {A = Unit} {B = A} {C = B} (λ _ → ptA) (λ _ → ptB)
-- Pointed versions
_⋁∙ₗ_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋁∙ₗ B = (A ⋁ B) , (inl (snd A))
_⋁∙ᵣ_ : ∀ {ℓ ℓ'} → Pointed ℓ → Pointed ℓ' → Pointed (ℓ-max ℓ ℓ')
A ⋁∙ᵣ B = (A ⋁ B) , (inr (snd B))
-- Wedge sums of functions
_∨→_ : ∀ {ℓ ℓ' ℓ''} {A : Pointed ℓ} {B : Pointed ℓ'} {C : Pointed ℓ''}
→ (f : A →∙ C) (g : B →∙ C)
→ A ⋁ B → fst C
(f ∨→ g) (inl x) = fst f x
(f ∨→ g) (inr x) = fst g x
(f ∨→ g) (push a i₁) = (snd f ∙ sym (snd g)) i₁
-- Pointed version
∨→∙ : ∀ {ℓ ℓ' ℓ''} {A : Pointed ℓ} {B : Pointed ℓ'} {C : Pointed ℓ''}
→ (f : A →∙ C) (g : B →∙ C) → ((A ⋁∙ₗ B) →∙ C)
fst (∨→∙ {A = A} f g) = f ∨→ g
snd (∨→∙ {A = A} f g) = snd f
-- Wedge sum of Units is contractible
isContr-Unit⋁Unit : isContr ((Unit , tt) ⋁ (Unit , tt))
fst isContr-Unit⋁Unit = inl tt
snd isContr-Unit⋁Unit (inl tt) = refl
snd isContr-Unit⋁Unit (inr tt) = push tt
snd isContr-Unit⋁Unit (push tt i) j = push tt (i ∧ j)
⋁↪ : ∀ {ℓ ℓ'} {A : Pointed ℓ} {B : Pointed ℓ'}
→ A ⋁ B → typ A × typ B
⋁↪ {B = B} (inl x) = x , pt B
⋁↪ {A = A} (inr x) = pt A , x
⋁↪ {A = A} {B = B} (push a i) = pt A , pt B
| {
"alphanum_fraction": 0.5258964143,
"avg_line_length": 32.0425531915,
"ext": "agda",
"hexsha": "f2094d066e3e87cb27b992a647b030fb4b85f8e2",
"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": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lpw25/cubical",
"max_forks_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"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": "lpw25/cubical",
"max_issues_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_line_length": 84,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9f9ad9dad7404c75cf457f81ba5ac269afe1b1a7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lpw25/cubical",
"max_stars_repo_path": "Cubical/HITs/Wedge/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 762,
"size": 1506
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Instances.Int where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Int
renaming (_+_ to _+ℤ_ ; _-_ to _-ℤ_; -_ to -ℤ_ ; _·_ to _·ℤ_)
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.Properties
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open GroupStr
ℤGroup : Group₀
fst ℤGroup = ℤ
1g (snd ℤGroup) = 0
_·_ (snd ℤGroup) = _+ℤ_
inv (snd ℤGroup) = -ℤ_
isGroup (snd ℤGroup) = isGroupℤ
where
abstract
isGroupℤ : IsGroup (pos 0) (_+ℤ_) (-ℤ_)
isGroupℤ = makeIsGroup isSetℤ
+Assoc (λ _ → refl) (+Comm 0)
-Cancel -Cancel'
ℤHom : (n : ℤ) → GroupHom ℤGroup ℤGroup
fst (ℤHom n) x = n ·ℤ x
snd (ℤHom n) =
makeIsGroupHom λ x y → ·DistR+ n x y
negEquivℤ : GroupEquiv ℤGroup ℤGroup
fst negEquivℤ =
isoToEquiv
(iso (GroupStr.inv (snd ℤGroup))
(GroupStr.inv (snd ℤGroup))
(GroupTheory.invInv ℤGroup)
(GroupTheory.invInv ℤGroup))
snd negEquivℤ =
makeIsGroupHom -Dist+
| {
"alphanum_fraction": 0.6704249783,
"avg_line_length": 25.6222222222,
"ext": "agda",
"hexsha": "131a3ec8758c9d5c4f52cb6816cb762b66d741ca",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/Group/Instances/Int.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/Group/Instances/Int.agda",
"max_line_length": 63,
"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/Algebra/Group/Instances/Int.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": 403,
"size": 1153
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Homogeneously-indexed binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via
-- `Relation.Binary.Indexed.Homogeneous`.
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Indexed.Homogeneous.Core where
open import Level using (Level; _⊔_)
open import Data.Product using (_×_)
open import Relation.Binary as B using (REL; Rel)
open import Relation.Binary.PropositionalEquality.Core using (_≡_; refl)
import Relation.Binary.Indexed.Heterogeneous as I
open import Relation.Unary.Indexed using (IPred)
private
variable
a b c ℓ : Level
I : Set c
------------------------------------------------------------------------
-- Homegeneously indexed binary relations
-- Heterogeneous types
IREL : (I → Set a) → (I → Set b) → (ℓ : Level) → Set _
IREL A B ℓ = ∀ {i} → REL (A i) (B i) ℓ
-- Homogeneous types
IRel : (I → Set a) → (ℓ : Level) → Set _
IRel A = IREL A A
------------------------------------------------------------------------
-- Lifting to non-indexed binary relations
-- Ideally this should be in: `Construct.Lift` but we want this relation
-- to be exported by the various structures & bundles.
Lift : (A : I → Set a) → IRel A ℓ → Rel (∀ i → A i) _
Lift _ _∼_ x y = ∀ i → x i ∼ y i
------------------------------------------------------------------------
-- Conversion between homogeneous and heterogeneously indexed relations
module _ {i a b} {I : Set i} {A : I → Set a} {B : I → Set b} where
OverPath : ∀ {ℓ} → IREL A B ℓ → ∀ {i j} → i ≡ j → REL (A i) (B j) ℓ
OverPath _∼_ refl = _∼_
toHetIndexed : ∀ {ℓ} → IREL A B ℓ → I.IREL A B (i ⊔ ℓ)
toHetIndexed _∼_ {i} {j} x y = (p : i ≡ j) → OverPath _∼_ p x y
fromHetIndexed : ∀ {ℓ} → I.IREL A B ℓ → IREL A B ℓ
fromHetIndexed _∼_ = _∼_
| {
"alphanum_fraction": 0.5280373832,
"avg_line_length": 31.5737704918,
"ext": "agda",
"hexsha": "e04c011fad2a2421854cf06e99067ceff650a966",
"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/Indexed/Homogeneous/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous/Core.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Indexed/Homogeneous/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": 541,
"size": 1926
} |
open import Agda.Primitive using (lzero; lsuc; _⊔_)
open import Agda.Builtin.Nat
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
open import Data.Fin
open import Relation.Binary
module SingleSorted.AlgebraicTheory where
open import SingleSorted.Context public
Arity : Set
Arity = Context
arg : Arity → Set
arg = var
-- an algebraic signature
record Signature : Set₁ where
field
oper : Set -- operations
oper-arity : oper → Arity -- the arity of an operation
-- terms over a signature in a context of a given sort
data Term (Γ : Context) : Set where
tm-var : var Γ → Term Γ
tm-oper : ∀ (f : oper) → (arg (oper-arity f) → Term Γ) → Term Γ
-- Substitutions (definitions - some useful properties are in another file)
_⇒s_ : ∀ (Γ Δ : Context) → Set
Γ ⇒s Δ = var Δ → Term Γ
infix 4 _⇒s_
-- identity substitution
id-s : ∀ {Γ : Context} → Γ ⇒s Γ
id-s = tm-var
-- the action of a substitution on a term (contravariant)
_[_]s : ∀ {Γ Δ : Context} → Term Δ → Γ ⇒s Δ → Term Γ
(tm-var x) [ σ ]s = σ x
(tm-oper f x) [ σ ]s = tm-oper f (λ i → x i [ σ ]s)
infixr 6 _[_]s
-- composition of substitutions
_∘s_ : ∀ {Γ Δ Θ : Context} → Δ ⇒s Θ → Γ ⇒s Δ → Γ ⇒s Θ
(σ ∘s ρ) x = σ x [ ρ ]s
infixl 7 _∘s_
-- Axioms are equations in context
record Equation : Set where
field
eq-ctx : Context
eq-lhs : Term eq-ctx
eq-rhs : Term eq-ctx
-- Theory
-- an equational theory is a family of equations over a given sort
record Theory ℓ (Σ : Signature) : Set (lsuc ℓ) where
open Signature Σ public
field
ax : Set ℓ -- the axiom names
ax-eq : ax → Equation -- the axioms
ax-ctx : ax → Context
ax-ctx ε = Equation.eq-ctx (ax-eq ε)
ax-lhs : ∀ (ε : ax) → Term (ax-ctx ε)
ax-lhs ε = Equation.eq-lhs (ax-eq ε)
ax-rhs : ∀ (ε : ax) → Term (ax-ctx ε)
ax-rhs ε = Equation.eq-rhs (ax-eq ε)
infix 4 _⊢_≈_
-- equality of terms
data _⊢_≈_ : (Γ : Context) → Term Γ → Term Γ → Set (lsuc ℓ) where
-- general rules
eq-refl : ∀ {Γ} {t : Term Γ} → Γ ⊢ t ≈ t
eq-symm : ∀ {Γ} {s t : Term Γ} → Γ ⊢ s ≈ t → Γ ⊢ t ≈ s
eq-tran : ∀ {Γ} {s t u : Term Γ} → Γ ⊢ s ≈ t → Γ ⊢ t ≈ u → Γ ⊢ s ≈ u
-- congruence rule
eq-congr : ∀ {Γ} {f : oper} {xs ys : arg (oper-arity f) → Term Γ} →
(∀ i → Γ ⊢ xs i ≈ ys i) → Γ ⊢ tm-oper f xs ≈ tm-oper f ys
-- equational axiom
eq-axiom : ∀ (ε : ax) {Γ : Context} (σ : Γ ⇒s (ax-ctx ε)) →
Γ ⊢ ax-lhs ε [ σ ]s ≈ ax-rhs ε [ σ ]s
≡-⊢-≈ : {Γ : Context} {s t : Term Γ} → s ≡ t → Γ ⊢ s ≈ t
≡-⊢-≈ refl = eq-refl
-- the action of the identity substitution is the identity
id-action : ∀ {Γ : Context} {a : Term Γ} → (Γ ⊢ a ≈ (a [ id-s ]s))
id-action {a = tm-var a} = eq-refl
id-action {a = tm-oper f x} = eq-congr (λ i → id-action {a = x i})
eq-axiom-id : ∀ (ε : ax) → ax-ctx ε ⊢ ax-lhs ε ≈ ax-rhs ε
eq-axiom-id ε = eq-tran id-action (eq-tran (eq-axiom ε id-s) (eq-symm id-action))
eq-setoid : ∀ (Γ : Context) → Setoid lzero (lsuc ℓ)
eq-setoid Γ =
record
{ Carrier = Term Γ
; _≈_ = λ s t → (Γ ⊢ s ≈ t)
; isEquivalence =
record
{ refl = eq-refl
; sym = eq-symm
; trans = eq-tran
}
}
| {
"alphanum_fraction": 0.5305466238,
"avg_line_length": 29.747826087,
"ext": "agda",
"hexsha": "25250c3543b40f994f02da89d57216e896e0d4f2",
"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/SingleSorted/AlgebraicTheory.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/SingleSorted/AlgebraicTheory.agda",
"max_line_length": 85,
"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/SingleSorted/AlgebraicTheory.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": 1258,
"size": 3421
} |
module +-swap where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
open import Data.Nat using (ℕ; _+_)
open import Induction′ using (+-assoc; +-comm)
+-swap : ∀ (m n p : ℕ) → m + (n + p) ≡ n + (m + p)
+-swap m n p =
begin
m + (n + p)
≡⟨ sym (+-assoc m n p) ⟩
(m + n) + p
≡⟨ cong (_+ p) (+-comm m n) ⟩
(n + m) + p
≡⟨ +-assoc n m p ⟩
n + (m + p)
∎
| {
"alphanum_fraction": 0.5172413793,
"avg_line_length": 22.0952380952,
"ext": "agda",
"hexsha": "d860e91bf833cfc18c2306fa5ff647ee1a81455e",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/induction/+-swap.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/induction/+-swap.agda",
"max_line_length": 53,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/induction/+-swap.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 203,
"size": 464
} |
------------------------------------------------------------------------------
-- Testing nested axioms
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
{-
Processing this file should be generate a TPTP file with the following
axioms
fof(..., axiom, ( a = b )).
fof(..., axiom, ( b = c )).
fof(..., axiom, ( c = d )).
-}
module NestedAxioms.C where
open import NestedAxioms.A
open import NestedAxioms.B
------------------------------------------------------------------------------
postulate
d : D
c≡d : c ≡ d
{-# ATP axiom c≡d #-}
postulate foo : d ≡ a
{-# ATP prove foo #-}
| {
"alphanum_fraction": 0.396965866,
"avg_line_length": 23.2647058824,
"ext": "agda",
"hexsha": "9fd5494eaeb7e21a9aafdb8ef1940c3263897b05",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/NestedAxioms/C.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/NestedAxioms/C.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/NestedAxioms/C.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 167,
"size": 791
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Instance.Cartesians where
open import Level
open import Categories.Category
open import Categories.Category.Helper
open import Categories.Category.Cartesian.Structure
open import Categories.Functor.Cartesian
open import Categories.Functor.Cartesian.Properties
open import Categories.NaturalTransformation.NaturalIsomorphism
module _ o ℓ e where
Cartesians : Category (suc (o ⊔ ℓ ⊔ e)) (o ⊔ ℓ ⊔ e) (o ⊔ ℓ ⊔ e)
Cartesians = categoryHelper record
{ Obj = CartesianCategory o ℓ e
; _⇒_ = CartesianF
; _≈_ = λ F G → CF.F F ≃ CF.F G
; id = idF-CartesianF _
; _∘_ = ∘-CartesianF
; assoc = λ {_ _ _ _ F G H} → associator (CF.F F) (CF.F G) (CF.F H)
; identityˡ = unitorˡ
; identityʳ = unitorʳ
; equiv = record
{ refl = ≃.refl
; sym = ≃.sym
; trans = ≃.trans
}
; ∘-resp-≈ = _ⓘₕ_
}
where module CF = CartesianF
| {
"alphanum_fraction": 0.621703854,
"avg_line_length": 29,
"ext": "agda",
"hexsha": "fb9ed4e58b5068b38723aa921a36ba53bb3fa5b6",
"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/Instance/Cartesians.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/Instance/Cartesians.agda",
"max_line_length": 75,
"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/Instance/Cartesians.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": 320,
"size": 986
} |
{-# OPTIONS --without-K --safe #-}
module Data.Nat.DivMod where
open import Data.Nat.Base
open import Agda.Builtin.Nat as Nat
open import Data.Bool
nonZero : ℕ → Bool
nonZero (suc _) = true
nonZero zero = false
infixl 8 _÷_
_÷_ : (n m : ℕ) → { m≢0 : T (nonZero m) } → ℕ
_÷_ n (suc m) = Nat.div-helper 0 m n m
rem : (n m : ℕ) → { m≢0 : T (nonZero m) } → ℕ
rem n (suc m) = Nat.mod-helper 0 m n m
even : ℕ → Bool
even n = rem n 2 Nat.== 0
| {
"alphanum_fraction": 0.602247191,
"avg_line_length": 20.2272727273,
"ext": "agda",
"hexsha": "bfa036510333488b6419150a568106e0a49ba18f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Nat/DivMod.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Nat/DivMod.agda",
"max_line_length": 45,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Nat/DivMod.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 180,
"size": 445
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Almost commutative rings
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Tactic.RingSolver.Core.AlmostCommutativeRing where
open import Level
open import Relation.Binary
open import Algebra.Core using (Op₁; Op₂)
open import Algebra.Structures using (IsCommutativeSemiring)
open import Algebra.Definitions
open import Algebra.Bundles using (RawRing; CommutativeRing; CommutativeSemiring)
import Algebra.Morphism as Morphism
open import Function
open import Level
open import Data.Maybe.Base as Maybe using (Maybe; just; nothing)
record IsAlmostCommutativeRing
{a ℓ} {A : Set a} (_≈_ : Rel A ℓ)
(_+_ _*_ : A → A → A) (-_ : A → A) (0# 1# : A) : Set (a ⊔ ℓ) where
field
isCommutativeSemiring : IsCommutativeSemiring _≈_ _+_ _*_ 0# 1#
-‿cong : -_ Preserves _≈_ ⟶ _≈_
-‿*-distribˡ : ∀ x y → ((- x) * y) ≈ (- (x * y))
-‿+-comm : ∀ x y → ((- x) + (- y)) ≈ (- (x + y))
open IsCommutativeSemiring isCommutativeSemiring public
import Algebra.Operations.Ring as Exp
record AlmostCommutativeRing c ℓ : Set (suc (c ⊔ ℓ)) where
infix 8 -_
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_
infixr 8 _^_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ
_+_ : Op₂ Carrier
_*_ : Op₂ Carrier
-_ : Op₁ Carrier
0# : Carrier
0≟_ : (x : Carrier) → Maybe (0# ≈ x)
1# : Carrier
isAlmostCommutativeRing :
IsAlmostCommutativeRing _≈_ _+_ _*_ -_ 0# 1#
open IsAlmostCommutativeRing isAlmostCommutativeRing hiding (refl) public
open import Data.Nat.Base as ℕ using (ℕ)
commutativeSemiring : CommutativeSemiring _ _
commutativeSemiring = record
{ isCommutativeSemiring = isCommutativeSemiring
}
open CommutativeSemiring commutativeSemiring public
using ( +-semigroup; +-monoid; +-commutativeMonoid
; *-semigroup; *-monoid; *-commutativeMonoid
; semiring
)
rawRing : RawRing _ _
rawRing = record
{ _≈_ = _≈_
; _+_ = _+_
; _*_ = _*_
; -_ = -_
; 0# = 0#
; 1# = 1#
}
_^_ : Carrier → ℕ → Carrier
_^_ = Exp._^_ rawRing
{-# NOINLINE _^_ #-}
refl : ∀ {x} → x ≈ x
refl = IsAlmostCommutativeRing.refl isAlmostCommutativeRing
record _-Raw-AlmostCommutative⟶_
{r₁ r₂ r₃ r₄}
(From : RawRing r₁ r₂)
(To : AlmostCommutativeRing r₃ r₄) : Set (r₁ ⊔ r₂ ⊔ r₃ ⊔ r₄) where
private
module F = RawRing From
module T = AlmostCommutativeRing To
open Morphism.Definitions F.Carrier T.Carrier T._≈_
field
⟦_⟧ : Morphism
+-homo : Homomorphic₂ ⟦_⟧ F._+_ T._+_
*-homo : Homomorphic₂ ⟦_⟧ F._*_ T._*_
-‿homo : Homomorphic₁ ⟦_⟧ F.-_ T.-_
0-homo : Homomorphic₀ ⟦_⟧ F.0# T.0#
1-homo : Homomorphic₀ ⟦_⟧ F.1# T.1#
-raw-almostCommutative⟶
: ∀ {r₁ r₂} (R : AlmostCommutativeRing r₁ r₂) →
AlmostCommutativeRing.rawRing R -Raw-AlmostCommutative⟶ R
-raw-almostCommutative⟶ R = record
{ ⟦_⟧ = id
; +-homo = λ _ _ → refl
; *-homo = λ _ _ → refl
; -‿homo = λ _ → refl
; 0-homo = refl
; 1-homo = refl
}
where open AlmostCommutativeRing R
-- A homomorphism induces a notion of equivalence on the raw ring.
Induced-equivalence :
∀ {c₁ c₂ c₃ ℓ} {Coeff : RawRing c₁ c₂} {R : AlmostCommutativeRing c₃ ℓ} →
Coeff -Raw-AlmostCommutative⟶ R → Rel (RawRing.Carrier Coeff) ℓ
Induced-equivalence {R = R} morphism a b = ⟦ a ⟧ ≈ ⟦ b ⟧
where
open AlmostCommutativeRing R
open _-Raw-AlmostCommutative⟶_ morphism
------------------------------------------------------------------------
-- Conversions
-- Commutative rings are almost commutative rings.
fromCommutativeRing : ∀ {r₁ r₂} (CR : CommutativeRing r₁ r₂) →
(open CommutativeRing CR) →
(∀ x → Maybe (0# ≈ x)) →
AlmostCommutativeRing _ _
fromCommutativeRing CR 0≟_ = record
{ isAlmostCommutativeRing = record
{ isCommutativeSemiring = isCommutativeSemiring
; -‿cong = -‿cong
; -‿*-distribˡ = -‿*-distribˡ
; -‿+-comm = ⁻¹-∙-comm
}
; 0≟_ = 0≟_
}
where
open CommutativeRing CR
open import Algebra.Properties.Ring ring
open import Algebra.Properties.AbelianGroup +-abelianGroup
fromCommutativeSemiring : ∀ {r₁ r₂} (CS : CommutativeSemiring r₁ r₂)
(open CommutativeSemiring CS) →
(∀ x → Maybe (0# ≈ x)) →
AlmostCommutativeRing _ _
fromCommutativeSemiring CS 0≟_ = record
{ -_ = id
; isAlmostCommutativeRing = record
{ isCommutativeSemiring = isCommutativeSemiring
; -‿cong = id
; -‿*-distribˡ = λ _ _ → refl
; -‿+-comm = λ _ _ → refl
}
; 0≟_ = 0≟_
}
where open CommutativeSemiring CS
| {
"alphanum_fraction": 0.5607240171,
"avg_line_length": 31.9130434783,
"ext": "agda",
"hexsha": "7eb859d28ca4c0ea3abf4723a0b0324848a4225a",
"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/AlmostCommutativeRing.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/AlmostCommutativeRing.agda",
"max_line_length": 81,
"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/AlmostCommutativeRing.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": 1723,
"size": 5138
} |
open import Data.Product using ( _×_ ; _,_ )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox using ( TBox )
open import Web.Semantic.Util using ( Finite )
module Web.Semantic.DL.Category.Object {Σ : Signature} where
infixr 4 _,_
data Object (S T : TBox Σ) : Set₁ where
_,_ : ∀ X → (X ∈ Finite × ABox Σ X) → Object S T
IN : ∀ {S T} → Object S T → Set
IN (X , X∈Fin , A) = X
fin : ∀ {S T} → (A : Object S T) → (IN A ∈ Finite)
fin (X , X∈Fin , A) = X∈Fin
iface : ∀ {S T} → (A : Object S T) → (ABox Σ (IN A))
iface (X , X∈Fin , A) = A
| {
"alphanum_fraction": 0.6214605067,
"avg_line_length": 29.1739130435,
"ext": "agda",
"hexsha": "73dfb3ce74df1c2358cca2504a52baf42e4815b2",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_line_length": 60,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Category/Object.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 249,
"size": 671
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Impl.NetworkMsg
open import LibraBFT.Concrete.System.Parameters
-- This module collects the implementation obligations for our (fake/simple, for now)
-- "implementation" into the structure required by Concrete.Properties.
open import LibraBFT.Impl.Properties.Aux
import LibraBFT.Impl.Properties.VotesOnce as VO
import LibraBFT.Impl.Properties.LockedRound as LR
open import LibraBFT.Concrete.Obligations
open import LibraBFT.Concrete.System impl-sps-avp
module LibraBFT.Impl.Properties where
theImplObligations : ImplObligations
theImplObligations = record { sps-cor = impl-sps-avp
; vo₁ = VO.vo₁
; vo₂ = VO.vo₂
; lr₁ = LR.lr₁ }
| {
"alphanum_fraction": 0.7093690249,
"avg_line_length": 43.5833333333,
"ext": "agda",
"hexsha": "9be371a67fd4d776fb8cdc5b23921c1ce5f22944",
"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": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "haroldcarr/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"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": "haroldcarr/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Properties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "34e4627855fb198665d0c98f377403a906ba75d7",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "haroldcarr/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 272,
"size": 1046
} |
{-# OPTIONS --cubical #-}
module Type.Cubical.Logic where
open import Functional
import Logic.Propositional as Logic
import Logic.Predicate as Logic
import Lvl
open import Type
open import Type.Cubical.Path.Equality
open import Type.Cubical.HTrunc₁
open import Type.Properties.Homotopy
open import Type.Properties.MereProposition
open import Structure.Relator
open import Syntax.Function
private variable ℓ ℓ₁ ℓ₂ : Lvl.Level
private variable T A B C Obj : Type{ℓ}
private variable Pred : Obj → Type{ℓ}
open import Logic.Propositional public using
( _∧_ ; [∧]-intro ; [∧]-elimₗ ; [∧]-elimᵣ
; _←_ ; [←]-intro ; [←]-elim
; _↔_ ; [↔]-intro ; [↔]-elimₗ ; [↔]-elimᵣ ; [↔]-to-[←] ; [↔]-to-[→]
; ¬_ ; [¬]-intro ; [¬]-elim
; ⊥ ; [⊥]-elim
; ⊤ ; [⊤]-intro
)
_∨_ : Type{ℓ₁} → Type{ℓ₂} → Type
_∨_ = HTrunc₁ ∘₂ (Logic._∨_)
[∨]-introₗ : A → (A ∨ B)
[∨]-introₗ = trunc ∘ Logic.[∨]-introₗ
[∨]-introᵣ : B → (A ∨ B)
[∨]-introᵣ = trunc ∘ Logic.[∨]-introᵣ
[∨]-elim : ⦃ prop-C : MereProposition(C) ⦄ → (A → C) → (B → C) → (A ∨ B) → C
[∨]-elim = HTrunc₁-function ∘₂ Logic.[∨]-elim
instance
[∨]-prop : MereProposition(A ∨ B)
[∨]-prop = HTrunc₁-prop
∃ : (Obj → Type{ℓ}) → Type
∃ = HTrunc₁ ∘ Logic.∃
[∃]-intro : (witness : Obj) → ⦃ proof : Pred(witness) ⦄ → ∃(Pred)
[∃]-intro witness = trunc(Logic.[∃]-intro witness)
[∃]-elim : ⦃ prop-A : MereProposition(A) ⦄ → (∀{x : Obj} → Pred(x) → A) → ∃(Pred) → A
[∃]-elim = HTrunc₁-function ∘ Logic.[∃]-elim
instance
[∃]-prop : MereProposition(∃ Pred)
[∃]-prop = HTrunc₁-prop
| {
"alphanum_fraction": 0.5948387097,
"avg_line_length": 26.724137931,
"ext": "agda",
"hexsha": "da71e1cdd0b3cc7e8b62d2e9c96521759a1c3fff",
"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": "Type/Cubical/Logic.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": "Type/Cubical/Logic.agda",
"max_line_length": 85,
"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": "Type/Cubical/Logic.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": 663,
"size": 1550
} |
{-# OPTIONS --type-in-type #-}
module dyn.fib where
open import prelude
open import functors
open import prelude.Stream using (take)
open import prelude.io
open import dyn
fib : Dyn
fib = (plus ⊠⊠⊠ delay ℕ) ⟫
λ ( f , f₋ ) → f₋ , λ (.tt)
→ ((f₋ , f) , f )
where plus = fun→dyn (uncurry _ℕ+_)
main : IO ⊤
main = printStream (run fib auto (1 , 1))
| {
"alphanum_fraction": 0.5789473684,
"avg_line_length": 21.1111111111,
"ext": "agda",
"hexsha": "aff36861f7c7ad2d4e69910f05db337b9bc05d62",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-30T11:45:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-07-10T17:19:37.000Z",
"max_forks_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dspivak/poly",
"max_forks_repo_path": "code-examples/agda/dyn/fib.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_issues_repo_issues_event_max_datetime": "2022-01-12T10:06:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-02T02:29:39.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dspivak/poly",
"max_issues_repo_path": "code-examples/agda/dyn/fib.agda",
"max_line_length": 42,
"max_stars_count": 53,
"max_stars_repo_head_hexsha": "425de958985aacbd3284d3057fe21fd682e315ea",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mstone/poly",
"max_stars_repo_path": "code-examples/agda/dyn/fib.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T23:08:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-18T16:31:04.000Z",
"num_tokens": 138,
"size": 380
} |
open import Categories.Category
import Categories.Functor as Fun
open import Categories.Monad
open import Categories.Object.BinaryCoproducts
import Categories.Normalise as Nm
module Categories.Monad.Coproduct {o ℓ e} (C : Category o ℓ e) (coprod : BinCoproducts C) where
open Category C
open Equiv
open BinCoproducts C coprod
module Internal where
module +Reasoning = Nm.+Reasoning C coprod
{- ----------------------------------------------------------------------------
Functoriality of left
---------------------------------------------------------------------------- -}
.left-id : ∀ {X Y} → left id ≡ id {X ∐ Y}
left-id {X} {Y} = by computation {↑ X ⊎ ↑ Y} (#left #id) #id
where
open +Reasoning
.left-∘ : ∀ {X Y Z W} {f : X ⇒ Y} {g : Y ⇒ Z} → left {C = W} (g ∘ f) ≡ left g ∘ left f
left-∘ {X} {Y} {Z} {W} {f = f} {g} =
by computation {↑ X ⊎ ↑ W}
(#left (↑↑ g #∘ ↑↑ f))
(#left (↑↑ g) #∘ #left (↑↑ f))
where
open +Reasoning
.left-resp-≡ : ∀ {x y z} → {f g : x ⇒ y} → f ≡ g → left {C = z} f ≡ left {C = z} g
left-resp-≡ {f = f} {g} p =
begin
[ i₁ ∘ f , i₂ ∘ id ]
↓⟨ []-cong₂ (∘-resp-≡ʳ p) refl ⟩
[ i₁ ∘ g , i₂ ∘ id ]
∎
where
open HomReasoning
{- ----------------------------------------------------------------------------
Functoriality of right
---------------------------------------------------------------------------- -}
.right-id : ∀ {X Y} → right id ≡ id {X ∐ Y}
right-id {X} {Y} = by computation {↑ X ⊎ ↑ Y} (#right #id) #id
where
open +Reasoning
.right-∘ : ∀ {X Y Z W} {f : X ⇒ Y} {g : Y ⇒ Z} → right {A = W} (g ∘ f) ≡ right g ∘ right f
right-∘ {X} {W = W} {f = f} {g} = by computation {↑ W ⊎ ↑ X}
(#right (↑↑ g #∘ ↑↑ f))
(#right (↑↑ g) #∘ #right (↑↑ f))
where
open +Reasoning
.right-resp-≡ : ∀ {x y z} → {f g : x ⇒ y} → f ≡ g → right {A = z} f ≡ right {A = z} g
right-resp-≡ {f = f} {g} p =
begin
[ i₁ ∘ id , i₂ ∘ f ]
↓⟨ []-cong₂ refl (∘-resp-≡ʳ p) ⟩
[ i₁ ∘ id , i₂ ∘ g ]
∎
where
open HomReasoning
{- ----------------------------------------------------------------------------
Left/Right functors
---------------------------------------------------------------------------- -}
Left : Obj → Fun.Functor C C
Left A =
record
{ F₀ = λ X → X ∐ A
; F₁ = left
; identity = left-id
; homomorphism = left-∘
; F-resp-≡ = left-resp-≡
}
Right : Obj → Fun.Functor C C
Right A =
record
{ F₀ = _∐_ A
; F₁ = right
; identity = right-id
; homomorphism = right-∘
; F-resp-≡ = right-resp-≡
}
private module I = Internal
{- ----------------------------------------------------------------------------
Left/Right monads
---------------------------------------------------------------------------- -}
Left : Obj -> Monad C
Left c =
record
{ F = I.Left c
; η = unit
; μ = join
; assoc = (λ {x} → by computation {#Left (#Left (#Left (↑ x)))}
(#join #∘ #left #join)
(#join #∘ #join))
; identityˡ = λ {x} → by computation {#Left (↑ x)} (#join #∘ #left #i₁) #id
; identityʳ = λ {x} → by computation {#Left (↑ x)} (#join #∘ #i₁) #id
}
module Left where
open I.+Reasoning
#Left = λ x → x ⊎ ↑ c
unit = record { η = λ X → i₁
; commute = λ {X} {Y} f → by computation {↑ X} {#Left (↑ Y)}
(#i₁ #∘ ↑↑ f) (#left (↑↑ f) #∘ #i₁)
}
#join : ∀ {A} -> Term (#Left (#Left A)) (#Left A)
#join = #[ #id , #i₂ ]
join = record { η = λ X → [ id , i₂ ]
; commute = λ {X} {Y} f → by computation {#Left (#Left (↑ X))}
(#join #∘ #left (#left (↑↑ f)))
(#left (↑↑ f) #∘ #join)
}
Right : Obj -> Monad C
Right c =
record
{ F = I.Right c
; η = unit
; μ = join
; assoc = (λ {x} → by computation {#Right (#Right (#Right (↑ x)))}
(#join #∘ #right #join)
(#join #∘ #join))
; identityˡ = λ {x} → by computation {#Right (↑ x)} (#join #∘ #right #i₂) #id
; identityʳ = λ {x} → by computation {#Right (↑ x)} (#join #∘ #i₂) #id
}
module Right where
open I.+Reasoning
#Right = λ x → ↑ c ⊎ x
unit = record { η = λ X → i₂
; commute = λ {X} {Y} f → by computation {↑ X} {#Right (↑ Y)}
(#i₂ #∘ ↑↑ f) (#right (↑↑ f) #∘ #i₂)
}
#join : ∀ {A} -> Term (#Right (#Right A)) (#Right A)
#join = #[ #i₁ , #id ]
join = record { η = λ X → [ i₁ , id ]
; commute = λ {X} {Y} f → by computation {#Right (#Right (↑ X))}
(#join #∘ #right (#right (↑↑ f)))
(#right (↑↑ f) #∘ #join)
}
| {
"alphanum_fraction": 0.3677596701,
"avg_line_length": 30.8666666667,
"ext": "agda",
"hexsha": "7a254cdf4a03d8cf8bc05f5415bc50583bf0c076",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "p-pavel/categories",
"max_forks_repo_path": "Categories/Monad/Coproduct.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "e41aef56324a9f1f8cf3cd30b2db2f73e01066f2",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "p-pavel/categories",
"max_issues_repo_path": "Categories/Monad/Coproduct.agda",
"max_line_length": 96,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Monad/Coproduct.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 1649,
"size": 5093
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Product where
open import Level
open import Function using () renaming (_∘_ to _∙_)
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂; zip; map; <_,_>; swap)
open import Categories.Utils.Product
open import Categories.Category using (Category)
open import Categories.Category.Groupoid using (IsGroupoid)
open import Categories.Functor renaming (id to idF)
open import Categories.NaturalTransformation.Core
open import Categories.NaturalTransformation.NaturalIsomorphism hiding (refl)
import Categories.Morphism as Morphism
private
variable
o ℓ e o′ ℓ′ e′ o″ ℓ″ e″ : Level
o₁ ℓ₁ e₁ o′₁ ℓ′₁ e′₁ o₂ ℓ₂ e₂ o′₂ ℓ′₂ e′₂ : Level
C C₁ C₂ D D₁ D₂ : Category o ℓ e
Product : (C : Category o ℓ e) (D : Category o′ ℓ′ e′) → Category (o ⊔ o′) (ℓ ⊔ ℓ′) (e ⊔ e′)
Product C D = record
{ Obj = C.Obj × D.Obj
; _⇒_ = C._⇒_ -< _×_ >- D._⇒_
; _≈_ = C._≈_ -< _×_ >- D._≈_
; _∘_ = zip C._∘_ D._∘_
; id = C.id , D.id
; assoc = C.assoc , D.assoc
; sym-assoc = C.sym-assoc , D.sym-assoc
; identityˡ = C.identityˡ , D.identityˡ
; identityʳ = C.identityʳ , D.identityʳ
; identity² = C.identity² , D.identity²
; equiv = record
{ refl = C.Equiv.refl , D.Equiv.refl
; sym = map C.Equiv.sym D.Equiv.sym
; trans = zip C.Equiv.trans D.Equiv.trans
}
; ∘-resp-≈ = zip C.∘-resp-≈ D.∘-resp-≈
}
where module C = Category C
module D = Category D
-- product of functors sharing the same domain
infixr 2 _※_
_※_ : ∀ (F : Functor C D₁) → (G : Functor C D₂) → Functor C (Product D₁ D₂)
F ※ G = record
{ F₀ = < F.F₀ , G.F₀ >
; F₁ = < F.F₁ , G.F₁ >
; identity = F.identity , G.identity
; homomorphism = F.homomorphism , G.homomorphism
; F-resp-≈ = < F.F-resp-≈ , G.F-resp-≈ >
}
where module F = Functor F
module G = Functor G
-- general product of functors
infixr 2 _⁂_
_⁂_ : ∀ (F₁ : Functor C₁ D₁) (F₂ : Functor C₂ D₂) → Functor (Product C₁ C₂) (Product D₁ D₂)
F ⁂ G = record
{ F₀ = map F.F₀ G.F₀
; F₁ = map F.F₁ G.F₁
; identity = F.identity , G.identity
; homomorphism = F.homomorphism , G.homomorphism
; F-resp-≈ = map F.F-resp-≈ G.F-resp-≈
}
where module F = Functor F
module G = Functor G
-- Natural Transformations respect the ⁂ product
infixr 5 _⁂ⁿ_
_⁂ⁿ_ : ∀ {C₁ : Category o₁ ℓ₁ e₁} {D₁ : Category o′₁ ℓ′₁ e′₁}
{C₂ : Category o₂ ℓ₂ e₂} {D₂ : Category o′₂ ℓ′₂ e′₂}
{F₁ G₁ : Functor C₁ D₁} {F₂ G₂ : Functor C₂ D₂}
(α : NaturalTransformation F₁ G₁) (β : NaturalTransformation F₂ G₂) →
NaturalTransformation (F₁ ⁂ F₂) (G₁ ⁂ G₂)
α ⁂ⁿ β = ntHelper record
{ η = map⁎′ α.η β.η
; commute = map⁎′ α.commute β.commute
}
where module α = NaturalTransformation α
module β = NaturalTransformation β
-- Natural Transformations respect the ※ product as well
infixr 5 _※ⁿ_
_※ⁿ_ : ∀ {D₁ : Category o ℓ e} {D₂ : Category o′ ℓ′ e′}
{F₁ G₁ : Functor C D₁} {F₂ G₂ : Functor C D₂}
(α : NaturalTransformation F₁ G₁) →
(β : NaturalTransformation F₂ G₂) →
NaturalTransformation (F₁ ※ F₂) (G₁ ※ G₂)
α ※ⁿ β = ntHelper record
{ η = < α.η , β.η >
; commute = < α.commute , β.commute >
}
where module α = NaturalTransformation α
module β = NaturalTransformation β
-- Natural Isomorphisms too
infixr 5 _⁂ⁿⁱ_
_⁂ⁿⁱ_ : ∀ {C₁ : Category o₁ ℓ₁ e₁} {D₁ : Category o′₁ ℓ′₁ e′₁}
{C₂ : Category o₂ ℓ₂ e₂} {D₂ : Category o′₂ ℓ′₂ e′₂}
{F₁ G₁ : Functor C₁ D₁} {F₂ G₂ : Functor C₂ D₂}
(α : NaturalIsomorphism F₁ G₁) (β : NaturalIsomorphism F₂ G₂) →
NaturalIsomorphism (F₁ ⁂ F₂) (G₁ ⁂ G₂)
α ⁂ⁿⁱ β = record
{ F⇒G = α.F⇒G ⁂ⁿ β.F⇒G
; F⇐G = α.F⇐G ⁂ⁿ β.F⇐G
; iso = λ where
(X , Y) → record
{ isoˡ = isoˡ (α.iso X) , isoˡ (β.iso Y)
; isoʳ = isoʳ (α.iso X) , isoʳ (β.iso Y)
}
}
where module α = NaturalIsomorphism α
module β = NaturalIsomorphism β
open Morphism.Iso
-- Natural Isomorphisms too
infixr 5 _※ⁿⁱ_
_※ⁿⁱ_ : ∀ {D₁ : Category o ℓ e} {D₂ : Category o′ ℓ′ e′}
{F₁ G₁ : Functor C D₁} {F₂ G₂ : Functor C D₂}
(α : NaturalIsomorphism F₁ G₁) →
(β : NaturalIsomorphism F₂ G₂) →
NaturalIsomorphism (F₁ ※ F₂) (G₁ ※ G₂)
α ※ⁿⁱ β = record
{ F⇒G = α.F⇒G ※ⁿ β.F⇒G
; F⇐G = α.F⇐G ※ⁿ β.F⇐G
; iso = λ X → record
{ isoˡ = isoˡ (α.iso X) , isoˡ (β.iso X)
; isoʳ = isoʳ (α.iso X) , isoʳ (β.iso X)
}
}
where module α = NaturalIsomorphism α
module β = NaturalIsomorphism β
open Morphism.Iso
module _ (C₁ : Category o ℓ e) (C₂ : Category o′ ℓ′ e′) (C₃ : Category o″ ℓ″ e″) where
private
module C₁ = Category C₁
module C₂ = Category C₂
module C₃ = Category C₃
assocˡ : Functor (Product (Product C₁ C₂) C₃) (Product C₁ (Product C₂ C₃))
assocˡ = record
{ F₀ = < proj₁ ∙ proj₁ , < proj₂ ∙ proj₁ , proj₂ > >
; F₁ = < proj₁ ∙ proj₁ , < proj₂ ∙ proj₁ , proj₂ > >
; identity = C₁.Equiv.refl , C₂.Equiv.refl , C₃.Equiv.refl
; homomorphism = C₁.Equiv.refl , C₂.Equiv.refl , C₃.Equiv.refl
; F-resp-≈ = < proj₁ ∙ proj₁ , < proj₂ ∙ proj₁ , proj₂ > >
}
assocʳ : Functor (Product C₁ (Product C₂ C₃)) (Product (Product C₁ C₂) C₃)
assocʳ = record
{ F₀ = < < proj₁ , proj₁ ∙ proj₂ > , proj₂ ∙ proj₂ >
; F₁ = < < proj₁ , proj₁ ∙ proj₂ > , proj₂ ∙ proj₂ >
; identity = (C₁.Equiv.refl , C₂.Equiv.refl) , C₃.Equiv.refl
; homomorphism = (C₁.Equiv.refl , C₂.Equiv.refl) , C₃.Equiv.refl
; F-resp-≈ = < < proj₁ , proj₁ ∙ proj₂ > , proj₂ ∙ proj₂ >
}
module _ {C : Category o ℓ e} {D : Category o′ ℓ′ e′} where
private
module C = Category C
module D = Category D
πˡ : Functor (Product C D) C
πˡ = record
{ F₀ = proj₁
; F₁ = proj₁
; identity = refl
; homomorphism = refl
; F-resp-≈ = proj₁
}
where open C.Equiv using (refl)
πʳ : Functor (Product C D) D
πʳ = record
{ F₀ = proj₂
; F₁ = proj₂
; identity = refl
; homomorphism = refl
; F-resp-≈ = proj₂
}
where open D.Equiv using (refl)
Swap : Functor (Product C D) (Product D C)
Swap = record
{ F₀ = swap
; F₁ = swap
; identity = D.Equiv.refl , C.Equiv.refl
; homomorphism = D.Equiv.refl , C.Equiv.refl
; F-resp-≈ = swap
}
-- Groupoid Product
Groupoid-× : {C : Category o₁ ℓ₁ e₁} {D : Category o₂ ℓ₂ e₂}
→ IsGroupoid C → IsGroupoid D → IsGroupoid (Product C D)
Groupoid-× c₁ c₂ = record
{ _⁻¹ = map (IsGroupoid._⁻¹ c₁) (IsGroupoid._⁻¹ c₂)
; iso = record { isoˡ = Iso.isoˡ i₁ , Iso.isoˡ i₂
; isoʳ = Iso.isoʳ i₁ , Iso.isoʳ i₂
}
}
where
open Morphism
i₁ = IsGroupoid.iso c₁
i₂ = IsGroupoid.iso c₂
| {
"alphanum_fraction": 0.5684754522,
"avg_line_length": 33.0142180095,
"ext": "agda",
"hexsha": "16beb7221f632ee7ebc27ed9d94cdd816cf671d9",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Product.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Product.agda",
"max_line_length": 92,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 2727,
"size": 6966
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.HSpace
open import homotopy.EilenbergMacLane1 using (EM₁-level₁)
module homotopy.EM1HSpace where
module EM₁HSpace {i} (G : AbGroup i) where
private
module G = AbGroup G
emloop-commutes : (g g' : G.El) → emloop g ∙ emloop g' == emloop g' ∙ emloop g
emloop-commutes g g' =
emloop g ∙ emloop g'
=⟨ ! (emloop-comp' G.grp g g') ⟩
emloop (G.comp g g')
=⟨ ap (emloop' G.grp) (G.comm g g') ⟩
emloop (G.comp g' g)
=⟨ emloop-comp' G.grp g' g ⟩
emloop g' ∙ emloop g =∎
mult-loop : G.El → (x : EM₁ G.grp) → x == x
mult-loop g = EM₁-set-elim
{P = λ x → x == x}
{{λ x → has-level-apply (EM₁-level₁ G.grp) x x}}
(emloop g)
(λ g' → ↓-idf=idf-in' (emloop-commutes g g' ∙ ∙=∙' (emloop g') (emloop g)))
private
EM₁-endo-Ω-group : Group i
EM₁-endo-Ω-group = Ω^S-group 0 ⊙[ (EM₁ G.grp → EM₁ G.grp) , (λ x → x) ]
mult-hom : GroupHom G.grp EM₁-endo-Ω-group
mult-hom = record {f = λ= ∘ mult-loop; pres-comp = pres-comp}
where
abstract
pres-comp' : (g₁ g₂ : G.El) (x : EM₁ G.grp) →
mult-loop (G.comp g₁ g₂) x == mult-loop g₁ x ∙ mult-loop g₂ x
pres-comp' g₁ g₂ =
EM₁-prop-elim
{P = λ x → mult-loop (G.comp g₁ g₂) x == mult-loop g₁ x ∙ mult-loop g₂ x}
{{λ x → has-level-apply (has-level-apply (EM₁-level₁ G.grp) _ _) _ _}}
(emloop-comp g₁ g₂)
pres-comp : (g₁ g₂ : G.El)
→ λ= (mult-loop (G.comp g₁ g₂)) ==
Group.comp EM₁-endo-Ω-group (λ= (mult-loop g₁)) (λ= (mult-loop g₂))
pres-comp g₁ g₂ =
ap λ= (λ= (pres-comp' g₁ g₂)) ∙
=ₛ-out (λ=-∙ (mult-loop g₁) (mult-loop g₂))
module MultRec = EM₁Level₁Rec {G = G.grp} {C = EM₁ G.grp → EM₁ G.grp} (λ x → x) mult-hom
abstract
mult : EM₁ G.grp → EM₁ G.grp → EM₁ G.grp
mult = MultRec.f
mult-embase-β : mult embase ↦ (λ x → x)
mult-embase-β = MultRec.embase-β
{-# REWRITE mult-embase-β #-}
mult-emloop-β : ∀ g y → ap (λ x → mult x y) (emloop g) == mult-loop g y
mult-emloop-β g y =
ap (λ x → mult x y) (emloop g)
=⟨ ap-∘ (λ f → f y) mult (emloop g) ⟩
app= (ap mult (emloop g)) y
=⟨ ap (λ w → app= w y) (MultRec.emloop-β g) ⟩
app= (λ= (mult-loop g)) y
=⟨ app=-β (mult-loop g) y ⟩
mult-loop g y =∎
H-⊙EM₁ : HSpaceStructure (⊙EM₁ G.grp)
H-⊙EM₁ = from-alt-h-space $ record { μ = mult; unit-l = unit-l; unit-r = unit-r; coh = coh }
where
unit-l : (x : EM₁ G.grp) → mult embase x == x
unit-l x = idp
unit-r : (x : EM₁ G.grp) → mult x embase == x
unit-r = EM₁-set-elim
{P = λ x → mult x embase == x}
{{λ x → has-level-apply (EM₁-level₁ G.grp) (mult x embase) x}}
idp
(λ g → ↓-app=idf-in $
idp ∙' emloop g
=⟨ ∙'-unit-l (emloop g) ⟩
emloop g
=⟨ ! (mult-emloop-β g embase) ⟩
ap (λ z → mult z embase) (emloop g)
=⟨ ! (∙-unit-r (ap (λ z → mult z embase) (emloop g))) ⟩
ap (λ z → mult z embase) (emloop g) ∙ idp ∎)
coh : unit-l embase == unit-r embase
coh = idp
open HSpaceStructure H-⊙EM₁
| {
"alphanum_fraction": 0.5202598206,
"avg_line_length": 32.9897959184,
"ext": "agda",
"hexsha": "3cfecb41745c606125b68202cabbaf6823e0bc22",
"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": "theorems/homotopy/EM1HSpace.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": "theorems/homotopy/EM1HSpace.agda",
"max_line_length": 94,
"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": "theorems/homotopy/EM1HSpace.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": 1260,
"size": 3233
} |
module InstanceArgumentsConstraintsModule where
data Bool : Set where
true false : Bool
module M (A1 A2 B C : Set) (a1 : A1) (a2 : A2) where
record Class (R : Bool → Set) : Set where
field f : (t : Bool) → R t
open Class {{...}} public
instance
class1 : Class (λ _ → A1)
class1 = record { f = λ _ → a1 }
class2 : Class (λ _ → A2)
class2 = record { f = λ _ → a2 }
module N (A1 A2 B C : Set) (a1 : A1) (a2 : A2) where
postulate someF : A1 → C
open M A1 A2 B C a1 a2
test : C
test = someF (f true)
| {
"alphanum_fraction": 0.5719557196,
"avg_line_length": 18.6896551724,
"ext": "agda",
"hexsha": "4436f7f7d33447bdbae9e3c356133f2982a6edf2",
"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/InstanceArgumentsConstraintsModule.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/InstanceArgumentsConstraintsModule.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/Succeed/InstanceArgumentsConstraintsModule.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 205,
"size": 542
} |
------------------------------------------------------------------------
-- Properties of homogeneous binary relations
------------------------------------------------------------------------
module Relation.Binary where
open import Data.Product
open import Data.Sum
open import Data.Function
import Relation.Binary.PropositionalEquality.Core as PropEq
open import Relation.Binary.Consequences
open import Relation.Binary.Core as Core using (_≡_)
------------------------------------------------------------------------
-- Simple properties and equivalence relations
open Core public hiding (_≡_; refl; _≢_)
------------------------------------------------------------------------
-- Preorders
record IsPreorder {a : Set}
(_≈_ : Rel a) -- The underlying equality.
(_∼_ : Rel a) -- The relation.
: Set where
field
isEquivalence : IsEquivalence _≈_
-- Reflexivity is expressed in terms of an underlying equality:
reflexive : _≈_ ⇒ _∼_
trans : Transitive _∼_
∼-resp-≈ : _∼_ Respects₂ _≈_
module Eq = IsEquivalence isEquivalence
refl : Reflexive _∼_
refl = reflexive Eq.refl
record Preorder : Set₁ where
infix 4 _≈_ _∼_
field
carrier : Set
_≈_ : Rel carrier -- The underlying equality.
_∼_ : Rel carrier -- The relation.
isPreorder : IsPreorder _≈_ _∼_
open IsPreorder isPreorder public
------------------------------------------------------------------------
-- Setoids
-- Equivalence relations are defined in Relation.Binary.Core.
record Setoid : Set₁ where
infix 4 _≈_
field
carrier : Set
_≈_ : Rel carrier
isEquivalence : IsEquivalence _≈_
open IsEquivalence isEquivalence public
isPreorder : IsPreorder _≡_ _≈_
isPreorder = record
{ isEquivalence = PropEq.isEquivalence
; reflexive = reflexive
; trans = trans
; ∼-resp-≈ = PropEq.resp₂ _≈_
}
preorder : Preorder
preorder = record { isPreorder = isPreorder }
------------------------------------------------------------------------
-- Decidable equivalence relations
record IsDecEquivalence {a : Set} (_≈_ : Rel a) : Set where
field
isEquivalence : IsEquivalence _≈_
_≟_ : Decidable _≈_
open IsEquivalence isEquivalence public
record DecSetoid : Set₁ where
infix 4 _≈_
field
carrier : Set
_≈_ : Rel carrier
isDecEquivalence : IsDecEquivalence _≈_
open IsDecEquivalence isDecEquivalence public
setoid : Setoid
setoid = record { isEquivalence = isEquivalence }
open Setoid setoid public using (preorder)
------------------------------------------------------------------------
-- Partial orders
record IsPartialOrder {a : Set} (_≈_ _≤_ : Rel a) : Set where
field
isPreorder : IsPreorder _≈_ _≤_
antisym : Antisymmetric _≈_ _≤_
open IsPreorder isPreorder public
renaming (∼-resp-≈ to ≤-resp-≈)
record Poset : Set₁ where
infix 4 _≈_ _≤_
field
carrier : Set
_≈_ : Rel carrier
_≤_ : Rel carrier
isPartialOrder : IsPartialOrder _≈_ _≤_
open IsPartialOrder isPartialOrder public
preorder : Preorder
preorder = record { isPreorder = isPreorder }
------------------------------------------------------------------------
-- Strict partial orders
record IsStrictPartialOrder {a : Set} (_≈_ _<_ : Rel a) : Set where
field
isEquivalence : IsEquivalence _≈_
irrefl : Irreflexive _≈_ _<_
trans : Transitive _<_
<-resp-≈ : _<_ Respects₂ _≈_
module Eq = IsEquivalence isEquivalence
record StrictPartialOrder : Set₁ where
infix 4 _≈_ _<_
field
carrier : Set
_≈_ : Rel carrier
_<_ : Rel carrier
isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_
open IsStrictPartialOrder isStrictPartialOrder public
------------------------------------------------------------------------
-- Total orders
record IsTotalOrder {a : Set} (_≈_ _≤_ : Rel a) : Set where
field
isPartialOrder : IsPartialOrder _≈_ _≤_
total : Total _≤_
open IsPartialOrder isPartialOrder public
record TotalOrder : Set₁ where
infix 4 _≈_ _≤_
field
carrier : Set
_≈_ : Rel carrier
_≤_ : Rel carrier
isTotalOrder : IsTotalOrder _≈_ _≤_
open IsTotalOrder isTotalOrder public
poset : Poset
poset = record { isPartialOrder = isPartialOrder }
open Poset poset public using (preorder)
------------------------------------------------------------------------
-- Decidable total orders
record IsDecTotalOrder {a : Set} (_≈_ _≤_ : Rel a) : Set where
field
isTotalOrder : IsTotalOrder _≈_ _≤_
_≟_ : Decidable _≈_
_≤?_ : Decidable _≤_
private
module TO = IsTotalOrder isTotalOrder
open TO public hiding (module Eq)
module Eq where
isDecEquivalence : IsDecEquivalence _≈_
isDecEquivalence = record
{ isEquivalence = TO.isEquivalence
; _≟_ = _≟_
}
open IsDecEquivalence isDecEquivalence public
record DecTotalOrder : Set₁ where
infix 4 _≈_ _≤_
field
carrier : Set
_≈_ : Rel carrier
_≤_ : Rel carrier
isDecTotalOrder : IsDecTotalOrder _≈_ _≤_
private
module DTO = IsDecTotalOrder isDecTotalOrder
open DTO public hiding (module Eq)
totalOrder : TotalOrder
totalOrder = record { isTotalOrder = isTotalOrder }
open TotalOrder totalOrder public using (poset; preorder)
module Eq where
decSetoid : DecSetoid
decSetoid = record { isDecEquivalence = DTO.Eq.isDecEquivalence }
open DecSetoid decSetoid public
------------------------------------------------------------------------
-- Strict total orders
-- Note that these orders are decidable (see compare).
record IsStrictTotalOrder {a : Set} (_≈_ _<_ : Rel a) : Set where
field
isEquivalence : IsEquivalence _≈_
trans : Transitive _<_
compare : Trichotomous _≈_ _<_
<-resp-≈ : _<_ Respects₂ _≈_
_≟_ : Decidable _≈_
_≟_ = tri⟶dec≈ compare
isDecEquivalence : IsDecEquivalence _≈_
isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
module Eq = IsDecEquivalence isDecEquivalence
isStrictPartialOrder : IsStrictPartialOrder _≈_ _<_
isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = tri⟶irr <-resp-≈ Eq.sym compare
; trans = trans
; <-resp-≈ = <-resp-≈
}
open IsStrictPartialOrder isStrictPartialOrder using (irrefl)
record StrictTotalOrder : Set₁ where
infix 4 _≈_ _<_
field
carrier : Set
_≈_ : Rel carrier
_<_ : Rel carrier
isStrictTotalOrder : IsStrictTotalOrder _≈_ _<_
open IsStrictTotalOrder isStrictTotalOrder public
hiding (module Eq)
strictPartialOrder : StrictPartialOrder
strictPartialOrder =
record { isStrictPartialOrder = isStrictPartialOrder }
decSetoid : DecSetoid
decSetoid = record { isDecEquivalence = isDecEquivalence }
module Eq = DecSetoid decSetoid
| {
"alphanum_fraction": 0.5800360961,
"avg_line_length": 26.9775280899,
"ext": "agda",
"hexsha": "d5c03b88dbc38579b2947cbe5e8414129d797564",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Relation/Binary.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Relation/Binary.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Binary.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 1954,
"size": 7203
} |
{-
Day 2, 2nd part
-}
module a2b where
open import Agda.Builtin.IO using (IO)
open import Agda.Builtin.Unit using (⊤)
open import Agda.Builtin.String using (String; primShowNat; primStringAppend)
open import Agda.Builtin.Equality
open import Data.Nat
open import Data.Bool using (if_then_else_)
open import Data.List
open import Data.Maybe renaming (map to maybeMap)
postulate putStrLn : String → IO ⊤
{-# FOREIGN GHC import qualified Data.Text as T #-}
{-# COMPILE GHC putStrLn = putStrLn . T.unpack #-}
-- helper
shopMaybeNat : Maybe ℕ → String
shopMaybeNat (just n) = primShowNat n
shopMaybeNat nothing = "nothing"
data Command : Set where
forward : ℕ → Command
up : ℕ → Command
down : ℕ → Command
record Position : Set where
constructor pos
field
h : ℕ
d : ℕ
{- Alignment of the submarine, i.e. position and aim -}
record Alignment : Set where
constructor state
field
h : ℕ
d : ℕ
aim : ℕ
open Position
apply : Command → Alignment → Maybe Alignment
apply (forward x) (state h d aim) = just (state (h + x) (d + (x * aim)) aim)
apply (up x) (state h d aim) = if aim <ᵇ x
then nothing
else just (state h d ∣ aim - x ∣)
apply (down x) (state h d aim) = just (state h d (aim + x))
iterate : List Command → Alignment → Maybe Alignment
iterate [] a = just a
iterate (command ∷ list) a with apply command a
... | just a' = iterate list a'
... | nothing = nothing
doTask : List Command → Maybe ℕ
doTask list = let maybeResult = iterate list (state 0 0 0)
in maybeMap multiplyComponents maybeResult
where multiplyComponents : Alignment → ℕ
multiplyComponents (state h d aim) = h * d
input : List Command
input =
forward 2 ∷
forward 3 ∷
forward 5 ∷
forward 6 ∷
down 7 ∷
forward 8 ∷
forward 4 ∷
forward 7 ∷
forward 5 ∷
forward 5 ∷
down 4 ∷
down 9 ∷
forward 8 ∷
forward 5 ∷
up 5 ∷
down 5 ∷
forward 3 ∷
down 4 ∷
down 8 ∷
forward 9 ∷
down 1 ∷
up 9 ∷
down 7 ∷
up 7 ∷
up 1 ∷
forward 1 ∷
down 1 ∷
down 4 ∷
down 4 ∷
down 8 ∷
down 4 ∷
up 3 ∷
down 1 ∷
down 3 ∷
forward 7 ∷
down 6 ∷
forward 3 ∷
forward 5 ∷
forward 2 ∷
up 9 ∷
forward 7 ∷
up 5 ∷
down 3 ∷
forward 1 ∷
forward 2 ∷
down 3 ∷
down 8 ∷
down 3 ∷
forward 8 ∷
up 5 ∷
down 5 ∷
forward 3 ∷
down 5 ∷
forward 9 ∷
down 3 ∷
down 4 ∷
down 9 ∷
down 7 ∷
up 3 ∷
down 9 ∷
up 9 ∷
up 1 ∷
forward 3 ∷
up 4 ∷
down 3 ∷
forward 7 ∷
forward 7 ∷
up 7 ∷
forward 6 ∷
down 7 ∷
down 6 ∷
forward 2 ∷
forward 9 ∷
down 5 ∷
forward 4 ∷
up 6 ∷
down 1 ∷
down 9 ∷
down 9 ∷
forward 4 ∷
down 1 ∷
forward 6 ∷
down 1 ∷
down 5 ∷
down 4 ∷
down 4 ∷
forward 4 ∷
forward 9 ∷
up 1 ∷
down 2 ∷
down 8 ∷
down 5 ∷
down 8 ∷
down 8 ∷
up 2 ∷
forward 8 ∷
up 1 ∷
forward 4 ∷
down 5 ∷
down 1 ∷
up 2 ∷
forward 6 ∷
forward 9 ∷
forward 2 ∷
forward 6 ∷
forward 9 ∷
up 6 ∷
forward 9 ∷
up 4 ∷
down 7 ∷
up 6 ∷
forward 2 ∷
down 1 ∷
up 3 ∷
forward 1 ∷
forward 8 ∷
down 6 ∷
down 8 ∷
down 8 ∷
forward 8 ∷
forward 2 ∷
forward 2 ∷
down 2 ∷
up 1 ∷
down 9 ∷
up 9 ∷
down 9 ∷
up 3 ∷
forward 9 ∷
up 4 ∷
up 7 ∷
up 6 ∷
down 9 ∷
forward 1 ∷
down 3 ∷
down 4 ∷
forward 8 ∷
down 3 ∷
down 9 ∷
up 3 ∷
forward 2 ∷
up 5 ∷
down 3 ∷
forward 8 ∷
up 3 ∷
down 3 ∷
forward 2 ∷
forward 9 ∷
down 1 ∷
down 9 ∷
down 4 ∷
up 7 ∷
down 4 ∷
up 6 ∷
forward 5 ∷
down 6 ∷
forward 3 ∷
down 2 ∷
forward 1 ∷
forward 8 ∷
down 4 ∷
forward 1 ∷
up 7 ∷
forward 6 ∷
up 9 ∷
forward 6 ∷
down 3 ∷
forward 2 ∷
down 4 ∷
forward 6 ∷
down 3 ∷
down 6 ∷
down 1 ∷
down 1 ∷
down 5 ∷
forward 3 ∷
forward 9 ∷
forward 8 ∷
down 3 ∷
forward 7 ∷
up 9 ∷
forward 9 ∷
up 2 ∷
forward 4 ∷
up 3 ∷
forward 1 ∷
up 6 ∷
up 8 ∷
down 5 ∷
down 6 ∷
up 9 ∷
down 6 ∷
down 9 ∷
up 9 ∷
down 4 ∷
forward 5 ∷
up 2 ∷
down 3 ∷
up 3 ∷
down 1 ∷
forward 3 ∷
down 5 ∷
forward 7 ∷
down 6 ∷
down 7 ∷
down 5 ∷
forward 2 ∷
up 6 ∷
down 9 ∷
down 4 ∷
down 3 ∷
forward 9 ∷
up 8 ∷
forward 2 ∷
down 2 ∷
forward 4 ∷
up 6 ∷
down 4 ∷
up 8 ∷
down 7 ∷
down 2 ∷
up 6 ∷
up 4 ∷
down 2 ∷
forward 5 ∷
up 4 ∷
down 8 ∷
forward 3 ∷
forward 1 ∷
down 7 ∷
forward 8 ∷
forward 7 ∷
down 7 ∷
up 4 ∷
forward 8 ∷
down 5 ∷
up 9 ∷
forward 1 ∷
forward 4 ∷
forward 9 ∷
forward 7 ∷
down 9 ∷
up 9 ∷
down 1 ∷
down 7 ∷
forward 7 ∷
down 7 ∷
down 7 ∷
down 3 ∷
down 5 ∷
forward 3 ∷
down 2 ∷
forward 6 ∷
down 9 ∷
up 5 ∷
up 3 ∷
forward 5 ∷
down 6 ∷
down 1 ∷
forward 4 ∷
down 3 ∷
forward 8 ∷
down 7 ∷
forward 7 ∷
forward 7 ∷
up 7 ∷
up 2 ∷
up 3 ∷
forward 9 ∷
down 5 ∷
up 2 ∷
forward 5 ∷
up 5 ∷
forward 2 ∷
forward 2 ∷
down 8 ∷
forward 2 ∷
up 4 ∷
forward 1 ∷
forward 3 ∷
up 8 ∷
up 9 ∷
forward 5 ∷
down 1 ∷
up 8 ∷
down 4 ∷
down 8 ∷
up 4 ∷
forward 9 ∷
down 6 ∷
down 8 ∷
up 2 ∷
up 3 ∷
down 7 ∷
down 4 ∷
forward 5 ∷
down 6 ∷
forward 3 ∷
forward 3 ∷
forward 8 ∷
down 1 ∷
down 7 ∷
down 9 ∷
down 2 ∷
down 7 ∷
forward 7 ∷
down 7 ∷
down 6 ∷
up 6 ∷
forward 8 ∷
forward 5 ∷
up 5 ∷
down 2 ∷
up 8 ∷
up 4 ∷
down 9 ∷
up 2 ∷
forward 5 ∷
up 2 ∷
down 4 ∷
up 4 ∷
forward 2 ∷
forward 4 ∷
forward 9 ∷
forward 9 ∷
up 4 ∷
up 5 ∷
down 1 ∷
down 6 ∷
down 1 ∷
down 4 ∷
down 5 ∷
down 3 ∷
forward 3 ∷
down 9 ∷
forward 6 ∷
down 3 ∷
down 9 ∷
down 2 ∷
up 2 ∷
down 2 ∷
down 7 ∷
forward 9 ∷
down 3 ∷
down 3 ∷
down 2 ∷
down 3 ∷
forward 2 ∷
down 9 ∷
down 9 ∷
up 5 ∷
up 3 ∷
forward 4 ∷
up 7 ∷
forward 8 ∷
up 6 ∷
forward 7 ∷
down 7 ∷
down 1 ∷
forward 5 ∷
down 2 ∷
up 1 ∷
down 8 ∷
up 3 ∷
forward 2 ∷
up 9 ∷
down 1 ∷
down 3 ∷
down 6 ∷
down 2 ∷
down 7 ∷
up 2 ∷
forward 5 ∷
forward 7 ∷
down 2 ∷
forward 5 ∷
forward 4 ∷
forward 5 ∷
down 3 ∷
forward 7 ∷
down 7 ∷
forward 8 ∷
down 3 ∷
down 2 ∷
up 1 ∷
forward 6 ∷
down 4 ∷
down 2 ∷
forward 7 ∷
up 3 ∷
down 4 ∷
forward 2 ∷
up 6 ∷
down 3 ∷
up 6 ∷
up 8 ∷
down 9 ∷
up 6 ∷
forward 8 ∷
forward 9 ∷
forward 4 ∷
forward 7 ∷
down 2 ∷
forward 9 ∷
down 7 ∷
up 9 ∷
down 5 ∷
down 6 ∷
up 5 ∷
down 4 ∷
forward 8 ∷
forward 4 ∷
forward 4 ∷
down 6 ∷
forward 3 ∷
forward 6 ∷
down 9 ∷
down 9 ∷
up 2 ∷
forward 7 ∷
down 8 ∷
down 9 ∷
down 9 ∷
forward 7 ∷
forward 3 ∷
down 7 ∷
down 8 ∷
forward 8 ∷
down 6 ∷
down 5 ∷
down 9 ∷
down 3 ∷
forward 1 ∷
down 5 ∷
forward 2 ∷
forward 8 ∷
down 2 ∷
forward 6 ∷
forward 3 ∷
down 7 ∷
down 4 ∷
forward 8 ∷
forward 1 ∷
down 6 ∷
forward 9 ∷
forward 6 ∷
up 1 ∷
up 3 ∷
down 8 ∷
forward 1 ∷
up 5 ∷
down 4 ∷
forward 7 ∷
up 3 ∷
down 2 ∷
forward 1 ∷
forward 9 ∷
down 9 ∷
down 7 ∷
forward 8 ∷
down 4 ∷
up 3 ∷
down 4 ∷
forward 2 ∷
forward 6 ∷
down 7 ∷
forward 6 ∷
down 6 ∷
down 4 ∷
down 1 ∷
up 9 ∷
down 4 ∷
down 7 ∷
up 4 ∷
down 9 ∷
forward 6 ∷
down 3 ∷
forward 2 ∷
down 4 ∷
forward 3 ∷
down 5 ∷
up 9 ∷
forward 8 ∷
up 7 ∷
up 6 ∷
up 4 ∷
forward 1 ∷
down 1 ∷
forward 4 ∷
up 6 ∷
forward 5 ∷
forward 4 ∷
forward 5 ∷
up 6 ∷
down 1 ∷
forward 3 ∷
up 7 ∷
down 9 ∷
up 9 ∷
down 5 ∷
forward 6 ∷
forward 4 ∷
up 1 ∷
down 4 ∷
up 1 ∷
forward 3 ∷
forward 1 ∷
down 3 ∷
forward 7 ∷
down 2 ∷
forward 3 ∷
up 2 ∷
forward 8 ∷
down 3 ∷
up 9 ∷
down 5 ∷
forward 6 ∷
down 1 ∷
down 8 ∷
down 5 ∷
forward 1 ∷
down 6 ∷
up 2 ∷
forward 6 ∷
down 2 ∷
down 1 ∷
up 6 ∷
up 7 ∷
down 5 ∷
forward 7 ∷
forward 6 ∷
forward 6 ∷
down 7 ∷
forward 4 ∷
down 5 ∷
up 5 ∷
down 1 ∷
up 8 ∷
down 8 ∷
down 2 ∷
down 2 ∷
down 9 ∷
up 9 ∷
forward 2 ∷
forward 7 ∷
down 7 ∷
down 4 ∷
down 4 ∷
down 8 ∷
forward 5 ∷
forward 2 ∷
up 9 ∷
down 9 ∷
forward 7 ∷
up 9 ∷
down 2 ∷
down 7 ∷
up 2 ∷
up 8 ∷
forward 8 ∷
down 4 ∷
forward 3 ∷
forward 4 ∷
forward 6 ∷
forward 2 ∷
down 1 ∷
down 2 ∷
forward 2 ∷
up 1 ∷
down 1 ∷
forward 5 ∷
up 3 ∷
up 3 ∷
down 3 ∷
down 1 ∷
down 4 ∷
up 5 ∷
up 6 ∷
forward 5 ∷
up 7 ∷
forward 6 ∷
down 4 ∷
down 7 ∷
up 8 ∷
forward 1 ∷
down 5 ∷
up 4 ∷
up 3 ∷
up 5 ∷
down 1 ∷
up 5 ∷
forward 3 ∷
up 5 ∷
forward 2 ∷
forward 2 ∷
forward 5 ∷
forward 2 ∷
up 9 ∷
forward 4 ∷
down 1 ∷
down 3 ∷
down 5 ∷
up 2 ∷
down 8 ∷
forward 8 ∷
forward 9 ∷
down 1 ∷
down 3 ∷
forward 8 ∷
forward 2 ∷
down 2 ∷
down 1 ∷
up 7 ∷
forward 2 ∷
forward 8 ∷
down 9 ∷
forward 1 ∷
forward 4 ∷
down 7 ∷
down 4 ∷
up 7 ∷
down 3 ∷
down 1 ∷
down 4 ∷
up 7 ∷
down 6 ∷
forward 7 ∷
down 8 ∷
up 2 ∷
up 4 ∷
up 6 ∷
down 9 ∷
down 9 ∷
down 8 ∷
forward 6 ∷
up 3 ∷
up 1 ∷
forward 9 ∷
forward 6 ∷
up 4 ∷
up 2 ∷
up 7 ∷
forward 5 ∷
up 9 ∷
up 9 ∷
forward 9 ∷
up 6 ∷
down 1 ∷
down 3 ∷
forward 3 ∷
down 2 ∷
down 2 ∷
down 6 ∷
down 9 ∷
forward 3 ∷
forward 7 ∷
up 3 ∷
forward 3 ∷
down 5 ∷
forward 9 ∷
up 6 ∷
down 2 ∷
forward 8 ∷
down 3 ∷
up 5 ∷
down 6 ∷
forward 9 ∷
down 5 ∷
down 2 ∷
down 6 ∷
forward 8 ∷
forward 6 ∷
down 1 ∷
forward 6 ∷
up 1 ∷
up 7 ∷
down 4 ∷
down 7 ∷
forward 4 ∷
forward 7 ∷
down 4 ∷
forward 8 ∷
down 8 ∷
down 7 ∷
forward 9 ∷
down 1 ∷
down 3 ∷
down 6 ∷
forward 7 ∷
forward 6 ∷
forward 3 ∷
forward 8 ∷
down 5 ∷
down 3 ∷
up 1 ∷
down 9 ∷
down 8 ∷
forward 3 ∷
down 6 ∷
down 1 ∷
forward 5 ∷
forward 5 ∷
forward 9 ∷
up 5 ∷
down 6 ∷
up 9 ∷
down 7 ∷
down 6 ∷
up 1 ∷
forward 5 ∷
forward 7 ∷
forward 8 ∷
forward 7 ∷
forward 6 ∷
forward 3 ∷
forward 1 ∷
forward 2 ∷
up 4 ∷
forward 3 ∷
forward 4 ∷
forward 5 ∷
up 2 ∷
up 3 ∷
forward 4 ∷
down 9 ∷
up 4 ∷
forward 7 ∷
down 6 ∷
down 6 ∷
down 1 ∷
forward 2 ∷
down 2 ∷
forward 2 ∷
down 3 ∷
forward 7 ∷
forward 8 ∷
down 4 ∷
up 7 ∷
forward 7 ∷
down 7 ∷
forward 7 ∷
forward 9 ∷
down 7 ∷
up 2 ∷
down 3 ∷
forward 7 ∷
down 1 ∷
forward 8 ∷
forward 2 ∷
up 9 ∷
down 3 ∷
forward 2 ∷
up 4 ∷
forward 9 ∷
down 4 ∷
down 4 ∷
forward 4 ∷
down 2 ∷
down 9 ∷
forward 4 ∷
down 2 ∷
down 6 ∷
forward 9 ∷
forward 2 ∷
up 1 ∷
forward 2 ∷
forward 3 ∷
down 5 ∷
up 8 ∷
down 4 ∷
down 4 ∷
forward 7 ∷
down 2 ∷
up 6 ∷
down 9 ∷
forward 9 ∷
up 1 ∷
forward 3 ∷
down 5 ∷
forward 3 ∷
down 3 ∷
forward 4 ∷
up 3 ∷
down 6 ∷
down 7 ∷
down 4 ∷
down 8 ∷
down 4 ∷
down 5 ∷
up 9 ∷
up 1 ∷
down 7 ∷
up 3 ∷
up 3 ∷
down 3 ∷
up 4 ∷
up 6 ∷
forward 8 ∷
down 1 ∷
forward 7 ∷
forward 4 ∷
down 9 ∷
down 1 ∷
forward 7 ∷
forward 9 ∷
forward 1 ∷
down 3 ∷
down 2 ∷
forward 3 ∷
forward 2 ∷
down 7 ∷
forward 9 ∷
forward 6 ∷
up 9 ∷
down 2 ∷
forward 9 ∷
up 6 ∷
forward 8 ∷
up 1 ∷
down 5 ∷
down 8 ∷
forward 1 ∷
down 1 ∷
forward 9 ∷
up 1 ∷
forward 9 ∷
forward 1 ∷
forward 1 ∷
down 7 ∷
forward 3 ∷
forward 6 ∷
down 5 ∷
forward 7 ∷
forward 1 ∷
down 7 ∷
down 6 ∷
down 6 ∷
forward 5 ∷
up 6 ∷
down 6 ∷
forward 8 ∷
up 2 ∷
down 8 ∷
down 3 ∷
up 5 ∷
up 8 ∷
down 6 ∷
forward 4 ∷
forward 2 ∷
up 3 ∷
forward 5 ∷
forward 3 ∷
up 8 ∷
forward 6 ∷
up 8 ∷
forward 1 ∷
up 8 ∷
up 7 ∷
up 6 ∷
forward 2 ∷
down 9 ∷
down 9 ∷
forward 3 ∷
down 7 ∷
forward 3 ∷
down 6 ∷
forward 9 ∷
up 5 ∷
down 1 ∷
forward 7 ∷
down 1 ∷
down 5 ∷
down 9 ∷
forward 8 ∷
forward 9 ∷
forward 7 ∷
down 9 ∷
up 4 ∷
forward 5 ∷
down 5 ∷
forward 5 ∷
down 9 ∷
forward 9 ∷
forward 3 ∷
up 5 ∷
forward 8 ∷
up 5 ∷
down 1 ∷
forward 8 ∷
down 3 ∷
forward 6 ∷
up 9 ∷
forward 8 ∷
down 4 ∷
forward 3 ∷
down 5 ∷
forward 8 ∷
forward 9 ∷
forward 2 ∷
down 1 ∷
down 6 ∷
down 4 ∷
forward 9 ∷
up 2 ∷
down 3 ∷
down 6 ∷
down 3 ∷
down 9 ∷
down 1 ∷
up 6 ∷
down 2 ∷
down 7 ∷
up 5 ∷
forward 5 ∷
up 1 ∷
down 7 ∷
forward 6 ∷
up 6 ∷
down 2 ∷
down 3 ∷
forward 3 ∷
down 5 ∷
forward 8 ∷
down 9 ∷
down 7 ∷
down 8 ∷
up 7 ∷
down 1 ∷
forward 1 ∷
forward 1 ∷
down 2 ∷
up 4 ∷
forward 2 ∷
down 3 ∷
up 2 ∷
down 3 ∷
down 2 ∷
forward 7 ∷
down 1 ∷
up 7 ∷
down 2 ∷
down 1 ∷
forward 6 ∷
down 9 ∷
up 9 ∷
down 4 ∷
down 6 ∷
up 9 ∷
forward 7 ∷
forward 9 ∷
forward 7 ∷
down 4 ∷
down 1 ∷
forward 7 ∷
down 4 ∷
down 7 ∷
down 3 ∷
down 5 ∷
forward 3 ∷
down 8 ∷
forward 8 ∷
forward 7 ∷
forward 8 ∷
down 4 ∷
down 9 ∷
forward 2 ∷
forward 7 ∷
up 8 ∷
forward 4 ∷
down 6 ∷
up 8 ∷
down 2 ∷
forward 3 ∷
down 6 ∷
down 8 ∷
forward 8 ∷
forward 2 ∷
forward 9 ∷
up 6 ∷
forward 7 ∷
down 3 ∷
down 5 ∷
forward 8 ∷
forward 9 ∷
down 3 ∷
forward 3 ∷
forward 2 ∷
forward 3 ∷
down 8 ∷
up 9 ∷
up 5 ∷
up 2 ∷
up 6 ∷
up 1 ∷
up 1 ∷
up 5 ∷
forward 3 ∷
forward 2 ∷
down 3 ∷
forward 4 ∷
[]
main : IO ⊤
main = putStrLn (shopMaybeNat (doTask input))
private
-- checks from the exercise text
_ : apply (forward 5) (state 0 0 0) ≡ just (state 5 0 0)
_ = refl
_ : apply (down 5) (state 5 0 0) ≡ just (state 5 0 5)
_ = refl
_ : apply (forward 8) (state 5 0 5) ≡ just (state 13 (8 * 5) 5)
_ = refl
_ : apply (up 3) (state 13 40 5) ≡ just (state 13 40 2)
_ = refl
_ : apply (down 8) (state 13 40 2) ≡ just (state 13 40 10)
_ = refl
_ : apply (forward 2) (state 13 40 10) ≡ just (state 15 60 10)
_ = refl
-- submarine does not 'fly'
_ : apply (up 7) (state 13 2 2) ≡ nothing
_ = refl
| {
"alphanum_fraction": 0.5084313448,
"avg_line_length": 12.8309090909,
"ext": "agda",
"hexsha": "4de2b378cd81099f3a4b144a121025d624a95453",
"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": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felixwellen/adventOfCode",
"max_forks_repo_path": "a2b.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"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": "felixwellen/adventOfCode",
"max_issues_repo_path": "a2b.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "834bc9e291a76bdbcd58cbff9805161f1b1cfe71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felixwellen/adventOfCode",
"max_stars_repo_path": "a2b.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7761,
"size": 14114
} |
module Oscar.Class.Injectivity where
open import Oscar.Level
record Injectivity {a} {A : Set a} {b} {B : Set b} {ℓ₁} (_≋₁_ : A → B → Set ℓ₁)
{i} {I : Set i} {ℓ₂} (_≋₂_ : I → I → Set ℓ₂)
(f : I → A)
(g : I → B)
: Set (a ⊔ b ⊔ ℓ₁ ⊔ i ⊔ ℓ₂) where
field
injectivity : ∀ {x y} → f x ≋₁ g y → x ≋₂ y
open Injectivity ⦃ … ⦄ public
record Injectivityoid a b ℓ₁ i ℓ₂ : Set (lsuc (a ⊔ b ⊔ ℓ₁ ⊔ i ⊔ ℓ₂)) where
field
{A} : Set a
{B} : Set b
_≋₁_ : A → B → Set ℓ₁
I : Set i
_≋₂_ : I → I → Set ℓ₂
μₗ : I → A
μᵣ : I → B
`injectivity : ∀ {x y} → μₗ x ≋₁ μᵣ y → x ≋₂ y
| {
"alphanum_fraction": 0.447806354,
"avg_line_length": 25.4230769231,
"ext": "agda",
"hexsha": "9c6f5e8996cdb820cfc72b19e0d78e32072686e1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Class/Injectivity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Class/Injectivity.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Class/Injectivity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 308,
"size": 661
} |
-- {-# OPTIONS -v tc.lhs:100 #-}
module IrrelevantData where
data T (A : Set) : Set where
c : .A → T A
d : ∀ {A} → T A → A
d (c x) = x
-- needs to fail since x is irrelevant under c | {
"alphanum_fraction": 0.5698924731,
"avg_line_length": 18.6,
"ext": "agda",
"hexsha": "42c969f01e9c7b4fe595a512bb3c979a0286efdc",
"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/IrrelevantData.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/IrrelevantData.agda",
"max_line_length": 46,
"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/IrrelevantData.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": 68,
"size": 186
} |
{-# OPTIONS --prop --allow-unsolved-metas #-}
{-# TERMINATING #-}
makeloop : {P : Prop} → P → P
makeloop p = makeloop p
postulate
A : Set
B : A → Prop
record AB : Set where
constructor _,_
field
a : A
b : B a
open AB public
id : AB → AB
id ab = a ab , makeloop (b ab)
postulate
f : (id* : AB → AB) → A → Set
C : A → Set
C = f id
postulate
D : (C : A → Set) (a : A) (c : C a) → Set
-- Works if you either give the type of v (C u) or the second argument of D (u)
loops : (u : A) (v : _) → D C _ v
loops = {!!}
| {
"alphanum_fraction": 0.5447761194,
"avg_line_length": 16.2424242424,
"ext": "agda",
"hexsha": "a8a33dc607ab26a98e7fadbecacb0b964291fede",
"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/Issue4120.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/Issue4120.agda",
"max_line_length": 79,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue4120.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": 203,
"size": 536
} |
{-# OPTIONS --guardedness --cubical #-}
module Issue2799 where
open import Agda.Primitive.Cubical
open import Agda.Builtin.Cubical.Path
record Stream (A : Set) : Set where
coinductive
constructor _,_
field
head : A
tail : Stream A
open Stream
mapS : ∀ {A B} → (A → B) → Stream A → Stream B
head (mapS f xs) = f (head xs)
tail (mapS f xs) = mapS f (tail xs)
mapS-id : ∀ {A} {xs : Stream A} → mapS (λ x → x) xs ≡ xs
head (mapS-id {xs = xs} i) = head xs
tail (mapS-id {xs = xs} i) = mapS-id {xs = tail xs} i
| {
"alphanum_fraction": 0.6197718631,
"avg_line_length": 21.04,
"ext": "agda",
"hexsha": "37c9a75155bdeeb38ee86bba6f78f63f336059ff",
"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/Issue2799.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/Issue2799.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/Issue2799.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": 191,
"size": 526
} |
module half where
open import Relation.Binary.PropositionalEquality using (_≡_ ; refl)
open import Size
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
half : ℕ → ℕ
half zero = zero
half (suc zero) = zero
half (suc (suc i)) = suc (half i)
_ : half 5 ≡ 2
_ = refl
data ℕₛ (n : Size) : Set where
zero : ℕₛ n
suc : (m : Size< n) → ℕₛ m → ℕₛ n
_ : ∀ {n} → ℕₛ n
_ = zero
_ : ∀ {n} (m : Size< n) → ℕₛ m → ℕₛ n
_ = suc
halfₛ : ∀ n → ℕₛ n → ℕₛ n
halfₛ n zero = zero
halfₛ n (suc m zero) = zero
halfₛ n (suc m (suc k i)) = suc k (halfₛ k i)
| {
"alphanum_fraction": 0.573943662,
"avg_line_length": 16.2285714286,
"ext": "agda",
"hexsha": "4df67933ac16d89064b44ba83ae4c5b647b1f0c2",
"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": "a6b4cf13104112c76a07d17a9dd18f3d3589d449",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis",
"max_forks_repo_path": "slides/agda/half.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a6b4cf13104112c76a07d17a9dd18f3d3589d449",
"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": "JLimperg/msc-thesis",
"max_issues_repo_path": "slides/agda/half.agda",
"max_line_length": 68,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "a6b4cf13104112c76a07d17a9dd18f3d3589d449",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis",
"max_stars_repo_path": "slides/agda/half.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-14T01:30:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-14T01:30:46.000Z",
"num_tokens": 246,
"size": 568
} |
module UnquoteDecl where
open import Common.Prelude
open import Common.Reflection
open import Common.Equality
open import Agda.Builtin.Sigma
infixr 3 _`⇒_
pattern _`⇒_ a b = pi (vArg a) (abs "_" b)
pattern `Nat = def (quote Nat) []
unquoteDecl x =
define (vArg x) (funDef `Nat (clause [] [] (quoteTerm 15) ∷ []))
y = x + 4
-- unquoteDecl loop = define loop (funDef `Nat (clause [] (def (quote loop) []) ∷ []))
pattern `zero = con (quote zero) []
pattern `suc n = con (quote suc) (vArg n ∷ [])
-- Note that in the body of the unquote, 'plus' really means 'quote plus'.
unquoteDecl plus =
define (vArg plus) (
funDef (`Nat `⇒ `Nat `⇒ `Nat)
( clause (("y" , vArg unknown) ∷ []) (vArg (con (quote zero) []) ∷ vArg (var 0) ∷ []) (var 0 [])
∷ clause (("y" , vArg unknown) ∷ ("x" , vArg unknown) ∷ [])
(vArg (con (quote suc) (vArg (var 1) ∷ [])) ∷ vArg (var 0) ∷ [])
(`suc (def plus (vArg (var 1 []) ∷ vArg (var 0 []) ∷ [])))
∷ []))
prf : plus 1 1 ≡ 2
prf = refl
magicDef : FunDef
magicDef =
funDef (def (quote ⊥) [] `⇒ `Nat)
(absurdClause (("()" , vArg unknown) ∷ []) (vArg absurd ∷ []) ∷ [])
unquoteDecl magic = define (vArg magic) magicDef
| {
"alphanum_fraction": 0.5586319218,
"avg_line_length": 29.2380952381,
"ext": "agda",
"hexsha": "f5398bca992070674b9e688660de7c59893dccae",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/UnquoteDecl.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"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": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/UnquoteDecl.agda",
"max_line_length": 105,
"max_stars_count": null,
"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/UnquoteDecl.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 437,
"size": 1228
} |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Congruity
open import Oscar.Class.Reflexivity
open import Oscar.Class.Symmetry
open import Oscar.Class.Transitivity
open import Oscar.Class.HasEquivalence
open import Oscar.Class.Transassociativity
open import Oscar.Class.Transleftidentity
open import Oscar.Class.Transrightidentity
open import Oscar.Class.IsPrecategory
open import Oscar.Class.IsCategory
open import Oscar.Class.Precategory
open import Oscar.Class.Category
open import Oscar.Data.¶
open import Oscar.Data.Descender
open import Oscar.Data.Proposequality
import Oscar.Property.Setoid.Proposequality
import Oscar.Class.Congruity.Proposequality
import Oscar.Class.Transextensionality.Proposequality
import Oscar.Data.Constraint
module Oscar.Property.Category.AListProposequality where
module _ {a} {A : ¶ → Set a} where
private AList = Descender⟨ A ⟩
instance
𝓡eflexivityAList : Reflexivity.class AList
𝓡eflexivityAList .⋆ = ∅
𝓣ransitivityAList : Transitivity.class AList
𝓣ransitivityAList .⋆ f ∅ = f
𝓣ransitivityAList .⋆ f (x , g) =
let _∙'_ = λ g f → 𝓣ransitivityAList .⋆ f g in -- FIXME needed to help Agda prove termination
x , g ∙' f
𝓣ransitivityAList' : Transitivity.class (flip AList)
𝓣ransitivityAList' .⋆ f g = transitivity g f
HasEquivalenceAList : ∀ {m n} → HasEquivalence (AList m n) _
HasEquivalenceAList = ∁ Proposequality
𝓣ransassociativityAList : Transassociativity.class AList Proposequality transitivity
𝓣ransassociativityAList .⋆ f g ∅ = ∅
𝓣ransassociativityAList .⋆ f g (x , h) = congruity (x ,_) $ 𝓣ransassociativityAList .⋆ _ _ h -- h ⟨∙ _ ⟨∙ _
𝓣ransassociativityAList' : Transassociativity.class (flip AList) Proposequality transitivity
𝓣ransassociativityAList' .⋆ f g h = symmetry (transassociativity h g f) -- Sym.[] {!!}
IsPrecategoryAList : IsPrecategory AList Proposequality transitivity
IsPrecategoryAList = ∁
IsPrecategoryAList' : IsPrecategory (flip AList) Proposequality transitivity
IsPrecategoryAList' = ∁
𝓣ransleftidentityAList : Transleftidentity.class AList Proposequality ε transitivity
𝓣ransleftidentityAList .⋆ = ∅
𝓣ransrightidentityAList : Transrightidentity.class AList Proposequality ε transitivity
𝓣ransrightidentityAList .⋆ {f = ∅} = ∅
𝓣ransrightidentityAList .⋆ {f = x , f} rewrite 𝓣ransrightidentityAList .⋆ {f = f} = ∅
-- 𝓣ransrightidentityAList .⋆ {f = x , f} = congruity (x ,_) (transrightidentity {_∼_ = AList} {_∼̇_ = Proposequality})
-- 𝓣ransrightidentityAList .⋆ {f = x , f} rewrite (f ∙ ε[ AList ] ≡ f) ∋ transrightidentity {_∼_ = AList} = ∅
𝓣ransleftidentityAList' : Transleftidentity.class (flip AList) Proposequality ε transitivity
𝓣ransleftidentityAList' .⋆ = transrightidentity {_∼_ = AList}
𝓣ransrightidentityAList' : Transrightidentity.class (flip AList) Proposequality ε transitivity
𝓣ransrightidentityAList' .⋆ = transleftidentity {_∼_ = AList}
IsCategoryAList : IsCategory AList Proposequality ε transitivity
IsCategoryAList = ∁
IsCategoryAList' : IsCategory (flip AList) Proposequality ε transitivity
IsCategoryAList' = ∁
module _ {a} (A : ¶ → Ø a) where
private AList = Descender⟨ A ⟩
PrecategoryAListProposequality : Precategory _ _ _
PrecategoryAListProposequality = ∁ AList Proposequality transitivity
CategoryAListProposequality : Category _ _ _
CategoryAListProposequality = ∁ AList Proposequality ε transitivity
PrecategoryAList'Proposequality : Precategory _ _ _
PrecategoryAList'Proposequality = ∁ (flip AList) Proposequality transitivity
CategoryAList'Proposequality : Category _ _ _
CategoryAList'Proposequality = ∁ (flip AList) Proposequality ε transitivity
| {
"alphanum_fraction": 0.7548472776,
"avg_line_length": 39.21875,
"ext": "agda",
"hexsha": "5c08bb4470ccd47a2c61d167cfdecfd6342579a4",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Property/Category/AListProposequality.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Property/Category/AListProposequality.agda",
"max_line_length": 123,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Property/Category/AListProposequality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1187,
"size": 3765
} |
-- Andreas, 2017-10-06, issue #2751
-- Highlighting for unsolved constraints
module _ where
open import Agda.Builtin.Size
module UnsolvedSizeConstraints where
mutual
data D (i : Size) (A : Set) : Set where
c : D′ i A → D i A
record D′ (i : Size) (A : Set) : Set where
inductive
field
size : Size< i
force : D size A
open D′
Map : (F : Set → Set) → Set₁
Map F = {A B : Set} → F A → F B
mutual
map-D : ∀ {i} → Map (D i)
map-D (c xs) = c (map-D′ xs)
map-D′ : ∀ {i} → Map (D′ i)
size (map-D′ {i} t) = foo where postulate foo : {!Size< i!}
force (map-D′ {i} t) = map-D {i = i} (force t) -- correct is i = foo
-- Produces an unsolved size constraint.
-- Problem WAS: no highlighting for unsolved constraints.
-- Now: yellow highlighting in last rhs.
-- Test also highlighting for unsolved level constraints:
module UnsolvedLevelConstraints where
mutual
l = _
data D {a} (A : Set a) : Set l where
c : A → D A -- highlighted
data E (A : Set l) : Set1 where
c : A → E A -- highlighted
| {
"alphanum_fraction": 0.5740236149,
"avg_line_length": 21.5882352941,
"ext": "agda",
"hexsha": "6b8478d40b213f3520b7ae30d39dfb5ada9b9dbd",
"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": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/interaction/Issue2751.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"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": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2751.agda",
"max_line_length": 76,
"max_stars_count": null,
"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/Issue2751.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 365,
"size": 1101
} |
open import Prelude
open import Data.Vec
open import Data.List.Properties
open import Data.List.Any hiding (map)
open import Data.List.All as All using ()
open import Extensions.Vec
open import Data.Product hiding (map)
module Implicits.Resolution.Ambiguous.Semantics where
open import Implicits.Syntax
open import Implicits.Resolution.Ambiguous.Resolution
open import Implicits.Substitutions
open import Implicits.Substitutions.Lemmas
open import Implicits.Semantics
open import Implicits.Semantics.Lemmas
open import SystemF.Everything as F using ()
module DerivationSemantics where
⟦_,_⟧r : ∀ {ν n} {Δ} {Γ : Ctx ν n} {a} → Δ ⊢ᵣ a → Γ # Δ →
∃ λ t → ⟦ Γ ⟧ctx→ F.⊢ t ∈ ⟦ a ⟧tp→
⟦_,_⟧r (r-tabs {r = r} p) m with ⟦ p , #tvar m ⟧r
⟦_,_⟧r {Γ = Γ} (r-tabs {r = r} p) m | _ , x =
, F.Λ (subst (λ u → u F.⊢ _ ∈ ⟦ r ⟧tp→) (⟦weaken⟧ctx→ Γ) x)
⟦_,_⟧r (r-tapp a p) m with ⟦ p , m ⟧r
⟦_,_⟧r {Γ = Γ} (r-tapp {r = a} b p) m | _ , x =
, subst
(λ u → ⟦ Γ ⟧ctx→ F.⊢ _ ∈ u)
(sym $ ⟦a/sub⟧tp→ a b)
(x F.[ ⟦ b ⟧tp→ ])
⟦_,_⟧r {Γ = Γ} {a = a} (r-ivar x) m with ∈⟶index (All.lookup m x)
⟦_,_⟧r {Γ = Γ} {a = a} (r-ivar x) m | i , lookup-i≡r =
, subst (λ u → _ F.⊢ F.var i ∈ u) eq (F.var i)
where
eq = begin
lookup i ⟦ Γ ⟧ctx→
≡⟨ sym $ lookup-⟦⟧ctx→ Γ i ⟩
⟦ lookup i Γ ⟧tp→
≡⟨ cong ⟦_⟧tp→ lookup-i≡r ⟩
⟦ a ⟧tp→ ∎
⟦_,_⟧r (r-iabs {a = a} p) m = , F.λ' ⟦ a ⟧tp→ (proj₂ ⟦ p , #ivar a m ⟧r)
⟦_,_⟧r (r-iapp p p₁) m = , (proj₂ ⟦ p , m ⟧r) F.· (proj₂ ⟦ p₁ , m ⟧r)
open Semantics _⊢ᵣ_ DerivationSemantics.⟦_,_⟧r public
| {
"alphanum_fraction": 0.5606720597,
"avg_line_length": 33.4791666667,
"ext": "agda",
"hexsha": "270016f1ba133a46fd5cab81e10d7c54b9c09d1f",
"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": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Implicits/Resolution/Ambiguous/Semantics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"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": "metaborg/ts.agda",
"max_issues_repo_path": "src/Implicits/Resolution/Ambiguous/Semantics.agda",
"max_line_length": 74,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Implicits/Resolution/Ambiguous/Semantics.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-07T04:08:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-04-05T17:57:11.000Z",
"num_tokens": 725,
"size": 1607
} |
-- Basic intuitionistic modal logic S4, without ∨, ⊥, or ◇.
-- Gentzen-style formalisation of labelled syntax, after Basin-Matthews-Viganò.
module BasicIS4.Syntax.LabelledGentzen where
open import BasicIS4.Syntax.Common public
-- Labels, as in Gabbay’s labelled deductive systems.
postulate
Label : Set
-- Label pairs, or relational access tokens.
-- x ↝ y means the world labelled y is accessible from the world labelled x.
infix 6 _↝_
record Token : Set where
constructor _↝_
field
x : Label
y : Label
-- Labelled types.
-- A ◎ x means the type A is inhabited at the world labelled x.
infix 6 _◎_
record LabelledTy : Set where
constructor _◎_
field
A : Ty
x : Label
infix 6 _◎⋆_
_◎⋆_ : Cx Ty → Label → Cx LabelledTy
∅ ◎⋆ x = ∅
(Ξ , A) ◎⋆ x = Ξ ◎⋆ x , A ◎ x
-- Derivations.
infix 3 _⊢ᴿ_
data _⊢ᴿ_ (Λ : Cx Token) : Token → Set where
rvar : ∀ {x y} → x ↝ y ∈ Λ → Λ ⊢ᴿ x ↝ y
rrefl : ∀ {x} → Λ ⊢ᴿ x ↝ x
rtrans : ∀ {x y z} → Λ ⊢ᴿ x ↝ y → Λ ⊢ᴿ y ↝ z → Λ ⊢ᴿ x ↝ z
infix 3 _⊢_
data _⊢_ : Cx² Ty Token → LabelledTy → Set where
var : ∀ {x A Γ Λ} → A ∈ Γ → Γ ⁏ Λ ⊢ A ◎ x
lam : ∀ {x A B Γ Λ} → Γ , A ⁏ Λ ⊢ B ◎ x → Γ ⁏ Λ ⊢ A ▻ B ◎ x
app : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ▻ B ◎ x → Γ ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ ⊢ B ◎ x
scan : ∀ {x A Γ Λ} → (∀ {y} → Γ ⁏ Λ , x ↝ y ⊢ A ◎ y) → Γ ⁏ Λ ⊢ □ A ◎ x
move : ∀ {x y A Γ Λ} → Γ ⁏ Λ ⊢ □ A ◎ x → Λ ⊢ᴿ x ↝ y → Γ ⁏ Λ ⊢ A ◎ y
pair : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ ⊢ B ◎ x → Γ ⁏ Λ ⊢ A ∧ B ◎ x
fst : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ∧ B ◎ x → Γ ⁏ Λ ⊢ A ◎ x
snd : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ∧ B ◎ x → Γ ⁏ Λ ⊢ B ◎ x
unit : ∀ {x Γ Λ} → Γ ⁏ Λ ⊢ ⊤ ◎ x
infix 3 _⊢⋆_
_⊢⋆_ : Cx² Ty Token → Cx LabelledTy → Set
Γ ⁏ Λ ⊢⋆ ∅ = 𝟙
Γ ⁏ Λ ⊢⋆ Ξ , A = Γ ⁏ Λ ⊢⋆ Ξ × Γ ⁏ Λ ⊢ A
-- Monotonicity with respect to context inclusion.
mono⊢ : ∀ {x A Γ Γ′ Λ} → Γ ⊆ Γ′ → Γ ⁏ Λ ⊢ A ◎ x → Γ′ ⁏ Λ ⊢ A ◎ x
mono⊢ η (var i) = var (mono∈ η i)
mono⊢ η (lam t) = lam (mono⊢ (keep η) t)
mono⊢ η (app t u) = app (mono⊢ η t) (mono⊢ η u)
mono⊢ η (scan t) = scan (mono⊢ η t)
mono⊢ η (move t u) = move (mono⊢ η t) u
mono⊢ η (pair t u) = pair (mono⊢ η t) (mono⊢ η u)
mono⊢ η (fst t) = fst (mono⊢ η t)
mono⊢ η (snd t) = snd (mono⊢ η t)
mono⊢ η unit = unit
mono⊢⋆ : ∀ {Ξ x Γ Γ′ Λ} → Γ ⊆ Γ′ → Γ ⁏ Λ ⊢⋆ Ξ ◎⋆ x → Γ′ ⁏ Λ ⊢⋆ Ξ ◎⋆ x
mono⊢⋆ {∅} η ∙ = ∙
mono⊢⋆ {Ξ , A} η (ts , t) = mono⊢⋆ η ts , mono⊢ η t
-- Monotonicity with respect to relational context inclusion.
rmono⊢ᴿ : ∀ {x y Λ Λ′} → Λ ⊆ Λ′ → Λ ⊢ᴿ x ↝ y → Λ′ ⊢ᴿ x ↝ y
rmono⊢ᴿ ρ (rvar i) = rvar (mono∈ ρ i)
rmono⊢ᴿ ρ rrefl = rrefl
rmono⊢ᴿ ρ (rtrans t u) = rtrans (rmono⊢ᴿ ρ t) (rmono⊢ᴿ ρ u)
rmono⊢ : ∀ {x A Γ Λ Λ′} → Λ ⊆ Λ′ → Γ ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ′ ⊢ A ◎ x
rmono⊢ ρ (var i) = var i
rmono⊢ ρ (lam t) = lam (rmono⊢ ρ t)
rmono⊢ ρ (app t u) = app (rmono⊢ ρ t) (rmono⊢ ρ u)
rmono⊢ ρ (scan t) = scan (rmono⊢ (keep ρ) t)
rmono⊢ ρ (move t u) = move (rmono⊢ ρ t) (rmono⊢ᴿ ρ u)
rmono⊢ ρ (pair t u) = pair (rmono⊢ ρ t) (rmono⊢ ρ u)
rmono⊢ ρ (fst t) = fst (rmono⊢ ρ t)
rmono⊢ ρ (snd t) = snd (rmono⊢ ρ t)
rmono⊢ ρ unit = unit
rmono⊢⋆ : ∀ {Ξ x Γ Λ Λ′} → Λ ⊆ Λ′ → Γ ⁏ Λ ⊢⋆ Ξ ◎⋆ x → Γ ⁏ Λ′ ⊢⋆ Ξ ◎⋆ x
rmono⊢⋆ {∅} ρ ∙ = ∙
rmono⊢⋆ {Ξ , A} ρ (ts , t) = rmono⊢⋆ ρ ts , rmono⊢ ρ t
-- Monotonicity using context pairs.
mono²⊢ : ∀ {x A Π Π′} → Π ⊆² Π′ → Π ⊢ A ◎ x → Π′ ⊢ A ◎ x
mono²⊢ (η , ρ) = mono⊢ η ∘ rmono⊢ ρ
-- Shorthand for variables.
v₀ : ∀ {x A Γ Λ} → Γ , A ⁏ Λ ⊢ A ◎ x
v₀ = var i₀
v₁ : ∀ {x A B Γ Λ} → Γ , A , B ⁏ Λ ⊢ A ◎ x
v₁ = var i₁
v₂ : ∀ {x A B C Γ Λ} → Γ , A , B , C ⁏ Λ ⊢ A ◎ x
v₂ = var i₂
rv₀ : ∀ {x y Λ} → Λ , x ↝ y ⊢ᴿ x ↝ y
rv₀ = rvar i₀
rv₁ : ∀ {x y x′ y′ Λ} → Λ , x ↝ y , x′ ↝ y′ ⊢ᴿ x ↝ y
rv₁ = rvar i₁
rv₂ : ∀ {x y x′ y′ x″ y″ Λ} → Λ , x ↝ y , x′ ↝ y′ , x″ ↝ y″ ⊢ᴿ x ↝ y
rv₂ = rvar i₂
-- Reflexivity.
refl⊢⋆ : ∀ {Γ x Λ} → Γ ⁏ Λ ⊢⋆ Γ ◎⋆ x
refl⊢⋆ {∅} = ∙
refl⊢⋆ {Γ , A} = mono⊢⋆ weak⊆ refl⊢⋆ , v₀
-- Deduction theorem is built-in.
lam⋆ : ∀ {Ξ x A Γ Λ} → Γ ⧺ Ξ ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ ⊢ Ξ ▻⋯▻ A ◎ x
lam⋆ {∅} = I
lam⋆ {Ξ , B} = lam⋆ {Ξ} ∘ lam
lam⋆₀ : ∀ {Γ x A Λ} → Γ ⁏ Λ ⊢ A ◎ x → ∅ ⁏ Λ ⊢ Γ ▻⋯▻ A ◎ x
lam⋆₀ {∅} = I
lam⋆₀ {Γ , B} = lam⋆₀ ∘ lam
-- Detachment theorem.
det : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ▻ B ◎ x → Γ , A ⁏ Λ ⊢ B ◎ x
det t = app (mono⊢ weak⊆ t) v₀
det⋆ : ∀ {Ξ x A Γ Λ} → Γ ⁏ Λ ⊢ Ξ ▻⋯▻ A ◎ x → Γ ⧺ Ξ ⁏ Λ ⊢ A ◎ x
det⋆ {∅} = I
det⋆ {Ξ , B} = det ∘ det⋆ {Ξ}
det⋆₀ : ∀ {Γ x A Λ} → ∅ ⁏ Λ ⊢ Γ ▻⋯▻ A ◎ x → Γ ⁏ Λ ⊢ A ◎ x
det⋆₀ {∅} = I
det⋆₀ {Γ , B} = det ∘ det⋆₀
-- Cut and multicut.
cut : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ◎ x → Γ , A ⁏ Λ ⊢ B ◎ x → Γ ⁏ Λ ⊢ B ◎ x
cut t u = app (lam u) t
multicut : ∀ {Ξ x A Γ Λ} → Γ ⁏ Λ ⊢⋆ Ξ ◎⋆ x → Ξ ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ ⊢ A ◎ x
multicut {∅} ∙ u = mono⊢ bot⊆ u
multicut {Ξ , B} (ts , t) u = app (multicut ts (lam u)) t
-- Transitivity.
trans⊢⋆ : ∀ {Γ″ x Γ′ Γ Λ} → Γ ⁏ Λ ⊢⋆ Γ′ ◎⋆ x → Γ′ ⁏ Λ ⊢⋆ Γ″ ◎⋆ x → Γ ⁏ Λ ⊢⋆ Γ″ ◎⋆ x
trans⊢⋆ {∅} ts ∙ = ∙
trans⊢⋆ {Γ″ , A} ts (us , u) = trans⊢⋆ ts us , multicut ts u
-- Contraction.
ccont : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ (A ▻ A ▻ B) ▻ A ▻ B ◎ x
ccont = lam (lam (app (app v₁ v₀) v₀))
cont : ∀ {x A B Γ Λ} → Γ , A , A ⁏ Λ ⊢ B ◎ x → Γ , A ⁏ Λ ⊢ B ◎ x
cont t = det (app ccont (lam (lam t)))
-- Exchange, or Schönfinkel’s C combinator.
cexch : ∀ {x A B C Γ Λ} → Γ ⁏ Λ ⊢ (A ▻ B ▻ C) ▻ B ▻ A ▻ C ◎ x
cexch = lam (lam (lam (app (app v₂ v₀) v₁)))
exch : ∀ {x A B C Γ Λ} → Γ , A , B ⁏ Λ ⊢ C ◎ x → Γ , B , A ⁏ Λ ⊢ C ◎ x
exch t = det (det (app cexch (lam (lam t))))
-- Composition, or Schönfinkel’s B combinator.
ccomp : ∀ {x A B C Γ Λ} → Γ ⁏ Λ ⊢ (B ▻ C) ▻ (A ▻ B) ▻ A ▻ C ◎ x
ccomp = lam (lam (lam (app v₂ (app v₁ v₀))))
comp : ∀ {x A B C Γ Λ} → Γ , B ⁏ Λ ⊢ C ◎ x → Γ , A ⁏ Λ ⊢ B ◎ x → Γ , A ⁏ Λ ⊢ C ◎ x
comp t u = det (app (app ccomp (lam t)) (lam u))
-- Useful theorems in functional form.
dist : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (A ▻ B) ◎ x → Γ ⁏ Λ ⊢ □ A ◎ x → Γ ⁏ Λ ⊢ □ B ◎ x
dist t u = scan (app (move (rmono⊢ weak⊆ t) rv₀) (move (rmono⊢ weak⊆ u) rv₀))
up : ∀ {x A Γ Λ} → Γ ⁏ Λ ⊢ □ A ◎ x → Γ ⁏ Λ ⊢ □ □ A ◎ x
up t = scan (scan (move (rmono⊢ (trans⊆ weak⊆ weak⊆) t) (rtrans rv₁ rv₀)))
down : ∀ {x A Γ Λ} → Γ ⁏ Λ ⊢ □ A ◎ x → Γ ⁏ Λ ⊢ A ◎ x
down t = move t rrefl
distup : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (□ A ▻ B) ◎ x → Γ ⁏ Λ ⊢ □ A ◎ x → Γ ⁏ Λ ⊢ □ B ◎ x
distup t u = dist t (up u)
box : ∀ {x A Γ Λ} → (∀ {y} → ∅ ⁏ Λ , x ↝ y ⊢ A ◎ y) → Γ ⁏ Λ ⊢ □ A ◎ x
box t = scan (mono⊢ bot⊆ t)
unbox : ∀ {x A C Γ Λ} → Γ ⁏ Λ ⊢ □ A ◎ x → Γ , □ A ⁏ Λ ⊢ C ◎ x → Γ ⁏ Λ ⊢ C ◎ x
unbox t u = app (lam u) t
-- Useful theorems in combinatory form.
ci : ∀ {x A Γ Λ} → Γ ⁏ Λ ⊢ A ▻ A ◎ x
ci = lam v₀
ck : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ▻ B ▻ A ◎ x
ck = lam (lam v₁)
cs : ∀ {x A B C Γ Λ} → Γ ⁏ Λ ⊢ (A ▻ B ▻ C) ▻ (A ▻ B) ▻ A ▻ C ◎ x
cs = lam (lam (lam (app (app v₂ v₀) (app v₁ v₀))))
cdist : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (A ▻ B) ▻ □ A ▻ □ B ◎ x
cdist = lam (lam (scan (app (move v₁ rv₀) (move v₀ rv₀))))
cup : ∀ {x A Γ Λ} → Γ ⁏ Λ ⊢ □ A ▻ □ □ A ◎ x
cup = lam (scan (scan (move v₀ (rtrans rv₁ rv₀))))
cdown : ∀ {x A Γ Λ} → Γ ⁏ Λ ⊢ □ A ▻ A ◎ x
cdown = lam (move v₀ rrefl)
cdistup : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (□ A ▻ B) ▻ □ A ▻ □ B ◎ x
cdistup = lam (lam (app (app cdist v₁) (app cup v₀)))
cunbox : ∀ {x A C Γ Λ} → Γ ⁏ Λ ⊢ □ A ▻ (□ A ▻ C) ▻ C ◎ x
cunbox = lam (lam (app v₀ v₁))
cpair : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ▻ B ▻ A ∧ B ◎ x
cpair = lam (lam (pair v₁ v₀))
cfst : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ∧ B ▻ A ◎ x
cfst = lam (fst v₀)
csnd : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ∧ B ▻ B ◎ x
csnd = lam (snd v₀)
-- Internalisation, or lifting, and additional theorems.
lift : ∀ {Γ x A Λ} → (∀ {y} → Γ ⁏ Λ , x ↝ y ⊢ A ◎ y) → □⋆ Γ ⁏ Λ ⊢ □ A ◎ x
lift {∅} t = box t
lift {Γ , B} t = det (app cdist (lift (lam t)))
hypup : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ A ▻ B ◎ x → Γ ⁏ Λ ⊢ □ A ▻ B ◎ x
hypup t = lam (app (mono⊢ weak⊆ t) (down v₀))
hypdown : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ □ A ▻ B ◎ x → Γ ⁏ Λ ⊢ □ A ▻ B ◎ x
hypdown t = lam (app (mono⊢ weak⊆ t) (up v₀))
cxup : ∀ {Γ x A Λ} → Γ ⁏ Λ ⊢ A ◎ x → □⋆ Γ ⁏ Λ ⊢ A ◎ x
cxup {∅} t = t
cxup {Γ , B} t = det (hypup (cxup (lam t)))
cxdown : ∀ {Γ x A Λ} → □⋆ □⋆ Γ ⁏ Λ ⊢ A ◎ x → □⋆ Γ ⁏ Λ ⊢ A ◎ x
cxdown {∅} t = t
cxdown {Γ , B} t = det (hypdown (cxdown (lam t)))
box⋆ : ∀ {Ξ x Γ Λ} → (∀ {y} → ∅ ⁏ Λ , x ↝ y ⊢⋆ Ξ ◎⋆ y) → Γ ⁏ Λ ⊢⋆ □⋆ Ξ ◎⋆ x
box⋆ {∅} f = ∙
box⋆ {Ξ , A} f = box⋆ (π₁ f) , box (π₂ f)
lift⋆ : ∀ {Ξ x Γ Λ} → (∀ {y} → Γ ⁏ Λ , x ↝ y ⊢⋆ Ξ ◎⋆ y) → □⋆ Γ ⁏ Λ ⊢⋆ □⋆ Ξ ◎⋆ x
lift⋆ {∅} f = ∙
lift⋆ {Ξ , A} f = lift⋆ (π₁ f) , lift (π₂ f)
up⋆ : ∀ {Ξ x Γ Λ} → Γ ⁏ Λ ⊢⋆ □⋆ Ξ ◎⋆ x → Γ ⁏ Λ ⊢⋆ □⋆ □⋆ Ξ ◎⋆ x
up⋆ {∅} f = ∙
up⋆ {Ξ , A} f = up⋆ (π₁ f) , up (π₂ f)
down⋆ : ∀ {Ξ x Γ Λ} → Γ ⁏ Λ ⊢⋆ □⋆ Ξ ◎⋆ x → Γ ⁏ Λ ⊢⋆ Ξ ◎⋆ x
down⋆ {∅} f = ∙
down⋆ {Ξ , A} f = down⋆ (π₁ f) , down (π₂ f)
multibox : ∀ {Ξ x A Γ Λ} → Γ ⁏ Λ ⊢⋆ □⋆ Ξ ◎⋆ x → (∀ {y} → □⋆ Ξ ⁏ ∅ , x ↝ y ⊢ A ◎ y) → Γ ⁏ Λ ⊢ □ A ◎ x
multibox ts u = multicut (up⋆ ts) (rmono⊢ bot⊆ (lift u))
dist′ : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (A ▻ B) ◎ x → Γ ⁏ Λ ⊢ □ A ▻ □ B ◎ x
dist′ t = lam (dist (mono⊢ weak⊆ t) v₀)
mpair : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ A ◎ x → Γ ⁏ Λ ⊢ □ B ◎ x → Γ ⁏ Λ ⊢ □ (A ∧ B) ◎ x
mpair t u = scan (pair (move (rmono⊢ weak⊆ t) rv₀) (move (rmono⊢ weak⊆ u) rv₀))
mfst : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (A ∧ B) ◎ x → Γ ⁏ Λ ⊢ □ A ◎ x
mfst t = scan (fst (move (rmono⊢ weak⊆ t) rv₀))
msnd : ∀ {x A B Γ Λ} → Γ ⁏ Λ ⊢ □ (A ∧ B) ◎ x → Γ ⁏ Λ ⊢ □ B ◎ x
msnd t = scan (snd (move (rmono⊢ weak⊆ t) rv₀))
-- Closure under context concatenation.
concat : ∀ {x A B Γ} Γ′ {Λ} → Γ , A ⁏ Λ ⊢ B ◎ x → Γ′ ⁏ Λ ⊢ A ◎ x → Γ ⧺ Γ′ ⁏ Λ ⊢ B ◎ x
concat Γ′ t u = app (mono⊢ (weak⊆⧺₁ Γ′) (lam t)) (mono⊢ weak⊆⧺₂ u)
-- TODO: Substitution.
-- [_≔_]_ : ∀ {x A B Γ Λ} → (i : A ∈ Γ) → Γ ∖ i ⁏ Λ ⊢ A ◎ x → Γ ⁏ Λ ⊢ B ◎ x → Γ ∖ i ⁏ Λ ⊢ B ◎ x
-- [ i ≔ s ] var j with i ≟∈ j
-- [ i ≔ s ] var .i | same = s
-- [ i ≔ s ] var ._ | diff j = var j
-- [ i ≔ s ] lam t = lam ([ pop i ≔ mono⊢ weak⊆ s ] t)
-- [ i ≔ s ] app t u = app ([ i ≔ s ] t) ([ i ≔ s ] u)
-- [ i ≔ s ] scan t = scan {![ i ≔ rmono⊢ weak⊆ s ] t!}
-- [ i ≔ s ] move t u = move {![ i ≔ s ] t!} u
-- [ i ≔ s ] pair t u = pair ([ i ≔ s ] t) ([ i ≔ s ] u)
-- [ i ≔ s ] fst t = fst ([ i ≔ s ] t)
-- [ i ≔ s ] snd t = snd ([ i ≔ s ] t)
-- [ i ≔ s ] unit = unit
-- TODO: Convertibility.
| {
"alphanum_fraction": 0.4324589842,
"avg_line_length": 29.5901162791,
"ext": "agda",
"hexsha": "c186125ffeb454fc92721b28a3e4212d0cc56e6f",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "BasicIS4/Syntax/LabelledGentzen.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "BasicIS4/Syntax/LabelledGentzen.agda",
"max_line_length": 100,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "BasicIS4/Syntax/LabelledGentzen.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 6143,
"size": 10179
} |
A : {!!}
A a = Set
-- Display constraints (C-c C-=):
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/Interaction/BasicOps.hs:457
| {
"alphanum_fraction": 0.688172043,
"avg_line_length": 26.5714285714,
"ext": "agda",
"hexsha": "e79a3a2997810663bb54cfb12daca1ad5d1fed83",
"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/Issue3503.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/Issue3503.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue3503.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": 52,
"size": 186
} |
open import Common.Product
open import Agda.Builtin.Equality
data ⊥ : Set where
record Empty : Set where
field absurdity : ⊥
magic₁ : Empty → ⊥
magic₁ ()
record EmptyIrr : Set where
field .absurdity : ⊥
magic₂ : EmptyIrr → ⊥
magic₂ ()
test : ∀ x y → magic₂ x ≡ magic₂ y
test x y = refl
postulate whatever : Set
magic₃ : Σ ⊥ (λ _ → whatever) → ⊥
magic₃ ()
magic₄ : Σ whatever (λ _ → ⊥) → ⊥
magic₄ ()
data D : whatever → Set where
magic₅ : Σ whatever D → ⊥
magic₅ ()
| {
"alphanum_fraction": 0.64375,
"avg_line_length": 14.5454545455,
"ext": "agda",
"hexsha": "62e3e805395394d876beecf4ab6d604f864eb3c1",
"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/EtaExpandEmptyRecord.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/EtaExpandEmptyRecord.agda",
"max_line_length": 34,
"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/EtaExpandEmptyRecord.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": 172,
"size": 480
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Group
open import lib.types.Lift
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
module lib.groups.Lift where
Lift-group-structure : ∀ {i j} {A : Type i}
→ GroupStructure A → GroupStructure (Lift {j = j} A)
Lift-group-structure GS = record
{ ident = lift ident
; inv = λ {(lift x) → lift (inv x)}
; comp = λ {(lift x) (lift y) → lift (comp x y)}
; unit-l = λ {(lift y) → ap lift (unit-l y)}
; assoc = λ {(lift x) (lift y) (lift z) → ap lift (assoc x y z)}
; inv-l = λ {(lift x) → ap lift (inv-l x)}
}
where open GroupStructure GS
Lift-group : ∀ {i j} → Group i → Group (lmax i j)
Lift-group {j = j} G = group (Lift {j = j} El) (Lift-level El-level)
(Lift-group-structure group-struct)
where open Group G
lift-hom : ∀ {i j} {G : Group i} → (G →ᴳ Lift-group {j = j} G)
lift-hom = group-hom lift (λ _ _ → idp)
lower-hom : ∀ {i j} {G : Group i} → (Lift-group {j = j} G →ᴳ G)
lower-hom = group-hom lower (λ _ _ → idp)
lift-iso : ∀ {i j} {G : Group i} → (G ≃ᴳ Lift-group {j = j} G)
lift-iso = lift-hom , snd lift-equiv
lower-iso : ∀ {i j} {G : Group i} → (Lift-group {j = j} G ≃ᴳ G)
lower-iso = lower-hom , snd lower-equiv
Lift-group-is-abelian : ∀ {i j} (G : Group i) → is-abelian G → is-abelian (Lift-group {j = j} G)
Lift-group-is-abelian G comm (lift g₁) (lift g₂) = ap lift (comm g₁ g₂)
Lift-abgroup : ∀ {i j} (G : AbGroup i) → AbGroup (lmax i j)
Lift-abgroup {j = j} G = Lift-group {j = j} (AbGroup.grp G)
, Lift-group-is-abelian (AbGroup.grp G) (AbGroup.comm G)
| {
"alphanum_fraction": 0.6017156863,
"avg_line_length": 35.4782608696,
"ext": "agda",
"hexsha": "02e7ff7fa2f368c9bc5b109183c2a1b1a1e36627",
"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": "core/lib/groups/Lift.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": "core/lib/groups/Lift.agda",
"max_line_length": 96,
"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": "core/lib/groups/Lift.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 598,
"size": 1632
} |
-- Andreas, 2019-04-10, issue #3689, reported by andrejtokarcik
-- Regression introduced by #3533 (dropping trivially impossible clauses
-- during case-splitting).
-- {-# OPTIONS -v interaction.case:100 #-}
-- {-# OPTIONS -v tc.cover:100 #-}
data _≡_ {A : Set} (a : A) : A → Set where
refl : a ≡ a
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
fst : A
snd : B fst
record R (A : Set) : Set where
field π : A
fun : {A : Set} (xyz : Σ (R A) λ r → Σ (R.π r ≡ R.π r) λ _ → R.π r ≡ R.π r) → Set
fun (x , y) = {!y !} -- C-c C-c
-- WAS: internal error.
-- Should succeed.
| {
"alphanum_fraction": 0.5730706076,
"avg_line_length": 22.5555555556,
"ext": "agda",
"hexsha": "2830d8e66efc2349cd389604d859f42f2e7ec22b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue3689.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue3689.agda",
"max_line_length": 81,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue3689.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": 227,
"size": 609
} |
-- Andreas, 2020-05-19, issue #4157, reported by nad
-- In old-style mutual blocks, it should be possible to have
-- several anonymous definitions.
open import Agda.Builtin.Equality
mutual
_ : Set₁
_ = Set
_ : Set → Set
_ = λ A → A
mutual
F : Set → Set
F = _
_ : F ≡ λ A → A
_ = refl
G : Set → Set
G = _
_ : G ≡ λ A → A → A
_ = refl
-- Should pass
| {
"alphanum_fraction": 0.5744125326,
"avg_line_length": 12.3548387097,
"ext": "agda",
"hexsha": "6eed04d296d65f14a9e918e8d7f46092c29aca28",
"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/Issue4157.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/Issue4157.agda",
"max_line_length": 60,
"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/Issue4157.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 140,
"size": 383
} |
module LocalOpenImplicit where
record Id (a : Set) : Set where
field id : a -> a
foo : {a b : Set} -> Id a -> Id b -> (a -> b) -> a -> b
foo id1 id2 f x = id id2 (f (id id1 x))
where open Id
| {
"alphanum_fraction": 0.5505050505,
"avg_line_length": 19.8,
"ext": "agda",
"hexsha": "96094cdd05ea602ff79a1ef58f06eb9d17c53e15",
"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/LocalOpenImplicit.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/LocalOpenImplicit.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/LocalOpenImplicit.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": 74,
"size": 198
} |
module _ where
postulate
C : Set → Set
A : Set
i : C A
foo : {X : Set} {{_ : C X}} → X
-- Let bindings need to be declared 'instance' to be eligible.
bar : A
bar = let z = i in foo
| {
"alphanum_fraction": 0.5729166667,
"avg_line_length": 14.7692307692,
"ext": "agda",
"hexsha": "6be2b948474c580f57a57526ca081c0fda23686f",
"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/LetInstance.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/LetInstance.agda",
"max_line_length": 62,
"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/LetInstance.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": 70,
"size": 192
} |
--------------------------------------------------------------------------------
-- Author : Bradley Hardy
--------------------------------------------------------------------------------
-- The first exercise from the ACS Algebraic Path Problems course, taught by
-- Timothy Griffin
--
-- Final proofs of 'fun fun facts' are at the bottom of the file; the rest
-- consists of definitions and supplementary proofs.
--------------------------------------------------------------------------------
module MLib.Lattices {ℓ} {S : Set ℓ} where
open import Matrix.Prelude
open import Function using (flip)
open Algebra.FunctionProperties (_≡_ {A = S}) using (Associative; Idempotent; Commutative)
module OperatorProperties (_∙_ : S → S → S) where
_≤L_ = λ a b → a ≡ a ∙ b
_≤R_ = λ a b → b ≡ a ∙ b
-- open OperatorProperties using (Associative; Idempotent; Commutative)
--------------------------------------------------------------------------------
-- Semigroups
--------------------------------------------------------------------------------
record IsCISemigroup (_∙_ : S → S → S) : Set ℓ where
field
isAssociative : Associative _∙_
isIdempotent : Idempotent _∙_
isCommutative : Commutative _∙_
open OperatorProperties _∙_ public
≤L→flip≤R : ∀ {x y} → x ≤L y → y ≤R x
≤L→flip≤R p = ≡.trans p (isCommutative _ _)
≤R→flip≤L : ∀ {x y} → x ≤R y → y ≤L x
≤R→flip≤L p = ≡.trans p (isCommutative _ _)
≤L-isPartialOrder : IsPartialOrder _≡_ _≤L_
≤L-isPartialOrder =
record
{ isPreorder =
record
{ isEquivalence = ≡.isEquivalence
; reflexive = λ {i j} p →
begin
i ≡⟨ ≡.sym (isIdempotent _) ⟩
i ∙ i ≡⟨ ≡.cong₂ _∙_ ≡.refl p ⟩
i ∙ j ∎
; trans = λ {i j k} p q →
begin
i ≡⟨ p ⟩
i ∙ j ≡⟨ ≡.cong₂ _∙_ ≡.refl q ⟩
i ∙ (j ∙ k) ≡⟨ ≡.sym (isAssociative _ _ _) ⟩
(i ∙ j) ∙ k ≡⟨ ≡.cong₂ _∙_ (≡.sym p) ≡.refl ⟩
i ∙ k ∎
}
; antisym = λ {x y} p q →
begin
x ≡⟨ p ⟩
x ∙ y ≡⟨ isCommutative _ _ ⟩
y ∙ x ≡⟨ ≡.sym q ⟩
y ∎
}
where open ≡.≡-Reasoning
-- Prove this by deferring to ≤L-isPartialOrder and taking advantage of the
-- fact that _≤L_ and _≤R_ are dual.
≤R-isPartialOrder : IsPartialOrder _≡_ _≤R_
≤R-isPartialOrder =
record
{ isPreorder =
record
{ isEquivalence = ≡.isEquivalence
; reflexive = λ p → fromL (≤L.reflexive (≡.sym p))
; trans = λ {i j k} p q → fromL (≤L.trans (toL q) (toL p))
}
; antisym = λ {x y} p q → ≤L.antisym (toL q) (toL p)
}
where module ≤L = IsPartialOrder ≤L-isPartialOrder
fromL = ≤L→flip≤R
toL = ≤R→flip≤L
--------------------------------------------------------------------------------
-- (Greatest) lower and (least) upper bounds
--------------------------------------------------------------------------------
record IsLowerBound (_≤_ : S → S → Set ℓ) (c a b : S) : Set ℓ where
field
≤L : c ≤ a
≤R : c ≤ b
record IsGlb (_≤_ : S → S → Set ℓ) (c a b : S) : Set ℓ where
field
isLowerBound : IsLowerBound _≤_ c a b
isGreatest : ∀ {d} → d ≤ a → d ≤ b → d ≤ c
open IsLowerBound isLowerBound public
record IsUpperBound (_≤_ : S → S → Set ℓ) (c a b : S) : Set ℓ where
field
L≤ : a ≤ c
R≤ : b ≤ c
record IsLub (_≤_ : S → S → Set ℓ) (c a b : S) : Set ℓ where
field
isUpperBound : IsUpperBound _≤_ c a b
isLeast : ∀ {d} → a ≤ d → b ≤ d → c ≤ d
open IsUpperBound isUpperBound public
-- A least upper bound is a greatest lower bound with respect to the reversed
-- order.
flipGlb : IsGlb (flip _≤_) c a b
flipGlb = record
{ isLowerBound = record { ≤L = L≤ ; ≤R = R≤ }
; isGreatest = isLeast
}
module IsGlbProperties {≤ c a b} (isGlb : IsGlb ≤ c a b) where
open IsGlb isGlb public
sym : IsGlb ≤ c b a
sym = record
{ isLowerBound = record { ≤L = ≤R ; ≤R = ≤L }
; isGreatest = λ x y → isGreatest y x
}
-- A greatest lower bound is a least upper bound with respect to the reversed
-- order.
flipLub : IsLub (flip ≤) c a b
flipLub = record
{ isUpperBound = record { L≤ = ≤L ; R≤ = ≤R }
; isLeast = isGreatest
}
module PartialOrderProperties (_≤_ : S → S → Set ℓ)
(isPartialOrder : IsPartialOrder _≡_ _≤_)
where
module ≤ = IsPartialOrder isPartialOrder
IsGlb-self : ∀ {a} → IsGlb _≤_ a a a
IsGlb-self = record
{ isLowerBound = record { ≤L = ≤.refl ; ≤R = ≤.refl }
; isGreatest = λ x y → x
}
-- In a partial order, there is at most one greatest lower bound for any given
-- pair of values.
IsGlb-unique : ∀ {a b c} → IsGlb _≤_ c a b → ∀ {d} → IsGlb _≤_ d a b → c ≡ d
IsGlb-unique p q =
≤.antisym
(IsGlb.isGreatest q (IsGlb.≤L p) (IsGlb.≤R p))
(IsGlb.isGreatest p (IsGlb.≤L q) (IsGlb.≤R q))
flipIsPartialOrder : IsPartialOrder _≡_ (flip _≤_)
flipIsPartialOrder = record
{ isPreorder = record
{ isEquivalence = ≡.isEquivalence
; reflexive = λ p → ≤.reflexive (≡.sym p)
; trans = flip ≤.trans
}
; antisym = flip ≤.antisym
}
--------------------------------------------------------------------------------
-- Semilattices
--------------------------------------------------------------------------------
record IsMeetSemilattice (_≤_ : S → S → Set ℓ) (_⊓_ : S → S → S) : Set ℓ where
field
isPartialOrder : IsPartialOrder _≡_ _≤_
isGlb : ∀ {a b} → IsGlb _≤_ (a ⊓ b) a b
open PartialOrderProperties _≤_ isPartialOrder public
module This {a b} = IsGlbProperties (isGlb {a} {b})
open This public
-- In a meet semilattice, the only greatest lower bound of any pair 'a' and
-- 'b' is 'a ⊓ b'.
glb-intro : ∀ {c a b} → IsGlb _≤_ c a b → c ≡ a ⊓ b
glb-intro p = IsGlb-unique p isGlb
module CISemigroup where
isCommutative : Commutative _⊓_
isCommutative _ _ = glb-intro (IsGlbProperties.sym isGlb)
isIdempotent : Idempotent _⊓_
isIdempotent _ = ≡.sym (glb-intro IsGlb-self)
isAssociative : Associative _⊓_
isAssociative a b c =
let d = (a ⊓ b) ⊓ c
d≤a : d ≤ a
d≤a = ≤.trans ≤L ≤L
d≤b : d ≤ b
d≤b = ≤.trans ≤L ≤R
d≤c : d ≤ c
d≤c = ≤R
d≤b⊓c : d ≤ (b ⊓ c)
d≤b⊓c = isGreatest d≤b d≤c
d-greatest : ∀ {d′} → d′ ≤ a → d′ ≤ b → d′ ≤ c → d′ ≤ d
d-greatest p q r = isGreatest (isGreatest p q) r
in glb-intro (
record
{ isLowerBound = record { ≤L = ≤.trans ≤L ≤L ; ≤R = d≤b⊓c}
; isGreatest = λ p q → d-greatest p (≤.trans q ≤L) (≤.trans q ≤R)
})
-- A meet semilattic is also a commutative idempotent semigroup
isCISemigroup : IsCISemigroup _⊓_
isCISemigroup = record { CISemigroup }
record IsJoinSemilattice (≤ : S → S → Set ℓ) (_⊔_ : S → S → S) : Set ℓ where
field
isPartialOrder : IsPartialOrder _≡_ ≤
isLub : ∀ {a b} → IsLub ≤ (a ⊔ b) a b
open PartialOrderProperties ≤ isPartialOrder public
module This {a b} = IsLub (isLub {a} {b})
open This
-- A join semilattice is a meet semilattice with respect to the reversed order
flipIsMeetSemilattice : IsMeetSemilattice (flip ≤) _⊔_
flipIsMeetSemilattice = record
{ isPartialOrder = flipIsPartialOrder
; isGlb = flipGlb
}
-- A join semilattice is also a commutative idempotent semigroup
open IsMeetSemilattice flipIsMeetSemilattice using (isCISemigroup) public
module MeetSemilatticeProperties {≤ ⊓}
(isMeetSemilattice : IsMeetSemilattice ≤ ⊓)
where
open IsMeetSemilattice isMeetSemilattice
-- A meet semilattice is a join semilattice with respect to the reversed order
flipIsJoinSemilattice : IsJoinSemilattice (flip ≤) ⊓
flipIsJoinSemilattice = record
{ isPartialOrder = flipIsPartialOrder
; isLub = flipLub
}
--------------------------------------------------------------------------------
-- Proofs of fun fun facts
--------------------------------------------------------------------------------
-- Commutative idempotent semigroups create meet and join semilattices from
-- their left and right natural orders respectively.
module FunFunFact1 {_∙_ : S → S → S} (isCISemigroup : IsCISemigroup _∙_) where
open IsCISemigroup isCISemigroup
funFunFact1Meet : IsMeetSemilattice _≤L_ _∙_
funFunFact1Meet =
record
{ isPartialOrder = ≤L-isPartialOrder
; isGlb = λ {a b} → record
{ isLowerBound = record
{ ≤L =
begin
a ∙ b ≡⟨ ≡.cong₂ _∙_ (≡.sym (isIdempotent _)) ≡.refl ⟩
(a ∙ a) ∙ b ≡⟨ isAssociative _ _ _ ⟩
a ∙ (a ∙ b) ≡⟨ isCommutative _ _ ⟩
(a ∙ b) ∙ a ∎
; ≤R =
begin
a ∙ b ≡⟨ ≡.cong₂ _∙_ ≡.refl (≡.sym (isIdempotent _)) ⟩
a ∙ (b ∙ b) ≡⟨ ≡.sym (isAssociative _ _ _) ⟩
(a ∙ b) ∙ b ∎
}
; isGreatest = λ {d} p q →
begin
d ≡⟨ ≡.sym (isIdempotent _) ⟩
d ∙ d ≡⟨ ≡.cong₂ _∙_ p q ⟩
(d ∙ a) ∙ (d ∙ b) ≡⟨ isAssociative _ _ _ ⟩
d ∙ (a ∙ (d ∙ b)) ≡⟨ ≡.cong₂ _∙_ ≡.refl (≡.sym (isAssociative _ _ _)) ⟩
d ∙ ((a ∙ d) ∙ b) ≡⟨ ≡.cong₂ _∙_ ≡.refl
(≡.cong₂ _∙_ (isCommutative _ _) ≡.refl) ⟩
d ∙ ((d ∙ a) ∙ b) ≡⟨ ≡.cong₂ _∙_ ≡.refl (isAssociative _ _ _) ⟩
d ∙ (d ∙ (a ∙ b)) ≡⟨ ≡.sym (isAssociative _ _ _) ⟩
(d ∙ d) ∙ (a ∙ b) ≡⟨ ≡.cong₂ _∙_ (isIdempotent _) ≡.refl ⟩
d ∙ (a ∙ b) ∎
}
}
where open ≡.≡-Reasoning
-- Prove for join by symmetry with meet
funFunFact1Join : IsJoinSemilattice _≤R_ _∙_
funFunFact1Join =
record
{ isPartialOrder = ≤R-isPartialOrder
; isLub = λ {a b} → record
{ isUpperBound = record
{ L≤ = fromL Meet.≤L
; R≤ = fromL Meet.≤R
}
; isLeast =
λ {d} p q →
fromL (Meet.isGreatest (toL p) (toL q))
}
}
where
open ≡.≡-Reasoning
module Meet = IsMeetSemilattice funFunFact1Meet
toL = ≤R→flip≤L
fromL = ≤L→flip≤R
-- Semilattices are commutative idempotent semigroups
module FunFunFact2 {≤ : S → S → Set ℓ} where
funFunFact2Meet : ∀ {⊓} → IsMeetSemilattice ≤ ⊓ → IsCISemigroup ⊓
funFunFact2Meet ijs = isCISemigroup
where open IsMeetSemilattice ijs
-- Note this is using 'isCISemigroup' from the flipped /meet/ semilattice.
funFunFact2Join : ∀ {⊔} → IsJoinSemilattice ≤ ⊔ → IsCISemigroup ⊔
funFunFact2Join ijs = isCISemigroup
where open IsJoinSemilattice ijs
| {
"alphanum_fraction": 0.513400335,
"avg_line_length": 32.5636363636,
"ext": "agda",
"hexsha": "4985295ad157a9df38c7a28ca33b0d18d8da9e9b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Lattices.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Lattices.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Lattices.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3843,
"size": 10746
} |
{-# OPTIONS --rewriting #-}
module Luau.OpSem where
open import Agda.Builtin.Equality using (_≡_)
open import Agda.Builtin.Float using (Float; primFloatPlus; primFloatMinus; primFloatTimes; primFloatDiv; primFloatEquality; primFloatLess; primFloatInequality)
open import Agda.Builtin.Bool using (Bool; true; false)
open import Agda.Builtin.String using (primStringEquality; primStringAppend)
open import Utility.Bool using (not; _or_; _and_)
open import Agda.Builtin.Nat using () renaming (_==_ to _==ᴬ_)
open import FFI.Data.Maybe using (Maybe; just; nothing)
open import Luau.Heap using (Heap; _≡_⊕_↦_; _[_]; function_is_end)
open import Luau.Substitution using (_[_/_]ᴮ)
open import Luau.Syntax using (Value; Expr; Stat; Block; nil; addr; val; var; function_is_end; _$_; block_is_end; local_←_; _∙_; done; return; name; fun; arg; binexp; BinaryOperator; +; -; *; /; <; >; ==; ~=; <=; >=; ··; number; bool; string)
open import Luau.RuntimeType using (RuntimeType; valueType)
open import Properties.Product using (_×_; _,_)
evalEqOp : Value → Value → Bool
evalEqOp Value.nil Value.nil = true
evalEqOp (addr x) (addr y) = (x ==ᴬ y)
evalEqOp (number x) (number y) = primFloatEquality x y
evalEqOp (bool true) (bool y) = y
evalEqOp (bool false) (bool y) = not y
evalEqOp _ _ = false
evalNeqOp : Value → Value → Bool
evalNeqOp (number x) (number y) = primFloatInequality x y
evalNeqOp x y = not (evalEqOp x y)
data _⟦_⟧_⟶_ : Value → BinaryOperator → Value → Value → Set where
+ : ∀ m n → (number m) ⟦ + ⟧ (number n) ⟶ number (primFloatPlus m n)
- : ∀ m n → (number m) ⟦ - ⟧ (number n) ⟶ number (primFloatMinus m n)
/ : ∀ m n → (number m) ⟦ / ⟧ (number n) ⟶ number (primFloatTimes m n)
* : ∀ m n → (number m) ⟦ * ⟧ (number n) ⟶ number (primFloatDiv m n)
< : ∀ m n → (number m) ⟦ < ⟧ (number n) ⟶ bool (primFloatLess m n)
> : ∀ m n → (number m) ⟦ > ⟧ (number n) ⟶ bool (primFloatLess n m)
<= : ∀ m n → (number m) ⟦ <= ⟧ (number n) ⟶ bool ((primFloatLess m n) or (primFloatEquality m n))
>= : ∀ m n → (number m) ⟦ >= ⟧ (number n) ⟶ bool ((primFloatLess n m) or (primFloatEquality m n))
== : ∀ v w → v ⟦ == ⟧ w ⟶ bool (evalEqOp v w)
~= : ∀ v w → v ⟦ ~= ⟧ w ⟶ bool (evalNeqOp v w)
·· : ∀ x y → (string x) ⟦ ·· ⟧ (string y) ⟶ string (primStringAppend x y)
data _⊢_⟶ᴮ_⊣_ {a} : Heap a → Block a → Block a → Heap a → Set
data _⊢_⟶ᴱ_⊣_ {a} : Heap a → Expr a → Expr a → Heap a → Set
data _⊢_⟶ᴱ_⊣_ where
function : ∀ a {H H′ F B} →
H′ ≡ H ⊕ a ↦ (function F is B end) →
-------------------------------------------
H ⊢ (function F is B end) ⟶ᴱ val(addr a) ⊣ H′
app₁ : ∀ {H H′ M M′ N} →
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
-----------------------------
H ⊢ (M $ N) ⟶ᴱ (M′ $ N) ⊣ H′
app₂ : ∀ v {H H′ N N′} →
H ⊢ N ⟶ᴱ N′ ⊣ H′ →
-----------------------------
H ⊢ (val v $ N) ⟶ᴱ (val v $ N′) ⊣ H′
beta : ∀ O v {H a F B} →
(O ≡ function F is B end) →
H [ a ] ≡ just(O) →
-----------------------------------------------------------------------------
H ⊢ (val (addr a) $ val v) ⟶ᴱ (block (fun F) is (B [ v / name(arg F) ]ᴮ) end) ⊣ H
block : ∀ {H H′ B B′ b} →
H ⊢ B ⟶ᴮ B′ ⊣ H′ →
----------------------------------------------------
H ⊢ (block b is B end) ⟶ᴱ (block b is B′ end) ⊣ H′
return : ∀ v {H B b} →
--------------------------------------------------------
H ⊢ (block b is return (val v) ∙ B end) ⟶ᴱ val v ⊣ H
done : ∀ {H b} →
--------------------------------------------
H ⊢ (block b is done end) ⟶ᴱ (val nil) ⊣ H
binOp₀ : ∀ {H op v₁ v₂ w} →
v₁ ⟦ op ⟧ v₂ ⟶ w →
--------------------------------------------------
H ⊢ (binexp (val v₁) op (val v₂)) ⟶ᴱ (val w) ⊣ H
binOp₁ : ∀ {H H′ x x′ op y} →
H ⊢ x ⟶ᴱ x′ ⊣ H′ →
---------------------------------------------
H ⊢ (binexp x op y) ⟶ᴱ (binexp x′ op y) ⊣ H′
binOp₂ : ∀ {H H′ x op y y′} →
H ⊢ y ⟶ᴱ y′ ⊣ H′ →
---------------------------------------------
H ⊢ (binexp x op y) ⟶ᴱ (binexp x op y′) ⊣ H′
data _⊢_⟶ᴮ_⊣_ where
local : ∀ {H H′ x M M′ B} →
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
-------------------------------------------------
H ⊢ (local x ← M ∙ B) ⟶ᴮ (local x ← M′ ∙ B) ⊣ H′
subst : ∀ v {H x B} →
------------------------------------------------------
H ⊢ (local x ← val v ∙ B) ⟶ᴮ (B [ v / name x ]ᴮ) ⊣ H
function : ∀ a {H H′ F B C} →
H′ ≡ H ⊕ a ↦ (function F is C end) →
--------------------------------------------------------------
H ⊢ (function F is C end ∙ B) ⟶ᴮ (B [ addr a / name(fun F) ]ᴮ) ⊣ H′
return : ∀ {H H′ M M′ B} →
H ⊢ M ⟶ᴱ M′ ⊣ H′ →
--------------------------------------------
H ⊢ (return M ∙ B) ⟶ᴮ (return M′ ∙ B) ⊣ H′
data _⊢_⟶*_⊣_ {a} : Heap a → Block a → Block a → Heap a → Set where
refl : ∀ {H B} →
----------------
H ⊢ B ⟶* B ⊣ H
step : ∀ {H H′ H″ B B′ B″} →
H ⊢ B ⟶ᴮ B′ ⊣ H′ →
H′ ⊢ B′ ⟶* B″ ⊣ H″ →
------------------
H ⊢ B ⟶* B″ ⊣ H″
| {
"alphanum_fraction": 0.4507667474,
"avg_line_length": 34.4166666667,
"ext": "agda",
"hexsha": "1f616c7e0830803ed5b3e9d7b3304da8006f3152",
"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": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "XanderYZZ/luau",
"max_forks_repo_path": "prototyping/Luau/OpSem.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "362428f8b4b6f5c9d43f4daf55bcf7873f536c3f",
"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": "XanderYZZ/luau",
"max_issues_repo_path": "prototyping/Luau/OpSem.agda",
"max_line_length": 242,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_stars_repo_path": "prototyping/Luau/OpSem.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-05T21:53:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-12-05T21:53:03.000Z",
"num_tokens": 1924,
"size": 4956
} |
module Numeric.Nat.Prime where
open import Prelude hiding (less-antirefl)
open import Numeric.Nat.GCD
open import Numeric.Nat.Divide
open import Numeric.Nat.Divide.Properties
open import Numeric.Nat.DivMod
open import Numeric.Nat.Sqrt
open import Numeric.Nat.Properties
open import Tactic.Nat
data Prime (n : Nat) : Set where
prime : n > 1 → (∀ k → k Divides n → Either (k ≡ 1) (k ≡ n)) → Prime n
private
lem : (a b : Nat) → b > 1 → suc a < suc a * b
lem a .(suc (k + 1)) (diff! k) = auto
data Composite (n : Nat) : Set where
composite : ∀ a b → a > 1 → b > 1 → a * b ≡ n → Composite n
pattern composite! a b 1<a 1<b = composite a b 1<a 1<b refl
composite-not-prime : ∀ {n} → Composite n → Prime n → ⊥
composite-not-prime (composite! 0 b (diff _ ()) _)
composite-not-prime (composite! (suc a) b sa>1 b>1) (prime _ f) =
case f (suc a) (divides-mul-l b divides-refl) of λ
{ (left sa=1) → less-antirefl sa>1 (sym sa=1)
; (right sa=sab) → less-antirefl (lem a b b>1) sa=sab
}
data Prime? n : Set where
yes : Prime n → Prime? n
no : Composite n → Prime? n
tiny : LessNat n 2 → Prime? n
private
less-inv : ∀ {a b} → ¬ LessNat a b → LessNat b (suc a)
less-inv {a} {b} a≮b with compare a b
less-inv a≮b | less a<b = ⊥-elim (a≮b a<b)
less-inv a≮b | equal refl = diff! 0
less-inv a≮b | greater a>b = by a>b
data _∈[_,_] (n a b : Nat) : Set where
in-range : a ≤ n → n ≤ b → n ∈[ a , b ]
empty-range : ∀ {n a b} → a > b → ¬ (n ∈[ a , b ])
empty-range a>b (in-range a≤n n≤b) = less-not-geq a>b (a≤n ⟨≤⟩ n≤b)
below-range : ∀ {n a b} → n < a → ¬ (n ∈[ a , b ])
below-range n<a (in-range a≤n _) = less-not-geq n<a a≤n
range-lower-bound : ∀ {n a b} → n ∈[ a , b ] → a ≤ n
range-lower-bound (in-range a<n _) = a<n
range-upper-bound : ∀ {n a b} → n ∈[ a , b ] → n ≤ b
range-upper-bound (in-range _ n<b) = n<b
singleton-range : ∀ {n a} → n ∈[ a , a ] → a ≡ n
singleton-range (in-range a<n n<a) = leq-antisym a<n n<a
suc-range-r : ∀ {n a b} → n ∈[ a , b ] → n ∈[ a , suc b ]
suc-range-r (in-range a<n n<b) = in-range a<n (by n<b)
suc-range-l : ∀ {n a b} → n ∈[ suc a , b ] → n ∈[ a , b ]
suc-range-l (in-range a<n n<b) = in-range (by a<n) n<b
in-range-l : ∀ {a b} → a ≤ b → a ∈[ a , b ]
in-range-l a<b = in-range (diff! 0) a<b
in-range-r : ∀ {a b} → a ≤ b → b ∈[ a , b ]
in-range-r a<b = in-range a<b (diff! 0)
non-zero-range : ∀ {n a b} → n ∈[ suc a , b ] → NonZero n
non-zero-range {zero} {a} (in-range (diff k eq) _) = refute eq
non-zero-range {suc _} _ = _
erase-in-range : ∀ {n a b} → n ∈[ a , b ] → n ∈[ a , b ]
erase-in-range r = in-range (fast-diff (range-lower-bound r))
(fast-diff (range-upper-bound r))
data _∈[_,_]? k a b : Set where
inside : k ∈[ a , b ] → k ∈[ a , b ]?
below : k < a → k ∈[ a , b ]?
above : k > b → k ∈[ a , b ]?
cmp-leq : (a b : Nat) → Either (a < b) (b ≤ a)
cmp-leq a b with compare a b
cmp-leq a b | less a<b = left a<b
cmp-leq a b | equal a=b = right (diff 0 (cong suc a=b))
cmp-leq a b | greater a>b = right (by a>b)
in-range? : ∀ k a b → k ∈[ a , b ]?
in-range? k a b with cmp-leq k a
in-range? k a b | left k<a = below k<a
in-range? k a b | right k≥a with cmp-leq b k
in-range? k a b | right k≥a | left k>b = above k>b
in-range? k a b | right k≥a | right k≤b = inside (in-range k≥a k≤b)
data FindInRange {ℓ} a b (P : Nat → Set ℓ) : Set ℓ where
here : ∀ k → k ∈[ a , b ] → P k → FindInRange a b P
none : (∀ k → k ∈[ a , b ] → ¬ P k) → FindInRange a b P
-- Version with less evidence. Faster to compute.
data FindInRange! {ℓ} (P : Nat → Set ℓ) : Set ℓ where
here : ∀ k → P k → FindInRange! P
none : FindInRange! P
private
not-first : ∀ {ℓ} {P : Nat → Set ℓ} {a b} →
¬ P a → (∀ k → k ∈[ suc a , b ] → ¬ P k) →
∀ k → k ∈[ a , b ] → ¬ P k
not-first {a = a} !pa !pa+ k k∈r pk with compare k a
not-first !pa !pa+ k k∈r pk | less k<a = below-range k<a k∈r
not-first !pa !pa+ k k∈r pk | equal refl = !pa pk
not-first !pa !pa+ k (in-range _ k≤b) pk | greater k>a = !pa+ k (in-range (by k>a) k≤b) pk
find! : ∀ {ℓ} {P : Nat → Set ℓ} (a d : Nat) → (∀ k → Dec (P k)) → FindInRange! P
find! a zero check = none
find! a (suc d) check with check a
find! a (suc d) check | yes pa = here a pa
find! a (suc d) check | no _ = force a λ a → find! (suc a) d check
found-in-range : ∀ {ℓ} {P : Nat → Set ℓ} a b d (eq : d + a ≡ suc b) (check : ∀ k → Dec (P k)) →
∀ k (pk : P k) → find! a d check ≡ here k pk → k ∈[ a , b ]
found-in-range a b zero eq check k pk ()
found-in-range a b (suc d) eq check k pk feq with check a
found-in-range a b (suc d) eq check .a pa refl | yes .pa = in-range-l (by eq)
found-in-range 0 b (suc d) eq check k pk feq | no !pa
with find! 1 d check | found-in-range 1 b d (by eq) check
found-in-range 0 b (suc d) eq check k pk refl | no !pa | here .k .pk | rec = suc-range-l (rec _ _ refl)
found-in-range 0 b (suc d) eq check k pk () | no !pa | none | rec
found-in-range (suc a) b (suc d) eq check k pk feq | no !pa
with find! (2 + a) d check | found-in-range (2 + a) b d (by eq) check
found-in-range (suc a) b (suc d) eq check k pk refl | no !pa | here .k .pk | rec = suc-range-l (rec _ _ refl)
found-in-range (suc a) b (suc d) eq check k pk () | no !pa | none | rec
not-found-in-range : ∀ {ℓ} {P : Nat → Set ℓ} a b d (eq : d + a ≡ suc b) (check : ∀ k → Dec (P k)) →
find! a d check ≡ none → ∀ k → k ∈[ a , b ] → ¬ P k
not-found-in-range 0 b zero eq check prf k k∈ab pk = empty-range (diff 0 eq) k∈ab
not-found-in-range (suc _) b zero eq check prf k k∈ab pk = empty-range (diff 0 eq) k∈ab
not-found-in-range a b (suc d) eq check prf k (in-range a<k k<b) pk with check a
not-found-in-range a b (suc d) eq check () k (in-range a<k k<b) pk | yes pa
not-found-in-range 0 b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa
with find! 1 d check | not-found-in-range 1 b d (by eq) check
not-found-in-range 0 b (suc d) eq check () k (in-range a<k k<b) pk | no !pa | here _ _ | rec
not-found-in-range 0 b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa | none | rec =
not-first !pa (rec refl) k (in-range a<k k<b) pk
not-found-in-range (suc a) b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa
with find! (suc (suc a)) d check | not-found-in-range (suc (suc a)) b d (by eq) check
not-found-in-range (suc a) b (suc d) eq check () k (in-range a<k k<b) pk | no !pa | here _ _ | rec
not-found-in-range (suc a) b (suc d) eq check prf k (in-range a<k k<b) pk | no !pa | none | rec =
not-first !pa (rec refl) k (in-range a<k k<b) pk
find : ∀ {ℓ} {P : Nat → Set ℓ} a b d → d + a ≡ suc b → (∀ k → Dec (P k)) → FindInRange a b P
find a b d eq check with inspect (find! a d check)
... | here k pk with≡ prf = here k (erase-in-range (found-in-range a b d eq check k pk prf)) pk
... | none with≡ prf = none (not-found-in-range a b d eq check prf)
findInRange : ∀ {ℓ} {P : Nat → Set ℓ} a b → (∀ k → Dec (P k)) → FindInRange a b P
findInRange a b check with compare a b
findInRange a ._ check | less (diff! k) = find a _ (2 + k) refl check
findInRange a .a check | equal refl = find a _ 1 refl check
findInRange a b check | greater gt = none (λ k k∈ab _ → empty-range gt k∈ab)
--- Reducing the required search space to 2..√a ---
private
lem-less : {n r d q : Nat} → r ^ 2 ≥ n →
q * d ≡ n → r < d → suc r ≤ q → ⊥
lem-less (diff k eq) refl (diff j refl) (diff! i) = refute eq
non-zero-less : ∀ {a} {{_ : NonZero a}} → 0 < a
non-zero-less {0} {{}}
non-zero-less {suc a} = diff a auto
div-unique : ∀ q {a b} {{_ : NonZero b}} → q * b ≡ a → a div b ≡ q
div-unique q {a} {b} eq = quot-unique (qr (a div b) (a mod b) (mod-less b a) (divmod-sound b a))
(qr q 0 non-zero-less (by eq))
divide-smaller : ∀ n r d {{_ : NonZero d}} → n ≤ r ^ 2 → d Divides n → d > r → n div d ≤ r
divide-smaller n r d n<r² (factor q eq) d>r =
let n/d=q : n div d ≡ q
n/d=q = div-unique q eq
in less-raa (lem-less n<r² (cong (_* d) n/d=q ⟨≡⟩ eq) d>r)
divide-bigger : ∀ n k {{_ : NonZero k}} → k < n → k Divides n → n div k ≥ 2
divide-bigger ._ k (diff! k₁) (factor zero eq) = refute eq
divide-bigger n k k<n (factor 1 eq) = ⊥-elim (less-antirefl k<n (by eq))
divide-bigger n k k<n (factor (suc (suc q)) eq) = by (sym (div-unique (2 + q) {b = k} eq))
up-to-root : ∀ r n → r ≤ n → r ^ 2 ≥ suc n → FindInRange 2 r (_Divides suc n) → FindInRange 2 n (_Divides suc n)
up-to-root r n r<n r²>n (none k∤sn) =
none λ k k∈2n k|sn → erase-⊥ $
case in-range? k 2 r of λ
{ (inside k∈2r) → k∤sn k k∈2r k|sn
; (below k<2) → less-not-geq k<2 (range-lower-bound k∈2n)
; (above k>r) →
let instance k≠0 : NonZero k
k≠0 = non-zero-range k∈2n
hi : suc n div k ≤ r
hi = divide-smaller (suc n) r k r²>n k|sn k>r
lo : suc n div k ≥ 2
lo = divide-bigger (suc n) k (range-upper-bound k∈2n) k|sn
in k∤sn (suc n div k) (in-range lo hi) (factor k (by (div-divides k|sn)))
}
up-to-root 0 _ _ _ (here k k∈⊥ _) = ⊥-elim (empty-range (diff! 1) k∈⊥)
up-to-root (suc r) n r<n r²>n (here k (in-range 2<k k<r) pk) =
here k (in-range 2<k (k<r ⟨≤⟩ r<n)) pk
private
is-1-or-n : ∀ {n} → (∀ k → k ∈[ 2 , n ] → k Divides suc n → ⊥) →
∀ k → k Divides suc n → Either (k ≡ 1) (k ≡ suc n)
is-1-or-n {n} no-div k (factor q kq=n) with in-range? k 2 n
is-1-or-n no-div k (factor q kq=n) | inside inr = ⊥-elim (no-div k inr (factor q kq=n))
is-1-or-n no-div .1 (factor q kq=n) | below (diff! zero) = left refl
is-1-or-n {n} no-div k (factor q kq=n) | below (diff (suc k₁) eq) =
refute (divides-zero (transport (_Divides suc n) (by eq) (factor q kq=n)))
is-1-or-n {n} no-div k (factor q kq=n) | above k>n =
right (leq-antisym {A = Nat} (divides-less (factor q kq=n)) (by k>n))
lem₂ : ∀ {n d : Nat} q → q * d ≡ suc n → d < suc n → q > 1
lem₂ 0 eq d≤n = refute eq
lem₂ 1 eq d≤n = ⊥-elim (less-antirefl d≤n (by eq))
lem₂ (suc (suc q)) eq d≤n = auto
two-is-prime : ∀ k → k Divides 2 → Either (k ≡ 1) (k ≡ 2)
two-is-prime k k|2 with divides-less k|2
two-is-prime 0 (factor q eq) | k≤2 = refute eq
two-is-prime 1 k|2 | k≤2 = left refl
two-is-prime 2 k|2 | k≤2 = right refl
two-is-prime (suc (suc (suc k))) k|2 | lt = refute lt
lem-sqrt : (n r : Nat) → r ^ 2 < 4 + n → ¬ (suc n < r)
lem-sqrt n ._ lt (diff! c) = refute lt
sqrt-less : (n : Nat) → n > 2 → suc (sqrt! n) < n
sqrt-less 0 (diff k ())
sqrt-less 1 (diff k eq) = refute eq
sqrt-less 2 (diff k eq) = refute eq
sqrt-less (suc (suc (suc n))) _ with sqrt (3 + n)
sqrt-less (suc (suc (suc n))) _ | root r lt _ =
less-raa λ n<r → lem-sqrt n r lt (by n<r)
isPrimeAux : ∀ n → Comparison _<_ 2 n → Prime? n
isPrimeAux 0 _ = tiny (diff! 1)
isPrimeAux 1 _ = tiny (diff! 0)
isPrimeAux 2 _ = yes (prime (diff! 0) two-is-prime)
isPrimeAux (suc (suc (suc n))) (greater (diff k eq)) = refute eq
isPrimeAux (suc (suc (suc _))) (equal ())
isPrimeAux (suc n) (less n>2) with sqrt (suc n) | sqrt-less _ n>2
... | root r r²<n sr²>n | r<n with up-to-root (suc r) n r<n (by sr²>n) $
findInRange 2 (suc r) (λ k → k divides? suc n)
... | none p = yes (prime (by n>2) (is-1-or-n p))
... | here d (in-range 2≤d d≤n) (factor q eq) =
no (composite d q (by 2≤d) (lem₂ q eq d≤n) (by eq))
isPrime : ∀ n → Prime? n
isPrime n = isPrimeAux n (compare 2 n)
isPrime! : Nat → Bool
isPrime! n with isPrime n
... | yes _ = true
... | no _ = false
... | tiny _ = false
decPrime : ∀ p → Dec (Prime p)
decPrime p =
case isPrime p of λ where
(yes isp) → yes isp
(no comp) → no (composite-not-prime comp)
(tiny p<2) → no λ where (prime p>1 dp) → less-not-geq p>1 p<2
-- Benchmarking
-- Todo: test only odd numbers
-- Composite
-- 5.0s + isPrime 1927 (41 * 47)
-- 40ms recurse from below
-- 5.2s + isPrime (1021 * 1021)
-- 0.2s remove range argument from check
-- 0.8s + isPrime (3581 * 3581)
-- 0.3s don't compute in-range proof in find!
-- Prime (no proof)
-- 2.3s + isPrime! 1021
-- 5.0s recurse from below
-- 0.1s remove range argument from check
-- 0.7s + isPrime! 3581
-- Prime (run proof: cheap because we're not actually running the (negative) function computed by find)
-- 0.7s + testPrimeProof 3581
-- Prime (print proof)
-- 1.8s + isPrime 83
-- 3.4s recurse from below
-- 2.6s remove range argument from check
-- 0.1s split negative proof into separate function
-- 0.6s + isPrime 3581
-- 0.2s only check up to sqrt
-- 0.7s + isPrime 12823607
-- 2.3s + isPrime 234576373
-- 1.4s don't compute in-range proof in find!
| {
"alphanum_fraction": 0.5466237942,
"avg_line_length": 42.6862745098,
"ext": "agda",
"hexsha": "20b6f65465cdb14baa846d7c92240a9d9c653790",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Numeric/Nat/Prime.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Numeric/Nat/Prime.agda",
"max_line_length": 114,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Numeric/Nat/Prime.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 5189,
"size": 13062
} |
open import Oscar.Prelude
open import Oscar.Data.¶
open import Oscar.Data.Fin
open import Oscar.Data.Vec
module Oscar.Data.Term where
module Term {𝔭} (𝔓 : Ø 𝔭) where
mutual
Terms : ¶ → ¶ → Ø 𝔭
Terms N n = ⟨ Term n ∞ ⟩¶⟨≤ N ⟩
data Term (n : ¶) : Ø 𝔭 where
i : (x : ¶⟨< n ⟩) → Term n
leaf : Term n
_fork_ : (s t : Term n) → Term n
function : 𝔓 → ∀ {N} → Terms N n → Term n
| {
"alphanum_fraction": 0.5469879518,
"avg_line_length": 19.7619047619,
"ext": "agda",
"hexsha": "244dd98182bb96bd5bf4c492991a18e9e34cdbad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Data/Term.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Data/Term.agda",
"max_line_length": 47,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Data/Term.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 163,
"size": 415
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.CommAlgebra.QuotientAlgebra where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Powerset using (_∈_; _⊆_)
open import Cubical.Foundations.Structure
open import Cubical.HITs.SetQuotients hiding (_/_)
open import Cubical.Data.Unit
open import Cubical.Data.Sigma.Properties using (Σ≡Prop)
open import Cubical.Algebra.CommRing
import Cubical.Algebra.CommRing.QuotientRing as CommRing
import Cubical.Algebra.Ring.QuotientRing as Ring
open import Cubical.Algebra.CommRing.Ideal hiding (IdealsIn)
open import Cubical.Algebra.CommAlgebra
open import Cubical.Algebra.CommAlgebra.Ideal
open import Cubical.Algebra.CommAlgebra.Kernel
open import Cubical.Algebra.CommAlgebra.Instances.Unit
open import Cubical.Algebra.Algebra.Base using (IsAlgebraHom; isPropIsAlgebraHom)
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Ideal using (isIdeal)
open import Cubical.Algebra.CommRingSolver.Reflection
open import Cubical.Algebra.Algebra.Properties
open AlgebraHoms using (compAlgebraHom)
private
variable
ℓ : Level
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_)
open CommAlgebraStr {{...}}
open RingTheory (CommRing→Ring (CommAlgebra→CommRing A)) using (-DistR·)
instance
_ : CommRingStr _
_ = snd R
_ : CommAlgebraStr _ _
_ = snd A
_/_ : CommAlgebra R ℓ
_/_ = commAlgebraFromCommRing
((CommAlgebra→CommRing A) CommRing./ I)
(λ r → elim (λ _ → squash/) (λ x → [ r ⋆ x ]) (eq r))
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r ·R s) ⋆ x ≡⟨ ⋆-assoc r s x ⟩
r ⋆ (s ⋆ x) ∎) i ])
(λ r s → elimProp (λ _ → squash/ _ _)
λ x i → [ ((r +R s) ⋆ x ≡⟨ ⋆-ldist r s x ⟩
r ⋆ x + s ⋆ x ∎) i ])
(λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ (r ⋆ (x + y) ≡⟨ ⋆-rdist r x y ⟩
r ⋆ x + r ⋆ y ∎) i ])
(elimProp (λ _ → squash/ _ _)
(λ x i → [ (1r ⋆ x ≡⟨ ⋆-lid x ⟩ x ∎) i ]))
λ r → elimProp2 (λ _ _ → squash/ _ _)
λ x y i → [ ((r ⋆ x) · y ≡⟨ ⋆-lassoc r x y ⟩
r ⋆ (x · y) ∎) i ]
where
open CommIdeal using (isCommIdeal)
eq : (r : fst R) (x y : fst A) → x - y ∈ (fst I) → [ r ⋆ x ] ≡ [ r ⋆ y ]
eq r x y x-y∈I = eq/ _ _
(subst (λ u → u ∈ fst I)
((r ⋆ 1a) · (x - y) ≡⟨ ·Rdist+ (r ⋆ 1a) x (- y) ⟩
(r ⋆ 1a) · x + (r ⋆ 1a) · (- y) ≡[ i ]⟨ (r ⋆ 1a) · x + -DistR· (r ⋆ 1a) y i ⟩
(r ⋆ 1a) · x - (r ⋆ 1a) · y ≡[ i ]⟨ ⋆-lassoc r 1a x i
- ⋆-lassoc r 1a y i ⟩
r ⋆ (1a · x) - r ⋆ (1a · y) ≡[ i ]⟨ r ⋆ (·Lid x i) - r ⋆ (·Lid y i) ⟩
r ⋆ x - r ⋆ y ∎ )
(isCommIdeal.·Closed (snd I) _ x-y∈I))
quotientHom : CommAlgebraHom A (_/_)
fst quotientHom x = [ x ]
IsAlgebraHom.pres0 (snd quotientHom) = refl
IsAlgebraHom.pres1 (snd quotientHom) = refl
IsAlgebraHom.pres+ (snd quotientHom) _ _ = refl
IsAlgebraHom.pres· (snd quotientHom) _ _ = refl
IsAlgebraHom.pres- (snd quotientHom) _ = refl
IsAlgebraHom.pres⋆ (snd quotientHom) _ _ = refl
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommRingStr {{...}} hiding (_-_; -_; dist; ·Lid; ·Rdist+) renaming (_·_ to _·R_; _+_ to _+R_)
open CommAlgebraStr ⦃...⦄
instance
_ : CommRingStr _
_ = snd R
_ : CommAlgebraStr _ _
_ = snd A
private
LRing = CommAlgebra→Ring (A / I)
RRing = (CommAlgebra→Ring A) Ring./ (CommIdeal→Ideal I)
-- sanity check / maybe a helper function some day
CommForget/ : RingEquiv (CommAlgebra→Ring (A / I)) ((CommAlgebra→Ring A) Ring./ (CommIdeal→Ideal I))
fst CommForget/ =
isoToEquiv
(iso
(rec (isSetRing LRing) (λ a → [ a ]) λ a b a-b∈I → eq/ a b a-b∈I)
(rec (isSetRing RRing) (λ a → [ a ]) (λ a b a-b∈I → eq/ a b a-b∈I))
(elimProp (λ _ → isSetRing LRing _ _) λ _ → refl)
(elimProp (λ _ → isSetRing RRing _ _) (λ _ → refl)))
IsRingHom.pres0 (snd CommForget/) = refl
IsRingHom.pres1 (snd CommForget/) = refl
IsRingHom.pres+ (snd CommForget/) = elimProp2 (λ _ _ → isSetRing RRing _ _) (λ _ _ → refl)
IsRingHom.pres· (snd CommForget/) = elimProp2 (λ _ _ → isSetRing RRing _ _) (λ _ _ → refl)
IsRingHom.pres- (snd CommForget/) = elimProp (λ _ → isSetRing RRing _ _) (λ _ → refl)
open IsAlgebraHom
inducedHom : (B : CommAlgebra R ℓ) (ϕ : CommAlgebraHom A B)
→ (fst I) ⊆ (fst (kernel A B ϕ))
→ CommAlgebraHom (A / I) B
fst (inducedHom B ϕ I⊆kernel) =
let open RingTheory (CommRing→Ring (CommAlgebra→CommRing B))
instance
_ : CommAlgebraStr R _
_ = snd B
_ : CommRingStr _
_ = snd (CommAlgebra→CommRing B)
in rec (isSetCommAlgebra B) (λ x → fst ϕ x)
λ a b a-b∈I →
equalByDifference
(fst ϕ a) (fst ϕ b)
((fst ϕ a) - (fst ϕ b) ≡⟨ cong (λ u → (fst ϕ a) + u) (sym (IsAlgebraHom.pres- (snd ϕ) _)) ⟩
(fst ϕ a) + (fst ϕ (- b)) ≡⟨ sym (IsAlgebraHom.pres+ (snd ϕ) _ _) ⟩
fst ϕ (a - b) ≡⟨ I⊆kernel (a - b) a-b∈I ⟩
0r ∎)
pres0 (snd (inducedHom B ϕ kernel⊆I)) = pres0 (snd ϕ)
pres1 (snd (inducedHom B ϕ kernel⊆I)) = pres1 (snd ϕ)
pres+ (snd (inducedHom B ϕ kernel⊆I)) = elimProp2 (λ _ _ → isSetCommAlgebra B _ _) (pres+ (snd ϕ))
pres· (snd (inducedHom B ϕ kernel⊆I)) = elimProp2 (λ _ _ → isSetCommAlgebra B _ _) (pres· (snd ϕ))
pres- (snd (inducedHom B ϕ kernel⊆I)) = elimProp (λ _ → isSetCommAlgebra B _ _) (pres- (snd ϕ))
pres⋆ (snd (inducedHom B ϕ kernel⊆I)) = λ r → elimProp (λ _ → isSetCommAlgebra B _ _) (pres⋆ (snd ϕ) r)
injectivePrecomp : (B : CommAlgebra R ℓ) (f g : CommAlgebraHom (A / I) B)
→ f ∘a (quotientHom A I) ≡ g ∘a (quotientHom A I)
→ f ≡ g
injectivePrecomp B f g p =
Σ≡Prop
(λ h → isPropIsAlgebraHom (CommRing→Ring R) (snd (CommAlgebra→Algebra (A / I))) h (snd (CommAlgebra→Algebra B)))
(descendMapPath (fst f) (fst g) (isSetCommAlgebra B)
λ x → λ i → fst (p i) x)
{- trivial quotient -}
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) where
open CommAlgebraStr (snd A)
oneIdealQuotient : CommAlgebraEquiv (A / (1Ideal A)) (UnitCommAlgebra R)
fst oneIdealQuotient =
isoToEquiv (iso (fst (terminalMap R (A / (1Ideal A))))
(λ _ → [ 0a ])
(λ _ → isPropUnit* _ _)
(elimProp (λ _ → squash/ _ _)
λ a → eq/ 0a a tt*))
snd oneIdealQuotient = snd (terminalMap R (A / (1Ideal A)))
zeroIdealQuotient : CommAlgebraEquiv A (A / (0Ideal A))
fst zeroIdealQuotient =
let open RingTheory (CommRing→Ring (CommAlgebra→CommRing A))
in isoToEquiv (iso (fst (quotientHom A (0Ideal A)))
(rec (isSetCommAlgebra A) (λ x → x) λ x y x-y≡0 → equalByDifference x y x-y≡0)
(elimProp (λ _ → squash/ _ _) λ _ → refl)
λ _ → refl)
snd zeroIdealQuotient = snd (quotientHom A (0Ideal A))
[_]/ : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A}
→ (a : fst A) → fst (A / I)
[ a ]/ = [ a ]
module _ {R : CommRing ℓ} (A : CommAlgebra R ℓ) (I : IdealsIn A) where
open CommIdeal using (isPropIsCommIdeal)
private
π = quotientHom A I
kernel≡I : kernel A (A / I) π ≡ I
kernel≡I =
kernel A (A / I) π ≡⟨ Σ≡Prop
(isPropIsCommIdeal (CommAlgebra→CommRing A))
refl ⟩
_ ≡⟨ CommRing.kernel≡I {R = CommAlgebra→CommRing A} I ⟩
I ∎
private
module _ (R : CommRing ℓ) where
open CommRingStr (snd R)
lemma : (y : (fst R)) → y ≡ y - 0r
lemma = solve R
isZeroFromIdeal : {R : CommRing ℓ} {A : CommAlgebra R ℓ} {I : IdealsIn A}
→ (x : ⟨ A ⟩) → x ∈ (fst I) → fst (quotientHom A I) x ≡ CommAlgebraStr.0a (snd (A / I))
isZeroFromIdeal {A = A} {I = I} x x∈I = eq/ x 0a (subst (λ y → y ∈ (fst I)) step x∈I )
where
open CommAlgebraStr (snd A)
step : x ≡ x - 0a
step = lemma (CommAlgebra→CommRing A) x
0' : ⟨ A / I ⟩
0' = fst (quotientHom A I) 0a
| {
"alphanum_fraction": 0.5460331894,
"avg_line_length": 42.5024154589,
"ext": "agda",
"hexsha": "444053fba5b1ed5675e3a6c73004e8c6b2f294f6",
"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": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "gmagaf/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"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": "gmagaf/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1d9b9691d375659fa8ebd9cbf8b63678955b196b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "gmagaf/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommAlgebra/QuotientAlgebra.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3198,
"size": 8798
} |
{-# OPTIONS --without-K --safe #-}
open import Definition.Typed.EqualityRelation
module Definition.LogicalRelation.Substitution.Introductions.Fst {{eqrel : EqRelSet}} where
open EqRelSet {{...}}
open import Definition.Untyped as U hiding (wk)
open import Definition.Untyped.Properties
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.Weakening as Wk hiding (wk; wkTerm; wkEqTerm)
open import Definition.Typed.RedSteps
open import Definition.LogicalRelation
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.Weakening
open import Definition.LogicalRelation.Properties
open import Definition.LogicalRelation.Application
open import Definition.LogicalRelation.Substitution
open import Definition.LogicalRelation.Substitution.Properties
open import Definition.LogicalRelation.Substitution.Introductions.Pi
open import Tools.Product
import Tools.PropositionalEquality as PE
fst-subst* : ∀ {Γ F G t t′} → Γ ⊢ F → Γ ∙ F ⊢ G
→ Γ ⊢ t ⇒* t′ ∷ Σ F ▹ G → Γ ⊢ fst t ⇒* fst t′ ∷ F
fst-subst* ⊢F ⊢G (id x) = id (fstⱼ ⊢F ⊢G x)
fst-subst* ⊢F ⊢G (x ⇨ t⇒t′) = fst-subst ⊢F ⊢G x ⇨ fst-subst* ⊢F ⊢G t⇒t′
-- Reducibility of fst with a specific typing derivation
fst′ : ∀ {F G t Γ l l′}
([F] : Γ ⊩⟨ l′ ⟩ F)
([ΣFG] : Γ ⊩⟨ l ⟩B⟨ BΣ ⟩ Σ F ▹ G)
([t] : Γ ⊩⟨ l ⟩ t ∷ Σ F ▹ G / B-intr BΣ [ΣFG])
→ Γ ⊩⟨ l′ ⟩ fst t ∷ F / [F]
fst′ {F = F} {t = t} {Γ = Γ} [F] (noemb (Bᵣ F' G' D ⊢F ⊢G A≡A [F'] [G'] G-ext))
(Σₜ p d pProd p≅p [fstp] [sndp]) with
B-PE-injectivity BΣ (whnfRed* (red D) Σₙ)
... | PE.refl , PE.refl =
let [fstp] : Γ ⊩⟨ _ ⟩ fst p ∷ F / [F]
[fstp] = irrelevanceTerm′ (wk-id F)
([F'] id (wf ⊢F)) [F]
[fstp]
in proj₁ (redSubst*Term (fst-subst* ⊢F ⊢G (redₜ d))
[F] [fstp])
fst′ {t = t} {Γ = Γ} {l = l} [F] (emb 0<1 x) [t] = fst′ [F] x [t]
-- Reducibility of fst with a general typing derivation
fst″ : ∀ {F G t Γ l l′}
([F] : Γ ⊩⟨ l′ ⟩ F)
([ΣFG] : Γ ⊩⟨ l ⟩ Σ F ▹ G)
([t] : Γ ⊩⟨ l ⟩ t ∷ Σ F ▹ G / [ΣFG])
→ Γ ⊩⟨ l′ ⟩ fst t ∷ F / [F]
fst″ {t = t} {Γ = Γ} {l = l} [F] [ΣFG] [t] =
let [t]′ = irrelevanceTerm [ΣFG] (B-intr BΣ (Σ-elim [ΣFG])) [t]
in fst′ [F] (Σ-elim [ΣFG]) [t]′
fst-cong′ : ∀ {F G t t′ Γ l l′}
([F] : Γ ⊩⟨ l′ ⟩ F)
([ΣFG] : Γ ⊩⟨ l ⟩B⟨ BΣ ⟩ Σ F ▹ G)
([t≡t′] : Γ ⊩⟨ l ⟩ t ≡ t′ ∷ Σ F ▹ G / B-intr BΣ [ΣFG])
→ Γ ⊩⟨ l′ ⟩ fst t ≡ fst t′ ∷ F / [F]
fst-cong′ {F = F} {G = G} {Γ = Γ} [F]
[ΣFG]@(noemb (Bᵣ F' G' D ⊢F ⊢G A≡A [F'] [G'] G-ext))
[t≡t′]@(Σₜ₌ p p′ d d′ pProd pProd′ p≅p′ [t] [t′] [fstp] [fstp′] [fst≡] [snd≡]) with
B-PE-injectivity BΣ (whnfRed* (red D) Σₙ)
... | PE.refl , PE.refl =
let ⊢Γ = wf ⊢F
[fstp]₁ = irrelevanceTerm′ (wk-id F) ([F'] id ⊢Γ) [F] [fstp]
[fstp′]₁ = irrelevanceTerm′ (wk-id F) ([F'] id ⊢Γ) [F] [fstp′]
[fst≡]₁ = irrelevanceEqTerm′ (wk-id F) ([F'] id ⊢Γ) [F] [fst≡]
[fstt≡fstp] = proj₂ (redSubst*Term (fst-subst* ⊢F ⊢G (redₜ d)) [F] [fstp]₁)
[fstt′≡fstp′] = proj₂ (redSubst*Term (fst-subst* ⊢F ⊢G (redₜ d′)) [F] [fstp′]₁)
in transEqTerm [F] [fstt≡fstp] (transEqTerm [F] [fst≡]₁ (symEqTerm [F] [fstt′≡fstp′]))
fst-cong′ [F] (emb 0<1 x) = fst-cong′ [F] x
-- Reducibility of congruence of fst
fst-cong″ : ∀ {F G t t′ Γ l l′}
([F] : Γ ⊩⟨ l′ ⟩ F)
([ΣFG] : Γ ⊩⟨ l ⟩ Σ F ▹ G)
([t≡t′] : Γ ⊩⟨ l ⟩ t ≡ t′ ∷ Σ F ▹ G / [ΣFG])
→ Γ ⊩⟨ l′ ⟩ fst t ≡ fst t′ ∷ F / [F]
fst-cong″ {F} {G} [F] [ΣFG] [t≡t′] =
let [t≡t′] = irrelevanceEqTerm [ΣFG] (B-intr BΣ (Σ-elim [ΣFG])) [t≡t′]
in fst-cong′ [F] (Σ-elim [ΣFG]) [t≡t′]
fst-congᵛ : ∀ {F G t t′ Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ Σ F ▹ G / [Γ] / Σᵛ {F} {G} [Γ] [F] [G])
([t′] : Γ ⊩ᵛ⟨ l ⟩ t′ ∷ Σ F ▹ G / [Γ] / Σᵛ {F} {G} [Γ] [F] [G])
([t≡t′] : Γ ⊩ᵛ⟨ l ⟩ t ≡ t′ ∷ Σ F ▹ G / [Γ] / Σᵛ {F} {G} [Γ] [F] [G])
→ Γ ⊩ᵛ⟨ l ⟩ fst t ≡ fst t′ ∷ F / [Γ] / [F]
fst-congᵛ {F} {G} [Γ] [F] [G] [t] [t′] [t≡t′] ⊢Δ [σ] =
let [ΣFG] = Σᵛ {F} {G} [Γ] [F] [G]
⊩σF = proj₁ ([F] ⊢Δ [σ])
⊩σΣFG = proj₁ ([ΣFG] ⊢Δ [σ])
⊩σt≡t′ = [t≡t′] ⊢Δ [σ]
in fst-cong″ ⊩σF ⊩σΣFG ⊩σt≡t′
-- Validity of first projection
fstᵛ : ∀ {F G t Γ l}
([Γ] : ⊩ᵛ Γ)
([F] : Γ ⊩ᵛ⟨ l ⟩ F / [Γ])
([G] : Γ ∙ F ⊩ᵛ⟨ l ⟩ G / [Γ] ∙ [F])
([t] : Γ ⊩ᵛ⟨ l ⟩ t ∷ Σ F ▹ G / [Γ] / Σᵛ {F} {G} [Γ] [F] [G])
→ Γ ⊩ᵛ⟨ l ⟩ fst t ∷ F / [Γ] / [F]
fstᵛ {F} {G} {t} {Γ} {l} [Γ] [F] [G] [t] {Δ = Δ} {σ = σ} ⊢Δ [σ] =
let [ΣFG] = Σᵛ {F} {G} [Γ] [F] [G]
σfst : ∀ {Δ σ} (⊢Δ : ⊢ Δ) ([σ] : Δ ⊩ˢ σ ∷ Γ / [Γ] / ⊢Δ)
→ Δ ⊩⟨ l ⟩ subst σ (fst t) ∷ subst σ F / proj₁ ([F] ⊢Δ [σ])
σfst {Δ} {σ} ⊢Δ [σ] =
let ⊩σF = proj₁ ([F] ⊢Δ [σ])
⊩σΣFG = proj₁ ([ΣFG] ⊢Δ [σ])
⊩σt = proj₁ ([t] ⊢Δ [σ])
in fst″ ⊩σF ⊩σΣFG ⊩σt
in σfst ⊢Δ [σ] ,
(λ {σ′} [σ′] [σ≡σ′] →
let [σF] = proj₁ ([F] ⊢Δ [σ])
[σΣFG] = proj₁ ([ΣFG] ⊢Δ [σ])
[σt≡σ′t] = proj₂ ([t] ⊢Δ [σ]) [σ′] [σ≡σ′]
in fst-cong″ [σF] [σΣFG] [σt≡σ′t])
| {
"alphanum_fraction": 0.4638712093,
"avg_line_length": 42.062992126,
"ext": "agda",
"hexsha": "820bec07353c6b5db1b8da8fc68a75a30efc6b0e",
"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": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Vtec234/logrel-mltt",
"max_forks_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Fst.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"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": "Vtec234/logrel-mltt",
"max_issues_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Fst.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4746894adb5b8edbddc8463904ee45c2e9b29b69",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Vtec234/logrel-mltt",
"max_stars_repo_path": "Definition/LogicalRelation/Substitution/Introductions/Fst.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2697,
"size": 5342
} |
------------------------------------------------------------------------------
-- The LTC-PCF natural numbers type
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.Type where
open import LTC-PCF.Base
------------------------------------------------------------------------------
-- The inductive predicate 'N' represents the type of the natural
-- numbers. They are a subset of 'D'.
-- The LTC-PCF natural numbers type (inductive predicate for total
-- natural numbers).
data N : D → Set where
nzero : N zero
nsucc : ∀ {n} → N n → N (succ₁ n)
-- Induction principle for N (elimination rule).
N-ind : (A : D → Set) →
A zero →
(∀ {n} → A n → A (succ₁ n)) →
∀ {n} → N n → A n
N-ind A A0 h nzero = A0
N-ind A A0 h (nsucc Nn) = h (N-ind A A0 h Nn)
| {
"alphanum_fraction": 0.4347399411,
"avg_line_length": 32.8709677419,
"ext": "agda",
"hexsha": "a87c86e9b45752b70d90ad9b49d577c379866b64",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/Type.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Data/Nat/Type.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Data/Nat/Type.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": 242,
"size": 1019
} |
open import Data.Product using ( _,_ )
open import Data.Sum using ( inj₁ ; inj₂ )
open import FRP.LTL.ISet.Core using
( ISet ; I⟦_⟧ ; M⟦_⟧ ; ⟦_⟧ ; ⌈_⌉ ; splitM⟦_⟧ ; subsumM⟦_⟧ ; i→m ; m→i ) renaming
( [_] to [_]′ )
open import FRP.LTL.ISet.Stateless using ( _⇒_ ; _$_ )
open import FRP.LTL.Time.Bound using ( fin ; +∞ ; +∞-top ; ≼-refl ; _≼-trans_ ; _≼-total_ ; _≼-asym_ ; ≺-impl-⋡ )
open import FRP.LTL.Time.Interval using ( ↑ ; [_⟩; _⊑_ ; lb≺ub ; lb≼ ; _,_ ; Int )
open import FRP.LTL.Util using ( ≡-relevant ; ⊥-elim )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Relation.Unary using ( _∈_ )
module FRP.LTL.ISet.Globally where
-- □ A is "A holds globally in the future"
□ : ISet → ISet
□ A = ⌈( λ t → M⟦ A ⟧ (↑ t) )⌉
-- Comonad structure of □
extend : ∀ {A B} → ⟦ A ⇒ B ⟧ → ⟦ □ A ⇒ □ B ⟧
extend {A} {B} f [ [ σ ]′ ]′ =
[ (λ t t∈i → i→m (λ j j⊑↑t → f [ subsumM⟦ A ⟧ j (↑ t) j⊑↑t (σ t t∈i) ]′)) ]′
extract : ∀ {A} → ⟦ □ A ⇒ A ⟧
extract {A} {[_⟩ {fin s} {t} s≺t} [ [ σ ]′ ]′ =
m→i (subsumM⟦ A ⟧ [ s≺t ⟩ (↑ s) (≼-refl , +∞-top) (σ s (≼-refl , s≺t)))
extract {A} {[_⟩ {+∞} {t} ∞≺t} [ [ σ ]′ ]′ =
⊥-elim (≺-impl-⋡ ∞≺t +∞-top)
duplicate : ∀ {A} → ⟦ □ A ⇒ □ (□ A) ⟧
duplicate {A} [ [ σ ]′ ]′ =
[ (λ t t∈i → [ (λ u u∈↑t → subsumM⟦ A ⟧ (↑ u) (↑ t) (lb≼ u∈↑t , ≼-refl) (σ t t∈i)) ]′) ]′
-- Applicative structure of □
[_] : ∀ {A} → ⟦ A ⟧ → ⟦ □ A ⟧
[ σ ] = [ (λ t t∈i → i→m (λ j j⊑↑t → σ)) ]′
_⟨*⟩_ : ∀ {A B} → ⟦ □ (A ⇒ B) ⇒ □ A ⇒ □ B ⟧
[ [ f ]′ ]′ ⟨*⟩ [ [ σ ]′ ]′ =
[ (λ t t∈i → (f t t∈i) $ (σ t t∈i)) ]′
| {
"alphanum_fraction": 0.4660691421,
"avg_line_length": 35.5,
"ext": "agda",
"hexsha": "cdfd48f08cb180869941a1057830c895c015269e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:04.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-01T07:33:00.000Z",
"max_forks_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/agda-frp-ltl",
"max_forks_repo_path": "src/FRP/LTL/ISet/Globally.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_issues_repo_issues_event_max_datetime": "2015-03-02T15:23:53.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-01T07:01:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/agda-frp-ltl",
"max_issues_repo_path": "src/FRP/LTL/ISet/Globally.agda",
"max_line_length": 114,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "e88107d7d192cbfefd0a94505e6a5793afe1a7a5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-frp-ltl",
"max_stars_repo_path": "src/FRP/LTL/ISet/Globally.agda",
"max_stars_repo_stars_event_max_datetime": "2020-06-15T02:51:13.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-02T20:25:05.000Z",
"num_tokens": 829,
"size": 1562
} |
{- NEW TRANSLATION STUFF: same thing but interpret source nat as ♭nat-}
open import Preliminaries
open import Source
open import Complexity
module Translation where
mutual
⟨⟨_⟩⟩ : Tp → CTp
⟨⟨ unit ⟩⟩ = unit
⟨⟨ nat ⟩⟩ = nat
⟨⟨ susp A ⟩⟩ = || A ||
⟨⟨ A ->s B ⟩⟩ = ⟨⟨ A ⟩⟩ ->c || B ||
⟨⟨ A ×s B ⟩⟩ = ⟨⟨ A ⟩⟩ ×c ⟨⟨ B ⟩⟩
⟨⟨ list A ⟩⟩ = list ⟨⟨ A ⟩⟩
⟨⟨ bool ⟩⟩ = bool
||_|| : Tp → CTp
|| τ || = C ×c ⟨⟨ τ ⟩⟩
⟨⟨_⟩⟩c : Source.Ctx → Complexity.Ctx
⟨⟨ [] ⟩⟩c = []
⟨⟨ x :: Γ ⟩⟩c = ⟨⟨ x ⟩⟩ :: ⟨⟨ Γ ⟩⟩c
interp-Cost : ∀{Γ} → Cost → Γ Complexity.|- C
interp-Cost 0c = 0C
interp-Cost 1c = 1C
interp-Cost (m +c n) = plusC (interp-Cost m) (interp-Cost n)
lookup : ∀{Γ τ} → τ Source.∈ Γ → ⟨⟨ τ ⟩⟩ Complexity.∈ ⟨⟨ Γ ⟩⟩c
lookup i0 = i0
lookup (iS x) = iS (lookup x)
_+C_ : ∀ {Γ τ} → Γ Complexity.|- C → Γ Complexity.|- (C ×c τ)→ Γ Complexity.|- (C ×c τ)
c +C e = prod (plusC c (l-proj e)) (r-proj e)
-- translation from source expressions to complexity expressions
||_||e : ∀{Γ τ} → Γ Source.|- τ → ⟨⟨ Γ ⟩⟩c Complexity.|- || τ ||
|| unit ||e = prod 0C unit
|| var x ||e = prod 0C (var (lookup x))
|| z ||e = prod 0C z
|| suc e ||e = prod (l-proj (|| e ||e)) (s (r-proj (|| e ||e)))
|| rec e e0 e1 ||e = (l-proj (|| e ||e)) +C (rec (r-proj || e ||e) (1C +C || e0 ||e) (1C +C || e1 ||e))
|| lam e ||e = prod 0C (lam || e ||e)
|| app e1 e2 ||e =
prod (plusC (plusC (plusC 1C (l-proj || e1 ||e)) (l-proj || e2 ||e)) (l-proj (app (r-proj || e1 ||e) (r-proj || e2 ||e))))
(r-proj (app (r-proj || e1 ||e) (r-proj || e2 ||e)))
|| prod e1 e2 ||e = prod (plusC (l-proj (|| e1 ||e)) (l-proj (|| e2 ||e))) (prod (r-proj (|| e1 ||e)) (r-proj (|| e2 ||e)))
|| delay e ||e = prod 0C (|| e ||e)
|| force e ||e = prod (plusC (l-proj (|| e ||e)) (l-proj (r-proj || e ||e))) (r-proj (r-proj (|| e ||e)))
|| split e0 e1 ||e = prod (plusC (l-proj (|| e0 ||e)) (l-proj E1)) (r-proj E1)
where E1 = (Complexity.subst || e1 ||e (Complexity.lem4 (l-proj (r-proj || e0 ||e)) (r-proj (r-proj || e0 ||e))))
|| nil ||e = prod 0C nil
|| e ::s e₁ ||e = prod (plusC (l-proj || e ||e) (l-proj || e₁ ||e)) ((r-proj || e ||e) ::c (r-proj || e₁ ||e))
|| listrec e e₁ e₂ ||e = l-proj || e ||e +C listrec (r-proj || e ||e) (1C +C || e₁ ||e) (1C +C || e₂ ||e)
|| true ||e = prod 0C true
|| false ||e = prod 0C false
-- new translation with let bindings to reduce exponential increase in term size
throw-s : ∀ {Γ Γ' τ} → Complexity.sctx Γ (τ :: Γ') → Complexity.sctx Γ Γ'
throw-s Θ x = Θ (iS x)
_+C'_ : ∀ {Γ τ} → Γ Complexity.|- C → Γ Complexity.|- (C ×c τ)→ Γ Complexity.|- (C ×c τ)
c +C' e = letc (prod (plusC (Complexity.wkn c) (l-proj (var i0))) (r-proj (var i0))) e
||_||e' : ∀{Γ τ} → Γ Source.|- τ → ⟨⟨ Γ ⟩⟩c Complexity.|- || τ ||
|| unit ||e' = prod 0C unit
|| var x ||e' = prod 0C (var (lookup x))
|| z ||e' = prod 0C z
|| suc e ||e' = (letc (prod (l-proj (var i0)) (s (r-proj (var i0)))) || e ||e')
-- || rec e e0 e1 ||e = (l-proj (|| e ||e)) +C (rec (r-proj || e ||e) (1C +C || e0 ||e) (1C +C || e1 ||e))
|| rec e e0 e1 ||e' =
letc (l-proj (var i0) +C' rec (r-proj (var i0))
(Complexity.wkn (1C +C' || e0 ||e'))
(Complexity.subst (1C +C' || e1 ||e') (Complexity.s-extend (Complexity.s-extend (throw-s Complexity.ids)))))
|| e ||e'
|| lam e ||e' = prod 0C (lam || e ||e')
|| app e1 e2 ||e' = letc (letc (prod (plusC (plusC (plusC 1C (l-proj (var (iS i0)))) (l-proj (var i0))) (l-proj (app (r-proj (var (iS i0))) (r-proj (var i0)))))
(r-proj (app (r-proj (var (iS i0))) (r-proj (var i0))))) (Complexity.wkn || e2 ||e')) || e1 ||e'
|| prod e1 e2 ||e' = letc (letc (prod (plusC (l-proj (var (iS i0))) (l-proj (var i0))) (prod (r-proj (var (iS i0))) (r-proj (var i0)))) (Complexity.wkn || e2 ||e')) || e1 ||e'
|| delay e ||e' = prod 0C || e ||e'
|| force e ||e' = letc (prod (plusC (l-proj (var i0)) (l-proj (r-proj (var i0)))) (r-proj (r-proj (var i0)))) || e ||e'
|| split e0 e1 ||e' = letc (prod (plusC (Complexity.wkn (l-proj || e0 ||e')) (l-proj (var i0))) (r-proj (var i0))) E1
where E1 = letc (Complexity.subst || e1 ||e' (Complexity.lem4 (l-proj (r-proj (var i0))) (r-proj (r-proj (var i0))) Complexity.ss Complexity.s-extend (Complexity.s-extend (throw-s Complexity.ids)))) || e0 ||e'
|| nil ||e' = prod 0C nil
|| e ::s e₁ ||e' = letc (letc (prod (plusC (l-proj (var (iS i0))) (l-proj (var i0))) (r-proj (var (iS i0)) ::c r-proj (var i0))) (Complexity.wkn || e₁ ||e')) || e ||e'
|| listrec e e₁ e₂ ||e' =
letc (l-proj (var i0) +C' listrec (r-proj (var i0))
(Complexity.wkn (1C +C' || e₁ ||e')) (Complexity.subst (1C +C' || e₂ ||e') (Complexity.s-extend (Complexity.s-extend (Complexity.s-extend (throw-s Complexity.ids)))))) || e ||e'
|| true ||e' = prod 0C true
|| false ||e' = prod 0C false
{- try prove ||.||old <=/=> ||.||new
trans-eq-l : ∀ {Γ τ} → (e : Γ Source.|- τ) → || e ||e ≤s || e ||e'
trans-eq-l unit = refl-s
trans-eq-l (var x) = refl-s
trans-eq-l z = refl-s
trans-eq-l (suc e) = (cong-prod (cong-lproj (trans-eq-l e)) (cong-suc (cong-rproj (trans-eq-l e))) trans lam-s) trans letc-app-r
trans-eq-l (rec e e₁ e₂) = {!!}
trans-eq-l (lam e) = cong-prod refl-s (cong-lam (trans-eq-l e))
trans-eq-l (app e e₁) = {!!}
trans-eq-l (prod e e₁) = (((cong-prod (cong-+ (cong-lproj {!!}) (cong-lproj {!!})) {!!} trans lam-s) trans letc-app-r) trans lam-s) trans letc-app-r
trans-eq-l (delay e) = {!!}
trans-eq-l (force e) = {!!}
trans-eq-l (split e e₁) = {!!}
trans-eq-l nil = {!!}
trans-eq-l (e ::s e₁) = {!!}
trans-eq-l (listrec e e₁ e₂) = {!!}
trans-eq-l true = refl-s
trans-eq-l false = refl-s
-}
| {
"alphanum_fraction": 0.4987012987,
"avg_line_length": 50.2173913043,
"ext": "agda",
"hexsha": "b89b0950585383f3475950bd7377687aa2803155",
"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": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "benhuds/Agda",
"max_forks_repo_path": "complexity/complexity-final/submit/Translation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_issues_repo_issues_event_max_datetime": "2020-05-12T00:32:45.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-23T08:39:04.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "benhuds/Agda",
"max_issues_repo_path": "complexity/complexity-final/submit/Translation.agda",
"max_line_length": 216,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "2404a6ef2688f879bda89860bb22f77664ad813e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "benhuds/Agda",
"max_stars_repo_path": "complexity/complexity-final/submit/Translation.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-08T12:27:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-26T20:22:22.000Z",
"num_tokens": 2505,
"size": 5775
} |
{-# OPTIONS --allow-unsolved-metas #-}
data U : ∀ t → Set
data T t : Set
| {
"alphanum_fraction": 0.5810810811,
"avg_line_length": 14.8,
"ext": "agda",
"hexsha": "c0f3d59d632829b47dd58f99772247e29bcb43a1",
"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/MissingDefinitionData.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/MissingDefinitionData.agda",
"max_line_length": 38,
"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/MissingDefinitionData.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": 24,
"size": 74
} |
module Quantifiers where
-- Imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_)
open import Relation.Nullary using (¬_)
open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
-- open import plfa.part1.Isomorphism using (_≃_; extensionality)
-- 同型 (isomorphism)
infix 0 _≃_
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
postulate
-- 外延性の公理
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
-- Universals
-- 全称量化子の除去則
∀-elim : ∀ {A : Set} {B : A → Set}
→ (L : ∀ (x : A) → B x)
→ (M : A)
---------------------
→ B M
∀-elim L M = L M
-- Existentials
-- 依存和型 (dependent sum type)
data Σ (A : Set) (B : A → Set) : Set where
⟨_,_⟩ : (x : A) → B x → Σ A B
Σ-syntax = Σ
infix 2 Σ-syntax
syntax Σ-syntax A (λ x → B) = Σ[ x ∈ A ] B
record Σ′ (A : Set) (B : A → Set) : Set where
field
proj₁′ : A
proj₂′ : B proj₁′
-- 存在量化子 (existential quantifier)
∃ : ∀ {A : Set} (B : A → Set) → Set
∃ {A} B = Σ A B
∃-syntax = ∃
syntax ∃-syntax (λ x → B) = ∃[ x ] B
-- 存在量化子の除去則
∃-elim : ∀ {A : Set} {B : A → Set} {C : Set}
→ (∀ x → B x → C)
→ ∃[ x ] B x
---------------
→ C
∃-elim f ⟨ x , y ⟩ = f x y
∀∃-currying : ∀ {A : Set} {B : A → Set} {C : Set}
→ (∀ x → B x → C) ≃ (∃[ x ] B x → C)
∀∃-currying =
record
{ to = λ{ f → λ{ ⟨ x , y ⟩ → f x y }}
; from = λ{ g → λ{ x → λ{ y → g ⟨ x , y ⟩ }}}
; from∘to = λ{ f → refl }
; to∘from = λ{ g → extensionality λ{ ⟨ x , y ⟩ → refl }}
}
-- An existential example
data even : ℕ → Set
data odd : ℕ → Set
data even where
even-zero : even zero
even-suc : ∀ {n : ℕ}
→ odd n
------------
→ even (suc n)
data odd where
odd-suc : ∀ {n : ℕ}
→ even n
-----------
→ odd (suc n)
even-∃ : ∀ {n : ℕ} → even n → ∃[ m ] ( m * 2 ≡ n)
odd-∃ : ∀ {n : ℕ} → odd n → ∃[ m ] (1 + m * 2 ≡ n)
even-∃ even-zero = ⟨ zero , refl ⟩
even-∃ (even-suc o) with odd-∃ o
... | ⟨ m , refl ⟩ = ⟨ suc m , refl ⟩
odd-∃ (odd-suc e) with even-∃ e
... | ⟨ m , refl ⟩ = ⟨ m , refl ⟩
∃-even : ∀ {n : ℕ} → ∃[ m ] ( m * 2 ≡ n) → even n
∃-odd : ∀ {n : ℕ} → ∃[ m ] (1 + m * 2 ≡ n) → odd n
∃-even ⟨ zero , refl ⟩ = even-zero
∃-even ⟨ suc m , refl ⟩ = even-suc (∃-odd ⟨ m , refl ⟩)
∃-odd ⟨ m , refl ⟩ = odd-suc (∃-even ⟨ m , refl ⟩)
-- Existentials, Universals, and Negation
-- B(x)が成り立たないxが存在することと、任意のxについてB(x)が成り立たないことは同型
¬∃≃∀¬ : ∀ {A : Set} {B : A → Set}
→ (¬ ∃[ x ] B x) ≃ ∀ x → ¬ B x
¬∃≃∀¬ =
record
{ to = λ{ ¬∃xy x y → ¬∃xy ⟨ x , y ⟩ }
; from = λ{ ∀¬xy ⟨ x , y ⟩ → ∀¬xy x y }
; from∘to = λ{ ¬∃xy → extensionality λ{ ⟨ x , y ⟩ → refl } }
; to∘from = λ{ ∀¬xy → refl }
}
| {
"alphanum_fraction": 0.4455117589,
"avg_line_length": 23.2230769231,
"ext": "agda",
"hexsha": "b1a3b68db2004c0d105e568daab767c3b70a6912",
"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": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/quantifiers/Quantifiers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"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": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/quantifiers/Quantifiers.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/quantifiers/Quantifiers.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 1349,
"size": 3019
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.