Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --safe #-}
module Generics.Constructions.Show where
open import Generics.Prelude hiding (lookup)
open import Generics.Telescope
open import Generics.Desc
open import Generics.All
open import Generics.HasDesc
import Generics.Helpers as Helpers
import Data.Vec.Base as Vec
import Data.String as String
open import Data.Maybe as Maybe
open import Data.These hiding (alignWith)
open String hiding (show)
record Show {l} (A : Set l) : Set l where field show : A → String
open Show ⦃...⦄ public
private
dummyShow : ∀ {l} (A : Set l) → Show A
dummyShow A .show _ = ""
join : These String String → String
join (this x) = x
join (that x) = x
join (these x y) = x ++ " , " ++ y
module _
{P I ℓ} {A : Indexed P I ℓ} (H : HasDesc A)
(open HasDesc H)
(open Helpers P I Show (const ⊤) (λ _ → Liftω ⊤))
where
ShowHelpers : ∀ p → Setω
ShowHelpers p = Helpers p D
module _ {p} (helpers : ShowHelpers p) where
variable
V : ExTele P
v : ⟦ V ⟧tel p
i : ⟦ I ⟧tel p
showData-wf : (x : ⟦ D ⟧Data A′ (p , i))
→ AllDataω Acc D x
→ Maybe String
show-wf : (x : A′ (p , i)) → Acc x → Maybe String
show-wf x (acc a) = showData-wf (split x) a
showData-wf (k , x) a = just $
Vec.lookup names k
++ fromMaybe "" (Maybe.map (λ x → " (" ++ x ++ ")")
(showCon (lookupCon D k) (lookupHelper helpers k) x a))
where
showIndArg : (C : ConDesc P V I)
(x : ⟦ C ⟧IndArg A′ (p , v))
→ AllIndArgω Acc C x
→ Maybe String
showIndArg (var _) x a = show-wf x a
showIndArg (π ia S C) x a = just "?f"
showIndArg (A ⊗ B) (xa , xb) (aa , ab)
= alignWith join (showIndArg A xa aa) (showIndArg B xb ab)
showCon : (C : ConDesc P V I)
(H : ConHelper p C)
(x : ⟦ C ⟧Con A′ (p , v , i))
→ AllConω Acc C x
→ Maybe String
showCon ._ var refl tt = nothing
showCon ._ (pi-irr ⦃ _ ⦄ ⦃ H ⦄) (s , x) a
= alignWith join (just "._") (showCon _ H x a)
showCon ._ (pi-rel ⦃ S ⦄ ⦃ H ⦄) (s , x) a
= alignWith join (just (show ⦃ S ⦄ s)) (showCon _ H x a)
showCon ._ (prod {A} {B} ⦃ HA ⦄ ⦃ HB ⦄) (xa , xb) (aa , ab)
= alignWith join (showIndArg A xa aa) (showCon B HB xb ab)
show′ : (x : A′ (p , i)) → Maybe String
show′ x = show-wf x (wf x)
deriveShow : ∀ {p} ⦃ SH : ShowHelpers p ⦄ {i} → Show (A′ (p , i))
deriveShow ⦃ SH ⦄ .show = fromMaybe "" ∘ show′ SH
|
{
"alphanum_fraction": 0.5261950287,
"avg_line_length": 29.7159090909,
"ext": "agda",
"hexsha": "07197116c32a8febfaefeef2fd39aec6d193e1c3",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Constructions/Show.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Constructions/Show.agda",
"max_line_length": 88,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Constructions/Show.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 893,
"size": 2615
}
|
------------------------------------------------------------------------------
-- Natural numbers (added for the Collatz function example)
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- We don't want populate the FOTC library with more first-order logic
-- axioms.
module FOTC.Program.Collatz.Data.Nat where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.UnaryNumbers
infixr 8 _^_
------------------------------------------------------------------------------
postulate
div : D → D → D
div-x<y : ∀ {m n} → n ≢ 0' → m < n → div m n ≡ zero
div-x≥y : ∀ {m n} → n ≢ 0' → m ≥ n → div m n ≡ succ₁ (div (m ∸ n) n)
{-# ATP axioms div-x<y div-x≥y #-}
postulate
_^_ : D → D → D
^-0 : ∀ n → n ^ zero ≡ 1'
^-S : ∀ m n → m ^ succ₁ n ≡ m * m ^ n
{-# ATP axioms ^-0 ^-S #-}
postulate
even : D → D
odd : D → D
even-0 : even zero ≡ true
even-S : ∀ n → even (succ₁ n) ≡ odd n
odd-0 : odd zero ≡ false
odd-S : ∀ n → odd (succ₁ n) ≡ even n
{-# ATP axioms even-0 even-S odd-0 odd-S #-}
Even : D → Set
Even n = even n ≡ true
{-# ATP definition Even #-}
NotEven : D → Set
NotEven n = even n ≡ false
{-# ATP definition NotEven #-}
Odd : D → Set
Odd n = odd n ≡ true
{-# ATP definition Odd #-}
|
{
"alphanum_fraction": 0.4675925926,
"avg_line_length": 26.0689655172,
"ext": "agda",
"hexsha": "61d7bbc88d3fbd81b177b4d42200ad10786b8bec",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Collatz/Data/Nat.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Collatz/Data/Nat.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Collatz/Data/Nat.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": 448,
"size": 1512
}
|
module plfa-code.Equality where
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
infix 4 _≡_
sym : ∀ {A : Set} {x y : A}
→ x ≡ y
-------
→ y ≡ x
sym refl = refl
trans : ∀ {A : Set} {x y z : A}
→ x ≡ y
→ y ≡ z
-------
→ x ≡ z
trans refl refl = refl
cong : ∀ {A B : Set} (f : A → B) {x y : A}
→ x ≡ y
-----------
→ f x ≡ f y
cong f refl = refl
cong₂ : ∀ {A B C : Set} (f : A → B → C) {u x : A} {v y : B}
→ u ≡ x
→ v ≡ y
---------------
→ f u v ≡ f x y
cong₂ _ refl refl = refl
cong-app : ∀ {A B : Set} {f g : A → B}
→ f ≡ g
------------------------
→ ∀ (x : A) → f x ≡ g x
cong-app refl _ = refl
subst : ∀ {A : Set} {x y : A} (P : A → Set)
→ x ≡ y
-----------
→ P x → P y
subst _ refl px = px
module ≡-Reasoning {A : Set} where
infix 1 begin_
infixr 2 _≡⟨⟩_ _≡⟨_⟩_
infix 3 _∎
begin_ : ∀ {x y : A}
→ x ≡ y
-------
→ x ≡ y
begin x≡y = x≡y
_≡⟨⟩_ : ∀ (x : A) {y : A}
→ x ≡ y
-------
→ x ≡ y
x ≡⟨⟩ x≡y = x≡y
_≡⟨_⟩_ : ∀ (x : A) {y z : A}
→ x ≡ y
→ y ≡ z
-------
→ x ≡ z
x ≡⟨ x≡y ⟩ y≡z = trans x≡y y≡z
_∎ : ∀ (x : A)
------
→ x ≡ x
x ∎ = refl
open ≡-Reasoning
trans′ : ∀ {A : Set} {x y z : A}
→ x ≡ y
→ y ≡ z
-------
→ x ≡ z
trans′ {A} {x} {y} {z} x≡y y≡z =
begin
x
≡⟨ x≡y ⟩
y
≡⟨ y≡z ⟩
z
∎
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
zero + n = n
(suc m) + n = suc (m + n)
-- use postulate
postulate
+-identity : ∀ (m : ℕ) → m + zero ≡ m
+-suc : ∀ (m n : ℕ) → m + suc n ≡ suc (m + n)
+-comm : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm m zero =
begin
m + zero
≡⟨ +-identity m ⟩
m
≡⟨⟩
zero + m
∎
+-comm m (suc n) =
begin
m + suc n
≡⟨ +-suc m n ⟩
suc (m + n)
≡⟨ cong suc (+-comm m n) ⟩
suc (n + m)
≡⟨⟩
suc n + m
∎
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ}
---------
→ zero ≤ n
s≤s : ∀ {m n : ℕ}
→ m ≤ n
--------------
→ suc m ≤ suc n
infix 4 _≤_
postulate
≤-trans : ∀ {m n p : ℕ} → m ≤ n → n ≤ p → m ≤ p
≤-refl : ∀ {n : ℕ} → n ≤ n
≡→≤ : ∀ {x y} → x ≡ y → x ≤ y
≡→≤ refl = ≤-refl
module ≤-Reasoning where
infix 1 ≤begin_
infixr 2 _≤⟨⟩_ _≤⟨_⟩_ _≤[_]_
infix 3 _≤∎
≤begin_ : ∀ {x y} → x ≤ y → x ≤ y
≤begin x≤y = x≤y
_≤⟨⟩_ : ∀ (x) {y : ℕ} → x ≤ y → x ≤ y
_ ≤⟨⟩ x≤y = x≤y
_≤⟨_⟩_ : ∀ (x) {y z : ℕ} → x ≤ y → y ≤ z → x ≤ z
x ≤⟨ x≤y ⟩ y≤z = ≤-trans x≤y y≤z
_≤[_]_ : ∀ (x) {y z : ℕ} → x ≡ y → y ≤ z → x ≤ z
x ≤[ x≡y ] y≤z = ≤-trans (≡→≤ x≡y) y≤z
_≤∎ : ∀ x → x ≤ x
_ ≤∎ = ≤-refl
open ≤-Reasoning
+-monoʳ-≤ : ∀ (n p q : ℕ) → p ≤ q → (n + p) ≤ (n + q)
+-monoʳ-≤ zero p q p≤q =
≤begin
(zero + p)
≤⟨⟩
p
≤⟨ p≤q ⟩
q
≤⟨⟩
zero + q
≤∎
+-monoʳ-≤ (suc n) p q p≤q =
≤begin
suc n + p
≤⟨⟩
suc (n + p)
≤⟨ s≤s (+-monoʳ-≤ _ _ _ p≤q) ⟩
suc (n + q)
≤⟨⟩
suc n + q
≤∎
+-monoˡ-≤ : ∀ (m n p : ℕ) → m ≤ n → (m + p) ≤ (n + p)
+-monoˡ-≤ m n p m≤n =
≤begin
m + p
≤[ +-comm m p ]
p + m
≤⟨ +-monoʳ-≤ p _ _ m≤n ⟩
p + n
≤[ +-comm p n ]
n + p
≤∎
+-mono-≤ : ∀ (m n p q : ℕ) → m ≤ n → p ≤ q → m + p ≤ n + q
+-mono-≤ m n p q m≤n p≤q =
≤begin
m + p
≤⟨ +-monoˡ-≤ _ _ _ m≤n ⟩
n + p
≤⟨ +-monoʳ-≤ _ _ _ p≤q ⟩
n + q
≤∎
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)
{-# BUILTIN EQUALITY _≡_ #-}
even-comm : ∀ (m n : ℕ)
→ even (m + n)
-------------
→ even (n + m)
even-comm m n ev rewrite +-comm n m = ev
+-comm′ : ∀ (m n : ℕ) → m + n ≡ n + m
+-comm′ zero n rewrite +-identity n = refl
+-comm′ (suc m) n rewrite +-suc n m | +-comm′ m n = refl
even-comm′ : ∀ (m n : ℕ)
→ even (m + n)
------------
→ even (n + m)
even-comm′ m n ev with m + n | +-comm m n
... | .(n + m) | refl = ev
_≐_ : ∀ {A : Set} (x y : A) → Set₁
_≐_ {A} x y = ∀ (P : A → Set) → P x → P y
refl-≐ : ∀ {A : Set} {x : A}
→ x ≐ x
refl-≐ P Px = Px
trans-≐ : ∀ {A : Set} {x y z : A}
→ x ≐ y
→ y ≐ z
------
→ x ≐ z
trans-≐ x≐y y≐z P Px = y≐z P (x≐y P Px)
sym-≐ : ∀ {A : Set} {x y : A}
→ x ≐ y
------
→ y ≐ x
sym-≐ {A} {x} {y} x≐y P = Qy
where
Q : A → Set
Q z = P z → P x
Qx : Q x
Qx = refl-≐ P
Qy : Q y
Qy = x≐y Q Qx
≡-implies-≐ : ∀ {A : Set} {x y : A}
→ x ≡ y
-------
→ x ≐ y
≡-implies-≐ x≡y P = subst P x≡y
≐-implies-≡ : ∀ {A : Set} {x y : A}
→ x ≐ y
-------
→ x ≡ y
≐-implies-≡ {A} {x} {y} x≐y = Qy
where
Q : A → Set
Q z = x ≡ z
Qx : Q x
Qx = refl
Qy : Q y
Qy = x≐y Q Qx
open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
data _≡′_ {ℓ : Level} {A : Set ℓ} (x : A) : A → Set ℓ where
refl′ : x ≡′ x
sym′ : ∀ {ℓ : Level} {A : Set ℓ} {x y : A}
→ x ≡′ y
--------
→ y ≡′ x
sym′ refl′ = refl′
_≐′_ : ∀ {ℓ : Level} {A : Set ℓ} (x y : A) → Set (lsuc ℓ)
_≐′_ {ℓ} {A} x y = ∀ (P : A → Set ℓ) → P x → P y
|
{
"alphanum_fraction": 0.3604336043,
"avg_line_length": 16.5576923077,
"ext": "agda",
"hexsha": "9d72125f440bfdc1c8cc7e5782d6cc1bd8bb2f96",
"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": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "chirsz-ever/plfa-code",
"max_forks_repo_path": "src/plfa-code/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"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": "chirsz-ever/plfa-code",
"max_issues_repo_path": "src/plfa-code/Equality.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ec5b359a8c22bf5268cae3c36a97e6737c75d5f3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "chirsz-ever/plfa-code",
"max_stars_repo_path": "src/plfa-code/Equality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2696,
"size": 5166
}
|
{-# OPTIONS --cubical --safe #-}
module Test where
open import Cubical.Core.Everything using (_≡_; Level; Type; Σ; _,_; fst; snd; _≃_; ~_)
open import Cubical.Foundations.Prelude using (refl; sym; _∙_; cong; transport; subst; funExt; transp; I; i0; i1)
open import Cubical.Foundations.Function using (_∘_)
open import Cubical.Foundations.Univalence using (ua)
open import Cubical.Foundations.Isomorphism using (iso; Iso; isoToPath; section; retract)
open import Data.Bool.Base using (Bool; true; false; _∧_)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Product using (_×_; proj₁; proj₂)
natrec : (P : ℕ → Type) → P 0 → ((n : ℕ) → P n → P (suc n)) → (n : ℕ) → P n
natrec P z s zero = z
natrec P z s (suc n) = s n (natrec P z s n)
_+_ : ℕ → ℕ → ℕ
_+_ = λ m → λ n → natrec (λ _ → ℕ) n (λ _ → suc) m
0=0 : 0 ≡ 0
0=0 = refl
suc=suc : (m n : ℕ) → m ≡ n → suc m ≡ suc n
suc=suc m n e = cong suc e
0+n=n : (n : ℕ) → 0 + n ≡ n
0+n=n = natrec (λ k → 0 + k ≡ k) 0=0 (λ n e → suc=suc n n e)
n=0+n : (n : ℕ) → n + 0 ≡ n
n=0+n = natrec (λ k → k + 0 ≡ k) 0=0 λ n e → suc=suc (n + 0) n e
|
{
"alphanum_fraction": 0.5903829029,
"avg_line_length": 33.0294117647,
"ext": "agda",
"hexsha": "56544ef5e4f87f87cc0014bf940970668ae5c16a",
"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": "5b22f5cb073dc2508ad158959a096df7763c57c4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/Alae",
"max_forks_repo_path": "agda/Test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5b22f5cb073dc2508ad158959a096df7763c57c4",
"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": "halfaya/Alae",
"max_issues_repo_path": "agda/Test.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5b22f5cb073dc2508ad158959a096df7763c57c4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/Alae",
"max_stars_repo_path": "agda/Test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 456,
"size": 1123
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- A generalisation of the arithmetic operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Nat.GeneralisedArithmetic where
open import Data.Nat
open import Data.Nat.Properties
open import Function using (_∘′_; _∘_; id)
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
module _ {a} {A : Set a} where
fold : A → (A → A) → ℕ → A
fold z s zero = z
fold z s (suc n) = s (fold z s n)
add : (0# : A) (1+ : A → A) → ℕ → A → A
add 0# 1+ n z = fold z 1+ n
mul : (0# : A) (1+ : A → A) → (+ : A → A → A) → (ℕ → A → A)
mul 0# 1+ _+_ n x = fold 0# (λ s → x + s) n
-- Properties
module _ {a} {A : Set a} where
fold-+ : ∀ {s : A → A} {z : A} →
∀ m {n} → fold z s (m + n) ≡ fold (fold z s n) s m
fold-+ zero = refl
fold-+ {s = s} (suc m) = cong s (fold-+ m)
fold-k : ∀ {s : A → A} {z : A} {k} m →
fold k (s ∘′_) m z ≡ fold (k z) s m
fold-k zero = refl
fold-k {s = s} (suc m) = cong s (fold-k m)
fold-* : ∀ {s : A → A} {z : A} m {n} →
fold z s (m * n) ≡ fold z (fold id (s ∘_) n) m
fold-* zero = refl
fold-* {s = s} {z} (suc m) {n} = let +n = fold id (s ∘′_) n in begin
fold z s (n + m * n) ≡⟨ fold-+ n ⟩
fold (fold z s (m * n)) s n ≡⟨ cong (λ z → fold z s n) (fold-* m) ⟩
fold (fold z +n m) s n ≡⟨ sym (fold-k n) ⟩
fold z +n (suc m) ∎
fold-pull : ∀ {s : A → A} {z : A} (g : A → A → A) (p : A)
(eqz : g z p ≡ p)
(eqs : ∀ l → s (g l p) ≡ g (s l) p) →
∀ m → fold p s m ≡ g (fold z s m) p
fold-pull _ _ eqz _ zero = sym eqz
fold-pull {s = s} {z} g p eqz eqs (suc m) = begin
s (fold p s m) ≡⟨ cong s (fold-pull g p eqz eqs m) ⟩
s (g (fold z s m) p) ≡⟨ eqs (fold z s m) ⟩
g (s (fold z s m)) p ∎
id-is-fold : ∀ m → fold zero suc m ≡ m
id-is-fold zero = refl
id-is-fold (suc m) = cong suc (id-is-fold m)
+-is-fold : ∀ m {n} → fold n suc m ≡ m + n
+-is-fold zero = refl
+-is-fold (suc m) = cong suc (+-is-fold m)
*-is-fold : ∀ m {n} → fold zero (n +_) m ≡ m * n
*-is-fold zero = refl
*-is-fold (suc m) {n} = cong (n +_) (*-is-fold m)
^-is-fold : ∀ {m} n → fold 1 (m *_) n ≡ m ^ n
^-is-fold zero = refl
^-is-fold {m} (suc n) = cong (m *_) (^-is-fold n)
*+-is-fold : ∀ m n {p} → fold p (n +_) m ≡ m * n + p
*+-is-fold m n {p} = begin
fold p (n +_) m ≡⟨ fold-pull _+_ p refl
(λ l → sym (+-assoc n l p)) m ⟩
fold 0 (n +_) m + p ≡⟨ cong (_+ p) (*-is-fold m) ⟩
m * n + p ∎
^*-is-fold : ∀ m n {p} → fold p (m *_) n ≡ m ^ n * p
^*-is-fold m n {p} = begin
fold p (m *_) n ≡⟨ fold-pull _*_ p (*-identityˡ p)
(λ l → sym (*-assoc m l p)) n ⟩
fold 1 (m *_) n * p ≡⟨ cong (_* p) (^-is-fold n) ⟩
m ^ n * p ∎
|
{
"alphanum_fraction": 0.4286671132,
"avg_line_length": 32.8131868132,
"ext": "agda",
"hexsha": "1c08acd0c6c817ac34d1f755abb12b7e783c7b83",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GeneralisedArithmetic.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/Nat/GeneralisedArithmetic.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/Nat/GeneralisedArithmetic.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1232,
"size": 2986
}
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- About the group structure of integers and bags for Nehemiah plugin.
------------------------------------------------------------------------
module Theorem.Groups-Nehemiah where
open import Structure.Bag.Nehemiah public
open import Relation.Binary.PropositionalEquality
open import Algebra.Structures
4-way-shuffle : ∀ {A : Set} {f} {z a b c d : A}
{{comm-monoid : IsCommutativeMonoid _≡_ f z}} →
f (f a b) (f c d) ≡ f (f a c) (f b d)
4-way-shuffle {f = f} {z = z} {a} {b} {c} {d} {{comm-monoid}} =
let
assoc = associative comm-monoid
cmute = commutative comm-monoid
in
begin
f (f a b) (f c d)
≡⟨ assoc a b (f c d) ⟩
f a (f b (f c d))
≡⟨ cong (f a) (sym (assoc b c d)) ⟩
f a (f (f b c) d)
≡⟨ cong (λ hole → f a (f hole d)) (cmute b c) ⟩
f a (f (f c b) d)
≡⟨ cong (f a) (assoc c b d) ⟩
f a (f c (f b d))
≡⟨ sym (assoc a c (f b d)) ⟩
f (f a c) (f b d)
∎ where open ≡-Reasoning
module _ where
open import Data.Nat
-- Apologies for irregular name.
ℕ-mn·pq=mp·nq : ∀ {m n p q : ℕ} →
(m + n) + (p + q) ≡ (m + p) + (n + q)
ℕ-mn·pq=mp·nq {m} {n} {p} {q} =
4-way-shuffle {a = m} {n} {p} {q} {{comm-monoid-nat}}
open import Data.Integer
n+[m-n]=m : ∀ {n m} → n + (m - n) ≡ m
n+[m-n]=m {n} {m} =
begin
n + (m - n)
≡⟨ cong (λ hole → n + hole) (commutative-int m (- n)) ⟩
n + (- n + m)
≡⟨ sym (associative-int n (- n) m) ⟩
(n - n) + m
≡⟨ cong (λ hole → hole + m) (right-inv-int n) ⟩
(+ 0) + m
≡⟨ left-id-int m ⟩
m
∎ where open ≡-Reasoning
a++[b\\a]=b : ∀ {a b} → a ++ (b \\ a) ≡ b
a++[b\\a]=b {b} {d} = trans
(cong (λ hole → b ++ hole) (commutative-bag d (negateBag b))) (trans
(sym (associative-bag b (negateBag b) d)) (trans
(cong (λ hole → hole ++ d) (right-inv-bag b))
(left-id-bag d)))
ab·cd=ac·bd : ∀ {a b c d : Bag} →
(a ++ b) ++ (c ++ d) ≡ (a ++ c) ++ (b ++ d)
ab·cd=ac·bd {a} {b} {c} {d} =
4-way-shuffle {a = a} {b} {c} {d} {{comm-monoid-bag}}
mn·pq=mp·nq : ∀ {m n p q : ℤ} →
(m + n) + (p + q) ≡ (m + p) + (n + q)
mn·pq=mp·nq {m} {n} {p} {q} =
4-way-shuffle {a = m} {n} {p} {q} {{comm-monoid-int}}
inverse-unique : ∀ {A : Set} {f neg} {z a b : A}
{{abelian : IsAbelianGroup _≡_ f z neg}} →
f a b ≡ z → b ≡ neg a
inverse-unique {f = f} {neg} {z} {a} {b} {{abelian}} ab=z =
let
assoc = associative (IsAbelianGroup.isCommutativeMonoid abelian)
cmute = commutative (IsAbelianGroup.isCommutativeMonoid abelian)
in
begin
b
≡⟨ sym (left-identity abelian b) ⟩
f z b
≡⟨ cong (λ hole → f hole b) (sym (left-inverse abelian a)) ⟩
f (f (neg a) a) b
≡⟨ assoc (neg a) a b ⟩
f (neg a) (f a b)
≡⟨ cong (f (neg a)) ab=z ⟩
f (neg a) z
≡⟨ right-identity abelian (neg a) ⟩
neg a
∎ where
open ≡-Reasoning
eq1 : f (neg a) (f a b) ≡ f (neg a) z
eq1 rewrite ab=z = cong (f (neg a)) refl
distribute-neg : ∀ {A : Set} {f neg} {z a b : A}
{{abelian : IsAbelianGroup _≡_ f z neg}} →
f (neg a) (neg b) ≡ neg (f a b)
distribute-neg {f = f} {neg} {z} {a} {b} {{abelian}} = inverse-unique
{{abelian}}
(begin
f (f a b) (f (neg a) (neg b))
≡⟨ 4-way-shuffle {{IsAbelianGroup.isCommutativeMonoid abelian}} ⟩
f (f a (neg a)) (f b (neg b))
≡⟨ cong₂ f (inverse a) (inverse b) ⟩
f z z
≡⟨ left-identity abelian z ⟩
z
∎) where
open ≡-Reasoning
inverse = right-inverse abelian
-a·-b=-ab : ∀ {a b : Bag} →
negateBag a ++ negateBag b ≡ negateBag (a ++ b)
-a·-b=-ab {a} {b} = distribute-neg {a = a} {b} {{abelian-bag}}
-m·-n=-mn : ∀ {m n : ℤ} →
(- m) + (- n) ≡ - (m + n)
-m·-n=-mn {m} {n} = distribute-neg {a = m} {n} {{abelian-int}}
[a++b]\\a=b : ∀ {a b} → (a ++ b) \\ a ≡ b
[a++b]\\a=b {b} {d} =
begin
(b ++ d) \\ b
≡⟨ cong (λ hole → hole \\ b) (commutative-bag b d) ⟩
(d ++ b) \\ b
≡⟨ associative-bag d b (negateBag b) ⟩
d ++ (b \\ b)
≡⟨ cong (_++_ d) (right-inv-bag b) ⟩
d ++ emptyBag
≡⟨ right-id-bag d ⟩
d
∎ where open ≡-Reasoning
|
{
"alphanum_fraction": 0.4872788951,
"avg_line_length": 29.2695035461,
"ext": "agda",
"hexsha": "73dbd184ade1dcefb6e2e2466c4da4524bb9e70b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Theorem/Groups-Nehemiah.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Theorem/Groups-Nehemiah.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Theorem/Groups-Nehemiah.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 1793,
"size": 4127
}
|
------------------------------------------------------------------------------
-- Properties related with the forest type
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.Mirror.Forest.PropertiesI where
open import Common.FOL.Relation.Binary.EqReasoning
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Base.List.PropertiesI
open import FOTC.Data.List
open import FOTC.Data.List.PropertiesI
using ( ++-leftCong
; ++-leftIdentity
; ++-rightCong
; mapCong₂
; revCong₁
; reverseCong
; reverse-[x]≡[x]
)
open import FOTC.Program.Mirror.Forest.TotalityI
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
++-rightIdentity : ∀ {xs} → Forest xs → xs ++ [] ≡ xs
++-rightIdentity fnil = ++-leftIdentity []
++-rightIdentity (fcons {x} {xs} Tx Fxs) =
(x ∷ xs) ++ []
≡⟨ ++-∷ x xs [] ⟩
x ∷ (xs ++ [])
≡⟨ ∷-rightCong (++-rightIdentity Fxs) ⟩
x ∷ xs ∎
++-assoc : ∀ {xs} → Forest xs → ∀ ys zs → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs)
++-assoc fnil ys zs =
([] ++ ys) ++ zs
≡⟨ ++-leftCong (++-leftIdentity ys) ⟩
ys ++ zs
≡⟨ sym (++-leftIdentity (ys ++ zs)) ⟩
[] ++ ys ++ zs ∎
++-assoc (fcons {x} {xs} Tx Fxs) ys zs =
((x ∷ xs) ++ ys) ++ zs
≡⟨ ++-leftCong (++-∷ x xs ys) ⟩
(x ∷ (xs ++ ys)) ++ zs
≡⟨ ++-∷ x (xs ++ ys) zs ⟩
x ∷ ((xs ++ ys) ++ zs)
≡⟨ ∷-rightCong (++-assoc Fxs ys zs) ⟩
x ∷ (xs ++ ys ++ zs)
≡⟨ sym (++-∷ x xs (ys ++ zs)) ⟩
(x ∷ xs) ++ ys ++ zs ∎
map-++ : ∀ f {xs} → (∀ {x} → Tree x → Tree (f · x)) →
Forest xs →
∀ ys → map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++ f h fnil ys =
map f ([] ++ ys)
≡⟨ mapCong₂ (++-leftIdentity ys) ⟩
map f ys
≡⟨ sym (++-leftIdentity (map f ys)) ⟩
[] ++ map f ys
≡⟨ ++-leftCong (sym (map-[] f)) ⟩
map f [] ++ map f ys ∎
map-++ f h (fcons {x} {xs} Tx Fxs) ys =
map f ((x ∷ xs) ++ ys)
≡⟨ mapCong₂ (++-∷ x xs ys) ⟩
map f (x ∷ xs ++ ys)
≡⟨ map-∷ f x (xs ++ ys) ⟩
f · x ∷ map f (xs ++ ys)
≡⟨ ∷-rightCong (map-++ f h Fxs ys) ⟩
f · x ∷ (map f xs ++ map f ys)
≡⟨ sym (++-∷ (f · x) (map f xs) (map f ys)) ⟩
(f · x ∷ map f xs) ++ map f ys
≡⟨ ++-leftCong (sym (map-∷ f x xs)) ⟩
map f (x ∷ xs) ++ map f ys ∎
rev-++ : ∀ {xs} → Forest xs → ∀ ys → rev xs ys ≡ rev xs [] ++ ys
rev-++ fnil ys =
rev [] ys ≡⟨ rev-[] ys ⟩
ys ≡⟨ sym (++-leftIdentity ys) ⟩
[] ++ ys ≡⟨ ++-leftCong (sym (rev-[] [])) ⟩
rev [] [] ++ ys ∎
rev-++ (fcons {x} {xs} Tx Fxs) ys =
rev (x ∷ xs) ys
≡⟨ rev-∷ x xs ys ⟩
rev xs (x ∷ ys)
≡⟨ rev-++ Fxs (x ∷ ys) ⟩
rev xs [] ++ x ∷ ys
≡⟨ ++-rightCong prf ⟩
rev xs [] ++ (x ∷ []) ++ ys
≡⟨ sym (++-assoc (rev-Forest Fxs fnil) (x ∷ []) ys) ⟩
(rev xs [] ++ (x ∷ [])) ++ ys
≡⟨ ++-leftCong (sym (rev-++ Fxs (x ∷ []))) ⟩
rev xs (x ∷ []) ++ ys
≡⟨ ++-leftCong (sym (rev-∷ x xs [])) ⟩
rev (x ∷ xs) [] ++ ys ∎
where prf : x ∷ ys ≡ (x ∷ []) ++ ys
prf = x ∷ ys ≡⟨ ∷-rightCong (sym (++-leftIdentity ys)) ⟩
x ∷ ([] ++ ys) ≡⟨ sym (++-∷ x [] ys) ⟩
(x ∷ []) ++ ys ∎
reverse-++ : ∀ {xs ys} → Forest xs → Forest ys →
reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++ {ys = ys} fnil Fys =
reverse ([] ++ ys)
≡⟨ reverseCong (++-leftIdentity ys) ⟩
reverse ys
≡⟨ sym (++-rightIdentity (reverse-Forest Fys)) ⟩
reverse ys ++ []
≡⟨ ++-rightCong (sym (rev-[] [])) ⟩
reverse ys ++ reverse [] ∎
reverse-++ (fcons {x} {xs} Tx Fxs) fnil =
reverse ((x ∷ xs) ++ [])
≡⟨ reverseCong (++-rightIdentity (fcons Tx Fxs)) ⟩
reverse (x ∷ xs)
≡⟨ sym (++-leftIdentity (reverse (x ∷ xs))) ⟩
[] ++ reverse (x ∷ xs)
≡⟨ ++-leftCong (sym (rev-[] [])) ⟩
reverse [] ++ reverse (x ∷ xs) ∎
reverse-++ (fcons {x} {xs} Tx Fxs) (fcons {y} {ys} Ty Fys) =
rev ((x ∷ xs) ++ y ∷ ys) []
≡⟨ revCong₁ (++-∷ x xs (y ∷ ys)) ⟩
rev (x ∷ (xs ++ y ∷ ys)) []
≡⟨ rev-∷ x (xs ++ y ∷ ys) [] ⟩
rev (xs ++ y ∷ ys) (x ∷ [])
≡⟨ rev-++ (++-Forest Fxs (fcons Ty Fys)) (x ∷ []) ⟩
rev (xs ++ y ∷ ys) [] ++ (x ∷ [])
≡⟨ ++-leftCong refl ⟩
reverse (xs ++ y ∷ ys) ++ (x ∷ [])
≡⟨ ++-leftCong (reverse-++ Fxs (fcons Ty Fys)) ⟩
(reverse (y ∷ ys) ++ reverse xs) ++ x ∷ []
≡⟨ ++-assoc (reverse-Forest (fcons Ty Fys))
(reverse xs)
(x ∷ [])
⟩
reverse (y ∷ ys) ++ rev xs [] ++ x ∷ []
≡⟨ ++-rightCong (sym (rev-++ Fxs (x ∷ []))) ⟩
reverse (y ∷ ys) ++ rev xs (x ∷ [])
≡⟨ ++-rightCong (sym (rev-∷ x xs [])) ⟩
reverse (y ∷ ys) ++ reverse (x ∷ xs) ∎
reverse-∷ : ∀ {x ys} → Tree x → Forest ys →
reverse (x ∷ ys) ≡ reverse ys ++ (x ∷ [])
reverse-∷ {x} Tx fnil =
rev (x ∷ []) []
≡⟨ rev-∷ x [] [] ⟩
rev [] (x ∷ [])
≡⟨ rev-[] (x ∷ []) ⟩
x ∷ []
≡⟨ sym (++-leftIdentity (x ∷ [])) ⟩
[] ++ x ∷ []
≡⟨ ++-leftCong (sym (rev-[] [])) ⟩
rev [] [] ++ x ∷ [] ∎
reverse-∷ {x} Tx (fcons {y} {ys} Ty Fys) = sym (
reverse (y ∷ ys) ++ x ∷ []
≡⟨ ++-rightCong (sym (reverse-[x]≡[x] x)) ⟩
(reverse (y ∷ ys) ++ reverse (x ∷ []))
≡⟨ sym (reverse-++ (fcons Tx fnil) (fcons Ty Fys)) ⟩
reverse ((x ∷ []) ++ (y ∷ ys))
≡⟨ reverseCong (++-∷ x [] (y ∷ ys)) ⟩
reverse (x ∷ ([] ++ (y ∷ ys)))
≡⟨ reverseCong (∷-rightCong (++-leftIdentity (y ∷ ys))) ⟩
reverse (x ∷ y ∷ ys) ∎
)
|
{
"alphanum_fraction": 0.4203516249,
"avg_line_length": 31.813559322,
"ext": "agda",
"hexsha": "a9cb805becc2ee24b339486e870c7ec5cf016412",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/Mirror/Forest/PropertiesI.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": 2306,
"size": 5631
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.AbGroup.TensorProduct where
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Function hiding (flip)
open import Cubical.Foundations.Isomorphism
open import Cubical.Relation.Binary
open import Cubical.Data.Sigma
open import Cubical.Data.List
open import Cubical.Data.Nat as ℕ
open import Cubical.Foundations.HLevels
open import Cubical.Data.Int
open import Cubical.Data.Sum hiding (map)
open import Cubical.HITs.PropositionalTruncation
renaming (map to pMap ; rec to pRec ; elim to pElim ; elim2 to pElim2)
open import Cubical.Algebra.Group
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Semigroup
private
variable
ℓ ℓ' : Level
module _ (AGr : AbGroup ℓ) (BGr : AbGroup ℓ') where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
data _⨂₁_ : Type (ℓ-max ℓ ℓ') where
_⊗_ : (a : A) → (b : B) → _⨂₁_
_+⊗_ : (w : _⨂₁_) → (u : _⨂₁_) → _⨂₁_
⊗comm : (x y : _) → x +⊗ y ≡ y +⊗ x
⊗assoc : (x y z : _) → x +⊗ (y +⊗ z) ≡ (x +⊗ y) +⊗ z
⊗lUnit : (x : _) → (0A ⊗ 0B) +⊗ x ≡ x
linl : (x y : A) (z : B) → (x +A y) ⊗ z ≡ ((x ⊗ z) +⊗ (y ⊗ z))
linr : (x : A) (y z : B) → x ⊗ (y +B z) ≡ ((x ⊗ y) +⊗ (x ⊗ z))
⊗squash : isSet _⨂₁_
module _ {AGr : AbGroup ℓ} {BGr : AbGroup ℓ'} where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
A⊗B = AGr ⨂₁ BGr
⊗elimProp : ∀ {ℓ} {C : AGr ⨂₁ BGr → Type ℓ}
→ ((x : _) → isProp (C x))
→ (f : (x : A) (b : B) → C (x ⊗ b))
→ (g : ((x y : _) → C x → C y → C (x +⊗ y)))
→ (x : _) → C x
⊗elimProp p f g (a ⊗ b) = f a b
⊗elimProp p f g (x +⊗ y) = g x y (⊗elimProp p f g x) (⊗elimProp p f g y)
⊗elimProp {C = C} p f g (⊗comm x y j) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g x y (⊗elimProp p f g x) (⊗elimProp p f g y))
(g y x (⊗elimProp p f g y) (⊗elimProp p f g x)) (⊗comm x y) j
⊗elimProp {C = C} p f g (⊗assoc x y z j) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g x (y +⊗ z) (⊗elimProp p f g x)
(g y z (⊗elimProp p f g y) (⊗elimProp p f g z)))
(g (x +⊗ y) z (g x y (⊗elimProp p f g x)
(⊗elimProp p f g y)) (⊗elimProp p f g z)) (⊗assoc x y z) j
⊗elimProp {C = C} p f g (⊗lUnit x i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(g (0A ⊗ 0B) x (f 0A 0B) (⊗elimProp p f g x))
(⊗elimProp p f g x)
(⊗lUnit x) i
⊗elimProp {C = C} p f g (linl x y z i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(f (x +A y) z) (g (x ⊗ z) (y ⊗ z) (f x z) (f y z)) (linl x y z) i
⊗elimProp {C = C} p f g (linr x y z i) =
isOfHLevel→isOfHLevelDep 1 {B = C} p
(f x (y +B z)) (g (x ⊗ y) (x ⊗ z) (f x y) (f x z)) (linr x y z) i
⊗elimProp {C = C} p f g (⊗squash x y q r i j) =
isOfHLevel→isOfHLevelDep 2 {B = C} (λ x → isProp→isSet (p x))
_ _ (λ j → ⊗elimProp p f g (q j)) (λ j → ⊗elimProp p f g (r j))
(⊗squash x y q r) i j
-- Group structure
0⊗ : AGr ⨂₁ BGr
0⊗ = 0A ⊗ 0B
-⊗ : AGr ⨂₁ BGr → AGr ⨂₁ BGr
-⊗ (a ⊗ b) = (-A a) ⊗ b
-⊗ (x +⊗ x₁) = -⊗ x +⊗ -⊗ x₁
-⊗ (⊗comm x y i) = ⊗comm (-⊗ x) (-⊗ y) i
-⊗ (⊗assoc x y z i) = ⊗assoc (-⊗ x) (-⊗ y) (-⊗ z) i
-⊗ (⊗lUnit x i) =
((λ i → (GroupTheory.inv1g (AbGroup→Group AGr) i ⊗ 0B) +⊗ -⊗ x)
∙ ⊗lUnit (-⊗ x)) i
-⊗ (linl x y z i) =
((λ i → (GroupTheory.invDistr (AbGroup→Group AGr) x y
∙ comm strA (-A y) (-A x)) i ⊗ z)
∙ linl (-A x) (-A y) z) i
-⊗ (linr x y z i) = linr (-A x) y z i
-⊗ (⊗squash x y p q i j) =
⊗squash _ _ (λ j → -⊗ (p j)) (λ j → -⊗ (q j)) i j
⊗rUnit : (x : A⊗B) → x +⊗ 0⊗ ≡ x
⊗rUnit x = ⊗comm x 0⊗ ∙ ⊗lUnit x
-------------------------------------------------------------------------------
-- Useful induction principle, which lets us view elements of A ⨂ B as lists
-- over (A × B). Used for the right cancellation law
unlist : List (A × B) → AGr ⨂₁ BGr
unlist [] = 0A ⊗ 0B
unlist (x ∷ x₁) = (fst x ⊗ snd x) +⊗ unlist x₁
unlist++ : (x y : List (A × B))
→ unlist (x ++ y) ≡ (unlist x +⊗ unlist y)
unlist++ [] y = sym (⊗lUnit (unlist y))
unlist++ (x ∷ x₁) y =
(λ i → (fst x ⊗ snd x) +⊗ (unlist++ x₁ y i))
∙ ⊗assoc (fst x ⊗ snd x) (unlist x₁) (unlist y)
∃List : (x : AGr ⨂₁ BGr) → ∃[ l ∈ List (A × B) ] (unlist l ≡ x)
∃List =
⊗elimProp (λ _ → squash₁)
(λ a b → ∣ [ a , b ] , ⊗rUnit (a ⊗ b) ∣₁)
λ x y → rec2 squash₁ λ {(l1 , p) (l2 , q)
→ ∣ (l1 ++ l2) , unlist++ l1 l2 ∙ cong₂ _+⊗_ p q ∣₁}
⊗elimPropUnlist : ∀ {ℓ} {C : AGr ⨂₁ BGr → Type ℓ}
→ ((x : _) → isProp (C x))
→ ((x : _) → C (unlist x))
→ (x : _) → C x
⊗elimPropUnlist {C = C} p f =
⊗elimProp p (λ x y → subst C (⊗rUnit (x ⊗ y)) (f [ x , y ]))
λ x y → pRec (isPropΠ2 λ _ _ → p _)
(pRec (isPropΠ3 λ _ _ _ → p _)
(λ {(l1 , p) (l2 , q) ind1 ind2
→ subst C (unlist++ l2 l1 ∙ cong₂ _+⊗_ q p) (f (l2 ++ l1))})
(∃List y))
(∃List x)
-----------------------------------------------------------------------------------
lCancelPrim : (x : B) → (0A ⊗ x) ≡ 0⊗
lCancelPrim x =
sym (⊗rUnit _)
∙∙ cong ((0A ⊗ x) +⊗_) (sym cancelLem)
∙∙ ⊗assoc (0A ⊗ x) (0A ⊗ x) (0A ⊗ (-B x))
∙∙ cong (_+⊗ (0A ⊗ (-B x))) inner
∙∙ cancelLem
where
cancelLem : (0A ⊗ x) +⊗ (0A ⊗ (-B x)) ≡ 0⊗
cancelLem = sym (linr 0A x (-B x)) ∙ (λ i → 0A ⊗ invr strB x i)
inner : (0A ⊗ x) +⊗ (0A ⊗ x) ≡ 0A ⊗ x
inner = sym (linl 0A 0A x) ∙ (λ i → rid strA 0A i ⊗ x)
rCancelPrim : (x : A) → (x ⊗ 0B) ≡ 0⊗
rCancelPrim x =
sym (⊗rUnit _)
∙∙ cong ((x ⊗ 0B) +⊗_) (sym cancelLem)
∙∙ ⊗assoc (x ⊗ 0B) (x ⊗ 0B) ((-A x) ⊗ 0B)
∙∙ cong (_+⊗ ((-A x) ⊗ 0B)) inner
∙∙ cancelLem
where
cancelLem : (x ⊗ 0B) +⊗ ((-A x) ⊗ 0B) ≡ 0⊗
cancelLem = sym (linl x (-A x) 0B) ∙ (λ i → invr strA x i ⊗ 0B)
inner : (x ⊗ 0B) +⊗ (x ⊗ 0B) ≡ x ⊗ 0B
inner = sym (linr x 0B 0B) ∙ (λ i → x ⊗ rid strB 0B i)
flip : (x : A) (b : B) → x ⊗ (-B b) ≡ ((-A x) ⊗ b)
flip x b =
sym (⊗rUnit _)
∙ cong ((x ⊗ (-B b)) +⊗_) (sym cancelLemA)
∙ ⊗assoc (x ⊗ (-B b)) (x ⊗ b) ((-A x) ⊗ b)
∙ cong (_+⊗ ((-A x) ⊗ b)) cancelLemB
∙ ⊗lUnit _
where
cancelLemA : (x ⊗ b) +⊗ ((-A x) ⊗ b) ≡ 0⊗
cancelLemA = sym (linl x (-A x) b) ∙ (λ i → invr strA x i ⊗ b) ∙ lCancelPrim b
cancelLemB : (x ⊗ (-B b)) +⊗ (x ⊗ b) ≡ 0⊗
cancelLemB = sym (linr x (-B b) b) ∙ (λ i → x ⊗ invl strB b i) ∙ rCancelPrim x
⊗rCancel : (x : AGr ⨂₁ BGr) → (x +⊗ -⊗ x) ≡ 0⊗
⊗rCancel =
⊗elimPropUnlist (λ _ → ⊗squash _ _) h
where
h : (x : List (A × B)) → (unlist x +⊗ -⊗ (unlist x)) ≡ 0⊗
h [] = sym (linl 0A (-A 0A) (0B))
∙ cong (λ x → _⊗_ {AGr = AGr} {BGr = BGr} x 0B) (invr strA 0A)
h (x ∷ x₁) =
move4 (fst x ⊗ snd x) (unlist x₁) ((-A fst x) ⊗ snd x) (-⊗ (unlist x₁))
_+⊗_ ⊗assoc ⊗comm
∙∙ cong₂ _+⊗_ (sym (linl (fst x) (-A (fst x)) (snd x))
∙∙ (λ i → invr strA (fst x) i ⊗ (snd x))
∙∙ lCancelPrim (snd x))
(h x₁)
∙∙ ⊗rUnit 0⊗
⊗lCancel : (x : AGr ⨂₁ BGr) → (-⊗ x +⊗ x) ≡ 0⊗
⊗lCancel x = ⊗comm _ _ ∙ ⊗rCancel x
module _ where
open AbGroupStr
open IsAbGroup
open IsGroup
open IsMonoid
open IsSemigroup
_⨂_ : AbGroup ℓ → AbGroup ℓ' → AbGroup (ℓ-max ℓ ℓ')
fst (A ⨂ B) = A ⨂₁ B
0g (snd (A ⨂ B)) = 0⊗
AbGroupStr._+_ (snd (A ⨂ B)) = _+⊗_
AbGroupStr.- snd (A ⨂ B) = -⊗
is-set (isSemigroup (isMonoid (isGroup (isAbGroup (snd (A ⨂ B)))))) = ⊗squash
assoc (isSemigroup (isMonoid (isGroup (isAbGroup (snd (A ⨂ B)))))) = ⊗assoc
fst (identity (isMonoid (isGroup (isAbGroup (snd (A ⨂ B))))) x) = ⊗rUnit x
snd (identity (isMonoid (isGroup (isAbGroup (snd (A ⨂ B))))) x) = ⊗lUnit x
fst (inverse (isGroup (isAbGroup (snd (A ⨂ B)))) x) = ⊗rCancel x
snd (inverse (isGroup (isAbGroup (snd (A ⨂ B)))) x) = ⊗lCancel x
comm (isAbGroup (snd (A ⨂ B))) = ⊗comm
-------------- Elimination principle into AbGroups --------------
module _ {ℓ ℓ' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G)
_+A_ = _+G_ (snd A)
_+B_ = _+G_ (snd B)
0A = 0g (snd A)
0B = 0g (snd B)
⨂→AbGroup-elim : ∀ {ℓ} (C : AbGroup ℓ)
→ (f : (fst A × fst B) → fst C)
→ (f (0A , 0B) ≡ 0g (snd C))
→ (linL : (x y : fst A) (b : fst B)
→ f (x +A y , b) ≡ _+G_ (snd C) (f (x , b)) (f (y , b)))
→ (linR : (a : fst A) (x y : fst B)
→ f (a , x +B y) ≡ _+G_ (snd C) (f (a , x)) (f (a , y)))
→ A ⨂₁ B → fst C
⨂→AbGroup-elim C f p linL linR (a ⊗ b) = f (a , b)
⨂→AbGroup-elim C f p linL linR (x +⊗ x₁) =
_+G_ (snd C) (⨂→AbGroup-elim C f p linL linR x)
(⨂→AbGroup-elim C f p linL linR x₁)
⨂→AbGroup-elim C f p linL linR (⊗comm x x₁ i) =
comm (snd C) (⨂→AbGroup-elim C f p linL linR x)
(⨂→AbGroup-elim C f p linL linR x₁) i
⨂→AbGroup-elim C f p linL linR (⊗assoc x x₁ x₂ i) =
assoc (snd C) (⨂→AbGroup-elim C f p linL linR x)
(⨂→AbGroup-elim C f p linL linR x₁)
(⨂→AbGroup-elim C f p linL linR x₂) i
⨂→AbGroup-elim C f p linL linR (⊗lUnit x i) =
(cong (λ y → (snd C +G y) (⨂→AbGroup-elim C f p linL linR x)) p
∙ (lid (snd C) (⨂→AbGroup-elim C f p linL linR x))) i
⨂→AbGroup-elim C f p linL linR (linl x y z i) = linL x y z i
⨂→AbGroup-elim C f p linL linR (linr x y z i) = linR x y z i
⨂→AbGroup-elim C f p linL linR (⊗squash x x₁ x₂ y i i₁) =
is-set (snd C) _ _
(λ i → ⨂→AbGroup-elim C f p linL linR (x₂ i))
(λ i → ⨂→AbGroup-elim C f p linL linR (y i)) i i₁
⨂→AbGroup-elim-hom : ∀ {ℓ} (C : AbGroup ℓ)
→ (f : (fst A × fst B) → fst C) (linL : _) (linR : _) (p : _)
→ AbGroupHom (A ⨂ B) C
fst (⨂→AbGroup-elim-hom C f linL linR p) = ⨂→AbGroup-elim C f p linL linR
snd (⨂→AbGroup-elim-hom C f linL linR p) =
makeIsGroupHom
(λ x y → refl)
private
_* = AbGroup→Group
----------- Definition of universal property ------------
tensorFun : (A : Group ℓ) (B : Group ℓ') (T C : AbGroup (ℓ-max ℓ ℓ'))
(f : GroupHom A (HomGroup B T *))
→ GroupHom (T *) (C *)
→ GroupHom A (HomGroup B C *)
fst (fst (tensorFun A B T C (f , p) (g , q)) a) b = g (fst (f a) b)
snd (fst (tensorFun A B T C (f , p) (g , q)) a) =
makeIsGroupHom λ x y
→ cong g (IsGroupHom.pres· (snd (f a)) x y)
∙ IsGroupHom.pres· q _ _
snd (tensorFun A B T C (f , p) (g , q)) =
makeIsGroupHom λ x y
→ Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt λ b
→ cong g (funExt⁻ (cong fst (IsGroupHom.pres· p x y)) b)
∙ IsGroupHom.pres· q _ _)
isTensorProductOf_and_ : AbGroup ℓ → AbGroup ℓ' → AbGroup (ℓ-max ℓ ℓ')→ Type _
isTensorProductOf_and_ {ℓ} {ℓ'} A B T =
Σ[ f ∈ GroupHom (A *) ((HomGroup (B *) T) *) ]
((C : AbGroup (ℓ-max ℓ ℓ'))
→ isEquiv {A = GroupHom (T *) (C *)}
{B = GroupHom (A *) ((HomGroup (B *) C) *)}
(tensorFun (A *) (B *) T C f))
------ _⨂_ satisfies the universal property --------
module UP (AGr : AbGroup ℓ) (BGr : AbGroup ℓ') where
private
open AbGroupStr renaming (_+_ to _+G_ ; -_ to -G_)
strA = snd AGr
strB = snd BGr
A = fst AGr
B = fst BGr
0A = 0g strA
0B = 0g strB
_+A_ = _+G_ strA
_+B_ = _+G_ strB
-A_ = -G_ strA
-B_ = -G_ strB
mainF : GroupHom (AGr *) (HomGroup (BGr *) (AGr ⨂ BGr) *)
fst (fst mainF a) b = a ⊗ b
snd (fst mainF a) =
makeIsGroupHom (linr a)
snd mainF =
makeIsGroupHom λ x y → Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt (linl x y))
isTensorProduct⨂ : (isTensorProductOf AGr and BGr) (AGr ⨂ BGr)
fst isTensorProduct⨂ = mainF
snd isTensorProduct⨂ C = isoToIsEquiv mainIso
where
invF : GroupHom (AGr *) (HomGroup (BGr *) C *) → GroupHom ((AGr ⨂ BGr) *) (C *)
fst (invF (f , p)) = F
where
lem : f (0g (snd AGr)) .fst (0g (snd BGr)) ≡ 0g (snd C)
lem = funExt⁻ (cong fst (IsGroupHom.pres1 p)) (0g (snd BGr))
F : ((AGr ⨂ BGr) *) .fst → (C *) .fst
F (a ⊗ b) = f a .fst b
F (x +⊗ x₁) = _+G_ (snd C) (F x) (F x₁)
F (⊗comm x x₁ i) = comm (snd C) (F x) (F x₁) i
F (⊗assoc x y z i) = assoc (snd C) (F x) (F y) (F z) i
F (⊗lUnit x i) = (cong (λ y → _+G_ (snd C) y (F x)) lem ∙ lid (snd C) (F x)) i
F (linl x y z i) = fst (IsGroupHom.pres· p x y i) z
F (linr x y z i) = IsGroupHom.pres· (f x .snd) y z i
F (⊗squash x x₁ x₂ y i i₁) =
is-set (snd C) (F x) (F x₁)
(λ i → F (x₂ i)) (λ i → F (y i)) i i₁
snd (invF (f , p)) =
makeIsGroupHom λ x y → refl
mainIso : Iso (GroupHom ((AGr ⨂ BGr) *) (C *))
(GroupHom (AGr *) (HomGroup (BGr *) C *))
Iso.fun mainIso = _
Iso.inv mainIso = invF
Iso.rightInv mainIso (f , p) =
Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt λ a → Σ≡Prop (λ _ → isPropIsGroupHom _ _) refl)
Iso.leftInv mainIso (f , p) =
Σ≡Prop (λ _ → isPropIsGroupHom _ _)
(funExt (⊗elimProp (λ _ → is-set (snd C) _ _)
(λ _ _ → refl)
λ x y ind1 ind2 → cong₂ (_+G_ (snd C)) ind1 ind2 ∙ sym (IsGroupHom.pres· p x y)))
-------------------- Commutativity ------------------------
commFun : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} → A ⨂₁ B → B ⨂₁ A
commFun (a ⊗ b) = b ⊗ a
commFun (x +⊗ x₁) = commFun x +⊗ commFun x₁
commFun (⊗comm x x₁ i) = ⊗comm (commFun x) (commFun x₁) i
commFun (⊗assoc x x₁ x₂ i) = ⊗assoc (commFun x) (commFun x₁) (commFun x₂) i
commFun (⊗lUnit x i) = ⊗lUnit (commFun x) i
commFun (linl x y z i) = linr z x y i
commFun (linr x y z i) = linl y z x i
commFun (⊗squash x x₁ x₂ y i i₁) =
⊗squash (commFun x) (commFun x₁)
(λ i → commFun (x₂ i)) (λ i → commFun (y i)) i i₁
commFun²≡id : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} (x : A ⨂₁ B)
→ commFun (commFun x) ≡ x
commFun²≡id =
⊗elimProp (λ _ → ⊗squash _ _)
(λ _ _ → refl)
λ _ _ p q → cong₂ _+⊗_ p q
⨂-commIso : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'}
→ GroupIso ((A ⨂ B) *) ((B ⨂ A) *)
Iso.fun (fst ⨂-commIso) = commFun
Iso.inv (fst ⨂-commIso) = commFun
Iso.rightInv (fst ⨂-commIso) = commFun²≡id
Iso.leftInv (fst ⨂-commIso) = commFun²≡id
snd ⨂-commIso = makeIsGroupHom λ x y → refl
⨂-comm : ∀ {ℓ ℓ'} {A : AbGroup ℓ} {B : AbGroup ℓ'} → AbGroupEquiv (A ⨂ B) (B ⨂ A)
fst ⨂-comm = isoToEquiv (fst (⨂-commIso))
snd ⨂-comm = snd ⨂-commIso
open AbGroupStr
-------------------- Associativity ------------------------
module _ {ℓ ℓ' ℓ'' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} {C : AbGroup ℓ''} where
private
f : (c : fst C) → AbGroupHom (A ⨂ B) (A ⨂ (B ⨂ C))
f c = ⨂→AbGroup-elim-hom (A ⨂ (B ⨂ C)) ((λ ab → fst ab ⊗ (snd ab ⊗ c)))
(λ x y b → linl x y (b ⊗ c))
(λ x y b → (λ i → x ⊗ (linl y b c i)) ∙ linr x (y ⊗ c) (b ⊗ c))
(λ i → 0g (snd A) ⊗ (lCancelPrim c i))
assocHom : AbGroupHom ((A ⨂ B) ⨂ C) (A ⨂ (B ⨂ C))
assocHom =
⨂→AbGroup-elim-hom _ (λ x → f (snd x) .fst (fst x))
(λ x y b → IsGroupHom.pres· (snd (f b)) x y)
(⊗elimProp (λ _ → isPropΠ2 λ _ _ → ⊗squash _ _)
(λ a b x y → (λ i → a ⊗ (linr b x y i))
∙∙ linr a (b ⊗ x) (b ⊗ y)
∙∙ refl)
λ a b ind1 ind2 x y → cong₂ _+⊗_ (ind1 x y) (ind2 x y)
∙∙ move4 (f x .fst a) (f y .fst a) (f x .fst b) (f y .fst b)
_+⊗_ ⊗assoc ⊗comm
∙∙ cong₂ _+⊗_ (sym (IsGroupHom.pres· (snd (f x)) a b))
(IsGroupHom.pres· (snd (f y)) a b))
refl
module _ {ℓ ℓ' ℓ'' : Level} {A : AbGroup ℓ} {B : AbGroup ℓ'} {C : AbGroup ℓ''} where
private
f' : (a : fst A) → AbGroupHom (B ⨂ C) ((A ⨂ B) ⨂ C)
f' a =
⨂→AbGroup-elim-hom ((A ⨂ B) ⨂ C)
(λ bc → (a ⊗ fst bc) ⊗ snd bc)
(λ x y b → (λ i → (linr a x y i) ⊗ b) ∙ linl (a ⊗ x) (a ⊗ y) b)
(λ x y b → linr (a ⊗ x) y b)
λ i → rCancelPrim a i ⊗ (0g (snd C))
assocHom⁻ : AbGroupHom (A ⨂ (B ⨂ C)) ((A ⨂ B) ⨂ C)
assocHom⁻ =
⨂→AbGroup-elim-hom _ (λ abc → f' (fst abc) .fst (snd abc))
(λ x y → ⊗elimProp (λ _ → ⊗squash _ _)
(λ b c → (λ i → linl x y b i ⊗ c) ∙ linl (x ⊗ b) (y ⊗ b) c)
λ a b ind1 ind2 → cong₂ _+⊗_ ind1 ind2
∙∙ move4 _ _ _ _ _+⊗_ ⊗assoc ⊗comm
∙∙ cong₂ _+⊗_ (IsGroupHom.pres· (snd (f' x)) a b)
(IsGroupHom.pres· (snd (f' y)) a b))
(λ a → IsGroupHom.pres· (snd (f' a)))
refl
⨂assocIso : Iso (A ⨂₁ (B ⨂ C)) ((A ⨂ B) ⨂₁ C)
Iso.fun ⨂assocIso = fst assocHom⁻
Iso.inv ⨂assocIso = fst assocHom
Iso.rightInv ⨂assocIso =
⊗elimProp (λ _ → ⊗squash _ _)
(⊗elimProp (λ _ → isPropΠ (λ _ → ⊗squash _ _))
(λ a b c → refl)
λ a b ind1 ind2 c → cong₂ _+⊗_ (ind1 c) (ind2 c) ∙ sym (linl a b c))
λ x y p q → cong (fst assocHom⁻) (IsGroupHom.pres· (snd assocHom) x y)
∙∙ IsGroupHom.pres· (snd assocHom⁻) (fst assocHom x) (fst assocHom y)
∙∙ cong₂ _+⊗_ p q
Iso.leftInv ⨂assocIso =
⊗elimProp (λ _ → ⊗squash _ _)
(λ a → ⊗elimProp (λ _ → ⊗squash _ _)
(λ b c → refl)
λ x y ind1 ind2 →
cong (fst assocHom ∘ fst assocHom⁻) (linr a x y)
∙∙ cong (fst assocHom) (IsGroupHom.pres· (snd assocHom⁻) (a ⊗ x) (a ⊗ y))
∙∙ IsGroupHom.pres· (snd assocHom) (fst assocHom⁻ (a ⊗ x)) (fst assocHom⁻ (a ⊗ y))
∙∙ cong₂ _+⊗_ ind1 ind2
∙∙ sym (linr a x y))
λ x y p q → cong (fst assocHom) (IsGroupHom.pres· (snd assocHom⁻) x y)
∙∙ IsGroupHom.pres· (snd assocHom) (fst assocHom⁻ x) (fst assocHom⁻ y)
∙∙ cong₂ _+⊗_ p q
⨂assoc : AbGroupEquiv (A ⨂ (B ⨂ C)) ((A ⨂ B) ⨂ C)
fst ⨂assoc = isoToEquiv ⨂assocIso
snd ⨂assoc = snd assocHom⁻
|
{
"alphanum_fraction": 0.4819225861,
"avg_line_length": 37.0236220472,
"ext": "agda",
"hexsha": "94a1f6a2049178c0d99114c15b1ff8a0bf3294e2",
"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": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/cubical",
"max_forks_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"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": "guilhermehas/cubical",
"max_issues_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.agda",
"max_line_length": 98,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ce3120d3f8d692847b2744162bcd7a01f0b687eb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/cubical",
"max_stars_repo_path": "Cubical/Algebra/AbGroup/TensorProduct.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": 8607,
"size": 18808
}
|
open import Preliminaries
module Preorder where
record Preorder-str (A : Set) : Set1 where
constructor preorder
field
≤ : A → A → Set
refl : ∀ x → ≤ x x
trans : ∀ x y z → ≤ x y → ≤ y z → ≤ x z
prop : ∀ x y → (p q : ≤ x y) → p == q
------------------------------------------
-- Task 1: Show that the Natural numbers with ≤ form a preorder
-- the ≤ relation on Natural numbers
≤nat : Nat → Nat → Set
≤nat Z Z = Unit
≤nat Z (S y) = Unit
≤nat (S x) Z = Void
≤nat (S x) (S y) = ≤nat x y
-- proof that Nat is reflexive under ≤
nat-refl : ∀ (x : Nat) → ≤nat x x
nat-refl Z = <>
nat-refl (S x) = nat-refl x
-- proof that Nat is transitive under ≤
nat-trans : ∀ (x y z : Nat) → ≤nat x y → ≤nat y z → ≤nat x z
nat-trans Z Z Z p q = <>
nat-trans Z Z (S z) p q = <>
nat-trans Z (S y) Z p q = abort q
nat-trans Z (S y) (S z) p q = <>
nat-trans (S x) Z Z () q
nat-trans (S x) Z (S z) () q
nat-trans (S x) (S y) Z p ()
nat-trans (S x) (S y) (S z) p q = nat-trans x y z p q
nat-prop : ∀ (x y : Nat) → (p q : ≤nat x y) → p == q
nat-prop Z Z <> <> = Refl
nat-prop Z (S y) <> <> = Refl
nat-prop (S x) Z () q
nat-prop (S x) (S y) p q = nat-prop x y p q
-- proof that Nat and ≤ (the ≤ relation defined on the natural numbers) form a preorder
nat-p : Preorder-str Nat
nat-p = preorder ≤nat nat-refl nat-trans nat-prop
--discrete nat
nat-eq : Nat → Nat → Set
nat-eq Z Z = Unit
nat-eq Z (S n) = Void
nat-eq (S m) Z = Void
nat-eq (S m) (S n) = nat-eq m n
♭nat-refl : (x : Nat) → nat-eq x x
♭nat-refl Z = <>
♭nat-refl (S x) = ♭nat-refl x
♭nat-trans : (x y z : Nat) → nat-eq x y → nat-eq y z → nat-eq x z
♭nat-trans Z Z Z x x₁ = <>
♭nat-trans Z Z (S z) x ()
♭nat-trans Z (S y) z () x₁
♭nat-trans (S x) Z z () x₂
♭nat-trans (S x) (S y) Z x₁ x₂ = x₂
♭nat-trans (S x) (S y) (S z) x₁ x₂ = ♭nat-trans x y z x₁ x₂
♭nat-prop : ∀ (x y : Nat) → (p q : nat-eq x y) → p == q
♭nat-prop Z Z <> <> = Refl
♭nat-prop Z (S y) () q
♭nat-prop (S x) Z () q
♭nat-prop (S x) (S y) p q = ♭nat-prop x y p q
♭nat-p : Preorder-str Nat
♭nat-p = preorder nat-eq ♭nat-refl ♭nat-trans ♭nat-prop
--bools
≤b : Bool → Bool → Set
≤b True True = Unit
≤b True False = Void
≤b False True = Void
≤b False False = Unit
b-refl : (x : Bool) → ≤b x x
b-refl True = <>
b-refl False = <>
b-trans : (x y z : Bool) → ≤b x y → ≤b y z → ≤b x z
b-trans True True True x x₁ = <>
b-trans True True False x ()
b-trans True False z () x₁
b-trans False True z () x₁
b-trans False False True x ()
b-trans False False False x x₁ = <>
b-prop : ∀ (x y : Bool) → (p q : ≤b x y) → p == q
b-prop True True <> <> = Refl
b-prop True False () q
b-prop False True () q
b-prop False False <> <> = Refl
bool-p : Preorder-str Bool
bool-p = preorder ≤b b-refl b-trans b-prop
--list
≤list : ∀ {A : Set} → Preorder-str A → List A → List A → Set
≤list PA [] [] = Unit
≤list PA [] (x :: l2) = Void
≤list PA (x :: l1) [] = Void
≤list PA (x :: l1) (x₁ :: l2) = Preorder-str.≤ PA x x₁ × ≤list PA l1 l2
l-refl : ∀ {A : Set} → (PA : Preorder-str A) → (l : List A) → ≤list PA l l
l-refl PA [] = <>
l-refl PA (x :: l) = (Preorder-str.refl PA x) , (l-refl PA l)
l-trans : ∀ {A : Set} → (PA : Preorder-str A) → (l1 l2 l3 : List A) → ≤list PA l1 l2 → ≤list PA l2 l3 → ≤list PA l1 l3
l-trans PA [] [] [] p q = <>
l-trans PA [] [] (x :: l3) p ()
l-trans PA [] (x :: l2) l3 () q
l-trans PA (x :: l1) [] l3 () q
l-trans PA (x :: l1) (x₁ :: l2) [] p ()
l-trans PA (x :: l1) (x₁ :: l2) (x₂ :: l3) p q = (Preorder-str.trans PA x x₁ x₂ (fst p) (fst q)) , (l-trans PA l1 l2 l3 (snd p) (snd q))
l-prop : ∀ {A : Set} → (PA : Preorder-str A) → (x y : List A) → (p q : ≤list PA x y) → p == q
l-prop PA [] [] <> <> = Refl
l-prop PA [] (x :: y) () q
l-prop PA (x :: x₁) [] () q
l-prop PA (x :: x₁) (x₂ :: y) (p1 , p2) (q1 , q2) = ap2 (λ x₃ x₄ → x₃ , x₄) (Preorder-str.prop PA x x₂ p1 q1) (l-prop PA x₁ y p2 q2)
list-p : ∀ {A : Set} (PA : Preorder-str A) → Preorder-str (List A)
list-p PA = preorder (≤list PA) (l-refl PA) (l-trans PA) (l-prop PA)
------------------------------------------
-- Task 2: Show that the product of two preorders is a preorder
{- defining the relation: when is one cartesian product 'less than' another?
if A and B are preorders and we have cartesian products (a1,b1) and (a2,b2)
such that a1,a2 ∈ A and b1,b2 ∈ B,
then (a1,b1)≤(a2,b2) iff a1≤a2 and b1≤b2
-}
≤axb : ∀ {A B : Set} → Preorder-str A → Preorder-str B → (A × B) → (A × B) → Set
≤axb PA PB (a1 , b1) (a2 , b2) = Preorder-str.≤ PA a1 a2 × Preorder-str.≤ PB b1 b2
{- a cartesian product (a,b) is 'less than' itself
if each component of the product is reflexive, i.e.
just show that a is reflexive and b is reflexive
-}
axb-refl : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x : (A × B)) → ≤axb PA PB x x
axb-refl PA PB (a , b) = Preorder-str.refl PA a , Preorder-str.refl PB b
-- same idea for transitivity...
axb-trans : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x y z : (A × B)) → ≤axb PA PB x y → ≤axb PA PB y z → ≤axb PA PB x z
axb-trans PA PB (a1 , b1) (a2 , b2) (a3 , b3) (a1<a2 , b1<b2) (a2<a3 , b2<b3) =
Preorder-str.trans PA a1 a2 a3 a1<a2 a2<a3 , Preorder-str.trans PB b1 b2 b3 b1<b2 b2<b3
axb-prop : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x y : (A × B)) → (p q : ≤axb PA PB x y) → p == q
axb-prop PA PB (x1 , x2) (y1 , y2) (p1 , p2) (q1 , q2) = ap2 (λ x x₁ → x , x₁) (Preorder-str.prop PA x1 y1 p1 q1) (Preorder-str.prop PB x2 y2 p2 q2)
-- proof that AxB is a preorder
axb-p : ∀ (A B : Set) → Preorder-str A → Preorder-str B → Preorder-str (A × B)
axb-p A B pre-a pre-b = record { ≤ = ≤axb pre-a pre-b; refl = axb-refl pre-a pre-b; trans = axb-trans pre-a pre-b; prop = axb-prop pre-a pre-b}
------------------------------------------
-- Task 4: Show that given a Preorder A and Preorder B, Preorder (Monotone A B)
-- the type of monotone functions from A to B
-- i.e. functions which give you bigger outputs when you give them bigger inputs
record Monotone (A : Set) (B : Set) (PA : Preorder-str A) (PB : Preorder-str B) : Set where
constructor monotone
field
f : A → B
is-monotone : ∀ (x y : A) → Preorder-str.≤ PA x y → Preorder-str.≤ PB (f x) (f y)
-- the order on monotone functions is just the
-- pointwise order on the underlying functions
≤mono : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (Monotone A B PA PB) → (Monotone A B PA PB) → Set
≤mono {A} PA PB f g = (x : A) → Preorder-str.≤ PB (Monotone.f f x) (Monotone.f g x)
mono-refl : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x : (Monotone A B PA PB)) → ≤mono PA PB x x
mono-refl PA PB f = λ x → Preorder-str.refl PB (Monotone.f f x)
mono-trans : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x y z : (Monotone A B PA PB)) → ≤mono PA PB x y → ≤mono PA PB y z → ≤mono PA PB x z
mono-trans PA PB f g h p q = λ x → Preorder-str.trans PB (Monotone.f f x) (Monotone.f g x) (Monotone.f h x) (p x) (q x)
mono-prop : ∀ {A B : Set} → (PA : Preorder-str A) → (PB : Preorder-str B) → (x y : (Monotone A B PA PB)) → (p q : ≤mono PA PB x y) → p == q
mono-prop PA PB x y p q = λ= (λ x₁ → Preorder-str.prop PB (Monotone.f x x₁) (Monotone.f y x₁) (p x₁) (q x₁))
mono-p : ∀ (A B : Set) → (PA : Preorder-str A) → (PB : Preorder-str B) → Preorder-str (Monotone A B PA PB)
mono-p A B PA PB = preorder (≤mono PA PB) (mono-refl PA PB) (mono-trans PA PB) (mono-prop PA PB)
------------------------------------------
-- New stuff: Interpreting types as preorders
-- repackaging preorder as a type together with a Preorder structure on that type
PREORDER = Σ (λ (A : Set) → Preorder-str A)
MONOTONE : (PΓ PA : PREORDER) → Set
MONOTONE (Γ , PΓ) (A , PA) = Monotone Γ A PΓ PA
PN : PREORDER
PN = Nat , nat-p
PL : PREORDER → PREORDER
PL (A , PA) = (List A) , list-p PA
-- some operations
_×p_ : PREORDER → PREORDER → PREORDER
(A , PA) ×p (B , PB) = A × B , axb-p A B PA PB
_->p_ : PREORDER → PREORDER → PREORDER
(A , PA) ->p (B , PB) = Monotone A B PA PB , mono-p A B PA PB
-- Unit is a preorder
unit-p : PREORDER
unit-p = Unit , preorder (λ x x₁ → Unit) (λ x → <>) (λ x y z _ _ → <>) (λ x y p q → Refl)
-- identity preserves monotonicity
id : ∀ {Γ} → MONOTONE Γ Γ
id = λ {Γ} → monotone (λ x → x) (λ x y x₁ → x₁)
-- composition preserves monotonicity
comp : ∀ {PA PB PC} → MONOTONE PA PB → MONOTONE PB PC → MONOTONE PA PC
comp (monotone f f-ismono) (monotone g g-ismono) = monotone (λ x → g (f x)) (λ x y x₁ → g-ismono (f x) (f y) (f-ismono x y x₁))
-- proofs that types like pairs etc. with preorders are monotone
pair' : ∀ {PΓ PA PB} → MONOTONE PΓ PA → MONOTONE PΓ PB → MONOTONE PΓ (PA ×p PB)
pair' (monotone f f-ismono) (monotone g g-ismono) = monotone (λ x → f x , g x) (λ x y z → f-ismono x y z , g-ismono x y z)
fst' : ∀ {PΓ PA PB} → MONOTONE PΓ (PA ×p PB) → MONOTONE PΓ PA
fst' (monotone f f-ismono) = monotone (λ x → fst (f x)) (λ x y z → fst (f-ismono x y z))
snd' : ∀ {PΓ PA PB} → MONOTONE PΓ (PA ×p PB) → MONOTONE PΓ PB
snd' (monotone f f-ismono) = monotone (λ x → snd (f x)) (λ x y z → snd (f-ismono x y z))
lam' : ∀ {PΓ PA PB} → MONOTONE (PΓ ×p PA) PB → MONOTONE PΓ (PA ->p PB)
lam' {Γ , preorder ≤Γ reflΓ transΓ pΓ} {a , preorder ≤a refla transa pa} {b , _} (monotone f f-ismono) =
monotone (λ x → monotone (λ p → f (x , p)) (λ a b c → f-ismono (x , a) (x , b) (reflΓ x , c))) (λ x y z w → f-ismono (x , w) (y , w) (z , refla w))
app' : ∀ {PΓ PA PB} → MONOTONE PΓ (PA ->p PB) → MONOTONE PΓ PA → MONOTONE PΓ PB
app' {Γ , preorder ≤Γ reflΓ transΓ pΓ} {a , preorder ≤a refla transa pa} {b , preorder ≤b reflb transb pb} (monotone f f-ismono) (monotone g g-ismono) =
monotone (λ x → Monotone.f (f x) (g x))
(λ x y z → transb
(Monotone.f (f x) (g x))
(Monotone.f (f y) (g x))
(Monotone.f (f y) (g y))
(f-ismono x y z (g x))
(Monotone.is-monotone (f y) (g x) (g y) (g-ismono x y z)))
unlam' : ∀ {PΓ PA PB} → MONOTONE PΓ (PA ->p PB) → MONOTONE (PΓ ×p PA) PB
unlam' {Γ , preorder ≤Γ reflΓ transΓ pΓ} {a , preorder ≤a refla transa pa} {b , preorder ≤b reflb transb pb} (monotone f f-ismono) =
monotone (λ x → Monotone.f (f (fst x)) (snd x))
(λ x y x₁ → transb
(Monotone.f (f (fst x)) (snd x))
(Monotone.f (f (fst x)) (snd y))
(Monotone.f (f (fst y)) (snd y))
(Monotone.is-monotone (f (fst x)) (snd x) (snd y) (snd x₁))
(f-ismono (fst x) (fst y) (fst x₁) (snd y)))
z' : ∀ {PΓ} → MONOTONE PΓ PN
z' = monotone (λ x → Z) (λ x y x₁ → <>)
suc' : ∀ {PΓ} → MONOTONE PΓ PN → MONOTONE PΓ PN
suc' {Γ , preorder ≤ refl trans pΓ} (monotone f f-is-monotone) = monotone (λ x → S (f x)) (λ x y x₁ → f-is-monotone x y x₁)
nil' : ∀ {PΓ PA} → MONOTONE PΓ (PL PA)
nil' = monotone (λ x → []) (λ x y x₁ → <>)
cons' : ∀ {PΓ PA} → MONOTONE PΓ PA → MONOTONE PΓ (PL PA) → MONOTONE PΓ (PL PA)
cons' (monotone f is-monotone) (monotone f₁ is-monotone₁) = monotone (λ x → f x :: f₁ x) (λ x y x₁ → (is-monotone x y x₁) , (is-monotone₁ x y x₁))
lrec : ∀ {A C : Set} → (l : List A) → (nil : C) → (cons : A → List A → C → C) → C
lrec [] nil cons = nil
lrec (x :: l) nil cons = cons x l (lrec l nil cons)
listrec-fix-args : ∀ {PΓ PA PC} → (enil : MONOTONE PΓ PC) → (econs : MONOTONE (((PΓ ×p PC) ×p PL PA) ×p PA) PC)
→ (x y : fst (PΓ ×p PL PA)) → (Preorder-str.≤ (snd (PΓ ×p PL PA)) x y)
→ Preorder-str.≤ (snd PC)
(lrec (snd x) (Monotone.f enil (fst x)) (λ x₁ x₂ x₃ → Monotone.f econs (((fst x , x₃) , x₂) , x₁)))
(lrec (snd y) (Monotone.f enil (fst x)) (λ x₁ x₂ x₃ → Monotone.f econs (((fst x , x₃) , x₂) , x₁)))
listrec-fix-args {_} {_} {fst₂ , preorder ≤₂ refl₂ trans₂ p₂} enil _ (x , []) (y , []) p = refl₂ (Monotone.f enil x)
listrec-fix-args _ _ (_ , []) (_ , x₁ :: ys) (_ , ())
listrec-fix-args _ _ (_ , x₁ :: xs) (_ , []) (_ , ())
listrec-fix-args {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} {fst₂ , preorder ≤₂ refl₂ trans₂ p3}
enil (monotone f is-monotone) (x , x₁ :: xs) (y , x₂ :: ys) (x≤y , (hlt , tlt)) =
is-monotone (((x , (lrec xs (Monotone.f enil x) (λ x₃ x₄ x₅ → f (((x , x₅) , x₄) , x₃)))) , xs) , x₁)
(((x , lrec ys (Monotone.f enil x) (λ x₃ x₄ x₅ → f (((x , x₅) , x₄) , x₃))) , ys) , x₂)
((((refl x) , (listrec-fix-args enil (monotone f is-monotone) (x , xs) (y , ys) (x≤y , tlt))) , tlt) , hlt)
listrec-fix-el : ∀ {PΓ PA PC} → (enil : MONOTONE PΓ PC) → (econs : MONOTONE (((PΓ ×p PC) ×p PL PA) ×p PA) PC)
→ (x y : fst (PΓ ×p PL PA)) → (Preorder-str.≤ (snd (PΓ ×p PL PA)) x y)
→ Preorder-str.≤ (snd PC)
(lrec (snd y) (Monotone.f enil (fst x)) (λ x₁ x₂ x₃ → Monotone.f econs (((fst x , x₃) , x₂) , x₁)))
(lrec (snd y) (Monotone.f enil (fst y)) (λ x₁ x₂ x₃ → Monotone.f econs (((fst y , x₃) , x₂) , x₁)))
listrec-fix-el (monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₃ , []) (fst₄ , []) (x≤y , <>) = is-monotone fst₃ fst₄ x≤y
listrec-fix-el _ _ (_ , []) (_ , x₁ :: ys) (_ , ())
listrec-fix-el _ _ (_ , x₁ :: xs) (_ , []) (_ , ())
listrec-fix-el {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} {fst₂ , preorder ≤₂ refl₂ trans₂ p3}
(monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₃ , x :: xs) (fst₄ , y :: ys) (x≤y , hlt , tlt) =
is-monotone₁ (((fst₃ , (lrec ys (f fst₃) (λ x₁ x₂ x₃ → f₁ (((fst₃ , x₃) , x₂) , x₁)))) , ys) , y)
(((fst₄ , (lrec ys (f fst₄) (λ x₁ x₂ x₃ → f₁ (((fst₄ , x₃) , x₂) , x₁)))) , ys) , y)
(((x≤y ,
listrec-fix-el {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} {fst₂ , preorder ≤₂ refl₂ trans₂ p3}
(monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₃ , xs) (fst₄ , ys) (x≤y , tlt)) ,
l-refl (preorder ≤₁ refl₁ trans₁ p2) ys) , (refl₁ y))
lrec-cong : ∀ {PΓ PA PC} → (enil enil' : MONOTONE PΓ PC) → (econs econs' : MONOTONE (((PΓ ×p PC) ×p PL PA) ×p PA) PC)
→ (x : fst (PΓ ×p PL PA))
→ Preorder-str.≤ (snd (PΓ ->p PC)) enil enil'
→ Preorder-str.≤ (snd ((((PΓ ×p PC) ×p PL PA) ×p PA) ->p PC)) econs econs'
→ Preorder-str.≤ (snd PC)
(lrec (snd x) (Monotone.f enil (fst x)) (λ x₁ x₂ x₃ → Monotone.f econs (((fst x , x₃) , x₂) , x₁)))
(lrec (snd x) (Monotone.f enil' (fst x)) (λ x₁ x₂ x₃ → Monotone.f econs' (((fst x , x₃) , x₂) , x₁)))
lrec-cong _ _ _ _ (x , []) p q = p x
lrec-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} {fst₂ , preorder ≤₂ refl₂ trans₂ p3} en en' ec ec' (x , x₁ :: l) p q =
trans₂
(lrec (x₁ :: l) (Monotone.f en x) (λ x₂ x₃ x₄ → Monotone.f ec (((x , x₄) , x₃) , x₂)))
(Monotone.f ec' (((x , lrec l (Monotone.f en x) (λ x₂ x₃ x₄ → Monotone.f ec (((x , x₄) , x₃) , x₂))) , l) , x₁))
(lrec (x₁ :: l) (Monotone.f en' x) (λ x₂ x₃ x₄ → Monotone.f ec' (((x , x₄) , x₃) , x₂)))
(q (((x , lrec l (Monotone.f en x) (λ x₂ x₃ x₄ → Monotone.f ec (((x , x₄) , x₃) , x₂))) , l) , x₁))
(Monotone.is-monotone ec'
(((x , lrec l (Monotone.f en x) (λ x₂ x₃ x₄ → Monotone.f ec (((x , x₄) , x₃) , x₂))) , l) , x₁)
(((x , lrec l (Monotone.f en' x) (λ x₂ x₃ x₄ → Monotone.f ec' (((x , x₄) , x₃) , x₂))) , l) , x₁)
((((refl x) ,
(lrec-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} {fst₂ , preorder ≤₂ refl₂ trans₂ p3} en en' ec ec' (x , l) p q)) ,
(l-refl (preorder ≤₁ refl₁ trans₁ p2) l)) ,
refl₁ x₁))
lrec' : ∀ {PΓ PA PC} → (enil : MONOTONE PΓ PC) → (econs : MONOTONE (((PΓ ×p PC) ×p PL PA) ×p PA) PC) → MONOTONE (PΓ ×p PL PA) PC
lrec' {Γ , preorder ≤Γ reflΓ transΓ pΓ} {A , preorder ≤A reflA transA pa} {C , preorder ≤C reflC transC pc} (monotone enil is-monotone) (monotone econs is-monotone₁) =
monotone (λ x → lrec (snd x) (enil (fst x)) (λ x₁ x₂ x₃ → econs ((((fst x) , x₃) , x₂) , x₁)))
(λ x y x₁ → transC
(lrec (snd x) (enil (fst x)) (λ x₂ x₃ x₄ → econs (((fst x , x₄) , x₃) , x₂)))
(lrec (snd y) (enil (fst x)) (λ x₂ x₃ x₄ → econs (((fst x , x₄) , x₃) , x₂)))
(lrec (snd y) (enil (fst y)) (λ x₂ x₃ x₄ → econs (((fst y , x₄) , x₃) , x₂)))
(listrec-fix-args {Γ , preorder ≤Γ reflΓ transΓ pΓ} {A , preorder ≤A reflA transA pa} {C , preorder ≤C reflC transC pc}
(monotone enil is-monotone) (monotone econs is-monotone₁) x y x₁)
(listrec-fix-el {Γ , preorder ≤Γ reflΓ transΓ pΓ} {A , preorder ≤A reflA transA pa} {C , preorder ≤C reflC transC pc}
(monotone enil is-monotone) (monotone econs is-monotone₁) x y x₁))
natrec : ∀{C : Set} → (base : C) → (step : Nat → C → C) → (n : Nat) → C
natrec base step Z = base
natrec base step (S n) = step n (natrec base step n)
h-lem : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PN) ×p PC) PC) → (x y : fst (PΓ ×p PN))
→ (∀ x → Preorder-str.≤ (snd PC) (Monotone.f e0 x) (Monotone.f e1 ((x , 0) , Monotone.f e0 x)))
→ Preorder-str.≤ (snd PΓ) (fst x) (fst y)
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , n) , x₂)) (snd x))
(natrec (Monotone.f e0 (fst y)) (λ n x₂ → Monotone.f e1 ((fst y , n) , x₂)) (snd x))
h-lem (monotone e0 e0-is-monotone) _ (x , Z) (y , m) p q = e0-is-monotone x y q
h-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , S n) (y , m) p q =
e1-is-monotone
((x , n) , natrec (e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) n)
((y , n) , natrec (e0 y) (λ n₁ x₂ → e1 ((y , n₁) , x₂)) n)
((q , (Preorder-str.refl nat-p n)) ,
(h-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , n) (y , m) p q))
h-lem2-lem : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PN) ×p PC) PC) → (x : fst (PΓ ×p PN))
→ (∀ x → Preorder-str.≤ (snd PC) (Monotone.f e0 x) (Monotone.f e1 ((x , 0) , Monotone.f e0 x)))
→ Preorder-str.≤ (snd PC)
(Monotone.f e0 (fst x))
(Monotone.f e1 (((fst x) , (snd x)) , (natrec (Monotone.f e0 (fst x)) (λ x₁ x₂ → Monotone.f e1 (((fst x) , x₁) , x₂)) (snd x))))
h-lem2-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , Z) p = p x
h-lem2-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , S n) p =
transc
(e0 x)
(e1 ((x , 0) , e0 x))
(e1 ((x , (S n)) , (natrec (e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) (S n))))
(p x)
(e1-is-monotone ((x , 0) , e0 x) ((x , (S n)) , (natrec (e0 x) (λ x₁ x₂ → e1 ((x , x₁) , x₂)) (S n)))
(((refl x) , <>) ,
h-lem2-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , n) p))
h-lem2 : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PN) ×p PC) PC) → (x y : fst (PΓ ×p PN))
→ (∀ x → Preorder-str.≤ (snd PC) (Monotone.f e0 x) (Monotone.f e1 ((x , 0) , Monotone.f e0 x)))
→ Preorder-str.≤ (snd PN) (snd x) (snd y)
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , n) , x₂)) (snd x))
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , n) , x₂)) (snd y))
h-lem2 {_} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , Z) (y , Z) p q = reflc (e0 x)
h-lem2 {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , Z) (y , S n) p q =
h-lem2-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , n) (λ x₁ → p x₁)
h-lem2 _ _ (x , S m) (y , Z) p ()
h-lem2 {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , S m) (y , S n) p q =
e1-is-monotone
((x , m) , (natrec (e0 x) (λ x₁ x₂ → e1 ((x , x₁) , x₂)) m))
((x , n) , natrec (e0 x) (λ x₁ x₂ → e1 ((x , x₁) , x₂)) n)
(((refl x) , q) ,
(h-lem2 {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (x , m) (y , n) p q))
h-cong : ∀ {PΓ PC} → (e0 e0' : MONOTONE PΓ PC) → (e1 e1' : MONOTONE ((PΓ ×p PN) ×p PC) PC) → (x : fst (PΓ ×p PN))
→ Preorder-str.≤ (snd (PΓ ->p PC)) e0 e0'
→ Preorder-str.≤ (snd (((PΓ ×p PN) ×p PC) ->p PC)) e1 e1'
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , n) , x₂)) (snd x))
(natrec (Monotone.f e0' (fst x)) (λ n x₂ → Monotone.f e1' ((fst x , n) , x₂)) (snd x))
h-cong {_} {_} e0 e0' e1 e1' (x , Z) p q = p x
h-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} e0 e0' (monotone e1 e1-is-monotone) (monotone e1' e1'-is-monotone) (x , S n) p q =
trans₁
(natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) (S n))
(e1' ((x , n) , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) n))
(natrec (Monotone.f e0' x) (λ n₁ x₂ → e1' ((x , n₁) , x₂)) (S n))
(q ((x , n) , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) n))
(e1'-is-monotone
((x , n) , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , n₁) , x₂)) n)
((x , n) , natrec (Monotone.f e0' x) (λ n₁ x₂ → e1' ((x , n₁) , x₂)) n)
(((refl x) ,
(nat-refl n)) ,
h-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} e0 e0' (monotone e1 e1-is-monotone) (monotone e1' e1'-is-monotone) (x , n) p q))
rec' : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PN) ×p PC) PC)
→ (∀ x → Preorder-str.≤ (snd PC) (Monotone.f e0 x) (Monotone.f e1 ((x , 0) , Monotone.f e0 x)))
→ MONOTONE (PΓ ×p PN) PC
rec' {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) p =
monotone (λ x → natrec (e0 (fst x)) (λ n x₂ → e1 ((fst x , n) , x₂)) (snd x))
(λ x y x₁ →
transc
(natrec (e0 (fst x)) (λ n x₂ → e1 ((fst x , n) , x₂)) (snd x))
(natrec (e0 (fst y)) (λ n x₂ → e1 ((fst y , n) , x₂)) (snd x))
(natrec (e0 (fst y)) (λ n x₂ → e1 ((fst y , n) , x₂)) (snd y))
(h-lem {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (fst x , snd x) (fst y , snd x) (λ x₂ → p x₂) (fst x₁))
(h-lem2 {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2}
(monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) (fst y , snd x) (fst y , snd y) (λ x₂ → p x₂) (snd x₁)))
h-cong2 : ∀ {PΓ PC} → (e0 e0' : MONOTONE PΓ PC) → (e1 e1' : MONOTONE ((PΓ ×p PN) ×p PC) PC)
→ Preorder-str.≤ (snd (PΓ ->p PC)) e0 e0'
→ Preorder-str.≤ (snd (((PΓ ×p PN) ×p PC) ->p PC)) e1 e1'
→ (x : ∀ x₁ → Preorder-str.≤ (snd PC) (Monotone.f e0 x₁) (Monotone.f e1 ((x₁ , 0) , Monotone.f e0 x₁)))
→ (y : ∀ x₁ → Preorder-str.≤ (snd PC) (Monotone.f e0' x₁) (Monotone.f e1' ((x₁ , 0) , Monotone.f e0' x₁)))
→ Preorder-str.≤ (snd ((PΓ ×p PN) ->p PC)) (rec' e0 e1 x) (rec' e0' e1' y)
h-cong2 {_} {_} _ _ _ _ d1 d2 p q (el , Z) = d1 el
h-cong2 {_} {_} e0 e0' e1 e1' d1 d2 p q (el , S n) = h-cong e0 e0' e1 e1' (el , (S n)) d1 d2
♭h-fix-args : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PC) ×p (Nat , ♭nat-p)) PC) → (x y : fst (PΓ ×p (Nat , ♭nat-p)))
→ nat-eq (snd x) (snd y)
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , x₂) , n)) (snd x))
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , x₂) , n)) (snd y))
♭h-fix-args {_} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} (monotone f is-monotone) (monotone g is-monotone₁) (x , Z) (y , Z) p = refl₁ (f x)
♭h-fix-args (monotone f is-monotone) (monotone g is-monotone₁) (x , Z) (y , S n) ()
♭h-fix-args (monotone f is-monotone) (monotone g is-monotone₁) (x , S m) (y , Z) ()
♭h-fix-args {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} (monotone f is-monotone) (monotone g is-monotone₁) (x , S m) (y , S n) p =
is-monotone₁ ((x , (natrec (f x) (λ n₁ x₂ → g ((x , x₂) , n₁)) m)) , m) ((x , (natrec (f x) (λ n₁ x₂ → g ((x , x₂) , n₁)) n)) , n)
(((refl x) , (♭h-fix-args {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} (monotone f is-monotone) (monotone g is-monotone₁) (x , m) (y , n) p)) , p)
♭h-fix-el : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PC) ×p (Nat , ♭nat-p)) PC) → (x y : fst (PΓ ×p (Nat , ♭nat-p)))
→ Preorder-str.≤ (snd (PΓ ×p (Nat , ♭nat-p))) x y
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , x₂) , n)) (snd y))
(natrec (Monotone.f e0 (fst y)) (λ n x₂ → Monotone.f e1 ((fst y , x₂) , n)) (snd y))
♭h-fix-el {fst , preorder ≤ refl trans p≤} {_} (monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₂ , Z) (fst₃ , Z) (p1 , p2) = is-monotone fst₂ fst₃ p1
♭h-fix-el (monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₂ , Z) (fst₃ , S n) (fst₄ , ())
♭h-fix-el (monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₂ , S m) (fst₃ , Z) (fst₄ , ())
♭h-fix-el {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} (monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₂ , S m) (fst₃ , S n) (fst₄ , snd) =
is-monotone₁ ((fst₂ , (natrec (f fst₂) (λ n₁ x₂ → f₁ ((fst₂ , x₂) , n₁)) n)) , n) ((fst₃ , (natrec (f fst₃) (λ n₁ x₂ → f₁ ((fst₃ , x₂) , n₁)) n)) , n)
((fst₄ ,
(♭h-fix-el {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2}
(monotone f is-monotone) (monotone f₁ is-monotone₁) (fst₂ , m) (fst₃ , n) (fst₄ , snd))) ,
(♭nat-refl n))
♭h-cong : ∀ {PΓ PC} → (e0 e0' : MONOTONE PΓ PC) → (e1 e1' : MONOTONE ((PΓ ×p PC) ×p (Nat , ♭nat-p)) PC) → (x : fst (PΓ ×p (Nat , ♭nat-p)))
→ Preorder-str.≤ (snd (PΓ ->p PC)) e0 e0'
→ Preorder-str.≤ (snd (((PΓ ×p PC) ×p (Nat , ♭nat-p)) ->p PC)) e1 e1'
→ Preorder-str.≤ (snd PC)
(natrec (Monotone.f e0 (fst x)) (λ n x₂ → Monotone.f e1 ((fst x , x₂) , n)) (snd x))
(natrec (Monotone.f e0' (fst x)) (λ n x₂ → Monotone.f e1' ((fst x , x₂) , n)) (snd x))
♭h-cong {_} {_} e0 e0' e1 e1' (x , Z) p q = p x
♭h-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} e0 e0' (monotone e1 e1-is-monotone) (monotone e1' e1'-is-monotone) (x , S n) p q =
trans₁
(natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , x₂) , n₁)) (S n))
(e1' ((x , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , x₂) , n₁)) n) , n))
(natrec (Monotone.f e0' x) (λ n₁ x₂ → e1' ((x , x₂) , n₁)) (S n))
(q ((x , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , x₂) , n₁)) n) , n))
(e1'-is-monotone
((x , natrec (Monotone.f e0 x) (λ n₁ x₂ → e1 ((x , x₂) , n₁)) n) , n)
((x , natrec (Monotone.f e0' x) (λ n₁ x₂ → e1' ((x , x₂) , n₁)) n) , n)
(((refl x) ,
♭h-cong {fst , preorder ≤ refl trans p1} {fst₁ , preorder ≤₁ refl₁ trans₁ p2} e0 e0' (monotone e1 e1-is-monotone) (monotone e1' e1'-is-monotone) (x , n) p q) ,
♭nat-refl n))
♭rec' : ∀ {PΓ PC} → (e0 : MONOTONE PΓ PC) → (e1 : MONOTONE ((PΓ ×p PC) ×p (Nat , ♭nat-p)) PC) → MONOTONE (PΓ ×p (Nat , ♭nat-p)) PC
♭rec' {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) =
monotone (λ x → natrec (e0 (fst x)) (λ n x₂ → e1 (((fst x) , x₂) , n)) (snd x))
(λ x y x₁ → transc
(natrec (e0 (fst x)) (λ n x₂ → e1 ((fst x , x₂) , n)) (snd x))
(natrec (e0 (fst x)) (λ n x₂ → e1 ((fst x , x₂) , n)) (snd y))
(natrec (e0 (fst y)) (λ n x₂ → e1 ((fst y , x₂) , n)) (snd y))
(♭h-fix-args {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) x y (snd x₁))
(♭h-fix-el {Γ , preorder ≤ refl trans p1} {C , preorder ≤c reflc transc p2} (monotone e0 e0-is-monotone) (monotone e1 e1-is-monotone) x y x₁))
--- extend Preorders so you can impose max on them if type has maximums
record Preorder-max-str {A : Set} (PA : Preorder-str A) : Set where
constructor preorder-max
field
max : A → A → A
max-l : ∀ l r → Preorder-str.≤ PA l (max l r)
max-r : ∀ l r → Preorder-str.≤ PA r (max l r)
max-lub : ∀ k l r → Preorder-str.≤ PA l k → Preorder-str.≤ PA r k → Preorder-str.≤ PA (max l r) k
nat-max : Nat → Nat → Nat
nat-max Z n = n
nat-max (S m) Z = S m
nat-max (S m) (S n) = S (nat-max m n)
nat-max-l : ∀ (l r : Nat) → ≤nat l (nat-max l r)
nat-max-l Z Z = <>
nat-max-l Z (S n) = <>
nat-max-l (S m) Z = nat-refl m
nat-max-l (S m) (S n) = nat-max-l m n
nat-max-r : ∀ (l r : Nat) → ≤nat r (nat-max l r)
nat-max-r Z Z = <>
nat-max-r Z (S n) = nat-refl n
nat-max-r (S m) Z = <>
nat-max-r (S m) (S n) = nat-max-r m n
nat-max-lub : ∀ (k l r : Nat) → ≤nat l k → ≤nat r k → ≤nat (nat-max l r) k
nat-max-lub Z Z Z p q = <>
nat-max-lub Z Z (S r) p ()
nat-max-lub Z (S l) Z () q
nat-max-lub Z (S l) (S r) () q
nat-max-lub (S k) Z Z p q = <>
nat-max-lub (S k) Z (S r) p q = q
nat-max-lub (S k) (S l) Z p q = p
nat-max-lub (S k) (S l) (S r) p q = nat-max-lub k l r p q
nat-pM : Preorder-max-str nat-p
nat-pM = preorder-max nat-max nat-max-l nat-max-r nat-max-lub
unit-pM : Preorder-max-str (snd unit-p)
unit-pM = preorder-max (λ x x₁ → <>) (λ l r → <>) (λ l r → <>) (λ k l r x x₁ → <>)
axb-max : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ Preorder-max-str PA → Preorder-max-str PB → (A × B) → (A × B) → (A × B)
axb-max PA PB (a1 , b1) (a2 , b2) = Preorder-max-str.max PA a1 a2 , Preorder-max-str.max PB b1 b2
axb-max-l : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMA : Preorder-max-str PA) → (PMB : Preorder-max-str PB) → (l r : (A × B)) → ≤axb PA PB l (axb-max PMA PMB l r)
axb-max-l PMA PMB (a1 , b1) (a2 , b2) = Preorder-max-str.max-l PMA a1 a2 , Preorder-max-str.max-l PMB b1 b2
axb-max-r : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMA : Preorder-max-str PA) → (PMB : Preorder-max-str PB) → (l r : (A × B)) → ≤axb PA PB r (axb-max PMA PMB l r)
axb-max-r PMA PMB (a1 , b1) (a2 , b2) = Preorder-max-str.max-r PMA a1 a2 , Preorder-max-str.max-r PMB b1 b2
axb-max-lub : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMA : Preorder-max-str PA) → (PMB : Preorder-max-str PB) → (k l r : (A × B))
→ ≤axb PA PB l k → ≤axb PA PB r k → ≤axb PA PB (axb-max PMA PMB l r) k
axb-max-lub PMA PMB (k1 , k2) (l1 , l2) (r1 , r2) (l1<k1 , l2<k2) (r1<k1 , r2<k2) =
Preorder-max-str.max-lub PMA k1 l1 r1 l1<k1 r1<k1 , Preorder-max-str.max-lub PMB k2 l2 r2 l2<k2 r2<k2
axb-pM : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ Preorder-max-str PA → Preorder-max-str PB → Preorder-max-str (axb-p A B PA PB)
axb-pM PMA PMB = preorder-max (axb-max PMA PMB) (axb-max-l PMA PMB) (axb-max-r PMA PMB) (axb-max-lub PMA PMB)
mono-max : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ Preorder-max-str PB
→ (Monotone A B PA PB) → (Monotone A B PA PB) → (Monotone A B PA PB)
mono-max {A} {B} {PA} {PB} PMB (monotone f f-ismono) (monotone g g-ismono) =
monotone (λ x → Preorder-max-str.max PMB (f x) (g x))
(λ x y x₁ → Preorder-max-str.max-lub PMB (Preorder-max-str.max PMB (f y) (g y)) (f x) (g x)
(Preorder-str.trans PB (f x) (f y)
(Preorder-max-str.max PMB (f y) (g y)) (f-ismono x y x₁)
(Preorder-max-str.max-l PMB (f y) (g y)))
(Preorder-str.trans PB (g x) (g y)
(Preorder-max-str.max PMB (f y) (g y)) (g-ismono x y x₁)
(Preorder-max-str.max-r PMB (f y) (g y))))
mono-max-l : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMB : Preorder-max-str PB) → (l r : Monotone A B PA PB) → ≤mono PA PB l (mono-max PMB l r)
mono-max-l PMB f g = λ x → Preorder-max-str.max-l PMB (Monotone.f f x) (Monotone.f g x)
mono-max-r : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMB : Preorder-max-str PB) → (l r : Monotone A B PA PB) → ≤mono PA PB r (mono-max PMB l r)
mono-max-r PMB f g = λ x → Preorder-max-str.max-r PMB (Monotone.f f x) (Monotone.f g x)
mono-max-lub : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ (PMB : Preorder-max-str PB)
→ (k l r : Monotone A B PA PB)
→ ≤mono PA PB l k → ≤mono PA PB r k → ≤mono PA PB (mono-max PMB l r) k
mono-max-lub PMB f g h p q = λ x → Preorder-max-str.max-lub PMB (Monotone.f f x) (Monotone.f g x) (Monotone.f h x) (p x) (q x)
mono-pM : ∀ {A B : Set} {PA : Preorder-str A} {PB : Preorder-str B}
→ Preorder-max-str PB → Preorder-max-str (mono-p A B PA PB)
mono-pM PMB = preorder-max (mono-max PMB) (mono-max-l PMB) (mono-max-r PMB) (mono-max-lub PMB)
--???
PREORDER-MAX = (Σ (λ (A : Set) → (PA : Preorder-str A) → Preorder-max-str PA))
-- stuff I need for monotonicity of plus
nat-lemma3 : ∀ (x : Nat) → ≤nat x (S x)
nat-lemma3 Z = <>
nat-lemma3 (S x) = nat-lemma3 x
plus-lem' : ∀ (a b c : Nat) → ≤nat a b → ≤nat a (b + c)
plus-lem' Z Z Z <> = <>
plus-lem' Z Z (S c) <> = <>
plus-lem' Z (S b) c x = <>
plus-lem' (S a) Z c ()
plus-lem' (S a) (S b) c x = plus-lem' a b c x
plus-rh-S : (n m : Nat) → ≤nat (S (n + m)) (n + S m)
plus-rh-S Z m = nat-refl m
plus-rh-S (S n) m = plus-rh-S n m
+-unit : ∀ (a : Nat) → ≤nat (a + 0) a
+-unit Z = <>
+-unit (S a) = +-unit a
+-comm : ∀ (a b : Nat) → ≤nat (a + b) (b + a)
+-comm Z b = plus-lem' b b Z (nat-refl b)
+-comm (S a) b = nat-trans (S (a + b)) (S (b + a)) (b + S a) (+-comm a b) (plus-rh-S b a)
plus-assoc : ∀ (a b c : Nat) → ≤nat (a + (b + c)) ((a + b) + c)
plus-assoc Z b c = nat-refl (b + c)
plus-assoc (S a) b c = plus-assoc a b c
plus-assoc' : ∀ (a b c : Nat) → ≤nat ((a + b) + c) (a + (b + c))
plus-assoc' Z b c = nat-refl (b + c)
plus-assoc' (S a) b c = plus-assoc' a b c
mutual
plus-lem'' : ∀ (a b : Nat) → ≤nat a (b + a)
plus-lem'' a Z = nat-refl a
plus-lem'' Z (S b) = <>
plus-lem'' (S a) (S b) = nat-trans a (b + a) (b + S a) (plus-lem'' a b) (plus-lem b a b (S a) (nat-refl b) (nat-lemma3 a))
plus-lem : ∀ (a b c d : Nat) → ≤nat a c → ≤nat b d → ≤nat (a + b) (c + d)
plus-lem Z b Z d p q = q
plus-lem Z Z (S c) Z p q = <>
plus-lem Z (S b) (S c) Z p ()
plus-lem Z Z (S c) (S d) p q = <>
plus-lem Z (S b) (S c) (S d) p q = nat-trans b d (c + S d) q (nat-trans d (S d) (c + S d) (nat-lemma3 d) (plus-lem'' (S d) c))
plus-lem (S a) b Z d () q
plus-lem (S a) b (S c) d p q = plus-lem a b c d p q
el : PREORDER → Set
el = fst
PREORDER≤ : (PA : PREORDER) → el PA → el PA → Set
PREORDER≤ PA = Preorder-str.≤ (snd PA)
|
{
"alphanum_fraction": 0.5173930865,
"avg_line_length": 55.8702290076,
"ext": "agda",
"hexsha": "7663d326673d538f6c1192125584cb8f4b16bc33",
"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/Preorder.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/Preorder.agda",
"max_line_length": 177,
"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/Preorder.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": 15510,
"size": 36595
}
|
module Common.Level where
open import Agda.Primitive public
|
{
"alphanum_fraction": 0.8360655738,
"avg_line_length": 15.25,
"ext": "agda",
"hexsha": "854dcb3fa39f4d1d0e18091d8e87e370ecad8aa9",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/Termination/Common/Level.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/Termination/Common/Level.agda",
"max_line_length": 33,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/Termination/Common/Level.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": 61
}
|
open import Relation.Binary.Core
module PLRTree.Drop.Permutation {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.List hiding (drop)
open import Data.Sum
open import List.Permutation.Base A
open import List.Permutation.Base.Equivalence A
open import PLRTree {A}
open import PLRTree.Complete {A}
open import PLRTree.Compound {A}
open import PLRTree.Drop _≤_ tot≤
open import PLRTree.Drop.Complete _≤_ tot≤
open import PLRTree.DropLast.Complete _≤_ tot≤
open import PLRTree.DropLast.Permutation _≤_ tot≤
open import PLRTree.Equality {A}
open import PLRTree.Order.Properties {A}
open import PLRTree.Push.Permutation _≤_ tot≤
lemma-drop-++ : {t : Tag}{x : A}{l r : PLRTree} → Complete (node t x l r) → flatten (drop (node t x l r)) ∼ (flatten l ++ flatten r)
lemma-drop-++ (perfect {leaf} {leaf} x leaf leaf ≃lf) = ∼[]
lemma-drop-++ (perfect {node perfect x' l' r'} {node perfect x'' l'' r''} x cl cr (≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'')) =
let _l = node perfect x' l' r' ;
_r = node perfect x'' l'' r'' ;
_l≃r = ≃nd x' x'' l'≃r' l''≃r'' l'≃l'' ;
cxlr = perfect x cl cr _l≃r ;
z = last (node perfect x _l _r) compound ;
t' = dropLast (node perfect x _l _r) ;
ct' = right x cl (lemma-dropLast-complete cr) (lemma-dropLast-≃ _l≃r compound)
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) (lemma-dropLast-∼ cxlr)
lemma-drop-++ (left {l} {r} x cl cr l⋘r)
with l | r | l⋘r | lemma-dropLast-⋘ l⋘r
... | leaf | _ | () | _
... | node perfect x' l' r' | _ | () | _
... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r
with dropLast (node left x' l' r') | ld⋘r | lemma-dropLast-complete cl | lemma-dropLast-∼ (left x cl cr (l⋘ x' x'' l'⋘r' l''≃r'' r'≃l''))
... | leaf | () | _ | _
... | node perfect _ _ _ | () | _ | _
... | node left x''' l''' r''' | ld⋘r' | cld | fzt'∼flfr =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node right x''' l''' r''' | ld⋘r' | cld | fzt'∼flfr =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
lemma-drop-++ (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r
with dropLast (node left x' l' r') | ld≃r | lemma-dropLast-complete cl | lemma-dropLast-∼ (left x cl cr (l⋘ x' x'' l'⋘r' l''≃r'' r'≃l''))
... | leaf | () | _ | _
... | node perfect x''' l''' r''' | ld≃r' | cld | fzt'∼flfr =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node left _ _ _ | () | _ | _
... | node right _ _ _ | () | _ | _
lemma-drop-++ (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _
lemma-drop-++ (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ ()
lemma-drop-++ (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' =
let z = last (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) compound ;
t' = dropLast (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) ;
ct' = perfect x (perfect x' leaf leaf ≃lf) cr x'≃x''' ;
fzt'∼flfr = lemma-dropLast-∼ (left x cl cr (x⋘ x' x'' x'''))
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
lemma-drop-++ (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r
with dropLast (node right x' l' r') | ld⋘r | lemma-dropLast-complete cl | lemma-dropLast-∼ (left x cl cr (r⋘ x' x'' l⋙r l''≃r'' l'⋗l''))
... | leaf | () | _ | _
... | node perfect _ _ _ | () | _ | _
... | node left x''' l''' r''' | ld⋘r' | cld | fzt'∼flfr =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node right x''' l''' r''' | ld⋘r' | cld | fzt'∼flfr =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
lemma-drop-++ (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r
with dropLast (node right x' l' r') | ld≃r | lemma-dropLast-complete cl | lemma-dropLast-∼ (left x cl cr (r⋘ x' x'' l⋙r l''≃r'' l'⋗l''))
... | leaf | () | _ | _
... | node perfect x''' l''' r''' | ld≃r' | cld | fzt'∼flfr =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node left _ _ _ | () | _ | _
... | node right _ _ _ | () | _ | _
lemma-drop-++ (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _
lemma-drop-++ (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _
lemma-drop-++ (right {l} {r} x cl cr l⋙r)
with l | r | l⋙r | lemma-dropLast-⋙ l⋙r
... | leaf | leaf | ⋙p () | _
... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') | _ = ∼x /head /head ∼[]
... | node perfect _ _ (node _ _ _ _) | leaf | ⋙p () | _
... | node perfect _ (node _ _ _ _) _ | leaf | ⋙p () | _
... | node left _ _ _ | leaf | ⋙p () | _
... | node right _ _ _ | leaf | ⋙p () | _
... | leaf | node perfect _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') | _ =
let z = last (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) ;
ct' = left x (lemma-dropLast-complete cl) cr (lemma-dropLast-⋗ (⋗nd x' x'' l'≃r' l''≃r'' l'⋗l'') compound) ;
fzt'∼flfr = lemma-dropLast-∼ (right x cl cr (⋙p (⋗nd x' x'' l'≃r' l''≃r'' l'⋗l'')))
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node left _ _ _ | node perfect _ _ _ | ⋙p () | _
... | node right _ _ _ | node perfect _ _ _ | ⋙p () | _
... | leaf | node left _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node left x'' l'' r'' | _l⋙r | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node left x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node left x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd ;
fzt'∼flfr = lemma-dropLast-∼ (right x cl cr _l⋙r)
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node perfect _ _ _ | node left _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node left _ _ _ | ⋙p () | _
... | node right _ _ _ | node left _ _ _ | ⋙p () | _
... | leaf | node right _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node right x'' l'' r'' | _l⋙r | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node right x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node right x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd ;
fzt'∼flfr = lemma-dropLast-∼ (right x cl cr _l⋙r)
in trans∼ (lemma-push-∼ (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))) fzt'∼flfr
... | node perfect _ _ _ | node right _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node right _ _ _ | ⋙p () | _
... | node right _ _ _ | node right _ _ _ | ⋙p () | _
lemma-drop-∼ : {t : Tag}{x : A}{l r : PLRTree} → Complete (node t x l r) → (x ∷ flatten (drop (node t x l r))) ∼ flatten (node t x l r)
lemma-drop-∼ (perfect x cl cr l≃r) = ∼x /head /head (lemma-drop-++ (perfect x cl cr l≃r))
lemma-drop-∼ (left x cl cr l⋘r) = ∼x /head /head (lemma-drop-++ (left x cl cr l⋘r))
lemma-drop-∼ (right x cl cr l⋙r) = ∼x /head /head (lemma-drop-++ (right x cl cr l⋙r))
|
{
"alphanum_fraction": 0.4941622286,
"avg_line_length": 70.2446043165,
"ext": "agda",
"hexsha": "9f374395c93282a9504837149336149145dfe36d",
"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": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree/Drop/Permutation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"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": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree/Drop/Permutation.agda",
"max_line_length": 149,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree/Drop/Permutation.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 3661,
"size": 9764
}
|
-- Classical propositional logic, PHOAS approach, initial encoding
module Pi.Cp where
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set1
Cx = Ty -> Set
isTrue : Ty -> Cx -> Set
isTrue a tc = tc a
-- Terms
module Cp where
infixl 1 _$_
data Tm (tc : Cx) : Ty -> Set where
var : forall {a} -> isTrue a tc -> Tm tc a
lam' : forall {a b} -> (isTrue a tc -> Tm tc b) -> Tm tc (a => b)
_$_ : forall {a b} -> Tm tc (a => b) -> Tm tc a -> Tm tc b
pair' : forall {a b} -> Tm tc a -> Tm tc b -> Tm tc (a && b)
fst : forall {a b} -> Tm tc (a && b) -> Tm tc a
snd : forall {a b} -> Tm tc (a && b) -> Tm tc b
left : forall {a b} -> Tm tc a -> Tm tc (a || b)
right : forall {a b} -> Tm tc b -> Tm tc (a || b)
case' : forall {a b c} -> Tm tc (a || b) -> (isTrue a tc -> Tm tc c) -> (isTrue b tc -> Tm tc c) -> Tm tc c
abort' : forall {a} -> (isTrue (NOT a) tc -> Tm tc FALSE) -> Tm tc a
lam'' : forall {tc a b} -> (Tm tc a -> Tm tc b) -> Tm tc (a => b)
lam'' f = lam' \x -> f (var x)
case'' : forall {tc a b c} -> Tm tc (a || b) -> (Tm tc a -> Tm tc c) -> (Tm tc b -> Tm tc c) -> Tm tc c
case'' xy f g = case' xy (\x -> f (var x)) (\y -> g (var y))
abort'' : forall {tc a} -> (Tm tc (NOT a) -> Tm tc FALSE) -> Tm tc a
abort'' f = abort' \na -> f (var na)
syntax lam'' (\a -> b) = lam a => b
syntax pair' x y = [ x , y ]
syntax case'' xy (\x -> z1) (\y -> z2) = case xy of x => z1 or y => z2
syntax abort'' (\x -> y) = abort x => y
Thm : Ty -> Set1
Thm a = forall {tc} -> Tm tc a
open Cp public
|
{
"alphanum_fraction": 0.4476945959,
"avg_line_length": 28.4084507042,
"ext": "agda",
"hexsha": "c5bd9ccd980af47bc784043723660fc586eb24a8",
"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": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Pi/Cp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Pi/Cp.agda",
"max_line_length": 112,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Pi/Cp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 795,
"size": 2017
}
|
module Inductions where
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl; cong; sym)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Data.Nat using (ℕ; zero; suc; _+_; _*_; _∸_)
open import Data.Nat using (ℕ; _+_; _*_; _∸_) hiding (zero) renaming (suc to succ)
|
{
"alphanum_fraction": 0.6970684039,
"avg_line_length": 38.375,
"ext": "agda",
"hexsha": "60786ece9e1395653ad5637bf4619be503005df7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-03-12T21:33:35.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-10-07T01:38:12.000Z",
"max_forks_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "dubinsky/intellij-dtlc",
"max_forks_repo_path": "testData/parse/agda/open using.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_issues_repo_issues_event_max_datetime": "2021-03-15T17:04:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-30T04:29:32.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "dubinsky/intellij-dtlc",
"max_issues_repo_path": "testData/parse/agda/open using.agda",
"max_line_length": 82,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "ee25a3a81dacebfe4449de7a9aaff029171456be",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "dubinsky/intellij-dtlc",
"max_stars_repo_path": "testData/parse/agda/open using.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-29T13:18:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-11T16:26:38.000Z",
"num_tokens": 114,
"size": 307
}
|
------------------------------------------------------------------------
-- Properties satisfied by decidable total orders
------------------------------------------------------------------------
open import Relation.Binary
module Relation.Binary.Props.DecTotalOrder (dt : DecTotalOrder) where
open Relation.Binary.DecTotalOrder dt hiding (trans)
import Relation.Binary.NonStrictToStrict as Conv
open Conv _≈_ _≤_
strictTotalOrder : StrictTotalOrder
strictTotalOrder = record
{ isStrictTotalOrder = record
{ isEquivalence = isEquivalence
; trans = trans isPartialOrder
; compare = trichotomous Eq.sym _≟_ antisym total
; <-resp-≈ = <-resp-≈ isEquivalence ≤-resp-≈
}
}
open StrictTotalOrder strictTotalOrder public
|
{
"alphanum_fraction": 0.5893782383,
"avg_line_length": 32.1666666667,
"ext": "agda",
"hexsha": "8e320cc25651c3c652994286668fee89adf616f0",
"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/Props/DecTotalOrder.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/Props/DecTotalOrder.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/Props/DecTotalOrder.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": 166,
"size": 772
}
|
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Algebra.Free.Evaluation (Σ : Signature) where
open import Fragment.Algebra.Free.Monad Σ
open import Fragment.Algebra.Algebra Σ
open import Fragment.Algebra.Free.Base Σ
open import Fragment.Algebra.Homomorphism Σ
open import Fragment.Setoid.Morphism as Morphism
open import Level using (Level)
open import Data.Empty using (⊥)
open import Data.Nat using (ℕ; suc)
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec using (Vec; []; _∷_; map)
open import Data.Vec.Relation.Binary.Pointwise.Inductive
using (Pointwise; []; _∷_)
open import Relation.Binary using (Setoid)
import Relation.Binary.PropositionalEquality as PE
private
variable
a b ℓ₁ ℓ₂ : Level
module _ (A : Algebra {a} {ℓ₁}) where
private
open Setoid ∥ A ∥/≈
open import Relation.Binary.Reasoning.Setoid ∥ A ∥/≈
mutual
map-∣eval∣ : ∀ {n} → Vec (Term ∥ A ∥) n → Vec ∥ A ∥ n
map-∣eval∣ [] = []
map-∣eval∣ (x ∷ xs) = ∣eval∣ x ∷ map-∣eval∣ xs
∣eval∣ : Term ∥ A ∥ → ∥ A ∥
∣eval∣ (atom x) = x
∣eval∣ (term f xs) = A ⟦ f ⟧ (map-∣eval∣ xs)
mutual
map-∣eval∣-cong : ∀ {n} {xs ys : Vec (Term ∥ A ∥) n}
→ Pointwise (_~_ ∥ A ∥/≈) xs ys
→ Pointwise ≈[ A ] (map-∣eval∣ xs)
(map-∣eval∣ ys)
map-∣eval∣-cong [] = []
map-∣eval∣-cong (p ∷ ps) = ∣eval∣-cong p ∷ map-∣eval∣-cong ps
∣eval∣-cong : Congruent (_~_ ∥ A ∥/≈) ≈[ A ] ∣eval∣
∣eval∣-cong (atom p) = p
∣eval∣-cong {x = term op _} (term p) =
(A ⟦ op ⟧-cong) (map-∣eval∣-cong p)
∣eval∣⃗ : Herbrand ∥ A ∥/≈ ↝ ∥ A ∥/≈
∣eval∣⃗ = record { ∣_∣ = ∣eval∣
; ∣_∣-cong = ∣eval∣-cong
}
∣eval∣-args≡map : ∀ {n} {xs : Vec (Term ∥ A ∥) n}
→ Pointwise _≈_ (map-∣eval∣ xs) (map ∣eval∣ xs)
∣eval∣-args≡map {xs = []} = []
∣eval∣-args≡map {xs = x ∷ xs} = refl ∷ ∣eval∣-args≡map
∣eval∣-hom : Homomorphic (Free ∥ A ∥/≈) A ∣eval∣
∣eval∣-hom f [] = refl
∣eval∣-hom f (x ∷ xs) = sym ((A ⟦ f ⟧-cong) (∣eval∣-args≡map {xs = x ∷ xs}))
eval : Free ∥ A ∥/≈ ⟿ A
eval = record { ∣_∣⃗ = ∣eval∣⃗
; ∣_∣-hom = ∣eval∣-hom
}
fold : ∀ {A : Setoid a ℓ₁} (B : Algebra {b} {ℓ₂})
→ (A ↝ ∥ B ∥/≈) → Free A ⟿ B
fold B f = (eval B) ⊙ bind (unit · f)
Env : (A : Algebra {a} {ℓ₁}) → ℕ → Set _
Env A n = Fin n → ∥ A ∥
env : ∀ {A : Algebra {a} {ℓ₁}} {n} → (Γ : Vec ∥ A ∥ n) → Env A n
env {A = _} {suc n} (x ∷ _) zero = x
env {A = A} {suc n} (_ ∷ xs) (suc i) = env {A = A} xs i
module _ {n}
{S : Setoid a ℓ₁}
(T : Setoid b ℓ₂)
(f : S ↝ T)
(g : Fin n → Setoid.Carrier T)
where
private
open Setoid S renaming (Carrier to A) using ()
open Setoid T renaming (Carrier to B)
∣sub∣ : BT A n → B
∣sub∣ (sta x) = Morphism.∣ f ∣ x
∣sub∣ (dyn x) = g x
∣sub∣-cong : Congruent (_≍_ S n) _≈_ ∣sub∣
∣sub∣-cong (sta p) = Morphism.∣ f ∣-cong p
∣sub∣-cong (dyn q) = reflexive (PE.cong g q)
sub : Atoms S n ↝ T
sub = record { ∣_∣ = ∣sub∣
; ∣_∣-cong = ∣sub∣-cong
}
module _ {n}
{A : Setoid a ℓ₁}
(B : Algebra {b} {ℓ₂})
(f : A ↝ ∥ B ∥/≈)
(g : Fin n → ∥ B ∥)
where
subst : Free (Atoms A n) ⟿ B
subst = fold B (sub ∥ B ∥/≈ f g)
ignore : ∀ (A : Setoid a ℓ₁) → PE.setoid ⊥ ↝ A
ignore _ = record { ∣_∣ = λ ()
; ∣_∣-cong = λ {}
}
inst : ∀ {n} (A : Algebra {a} {ℓ₁})
→ Env A n → F n ⟿ A
inst {n = n} A θ = subst A (ignore ∥ A ∥/≈) θ
|
{
"alphanum_fraction": 0.4890139335,
"avg_line_length": 28.4885496183,
"ext": "agda",
"hexsha": "3af2b9aeb6b582421e1db568618dd2459ad8f680",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Algebra/Free/Evaluation.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Algebra/Free/Evaluation.agda",
"max_line_length": 80,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Algebra/Free/Evaluation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T17:26:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-15T15:45:39.000Z",
"num_tokens": 1617,
"size": 3732
}
|
{-# OPTIONS --safe #-}
module Definition.Typed.EqualityRelation where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Weakening using (_∷_⊆_)
-- Generic equality relation used with the logical relation
record EqRelSet : Set₁ where
constructor eqRel
field
---------------
-- Relations --
---------------
-- Equality of types
_⊢_≅_^_ : Con Term → (A B : Term) → TypeInfo → Set
-- Equality of terms
_⊢_≅_∷_^_ : Con Term → (t u A : Term) → TypeInfo → Set
-- Equality of neutral terms
_⊢_~_∷_^_ : Con Term → (t u A : Term) → TypeInfo → Set
----------------
-- Properties --
----------------
-- Generic equality compatibility
~-to-≅ₜ : ∀ {k l A r Γ}
→ Γ ⊢ k ~ l ∷ A ^ r
→ Γ ⊢ k ≅ l ∷ A ^ r
-- Judgmental conversion compatibility
≅-eq : ∀ {A B r Γ}
→ Γ ⊢ A ≅ B ^ r
→ Γ ⊢ A ≡ B ^ r
≅ₜ-eq : ∀ {t u A r Γ}
→ Γ ⊢ t ≅ u ∷ A ^ r
→ Γ ⊢ t ≡ u ∷ A ^ r
-- Universe
≅-univ : ∀ {A B r l Γ}
→ Γ ⊢ A ≅ B ∷ (Univ r l) ^ [ ! , next l ]
→ Γ ⊢ A ≅ B ^ [ r , ι l ]
≅-un-univ : ∀ {A B r l Γ}
→ Γ ⊢ A ≅ B ^ [ r , ι l ]
→ Γ ⊢ A ≅ B ∷ (Univ r l) ^ [ ! , next l ]
-- Symmetry
≅-sym : ∀ {A B Γ r} → Γ ⊢ A ≅ B ^ r → Γ ⊢ B ≅ A ^ r
≅ₜ-sym : ∀ {t u A r Γ} → Γ ⊢ t ≅ u ∷ A ^ r → Γ ⊢ u ≅ t ∷ A ^ r
~-sym : ∀ {k l A Γ r} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ k ∷ A ^ r
-- Transitivity
≅-trans : ∀ {A B C r Γ} → Γ ⊢ A ≅ B ^ r → Γ ⊢ B ≅ C ^ r → Γ ⊢ A ≅ C ^ r
≅ₜ-trans : ∀ {t u v A r Γ} → Γ ⊢ t ≅ u ∷ A ^ r → Γ ⊢ u ≅ v ∷ A ^ r → Γ ⊢ t ≅ v ∷ A ^ r
~-trans : ∀ {k l m A r Γ} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ l ~ m ∷ A ^ r → Γ ⊢ k ~ m ∷ A ^ r
-- Conversion
≅-conv : ∀ {t u A B r Γ} → Γ ⊢ t ≅ u ∷ A ^ r → Γ ⊢ A ≡ B ^ r → Γ ⊢ t ≅ u ∷ B ^ r
~-conv : ∀ {k l A B r Γ} → Γ ⊢ k ~ l ∷ A ^ r → Γ ⊢ A ≡ B ^ r → Γ ⊢ k ~ l ∷ B ^ r
-- Weakening
≅-wk : ∀ {A B r ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ A ≅ B ^ r
→ Δ ⊢ wk ρ A ≅ wk ρ B ^ r
≅ₜ-wk : ∀ {t u A r ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ t ≅ u ∷ A ^ r
→ Δ ⊢ wk ρ t ≅ wk ρ u ∷ wk ρ A ^ r
~-wk : ∀ {k l A r ρ Γ Δ}
→ ρ ∷ Δ ⊆ Γ
→ ⊢ Δ
→ Γ ⊢ k ~ l ∷ A ^ r
→ Δ ⊢ wk ρ k ~ wk ρ l ∷ wk ρ A ^ r
-- Weak head expansion
≅-red : ∀ {A A′ B B′ r Γ}
→ Γ ⊢ A ⇒* A′ ^ r
→ Γ ⊢ B ⇒* B′ ^ r
→ Whnf A′
→ Whnf B′
→ Γ ⊢ A′ ≅ B′ ^ r
→ Γ ⊢ A ≅ B ^ r
≅ₜ-red : ∀ {a a′ b b′ A B l Γ}
→ Γ ⊢ A ⇒* B ^ [ ! , l ]
→ Γ ⊢ a ⇒* a′ ∷ B ^ l
→ Γ ⊢ b ⇒* b′ ∷ B ^ l
→ Whnf B
→ Whnf a′
→ Whnf b′
→ Γ ⊢ a′ ≅ b′ ∷ B ^ [ ! , l ]
→ Γ ⊢ a ≅ b ∷ A ^ [ ! , l ]
-- Large universe type reflexivity
≅-U¹refl : ∀ {r Γ} → ⊢ Γ → Γ ⊢ (Univ r ¹) ≅ (Univ r ¹) ^ [ ! , ∞ ]
-- Small universe type reflexivity
≅-U⁰refl : ∀ {r Γ} → ⊢ Γ → Γ ⊢ (Univ r ⁰) ≅ (Univ r ⁰) ∷ U ¹ ^ [ ! , ∞ ]
-- Natural number type reflexivity
≅ₜ-ℕrefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ ℕ ≅ ℕ ∷ U ⁰ ^ [ ! , next ⁰ ]
-- Empty type reflexivity
≅ₜ-Emptyrefl : ∀ {Γ l} → ⊢ Γ → Γ ⊢ Empty l ≅ Empty l ∷ SProp l ^ [ ! , next l ]
-- Π-congruence
≅ₜ-Π-cong : ∀ {F G H E rF lF r lG l Γ}
→ lF ≤ l
→ lG ≤ l
→ Γ ⊢ F ^ [ rF , ι lF ]
→ Γ ⊢ F ≅ H ∷ (Univ rF lF) ^ [ ! , next lF ]
→ Γ ∙ F ^ [ rF , ι lF ] ⊢ G ≅ E ∷ (Univ r lG) ^ [ ! , next lG ]
→ Γ ⊢ Π F ^ rF ° lF ▹ G ° lG ° l ≅ Π H ^ rF ° lF ▹ E ° lG ° l ∷ (Univ r l) ^ [ ! , next l ]
-- ∃-congruence
-- Since ∃ types are always small, no need for a type-level rule
≅ₜ-∃-cong : ∀ {F G H E l Γ}
→ Γ ⊢ F ^ [ % , ι l ]
→ Γ ⊢ F ≅ H ∷ SProp l ^ [ ! , next l ]
→ Γ ∙ F ^ [ % , ι l ] ⊢ G ≅ E ∷ SProp l ^ [ ! , next l ]
→ Γ ⊢ ∃ F ▹ G ≅ ∃ H ▹ E ∷ SProp l ^ [ ! , next l ]
-- Zero reflexivity
≅ₜ-zerorefl : ∀ {Γ} → ⊢ Γ → Γ ⊢ zero ≅ zero ∷ ℕ ^ [ ! , ι ⁰ ]
-- Successor congruence
≅-suc-cong : ∀ {m n Γ} → Γ ⊢ m ≅ n ∷ ℕ ^ [ ! , ι ⁰ ] → Γ ⊢ suc m ≅ suc n ∷ ℕ ^ [ ! , ι ⁰ ]
-- η-equality
≅-η-eq : ∀ {f g F G rF lF lG l Γ}
→ lF ≤ l
→ lG ≤ l
→ Γ ⊢ F ^ [ rF , ι lF ]
→ Γ ⊢ f ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]
→ Γ ⊢ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]
→ Function f
→ Function g
→ Γ ∙ F ^ [ rF , ι lF ] ⊢ wk1 f ∘ var 0 ^ l ≅ wk1 g ∘ var 0 ^ l ∷ G ^ [ ! , ι lG ]
→ Γ ⊢ f ≅ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]
-- Variable reflexivity
~-var : ∀ {x A Γ r} → Γ ⊢ var x ∷ A ^ r → Γ ⊢ var x ~ var x ∷ A ^ r
-- Application congurence
~-app : ∀ {a b f g F G rF lF lG l Γ}
→ Γ ⊢ f ~ g ∷ Π F ^ rF ° lF ▹ G ° lG ° l ^ [ ! , ι l ]
→ Γ ⊢ a ≅ b ∷ F ^ [ rF , ι lF ]
→ Γ ⊢ f ∘ a ^ l ~ g ∘ b ^ l ∷ G [ a ] ^ [ ! , ι lG ]
-- Natural recursion congurence
~-natrec : ∀ {z z′ s s′ n n′ F F′ l Γ}
→ Γ ∙ ℕ ^ [ ! , ι ⁰ ] ⊢ F ≅ F′ ^ [ ! , ι l ]
→ Γ ⊢ z ≅ z′ ∷ F [ zero ] ^ [ ! , ι l ]
→ Γ ⊢ s ≅ s′ ∷ Π ℕ ^ ! ° ⁰ ▹ (F ^ ! ° l ▹▹ F [ suc (var 0) ]↑ ° l ° l ) ° l ° l ^ [ ! , ι l ]
→ Γ ⊢ n ~ n′ ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ natrec l F z s n ~ natrec l F′ z′ s′ n′ ∷ F [ n ] ^ [ ! , ι l ]
-- Empty recursion congurence
~-Emptyrec : ∀ {e e′ F F′ l lEmpty Γ}
→ Γ ⊢ F ≅ F′ ^ [ ! , ι l ]
→ Γ ⊢ e ∷ Empty lEmpty ^ [ % , ι lEmpty ]
→ Γ ⊢ e′ ∷ Empty lEmpty ^ [ % , ι lEmpty ]
→ Γ ⊢ Emptyrec l lEmpty F e ~ Emptyrec l lEmpty F′ e′ ∷ F ^ [ ! , ι l ]
-- Id congruences
~-Id : ∀ {A A' l t t' u u' Γ}
→ Γ ⊢ A ~ A' ∷ Univ ! l ^ [ ! , next l ]
→ Γ ⊢ t ≅ t' ∷ A ^ [ ! , ι l ]
→ Γ ⊢ u ≅ u' ∷ A ^ [ ! , ι l ]
→ Γ ⊢ Id A t u ~ Id A' t' u' ∷ SProp l ^ [ ! , next l ]
~-Idℕ : ∀ {t t' u u' Γ}
→ ⊢ Γ
→ Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ u ≅ u' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ Id ℕ t u ~ Id ℕ t' u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-Idℕ0 : ∀ {u u' Γ}
→ ⊢ Γ
→ Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ Id ℕ zero u ~ Id ℕ zero u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-IdℕS : ∀ {t t' u u' Γ}
→ ⊢ Γ
→ Γ ⊢ t ≅ t' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ u ~ u' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ Id ℕ (suc t) u ~ Id ℕ (suc t') u' ∷ SProp ⁰ ^ [ ! , next ⁰ ]
~-IdU : ∀ {t t' u u' Γ} →
let l = ⁰ in
let l' = ¹ in
⊢ Γ
→ Γ ⊢ t ~ t' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ u ≅ u' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ Id (U l) t u ~ Id (U l) t' u' ∷ SProp l' ^ [ ! , next l' ]
~-IdUℕ : ∀ {u u' Γ}
→ ⊢ Γ
→ Γ ⊢ u ~ u' ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Id (U ⁰) ℕ u ~ Id (U ⁰) ℕ u' ∷ SProp ¹ ^ [ ! , next ¹ ]
~-IdUΠ : ∀ {A rA B A' B' u u' Γ} →
let l = ⁰ in
let l' = ¹ in
Γ ⊢ Π A ^ rA ° ⁰ ▹ B ° ⁰ ° ⁰ ≅ Π A' ^ rA ° ⁰ ▹ B' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ u ~ u' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ Id (U l) (Π A ^ rA ° l ▹ B ° l ° ⁰ ) u ~ Id (U l) (Π A' ^ rA ° l ▹ B' ° l ° ⁰) u' ∷ SProp l' ^ [ ! , next l' ]
-- cast congruences
~-cast : ∀ {A A' B B' e e' t t' Γ} →
let l = ⁰ in
Γ ⊢ A ~ A' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ B ≅ B' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ t ≅ t' ∷ A ^ [ ! , ι l ]
→ Γ ⊢ e ∷ (Id (U ⁰) A B) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) A' B') ^ [ % , next ⁰ ]
→ Γ ⊢ cast l A B e t ~ cast l A' B' e' t' ∷ B ^ [ ! , ι l ]
~-castℕ : ∀ {B B' e e' t t' Γ}
→ ⊢ Γ
→ Γ ⊢ B ~ B' ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ t ≅ t' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ e ∷ (Id (U ⁰) ℕ B) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) ℕ B') ^ [ % , next ⁰ ]
→ Γ ⊢ cast ⁰ ℕ B e t ~ cast ⁰ ℕ B' e' t' ∷ B ^ [ ! , ι ⁰ ]
~-castℕℕ : ∀ {e e' t t' Γ}
→ ⊢ Γ
→ Γ ⊢ t ~ t' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ e ∷ (Id (U ⁰) ℕ ℕ) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) ℕ ℕ) ^ [ % , next ⁰ ]
→ Γ ⊢ cast ⁰ ℕ ℕ e t ~ cast ⁰ ℕ ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castΠ : ∀ {A A' rA P P' B B' e e' t t' Γ} →
let l = ⁰ in
Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ≅ Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ B ~ B' ∷ U l ^ [ ! , next l ]
→ Γ ⊢ t ≅ t' ∷ Π A ^ rA ° l ▹ P ° l ° l ^ [ ! , ι l ]
→ Γ ⊢ e ∷ (Id (U ⁰) (Π A ^ rA ° l ▹ P ° l ° l) B) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) (Π A' ^ rA ° l ▹ P' ° l ° l) B') ^ [ % , next ⁰ ]
→ Γ ⊢ cast l (Π A ^ rA ° l ▹ P ° l ° l) B e t ~ cast l (Π A' ^ rA ° l ▹ P' ° l ° l) B' e' t' ∷ B ^ [ ! , ι l ]
~-castℕΠ : ∀ {A A' rA P P' e e' t t' Γ}
→ Γ ⊢ A ∷ Univ rA ⁰ ^ [ ! , next ⁰ ]
→ Γ ∙ A ^ [ rA , ι ⁰ ] ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ≅ Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ t ≅ t' ∷ ℕ ^ [ ! , ι ⁰ ]
→ Γ ⊢ e ∷ (Id (U ⁰) ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ cast ⁰ ℕ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) e t ~ cast ⁰ ℕ (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) e' t' ∷ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ^ [ ! , ι ⁰ ]
~-castΠℕ : ∀ {A A' rA P P' e e' t t' Γ} →
let l = ⁰ in
Γ ⊢ A ∷ Univ rA l ^ [ ! , next l ]
→ Γ ∙ A ^ [ rA , ι l ] ⊢ P ∷ U l ^ [ ! , next l ]
→ Γ ⊢ Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰ ≅ Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ t ≅ t' ∷ (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ^ [ ! , ι l ]
→ Γ ⊢ e ∷ (Id (U ⁰) (Π A ^ rA ° l ▹ P ° l ° ⁰) ℕ) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) (Π A' ^ rA ° l ▹ P' ° l ° ⁰) ℕ) ^ [ % , next ⁰ ]
→ Γ ⊢ cast l (Π A ^ rA ° ⁰ ▹ P ° ⁰ ° ⁰) ℕ e t ~ cast l (Π A' ^ rA ° ⁰ ▹ P' ° ⁰ ° ⁰) ℕ e' t' ∷ ℕ ^ [ ! , ι ⁰ ]
~-castΠΠ%! : ∀ {A A' P P' B B' Q Q' e e' t t' Γ}
→ Γ ⊢ A ∷ Univ % ⁰ ^ [ ! , next ⁰ ]
→ Γ ∙ A ^ [ % , ι ⁰ ] ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ ≅ Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ B ∷ Univ ! ⁰ ^ [ ! , next ⁰ ]
→ Γ ∙ B ^ [ ! , ι ⁰ ] ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ ≅ Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ t ≅ t' ∷ Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
→ Γ ⊢ e ∷ (Id (U ⁰) (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ cast ⁰ (Π A ^ % ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ (Π A' ^ % ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ ! ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ ! ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-castΠΠ!% : ∀ {A A' P P' B B' Q Q' e e' t t' Γ}
→ Γ ⊢ A ∷ Univ ! ⁰ ^ [ ! , next ⁰ ]
→ Γ ∙ A ^ [ ! , ι ⁰ ] ⊢ P ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ ≅ Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ B ∷ Univ % ⁰ ^ [ ! , next ⁰ ]
→ Γ ∙ B ^ [ % , ι ⁰ ] ⊢ Q ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ ≅ Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰ ∷ U ⁰ ^ [ ! , next ⁰ ]
→ Γ ⊢ t ≅ t' ∷ Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
→ Γ ⊢ e ∷ (Id (U ⁰) (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ e' ∷ (Id (U ⁰) (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰)) ^ [ % , next ⁰ ]
→ Γ ⊢ cast ⁰ (Π A ^ ! ° ⁰ ▹ P ° ⁰ ° ⁰) (Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰) e t ~ cast ⁰ (Π A' ^ ! ° ⁰ ▹ P' ° ⁰ ° ⁰) (Π B' ^ % ° ⁰ ▹ Q' ° ⁰ ° ⁰) e' t' ∷ Π B ^ % ° ⁰ ▹ Q ° ⁰ ° ⁰ ^ [ ! , ι ⁰ ]
~-irrelevance : ∀ {n n′ A l Γ} → Γ ⊢ n ∷ A ^ [ % , l ] → Γ ⊢ n′ ∷ A ^ [ % , l ]
→ Γ ⊢ n ~ n′ ∷ A ^ [ % , l ]
-- Composition of universe and generic equality compatibility
~-to-≅ : ∀ {t u r l Γ} → Γ ⊢ t ~ u ∷ (Univ r l) ^ [ ! , next l ] → Γ ⊢ t ≅ u ^ [ r , ι l ]
~-to-≅ t~u = ≅-univ (~-to-≅ₜ t~u)
|
{
"alphanum_fraction": 0.2944239705,
"avg_line_length": 41.1947194719,
"ext": "agda",
"hexsha": "b891f4b16434d38e082b8131a19f591d3d5df087",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_line_length": 193,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/EqualityRelation.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 6374,
"size": 12482
}
|
{-# OPTIONS --without-K #-}
open import container.core
module container.m.coalgebra {li la lb}
(c : Container li la lb) where
open import level
open import sum
open import function as F hiding (_∘_ ; module _≅_ ; _≅_ ; iso ; ≅⇒≡)
open import equality
open import hott
------------------------------------------------------------------------------
open Container c
-- Definition 3 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
Coalg : ∀ ℓ → Set _
Coalg ℓ = Σ (I → Set ℓ) λ X → X →ⁱ F X
carrier : ∀ {ℓ} → Coalg ℓ → I → Set ℓ
carrier (X , _) = X
IsMor : ∀ {ℓ₁ ℓ₂}(𝓧 : Coalg ℓ₁)(𝓨 : Coalg ℓ₂)
→ (carrier 𝓧 →ⁱ carrier 𝓨) → Set _
IsMor (X , θ) (Y , ψ) f = ψ ∘ⁱ f ≡ imap f ∘ⁱ θ
_⇒_ : ∀ {ℓ₁ ℓ₂} → Coalg ℓ₁ → Coalg ℓ₂ → Set _
𝓧 ⇒ 𝓨 = Σ (carrier 𝓧 →ⁱ carrier 𝓨) (IsMor 𝓧 𝓨)
idf : ∀ {ℓ} → (𝓧 : Coalg ℓ) → 𝓧 ⇒ 𝓧
idf 𝓧 = (λ i x → x) , refl
_∘_ : ∀ {ℓ} → ⦃ 𝓧 𝓨 𝓩 : Coalg ℓ ⦄ → 𝓨 ⇒ 𝓩 → 𝓧 ⇒ 𝓨 → 𝓧 ⇒ 𝓩
(g , coh₁) ∘ (f , coh₂) = g ∘ⁱ f , funextⁱ (λ i x → funext-invⁱ coh₁ i (f i x)
· ap (imap g i) (funext-invⁱ coh₂ i x))
private
subst-coerce : ∀ {a b} {A : Set a} {B : A → Set b}
{x y : A} (p : x ≡ y) {u : B x}
→ subst B p u ≡ coerce (ap B p) u
subst-coerce refl = refl
app= : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x} → f ≡ g
→(x : A) → f x ≡ g x
app= p x = ap (λ u → u x) p
app=-β : ∀ {a b} {A : Set a} {B : A → Set b} {f g : (x : A) → B x}
(p : ∀ x → f x ≡ g x) (x : A)
→ app= (funext p) x ≡ p x
app=-β {B = B} p x = helper (funext p) x
· app= (F._≅_.iso₁ strong-funext-iso p) x
where helper : ∀ {f g : ∀ x → B x} (p : f ≡ g) x → app= p x ≡ funext-inv p x
helper refl x = refl
abstract
ua : ∀ {i}{X Y : Set i} → X F.≅ Y → X ≡ Y
ua = F.≅⇒≡
coerce-β : ∀ {a} {X Y : Set a} → (e : X F.≅ Y)
→ ∀ x → coerce (ua e) x ≡ apply e x
coerce-β e x = app= (uni-coherence (≅⇒≈ e)) x
substⁱ-lemma : ∀ {ℓ} {X Y : I → Set ℓ} {f : X →ⁱ F X} {g : Y →ⁱ F Y}
→ (p : X ≡ Y)
→ (∀ i x → subst (λ Z → F Z i) p (f i x)
≡ g i (subst (λ Z → Z i) p x))
→ subst (λ Z → Z →ⁱ F Z) p f ≡ g
substⁱ-lemma refl = funextⁱ
imap-subst : ∀ {ℓ} {X Y : I → Set ℓ} (p : X ≡ Y)
→ imap (λ i → subst (λ Z → Z i) p) ≡ (λ i → subst (λ Z → F Z i) p)
imap-subst refl = refl
record _≅_ {ℓ} (𝓧 𝓨 : Coalg ℓ) : Set (lsuc $ ℓ ⊔ li ⊔ la ⊔ lb) where
constructor iso
field
f : 𝓧 ⇒ 𝓨
g : 𝓨 ⇒ 𝓧
f-g : f ∘ g ≡ idf 𝓨
g-f : g ∘ f ≡ idf 𝓧
≅⇒≡ : ∀ {ℓ} {𝓧 𝓨 : Coalg ℓ} → 𝓧 ≅ 𝓨 → 𝓧 ≡ 𝓨
≅⇒≡ {𝓧 = X , θ} {𝓨 = Y , ψ} 𝓧≅𝓨 = unapΣ (π₁≡ , π₂≡)
where open _≅_ 𝓧≅𝓨
X≅Y : ∀ i → X i F.≅ Y i
X≅Y i = F.iso (proj₁ f i) (proj₁ g i)
(funext-invⁱ (ap proj₁ g-f) i)
(funext-invⁱ (ap proj₁ f-g) i)
π₁≡ : X ≡ Y
π₁≡ = funext λ i → ua (X≅Y i)
π₂≡ : subst (λ Z → Z →ⁱ F Z) π₁≡ θ ≡ ψ
π₂≡ = substⁱ-lemma π₁≡ λ i x →
app= (lemma₂ i) _
· sym (funext-invⁱ (proj₂ f) i x)
· ap (ψ i) (sym (lemma₁ i x))
where lemma₁ : ∀ i x → subst (λ Z → Z i) π₁≡ x ≡ proj₁ f i x
lemma₁ i x = subst-coerce π₁≡
· ap (λ u → coerce u x) (app=-β _ i)
· coerce-β (X≅Y i) _
lemma₂ : ∀ i → subst (λ Z → F Z i) π₁≡ ≡ imap (proj₁ f) i
lemma₂ i = sym $ funext (hmap (λ i x → sym (lemma₁ i x)) i)
· app= (imap-subst π₁≡) i
IsFinal : ∀ {ℓ} → Coalg ℓ → Set _
IsFinal {ℓ} 𝓧 = ∀ (𝓨 : Coalg ℓ) → contr (𝓨 ⇒ 𝓧)
Final : ∀ ℓ → Set _
Final ℓ = Σ (Coalg ℓ) IsFinal
prop-IsFinal : ∀ {ℓ} (𝓧 : Coalg ℓ) → prop (IsFinal 𝓧)
prop-IsFinal 𝓧 = h1⇒prop (Π-level (λ 𝓨 → contr-h1 _))
-- Lemma 5 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
Final-prop : ∀ {ℓ} → prop (Final ℓ)
Final-prop (𝓧 , IsFinal-𝓧) (𝓨 , IsFinal-𝓨) =
unapΣ (𝓧≡𝓨 , prop-IsFinal 𝓨 _ _)
where 𝓧≡𝓨 : 𝓧 ≡ 𝓨
𝓧≡𝓨 = ≅⇒≡ $ iso (proj₁ (IsFinal-𝓨 𝓧)) (proj₁ (IsFinal-𝓧 𝓨))
(contr⇒prop (IsFinal-𝓨 𝓨) _ _)
(contr⇒prop (IsFinal-𝓧 𝓧) _ _)
|
{
"alphanum_fraction": 0.4401709402,
"avg_line_length": 35.1,
"ext": "agda",
"hexsha": "a9153a2b35487fa076f15bc28a686bee3e6864a2",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/m/coalgebra.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/m/coalgebra.agda",
"max_line_length": 80,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/m/coalgebra.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 1982,
"size": 4212
}
|
{-# OPTIONS --without-K --safe #-}
-- https://personal.cis.strath.ac.uk/conor.mcbride/pub/DepRep/DepRep.pdf
module Experiment.Outrageous.#01 where
open import Data.Unit using (⊤)
open import Data.Product using (_×_) renaming (_,_ to _,,_)
open import Data.Nat using (ℕ)
infixl 30 _,_
infixr 40 _:→_
-- Star
data St : Set where
:ℕ : St
_:→_ : St → St → St
data Cx : Set where
ε : Cx
_,_ : Cx → St → Cx
data _∈_ : St → Cx → Set where
top : ∀ {Γ τ} → τ ∈ Γ , τ
pop : ∀ {Γ σ τ} → τ ∈ Γ → τ ∈ Γ , σ
data _⊢_ : Cx → St → Set where
var : ∀ {Γ τ} → τ ∈ Γ → Γ ⊢ τ
lam : ∀ {Γ σ τ} → Γ , σ ⊢ τ → Γ ⊢ σ :→ τ
app : ∀ {Γ σ τ} → Γ ⊢ σ :→ τ → Γ ⊢ σ → Γ ⊢ τ
⟦_⟧St : St → Set
⟦ :ℕ ⟧St = ℕ
⟦ σ :→ τ ⟧St = ⟦ σ ⟧St → ⟦ τ ⟧St
⟦_⟧Cx : Cx → Set
⟦ ε ⟧Cx = ⊤
⟦ Γ , σ ⟧Cx = ⟦ Γ ⟧Cx × ⟦ σ ⟧St
⟦_⟧∈ : ∀ {Γ τ} → τ ∈ Γ → ⟦ Γ ⟧Cx → ⟦ τ ⟧St
⟦ top ⟧∈ (γ ,, t) = t
⟦ pop i ⟧∈ (γ ,, s) = ⟦ i ⟧∈ γ
⟦_⟧⊢ : ∀ {Γ τ} → Γ ⊢ τ → ⟦ Γ ⟧Cx → ⟦ τ ⟧St
⟦ var i ⟧⊢ γ = ⟦ i ⟧∈ γ
⟦ lam t ⟧⊢ γ = λ s → ⟦ t ⟧⊢ (γ ,, s)
⟦ app f a ⟧⊢ γ = ⟦ f ⟧⊢ γ (⟦ a ⟧⊢ γ)
|
{
"alphanum_fraction": 0.4437022901,
"avg_line_length": 21.8333333333,
"ext": "agda",
"hexsha": "b4ac295c1488c9c4855c6ed0f4df777ccd6a9df1",
"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": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Outrageous/#01.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"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": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Outrageous/#01.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Outrageous/#01.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 565,
"size": 1048
}
|
------------------------------------------------------------------------
-- Alternative functional semantics for an untyped λ-calculus with
-- constants
------------------------------------------------------------------------
-- I noted that the compiler correctness proof in
-- Lambda.Closure.Functional might be easier if the semantics was
-- defined using continuation-passing style, so I decided to try this
-- out. The proof at the end of this module /is/ slightly shorter, but
-- the continuation-passing definition of the semantics is quite
-- awkward (due to the limitations imposed by Agda). Furthermore it
-- seemed to me as if the soundness proofs in
-- Lambda.Closure.Equivalence would be harder to prove using this
-- formulation of the semantics.
module Lambda.Closure.Functional.Alternative where
open import Category.Monad
open import Category.Monad.Partiality as Partiality
using (_⊥; never; Kind; OtherKind)
open import Codata.Musical.Notation
open import Data.List hiding (lookup)
open import Data.Maybe
import Data.Maybe.Categorical as Maybe
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Function
open import Level
open import Relation.Binary using (module Preorder)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open Partiality._⊥
open Partiality.Kind
private
open module E {A : Set} = Partiality.Equality (_≡_ {A = A})
open module R {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
open import Lambda.Syntax
open Closure Tm
open import Lambda.VirtualMachine
open Functional
private
module VM = Closure Code
------------------------------------------------------------------------
-- A monad with partiality and failure
PF : RawMonad {f = zero} (_⊥ ∘ Maybe)
PF = Maybe.monadT Partiality.monad
module PF where
open RawMonad PF public
fail : {A : Set} → Maybe A ⊥
fail = now nothing
open PF
------------------------------------------------------------------------
-- Semantics
module Workaround₁ where
-- This module provides a workaround for the limitations of
-- guardedness.
mutual
data Maybe_⊥P (A : Set) : Set where
⌈_⌉ : (x : Maybe A ⊥) → Maybe A ⊥P
later : (x : ∞ (Maybe A ⊥P)) → Maybe A ⊥P
⟦_⟧P : ∀ {n} (t : Tm n) (ρ : Env n) (k : Value → Maybe A ⊥W) →
Maybe A ⊥P
data Maybe_⊥W (A : Set) : Set where
⌈_⌉ : (x : Maybe A ⊥) → Maybe A ⊥W
later : (x : Maybe A ⊥P) → Maybe A ⊥W
mutual
-- The semantics, in slightly scrambled form.
infix 5 _∙W_
⟦_⟧W : ∀ {A n} → Tm n → Env n → (Value → Maybe A ⊥W) → Maybe A ⊥W
⟦ con i ⟧W ρ k = k (con i)
⟦ var x ⟧W ρ k = k (lookup ρ x)
⟦ ƛ t ⟧W ρ k = k (ƛ t ρ)
⟦ t₁ · t₂ ⟧W ρ k = ⟦ t₁ ⟧W ρ (λ v₁ →
⟦ t₂ ⟧W ρ (λ v₂ →
(v₁ ∙W v₂) k))
_∙W_ : ∀ {A} → Value → Value → (Value → Maybe A ⊥W) → Maybe A ⊥W
(con i ∙W v₂) k = ⌈ fail ⌉
(ƛ t₁ ρ ∙W v₂) k = later (⟦ t₁ ⟧P (v₂ ∷ ρ) k)
-- Interpretation of the definitions above.
whnf : ∀ {A} → Maybe A ⊥P → Maybe A ⊥W
whnf ⌈ x ⌉ = ⌈ x ⌉
whnf (later x) = later (♭ x)
whnf (⟦ t ⟧P ρ k) = ⟦ t ⟧W ρ k
mutual
⟪_⟫W : ∀ {A} → Maybe A ⊥W → Maybe A ⊥
⟪ ⌈ x ⌉ ⟫W = x
⟪ later x ⟫W = later (♯ ⟪ x ⟫P)
⟪_⟫P : ∀ {A} → Maybe A ⊥P → Maybe A ⊥
⟪ x ⟫P = ⟪ whnf x ⟫W
-- The actual semantics. Note that this definition gives us
-- determinism "for free".
infix 5 _∙_
⟦_⟧ : ∀ {A n} → Tm n → Env n → (Value → Maybe A ⊥) → Maybe A ⊥
⟦ t ⟧ ρ k = ⟪ ⟦ t ⟧P ρ (λ v → ⌈ k v ⌉) ⟫P
where open Workaround₁
_∙_ : ∀ {A} → Value → Value → (Value → Maybe A ⊥) → Maybe A ⊥
(v₁ ∙ v₂) k = ⟪ (v₁ ∙W v₂) (λ v → ⌈ k v ⌉) ⟫W
where open Workaround₁
-- ⟦_⟧ and _∙_ preserve equality of their continuations.
module Workaround₂ {k : Kind} where
open Workaround₁
mutual
infix 4 _≈P_ _≈W_
data _≈P_ {A : Set} : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel k x y) → x ≈P y
later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y
⟦_⟧W-congP : ∀ {n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥W}
(k₁≈k₂ : ∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ ⟦ t ⟧W ρ k₁ ⟫W ≈P ⟪ ⟦ t ⟧W ρ k₂ ⟫W
data _≈W_ {A : Set} : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel k x y) → x ≈W y
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
mutual
⟦_⟧W-congW : ∀ {A n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥W} →
(∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ ⟦ t ⟧W ρ k₁ ⟫W ≈W ⟪ ⟦ t ⟧W ρ k₂ ⟫W
⟦ con i ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (con i)
⟦ var x ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (lookup ρ x)
⟦ ƛ t ⟧W-congW ρ k₁≈k₂ = k₁≈k₂ (ƛ t ρ)
⟦ t₁ · t₂ ⟧W-congW ρ k₁≈k₂ = ⟦ t₁ ⟧W-congW ρ (λ v₁ →
⟦ t₂ ⟧W-congW ρ (λ v₂ →
(v₁ ∙W v₂ -congW) k₁≈k₂))
_∙W_-congW : ∀ {A} v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥W} →
(∀ v → ⟪ k₁ v ⟫W ≈W ⟪ k₂ v ⟫W) →
⟪ (v₁ ∙W v₂) k₁ ⟫W ≈W ⟪ (v₁ ∙W v₂) k₂ ⟫W
(con i ∙W v₂ -congW) k₁≈k₂ = ⌈ fail ∎ ⌉
(ƛ t₁ ρ ∙W v₂ -congW) k₁≈k₂ = later (⟦ t₁ ⟧W-congP (v₂ ∷ ρ) k₁≈k₂)
whnf≈ : ∀ {A} {x y : Maybe A ⊥} → x ≈P y → x ≈W y
whnf≈ ⌈ x≈y ⌉ = ⌈ x≈y ⌉
whnf≈ (later x≈y) = later (♭ x≈y)
whnf≈ (⟦ t ⟧W-congP ρ k₁≈k₂) = ⟦ t ⟧W-congW ρ k₁≈k₂
mutual
soundW : ∀ {A} {x y : Maybe A ⊥} → x ≈W y → Rel k x y
soundW ⌈ x≈y ⌉ = x≈y
soundW (later x≈y) = later (♯ soundP x≈y)
soundP : ∀ {A} {x y : Maybe A ⊥} → x ≈P y → Rel k x y
soundP x≈y = soundW (whnf≈ x≈y)
⟦_⟧-cong : ∀ {k A n} t (ρ : Env n) {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → Rel k (k₁ v) (k₂ v)) →
Rel k (⟦ t ⟧ ρ k₁) (⟦ t ⟧ ρ k₂)
⟦ t ⟧-cong ρ k₁≈k₂ = soundW (⟦ t ⟧W-congW ρ (λ v → ⌈ k₁≈k₂ v ⌉))
where open Workaround₂
_∙_-cong : ∀ {k A} v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → Rel k (k₁ v) (k₂ v)) →
Rel k ((v₁ ∙ v₂) k₁) ((v₁ ∙ v₂) k₂)
(v₁ ∙ v₂ -cong) k₁≈k₂ = soundW ((v₁ ∙W v₂ -congW) (λ v → ⌈ k₁≈k₂ v ⌉))
where open Workaround₂
-- ⟦_⟧ and _∙_ satisfy their intended defining equations.
sem-con : ∀ {A n} i {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ con i ⟧ ρ k ≅ k (con i)
sem-con i {k = k} = k (con i) ∎
sem-var : ∀ {A n} x {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ var x ⟧ ρ k ≅ k (lookup ρ x)
sem-var x {ρ} {k} = k (lookup ρ x) ∎
sem-ƛ : ∀ {A n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ ƛ t ⟧ ρ k ≅ k (ƛ t ρ)
sem-ƛ t {ρ} {k} = k (ƛ t ρ) ∎
sem-· : ∀ {A n} t₁ t₂ {ρ : Env n} {k : Value → Maybe A ⊥} →
⟦ t₁ · t₂ ⟧ ρ k ≅ (⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k)
sem-· t₁ t₂ {ρ} {k} = soundW $
⟦ t₁ ⟧W-congW ρ λ v₁ →
⟦ t₂ ⟧W-congW ρ λ v₂ →
⌈ (v₁ ∙ v₂) k ∎ ⌉
where open Workaround₂
app-con : ∀ {A} i v₂ {k : Value → Maybe A ⊥} →
(con i ∙ v₂) k ≅ fail
app-con i v₂ = fail ∎
app-ƛ : ∀ {A n} t₁ (ρ : Env n) v₂ {k : Value → Maybe A ⊥} →
(ƛ t₁ ρ ∙ v₂) k ≅ later (♯ ⟦ t₁ ⟧ (v₂ ∷ ρ) k)
app-ƛ t₁ ρ v₂ {k} = later (♯ (⟦ t₁ ⟧ (v₂ ∷ ρ) k ∎))
-- ⟦_⟧ and _∙_ are the unique solutions to the system of equations
-- which is intended to define them. I have stated this result using
-- strong equality, which is (more or less) the kind of equality you
-- get from a definition. I tried using weak equality instead, but
-- this turned out to make the proof tricky (due to the lack of
-- transitivity).
module Unique
{A : Set}
(⟪_⟫ : ∀ {n} t (ρ : Env n) (k : Value → Maybe A ⊥) → Maybe A ⊥)
(_○_ : Value → Value → (Value → Maybe A ⊥) → Maybe A ⊥)
(⟪con⟫ : ∀ {n} i {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ con i ⟫ ρ k ≅ k (con i))
(⟪var⟫ : ∀ {n} x {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ var x ⟫ ρ k ≅ k (lookup ρ x))
(⟪ƛ⟫ : ∀ {n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ ƛ t ⟫ ρ k ≅ k (ƛ t ρ))
(⟪·⟫ : ∀ {n} t₁ t₂ {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ t₁ · t₂ ⟫ ρ k ≅ (⟪ t₁ ⟫ ρ λ v₁ → ⟪ t₂ ⟫ ρ λ v₂ → (v₁ ○ v₂) k))
(con○ : ∀ i v₂ {k : Value → Maybe A ⊥} →
(con i ○ v₂) k ≅ fail)
(ƛ○ : ∀ {n} t₁ (ρ : Env n) v₂ {k : Value → Maybe A ⊥} →
(ƛ t₁ ρ ○ v₂) k ≅ later (♯ ⟪ t₁ ⟫ (v₂ ∷ ρ) k))
where
infix 4 _≅P_ _≅W_
infixr 2 _≅⟨_⟩P_ _≅⟨_⟩W_ _≅⟪_⟫P_ _≅⟪_⟫W_
mutual
data _≅P_ : Maybe A ⊥ → Maybe A ⊥ → Set where
_≅⟨_⟩P_ : ∀ x {y z} (x≅y : x ≅ y) (y≅z : y ≅P z) → x ≅P z
_≅⟪_⟫P_ : ∀ x {y z} (x≅y : x ≅P y) (y≅z : y ≅ z) → x ≅P z
semP : ∀ {n} t {ρ : Env n} {k₁ k₂ : Value → Maybe A ⊥} →
(k₁≅k₂ : ∀ v → k₁ v ≅W k₂ v) →
⟪ t ⟫ ρ k₁ ≅P ⟦ t ⟧ ρ k₂
data _≅W_ : Maybe A ⊥ → Maybe A ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≅y : x ≅ y) → x ≅W y
later : ∀ {x y} (x≅y : ♭ x ≅P ♭ y) → later x ≅W later y
_≅⟨_⟩W_ : ∀ x {y z} → x ≅ y → y ≅W z → x ≅W z
_ ≅⟨ x≅y ⟩W ⌈ y≅z ⌉ = ⌈ _ ≅⟨ x≅y ⟩ y≅z ⌉
._ ≅⟨ later x≅y ⟩W later y≅z = later (_ ≅⟨ ♭ x≅y ⟩P y≅z)
_≅⟪_⟫W_ : ∀ x {y z} → x ≅W y → y ≅ z → x ≅W z
_ ≅⟪ ⌈ x≅y ⌉ ⟫W y≅z = ⌈ _ ≅⟨ x≅y ⟩ y≅z ⌉
._ ≅⟪ later x≅y ⟫W later y≅z = later (_ ≅⟪ x≅y ⟫P ♭ y≅z)
mutual
semW : ∀ {n} t {ρ : Env n} {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → k₁ v ≅W k₂ v) → ⟪ t ⟫ ρ k₁ ≅W ⟦ t ⟧ ρ k₂
semW (con i) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ con i ⟫ ρ k₁ ≅⟨ ⟪con⟫ i ⟩W
k₁ (con i) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (con i) ∎
semW (var x) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ var x ⟫ ρ k₁ ≅⟨ ⟪var⟫ x ⟩W
k₁ (lookup ρ x) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (lookup ρ x) ∎
semW (ƛ t) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ ƛ t ⟫ ρ k₁ ≅⟨ ⟪ƛ⟫ t ⟩W
k₁ (ƛ t ρ) ≅⟪ k₁≅k₂ _ ⟫W
k₂ (ƛ t ρ) ∎
semW (t₁ · t₂) {ρ} {k₁} {k₂} k₁≅k₂ =
⟪ t₁ · t₂ ⟫ ρ k₁ ≅⟨ ⟪·⟫ t₁ t₂ ⟩W
(⟪ t₁ ⟫ ρ λ v₁ → ⟪ t₂ ⟫ ρ λ v₂ → (v₁ ○ v₂) k₁) ≅⟪ semW t₁ (λ v₁ → semW t₂ (λ v₂ → appW v₁ v₂ k₁≅k₂)) ⟫W
(⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k₂) ≅⟨ sym $ sem-· t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ k₂ ∎
appW : ∀ v₁ v₂ {k₁ k₂ : Value → Maybe A ⊥} →
(∀ v → k₁ v ≅W k₂ v) → (v₁ ○ v₂) k₁ ≅W (v₁ ∙ v₂) k₂
appW (con i) v₂ {k₁} {k₂} k₁≅k₂ =
⌈ (con i ○ v₂) k₁ ≅⟨ con○ i v₂ ⟩
fail ∎ ⌉
appW (ƛ t₁ ρ) v₂ {k₁} {k₂} k₁≅k₂ =
(ƛ t₁ ρ ○ v₂) k₁ ≅⟨ ƛ○ t₁ ρ v₂ ⟩W
later _ ≅⟪ later (semP t₁ k₁≅k₂) ⟫W
(ƛ t₁ ρ ∙ v₂) k₂ ∎
whnf : ∀ {x y} → x ≅P y → x ≅W y
whnf (x ≅⟨ x≅y ⟩P y≅z) = x ≅⟨ x≅y ⟩W whnf y≅z
whnf (x ≅⟪ x≅y ⟫P y≅z) = x ≅⟪ whnf x≅y ⟫W y≅z
whnf (semP t k₁≅k₂) = semW t k₁≅k₂
mutual
soundW : ∀ {x y} → x ≅W y → x ≅ y
soundW ⌈ x≅y ⌉ = x≅y
soundW (later x≅y) = later (♯ soundP x≅y)
soundP : ∀ {x y} → x ≅P y → x ≅ y
soundP x≅y = soundW (whnf x≅y)
sem : ∀ {n} t {ρ : Env n} {k : Value → Maybe A ⊥} →
⟪ t ⟫ ρ k ≅ ⟦ t ⟧ ρ k
sem t {k = k} = soundW (semW t (λ v → ⌈ k v ∎ ⌉))
dot : ∀ v₁ v₂ {k : Value → Maybe A ⊥} →
(v₁ ○ v₂) k ≅ (v₁ ∙ v₂) k
dot v₁ v₂ {k} = soundW (appW v₁ v₂ (λ v → ⌈ k v ∎ ⌉))
------------------------------------------------------------------------
-- Example
Ω-loops : ⟦ Ω ⟧ [] return ≈ never
Ω-loops = later (♯ Ω-loops)
------------------------------------------------------------------------
-- Compiler correctness
module Correctness {k : OtherKind} where
infix 4 _≈P_ _≈W_
infixr 2 _≡⟨_⟩W_ _≈⟨_⟩P_ _≈⟨_⟩W_
mutual
data _≈P_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
_≈⟨_⟩P_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅ z) → x ≈P z
correct :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(hyp : ∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩
≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈P ⟦ t ⟧ ρ k
data _≈W_ : Maybe VM.Value ⊥ → Maybe VM.Value ⊥ → Set where
⌈_⌉ : ∀ {x y} (x≈y : Rel (other k) x y) → x ≈W y
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
laterˡ : ∀ {x y} (x≈y : ♭ x ≈W y) → later x ≈W y
_≡⟨_⟩W_ : ∀ x {y z} → x ≡ y → y ≈W z → x ≈W z
_ ≡⟨ P.refl ⟩W y≈z = y≈z
_≈⟨_⟩W_ : ∀ x {y z} → x ≈W y → y ≅ z → x ≈W z
._ ≈⟨ later x≈y ⟩W later y≅z = later (_ ≈⟨ x≈y ⟩P ♭ y≅z)
._ ≈⟨ laterˡ x≈y ⟩W y≅z = laterˡ (_ ≈⟨ x≈y ⟩W y≅z)
_ ≈⟨ ⌈ x≈y ⌉ ⟩W y≅z = ⌈ trans x≈y (Partiality.≅⇒ y≅z) ⌉
where trans = Preorder.trans (Partiality.preorder P.isPreorder _)
mutual
correctW :
∀ {n} t {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ comp t c , s , comp-env ρ ⟩ ≈W ⟦ t ⟧ ρ k
correctW (con i) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (Lambda.Syntax.Closure.con i) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (con i) ⟩W
k (con i) ∎)
correctW (var x) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (lookup (comp-env ρ) x) ∷ s , comp-env ρ ⟩ ≡⟨ P.cong (λ v → exec ⟨ c , val v ∷ s , comp-env ρ ⟩) $ lookup-hom x ρ ⟩W
exec ⟨ c , val (comp-val (lookup ρ x)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (lookup ρ x) ⟩W
k (lookup ρ x) ∎)
correctW (ƛ t) {ρ} {c} {s} {k} hyp = laterˡ (
exec ⟨ c , val (comp-val (ƛ t ρ)) ∷ s , comp-env ρ ⟩ ≈⟨ hyp (ƛ t ρ) ⟩W
k (ƛ t ρ) ∎)
correctW (t₁ · t₂) {ρ} {c} {s} {k} hyp =
exec ⟨ comp t₁ (comp t₂ (app ∷ c)) , s , comp-env ρ ⟩ ≈⟨ correctW t₁ (λ v₁ → correctW t₂ (λ v₂ → ∙-correctW v₁ v₂ hyp)) ⟩W
(⟦ t₁ ⟧ ρ λ v₁ → ⟦ t₂ ⟧ ρ λ v₂ → (v₁ ∙ v₂) k) ≅⟨ sym $ sem-· t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ k ∎
∙-correctW :
∀ {n} v₁ v₂ {ρ : Env n} {c s} {k : Value → Maybe VM.Value ⊥} →
(∀ v → exec ⟨ c , val (comp-val v) ∷ s , comp-env ρ ⟩ ≈W k v) →
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val v₁) ∷ s , comp-env ρ ⟩ ≈W
(v₁ ∙ v₂) k
∙-correctW (con i) v₂ _ = ⌈ fail ∎ ⌉
∙-correctW (ƛ t₁ ρ₁) v₂ {ρ} {c} {s} {k} hyp =
exec ⟨ app ∷ c , val (comp-val v₂) ∷ val (comp-val (ƛ t₁ ρ₁)) ∷ s , comp-env ρ ⟩ ≈⟨ later (
exec ⟨ comp t₁ [ ret ] , ret c (comp-env ρ) ∷ s , comp-env (v₂ ∷ ρ₁) ⟩ ≈⟨ correct t₁ (λ v → laterˡ (hyp v)) ⟩P
(⟦ t₁ ⟧ (v₂ ∷ ρ₁) k) ∎) ⟩W
(ƛ t₁ ρ₁ ∙ v₂) k ∎
whnf : ∀ {x y} → x ≈P y → x ≈W y
whnf (x ≈⟨ x≈y ⟩P y≅z) = x ≈⟨ whnf x≈y ⟩W y≅z
whnf (correct t hyp) = correctW t hyp
mutual
soundW : ∀ {x y} → x ≈W y → Rel (other k) x y
soundW ⌈ x≈y ⌉ = x≈y
soundW (later x≈y) = later (♯ soundP x≈y)
soundW (laterˡ x≈y) = laterˡ (soundW x≈y)
soundP : ∀ {x y} → x ≈P y → Rel (other k) x y
soundP x≈y = soundW (whnf x≈y)
correct : ∀ t →
exec ⟨ comp t [] , [] , [] ⟩ ≈
⟦ t ⟧ [] (λ v → return (comp-val v))
correct t =
soundP $ Correctness.correct t (λ v → ⌈ return (comp-val v) ∎ ⌉)
where open Correctness
|
{
"alphanum_fraction": 0.4459396443,
"avg_line_length": 35.8257756563,
"ext": "agda",
"hexsha": "39b2850b3005cf04adbab228a64c8570768bd3d7",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Closure/Functional/Alternative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "Lambda/Closure/Functional/Alternative.agda",
"max_line_length": 138,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Closure/Functional/Alternative.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 7208,
"size": 15011
}
|
{-
Reported by sattler.christian, Oct 10 (3 days ago)
This is a funny one. The below code snippet produces the following error under the current Agda development version:
An internal error has occurred. Please report this as a bug.
Location of the error: src/full/Agda/TypeChecking/Eliminators.hs:85
Note the spurious Tm datatype that isn't used anywhere? Remove it, move its declaration forward, or its definition backward, and the internal error vanishes, leaving a few yellow spots.
Now uncomment the two implicit arguments at the bottom of the code. All metavars are now resolved. Now put the Tm datatype back in - yellow spots reappear, but different from before!
-}
{-# OPTIONS --cubical-compatible #-}
module Issue918 where
record ⊤ : Set where
constructor tt
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
_∘_ : {A B C : Set} → (B → C) → (A → B) → A → C
g ∘ f = λ x → g (f x)
_+'_ : ℕ → ℕ → ℕ
i +' zero = i
i +' suc j = suc i +' j
U : ℕ → Set
U zero = ⊤
U (suc n) = Σ (U n) (λ _ → ⊤)
V : ℕ → Set
V zero = ⊤
V (suc m) = Σ ⊤ (λ _ → V m)
combine : {i j : ℕ} → Σ (U i) (λ _ → V j) → U (i +' j)
combine {j = zero} = λ {(A , _) → A}
combine {j = suc j} = combine {j = j} ∘ (λ {(Γ , (A , T)) → ((Γ , A) , T)})
data Tm : Set
ctx-hom : (m : ℕ) → U m → Set
ctx-hom zero _ = ⊤
ctx-hom (suc m) (Δ , _) = Σ (ctx-hom m Δ) (λ _ → ⊤)
ctx-hom-split-iso : {m k : ℕ} {Δ : U m} {T : V k}
→ ctx-hom (m +' k) (combine (Δ , T))
→ Σ (ctx-hom m Δ) (λ _ → V k)
ctx-hom-split-iso {k = zero} = λ Δ → (Δ , tt)
ctx-hom-split-iso {m} {k = suc k} {Δ} {(A , T)} =
((λ {((Γ , A) , T) → (Γ , (A , T))}))
∘ ctx-hom-split-iso {m = suc m} --{Δ = (Δ , A)}
data Tm where
{- Project Member #1 andreas.m.abel
That was quite a riddle to solve.
1. The internal error is actually triggered in the termination checking phase.
I fixed this, will push soon.
A workaround is --no-termination-check
2. The data-Tm-brace puts ctx-hom and ctx-hom-split-iso into a mutual block.
This prevents ctx-hom to be unfolded during checking the -split-iso.
You can achieve the same by explicitely putting the two defs into a mutual
block.
If the mutual block is removed, the yellow stuff appears.
HO-unification is sensitive to reduction, at this moment I do not see an
easy fix for this behavior.
3. "yellow spots reappear, but in different places" I could not replay this.
For me, the yellow only disappeared if I also gave {T = T}, but then
it consistently disappears and reappears when putting in and out of a mutual
block.
-}
|
{
"alphanum_fraction": 0.6219015908,
"avg_line_length": 29.7032967033,
"ext": "agda",
"hexsha": "72a6bc5072d48f1aa48df89dc367bfd65aca7d8d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue918.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue918.agda",
"max_line_length": 185,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue918.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 894,
"size": 2703
}
|
{-# OPTIONS --rewriting #-}
module Luau.RuntimeError where
open import Agda.Builtin.Equality using (_≡_)
open import Luau.Heap using (Heap; _[_])
open import FFI.Data.Maybe using (just; nothing)
open import FFI.Data.String using (String)
open import Luau.Syntax using (BinaryOperator; Block; Expr; nil; var; val; addr; block_is_end; _$_; local_←_; return; done; _∙_; number; string; binexp; +; -; *; /; <; >; <=; >=; ··)
open import Luau.RuntimeType using (RuntimeType; valueType; function; number; string)
open import Properties.Equality using (_≢_)
data BinOpError : BinaryOperator → RuntimeType → Set where
+ : ∀ {t} → (t ≢ number) → BinOpError + t
- : ∀ {t} → (t ≢ number) → BinOpError - t
* : ∀ {t} → (t ≢ number) → BinOpError * t
/ : ∀ {t} → (t ≢ number) → BinOpError / t
< : ∀ {t} → (t ≢ number) → BinOpError < t
> : ∀ {t} → (t ≢ number) → BinOpError > t
<= : ∀ {t} → (t ≢ number) → BinOpError <= t
>= : ∀ {t} → (t ≢ number) → BinOpError >= t
·· : ∀ {t} → (t ≢ string) → BinOpError ·· t
data RuntimeErrorᴮ {a} (H : Heap a) : Block a → Set
data RuntimeErrorᴱ {a} (H : Heap a) : Expr a → Set
data RuntimeErrorᴱ H where
FunctionMismatch : ∀ v w → (valueType v ≢ function) → RuntimeErrorᴱ H (val v $ val w)
BinOpMismatch₁ : ∀ v w {op} → (BinOpError op (valueType v)) → RuntimeErrorᴱ H (binexp (val v) op (val w))
BinOpMismatch₂ : ∀ v w {op} → (BinOpError op (valueType w)) → RuntimeErrorᴱ H (binexp (val v) op (val w))
UnboundVariable : ∀ {x} → RuntimeErrorᴱ H (var x)
SEGV : ∀ {a} → (H [ a ] ≡ nothing) → RuntimeErrorᴱ H (val (addr a))
app₁ : ∀ {M N} → RuntimeErrorᴱ H M → RuntimeErrorᴱ H (M $ N)
app₂ : ∀ {M N} → RuntimeErrorᴱ H N → RuntimeErrorᴱ H (M $ N)
block : ∀ {b B} → RuntimeErrorᴮ H B → RuntimeErrorᴱ H (block b is B end)
bin₁ : ∀ {M N op} → RuntimeErrorᴱ H M → RuntimeErrorᴱ H (binexp M op N)
bin₂ : ∀ {M N op} → RuntimeErrorᴱ H N → RuntimeErrorᴱ H (binexp M op N)
data RuntimeErrorᴮ H where
local : ∀ {x M B} → RuntimeErrorᴱ H M → RuntimeErrorᴮ H (local x ← M ∙ B)
return : ∀ {M B} → RuntimeErrorᴱ H M → RuntimeErrorᴮ H (return M ∙ B)
|
{
"alphanum_fraction": 0.619047619,
"avg_line_length": 50,
"ext": "agda",
"hexsha": "b9b305c9e105699062334be616bf4183a89caf70",
"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": "72d8d443431875607fd457a13fe36ea62804d327",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "TheGreatSageEqualToHeaven/luau",
"max_forks_repo_path": "prototyping/Luau/RuntimeError.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "72d8d443431875607fd457a13fe36ea62804d327",
"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": "TheGreatSageEqualToHeaven/luau",
"max_issues_repo_path": "prototyping/Luau/RuntimeError.agda",
"max_line_length": 182,
"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/RuntimeError.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": 780,
"size": 2100
}
|
module Numeral.Natural.Oper.Modulo.Proofs.DivisibilityWithRemainder where
open import Data
open import Functional
open import Numeral.Finite
import Numeral.Finite.Proofs as 𝕟
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs.Algorithm
open import Numeral.Natural.Relation.DivisibilityWithRemainder hiding (base₀ ; base₊ ; step)
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Relator
open import Syntax.Transitivity
-- The remainder of the divisibility relation is given by the modulo operation.
[mod][∣ᵣₑₘ]-remainder-equality : ∀{x y r}{p : (𝐒(y) ∣ᵣₑₘ x)(r)} → ((x mod 𝐒(y)) ≡ 𝕟-to-ℕ ([∣ᵣₑₘ]-remainder p))
[mod][∣ᵣₑₘ]-remainder-equality {𝟎} {_} {𝟎} {DivRem𝟎} = [≡]-intro
[mod][∣ᵣₑₘ]-remainder-equality {𝐒 .(𝕟-to-ℕ r)} {𝐒 y} {𝐒 r} {DivRem𝟎} = mod'-lesser-dividend {1}{𝐒(y)}{𝕟-to-ℕ r}{y} ([≤]-without-[𝐒] 𝕟.bounded)
[mod][∣ᵣₑₘ]-remainder-equality {𝐒 x} {𝟎} {𝟎} {DivRem𝐒 p} = mod'-zero-all-except-dividend {x}
{-# CATCHALL #-}
[mod][∣ᵣₑₘ]-remainder-equality {𝐒 .(x + y)} {y} {r} {DivRem𝐒 {x = x} p} =
([ 𝟎 , y ] 𝐒(x + y) mod' y) 🝖[ _≡_ ]-[]
([ 𝟎 , y ] (𝐒(x) + y) mod' y) 🝖[ _≡_ ]-[ mod'-sumᵣ-modulo {0}{y}{x}{y} ]
([ 𝟎 , y ] x mod' y) 🝖[ _≡_ ]-[ [mod][∣ᵣₑₘ]-remainder-equality {p = p} ]
𝕟-to-ℕ ([∣ᵣₑₘ]-remainder p) 🝖[ _≡_ ]-[]
𝕟-to-ℕ ([∣ᵣₑₘ]-remainder (DivRem𝐒 p)) 🝖-end
|
{
"alphanum_fraction": 0.6335927367,
"avg_line_length": 51.4,
"ext": "agda",
"hexsha": "0a3cfee32acdb18126f0021fef6846a1a4907937",
"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": "Numeral/Natural/Oper/Modulo/Proofs/DivisibilityWithRemainder.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": "Numeral/Natural/Oper/Modulo/Proofs/DivisibilityWithRemainder.agda",
"max_line_length": 142,
"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": "Numeral/Natural/Oper/Modulo/Proofs/DivisibilityWithRemainder.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": 686,
"size": 1542
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Rings.Definition
open import Setoids.Setoids
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Fields.Fields where
record Field {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} (R : Ring S _+_ _*_) : Set (lsuc m ⊔ n) where
open Ring R
open Group additiveGroup
open Setoid S
field
allInvertible : (a : A) → ((a ∼ Group.0G (Ring.additiveGroup R)) → False) → Sg A (λ t → t * a ∼ 1R)
nontrivial : (0R ∼ 1R) → False
0F : A
0F = Ring.0R R
record Field' {m n : _} : Set (lsuc m ⊔ lsuc n) where
field
A : Set m
S : Setoid {m} {n} A
_+_ : A → A → A
_*_ : A → A → A
R : Ring S _+_ _*_
isField : Field R
encapsulateField : {m n : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (F : Field R) → Field'
encapsulateField {A = A} {S = S} {_+_} {_*_} {R} F = record { A = A ; S = S ; _+_ = _+_ ; _*_ = _*_ ; R = R ; isField = F }
{-
record OrderedField {n} {A : Set n} {R : Ring A} (F : Field R) : Set (lsuc n) where
open Field F
field
ord : TotalOrder A
open TotalOrder ord
open Ring R
field
productPos : {a b : A} → (0R < a) → (0R < b) → (0R < (a * b))
orderRespectsAddition : {a b c : A} → (a < b) → (a + c) < (b + c)
-}
|
{
"alphanum_fraction": 0.5446109921,
"avg_line_length": 29.8085106383,
"ext": "agda",
"hexsha": "d902f3e403bd38210ed1a5df3e24231a866eb9d6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/Fields.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/Fields.agda",
"max_line_length": 143,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/Fields.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 573,
"size": 1401
}
|
{-# OPTIONS --without-K #-}
module PiEquiv where
open import Data.Empty
open import Data.Unit
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; Σ; _,_; proj₁; proj₂)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; cong; cong₂)
open import Function using (_∘_; id)
open import Equiv
open import EquivEquiv
open _≋_
open import TypeEquiv as TE
open import TypeEquivEquiv
-- open import TypeEquivCat
open import PiU
open import PiLevel0
open import PiLevel1
open import Data.Sum.Properties2
open import Data.SumProd.Properties
------------------------------------------------------------------------------
-- A combinator t₁ ⟷ t₂ denotes an equivalence to types
-- note how we don't have to look at the types at all.
⟦_⟧ : U → Set
⟦ ZERO ⟧ = ⊥
⟦ ONE ⟧ = ⊤
⟦ PLUS t₁ t₂ ⟧ = ⟦ t₁ ⟧ ⊎ ⟦ t₂ ⟧
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
eval : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₁ ⟧ → ⟦ t₂ ⟧
eval unite₊l (inj₁ ())
eval unite₊l (inj₂ v) = v
eval uniti₊l v = inj₂ v
eval unite₊r (inj₁ x) = x
eval unite₊r (inj₂ ())
eval uniti₊r v = inj₁ v
eval swap₊ (inj₁ v) = inj₂ v
eval swap₊ (inj₂ v) = inj₁ v
eval assocl₊ (inj₁ v) = inj₁ (inj₁ v)
eval assocl₊ (inj₂ (inj₁ v)) = inj₁ (inj₂ v)
eval assocl₊ (inj₂ (inj₂ v)) = inj₂ v
eval assocr₊ (inj₁ (inj₁ v)) = inj₁ v
eval assocr₊ (inj₁ (inj₂ v)) = inj₂ (inj₁ v)
eval assocr₊ (inj₂ v) = inj₂ (inj₂ v)
eval unite⋆l (tt , v) = v
eval uniti⋆l v = (tt , v)
eval unite⋆r (v , tt) = v
eval uniti⋆r v = v , tt
eval swap⋆ (v₁ , v₂) = (v₂ , v₁)
eval assocl⋆ (v₁ , (v₂ , v₃)) = ((v₁ , v₂) , v₃)
eval assocr⋆ ((v₁ , v₂) , v₃) = (v₁ , (v₂ , v₃))
eval absorbr (x , _) = x
eval absorbl (_ , y) = y
eval factorzl ()
eval factorzr ()
eval dist (inj₁ v₁ , v₃) = inj₁ (v₁ , v₃)
eval dist (inj₂ v₂ , v₃) = inj₂ (v₂ , v₃)
eval factor (inj₁ (v₁ , v₃)) = (inj₁ v₁ , v₃)
eval factor (inj₂ (v₂ , v₃)) = (inj₂ v₂ , v₃)
eval distl (v , inj₁ x) = inj₁ (v , x)
eval distl (v , inj₂ y) = inj₂ (v , y)
eval factorl (inj₁ (x , y)) = x , inj₁ y
eval factorl (inj₂ (x , y)) = x , inj₂ y
eval id⟷ v = v
eval (c₁ ◎ c₂) v = eval c₂ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₁ v) = inj₁ (eval c₁ v)
eval (c₁ ⊕ c₂) (inj₂ v) = inj₂ (eval c₂ v)
eval (c₁ ⊗ c₂) (v₁ , v₂) = (eval c₁ v₁ , eval c₂ v₂)
-- useful to have the backwards eval too
evalB : {t₁ t₂ : U} → (t₁ ⟷ t₂) → ⟦ t₂ ⟧ → ⟦ t₁ ⟧
evalB unite₊l x = inj₂ x
evalB uniti₊l (inj₁ ())
evalB uniti₊l (inj₂ y) = y
evalB unite₊r v = inj₁ v
evalB uniti₊r (inj₁ x) = x
evalB uniti₊r (inj₂ ())
evalB swap₊ (inj₁ x) = inj₂ x
evalB swap₊ (inj₂ y) = inj₁ y
evalB assocl₊ (inj₁ (inj₁ x)) = inj₁ x
evalB assocl₊ (inj₁ (inj₂ y)) = inj₂ (inj₁ y)
evalB assocl₊ (inj₂ y) = inj₂ (inj₂ y)
evalB assocr₊ (inj₁ x) = inj₁ (inj₁ x)
evalB assocr₊ (inj₂ (inj₁ x)) = inj₁ (inj₂ x)
evalB assocr₊ (inj₂ (inj₂ y)) = inj₂ y
evalB unite⋆l x = tt , x
evalB uniti⋆l (tt , x) = x
evalB unite⋆r v = v , tt
evalB uniti⋆r (v , tt) = v
evalB swap⋆ (x , y) = y , x
evalB assocl⋆ ((x , y) , z) = x , y , z
evalB assocr⋆ (x , y , z) = (x , y) , z
evalB absorbr ()
evalB absorbl ()
evalB factorzr (_ , x) = x
evalB factorzl (x , _) = x
evalB dist (inj₁ (x , y)) = inj₁ x , y
evalB dist (inj₂ (x , y)) = inj₂ x , y
evalB factor (inj₁ x , z) = inj₁ (x , z)
evalB factor (inj₂ y , z) = inj₂ (y , z)
evalB distl (inj₁ (x , y)) = x , inj₁ y
evalB distl (inj₂ (x , y)) = x , inj₂ y
evalB factorl (v , inj₁ x) = inj₁ (v , x)
evalB factorl (v , inj₂ y) = inj₂ (v , y)
evalB id⟷ x = x
evalB (c₀ ◎ c₁) x = evalB c₀ (evalB c₁ x)
evalB (c₀ ⊕ c₁) (inj₁ x) = inj₁ (evalB c₀ x)
evalB (c₀ ⊕ c₁) (inj₂ y) = inj₂ (evalB c₁ y)
evalB (c₀ ⊗ c₁) (x , y) = evalB c₀ x , evalB c₁ y
-- should probably prove that these are inverses!
-- to a certain extent, no need, because here's
-- the right way to do it:
c2equiv : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → ⟦ t₁ ⟧ ≃ ⟦ t₂ ⟧
c2equiv unite₊l = TE.unite₊equiv
c2equiv uniti₊l = TE.uniti₊equiv
c2equiv unite₊r = TE.unite₊′equiv
c2equiv uniti₊r = TE.uniti₊′equiv
c2equiv swap₊ = TE.swap₊equiv
c2equiv assocl₊ = TE.assocl₊equiv
c2equiv assocr₊ = TE.assocr₊equiv
c2equiv unite⋆l = TE.unite⋆equiv
c2equiv uniti⋆l = TE.uniti⋆equiv
c2equiv unite⋆r = TE.unite⋆′equiv
c2equiv uniti⋆r = TE.uniti⋆′equiv
c2equiv swap⋆ = TE.swap⋆equiv
c2equiv assocl⋆ = TE.assocl⋆equiv
c2equiv assocr⋆ = TE.assocr⋆equiv
c2equiv absorbr = TE.distzequiv
c2equiv absorbl = TE.distzrequiv
c2equiv factorzr = TE.factorzrequiv
c2equiv factorzl = TE.factorzequiv
c2equiv dist = TE.distequiv
c2equiv factor = TE.factorequiv
c2equiv distl = TE.distlequiv
c2equiv factorl = TE.factorlequiv
c2equiv id⟷ = id≃
c2equiv (c ◎ c₁) = c2equiv c₁ ● c2equiv c
c2equiv (c ⊕ c₁) = (c2equiv c) ⊎≃ (c2equiv c₁)
c2equiv (c ⊗ c₁) = (c2equiv c) ×≃ (c2equiv c₁)
-- and these are 'coherent'
-- first with evaluation:
lemma0 : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (v : ⟦ t₁ ⟧) →
eval c v ≡ proj₁ (c2equiv c) v
lemma0 unite₊l (inj₁ ())
lemma0 unite₊l (inj₂ y) = refl
lemma0 uniti₊l v = refl
lemma0 unite₊r (inj₁ x) = refl
lemma0 unite₊r (inj₂ ())
lemma0 uniti₊r v = refl
lemma0 PiLevel0.swap₊ (inj₁ x) = refl
lemma0 PiLevel0.swap₊ (inj₂ y) = refl
lemma0 PiLevel0.assocl₊ (inj₁ x) = refl
lemma0 PiLevel0.assocl₊ (inj₂ (inj₁ x)) = refl
lemma0 PiLevel0.assocl₊ (inj₂ (inj₂ y)) = refl
lemma0 PiLevel0.assocr₊ (inj₁ (inj₁ x)) = refl
lemma0 PiLevel0.assocr₊ (inj₁ (inj₂ y)) = refl
lemma0 PiLevel0.assocr₊ (inj₂ y) = refl
lemma0 unite⋆l v = refl -- yay for η !
lemma0 uniti⋆l v = refl
lemma0 unite⋆r v = refl
lemma0 uniti⋆r v = refl
lemma0 PiLevel0.swap⋆ v = refl
lemma0 PiLevel0.assocl⋆ v = refl
lemma0 PiLevel0.assocr⋆ v = refl
lemma0 absorbr v = refl
lemma0 absorbl v = refl
lemma0 factorzr ()
lemma0 factorzl ()
lemma0 PiLevel0.dist (inj₁ x , proj₂) = refl
lemma0 PiLevel0.dist (inj₂ y , proj₂) = refl
lemma0 PiLevel0.factor (inj₁ x) = refl
lemma0 PiLevel0.factor (inj₂ y) = refl
lemma0 PiLevel0.distl (proj₁ , inj₁ x) = refl
lemma0 PiLevel0.distl (proj₁ , inj₂ y) = refl
lemma0 PiLevel0.factorl (inj₁ x) = refl
lemma0 PiLevel0.factorl (inj₂ y) = refl
lemma0 id⟷ v = refl
lemma0 (c ◎ c₁) v =
trans (cong (eval c₁) (lemma0 c v)) (
trans (lemma0 c₁ (proj₁ (c2equiv c) v))
(sym (β₁ v)))
lemma0 (c ⊕ c₁) (inj₁ x) =
trans (cong inj₁ (lemma0 c x)) (sym (β⊎₁ (inj₁ x)))
lemma0 (c ⊕ c₁) (inj₂ y) =
trans (cong inj₂ (lemma0 c₁ y)) (sym (β⊎₁ (inj₂ y)))
lemma0 (c ⊗ c₁) (x , y) =
trans (cong₂ _,_ (lemma0 c x) (lemma0 c₁ y)) (sym (β×₁ (x , y)))
lemma1 : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) → (v : ⟦ t₂ ⟧) →
evalB c v ≡ proj₁ (sym≃ (c2equiv c)) v
lemma1 PiLevel0.unite₊l v = refl
lemma1 PiLevel0.uniti₊l (inj₁ ())
lemma1 PiLevel0.uniti₊l (inj₂ y) = refl
lemma1 PiLevel0.unite₊r v = refl
lemma1 uniti₊r (inj₁ x) = refl
lemma1 uniti₊r (inj₂ ())
lemma1 PiLevel0.swap₊ (inj₁ x) = refl
lemma1 PiLevel0.swap₊ (inj₂ y) = refl
lemma1 PiLevel0.assocl₊ (inj₁ (inj₁ x)) = refl
lemma1 PiLevel0.assocl₊ (inj₁ (inj₂ y)) = refl
lemma1 PiLevel0.assocl₊ (inj₂ y) = refl
lemma1 PiLevel0.assocr₊ (inj₁ x) = refl
lemma1 PiLevel0.assocr₊ (inj₂ (inj₁ x)) = refl
lemma1 PiLevel0.assocr₊ (inj₂ (inj₂ y)) = refl
lemma1 PiLevel0.unite⋆l v = refl
lemma1 PiLevel0.uniti⋆l (tt , x) = refl
lemma1 PiLevel0.unite⋆r v = refl
lemma1 uniti⋆r (x , tt) = refl
lemma1 PiLevel0.swap⋆ (x , y) = refl
lemma1 PiLevel0.assocl⋆ ((x , y) , z) = refl
lemma1 PiLevel0.assocr⋆ (x , y , z) = refl
lemma1 absorbr ()
lemma1 absorbl ()
lemma1 PiLevel0.factorzr (_ , ())
lemma1 factorzl (() , v)
lemma1 PiLevel0.dist (inj₁ (proj₁ , proj₂)) = refl
lemma1 PiLevel0.dist (inj₂ (proj₁ , proj₂)) = refl
lemma1 PiLevel0.factor (inj₁ x , proj₂) = refl
lemma1 PiLevel0.factor (inj₂ y , proj₂) = refl
lemma1 PiLevel0.distl (inj₁ (proj₁ , proj₂)) = refl
lemma1 PiLevel0.distl (inj₂ (proj₁ , proj₂)) = refl
lemma1 PiLevel0.factorl (v , inj₁ x) = refl
lemma1 PiLevel0.factorl (v , inj₂ y) = refl
lemma1 id⟷ v = refl
lemma1 (c₀ ◎ c₁) v = trans (
trans (cong (evalB c₀) (lemma1 c₁ v)) (lemma1 c₀ (gg (c2equiv c₁) v)) )
(sym (β₂ v))
lemma1 (c₀ ⊕ c₁) (inj₁ x) = trans (cong inj₁ (lemma1 c₀ x)) (sym (β⊎₂ (inj₁ x))) -- cong inj₁ (lemma1 c₀ x)
lemma1 (c₀ ⊕ c₁) (inj₂ y) = trans (cong inj₂ (lemma1 c₁ y)) (sym (β⊎₂ (inj₂ y)))
lemma1 (c₀ ⊗ c₁) (x , y) = trans (cong₂ _,_ (lemma1 c₀ x) (lemma1 c₁ y)) (sym (β×₂ (x , y)))
-- and with reverse
!≡sym≃ : {t₁ t₂ : U} → (c : t₁ ⟷ t₂) →
c2equiv (! c) ≋ sym≃ (c2equiv c)
!≡sym≃ unite₊l = id≋
!≡sym≃ uniti₊l = id≋
!≡sym≃ unite₊r = id≋
!≡sym≃ uniti₊r = id≋
!≡sym≃ PiLevel0.swap₊ = id≋
!≡sym≃ PiLevel0.assocl₊ = id≋
!≡sym≃ PiLevel0.assocr₊ = id≋
!≡sym≃ unite⋆l = id≋
!≡sym≃ uniti⋆l = id≋
!≡sym≃ unite⋆r = id≋
!≡sym≃ uniti⋆r = id≋
!≡sym≃ PiLevel0.swap⋆ = id≋
!≡sym≃ PiLevel0.assocl⋆ = id≋
!≡sym≃ PiLevel0.assocr⋆ = id≋
!≡sym≃ absorbr = id≋
!≡sym≃ absorbl = id≋
!≡sym≃ PiLevel0.factorzr = id≋
!≡sym≃ factorzl = id≋
!≡sym≃ PiLevel0.dist = id≋
!≡sym≃ PiLevel0.factor = id≋
!≡sym≃ PiLevel0.distl = id≋
!≡sym≃ PiLevel0.factorl = id≋
!≡sym≃ id⟷ = id≋
!≡sym≃ (c ◎ c₁) = trans≋ (EquivEquiv._◎_ (!≡sym≃ c) (!≡sym≃ c₁)) (sym≋ sym≃●)
!≡sym≃ (c ⊕ c₁) = trans≋ ((!≡sym≃ c) ⊎≋ (!≡sym≃ c₁)) (sym≋ sym≃-distrib⊎)
!≡sym≃ (c ⊗ c₁) = trans≋ ((!≡sym≃ c) ×≋ (!≡sym≃ c₁)) (sym≋ sym≃-distrib×)
left-inv : {t₁ t₂ : U} (c : t₁ ⟷ t₂) →
(c2equiv (! c) ● c2equiv c) ≋ id≃
left-inv c =
let p = c2equiv c in
trans≋ (!≡sym≃ c EquivEquiv.◎ id≋) (linv≋ p)
right-inv : {t₁ t₂ : U} (c : t₁ ⟷ t₂) →
(c2equiv c ● c2equiv (! c)) ≋ id≃
right-inv c =
let p = c2equiv c in
trans≋ (id≋ EquivEquiv.◎ (!≡sym≃ c)) (rinv≋ p)
----------------------------------------------------------
cc2equiv : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →
c2equiv c₁ ≋ c2equiv c₂
cc2equiv assoc◎l = ●-assoc
cc2equiv assoc◎r = ●-assocl
cc2equiv assocl⊕l = assocl₊-nat
cc2equiv assocl⊕r = sym≋ assocl₊-nat
cc2equiv assocl⊗l = assocl⋆-nat
cc2equiv assocl⊗r = sym≋ assocl⋆-nat
cc2equiv assocr⊕r = assocr₊-nat
cc2equiv assocr⊗l = sym≋ assocr⋆-nat
cc2equiv assocr⊗r = assocr⋆-nat
cc2equiv assocr⊕l = sym≋ assocr₊-nat
cc2equiv dist⇔l = dist-nat
cc2equiv dist⇔r = sym≋ dist-nat
cc2equiv distl⇔l = distl-nat
cc2equiv distl⇔r = sym≋ distl-nat
cc2equiv factor⇔l = factor-nat
cc2equiv factor⇔r = sym≋ factor-nat
cc2equiv factorl⇔l = factorl-nat
cc2equiv factorl⇔r = sym≋ factorl-nat
cc2equiv idl◎l = rid≋
cc2equiv idl◎r = sym≋ rid≋
cc2equiv idr◎l = lid≋
cc2equiv idr◎r = sym≋ lid≋
cc2equiv (linv◎l {c = c}) = left-inv c
cc2equiv (linv◎r {c = c}) = sym≋ (left-inv c)
cc2equiv (rinv◎l {c = c}) = right-inv c
cc2equiv (rinv◎r {c = c}) = sym≋ (right-inv c)
cc2equiv (unite₊l⇔l {c₁ = c₁} {c₂}) = sym≋ (unite₊-nat {f = c2equiv c₂})
cc2equiv unite₊l⇔r = unite₊-nat
cc2equiv uniti₊l⇔l = sym≋ uniti₊-nat
cc2equiv uniti₊l⇔r = uniti₊-nat
cc2equiv unite₊r⇔l = sym≋ unite₊′-nat
cc2equiv unite₊r⇔r = unite₊′-nat
cc2equiv uniti₊r⇔l = sym≋ uniti₊′-nat
cc2equiv uniti₊r⇔r = uniti₊′-nat
cc2equiv swapl₊⇔ = sym≋ swap₊-nat
cc2equiv swapr₊⇔ = swap₊-nat
cc2equiv unitel⋆⇔l = sym≋ unite⋆-nat
cc2equiv uniter⋆⇔l = unite⋆-nat
cc2equiv unitil⋆⇔l = sym≋ uniti⋆-nat
cc2equiv unitir⋆⇔l = uniti⋆-nat
cc2equiv unitel⋆⇔r = sym≋ unite⋆′-nat
cc2equiv uniter⋆⇔r = unite⋆′-nat
cc2equiv unitil⋆⇔r = sym≋ uniti⋆′-nat
cc2equiv unitir⋆⇔r = uniti⋆′-nat
cc2equiv swapl⋆⇔ = sym≋ swap⋆-nat
cc2equiv swapr⋆⇔ = swap⋆-nat
cc2equiv id⇔ = id≋
cc2equiv (trans⇔ ce ce₁) = trans≋ (cc2equiv ce) (cc2equiv ce₁)
cc2equiv (ce ⊡ ce₁) = (cc2equiv ce₁) EquivEquiv.◎ (cc2equiv ce)
cc2equiv (resp⊕⇔ ce ce₁) = cc2equiv ce ⊎≋ cc2equiv ce₁
cc2equiv (resp⊗⇔ ce ce₁) = cc2equiv ce ×≋ cc2equiv ce₁
cc2equiv id⟷⊕id⟷⇔ = [id,id]≋id
cc2equiv split⊕-id⟷ = sym≋ [id,id]≋id
cc2equiv hom⊕◎⇔ = ⊎●≋●⊎
cc2equiv hom◎⊕⇔ = sym≋ ⊎●≋●⊎
cc2equiv id⟷⊗id⟷⇔ = id×id≋id
cc2equiv split⊗-id⟷ = sym≋ id×id≋id
cc2equiv hom⊗◎⇔ = ×●≋●×
cc2equiv hom◎⊗⇔ = sym≋ ×●≋●×
cc2equiv triangle⊕l = unite-assocr₊-coh
cc2equiv triangle⊕r = sym≋ unite-assocr₊-coh
cc2equiv triangle⊗l = unite-assocr⋆-coh
cc2equiv triangle⊗r = sym≋ unite-assocr⋆-coh
cc2equiv unite₊l-coh-l = unite₊l-coh
cc2equiv unite₊l-coh-r = sym≋ unite₊l-coh
cc2equiv unite⋆l-coh-l = unite⋆l-coh
cc2equiv unite⋆l-coh-r = sym≋ unite⋆l-coh
cc2equiv pentagon⊕l = assocr₊-coh
cc2equiv pentagon⊕r = sym≋ assocr₊-coh
cc2equiv pentagon⊗l = assocr⋆-coh
cc2equiv pentagon⊗r = sym≋ assocr⋆-coh
cc2equiv hexagonr⊕l = assocr₊-swap₊-coh
cc2equiv hexagonr⊕r = sym≋ assocr₊-swap₊-coh
cc2equiv hexagonl⊕l = assocl₊-swap₊-coh
cc2equiv hexagonl⊕r = sym≋ assocl₊-swap₊-coh
cc2equiv hexagonr⊗l = assocr⋆-swap⋆-coh
cc2equiv hexagonr⊗r = sym≋ assocr⋆-swap⋆-coh
cc2equiv hexagonl⊗l = assocl⋆-swap⋆-coh
cc2equiv hexagonl⊗r = sym≋ assocl⋆-swap⋆-coh
cc2equiv absorbl⇔l = distzr-nat
cc2equiv absorbl⇔r = sym≋ distzr-nat
cc2equiv absorbr⇔l = distz-nat
cc2equiv absorbr⇔r = sym≋ distz-nat
cc2equiv factorzl⇔l = factorz-nat
cc2equiv factorzl⇔r = sym≋ factorz-nat
cc2equiv factorzr⇔l = factorzr-nat
cc2equiv factorzr⇔r = sym≋ factorzr-nat
cc2equiv swap₊distl⇔l = A×[B⊎C]≃[A×C]⊎[A×B]
cc2equiv swap₊distl⇔r = sym≋ A×[B⊎C]≃[A×C]⊎[A×B]
cc2equiv dist-swap⋆⇔l = [A⊎B]×C≃[C×A]⊎[C×B]
cc2equiv dist-swap⋆⇔r = sym≋ [A⊎B]×C≃[C×A]⊎[C×B]
cc2equiv assocl₊-dist-dist⇔l = [A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D
cc2equiv assocl₊-dist-dist⇔r = sym≋ [A⊎B⊎C]×D≃[A×D⊎B×D]⊎C×D
cc2equiv assocl⋆-distl⇔l = A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D
cc2equiv assocl⋆-distl⇔r = sym≋ A×B×[C⊎D]≃[A×B]×C⊎[A×B]×D
cc2equiv absorbr0-absorbl0⇔ = 0×0≃0
cc2equiv absorbl0-absorbr0⇔ = sym≋ 0×0≃0
cc2equiv absorbr⇔distl-absorb-unite = 0×[A⊎B]≃0
cc2equiv distl-absorb-unite⇔absorbr = sym≋ 0×[A⊎B]≃0
cc2equiv unite⋆r0-absorbr1⇔ = 0×1≃0
cc2equiv absorbr1-unite⋆r-⇔ = sym≋ 0×1≃0
cc2equiv absorbl≡swap⋆◎absorbr = A×0≃0
cc2equiv swap⋆◎absorbr≡absorbl = sym≋ A×0≃0
cc2equiv absorbr⇔[assocl⋆◎[absorbr⊗id⟷]]◎absorbr = 0×A×B≃0
cc2equiv [assocl⋆◎[absorbr⊗id⟷]]◎absorbr⇔absorbr = sym≋ 0×A×B≃0
cc2equiv [id⟷⊗absorbr]◎absorbl⇔assocl⋆◎[absorbl⊗id⟷]◎absorbr = A×0×B≃0
cc2equiv assocl⋆◎[absorbl⊗id⟷]◎absorbr⇔[id⟷⊗absorbr]◎absorbl = sym≋ A×0×B≃0
cc2equiv elim⊥-A[0⊕B]⇔l = A×[0+B]≃A×B
cc2equiv elim⊥-A[0⊕B]⇔r = sym≋ A×[0+B]≃A×B
cc2equiv elim⊥-1[A⊕B]⇔l = 1×[A⊎B]≃A⊎B
cc2equiv elim⊥-1[A⊕B]⇔r = sym≋ 1×[A⊎B]≃A⊎B
cc2equiv fully-distribute⇔l = [A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D
cc2equiv fully-distribute⇔r = sym≋ [A⊎B]×[C⊎D]≃[[A×C⊎B×C]⊎A×D]⊎B×D
--
-- These programs really are equivalent. Here's two ways to see that:
-- 1. they give the same results as programs:
≋⇒≡ : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →
eval c₁ ∼ eval c₂
≋⇒≡ {c₁ = c₁} {c₂} ce =
trans∼ (lemma0 c₁) (
trans∼ (_≋_.f≡ (cc2equiv ce))
(sym∼ (lemma0 c₂)))
-- 2. in fact, you can run one forward, then the other
-- backward, and that's the identity
ping-pong : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} (ce : c₁ ⇔ c₂) →
evalB c₂ ∘ eval c₁ ∼ id
ping-pong {c₁ = c₁} {c₂} ce =
trans∼ (cong₂∘ (lemma1 c₂) (lemma0 c₁)) (
trans∼ (cong∘r (proj₁ (c2equiv c₁)) (_≋_.f≡ (flip≋ (cc2equiv (2! ce))) )) (
trans∼(sym∼ β₁)
(_≋_.f≡ (linv≋ (c2equiv c₁)))))
|
{
"alphanum_fraction": 0.6348742352,
"avg_line_length": 34.6117647059,
"ext": "agda",
"hexsha": "3225b1e52016e3c315ea5b29935a4450e70e9687",
"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/PiEquiv.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/PiEquiv.agda",
"max_line_length": 107,
"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/PiEquiv.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": 7690,
"size": 14710
}
|
module _ where
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
data ⊥ : Set where
T : Nat → Set
T zero = ⊥
T (suc n) = Nat
module M (n : Nat) where
foo : n ≡ 0 → T n → Nat
foo refl t = 0
module M' where
bar : ⊥
bar = t
bad : ⊥
bad = M'.bar
loop : ⊥
loop = M.bad 0
|
{
"alphanum_fraction": 0.5541401274,
"avg_line_length": 12.0769230769,
"ext": "agda",
"hexsha": "37aa1d6f7549fcf271f01ce198900bdde405c6e2",
"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/Issue2897.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/Issue2897.agda",
"max_line_length": 33,
"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/Issue2897.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": 125,
"size": 314
}
|
module PigeonHole where
open import Prelude
open import Data.Nat hiding (_==_; _<_)
open import Data.Fin
open import Data.Vec as Vec
open import Logic.Base
open import Logic.Identity
open Vec.Elem
tooManyPigeons : {n : Nat}(xs : Vec (Fin (suc n)) n) -> ∃ \p -> p ∉ xs
tooManyPigeons {zero} [] = ∃-I fzero nl
tooManyPigeons {suc n} zs = aux zs (find _==_ fzero zs)
where
-- We start by checking whether or not fzero is an element of the list
aux : {n : Nat}(xs : Vec (Fin (suc (suc n))) (suc n)) ->
fzero ∈ xs \/ fzero ∉ xs -> ∃ \p -> p ∉ xs
-- If it's not then we're done
aux xs (\/-IR z∉xs) = ∃-I fzero z∉xs
-- If it is we have to find another element
aux xs (\/-IL z∈xs) = lem₂ ih
where
-- Let's remove the occurrence of fzero from the list and strip a fsuc
-- from each of the other elements (i.e. map pred $ delete fzero xs)
-- We can apply the induction hypothesis, giving us a p which is not in
-- this list.
ih : ∃ \p -> p ∉ map pred (delete fzero xs z∈xs)
ih = tooManyPigeons (map pred $ delete _ xs z∈xs)
-- First observe that if i ∉ map pred xs then fsuc i ∉ xs. Using this
-- lemma we conclude that fsuc p ∉ delete fzero xs.
lem₀ : {n m : Nat}(i : Fin (suc n))(xs : Vec (Fin (suc (suc n))) m) ->
i ∉ map pred xs -> fsuc i ∉ xs
lem₀ i [] nl = nl
lem₀ i (x :: xs) (cns h t) = cns (rem₀ h) (lem₀ i xs t)
where
rem₀ : {n : Nat}{i : Fin (suc n)}{j : Fin (suc (suc n))} ->
i ≢ pred j -> fsuc i ≢ j
rem₀ i≠i refl = i≠i refl
-- Furthermore, if i ∉ delete j xs and i ≠ j then i ∉ xs.
lem₁ : {n m : Nat}{i : Fin (suc n)}{j : Fin n}
(xs : Vec (Fin (suc n)) (suc m))(p : i ∈ xs) ->
thin i j ∉ delete i xs p -> thin i j ∉ xs
lem₁ (x :: xs) hd el = cns (thin-ij≠i _ _) el
lem₁ {m = zero } (x :: xs) (tl ()) _
lem₁ {m = suc _} (x :: xs) (tl p) (cns h t) = cns h (lem₁ xs p t)
-- So we get fsuc p ∉ xs and we're done.
lem₂ : (∃ \p -> p ∉ map pred (delete fzero xs z∈xs)) ->
(∃ \p -> p ∉ xs)
lem₂ (∃-I p h) = ∃-I (fsuc p) (lem₁ xs z∈xs $ lem₀ _ _ h)
-- tooManyHoles : {n : Nat}(xs : Vec (Fin n) (suc n)) ->
-- ∃ \p -> ∃ \i -> ∃ \j -> xs ! i ≡ p /\ xs ! thin i j ≡ p
-- tooManyHoles = ?
|
{
"alphanum_fraction": 0.5547016275,
"avg_line_length": 34.5625,
"ext": "agda",
"hexsha": "cdc82109fe70fa7d1c721190c9ede098b25bb803",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/PigeonHole.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"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": "larrytheliquid/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/PigeonHole.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/PigeonHole.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 881,
"size": 2212
}
|
module Data.Vec.Extra where
open import Data.Product hiding (map; zip)
open import Data.Nat
open import Data.Fin
open import Data.Vec
open import Relation.Binary.PropositionalEquality
open import Function
map-with-∈ : ∀ {a}{A : Set a}{b n}{B : Set b}
(xs : Vec A n) → (∀ i {x} → lookup i xs ≡ x → B) → Vec B n
map-with-∈ [] f = []
map-with-∈ (x ∷ xs) f = f zero refl ∷ map-with-∈ xs (λ i x → f (suc i) refl)
|
{
"alphanum_fraction": 0.6153846154,
"avg_line_length": 30.6428571429,
"ext": "agda",
"hexsha": "677734b1d26b0ec36c862f9b940ce17bf7179d87",
"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/Data/Vec/Extra.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/Data/Vec/Extra.agda",
"max_line_length": 76,
"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/Data/Vec/Extra.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": 149,
"size": 429
}
|
record R : Set₁ where
field
X : Set
data Δ (A : Set) : Set where
_,_ : A → A → Δ A
foo : (A : Set) → R → Δ A → Set
foo A = λ { r (x , y) → let open R r in X }
-- (y₁ : r) → Set !=< Set of type Set₁
-- when checking that the expression .Foo.X has type Set
|
{
"alphanum_fraction": 0.5296296296,
"avg_line_length": 20.7692307692,
"ext": "agda",
"hexsha": "f4d0cdc0093111b4a956b53075e03337613d7180",
"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/Issue2883b.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/Issue2883b.agda",
"max_line_length": 58,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2883b.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": 104,
"size": 270
}
|
-- Andreas, 2017-12-01, issue #2859 introduced by parameter-refinement
-- In Agda 2.5.2 any definition by pattern matching in a module
-- with a parameter that shadows a constructor will complain
-- about pattern variables with the same name as a constructor.
-- These are pattern variables added by the parameter-refinement
-- machinery, not user written ones. Thus, no reason to complain here.
-- {-# OPTIONS -v scope.pat:60 #-}
-- {-# OPTIONS -v tc.lhs.shadow:30 #-}
data D : Set where
c : D
module M (c : D) where
data DD : Set where
cc : DD
should-work : DD → Set
should-work cc = DD
should-fail : D → D
should-fail c = c
-- Expected error:
-- The pattern variable c has the same name as the constructor c
-- when checking the clause test c = c
|
{
"alphanum_fraction": 0.6920103093,
"avg_line_length": 25.8666666667,
"ext": "agda",
"hexsha": "8df89e2817dc5dffa6698359d6bc455728745c21",
"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/Issue2859.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/Issue2859.agda",
"max_line_length": 71,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2859.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": 208,
"size": 776
}
|
{-# OPTIONS --without-K --safe #-}
-- | Functions for the composition of binary relations.
module Dodo.Binary.Composition where
-- Stdlib imports
open import Level using (Level; _⊔_)
open import Data.Product using (_,_; _×_; ∃-syntax)
open import Function.Base using (flip)
open import Relation.Binary using (Rel; REL)
open import Relation.Binary using (Transitive; Symmetric)
-- Local imports
open import Dodo.Binary.Equality
-- # Definitions
infixl 10 _⨾_ ⨾:
-- | Composition of binary relations.
--
-- The composition of two relations P and Q, is mathematically denoted as `P⨾Q`. It is
-- inhabited as `(P⨾Q) x y`, iff `P x z` and `Q z y` are inhabited, for some `z`.
--
-- The notation used here is:
-- > Pxz ⨾[ z ]⨾ Qzy : (P ⨾ Q) x y
--
-- Where the corresponding types are:
-- > Pxz : P x z
-- > Qzy : Q z y
--
-- That notation is syntactic sugar for the constructor below:
-- > ⨾: z Pxz Qzy
--
--
-- # Design decision: Syntactic sugar with explicit `z`
--
-- The syntactic sugar /cannot/ be the actual constructor, as `Pxz` depends on `z`; Meaning
-- that Agda requires to know `z` before `Pxz`. Alternatively, `z` could be /implicit/
-- (as it is in the standard library). For instance:
-- > Pxz ⨾ Qzy : (P ⨾ Q) x y
--
-- The disadvantage of that approach is that `z` may not always be inferred from `Pxz` and `Qzy`.
-- After all, `Pxz` and `Qzy` may be beta-reduced, for which different types of `P`, `Q`, `x`, `y`,
-- and `z` hold; Which introduces ambiguity during type checking. This, in turn, requires making
-- the implicit argument /explicit/ in practice; namely:
-- > _⨾_ {z} Pxz Qzy
--
-- Which is syntactically even less desirable. Hence, in the definition below, `z` is represented
-- explicitly.
data _⨾_ {a b c ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {C : Set c} (L : REL A B ℓ₁) (R : REL B C ℓ₂)
(i : A) (j : C) : Set (a ⊔ b ⊔ c ⊔ ℓ₁ ⊔ ℓ₂) where
⨾: : (k : B) → L i k → R k j → (L ⨾ R) i j
syntax ⨾: k Pik Qkj = Pik ⨾[ k ]⨾ Qkj
-- # Properties
module _ {a b c d ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {C : Set c} {D : Set d}
{P : REL A B ℓ₁} {Q : REL B C ℓ₂} {R : REL C D ℓ₃} where
-- | Composition of binary relations is associative.
⨾-assoc : (P ⨾ Q) ⨾ R ⇔₂ P ⨾ (Q ⨾ R)
⨾-assoc = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : (P ⨾ Q) ⨾ R ⊆₂' P ⨾ (Q ⨾ R)
⊆-proof _ _ ((Pxb ⨾[ b ]⨾ Qbc) ⨾[ c ]⨾ Rcy) = Pxb ⨾[ b ]⨾ (Qbc ⨾[ c ]⨾ Rcy)
⊇-proof : P ⨾ (Q ⨾ R) ⊆₂' (P ⨾ Q) ⨾ R
⊇-proof _ _ (Pxb ⨾[ b ]⨾ (Qbc ⨾[ c ]⨾ Rcy)) = (Pxb ⨾[ b ]⨾ Qbc) ⨾[ c ]⨾ Rcy
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
-- | The composition of a transitive relation with itself is a subset of itself.
⨾-trans-⊆₂ : Transitive R → (R ⨾ R) ⊆₂ R
⨾-trans-⊆₂ transR = ⊆: lemma
where
lemma : (R ⨾ R) ⊆₂' R
lemma _ _ (Rxz ⨾[ z ]⨾ Rzy) = transR Rxz Rzy
-- # Operations
module _ {a b c ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {C : Set c}
{P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL B C ℓ₃} where
⨾-substˡ-⊆₂ : P ⊆₂ Q → (P ⨾ R) ⊆₂ (Q ⨾ R)
⨾-substˡ-⊆₂ (⊆: P⊆Q) = ⊆: ⊆-proof
where
⊆-proof : (P ⨾ R) ⊆₂' (Q ⨾ R)
⊆-proof x y (Pxz ⨾[ z ]⨾ Rzy) = P⊆Q x z Pxz ⨾[ z ]⨾ Rzy
module _ {a b c ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {C : Set c}
{P : REL A B ℓ₁} {Q : REL A B ℓ₂} {R : REL B C ℓ₃} where
⨾-substˡ : P ⇔₂ Q → (P ⨾ R) ⇔₂ (Q ⨾ R)
⨾-substˡ = ⇔₂-compose ⨾-substˡ-⊆₂ ⨾-substˡ-⊆₂
module _ {a b c ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {C : Set c}
{P : REL B C ℓ₁} {Q : REL B C ℓ₂} {R : REL A B ℓ₃} where
⨾-substʳ-⊆₂ : P ⊆₂ Q → (R ⨾ P) ⊆₂ (R ⨾ Q)
⨾-substʳ-⊆₂ (⊆: P⊆Q) = ⊆: ⊆-proof
where
⊆-proof : (R ⨾ P) ⊆₂' (R ⨾ Q)
⊆-proof x y (Rxz ⨾[ z ]⨾ Pzy) = Rxz ⨾[ z ]⨾ P⊆Q z y Pzy
module _ {a b c ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set a} {B : Set b} {C : Set c}
{P : REL B C ℓ₁} {Q : REL B C ℓ₂} {R : REL A B ℓ₃} where
⨾-substʳ : P ⇔₂ Q → (R ⨾ P) ⇔₂ (R ⨾ Q)
⨾-substʳ = ⇔₂-compose ⨾-substʳ-⊆₂ ⨾-substʳ-⊆₂
module _ {a b c ℓ₁ ℓ₂ : Level} {A : Set a} {B : Set b} {C : Set c}
{P : REL A B ℓ₁} {Q : REL B C ℓ₂} where
-- | Expanded definition of flipping the composition of two relations.
⨾-flip : flip (P ⨾ Q) ⇔₂ flip Q ⨾ flip P
⨾-flip = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : flip (P ⨾ Q) ⊆₂' flip Q ⨾ flip P
⊆-proof x y (Pyz ⨾[ z ]⨾ Qzx) = (Qzx ⨾[ z ]⨾ Pyz)
⊇-proof : flip Q ⨾ flip P ⊆₂' flip (P ⨾ Q)
⊇-proof x y (Qzy ⨾[ z ]⨾ Pxz) = (Pxz ⨾[ z ]⨾ Qzy)
|
{
"alphanum_fraction": 0.5332005312,
"avg_line_length": 34.7538461538,
"ext": "agda",
"hexsha": "49fcb37c6e2b0146dd7a9c67213df2c5a32732da",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "sourcedennis/agda-dodo",
"max_forks_repo_path": "src/Dodo/Binary/Composition.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "sourcedennis/agda-dodo",
"max_issues_repo_path": "src/Dodo/Binary/Composition.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "376f0ccee1e1aa31470890e494bcb534324f598a",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "sourcedennis/agda-dodo",
"max_stars_repo_path": "src/Dodo/Binary/Composition.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2084,
"size": 4518
}
|
{-# OPTIONS --allow-unsolved-metas #-}
open import Agda.Builtin.Unit
open import Agda.Builtin.Equality
postulate
A : Set
u₁ u₂ : ⊤
mutual
X : (⊤ → ⊤) → A
X = _
test : X (λ x → u₁) ≡ X (λ x → u₂)
test = refl
|
{
"alphanum_fraction": 0.5739910314,
"avg_line_length": 13.9375,
"ext": "agda",
"hexsha": "1905c814e5e165b69b2bdbda29609847a8d4746a",
"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/Issue3785.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/Issue3785.agda",
"max_line_length": 38,
"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/Issue3785.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 91,
"size": 223
}
|
{- 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
-}
-- RWS monad implementation, and functionality for proving properties about
-- programs written using this RWS monad.
-- It includes constructors for branching code, to aid in the verification.
module Haskell.Modules.RWS where
open import Haskell.Prelude
------------------------------------------------------------------------------
open import Data.Product using (_×_; _,_)
-- (free) RWS : the AST of computations with state `St` reading from an environment
-- `Ev` and producing a list of outputs of type `Wr`
data RWS (Ev Wr St : Set) : Set → Set₁ where
-- Primitive combinators
RWS-return : ∀ {A} → A → RWS Ev Wr St A
RWS-bind : ∀ {A B} → RWS Ev Wr St A → (A → RWS Ev Wr St B) → RWS Ev Wr St B
RWS-gets : ∀ {A} → (St → A) → RWS Ev Wr St A
RWS-put : St → RWS Ev Wr St Unit
RWS-ask : RWS Ev Wr St Ev
RWS-tell : List Wr → RWS Ev Wr St Unit
-- Branching combinators (used for creating more convenient contracts)
RWS-if : ∀ {A} → Guards (RWS Ev Wr St A) → RWS Ev Wr St A
RWS-either : ∀ {A B C}
→ (B → RWS Ev Wr St A) → (C → RWS Ev Wr St A)
→ Either B C → RWS Ev Wr St A
RWS-ebind : ∀ {A B C}
→ RWS Ev Wr St (Either C A)
→ (A → RWS Ev Wr St (Either C B)) → RWS Ev Wr St (Either C B)
RWS-maybe : ∀ {A B}
→ (RWS Ev Wr St A) → (B → RWS Ev Wr St A) → Maybe B → RWS Ev Wr St A
private
variable
Ev Wr St : Set
A B C : Set
-- From this instance declaration, we get _<$>_, pure, and _<*>_ also.
instance
RWS-Monad : Monad (RWS Ev Wr St)
Monad.return RWS-Monad = RWS-return
Monad._>>=_ RWS-Monad = RWS-bind
gets : (St → A) → RWS Ev Wr St A
gets = RWS-gets
get : RWS Ev Wr St St
get = gets id
put : St → RWS Ev Wr St Unit
put = RWS-put
modify : (St → St) → RWS Ev Wr St Unit
modify f = do
st ← get
put (f st)
ask : RWS Ev Wr St Ev
ask = RWS-ask
tell : List Wr → RWS Ev Wr St Unit
tell = RWS-tell
void : RWS Ev Wr St A → RWS Ev Wr St Unit
void m = do
_ ← m
pure unit
-- To execute an RWS program, you provide an environment and prestate.
-- This produces a result value, poststate, and list of outputs.
RWS-run : RWS Ev Wr St A → Ev → St → A × St × List Wr
RWS-run (RWS-return x) ev st = x , st , []
RWS-run (RWS-bind m f) ev st
with RWS-run m ev st
...| x₁ , st₁ , outs₁
with RWS-run (f x₁) ev st₁
...| x₂ , st₂ , outs₂ = x₂ , st₂ , outs₁ ++ outs₂
RWS-run (RWS-gets f) ev st = f st , st , []
RWS-run (RWS-put st) ev _ = unit , st , []
RWS-run RWS-ask ev st = ev , st , []
RWS-run (RWS-tell outs) ev st = unit , st , outs
RWS-run (RWS-if (clause (b ≔ c) gs)) ev st =
if toBool b then RWS-run c ev st else RWS-run (RWS-if gs) ev st
RWS-run (RWS-if (otherwise≔ c)) ev st = RWS-run c ev st
RWS-run (RWS-either f₁ f₂ (Left x) ) ev st = RWS-run (f₁ x) ev st
RWS-run (RWS-either f₁ f₂ (Right y)) ev st = RWS-run (f₂ y) ev st
RWS-run (RWS-ebind m f) ev st
with RWS-run m ev st
...| Left c , st₁ , outs₁ = Left c , st₁ , outs₁
...| Right a , st₁ , outs₁
with RWS-run (f a) ev st₁
...| r , st₂ , outs₂ = r , st₂ , outs₁ ++ outs₂
RWS-run (RWS-maybe f₁ f₂ nothing ) ev st = RWS-run f₁ ev st
RWS-run (RWS-maybe f₁ f₂ (just x)) ev st = RWS-run (f₂ x) ev st
-- Accessors for the result, poststate, and outputs.
RWS-result : RWS Ev Wr St A → Ev → St → A
RWS-result m ev st = fst (RWS-run m ev st)
RWS-post : RWS Ev Wr St A → Ev → St → St
RWS-post m ev st = fst (snd (RWS-run m ev st))
RWS-outs : RWS Ev Wr St A → Ev → St → List Wr
RWS-outs m ev st = snd (snd (RWS-run m ev st))
|
{
"alphanum_fraction": 0.5375886525,
"avg_line_length": 38.4545454545,
"ext": "agda",
"hexsha": "27db2bfaac3f8aee196e3268cf9c3cf59402a62a",
"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/Haskell/Modules/RWS.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/Haskell/Modules/RWS.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/Haskell/Modules/RWS.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1371,
"size": 4230
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Functions.Definition
module Orders.Total.Definition {a : _} (carrier : Set a) where
open import Orders.Partial.Definition carrier
record TotalOrder {b : _} : Set (a ⊔ lsuc b) where
field
order : PartialOrder {b}
_<_ : Rel carrier
_<_ = PartialOrder._<_ order
_≤_ : Rel carrier
_≤_ a b = (a < b) || (a ≡ b)
field
totality : (a b : carrier) → ((a < b) || (b < a)) || (a ≡ b)
min : carrier → carrier → carrier
min a b with totality a b
min a b | inl (inl a<b) = a
min a b | inl (inr b<a) = b
min a b | inr a=b = a
max : carrier → carrier → carrier
max a b with totality a b
max a b | inl (inl a<b) = b
max a b | inl (inr b<a) = a
max a b | inr a=b = b
irreflexive = PartialOrder.irreflexive order
<Transitive = PartialOrder.<Transitive order
<WellDefined = PartialOrder.<WellDefined order
|
{
"alphanum_fraction": 0.6353535354,
"avg_line_length": 26.7567567568,
"ext": "agda",
"hexsha": "35238ab26e40f8c0daf597005a42d356076cbb06",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Orders/Total/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Orders/Total/Definition.agda",
"max_line_length": 64,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Orders/Total/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 346,
"size": 990
}
|
{-# OPTIONS --safe #-}
open import Generics.Prelude
open import Generics.Telescope
open import Generics.Desc
open import Generics.HasDesc
open import Generics.All
module Generics.Constructions.Mu
{P I ℓ} (A : Indexed P I ℓ) (H : HasDesc A)
(open HasDesc H)
{p} where
private
variable
V : ExTele P
i : ⟦ I ⟧tel p
v : ⟦ V ⟧tel p
open import Generics.Mu public
toData : (x : ⟦ D ⟧Data A′ (p , i)) → AllDataω Acc D x → μ D (p , i)
to-wf : (x : A′ (p , i)) → Acc x → μ D (p , i)
to-wf x (acc a) = toData (split x) a
toData (k , x) a = ⟨ k , toCon (lookupCon D k) x a ⟩
where
toIndArg : (C : ConDesc P V I)
(x : ⟦ C ⟧IndArg A′ (p , v))
→ AllIndArgω Acc C x
→ ⟦ C ⟧IndArgω (μ D) (p , v)
toIndArg (var _) x a = to-wf x a
toIndArg (π ai _ C) x a s = toIndArg C (app< ai > x s) (a s)
toIndArg (A ⊗ B) (xa , xb) (aa , ab)
= toIndArg A xa aa , toIndArg B xb ab
toCon : (C : ConDesc P V I)
(x : ⟦ C ⟧Con A′ (p , v , i))
→ AllConω Acc C x
→ ⟦ C ⟧Conω (μ D) (p , v , i)
toCon (var _) refl _ = liftω refl
toCon (π _ _ C) (s , x) a = s , toCon C x a
toCon (A ⊗ B) (xa , xb) (aa , ab)
= toIndArg A xa aa , toCon B xb ab
to : A′ (p , i) → μ D (p , i)
to x = to-wf x (wf x)
from : μ D (p , i) → A′ (p , i)
fromIndArg : (C : ConDesc P V I)
→ ⟦ C ⟧IndArgω (μ D) (p , v)
→ ⟦ C ⟧IndArg A′ (p , v)
fromIndArg (var _) x = from x
fromIndArg (π ai S C) x = fun< ai > λ s → fromIndArg C (x s)
fromIndArg (A ⊗ B) (xa , xb) = fromIndArg A xa , fromIndArg B xb
fromCon : (C : ConDesc P V I)
→ ⟦ C ⟧Conω (μ D) (p , v , i)
→ ⟦ C ⟧Con A′ (p , v , i)
fromCon (var _) (liftω refl) = refl
fromCon (π _ S C) (s , x) = s , fromCon C x
fromCon (A ⊗ B) (xa , xb) = fromIndArg A xa , fromCon B xb
from ⟨ k , x ⟩ = constr (k , fromCon (lookupCon D k) x)
|
{
"alphanum_fraction": 0.5113098369,
"avg_line_length": 27.9558823529,
"ext": "agda",
"hexsha": "264b4d77b85dddc84f2b698eec009a3af17ff95a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-01-14T10:35:16.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-08T08:32:42.000Z",
"max_forks_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/generics",
"max_forks_repo_path": "src/Generics/Constructions/Mu.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T10:48:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-09-13T07:33:50.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "flupe/generics",
"max_issues_repo_path": "src/Generics/Constructions/Mu.agda",
"max_line_length": 68,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "db764f858d908aa39ea4901669a6bbce1525f757",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/generics",
"max_stars_repo_path": "src/Generics/Constructions/Mu.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T09:35:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-08T15:10:20.000Z",
"num_tokens": 790,
"size": 1901
}
|
------------------------------------------------------------------------------
-- A simple network using the Agda standard library
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- From (Sander, 1992, pp. 68-69).
module FOT.FOTC.Program.ABP.SimpleNetwork-SL where
open import Codata.Musical.Stream
open import Data.Bool.Base
------------------------------------------------------------------------------
postulate
f₁ : {A : Set} → Stream A → Stream A → Stream A
f₂ : {A : Set} → Stream A → Stream A
{-# TERMINATING #-}
trans : {A : Set} → Stream A → Stream A
trans {A} is = os
where
ys os : Stream A
ys = f₁ os is
os = f₂ ys
Ty : Set → Set
Ty A = (Stream A → Stream A → Stream A) → (Stream A → Stream A) →
Stream A → Stream A
{-# TERMINATING #-}
trans' hys : {A : Set} → Ty A
trans' f₁ f₂ is = f₂ (hys f₁ f₂ is)
hys f₁ f₂ is = f₁ (trans' f₁ f₂ is) is
------------------------------------------------------------------------------
-- References
--
-- Sander, Herbert P. (1992). A Logic of Functional Programs with an
-- Application to Concurrency. PhD thesis. Department of Computer
-- Sciences: Chalmers University of Technology and University of
-- Gothenburg.
|
{
"alphanum_fraction": 0.4810578985,
"avg_line_length": 28.5510204082,
"ext": "agda",
"hexsha": "de23cea9cec55b0cb508cae09d19590075cdd5ab",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/ABP/SimpleNetwork-SL.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/ABP/SimpleNetwork-SL.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/ABP/SimpleNetwork-SL.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": 336,
"size": 1399
}
|
postulate
F : Set₂ → Set₃
#_ : Set₁ → Set₂
!_ : Set₀ → Set₁
infix 1 F
infix 2 #_
infix 3 !_
syntax F x = ! x
ok₁ : Set₁ → Set₃
ok₁ X = ! # X
ok₂ : Set₀ → Set₂
ok₂ X = # ! X
|
{
"alphanum_fraction": 0.4711538462,
"avg_line_length": 12.2352941176,
"ext": "agda",
"hexsha": "d8f41dfcf5ec4412922a58a0162cfd3aecfc01a3",
"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/Issue1436-7.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/Issue1436-7.agda",
"max_line_length": 20,
"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/Issue1436-7.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": 99,
"size": 208
}
|
{- Category of sets -}
module CategoryTheory.Instances.Sets where
open import CategoryTheory.Categories
open import CategoryTheory.BCCCs
import Function as F using (_∘_)
open import Data.Unit using () renaming (⊤ to top) public
open import Data.Product public
open import Data.Empty using (⊥-elim) renaming (⊥ to bot) public
open import Data.Sum
-- Category of sets.
𝕊et : Category lzero
𝕊et = record
{ obj = Set
; _~>_ = λ a b -> (a -> b)
; id = λ a -> a
; _∘_ = λ g f a -> g (f a)
; _≈_ = λ f g -> ∀ {a} -> f a ≡ g a
; id-left = refl
; id-right = refl
; ∘-assoc = refl
; ≈-equiv = record { refl = refl
; sym = λ p → sym p
; trans = λ p q → trans p q }
; ≈-cong = ≈-cong-𝕊
}
where
≈-cong-𝕊 : ∀{A B C : Set} {f f′ : A -> B} {g g′ : B -> C}
-> (∀ {a} -> f a ≡ f′ a)
-> (∀ {b} -> g b ≡ g′ b)
-> (∀ {a} -> g (f a) ≡ g′ (f′ a))
≈-cong-𝕊 {f′ = f′} fe ge {a′} rewrite fe {a′} | ge {f′ a′} = refl
-- Bicartesian closed structure
𝕊et-BCCC : BicartesianClosed 𝕊et
𝕊et-BCCC = record
{ cart = record
{ term = record
{ ⊤ = top
; ! = λ {A} _ → top.tt
; !-unique = λ m → refl
}
; prod = λ A B → record
{ A⊗B = A × B
; π₁ = proj₁
; π₂ = proj₂
; ⟨_,_⟩ = <_,_>
; π₁-comm = refl
; π₂-comm = refl
; ⊗-unique = λ pr1 pr2 → unique-cart (ext λ x → pr1 {x}) (ext λ x → pr2 {x})
}
}
; cocart = record
{ init = record
{ ⊥ = bot
; ¡ = ⊥-elim
; ¡-unique = λ {A} m → λ {}
}
; sum = λ A B → record
{ A⊕B = A ⊎ B
; ι₁ = inj₁
; ι₂ = inj₂
; [_⁏_] = [_,_]
; ι₁-comm = λ {S} {i₁} {i₂} {a} → refl
; ι₂-comm = λ {S} {i₁} {i₂} {a} → refl
; ⊕-unique = λ {S} {i₁} {i₂} {m} pr1 pr2
-> unique-cocart {m = m} (ext λ x → pr1 {x}) (ext λ x → pr2 {x})
}
}
; closed = record
{ exp = λ A B → record
{ A⇒B = A -> B
; eval = λ fa → proj₁ fa (proj₂ fa)
; Λ = λ f a b → f (a , b)
; Λ-comm = refl
; Λ-unique = λ pr → λ {a} -> unique-closed (ext λ x → pr {x})
; Λ-cong = λ pr → ext (λ _ → pr)
}
}
}
where
unique-cart : ∀{A B P : Set}{a}
-> {p₁ : P -> A} {p₂ : P -> B} {m : P -> A × B}
-> proj₁ F.∘ m ≡ p₁ -> proj₂ F.∘ m ≡ p₂
-> < p₁ , p₂ > a ≡ m a
unique-cart refl refl = refl
unique-cocart : ∀{A B S : Set}{a}
-> {i₁ : A -> S} {i₂ : B -> S} {m : A ⊎ B -> S}
-> m F.∘ inj₁ ≡ i₁ -> m F.∘ inj₂ ≡ i₂
-> [ i₁ , i₂ ] a ≡ m a
unique-cocart {a = inj₁ x} refl refl = refl
unique-cocart {a = inj₂ y} refl refl = refl
open Category 𝕊et
unique-closed : ∀{A B E : Set}{a}
-> {e : E × A -> B} {m : E -> (A -> B)}
-> (λ fa → proj₁ fa (proj₂ fa)) ∘ < m ∘ proj₁ , proj₂ > ≡ e
-> (λ b → e (a , b)) ≡ m a
unique-closed refl = refl
|
{
"alphanum_fraction": 0.3865853659,
"avg_line_length": 32.1568627451,
"ext": "agda",
"hexsha": "2009ff54798b7f4277f8f910ede7df1b769279ea",
"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": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DimaSamoz/temporal-type-systems",
"max_forks_repo_path": "src/CategoryTheory/Instances/Sets.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"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": "DimaSamoz/temporal-type-systems",
"max_issues_repo_path": "src/CategoryTheory/Instances/Sets.agda",
"max_line_length": 88,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7d993ba55e502d5ef8707ca216519012121a08dd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DimaSamoz/temporal-type-systems",
"max_stars_repo_path": "src/CategoryTheory/Instances/Sets.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-04T09:33:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-31T20:37:04.000Z",
"num_tokens": 1224,
"size": 3280
}
|
------------------------------------------------------------------------------
-- First-order Peano arithmetic
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Axiomatic.Standard.README where
-- Formalization of first-order Peano arithmetic using Agda postulates
-- for the non-logical constants and the Peano's axioms, and using
-- axioms based on the propositional equality (see, for example,
-- (Machover 1996, p. 263), (Hájek and Pudlák 1998, p. 28).
------------------------------------------------------------------------------
-- The axioms
open import PA.Axiomatic.Standard.Base
-- Some properties
open import PA.Axiomatic.Standard.PropertiesATP
open import PA.Axiomatic.Standard.PropertiesI
------------------------------------------------------------------------------
-- References
--
-- Machover, Moshé (1996). Set theory, Logic and their
-- Limitations. Cambridge University Press.
-- Hájek, Petr and Pudlák, Pavel (1998). Metamathematics of
-- First-Order Arithmetic. 2nd printing. Springer.
|
{
"alphanum_fraction": 0.5248979592,
"avg_line_length": 37.1212121212,
"ext": "agda",
"hexsha": "30af30eb4ba21e494972196eacfc0305d30c8310",
"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/PA/Axiomatic/Standard/README.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/PA/Axiomatic/Standard/README.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/PA/Axiomatic/Standard/README.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": 244,
"size": 1225
}
|
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Parameters where
data List (A : Set) : Set where
[] : List A
_∷_ : A → List A → List A
-- Error: The type of the constructor does not fit in the sort of the
-- datatype, since Set₁ is not less or equal than Set when checking
-- the constructor [] in the declaration of List₁
--
-- data List₁ : Set → Set where
-- [] : {A : Set} → List₁ A
-- _∷_ : {A : Set} → A → List₁ A → List₁ A
data List₁ : Set → Set₁ where
[] : {A : Set} → List₁ A
_∷_ : {A : Set} → A → List₁ A → List₁ A
|
{
"alphanum_fraction": 0.5623145401,
"avg_line_length": 29.3043478261,
"ext": "agda",
"hexsha": "f7fb48a465d960166e872a84c13cb9e0f9c24849",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/Parameters.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/Parameters.agda",
"max_line_length": 69,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/Parameters.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": 207,
"size": 674
}
|
open import Agda.Builtin.Reflection
open import Agda.Builtin.String
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Equality
open import Agda.Builtin.Sigma
data Wrap (A : Set) : Set where
[_] : A → Wrap A
macro
give : Wrap Term → Term → TC ⊤
give [ t ] hole = unify hole t
pattern vArg x = arg (arg-info visible relevant) x
pattern hArg x = arg (arg-info hidden relevant) x
-- Naming the variable "_" doesn't affect the deBruijn indices for lambda and pi
`id : Term
`id = lam visible (abs "_" (var 0 []))
`IdType : Term
`IdType = pi (hArg (agda-sort (lit 0))) (abs "_" (pi (vArg (var 0 [])) (abs "_" (var 1 []))))
id : give [ `IdType ]
id = give [ `id ]
id-ok : (λ {A : Set} (x : A) → x) ≡ id
id-ok = refl
-- Underscores should behave the same for clauses as for lambda and pi
idClause : Clause
idClause = clause
(("_" , vArg unknown) ∷ ("_" , hArg unknown) ∷ [])
(hArg (var 1) ∷ vArg (var 0) ∷ [])
(var 0 [])
infixr 4 _>>=_
_>>=_ = bindTC
unquoteDecl id₂ =
declareDef (vArg id₂) `IdType >>= λ _ →
defineFun id₂ (idClause ∷ [])
id₂-ok : (λ {A : Set} (x : A) → x) ≡ id₂
id₂-ok = refl
|
{
"alphanum_fraction": 0.615004122,
"avg_line_length": 23.7843137255,
"ext": "agda",
"hexsha": "d4da3d57daeff99384d9803a391006bff60d07ef",
"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/Issue2129.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/Issue2129.agda",
"max_line_length": 93,
"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/Issue2129.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 414,
"size": 1213
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Some derivable properties
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Algebra.Properties.CommutativeMonoid {g₁ g₂} (M : CommutativeMonoid g₁ g₂) where
open import Algebra.Operations.CommutativeMonoid M
open import Algebra.Solver.CommutativeMonoid M
open import Relation.Binary as B using (_Preserves_⟶_)
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Data.Product
open import Data.Nat using (ℕ; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Data.List as List using ([]; _∷_)
import Data.Fin.Properties as FP
open import Data.Fin.Permutation as Perm using (Permutation; Permutation′; _⟨$⟩ˡ_; _⟨$⟩ʳ_)
open import Data.Fin.Permutation.Components as PermC
open import Data.Table as Table
open import Data.Table.Relation.Binary.Equality as TE using (_≗_)
open import Data.Unit using (tt)
import Data.Table.Properties as TP
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Nullary.Decidable using (⌊_⌋)
open CommutativeMonoid M
renaming
( ε to 0#
; _∙_ to _+_
; ∙-cong to +-cong
; ∙-congˡ to +-congˡ
; ∙-congʳ to +-congʳ
; identityˡ to +-identityˡ
; identityʳ to +-identityʳ
; assoc to +-assoc
; comm to +-comm
)
open import Algebra.FunctionProperties _≈_
open import Relation.Binary.Reasoning.Setoid setoid
module _ {n} where
open B.Setoid (TE.setoid setoid n) public
using ()
renaming (_≈_ to _≋_)
-- When summing over a function from a finite set, we can pull out any value and move it to the front.
sumₜ-remove : ∀ {n} {i : Fin (suc n)} t → sumₜ t ≈ lookup t i + sumₜ (remove i t)
sumₜ-remove {_} {zero} t = refl
sumₜ-remove {zero} {suc ()} t
sumₜ-remove {suc n} {suc i} t′ =
begin
t₀ + ∑t ≈⟨ +-congˡ (sumₜ-remove t) ⟩
t₀ + (tᵢ + ∑t′) ≈⟨ solve 3 (λ x y z → x ⊕ (y ⊕ z) ⊜ y ⊕ (x ⊕ z)) refl t₀ tᵢ ∑t′ ⟩
tᵢ + (t₀ + ∑t′) ∎
where
t = tail t′
t₀ = head t′
tᵢ = lookup t i
∑t = sumₜ t
∑t′ = sumₜ (remove i t)
-- '_≈_' is a congruence over 'sumTable n'.
sumₜ-cong-≈ : ∀ {n} → sumₜ {n} Preserves _≋_ ⟶ _≈_
sumₜ-cong-≈ {zero} p = refl
sumₜ-cong-≈ {suc n} p = +-cong (p _) (sumₜ-cong-≈ (p ∘ suc))
-- '_≡_' is a congruence over 'sum n'.
sumₜ-cong-≡ : ∀ {n} → sumₜ {n} Preserves _≗_ ⟶ _≡_
sumₜ-cong-≡ {zero} p = P.refl
sumₜ-cong-≡ {suc n} p = P.cong₂ _+_ (p _) (sumₜ-cong-≡ (p ∘ suc))
-- If addition is idempotent on a particular value 'x', then summing over a
-- nonzero number of copies of 'x' gives back 'x'.
sumₜ-idem-replicate : ∀ n {x} → _+_ IdempotentOn x → sumₜ (replicate {n = suc n} x) ≈ x
sumₜ-idem-replicate zero idem = +-identityʳ _
sumₜ-idem-replicate (suc n) {x} idem = begin
x + (x + sumₜ (replicate {n = n} x)) ≈⟨ sym (+-assoc _ _ _) ⟩
(x + x) + sumₜ (replicate {n = n} x) ≈⟨ +-congʳ idem ⟩
x + sumₜ (replicate {n = n} x) ≈⟨ sumₜ-idem-replicate n idem ⟩
x ∎
-- The sum over the constantly zero function is zero.
sumₜ-zero : ∀ n → sumₜ (replicate {n = n} 0#) ≈ 0#
sumₜ-zero n = begin
sumₜ (replicate {n = n} 0#) ≈⟨ sym (+-identityˡ _) ⟩
0# + sumₜ (replicate {n = n} 0#) ≈⟨ sumₜ-idem-replicate n (+-identityˡ 0#) ⟩
0# ∎
-- The '∑' operator distributes over addition.
∑-distrib-+ : ∀ n (f g : Fin n → Carrier) → ∑[ i < n ] (f i + g i) ≈ ∑[ i < n ] f i + ∑[ i < n ] g i
∑-distrib-+ zero f g = sym (+-identityˡ _)
∑-distrib-+ (suc n) f g = begin
f₀ + g₀ + ∑fg ≈⟨ +-assoc _ _ _ ⟩
f₀ + (g₀ + ∑fg) ≈⟨ +-congˡ (+-congˡ (∑-distrib-+ n _ _)) ⟩
f₀ + (g₀ + (∑f + ∑g)) ≈⟨ solve 4 (λ a b c d → a ⊕ (c ⊕ (b ⊕ d)) ⊜ (a ⊕ b) ⊕ (c ⊕ d)) refl f₀ ∑f g₀ ∑g ⟩
(f₀ + ∑f) + (g₀ + ∑g) ∎
where
f₀ = f zero
g₀ = g zero
∑f = ∑[ i < n ] f (suc i)
∑g = ∑[ i < n ] g (suc i)
∑fg = ∑[ i < n ] (f (suc i) + g (suc i))
-- The '∑' operator commutes with itself.
∑-comm : ∀ n m (f : Fin n → Fin m → Carrier) → ∑[ i < n ] ∑[ j < m ] f i j ≈ ∑[ j < m ] ∑[ i < n ] f i j
∑-comm zero m f = sym (sumₜ-zero m)
∑-comm (suc n) m f = begin
∑[ j < m ] f zero j + ∑[ i < n ] ∑[ j < m ] f (suc i) j ≈⟨ +-congˡ (∑-comm n m _) ⟩
∑[ j < m ] f zero j + ∑[ j < m ] ∑[ i < n ] f (suc i) j ≈⟨ sym (∑-distrib-+ m _ _) ⟩
∑[ j < m ] (f zero j + ∑[ i < n ] f (suc i) j) ∎
-- Any permutation of a table has the same sum as the original.
sumₜ-permute : ∀ {m n} t (π : Permutation m n) → sumₜ t ≈ sumₜ (permute π t)
sumₜ-permute {zero} {zero} t π = refl
sumₜ-permute {zero} {suc n} t π = contradiction π (Perm.refute λ())
sumₜ-permute {suc m} {zero} t π = contradiction π (Perm.refute λ())
sumₜ-permute {suc m} {suc n} t π = begin
sumₜ t ≡⟨⟩
lookup t 0i + sumₜ (remove 0i t) ≡⟨ P.cong₂ _+_ (P.cong (lookup t) (P.sym (Perm.inverseʳ π))) P.refl ⟩
lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (remove 0i t) ≈⟨ +-congˡ (sumₜ-permute (remove 0i t) (Perm.remove (π ⟨$⟩ˡ 0i) π)) ⟩
lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (permute (Perm.remove (π ⟨$⟩ˡ 0i) π) (remove 0i t)) ≡⟨ P.cong₂ _+_ P.refl (sumₜ-cong-≡ (P.sym ∘ TP.remove-permute π 0i t)) ⟩
lookup πt (π ⟨$⟩ˡ 0i) + sumₜ (remove (π ⟨$⟩ˡ 0i) πt) ≈⟨ sym (sumₜ-remove (permute π t)) ⟩
sumₜ πt ∎
where
0i = zero
πt = permute π t
∑-permute : ∀ {m n} f (π : Permutation m n) → ∑[ i < n ] f i ≈ ∑[ i < m ] f (π ⟨$⟩ʳ i)
∑-permute = sumₜ-permute ∘ tabulate
-- If the function takes the same value at 'i' and 'j', then transposing 'i' and
-- 'j' then selecting 'j' is the same as selecting 'i'.
select-transpose : ∀ {n} t (i j : Fin n) → lookup t i ≈ lookup t j → ∀ k → (lookup (select 0# j t) ∘ PermC.transpose i j) k ≈ lookup (select 0# i t) k
select-transpose _ i j e k with k FP.≟ i
... | yes p rewrite P.≡-≟-identity FP._≟_ {j} P.refl = sym e
... | no ¬p with k FP.≟ j
... | no ¬q rewrite proj₂ (P.≢-≟-identity FP._≟_ ¬q) = refl
... | yes q rewrite proj₂ (P.≢-≟-identity FP._≟_
(¬p ∘ P.trans q ∘ P.sym)) = refl
-- Summing over a pulse gives you the single value picked out by the pulse.
sumₜ-select : ∀ {n i} (t : Table Carrier n) → sumₜ (select 0# i t) ≈ lookup t i
sumₜ-select {zero} {()}
sumₜ-select {suc n} {i} t = begin
sumₜ (select 0# i t) ≈⟨ sumₜ-remove {i = i} (select 0# i t) ⟩
lookup (select 0# i t) i + sumₜ (remove i (select 0# i t)) ≡⟨ P.cong₂ _+_ (TP.select-lookup t) (sumₜ-cong-≡ (TP.select-remove i t)) ⟩
lookup t i + sumₜ (replicate {n = n} 0#) ≈⟨ +-congˡ (sumₜ-zero n) ⟩
lookup t i + 0# ≈⟨ +-identityʳ _ ⟩
lookup t i ∎
-- Converting to a table then summing is the same as summing the original list
sumₜ-fromList : ∀ xs → sumₜ (fromList xs) ≡ sumₗ xs
sumₜ-fromList [] = P.refl
sumₜ-fromList (x ∷ xs) = P.cong (_ +_) (sumₜ-fromList xs)
-- Converting to a list then summing is the same as summing the original table
sumₜ-toList : ∀ {n} (t : Table Carrier n) → sumₜ t ≡ sumₗ (toList t)
sumₜ-toList {zero} _ = P.refl
sumₜ-toList {suc n} _ = P.cong (_ +_) (sumₜ-toList {n} _)
|
{
"alphanum_fraction": 0.539166885,
"avg_line_length": 42.4111111111,
"ext": "agda",
"hexsha": "c1eee5255809c804193aa28828bd450a18b5d786",
"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/Algebra/Properties/CommutativeMonoid.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/Algebra/Properties/CommutativeMonoid.agda",
"max_line_length": 156,
"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/Algebra/Properties/CommutativeMonoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3059,
"size": 7634
}
|
{-# OPTIONS --without-K #-}
module Cauchy where
-- Definitions for permutations in the Cauchy representation
open import Relation.Binary.PropositionalEquality using (subst)
open import Data.Nat.Properties.Simple
using (+-right-identity; +-suc; +-assoc; +-comm;
*-assoc; *-comm; *-right-zero; distribʳ-*-+; +-*-suc)
open import Data.Bool using (Bool; false; true)
open import Data.Nat using (ℕ; suc; _+_; _*_)
open import Data.Fin
using (Fin; zero; suc; toℕ; fromℕ;
raise; inject+; inject₁; inject≤; _≻toℕ_)
open import Data.Vec
using (Vec; tabulate; []; _∷_; lookup; allFin)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Function using (id)
open import Proofs using (i*n+k≤m*n; trans≤; refl′; splitVOp+)
------------------------------------------------------------------------------
-- Semantic representations of permutations
-- One possibility of course is to represent them as functions but
-- this is a poor representation and eventually requires function
-- extensionality.
-- Representation III
-- This is the 2 line Cauchy representation. The first line is in
-- canonical order and implicit in the indices of the vector
Cauchy : ℕ → Set
Cauchy n = Vec (Fin n) n
------------------------------------------------------------------------------
-- Elementary permutations in the Cauchy representation
emptycauchy : Cauchy 0
emptycauchy = []
idcauchy : (n : ℕ) → Cauchy n
idcauchy = allFin
-- Sequential composition
scompcauchy : ∀ {n} → Cauchy n → Cauchy n → Cauchy n
scompcauchy {n} perm₁ perm₂ =
tabulate (λ i → lookup (lookup i perm₁) perm₂)
-- swap the first m elements with the last n elements
-- [ v₀ , v₁ , v₂ , ... , vm-1 , vm , vm₊₁ , ... , vm+n-1 ]
-- ==>
-- [ vm , vm₊₁ , ... , vm+n-1 , v₀ , v₁ , v₂ , ... , vm-1 ]
id+ : ∀ {m n} → Fin (n + m) → Fin (m + n)
id+ {m} {n} x = subst Fin (+-comm n m) x
swap+cauchy : (m n : ℕ) → Cauchy (m + n)
swap+cauchy m n = splitVOp+ {m} {n} {f = id+ {m} {n}}
-- Parallel additive composition
-- append both permutations but adjust the indices in the second
-- permutation by the size of the first type so that it acts on the
-- second part of the vector
pcompcauchy : ∀ {m n} → Cauchy m → Cauchy n → Cauchy (m + n)
pcompcauchy {m} {n} α β = mapV (inject+ n) α ++V mapV (raise m) β
-- Tensor multiplicative composition
-- Transpositions in α correspond to swapping entire rows
-- Transpositions in β correspond to swapping entire columns
tcompcauchy : ∀ {m n} → Cauchy m → Cauchy n → Cauchy (m * n)
tcompcauchy {m} {n} α β =
concatV
(mapV
(λ b →
mapV (λ d → inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)) β)
α)
-- swap⋆
--
-- This is essentially the classical problem of in-place matrix transpose:
-- "http://en.wikipedia.org/wiki/In-place_matrix_transposition"
-- Given m and n, the desired permutation in Cauchy representation is:
-- P(i) = m*n-1 if i=m*n-1
-- = m*i mod m*n-1 otherwise
transposeIndex : (m n : ℕ) →
(b : Fin m) → (d : Fin n) → Fin (m * n)
transposeIndex m n b d =
inject≤
(fromℕ (toℕ d * m + toℕ b))
(trans≤ (i*n+k≤m*n d b) (refl′ (*-comm n m)))
swap⋆cauchy : (m n : ℕ) → Cauchy (m * n)
swap⋆cauchy m n =
concatV (mapV
(λ b → mapV (λ d → transposeIndex m n b d) (allFin n))
(allFin m))
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.5891291642,
"avg_line_length": 32.2830188679,
"ext": "agda",
"hexsha": "9d00d9b2f2c49e52d5be209345d8607b9d7d73c0",
"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/Cauchy.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/Cauchy.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/Cauchy.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": 1091,
"size": 3422
}
|
module Issue329c where
private
infixl 0 D Undeclared
data D : Set where
|
{
"alphanum_fraction": 0.7435897436,
"avg_line_length": 11.1428571429,
"ext": "agda",
"hexsha": "8bcb815f1137058d1c5cf02b594b6b3a2e0d164a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue329c.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/Issue329c.agda",
"max_line_length": 23,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue329c.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": 26,
"size": 78
}
|
{-# OPTIONS --cubical --safe --guardedness --postfix-projections #-}
module Codata.Stream where
open import Prelude
open import Data.List using (List; _∷_; [])
open import Data.List.Kleene
import Data.List.Kleene.Membership as Kleene
open import Data.Fin
infixr 5 _◃_
record Stream (A : Type a) : Type a where
constructor _◃_
coinductive
field
head : A
tail : Stream A
open Stream public
Stream′ : Type a → Type a
Stream′ A = ℕ → A
_!_ : Stream A → Stream′ A
xs ! zero = xs .head
xs ! suc n = xs .tail ! n
tabulate : Stream′ A → Stream A
tabulate xs .head = xs zero
tabulate xs .tail = tabulate (xs ∘ suc)
linv : (xs : Stream A) → tabulate (xs !_) ≡ xs
linv xs i .head = xs .head
linv xs i .tail = linv (xs .tail) i
rinv : (xs : Stream′ A) → (tabulate xs !_) ≡ xs
rinv xs i zero = xs zero
rinv xs i (suc n) = rinv (xs ∘ suc) i n
stream : Stream A ⇔ Stream′ A
stream .fun = _!_
stream .inv = tabulate
stream .rightInv = rinv
stream .leftInv = linv
-- infixr 5 _∈_
-- _∈_ : A → Stream A → Type _
-- x ∈ xs = fiber xs x
-- toList : ℕ → Stream A → List A
-- toList zero xs = []
-- toList (suc n) xs = xs zero ∷ toList n (xs ∘ suc)
-- mutual
-- concat⋆ : A ⋆ → Stream (A ⁺) → Stream A
-- concat⋆ [] xs = concat⁺ (xs zero) (xs ∘ suc)
-- concat⋆ (∹ x) xs = concat⁺ x xs
-- concat⁺ : A ⁺ → Stream (A ⁺) → Stream A
-- concat⁺ x xs zero = x .head
-- concat⁺ x xs (suc n) = concat⋆ (x .tail) xs n
-- concat : Stream (A ⁺) → Stream A
-- concat xs = concat⁺ (xs zero) (xs ∘ suc)
-- infixr 5 _∈²_
-- _∈²_ : A → Stream (A ⁺) → Type _
-- x ∈² xs = ∃ n x Kleene.∈⁺ xs n
-- mutual
-- ◇++⋆ : ∀ (x : A) y ys → x Kleene.∈⋆ y → x ∈ concat⋆ y ys
-- ◇++⋆ x (∹ y) ys x∈y = ◇++⁺ x y ys x∈y
-- ◇++⁺ : ∀ (x : A) y ys → x Kleene.∈⁺ y → x ∈ concat⁺ y ys
-- ◇++⁺ x y ys (f0 , x∈y) = zero , x∈y
-- ◇++⁺ x y ys (fs n , x∈y) = let m , p = ◇++⋆ x (y .tail) ys (n , x∈y) in suc m , p
-- mutual
-- ++◇⋆ : ∀ (x : A) y ys → x ∈ concat ys → x ∈ concat⋆ y ys
-- ++◇⋆ x [] ys x∈ys = x∈ys
-- ++◇⋆ x (∹ y) ys x∈ys = ++◇⁺ x y ys x∈ys
-- ++◇⁺ : ∀ (x : A) y ys → x ∈ concat ys → x ∈ concat⁺ y ys
-- ++◇⁺ x y ys x∈ys = let n , p = ++◇⋆ x (y .tail) ys x∈ys in suc n , p
-- concat-∈ : ∀ (x : A) xs → x ∈² xs → x ∈ concat xs
-- concat-∈ x xs (zero , x∈xs) = ◇++⁺ x (xs zero) (xs ∘ suc) x∈xs
-- concat-∈ x xs (suc n , x∈xs) = ++◇⁺ x (xs zero) (xs ∘ suc) (concat-∈ x (xs ∘ suc) (n , x∈xs))
|
{
"alphanum_fraction": 0.5268817204,
"avg_line_length": 26.8666666667,
"ext": "agda",
"hexsha": "9edd981047315f3f75a1e9c40c282a43747f0968",
"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": "Codata/Stream.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": "Codata/Stream.agda",
"max_line_length": 96,
"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": "Codata/Stream.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": 1079,
"size": 2418
}
|
------------------------------------------------------------------------------
-- Axiomatic Peano arithmetic base
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- Mendelson's axioms for first-order Peano arithmetic [Mendelson,
-- 1977, p. 155].
-- Elliott Mendelson. Introduction to mathematical logic. Chapman &
-- Hall, 4th edition, 1997, p. 155.
-- NB. These axioms formalize the propositional equality.
module PA.Axiomatic.Mendelson.Base where
infixl 7 _*_
infixl 6 _+_
infix 4 _≈_ _≉_
------------------------------------------------------------------------------
-- First-order logic (without equality)
open import Common.FOL.FOL public renaming ( D to ℕ )
-- Non-logical constants
postulate
zero : ℕ
succ : ℕ → ℕ
_+_ _*_ : ℕ → ℕ → ℕ
-- The PA equality.
--
-- N.B. We use the symbol _≈_ for avoiding to use the
-- --no-internal-equality Apia option.
postulate _≈_ : ℕ → ℕ → Set
-- Inequality.
_≉_ : ℕ → ℕ → Set
x ≉ y = ¬ x ≈ y
{-# ATP definition _≉_ #-}
-- Proper axioms
-- S₁. m = n → m = o → n = o
-- S₂. m = n → succ m = succ n
-- S₃. 0 ≠ succ n
-- S₄. succ m = succ n → m = n
-- S₅. 0 + n = n
-- S₆. succ m + n = succ (m + n)
-- S₇. 0 * n = 0
-- S₈. succ m * n = (m * n) + n
-- S₉. P(0) → (∀n.P(n) → P(succ n)) → ∀n.P(n), for any wff P(n) of PA.
postulate
S₁ : ∀ {m n o} → m ≈ n → m ≈ o → n ≈ o
S₂ : ∀ {m n} → m ≈ n → succ m ≈ succ n
S₃ : ∀ {n} → zero ≉ succ n
S₄ : ∀ {m n} → succ m ≈ succ n → m ≈ n
S₅ : ∀ n → zero + n ≈ n
S₆ : ∀ m n → succ m + n ≈ succ (m + n)
S₇ : ∀ n → zero * n ≈ zero
S₈ : ∀ m n → succ m * n ≈ n + m * n
{-# ATP axioms S₁ S₂ S₃ S₄ S₅ S₆ S₇ S₈ #-}
-- S₉ is an axiom schema, therefore we do not translate it to TPTP.
postulate S₉ : (A : ℕ → Set) → A zero → (∀ n → A n → A (succ n)) → ∀ n → A n
|
{
"alphanum_fraction": 0.4787018256,
"avg_line_length": 28.1714285714,
"ext": "agda",
"hexsha": "8d9d1fc4527596a2501bdb3703d19d84003326d9",
"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/PA/Axiomatic/Mendelson/Base.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/PA/Axiomatic/Mendelson/Base.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/PA/Axiomatic/Mendelson/Base.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": 698,
"size": 1972
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Data.Bool.Base where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Data.Empty
open import Cubical.Data.Sum.Base
open import Cubical.Data.Unit.Base
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
-- Obtain the booleans
open import Agda.Builtin.Bool public
private
variable
ℓ : Level
A : Type ℓ
infixr 6 _and_
infixr 5 _or_
infix 0 if_then_else_
not : Bool → Bool
not true = false
not false = true
_or_ : Bool → Bool → Bool
false or false = false
false or true = true
true or false = true
true or true = true
_and_ : Bool → Bool → Bool
false and false = false
false and true = false
true and false = false
true and true = true
-- xor / mod-2 addition
_⊕_ : Bool → Bool → Bool
false ⊕ x = x
true ⊕ x = not x
if_then_else_ : Bool → A → A → A
if true then x else y = x
if false then x else y = y
_≟_ : Discrete Bool
false ≟ false = yes refl
false ≟ true = no λ p → subst (λ b → if b then ⊥ else Bool) p true
true ≟ false = no λ p → subst (λ b → if b then Bool else ⊥) p true
true ≟ true = yes refl
Dec→Bool : Dec A → Bool
Dec→Bool (yes p) = true
Dec→Bool (no ¬p) = false
-- Helpers for automatic proof
Bool→Type : Bool → Type₀
Bool→Type true = Unit
Bool→Type false = ⊥
True : Dec A → Type₀
True Q = Bool→Type (Dec→Bool Q)
False : Dec A → Type₀
False Q = Bool→Type (not (Dec→Bool Q))
toWitness : {Q : Dec A} → True Q → A
toWitness {Q = yes p} _ = p
toWitnessFalse : {Q : Dec A} → False Q → ¬ A
toWitnessFalse {Q = no ¬p} _ = ¬p
dichotomyBool : (x : Bool) → (x ≡ true) ⊎ (x ≡ false)
dichotomyBool true = inl refl
dichotomyBool false = inr refl
-- TODO: this should be uncommented and implemented using instance arguments
-- _==_ : {dA : Discrete A} → A → A → Bool
-- _==_ {dA = dA} x y = Dec→Bool (dA x y)
|
{
"alphanum_fraction": 0.67,
"avg_line_length": 22.0930232558,
"ext": "agda",
"hexsha": "998b6a1a09ba05e1594fa3a48f1e65969aeddc6f",
"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/Data/Bool/Base.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/Data/Bool/Base.agda",
"max_line_length": 76,
"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/Data/Bool/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 644,
"size": 1900
}
|
{-# OPTIONS --without-K #-}
module #1 where
open import Relation.Binary.PropositionalEquality
{-
Exercise 2.1. Show that the three obvious proofs of Lemma 2.1.2 are pairwise equal.
-}
ind₌ : ∀{a b}{A : Set a} → (C : (x y : A) → (x ≡ y) → Set b) → ((x : A) → C x x refl) → {x y : A} → (p : x ≡ y) → C x y p
ind₌ C c {x}{y} p rewrite p = c y
composite : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
composite {i} {A} {_}{_}{z} p = ind₌ D d p where
D : (x y : A) → (p : x ≡ y) → Set i
D x y _ = y ≡ z → x ≡ z
d : (x₁ : A) → D x₁ x₁ refl
d _ = λ x → x
composite' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
composite' {i} {A} {_}{_}{z} = ind₌ D d where
D : (x y : A) → (p : x ≡ y) → Set i
D x y _ = y ≡ z → x ≡ z
d : (x : A) → D x x refl
d x = ind₌ E e where
E : (x z : A) → (q : x ≡ z) → Set i
E x z _ = x ≡ z
e : (x : A) → E x x refl
e x = refl
composite'' : ∀ {i} {A : Set i}{x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
composite'' refl refl = refl
composite=composite' : ∀ {i} {A : Set i}{x y z : A} → (p : x ≡ y)(q : y ≡ z) → composite p q ≡ composite' p q
composite=composite' refl refl = refl
composite=composite'' : ∀ {i} {A : Set i}{x y z : A} → (p : x ≡ y)(q : y ≡ z) → composite p q ≡ composite'' p q
composite=composite'' refl refl = refl
composite'=composite'' : ∀ {i} {A : Set i}{x y z : A} → (p : x ≡ y)(q : y ≡ z) → composite' p q ≡ composite'' p q
composite'=composite'' refl refl = refl
|
{
"alphanum_fraction": 0.4800270819,
"avg_line_length": 30.1428571429,
"ext": "agda",
"hexsha": "ab919f6a70eee7944680fceb49eee3fa64007b31",
"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": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CodaFi/HoTT-Exercises",
"max_forks_repo_path": "Chapter2/#1.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"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": "CodaFi/HoTT-Exercises",
"max_issues_repo_path": "Chapter2/#1.agda",
"max_line_length": 121,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3411b253b0a49a5f9c3301df175ae8ecdc563b12",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CodaFi/HoTT-Exercises",
"max_stars_repo_path": "Chapter2/#1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 657,
"size": 1477
}
|
module Pi-2 where
open import Data.Unit
open import Data.Product
open import Relation.Binary.PropositionalEquality
open import Groupoid
infixr 10 _◎_
infixr 30 _⟷_
------------------------------------------------------------------------------
-- Level -2
-- Types are -2 groupoids or equivalently all types are contractible or
-- equivalently all types have exactly one point
-- There is no interesting path structure but we have the trivial paths
-- explicitly below.
-- Types and values are defined mutually without reference to programs Types
-- always include PATHs in addition to the usual types.
mutual
data U : Set where
ONE : U
TIMES : U → U → U
PATH : {t : U} → ⟦ t ⟧ → ⟦ t ⟧ → U
⟦_⟧ : U → Set
⟦ ONE ⟧ = ⊤
⟦ TIMES t₁ t₂ ⟧ = ⟦ t₁ ⟧ × ⟦ t₂ ⟧
⟦ PATH v₁ v₂ ⟧ = (v₁ ≡ v₂)
-- Proof that all types are contractible. Def. 3.11.1 in the HoTT book
isContr : (t : U) → Σ[ v ∈ ⟦ t ⟧ ] ((v' : ⟦ t ⟧) → (v ≡ v'))
isContr ONE = (tt , λ v → refl)
isContr (TIMES t₁ t₂) with isContr t₁ | isContr t₂
... | (v₁ , f₁) | (v₂ , f₂) = ((v₁ , v₂) , f)
where f : (vv : ⟦ t₁ ⟧ × ⟦ t₂ ⟧) → (v₁ , v₂) ≡ vv
f (v₁' , v₂') = cong₂ _,′_ (f₁ v₁') (f₂ v₂')
isContr (PATH {t} v₁ v₂) with isContr t
isContr (PATH {t} v₁ v₂) | (v' , f') = (p , λ q → proof-irrelevance p q)
where p = trans (sym (f' v₁)) (f' v₂)
-- Proof that every type is a groupoid; this does not depend on the
-- definition of programs
isGroupoid : U → 1Groupoid
isGroupoid ONE = discrete ⊤
isGroupoid (TIMES t₁ t₂) = isGroupoid t₁ ×G isGroupoid t₂
isGroupoid (PATH {t} v₁ v₂) = discrete (v₁ ≡ v₂)
-- Programs
-- We use pointed types; programs map a pointed type to another
-- In other words, each program takes one particular value to another; if we
-- want to work on another value, we generally use another program
record U• : Set where
constructor •[_,_]
field
∣_∣ : U
• : ⟦ ∣_∣ ⟧
open U•
Space : (t• : U•) → Set
Space •[ t , v ] = ⟦ t ⟧
point : (t• : U•) → Space t•
point •[ t , v ] = v
data _⟷_ : U• → U• → Set where
id⟷ : {t : U•} → t ⟷ t
sym⟷ : {t₁ t₂ : U•} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
_◎_ : {t₁ t₂ t₃ : U•} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
unite⋆ : {t : U•} → •[ TIMES ONE ∣ t ∣ , (tt , • t) ] ⟷ t
uniti⋆ : {t : U•} → t ⟷ •[ TIMES ONE ∣ t ∣ , (tt , • t) ]
swap⋆ : {t₁ t₂ : U•} → •[ TIMES ∣ t₁ ∣ ∣ t₂ ∣ , (• t₁ , • t₂) ] ⟷
•[ TIMES ∣ t₂ ∣ ∣ t₁ ∣ , (• t₂ , • t₁) ]
assocl⋆ : {t₁ t₂ t₃ : U•} →
•[ TIMES ∣ t₁ ∣ (TIMES ∣ t₂ ∣ ∣ t₃ ∣) , (• t₁ , (• t₂ , • t₃)) ] ⟷
•[ TIMES (TIMES ∣ t₁ ∣ ∣ t₂ ∣) ∣ t₃ ∣ , ((• t₁ , • t₂) , • t₃) ]
assocr⋆ : {t₁ t₂ t₃ : U•} →
•[ TIMES (TIMES ∣ t₁ ∣ ∣ t₂ ∣) ∣ t₃ ∣ , ((• t₁ , • t₂) , • t₃) ] ⟷
•[ TIMES ∣ t₁ ∣ (TIMES ∣ t₂ ∣ ∣ t₃ ∣) , (• t₁ , (• t₂ , • t₃)) ]
_⊗_ : {t₁ t₂ t₃ t₄ : U•} → (t₁ ⟷ t₃) → (t₂ ⟷ t₄) →
(•[ TIMES ∣ t₁ ∣ ∣ t₂ ∣ , (• t₁ , • t₂ ) ] ⟷
•[ TIMES ∣ t₃ ∣ ∣ t₄ ∣ , (• t₃ , • t₄ ) ])
-- Proof that the universe is itself a groupoid; this DOES depend on the
-- definition of programs; the morphisms between types ARE the programs; all
-- programs between the same types are forced to be the same using a
-- degenerate observational equivalence relation.
_obs≅_ : {t₁ t₂ : U•} → (c₁ c₂ : t₁ ⟷ t₂) → Set
c₁ obs≅ c₂ = ⊤
UG : 1Groupoid
UG = record
{ set = U•
; _↝_ = _⟷_
; _≈_ = _obs≅_
; id = id⟷
; _∘_ = λ y⟷z x⟷y → x⟷y ◎ y⟷z
; _⁻¹ = sym⟷
; lneutr = λ _ → tt
; rneutr = λ _ → tt
; assoc = λ _ _ _ → tt
; equiv = record { refl = tt
; sym = λ _ → tt
; trans = λ _ _ → tt
}
; linv = λ _ → tt
; rinv = λ _ → tt
; ∘-resp-≈ = λ _ _ → tt
}
-- Examples
ONE• ONE×ONE• : U•
ONE• = •[ ONE , tt ]
ONE×ONE• = •[ TIMES ONE ONE , (tt , tt) ]
PathSpace : {t : U•} → ⟦ ∣ t ∣ ⟧ → U•
PathSpace v = •[ PATH v v , refl ]
c₁ c₂ c₃ : ONE• ⟷ ONE•
c₁ = id⟷
c₂ = uniti⋆ ◎ swap⋆ ◎ unite⋆
c₃ = uniti⋆ ◎ uniti⋆ ◎ assocl⋆ ◎ (swap⋆ ⊗ (sym⟷ id⟷)) ◎
assocr⋆ ◎ unite⋆ ◎ unite⋆
-- The evaluation of a program like c₁, c₂, c₃ above is not done in order to
-- figure out the output value. Both the input and output values are encoded
-- in the type of the program; what the evaluation does is follow the path to
-- constructively reach the ouput value from the input value. Even though the
-- programs are observationally equivalent, they follow different paths. The
-- next level will allow us to reason about which of these paths are
-- connected by 2paths etc. In general, one write programs at level i, and
-- reasons about their (observational) equivalence at levels i+1 and
-- higher. It is always possible to stop this game and use extensional
-- equality at some level, i.e., to equate all programs that connect the same
-- input and output values.
c₄ : ONE×ONE• ⟷ ONE•
c₄ = unite⋆
c₅ : PathSpace tt ⟷ PathSpace tt
c₅ = id⟷
c₁≅c₂ : c₁ obs≅ c₂
c₁≅c₂ = tt
-- the following does not typecheck
-- c₁≅c₄ : c₁ obs≅ c₄
-- it is not possible to equate programs that go between different types/values.
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.5257186082,
"avg_line_length": 32.6419753086,
"ext": "agda",
"hexsha": "2d37b71cbb57a63f6ab1d59168ce4c747c1022b5",
"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/PiWithLevels/Pi-2.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/PiWithLevels/Pi-2.agda",
"max_line_length": 80,
"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/PiWithLevels/Pi-2.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": 2080,
"size": 5288
}
|
{-# OPTIONS --allow-unsolved-metas #-}
module Imports.Issue3730 where
X : _
X = _
|
{
"alphanum_fraction": 0.6829268293,
"avg_line_length": 16.4,
"ext": "agda",
"hexsha": "7b2a5130ec2bf1c01e7d0dc091dbf6b61f430c88",
"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/Imports/Issue3730.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/Imports/Issue3730.agda",
"max_line_length": 38,
"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/Imports/Issue3730.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": 82
}
|
----------------------------------------------------------------------
-- Copyright: 2013, Jan Stolarek, Lodz University of Technology --
-- --
-- License: See LICENSE file in root of the repo --
-- Repo address: https://github.com/jstolarek/dep-typed-wbl-heaps --
-- --
-- Weight biased leftist tree that proves both priority and rank --
-- invariants. Uses a two-pass merging algorithm. --
----------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module TwoPassMerge.CombinedProofs where
open import Basics
open import Sized
open import TwoPassMerge.RankProof using ( makeT-lemma; proof-1; proof-2 )
-- Now that we have separate proofs of priority and rank invariants we
-- can combine them into one proof. We index Heap with two indices:
-- one for Priority and one for Rank.
data Heap : {i : Size} → Priority → Rank → Set where
empty : {i : Size} {b : Priority} → Heap {↑ i} b zero
node : {i : Size} {b : Priority} → (p : Priority) → p ≥ b → {l r : Rank} →
l ≥ r → Heap {i} p l → Heap {i} p r → Heap {↑ i} b (suc (l + r))
-- Now we will combine functions that prove priority invariant and
-- functions that prove rank invariant into functions that prove both
-- invariants.
-- Let's begin with singleton. Note the type of created Heap. We set
-- first index to zero, because it proves the priority invariant and
-- second index to one because it proves rank invariant. The node now
-- needs two ge0 evidence.
singleton : Priority → Heap zero one
singleton p = node p ge0 ge0 empty empty
-- makeT function requires that we supply evidence that priority
-- invariant holds (value of type p ≥ b), guarantees that resulting
-- heap has correct size and maintains rank invariant by using Order
-- type to supply evidence of rank correctness to node constructor.
makeT : {b : Priority} {l r : Rank} → (p : Priority) → p ≥ b →
Heap p l → Heap p r → Heap b (suc (l + r))
makeT {b} {l-rank} {r-rank} p p≥n l r with order l-rank r-rank
makeT {b} {l-rank} {r-rank} p p≥n l r | ge l≥r
= node p p≥n l≥r l r
makeT {b} {l-rank} {r-rank} p p≥n l r | le r≥l
= subst (Heap b) (makeT-lemma r-rank l-rank) (node p p≥n r≥l r l)
-- merge combines previous proofs:
--
-- 1) it enforces priority invariant by comparing priorities using
-- order function. Recall that this function returns value of
-- Order datatype that not only gives a result of comparison but
-- also supplies evidence that result is true. That evidence is
-- given to makeT which uses it to construct a new node.
--
-- 2) it proves size invariant of merge by reusing proofs from
-- TwoPassMerge.RankProof
--
-- 3) it delegates the proof of rank invariant to makeT
merge : {i j : Size} {b : Priority} {l r : Rank} → Heap {i} b l → Heap {j} b r
→ Heap b (l + r)
merge empty h2 = h2 -- See [merge, proof 0a]
merge {_} .{_} {b} {suc l} {zero} h1 empty
= subst (Heap b)
(sym (+0 (suc l))) -- See [merge, proof 0b]
h1
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
with order p1 p2
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| le p1≤p2
= subst (Heap b)
(proof-1 l1-rank r1-rank l2-rank r2-rank) -- See [merge, proof 1]
(makeT p1 p1≥b l1 (merge {i} {↑ j} r1 (node p2 p1≤p2 l2≥r2 l2 r2)))
merge .{↑ i} .{↑ j} .{b} {suc .(l1-rank + r1-rank)} {suc .(l2-rank + r2-rank)}
(node {i} .{b} p1 p1≥b {l1-rank} {r1-rank} l1≥r1 l1 r1)
(node {j} {b} p2 p2≥b {l2-rank} {r2-rank} l2≥r2 l2 r2)
| ge p1≥p2
= subst (Heap b)
(proof-2 l1-rank r1-rank l2-rank r2-rank) -- See [merge, proof 2]
(makeT p2 p2≥b l2 (merge {j} {↑ i} r2 (node p1 p1≥p2 l1≥r1 l1 r1)))
-- Implementations of insert and findMin are the same as
-- previously. We only need to update the type signature accordingly.
insert : {b : Priority} {r : Rank} → Priority → Heap zero r → Heap zero (suc r)
insert p h = merge (singleton p) h
findMin : {b : Priority} {r : Rank} → Heap b (suc r) → Priority
findMin (node p _ _ _ _) = p
-- To define deleteMin we will need to update definition of
-- liftBound. We need to redefine ≥trans because Agda won't let us
-- import it from a module that has unfinished implementation (recall
-- that we left definitions of findMin and deleteMin incomplete in
-- TwoPassMerge.PriorityProof).
≥trans : {a b c : Nat} → a ≥ b → b ≥ c → a ≥ c
≥trans a≥b ge0 = ge0
≥trans (geS a≥b) (geS b≥c) = geS (≥trans a≥b b≥c)
liftBound : {p b : Priority} → b ≥ p → {r : Rank} → Heap b r → Heap p r
liftBound b≥n empty = empty
liftBound b≥n (node p p≥b l≥r l r) = node p (≥trans p≥b b≥n) l≥r l r
-- With the new definition of liftBound we can now define deleteMin.
-- Implementation is identical to the one in TwoPassMerge.RankProof -
-- we only had to update type signature.
deleteMin : {b : Priority} {r : Rank} → Heap b (suc r) → Heap b r
deleteMin (node _ p≥b _ l r) = merge (liftBound p≥b l) (liftBound p≥b r)
|
{
"alphanum_fraction": 0.6029194383,
"avg_line_length": 47.8938053097,
"ext": "agda",
"hexsha": "412f6bb857fed6454424514aa49d7f1daa1dcb5f",
"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": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_forks_repo_path": "src/TwoPassMerge/CombinedProofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"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": "jstolarek/dep-typed-wbl-heaps",
"max_issues_repo_path": "src/TwoPassMerge/CombinedProofs.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "57db566cb840dc70331c29eb7bf3a0c849f8b27e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "jstolarek/dep-typed-wbl-heaps",
"max_stars_repo_path": "src/TwoPassMerge/CombinedProofs.agda",
"max_stars_repo_stars_event_max_datetime": "2018-05-02T21:48:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-02T21:48:43.000Z",
"num_tokens": 1838,
"size": 5412
}
|
-- This was accepted, since we didn't fail on mismatched sorts when
-- comparing types.
module Issue485 where
ap : ((A : Set) → A → A) → Set → Set
ap f A = f _ A
|
{
"alphanum_fraction": 0.6503067485,
"avg_line_length": 23.2857142857,
"ext": "agda",
"hexsha": "0712df7f4759ff8dd7985146be26452201c296d8",
"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/Issue485.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/Issue485.agda",
"max_line_length": 67,
"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/Issue485.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": 50,
"size": 163
}
|
{-# OPTIONS --without-K --safe #-}
module Data.Nat.Reasoning where
open import Data.Nat
import Data.Nat.Properties as ℕ-Prop
open import Relation.Binary.PropositionalEquality
infixr 3 _*≫_ _≪*_ _+≫_ _≪+_
_*≫_ : ∀ {x y} z → x ≡ y → z * x ≡ z * y
_*≫_ _ = cong _
_+≫_ : ∀ {x y} z → x ≡ y → z + x ≡ z + y
_+≫_ _ = cong _
_≪*_ : ∀ {x y} z → x ≡ y → x * z ≡ y * z
_≪*_ _ = cong _
_≪+_ : ∀ {x y} z → x ≡ y → x + z ≡ y + z
_≪+_ _ = cong _
|
{
"alphanum_fraction": 0.5228310502,
"avg_line_length": 20.8571428571,
"ext": "agda",
"hexsha": "ecbfabe4a6a65fa77178b60b4540a5d0ed95fa2b",
"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": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-binary",
"max_forks_repo_path": "Data/Nat/Reasoning.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"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-binary",
"max_issues_repo_path": "Data/Nat/Reasoning.agda",
"max_line_length": 49,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "92af4d620febd47a9791d466d747278dc4a417aa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-binary",
"max_stars_repo_path": "Data/Nat/Reasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-21T21:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-21T21:30:10.000Z",
"num_tokens": 204,
"size": 438
}
|
------------------------------------------------------------------------
-- The state monad transformer
------------------------------------------------------------------------
-- The interface is based on that used by the "mtl" package on
-- Hackage.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Monad.State
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Prelude
open Derived-definitions-and-properties eq
open import Monad eq
-- The state monad transformer, defined using a wrapper type to make
-- instance resolution easier.
record StateT {s} (S : Type s)
(M : Type s → Type s)
(A : Type s) : Type s where
constructor wrap
field
run : S → M (A × S)
open StateT public
instance
-- StateT is a "raw monad" transformer.
raw-monad-transformer :
∀ {s} {S : Type s} →
Raw-monad-transformer (StateT S)
run (Raw-monad.return (Raw-monad-transformer.transform
raw-monad-transformer) x) =
λ s → return (x , s)
run (Raw-monad._>>=_ (Raw-monad-transformer.transform
raw-monad-transformer) x f) =
λ s → run x s >>= λ { (x , s) → run (f x) s }
run (Raw-monad-transformer.liftʳ raw-monad-transformer m) =
λ s → map (_, s) m
transform : ∀ {s} {S : Type s} {M} ⦃ is-raw-monad : Raw-monad M ⦄ →
Raw-monad (StateT S M)
transform = Raw-monad-transformer.transform raw-monad-transformer
-- StateT is a monad transformer (assuming extensionality).
monad-transformer :
∀ {s} {S : Type s} →
Extensionality s s →
Monad-transformer (StateT S)
Monad.raw-monad (Monad-transformer.transform (monad-transformer _)) =
Raw-monad-transformer.transform raw-monad-transformer
Monad.left-identity (Monad-transformer.transform
(monad-transformer ext)) x f =
cong wrap (apply-ext ext λ s →
(return (x , s) >>= λ { (x , s) → run (f x) s }) ≡⟨ left-identity _ _ ⟩∎
run (f x) s ∎)
Monad.right-identity (Monad-transformer.transform
(monad-transformer ext)) x =
cong wrap (apply-ext ext λ s →
run x s >>= (λ { (x , s) → return (x , s) }) ≡⟨ right-identity _ ⟩∎
run x s ∎)
Monad.associativity (Monad-transformer.transform
(monad-transformer ext)) x f g =
cong wrap (apply-ext ext λ s →
(run x s >>= λ { (x , s) →
run (f x) s >>= λ { (x , s) →
run (g x) s } }) ≡⟨ associativity _ _ _ ⟩∎
((run x s >>= λ { (x , s) → run (f x) s }) >>= λ { (x , s) →
run (g x) s }) ∎)
Monad-transformer.liftᵐ (monad-transformer _) = liftʳ
Monad-transformer.lift-return (monad-transformer ext) x =
cong wrap (apply-ext ext λ s →
map (_, s) (return x) ≡⟨ map-return _ _ ⟩∎
return (x , s) ∎)
Monad-transformer.lift->>= (monad-transformer ext) x f =
cong wrap (apply-ext ext λ s →
map (_, s) (x >>= f) ≡⟨ map->>= _ _ _ ⟩
(x >>= λ x → map (_, s) (f x)) ≡⟨ sym $ >>=-map ext _ _ _ ⟩∎
(map (_, s) x >>= λ { (x , s) → map (_, s) (f x) }) ∎)
-- Returns the state.
get : ∀ {s} {S : Type s} {M} ⦃ is-monad : Raw-monad M ⦄ →
StateT S M S
run get = λ s → return (s , s)
-- Types the state.
set : ∀ {s} {S : Type s} {M} ⦃ is-monad : Raw-monad M ⦄ →
S → StateT S M (↑ _ ⊤)
run (set s) = λ _ → return (_ , s)
-- Modifies the state.
modify :
∀ {s} {S : Type s} {M} ⦃ is-monad : Raw-monad M ⦄ →
(S → S) → StateT S M (↑ _ ⊤)
modify f = get >>= set ∘ f
|
{
"alphanum_fraction": 0.5084193373,
"avg_line_length": 32.0173913043,
"ext": "agda",
"hexsha": "bfd885e96955f552a2aec23843c0dc8b45f76c18",
"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/Monad/State.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/Monad/State.agda",
"max_line_length": 91,
"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/Monad/State.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": 1126,
"size": 3682
}
|
module Records where
variable
a b : Set
-- parametrized record type exported as an Haskell record
record Pair (a b : Set) : Set where
constructor MkPair
field
proj₁ : a
proj₂ : b
open Pair public
{-# COMPILE AGDA2HS Pair #-}
-- no named constructor means we reuse the record name
record Wrap (a : Set) : Set where
field
unwrap : a
open Wrap public
{-# COMPILE AGDA2HS Wrap #-}
-- record type exported as an Haskell class definition
record MyMonoid (a : Set) : Set where
field
mempty : a
mappend : a → a → a
{-# COMPILE AGDA2HS MyMonoid class #-}
swap : Pair a b → Pair b a
swap (MkPair x y) = MkPair y x
swap₂ : Wrap (Pair a b) → Wrap (Pair b a)
swap₂ (record {unwrap = p}) = record {unwrap = record { proj₁ = proj₂ p; proj₂ = p .proj₁ } }
{-# COMPILE AGDA2HS swap #-}
{-# COMPILE AGDA2HS swap₂ #-}
|
{
"alphanum_fraction": 0.6536180308,
"avg_line_length": 19.6046511628,
"ext": "agda",
"hexsha": "141e754c3586eeaa2f573c8db1f1a5f6da22403f",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/Records.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/Records.agda",
"max_line_length": 93,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "test/Records.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 258,
"size": 843
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.ZariskiLattice.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Transport
open import Cubical.Foundations.Powerset using (⊆-refl-consequence)
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm
; ·-identityʳ to ·ℕ-rid)
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Relation.Binary.Poset
open import Cubical.Algebra.Ring
open import Cubical.Algebra.Ring.Properties
open import Cubical.Algebra.Ring.BigOps
open import Cubical.Algebra.Algebra
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.BinomialThm
open import Cubical.Algebra.CommRing.Ideal
open import Cubical.Algebra.CommRing.FGIdeal
open import Cubical.Algebra.CommRing.RadicalIdeal
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.Algebra.CommRing.Localisation.InvertingElements
open import Cubical.Algebra.CommAlgebra.Base
open import Cubical.Algebra.CommAlgebra.Properties
open import Cubical.Algebra.CommAlgebra.Localisation
open import Cubical.Algebra.RingSolver.ReflectionSolving
open import Cubical.Algebra.Semilattice
open import Cubical.Algebra.Lattice
open import Cubical.Algebra.DistLattice
open import Cubical.Algebra.DistLattice.BigOps
open import Cubical.Algebra.Matrix
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
open BinaryRelation
open isEquivRel
private
variable
ℓ ℓ' : Level
module ZarLat (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open Sum (CommRing→Ring R')
open CommRingTheory R'
open Exponentiation R'
open BinomialThm R'
open CommIdeal R'
open RadicalIdeal R'
open isCommIdeal
open ProdFin R'
private
R = fst R'
A = Σ[ n ∈ ℕ ] (FinVec R n)
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
_∼_ : A → A → Type (ℓ-suc ℓ)
(_ , α) ∼ (_ , β) = √ ⟨ α ⟩ ≡ √ ⟨ β ⟩
∼EquivRel : isEquivRel (_∼_)
reflexive ∼EquivRel _ = refl
symmetric ∼EquivRel _ _ = sym
transitive ∼EquivRel _ _ _ = _∙_
ZL : Type (ℓ-suc ℓ)
ZL = A / _∼_
0z : ZL
0z = [ 0 , (λ ()) ]
1z : ZL
1z = [ 1 , (replicateFinVec 1 1r) ]
_∨z_ : ZL → ZL → ZL
_∨z_ = setQuotSymmBinOp (reflexive ∼EquivRel) (transitive ∼EquivRel)
(λ (_ , α) (_ , β) → (_ , α ++Fin β))
(λ (_ , α) (_ , β) → cong √ (FGIdealAddLemma _ α β ∙∙ +iComm _ _ ∙∙ sym (FGIdealAddLemma _ β α)))
λ (_ , α) (_ , β) (_ , γ) α∼β → --need to show α∨γ ∼ β∨γ
√ ⟨ α ++Fin γ ⟩ ≡⟨ cong √ (FGIdealAddLemma _ α γ) ⟩
√ (⟨ α ⟩ +i ⟨ γ ⟩) ≡⟨ sym (√+LContr _ _) ⟩
√ (√ ⟨ α ⟩ +i ⟨ γ ⟩) ≡⟨ cong (λ I → √ (I +i ⟨ γ ⟩)) α∼β ⟩
√ (√ ⟨ β ⟩ +i ⟨ γ ⟩) ≡⟨ √+LContr _ _ ⟩
√ (⟨ β ⟩ +i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealAddLemma _ β γ)) ⟩
√ ⟨ β ++Fin γ ⟩ ∎
_∧z_ : ZL → ZL → ZL
_∧z_ = setQuotSymmBinOp (reflexive ∼EquivRel) (transitive ∼EquivRel)
(λ (_ , α) (_ , β) → (_ , α ··Fin β))
(λ (_ , α) (_ , β) → cong √ (FGIdealMultLemma _ α β ∙∙ ·iComm _ _ ∙∙ sym (FGIdealMultLemma _ β α)))
λ (_ , α) (_ , β) (_ , γ) α∼β → --need to show α∧γ ∼ β∧γ
√ ⟨ α ··Fin γ ⟩ ≡⟨ cong √ (FGIdealMultLemma _ α γ) ⟩
√ (⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ sym (√·LContr _ _) ⟩
√ (√ ⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ cong (λ I → √ (I ·i ⟨ γ ⟩)) α∼β ⟩
√ (√ ⟨ β ⟩ ·i ⟨ γ ⟩) ≡⟨ √·LContr _ _ ⟩
√ (⟨ β ⟩ ·i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealMultLemma _ β γ)) ⟩
√ ⟨ β ··Fin γ ⟩ ∎
-- join axioms
∨zAssoc : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∨z (𝔟 ∨z 𝔠) ≡ (𝔞 ∨z 𝔟) ∨z 𝔠
∨zAssoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _ (cong √ (IdealAddAssoc _ _ _ _))
∨zComm : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∨z 𝔟 ≡ 𝔟 ∨z 𝔞
∨zComm = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(cong √ (FGIdealAddLemma _ α β ∙∙ +iComm _ _ ∙∙ sym (FGIdealAddLemma _ β α)))
∨zLid : ∀ (𝔞 : ZL) → 0z ∨z 𝔞 ≡ 𝔞
∨zLid = SQ.elimProp (λ _ → squash/ _ _) λ _ → eq/ _ _ refl
∨zRid : ∀ (𝔞 : ZL) → 𝔞 ∨z 0z ≡ 𝔞
∨zRid _ = ∨zComm _ _ ∙ ∨zLid _
-- -- meet axioms
∧zAssoc : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∧z (𝔟 ∧z 𝔠) ≡ (𝔞 ∧z 𝔟) ∧z 𝔠
∧zAssoc = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _
(√ ⟨ α ··Fin (β ··Fin γ) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i ⟨ β ··Fin γ ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i (⟨ β ⟩ ·i ⟨ γ ⟩)) ≡⟨ cong √ (·iAssoc _ _ _) ⟩
√ ((⟨ α ⟩ ·i ⟨ β ⟩) ·i ⟨ γ ⟩) ≡⟨ cong (λ x → √ (x ·i ⟨ γ ⟩)) (sym (FGIdealMultLemma _ _ _)) ⟩
√ (⟨ α ··Fin β ⟩ ·i ⟨ γ ⟩) ≡⟨ cong √ (sym (FGIdealMultLemma _ _ _)) ⟩
√ ⟨ (α ··Fin β) ··Fin γ ⟩ ∎)
∧zComm : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∧z 𝔟 ≡ 𝔟 ∧z 𝔞
∧zComm = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(cong √ (FGIdealMultLemma _ α β ∙∙ ·iComm _ _ ∙∙ sym (FGIdealMultLemma _ β α)))
∧zRid : ∀ (𝔞 : ZL) → 𝔞 ∧z 1z ≡ 𝔞
∧zRid = SQ.elimProp (λ _ → squash/ _ _)
λ (_ , α) → eq/ _ _ (cong √
(⟨ α ··Fin (replicateFinVec 1 1r) ⟩ ≡⟨ FGIdealMultLemma _ _ _ ⟩
⟨ α ⟩ ·i ⟨ (replicateFinVec 1 1r) ⟩ ≡⟨ cong (⟨ α ⟩ ·i_) (contains1Is1 _ (indInIdeal _ _ zero)) ⟩
⟨ α ⟩ ·i 1Ideal ≡⟨ ·iRid _ ⟩
⟨ α ⟩ ∎))
-- absorption and distributivity
∧zAbsorb∨z : ∀ (𝔞 𝔟 : ZL) → 𝔞 ∧z (𝔞 ∨z 𝔟) ≡ 𝔞
∧zAbsorb∨z = SQ.elimProp2 (λ _ _ → squash/ _ _)
λ (_ , α) (_ , β) → eq/ _ _
(√ ⟨ α ··Fin (α ++Fin β) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ α (α ++Fin β)) ⟩
√ (⟨ α ⟩ ·i ⟨ α ++Fin β ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealAddLemma _ α β) ⟩
√ (⟨ α ⟩ ·i (⟨ α ⟩ +i ⟨ β ⟩)) ≡⟨ √·Absorb+ _ _ ⟩
√ ⟨ α ⟩ ∎)
∧zLDist∨z : ∀ (𝔞 𝔟 𝔠 : ZL) → 𝔞 ∧z (𝔟 ∨z 𝔠) ≡ (𝔞 ∧z 𝔟) ∨z (𝔞 ∧z 𝔠)
∧zLDist∨z = SQ.elimProp3 (λ _ _ _ → squash/ _ _)
λ (_ , α) (_ , β) (_ , γ) → eq/ _ _
(√ ⟨ α ··Fin (β ++Fin γ) ⟩ ≡⟨ cong √ (FGIdealMultLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i ⟨ β ++Fin γ ⟩) ≡⟨ cong (λ x → √ (⟨ α ⟩ ·i x)) (FGIdealAddLemma _ _ _) ⟩
√ (⟨ α ⟩ ·i (⟨ β ⟩ +i ⟨ γ ⟩)) ≡⟨ cong √ (·iRdist+i _ _ _) ⟩
-- L/R-dist are swapped
-- in Lattices vs Rings
√ (⟨ α ⟩ ·i ⟨ β ⟩ +i ⟨ α ⟩ ·i ⟨ γ ⟩) ≡⟨ cong₂ (λ x y → √ (x +i y))
(sym (FGIdealMultLemma _ _ _))
(sym (FGIdealMultLemma _ _ _)) ⟩
√ (⟨ α ··Fin β ⟩ +i ⟨ α ··Fin γ ⟩) ≡⟨ cong √ (sym (FGIdealAddLemma _ _ _)) ⟩
√ ⟨ (α ··Fin β) ++Fin (α ··Fin γ) ⟩ ∎)
ZariskiLattice : DistLattice (ℓ-suc ℓ)
fst ZariskiLattice = ZL
DistLatticeStr.0l (snd ZariskiLattice) = 0z
DistLatticeStr.1l (snd ZariskiLattice) = 1z
DistLatticeStr._∨l_ (snd ZariskiLattice) = _∨z_
DistLatticeStr._∧l_ (snd ZariskiLattice) = _∧z_
DistLatticeStr.isDistLattice (snd ZariskiLattice) =
makeIsDistLattice∧lOver∨l squash/ ∨zAssoc ∨zRid ∨zComm
∧zAssoc ∧zRid ∧zComm ∧zAbsorb∨z ∧zLDist∨z
module _ (R' : CommRing ℓ) (L' : DistLattice ℓ') where
open CommRingStr (R' .snd)
open RingTheory (CommRing→Ring R')
open Sum (CommRing→Ring R')
open CommRingTheory R'
open Exponentiation R'
open DistLatticeStr (L' .snd) renaming (is-set to isSetL)
open Join L'
open LatticeTheory (DistLattice→Lattice L')
open Order (DistLattice→Lattice L')
open JoinSemilattice (Lattice→JoinSemilattice (DistLattice→Lattice L'))
open PosetReasoning IndPoset
open PosetStr (IndPoset .snd) hiding (_≤_)
private
R = fst R'
L = fst L'
record IsZarMap (d : R → L) : Type (ℓ-max ℓ ℓ') where
constructor iszarmap
field
pres0 : d 0r ≡ 0l
pres1 : d 1r ≡ 1l
·≡∧ : ∀ x y → d (x · y) ≡ d x ∧l d y
+≤∨ : ∀ x y → d (x + y) ≤ d x ∨l d y
∑≤⋁ : {n : ℕ} (U : FinVec R n) → d (∑ U) ≤ ⋁ λ i → d (U i)
∑≤⋁ {n = zero} U = ∨lRid _ ∙ pres0
∑≤⋁ {n = suc n} U = d (∑ U) ≤⟨ ∨lIdem _ ⟩
d (U zero + ∑ (U ∘ suc)) ≤⟨ +≤∨ _ _ ⟩
d (U zero) ∨l d (∑ (U ∘ suc)) ≤⟨ ≤-∨LPres _ _ _ (∑≤⋁ (U ∘ suc)) ⟩
d (U zero) ∨l ⋁ (d ∘ U ∘ suc) ≤⟨ ∨lIdem _ ⟩
⋁ (d ∘ U) ◾
d·LCancel : ∀ x y → d (x · y) ≤ d y
d·LCancel x y = subst (λ a → a ≤ d y) (sym (·≡∧ x y)) (∧≤LCancelJoin _ _)
linearCombination≤LCancel : {n : ℕ} (α β : FinVec R n)
→ d (linearCombination R' α β) ≤ ⋁ (d ∘ β)
linearCombination≤LCancel α β = is-trans _ _ _ (∑≤⋁ (λ i → α i · β i))
(≤-⋁Ext _ _ λ i → d·LCancel (α i) (β i))
ZarMapIdem : ∀ (n : ℕ) (x : R) → d (x ^ (suc n)) ≡ d x
ZarMapIdem zero x = ·≡∧ _ _ ∙∙ cong (d x ∧l_) pres1 ∙∙ ∧lRid _
ZarMapIdem (suc n) x = ·≡∧ _ _ ∙∙ cong (d x ∧l_) (ZarMapIdem n x) ∙∙ ∧lIdem _
ZarMapExpIneq : ∀ (n : ℕ) (x : R) → d x ≤ d (x ^ n)
ZarMapExpIneq zero x = cong (d x ∨l_) pres1 ∙∙ 1lRightAnnihilates∨l _ ∙∙ sym pres1
ZarMapExpIneq (suc n) x = subst (λ y → d x ≤ y) (sym (ZarMapIdem _ x)) (∨lIdem _)
-- the crucial lemma about "Zariski maps"
open CommIdeal R'
open RadicalIdeal R'
open isCommIdeal
private
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
ZarMapRadicalIneq : ∀ {n : ℕ} (α : FinVec R n) (x : R)
→ x ∈ √ ⟨ α ⟩ → d x ≤ ⋁ (d ∘ α)
ZarMapRadicalIneq α x = PT.elim (λ _ → isSetL _ _)
(uncurry (λ n → (PT.elim (λ _ → isSetL _ _) (uncurry (curriedHelper n)))))
where
curriedHelper : (n : ℕ) (β : FinVec R _)
→ x ^ n ≡ linearCombination R' β α → d x ≤ ⋁ (d ∘ α)
curriedHelper n β xⁿ≡∑βα = d x ≤⟨ ZarMapExpIneq n x ⟩
d (x ^ n)
≤⟨ subst (λ y → y ≤ ⋁ (d ∘ α)) (sym (cong d xⁿ≡∑βα)) (linearCombination≤LCancel β α) ⟩
⋁ (d ∘ α) ◾
module ZarLatUniversalProp (R' : CommRing ℓ) where
open CommRingStr (snd R')
open RingTheory (CommRing→Ring R')
open Sum (CommRing→Ring R')
open CommRingTheory R'
open Exponentiation R'
open BinomialThm R'
open CommIdeal R'
open RadicalIdeal R'
open isCommIdeal
open ProdFin R'
open ZarLat R'
open IsZarMap
private
R = fst R'
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
D : R → ZL
D x = [ 1 , replicateFinVec 1 x ] -- λ x → √⟨x⟩
isZarMapD : IsZarMap R' ZariskiLattice D
pres0 isZarMapD = eq/ _ _ (cong √ (0FGIdeal _ ∙ sym (emptyFGIdeal _ _)))
pres1 isZarMapD = refl
·≡∧ isZarMapD x y = cong {B = λ _ → ZL} (λ U → [ 1 , U ]) (Length1··Fin x y)
+≤∨ isZarMapD x y = eq/ _ _ (cong √ (CommIdeal≡Char (inclOfFGIdeal _ 3Vec ⟨ 2Vec ⟩ 3Vec⊆2Vec)
(inclOfFGIdeal _ 2Vec ⟨ 3Vec ⟩ 2Vec⊆3Vec)))
where
2Vec = replicateFinVec 1 x ++Fin replicateFinVec 1 y
3Vec = replicateFinVec 1 (x + y) ++Fin (replicateFinVec 1 x ++Fin replicateFinVec 1 y)
3Vec⊆2Vec : ∀ (i : Fin 3) → 3Vec i ∈ ⟨ 2Vec ⟩
3Vec⊆2Vec zero = ⟨ 2Vec ⟩ .snd .+Closed (indInIdeal _ _ zero) (indInIdeal _ _ (suc zero))
3Vec⊆2Vec (suc zero) = indInIdeal _ _ zero
3Vec⊆2Vec (suc (suc zero)) = indInIdeal _ _ (suc zero)
2Vec⊆3Vec : ∀ (i : Fin 2) → 2Vec i ∈ ⟨ 3Vec ⟩
2Vec⊆3Vec zero = indInIdeal _ _ (suc zero)
2Vec⊆3Vec (suc zero) = indInIdeal _ _ (suc (suc zero))
-- defintion of the universal property
hasZarLatUniversalProp : (L : DistLattice ℓ') (D : R → fst L)
→ IsZarMap R' L D
→ Type _
hasZarLatUniversalProp {ℓ' = ℓ'} L D _ = ∀ (L' : DistLattice ℓ') (d : R → fst L')
→ IsZarMap R' L' d
→ ∃![ χ ∈ DistLatticeHom L L' ] (fst χ) ∘ D ≡ d
isPropZarLatUniversalProp : (L : DistLattice ℓ') (D : R → fst L) (isZarMapD : IsZarMap R' L D)
→ isProp (hasZarLatUniversalProp L D isZarMapD)
isPropZarLatUniversalProp L D isZarMapD = isPropΠ3 (λ _ _ _ → isPropIsContr)
ZLHasUniversalProp : hasZarLatUniversalProp ZariskiLattice D isZarMapD
ZLHasUniversalProp L' d isZarMapd = (χ , funExt χcomp) , χunique
where
open DistLatticeStr (snd L') renaming (is-set to isSetL)
open LatticeTheory (DistLattice→Lattice L')
open Join L'
open IsLatticeHom
L = fst L'
χ : DistLatticeHom ZariskiLattice L'
fst χ = SQ.rec isSetL (λ (_ , α) → ⋁ (d ∘ α))
λ (_ , α) (_ , β) → curriedHelper α β
where
curriedHelper : {n m : ℕ} (α : FinVec R n) (β : FinVec R m)
→ √ ⟨ α ⟩ ≡ √ ⟨ β ⟩ → ⋁ (d ∘ α) ≡ ⋁ (d ∘ β)
curriedHelper α β √⟨α⟩≡√⟨β⟩ = is-antisym _ _ ineq1 ineq2
where
open Order (DistLattice→Lattice L')
open JoinSemilattice (Lattice→JoinSemilattice (DistLattice→Lattice L'))
open PosetReasoning IndPoset
open PosetStr (IndPoset .snd) hiding (_≤_)
incl1 : √ ⟨ α ⟩ ⊆ √ ⟨ β ⟩
incl1 = ⊆-refl-consequence _ _ (cong fst √⟨α⟩≡√⟨β⟩) .fst
ineq1 : ⋁ (d ∘ α) ≤ ⋁ (d ∘ β)
ineq1 = ⋁IsMax (d ∘ α) (⋁ (d ∘ β))
λ i → ZarMapRadicalIneq isZarMapd β (α i) (√FGIdealCharLImpl α ⟨ β ⟩ incl1 i)
incl2 : √ ⟨ β ⟩ ⊆ √ ⟨ α ⟩
incl2 = ⊆-refl-consequence _ _ (cong fst √⟨α⟩≡√⟨β⟩) .snd
ineq2 : ⋁ (d ∘ β) ≤ ⋁ (d ∘ α)
ineq2 = ⋁IsMax (d ∘ β) (⋁ (d ∘ α))
λ i → ZarMapRadicalIneq isZarMapd α (β i) (√FGIdealCharLImpl β ⟨ α ⟩ incl2 i)
pres0 (snd χ) = refl
pres1 (snd χ) = ∨lRid _ ∙ isZarMapd .pres1
pres∨l (snd χ) = elimProp2 (λ _ _ → isSetL _ _) (uncurry (λ n α → uncurry (curriedHelper n α)))
where
curriedHelper : (n : ℕ) (α : FinVec R n) (m : ℕ) (β : FinVec R m)
→ ⋁ (d ∘ (α ++Fin β)) ≡ ⋁ (d ∘ α) ∨l ⋁ (d ∘ β)
curriedHelper zero α _ β = sym (∨lLid _)
curriedHelper (suc n) α _ β =
⋁ (d ∘ (α ++Fin β)) ≡⟨ refl ⟩
d (α zero) ∨l ⋁ (d ∘ ((α ∘ suc) ++Fin β))
≡⟨ cong (d (α zero) ∨l_) (curriedHelper _ (α ∘ suc) _ β) ⟩
d (α zero) ∨l (⋁ (d ∘ α ∘ suc) ∨l ⋁ (d ∘ β))
≡⟨ ∨lAssoc _ _ _ ⟩
⋁ (d ∘ α) ∨l ⋁ (d ∘ β) ∎
pres∧l (snd χ) = elimProp2 (λ _ _ → isSetL _ _) (uncurry (λ n α → uncurry (curriedHelper n α)))
where
-- have to repeat this one here so the termination checker won't complain
oldHelper : (n : ℕ) (α : FinVec R n) (m : ℕ) (β : FinVec R m)
→ ⋁ (d ∘ (α ++Fin β)) ≡ ⋁ (d ∘ α) ∨l ⋁ (d ∘ β)
oldHelper zero α _ β = sym (∨lLid _)
oldHelper (suc n) α _ β = cong (d (α zero) ∨l_) (oldHelper _ (α ∘ suc) _ β) ∙ ∨lAssoc _ _ _
curriedHelper : (n : ℕ) (α : FinVec R n) (m : ℕ) (β : FinVec R m)
→ ⋁ (d ∘ (α ··Fin β)) ≡ ⋁ (d ∘ α) ∧l ⋁ (d ∘ β)
curriedHelper zero α _ β = sym (0lLeftAnnihilates∧l _)
curriedHelper (suc n) α _ β =
⋁ (d ∘ (α ··Fin β)) ≡⟨ refl ⟩
⋁ (d ∘ ((λ j → α zero · β j) ++Fin ((α ∘ suc) ··Fin β)))
≡⟨ oldHelper _ (λ j → α zero · β j) _ ((α ∘ suc) ··Fin β) ⟩
⋁ (d ∘ (λ j → α zero · β j)) ∨l ⋁ (d ∘ ((α ∘ suc) ··Fin β))
≡⟨ cong (_∨l ⋁ (d ∘ ((α ∘ suc) ··Fin β))) (⋁Ext (λ j → isZarMapd .·≡∧ (α zero) (β j))) ⟩
⋁ (λ j → d (α zero) ∧l d (β j)) ∨l ⋁ (d ∘ ((α ∘ suc) ··Fin β))
≡⟨ cong (_∨l ⋁ (d ∘ ((α ∘ suc) ··Fin β))) (sym (⋁Meetrdist _ _)) ⟩
(d (α zero) ∧l ⋁ (d ∘ β)) ∨l ⋁ (d ∘ ((α ∘ suc) ··Fin β))
≡⟨ cong ((d (α zero) ∧l ⋁ (d ∘ β)) ∨l_) (curriedHelper _ (α ∘ suc) _ β) ⟩
(d (α zero) ∧l ⋁ (d ∘ β)) ∨l (⋁ (d ∘ α ∘ suc) ∧l ⋁ (d ∘ β))
≡⟨ sym (∧lRdist∨l _ _ _) ⟩
⋁ (d ∘ α) ∧l ⋁ (d ∘ β) ∎
χcomp : ∀ (f : R) → χ .fst (D f) ≡ d f
χcomp f = ∨lRid (d f)
χunique : (y : Σ[ χ' ∈ DistLatticeHom ZariskiLattice L' ] fst χ' ∘ D ≡ d)
→ (χ , funExt χcomp) ≡ y
χunique (χ' , χ'∘D≡d) = Σ≡Prop (λ _ → isSetΠ (λ _ → isSetL) _ _) (LatticeHom≡f _ _
(funExt (elimProp (λ _ → isSetL _ _) (uncurry uniqHelper))))
where
uniqHelper : (n : ℕ) (α : FinVec R n) → fst χ [ n , α ] ≡ fst χ' [ n , α ]
uniqHelper zero _ = sym (cong (λ α → fst χ' [ 0 , α ]) (funExt (λ ())) ∙ χ' .snd .pres0)
uniqHelper (suc n) α =
⋁ (d ∘ α) ≡⟨ refl ⟩
d (α zero) ∨l ⋁ (d ∘ α ∘ suc)
≡⟨ cong (d (α zero) ∨l_) (uniqHelper n (α ∘ suc)) ⟩ -- the inductive step
d (α zero) ∨l fst χ' [ n , α ∘ suc ]
≡⟨ cong (_∨l fst χ' [ n , α ∘ suc ]) (sym (funExt⁻ χ'∘D≡d (α zero))) ⟩
fst χ' (D (α zero)) ∨l fst χ' [ n , α ∘ suc ]
≡⟨ sym (χ' .snd .pres∨l _ _) ⟩
fst χ' (D (α zero) ∨z [ n , α ∘ suc ])
≡⟨ cong (λ β → fst χ' [ suc n , β ]) (funExt (λ { zero → refl ; (suc i) → refl })) ⟩
fst χ' [ suc n , α ] ∎
-- An equivalent definition that doesn't bump up the unviverse level
module SmallZarLat (R' : CommRing ℓ) where
open CommRingStr (snd R')
open CommIdeal R'
open RadicalIdeal R'
open ZarLat R'
open Iso
private
R = fst R'
A = Σ[ n ∈ ℕ ] (FinVec R n)
⟨_⟩ : {n : ℕ} → FinVec R n → CommIdeal
⟨ V ⟩ = ⟨ V ⟩[ R' ]
-- This is small!
_≼_ : A → A → Type ℓ
(_ , α) ≼ (_ , β) = ∀ i → α i ∈ √ ⟨ β ⟩
_∼'_ : A → A → Type ℓ
α ∼' β = (α ≼ β) × (β ≼ α)
-- lives in the same universe as R
ZL' : Type ℓ
ZL' = A / (_∼'_)
IsoLarLatSmall : Iso ZL ZL'
IsoLarLatSmall = relBiimpl→TruncIso ~→∼' ~'→∼
where
~→∼' : ∀ {a b : A} → a ∼ b → a ∼' b
~→∼' r = √FGIdealCharLImpl _ ⟨ _ ⟩ (λ x h → subst (λ p → x ∈ p) r h)
, √FGIdealCharLImpl _ ⟨ _ ⟩ (λ x h → subst (λ p → x ∈ p) (sym r) h)
~'→∼ : ∀ {a b : A} → a ∼' b → a ∼ b
~'→∼ r = CommIdeal≡Char (√FGIdealCharRImpl _ ⟨ _ ⟩ (fst r))
(√FGIdealCharRImpl _ ⟨ _ ⟩ (snd r))
ZL≃ZL' : ZL ≃ ZL'
ZL≃ZL' = isoToEquiv IsoLarLatSmall
|
{
"alphanum_fraction": 0.5179111869,
"avg_line_length": 37.2397540984,
"ext": "agda",
"hexsha": "51dfbb2db5b1816a68171d5f591e54cff469244e",
"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": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dolio/cubical",
"max_forks_repo_path": "Cubical/Algebra/ZariskiLattice/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"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": "dolio/cubical",
"max_issues_repo_path": "Cubical/Algebra/ZariskiLattice/Base.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8d687c1a6237ad2db1396c6b0af6667bd203f548",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dolio/cubical",
"max_stars_repo_path": "Cubical/Algebra/ZariskiLattice/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 8022,
"size": 18173
}
|
------------------------------------------------------------------------
-- The semantics in Lambda.Closure.Relational and
-- Lambda.Closure.Functional are equivalent
------------------------------------------------------------------------
module Lambda.Closure.Equivalence where
open import Axiom.ExcludedMiddle
open import Category.Monad.Partiality as Partiality
using (_⊥; never; steps; module Steps)
open import Codata.Musical.Notation
open import Data.Empty using (⊥-elim)
open import Data.Maybe hiding (_>>=_)
open import Data.Nat
open import Data.Nat.Induction
import Data.Nat.Properties as ℕ
import Data.Nat.Solver as ℕ
open import Data.Product
open import Data.Sum
open import Data.Vec using (Vec; []; _∷_)
open import Function
import Level
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open import Relation.Nullary.Negation
open ℕ.+-*-Solver using (solve; _:=_; _:+_; con)
open Partiality._⊥
private
open module PE {A : Set} = Partiality.Equality (_≡_ {A = A})
open module PR {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
hiding (_≡⟨_⟩_) renaming (_∎ to _□)
open import Lambda.Syntax
open Closure Tm
open import Lambda.Closure.Relational as R
open import Lambda.Closure.Functional as F hiding (module Workaround)
open PF
------------------------------------------------------------------------
-- Successful, terminating computations
-- The functional semantics is complete with respect to the relational
-- one.
complete⇓ : ∀ {n} {t : Tm n} {ρ v} →
ρ ⊢ t ⇓ v → ⟦ t ⟧ ρ ≈ return v
complete⇓ var = _ □
complete⇓ con = _ □
complete⇓ ƛ = _ □
complete⇓ {ρ = ρ} {v} (app {t₁} {t₂} {t = t} {ρ′} {v′ = v′} t₁⇓ t₂⇓ t₁t₂⇓) =
⟦ t₁ · t₂ ⟧ ρ ≅⟨ ·-comp t₁ t₂ ⟩
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟨ complete⇓ t₁⇓ ⟦·⟧-cong complete⇓ t₂⇓ ⟩
return (ƛ t ρ′) ⟦·⟧ return v′ ≳⟨ laterˡ (_ □) ⟩
⟦ t ⟧ (v′ ∷ ρ′) ≈⟨ complete⇓ t₁t₂⇓ ⟩
return v □
-- The functional semantics is sound with respect to the relational
-- one.
sound⇓ : ∀ {n} (t : Tm n) {ρ : Env n} {v} →
⟦ t ⟧ ρ ≈ return v → ρ ⊢ t ⇓ v
sound⇓ t t⇓ = <′-rec P sound⇓′ (steps t⇓) t t⇓ P.refl
where
P : ℕ → Set
P s = ∀ {n} (t : Tm n) {ρ : Env n} {v}
(t⇓ : ⟦ t ⟧ ρ ≈ return v) → steps t⇓ ≡ s → ρ ⊢ t ⇓ v
sound⇓′ : ∀ s → <′-Rec P s → P s
sound⇓′ s rec (con i) (now P.refl) _ = con
sound⇓′ s rec (var x) (now P.refl) _ = var
sound⇓′ s rec (ƛ t) (now P.refl) _ = ƛ
sound⇓′ s rec (t₁ · t₂) {ρ} {v} t₁t₂⇓ eq
with >>=-inversion-⇓ (⟦ t₁ ⟧ ρ) (
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩
return v □)
sound⇓′ s rec (t₁ · t₂) {ρ} t₁t₂⇓ eq | (v₁ , t₁⇓ , t₂∙⇓ , eq₁) with >>=-inversion-⇓ (⟦ t₂ ⟧ ρ) t₂∙⇓
sound⇓′ s rec (t₁ · t₂) t₁t₂⇓ eq | (con i , t₁⇓ , t₂∙⇓ , eq₁) | (v₂ , t₂⇓ , now () , _ )
sound⇓′ s rec (t₁ · t₂) {ρ} {v} t₁t₂⇓ eq | (ƛ t _ , t₁⇓ , t₂∙⇓ , eq₁) | (v₂ , t₂⇓ , laterˡ ∙⇓ , eq₂) =
app (rec (steps t₁⇓) ₁< t₁ t₁⇓ P.refl)
(rec (steps t₂⇓) ₂< t₂ t₂⇓ P.refl)
(rec (steps ∙⇓) ∙< t ∙⇓ P.refl)
where
open ℕ.≤-Reasoning
₁₂∙< = begin
1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≡⟨ solve 3 (λ x y z → con 1 :+ x :+ (y :+ z) :=
x :+ (y :+ (con 1 :+ z)))
P.refl (steps t₁⇓) (steps t₂⇓) _ ⟩
steps t₁⇓ + (steps t₂⇓ + (1 + steps ∙⇓)) ≡⟨ P.cong (_+_ (steps t₁⇓)) eq₂ ⟩
steps t₁⇓ + steps t₂∙⇓ ≡⟨ eq₁ ⟩
steps (⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩
return v □) ≡⟨ Steps.left-identity (sym $ ·-comp t₁ t₂) _ ⟩
steps (⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇓ ⟩
return v □) ≡⟨ Steps.right-identity t₁t₂⇓ (return v □) ⟩
steps t₁t₂⇓ ≡⟨ eq ⟩
s ∎
₁< = ℕ.≤⇒≤′ (begin
1 + steps t₁⇓ ≤⟨ ℕ.m≤m+n (1 + steps t₁⇓) _ ⟩
1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≤⟨ ₁₂∙< ⟩
s ∎)
₂∙< = begin
1 + steps t₂⇓ + steps ∙⇓ ≤⟨ s≤s (ℕ.m≤n+m _ (steps t₁⇓)) ⟩
1 + steps t₁⇓ + (steps t₂⇓ + steps ∙⇓) ≤⟨ ₁₂∙< ⟩
s ∎
₂< = ℕ.≤⇒≤′ (begin
1 + steps t₂⇓ ≤⟨ ℕ.m≤m+n (1 + steps t₂⇓) _ ⟩
1 + steps t₂⇓ + steps ∙⇓ ≤⟨ ₂∙< ⟩
s ∎)
∙< = ℕ.≤⇒≤′ (begin
1 + steps ∙⇓ ≤⟨ s≤s (ℕ.m≤n+m _ (steps t₂⇓)) ⟩
1 + steps t₂⇓ + steps ∙⇓ ≤⟨ ₂∙< ⟩
s ∎)
------------------------------------------------------------------------
-- Non-terminating computations
-- The functional semantics is complete for non-terminating computations.
module Complete⇑ where
infix 4 _≈P_ _≈W_
infixr 2 _≅⟪_⟫_ _≳⟪_⟫_ _≈⟪_⟫_
data _≈P_ : Maybe Value ⊥ → Maybe Value ⊥ → Set₁ where
⌈_⌉ : ∀ {x y} (x≳y : x ≳ y) → x ≈P y
later : ∀ {x y} (x≈y : ∞ (♭ x ≈P ♭ y)) → later x ≈P later y
_>>=P_ : ∀ {x₁ x₂ f₁ f₂} →
(x₁≈x₂ : x₁ ≈P x₂) (f₁≈f₂ : ∀ x → f₁ x ≈P f₂ x) →
(x₁ >>= f₁) ≈P (x₂ >>= f₂)
_⟦·⟧P_ : ∀ {v₁₁ v₁₂ v₂₁ v₂₂} →
(v₁₁≈v₂₁ : v₁₁ ≈P v₂₁) (v₁₂≈v₂₂ : v₁₂ ≈P v₂₂) →
v₁₁ ⟦·⟧ v₁₂ ≈P v₂₁ ⟦·⟧ v₂₂
_≅⟪_⟫_ : ∀ x {y z} (x≅y : x ≅ y) (y≈z : y ≈P z) → x ≈P z
_≳⟪_⟫_ : ∀ x {y z} (x≳y : x ≳ y) (y≈z : y ≈P z) → x ≈P z
_≈⟪_⟫_ : ∀ x {y z} (x≈y : x ≈P y) (y≅z : y ≅ z) → x ≈P z
private
data _≈W_ : Maybe Value ⊥ → Maybe Value ⊥ → Set₁ where
now : ∀ {v} → now v ≈W now v
later : ∀ {x y} (x≈y : ♭ x ≈P ♭ y) → later x ≈W later y
laterˡ : ∀ {x y} (x≈y : ♭ x ≈W y) → later x ≈W y
⌈_⌉W : ∀ {x y} → x ≳ y → x ≈W y
⌈ now P.refl ⌉W = now
⌈ later x≳y ⌉W = later ⌈ ♭ x≳y ⌉
⌈ laterˡ x≳y ⌉W = laterˡ ⌈ x≳y ⌉W
program : ∀ {x y} → x ≈W y → x ≈P y
program now = ⌈ now P.refl ⌉
program (later x≈y) = later (♯ x≈y)
program (laterˡ x≈y) = _ ≳⟪ laterˡ (_ □) ⟫ program x≈y
_>>=W_ : ∀ {x₁ x₂ f₁ f₂} →
x₁ ≈W x₂ → (∀ x → f₁ x ≈W f₂ x) →
(x₁ >>= f₁) ≈W (x₂ >>= f₂)
now {v = nothing} >>=W f₁≈f₂ = now
now {v = just v } >>=W f₁≈f₂ = f₁≈f₂ v
later x≈y >>=W f₁≈f₂ = later (x≈y >>=P (program ∘ f₁≈f₂))
laterˡ x≈y >>=W f₁≈f₂ = laterˡ (x≈y >>=W f₁≈f₂)
_⟦·⟧W_ : ∀ {v₁₁ v₁₂ v₂₁ v₂₂} →
v₁₁ ≈W v₂₁ → v₁₂ ≈W v₂₂ → v₁₁ ⟦·⟧ v₁₂ ≈W v₂₁ ⟦·⟧ v₂₂
v₁₁≈v₂₁ ⟦·⟧W v₁₂≈v₂₂ =
v₁₁≈v₂₁ >>=W λ v₁ →
v₁₂≈v₂₂ >>=W λ v₂ →
⌈ ⟪ v₁ ∙ v₂ ⟫P □ ⌉W
where open F.Workaround
trans≅≈W : ∀ {x y z} → x ≅ y → y ≈W z → x ≈W z
trans≅≈W (now P.refl) now = now
trans≅≈W (later x≅y) (later y≈z) = later (_ ≅⟪ ♭ x≅y ⟫ y≈z)
trans≅≈W (later x≅y) (laterˡ y≈z) = laterˡ (trans≅≈W (♭ x≅y) y≈z)
trans≳≈W : ∀ {x y z} → x ≳ y → y ≈W z → x ≈W z
trans≳≈W (now P.refl) now = now
trans≳≈W (later x≳y) (later y≈z) = later (_ ≳⟪ ♭ x≳y ⟫ y≈z)
trans≳≈W (later x≳y) (laterˡ y≈z) = laterˡ (trans≳≈W (♭ x≳y) y≈z)
trans≳≈W (laterˡ x≳y) y≈z = laterˡ (trans≳≈W x≳y y≈z)
trans≈W≅ : ∀ {x y z} → x ≈W y → y ≅ z → x ≈W z
trans≈W≅ now (now P.refl) = now
trans≈W≅ (later x≈y) (later y≅z) = later (_ ≈⟪ x≈y ⟫ ♭ y≅z)
trans≈W≅ (laterˡ x≈y) y≅z = laterˡ (trans≈W≅ x≈y y≅z)
whnf : ∀ {x y} → x ≈P y → x ≈W y
whnf ⌈ x≳y ⌉ = ⌈ x≳y ⌉W
whnf (later x≈y) = later (♭ x≈y)
whnf (x₁≈x₂ >>=P f₁≈f₂) = whnf x₁≈x₂ >>=W λ v → whnf (f₁≈f₂ v)
whnf (v₁₁≈v₂₁ ⟦·⟧P v₁₂≈v₂₂) = whnf v₁₁≈v₂₁ ⟦·⟧W whnf v₁₂≈v₂₂
whnf (x ≅⟪ x≅y ⟫ y≈z) = trans≅≈W x≅y (whnf y≈z)
whnf (x ≳⟪ x≳y ⟫ y≈z) = trans≳≈W x≳y (whnf y≈z)
whnf (x ≈⟪ x≈y ⟫ y≅z) = trans≈W≅ (whnf x≈y) y≅z
mutual
-- Note that the types of soundW and soundP could be strengthened:
-- laterʳ is not used.
private
soundW : ∀ {x y} → x ≈W y → x ≈ y
soundW now = now P.refl
soundW (later x≈y) = later (♯ soundP x≈y)
soundW (laterˡ x≈y) = laterˡ (soundW x≈y)
soundP : ∀ {x y} → x ≈P y → x ≈ y
soundP x≈y = soundW (whnf x≈y)
-- The language _≈P_ does not include transitivity for weak
-- equality, as this would be unsound. Instead some limited notions
-- of transitivity are used:
--
-- • Weak equality can be combined with strong equality on both
-- sides.
--
-- • The _≳_ order can be "prepended" to a weak equality. Note that
-- results of the form "x ≈ return v" can be turned into
-- "x ≳ return v", as in the first case below.
complete⇑ : ∀ {n} {t : Tm n} {ρ : Env n} →
ρ ⊢ t ⇑ → ⟦ t ⟧ ρ ≈P never
complete⇑ {ρ = ρ} (app {t₁} {t₂} {t = t} {ρ′} {v} t₁⇓ t₂⇓ t₁t₂⇑) =
⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≳⟪ Partiality.now⇒now (complete⇓ t₁⇓) ⟦·⟧-cong
Partiality.now⇒now (complete⇓ t₂⇓) ⟫
return (ƛ t ρ′) ⟦·⟧ return v ≅⟪ later (♯ (_ □)) ⟫
later (♯ ⟦ t ⟧ (v ∷ ρ′)) ≈⟪ later (♯ complete⇑ (♭ t₁t₂⇑)) ⟫
never □
complete⇑ {ρ = ρ} (·ˡ {t₁} {t₂} t₁⇑) =
⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟪ complete⇑ (♭ t₁⇑) ⟦·⟧P ⌈ ⟦ t₂ ⟧ ρ □ ⌉ ⟫
never ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ Partiality.left-zero _ ⟩
never □
complete⇑ {ρ = ρ} (·ʳ {t₁} {t₂} {v} t₁⇓ t₂⇑) =
⟦ t₁ · t₂ ⟧ ρ ≅⟪ ·-comp t₁ t₂ ⟫
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≈⟪ ⌈ Partiality.now⇒now (complete⇓ t₁⇓) ⌉ ⟦·⟧P complete⇑ (♭ t₂⇑) ⟫
return v ⟦·⟧ never ≅⟨ Partiality.left-zero _ ⟩
never □
complete⇑ : ∀ {n} {t : Tm n} {ρ : Env n} →
ρ ⊢ t ⇑ → ⟦ t ⟧ ρ ≈ never
complete⇑ = Complete⇑.soundP ∘ Complete⇑.complete⇑
-- The functional semantics is sound for non-terminating computations.
-- I assume excluded middle here because double-negation elimination
-- is used "infinitely often".
sound⇑ : ExcludedMiddle Level.zero →
∀ {n} (t : Tm n) {ρ : Env n} →
⟦ t ⟧ ρ ≈ never → ρ ⊢ t ⇑
sound⇑ em (con i) i⇑ = ⊥-elim (Partiality.now≉never i⇑)
sound⇑ em (var x) x⇑ = ⊥-elim (Partiality.now≉never x⇑)
sound⇑ em (ƛ t) ƛ⇑ = ⊥-elim (Partiality.now≉never ƛ⇑)
sound⇑ em (t₁ · t₂) {ρ} t₁t₂⇑
with decidable-stable em $ >>=-inversion-⇑ (⟦ t₁ ⟧ ρ) (
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ≅⟨ sym $ ·-comp t₁ t₂ ⟩
⟦ t₁ · t₂ ⟧ ρ ≈⟨ t₁t₂⇑ ⟩
never □)
sound⇑ em (t₁ · t₂) ⇑ | inj₁ t₁⇑ = ·ˡ (♯ sound⇑ em t₁ t₁⇑)
sound⇑ em (t₁ · t₂) {ρ} ⇑ | inj₂ (v₁ , t₁⇓ , t₂∙⇑)
with decidable-stable em $ >>=-inversion-⇑ (⟦ t₂ ⟧ ρ) t₂∙⇑
sound⇑ em (t₁ · t₂) ⇑ | inj₂ (v₁ , t₁⇓ , t₂∙⇑) | inj₁ t₂⇑ = ·ʳ (sound⇓ t₁ t₁⇓) (♯ sound⇑ em t₂ t₂⇑)
sound⇑ em (t₁ · t₂) ⇑ | inj₂ (con i , t₁⇓ , t₂∙⇑) | inj₂ (v₂ , t₂⇓ , ∙⇑) = ⊥-elim (Partiality.now≉never ∙⇑)
sound⇑ em (t₁ · t₂) ⇑ | inj₂ (ƛ t _ , t₁⇓ , t₂∙⇑) | inj₂ (v₂ , t₂⇓ , ∙⇑) =
app (sound⇓ t₁ t₁⇓) (sound⇓ t₂ t₂⇓) (♯ sound⇑ em t (Partiality.later⁻¹ ∙⇑))
------------------------------------------------------------------------
-- Crashing computations
-- The functional semantics is complete for crashing computations.
complete↯ : ExcludedMiddle Level.zero →
∀ {n} (t : Tm n) (ρ : Env n) →
ρ ⊢ t ↯ → ⟦ t ⟧ ρ ≈ fail
complete↯ em t ρ ¬⇒
with decidable-stable em $
Partiality.now-or-never {_∼_ = _≡_} P.refl
{k = Partiality.weak} (⟦ t ⟧ ρ)
... | inj₂ t⇑ = ⊥-elim (proj₂ ¬⇒ (sound⇑ em t t⇑))
... | inj₁ (nothing , t↯) = t↯
... | inj₁ (just v , t⇓) = ⊥-elim (proj₁ ¬⇒ (-, sound⇓ t t⇓))
-- The functional semantics is sound for crashing computations.
sound↯ : ∀ {n} {t : Tm n} {ρ : Env n} →
⟦ t ⟧ ρ ≈ fail → ρ ⊢ t ↯
sound↯ {t = t} {ρ} t↯ = (¬⇓ , ¬⇑)
where
¬⇓ : ¬ (∃ λ v → ρ ⊢ t ⇓ v)
¬⇓ (v , t⇓) with
fail ≈⟨ sym t↯ ⟩
⟦ t ⟧ ρ ≈⟨ complete⇓ t⇓ ⟩
return v □
... | now ()
¬⇑ : ¬ (ρ ⊢ t ⇑)
¬⇑ t⇑ = Partiality.now≉never (
fail ≈⟨ sym t↯ ⟩
⟦ t ⟧ ρ ≈⟨ complete⇑ t⇑ ⟩
never □)
|
{
"alphanum_fraction": 0.436521878,
"avg_line_length": 40.0127795527,
"ext": "agda",
"hexsha": "c4dcb48bac13bef45990635ddad197df4e25f080",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Closure/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "Lambda/Closure/Equivalence.agda",
"max_line_length": 114,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Closure/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 6052,
"size": 12524
}
|
module sn-calculus-compatconf.eview where
open import sn-calculus-compatconf.base
open import sn-calculus-compatconf.in-lift using (1-steplρ-E-view-ecin-lift)
open import sn-calculus-compatconf.split using (1-steplρ-E-view-ecsplit)
open import sn-calculus-compatconf.same using (1-steplρ-E-view-ecsame)
open import sn-calculus
open import utility renaming (_U̬_ to _∪_)
open import context-properties
using (get-view ; ->E-view ; ->pot-view)
open import sn-calculus-confluence
using (R-confluent)
open import Esterel.Lang
open import Esterel.Lang.Properties
open import Esterel.Lang.Binding
open import Esterel.Lang.CanFunction
using (Can ; Canₛ ; Canₛₕ ; Canₖ ; module CodeSet)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; Dom ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Context.Properties
using (plugc)
open import Esterel.CompletionCode as Code
using () renaming (CompletionCode to Code)
open import Esterel.Variable.Signal as Signal
using (Signal ; _ₛ)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar ; _ₛₕ)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar ; _ᵥ)
open import Relation.Nullary
using (¬_ ; Dec ; yes ; no)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; sym ; cong ; trans ; subst ; module ≡-Reasoning)
open import Data.Bool
using (Bool ; if_then_else_)
open import Data.Empty
using (⊥ ; ⊥-elim)
open import Data.List
using (List ; _∷_ ; [] ; _++_)
open import Data.List.Any
using (Any ; any ; here ; there)
open import Data.List.Any.Properties
using ()
renaming ( ++⁺ˡ to ++ˡ ; ++⁺ʳ to ++ʳ )
open import Data.Maybe
using (Maybe ; just ; nothing)
open import Data.Nat
using (ℕ ; zero ; suc ; _+_) renaming (_⊔_ to _⊔ℕ_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; _,′_ ; proj₁ ; proj₂ ; _×_ ; ∃ ; map)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open import Function using (_∘_ ; id ; _∋_)
open import Data.OrderedListMap Signal Signal.unwrap Signal.Status as SigM
open import Data.OrderedListMap SharedVar SharedVar.unwrap (Σ SharedVar.Status (λ _ → ℕ)) as ShrM
open import Data.OrderedListMap SeqVar SeqVar.unwrap ℕ as SeqM
open ->E-view
open ->pot-view
open EvaluationContext1
open _≐_⟦_⟧e
open Context1
open _≐_⟦_⟧c
open ListSet Data.Nat._≟_
{-
p
ρθ. E⟦qin⟧ -- sn⟶₁ -> ρθq. E⟦qo⟧
(ρθ) C⟦rin⟧ -- sn⟶ -> (ρθ) C⟦ro⟧
-}
1-steplρ-E-view : ∀{E C p qin q qo rin ro θ θq BV FV A Aq} →
{ρθ·psn⟶₁ρθq·q : ρ⟨ θ , A ⟩· p sn⟶₁ ρ⟨ θq , Aq ⟩· q} →
CorrectBinding (ρ⟨ θ , A ⟩· p) BV FV →
(p≐E⟦qin⟧ : p ≐ E ⟦ qin ⟧e) →
(q≐E⟦qo⟧ : q ≐ E ⟦ qo ⟧e) →
->E-view ρθ·psn⟶₁ρθq·q p≐E⟦qin⟧ q≐E⟦qo⟧ →
(p≐E⟦rin⟧ : p ≐ C ⟦ rin ⟧c) →
(rinsn⟶₁ro : rin sn⟶₁ ro) →
∃ λ { (θo , Ao , po) →
(ρ⟨ θq , Aq ⟩· q sn⟶* ρ⟨ θo , Ao ⟩· po) ×
(ρ⟨ θ , A ⟩· C ⟦ ro ⟧c sn⟶* ρ⟨ θo , Ao ⟩· po) }
1-steplρ-E-view (CBρ cb) p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro
with get-context-prefix p≐E⟦qin⟧ p≐C⟦rin⟧
1-steplρ-E-view (CBρ cb) p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro | ecsame =
map proj₁ (map (sn⟶*-inclusion ∘ sn⟶-inclusion) (sn⟶*-inclusion ∘ sn⟶-inclusion ∘ proj₁))
(1-steplρ-E-view-ecsame cb p≐E⟦qin⟧ q≐E⟦qo⟧ e-view
p≐C⟦rin⟧ (plugc refl) rinsn⟶₁ro)
1-steplρ-E-view (CBρ cb) p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro | ecin-lift =
⊥-elim
(1-steplρ-E-view-ecin-lift cb p≐E⟦qin⟧ q≐E⟦qo⟧ e-view
p≐C⟦rin⟧ (plugc refl) rinsn⟶₁ro)
1-steplρ-E-view (CBρ cb) p≐E⟦qin⟧ q≐E⟦qo⟧ e-view p≐C⟦rin⟧ rinsn⟶₁ro | ecsplit div
with 1-steplρ-E-view-ecsplit cb div p≐E⟦qin⟧ q≐E⟦qo⟧ e-view
p≐C⟦rin⟧ (plugc refl) rinsn⟶₁ro
... | po , inj₁ refl , _ , _ , _ , ρθ·rsn⟶₁ρθq·po , e-view' =
_ , rrefl ,′ sn⟶*-inclusion (sn⟶-inclusion ρθ·rsn⟶₁ρθq·po)
... | po , inj₂ qsn⟶po , _ , _ , _ , ρθ·rsn⟶₁ρθq·po , e-view' =
_ , sn⟶*-inclusion (Context1-sn⟶ (cenv _ _) qsn⟶po) ,′ sn⟶*-inclusion (sn⟶-inclusion ρθ·rsn⟶₁ρθq·po)
|
{
"alphanum_fraction": 0.6449029126,
"avg_line_length": 36.4601769912,
"ext": "agda",
"hexsha": "6e90333118cd2cf84eb9f353d57848e49f26c1d6",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus-compatconf/eview.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus-compatconf/eview.agda",
"max_line_length": 104,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus-compatconf/eview.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 1807,
"size": 4120
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Union of two binary relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Binary.Construct.Union where
open import Data.Product
open import Data.Sum
open import Function using (_∘_)
open import Level using (_⊔_)
open import Relation.Binary
open import Relation.Nullary using (yes; no)
------------------------------------------------------------------------
-- Definition
_∪_ : ∀ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} →
REL A B ℓ₁ → REL A B ℓ₂ → REL A B (ℓ₁ ⊔ ℓ₂)
L ∪ R = λ i j → L i j ⊎ R i j
------------------------------------------------------------------------
-- Properties
module _ {a ℓ} {A : Set a} (L : Rel A ℓ) (R : Rel A ℓ) where
reflexive : Reflexive L ⊎ Reflexive R → Reflexive (L ∪ R)
reflexive (inj₁ L-refl) = inj₁ L-refl
reflexive (inj₂ R-refl) = inj₂ R-refl
total : Total L ⊎ Total R → Total (L ∪ R)
total (inj₁ L-total) x y = [ inj₁ ∘ inj₁ , inj₂ ∘ inj₁ ] (L-total x y)
total (inj₂ R-total) x y = [ inj₁ ∘ inj₂ , inj₂ ∘ inj₂ ] (R-total x y)
min : ∀ {⊤} → Minimum L ⊤ ⊎ Minimum R ⊤ → Minimum (L ∪ R) ⊤
min = [ inj₁ ∘_ , inj₂ ∘_ ]
max : ∀ {⊥} → Maximum L ⊥ ⊎ Maximum R ⊥ → Maximum (L ∪ R) ⊥
max = [ inj₁ ∘_ , inj₂ ∘_ ]
module _ {a ℓ} {A : Set a} {L : Rel A ℓ} {R : Rel A ℓ} where
symmetric : Symmetric L → Symmetric R → Symmetric (L ∪ R)
symmetric L-sym R-sym = [ inj₁ ∘ L-sym , inj₂ ∘ R-sym ]
respects : ∀ {p} {P : A → Set p} →
P Respects L → P Respects R → P Respects (L ∪ R)
respects resp-L resp-R = [ resp-L , resp-R ]
module _ {a b ℓ₁ ℓ₂ ℓ₃} {A : Set a} {B : Set b}
(≈ : REL A B ℓ₁) (L : REL A B ℓ₂) (R : REL A B ℓ₃) where
implies : (≈ ⇒ L) ⊎ (≈ ⇒ R) → ≈ ⇒ (L ∪ R)
implies = [ inj₁ ∘_ , inj₂ ∘_ ]
irreflexive : Irreflexive ≈ L → Irreflexive ≈ R → Irreflexive ≈ (L ∪ R)
irreflexive L-irrefl R-irrefl x≈y = [ L-irrefl x≈y , R-irrefl x≈y ]
module _ {a b ℓ₁ ℓ₂} {A : Set a} {B : Set b} {L : REL A B ℓ₁} {R : REL A B ℓ₂} where
decidable : Decidable L → Decidable R → Decidable (L ∪ R)
decidable L? R? x y with L? x y | R? x y
... | yes Lxy | _ = yes (inj₁ Lxy)
... | no _ | yes Rxy = yes (inj₂ Rxy)
... | no ¬Lxy | no ¬Rxy = no [ ¬Lxy , ¬Rxy ]
|
{
"alphanum_fraction": 0.4882928906,
"avg_line_length": 34.0434782609,
"ext": "agda",
"hexsha": "5e25f3e54879f6528f8f8e093f4e4c720f31bfdf",
"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/Relation/Binary/Construct/Union.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/Relation/Binary/Construct/Union.agda",
"max_line_length": 84,
"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/Relation/Binary/Construct/Union.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 885,
"size": 2349
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Core algebraic definitions
------------------------------------------------------------------------
-- The contents of this module should be accessed via `Algebra`.
{-# OPTIONS --without-K --safe #-}
module Algebra.Core where
open import Level using (_⊔_)
------------------------------------------------------------------------
-- Unary and binary operations
Op₁ : ∀ {ℓ} → Set ℓ → Set ℓ
Op₁ A = A → A
Op₂ : ∀ {ℓ} → Set ℓ → Set ℓ
Op₂ A = A → A → A
------------------------------------------------------------------------
-- Left and right actions
Opₗ : ∀ {a b} → Set a → Set b → Set (a ⊔ b)
Opₗ A B = A → B → B
Opᵣ : ∀ {a b} → Set a → Set b → Set (a ⊔ b)
Opᵣ A B = B → A → B
|
{
"alphanum_fraction": 0.3656998739,
"avg_line_length": 24.78125,
"ext": "agda",
"hexsha": "9256d011e962eb38f4d3b2e450d32e149c9dc64a",
"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/Algebra/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/Algebra/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/Algebra/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": 195,
"size": 793
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Properties related to AllPairs
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.AllPairs.Properties where
open import Data.List hiding (any)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
import Data.List.Relation.Unary.All.Properties as All
open import Data.List.Relation.Unary.AllPairs as AllPairs using (AllPairs; []; _∷_)
open import Data.Bool.Base using (true; false)
open import Data.Fin.Base using (Fin)
open import Data.Fin.Properties using (suc-injective)
open import Data.Nat.Base using (zero; suc; _<_; z≤n; s≤s)
open import Data.Nat.Properties using (≤-refl; ≤-step)
open import Function using (_∘_; flip)
open import Relation.Binary using (Rel; DecSetoid)
open import Relation.Binary.PropositionalEquality using (_≢_)
open import Relation.Unary using (Pred; Decidable)
open import Relation.Nullary using (does)
------------------------------------------------------------------------
-- Introduction (⁺) and elimination (⁻) rules for list operations
------------------------------------------------------------------------
-- map
module _ {a b ℓ} {A : Set a} {B : Set b} {R : Rel A ℓ} {f : B → A} where
map⁺ : ∀ {xs} → AllPairs (λ x y → R (f x) (f y)) xs →
AllPairs R (map f xs)
map⁺ [] = []
map⁺ (x∉xs ∷ xs!) = All.map⁺ x∉xs ∷ map⁺ xs!
------------------------------------------------------------------------
-- ++
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
++⁺ : ∀ {xs ys} → AllPairs R xs → AllPairs R ys →
All (λ x → All (R x) ys) xs → AllPairs R (xs ++ ys)
++⁺ [] Rys _ = Rys
++⁺ (px ∷ Rxs) Rys (Rxys ∷ Rxsys) = All.++⁺ px Rxys ∷ ++⁺ Rxs Rys Rxsys
------------------------------------------------------------------------
-- concat
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
concat⁺ : ∀ {xss} → All (AllPairs R) xss →
AllPairs (λ xs ys → All (λ x → All (R x) ys) xs) xss →
AllPairs R (concat xss)
concat⁺ [] [] = []
concat⁺ (pxs ∷ pxss) (Rxsxss ∷ Rxss) = ++⁺ pxs (concat⁺ pxss Rxss)
(All.map All.concat⁺ (All.All-swap Rxsxss))
------------------------------------------------------------------------
-- take and drop
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
take⁺ : ∀ {xs} n → AllPairs R xs → AllPairs R (take n xs)
take⁺ zero pxs = []
take⁺ (suc n) [] = []
take⁺ (suc n) (px ∷ pxs) = All.take⁺ n px ∷ take⁺ n pxs
drop⁺ : ∀ {xs} n → AllPairs R xs → AllPairs R (drop n xs)
drop⁺ zero pxs = pxs
drop⁺ (suc n) [] = []
drop⁺ (suc n) (_ ∷ pxs) = drop⁺ n pxs
------------------------------------------------------------------------
-- applyUpTo
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
applyUpTo⁺₁ : ∀ f n → (∀ {i j} → i < j → j < n → R (f i) (f j)) → AllPairs R (applyUpTo f n)
applyUpTo⁺₁ f zero Rf = []
applyUpTo⁺₁ f (suc n) Rf =
All.applyUpTo⁺₁ _ n (Rf (s≤s z≤n) ∘ s≤s) ∷
applyUpTo⁺₁ _ n (λ i≤j j<n → Rf (s≤s i≤j) (s≤s j<n))
applyUpTo⁺₂ : ∀ f n → (∀ i j → R (f i) (f j)) → AllPairs R (applyUpTo f n)
applyUpTo⁺₂ f n Rf = applyUpTo⁺₁ f n (λ _ _ → Rf _ _)
------------------------------------------------------------------------
-- applyDownFrom
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
applyDownFrom⁺₁ : ∀ f n → (∀ {i j} → j < i → i < n → R (f i) (f j)) →
AllPairs R (applyDownFrom f n)
applyDownFrom⁺₁ f zero Rf = []
applyDownFrom⁺₁ f (suc n) Rf =
All.applyDownFrom⁺₁ _ n (flip Rf ≤-refl) ∷
applyDownFrom⁺₁ f n (λ j<i i<n → Rf j<i (≤-step i<n))
applyDownFrom⁺₂ : ∀ f n → (∀ i j → R (f i) (f j)) → AllPairs R (applyDownFrom f n)
applyDownFrom⁺₂ f n Rf = applyDownFrom⁺₁ f n (λ _ _ → Rf _ _)
------------------------------------------------------------------------
-- tabulate
module _ {a ℓ} {A : Set a} {R : Rel A ℓ} where
tabulate⁺ : ∀ {n} {f : Fin n → A} → (∀ {i j} → i ≢ j → R (f i) (f j)) →
AllPairs R (tabulate f)
tabulate⁺ {zero} fᵢ~fⱼ = []
tabulate⁺ {suc n} fᵢ~fⱼ =
All.tabulate⁺ (λ j → fᵢ~fⱼ λ()) ∷
tabulate⁺ (fᵢ~fⱼ ∘ (_∘ suc-injective))
------------------------------------------------------------------------
-- filter
module _ {a ℓ p} {A : Set a} {R : Rel A ℓ}
{P : Pred A p} (P? : Decidable P) where
filter⁺ : ∀ {xs} → AllPairs R xs → AllPairs R (filter P? xs)
filter⁺ {_} [] = []
filter⁺ {x ∷ xs} (x∉xs ∷ xs!) with does (P? x)
... | false = filter⁺ xs!
... | true = All.filter⁺ P? x∉xs ∷ filter⁺ xs!
|
{
"alphanum_fraction": 0.458164786,
"avg_line_length": 36.9842519685,
"ext": "agda",
"hexsha": "0aeeb7bb89a0d1cd15746300ad8b326adfc50b7d",
"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/Unary/AllPairs/Properties.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/Unary/AllPairs/Properties.agda",
"max_line_length": 94,
"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/Unary/AllPairs/Properties.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": 1611,
"size": 4697
}
|
record R₁ (M : Set → Set) : Set₁ where
field
return : ∀ {A} → A → M A
map : ∀ {A B} → (A → B) → M A → M B
open R₁ ⦃ … ⦄ public
record R₂ (M : Set → Set) : Set₁ where
field
instance
r₁ : R₁ M
data Wrap₁ (A : Set) : Set where
box : A → Wrap₁ A
instance
r₁ : R₁ Wrap₁
R₁.return r₁ x = box x
R₁.map r₁ f (box x) = box (f x)
record Wrap₂ (A : Set) : Set where
field
run : A
postulate
instance
r₂ : R₂ Wrap₂
A : Set
f : A → A
g : A → Wrap₁ A
_≡_ : {A : Set} → A → A → Set
refl : {A : Set} (x : A) → x ≡ x
trans : {A : Set} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z
id : {A : Set} (x : A) {y : A} → x ≡ y → x ≡ y
h : ∀ x → map f (g x) ≡ map f (return x) → map f (g x) ≡ return (f x)
h x eq =
trans (map f (g x))
eq
(id (map f (return x))
(refl (return (f x))))
|
{
"alphanum_fraction": 0.4471264368,
"avg_line_length": 19.3333333333,
"ext": "agda",
"hexsha": "ecd14461ccfe43227ed92935cdb9cbd1f4e23c46",
"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/Issue2296.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/Issue2296.agda",
"max_line_length": 69,
"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/Issue2296.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": 389,
"size": 870
}
|
open import Algebra
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Pos as ℕ⁺
open import Data.List as L using (List; []; _∷_; _++_)
open import Data.List.Any as LA using (Any; here; there)
open import Data.List.Any.BagAndSetEquality as B
open import Data.Product as PR using (∃; _×_; _,_; proj₁; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_$_; flip)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as I using ()
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import Data.Environment
open import nodcap.Base
open import nodcap.NF.Typing
module nodcap.NF.Expand where
open I.Inverse using (to; from)
private module ++ {a} {A : Set a} = Monoid (L.monoid A)
{-# TERMINATING #-}
-- Lemma:
-- We can expand an instance of ?[ n ] A into n repetitions of A,
-- by induction on n.
--
-- Problematic calls:
-- * in the recursive call under cont, the index n is split as
-- n₁ + n₂, for which we have n₁, n₂ < n, but not definitionally.
mutual
expand : {Γ : Environment} {A : Type} {n : ℕ⁺} →
⊢ⁿᶠ ?[ n ] A ∷ Γ →
--------------------
⊢ⁿᶠ replicate⁺ n A ++ Γ
expand (mk?₁ x) = x
expand (cont {Γ} {A} {m} {n} x)
= P.subst (λ Δ → ⊢ⁿᶠ Δ ++ Γ) (replicate⁺-++-commute m n)
$ P.subst ⊢ⁿᶠ_ (P.sym (++.assoc (replicate⁺ m A) (replicate⁺ n A) Γ))
$ exch (swp [] (replicate⁺ m A) (replicate⁺ n A))
$ expand {n = n}
$ exch (fwd [] (replicate⁺ m A))
$ expand {n = m} x
expand {Γ} {A} {n} (exch b x)
= exch (B.++-cong {xs₁ = replicate⁺ n A} I.id (del-from b (here P.refl)))
$ expandIn (from b ⟨$⟩ here P.refl) x
expandIn : {Γ : Environment} {A : Type} {n : ℕ⁺} (i : ?[ n ] A ∈ Γ) →
⊢ⁿᶠ Γ →
----------------------------
⊢ⁿᶠ replicate⁺ n A ++ Γ - i
expandIn (here P.refl) x = expand x
expandIn {_} {A} {n} (there i) (send {Γ} {Δ} x h)
with split Γ i
... | inj₁ (j , p) rewrite p
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ replicate⁺ n A) (Γ - j) Δ)
$ flip send h
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there j) x
... | inj₂ (j , p) rewrite p
= exch (swp [] (replicate⁺ n A) (_ ∷ Γ))
$ send x
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there j) h
expandIn {Γ} {A} {n} (there i) (recv x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ recv
$ exch (swp [] (_ ∷ _ ∷ []) (replicate⁺ n A))
$ expandIn (there (there i)) x
expandIn {Γ} {A} {n} (there i) (sel₁ x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ sel₁
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) x
expandIn {Γ} {A} {n} (there i) (sel₂ x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ sel₂
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) x
expandIn {Γ} {A} {n} (there i) (case x h)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ case
( exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) x )
( exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) h )
expandIn (there ()) halt
expandIn {Γ} {A} {n} (there i) (wait x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ wait
$ expandIn i x
expandIn {Γ} {A} {n} (there i) loop
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ loop
expandIn {Γ} {A} {n} (there i) (mk?₁ x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ mk?₁
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) x
expandIn {Γ} {A} {n} (there i) (mk!₁ x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ mk!₁
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there i) x
expandIn {Γ} {A} {n} (there i) (cont x)
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ cont
$ exch (swp [] (_ ∷ _ ∷ []) (replicate⁺ n A))
$ expandIn (there (there i)) x
expandIn {_} {A} {n} (there i) (pool {Γ} {Δ} x y)
with split Γ i
... | inj₁ (j , p) rewrite p
= exch (swp [] (replicate⁺ n A) (_ ∷ []))
$ P.subst ⊢ⁿᶠ_ (++.assoc (_ ∷ replicate⁺ n A) (Γ - j) Δ)
$ flip pool y
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there j) x
... | inj₂ (j , p) rewrite p
= exch (swp [] (replicate⁺ n A) (_ ∷ Γ))
$ pool x
$ exch (swp [] (_ ∷ []) (replicate⁺ n A))
$ expandIn (there j) y
expandIn {Γ} {A} {n} i (exch b x)
= exch (B.++-cong {xs₁ = replicate⁺ n A} I.id (del-from b i))
$ expandIn (from b ⟨$⟩ i) x
|
{
"alphanum_fraction": 0.5145458583,
"avg_line_length": 34.3740458015,
"ext": "agda",
"hexsha": "a054bd4333c22e7d1f46c0eec9eadcbe4373bad5",
"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/NF/Expand.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/NF/Expand.agda",
"max_line_length": 77,
"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/NF/Expand.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": 1838,
"size": 4503
}
|
open import Type
module Graph {ℓ₁ ℓ₂} (V : Type{ℓ₁}) where
-- A graph is represented by a binary relation which states whether there is an edge from one vertex to another.
-- In other words, a graph is here defined by only its adjacency relation.
-- This is by default (without any assumptions) a directed multigraph which is possibly infinite.
--
-- An object of type Graph is the adjacency relation.
-- For (_⟶_ : Graph), (a b : V), an object of type (a ⟶ b) is an edge from vertices a to b, and its existence means that there is an edge from a to b.
Graph : Type
Graph = (V → V → Type{ℓ₂})
module _ (_⟶_ : Graph) where
-- Two vertices are adjacent when there is an edge from the first one to the second one.
Adjacent = _⟶_
|
{
"alphanum_fraction": 0.7135061392,
"avg_line_length": 43.1176470588,
"ext": "agda",
"hexsha": "0e0aec86c63521d6419d820930d962a56bfb94ca",
"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": "Graph.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": "Graph.agda",
"max_line_length": 150,
"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": "Graph.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": 198,
"size": 733
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Definition of Terminal object and some properties
module Categories.Object.Terminal {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Relation.Binary using (IsEquivalence; Setoid)
open import Relation.Binary.PropositionalEquality as ≡ using (_≡_)
open import Categories.Morphism C
open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟)
open import Categories.Morphism.Reasoning C
open Category C
open HomReasoning
record Terminal : Set (o ⊔ ℓ ⊔ e) where
field
⊤ : Obj
! : {A : Obj} → (A ⇒ ⊤)
!-unique : ∀ {A} → (f : A ⇒ ⊤) → ! ≈ f
!-unique₂ : ∀ {A} {f g : A ⇒ ⊤} → f ≈ g
!-unique₂ {A} {f} {g} = begin
f ≈˘⟨ !-unique f ⟩
! ≈⟨ !-unique g ⟩
g ∎
where open HomReasoning
⊤-id : (f : ⊤ ⇒ ⊤) → f ≈ id
⊤-id _ = !-unique₂
open Terminal
from-⊤-is-Mono : ∀ {A : Obj} {t : Terminal} → (f : ⊤ t ⇒ A) → Mono f
from-⊤-is-Mono {_} {t} _ = λ _ _ _ → !-unique₂ t
up-to-iso : (t₁ t₂ : Terminal) → ⊤ t₁ ≅ ⊤ t₂
up-to-iso t₁ t₂ = record
{ from = ! t₂
; to = ! t₁
; iso = record { isoˡ = ⊤-id t₁ _; isoʳ = ⊤-id t₂ _ }
}
transport-by-iso : (t : Terminal) → ∀ {X} → ⊤ t ≅ X → Terminal
transport-by-iso t {X} t≅X = record
{ ⊤ = X
; ! = from ∘ ! t
; !-unique = λ h → begin
from ∘ ! t ≈⟨ refl⟩∘⟨ !-unique t (to ∘ h) ⟩
from ∘ to ∘ h ≈⟨ cancelˡ isoʳ ⟩
h ∎
}
where open _≅_ t≅X
up-to-iso-unique : ∀ t t′ → (i : ⊤ t ≅ ⊤ t′) → up-to-iso t t′ ≃ i
up-to-iso-unique t t′ i = ⌞ !-unique t′ _ ⌟
up-to-iso-invˡ : ∀ {t X} {i : ⊤ t ≅ X} → up-to-iso t (transport-by-iso t i) ≃ i
up-to-iso-invˡ {t} {i = i} = up-to-iso-unique t (transport-by-iso t i) i
up-to-iso-invʳ : ∀ {t t′} → ⊤ (transport-by-iso t (up-to-iso t t′)) ≡ ⊤ t′
up-to-iso-invʳ {t} {t′} = ≡.refl
|
{
"alphanum_fraction": 0.5432166302,
"avg_line_length": 27.2835820896,
"ext": "agda",
"hexsha": "c9b75edd60560df7d09e7ce90da262e79387a5f3",
"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": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Terminal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"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": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Terminal.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Terminal.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 795,
"size": 1828
}
|
------------------------------------------------------------------------
-- Non-empty lists
------------------------------------------------------------------------
module Data.List.NonEmpty where
open import Data.Product hiding (map)
open import Data.Nat
open import Data.Function
open import Data.Vec as Vec using (Vec; []; _∷_)
open import Data.List as List using (List; []; _∷_)
open import Category.Monad
open import Relation.Binary.PropositionalEquality
infixr 5 _∷_ _∷ʳ_ _⁺++⁺_ _++⁺_ _⁺++_
data List⁺ (A : Set) : Set where
[_] : (x : A) → List⁺ A
_∷_ : (x : A) (xs : List⁺ A) → List⁺ A
length_-1 : ∀ {A} → List⁺ A → ℕ
length [ x ] -1 = 0
length x ∷ xs -1 = 1 + length xs -1
------------------------------------------------------------------------
-- Conversion
fromVec : ∀ {n A} → Vec A (suc n) → List⁺ A
fromVec {zero} (x ∷ _) = [ x ]
fromVec {suc n} (x ∷ xs) = x ∷ fromVec xs
toVec : ∀ {A} (xs : List⁺ A) → Vec A (suc (length xs -1))
toVec [ x ] = Vec.[_] x
toVec (x ∷ xs) = x ∷ toVec xs
lift : ∀ {A B} →
(∀ {m} → Vec A (suc m) → ∃ λ n → Vec B (suc n)) →
List⁺ A → List⁺ B
lift f xs = fromVec (proj₂ (f (toVec xs)))
fromList : ∀ {A} → A → List A → List⁺ A
fromList x xs = fromVec (Vec.fromList (x ∷ xs))
toList : ∀ {A} → List⁺ A → List A
toList = Vec.toList ∘ toVec
------------------------------------------------------------------------
-- Other operations
head : ∀ {A} → List⁺ A → A
head = Vec.head ∘ toVec
tail : ∀ {A} → List⁺ A → List A
tail = Vec.toList ∘ Vec.tail ∘ toVec
map : ∀ {A B} → (A → B) → List⁺ A → List⁺ B
map f = lift (λ xs → (, Vec.map f xs))
-- Right fold. Note that s is only applied to the last element (see
-- the examples below).
foldr : {A B : Set} → (A → B → B) → (A → B) → List⁺ A → B
foldr c s [ x ] = s x
foldr c s (x ∷ xs) = c x (foldr c s xs)
-- Left fold. Note that s is only applied to the first element (see
-- the examples below).
foldl : {A B : Set} → (B → A → B) → (A → B) → List⁺ A → B
foldl c s [ x ] = s x
foldl c s (x ∷ xs) = foldl c (c (s x)) xs
-- Append (several variants).
_⁺++⁺_ : ∀ {A} → List⁺ A → List⁺ A → List⁺ A
xs ⁺++⁺ ys = foldr _∷_ (λ x → x ∷ ys) xs
_⁺++_ : ∀ {A} → List⁺ A → List A → List⁺ A
xs ⁺++ ys = foldr _∷_ (λ x → fromList x ys) xs
_++⁺_ : ∀ {A} → List A → List⁺ A → List⁺ A
xs ++⁺ ys = List.foldr _∷_ ys xs
concat : ∀ {A} → List⁺ (List⁺ A) → List⁺ A
concat [ xs ] = xs
concat (xs ∷ xss) = xs ⁺++⁺ concat xss
monad : RawMonad List⁺
monad = record
{ return = [_]
; _>>=_ = λ xs f → concat (map f xs)
}
reverse : ∀ {A} → List⁺ A → List⁺ A
reverse = lift (,_ ∘′ Vec.reverse)
-- Snoc.
_∷ʳ_ : ∀ {A} → List⁺ A → A → List⁺ A
xs ∷ʳ x = foldr _∷_ (λ y → y ∷ [ x ]) xs
------------------------------------------------------------------------
-- Examples
-- Note that these examples are simple unit tests, because the type
-- checker verifies them.
private
module Examples {A B : Set}
(_⊕_ : A → B → B)
(_⊗_ : B → A → B)
(f : A → B)
(a b c : A)
where
hd : head (a ∷ b ∷ [ c ]) ≡ a
hd = refl
tl : tail (a ∷ b ∷ [ c ]) ≡ b ∷ c ∷ []
tl = refl
mp : map f (a ∷ b ∷ [ c ]) ≡ f a ∷ f b ∷ [ f c ]
mp = refl
right : foldr _⊕_ f (a ∷ b ∷ [ c ]) ≡ a ⊕ (b ⊕ f c)
right = refl
left : foldl _⊗_ f (a ∷ b ∷ [ c ]) ≡ (f a ⊗ b) ⊗ c
left = refl
⁺app⁺ : (a ∷ b ∷ [ c ]) ⁺++⁺ (b ∷ [ c ]) ≡
a ∷ b ∷ c ∷ b ∷ [ c ]
⁺app⁺ = refl
⁺app : (a ∷ b ∷ [ c ]) ⁺++ (b ∷ c ∷ []) ≡
a ∷ b ∷ c ∷ b ∷ [ c ]
⁺app = refl
app⁺ : (a ∷ b ∷ c ∷ []) ++⁺ (b ∷ [ c ]) ≡
a ∷ b ∷ c ∷ b ∷ [ c ]
app⁺ = refl
conc : concat ((a ∷ b ∷ [ c ]) ∷ [ b ∷ [ c ] ]) ≡
a ∷ b ∷ c ∷ b ∷ [ c ]
conc = refl
rev : reverse (a ∷ b ∷ [ c ]) ≡ c ∷ b ∷ [ a ]
rev = refl
snoc : (a ∷ b ∷ [ c ]) ∷ʳ a ≡ a ∷ b ∷ c ∷ [ a ]
snoc = refl
|
{
"alphanum_fraction": 0.4320413437,
"avg_line_length": 25.4605263158,
"ext": "agda",
"hexsha": "e859c435eba5e9a493e9421c02676ad70e3b84dc",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/List/NonEmpty.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/List/NonEmpty.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/List/NonEmpty.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": 1554,
"size": 3870
}
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- The syntax of terms (Fig. 1a and 1b).
------------------------------------------------------------------------
-- The syntax of terms depends on the syntax of simple types
-- (because terms are indexed by types in order to rule out
-- ill-typed terms). But we are in the Parametric.* hierarchy, so
-- we don't know the full syntax of types, only how to lift the
-- syntax of base types into the syntax of simple types. This
-- means that we have to be parametric in the syntax of base
-- types, too.
--
-- In such parametric modules that depend on other parametric
-- modules, we first import our dependencies under a more
-- convenient name.
import Parametric.Syntax.Type as Type
-- Then we start the module proper, with parameters for all
-- extension points of our dependencies. Note that here, the
-- "Structure" naming convenion makes some sense, because we can
-- say that we need some "Type.Structure" in order to define the
-- "Term.Structure".
module Parametric.Syntax.Term
(Base : Type.Structure)
where
-- Now inside the module, we can open our dependencies with the
-- parameters for their extension points. Again, here the name
-- "Structure" makes some sense, because we can say that we want
-- to access the "Type.Structure" that is induced by Base.
open Type.Structure Base
-- At this point, we have dealt with the extension points of our
-- dependencies, and we have all the definitions about simple
-- types, contexts, variables, and variable sets in scope that we
-- provided in Parametric.Syntax.Type. Now we can proceed to
-- define our own extension point, following the pattern
-- explained in Parametric.Syntax.Type.
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Function using (_∘_)
open import Data.Unit
open import Data.Sum
-- Our extension point is a set of primitives, indexed by the
-- types of their arguments and their return type. In general, if
-- you're confused about what an extension point means, you might
-- want to open the corresponding module in the Nehemiah
-- hierarchy to see how it is implemented in the example
-- plugin. In this case, that would be the Nehemiah.Syntax.Term
-- module.
Structure : Set₁
Structure = Type → Set
module Structure (Const : Structure) where
-- Declarations of Term and Terms to enable mutual recursion.
--
-- Note that terms are indexed by contexts and types. In the
-- paper, we define the abstract syntax of terms in Fig 1a and
-- then define a type system in Fig 1b. All lemmas and theorems
-- then explicitly specify that they only hold for well-typed
-- terms. Here, we use the indices to define a type that can
-- only hold well-typed terms in the first place.
data Term
(Γ : Context) :
(τ : Type) → Set
open import Base.Data.DependentList public
-- (Terms Γ Σ) represents a list of terms with types from Σ
-- with free variables bound in Γ.
Terms : Context → Context → Set
Terms Γ = DependentList (Term Γ)
-- (Term Γ τ) represents a term of type τ
-- with free variables bound in Γ.
data Term Γ where
-- constants aka. primitives
const : ∀ {τ} →
(c : Const τ) →
Term Γ τ
var : ∀ {τ} →
(x : Var Γ τ) →
Term Γ τ
app : ∀ {σ τ}
(s : Term Γ (σ ⇒ τ)) →
(t : Term Γ σ) →
Term Γ τ
-- we use de Bruijn indices, so we don't need binding occurrences.
abs : ∀ {σ τ}
(t : Term (σ • Γ) τ) →
Term Γ (σ ⇒ τ)
-- Free variables
FV : ∀ {τ Γ} → Term Γ τ → Vars Γ
FV (const ι) = none
FV (var x) = singleton x
FV (abs t) = tail (FV t)
FV (app s t) = FV s ∪ FV t
closed? : ∀ {τ Γ} → (t : Term Γ τ) → (FV t ≡ none) ⊎ ⊤
closed? t = empty? (FV t)
-- Weakening
weaken : ∀ {Γ₁ Γ₂ τ} →
(Γ₁≼Γ₂ : Γ₁ ≼ Γ₂) →
Term Γ₁ τ →
Term Γ₂ τ
weaken Γ₁≼Γ₂ (const c) = const c
weaken Γ₁≼Γ₂ (var x) = var (weaken-var Γ₁≼Γ₂ x)
weaken Γ₁≼Γ₂ (app s t) = app (weaken Γ₁≼Γ₂ s) (weaken Γ₁≼Γ₂ t)
weaken Γ₁≼Γ₂ (abs {σ} t) = abs (weaken (keep σ • Γ₁≼Γ₂) t)
-- Specialized weakening
weaken₁ : ∀ {Γ σ τ} →
Term Γ τ → Term (σ • Γ) τ
weaken₁ t = weaken (drop _ • ≼-refl) t
weaken₂ : ∀ {Γ α β τ} →
Term Γ τ → Term (α • β • Γ) τ
weaken₂ t = weaken (drop _ • drop _ • ≼-refl) t
weaken₃ : ∀ {Γ α β γ τ} →
Term Γ τ → Term (α • β • γ • Γ) τ
weaken₃ t = weaken (drop _ • drop _ • drop _ • ≼-refl) t
-- Shorthands for nested applications
app₂ : ∀ {Γ α β γ} →
Term Γ (α ⇒ β ⇒ γ) →
Term Γ α → Term Γ β → Term Γ γ
app₂ f x = app (app f x)
app₃ : ∀ {Γ α β γ δ} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ
app₃ f x = app₂ (app f x)
app₄ : ∀ {Γ α β γ δ ε} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε
app₄ f x = app₃ (app f x)
app₅ : ∀ {Γ α β γ δ ε ζ} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε → Term Γ ζ
app₅ f x = app₄ (app f x)
app₆ : ∀ {Γ α β γ δ ε ζ η} →
Term Γ (α ⇒ β ⇒ γ ⇒ δ ⇒ ε ⇒ ζ ⇒ η) →
Term Γ α → Term Γ β → Term Γ γ → Term Γ δ →
Term Γ ε → Term Γ ζ → Term Γ η
app₆ f x = app₅ (app f x)
-- HOAS-like smart constructors for lambdas, for different arities.
-- We could also write this:
module NamespaceForBadAbs₁ where
abs₁′ :
∀ {Γ τ₁ τ} →
(Term (τ₁ • Γ) τ₁ → Term (τ₁ • Γ) τ) →
(Term Γ (τ₁ ⇒ τ))
abs₁′ {Γ} {τ₁} = λ f → abs (f (var this))
-- However, this is less general, and it is harder to reuse. In particular,
-- this cannot be used inside abs₂, ..., abs₆.
-- Now, let's write other variants with a loop!
open import Data.Vec using (_∷_; []; Vec; foldr; [_]; reverse)
open import Data.Nat
module AbsNHelpers where
open import Function
hoasArgType : ∀ {n} → Context → Type → Vec Type n → Set
hoasArgType Γ τres = foldr _ (λ a b → a → b) (Term Γ τres) ∘ Data.Vec.map (Term Γ)
-- That is,
--hoasArgType Γ τres [] = Term Γ τres
--hoasArgType Γ τres (τ₀ ∷ τs) = Term Γ τ₀ → hoasArgType Γ τres τs
hoasResType : ∀ {n} → Type → Vec Type n → Type
hoasResType τres = foldr _ _⇒_ τres
absNType : {n : ℕ} → Vec _ n → Set
absNType τs = ∀ {Γ τres} →
(f : ∀ {Γ′} → {Γ≼Γ′ : Γ ≼ Γ′} → hoasArgType Γ′ τres τs) →
Term Γ (hoasResType τres τs)
drop-≼-l : ∀ {Γ Γ′ τ} → (τ • Γ ≼ Γ′) → Γ ≼ Γ′
drop-≼-l Γ′≼Γ′₁ = ≼-trans (drop _ • ≼-refl) Γ′≼Γ′₁
absN : {n : ℕ} → (τs : Vec _ n) → absNType τs
absN [] f = f {Γ≼Γ′ = ≼-refl}
absN (τ₁ ∷ τs) f =
abs (absN τs
(λ {_} {Γ′≼Γ′₁} →
f
{Γ≼Γ′ = drop-≼-l Γ′≼Γ′₁}
(weaken Γ′≼Γ′₁ (var this))))
-- Using a similar trick, we can declare absV (where V stands for variadic),
-- which takes the N implicit type arguments individually, collects them and
-- passes them on to absN. This is inspired by the example in the Agda 2.4.0
-- release notes about support for varying arity. To collect them, we need
-- to use an accumulator argument.
absVType : ∀ n {m} (τs : Vec Type m) → Set
absVType zero τs = absNType (reverse τs)
absVType (suc n) τs = {τ₁ : Type} → absVType n (τ₁ ∷ τs)
absVAux : ∀ {m} → (τs : Vec Type m) → ∀ n → absVType n τs
absVAux τs zero = absN (reverse τs)
-- (Support for varying arity does not work here, so {τ₁} must be bound in
-- the right-hand side).
absVAux τs (suc n) {τ₁} = absVAux (τ₁ ∷ τs) n --λ {τ₁} → absVAux (τ₁ ∷ τs) n
-- "Initialize" accumulator to the empty list.
absV = absVAux []
-- We could maybe define absV directly, without going through absN, by
-- making hoasArgType and hoasResType also variadic, but I don't see a clear
-- advantage.
open AbsNHelpers using (absV) public
{-
Example types:
absV 1:
{τ₁ : Type} {Γ : Context} {τres : Type} →
({Γ′ : Context} {Γ≼Γ′ : Γ ≼ Γ′} → Term Γ′ τ₁ → Term Γ′ τres) →
Term Γ (τ₁ ⇒ τres)
absV 2:
{τ₁ : Type} {τ₁ = τ₂ : Type} {Γ : Context} {τres : Type} →
({Γ′ : Context} {Γ≼Γ′ : Γ ≼ Γ′} →
Term Γ′ τ₁ → Term Γ′ τ₂ → Term Γ′ τres) →
Term Γ (τ₁ ⇒ τ₂ ⇒ τres)
-}
|
{
"alphanum_fraction": 0.5933357655,
"avg_line_length": 33.2914979757,
"ext": "agda",
"hexsha": "8d911730945e948230127e4e5107f1f3c5f49613",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Parametric/Syntax/Term.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Parametric/Syntax/Term.agda",
"max_line_length": 86,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Parametric/Syntax/Term.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 2860,
"size": 8223
}
|
{-# OPTIONS --type-in-type --no-pattern-matching #-}
open import Spire.IDarkwingDuck.Primitive
open import Spire.IDarkwingDuck.Derived
module Spire.IDarkwingDuck.Examples where
----------------------------------------------------------------------
ℕR : Data
ℕR = Decl End End
("zero" ∷ "suc" ∷ [])
(End tt , Rec tt (End tt) , tt)
ℕ : Set
ℕ = Form ℕR
zero : ℕ
zero = inj ℕR here
suc : ℕ → ℕ
suc = inj ℕR (there here)
VecR : Data
VecR = Decl
(Arg Set λ _ → End)
(λ _ → Arg ℕ λ _ → End)
("nil" ∷ "cons" ∷ [])
(λ A →
End (zero , tt)
, IArg ℕ (λ n → Arg A λ _ → Rec (n , tt) (End (suc n , tt)))
, tt
)
Vec : (A : Set) → ℕ → Set
Vec = Form VecR
nil : {A : Set} → Vec A zero
nil = inj VecR here
cons : {A : Set} {n : ℕ} (x : A) (xs : Vec A n) → Vec A (suc n)
cons = inj VecR (there here)
----------------------------------------------------------------------
add : ℕ → ℕ → ℕ
add = elim ℕR
(λ n → ℕ → ℕ)
(λ n → n)
(λ m ih n → suc (ih n))
mult : ℕ → ℕ → ℕ
mult = elim ℕR
(λ n → ℕ → ℕ)
(λ n → zero)
(λ m ih n → add n (ih n))
append : {A : Set} {m n : ℕ} (xs : Vec A m) (ys : Vec A n) → Vec A (add m n)
append {A} {m} {n} = elim VecR
(λ m xs → (ys : Vec A n) → Vec A (add m n))
(λ ys → ys)
(λ x xs ih ys → cons x (ih ys))
m
concat : {A : Set} {m n : ℕ} (xss : Vec (Vec A m) n) → Vec A (mult n m)
concat {A} {m} {n} = elim VecR
(λ n xss → Vec A (mult n m))
nil
(λ xs xss ih → append xs ih)
n
----------------------------------------------------------------------
one : ℕ
one = suc zero
two : ℕ
two = suc one
three : ℕ
three = suc two
[1,2] : Vec ℕ two
[1,2] = cons one (cons two nil)
[3] : Vec ℕ one
[3] = cons three nil
[1,2,3] : Vec ℕ three
[1,2,3] = cons one (cons two (cons three nil))
test-append : [1,2,3] ≡ append [1,2] [3]
test-append = refl
----------------------------------------------------------------------
|
{
"alphanum_fraction": 0.450053135,
"avg_line_length": 20.0212765957,
"ext": "agda",
"hexsha": "e797ace97ad6b5646d251d4ef83cb0568a80fd7e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-08-17T21:00:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-08-17T21:00:07.000Z",
"max_forks_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "spire/spire",
"max_forks_repo_path": "formalization/agda/Spire/IDarkwingDuck/Examples.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"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": "spire/spire",
"max_issues_repo_path": "formalization/agda/Spire/IDarkwingDuck/Examples.agda",
"max_line_length": 76,
"max_stars_count": 43,
"max_stars_repo_head_hexsha": "3d67f137ee9423b7e6f8593634583998cd692353",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "spire/spire",
"max_stars_repo_path": "formalization/agda/Spire/IDarkwingDuck/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T17:10:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-28T23:25:33.000Z",
"num_tokens": 688,
"size": 1882
}
|
module 08-higherOrder where
explicitize : ∀ {A : Set} {B : A → Set} → ({{x : A}} → B x) → (x : A) → B x
explicitize f x = f {{x}}
implicitize : ∀ {A : Set} {B : A → Set} → ((x : A) → B x) → {{x : A}} → B x
implicitize f {{x}} = f x
data T : Set where
tt : T
test = explicitize (λ {{t : T}} → t)
|
{
"alphanum_fraction": 0.4817275748,
"avg_line_length": 23.1538461538,
"ext": "agda",
"hexsha": "e8092d8a71aac482a8df6d5ae4d065913474c335",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/instance-arguments/08-higherOrder.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/instance-arguments/08-higherOrder.agda",
"max_line_length": 75,
"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/instance-arguments/08-higherOrder.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": 125,
"size": 301
}
|
-- Andreas, 2018-11-23, issue #3404, regression in Agda 2.5.4
--
-- The positivity checker judged postulates in mutual blocks
-- as constants, since it found no uses of its arguments.
--
-- The natural cure is to not unleash the positivity checker
-- onto things that do not have a definition, such as postulates.
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
cong : ∀{A B : Set} (f : A → B) {x y : A} (eq : x ≡ y) → f x ≡ f y
cong f refl = refl
trans : {A : Set} {a b c : A} → a ≡ b → b ≡ c → a ≡ c
trans refl refl = refl
module UnsolvedMeta where
postulate A : Set
mutual postulate B : A → Set -- Problem WAS: B is judged constant
postulate f : (a : A) → B a
g : (a : A) → B a
g a = f _ -- WAS: yellow
-- Should solve.
-- False golfing:
module Word64 where
{-# BUILTIN WORD64 Word64 #-}
primitive primWord64ToNat : Word64 → Nat
mutual primitive primWord64FromNat : Nat → Word64
-- Before fix of #3404, positivity checker judged
-- a primitive in a mutual block as constant.
fromNatConst : ∀ x y → primWord64FromNat x ≡ primWord64FromNat y
fromNatConst x y = refl
-- Should fail with error like:
--
-- x != y of type Nat
-- when checking that the expression refl has type
-- primWord64FromNat x ≡ primWord64FromNat y
0≡1 : 0 ≡ 1
0≡1 = cong primWord64ToNat (fromNatConst 0 1)
-- Guillaume Brunerie's original example:
mutual
postulate
2^ : Nat → Nat -- If this function is deemed constant,
2^0 : 1 ≡ 2^ 0 -- then these equalities can be composed.
2^1 : 2^ 1 ≡ 2
bad : 1 ≡ 2
bad = trans 2^0 2^1
-- Should fail with error like:
--
-- 1 != 0 of type Nat
-- when checking that the expression 2^1 has type 2^ 0 ≡ 2
|
{
"alphanum_fraction": 0.6419113414,
"avg_line_length": 25.9253731343,
"ext": "agda",
"hexsha": "f5d53cd1f7804ead1afd139c19ec3abd25d07ee5",
"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": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "bennn/agda",
"max_forks_repo_path": "test/Fail/Issue3404.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"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": "bennn/agda",
"max_issues_repo_path": "test/Fail/Issue3404.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f77b563d328513138d6c88bf0a3e350a9b91f8ed",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "bennn/agda",
"max_stars_repo_path": "test/Fail/Issue3404.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 582,
"size": 1737
}
|
-- Andreas, 2014-09-02, reported by Nisse
-- {-# OPTIONS -v scope.mod.inst:30 #-}
record R : Set₁ where
field
A : Set
-- works : (A : R) → let open R A renaming (A to B) in B → B
-- works _ a = a
test : (A : R) → let open R A in A → A
test _ a = a
-- WAS:
-- Either the A introduced by the let should shadow the outer A, or an
-- ambiguity error should be raised. Current error message:
--
-- R !=< Set of type Set₁
-- when checking that the expression A has type Set
-- NOW: ambiguity error.
|
{
"alphanum_fraction": 0.6277227723,
"avg_line_length": 21.9565217391,
"ext": "agda",
"hexsha": "f4a4115185afd79c23b9a28d6420b5a50a3bb7ed",
"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/Issue1266.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/Issue1266.agda",
"max_line_length": 70,
"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/Issue1266.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": 156,
"size": 505
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Monoid.BigOp where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.SIP
open import Cubical.Data.Nat using (ℕ ; zero ; suc)
open import Cubical.Data.FinData
open import Cubical.Algebra.Monoid.Base
private
variable
ℓ ℓ' : Level
module MonoidBigOp (M' : Monoid ℓ) where
private M = ⟨ M' ⟩
open MonoidStr (snd M')
bigOp : {n : ℕ} → FinVec M n → M
bigOp = foldrFin _·_ ε
bigOpExt : ∀ {n} {V W : FinVec M n} → ((i : Fin n) → V i ≡ W i) → bigOp V ≡ bigOp W
bigOpExt h = cong bigOp (funExt h)
bigOpε : ∀ n → bigOp (replicateFinVec n ε) ≡ ε
bigOpε zero = refl
bigOpε (suc n) = cong (ε ·_) (bigOpε n) ∙ ·IdR _
bigOpLast : ∀ {n} (V : FinVec M (suc n)) → bigOp V ≡ bigOp (V ∘ weakenFin) · V (fromℕ n)
bigOpLast {n = zero} V = ·IdR _ ∙ sym (·IdL _)
bigOpLast {n = suc n} V = cong (V zero ·_) (bigOpLast (V ∘ suc)) ∙ ·Assoc _ _ _
-- requires a commutative monoid:
bigOpSplit : (∀ x y → x · y ≡ y · x)
→ {n : ℕ} → (V W : FinVec M n) → bigOp (λ i → V i · W i) ≡ bigOp V · bigOp W
bigOpSplit _ {n = zero} _ _ = sym (·IdR _)
bigOpSplit comm {n = suc n} V W =
V zero · W zero · bigOp (λ i → V (suc i) · W (suc i))
≡⟨ (λ i → V zero · W zero · bigOpSplit comm (V ∘ suc) (W ∘ suc) i) ⟩
V zero · W zero · (bigOp (V ∘ suc) · bigOp (W ∘ suc))
≡⟨ sym (·Assoc _ _ _) ⟩
V zero · (W zero · (bigOp (V ∘ suc) · bigOp (W ∘ suc)))
≡⟨ cong (V zero ·_) (·Assoc _ _ _) ⟩
V zero · ((W zero · bigOp (V ∘ suc)) · bigOp (W ∘ suc))
≡⟨ cong (λ x → V zero · (x · bigOp (W ∘ suc))) (comm _ _) ⟩
V zero · ((bigOp (V ∘ suc) · W zero) · bigOp (W ∘ suc))
≡⟨ cong (V zero ·_) (sym (·Assoc _ _ _)) ⟩
V zero · (bigOp (V ∘ suc) · (W zero · bigOp (W ∘ suc)))
≡⟨ ·Assoc _ _ _ ⟩
V zero · bigOp (V ∘ suc) · (W zero · bigOp (W ∘ suc)) ∎
bigOpSplit++ : (∀ x y → x · y ≡ y · x)
→ {n m : ℕ} → (V : FinVec M n) → (W : FinVec M m)
→ bigOp (V ++Fin W) ≡ bigOp V · bigOp W
bigOpSplit++ comm {n = zero} V W = sym (·IdL _)
bigOpSplit++ comm {n = suc n} V W = cong (V zero ·_) (bigOpSplit++ comm (V ∘ suc) W) ∙ ·Assoc _ _ _
|
{
"alphanum_fraction": 0.5484903934,
"avg_line_length": 35.8360655738,
"ext": "agda",
"hexsha": "c63b8ce67ec0c5bef0779dc5f7c82812670eed6f",
"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/Monoid/BigOp.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/Monoid/BigOp.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/Monoid/BigOp.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 908,
"size": 2186
}
|
module _ {A : Set} (P : A → Set) where
postulate
bla : {x : A} {{_ : P x}} → Set → Set
test : {x : A} {{_ : P x}} → Set → Set
test B = bla B
|
{
"alphanum_fraction": 0.4415584416,
"avg_line_length": 19.25,
"ext": "agda",
"hexsha": "f710b93e1ddf072164525e42c7e1d7b0476f6a4e",
"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/Issue1452.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/Issue1452.agda",
"max_line_length": 41,
"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/Issue1452.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 66,
"size": 154
}
|
module Issue4408 where
comp :
(A : Set)
(B : A → Set)
(C : (x : A) → B x → Set) →
((x : A) (y : B x) → C x y) →
(g : (x : A) → B x) →
((x : A) → C x (g x))
comp _ _ _ f g x = f x (g x)
data Unit : Set where
unit : Unit
P : Unit → Set
P unit = Unit
Q : Unit → Set → Set
Q unit = λ _ → Unit
f : (x : Unit) → P x → P x
f unit x = x
g :
(A : Set) →
((x : Unit) → Q x A → P x) →
((x : Unit) → Q x A → P x)
g A h x = comp _ _ _ (λ _ → f _) (h _)
|
{
"alphanum_fraction": 0.4206008584,
"avg_line_length": 16.0689655172,
"ext": "agda",
"hexsha": "db31fd979ebe0e15e05f8dca5014f3e74a10d52d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue4408.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/Issue4408.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/Succeed/Issue4408.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": 217,
"size": 466
}
|
import Lvl
open import Type
module Type.Functions {ℓₗ : Lvl.Level}{ℓₒ₁}{ℓₒ₂} {X : Type{ℓₒ₁}} {Y : Type{ℓₒ₂}} where
open import Function.Domains
open import Type.Properties.Empty
open import Type.Properties.Singleton
record Bijective (f : X → Y) : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂} where
constructor intro
field
proof : ∀{y} → IsUnit{ℓₗ Lvl.⊔ ℓₒ₁} (Unapply {ℓₗ}{X = X}{Y = Y} f(y))
record Injective (f : X → Y) : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂} where
constructor intro
field
proof : ∀{y} → MereProposition{ℓₗ Lvl.⊔ ℓₒ₁} (Unapply {ℓₗ}{X = X}{Y = Y} f(y))
record Surjective (f : X → Y) : Type{ℓₗ Lvl.⊔ ℓₒ₁ Lvl.⊔ ℓₒ₂} where
constructor intro
field
proof : ∀{y} → ◊(Unapply {ℓₗ}{X = X}{Y = Y} f(y))
|
{
"alphanum_fraction": 0.6291666667,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "b4f95170e416d4184c813dc2dbfb96d42f343efe",
"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": "old/Type/Functions.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": "old/Type/Functions.agda",
"max_line_length": 86,
"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": "old/Type/Functions.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": 350,
"size": 720
}
|
------------------------------------------------------------------------
-- Parallel substitutions (defined using an inductive family)
------------------------------------------------------------------------
open import Data.Universe.Indexed
module deBruijn.Substitution.Data.Basics
{i u e} {Uni : IndexedUniverse i u e} where
import deBruijn.Context; open deBruijn.Context Uni
open import Function using (id; _∘_; _$_)
open import Level using (_⊔_)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
private
module Dummy₁ {t} (T : Term-like t) where
open Term-like T
infixl 5 _▻_
-- Substitutions, represented as sequences of terms.
data Sub : ∀ {Γ Δ} → Γ ⇨̂ Δ → Set (i ⊔ u ⊔ e ⊔ t) where
ε : ∀ {Δ} → Sub ε̂[ Δ ]
_▻_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ}
(ρ : Sub ρ̂) (t : Δ ⊢ σ /̂ ρ̂) → Sub (ρ̂ ▻̂[ σ ] ⟦ t ⟧)
-- A sequence of matching substitutions. (The reflexive transitive
-- closure of Sub.)
data Subs {Γ} : ∀ {Δ} → Γ ⇨̂ Δ → Set (i ⊔ u ⊔ e ⊔ t) where
ε : Subs îd[ Γ ]
_▻_ : ∀ {Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε}
(ρs : Subs ρ̂₁) (ρ : Sub ρ̂₂) → Subs (ρ̂₁ ∘̂ ρ̂₂)
open Dummy₁ public
-- Originally these substitutions were defined without the context
-- morphism index, but this led to the need to prove lots of lemmas
-- which hold by definition in the current setting. As an example the
-- map function (in deBruijn.Substitution.Data.Map) is currently
-- defined as follows:
--
-- -- Map.
--
-- map : ∀ {Γ Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →
-- [ T₁ ⟶ T₂ ] ρ̂₂ → Sub T₁ ρ̂₁ → Sub T₂ (ρ̂₁ ∘̂ ρ̂₂)
-- map f ε = ε
-- map {ρ̂₂ = ρ̂₂} f (ρ₁ ▻ t) =
-- P.subst (λ v → Sub T₂ (⟦ ρ₁ ⟧⇨ ∘̂ ρ̂₂ ▻̂ v))
-- (≅-Value-⇒-≡ $ P.sym $ corresponds f t)
-- (map f ρ₁ ▻ f · t)
--
-- Previously it was defined roughly as follows (the code below is
-- untested and has been adapted to the current version of the
-- library, as it was at the time of writing, with some imagined
-- changes):
--
-- mutual
--
-- -- Map.
--
-- map : ∀ {Γ Δ Ε} {ρ̂₂ : Δ ⇨̂ Ε} →
-- [ T₁ ⟶ T₂ ] ρ̂₂ → (ρ₁ : Γ ⇨₁ Δ) → Γ ⇨₂ Ε
-- map f ε = ε
-- map f (_▻_ {σ = σ} ρ t) =
-- map f ρ ▻
-- P.subst (λ ρ̂ → _ ⊢₂ σ /̂ ρ̂)
-- (≅-⇨̂-⇒-≡ $ P.sym $ map-lemma f ρ)
-- (f · t)
--
-- abstract
--
-- map-lemma :
-- ∀ {Γ Δ Ε} {ρ̂₂ : Δ ⇨̂ Ε} →
-- (f : [ T₁ ⟶ T₂ ] ρ̂₂) (ρ₁ : Γ ⇨₁ Δ) →
-- ⟦ map f ρ₁ ⟧₂⇨ ≅-⇨̂ ⟦ ρ₁ ⟧₁⇨ ∘̂ ρ₂
-- map-lemma f ε = P.refl
-- map-lemma {ρ₂ = ρ₂} f (_▻_ {σ = σ} ρ t) =
-- ▻̂-cong P.refl (map-lemma f ρ) (begin
-- [ ⟦ P.subst (λ ρ̂ → _ ⊢₂ σ /̂ ρ̂)
-- (≅-⇨̂-⇒-≡ $ P.sym (map-lemma f ρ))
-- (f · t) ⟧₂ ] ≡⟨ Term-like.⟦⟧-cong T₂
-- (Term-like.drop-subst-⊢ T₂
-- (λ ρ̂ → σ /̂ ρ̂)
-- (≅-⇨̂-⇒-≡ $ P.sym (map-lemma f ρ))) ⟩
-- [ ⟦ f · t ⟧₂ ] ≡⟨ P.sym $ corresponds f t ⟩
-- [ ⟦ t ⟧₁ /̂Val ρ₂ ] ∎)
private
module Dummy₂ {t} {T : Term-like t} where
open Term-like T
-- Some variants.
ε⇨[_] : ∀ Δ → Sub T ε̂[ Δ ]
ε⇨[ _ ] = ε
infixl 5 _▻⇨[_]_
_▻⇨[_]_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} →
Sub T ρ̂ → ∀ σ (t : Δ ⊢ σ /̂ ρ̂) → Sub T (ρ̂ ▻̂[ σ ] ⟦ t ⟧)
ρ ▻⇨[ _ ] t = ρ ▻ t
ε⇨⋆[_] : ∀ Γ → Subs T îd[ Γ ]
ε⇨⋆[ _ ] = ε
-- Equality of substitutions.
record [⇨] : Set (i ⊔ u ⊔ e ⊔ t) where
constructor [_]
field
{Γ Δ} : Ctxt
{ρ̂} : Γ ⇨̂ Δ
ρ : Sub T ρ̂
infix 4 _≅-⇨_
_≅-⇨_ : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} (ρ₁ : Sub T ρ̂₁)
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} (ρ₂ : Sub T ρ̂₂) → Set _
ρ₁ ≅-⇨ ρ₂ = _≡_ {A = [⇨]} [ ρ₁ ] [ ρ₂ ]
≅-⇨-⇒-≡ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} {ρ₁ ρ₂ : Sub T ρ̂} →
ρ₁ ≅-⇨ ρ₂ → ρ₁ ≡ ρ₂
≅-⇨-⇒-≡ P.refl = P.refl
-- Certain uses of substitutivity can be removed.
drop-subst-Sub :
∀ {a} {A : Set a} {x₁ x₂ : A} {Γ Δ}
(f : A → Γ ⇨̂ Δ) {ρ} (eq : x₁ ≡ x₂) →
P.subst (λ x → Sub T (f x)) eq ρ ≅-⇨ ρ
drop-subst-Sub f P.refl = P.refl
-- Equality of sequences of substitutions.
record [⇨⋆] : Set (i ⊔ u ⊔ e ⊔ t) where
constructor [_]
field
{Γ Δ} : Ctxt
{ρ̂} : Γ ⇨̂ Δ
ρs : Subs T ρ̂
infix 4 _≅-⇨⋆_
_≅-⇨⋆_ : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} (ρs₁ : Subs T ρ̂₁)
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} (ρs₂ : Subs T ρ̂₂) → Set _
ρs₁ ≅-⇨⋆ ρs₂ = _≡_ {A = [⇨⋆]} [ ρs₁ ] [ ρs₂ ]
≅-⇨⋆-⇒-≡ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} {ρs₁ ρs₂ : Subs T ρ̂} →
ρs₁ ≅-⇨⋆ ρs₂ → ρs₁ ≡ ρs₂
≅-⇨⋆-⇒-≡ P.refl = P.refl
-- Interpretation of substitutions: context morphisms.
⟦_⟧⇨ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → Γ ⇨̂ Δ
⟦_⟧⇨ {ρ̂ = ρ̂} _ = ρ̂
⟦_⟧⇨⋆ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → Γ ⇨̂ Δ
⟦_⟧⇨⋆ {ρ̂ = ρ̂} _ = ρ̂
-- Application of substitutions to types.
infixl 8 _/I_ _/_ _/⋆_
_/I_ : ∀ {Γ Δ i} {ρ̂ : Γ ⇨̂ Δ} → IType Γ i → Sub T ρ̂ → IType Δ i
σ /I ρ = σ /̂I ⟦ ρ ⟧⇨
_/_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Type Γ → Sub T ρ̂ → Type Δ
σ / ρ = σ /̂ ⟦ ρ ⟧⇨
_/⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Type Γ → Subs T ρ̂ → Type Δ
σ /⋆ ρs = σ /̂ ⟦ ρs ⟧⇨⋆
-- Application of substitutions to values.
infixl 8 _/Val_
_/Val_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} →
Value Γ σ → Sub T ρ̂ → Value Δ (σ /̂ ρ̂)
v /Val ρ = v /̂Val ⟦ ρ ⟧⇨
-- Application of substitutions to context extensions.
infixl 8 _/⁺_ _/⁺⋆_ _/₊_ _/₊⋆_
_/⁺_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt⁺ Γ → Sub T ρ̂ → Ctxt⁺ Δ
Γ⁺ /⁺ ρ = Γ⁺ /̂⁺ ⟦ ρ ⟧⇨
_/⁺⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt⁺ Γ → Subs T ρ̂ → Ctxt⁺ Δ
Γ⁺ /⁺⋆ ρs = Γ⁺ /̂⁺ ⟦ ρs ⟧⇨⋆
_/₊_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt₊ Γ → Sub T ρ̂ → Ctxt₊ Δ
Γ₊ /₊ ρ = Γ₊ /̂₊ ⟦ ρ ⟧⇨
_/₊⋆_ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Ctxt₊ Γ → Subs T ρ̂ → Ctxt₊ Δ
Γ₊ /₊⋆ ρs = Γ₊ /̂₊ ⟦ ρs ⟧⇨⋆
-- Application of substitutions to variables.
infixl 8 _/∋_ _/∋-lemma_
_/∋_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} → Γ ∋ σ → (ρ : Sub T ρ̂) → Δ ⊢ σ / ρ
zero /∋ (ρ ▻ y) = y
suc x /∋ (ρ ▻ y) = x /∋ ρ
abstract
_/∋-lemma_ : ∀ {Γ Δ σ} {ρ̂ : Γ ⇨̂ Δ} (x : Γ ∋ σ) (ρ : Sub T ρ̂) →
x /̂∋ ⟦ ρ ⟧⇨ ≅-Value ⟦ x /∋ ρ ⟧
zero /∋-lemma (ρ ▻ y) = P.refl
suc x /∋-lemma (ρ ▻ y) = x /∋-lemma ρ
app∋ : ∀ {Γ Δ} {ρ̂ : Γ ⇨̂ Δ} → Sub T ρ̂ → [ Var ⟶ T ] ρ̂
app∋ ρ = record
{ function = λ _ x → x /∋ ρ
; corresponds = λ _ x → x /∋-lemma ρ
}
-- The tail of a nonempty substitution.
tail : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} → Sub T ρ̂ → Sub T (t̂ail ρ̂)
tail (ρ ▻ t) = ρ
-- The head of a nonempty substitution.
head : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) → Δ ⊢ σ / tail ρ
head (ρ ▻ t) = t
head-lemma : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) →
ĥead ⟦ ρ ⟧⇨ ≅-Value ⟦ head ρ ⟧
head-lemma (ρ ▻ t) = P.refl
-- Fold for sequences of substitutions.
fold : ∀ {f} (F : ∀ {Γ Δ} → Γ ⇨̂ Δ → Set f) {Γ} →
F (îd {Γ = Γ}) →
(∀ {Δ Ε} {ρ̂₁ : Γ ⇨̂ Δ} {ρ̂₂ : Δ ⇨̂ Ε} →
F ρ̂₁ → Sub T ρ̂₂ → F (ρ̂₁ ∘̂ ρ̂₂)) →
∀ {Δ} {ρ̂ : Γ ⇨̂ Δ} → Subs T ρ̂ → F ρ̂
fold F nil cons ε = nil
fold F nil cons (ρs ▻ ρ) = cons (fold F nil cons ρs) ρ
-- Some congruence lemmas.
ε⇨-cong : ∀ {Δ₁ Δ₂} → Δ₁ ≅-Ctxt Δ₂ → ε⇨[ Δ₁ ] ≅-⇨ ε⇨[ Δ₂ ]
ε⇨-cong P.refl = P.refl
▻⇨-cong :
∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁} {t₁ : Δ₁ ⊢ σ₁ / ρ₁}
{Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} {t₂ : Δ₂ ⊢ σ₂ / ρ₂} →
σ₁ ≅-Type σ₂ → ρ₁ ≅-⇨ ρ₂ → t₁ ≅-⊢ t₂ →
ρ₁ ▻⇨[ σ₁ ] t₁ ≅-⇨ ρ₂ ▻⇨[ σ₂ ] t₂
▻⇨-cong P.refl P.refl P.refl = P.refl
ε⇨⋆-cong : ∀ {Γ₁ Γ₂} → Γ₁ ≡ Γ₂ → ε⇨⋆[ Γ₁ ] ≅-⇨⋆ ε⇨⋆[ Γ₂ ]
ε⇨⋆-cong P.refl = P.refl
▻⇨⋆-cong :
∀ {Γ₁ Δ₁ Ε₁} {ρ̂₁₁ : Γ₁ ⇨̂ Δ₁} {ρ̂₂₁ : Δ₁ ⇨̂ Ε₁}
{ρs₁ : Subs T ρ̂₁₁} {ρ₁ : Sub T ρ̂₂₁}
{Γ₂ Δ₂ Ε₂} {ρ̂₁₂ : Γ₂ ⇨̂ Δ₂} {ρ̂₂₂ : Δ₂ ⇨̂ Ε₂}
{ρs₂ : Subs T ρ̂₁₂} {ρ₂ : Sub T ρ̂₂₂} →
ρs₁ ≅-⇨⋆ ρs₂ → ρ₁ ≅-⇨ ρ₂ → ρs₁ ▻ ρ₁ ≅-⇨⋆ ρs₂ ▻ ρ₂
▻⇨⋆-cong P.refl P.refl = P.refl
⟦⟧⇨-cong : ∀ {Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
ρ₁ ≅-⇨ ρ₂ → ⟦ ρ₁ ⟧⇨ ≅-⇨̂ ⟦ ρ₂ ⟧⇨
⟦⟧⇨-cong P.refl = P.refl
/I-cong :
∀ {i}
{Γ₁ Δ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {σ₁ : IType Γ₁ i} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {σ₂ : IType Γ₂ i} {ρ₂ : Sub T ρ̂₂} →
σ₁ ≅-IType σ₂ → ρ₁ ≅-⇨ ρ₂ → σ₁ /I ρ₁ ≅-IType σ₂ /I ρ₂
/I-cong P.refl P.refl = P.refl
/-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
σ₁ ≅-Type σ₂ → ρ₁ ≅-⇨ ρ₂ → σ₁ / ρ₁ ≅-Type σ₂ / ρ₂
/-cong P.refl P.refl = P.refl
/⁺-cong : ∀ {Γ₁ Δ₁ Γ⁺₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ Γ⁺₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρ₁ ≅-⇨ ρ₂ → Γ⁺₁ /⁺ ρ₁ ≅-Ctxt⁺ Γ⁺₂ /⁺ ρ₂
/⁺-cong P.refl P.refl = P.refl
/⁺⋆-cong : ∀ {Γ₁ Δ₁ Γ⁺₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁}
{Γ₂ Δ₂ Γ⁺₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} →
Γ⁺₁ ≅-Ctxt⁺ Γ⁺₂ → ρs₁ ≅-⇨⋆ ρs₂ →
Γ⁺₁ /⁺⋆ ρs₁ ≅-Ctxt⁺ Γ⁺₂ /⁺⋆ ρs₂
/⁺⋆-cong P.refl P.refl = P.refl
/₊-cong : ∀ {Γ₁ Δ₁ Γ₊₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ Γ₊₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρ₁ ≅-⇨ ρ₂ → Γ₊₁ /₊ ρ₁ ≅-Ctxt₊ Γ₊₂ /₊ ρ₂
/₊-cong P.refl P.refl = P.refl
/₊⋆-cong : ∀ {Γ₁ Δ₁ Γ₊₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρs₁ : Subs T ρ̂₁}
{Γ₂ Δ₂ Γ₊₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρs₂ : Subs T ρ̂₂} →
Γ₊₁ ≅-Ctxt₊ Γ₊₂ → ρs₁ ≅-⇨⋆ ρs₂ →
Γ₊₁ /₊⋆ ρs₁ ≅-Ctxt₊ Γ₊₂ /₊⋆ ρs₂
/₊⋆-cong P.refl P.refl = P.refl
/∋-cong : ∀ {Γ₁ Δ₁ σ₁} {x₁ : Γ₁ ∋ σ₁} {ρ̂₁ : Γ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ σ₂} {x₂ : Γ₂ ∋ σ₂} {ρ̂₂ : Γ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
x₁ ≅-∋ x₂ → ρ₁ ≅-⇨ ρ₂ → x₁ /∋ ρ₁ ≅-⊢ x₂ /∋ ρ₂
/∋-cong P.refl P.refl = P.refl
tail-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ▻ σ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ▻ σ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
ρ₁ ≅-⇨ ρ₂ → tail ρ₁ ≅-⇨ tail ρ₂
tail-cong P.refl = P.refl
head-cong : ∀ {Γ₁ Δ₁ σ₁} {ρ̂₁ : Γ₁ ▻ σ₁ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Γ₂ Δ₂ σ₂} {ρ̂₂ : Γ₂ ▻ σ₂ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
ρ₁ ≅-⇨ ρ₂ → head ρ₁ ≅-⊢ head ρ₂
head-cong P.refl = P.refl
abstract
-- Some eta-laws.
ηε : ∀ {Δ} {ρ̂ : ε ⇨̂ Δ} (ρ : Sub T ρ̂) → ρ ≅-⇨ ε⇨[ Δ ]
ηε ε = P.refl
η▻ : ∀ {Γ Δ σ} {ρ̂ : Γ ▻ σ ⇨̂ Δ} (ρ : Sub T ρ̂) →
ρ ≅-⇨ tail ρ ▻⇨[ σ ] head ρ
η▻ (ρ ▻ t) = P.refl
-- Two substitutions are equal if their indices are equal and
-- their projections are pairwise equal.
extensionality :
∀ {Γ Δ₁} {ρ̂₁ : Γ ⇨̂ Δ₁} {ρ₁ : Sub T ρ̂₁}
{Δ₂} {ρ̂₂ : Γ ⇨̂ Δ₂} {ρ₂ : Sub T ρ̂₂} →
Δ₁ ≅-Ctxt Δ₂ → (∀ {σ} (x : Γ ∋ σ) → x /∋ ρ₁ ≅-⊢ x /∋ ρ₂) →
ρ₁ ≅-⇨ ρ₂
extensionality {ρ₁ = ε} {ρ₂ = ε} Δ₁≅Δ₂ hyp = ε⇨-cong Δ₁≅Δ₂
extensionality {ρ₁ = ρ₁ ▻ t₁} {ρ₂ = ρ₂ ▻ t₂} Δ₁≅Δ₂ hyp =
▻⇨-cong P.refl
(extensionality Δ₁≅Δ₂ (hyp ∘ suc))
(hyp zero)
open Dummy₂ public
|
{
"alphanum_fraction": 0.4056174766,
"avg_line_length": 32.1346704871,
"ext": "agda",
"hexsha": "915f0c6ee080f29bf90306215cd27a3290327b53",
"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": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/dependently-typed-syntax",
"max_forks_repo_path": "deBruijn/Substitution/Data/Basics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"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/dependently-typed-syntax",
"max_issues_repo_path": "deBruijn/Substitution/Data/Basics.agda",
"max_line_length": 107,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "498f8aefc570f7815fd1d6616508eeb92c52abce",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/dependently-typed-syntax",
"max_stars_repo_path": "deBruijn/Substitution/Data/Basics.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-08T22:51:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T12:14:44.000Z",
"num_tokens": 6405,
"size": 11215
}
|
-- Andreas, 2019-08-19, issue #4007 reported by nad
-- The scope checker was not run in the TCEnv of the interaction meta.
-- Thus, the extended lambda was not inheriting the IsAbstract from
-- the AbstractMode of the meta, leading to checking the
-- extended lambda in the wrong ConcreteMode.
-- {-# OPTIONS -v interaction.give:20 #-}
-- {-# OPTIONS -v scope.extendedLambda:10 #-}
-- {-# OPTIONS -v tc.term.exlam:20 #-}
-- -- {-# OPTIONS -v tc.decl:10 #-}
-- {-# OPTIONS -v tc.interaction:20 #-}
-- {-# OPTIONS -v tc.decl.abstract:25 #-}
-- {-# OPTIONS -v tc.meta.check:20 #-}
-- {-# OPTIONS -v tc.meta.new:50 #-}
abstract
data D : Set where
c : D
works : D → D
works = λ { c → c }
test : D → D
test = {!λ { c → c }!} -- give
-- Giving should succeed.
|
{
"alphanum_fraction": 0.6162790698,
"avg_line_length": 26.6896551724,
"ext": "agda",
"hexsha": "9b6e4f3a19a1074b7b9135e230a75d9d799d59cc",
"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/Issue4007.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/Issue4007.agda",
"max_line_length": 70,
"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/Issue4007.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": 229,
"size": 774
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Lemmas
open import Groups.Definition
open import Rings.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Orders.Total.Definition
open import Rings.Lemmas
open import Setoids.Setoids
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Rings.IntegralDomains.Definition
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Fields.Fields
open import Fields.Orders.Total.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
module Fields.Orders.Lemmas {m n o : _} {A : Set m} {S : Setoid {m} {n} A} {_+_ : A → A → A} {_*_ : A → A → A} {_<_ : Rel {_} {o} A} {R : Ring S _+_ _*_} {pOrder : SetoidPartialOrder S _<_} {F : Field R} {pRing : PartiallyOrderedRing R pOrder} (oF : TotallyOrderedField F pRing) where
abstract
open import Rings.InitialRing R
open Ring R
open PartiallyOrderedRing pRing
open Group additiveGroup
open TotallyOrderedRing (TotallyOrderedField.oRing oF)
open SetoidTotalOrder total
open import Rings.Orders.Partial.Lemmas pRing
open import Rings.Orders.Total.Lemmas (TotallyOrderedField.oRing oF)
open import Fields.Lemmas F
open Setoid S
open SetoidPartialOrder pOrder
open Equivalence eq
open Field F
clearDenominatorHalf : (x y 1/2 : A) → (1/2 + 1/2 ∼ 1R) → x < (y * 1/2) → (x + x) < y
clearDenominatorHalf x y 1/2 pr1/2 x<1/2y = <WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq *DistributesOver+) (Equivalence.transitive eq *Commutative (*WellDefined pr1/2 (Equivalence.reflexive eq)))) identIsIdent) (ringAddInequalities x<1/2y x<1/2y)
clearDenominatorHalf' : (x y 1/2 : A) → (1/2 + 1/2 ∼ 1R) → (x * 1/2) < y → x < (y + y)
clearDenominatorHalf' x y 1/2 pr1/2 1/2x<y = <WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq *DistributesOver+) (Equivalence.transitive eq (Equivalence.transitive eq *Commutative (*WellDefined pr1/2 (Equivalence.reflexive eq))) identIsIdent)) (Equivalence.reflexive eq) (ringAddInequalities 1/2x<y 1/2x<y)
halveInequality : (x y 1/2 : A) → (1/2 + 1/2 ∼ 1R) → (x + x) < y → x < (y * 1/2)
halveInequality x y 1/2 pr1/2 2x<y with totality 0R 1R
... | inl (inl 0<1') = <WellDefined (halfHalves 1/2 pr1/2) (Equivalence.reflexive eq) (ringCanMultiplyByPositive {_} {_} {1/2} (halvePositive 1/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq pr1/2) (0<1 λ bad → irreflexive {0R} (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq bad) 0<1')))) 2x<y)
... | inl (inr 1<0) = <WellDefined (halfHalves 1/2 pr1/2) (Equivalence.reflexive eq) (ringCanMultiplyByPositive {_} {_} {1/2} (halvePositive 1/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq pr1/2) (0<1 λ bad → irreflexive {0R} (<WellDefined (Equivalence.symmetric eq bad) (Equivalence.reflexive eq) 1<0)))) 2x<y)
... | inr 0=1 = exFalso (irreflexive {0R} (<WellDefined (oneZeroImpliesAllZero R 0=1) (oneZeroImpliesAllZero R 0=1) 2x<y))
halveInequality' : (x y 1/2 : A) → (1/2 + 1/2 ∼ 1R) → x < (y + y) → (x * 1/2) < y
halveInequality' x y 1/2 pr1/2 x<2y with halveInequality (inverse y) (inverse x) 1/2 pr1/2 (<WellDefined (invContravariant additiveGroup) (Equivalence.reflexive eq) (ringSwapNegatives' x<2y))
... | bl = ringSwapNegatives (<WellDefined (Equivalence.reflexive eq) (ringMinusExtracts' R) bl)
dense : (charNot2 : ((1R + 1R) ∼ 0R) → False) {x y : A} → (x < y) → Sg A (λ i → (x < i) && (i < y))
dense charNot2 {x} {y} x<y with halve charNot2 1R
dense charNot2 {x} {y} x<y | 1/2 , pr1/2 = ((x + y) * 1/2) , (halveInequality x (x + y) 1/2 pr1/2 (<WellDefined (Equivalence.reflexive eq) groupIsAbelian (orderRespectsAddition x<y x)) ,, halveInequality' (x + y) y 1/2 pr1/2 (orderRespectsAddition x<y y))
halfLess : (e/2 e : A) → (0<e : 0G < e) → (pr : e/2 + e/2 ∼ e) → e/2 < e
halfLess e/2 e 0<e pr with halvePositive e/2 (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq pr) 0<e)
... | 0<e/2 = <WellDefined identLeft pr (orderRespectsAddition 0<e/2 e/2)
inversePositiveIsPositive : {a b : A} → (a * b) ∼ 1R → 0R < b → 0R < a
inversePositiveIsPositive {a} {b} ab=1 0<b with totality 0R a
inversePositiveIsPositive {a} {b} ab=1 0<b | inl (inl 0<a) = 0<a
inversePositiveIsPositive {a} {b} ab=1 0<b | inl (inr a<0) with <WellDefined *Commutative (Equivalence.reflexive eq) (posTimesNeg _ _ 0<b a<0)
... | ab<0 = exFalso (1<0False (<WellDefined ab=1 (Equivalence.reflexive eq) ab<0))
inversePositiveIsPositive {a} {b} ab=1 0<b | inr 0=a = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (oneZeroImpliesAllZero R 0=1) 0<b))
where
0=1 : 0R ∼ 1R
0=1 = Equivalence.transitive eq (Equivalence.symmetric eq (Equivalence.transitive eq (*WellDefined (Equivalence.symmetric eq 0=a) (Equivalence.reflexive eq)) (Equivalence.transitive eq *Commutative timesZero))) ab=1
halvesEqual : ((1R + 1R ∼ 0R) → False) → (1/2 1/2' : A) → (1/2 + 1/2) ∼ 1R → (1/2' + 1/2') ∼ 1R → 1/2 ∼ 1/2'
halvesEqual charNot2 1/2 1/2' pr1 pr2 = Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.symmetric eq identIsIdent) (Equivalence.transitive eq *Commutative (*WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.symmetric eq p1) *Commutative)))) (Equivalence.transitive eq r (Equivalence.transitive eq (Equivalence.transitive eq (*WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq *Commutative p1)) *Commutative) (identIsIdent)))
where
p : 1/2 * (1R + 1R) ∼ 1/2' * (1R + 1R)
p = Equivalence.transitive eq *DistributesOver+ (Equivalence.transitive eq (Equivalence.transitive eq (Equivalence.transitive eq (+WellDefined (Equivalence.transitive eq *Commutative identIsIdent) (Equivalence.transitive eq *Commutative identIsIdent)) pr1) (Equivalence.transitive eq (Equivalence.symmetric eq pr2) (+WellDefined (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative identIsIdent)) (Equivalence.symmetric eq (Equivalence.transitive eq *Commutative identIsIdent))))) (Equivalence.symmetric eq *DistributesOver+))
x : A
x with Field.allInvertible F (1R + 1R) charNot2
... | y , _ = y
p1 : (x * (1R + 1R)) ∼ 1R
p1 with Field.allInvertible F (1R + 1R) charNot2
... | _ , pr = pr
q : ((1/2 * (1R + 1R)) * x) ∼ ((1/2' * (1R + 1R)) * x)
q = *WellDefined p (Equivalence.reflexive eq)
r : (1/2 * ((1R + 1R) * x)) ∼ (1/2' * ((1R + 1R) * x))
r = Equivalence.transitive eq *Associative (Equivalence.transitive eq q (Equivalence.symmetric eq *Associative))
private
orderedFieldIntDom : {a b : A} → (a * b ∼ 0R) → (a ∼ 0R) || (b ∼ 0R)
orderedFieldIntDom {a} {b} ab=0 with totality 0R a
... | inl (inl x) = inr (Equivalence.transitive eq (Equivalence.transitive eq (symmetric identIsIdent) (*WellDefined q reflexive)) p')
where
a!=0 : (a ∼ Group.0G additiveGroup) → False
a!=0 pr = SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (symmetric pr) reflexive x)
invA : A
invA = underlying (Field.allInvertible F a a!=0)
q : 1R ∼ (invA * a)
q with Field.allInvertible F a a!=0
... | invA , pr = symmetric pr
p : invA * (a * b) ∼ invA * Group.0G additiveGroup
p = *WellDefined reflexive ab=0
p' : (invA * a) * b ∼ Group.0G additiveGroup
p' = Equivalence.transitive eq (symmetric *Associative) (Equivalence.transitive eq p (Ring.timesZero R))
orderedFieldIntDom {a} {b} ab=0 | inl (inr x) = inr (Equivalence.transitive eq (Equivalence.transitive eq (symmetric identIsIdent) (*WellDefined q reflexive)) p')
where
a!=0 : (a ∼ Group.0G additiveGroup) → False
a!=0 pr = SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder reflexive (symmetric pr) x)
invA : A
invA = underlying (Field.allInvertible F a a!=0)
q : 1R ∼ (invA * a)
q with Field.allInvertible F a a!=0
... | invA , pr = symmetric pr
p : invA * (a * b) ∼ invA * Group.0G additiveGroup
p = *WellDefined reflexive ab=0
p' : (invA * a) * b ∼ Group.0G additiveGroup
p' = Equivalence.transitive eq (symmetric *Associative) (Equivalence.transitive eq p (Ring.timesZero R))
orderedFieldIntDom {a} {b} ab=0 | inr x = inl (Equivalence.symmetric (Setoid.eq S) x)
orderedFieldIsIntDom : IntegralDomain R
IntegralDomain.intDom orderedFieldIsIntDom = decidedIntDom R orderedFieldIntDom
IntegralDomain.nontrivial orderedFieldIsIntDom pr = Field.nontrivial F (Equivalence.symmetric (Setoid.eq S) pr)
charZero : (n : ℕ) → (0R ∼ (fromN (succ n))) → False
charZero n 0=sn = irreflexive (<WellDefined 0=sn reflexive (fromNPreservesOrder (0<1 (Field.nontrivial F)) (succIsPositive n)))
charZero' : (n : ℕ) → ((fromN (succ n)) ∼ 0R) → False
charZero' n pr = charZero n (symmetric pr)
|
{
"alphanum_fraction": 0.6848005275,
"avg_line_length": 71.0859375,
"ext": "agda",
"hexsha": "b04d4450b31c1d273a6fac06cc4e78bea568b378",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/Orders/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/Orders/Lemmas.agda",
"max_line_length": 545,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/Orders/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 3222,
"size": 9099
}
|
{-# OPTIONS --allow-unsolved-metas #-}
open import Tutorials.Monday-Complete
open import Tutorials.Tuesday
open List using (List; []; _∷_; _++_)
open Vec using (Vec; []; _∷_; _!_)
open Fin using (Fin; zero; suc)
module Tutorials.Wednesday where
-----------
-- Interfaces, isomorphisms
-----------
module Isomorphism where
-- Why can we import _,_ from both modules without resulting in a nameclash?
open Simple using (_⊎_; _×_; _,_; inl; inr)
open Product using (Σ-syntax; Σ-⊎; Σ-×; Π-×; Π-→; _,_)
infix 2 _≅_
record _≅_ (A B : Set) : Set where
constructor Mk≅
field
to : A → B
from : B → A
from∘to : ∀ a → from (to a) ≡ a
to∘from : ∀ b → to (from b) ≡ b
open _≅_
-- We can use copattern matching to construct a record by defining how to construct each of its fields
Σ-⊎-≅ : Σ-⊎ A B ≅ A ⊎ B
Σ-⊎-≅ = {!!}
Σ-×-≅ : Σ-× A B ≅ A × B
Σ-×-≅ = {!!}
Π-→-≅ : Π-→ A B ≅ (A → B)
to Π-→-≅ = {!!}
from Π-→-≅ = {!!}
-- Needs η laws for functions (∀ x → f x) ≡ f
from∘to Π-→-≅ = {!!}
to∘from Π-→-≅ = {!!}
-- The following isomorphism needs of function extensionality
-- Function extensionality claims that if two functions give the same output on the same input, then they are equal
-- This does not hold internally in Agda and we therefore need to postulate it as an axiom
postulate
extensionality : {P : A → Set} {f g : (a : A) → P a} → (∀ x → f x ≡ g x) → f ≡ g
Π-×-≅ : Π-× A B ≅ A × B
Π-×-≅ = {!!}
curry : Π-→ A (Π-→ B C) → Π-→ (Σ-× A B) C
curry f (a , b) = f a b
uncurry : Π-→ (Σ-× A B) C → Π-→ A (Π-→ B C)
uncurry f a b = f (a , b)
curry-uncurry : Π-→ A (Π-→ B C) ≅ Π-→ (Σ-× A B) C
curry-uncurry = {!!}
Fin-≤-≅ : Fin m ≅ Σ[ n ∈ ℕ ] n < m
Fin-≤-≅ = {!!}
_iso-∘_ : B ≅ C → A ≅ B → A ≅ C
x iso-∘ y = {!!}
-----------
-- Decidability
-----------
module Dec where
open Product using (_×_; _,_; fst; snd)
open Simple using (¬_)
data Dec (A : Set) : Set where
yes : A → Dec A
no : ¬ A → Dec A
DecEq : Set → Set
DecEq A = (x y : A) → Dec (x ≡ y)
map : (A → B) → (¬ A → B) → Dec A → B
map f g (yes x) = f x
map f g (no x) = g x
infix 5 _×-dec_
_×-dec_ : Dec A → Dec B → Dec (A × B)
yes x ×-dec yes y = yes (x , y)
yes x ×-dec no ¬y = no (¬y ∘ snd)
no ¬x ×-dec B? = no (¬x ∘ fst)
_ℕ-≟_ : (n m : ℕ) → Dec (n ≡ m)
n ℕ-≟ m = {!!}
suc-injective : {i j : Fin n} → _≡_ {A = Fin (suc n)} (suc i) (suc j) → i ≡ j
suc-injective refl = refl
_Fin-≟_ : (i j : Fin n) → Dec (i ≡ j)
zero Fin-≟ zero = yes refl
zero Fin-≟ suc j = no λ ()
suc i Fin-≟ zero = no λ ()
suc i Fin-≟ suc j = map
(yes ∘ cong suc)
(no ∘ (λ neq → neq ∘ suc-injective))
(i Fin-≟ j)
∷-injective : {x y : A} {xs ys : List A} → _≡_ {A = List A} (x ∷ xs) (y ∷ ys) → x ≡ y × xs ≡ ys
∷-injective refl = refl , refl
List-≟ : (_A-≟_ : (x y : A) → Dec (x ≡ y)) → (xs ys : List A) → Dec (xs ≡ ys)
List-≟ _A-≟_ [] [] = yes refl
List-≟ _A-≟_ [] (y ∷ ys) = no λ ()
List-≟ _A-≟_ (x ∷ xs) [] = no λ ()
List-≟ _A-≟_ (x ∷ xs) (y ∷ ys) = map
(yes ∘ Isomorphism.curry (cong₂ _∷_))
(no ∘ (λ neq → neq ∘ ∷-injective))
(x A-≟ y ×-dec List-≟ _A-≟_ xs ys)
-----------
-- Interfaces
-----------
-- We define what it is to be a monoid on a carrier set C
record Monoid (C : Set) : Set where
constructor MkMonoid
field
ε : C
_∙_ : C → C → C
-- Including the algebraic laws
idˡ : (x : C) → ε ∙ x ≡ x
idʳ : (x : C) → x ∙ ε ≡ x
assoc : (x y z : C) → (x ∙ y) ∙ z ≡ x ∙ (y ∙ z)
module MonoidSolver (Symbol : Set) (symbol-≟ : Dec.DecEq Symbol) where
-- The syntax for an expression tree of symbolic monoidal operations
infixl 20 _‵∙_
infix 25 ‵_
data Expr : Set where
‵ε : Expr
‵_ : Symbol → Expr
_‵∙_ : Expr → Expr → Expr
-- And define equations on monoids
infix 10 _‵≡_
record Eqn : Set where
constructor _‵≡_
field
lhs : Expr
rhs : Expr
-- The canonical normal form for expression trees
NormalForm : Set
NormalForm = List Symbol
normalise : Expr → NormalForm
normalise ‵ε = []
normalise (‵ x) = x ∷ []
normalise (xs ‵∙ ys) = normalise xs ++ normalise ys
module Eval (M : Monoid C) where
open Monoid M
-- An environment maps symbols to values in the carrier set
Env : Set
Env = Symbol → C
-- Evaluate the syntax in a given environment
⟦_⟧ : Expr → Env → C
⟦ ‵ε ⟧ Γ = ε
⟦ ‵ x ⟧ Γ = Γ x
⟦ x ‵∙ y ⟧ Γ = ⟦ x ⟧ Γ ∙ ⟦ y ⟧ Γ
-- Evaluate the normal form in a given environment
⟦_⟧⇓ : NormalForm → Env → C
⟦ [] ⟧⇓ Γ = ε
⟦ x ∷ xs ⟧⇓ Γ = Γ x ∙ ⟦ xs ⟧⇓ Γ
-- The evaluation of normal forms distributes over list concatenation
++-homo : ∀ Γ (xs ys : NormalForm) → ⟦ xs ++ ys ⟧⇓ Γ ≡ ⟦ xs ⟧⇓ Γ ∙ ⟦ ys ⟧⇓ Γ
++-homo Γ [] ys = sym (idˡ _)
++-homo Γ (x ∷ xs) ys = begin
Γ x ∙ ⟦ xs ++ ys ⟧⇓ Γ
≡⟨ cong (_ ∙_) (++-homo Γ xs ys) ⟩
Γ x ∙ (⟦ xs ⟧⇓ Γ ∙ ⟦ ys ⟧⇓ Γ)
≡⟨ sym (assoc _ _ _) ⟩
(Γ x ∙ ⟦ xs ⟧⇓ Γ) ∙ ⟦ ys ⟧⇓ Γ
∎
-- Normalising and then evaluating the normal form is equal to evaluating the original expression
correct : ∀ Γ (expr : Expr) → ⟦ normalise expr ⟧⇓ Γ ≡ ⟦ expr ⟧ Γ
correct Γ ‵ε = refl
correct Γ (‵ x) = idʳ _
correct Γ (le ‵∙ re) = begin
⟦ normalise le ++ normalise re ⟧⇓ Γ ≡⟨ ++-homo Γ (normalise le) (normalise re) ⟩
⟦ normalise le ⟧⇓ Γ ∙ ⟦ normalise re ⟧⇓ Γ ≡⟨ cong₂ _∙_ (correct Γ le) (correct Γ re) ⟩
⟦ le ⟧ Γ ∙ ⟦ re ⟧ Γ ∎
-- We describe what it is to be a solution to an equation
-- If both sides normalise to the same symbols in the same order,
-- we claim that the monoid laws make the equations hold in any environment
Solution : Eqn → Set
Solution (lhs ‵≡ rhs) =
Dec.map
-- Both sides normalise to a common list of symbols, we must now show that the equation holds under any environment
(λ _ → ∀ (Γ : Env) → ⟦ lhs ⟧ Γ ≡ ⟦ rhs ⟧ Γ)
-- Both sides do *not* normalise to a common list of symbols, we claim only the trivial
(λ _ → ⊤)
(Dec.List-≟ symbol-≟ (normalise lhs) (normalise rhs))
-- Now that we have described what a solution is, we show that we can provide one
solve : (eqn : Eqn) → Solution eqn
-- Pattern matching using with makes the goal type compute
solve (lhs ‵≡ rhs) with Dec.List-≟ symbol-≟ (normalise lhs) (normalise rhs)
solve (lhs ‵≡ rhs) | Dec.no _ = tt
solve (lhs ‵≡ rhs) | Dec.yes lhs⇓≡rhs⇓ = λ Γ → begin
⟦ lhs ⟧ Γ ≡⟨ sym (correct Γ lhs) ⟩
⟦ normalise lhs ⟧⇓ Γ ≡⟨ cong (λ ● → ⟦ ● ⟧⇓ Γ) lhs⇓≡rhs⇓ ⟩
⟦ normalise rhs ⟧⇓ Γ ≡⟨ correct Γ rhs ⟩
⟦ rhs ⟧ Γ ∎
open MonoidSolver
-- An example instance of a monoid: natural numbers with addition
NAT-MONOID : Monoid ℕ
Monoid.ε NAT-MONOID = zero
Monoid._∙_ NAT-MONOID = _+_
Monoid.idˡ NAT-MONOID = +-idˡ
Monoid.idʳ NAT-MONOID = +-idʳ
Monoid.assoc NAT-MONOID = +-assoc
-- An example usage of the monoid solver
-- We first need to "quote" the goal, i.e. describe it in terms of the expression language / syntax
-- NAT-MONOID describes how to interpret the syntax back and evaluate the expression into a value of the carrier set
eqn₁-auto : (x y z : ℕ) → (0 + x) + y + (y + z) ≡ x + (0 + y + 0) + (y + z + 0)
eqn₁-auto x y z =
let
‵x = zero
‵y = suc zero
‵z = suc (suc zero)
lhs = (‵ε ‵∙ ‵ ‵x) ‵∙ ‵ ‵y ‵∙ (‵ ‵y ‵∙ ‵ ‵z)
rhs = ‵ ‵x ‵∙ (‵ε ‵∙ ‵ ‵y ‵∙ ‵ε) ‵∙ (‵ ‵y ‵∙ ‵ ‵z ‵∙ ‵ε)
in
Eval.solve (Fin 3) Dec._Fin-≟_ NAT-MONOID (lhs ‵≡ rhs) λ where
zero → x
(suc zero) → y
(suc (suc zero)) → z
|
{
"alphanum_fraction": 0.5305053679,
"avg_line_length": 30.7983870968,
"ext": "agda",
"hexsha": "2e99df9de532ca0021bdb82c2ac3f6543e323c99",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:50:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-23T08:50:13.000Z",
"max_forks_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "poncev/agda-bcam",
"max_forks_repo_path": "Tutorials/Wednesday.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"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": "poncev/agda-bcam",
"max_issues_repo_path": "Tutorials/Wednesday.agda",
"max_line_length": 123,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "ccd2a78642e93754011deffbe85e9ef5071e4cb7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "poncev/agda-bcam",
"max_stars_repo_path": "Tutorials/Wednesday.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-03T22:53:51.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T17:59:21.000Z",
"num_tokens": 3181,
"size": 7638
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- List-related properties
------------------------------------------------------------------------
-- Note that the lemmas below could be generalised to work with other
-- equalities than _≡_.
module Data.List.Properties where
open import Algebra
import Algebra.Monoid-solver
open import Category.Monad
open import Data.Bool
open import Data.List as List
open import Data.List.All using (All; []; _∷_)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Nat
open import Data.Nat.Properties
open import Data.Product as Prod hiding (map)
open import Function
import Algebra.FunctionProperties
import Relation.Binary.EqReasoning as EqR
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≢_; _≗_; refl)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (⌊_⌋)
open import Relation.Unary using (Decidable)
private
open module FP {a} {A : Set a} =
Algebra.FunctionProperties (_≡_ {A = A})
open module LMP {ℓ} = RawMonadPlus (List.monadPlus {ℓ = ℓ})
module LM {a} {A : Set a} = Monoid (List.monoid A)
module List-solver {a} {A : Set a} =
Algebra.Monoid-solver (monoid A) renaming (id to nil)
∷-injective : ∀ {a} {A : Set a} {x y : A} {xs ys} →
x ∷ xs ≡ y List.∷ ys → x ≡ y × xs ≡ ys
∷-injective refl = (refl , refl)
∷ʳ-injective : ∀ {a} {A : Set a} {x y : A} xs ys →
xs ∷ʳ x ≡ ys ∷ʳ y → xs ≡ ys × x ≡ y
∷ʳ-injective [] [] refl = (refl , refl)
∷ʳ-injective (x ∷ xs) (y ∷ ys) eq with ∷-injective eq
∷ʳ-injective (x ∷ xs) (.x ∷ ys) eq | (refl , eq′) =
Prod.map (P.cong (_∷_ x)) id $ ∷ʳ-injective xs ys eq′
∷ʳ-injective [] (_ ∷ []) ()
∷ʳ-injective [] (_ ∷ _ ∷ _) ()
∷ʳ-injective (_ ∷ []) [] ()
∷ʳ-injective (_ ∷ _ ∷ _) [] ()
right-identity-unique : ∀ {a} {A : Set a} (xs : List A) {ys} →
xs ≡ xs ++ ys → ys ≡ []
right-identity-unique [] refl = refl
right-identity-unique (x ∷ xs) eq =
right-identity-unique xs (proj₂ (∷-injective eq))
left-identity-unique : ∀ {a} {A : Set a} {xs} (ys : List A) →
xs ≡ ys ++ xs → ys ≡ []
left-identity-unique [] _ = refl
left-identity-unique {xs = []} (y ∷ ys) ()
left-identity-unique {xs = x ∷ xs} (y ∷ ys) eq
with left-identity-unique (ys ++ [ x ]) (begin
xs ≡⟨ proj₂ (∷-injective eq) ⟩
ys ++ x ∷ xs ≡⟨ P.sym (LM.assoc ys [ x ] xs) ⟩
(ys ++ [ x ]) ++ xs ∎)
where open P.≡-Reasoning
left-identity-unique {xs = x ∷ xs} (y ∷ [] ) eq | ()
left-identity-unique {xs = x ∷ xs} (y ∷ _ ∷ _) eq | ()
-- Map, sum, and append.
map-++-commute : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) xs ys →
map f (xs ++ ys) ≡ map f xs ++ map f ys
map-++-commute f [] ys = refl
map-++-commute f (x ∷ xs) ys =
P.cong (_∷_ (f x)) (map-++-commute f xs ys)
sum-++-commute : ∀ xs ys → sum (xs ++ ys) ≡ sum xs + sum ys
sum-++-commute [] ys = refl
sum-++-commute (x ∷ xs) ys = begin
x + sum (xs ++ ys)
≡⟨ P.cong (_+_ x) (sum-++-commute xs ys) ⟩
x + (sum xs + sum ys)
≡⟨ P.sym $ +-assoc x _ _ ⟩
(x + sum xs) + sum ys
∎
where
open CommutativeSemiring commutativeSemiring hiding (_+_)
open P.≡-Reasoning
-- Various properties about folds.
foldr-universal : ∀ {a b} {A : Set a} {B : Set b}
(h : List A → B) f e →
(h [] ≡ e) →
(∀ x xs → h (x ∷ xs) ≡ f x (h xs)) →
h ≗ foldr f e
foldr-universal h f e base step [] = base
foldr-universal h f e base step (x ∷ xs) = begin
h (x ∷ xs)
≡⟨ step x xs ⟩
f x (h xs)
≡⟨ P.cong (f x) (foldr-universal h f e base step xs) ⟩
f x (foldr f e xs)
∎
where open P.≡-Reasoning
foldr-fusion : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
(h : B → C) {f : A → B → B} {g : A → C → C} (e : B) →
(∀ x y → h (f x y) ≡ g x (h y)) →
h ∘ foldr f e ≗ foldr g (h e)
foldr-fusion h {f} {g} e fuse =
foldr-universal (h ∘ foldr f e) g (h e) refl
(λ x xs → fuse x (foldr f e xs))
idIsFold : ∀ {a} {A : Set a} → id {A = List A} ≗ foldr _∷_ []
idIsFold = foldr-universal id _∷_ [] refl (λ _ _ → refl)
++IsFold : ∀ {a} {A : Set a} (xs ys : List A) →
xs ++ ys ≡ foldr _∷_ ys xs
++IsFold xs ys =
begin
xs ++ ys
≡⟨ P.cong (λ xs → xs ++ ys) (idIsFold xs) ⟩
foldr _∷_ [] xs ++ ys
≡⟨ foldr-fusion (λ xs → xs ++ ys) [] (λ _ _ → refl) xs ⟩
foldr _∷_ ([] ++ ys) xs
≡⟨ refl ⟩
foldr _∷_ ys xs
∎
where open P.≡-Reasoning
mapIsFold : ∀ {a b} {A : Set a} {B : Set b} {f : A → B} →
map f ≗ foldr (λ x ys → f x ∷ ys) []
mapIsFold {f = f} =
begin
map f
≈⟨ P.cong (map f) ∘ idIsFold ⟩
map f ∘ foldr _∷_ []
≈⟨ foldr-fusion (map f) [] (λ _ _ → refl) ⟩
foldr (λ x ys → f x ∷ ys) []
∎
where open EqR (P._→-setoid_ _ _)
concat-map : ∀ {a b} {A : Set a} {B : Set b} {f : A → B} →
concat ∘ map (map f) ≗ map f ∘ concat
concat-map {b = b} {f = f} =
begin
concat ∘ map (map f)
≈⟨ P.cong concat ∘ mapIsFold {b = b} ⟩
concat ∘ foldr (λ xs ys → map f xs ∷ ys) []
≈⟨ foldr-fusion {b = b} concat [] (λ _ _ → refl) ⟩
foldr (λ ys zs → map f ys ++ zs) []
≈⟨ P.sym ∘
foldr-fusion (map f) [] (λ ys zs → map-++-commute f ys zs) ⟩
map f ∘ concat
∎
where open EqR (P._→-setoid_ _ _)
map-id : ∀ {a} {A : Set a} → map id ≗ id {A = List A}
map-id {A = A} = begin
map id ≈⟨ mapIsFold ⟩
foldr _∷_ [] ≈⟨ P.sym ∘ idIsFold {A = A} ⟩
id ∎
where open EqR (P._→-setoid_ _ _)
map-compose : ∀ {a b c} {A : Set a} {B : Set b} {C : Set c}
{g : B → C} {f : A → B} →
map (g ∘ f) ≗ map g ∘ map f
map-compose {A = A} {B} {g = g} {f} =
begin
map (g ∘ f)
≈⟨ P.cong (map (g ∘ f)) ∘ idIsFold ⟩
map (g ∘ f) ∘ foldr _∷_ []
≈⟨ foldr-fusion (map (g ∘ f)) [] (λ _ _ → refl) ⟩
foldr (λ a y → g (f a) ∷ y) []
≈⟨ P.sym ∘ foldr-fusion (map g) [] (λ _ _ → refl) ⟩
map g ∘ foldr (λ a y → f a ∷ y) []
≈⟨ P.cong (map g) ∘ P.sym ∘ mapIsFold {A = A} {B = B} ⟩
map g ∘ map f
∎
where open EqR (P._→-setoid_ _ _)
foldr-cong : ∀ {a b} {A : Set a} {B : Set b}
{f₁ f₂ : A → B → B} {e₁ e₂ : B} →
(∀ x y → f₁ x y ≡ f₂ x y) → e₁ ≡ e₂ →
foldr f₁ e₁ ≗ foldr f₂ e₂
foldr-cong {f₁ = f₁} {f₂} {e} f₁≗₂f₂ refl =
begin
foldr f₁ e
≈⟨ P.cong (foldr f₁ e) ∘ idIsFold ⟩
foldr f₁ e ∘ foldr _∷_ []
≈⟨ foldr-fusion (foldr f₁ e) [] (λ x xs → f₁≗₂f₂ x (foldr f₁ e xs)) ⟩
foldr f₂ e
∎
where open EqR (P._→-setoid_ _ _)
map-cong : ∀ {a b} {A : Set a} {B : Set b} {f g : A → B} →
f ≗ g → map f ≗ map g
map-cong {A = A} {B} {f} {g} f≗g =
begin
map f
≈⟨ mapIsFold ⟩
foldr (λ x ys → f x ∷ ys) []
≈⟨ foldr-cong (λ x ys → P.cong₂ _∷_ (f≗g x) refl) refl ⟩
foldr (λ x ys → g x ∷ ys) []
≈⟨ P.sym ∘ mapIsFold {A = A} {B = B} ⟩
map g
∎
where open EqR (P._→-setoid_ _ _)
-- Take, drop, and splitAt.
take++drop : ∀ {a} {A : Set a}
n (xs : List A) → take n xs ++ drop n xs ≡ xs
take++drop zero xs = refl
take++drop (suc n) [] = refl
take++drop (suc n) (x ∷ xs) =
P.cong (λ xs → x ∷ xs) (take++drop n xs)
splitAt-defn : ∀ {a} {A : Set a} n →
splitAt {A = A} n ≗ < take n , drop n >
splitAt-defn zero xs = refl
splitAt-defn (suc n) [] = refl
splitAt-defn (suc n) (x ∷ xs) with splitAt n xs | splitAt-defn n xs
... | (ys , zs) | ih = P.cong (Prod.map (_∷_ x) id) ih
-- TakeWhile, dropWhile, and span.
takeWhile++dropWhile : ∀ {a} {A : Set a} (p : A → Bool) (xs : List A) →
takeWhile p xs ++ dropWhile p xs ≡ xs
takeWhile++dropWhile p [] = refl
takeWhile++dropWhile p (x ∷ xs) with p x
... | true = P.cong (_∷_ x) (takeWhile++dropWhile p xs)
... | false = refl
span-defn : ∀ {a} {A : Set a} (p : A → Bool) →
span p ≗ < takeWhile p , dropWhile p >
span-defn p [] = refl
span-defn p (x ∷ xs) with p x
... | true = P.cong (Prod.map (_∷_ x) id) (span-defn p xs)
... | false = refl
-- Partition, filter.
partition-defn : ∀ {a} {A : Set a} (p : A → Bool) →
partition p ≗ < filter p , filter (not ∘ p) >
partition-defn p [] = refl
partition-defn p (x ∷ xs)
with p x | partition p xs | partition-defn p xs
... | true | (ys , zs) | eq = P.cong (Prod.map (_∷_ x) id) eq
... | false | (ys , zs) | eq = P.cong (Prod.map id (_∷_ x)) eq
filter-filters : ∀ {a p} {A : Set a} →
(P : A → Set p) (dec : Decidable P) (xs : List A) →
All P (filter (⌊_⌋ ∘ dec) xs)
filter-filters P dec [] = []
filter-filters P dec (x ∷ xs) with dec x
filter-filters P dec (x ∷ xs) | yes px = px ∷ filter-filters P dec xs
filter-filters P dec (x ∷ xs) | no ¬px = filter-filters P dec xs
-- Inits, tails, and scanr.
scanr-defn : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B → B) (e : B) →
scanr f e ≗ map (foldr f e) ∘ tails
scanr-defn f e [] = refl
scanr-defn f e (x ∷ []) = refl
scanr-defn f e (x₁ ∷ x₂ ∷ xs)
with scanr f e (x₂ ∷ xs) | scanr-defn f e (x₂ ∷ xs)
... | [] | ()
... | y ∷ ys | eq with ∷-injective eq
... | y≡fx₂⦇f⦈xs , _ = P.cong₂ (λ z zs → f x₁ z ∷ zs) y≡fx₂⦇f⦈xs eq
scanl-defn : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B → A) (e : A) →
scanl f e ≗ map (foldl f e) ∘ inits
scanl-defn f e [] = refl
scanl-defn f e (x ∷ xs) = P.cong (_∷_ e) (begin
scanl f (f e x) xs
≡⟨ scanl-defn f (f e x) xs ⟩
map (foldl f (f e x)) (inits xs)
≡⟨ refl ⟩
map (foldl f e ∘ (_∷_ x)) (inits xs)
≡⟨ map-compose (inits xs) ⟩
map (foldl f e) (map (_∷_ x) (inits xs))
∎)
where open P.≡-Reasoning
-- Length.
length-map : ∀ {a b} {A : Set a} {B : Set b} (f : A → B) xs →
length (map f xs) ≡ length xs
length-map f [] = refl
length-map f (x ∷ xs) = P.cong suc (length-map f xs)
length-++ : ∀ {a} {A : Set a} (xs : List A) {ys} →
length (xs ++ ys) ≡ length xs + length ys
length-++ [] = refl
length-++ (x ∷ xs) = P.cong suc (length-++ xs)
length-replicate : ∀ {a} {A : Set a} n {x : A} →
length (replicate n x) ≡ n
length-replicate zero = refl
length-replicate (suc n) = P.cong suc (length-replicate n)
length-gfilter : ∀ {a b} {A : Set a} {B : Set b} (p : A → Maybe B) xs →
length (gfilter p xs) ≤ length xs
length-gfilter p [] = z≤n
length-gfilter p (x ∷ xs) with p x
length-gfilter p (x ∷ xs) | just y = s≤s (length-gfilter p xs)
length-gfilter p (x ∷ xs) | nothing = ≤-step (length-gfilter p xs)
-- Reverse.
unfold-reverse : ∀ {a} {A : Set a} (x : A) (xs : List A) →
reverse (x ∷ xs) ≡ reverse xs ∷ʳ x
unfold-reverse x xs = begin
foldl (flip _∷_) [ x ] xs ≡⟨ helper [ x ] xs ⟩
reverse xs ∷ʳ x ∎
where
open P.≡-Reasoning
helper : ∀ {a} {A : Set a} (xs ys : List A) →
foldl (flip _∷_) xs ys ≡ reverse ys ++ xs
helper xs [] = P.refl
helper xs (y ∷ ys) = begin
foldl (flip _∷_) (y ∷ xs) ys ≡⟨ helper (y ∷ xs) ys ⟩
reverse ys ++ y ∷ xs ≡⟨ P.sym $ LM.assoc (reverse ys) _ _ ⟩
(reverse ys ∷ʳ y) ++ xs ≡⟨ P.sym $ P.cong (λ zs → zs ++ xs) (unfold-reverse y ys) ⟩
reverse (y ∷ ys) ++ xs ∎
reverse-++-commute :
∀ {a} {A : Set a} (xs ys : List A) →
reverse (xs ++ ys) ≡ reverse ys ++ reverse xs
reverse-++-commute {a} [] ys = begin
reverse ys ≡⟨ P.sym $ proj₂ {a = a} {b = a} LM.identity _ ⟩
reverse ys ++ [] ≡⟨ P.refl ⟩
reverse ys ++ reverse [] ∎
where open P.≡-Reasoning
reverse-++-commute (x ∷ xs) ys = begin
reverse (x ∷ xs ++ ys) ≡⟨ unfold-reverse x (xs ++ ys) ⟩
reverse (xs ++ ys) ++ [ x ] ≡⟨ P.cong (λ zs → zs ++ [ x ]) (reverse-++-commute xs ys) ⟩
(reverse ys ++ reverse xs) ++ [ x ] ≡⟨ LM.assoc (reverse ys) _ _ ⟩
reverse ys ++ (reverse xs ++ [ x ]) ≡⟨ P.sym $ P.cong (λ zs → reverse ys ++ zs) (unfold-reverse x xs) ⟩
reverse ys ++ reverse (x ∷ xs) ∎
where open P.≡-Reasoning
reverse-map-commute :
∀ {a b} {A : Set a} {B : Set b} (f : A → B) → (xs : List A) →
map f (reverse xs) ≡ reverse (map f xs)
reverse-map-commute f [] = refl
reverse-map-commute f (x ∷ xs) = begin
map f (reverse (x ∷ xs)) ≡⟨ P.cong (map f) $ unfold-reverse x xs ⟩
map f (reverse xs ∷ʳ x) ≡⟨ map-++-commute f (reverse xs) ([ x ]) ⟩
map f (reverse xs) ∷ʳ f x ≡⟨ P.cong (λ y → y ∷ʳ f x) $ reverse-map-commute f xs ⟩
reverse (map f xs) ∷ʳ f x ≡⟨ P.sym $ unfold-reverse (f x) (map f xs) ⟩
reverse (map f (x ∷ xs)) ∎
where open P.≡-Reasoning
reverse-involutive : ∀ {a} {A : Set a} → Involutive (reverse {A = A})
reverse-involutive [] = refl
reverse-involutive (x ∷ xs) = begin
reverse (reverse (x ∷ xs)) ≡⟨ P.cong reverse $ unfold-reverse x xs ⟩
reverse (reverse xs ∷ʳ x) ≡⟨ reverse-++-commute (reverse xs) ([ x ]) ⟩
x ∷ reverse (reverse (xs)) ≡⟨ P.cong (λ y → x ∷ y) $ reverse-involutive xs ⟩
x ∷ xs ∎
where open P.≡-Reasoning
-- The list monad.
module Monad where
left-zero : ∀ {ℓ} {A B : Set ℓ} (f : A → List B) → (∅ >>= f) ≡ ∅
left-zero f = refl
right-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) →
(xs >>= const ∅) ≡ ∅ {A = B}
right-zero [] = refl
right-zero (x ∷ xs) = right-zero xs
private
not-left-distributive :
let xs = true ∷ false ∷ []; f = return; g = return in
(xs >>= λ x → f x ∣ g x) ≢ ((xs >>= f) ∣ (xs >>= g))
not-left-distributive ()
right-distributive : ∀ {ℓ} {A B : Set ℓ}
(xs ys : List A) (f : A → List B) →
(xs ∣ ys >>= f) ≡ ((xs >>= f) ∣ (ys >>= f))
right-distributive [] ys f = refl
right-distributive (x ∷ xs) ys f = begin
f x ∣ (xs ∣ ys >>= f) ≡⟨ P.cong (_∣_ (f x)) $ right-distributive xs ys f ⟩
f x ∣ ((xs >>= f) ∣ (ys >>= f)) ≡⟨ P.sym $ LM.assoc (f x) _ _ ⟩
(f x ∣ (xs >>= f)) ∣ (ys >>= f) ∎
where open P.≡-Reasoning
left-identity : ∀ {ℓ} {A B : Set ℓ} (x : A) (f : A → List B) →
(return x >>= f) ≡ f x
left-identity {ℓ} x f = proj₂ (LM.identity {a = ℓ}) (f x)
right-identity : ∀ {a} {A : Set a} (xs : List A) →
(xs >>= return) ≡ xs
right-identity [] = refl
right-identity (x ∷ xs) = P.cong (_∷_ x) (right-identity xs)
associative : ∀ {ℓ} {A B C : Set ℓ}
(xs : List A) (f : A → List B) (g : B → List C) →
(xs >>= λ x → f x >>= g) ≡ (xs >>= f >>= g)
associative [] f g = refl
associative (x ∷ xs) f g = begin
(f x >>= g) ∣ (xs >>= λ x → f x >>= g) ≡⟨ P.cong (_∣_ (f x >>= g)) $ associative xs f g ⟩
(f x >>= g) ∣ (xs >>= f >>= g) ≡⟨ P.sym $ right-distributive (f x) (xs >>= f) g ⟩
(f x ∣ (xs >>= f) >>= g) ∎
where open P.≡-Reasoning
cong : ∀ {ℓ} {A B : Set ℓ} {xs₁ xs₂} {f₁ f₂ : A → List B} →
xs₁ ≡ xs₂ → f₁ ≗ f₂ → (xs₁ >>= f₁) ≡ (xs₂ >>= f₂)
cong {xs₁ = xs} refl f₁≗f₂ = P.cong concat (map-cong f₁≗f₂ xs)
-- The applicative functor derived from the list monad.
-- Note that these proofs (almost) show that RawIMonad.rawIApplicative
-- is correctly defined. The proofs can be reused if proof components
-- are ever added to RawIMonad and RawIApplicative.
module Applicative where
open P.≡-Reasoning
private
-- A variant of flip map.
pam : ∀ {ℓ} {A B : Set ℓ} → List A → (A → B) → List B
pam xs f = xs >>= return ∘ f
-- ∅ is a left zero for _⊛_.
left-zero : ∀ {ℓ} {A B : Set ℓ} (xs : List A) → ∅ ⊛ xs ≡ ∅ {A = B}
left-zero xs = begin
∅ ⊛ xs ≡⟨ refl ⟩
(∅ >>= pam xs) ≡⟨ Monad.left-zero (pam xs) ⟩
∅ ∎
-- ∅ is a right zero for _⊛_.
right-zero : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) → fs ⊛ ∅ ≡ ∅
right-zero {ℓ} fs = begin
fs ⊛ ∅ ≡⟨ refl ⟩
(fs >>= pam ∅) ≡⟨ (Monad.cong (refl {x = fs}) λ f →
Monad.left-zero (return {ℓ = ℓ} ∘ f)) ⟩
(fs >>= λ _ → ∅) ≡⟨ Monad.right-zero fs ⟩
∅ ∎
-- _⊛_ distributes over _∣_ from the right.
right-distributive :
∀ {ℓ} {A B : Set ℓ} (fs₁ fs₂ : List (A → B)) xs →
(fs₁ ∣ fs₂) ⊛ xs ≡ (fs₁ ⊛ xs ∣ fs₂ ⊛ xs)
right-distributive fs₁ fs₂ xs = begin
(fs₁ ∣ fs₂) ⊛ xs ≡⟨ refl ⟩
(fs₁ ∣ fs₂ >>= pam xs) ≡⟨ Monad.right-distributive fs₁ fs₂ (pam xs) ⟩
(fs₁ >>= pam xs) ∣ (fs₂ >>= pam xs) ≡⟨ refl ⟩
fs₁ ⊛ xs ∣ fs₂ ⊛ xs ∎
-- _⊛_ does not distribute over _∣_ from the left.
private
not-left-distributive :
let fs = id ∷ id ∷ []; xs₁ = true ∷ []; xs₂ = true ∷ false ∷ [] in
fs ⊛ (xs₁ ∣ xs₂) ≢ (fs ⊛ xs₁ ∣ fs ⊛ xs₂)
not-left-distributive ()
-- Applicative functor laws.
identity : ∀ {a} {A : Set a} (xs : List A) → return id ⊛ xs ≡ xs
identity xs = begin
return id ⊛ xs ≡⟨ refl ⟩
(return id >>= pam xs) ≡⟨ Monad.left-identity id (pam xs) ⟩
(xs >>= return) ≡⟨ Monad.right-identity xs ⟩
xs ∎
private
pam-lemma : ∀ {ℓ} {A B C : Set ℓ}
(xs : List A) (f : A → B) (fs : B → List C) →
(pam xs f >>= fs) ≡ (xs >>= λ x → fs (f x))
pam-lemma xs f fs = begin
(pam xs f >>= fs) ≡⟨ P.sym $ Monad.associative xs (return ∘ f) fs ⟩
(xs >>= λ x → return (f x) >>= fs) ≡⟨ Monad.cong (refl {x = xs}) (λ x → Monad.left-identity (f x) fs) ⟩
(xs >>= λ x → fs (f x)) ∎
composition :
∀ {ℓ} {A B C : Set ℓ}
(fs : List (B → C)) (gs : List (A → B)) xs →
return _∘′_ ⊛ fs ⊛ gs ⊛ xs ≡ fs ⊛ (gs ⊛ xs)
composition {ℓ} fs gs xs = begin
return _∘′_ ⊛ fs ⊛ gs ⊛ xs ≡⟨ refl ⟩
(return _∘′_ >>= pam fs >>= pam gs >>= pam xs) ≡⟨ Monad.cong (Monad.cong (Monad.left-identity _∘′_ (pam fs))
(λ f → refl {x = pam gs f}))
(λ fg → refl {x = pam xs fg}) ⟩
(pam fs _∘′_ >>= pam gs >>= pam xs) ≡⟨ Monad.cong (pam-lemma fs _∘′_ (pam gs)) (λ _ → refl) ⟩
((fs >>= λ f → pam gs (_∘′_ f)) >>= pam xs) ≡⟨ P.sym $ Monad.associative fs (λ f → pam gs (_∘′_ f)) (pam xs) ⟩
(fs >>= λ f → pam gs (_∘′_ f) >>= pam xs) ≡⟨ (Monad.cong (refl {x = fs}) λ f →
pam-lemma gs (_∘′_ f) (pam xs)) ⟩
(fs >>= λ f → gs >>= λ g → pam xs (f ∘′ g)) ≡⟨ (Monad.cong (refl {x = fs}) λ f →
Monad.cong (refl {x = gs}) λ g →
P.sym $ pam-lemma xs g (return ∘ f)) ⟩
(fs >>= λ f → gs >>= λ g → pam (pam xs g) f) ≡⟨ (Monad.cong (refl {x = fs}) λ f →
Monad.associative gs (pam xs) (return ∘ f)) ⟩
(fs >>= pam (gs >>= pam xs)) ≡⟨ refl ⟩
fs ⊛ (gs ⊛ xs) ∎
homomorphism : ∀ {ℓ} {A B : Set ℓ} (f : A → B) x →
return f ⊛ return x ≡ return (f x)
homomorphism f x = begin
return f ⊛ return x ≡⟨ refl ⟩
(return f >>= pam (return x)) ≡⟨ Monad.left-identity f (pam (return x)) ⟩
pam (return x) f ≡⟨ Monad.left-identity x (return ∘ f) ⟩
return (f x) ∎
interchange : ∀ {ℓ} {A B : Set ℓ} (fs : List (A → B)) {x} →
fs ⊛ return x ≡ return (λ f → f x) ⊛ fs
interchange fs {x} = begin
fs ⊛ return x ≡⟨ refl ⟩
(fs >>= pam (return x)) ≡⟨ (Monad.cong (refl {x = fs}) λ f →
Monad.left-identity x (return ∘ f)) ⟩
(fs >>= λ f → return (f x)) ≡⟨ refl ⟩
(pam fs (λ f → f x)) ≡⟨ P.sym $ Monad.left-identity (λ f → f x) (pam fs) ⟩
(return (λ f → f x) >>= pam fs) ≡⟨ refl ⟩
return (λ f → f x) ⊛ fs ∎
|
{
"alphanum_fraction": 0.4701183432,
"avg_line_length": 37.5555555556,
"ext": "agda",
"hexsha": "2280e04d6be5d149e5888abcf167674878d56ddc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/List/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/List/Properties.agda",
"max_line_length": 118,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/List/Properties.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": 8006,
"size": 20280
}
|
module container.m.extensionality where
open import sum
open import equality
open import container.core
open import container.fixpoint
open import container.equality
open import container.m.core
module Extensionality {li la lb}(c : Container li la lb) where
private
module C where
open Definition c public
fp : Fixpoint c _
fp = fix M fixpoint
open Fixpoint fp public
using (head; tail)
module S where
open Equality c C.fp
using (equality)
open Equality c C.fp public
using (substX)
open Definition equality public
fp : Fixpoint equality _
fp = fix M fixpoint
open Fixpoint fp public
using (head; tail)
open C
-- bisimilarity relation
_≡M_ : ∀ {i}(u v : M i) → Set _
u ≡M v = S.M (_ , u , v)
reflM : ∀ {i}{u : M i} → u ≡M u
reflM = S.inf refl (λ b → ♯ reflM)
private
-- total space of bisimilarity
E : ∀ i → Set _
E i = Σ (M i × M i) (uncurry _≡M_)
f : E →ⁱ F E
f i ((xs , ys) , bisim)
= head xs
, (λ b → (( tail xs b
, S.substX (S.head bisim) b
(tail ys (subst B (S.head bisim) b)))
, S.tail bisim b))
π₁ : E →ⁱ M
π₁ i ((xs , _), _) = xs
π₁-mor : ∀ {i} (e : E i) → out i (π₁ i e) ≡ imap π₁ i (f i e)
π₁-mor ((xs , ys) , p) = refl
π₂ : E →ⁱ M
π₂ _ ((_ , ys), _) = ys
π₂-mor : ∀ {i} (e : E i) → out i (π₂ i e) ≡ imap π₂ i (f i e)
π₂-mor {i} ((xs , ys) , bisim) = lem (S.head bisim) (tail ys)
where
lem : {a a' : A i}(p : a ≡ a')
→ (f : (b' : B a') → M (r b'))
→ _≡_ {A = F M i}
(a' , f)
(a , λ b → S.substX p b (f (subst B p b)))
lem refl f = refl
equal-π : ∀ {i}(e : E i) → π₁ i e ≡ π₂ i e
equal-π e = unfold-η f π₁ π₁-mor e · sym (unfold-η f π₂ π₂-mor e)
abstract
mext₀ : ∀ {i} {xs ys : M i} → xs ≡M ys → xs ≡ ys
mext₀ p = equal-π (_ , p)
mext-inv : ∀ {i}{xs ys : M i} → xs ≡ ys → xs ≡M ys
mext-inv refl = reflM
mext : ∀ {i} {xs ys : M i} → xs ≡M ys → xs ≡ ys
mext p = mext₀ p · sym (mext₀ reflM)
mext-id : ∀ {i}{u : M i} → mext (reflM {u = u}) ≡ refl
mext-id = left-inverse (mext₀ reflM)
mext-retraction : ∀ {i}{xs ys : M i}(p : xs ≡ ys)
→ mext (mext-inv p) ≡ p
mext-retraction refl = left-inverse (mext₀ reflM)
|
{
"alphanum_fraction": 0.499792445,
"avg_line_length": 25.6276595745,
"ext": "agda",
"hexsha": "3117120599021e1e8a249c22b785f6f122f102b7",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/m/extensionality.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/container/m/extensionality.agda",
"max_line_length": 69,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "container/m/extensionality.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 892,
"size": 2409
}
|
{-# OPTIONS --allow-unsolved-metas #-}
module fin where
open import Data.Fin hiding (_<_ ; _≤_ ; _>_ ; _+_ )
open import Data.Fin.Properties hiding (≤-trans ; <-trans ; ≤-refl ) renaming ( <-cmp to <-fcmp )
open import Data.Nat
open import Data.Nat.Properties
open import logic
open import nat
open import Relation.Binary.PropositionalEquality
-- toℕ<n
fin<n : {n : ℕ} {f : Fin n} → toℕ f < n
fin<n {_} {zero} = s≤s z≤n
fin<n {suc n} {suc f} = s≤s (fin<n {n} {f})
-- toℕ≤n
fin≤n : {n : ℕ} (f : Fin (suc n)) → toℕ f ≤ n
fin≤n {_} zero = z≤n
fin≤n {suc n} (suc f) = s≤s (fin≤n {n} f)
pred<n : {n : ℕ} {f : Fin (suc n)} → n > 0 → Data.Nat.pred (toℕ f) < n
pred<n {suc n} {zero} (s≤s z≤n) = s≤s z≤n
pred<n {suc n} {suc f} (s≤s z≤n) = fin<n
fin<asa : {n : ℕ} → toℕ (fromℕ< {n} a<sa) ≡ n
fin<asa = toℕ-fromℕ< nat.a<sa
-- fromℕ<-toℕ
toℕ→from : {n : ℕ} {x : Fin (suc n)} → toℕ x ≡ n → fromℕ n ≡ x
toℕ→from {0} {zero} refl = refl
toℕ→from {suc n} {suc x} eq = cong (λ k → suc k ) ( toℕ→from {n} {x} (cong (λ k → Data.Nat.pred k ) eq ))
0≤fmax : {n : ℕ } → (# 0) Data.Fin.≤ fromℕ< {n} a<sa
0≤fmax = subst (λ k → 0 ≤ k ) (sym (toℕ-fromℕ< a<sa)) z≤n
0<fmax : {n : ℕ } → (# 0) Data.Fin.< fromℕ< {suc n} a<sa
0<fmax = subst (λ k → 0 < k ) (sym (toℕ-fromℕ< a<sa)) (s≤s z≤n)
-- toℕ-injective
i=j : {n : ℕ} (i j : Fin n) → toℕ i ≡ toℕ j → i ≡ j
i=j {suc n} zero zero refl = refl
i=j {suc n} (suc i) (suc j) eq = cong ( λ k → suc k ) ( i=j i j (cong ( λ k → Data.Nat.pred k ) eq) )
-- raise 1
fin+1 : { n : ℕ } → Fin n → Fin (suc n)
fin+1 zero = zero
fin+1 (suc x) = suc (fin+1 x)
open import Data.Nat.Properties as NatP hiding ( _≟_ )
fin+1≤ : { i n : ℕ } → (a : i < n) → fin+1 (fromℕ< a) ≡ fromℕ< (<-trans a a<sa)
fin+1≤ {0} {suc i} (s≤s z≤n) = refl
fin+1≤ {suc n} {suc (suc i)} (s≤s (s≤s a)) = cong (λ k → suc k ) ( fin+1≤ {n} {suc i} (s≤s a) )
fin+1-toℕ : { n : ℕ } → { x : Fin n} → toℕ (fin+1 x) ≡ toℕ x
fin+1-toℕ {suc n} {zero} = refl
fin+1-toℕ {suc n} {suc x} = cong (λ k → suc k ) (fin+1-toℕ {n} {x})
open import Relation.Nullary
open import Data.Empty
fin-1 : { n : ℕ } → (x : Fin (suc n)) → ¬ (x ≡ zero ) → Fin n
fin-1 zero ne = ⊥-elim (ne refl )
fin-1 {n} (suc x) ne = x
fin-1-sx : { n : ℕ } → (x : Fin n) → fin-1 (suc x) (λ ()) ≡ x
fin-1-sx zero = refl
fin-1-sx (suc x) = refl
fin-1-xs : { n : ℕ } → (x : Fin (suc n)) → (ne : ¬ (x ≡ zero )) → suc (fin-1 x ne ) ≡ x
fin-1-xs zero ne = ⊥-elim ( ne refl )
fin-1-xs (suc x) ne = refl
-- suc-injective
-- suc-eq : {n : ℕ } {x y : Fin n} → Fin.suc x ≡ Fin.suc y → x ≡ y
-- suc-eq {n} {x} {y} eq = subst₂ (λ j k → j ≡ k ) {!!} {!!} (cong (λ k → Data.Fin.pred k ) eq )
-- this is refl
lemma3 : {a b : ℕ } → (lt : a < b ) → fromℕ< (s≤s lt) ≡ suc (fromℕ< lt)
lemma3 (s≤s lt) = refl
-- fromℕ<-toℕ
lemma12 : {n m : ℕ } → (n<m : n < m ) → (f : Fin m ) → toℕ f ≡ n → f ≡ fromℕ< n<m
lemma12 {zero} {suc m} (s≤s z≤n) zero refl = refl
lemma12 {suc n} {suc m} (s≤s n<m) (suc f) refl = cong suc ( lemma12 {n} {m} n<m f refl )
open import Relation.Binary.HeterogeneousEquality as HE using (_≅_ )
-- <-irrelevant
<-nat=irr : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n
<-nat=irr {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
<-nat=irr {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( <-nat=irr {i} {i} {n} refl )
lemma8 : {i j n : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → i<n ≅ j<n
lemma8 {zero} {zero} {suc n} refl {s≤s z≤n} {s≤s z≤n} = HE.refl
lemma8 {suc i} {suc i} {suc n} refl {s≤s i<n} {s≤s j<n} = HE.cong (λ k → s≤s k ) ( lemma8 {i} {i} {n} refl )
-- fromℕ<-irrelevant
lemma10 : {n i j : ℕ } → ( i ≡ j ) → {i<n : i < n } → {j<n : j < n } → fromℕ< i<n ≡ fromℕ< j<n
lemma10 {n} refl = HE.≅-to-≡ (HE.cong (λ k → fromℕ< k ) (lemma8 refl ))
lemma31 : {a b c : ℕ } → { a<b : a < b } { b<c : b < c } { a<c : a < c } → NatP.<-trans a<b b<c ≡ a<c
lemma31 {a} {b} {c} {a<b} {b<c} {a<c} = HE.≅-to-≡ (lemma8 refl)
-- toℕ-fromℕ<
lemma11 : {n m : ℕ } {x : Fin n } → (n<m : n < m ) → toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m)) ≡ toℕ x
lemma11 {n} {m} {x} n<m = begin
toℕ (fromℕ< (NatP.<-trans (toℕ<n x) n<m))
≡⟨ toℕ-fromℕ< _ ⟩
toℕ x
∎ where
open ≡-Reasoning
x<y→fin-1 : {n : ℕ } → { x y : Fin (suc n)} → toℕ x < toℕ y → Fin n
x<y→fin-1 {n} {x} {y} lt = fromℕ< (≤-trans lt (fin≤n _ ))
x<y→fin-1-eq : {n : ℕ } → { x y : Fin (suc n)} → (lt : toℕ x < toℕ y ) → toℕ x ≡ toℕ (x<y→fin-1 lt )
x<y→fin-1-eq {n} {x} {y} lt = sym ( begin
toℕ (fromℕ< (≤-trans lt (fin≤n y)) ) ≡⟨ toℕ-fromℕ< _ ⟩
toℕ x ∎ ) where open ≡-Reasoning
f<→< : {n : ℕ } → { x y : Fin n} → x Data.Fin.< y → toℕ x < toℕ y
f<→< {_} {zero} {suc y} (s≤s lt) = s≤s z≤n
f<→< {_} {suc x} {suc y} (s≤s lt) = s≤s (f<→< {_} {x} {y} lt)
f≡→≡ : {n : ℕ } → { x y : Fin n} → x ≡ y → toℕ x ≡ toℕ y
f≡→≡ refl = refl
open import Data.List
open import Relation.Binary.Definitions
-- fin-count : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → ℕ
-- fin-count q p[ = 0
-- fin-count q (q0 ∷ qs ) with <-fcmp q q0
-- ... | tri-e = suc (fin-count q qs)
-- ... | false = fin-count q qs
-- fin-not-dup-in-list : { n : ℕ} (qs : List (Fin n) ) → Set
-- fin-not-dup-in-list {n} qs = (q : Fin n) → fin-count q ≤ 1
-- this is far easier
-- fin-not-dup-in-list→len<n : { n : ℕ} (qs : List (Fin n) ) → ( (q : Fin n) → fin-not-dup-in-list qs q) → length qs ≤ n
-- fin-not-dup-in-list→len<n = ?
fin-phase2 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
fin-phase2 q [] = false
fin-phase2 q (x ∷ qs) with <-fcmp q x
... | tri< a ¬b ¬c = fin-phase2 q qs
... | tri≈ ¬a b ¬c = true
... | tri> ¬a ¬b c = fin-phase2 q qs
fin-phase1 : { n : ℕ } (q : Fin n) (qs : List (Fin n) ) → Bool
fin-phase1 q [] = false
fin-phase1 q (x ∷ qs) with <-fcmp q x
... | tri< a ¬b ¬c = fin-phase1 q qs
... | tri≈ ¬a b ¬c = fin-phase2 q qs
... | tri> ¬a ¬b c = fin-phase1 q qs
fin-dup-in-list : { n : ℕ} (q : Fin n) (qs : List (Fin n) ) → Bool
fin-dup-in-list {n} q qs = fin-phase1 q qs
record FDup-in-list (n : ℕ ) (qs : List (Fin n)) : Set where
field
dup : Fin n
is-dup : fin-dup-in-list dup qs ≡ true
list-less : {n : ℕ } → List (Fin (suc n)) → List (Fin n)
list-less [] = []
list-less {n} (i ∷ ls) with <-fcmp (fromℕ< a<sa) i
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ i < suc k ) (sym fin<asa) (fin≤n _ )))
... | tri≈ ¬a b ¬c = list-less ls
... | tri> ¬a ¬b c = x<y→fin-1 c ∷ list-less ls
fin010 : {n m : ℕ } {x : Fin n} (c : suc (toℕ x) ≤ toℕ (fromℕ< {m} a<sa) ) → toℕ (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) ≡ toℕ x
fin010 {_} {_} {x} c = begin
toℕ (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) ≡⟨ toℕ-fromℕ< _ ⟩
toℕ x ∎ where open ≡-Reasoning
---
--- if List (Fin n) is longer than n, there is at most one duplication
---
fin-dup-in-list>n : {n : ℕ } → (qs : List (Fin n)) → (len> : length qs > n ) → FDup-in-list n qs
fin-dup-in-list>n {zero} [] ()
fin-dup-in-list>n {zero} (() ∷ qs) lt
fin-dup-in-list>n {suc n} qs lt = fdup-phase0 where
open import Level using ( Level )
-- make a dup from one level below
fdup+1 : (qs : List (Fin (suc n))) (i : Fin n) → fin-dup-in-list (fromℕ< a<sa ) qs ≡ false
→ fin-dup-in-list i (list-less qs) ≡ true → FDup-in-list (suc n) qs
fdup+1 qs i ne p = record { dup = fin+1 i ; is-dup = f1-phase1 qs p (case1 ne) } where
-- we have two loops on the max element and the current level. The disjuction means the phases may differ.
f1-phase2 : (qs : List (Fin (suc n)) ) → fin-phase2 i (list-less qs) ≡ true
→ (fin-phase1 (fromℕ< a<sa) qs ≡ false ) ∨ (fin-phase2 (fromℕ< a<sa) qs ≡ false)
→ fin-phase2 (fin+1 i) qs ≡ true
f1-phase2 (x ∷ qs) p (case1 q1) with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
f1-phase2 (x ∷ qs) p (case1 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
... | tri< a ¬b ¬c₁ = f1-phase2 qs p (case2 q1)
... | tri≈ ¬a₁ b₁ ¬c₁ = refl
... | tri> ¬a₁ ¬b c = f1-phase2 qs p (case2 q1)
-- two fcmp is only different in the size of Fin, but to develop both f1-phase and list-less both fcmps are required
f1-phase2 (x ∷ qs) p (case1 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase2 qs p (case1 q1)
... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = refl
... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase2 qs p (case1 q1)
f1-phase2 (x ∷ qs) p (case2 q1) with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
f1-phase2 (x ∷ qs) p (case2 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
... | tri< a ¬b ¬c₁ = ⊥-elim ( ¬-bool q1 refl )
... | tri≈ ¬a₁ b₁ ¬c₁ = refl
... | tri> ¬a₁ ¬b c = ⊥-elim ( ¬-bool q1 refl )
f1-phase2 (x ∷ qs) p (case2 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase2 qs p (case2 q1)
... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = refl
... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase2 qs p (case2 q1 )
f1-phase1 : (qs : List (Fin (suc n)) ) → fin-phase1 i (list-less qs) ≡ true
→ (fin-phase1 (fromℕ< a<sa) qs ≡ false ) ∨ (fin-phase2 (fromℕ< a<sa) qs ≡ false)
→ fin-phase1 (fin+1 i) qs ≡ true
f1-phase1 (x ∷ qs) p (case1 q1) with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
f1-phase1 (x ∷ qs) p (case1 q1) | tri≈ ¬a b ¬c with <-fcmp (fin+1 i) x
... | tri< a ¬b ¬c₁ = f1-phase1 qs p (case2 q1)
... | tri≈ ¬a₁ b₁ ¬c₁ = ⊥-elim (fdup-10 b b₁) where
fdup-10 : fromℕ< a<sa ≡ x → fin+1 i ≡ x → ⊥
fdup-10 eq eq1 = nat-≡< (cong toℕ (trans eq1 (sym eq))) (subst₂ (λ j k → j < k ) (sym fin+1-toℕ) (sym fin<asa) fin<n )
... | tri> ¬a₁ ¬b c = f1-phase1 qs p (case2 q1)
f1-phase1 (x ∷ qs) p (case1 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase1 qs p (case1 q1)
... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = f1-phase2 qs p (case1 q1)
... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase1 qs p (case1 q1)
f1-phase1 (x ∷ qs) p (case2 q1) with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
f1-phase1 (x ∷ qs) p (case2 q1) | tri≈ ¬a b ¬c = ⊥-elim ( ¬-bool q1 refl )
f1-phase1 (x ∷ qs) p (case2 q1) | tri> ¬a ¬b c with <-fcmp i (fromℕ< (≤-trans c (fin≤n (fromℕ< a<sa)))) | <-fcmp (fin+1 i) x
... | tri< a ¬b₁ ¬c | tri< a₁ ¬b₂ ¬c₁ = f1-phase1 qs p (case2 q1)
... | tri< a ¬b₁ ¬c | tri≈ ¬a₁ b ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri< a ¬b₁ ¬c | tri> ¬a₁ ¬b₂ c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) (sym fin+1-toℕ) (toℕ-fromℕ< _) a ))
... | tri≈ ¬a₁ b ¬c | tri< a ¬b₁ ¬c₁ = ⊥-elim ( ¬a₁ (subst₂ (λ j k → j < k) fin+1-toℕ (sym (toℕ-fromℕ< _)) a ))
... | tri≈ ¬a₁ b ¬c | tri≈ ¬a₂ b₁ ¬c₁ = f1-phase2 qs p (case2 q1)
... | tri≈ ¬a₁ b ¬c | tri> ¬a₂ ¬b₁ c₁ = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) fin+1-toℕ (sym (toℕ-fromℕ< _)) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri< a ¬b₂ ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri≈ ¬a₂ b ¬c = ⊥-elim ( ¬c (subst₂ (λ j k → j > k) (sym fin+1-toℕ) (toℕ-fromℕ< _) c₁ ))
... | tri> ¬a₁ ¬b₁ c₁ | tri> ¬a₂ ¬b₂ c₂ = f1-phase1 qs p (case2 q1)
fdup-phase0 : FDup-in-list (suc n) qs
fdup-phase0 with fin-dup-in-list (fromℕ< a<sa) qs | inspect (fin-dup-in-list (fromℕ< a<sa)) qs
... | true | record { eq = eq } = record { dup = fromℕ< a<sa ; is-dup = eq }
... | false | record { eq = ne } = fdup+1 qs (FDup-in-list.dup fdup) ne (FDup-in-list.is-dup fdup) where
-- if no dup in the max element, the list without the element is only one length shorter
fless : (qs : List (Fin (suc n))) → length qs > suc n → fin-dup-in-list (fromℕ< a<sa) qs ≡ false → n < length (list-less qs)
fless qs lt p = fl-phase1 n qs lt p where
fl-phase2 : (n1 : ℕ) (qs : List (Fin (suc n))) → length qs > n1 → fin-phase2 (fromℕ< a<sa) qs ≡ false → n1 < length (list-less qs)
fl-phase2 zero (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
... | tri> ¬a ¬b c = s≤s z≤n
fl-phase2 (suc n1) (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
... | tri> ¬a ¬b c = s≤s ( fl-phase2 n1 qs lt p )
fl-phase1 : (n1 : ℕ) (qs : List (Fin (suc n))) → length qs > suc n1 → fin-phase1 (fromℕ< a<sa) qs ≡ false → n1 < length (list-less qs)
fl-phase1 zero (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
... | tri≈ ¬a b ¬c = fl-phase2 0 qs lt p
... | tri> ¬a ¬b c = s≤s z≤n
fl-phase1 (suc n1) (x ∷ qs) (s≤s lt) p with <-fcmp (fromℕ< a<sa) x
... | tri< a ¬b ¬c = ⊥-elim ( nat-≤> a (subst (λ k → toℕ x < suc k ) (sym fin<asa) (fin≤n _ )))
... | tri≈ ¬a b ¬c = fl-phase2 (suc n1) qs lt p
... | tri> ¬a ¬b c = s≤s ( fl-phase1 n1 qs lt p )
-- if the list without the max element is only one length shorter, we can recurse
fdup : FDup-in-list n (list-less qs)
fdup = fin-dup-in-list>n (list-less qs) (fless qs lt ne)
|
{
"alphanum_fraction": 0.4784482759,
"avg_line_length": 56.8,
"ext": "agda",
"hexsha": "00718934399ad12be87558781600828b061375f1",
"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": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/fin.agda",
"max_line_length": 151,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/fin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7671,
"size": 16472
}
|
open import Level using (Level; suc; zero; _⊔_)
open import Function using (const)
open import Algebra
open import Algebra.Structures
open import Algebra.OrderedMonoid
open import Algebra.FunctionProperties as FunctionProperties using (Op₁; Op₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Relation.Binary
open import Relation.Binary.PartialOrderReasoning as ≤-Reasoning using ()
module Algebra.Pregroup where
-- Definition of the properties of left and right contraction and
-- expansion for usage in the below definition of pregroups.
module AdjointProperties {a ℓ} {A : Set a} (_≤_ : Rel A ℓ) (_∙_ : Op₂ A) (ε : A) where
LeftContract : Op₁ A → Set _
LeftContract _ˡ = ∀ x → (x ˡ ∙ x) ≤ ε
LeftExpand : Op₁ A → Set _
LeftExpand _ˡ = ∀ x → ε ≤ (x ∙ x ˡ)
RightContract : Op₁ A → Set _
RightContract _ʳ = ∀ x → (x ∙ x ʳ) ≤ ε
RightExpand : Op₁ A → Set _
RightExpand _ʳ = ∀ x → ε ≤ (x ʳ ∙ x)
-- define shorthand notation for a term being the left/right adjoint
-- of another term, which can be proven to be unique.
_LeftAdjointOf_ : ∀ y x → Set _
_LeftAdjointOf_ y x = (y ∙ x) ≤ ε × ε ≤ (x ∙ y)
_RightAdjointOf_ : ∀ y x → Set _
_RightAdjointOf_ y x = (x ∙ y) ≤ ε × ε ≤ (y ∙ x)
-- Definition of a pregroup, which adds a left and a right adjoint to
-- an ordered monoid.
record IsPregroup {a ℓ₁ ℓ₂} {A : Set a} (≈ : Rel A ℓ₁) (≤ : Rel A ℓ₂)
(∙ : Op₂ A) (ε : A) (ˡ : Op₁ A) (ʳ : Op₁ A) : Set (a ⊔ ℓ₁ ⊔ ℓ₂) where
open AdjointProperties ≤ ∙ ε
field
isOrderedMonoid : IsOrderedMonoid ≈ ≤ ∙ ε
ˡ-cong : ˡ Preserves ≈ ⟶ ≈
ʳ-cong : ʳ Preserves ≈ ⟶ ≈
ˡ-contract : LeftContract ˡ
ˡ-expand : LeftExpand ˡ
ʳ-contract : RightContract ʳ
ʳ-expand : RightExpand ʳ
open IsOrderedMonoid isOrderedMonoid public
open AdjointProperties ≤ ∙ ε public
record Pregroup c ℓ₁ ℓ₂ : Set (suc (c ⊔ ℓ₁ ⊔ ℓ₂)) where
infixl 7 _∙_
infix 4 _≈_
infix 4 _≤_
field
Carrier : Set c
_≈_ : Rel Carrier ℓ₁
_≤_ : Rel Carrier ℓ₂
_∙_ : Op₂ Carrier
_ˡ : Op₁ Carrier
_ʳ : Op₁ Carrier
ε : Carrier
isPregroup : IsPregroup _≈_ _≤_ _∙_ ε _ˡ _ʳ
open IsPregroup isPregroup public
private
-- for usage with ≤-Reasoning
poset : Poset c ℓ₁ ℓ₂
poset = record { isPartialOrder = isPartialOrder }
open ≤-Reasoning poset
-- for usage of substitutivity (which is not defined in IsPregroup)
orderedMonoid : OrderedMonoid _ _ _
orderedMonoid = record { isOrderedMonoid = isOrderedMonoid }
open OrderedMonoid orderedMonoid public using (substitutivity)
ˡ-unique : ∀ {x y} → y LeftAdjointOf x → y ≈ x ˡ
ˡ-unique {x} {y} (y-contract , y-expand) = antisym y≤xˡ xˡ≤y
where
y≤xˡ : y ≤ x ˡ
y≤xˡ =
begin
y ≈⟨ sym (proj₂ identity y) ⟩
y ∙ ε ≤⟨ compatibility ≤-refl (ˡ-expand x) ⟩
y ∙ (x ∙ x ˡ) ≈⟨ sym (assoc y x (x ˡ)) ⟩
(y ∙ x) ∙ x ˡ ≤⟨ compatibility y-contract ≤-refl ⟩
ε ∙ x ˡ ≈⟨ proj₁ identity (x ˡ) ⟩
x ˡ
∎
xˡ≤y : x ˡ ≤ y
xˡ≤y =
begin
x ˡ ≈⟨ sym (proj₂ identity (x ˡ)) ⟩
x ˡ ∙ ε ≤⟨ compatibility ≤-refl y-expand ⟩
x ˡ ∙ (x ∙ y) ≈⟨ sym (assoc (x ˡ) x y) ⟩
(x ˡ ∙ x) ∙ y ≤⟨ compatibility (ˡ-contract x) ≤-refl ⟩
ε ∙ y ≈⟨ proj₁ identity y ⟩
y
∎
ʳ-unique : ∀ {x y} → y RightAdjointOf x → y ≈ x ʳ
ʳ-unique {x} {y} (y-contract , y-expand) = antisym y≤xʳ xʳ≤y
where
xʳ≤y : x ʳ ≤ y
xʳ≤y =
begin
x ʳ ≈⟨ sym (proj₁ identity (x ʳ)) ⟩
ε ∙ x ʳ ≤⟨ compatibility y-expand ≤-refl ⟩
(y ∙ x) ∙ x ʳ ≈⟨ assoc y x (x ʳ) ⟩
y ∙ (x ∙ x ʳ) ≤⟨ compatibility ≤-refl (ʳ-contract x) ⟩
y ∙ ε ≈⟨ proj₂ identity y ⟩
y
∎
y≤xʳ : y ≤ x ʳ
y≤xʳ =
begin
y ≈⟨ sym (proj₁ identity y) ⟩
ε ∙ y ≤⟨ compatibility (ʳ-expand x) ≤-refl ⟩
(x ʳ ∙ x) ∙ y ≈⟨ assoc (x ʳ) x y ⟩
x ʳ ∙ (x ∙ y) ≤⟨ compatibility ≤-refl y-contract ⟩
x ʳ ∙ ε ≈⟨ proj₂ identity (x ʳ) ⟩
x ʳ
∎
ˡ-identity : ε ˡ ≈ ε
ˡ-identity = antisym εˡ≤ε ε≤εˡ
where
εˡ≤ε : ε ˡ ≤ ε
εˡ≤ε =
begin
ε ˡ ≈⟨ sym (proj₂ identity (ε ˡ)) ⟩
ε ˡ ∙ ε ≤⟨ ˡ-contract ε ⟩
ε
∎
ε≤εˡ : ε ≤ ε ˡ
ε≤εˡ =
begin
ε ≤⟨ ˡ-expand ε ⟩
ε ∙ ε ˡ ≈⟨ proj₁ identity (ε ˡ) ⟩
ε ˡ
∎
ʳ-identity : ε ʳ ≈ ε
ʳ-identity = antisym εʳ≤ε ε≤εʳ
where
εʳ≤ε : ε ʳ ≤ ε
εʳ≤ε =
begin
ε ʳ ≈⟨ sym (proj₁ identity (ε ʳ)) ⟩
ε ∙ ε ʳ ≤⟨ ʳ-contract ε ⟩
ε
∎
ε≤εʳ : ε ≤ ε ʳ
ε≤εʳ =
begin
ε ≤⟨ ʳ-expand ε ⟩
ε ʳ ∙ ε ≈⟨ proj₂ identity (ε ʳ) ⟩
ε ʳ
∎
ˡ-distrib : ∀ x y → y ˡ ∙ x ˡ ≈ (x ∙ y) ˡ
ˡ-distrib x y = ˡ-unique ([yˡxˡ][xy]≤ε , ε≤[xy][yˡxˡ])
where
[yˡxˡ][xy]≤ε : (y ˡ ∙ x ˡ) ∙ (x ∙ y) ≤ ε
[yˡxˡ][xy]≤ε =
begin
(y ˡ ∙ x ˡ) ∙ (x ∙ y) ≈⟨ sym (assoc (y ˡ ∙ x ˡ) x y) ⟩
((y ˡ ∙ x ˡ) ∙ x) ∙ y ≈⟨ ∙-cong (assoc (y ˡ) (x ˡ) x) refl ⟩
(y ˡ ∙ (x ˡ ∙ x)) ∙ y ≤⟨ compatibility (compatibility ≤-refl (ˡ-contract x)) ≤-refl ⟩
y ˡ ∙ ε ∙ y ≈⟨ ∙-cong (proj₂ identity (y ˡ)) refl ⟩
y ˡ ∙ y ≤⟨ ˡ-contract y ⟩
ε
∎
ε≤[xy][yˡxˡ] : ε ≤ (x ∙ y) ∙ (y ˡ ∙ x ˡ)
ε≤[xy][yˡxˡ] =
begin
ε ≤⟨ ˡ-expand x ⟩
x ∙ x ˡ ≈⟨ ∙-cong (sym (proj₂ identity x)) refl ⟩
x ∙ ε ∙ x ˡ ≤⟨ compatibility (compatibility ≤-refl (ˡ-expand y)) ≤-refl ⟩
(x ∙ (y ∙ y ˡ) ∙ x ˡ) ≈⟨ ∙-cong (sym (assoc x y (y ˡ))) refl ⟩
((x ∙ y) ∙ y ˡ) ∙ x ˡ ≈⟨ assoc (x ∙ y) (y ˡ) (x ˡ) ⟩
(x ∙ y) ∙ (y ˡ ∙ x ˡ)
∎
ʳ-distrib : ∀ x y → y ʳ ∙ x ʳ ≈ (x ∙ y) ʳ
ʳ-distrib x y = ʳ-unique ([xy][yʳxʳ]≤ε , ε≤[xy][yʳxʳ])
where
[xy][yʳxʳ]≤ε : (x ∙ y) ∙ (y ʳ ∙ x ʳ) ≤ ε
[xy][yʳxʳ]≤ε =
begin
(x ∙ y) ∙ (y ʳ ∙ x ʳ) ≈⟨ sym (assoc (x ∙ y) (y ʳ) (x ʳ)) ⟩
((x ∙ y) ∙ y ʳ) ∙ x ʳ ≈⟨ ∙-cong (assoc x y (y ʳ)) refl ⟩
(x ∙ (y ∙ y ʳ) ∙ x ʳ) ≤⟨ compatibility (compatibility ≤-refl (ʳ-contract y)) ≤-refl ⟩
x ∙ ε ∙ x ʳ ≈⟨ ∙-cong (proj₂ identity x) refl ⟩
x ∙ x ʳ ≤⟨ ʳ-contract x ⟩
ε
∎
ε≤[xy][yʳxʳ] : ε ≤ (y ʳ ∙ x ʳ) ∙ (x ∙ y)
ε≤[xy][yʳxʳ] =
begin
ε ≤⟨ ʳ-expand y ⟩
y ʳ ∙ y ≈⟨ ∙-cong refl (sym (proj₁ identity y)) ⟩
y ʳ ∙ (ε ∙ y) ≤⟨ compatibility ≤-refl (compatibility (ʳ-expand x) ≤-refl) ⟩
y ʳ ∙ ((x ʳ ∙ x) ∙ y) ≈⟨ ∙-cong refl (assoc (x ʳ) x y) ⟩
y ʳ ∙ (x ʳ ∙ (x ∙ y)) ≈⟨ sym (assoc (y ʳ) (x ʳ) (x ∙ y)) ⟩
(y ʳ ∙ x ʳ) ∙ (x ∙ y)
∎
ˡ-contra : ∀ {x y} → x ≤ y → y ˡ ≤ x ˡ
ˡ-contra {x} {y} x≤y =
begin
y ˡ ≈⟨ sym (proj₂ identity (y ˡ)) ⟩
y ˡ ∙ ε ≤⟨ compatibility ≤-refl (ˡ-expand x) ⟩
y ˡ ∙ (x ∙ x ˡ) ≈⟨ sym (assoc (y ˡ) x (x ˡ)) ⟩
(y ˡ ∙ x) ∙ x ˡ ≤⟨ substitutivity x≤y ⟩
(y ˡ ∙ y) ∙ x ˡ ≤⟨ compatibility (ˡ-contract y) ≤-refl ⟩
ε ∙ x ˡ ≈⟨ proj₁ identity (x ˡ) ⟩
x ˡ
∎
ʳ-contra : ∀ {x y} → x ≤ y → y ʳ ≤ x ʳ
ʳ-contra {x} {y} x≤y =
begin
y ʳ ≈⟨ sym (proj₁ identity (y ʳ)) ⟩
ε ∙ y ʳ ≤⟨ compatibility (ʳ-expand x) ≤-refl ⟩
(x ʳ ∙ x) ∙ y ʳ ≤⟨ substitutivity x≤y ⟩
(x ʳ ∙ y) ∙ y ʳ ≈⟨ assoc (x ʳ) y (y ʳ) ⟩
x ʳ ∙ (y ∙ y ʳ) ≤⟨ compatibility ≤-refl (ʳ-contract y) ⟩
x ʳ ∙ ε ≈⟨ proj₂ identity (x ʳ) ⟩
x ʳ
∎
ʳˡ-cancel : ∀ x → x ʳ ˡ ≈ x
ʳˡ-cancel x = sym (ˡ-unique (ʳ-contract x , ʳ-expand x))
ˡʳ-cancel : ∀ x → x ˡ ʳ ≈ x
ˡʳ-cancel x = sym (ʳ-unique (ˡ-contract x , ˡ-expand x))
|
{
"alphanum_fraction": 0.4631398482,
"avg_line_length": 33.1951219512,
"ext": "agda",
"hexsha": "37b2806292719dc215f5e6e6d7ad5d17c0f77719",
"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": "2cc4f28f23cc369d2582ad065739cabfa46ce799",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wenkokke/agda-pregroup",
"max_forks_repo_path": "Algebra/Pregroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2cc4f28f23cc369d2582ad065739cabfa46ce799",
"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": "wenkokke/agda-pregroup",
"max_issues_repo_path": "Algebra/Pregroup.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "2cc4f28f23cc369d2582ad065739cabfa46ce799",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/agda-pregroup",
"max_stars_repo_path": "Algebra/Pregroup.agda",
"max_stars_repo_stars_event_max_datetime": "2017-03-02T01:23:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-02T01:23:52.000Z",
"num_tokens": 3836,
"size": 8166
}
|
--------------------------------------------------------------------------------
-- This is part of Agda Inference Systems
{-# OPTIONS --sized-types --guardedness #-}
open import Data.Nat
open import Data.Vec
open import Data.Product
open import Data.Sum
open import Data.Fin
open import Relation.Binary.PropositionalEquality
open import Data.Unit
open import Data.Bool
open import Data.Empty
open import Codata.Colist
open import Codata.Thunk
open import Size
open import Examples.Colists.Auxiliary.Colist_member
open import Examples.Colists.Auxiliary.MaxOf
open import is-lib.InfSys
module Examples.Colists.Max where
U = ℕ × Colist ℕ ∞
data maxElemRN : Set where
max-h max-t : maxElemRN
data maxElemCoRN : Set where
co-max-h : maxElemCoRN
max-h-r : FinMetaRule U
max-h-r .Ctx = Σ[ (_ , xs) ∈ ℕ × Thunk (Colist ℕ) ∞ ] xs .force ≡ []
max-h-r .comp ((x , xs) , _) =
[] ,
--------------
(x , x ∷ xs)
max-t-r : FinMetaRule U
max-t-r .Ctx = Σ[ (x , y , z , _) ∈ ℕ × ℕ × ℕ × Thunk (Colist ℕ) ∞ ] z ≡ max x y
max-t-r .comp ((x , y , z , xs) , _) =
(x , xs .force) ∷ [] ,
--------------
(z , y ∷ xs)
co-max-h-r : FinMetaRule U
co-max-h-r .Ctx = ℕ × Thunk (Colist ℕ) ∞
co-max-h-r .comp (x , xs) =
[] ,
--------------
(x , x ∷ xs)
maxElemIS : IS U
maxElemIS .Names = maxElemRN
maxElemIS .rules max-h = from max-h-r
maxElemIS .rules max-t = from max-t-r
maxElemCoIS : IS U
maxElemCoIS .Names = maxElemCoRN
maxElemCoIS .rules co-max-h = from co-max-h-r
_maxElem_ : ℕ → Colist ℕ ∞ → Set
x maxElem xs = FCoInd⟦ maxElemIS , maxElemCoIS ⟧ (x , xs)
_maxElemᵢ_ : ℕ → Colist ℕ ∞ → Set
x maxElemᵢ xs = Ind⟦ maxElemIS ∪ maxElemCoIS ⟧ (x , xs)
maxSpec inSpec geqSpec : U → Set
inSpec (x , xs) = x ∈ xs
geqSpec (x , xs) = ∀{n} → n ∈ xs → x ≡ max x n
maxSpec u = inSpec u × geqSpec u
maxElemSound-in-ind : ∀{x xs} → x maxElemᵢ xs → inSpec (x , xs)
maxElemSound-in-ind (fold (inj₁ max-h , _ , refl , _)) = here
maxElemSound-in-ind (fold (inj₁ max-t , (_ , eq) , refl , prem)) with max-refl-eq eq
maxElemSound-in-ind (fold (inj₁ max-t , (_ , eq) , refl , prem)) | inj₁ refl = there (maxElemSound-in-ind (prem zero))
maxElemSound-in-ind (fold (inj₁ max-t , (_ , eq) , refl , prem)) | inj₂ refl = here
maxElemSound-in-ind (fold (inj₂ co-max-h , _ , refl , _)) = here
maxElemSound-in : ∀{x xs} → x maxElem xs → inSpec (x , xs)
maxElemSound-in max = maxElemSound-in-ind (fcoind-to-ind max)
maxElemSound-gr : ∀{x xs} → x maxElem xs → geqSpec (x , xs)
maxElemSound-gr max here with max .CoInd⟦_⟧.unfold
maxElemSound-gr max here | max-h , _ , refl , _ = max-self
maxElemSound-gr max here | max-t , ((_ , eq) , _) , refl , _ with max-refl-eq eq
... | inj₁ refl = eq
... | inj₂ refl = max-self
maxElemSound-gr max (there mem) with max .CoInd⟦_⟧.unfold
maxElemSound-gr max (there mem) | max-h , ((_ , eq) , _) , refl , _ = ⊥-elim (mem-abs mem eq)
maxElemSound-gr max (there mem) | max-t , ((_ , eq) , _) , refl , pr with max-refl-eq eq
... | inj₁ refl = maxElemSound-gr (pr zero) mem
... | inj₂ refl =
let rec = maxElemSound-gr (pr zero) mem in
max-trans rec (max-comm eq)
maxElemSound : ∀{x xs} → x maxElem xs → maxSpec (x , xs)
maxElemSound max = maxElemSound-in max , maxElemSound-gr max
maxSpecBounded : ∀{x xs} → inSpec (x , xs) → geqSpec (x , xs) → x maxElemᵢ xs
maxSpecBounded here _ = apply-ind (inj₂ co-max-h) _ λ ()
maxSpecBounded (there mem) gr = apply-ind (inj₁ max-t) (_ , gr here) λ{zero → maxSpecBounded mem λ m → gr (there m)}
postulate
old-max : ∀{n x y xs ys} → Thunk.force xs ≡ (y ∷ ys) →
maxSpec (n , (x ∷ xs)) → Σ[ m ∈ ℕ ] maxSpec (m , (y ∷ ys))
maxSpecCons : ∀{x xs} → inSpec (x , xs) → geqSpec (x , xs) → ISF[ maxElemIS ] maxSpec (x , xs)
maxSpecCons {x} {x ∷ xs} here gr with xs .force | inspect (λ t → t .force) xs
maxSpecCons {x} {x ∷ xs} here gr | [] | [ eq ] = max-h , (_ , eq) , refl , λ ()
maxSpecCons {x} {x ∷ xs} here gr | _ ∷ _ | [ eq ] =
let old , mem , gr' = old-max eq (here , gr) in
let mem-xs = subst (λ xs → old ∈ xs) (sym eq) mem in
max-t , (_ , max-comm (gr (there mem-xs))) , refl , λ{zero → mem-xs , λ m → gr' (subst (λ xs → _ ∈ xs) eq m)}
maxSpecCons {x} {.(_ ∷ _)} (there mem) gr = max-t , (_ , gr here) , refl , λ{zero → mem , λ m → gr (there m)}
maxElemComplete : ∀{x xs} → maxSpec (x , xs) → x maxElem xs
maxElemComplete =
bounded-coind[ maxElemIS , maxElemCoIS ] maxSpec (λ{(x , xs) → maxSpecBounded x xs}) λ{(x , xs) → maxSpecCons x xs}
|
{
"alphanum_fraction": 0.5857485291,
"avg_line_length": 37.6147540984,
"ext": "agda",
"hexsha": "f2479bdb9e134cca8567b6d07c01612a3c5db120",
"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": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "LcicC/inference-systems-agda",
"max_forks_repo_path": "Examples/Colists/Max.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"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": "LcicC/inference-systems-agda",
"max_issues_repo_path": "Examples/Colists/Max.agda",
"max_line_length": 120,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "b9043f99e4bf7211db4066a7a943401d127f0c8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "LcicC/inference-systems-agda",
"max_stars_repo_path": "Examples/Colists/Max.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-25T15:48:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-10T15:53:47.000Z",
"num_tokens": 1658,
"size": 4589
}
|
------------------------------------------------------------------------
-- A stream equality universe
------------------------------------------------------------------------
module Stream.Equality where
open import Codata.Musical.Notation
open import Stream hiding (_⋎_)
open import Stream.Programs
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Data.Vec using (Vec; []; _∷_)
infixr 5 _≺_
infix 3 _≃_ _≅_ _≊_ _∎
infixr 2 _≊⟨_⟩_ _≡⟨_⟩_
mutual
_≊_ : ∀ {A} (xs ys : Prog A) → Set1
xs ≊ ys = ⟦ xs ⟧ ≅ ⟦ ys ⟧
data _≅_ {A} : (xs ys : Stream A) → Set1 where
_≺_ : ∀ {x y xs ys}
(x≡ : x ≡ y) (xs≈ : ∞ (♭ xs ≅ ♭ ys)) →
x ≺ xs ≅ y ≺ ys
_≊⟨_⟩_ : ∀ xs {ys zs}
(xs≈ys : ⟦ xs ⟧ ≅ ys) (ys≈zs : ys ≅ zs) → ⟦ xs ⟧ ≅ zs
_≡⟨_⟩_ : ∀ xs {ys zs}
(xs≡ys : ⟦ xs ⟧ ≡ ys) (ys≈zs : ys ≅ zs) → ⟦ xs ⟧ ≅ zs
≅-sym : ∀ {xs ys} (xs≈ys : xs ≅ ys) → ys ≅ xs
·-cong : ∀ {B}
(f : B → A) xs ys (xs≈ys : xs ≊ ys) →
f · xs ≊ f · ys
⟨_⟩-cong : ∀ {B C} (_∙_ : B → C → A)
xs xs′ (xs≈xs′ : xs ≊ xs′)
ys ys′ (ys≈ys′ : ys ≊ ys′) →
xs ⟨ _∙_ ⟩ ys ≊ xs′ ⟨ _∙_ ⟩ ys′
⋎-cong : ∀ xs xs′ (xs≈xs′ : xs ≊ xs′)
ys ys′ (ys≈ys′ : ys ≊ ys′) →
xs ⋎ ys ≊ xs′ ⋎ ys′
≺≺-cong : ∀ {n}
(xs xs′ : Vec A n) (xs≡xs′ : xs ≡ xs′)
ys ys′ (ys≈ys′ : ys ≊ ys′) →
xs ≺≺ ys ≊ xs′ ≺≺ ys′
data _≃_ {A} : (xs ys : Stream A) → Set1 where
_≺_ : ∀ {x y xs ys}
(x≡ : x ≡ y) (xs≈ : ♭ xs ≅ ♭ ys) → x ≺ xs ≃ y ≺ ys
≅⇒≃ : ∀ {A} {xs ys : Stream A} → xs ≅ ys → xs ≃ ys
≅⇒≃ (x≡ ≺ xs≈) = x≡ ≺ ♭ xs≈
≅⇒≃ (xs ≊⟨ xs≈ys ⟩ ys≈zs) with whnf xs | ≅⇒≃ xs≈ys | ≅⇒≃ ys≈zs
≅⇒≃ (xs ≊⟨ xs≈ys ⟩ ys≈zs) | x ≺ xs′ | x≡y ≺ xs≈ys′ | y≡z ≺ ys≈zs′ =
trans x≡y y≡z ≺ (xs′ ≊⟨ xs≈ys′ ⟩ ys≈zs′)
≅⇒≃ (xs ≡⟨ refl ⟩ ys≈zs) = ≅⇒≃ ys≈zs
≅⇒≃ (≅-sym xs≈ys) with ≅⇒≃ xs≈ys
≅⇒≃ (≅-sym xs≈ys) | x≡y ≺ xs≈ys′ = sym x≡y ≺ ≅-sym xs≈ys′
≅⇒≃ (·-cong f xs ys xs≈ys) with whnf xs | whnf ys | ≅⇒≃ xs≈ys
≅⇒≃ (·-cong f xs ys xs≈ys) | x ≺ xs′ | y ≺ ys′ | x≡y ≺ xs≈ys′ =
cong f x≡y ≺ ·-cong f xs′ ys′ xs≈ys′
≅⇒≃ (⟨ ∙ ⟩-cong xs xs′ xs≈xs′
ys ys′ ys≈ys′) with whnf xs | whnf xs′ | ≅⇒≃ xs≈xs′
| whnf ys | whnf ys′ | ≅⇒≃ ys≈ys′
≅⇒≃ (⟨ ∙ ⟩-cong xs xs′ xs≈xs′
ys ys′ ys≈ys′) | _ ≺ txs | _ ≺ txs′ | x≡y ≺ txs≈txs′
| _ ≺ tys | _ ≺ tys′ | x≡y′ ≺ tys≈tys′ =
cong₂ ∙ x≡y x≡y′ ≺
⟨ ∙ ⟩-cong txs txs′ txs≈txs′
tys tys′ tys≈tys′
≅⇒≃ (⋎-cong xs xs′ xs≈xs′
ys ys′ ys≈ys′) with whnf xs | whnf xs′ | ≅⇒≃ xs≈xs′
≅⇒≃ (⋎-cong xs xs′ xs≈xs′
ys ys′ ys≈ys′) | _ ≺ txs | _ ≺ txs′ | x≡y ≺ txs≈txs′ =
x≡y ≺ ⋎-cong ys ys′ ys≈ys′
txs txs′ txs≈txs′
≅⇒≃ (≺≺-cong [] [] refl
ys ys′ ys≈ys′) = ≅⇒≃ ys≈ys′
≅⇒≃ (≺≺-cong
(x ∷ xs) .(_ ∷ _) refl
ys ys′ ys≈ys′) = refl ≺ ≺≺-cong xs xs refl ys ys′ ys≈ys′
mutual
≃⇒≈ : ∀ {A} {xs ys : Stream A} → xs ≃ ys → xs ≈ ys
≃⇒≈ (refl ≺ xs≈) = refl ≺ ♯ ≅⇒≈ xs≈
≅⇒≈ : ∀ {A} {xs ys : Stream A} → xs ≅ ys → xs ≈ ys
≅⇒≈ xs≈ = ≃⇒≈ (≅⇒≃ xs≈)
≊⇒≈ : ∀ {A} {xs ys : Prog A} → xs ≊ ys → ⟦ xs ⟧ ≈ ⟦ ys ⟧
≊⇒≈ = ≅⇒≈
≈⇒≅ : ∀ {A} {xs ys : Stream A} → xs ≈ ys → xs ≅ ys
≈⇒≅ (refl ≺ xs≈) = refl ≺ ♯ ≈⇒≅ (♭ xs≈)
_∎ : ∀ {A} (xs : Prog A) → xs ≊ xs
xs ∎ = ≈⇒≅ (Setoid.refl (Stream.setoid _))
≊-η : ∀ {A} (xs : Prog A) → xs ≊ headP xs ≺ ♯ tailP xs
≊-η xs with whnf xs
≊-η xs | x ≺ xs′ = refl ≺ ♯ (xs′ ∎)
|
{
"alphanum_fraction": 0.3421450151,
"avg_line_length": 38.5631067961,
"ext": "agda",
"hexsha": "b25970043ba1439b501a70c3e612e90b7d48ca69",
"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": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Stream/Equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"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/codata",
"max_issues_repo_path": "Stream/Equality.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Stream/Equality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1991,
"size": 3972
}
|
module sbconst2 where
open import Level renaming ( suc to succ ; zero to Zero )
open import Data.Nat
open import Data.Fin
open import Data.List
open import automaton
open import nfa
open import logic
open NAutomaton
open Automaton
open import Relation.Binary.PropositionalEquality hiding ( [_] )
open Bool
δconv : { Q : Set } { Σ : Set } → ( ( Q → Bool ) → Bool ) → ( nδ : Q → Σ → Q → Bool ) → (f : Q → Bool) → (i : Σ) → (Q → Bool)
δconv {Q} { Σ} exists nδ f i q = exists ( λ r → f r /\ nδ r i q )
subset-construction : { Q : Set } { Σ : Set } →
( ( Q → Bool ) → Bool ) →
(NAutomaton Q Σ ) → (Automaton (Q → Bool) Σ )
subset-construction {Q} { Σ} exists NFA = record {
δ = λ q x → δconv exists ( Nδ NFA ) q x
; aend = λ f → exists ( λ q → f q /\ Nend NFA q )
}
test4 = subset-construction existsS1 am2
test51 = accept test4 start1 ( i0 ∷ i1 ∷ i0 ∷ [] )
test61 = accept test4 start1 ( i1 ∷ i1 ∷ i1 ∷ [] )
subset-construction-lemma→ : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) →
(NFA : NAutomaton Q Σ ) → (astart : Q → Bool )
→ (x : List Σ)
→ Naccept NFA exists astart x ≡ true
→ accept ( subset-construction exists NFA ) astart x ≡ true
subset-construction-lemma→ {Q} {Σ} exists NFA astart x naccept = lemma1 x astart naccept where
lemma1 : (x : List Σ) → ( states : Q → Bool )
→ Naccept NFA exists states x ≡ true
→ accept ( subset-construction exists NFA ) states x ≡ true
lemma1 [] states naccept = naccept
lemma1 (h ∷ t ) states naccept = lemma1 t (δconv exists (Nδ NFA) states h) naccept
subset-construction-lemma← : { Q : Set } { Σ : Set } → (exists : ( Q → Bool ) → Bool ) →
(NFA : NAutomaton Q Σ ) → (astart : Q → Bool )
→ (x : List Σ)
→ accept ( subset-construction exists NFA ) astart x ≡ true
→ Naccept NFA exists astart x ≡ true
subset-construction-lemma← {Q} {Σ} exists NFA astart x saccept = lemma2 x astart saccept where
lemma2 : (x : List Σ) → ( states : Q → Bool )
→ accept ( subset-construction exists NFA ) states x ≡ true
→ Naccept NFA exists states x ≡ true
lemma2 [] states saccept = saccept
lemma2 (h ∷ t ) states saccept = lemma2 t (δconv exists (Nδ NFA) states h) saccept
|
{
"alphanum_fraction": 0.5997352162,
"avg_line_length": 40.4642857143,
"ext": "agda",
"hexsha": "d0918b929c485657077be8602d90e41040604ae7",
"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": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/automaton-in-agda",
"max_forks_repo_path": "src/sbconst2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/automaton-in-agda",
"max_issues_repo_path": "src/sbconst2.agda",
"max_line_length": 127,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "eba0538f088f3d0c0fedb19c47c081954fbc69cb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/automaton-in-agda",
"max_stars_repo_path": "src/sbconst2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 798,
"size": 2266
}
|
{-# OPTIONS --without-K #-}
module function where
open import function.core public
open import function.overloading public
open import function.isomorphism public
open import function.extensionality public
open import function.fibration public
|
{
"alphanum_fraction": 0.8285714286,
"avg_line_length": 27.2222222222,
"ext": "agda",
"hexsha": "9e773336d04e0abed8939d70d29b286a4cf69ad5",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "function.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "function.agda",
"max_line_length": 42,
"max_stars_count": 27,
"max_stars_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "HoTT/M-types",
"max_stars_repo_path": "function.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-09T07:26:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-14T15:47:03.000Z",
"num_tokens": 45,
"size": 245
}
|
{-# OPTIONS --copatterns #-}
{-# IMPORT Ex4Haskell #-}
{-# IMPORT System.IO #-}
module Ex4 where -- Conor: 8/20
{- I'm sorry I haven't quite finished setting this exercise yet, but by
the joy of version control, the rest of it can be merged in later
(quite soon). At least you can get cracking: I promise not to break
anything, just to add a bit more on the end.
The deadline for this is Friday of Week 12 (11 Dec).
It'd be good to get the marks in before Christmas, but if the end of
term is looking deadlinetastic, please open negotiations.
UPDATE: I had to work around a bug in Agda to get this finished, so
it took longer than I had hoped. I apologise, and will be flexible
with deadlines, consequently. Also, I had to tweak the setup for
cp a little, asking you to abstract out your definition of the
FinalState of cp. I need to refer to it in the later code. That may
cause a wee merge conflict, easily rectified with cut and paste.
-}
open import CS410-Prelude
open import CS410-Indexed
{-
data List (X : Set) : Set where -- X scopes over the whole declaration...
[] : List X -- ...so you can use it here...
_::_ : X -> List X -> List X -- ...and here.
infixr 3 _::_
{-# BUILTIN BOOL Two #-}
{-# BUILTIN TRUE tt #-}
{-# BUILTIN FALSE ff #-}
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _::_ #-}
{-# COMPILED_DATA List [] [] (:) #-}
postulate -- this means that we just suppose the following things exist...
Char : Set
String : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
primitive -- these are baked in; they even work!
primCharEquality : Char -> Char -> Two
primStringAppend : String -> String -> String
primStringToList : String -> List Char
primStringFromList : List Char -> String
-}
---------------------------------------------------------------------------
-- WRITING FILES, AN INTERFACE
---------------------------------------------------------------------------
{- If you possess the ability to open a file for writing, you might
have the following interface. -}
-- States
data WriteState : Set where
opened closed : WriteState -- do you currently have a file open or not?
-- Commands
data WriteC : WriteState -> Set where
openWrite : (fileName : String) -> WriteC closed
writeChar : Char -> WriteC opened
closeWrite : WriteC opened
-- Responses
WriteR : (j : WriteState)(c : WriteC j) -> Set
WriteR .closed (openWrite fileName) = WriteState -- we get told whether it worked
WriteR .opened (writeChar x) = One -- always works
WriteR .opened closeWrite = One -- always works
{- 4.1 Implement the following operation which determines the next
state. You should ensure that you can write characters only to
a successfully opened file, and that you can write as many as
you want. It should also be possible to insist that a process
closes its file. -} -- Conor: 1/1
writeNext : (j : WriteState)(c : WriteC j) -> WriteR j c -> WriteState
writeNext .closed (openWrite fileName) r = r
writeNext .opened (writeChar x) r = opened
writeNext .opened closeWrite r = closed
-- the file writing interface, assembled as an indexed container
WRITE : WriteState => WriteState
WRITE = WriteC <! WriteR / writeNext
---------------------------------------------------------------------------
-- READING FILES, AN INTERFACE
---------------------------------------------------------------------------
{- To read from a file, it should be open, and you shouldn't be at the
end of it. -}
-- States
data ReadState : Set where
opened : (eof : Two) -> ReadState -- eof is tt if we're at end of file
closed : ReadState
{- 4.2 Finish the READ implementation, in accordance with the description. -}
-- Conor: 2.5/3
-- Commands
data ReadC : ReadState -> Set where
openRead : (fileName : String) -> ReadC closed
-- needs a filename; might not open successfully;
-- might open an empty file
readChar : ReadC (opened ff)
-- makes sense only if we're not at end of file
-- and might take us to end of file
closeRead : (eof : Two) -> ReadC (opened eof)
-- makes sense only if the file is open
-- Responses
ReadR : (j : ReadState)(c : ReadC j) -> Set
ReadR .closed (openRead fileName) = ReadState
ReadR .(opened ff) readChar = Two -- Conor: the character read should also be given
ReadR .(opened eof) (closeRead eof) = One
-- next State; you need to make sure the response gives enough info
readNext : (j : ReadState)(c : ReadC j) -> ReadR j c -> ReadState
readNext .closed (openRead fileName) r = r
readNext .(opened ff) readChar r = opened r
readNext .(opened eof) (closeRead eof) r = closed
READ : ReadState => ReadState
READ = ReadC <! ReadR / readNext
---------------------------------------------------------------------------
-- COMBINING TWO INTERFACES WITH SHARED STATE
---------------------------------------------------------------------------
{- 4.3 Let's suppose we have two command-response interfaces which offer
different functionality for the same system. Correspondingly, we'll
have two indexed containers for the same index set. Show that you
can combine them into one indexed container which lets you choose a
command from either menu and evolves the state as specified by
whichever interface offered the chosen command.
-} -- Conor: 1/1
_=+=_ : {I : Set} -> I => I -> I => I -> I => I
(Shape <! Position / index) =+= (Shape1 <! Position1 / index1) =
(Shape +: Shape1) <!
(λ j → λ {(inl x) → Position j x; (inr x) -> Position1 j x }) /
(λ j → \{(inl x) → index j x ; (inr x) -> index1 j x})
-- {!λ {(inl x) Position → index j x Position ;(inl x) Position → index1 j x Position1 }!})
--_=+=_ : {I : Set} -> I => I -> I => I -> I => I
--(Shape <! Position / index) =+= (Shape1 <! Position1 / index1)
-- = (Shape +: Shape1) <!
-- (λ j → λ {(inl x) → Position j x; (inr x) -> Position1 j x }) /
-- (λ j x y → {! λ {?}!})
--
--(λ j x y → {!λ {(inl x) y → index j x y ;(inl x) y → index1 j x y }!})
--record _=>_ (I J : Set) : Set1 where
-- constructor _<!_/_
-- field
-- Shape : J -> Set
-- Position : (j : J) -> Shape j -> Set
-- index : (j : J)(s : Shape j) -> Position j s -> I
---------------------------------------------------------------------------
-- WHEN IGNORANCE IS BLISS, BIS
---------------------------------------------------------------------------
{- 4.4 If we have a command-response interface with index I representing
states of the system, show that we can index basically the same
commands and responses over a state, I * J, where the J is just
useless information which never changes. (This operation isn't
super-useful on its own, but it's handy in combination with other
things. -} -- Conor: 2/2
GrowR : {I J : Set} -> I => I -> (I * J) => (I * J)
GrowR (Shape <! Position / index)
= (λ z → Shape (fst z))
<! (λ j z → Position (fst j) z )
/ (λ j s x → index (fst j) s x , snd j)
-- do the same for "growing the index on the left"
GrowL : {I J : Set} -> I => I -> (J * I) => (J * I)
GrowL (Shape <! Position / index)
= (λ z → Shape (snd z))
<! (λ j z → Position (snd j) z)
/ (λ j s x → fst j , index (snd j) s x)
---------------------------------------------------------------------------
-- COMBINING TWO INTERFACES WITH SEPARATE STATE
---------------------------------------------------------------------------
{- 4.5 Making use of 4.3 and 4.4, show how to combine two interfaces which
operate independently on separate state: commands from one should
not affect the state of the other.
-} -- Conor: 1/1
_<+>_ : {I0 I1 : Set} -> I0 => I0 -> I1 => I1 -> (I0 * I1) => (I0 * I1)
CRn0 <+> CRn1 = GrowR CRn0 =+= GrowL CRn1
---------------------------------------------------------------------------
-- ERROR REPORTING, AN INTERFACE
---------------------------------------------------------------------------
{- I'm building the next bit for you.
When things go wrong, we need to trigger an error condition and abort
mission. However, if we have other stuff going on (open files, etc),
it may not always be ok to drop everything and run away. There will
be some states in which it is safe to escape (and deliver a suitable
error message, perhaps) and other states in which escape should be
impossible.
If it is safe to issue an error message, we should be able to do so
without fear of any response from the environment that would oblige
us to carry on.
-}
data ErrorC {I : Set}(SafeMessage : I -> Set)(i : I) : Set where
error : SafeMessage i -> ErrorC SafeMessage i
-- the SafeMessage parameter tells us what is an acceptable
-- error message in any given state; in states where this gives
-- Zero, it will be impossible to trigger an error!
ErrorR : {I : Set}{SafeMessage : I -> Set}(i : I)(c : ErrorC SafeMessage i) -> Set
ErrorR _ _ = Zero -- there's no comeback
errorNext : {I : Set}{SafeMessage : I -> Set}
(i : I)(c : ErrorC SafeMessage i) -> ErrorR i c -> I
errorNext i c () -- so we don't have to say how the state will evolve
ERROR : {I : Set}(SafeMessage : I -> Set) -> I => I
ERROR SafeMessage = ErrorC SafeMessage <! ErrorR / errorNext
---------------------------------------------------------------------------
-- COPY A FILE
---------------------------------------------------------------------------
{- 4.6 Implement a process which, given access to suitable interfaces, will
give the process for copying a named source file to a named target
file. This goes in two phases.
-}
{- 4.6.1 Firstly, you should identify the command-reponse interface within
which you need to work. You will need to be able to read and write files,
but also to signal errors (in case a file fails to open for some reason).
You must ensure that it is impossible for any process using your interface
to escape with an error leaving a file open. You must also make it
possible to guarantee that your copying process will, error or not, leave
all files closed.
-} -- Conor: 0.5/1
CPState : Set
CPState = ReadState * WriteState
CPInterface : CPState => CPState
CPInterface = (READ <+> WRITE) -- Conor: good start but, yes
--ERROR -- Conor: is the question
{-
ReadState WriteState
-}
{- 4.6.2 Secondly, you should implement your copying process, working to your
interface.
-} -- Conor: 0/3
FinalState : CPState -> Set
FinalState c = {!!}
cp : (sourceFile targetFile : String) -> IterIx CPInterface FinalState {!!}
cp sourceFile targetFile = {!!}
{- HINTS
You will certainly need to build some extra bits and pieces.
You have the components for reading, writing and error handling, and
suitable kit with which to combine them. Reading and writing don't
interfere with each other, but it's important to make sure that you
can't bomb out with an error, so some shared state seems important.
There are really two phases to the process:
(1) getting the files open -- this may go wrong
(2) copying from one to the other -- this will work if we reach it
You might want to split these phases apart.
-}
---------------------------------------------------------------
-- TO BE CONTINUED...
---------------------------------------------------------------
-- The rest of the exercise is to fill selected gaps in code that
-- gets your cp process to the stage where it actually compiles.
-- Agda version 2.4.2.4 is needed t compile the "copatterns" involved
-- in the code, but you should be able to complete the exercise
-- without upgrading, if you are currently using an earlier version.
-- It is only the business of generating a standalone executable that
-- needs the upgrade. Still, it'd be nice to see it go, wouldn't it?
-- The key is to build a device driver between your carefully
-- designed command-response system and "scripts" built from
-- low-level Haskell commands, maintaining the file handles
-- involved as you go.
-- Then you'll need to explain how to run the low-level script.
---------------------------------------------------------------
-- What's a Device Driver? (My bit. Do read.)
---------------------------------------------------------------
open _=>_ public
Driver :
{I J : Set} -- I is "high-level state" ; J, "low"
(Sync : I -> J -> Set) -- when are states "in sync"?
(Hi : I => I) -- high-level command-response system
(Lo : J => J) -- low-level command-response system
-> Set
Driver {I}{J} Sync Hi Lo =
forall i j -> Sync i j -> -- whenever we're in sync,
(c : Shape Hi i) -> -- we can take a high-level command
Sg (Shape Lo j) \ c' -> -- and give the low-level version,
(r' : Position Lo j c') -> -- then take the low-level response
Sg (Position Hi i c) \ r -> -- and give the high-level version,
Sync (index Hi i c r) (index Lo j c' r') -- and stay in sync!
drive : forall {I J}{Sync : I -> J -> Set}
{Hi : I => I}{Lo : J => J}
(D : Driver Sync Hi Lo)
{X : I -> Set}
(i : I)(j : J)
(ij : Sync i j) -> -- if we're in sync and have
IC Hi X i -> -- a high-level way to get an X
IC Lo (\ j -> Sg I \ i -> Sync i j * X i) j
-- then we have a low-level plan to
-- stay in sync and get an X
drive D i j ij (c , k) =
let x = D i j ij c ; c' = fst x ; D' = snd x
in c' , \ r' -> -- issue low-level command c', get response r'
let y = D' r' ; r = fst y ; s = snd y
in _ , s , k r -- choose sync state from driver, call continuation
---------------------------------------------------------------
-- SCRIPTING COMMANDS (your bit)
---------------------------------------------------------------
{- 4.7 Complete the definition of the command response system
for scripting commands built from another command response system,
C. A scripted command is a whole strategy for interacting with C,
the way you can write shell scripts which give strategies for
issuing commands at a terminal. Your job is to give the type
for responses (which should pack up all the responses to the
commands) and compute the next state (which should be the state
the system reaches when the script stops).
Then you should construct the function which translates
one SCRIPT C interaction to many C interactions. That's to say,
implement the "script interpreter".
-} -- Conor: 0/2
SCRIPT : forall {I} -> (I => I) -> (I => I)
SCRIPT {I} C = FreeIx C (\ _ -> One) <! ScriptR / ScriptN where
ScriptR : (i : I) -> FreeIx C (\ _ -> One) i -> Set
ScriptR i cs = {!!}
ScriptN : (i : I)(c : FreeIx C (\ _ -> One) i) -> ScriptR i c -> I
ScriptN i cs rs = {!!}
unscript : forall {I}{X : I -> Set}(C : I => I) ->
[ IC (SCRIPT C) X -:> FreeIx C X ]
unscript {I}{X} C (c , k) = help c k where
help : {i : I}(c : FreeIx C (\ _ -> One) i)
(k : (p : Position (SCRIPT C) i c) ->
X (index (SCRIPT C) i c p)) ->
FreeIx C X i
help cs k = {!!}
---------------------------------------------------------------
-- An Interface to Haskell IO (also my bit)
---------------------------------------------------------------
-- an Agda Maybe-type which connects to Haskell's
data Maybe (X : Set) : Set where
yes : X -> Maybe X
no : Maybe X
{-# COMPILED_DATA Maybe Maybe Just Nothing #-}
-- an Agda Either-type which connects to Haskell's
data Either (S T : Set) : Set where
left : S -> Either S T
right : T -> Either S T
{-# COMPILED_DATA Either Either Left Right #-}
-- a copy of Haskell's file access more datatype
data IOMode : Set where
readMode writeMode appendMode readWriteMode : IOMode
{-# COMPILED_DATA IOMode System.IO.IOMode System.IO.ReadMode System.IO.WriteMode System.IO.AppendMode System.IO.ReadWriteMode #-}
-- Haskell's file handles imported abstractly
postulate Handle : Set
{-# COMPILED_TYPE Handle System.IO.Handle #-}
-- The Low-Level Haskell Command-Response System. Please use wisely.
data HaskellIOCommand : Set where
hOpen : String -> IOMode -> HaskellIOCommand
hClose hIsEOF hGetChar : Handle -> HaskellIOCommand
hPutChar : Handle -> Char -> HaskellIOCommand
hError : String -> HaskellIOCommand
HaskellIOResponse : HaskellIOCommand -> Set
HaskellIOResponse (hOpen f m) = Maybe Handle
HaskellIOResponse (hClose h) = One
HaskellIOResponse (hIsEOF h) = Two
HaskellIOResponse (hGetChar h) = Char
HaskellIOResponse (hPutChar h c) = One
HaskellIOResponse (hError e) = Zero
HASKELLIO : One => One
HASKELLIO = (\ _ -> HaskellIOCommand) <! (\ _ -> HaskellIOResponse) / _
postulate -- Haskell has a monad for doing IO, which we use at the top level
IO : Set -> Set
return : {A : Set} -> A -> IO A
_>>=_ : {A B : Set} -> IO A -> (A -> IO B) -> IO B
hOpenIO : String -> IOMode -> IO (Maybe Handle)
hCloseIO : Handle -> IO One
hIsEOFIO : Handle -> IO Two
hGetCharIO : Handle -> IO Char
hPutCharIO : Handle -> Char -> IO One
hErrorIO : {X : Set} -> String -> IO X
mainLoop : {S : Set} -> (S -> Either String (IO S)) -> (String -> String -> S) -> IO One
infixl 1 _>>=_
{-# BUILTIN IO IO #-}
{-# COMPILED_TYPE IO IO #-}
{-# COMPILED return (\ _ -> return) #-}
{-# COMPILED _>>=_ (\ _ _ -> (>>=)) #-}
{-# COMPILED hOpenIO Ex4Haskell.hOpenIO #-}
{-# COMPILED hCloseIO Ex4Haskell.hCloseIO #-}
{-# COMPILED hIsEOFIO Ex4Haskell.hIsEOFIO #-}
{-# COMPILED hGetCharIO Ex4Haskell.hGetCharIO #-}
{-# COMPILED hPutCharIO Ex4Haskell.hPutCharIO #-}
{-# COMPILED hErrorIO (\ _ -> Ex4Haskell.hErrorIO) #-}
{-# COMPILED mainLoop (\ _ -> Ex4Haskell.mainLoop) #-}
-- We explain how to do one command.
doHaskellCommand : (c : HaskellIOCommand) -> IO (HaskellIOResponse c)
doHaskellCommand (hOpen n m) = hOpenIO n m
doHaskellCommand (hClose h) = hCloseIO h
doHaskellCommand (hIsEOF h) = hIsEOFIO h
doHaskellCommand (hGetChar h) = hGetCharIO h
doHaskellCommand (hPutChar h c) = hPutCharIO h c
doHaskellCommand (hError e) = hErrorIO e
-- We need a MONAD MORPHISM to translate our HASKELLIO monad to
-- Haskell's IO Monad. A monad morphism is a function between monads
-- which respects return and >>=. Every monad morphism from a FREE
-- monad is given by explaining how to do one command.
haskellIO : forall {X} -> FreeIx HASKELLIO (\ _ -> X) <> -> IO X
haskellIO (ret x) = return x
haskellIO (do (c , k)) = doHaskellCommand c >>= \ v -> haskellIO (k v)
---------------------------------------------------------------
-- The Driver (your bit)
---------------------------------------------------------------
-- Due to an annoying bug in Agda (which I reported and which has
-- been fixed in the head version), I had to resort to making
-- a rubbish version of One, called Dull.
postulate
Dull : Set -- it's a unit type
dull : Dull -- see? it has one thing in it?
-- you can't pattern match on it
-- For read and write states, we can say which handles we need to
-- know. We should know handles only when files are open.
RH : ReadState -> Set
RH (opened eof) = Handle
RH closed = Dull
WH : WriteState -> Set
WH opened = Handle
WH closed = Dull
{- 4.8 Define the appropriate notion of Sync for your notion of
CPState. It should be a collection of the handles appropriate
for the files currently open, built using RH and WH.
Then build the driver, carefully. Remember, when reading, to
check the end-of-file status as required.
-} -- Conor: 0/4
HANDLES : CPState -> One -> Set
HANDLES cps = {!!}
haskellDriver : Driver HANDLES CPInterface (SCRIPT HASKELLIO)
haskellDriver i j s c = {!!}
---------------------------------------------------------------
-- Putting it all together
---------------------------------------------------------------
-- A concrete STATE is some CPState for which we have
-- (i) the right handles, and
-- (ii) a plan for how to make progress with copying.
STATE : Set
STATE = Sg CPState \ i ->
HANDLES i <> * IterIx CPInterface FinalState i
{- 4.9 For your chosen final state, you need to explain how to
issue a message signalling successful completion. The empty
string will do, but perhaps you want more. -} -- Conor: 0/1
finalMessage : (i : CPState) -> FinalState i -> String
finalMessage i x = {!!}
-- Now, in each state, we will either discover we're done, or
-- we'll learn the next bunch of Haskell commands to do.
runCP : STATE -> Either String (IO STATE)
runCP (i , h , cp) with force cp
runCP (i , h , cp) | ret x = left (finalMessage i x)
runCP (i , h , cp) | do c = right
(haskellIO (unscript HASKELLIO
(drive haskellDriver {IterIx CPInterface FinalState} i <> h c)))
{- 4.10 To complete the main program, fill in the starting
CPState and its associated handle information. -} -- Conor: 0/1
main : IO One
main = mainLoop runCP \ src trg ->
{!!} , {!!} , cp src trg
-- Now, to compile this (using Agda 2.4.2.4), grab a terminal and
-- issue the command
--
-- agda --compile Ex4.agda
--
-- and if you're very lucky, you should be able to issue commands
--
-- ./Ex4 <sourceFile> <targetFile>
--
-- Be careful not to overwrite your homework.
--
-- PS if in doubt about Agda versions, try
--
-- agda -V
|
{
"alphanum_fraction": 0.5914346499,
"avg_line_length": 37.5381944444,
"ext": "agda",
"hexsha": "96683a1f1f1bffd507c341c50d6540f682cf8b32",
"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": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "Ex4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"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": "clarkdm/CS410",
"max_issues_repo_path": "Ex4.agda",
"max_line_length": 129,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "Ex4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5715,
"size": 21622
}
|
------------------------------------------------------------------------------
-- The gcd program is correct
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- This module proves the correctness of the gcd program using
-- the Euclid's algorithm.
module LTC-PCF.Program.GCD.Total.CorrectnessProof where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat.Type
open import LTC-PCF.Program.GCD.Total.CommonDivisor using ( gcdCD )
open import LTC-PCF.Program.GCD.Total.Definitions using ( gcdSpec )
open import LTC-PCF.Program.GCD.Total.Divisible using ( gcdDivisible )
open import LTC-PCF.Program.GCD.Total.GCD using ( gcd )
------------------------------------------------------------------------------
-- The gcd is correct.
gcdCorrect : ∀ {m n} → N m → N n → gcdSpec m n (gcd m n)
gcdCorrect Nm Nn = gcdCD Nm Nn , gcdDivisible Nm Nn
|
{
"alphanum_fraction": 0.5335249042,
"avg_line_length": 40.1538461538,
"ext": "agda",
"hexsha": "e937f8c198b881b716544700e07e70dc2439222f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/CorrectnessProof.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/CorrectnessProof.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/CorrectnessProof.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": 220,
"size": 1044
}
|
-- When checking pattern coverage we might end up having to split
-- on a dot pattern (if the individual clauses split differently).
-- This is fine as long as the dot pattern is on constructor form.
module SplitOnDotPattern where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
data Vec (A : Set) : Nat -> Set where
[] : Vec A zero
_::_ : forall {n} -> A -> Vec A n -> Vec A (suc n)
rev : forall {A n m} -> Vec A n -> Vec A m -> Vec A m
rev [] ys = ys
rev {n = suc n} (x :: xs) ys = ys
|
{
"alphanum_fraction": 0.6003824092,
"avg_line_length": 27.5263157895,
"ext": "agda",
"hexsha": "dac619dcb574855b41fd7f95e76b413ee8f8deb3",
"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/SplitOnDotPattern.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/SplitOnDotPattern.agda",
"max_line_length": 66,
"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/SplitOnDotPattern.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": 156,
"size": 523
}
|
{-# OPTIONS --safe #-}
module Issue2487-3 where
import Issue2487.B
|
{
"alphanum_fraction": 0.7058823529,
"avg_line_length": 13.6,
"ext": "agda",
"hexsha": "c120b5fae470da4822ddfee47a9130ff30b1fc8e",
"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/Issue2487-3.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/Issue2487-3.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2487-3.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": 19,
"size": 68
}
|
{-# OPTIONS --without-K #-}
module Common.Unit where
open import Agda.Builtin.Unit public renaming (⊤ to Unit; tt to unit)
|
{
"alphanum_fraction": 0.712,
"avg_line_length": 20.8333333333,
"ext": "agda",
"hexsha": "a34f955cb3f5e14160d33d7a6128ffdc5ca486f9",
"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/Common/Unit.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/Common/Unit.agda",
"max_line_length": 69,
"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/Common/Unit.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": 31,
"size": 125
}
|
-- Andreas, 2017-03-01 issue #2480, reported by nad, discovered by simonhu
-- Exploit by Jesper Cockx
-- {-# OPTIONS -v tc.lhs.split:60 #-}
open import Agda.Builtin.Equality
data Bool : Set where
tt ff : Bool
const : Bool → (Bool → Bool)
const = λ x _ → x
ap : {A : Set} {B : Set} (f : A → B) {a b : A} (p : a ≡ b) → f a ≡ f b
ap f refl = refl
mutual
-- Type of constant boolean functions, using @UnusedArg@
Bool→cBool : Set
Bool→cBool = _
accepted : (p : const tt ≡ const ff) → ap (λ f → f tt) p ≡ ap (λ f → f ff) p
accepted p = refl {x = ap {A = Bool→cBool} (λ f → f tt) p}
constant : (f : Bool→cBool) (x y : Bool) → f x ≡ f y
constant f x y = refl
swap : Bool→cBool
swap tt = ff
swap ff = tt
-- swap is definitely not constant, should be rejected
BOOM : tt ≡ ff
BOOM = constant swap ff tt
|
{
"alphanum_fraction": 0.6081081081,
"avg_line_length": 23.2571428571,
"ext": "agda",
"hexsha": "4e52b42c49dcdea0d70e3cf214bcf710bef0be9c",
"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/Issue2480false.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/Issue2480false.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2480false.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": 299,
"size": 814
}
|
-- Andreas, 2014-05-02
-- Epic issue by Nisse and Andrea Vezzosi
record R : Set₁ where
field
A : Set
postulate
X : R
x : R.A X
Y : R
Y = X
record S : Set where
field
G : R.A Y -- Works if Y is replaced by X.
s : S
s = record { G = x }
-- This crashed epic with an internal error.
-- Expected behavior now: crash because main is missing.
|
{
"alphanum_fraction": 0.6232686981,
"avg_line_length": 14.44,
"ext": "agda",
"hexsha": "a03001c95db306a1ddca393eb6bde015a03bf5a3",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue1117.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/Issue1117.agda",
"max_line_length": 56,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue1117.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 119,
"size": 361
}
|
{-# OPTIONS --safe #-}
module Cubical.Categories.Abelian.Instances.Terminal where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Abelian.Base
open import Cubical.Categories.Additive.Instances.Terminal
open import Cubical.Data.Unit
private
variable
ℓ : Level
private
open PreAbCategory
open PreAbCategoryStr
terminalPreAbCategory : PreAbCategory ℓ ℓ
PreAbCategory.additive terminalPreAbCategory = terminalAdditiveCategory
Kernel.k (hasKernels (preAbStr terminalPreAbCategory) f) = tt*
Kernel.ker (hasKernels (preAbStr terminalPreAbCategory) f) = refl
IsKernel.ker⋆f (Kernel.isKer (hasKernels (preAbStr terminalPreAbCategory) f)) = refl
IsKernel.univ (Kernel.isKer (hasKernels (preAbStr terminalPreAbCategory) f)) = λ _ _ _ → (refl , refl) , λ _ → refl
Cokernel.c (hasCokernels (preAbStr terminalPreAbCategory) f) = tt*
Cokernel.coker (hasCokernels (preAbStr terminalPreAbCategory) f) = refl
IsCokernel.f⋆coker (Cokernel.isCoker (hasCokernels (preAbStr terminalPreAbCategory) f)) = refl
IsCokernel.univ (Cokernel.isCoker (hasCokernels (preAbStr terminalPreAbCategory) f)) = λ _ _ _ → (refl , refl) , λ _ → refl
open AbelianCategory
open AbelianCategoryStr
terminalAbelianCategory : AbelianCategory ℓ ℓ
preAb terminalAbelianCategory = terminalPreAbCategory
fst (monNormal (abelianStr terminalAbelianCategory) m _) = tt*
fst (snd (monNormal (abelianStr terminalAbelianCategory) m _)) = m
IsKernel.ker⋆f (snd (snd (monNormal (abelianStr terminalAbelianCategory) m _))) = refl
IsKernel.univ (snd (snd (monNormal (abelianStr terminalAbelianCategory) m _))) = λ _ _ _ → (refl , refl) , (λ _ → refl)
fst (epiNormal (abelianStr terminalAbelianCategory) e _) = tt*
fst (snd (epiNormal (abelianStr terminalAbelianCategory) e _)) = e
IsCokernel.f⋆coker (snd (snd (epiNormal (abelianStr terminalAbelianCategory) e _))) = refl
IsCokernel.univ (snd (snd (epiNormal (abelianStr terminalAbelianCategory) e _))) = λ _ _ _ → (refl , refl) , (λ _ → refl)
|
{
"alphanum_fraction": 0.768,
"avg_line_length": 42.5531914894,
"ext": "agda",
"hexsha": "b897f2df2abdb50ca0dfe32bf0a296834b10cdb3",
"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/Categories/Abelian/Instances/Terminal.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/Categories/Abelian/Instances/Terminal.agda",
"max_line_length": 125,
"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/Categories/Abelian/Instances/Terminal.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": 631,
"size": 2000
}
|
{-# OPTIONS --safe --warning=error #-}
open import Sets.EquivalenceRelations
open import Functions.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_; Setω)
open import Setoids.Setoids
open import Groups.Definition
open import LogicalFormulae
open import Orders.WellFounded.Definition
open import Numbers.Naturals.Semiring
open import Groups.Lemmas
module Groups.FreeProduct.Group {i : _} {I : Set i} (decidableIndex : (x y : I) → ((x ≡ y) || ((x ≡ y) → False))) {a b : _} {A : I → Set a} {S : (i : I) → Setoid {a} {b} (A i)} {_+_ : (i : I) → (A i) → (A i) → A i} (decidableGroups : (i : I) → (x y : A i) → ((Setoid._∼_ (S i) x y)) || ((Setoid._∼_ (S i) x y) → False)) (G : (i : I) → Group (S i) (_+_ i)) where
open import Groups.FreeProduct.Definition decidableIndex decidableGroups G
open import Groups.FreeProduct.Setoid decidableIndex decidableGroups G
open import Groups.FreeProduct.Addition decidableIndex decidableGroups G
private
plus'WDlemm : {i : I} (x1 x2 : ReducedSequenceBeginningWith i) (y : ReducedSequence) → (=RP' x1 x2) → plus' x1 y =RP plus' x2 y
plus'WDlemm (ofEmpty i g nonZero) (ofEmpty .i g₁ nonZero₁) y x1=x2 with decidableIndex i i
plus'WDlemm (ofEmpty i g nonZero) (ofEmpty .i h nonZero2) y x1=x2 | inl refl = prependWD g h nonZero nonZero2 y x1=x2
plus'WDlemm (prependLetter i g nonZero {j} x1 x) (prependLetter .i h nonZero2 {j2} x2 pr) y x1=x2 with decidableIndex i i
... | inl refl with decidableIndex j j2
plus'WDlemm (prependLetter i g nonZero {j} x1 x) (prependLetter .i h nonZero2 {.j} x2 pr) y x1=x2 | inl refl | inl refl = Equivalence.transitive (Setoid.eq freeProductSetoid) {prepend i g nonZero (plus' x1 y)} {prepend i h nonZero2 (plus' x1 y)} {plus' (prependLetter i h nonZero2 x2 pr) y} (prependWD g h nonZero nonZero2 (plus' x1 y) (_&&_.fst x1=x2)) (prependWD' h nonZero2 (plus' x1 y) (plus' x2 y) (plus'WDlemm x1 x2 y (_&&_.snd x1=x2)))
... | inr j!=j2 = exFalso (notEqualIfStartDifferent j!=j2 x1 x2 (_&&_.snd x1=x2))
plus'WDlemm _ _ _ _ | inr bad = exFalso (bad refl)
plus'WD : {i j : I} (x1 : ReducedSequenceBeginningWith i) (x2 : ReducedSequenceBeginningWith j) (y : ReducedSequence) → (=RP' x1 x2) → plus' x1 y =RP plus' x2 y
plus'WD {i} {j} x1 x2 y x1=x2 with decidableIndex i j
plus'WD {i} {.i} x1 x2 y x1=x2 | inl refl = plus'WDlemm x1 x2 y x1=x2
plus'WD {i} {j} x1 x2 y x1=x2 | inr x = exFalso (notEqualIfStartDifferent x x1 x2 x1=x2)
plusWD : (m n o p : ReducedSequence) → (m =RP o) → (n =RP p) → (m +RP n) =RP (o +RP p)
plusWD empty empty empty empty m=o n=p = record {}
plusWD empty (nonempty i x) empty (nonempty i₁ x₁) m=o n=p = n=p
plusWD (nonempty i x) empty (nonempty j y) empty m=o record {} = Equivalence.transitive (Setoid.eq freeProductSetoid) {plus' x empty} {nonempty i x} {plus' y empty} (plusEmptyRight x) (Equivalence.transitive (Setoid.eq freeProductSetoid) {nonempty i x} {nonempty j y} {plus' y empty} m=o (Equivalence.symmetric (Setoid.eq freeProductSetoid) {plus' y empty} {nonempty j y} (plusEmptyRight y)))
plusWD (nonempty i1 x1) (nonempty i2 x2) (nonempty i3 x3) (nonempty i4 x4) m=o n=p = (Equivalence.transitive (Setoid.eq freeProductSetoid)) {plus' x1 (nonempty i2 x2)} {plus' x3 (nonempty i2 x2)} {plus' x3 (nonempty i4 x4)} (plus'WD x1 x3 (nonempty i2 x2) m=o) (plus'WD' x3 (nonempty i2 x2) (nonempty i4 x4) n=p)
prependAssocLemma' : {i : I} {g : A i} .(nz : Setoid._∼_ (S i) g (Group.0G (G i)) → False) (b c : ReducedSequence) → (prepend i g nz b +RP c) =RP prepend i g nz (b +RP c)
prependAssocLemma' {i} {g} nz empty c = Equivalence.reflexive (Setoid.eq freeProductSetoid) {prepend i g _ c}
prependAssocLemma' {i} nz (nonempty k x) c with decidableIndex i k
prependAssocLemma' {.k} {g1} nz (nonempty k (ofEmpty .k g nonZero)) c | inl refl with decidableGroups k ((k + g1) g) (Group.0G (G k))
prependAssocLemma' {.k} {g1} nz (nonempty k (ofEmpty .k g nonZero)) c | inl refl | inl eq1 = Equivalence.symmetric (Setoid.eq freeProductSetoid) {prepend k g1 _ (prepend k g _ c)} {c} (prependFrom' g1 g eq1 c nz nonZero)
prependAssocLemma' {.k} {g1} nz (nonempty k (ofEmpty .k g nonZero)) c | inl refl | inr neq1 = (prependFrom g1 g neq1 c nz nonZero)
prependAssocLemma' {.k} {g1} nz (nonempty k (prependLetter .k g nonZero x x₁)) c | inl refl with decidableGroups k ((k + g1) g) (Group.0G (G k))
prependAssocLemma' {.k} {g1} nz (nonempty k (prependLetter .k g nonZero x x₁)) c | inl refl | inl eq1 = Equivalence.symmetric (Setoid.eq freeProductSetoid) {prepend k g1 _ (prepend k g _ (plus' x c))} {plus' x c} (prependFrom' g1 g eq1 (plus' x c) nz nonZero)
prependAssocLemma' {.k} {g1} nz (nonempty k (prependLetter .k g nonZero x x₁)) c | inl refl | inr neq1 = prependFrom g1 g neq1 (plus' x c) nz nonZero
prependAssocLemma' {i} {g} nz (nonempty k x) c | inr i!=k = Equivalence.reflexive (Setoid.eq freeProductSetoid) {prepend i g _ (plus' x c)}
plusAssocLemma : {i : I} (x : ReducedSequenceBeginningWith i) (b c : ReducedSequence) → (plus' x b +RP c) =RP plus' x (b +RP c)
plusAssocLemma (ofEmpty i g nonZero) empty c = Equivalence.reflexive (Setoid.eq freeProductSetoid) {prepend i g _ c}
plusAssocLemma (ofEmpty i g nonZero) (nonempty j b) c with decidableIndex i j
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (ofEmpty .i g₁ nonZero₁)) c | inl refl with decidableIndex i i
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (ofEmpty .i h nonZero₁)) c | inl refl | inl refl with decidableGroups i ((i + g) h) (Group.0G (G i))
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (ofEmpty .i h nonZero₁)) c | inl refl | inl refl | inl t = Equivalence.symmetric (Setoid.eq freeProductSetoid) {prepend i g _ (prepend i h _ c)} {c} (prependFrom' g h t c _ _)
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (ofEmpty .i h nonZero₁)) c | inl refl | inl refl | inr t = prependFrom g h t c _ _
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (ofEmpty .i g₁ nonZero₁)) c | inl refl | inr bad = exFalso (bad refl)
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (prependLetter .i h nonZero₁ b x)) c | inl refl with decidableGroups i ((i + g) h) (Group.0G (G i))
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (prependLetter .i h nonZero₁ b x)) c | inl refl | inl eq1 = Equivalence.symmetric (Setoid.eq freeProductSetoid) {prepend i g _ (prepend i h _ (plus' b c))} {plus' b c} (prependFrom' g h eq1 (plus' b c) _ _)
plusAssocLemma (ofEmpty i g nonZero) (nonempty .i (prependLetter .i h nonZero₁ b x)) c | inl refl | inr neq1 = prependFrom g h neq1 (plus' b c) nonZero _
plusAssocLemma (ofEmpty i g nonZero) (nonempty j b) c | inr i!=j = Equivalence.reflexive (Setoid.eq freeProductSetoid) {prepend i g _ (plus' b c)}
plusAssocLemma (prependLetter i g nonZero {j} w i!=j) b c = Equivalence.transitive (Setoid.eq freeProductSetoid) {prepend i g _ (plus' w b) +RP c} {prepend i g _ (plus' w b +RP c)} {prepend i g _ (plus' w (b +RP c))} (prependAssocLemma' nonZero (plus' w b) c) (prependWD' g nonZero (plus' w b +RP c) (plus' w (b +RP c)) (plusAssocLemma w b c))
plusAssoc : (a b c : ReducedSequence) → ((a +RP b) +RP c) =RP (a +RP (b +RP c))
plusAssoc empty b c = Equivalence.reflexive (Setoid.eq freeProductSetoid) {b +RP c}
plusAssoc (nonempty i x) b c = plusAssocLemma x b c
private
inv' : {i : I} (x : ReducedSequenceBeginningWith i) → ReducedSequence
inv' (ofEmpty i g nonZero) = nonempty i (ofEmpty i (Group.inverse (G i) g) (λ pr → nonZero (Equivalence.transitive (Setoid.eq (S i)) (swapInv (G i) pr) (invIdent (G i)))))
inv' (prependLetter i g nonZero {j} w i!=j) = (inv' w) +RP injection (Group.inverse (G i) g) (λ pr → nonZero (Equivalence.transitive (Setoid.eq (S i)) (swapInv (G i) pr) (invIdent (G i))))
inv : (x : ReducedSequence) → ReducedSequence
inv empty = empty
inv (nonempty i w) = inv' w
private
abstract
lemma1 : {i j k : I} (i!=j : (i ≡ j) → False) (g : A i) (h : A j) (w : ReducedSequenceBeginningWith k) (j!=k : (j ≡ k) → False) → .(pr : _) .(pr2 : _) .(pr3 : _) → (prepend i (Group.inverse (G i) g) pr (nonempty i (prependLetter i g pr2 (prependLetter j h pr3 w j!=k) i!=j))) =RP nonempty j (prependLetter j h pr3 w j!=k)
lemma1 {i} {j} {k} i!=j g h r j!=k pr pr2 pr3 with decidableIndex i i
... | inr x = exFalso (x refl)
lemma1 {i} {j} {k} i!=j g h r j!=k pr pr2 pr3 | inl refl with decidableGroups i ((i + Group.inverse (G i) g) g) (Group.0G (G i))
... | inr bad = exFalso (bad (Group.invLeft (G i)))
lemma1 {i} {j} {k} i!=j g h r j!=k pr pr2 pr3 | inl refl | inl eq1 with decidableIndex j j
... | inr bad = exFalso (bad refl)
... | inl refl = Equivalence.reflexive (Setoid.eq (S j)) ,, =RP'reflex r
abstract
lemma2 : {j k : I} (j!=k : (j ≡ k) → False) (h : A j) (w : ReducedSequenceBeginningWith k) .(pr : _) .(pr2 : _) → (prepend j (Group.inverse (G j) h) pr (nonempty j (prependLetter j h pr2 w j!=k))) =RP (nonempty k w)
lemma2 {j} {k} j!=k h r pr pr2 with decidableIndex j j
... | inr bad = exFalso (bad refl)
lemma2 {j} {k} j!=k h r pr pr2 | inl refl with decidableGroups j ((j + Group.inverse (G j) h) h) (Group.0G (G j))
... | inr bad = exFalso (bad (Group.invLeft (G j)))
... | inl x = =RP'reflex r
abstract
unpeel : (k : ReducedSequence) {j : I} (g : A j) .(pr : _) .(pr2 : _) → k =RP empty → (prepend j g pr (k +RP (nonempty j (ofEmpty j (Group.inverse (G j) g) pr2)))) =RP empty
unpeel empty {j} g pr pr2 x with decidableIndex j j
... | inr bad = exFalso (bad refl)
unpeel empty {j} g pr pr2 x | inl refl with decidableGroups j ((j + g) (Group.inverse (G j) g)) (Group.0G (G j))
... | inl _ = record {}
... | inr bad = exFalso (bad (Group.invRight (G j)))
abstract
invRight' : {i : I} (x : ReducedSequenceBeginningWith i) → ((nonempty i x) +RP inv (nonempty i x)) =RP empty
invRight' {i} (ofEmpty _ g nonZero) with decidableIndex i i
... | inr x = exFalso (x refl)
invRight' {i} (ofEmpty _ g nonZero) | inl refl with decidableGroups i ((i + g) (Group.inverse (G i) g)) (Group.0G (G i))
... | inr x = exFalso (x (Group.invRight (G i)))
... | inl x = record {}
invRight' {j} (prependLetter _ g nonZero {k} (ofEmpty .k h nonZero1) j!=k) with decidableIndex k j
... | inl x = exFalso (j!=k (equalityCommutative x))
invRight' {j} (prependLetter _ g nonZero {k} (ofEmpty .k h nonZero1) j!=k) | inr _ with decidableIndex k k
... | inr x = exFalso (x refl)
invRight' {j} (prependLetter _ g nonZero {k} (ofEmpty .k h nonZero1) j!=k) | inr _ | inl refl with decidableGroups k ((k + h) (Group.inverse (G k) h)) (Group.0G (G k))
... | inr x = exFalso (x (Group.invRight (G k)))
invRight' {j} (prependLetter _ g nonZero {k} (ofEmpty .k h nonZero1) j!=k) | inr _ | inl refl | inl _ with decidableIndex j j
... | inr x = exFalso (x refl)
invRight' {j} (prependLetter _ g nonZero {k} (ofEmpty .k h nonZero1) j!=k) | inr _ | inl refl | inl _ | inl refl with decidableGroups j ((j + g) (Group.inverse (G j) g)) (Group.0G (G j))
... | inr bad = exFalso (bad (Group.invRight (G j)))
... | inl r = record {}
invRight' {j} (prependLetter _ g nonZero {k} (prependLetter .k h nonZero1 {i} x k!=i) j!=k) rewrite refl {x = 0} = Equivalence.transitive (Setoid.eq freeProductSetoid) {prepend j g _ (prepend k h _ (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _)) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) _))))} {prepend j g nonZero (prepend k h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t)))) +RP (nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G j) t))))} {empty} (prependWD' g nonZero (prepend k h nonZero1 (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _)) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G j) t))))) (prepend k h _ (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t)))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) λ i → nonZero (invZeroImpliesZero (G j) i))) (Equivalence.symmetric (Setoid.eq freeProductSetoid) {(prepend k h _ (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) _))} {prepend k h _ (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _)) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) _)))} t)) (unpeel (prepend k h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _)))) g nonZero (λ t → nonZero (invZeroImpliesZero (G j) t)) (Equivalence.transitive (Setoid.eq freeProductSetoid) {prepend k h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t))))} {prepend k h nonZero1 ((plus' x (inv' x)) +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t)))} {empty} (prependWD' h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t)))) (plus' x (inv' x) +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t))) (Equivalence.symmetric (Setoid.eq freeProductSetoid) {plus' x (inv' x) +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G k) t))} (plusAssoc (nonempty _ x) (inv' x) (nonempty k (ofEmpty k (Group.inverse (G k) h) (λ t → nonZero1 (invZeroImpliesZero (G k) t))))))) (unpeel (plus' x (inv' x)) h nonZero1 (λ t → nonZero1 (invZeroImpliesZero (G k) t)) (invRight' x))))
where
t : (prepend k h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) (λ t → nonZero1 (invZeroImpliesZero (G _) t))))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) (λ t → nonZero (invZeroImpliesZero (G j) t)))) =RP (prepend k h nonZero1 (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) (λ t → nonZero1 (invZeroImpliesZero (G _) t)))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) (λ t → nonZero (invZeroImpliesZero (G j) t))))))
t = Equivalence.transitive (Setoid.eq freeProductSetoid) {(prepend k h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) (λ t → nonZero1 (invZeroImpliesZero (G _) t))))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) (λ t → nonZero (invZeroImpliesZero (G j) t))))} {prepend k h _ (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G _) t))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G _) t)))} {(prepend k h nonZero1 (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) (λ t → nonZero1 (invZeroImpliesZero (G _) t)))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) (λ t → nonZero (invZeroImpliesZero (G j) t))))))} (prependAssocLemma' {k} {h} nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) _))) (nonempty j (ofEmpty j (Group.inverse (G j) g) _))) (prependWD' h nonZero1 (plus' x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G _) t))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G _) t))) (plus' x ((inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G _) t))) +RP nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G _) t)))) (plusAssocLemma x (inv' x +RP nonempty k (ofEmpty k (Group.inverse (G k) h) λ t → nonZero1 (invZeroImpliesZero (G _) t))) (nonempty j (ofEmpty j (Group.inverse (G j) g) λ t → nonZero (invZeroImpliesZero (G _) t)))))
abstract
invRight : (x : ReducedSequence) → (x +RP (inv x)) =RP empty
invRight empty = record {}
invRight (nonempty i w) = invRight' {i} w
abstract
invLeft' : {i : I} (x : ReducedSequenceBeginningWith i) → (inv (nonempty i x) +RP (nonempty i x)) =RP empty
invLeft' {i} (ofEmpty .i g nonZero) with decidableIndex i i
invLeft' {i} (ofEmpty .i g nonZero) | inl refl with decidableGroups i ((i + Group.inverse (G i) g) g) (Group.0G (G i))
... | inl good = record {}
... | inr bad = exFalso (bad (Group.invLeft (G i) {g}))
invLeft' {i} (ofEmpty .i g nonZero) | inr x = exFalso (x refl)
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) with decidableIndex j i
... | inl pr = exFalso (i!=j (equalityCommutative pr))
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr with decidableIndex i i
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr | inl refl with decidableGroups i ((i + Group.inverse (G i) g) g) (Group.0G (G i))
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr | inl refl | inl k with decidableIndex j j
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j h nonZero₁) i!=j) | inr pr | inl refl | inl k | inl refl with decidableGroups j ((j + Group.inverse (G j) h) h) (Group.0G (G j))
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j h nonZero₁) i!=j) | inr pr | inl refl | inl k | inl refl | inl good = record {}
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j h nonZero₁) i!=j) | inr pr | inl refl | inl k | inl refl | inr bad = exFalso (bad (Group.invLeft (G j)))
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr | inl refl | inl k | inr bad = exFalso (bad refl)
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr | inl refl | inr k = exFalso (k (Group.invLeft (G i) {g}))
invLeft' {i} (prependLetter .i g nonZero {.j} (ofEmpty j g₁ nonZero₁) i!=j) | inr pr | inr bad = exFalso (bad refl)
invLeft' {i} (prependLetter .i g nonZero {.j} (prependLetter j h nonZero1 {k} w x) i!=j) = Equivalence.transitive (Setoid.eq freeProductSetoid) {(((inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) +RP nonempty i (ofEmpty i (Group.inverse (G i) g) _)) +RP nonempty i (prependLetter i g _ (prependLetter j h _ w x) i!=j))} {_} {empty} (plusAssoc (inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) (nonempty i (ofEmpty i (Group.inverse (G i) g) _)) (nonempty i (prependLetter i g _ (prependLetter j h _ w x) i!=j))) (Equivalence.transitive (Setoid.eq freeProductSetoid) {((inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) +RP (prepend i (Group.inverse (G i) g) _ (nonempty i (prependLetter i g _ (prependLetter j h _ w x) i!=j))))} {(inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) +RP (nonempty j (prependLetter j h nonZero1 w x))} {empty} (plusWD (inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) (prepend i (Group.inverse (G i) g) _ (nonempty i (prependLetter i g _ (prependLetter j h _ w x) i!=j))) (inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) (nonempty j (prependLetter j h _ w x)) (Equivalence.reflexive (Setoid.eq freeProductSetoid) {inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)}) (lemma1 {i} {j} {k} i!=j g h w x (λ p → nonZero (invZeroImpliesZero (G i) p)) nonZero nonZero1)) (Equivalence.transitive (Setoid.eq freeProductSetoid) {(inv' w +RP nonempty j (ofEmpty j (Group.inverse (G j) h) _)) +RP nonempty j (prependLetter j h _ w x)} {inv' w +RP (nonempty j (ofEmpty j (Group.inverse (G j) h) λ p → nonZero1 (invZeroImpliesZero (G j) p)) +RP nonempty j (prependLetter j h nonZero1 w x))} {empty} (plusAssoc (inv' w) (nonempty j (ofEmpty j (Group.inverse (G j) h) _)) (nonempty j (prependLetter j h _ w x))) (Equivalence.transitive (Setoid.eq freeProductSetoid) {inv' w +RP (prepend j (Group.inverse (G j) h) _ (nonempty j (prependLetter j h nonZero1 w x)))} {inv' w +RP (nonempty k w)} {empty} (plusWD (inv' w) (prepend j (Group.inverse (G j) h) _ (nonempty j (prependLetter j h nonZero1 w x))) (inv' w) (nonempty k w) (Equivalence.reflexive (Setoid.eq freeProductSetoid) {inv' w}) (lemma2 {j} {k} x h w (λ p → nonZero1 (invZeroImpliesZero (G j) p)) nonZero1)) (invLeft' {k} w))))
abstract
invLeft : (x : ReducedSequence) → ((inv x) +RP x) =RP empty
invLeft empty = record {}
invLeft (nonempty i w) = invLeft' {i} w
FreeProductGroup : Group freeProductSetoid _+RP_
Group.+WellDefined FreeProductGroup {m} {n} {x} {y} m=x n=y = plusWD m n x y m=x n=y
Group.0G FreeProductGroup = empty
Group.inverse FreeProductGroup = inv
Group.+Associative FreeProductGroup {a} {b} {c} = Equivalence.symmetric (Setoid.eq freeProductSetoid) {(a +RP b) +RP c} {a +RP (b +RP c)} (plusAssoc a b c)
Group.identRight FreeProductGroup {empty} = Equivalence.reflexive (Setoid.eq freeProductSetoid) {empty}
Group.identRight FreeProductGroup {nonempty i x} rewrite refl {x = 0} = plusEmptyRight x
Group.identLeft FreeProductGroup {empty} = Equivalence.reflexive (Setoid.eq freeProductSetoid) {empty}
Group.identLeft FreeProductGroup {nonempty i x} = Equivalence.reflexive (Setoid.eq freeProductSetoid) {nonempty i x}
Group.invLeft FreeProductGroup {x} = invLeft x
Group.invRight FreeProductGroup {x} = invRight x
|
{
"alphanum_fraction": 0.6586936958,
"avg_line_length": 124.9289940828,
"ext": "agda",
"hexsha": "ec90a32d5e8b011008311b3feaec2a30d980795a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/FreeProduct/Group.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/FreeProduct/Group.agda",
"max_line_length": 2521,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/FreeProduct/Group.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 7774,
"size": 21113
}
|
------------------------------------------------------------------------------
-- Conversion rules for the greatest common divisor
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.GCD.Total.ConversionRules where
open import Common.FOL.Relation.Binary.EqReasoning
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Data.Nat.Inequalities.Properties
open import LTC-PCF.Program.GCD.Total.GCD
------------------------------------------------------------------------------
private
-- Before to prove some properties for the gcd it is convenient to
-- descompose the behavior of the function step by step.
-- Initially, we define the possible states (gcd-s₁, gcd-s₂,
-- ...). Then we write down the proof for the execution step from
-- the state p to the state q, e.g.
--
-- proof₂₋₃ : ∀ m n → gcd-s₂ m n → gcd-s₃ m n.
-- The functions gcd-00, gcd-S0, gcd-0S, gcd-Sm>Sn and gcd-Sm≯Sn
-- show the use of the states gcd-s₁, gcd-s₂, ..., and the proofs
-- associated with the execution steps.
----------------------------------------------------------------------------
-- The steps
-- Initially, the conversion rule fix-eq is applied.
gcd-s₁ : D → D → D
gcd-s₁ m n = gcdh (fix gcdh) · m · n
-- First argument application.
gcd-s₂ : D → D
gcd-s₂ m = lam (λ n →
if (iszero₁ n)
then m
else (if (iszero₁ m)
then n
else (if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m))))
-- Second argument application.
gcd-s₃ : D → D → D
gcd-s₃ m n = if (iszero₁ n)
then m
else (if (iszero₁ m)
then n
else (if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m)))
-- First if_then_else_ iszero₁ n = b.
gcd-s₄ : D → D → D → D
gcd-s₄ m n b = if b
then m
else (if (iszero₁ m)
then n
else (if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m)))
-- First if_then_else_ when if true ...
gcd-s₅ : D → D
gcd-s₅ m = m
-- First if_then_else_ when if false ...
gcd-s₆ : D → D → D
gcd-s₆ m n = if (iszero₁ m)
then n
else (if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m))
-- Second if_then_else_ iszero₁ m = b.
gcd-s₇ : D → D → D → D
gcd-s₇ m n b = if b
then n
else (if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m))
-- Second if_then_else_ when if false ...
gcd-s₈ : D → D → D
gcd-s₈ m n = if (gt m n)
then fix gcdh · (m ∸ n) · n
else fix gcdh · m · (n ∸ m)
-- Third if_then_else_ gt m n = b.
gcd-s₉ : D → D → D → D
gcd-s₉ m n b = if b then fix gcdh · (m ∸ n) · n else fix gcdh · m · (n ∸ m)
----------------------------------------------------------------------------
-- Congruence properties
gcd-s₉Cong₃ : ∀ {m n b b'} → b ≡ b' → gcd-s₉ m n b ≡ gcd-s₉ m n b'
gcd-s₉Cong₃ refl = refl
----------------------------------------------------------------------------
-- The execution steps
{-
To prove the execution steps, e.g.
proof₃₋₄ : ∀ m n → gcd-s₃ m n → gcd_s₄ m n,
we usually need to prove that
C [m] ≡ C [n] (1)
given that
m ≡ n, (2)
where (2) is a conversion rule usually.
We prove (1) using
subst : ∀ {x y} (D : A → Set) → x ≡ y → P x → P y
where
• P is given by λ m → C [m ] ≡ C [n],
• x ≡ y is given n ≡ m (actually, we use sym (m ≡ n)) and
• P x is given by C [n] ≡ C [n] (i.e. refl).
-}
proof₀₋₁ : ∀ m n → fix gcdh · m · n ≡ gcd-s₁ m n
proof₀₋₁ m n = subst (λ x → x · m · n ≡ gcdh (fix gcdh) · m · n)
(sym (fix-eq gcdh))
refl
proof₁₋₂ : ∀ m n → gcd-s₁ m n ≡ gcd-s₂ m · n
proof₁₋₂ m n = subst (λ x → x · n ≡ gcd-s₂ m · n)
(sym (beta gcd-s₂ m))
refl
proof₂₋₃ : ∀ m n → gcd-s₂ m · n ≡ gcd-s₃ m n
proof₂₋₃ m n = beta (gcd-s₃ m) n
-- 25 April 2014. Failed with Andreas' --without-K.
proof₃₋₄ : ∀ m n b → iszero₁ n ≡ b → gcd-s₃ m n ≡ gcd-s₄ m n b
proof₃₋₄ m n .(iszero₁ n) refl = refl
proof₄₊ : ∀ m n → gcd-s₄ m n true ≡ gcd-s₅ m
proof₄₊ m _ = if-true (gcd-s₅ m)
proof₄₋₆ : ∀ m n → gcd-s₄ m n false ≡ gcd-s₆ m n
proof₄₋₆ m n = if-false (gcd-s₆ m n)
proof₆₋₇ : ∀ m n b → iszero₁ m ≡ b → gcd-s₆ m n ≡ gcd-s₇ m n b
proof₆₋₇ m n .(iszero₁ m) refl = refl
proof₇₊ : ∀ m n → gcd-s₇ m n true ≡ n
proof₇₊ _ n = if-true n
proof₇₋₈ : ∀ m n → gcd-s₇ m n false ≡ gcd-s₈ m n
proof₇₋₈ m n = if-false (gcd-s₈ m n)
proof₈₋₉ : ∀ m n b → gt m n ≡ b → gcd-s₈ m n ≡ gcd-s₉ m n b
proof₈₋₉ m n b = gcd-s₉Cong₃
proof₉₊ : ∀ m n → gcd-s₉ m n true ≡ fix gcdh · (m ∸ n) · n
proof₉₊ m n = if-true (fix gcdh · (m ∸ n) · n)
proof₉₋ : ∀ m n → gcd-s₉ m n false ≡ fix gcdh · m · (n ∸ m)
proof₉₋ m n = if-false (fix gcdh · m · (n ∸ m))
------------------------------------------------------------------------------
-- The five equations for gcd
-- First equation.
gcd-00 : gcd zero zero ≡ zero
gcd-00 =
gcd zero zero ≡⟨ proof₀₋₁ zero zero ⟩
gcd-s₁ zero zero ≡⟨ proof₁₋₂ zero zero ⟩
gcd-s₂ zero · zero ≡⟨ proof₂₋₃ zero zero ⟩
gcd-s₃ zero zero ≡⟨ proof₃₋₄ zero zero true iszero-0 ⟩
gcd-s₄ zero zero true ≡⟨ proof₄₊ zero zero ⟩
zero ∎
-- Second equation.
gcd-S0 : ∀ n → gcd (succ₁ n) zero ≡ succ₁ n
gcd-S0 n =
gcd (succ₁ n) zero ≡⟨ proof₀₋₁ (succ₁ n) zero ⟩
gcd-s₁ (succ₁ n) zero ≡⟨ proof₁₋₂ (succ₁ n) zero ⟩
gcd-s₂ (succ₁ n) · zero ≡⟨ proof₂₋₃ (succ₁ n) zero ⟩
gcd-s₃ (succ₁ n) zero ≡⟨ proof₃₋₄ (succ₁ n) zero true iszero-0 ⟩
gcd-s₄ (succ₁ n) zero true ≡⟨ proof₄₊ (succ₁ n) zero ⟩
succ₁ n ∎
-- Third equation.
gcd-0S : ∀ n → gcd zero (succ₁ n) ≡ succ₁ n
gcd-0S n =
gcd zero (succ₁ n) ≡⟨ proof₀₋₁ zero (succ₁ n) ⟩
gcd-s₁ zero (succ₁ n) ≡⟨ proof₁₋₂ zero (succ₁ n) ⟩
gcd-s₂ zero · (succ₁ n) ≡⟨ proof₂₋₃ zero (succ₁ n) ⟩
gcd-s₃ zero (succ₁ n) ≡⟨ proof₃₋₄ zero (succ₁ n) false (iszero-S n) ⟩
gcd-s₄ zero (succ₁ n) false ≡⟨ proof₄₋₆ zero (succ₁ n) ⟩
gcd-s₆ zero (succ₁ n) ≡⟨ proof₆₋₇ zero (succ₁ n) true iszero-0 ⟩
gcd-s₇ zero (succ₁ n) true ≡⟨ proof₇₊ zero (succ₁ n) ⟩
succ₁ n ∎
-- Fourth equation.
gcd-S>S : ∀ m n → succ₁ m > succ₁ n →
gcd (succ₁ m) (succ₁ n) ≡ gcd (succ₁ m ∸ succ₁ n) (succ₁ n)
gcd-S>S m n Sm>Sn =
gcd (succ₁ m) (succ₁ n)
≡⟨ proof₀₋₁ (succ₁ m) (succ₁ n) ⟩
gcd-s₁ (succ₁ m) (succ₁ n)
≡⟨ proof₁₋₂ (succ₁ m) (succ₁ n) ⟩
gcd-s₂ (succ₁ m) · (succ₁ n)
≡⟨ proof₂₋₃ (succ₁ m) (succ₁ n) ⟩
gcd-s₃ (succ₁ m) (succ₁ n)
≡⟨ proof₃₋₄ (succ₁ m) (succ₁ n) false (iszero-S n) ⟩
gcd-s₄ (succ₁ m) (succ₁ n) false
≡⟨ proof₄₋₆ (succ₁ m) (succ₁ n) ⟩
gcd-s₆ (succ₁ m) (succ₁ n)
≡⟨ proof₆₋₇ (succ₁ m) (succ₁ n) false (iszero-S m) ⟩
gcd-s₇ (succ₁ m) (succ₁ n) false
≡⟨ proof₇₋₈ (succ₁ m) (succ₁ n) ⟩
gcd-s₈ (succ₁ m) (succ₁ n)
≡⟨ proof₈₋₉ (succ₁ m) (succ₁ n) true Sm>Sn ⟩
gcd-s₉ (succ₁ m) (succ₁ n) true
≡⟨ proof₉₊ (succ₁ m) (succ₁ n) ⟩
fix gcdh · (succ₁ m ∸ succ₁ n) · succ₁ n ∎
-- Fifth equation.
gcd-S≯S : ∀ m n → succ₁ m ≯ succ₁ n →
gcd (succ₁ m) (succ₁ n) ≡ gcd (succ₁ m) (succ₁ n ∸ succ₁ m)
gcd-S≯S m n Sm≯Sn =
gcd (succ₁ m) (succ₁ n)
≡⟨ proof₀₋₁ (succ₁ m) (succ₁ n) ⟩
gcd-s₁ (succ₁ m) (succ₁ n)
≡⟨ proof₁₋₂ (succ₁ m) (succ₁ n) ⟩
gcd-s₂ (succ₁ m) · (succ₁ n)
≡⟨ proof₂₋₃ (succ₁ m) (succ₁ n) ⟩
gcd-s₃ (succ₁ m) (succ₁ n)
≡⟨ proof₃₋₄ (succ₁ m) (succ₁ n) false (iszero-S n) ⟩
gcd-s₄ (succ₁ m) (succ₁ n) false
≡⟨ proof₄₋₆ (succ₁ m) (succ₁ n) ⟩
gcd-s₆ (succ₁ m) (succ₁ n)
≡⟨ proof₆₋₇ (succ₁ m) (succ₁ n) false (iszero-S m) ⟩
gcd-s₇ (succ₁ m) (succ₁ n) false
≡⟨ proof₇₋₈ (succ₁ m) (succ₁ n) ⟩
gcd-s₈ (succ₁ m) (succ₁ n)
≡⟨ proof₈₋₉ (succ₁ m) (succ₁ n) false Sm≯Sn ⟩
gcd-s₉ (succ₁ m) (succ₁ n) false
≡⟨ proof₉₋ (succ₁ m) (succ₁ n) ⟩
fix gcdh · succ₁ m · (succ₁ n ∸ succ₁ m) ∎
|
{
"alphanum_fraction": 0.4755807365,
"avg_line_length": 33.8122605364,
"ext": "agda",
"hexsha": "e2f1f4ccaed30562bc4e17ed94ed2153a16b8b53",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/ConversionRules.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/ConversionRules.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/GCD/Total/ConversionRules.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": 3406,
"size": 8825
}
|
module sortedLists where
open import lib
{- we use internal verification to define a datatype of sorted lists
of natural numbers, where typing ensures that the lists are truly
sorted in non-decreasing order.
A list of type (sortedList n) is sorted and guaranteed to have
all its data greater than or equal to n; so n is a lower bound
on the data in the list. Keeping this lower bound explicit in
the type enables us to require a proof of a constant-time check,
namely d ≤ n, when insert d into a list with lower-bound n. For
cons nodes, we allow the lower-bound to be less than the head of
the list. This is needed for merge below.
There are three constructors:
-- nil, as usual (empty list)
-- cons, as usual (build a new list from head and tail)
-- weaken, decrease the lower bound (this was missing in my first
attempt, which led to nasty problems in the case of merge below)
-}
data sortedList : ℕ → Set where
nil : ∀ (n : ℕ) → sortedList n -- empty lists can have any lower bound you like
cons : ∀ (d : ℕ) → -- the head of the list
{n : ℕ} → -- the lower-bound for the tail
sortedList n → -- the tail of the list, with lower bound n on its data
d ≤ n ≡ tt → {- proof that d is less than or equal to that lower bound, and
hence less than or equal to all data in the tail -}
sortedList d -- d is the lower bound for the new list created by the cons
weaken : ∀ (n : ℕ) {n' : ℕ} → sortedList n' → n ≤ n' ≡ tt → sortedList n
-- fill in the holes below, just to help you get a feel for how the sortedList datatype works
-- [5 points]
simple : sortedList 1
simple = weaken 1 (cons 2 (nil 3) refl)refl
{- glb stands for greatest lower bound. min d n is the greatest
lower bound of d and n, in the sense that if any other d' is a lower bound
of both d and n, then it is also a lower bound of min d n. (Ideas from
basic lattice theory.)
To prove this, you will run into a mess if you case split on d', d, or n.
Instead, you should consider cases for whether or not d < n. You can use
"with" for this, as discussed in Section 4.3.3 (page 86) of the book.
-}
-- [10 points]
glb : ∀ d' d n → d' ≤ d ≡ tt → d' ≤ n ≡ tt → d' ≤ min d n ≡ tt
glb d' d n x y with keep (d < n)
... | tt , p rewrite p = x
... | ff , p rewrite p = y
{- insert d xs should insert d into xs as the right position to keep the list
sorted.
So you will case split on xs (the sortedList), and in the cons case,
consider whether the data you are inserting is ≤ the data at the head of the
list.
I found I needed to use the "with keep" idiom; see Section 4.3.3 (page 90).
Another hint: I also needed a few theorems from nat-thms.agda in the IAL:
<≤, min-mono2, <ff
Note that you can pattern match on implicit arguments, for example for a cons, like this:
(cons d' {n} xs x)
The {n} is used to match on that implicit lower-bound for the sortedList xs.
[15 points]
-}
insert : ∀ (d : ℕ) → {n : ℕ} → sortedList n → sortedList (min d n)
insert d (nil n) with keep ( d < n )
... | tt , p rewrite p = cons d (nil n) (<≤ {d} p)
... | ff , p rewrite p = weaken n (cons d (nil d) (≤-refl d)) (<ff {d} p)
insert d (cons d1 {n} xs x) with keep ( d < d1 )
... | tt , p rewrite p = cons d ( cons d1 {n} xs x ) ( <≤ {d} {d1} p )
... | ff , p rewrite p = cons d1 (nil d) (<ff {d} {d1} p )
insert d (weaken d1 {n} xs x) with keep ( d < d1 )
... | tt , p rewrite p = cons d ( weaken d1 xs x ) ( <≤ {d} p )
... | ff , p rewrite p = weaken d1 (insert d xs) (glb d1 d n (<ff {d} p) x)
{- Write code to merge two sorted lists.
I found I needed these lemmas from the IAL:
min-<1, min-<2, <ff, <≤
Additionally, I found I could save myself some cases by considering these cases for two input lists:
nil and ys
xs and nil
weaken and ys
xs and weaken
cons and cons
This is just five cases, instead of the nine that would be required if you considered the three
cases for the first list simultaneously with the three for the second (3 * 3 gives 9 cases).
You will see light gray highlighting on the patterns in the cases if you do this, but that
is ok (it is just Agda warning you that you are not breaking out all the cases explicitly).
[20 points]
-}
merge : ∀ {n : ℕ} → sortedList n → {m : ℕ} → sortedList m → sortedList (min n m)
merge (nil d) (nil d1) with keep ( d < d1 )
... | tt , p rewrite p = weaken d (nil d1) (<≤ {d} p)
... | ff , p rewrite p = weaken d1 (nil d) (<ff {d} p)
merge (nil d) (cons d1 d1s pd1) with keep ( d < d1 )
... | tt , p rewrite p = weaken d (cons d1 d1s pd1 ) ( <≤ {d} p)
... | ff , p rewrite p = cons d1 d1s pd1
merge ( nil d ) ( weaken d1 d1s pd1 ) with keep ( d < d1 )
... | tt , p rewrite p = weaken d ( weaken d1 d1s pd1 ) ( <≤ {d} p )
... | ff , p rewrite p = weaken d1 d1s pd1
merge ( cons d ds pd ) ( nil d1 ) with keep ( d < d1 )
... | tt , p rewrite p = cons d ds pd
... | ff , p rewrite p = weaken d1 ( cons d ds pd ) ( <ff {d} p )
merge ( cons d {dn} ds pd ) ( cons d1 {d1n} d1s pd1 ) with keep ( d < d1 )
... | tt , p rewrite p = cons d ( merge ds ( cons d1 d1s pd1 ) ) ( glb d dn d1 pd ( <≤ {d} p ) )
... | ff , p rewrite p = cons d1 ( merge d1s ( cons d ds pd) ) ( glb d1 d1n d pd1 ( <ff {d} p ) )
merge ( cons d {dn} ds pd ) ( weaken d1 {d1n} d1s pd1 ) with keep ( d < d1 )
... | tt , p rewrite p = cons d ( merge ds ( weaken d1 d1s pd1 ) ) ( glb d dn d1 pd ( <≤ {d} p ) )
... | ff , p rewrite p = weaken d1 ( merge d1s ( cons d ds pd ) ) ( glb d1 d1n d pd1 ( <ff {d} p ) )
merge ( weaken d ds pd ) ( nil d1 ) with keep ( d < d1 )
... | tt , p rewrite p = weaken d ds pd
... | ff , p rewrite p = weaken d1 ( weaken d ds pd ) ( <ff {d} p )
merge ( weaken d {dn} ds pd ) ( cons d1 {d1n} d1s pd1 ) with keep ( d < d1 )
... | tt , p rewrite p = weaken d ( merge ds ( cons d1 d1s pd1 ) ) ( glb d dn d1 pd ( <≤ {d} p ) )
... | ff , p rewrite p = cons d1 ( merge d1s ( weaken d ds pd ) ) ( glb d1 d1n d pd1 ( <ff {d} p ) )
merge ( weaken d {dn} ds pd ) ( weaken d1 {d1n} d1s pd1 ) with keep ( d < d1 )
... | tt , p rewrite p = weaken d ( merge ds ( weaken d1 d1s pd1 ) ) ( glb d dn d1 pd ( <≤ {d} p ) )
... | ff , p rewrite p = weaken d1 ( merge d1s ( weaken d ds pd ) ) ( glb d1 d1n d pd1 ( <ff {d} p ) )
|
{
"alphanum_fraction": 0.5939664461,
"avg_line_length": 45.7535211268,
"ext": "agda",
"hexsha": "f212eb188119d0acadae463363780beb15df7180",
"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": "c2da60d7becdbb809aae20e7a6df6ea509b991c5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout8",
"max_forks_repo_path": "sortedLists.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c2da60d7becdbb809aae20e7a6df6ea509b991c5",
"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": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout8",
"max_issues_repo_path": "sortedLists.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c2da60d7becdbb809aae20e7a6df6ea509b991c5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DTMcNamara/CS3820-ProgrammingLanguageConcepts-Workout8",
"max_stars_repo_path": "sortedLists.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2112,
"size": 6497
}
|
-- Andreas, 2016-06-01, issue 1997 reported by Andres
{-# OPTIONS --rewriting #-}
infix 4 _≡_
infixl 6 _+_
data _≡_ {a} {A : Set a} (x : A) : A → Set a where
refl : x ≡ x
{-# BUILTIN REWRITE _≡_ #-}
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
data ℕ : Set where
zero : ℕ
suc : (n : ℕ) → ℕ
_+_ : ℕ → ℕ → ℕ
zero + m = m
suc n + m = suc (n + m)
plus0 : (x : ℕ) → x + zero ≡ x
plus0 zero = refl
plus0 (suc x) = cong suc (plus0 x)
{-# REWRITE plus0 #-}
{-# REWRITE plus0 #-}
-- Should complain about duplicate rewrite rule
|
{
"alphanum_fraction": 0.5258764608,
"avg_line_length": 18.1515151515,
"ext": "agda",
"hexsha": "e01f9afc9bd9bc35a097c2d07bcc7c2257efe559",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Succeed/Issue1997.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Succeed/Issue1997.agda",
"max_line_length": 53,
"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/Succeed/Issue1997.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": 247,
"size": 599
}
|
open import Relation.Binary.Core
module Mergesort.Impl2.Correctness.Order {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.List
open import Function using (_∘_)
open import List.Sorted _≤_
open import Mergesort.Impl2 _≤_ tot≤
open import OList _≤_
open import OList.Properties _≤_
theorem-mergesort-sorted : (xs : List A) → Sorted (forget (mergesort xs))
theorem-mergesort-sorted = lemma-olist-sorted ∘ mergesort
|
{
"alphanum_fraction": 0.6855345912,
"avg_line_length": 29.8125,
"ext": "agda",
"hexsha": "3b4c63dc6a55cdbcdba75f82b296a4a0586389f4",
"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": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/Mergesort/Impl2/Correctness/Order.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"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": "bgbianchi/sorting",
"max_issues_repo_path": "agda/Mergesort/Impl2/Correctness/Order.agda",
"max_line_length": 73,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/Mergesort/Impl2/Correctness/Order.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 148,
"size": 477
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Functor
module Categories.Diagram.Limit.Properties
{o ℓ e} {o′ ℓ′ e′} {C : Category o ℓ e} {J : Category o′ ℓ′ e′} where
open import Function.Equality using (Π)
open import Relation.Binary using (Setoid)
open import Categories.Category.Instance.Setoids
open import Categories.Diagram.Cone.Properties
open import Categories.Functor.Hom
open import Categories.NaturalTransformation.NaturalIsomorphism using (NaturalIsomorphism; _≃_; module ≃)
open import Categories.Morphism.Reasoning C
open import Categories.Morphism C
import Categories.Category.Construction.Cones as Con
import Categories.Diagram.Limit as Lim
open Π
open Hom C
private
module J = Category J
module C = Category C
open C
variable
X Y Z : Obj
f g h : X ⇒ Y
open HomReasoning
-- Hom functor preserves limits in C
module _ (W : Obj) {F : Functor J C} (lim : Lim.Limit F) where
private
module F = Functor F
module LF = Lim F
module CF = Con F
module lim = LF.Limit lim
open lim
HomF : Functor J (Setoids ℓ e)
HomF = Hom[ W ,-] ∘F F
module LHomF = Lim HomF
module CHomF = Con HomF
hom-resp-limit : LHomF.Limit
hom-resp-limit = record
{ terminal = record
{ ⊤ = ⊤
; ! = !
; !-unique = !-unique
}
}
where ⊤ : CHomF.Cone
⊤ = record
{ N = hom-setoid {W} {apex}
; apex = record
{ ψ = λ X → record
{ _⟨$⟩_ = λ f → proj X ∘ f
; cong = ∘-resp-≈ʳ
}
; commute = λ {X Y} f {h i} eq → begin
F.F₁ f ∘ (proj X ∘ h) ∘ C.id ≈⟨ center⁻¹ (limit-commute f) identityʳ ⟩
proj Y ∘ h ≈⟨ refl⟩∘⟨ eq ⟩
proj Y ∘ i ∎
}
}
KW : (K : CHomF.Cone) → Setoid.Carrier (CHomF.Cone.N K) → CF.Cone
KW K x = record
{ N = W
; apex = record
{ ψ = λ X → K.ψ X ⟨$⟩ x
; commute = λ f → sym (∘-resp-≈ʳ identityʳ) ○ K.commute f (Setoid.refl K.N)
}
}
where module K = CHomF.Cone K
! : ∀ {K : CHomF.Cone} → CHomF.Cones [ K , ⊤ ]
! {K} = record
{ arr = record
{ _⟨$⟩_ = λ x → rep (KW K x)
; cong = λ {x y} eq → LF.ψ-≈⇒rep-≈ W (CF.Cone.apex (KW K x)) (CF.Cone.apex (KW K y)) lim
(λ A → cong (K.ψ A) eq)
}
; commute = λ {X} {x y} eq → begin
proj X ∘ rep (KW K x) ≈⟨ lim.commute ⟩
K.ψ X ⟨$⟩ x ≈⟨ cong (K.ψ X) eq ⟩
K.ψ X ⟨$⟩ y ∎
}
where module K = CHomF.Cone K
!-unique : ∀ {K : CHomF.Cone} (f : CHomF.Cones [ K , ⊤ ]) → CHomF.Cones [ ! ≈ f ]
!-unique {K} f {x} {y} x≈y = begin
rep (KW K x) ≈⟨ terminal.!-unique f′ ⟩
f.arr ⟨$⟩ x ≈⟨ cong f.arr x≈y ⟩
f.arr ⟨$⟩ y ∎
where module K = CHomF.Cone K
module f = CHomF.Cone⇒ f
f′ : CF.Cones [ KW K x , limit ]
f′ = record
{ arr = f.arr ⟨$⟩ x
; commute = f.commute (Setoid.refl K.N)
}
-- natural isomorphisms respects limits
module _ {F G : Functor J C} (F≃G : F ≃ G) where
private
module F = Functor F
module G = Functor G
module LF = Lim F
module LG = Lim G
open NaturalIsomorphism F≃G
≃-resp-lim : LF.Limit → LG.Limit
≃-resp-lim L = record
{ terminal = record
{ ⊤ = record
{ apex = record
{ ψ = λ j → ⇒.η j ∘ proj j
; commute = λ {X Y} f → begin
G.F₁ f ∘ ⇒.η X ∘ proj X ≈⟨ pullˡ (⇒.sym-commute f) ⟩
(⇒.η Y ∘ F.F₁ f) ∘ proj X ≈⟨ pullʳ (limit-commute f) ⟩
⇒.η Y ∘ proj Y ∎
}
}
; ! = λ {A} → record
{ arr = rep (nat-map-Cone F⇐G A)
; commute = λ {j} → assoc ○ ⟺ (switch-tofromˡ (record { iso = iso j }) (⟺ commute))
}
; !-unique = λ {K} f →
let module f = Con.Cone⇒ G f
in terminal.!-unique record
{ arr = f.arr
; commute = λ {j} → switch-fromtoˡ (record { iso = iso j }) (sym-assoc ○ f.commute)
}
}
}
where open LF.Limit L
≃⇒Cone⇒ : ∀ (Lf : LF.Limit) (Lg : LG.Limit) → Con.Cones G [ LG.Limit.limit (≃-resp-lim Lf) , LG.Limit.limit Lg ]
≃⇒Cone⇒ Lf Lg = rep-cone (LG.Limit.limit (≃-resp-lim Lf))
where open LG.Limit Lg
≃⇒lim≅ : ∀ {F G : Functor J C} (F≃G : F ≃ G) (Lf : Lim.Limit F) (Lg : Lim.Limit G) → Lim.Limit.apex Lf ≅ Lim.Limit.apex Lg
≃⇒lim≅ {F = F} {G} F≃G Lf Lg = record
{ from = arr (≃⇒Cone⇒ F≃G Lf Lg)
; to = arr (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf)
; iso = record
{ isoˡ = Lf.terminal.⊤-id record
{ commute = λ {j} → begin
Lf.proj j ∘ arr (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf) ∘ arr (≃⇒Cone⇒ F≃G Lf Lg) ≈⟨ pullˡ (⇒-commute (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf)) ⟩
(⇐.η j ∘ Lg.proj j) ∘ arr (≃⇒Cone⇒ F≃G Lf Lg) ≈⟨ pullʳ (⇒-commute (≃⇒Cone⇒ F≃G Lf Lg)) ⟩
⇐.η j ∘ ⇒.η j ∘ Lf.proj j ≈⟨ cancelˡ (iso.isoˡ j) ⟩
Lf.proj j ∎
}
; isoʳ = Lg.terminal.⊤-id record
{ commute = λ {j} → begin
Lg.proj j ∘ arr (≃⇒Cone⇒ F≃G Lf Lg) ∘ arr (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf) ≈⟨ pullˡ (⇒-commute (≃⇒Cone⇒ F≃G Lf Lg)) ⟩
(⇒.η j ∘ Lf.proj j) ∘ arr (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf) ≈⟨ pullʳ (⇒-commute (≃⇒Cone⇒ (≃.sym F≃G) Lg Lf)) ⟩
⇒.η j ∘ ⇐.η j ∘ Lg.proj j ≈⟨ cancelˡ (iso.isoʳ j) ⟩
Lg.proj j ∎
}
}
}
where open Con.Cone⇒ renaming (commute to ⇒-commute)
module Lf = Lim.Limit Lf
module Lg = Lim.Limit Lg
open NaturalIsomorphism F≃G
|
{
"alphanum_fraction": 0.4535882067,
"avg_line_length": 35.0738636364,
"ext": "agda",
"hexsha": "c68386cc02155766d00ff5a6e8de6c7c290725f7",
"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": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Limit/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"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": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Limit/Properties.agda",
"max_line_length": 128,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Limit/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2320,
"size": 6173
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.