Search is not available for this dataset
text
string | meta
dict |
---|---|
-- For the first task, we are asked to prove that max is idempotent and
-- associative. The proves presented in this file are as succint as they
-- possibly can. The proves come with added comments to aid understanding as
-- the proves are meant to be short and simple but not very legible. The
-- solution to task 1 starts in lines 44 and 51.
module sv20.assign2.First where
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; trans; cong)
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Nat using (_≤_; z≤n; s≤s; _<_)
open import Relation.Nullary using (¬_)
open import Data.Empty using (⊥-elim)
open import Function using (_∘_)
-- First, we define the max function. Notice, how the function differs from the
-- definition offered for the assignment
max : ℕ → ℕ → ℕ
max zero n = n
max (suc m) zero = suc m
max (suc m) (suc n) = suc (max m n)
-- Nonetheless, we can prove that the definition of max presented in the
-- assignment follows from ours.
-- In athena, the first part of the definition corresponds to the sentence
-- "y < x ==> x max y = x", which translated into Agda corresponds to:
less : ∀ {x y} → y < x → max x y ≡ x
-- and it is easily proven by:
less {zero} () -- Nonesense case
less {suc m} {zero} (s≤s z≤n) = refl -- Simplest case, y ≡ 0
less {suc m} {suc n} (s≤s n<m) = cong suc (less n<m) -- if "n < m → max m n ≡ m" then "suc n < suc m → max (suc m) (suc n) ≡ (suc m)"
-- The second part of the definition asserts (in Athena) that
-- "~ y < x ==> x max y = y"
not-less : ∀ {x y} → ¬ (y < x) → max x y ≡ y
-- which is easily proven by induction with:
not-less {zero} {n} ¬y<x = refl -- Base case 1
not-less {suc m} {zero} ¬z<sm = ⊥-elim (¬z<sm (s≤s z≤n)) -- Base case 2
not-less {suc m} {suc n} ¬sn<sm = cong suc (not-less (¬sn<sm ∘ s≤s)) -- Inductive case
--not-less {suc m} {suc n} ¬sn<sm = cong suc (not-less {m} {n} (λ n<m → ¬sn<sm (s≤s n<m)))
-- The pattern ¬sn<sm ∘ s≤s means that you are creating a function ¬n<m from ¬sn<sm
-- SOLUTIONS
-- max is idempotent
-- By induction:
max-idem : ∀ x → max x x ≡ x
max-idem zero = refl -- Base case: max 0 0 ≡ 0
max-idem (suc n) = cong suc (max-idem n) -- Inductive case: if "max n n ≡ n" then "max (suc n) (suc n) ≡ suc n" because "max (suc n) (suc n) ≡ suc (max n n)"
-- max is associative
-- By induction:
max-assoc : ∀ x y z → max x (max y z) ≡ max (max x y) z
max-assoc zero _ _ = refl -- Base cases: when one of the numbers is 0, then "max 0 n ≡ n" by definition of max
max-assoc (suc m) zero _ = refl --
max-assoc (suc m) (suc n) zero = refl --
max-assoc (suc m) (suc n) (suc o) = cong suc (max-assoc m n o) -- Inductive case: if "max m (max n o) ≡ max (max m n) o" then "max (suc m) (max (suc n) (suc o)) ≡ suc (max m (max n o)) ≡ suc (max (max m n) o) ≡ max (max (suc m) (suc n)) (suc o)"
| {
"alphanum_fraction": 0.6208088489,
"avg_line_length": 50.7543859649,
"ext": "agda",
"hexsha": "fbd4be5763e0b9a94611c3f764d5c78a7080145b",
"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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/sv20/assign2/First.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/sv20/assign2/First.agda",
"max_line_length": 245,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/sv20/assign2/First.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1026,
"size": 2893
} |
module PiFrac.Examples where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Data.Nat
open import Relation.Binary.Core
open import Relation.Binary
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Data.Maybe
open import PiFrac.Syntax
open import PiFrac.Opsem
open import PiFrac.Eval
-----------------------------------------------------------------------------
-- Patterns and data definitions
pattern 𝔹 = 𝟙 +ᵤ 𝟙
pattern 𝔽 = inj₁ tt
pattern 𝕋 = inj₂ tt
𝔹^ : ℕ → 𝕌
𝔹^ 0 = 𝟙
𝔹^ 1 = 𝔹
𝔹^ (suc (suc n)) = 𝔹 ×ᵤ 𝔹^ (suc n)
-----------------------------------------------------------------------------
-- Adaptors
[A+B]+C=[C+B]+A : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (C +ᵤ B) +ᵤ A
[A+B]+C=[C+B]+A = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ swap₊
[A+B]+C=[A+C]+B : ∀ {A B C} → (A +ᵤ B) +ᵤ C ↔ (A +ᵤ C) +ᵤ B
[A+B]+C=[A+C]+B = assocr₊ ⨾ (id↔ ⊕ swap₊) ⨾ assocl₊
[A+B]+[C+D]=[A+C]+[B+D] : {A B C D : 𝕌} → (A +ᵤ B) +ᵤ (C +ᵤ D) ↔ (A +ᵤ C) +ᵤ (B +ᵤ D)
[A+B]+[C+D]=[A+C]+[B+D] = assocl₊ ⨾ (assocr₊ ⊕ id↔) ⨾ ((id↔ ⊕ swap₊) ⊕ id↔) ⨾ (assocl₊ ⊕ id↔) ⨾ assocr₊
Ax[BxC]=Bx[AxC] : {A B C : 𝕌} → A ×ᵤ (B ×ᵤ C) ↔ B ×ᵤ (A ×ᵤ C)
Ax[BxC]=Bx[AxC] = assocl⋆ ⨾ (swap⋆ ⊗ id↔) ⨾ assocr⋆
[AxB]×C=[A×C]xB : ∀ {A B C} → (A ×ᵤ B) ×ᵤ C ↔ (A ×ᵤ C) ×ᵤ B
[AxB]×C=[A×C]xB = assocr⋆ ⨾ (id↔ ⊗ swap⋆) ⨾ assocl⋆
[A×B]×[C×D]=[A×C]×[B×D] : {A B C D : 𝕌} → (A ×ᵤ B) ×ᵤ (C ×ᵤ D) ↔ (A ×ᵤ C) ×ᵤ (B ×ᵤ D)
[A×B]×[C×D]=[A×C]×[B×D] = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ swap⋆) ⊗ id↔) ⨾ (assocl⋆ ⊗ id↔) ⨾ assocr⋆
-- CNOT(b₁,b₂) = (b₁,b₁ xor b₂)
CNOT : 𝔹 ×ᵤ 𝔹 ↔ 𝔹 ×ᵤ 𝔹
CNOT = dist ⨾ (id↔ ⊕ (id↔ ⊗ swap₊)) ⨾ factor
-- Trace
trace⋆ : ∀ {A B C} → (c : ⟦ C ⟧) → A ×ᵤ C ↔ B ×ᵤ C → A ↔ B
trace⋆ c f = uniti⋆r ⨾ (id↔ ⊗ ηₓ c) ⨾ assocl⋆ ⨾
(f ⊗ id↔) ⨾
assocr⋆ ⨾ (id↔ ⊗ εₓ _) ⨾ unite⋆r
ex1 ex2 : Maybe ⟦ 𝟙 +ᵤ 𝟙 ⟧
ex1 = eval (trace⋆ (inj₁ tt) swap⋆) (inj₁ tt) -- just (inj₁ tt)
ex2 = eval (trace⋆ (inj₁ tt) swap⋆) (inj₂ tt) -- nothing
-----------------------------------------------------------------------------
-- Higher-Order Combinators
hof/ : {A B : 𝕌} → (A ↔ B) → (v : ⟦ A ⟧) → (𝟙 ↔ 𝟙/ v ×ᵤ B)
hof/ c v = ηₓ v ⨾ (c ⊗ id↔) ⨾ swap⋆
comp/ : {A B C : 𝕌} {v : ⟦ A ⟧} → (w : ⟦ B ⟧) →
(𝟙/ v ×ᵤ B) ×ᵤ (𝟙/ w ×ᵤ C) ↔ (𝟙/ v ×ᵤ C)
comp/ w = assocl⋆ ⨾ (assocr⋆ ⊗ id↔) ⨾ ((id↔ ⊗ εₓ w) ⊗ id↔) ⨾ (unite⋆r ⊗ id↔)
app/ : {A B : 𝕌} → (v : ⟦ A ⟧) → (𝟙/ v ×ᵤ B) ×ᵤ A ↔ B
app/ v = swap⋆ ⨾ assocl⋆ ⨾ (εₓ _ ⊗ id↔) ⨾ unite⋆l
curry/ : {A B C : 𝕌} → (A ×ᵤ B ↔ C) → (v : ⟦ B ⟧) → (A ↔ 𝟙/ v ×ᵤ C)
curry/ c v = uniti⋆l ⨾ (ηₓ v ⊗ id↔) ⨾ swap⋆ ⨾ assocl⋆ ⨾ (c ⊗ id↔) ⨾ swap⋆
-- h.o. version of cnot specialized to input input (v , w)
htf : ∀ (v w : _) → 𝟙 ↔ 𝟙/ (v , w) ×ᵤ (𝔹 ×ᵤ 𝔹)
htf v w = hof/ CNOT (v , w)
-- applying htf to incoming input
htfc : ∀ (v w : _) → (𝔹 ×ᵤ 𝔹) ↔ (𝔹 ×ᵤ 𝔹)
htfc v w = uniti⋆l ⨾ (htf v w ⊗ id↔) ⨾ app/ (v , w)
htfca : ⟦ 𝔹 ×ᵤ 𝔹 ⟧ → Maybe ⟦ 𝔹 ×ᵤ 𝔹 ⟧
htfca (v , w) = eval (htfc v w) (v , w)
x1 x2 x3 x4 : Maybe ⟦ 𝔹 ×ᵤ 𝔹 ⟧
x1 = htfca (𝔽 , 𝔽) -- just (𝔽 , 𝔽)
x2 = htfca (𝔽 , 𝕋) -- just (𝔽 , 𝕋)
x3 = htfca (𝕋 , 𝔽) -- just (𝕋 , 𝕋)
x4 = htfca (𝕋 , 𝕋) -- just (𝕋 , 𝔽)
-----------------------------------------------------------------------------
-- Algebraic Identities
inv/ : {A : 𝕌} {v : ⟦ A ⟧} → A ↔ (𝟙/_ {𝟙/ v} ↻)
inv/ = uniti⋆r ⨾ (id↔ ⊗ ηₓ _) ⨾ assocl⋆ ⨾ (εₓ _ ⊗ id↔) ⨾ unite⋆l
dist/ : {A B : 𝕌} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → 𝟙/ (a , b) ↔ 𝟙/ a ×ᵤ 𝟙/ b
dist/ {A} {B} {a} {b} =
uniti⋆l ⨾ (ηₓ b ⊗ id↔) ⨾ uniti⋆l ⨾ (ηₓ a ⊗ id↔) ⨾ assocl⋆ ⨾
([A×B]×[C×D]=[A×C]×[B×D] ⊗ id↔) ⨾
(swap⋆ ⊗ id↔) ⨾ assocr⋆ ⨾ (id↔ ⊗ εₓ (a , b)) ⨾ unite⋆r
neg/ : {A B : 𝕌} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → (A ↔ B) → (𝟙/ a ↔ 𝟙/ b)
neg/ {A} {B} {a} {b} c =
uniti⋆r ⨾ (id↔ ⊗ ηₓ _) ⨾
(id↔ ⊗ (! c) ⊗ id↔) ⨾ assocl⋆ ⨾
((swap⋆ ⨾ εₓ _) ⊗ id↔) ⨾ unite⋆l
fracDist : ∀ {A B} {a : ⟦ A ⟧} {b : ⟦ B ⟧} → 𝟙/ a ×ᵤ 𝟙/ b ↔ 𝟙/ (a , b)
fracDist =
uniti⋆l ⨾ ((ηₓ _ ⨾ swap⋆) ⊗ id↔) ⨾ assocr⋆ ⨾
(id↔ ⊗ ([A×B]×[C×D]=[A×C]×[B×D] ⨾ (εₓ _ ⊗ εₓ _) ⨾ unite⋆l)) ⨾ unite⋆r
mulFrac : ∀ {A B C D} {b : ⟦ B ⟧} {d : ⟦ D ⟧}
→ (A ×ᵤ 𝟙/ b) ×ᵤ (C ×ᵤ 𝟙/ d) ↔ (A ×ᵤ C) ×ᵤ (𝟙/ (b , d))
mulFrac = [A×B]×[C×D]=[A×C]×[B×D] ⨾ (id↔ ⊗ fracDist)
addFracCom : ∀ {A B C} {v : ⟦ C ⟧}
→ (A ×ᵤ 𝟙/ v) +ᵤ (B ×ᵤ 𝟙/ v) ↔ (A +ᵤ B) ×ᵤ (𝟙/ v)
addFracCom = factor
addFrac : ∀ {A B C D} → (v : ⟦ C ⟧) → (w : ⟦ D ⟧)
→ (A ×ᵤ 𝟙/_ {C} v) +ᵤ (B ×ᵤ 𝟙/_ {D} w) ↔
((A ×ᵤ D) +ᵤ (C ×ᵤ B)) ×ᵤ (𝟙/_ {C ×ᵤ D} (v , w))
addFrac v w = ((uniti⋆r ⨾ (id↔ ⊗ ηₓ w)) ⊕ (uniti⋆l ⨾ (ηₓ v ⊗ id↔))) ⨾
[A×B]×[C×D]=[A×C]×[B×D] ⊕ [A×B]×[C×D]=[A×C]×[B×D] ⨾
((id↔ ⊗ fracDist) ⊕ (id↔ ⊗ fracDist)) ⨾ factor
| {
"alphanum_fraction": 0.4122977346,
"avg_line_length": 34.8496240602,
"ext": "agda",
"hexsha": "016251245ced9595fd206c4eb1b2a13baa26dcd0",
"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": "PiFrac/Examples.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": "PiFrac/Examples.agda",
"max_line_length": 103,
"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": "PiFrac/Examples.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": 2915,
"size": 4635
} |
------------------------------------------------------------------------------
-- The map-iterate property: A property using co-induction
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
-- The map-iterate property (Gibbons and Hutton, 2005):
-- map f (iterate f x) = iterate f (f · x)
module FOTC.Program.MapIterate.MapIterateATP where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List
open import FOTC.Relation.Binary.Bisimilarity.Type
------------------------------------------------------------------------------
-- The map-iterate property.
≈-map-iterate : ∀ f x → map f (iterate f x) ≈ iterate f (f · x)
≈-map-iterate f x = ≈-coind B h₁ h₂
where
-- Based on the relation used by (Giménez and Castéran, 2007).
B : D → D → Set
B xs ys = ∃[ y ] xs ≡ map f (iterate f y) ∧ ys ≡ iterate f (f · y)
{-# ATP definition B #-}
postulate
h₁ : ∀ {xs} {ys} → B xs ys →
∃[ x' ] ∃[ xs' ] ∃[ ys' ] xs ≡ x' ∷ xs' ∧ ys ≡ x' ∷ ys' ∧ B xs' ys'
{-# ATP prove h₁ #-}
postulate h₂ : B (map f (iterate f x)) (iterate f (f · x))
{-# ATP prove h₂ #-}
------------------------------------------------------------------------------
-- References
--
-- Giménez, Eduardo and Casterán, Pierre (2007). A Tutorial on
-- [Co-]Inductive Types in Coq.
--
-- Gibbons, Jeremy and Hutton, Graham (2005). Proof Methods for
-- Corecursive Programs. Fundamenta Informaticae XX, pp. 1–14.
| {
"alphanum_fraction": 0.4879555281,
"avg_line_length": 35.1956521739,
"ext": "agda",
"hexsha": "330d088cf516533bcb6bb16e51bc6d1bf19917e9",
"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/MapIterate/MapIterateATP.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/MapIterate/MapIterateATP.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/MapIterate/MapIterateATP.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": 446,
"size": 1619
} |
open import Prelude
open import Nat
open import Bij
module NatDelta where
instance
NatBij : bij Nat Nat
NatBij = record {
convert = λ n → n;
inj = λ n → n;
surj = λ n → n , refl}
open import Delta Nat {{NatBij}}
nat-dd = dd
| {
"alphanum_fraction": 0.5805243446,
"avg_line_length": 15.7058823529,
"ext": "agda",
"hexsha": "ee04a375c2de868a829b8b16e8471d70a63e9220",
"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": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nickcollins/dependent-dicts-agda",
"max_forks_repo_path": "NatDelta.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"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": "nickcollins/dependent-dicts-agda",
"max_issues_repo_path": "NatDelta.agda",
"max_line_length": 34,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "db857f3e7dc9a4793f68504e6365d93ed75d7f88",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nickcollins/dependent-dicts-agda",
"max_stars_repo_path": "NatDelta.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 81,
"size": 267
} |
module Utils.HaskellTypes where
postulate String : Set
{-# BUILTIN STRING String #-}
data Unit : Set where
triv : Unit
{-# COMPILED_DATA Unit () () #-}
data Prod (A : Set) (B : Set) : Set where
_,_ : A → B → Prod A B
{-# COMPILED_DATA Prod (,) (,) #-}
data Triple (A B C : Set) : Set where
triple : A → B → C → Triple A B C
{-# COMPILED_DATA Triple (,,) (,,) #-}
infixr 20 _::_
data List (A : Set) : Set where
[] : List A
_::_ : A → List A → List A
{-# COMPILED_DATA List [] [] (:) #-}
| {
"alphanum_fraction": 0.5648702595,
"avg_line_length": 21.7826086957,
"ext": "agda",
"hexsha": "04de9d8cc372135f00b2c50a1c59af7562a119ad",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "heades/Agda-LLS",
"max_forks_repo_path": "Source/ALL/Utils/HaskellTypes.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "heades/Agda-LLS",
"max_issues_repo_path": "Source/ALL/Utils/HaskellTypes.agda",
"max_line_length": 41,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "heades/Agda-LLS",
"max_stars_repo_path": "Source/ALL/Utils/HaskellTypes.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z",
"num_tokens": 167,
"size": 501
} |
module Numeral.Natural.Relation.DivisibilityWithRemainder.Proofs where
import Lvl
open import Data
open import Data.Boolean.Stmt
open import Functional
open import Logic.Predicate
open import Logic.Propositional
open import Numeral.Finite
import Numeral.Finite.Proofs as 𝕟
open import Numeral.Natural
open import Numeral.Natural.Inductions
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation.DivisibilityWithRemainder hiding (base₀ ; base₊ ; step)
open import Numeral.Natural.Relation.Order.Decidable
open import Numeral.Natural.Relation.Order.Proofs
open import Numeral.Natural.Relation.Order
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Function
open import Structure.Operator
open import Structure.Operator.Proofs.Util
open import Structure.Relator
open import Syntax.Transitivity
open import Type.Properties.Decidable.Proofs
-- 0 does not divide anything with any remainder.
[∣ᵣₑₘ]-0-divides : ∀{x}{r} → ¬(0 ∣ᵣₑₘ x)(r)
[∣ᵣₑₘ]-0-divides {r = ()}
-- 1 divides everything with the only possible remainder 0.
[∣ᵣₑₘ]-1-divides : ∀{x}{r} → (1 ∣ᵣₑₘ x)(r)
[∣ᵣₑₘ]-1-divides {𝟎} {r = 𝟎} = DivRem𝟎
[∣ᵣₑₘ]-1-divides {𝐒 x} {r = 𝟎} = DivRem𝐒 [∣ᵣₑₘ]-1-divides
-- The quotient is the dividend when divided by 1.
[∣ᵣₑₘ]-quotient-of-1 : ∀{x}{r} → (p : (1 ∣ᵣₑₘ x)(r)) → ([∣ᵣₑₘ]-quotient p ≡ x)
[∣ᵣₑₘ]-quotient-of-1 {𝟎} {𝟎} DivRem𝟎 = [≡]-intro
[∣ᵣₑₘ]-quotient-of-1 {𝐒 x}{𝟎} (DivRem𝐒 p) = [≡]-with(𝐒) ([∣ᵣₑₘ]-quotient-of-1 {x}{𝟎} p)
-- [∣ᵣₑₘ]-remainder-dividend : ∀{x y}{r : 𝕟(y)} → (x < y) → (y ∣ᵣₑₘ x)(r) → (x ≡ 𝕟-to-ℕ r)
-- How the arguments in the divisibility relation is related to each other by elementary functions.
-- Note: The division theorem is proven using this. By proving that [∣ᵣₑₘ]-quotient and [∣ᵣₑₘ]-remainder is equal to the algorithmic functions of floored division and modulo, the theorem follows directly from this.
[∣ᵣₑₘ]-is-division-with-remainder : ∀{x y}{r} → (p : (y ∣ᵣₑₘ x)(r)) → ((([∣ᵣₑₘ]-quotient p) ⋅ y) + (𝕟-to-ℕ ([∣ᵣₑₘ]-remainder p)) ≡ x)
[∣ᵣₑₘ]-is-division-with-remainder {𝟎} {_} {𝟎} DivRem𝟎 = [≡]-intro
[∣ᵣₑₘ]-is-division-with-remainder {𝐒 .(x + y)} {𝐒 y} {𝟎} (DivRem𝐒 {x = x} p) =
𝐒([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y) 🝖[ _≡_ ]-[ [⋅]-with-[𝐒]ₗ {[∣ᵣₑₘ]-quotient p}{𝐒(y)} ]
(([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + 𝐒(y) 🝖[ _≡_ ]-[]
𝐒((([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + y) 🝖[ _≡_ ]-[ congruence₁(𝐒) (congruence₂ₗ(_+_)(y) ([∣ᵣₑₘ]-is-division-with-remainder p)) ]
𝐒(x + y) 🝖-end
[∣ᵣₑₘ]-is-division-with-remainder {𝐒 .(𝕟-to-ℕ r)} {𝐒 y} {𝐒 r} DivRem𝟎 = [≡]-intro
[∣ᵣₑₘ]-is-division-with-remainder {𝐒 .(x + y)} {𝐒(y@(𝐒 _))} {r@(𝐒 _)} (DivRem𝐒 {x = x} p) =
(([∣ᵣₑₘ]-quotient (DivRem𝐒 p)) ⋅ 𝐒(y)) + (𝕟-to-ℕ r) 🝖[ _≡_ ]-[]
(𝐒([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + (𝕟-to-ℕ r) 🝖[ _≡_ ]-[ congruence₂ₗ(_+_)(𝕟-to-ℕ r) ([⋅]-with-[𝐒]ₗ {[∣ᵣₑₘ]-quotient p}{𝐒(y)}) ]
((([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + 𝐒(y)) + (𝕟-to-ℕ r) 🝖[ _≡_ ]-[ One.commuteᵣ-assocₗ {a = ([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)}{b = 𝐒(y)}{c = 𝕟-to-ℕ r} ]
((([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + (𝕟-to-ℕ r)) + 𝐒(y) 🝖[ _≡_ ]-[]
𝐒(((([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + (𝕟-to-ℕ r)) + y) 🝖[ _≡_ ]-[ congruence₁(𝐒) (congruence₂ₗ(_+_)(y) ([∣ᵣₑₘ]-is-division-with-remainder p)) ]
𝐒(x + y) 🝖-end
-- When the arguments in the divisibility relation are related to each other.
-- This also indicates that the divisibility relation actually states something about divisibility in the sense of the inverse of multiplication.
[∣ᵣₑₘ]-equivalence : ∀{x y}{r} → (y ∣ᵣₑₘ x)(r) ↔ ∃(q ↦ (q ⋅ y) + (𝕟-to-ℕ r) ≡ x)
[∣ᵣₑₘ]-equivalence = [↔]-intro (p ↦ l {q = [∃]-witness p} ([∃]-proof p)) (p ↦ [∃]-intro ([∣ᵣₑₘ]-quotient p) ⦃ [∣ᵣₑₘ]-is-division-with-remainder p ⦄) where
l : ∀{x y q}{r} → ((q ⋅ y) + (𝕟-to-ℕ r) ≡ x) → (y ∣ᵣₑₘ x)(r)
l {_}{_}{𝟎} {_} [≡]-intro = DivRem𝟎
l {x}{y}{𝐒 q}{r} p = substitute₁(x ↦ (y ∣ᵣₑₘ x)(r)) eq (DivRem𝐒 (l{(q ⋅ y) + (𝕟-to-ℕ r)}{y}{q}{r} [≡]-intro)) where
eq =
((q ⋅ y) + (𝕟-to-ℕ r)) + y 🝖[ _≡_ ]-[ One.commuteᵣ-assocₗ {a = q ⋅ y}{b = 𝕟-to-ℕ r}{c = y} ]
((q ⋅ y) + y) + (𝕟-to-ℕ r) 🝖[ _≡_ ]-[ congruence₂ₗ(_+_)(𝕟-to-ℕ r) ([⋅]-with-[𝐒]ₗ {q}{y}) ]-sym
(𝐒(q) ⋅ y) + (𝕟-to-ℕ r) 🝖[ _≡_ ]-[ p ]
x 🝖-end
-- ⌊/⌋-when-zero : ∀{x y} → (x ⌊/⌋ 𝐒(y) ≡ 𝟎) → (x ≡ 0)
-- ⌊/⌋-when-positive : ∀{x y q} → (x ⌊/⌋ 𝐒(y) ≡ 𝐒(q)) → ∃(x₀ ↦ (x ≡ x₀ + 𝐒(y)))
{-
[∣ᵣₑₘ]-existence : ∀{x y} → ∃(𝐒(y) ∣ᵣₑₘ x)
∃.witness ([∣ᵣₑₘ]-existence {x} {y}) = ℕ-to-𝕟 (x mod 𝐒(y)) ⦃ {![↔]-to-[→] decide-is-true mod-maxᵣ!} ⦄
∃.proof ([∣ᵣₑₘ]-existence {x} {y}) = [↔]-to-[←] [∣ᵣₑₘ]-equivalence ([∃]-intro (x ⌊/⌋ 𝐒(y)) ⦃ {!TODO: Insert division theorem here!} ⦄)
-}
DivRem𝟎Alt : ∀{x y} → (xy : (x < y)) → (y ∣ᵣₑₘ x)(ℕ-to-𝕟 x ⦃ [↔]-to-[→] decider-true xy ⦄)
DivRem𝟎Alt {x} {𝐒 y} (succ p) = [≡]-substitutionᵣ (𝕟.𝕟-ℕ-inverse) {expr ↦ (𝐒 y ∣ᵣₑₘ expr)(ℕ-to-𝕟 x)} ((DivRem𝟎{𝐒(y)}{ℕ-to-𝕟 x})) where
instance
x<𝐒y : IsTrue (x <? 𝐒(y))
x<𝐒y = [↔]-to-[→] decider-true ([≤]-with-[𝐒] ⦃ p ⦄)
DivRem𝐒Alt : ∀{x y}{r : 𝕟(y)} → (x ≥ y) → (y ∣ᵣₑₘ x −₀ y)(r) → (y ∣ᵣₑₘ x)(r)
DivRem𝐒Alt{x}{𝟎}{}
DivRem𝐒Alt{x}{𝐒(y)}{r} xy = [≡]-substitutionᵣ ([↔]-to-[→] ([−₀][+]-nullify2ᵣ{𝐒(y)}{x}) xy) {\expr → (𝐒(y) ∣ᵣₑₘ expr) r} ∘ DivRem𝐒{𝐒(y)}{x −₀ 𝐒(y)}{r}
-- Every pair of numbers (positive divisor) when divided will yield a remainder and there is always a proof of it being the case.
-- This is an alternative way of constructing the modulo operator.
[∣ᵣₑₘ]-existence-alt : ∀{x y} → ∃(𝐒(y) ∣ᵣₑₘ x)
[∣ᵣₑₘ]-existence-alt {x} {y} = [ℕ]-strong-induction {φ = x ↦ ∃(𝐒(y) ∣ᵣₑₘ x)} base step {x} where
base : ∃(𝐒(y) ∣ᵣₑₘ 𝟎)
base = [∃]-intro 𝟎 ⦃ DivRem𝟎 ⦄
step : ∀{i} → (∀{j} → (j ≤ i) → ∃(𝐒(y) ∣ᵣₑₘ j)) → ∃(𝐒(y) ∣ᵣₑₘ 𝐒(i))
step{i} p with [≤][>]-dichotomy {y}{i}
... | [∨]-introₗ yi = [∃]-map-proof (DivRem𝐒Alt([≤]-with-[𝐒] ⦃ yi ⦄)) (p{𝐒(i) −₀ 𝐒(y)} ([−₀]-lesser {i}{y}))
... | [∨]-introᵣ 𝐒iy = [∃]-intro (ℕ-to-𝕟 (𝐒(i)) ⦃ [↔]-to-[→] decider-true 𝐒iy ⦄) ⦃ DivRem𝟎Alt ([≤]-with-[𝐒] ⦃ 𝐒iy ⦄) ⦄
{-
open import Structure.Setoid.Uniqueness
{-[∣ᵣₑₘ]-uniqueness : ∀{x y}{p : ∃(𝐒(y) ∣ᵣₑₘ x)} → (p ≡ [∣ᵣₑₘ]-existence)
[∣ᵣₑₘ]-uniqueness {.(𝕟-to-ℕ r)} {y} {[∃]-intro r ⦃ DivRem𝟎 ⦄} = {![≡]-intro!}
[∣ᵣₑₘ]-uniqueness {.(x + 𝐒 y)} {y} {[∃]-intro r ⦃ DivRem𝐒 {x = x} p ⦄} = {!!}-}
{-[∣ᵣₑₘ]-unique-remainder : ∀{x y} → Unique(𝐒(y) ∣ᵣₑₘ x)
[∣ᵣₑₘ]-unique-remainder {.(𝕟-to-ℕ a)} {y} {a} {b} DivRem𝟎 q = {!!}
[∣ᵣₑₘ]-unique-remainder {.(x + 𝐒 y)} {y} {a} {b} (DivRem𝐒 {x = x} p) q = {!!}-}
open import Type.Properties.MereProposition
[∣ᵣₑₘ]-mereProposition : ∀{x y}{r : 𝕟(𝐒(y))} → MereProposition((𝐒(y) ∣ᵣₑₘ x)(r))
[∣ᵣₑₘ]-mereProposition = intro proof where
proof : ∀{x y}{r : 𝕟(𝐒(y))}{p q : (𝐒(y) ∣ᵣₑₘ x)(r)} → (p ≡ q)
proof {.(𝕟-to-ℕ r)} {y} {r} {DivRem𝟎} {q} = {!!}
proof {.(x + 𝐒 y)} {y} {r} {DivRem𝐒 {x = x} p} {q} = {!p!}
-- testor : ∀{y x}{r : 𝕟(𝐒 y)}{p : (𝐒(y) ∣ᵣₑₘ x)(r)} → (p ≡ DivRem𝟎) ∨ ∃(q ↦ (p ≡ DivRem𝐒 q))
-- TODO: Maybe by injectivity of 𝕟-to-ℕ?
test : ∀{y}{r : 𝕟(𝐒 y)}{p : (𝐒(y) ∣ᵣₑₘ (𝕟-to-ℕ r))(r)} → (p ≡ DivRem𝟎)
{- test {y} {r} {p} with 𝕟-to-ℕ r
test {_} {_} {_} | 𝟎 = {!!}-}
-}
{-
open import Data.Tuple using (_⨯_ ; _,_)
open import Type.Dependent
open import Type.Properties.MereProposition
[∣ᵣₑₘ]-mereProposition : ∀{x y}{r : 𝕟(y)} → MereProposition((y ∣ᵣₑₘ x)(r))
[∣ᵣₑₘ]-mereProposition = intro {!!} where
proof : ∀{y}{r : 𝕟(y)} → (p q : Σ(ℕ) (x ↦ (y ∣ᵣₑₘ x)(r))) → (p ≡ q)
proof {y} {r} (intro .(𝕟-to-ℕ r) DivRem𝟎) (intro .(𝕟-to-ℕ r) DivRem𝟎) = [≡]-intro
proof {y} {r} (intro .(𝕟-to-ℕ r) DivRem𝟎) (intro .(x₂ + y) (DivRem𝐒{x = x₂} p₂)) = {!!}
proof {y} {r} (intro .(x₁ + y) (DivRem𝐒{x = x₁} p₁)) (intro .(𝕟-to-ℕ r) DivRem𝟎) = {!!}
proof {y} {r} (intro .(x₁ + y) (DivRem𝐒{x = x₁} p₁)) (intro .(x₂ + y) (DivRem𝐒{x = x₂} p₂)) = {!congruence₂ₗ(_+_)(y) (congruence₁(Σ.left) eq)!} where
eq = proof (intro x₁ p₁) (intro x₂ p₂)
test : ∀{a₁ a₂ : A}{b₁ : B(a₁)}{b₂ : B(a₂)} → (a₁ ≡ a₂) → (intro a₁ b₁ ≡ intro a₂ b₂)
-}
| {
"alphanum_fraction": 0.5542420884,
"avg_line_length": 55.6232876712,
"ext": "agda",
"hexsha": "7f0a9234f76273402389cda8f0af535d57247f7d",
"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/Relation/DivisibilityWithRemainder/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Relation/DivisibilityWithRemainder/Proofs.agda",
"max_line_length": 214,
"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/Relation/DivisibilityWithRemainder/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 4547,
"size": 8121
} |
{-
Maybe structure: X ↦ Maybe (S X)
-}
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Structures.Maybe where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.SIP
open import Cubical.Functions.FunExtEquiv
open import Cubical.Data.Unit
open import Cubical.Data.Empty
open import Cubical.Data.Maybe
private
variable
ℓ ℓ₁ ℓ₁' : Level
MaybeRel : {A B : Type ℓ} (R : A → B → Type ℓ₁) → Maybe A → Maybe B → Type ℓ₁
MaybeRel R nothing nothing = Lift Unit
MaybeRel R nothing (just _) = Lift ⊥
MaybeRel R (just _) nothing = Lift ⊥
MaybeRel R (just x) (just y) = R x y
congMaybeRel : {A B : Type ℓ} {R : A → B → Type ℓ₁} {S : A → B → Type ℓ₁'}
→ (∀ x y → R x y ≃ S x y)
→ ∀ ox oy → MaybeRel R ox oy ≃ MaybeRel S ox oy
congMaybeRel e nothing nothing = Lift≃Lift (idEquiv _)
congMaybeRel e nothing (just _) = Lift≃Lift (idEquiv _)
congMaybeRel e (just _) nothing = Lift≃Lift (idEquiv _)
congMaybeRel e (just x) (just y) = e x y
module MaybePathP where
Code : (A : I → Type ℓ) → Maybe (A i0) → Maybe (A i1) → Type ℓ
Code A = MaybeRel (PathP A)
encodeRefl : {A : Type ℓ} → ∀ ox → Code (λ _ → A) ox ox
encodeRefl nothing = lift tt
encodeRefl (just _) = refl
encode : (A : I → Type ℓ) → ∀ ox oy → PathP (λ i → Maybe (A i)) ox oy → Code A ox oy
encode A ox oy p = transport (λ j → Code (λ i → A (i ∧ j)) ox (p j)) (encodeRefl ox)
decode : {A : I → Type ℓ} → ∀ ox oy → Code A ox oy → PathP (λ i → Maybe (A i)) ox oy
decode nothing nothing p i = nothing
decode (just _) (just _) p i = just (p i)
decodeEncodeRefl : {A : Type ℓ} (ox : Maybe A) → decode ox ox (encodeRefl ox) ≡ refl
decodeEncodeRefl nothing = refl
decodeEncodeRefl (just _) = refl
decodeEncode : {A : I → Type ℓ} → ∀ ox oy p → decode ox oy (encode A ox oy p) ≡ p
decodeEncode {A = A} ox oy p =
transport
(λ k →
decode _ _ (transp (λ j → Code (λ i → A (i ∧ j ∧ k)) ox (p (j ∧ k))) (~ k) (encodeRefl ox))
≡ (λ i → p (i ∧ k)))
(decodeEncodeRefl ox)
encodeDecode : (A : I → Type ℓ) → ∀ ox oy c → encode A ox oy (decode ox oy c) ≡ c
encodeDecode A nothing nothing c = refl
encodeDecode A (just x) (just y) c =
transport
(λ k →
encode (λ i → A (i ∧ k)) _ _ (decode (just x) (just (c k)) (λ i → c (i ∧ k)))
≡ (λ i → c (i ∧ k)))
(transportRefl _)
Code≃PathP : {A : I → Type ℓ} → ∀ ox oy → Code A ox oy ≃ PathP (λ i → Maybe (A i)) ox oy
Code≃PathP {A = A} ox oy = isoToEquiv isom
where
isom : Iso _ _
isom .Iso.fun = decode ox oy
isom .Iso.inv = encode _ ox oy
isom .Iso.rightInv = decodeEncode ox oy
isom .Iso.leftInv = encodeDecode A ox oy
-- Structured isomorphisms
MaybeStructure : (S : Type ℓ → Type ℓ₁) → Type ℓ → Type ℓ₁
MaybeStructure S X = Maybe (S X)
MaybeEquivStr : {S : Type ℓ → Type ℓ₁}
→ StrEquiv S ℓ₁' → StrEquiv (MaybeStructure S) ℓ₁'
MaybeEquivStr ι (X , ox) (Y , oy) e = MaybeRel (λ x y → ι (X , x) (Y , y) e) ox oy
maybeUnivalentStr : {S : Type ℓ → Type ℓ₁} (ι : StrEquiv S ℓ₁')
→ UnivalentStr S ι → UnivalentStr (MaybeStructure S) (MaybeEquivStr ι)
maybeUnivalentStr ι θ {X , ox} {Y , oy} e =
compEquiv
(congMaybeRel (λ x y → θ {X , x} {Y , y} e) ox oy)
(MaybePathP.Code≃PathP ox oy)
maybeEquivAction : {S : Type ℓ → Type ℓ₁}
→ EquivAction S → EquivAction (MaybeStructure S)
maybeEquivAction α e = congMaybeEquiv (α e)
maybeTransportStr : {S : Type ℓ → Type ℓ₁} (α : EquivAction S)
→ TransportStr α → TransportStr (maybeEquivAction α)
maybeTransportStr _ τ e nothing = refl
maybeTransportStr _ τ e (just x) = cong just (τ e x)
| {
"alphanum_fraction": 0.628005284,
"avg_line_length": 34.7247706422,
"ext": "agda",
"hexsha": "8056ce4f6c82db989b18a230facb781a2c88d5fb",
"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/Structures/Maybe.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/Structures/Maybe.agda",
"max_line_length": 99,
"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/Structures/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1384,
"size": 3785
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
open import Cubical.Core.Everything
open import Cubical.Foundations.Embedding
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
-- A helper module for deriving univalence for a higher inductive-recursive
-- universe.
--
-- U is the type of codes
-- El is the decoding
-- uaf is a higher constructor that requires paths between codes to exist
-- for equivalences of decodings
-- comp is intended to be the computational behavior of El on uaf, although
-- it seems that being a path is sufficient.
-- ret is a higher constructor that fills out the equivalence structure
-- for uaf and the computational behavior of El.
--
-- Given a universe defined as above, it's possible to show that the path
-- space of the code type is equivalent to the path space of the actual
-- decodings, which are themselves determined by equivalences.
--
-- The levels are left independent, but of course it will generally be
-- impossible to define this sort of universe unless ℓ' < ℓ, because El will
-- be too big to go in a constructor of U. The exception would be if U could
-- be defined independently of El, though it might be tricky to get the right
-- higher structure in such a case.
module Cubical.Foundations.Univalence.Universe {ℓ ℓ'}
(U : Type ℓ)
(El : U → Type ℓ')
(uaf : ∀{s t} → El s ≃ El t → s ≡ t)
(comp : ∀{s t} (e : El s ≃ El t) → cong El (uaf e) ≡ ua e)
(ret : ∀{s t : U} → (p : s ≡ t) → uaf (lineToEquiv (λ i → El (p i))) ≡ p)
where
minivalence : ∀{s t} → (s ≡ t) ≃ (El s ≡ El t)
minivalence {s} {t} = isoToEquiv mini
where
open Iso
mini : Iso (s ≡ t) (El s ≡ El t)
mini .fun = cong El
mini .inv = uaf ∘ pathToEquiv
mini .rightInv p = comp (pathToEquiv p) ∙ uaη p
mini .leftInv = ret
isEmbeddingEl : isEmbedding El
isEmbeddingEl s t = snd minivalence
| {
"alphanum_fraction": 0.7030242935,
"avg_line_length": 38.0566037736,
"ext": "agda",
"hexsha": "9f261cd537535f7b5c522c78846bcfc44e82aa9e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Foundations/Univalence/Universe.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Foundations/Univalence/Universe.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Foundations/Univalence/Universe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 596,
"size": 2017
} |
module Main where
open import IO
open import Data.String
open import Data.List
open import Data.Bool
{-# IMPORT AST #-}
{-# COMPILED_TYPE String AST.Type #-}
{-# COMPILED_TYPE String AST.Identifier #-}
data Variable : Set where
V : String → String → Variable
varName : Variable → String
varName (V _ name) = name
{-# COMPILED_DATA Variable AST.Variable AST.Variable #-}
data Expression : Set where
New : String → List Expression → Expression
FieldAccess : String → Expression → String → Expression
MethodCall : String → Expression → String → List Expression → Expression
Var : String → String → Expression
exprType : Expression → String
exprType (New t _) = t
exprType (FieldAccess t _ _) = t
exprType (MethodCall t _ _ _) = t
exprType (Var t _) = t
{-# COMPILED_DATA Expression AST.Expression AST.New AST.FieldAccess AST.MethodCall AST.Var #-}
data Method : Set where
Mth : String → List Variable → Expression → Method
{-# COMPILED_DATA Method AST.Method AST.Method #-}
data Constructor : Set where
Cons : List Variable → Constructor
{-# COMPILED_DATA Constructor AST.Constructor AST.Constructor #-}
data Pair (A B : Set) : Set where
P : A → B → Pair A B
{-# COMPILED_DATA Pair (,) (,) #-}
data SimpleMap (A B : Set) : Set where
SM : List (Pair A B) → SimpleMap A B
{-# COMPILED_DATA SimpleMap AST.SimpleMap AST.SimpleMap #-}
data Class : Set where
Cls : String → SimpleMap String String → Constructor → SimpleMap String Method → Class
{-# COMPILED_DATA Class AST.Class AST.Class #-}
data Program : Set where
Prog : SimpleMap String Class → Program
{-# COMPILED_DATA Program AST.Program AST.Program #-}
postulate
parseUnsafe : String → Program
showProgram : Program → String
getValue : {A B : Set} → A → SimpleMap A B → B
{-# COMPILED parseUnsafe AST.parseUnsafe #-}
{-# COMPILED showProgram AST.showProgram #-}
infixr 5 _++l_
_++l_ : ∀ {a} {A : Set a} → List A → List A → List A
xs ++l ys = Data.List._++_ xs ys
{-# NO_TERMINATION_CHECK #-}
subst : Pair String Expression → Expression → Expression
subst substExpr (New t ps) = New t (map (subst substExpr) ps)
subst substExpr (FieldAccess t e f) = FieldAccess t (subst substExpr e) f
subst substExpr (MethodCall t e m ps) = MethodCall t (subst substExpr e) m (map (subst substExpr) ps)
subst (P name expr) (Var t vName) = if name == vName then expr else (Var t vName)
getMethod : Program → String → String → Method
getMethod (Prog classes) clsName mthName with getValue clsName classes
... | Cls _ _ _ methods = getValue mthName methods
reduceInvk : Program → Expression → String → List Expression → Expression
reduceInvk p e mthName params with getMethod p (exprType e) mthName
... | Mth _ vars body = foldr subst body ((P "this" e) ∷ (zipWith P (map varName vars) params))
data Reduce {Pr : Program} : Expression → Expression → Set where
RInvk : ∀ {t consParams mthType mthName mthParams} → Reduce {Pr} (MethodCall mthType (New t consParams) mthName mthParams) (reduceInvk Pr (New t consParams) mthName mthParams)
RCField : ∀ {e₁ e₂ t f} → Reduce {Pr} e₁ e₂ → Reduce {Pr} (FieldAccess t e₁ f) (FieldAccess t e₂ f)
RCInvk : ∀ {e₁ e₂ t m p} → Reduce {Pr} e₁ e₂ → Reduce {Pr} (MethodCall t e₁ m p) (MethodCall t e₂ m p)
RCInvkArg : ∀ {e e₁ e₂ t m p₁ p₂} → Reduce {Pr} e₁ e₂ → Reduce {Pr} (MethodCall t e m (p₁ ++l [ e₁ ] ++l p₂)) (MethodCall t e m (p₁ ++l [ e₂ ] ++l p₂))
RCNewArg : ∀ {e₁ e₂ t p₁ p₂} → Reduce {Pr} e₁ e₂ → Reduce {Pr} (New t (p₁ ++l [ e₁ ] ++l p₂)) (New t (p₁ ++l [ e₂ ] ++l p₂))
main = run (putStrLn (showProgram (parseUnsafe "class A extends Object { A() {super();} }")))
| {
"alphanum_fraction": 0.6868938764,
"avg_line_length": 36.09,
"ext": "agda",
"hexsha": "d4579ab6de3b106a2a2d79a0ed7e62cb2cbbf53d",
"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": "b7042f7bfde851d5df7575bbe9bd51ecfc50f11f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "ademinn/RefactoringVerification",
"max_forks_repo_path": "src/prover/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7042f7bfde851d5df7575bbe9bd51ecfc50f11f",
"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": "ademinn/RefactoringVerification",
"max_issues_repo_path": "src/prover/Main.agda",
"max_line_length": 177,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7042f7bfde851d5df7575bbe9bd51ecfc50f11f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "ademinn/RefactoringVerification",
"max_stars_repo_path": "src/prover/Main.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1069,
"size": 3609
} |
module trees where
data Tree (A : Set) : Set where
empty : Tree A
node : Tree A -> A -> Tree A -> Tree A
open import Data.Nat
#nodes : {A : Set} -> Tree A -> ℕ
#nodes empty = 0
#nodes (node t x t₁) = (#nodes t) + (1 + (#nodes t₁))
#leafs : {A : Set} -> Tree A -> ℕ
#leafs empty = zero
-- #leafs (node empty x empty) = 1
#leafs (node t x t₁) with t | t₁
... | empty | empty = 1
... | _ | _ = (#leafs t) + (#leafs t₁)
| {
"alphanum_fraction": 0.4686868687,
"avg_line_length": 24.75,
"ext": "agda",
"hexsha": "42d477bd80624d56d4d10b4cc9da682932b97ba6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "hablapps/safeoptics",
"max_forks_repo_path": "src/main/agda/trees.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "hablapps/safeoptics",
"max_issues_repo_path": "src/main/agda/trees.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "90fc9586f4c126ee83b8aa54ad417bb7a5325b1b",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "hablapps/safeoptics",
"max_stars_repo_path": "src/main/agda/trees.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 178,
"size": 495
} |
------------------------------------------------------------------------
-- Queue instances for the queues in Queue.Truncated
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
import Equality.Path as P
open import Prelude
import Queue
module Queue.Truncated.Instances
{e⁺}
(eq : ∀ {a p} → P.Equality-with-paths a p e⁺)
(open P.Derived-definitions-and-properties eq)
{Q : ∀ {ℓ} → Type ℓ → Type ℓ}
⦃ is-queue :
∀ {ℓ} →
Queue.Is-queue equality-with-J Q (λ _ → ↑ _ ⊤) ℓ ⦄
⦃ is-queue-with-map :
∀ {ℓ₁ ℓ₂} →
Queue.Is-queue-with-map equality-with-J Q ℓ₁ ℓ₂ ⦄
where
open Queue equality-with-J
open import Queue.Truncated eq as Q using (Queue)
open import Bijection equality-with-J using (_↔_)
open import Erased.Cubical eq hiding (map)
open import H-level.Closure equality-with-J
open import List equality-with-J as L hiding (map)
open import Maybe equality-with-J
open import Monad equality-with-J hiding (map)
import Nat equality-with-J as Nat
private
variable
a ℓ ℓ₁ ℓ₂ : Level
A : Type a
xs : List A
module N = Q.Non-indexed
instance
-- Instances.
Queue-is-queue : Is-queue (Queue Q) Very-stableᴱ-≡ ℓ
Queue-is-queue .Is-queue.to-List = Q.to-List
Queue-is-queue .Is-queue.from-List = Q.from-List
Queue-is-queue .Is-queue.to-List-from-List = _↔_.right-inverse-of
(Q.Queue↔List _) _
Queue-is-queue .Is-queue.enqueue = N.enqueue
Queue-is-queue .Is-queue.to-List-enqueue = N.to-List-enqueue
Queue-is-queue .Is-queue.dequeue = N.dequeue
Queue-is-queue .Is-queue.to-List-dequeue = N.to-List-dequeue
Queue-is-queue .Is-queue.dequeue⁻¹ = N.dequeue⁻¹
Queue-is-queue .Is-queue.to-List-dequeue⁻¹ = N.to-List-dequeue⁻¹
Queue-is-queue-with-map : Is-queue-with-map (Queue Q) ℓ₁ ℓ₂
Queue-is-queue-with-map .Is-queue-with-map.map = N.map
Queue-is-queue-with-map .Is-queue-with-map.to-List-map = N.to-List-map
Queue-is-queue-with-unique-representations :
Is-queue-with-unique-representations (Queue Q) ℓ
Queue-is-queue-with-unique-representations
.Is-queue-with-unique-representations.from-List-to-List =
_↔_.left-inverse-of (Q.Queue↔List _) _
------------------------------------------------------------------------
-- Some examples
private
ns = Very-stable→Very-stableᴱ 1 $
Decidable-equality→Very-stable-≡ Nat._≟_
dequeue′ = dequeue ns
to-List′ = to-List ns
empty′ = empty ⦂ Queue Q ℕ
example₁ : map suc (enqueue 3 empty) ≡ enqueue 4 empty′
example₁ = _↔_.to Q.≡-for-indices↔≡ [ refl _ ]
example₂ : dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) ≡
just (10 , enqueue 6 empty)
example₂ =
dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty))) ≡⟨ cong dequeue′ (_↔_.to Q.≡-for-indices↔≡ [ refl _ ]) ⟩
dequeue′ (cons 10 (enqueue 6 empty)) ≡⟨ _↔_.right-inverse-of (Queue↔Maybe[×Queue] _) _ ⟩∎
just (10 , enqueue 6 empty) ∎
example₃ :
(do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty)))
return (enqueue (3 * x) q)) ≡
just (enqueue 30 (enqueue 6 empty))
example₃ =
(do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty)))
return (enqueue (3 * x) q ⦂ Queue Q ℕ)) ≡⟨ cong (_>>= λ _ → return (enqueue _ _)) example₂ ⟩
(do x , q ← just (10 , enqueue 6 empty)
return (enqueue (3 * x) (q ⦂ Queue Q ℕ))) ≡⟨⟩
just (enqueue 30 (enqueue 6 empty)) ∎
example₄ :
(do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty)))
let q = enqueue (3 * x) q
return (to-List′ q)) ≡
just (6 ∷ 30 ∷ [])
example₄ =
(do x , q ← dequeue′ (map (_* 2) (enqueue 3 (enqueue 5 empty)))
return (to-List′ (enqueue (3 * x) q))) ≡⟨ cong (_>>= λ _ → return (to-List′ (enqueue _ _))) example₂ ⟩
(do x , q ← just (10 , enqueue 6 empty)
return (to-List′ (enqueue (3 * x) (q ⦂ Queue Q ℕ)))) ≡⟨⟩
just (to-List′ (enqueue 30 (enqueue 6 empty))) ≡⟨ cong just $ to-List-foldl-enqueue-empty _ ⟩∎
just (6 ∷ 30 ∷ []) ∎
example₅ :
∀ {xs} →
dequeue′ (from-List (1 ∷ 2 ∷ 3 ∷ xs)) ≡
just (1 , from-List (2 ∷ 3 ∷ xs))
example₅ {xs = xs} =
dequeue′ (from-List (1 ∷ 2 ∷ 3 ∷ xs)) ≡⟨ cong dequeue′ (_↔_.to Q.≡-for-indices↔≡ [ refl _ ]) ⟩
dequeue′ (cons 1 (from-List (2 ∷ 3 ∷ xs))) ≡⟨ _↔_.right-inverse-of (Queue↔Maybe[×Queue] _) _ ⟩∎
just (1 , from-List (2 ∷ 3 ∷ xs)) ∎
example₆ :
foldr enqueue empty′ (3 ∷ 2 ∷ 1 ∷ []) ≡
from-List (1 ∷ 2 ∷ 3 ∷ [])
example₆ = _↔_.to Q.≡-for-indices↔≡ [ refl _ ]
| {
"alphanum_fraction": 0.5404796065,
"avg_line_length": 36.4104477612,
"ext": "agda",
"hexsha": "a8a535154d069d5ffe4f7fa41d796fedd67157f4",
"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/Queue/Truncated/Instances.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/Queue/Truncated/Instances.agda",
"max_line_length": 132,
"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/Queue/Truncated/Instances.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": 1635,
"size": 4879
} |
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym)
open import Data.Sum using (_⊎_)
open _⊎_
module AKS.Nat.Roots where
open import AKS.Nat using (ℕ; _≤_; _<_; n≤m⇒n<m⊎n≡m; <-irrefl; *-1-commutativeMonoid)
open ℕ
open import AKS.Nat using ([_,_]; binary-search; acc)
open import AKS.Exponentiation *-1-commutativeMonoid using (_^_)
record Root (n : ℕ) (b : ℕ) : Set where
constructor Root✓
field
root : ℕ
root^b≤n : root ^ b ≤ n
n<root^[1+b] : n < (suc root) ^ b
open import AKS.Unsafe using (TODO)
find-root : ∀ n b → Root n b
find-root n b = loop 0 n binary-search
where
loop : ∀ l h → [ l , h ] → Root n b
loop l h (acc downward upward) = TODO
-- root-unique : root ^ b < n → n < (suc root) ^ b
record Power (n : ℕ) (b : ℕ) : Set where
constructor Power✓
field
root : ℕ
n≡root^b : n ≡ root ^ b
power? : ∀ n b → Dec (Power n b)
power? n b with find-root n b
... | Root✓ root₁ root₁^b≤n n<root₁^[1+b] with n≤m⇒n<m⊎n≡m root₁^b≤n
... | inj₁ root₁^b<n = no λ { (Power✓ root₂ n≡root₂^b) → TODO }
... | inj₂ root₁^b≡n = yes (Power✓ root₁ (sym root₁^b≡n))
record Perfect (n : ℕ) : Set where
constructor Perfect✓
field
b : ℕ
power : Power n b
perfect? : ∀ n → Dec (Perfect n)
perfect? = TODO
| {
"alphanum_fraction": 0.6194086429,
"avg_line_length": 25.862745098,
"ext": "agda",
"hexsha": "76d81ddd73ebddb0f0902b809161f5914a876e02",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Nat/Roots.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Nat/Roots.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Nat/Roots.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 516,
"size": 1319
} |
{-# OPTIONS --cubical --safe #-}
module Function.Surjective.Base where
open import Path
open import Function.Fiber
open import Level
open import HITs.PropositionalTruncation
open import Data.Sigma
Surjective : (A → B) → Type _
Surjective f = ∀ y → ∥ fiber f y ∥
SplitSurjective : (A → B) → Type _
SplitSurjective f = ∀ y → fiber f y
infixr 0 _↠!_ _↠_
_↠!_ : Type a → Type b → Type (a ℓ⊔ b)
A ↠! B = Σ (A → B) SplitSurjective
_↠_ : Type a → Type b → Type (a ℓ⊔ b)
A ↠ B = Σ (A → B) Surjective
| {
"alphanum_fraction": 0.6513026052,
"avg_line_length": 20.7916666667,
"ext": "agda",
"hexsha": "34131a0157ba9f9bf0d40e573e4724171a89f11b",
"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": "Function/Surjective/Base.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": "Function/Surjective/Base.agda",
"max_line_length": 40,
"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": "Function/Surjective/Base.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": 187,
"size": 499
} |
module T where
postulate x : Set
postulate y : Set
postulate p : Set -> Set
e : Set
e = p y
| {
"alphanum_fraction": 0.6489361702,
"avg_line_length": 10.4444444444,
"ext": "agda",
"hexsha": "f83bf575c5f8d2657a54d627d27d38a1a3697719",
"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": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "andrejtokarcik/agda-semantics",
"max_forks_repo_path": "tests/covered/T.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"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": "andrejtokarcik/agda-semantics",
"max_issues_repo_path": "tests/covered/T.agda",
"max_line_length": 24,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "dc333ed142584cf52cc885644eed34b356967d8b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "andrejtokarcik/agda-semantics",
"max_stars_repo_path": "tests/covered/T.agda",
"max_stars_repo_stars_event_max_datetime": "2018-12-06T17:24:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-10T15:33:56.000Z",
"num_tokens": 33,
"size": 94
} |
open import Agda.Builtin.Reflection
open import Agda.Builtin.Unit
@0 A : Set₁
A = Set
macro
@0 m : Term → TC ⊤
m B =
bindTC (quoteTC A) λ A →
unify A B
B : Set₁
B = m
| {
"alphanum_fraction": 0.606557377,
"avg_line_length": 11.4375,
"ext": "agda",
"hexsha": "ac692099fa37387e3be54b923e089ce8b844e798",
"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": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "Seanpm2001-Agda-lang/agda",
"max_forks_repo_path": "test/Fail/ErasedMacro1.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "b5b3b1657556f720a7310cb7744edb1fac71eaf4",
"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": "Seanpm2001-Agda-lang/agda",
"max_issues_repo_path": "test/Fail/ErasedMacro1.agda",
"max_line_length": 35,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Fail/ErasedMacro1.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:25:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:25:14.000Z",
"num_tokens": 70,
"size": 183
} |
module Prelude.Bool where
open import Prelude.Unit
open import Prelude.Empty
open import Prelude.Equality
open import Prelude.Decidable
open import Prelude.Function
open import Agda.Builtin.Bool public
infix 0 if_then_else_
if_then_else_ : ∀ {a} {A : Set a} → Bool → A → A → A
if true then x else y = x
if false then x else y = y
{-# INLINE if_then_else_ #-}
infixr 3 _&&_
infixr 2 _||_
_||_ : Bool → Bool → Bool
true || _ = true
false || x = x
{-# INLINE _||_ #-}
_&&_ : Bool → Bool → Bool
true && x = x
false && _ = false
{-# INLINE _&&_ #-}
not : Bool → Bool
not true = false
not false = true
{-# INLINE not #-}
data IsTrue : Bool → Set where
instance true : IsTrue true
data IsFalse : Bool → Set where
instance false : IsFalse false
instance
EqBool : Eq Bool
_==_ {{EqBool}} false false = yes refl
_==_ {{EqBool}} false true = no λ ()
_==_ {{EqBool}} true false = no λ ()
_==_ {{EqBool}} true true = yes refl
decBool : ∀ b → Dec (IsTrue b)
decBool false = no λ ()
decBool true = yes true
{-# INLINE decBool #-}
isYes : ∀ {a} {A : Set a} → Dec A → Bool
isYes (yes _) = true
isYes (no _) = false
isNo : ∀ {a} {A : Set a} → Dec A → Bool
isNo = not ∘ isYes
infix 0 if′_then_else_
if′_then_else_ : ∀ {a} {A : Set a} (b : Bool) → ({{_ : IsTrue b}} → A) → ({{_ : IsFalse b}} → A) → A
if′ true then x else _ = x
if′ false then _ else y = y
| {
"alphanum_fraction": 0.6155523256,
"avg_line_length": 21.1692307692,
"ext": "agda",
"hexsha": "5abd0bec9a543697ef54903d3066d63722d99b6a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Prelude/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "src/Prelude/Bool.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Prelude/Bool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 474,
"size": 1376
} |
module Prelude.Char where
open import Prelude.Bool
postulate
Char : Set
{-# BUILTIN CHAR Char #-}
private
primitive
primCharEquality : (c c' : Char) -> Bool
postulate
eof : Char
{-# COMPILED_EPIC eof () -> Int = foreign Int "eof" () #-}
charEq : Char -> Char -> Bool
charEq = primCharEquality
| {
"alphanum_fraction": 0.6559485531,
"avg_line_length": 14.1363636364,
"ext": "agda",
"hexsha": "724035496d6b583d134d549f2c1c7aaa72f0322c",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/epic/Prelude/Char.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/epic/Prelude/Char.agda",
"max_line_length": 58,
"max_stars_count": null,
"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/epic/Prelude/Char.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 86,
"size": 311
} |
-- Andreas, 2018-06-15, issue #1086
-- Reported by Andrea
-- Fixed by Jesper in https://github.com/agda/agda/commit/242684bca62fabe43e125aefae7526be4b26a135
open import Common.Bool
open import Common.Equality
and : (a b : Bool) → Bool
and true b = b
and false b = false
test : ∀ a b → and a b ≡ true → a ≡ true
test true true refl = refl
-- Should succeed.
| {
"alphanum_fraction": 0.7071823204,
"avg_line_length": 22.625,
"ext": "agda",
"hexsha": "bb59721f8148d8643222d0a51f86ada64b905304",
"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/Issue1086.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/Issue1086.agda",
"max_line_length": 98,
"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/Issue1086.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 124,
"size": 362
} |
------------------------------------------------------------------------
-- Encoder and decoder instances for Atom.χ-ℕ-atoms
------------------------------------------------------------------------
module Coding.Instances.Nat where
open import Atom
-- The code-Var and code-Const instances are hidden: they are replaced
-- by the code-ℕ instance.
open import Coding.Instances χ-ℕ-atoms public
hiding (rep-Var; rep-Const)
| {
"alphanum_fraction": 0.5011709602,
"avg_line_length": 30.5,
"ext": "agda",
"hexsha": "0cfb1c7c74e76cfd11f54c5c5407dcec99b482f4",
"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": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Coding/Instances/Nat.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Coding/Instances/Nat.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Coding/Instances/Nat.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 82,
"size": 427
} |
{-# OPTIONS --warning=error --without-K --guardedness --safe #-}
open import LogicalFormulae
open import Numbers.Naturals.Definition
open import Setoids.Setoids
open import Numbers.Naturals.Order
open import Vectors
module Sequences where
record Sequence {a : _} (A : Set a) : Set a where
coinductive
field
head : A
tail : Sequence A
headInjective : {a : _} {A : Set a} {s1 s2 : Sequence A} → s1 ≡ s2 → Sequence.head s1 ≡ Sequence.head s2
headInjective {s1 = s1} {.s1} refl = refl
constSequence : {a : _} {A : Set a} (k : A) → Sequence A
Sequence.head (constSequence k) = k
Sequence.tail (constSequence k) = constSequence k
index : {a : _} {A : Set a} (s : Sequence A) (n : ℕ) → A
index s zero = Sequence.head s
index s (succ n) = index (Sequence.tail s) n
funcToSequence : {a : _} {A : Set a} (f : ℕ → A) → Sequence A
Sequence.head (funcToSequence f) = f 0
Sequence.tail (funcToSequence f) = funcToSequence (λ i → f (succ i))
funcToSequenceReversible : {a : _} {A : Set a} (f : ℕ → A) → (n : ℕ) → index (funcToSequence f) n ≡ f n
funcToSequenceReversible f zero = refl
funcToSequenceReversible f (succ n) = funcToSequenceReversible (λ i → f (succ i)) n
map : {a b : _} {A : Set a} {B : Set b} (f : A → B) (s : Sequence A) → Sequence B
Sequence.head (map f s) = f (Sequence.head s)
Sequence.tail (map f s) = map f (Sequence.tail s)
apply : {a b c : _} {A : Set a} {B : Set b} {C : Set c} (f : A → B → C) (s1 : Sequence A) (s2 : Sequence B) → Sequence C
Sequence.head (apply f s1 s2) = f (Sequence.head s1) (Sequence.head s2)
Sequence.tail (apply f s1 s2) = apply f (Sequence.tail s1) (Sequence.tail s2)
indexAndConst : {a : _} {A : Set a} (a : A) (n : ℕ) → index (constSequence a) n ≡ a
indexAndConst a zero = refl
indexAndConst a (succ n) = indexAndConst a n
mapTwice : {a b c : _} {A : Set a} {B : Set b} {C : Set c} (f : A → B) (g : B → C) (s : Sequence A) → {n : ℕ} → index (map g (map f s)) n ≡ index (map (λ i → g (f i)) s) n
mapTwice f g s {zero} = refl
mapTwice f g s {succ n} = mapTwice f g (Sequence.tail s) {n}
mapAndIndex : {a b : _} {A : Set a} {B : Set b} (s : Sequence A) (f : A → B) (n : ℕ) → f (index s n) ≡ index (map f s) n
mapAndIndex s f zero = refl
mapAndIndex s f (succ n) = mapAndIndex (Sequence.tail s) f n
indexExtensional : {a b c : _} {A : Set a} {B : Set b} (T : Setoid {_} {c} B) (s : Sequence A) (f g : A → B) → (extension : ∀ {x} → (Setoid._∼_ T (f x) (g x))) → {n : ℕ} → Setoid._∼_ T (index (map f s) n) (index (map g s) n)
indexExtensional T s f g extension {zero} = extension
indexExtensional T s f g extension {succ n} = indexExtensional T (Sequence.tail s) f g extension {n}
indexAndApply : {a b c : _} {A : Set a} {B : Set b} {C : Set c} (s1 : Sequence A) (s2 : Sequence B) (f : A → B → C) → {m : ℕ} → index (apply f s1 s2) m ≡ f (index s1 m) (index s2 m)
indexAndApply s1 s2 f {zero} = refl
indexAndApply s1 s2 f {succ m} = indexAndApply (Sequence.tail s1) (Sequence.tail s2) f {m}
mapAndApply : {a b c d : _} {A : Set a} {B : Set b} {C : Set c} {D : Set d} (s1 : Sequence A) (s2 : Sequence B) (f : A → B → C) (g : C → D) → (m : ℕ) → index (map g (apply f s1 s2)) m ≡ g (f (index s1 m) (index s2 m))
mapAndApply s1 s2 f g zero = refl
mapAndApply s1 s2 f g (succ m) = mapAndApply (Sequence.tail s1) (Sequence.tail s2) f g m
assemble : {a : _} {A : Set a} → (x : A) → (s : Sequence A) → Sequence A
Sequence.head (assemble x s) = x
Sequence.tail (assemble x s) = s
allTrue : {a : _} {A : Set a} {c : _} (pred : A → Set c) (s : Sequence A) → Set c
allTrue pred s = (n : ℕ) → pred (index s n)
tailFrom : {a : _} {A : Set a} (n : ℕ) → (s : Sequence A) → Sequence A
tailFrom zero s = s
tailFrom (succ n) s = tailFrom n (Sequence.tail s)
subsequence : {a : _} {A : Set a} (x : Sequence A) → (indices : Sequence ℕ) → ((n : ℕ) → index indices n <N index indices (succ n)) → Sequence A
Sequence.head (subsequence x selector increasing) = index x (Sequence.head selector)
Sequence.tail (subsequence x selector increasing) = subsequence (tailFrom (succ (Sequence.head selector)) x) (Sequence.tail selector) λ n → increasing (succ n)
take : {a : _} {A : Set a} (n : ℕ) (s : Sequence A) → Vec A n
take zero s = []
take (succ n) s = Sequence.head s ,- take n (Sequence.tail s)
unfold : {a : _} {A : Set a} → (A → A) → A → Sequence A
Sequence.head (unfold f a) = a
Sequence.tail (unfold f a) = unfold f (f a)
indexAndUnfold : {a : _} {A : Set a} (f : A → A) (start : A) (n : ℕ) → index (unfold f start) (succ n) ≡ f (index (unfold f start) n)
indexAndUnfold f s zero = refl
indexAndUnfold f s (succ n) = indexAndUnfold f (f s) n
| {
"alphanum_fraction": 0.6155691234,
"avg_line_length": 48.7872340426,
"ext": "agda",
"hexsha": "45e0edb0de6b24ea09992ec041df924fde6ef438",
"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": "Sequences.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": "Sequences.agda",
"max_line_length": 224,
"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": "Sequences.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": 1701,
"size": 4586
} |
{-
Properties and Formulae about Cardinality
This file contains:
- Relation between abstract properties and cardinality in special cases;
- Combinatorial formulae, namely, cardinality of A+B, A×B, ΣAB, ΠAB, etc;
- A general form of Pigeonhole Principle;
- Maximal value of numerical function on finite sets;
- Set truncation of FinSet is equivalent to ℕ;
- FinProp is equivalent to Bool.
-}
{-# OPTIONS --safe #-}
module Cubical.Data.FinSet.Cardinality where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Equiv renaming (_∙ₑ_ to _⋆_)
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.Transport
open import Cubical.HITs.PropositionalTruncation as Prop
open import Cubical.HITs.SetTruncation as Set
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
open import Cubical.Data.Unit
open import Cubical.Data.Empty as Empty
open import Cubical.Data.Bool hiding (_≟_)
open import Cubical.Data.Sum
open import Cubical.Data.Sigma
open import Cubical.Data.Fin using (Fin-inj)
open import Cubical.Data.Fin.LehmerCode as LehmerCode
open import Cubical.Data.SumFin
open import Cubical.Data.FinSet.Base
open import Cubical.Data.FinSet.Properties
open import Cubical.Data.FinSet.FiniteChoice
open import Cubical.Data.FinSet.Constructors
open import Cubical.Data.FinSet.Induction hiding (_+_)
open import Cubical.Relation.Nullary
open import Cubical.Functions.Fibration
open import Cubical.Functions.Embedding
open import Cubical.Functions.Surjection
private
variable
ℓ ℓ' ℓ'' : Level
n : ℕ
X : FinSet ℓ
Y : FinSet ℓ'
-- cardinality of finite sets
∣≃card∣ : (X : FinSet ℓ) → ∥ X .fst ≃ Fin (card X) ∥
∣≃card∣ X = X .snd .snd
-- cardinality is invariant under equivalences
cardEquiv : (X : FinSet ℓ)(Y : FinSet ℓ') → ∥ X .fst ≃ Y .fst ∥ → card X ≡ card Y
cardEquiv X Y e =
Prop.rec (isSetℕ _ _) (λ p → Fin-inj _ _ (ua p))
(∣ invEquiv (SumFin≃Fin _) ∣ ⋆̂ ∣invEquiv∣ (∣≃card∣ X) ⋆̂ e ⋆̂ ∣≃card∣ Y ⋆̂ ∣ SumFin≃Fin _ ∣)
cardInj : card X ≡ card Y → ∥ X .fst ≃ Y .fst ∥
cardInj {X = X} {Y = Y} p =
∣≃card∣ X ⋆̂ ∣ pathToEquiv (cong Fin p) ∣ ⋆̂ ∣invEquiv∣ (∣≃card∣ Y)
cardReflection : card X ≡ n → ∥ X .fst ≃ Fin n ∥
cardReflection {X = X} = cardInj {X = X} {Y = _ , isFinSetFin}
card≡MereEquiv : (card X ≡ card Y) ≡ ∥ X .fst ≃ Y .fst ∥
card≡MereEquiv {X = X} {Y = Y} =
hPropExt (isSetℕ _ _) isPropPropTrunc (cardInj {X = X} {Y = Y}) (cardEquiv X Y)
-- special properties about specific cardinality
module _
{X : FinSet ℓ} where
card≡0→isEmpty : card X ≡ 0 → ¬ X .fst
card≡0→isEmpty p x =
Prop.rec isProp⊥ (λ e → subst Fin p (e .fst x)) (∣≃card∣ X)
card>0→isInhab : card X > 0 → ∥ X .fst ∥
card>0→isInhab p =
Prop.map (λ e → invEq e (Fin>0→isInhab _ p)) (∣≃card∣ X)
card>1→hasNonEqualTerm : card X > 1 → ∥ Σ[ a ∈ X .fst ] Σ[ b ∈ X .fst ] ¬ a ≡ b ∥
card>1→hasNonEqualTerm p =
Prop.map
(λ e →
e .fst (Fin>1→hasNonEqualTerm _ p .fst) ,
e .fst (Fin>1→hasNonEqualTerm _ p .snd .fst) ,
Fin>1→hasNonEqualTerm _ p .snd .snd ∘ invEq (congEquiv e))
(∣invEquiv∣ (∣≃card∣ X))
card≡1→isContr : card X ≡ 1 → isContr (X .fst)
card≡1→isContr p =
Prop.rec isPropIsContr
(λ e → isOfHLevelRespectEquiv 0 (invEquiv (e ⋆ substEquiv Fin p)) isContrSumFin1) (∣≃card∣ X)
card≤1→isProp : card X ≤ 1 → isProp (X .fst)
card≤1→isProp p =
Prop.rec isPropIsProp (λ e → isOfHLevelRespectEquiv 1 (invEquiv e) (Fin≤1→isProp (card X) p)) (∣≃card∣ X)
card≡n : card X ≡ n → ∥ X ≡ 𝔽in n ∥
card≡n {n = n} p =
Prop.map
(λ e →
(λ i →
ua e i ,
isProp→PathP {B = λ j → isFinSet (ua e j)}
(λ _ → isPropIsFinSet) (X .snd) (𝔽in n .snd) i ))
(∣≃card∣ X ⋆̂ ∣ pathToEquiv (cong Fin p) ⋆ invEquiv (𝔽in≃Fin n) ∣)
card≡0 : card X ≡ 0 → X ≡ 𝟘
card≡0 p =
propTruncIdempotent≃
(isOfHLevelRespectEquiv
1 (FinSet≡ X 𝟘)
(isOfHLevel≡ 1
(card≤1→isProp (subst (λ a → a ≤ 1) (sym p) (≤-solver 0 1))) (isProp⊥*))) .fst
(card≡n p)
card≡1 : card X ≡ 1 → X ≡ 𝟙
card≡1 p =
propTruncIdempotent≃
(isOfHLevelRespectEquiv
1 (FinSet≡ X 𝟙)
(isOfHLevel≡ 1
(card≤1→isProp (subst (λ a → a ≤ 1) (sym p) (≤-solver 1 1))) (isPropUnit*))) .fst
(Prop.map (λ q → q ∙ 𝔽in1≡𝟙) (card≡n p))
module _
(X : FinSet ℓ) where
isEmpty→card≡0 : ¬ X .fst → card X ≡ 0
isEmpty→card≡0 p =
Prop.rec (isSetℕ _ _) (λ e → sym (isEmpty→Fin≡0 _ (p ∘ invEq e))) (∣≃card∣ X)
isInhab→card>0 : ∥ X .fst ∥ → card X > 0
isInhab→card>0 = Prop.rec2 m≤n-isProp (λ p x → isInhab→Fin>0 _ (p .fst x)) (∣≃card∣ X)
hasNonEqualTerm→card>1 : {a b : X. fst} → ¬ a ≡ b → card X > 1
hasNonEqualTerm→card>1 {a = a} {b = b} q =
Prop.rec m≤n-isProp (λ p → hasNonEqualTerm→Fin>1 _ (p .fst a) (p .fst b) (q ∘ invEq (congEquiv p))) (∣≃card∣ X)
isContr→card≡1 : isContr (X .fst) → card X ≡ 1
isContr→card≡1 p = cardEquiv X (_ , isFinSetUnit) ∣ isContr→≃Unit p ∣
isProp→card≤1 : isProp (X .fst) → card X ≤ 1
isProp→card≤1 p = isProp→Fin≤1 (card X) (Prop.rec isPropIsProp (λ e → isOfHLevelRespectEquiv 1 e p) (∣≃card∣ X))
{- formulae about cardinality -}
-- results to be used in direct induction on FinSet
card𝟘 : card (𝟘 {ℓ}) ≡ 0
card𝟘 {ℓ = ℓ} = isEmpty→card≡0 (𝟘 {ℓ}) (Empty.rec*)
card𝟙 : card (𝟙 {ℓ}) ≡ 1
card𝟙 {ℓ = ℓ} = isContr→card≡1 (𝟙 {ℓ}) isContrUnit*
card𝔽in : (n : ℕ) → card (𝔽in {ℓ} n) ≡ n
card𝔽in {ℓ = ℓ} n = cardEquiv (𝔽in {ℓ} n) (_ , isFinSetFin) ∣ 𝔽in≃Fin n ∣
-- addition/product formula
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
card+ : card (_ , isFinSet⊎ X Y) ≡ card X + card Y
card+ = refl
card× : card (_ , isFinSet× X Y) ≡ card X · card Y
card× = refl
-- total summation/product of numerical functions from finite sets
module _
(X : FinSet ℓ)
(f : X .fst → ℕ) where
sum : ℕ
sum = card (_ , isFinSetΣ X (λ x → Fin (f x) , isFinSetFin))
prod : ℕ
prod = card (_ , isFinSetΠ X (λ x → Fin (f x) , isFinSetFin))
module _
(f : 𝟘 {ℓ} .fst → ℕ) where
sum𝟘 : sum 𝟘 f ≡ 0
sum𝟘 =
isEmpty→card≡0 (_ , isFinSetΣ 𝟘 (λ x → Fin (f x) , isFinSetFin))
((invEquiv (Σ-cong-equiv-fst (invEquiv 𝟘≃Empty)) ⋆ ΣEmpty _) .fst)
prod𝟘 : prod 𝟘 f ≡ 1
prod𝟘 =
isContr→card≡1 (_ , isFinSetΠ 𝟘 (λ x → Fin (f x) , isFinSetFin))
(isContrΠ⊥*)
module _
(f : 𝟙 {ℓ} .fst → ℕ) where
sum𝟙 : sum 𝟙 f ≡ f tt*
sum𝟙 =
cardEquiv (_ , isFinSetΣ 𝟙 (λ x → Fin (f x) , isFinSetFin))
(Fin (f tt*) , isFinSetFin) ∣ Σ-contractFst isContrUnit* ∣
prod𝟙 : prod 𝟙 f ≡ f tt*
prod𝟙 =
cardEquiv (_ , isFinSetΠ 𝟙 (λ x → Fin (f x) , isFinSetFin))
(Fin (f tt*) , isFinSetFin) ∣ ΠUnit* _ ∣
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst ⊎ Y .fst → ℕ) where
sum⊎ : sum (_ , isFinSet⊎ X Y) f ≡ sum X (f ∘ inl) + sum Y (f ∘ inr)
sum⊎ =
cardEquiv (_ , isFinSetΣ (_ , isFinSet⊎ X Y) (λ x → Fin (f x) , isFinSetFin))
(_ , isFinSet⊎ (_ , isFinSetΣ X (λ x → Fin (f (inl x)) , isFinSetFin))
(_ , isFinSetΣ Y (λ y → Fin (f (inr y)) , isFinSetFin))) ∣ Σ⊎≃ ∣
∙ card+ (_ , isFinSetΣ X (λ x → Fin (f (inl x)) , isFinSetFin))
(_ , isFinSetΣ Y (λ y → Fin (f (inr y)) , isFinSetFin))
prod⊎ : prod (_ , isFinSet⊎ X Y) f ≡ prod X (f ∘ inl) · prod Y (f ∘ inr)
prod⊎ =
cardEquiv (_ , isFinSetΠ (_ , isFinSet⊎ X Y) (λ x → Fin (f x) , isFinSetFin))
(_ , isFinSet× (_ , isFinSetΠ X (λ x → Fin (f (inl x)) , isFinSetFin))
(_ , isFinSetΠ Y (λ y → Fin (f (inr y)) , isFinSetFin))) ∣ Π⊎≃ ∣
∙ card× (_ , isFinSetΠ X (λ x → Fin (f (inl x)) , isFinSetFin))
(_ , isFinSetΠ Y (λ y → Fin (f (inr y)) , isFinSetFin))
-- technical lemma
module _
(n : ℕ)(f : 𝔽in {ℓ} (1 + n) .fst → ℕ) where
sum𝔽in1+n : sum (𝔽in (1 + n)) f ≡ f (inl tt*) + sum (𝔽in n) (f ∘ inr)
sum𝔽in1+n = sum⊎ 𝟙 (𝔽in n) f ∙ (λ i → sum𝟙 (f ∘ inl) i + sum (𝔽in n) (f ∘ inr))
prod𝔽in1+n : prod (𝔽in (1 + n)) f ≡ f (inl tt*) · prod (𝔽in n) (f ∘ inr)
prod𝔽in1+n = prod⊎ 𝟙 (𝔽in n) f ∙ (λ i → prod𝟙 (f ∘ inl) i · prod (𝔽in n) (f ∘ inr))
sumConst𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(c : ℕ)(h : (x : 𝔽in n .fst) → f x ≡ c) → sum (𝔽in n) f ≡ c · n
sumConst𝔽in 0 f c _ = sum𝟘 f ∙ 0≡m·0 c
sumConst𝔽in (suc n) f c h =
sum𝔽in1+n n f
∙ (λ i → h (inl tt*) i + sumConst𝔽in n (f ∘ inr) c (h ∘ inr) i)
∙ sym (·-suc c n)
prodConst𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(c : ℕ)(h : (x : 𝔽in n .fst) → f x ≡ c) → prod (𝔽in n) f ≡ c ^ n
prodConst𝔽in 0 f c _ = prod𝟘 f
prodConst𝔽in (suc n) f c h =
prod𝔽in1+n n f
∙ (λ i → h (inl tt*) i · prodConst𝔽in n (f ∘ inr) c (h ∘ inr) i)
module _
(X : FinSet ℓ)
(f : X .fst → ℕ)
(c : ℕ)(h : (x : X .fst) → f x ≡ c) where
sumConst : sum X f ≡ c · card X
sumConst =
elimProp
(λ X → (f : X .fst → ℕ)(c : ℕ)(h : (x : X .fst) → f x ≡ c) → sum X f ≡ c · (card X))
(λ X → isPropΠ3 (λ _ _ _ → isSetℕ _ _))
(λ n f c h → sumConst𝔽in n f c h ∙ (λ i → c · card𝔽in {ℓ = ℓ} n (~ i))) X f c h
prodConst : prod X f ≡ c ^ card X
prodConst =
elimProp
(λ X → (f : X .fst → ℕ)(c : ℕ)(h : (x : X .fst) → f x ≡ c) → prod X f ≡ c ^ (card X))
(λ X → isPropΠ3 (λ _ _ _ → isSetℕ _ _))
(λ n f c h → prodConst𝔽in n f c h ∙ (λ i → c ^ card𝔽in {ℓ = ℓ} n (~ i))) X f c h
private
≡≤ : {m n l k r s : ℕ} → m ≤ n → l ≤ k → r ≡ m + l → s ≡ n + k → r ≤ s
≡≤ {m = m} {l = l} {k = k} p q u v = subst2 (_≤_) (sym u) (sym v) (≤-+-≤ p q)
≡< : {m n l k r s : ℕ} → m < n → l ≤ k → r ≡ m + l → s ≡ n + k → r < s
≡< {m = m} {l = l} {k = k} p q u v = subst2 (_<_) (sym u) (sym v) (<-+-≤ p q)
sum≤𝔽in : (n : ℕ)(f g : 𝔽in {ℓ} n .fst → ℕ)(h : (x : 𝔽in n .fst) → f x ≤ g x) → sum (𝔽in n) f ≤ sum (𝔽in n) g
sum≤𝔽in 0 f g _ = subst2 (_≤_) (sym (sum𝟘 f)) (sym (sum𝟘 g)) ≤-refl
sum≤𝔽in (suc n) f g h =
≡≤ (h (inl tt*)) (sum≤𝔽in n (f ∘ inr) (g ∘ inr) (h ∘ inr)) (sum𝔽in1+n n f) (sum𝔽in1+n n g)
sum<𝔽in : (n : ℕ)(f g : 𝔽in {ℓ} n .fst → ℕ)(t : ∥ 𝔽in {ℓ} n .fst ∥)(h : (x : 𝔽in n .fst) → f x < g x)
→ sum (𝔽in n) f < sum (𝔽in n) g
sum<𝔽in {ℓ = ℓ} 0 _ _ t _ = Empty.rec (<→≢ (isInhab→card>0 (𝔽in 0) t) (card𝟘 {ℓ = ℓ}))
sum<𝔽in (suc n) f g t h =
≡< (h (inl tt*)) (sum≤𝔽in n (f ∘ inr) (g ∘ inr) (<-weaken ∘ h ∘ inr)) (sum𝔽in1+n n f) (sum𝔽in1+n n g)
module _
(X : FinSet ℓ)
(f g : X .fst → ℕ) where
module _
(h : (x : X .fst) → f x ≡ g x) where
sum≡ : sum X f ≡ sum X g
sum≡ i = sum X (λ x → h x i)
prod≡ : prod X f ≡ prod X g
prod≡ i = prod X (λ x → h x i)
module _
(h : (x : X .fst) → f x ≤ g x) where
sum≤ : sum X f ≤ sum X g
sum≤ =
elimProp
(λ X → (f g : X .fst → ℕ)(h : (x : X .fst) → f x ≤ g x) → sum X f ≤ sum X g)
(λ X → isPropΠ3 (λ _ _ _ → m≤n-isProp)) sum≤𝔽in X f g h
module _
(t : ∥ X .fst ∥)
(h : (x : X .fst) → f x < g x) where
sum< : sum X f < sum X g
sum< =
elimProp
(λ X → (f g : X .fst → ℕ)(t : ∥ X .fst ∥)(h : (x : X .fst) → f x < g x) → sum X f < sum X g)
(λ X → isPropΠ4 (λ _ _ _ _ → m≤n-isProp)) sum<𝔽in X f g t h
module _
(X : FinSet ℓ)
(f : X .fst → ℕ) where
module _
(c : ℕ)(h : (x : X .fst) → f x ≤ c) where
sumBounded : sum X f ≤ c · card X
sumBounded = subst (λ a → sum X f ≤ a) (sumConst X (λ _ → c) c (λ _ → refl)) (sum≤ X f (λ _ → c) h)
module _
(c : ℕ)(h : (x : X .fst) → f x ≥ c) where
sumBoundedBelow : sum X f ≥ c · card X
sumBoundedBelow = subst (λ a → sum X f ≥ a) (sumConst X (λ _ → c) c (λ _ → refl)) (sum≤ X (λ _ → c) f h)
-- some combinatorial identities
module _
(X : FinSet ℓ )
(Y : X .fst → FinSet ℓ') where
cardΣ : card (_ , isFinSetΣ X Y) ≡ sum X (λ x → card (Y x))
cardΣ =
cardEquiv (_ , isFinSetΣ X Y) (_ , isFinSetΣ X (λ x → Fin (card (Y x)) , isFinSetFin))
(Prop.map Σ-cong-equiv-snd
(choice X (λ x → Y x .fst ≃ Fin (card (Y x))) (λ x → ∣≃card∣ (Y x))))
cardΠ : card (_ , isFinSetΠ X Y) ≡ prod X (λ x → card (Y x))
cardΠ =
cardEquiv (_ , isFinSetΠ X Y) (_ , isFinSetΠ X (λ x → Fin (card (Y x)) , isFinSetFin))
(Prop.map equivΠCod
(choice X (λ x → Y x .fst ≃ Fin (card (Y x))) (λ x → ∣≃card∣ (Y x))))
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
card→ : card (_ , isFinSet→ X Y) ≡ card Y ^ card X
card→ = cardΠ X (λ _ → Y) ∙ prodConst X (λ _ → card Y) (card Y) (λ _ → refl)
module _
(X : FinSet ℓ ) where
cardAut : card (_ , isFinSetAut X) ≡ LehmerCode.factorial (card X)
cardAut = refl
module _
(X : FinSet ℓ )
(Y : FinSet ℓ')
(f : X .fst → Y .fst) where
sumCardFiber : card X ≡ sum Y (λ y → card (_ , isFinSetFiber X Y f y))
sumCardFiber =
cardEquiv X (_ , isFinSetΣ Y (λ y → _ , isFinSetFiber X Y f y)) ∣ totalEquiv f ∣
∙ cardΣ Y (λ y → _ , isFinSetFiber X Y f y)
-- the pigeonhole priniple
-- a logical lemma
private
¬ΠQ→¬¬ΣP : (X : Type ℓ)
(P : X → Type ℓ' )
(Q : X → Type ℓ'')
(r : (x : X) → ¬ (P x) → Q x)
→ ¬ ((x : X) → Q x) → ¬ ¬ (Σ X P)
¬ΠQ→¬¬ΣP _ _ _ r g f = g (λ x → r x (λ p → f (x , p)))
module _
(f : X .fst → Y .fst)
(n : ℕ) where
fiberCount : ((y : Y .fst) → card (_ , isFinSetFiber X Y f y) ≤ n) → card X ≤ n · card Y
fiberCount h =
subst (λ a → a ≤ _) (sym (sumCardFiber X Y f))
(sumBounded Y (λ y → card (_ , isFinSetFiber X Y f y)) n h)
module _
(p : card X > n · card Y) where
¬¬pigeonHole : ¬ ¬ (Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > n)
¬¬pigeonHole =
¬ΠQ→¬¬ΣP (Y .fst) (λ y → _ > n) (λ y → _ ≤ n)
(λ y → <-asym') (λ h → <-asym p (fiberCount h))
pigeonHole : ∥ Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > n ∥
pigeonHole = PeirceLaw (isFinSetΣ Y (λ _ → _ , isDecProp→isFinSet m≤n-isProp (≤Dec _ _))) ¬¬pigeonHole
-- a special case, proved in Cubical.Data.Fin.Properties
-- a technical lemma
private
Σ∥P∥→∥ΣP∥ : (X : Type ℓ)(P : X → Type ℓ')
→ Σ X (λ x → ∥ P x ∥) → ∥ Σ X P ∥
Σ∥P∥→∥ΣP∥ _ _ (x , p) = Prop.map (λ q → x , q) p
module _
(f : X .fst → Y .fst)
(p : card X > card Y) where
fiberNonEqualTerm : Σ[ y ∈ Y .fst ] card (_ , isFinSetFiber X Y f y) > 1
→ ∥ Σ[ y ∈ Y .fst ] Σ[ a ∈ fiber f y ] Σ[ b ∈ fiber f y ] ¬ a ≡ b ∥
fiberNonEqualTerm (y , p) = Σ∥P∥→∥ΣP∥ _ _ (y , card>1→hasNonEqualTerm {X = _ , isFinSetFiber X Y f y} p)
nonInj : Σ[ y ∈ Y .fst ] Σ[ a ∈ fiber f y ] Σ[ b ∈ fiber f y ] ¬ a ≡ b
→ Σ[ x ∈ X .fst ] Σ[ x' ∈ X .fst ] (¬ x ≡ x') × (f x ≡ f x')
nonInj (y , (x , p) , (x' , q) , t) .fst = x
nonInj (y , (x , p) , (x' , q) , t) .snd .fst = x'
nonInj (y , (x , p) , (x' , q) , t) .snd .snd .fst u =
t (λ i → u i , isSet→SquareP (λ i j → isFinSet→isSet (Y .snd)) p q (cong f u) refl i)
nonInj (y , (x , p) , (x' , q) , t) .snd .snd .snd = p ∙ sym q
pigeonHole' : ∥ Σ[ x ∈ X .fst ] Σ[ x' ∈ X .fst ] (¬ x ≡ x') × (f x ≡ f x') ∥
pigeonHole' =
Prop.map nonInj
(Prop.rec isPropPropTrunc fiberNonEqualTerm
(pigeonHole {X = X} {Y = Y} f 1 (subst (λ a → _ > a) (sym (·-identityˡ _)) p)))
-- cardinality and injection/surjection
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
module _
(f : X .fst → Y .fst) where
card↪Inequality' : isEmbedding f → card X ≤ card Y
card↪Inequality' p =
subst2 (_≤_)
(sym (sumCardFiber X Y f))
(·-identityˡ _)
(sumBounded Y (λ y → card (_ , isFinSetFiber X Y f y)) 1
(λ y → isProp→card≤1 (_ , isFinSetFiber X Y f y)
(isEmbedding→hasPropFibers p y)))
card↠Inequality' : isSurjection f → card X ≥ card Y
card↠Inequality' p =
subst2 (_≥_)
(sym (sumCardFiber X Y f))
(·-identityˡ _)
(sumBoundedBelow Y (λ y → card (_ , isFinSetFiber X Y f y)) 1
(λ y → isInhab→card>0 (_ , isFinSetFiber X Y f y) (p y)))
card↪Inequality : ∥ X .fst ↪ Y .fst ∥ → card X ≤ card Y
card↪Inequality = Prop.rec m≤n-isProp (λ (f , p) → card↪Inequality' f p)
card↠Inequality : ∥ X .fst ↠ Y .fst ∥ → card X ≥ card Y
card↠Inequality = Prop.rec m≤n-isProp (λ (f , p) → card↠Inequality' f p)
-- maximal value of numerical functions
module _
(X : Type ℓ)
(f : X → ℕ) where
module _
(x : X) where
isMax : Type ℓ
isMax = (x' : X) → f x' ≤ f x
isPropIsMax : isProp isMax
isPropIsMax = isPropΠ (λ _ → m≤n-isProp)
uniqMax : (x x' : X) → isMax x → isMax x' → f x ≡ f x'
uniqMax x x' p q = ≤-antisym (q x) (p x')
ΣMax : Type ℓ
ΣMax = Σ[ x ∈ X ] isMax x
∃Max : Type ℓ
∃Max = ∥ ΣMax ∥
∃Max→maxValue : ∃Max → ℕ
∃Max→maxValue =
SetElim.rec→Set
isSetℕ (λ (x , p) → f x)
(λ (x , p) (x' , q) → uniqMax x x' p q)
-- lemma about maximal value on sum type
module _
(X : Type ℓ )
(Y : Type ℓ')
(f : X ⊎ Y → ℕ) where
ΣMax⊎-case : ((x , p) : ΣMax X (f ∘ inl))((y , q) : ΣMax Y (f ∘ inr))
→ Trichotomy (f (inl x)) (f (inr y)) → ΣMax (X ⊎ Y) f
ΣMax⊎-case (x , p) (y , q) (lt r) .fst = inr y
ΣMax⊎-case (x , p) (y , q) (lt r) .snd (inl x') = ≤-trans (p x') (<-weaken r)
ΣMax⊎-case (x , p) (y , q) (lt r) .snd (inr y') = q y'
ΣMax⊎-case (x , p) (y , q) (eq r) .fst = inr y
ΣMax⊎-case (x , p) (y , q) (eq r) .snd (inl x') = ≤-trans (p x') (_ , r)
ΣMax⊎-case (x , p) (y , q) (eq r) .snd (inr y') = q y'
ΣMax⊎-case (x , p) (y , q) (gt r) .fst = inl x
ΣMax⊎-case (x , p) (y , q) (gt r) .snd (inl x') = p x'
ΣMax⊎-case (x , p) (y , q) (gt r) .snd (inr y') = ≤-trans (q y') (<-weaken r)
∃Max⊎ : ∃Max X (f ∘ inl) → ∃Max Y (f ∘ inr) → ∃Max (X ⊎ Y) f
∃Max⊎ = Prop.map2 (λ p q → ΣMax⊎-case p q (_≟_ _ _))
ΣMax𝟙 : (f : 𝟙 {ℓ} .fst → ℕ) → ΣMax _ f
ΣMax𝟙 f .fst = tt*
ΣMax𝟙 f .snd x = _ , cong f (sym (isContrUnit* .snd x))
∃Max𝟙 : (f : 𝟙 {ℓ} .fst → ℕ) → ∃Max _ f
∃Max𝟙 f = ∣ ΣMax𝟙 f ∣
∃Max𝔽in : (n : ℕ)(f : 𝔽in {ℓ} n .fst → ℕ)(x : ∥ 𝔽in {ℓ} n .fst ∥) → ∃Max _ f
∃Max𝔽in {ℓ = ℓ} 0 _ x = Empty.rec (<→≢ (isInhab→card>0 (𝔽in 0) x) (card𝟘 {ℓ = ℓ}))
∃Max𝔽in 1 f _ =
subst (λ X → (f : X .fst → ℕ) → ∃Max _ f) (sym 𝔽in1≡𝟙) ∃Max𝟙 f
∃Max𝔽in (suc (suc n)) f _ =
∃Max⊎ (𝟙 .fst) (𝔽in (suc n) .fst) f (∃Max𝟙 (f ∘ inl)) (∃Max𝔽in (suc n) (f ∘ inr) ∣ * {n = n} ∣)
module _
(X : FinSet ℓ)
(f : X .fst → ℕ)
(x : ∥ X .fst ∥) where
∃MaxFinSet : ∃Max _ f
∃MaxFinSet =
elimProp
(λ X → (f : X .fst → ℕ)(x : ∥ X .fst ∥) → ∃Max _ f)
(λ X → isPropΠ2 (λ _ _ → isPropPropTrunc)) ∃Max𝔽in X f x
maxValue : ℕ
maxValue = ∃Max→maxValue _ _ ∃MaxFinSet
{- some formal consequences of card -}
-- card induces equivalence from set truncation of FinSet to natural numbers
open Iso
Iso-∥FinSet∥₂-ℕ : Iso ∥ FinSet ℓ ∥₂ ℕ
Iso-∥FinSet∥₂-ℕ .fun = Set.rec isSetℕ card
Iso-∥FinSet∥₂-ℕ .inv n = ∣ 𝔽in n ∣₂
Iso-∥FinSet∥₂-ℕ .rightInv n = card𝔽in n
Iso-∥FinSet∥₂-ℕ {ℓ = ℓ} .leftInv =
Set.elim {B = λ X → ∣ 𝔽in (Set.rec isSetℕ card X) ∣₂ ≡ X}
(λ X → isSetPathImplicit)
(elimProp (λ X → ∣ 𝔽in (card X) ∣₂ ≡ ∣ X ∣₂) (λ X → squash₂ _ _)
(λ n i → ∣ 𝔽in (card𝔽in {ℓ = ℓ} n i) ∣₂))
-- this is the definition of natural numbers you learned from school
∥FinSet∥₂≃ℕ : ∥ FinSet ℓ ∥₂ ≃ ℕ
∥FinSet∥₂≃ℕ = isoToEquiv Iso-∥FinSet∥₂-ℕ
-- FinProp is equivalent to Bool
Bool→FinProp : Bool → FinProp ℓ
Bool→FinProp true = 𝟙 , isPropUnit*
Bool→FinProp false = 𝟘 , isProp⊥*
injBool→FinProp : (x y : Bool) → Bool→FinProp {ℓ = ℓ} x ≡ Bool→FinProp y → x ≡ y
injBool→FinProp true true _ = refl
injBool→FinProp false false _ = refl
injBool→FinProp true false p = Empty.rec (snotz (cong (card ∘ fst) p))
injBool→FinProp false true p = Empty.rec (znots (cong (card ∘ fst) p))
isEmbeddingBool→FinProp : isEmbedding (Bool→FinProp {ℓ = ℓ})
isEmbeddingBool→FinProp = injEmbedding isSetBool isSetFinProp (λ {x} {y} → injBool→FinProp x y)
card-case : (P : FinProp ℓ) → {n : ℕ} → card (P .fst) ≡ n → Σ[ x ∈ Bool ] Bool→FinProp x ≡ P
card-case P {n = 0} p = false , FinProp≡ (𝟘 , isProp⊥*) P .fst (cong fst (sym (card≡0 {X = P .fst} p)))
card-case P {n = 1} p = true , FinProp≡ (𝟙 , isPropUnit*) P .fst (cong fst (sym (card≡1 {X = P .fst} p)))
card-case P {n = suc (suc n)} p =
Empty.rec (¬-<-zero (pred-≤-pred (subst (λ a → a ≤ 1) p (isProp→card≤1 (P .fst) (P .snd)))))
isSurjectionBool→FinProp : isSurjection (Bool→FinProp {ℓ = ℓ})
isSurjectionBool→FinProp P = ∣ card-case P refl ∣
FinProp≃Bool : FinProp ℓ ≃ Bool
FinProp≃Bool =
invEquiv (Bool→FinProp ,
isEmbedding×isSurjection→isEquiv (isEmbeddingBool→FinProp , isSurjectionBool→FinProp))
isFinSetFinProp : isFinSet (FinProp ℓ)
isFinSetFinProp = EquivPresIsFinSet (invEquiv FinProp≃Bool) isFinSetBool
-- a more computationally efficient version of equivalence type
module _
(X : FinSet ℓ )
(Y : FinSet ℓ') where
isFinSet≃Eff' : Dec (card X ≡ card Y) → isFinSet (X .fst ≃ Y .fst)
isFinSet≃Eff' (yes p) = factorial (card Y) ,
Prop.elim2 (λ _ _ → isPropPropTrunc {A = _ ≃ Fin _})
(λ p1 p2
→ ∣ equivComp (p1 ⋆ pathToEquiv (cong Fin p) ⋆ SumFin≃Fin _) (p2 ⋆ SumFin≃Fin _)
⋆ lehmerEquiv ⋆ lehmerFinEquiv
⋆ invEquiv (SumFin≃Fin _) ∣)
(∣≃card∣ X) (∣≃card∣ Y)
isFinSet≃Eff' (no ¬p) = 0 , ∣ uninhabEquiv (¬p ∘ cardEquiv X Y ∘ ∣_∣) (idfun _) ∣
isFinSet≃Eff : isFinSet (X .fst ≃ Y .fst)
isFinSet≃Eff = isFinSet≃Eff' (discreteℕ _ _)
module _
(X Y : FinSet ℓ) where
isFinSetType≡Eff : isFinSet (X .fst ≡ Y .fst)
isFinSetType≡Eff = EquivPresIsFinSet (invEquiv univalence) (isFinSet≃Eff X Y)
| {
"alphanum_fraction": 0.5474364896,
"avg_line_length": 33.6702954899,
"ext": "agda",
"hexsha": "4402e7b8b69e66e590ea704d8d740114275663e2",
"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": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Data/FinSet/Cardinality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"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": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Data/FinSet/Cardinality.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Data/FinSet/Cardinality.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 9972,
"size": 21650
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidable setoid membership over vectors.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (DecSetoid)
module Data.Vec.Membership.DecSetoid {c ℓ} (DS : DecSetoid c ℓ) where
open import Data.Vec using (Vec)
open import Data.Vec.Relation.Unary.Any using (any)
open import Relation.Nullary using (Dec)
open DecSetoid DS renaming (Carrier to A)
------------------------------------------------------------------------
-- Re-export contents of propositional membership
open import Data.Vec.Membership.Setoid setoid public
------------------------------------------------------------------------
-- Other operations
infix 4 _∈?_
_∈?_ : ∀ x {n} (xs : Vec A n) → Dec (x ∈ xs)
x ∈? xs = any (x ≟_) xs
| {
"alphanum_fraction": 0.4822616408,
"avg_line_length": 30.0666666667,
"ext": "agda",
"hexsha": "f8b7abd5d88df66cde09f50297bd4f2e03152026",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Membership/DecSetoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Membership/DecSetoid.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/Vec/Membership/DecSetoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 185,
"size": 902
} |
module _ where
open import Agda.Primitive.Cubical
postulate
PathP : ∀ {ℓ} (A : I → Set ℓ) → A i0 → A i1 → Set ℓ
{-# BUILTIN PATHP PathP #-}
| {
"alphanum_fraction": 0.5769230769,
"avg_line_length": 17.3333333333,
"ext": "agda",
"hexsha": "ca938f5c2c0dafcedc08fcef44d95e2033ca8b3c",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-04-01T18:30:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-04-01T18:30:09.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/Issue2788c.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Fail/Issue2788c.agda",
"max_line_length": 53,
"max_stars_count": 2,
"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/Issue2788c.agda",
"max_stars_repo_stars_event_max_datetime": "2020-09-20T00:28:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-29T09:40:30.000Z",
"num_tokens": 58,
"size": 156
} |
module #8 where
{-
Define multiplication and exponentiation using recN. Verify that (N, +, 0, ×, 1) is
a semiring using only indN. You will probably also need to use symmetry and transitivity of
equality, Lemmas 2.1.1 and 2.1.2.
-}
open import Data.Nat
recₙ : ∀{c}{C : Set c} → C → (ℕ → C → C) → ℕ → C
recₙ c₀ cₛ zero = c₀
recₙ c₀ cₛ (suc n) = cₛ n (recₙ c₀ cₛ n)
mul-recₙ : ℕ → ℕ → ℕ
mul-recₙ n = recₙ 0 (λ _ z → z + n)
exp-recₙ : ℕ → ℕ → ℕ
exp-recₙ n = recₙ 1 (λ _ z → z * n)
ind-ℕ : ∀{k}{C : ℕ → Set k} → C zero → ((n : ℕ) → C n → C (suc n)) → (n : ℕ) → C n
ind-ℕ c0 cs zero = c0
ind-ℕ c0 cs (suc n) = cs n (ind-ℕ c0 cs n)
record Semiring (X : Set) : Set where
field
ε : X
_⊕_ : X → X → X
_⊛_ : X → X → X
open Semiring {{...}} public
natIsSemiring : Semiring ℕ
natIsSemiring = record { ε = zero
; _⊕_ = _+_
; _⊛_ = _*_
}
{- Semiring Laws Follow -}
| {
"alphanum_fraction": 0.523659306,
"avg_line_length": 23.1951219512,
"ext": "agda",
"hexsha": "1fada7ccbf1f7dba8746424964a31642f2cdb124",
"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": "Chapter1/#8.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": "Chapter1/#8.agda",
"max_line_length": 93,
"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": "Chapter1/#8.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 403,
"size": 951
} |
---------------------------------------
-- Pairs of sets
---------------------------------------
{-# OPTIONS --allow-unsolved-meta #-}
module sv20.assign2.SetTheory.Pairs where
-- Everything involving pairs, be them unordered
-- or ordered pairs. Also the definition of power set
-- and cartesian product between sets.
open import sv20.assign2.SetTheory.Logic
open import sv20.assign2.SetTheory.Algebra
open import sv20.assign2.SetTheory.Subset
open import sv20.assign2.SetTheory.ZAxioms
-- Pairs, justified by the pair axiom
_ₚ_ : 𝓢 → 𝓢 → 𝓢
x ₚ y = proj₁ (pair x y)
pair-d : (x y : 𝓢) → ∀ {z} → z ∈ x ₚ y ⇔ (z ≡ x ∨ z ≡ y)
pair-d x y = proj₂ _ (pair x y)
-- Both ∧-projections
pair-d₁ : (x y : 𝓢) → ∀ {z} → z ∈ x ₚ y → (z ≡ x ∨ z ≡ y)
pair-d₁ x y = ∧-proj₁ (pair-d x y)
pair-d₂ : (x y : 𝓢) → ∀ {z} → (z ≡ x ∨ z ≡ y) → z ∈ x ₚ y
pair-d₂ x y = ∧-proj₂ (pair-d x y)
pair-p₁ : (x y : 𝓢) → x ₚ y ≡ y ₚ x
pair-p₁ x y = equalitySubset (x ₚ y) (y ₚ x) (p₁ , p₂)
where
p₁ : (z : 𝓢) → z ∈ x ₚ y → z ∈ y ₚ x
p₁ z z∈x,y = pair-d₂ y x (∨-sym _ _ (pair-d₁ x y z∈x,y))
p₂ : (z : 𝓢) → z ∈ y ₚ x → z ∈ x ₚ y
p₂ z z∈y,x = pair-d₂ x y (∨-sym _ _ (pair-d₁ y x z∈y,x))
singleton : 𝓢 → 𝓢
singleton x = x ₚ x
singletonp : (x : 𝓢) → ∀ {z} → z ∈ singleton x → z ≡ x
singletonp x x₁ = ∨-idem _ (pair-d₁ x x x₁)
singletonp₂ : (x : 𝓢) → x ∈ singleton x
singletonp₂ x = pair-d₂ x x (inj₁ refl)
singletonp₃ : (x : 𝓢) → ∀ {y} → x ≡ y → x ∈ singleton y
singletonp₃ x x≡y = pair-d₂ _ _ (inj₁ x≡y)
singletonp₄ : (x y : 𝓢) → x ∈ singleton y → x ∩ singleton y ≡ ∅
singletonp₄ x y h = {!!}
where
p₁ : x ≡ y
p₁ = singletonp _ h
p₂ : x ∩ singleton x ≡ ∅
p₂ = {!!}
pair-prop-helper₁ : {a b c : 𝓢} → a ≡ b ∨ a ≡ c → a ≢ b → a ≡ c
pair-prop-helper₁ (inj₁ a≡b) h = ⊥-elim (h a≡b)
pair-prop-helper₁ (inj₂ refl) _ = refl
pair-prop-helper₂ : {a b : 𝓢} → a ≢ b → b ≢ a
pair-prop-helper₂ h b≡a = h (sym _ _ b≡a)
-- Theorem 44, p. 31 (Suppes, 1972).
pair-prop : (x y u v : 𝓢) → x ₚ y ≡ u ₚ v → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
pair-prop x y u v eq = ∨-e _ _ _ (pem (x ≡ y)) h-x≡y h-x≢y
where
u∈u,v : u ∈ (u ₚ v)
u∈u,v = ∨-prop₁ (pair-d₂ u v) refl
u∈x,y : u ∈ (x ₚ y)
u∈x,y = memberEq u (u ₚ v) (x ₚ y) (u∈u,v , (sym _ _ eq))
disj₁ : u ≡ x ∨ u ≡ y
disj₁ = pair-d₁ _ _ u∈x,y
v∈u,v : v ∈ (u ₚ v)
v∈u,v = ∨-prop₂ (pair-d₂ u v) refl
v∈x,y : v ∈ (x ₚ y)
v∈x,y = memberEq v (u ₚ v) (x ₚ y) (v∈u,v , (sym _ _ eq))
disj₂ : v ≡ x ∨ v ≡ y
disj₂ = pair-d₁ _ _ v∈x,y
x∈x,y : x ∈ (x ₚ y)
x∈x,y = ∨-prop₁ (pair-d₂ x y) refl
x∈u,v : x ∈ (u ₚ v)
x∈u,v = memberEq x (x ₚ y) (u ₚ v) (x∈x,y , eq)
disj₃ : x ≡ u ∨ x ≡ v
disj₃ = pair-d₁ _ _ x∈u,v
y∈x,y : y ∈ (x ₚ y)
y∈x,y = ∨-prop₂ (pair-d₂ x y) refl
y∈u,v : y ∈ (u ₚ v)
y∈u,v = memberEq y (x ₚ y) (u ₚ v) (y∈x,y , eq)
disj₄ : y ≡ u ∨ y ≡ v
disj₄ = pair-d₁ _ _ y∈u,v
h-x≡y : x ≡ y → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h-x≡y eq₂ = inj₁ (x≡u , v≡y)
where
x≡u : u ≡ x
x≡u = ∨-idem _ disj-aux
where
disj-aux : u ≡ x ∨ u ≡ x
disj-aux = subs _ (sym _ _ eq₂) disj₁
v≡y : v ≡ y
v≡y = ∨-idem _ disj-aux
where
disj-aux : v ≡ y ∨ v ≡ y
disj-aux = subs _ eq₂ disj₂
h-x≢y : x ≢ y → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h-x≢y ¬eq = ∨-e _ _ _ (pem (x ≡ u)) h₁ h₂
where
h₁ : x ≡ u → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h₁ x≡u = ∨-e _ _ _ (pem (y ≡ u)) h₁₁ h₁₂
where
h₁₁ : y ≡ u → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h₁₁ y≡u = ⊥-elim (¬eq (trans x≡u (sym _ _ y≡u)))
h₁₂ : y ≢ u → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h₁₂ h = inj₁ (sym _ _ x≡u , sym _ _ (pair-prop-helper₁ disj₄ h))
h₂ : x ≢ u → (u ≡ x ∧ v ≡ y) ∨ (v ≡ x ∧ u ≡ y)
h₂ h = inj₂ (sym _ _ (pair-prop-helper₁ disj₃ h)
,
(pair-prop-helper₁ disj₁ (pair-prop-helper₂ h)))
-- Theorem 45, p. 32 (Suppes 1960).
singleton-eq : (x y : 𝓢) → singleton x ≡ singleton y → x ≡ y
singleton-eq x y eq = sym _ _ (∧-proj₁ (∨-idem _ aux))
where
aux : ((y ≡ x) ∧ (y ≡ x)) ∨ ((y ≡ x) ∧ (y ≡ x))
aux = pair-prop x x y y eq
singleton-⊆ : (x A : 𝓢) → x ∈ A → singleton x ⊆ A
singleton-⊆ x A x∈A t t∈xₛ = subs _ (sym _ _ (singletonp _ t∈xₛ)) x∈A
prop-p₂ : (y z : 𝓢) → y ₚ z ≡ singleton y ∪ singleton z
prop-p₂ y z = equalitySubset _ _ (p₁ , p₂)
where
p₁ : (x : 𝓢) → x ∈ y ₚ z → x ∈ singleton y ∪ singleton z
p₁ _ h = ∪-d₂ _ _ (∨-prop₅ (pair-d₁ _ _ h) (singletonp₃ _) (singletonp₃ _))
p₂ : (x : 𝓢) → x ∈ singleton y ∪ singleton z → x ∈ y ₚ z
p₂ x h = pair-d₂ _ _ (∨-prop₅ (∪-d₁ _ _ h) (singletonp _) (singletonp _))
-- Ordered pairs
_ₒ_ : 𝓢 → 𝓢 → 𝓢
x ₒ y = singleton x ₚ (x ₚ y)
-- Just an abvreviation for next theorem
abv₁ : 𝓢 → 𝓢 → 𝓢 → 𝓢 → Set
abv₁ u x v y = (u ₚ u ≡ x ₚ x ∧ u ₚ v ≡ x ₚ y) ∨ (u ₚ v ≡ x ₚ x ∧ u ₚ u ≡ x ₚ y)
-- Theorem 46, p. 32 (Suppes).
ord-p : (x y u v : 𝓢) → x ₒ y ≡ u ₒ v → x ≡ u ∧ y ≡ v
ord-p x y u v eq = ∨-e _ _ _ aux a→c b→c
where
aux : (singleton u ≡ singleton x ∧ (u ₚ v) ≡ (x ₚ y)) ∨
((u ₚ v) ≡ singleton x ∧ singleton u ≡ (x ₚ y))
aux = pair-prop _ _ _ _ eq
a→c : singleton u ≡ singleton x ∧ u ₚ v ≡ x ₚ y → x ≡ u ∧ y ≡ v
a→c (eqₚ , eqₛ) = x≡u , y≡v
where
x≡u : x ≡ u
x≡u = singleton-eq _ _ (sym _ _ eqₚ)
p₁ : (x ≡ u ∧ y ≡ v) ∨ (y ≡ u ∧ x ≡ v)
p₁ = pair-prop _ _ _ _ eqₛ
p₂ : x ≡ u ∧ y ≡ v → y ≡ v
p₂ (h₁ , h₂) = h₂
p₃ : y ≡ u ∧ x ≡ v → y ≡ v
p₃ (h₁ , h₂) = subs (λ w → w ≡ v) x≡y h₂
where
x≡y : x ≡ y
x≡y = subs (λ w → x ≡ w) (sym y u h₁) x≡u
y≡v : y ≡ v
y≡v = ∨-e _ _ _ p₁ p₂ p₃
b→c : u ₚ v ≡ singleton x ∧ singleton u ≡ x ₚ y → x ≡ u ∧ y ≡ v
b→c (h₁ , h₂) = p₃ , subs (λ w → w ≡ v) p₈ p₄
where
p₁ : (x ≡ u ∧ x ≡ v) ∨ (x ≡ u ∧ x ≡ v)
p₁ = pair-prop _ _ _ _ h₁
p₂ : x ≡ u ∧ x ≡ v
p₂ = ∨-idem _ p₁
p₃ : x ≡ u
p₃ = ∧-proj₁ p₂
p₄ : x ≡ v
p₄ = ∧-proj₂ p₂
p₅ : (x ≡ u ∧ y ≡ u) ∨ (y ≡ u ∧ x ≡ u)
p₅ = pair-prop _ _ _ _ h₂
p₆ : x ≡ u ∧ y ≡ u
p₆ = ∨-∧ p₅
p₇ : y ≡ u
p₇ = ∧-proj₂ p₆
p₈ : x ≡ y
p₈ = subs (λ w → w ≡ y) (sym _ _ p₃) (sym _ _ p₇)
-- Power sets
𝓟_ : 𝓢 → 𝓢
𝓟 x = proj₁ (pow x)
-- Theorem 86, p. 47 (Suppes 1960)
𝓟-d : (x : 𝓢) → ∀ {z} → z ∈ (𝓟 x) ⇔ z ⊆ x
𝓟-d x = proj₂ _ (pow x)
-- Both projections.
𝓟-d₁ : (x : 𝓢) → ∀ {z} → z ∈ (𝓟 x) → z ⊆ x
𝓟-d₁ _ = ∧-proj₁ (𝓟-d _)
𝓟-d₂ : (x : 𝓢) → ∀ {z} → z ⊆ x → z ∈ (𝓟 x)
𝓟-d₂ _ = ∧-proj₂ (𝓟-d _)
-- Theorem 87, p. 47 (Suppes 1960).
A∈𝓟A : (A : 𝓢) → A ∈ 𝓟 A
A∈𝓟A A = 𝓟-d₂ A subsetOfItself
-- Theorem 91, p. 48 (Suppes 1960).
⊆𝓟 : (A B : 𝓢) → A ⊆ B ⇔ 𝓟 A ⊆ 𝓟 B
⊆𝓟 A B = iₗ , iᵣ
where
iₗ : A ⊆ B → 𝓟 A ⊆ 𝓟 B
iₗ A⊆B t t∈𝓟A = 𝓟-d₂ _ t⊆B
where
t⊆A : t ⊆ A
t⊆A = 𝓟-d₁ A t∈𝓟A
t⊆B : t ⊆ B
t⊆B = trans-⊆ _ _ _ (t⊆A , A⊆B)
iᵣ : 𝓟 A ⊆ 𝓟 B → A ⊆ B
iᵣ 𝓟A⊆𝓟B t t∈A = 𝓟-d₁ _ A∈𝓟B _ t∈A
where
A∈𝓟B : A ∈ 𝓟 B
A∈𝓟B = 𝓟A⊆𝓟B _ (A∈𝓟A _)
-- Theorem 92, p. 48 (Suppes 1960).
𝓟∪ : (A B : 𝓢) → (𝓟 A) ∪ (𝓟 B) ⊆ 𝓟 (A ∪ B)
𝓟∪ A B t t∈𝓟A∪𝓟B = 𝓟-d₂ _ t⊆A∪B
where
∪₁ : t ∈ 𝓟 A ∨ t ∈ 𝓟 B
∪₁ = ∪-d₁ _ _ t∈𝓟A∪𝓟B
p : t ⊆ A ∨ t ⊆ B
p = ∨-prop₄ aux₁ (𝓟-d₁ _)
where
aux₁ : t ⊆ A ∨ t ∈ 𝓟 B
aux₁ = ∨-prop₃ ∪₁ (𝓟-d₁ _)
t⊆A∪B : t ⊆ A ∪ B
t⊆A∪B = ∪-prop₂ _ _ _ p
-- Cartesian Product. First we have to prove some things using
-- the subset axiom in order to be able to define cartesian products.
-- Two abvreviations to make sub₄ shorter.
abv₂ : 𝓢 → 𝓢 → 𝓢 → Set
abv₂ z A B = z ∈ 𝓟 (𝓟 (A ∪ B))
abv₃ : 𝓢 → 𝓢 → 𝓢 → Set
abv₃ z A B = ∃ (λ y → ∃ (λ w → (y ∈ A ∧ w ∈ B) ∧ z ≡ y ₒ w))
--Instance of the subset axiom.
sub₄ : (A B : 𝓢) → ∃ (λ C → {z : 𝓢} → z ∈ C ⇔ abv₂ z A B ∧ abv₃ z A B)
sub₄ A B = sub (λ x → abv₃ x A B) (𝓟 (𝓟 (A ∪ B)))
-- Proved inside theorem 95, p. 49 (Suppes 1960)
prop₁ : (A B x : 𝓢) → abv₃ x A B → abv₂ x A B
prop₁ A B x (y , (z , ((y∈A , z∈B) , eqo))) = subs _ (sym _ _ eqo) yₒz∈𝓟𝓟A∪B
where
yₛ⊆A : singleton y ⊆ A
yₛ⊆A = singleton-⊆ _ _ y∈A
yₛ⊆A∪B : singleton y ⊆ A ∪ B
yₛ⊆A∪B t t∈yₛ = trans-⊆ _ _ _ (yₛ⊆A , (∪-prop _ _)) _ t∈yₛ
zₛ⊆B : singleton z ⊆ B
zₛ⊆B = singleton-⊆ _ _ z∈B
zₛ⊆A∪B : singleton z ⊆ A ∪ B
zₛ⊆A∪B t t∈zₛ = trans-⊆ _ _ _ (zₛ⊆B , ∪-prop₃ _ _) _ t∈zₛ
y,z⊆A∪B : y ₚ z ⊆ A ∪ B
y,z⊆A∪B t t∈y,z = ∪-prop₄ _ _ _ yₛ⊆A∪B zₛ⊆A∪B _ p
where
p : t ∈ singleton y ∪ singleton z
p = subs (λ w → t ∈ w) (prop-p₂ y z) t∈y,z
yₛ∈𝓟A∪B : singleton y ∈ 𝓟 (A ∪ B)
yₛ∈𝓟A∪B = 𝓟-d₂ _ yₛ⊆A∪B
y,z∈𝓟A∪B : y ₚ z ∈ 𝓟 (A ∪ B)
y,z∈𝓟A∪B = 𝓟-d₂ _ y,z⊆A∪B
yₒz⊆𝓟A∪B : y ₒ z ⊆ 𝓟 (A ∪ B)
yₒz⊆𝓟A∪B t t∈o = ∨-e _ _ _ (pair-d₁ _ _ t∈o) i₁ i₂
where
i₁ : t ≡ singleton y → t ∈ 𝓟 (A ∪ B)
i₁ eq = subs _ (sym t (singleton y) eq) yₛ∈𝓟A∪B
i₂ : t ≡ y ₚ z → t ∈ 𝓟 (A ∪ B)
i₂ eq = subs _ (sym t (y ₚ z) eq) y,z∈𝓟A∪B
yₒz∈𝓟𝓟A∪B : y ₒ z ∈ 𝓟 (𝓟 (A ∪ B))
yₒz∈𝓟𝓟A∪B = 𝓟-d₂ _ yₒz⊆𝓟A∪B
Aᵤ : 𝓢 → 𝓢 → 𝓢
Aᵤ A B = proj₁ (sub₄ A B)
-- Theorem 95, p 49 (Suppes 1960).
pAᵤ : (A B : 𝓢) → {z : 𝓢} → z ∈ (Aᵤ A B) ⇔ abv₂ z A B ∧ abv₃ z A B
pAᵤ A B = proj₂ _ (sub₄ A B)
crts : (A B : 𝓢) → ∃ (λ C → (z : 𝓢) → z ∈ C ⇔ abv₃ z A B)
crts A B = (Aᵤ A B) , (λ w → ⇔-p₂ w (pAᵤ A B) (prop₁ A B w))
_X_ : 𝓢 → 𝓢 → 𝓢
A X B = proj₁ (crts A B)
-- Theorem 97, p. 50 (Suppes 1960).
crts-p : (A B x : 𝓢) → x ∈ A X B ⇔ abv₃ x A B
crts-p A B x = proj₂ _ (crts A B) x
-- Both projections
crts-p₁ : (A B x : 𝓢) → x ∈ A X B → abv₃ x A B
crts-p₁ A B x = ∧-proj₁ (crts-p A B x)
crts-p₂ : (A B x : 𝓢) → abv₃ x A B → x ∈ A X B
crts-p₂ A B x = ∧-proj₂ (crts-p A B x)
crts-d₁ : (x y A B : 𝓢) → x ₒ y ∈ A X B → x ∈ A ∧ y ∈ B
crts-d₁ x y A B h = (subs (λ w → w ∈ A) (sym _ _ eq₁) aux∈A)
,
subs (λ w → w ∈ B) (sym _ _ eq₂) aux₂∈B
where
foo : ∃ (λ z → ∃ (λ w → (z ∈ A ∧ w ∈ B) ∧ (x ₒ y) ≡ (z ₒ w)))
foo = crts-p₁ A B (x ₒ y) h
aux : 𝓢
aux = proj₁ foo
aux-p : ∃ (λ w → (aux ∈ A ∧ w ∈ B) ∧ (x ₒ y) ≡ (aux ₒ w))
aux-p = proj₂ _ foo
aux₂ : 𝓢
aux₂ = proj₁ aux-p
aux₂-p : (aux ∈ A ∧ aux₂ ∈ B) ∧ (x ₒ y) ≡ (aux ₒ aux₂)
aux₂-p = proj₂ _ aux-p
aux∈A : aux ∈ A
aux∈A = ∧-proj₁ (∧-proj₁ aux₂-p)
aux₂∈B : aux₂ ∈ B
aux₂∈B = ∧-proj₂ (∧-proj₁ aux₂-p)
eq : x ₒ y ≡ aux ₒ aux₂
eq = ∧-proj₂ aux₂-p
eqs : x ≡ aux ∧ y ≡ aux₂
eqs = ord-p _ _ _ _ eq
eq₁ : x ≡ aux
eq₁ = ∧-proj₁ eqs
eq₂ : y ≡ aux₂
eq₂ = ∧-proj₂ eqs
-- References
--
-- Suppes, Patrick (1960). Axiomatic Set Theory.
-- The University Series in Undergraduate Mathematics.
-- D. Van Nostrand Company, inc.
--
-- Enderton, Herbert B. (1977). Elements of Set Theory.
-- Academic Press Inc.
| {
"alphanum_fraction": 0.4769157544,
"avg_line_length": 26.1970074813,
"ext": "agda",
"hexsha": "48ee1677182bdfc71178d3c210544410db30e2b5",
"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": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Pairs.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Pairs.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/sv20/assign2/SetTheory/Pairs.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5939,
"size": 10505
} |
postulate
A : Set
I : ..(_ : A) → Set
R : A → Set
f : ∀ ..(x : A) (r : R x) → I x
-- can now be used here ^
| {
"alphanum_fraction": 0.406779661,
"avg_line_length": 14.75,
"ext": "agda",
"hexsha": "46d60cb9dac6d05121214ac3beb144c23f7e7c24",
"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/Issue2128.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/Issue2128.agda",
"max_line_length": 33,
"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/Issue2128.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": 54,
"size": 118
} |
module examplesPaperJFP.VariableListForDispatchOnly where
open import Data.Product hiding (map)
open import Data.List
open import NativeIO
open import StateSizedIO.GUI.WxBindingsFFI
open import Relation.Binary.PropositionalEquality
data VarList : Set₁ where
[] : VarList
addVar : (A : Set) → Var A → VarList → VarList
prod : VarList → Set
prod [] = Unit
prod (addVar A v []) = A
prod (addVar A v l) = A × prod l
takeVar : (l : VarList) → NativeIO (prod l)
takeVar [] = nativeReturn unit
takeVar (addVar A v []) =
nativeTakeVar {A} v native>>= λ a → nativeReturn a
takeVar (addVar A v (addVar B v′ l)) =
nativeTakeVar {A} v native>>= λ a →
takeVar (addVar B v′ l) native>>= λ rest → nativeReturn ( a , rest )
putVar : (l : VarList) → prod l → NativeIO Unit
putVar [] _ = nativeReturn unit
putVar (addVar A v []) a = nativePutVar {A} v a
putVar (addVar A v (addVar B v′ l)) (a , rest) =
nativePutVar {A} v a native>>= λ _ →
putVar (addVar B v′ l) rest native>>= nativeReturn
dispatch : (l : VarList) → (prod l → NativeIO (prod l)) → NativeIO Unit
dispatch l f = takeVar l native>>= λ a →
f a native>>= λ a₁ →
putVar l a₁
dispatchList : (l : VarList) → List (prod l → NativeIO (prod l)) → NativeIO Unit
dispatchList l [] = nativeReturn unit
dispatchList l (p ∷ rest) = dispatch l p native>>= λ _ →
dispatchList l rest
| {
"alphanum_fraction": 0.5677540778,
"avg_line_length": 36.2272727273,
"ext": "agda",
"hexsha": "643c5459e42d44a8a7cd5a8b48f8b9235913aab9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/examplesPaperJFP/VariableListForDispatchOnly.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"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": "agda/ooAgda",
"max_issues_repo_path": "examples/examplesPaperJFP/VariableListForDispatchOnly.agda",
"max_line_length": 80,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/examplesPaperJFP/VariableListForDispatchOnly.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 483,
"size": 1594
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
{-
The generic nonrecursive higher inductive type with one point constructor and
one paths constructor.
-}
module lib.types.Generic1HIT {i j} (A : Type i) (B : Type j)
(g h : B → A) where
{-
data T : Type where
cc : A → T
pp : (b : B) → cc (f' b) ≡ cc (g b)
-}
module _ where
private
data #T-aux : Type (lmax i j) where
#cc : A → #T-aux
data #T : Type (lmax i j) where
#t : #T-aux → (Unit → Unit) → #T
T : Type _
T = #T
cc : A → T
cc a = #t (#cc a) _
postulate -- HIT
pp : (b : B) → cc (g b) == cc (h b)
module Elim {k} {P : T → Type k} (cc* : (a : A) → P (cc a))
(pp* : (b : B) → cc* (g b) == cc* (h b) [ P ↓ pp b ]) where
f : Π T P
f = f-aux phantom where
f-aux : Phantom pp* → Π T P
f-aux phantom (#t (#cc a) _) = cc* a
postulate -- HIT
pp-β : (b : B) → apd f (pp b) == pp* b
open Elim public using () renaming (f to elim)
module Rec {k} {C : Type k} (cc* : A → C)
(pp* : (b : B) → cc* (g b) == cc* (h b)) where
private module M = Elim cc* (λ b → ↓-cst-in (pp* b))
f : T → C
f = M.f
pp-β : (b : B) → ap f (pp b) == pp* b
pp-β b = apd=cst-in {f = f} (M.pp-β b)
module RecType {k} (C : A → Type k) (D : (b : B) → C (g b) ≃ C (h b)) where
open Rec C (ua ∘ D) public
coe-pp-β : (b : B) (d : C (g b)) → coe (ap f (pp b)) d == –> (D b) d
coe-pp-β b d =
coe (ap f (pp b)) d =⟨ pp-β _ |in-ctx (λ u → coe u d) ⟩
coe (ua (D b)) d =⟨ coe-β (D b) d ⟩
–> (D b) d ∎
-- Dependent path in [P] over [pp b]
module _ {b : B} {d : C (g b)} {d' : C (h b)} where
↓-pp-in : –> (D b) d == d' → d == d' [ f ↓ pp b ]
↓-pp-in p = from-transp f (pp b) (coe-pp-β b d ∙' p)
↓-pp-out : d == d' [ f ↓ pp b ] → –> (D b) d == d'
↓-pp-out p = ! (coe-pp-β b d) ∙ to-transp p
↓-pp-β : (q : –> (D b) d == d') → ↓-pp-out (↓-pp-in q) == q
↓-pp-β q =
↓-pp-out (↓-pp-in q)
=⟨ idp ⟩
! (coe-pp-β b d) ∙ to-transp (from-transp f (pp b) (coe-pp-β b d ∙' q))
=⟨ to-transp-β f (pp b) (coe-pp-β b d ∙' q) |in-ctx (λ u → ! (coe-pp-β b d) ∙ u) ⟩
! (coe-pp-β b d) ∙ (coe-pp-β b d ∙' q)
=⟨ lem (coe-pp-β b d) q ⟩
q ∎ where
lem : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : y == z)
→ ! p ∙ (p ∙' q) == q
lem idp idp = idp
| {
"alphanum_fraction": 0.4291649356,
"avg_line_length": 26.1630434783,
"ext": "agda",
"hexsha": "cd5a24776f4e1e53f36cd77aaba997f068de6f57",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/Generic1HIT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/Generic1HIT.agda",
"max_line_length": 99,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/Generic1HIT.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 1089,
"size": 2407
} |
-- Andreas, 2017-01-12, issue #2386
id : ∀{a}{A : Set a} → A → A
id x = x
data Eq (A : Set) : (x y : id A) → Set where
refl : (x : A) → Eq A x x
{-# BUILTIN EQUALITY Eq #-}
-- Should be accepted.
| {
"alphanum_fraction": 0.5198019802,
"avg_line_length": 16.8333333333,
"ext": "agda",
"hexsha": "af89e1cde945e2823ee5c718dcfa37d10b9df0ba",
"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/Issue2386BuiltinEqualityId.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/Issue2386BuiltinEqualityId.agda",
"max_line_length": 44,
"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/Issue2386BuiltinEqualityId.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": 82,
"size": 202
} |
{-# OPTIONS --warning=error --safe #-}
open import Everything.Safe
-- This file contains everything that is --safe, but uses K.
open import Logic.PropositionalLogic
open import Logic.PropositionalLogicExamples
open import Logic.PropositionalAxiomsTautology
open import Sets.FinSetWithK
open import Groups.FreeGroup.Lemmas
open import Groups.FreeGroup.UniversalProperty
open import Groups.FreeGroup.Parity
open import Groups.FreeProduct.UniversalProperty
module Everything.WithK where
| {
"alphanum_fraction": 0.8323108384,
"avg_line_length": 27.1666666667,
"ext": "agda",
"hexsha": "c48e1e28f618ce091d3dd8e5b03863a063a044f9",
"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": "Everything/WithK.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": "Everything/WithK.agda",
"max_line_length": 60,
"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": "Everything/WithK.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": 108,
"size": 489
} |
module Generic.Lib.Data.Product where
open import Data.Product renaming (map to pmap; zip to pzip) hiding (map₁; map₂) public
open import Generic.Lib.Intro
open import Generic.Lib.Category
infixl 4 _,ᵢ_
first : ∀ {α β γ} {A : Set α} {B : Set β} {C : A -> Set γ}
-> (∀ x -> C x) -> (p : A × B) -> C (proj₁ p) × B
first f (x , y) = f x , y
second : ∀ {α β γ} {A : Set α} {B : A -> Set β} {C : A -> Set γ}
-> (∀ {x} -> B x -> C x) -> Σ A B -> Σ A C
second g (x , y) = x , g y
-- `B` and `C` are in the same universe.
firstF : ∀ {α β} {A : Set α} {B : Set β} {C : A -> Set β}
{F : Set β -> Set β} {{fFunctor : RawFunctor F}}
-> (∀ x -> F (C x)) -> (p : A × B) -> F (C (proj₁ p) × B)
firstF f (x , y) = flip _,_ y <$> f x
-- `A` and `C` are in the same universe.
secondF : ∀ {α β} {A : Set α} {B : A -> Set β} {C : A -> Set α}
{F : Set α -> Set α} {{fFunctor : RawFunctor F}}
-> (∀ {x} -> B x -> F (C x)) -> Σ A B -> F (Σ A C)
secondF g (x , y) = _,_ x <$> g y
record Σᵢ {α β} (A : Set α) (B : .A -> Set β) : Set (α ⊔ β) where
constructor _,ᵢ_
field
.iproj₁ : A
iproj₂ : B iproj₁
open Σᵢ public
∃ᵢ : ∀ {α β} {A : Set α} -> (.A -> Set β) -> Set (α ⊔ β)
∃ᵢ = Σᵢ _
instance
,-inst : ∀ {α β} {A : Set α} {B : A -> Set β} {{x : A}} {{y : B x}} -> Σ A B
,-inst {{x}} {{y}} = x , y
,ᵢ-inst : ∀ {α β} {A : Set α} {B : .A -> Set β} {{x : A}} {{y : B x}} -> Σᵢ A B
,ᵢ-inst {{x}} {{y}} = x ,ᵢ y
| {
"alphanum_fraction": 0.4514363885,
"avg_line_length": 31.7826086957,
"ext": "agda",
"hexsha": "efb22caced340ab9533d17509d9db817f87dde22",
"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": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"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": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/Product.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 652,
"size": 1462
} |
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Modulo where
open import Cubical.HITs.Modulo.Base public
open import Cubical.HITs.Modulo.Properties public
| {
"alphanum_fraction": 0.7777777778,
"avg_line_length": 23.1428571429,
"ext": "agda",
"hexsha": "f23d6066165ea8fbdae3e6713532327d04c7d0f5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/HITs/Modulo.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/HITs/Modulo.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/HITs/Modulo.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 43,
"size": 162
} |
{-# OPTIONS --without-K --safe #-}
module Categories.Utils.EqReasoning where
open import Level
open import Relation.Binary.PropositionalEquality
open import Data.Product using (Σ; _,_; _×_)
open import Categories.Utils.Product
subst₂-sym-subst₂ : {ℓa ℓb ℓp : Level} {A : Set ℓa} {B : Set ℓb} {a₁ a₂ : A} {b₁ b₂ : B}
(R : A → B → Set ℓp) {p : R a₁ b₁} (eq₁ : a₁ ≡ a₂) (eq₂ : b₁ ≡ b₂) →
subst₂ R (sym eq₁) (sym eq₂) (subst₂ R eq₁ eq₂ p) ≡ p
subst₂-sym-subst₂ R refl refl = refl
subst₂-subst₂-sym : {ℓa ℓb ℓp : Level} {A : Set ℓa} {B : Set ℓb} {a₁ a₂ : A} {b₁ b₂ : B}
(R : A → B → Set ℓp) {p : R a₁ b₁} (eq₁ : a₂ ≡ a₁) (eq₂ : b₂ ≡ b₁) →
subst₂ R eq₁ eq₂ (subst₂ R (sym eq₁) (sym eq₂) p) ≡ p
subst₂-subst₂-sym R refl refl = refl
subst₂-subst₂ : {ℓa ℓb ℓp : Level} {A : Set ℓa} {B : Set ℓb} {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B}
(R : A → B → Set ℓp) {p : R a₁ b₁}
(eq-a₁₂ : a₁ ≡ a₂) (eq-a₂₃ : a₂ ≡ a₃)
(eq-b₁₂ : b₁ ≡ b₂) (eq-b₂₃ : b₂ ≡ b₃) →
subst₂ R eq-a₂₃ eq-b₂₃ (subst₂ R eq-a₁₂ eq-b₁₂ p) ≡ subst₂ R (trans eq-a₁₂ eq-a₂₃) (trans eq-b₁₂ eq-b₂₃) p
subst₂-subst₂ R refl refl refl refl = refl
subst₂-app : ∀ {a₁ a₂ a₃ a₄ b₁ b₂} {A₁ : Set a₁} {A₂ : Set a₂} {A₃ : Set a₃} {A₄ : Set a₄}
(B₁ : A₁ → A₃ → Set b₁) {B₂ : A₂ → A₄ → Set b₂}
{f : A₂ → A₁} {h : A₄ → A₃} {x₁ x₂ : A₂} {x₃ x₄ : A₄} (y : B₂ x₁ x₃)
(g : ∀ w z → B₂ w z → B₁ (f w) (h z)) (eq₁ : x₁ ≡ x₂) (eq₂ : x₃ ≡ x₄) →
subst₂ B₁ (cong f eq₁) (cong h eq₂) (g x₁ x₃ y) ≡ g x₂ x₄ (subst₂ B₂ eq₁ eq₂ y)
subst₂-app _ _ _ refl refl = refl
subst₂-prod : ∀ {ℓa ℓb ℓr ℓs} {A : Set ℓa} {B : Set ℓb}
(R : A → A → Set ℓr) (S : B → B → Set ℓs) {a b c d : A} {x y z w : B}
{f : R a b} {g : S x y}
(eq₁ : a ≡ c) (eq₂ : b ≡ d) (eq₃ : x ≡ z) (eq₄ : y ≡ w) →
subst₂ (λ { (p , q) (r , s) → R p r × S q s })
(sym (cong₂ _,_ (sym eq₁) (sym eq₃)))
(sym (cong₂ _,_ (sym eq₂) (sym eq₄)))
(f , g)
≡
(subst₂ R eq₁ eq₂ f , subst₂ S eq₃ eq₄ g)
subst₂-prod R S refl refl refl refl = refl
------------------
-- For reasoning with things from Categories.Utils.Product
subst₂-expand : ∀ {a b ℓ ℓ′ p q} {A : Set a} {B : Set b}
{P : A → Set p} {Q : B → Set q}
(_∙_ : A → B → Set ℓ) → (_∘_ : ∀ {x y} → P x → Q y → Set ℓ′) →
{a₁ a₂ : A} {b₁ b₂ : B} {p₁ p₂ : P a₁} {q₁ q₂ : Q b₁}
(eq₁ : a₁ ≡ a₂) (eq₂ : p₁ ≡ p₂) (eq₃ : b₁ ≡ b₂) (eq₄ : q₁ ≡ q₂) →
(F : a₁ ∙ b₁) → (G : p₁ ∘ q₁) →
subst₂ (_∙_ -< _×_ >- _∘_)
(cong₂ _,_ eq₁ eq₂)
(cong₂ _,_ eq₃ eq₄)
(F , G) ≡ (subst₂ _∙_ eq₁ eq₃ F , subst₂ _∘_ eq₂ eq₄ G)
subst₂-expand T₁ T₂ refl refl refl refl F G = refl
| {
"alphanum_fraction": 0.4883889695,
"avg_line_length": 45.9333333333,
"ext": "agda",
"hexsha": "d8559d18c0b471a2f5b460090432c995db927f33",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Utils/EqReasoning.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Utils/EqReasoning.agda",
"max_line_length": 120,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Utils/EqReasoning.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 1334,
"size": 2756
} |
module BuildingBlock.BinaryLeafTree where
open import Function
open import Data.Nat
open import Data.Nat.Etc
open import Data.Nat.Properties.Simple using (+-right-identity)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Data.Fin
using (Fin; toℕ; fromℕ; fromℕ≤; reduce≥)
renaming (zero to Fzero; suc to Fsuc)
open import Data.Empty
open import Relation.Nullary using (Dec; yes; no; ¬_)
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; _≢_; refl; cong; trans; sym; inspect)
open PropEq.≡-Reasoning
--------------------------------------------------------------------------------
-- Complete Binary Leaf Trees
data BinaryLeafTree (A : Set) : ℕ → Set where
Leaf : A → BinaryLeafTree A 0
Node : ∀ {n} → BinaryLeafTree A n
→ BinaryLeafTree A n
→ BinaryLeafTree A (suc n)
-- splits a BinaryLeafTree into 2
split : ∀ {A n} → BinaryLeafTree A (suc n)
→ BinaryLeafTree A n × BinaryLeafTree A n
split (Node xs ys) = xs , ys
-- merge 2 BinaryLeafTree
merge : ∀ {A n} → BinaryLeafTree A n
→ BinaryLeafTree A n
→ BinaryLeafTree A (suc n)
merge = Node
split-merge : ∀ {n A} → (xs : BinaryLeafTree A (suc n))
→ merge (proj₁ (split xs)) (proj₂ (split xs)) ≡ xs
split-merge (Node xs ys) = refl
-- get the first element
head : ∀ {A n} → BinaryLeafTree A n → A
head (Leaf x) = x
head (Node xs ys) = head xs
-- searching
transportFin : ∀ {a b} → a ≡ b → Fin a → Fin b
transportFin refl i = i
¬a≤b⇒b<a : ∀ {a b} → ¬ (a ≤ b) → b < a
¬a≤b⇒b<a {zero } {b } p = ⊥-elim (p z≤n)
¬a≤b⇒b<a {suc a} {zero } p = s≤s z≤n
¬a≤b⇒b<a {suc a} {suc b} p = s≤s (¬a≤b⇒b<a (λ z → p (s≤s z)))
elemAt : ∀ {A n} → BinaryLeafTree A n → Fin (2 ^ n) → A
elemAt {n = zero} (Leaf x) Fzero = x
elemAt {n = zero} (Leaf x) (Fsuc ())
elemAt {n = suc n} (Node xs ys) i with (2 ^ n) ≤? toℕ i
elemAt {n = suc n} (Node xs ys) i | yes p = elemAt ys (transportFin (+-right-identity (2 ^ n)) (reduce≥ {2 ^ n} {2 ^ n + 0} i p))
elemAt {n = suc n} (Node xs ys) i | no ¬p = elemAt xs (fromℕ≤ (¬a≤b⇒b<a ¬p))
-- examples
private
fier : BinaryLeafTree ℕ 2
fier = Node
(Node
(Leaf 0)
(Leaf 2))
(Node
(Leaf 3)
(Leaf 1))
| {
"alphanum_fraction": 0.5566037736,
"avg_line_length": 31.0933333333,
"ext": "agda",
"hexsha": "97adaef17dfc08d6e3ec9e624fc5dce694c960f1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-05-30T05:50:50.000Z",
"max_forks_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/numeral",
"max_forks_repo_path": "legacy/BuildingBlock/BinaryLeafTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/numeral",
"max_issues_repo_path": "legacy/BuildingBlock/BinaryLeafTree.agda",
"max_line_length": 129,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aae093cc9bf21f11064e7f7b12049448cd6449f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/numeral",
"max_stars_repo_path": "legacy/BuildingBlock/BinaryLeafTree.agda",
"max_stars_repo_stars_event_max_datetime": "2015-04-23T15:58:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-23T15:58:28.000Z",
"num_tokens": 819,
"size": 2332
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
{-
This module develops Lehmer codes, i.e. an encoding of permutations as finite integers.
-}
module Cubical.Data.Fin.LehmerCode where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Equiv.Properties
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Transport
open import Cubical.Functions.Embedding
open import Cubical.Functions.Surjection
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.DecidableEq
open import Cubical.Data.Unit as ⊤
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Nat
open import Cubical.Data.Nat.Order
open import Cubical.Data.Fin.Base as F
open import Cubical.Data.Fin.Properties
renaming (punchOut to punchOutPrim)
open import Cubical.Data.Sigma
open import Cubical.Data.Sum as Sum using (_⊎_; inl; inr)
private
variable
n : ℕ
FinExcept : (i : Fin n) → Type₀
FinExcept i = Σ[ j ∈ Fin _ ] ¬ (i ≡ j)
isSetFinExcept : {i : Fin n} → isSet (FinExcept i)
isSetFinExcept = isOfHLevelΣ 2 isSetFin (λ _ → isProp→isSet (isPropΠ (λ _ → ⊥.isProp⊥)))
fsucExc : {i : Fin n} → FinExcept i → FinExcept (fsuc i)
fsucExc {i = i} j = fsuc (fst j) , snd j ∘ fsuc-inj
toFinExc : {i : Fin n} → FinExcept i → Fin n
toFinExc = fst
toFinExc-injective : {i : Fin n} → {j k : FinExcept i} → toFinExc j ≡ toFinExc k → j ≡ k
toFinExc-injective = Σ≡Prop (λ _ → isPropΠ λ _ → ⊥.isProp⊥)
toℕExc : {i : Fin n} → FinExcept i → ℕ
toℕExc = toℕ ∘ toFinExc
toℕExc-injective : {i : Fin n} → {j k : FinExcept i} → toℕExc j ≡ toℕExc k → j ≡ k
toℕExc-injective = toFinExc-injective ∘ toℕ-injective
projectionEquiv : {i : Fin n} → (Unit ⊎ FinExcept i) ≃ Fin n
projectionEquiv {n = n} {i = i} = isoToEquiv goal where
goal : Iso (Unit ⊎ FinExcept i) (Fin n)
goal .Iso.fun (inl _) = i
goal .Iso.fun (inr m) = fst m
goal .Iso.inv m = case discreteFin i m of λ { (yes _) → inl tt ; (no n) → inr (m , n) }
goal .Iso.rightInv m with discreteFin i m
... | (yes p) = p
... | (no _) = toℕ-injective refl
goal .Iso.leftInv (inl tt) with discreteFin i i
... | (yes _) = refl
... | (no ¬ii) = ⊥.rec (¬ii refl)
goal .Iso.leftInv (inr m) with discreteFin i (fst m)
... | (yes p) = ⊥.rec (snd m p)
... | (no _) = cong inr (toℕExc-injective refl)
punchOut : (i : Fin (suc n)) → FinExcept i → Fin n
punchOut i ¬i = punchOutPrim (snd ¬i)
punchOut-injective : (i : Fin (suc n)) → ∀ j k → punchOut i j ≡ punchOut i k → j ≡ k
punchOut-injective i j k = toFinExc-injective ∘ punchOut-inj (snd j) (snd k)
punchIn : (i : Fin (suc n)) → Fin n → FinExcept i
punchIn {_} i j with fsplit i
... | inl iz = fsuc j , fznotfs ∘ (iz ∙_)
punchIn {n} i j | inr (i′ , is) with n
... | zero = ⊥.rec (¬Fin0 j)
... | suc n′ with fsplit j
... | inl jz = fzero , fznotfs ∘ sym ∘ (is ∙_)
... | inr (j′ , _) =
let (k , ¬k≡i′) = punchIn i′ j′
in fsuc k , ¬k≡i′ ∘ fsuc-inj ∘ (is ∙_)
punchOut∘In :(i : Fin (suc n)) → ∀ j → punchOut i (punchIn i j) ≡ j
punchOut∘In {_} i j with fsplit i
... | inl iz = toℕ-injective refl
punchOut∘In {n} i j | inr (i′ , _) with n
... | zero = ⊥.rec (¬Fin0 j)
... | suc n′ with fsplit j
... | inl jz = toℕ-injective (cong toℕ jz)
... | inr (j′ , prfj) =
-- the following uses a definitional equality of punchIn but I don't see
-- how to sidestep this while using with-abstractions
fsuc (punchOut i′ _) ≡⟨ cong (λ j → fsuc (punchOut i′ j)) (toℕExc-injective refl) ⟩
fsuc (punchOut i′ (punchIn i′ j′)) ≡⟨ cong fsuc (punchOut∘In i′ j′) ⟩
fsuc j′ ≡⟨ toℕ-injective (cong toℕ prfj) ⟩
j ∎
isEquivPunchOut : {i : Fin (suc n)} → isEquiv (punchOut i)
isEquivPunchOut {i = i} = isEmbedding×isSurjection→isEquiv (isEmbPunchOut , isSurPunchOut) where
isEmbPunchOut : isEmbedding (punchOut i)
isEmbPunchOut = injEmbedding isSetFinExcept isSetFin λ {_} {_} → punchOut-injective i _ _
isSurPunchOut : isSurjection (punchOut i)
isSurPunchOut b = ∣ _ , punchOut∘In i b ∣
punchOutEquiv : {i : Fin (suc n)} → FinExcept i ≃ Fin n
punchOutEquiv = _ , isEquivPunchOut
infixr 4 _∷_
data LehmerCode : (n : ℕ) → Type₀ where
[] : LehmerCode zero
_∷_ : ∀ {n} → Fin (suc n) → LehmerCode n → LehmerCode (suc n)
isContrLehmerZero : isContr (LehmerCode 0)
isContrLehmerZero = [] , λ { [] → refl }
lehmerSucEquiv : Fin (suc n) × LehmerCode n ≃ LehmerCode (suc n)
lehmerSucEquiv = isoToEquiv (iso (λ (e , c) → e ∷ c)
(λ { (e ∷ c) → (e , c) })
(λ { (e ∷ c) → refl })
(λ (e , c) → refl))
lehmerEquiv : (Fin n ≃ Fin n) ≃ LehmerCode n
lehmerEquiv {zero} = isContr→Equiv contrFF isContrLehmerZero where
contrFF : isContr (Fin zero ≃ Fin zero)
contrFF = idEquiv _ , λ y → equivEq (funExt λ f → ⊥.rec (¬Fin0 f))
lehmerEquiv {suc n} =
(Fin (suc n) ≃ Fin (suc n)) ≃⟨ isoToEquiv i ⟩
(Σ[ k ∈ Fin (suc n) ] (FinExcept fzero ≃ FinExcept k)) ≃⟨ Σ-cong-equiv-snd ii ⟩
(Fin (suc n) × (Fin n ≃ Fin n)) ≃⟨ Σ-cong-equiv-snd (λ _ → lehmerEquiv) ⟩
(Fin (suc n) × LehmerCode n) ≃⟨ lehmerSucEquiv ⟩
LehmerCode (suc n) ■ where
equivIn : (f : Fin (suc n) ≃ Fin (suc n))
→ FinExcept fzero ≃ FinExcept (equivFun f fzero)
equivIn f =
FinExcept fzero
≃⟨ Σ-cong-equiv-snd (λ _ → preCompEquiv (invEquiv (congEquiv f))) ⟩
(Σ[ x ∈ Fin (suc n) ] ¬ ffun fzero ≡ ffun x)
≃⟨ Σ-cong-equiv-fst f ⟩
FinExcept (ffun fzero)
■ where ffun = equivFun f
-- equivInChar : ∀ {f} x → fst (equivFun (equivIn f) x) ≡ equivFun f (fst x)
-- equivInChar x = refl
equivOut : ∀ {k} → FinExcept (fzero {k = n}) ≃ FinExcept k
→ Fin (suc n) ≃ Fin (suc n)
equivOut {k = k} f =
Fin (suc n)
≃⟨ invEquiv projectionEquiv ⟩
Unit ⊎ FinExcept fzero
≃⟨ isoToEquiv (Sum.⊎Iso idIso (equivToIso f)) ⟩
Unit ⊎ FinExcept k
≃⟨ projectionEquiv ⟩
Fin (suc n)
■
equivOutChar : ∀ {k} {f} (x : FinExcept fzero) → equivFun (equivOut {k = k} f) (fst x) ≡ fst (equivFun f x)
equivOutChar {f = f} x with discreteFin fzero (fst x)
... | (yes y) = ⊥.rec (x .snd y)
... | (no n) = cong (λ x′ → fst (equivFun f x′)) (toℕExc-injective refl)
i : Iso (Fin (suc n) ≃ Fin (suc n))
(Σ[ k ∈ Fin (suc n) ] (FinExcept (fzero {k = n}) ≃ FinExcept k))
Iso.fun i f = equivFun f fzero , equivIn f
Iso.inv i (k , f) = equivOut f
Iso.rightInv i (k , f) = ΣPathP (refl , equivEq (funExt λ x →
toℕExc-injective (cong toℕ (equivOutChar {f = f} x))))
Iso.leftInv i f = equivEq (funExt goal) where
goal : ∀ x → equivFun (equivOut (equivIn f)) x ≡ equivFun f x
goal x = case fsplit x return (λ _ → equivFun (equivOut (equivIn f)) x ≡ equivFun f x) of λ
{ (inl xz) → subst (λ x → equivFun (equivOut (equivIn f)) x ≡ equivFun f x) xz refl
; (inr (_ , xn)) → equivOutChar {f = equivIn f} (x , fznotfs ∘ (_∙ sym xn))
}
ii : ∀ k → (FinExcept fzero ≃ FinExcept k) ≃ (Fin n ≃ Fin n)
ii k = (FinExcept fzero ≃ FinExcept k) ≃⟨ cong≃ (λ R → FinExcept fzero ≃ R) punchOutEquiv ⟩
(FinExcept fzero ≃ Fin n) ≃⟨ cong≃ (λ L → L ≃ Fin n) punchOutEquiv ⟩
(Fin n ≃ Fin n) ■
encode : (Fin n ≃ Fin n) → LehmerCode n
encode = equivFun lehmerEquiv
decode : LehmerCode n → Fin n ≃ Fin n
decode = invEq lehmerEquiv
factorial : ℕ → ℕ
factorial zero = 1
factorial (suc n) = suc n · factorial n
lehmerFinEquiv : LehmerCode n ≃ Fin (factorial n)
lehmerFinEquiv {zero} = isContr→Equiv isContrLehmerZero isContrFin1
lehmerFinEquiv {suc n} = _ ≃⟨ invEquiv lehmerSucEquiv ⟩
_ ≃⟨ ≃-× (idEquiv _) lehmerFinEquiv ⟩
_ ≃⟨ factorEquiv ⟩
_ ■
private
-- this example is copied from wikipedia, using the permutation of the letters A-G
-- B,F,A,G,D,E,C
-- given by the corresponding Lehmer code of
-- 1 4 0 3 1 1 0
exampleCode : LehmerCode 7
exampleCode = (1 , (5 , refl)) ∷ (4 , (1 , refl)) ∷ (0 , (4 , refl)) ∷ (3 , (0 , refl)) ∷ (1 , (1 , refl)) ∷ (1 , (0 , refl)) ∷ (0 , (0 , refl)) ∷ []
example : Fin 7 ≃ Fin 7
example = decode exampleCode
-- C should decode to G
computation : fst (equivFun example (3 , (3 , refl))) ≡ 6
computation = refl
_ : toℕ (equivFun lehmerFinEquiv exampleCode) ≡ 4019
_ = refl
| {
"alphanum_fraction": 0.5695570112,
"avg_line_length": 40.3901345291,
"ext": "agda",
"hexsha": "7c279d3698c9b94bcfd79692477f31e14c97b3ca",
"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": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Data/Fin/LehmerCode.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"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": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Data/Fin/LehmerCode.agda",
"max_line_length": 151,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Data/Fin/LehmerCode.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3293,
"size": 9007
} |
{-# OPTIONS --without-K --safe #-}
-- A Logical Relation for Dependent Type Theory Formalized in Agda
module Logrel-MLTT where
-- README
import README
-- Minimal library
import Tools.Empty
import Tools.Unit
import Tools.Nat
import Tools.Sum
import Tools.Product
import Tools.Function
import Tools.Nullary
import Tools.List
import Tools.PropositionalEquality
import Tools.Fin
-- Grammar of the language
import Definition.Untyped
import Definition.Untyped.Properties
-- Typing and conversion rules of language
import Definition.Typed
import Definition.Typed.Properties
import Definition.Typed.Weakening
import Definition.Typed.Reduction
import Definition.Typed.RedSteps
import Definition.Typed.EqualityRelation
import Definition.Typed.EqRelInstance
-- Logical relation
import Definition.LogicalRelation
import Definition.LogicalRelation.ShapeView
import Definition.LogicalRelation.Irrelevance
import Definition.LogicalRelation.Weakening
import Definition.LogicalRelation.Properties
import Definition.LogicalRelation.Application
import Definition.LogicalRelation.Substitution
import Definition.LogicalRelation.Substitution.Properties
import Definition.LogicalRelation.Substitution.Irrelevance
import Definition.LogicalRelation.Substitution.Conversion
import Definition.LogicalRelation.Substitution.Reduction
import Definition.LogicalRelation.Substitution.Reflexivity
import Definition.LogicalRelation.Substitution.Weakening
import Definition.LogicalRelation.Substitution.Reducibility
import Definition.LogicalRelation.Substitution.Escape
import Definition.LogicalRelation.Substitution.MaybeEmbed
import Definition.LogicalRelation.Substitution.Introductions
import Definition.LogicalRelation.Fundamental
import Definition.LogicalRelation.Fundamental.Reducibility
-- Consequences of the logical relation for typing and conversion
import Definition.Typed.Consequences.Canonicity
import Definition.Typed.Consequences.Injectivity
import Definition.Typed.Consequences.Syntactic
import Definition.Typed.Consequences.Inversion
import Definition.Typed.Consequences.Inequality
import Definition.Typed.Consequences.Substitution
import Definition.Typed.Consequences.Equality
import Definition.Typed.Consequences.InverseUniv
import Definition.Typed.Consequences.Reduction
import Definition.Typed.Consequences.NeTypeEq
import Definition.Typed.Consequences.SucCong
import Definition.Typed.Consequences.Consistency
-- Algorithmic equality with lemmas that depend on typing consequences
import Definition.Conversion
import Definition.Conversion.Conversion
import Definition.Conversion.Lift
import Definition.Conversion.Reduction
import Definition.Conversion.Soundness
import Definition.Conversion.Stability
import Definition.Conversion.Symmetry
import Definition.Conversion.Transitivity
import Definition.Conversion.Universe
import Definition.Conversion.Weakening
import Definition.Conversion.Whnf
import Definition.Conversion.Decidable
import Definition.Conversion.EqRelInstance
import Definition.Conversion.FullReduction
-- Consequences of the logical relation for algorithmic equality
import Definition.Conversion.Consequences.Completeness
-- Decidability of conversion
import Definition.Typed.Decidable
| {
"alphanum_fraction": 0.8771875,
"avg_line_length": 34.4086021505,
"ext": "agda",
"hexsha": "88a1214d9f411dd79de9e02c50036e27454209ee",
"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": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "fhlkfy/logrel-mltt",
"max_forks_repo_path": "Logrel-MLTT.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"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": "fhlkfy/logrel-mltt",
"max_issues_repo_path": "Logrel-MLTT.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ea83fc4f618d1527d64ecac82d7d17e2f18ac391",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "fhlkfy/logrel-mltt",
"max_stars_repo_path": "Logrel-MLTT.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 603,
"size": 3200
} |
module Prelude.Int.Core where
open import Prelude.Unit
open import Prelude.Empty
open import Prelude.Nat
open import Prelude.Number
open import Prelude.Semiring
open import Prelude.Ord
open import Agda.Builtin.Int public
neg : Nat → Int
neg zero = pos zero
neg (suc n) = negsuc n
{-# INLINE neg #-}
-- Integers are numbers --
instance
NumInt : Number Int
Number.Constraint NumInt _ = ⊤
Number.fromNat NumInt n = pos n
NegInt : Negative Int
Negative.Constraint NegInt _ = ⊤
Negative.fromNeg NegInt n = neg n
-- Arithmetic --
_-NZ_ : Nat → Nat → Int
a -NZ b with compare a b
... | less (diff k _) = negsuc k
... | equal _ = pos (a - b) -- a - b instead of 0 makes it compile to Integer minus
... | greater (diff k _) = pos (suc k)
{-# INLINE _-NZ_ #-}
_+Z_ : Int → Int → Int
pos a +Z pos b = pos (a + b)
pos a +Z negsuc b = a -NZ suc b
negsuc a +Z pos b = b -NZ suc a
negsuc a +Z negsuc b = negsuc (suc a + b)
{-# INLINE _+Z_ #-}
{-# DISPLAY _+Z_ a b = a + b #-}
negateInt : Int → Int
negateInt (pos n) = neg n
negateInt (negsuc n) = pos (suc n)
{-# INLINE negateInt #-}
{-# DISPLAY negateInt a = negate a #-}
_-Z_ : Int → Int → Int
a -Z b = a +Z negateInt b
{-# INLINE _-Z_ #-}
abs : Int → Nat
abs (pos n) = n
abs (negsuc n) = suc n
_*Z_ : Int → Int → Int
pos a *Z pos b = pos (a * b)
pos a *Z negsuc b = neg (a * suc b)
negsuc a *Z pos b = neg (suc a * b)
negsuc a *Z negsuc b = pos (suc a * suc b)
{-# INLINE _*Z_ #-}
{-# DISPLAY _*Z_ a b = a * b #-}
instance
SemiringInt : Semiring Int
Semiring.zro SemiringInt = 0
Semiring.one SemiringInt = 1
Semiring._+_ SemiringInt = _+Z_
Semiring._*_ SemiringInt = _*Z_
SubInt : Subtractive Int
Subtractive._-_ SubInt = _-Z_
Subtractive.negate SubInt = negateInt
NonZeroInt : Int → Set
NonZeroInt (pos zero) = ⊥
NonZeroInt _ = ⊤
infixl 7 quotInt-by remInt-by
syntax quotInt-by b a = a quot b
quotInt-by : (b : Int) {{_ : NonZeroInt b}} → Int → Int
quotInt-by (pos zero) {{}} _
quotInt-by (pos (suc n)) (pos m) = pos (m div suc n)
quotInt-by (pos (suc n)) (negsuc m) = neg (suc m div suc n)
quotInt-by (negsuc n) (pos m) = neg (m div suc n)
quotInt-by (negsuc n) (negsuc m) = pos (suc m div suc n)
{-# INLINE quotInt-by #-}
syntax remInt-by b a = a rem b
remInt-by : (b : Int) {{_ : NonZeroInt b}} → Int → Int
remInt-by (pos zero) {{}} _
remInt-by (pos (suc n)) (pos m) = pos ( m mod suc n)
remInt-by (pos (suc n)) (negsuc m) = neg (suc m mod suc n)
remInt-by (negsuc n) (pos m) = pos ( m mod suc n)
remInt-by (negsuc n) (negsuc m) = neg (suc m mod suc n)
{-# INLINE remInt-by #-}
| {
"alphanum_fraction": 0.6086629002,
"avg_line_length": 25.2857142857,
"ext": "agda",
"hexsha": "3e27451ccb3d22bd82f34adbfc305313c75e6241",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "L-TChen/agda-prelude",
"max_forks_repo_path": "src/Prelude/Int/Core.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "L-TChen/agda-prelude",
"max_issues_repo_path": "src/Prelude/Int/Core.agda",
"max_line_length": 95,
"max_stars_count": 111,
"max_stars_repo_head_hexsha": "158d299b1b365e186f00d8ef5b8c6844235ee267",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "L-TChen/agda-prelude",
"max_stars_repo_path": "src/Prelude/Int/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 960,
"size": 2655
} |
open import Oscar.Prelude
module Oscar.Data.Maybe where
data Maybe {a} (A : Ø a) : Ø a where
∅ : Maybe A
↑_ : A → Maybe A
-- A dependent eliminator.
maybe : ∀ {a b} {A : Set a} {B : Maybe A → Set b} →
((x : A) → B (↑ x)) → B ∅ → (x : Maybe A) → B x
maybe j n (↑ x) = j x
maybe j n ∅ = n
-- A non-dependent eliminator.
maybe′ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → B → Maybe A → B
maybe′ = maybe
| {
"alphanum_fraction": 0.5118483412,
"avg_line_length": 20.0952380952,
"ext": "agda",
"hexsha": "4eba1482f1aa41cadd6eb09aa93952b7dc6463db",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Data/Maybe.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Data/Maybe.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Data/Maybe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 168,
"size": 422
} |
{- 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
-}
module Dijkstra.EitherD where
open import Agda.Builtin.Equality using (_≡_; refl)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Haskell.Prelude
data EitherD (E : Set) : Set → Set₁ where
-- Primitive combinators
EitherD-return : ∀ {A} → A → EitherD E A
EitherD-bind : ∀ {A B} → EitherD E A → (A → EitherD E B) → EitherD E B
EitherD-bail : ∀ {A} → E → EitherD E A
-- Branching conditionals (used for creating more convenient contracts)
EitherD-if : ∀ {A} → Guards (EitherD E A) → EitherD E A
EitherD-either : ∀ {A B C}
→ (B → EitherD E A) → (C → EitherD E A) → Either B C → EitherD E A
EitherD-maybe : ∀ {A B} → EitherD E B → (A → EitherD E B) → Maybe A → EitherD E B
pattern LeftD x = EitherD-bail x
pattern RightD x = EitherD-return x
private
variable
E : Set
A B C : Set
EitherD-run : EitherD E A → Either E A
EitherD-run (EitherD-return x) = Right x
EitherD-run (EitherD-bind m f)
with EitherD-run m
... | Left x = Left x
... | Right y = EitherD-run (f y)
EitherD-run (EitherD-bail x) = Left x
EitherD-run (EitherD-if (clause (b ≔ c) gs)) =
if toBool b then EitherD-run c else EitherD-run (EitherD-if gs)
EitherD-run (EitherD-if (otherwise≔ c)) =
EitherD-run c
EitherD-run (EitherD-either f₁ f₂ (Left x)) = EitherD-run (f₁ x)
EitherD-run (EitherD-either f₁ f₂ (Right y)) = EitherD-run (f₂ y)
EitherD-run (EitherD-maybe n s nothing ) = EitherD-run n
EitherD-run (EitherD-maybe n s (just x)) = EitherD-run (s x)
EitherD-Pre : (E A : Set) → Set₁
EitherD-Pre E A = Set
EitherD-Post : (E A : Set) → Set₁
EitherD-Post E A = Either E A → Set
EitherD-Post-⇒ : ∀ {E} {A} → (P Q : EitherD-Post E A) → Set
EitherD-Post-⇒ P Q = ∀ r → P r → Q r
EitherD-PredTrans : (E A : Set) → Set₁
EitherD-PredTrans E A = EitherD-Post E A → EitherD-Pre E A
EitherD-weakestPre-bindPost : (f : A → EitherD E B) → EitherD-Post E B → EitherD-Post E A
EitherD-weakestPre : (m : EitherD E A) → EitherD-PredTrans E A
EitherD-weakestPre (EitherD-return x) P = P (Right x)
EitherD-weakestPre (EitherD-bind m f) P =
EitherD-weakestPre m (EitherD-weakestPre-bindPost f P)
EitherD-weakestPre (EitherD-bail x) P = P (Left x)
EitherD-weakestPre (EitherD-if (clause (b ≔ c) gs)) P =
(toBool b ≡ true → EitherD-weakestPre c P)
× (toBool b ≡ false → EitherD-weakestPre (EitherD-if gs) P)
EitherD-weakestPre (EitherD-if (otherwise≔ x)) P =
EitherD-weakestPre x P
EitherD-weakestPre (EitherD-either f₁ f₂ e) P =
(∀ x → e ≡ Left x → EitherD-weakestPre (f₁ x) P)
× (∀ y → e ≡ Right y → EitherD-weakestPre (f₂ y) P)
EitherD-weakestPre (EitherD-maybe n s m) P =
(m ≡ nothing → EitherD-weakestPre n P)
× (∀ j → m ≡ just j → EitherD-weakestPre (s j) P)
EitherD-weakestPre-bindPost f P (Left x) =
P (Left x)
EitherD-weakestPre-bindPost f P (Right y) =
∀ c → c ≡ y → EitherD-weakestPre (f c) P
EitherD-Contract : (m : EitherD E A) → Set₁
EitherD-Contract{E}{A} m =
(P : EitherD-Post E A)
→ EitherD-weakestPre m P → P (EitherD-run m)
EitherD-contract : (m : EitherD E A) → EitherD-Contract m
EitherD-contract (EitherD-return x) P wp = wp
EitherD-contract (EitherD-bind m f) P wp
with EitherD-contract m _ wp
...| wp'
with EitherD-run m
... | Left x = wp'
... | Right y = EitherD-contract (f y) P (wp' y refl)
EitherD-contract (EitherD-bail x) P wp = wp
EitherD-contract{E}{A} (EitherD-if gs) P wp =
EitherD-contract-if gs P wp
where
EitherD-contract-if : (gs : Guards (EitherD E A)) → EitherD-Contract (EitherD-if gs)
EitherD-contract-if (clause (b ≔ c) gs) P wp
with toBool b
... | false = EitherD-contract-if gs P (proj₂ wp refl)
... | true = EitherD-contract c P (proj₁ wp refl)
EitherD-contract-if (otherwise≔ x) P wp = EitherD-contract x P wp
EitherD-contract (EitherD-either f₁ f₂ (Left x)) P wp =
EitherD-contract (f₁ x) P (proj₁ wp x refl)
EitherD-contract (EitherD-either f₁ f₂ (Right y)) P wp =
EitherD-contract (f₂ y) P (proj₂ wp y refl)
EitherD-contract (EitherD-maybe f₁ f₂ nothing) P wp =
EitherD-contract f₁ P (proj₁ wp refl)
EitherD-contract (EitherD-maybe f₁ f₂ (just x)) P wp =
EitherD-contract (f₂ x) P (proj₂ wp x refl)
EitherD-⇒
: ∀ {E A} {P Q : EitherD-Post E A}
→ ∀ m → EitherD-weakestPre m P
→ (EitherD-Post-⇒ P Q)
→ EitherD-weakestPre m Q
EitherD-⇒ {P = Post₁} {Post₂} (LeftD x ) pre pf = pf (Left x ) pre
EitherD-⇒ {P = Post₁} {Post₂} (RightD x) pre pf = pf (Right x) pre
EitherD-⇒ {P = Post₁} {Post₂} (EitherD-bind m x) pre pf =
EitherD-⇒ m pre P⇒Q
where
P⇒Q : EitherD-Post-⇒ (EitherD-weakestPre-bindPost x Post₁)
(EitherD-weakestPre-bindPost x Post₂)
P⇒Q (Left rL) Pr = pf (Left rL) Pr
P⇒Q (Right rR) Pr .rR refl = EitherD-⇒ (x rR) (Pr rR refl) pf
EitherD-⇒ {Post₁} {Post₂} (EitherD-if (otherwise≔ x)) pre pf = EitherD-⇒ x pre pf
EitherD-⇒ {Post₁} {Post₂} (EitherD-if (clause (x ≔ x₂) x₁)) (pre₁ , pre₂) pf =
(λ x≡true → EitherD-⇒ x₂ (pre₁ x≡true) pf)
, (λ x≡false → EitherD-⇒ (EitherD-if x₁) (pre₂ x≡false) pf)
proj₁ (EitherD-⇒ {Post₁} {Post₂} (EitherD-either x₁ x₂ (Left x)) (pre₁ , pre₂) pf) .x refl =
EitherD-⇒ (x₁ x) (pre₁ x refl) pf
proj₂ (EitherD-⇒ {Post₁} {Post₂} (EitherD-either x₁ x₂ (Right x)) (pre₁ , pre₂) pf) .x refl =
EitherD-⇒ (x₂ x) (pre₂ x refl) pf
proj₁ (EitherD-⇒ {Post₁} {Post₂} (EitherD-maybe m x₁ .nothing) (pre₁ , pre₂) pf) refl =
EitherD-⇒ m (pre₁ refl) pf
proj₂ (EitherD-⇒ {Post₁} {Post₂} (EitherD-maybe m x₁ (just x)) (pre₁ , pre₂) pf) j refl =
EitherD-⇒ (x₁ j) (pre₂ j refl) pf
EitherD-⇒-bind :
∀ {E} {A} {P : EitherD-Post E A}
→ {Q : EitherD-Post E B}
→ {f : A → EitherD E B}
→ ∀ m → EitherD-weakestPre m P
→ EitherD-Post-⇒ P (EitherD-weakestPre-bindPost f Q)
→ EitherD-weakestPre (EitherD-bind m f) Q
EitherD-⇒-bind = EitherD-⇒
EitherD-vacuous : ∀ (m : EitherD E A) → EitherD-weakestPre m (const Unit)
EitherD-vacuous (LeftD x) = unit
EitherD-vacuous (RightD x) = unit
EitherD-vacuous (EitherD-if (otherwise≔ x)) = EitherD-vacuous x
EitherD-vacuous (EitherD-if (clause (b ≔ x) x₁)) = (const (EitherD-vacuous x)) , (const (EitherD-vacuous (EitherD-if x₁)))
EitherD-vacuous (EitherD-either x₁ x₂ x) = (λ x₃ _ → EitherD-vacuous (x₁ x₃)) , (λ y _ → EitherD-vacuous (x₂ y))
EitherD-vacuous (EitherD-maybe m x₁ x) = (const (EitherD-vacuous m)) , λ j _ → EitherD-vacuous (x₁ j)
EitherD-vacuous (EitherD-bind m x) = EitherD-⇒-bind m (EitherD-vacuous m) λ { (Left _) _ → unit
; (Right _) _ → λ c _ → EitherD-vacuous (x c) }
| {
"alphanum_fraction": 0.6301527818,
"avg_line_length": 42.8271604938,
"ext": "agda",
"hexsha": "e06585cf976ccffd4c9354519ec09738d0ca04a6",
"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/Dijkstra/EitherD.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/Dijkstra/EitherD.agda",
"max_line_length": 137,
"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/Dijkstra/EitherD.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2611,
"size": 6938
} |
module Structure.Category.NaturalTransformation where
open import Functional using () renaming (id to idᶠⁿ)
open import Functional.Dependent using () renaming (_∘_ to _∘ᶠⁿ_)
import Lvl
open import Logic
open import Logic.Predicate
open import Structure.Category
open import Structure.Category.Functor
open import Structure.Category.Proofs
open import Structure.Categorical.Properties
open import Structure.Setoid
open import Syntax.Function
open import Type
open Category.ArrowNotation ⦃ … ⦄
open Category ⦃ … ⦄ hiding (identity)
open CategoryObject ⦃ … ⦄
open Functor ⦃ … ⦄
module _
{ℓₗₒ ℓₗₘ ℓₗₑ ℓᵣₒ ℓᵣₘ ℓᵣₑ}
{Cₗ : CategoryObject{ℓₗₒ}{ℓₗₘ}{ℓₗₑ}}
{Cᵣ : CategoryObject{ℓᵣₒ}{ℓᵣₘ}{ℓᵣₑ}}
where
private instance _ = Cₗ
private instance _ = Cᵣ
module _ (([∃]-intro F₁ ⦃ functor₁ ⦄) ([∃]-intro F₂ ⦃ functor₂ ⦄) : Cₗ →ᶠᵘⁿᶜᵗᵒʳ Cᵣ) where
-- A natural transformation is a family of morphisms on
record NaturalTransformation(η : ∀(x) → (F₁(x) ⟶ F₂(x))) : Type{Lvl.of(Type.of(Cₗ)) Lvl.⊔ Lvl.of(Type.of(Cᵣ))} where
constructor intro
field natural : ∀{x y}{f : x ⟶ y} → (η(y) ∘ map(f) ≡ map(f) ∘ η(x))
record NaturalIsomorphism(η : ∀(x) → (F₁(x) ⟶ F₂(x))) : Type{Lvl.of(Type.of(Cₗ)) Lvl.⊔ Lvl.of(Type.of(Cᵣ))} where -- TODO: Consider defining this by two natural tranformations instead
constructor intro
field
⦃ naturalTransformation ⦄ : NaturalTransformation(η)
⦃ components-isomorphism ⦄ : ∀{x} → Morphism.Isomorphism{Morphism = Morphism ⦃ Cᵣ ⦄}(_∘_)(id) (η(x))
_→ᴺᵀ_ = ∃(NaturalTransformation)
_↔ᴺᵀ_ = ∃(NaturalIsomorphism)
module _ (F₁ F₂ : Cₗ →ᶠᵘⁿᶜᵗᵒʳ Cᵣ) where
open NaturalIsomorphism ⦃ … ⦄
NaturalIsomorphism-inverse : ∀{η} → ⦃ ni : NaturalIsomorphism(F₁)(F₂)(η) ⦄ → NaturalIsomorphism(F₂)(F₁)(x ↦ Morphism.inv(_∘_)(id) (η(x))) -- TODO: Should not be an instance parameter
NaturalTransformation.natural (NaturalIsomorphism.naturalTransformation NaturalIsomorphism-inverse) {x} {y} {f} = a where
postulate a : ∀{a} → a -- TODO: Prove, and also move natural isomorphisms to a new file
NaturalIsomorphism.components-isomorphism (NaturalIsomorphism-inverse {η}) {x} = inverse-isomorphism category (η(x))
module _ {F₁ F₂ : Cₗ →ᶠᵘⁿᶜᵗᵒʳ Cᵣ} where
open NaturalIsomorphism ⦃ … ⦄
invᴺᵀ : (F₁ ↔ᴺᵀ F₂) → (F₂ ↔ᴺᵀ F₁)
invᴺᵀ ([∃]-intro _) = [∃]-intro _ ⦃ NaturalIsomorphism-inverse F₁ F₂ ⦄
| {
"alphanum_fraction": 0.6820448878,
"avg_line_length": 41.4827586207,
"ext": "agda",
"hexsha": "b031383fbf502b2ea9784dd632e3359750b1e13c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Category/NaturalTransformation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Category/NaturalTransformation.agda",
"max_line_length": 187,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Category/NaturalTransformation.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": 977,
"size": 2406
} |
module UniDB.Morph.Pair where
open import UniDB.Spec
--------------------------------------------------------------------------------
infixl 5 _⊗_
data Pair (Ξ Ζ : MOR) : MOR where
_⊗_ : {γ₁ γ₂ γ₃ : Dom} (ξ : Ξ γ₁ γ₂) (ζ : Ζ γ₂ γ₃) →
Pair Ξ Ζ γ₁ γ₃
instance
iHCompPair : {Ξ Ζ : MOR} → HComp Ξ Ζ (Pair Ξ Ζ)
_⊡_ {{iHCompPair}} = _⊗_
module _
{Ξ : MOR} {{upΞ : Up Ξ}}
{Ζ : MOR} {{upΖ : Up Ζ}}
where
instance
iUpPair : Up (Pair Ξ Ζ)
_↑₁ {{iUpPair}} (ξ ⊗ ζ) = ξ ↑₁ ⊗ ζ ↑₁
_↑_ {{iUpPair}} (ξ ⊗ ζ) δ = (ξ ↑ δ) ⊗ (ζ ↑ δ)
↑-zero {{iUpPair}} (ξ ⊗ ζ) rewrite ↑-zero ξ | ↑-zero ζ = refl
↑-suc {{iUpPair}} (ξ ⊗ ζ) δ⁺ rewrite ↑-suc ξ δ⁺ | ↑-suc ζ δ⁺ = refl
iUpHCompPair : UpHComp Ξ Ζ (Pair Ξ Ζ)
⊡-↑₁ {{iUpHCompPair}} ξ ζ = refl
--------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.42,
"avg_line_length": 25.7575757576,
"ext": "agda",
"hexsha": "6c59f1b1e7e79f40645f74e6f67a0c7285317cb1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "skeuchel/unidb-agda",
"max_forks_repo_path": "UniDB/Morph/Pair.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "skeuchel/unidb-agda",
"max_issues_repo_path": "UniDB/Morph/Pair.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7ae52205db44ad4f463882ba7e5082120fb76349",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "skeuchel/unidb-agda",
"max_stars_repo_path": "UniDB/Morph/Pair.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 379,
"size": 850
} |
-- Andreas, 2015-11-28 Check that postfix constructors are fine.
-- There was a TODO in Agda.Syntax.Concrete.Operators which claimed
-- there would be an ambiguity between `true` applied to variable `wrap`
-- and (_wrap true), and arity of constructors would have to be checked.
-- Parsing works fine, so I removed this TODO.
data Bool : Set where true false : Bool
record Wrap A : Set where
constructor _wrap
field wrapped : A
test : Wrap Bool → Set
test (true wrap) = Bool
test (false wrap) = Bool
test2 : {A : Set} → Wrap A → A
test2 y = let x wrap = y in x
| {
"alphanum_fraction": 0.7105263158,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "710256e3d15db86f991e6d9e4552fff71f173171",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Succeed/PostfixConstructorInPattern.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Succeed/PostfixConstructorInPattern.agda",
"max_line_length": 72,
"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/Succeed/PostfixConstructorInPattern.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": 154,
"size": 570
} |
open import Agda.Builtin.Nat
data B {A : Set} : A → Set where
b : (a : A) → B a
data C {A : Set} : ∀ {a} → B {A} a → Set where
c : {a : A} → C (b a)
id : ∀ {b} → C b → B 0
id c = {!!}
| {
"alphanum_fraction": 0.4397905759,
"avg_line_length": 17.3636363636,
"ext": "agda",
"hexsha": "793e2fcaeb91b23b5f1ee1a9be54faed0dc6f498",
"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/interaction/Issue2620.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/interaction/Issue2620.agda",
"max_line_length": 46,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/interaction/Issue2620.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 89,
"size": 191
} |
{-# OPTIONS --includeC=helloworld.c #-}
module Prelude.FFI where
open import Prelude.IO
open import Prelude.String
open import Prelude.Unit
postulate
helloworld : IO Unit
test : IO String
{-# COMPILED_EPIC helloworld (u : Unit) -> Unit = foreign Unit "hello_world" () #-}
{-# COMPILED_EPIC test (u : Unit) -> Unit = foreign String "test" () #-}
main : IO Unit
main =
helloworld ,,
x <- test ,
putStrLn x
| {
"alphanum_fraction": 0.6746411483,
"avg_line_length": 20.9,
"ext": "agda",
"hexsha": "9ea9e341206121084f9caeb4846b2d6c74c14261",
"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": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/epic/Prelude/FFI.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/epic/Prelude/FFI.agda",
"max_line_length": 83,
"max_stars_count": null,
"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/epic/Prelude/FFI.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 113,
"size": 418
} |
-- Σ-Terms
module Terms where
open import Data.Vec hiding (_++_)
open import Relation.Binary.PropositionalEquality
open import Data.Nat
open import Data.List
open import Data.List.All
open import Data.Fin.Base
open import Size
-- Ranked alphabet: Vector of natural numbers, where vec[i] denotes the arity of symbol i
RankAlph : ℕ → Set
RankAlph n = Vec ℕ n
-- Types
data Type : Set where
TTerm : ∀ {n} → RankAlph n → Type
TFun : Type → Type → Type
-- Type environment
Env : Set
Env = List Type
-- Environment lookup
data _∈`_ : Type → Env → Set where
here : ∀ {φ A} → A ∈` (A ∷ φ)
there : ∀ {φ A A'} → A ∈` φ → A ∈` (A' ∷ φ)
-- Bind a type n times on top of an environment
bind : Env → (A : Type) → ℕ → Env
bind φ A zero = φ
bind φ A (suc n) = A ∷ (bind φ A n)
-- Zero & Successor, Variables, prim. recursion on Σ-Nat, Abstraction, Application
data Expr : Env → Type → Set where
-- Given terms σ₁, ..., σₘ and a term σ with arity α(σ) = m, we get a new term σ(σ₁, ..., σₘ); Special case: m = 0
Term : ∀ {φ n vec} {i : Fin n} {m} {eq : Data.Vec.lookup vec i ≡ m} → (∀ (l : Fin m) → Expr φ (TTerm vec)) → Expr φ (TTerm vec)
-- Recursion on Terms: For every term σ ∈ Σ with arity α(σ) = m, we have an expression of type A in an environment that binds m variables of type A
-- Together with an expression of type Σ, by recursion on the correct expression we get an expression of type A
Term-Rec : ∀ {φ n vec A} → (∀ {l : Fin n} {m} {eq : (Data.Vec.lookup vec l) ≡ m} → Expr (bind φ A m) A) → Expr φ (TTerm vec) → Expr φ A
Var : ∀ {φ A} → A ∈` φ → Expr φ A
Abs : ∀ {φ A B} → Expr (A ∷ φ) B → Expr φ (TFun A B)
App : ∀ {φ A B} → Expr φ (TFun A B) → Expr φ A → Expr φ B
----- Big step semantics using Agda semantics -----
-- Data type for terms
data TTerm' {n} : RankAlph n → Set where
Term' : ∀ {vec m} {i : Fin n} {eq : (Data.Vec.lookup vec i) ≡ m} → (∀ (l : Fin m) → (TTerm' vec)) → (TTerm' vec)
data TTerm'' {n} (ra : RankAlph n) : {i : Size} → Set where
mk : ∀ {i} → (symb : Fin n) → Vec (TTerm'' ra {i}) (Data.Vec.lookup ra symb) → TTerm'' ra {↑ i}
-- From data type to expression
conversion : ∀ {φ n} {vec : RankAlph n} → TTerm' vec → Expr φ (TTerm vec)
conversion (Term'{m = zero}{eq = eq} x) = Term{eq = eq} λ ()
conversion (Term'{m = suc n}{eq = eq} x) = Term{eq = eq} (λ l → conversion (x l))
-- Value definition
Value : Type → Set
Value (TTerm vec) = TTerm' vec
Value (TFun A B) = Value A → Value B
-- Lookup in environment of values
access : ∀ {A φ} → A ∈` φ → All Value φ → Value A
access here (px ∷ p) = px
access (there x) (px ∷ p) = access x p
-- Given a map from Fin (suc m) to anything; we can derive a map from Fin m to anything
-- (make the Urbild smaller)
urbild : ∀ {m} {A : Set} → (Fin (suc m) → A) → (Fin m → A)
urbild l = λ x → l (raise 1 x)
nary : (A : Set) → ℕ → Set
nary A zero = A
nary A (suc n) = A → nary A n
algebra : ∀ {n} → RankAlph n → (A : Set) → Vec Set n
algebra vec A = Data.Vec.map (nary A) vec
term-rec : ∀ {A : Set} {n : ℕ} {vec : RankAlph n} → (alg : Vec Set n) → TTerm' vec → A
term-rec v (Term'{m = zero} x) = {!!}
term-rec v (Term'{m = suc m} x) = {!!}
-- Evaluation
eval : ∀ {φ A} → Expr φ A → All Value φ → Value A
--
eval (Term{m = zero}{eq = eq} x) ϱ = Term'{eq = eq} λ ()
eval (Term{m = suc n}{eq = eq} x) ϱ = Term'{eq = eq} (λ l → eval (x l) ϱ)
eval (Term-Rec σ-exprs eₛ) ϱ = {!!}
eval (Var x) ϱ = access x ϱ
eval (Abs e) ϱ = λ x → eval e (x ∷ ϱ)
eval (App e e₁) ϱ = (eval e ϱ) (eval e₁ ϱ)
-----
{--
-- eval (Σ-Rec σ-exprs eₛ) with (eval eₛ ϱ)
-- ... | σ∈Σ⁰ i x = eval (σ-exprs i x) ϱ
-- ... | σ∈Σᵐ i x x₁ = eval (σ-exprs i x₁) (rec σ-exprs ϱ x)
-- rec : ∀ {φ A n m} {vec : Vec ℕ n} → (∀ (l : Fin n) → ∀ {m} → (Data.Vec.lookup vec l) ≡ m → Expr (bind φ A m) A) → All Value φ → (∀ (l : Fin m) → (Σ' vec)) → All Value (bind φ A m)
-- rec {m = zero} σ-exprs ϱ terms = ϱ
-- rec {m = suc m} σ-exprs ϱ terms = eval (Σ-Rec σ-exprs (conversion (terms (fromℕ m)))) ϱ ∷ (rec{m = m} σ-exprs ϱ (urbild terms))
-- Example: ℕ; Σ = {Z⁰, S¹} (where ⁿ defines arity)
Nat : Type
Nat = TTerm (0 ∷ 1 ∷ [])
--- Natural number to expression
ℕtoE : ℕ → Expr [] Nat
--- Cases
plus-exprs : ℕ → (∀ (l : Fin 2) → ∀ {m} → (Data.Vec.lookup (0 ∷ 1 ∷ []) l) ≡ m → Expr (bind [] (Nat) m) Nat)
-- base case for n + zero = n
plus-exprs n zero {zero} 0≡0 = ℕtoE n
-- suc case, n + (suc m) = suc (n + m); (n + m) recursively calculated and put ontop of the environemnt, hence Var here
-- plus-exprs n (suc zero) {suc zero} 1≡1 = Term{m = 1} (suc zero) (λ l → Var here) refl
_plus_ : ℕ → ℕ → Expr [] (Nat)
n plus m = Term-Rec (plus-exprs n) (ℕtoE m)
-- Example with explanation
--
--}
----- Small step semantics -----
----- Substitution: See SystemT.agda for a more detailed description
insdebr : ∀ {φ φ'} {A B} → B ∈` (φ' ++ φ) → B ∈` (φ' ++ (A ∷ φ))
insdebr {φ' = []} here = there here
insdebr {φ' = []} (there x) = there (there x)
insdebr {φ' = y ∷ ys} here = here
insdebr {φ' = y ∷ ys} (there x) = there (insdebr x)
-- Extract the ℕ m from proof that vector contains it at index l
extr : ∀ {n l m} {vec : RankAlph n} → (Data.Vec.lookup vec l ≡ m) → ℕ
extr {m} refl = m
-- Proof that (A' ∷ ... ∷ A' ∷ (φ' ++ A ∷ φ)) is "equal to itself", Agda cannot see this
-- from the definition of bind
insbind : ∀ (φ' : Env) (φ : Env) (A' : Type) (m : ℕ) → bind (φ' ++ φ) A' m ≡ bind φ' A' m ++ φ
insbind [] φ' A' zero = refl
insbind [] φ' A' (suc m) = cong (_∷_ A') (insbind [] φ' A' m)
insbind (x ∷ φ) φ' A' zero = refl
insbind (x ∷ φ) φ' A' (suc m) = cong (_∷_ A') (insbind (x ∷ φ) φ' A' m)
ins : ∀ {φ φ'} {A B} → Expr (φ' ++ φ) B → Expr (φ' ++ A ∷ φ) B
ins (Var x) = Var (insdebr x)
ins (Term{m = zero}{eq = eq} x) = Term{eq = eq} (λ ())
ins (Term{m = suc m}{eq = eq} x) = Term{eq = eq} λ l → ins (x l)
-- Direct rewriting does not work since arity (m) is not in scope
-- ins {φ} {φ'} {A} {B} (Term-Rec{n = n}{vec = vec}{A = .B} x x₁) rewrite (insbind φ' φ B {!!})
ins {φ} {φ'} {A} {B} (Term-Rec{n = n}{vec = vec}{A = .B} x x₁)
= Term-Rec (λ {l : Fin n} {m} {eq : Data.Vec.lookup vec l ≡ m} → ϱ{vec = vec} l m eq (x {l} {m} {eq})) (ins x₁)
where
ϱ : ∀ {vec} → (l : Fin n) → (m : ℕ) → (Data.Vec.lookup vec l) ≡ m → Expr (bind (φ' ++ φ) B m) B → Expr (bind (φ' ++ (A ∷ φ)) B m) B
ϱ l m eq ex rewrite (insbind φ' φ B m) | (insbind φ' (A ∷ φ) B m) = ins{φ = φ}{φ' = bind φ' B m}{A = A} ex
ins {φ' = φ'} (Abs{A = A'} x) = Abs (ins{φ' = A' ∷ φ'} x)
ins (App x y) = App (ins x) (ins y)
varsub : ∀ {φ φ'} {A B} → A ∈` (φ' ++ B ∷ φ) → Expr φ B → Expr (φ' ++ φ) A
varsub {φ' = []} here M = M
varsub {φ' = []} (there x) M = Var x
varsub {φ' = z ∷ zs} here M = Var here
varsub {φ' = z ∷ zs} (there x) M = ins{φ' = []} (varsub x M)
_[[_]] : ∀ {φ φ'} {A B : Type} → Expr (φ' ++ B ∷ φ) A → Expr φ B → Expr (φ' ++ φ) A
Var x [[ M ]] = varsub x M
Term{m = zero}{eq = eq} x [[ M ]] = Term{eq = eq} (λ ())
Term{m = suc m}{eq = eq} x [[ M ]] = Term{eq = eq} λ l → x l [[ M ]]
_[[_]] {φ} {φ'} {A} {B} (Term-Rec{n = n}{vec = vec}{A = A'} trms e) M
= Term-Rec (λ {l} {m} {eq} → ϱ{vec = vec} l m eq (trms {l} {m} {eq})) (e [[ M ]])
where
ϱ : ∀ {vec} → (l : Fin n) → (m : ℕ) → (Data.Vec.lookup vec l) ≡ m → Expr (bind (φ' ++ B ∷ φ) A m) A → Expr (bind (φ' ++ φ) A m) A
ϱ l m eq expr rewrite (insbind φ' (B ∷ φ) A m) | (insbind φ' φ A m) = _[[_]] {φ} {bind φ' A m} {A} {B} expr M
Abs N [[ M ]] = Abs (N [[ M ]])
App N N' [[ M ]] = App (N [[ M ]]) (N' [[ M ]])
-- Values
data Value' {φ} : (t : Type) → Expr φ t → Set where
VTerm : ∀ {n} {vec : Vec ℕ n} {i : Fin n} {m} {eq : Data.Vec.lookup vec i ≡ m}
→ (subt : Fin m → Expr φ (TTerm vec))
→ (∀ {l : Fin m} → Value' (TTerm vec) (subt l))
→ Value' (TTerm vec) (Term {i = i}{m}{eq} subt)
VFun : ∀ {A B expr} → Value' (TFun A B) (Abs expr)
---- Functions required for Term-Rec
-- Select term for recursion
termsel : ∀ {φ A n m vec} → (∀ {l : Fin n} {m'} {eq : Data.Vec.lookup vec l ≡ m'} → Expr (bind φ A m') A) → Expr φ (TTerm vec) → Expr (bind φ A m) A
termsel {m = m} {vec = vec} trms (Term{i = i}{m = m'}{eq = eq} x) = {!!}
termsel trms (Term-Rec x trm) = {!!}
termsel trms (Var x) = {!!}
termsel trms (App trm trm₁) = {!!}
-- Proof that (bind (A ∷ φ) A m) ≡ (A ∷ bind φ A m)
bindapp : ∀ {φ A m} → bind (A ∷ φ) A m ≡ (A ∷ bind φ A m)
bindapp {m = zero} = refl
bindapp {A = A} {m = suc m} = cong (_∷_ A) bindapp
-- Looks more complicated than it is:
-- Given a Term-Rec expression - including a map that for each term t' in our ranked alphabet with arity α(t') = m'
-- defines an expression with m' bound variables - and a specific Term t with arity α(t) = m:
-- Recursively, on m from "right-to-left", bind a Term-Rec expression with the same map using the topmost subterm on top of the environment
-- Term-Rec trms σ(t₁, ..., tₘ) →
-- ( ... ((trms(σ) [y₁ ↦ Term-Rec trms t₁]) [y₂ ↦ Term-Rec trms t₂]) ...) [yₘ ↦ Term-Rec trms tₘ]
bindtosubs : ∀ {m n φ A} {vec : RankAlph n} →
(trms : (∀ {l : Fin n} {m'} {eq : Data.Vec.lookup vec l ≡ m'} → Expr (bind φ A m') A)) →
(subtrms : (∀ (l : Fin m) → Expr φ (TTerm vec))) →
Expr (bind φ A m) A →
Expr φ A
bindtosubs {zero} trms subtrms e = e
bindtosubs {suc m} {n = n} {φ} {A} {vec = vec} trms subtrms e rewrite sym (bindapp {φ} {A} {m})
= (bindtosubs{m = m}{n = n}{vec = vec} (λ {l} {m'} {eq} → ϱ l m' eq (trms {l} {m'} {eq})) (λ l → ins{φ' = []}{A = A} ((urbild subtrms) l)) e)
[[ Term-Rec (λ {l} {m'} {eq} → trms {l} {m'} {eq}) (subtrms (fromℕ m)) ]]
where -- Adjustement of environment/DeBruijn indices: In the recursion step, we have to adjust the term map (∀ t' with α(t') = m' we get an Expr with m' bound vars)
-- by adding another bound variable. If we for example have a "Var here" in σ, this adjustement leads to the correct
-- substitution with evaluated σ₁ that has m bound variables.
ϱ : (l : Fin n) → (m' : ℕ) → (Data.Vec.lookup vec l) ≡ m' → Expr (bind φ A m') A → Expr (bind (A ∷ φ) A m') A
ϱ l m' eq ex rewrite (bindapp {φ} {A} {m'}) = ins{φ' = []}{A = A} ex
data _↠_ {φ} : {A : Type} → Expr φ A → Expr φ A → Set where
-- Basic call-by-value λ-calc. stuff
-- Application: Elimination & Reduction
ξ-App1 : ∀ {A B} {L L' : Expr φ (TFun B A)} {M}
→ L ↠ L'
→ App L M ↠ App L' M
ξ-App2 : ∀ {A B} {M M' : Expr φ A} {L : Expr φ (TFun A B)}
→ Value' (TFun A B) L
→ M ↠ M'
→ App L M ↠ App L M'
β-App : ∀ {A B M exp}
→ Value' B M
→ App{B = A} (Abs exp) M ↠ (exp [[ M ]])
-- Term elimination
ξ-TermRec : ∀ {A} {n} {vec : RankAlph n} {e e'}
{trms : (∀ {l : Fin n} {m : ℕ} {eq : (Data.Vec.lookup vec l ≡ m)} → Expr (bind φ A m) A)}
→ e ↠ e'
→ Term-Rec{n = n}{vec = vec} (λ {l} {m'} {eq} → trms {l} {m'} {eq}) e ↠ Term-Rec (λ {l} {m'} {eq} → trms {l} {m'} {eq}) e'
{-
β-TermRec : ∀ {A} {n i} {vec : Vec ℕ n} {e}
{trms : (∀ {l : Fin n} {m : ℕ} {eq : (Data.Vec.lookup vec i ≡ m)} → Expr (bind φ A m) A)}
→ Value' (TTerm vec) e
→ {!!}
-}
| {
"alphanum_fraction": 0.5023850085,
"avg_line_length": 46.5873015873,
"ext": "agda",
"hexsha": "c03183b7ca82d5fdc15ac53161f7b886c463959b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-14T17:52:29.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-14T17:52:29.000Z",
"max_forks_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kcaliban/ldlc",
"max_forks_repo_path": "src/sigmatypes/Terms.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"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": "kcaliban/ldlc",
"max_issues_repo_path": "src/sigmatypes/Terms.agda",
"max_line_length": 203,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kcaliban/ldlc",
"max_stars_repo_path": "src/sigmatypes/Terms.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4562,
"size": 11740
} |
-- Andreas, 2017-08-28, issue #2723, reported by Andrea
{-# OPTIONS --allow-unsolved-metas #-}
-- {-# OPTIONS --warning=error #-}
-- {-# OPTIONS -v tc.cover:30 #-}
record Test : Set1 where
field
one two : Set
open Test
foo : Test
foo .one = {!!}
foo = {!!}
foo .two = {!!}
-- WAS: internal error in clause compiler
-- NOW: warning about unreachable clause
| {
"alphanum_fraction": 0.6195652174,
"avg_line_length": 17.5238095238,
"ext": "agda",
"hexsha": "6d07fe5c98afc177cb9c48a9b09765bc7c65ce6b",
"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/Issue2723.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/Issue2723.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Succeed/Issue2723.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 106,
"size": 368
} |
module huffman where
open import lib
open import huffman-types public
----------------------------------------------------------------------------------
-- Run-rewriting rules
----------------------------------------------------------------------------------
data gratr2-nt : Set where
_ws-plus-10 : gratr2-nt
_ws : gratr2-nt
_words : gratr2-nt
_word : gratr2-nt
_start : gratr2-nt
_posinfo : gratr2-nt
_ows-star-11 : gratr2-nt
_ows : gratr2-nt
_digit : gratr2-nt
_codes : gratr2-nt
_code : gratr2-nt
_cmd : gratr2-nt
_character-range-2 : gratr2-nt
_character-range-1 : gratr2-nt
_character-bar-7 : gratr2-nt
_character-bar-6 : gratr2-nt
_character-bar-5 : gratr2-nt
_character-bar-4 : gratr2-nt
_character-bar-3 : gratr2-nt
_character : gratr2-nt
_bvlit : gratr2-nt
_aws-bar-9 : gratr2-nt
_aws-bar-8 : gratr2-nt
_aws : gratr2-nt
gratr2-nt-eq : gratr2-nt → gratr2-nt → 𝔹
gratr2-nt-eq _ws-plus-10 _ws-plus-10 = tt
gratr2-nt-eq _ws _ws = tt
gratr2-nt-eq _words _words = tt
gratr2-nt-eq _word _word = tt
gratr2-nt-eq _start _start = tt
gratr2-nt-eq _posinfo _posinfo = tt
gratr2-nt-eq _ows-star-11 _ows-star-11 = tt
gratr2-nt-eq _ows _ows = tt
gratr2-nt-eq _digit _digit = tt
gratr2-nt-eq _codes _codes = tt
gratr2-nt-eq _code _code = tt
gratr2-nt-eq _cmd _cmd = tt
gratr2-nt-eq _character-range-2 _character-range-2 = tt
gratr2-nt-eq _character-range-1 _character-range-1 = tt
gratr2-nt-eq _character-bar-7 _character-bar-7 = tt
gratr2-nt-eq _character-bar-6 _character-bar-6 = tt
gratr2-nt-eq _character-bar-5 _character-bar-5 = tt
gratr2-nt-eq _character-bar-4 _character-bar-4 = tt
gratr2-nt-eq _character-bar-3 _character-bar-3 = tt
gratr2-nt-eq _character _character = tt
gratr2-nt-eq _bvlit _bvlit = tt
gratr2-nt-eq _aws-bar-9 _aws-bar-9 = tt
gratr2-nt-eq _aws-bar-8 _aws-bar-8 = tt
gratr2-nt-eq _aws _aws = tt
gratr2-nt-eq _ _ = ff
open import rtn gratr2-nt
huffman-start : gratr2-nt → 𝕃 gratr2-rule
huffman-start _ws-plus-10 = (just "P71" , nothing , just _ws-plus-10 , inj₁ _aws :: inj₁ _ws-plus-10 :: []) :: (just "P70" , nothing , just _ws-plus-10 , inj₁ _aws :: []) :: []
huffman-start _ws = (just "P72" , nothing , just _ws , inj₁ _ws-plus-10 :: []) :: []
huffman-start _words = (just "WordsStart" , nothing , just _words , inj₁ _word :: []) :: (just "WordsNext" , nothing , just _words , inj₁ _word :: inj₁ _ws :: inj₁ _words :: []) :: []
huffman-start _word = (just "P1" , nothing , just _word , inj₁ _character :: inj₁ _word :: []) :: (just "P0" , nothing , just _word , inj₁ _character :: []) :: []
huffman-start _start = (just "File" , nothing , just _start , inj₁ _ows :: inj₁ _cmd :: inj₁ _ows :: []) :: []
huffman-start _posinfo = (just "Posinfo" , nothing , just _posinfo , []) :: []
huffman-start _ows-star-11 = (just "P74" , nothing , just _ows-star-11 , inj₁ _aws :: inj₁ _ows-star-11 :: []) :: (just "P73" , nothing , just _ows-star-11 , []) :: []
huffman-start _ows = (just "P75" , nothing , just _ows , inj₁ _ows-star-11 :: []) :: []
huffman-start _digit = (just "Zero" , nothing , just _digit , inj₂ '0' :: []) :: (just "One" , nothing , just _digit , inj₂ '1' :: []) :: []
huffman-start _codes = (just "CodesStart" , nothing , just _codes , inj₁ _code :: []) :: (just "CodesNext" , nothing , just _codes , inj₁ _code :: inj₁ _ws :: inj₁ _codes :: []) :: []
huffman-start _code = (just "Code" , nothing , just _code , inj₁ _word :: inj₁ _ws :: inj₂ '<' :: inj₂ '-' :: inj₁ _ws :: inj₁ _bvlit :: []) :: []
huffman-start _cmd = (just "Encode" , nothing , just _cmd , inj₁ _words :: []) :: (just "Decode" , nothing , just _cmd , inj₂ '!' :: inj₁ _ws :: inj₁ _codes :: inj₁ _ws :: inj₁ _bvlit :: []) :: []
huffman-start _character-range-2 = (just "P53" , nothing , just _character-range-2 , inj₂ 'Z' :: []) :: (just "P52" , nothing , just _character-range-2 , inj₂ 'Y' :: []) :: (just "P51" , nothing , just _character-range-2 , inj₂ 'X' :: []) :: (just "P50" , nothing , just _character-range-2 , inj₂ 'W' :: []) :: (just "P49" , nothing , just _character-range-2 , inj₂ 'V' :: []) :: (just "P48" , nothing , just _character-range-2 , inj₂ 'U' :: []) :: (just "P47" , nothing , just _character-range-2 , inj₂ 'T' :: []) :: (just "P46" , nothing , just _character-range-2 , inj₂ 'S' :: []) :: (just "P45" , nothing , just _character-range-2 , inj₂ 'R' :: []) :: (just "P44" , nothing , just _character-range-2 , inj₂ 'Q' :: []) :: (just "P43" , nothing , just _character-range-2 , inj₂ 'P' :: []) :: (just "P42" , nothing , just _character-range-2 , inj₂ 'O' :: []) :: (just "P41" , nothing , just _character-range-2 , inj₂ 'N' :: []) :: (just "P40" , nothing , just _character-range-2 , inj₂ 'M' :: []) :: (just "P39" , nothing , just _character-range-2 , inj₂ 'L' :: []) :: (just "P38" , nothing , just _character-range-2 , inj₂ 'K' :: []) :: (just "P37" , nothing , just _character-range-2 , inj₂ 'J' :: []) :: (just "P36" , nothing , just _character-range-2 , inj₂ 'I' :: []) :: (just "P35" , nothing , just _character-range-2 , inj₂ 'H' :: []) :: (just "P34" , nothing , just _character-range-2 , inj₂ 'G' :: []) :: (just "P33" , nothing , just _character-range-2 , inj₂ 'F' :: []) :: (just "P32" , nothing , just _character-range-2 , inj₂ 'E' :: []) :: (just "P31" , nothing , just _character-range-2 , inj₂ 'D' :: []) :: (just "P30" , nothing , just _character-range-2 , inj₂ 'C' :: []) :: (just "P29" , nothing , just _character-range-2 , inj₂ 'B' :: []) :: (just "P28" , nothing , just _character-range-2 , inj₂ 'A' :: []) :: []
huffman-start _character-range-1 = (just "P9" , nothing , just _character-range-1 , inj₂ 'h' :: []) :: (just "P8" , nothing , just _character-range-1 , inj₂ 'g' :: []) :: (just "P7" , nothing , just _character-range-1 , inj₂ 'f' :: []) :: (just "P6" , nothing , just _character-range-1 , inj₂ 'e' :: []) :: (just "P5" , nothing , just _character-range-1 , inj₂ 'd' :: []) :: (just "P4" , nothing , just _character-range-1 , inj₂ 'c' :: []) :: (just "P3" , nothing , just _character-range-1 , inj₂ 'b' :: []) :: (just "P27" , nothing , just _character-range-1 , inj₂ 'z' :: []) :: (just "P26" , nothing , just _character-range-1 , inj₂ 'y' :: []) :: (just "P25" , nothing , just _character-range-1 , inj₂ 'x' :: []) :: (just "P24" , nothing , just _character-range-1 , inj₂ 'w' :: []) :: (just "P23" , nothing , just _character-range-1 , inj₂ 'v' :: []) :: (just "P22" , nothing , just _character-range-1 , inj₂ 'u' :: []) :: (just "P21" , nothing , just _character-range-1 , inj₂ 't' :: []) :: (just "P20" , nothing , just _character-range-1 , inj₂ 's' :: []) :: (just "P2" , nothing , just _character-range-1 , inj₂ 'a' :: []) :: (just "P19" , nothing , just _character-range-1 , inj₂ 'r' :: []) :: (just "P18" , nothing , just _character-range-1 , inj₂ 'q' :: []) :: (just "P17" , nothing , just _character-range-1 , inj₂ 'p' :: []) :: (just "P16" , nothing , just _character-range-1 , inj₂ 'o' :: []) :: (just "P15" , nothing , just _character-range-1 , inj₂ 'n' :: []) :: (just "P14" , nothing , just _character-range-1 , inj₂ 'm' :: []) :: (just "P13" , nothing , just _character-range-1 , inj₂ 'l' :: []) :: (just "P12" , nothing , just _character-range-1 , inj₂ 'k' :: []) :: (just "P11" , nothing , just _character-range-1 , inj₂ 'j' :: []) :: (just "P10" , nothing , just _character-range-1 , inj₂ 'i' :: []) :: []
huffman-start _character-bar-7 = (just "P63" , nothing , just _character-bar-7 , inj₁ _character-bar-6 :: []) :: (just "P62" , nothing , just _character-bar-7 , inj₁ _character-range-1 :: []) :: []
huffman-start _character-bar-6 = (just "P61" , nothing , just _character-bar-6 , inj₁ _character-bar-5 :: []) :: (just "P60" , nothing , just _character-bar-6 , inj₁ _character-range-2 :: []) :: []
huffman-start _character-bar-5 = (just "P59" , nothing , just _character-bar-5 , inj₁ _character-bar-4 :: []) :: (just "P58" , nothing , just _character-bar-5 , inj₂ '(' :: []) :: []
huffman-start _character-bar-4 = (just "P57" , nothing , just _character-bar-4 , inj₁ _character-bar-3 :: []) :: (just "P56" , nothing , just _character-bar-4 , inj₂ ')' :: []) :: []
huffman-start _character-bar-3 = (just "P55" , nothing , just _character-bar-3 , inj₂ '.' :: []) :: (just "P54" , nothing , just _character-bar-3 , inj₂ ',' :: []) :: []
huffman-start _character = (just "P64" , nothing , just _character , inj₁ _character-bar-7 :: []) :: []
huffman-start _bvlit = (just "BvlitStart" , nothing , just _bvlit , inj₁ _digit :: []) :: (just "BvlitCons" , nothing , just _bvlit , inj₁ _digit :: inj₁ _bvlit :: []) :: []
huffman-start _aws-bar-9 = (just "P68" , nothing , just _aws-bar-9 , inj₁ _aws-bar-8 :: []) :: (just "P67" , nothing , just _aws-bar-9 , inj₂ '\n' :: []) :: []
huffman-start _aws-bar-8 = (just "P66" , nothing , just _aws-bar-8 , inj₂ ' ' :: []) :: (just "P65" , nothing , just _aws-bar-8 , inj₂ '\t' :: []) :: []
huffman-start _aws = (just "P69" , nothing , just _aws , inj₁ _aws-bar-9 :: []) :: []
huffman-return : maybe gratr2-nt → 𝕃 gratr2-rule
huffman-return _ = []
huffman-rtn : gratr2-rtn
huffman-rtn = record { start = _start ; _eq_ = gratr2-nt-eq ; gratr2-start = huffman-start ; gratr2-return = huffman-return }
open import run ptr
open noderiv
------------------------------------------
-- Length-decreasing rules
------------------------------------------
len-dec-rewrite : Run → maybe (Run × ℕ)
len-dec-rewrite {- BvlitCons-} ((Id "BvlitCons") :: (ParseTree (parsed-digit x0)) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-bvlit (norm-bvlit (BvlitCons x0 x1))) ::' rest , 3)
len-dec-rewrite {- BvlitStart-} ((Id "BvlitStart") :: _::_(ParseTree (parsed-digit x0)) rest) = just (ParseTree (parsed-bvlit (norm-bvlit (BvlitStart x0))) ::' rest , 2)
len-dec-rewrite {- Code-} ((Id "Code") :: (ParseTree (parsed-word x0)) :: (ParseTree parsed-ws) :: (InputChar '<') :: (InputChar '-') :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-code (norm-code (Code x0 x1))) ::' rest , 7)
len-dec-rewrite {- CodesNext-} ((Id "CodesNext") :: (ParseTree (parsed-code x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-codes x1)) rest) = just (ParseTree (parsed-codes (norm-codes (CodesNext x0 x1))) ::' rest , 4)
len-dec-rewrite {- CodesStart-} ((Id "CodesStart") :: _::_(ParseTree (parsed-code x0)) rest) = just (ParseTree (parsed-codes (norm-codes (CodesStart x0))) ::' rest , 2)
len-dec-rewrite {- Decode-} ((Id "Decode") :: (InputChar '!') :: (ParseTree parsed-ws) :: (ParseTree (parsed-codes x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-bvlit x1)) rest) = just (ParseTree (parsed-cmd (norm-cmd (Decode x0 x1))) ::' rest , 6)
len-dec-rewrite {- Encode-} ((Id "Encode") :: _::_(ParseTree (parsed-words x0)) rest) = just (ParseTree (parsed-cmd (norm-cmd (Encode x0))) ::' rest , 2)
len-dec-rewrite {- File-} ((Id "File") :: (ParseTree parsed-ows) :: (ParseTree (parsed-cmd x0)) :: _::_(ParseTree parsed-ows) rest) = just (ParseTree (parsed-start (norm-start (File x0))) ::' rest , 4)
len-dec-rewrite {- One-} ((Id "One") :: _::_(InputChar '1') rest) = just (ParseTree (parsed-digit (norm-digit One)) ::' rest , 2)
len-dec-rewrite {- P0-} ((Id "P0") :: _::_(ParseTree (parsed-character x0)) rest) = just (ParseTree (parsed-word (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P1-} ((Id "P1") :: (ParseTree (parsed-character x0)) :: _::_(ParseTree (parsed-word x1)) rest) = just (ParseTree (parsed-word (string-append 1 x0 x1)) ::' rest , 3)
len-dec-rewrite {- P10-} ((Id "P10") :: _::_(InputChar 'i') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'i'))) ::' rest , 2)
len-dec-rewrite {- P11-} ((Id "P11") :: _::_(InputChar 'j') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'j'))) ::' rest , 2)
len-dec-rewrite {- P12-} ((Id "P12") :: _::_(InputChar 'k') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'k'))) ::' rest , 2)
len-dec-rewrite {- P13-} ((Id "P13") :: _::_(InputChar 'l') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'l'))) ::' rest , 2)
len-dec-rewrite {- P14-} ((Id "P14") :: _::_(InputChar 'm') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'm'))) ::' rest , 2)
len-dec-rewrite {- P15-} ((Id "P15") :: _::_(InputChar 'n') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'n'))) ::' rest , 2)
len-dec-rewrite {- P16-} ((Id "P16") :: _::_(InputChar 'o') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'o'))) ::' rest , 2)
len-dec-rewrite {- P17-} ((Id "P17") :: _::_(InputChar 'p') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'p'))) ::' rest , 2)
len-dec-rewrite {- P18-} ((Id "P18") :: _::_(InputChar 'q') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'q'))) ::' rest , 2)
len-dec-rewrite {- P19-} ((Id "P19") :: _::_(InputChar 'r') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'r'))) ::' rest , 2)
len-dec-rewrite {- P2-} ((Id "P2") :: _::_(InputChar 'a') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'a'))) ::' rest , 2)
len-dec-rewrite {- P20-} ((Id "P20") :: _::_(InputChar 's') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 's'))) ::' rest , 2)
len-dec-rewrite {- P21-} ((Id "P21") :: _::_(InputChar 't') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 't'))) ::' rest , 2)
len-dec-rewrite {- P22-} ((Id "P22") :: _::_(InputChar 'u') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'u'))) ::' rest , 2)
len-dec-rewrite {- P23-} ((Id "P23") :: _::_(InputChar 'v') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'v'))) ::' rest , 2)
len-dec-rewrite {- P24-} ((Id "P24") :: _::_(InputChar 'w') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'w'))) ::' rest , 2)
len-dec-rewrite {- P25-} ((Id "P25") :: _::_(InputChar 'x') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'x'))) ::' rest , 2)
len-dec-rewrite {- P26-} ((Id "P26") :: _::_(InputChar 'y') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'y'))) ::' rest , 2)
len-dec-rewrite {- P27-} ((Id "P27") :: _::_(InputChar 'z') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'z'))) ::' rest , 2)
len-dec-rewrite {- P28-} ((Id "P28") :: _::_(InputChar 'A') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'A'))) ::' rest , 2)
len-dec-rewrite {- P29-} ((Id "P29") :: _::_(InputChar 'B') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'B'))) ::' rest , 2)
len-dec-rewrite {- P3-} ((Id "P3") :: _::_(InputChar 'b') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'b'))) ::' rest , 2)
len-dec-rewrite {- P30-} ((Id "P30") :: _::_(InputChar 'C') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'C'))) ::' rest , 2)
len-dec-rewrite {- P31-} ((Id "P31") :: _::_(InputChar 'D') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'D'))) ::' rest , 2)
len-dec-rewrite {- P32-} ((Id "P32") :: _::_(InputChar 'E') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'E'))) ::' rest , 2)
len-dec-rewrite {- P33-} ((Id "P33") :: _::_(InputChar 'F') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'F'))) ::' rest , 2)
len-dec-rewrite {- P34-} ((Id "P34") :: _::_(InputChar 'G') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'G'))) ::' rest , 2)
len-dec-rewrite {- P35-} ((Id "P35") :: _::_(InputChar 'H') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'H'))) ::' rest , 2)
len-dec-rewrite {- P36-} ((Id "P36") :: _::_(InputChar 'I') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'I'))) ::' rest , 2)
len-dec-rewrite {- P37-} ((Id "P37") :: _::_(InputChar 'J') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'J'))) ::' rest , 2)
len-dec-rewrite {- P38-} ((Id "P38") :: _::_(InputChar 'K') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'K'))) ::' rest , 2)
len-dec-rewrite {- P39-} ((Id "P39") :: _::_(InputChar 'L') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'L'))) ::' rest , 2)
len-dec-rewrite {- P4-} ((Id "P4") :: _::_(InputChar 'c') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'c'))) ::' rest , 2)
len-dec-rewrite {- P40-} ((Id "P40") :: _::_(InputChar 'M') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'M'))) ::' rest , 2)
len-dec-rewrite {- P41-} ((Id "P41") :: _::_(InputChar 'N') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'N'))) ::' rest , 2)
len-dec-rewrite {- P42-} ((Id "P42") :: _::_(InputChar 'O') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'O'))) ::' rest , 2)
len-dec-rewrite {- P43-} ((Id "P43") :: _::_(InputChar 'P') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'P'))) ::' rest , 2)
len-dec-rewrite {- P44-} ((Id "P44") :: _::_(InputChar 'Q') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Q'))) ::' rest , 2)
len-dec-rewrite {- P45-} ((Id "P45") :: _::_(InputChar 'R') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'R'))) ::' rest , 2)
len-dec-rewrite {- P46-} ((Id "P46") :: _::_(InputChar 'S') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'S'))) ::' rest , 2)
len-dec-rewrite {- P47-} ((Id "P47") :: _::_(InputChar 'T') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'T'))) ::' rest , 2)
len-dec-rewrite {- P48-} ((Id "P48") :: _::_(InputChar 'U') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'U'))) ::' rest , 2)
len-dec-rewrite {- P49-} ((Id "P49") :: _::_(InputChar 'V') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'V'))) ::' rest , 2)
len-dec-rewrite {- P5-} ((Id "P5") :: _::_(InputChar 'd') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'd'))) ::' rest , 2)
len-dec-rewrite {- P50-} ((Id "P50") :: _::_(InputChar 'W') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'W'))) ::' rest , 2)
len-dec-rewrite {- P51-} ((Id "P51") :: _::_(InputChar 'X') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'X'))) ::' rest , 2)
len-dec-rewrite {- P52-} ((Id "P52") :: _::_(InputChar 'Y') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Y'))) ::' rest , 2)
len-dec-rewrite {- P53-} ((Id "P53") :: _::_(InputChar 'Z') rest) = just (ParseTree (parsed-character-range-2 (string-append 0 (char-to-string 'Z'))) ::' rest , 2)
len-dec-rewrite {- P54-} ((Id "P54") :: _::_(InputChar ',') rest) = just (ParseTree (parsed-character-bar-3 (string-append 0 (char-to-string ','))) ::' rest , 2)
len-dec-rewrite {- P55-} ((Id "P55") :: _::_(InputChar '.') rest) = just (ParseTree (parsed-character-bar-3 (string-append 0 (char-to-string '.'))) ::' rest , 2)
len-dec-rewrite {- P56-} ((Id "P56") :: _::_(InputChar ')') rest) = just (ParseTree (parsed-character-bar-4 (string-append 0 (char-to-string ')'))) ::' rest , 2)
len-dec-rewrite {- P57-} ((Id "P57") :: _::_(ParseTree (parsed-character-bar-3 x0)) rest) = just (ParseTree (parsed-character-bar-4 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P58-} ((Id "P58") :: _::_(InputChar '(') rest) = just (ParseTree (parsed-character-bar-5 (string-append 0 (char-to-string '('))) ::' rest , 2)
len-dec-rewrite {- P59-} ((Id "P59") :: _::_(ParseTree (parsed-character-bar-4 x0)) rest) = just (ParseTree (parsed-character-bar-5 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P6-} ((Id "P6") :: _::_(InputChar 'e') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'e'))) ::' rest , 2)
len-dec-rewrite {- P60-} ((Id "P60") :: _::_(ParseTree (parsed-character-range-2 x0)) rest) = just (ParseTree (parsed-character-bar-6 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P61-} ((Id "P61") :: _::_(ParseTree (parsed-character-bar-5 x0)) rest) = just (ParseTree (parsed-character-bar-6 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P62-} ((Id "P62") :: _::_(ParseTree (parsed-character-range-1 x0)) rest) = just (ParseTree (parsed-character-bar-7 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P63-} ((Id "P63") :: _::_(ParseTree (parsed-character-bar-6 x0)) rest) = just (ParseTree (parsed-character-bar-7 (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P64-} ((Id "P64") :: _::_(ParseTree (parsed-character-bar-7 x0)) rest) = just (ParseTree (parsed-character (string-append 0 x0)) ::' rest , 2)
len-dec-rewrite {- P65-} ((Id "P65") :: _::_(InputChar '\t') rest) = just (ParseTree parsed-aws-bar-8 ::' rest , 2)
len-dec-rewrite {- P66-} ((Id "P66") :: _::_(InputChar ' ') rest) = just (ParseTree parsed-aws-bar-8 ::' rest , 2)
len-dec-rewrite {- P67-} ((Id "P67") :: _::_(InputChar '\n') rest) = just (ParseTree parsed-aws-bar-9 ::' rest , 2)
len-dec-rewrite {- P68-} ((Id "P68") :: _::_(ParseTree parsed-aws-bar-8) rest) = just (ParseTree parsed-aws-bar-9 ::' rest , 2)
len-dec-rewrite {- P69-} ((Id "P69") :: _::_(ParseTree parsed-aws-bar-9) rest) = just (ParseTree parsed-aws ::' rest , 2)
len-dec-rewrite {- P7-} ((Id "P7") :: _::_(InputChar 'f') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'f'))) ::' rest , 2)
len-dec-rewrite {- P70-} ((Id "P70") :: _::_(ParseTree parsed-aws) rest) = just (ParseTree parsed-ws-plus-10 ::' rest , 2)
len-dec-rewrite {- P71-} ((Id "P71") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ws-plus-10) rest) = just (ParseTree parsed-ws-plus-10 ::' rest , 3)
len-dec-rewrite {- P72-} ((Id "P72") :: _::_(ParseTree parsed-ws-plus-10) rest) = just (ParseTree parsed-ws ::' rest , 2)
len-dec-rewrite {- P74-} ((Id "P74") :: (ParseTree parsed-aws) :: _::_(ParseTree parsed-ows-star-11) rest) = just (ParseTree parsed-ows-star-11 ::' rest , 3)
len-dec-rewrite {- P75-} ((Id "P75") :: _::_(ParseTree parsed-ows-star-11) rest) = just (ParseTree parsed-ows ::' rest , 2)
len-dec-rewrite {- P8-} ((Id "P8") :: _::_(InputChar 'g') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'g'))) ::' rest , 2)
len-dec-rewrite {- P9-} ((Id "P9") :: _::_(InputChar 'h') rest) = just (ParseTree (parsed-character-range-1 (string-append 0 (char-to-string 'h'))) ::' rest , 2)
len-dec-rewrite {- WordsNext-} ((Id "WordsNext") :: (ParseTree (parsed-word x0)) :: (ParseTree parsed-ws) :: _::_(ParseTree (parsed-words x1)) rest) = just (ParseTree (parsed-words (norm-words (WordsNext x0 x1))) ::' rest , 4)
len-dec-rewrite {- WordsStart-} ((Id "WordsStart") :: _::_(ParseTree (parsed-word x0)) rest) = just (ParseTree (parsed-words (norm-words (WordsStart x0))) ::' rest , 2)
len-dec-rewrite {- Zero-} ((Id "Zero") :: _::_(InputChar '0') rest) = just (ParseTree (parsed-digit (norm-digit Zero)) ::' rest , 2)
len-dec-rewrite {- P73-} (_::_(Id "P73") rest) = just (ParseTree parsed-ows-star-11 ::' rest , 1)
len-dec-rewrite {- Posinfo-} (_::_(Posinfo n) rest) = just (ParseTree (parsed-posinfo (ℕ-to-string n)) ::' rest , 1)
len-dec-rewrite x = nothing
rrs : rewriteRules
rrs = record { len-dec-rewrite = len-dec-rewrite }
| {
"alphanum_fraction": 0.6151631478,
"avg_line_length": 118.6435643564,
"ext": "agda",
"hexsha": "0e7b043b31a0fbc508be481c404df50f09496096",
"lang": "Agda",
"max_forks_count": 17,
"max_forks_repo_forks_event_max_datetime": "2021-11-28T20:13:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-03T22:38:15.000Z",
"max_forks_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rfindler/ial",
"max_forks_repo_path": "huffman/huffman.agda",
"max_issues_count": 8,
"max_issues_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_issues_repo_issues_event_max_datetime": "2022-03-22T03:43:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-09T22:53:38.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rfindler/ial",
"max_issues_repo_path": "huffman/huffman.agda",
"max_line_length": 1831,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "f3f0261904577e930bd7646934f756679a6cbba6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rfindler/ial",
"max_stars_repo_path": "huffman/huffman.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T15:05:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-06T13:09:31.000Z",
"num_tokens": 8404,
"size": 23966
} |
{-# OPTIONS --without-K --safe #-}
module Data.Binary.Tests.Subtraction where
open import Data.List as List using (List; _∷_; [])
open import Data.Product
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Binary.Definitions
open import Data.Binary.Operations.Semantics as Pos using (⟦_⇓⟧⁺)
open import Relation.Binary.PropositionalEquality
open import Data.Maybe as Maybe using (Maybe; just; nothing)
ℤ : Set
ℤ = Bit × ℕ
⟦_⇓⟧ : 𝔹± → ℤ
⟦ 0< (O , snd) ⇓⟧ = O , ⟦ snd ⇓⟧⁺
⟦ 0< (I , snd) ⇓⟧ = I , ℕ.pred ⟦ snd ⇓⟧⁺
⟦ 0ᵇ ⇓⟧ = O , 0
- : ℕ → ℤ
- zero = O , zero
- (suc snd) = I , snd
+⇑ : ℕ → ℤ
+⇑ = O ,_
⟦_⇑⟧ : ℤ → 𝔹±
⟦ O , snd ⇑⟧ = Maybe.map (O ,_) Pos.⟦ snd ⇑⟧
⟦ I , snd ⇑⟧ = Maybe.map (I ,_) Pos.⟦ suc snd ⇑⟧
-- _≡⌈_⌉≡_ : (𝔹 → 𝔹) → ℕ → (ℕ → ℕ) → Set
-- fᵇ ≡⌈ n ⌉≡ fⁿ = let xs = List.upTo n in List.map (λ x → ⟦ fᵇ ⟦ x ⇑⟧ ⇓⟧ ) xs ≡ List.map fⁿ xs
prod : ∀ {a b} {A : Set a} {B : Set b} → List A → List B → List (A × B)
prod [] ys = []
prod (x ∷ xs) ys = List.foldr (λ y ys → (x , y) ∷ ys) (prod xs ys) ys
_≡⌈_⌉₂≡_ : (𝔹± → 𝔹± → 𝔹±) → ℕ → (ℤ → ℤ → ℤ) → Set
fᵇ ≡⌈ n ⌉₂≡ fⁿ = List.map (λ { (x , y) → ⟦ fᵇ ⟦ x ⇑⟧ ⟦ y ⇑⟧ ⇓⟧ }) zs ≡ List.map (uncurry fⁿ) zs
where
xs : List ℕ
xs = List.upTo n
ys = List.map (I ,_) xs List.++ List.map (O ,_) xs
zs = prod ys ys
_ℤ-_ : ℕ → ℕ → ℤ
x ℤ- y with y ℕ.<ᵇ x
(x ℤ- y) | I = O , (x ℕ.∸ suc y)
(x ℤ- y) | O = I , (y ℕ.∸ x)
_z+_ : ℤ → ℤ → ℤ
(O , x) z+ (O , y) = O , (x ℕ.+ y)
(O , x) z+ (I , y) = x ℤ- y
(I , x) z+ (O , y) = y ℤ- x
(I , x) z+ (I , y) = I , (suc x ℕ.+ y)
{-# DISPLAY _,_ I xn = - (suc xn) #-}
{-# DISPLAY _,_ O xn = +⇑ xn #-}
open import Data.Binary.Operations.Subtraction
-- _ : ⟦ ⟦ (- 3) ⇑⟧ + ⟦ +⇑ 2 ⇑⟧ ⇓⟧ ≡ (- 1)
-- _ = refl
-- _ : _+_ ≡⌈ 3 ⌉₂≡ _z+_
-- _ = refl
| {
"alphanum_fraction": 0.4848311391,
"avg_line_length": 24.9571428571,
"ext": "agda",
"hexsha": "b59a31d34bb13c624f35e445cf705e285b6add6e",
"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/Binary/Tests/Subtraction.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/Binary/Tests/Subtraction.agda",
"max_line_length": 95,
"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/Binary/Tests/Subtraction.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": 913,
"size": 1747
} |
module NoSig where
open import Data.Nat
myFun : ℕ
myFun = (\ x y -> y ) (\ x -> x) 0
| {
"alphanum_fraction": 0.5747126437,
"avg_line_length": 12.4285714286,
"ext": "agda",
"hexsha": "18aa41ad1c0c1e753c0165f90b199ec452966d35",
"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": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "JoeyEremondi/lambda-pi-constraint",
"max_forks_repo_path": "examples/NoSig.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"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": "JoeyEremondi/lambda-pi-constraint",
"max_issues_repo_path": "examples/NoSig.agda",
"max_line_length": 34,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "64a1b4c6632153d75cba540f7c91f40b49375e2f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "JoeyEremondi/lambda-pi-constraint",
"max_stars_repo_path": "examples/NoSig.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-05T20:21:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-03-16T11:14:56.000Z",
"num_tokens": 33,
"size": 87
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Induction over Subset
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Fin.Subset.Induction where
open import Data.Nat.Base using (ℕ)
open import Data.Nat.Induction using (<-wellFounded)
open import Data.Fin.Subset using (Subset; _⊂_; ∣_∣)
open import Data.Fin.Subset.Properties
open import Induction
open import Induction.WellFounded as WF
------------------------------------------------------------------------
-- Re-export accessability
open WF public using (Acc; acc)
------------------------------------------------------------------------
-- Complete induction based on _⊂_
⊂-Rec : ∀ {n ℓ} → RecStruct (Subset n) ℓ ℓ
⊂-Rec = WfRec _⊂_
⊂-wellFounded : ∀ {n} → WellFounded (_⊂_ {n})
⊂-wellFounded {n} = Subrelation.wellFounded p⊂q⇒∣p∣<∣q∣ (InverseImage.wellFounded ∣_∣ <-wellFounded)
| {
"alphanum_fraction": 0.4989754098,
"avg_line_length": 31.4838709677,
"ext": "agda",
"hexsha": "df304e1d5f8786c271161f4f8117c2dc807d6937",
"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/Fin/Subset/Induction.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/Fin/Subset/Induction.agda",
"max_line_length": 100,
"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/Fin/Subset/Induction.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": 246,
"size": 976
} |
module Data.QuadTree.LensProofs.Valid-LensWrappedTree where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Data.QuadTree.InternalAgda
open import Agda.Primitive
open import Data.Lens.Proofs.LensLaws
open import Data.Lens.Proofs.LensPostulates
open import Data.Lens.Proofs.LensComposition
open import Data.QuadTree.Implementation.QuadrantLenses
open import Data.QuadTree.Implementation.Definition
open import Data.QuadTree.Implementation.ValidTypes
open import Data.QuadTree.Implementation.SafeFunctions
open import Data.QuadTree.Implementation.PublicFunctions
open import Data.QuadTree.Implementation.DataLenses
---- Lens laws for lensWrappedTree
ValidLens-WrappedTree-ViewSet :
{t : Set} {{eqT : Eq t}} {dep : Nat}
-> ViewSet (lensWrappedTree {t} {dep})
ValidLens-WrappedTree-ViewSet (CVQuadrant qdi) (CVQuadTree (Wrapper (w , h) qdo)) = refl
ValidLens-WrappedTree-SetView :
{t : Set} {{eqT : Eq t}} {dep : Nat}
-> SetView (lensWrappedTree {t} {dep})
ValidLens-WrappedTree-SetView (CVQuadTree (Wrapper (w , h) qdo)) = refl
ValidLens-WrappedTree-SetSet :
{t : Set} {{eqT : Eq t}} {dep : Nat}
-> SetSet (lensWrappedTree {t} {dep})
ValidLens-WrappedTree-SetSet (CVQuadrant qd1) (CVQuadrant qd2) (CVQuadTree (Wrapper (w , h) qdo)) = refl
ValidLens-WrappedTree :
{t : Set} {{eqT : Eq t}} {dep : Nat}
-> ValidLens (VQuadTree t {dep}) (VQuadrant t {dep})
ValidLens-WrappedTree = CValidLens lensWrappedTree (ValidLens-WrappedTree-ViewSet) (ValidLens-WrappedTree-SetView) (ValidLens-WrappedTree-SetSet) | {
"alphanum_fraction": 0.7563704164,
"avg_line_length": 42.3421052632,
"ext": "agda",
"hexsha": "33a9b3da0e8a2d4394c3c8dbffd4ba4c418d1788",
"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": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda",
"max_line_length": 145,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/QuadTree/LensProofs/Valid-LensWrappedTree.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 480,
"size": 1609
} |
module LRTree {A : Set} where
open import Data.List
data Tag : Set where
left : Tag
right : Tag
data LRTree : Set where
empty : LRTree
leaf : A → LRTree
node : Tag → LRTree → LRTree → LRTree
insert : A → LRTree → LRTree
insert x empty = leaf x
insert x (leaf y) = node left (leaf y) (leaf x)
insert x (node left l r) = node right (insert x l) r
insert x (node right l r) = node left l (insert x r)
flatten : LRTree → List A
flatten empty = []
flatten (leaf x) = x ∷ []
flatten (node _ l r) = flatten l ++ flatten r
| {
"alphanum_fraction": 0.6471698113,
"avg_line_length": 22.0833333333,
"ext": "agda",
"hexsha": "984c35d11e895b42eebd06a802dc417bc56904a0",
"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/LRTree.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/LRTree.agda",
"max_line_length": 52,
"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/LRTree.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": 181,
"size": 530
} |
module Issue206 where
postulate
I : Set
P : I → Set
i : I
Q : P i → Set
Foo : (p : P i) → Q p → Set₁
Foo p q with i
Foo p q | i′ = Set
-- Now better error message:
-- Issue206.agda:11,1-19
-- w != i of type I
-- when checking that the type of the generated with function
-- (w : I) (p : P w) (q : Q p) → Set₁ is well-formed
| {
"alphanum_fraction": 0.5833333333,
"avg_line_length": 17.6842105263,
"ext": "agda",
"hexsha": "828bc7b2e53f4ace854c0d97fbad118b61d3e44e",
"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/Issue206.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/Issue206.agda",
"max_line_length": 61,
"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/Issue206.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": 127,
"size": 336
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Groups.Abelian.Definition
open import Setoids.Setoids
open import Vectors
open import Numbers.Naturals.Semiring
open import Sets.EquivalenceRelations
module Groups.Vector {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} (G : Group S _+_) where
open Setoid S
open Equivalence eq
open Group G
vecEquiv : {n : ℕ} → Vec A n → Vec A n → Set b
vecEquiv {zero} [] [] = True'
vecEquiv {succ n} (x ,- v1) (y ,- v2) = (x ∼ y) && vecEquiv v1 v2
private
vecEquivRefl : {n : ℕ} → (x : Vec A n) → vecEquiv x x
vecEquivRefl [] = record {}
vecEquivRefl (x ,- xs) = reflexive ,, vecEquivRefl xs
vecEquivSymm : {n : ℕ} → (x y : Vec A n) → vecEquiv x y → vecEquiv y x
vecEquivSymm [] [] record {} = record {}
vecEquivSymm (x ,- xs) (y ,- ys) (fst ,, snd) = symmetric fst ,, vecEquivSymm _ _ snd
vecEquivTrans : {n : ℕ} → (x y z : Vec A n) → vecEquiv x y → vecEquiv y z → vecEquiv x z
vecEquivTrans [] [] [] x=y y=z = record {}
vecEquivTrans (x ,- xs) (y ,- ys) (z ,- zs) (fst1 ,, snd1) (fst2 ,, snd2) = transitive fst1 fst2 ,, vecEquivTrans xs ys zs snd1 snd2
vectorSetoid : (n : ℕ) → Setoid (Vec A n)
Setoid._∼_ (vectorSetoid n) = vecEquiv {n}
Equivalence.reflexive (Setoid.eq (vectorSetoid n)) {x} = vecEquivRefl x
Equivalence.symmetric (Setoid.eq (vectorSetoid n)) {x} {y} = vecEquivSymm x y
Equivalence.transitive (Setoid.eq (vectorSetoid n)) {x} {y} {z} = vecEquivTrans x y z
vectorAdd : {n : ℕ} → Vec A n → Vec A n → Vec A n
vectorAdd [] [] = []
vectorAdd (x ,- v1) (y ,- v2) = (x + y) ,- (vectorAdd v1 v2)
private
addWellDefined : {n : ℕ} → (m k x y : Vec A n) → Setoid._∼_ (vectorSetoid n) m x → Setoid._∼_ (vectorSetoid n) k y → Setoid._∼_ (vectorSetoid n) (vectorAdd m k) (vectorAdd x y)
addWellDefined [] [] [] [] m=x k=y = record {}
addWellDefined (m ,- ms) (k ,- ks) (x ,- xs) (y ,- ys) (m=x ,, ms=xs) (k=y ,, ks=ys) = +WellDefined m=x k=y ,, addWellDefined ms ks xs ys ms=xs ks=ys
addAssoc : {n : ℕ} → (x y z : Vec A n) → Setoid._∼_ (vectorSetoid n) (vectorAdd x (vectorAdd y z)) (vectorAdd (vectorAdd x y) z)
addAssoc [] [] [] = record {}
addAssoc (x ,- xs) (y ,- ys) (z ,- zs) = +Associative ,, addAssoc xs ys zs
vecIdentRight : {n : ℕ} → (a : Vec A n) → Setoid._∼_ (vectorSetoid n) (vectorAdd a (vecPure 0G)) a
vecIdentRight [] = record {}
vecIdentRight (x ,- a) = identRight ,, vecIdentRight a
vecIdentLeft : {n : ℕ} → (a : Vec A n) → Setoid._∼_ (vectorSetoid n) (vectorAdd (vecPure 0G) a) a
vecIdentLeft [] = record {}
vecIdentLeft (x ,- a) = identLeft ,, vecIdentLeft a
vecInvLeft : {n : ℕ} → (a : Vec A n) → Setoid._∼_ (vectorSetoid n) (vectorAdd (vecMap inverse a) a) (vecPure 0G)
vecInvLeft [] = record {}
vecInvLeft (x ,- a) = invLeft ,, vecInvLeft a
vecInvRight : {n : ℕ} → (a : Vec A n) → Setoid._∼_ (vectorSetoid n) (vectorAdd a (vecMap inverse a)) (vecPure 0G)
vecInvRight [] = record {}
vecInvRight (x ,- a) = invRight ,, vecInvRight a
vectorGroup : {n : ℕ} → Group (vectorSetoid n) (vectorAdd {n})
Group.+WellDefined vectorGroup {m} {n} {x} {y} = addWellDefined m n x y
Group.0G vectorGroup = vecPure 0G
Group.inverse vectorGroup x = vecMap inverse x
Group.+Associative vectorGroup {x} {y} {z} = addAssoc x y z
Group.identRight vectorGroup {a} = vecIdentRight a
Group.identLeft vectorGroup {a} = vecIdentLeft a
Group.invLeft vectorGroup {a} = vecInvLeft a
Group.invRight vectorGroup {a} = vecInvRight a
abelianVectorGroup : {n : ℕ} → AbelianGroup G → AbelianGroup (vectorGroup {n})
AbelianGroup.commutative (abelianVectorGroup grp) {[]} {[]} = record {}
AbelianGroup.commutative (abelianVectorGroup grp) {x ,- xs} {y ,- ys} = AbelianGroup.commutative grp ,, AbelianGroup.commutative (abelianVectorGroup grp) {xs} {ys}
| {
"alphanum_fraction": 0.644589309,
"avg_line_length": 46.7682926829,
"ext": "agda",
"hexsha": "156b03f509dd77110fd10baadb20e4e815a9bf58",
"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/Vector.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/Vector.agda",
"max_line_length": 178,
"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/Vector.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": 1404,
"size": 3835
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Operations on and properties of decidable relations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Relation.Nullary.Decidable where
open import Data.Bool.Base using (Bool; false; true; not; T)
open import Data.Empty
open import Data.Product hiding (map)
open import Data.Unit
open import Function
open import Function.Equality using (_⟨$⟩_; module Π)
open import Function.Equivalence
using (_⇔_; equivalence; module Equivalence)
open import Function.Injection using (Injection; module Injection)
open import Level using (Lift)
open import Relation.Binary using (Setoid; module Setoid; Decidable)
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
⌊_⌋ : ∀ {p} {P : Set p} → Dec P → Bool
⌊ yes _ ⌋ = true
⌊ no _ ⌋ = false
True : ∀ {p} {P : Set p} → Dec P → Set
True Q = T ⌊ Q ⌋
False : ∀ {p} {P : Set p} → Dec P → Set
False Q = T (not ⌊ Q ⌋)
-- Gives a witness to the "truth".
toWitness : ∀ {p} {P : Set p} {Q : Dec P} → True Q → P
toWitness {Q = yes p} _ = p
toWitness {Q = no _} ()
-- Establishes a "truth", given a witness.
fromWitness : ∀ {p} {P : Set p} {Q : Dec P} → P → True Q
fromWitness {Q = yes p} = const _
fromWitness {Q = no ¬p} = ¬p
-- Variants for False.
toWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → False Q → ¬ P
toWitnessFalse {Q = yes _} ()
toWitnessFalse {Q = no ¬p} _ = ¬p
fromWitnessFalse : ∀ {p} {P : Set p} {Q : Dec P} → ¬ P → False Q
fromWitnessFalse {Q = yes p} = flip _$_ p
fromWitnessFalse {Q = no ¬p} = const _
map : ∀ {p q} {P : Set p} {Q : Set q} → P ⇔ Q → Dec P → Dec Q
map P⇔Q (yes p) = yes (Equivalence.to P⇔Q ⟨$⟩ p)
map P⇔Q (no ¬p) = no (¬p ∘ _⟨$⟩_ (Equivalence.from P⇔Q))
map′ : ∀ {p q} {P : Set p} {Q : Set q} →
(P → Q) → (Q → P) → Dec P → Dec Q
map′ P→Q Q→P = map (equivalence P→Q Q→P)
module _ {a₁ a₂ b₁ b₂} {A : Setoid a₁ a₂} {B : Setoid b₁ b₂} where
open Injection
open Setoid A using () renaming (_≈_ to _≈A_)
open Setoid B using () renaming (_≈_ to _≈B_)
-- If there is an injection from one setoid to another, and the
-- latter's equivalence relation is decidable, then the former's
-- equivalence relation is also decidable.
via-injection : Injection A B → Decidable _≈B_ → Decidable _≈A_
via-injection inj dec x y with dec (to inj ⟨$⟩ x) (to inj ⟨$⟩ y)
... | yes injx≈injy = yes (Injection.injective inj injx≈injy)
... | no injx≉injy = no (λ x≈y → injx≉injy (Π.cong (to inj) x≈y))
-- If a decision procedure returns "yes", then we can extract the
-- proof using from-yes.
module _ {p} {P : Set p} where
From-yes : Dec P → Set p
From-yes (yes _) = P
From-yes (no _) = Lift p ⊤
from-yes : (p : Dec P) → From-yes p
from-yes (yes p) = p
from-yes (no _) = _
-- If a decision procedure returns "no", then we can extract the proof
-- using from-no.
From-no : Dec P → Set p
From-no (no _) = ¬ P
From-no (yes _) = Lift p ⊤
from-no : (p : Dec P) → From-no p
from-no (no ¬p) = ¬p
from-no (yes _) = _
| {
"alphanum_fraction": 0.5922019815,
"avg_line_length": 30.3786407767,
"ext": "agda",
"hexsha": "dae24e0a80c56b3e919e7b1cdf2e36573cd86481",
"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/Nullary/Decidable.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/Nullary/Decidable.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/Relation/Nullary/Decidable.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1089,
"size": 3129
} |
module MLib.Prelude.Fin where
open import MLib.Prelude.FromStdlib
open import Data.Fin public
open import Data.Fin.Properties public
open FE using (cong)
import Relation.Binary.Indexed as I
--------------------------------------------------------------------------------
-- Types
--------------------------------------------------------------------------------
-- 'Fin∸ {n} i' is a finite set with "n - i" inhabitants.
Fin∸ : ∀ {n} → Fin n → Set
Fin∸ {n} i = Fin (n Nat.∸ toℕ i)
--------------------------------------------------------------------------------
-- Combinators
--------------------------------------------------------------------------------
foldUpto : ∀ {a} {A : Set a} n → A → (Fin n → A → A) → A
foldUpto Nat.zero z f = z
foldUpto (Nat.suc n) z f = f zero (foldUpto n z (f ∘ suc))
foldMap : ∀ {n ℓ} {A : Set ℓ} → A → (A → A → A) → (Fin n → A) → A
foldMap {n} z f g = foldUpto n z (f ∘ g)
inject∸ : ∀ {n} (i : Fin n) → Fin∸ i → Fin n
inject∸ zero j = j
inject∸ (suc i) j = inject₁ (inject∸ i j)
strengthen∸ : ∀ {n} (i : Fin n) → Fin∸ i → Fin n
strengthen∸ zero j = j
strengthen∸ (suc i) j = Fin.suc (strengthen∸ i j)
module _ where
open import Data.List using (List; []; _∷_; _++_)
open import Data.Maybe using (Is-just)
-- Performs a comprehension over the finite set.
collect : ∀ n {a} {A : Fin n → Set a} (f : ∀ i → Maybe (A i)) → List (∃ A)
collect n {A = A} f = foldUpto n [] (λ i xs → maybe (λ x → (i , x) ∷ xs) xs (f i))
collect′ : ∀ n {a} {A : Set a} (f : Fin n → Maybe A) → List A
collect′ n {A = A} f = foldUpto n [] (λ i xs → maybe (λ x → x List.∷ xs) xs (f i))
--------------------------------------------------------------------------------
-- Theorems
--------------------------------------------------------------------------------
module _ {ℓ p} (setoid : Setoid ℓ p) where
open Setoid setoid renaming (Carrier to A)
module _ {x y : A} {_+_ : A → A → A} (z-cong : x ≈ y) (+-cong : ∀ {x y u v} → x ≈ y → u ≈ v → (x + u) ≈ (y + v)) where
foldMap-cong :
∀ {n}
→ (f g : Fin n → A)
→ (∀ i → f i ≈ g i)
→ foldMap {n} x _+_ f ≈ foldMap y _+_ g
foldMap-cong {Nat.zero} f g p = z-cong
foldMap-cong {Nat.suc n} f g p = +-cong (p _) (foldMap-cong (f ∘ suc) (g ∘ suc) (p ∘ suc))
≠-inject : ∀ n (x : Fin n) → ¬ fromℕ n ≡ inject₁ x
≠-inject .(Nat.suc _) zero ()
≠-inject .(Nat.suc _) (suc x) = ≠-inject _ x ∘ suc-injective
suc≠inject : ∀ {n} (i : Fin n) → ¬ (suc i ≡ inject₁ i)
suc≠inject zero ()
suc≠inject (suc i) p = suc≠inject i (suc-injective p)
toℕ≤n : ∀ {n} (i : Fin n) → toℕ i Nat.≤ n
toℕ≤n zero = Nat.z≤n
toℕ≤n (suc i) = Nat.s≤s (toℕ≤n i)
inject-refute : ∀ n {i : Fin (Nat.suc n)} x → i ≡ fromℕ n → ¬ i ≡ inject₁ x
inject-refute _ {zero} zero ()
inject-refute _ {zero} (suc x) ()
inject-refute Nat.zero {suc i} _()
inject-refute (Nat.suc n) {suc i} (zero) p ()
inject-refute (Nat.suc n) {suc i} (suc x) p q = inject-refute _ _ (suc-injective p) (suc-injective q)
inject-< : ∀ {n} (i : Fin n) (j : Fin′ i) → inject j < i
inject-< zero ()
inject-< (suc i) zero = Nat.s≤s Nat.z≤n
inject-< (suc i) (suc j) = Nat.s≤s (inject-< i j)
data Compareℕ {m} : (i : Fin m) (n : ℕ) → Set where
less : ∀ bound (least : Fin′ bound) {greatest} → Compareℕ (inject! least) greatest
equal : ∀ i → Compareℕ i (toℕ i)
greater : ∀ greatest (least : Fin′ greatest) → Compareℕ greatest (toℕ least)
compareℕ : ∀ {m} (i : Fin m) (n : ℕ) → Compareℕ i n
compareℕ zero Nat.zero = equal _
compareℕ zero (Nat.suc n) = less (suc zero) zero
compareℕ (suc i) Nat.zero = greater (suc i) zero
compareℕ (suc i) (Nat.suc n) with compareℕ i n
compareℕ (suc .(inject! least)) (Nat.suc n) | less bound least = less (suc bound) (suc least)
compareℕ (suc i) (Nat.suc .(toℕ i)) | equal .i = equal (suc i)
compareℕ (suc i) (Nat.suc .(toℕ least)) | greater .i least = greater (suc i) (suc least)
reduce+ : ∀ m {n} (i : Fin (m Nat.+ n)) → (∃ λ (j : Fin m) → inject+ n j ≡ i) ⊎ ∃ λ j → raise m j ≡ i
reduce+ Nat.zero i = inj₂ (i , ≡.refl)
reduce+ (Nat.suc m) zero = inj₁ (zero , ≡.refl)
reduce+ (Nat.suc m) (suc i) with reduce+ m i
reduce+ (Nat.suc m) (suc i) | inj₁ (j , p) = inj₁ (suc j , ≡.cong suc p)
reduce+ (Nat.suc m) (suc i) | inj₂ (j , p) = inj₂ (j , ≡.cong suc p)
inject+-injective : ∀ {n m} {i j : Fin m} → inject+ n i ≡ inject+ n j → i ≡ j
inject+-injective {i = zero} {zero} p = ≡.refl
inject+-injective {i = zero} {suc j} ()
inject+-injective {i = suc i} {zero} ()
inject+-injective {n} {i = suc i} {suc j} p = ≡.cong suc (inject+-injective {n} (suc-injective p))
raise≢ : ∀ m n {i : Fin m} {j : Fin n} → ¬ raise n i ≡ inject+ m j
raise≢ _ _ {j = zero} ()
raise≢ _ _ {j = suc _} p = ⊥-elim (raise≢ _ _ (suc-injective p))
raise-injective : ∀ {m} n {i j : Fin m} → raise n i ≡ raise n j → i ≡ j
raise-injective Nat.zero {i} {j} p = p
raise-injective (Nat.suc n) {i} {j} p = raise-injective n (suc-injective p)
toℕ-injective′ : ∀ {m n} {i : Fin m} {j : Fin n} → toℕ i ≡ toℕ j → m ≡ n → i ≅ j
toℕ-injective′ {i = i} {j} p ≡.refl = ≅.≡-to-≅ (toℕ-injective p)
toℕ-injective₂ : ∀ {m} {f : Fin m → ℕ} {i i′ : Fin m} {j : Fin (f i)} {j′ : Fin (f i′)} → (toℕ i , toℕ j) ≡ (toℕ i′ , toℕ j′) → _≡_ {A = Σ (Fin m) (Fin ∘ f)} (i , j) (i′ , j′)
toℕ-injective₂ {f = f} p =
let q , r = Σ.≡⇒Pointwise-≡ p
q′ = toℕ-injective q
in Σ.Pointwise-≡⇒≡ (q′ , toℕ-injective′ (≅.≅-to-≡ r) (≡.cong f q′))
| {
"alphanum_fraction": 0.5100558659,
"avg_line_length": 40.3759398496,
"ext": "agda",
"hexsha": "167b1eb45a67518a6af14c2a006db79e43ed15ed",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bch29/agda-matrices",
"max_forks_repo_path": "src/MLib/Prelude/Fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bch29/agda-matrices",
"max_issues_repo_path": "src/MLib/Prelude/Fin.agda",
"max_line_length": 175,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e26ae2e0aa7721cb89865aae78625a2f3fd2b574",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bch29/agda-matrices",
"max_stars_repo_path": "src/MLib/Prelude/Fin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2164,
"size": 5370
} |
------------------------------------------------------------------------
-- Higher lenses
------------------------------------------------------------------------
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Lens.Non-dependent.Higher
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
import Bi-invertibility
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id) renaming (_∘_ to _⊚_)
open import Bijection equality-with-J as Bij using (_↔_)
open import Category equality-with-J as C using (Category; Precategory)
open import Circle eq as Circle using (𝕊¹)
open import Equality.Decidable-UIP equality-with-J
open import Equality.Decision-procedures equality-with-J
open import Equality.Path.Isomorphisms eq hiding (univ)
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Function-universe equality-with-J as F hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import H-level.Truncation.Propositional eq as Trunc
import Nat equality-with-J as Nat
open import Preimage equality-with-J using (_⁻¹_)
open import Surjection equality-with-J using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq as Non-dependent
hiding (no-first-projection-lens)
import Lens.Non-dependent.Traditional eq as Traditional
private
variable
a b c d r : Level
A A₁ A₂ B B₁ B₂ C X Y : Set a
n : ℕ
------------------------------------------------------------------------
-- Higher lenses
-- Higher lenses.
--
-- A little history: The "lenses" in Lens.Non-dependent.Bijection are
-- not very well-behaved. I had previously considered some other
-- variants, when Andrea Vezzosi suggested that I should look at Paolo
-- Capriotti's higher lenses, and that I could perhaps use R → ∥ B ∥.
-- This worked out nicely.
--
-- For performance reasons η-equality is turned off for this record
-- type. One can match on the constructor to block evaluation.
record Lens (A : Set a) (B : Set b) : Set (lsuc (a ⊔ b)) where
constructor ⟨_,_,_⟩
pattern
no-eta-equality
field
-- Remainder type.
R : Set (a ⊔ b)
-- Equivalence.
equiv : A ≃ (R × B)
-- The proof of (mere) inhabitance.
inhabited : R → ∥ B ∥
-- Remainder.
remainder : A → R
remainder a = proj₁ (_≃_.to equiv a)
-- Getter.
get : A → B
get a = proj₂ (_≃_.to equiv a)
-- Setter.
set : A → B → A
set a b = _≃_.from equiv (remainder a , b)
-- A combination of get and set.
modify : (B → B) → A → A
modify f x = set x (f (get x))
-- Lens laws.
get-set : ∀ a b → get (set a b) ≡ b
get-set a b =
proj₂ (_≃_.to equiv (_≃_.from equiv (remainder a , b))) ≡⟨ cong proj₂ (_≃_.right-inverse-of equiv _) ⟩∎
proj₂ (remainder a , b) ∎
set-get : ∀ a → set a (get a) ≡ a
set-get a =
_≃_.from equiv (_≃_.to equiv a) ≡⟨ _≃_.left-inverse-of equiv _ ⟩∎
a ∎
set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
set-set a b₁ b₂ =
let r = remainder a in
_≃_.from equiv (remainder (_≃_.from equiv (r , b₁)) , b₂) ≡⟨⟩
_≃_.from equiv
(proj₁ (_≃_.to equiv (_≃_.from equiv (r , b₁))) , b₂) ≡⟨ cong (λ x → _≃_.from equiv (proj₁ x , b₂))
(_≃_.right-inverse-of equiv _) ⟩∎
_≃_.from equiv (r , b₂) ∎
-- Another law.
remainder-set : ∀ a b → remainder (set a b) ≡ remainder a
remainder-set a b =
proj₁ (_≃_.to equiv (_≃_.from equiv (remainder a , b))) ≡⟨ cong proj₁ $ _≃_.right-inverse-of equiv _ ⟩∎
remainder a ∎
-- The remainder function is surjective.
remainder-surjective : Surjective remainder
remainder-surjective r =
∥∥-map (λ b → _≃_.from equiv (r , b)
, (remainder (_≃_.from equiv (r , b)) ≡⟨ cong proj₁ $ _≃_.right-inverse-of equiv _ ⟩∎
r ∎))
(inhabited r)
-- Traditional lens.
traditional-lens : Traditional.Lens A B
traditional-lens = record
{ get = get
; set = set
; get-set = get-set
; set-get = set-get
; set-set = set-set
}
-- The following two coherence laws, which do not necessarily hold
-- for traditional lenses (see
-- Traditional.getter-equivalence-but-not-coherent), hold
-- unconditionally for higher lenses.
get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a)
get-set-get a =
cong (proj₂ ⊚ _≃_.to equiv) (_≃_.left-inverse-of equiv _) ≡⟨ sym $ cong-∘ _ _ (_≃_.left-inverse-of equiv _) ⟩
cong proj₂ (cong (_≃_.to equiv) (_≃_.left-inverse-of equiv _)) ≡⟨ cong (cong proj₂) $ _≃_.left-right-lemma equiv _ ⟩∎
cong proj₂ (_≃_.right-inverse-of equiv _) ∎
get-set-set :
∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))
get-set-set a b₁ b₂ = elim₁
(λ eq →
cong (proj₂ ⊚ _≃_.to equiv)
(cong (λ p → _≃_.from equiv (proj₁ p , _)) eq) ≡
trans (cong proj₂ (_≃_.right-inverse-of equiv _))
(sym (cong proj₂ (_≃_.right-inverse-of equiv _))))
(cong (proj₂ ⊚ _≃_.to equiv)
(cong (λ p → _≃_.from equiv (proj₁ p , b₂))
(refl (proj₁ (_≃_.to equiv a) , b₁))) ≡⟨ cong (cong (proj₂ ⊚ _≃_.to equiv)) $ cong-refl _ ⟩
cong (proj₂ ⊚ _≃_.to equiv) (refl _) ≡⟨ cong-refl _ ⟩
refl _ ≡⟨ sym $ trans-symʳ _ ⟩∎
trans (cong proj₂ (_≃_.right-inverse-of equiv _))
(sym (cong proj₂ (_≃_.right-inverse-of equiv _))) ∎)
(_≃_.right-inverse-of equiv _)
-- A somewhat coherent lens.
coherent-lens : Traditional.Coherent-lens A B
coherent-lens = record
{ lens = traditional-lens
; get-set-get = get-set-get
; get-set-set = get-set-set
}
instance
-- Higher lenses have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
------------------------------------------------------------------------
-- Simple definitions related to lenses
-- Lens can be expressed as a nested Σ-type.
Lens-as-Σ :
{A : Set a} {B : Set b} →
Lens A B ↔
∃ λ (R : Set (a ⊔ b)) →
(A ≃ (R × B)) ×
(R → ∥ B ∥)
Lens-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ l → R l , equiv l , inhabited l
; from = λ (R , equiv , inhabited) → record
{ R = R
; equiv = equiv
; inhabited = inhabited
}
}
; right-inverse-of = refl
}
; left-inverse-of = λ { ⟨ _ , _ , _ ⟩ → refl _ }
}
where
open Lens
-- Isomorphisms can be converted into lenses.
isomorphism-to-lens :
{A : Set a} {B : Set b} {R : Set (a ⊔ b)} →
A ↔ R × B → Lens A B
isomorphism-to-lens {A = A} {B = B} {R = R} iso = record
{ R = R × ∥ B ∥
; equiv = A ↔⟨ iso ⟩
R × B ↔⟨ F.id ×-cong inverse ∥∥×↔ ⟩
R × ∥ B ∥ × B ↔⟨ ×-assoc ⟩□
(R × ∥ B ∥) × B □
; inhabited = proj₂
}
-- Converts equivalences to lenses.
≃→lens :
{A : Set a} {B : Set b} →
A ≃ B → Lens A B
≃→lens {a = a} {A = A} {B = B} A≃B = record
{ R = ∥ ↑ a B ∥
; equiv = A ↝⟨ A≃B ⟩
B ↝⟨ inverse ∥∥×≃ ⟩
∥ B ∥ × B ↔⟨ ∥∥-cong (inverse Bij.↑↔) ×-cong F.id ⟩□
∥ ↑ a B ∥ × B □
; inhabited = ∥∥-map lower
}
-- Converts equivalences between types with the same universe level to
-- lenses.
≃→lens′ :
{A B : Set a} →
A ≃ B → Lens A B
≃→lens′ {a = a} {A = A} {B = B} A≃B = record
{ R = ∥ B ∥
; equiv = A ↝⟨ A≃B ⟩
B ↝⟨ inverse ∥∥×≃ ⟩□
∥ B ∥ × B □
; inhabited = P.id
}
------------------------------------------------------------------------
-- Equality characterisations for lenses
-- Equality of lenses is isomorphic to certain pairs.
equality-characterisation₀ :
{l₁ l₂ : Lens A B} →
let open Lens in
l₁ ≡ l₂
↔
∃ λ (p : R l₁ ≡ R l₂) →
subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂
equality-characterisation₀ {A = A} {B = B} {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ Lens-as-Σ ⟩
l₁′ ≡ l₂′ ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩
(∃ λ (p : R l₁ ≡ R l₂) →
subst (λ R → A ≃ (R × B) × (R → ∥ B ∥)) p (proj₂ l₁′) ≡
proj₂ l₂′) ↝⟨ (∃-cong λ _ → inverse $
ignore-propositional-component
(Π-closure ext 1 λ _ →
truncation-is-proposition)) ⟩
(∃ λ (p : R l₁ ≡ R l₂) →
proj₁ (subst (λ R → A ≃ (R × B) × (R → ∥ B ∥))
p
(proj₂ l₁′)) ≡
equiv l₂) ↝⟨ (∃-cong λ p → ≡⇒↝ _ $
cong (λ x → proj₁ x ≡ _) (push-subst-, {y≡z = p} _ _)) ⟩□
(∃ λ (p : R l₁ ≡ R l₂) →
subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) □
where
open Lens
l₁′ = _↔_.to Lens-as-Σ l₁
l₂′ = _↔_.to Lens-as-Σ l₂
-- Equality of lenses is isomorphic to certain pairs (assuming
-- univalence).
equality-characterisation₁ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
(eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂
equality-characterisation₁ {A = A} {B} {l₁} {l₂} univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₀ ⟩
(∃ λ (p : R l₁ ≡ R l₂) →
subst (λ R → A ≃ (R × B)) p (equiv l₁) ≡ equiv l₂) ↝⟨ inverse $ Σ-cong (inverse $ ≡≃≃ univ) (λ _ → F.id) ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
subst (λ R → A ≃ (R × B)) (≃⇒≡ univ eq) (equiv l₁) ≡ equiv l₂) ↝⟨ (∃-cong λ _ → inverse $ ≡⇒↝ _ $ cong (λ p → p ≡ _) $
transport-theorem
(λ R → A ≃ (R × B)) resp
(λ _ → Eq.lift-equality ext (refl _))
univ _ _) ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) → resp eq (equiv l₁) ≡ equiv l₂) □
where
open Lens
resp : X ≃ Y → A ≃ (X × B) → A ≃ (Y × B)
resp {X = X} {Y = Y} X≃Y A≃X×B =
A ↝⟨ A≃X×B ⟩
X × B ↝⟨ X≃Y ×-cong F.id ⟩□
Y × B □
-- Equality of lenses is isomorphic to certain pairs (assuming
-- univalence).
equality-characterisation₂ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡
_≃_.to (equiv l₂) x
equality-characterisation₂ {l₁ = l₁} {l₂} univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ univ ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
(eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂) ↝⟨ (∃-cong λ _ → inverse $ ≃-to-≡↔≡ ext) ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡
_≃_.to (equiv l₂) x) □
where
open Lens
-- Equality of lenses is isomorphic to certain triples (assuming
-- univalence).
equality-characterisation₃ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
(∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x)
×
(∀ x → get l₁ x ≡ get l₂ x)
equality-characterisation₃ {l₁ = l₁} {l₂} univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₂ univ ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → (_≃_.to eq (remainder l₁ x) , get l₁ x) ≡
_≃_.to (equiv l₂) x) ↝⟨ (∃-cong λ _ → ∀-cong ext λ _ → inverse ≡×≡↔≡) ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x
×
get l₁ x ≡ get l₂ x) ↝⟨ (∃-cong λ _ → ΠΣ-comm) ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
(∀ x → _≃_.to eq (remainder l₁ x) ≡ remainder l₂ x)
×
(∀ x → get l₁ x ≡ get l₂ x)) □
where
open Lens
-- Equality of lenses is isomorphic to certain pairs (assuming
-- univalence).
equality-characterisation₄ :
{A : Set a} {B : Set b} {l₁ l₂ : Lens A B} →
let open Lens in
Univalence (a ⊔ b) →
l₁ ≡ l₂
↔
∃ λ (eq : R l₁ ≃ R l₂) →
∀ p → _≃_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡
_≃_.from (equiv l₂) p
equality-characterisation₄ {l₁ = l₁} {l₂} univ =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ univ ⟩
(∃ λ (eq : R l₁ ≃ R l₂) →
(eq ×-cong F.id) F.∘ equiv l₁ ≡ equiv l₂) ↝⟨ (∃-cong λ _ → inverse $ ≃-from-≡↔≡ ext) ⟩□
(∃ λ (eq : R l₁ ≃ R l₂) →
∀ p → _≃_.from (equiv l₁) (_≃_.from eq (proj₁ p) , proj₂ p) ≡
_≃_.from (equiv l₂) p) □
where
open Lens
------------------------------------------------------------------------
-- More lens equalities
-- If the forward direction of an equivalence is Lens.get l, then the
-- setter of l can be expressed using the other direction of the
-- equivalence.
from≡set :
∀ (l : Lens A B) is-equiv →
let open Lens
A≃B = Eq.⟨ get l , is-equiv ⟩
in
∀ a b → _≃_.from A≃B b ≡ set l a b
from≡set l is-equiv a b =
_≃_.to-from Eq.⟨ get , is-equiv ⟩ (
get (set a b) ≡⟨ get-set _ _ ⟩∎
b ∎)
where
open Lens l
-- If two lenses have equal setters, then they also have equal
-- getters.
getters-equal-if-setters-equal :
let open Lens in
(l₁ l₂ : Lens A B) →
set l₁ ≡ set l₂ →
get l₁ ≡ get l₂
getters-equal-if-setters-equal l₁ l₂ setters-equal = ⟨ext⟩ λ a →
get l₁ a ≡⟨ cong (get l₁) $ sym $ set-get l₂ _ ⟩
get l₁ (set l₂ a (get l₂ a)) ≡⟨ cong (λ f → get l₁ (f a (get l₂ a))) $ sym setters-equal ⟩
get l₁ (set l₁ a (get l₂ a)) ≡⟨ get-set l₁ _ _ ⟩∎
get l₂ a ∎
where
open Lens
-- A generalisation of lenses-equal-if-setters-equal (which is defined
-- below).
lenses-equal-if-setters-equal′ :
let open Lens in
{A : Set a} {B : Set b}
(univ : Univalence (a ⊔ b))
(l₁ l₂ : Lens A B)
(f : R l₁ → R l₂) →
(B → ∀ r →
∃ λ b′ → remainder l₂ (_≃_.from (equiv l₁) (r , b′)) ≡ f r) →
(∀ a → f (remainder l₁ a) ≡ remainder l₂ a) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal′
{A = A} {B = B} univ l₁ l₂
f ∃≡f f-remainder≡remainder setters-equal =
_↔_.from (equality-characterisation₃ univ)
( R≃R
, f-remainder≡remainder
, ext⁻¹ (getters-equal-if-setters-equal l₁ l₂ setters-equal)
)
where
open Lens
open _≃_
BR≃BR =
B × R l₁ ↔⟨ ×-comm ⟩
R l₁ × B ↝⟨ inverse (equiv l₁) ⟩
A ↝⟨ equiv l₂ ⟩
R l₂ × B ↔⟨ ×-comm ⟩□
B × R l₂ □
to-BR≃BR :
∀ b b′ r →
to BR≃BR (b , r) ≡ (b , remainder l₂ (from (equiv l₁) (r , b′)))
to-BR≃BR b b′ r =
swap (to (equiv l₂) (from (equiv l₁) (swap (b , r)))) ≡⟨ cong swap lemma ⟩
swap (swap (b , remainder l₂ (from (equiv l₁) (r , b′)))) ≡⟨⟩
b , remainder l₂ (from (equiv l₁) (r , b′)) ∎
where
lemma =
to (equiv l₂) (from (equiv l₁) (swap (b , r))) ≡⟨⟩
to (equiv l₂) (from (equiv l₁) (r , b)) ≡⟨ cong (λ r → to (equiv l₂) (from (equiv l₁) (proj₁ r , b))) $ sym $
right-inverse-of (equiv l₁) _ ⟩
to (equiv l₂) (from (equiv l₁)
(proj₁ (to (equiv l₁) (from (equiv l₁) (r , b′))) , b)) ≡⟨⟩
to (equiv l₂) (set l₁ (from (equiv l₁) (r , b′)) b) ≡⟨ cong (to (equiv l₂)) $ ext⁻¹ (ext⁻¹ setters-equal _) _ ⟩
to (equiv l₂) (set l₂ (from (equiv l₁) (r , b′)) b) ≡⟨⟩
to (equiv l₂) (from (equiv l₂)
(remainder l₂ (from (equiv l₁) (r , b′)) , b)) ≡⟨ right-inverse-of (equiv l₂) _ ⟩
remainder l₂ (from (equiv l₁) (r , b′)) , b ≡⟨⟩
swap (b , remainder l₂ (from (equiv l₁) (r , b′))) ∎
id-f≃ : Eq.Is-equivalence (Σ-map P.id f)
id-f≃ = Eq.respects-extensional-equality
(λ (b , r) →
let b′ , ≡fr = ∃≡f b r in
to BR≃BR (b , r) ≡⟨ to-BR≃BR _ _ _ ⟩
b , remainder l₂ (from (equiv l₁) (r , b′)) ≡⟨ cong (b ,_) ≡fr ⟩
b , f r ≡⟨⟩
Σ-map P.id f (b , r) ∎)
(is-equivalence BR≃BR)
f≃ : Eq.Is-equivalence f
f≃ r =
Trunc.rec
(H-level-propositional ext 0)
(λ b → Eq.drop-Σ-map-id _ id-f≃ b r)
(inhabited l₂ r)
R≃R : R l₁ ≃ R l₂
R≃R = Eq.⟨ f , f≃ ⟩
-- If the codomain of a lens is inhabited when it is merely inhabited
-- and the remainder type is inhabited, then this lens is equal to
-- another lens if their setters are equal (assuming univalence).
lenses-equal-if-setters-equal :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l₁ l₂ : Lens A B) →
(Lens.R l₁ → ∥ B ∥ → B) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal {B = B} univ l₁ l₂ inh′ setters-equal =
lenses-equal-if-setters-equal′
univ l₁ l₂ f
(λ _ r →
inh r
, (remainder l₂ (_≃_.from (equiv l₁) (r , inh r)) ≡⟨⟩
f r ∎))
(λ a →
f (remainder l₁ a) ≡⟨⟩
remainder l₂ (set l₁ a (inh (remainder l₁ a))) ≡⟨ cong (remainder l₂) $ ext⁻¹ (ext⁻¹ setters-equal _) _ ⟩
remainder l₂ (set l₂ a (inh (remainder l₁ a))) ≡⟨ remainder-set l₂ _ _ ⟩∎
remainder l₂ a ∎)
setters-equal
where
open Lens
inh : Lens.R l₁ → B
inh r = inh′ r (inhabited l₁ r)
f : R l₁ → R l₂
f r = remainder l₂ (_≃_.from (equiv l₁) (r , inh r))
-- If a lens has a propositional remainder type, then this lens is
-- equal to another lens if their setters are equal (assuming
-- univalence).
lenses-equal-if-setters-equal-and-remainder-propositional :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l₁ l₂ : Lens A B) →
Is-proposition (Lens.R l₂) →
Lens.set l₁ ≡ Lens.set l₂ →
l₁ ≡ l₂
lenses-equal-if-setters-equal-and-remainder-propositional
univ l₁ l₂ R₂-prop =
lenses-equal-if-setters-equal′
univ l₁ l₂ f
(λ b r →
b
, (remainder l₂ (_≃_.from (equiv l₁) (r , b)) ≡⟨ R₂-prop _ _ ⟩∎
f r ∎))
(λ a →
f (remainder l₁ a) ≡⟨ R₂-prop _ _ ⟩
remainder l₂ a ∎)
where
open Lens
f : R l₁ → R l₂
f r =
Trunc.rec R₂-prop
(λ b → remainder l₂ (_≃_.from (equiv l₁) (r , b)))
(inhabited l₁ r)
-- The functions ≃→lens and ≃→lens′ are pointwise equal (when
-- applicable, assuming univalence).
≃→lens≡≃→lens′ :
{A B : Set a} →
Univalence a →
(A≃B : A ≃ B) → ≃→lens A≃B ≡ ≃→lens′ A≃B
≃→lens≡≃→lens′ {B = B} univ A≃B =
_↔_.from (equality-characterisation₃ univ)
( (∥ ↑ _ B ∥ ↔⟨ ∥∥-cong Bij.↑↔ ⟩□
∥ B ∥ □)
, (λ _ → refl _)
, (λ _ → refl _)
)
-- If the getter of a lens is an equivalence, then the lens formed
-- using the equivalence (using ≃→lens) is equal to the lens (assuming
-- univalence).
get-equivalence→≡≃→lens :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
(eq : Is-equivalence (Lens.get l)) →
l ≡ ≃→lens Eq.⟨ Lens.get l , eq ⟩
get-equivalence→≡≃→lens {A = A} {B = B} univ l eq =
lenses-equal-if-setters-equal-and-remainder-propositional
univ l (≃→lens Eq.⟨ Lens.get l , eq ⟩)
truncation-is-proposition
(⟨ext⟩ λ a → ⟨ext⟩ λ b →
set l a b ≡⟨ sym $ from≡set l eq a b ⟩
_≃_.from A≃B b ≡⟨⟩
set (≃→lens A≃B) a b ∎)
where
open Lens
A≃B : A ≃ B
A≃B = Eq.⟨ _ , eq ⟩
-- A variant of get-equivalence→≡≃→lens.
get-equivalence→≡≃→lens′ :
{A B : Set a} →
Univalence a →
(l : Lens A B) →
(eq : Is-equivalence (Lens.get l)) →
l ≡ ≃→lens′ Eq.⟨ Lens.get l , eq ⟩
get-equivalence→≡≃→lens′ {A = A} {B = B} univ l eq =
l ≡⟨ get-equivalence→≡≃→lens univ _ _ ⟩
≃→lens A≃B ≡⟨ ≃→lens≡≃→lens′ univ _ ⟩∎
≃→lens′ A≃B ∎
where
A≃B = Eq.⟨ Lens.get l , eq ⟩
------------------------------------------------------------------------
-- Some lens isomorphisms
-- A generalised variant of Lens preserves bijections.
Lens-cong′ :
A₁ ↔ A₂ → B₁ ↔ B₂ →
(∃ λ (R : Set r) → A₁ ≃ (R × B₁) × (R → ∥ B₁ ∥)) ↔
(∃ λ (R : Set r) → A₂ ≃ (R × B₂) × (R → ∥ B₂ ∥))
Lens-cong′ A₁↔A₂ B₁↔B₂ =
∃-cong λ _ →
Eq.≃-preserves-bijections ext A₁↔A₂ (F.id ×-cong B₁↔B₂)
×-cong
→-cong ext F.id (∥∥-cong B₁↔B₂)
-- Lens preserves level-preserving bijections.
Lens-cong :
{A₁ A₂ : Set a} {B₁ B₂ : Set b} →
A₁ ↔ A₂ → B₁ ↔ B₂ →
Lens A₁ B₁ ↔ Lens A₂ B₂
Lens-cong {A₁ = A₁} {A₂ = A₂} {B₁ = B₁} {B₂ = B₂} A₁↔A₂ B₁↔B₂ =
Lens A₁ B₁ ↝⟨ Lens-as-Σ ⟩
(∃ λ R → A₁ ≃ (R × B₁) × (R → ∥ B₁ ∥)) ↝⟨ Lens-cong′ A₁↔A₂ B₁↔B₂ ⟩
(∃ λ R → A₂ ≃ (R × B₂) × (R → ∥ B₂ ∥)) ↝⟨ inverse Lens-as-Σ ⟩□
Lens A₂ B₂ □
-- If B is a proposition, then Lens A B is isomorphic to A → B
-- (assuming univalence).
lens-to-proposition↔get :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition B →
Lens A B ↔ (A → B)
lens-to-proposition↔get {b = b} {A = A} {B = B} univ B-prop =
Lens A B ↝⟨ Lens-as-Σ ⟩
(∃ λ R → A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
∥∥↔ B-prop) ⟩
(∃ λ R → A ≃ (R × B) × (R → B)) ↝⟨ (∃-cong λ _ →
×-cong₁ λ R→B →
Eq.≃-preserves-bijections ext F.id $
drop-⊤-right λ r →
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible B-prop (R→B r)) ⟩
(∃ λ R → A ≃ R × (R → B)) ↔⟨ (∃-cong λ _ →
∃-cong λ A≃R →
→-cong {k = equivalence} ext (inverse A≃R) F.id) ⟩
(∃ λ R → A ≃ R × (A → B)) ↝⟨ Σ-assoc ⟩
(∃ λ R → A ≃ R) × (A → B) ↝⟨ (drop-⊤-left-× λ _ → other-singleton-with-≃-↔-⊤ {b = b} ext univ) ⟩□
(A → B) □
_ :
{A : Set a} {B : Set b}
(univ : Univalence (a ⊔ b))
(prop : Is-proposition B)
(l : Lens A B) →
_↔_.to (lens-to-proposition↔get univ prop) l ≡
rec prop P.id ⊚ Lens.inhabited l ⊚ Lens.remainder l
_ = λ _ _ _ → refl _
-- A variant of the previous result.
lens-to-proposition≃get :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition B →
Lens A B ≃ (A → B)
lens-to-proposition≃get {b = b} {A = A} {B = B} univ prop = Eq.↔→≃
get
from
refl
(λ l →
let lemma =
↑ b A ↔⟨ Bij.↑↔ ⟩
A ↝⟨ equiv l ⟩
R l × B ↔⟨ (drop-⊤-right λ r → _⇔_.to contractible⇔↔⊤ $
Trunc.rec
(Contractible-propositional ext)
(propositional⇒inhabited⇒contractible prop)
(inhabited l r)) ⟩□
R l □
in
_↔_.from (equality-characterisation₂ univ)
(lemma , λ _ → refl _))
where
open Lens
from = λ get → record
{ R = ↑ b A
; equiv = A ↔⟨ inverse Bij.↑↔ ⟩
↑ b A ↔⟨ (inverse $ drop-⊤-right {k = bijection} λ (lift a) →
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible prop (get a)) ⟩□
↑ b A × B □
; inhabited = ∣_∣ ⊚ get ⊚ lower
}
_ :
{A : Set a} {B : Set b}
(univ : Univalence (a ⊔ b))
(prop : Is-proposition B)
(l : Lens A B) →
_≃_.to (lens-to-proposition≃get univ prop) l ≡ Lens.get l
_ = λ _ _ _ → refl _
-- If B is contractible, then Lens A B is isomorphic to ⊤ (assuming
-- univalence).
lens-to-contractible↔⊤ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Contractible B →
Lens A B ↔ ⊤
lens-to-contractible↔⊤ {A = A} {B} univ cB =
Lens A B ↝⟨ lens-to-proposition↔get univ (mono₁ 0 cB) ⟩
(A → B) ↝⟨ →-cong ext F.id $ _⇔_.to contractible⇔↔⊤ cB ⟩
(A → ⊤) ↝⟨ →-right-zero ⟩□
⊤ □
-- Lens A ⊥ is isomorphic to ¬ A (assuming univalence).
lens-to-⊥↔¬ :
{A : Set a} →
Univalence (a ⊔ b) →
Lens A (⊥ {ℓ = b}) ↔ ¬ A
lens-to-⊥↔¬ {A = A} univ =
Lens A ⊥ ↝⟨ lens-to-proposition↔get univ ⊥-propositional ⟩
(A → ⊥) ↝⟨ inverse $ ¬↔→⊥ ext ⟩□
¬ A □
-- If A is contractible, then Lens A B is isomorphic to Contractible B
-- (assuming univalence).
lens-from-contractible↔codomain-contractible :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Contractible A →
Lens A B ↔ Contractible B
lens-from-contractible↔codomain-contractible {A = A} {B} univ cA =
Lens A B ↝⟨ Lens-as-Σ ⟩
(∃ λ R → A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ →
Eq.≃-preserves-bijections ext (_⇔_.to contractible⇔↔⊤ cA) F.id
×-cong
F.id) ⟩
(∃ λ R → ⊤ ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → Eq.inverse-isomorphism ext ×-cong F.id) ⟩
(∃ λ R → (R × B) ≃ ⊤ × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → inverse (contractible↔≃⊤ ext) ×-cong F.id) ⟩
(∃ λ R → Contractible (R × B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → Contractible-commutes-with-× ext ×-cong F.id) ⟩
(∃ λ R → (Contractible R × Contractible B) × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → inverse ×-assoc) ⟩
(∃ λ R → Contractible R × Contractible B × (R → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → ∃-cong λ cR →
F.id
×-cong
→-cong ext (_⇔_.to contractible⇔↔⊤ cR) F.id) ⟩
(∃ λ R → Contractible R × Contractible B × (⊤ → ∥ B ∥)) ↝⟨ ∃-cong (λ _ → F.id ×-cong F.id ×-cong Π-left-identity) ⟩
(∃ λ R → Contractible R × Contractible B × ∥ B ∥) ↝⟨ ∃-cong (λ _ → ×-comm) ⟩
(∃ λ R → (Contractible B × ∥ B ∥) × Contractible R) ↝⟨ ∃-comm ⟩
(Contractible B × ∥ B ∥) × (∃ λ R → Contractible R) ↝⟨ drop-⊤-right (λ _ → ∃Contractible↔⊤ ext univ) ⟩
Contractible B × ∥ B ∥ ↝⟨ drop-⊤-right (λ cB → inhabited⇒∥∥↔⊤ ∣ proj₁ cB ∣) ⟩□
Contractible B □
-- Lens ⊥ B is isomorphic to the unit type (assuming univalence).
lens-from-⊥↔⊤ :
{B : Set b} →
Univalence (a ⊔ b) →
Lens (⊥ {ℓ = a}) B ↔ ⊤
lens-from-⊥↔⊤ {B = B} univ =
_⇔_.to contractible⇔↔⊤ $
isomorphism-to-lens
(⊥ ↝⟨ inverse ×-left-zero ⟩□
⊥ × B □) ,
λ l → _↔_.from (equality-characterisation₂ univ)
( (⊥ × ∥ B ∥ ↔⟨ ×-left-zero ⟩
⊥₀ ↔⟨ lemma l ⟩□
R l □)
, λ x → ⊥-elim x
)
where
open Lens
lemma : (l : Lens ⊥ B) → ⊥₀ ↔ R l
lemma l = record
{ surjection = record
{ logical-equivalence = record
{ to = ⊥-elim
; from = whatever
}
; right-inverse-of = whatever
}
; left-inverse-of = λ x → ⊥-elim x
}
where
whatever : ∀ {ℓ} {Whatever : R l → Set ℓ} → (r : R l) → Whatever r
whatever r = ⊥-elim {ℓ = lzero} $
rec ⊥-propositional
(λ b → ⊥-elim (_≃_.from (equiv l) (r , b)))
(inhabited l r)
-- There is an equivalence between A ≃ B and
-- ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l) (assuming
-- univalence).
--
-- See also ≃≃≊ below.
≃-≃-Σ-Lens-Is-equivalence-get :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
(A ≃ B) ≃ (∃ λ (l : Lens A B) → Is-equivalence (Lens.get l))
≃-≃-Σ-Lens-Is-equivalence-get univ = Eq.↔→≃
(λ A≃B → ≃→lens A≃B , _≃_.is-equivalence A≃B)
(λ (l , eq) → Eq.⟨ Lens.get l , eq ⟩)
(λ (l , eq) → Σ-≡,≡→≡
(sym $ get-equivalence→≡≃→lens univ l eq)
(Eq.propositional ext _ _ _))
(λ _ → Eq.lift-equality ext (refl _))
-- The right-to-left direction of ≃-≃-Σ-Lens-Is-equivalence-get
-- returns the lens's getter (and some proof).
to-from-≃-≃-Σ-Lens-Is-equivalence-get≡get :
{A : Set a} {B : Set b} →
(univ : Univalence (a ⊔ b))
(p@(l , _) : ∃ λ (l : Lens A B) → Is-equivalence (Lens.get l)) →
_≃_.to (_≃_.from (≃-≃-Σ-Lens-Is-equivalence-get univ) p) ≡
Lens.get l
to-from-≃-≃-Σ-Lens-Is-equivalence-get≡get _ _ = refl _
------------------------------------------------------------------------
-- Results relating different kinds of lenses
-- In general there is no split surjection from Lens A B to
-- Traditional.Lens A B (assuming univalence).
¬Lens↠Traditional-lens :
Univalence lzero →
Univalence a →
∃ λ (A : Set a) →
¬ (Lens A ⊤ ↠ Traditional.Lens A ⊤)
¬Lens↠Traditional-lens univ₀ univ =
let A = _ in
A ,
(λ surj → $⟨ _⇔_.from contractible⇔↔⊤ (lens-to-contractible↔⊤ univ ⊤-contractible) ⟩
Contractible (Lens A ⊤) ↝⟨ H-level.respects-surjection surj 0 ⟩
Contractible (Traditional.Lens A ⊤) ↝⟨ mono₁ 0 ⟩
Is-proposition (Traditional.Lens A ⊤) ↝⟨ proj₂ $ Traditional.¬-lens-to-⊤-propositional univ₀ ⟩□
⊥ □)
-- Some lemmas used in Lens↠Traditional-lens and Lens↔Traditional-lens
-- below.
private
module Lens↔Traditional-lens
{A : Set a} {B : Set b}
(A-set : Is-set A)
where
from : Block "conversion" → Traditional.Lens A B → Lens A B
from ⊠ l = isomorphism-to-lens
{R = ∃ λ (f : B → A) → ∀ b b′ → set (f b) b′ ≡ f b′}
(record
{ surjection = record
{ logical-equivalence = record
{ to = λ a → (set a , set-set a) , get a
; from = λ { ((f , _) , b) → f b }
}
; right-inverse-of = λ { ((f , h) , b) →
let
irr = {p q : ∀ b b′ → set (f b) b′ ≡ f b′} → p ≡ q
irr =
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
A-set) _ _
lemma =
get (f b) ≡⟨ cong get (sym (h b b)) ⟩
get (set (f b) b) ≡⟨ get-set (f b) b ⟩∎
b ∎
in
(set (f b) , set-set (f b)) , get (f b) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ (⟨ext⟩ (h b)) irr) lemma ⟩∎
(f , h ) , b ∎ }
}
; left-inverse-of = λ a →
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
})
where
open Traditional.Lens l
to∘from : ∀ bc l → Lens.traditional-lens (from bc l) ≡ l
to∘from ⊠ l = _↔_.from Traditional.equality-characterisation₁
( refl _
, refl _
, (λ a _ → B-set a _ _)
, (λ _ → A-set _ _)
, (λ _ _ _ → A-set _ _)
)
where
open Traditional.Lens l
B-set : A → Is-set B
B-set a =
Traditional.h-level-respects-lens-from-inhabited 2 l a A-set
from∘to :
Univalence (a ⊔ b) →
∀ bc l → from bc (Lens.traditional-lens l) ≡ l
from∘to univ ⊠ l′ =
_↔_.from (equality-characterisation₄ univ)
( lemma
, λ p →
_≃_.from l (subst (λ _ → R) (refl _) (proj₁ p) , proj₂ p) ≡⟨ cong (λ r → _≃_.from l (r , proj₂ p)) $ subst-refl _ _ ⟩∎
_≃_.from l p ∎
)
where
open Lens l′ renaming (equiv to l)
B-set : (B → R) → ∥ B ∥ → Is-set B
B-set f =
rec (H-level-propositional ext 2)
(λ b → proj₂-closure (f b) 2 $
H-level.respects-surjection
(_≃_.surjection l) 2 A-set)
R-set : ∥ B ∥ → Is-set R
R-set =
rec (H-level-propositional ext 2)
(λ b → proj₁-closure (const b) 2 $
H-level.respects-surjection
(_≃_.surjection l) 2 A-set)
lemma′ : (∥ B ∥ × (∥ B ∥ → R)) ↔ R
lemma′ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ { (∥b∥ , f) → f ∥b∥ }
; from = λ r → inhabited r , λ _ → r
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (∥b∥ , f) →
curry (_↔_.to ≡×≡↔≡)
(truncation-is-proposition _ _)
(⟨ext⟩ λ ∥b∥′ →
f ∥b∥ ≡⟨ cong f (truncation-is-proposition _ _) ⟩∎
f ∥b∥′ ∎) }
}
lemma =
(∃ λ (f : B → A) → ∀ b b′ →
_≃_.from l (proj₁ (_≃_.to l (f b)) , b′) ≡ f b′) ×
∥ B ∥ ↔⟨ ×-comm ⟩
(∥ B ∥ ×
∃ λ (f : B → A) → ∀ b b′ →
_≃_.from l (proj₁ (_≃_.to l (f b)) , b′) ≡ f b′) ↝⟨ (∃-cong λ _ →
Σ-cong (→-cong ext F.id l) λ f →
∀-cong ext λ b → ∀-cong ext λ b′ →
≡⇒↝ _ (cong (_≃_.from l (proj₁ (_≃_.to l (f b)) , b′) ≡_)
(sym $ _≃_.left-inverse-of l _))) ⟩
(∥ B ∥ ×
∃ λ (f : B → R × B) → ∀ b b′ →
_≃_.from l (proj₁ (f b) , b′) ≡ _≃_.from l (f b′)) ↝⟨ ∃-cong (λ _ → ∃-cong λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
Eq.≃-≡ (inverse l)) ⟩
(∥ B ∥ ×
∃ λ (f : B → R × B) → ∀ b b′ → (proj₁ (f b) , b′) ≡ f b′) ↔⟨ (∃-cong λ _ → Σ-cong ΠΣ-comm λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
inverse $ ≡×≡↔≡) ⟩
(∥ B ∥ ×
∃ λ (p : (B → R) × (B → B)) →
∀ b b′ → proj₁ p b ≡ proj₁ p b′ × b′ ≡ proj₂ p b′) ↔⟨ (∃-cong λ _ → inverse Σ-assoc) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
∀ b b′ → f b ≡ f b′ × b′ ≡ g b′) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ∀-cong ext λ _ →
ΠΣ-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
∀ b → (∀ b′ → f b ≡ f b′) × (∀ b′ → b′ ≡ g b′)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ → ΠΣ-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → ∃ λ (g : B → B) →
Constant f × (B → ∀ b → b ≡ g b)) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-comm) ⟩
(∥ B ∥ ×
∃ λ (f : B → R) → Constant f ×
∃ λ (g : B → B) → B → ∀ b → b ≡ g b) ↔⟨ (∃-cong λ _ → Σ-assoc) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → B → ∀ b → b ≡ g b)) ↔⟨ (∃-cong λ ∥b∥ → ∃-cong $ uncurry λ f _ → ∃-cong λ _ → inverse $
→-intro ext (λ _ → B-set f ∥b∥)) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → ∀ b → b ≡ g b)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → ∃-cong λ _ →
Eq.extensionality-isomorphism ext) ⟩
(∥ B ∥ ×
(∃ λ (f : B → R) → Constant f) ×
(∃ λ (g : B → B) → F.id ≡ g)) ↔⟨ (∃-cong λ _ → drop-⊤-right λ _ →
_⇔_.to contractible⇔↔⊤ $
other-singleton-contractible _) ⟩
(∥ B ∥ × ∃ λ (f : B → R) → Constant f) ↝⟨ (∃-cong λ ∥b∥ → constant-function≃∥inhabited∥⇒inhabited (R-set ∥b∥)) ⟩
(∥ B ∥ × (∥ B ∥ → R)) ↔⟨ lemma′ ⟩□
R □
iso :
Block "conversion" →
Univalence (a ⊔ b) →
Lens A B ↔ Traditional.Lens A B
iso bc univ = record
{ surjection = record
{ logical-equivalence = record { from = from bc }
; right-inverse-of = to∘from bc
}
; left-inverse-of = from∘to univ bc
}
-- If the domain A is a set, then there is a split surjection from
-- Lens A B to Traditional.Lens A B.
Lens↠Traditional-lens :
Block "conversion" →
Is-set A →
Lens A B ↠ Traditional.Lens A B
Lens↠Traditional-lens {A = A} {B = B} bc A-set = record
{ logical-equivalence = record
{ to = Lens.traditional-lens
; from = Lens↔Traditional-lens.from A-set bc
}
; right-inverse-of = Lens↔Traditional-lens.to∘from A-set bc
}
-- The split surjection above preserves getters and setters.
Lens↠Traditional-lens-preserves-getters-and-setters :
{A : Set a}
(b : Block "conversion")
(s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_↠_.logical-equivalence (Lens↠Traditional-lens b s))
Lens↠Traditional-lens-preserves-getters-and-setters ⊠ _ =
(λ _ → refl _ , refl _) , (λ _ → refl _ , refl _)
-- If the domain A is a set, then Traditional.Lens A B and Lens A B
-- are isomorphic (assuming univalence).
Lens↔Traditional-lens :
{A : Set a} {B : Set b} →
Block "conversion" →
Univalence (a ⊔ b) →
Is-set A →
Lens A B ↔ Traditional.Lens A B
Lens↔Traditional-lens bc univ A-set =
Lens↔Traditional-lens.iso A-set bc univ
-- The isomorphism preserves getters and setters.
Lens↔Traditional-lens-preserves-getters-and-setters :
{A : Set a} {B : Set b}
(bc : Block "conversion")
(univ : Univalence (a ⊔ b))
(s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_↔_.logical-equivalence (Lens↔Traditional-lens bc univ s))
Lens↔Traditional-lens-preserves-getters-and-setters bc _ =
Lens↠Traditional-lens-preserves-getters-and-setters bc
-- If the codomain B is an inhabited set, then Lens A B and
-- Traditional.Lens A B are logically equivalent.
--
-- This definition is inspired by the statement of Corollary 13 from
-- "Algebras and Update Strategies" by Johnson, Rosebrugh and Wood.
--
-- See also Lens.Non-dependent.Equivalent-preimages.coherent↠higher.
Lens⇔Traditional-lens :
Is-set B →
B →
Lens A B ⇔ Traditional.Lens A B
Lens⇔Traditional-lens {B = B} {A = A} B-set b₀ = record
{ to = Lens.traditional-lens
; from = from
}
where
from : Traditional.Lens A B → Lens A B
from l = isomorphism-to-lens
{R = ∃ λ (a : A) → get a ≡ b₀}
(record
{ surjection = record
{ logical-equivalence = record
{ to = λ a → (set a b₀ , get-set a b₀) , get a
; from = λ { ((a , _) , b) → set a b }
}
; right-inverse-of = λ { ((a , h) , b) →
let
lemma =
set (set a b) b₀ ≡⟨ set-set a b b₀ ⟩
set a b₀ ≡⟨ cong (set a) (sym h) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
in
((set (set a b) b₀ , get-set (set a b) b₀) , get (set a b)) ≡⟨ cong₂ _,_ (Σ-≡,≡→≡ lemma (B-set _ _)) (get-set a b) ⟩∎
((a , h ) , b ) ∎
}
}
; left-inverse-of = λ a →
set (set a b₀) (get a) ≡⟨ set-set a b₀ (get a) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎
})
where
open Traditional.Lens l
-- The logical equivalence preserves getters and setters.
Lens⇔Traditional-lens-preserves-getters-and-setters :
{B : Set b}
(s : Is-set B)
(b₀ : B) →
Preserves-getters-and-setters-⇔ A B (Lens⇔Traditional-lens s b₀)
Lens⇔Traditional-lens-preserves-getters-and-setters _ b₀ =
(λ _ → refl _ , refl _)
, (λ l → refl _
, ⟨ext⟩ λ a → ⟨ext⟩ λ b →
set l (set l a b₀) b ≡⟨ set-set l _ _ _ ⟩∎
set l a b ∎)
where
open Traditional.Lens
------------------------------------------------------------------------
-- Some results related to h-levels
-- If the domain of a lens is inhabited and has h-level n, then the
-- codomain also has h-level n.
h-level-respects-lens-from-inhabited :
Lens A B → A → H-level n A → H-level n B
h-level-respects-lens-from-inhabited {A = A} {B = B} {n = n} l a =
H-level n A ↝⟨ H-level.respects-surjection (_≃_.surjection equiv) n ⟩
H-level n (R × B) ↝⟨ proj₂-closure (remainder a) n ⟩□
H-level n B □
where
open Lens l
-- This is not necessarily true for arbitrary domains (assuming
-- univalence).
¬-h-level-respects-lens :
Univalence (a ⊔ b) →
¬ (∀ n {A : Set a} {B : Set b} →
Lens A B → H-level n A → H-level n B)
¬-h-level-respects-lens univ resp =
$⟨ ⊥-propositional ⟩
Is-proposition ⊥ ↝⟨ resp 1 (_↔_.from (lens-from-⊥↔⊤ univ) _) ⟩
Is-proposition (↑ _ Bool) ↝⟨ ↑⁻¹-closure 1 ⟩
Is-proposition Bool ↝⟨ ¬-Bool-propositional ⟩□
⊥₀ □
-- In fact, there is a lens with a proposition as its domain and a
-- non-set as its codomain (assuming univalence).
--
-- (The lemma does not actually use the univalence argument, but
-- univalence is used by Circle.¬-𝕊¹-set.)
lens-from-proposition-to-non-set :
Univalence (# 0) →
∃ λ (A : Set a) → ∃ λ (B : Set b) →
Lens A B × Is-proposition A × ¬ Is-set B
lens-from-proposition-to-non-set {b = b} _ =
⊥
, ↑ b 𝕊¹
, record
{ R = ⊥
; equiv = ⊥ ↔⟨ inverse ×-left-zero ⟩□
⊥ × ↑ _ 𝕊¹ □
; inhabited = ⊥-elim
}
, ⊥-propositional
, Circle.¬-𝕊¹-set ⊚
H-level.respects-surjection (_↔_.surjection Bij.↑↔) 2
-- Lenses with contractible domains have contractible codomains.
contractible-to-contractible :
Lens A B → Contractible A → Contractible B
contractible-to-contractible l c =
h-level-respects-lens-from-inhabited l (proj₁ c) c
-- If the domain type of a lens is contractible, then the remainder
-- type is also contractible.
domain-contractible⇒remainder-contractible :
(l : Lens A B) → Contractible A → Contractible (Lens.R l)
domain-contractible⇒remainder-contractible {A = A} {B = B} l =
Contractible A ↔⟨ H-level-cong {k₂ = equivalence} ext 0 equiv ⟩
Contractible (R × B) ↔⟨ Contractible-commutes-with-× {k = bijection} ext ⟩
Contractible R × Contractible B ↝⟨ proj₁ ⟩□
Contractible R □
where
open Lens l
-- If the domain type of a lens has h-level n, then the remainder type
-- also has h-level n.
remainder-has-same-h-level-as-domain :
(l : Lens A B) → ∀ n → H-level n A → H-level n (Lens.R l)
remainder-has-same-h-level-as-domain l zero =
domain-contractible⇒remainder-contractible l
remainder-has-same-h-level-as-domain {A = A} {B = B} l (suc n) h =
[inhabited⇒+]⇒+ n λ r →
$⟨ h ⟩
H-level (1 + n) A ↝⟨ H-level.respects-surjection (_≃_.surjection equiv) (1 + n) ⟩
H-level (1 + n) (R × B) ↝⟨ rec (Π-closure ext 1 λ _ → H-level-propositional ext (1 + n))
(λ b → proj₁-closure (λ _ → b) (1 + n))
(inhabited r) ⟩□
H-level (1 + n) R □
where
open Lens l
-- If the getter function is an equivalence, then the remainder type
-- is propositional.
get-equivalence→remainder-propositional :
(l : Lens A B) →
Is-equivalence (Lens.get l) →
Is-proposition (Lens.R l)
get-equivalence→remainder-propositional l is-equiv =
[inhabited⇒+]⇒+ 0 λ r →
Trunc.rec
(H-level-propositional ext 1)
(λ b r₁ r₂ →
r₁ ≡⟨ lemma _ _ ⟩
remainder (from A≃B b) ≡⟨ sym $ lemma _ _ ⟩∎
r₂ ∎)
(inhabited r)
where
open _≃_
open Lens l
A≃B = Eq.⟨ _ , is-equiv ⟩
lemma : ∀ b r → r ≡ remainder (from A≃B b)
lemma b r =
r ≡⟨ cong proj₁ $ sym $ right-inverse-of equiv _ ⟩
proj₁ (to equiv (from equiv (r , b))) ≡⟨ cong (proj₁ ⊚ to equiv) $ sym $ left-inverse-of A≃B _ ⟩
proj₁ (to equiv (from A≃B (to A≃B (from equiv (r , b))))) ≡⟨⟩
remainder (from A≃B (proj₂ (to equiv (from equiv (r , b))))) ≡⟨ cong (remainder ⊚ from A≃B ⊚ proj₂) $ right-inverse-of equiv _ ⟩∎
remainder (from A≃B b) ∎
-- If the getter function is pointwise equal to the identity
-- function, then the remainder type is propositional.
get≡id→remainder-propositional :
(l : Lens A A) →
(∀ a → Lens.get l a ≡ a) →
Is-proposition (Lens.R l)
get≡id→remainder-propositional l =
(∀ a → Lens.get l a ≡ a) ↝⟨ (λ hyp → Eq.respects-extensional-equality (sym ⊚ hyp) (_≃_.is-equivalence F.id)) ⟩
Is-equivalence (Lens.get l) ↝⟨ get-equivalence→remainder-propositional l ⟩□
Is-proposition (Lens.R l) □
-- It is not necessarily the case that contractibility of A implies
-- contractibility of Lens A B (assuming univalence).
¬-Contractible-closed-domain :
∀ {a b} →
Univalence (a ⊔ b) →
¬ ({A : Set a} {B : Set b} →
Contractible A → Contractible (Lens A B))
¬-Contractible-closed-domain univ closure =
$⟨ ↑⊤-contractible ⟩
Contractible (↑ _ ⊤) ↝⟨ closure ⟩
Contractible (Lens (↑ _ ⊤) ⊥) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ lens-from-contractible↔codomain-contractible univ ↑⊤-contractible)
0 ⟩
Contractible (Contractible ⊥) ↝⟨ proj₁ ⟩
Contractible ⊥ ↝⟨ proj₁ ⟩
⊥ ↝⟨ ⊥-elim ⟩□
⊥₀ □
where
↑⊤-contractible = ↑-closure 0 ⊤-contractible
-- Contractible is closed under Lens A (assuming univalence).
Contractible-closed-codomain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Contractible B → Contractible (Lens A B)
Contractible-closed-codomain {A = A} {B} univ cB =
$⟨ lens-to-contractible↔⊤ univ cB ⟩
Lens A B ↔ ⊤ ↝⟨ _⇔_.from contractible⇔↔⊤ ⟩□
Contractible (Lens A B) □
-- If B is a proposition, then Lens A B is also a proposition
-- (assuming univalence).
Is-proposition-closed-codomain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition B → Is-proposition (Lens A B)
Is-proposition-closed-codomain {A = A} {B} univ B-prop =
$⟨ Π-closure ext 1 (λ _ → B-prop) ⟩
Is-proposition (A → B) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse $ lens-to-proposition↔get univ B-prop)
1 ⟩□
Is-proposition (Lens A B) □
private
-- If A has h-level 1 + n and equivalence between certain remainder
-- types has h-level n, then Lens A B has h-level 1 + n (assuming
-- univalence).
domain-1+-remainder-equivalence-0+⇒lens-1+ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
∀ n →
H-level (1 + n) A →
((l₁ l₂ : Lens A B) →
H-level n (Lens.R l₁ ≃ Lens.R l₂)) →
H-level (1 + n) (Lens A B)
domain-1+-remainder-equivalence-0+⇒lens-1+
{A = A} univ n hA hR = ≡↔+ _ _ λ l₁ l₂ → $⟨ Σ-closure n (hR l₁ l₂) (λ _ →
Π-closure ext n λ _ →
+⇒≡ hA) ⟩
H-level n (∃ λ (eq : R l₁ ≃ R l₂) → ∀ p → _≡_ {A = A} _ _) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse $ equality-characterisation₄ univ)
n ⟩□
H-level n (l₁ ≡ l₂) □
where
open Lens
-- If A is a proposition, then Lens A B is also a proposition
-- (assuming univalence).
Is-proposition-closed-domain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition A → Is-proposition (Lens A B)
Is-proposition-closed-domain {b = b} {A = A} {B = B} univ A-prop =
$⟨ R₁≃R₂ ⟩
(∀ l₁ l₂ → R l₁ ≃ R l₂) ↝⟨ (λ hyp l₁ l₂ → propositional⇒inhabited⇒contractible
(Eq.left-closure ext 0 (R-prop l₁))
(hyp l₁ l₂)) ⟩
(∀ l₁ l₂ → Contractible (R l₁ ≃ R l₂)) ↝⟨ domain-1+-remainder-equivalence-0+⇒lens-1+ univ 0 A-prop ⟩□
Is-proposition (Lens A B) □
where
open Lens
R-prop : (l : Lens A B) → Is-proposition (R l)
R-prop l =
remainder-has-same-h-level-as-domain l 1 A-prop
remainder⁻¹ : (l : Lens A B) → R l → A
remainder⁻¹ l r =
rec A-prop
(λ b → _≃_.from (equiv l) (r , b))
(inhabited l r)
R-to-R : (l₁ l₂ : Lens A B) → R l₁ → R l₂
R-to-R l₁ l₂ = remainder l₂ ⊚ remainder⁻¹ l₁
involutive : (l : Lens A B) {f : R l → R l} → ∀ r → f r ≡ r
involutive l _ = R-prop l _ _
R₁≃R₂ : (l₁ l₂ : Lens A B) → R l₁ ≃ R l₂
R₁≃R₂ l₁ l₂ = Eq.↔⇒≃ $
Bij.bijection-from-involutive-family
R-to-R (λ l _ → involutive l) l₁ l₂
-- An alternative proof.
Is-proposition-closed-domain′ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-proposition A → Is-proposition (Lens A B)
Is-proposition-closed-domain′ {A = A} {B} univ A-prop =
$⟨ Traditional.lens-preserves-h-level-of-domain 0 A-prop ⟩
Is-proposition (Traditional.Lens A B) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse $ Lens↔Traditional-lens ⊠ univ (mono₁ 1 A-prop))
1 ⟩□
Is-proposition (Lens A B) □
-- If A is a set, then Lens A B is also a set (assuming univalence).
--
-- TODO: Can one prove that the corresponding result does not hold for
-- codomains? Are there types A and B such that B is a set, but
-- Lens A B is not?
Is-set-closed-domain :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
Is-set A → Is-set (Lens A B)
Is-set-closed-domain {A = A} {B} univ A-set =
$⟨ (λ {_ _} → Traditional.lens-preserves-h-level-of-domain 1 A-set) ⟩
Is-set (Traditional.Lens A B) ↝⟨ H-level.respects-surjection
(_↔_.surjection $ inverse $ Lens↔Traditional-lens ⊠ univ A-set)
2 ⟩□
Is-set (Lens A B) □
-- If A has h-level n, then Lens A B has h-level 1 + n (assuming
-- univalence).
--
-- See also
-- Lens.Non-dependent.Equivalent-preimages.higher-lens-preserves-h-level-of-domain.
domain-0+⇒lens-1+ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
∀ n → H-level n A → H-level (1 + n) (Lens A B)
domain-0+⇒lens-1+ {A = A} {B} univ n hA =
$⟨ (λ l₁ l₂ → Eq.h-level-closure ext n (hR l₁) (hR l₂)) ⟩
((l₁ l₂ : Lens A B) → H-level n (R l₁ ≃ R l₂)) ↝⟨ domain-1+-remainder-equivalence-0+⇒lens-1+ univ n (mono₁ n hA) ⟩□
H-level (1 + n) (Lens A B) □
where
open Lens
hR : ∀ l → H-level n (R l)
hR l = remainder-has-same-h-level-as-domain l n hA
-- An alternative proof.
domain-0+⇒lens-1+′ :
{A : Set a} {B : Set b} →
Univalence (a ⊔ b) →
∀ n → H-level n A → H-level (1 + n) (Lens A B)
domain-0+⇒lens-1+′ {A = A} {B} univ n hA =
$⟨ Σ-closure (1 + n)
(∃-H-level-H-level-1+ ext univ n)
(λ _ → ×-closure (1 + n)
(Eq.left-closure ext n (mono₁ n hA))
(Π-closure ext (1 + n) λ _ →
mono (Nat.suc≤suc (Nat.zero≤ n)) $
truncation-is-proposition)) ⟩
H-level (1 + n)
(∃ λ (p : ∃ (H-level n)) →
A ≃ (proj₁ p × B) × (proj₁ p → ∥ B ∥)) ↝⟨ H-level.respects-surjection (_↔_.surjection $ inverse iso) (1 + n) ⟩□
H-level (1 + n) (Lens A B) □
where
open Lens
iso =
Lens A B ↝⟨ inverse $ drop-⊤-right (λ l →
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(H-level-propositional ext n)
(remainder-has-same-h-level-as-domain l n hA)) ⟩
(∃ λ (l : Lens A B) → H-level n (R l)) ↝⟨ inverse Σ-assoc F.∘ Σ-cong Lens-as-Σ (λ _ → F.id) ⟩
(∃ λ R → (A ≃ (R × B) × (R → ∥ B ∥)) × H-level n R) ↝⟨ (∃-cong λ _ → ×-comm) ⟩
(∃ λ R → H-level n R × A ≃ (R × B) × (R → ∥ B ∥)) ↝⟨ Σ-assoc ⟩□
(∃ λ (p : ∃ (H-level n)) →
A ≃ (proj₁ p × B) × (proj₁ p → ∥ B ∥)) □
------------------------------------------------------------------------
-- An existence result
-- There is, in general, no lens for the first projection from a
-- Σ-type.
no-first-projection-lens :
∃ λ (A : Set a) → ∃ λ (B : A → Set b) →
¬ Lens (Σ A B) A
no-first-projection-lens =
Non-dependent.no-first-projection-lens
Lens contractible-to-contractible
------------------------------------------------------------------------
-- Some results related to the remainder type
-- The remainder type of a lens l : Lens A B is, for every b : B,
-- equivalent to the preimage of the getter with respect to b.
--
-- This result was pointed out to me by Andrea Vezzosi.
remainder≃get⁻¹ :
(l : Lens A B) (b : B) → Lens.R l ≃ Lens.get l ⁻¹ b
remainder≃get⁻¹ l b = Eq.↔→≃
(λ r → _≃_.from equiv (r , b)
, (get (_≃_.from equiv (r , b)) ≡⟨⟩
proj₂ (_≃_.to equiv (_≃_.from equiv (r , b))) ≡⟨ cong proj₂ $ _≃_.right-inverse-of equiv _ ⟩∎
b ∎))
(λ (a , _) → remainder a)
(λ (a , get-a≡b) →
let lemma =
cong get
(trans (cong (set a) (sym get-a≡b))
(_≃_.left-inverse-of equiv _)) ≡⟨ cong-trans _ _ (_≃_.left-inverse-of equiv _) ⟩
trans (cong get (cong (set a) (sym get-a≡b)))
(cong get (_≃_.left-inverse-of equiv _)) ≡⟨ cong₂ trans
(cong-∘ _ _ (sym get-a≡b))
(sym $ cong-∘ _ _ (_≃_.left-inverse-of equiv _)) ⟩
trans (cong (get ⊚ set a) (sym get-a≡b))
(cong proj₂ (cong (_≃_.to equiv)
(_≃_.left-inverse-of equiv _))) ≡⟨ cong₂ (λ p q → trans p (cong proj₂ q))
(cong-sym _ get-a≡b)
(_≃_.left-right-lemma equiv _) ⟩
trans (sym (cong (get ⊚ set a) get-a≡b))
(cong proj₂ (_≃_.right-inverse-of equiv _)) ≡⟨ sym $ sym-sym _ ⟩
sym (sym (trans (sym (cong (get ⊚ set a) get-a≡b))
(cong proj₂ (_≃_.right-inverse-of equiv _)))) ≡⟨ cong sym $
sym-trans _ (cong proj₂ (_≃_.right-inverse-of equiv _)) ⟩
sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(sym (sym (cong (get ⊚ set a) get-a≡b)))) ≡⟨ cong (λ eq → sym (trans (sym (cong proj₂
(_≃_.right-inverse-of equiv _)))
eq)) $
sym-sym (cong (get ⊚ set a) get-a≡b) ⟩∎
sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b)) ∎
in
Σ-≡,≡→≡
(_≃_.from equiv (remainder a , b) ≡⟨⟩
set a b ≡⟨ cong (set a) (sym get-a≡b) ⟩
set a (get a) ≡⟨ set-get a ⟩∎
a ∎)
(subst (λ a → get a ≡ b)
(trans (cong (set a) (sym get-a≡b)) (set-get a))
(cong proj₂ $ _≃_.right-inverse-of equiv (remainder a , b)) ≡⟨⟩
subst (λ a → get a ≡ b)
(trans (cong (set a) (sym get-a≡b))
(_≃_.left-inverse-of equiv _))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ subst-∘ _ _ (trans _ (_≃_.left-inverse-of equiv _)) ⟩
subst (_≡ b)
(cong get
(trans (cong (set a) (sym get-a≡b))
(_≃_.left-inverse-of equiv _)))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (λ eq → subst (_≡ b) eq
(cong proj₂ $ _≃_.right-inverse-of equiv _))
lemma ⟩
subst (_≡ b)
(sym (trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b)))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ subst-trans (trans _ (cong (get ⊚ set a) get-a≡b)) ⟩
trans
(trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong (get ⊚ set a) get-a≡b))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ elim¹
(λ eq → trans
(trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong (get ⊚ set a) eq))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡
eq)
(
trans
(trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong (get ⊚ set a) (refl _)))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (λ eq → trans (trans (sym (cong proj₂
(_≃_.right-inverse-of equiv _)))
eq)
(cong proj₂ $ _≃_.right-inverse-of equiv _)) $
cong-refl _ ⟩
trans
(trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(refl _))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩
trans (sym (cong proj₂ (_≃_.right-inverse-of equiv _)))
(cong proj₂ $ _≃_.right-inverse-of equiv _) ≡⟨ trans-symˡ (cong proj₂ (_≃_.right-inverse-of equiv _)) ⟩∎
refl _ ∎)
get-a≡b ⟩∎
get-a≡b ∎))
(λ r →
remainder (_≃_.from equiv (r , b)) ≡⟨⟩
proj₁ (_≃_.to equiv (_≃_.from equiv (r , b))) ≡⟨ cong proj₁ $ _≃_.right-inverse-of equiv _ ⟩∎
r ∎)
where
open Lens l
-- A corollary: Lens.get l ⁻¹_ is constant (up to equivalence).
--
-- Paolo Capriotti discusses this kind of property
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
get⁻¹-constant :
(l : Lens A B) (b₁ b₂ : B) → Lens.get l ⁻¹ b₁ ≃ Lens.get l ⁻¹ b₂
get⁻¹-constant l b₁ b₂ =
Lens.get l ⁻¹ b₁ ↝⟨ inverse $ remainder≃get⁻¹ l b₁ ⟩
Lens.R l ↝⟨ remainder≃get⁻¹ l b₂ ⟩□
Lens.get l ⁻¹ b₂ □
-- The set function can be expressed using get⁻¹-constant and get.
--
-- Paolo Capriotti defines set in a similar way
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
set-in-terms-of-get⁻¹-constant :
(l : Lens A B) →
Lens.set l ≡
λ a b →
proj₁ (_≃_.to (get⁻¹-constant l (Lens.get l a) b) (a , refl _))
set-in-terms-of-get⁻¹-constant l = refl _
-- The remainder function can be expressed using remainder≃get⁻¹ and
-- get.
remainder-in-terms-of-remainder≃get⁻¹ :
(l : Lens A B) →
Lens.remainder l ≡
λ a → _≃_.from (remainder≃get⁻¹ l (Lens.get l a)) (a , refl _)
remainder-in-terms-of-remainder≃get⁻¹ l = refl _
-- The lemma get⁻¹-constant satisfies some coherence properties.
--
-- The first and third properties are discussed by Paolo Capriotti
-- (http://homotopytypetheory.org/2014/04/29/higher-lenses/).
get⁻¹-constant-∘ :
(l : Lens A B) (b₁ b₂ b₃ : B) (p : Lens.get l ⁻¹ b₁) →
_≃_.to (get⁻¹-constant l b₂ b₃) (_≃_.to (get⁻¹-constant l b₁ b₂) p) ≡
_≃_.to (get⁻¹-constant l b₁ b₃) p
get⁻¹-constant-∘ l _ b₂ b₃ p =
from (r₂ , b₃) , cong proj₂ (right-inverse-of (r₂ , b₃)) ≡⟨ cong (λ r → from (r , b₃) , cong proj₂ (right-inverse-of (r , b₃))) $
cong proj₁ $ right-inverse-of _ ⟩∎
from (r₁ , b₃) , cong proj₂ (right-inverse-of (r₁ , b₃)) ∎
where
open Lens l
open _≃_ equiv
r₁ r₂ : R
r₁ = proj₁ (to (proj₁ p))
r₂ = proj₁ (to (from (r₁ , b₂)))
get⁻¹-constant-inverse :
(l : Lens A B) (b₁ b₂ : B) (p : Lens.get l ⁻¹ b₁) →
_≃_.to (get⁻¹-constant l b₁ b₂) p ≡
_≃_.from (get⁻¹-constant l b₂ b₁) p
get⁻¹-constant-inverse _ _ _ _ = refl _
get⁻¹-constant-id :
(l : Lens A B) (b : B) (p : Lens.get l ⁻¹ b) →
_≃_.to (get⁻¹-constant l b b) p ≡ p
get⁻¹-constant-id l b p =
_≃_.to (get⁻¹-constant l b b) p ≡⟨ sym $ get⁻¹-constant-∘ l b _ _ p ⟩
_≃_.to (get⁻¹-constant l b b) (_≃_.to (get⁻¹-constant l b b) p) ≡⟨⟩
_≃_.from (get⁻¹-constant l b b) (_≃_.to (get⁻¹-constant l b b) p) ≡⟨ _≃_.left-inverse-of (get⁻¹-constant l b b) _ ⟩∎
p ∎
-- Another kind of coherence property does not hold for
-- get⁻¹-constant.
--
-- This kind of property came up in a discussion with Andrea Vezzosi.
get⁻¹-constant-not-coherent :
¬ ({A B : Set} (l : Lens A B) (b₁ b₂ : B)
(f : ∀ b → Lens.get l ⁻¹ b) →
_≃_.to (get⁻¹-constant l b₁ b₂) (f b₁) ≡ f b₂)
get⁻¹-constant-not-coherent =
({A B : Set} (l : Lens A B) (b₁ b₂ : B) (f : ∀ b → Lens.get l ⁻¹ b) →
_≃_.to (get⁻¹-constant l b₁ b₂) (f b₁) ≡ f b₂) ↝⟨ (λ hyp → hyp l true false f) ⟩
_≃_.to (get⁻¹-constant l true false) (f true) ≡ f false ↝⟨ cong (proj₁ ⊚ proj₁) ⟩
true ≡ false ↝⟨ Bool.true≢false ⟩□
⊥ □
where
l : Lens (Bool × Bool) Bool
l = record
{ R = Bool
; equiv = F.id
; inhabited = ∣_∣
}
f : ∀ b → Lens.get l ⁻¹ b
f b = (b , b) , refl _
-- If B is inhabited whenever it is merely inhabited, then the
-- remainder type of a lens of type Lens A B can be expressed in terms
-- of preimages of the lens's getter.
remainder≃∃get⁻¹ :
(l : Lens A B) (∥B∥→B : ∥ B ∥ → B) →
Lens.R l ≃ ∃ λ (b : ∥ B ∥) → Lens.get l ⁻¹ (∥B∥→B b)
remainder≃∃get⁻¹ {B = B} l ∥B∥→B =
R ↔⟨ (inverse $ drop-⊤-left-× λ r → _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible truncation-is-proposition (inhabited r)) ⟩
∥ B ∥ × R ↝⟨ (∃-cong λ _ → remainder≃get⁻¹ l _) ⟩□
(∃ λ (b : ∥ B ∥) → get ⁻¹ (∥B∥→B b)) □
where
open Lens l
------------------------------------------------------------------------
-- Lens combinators
module Lens-combinators where
-- The definition of the identity lens is unique, if the get
-- function is required to be the identity (assuming univalence).
id-unique :
{A : Set a} →
Univalence a →
((l₁ , _) (l₂ , _) :
∃ λ (l : Lens A A) → ∀ a → Lens.get l a ≡ a) →
l₁ ≡ l₂
id-unique {A = A} univ l₁ l₂ =
_↔_.from (equality-characterisation₃ univ)
( R₁≃R₂
, (λ _ → uncurry get≡id→remainder-propositional l₂ _ _)
, λ a →
get (proj₁ l₁) a ≡⟨ proj₂ l₁ a ⟩
a ≡⟨ sym $ proj₂ l₂ a ⟩∎
get (proj₁ l₂) a ∎
)
where
open Lens
R→R :
(l₁ l₂ : ∃ λ (l : Lens A A) → ∀ a → get l a ≡ a) →
R (proj₁ l₁) → R (proj₁ l₂)
R→R (l₁ , l₁-id) (l₂ , l₂-id) r =
Trunc.rec
(get≡id→remainder-propositional l₂ l₂-id)
(A ↔⟨ equiv l₂ ⟩
R l₂ × A ↝⟨ proj₁ ⟩□
R l₂ □)
(inhabited l₁ r)
R₁≃R₂ : R (proj₁ l₁) ≃ R (proj₁ l₂)
R₁≃R₂ =
_↠_.from (Eq.≃↠⇔ (uncurry get≡id→remainder-propositional l₁)
(uncurry get≡id→remainder-propositional l₂))
(record { to = R→R l₁ l₂
; from = R→R l₂ l₁
})
-- The result of composing two lenses is unique if the codomain type
-- is inhabited whenever it is merely inhabited, and we require that
-- the resulting setter function is defined in a certain way
-- (assuming univalence).
∘-unique :
let open Lens in
{A : Set a} {C : Set c} →
Univalence (a ⊔ c) →
(∥ C ∥ → C) →
((comp₁ , _) (comp₂ , _) :
∃ λ (comp : Lens B C → Lens A B → Lens A C) →
∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp₁ ≡ comp₂
∘-unique {A = A} {C = C} univ ∥C∥→C
(comp₁ , set₁) (comp₂ , set₂) =
⟨ext⟩ λ l₁ → ⟨ext⟩ λ l₂ →
lenses-equal-if-setters-equal univ
(comp₁ l₁ l₂) (comp₂ l₁ l₂) (λ _ → ∥C∥→C) $
⟨ext⟩ λ a → ⟨ext⟩ λ c →
set (comp₁ l₁ l₂) a c ≡⟨ set₁ _ _ _ _ ⟩
set l₂ a (set l₁ (get l₂ a) c) ≡⟨ sym $ set₂ _ _ _ _ ⟩∎
set (comp₂ l₁ l₂) a c ∎
where
open Lens
-- Identity lens.
id : Block "id" → Lens A A
id {A = A} ⊠ = record
{ R = ∥ A ∥
; equiv = A ↔⟨ inverse ∥∥×↔ ⟩□
∥ A ∥ × A □
; inhabited = P.id
}
-- Composition of lenses.
--
-- Note that the domains are required to be at least as large as the
-- codomains; this should match many use-cases. Without this
-- restriction I failed to find a satisfactory definition of
-- composition. (I suspect that if Agda had had cumulativity, then
-- the domain and codomain could have lived in the same universe
-- without any problems.)
--
-- The composition operation matches on the lenses to ensure that it
-- does not unfold when applied to neutral lenses.
--
-- See also Lens.Non-dependent.Equivalent-preimages.⟨_⟩_⊚_.
infix 9 ⟨_,_⟩_∘_
⟨_,_⟩_∘_ :
∀ a b {A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} →
Lens B C → Lens A B → Lens A C
⟨_,_⟩_∘_ _ _ {A = A} {B} {C} l₁@(⟨ _ , _ , _ ⟩) l₂@(⟨ _ , _ , _ ⟩) =
record
{ R = R l₂ × R l₁
; equiv = A ↝⟨ equiv l₂ ⟩
R l₂ × B ↝⟨ F.id ×-cong equiv l₁ ⟩
R l₂ × (R l₁ × C) ↔⟨ ×-assoc ⟩□
(R l₂ × R l₁) × C □
; inhabited = ∥∥-map (get l₁) ⊚ inhabited l₂ ⊚ proj₁
}
where
open Lens
-- A variant of composition for lenses between types with the same
-- universe level.
infixr 9 _∘_
_∘_ :
{A B C : Set a} →
Lens B C → Lens A B → Lens A C
l₁ ∘ l₂ = ⟨ lzero , lzero ⟩ l₁ ∘ l₂
-- Other definitions of composition match ⟨_,_⟩_∘_, if the codomain
-- type is inhabited whenever it is merely inhabited, and the
-- resulting setter function is defined in a certain way (assuming
-- univalence).
composition≡∘ :
let open Lens in
∀ a b {A : Set (a ⊔ b ⊔ c)} {B : Set (b ⊔ c)} {C : Set c} →
Univalence (a ⊔ b ⊔ c) →
(∥ C ∥ → C) →
(comp : Lens B C → Lens A B → Lens A C) →
(∀ l₁ l₂ a c →
set (comp l₁ l₂) a c ≡ set l₂ a (set l₁ (get l₂ a) c)) →
comp ≡ ⟨ a , b ⟩_∘_
composition≡∘ _ _ univ ∥C∥→C comp set-comp =
∘-unique univ ∥C∥→C (comp , set-comp)
(_ , λ { ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ _ _ → refl _ })
-- Identity and composition form a kind of precategory (assuming
-- univalence).
associativity :
∀ a b c
{A : Set (a ⊔ b ⊔ c ⊔ d)} {B : Set (b ⊔ c ⊔ d)}
{C : Set (c ⊔ d)} {D : Set d} →
Univalence (a ⊔ b ⊔ c ⊔ d) →
(l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →
⟨ a ⊔ b , c ⟩ l₁ ∘ (⟨ a , b ⟩ l₂ ∘ l₃) ≡
⟨ a , b ⊔ c ⟩ (⟨ b , c ⟩ l₁ ∘ l₂) ∘ l₃
associativity _ _ _ univ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ ⟨ _ , _ , _ ⟩ =
_↔_.from (equality-characterisation₂ univ)
(Eq.↔⇒≃ (inverse ×-assoc) , λ _ → refl _)
left-identity :
∀ bi a {A : Set (a ⊔ b)} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ a , lzero ⟩ id bi ∘ l ≡ l
left-identity ⊠ _ {B = B} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₂ univ)
( (R × ∥ B ∥ ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : R × ∥ B ∥ ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₁
; from = λ r → r , inhabited r
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (r , _) →
cong (λ x → r , x) $ truncation-is-proposition _ _ }
}
right-identity :
∀ bi a {A : Set (a ⊔ b)} {B : Set b} →
Univalence (a ⊔ b) →
(l : Lens A B) →
⟨ lzero , a ⟩ l ∘ id bi ≡ l
right-identity ⊠ _ {A = A} univ l@(⟨ _ , _ , _ ⟩) =
_↔_.from (equality-characterisation₂ univ)
( (∥ A ∥ × R ↔⟨ lemma ⟩□
R □)
, λ _ → refl _
)
where
open Lens l
lemma : ∥ A ∥ × R ↔ R
lemma = record
{ surjection = record
{ logical-equivalence = record
{ to = proj₂
; from = λ r → ∥∥-map (λ b → _≃_.from equiv (r , b))
(inhabited r)
, r
}
; right-inverse-of = refl
}
; left-inverse-of = λ { (_ , r) →
cong (λ x → x , r) $ truncation-is-proposition _ _ }
}
open Lens-combinators
------------------------------------------------------------------------
-- Isomorphisms expressed using lens quasi-inverses
private
module B {a} (b : Block "id") =
Bi-invertibility equality-with-J (Set a) Lens (id b) _∘_
module BM {a} (b : Block "id") (univ : Univalence a) = B.More
b
(left-identity b _ univ)
(right-identity b _ univ)
(associativity _ _ _ univ)
-- A form of isomorphism between types, expressed using lenses.
open B public renaming (_≅_ to [_]_≅_) using (Has-quasi-inverse)
-- Lenses with quasi-inverses can be converted to equivalences.
≅→≃ : ∀ b → [ b ] A ≅ B → A ≃ B
≅→≃
⊠
(l@(⟨ _ , _ , _ ⟩) , l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id , l⁻¹∘l≡id) =
Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = get l
; from = get l⁻¹
}
; right-inverse-of = λ b → cong (λ l → get l b) l∘l⁻¹≡id
}
; left-inverse-of = λ a → cong (λ l → get l a) l⁻¹∘l≡id
})
where
open Lens
-- There is a split surjection from [ b ] A ≅ B to A ≃ B (assuming
-- univalence).
≅↠≃ :
{A B : Set a}
(b : Block "id") →
Univalence a →
([ b ] A ≅ B) ↠ (A ≃ B)
≅↠≃ {A = A} {B = B} b univ = record
{ logical-equivalence = record
{ to = ≅→≃ b
; from = from b
}
; right-inverse-of = ≅→≃∘from b
}
where
from : ∀ b → A ≃ B → [ b ] A ≅ B
from b A≃B = l , l⁻¹ , l∘l⁻¹≡id b , l⁻¹∘l≡id b
where
l = ≃→lens′ A≃B
l⁻¹ = ≃→lens′ (inverse A≃B)
l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹ ≡ id b
l∘l⁻¹≡id ⊠ = _↔_.from (equality-characterisation₂ univ)
( (∥ A ∥ × ∥ B ∥ ↝⟨ Eq.⇔→≃
(×-closure 1 truncation-is-proposition
truncation-is-proposition)
truncation-is-proposition
proj₂
(λ b → ∥∥-map (_≃_.from A≃B) b , b) ⟩
∥ B ∥ □)
, λ _ → cong₂ _,_
(truncation-is-proposition _ _)
(_≃_.right-inverse-of A≃B _)
)
l⁻¹∘l≡id : ∀ b → l⁻¹ ∘ l ≡ id b
l⁻¹∘l≡id ⊠ = _↔_.from (equality-characterisation₂ univ)
( (∥ B ∥ × ∥ A ∥ ↝⟨ Eq.⇔→≃
(×-closure 1 truncation-is-proposition
truncation-is-proposition)
truncation-is-proposition
proj₂
(λ a → ∥∥-map (_≃_.to A≃B) a , a) ⟩
∥ A ∥ □)
, λ _ → cong₂ _,_
(truncation-is-proposition _ _)
(_≃_.left-inverse-of A≃B _)
)
≅→≃∘from : ∀ b A≃B → ≅→≃ b (from b A≃B) ≡ A≃B
≅→≃∘from ⊠ _ = Eq.lift-equality ext (refl _)
-- There is not necessarily a split surjection from
-- Is-equivalence (Lens.get l) to Has-quasi-inverse l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalence-get↠Has-quasi-inverse :
(b : Block "id") →
Univalence a →
¬ ({A B : Set a}
(l : Lens A B) →
Is-equivalence (Lens.get l) ↠ Has-quasi-inverse b l)
¬Is-equivalence-get↠Has-quasi-inverse b univ surj =
$⟨ ⊤-contractible ⟩
Contractible ⊤ ↝⟨ H-level.respects-surjection lemma₃ 0 ⟩
Contractible ((z : Z) → z ≡ z) ↝⟨ mono₁ 0 ⟩
Is-proposition ((z : Z) → z ≡ z) ↝⟨ ¬-prop ⟩□
⊥ □
where
open Lens
Z,¬-prop = Circle.¬-type-of-refl-propositional
Z = proj₁ Z,¬-prop
¬-prop = proj₂ Z,¬-prop
lemma₂ :
∀ b →
(∃ λ (eq : R (id b) ≃ R (id b)) →
(∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)
×
((z : Z) → get (id b) z ≡ get (id b) z)) ≃
((z : Z) → z ≡ z)
lemma₂ ⊠ =
(∃ λ (eq : ∥ Z ∥ ≃ ∥ Z ∥) →
((z : Z) → _≃_.to eq ∣ z ∣ ≡ ∣ z ∣)
×
((z : Z) → z ≡ z)) ↔⟨ (∃-cong λ _ → drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
+⇒≡ truncation-is-proposition) ⟩
(∥ Z ∥ ≃ ∥ Z ∥) × ((z : Z) → z ≡ z) ↔⟨ drop-⊤-left-Σ $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Eq.left-closure ext 0 truncation-is-proposition)
F.id ⟩□
((z : Z) → z ≡ z) □
lemma₃ =
⊤ ↔⟨ inverse $ _⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Eq.propositional ext _)
(_≃_.is-equivalence Eq.id) ⟩
Is-equivalence P.id ↔⟨ ≡⇒↝ equivalence $ cong Is-equivalence $
unblock b (λ b → _ ≡ get (id b)) (refl _) ⟩
Is-equivalence (get (id b)) ↝⟨ surj (id b) ⟩
Has-quasi-inverse b (id b) ↔⟨ BM.Has-quasi-inverse≃id≡id-domain b univ
(id b , left-identity b _ univ _ , right-identity b _ univ _) ⟩
id b ≡ id b ↔⟨ equality-characterisation₃ univ ⟩
(∃ λ (eq : R (id b) ≃ R (id b)) →
(∀ z → _≃_.to eq (remainder (id b) z) ≡ remainder (id b) z)
×
(∀ z → get (id b) z ≡ get (id b) z)) ↔⟨ lemma₂ b ⟩□
((z : Z) → z ≡ z) □
-- See also ≃≃≅ below.
------------------------------------------------------------------------
-- Equivalences expressed using bi-invertibility for lenses
-- A form of equivalence between types, expressed using lenses.
open B public
renaming (_≊_ to [_]_≊_)
using (Has-left-inverse; Has-right-inverse; Is-bi-invertible)
open BM public using (equality-characterisation-≊)
-- Lenses with left inverses have propositional remainder types.
has-left-inverse→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-left-inverse b l →
Is-proposition (Lens.R l)
has-left-inverse→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id) =
$⟨ get≡id→remainder-propositional
(l⁻¹ ∘ l)
(λ a → cong (flip get a) l⁻¹∘l≡id) ⟩
Is-proposition (R (l⁻¹ ∘ l)) ↔⟨⟩
Is-proposition (R l × R l⁻¹) ↝⟨ H-level-×₁ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- Lenses with right inverses have propositional remainder types.
has-right-inverse→remainder-propositional :
(b : Block "id")
(l : Lens A B) →
Has-right-inverse b l →
Is-proposition (Lens.R l)
has-right-inverse→remainder-propositional
⊠ l@(⟨ _ , _ , _ ⟩) (l⁻¹@(⟨ _ , _ , _ ⟩) , l∘l⁻¹≡id) =
$⟨ get≡id→remainder-propositional
(l ∘ l⁻¹)
(λ a → cong (flip get a) l∘l⁻¹≡id) ⟩
Is-proposition (R (l ∘ l⁻¹)) ↔⟨⟩
Is-proposition (R l⁻¹ × R l) ↝⟨ H-level-×₂ (∥∥-map (remainder l⁻¹) ⊚ inhabited l) 1 ⟩□
Is-proposition (R l) □
where
open Lens
-- There is an equivalence between A ≃ B and [ b ] A ≊ B (assuming
-- univalence).
≃≃≊ :
{A B : Set a}
(b : Block "id") →
Univalence a →
(A ≃ B) ≃ ([ b ] A ≊ B)
≃≃≊ {A = A} {B = B} b univ = Eq.↔⇒≃ (record
{ surjection = record
{ logical-equivalence = record
{ to = to b
; from = from b
}
; right-inverse-of = to∘from b
}
; left-inverse-of = from∘to b
})
where
open Lens
to : ∀ b → A ≃ B → [ b ] A ≊ B
to b = B.≅→≊ b ⊚ _↠_.from (≅↠≃ b univ)
from : ∀ b → [ b ] A ≊ B → A ≃ B
from b = _↠_.to (≅↠≃ b univ) ⊚ _↠_.from (BM.≅↠≊ b univ)
to∘from : ∀ b A≊B → to b (from b A≊B) ≡ A≊B
to∘from b A≊B =
_≃_.from (equality-characterisation-≊ b univ _ _) $
_↔_.from (equality-characterisation₃ univ)
( ∥B∥≃R b A≊B
, lemma₁ b A≊B
, lemma₂ b A≊B
)
where
l′ : ∀ b (A≊B : [ b ] A ≊ B) → Lens A B
l′ b A≊B = proj₁ (to b (from b A≊B))
∥B∥≃R : ∀ b (A≊B@(l , _) : [ b ] A ≊ B) → ∥ B ∥ ≃ R l
∥B∥≃R b (l , (l-inv@(l⁻¹ , _) , _)) = Eq.⇔→≃
truncation-is-proposition
R-prop
(Trunc.rec R-prop (remainder l ⊚ get l⁻¹))
(inhabited l)
where
R-prop = has-left-inverse→remainder-propositional b l l-inv
lemma₁ :
∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →
_≃_.to (∥B∥≃R b A≊B) (remainder (l′ b A≊B) a) ≡ remainder l a
lemma₁
⊠
( l@(⟨ _ , _ , _ ⟩)
, (l⁻¹@(⟨ _ , _ , _ ⟩) , l⁻¹∘l≡id)
, (⟨ _ , _ , _ ⟩ , _)
) a =
remainder l (get l⁻¹ (get l a)) ≡⟨⟩
remainder l (get (l⁻¹ ∘ l) a) ≡⟨ cong (λ l′ → remainder l (get l′ a)) l⁻¹∘l≡id ⟩
remainder l (get (id ⊠) a) ≡⟨⟩
remainder l a ∎
lemma₂ :
∀ b (A≊B@(l , _) : [ b ] A ≊ B) a →
get (l′ b A≊B) a ≡ get l a
lemma₂ ⊠
(⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) _ =
refl _
from∘to :
∀ b A≃B →
_↠_.to (≅↠≃ b univ) (_↠_.from (BM.≅↠≊ b univ)
(B.≅→≊ b (_↠_.from (≅↠≃ b univ) A≃B))) ≡
A≃B
from∘to ⊠ _ = Eq.lift-equality ext (refl _)
-- The right-to-left direction of ≃≃≊ maps bi-invertible lenses to
-- their getter functions.
to-from-≃≃≊≡get :
(b : Block "id")
(univ : Univalence a)
(A≊B@(l , _) : [ b ] A ≊ B) →
_≃_.to (_≃_.from (≃≃≊ b univ) A≊B) ≡ Lens.get l
to-from-≃≃≊≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- A variant of ≃≃≊ that works even if A and B live in different
-- universes.
--
-- This variant came up in a discussion with Andrea Vezzosi.
≃≃≊′ :
{A : Set a} {B : Set b}
(b-id : Block "id") →
Univalence (a ⊔ b) →
(A ≃ B) ≃ ([ b-id ] ↑ b A ≊ ↑ a B)
≃≃≊′ {a = a} {b = b} {A = A} {B = B} b-id univ =
A ≃ B ↔⟨ inverse $ Eq.≃-preserves-bijections ext Bij.↑↔ Bij.↑↔ ⟩
↑ b A ≃ ↑ a B ↝⟨ ≃≃≊ b-id univ ⟩□
[ b-id ] ↑ b A ≊ ↑ a B □
-- The right-to-left direction of ≃≃≊′ maps bi-invertible lenses to a
-- variant of their getter functions.
to-from-≃≃≊′≡get :
{A : Set a} {B : Set b}
(b-id : Block "id")
(univ : Univalence (a ⊔ b)) →
(A≊B@(l , _) : [ b-id ] ↑ b A ≊ ↑ a B) →
_≃_.to (_≃_.from (≃≃≊′ b-id univ) A≊B) ≡ lower ⊚ Lens.get l ⊚ lift
to-from-≃≃≊′≡get
⊠ _ (⟨ _ , _ , _ ⟩ , (⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
refl _
-- The getter function of a bi-invertible lens is an equivalence
-- (assuming univalence).
Is-bi-invertible→Is-equivalence-get :
{A : Set a}
(b : Block "id") →
Univalence a →
(l : Lens A B) →
Is-bi-invertible b l → Is-equivalence (Lens.get l)
Is-bi-invertible→Is-equivalence-get
b@⊠ univ l@(⟨ _ , _ , _ ⟩)
is-bi-inv@((⟨ _ , _ , _ ⟩ , _) , (⟨ _ , _ , _ ⟩ , _)) =
_≃_.is-equivalence (_≃_.from (≃≃≊ b univ) (l , is-bi-inv))
-- If l is a lens between types in the same universe, then there is an
-- equivalence between "l is bi-invertible" and "the getter of l is an
-- equivalence" (assuming univalence).
Is-bi-invertible≃Is-equivalence-get :
{A B : Set a}
(b : Block "id") →
Univalence a →
(l : Lens A B) →
Is-bi-invertible b l ≃ Is-equivalence (Lens.get l)
Is-bi-invertible≃Is-equivalence-get b univ l = Eq.⇔→≃
(BM.Is-bi-invertible-propositional b univ l)
(Eq.propositional ext _)
(Is-bi-invertible→Is-equivalence-get b univ l)
(λ is-equiv →
let l′ = ≃→lens′ Eq.⟨ get l , is-equiv ⟩ in
$⟨ proj₂ (_≃_.to (≃≃≊ b univ) Eq.⟨ _ , is-equiv ⟩) ⟩
Is-bi-invertible b l′ ↝⟨ subst (Is-bi-invertible b) (sym $ get-equivalence→≡≃→lens′ univ l is-equiv) ⟩□
Is-bi-invertible b l □)
where
open Lens
-- If A is a set, then there is an equivalence between [ b ] A ≊ B and
-- [ b ] A ≅ B (assuming univalence).
≊≃≅ :
{A B : Set a}
(b : Block "id") →
Univalence a →
Is-set A →
([ b ] A ≊ B) ≃ ([ b ] A ≅ B)
≊≃≅ b univ A-set =
∃-cong λ _ →
BM.Is-bi-invertible≃Has-quasi-inverse-domain
b univ
(Is-set-closed-domain univ A-set)
------------------------------------------------------------------------
-- A category
-- If A is a set, then there is an equivalence between A ≃ B and
-- [ b ] A ≅ B (assuming univalence).
≃≃≅ :
{A B : Set a}
(b : Block "≃≃≅") →
Univalence a →
Is-set A →
(A ≃ B) ≃ ([ b ] A ≅ B)
≃≃≅ {A = A} {B = B} b@⊠ univ A-set =
A ≃ B ↝⟨ ≃≃≊ b univ ⟩
[ b ] A ≊ B ↝⟨ ≊≃≅ b univ A-set ⟩□
[ b ] A ≅ B □
-- The equivalence ≃≃≅ maps identity to identity.
≃≃≅-id≡id :
{A : Set a}
(b : Block "≃≃≅") (univ : Univalence a) (A-set : Is-set A) →
proj₁ (_≃_.to (≃≃≅ b univ A-set) F.id) ≡ id b
≃≃≅-id≡id ⊠ univ _ =
_↔_.from (equality-characterisation₂ univ)
(F.id , λ _ → refl _)
-- Lenses between sets in the same universe form a precategory
-- (assuming univalence).
private
precategory′ :
Block "id" →
Univalence a →
C.Precategory′ (lsuc a) (lsuc a)
precategory′ {a = a} b univ =
SET a
, (λ (A , A-set) (B , _) →
Lens A B
, Is-set-closed-domain univ A-set)
, id b
, _∘_
, left-identity b lzero univ _
, right-identity b lzero univ _
, (λ {_ _ _ _ l₁ l₂ l₃} →
associativity lzero lzero lzero univ l₃ l₂ l₁)
precategory :
Block "precategory" →
Univalence a →
Precategory (lsuc a) (lsuc a)
precategory ⊠ univ .C.Precategory.precategory =
block λ b → precategory′ b univ
-- Lenses between sets in the same universe form a category
-- (assuming univalence).
category :
Block "category" →
Univalence a →
Category (lsuc a) (lsuc a)
category ⊠ univ =
block λ b →
C.precategory-with-SET-to-category
ext
(λ _ _ → univ)
(proj₂ $ precategory′ b univ)
(λ (_ , A-set) _ → ≃≃≅ b univ A-set)
(λ (_ , A-set) → ≃≃≅-id≡id b univ A-set)
-- The precategory defined here is equal to the one defined in
-- Traditional, if the latter one is lifted (assuming univalence).
precategory≡precategory :
(b : Block "precategory") →
Univalence (lsuc a) →
(univ : Univalence a) →
precategory b univ ≡
C.lift-precategory-Hom _ Traditional.precategory
precategory≡precategory ⊠ univ⁺ univ =
block λ b →
_↔_.to (C.equality-characterisation-Precategory ext univ⁺ univ⁺)
( F.id
, (λ (X , X-set) (Y , _) →
Lens X Y ↔⟨ Lens↔Traditional-lens b univ X-set ⟩
Traditional.Lens X Y ↔⟨ inverse Bij.↑↔ ⟩□
↑ _ (Traditional.Lens X Y) □)
, (λ (_ , X-set) → cong lift $ _↔_.from
(Traditional.equality-characterisation-for-sets X-set)
(refl _))
, (λ (_ , X-set) (_ , Y-set) _ (lift l₁) (lift l₂) →
cong lift (∘-lemma b X-set Y-set l₁ l₂))
)
where
∘-lemma :
∀ b (A-set : Is-set A) (B-set : Is-set B)
(l₁ : Traditional.Lens B C) (l₂ : Traditional.Lens A B) →
Lens.traditional-lens
(Lens↔Traditional-lens.from B-set b l₁ ∘
Lens↔Traditional-lens.from A-set b l₂) ≡
l₁ Traditional.Lens-combinators.∘ l₂
∘-lemma ⊠ A-set _ _ _ =
_↔_.from (Traditional.equality-characterisation-for-sets A-set)
(refl _)
-- The category defined here is equal to the one defined in
-- Traditional, if the latter one is lifted (assuming univalence).
category≡category :
(b : Block "category") →
Univalence (lsuc a) →
(univ : Univalence a) →
category b univ ≡
C.lift-category-Hom _ (Traditional.category univ)
category≡category b univ⁺ univ =
_↔_.from (C.≡↔precategory≡precategory ext)
(Category.precategory (category b univ) ≡⟨ lemma b ⟩
precategory b univ ≡⟨ precategory≡precategory b univ⁺ univ ⟩∎
Category.precategory
(C.lift-category-Hom _ (Traditional.category univ)) ∎)
where
lemma :
∀ b →
Category.precategory (category b univ) ≡
precategory b univ
lemma ⊠ = refl _
| {
"alphanum_fraction": 0.4599145656,
"avg_line_length": 36.0516050386,
"ext": "agda",
"hexsha": "71d74fce8410856ff9b87b963a402a3035062c46",
"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": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Saizan/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Higher.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"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": "Saizan/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Higher.agda",
"max_line_length": 148,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Saizan/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Higher.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 31517,
"size": 88723
} |
open import Categories
open import Functors
open import RMonads
module RMonads.CatofRAdj.TermRAdj {a b c d}{C : Cat {a}{b}}{D : Cat {c}{d}}
{J : Fun C D}(M : RMonad J) where
open import Library
open import RAdjunctions
open import RMonads.CatofRAdj M
open import Categories.Terminal
open import RMonads.REM M
open import RMonads.REM.Adjunction M
open import RAdjunctions.RAdj2RMon
open import RMonads.CatofRAdj.TermRAdjObj M
open import RMonads.CatofRAdj.TermRAdjHom M
open Cat
open Fun
open RAdj
omaplem : {X : Obj CatofAdj} {f : Hom CatofAdj X EMObj} →
OMap (HomAdj.K (EMHom {X})) ≅ OMap (HomAdj.K f)
omaplem {A}{f} = ext (λ X → AlgEq
(fcong X (cong OMap (HomAdj.Rlaw f)))
(iext λ Y →
dext
(λ {g} {g'} p →
trans
(trans
(stripsubst (λ Z → Hom D Z (OMap (R (ObjAdj.adj A)) X))
(HMap (R (ObjAdj.adj A)) (right (ObjAdj.adj A) g))
(fcong Y (cong OMap (ObjAdj.law A))))
(cong' refl (ext (λ g₁ →
cong
(λ (F : Obj (ObjAdj.E A) → Obj D) →
Hom D (F (OMap (L (ObjAdj.adj A)) Y)) (F X))
(cong OMap (HomAdj.Rlaw f))))
(icong' refl (ext (λ Z →
cong
(λ (F : Obj (ObjAdj.E A) → Obj D) →
Hom (ObjAdj.E A) (OMap (L (ObjAdj.adj A)) Y) Z →
Hom D (F (OMap (L (ObjAdj.adj A)) Y)) (F Z))
(cong OMap (HomAdj.Rlaw f))))
(icong'
refl
(ext (λ Z → cong
(λ (F : Obj (ObjAdj.E A) → Obj D) →
{Y₁ : Obj (ObjAdj.E A)} →
Hom (ObjAdj.E A) Z Y₁ → Hom D (F Z) (F Y₁))
(cong OMap (HomAdj.Rlaw f))))
(cong HMap (HomAdj.Rlaw f))
(refl {x = OMap (L (ObjAdj.adj A)) Y}))
(refl {x = X}))
(refl {x = right (ObjAdj.adj A) g})))
(trans
(cong₃ (λ A1 A2 → RAlgMorph.amor {A1}{A2})
(fcong Y (cong OMap (HomAdj.Llaw f))) refl
(HomAdj.rightlaw f {Y} {X} {g}))
(cong (RAlg.astr (OMap (HomAdj.K f) X))
(trans
(stripsubst (Hom D (OMap J Y)) g
(fcong X (cong OMap (HomAdj.Rlaw f))))
p))))))
hmaplem : {X : Obj CatofAdj} {f : Hom CatofAdj X EMObj} →
{X₁ Y : Obj (ObjAdj.E X)} (f₁ : Hom (ObjAdj.E X) X₁ Y) →
HMap (HomAdj.K (EMHom {X})) f₁ ≅ HMap (HomAdj.K f) f₁
hmaplem {A}{V}{X}{Y} f = lemZ
(fcong X (omaplem {A} {V}))
(fcong Y (omaplem {A} {V}))
(cong'
refl
(ext (λ Z → cong
(λ (F : Obj (ObjAdj.E A) → Obj D) → Hom D (F X) (F Y))
(cong OMap (HomAdj.Rlaw V))))
(icong'
refl
(ext (λ Z → cong
(λ (F : Obj (ObjAdj.E A) → Obj D) →
Hom (ObjAdj.E A) X Z → Hom D (F X) (F Z))
(cong OMap (HomAdj.Rlaw V))))
(icong'
refl
(ext (λ Z → cong
(λ (F : Obj (ObjAdj.E A) → Obj D) →
{Y₁ : Obj (ObjAdj.E A)} →
Hom (ObjAdj.E A) Z Y₁ → Hom D (F Z) (F Y₁))
(cong OMap (HomAdj.Rlaw V))))
(cong HMap (HomAdj.Rlaw V))
(refl {x = X}))
(refl {x = Y}))
(refl {x = f}))
uniq : {X : Obj CatofAdj} {f : Hom CatofAdj X EMObj} →
EMHom {X} ≅ f
uniq {X} {f} = HomAdjEq _ _ (FunctorEq _ _
(omaplem {X} {f})
(iext λ _ → iext λ _ → ext (hmaplem {X}{f})))
EMIsTerm : Term CatofAdj EMObj
EMIsTerm = record {
t = EMHom;
law = uniq}
| {
"alphanum_fraction": 0.4601429357,
"avg_line_length": 34,
"ext": "agda",
"hexsha": "58827e1d1dee34177440fdfbfcc6f1c32bfc8956",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "RMonads/CatofRAdj/TermRAdj.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "RMonads/CatofRAdj/TermRAdj.agda",
"max_line_length": 75,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "RMonads/CatofRAdj/TermRAdj.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 1300,
"size": 3638
} |
{-# OPTIONS --without-K --safe #-}
open import Algebra
module Data.FingerTree
{c m}
(ℳ : Monoid c m)
where
open import Data.FingerTree.Measures ℳ
open import Data.FingerTree.Structures ℳ
open import Data.FingerTree.Cons ℳ
open import Data.FingerTree.View ℳ
open import Data.FingerTree.Split ℳ
| {
"alphanum_fraction": 0.7102803738,
"avg_line_length": 21.4,
"ext": "agda",
"hexsha": "0c62242f58acdf5e83edb1f3d2c1acb77855296d",
"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": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-indexed-fingertree",
"max_forks_repo_path": "src/Data/FingerTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"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-indexed-fingertree",
"max_issues_repo_path": "src/Data/FingerTree.agda",
"max_line_length": 40,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "39c3d96937384b052b782ffddf4fdec68c5d139f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-indexed-fingertree",
"max_stars_repo_path": "src/Data/FingerTree.agda",
"max_stars_repo_stars_event_max_datetime": "2019-02-26T07:04:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-02-26T07:04:54.000Z",
"num_tokens": 92,
"size": 321
} |
{-# OPTIONS --guardedness #-}
module hello-world-prog where
open import IO
main : Main
main = run (putStrLn "Hello, World!")
| {
"alphanum_fraction": 0.6929133858,
"avg_line_length": 15.875,
"ext": "agda",
"hexsha": "a9f00ec074b7f6fc112c9404e67213af86c7704c",
"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": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "avieor/agda-demos",
"max_forks_repo_path": "hello-world-prog.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d",
"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": "avieor/agda-demos",
"max_issues_repo_path": "hello-world-prog.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "3f6ea9a742135007ccb2b5f820147a7fc9472b9d",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "avieor/agda-demos",
"max_stars_repo_path": "hello-world-prog.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 32,
"size": 127
} |
module CTL.Modalities.EF where
open import FStream.Core
open import Library
-- Possibly sometime : s₀ ⊧ φ ⇔ ∃ s₀ R s₁ R ... ∃ i . sᵢ ⊧ φ
data EF' {ℓ₁ ℓ₂} {C : Container ℓ₁}
(props : FStream' C (Set ℓ₂)) : Set (ℓ₁ ⊔ ℓ₂) where
alreadyE : head props → EF' props
notYetE : E (fmap EF' (inF (tail props))) → EF' props
open EF'
EF : ∀ {ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)
EF props = APred EF' (inF props)
mutual
EFₛ' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream' C (Set ℓ₂) → FStream' {i} C (Set (ℓ₁ ⊔ ℓ₂))
head (EFₛ' props) = EF' props
tail (EFₛ' props) = EFₛ (tail props)
EFₛ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → FStream {i} C (Set (ℓ₁ ⊔ ℓ₂))
inF (EFₛ props) = fmap EFₛ' (inF props)
| {
"alphanum_fraction": 0.5757180157,
"avg_line_length": 29.4615384615,
"ext": "agda",
"hexsha": "3afad91129bdd62aa5110c2291a5de4628ddf38a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-12-13T15:56:38.000Z",
"max_forks_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "zimbatm/condatis",
"max_forks_repo_path": "CTL/Modalities/EF.agda",
"max_issues_count": 5,
"max_issues_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_issues_repo_issues_event_max_datetime": "2020-09-01T16:52:07.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-03T20:02:22.000Z",
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "zimbatm/condatis",
"max_issues_repo_path": "CTL/Modalities/EF.agda",
"max_line_length": 61,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "64d95885579395f641e9a9cb1b9487cf79280446",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Aerate/condatis",
"max_stars_repo_path": "CTL/Modalities/EF.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-13T16:52:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-13T16:52:28.000Z",
"num_tokens": 353,
"size": 766
} |
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Surjection
open import Oscar.Class.Smap
open import Oscar.Class.Reflexivity
open import Oscar.Data.Proposequality
module Oscar.Class.Surjidentity where
module _
{𝔬₁ 𝔯₁ 𝔬₂ 𝔯₂ ℓ₂}
{𝔒₁ : Ø 𝔬₁}
{𝔒₂ : Ø 𝔬₂}
where
module Surjidentity
{μ : Surjection.type 𝔒₁ 𝔒₂}
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
(_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
(§ : Smap.type _∼₁_ _∼₂_ μ μ)
(ε₁ : Reflexivity.type _∼₁_)
(ε₂ : Reflexivity.type _∼₂_)
= ℭLASS ((λ {x} {y} → § {x} {y}) , (λ {x} → ε₁ {x}) , (λ {x y} → _∼̇₂_ {x} {y}) , (λ {x} → ε₂ {x})) (∀ {x} → § (ε₁ {x}) ∼̇₂ ε₂)
module _
{μ : Surjection.type 𝔒₁ 𝔒₂}
{_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁}
{_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂}
{_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂}
{§ : Smap.type _∼₁_ _∼₂_ μ μ}
{ε₁ : Reflexivity.type _∼₁_}
{ε₂ : Reflexivity.type _∼₂_}
where
surjidentity = Surjidentity.method _∼₁_ _∼₂_ _∼̇₂_ (λ {x} {y} → § {x} {y}) (λ {x} → ε₁ {x}) (λ {x} → ε₂ {x})
module Surjidentity!
(∼₁ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
(∼₂ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂)
(∼̇₂ : ∀ {x y} → ∼₂ x y → ∼₂ x y → Ø ℓ₂)
⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄
⦃ _ : Smap!.class ∼₁ ∼₂ ⦄
⦃ _ : Reflexivity.class ∼₁ ⦄
⦃ _ : Reflexivity.class ∼₂ ⦄
= Surjidentity {surjection} ∼₁ ∼₂ ∼̇₂ § ε ε
module _
(_∼₁_ : 𝔒₁ → 𝔒₁ → Ø 𝔯₁)
{_∼₂_ : 𝔒₂ → 𝔒₂ → Ø 𝔯₂}
(_∼̇₂_ : ∀ {x y} → x ∼₂ y → x ∼₂ y → Ø ℓ₂)
⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄
⦃ _ : Smap!.class _∼₁_ _∼₂_ ⦄
⦃ _ : Reflexivity.class _∼₁_ ⦄
⦃ _ : Reflexivity.class _∼₂_ ⦄
where
surjidentity[_,_] = Surjidentity.method {surjection} _∼₁_ _∼₂_ _∼̇₂_ § ε ε
| {
"alphanum_fraction": 0.5189125296,
"avg_line_length": 31.3333333333,
"ext": "agda",
"hexsha": "2042b2c14737b7d571ace0e3f5c55332746b30f7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Surjidentity.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Surjidentity.agda",
"max_line_length": 131,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Surjidentity.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 928,
"size": 1692
} |
-- Andreas, 2011-10-04, transcription of Dan Doel's post on the Agda list
{-# OPTIONS --experimental-irrelevance #-}
module IrrelevantMatchRefl where
postulate
Level : Set
lzero : Level
lsuc : (i : Level) → Level
_⊔_ : Level -> Level -> Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO lzero #-}
{-# BUILTIN LEVELSUC lsuc #-}
{-# BUILTIN LEVELMAX _⊔_ #-}
infixl 6 _⊔_
data _≡_ {i : Level}{A : Set i}(a : A) : A → Set where
refl : a ≡ a
sym : ∀ {i}{A B : Set i} → A ≡ B → B ≡ A
sym refl = refl
-- irrelevant subst should be rejected, because it suggests
-- that the equality proof is irrelevant also for reduction
subst : ∀ {i j}{A : Set i}(P : A → Set j){a b : A} → .(a ≡ b) → P a → P b
subst P refl x = x
postulate
D : Set
lie : (D → D) ≡ D
-- the following two substs may not reduce! ...
abs : (D → D) → D
abs f = subst (λ T → T) lie f
app : D → D → D
app d = subst (λ T → T) (sym lie) d
ω : D
ω = abs (λ d → app d d)
-- ... otherwise Ω loops
Ω : D
Ω = app ω ω
-- ... and this would be a real fixed-point combinator
Y : (D → D) → D
Y f = app δ δ
where δ = abs (λ x → f (app x x))
K : D → D
K x = abs (λ y → x)
K∞ : D
K∞ = Y K
mayloop : K∞ ≡ abs (λ y → K∞)
mayloop = refl
-- gives error D != D → D
| {
"alphanum_fraction": 0.5642458101,
"avg_line_length": 20.5409836066,
"ext": "agda",
"hexsha": "c75f369bff6e2f168a8325bd19c8b1f9f42fdb7b",
"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": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dagit/agda",
"max_forks_repo_path": "test/fail/IrrelevantMatchRefl.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"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": "dagit/agda",
"max_issues_repo_path": "test/fail/IrrelevantMatchRefl.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/IrrelevantMatchRefl.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z",
"num_tokens": 481,
"size": 1253
} |
module Common.Prelude where
{-# IMPORT Common.FFI #-}
import Common.Level
data ⊥ : Set where
record ⊤ : Set where
postulate Char : Set
{-# BUILTIN CHAR Char #-}
{-# COMPILED_TYPE Char Char #-}
postulate String : Set
{-# BUILTIN STRING String #-}
{-# COMPILED_TYPE String String #-}
data Nat : Set where
zero : Nat
suc : Nat → Nat
{-# BUILTIN NATURAL Nat #-}
{-# COMPILED_DATA Nat Common.FFI.Nat Common.FFI.Zero Common.FFI.Suc #-}
{-# COMPILED_JS Nat function (x,v) { return (x < 1? v.zero(): v.suc(x-1)); } #-}
{-# COMPILED_JS zero 0 #-}
{-# COMPILED_JS suc function (x) { return x+1; } #-}
_+_ : Nat → Nat → Nat
zero + n = n
suc m + n = suc (m + n)
{-# COMPILED_JS _+_ function (x) { return function (y) { return x+y; }; } #-}
_∸_ : Nat → Nat → Nat
m ∸ zero = m
zero ∸ _ = zero
suc m ∸ suc n = m ∸ n
{-# COMPILED_JS _∸_ function (x) { return function (y) { return Math.max(0,x-y); }; } #-}
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
data List A : Set where
[] : List A
_∷_ : A → List A → List A
infixr 40 _∷_ _++_
_++_ : ∀ {A : Set} → List A → List A → List A
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
{-# BUILTIN LIST List #-}
{-# BUILTIN NIL [] #-}
{-# BUILTIN CONS _∷_ #-}
{-# COMPILED_DATA List [] [] (:) #-}
data Bool : Set where
true false : Bool
if_then_else_ : ∀ {A : Set} → Bool → A → A → A
if true then t else f = t
if false then t else f = f
{-# BUILTIN BOOL Bool #-}
{-# BUILTIN TRUE true #-}
{-# BUILTIN FALSE false #-}
{-# COMPILED_DATA Bool Bool True False #-}
{-# COMPILED_JS Bool function (x,v) { return (x? v["true"](): v["false"]()); } #-}
{-# COMPILED_JS true true #-}
{-# COMPILED_JS false false #-}
data Unit : Set where
unit : Unit
{-# COMPILED_DATA Unit () () #-}
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
{-# BUILTIN IO IO #-}
| {
"alphanum_fraction": 0.5623995715,
"avg_line_length": 19.8617021277,
"ext": "agda",
"hexsha": "cd9975abd48bbfde684513447c9a73fde5408911",
"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/Common/Prelude.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/Common/Prelude.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "test/Common/Prelude.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": 615,
"size": 1867
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
module Setoids.DirectSum {m n o p : _} {A : Set m} {B : Set n} (R : Setoid {m} {o} A) (S : Setoid {n} {p} B) where
directSumSetoid : Setoid {m ⊔ n} (A || B)
Setoid._∼_ directSumSetoid (inl x) (inl y) = embedLevel {o} {p} (Setoid._∼_ R x y)
Setoid._∼_ directSumSetoid (inl x) (inr y) = False'
Setoid._∼_ directSumSetoid (inr x) (inl y) = False'
Setoid._∼_ directSumSetoid (inr x) (inr y) = embedLevel {p} {o} (Setoid._∼_ S x y)
Equivalence.reflexive (Setoid.eq directSumSetoid) {inl x} = Equivalence.reflexive (Setoid.eq R) {x} ,, record {}
Equivalence.reflexive (Setoid.eq directSumSetoid) {inr x} = Equivalence.reflexive (Setoid.eq S) {x} ,, record {}
Equivalence.symmetric (Setoid.eq directSumSetoid) {inl x} {inl y} (x=y ,, _) = (Equivalence.symmetric (Setoid.eq R) x=y) ,, record {}
Equivalence.symmetric (Setoid.eq directSumSetoid) {inr x} {inr y} (x=y ,, _) = (Equivalence.symmetric (Setoid.eq S) x=y) ,, record {}
Equivalence.transitive (Setoid.eq directSumSetoid) {inl x} {inl y} {inl z} (x=y ,, _) (y=z ,, _) = Equivalence.transitive (Setoid.eq R) x=y y=z ,, record {}
Equivalence.transitive (Setoid.eq directSumSetoid) {inr x} {inr y} {inr z} (x=y ,, _) (y=z ,, _) = Equivalence.transitive (Setoid.eq S) x=y y=z ,, record {}
| {
"alphanum_fraction": 0.6775312067,
"avg_line_length": 68.6666666667,
"ext": "agda",
"hexsha": "2920760d05b33f9ce78cf7293983e1e478a34dde",
"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": "Setoids/DirectSum.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": "Setoids/DirectSum.agda",
"max_line_length": 156,
"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": "Setoids/DirectSum.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": 525,
"size": 1442
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
postulate
⊤ ⊥ : Set
_&_ : Set → Set → Set
_≤_ : Nat → Nat → Set
{-# TERMINATING #-}
_∣_ : Nat → Nat → Set
m ∣ zero = ⊤
zero ∣ suc n = ⊥
suc m ∣ suc n = (suc m ≤ suc n) & (suc m ∣ (n - m))
variable m n : Nat
postulate
divide-to-nat : n ∣ m → Nat
trivial : m ≡ n
divide-to-nat-correct : (e : m ∣ n) → divide-to-nat e * n ≡ m
divide-to-nat-correct e = trivial
| {
"alphanum_fraction": 0.5701357466,
"avg_line_length": 18.4166666667,
"ext": "agda",
"hexsha": "cbc389bd2033dd620b687c3d3fd2bb7756a3339e",
"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/Issue3134.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/Issue3134.agda",
"max_line_length": 61,
"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/Issue3134.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": 182,
"size": 442
} |
{-# OPTIONS --without-K #-}
module hott.equivalence.core where
open import equality.core using (_≡_ ; refl ; ap)
open import sum using (Σ ; proj₁ ; proj₂ ; _,_)
open import level using (_⊔_)
open import hott.level.core using (contr ; prop ; _⁻¹_)
open import function.core using (_$_)
open import function.isomorphism.core using (_≅_ ; iso)
-- a function is a weak equivalence, if the inverse images of all points are contractible
weak-equiv : ∀ {i k} {X : Set i} {Y : Set k} (f : X → Y) → Set (i ⊔ k)
weak-equiv {_} {_} {X} {Y} f = (y : Y) → contr $ f ⁻¹ y
-- weak equivalences
_≈_ : ∀ {i j} (X : Set i) (Y : Set j) → Set _
X ≈ Y = Σ (X → Y) λ f → weak-equiv f
apply≈ : ∀ {i j} {X : Set i}{Y : Set j} → X ≈ Y → X → Y
apply≈ = proj₁
≈⇒≅ : ∀ {i j} {X : Set i} {Y : Set j} → X ≈ Y → X ≅ Y
≈⇒≅ {X = X}{Y} (f , we) = iso f g iso₁ iso₂
where
g : Y → X
g y = proj₁ (proj₁ (we y))
iso₁ : (x : X) → g (f x) ≡ x
iso₁ x = ap proj₁ (proj₂ (we (f x)) (x , refl))
iso₂ : (y : Y) → f (g y) ≡ y
iso₂ y = proj₂ (proj₁ (we y))
invert≈ : ∀ {i j} {X : Set i}{Y : Set j} → X ≈ Y → Y → X
invert≈ (_ , we) y = proj₁ (proj₁ (we y))
| {
"alphanum_fraction": 0.5406824147,
"avg_line_length": 31.75,
"ext": "agda",
"hexsha": "13a3cde54a3536630517ec9bdab5e445a5562e64",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/hott/equivalence/core.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/hott/equivalence/core.agda",
"max_line_length": 89,
"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": "hott/equivalence/core.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": 468,
"size": 1143
} |
{-# OPTIONS --cubical --safe #-}
module Data.Binary.Increment.Strict where
open import Prelude
open import Strict
open import Data.Binary.Definition
open import Data.Bits.Strict
open import Data.Binary.Increment
inc′ : 𝔹 → 𝔹
inc′ 0ᵇ = 1ᵇ 0ᵇ
inc′ (1ᵇ xs) = 2ᵇ xs
inc′ (2ᵇ xs) = 0∷! inc′ xs
inc′≡inc : ∀ xs → inc′ xs ≡ inc xs
inc′≡inc 0ᵇ = refl
inc′≡inc (1ᵇ xs) = refl
inc′≡inc (2ᵇ xs) = 0∷!≡0∷ (inc′ xs) ; cong 1ᵇ_ (inc′≡inc xs)
| {
"alphanum_fraction": 0.6498855835,
"avg_line_length": 21.85,
"ext": "agda",
"hexsha": "a43042b4a433b00afab4b68a414005d83e2c01d0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Binary/Increment/Strict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Binary/Increment/Strict.agda",
"max_line_length": 60,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Binary/Increment/Strict.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": 204,
"size": 437
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Algebra.Group
module Cubical.Algebra.Group.Coset {ℓ} (G : Group ℓ) where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function using (id; _∘_; flip)
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.HLevels
open import Cubical.Functions.Embedding
open import Cubical.Algebra.Group.Subgroup
open import Cubical.Relation.Unary
open import Cubical.Relation.Unary.Properties
open import Cubical.Relation.Binary using (Reflexive; Symmetric; Transitive)
open import Cubical.HITs.PropositionalTruncation
open import Cubical.Relation.Binary.Reasoning.Equality
open Group G
open GroupLemmas G
private
variable
ℓ′ : Level
_≅[_]ˡ_ : ⟨ G ⟩ → Subgroup G ℓ′ → ⟨ G ⟩ → hProp _
x ≅[ H ]ˡ y = Subgroup.Member H (x ⁻¹ • y)
module _ (H : Subgroup G ℓ′) where
private module H = Subgroup H
≅ˡ-reflexive : Reflexive _≅[ H ]ˡ_
≅ˡ-reflexive = subst⁻ (_∈ H.Member) (inverseˡ _) H.preservesId
≅ˡ-symmetric : Symmetric _≅[ H ]ˡ_
≅ˡ-symmetric {x} {y} = subst (_∈ H.Member) (invDistr (x ⁻¹) y ∙ cong (y ⁻¹ •_) (invInvo x)) ∘ H.preservesInv
≅ˡ-transitive : Transitive _≅[ H ]ˡ_
≅ˡ-transitive {i} {j} {k} x y = subst (_∈ H.Member) eq (H.preservesOp x y)
where
eq : _
eq =
(i ⁻¹ • j) • (j ⁻¹ • k) ≡˘⟨ assoc _ _ _ ⟩
((i ⁻¹ • j) • j ⁻¹) • k ≡⟨ cong (_• k) (assoc _ _ _) ⟩
(i ⁻¹ • (j • j ⁻¹)) • k ≡⟨ cong (λ v → (i ⁻¹ • v) • k) (inverseʳ j) ⟩
(i ⁻¹ • ε) • k ≡⟨ cong (_• k) (identityʳ (i ⁻¹)) ⟩
i ⁻¹ • k ∎
infix 9 _<•_
infixr 9 _<•′_
_<•′_ : ⟨ G ⟩ → Pred ⟨ G ⟩ ℓ′ → Pred ⟨ G ⟩ _
g <•′ H = (g •_) ⊣ H
_<•_ : ⟨ G ⟩ → Subgroup G ℓ′ → Pred ⟨ G ⟩ _
g <• H = g <•′ Subgroup.Member H
module _ (H : Pred ⟨ G ⟩ ℓ′) where
cosetˡ-identity→ : ε <•′ H ⊆ H
cosetˡ-identity→ = rec (isProp[ H ] _)
λ ((h , subh) , εh≡x) → subst (_∈ H) (sym (identityˡ h) ∙ εh≡x) subh
cosetˡ-identity← : H ⊆ ε <•′ H
cosetˡ-identity← x∈H = ∣ (_ , x∈H) , identityˡ _ ∣
cosetˡ-identity : ε <•′ H ⇔ H
cosetˡ-identity = cosetˡ-identity→ , cosetˡ-identity←
cosetˡ-assoc→ : ∀ a b → (a • b) <•′ H ⊆ a <•′ b <•′ H
cosetˡ-assoc→ a b =
map λ ((h , subh) , abh≡x) → (b • h ,
∣ (h , subh) , refl ∣) ,
sym (assoc _ _ _) ∙ abh≡x
cosetˡ-assoc← : ∀ a b → a <•′ b <•′ H ⊆ (a • b) <•′ H
cosetˡ-assoc← a b {x} =
rec squash λ ((h , subh) , ah≡x) →
map (λ ((g , subg) , bg≡h) → (g , subg) , (
a • b • g ≡⟨ assoc a b g ⟩
a • (b • g) ≡⟨ cong (a •_) bg≡h ⟩
a • h ≡⟨ ah≡x ⟩
x ∎
)) subh
cosetˡ-assoc : ∀ a b → (a • b) <•′ H ≡ a <•′ b <•′ H
cosetˡ-assoc a b = ⇔toPath _ _ (cosetˡ-assoc→ a b , cosetˡ-assoc← a b)
module _ (H : Subgroup G ℓ′) where
private module H = Subgroup H
g∈gH : ∀ g → g ∈ g <• H
g∈gH g = ∣ H.ε , identityʳ _ ∣
≅-cosetˡ→ : ∀ x y → ⟨ x ≅[ H ]ˡ y ⟩ → x <• H ⇔ y <• H
≅-cosetˡ→ x y x≅y = xH⊆yH , xH⊇yH
where
xH⊆yH : x <• H ⊆ y <• H
xH⊆yH {a} = map λ ((h , subh) , xh≡a) → (y ⁻¹ • x • h , H.preservesOp (≅ˡ-symmetric H x≅y) subh) ,
(
y • (y ⁻¹ • x • h) ≡˘⟨ assoc y (y ⁻¹ • x) h ⟩
y • (y ⁻¹ • x) • h ≡˘⟨ cong (_• h) (assoc y (y ⁻¹) x) ⟩
y • y ⁻¹ • x • h ≡⟨ cong (λ v → v • x • h) (inverseʳ y) ⟩
ε • x • h ≡⟨ cong (_• h) (identityˡ x) ⟩
x • h ≡⟨ xh≡a ⟩
a ∎)
xH⊇yH : x <• H ⊇ y <• H
xH⊇yH {a} = map λ ((h , subh) , yh≡a) → (x ⁻¹ • y • h , H.preservesOp x≅y subh) ,
(
x • (x ⁻¹ • y • h) ≡˘⟨ assoc x (x ⁻¹ • y) h ⟩
x • (x ⁻¹ • y) • h ≡˘⟨ cong (_• h) (assoc x (x ⁻¹) y) ⟩
x • x ⁻¹ • y • h ≡⟨ cong (λ v → v • y • h) (inverseʳ x) ⟩
ε • y • h ≡⟨ cong (_• h) (identityˡ y) ⟩
y • h ≡⟨ yh≡a ⟩
a ∎)
≅-cosetˡ← : ∀ x y → x <• H ⇔ y <• H → ⟨ x ≅[ H ]ˡ y ⟩
≅-cosetˡ← x y (xH⊆yH , yH⊆xH) = rec ((_ ≅[ H ]ˡ _) .snd)
(λ ((h , subh) , yh≡x) →
subst (_∈ H.Member) (cong _⁻¹ (
h ≡˘⟨ identityˡ h ⟩
ε • h ≡˘⟨ cong (_• h) (inverseˡ y) ⟩
y ⁻¹ • y • h ≡⟨ assoc _ _ _ ⟩
y ⁻¹ • (y • h) ≡⟨ cong (y ⁻¹ •_) yh≡x ⟩
y ⁻¹ • x ∎
) ∙ invDistr (y ⁻¹) x ∙ cong (x ⁻¹ •_) (invInvo y)) (H.preservesInv subh)
)
(xH⊆yH {x} (g∈gH x))
≅-cosetˡ : ∀ x y → ⟨ x ≅[ H ]ˡ y ⟩ ≃ (x <• H ⇔ y <• H)
≅-cosetˡ x y = isPropEquiv→Equiv ((x ≅[ H ]ˡ y) .snd) (isProp⇔ (x <• H) (y <• H))
(≅-cosetˡ→ x y) (≅-cosetˡ← x y)
cosetˡ-idem→ : ((h , _) : ⟨ H ⟩) → h <• H ⊆ H.Member
cosetˡ-idem→ (h , subh) = rec (isProp[ H.Member ] _)
λ ((g , subg) , hg≡x) → subst (_∈ H.Member) hg≡x (H.preservesOp subh subg)
cosetˡ-idem← : ((h , _) : ⟨ H ⟩) → H.Member ⊆ h <• H
cosetˡ-idem← (h , subh) {x} subx =
∣
(h ⁻¹ • x , H.preservesOp (H.preservesInv subh) subx) , (
h • (h ⁻¹ • x) ≡˘⟨ assoc h (h ⁻¹) x ⟩
(h • h ⁻¹) • x ≡⟨ cong (_• x) (inverseʳ h) ⟩
ε • x ≡⟨ identityˡ x ⟩
x ∎)
∣
cosetˡ-idem : ((h , _) : ⟨ H ⟩) → h <• H ⇔ H.Member
cosetˡ-idem h = cosetˡ-idem→ h , cosetˡ-idem← h
_≅[_]ʳ_ : ⟨ G ⟩ → Subgroup G ℓ′ → ⟨ G ⟩ → hProp _
x ≅[ H ]ʳ y = Subgroup.Member H (x • y ⁻¹)
module _ (H : Subgroup G ℓ′) where
private module H = Subgroup H
≅ʳ-reflexive : Reflexive _≅[ H ]ʳ_
≅ʳ-reflexive = subst⁻ (_∈ H.Member) (inverseʳ _) H.preservesId
≅ʳ-symmetric : Symmetric _≅[ H ]ʳ_
≅ʳ-symmetric {x} {y} = subst (_∈ H.Member) (invDistr x (y ⁻¹) ∙ cong (_• x ⁻¹) (invInvo y)) ∘ H.preservesInv
≅ʳ-transitive : Transitive _≅[ H ]ʳ_
≅ʳ-transitive {i} {j} {k} x y = subst (_∈ H.Member) eq (H.preservesOp x y)
where
eq : _
eq =
(i • j ⁻¹) • (j • k ⁻¹) ≡˘⟨ assoc _ _ _ ⟩
((i • j ⁻¹) • j) • k ⁻¹ ≡⟨ cong (_• k ⁻¹) (assoc _ _ _) ⟩
(i • (j ⁻¹ • j)) • k ⁻¹ ≡⟨ cong (λ v → (i • v) • k ⁻¹) (inverseˡ j) ⟩
(i • ε) • k ⁻¹ ≡⟨ cong (_• k ⁻¹) (identityʳ i) ⟩
i • k ⁻¹ ∎
infix 9 _•>_
infixl 9 _•>′_
_•>′_ : Pred ⟨ G ⟩ ℓ′ → ⟨ G ⟩ → Pred ⟨ G ⟩ _
H •>′ g = (_• g) ⊣ H
_•>_ : Subgroup G ℓ′ → ⟨ G ⟩ → Pred ⟨ G ⟩ _
H •> g = Subgroup.Member H •>′ g
module _ (H : Pred ⟨ G ⟩ ℓ′) where
cosetʳ-identity→ : H •>′ ε ⊆ H
cosetʳ-identity→ = rec (isProp[ H ] _)
λ ((h , subh) , hε≡x) → subst (_∈ H) (sym (identityʳ h) ∙ hε≡x) subh
cosetʳ-identity← : H ⊆ H •>′ ε
cosetʳ-identity← x∈H = ∣ (_ , x∈H) , identityʳ _ ∣
cosetʳ-identity : H •>′ ε ⇔ H
cosetʳ-identity = cosetʳ-identity→ , cosetʳ-identity←
cosetʳ-assoc→ : ∀ a b → H •>′ (a • b) ⊆ H •>′ a •>′ b
cosetʳ-assoc→ a b =
map λ ((h , subh) , hab≡x) → (h • a ,
∣ (h , subh) , refl ∣) ,
assoc _ _ _ ∙ hab≡x
cosetʳ-assoc← : ∀ a b → H •>′ a •>′ b ⊆ H •>′ (a • b)
cosetʳ-assoc← a b {x} =
rec squash λ ((h , subh) , hb≡x) →
map (λ ((g , subg) , ga≡h) → (g , subg) , (
g • (a • b) ≡˘⟨ assoc g a b ⟩
(g • a) • b ≡⟨ cong (_• b) ga≡h ⟩
h • b ≡⟨ hb≡x ⟩
x ∎
)) subh
cosetʳ-assoc : ∀ a b → H •>′ (a • b) ≡ H •>′ a •>′ b
cosetʳ-assoc a b = ⇔toPath _ _ (cosetʳ-assoc→ a b , cosetʳ-assoc← a b)
module _ (H : Subgroup G ℓ′) where
private module H = Subgroup H
g∈Hg : ∀ g → g ∈ H •> g
g∈Hg g = ∣ H.ε , identityˡ _ ∣
≅-cosetʳ→ : ∀ x y → ⟨ x ≅[ H ]ʳ y ⟩ → H •> x ⇔ H •> y
≅-cosetʳ→ x y x≅y = Hx⊆Hy , Hx⊇Hy
where
Hx⊆Hy : H •> x ⊆ H •> y
Hx⊆Hy {a} = map
λ ((h , subh) , hx≡a) → (h • (x • y ⁻¹) , H.preservesOp subh x≅y) , (
h • (x • y ⁻¹) • y ≡˘⟨ cong (_• y) (assoc h x (y ⁻¹)) ⟩
h • x • y ⁻¹ • y ≡⟨ assoc (h • x) (y ⁻¹) y ⟩
(h • x) • (y ⁻¹ • y) ≡⟨ cong (h • x •_) (inverseˡ y) ⟩
h • x • ε ≡⟨ identityʳ (h • x) ⟩
h • x ≡⟨ hx≡a ⟩
a ∎)
Hx⊇Hy : H •> x ⊇ H •> y
Hx⊇Hy {a} = map
λ ((h , subh) , hy≡a) → (h • (y • x ⁻¹) , H.preservesOp subh (≅ʳ-symmetric H x≅y)) , (
h • (y • x ⁻¹) • x ≡˘⟨ cong (_• x) (assoc h y (x ⁻¹)) ⟩
h • y • x ⁻¹ • x ≡⟨ assoc (h • y) (x ⁻¹) x ⟩
(h • y) • (x ⁻¹ • x) ≡⟨ cong (h • y •_) (inverseˡ x) ⟩
h • y • ε ≡⟨ identityʳ (h • y) ⟩
h • y ≡⟨ hy≡a ⟩
a ∎)
≅-cosetʳ← : ∀ x y → H •> x ⇔ H •> y → ⟨ x ≅[ H ]ʳ y ⟩
≅-cosetʳ← x y (Hx⊆Hy , Hy⊆Hx) = rec ((_ ≅[ H ]ʳ _) .snd)
(λ ((h , subh) , hy≡x) →
subst (_∈ H.Member) (
h ≡˘⟨ identityʳ h ⟩
h • ε ≡˘⟨ cong (h •_) (inverseʳ y) ⟩
h • (y • y ⁻¹) ≡˘⟨ assoc h y (y ⁻¹) ⟩
(h • y) • y ⁻¹ ≡⟨ cong (_• y ⁻¹) hy≡x ⟩
x • y ⁻¹ ∎
) subh
)
(Hx⊆Hy {x} (g∈Hg x))
≅-cosetʳ : ∀ x y → ⟨ x ≅[ H ]ʳ y ⟩ ≃ (H •> x ⇔ H •> y)
≅-cosetʳ x y = isPropEquiv→Equiv ((x ≅[ H ]ʳ y) .snd) (isProp⇔ (H •> x) (H •> y))
(≅-cosetʳ→ x y) (≅-cosetʳ← x y)
cosetʳ-idem→ : ((h , _) : ⟨ H ⟩) → H •> h ⊆ H.Member
cosetʳ-idem→ (h , subh) = rec (isProp[ H.Member ] _)
λ ((g , subg) , gh≡x) → subst (_∈ H.Member) gh≡x (H.preservesOp subg subh)
cosetʳ-idem← : ((h , _) : ⟨ H ⟩) → H.Member ⊆ H •> h
cosetʳ-idem← (h , subh) {x} subx =
∣
(x • h ⁻¹ , H.preservesOp subx (H.preservesInv subh)) , (
(x • h ⁻¹) • h ≡⟨ assoc x (h ⁻¹) h ⟩
x • (h ⁻¹ • h) ≡⟨ cong (x •_) (inverseˡ h) ⟩
x • ε ≡⟨ identityʳ x ⟩
x ∎)
∣
cosetʳ-idem : ((h , _) : ⟨ H ⟩) → H •> h ⇔ H.Member
cosetʳ-idem h = cosetʳ-idem→ h , cosetʳ-idem← h
| {
"alphanum_fraction": 0.3969863269,
"avg_line_length": 36.4440677966,
"ext": "agda",
"hexsha": "dc54c91703a45619458b6d753e635bfc3c440ee1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Algebra/Group/Coset.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Algebra/Group/Coset.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Algebra/Group/Coset.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4794,
"size": 10751
} |
open import Agda.Builtin.List
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.Reflection
pattern vArg x = arg (arg-info visible (modality relevant quantity-ω)) x
make2 : Term → TC ⊤
make2 hole = bindTC (normalise (def (quote _+_) (vArg (lit (nat 1)) ∷ vArg (lit (nat 1)) ∷ []))) (unify hole)
macro
tester : Term → TC ⊤
tester hole = onlyReduceDefs (quote _+_ ∷ []) (make2 hole)
_ = tester
| {
"alphanum_fraction": 0.6928406467,
"avg_line_length": 27.0625,
"ext": "agda",
"hexsha": "83f26ed12f43ba5ffa088121272c38a9fe640fda",
"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": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/Succeed/Issue5469.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"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-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/Succeed/Issue5469.agda",
"max_line_length": 109,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/Succeed/Issue5469.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": 142,
"size": 433
} |
-- a simple error monad
module error where
open import level
open import string
infixr 1 _≫=err_ _≫err_
data error-t{ℓ}(A : Set ℓ) : Set ℓ where
no-error : A → error-t A
yes-error : string → error-t A
_≫=err_ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → error-t A → (A → error-t B) → error-t B
(no-error a) ≫=err f = f a
(yes-error e) ≫=err _ = yes-error e
_≫err_ : ∀{ℓ ℓ'}{A : Set ℓ}{B : Set ℓ'} → error-t A → error-t B → error-t B
a ≫err b = a ≫=err λ _ → b
| {
"alphanum_fraction": 0.5804347826,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "45d7126d3a68e2b8293eac2f7a08dffb0b8989aa",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "error.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "error.agda",
"max_line_length": 82,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "error.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 201,
"size": 460
} |
-------------------------------------------
-- This file contains basic definitions. --
-------------------------------------------
module Basics where
open import Level
data ⊥-poly {l : Level} : Set l where
⊥-poly-elim : ∀ {l w} {Whatever : Set w} → ⊥-poly {l} → Whatever
⊥-poly-elim ()
| {
"alphanum_fraction": 0.4262295082,
"avg_line_length": 25.4166666667,
"ext": "agda",
"hexsha": "2966cae708ad6e70042228ea1fd0bd48aafc3728",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "setoid-cats/Basics.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "setoid-cats/Basics.agda",
"max_line_length": 66,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "setoid-cats/Basics.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 76,
"size": 305
} |
module leftpad where
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Data.Nat.Properties
open import Data.Vec
open import Data.Product
open import Function
open import Relation.Binary.PropositionalEquality
data LeOrGt : ℕ → ℕ → Set where
le : ∀ m k → LeOrGt m (k + m)
gt : ∀ m k → LeOrGt (suc k + m) m
compare : ∀ m n → LeOrGt m n
compare zero n = cast $ le 0 n
where cast = subst (LeOrGt 0) (+-identityʳ n)
compare (suc m) zero = cast $ gt 0 m
where cast = subst (flip LeOrGt 0) (+-identityʳ (suc m))
compare (suc m) (suc n) with compare m n
... | le .m k = cast $ le (suc m) k
where cast = subst (LeOrGt (suc m)) (+-suc k m)
... | gt .n k = cast $ gt (suc n) k
where cast = subst (flip LeOrGt (suc n) ∘′ suc) (+-suc k n)
_⊔_ : ℕ → ℕ → ℕ
m ⊔ n with compare m n
... | le _ _ = n
... | gt _ _ = m
module _ {a} {A : Set a} (x : A) where
data LeftPad {n : ℕ} (xs : Vec A n) : ∀ m → Vec A m → Set where
Padded : ∀ k → LeftPad xs (k + n) (replicate {n = k} x ++ xs)
leftPad : ∀ n m (xs : Vec A n) → ∃ (LeftPad xs (n ⊔ m))
leftPad n m xs with compare n m
... | le .n k = , Padded k
... | gt .m k = , Padded 0
| {
"alphanum_fraction": 0.5865970409,
"avg_line_length": 29.4615384615,
"ext": "agda",
"hexsha": "2a9755059e57997df931efde00228bd6831312ac",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2021-11-24T10:17:34.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-05-15T21:48:31.000Z",
"max_forks_repo_head_hexsha": "4c28fb7c10710b66c4ebb72c3a4b0ec8d2ba4469",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "RomainGehrig/lets-prove-leftpad",
"max_forks_repo_path": "agda/leftpad.agda",
"max_issues_count": 32,
"max_issues_repo_head_hexsha": "4c28fb7c10710b66c4ebb72c3a4b0ec8d2ba4469",
"max_issues_repo_issues_event_max_datetime": "2021-12-03T09:56:05.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-05-15T22:32:16.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "RomainGehrig/lets-prove-leftpad",
"max_issues_repo_path": "agda/leftpad.agda",
"max_line_length": 65,
"max_stars_count": 443,
"max_stars_repo_head_hexsha": "4c28fb7c10710b66c4ebb72c3a4b0ec8d2ba4469",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "RomainGehrig/lets-prove-leftpad",
"max_stars_repo_path": "agda/leftpad.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T16:48:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-05-16T01:35:53.000Z",
"num_tokens": 457,
"size": 1149
} |
{-# OPTIONS --rewriting #-}
module Term.Core where
open import Context
open import Type
open import Function
open import Relation.Binary.PropositionalEquality hiding ([_])
open import Data.Empty
open import Data.Unit.Base
open import Data.Sum.Base
{-# BUILTIN REWRITE _≡_ #-}
{-# REWRITE foldlᶜ-▻-ε #-}
{-# REWRITE mapᶜ-▻▻ #-}
{-# REWRITE keep-id #-}
{-# REWRITE dupl-keep-vs #-}
{-# REWRITE renᵗ-id #-}
{-# REWRITE renᵗ-∘ #-}
{-# REWRITE subᵗ-idᵉ #-}
{-# REWRITE subᵗ-renᵗ #-}
{-# REWRITE subᵗ-Var #-}
{-# REWRITE inject-foldr-⇒-renᵗ #-}
{-# REWRITE inject-foldr-⇒-subᵗ #-}
infix 3 _⊢_
infix 4 Λ_ ƛ_
infixl 7 _·_
infix 9 _[_]
unfold : ∀ {Θ κ} -> Θ ⊢ᵗ (κ ⇒ᵏ ⋆) ⇒ᵏ κ ⇒ᵏ ⋆ -> Θ ⊢ᵗ κ -> Θ ⊢ᵗ ⋆
unfold ψ α = normalize $ ψ ∙ Lam (μ (shiftᵗ ψ) (Var vz)) ∙ α
data _⊢_ : ∀ {Θ} -> Con (Star Θ) -> Star Θ -> Set where
var : ∀ {Θ Γ} {α : Star Θ} -> α ∈ Γ -> Γ ⊢ α
Λ_ : ∀ {Θ Γ σ} {α : Star (Θ ▻ σ)} -> shiftᶜ Γ ⊢ α -> Γ ⊢ π σ α
-- A normalizing at the type level type instantiation.
_[_] : ∀ {Θ Γ σ} {β : Star (Θ ▻ σ)} -> Γ ⊢ π σ β -> (α : Θ ⊢ᵗ σ) -> Γ ⊢ β [ α ]ᵗ
-- A non-normalizing at the type level type instantiation.
_<_> : ∀ {Θ Γ σ} {β : Star (Θ ▻ σ)} -> Γ ⊢ π σ β -> (α : Θ ⊢ᵗ σ) -> Γ ⊢ β < α >ᵗ
-- A shorthand for `_< Var vz >` with more convenient computation at the type level.
_<> : ∀ {Θ σ Γ} {β : Star (Θ ▻ σ ▻ σ)} -> Γ ⊢ π σ β -> Γ ⊢ unshiftᵗ β
ƛ_ : ∀ {Θ Γ} {α β : Star Θ} -> Γ ▻ α ⊢ β -> Γ ⊢ α ⇒ β
_·_ : ∀ {Θ Γ} {α β : Star Θ} -> Γ ⊢ α ⇒ β -> Γ ⊢ α -> Γ ⊢ β
iwrap : ∀ {Θ Γ κ ψ} {α : Θ ⊢ᵗ κ} -> Γ ⊢ unfold ψ α -> Γ ⊢ μ ψ α
unwrap : ∀ {Θ Γ κ ψ} {α : Θ ⊢ᵗ κ} -> Γ ⊢ μ ψ α -> Γ ⊢ unfold ψ α
Term⁺ : Star⁺ -> Set
Term⁺ α = ∀ {Θ} {Γ : Con (Star Θ)} -> Γ ⊢ normalize α
Term⁻ : ∀ {Θ} -> Star Θ -> Set
Term⁻ α = ∀ {Γ} -> Γ ⊢ normalize α
bind : ∀ {Θ Γ} {α β : Star Θ} -> Γ ⊢ α -> Γ ▻ α ⊢ β -> Γ ⊢ β
bind term body = (ƛ body) · term
ren : ∀ {Θ Γ Δ} {α : Star Θ} -> Γ ⊆ Δ -> Γ ⊢ α -> Δ ⊢ α
ren ι (var v) = var (renᵛ ι v)
ren ι (Λ body) = Λ (ren (mapᶜ-⊆ ι) body)
ren ι (fun [ α ]) = ren ι fun [ α ]
ren ι (fun < α >) = ren ι fun < α >
ren ι (fun <>) = ren ι fun <>
ren ι (ƛ body) = ƛ (ren (keep ι) body)
ren ι (fun · arg) = ren ι fun · ren ι arg
ren ι (iwrap term) = iwrap (ren ι term)
ren ι (unwrap term) = unwrap (ren ι term)
shiftⁿ : ∀ {Θ Γ} {α : Star Θ} Δ -> Γ ⊢ α -> Γ ▻▻ Δ ⊢ α
shiftⁿ = ren ∘ extʳ
shift : ∀ {Θ Γ} {α β : Star Θ} -> Γ ⊢ α -> Γ ▻ β ⊢ α
shift = shiftⁿ (ε ▻ _)
instNonRec : ∀ {Θ Γ Δ} {α : Star Θ} -> Seq (Γ ⊢_) Δ -> Γ ▻▻ Δ ⊢ α -> Γ ⊢ α
instNonRec ø body = body
instNonRec {Δ = Δ ▻ _} (seq ▶ term) body = instNonRec seq (bind (shiftⁿ Δ term) body)
module Y where
self : Type⁺ (⋆ ⇒ᵏ ⋆)
self = Lam μ (Lam Lam (Var (vs vz) ∙ Var vz ⇒ Var vz)) (Var vz)
unfoldˢ : Term⁺ (π ⋆ $ self ∙ Var vz ⇒ self ∙ Var vz ⇒ Var vz)
unfoldˢ = Λ ƛ unwrap (var vz)
unrollˢ : Term⁺ (π ⋆ $ self ∙ Var vz ⇒ Var vz)
unrollˢ = Λ ƛ unfoldˢ [ Var vz ] · var vz · var vz
fix : Term⁺ (π ⋆ $ (Var vz ⇒ Var vz) ⇒ Var vz)
fix = Λ ƛ unrollˢ [ Var vz ] · iwrap (ƛ var (vs vz) · (unrollˢ [ Var vz ] · var vz))
open Y using (fix)
tuple : ∀ {Θ} -> Star (Θ ▻ ⋆) -> Star Θ
tuple Fv = π ⋆ $ Fv ⇒ Var vz
endo : ∀ {Θ} -> Star (Θ ▻ ⋆) -> Star Θ
endo Fv = π ⋆ $ Fv ⇒ Fv
fixBy
: ∀ {Θ} {Γ : Con (Star Θ)}
-> (Fv : Star (Θ ▻ ⋆))
-> Γ ⊢ (tuple Fv ⇒ tuple Fv) ⇒ endo Fv ⇒ tuple Fv
fixBy Fv =
ƛ fix < endo Fv ⇒ tuple Fv > ·
(ƛ ƛ Λ ƛ (var (vs vs vs vz) ·
(Λ ƛ (var (vs vs vs vz) · var (vs vs vz)) <> ·
-- `bind` is in order to make REWRITE rules fire (yeah, it's silly).
(bind (var (vs vs vz) <>) (var vz) · var vz))) <> · var vz)
ƛⁿ
: ∀ {Θ Ξ Γ} {f : Star Ξ -> Star Θ} {β}
-> ∀ Δ -> Γ ▻▻ mapᶜ f Δ ⊢ β -> Γ ⊢ conToTypeBy f Δ β
ƛⁿ ε term = term
ƛⁿ (Δ ▻ τ) body = ƛⁿ Δ (ƛ body)
ƛⁿ'
: ∀ {Θ Γ} {β : Star Θ}
-> ∀ Δ -> Γ ▻▻ Δ ⊢ β -> Γ ⊢ conToTypeBy id Δ β
ƛⁿ' ε term = term
ƛⁿ' (Δ ▻ τ) body = ƛⁿ' Δ (ƛ body)
applyⁿ
: ∀ {Θ Ξ Γ} {β : Star Θ} {f : Star Ξ -> Star Θ}
-> ∀ Δ -> Γ ⊢ conToTypeBy f Δ β -> Seq (λ τ -> Γ ⊢ f τ) Δ -> Γ ⊢ β
applyⁿ _ y ø = y
applyⁿ _ f (seq ▶ x) = applyⁿ _ f seq · x
deeply
: ∀ {Θ Ξ Γ} {f : Star Ξ -> Star Θ} {β γ}
-> ∀ Δ
-> Γ ▻▻ mapᶜ f Δ ⊢ β ⇒ γ
-> Γ ⊢ conToTypeBy f Δ β
-> Γ ⊢ conToTypeBy f Δ γ
deeply ε g y = g · y
deeply (Δ ▻ τ) g f = deeply Δ (ƛ ƛ shiftⁿ (ε ▻ _ ▻ _) (ƛ g) · var vz · (var (vs vz) · var vz)) f
conToTypeShift : ∀ {Θ} -> Con (Star Θ) -> Star (Θ ▻ ⋆)
conToTypeShift Δ = conToTypeBy shiftᵗ Δ (Var vz)
-- This is not easy, but makes perfect sense and should be doable.
postulate
shift-⊢ : ∀ {Θ Γ β} {α : Star Θ} -> Γ ⊢ α -> shiftᶜ {τ = β} Γ ⊢ shiftᵗ α
recursive
: ∀ {Θ} {Γ : Con (Star (Θ ▻ ⋆))}
-> (Δ : Con (Star Θ))
-> Γ ⊢ π ⋆ (conToTypeBy (shiftᵗⁿ (ε ▻ _ ▻ _)) Δ (Var vz) ⇒ Var vz)
-> Seq (λ β -> Γ ⊢ shiftᵗ β) Δ
recursive ε h = ø
recursive (Δ ▻ τ) h
= recursive Δ (Λ ƛ shift (shift-⊢ h <>) · deeply Δ (ƛ ƛ var (vs vz)) (var vz))
▶ h < shiftᵗ τ > · (ƛⁿ Δ (ƛ var vz)) where
byCon : ∀ {Θ} (Δ : Con (Star Θ)) -> let F = conToTypeShift Δ in ∀ {Γ} -> Γ ⊢ tuple F ⇒ tuple F
byCon Δ = ƛ Λ ƛ applyⁿ Δ (var vz) (recursive Δ (var (vs vz)))
fixCon : ∀ {Θ} (Δ : Con (Star Θ)) -> let F = conToTypeShift Δ in ∀ {Γ} -> Γ ⊢ endo F ⇒ tuple F
fixCon Δ = fixBy (conToTypeShift Δ) · byCon Δ
record Tuple {Θ} (Γ Δ : Con (Star Θ)) : Set where
constructor PackTuple
field tupleTerm : Γ ⊢ tuple (conToTypeShift Δ)
mutualFix : ∀ {Θ} {Γ Δ : Con (Star Θ)} -> Seq (Γ ▻▻ Δ ⊢_) Δ -> Tuple Γ Δ
mutualFix {Γ = Γ} {Δ} seq
= PackTuple
$ fixCon Δ
· (Λ ƛ ƛⁿ Δ (applyⁿ Δ (var (vsⁿ (shiftᶜ Δ))) $
mapˢ (ren (keepⁿ (shiftᶜ Δ) ∘ extʳ $ ε ▻ _) ∘′ shift-⊢) seq))
-- Note that we do not perform the "pass the whole tuple in and extract each its element
-- separately" trick, because we do know the type of the result (it's `α`).
bindTuple : ∀ {Θ Γ Δ} {α : Star Θ} -> Tuple Γ Δ -> Γ ▻▻ Δ ⊢ α -> Γ ⊢ α
bindTuple {Θ} {Γ} {Δ} {α} (PackTuple tup) body = tup < α > · (ƛⁿ Δ body)
instRec : ∀ {Θ Γ Δ} {α : Star Θ} -> Seq (Γ ▻▻ Δ ⊢_) Δ -> Γ ▻▻ Δ ⊢ α -> Γ ⊢ α
instRec = bindTuple ∘ mutualFix
| {
"alphanum_fraction": 0.5090193506,
"avg_line_length": 33.3224043716,
"ext": "agda",
"hexsha": "bc8ce8242654c56f966df8988eef3b273c2cd3b6",
"lang": "Agda",
"max_forks_count": 399,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T11:18:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-05T09:36:10.000Z",
"max_forks_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "AriFordsham/plutus",
"max_forks_repo_path": "papers/unraveling-recursion/code/src/Term/Core.agda",
"max_issues_count": 2493,
"max_issues_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T15:31:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-09-28T19:28:17.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "AriFordsham/plutus",
"max_issues_repo_path": "papers/unraveling-recursion/code/src/Term/Core.agda",
"max_line_length": 96,
"max_stars_count": 1299,
"max_stars_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "AriFordsham/plutus",
"max_stars_repo_path": "papers/unraveling-recursion/code/src/Term/Core.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-28T01:10:02.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-02T13:41:39.000Z",
"num_tokens": 2923,
"size": 6098
} |
{-# OPTIONS --cubical-compatible #-}
record Erased (A : Set) : Set where
constructor [_]
field
@0 erased : A
open Erased
data W (A : Set) (B : A → Set) : Set where
sup : (x : A) → (B x → W A B) → W A B
lemma :
{A : Set} {B : A → Set} →
Erased (W A B) → W (Erased A) (λ x → Erased (B (erased x)))
lemma [ sup x f ] = sup [ x ] λ ([ y ]) → lemma [ f y ]
data ⊥ : Set where
data E : Set where
c : E → E
magic : @0 E → ⊥
magic (c e) = magic e
| {
"alphanum_fraction": 0.5108225108,
"avg_line_length": 18.48,
"ext": "agda",
"hexsha": "01936149f66b92fafc7d18377019137410d0b44b",
"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/Issue4172-without-K.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/Issue4172-without-K.agda",
"max_line_length": 61,
"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/Issue4172-without-K.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 182,
"size": 462
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Numbers.Naturals.Definition
open import Numbers.Integers.Definition
open import Numbers.Integers.Addition
open import Numbers.Integers.Multiplication
open import Numbers.Integers.Order
open import Groups.Definition
module Numbers.Integers.Integers where
open Numbers.Integers.Definition using (ℤ ; nonneg ; negSucc) public
open Numbers.Integers.Addition using (_+Z_ ; ℤGroup ; ℤAbGrp) public
open Numbers.Integers.Multiplication using (_*Z_) public
open import Numbers.Integers.RingStructure.IntegralDomain public using (ℤIntDom) public
open import Numbers.Integers.RingStructure.Ring public using (ℤRing) public
open Numbers.Integers.Order using (_<Z_ ; ℤOrderedRing) public
_-Z_ : ℤ → ℤ → ℤ
a -Z b = a +Z (Group.inverse ℤGroup b)
_^Z_ : ℤ → ℕ → ℤ
a ^Z zero = nonneg 1
a ^Z succ b = a *Z (a ^Z b)
| {
"alphanum_fraction": 0.7713625866,
"avg_line_length": 34.64,
"ext": "agda",
"hexsha": "bda1730a913b4a4f8cdb495c29620a203d2d8080",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Numbers/Integers/Integers.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Numbers/Integers/Integers.agda",
"max_line_length": 87,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Numbers/Integers/Integers.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": 249,
"size": 866
} |
module AocUtil where
open import Data.Maybe
open import Data.String as String
open import Foreign.Haskell using (Unit)
open import Data.List as List
open import Data.Nat
open import Data.Char
open import Data.Bool.Base
open import AocIO
void : ∀ {a} {A : Set a} → IO A → IO Unit
void m = m >>= λ _ → return Unit.unit
printString : String → IO Unit
printString s = putStrLn (toCostring s)
mainBuilder : (String → (List String) → IO Unit) → IO Unit
mainBuilder main' = getProgName >>= λ name → getArgs >>= main' name
readFileMain : (String → IO Unit) → String → (List String) → IO Unit
readFileMain f name (file ∷ []) = readFiniteFile file >>= f
readFileMain f name _ = putStrLn (toCostring ("Usage: " String.++ name String.++ " FILE"))
splitWhen : ∀ {a} {A : Set a} → (A → Bool) → List A → List (List A)
splitWhen pred [] = []
splitWhen pred (x ∷ ls) with (pred x) | splitWhen pred ls
... | false | [] = List.[ List.[ x ] ]
splitWhen pred (x ∷ ls) | false | top-list ∷ rest = (x ∷ top-list) ∷ rest
... | true | rec = [] ∷ rec
lines : List Char → List (List Char)
lines = splitWhen isNewline
where
isNewline : Char → Bool
isNewline '\n' = true
isNewline _ = false
words : List Char → List (List Char)
words = splitWhen isWhitespace
where
isWhitespace : Char → Bool
isWhitespace ' ' = true
isWhitespace '\t' = true
isWhitespace _ = false
sequence-io-prim : ∀ {a} {A : Set a} → List (IO A) → IO (List A)
sequence-io-prim [] = return []
sequence-io-prim (m ∷ ms) = m >>= λ x → sequence-io-prim ms >>= λ xs → return (x ∷ xs)
toDigit : Char → Maybe ℕ
toDigit '0' = just 0
toDigit '1' = just 1
toDigit '2' = just 2
toDigit '3' = just 3
toDigit '4' = just 4
toDigit '5' = just 5
toDigit '6' = just 6
toDigit '7' = just 7
toDigit '8' = just 8
toDigit '9' = just 9
toDigit _ = nothing
unsafeParseNat : List Char → ℕ
unsafeParseNat ls = unsafeParseNat' 0 ls
where
unsafeParseNat' : ℕ → List Char → ℕ
unsafeParseNat' acc [] = acc
unsafeParseNat' acc (x ∷ ls) with (toDigit x)
... | nothing = acc * 10
... | just n = unsafeParseNat' (n + (acc * 10)) ls
| {
"alphanum_fraction": 0.6378326996,
"avg_line_length": 29.6338028169,
"ext": "agda",
"hexsha": "66988ff466dee1573ac3f9cd6de19b37d77112c7",
"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": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Zalastax/adventofcode2017",
"max_forks_repo_path": "lib/AocUtil.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Zalastax/adventofcode2017",
"max_issues_repo_path": "lib/AocUtil.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "37956e581dc51bf78008d7dd902bb18d2ee481f6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Zalastax/adventofcode2017",
"max_stars_repo_path": "lib/AocUtil.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 691,
"size": 2104
} |
------------------------------------------------------------------------
-- The extensional sublist relation over decidable setoid equality.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Subset.DecSetoid
{c ℓ} (S : DecSetoid c ℓ) where
-- import Data.List.Relation.Binary.Permutation.Setoid as SetoidPerm
-- import Data.List.Relation.Binary.Subset.Setoid as SetoidSubset
-- import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties
-- as HeterogeneousProperties
open import Level using (_⊔_)
-- open DecSetoid S
-- open SetoidSubset setoid public
-- open DecSetoidEquality S
open Relation.Binary using (Rel)
open import Data.List using (List)
------------------------------------------------------------------------
-- Subset relation
module _ where
open import Function using (_∘_)
open import Data.List
open import Data.List.Membership.DecSetoid S using (_∈_; _∈?_)
open import Relation.Nullary
open import Data.List.Relation.Unary.Any public
open import Data.List.Relation.Unary.Any.Properties using (¬Any[])
open DecSetoid S
infix 4 _⊆_ _⊈_
_⊆_ : Rel (List Carrier) (c ⊔ ℓ)
xs ⊆ ys = ∀ x → x ∈ xs → x ∈ ys
_⊈_ : Rel (List Carrier) (c ⊔ ℓ)
xs ⊈ ys = ¬ xs ⊆ ys
-- lemma
∈-cong : ∀ {xs x y} → x ≈ y → x ∈ xs → y ∈ xs
∈-cong x≈y (here P) = here (trans (sym x≈y) P)
∈-cong x≈y (there P) = there (∈-cong x≈y P)
∉[] : ∀ {x xs} → ¬ x ∷ xs ⊆ []
∉[] {x} {xs} P = ¬Any[] (∈-cong {[]} {x} {x} refl (P x (here refl)))
⊆-refl : ∀ {xs} → xs ⊆ xs
⊆-refl x P = P
∷-mono : ∀ {xs ys x y} → x ≈ y → xs ⊆ ys → x ∷ xs ⊆ y ∷ ys
∷-mono x≈y P x (here Q) = here (trans Q x≈y)
∷-mono x≈y P x (there Q) = there (P x Q)
⊆-swap : ∀ {xs x y} → x ∷ y ∷ xs ⊆ y ∷ x ∷ xs
⊆-swap x (here P) = there (here P)
⊆-swap x (there (here P)) = here P
⊆-swap x (there (there P)) = there (there P)
infix 4 _⊆?_
_⊆?_ : Decidable _⊆_
[] ⊆? ys = yes (λ x ())
x ∷ xs ⊆? [] = no ∉[]
x ∷ xs ⊆? y ∷ ys with x ∈? y ∷ ys
x ∷ xs ⊆? y ∷ ys | yes P with xs ⊆? y ∷ ys
... | yes Q = yes λ where x (here R) → ∈-cong (sym R) P
x (there R) → Q x R
... | no ¬Q = no λ R → ¬Q λ x S → R x (there S)
x ∷ xs ⊆? y ∷ ys | no ¬P = no λ Q → ¬P (Q x (here refl))
------------------------------------------------------------------------
-- Equivalence relation
module _ where
open DecSetoid S
open import Data.Product
open import Data.List
open import Relation.Binary.Construct.Intersection
open import Function.Base using (flip)
infix 4 _≋_
_≋_ : Rel (List Carrier) (c ⊔ ℓ)
_≋_ = _⊆_ ∩ flip _⊆_
{-# DISPLAY _⊆_ ∩ flip _⊆_ = _≋_ #-}
∷-cong : ∀ {xs ys x y} → x ≈ y → xs ≋ ys → x ∷ xs ≋ y ∷ ys
∷-cong x≈y (xs⊆ys , ys⊆xs) = ∷-mono x≈y xs⊆ys , ∷-mono (sym x≈y) ys⊆xs
≋-swap : ∀ {xs x y} → x ∷ y ∷ xs ≋ y ∷ x ∷ xs
≋-swap = ⊆-swap , ⊆-swap
open import Data.List.Relation.Binary.Permutation.Homogeneous
open import Relation.Nullary
open import Relation.Nullary.Decidable
infix 4 _≋?_
_≋?_ : Decidable _≋_
_≋?_ = decidable _⊆?_ (flip _⊆?_)
------------------------------------------------------------------------
-- Relational properties
module _ where
open import Data.Product
≋-isEquivalence : IsEquivalence _≋_
≋-isEquivalence = record
{ refl = (λ x z → z) , (λ x z → z)
; sym = λ where (P , Q) → Q , P
; trans = λ where (P , Q) (S , T) → (λ x U → S x (P x U)) , λ x V → Q x (T x V)
}
-- shorthands
≋-refl : Reflexive _≋_
≋-refl = IsEquivalence.refl ≋-isEquivalence
≋-sym : Symmetric _≋_
≋-sym = IsEquivalence.sym ≋-isEquivalence
≋-trans : Transitive _≋_
≋-trans = IsEquivalence.trans ≋-isEquivalence
⊆-IsPreorder : IsPreorder _≋_ _⊆_
⊆-IsPreorder = record
{ isEquivalence = ≋-isEquivalence
; reflexive = λ where (P , Q) x R → P x R
; trans = λ P Q x R → Q x (P x R)
}
⊆-Antisymmetric : Antisymmetric _≋_ _⊆_
⊆-Antisymmetric P Q = P , Q
⊆-isPartialOrder : IsPartialOrder _≋_ _⊆_
⊆-isPartialOrder = record
{ isPreorder = ⊆-IsPreorder
; antisym = ⊆-Antisymmetric }
⊆-isDecPartialOrder : IsDecPartialOrder _≋_ _⊆_
⊆-isDecPartialOrder = record
{ isPartialOrder = ⊆-isPartialOrder
; _≟_ = _≋?_
; _≤?_ = _⊆?_
}
------------------------------------------------------------------------
-- Bundles
poset : Poset _ _ _
poset = record
{ Carrier = List (DecSetoid.Carrier S)
; _≈_ = _≋_
; _≤_ = _⊆_
; isPartialOrder = ⊆-isPartialOrder
}
setoid : Setoid _ _
setoid = record
{ Carrier = List (DecSetoid.Carrier S)
; _≈_ = _≋_
; isEquivalence = ≋-isEquivalence
}
------------------------------------------------------------------------
-- Reasoning
module PosetReasoning where
open import Relation.Binary.Reasoning.PartialOrder poset public
module EqReasoning where
open import Relation.Binary.Reasoning.Setoid setoid public | {
"alphanum_fraction": 0.5335195531,
"avg_line_length": 28.8045977011,
"ext": "agda",
"hexsha": "198472e46fc6fcfddb940499ab182ad07aabfaf7",
"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": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "banacorn/bidirectional",
"max_forks_repo_path": "Data/List/Relation/Binary/Subset/DecSetoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "banacorn/bidirectional",
"max_issues_repo_path": "Data/List/Relation/Binary/Subset/DecSetoid.agda",
"max_line_length": 84,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "0c9a6e79c23192b28ddb07315b200a94ee900ca6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "banacorn/bidirectional",
"max_stars_repo_path": "Data/List/Relation/Binary/Subset/DecSetoid.agda",
"max_stars_repo_stars_event_max_datetime": "2020-08-25T14:05:01.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-08-25T07:34:40.000Z",
"num_tokens": 1820,
"size": 5012
} |
module Esterel.Variable.Signal where
open import Data.Nat
using (ℕ) renaming (_≟_ to _≟ℕ_)
open import Function
using (_∘_)
open import Relation.Nullary
using (Dec ; yes ; no ; ¬_)
open import Relation.Binary
using (Decidable)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; cong ; trans ; sym)
data Signal : Set where
_ₛ : (S : ℕ) → Signal
unwrap : Signal → ℕ
unwrap (n ₛ) = n
unwrap-inverse : ∀ {s} → (unwrap s) ₛ ≡ s
unwrap-inverse {_ ₛ} = refl
unwrap-injective : ∀ {s t} → unwrap s ≡ unwrap t → s ≡ t
unwrap-injective s'≡t' = trans (sym unwrap-inverse) (trans (cong _ₛ s'≡t') unwrap-inverse)
wrap : ℕ → Signal
wrap = _ₛ
bijective : ∀{x} → unwrap (wrap x) ≡ x
bijective = refl
-- for backward compatibility
unwrap-neq : ∀{k1 : Signal} → ∀{k2 : Signal} → ¬ k1 ≡ k2 → ¬ (unwrap k1) ≡ (unwrap k2)
unwrap-neq = (_∘ unwrap-injective)
_≟_ : Decidable {A = Signal} _≡_
(s ₛ) ≟ (t ₛ) with s ≟ℕ t
... | yes p = yes (cong _ₛ p)
... | no ¬p = no (¬p ∘ cong unwrap)
data Status : Set where
present : Status
absent : Status
unknown : Status
_≟ₛₜ_ : Decidable {A = Status} _≡_
present ≟ₛₜ present = yes refl
present ≟ₛₜ absent = no λ()
present ≟ₛₜ unknown = no λ()
absent ≟ₛₜ present = no λ()
absent ≟ₛₜ absent = yes refl
absent ≟ₛₜ unknown = no λ()
unknown ≟ₛₜ present = no λ()
unknown ≟ₛₜ absent = no λ()
unknown ≟ₛₜ unknown = yes refl
| {
"alphanum_fraction": 0.6433212996,
"avg_line_length": 24.7321428571,
"ext": "agda",
"hexsha": "75d5b62fad16ee91ab8fe95161b4e2c71795bc31",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/Esterel/Variable/Signal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/Esterel/Variable/Signal.agda",
"max_line_length": 90,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/Esterel/Variable/Signal.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": 529,
"size": 1385
} |
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.Semigroup.Arith.Base where
open import Fragment.Prelude public
open import Data.Nat using (ℕ; _*_; _+_) public
open import Data.Nat.Properties
using (*-isSemigroup; +-isSemigroup)
open import Relation.Binary.PropositionalEquality public
open ≡-Reasoning public
+-semigroup = semigroup→model +-isSemigroup
*-semigroup = semigroup→model *-isSemigroup
| {
"alphanum_fraction": 0.7710843373,
"avg_line_length": 27.6666666667,
"ext": "agda",
"hexsha": "3d66a0ac3f5b62dcf286e862b9efddd57f66b374",
"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/Examples/Semigroup/Arith/Base.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/Examples/Semigroup/Arith/Base.agda",
"max_line_length": 56,
"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/Examples/Semigroup/Arith/Base.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": 110,
"size": 415
} |
module Bound.Lower.Order {A : Set}(_≤_ : A → A → Set) where
open import Bound.Lower A
data LeB : Bound → Bound → Set where
lebx : {b : Bound}
→ LeB bot b
lexy : {a b : A}
→ a ≤ b
→ LeB (val a) (val b)
| {
"alphanum_fraction": 0.4444444444,
"avg_line_length": 19.2857142857,
"ext": "agda",
"hexsha": "86675c91302aadc0b5e1539909755dea1527a507",
"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/Bound/Lower/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/Bound/Lower/Order.agda",
"max_line_length": 59,
"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/Bound/Lower/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": 87,
"size": 270
} |
module Issue1078.A where -- The typo in the module name is intended!
open import Common.Level using (Level)
open import Issue1078A
test = Level
| {
"alphanum_fraction": 0.7739726027,
"avg_line_length": 20.8571428571,
"ext": "agda",
"hexsha": "d2c4c7b06ea92ef509a10550f7fdf4b6c5d92a5e",
"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/Issue1078/B.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/Issue1078/B.agda",
"max_line_length": 68,
"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/Issue1078/B.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 35,
"size": 146
} |
------------------------------------------------------------------------
-- A quotient inductive-inductive definition of the partiality monad
------------------------------------------------------------------------
{-# OPTIONS --erased-cubical --safe #-}
module Partiality-monad.Inductive where
import Equality.Path as P
open import Equality.Propositional.Cubical
open import Logical-equivalence using (_⇔_)
open import Prelude hiding (⊥)
open import Bijection equality-with-J using (_↔_)
open import Equivalence equality-with-J as Eq using (_≃_)
open import Function-universe equality-with-J hiding (id; _∘_)
open import H-level equality-with-J
open import H-level.Closure equality-with-J
open import Partiality-algebra as PA hiding (_∘_)
open import Partiality-algebra.Eliminators as PAE hiding (Arguments)
import Partiality-algebra.Properties
private
variable
a ℓ p q : Level
A : Type a
mutual
infix 10 _⊥
infix 4 _⊑_
-- Originally the monad was postulated. After the release of Cubical
-- Agda it was turned into a QIIT, but in order to not get any extra
-- computation rules it was made abstract.
abstract
-- The partiality monad.
data _⊥ (A : Type a) : Type a where
never : A ⊥
now : A → A ⊥
⨆ : Increasing-sequence A → A ⊥
antisymmetry : x ⊑ y → y ⊑ x → x P.≡ y
-- We have chosen to explicitly make the type set-truncated.
-- However, this constructor is mostly unused: it is used to
-- define partiality-algebra below (and the corresponding record
-- field is in turn also mostly unused, see its documentation
-- for details), and it is mentioned in the implementation of
-- eliminators (also below).
⊥-is-set-unused : P.Is-set (A ⊥)
-- Increasing sequences.
Increasing-sequence : Type ℓ → Type ℓ
Increasing-sequence A =
Σ (ℕ → A ⊥) λ f → ∀ n → f n ⊑ f (suc n)
-- Upper bounds.
Is-upper-bound :
{A : Type a} → Increasing-sequence A → A ⊥ → Type a
Is-upper-bound s x = ∀ n → (s [ n ]) ⊑ x
-- A projection function for Increasing-sequence.
infix 30 _[_]
_[_] : Increasing-sequence A → ℕ → A ⊥
_[_] s n = proj₁ {A = _ → _ ⊥} s n
private
variable
x y z : A ⊥
abstract
-- An ordering relation.
data _⊑_ {A : Type a} : A ⊥ → A ⊥ → Type a where
⊑-refl : ∀ x → x ⊑ x
⊑-trans : x ⊑ y → y ⊑ z → x ⊑ z
never⊑ : ∀ x → never ⊑ x
upper-bound : ∀ s → Is-upper-bound s (⨆ s)
least-upper-bound : ∀ s ub → Is-upper-bound s ub → ⨆ s ⊑ ub
⊑-propositional : P.Is-proposition (x ⊑ y)
-- A partiality algebra for the partiality monad.
partiality-algebra : ∀ {a} (A : Type a) → Partiality-algebra a a A
partiality-algebra A = record
{ T = A ⊥
; partiality-algebra-with = record
{ _⊑_ = _⊑_
; never = never′
; now = now′
; ⨆ = ⨆′
; antisymmetry = antisymmetry′
; T-is-set-unused = T-is-set-unused′
; ⊑-refl = ⊑-refl′
; ⊑-trans = ⊑-trans′
; never⊑ = never⊑′
; upper-bound = upper-bound′
; least-upper-bound = least-upper-bound′
; ⊑-propositional = ⊑-propositional′
}
}
where
abstract
never′ : A ⊥
never′ = never
now′ : A → A ⊥
now′ = now
⨆′ : Increasing-sequence A → A ⊥
⨆′ = ⨆
antisymmetry′ : x ⊑ y → y ⊑ x → x ≡ y
antisymmetry′ = λ p q → _↔_.from ≡↔≡ (antisymmetry p q)
T-is-set-unused′ : Is-set (A ⊥)
T-is-set-unused′ =
$⟨ (λ {x y} → ⊥-is-set-unused {x = x} {y = y}) ⟩
P.Is-set (A ⊥) ↝⟨ _↔_.from (H-level↔H-level 2) ⟩□
Is-set (A ⊥) □
⊑-refl′ : (x : A ⊥) → x ⊑ x
⊑-refl′ = ⊑-refl
⊑-trans′ : x ⊑ y → y ⊑ z → x ⊑ z
⊑-trans′ = ⊑-trans
never⊑′ : ∀ x → never′ ⊑ x
never⊑′ = never⊑
upper-bound′ : ∀ s → Is-upper-bound s (⨆′ s)
upper-bound′ = upper-bound
least-upper-bound′ : ∀ s ub → Is-upper-bound s ub → ⨆′ s ⊑ ub
least-upper-bound′ = least-upper-bound
⊑-propositional′ : Is-proposition (x ⊑ y)
⊑-propositional′ {x = x} {y = y} =
$⟨ ⊑-propositional ⟩
P.Is-proposition (x ⊑ y) ↝⟨ _↔_.from (H-level↔H-level 1) ⟩□
Is-proposition (x ⊑ y) □
abstract
-- The elimination principle.
eliminators : Elimination-principle p q (partiality-algebra A)
eliminators {A = A} args = record
{ ⊥-rec = ⊥-rec
; ⊑-rec = ⊑-rec
; ⊥-rec-never = refl
; ⊥-rec-now = λ _ → refl
; ⊥-rec-⨆ = λ _ → refl
}
where
module A = PAE.Arguments args
mutual
inc-rec : (s : Increasing-sequence A) → A.Inc A.P A.Q s
inc-rec (s , inc) = (λ n → ⊥-rec (s n))
, (λ n → ⊑-rec (inc n))
⊥-rec : (x : A ⊥) → A.P x
⊥-rec never = A.pe
⊥-rec (now x) = A.po x
⊥-rec (⨆ s) = A.pl s (inc-rec s)
⊥-rec (antisymmetry {x = x} {y = y} p q i) = subst≡→[]≡
{B = A.P}
{eq = antisymmetry p q}
(A.pa p q
(⊥-rec x) (⊥-rec y)
(⊑-rec p) (⊑-rec q))
i
⊥-rec (⊥-is-set-unused {x = x} {y = y} p q i j) = lemma i j
where
⊥-is-set-unused′ : P.Is-set (A ⊥)
⊥-is-set-unused′ = ⊥-is-set-unused
lemma :
P.[ (λ i → P.[ (λ j → A.P (⊥-is-set-unused′ p q i j)) ]
⊥-rec x ≡ ⊥-rec y) ]
(λ i → ⊥-rec (p i)) ≡ (λ i → ⊥-rec (q i))
lemma = P.heterogeneous-UIP
(λ x → _↔_.to (H-level↔H-level 2) (A.pp {x = x}))
(⊥-is-set-unused p q)
_ _
⊑-rec : (x⊑y : x ⊑ y) → A.Q (⊥-rec x) (⊥-rec y) x⊑y
⊑-rec (⊑-refl x) = A.qr x (⊥-rec x)
⊑-rec (⊑-trans {x = x} {y = y} {z = z} p q) = A.qt p q
(⊥-rec x) (⊥-rec y) (⊥-rec z)
(⊑-rec p) (⊑-rec q)
⊑-rec (never⊑ x) = A.qe x (⊥-rec x)
⊑-rec (upper-bound s n) = A.qu s (inc-rec s) n
⊑-rec (least-upper-bound s ub is-ub) = A.ql s ub is-ub
(inc-rec s) (⊥-rec ub)
(λ n → ⊑-rec {x = proj₁ s n}
(is-ub n))
⊑-rec (⊑-propositional {x = x} {y = y} p q i) = lemma i
where
⊑-propositional′ : P.Is-proposition (x ⊑ y)
⊑-propositional′ = ⊑-propositional
lemma : P.[ (λ i → A.Q (⊥-rec x) (⊥-rec y)
(⊑-propositional′ p q i)) ]
⊑-rec p ≡ ⊑-rec q
lemma =
P.heterogeneous-irrelevance
(λ p → _↔_.to (H-level↔H-level 1)
(A.qp (⊥-rec x) (⊥-rec y) p))
module _ {A : Type a} where
open Partiality-algebra (partiality-algebra A) public
hiding (T; _⊑_; _[_]; Increasing-sequence; Is-upper-bound)
renaming ( T-is-set to ⊥-is-set
; equality-characterisation-T to
equality-characterisation-⊥
)
open Partiality-algebra.Properties (partiality-algebra A) public
-- The eliminators' arguments.
Arguments : ∀ {a} p q (A : Type a) → Type (a ⊔ lsuc (p ⊔ q))
Arguments p q A = PAE.Arguments p q (partiality-algebra A)
module _ (args : Arguments p q A) where
open Eliminators (eliminators args) public
-- Initiality.
initial : Initial p q (partiality-algebra A)
initial = eliminators→initiality _ eliminators
| {
"alphanum_fraction": 0.4592729513,
"avg_line_length": 32.8542510121,
"ext": "agda",
"hexsha": "94f23fa758118a2a36a493e46abc24e25c0f358d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/partiality-monad",
"max_forks_repo_path": "src/Partiality-monad/Inductive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/partiality-monad",
"max_issues_repo_path": "src/Partiality-monad/Inductive.agda",
"max_line_length": 85,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "f69749280969f9093e5e13884c6feb0ad2506eae",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/partiality-monad",
"max_stars_repo_path": "src/Partiality-monad/Inductive.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-03T08:56:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:59:18.000Z",
"num_tokens": 2621,
"size": 8115
} |
module para where
module Top (A B : Set) where
module A (C D : Set) where
postulate f : A -> B -> C -> D
module B (E F : Set) = A F E renaming (f to j)
postulate h : A -> B
module C (G H : Set) where
module D = B G H
g' : A -> B
g' = h
g : A -> H -> G
g x y = D.j x (h x) y
module Bottom where
postulate
Nat : Set
zero : Nat
module D = Top Nat Nat
module C = D.C Nat Nat
x : Nat
x = C.g zero zero
| {
"alphanum_fraction": 0.5075921909,
"avg_line_length": 13.1714285714,
"ext": "agda",
"hexsha": "e6f8b4c1b631eff0c40f763c6c64b5945da9a667",
"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/para.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/para.agda",
"max_line_length": 48,
"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/para.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": 171,
"size": 461
} |
-------------------------------------------------------------------------------
--
-- SET (in Hedberg library) for agda2
-- as of 2006.9.29 morning
-- Yoshiki.
--
module SET where
----------------------------------------------------------------------------
-- Auxiliary.
----------------------------------------------------------------------------
-- no : (x : A) -> B : Set if A : Set B : Set
-- yes : (x : A) -> B type if A type B type
-- El M type if M : Set
data Unop (A : Set) : Set1 where
unopI : (A -> A) -> Unop A
data Pred (A : Set) : Set1 where
PredI : (A -> Set) -> Pred A
data Rel (A : Set) : Set1 where
RelI : (A -> A -> Set) -> Rel A
data Reflexive {A : Set} (R : A -> A -> Set) : Set where
reflexiveI : ((a : A) -> R a a) -> Reflexive R
data Symmetrical {A : Set} (R : A -> A -> Set) : Set where
symmetricalI : ({a b : A} -> R a b -> R a b) -> Symmetrical R
data Transitive {A : Set} (R : A -> A -> Set) : Set where
transitiveI : ({a b c : A} -> R a b -> R b c -> R a c) -> Transitive R
compositionalI :
{A : Set} -> (R : A -> A -> Set)
-> ({a b c : A} -> R b c -> R a b -> R a c) -> Transitive R
compositionalI {A} R f =
transitiveI (\{a b c : A} -> \(x : R a b) -> \(y : R b c) -> f y x)
data Substitutive {A : Set} (R : A -> A -> Set) : Set1 where
substitutiveI : ((P : A -> Set) -> {a b : A} -> R a b -> P a -> P b)
-> Substitutive R
data Collapsed (A : Set) : Set1 where
collapsedI : ((P : A -> Set) -> {a b : A} -> P a -> P b) -> Collapsed A
cmp : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
cmp f g a = f (g a)
seq : {A B C : Set} -> (A -> B) -> (B -> C) -> A -> C
seq f g = cmp g f
S : {A B C : Set} -> (C -> B -> A) -> (C -> B) -> C -> A
S x y z = x z (y z)
K : {A B : Set} -> A -> B -> A
K x y = x
I : {A : Set} -> A -> A
I a = a
-- of course I = S K K
id = \{A : Set} -> I {A}
const = \{A B : Set} -> K {A}{B}
-- Set version
pS : {P Q R : Set} -> (R -> Q -> P) -> (R -> Q) -> R -> P
pS x y z = x z (y z)
pK : {P Q : Set} -> P -> Q -> P
pK x y = x
pI : {P : Set} -> P -> P
pI a = a
proj : {A : Set} -> (B : A -> Set) -> (a : A) -> (f : (aa : A) -> B aa) -> B a
proj B a f = f a
flip : {A B C : Set} (f : A -> B -> C) (b : B) (a : A) -> C
flip f b a = f a b
-- separate definition of FlipRel is necessary because it is not the case
-- that Set : Set.
FlipRel : {A : Set} -> (R : A -> A -> Set) -> (a b : A) -> Set
FlipRel R a b = R b a
----------------------------------------------------------------------------
-- Product sets.
----------------------------------------------------------------------------
-- Prod : (A : Set) -> (A -> Set) -> Set
-- Prod A B = (a : A) -> B a
-- The above is not type-correct since (a : A) -> B a is not well-formed
-- but the following works.
data Prod (A : Set) (B : A -> Set) : Set where
prodI : ((a : A) -> B a) -> Prod A B
mapProd : {A : Set} -> {B C : A -> Set} -> ((a : A) -> B a -> C a)
-> Prod A B -> Prod A C
mapProd {A} f (prodI g) = prodI (\(a : A) -> f a (g a))
-- data Fun (A B : Set) : Set1 where
-- funI : (A -> B) -> Fun A B
Fun : Set -> Set -> Set
Fun A B = Prod A (\(_ : A) -> B)
mapFun : {A B C D : Set} -> (B -> A) -> (C -> D) -> (A -> C) -> B -> D
mapFun {A} {B} {C} {D} f g h x = g (h (f x))
-- mapFun (|X1 |X2 |Y1 |Y2 :: Set)
-- :: (X2 -> X1) -> (Y1 -> Y2) -> (X1 -> Y1) -> X2 -> Y2
-- = \f -> \g -> \h -> \x ->
-- g (h (f x))
---------------------------------------------------------------------------
-- Identity proof sets.
---------------------------------------------------------------------------
-- to accept the following definition more general scheme of
-- inductive definition is required
-- data Id (A : Set) (a b : A) : Set1 where
-- ref : (a : A) -> Id A a a
--
-- elimId (|X :: Set)
-- (C :: (x1 x2 :: X) |-> Id x1 x2 -> Set)
-- (refC :: (x :: X) -> C (refId x))
-- (|x1 |x2 :: X)
-- (u :: Id x1 x2) ::
-- C u
-- = case u of { (ref x) -> refC x;}
--
-- abstract whenId (|X :: Set)(C :: Rel X)(c :: (x :: X) -> C x x)
-- :: (x1 x2 :: X) |-> Id x1 x2 -> C x1 x2
-- = elimId (\x1 x2 |-> \(u :: Id x1 x2) -> C x1 x2) c
--
-- abstract substId (|X :: Set) :: Substitutive Id
-- = \(C :: Pred X) ->
-- whenId (\x1 x2 -> C x1 -> C x2) (\x -> id)
--
-- abstract mapId (|X :: Set)(|Y :: Set)(f :: X -> Y)
-- :: (x1 x2 :: X) |-> Id x1 x2 -> Id (f x1) (f x2)
-- = whenId (\x1 x2 -> Id (f x1) (f x2)) (\(x :: X) -> refId (f x))
--
-- abstract symId (|X :: Set) :: Symmetrical Id
-- = whenId (\(x1 x2 :: X) -> Id x2 x1) refId
--
-- abstract cmpId (|X :: Set) :: Compositional Id
-- = let lem :: (x y :: X) |-> Id x y -> (z :: X) |-> Id z x -> Id z y
-- = whenId ( \(x y :: _) -> (z :: X) |-> Id z x -> Id z y)
-- ( \x -> \z |-> id)
-- in \(x1 x2 x3 :: _) |->
-- \(u :: Id x2 x3) ->
-- \(v :: Id x1 x2) ->
-- lem u v
--
-- abstract tranId (|X :: Set) :: Transitive Id
-- = \(x1 x2 x3 :: X) |->
-- \(u :: Id x1 x2) ->
-- \(v :: Id x2 x3) ->
-- cmpId v u
----------------------------------------------------------------------------
-- The empty set.
----------------------------------------------------------------------------
data Zero : Set where
-- --abstract whenZero (X :: Set)(z :: Zero) :: X
-- -- = case z of { }
-- do not know how to encode whenZero; the following does not work.
-- whenZero : (X : Set) -> (z : Zero) -> X
-- whenZero X z =
-- --elimZero (C :: Zero -> Set)(z :: Zero) :: C z
-- -- = case z of { }
-- elimZero either!
-- elimZero : (C : Zero -> Set) -> (z : Zero) -> C z
-- elimZero C z =
--
-- abstract collZero :: Collapsed Zero
-- = \(C :: Zero -> Set) ->
-- \(z1 z2 :: Zero) |->
-- \(c :: C z1) ->
-- case z1 of { }
--
----------------------------------------------------------------------------
-- The singleton set.
----------------------------------------------------------------------------
data Unit : Set where
uu : Unit
elUnit = uu
elimUnit : (C : Unit -> Set) -> C uu -> (u : Unit) -> C u
elimUnit C c uu = c
-- Do not know of the exact use of Collapse!
-- collUnit : (C : Unit -> Set) -> {u1 u2 : Unit} -> C u1 -> Collapsed Unit
-- collUnit C {uu} {uu} A = collapsedI (\(P : Unit -> Set) -> \{a b : Unit} -> \(y : P a) -> A)
-- abstract collUnit :: Collapsed Unit
-- = \(C :: Unit -> Set) ->
-- \(u1 u2 :: Unit) |->
-- \(c :: C u1) ->
-- case u1 of { (tt) -> case u2 of { (tt) -> c;};}
---------------------------------------------------------------------------
-- The successor set adds a new element.
---------------------------------------------------------------------------
data Succ (A : Set) : Set where
zerS : Succ A
sucS : A -> Succ A
zerSucc = \{A : Set} -> zerS {A}
sucSucc = \{A : Set} -> sucS {A}
elimSucc : {X : Set} -> (C : Succ X -> Set)
-> C zerS -> ((x : X) -> C (sucS x)) -> (xx : Succ X) -> (C xx)
elimSucc C c_z c_s zerS = c_z
elimSucc C c_z c_s (sucS x) = c_s x
whenSucc : {X Y : Set} -> Y -> (X -> Y) -> (Succ X) -> Y
whenSucc y_z y_s zerS = y_z
whenSucc y_z y_s (sucS x) = y_s x
mapSucc : {X Y : Set} -> (X -> Y) -> Succ X -> Succ Y
mapSucc {X} {_} f
= whenSucc zerS (\(x : X) -> sucS (f x))
---------------------------------------------------------------------------
-- The (binary) disjoint union.
---------------------------------------------------------------------------
data Plus (A B : Set) : Set where
inl : A -> Plus A B
inr : B -> Plus A B
elimPlus : {X Y : Set} ->
(C : Plus X Y -> Set) ->
((x : X) -> C (inl x)) ->
((y : Y) -> C (inr y)) ->
(z : Plus X Y) ->
C z
elimPlus {X} {Y} C c_lft c_rgt (inl x) = c_lft x
elimPlus {X} {Y} C c_lft c_rgt (inr x) = c_rgt x
when : {X Y Z : Set} -> (X -> Z) -> (Y -> Z) -> Plus X Y -> Z
when {X} {Y} {Z} f g (inl x) = f x
when {X} {Y} {Z} f g (inr y) = g y
whenplus : {X Y Z : Set} -> (X -> Z) -> (Y -> Z) -> Plus X Y -> Z
whenplus = when
mapPlus : {X1 X2 Y1 Y2 : Set} -> (X1 -> X2) -> (Y1 -> Y2)
-> Plus X1 Y1 -> Plus X2 Y2
mapPlus f g = when (\x1 -> inl (f x1)) (\y1 -> inr (g y1))
swapPlus : {X Y : Set} -> Plus X Y -> Plus Y X
swapPlus = when inr inl
----------------------------------------------------------------------------
-- Dependent pairs.
----------------------------------------------------------------------------
data Sum (A : Set) (B : A -> Set) : Set where
sumI : (fst : A) -> B fst -> Sum A B
depPair : {A : Set} -> {B : A -> Set} -> (a : A) -> B a -> Sum A B
depPair a b = sumI a b
depFst : {A : Set} -> {B : A -> Set} -> (c : Sum A B) -> A
depFst (sumI fst snd) = fst
depSnd : {A : Set} -> {B : A -> Set} -> (c : Sum A B) -> B (depFst c)
depSnd (sumI fst snd) = snd
depCur : {A : Set} -> {B : A -> Set} -> {C : Set} -> (f : Sum A B -> C)
-> (a : A) -> B a -> C
depCur f = \a -> \b -> f (depPair a b)
-- the above works but the below does not---why?
-- depCur : {X : Set} -> {Y : X -> Set} -> {Z : Set} -> (f : Sum X Y -> Z)
-- -> {x : X} -> Y x -> Z
-- depCur {X} {Y} {Z} f = \{x} -> \y -> f (depPair x y)
-- Error message :
-- When checking that the expression \{x} -> \y -> f (depPair x y)
-- has type Y _x -> Z
-- found an implicit lambda where an explicit lambda was expected
depUncur : {A : Set} -> {B : A -> Set} -> {C : Set}
-> ((a : A) -> B a -> C) -> Sum A B -> C
depUncur f ab = f (depFst ab) (depSnd ab)
depCurry : {A : Set} ->
{B : A -> Set} ->
{C : Sum A B -> Set} ->
(f : (ab : Sum A B) -> C ab) ->
(a : A) ->
(b : B a) ->
C (depPair a b)
depCurry f a b = f (depPair a b)
depUncurry : {A : Set} ->
{B : A -> Set} ->
{C : Sum A B -> Set} ->
(f : (a : A) -> (b : B a) -> C (depPair a b)) ->
(ab : Sum A B) ->
C ab
depUncurry f (sumI fst snd) = f fst snd
mapSum : {A : Set} -> {B1 : A -> Set} -> {B2 : A -> Set}
-> (f : (a : A) -> B1 a -> B2 a)
-> Sum A B1 -> Sum A B2
mapSum f (sumI fst snd) = depPair fst (f fst snd)
elimSum = \{A : Set}{B : A -> Set}{C : Sum A B -> Set} -> depUncurry{A}{B}{C}
---------------------------------------------------------------------------
-- Nondependent pairs (binary) cartesian product.
---------------------------------------------------------------------------
Times : Set -> Set -> Set
Times A B = Sum A (\(_ : A) -> B)
pair : {A : Set} -> {B : Set} -> A -> B -> Times A B
pair a b = sumI a b
fst : {A : Set} -> {B : Set} -> Times A B -> A
fst (sumI a _) = a
snd : {A : Set} -> {B : Set} -> Times A B -> B
snd (sumI _ b) = b
pairfun : {C : Set} -> {A : Set} -> {B : Set}
-> (C -> A) -> (C -> B) -> C -> Times A B
pairfun f g c = pair (f c) (g c)
mapTimes : {A1 : Set} -> {A2 : Set} -> {B1 : Set} -> {B2 : Set}
-> (A1 -> A2) -> (B1 -> B2) -> Times A1 B1 -> Times A2 B2
mapTimes f g (sumI a b) = pair (f a) (g b)
swapTimes : {A : Set} -> {B : Set} -> Times A B -> Times B A
swapTimes (sumI a b) = sumI b a
cur : {A : Set} -> {B : Set} -> {C : Set} -> (f : Times A B -> C) -> A -> B -> C
cur f a b = f (pair a b)
uncur : {A : Set} -> {B : Set} -> {C : Set} -> (A -> B -> C) -> Times A B -> C
uncur f (sumI a b) = f a b
curry : {A : Set} -> {B : Set} -> {C : Times A B -> Set}
-> ((p : Times A B) -> C p) -> (a : A) ->(b : B) -> C (pair a b)
curry f a b = f (pair a b)
uncurry : {A : Set} -> {B : Set} -> {C : Times A B -> Set}
-> ((a : A) -> (b : B) -> C (pair a b)) -> (p : Times A B) -> C p
uncurry f (sumI a b) = f a b
elimTimes = \{A B : Set}{C : Times A B -> Set} -> uncurry{A}{B}{C}
---------------------------------------------------------------------------
-- Natural numbers.
---------------------------------------------------------------------------
data Nat : Set where
zero : Nat
succ : Nat -> Nat
elimNat : (C : Nat -> Set)
-> (C zero) -> ((m : Nat) -> C m -> C (succ m)) -> (n : Nat) -> C n
elimNat C c_z c_s zero = c_z
elimNat C c_z c_s (succ m') = c_s m' (elimNat C c_z c_s m')
----------------------------------------------------------------------------
-- Linear universe of finite sets.
----------------------------------------------------------------------------
Fin : (m : Nat) -> Set
Fin zero = Zero
Fin (succ n) = Succ (Fin n)
{-
Fin 0 = {}
Fin 1 = { zerS }
Fin 2 = { zerS (sucS zerS) }
Fin 3 = { zerS (sucS zerS) (sucS (sucS zerS)) }
-}
valFin : (n' : Nat) -> Fin n' -> Nat
valFin zero ()
valFin (succ n) zerS = zero
valFin (succ n) (sucS x) = succ (valFin n x)
zeroFin : (n : Nat) -> Fin (succ n)
zeroFin n = zerS
succFin : (n : Nat) -> Fin n -> Fin (succ n)
succFin n N = sucS N
----------------------------------------------------------------------------
-- Do these really belong here?
----------------------------------------------------------------------------
HEAD : {A : Set} -> (n : Nat) -> (Fin (succ n) -> A) -> A
HEAD n f = f (zeroFin n)
TAIL : {A : Set} -> (n : Nat) -> (Fin (succ n) -> A) -> Fin n -> A
TAIL n f N = f (succFin n N)
----------------------------------------------------------------------------
-- Lists.
----------------------------------------------------------------------------
data List (A : Set) : Set where
nil : List A
con : A -> List A -> List A
elimList : {A : Set} ->
(C : List A -> Set) ->
(C nil) ->
((a : A) -> (as : List A) -> C as -> C (con a as)) ->
(as : List A) ->
C as
elimList _ c_nil _ nil = c_nil
elimList C c_nil c_con (con a as) = c_con a as (elimList C c_nil c_con as)
----------------------------------------------------------------------------
-- Tuples are "dependently typed vectors".
----------------------------------------------------------------------------
data Nill : Set where
nill : Nill
data Cons (A B : Set) : Set where
cons : A -> B -> Cons A B
Tuple : (n : Nat) -> (C : Fin n -> Set) -> Set
Tuple zero = \ C -> Nill
Tuple (succ n) = \ C -> Cons (C zerS) (Tuple n (\(N : Fin n) -> C (sucS N)))
----------------------------------------------------------------------------
-- Vectors homogeneously typed tuples.
----------------------------------------------------------------------------
Vec : Set -> Nat -> Set
Vec A m = Tuple m (\(n : Fin m) -> A)
----------------------------------------------------------------------------
-- Monoidal expressions.
----------------------------------------------------------------------------
data Mon (A : Set) : Set where
unit : Mon A
at : A -> Mon A
mul : Mon A -> Mon A -> Mon A
{-
-}
----------------------------------------------------------------------------
-- Propositions.
----------------------------------------------------------------------------
data Implies (A B : Set) : Set where
impliesI : (A -> B) -> Implies A B
data Absurd : Set where
data Taut : Set where
tt : Taut
data Not (P : Set) : Set where
notI : (P -> Absurd) -> Not P
-- encoding of Exists is unsatisfactory! Its type should be Set.
data Exists (A : Set) (P : A -> Set) : Set where
existsI : (evidence : A) -> P evidence -> Exists A P
data Forall (A : Set) (P : A -> Set) : Set where
forallI : ((a : A) -> P a) -> Forall A P
data And (A B : Set) : Set where
andI : A -> B -> And A B
Iff : Set -> Set -> Set
Iff A B = And (Implies A B) (Implies B A)
data Or (A B : Set) : Set where
orIl : (a : A) -> Or A B
orIr : (b : B) -> Or A B
Decidable : Set -> Set
Decidable P = Or P (Implies P Absurd)
data DecidablePred {A : Set} (P : A -> Set) : Set where
decidablepredIl : (a : A) -> (P a) -> DecidablePred P
decidablepredIr : (a : A) -> (Implies (P a) Absurd) -> DecidablePred P
data DecidableRel {A : Set} (R : A -> A -> Set) : Set where
decidablerelIl : (a b : A) -> (R a b) -> DecidableRel R
decidablerelIr : (a b : A) -> (Implies (R a b) Absurd) -> DecidableRel R
data Least {A : Set} (_<=_ : A -> A -> Set) (P : A -> Set) (a : A) : Set where
leastI : (P a) -> ((aa : A) -> P aa -> (a <= aa)) -> Least _<=_ P a
data Greatest {A : Set} (_<=_ : A -> A -> Set) (P : A -> Set) (a : A) : Set where
greatestI : (P a) -> ((aa : A) -> P aa -> (aa <= a)) -> Greatest _<=_ P a
----------------------------------------------------------------------------
-- Booleans.
----------------------------------------------------------------------------
data Bool : Set where
true : Bool
false : Bool
elimBool : (C : Bool -> Set) -> C true -> C false -> (b : Bool) -> C b
elimBool C c_t c_f true = c_t
elimBool C c_t c_f false = c_f
whenBool : (C : Set) -> C -> C -> Bool -> C
whenBool C c_t c_f b = elimBool (\(_ : Bool) -> C) c_t c_f b
data pred (A : Set) : Set where
predI : (A -> Bool) -> pred A
data rel (A : Set) : Set where
relI : (A -> A -> Bool) -> rel A
True : Bool -> Set
True true = Taut
True false = Absurd
bool2set = True
pred2Pred : {A : Set} -> pred A -> Pred A
pred2Pred (predI p) = PredI (\a -> True (p a))
rel2Rel : {A : Set} -> rel A -> Rel A
rel2Rel (relI r) = RelI (\a -> \b -> True (r a b))
-- decTrue : (p : Bool) -> Decidable (True p)
-- decTrue true = orIl tt
-- decTrue false = orIr (impliesI pI)
-- decTrue false = orIr (impliesI (\(p : (True false)) -> p))
-- dec_lem : {P : Set} -> (decP : Decidable P)
-- -> Exists A
{-
abstract dec_lem (|P :: Set)(decP :: Decidable P)
:: Exist |_ (\(b :: Bool) -> Iff (True b) P)
= case decP of {
(inl trueP) ->
struct {
fst = true@_;
snd =
struct {
fst = const |_ |_ trueP; -- (True true@_)
snd = const |_ |_ tt;};};
(inr notP) ->
struct {
fst = false@_;
snd =
struct {
fst = whenZero P;
snd = notP;};};}
dec2bool :: (P :: Set) |-> (decP :: Decidable P) -> Bool
= \(P :: Set) |-> \(decP :: Decidable P) -> (dec_lem |_ decP).fst
dec2bool_spec (|P :: Set)(decP :: Decidable P)
:: Iff (True (dec2bool |_ decP)) P
= (dec_lem |_ decP).snd
abstract collTrue :: (b :: Bool) -> Collapsed (True b)
= let aux (X :: Set)(C :: X -> Set)
:: (b :: Bool) ->
(f :: True b -> X) ->
(t1 :: True b) |->
(t2 :: True b) |->
C (f t1) -> C (f t2)
= \(b :: Bool) ->
case b of {
(true) ->
\(f :: (x :: True true@_) -> X) ->
\(t1 t2 :: True true@_) |->
\(c :: C (f t1)) ->
case t1 of { (tt) -> case t2 of { (tt) -> c;};};
(false) ->
\(f :: (x :: True false@_) -> X) ->
\(t1 t2 :: True false@_) |->
\(c :: C (f t1)) ->
case t1 of { };}
in \(b :: Bool) -> \(P :: True b -> Set) -> aux (True b) P b id
bool2nat (p :: Bool) :: Nat
= case p of {
(true) -> succ zero;
(false) -> zero;}
-}
| {
"alphanum_fraction": 0.3778459964,
"avg_line_length": 39.2469879518,
"ext": "agda",
"hexsha": "41ace045c22719b170bc52d16bb68c3dcfa41862",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/AIM5/yoshiki/SET.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/AIM5/yoshiki/SET.agda",
"max_line_length": 96,
"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/AIM5/yoshiki/SET.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": 6569,
"size": 19545
} |
-- Andreas, 2014-09-23
module _ where
syntax c x = ⟦ x ⟧
syntax c x y = x + y
-- Should complain about multiple notations.
| {
"alphanum_fraction": 0.6484375,
"avg_line_length": 14.2222222222,
"ext": "agda",
"hexsha": "69eae2ff9b9ff531f09242c2a577df12533ed190",
"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/MultipleNotations.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/MultipleNotations.agda",
"max_line_length": 44,
"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/MultipleNotations.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": 43,
"size": 128
} |
-- An Agda example file
module test where
open import Coinduction
open import Data.Bool
open import {- pointless comment between import and module name -} Data.Char
open import Data.Nat
open import Data.Nat.Properties
open import Data.String
open import Data.List hiding ([_])
open import Data.Vec hiding ([_])
open import Relation.Nullary.Core
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong; trans; inspect; [_])
open SemiringSolver
{- this is a {- nested -} comment -}
-- Factorial
_! : ℕ → ℕ
0 ! = 1
(suc n) ! = (suc n) * n !
-- The binomial coefficient
_choose_ : ℕ → ℕ → ℕ
_ choose 0 = 1
0 choose _ = 0
(suc n) choose (suc m) = (n choose m) + (n choose (suc m)) -- Pascal's rule
choose-too-many : ∀ n m → n ≤ m → n choose (suc m) ≡ 0
choose-too-many .0 m z≤n = refl
choose-too-many (suc n) (suc m) (s≤s le) with n choose (suc m) | choose-too-many n m le | n choose (suc (suc m)) | choose-too-many n (suc m) (≤-step le)
... | .0 | refl | .0 | refl = refl
_++'_ : ∀ {a n m} {A : Set a} → Vec A n → Vec A m → Vec A (m + n)
_++'_ {_} {n} {m} v₁ v₂ rewrite solve 2 (λ a b → b :+ a := a :+ b) refl n m = v₁ Data.Vec.++ v₂
++'-test : (1 ∷ 2 ∷ 3 ∷ []) ++' (4 ∷ 5 ∷ []) ≡ (1 ∷ 2 ∷ 3 ∷ 4 ∷ 5 ∷ [])
++'-test = refl
data Coℕ : Set where
co0 : Coℕ
cosuc : ∞ Coℕ → Coℕ
nanana : Coℕ
nanana = let two = ♯ cosuc (♯ (cosuc (♯ co0))) in cosuc two
abstract
data VacuumCleaner : Set where
Roomba : VacuumCleaner
pointlessLemmaAboutBoolFunctions : (f : Bool → Bool) → f (f (f true)) ≡ f true
pointlessLemmaAboutBoolFunctions f with f true | inspect f true
... | true | [ eq₁ ] = trans (cong f eq₁) eq₁
... | false | [ eq₁ ] with f false | inspect f false
... | true | _ = eq₁
... | false | [ eq₂ ] = eq₂
mutual
isEven : ℕ → Bool
isEven 0 = true
isEven (suc n) = not (isOdd n)
isOdd : ℕ → Bool
isOdd 0 = false
isOdd (suc n) = not (isEven n)
foo : String
foo = "Hello World!"
nl : Char
nl = '\n'
private
intersperseString : Char → List String → String
intersperseString c [] = ""
intersperseString c (x ∷ xs) = Data.List.foldl (λ a b → a Data.String.++ Data.String.fromList (c ∷ []) Data.String.++ b) x xs
baz : String
baz = intersperseString nl (Data.List.replicate 5 foo)
postulate
Float : Set
{-# BUILTIN FLOAT Float #-}
pi : Float
pi = 3.141593
-- Astronomical unit
au : Float
au = 1.496e11 -- m
plusFloat : Float → Float → Float
plusFloat a b = {! !}
record Subset (A : Set) (P : A → Set) : Set where
constructor _#_
field
elem : A
.proof : P elem
| {
"alphanum_fraction": 0.6082877248,
"avg_line_length": 24.8349514563,
"ext": "agda",
"hexsha": "d930a77b6abbd22305d4945b4169cee9ab1a80f0",
"lang": "Agda",
"max_forks_count": 16,
"max_forks_repo_forks_event_max_datetime": "2021-02-14T10:05:12.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-06T20:43:39.000Z",
"max_forks_repo_head_hexsha": "b8bf8ef1bc30999223deb95506b0685b4ec8449a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agent010101/agent010101.github.io",
"max_forks_repo_path": "vendor/bundle/ruby/2.0.0/gems/pygments.rb-0.6.1/vendor/pygments-main/tests/examplefiles/test.agda",
"max_issues_count": 34,
"max_issues_repo_head_hexsha": "b8bf8ef1bc30999223deb95506b0685b4ec8449a",
"max_issues_repo_issues_event_max_datetime": "2019-01-28T14:30:46.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-12T17:54:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agent010101/agent010101.github.io",
"max_issues_repo_path": "vendor/bundle/ruby/2.0.0/gems/pygments.rb-0.6.1/vendor/pygments-main/tests/examplefiles/test.agda",
"max_line_length": 152,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "b8bf8ef1bc30999223deb95506b0685b4ec8449a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agent010101/agent010101.github.io",
"max_stars_repo_path": "vendor/bundle/ruby/2.0.0/gems/pygments.rb-0.6.1/vendor/pygments-main/tests/examplefiles/test.agda",
"max_stars_repo_stars_event_max_datetime": "2017-08-25T17:11:52.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-02-17T18:34:15.000Z",
"num_tokens": 922,
"size": 2558
} |
module Monad where
module Prelude where
infixl 40 _∘_
id : {A : Set} -> A -> A
id x = x
_∘_ : {A B C : Set} -> (B -> C) -> (A -> B) -> A -> C
f ∘ g = \x -> f (g x)
data Nat : Set where
zero : Nat
suc : Nat -> Nat
module Base where
data Monad (M : Set -> Set) : Set1 where
monad : (return : {A : Set} -> A -> M A) ->
(bind : {A B : Set} -> M A -> (A -> M B) -> M B) ->
Monad M
monadReturn : {M : Set -> Set} -> Monad M -> {A : Set} -> A -> M A
monadReturn (monad ret bind) = ret
monadBind : {M : Set -> Set} -> Monad M -> {A B : Set} -> M A -> (A -> M B) -> M B
monadBind (monad ret bind) = bind
module Monad {M : Set -> Set}(monadM : Base.Monad M) where
open Prelude
infixl 15 _>>=_
-- Return and bind --------------------------------------------------------
return : {A : Set} -> A -> M A
return = Base.monadReturn monadM
_>>=_ : {A B : Set} -> M A -> (A -> M B) -> M B
_>>=_ = Base.monadBind monadM
-- Other operations -------------------------------------------------------
liftM : {A B : Set} -> (A -> B) -> M A -> M B
liftM f m = m >>= return ∘ f
module List where
infixr 20 _++_ _::_
-- The list datatype ------------------------------------------------------
data List (A : Set) : Set where
nil : List A
_::_ : A -> List A -> List A
-- Some list operations ---------------------------------------------------
foldr : {A B : Set} -> (A -> B -> B) -> B -> List A -> B
foldr f e nil = e
foldr f e (x :: xs) = f x (foldr f e xs)
map : {A B : Set} -> (A -> B) -> List A -> List B
map f nil = nil
map f (x :: xs) = f x :: map f xs
_++_ : {A : Set} -> List A -> List A -> List A
nil ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
concat : {A : Set} -> List (List A) -> List A
concat = foldr _++_ nil
-- List is a monad --------------------------------------------------------
open Base
monadList : Monad List
monadList = monad ret bind
where
ret : {A : Set} -> A -> List A
ret x = x :: nil
bind : {A B : Set} -> List A -> (A -> List B) -> List B
bind xs f = concat (map f xs)
open Prelude
open List
module MonadList = Monad monadList
open MonadList
| {
"alphanum_fraction": 0.4249779347,
"avg_line_length": 23.8526315789,
"ext": "agda",
"hexsha": "6485e98e7a328f4fa11353347b8d0a8631b3ba5d",
"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/Monad.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/Monad.agda",
"max_line_length": 84,
"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/Monad.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": 746,
"size": 2266
} |
module Highlighting.M where
postulate
ℕ : Set
_+_ _*_ : (x y : ℕ) → ℕ
| {
"alphanum_fraction": 0.6,
"avg_line_length": 12.5,
"ext": "agda",
"hexsha": "692b79adecf24e0ecd82059b408deb40ec72237e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Highlighting/M.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Highlighting/M.agda",
"max_line_length": 27,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Highlighting/M.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 29,
"size": 75
} |
module Definitions where
data _∨_ (A B : Set) : Set where
inl : A → A ∨ B
inr : B → A ∨ B
data _∧_ (A B : Set) : Set where
_,_ : A → B → A ∧ B
data ⊥ : Set where
¬_ : Set → Set
¬ A = A → ⊥
| {
"alphanum_fraction": 0.4974874372,
"avg_line_length": 14.2142857143,
"ext": "agda",
"hexsha": "5bd6195a619d6550acefca50f0b9beafe63cb1c6",
"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": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "danr/agder",
"max_forks_repo_path": "problems/DeMorgan/Definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"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": "danr/agder",
"max_issues_repo_path": "problems/DeMorgan/Definitions.agda",
"max_line_length": 32,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ece25bed081a24f02e9f85056d05933eae2afabf",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "danr/agder",
"max_stars_repo_path": "problems/DeMorgan/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-17T12:07:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-17T12:07:03.000Z",
"num_tokens": 90,
"size": 199
} |
{-# OPTIONS --without-K #-}
module equality.calculus where
open import sum using (Σ ; _,_ ; proj₁; proj₂)
open import equality.core
open import equality.groupoid public
open import function.core
ap' : ∀ {i j} {X : Set i}{Y : X → Set j}
{x x' : X}(f : (x : X) → Y x)(p : x ≡ x')
→ subst Y p (f x) ≡ f x'
ap' _ refl = refl
subst-naturality : ∀ {i i' j} {X : Set i} {Y : Set i'}
{x x' : X} (P : Y → Set j)
(f : X → Y)(p : x ≡ x')(u : P (f x))
→ subst (P ∘ f) p u ≡ subst P (ap f p) u
subst-naturality _ _ refl _ = refl
subst-hom : ∀ {i j}{X : Set i}(P : X → Set j){x y z : X}
→ (p : x ≡ y)(q : y ≡ z)(u : P x)
→ subst P q (subst P p u) ≡ subst P (p · q) u
subst-hom _ refl q u = refl
subst-eq : ∀ {i} {X : Set i}{x y z : X}
→ (p : y ≡ x)(q : y ≡ z)
→ subst (λ y → y ≡ z) p q
≡ sym p · q
subst-eq refl _ = refl
subst-eq₂ : ∀ {i} {X : Set i}{x y : X}
→ (p : x ≡ y)
→ (q : x ≡ x)
→ subst (λ z → z ≡ z) p q ≡ sym p · q · p
subst-eq₂ refl q = sym (left-unit _)
subst-const : ∀ {i j} {A : Set i}{X : Set j}
→ {a a' : A}(p : a ≡ a')(x : X)
→ subst (λ _ → X) p x ≡ x
subst-const refl x = refl
subst-const-ap : ∀ {i j} {A : Set i}{X : Set j}
→ {a a' : A}(f : A → X)(p : a ≡ a')
→ ap' f p ≡ subst-const p (f a) · ap f p
subst-const-ap f refl = refl
apΣ : ∀ {i j}{A : Set i}{B : A → Set j}
{x x' : Σ A B}
→ (p : x ≡ x')
→ Σ (proj₁ x ≡ proj₁ x') λ q
→ subst B q (proj₂ x) ≡ proj₂ x'
apΣ {B = B} p =
J (λ x x' p → Σ (proj₁ x ≡ proj₁ x') λ q
→ subst B q (proj₂ x) ≡ proj₂ x')
(λ x → refl , refl)
_ _ p
unapΣ : ∀ {i j}{A : Set i}{B : A → Set j}
{a a' : A}{b : B a}{b' : B a'}
→ (Σ (a ≡ a') λ q → subst B q b ≡ b')
→ (a , b) ≡ (a' , b')
unapΣ (refl , refl) = refl
pair≡ : ∀ {i j}{A : Set i}{B : Set j}
{a a' : A}{b b' : B}
→ (a ≡ a') → (b ≡ b')
→ (a , b) ≡ (a' , b')
pair≡ refl refl = refl
apΣ-proj : ∀ {i j}{A : Set i}{B : A → Set j}
{a a' : A}{b : B a}{b' : B a'}
(p : (a , b) ≡ (a' , b'))
→ proj₁ (apΣ p)
≡ ap proj₁ p
apΣ-proj =
J (λ _ _ p → proj₁ (apΣ p) ≡ ap proj₁ p)
(λ x → refl) _ _
apΣ-sym : ∀ {i j}{A : Set i}{B : A → Set j}
{a a' : A}{b : B a}{b' : B a'}
(p : (a , b) ≡ (a' , b'))
→ proj₁ (apΣ (sym p))
≡ sym (proj₁ (apΣ p))
apΣ-sym =
J (λ _ _ p → proj₁ (apΣ (sym p))
≡ sym (proj₁ (apΣ p)))
(λ x → refl) _ _
subst-ap : ∀ {i j}{A : Set i}{B : Set j}{a a' : A}
→ (f : A → B)
→ (p : a ≡ a')
→ ap f (sym p)
≡ subst (λ x → f x ≡ f a) p refl
subst-ap f refl = refl
ap-map-id : ∀ {i j}{X : Set i}{Y : Set j}{x : X}
→ (f : X → Y)
→ ap f (refl {x = x}) ≡ refl {x = f x}
ap-map-id f = refl
ap-map-hom : ∀ {i j}{X : Set i}{Y : Set j}{x y z : X}
→ (f : X → Y)(p : x ≡ y)(q : y ≡ z)
→ ap f (p · q) ≡ ap f p · ap f q
ap-map-hom f refl _ = refl
ap-id : ∀ {l} {A : Set l}{x y : A}(p : x ≡ y)
→ ap id p ≡ p
ap-id refl = refl
ap-hom : ∀ {l m n} {A : Set l}{B : Set m}{C : Set n}
{x y : A}(f : A → B)(g : B → C)(p : x ≡ y)
→ ap g (ap f p) ≡ ap (g ∘ f) p
ap-hom f g refl = refl
ap-inv : ∀ {i j} {X : Set i} {Y : Set j}
→ {x x' : X}
→ (f : X → Y)(p : x ≡ x')
→ ap f (sym p) ≡ sym (ap f p)
ap-inv f refl = refl
double-inverse : ∀ {i} {X : Set i} {x y : X}
(p : x ≡ y) → sym (sym p) ≡ p
double-inverse refl = refl
inverse-comp : ∀ {i} {X : Set i} {x y z : X}
(p : x ≡ y)(q : y ≡ z)
→ sym (p · q) ≡ sym q · sym p
inverse-comp refl q = sym (left-unit (sym q))
inverse-unique : ∀ {i} {X : Set i} {x y : X}
(p : x ≡ y)(q : y ≡ x)
→ p · q ≡ refl
→ sym p ≡ q
inverse-unique refl q t = sym t
| {
"alphanum_fraction": 0.3852255825,
"avg_line_length": 29.8814814815,
"ext": "agda",
"hexsha": "1ea1053198fbbda4e42a6ada3aee20604950487e",
"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": "equality/calculus.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": "equality/calculus.agda",
"max_line_length": 57,
"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": "equality/calculus.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": 1691,
"size": 4034
} |
open import Relation.Nullary.Decidable using (False)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong; module ≡-Reasoning)
open import Data.List using (List)
open List
open import Data.Unit using (tt)
module AKS.Binary.Base where
open import Polynomial.Simple.AlmostCommutativeRing using (AlmostCommutativeRing)
open import Polynomial.Simple.AlmostCommutativeRing.Instances using (module Nat)
open Nat.Reflection using (∀⟨_⟩)
open import AKS.Nat using (ℕ; _+_; _*_; _≟_; _<_; lte; suc-mono-≤)
open ℕ
open import AKS.Nat using (ℕ⁺; ℕ+; ⟅_⇑⟆)
open import AKS.Nat using (Euclidean; Euclidean✓; _div_)
open import AKS.Nat using (Acc; acc; <-well-founded)
2* : ℕ → ℕ
2* n = n + n
infixl 5 _0ᵇ _1ᵇ
data 𝔹⁺ : Set where
𝕓1ᵇ : 𝔹⁺
_0ᵇ _1ᵇ : 𝔹⁺ → 𝔹⁺
infixr 4 +_
data 𝔹 : Set where
𝕓0ᵇ : 𝔹
+_ : 𝔹⁺ → 𝔹
⟦_⇓⟧⁺ : 𝔹⁺ → ℕ
⟦ 𝕓1ᵇ ⇓⟧⁺ = 1
⟦ x 0ᵇ ⇓⟧⁺ = 2* ⟦ x ⇓⟧⁺
⟦ x 1ᵇ ⇓⟧⁺ = 1 + 2* ⟦ x ⇓⟧⁺
⟦_⇓⟧ : 𝔹 → ℕ
⟦ 𝕓0ᵇ ⇓⟧ = 0
⟦ + x ⇓⟧ = ⟦ x ⇓⟧⁺
private
lemma₁ : ∀ {q} → suc q < suc (q + suc (q + zero))
lemma₁ {q} = lte q (∀⟨ q ∷ [] ⟩)
lemma₂ : ∀ {q} → suc q < suc (suc (q + suc (q + zero)))
lemma₂ {q} = lte (suc q) (∀⟨ q ∷ [] ⟩)
⟦_⇑_⟧ʰ : ∀ n → Acc _<_ n → ∀ {≢0 : False (n ≟ 0)} → 𝔹⁺
⟦ suc n ⇑ acc downward ⟧ʰ with suc n div 2
... | Euclidean✓ (suc q) 0 refl r<m = ⟦ suc q ⇑ downward lemma₁ ⟧ʰ 0ᵇ
... | Euclidean✓ zero 1 refl r<m = 𝕓1ᵇ
... | Euclidean✓ (suc q) 1 refl r<m = ⟦ suc q ⇑ downward lemma₂ ⟧ʰ 1ᵇ
⟦_⇑⟧⁺ : ℕ⁺ → 𝔹⁺
⟦ ℕ+ n ⇑⟧⁺ = ⟦ suc n ⇑ <-well-founded ⟧ʰ
⟦_⇑⟧ : ℕ → 𝔹
⟦ zero ⇑⟧ = 𝕓0ᵇ
⟦ suc n ⇑⟧ = + ⟦ ℕ+ n ⇑⟧⁺
ℕ→𝔹→ℕ : ∀ n → ⟦ ⟦ n ⇑⟧ ⇓⟧ ≡ n
ℕ→𝔹→ℕ zero = refl
ℕ→𝔹→ℕ (suc n) = ℕ⁺→𝔹⁺→ℕ (suc n) <-well-founded
where
ℕ⁺→𝔹⁺→ℕ : ∀ (n : ℕ) (rec : Acc _<_ n) {≢0 : False (n ≟ 0)} → ⟦ ⟦ n ⇑ rec ⟧ʰ {≢0} ⇓⟧⁺ ≡ n
ℕ⁺→𝔹⁺→ℕ (suc n) (acc downward) with suc n div 2
... | Euclidean✓ (suc q) 0 refl r<m rewrite ℕ⁺→𝔹⁺→ℕ (suc q) (downward lemma₁) {tt} = ∀⟨ q ∷ [] ⟩
... | Euclidean✓ zero 1 refl r<m = refl
... | Euclidean✓ (suc q) 1 refl r<m rewrite ℕ⁺→𝔹⁺→ℕ (suc q) (downward lemma₂) {tt} = ∀⟨ q ∷ [] ⟩
⌈log₂_⌉⁺ : 𝔹⁺ → ℕ
⌈log₂ 𝕓1ᵇ ⌉⁺ = 1
⌈log₂ (b 0ᵇ) ⌉⁺ = 1 + ⌈log₂ b ⌉⁺
⌈log₂ (b 1ᵇ) ⌉⁺ = 1 + ⌈log₂ b ⌉⁺
⌈log₂_⌉ : 𝔹 → ℕ
⌈log₂ 𝕓0ᵇ ⌉ = 0
⌈log₂ + b ⌉ = ⌈log₂ b ⌉⁺
⌊_/2⌋⁺ : 𝔹⁺ → 𝔹⁺
⌊ 𝕓1ᵇ /2⌋⁺ = 𝕓1ᵇ
⌊ b 0ᵇ /2⌋⁺ = b
⌊ b 1ᵇ /2⌋⁺ = b
⌊_/2⌋ : 𝔹 → 𝔹
⌊ 𝕓0ᵇ /2⌋ = 𝕓0ᵇ
⌊ + b /2⌋ = + ⌊ b /2⌋⁺
-- _+ᵇ_ : 𝔹 → 𝔹 → 𝔹
-- n +ᵇ m = ⟦ ⟦ n ⇓⟧ + ⟦ m ⇓⟧ ⇑⟧
-- -- data Bit : Set where
-- -- 0𝑏 : Bit
-- -- 1𝑏 : Bit
-- -- _+ᵇ⁺_ : 𝔹⁺ → 𝔹⁺ → 𝔹⁺
-- -- n +ᵇ⁺ m = ⟦ ⟦ n ⇓⟧⁺ ⇑⟧⁺
-- -- where
-- -- loop : Bit → 𝔹⁺ → 𝔹⁺ → 𝔹⁺
-- -- loop carry x y = ?
-- -- unique⁺ : ∀ x y → ⟦ x ⇓⟧⁺ ≡ ⟦ y ⇓⟧⁺ → x ≡ y
-- -- unique⁺ 1ᵇ 1ᵇ p = refl
-- -- unique⁺ 1ᵇ (y 0ᵇ) p = {!!}
-- -- unique⁺ 1ᵇ (y 1ᵇ) p = {!!}
-- -- unique⁺ (x 0ᵇ) 1ᵇ p = {!!}
-- -- unique⁺ (x 0ᵇ) (y 0ᵇ) p = {!!}
-- -- unique⁺ (x 0ᵇ) (y 1ᵇ) p = {!!}
-- -- unique⁺ (x 1ᵇ) y p = {!!}
-- -- unique : ∀ x y → ⟦ x ⇓⟧ ≡ ⟦ y ⇓⟧ → x ≡ y
-- -- unique 𝕓0ᵇ 𝕓0ᵇ p = refl
-- -- unique 𝕓0ᵇ (𝕓 y) p = {!!}
-- -- unique (𝕓 x) 𝕓0ᵇ p = {!!}
-- -- unique (𝕓 x) (𝕓 y) p = {!!}
module Test where
eval-unit₁ : ⟦ + 𝕓1ᵇ 0ᵇ 1ᵇ 0ᵇ ⇓⟧ ≡ 10
eval-unit₁ = refl
log-unit₁ : ⌈log₂ ⟦ 15 ⇑⟧ ⌉ ≡ 4
log-unit₁ = refl
| {
"alphanum_fraction": 0.4874960431,
"avg_line_length": 25.6829268293,
"ext": "agda",
"hexsha": "fd3b5b2de495af2b26169e3dc480bd278a2df4bb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Binary/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Binary/Base.agda",
"max_line_length": 98,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Binary/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 2009,
"size": 3159
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Sets.EquivalenceRelations
open import Setoids.Setoids
module Setoids.Algebra.Lemmas {a b : _} {A : Set a} (S : Setoid {a} {b} A) where
open Setoid S
open Equivalence eq
open import Setoids.Subset S
open import Setoids.Equality S
open import Setoids.Intersection.Definition S
open import Setoids.Union.Definition S
intersectionAndUnion : {c d e : _} {pred1 : A → Set c} {pred2 : A → Set d} {pred3 : A → Set e} → (s1 : subset pred1) (s2 : subset pred2) (s3 : subset pred3) → intersection s1 (union s2 s3) =S union (intersection s1 s2) (intersection s1 s3)
intersectionAndUnion s1 s2 s3 x = ans1 ,, ans2
where
ans1 : _
ans1 (fst ,, inl x) = inl (fst ,, x)
ans1 (fst ,, inr x) = inr (fst ,, x)
ans2 : _
ans2 (inl x) = _&&_.fst x ,, inl (_&&_.snd x)
ans2 (inr x) = _&&_.fst x ,, inr (_&&_.snd x)
| {
"alphanum_fraction": 0.6632337796,
"avg_line_length": 37.3461538462,
"ext": "agda",
"hexsha": "e610f2e6b5328ad29047225df61883613378e76d",
"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": "Setoids/Algebra/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": "Setoids/Algebra/Lemmas.agda",
"max_line_length": 239,
"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": "Setoids/Algebra/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": 338,
"size": 971
} |
-- {-# OPTIONS -v tc:30 #-}
-- Andreas, 2016-07-19, issue #2102
-- An abstract definition in a where block should not
-- stop metas of parent function to be solved!
test : _
test = Set -- WAS: yellow
where
abstract def = Set
-- should succeed
test1 = Set
module M where
abstract def = Set
-- Similar situation
mutual
test2 : _
abstract def = Set
test2 = Set
| {
"alphanum_fraction": 0.6596306069,
"avg_line_length": 15.7916666667,
"ext": "agda",
"hexsha": "c6380372dff9de7eaf7b00f4af3cdf04f6948373",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.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/Issue2102.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2102.agda",
"max_line_length": 53,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2102.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": 113,
"size": 379
} |
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Wedge where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁)
open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)
open import Cubical.Data.Nat
open import Cubical.Algebra.Group
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.HITs.Pushout
open import Cubical.Data.Sigma
open import Cubical.Foundations.Isomorphism
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Susp
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.Foundations.Equiv
open GroupIso renaming (map to map')
open GroupHom
{-
This module proves that Hⁿ(A ⋁ B) ≅ Hⁿ(A) × Hⁿ(B) for n ≥ 1 directly (rather than by means of Mayer-Vietoris).
Proof sketch:
Any ∣ f ∣₂ ∈ Hⁿ(A ⋁ B) is uniquely characterised by a pair of functions
f₁ : A → Kₙ
f₂ : B → Kₙ
together with a path
p : f₁ (pt A) ≡ f₂ (pt B)
The map F : Hⁿ(A ⋁ B) → Hⁿ(A) × Hⁿ(B) simply forgets about p, i.e.:
F(∣ f ∣₂) := (∣ f₁ ∣₂ , ∣ f₂ ∣₂)
The construction of its inverse is defined by
F⁻(∣ f₁ ∣₂ , ∣ f₂ ∣₂) := ∣ f₁∨f₂ ∣₂
where
f₁∨f₂ : A ⋁ B → Kₙ is defined inductively by
f₁∨f₂ (inl x) := f₁ x + f₂ (pt B)
f₁∨f₂ (inr x) := f₂ x + f₁ (pt B)
cong f₁∨f₂ (push tt) := "f₁ (pt A) + f₂ (pt B) =(commutativity) f₂ (pt B) + f₁ (pt A)"
(this is the map wedgeFun⁻ below)
Note that the cong-case above reduces to refl when f₁ (pt A) := f₂ (pt B) := 0
The fact that F and F⁻ cancel out is a proposition and we may thus assume for any
∣ f ∣₂ ∈ Hⁿ(A ⋁ B) and its corresponding f₁ that
f₁ (pt A) = f₂ (pt B) = 0 (*)
and
f (inl (pt A)) = 0 (**)
The fact that F(F⁻(∣ f₁ ∣₂ , ∣ f₂ ∣₂)) = ∣ f₁ ∣₂ , ∣ f₂ ∣₂) follows immediately from (*)
The other way is slightly trickier. We need to construct paths
Pₗ : f (inl (x)) + f (inr (pt B)) ---> f (inl (x))
Pᵣ : f (inr (x)) + f (inl (pt A)) ---> f (inr (x))
Together with a filler of the following square
cong f (push tt)
----------------->
^ ^
| |
| |
Pₗ | | Pᵣ
| |
| |
| |
----------------->
Q
where Q is commutativity proof f (inl (pt A)) + f (inr (pt B)) = f (inr (pt B)) + f (inl (pt A))
The square is filled by first constructing Pₗ by
f (inl (x)) + f (inr (pt B)) ---[cong f (push tt)⁻¹]--->
f (inl (x)) + f (inl (pt A)) ---[(**)]--->
f (inl (x)) + 0 ---[right-unit]--->
f (inl (x))
and then Pᵣ by
f (inr (x)) + f (inl (pt A)) ---[(**)]--->
f (inr (x)) + 0 ---[right-unit]--->
f (inr (x))
and finally by using the fact that the group laws for Kₙ are refl at its base point.
-}
module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where
private
wedgeFun⁻ : ∀ n → (f : typ A → coHomK (suc n)) (g : typ B → coHomK (suc n))
→ ((A ⋁ B) → coHomK (suc n))
wedgeFun⁻ n f g (inl x) = f x +ₖ g (pt B)
wedgeFun⁻ n f g (inr x) = g x +ₖ f (pt A)
wedgeFun⁻ n f g (push a i) = commₖ (suc n) (f (pt A)) (g (pt B)) i
Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B))
fun (map' (Hⁿ-⋁ zero)) =
sElim (λ _ → isSet× setTruncIsSet setTruncIsSet)
λ f → ∣ (λ x → f (inl x)) ∣₂ , ∣ (λ x → f (inr x)) ∣₂
isHom (map' (Hⁿ-⋁ zero)) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ _ _ → refl
inv (Hⁿ-⋁ zero) = uncurry (sElim2 (λ _ _ → setTruncIsSet)
λ f g → ∣ wedgeFun⁻ 0 f g ∣₂)
rightInv (Hⁿ-⋁ zero) =
uncurry
(coHomPointedElim _ (pt A) (λ _ → isPropΠ λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ f fId → coHomPointedElim _ (pt B) (λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ g gId → ΣPathP (cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) gId ∙ rUnitₖ 1 (f x))) ,
cong ∣_∣₂ (funExt (λ x → cong (g x +ₖ_) fId ∙ rUnitₖ 1 (g x)))))
leftInv (Hⁿ-⋁ zero) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → pRec (setTruncIsSet _ _)
(λ fId → cong ∣_∣₂ (sym fId))
(helper f _ refl))
where
helper : (f : A ⋁ B → coHomK 1) (x : coHomK 1)
→ f (inl (pt A)) ≡ x
→ ∥ f ≡ wedgeFun⁻ 0 (λ x → f (inl x)) (λ x → f (inr x)) ∥
helper f =
trElim (λ _ → isProp→isOfHLevelSuc 2 (isPropΠ λ _ → propTruncIsProp))
(sphereElim 0 (λ _ → isPropΠ λ _ → propTruncIsProp)
λ inlId → (∣ funExt (λ { (inl x) → sym (rUnitₖ 1 (f (inl x)))
∙∙ cong ((f (inl x)) +ₖ_) (sym inlId)
∙∙ cong ((f (inl x)) +ₖ_) (cong f (push tt))
; (inr x) → sym (rUnitₖ 1 (f (inr x)))
∙ cong ((f (inr x)) +ₖ_) (sym inlId)
; (push tt i) j → cheating (f (inl (pt A))) (sym (inlId))
(f (inr (pt B)))
(cong f (push tt)) j i}) ∣₁))
where
cheating : (x : coHomK 1) (r : ∣ base ∣ ≡ x) (y : coHomK 1) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ 1 x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (rUnitₖ 1 y) ∙ cong (y +ₖ_) r) j)
p (commₖ 1 x y)
cheating x = J (λ x r → (y : coHomK 1) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ 1 x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (rUnitₖ 1 y) ∙ cong (y +ₖ_) r) j)
p (commₖ 1 x y))
λ y → J (λ y p → PathP (λ j → ((sym (rUnitₖ 1 ∣ base ∣) ∙∙ refl ∙∙ cong (∣ base ∣ +ₖ_) p)) j
≡ (sym (rUnitₖ 1 y) ∙ refl) j)
p (commₖ 1 ∣ base ∣ y))
λ i j → comp (λ _ → hLevelTrunc 3 S¹)
(λ k → λ {(i = i0) → ∣ base ∣
; (i = i1) → ∣ base ∣
; (j = i0) → (rUnit (λ _ → ∣ base ∣) k) i
; (j = i1) → (rUnit (λ _ → ∣ base ∣) k) i})
∣ base ∣
fun (map' (Hⁿ-⋁ (suc n))) =
sElim (λ _ → isSet× setTruncIsSet setTruncIsSet)
λ f → ∣ (λ x → f (inl x)) ∣₂ , ∣ (λ x → f (inr x)) ∣₂
isHom (map' (Hⁿ-⋁ (suc n))) =
sElim2 (λ _ _ → isOfHLevelPath 2 (isSet× setTruncIsSet setTruncIsSet) _ _)
λ _ _ → refl
inv (Hⁿ-⋁ (suc n)) =
uncurry (sElim2 (λ _ _ → setTruncIsSet)
λ f g → ∣ wedgeFun⁻ (suc n) f g ∣₂)
rightInv (Hⁿ-⋁ (suc n)) =
uncurry
(coHomPointedElim _ (pt A) (λ _ → isPropΠ λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ f fId → coHomPointedElim _ (pt B) (λ _ → isSet× setTruncIsSet setTruncIsSet _ _)
λ g gId → ΣPathP (cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) gId ∙ rUnitₖ (2 + n) (f x))) ,
cong ∣_∣₂ (funExt (λ x → cong (g x +ₖ_) fId ∙ rUnitₖ (2 + n) (g x)))))
leftInv (Hⁿ-⋁ (suc n)) =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(λ f → pRec (setTruncIsSet _ _)
(λ fId → cong ∣_∣₂ (sym fId))
(helper f _ refl))
where
helper : (f : A ⋁ B → coHomK (2 + n)) (x : coHomK (2 + n))
→ f (inl (pt A)) ≡ x
→ ∥ f ≡ wedgeFun⁻ (suc n) (λ x → f (inl x)) (λ x → f (inr x)) ∥
helper f =
trElim (λ _ → isProp→isOfHLevelSuc (3 + n) (isPropΠ λ _ → propTruncIsProp))
(sphereToPropElim (suc n) (λ _ → isPropΠ λ _ → propTruncIsProp)
λ inlId → (∣ funExt (λ { (inl x) → sym (rUnitₖ (2 + n) (f (inl x)))
∙∙ cong ((f (inl x)) +ₖ_) (sym inlId)
∙∙ cong ((f (inl x)) +ₖ_) (cong f (push tt))
; (inr x) → sym (rUnitₖ (2 + n) (f (inr x)))
∙ cong ((f (inr x)) +ₖ_) (sym inlId)
; (push tt i) j → cheating (f (inl (pt A))) (sym (inlId))
(f (inr (pt B))) (cong f (push tt)) j i}) ∣₁))
where
cheating : (x : coHomK (2 + n)) (r : ∣ north ∣ ≡ x) (y : coHomK (2 + n)) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ (2 + n) x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (rUnitₖ (2 + n) y) ∙ cong (y +ₖ_) r) j)
p (commₖ (2 + n) x y)
cheating x =
J (λ x r → (y : coHomK (2 + n)) (p : x ≡ y)
→ PathP (λ j → ((sym (rUnitₖ (2 + n) x) ∙∙ cong (x +ₖ_) r ∙∙ cong (x +ₖ_) p)) j
≡ (sym (rUnitₖ (2 + n) y) ∙ cong (y +ₖ_) r) j)
p (commₖ (2 + n) x y))
doubleCheating
where
doubleCheating : (y : coHomK (2 + n)) → (p : ∣ north ∣ ≡ y)
→ PathP (λ j → ((refl ∙∙ refl ∙∙ cong (∣ north ∣ +ₖ_) p)) j
≡ (sym (rUnitₖ (2 + n) y) ∙ refl) j)
p
(commₖ (2 + n) ∣ north ∣ y)
doubleCheating y =
J (λ y p → PathP (λ j → ((refl ∙∙ refl ∙∙ cong (∣ north ∣ +ₖ_) p)) j
≡ (sym (rUnitₖ (2 + n) y) ∙ refl) j)
p
(commₖ (2 + n) ∣ north ∣ y))
λ i j → comp (λ _ → coHomK (2 + n))
(λ k → λ {(i = i0) → ∣ north ∣
; (i = i1) → commₖ-base (2 + n) (~ k) j
; (j = i0) → rUnit (λ _ → ∣ north ∣) k i
; (j = i1) → rUnit (λ _ → ∣ north ∣) k i})
∣ north ∣
wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥
wedgeConnected conA conB =
PushoutToProp (λ _ → propTruncIsProp)
(λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a))
λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)
open import Cubical.Data.Int
open import Cubical.Data.Empty renaming (rec to ⊥-rec)
open import Cubical.Data.Bool
open import Cubical.Data.Int renaming (+-comm to +-commℤ ; _+_ to _+ℤ_)
even : Int → Bool
even (pos zero) = true
even (pos (suc zero)) = false
even (pos (suc (suc n))) = even (pos n)
even (negsuc zero) = false
even (negsuc (suc n)) = even (pos n)
open import Cubical.Data.Sum
even-2 : (x : Int) → even (-2 +ℤ x) ≡ even x
even-2 (pos zero) = refl
even-2 (pos (suc zero)) = refl
even-2 (pos (suc (suc n))) =
cong even (cong sucInt (sucInt+pos _ _)
∙∙ sucInt+pos _ _
∙∙ +-commℤ 0 (pos n))
∙ noClueWhy n
where
noClueWhy : (n : ℕ) → even (pos n) ≡ even (pos n)
noClueWhy n = refl
even-2 (negsuc zero) = refl
even-2 (negsuc (suc n)) =
cong even (predInt+negsuc n _
∙ +-commℤ -3 (negsuc n))
∙ noClueWhy n
where
noClueWhy : (n : ℕ) → even (negsuc (suc (suc (suc n)))) ≡ even (pos n)
noClueWhy n = refl
test3 : (p : 0ₖ 1 ≡ 0ₖ 1) → even (ΩKn+1→Kn 0 (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1) p)) ≡ even (ΩKn+1→Kn 0 p)
test3 p = cong even (cong (ΩKn+1→Kn 0) (cong (transport (λ i → ∣ (loop ∙ loop) i ∣ ≡ 0ₖ 1)) (lUnit p)))
∙∙ cong even (cong (ΩKn+1→Kn 0) λ j → transp (λ i → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) j ((λ i → ∣ (loop ∙ loop) (~ i ∧ j) ∣) ∙ p))
∙∙ cong even (ΩKn+1→Kn-hom 0 (sym (cong ∣_∣ (loop ∙ loop))) p)
∙ even-2 (ΩKn+1→Kn 0 p)
test2 : Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 → Bool
test2 = uncurry (trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelSuc 2 isSetBool)
λ {base p → even (ΩKn+1→Kn 0 p)
; (loop i) p → hcomp (λ k → λ { (i = i0) → test3 p k
; (i = i1) → even (ΩKn+1→Kn 0 p)})
(even (ΩKn+1→Kn 0 (transp (λ j → ∣ (loop ∙ loop) (i ∨ j) ∣ ≡ 0ₖ 1) i
p)))})
*' : (x y : coHomK 1) (p : x +ₖ x ≡ 0ₖ 1) (q : y +ₖ y ≡ 0ₖ 1) → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
*' =
trElim2 (λ _ _ → isGroupoidΠ2 λ _ _ → isOfHLevelSuc 2 setTruncIsSet)
(wedgeConSn _ _
(λ _ _ → isSetΠ2 λ _ _ → setTruncIsSet)
(λ x p q → ∣ ∣ x ∣ , cong₂ _+ₖ_ p q ∣₂)
(λ y p q → ∣ ∣ y ∣ , sym (rUnitₖ 1 (∣ y ∣ +ₖ ∣ y ∣)) ∙ cong₂ _+ₖ_ p q ∣₂)
(funExt λ p → funExt λ q → cong ∣_∣₂ (ΣPathP (refl , (sym (lUnit _))))) .fst)
_*_ : ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
_*_ = sRec (isSetΠ (λ _ → setTruncIsSet)) λ a → sRec setTruncIsSet λ b → *' (fst a) (fst b) (snd a) (snd b)
*=∙ : (p q : 0ₖ 1 ≡ 0ₖ 1) → ∣ 0ₖ 1 , p ∣₂ * ∣ 0ₖ 1 , q ∣₂ ≡ ∣ 0ₖ 1 , p ∙ q ∣₂
*=∙ p q = cong ∣_∣₂ (ΣPathP (refl , sym (∙≡+₁ p q)))
help : (n : ℕ) → even (pos (suc n)) ≡ true → even (negsuc n) ≡ true
help zero p = ⊥-rec (true≢false (sym p))
help (suc n) p = p
help2 : (n : ℕ) → even (pos (suc n)) ≡ false → even (negsuc n) ≡ false
help2 zero p = refl
help2 (suc n) p = p
evenCharac : (x : Int) → even x ≡ true
→ Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂
∣ (0ₖ 1 , refl) ∣₂
evenCharac (pos zero) iseven i = ∣ (0ₖ 1) , (rUnit refl (~ i)) ∣₂
evenCharac (pos (suc zero)) iseven = ⊥-rec (true≢false (sym iseven))
evenCharac (pos (suc (suc zero))) iseven = cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (cong ∣_∣ ((lUnit loop (~ i)) ∙ loop)) (~ i))
∙ (ΣPathP (cong ∣_∣ loop , λ i j → ∣ (loop ∙ loop) (i ∨ j) ∣)))
evenCharac (pos (suc (suc (suc n)))) iseven =
(λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos (suc n)) 2 i ∣₂)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos (suc n))) (Kn→ΩKn+1 0 (pos 2)))
∙∙ (cong₂ _*_ (evenCharac (pos (suc n)) iseven) (evenCharac 2 refl))
evenCharac (negsuc zero) iseven = ⊥-rec (true≢false (sym iseven))
evenCharac (negsuc (suc zero)) iseven =
cong ∣_∣₂ ((λ i → 0ₖ 1 , λ i₁ → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) i₁)
(inS ∣ compPath≡compPath' (sym loop) (sym loop) i i₁ ∣) (~ i))
∙ ΣPathP ((cong ∣_∣ (sym loop)) , λ i j → ∣ (sym loop ∙' sym loop) (i ∨ j) ∣))
evenCharac (negsuc (suc (suc n))) iseven =
cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))
∙∙ cong₂ _*_ (evenCharac (negsuc n) (help n iseven)) (evenCharac -2 refl) -- i
oddCharac : (x : Int) → even x ≡ false
→ Path ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
∣ (0ₖ 1 , Kn→ΩKn+1 0 x) ∣₂
∣ (0ₖ 1 , cong ∣_∣ loop) ∣₂
oddCharac (pos zero) isOdd = ⊥-rec (true≢false isOdd)
oddCharac (pos (suc zero)) isOdd i =
∣ (0ₖ 1 , λ j → hfill (doubleComp-faces (λ i₂ → ∣ base ∣) (λ _ → ∣ base ∣) j)
(inS ∣ lUnit loop (~ i) j ∣) (~ i)) ∣₂
oddCharac (pos (suc (suc n))) isOdd =
(λ i → ∣ 0ₖ 1 , Kn→ΩKn+1-hom 0 (pos n) 2 i ∣₂)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (pos n)) (Kn→ΩKn+1 0 2))
∙∙ cong₂ _*_ (oddCharac (pos n) isOdd) (evenCharac 2 refl)
oddCharac (negsuc zero) isOdd =
cong ∣_∣₂ ((λ i → 0ₖ 1 , rUnit (sym (cong ∣_∣ loop)) (~ i))
∙ ΣPathP (cong ∣_∣ (sym loop) , λ i j → ∣ hcomp (λ k → λ { (i = i0) → loop (~ j ∧ k)
; (i = i1) → loop j
; (j = i1) → base})
(loop (j ∨ ~ i)) ∣))
oddCharac (negsuc (suc zero)) isOdd = ⊥-rec (true≢false isOdd)
oddCharac (negsuc (suc (suc n))) isOdd =
cong ∣_∣₂ (λ i → 0ₖ 1 , Kn→ΩKn+1-hom 0 (negsuc n) -2 i)
∙∙ sym (*=∙ (Kn→ΩKn+1 0 (negsuc n)) (Kn→ΩKn+1 0 -2))
∙∙ cong₂ _*_ (oddCharac (negsuc n) (help2 n isOdd)) (evenCharac (negsuc 1) refl)
map⁻ : Bool → ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂
map⁻ false = ∣ 0ₖ 1 , cong ∣_∣ loop ∣₂
map⁻ true = ∣ 0ₖ 1 , refl ∣₂
testIso : Iso ∥ Σ[ x ∈ coHomK 1 ] x +ₖ x ≡ 0ₖ 1 ∥₂ Bool
Iso.fun testIso = sRec isSetBool test2
Iso.inv testIso = map⁻
Iso.rightInv testIso false = refl
Iso.rightInv testIso true = refl
Iso.leftInv testIso =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry (trElim
(λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _))
(toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _))
(λ p → path p (even (ΩKn+1→Kn 0 p)) refl))))
where
path : (p : 0ₖ 1 ≡ 0ₖ 1) (b : Bool) → (even (ΩKn+1→Kn 0 p) ≡ b) → map⁻ (test2 (∣ base ∣ , p)) ≡ ∣ ∣ base ∣ , p ∣₂
path p false q =
(cong map⁻ q)
∙∙ sym (oddCharac (ΩKn+1→Kn 0 p) q)
∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , Iso.rightInv (Iso-Kn-ΩKn+1 0) p i
path p true q =
cong map⁻ q
∙∙ sym (evenCharac (ΩKn+1→Kn 0 p) q)
∙∙ cong ∣_∣₂ λ i → 0ₖ 1 , Iso.rightInv (Iso-Kn-ΩKn+1 0) p i
| {
"alphanum_fraction": 0.4650357462,
"avg_line_length": 47.4907161804,
"ext": "agda",
"hexsha": "bfe6db8dbfecbe7009e8698fcffcc6dd3ef4b840",
"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": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"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": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda",
"max_line_length": 136,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 7420,
"size": 17904
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
-- This module defines a data type for balanced strings of parentheses,
-- which is isomorphic to binary trees.
module Data.Dyck.Rose where
open import Prelude
open import Data.Nat using (_+_)
open import Data.Vec.Iterated using (Vec; _∷_; []; foldlN; head)
open import Data.Tree.Rose
open import Data.List
private
variable
n : ℕ
--------------------------------------------------------------------------------
-- Programs: definition and associated functions
--------------------------------------------------------------------------------
data Prog (A : Type a) : ℕ → Type a where
halt : Prog A 1
pull : Prog A (1 + n) → Prog A n
push : A → Prog A (1 + n) → Prog A (2 + n)
--------------------------------------------------------------------------------
-- Conversion from a Prog to a Tree
--------------------------------------------------------------------------------
prog→tree⊙ : Prog A n → Vec (Forest A) n → Forest A
prog→tree⊙ halt (v ∷ []) = v
prog→tree⊙ (pull is) st = prog→tree⊙ is ([] ∷ st)
prog→tree⊙ (push v is) (t₁ ∷ t₂ ∷ st) = prog→tree⊙ is (((v & t₂) ∷ t₁) ∷ st)
prog→tree : Prog A zero → Forest A
prog→tree ds = prog→tree⊙ ds []
--------------------------------------------------------------------------------
-- Conversion from a Tree to a Prog
--------------------------------------------------------------------------------
tree→prog⊙ : Forest A → Prog A (suc n) → Prog A n
tree→prog⊙ [] = pull
tree→prog⊙ ((t & ts) ∷ xs) = tree→prog⊙ ts ∘ tree→prog⊙ xs ∘ push t
tree→prog : Forest A → Prog A zero
tree→prog tr = tree→prog⊙ tr halt
--------------------------------------------------------------------------------
-- Proof of isomorphism
--------------------------------------------------------------------------------
tree→prog→tree⊙ : (e : Forest A) (is : Prog A (1 + n)) (st : Vec (Forest A) n) →
prog→tree⊙ (tree→prog⊙ e is) st ≡ prog→tree⊙ is (e ∷ st)
tree→prog→tree⊙ [] is st = refl
tree→prog→tree⊙ ((t & ts) ∷ xs) is st =
tree→prog→tree⊙ ts _ st ; tree→prog→tree⊙ xs (push t is) (ts ∷ st)
tree→prog→tree : (e : Forest A) → prog→tree (tree→prog e) ≡ e
tree→prog→tree e = tree→prog→tree⊙ e halt []
prog→tree→prog⊙ : (is : Prog A n) (st : Vec (Forest A) n) →
tree→prog (prog→tree⊙ is st) ≡ foldlN (Prog A) tree→prog⊙ is st
prog→tree→prog⊙ halt st = refl
prog→tree→prog⊙ (pull is) st = prog→tree→prog⊙ is ([] ∷ st)
prog→tree→prog⊙ (push x is) (t₁ ∷ t₂ ∷ st) =
prog→tree→prog⊙ is (((x & t₂) ∷ t₁) ∷ st)
prog→tree→prog : (is : Prog A 0) → tree→prog (prog→tree is) ≡ is
prog→tree→prog is = prog→tree→prog⊙ is []
prog-iso : Prog A zero ⇔ Forest A
prog-iso .fun = prog→tree
prog-iso .inv = tree→prog
prog-iso .rightInv = tree→prog→tree
prog-iso .leftInv = prog→tree→prog
| {
"alphanum_fraction": 0.4713532513,
"avg_line_length": 36.4743589744,
"ext": "agda",
"hexsha": "e3c6c5d1d487c46b2b91b95a397d2535b45e2ac1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Dyck/Rose.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Dyck/Rose.agda",
"max_line_length": 80,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Dyck/Rose.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": 894,
"size": 2845
} |
{-# OPTIONS --cubical --safe --postfix-projections #-}
module Data.Sum.Properties where
open import Prelude
open import Data.Sum
open import Data.Bool
sumAsSigma : A ⊎ B ≃ Σ[ x ⦂ Bool ] (if x then A else B)
sumAsSigma = isoToEquiv $
iso
(either (true ,_) (false ,_))
(uncurry (bool inr inl))
(λ { (false , _) → refl ; (true , _) → refl})
(λ { (inl _) → refl ; (inr _) → refl})
| {
"alphanum_fraction": 0.6055276382,
"avg_line_length": 24.875,
"ext": "agda",
"hexsha": "cc3f8836dfd9ca9db4cbfcbf5ec42c96897a2ee7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-05T14:05:30.000Z",
"max_forks_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/combinatorics-paper",
"max_forks_repo_path": "agda/Data/Sum/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/combinatorics-paper",
"max_issues_repo_path": "agda/Data/Sum/Properties.agda",
"max_line_length": 55,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "3c176d4690566d81611080e9378f5a178b39b851",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/combinatorics-paper",
"max_stars_repo_path": "agda/Data/Sum/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-05T15:32:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-05T14:07:44.000Z",
"num_tokens": 131,
"size": 398
} |
{-# OPTIONS --without-K --safe #-}
module Dodo.Binary.SplittableOrder where
-- Stdlib imports
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; refl)
open import Level using (Level; _⊔_)
open import Function using (_∘_)
open import Data.Empty using (⊥-elim)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂; ∃-syntax)
open import Relation.Nullary using (¬_)
open import Relation.Unary using (Pred)
open import Relation.Binary using (Rel; REL; Transitive; Trichotomous; Tri; tri<; tri≈; tri>)
open import Relation.Binary.Construct.Closure.Transitive using (TransClosure; [_]; _∷_; _++_)
-- Local imports
open import Dodo.Unary.Equality
open import Dodo.Binary.Equality
open import Dodo.Binary.Immediate
open import Dodo.Binary.Trichotomous
open import Dodo.Binary.Transitive
open import Dodo.Binary.Domain
open import Dodo.Binary.Filter
open import Function using (flip)
-- # Definitions #
-- For any `R x y` there exists a /path/ from `x` to `y`.
SplittableOrder : {a ℓ : Level} {A : Set a} (R : Rel A ℓ) → Set (a ⊔ ℓ)
SplittableOrder R = R ⇔₂ TransClosure (immediate R)
-- # Properties #
module _ {a ℓ : Level} {A : Set a} {R : Rel A ℓ} where
splittable-trans : SplittableOrder R → Transitive R
splittable-trans splitR Rij Rjk =
⇔₂-apply-⊇₂ splitR (⇔₂-apply-⊆₂ splitR Rij ++ ⇔₂-apply-⊆₂ splitR Rjk)
splittable-flip : SplittableOrder R → SplittableOrder (flip R)
splittable-flip splitR = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : flip R ⊆₂' TransClosure (immediate (flip R))
⊆-proof _ _ = ⁺-map _ imm-flip ∘ ⁺-flip ∘ ⇔₂-apply-⊆₂ splitR
⊇-proof : TransClosure (immediate (flip R)) ⊆₂' flip R
⊇-proof _ _ = ⇔₂-apply-⊇₂ splitR ∘ ⁺-flip ∘ ⁺-map _ imm-flip
-- # Operations #
-- Split the left-most element from the ordered relation chain
splitˡ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ {x y : A}
→ R x y
--------------------------------------------------
→ immediate R x y ⊎ ∃[ z ] (immediate R x z × R z y)
splitˡ splitR Rxy with ⇔₂-apply-⊆₂ splitR Rxy
... | [ immRxy ] = inj₁ immRxy
... | _∷_ {x} {z} {y} immRxz immR⁺zy = inj₂ (z , immRxz , ⇔₂-apply-⊇₂ splitR immR⁺zy)
-- Split the right-most element from the ordered relation chain
splitʳ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ {x y : A}
→ R x y
--------------------------------------------------
→ immediate R x y ⊎ ∃[ z ] (R x z × immediate R z y)
splitʳ {A = A} {R = R} splitR Rxy = lemma (⇔₂-apply-⊆₂ splitR Rxy)
where
lemma : ∀ {x y : A} → TransClosure (immediate R) x y → immediate R x y ⊎ ∃[ z ] (R x z × immediate R z y)
lemma [ immRxy ] = inj₁ immRxy
lemma ( _∷_ {x} {z} {y} immRxz immR⁺zy ) with lemma immR⁺zy
... | inj₁ immRzy = inj₂ (z , proj₁ immRxz , immRzy)
... | inj₂ (w , Rzw , immRwy) = inj₂ (w , splittable-trans splitR (proj₁ immRxz) Rzw , immRwy)
-- Splits the given left-most element from the chain.
unsplitˡ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a} {_≈_ : Rel A ℓ₁} {R : Rel A ℓ₂}
→ Trichotomous _≈_ R
→ SplittableOrder R
→ {x y z : A}
→ R x z
→ immediate R x y
→ y ≈ z ⊎ R y z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy with splitˡ splitR Rxz
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₁ immRxz = inj₁ (tri-immʳ triR immRxy immRxz)
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) with triR y z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri< Ryz y≢z ¬Rzy = inj₂ Ryz
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri≈ ¬Ryz y≡z ¬Rzy = inj₁ y≡z
unsplitˡ triR splitR {x} {y} {z} Rxz immRxy | inj₂ (v , immRxv , Rvz) | tri> ¬Ryz y≢z Rzy = ⊥-elim (proj₂ immRxy (z , Rxz , [ Rzy ]))
-- Splits the given right-most element from the chain.
unsplitʳ : ∀ {a ℓ₁ ℓ₂ : Level} {A : Set a} {_≈_ : Rel A ℓ₁} {R : Rel A ℓ₂}
→ Trichotomous _≈_ R
→ SplittableOrder R
→ {x y z : A}
→ R x z
→ immediate R y z
→ x ≈ y ⊎ R x y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz with splitʳ splitR Rxz
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₁ iRxz = inj₁ (tri-immˡ triR iRxz iRyz)
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) with triR x y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri< Rxy x≢y ¬Ryx = inj₂ Rxy
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri≈ ¬Rxy x≡y ¬Ryx = inj₁ x≡y
unsplitʳ triR splitR {x} {y} {z} Rxz iRyz | inj₂ (v , Rxv , iRvz) | tri> ¬Rxy x≢y Ryx = ⊥-elim (proj₂ iRyz (x , Ryx , [ Rxz ]))
splittable-imm-udr : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ udr R ⇔₁ udr (immediate R)
splittable-imm-udr {R = R} splitR = ⇔: ⊆-proof ⊇-proof
where
⊆-proof : udr R ⊆₁' udr (immediate R)
⊆-proof x (inj₁ (y , Rxy)) = inj₁ (⁺-dom (⇔₂-apply-⊆₂ splitR Rxy))
⊆-proof y (inj₂ (x , Rxy)) = inj₂ (⁺-codom (⇔₂-apply-⊆₂ splitR Rxy))
⊇-proof : udr (immediate R) ⊆₁' udr R
⊇-proof x (inj₁ (y , Rxy)) = inj₁ (y , proj₁ Rxy)
⊇-proof y (inj₂ (x , Rxy)) = inj₂ (x , proj₁ Rxy)
-- | If any value in the chain of R satisfies P, it remains splittable after lifting.
--
-- The chain is traversed /to the left/.
filter-splittableˡ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ (P : Pred A ℓ)
→ (∀ {x y : A} → P y → R x y → P x)
---------------------------------
→ SplittableOrder (filter-rel P R)
filter-splittableˡ {A = A} {R = R} splitR P f = ⇔: ⊆-proof ⊇-proof
where
lemma⊆-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate R x y → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
lemma⊆-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] filter-rel P R (with-pred x Px) z × TransClosure (filter-rel P R) z (with-pred y Py))
¬∃z' (with-pred z Pz , Rxz , R⁺zy) = ¬∃z (z , Rxz , ⁺-strip-filter R⁺zy)
lemma⊆ : ∀ {x y : A} → (Px : P x) → (Py : P y) → TransClosure (immediate R) x y
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
lemma⊆ Px Py [ iRxy ] = [ lemma⊆-imm Px Py iRxy ]
lemma⊆ Px Py ( iRxz ∷ iR⁺zy ) =
let Pz = ⁺-predˡ (λ Pz → f Pz ∘ proj₁) iR⁺zy Py
in lemma⊆-imm Px Pz iRxz ∷ lemma⊆ Pz Py iR⁺zy
⊆-proof : filter-rel P R ⊆₂' TransClosure (immediate (filter-rel P R))
⊆-proof (with-pred x Px) (with-pred y Py) Rxy = lemma⊆ Px Py (⇔₂-apply-⊆₂ splitR Rxy)
lemma⊇-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
→ immediate R x y
lemma⊇-imm {x} {y} Px Py (Rxy , ¬∃z) = (Rxy , ¬∃z')
where
¬∃z' : ¬ (∃[ z ] R x z × TransClosure R z y)
¬∃z' (z , Rxz , R⁺zy) =
let Pz = ⁺-predˡ f R⁺zy Py
in ¬∃z (with-pred z Pz , Rxz , ⁺-filter-relˡ f Pz Py R⁺zy)
lemma⊇ : ∀ {x y : A} → (Px : P x) → (Py : P y)
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
→ TransClosure (immediate R) x y
lemma⊇ Px Py [ iRxy ] = [ lemma⊇-imm Px Py iRxy ]
lemma⊇ Px Py ( _∷_ {_} {with-pred z Pz} iRxz iR⁺zy ) = lemma⊇-imm Px Pz iRxz ∷ lemma⊇ Pz Py iR⁺zy
⊇-proof : TransClosure (immediate (filter-rel P R)) ⊆₂' filter-rel P R
⊇-proof (with-pred x Px) (with-pred y Py) Rxy = ⇔₂-apply-⊇₂ splitR (lemma⊇ Px Py Rxy)
-- | If any value in the chain of R satisfies P, it remains splittable after lifting.
--
-- The chain is traversed /to the right/.
filter-splittableʳ : ∀ {a ℓ : Level} {A : Set a} {R : Rel A ℓ}
→ SplittableOrder R
→ (P : Pred A ℓ)
→ (∀ {x y : A} → P x → R x y → P y)
---------------------------------
→ SplittableOrder (filter-rel P R)
filter-splittableʳ {A = A} {R = R} splitR P f = ⇔: ⊆-proof ⊇-proof
where
lemma⊆-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate R x y → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
lemma⊆-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] filter-rel P R (with-pred x Px) z × TransClosure (filter-rel P R) z (with-pred y Py))
¬∃z' (with-pred z Pz , Rxz , R⁺zy) = ¬∃z (z , Rxz , ⁺-strip-filter R⁺zy)
lemma⊆ : ∀ {x y : A} → (Px : P x) → (Py : P y) → TransClosure (immediate R) x y
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
lemma⊆ Px Py [ iRxy ] = [ lemma⊆-imm Px Py iRxy ]
lemma⊆ Px Py ( iRxz ∷ iR⁺zy ) =
let Pz = f Px (proj₁ iRxz)
in lemma⊆-imm Px Pz iRxz ∷ lemma⊆ Pz Py iR⁺zy
⊆-proof : filter-rel P R ⊆₂' TransClosure (immediate (filter-rel P R))
⊆-proof (with-pred x Px) (with-pred y Py) Rxy = lemma⊆ Px Py (⇔₂-apply-⊆₂ splitR Rxy)
lemma⊇-imm : ∀ {x y : A} → (Px : P x) → (Py : P y) → immediate (filter-rel P R) (with-pred x Px) (with-pred y Py)
→ immediate R x y
lemma⊇-imm {x} {y} Px Py (Rxy , ¬∃z) = Rxy , ¬∃z'
where
¬∃z' : ¬ (∃[ z ] R x z × TransClosure R z y)
¬∃z' (z , Rxz , R⁺zy) =
let Pz = f Px Rxz
in ¬∃z (with-pred z Pz , Rxz , ⁺-filter-relʳ f Pz Py R⁺zy)
lemma⊇ : ∀ {x y : A} → (Px : P x) → (Py : P y)
→ TransClosure (immediate (filter-rel P R)) (with-pred x Px) (with-pred y Py)
→ TransClosure (immediate R) x y
lemma⊇ Px Py [ iRxy ] = [ lemma⊇-imm Px Py iRxy ]
lemma⊇ Px Py ( _∷_ {_} {with-pred z Pz} iRxz iR⁺zy ) = lemma⊇-imm Px Pz iRxz ∷ lemma⊇ Pz Py iR⁺zy
⊇-proof : TransClosure (immediate (filter-rel P R)) ⊆₂' filter-rel P R
⊇-proof (with-pred x Px) (with-pred y Py) Rxy = ⇔₂-apply-⊇₂ splitR (lemma⊇ Px Py Rxy)
| {
"alphanum_fraction": 0.5836170213,
"avg_line_length": 42.5339366516,
"ext": "agda",
"hexsha": "593062074f05cf20e7700abc546bea7167cd6e05",
"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/SplittableOrder.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/SplittableOrder.agda",
"max_line_length": 134,
"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/SplittableOrder.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4077,
"size": 9400
} |
{-# OPTIONS --without-K #-}
{- The main definitions are the following:
* exploreΣ
* exploreΣ-ind
* adequate-sumΣ
-}
open import Level.NP
open import Type hiding (★)
open import Type.Identities
open import Function.NP
open import Function.Extensionality
open import Data.Two
open import Data.Product.NP
open import Data.Fin
open import Relation.Binary.Logical
open import Relation.Binary.PropositionalEquality.NP using (_≡_ ; module ≡-Reasoning; !_; _∙_; coe; tr; ap; ap₂; J-orig)
open import HoTT
open import Category.Monad.Continuation.Alias
open import Explore.Core
open import Explore.Properties
import Explore.Monad as EM
open import Explore.Explorable
module Explore.Product where
module _ {m a b} {A : ★ a} {B : A → ★ b} where
exploreΣ : Explore m A → (∀ {x} → Explore m (B x)) → Explore m (Σ A B)
exploreΣ exploreᴬ exploreᴮ ε _⊕_ = exploreᴬ ε _⊕_ ⟨,⟩ exploreᴮ ε _⊕_
module _ {eᴬ : Explore m A} {eᴮ : ∀ {x} → Explore m (B x)} where
exploreΣ-ind : ∀ {p} → ExploreInd p eᴬ → (∀ {x} → ExploreInd p (eᴮ {x})) → ExploreInd p (exploreΣ eᴬ eᴮ)
exploreΣ-ind Peᴬ Peᴮ P Pε P⊕ Pf =
Peᴬ (λ e → P (λ _ _ _ → e _ _ _)) Pε P⊕ (λ x → Peᴮ {x} (λ e → P (λ _ _ _ → e _ _ _)) Pε P⊕ (curry Pf x))
module _
{ℓ₀ ℓ₁ ℓᵣ}
{a₀ a₁ aᵣ} {A₀ : ★ a₀} {A₁ : ★ a₁} {Aᵣ : ⟦★⟧ aᵣ A₀ A₁}
{b₀ b₁ bᵣ} {B₀ : A₀ → ★ b₀} {B₁ : A₁ → ★ b₁} {Bᵣ : (Aᵣ ⟦→⟧ ⟦★⟧ bᵣ) B₀ B₁}
{eᴬ₀ : Explore ℓ₀ A₀} {eᴬ₁ : Explore ℓ₁ A₁}(eᴬᵣ : ⟦Explore⟧ ℓᵣ Aᵣ eᴬ₀ eᴬ₁)
{eᴮ₀ : ∀ {x} → Explore ℓ₀ (B₀ x)} {eᴮ₁ : ∀ {x} → Explore ℓ₁ (B₁ x)}(eᴮᵣ : ∀ {x₀ x₁}(x : Aᵣ x₀ x₁) → ⟦Explore⟧ ℓᵣ (Bᵣ x) (eᴮ₀ {x₀}) (eᴮ₁ {x₁}))
where
⟦exploreΣ⟧ : ⟦Explore⟧ ℓᵣ (⟦Σ⟧ Aᵣ Bᵣ) (exploreΣ eᴬ₀ (λ {x} → eᴮ₀ {x})) (exploreΣ eᴬ₁ (λ {x} → eᴮ₁ {x}))
⟦exploreΣ⟧ P Pε P⊕ Pf = eᴬᵣ P Pε P⊕ (λ {x₀} {x₁} x → eᴮᵣ x P Pε P⊕ (λ xᵣ → Pf (x ⟦,⟧ xᵣ)))
module _
{ℓ₀ ℓ₁ ℓᵣ}
{a} {A : ★ a}
{b} {B : A → ★ b}
{eᴬ₀ : Explore ℓ₀ A} {eᴬ₁ : Explore ℓ₁ A}(eᴬᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴬ₀ eᴬ₁)
{eᴮ₀ : ∀ {x} → Explore ℓ₀ (B x)} {eᴮ₁ : ∀ {x} → Explore ℓ₁ (B x)}
(eᴮᵣ : ∀ x → ⟦Explore⟧ ℓᵣ _≡_ (eᴮ₀ {x}) (eᴮ₁ {x}))
where
⟦exploreΣ⟧≡ : ⟦Explore⟧ ℓᵣ _≡_ (exploreΣ eᴬ₀ (λ {x} → eᴮ₀ {x})) (exploreΣ eᴬ₁ (λ {x} → eᴮ₁ {x}))
⟦exploreΣ⟧≡ P Pε P⊕ Pf = eᴬᵣ P Pε P⊕ λ x → J-orig _ (λ y → eᴮᵣ y P Pε P⊕ (Pf ∘ ap (_,_ y))) x
module _
{ℓ₀ ℓ₁ ℓᵣ}
{a} {A : ★ a}
{b} {B : A → ★ b}
{eᴬ₀ : Explore ℓ₀ A} {eᴬ₁ : Explore ℓ₁ A}(eᴬᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴬ₀ eᴬ₁)
{eᴮ₀ : ∀ {x} → Explore ℓ₀ (B x)} {eᴮ₁ : ∀ {x} → Explore ℓ₁ (B x)}
(eᴮᵣ : ∀ {x₀ x₁} (x : x₀ ≡ x₁) → ⟦Explore⟧ ℓᵣ (λ b₀ b₁ → tr B x b₀ ≡ b₁) (eᴮ₀ {x₀}) (eᴮ₁ {x₁}))
where
⟦exploreΣ⟧↑≡ : ⟦Explore⟧ ℓᵣ _≡_ (exploreΣ eᴬ₀ (λ {x} → eᴮ₀ {x})) (exploreΣ eᴬ₁ (λ {x} → eᴮ₁ {x}))
⟦exploreΣ⟧↑≡ P Pε P⊕ Pf = eᴬᵣ P Pε P⊕ (λ x → eᴮᵣ x P Pε P⊕ (Pf ∘ pair= x))
module _ {A : ★₀} {B : A → ★₀} {sumᴬ : Sum A} {sumᴮ : ∀ {x} → Sum (B x)}{{_ : FunExt}}{{_ : UA}} where
open Adequacy _≡_
private
sumᴬᴮ : Sum (Σ A B)
sumᴬᴮ = sumᴬ ⟨,⟩ (λ {x} → sumᴮ {x})
adequate-sumΣ : Adequate-sum sumᴬ → (∀ {x} → Adequate-sum (sumᴮ {x})) → Adequate-sum sumᴬᴮ
adequate-sumΣ asumᴬ asumᴮ f
= Fin (sumᴬᴮ f)
≡⟨by-definition⟩
Fin (sumᴬ (λ a → sumᴮ (λ b → f (a , b))))
≡⟨ asumᴬ _ ⟩
Σ A (λ a → Fin (sumᴮ (λ b → f (a , b))))
≡⟨ Σ=′ _ (λ _ → asumᴮ _) ⟩
Σ A (λ a → Σ (B a) (λ b → Fin (f (a , b))))
≡⟨ Σ-assoc ⟩
Σ (Σ A B) (Fin ∘ f)
∎
where open ≡-Reasoning
-- From now on, these are derived definitions for convenience and pedagogical reasons
explore× : ∀ {m a b} {A : ★ a} {B : ★ b} → Explore m A → Explore m B → Explore m (A × B)
explore× exploreᴬ exploreᴮ = exploreΣ exploreᴬ exploreᴮ
explore×-ind : ∀ {m p a b} {A : ★ a} {B : ★ b} {eᴬ : Explore m A} {eᴮ : Explore m B}
→ ExploreInd p eᴬ → ExploreInd p eᴮ
→ ExploreInd p (explore× eᴬ eᴮ)
explore×-ind Peᴬ Peᴮ = exploreΣ-ind Peᴬ Peᴮ
sumΣ : ∀ {a b} {A : ★ a} {B : A → ★ b} → Sum A → (∀ {x} → Sum (B x)) → Sum (Σ A B)
sumΣ = _⟨,⟩_
sum× : ∀ {a b} {A : ★ a} {B : ★ b} → Sum A → Sum B → Sum (A × B)
sum× = _⟨,⟩′_
module _ {ℓ₀ ℓ₁ ℓᵣ A₀ A₁ B₀ B₁}
{Aᵣ : ⟦★₀⟧ A₀ A₁}
{Bᵣ : ⟦★₀⟧ B₀ B₁}
{eᴬ₀ : Explore ℓ₀ A₀} {eᴬ₁ : Explore ℓ₁ A₁}(eᴬᵣ : ⟦Explore⟧ ℓᵣ Aᵣ eᴬ₀ eᴬ₁)
{eᴮ₀ : Explore ℓ₀ B₀} {eᴮ₁ : Explore ℓ₁ B₁}(eᴮᵣ : ⟦Explore⟧ ℓᵣ Bᵣ eᴮ₀ eᴮ₁)
where
⟦explore×⟧ : ⟦Explore⟧ ℓᵣ (Aᵣ ⟦×⟧ Bᵣ) (explore× eᴬ₀ eᴮ₀) (explore× eᴬ₁ eᴮ₁)
⟦explore×⟧ P Pε P⊕ Pf = eᴬᵣ P Pε P⊕ (λ x → eᴮᵣ P Pε P⊕ (λ y → Pf (_⟦,⟧_ x y)))
module _ {ℓ₀ ℓ₁ ℓᵣ} {A B : ★₀}
{eᴬ₀ : Explore ℓ₀ A} {eᴬ₁ : Explore ℓ₁ A}(eᴬᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴬ₀ eᴬ₁)
{eᴮ₀ : Explore ℓ₀ B} {eᴮ₁ : Explore ℓ₁ B}(eᴮᵣ : ⟦Explore⟧ ℓᵣ _≡_ eᴮ₀ eᴮ₁)
where
⟦explore×⟧≡ : ⟦Explore⟧ ℓᵣ _≡_ (explore× eᴬ₀ eᴮ₀) (explore× eᴬ₁ eᴮ₁)
⟦explore×⟧≡ P Pε P⊕ Pf = eᴬᵣ P Pε P⊕ (λ x → eᴮᵣ P Pε P⊕ (λ y → Pf (ap₂ _,_ x y)))
{-
μΣ : ∀ {A} {B : A → ★ _} → Explorable A → (∀ {x} → Explorable (B x)) → Explorable (Σ A B)
μΣ μA μB = mk _ (exploreΣ-ind (explore-ind μA) (explore-ind μB))
(adequate-sumΣ (adequate-sum μA) (adequate-sum μB))
infixr 4 _×-μ_
_×-μ_ : ∀ {A B} → Explorable A → Explorable B → Explorable (A × B)
μA ×-μ μB = μΣ μA μB
_×-cmp_ : ∀ {A B : ★₀ } → Cmp A → Cmp B → Cmp (A × B)
(ca ×-cmp cb) (a , b) (a' , b') = ca a a' ∧ cb b b'
×-unique : ∀ {A B}(μA : Explorable A)(μB : Explorable B)(cA : Cmp A)(cB : Cmp B)
→ Unique cA (count μA) → Unique cB (count μB) → Unique (cA ×-cmp cB) (count (μA ×-μ μB))
×-unique μA μB cA cB uA uB (x , y) = count (μA ×-μ μB) ((cA ×-cmp cB) (x , y)) ≡⟨ explore-ext μA _ (λ x' → help (cA x x')) ⟩
count μA (cA x) ≡⟨ uA x ⟩
1 ∎
where
open ≡-Reasoning
help : ∀ b → count μB (λ y' → b ∧ cB y y') ≡ (if b then 1 else 0)
help = [0: sum-zero μB 1: uB y ]
-}
{-
module _ {A} {Aₚ : A → ★₀} {B : A → _} {eᴬ : Explore ₁ A} (eᴬₚ : [Explore] _ _ Aₚ eᴬ) (eᴬ-ind : ExploreInd (ₛ ₀) eᴬ) {eᴮ : ∀ {x} → Explore ₀ (B x)} where
open import Explore.One
--open import Explore.Product
exploreΠᵉ : Explore ₀ (Πᵉ eᴬ B)
exploreΠᵉ = eᴬ-ind (λ e → Explore ₀ (Πᵉ e B)) (λ ε _∙₁_ x → x _) explore× (λ x → eᴮ {x})
exploreΠᵉ' : Explore ₀ (Πᵉ eᴬ B)
exploreΠᵉ' = λ {M} ε _∙₁_ x → {!eᴬₚ (const (Lift M))!}
exploreΠᵉ-ind : ExploreInd ₁ exploreΠᵉ
exploreΠᵉ-ind = {!⟦Explore⟧ᵤ _ _ _ eᴬ!}
-}
module _ {ℓ a b} {A : ★ a} {B : A → ★ b} {eᴬ : Explore (ₛ ℓ) A} {eᴮ : ∀ {x} → Explore (ₛ ℓ) (B x)} where
private
eᴬᴮ = exploreΣ eᴬ λ {x} → eᴮ {x}
focusΣ : Focus eᴬ → (∀ {x} → Focus (eᴮ {x})) → Focus eᴬᴮ
focusΣ fᴬ fᴮ ((x , y) , z) = fᴬ (x , fᴮ (y , z))
lookupΣ : Lookup eᴬ → (∀ {x} → Lookup (eᴮ {x})) → Lookup eᴬᴮ
lookupΣ lookupᴬ lookupᴮ d = uncurry (lookupᴮ ∘ lookupᴬ d)
-- can also be derived from explore-ind
reifyΣ : Reify eᴬ → (∀ {x} → Reify (eᴮ {x})) → Reify eᴬᴮ
reifyΣ reifyᴬ reifyᴮ f = reifyᴬ (reifyᴮ ∘ curry f)
module _ {ℓ} {A : ★₀} {B : A → ★₀}
{eᴬ : Explore (ₛ ℓ) A} {eᴮ : ∀ {x} → Explore (ₛ ℓ) (B x)}
{{_ : UA}}{{_ : FunExt}} where
private
eᴬᴮ = exploreΣ eᴬ λ {x} → eᴮ {x}
ΣᵉΣ-ok : Adequate-Σ (Σᵉ eᴬ) → (∀ {x} → Adequate-Σ (Σᵉ (eᴮ {x}))) → Adequate-Σ (Σᵉ eᴬᴮ)
ΣᵉΣ-ok eᴬ eᴮ f = eᴬ _ ∙ Σ=′ _ (λ _ → eᴮ _) ∙ Σ-assoc
ΠᵉΣ-ok : Adequate-Π (Πᵉ eᴬ) → (∀ {x} → Adequate-Π (Πᵉ (eᴮ {x}))) → Adequate-Π (Πᵉ eᴬᴮ)
ΠᵉΣ-ok eᴬ eᴮ f = eᴬ _ ∙ Π=′ _ (λ _ → eᴮ _) ∙ ! ΠΣ-curry
module _ {ℓ a b} {A : ★ a} {B : ★ b} {eᴬ : Explore (ₛ ℓ) A} {eᴮ : Explore (ₛ ℓ) B} where
private
eᴬᴮ = explore× eᴬ eᴮ
focus× : Focus eᴬ → Focus eᴮ → Focus eᴬᴮ
focus× fᴬ fᴮ = focusΣ {eᴬ = eᴬ} {eᴮ = eᴮ} fᴬ fᴮ
lookup× : Lookup eᴬ → Lookup eᴮ → Lookup eᴬᴮ
lookup× fᴬ fᴮ = lookupΣ {eᴬ = eᴬ} {eᴮ = eᴮ} fᴬ fᴮ
module _ {ℓ} {A B : ★₀} {eᴬ : Explore (ₛ ℓ) A} {eᴮ : Explore (ₛ ℓ) B} where
private
eᴬᴮ = explore× eᴬ eᴮ
Σᵉ×-ok : {{_ : UA}}{{_ : FunExt}} → Adequate-Σ (Σᵉ eᴬ) → Adequate-Σ (Σᵉ eᴮ) → Adequate-Σ (Σᵉ eᴬᴮ)
Σᵉ×-ok eᴬ eᴮ f = eᴬ _ ∙ Σ=′ _ (λ _ → eᴮ _) ∙ Σ-assoc
Πᵉ×-ok : {{_ : UA}}{{_ : FunExt}} → Adequate-Π (Πᵉ eᴬ) → Adequate-Π (Πᵉ eᴮ) → Adequate-Π (Πᵉ eᴬᴮ)
Πᵉ×-ok eᴬ eᴮ f = eᴬ _ ∙ Π=′ _ (λ _ → eᴮ _) ∙ ! ΠΣ-curry
module Operators where
infixr 4 _×ᵉ_ _×ⁱ_ _×ˢ_
_×ᵉ_ = explore×
_×ⁱ_ = explore×-ind
_×ᵃ_ = adequate-sumΣ
_×ˢ_ = sum×
_×ᶠ_ = focus×
_×ˡ_ = lookup×
-- Those are here only for pedagogical use
private
fst-explore : ∀ {m} {A : ★₀} {B : A → ★₀} → Explore m (Σ A B) → Explore m A
fst-explore = EM.map _ fst
snd-explore : ∀ {m} {A B : ★₀} → Explore m (A × B) → Explore m B
snd-explore = EM.map _ snd
sum'Σ : ∀ {A : ★₀} {B : A → ★₀} → Sum A → (∀ x → Sum (B x)) → Sum (Σ A B)
sum'Σ sumᴬ sumᴮ f = sumᴬ (λ x₀ →
sumᴮ x₀ (λ x₁ →
f (x₀ , x₁)))
explore×' : ∀ {A B : ★₀} → Explore₀ A → Explore _ B → Explore _ (A × B)
explore×' exploreᴬ exploreᴮ ε _⊕_ f = exploreᴬ ε _⊕_ (λ x → exploreᴮ ε _⊕_ (curry f x))
explore×-ind' : ∀ {A B} {eᴬ : Explore _ A} {eᴮ : Explore _ B}
→ ExploreInd₀ eᴬ → ExploreInd₀ eᴮ → ExploreInd₀ (explore×' eᴬ eᴮ)
explore×-ind' Peᴬ Peᴮ P Pε P⊕ Pf =
Peᴬ (λ e → P (λ _ _ _ → e _ _ _)) Pε P⊕ (Peᴮ (λ e → P (λ _ _ _ → e _ _ _)) Pε P⊕ ∘ curry Pf)
-- liftM2 _,_ in the continuation monad
sum×' : ∀ {A B : ★₀} → Sum A → Sum B → Sum (A × B)
sum×' sumᴬ sumᴮ f = sumᴬ λ x₀ →
sumᴮ λ x₁ →
f (x₀ , x₁)
-- -}
-- -}
-- -}
| {
"alphanum_fraction": 0.5169553806,
"avg_line_length": 39.0368852459,
"ext": "agda",
"hexsha": "699bd320c0b9c9f14f50b4dbfd308fe4c5003fa5",
"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": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "crypto-agda/explore",
"max_forks_repo_path": "lib/Explore/Product.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_issues_repo_issues_event_max_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-03-16T14:24:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "crypto-agda/explore",
"max_issues_repo_path": "lib/Explore/Product.agda",
"max_line_length": 153,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "16bc8333503ff9c00d47d56f4ec6113b9269a43e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "crypto-agda/explore",
"max_stars_repo_path": "lib/Explore/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2017-06-28T19:19:29.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-05T09:25:32.000Z",
"num_tokens": 5331,
"size": 9525
} |
{-# OPTIONS --without-K #-}
module sets.vec.dependent where
open import sets.nat.core
open import sets.fin.core
-- syntactic sugar to create finite dependent functions
⟦⟧ : ∀ {i}{P : Fin 0 → Set i} → (i : Fin 0) → P i
⟦⟧ ()
_∷∷_ : ∀ {i n}{P : Fin (suc n) → Set i}
→ (x : P zero)(xs : (i : Fin n) → P (suc i))
→ (i : Fin (suc n)) → P i
_∷∷_ {P = P} x xs zero = x
_∷∷_ {P = P} x xs (suc i) = xs i
infixr 5 _∷∷_
| {
"alphanum_fraction": 0.5355450237,
"avg_line_length": 22.2105263158,
"ext": "agda",
"hexsha": "00e4a4904cf7f3d01a4bb68479a71490f1930224",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/vec/dependent.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/sets/vec/dependent.agda",
"max_line_length": 55,
"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": "sets/vec/dependent.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": 183,
"size": 422
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.