Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --safe #-}
module Cats.Category.Fun.Facts.Iso where
open import Cats.Category
open import Cats.Category.Cat using (_≈_)
open import Cats.Category.Fun using (Fun ; Trans ; ≈-intro ; ≈-elim)
open import Cats.Functor using (Functor)
open import Cats.Trans.Iso using (NatIso)
import Cats.Category.Constructions.Iso as Iso
open NatIso
open Trans
open Iso.Iso
module _ {lo la l≈ lo′ la′ l≈′}
{C : Category lo la l≈} {D : Category lo′ la′ l≈′}
{F G : Functor C D}
where
open Category (Fun C D) using (_≅_)
≈→≅ : F ≈ G → F ≅ G
≈→≅ i = record
{ forth = Forth i
; back = Back i
; back-forth = ≈-intro (back-forth (iso i))
; forth-back = ≈-intro (forth-back (iso i))
}
≅→≈ : F ≅ G → F ≈ G
≅→≈ i = record
{ iso = λ {c} → record
{ forth = component (forth i) c
; back = component (back i) c
; back-forth = ≈-elim (back-forth i)
; forth-back = ≈-elim (forth-back i)
}
; forth-natural = natural (forth i)
}
| {
"alphanum_fraction": 0.5886454183,
"avg_line_length": 22.8181818182,
"ext": "agda",
"hexsha": "68a8af839f820f11c45aae76652d4da086da5b59",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-18T15:35:07.000Z",
"max_forks_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/cats",
"max_forks_repo_path": "Cats/Category/Fun/Facts/Iso.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/cats",
"max_issues_repo_path": "Cats/Category/Fun/Facts/Iso.agda",
"max_line_length": 68,
"max_stars_count": 24,
"max_stars_repo_head_hexsha": "1ad7b243acb622d46731e9ae7029408db6e561f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/cats",
"max_stars_repo_path": "Cats/Category/Fun/Facts/Iso.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-06T05:00:46.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-03T15:18:57.000Z",
"num_tokens": 351,
"size": 1004
} |
module PiFrac.NoRepeat where
open import Data.Empty
open import Data.Unit hiding (_≟_)
open import Data.Sum
open import Data.Product
open import Relation.Binary.Core
open import Relation.Binary
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Function using (_∘_)
open import PiFrac.Syntax
open import PiFrac.Opsem
open import PiFrac.AuxLemmas
import PartialRevNoRepeat
-- Forward deterministic
deterministic : ∀ {st st₁ st₂} → st ↦ st₁ → st ↦ st₂ → st₁ ≡ st₂
deterministic (↦₁ {b = b₁}) (↦₁ {b = b₂}) with base-is-prop _ b₁ b₂
... | refl = refl
deterministic ↦₂ ↦₂ = refl
deterministic ↦₃ ↦₃ = refl
deterministic ↦₄ ↦₄ = refl
deterministic ↦₅ ↦₅ = refl
deterministic ↦₆ ↦₆ = refl
deterministic ↦₇ ↦₇ = refl
deterministic ↦₈ ↦₈ = refl
deterministic ↦₉ ↦₉ = refl
deterministic ↦₁₀ ↦₁₀ = refl
deterministic ↦₁₁ ↦₁₁ = refl
deterministic ↦₁₂ ↦₁₂ = refl
deterministic ↦η ↦η = refl
deterministic ↦ε₁ ↦ε₁ = refl
deterministic (↦ε₁ {eq = eq}) (↦ε₂ {neq = neq}) = ⊥-elim (neq eq)
deterministic (↦ε₂ {neq = neq}) (↦ε₁ {eq = eq}) = ⊥-elim (neq eq)
deterministic ↦ε₂ ↦ε₂ = refl
-- Backward deterministic
deterministicᵣₑᵥ : ∀ {st st₁ st₂} → st₁ ↦ st → st₂ ↦ st → st ≢ ⊠ → st₁ ≡ st₂
deterministicᵣₑᵥ {[ c ∣ _ ∣ κ ]} {⟨ c ∣ v ∣ κ ⟩} {⟨ c' ∣ v' ∣ κ' ⟩} ↦₁ r st≠⊠ with Lemma₁ r
... | refl , refl with Lemma₂ r
deterministicᵣₑᵥ {[ uniti₊l ∣ _ ∣ κ ]} {⟨ _ ∣ x ∣ κ ⟩} {⟨ _ ∣ x ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ unite₊l ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ x ∣ κ ⟩} {⟨ _ ∣ inj₂ x ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₁ x ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ y ∣ κ ⟩} {⟨ _ ∣ inj₂ y ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₁ x ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} ↦₁ () _ | refl , refl | refl , refl
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ x ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} ↦₁ () _ | refl , refl | refl , refl
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₁ y) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} {⟨ _ ∣ inj₂ (inj₂ z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₁ x) ∣ κ ⟩} ↦₁ () _ | refl , refl | refl , refl
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₁ (inj₂ y) ∣ κ ⟩} ↦₁ () _ | refl , refl | refl , refl
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ z ∣ κ ⟩} {⟨ _ ∣ inj₂ z ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ unite⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ (tt , v) ∣ κ ⟩} {⟨ _ ∣ (tt , v) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ uniti⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {⟨ _ ∣ v ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ swap⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ (x , y) ∣ κ ⟩} {⟨ _ ∣ (x , y) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocl⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ (x , (y , z)) ∣ κ ⟩} {⟨ _ ∣ (x , (y , z)) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ assocr⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ ((x , y) , z) ∣ κ ⟩} {⟨ _ ∣ ((x , y) , z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ (inj₁ x , z) ∣ κ ⟩} {⟨ _ ∣ (inj₁ x , z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ (inj₂ y , z) ∣ κ ⟩} {⟨ _ ∣ (inj₂ y , z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ inj₁ (x , z) ∣ κ ⟩} {⟨ _ ∣ inj₁ (x , z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ inj₂ (y , z) ∣ κ ⟩} {⟨ _ ∣ inj₂ (y , z) ∣ κ ⟩} ↦₁ ↦₁ _ | refl , refl | refl , refl = refl
deterministicᵣₑᵥ {[ swap₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ assocl₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ assocr₊ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ unite⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ uniti⋆l ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ swap⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ assocl⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ assocr⋆ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ dist ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ factor ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} ↦₁ ()
deterministicᵣₑᵥ {[ id↔ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})
deterministicᵣₑᵥ {[ c₁ ⨾ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})
deterministicᵣₑᵥ {[ c₁ ⊕ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})
deterministicᵣₑᵥ {[ c₁ ⊗ c₂ ∣ _ ∣ κ ]} {⟨ _ ∣ v ∣ κ ⟩} {[ c' ∣ v' ∣ κ' ]} (↦₁ {b = ()})
deterministicᵣₑᵥ {_} {_} {_} ↦₂ ↦₂ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₃ ↦₃ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₄ ↦₄ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₅ ↦₅ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₆ ↦₆ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₇ ↦₇ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₈ ↦₈ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₉ ↦₉ st≠⊠ = refl
deterministicᵣₑᵥ {_} {_} {_} ↦₁₀ ↦₁₀ st≠⊠ = refl
deterministicᵣₑᵥ {.([ _ ⊕ _ ∣ inj₁ _ ∣ _ ])} {_} {⟨ c ∣ v ∣ κ ⟩} ↦₁₁ r st≠⊠ with Lemma₁ r
... | refl , refl with Lemma₂ r
... | refl , refl with Lemma₃ r
... | inj₂ (inj₂ refl) with Lemma₄ r
... | inj₁ ()
... | inj₂ ()
deterministicᵣₑᵥ {[ _ ⊕ _ ∣ inj₁ _ ∣ _ ]} {_} {_} ↦₁₁ ↦₁₁ st≠⊠ = refl
deterministicᵣₑᵥ {[ _ ⊕ _ ∣ inj₂ _ ∣ _ ]} {[ _ ∣ _ ∣ _ ⊕☐• _ ]} {⟨ c ∣ v ∣ κ ⟩} ↦₁₂ r st≠⊠ with Lemma₁ r
... | refl , refl with Lemma₂ r
... | refl , refl with Lemma₃ r
... | inj₂ (inj₂ refl) with Lemma₄ r
... | inj₁ ()
... | inj₂ ()
deterministicᵣₑᵥ {[ _ ⊕ _ ∣ inj₂ _ ∣ _ ]} {_} {_} ↦₁₂ ↦₁₂ st≠⊠ = refl
deterministicᵣₑᵥ {[ ηₓ v ∣ _ ∣ _ ]} {⟨ ηₓ v ∣ tt ∣ _ ⟩} {⟨ _ ∣ v' ∣ _ ⟩} ↦η r st≠⊠ with Lemma₁ r
... | refl , refl with Lemma₂ r
... | refl , refl with v'
... | tt = refl
deterministicᵣₑᵥ {[ εₓ v ∣ tt ∣ _ ]} {_} {_} (↦ε₁ {eq = refl}) (↦ε₁ {eq = refl}) st≠⊠ = refl
deterministicᵣₑᵥ {⊠} {⟨ εₓ v ∣ _ , ↻ ∣ _ ⟩} {_} ↦ε₂ ↦ε₂ st≠⊠ = ⊥-elim (st≠⊠ refl)
-- Non-repeating Lemma
⊠-is-stuck : ∀ {st} → st ≡ ⊠ → ∄[ st' ] (st ↦ st')
⊠-is-stuck refl = λ ()
open PartialRevNoRepeat (record { State = State
; _↦_ = _↦_
; is-fail = λ st → st ≡ ⊠
; is-fail? = (λ { ⊠ → yes refl
; ⟨ _ ∣ _ ∣ _ ⟩ → no (λ ())
; [ _ ∣ _ ∣ _ ] → no (λ ())})
; fail-is-stuck = ⊠-is-stuck
; deterministic = deterministic
; deterministicᵣₑᵥ = deterministicᵣₑᵥ}) public
| {
"alphanum_fraction": 0.4739023443,
"avg_line_length": 63.2868852459,
"ext": "agda",
"hexsha": "4073a0df5c61eab05872daea68aaa2d28443b758",
"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/NoRepeat.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/NoRepeat.agda",
"max_line_length": 138,
"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/NoRepeat.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": 4367,
"size": 7721
} |
{-# OPTIONS --type-in-type #-}
module ArgsWrongOrder where
open import AgdaPrelude
myFun : (a : Set) -> a -> Nat -> Nat
myFun _ x y = y
myApp = myFun _ Zero (Nil Nat)
| {
"alphanum_fraction": 0.6374269006,
"avg_line_length": 17.1,
"ext": "agda",
"hexsha": "b7ec8b4ab479c62061e02bb9a6b323c66e22e39e",
"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": "thesisExamples/ArgsWrongOrder.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": "thesisExamples/ArgsWrongOrder.agda",
"max_line_length": 36,
"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": "thesisExamples/ArgsWrongOrder.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": 55,
"size": 171
} |
{-# OPTIONS --prop #-}
data _≡_ {X : Set} (a : X) : X → Prop where
refl : a ≡ a
postulate
A : Set
P : Prop
p : P
u : P → A
f : {x : A} (q : u p ≡ x) → P
f refl = p -- works in 2.6.0.1
| {
"alphanum_fraction": 0.4371859296,
"avg_line_length": 14.2142857143,
"ext": "agda",
"hexsha": "70f65479b8cedf7c3c8559f598f6737a495373f3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue4122-match.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue4122-match.agda",
"max_line_length": 43,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue4122-match.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 95,
"size": 199
} |
{-# OPTIONS --without-K --rewriting #-}
{-
favonia:
On 2017/03/23, after I added back Mayer-Vietoris, it seems
difficult to type check everything in one round on travis,
so parts of index.agda are moved here.
favonia:
On 2017/05/08, I further partition the results into multiple
independent index[n].agda files because the garbage collection
is not really working.
-}
module index2stage2 where
{- isomorphisms between different kinds of cohomology groups for finite CWs. -}
import cw.cohomology.AxiomaticIsoCellular
| {
"alphanum_fraction": 0.7555970149,
"avg_line_length": 28.2105263158,
"ext": "agda",
"hexsha": "812141184306c70ee391021ce876391f6a6f9943",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/index2stage2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/index2stage2.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/index2stage2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 144,
"size": 536
} |
{-# OPTIONS --cubical --no-exact-split --safe #-}
module Multidimensional.Data.Extra.Nat.Base where
open import Cubical.Data.Nat
sucn : (n : ℕ) → (ℕ → ℕ)
sucn n = iter n suc
| {
"alphanum_fraction": 0.6704545455,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "fd8cf7913d3e757fdbb6ac99ad68ce062e49675c",
"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": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_forks_repo_path": "Multidimensional/Data/Extra/Nat/Base.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_issues_repo_issues_event_max_datetime": "2019-07-02T16:24:01.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-19T20:40:07.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_issues_repo_path": "Multidimensional/Data/Extra/Nat/Base.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "55709dd950e319c4a105ace33ddaf8b955354add",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wrrnhttn/agda-cubical-multidimensional",
"max_stars_repo_path": "Multidimensional/Data/Extra/Nat/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 59,
"size": 176
} |
------------------------------------------------------------------------------
-- Testing the translation of definitions
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module Definition01b where
postulate
D : Set
_≡_ : D → D → Set
-- We test the translation of the definition of a unary function.
foo : D → D
foo d = d
{-# ATP definition foo #-}
postulate bar : ∀ d → d ≡ foo d
{-# ATP prove bar #-}
| {
"alphanum_fraction": 0.4292682927,
"avg_line_length": 26.7391304348,
"ext": "agda",
"hexsha": "752b8ef1dd595915549d551bc489d0aba3957dd1",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "test/Succeed/fol-theorems/Definition01b.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "test/Succeed/fol-theorems/Definition01b.agda",
"max_line_length": 78,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "test/Succeed/fol-theorems/Definition01b.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 117,
"size": 615
} |
{-# OPTIONS --safe --warning=error --without-K --guardedness #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.ClassicalReals.RealField
open import LogicalFormulae
open import Setoids.Subset
open import Setoids.Setoids
open import Setoids.Orders
open import Sets.EquivalenceRelations
open import Rings.Orders.Total.Definition
open import Rings.Orders.Partial.Definition
open import Rings.Definition
open import Fields.Fields
open import Groups.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Order.Lemmas
open import Sequences
module Numbers.ClassicalReals.Sequences (ℝ : RealField) where
open RealField ℝ
open Setoid S
open Equivalence eq
open Ring R
open Field F
open SetoidPartialOrder pOrder
open import Fields.Orders.LeastUpperBounds.Definition pOrder
open import Rings.Orders.Total.Lemmas orderedRing
open import Rings.Orders.Partial.Lemmas pOrderedRing
open Group additiveGroup
open PartiallyOrderedRing pOrderedRing
open SetoidTotalOrder (TotallyOrderedRing.total orderedRing)
open import Rings.InitialRing R
open import Fields.Orders.Lemmas oField
open import Rings.Lemmas R
open import Groups.Lemmas additiveGroup
open import Numbers.Intervals.Definition pOrderedRing
open import Numbers.Intervals.Arithmetic pOrderedRing
open import Fields.Lemmas F
open import Fields.Orders.Total.Definition F
orderedField : TotallyOrderedField pOrderedRing
orderedField = record { oRing = orderedRing }
open import Fields.Orders.Limits.Definition orderedField
StrictlyIncreasing : Sequence A → Set c
StrictlyIncreasing x = (n : ℕ) → (index x n) < (index x (succ n))
Increasing : Sequence A → Set (b ⊔ c)
Increasing x = (n : ℕ) → ((index x n) < (index x (succ n))) || ((index x n) ∼ (index x (succ n)))
sequencePredicate : (x : Sequence A) → A → Set b
sequencePredicate x a = Sg ℕ (λ n → index x n ∼ a)
sequenceSubset : (x : Sequence A) → subset S (sequencePredicate x)
sequenceSubset sequence {x} {y} x=y (n , sn=x) = n , transitive sn=x x=y
boundedSequenceBounds : (K : A) (x : Sequence A) → ((n : ℕ) → index x n < K) → UpperBound (sequenceSubset x) K
boundedSequenceBounds K x pr y (n , y=xn) = inl (<WellDefined y=xn reflexive (pr n))
increasingBoundedLimit : (x : Sequence A) → Increasing x → Bounded x → A
increasingBoundedLimit x increasing (K , kIsBound) with lub (sequenceSubset x) ((index x 0) , (0 , reflexive)) (K , boundedSequenceBounds K x kIsBound)
... | a , _ = a
increasingBoundedConverges : (x : Sequence A) → (increasing : Increasing x) → (bounded : Bounded x) → x ~> (increasingBoundedLimit x increasing bounded)
increasingBoundedConverges x increasing (K , prBound) with lub (sequenceSubset x) (Sequence.head x , (0 , reflexive)) (K , boundedSequenceBounds K x prBound)
... | lub , isLub = {!!}
| {
"alphanum_fraction": 0.7643515237,
"avg_line_length": 39.7464788732,
"ext": "agda",
"hexsha": "55094dce1daafb37c09b4a4c00363810afe6fe3e",
"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/ClassicalReals/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": "Numbers/ClassicalReals/Sequences.agda",
"max_line_length": 157,
"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/ClassicalReals/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": 768,
"size": 2822
} |
------------------------------------------------------------------------
-- Code related to the paper "Up-to Techniques using Sized Types"
--
-- Nils Anders Danielsson
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module README where
------------------------------------------------------------------------
-- Pointers to results from the paper
-- In order to more easily find code corresponding to results from the
-- paper, see the following module. Note that some of the code
-- referenced below is not discussed at all in the paper.
import README.Pointers-to-results-from-the-paper
------------------------------------------------------------------------
-- Some preliminaries
-- Overloaded "equational" reasoning combinators.
import Equational-reasoning
-- Unary and binary relations.
import Relation
------------------------------------------------------------------------
-- Containers
-- Indexed containers.
import Indexed-container
-- Container combinators.
import Indexed-container.Combinators
-- The delay monad defined as the greatest fixpoint of an indexed
-- container.
import Indexed-container.Delay-monad
------------------------------------------------------------------------
-- Up-to techniques
-- Up-to techniques, compatibility, size-preserving functions, and the
-- companion.
import Up-to
-- Closure properties for Compatible and Size-preserving.
--
-- (Some negative results in this module depend on code presented
-- further down.)
import Up-to.Closure
-- Up-to techniques via.
import Up-to.Via
------------------------------------------------------------------------
-- Labelled transition systems
-- Labelled transition systems (LTSs).
import Labelled-transition-system
import Labelled-transition-system.Equational-reasoning-instances
-- CCS.
import Labelled-transition-system.CCS
-- A labelled transition system for the delay monad.
import Labelled-transition-system.Delay-monad
-- An LTS from Section 6.2.5 of "Enhancements of the bisimulation
-- proof method" by Pous and Sangiorgi.
import Labelled-transition-system.6-2-5
------------------------------------------------------------------------
-- Similarity
-- The one-sided Step function, used to define similarity and the
-- two-sided Step function.
import Similarity.Step
-- A parametrised coinductive definition that can be used to define
-- various forms of similarity.
import Similarity.General
-- For more information about similarity, see "Similarity, continued"
-- below.
------------------------------------------------------------------------
-- Strong bisimilarity
-- The Step function, used to define strong and weak bisimilarity as
-- well as expansion.
import Bisimilarity.Step
-- A parametrised coinductive definition that can be used to define
-- strong and weak bisimilarity as well as expansion.
import Bisimilarity.General
-- A coinductive definition of (strong) bisimilarity.
import Bisimilarity
import Bisimilarity.Equational-reasoning-instances
-- The classical definition of (strong) bisimilarity.
import Bisimilarity.Classical
import Bisimilarity.Classical.Equational-reasoning-instances
-- A comparison of the two definitions of bisimilarity.
import Bisimilarity.Comparison
-- Some results related to strong bisimilarity for the delay monad.
import Bisimilarity.Delay-monad
-- Some results related to CCS, implemented without using a fixed form
-- of bisimilarity.
import Bisimilarity.CCS.General
-- Various results or examples related to CCS, implemented using the
-- coinductive definition of bisimilarity.
import Bisimilarity.CCS
import Bisimilarity.CCS.Examples
import Bisimilarity.CCS.Examples.Natural-numbers
-- Some of the results/examples above have also been implemented using
-- the classical definition of bisimilarity.
import Bisimilarity.CCS.Classical
import Bisimilarity.CCS.Examples.Classical
-- Up-to techniques for strong bisimilarity.
import Bisimilarity.Up-to
import Bisimilarity.Up-to.CCS
import Bisimilarity.Up-to.Counterexamples
-- Some results related to an LTS from Section 6.2.5 of "Enhancements
-- of the bisimulation proof method" by Pous and Sangiorgi,
-- implemented using the coinductive definition of bisimilarity.
import Bisimilarity.6-2-5
------------------------------------------------------------------------
-- Expansion
-- A coinductive definition of the expansion ordering.
import Expansion
import Expansion.Equational-reasoning-instances
-- Lemmas related to expansion and CCS.
import Expansion.CCS
-- Some results related to expansion for the delay monad.
import Expansion.Delay-monad
------------------------------------------------------------------------
-- Weak bisimilarity
-- A coinductive definition of weak bisimilarity.
import Bisimilarity.Weak
import Bisimilarity.Weak.Equational-reasoning-instances
-- An alternative (non-standard) coinductive definition of weak
-- bisimilarity.
import Bisimilarity.Weak.Alternative
import Bisimilarity.Weak.Alternative.Equational-reasoning-instances
-- An alternative (non-standard) classical definition of weak
-- bisimilarity.
import Bisimilarity.Weak.Alternative.Classical
-- A comparison of the two alternative definitions of weak
-- bisimilarity.
import Bisimilarity.Weak.Alternative.Comparison
-- The two coinductive definitions of weak bisimilarity are pointwise
-- logically equivalent.
import Bisimilarity.Weak.Equivalent
-- Lemmas related to weak bisimilarity and CCS.
import Bisimilarity.Weak.CCS
-- Examples/exercises related to CCS from "Enhancements of the
-- bisimulation proof method" by Pous and Sangiorgi.
import Bisimilarity.Weak.CCS.Examples
-- Some results about various forms of coinductively defined weak
-- bisimilarity for the delay monad.
import Bisimilarity.Weak.Delay-monad
-- Up-to techniques for the standard coinductive definition of weak
-- bisimilarity.
import Bisimilarity.Weak.Up-to
import Bisimilarity.Weak.Up-to.CCS
-- Up-to techniques for the delay monad and the alternative
-- coinductive definition of weak bisimilarity.
import Bisimilarity.Weak.Alternative.Up-to.Delay-monad
------------------------------------------------------------------------
-- Similarity, continued
-- A coinductive definition of (strong) similarity.
import Similarity
import Similarity.Equational-reasoning-instances
-- Lemmas related to strong similarity for CCS.
import Similarity.CCS
-- A coinductive definition of weak similarity.
import Similarity.Weak
import Similarity.Weak.Equational-reasoning-instances
-- An up-to technique for weak similarity.
import Similarity.Weak.Up-to
| {
"alphanum_fraction": 0.6893700195,
"avg_line_length": 26.1850393701,
"ext": "agda",
"hexsha": "00936431906d6703a62490e2214f81dced054cfb",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "README.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1354,
"size": 6651
} |
-- Length-indexed lists as a recursive family
-- From "Dependent Types at Work", section 3.1
module xx where
open import Level renaming (suc to lsuc)
open import Data.Nat hiding (_^_)
open import Data.Empty.Polymorphic
open import Data.Unit.Polymorphic
open import Data.Maybe hiding (map ; zip)
open import Data.Product hiding (map ; zip)
private
variable
m n : ℕ
ℓ ℓ′ : Level
A : Set ℓ
B : Set ℓ′
-- Vec : Set ℓ → ℕ → Set ℓ
-- Vec A zero = ⊤
-- Vec A (suc n) = A × Vec A n
-- Generalize Vec
open import Function
iter : A → (A → A) → ℕ → A
iter z f zero = z
iter z f (suc n) = f (iter z f n)
-- Is iter defined somewhere standard?
Vec : Set ℓ → ℕ → Set ℓ
Vec A = iter ⊤ (A ×_)
head : Vec A (suc n) → A
head (a , _) = a
tail : Vec A (suc n) → Vec A n
tail (_ , as) = as
map : (A → B) → Vec A n → Vec B n
map {n = zero } _ _ = tt
map {n = suc n} f (a , as) = f a , map {n = n} f as
zip : Vec A n → Vec B n → Vec (A × B) n
zip {n = zero } _ _ = tt
zip {n = suc n} (a , as) (b , bs) = (a , b) , zip {n = n} as bs
Fin : ℕ → Set
Fin zero = ⊥
Fin (suc n) = Maybe (Fin n)
f5 : Fin 5
f5 = nothing
f4 : Fin 4
f4 = nothing
f3 : Fin 3
f3 = nothing
f2 : Fin 2
f2 = just nothing -- an element of the type
f1 : Fin 1
f1 = nothing
-- f0 : Fin 0
-- f0 = {!!} -- no solution found
_!_ : Vec A n → Fin n → A
_!_ {n = suc m} (a , _ ) nothing = a
_!_ {n = suc m} (_ , as) (just i) = as ! i
_!'_ : Vec A n → Fin n → A
_!'_ {n = suc m} (a , _) nothing = a
_!'_ {n = suc m} (_ , as) (just finm) = as !' finm
{-
(0 , 1 , 2 , tt) ! nothing
(0 , 1 , 2 , tt) ! just nothing
(0 , 1 , 2 , tt) ! just (just nothing)
(0 , 1 , 2 , tt) ! just (just (just nothing))
-}
-- Perfect binary leaf tree
BTree : Set ℓ → ℕ → Set ℓ
BTree A = iter A (λ τ → τ × τ)
| {
"alphanum_fraction": 0.5410654828,
"avg_line_length": 20.9534883721,
"ext": "agda",
"hexsha": "45ff6949b18ea45025374a642c66854be4e19279",
"lang": "Agda",
"max_forks_count": 8,
"max_forks_repo_forks_event_max_datetime": "2021-09-21T15:58:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-13T21:40:15.000Z",
"max_forks_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_forks_repo_path": "agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/xx.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"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": "haroldcarr/learn-haskell-coq-ml-etc",
"max_issues_repo_path": "agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/xx.agda",
"max_line_length": 63,
"max_stars_count": 36,
"max_stars_repo_head_hexsha": "3dc7abca7ad868316bb08f31c77fbba0d3910225",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "haroldcarr/learn-haskell-coq-ml-etc",
"max_stars_repo_path": "agda/paper/2009-Dependent_Types_at_Work-Bove_and_Dybjer/xx.agda",
"max_stars_repo_stars_event_max_datetime": "2021-07-30T06:55:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-29T14:37:15.000Z",
"num_tokens": 718,
"size": 1802
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Structures for homogeneous binary relations
------------------------------------------------------------------------
-- The contents of this module should be accessed via `Relation.Binary`.
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary.Core
module Relation.Binary.Structures
{a ℓ} {A : Set a} -- The underlying set
(_≈_ : Rel A ℓ) -- The underlying equality relation
where
open import Data.Product using (proj₁; proj₂; _,_)
open import Level using (Level; _⊔_)
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality.Core as P using (_≡_)
open import Relation.Binary.Consequences
open import Relation.Binary.Definitions
private
variable
ℓ₂ : Level
------------------------------------------------------------------------
-- Equivalences
------------------------------------------------------------------------
-- Note all the following equivalences refer to the equality provided
-- as a module parameter at the top of this file.
record IsPartialEquivalence : Set (a ⊔ ℓ) where
field
sym : Symmetric _≈_
trans : Transitive _≈_
-- The preorders of this library are defined in terms of an underlying
-- equivalence relation, and hence equivalence relations are not
-- defined in terms of preorders.
-- To preserve backwards compatability, equivalence relations are
-- not defined in terms of their partial counterparts.
record IsEquivalence : Set (a ⊔ ℓ) where
field
refl : Reflexive _≈_
sym : Symmetric _≈_
trans : Transitive _≈_
reflexive : _≡_ ⇒ _≈_
reflexive P.refl = refl
isPartialEquivalence : IsPartialEquivalence
isPartialEquivalence = record
{ sym = sym
; trans = trans
}
record IsDecEquivalence : Set (a ⊔ ℓ) where
infix 4 _≟_
field
isEquivalence : IsEquivalence
_≟_ : Decidable _≈_
open IsEquivalence isEquivalence public
------------------------------------------------------------------------
-- Preorders
------------------------------------------------------------------------
record IsPreorder (_∼_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
field
isEquivalence : IsEquivalence
-- Reflexivity is expressed in terms of the underlying equality:
reflexive : _≈_ ⇒ _∼_
trans : Transitive _∼_
module Eq = IsEquivalence isEquivalence
refl : Reflexive _∼_
refl = reflexive Eq.refl
∼-respˡ-≈ : _∼_ Respectsˡ _≈_
∼-respˡ-≈ x≈y x∼z = trans (reflexive (Eq.sym x≈y)) x∼z
∼-respʳ-≈ : _∼_ Respectsʳ _≈_
∼-respʳ-≈ x≈y z∼x = trans z∼x (reflexive x≈y)
∼-resp-≈ : _∼_ Respects₂ _≈_
∼-resp-≈ = ∼-respʳ-≈ , ∼-respˡ-≈
------------------------------------------------------------------------
-- Partial orders
------------------------------------------------------------------------
record IsPartialOrder (_≤_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
field
isPreorder : IsPreorder _≤_
antisym : Antisymmetric _≈_ _≤_
open IsPreorder isPreorder public
renaming
( ∼-respˡ-≈ to ≤-respˡ-≈
; ∼-respʳ-≈ to ≤-respʳ-≈
; ∼-resp-≈ to ≤-resp-≈
)
record IsDecPartialOrder (_≤_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
infix 4 _≟_ _≤?_
field
isPartialOrder : IsPartialOrder _≤_
_≟_ : Decidable _≈_
_≤?_ : Decidable _≤_
open IsPartialOrder isPartialOrder public
hiding (module Eq)
module Eq where
isDecEquivalence : IsDecEquivalence
isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
open IsDecEquivalence isDecEquivalence public
record IsStrictPartialOrder (_<_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
field
isEquivalence : IsEquivalence
irrefl : Irreflexive _≈_ _<_
trans : Transitive _<_
<-resp-≈ : _<_ Respects₂ _≈_
module Eq = IsEquivalence isEquivalence
asym : Asymmetric _<_
asym {x} {y} = trans∧irr⟶asym Eq.refl trans irrefl {x = x} {y}
<-respʳ-≈ : _<_ Respectsʳ _≈_
<-respʳ-≈ = proj₁ <-resp-≈
<-respˡ-≈ : _<_ Respectsˡ _≈_
<-respˡ-≈ = proj₂ <-resp-≈
asymmetric = asym
{-# WARNING_ON_USAGE asymmetric
"Warning: asymmetric was deprecated in v0.16.
Please use asym instead."
#-}
record IsDecStrictPartialOrder (_<_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
infix 4 _≟_ _<?_
field
isStrictPartialOrder : IsStrictPartialOrder _<_
_≟_ : Decidable _≈_
_<?_ : Decidable _<_
private
module SPO = IsStrictPartialOrder isStrictPartialOrder
open SPO public hiding (module Eq)
module Eq where
isDecEquivalence : IsDecEquivalence
isDecEquivalence = record
{ isEquivalence = SPO.isEquivalence
; _≟_ = _≟_
}
open IsDecEquivalence isDecEquivalence public
------------------------------------------------------------------------
-- Total orders
------------------------------------------------------------------------
record IsTotalOrder (_≤_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
field
isPartialOrder : IsPartialOrder _≤_
total : Total _≤_
open IsPartialOrder isPartialOrder public
record IsDecTotalOrder (_≤_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
infix 4 _≟_ _≤?_
field
isTotalOrder : IsTotalOrder _≤_
_≟_ : Decidable _≈_
_≤?_ : Decidable _≤_
open IsTotalOrder isTotalOrder public
hiding (module Eq)
isDecPartialOrder : IsDecPartialOrder _≤_
isDecPartialOrder = record
{ isPartialOrder = isPartialOrder
; _≟_ = _≟_
; _≤?_ = _≤?_
}
module Eq where
isDecEquivalence : IsDecEquivalence
isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
open IsDecEquivalence isDecEquivalence public
-- Note that these orders are decidable. The current implementation
-- of `Trichotomous` subsumes irreflexivity and asymmetry. Any reasonable
-- definition capturing these three properties implies decidability
-- as `Trichotomous` necessarily separates out the equality case.
record IsStrictTotalOrder (_<_ : Rel A ℓ₂) : Set (a ⊔ ℓ ⊔ ℓ₂) where
field
isEquivalence : IsEquivalence
trans : Transitive _<_
compare : Trichotomous _≈_ _<_
infix 4 _≟_ _<?_
_≟_ : Decidable _≈_
_≟_ = tri⟶dec≈ compare
_<?_ : Decidable _<_
_<?_ = tri⟶dec< compare
isDecEquivalence : IsDecEquivalence
isDecEquivalence = record
{ isEquivalence = isEquivalence
; _≟_ = _≟_
}
module Eq = IsDecEquivalence isDecEquivalence
isStrictPartialOrder : IsStrictPartialOrder _<_
isStrictPartialOrder = record
{ isEquivalence = isEquivalence
; irrefl = tri⟶irr compare
; trans = trans
; <-resp-≈ = trans∧tri⟶resp≈ Eq.sym Eq.trans trans compare
}
isDecStrictPartialOrder : IsDecStrictPartialOrder _<_
isDecStrictPartialOrder = record
{ isStrictPartialOrder = isStrictPartialOrder
; _≟_ = _≟_
; _<?_ = _<?_
}
open IsStrictPartialOrder isStrictPartialOrder public
using (irrefl; asym; <-respʳ-≈; <-respˡ-≈; <-resp-≈)
| {
"alphanum_fraction": 0.5858908485,
"avg_line_length": 26.9700374532,
"ext": "agda",
"hexsha": "5aa13eab0e60cf5951062941010e777f72b8ec33",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Relation/Binary/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Relation/Binary/Structures.agda",
"max_line_length": 73,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Relation/Binary/Structures.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": 2185,
"size": 7201
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Maybes where all the elements satisfy a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Maybe.Relation.Unary.All where
open import Category.Applicative
open import Category.Monad
open import Data.Maybe.Base using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.Any using (Any; just)
open import Data.Product as Prod using (_,_)
open import Function using (id; _∘′_)
open import Function.Equivalence using (_⇔_; equivalence)
open import Level
open import Relation.Binary.PropositionalEquality as P using (_≡_; cong)
open import Relation.Unary
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
------------------------------------------------------------------------
-- Definition
data All {a p} {A : Set a} (P : Pred A p) : Pred (Maybe A) (a ⊔ p) where
just : ∀ {x} → P x → All P (just x)
nothing : All P nothing
------------------------------------------------------------------------
-- Basic operations
module _ {a p} {A : Set a} {P : Pred A p} where
drop-just : ∀ {x} → All P (just x) → P x
drop-just (just px) = px
just-equivalence : ∀ {x} → P x ⇔ All P (just x)
just-equivalence = equivalence just drop-just
map : ∀ {q} {Q : Pred A q} → P ⊆ Q → All P ⊆ All Q
map f (just px) = just (f px)
map f nothing = nothing
fromAny : Any P ⊆ All P
fromAny (just px) = just px
------------------------------------------------------------------------
-- (un/)zip(/With)
module _ {a p q r} {A : Set a} {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
zipWith f (just px , just qx) = just (f (px , qx))
zipWith f (nothing , nothing) = nothing
unzipWith : P ⊆ Q ∩ R → All P ⊆ All Q ∩ All R
unzipWith f (just px) = Prod.map just just (f px)
unzipWith f nothing = nothing , nothing
module _ {a p q} {A : Set a} {P : Pred A p} {Q : Pred A q} where
zip : All P ∩ All Q ⊆ All (P ∩ Q)
zip = zipWith id
unzip : All (P ∩ Q) ⊆ All P ∩ All Q
unzip = unzipWith id
------------------------------------------------------------------------
-- Traversable-like functions
module _ {a} p {A : Set a} {P : Pred A (a ⊔ p)} {F}
(App : RawApplicative {a ⊔ p} F) where
open RawApplicative App
sequenceA : All (F ∘′ P) ⊆ F ∘′ All P
sequenceA nothing = pure nothing
sequenceA (just px) = just <$> px
mapA : ∀ {q} {Q : Pred A q} → (Q ⊆ F ∘′ P) → All Q ⊆ (F ∘′ All P)
mapA f = sequenceA ∘′ map f
forA : ∀ {q} {Q : Pred A q} {xs} → All Q xs → (Q ⊆ F ∘′ P) → F (All P xs)
forA qxs f = mapA f qxs
module _ {a} p {A : Set a} {P : Pred A (a ⊔ p)} {M}
(Mon : RawMonad {a ⊔ p} M) where
private App = RawMonad.rawIApplicative Mon
sequenceM : All (M ∘′ P) ⊆ M ∘′ All P
sequenceM = sequenceA p App
mapM : ∀ {q} {Q : Pred A q} → (Q ⊆ M ∘′ P) → All Q ⊆ (M ∘′ All P)
mapM = mapA p App
forM : ∀ {q} {Q : Pred A q} {xs} → All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
forM = forA p App
------------------------------------------------------------------------
-- Seeing All as a predicate transformer
module _ {a p} {A : Set a} {P : Pred A p} where
dec : Decidable P → Decidable (All P)
dec P-dec nothing = yes nothing
dec P-dec (just x) = Dec.map just-equivalence (P-dec x)
universal : Universal P → Universal (All P)
universal P-universal (just x) = just (P-universal x)
universal P-universal nothing = nothing
irrelevant : Irrelevant P → Irrelevant (All P)
irrelevant P-irrelevant (just p) (just q) = cong just (P-irrelevant p q)
irrelevant P-irrelevant nothing nothing = P.refl
satisfiable : Satisfiable (All P)
satisfiable = nothing , nothing
| {
"alphanum_fraction": 0.5321821036,
"avg_line_length": 31.5867768595,
"ext": "agda",
"hexsha": "24d890ff20b758fe128ddc57f44ac1588a7a8cc3",
"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/Maybe/Relation/Unary/All.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/Maybe/Relation/Unary/All.agda",
"max_line_length": 81,
"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/Maybe/Relation/Unary/All.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1186,
"size": 3822
} |
-- Andreas, 2017-03-30, issue #2524
-- compile abstract definitions to arbitrary Haskell code
module Issue2524 where
open import Agda.Builtin.Nat
open import Agda.Builtin.Unit
open import Agda.Builtin.String
{-# FOREIGN GHC import qualified Data.Text #-}
postulate
NativeIO : Set → Set
nativeReturn : {A : Set} → A → NativeIO A
_native>>=_ : {A B : Set} → NativeIO A → (A → NativeIO B) → NativeIO B
{-# BUILTIN IO NativeIO #-}
{-# COMPILE GHC NativeIO = type IO #-}
{-# COMPILE GHC nativeReturn = (\_ -> return :: a -> IO a) #-}
{-# COMPILE GHC _native>>=_ = (\_ _ -> (>>=) :: IO a -> (a -> IO b) -> IO b) #-}
{-# COMPILE JS nativeReturn =
function(u0) { return function(u1) { return function(x) { return function(cb) { cb(x); }; }; }; } #-}
{-# COMPILE JS _native>>=_ =
function(u0) { return function(u1) { return function(u2) { return function(u3) {
return function(x) { return function(y) { return function(cb) {
x(function (xx) { y(xx)(cb); });
}; }; };
}; }; }; }
#-}
postulate
nativePutStrLn : String → NativeIO ⊤
primShowNat : Nat → String
{-# COMPILE GHC nativePutStrLn = (\ s -> putStrLn (Data.Text.unpack s)) #-}
{-# COMPILE GHC primShowNat = Data.Text.pack . show #-}
{-# COMPILE JS nativePutStrLn = function (x) { return function(cb) { process.stdout.write(x + '\n'); cb(0); }; } #-}
{-# COMPILE JS primShowNat = agdaRTS.primShowInteger #-}
abstract
record Pointer : Set where
constructor mkPointer
field thePointer : Nat
otherInfo : Nat
newPointer : Pointer
newPointer = mkPointer 5 17
showPointer : Pointer → String
showPointer p = primShowNat (Pointer.thePointer p)
{-# COMPILE GHC Pointer = type Integer #-}
{-# COMPILE GHC newPointer = 5 #-}
{-# COMPILE GHC showPointer = Data.Text.pack . show #-}
{-# COMPILE JS newPointer = 5 #-}
{-# COMPILE JS showPointer = function(x) { return x; } #-}
main : NativeIO ⊤
main = nativePutStrLn (showPointer newPointer)
| {
"alphanum_fraction": 0.6363171355,
"avg_line_length": 32.0491803279,
"ext": "agda",
"hexsha": "a46b1bfe228c00e6014b7f87fb733bf329dca6b1",
"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/Compiler/simple/Issue2524.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/Compiler/simple/Issue2524.agda",
"max_line_length": 116,
"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/Compiler/simple/Issue2524.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": 552,
"size": 1955
} |
module Data.Lens.Proofs.LensLaws where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Data.Lens.Lens
open import Data.Logic
open import Agda.Primitive
-- First, define the lens laws
ViewSet : {a b : Set} -> (l : Lens a b) -> Set
ViewSet {a} {b} l = (v : b) (s : a) -> view l (set l v s) ≡ v
SetView : {a b : Set} -> (l : Lens a b) -> Set
SetView {a} {b} l = (s : a) -> set l (view l s) s ≡ s
SetSet : {a b : Set} -> (l : Lens a b) -> Set
SetSet {a} {b} l = (v1 v2 : b) (s : a) -> set l v2 (set l v1 s) ≡ set l v2 s
-- Define ValidLens as a lens for which the laws hold
data ValidLens (a b : Set) : Set₁ where
CValidLens : (l : Lens a b) -> ViewSet l -> SetView l -> SetSet l -> ValidLens a b
toLens : ValidLens a b -> Lens a b
toLens (CValidLens l _ _ _) = l
| {
"alphanum_fraction": 0.6020151134,
"avg_line_length": 29.4074074074,
"ext": "agda",
"hexsha": "20f152bdfa894d785a75ecb2c120ec8a5cfde202",
"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/Lens/Proofs/LensLaws.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/Lens/Proofs/LensLaws.agda",
"max_line_length": 84,
"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/Lens/Proofs/LensLaws.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": 299,
"size": 794
} |
record R {a} (A : Set a) : Set a where
field
some : A
module Works0 where
works : ∀ {a}{A : Set a} {{r : R A}} -> A
works = x
where
open R {{...}}
x = some
-- If we add a dummy argument of type Set to "works" we fail, see module Fails
-- below.
-- But there is a chance it still works:
module Works where
postulate
works : ∀ {a}{A : Set a} -> A
test : ∀ {a}{A : Set a} {{r : R A}} -> Set -> A
test B = x
where
open R {{...}}
x = some
-- Or, we could have an unsolved meta:
module Unsolved where
postulate
works : ∀ {a}{A : Set a} {r : R A} -> A
test : ∀ {a}{A : Set a} {{r : R A}} -> Set -> A
test B = x
where
open R {{...}}
x = some
-- unsolved at "x" in "test B = x":
-- _r_45 : R (R .A)
-- This is the mysterious failure instance:
module Fails where
fails : ∀ {a}{A : Set a} {{r : R A}} -> Set -> A
fails B = x
where
open R {{...}}
x = some
-- No variable of type R (_A_54 .some B) was found in scope
-- when checking that the expression x has type .A
| {
"alphanum_fraction": 0.5167286245,
"avg_line_length": 19.2142857143,
"ext": "agda",
"hexsha": "74f154bfd6dc4fc960c62dae7f499c301461b2fc",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue777.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue777.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue777.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": 372,
"size": 1076
} |
module _ where
module A where
infix 2 _↑
infix 1 _↓_
data D : Set where
● : D
_↑ : D → D
_↓_ : D → D → D
module B where
data D : Set where
_↓_ : D → D → D
open A
open B
rejected : A.D
rejected = ● ↑ ↓ ●
| {
"alphanum_fraction": 0.5021097046,
"avg_line_length": 10.3043478261,
"ext": "agda",
"hexsha": "0947c176fd402c99b705e687ab5376fdee0d7e01",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue1436-4.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue1436-4.agda",
"max_line_length": 20,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue1436-4.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 95,
"size": 237
} |
-- Andreas, 2014-05-20, issue reported by Fabien Renaud
module Issue1125 where
f : {A- : Set} -> Set
f {A-} = A-
-- Should give a parse error now
-- since a comment is closed -} but none opened.
| {
"alphanum_fraction": 0.6582914573,
"avg_line_length": 18.0909090909,
"ext": "agda",
"hexsha": "e5d4d740375fce3bd5b493c57b1ce6dfcf77da1e",
"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/Issue1125.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/Issue1125.agda",
"max_line_length": 55,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1125.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 64,
"size": 199
} |
-- Andreas, 2021-01-28 documenting #4702, reported by gallais
open import Agda.Builtin.Nat
case_of_ : {A B : Set} → A → (A → B) → B
case x of f = f x
-- Needed for making `plus` pass the termination checker.
-- Used to be automatic via `--auto-inline`, since 2.6.2 this flag
-- is off by default.
{-# INLINE case_of_ #-}
plus : Nat → Nat → Nat
plus m n = case m of λ
{ zero → n
; (suc m) → suc (plus m n)
}
| {
"alphanum_fraction": 0.6155660377,
"avg_line_length": 22.3157894737,
"ext": "agda",
"hexsha": "e3edde391b1a0cba0cf143e6fc29d8568a4ab488",
"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/Issue4702.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/Issue4702.agda",
"max_line_length": 66,
"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/Issue4702.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 143,
"size": 424
} |
module Numeral.Ordinal where
import Lvl
open import Numeral.Natural
open import Syntax.Function
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
-- Ordinal numbers up to a certain level as a type.
-- 𝟎 is the zero ordinal, the smallest ordinal number.
-- 𝐒 is the successor ordinal function, the smallest ordinal greater than the given argument.
-- lim is the limit ordinal function, the "limit" of the given sequence. The smallest ordinal greater than all values of the given sequence. Note that this is not the usual definition of a "limit ordinal" because `lim` allows arbitrary sequences, specifically those with a maximum, resulting in an equivalent to the successor ordinal `𝐒` (TODO: If this is the case, then 𝐒 is actually unnecessary? Just define it by (lim ∘ const)?
-- Note: Usually the indexing in a limit ordinal should be the class of ordinals before it, so this definition is probably unable to express all ordinals.
data Ordinal(T : Type{ℓ}) : Type{ℓ} where
𝟎 : Ordinal(T)
𝐒 : Ordinal(T) → Ordinal(T)
lim : (T → Ordinal(T)) → Ordinal(T)
{-
data Ordinal' : (ℓ : Lvl.Level) → Typeω where
𝟎 : Ordinal'(ℓ)
𝐒 : Ordinal'(ℓ) → Ordinal'(ℓ)
lim : (Ordinal'(ℓ) → Ordinal'(Lvl.𝐒(ℓ))) → Ordinal'(Lvl.𝐒(ℓ)) -- When the next ordinal have the current ordinal as its index
data Ordinal(T : Type{ℓ}) : Type{ℓ} where
𝟎 : Ordinal(T)
lim : (T → Ordinal(T)) → Ordinal(T) -- 𝐒 is expressable through lim
data Ordinal(T : Type{ℓ}) : Type{ℓ} where
𝟎 : Ordinal(T)
𝐒 : Ordinal(T) → Ordinal(T)
lim : (f : T → Ordinal(T)) → ∃(IncreasingSubsequence(_<_)(f)) → Ordinal(T) -- This excludes the cases where f have a maximum, resulting in no intersection between 𝐒 and lim
-}
_+_ : Ordinal(T) → Ordinal(T) → Ordinal(T)
x + 𝟎 = x
x + 𝐒(y) = 𝐒(x + y)
x + lim f = lim(y ↦ (x + f(y)))
_⋅_ : Ordinal(T) → Ordinal(T) → Ordinal(T)
x ⋅ 𝟎 = 𝟎
x ⋅ 𝐒(y) = (x ⋅ y) + x
x ⋅ lim f = lim(y ↦ (x ⋅ f(y)))
_^_ : Ordinal(T) → Ordinal(T) → Ordinal(T)
x ^ 𝟎 = x
x ^ 𝐒(y) = (x ^ y) ⋅ x
x ^ lim f = lim(y ↦ (x ^ f(y)))
open import Logic.Propositional
private variable x y z x₁ x₂ y₁ y₂ z₁ z₂ : Ordinal(T)
module _ {T : Type{ℓ}} where
open import Functional
open import Logic.Propositional
-- TODO: Not sure if this is correct
data _<_ : Ordinal(T) → Ordinal(T) → Type{ℓ} where
minimal : ∀{x} → (𝟎 < 𝐒(x))
step : ∀{x y} → (x < y) → (𝐒(x) < 𝐒(y))
limitₗ : ∀{f}{x} → (∀{i} → (f(i) < x)) → (lim f < 𝐒(x))
limitᵣ : ∀{i}{f}{x} → (x < 𝐒(f(i))) → (x < lim f)
_>_ = swap(_<_)
_≤_ : Ordinal(T) → Ordinal(T) → Type
x ≤ y = x < 𝐒(y)
_≥_ = swap(_≤_)
_≡_ : Ordinal(T) → Ordinal(T) → Type
x ≡ y = (y ≤ x) ∧ (x ≤ y)
open import Numeral.Natural.Induction
from-ℕ : ℕ → Ordinal(T)
from-ℕ = ℕ-elim 𝟎 (const 𝐒)
_+ₙ_ : Ordinal(T) → ℕ → Ordinal(T)
_+ₙ_ x = ℕ-elim x (const 𝐒)
private variable f g : T → Ordinal(T)
private variable n : T
[<]-limitₗ-inv : (lim f < 𝐒(x)) → (∀{n} → (f(n) < x))
[<]-limitₗ-inv (limitₗ p) = p
open import Logic.Predicate
open import Type.Properties.Inhabited
[<]-limitᵣ-inv : (x < lim f) → ∃(n ↦ (x < 𝐒(f(n))))
[<]-limitᵣ-inv (limitᵣ{n} p) = [∃]-intro n ⦃ p ⦄
[<]-lim-minimal : ⦃ ◊ T ⦄ → (𝟎 < lim f)
[<]-lim-minimal = limitᵣ{i = [◊]-existence} minimal
[<]-lim-maximum : (f(n) < lim f)
[<]-of-step : (x < 𝐒(x))
[<]-lim-maximum{f}{n} = limitᵣ{n} [<]-of-step
[<]-without-step : (𝐒(x) < 𝐒(y)) → (x < y)
[<]-without-step (step p) = p
[<]-of-step {𝟎} = minimal
[<]-of-step {𝐒(x)} = step [<]-of-step
[<]-of-step {lim f} = limitₗ [<]-lim-maximum
[<]-transitivity : (x < y) → (y < z) → (x < z)
[<]-transitivity minimal (step yz) = minimal
[<]-transitivity minimal (limitᵣ {n}{f} yz) = limitᵣ {n}{f} minimal
[<]-transitivity (step xy) (step yz) = step ([<]-transitivity xy yz)
[<]-transitivity (step xy) (limitᵣ yz) = limitᵣ ([<]-transitivity (step xy) yz)
[<]-transitivity (limitₗ xy) (step yz) = limitₗ ([<]-transitivity xy yz)
[<]-transitivity (limitₗ xy) (limitᵣ yz) = limitᵣ (limitₗ ([<]-without-step([<]-transitivity (step xy) yz)))
[<]-transitivity (limitᵣ xy) (limitₗ yz) = [<]-transitivity xy (step yz)
[<]-transitivity (limitᵣ xy) (limitᵣ yz) = limitᵣ ([<]-transitivity (limitᵣ xy) yz)
[<]-stepᵣ : (x < y) → (x < 𝐒(y))
[<]-stepᵣ minimal = minimal
[<]-stepᵣ (step p) = step ([<]-stepᵣ p)
[<]-stepᵣ (limitₗ p) = limitₗ ([<]-stepᵣ p)
[<]-stepᵣ (limitᵣ p) = [<]-transitivity p (step [<]-lim-maximum)
[<]-to-[≤] : (x < y) → (x ≤ y)
[<]-to-[≤] = [<]-stepᵣ
[<]-irreflexivity : ¬(x < x)
[<]-irreflexivity (step p) = [<]-irreflexivity p
[<]-irreflexivity (limitᵣ (limitₗ x)) = [<]-irreflexivity x
[<]-asymmetry : (x < y) → (y < x) → ⊥
[<]-asymmetry xy yx = [<]-irreflexivity([<]-transitivity xy yx)
[<]-without-stepₗ : (𝐒(x) < y) → (x < y)
[<]-without-stepₗ (step p) = [<]-stepᵣ p
[<]-without-stepₗ (limitᵣ p) = limitᵣ ([<]-without-stepₗ p)
[<]-no-less-than-minimum : ¬(x < 𝟎)
[<]-no-less-than-minimum ()
[≤]-minimal : (𝟎 ≤ x)
[≤]-minimal = minimal
[≤]-step : (x ≤ y) → (𝐒(x) ≤ 𝐒(y))
[≤]-step = step
[≤]-reflexivity : (x ≤ x)
[≤]-reflexivity = [<]-of-step
[≡]-reflexivity : (x ≡ x)
[≡]-reflexivity = [∧]-intro [≤]-reflexivity [≤]-reflexivity
open import Logic.Propositional.Theorems
[≡]-symmetry : (x ≡ y) → (y ≡ x)
[≡]-symmetry = [∧]-symmetry
[≡]-step : (x ≡ y) → (𝐒(x) ≡ 𝐒(y))
[≡]-step = [∧]-map step step
open import Relator.Equals renaming (_≡_ to _≡ₑ_)
[<]-less-than-one : ⦃ ◊ T ⦄ → (x < 𝐒(𝟎)) → (x ≡ₑ 𝟎)
[<]-less-than-one minimal = [≡]-intro
[<]-less-than-one (limitₗ p) with () ← p{[◊]-existence}
[<][≤]-semitransitivityₗ : ⦃ ◊ T ⦄ → (x ≤ y) → (y < z) → (x < z)
[<][≤]-semitransitivityₗ {_} {y} {.(lim _)} xy (limitᵣ yz) = limitᵣ ([<][≤]-semitransitivityₗ xy yz)
[<][≤]-semitransitivityₗ {.𝟎} {.𝟎} {.(𝐒 _)} minimal minimal = minimal
[<][≤]-semitransitivityₗ {.𝟎} {.(𝐒 _)} {.(𝐒 _)} minimal (step yz) = minimal
[<][≤]-semitransitivityₗ {.𝟎} {.(lim _)} {.(𝐒 _)} minimal (limitₗ x) = minimal
[<][≤]-semitransitivityₗ {.(𝐒 _)} {.(𝐒 _)} {.(𝐒 _)} (step xy) (step yz) = step ([<][≤]-semitransitivityₗ xy yz)
[<][≤]-semitransitivityₗ {.(𝐒 _)} {.(lim _)} {.(𝐒 _)} (step (limitᵣ xy)) (limitₗ yz) = step ([<][≤]-semitransitivityₗ xy yz)
[<][≤]-semitransitivityₗ {.(lim _)} {.𝟎} {.(𝐒 _)} (limitₗ xy) minimal with () ← xy{[◊]-existence}
[<][≤]-semitransitivityₗ {.(lim _)} {.(𝐒 _)} {.(𝐒 _)} (limitₗ xy) (step yz) = limitₗ ([<][≤]-semitransitivityₗ xy yz)
[<][≤]-semitransitivityₗ {.(lim _)} {.(lim _)} {.(𝐒 _)} (limitₗ xy) (limitₗ yz) = limitₗ ([<][≤]-semitransitivityₗ ([∃]-proof([<]-limitᵣ-inv xy)) yz)
[≤]-transitivity : ⦃ ◊ T ⦄ → (x ≤ y) → (y ≤ z) → (x ≤ z)
[≤]-transitivity = [<][≤]-semitransitivityₗ
[≡]-transitivity : ⦃ ◊ T ⦄ → (x ≡ y) → (y ≡ z) → (x ≡ z)
[≡]-transitivity ([∧]-intro yx xy) ([∧]-intro zy yz) = [∧]-intro ([≤]-transitivity zy yx) ([≤]-transitivity xy yz)
[<][≤]-semitransitivityᵣ : ⦃ ◊ T ⦄ → (x < y) → (y ≤ z) → (x < z)
[<][≤]-semitransitivityᵣ {.𝟎} {.(𝐒 𝟎)} {.(𝐒 _)} minimal (step minimal) = minimal
[<][≤]-semitransitivityᵣ {.𝟎} {.(𝐒 (𝐒 _))} {.(𝐒 _)} minimal (step (step yz)) = minimal
[<][≤]-semitransitivityᵣ {.𝟎} {.(𝐒 (lim _))} {.(𝐒 _)} minimal (step (limitₗ yz)) = minimal
[<][≤]-semitransitivityᵣ {.𝟎} {.(𝐒 _)} {.(lim _)} minimal (step (limitᵣ yz)) = limitᵣ{[◊]-existence} minimal
[<][≤]-semitransitivityᵣ {.(𝐒 _)} {.(𝐒 _)} {𝐒 z} (step xy) (step yz) = step ([<][≤]-semitransitivityᵣ xy yz)
[<][≤]-semitransitivityᵣ {.(𝐒 _)} {.(𝐒 _)} {lim z} (step xy) (step (limitᵣ yz)) = limitᵣ (step ([<][≤]-semitransitivityᵣ xy yz))
[<][≤]-semitransitivityᵣ {.(lim _)} {.(𝐒 _)} {𝐒 z} (limitₗ xy) (step yz) = limitₗ ([<][≤]-semitransitivityᵣ xy yz)
[<][≤]-semitransitivityᵣ {.(lim _)} {.(𝐒 _)} {lim z} (limitₗ xy) (step (limitᵣ yz)) = limitᵣ ([<][≤]-semitransitivityᵣ (limitₗ xy) (step yz))
[<][≤]-semitransitivityᵣ {x} {.(lim _)} {z} (limitᵣ xy) (limitₗ yz) = [<][≤]-semitransitivityᵣ xy (step yz)
{-
StrictlyIncreasingSubsequenceExistence : ∀{ℓ}{I : Type{ℓ}} → (I → Ordinal(T)) → Type
StrictlyIncreasingSubsequenceExistence{I = I} (f) = ∃{Obj = ℕ → I}(g ↦ ∀{n} → (f(g(n)) < f(g(𝐒(n)))))
-- TODO: Requires some kind of search for T
StrictlyIncreasingSubsequenceExistence-to-no-maximum : StrictlyIncreasingSubsequenceExistence(f) → ¬ ∃(max ↦ ∀{x} → (f(x) < f(max)))
StrictlyIncreasingSubsequenceExistence-to-no-maximum ([∃]-intro witness) ([∃]-intro witness₁) = [<]-asymmetry {!!} {!!}
-}
{- TODO: Maybe unprovable constructively
[<]-classical : (x < y) ∨ ¬(x < y)
[<]-classical {𝟎} {𝟎} = [∨]-introᵣ \()
[<]-classical {𝟎} {𝐒 y} = [∨]-introₗ minimal
[<]-classical {𝟎} {lim y} = [∨]-introₗ (limitᵣ{𝟎} minimal)
[<]-classical {𝐒 x} {𝟎} = [∨]-introᵣ \()
[<]-classical {𝐒 x} {𝐒 y} = [∨]-elim2 step (_∘ [<]-without-step) ([<]-classical {x} {y})
[<]-classical {𝐒 x} {lim y} with [<]-classical {x} {lim y}
... | [∨]-introₗ p = {!!}
... | [∨]-introᵣ p = {!!}
[<]-classical {lim x} {𝟎} = [∨]-introᵣ \()
[<]-classical {lim x} {𝐒 y} with [<]-classical {lim x} {y}
... | [∨]-introₗ (limitₗ p) = [∨]-introₗ (limitₗ ([<]-stepᵣ p))
... | [∨]-introₗ (limitᵣ (limitₗ p)) = [∨]-introₗ (limitₗ (limitᵣ ([<]-stepᵣ p)))
... | [∨]-introᵣ p = [∨]-introᵣ (p ∘ (q ↦ {![<]-limitₗ-inv q!}))
[<]-classical {lim x} {lim y} = {!!}
-}
{- TODO: This is true when there is no maximum for f
∀{x} → ∃(y ↦ (x < y) ∧ (f(x) < f(y)))
test : (x < lim f) → (𝐒(x) < lim f)
test {𝟎} (limitᵣ minimal) = limitᵣ (step {!!})
test {𝐒 x} (limitᵣ (step p)) = limitᵣ (step {!!})
test {lim x} (limitᵣ (limitₗ x₁)) = {!!}
-}
{- TODO: Also unprovable constructively?
f either have a maximum value or is unbounded (so, this would require some kind of search?)
[<]-sequence-limit : ∀{n} → (f(n) < lim g) → ((∀{n} → (f(n) < lim g)) ∨ (f(n) ≡ x))
[≤]-total : ⦃ ◊ T ⦄ → ((x ≤ y) ∨ (y ≤ x))
[≤]-total {𝟎} {_} = [∨]-introₗ minimal
[≤]-total {_} {𝟎} = [∨]-introᵣ minimal
[≤]-total {𝐒 x} {𝐒 y} = [∨]-elim2 step step ([≤]-total {x} {y})
[≤]-total {𝐒 x} {lim y} with [≤]-total {x} {lim y}
... | [∨]-introₗ minimal = [∨]-introₗ (step [<]-lim-minimal)
... | [∨]-introₗ (step (limitᵣ p)) = [∨]-introₗ (step (limitᵣ (step {!!})))
... | [∨]-introₗ (limitₗ p) = [∨]-introₗ (step (limitᵣ (limitₗ (\{n} → {![<]-limitᵣ-inv (p{n})!}))))
... | [∨]-introᵣ p = [∨]-introᵣ ([<]-stepᵣ p)
[≤]-total {lim x} {𝐒 y} = {!!} -- [∨]-symmetry ([≤]-total {𝐒 y} {lim x})
[≤]-total {lim x} {lim y} = {!!}
-}
{-
[≤]-to-[<][≡] : ⦃ ◊ T ⦄ → (x ≤ y) → ((x < y) ∨ (x ≡ y))
[≤]-to-[<][≡] {𝟎} {𝟎} minimal = [∨]-introᵣ ([∧]-intro minimal minimal)
[≤]-to-[<][≡] {𝟎} {𝐒 y} minimal = [∨]-introₗ minimal
[≤]-to-[<][≡] {𝟎} {lim y} minimal = [∨]-introₗ [<]-lim-minimal
[≤]-to-[<][≡] {𝐒 x} {𝐒 y} (step p) = [∨]-elim2 step [≡]-step ([≤]-to-[<][≡] {x}{y} p)
[≤]-to-[<][≡] {𝐒 x} {lim y} (step (limitᵣ p)) with [≤]-to-[<][≡] p
... | [∨]-introₗ pp = [∨]-introₗ (limitᵣ (step pp))
... | [∨]-introᵣ ([∧]-intro l r) = {!!}
-- [∨]-introᵣ ([∧]-intro (limitₗ (\{n} → {!!})) (step (limitᵣ r)))
-- [∨]-elim2 (limitᵣ ∘ step) (\([∧]-intro l r) → [∧]-intro (limitₗ {![<]-stepᵣ l!}) (step (limitᵣ r))) ([≤]-to-[<][≡] p)
[≤]-to-[<][≡] {lim x} {𝟎} (limitₗ p) = [∨]-introᵣ ([∧]-intro minimal (limitₗ p))
[≤]-to-[<][≡] {lim x} {𝐒 y} (limitₗ p) = {!!}
[≤]-to-[<][≡] {lim x} {lim y} (limitₗ p) = {!!}
[<]-trichotomy : ⦃ ◊ T ⦄ → ((x < y) ∨ (x ≡ y) ∨ (x > y))
[<]-trichotomy {𝟎} {𝟎} = [∨]-introₗ ([∨]-introᵣ [≡]-reflexivity)
[<]-trichotomy {𝟎} {𝐒 y} = [∨]-introₗ ([∨]-introₗ minimal)
[<]-trichotomy {𝟎} {lim y} = [∨]-introₗ ([∨]-introₗ [<]-lim-minimal)
[<]-trichotomy {𝐒 x} {𝟎} = [∨]-introᵣ minimal
[<]-trichotomy {lim x} {𝟎} = [∨]-introᵣ [<]-lim-minimal
[<]-trichotomy {𝐒 x} {𝐒 y} = [∨]-elim2 ([∨]-elim2 step [≡]-step) step ([<]-trichotomy {x}{y})
[<]-trichotomy {𝐒 x} {lim y} with [<]-trichotomy {x} {lim y}
... | [∨]-introₗ ([∨]-introᵣ ([∧]-intro p _)) = [∨]-introᵣ p
... | [∨]-introᵣ p = [∨]-introᵣ ([<]-stepᵣ p)
... | [∨]-introₗ ([∨]-introₗ (limitᵣ{n} p)) = {!!}
[<]-trichotomy {lim x} {𝐒 y} = {!!}
[<]-trichotomy {lim x} {lim y} = {!!}
-}
lim-of-constant : ⦃ ◊ T ⦄ → (lim(const x) ≡ 𝐒(x))
lim-of-constant = [∧]-intro (step (limitᵣ{[◊]-existence} [<]-of-step)) (limitₗ [<]-of-step)
lim-of-sequence-with-maximum : ∀{max} → (∀{n} → (f(n) ≤ f(max))) → (lim f ≡ 𝐒(f(max)))
lim-of-sequence-with-maximum{max = max} p = [∧]-intro (step (limitᵣ{max} [<]-of-step)) (limitₗ p)
-- ∃(max ↦ (∀{n} → (f(n) ≤ f(max))) ∧ (lim f ≡ 𝐒(f(max)))) ∨ (∀{x} → (𝐒(f(x)) < lim f)) -- or maybe (∀{x y} → (f(x) + f(y) < lim f))
lim-[≤]-function : (∀{x} → (f(x) ≤ g(x))) → (lim f ≤ lim g)
lim-[≤]-function p = limitₗ(limitᵣ p)
lim-function : (∀{x} → (f(x) ≡ g(x))) → (lim f ≡ lim g)
lim-function p = [∧]-intro (lim-[≤]-function([∧]-elimₗ p)) (lim-[≤]-function([∧]-elimᵣ p))
[+]-identityᵣ : ((x + 𝟎) ≡ x)
[+]-identityᵣ = [≡]-reflexivity
[+]-identityₗ : ((𝟎 + x) ≡ x)
[+]-identityₗ {𝟎} = [+]-identityᵣ
[+]-identityₗ {𝐒 x} = [≡]-step ([+]-identityₗ {x})
[+]-identityₗ {lim x} = lim-function [+]-identityₗ
[+]-associativity : (((x + y) + z) ≡ (x + (y + z)))
[+]-associativity {x}{y}{𝟎} = [≡]-reflexivity
[+]-associativity {x}{y}{𝐒 z} = [≡]-step ([+]-associativity {x}{y}{z})
[+]-associativity {x}{y}{lim z} = lim-function ([+]-associativity {x}{y}{_})
[+]ₗ-[<][≤]-semifunction : (x < y) → ((x + z) ≤ (y + z))
[+]ₗ-[<][≤]-semifunction {z = 𝟎} p = [<]-to-[≤] p
[+]ₗ-[<][≤]-semifunction {z = 𝐒 z} p = [≤]-step([+]ₗ-[<][≤]-semifunction {z = z} p)
[+]ₗ-[<][≤]-semifunction {z = lim x} p = limitₗ (limitᵣ ([+]ₗ-[<][≤]-semifunction p))
[+]ᵣ-[<]-function : ⦃ ◊ T ⦄ → (y < z) → ((x + y) < (x + z))
[+]ᵣ-[<]-function (minimal {𝟎}) = [<]-of-step
[+]ᵣ-[<]-function (minimal {𝐒 x}) = [<]-stepᵣ ([+]ᵣ-[<]-function minimal)
[+]ᵣ-[<]-function (minimal {lim x}) = [<]-stepᵣ (limitᵣ{[◊]-existence} ([+]ᵣ-[<]-function minimal))
[+]ᵣ-[<]-function (step p) = step ([+]ᵣ-[<]-function p)
[+]ᵣ-[<]-function (limitₗ p) = limitₗ ([+]ᵣ-[<]-function p)
[+]ᵣ-[<]-function (limitᵣ p) = limitᵣ ([+]ᵣ-[<]-function p)
{-
[+]-operator : ⦃ ◊ T ⦄ → (x₁ ≡ x₂) → (y₁ ≡ y₂) → ((x₁ + y₁) ≡ (x₂ + y₂))
[+]-operator ([∧]-intro pxl pxr) ([∧]-intro pyl pyr) = [∧]-intro {!!} {!!} where
l : (x₁ ≡ x₂) → ((x₁ + y) ≡ (x₂ + y))
l {𝟎} {x₂} ([∧]-intro pl pr) = [∧]-intro {!!} {!!}
l {𝐒 x₁} {x₂} ([∧]-intro pl pr) = [∧]-intro {!!} {!!}
l {lim x₁} {x₂} ([∧]-intro pl pr) = [∧]-intro {!!} {!!}
r : (y₁ ≡ y₂) → ((x + y₁) ≡ (x + y₂))
r ([∧]-intro pl pr) = [∧]-intro ([+]ᵣ-[<]-function pl) ([+]ᵣ-[<]-function pr)
-}
open import Structure.Relator.Ordering
open Structure.Relator.Ordering.Strict.Properties using (intro)
Ordinal-accessibleₗ : ⦃ ◊ T ⦄ → Strict.Properties.Accessibleₗ(_<_)(x)
Ordinal-accessibleₗ {n} = intro ⦃ proof{n} ⦄ where
proof : ∀{y x} → ⦃ _ : (x < y) ⦄ → Strict.Properties.Accessibleₗ(_<_)(x)
proof {_} {𝟎} = intro ⦃ \ ⦃ ⦄ ⦄
proof {𝐒 𝟎} {lim y} ⦃ limitₗ p ⦄ with () ← p{[◊]-existence}
proof {𝐒 x} {𝐒 y} ⦃ step p ⦄ = intro ⦃ \{z} ⦃ pz ⦄ → Strict.Properties.Accessibleₗ.proof (Ordinal-accessibleₗ {x}) ⦃ [<][≤]-semitransitivityₗ pz p ⦄ ⦄
proof {𝐒(𝐒 x)} {lim y} ⦃ limitₗ p ⦄ = intro ⦃ \{z} ⦃ pz ⦄ → Strict.Properties.Accessibleₗ.proof (Ordinal-accessibleₗ {𝐒 x}) ⦃ [<][≤]-semitransitivityₗ ([∃]-proof([<]-limitᵣ-inv pz)) p ⦄ ⦄
proof {𝐒(lim x)} {lim y} ⦃ limitₗ p ⦄ = intro ⦃ \{z} ⦃ pz ⦄ → Strict.Properties.Accessibleₗ.proof (Ordinal-accessibleₗ {lim x}) ⦃ [<][≤]-semitransitivityₗ ([∃]-proof([<]-limitᵣ-inv pz)) p ⦄ ⦄
proof {lim x} {𝐒 y} ⦃ limitᵣ(step p) ⦄ = intro ⦃ \{z} ⦃ pz ⦄ → Strict.Properties.Accessibleₗ.proof Ordinal-accessibleₗ ⦃ [<][≤]-semitransitivityₗ pz p ⦄ ⦄
proof {lim x} {lim y} ⦃ limitᵣ(limitₗ p) ⦄ = intro ⦃ \{z} ⦃ pz ⦄ → Strict.Properties.Accessibleₗ.proof Ordinal-accessibleₗ ⦃ [<][≤]-semitransitivityₗ ([∃]-proof([<]-limitᵣ-inv pz)) p ⦄ ⦄
module _ where
open import Functional
open import Function.Iteration
open import Numeral.Natural.Induction
private variable n : ℕ
_⋅ₙ_ : Ordinal(ℕ) → ℕ → Ordinal(ℕ)
_⋅ₙ_ x = ℕ-elim 𝟎 (const(lim ∘ (_+ₙ_)))
ω : Ordinal(ℕ)
ω = lim from-ℕ
ω² : Ordinal(ℕ)
ω² = lim(ω ⋅ₙ_)
ω-[<]-correctness : from-ℕ(n) < ω
ω-[<]-correctness {𝟎} = limitᵣ{i = 𝟎} minimal
ω-[<]-correctness {𝐒(n)} = limitᵣ{i = 𝐒(n)} (step [<]-of-step)
open import Relator.Equals renaming (_≡_ to _≡ₑ_)
open import Relator.Equals.Proofs
open import Type.Properties.Inhabited
open import Structure.Relator
private variable f : ℕ → Ordinal(ℕ)
instance
ℕ-inhabited : ◊ ℕ
ℕ-inhabited = intro ⦃ 𝟎 ⦄
strictly-increasing-sequence-when-zero : (∀{n} → (f(n) < f(𝐒(n)))) → (f(n) ≡ₑ 𝟎) → (n ≡ₑ 𝟎)
strictly-increasing-sequence-when-zero {f = f}{n = 𝟎} ord p = [≡]-intro
strictly-increasing-sequence-when-zero {f = f}{n = 𝐒 n} ord p with f(n) | ord{n}
... | 𝟎 | ord' with () ← [<]-irreflexivity (substitute₂ᵣ(_<_) p ord')
... | 𝐒 fn | ord' with () ← [<]-asymmetry minimal (substitute₂ᵣ(_<_) p ord')
... | lim x | ord' with () ← [<]-asymmetry [<]-lim-minimal (substitute₂ᵣ(_<_) p ord')
| {
"alphanum_fraction": 0.5130799329,
"avg_line_length": 46.832460733,
"ext": "agda",
"hexsha": "d695b8b4ab94a25ebb2812e6c5c80c2f267e46f3",
"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/Ordinal.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/Ordinal.agda",
"max_line_length": 430,
"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/Ordinal.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": 8206,
"size": 17890
} |
record ∃ {A : Set} (B : A → Set) : Set where
field
fst : A
snd : B fst
data ⊥ : Set where
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
infixr 1 _⊎_
data _⊎_ (A B : Set) : Set where
inj₁ : A → A ⊎ B
inj₂ : B → A ⊎ B
⊎-map : ∀ {A₁ A₂ B₁ B₂ : Set} →
(A₁ → A₂) → (B₁ → B₂) → A₁ ⊎ B₁ → A₂ ⊎ B₂
⊎-map f g (inj₁ x) = inj₁ (f x)
⊎-map f g (inj₂ y) = inj₂ (g y)
record Raw-monad (M : Set → Set) : Set₁ where
constructor mk
infixl 5 _>>=_
field
return : ∀ {A} → A → M A
_>>=_ : ∀ {A B} → M A → (A → M B) → M B
map : ∀ {A B} → (A → B) → M A → M B
map f x = x >>= λ x → return (f x)
open Raw-monad ⦃ … ⦄
-- Id is included in order to make run overloaded.
record Id (A : Set) : Set where
field
run : A
open Id
infix 3 ¬¬_
record ¬¬_ (A : Set) : Set where
field
run : ¬ ¬ A
open ¬¬_
instance
double-negation-monad : Raw-monad ¬¬_
run (Raw-monad.return double-negation-monad x) = λ f → f x
run (Raw-monad._>>=_ double-negation-monad x f) =
λ ¬b → run x (λ a → run (f a) ¬b)
excluded-middle : {A : Set} → ¬¬ (A ⊎ ¬ A)
run excluded-middle ¬[a⊎¬a] = ¬[a⊎¬a] (inj₂ λ a → ¬[a⊎¬a] (inj₁ a))
postulate
A : Set
P : Set → Set
_⇓_ : P A → A → Set
_⇑ : P A → Set
¬⇓→⇑ : {x : P A} → ¬ (∃ λ y → x ⇓ y) → x ⇑
¬¬[⇓⊎⇑] : (x : P A) → ¬ ¬ ((∃ λ y → x ⇓ y) ⊎ x ⇑)
¬¬[⇓⊎⇑] x = run (map (⊎-map (λ x → x) ¬⇓→⇑) excluded-middle)
| {
"alphanum_fraction": 0.4723220705,
"avg_line_length": 19.0547945205,
"ext": "agda",
"hexsha": "507634655e1824a8990cc242fe9c7caf11f12c84",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue3518.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue3518.agda",
"max_line_length": 67,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3518.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": 687,
"size": 1391
} |
{-# OPTIONS --cubical --no-import-sorts #-}
module Summary where
import Cubical.Data.Nat using (ℕ)
open import Cubical.Foundations.Prelude using (Lift; refl)
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Unit.Base using (Unit)
open import Cubical.Data.Sigma.Base
infix 1 _≅_
_≅_ = Iso
open import Number.Postulates
open import Number.Base
open import Number.Prettyprint
open ℕⁿ
open ℤᶻ
open ℚᶠ
open ℝʳ
open ℂᶜ
number-≅-Σ : ∀{p} → Number p ≅ NumberInterpretation p
number-≅-Σ = λ where
.Iso.fun → pop
.Iso.inv (x , p) → x ,, p
.Iso.leftInv (x ,, p) → refl
.Iso.rightInv (x , p) → refl
iso00 : [ℕ] ≅ Σ[ x ∈ Cubical.Data.Nat.ℕ ] Unit
iso01 : [ℕ⁺⁻] ≅ Σ[ x ∈ Cubical.Data.Nat.ℕ ] x #ⁿ 0ⁿ
iso02 : [ℕ₀⁺] ≅ Σ[ x ∈ Cubical.Data.Nat.ℕ ] 0ⁿ ≤ⁿ x
iso03 : [ℕ⁺] ≅ Σ[ x ∈ Cubical.Data.Nat.ℕ ] 0ⁿ <ⁿ x
iso04 : [ℕ₀⁻] ≅ Σ[ x ∈ Cubical.Data.Nat.ℕ ] x ≤ⁿ 0ⁿ
iso05 : [ℤ] ≅ Σ[ x ∈ ℤ.Carrier ] Lift {j = ℤℓ'} Unit
iso06 : [ℤ⁺⁻] ≅ Σ[ x ∈ ℤ.Carrier ] x #ᶻ 0ᶻ
iso07 : [ℤ₀⁺] ≅ Σ[ x ∈ ℤ.Carrier ] 0ᶻ ≤ᶻ x
iso08 : [ℤ⁺] ≅ Σ[ x ∈ ℤ.Carrier ] 0ᶻ <ᶻ x
iso09 : [ℤ⁻] ≅ Σ[ x ∈ ℤ.Carrier ] x <ᶻ 0ᶻ
iso10 : [ℤ₀⁻] ≅ Σ[ x ∈ ℤ.Carrier ] x ≤ᶻ 0ᶻ
iso11 : [ℚ] ≅ Σ[ x ∈ ℚ.Carrier ] Lift {j = ℚℓ'} Unit
iso12 : [ℚ⁺⁻] ≅ Σ[ x ∈ ℚ.Carrier ] x #ᶠ 0ᶠ
iso13 : [ℚ₀⁺] ≅ Σ[ x ∈ ℚ.Carrier ] 0ᶠ ≤ᶠ x
iso14 : [ℚ⁺] ≅ Σ[ x ∈ ℚ.Carrier ] 0ᶠ <ᶠ x
iso15 : [ℚ⁻] ≅ Σ[ x ∈ ℚ.Carrier ] x <ᶠ 0ᶠ
iso16 : [ℚ₀⁻] ≅ Σ[ x ∈ ℚ.Carrier ] x ≤ᶠ 0ᶠ
iso17 : [ℝ] ≅ Σ[ x ∈ ℝ.Carrier ] Lift {j = ℝℓ'} Unit
iso18 : [ℝ⁺⁻] ≅ Σ[ x ∈ ℝ.Carrier ] x #ʳ 0ʳ
iso19 : [ℝ₀⁺] ≅ Σ[ x ∈ ℝ.Carrier ] 0ʳ ≤ʳ x
iso20 : [ℝ⁺] ≅ Σ[ x ∈ ℝ.Carrier ] 0ʳ <ʳ x
iso21 : [ℝ⁻] ≅ Σ[ x ∈ ℝ.Carrier ] x <ʳ 0ʳ
iso22 : [ℝ₀⁻] ≅ Σ[ x ∈ ℝ.Carrier ] x ≤ʳ 0ʳ
iso23 : [ℂ] ≅ Σ[ x ∈ ℂ.Carrier ] Lift {j = ℂℓ'} Unit
iso24 : [ℂ⁺⁻] ≅ Σ[ x ∈ ℂ.Carrier ] x #ᶜ 0ᶜ
iso00 = number-≅-Σ
iso01 = number-≅-Σ
iso02 = number-≅-Σ
iso03 = number-≅-Σ
iso04 = number-≅-Σ
iso05 = number-≅-Σ
iso06 = number-≅-Σ
iso07 = number-≅-Σ
iso08 = number-≅-Σ
iso09 = number-≅-Σ
iso10 = number-≅-Σ
iso11 = number-≅-Σ
iso12 = number-≅-Σ
iso13 = number-≅-Σ
iso14 = number-≅-Σ
iso15 = number-≅-Σ
iso16 = number-≅-Σ
iso17 = number-≅-Σ
iso18 = number-≅-Σ
iso19 = number-≅-Σ
iso20 = number-≅-Σ
iso21 = number-≅-Σ
iso22 = number-≅-Σ
iso23 = number-≅-Σ
iso24 = number-≅-Σ
| {
"alphanum_fraction": 0.5304804199,
"avg_line_length": 30.2073170732,
"ext": "agda",
"hexsha": "9c5a879511ec12da902b0f39f138ff659189f312",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/Summary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/Summary.agda",
"max_line_length": 63,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/Summary.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 1337,
"size": 2477
} |
open import Agda.Builtin.Equality
postulate
A : Set
F G H I J : (A : Set₁) → (A → A → Set) → Set
K : ⦃ Set → Set → Set ⦄ → { Set → Set → Set } → Set
syntax F A (λ x y → B) = y ⟨ A ∼ B ⟩₁ x
syntax G A (λ _ y → B) = y ⟨ A ∼ B ⟩₂
syntax H A (λ x _ → B) = ⟨ B ∼ A ⟩₃ x
syntax I A (λ _ _ → B) = ⟨ B ∼ A ⟩₄
syntax J A (λ x y → B) = x y ∶ A ↝ B
syntax K ⦃ λ A B → C ⦄ { λ D E → F } = A B C - D E F
_ : (P ⟨ (Set → Set) ∼ P (Q A) ⟩₁ Q) ≡ F (Set → Set) (λ F G → G (F A))
_ = refl
_ : (P ⟨ (Set → Set) ∼ P A ⟩₂) ≡ G (Set → Set) (λ _ G → G A)
_ = refl
_ : (⟨ Q A ∼ (Set → Set) ⟩₃ Q) ≡ H (Set → Set) (λ F _ → F A)
_ = refl
_ : (⟨ A ∼ (Set → Set) ⟩₄) ≡ I (Set → Set) (λ _ _ → A)
_ = refl
_ : (P Q ∶ (Set → Set) ↝ P (Q A)) ≡ J (Set → Set) (λ F G → F (G A))
_ = refl
_ : (x x x - x x x) ≡ K ⦃ λ _ x → x ⦄ { λ _ y → y }
_ = refl
| {
"alphanum_fraction": 0.3773173391,
"avg_line_length": 28.65625,
"ext": "agda",
"hexsha": "936ddee2af837064f6037b5285e7a156d608ec47",
"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/Issue394.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/Issue394.agda",
"max_line_length": 70,
"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/Issue394.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": 446,
"size": 917
} |
module Generic.Lib.Data.Sets where
open import Generic.Lib.Intro
open import Generic.Lib.Data.Nat
open import Generic.Lib.Data.Product
open import Generic.Lib.Data.Pow
infixl 6 _⊔ⁿ_
_⊔ⁿ_ : ∀ {n} -> Level ^ n -> Level -> Level
_⊔ⁿ_ = flip $ foldPow _ _⊔_
Sets : ∀ {n} -> (αs : Level ^ n) -> Set (mapPow lsuc αs ⊔ⁿ lzero)
Sets {0} _ = ⊤
Sets {suc _} (α , αs) = Set α × Sets αs
FoldSets : ∀ {n β αs} -> Sets {n} αs -> Set β -> Set (αs ⊔ⁿ β)
FoldSets {0} tt B = B
FoldSets {suc _} (A , As) B = A -> FoldSets As B
HList : ∀ {n} {αs} -> Sets {n} αs -> Set (αs ⊔ⁿ lzero)
HList {0} tt = ⊤
HList {suc _} (A , As) = A × HList As
applyFoldSets : ∀ {n β αs} {As : Sets {n} αs} {B : Set β} -> FoldSets As B -> HList As -> B
applyFoldSets {0} y tt = y
applyFoldSets {suc n} f (x , xs) = applyFoldSets (f x) xs
| {
"alphanum_fraction": 0.5663507109,
"avg_line_length": 30.1428571429,
"ext": "agda",
"hexsha": "ccb26d7ec23c11b3705f3e10b829bdb95c50a159",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2021-01-27T12:57:09.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-07-17T07:23:39.000Z",
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Data/Sets.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": "2022-01-04T15:43:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-04-06T18:58:09.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Data/Sets.agda",
"max_line_length": 91,
"max_stars_count": 30,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Data/Sets.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T10:19:38.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-19T21:10:54.000Z",
"num_tokens": 352,
"size": 844
} |
module Prelude.List.Relations.Properties where
open import Agda.Primitive
open import Prelude.Equality
open import Prelude.Nat
open import Prelude.Empty
open import Prelude.Unit
open import Prelude.Product
open import Prelude.Number
open import Prelude.Decidable
open import Prelude.List.Base
open import Prelude.List.Relations.All
open import Prelude.List.Relations.Any
open import Prelude.Nat.Properties
open import Prelude.Variables
open import Prelude.Applicative
-- All --
module _ {a b} {A : Set a} {P Q : A → Set b} (f : ∀ {x} → P x → Q x) where
mapAll : ∀ {xs} → All P xs → All Q xs
mapAll [] = []
mapAll (x ∷ xs) = f x ∷ mapAll xs
traverseAll : ∀ {a b} {A : Set a} {B : A → Set a} {F : Set a → Set b}
{{AppF : Applicative F}} →
(∀ x → F (B x)) → (xs : List A) → F (All B xs)
traverseAll f [] = pure []
traverseAll f (x ∷ xs) = ⦇ f x ∷ traverseAll f xs ⦈
module _ {a b} {A : Set a} {P : A → Set b} where
-- Append
infixr 5 _++All_
_++All_ : ∀ {xs ys} → All P xs → All P ys → All P (xs ++ ys)
[] ++All qs = qs
(p ∷ ps) ++All qs = p ∷ ps ++All qs
-- Any --
module _ {a b} {A : Set a} {P Q : A → Set b} (f : ∀ {x} → P x → Q x) where
mapAny : ∀ {xs} → Any P xs → Any Q xs
mapAny (zero x) = zero (f x)
mapAny (suc i) = suc (mapAny i)
-- Literal overloading for Any
module _ {a b} {A : Set a} {P : A → Set b} where
private
AnyConstraint : List A → Nat → Set (a ⊔ b)
AnyConstraint [] _ = ⊥′
AnyConstraint (x ∷ _) zero = ⊤′ {a} × P x -- hack to line up levels
AnyConstraint (_ ∷ xs) (suc i) = AnyConstraint xs i
natToIx : ∀ (xs : List A) n → {{_ : AnyConstraint xs n}} → Any P xs
natToIx [] n {{}}
natToIx (x ∷ xs) zero {{_ , px}} = zero px
natToIx (x ∷ xs) (suc n) = suc (natToIx xs n)
instance
NumberAny : ∀ {xs} → Number (Any P xs)
Number.Constraint (NumberAny {xs}) = AnyConstraint xs
fromNat {{NumberAny {xs}}} = natToIx xs
lookupAny : ∀ {a b} {A : Set a} {P Q : A → Set b} {xs} → All P xs → Any Q xs → Σ A (λ x → P x × Q x)
lookupAny (p ∷ ps) (zero q) = _ , p , q
lookupAny (p ∷ ps) (suc i) = lookupAny ps i
lookup∈ : ∀ {a b} {A : Set a} {P : A → Set b} {xs x} → All P xs → x ∈ xs → P x
lookup∈ (p ∷ ps) (zero refl) = p
lookup∈ (p ∷ ps) (suc i) = lookup∈ ps i
module _ {a b} {A : Set a} {P : A → Set b} {{EqP : ∀ {x} → Eq (P x)}} where
private
z' : ∀ {x xs} → P x → Any P (x ∷ xs)
z' = zero
zero-inj : ∀ {x} {xs : List A} {p q : P x} → Any.zero {xs = xs} p ≡ z' q → p ≡ q
zero-inj refl = refl
sucAny-inj : ∀ {x xs} {i j : Any P xs} → Any.suc {x = x} i ≡ Any.suc {x = x} j → i ≡ j
sucAny-inj refl = refl
cons-inj₁ : ∀ {x xs} {p q : P x} {ps qs : All P xs} → p All.∷ ps ≡ q ∷ qs → p ≡ q
cons-inj₁ refl = refl
cons-inj₂ : ∀ {x xs} {p q : P x} {ps qs : All P xs} → p All.∷ ps ≡ q ∷ qs → ps ≡ qs
cons-inj₂ refl = refl
instance
EqAny : ∀ {xs} → Eq (Any P xs)
_==_ {{EqAny}} (zero p) (zero q) = decEq₁ zero-inj (p == q)
_==_ {{EqAny}} (suc i) (suc j) = decEq₁ sucAny-inj (i == j)
_==_ {{EqAny}} (zero _) (suc _) = no λ ()
_==_ {{EqAny}} (suc _) (zero _) = no λ ()
EqAll : ∀ {xs} → Eq (All P xs)
_==_ {{EqAll}} [] [] = yes refl
_==_ {{EqAll}} (x ∷ xs) (y ∷ ys) = decEq₂ cons-inj₁ cons-inj₂ (x == y) (xs == ys)
| {
"alphanum_fraction": 0.5288004751,
"avg_line_length": 31.7735849057,
"ext": "agda",
"hexsha": "2b0302b8ddc68588af35d815563ae35a7ab021aa",
"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": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Prelude/List/Relations/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"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": "t-more/agda-prelude",
"max_issues_repo_path": "src/Prelude/List/Relations/Properties.agda",
"max_line_length": 100,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "t-more/agda-prelude",
"max_stars_repo_path": "src/Prelude/List/Relations/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1325,
"size": 3368
} |
{-# OPTIONS --without-K --safe #-}
module Algebra.Linear.Structures where
open import Algebra.Structures.Field public
open import Algebra.Linear.Structures.VectorSpace public
| {
"alphanum_fraction": 0.7966101695,
"avg_line_length": 25.2857142857,
"ext": "agda",
"hexsha": "3a46132dce688003be4dbe15616a250a961ff3f3",
"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": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "felko/linear-algebra",
"max_forks_repo_path": "src/Algebra/Linear/Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"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": "felko/linear-algebra",
"max_issues_repo_path": "src/Algebra/Linear/Structures.agda",
"max_line_length": 56,
"max_stars_count": 15,
"max_stars_repo_head_hexsha": "d87c5a1eb5dd0569238272e67bce1899616b789a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "felko/linear-algebra",
"max_stars_repo_path": "src/Algebra/Linear/Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-30T06:18:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-02T14:11:00.000Z",
"num_tokens": 33,
"size": 177
} |
module _ (A : Set) where
{-# POLARITY A #-}
| {
"alphanum_fraction": 0.5555555556,
"avg_line_length": 11.25,
"ext": "agda",
"hexsha": "321085af058c11b175b010822dd224b391045e72",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pthariensflame/agda",
"max_forks_repo_path": "test/Fail/Polarity-pragma-for-module-parameter.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pthariensflame/agda",
"max_issues_repo_path": "test/Fail/Polarity-pragma-for-module-parameter.agda",
"max_line_length": 24,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "222c4c64b2ccf8e0fc2498492731c15e8fef32d4",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pthariensflame/agda",
"max_stars_repo_path": "test/Fail/Polarity-pragma-for-module-parameter.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": 15,
"size": 45
} |
module Lvl.MultiFunctions where
open import Data
open import Data.Tuple
open import Data.Tuple.Raise
import Data.Tuple.Raiseᵣ.Functions as Raise
open import Lvl
-- The maximum level of a tuple list of levels.
⨆ : ∀{n} → (Level ^ n) → Level
⨆ = Raise.foldᵣ(_⊔_) 𝟎
| {
"alphanum_fraction": 0.7222222222,
"avg_line_length": 22.5,
"ext": "agda",
"hexsha": "2cb94b936daf0a7dd0211fb18fa0027725bb7fb6",
"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": "Lvl/MultiFunctions.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": "Lvl/MultiFunctions.agda",
"max_line_length": 48,
"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": "Lvl/MultiFunctions.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": 90,
"size": 270
} |
open import FRP.JS.Nat using ( ℕ ; suc ; _+_ )
open import FRP.JS.DOM
open import FRP.JS.RSet
open import FRP.JS.Time using ( Time ; epoch )
open import FRP.JS.Delay using ( _ms )
open import FRP.JS.Behaviour
open import FRP.JS.Bool using ( Bool ; not ; true )
open import FRP.JS.QUnit using ( TestSuite ; ok◇ ; test ; _,_ ; ε )
module FRP.JS.Test.DOM where
withDOW : {A : Set} → ((w : DOW) → A) → A
withDOW f = f unattached
tests : TestSuite
tests =
( test "≟*"
( ok◇ "[] ≟* []"
(withDOW λ w → [] {w} ≟* [])
, ok◇ "[] ++ [] ≟* []"
(withDOW λ w → [] {left w} ++ [] ≟* []) )
, test "attr"
( ok◇ "attr class [ alpha ] ≟* attr class [ alpha ]"
(withDOW λ w → attr {w} "class" [ "alpha" ] ≟* attr "class" [ "alpha" ])
, ok◇ "attr foo [ alpha ] ≟* attr foo [ alpha ]"
(withDOW λ w → attr {w} "foo" [ "alpha" ] ≟* attr "foo" [ "alpha" ])
, ok◇ "attr foo [ alpha ] ++ attr bar [ alpha ] ≟* attr foo [ alpha ] ++ attr bar [ alpha ]"
(withDOW λ w → attr {left w} "foo" [ "alpha" ] ++ attr "bar" [ "alpha" ] ≟* attr "foo" [ "alpha" ] ++ attr "bar" [ "alpha" ])
, ok◇ "attr class [ beta ] ≟* attr class [ alpha ]"
(withDOW λ w → not* (attr {w} "class" [ "beta" ] ≟* attr "class" [ "alpha" ]))
, ok◇ "attr foo [ alpha ] ≟* attr class [ alpha ]"
(withDOW λ w → not* (attr {w} "foo" [ "alpha" ] ≟* attr "class" [ "alpha" ]))
, ok◇ "attr foo [ alpha ] ++ attr bar [ alpha ] ≟* attr foo [ alpha ]"
(withDOW λ w → not* (attr {left w} "foo" [ "alpha" ] ++ attr "bar" [ "alpha" ] ≟* attr "foo" [ "alpha" ])) )
, test "text"
( ok◇ "text [ abc ] ≟* text [ abc ]"
(withDOW λ w → text {w} [ "abc" ] ≟* text [ "abc" ])
, ok◇ "text [ a ] ≟* text [ abc ]"
(withDOW λ w → not* (text {w} [ "a" ] ≟* text [ "abc" ]))
, ok◇ "[] ≟* text [ abc ]"
(withDOW λ w → not* ([] ≟* text {w} [ "abc" ]))
, ok◇ "text [ abc ] ++ [] ≟* text [ abc ]"
(withDOW λ w → text {left w} [ "abc" ] ++ [] ≟* (text [ "abc" ]))
, ok◇ "[] ++ text [ abc ] ≟* text [ abc ]"
(withDOW λ w → [] ++ text {right w} [ "abc" ] ≟* (text [ "abc" ])) )
, test "element"
( ok◇ "element p (text [ abc ]) ≟* element p (text [ abc ])"
(withDOW λ w → element "p" {w} (text [ "abc" ]) ≟* element "p" (text [ "abc" ]))
, ok◇ "element p (text [ a ]) ≟* element p (text [ abc ])"
(withDOW λ w → not* (element "p" {w} (text [ "a" ]) ≟* element "p" (text [ "abc" ])))
, ok◇ "element div (attr class [ alpha ] ++ text [ abc ]) ≟* element div (attr class [ alpha ] ++ text [ abc ])"
(withDOW λ w → element "div" {w} (attr "class" [ "alpha" ] ++ text [ "abc" ]) ≟* element "div" {w} (attr "class" [ "alpha" ] ++ text [ "abc" ]))
, ok◇ "element div (attr class [ beta ] ++ text [ abc ]) ≟* element div (attr class [ alpha ] ++ text [ abc ])"
(withDOW λ w → not* (element "div" {w} (attr "class" [ "beta" ] ++ text [ "abc" ]) ≟* element "div" {w} (attr "class" [ "alpha" ] ++ text [ "abc" ])))
, ok◇ "element p (text [ abc ]) ≟* element p (text [ abc ])"
(withDOW λ w → element "p" {w} (text [ "abc" ]) ≟* element "p" (text [ "abc" ]))
, ok◇ "element p (text [ a ]) ++ element p (text [ b ]) ≟* element p (text [ a ])"
(withDOW λ w → not* (element "p" {left w} (text [ "a" ]) ++ element "p" (text [ "b" ]) ≟* element "p" (text [ "a" ])))
)
, test "join"
( ok◇ "text (join (map [ x ] [ abc ])) ≟* text [ abc ]"
(withDOW λ w → text {w} (join (map (λ s → [ s ]) [ "abc" ])) ≟* text [ "abc" ])
, ok◇ "join (map (text [ x ]) [ abc ]) ≟* text [ abc ]"
(withDOW λ w → join (map (λ s → text {w} [ s ]) [ "abc" ]) ≟* text [ "abc" ])
, ok◇ "element p (join (map (attr foo [ x ]) [ alpha ]) ++ join (map (attr bar [ x ]) [ alpha ])) ≟* element p (attr foo [ alpha ] ++ attr bar [ alpha ])"
(withDOW λ w → element "p" {w} (join (map (λ s → attr "foo" [ s ]) [ "alpha" ]) ++ join (map (λ s → attr "bar" [ s ]) [ "alpha" ])) ≟* element "p" (attr "foo" [ "alpha" ] ++ attr "bar" [ "alpha" ]))
, ok◇ "element p (join (map (attr foo [ x ]) [ beta ]) ++ join (map (attr bar [ x ]) [ alpha ])) ≟* element p (attr foo [ alpha ] ++ attr bar [ alpha ])"
(withDOW λ w → not* (element "p" {w} (join (map (λ s → attr "foo" [ s ]) [ "beta" ]) ++ join (map (λ s → attr "bar" [ s ]) [ "alpha" ])) ≟* element "p" (attr "foo" [ "alpha" ] ++ attr "bar" [ "alpha" ])))
, ok◇ "text (join (map [ x ] [ a ])) ≟* text [ abc ]"
(withDOW λ w → not* (text {w} (join (map (λ s → [ s ]) [ "a" ])) ≟* text [ "abc" ]))
, ok◇ "join (map (text [ x ]) [ a ]) ≟* text [ abc ]"
(withDOW λ w → not* (join (map (λ s → text {w} [ s ]) [ "a" ]) ≟* text [ "abc" ])) ) )
| {
"alphanum_fraction": 0.469787234,
"avg_line_length": 63.5135135135,
"ext": "agda",
"hexsha": "2722ee783524e1e1892a164d1d45e105e47115a6",
"lang": "Agda",
"max_forks_count": 7,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:39:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-11-07T21:50:58.000Z",
"max_forks_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_forks_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_forks_repo_name": "agda/agda-frp-js",
"max_forks_repo_path": "test/agda/FRP/JS/Test/DOM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_issues_repo_name": "agda/agda-frp-js",
"max_issues_repo_path": "test/agda/FRP/JS/Test/DOM.agda",
"max_line_length": 210,
"max_stars_count": 63,
"max_stars_repo_head_hexsha": "c7ccaca624cb1fa1c982d8a8310c313fb9a7fa72",
"max_stars_repo_licenses": [
"MIT",
"BSD-3-Clause"
],
"max_stars_repo_name": "agda/agda-frp-js",
"max_stars_repo_path": "test/agda/FRP/JS/Test/DOM.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T09:46:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-20T21:47:00.000Z",
"num_tokens": 1863,
"size": 4700
} |
-- Given two abelian groups A, B
-- the set of all group homomorphisms from A to B
-- is itself an abelian group.
-- In other words, Ab is cartesian closed.
-- This is needed to show Ab is an abelian category.
{-# OPTIONS --safe #-}
module Cubical.Algebra.AbGroup.Instances.Hom where
open import Cubical.Algebra.AbGroup.Base
open import Cubical.Algebra.Group.Morphisms
open import Cubical.Algebra.Group.MorphismProperties
open import Cubical.Algebra.Group.Properties
open import Cubical.Foundations.Prelude
private
variable
ℓ ℓ' : Level
module _ (A : AbGroup ℓ) (B : AbGroup ℓ') where
-- These names are useful for the proofs
private
open IsGroupHom
open AbGroupStr (A .snd) using () renaming (0g to 0A; _+_ to _⋆_; -_ to inv)
open AbGroupStr (B .snd) using (_+_; -_; +Comm; +Assoc; +IdR ; +InvR)
renaming (0g to 0B)
open GroupTheory (AbGroup→Group B) using (invDistr) renaming (inv1g to inv0B)
-- Some lemmas
idrB : (b : B .fst) → b + 0B ≡ b
idrB b = +IdR b
invrB : (b : B .fst) → b + (- b) ≡ 0B
invrB b = +InvR b
hom0AB : (f : AbGroupHom A B) → f .fst 0A ≡ 0B
hom0AB f = hom1g (AbGroupStr→GroupStr (A .snd)) (f .fst)
(AbGroupStr→GroupStr (B .snd)) (f .snd .pres·)
homInvAB : (f : AbGroupHom A B) → (a : A .fst) → f .fst (inv a) ≡ (- f .fst a)
homInvAB f a = homInv (AbGroupStr→GroupStr (A .snd)) (f .fst)
(AbGroupStr→GroupStr (B .snd)) (f .snd .pres·) a
-- Zero morphism
zero : AbGroupHom A B
zero .fst a = 0B
zero .snd .pres· a a' = sym (idrB _)
zero .snd .pres1 = refl
zero .snd .presinv a = sym (inv0B)
-- Pointwise addition of morphisms
module _ (f* g* : AbGroupHom A B) where
private
f = f* .fst
g = g* .fst
HomAdd : AbGroupHom A B
HomAdd .fst = λ a → f a + g a
HomAdd .snd .pres· a a' =
f (a ⋆ a') + g (a ⋆ a') ≡⟨ cong (_+ g(a ⋆ a')) (f* .snd .pres· _ _) ⟩
(f a + f a') + g (a ⋆ a') ≡⟨ cong ((f a + f a') +_) (g* .snd .pres· _ _) ⟩
(f a + f a') + (g a + g a') ≡⟨ sym (+Assoc _ _ _) ⟩
f a + (f a' + (g a + g a')) ≡⟨ cong (f a +_) (+Assoc _ _ _) ⟩
f a + ((f a' + g a) + g a') ≡⟨ cong (λ b → (f a + b + g a')) (+Comm _ _) ⟩
f a + ((g a + f a') + g a') ≡⟨ cong (f a +_) (sym (+Assoc _ _ _)) ⟩
f a + (g a + (f a' + g a')) ≡⟨ +Assoc _ _ _ ⟩
(f a + g a) + (f a' + g a') ∎
HomAdd .snd .pres1 =
f 0A + g 0A ≡⟨ cong (_+ g 0A) (hom0AB f*) ⟩
0B + g 0A ≡⟨ cong (0B +_) (hom0AB g*) ⟩
0B + 0B ≡⟨ idrB _ ⟩
0B ∎
HomAdd .snd .presinv a =
f (inv a) + g (inv a) ≡⟨ cong (_+ g (inv a)) (homInvAB f* _) ⟩
(- f a) + g (inv a) ≡⟨ cong ((- f a) +_) (homInvAB g* _) ⟩
(- f a) + (- g a) ≡⟨ +Comm _ _ ⟩
(- g a) + (- f a) ≡⟨ sym (invDistr _ _) ⟩
- (f a + g a) ∎
-- Pointwise inverse of morphism
module _ (f* : AbGroupHom A B) where
private
f = f* .fst
HomInv : AbGroupHom A B
HomInv .fst = λ a → - f a
HomInv .snd .pres· a a' =
- f (a ⋆ a') ≡⟨ cong -_ (f* .snd .pres· _ _) ⟩
- (f a + f a') ≡⟨ invDistr _ _ ⟩
(- f a') + (- f a) ≡⟨ +Comm _ _ ⟩
(- f a) + (- f a') ∎
HomInv .snd .pres1 =
- (f 0A) ≡⟨ cong -_ (f* .snd .pres1) ⟩
- 0B ≡⟨ inv0B ⟩
0B ∎
HomInv .snd .presinv a =
- f (inv a) ≡⟨ cong -_ (homInvAB f* _) ⟩
- (- f a) ∎
-- Group laws for morphisms
private
0ₕ = zero
_+ₕ_ = HomAdd
-ₕ_ = HomInv
-- Morphism addition is associative
HomAdd-assoc : (f g h : AbGroupHom A B) → (f +ₕ (g +ₕ h)) ≡ ((f +ₕ g) +ₕ h)
HomAdd-assoc f g h = GroupHom≡ (funExt λ a → +Assoc _ _ _)
-- Morphism addition is commutative
HomAdd-comm : (f g : AbGroupHom A B) → (f +ₕ g) ≡ (g +ₕ f)
HomAdd-comm f g = GroupHom≡ (funExt λ a → +Comm _ _)
-- zero is right identity
HomAdd-zero : (f : AbGroupHom A B) → (f +ₕ zero) ≡ f
HomAdd-zero f = GroupHom≡ (funExt λ a → idrB _)
-- -ₕ is right inverse
HomInv-invr : (f : AbGroupHom A B) → (f +ₕ (-ₕ f)) ≡ zero
HomInv-invr f = GroupHom≡ (funExt λ a → invrB _)
-- Abelian group structure on AbGroupHom A B
open AbGroupStr
HomAbGroupStr : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroupStr (AbGroupHom A B)
HomAbGroupStr A B .0g = zero A B
HomAbGroupStr A B ._+_ = HomAdd A B
HomAbGroupStr A B .-_ = HomInv A B
HomAbGroupStr A B .isAbGroup = makeIsAbGroup isSetGroupHom
(HomAdd-assoc A B) (HomAdd-zero A B) (HomInv-invr A B) (HomAdd-comm A B)
HomAbGroup : (A : AbGroup ℓ) → (B : AbGroup ℓ') → AbGroup (ℓ-max ℓ ℓ')
HomAbGroup A B = AbGroupHom A B , HomAbGroupStr A B
| {
"alphanum_fraction": 0.5084050841,
"avg_line_length": 33.4109589041,
"ext": "agda",
"hexsha": "3784129bb6eda5bde67c6cbb3fdf7ddf71af0133",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/AbGroup/Instances/Hom.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/AbGroup/Instances/Hom.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/AbGroup/Instances/Hom.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1944,
"size": 4878
} |
module _ where
open import Agda.Builtin.Nat
open import Agda.Builtin.Bool
open import Agda.Builtin.Equality
data Nat+Bool : Set where
nat : Nat → Nat+Bool
bool : Bool → Nat+Bool
data P : Nat+Bool → Set where
p : {x : Nat+Bool} → P x
mkBool : ∀ {n b} → P (nat n) → P (bool b)
mkBool {zero} _ = p {bool _}
mkBool {suc _} _ = p {bool _}
f : {x : Nat+Bool} → P x
f = λ { {nat n} → g
; {bool b} → mkBool g }
where
g : P _
g = p
crash : f {bool true} ≡ p {bool true}
crash = refl
| {
"alphanum_fraction": 0.5779092702,
"avg_line_length": 18.1071428571,
"ext": "agda",
"hexsha": "8298ffa495698981e16c54d56ead337327ba2299",
"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/Issue2001.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/Issue2001.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2001.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": 199,
"size": 507
} |
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.EqRelInstance where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Weakening
open import Definition.Typed.Reduction
open import Definition.Typed.EqualityRelation
open import Tools.Function
-- Judgmental instance of the equality relation
instance eqRelInstance : EqRelSet
eqRelInstance = eqRel _⊢_≡_ _⊢_≡_∷_ _⊢_≡_∷_
idᶠ idᶠ idᶠ univ
sym sym sym trans trans trans
conv conv wkEq wkEqTerm wkEqTerm
reduction reductionₜ
(refl ∘ᶠ Uⱼ) (refl ∘ᶠ ℕⱼ) (refl ∘ᶠ ℕⱼ)
Π-cong Π-cong (refl ∘ᶠ zeroⱼ) suc-cong
(λ x x₁ x₂ x₃ x₄ x₅ → η-eq x x₁ x₂ x₅)
refl app-cong natrec-cong
| {
"alphanum_fraction": 0.6104513064,
"avg_line_length": 32.3846153846,
"ext": "agda",
"hexsha": "74b72db845b79e97139cb2412d5b2b2ad854c5a6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Typed/EqRelInstance.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Typed/EqRelInstance.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Typed/EqRelInstance.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 259,
"size": 842
} |
module NamedWhere where
data _==_ {A : Set}(x : A) : A -> Set where
refl : x == x
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
_++_ : {A : Set} -> List A -> List A -> List A
[] ++ ys = ys
(x :: xs) ++ ys = x :: (xs ++ ys)
reverse : {A : Set} -> List A -> List A
reverse {A} xs = rev xs []
module reverse where
rev : List A -> List A -> List A
rev [] ys = ys
rev (x :: xs) ys = rev xs (x :: ys)
rev : {A : Set} -> List A -> List A -> List A
rev = reverse.rev []
| {
"alphanum_fraction": 0.4718045113,
"avg_line_length": 21.28,
"ext": "agda",
"hexsha": "c35ea618acbbc6463f2beec09da284dea4a04e57",
"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/NamedWhere.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/NamedWhere.agda",
"max_line_length": 46,
"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/NamedWhere.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": 188,
"size": 532
} |
module Metalogic.Classical.Propositional.TruthSemanticsModel {ℓ} (Proposition : Set(ℓ)) where
import Lvl
open import Data.Boolean
open import Data
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Metalogic.Classical.Propositional.Syntax{ℓ} (Proposition)
renaming (
⊤ to ⊤ₗ ;
⊥ to ⊥ₗ ;
¬_ to ¬ₗ_ ;
_∧_ to _∧ₗ_ ;
_∨_ to _∨ₗ_ ;
_⇒_ to _⇒ₗ_ )
open import Relator.Equals
open import Relator.Equals.Proofs
open import Sets.BoolSet
-- A model decides whether a proposition is true or false
-- Also known as Interpretation, Structure, Model
record Model : Set(ℓ) where
field
interpretProp : Proposition → Bool
-- TODO: Can this be called a "theory" of propositional logic? So that instances of the type Semantics is the "models" of logic?
-- TODO: Now, all the metalogic depends on booleans, which may not be satisfactory
module _ where
import Data.Boolean.Operators
open Data.Boolean.Operators.Logic
satisfaction : Model → Formula → Bool
satisfaction(𝔐)(• prop) = Model.interpretProp(𝔐) (prop)
satisfaction(𝔐)(⊤ₗ) = 𝑇
satisfaction(𝔐)(⊥ₗ) = 𝐹
satisfaction(𝔐)(¬ₗ φ) = ¬(satisfaction(𝔐)(φ))
satisfaction(𝔐)(φ₁ ∧ₗ φ₂) = (satisfaction(𝔐)(φ₁)) ∧ (satisfaction(𝔐)(φ₂))
satisfaction(𝔐)(φ₁ ∨ₗ φ₂) = (satisfaction(𝔐)(φ₁)) ∨ (satisfaction(𝔐)(φ₂))
satisfaction(𝔐)(φ₁ ⇒ₗ φ₂) = ¬(satisfaction(𝔐)(φ₁)) ∨ (satisfaction(𝔐)(φ₂))
-- Syntactic details with the relation symbol
record SatisfactionRelation {ℓ₁}{ℓ₂} (Obj : Set(ℓ) → Set(ℓ₁)) : Set(Lvl.𝐒(ℓ Lvl.⊔ ℓ₁ Lvl.⊔ ℓ₂)) where
field
_⊧_ : Model → Obj(Formula) → Set(ℓ₂)
open SatisfactionRelation ⦃ ... ⦄ public
instance
-- Satisfaction for a single formula
formula-satisfaction-relation : SatisfactionRelation(id)
formula-satisfaction-relation = record{_⊧_ = \𝔐 φ → satisfaction(𝔐)(φ) ≡ 𝑇}
instance
-- Satisfaction for a list of formulas
list-satisfaction-relation : SatisfactionRelation(BoolSet{ℓ})
list-satisfaction-relation = record{_⊧_ = \𝔐 Γ → (∀{γ} → (γ ∈ Γ) → satisfaction(𝔐)(γ) ≡ 𝑇)}
-- Entailment
data _⊨_ (Γ : BoolSet{ℓ}(Formula)) (φ : Formula) : Set(ℓ) where
[⊨]-intro : (∀{𝔐} → (𝔐 ⊧ Γ) → (𝔐 ⊧ φ)) → (Γ ⊨ φ)
_⊭_ : BoolSet{ℓ}(Formula) → Formula → Set(ℓ)
_⊭_ Γ φ = (_⊨_ Γ φ) → Empty{ℓ}
-- Validity
valid : Formula → Set(ℓ)
valid = (∅ ⊨_)
module Theorems where
[⊤]-entailment : (∅ ⊨ ⊤ₗ)
[⊤]-entailment = [⊨]-intro(const [≡]-intro)
-- ∅ ⊨ ⊤ₗ
-- ∀{𝔐} → (𝔐 ⊧ ∅) → (𝔐 ⊧ ⊤ₗ)
-- ∀{𝔐} → (𝔐 ⊧ ∅) → (satisfaction(𝔐)(⊤ₗ) ≡ 𝑇)
-- ∀{𝔐} → (∀{γ} → (γ ∈ ∅) → satisfaction(𝔐)(γ) ≡ 𝑇) → (satisfaction(𝔐)(⊤ₗ) ≡ 𝑇)
-- [∧]-entailment : ∀{φ₁ φ₂} → ([ φ₁ ⊰ φ₂ ] ⊨ (φ₁ ∧ₗ φ₂))
-- [∧]-entailment{φ₁}{φ₂} = [⊨]-intro ([∈]-proof ↦ congruence₁-op(_∧_) ([∈]-proof (use)) ([∈]-proof (skip use)))
-- [ φ₁ ⊰ φ₂ ] ⊨ (φ₁ ∧ φ₂)
-- ∀{𝔐} → (𝔐 ⊧ [ φ₁ ⊰ φ₂ ]) → (𝔐 ⊧ (φ₁ ∧ φ₂))
-- ∀{𝔐} → (𝔐 ⊧ [ φ₁ ⊰ φ₂ ]) → (satisfaction(𝔐)(φ₁ ∧ₗ φ₂) ≡ 𝑇)
-- ∀{𝔐} → (𝔐 ⊧ [ φ₁ ⊰ φ₂ ]) → (satisfaction(𝔐)(φ₁) ∧ satisfaction(𝔐)(φ₂) ≡ 𝑇)
-- ∀{𝔐} → (∀{γ} → (γ ∈ [ φ₁ ⊰ φ₂ ]) → satisfaction(𝔐)(γ) ≡ 𝑇) → (satisfaction(𝔐)(φ₁) ∧ satisfaction(𝔐)(φ₂) ≡ 𝑇)
| {
"alphanum_fraction": 0.5950047423,
"avg_line_length": 38.1084337349,
"ext": "agda",
"hexsha": "10309dc1d6ce8c224a45e22f9ef04076d939fc21",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "old/Metalogic/Metalogic/Classical/Propositional/TruthSemanticsModel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "old/Metalogic/Metalogic/Classical/Propositional/TruthSemanticsModel.agda",
"max_line_length": 128,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "old/Metalogic/Metalogic/Classical/Propositional/TruthSemanticsModel.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": 1394,
"size": 3163
} |
module Structure.Operator.Monoid.Homomorphism where
import Lvl
open import Logic
open import Logic.Predicate
open import Structure.Function
open import Structure.Function.Multi
open import Structure.Operator.Monoid
open import Structure.Setoid
open import Type
record Homomorphism
{ℓ₁ ℓ₂ ℓₑ₁ ℓₑ₂}
{X : Type{ℓ₁}} ⦃ _ : Equiv{ℓₑ₁}(X) ⦄ {_▫X_ : X → X → X} ( structureₗ : Monoid(_▫X_))
{Y : Type{ℓ₂}} ⦃ _ : Equiv{ℓₑ₂}(Y) ⦄ {_▫Y_ : Y → Y → Y} ( structureᵣ : Monoid(_▫Y_))
(f : X → Y)
: Stmt{ℓ₁ Lvl.⊔ ℓₑ₁ Lvl.⊔ ℓ₂ Lvl.⊔ ℓₑ₂} where
constructor intro
idₗ = Monoid.id(structureₗ)
idᵣ = Monoid.id(structureᵣ)
field
⦃ function ⦄ : Function(f)
⦃ preserve-op ⦄ : Preserving₂(f)(_▫X_)(_▫Y_)
⦃ preserve-id ⦄ : Preserving₀(f)(idₗ)(idᵣ)
_→ᵐᵒⁿᵒⁱᵈ_ : ∀{ℓₗ ℓₗₑ ℓᵣ ℓᵣₑ} → MonoidObject{ℓₗ}{ℓₗₑ} → MonoidObject{ℓᵣ}{ℓᵣₑ} → Type
A →ᵐᵒⁿᵒⁱᵈ B = ∃(Homomorphism(MonoidObject.monoid A)(MonoidObject.monoid B))
| {
"alphanum_fraction": 0.671009772,
"avg_line_length": 29.7096774194,
"ext": "agda",
"hexsha": "61a70270ba3c9a689eec895209f5654e7816b131",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Structure/Operator/Monoid/Homomorphism.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Structure/Operator/Monoid/Homomorphism.agda",
"max_line_length": 86,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Structure/Operator/Monoid/Homomorphism.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": 455,
"size": 921
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.types.Empty
open import lib.types.Nat
module lib.types.TLevel where
⟨_⟩₋₁ : ℕ → ℕ₋₂
⟨ n ⟩₋₁ = S ⟨ n ⟩₋₂
⟨_⟩ : ℕ → ℕ₋₂
⟨ n ⟩ = S (S ⟨ n ⟩₋₂)
infixl 80 _+2+_
_+2+_ : ℕ₋₂ → ℕ₋₂ → ℕ₋₂
⟨-2⟩ +2+ n = n
S m +2+ n = S (m +2+ n)
+2+-unit-r : (m : ℕ₋₂) → m +2+ ⟨-2⟩ == m
+2+-unit-r ⟨-2⟩ = idp
+2+-unit-r (S m) = ap S (+2+-unit-r m)
+2+-βr : (m n : ℕ₋₂) → m +2+ (S n) == S (m +2+ n)
+2+-βr ⟨-2⟩ n = idp
+2+-βr (S m) n = ap S (+2+-βr m n)
+2+-comm : (m n : ℕ₋₂) → m +2+ n == n +2+ m
+2+-comm m ⟨-2⟩ = +2+-unit-r m
+2+-comm m (S n) = +2+-βr m n ∙ ap S (+2+-comm m n)
+2+0 : (n : ℕ₋₂) → n +2+ 0 == S (S n)
+2+0 n = +2+-comm n 0
{- Inequalities -}
infix 40 _<T_
infix 40 _≤T_
data _<T_ : ℕ₋₂ → ℕ₋₂ → Type₀ where
ltS : {m : ℕ₋₂} → m <T (S m)
ltSR : {m n : ℕ₋₂} → m <T n → m <T (S n)
_≤T_ : ℕ₋₂ → ℕ₋₂ → Type₀
m ≤T n = Coprod (m == n) (m <T n)
-2<T : (m : ℕ₋₂) → ⟨-2⟩ <T S m
-2<T ⟨-2⟩ = ltS
-2<T (S m) = ltSR (-2<T m)
-2≤T : (m : ℕ₋₂) → ⟨-2⟩ ≤T m
-2≤T ⟨-2⟩ = inl idp
-2≤T (S m) = inr (-2<T m)
<T-trans : {m n k : ℕ₋₂} → m <T n → n <T k → m <T k
<T-trans lt₁ ltS = ltSR lt₁
<T-trans lt₁ (ltSR lt₂) = ltSR (<T-trans lt₁ lt₂)
≤T-refl : {m : ℕ₋₂} → m ≤T m
≤T-refl = inl idp
≤T-trans : {m n k : ℕ₋₂} → m ≤T n → n ≤T k → m ≤T k
≤T-trans {k = k} (inl p₁) lte₂ = transport (λ t → t ≤T k) (! p₁) lte₂
≤T-trans {m = m} lte₁ (inl p₂) = transport (λ t → m ≤T t) p₂ lte₁
≤T-trans (inr lt₁) (inr lt₂) = inr (<T-trans lt₁ lt₂)
<T-ap-S : {m n : ℕ₋₂} → m <T n → S m <T S n
<T-ap-S ltS = ltS
<T-ap-S (ltSR lt) = ltSR (<T-ap-S lt)
≤T-ap-S : {m n : ℕ₋₂} → m ≤T n → S m ≤T S n
≤T-ap-S (inl p) = inl (ap S p)
≤T-ap-S (inr lt) = inr (<T-ap-S lt)
<T-cancel-S : {m n : ℕ₋₂} → S m <T S n → m <T n
<T-cancel-S ltS = ltS
<T-cancel-S (ltSR lt) = <T-trans ltS lt
<T-+2+-l : {m n : ℕ₋₂} (k : ℕ₋₂) → m <T n → (k +2+ m) <T (k +2+ n)
<T-+2+-l ⟨-2⟩ lt = lt
<T-+2+-l (S k) lt = <T-ap-S (<T-+2+-l k lt)
≤T-+2+-l : {m n : ℕ₋₂} (k : ℕ₋₂) → m ≤T n → (k +2+ m) ≤T (k +2+ n)
≤T-+2+-l k (inl p) = inl (ap (λ t → k +2+ t) p)
≤T-+2+-l k (inr lt) = inr (<T-+2+-l k lt)
<T-+2+-r : {m n : ℕ₋₂} (k : ℕ₋₂) → m <T n → (m +2+ k) <T (n +2+ k)
<T-+2+-r k ltS = ltS
<T-+2+-r k (ltSR lt) = ltSR (<T-+2+-r k lt)
≤T-+2+-r : {m n : ℕ₋₂} (k : ℕ₋₂) → m ≤T n → (m +2+ k) ≤T (n +2+ k)
≤T-+2+-r k (inl p) = inl (ap (λ t → t +2+ k) p)
≤T-+2+-r k (inr lt) = inr (<T-+2+-r k lt)
private
T-get-S : ℕ₋₂ → ℕ₋₂
T-get-S ⟨-2⟩ = ⟨ 42 ⟩
T-get-S (S n) = n
T-S≠⟨-2⟩-type : ℕ₋₂ → Type₀
T-S≠⟨-2⟩-type ⟨-2⟩ = Empty
T-S≠⟨-2⟩-type (S n) = Unit
T-S≠⟨-2⟩ : (n : ℕ₋₂) → S n ≠ ⟨-2⟩
T-S≠⟨-2⟩ n p = transport T-S≠⟨-2⟩-type p unit
T-S≠ : (n : ℕ₋₂) → S n ≠ n
T-S≠ ⟨-2⟩ p = T-S≠⟨-2⟩ ⟨-2⟩ p
T-S≠ (S n) p = T-S≠ n (ap T-get-S p)
T-S+2+≠ : (n k : ℕ₋₂) → S (k +2+ n) ≠ n
T-S+2+≠ ⟨-2⟩ k p = T-S≠⟨-2⟩ (k +2+ ⟨-2⟩) p
T-S+2+≠ (S n) k p = T-S+2+≠ n k (ap T-get-S (ap S (! (+2+-βr k n)) ∙ p))
<T-witness : {m n : ℕ₋₂} → (m <T n) → Σ ℕ₋₂ (λ k → S k +2+ m == n)
<T-witness ltS = (⟨-2⟩ , idp)
<T-witness (ltSR lt) = let w' = <T-witness lt in (S (fst w') , ap S (snd w'))
≤T-witness : {m n : ℕ₋₂} → (m ≤T n) → Σ ℕ₋₂ (λ k → k +2+ m == n)
≤T-witness (inl p) = (⟨-2⟩ , p)
≤T-witness (inr lt) = let w' = <T-witness lt in (S (fst w') , snd w')
<T-to-≤T : {m n : ℕ₋₂} → m <T S n → m ≤T n
<T-to-≤T ltS = inl idp
<T-to-≤T (ltSR lt) = inr lt
<T-to-≠ : {m n : ℕ₋₂} → (m <T n) → m ≠ n
<T-to-≠ {m} {n} lt p = T-S+2+≠ m (fst w) (snd w ∙ ! p)
where w = <T-witness lt
=-to-≮T : {m n : ℕ₋₂} → (m == n) → ¬ (m <T n)
=-to-≮T p lt = <T-to-≠ lt p
<T-to-≯T : {m n : ℕ₋₂} → (m <T n) → ¬ (n <T m)
<T-to-≯T lt gt = =-to-≮T idp (<T-trans lt gt)
<T-to-≱T : {m n : ℕ₋₂} → (m <T n) → ¬ (n ≤T m)
<T-to-≱T lt (inl p) = <T-to-≠ lt (! p)
<T-to-≱T lt (inr gt) = <T-to-≯T lt gt
{-
-2-monotone-< : {m n : ℕ} → (m < n) → (m -2 <T n -2)
-2-monotone-< ltS = ltS
-2-monotone-< (ltSR lt) = ltSR (-2-monotone-< lt)
-2-monotone-≤ : {m n : ℕ} → (m ≤ n) → (m -2 ≤T n -2)
-2-monotone-≤ (inl p) = inl (ap _-2 p)
-2-monotone-≤ (inr lt) = inr (-2-monotone-< lt)
-}
⟨⟩-monotone-< : {m n : ℕ} → (m < n) → (⟨ m ⟩ <T ⟨ n ⟩)
⟨⟩-monotone-< ltS = ltS
⟨⟩-monotone-< (ltSR lt) = ltSR (⟨⟩-monotone-< lt)
⟨⟩-monotone-≤ : {m n : ℕ} → (m ≤ n) → (⟨ m ⟩ ≤T ⟨ n ⟩)
⟨⟩-monotone-≤ (inl p) = inl (ap ⟨_⟩ p)
⟨⟩-monotone-≤ (inr lt) = inr (⟨⟩-monotone-< lt)
minT : ℕ₋₂ → ℕ₋₂ → ℕ₋₂
minT ⟨-2⟩ n = ⟨-2⟩
minT (S m) ⟨-2⟩ = ⟨-2⟩
minT (S m) (S n) = S (minT m n)
minT≤l : (m n : ℕ₋₂) → minT m n ≤T m
minT≤l ⟨-2⟩ n = inl idp
minT≤l (S m) ⟨-2⟩ = -2≤T (S m)
minT≤l (S m) (S n) = ≤T-ap-S (minT≤l m n)
minT≤r : (m n : ℕ₋₂) → minT m n ≤T n
minT≤r ⟨-2⟩ n = -2≤T n
minT≤r (S m) ⟨-2⟩ = inl idp
minT≤r (S m) (S n) = ≤T-ap-S (minT≤r m n)
minT-out : (m n : ℕ₋₂) → Coprod (minT m n == m) (minT m n == n)
minT-out ⟨-2⟩ _ = inl idp
minT-out (S _) ⟨-2⟩ = inr idp
minT-out (S m) (S n) with minT-out m n
minT-out (S m) (S n) | inl p = inl (ap S p)
minT-out (S m) (S n) | inr q = inr (ap S q)
minT-out-l : {m n : ℕ₋₂} → (m ≤T n) → minT m n == m
minT-out-l {m} {n} lte with minT-out m n
minT-out-l lte | inl eqm = eqm
minT-out-l (inl p) | inr eqn = eqn ∙ ! p
minT-out-l {m} {n} (inr lt) | inr eq =
⊥-rec (<T-to-≱T (transport (λ k → m <T k) (! eq) lt) (minT≤l m n))
| {
"alphanum_fraction": 0.444380514,
"avg_line_length": 27.8823529412,
"ext": "agda",
"hexsha": "6299b969bbdf394099eff2bcfa09a4dcb386590a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/TLevel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/TLevel.agda",
"max_line_length": 77,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/TLevel.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3054,
"size": 5214
} |
------------------------------------------------------------------------
-- Propierties of abstract typing contexts
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module Data.Context.Properties where
open import Data.Fin using (Fin; zero; suc; lift; raise)
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Product using (_×_; _,_)
open import Data.Vec as Vec using (Vec; []; _∷_)
import Data.Vec.Properties as VecProps
open import Function as Fun using (_∘_; flip)
open import Relation.Binary.PropositionalEquality hiding (subst-∘)
open ≡-Reasoning
open import Relation.Unary using (Pred)
open import Data.Context
open import Data.Context.WellFormed
------------------------------------------------------------------------
-- Properties of abstract contexts and context extensions.
-- Properties of the `map' functions.
module _ {ℓ₁ ℓ₂} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} where
-- pointwise equality is a congruence w.r.t. map and mapExt.
map-cong : ∀ {n} {f g : ∀ {k} → T₁ k → T₂ k} → (∀ {k} → f {k} ≗ g {k}) →
_≗_ {A = Ctx T₁ n} (map f) (map g)
map-cong f≗g [] = refl
map-cong f≗g (_∷_ t Γ) = cong₂ _∷_ (f≗g t) (map-cong f≗g Γ)
mapExt-cong : ∀ {k m n} {f g : ∀ i → T₁ (i + m) → T₂ (i + n)} →
(∀ {i} → f i ≗ g i) →
_≗_ {A = CtxExt T₁ m k} (mapExt {T₂ = T₂} f) (mapExt g)
mapExt-cong f≗g [] = refl
mapExt-cong f≗g (_∷_ {l} t Γ) = cong₂ _∷_ (f≗g {l} t) (mapExt-cong f≗g Γ)
module _ {ℓ} {T : Pred ℕ ℓ} where
-- map and mapExt are functorial.
map-id : ∀ {n} → _≗_ {A = Ctx T n} (map Fun.id) Fun.id
map-id [] = refl
map-id (t ∷ Γ) = cong (t ∷_) (map-id Γ)
mapExt-id : ∀ {m n} → _≗_ {A = CtxExt T m n} (mapExt λ _ t → t) Fun.id
mapExt-id [] = refl
mapExt-id (t ∷ Γ) = cong (t ∷_) (mapExt-id Γ)
module _ {ℓ₁ ℓ₂ ℓ₃} {T₁ : Pred ℕ ℓ₁} {T₂ : Pred ℕ ℓ₂} {T₃ : Pred ℕ ℓ₃} where
map-∘ : ∀ {n} (f : ∀ {k} → T₂ k → T₃ k) (g : ∀ {k} → T₁ k → T₂ k)
(Γ : Ctx T₁ n) → map {T₂ = T₃} (f ∘ g) Γ ≡ map {T₁ = T₂} f (map g Γ)
map-∘ f g [] = refl
map-∘ f g (t ∷ Γ) = cong (_ ∷_) (map-∘ f g Γ)
mapExt-∘ : ∀ {k l m n}
(f : ∀ i → T₂ (i + m) → T₃ (i + n))
(g : ∀ i → T₁ (i + l) → T₂ (i + m)) →
(Γ : CtxExt T₁ l k) →
mapExt {T₂ = T₃} (λ i t → f i (g i t)) Γ ≡
mapExt {T₁ = T₂} f (mapExt g Γ)
mapExt-∘ f g [] = refl
mapExt-∘ f g (t ∷ Γ) = cong (_ ∷_) (mapExt-∘ f g Γ)
-- Lemmas about operations on contexts that require weakening of
-- types.
module WeakenOpsLemmas {ℓ} {T : Pred ℕ ℓ} (extension : Extension T) where
-- The underlyig operations.
open WeakenOps extension
-- Conversion to vector representation commutes with
-- concatenation.
toVec-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) →
toVec (Δ ++ Γ) ≡ extToVec Δ (toVec Γ)
toVec-++ [] Γ = refl
toVec-++ (t ∷ Δ) Γ =
cong ((_ ∷_) ∘ Vec.map weaken) (toVec-++ Δ Γ)
-- Lookup commutes with concatenation.
lookup-++ : ∀ {m n} (Δ : CtxExt T m n) (Γ : Ctx T m) x →
lookup (Δ ++ Γ) x ≡ extLookup Δ (toVec Γ) x
lookup-++ Δ Γ x = cong (flip Vec.lookup x) (toVec-++ Δ Γ)
-- We can skip the first element when looking up others.
lookup-suc : ∀ {n} t (Γ : Ctx T n) x →
lookup (t ∷ Γ) (suc x) ≡ weaken (lookup Γ x)
lookup-suc t Γ x = VecProps.lookup-map x weaken (toVec Γ)
extLookup-suc : ∀ {k m n} t (Γ : CtxExt T m n) (ts : Vec (T m) k) x →
extLookup (t ∷ Γ) ts (suc x) ≡ weaken (extLookup Γ ts x)
extLookup-suc t Γ ts x = VecProps.lookup-map x weaken (extToVec Γ ts)
-- We can skip a spliced-in element when looking up others.
lookup-lift : ∀ {k m n} (Γ : CtxExt T m n) t (ts : Vec (T m) k) x →
extLookup Γ ts x ≡ extLookup Γ (t ∷ ts) (lift n suc x)
lookup-lift [] t ts x = refl
lookup-lift (u ∷ Δ) t ts zero = refl
lookup-lift {n = suc n} (u ∷ Δ) t ts (suc x) = begin
extLookup (u ∷ Δ) ts (suc x)
≡⟨ extLookup-suc u Δ ts x ⟩
weaken (extLookup Δ ts x)
≡⟨ cong weaken (lookup-lift Δ t ts x) ⟩
weaken (extLookup Δ (t ∷ ts) (lift n suc x))
≡⟨ sym (extLookup-suc u Δ (t ∷ ts) (lift n suc x)) ⟩
extLookup (u ∷ Δ) (t ∷ ts) (suc (lift n suc x))
∎
-- Lookup in the prefix of a concatenation results in weakening.
lookup-weaken⋆ : ∀ {m} n (Δ : CtxExt T m n) (Γ : Ctx T m) x →
lookup (Δ ++ Γ) (raise n x) ≡ weaken⋆ n (lookup Γ x)
lookup-weaken⋆ zero [] Γ x = refl
lookup-weaken⋆ (suc n) (t ∷ Δ) Γ x = begin
lookup (t ∷ Δ ++ Γ) (suc (raise n x))
≡⟨ VecProps.lookup-map (raise n x) weaken (toVec (Δ ++ Γ)) ⟩
weaken (lookup (Δ ++ Γ) (raise n x))
≡⟨ cong weaken (lookup-weaken⋆ n Δ Γ x) ⟩
weaken (weaken⋆ n (lookup Γ x))
∎
-- Lemmas relating conversions of context extensions to vector
-- representation with conversions of the underling entries.
module ConversionLemmas {T₁ T₂ : ℕ → Set}
(extension₁ : Extension T₁)
(extension₂ : Extension T₂) where
private
module W₁ = WeakenOps extension₁
module W₂ = WeakenOps extension₂
toVec-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) →
(∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) →
W₂.toVec (map f Γ) ≡ Vec.map f (W₁.toVec Γ)
toVec-map f [] _ = refl
toVec-map f (_∷_ t Γ) hyp = cong₂ _∷_ (hyp t) (begin
Vec.map W₂.weaken (W₂.toVec (map f Γ))
≡⟨ cong (Vec.map W₂.weaken) (toVec-map f Γ hyp) ⟩
(Vec.map W₂.weaken (Vec.map f (W₁.toVec Γ)))
≡⟨ sym (VecProps.map-∘ W₂.weaken f (W₁.toVec Γ)) ⟩
(Vec.map (W₂.weaken ∘ f) (W₁.toVec Γ))
≡⟨ VecProps.map-cong hyp (W₁.toVec Γ) ⟩
(Vec.map (f ∘ W₁.weaken) (W₁.toVec Γ))
≡⟨ VecProps.map-∘ f W₁.weaken (W₁.toVec Γ) ⟩
(Vec.map f (Vec.map W₁.weaken (W₁.toVec Γ)))
∎)
-- Lookup commutes with re-indexing, provided that the reindexing
-- function commutes with weakening.
lookup-map : ∀ {n} (f : ∀ {k} → T₁ k → T₂ k) (Γ : Ctx T₁ n) x →
(∀ {k} (t : T₁ k) → W₂.weaken (f t) ≡ f (W₁.weaken t)) →
W₂.lookup (map f Γ) x ≡ f (W₁.lookup Γ x)
lookup-map f Γ x hyp = begin
W₂.lookup (map f Γ) x
≡⟨ cong (flip Vec.lookup x) (toVec-map f Γ hyp) ⟩
Vec.lookup (Vec.map f (W₁.toVec Γ)) x
≡⟨ VecProps.lookup-map x f (W₁.toVec Γ) ⟩
f (W₁.lookup Γ x)
∎
-- Lemmas about well-formed contexts and context extensions.
module ContextFormationLemmas {t ℓ} {T : Pred ℕ t}
(_⊢_wf : Wf T T ℓ) where
open ContextFormation _⊢_wf
-- Concatenation preserves well-formedness of contexts.
wf-++-wfExt : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} →
Γ ⊢ Δ wfExt → Γ wf → Δ ++ Γ wf
wf-++-wfExt [] Γ-wf = Γ-wf
wf-++-wfExt (t-wf ∷ Δ-wfExt) Γ-wf = t-wf ∷ wf-++-wfExt Δ-wfExt Γ-wf
-- Splitting of well-formed contexts.
wf-split : ∀ {m n} {Δ : CtxExt T m n} {Γ : Ctx T m} →
Δ ++ Γ wf → Γ ⊢ Δ wfExt × Γ wf
wf-split {Δ = []} Γ-wf = [] , Γ-wf
wf-split {Δ = t ∷ Δ} (t-wf ∷ Δ++Γ-wf) =
let Δ-wfExt , Γ-wf = wf-split Δ++Γ-wf
in t-wf ∷ Δ-wfExt , Γ-wf
| {
"alphanum_fraction": 0.5211305884,
"avg_line_length": 37.9329896907,
"ext": "agda",
"hexsha": "140d2cdfb76a9553f1db7e209b17a85762026c02",
"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": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/Data/Context/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"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": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/Data/Context/Properties.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/Data/Context/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2826,
"size": 7359
} |
module Haskell.Prim.Monad where
open import Haskell.Prim
open import Haskell.Prim.Applicative
open import Haskell.Prim.Either
open import Haskell.Prim.Foldable
open import Haskell.Prim.Functor
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Monoid
open import Haskell.Prim.String
open import Haskell.Prim.Tuple
--------------------------------------------------
-- Monad
record Monad (m : Set → Set) : Set₁ where
field
_>>=_ : m a → (a → m b) → m b
overlap ⦃ super ⦄ : Applicative m
return : a → m a
return = pure
_>>_ : m a → m b → m b
m >> m₁ = m >>= λ _ → m₁
_=<<_ : (a → m b) → m a → m b
_=<<_ = flip _>>=_
open Monad ⦃ ... ⦄ public
mapM₋ : ⦃ Monad m ⦄ → ⦃ Foldable t ⦄ → (a → m b) → t a → m ⊤
mapM₋ f = foldr (λ x k → f x >> k) (pure tt)
sequence₋ : ⦃ Monad m ⦄ → ⦃ Foldable t ⦄ → t (m a) → m ⊤
sequence₋ = foldr _>>_ (pure tt)
instance
iMonadList : Monad List
iMonadList ._>>=_ = flip concatMap
iMonadMaybe : Monad Maybe
iMonadMaybe ._>>=_ m k = maybe Nothing k m
iMonadEither : Monad (Either a)
iMonadEither ._>>=_ m k = either Left k m
iMonadFun : Monad (λ b → a → b)
iMonadFun ._>>=_ f k r = k (f r) r
iMonadTuple₂ : ⦃ Monoid a ⦄ → Monad (a ×_)
iMonadTuple₂ ._>>=_ (a , x) k = first (a <>_) (k x)
iMonadTuple₃ : ⦃ Monoid a ⦄ → ⦃ Monoid b ⦄ → Monad (a × b ×_)
iMonadTuple₃ ._>>=_ (a , b , x) k =
case k x of λ where
(a₁ , b₁ , y) → a <> a₁ , b <> b₁ , y
iMonadTuple₄ : ⦃ Monoid a ⦄ → ⦃ Monoid b ⦄ → ⦃ Monoid c ⦄ →
Monad (λ d → Tuple (a ∷ b ∷ c ∷ d ∷ []))
iMonadTuple₄ ._>>=_ (a ∷ b ∷ c ∷ x ∷ []) k =
case k x of λ where
(a₁ ∷ b₁ ∷ c₁ ∷ y ∷ []) → a <> a₁ ∷ b <> b₁ ∷ c <> c₁ ∷ y ∷ []
record MonadFail (m : Set → Set) : Set₁ where
field
fail : String → m a
overlap ⦃ super ⦄ : Monad m
open MonadFail ⦃ ... ⦄ public
instance
MonadFailList : MonadFail List
MonadFailList .fail _ = []
MonadFailMaybe : MonadFail Maybe
MonadFailMaybe .fail _ = Nothing
| {
"alphanum_fraction": 0.5634291378,
"avg_line_length": 25.225,
"ext": "agda",
"hexsha": "82a53a42366fcfe9314332287816e347f59b306c",
"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": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "flupe/agda2hs",
"max_forks_repo_path": "lib/Haskell/Prim/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"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": "flupe/agda2hs",
"max_issues_repo_path": "lib/Haskell/Prim/Monad.agda",
"max_line_length": 68,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "4cb28f1b5032948b19b977b390fa260be292abf6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "flupe/agda2hs",
"max_stars_repo_path": "lib/Haskell/Prim/Monad.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 781,
"size": 2018
} |
{- 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
-}
-- This module provides functionality for proving properties about
-- programs written using this RWS monad. The main definitions are:
-- - RWS-weakestPre, a large elimination that, given an RWS program and a
-- post condition for the program, produces the weakest precondition needed
-- to satisfy that post condition. Branches in code using the constructors
-- `RWS-if` and friends are translated into products, with each component of
-- the product corresponding to a possible branch taken.
-- - RWS-Contract is the type of proofs that, given a stateful computation and
-- a post condition, the weakest precondition suffices to prove that post
-- condition.
-- - RWS-contract proves RWS-Contract, i.e., for every stateful computation
-- `m` and post condition `P`, given a proof over a pre-state `pre` the
-- weakest precondition for `P` holds, then postcondition `P` holds for the
-- post-state obtained from running `m` in state `pre`.
module Dijkstra.RWS where
open import Agda.Builtin.Equality using (_≡_; refl)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Haskell.Modules.RWS
open import Haskell.Prelude
private
variable
Ev Wr St : Set
A B C : Set
-- Preconditions are predicates over environments and prestates.
RWS-Pre : (Ev St : Set) → Set₁
RWS-Pre Ev St = (ev : Ev) (pre : St) → Set
-- Postconditions are predicates over a result, poststate, and list of outputs.
RWS-Post : (Wr St A : Set) → Set₁
RWS-Post Wr St A = (x : A) (post : St) (outs : List Wr) → Set
RWS-Post-⇒ : (P Q : RWS-Post Wr St A) → Set
RWS-Post-⇒ P Q = ∀ r st outs → P r st outs → Q r st outs
-- RWS-weakestPre computes a predicate transformer: it maps a RWS
-- computation `m` and desired postcondition `Post` to the weakest precondition
-- needed to prove `P` holds after running `m`.
RWS-PredTrans : (Ev Wr St A : Set) → Set₁
RWS-PredTrans Ev Wr St A = RWS-Post Wr St A → RWS-Pre Ev St
-- When RWS computations are sequenced, e.g., `RWS-bind m λ x → f x`,
-- outputs are concatenated. The postcondition desired for the above sequence
-- becomes a postcondition for `f x` in which the outputs of `m` are prepended
-- to the outputs of `f x`.
RWS-Post++ : ∀ {Wr St A} → RWS-Post Wr St A → List Wr → RWS-Post Wr St A
RWS-Post++ P outs x post outs₁ = P x post (outs ++ outs₁)
-- Consider again the sequence `RWS-bind m₁ λ x → f x`. We also translate a
-- postcondition `P` for the sequence into a postcondition for `m` ---
-- specifically, the post condition we want for `m` is that the weakest
-- precondition for `RWS-Post++ P outs` holds, where `outs` are the outputs of
-- `m`.
RWS-weakestPre-bindPost : (ev : Ev) (f : A → RWS Ev Wr St B) → RWS-Post Wr St B → RWS-Post Wr St A
RWS-weakestPre-ebindPost : (ev : Ev) (f : A → RWS Ev Wr St (Either C B)) → RWS-Post Wr St (Either C B) → RWS-Post Wr St (Either C A)
RWS-weakestPre : (m : RWS Ev Wr St A) → RWS-PredTrans Ev Wr St A
RWS-weakestPre (RWS-return x) P ev pre = P x pre []
RWS-weakestPre (RWS-bind m f) P ev pre =
RWS-weakestPre m (RWS-weakestPre-bindPost ev f P) ev pre
RWS-weakestPre (RWS-gets f) P ev pre = P (f pre) pre []
RWS-weakestPre (RWS-put post) P ev pre = P unit post []
RWS-weakestPre RWS-ask P ev pre = P ev pre []
RWS-weakestPre (RWS-tell outs) P ev pre = P unit pre outs
RWS-weakestPre (RWS-if (clause (b ≔ c) gs)) P ev pre =
(toBool b ≡ true → RWS-weakestPre c P ev pre)
× (toBool b ≡ false → RWS-weakestPre (RWS-if gs) P ev pre)
RWS-weakestPre (RWS-if (otherwise≔ c)) P ev pre =
RWS-weakestPre c P ev pre
RWS-weakestPre (RWS-either f₁ f₂ e) P ev pre =
(∀ x → (e ≡ Left x) →
RWS-weakestPre (f₁ x) P ev pre)
× (∀ y → (e ≡ Right y) →
RWS-weakestPre (f₂ y) P ev pre)
RWS-weakestPre (RWS-ebind m f) P ev pre =
RWS-weakestPre m (RWS-weakestPre-ebindPost ev f P) ev pre
RWS-weakestPre (RWS-maybe f₁ f₂ m) P ev pre =
(m ≡ nothing → RWS-weakestPre f₁ P ev pre)
× (∀ j → m ≡ just j → RWS-weakestPre (f₂ j) P ev pre)
RWS-weakestPre-ebindPost ev f Post (Left r) post outs =
Post (Left r) post outs
RWS-weakestPre-ebindPost ev f Post (Right r) post outs =
∀ c → c ≡ r → RWS-weakestPre (f c) (RWS-Post++ Post outs) ev post
RWS-weakestPre-bindPost ev f Post x post outs =
∀ r → r ≡ x → RWS-weakestPre (f r) (RWS-Post++ Post outs) ev post
-- The post condition `P` holds for `m` with environment `ev` and prestate `pre`
RWS-Post-True : (P : RWS-Post Wr St A) (m : RWS Ev Wr St A) (ev : Ev) (pre : St) → Set
RWS-Post-True P m ev pre =
let (x , post , outs) = RWS-run m ev pre in
P x post outs
-- For every RWS computation `m`, `RWS-Contract m` is the type of proofs that,
-- for all post conditions `P`, starting environments `ev` and prestates `pre`,
-- to prove that `P` holds after running `m` in `ev` and `pre`, it suffices to
-- provide a proof of the weakest precondition for `P` with respect to `m`,
-- `ev`, and `pre`.
RWS-Contract : (m : RWS Ev Wr St A) → Set₁
RWS-Contract{Ev}{Wr}{St}{A} m =
(P : RWS-Post Wr St A)
→ (ev : Ev) (pre : St) → RWS-weakestPre m P ev pre
→ RWS-Post-True P m ev pre
-- This proves that `RWS-weakestPre` gives a *sufficient* precondition for
-- establishing a desired postcondition. Note thought that it does not prove
-- that this precondition is the weakest such one; even though this is true, it
-- is not important for our purposes.
RWS-contract : (m : RWS Ev Wr St A) → RWS-Contract m
RWS-contract (RWS-return x₁) P ev pre wp = wp
RWS-contract (RWS-bind m f) P ev pre wp
with RWS-contract m _ ev pre wp
...| con
with RWS-run m ev pre
...| x₁ , st₁ , outs₁ =
RWS-contract (f x₁) _ ev st₁ (con x₁ refl)
RWS-contract (RWS-gets f) P ev pre wp = wp
RWS-contract (RWS-put x₁) P ev pre wp = wp
RWS-contract RWS-ask P ev pre wp = wp
RWS-contract (RWS-tell x₁) P ev pre wp = wp
RWS-contract{Ev}{Wr}{St}{A} (RWS-if gs) P ev pre wp = RWS-contract-if gs P ev pre wp
where
RWS-contract-if : (gs : Guards (RWS Ev Wr St A)) → RWS-Contract (RWS-if gs)
RWS-contract-if (clause (b ≔ c) gs) P ev pre (wp₁ , wp₂)
with toBool b
...| true = RWS-contract c _ ev pre (wp₁ refl)
...| false = RWS-contract-if gs _ ev pre (wp₂ refl)
RWS-contract-if (otherwise≔ x) P ev pre wp =
RWS-contract x P ev pre wp
RWS-contract (RWS-either f₁ f₂ (Left x)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₁ x) _ ev pre (wp₁ x refl)
RWS-contract (RWS-either f₁ f₂ (Right y)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₂ y) _ ev pre (wp₂ y refl)
RWS-contract (RWS-ebind m f) P ev pre wp
with RWS-contract m _ ev pre wp
...| con
with RWS-run m ev pre
... | Left x , st₁ , outs₁ = con
... | Right y , st₁ , outs₁ = RWS-contract (f y) _ ev st₁ (con y refl)
RWS-contract (RWS-maybe f₁ f₂ nothing) P ev pre (wp₁ , wp₂)
= RWS-contract f₁ _ ev pre (wp₁ refl)
RWS-contract (RWS-maybe f₁ f₂ (just x)) P ev pre (wp₁ , wp₂) =
RWS-contract (f₂ x) _ ev pre (wp₂ x refl)
-- This helper function is primarily used to take a proof concerning one
-- computation `m` and show that that proof implies a property concerning a
-- larger computation which contains `m`.
RWS-⇒
: ∀ {P Q : RWS-Post Wr St A}
→ ∀ m (ev : Ev) st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P Q
→ RWS-weakestPre m Q ev st
RWS-⇒ (RWS-return x) ev st pre pf = pf x st [] pre
RWS-⇒ (RWS-bind m f) ev st pre pf =
RWS-⇒
m ev st pre
(λ r₁ st₁ outs₁ pf₁ x x≡ →
RWS-⇒
(f x) ev st₁ (pf₁ x x≡)
(λ r₂ st₂ outs₂ pf₂ → pf r₂ st₂ (outs₁ ++ outs₂) pf₂))
RWS-⇒ (RWS-gets f) ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-put x) ev st pre pf = pf _ _ _ pre
RWS-⇒ RWS-ask ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-tell x) ev st pre pf = pf _ _ _ pre
RWS-⇒ (RWS-if (otherwise≔ x)) ev st pre pf = RWS-⇒ x ev st pre pf
RWS-⇒ (RWS-if (clause (b ≔ c) cs)) ev st (pre₁ , pre₂) pf =
(λ pf' → RWS-⇒ c ev st (pre₁ pf') pf)
, λ pf' → RWS-⇒ (RWS-if cs) ev st (pre₂ pf') pf
proj₁ (RWS-⇒ (RWS-either f₁ f₂ (Left x)) ev st (pre₁ , pre₂) pf) x₁ x₁≡ =
RWS-⇒ (f₁ x₁) ev st (pre₁ x₁ x₁≡) pf
proj₂ (RWS-⇒ (RWS-either f₁ f₂ (Left x) ) ev st (pre₁ , pre₂) pf) y ()
proj₁ (RWS-⇒ (RWS-either f₁ f₂ (Right y)) ev st (pre₁ , pre₂) pf) y₁ ()
proj₂ (RWS-⇒ (RWS-either f₁ f₂ (Right y)) ev st (pre₁ , pre₂) pf) y₁ y₁≡ =
RWS-⇒ (f₂ y₁) ev st (pre₂ y₁ y₁≡) pf
RWS-⇒ (RWS-ebind m f) ev st pre pf =
RWS-⇒ m ev st pre
(λ { (Left x₁) st₁ outs x → pf _ _ _ x
; (Right y) st₁ outs x → λ c x₁ →
RWS-⇒ (f c) ev st₁ (x c x₁) (λ r st₂ outs₁ x₂ → pf r st₂ (outs ++ outs₁) x₂) })
proj₁ (RWS-⇒ (RWS-maybe m f x) ev st (pre₁ , pre₂) pf) ≡nothing = RWS-⇒ m ev st (pre₁ ≡nothing) pf
proj₂ (RWS-⇒ (RWS-maybe m f x) ev st (pre₁ , pre₂) pf) b b≡ = RWS-⇒ (f b) ev st (pre₂ b b≡) pf
RWS-⇒-bind
: ∀ {P : RWS-Post Wr St A}
{Q : RWS-Post Wr St B}
→ {f : A → RWS Ev Wr St B}
→ ∀ m ev st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P (RWS-weakestPre-bindPost ev f Q)
→ RWS-weakestPre (RWS-bind m f) Q ev st
RWS-⇒-bind m ev st con pf =
RWS-⇒ m ev st con pf
RWS-⇒-ebind
: ∀ {P : RWS-Post Wr St (Either C A)}
{Q : RWS-Post Wr St (Either C B)}
→ {f : A → RWS Ev Wr St (Either C B)}
→ ∀ m ev st
→ RWS-weakestPre m P ev st
→ RWS-Post-⇒ P (RWS-weakestPre-ebindPost ev f Q)
→ RWS-weakestPre (RWS-ebind m f) Q ev st
RWS-⇒-ebind m ev st con pf =
RWS-⇒ m ev st con pf
| {
"alphanum_fraction": 0.6434563758,
"avg_line_length": 44.3534883721,
"ext": "agda",
"hexsha": "7c9feeb64fc9e7ec1dfb9b8ed0f4e11ace353260",
"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/RWS.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/Dijkstra/RWS.agda",
"max_line_length": 132,
"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/RWS.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3583,
"size": 9536
} |
open import Agda.Builtin.Reflection
open import Agda.Builtin.Bool
open import Agda.Builtin.String
open import Agda.Builtin.Equality
open import Agda.Builtin.Unit
open import Agda.Builtin.List
_>>=_ = bindTC
`false `true : Term
`false = con (quote false) []
`true = con (quote true) []
macro
macro? : Name → Term → TC ⊤
macro? x hole =
isMacro x >>= λ where
false → unify hole `false
true → unify hole `true
test₁ : macro? macro? ≡ true
test₁ = refl
test₂ : macro? test₁ ≡ false
test₂ = refl
test₃ : macro? true ≡ false
test₃ = refl
| {
"alphanum_fraction": 0.6797153025,
"avg_line_length": 18.7333333333,
"ext": "agda",
"hexsha": "2efe07d894f45e30648323fa03ec1d10fe11a6f2",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue2182.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue2182.agda",
"max_line_length": 35,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue2182.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": 178,
"size": 562
} |
{-# OPTIONS --without-K --exact-split --safe #-}
open import Fragment.Algebra.Signature
module Fragment.Equational.Model.Satisfaction {Σ : Signature} where
open import Fragment.Equational.Theory.Base hiding (Σ)
open import Fragment.Algebra.Algebra Σ
open import Fragment.Algebra.Free Σ
open import Fragment.Algebra.Homomorphism Σ
open import Level using (Level; _⊔_)
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
open import Data.Product using (_,_)
open import Relation.Binary using (Setoid)
private
variable
a ℓ : Level
_⊨⟨_⟩_ : ∀ {n} → (A : Algebra {a} {ℓ})
→ Env A n → Eq Σ n → Set ℓ
A ⊨⟨ θ ⟩ (lhs , rhs) =
∣ inst A θ ∣ lhs =[ A ] ∣ inst A θ ∣ rhs
_⊨_ : ∀ {n} → Algebra {a} {ℓ} → Eq Σ n → Set (a ⊔ ℓ)
_⊨_ S eq = ∀ θ → S ⊨⟨ θ ⟩ eq
| {
"alphanum_fraction": 0.6572164948,
"avg_line_length": 26.7586206897,
"ext": "agda",
"hexsha": "ea997760450b9bf79ca174a051b622c3e4ebdc79",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Equational/Model/Satisfaction.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Equational/Model/Satisfaction.agda",
"max_line_length": 67,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Equational/Model/Satisfaction.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": 275,
"size": 776
} |
module Lemmachine.Response where
open import Lemmachine.Response.Status public
open import Data.Product
open import Data.List hiding (_++_)
open import Data.Nat
open import Data.String
data ResponseHeader : Set where
_,_ : String → String → ResponseHeader
{-# COMPILED_DATA ResponseHeader
Lemmachine.FFI.ResponseHeader
Lemmachine.FFI.ResponseHeader
#-}
ResponseHeaders = List ResponseHeader
record Response : Set where
field
status : Status
headers : ResponseHeaders
body : String
showStatus : Status → String
showStatus OK = "200"
showStatus Created = "201"
showStatus Accepted = "202"
showStatus NoContent = "204"
showStatus MultipleChoices = "300"
showStatus MovedPermanently = "301"
showStatus SeeOther = "303"
showStatus NotModified = "304"
showStatus MovedTemporarily = "307"
showStatus BadRequest = "400"
showStatus Unauthorized = "401"
showStatus Forbidden = "403"
showStatus NotFound = "404"
showStatus MethodNotAllowed = "405"
showStatus NotAcceptable = "406"
showStatus Conflict = "409"
showStatus Gone = "410"
showStatus PreconditionFailed = "412"
showStatus RequestEntityTooLarge = "413"
showStatus RequestURItooLong = "414"
showStatus UnsupportedMediaType = "415"
showStatus NotImplemented = "501"
showStatus ServiceUnavailable = "503"
defaultHtml : Status → String
defaultHtml x = doctype ++ html x where
doctype = "<!DOCTYPE html>"
head = "<head><meta charset=utf-8 /><title>Lemmachine</title></head>"
body : Status → String
body x = "<body>This HTTP status (" ++ showStatus x ++ ") is brought to you by Lemmachine!</body>"
html : Status → String
html x = "<html lang='en'>" ++ head ++ body x ++ "</html>"
| {
"alphanum_fraction": 0.7406962785,
"avg_line_length": 29.2280701754,
"ext": "agda",
"hexsha": "3c9302fbb63a39f5d6575fee7009b2a2f55312d1",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "src/Lemmachine/Response.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "src/Lemmachine/Response.agda",
"max_line_length": 100,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "src/Lemmachine/Response.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-21T17:02:19.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-20T02:11:42.000Z",
"num_tokens": 412,
"size": 1666
} |
-- Andreas, 2019-10-21, issue #4148, reported by omelkonian
{-# OPTIONS -v impossible:100 #-}
postulate
A : Set
module M (I : Set) where
postulate
P : I → Set
record R (i : I) : Set where
constructor mk
field
f : P i
open module N = M A
data D : ∀ {i} → R i → Set where
c : ∀ {i} {t : P i} → D (mk t)
test : ∀ {i} {t : R i} → D t → Set₁
test c = Set
-- WAS: internal error in a sanity check in etaExpandRecord'_
-- Should succeed
| {
"alphanum_fraction": 0.5729613734,
"avg_line_length": 16.0689655172,
"ext": "agda",
"hexsha": "b1b7ebd5e370e6367dc4a739b1e2412f7b59be32",
"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/Issue4148.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/Issue4148.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/Issue4148.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": 167,
"size": 466
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Group
open import lib.groups.Homomorphism
open import lib.groups.TensorProduct
module lib.types.CRing where
-- 1-approximation of commutative rings without higher coherence conditions.
record CRingStructure {i} (El : Type i)
: Type i where
constructor ring-structure
field
add-group-struct : GroupStructure El
open GroupStructure add-group-struct
zero : El
zero = ident
add : El → El → El
add = comp
neg : El → El
neg = inv
field
add-comm : ∀ a b → add a b == add b a
one : El
mult : El → El → El
mult-unit-l : ∀ a → mult one a == a
mult-assoc : ∀ a b c → mult (mult a b) c == mult a (mult b c)
mult-comm : ∀ a b → mult a b == mult b a
distr-l : ∀ a b c → mult (add a b) c == add (mult a c) (mult b c)
private
infix 80 _⊕_
_⊕_ = add
infix 90 _⊗_
_⊗_ = mult
add-assoc : ∀ a b c → (a ⊕ b) ⊕ c == a ⊕ (b ⊕ c)
add-assoc = assoc
abstract
mult-unit-r : ∀ a → a ⊗ one == a
mult-unit-r a =
a ⊗ one =⟨ mult-comm a one ⟩
one ⊗ a =⟨ mult-unit-l a ⟩
a =∎
distr-r : ∀ a b c → a ⊗ (b ⊕ c) == a ⊗ b ⊕ a ⊗ c
distr-r a b c =
a ⊗ (b ⊕ c) =⟨ mult-comm a (add b c) ⟩
(b ⊕ c) ⊗ a =⟨ distr-l b c a ⟩
b ⊗ a ⊕ c ⊗ a =⟨ (mult-comm b a) |in-ctx (λ x → add x (mult c a)) ⟩
a ⊗ b ⊕ c ⊗ a =⟨ (mult-comm c a) |in-ctx (add (mult a b)) ⟩
a ⊗ b ⊕ a ⊗ c =∎
mult-zero-l : ∀ a → zero ⊗ a == zero
mult-zero-l a =
cancel-l (zero ⊗ a) $
zero ⊗ a ⊕ zero ⊗ a =⟨ ! (distr-l zero zero a) ⟩
(zero ⊕ zero) ⊗ a =⟨ unit-l zero |in-ctx (λ x → x ⊗ a) ⟩
zero ⊗ a =⟨ ! (unit-r (zero ⊗ a)) ⟩
zero ⊗ a ⊕ zero =∎
mult-zero-r : ∀ a → a ⊗ zero == zero
mult-zero-r a =
a ⊗ zero =⟨ mult-comm a zero ⟩
zero ⊗ a =⟨ mult-zero-l a ⟩
zero =∎
record CRing i : Type (lsucc i) where
constructor ring
field
El : Type i
{{El-level}} : has-level 0 El
ring-struct : CRingStructure El
open CRingStructure ring-struct public
add-group : Group i
add-group = group El add-group-struct
add-abgroup : AbGroup i
add-abgroup = add-group , add-comm
mult-hom : El → add-group →ᴳ add-group
mult-hom g = group-hom (mult g) (distr-r g)
mult-hom-zero : mult-hom zero == cst-hom
mult-hom-zero = group-hom= (λ= mult-zero-l)
private
module R⊗R = TensorProduct add-abgroup add-abgroup
module UP = R⊗R.UniversalProperty add-abgroup
mult-bilinear-map : UP.BilinearMap
mult-bilinear-map =
record
{ bmap = mult
; linearity-l = distr-l
; linearity-r = distr-r
}
mult-hom' : R⊗R.grp →ᴳ add-group
mult-hom' = UP.extend mult-bilinear-map
mult-hom'-β : ∀ a b → GroupHom.f mult-hom' (a R⊗R.⊗ b) == mult a b
mult-hom'-β = UP.extend-β mult-bilinear-map
Ring₀ : Type (lsucc lzero)
Ring₀ = CRing lzero
| {
"alphanum_fraction": 0.5442359249,
"avg_line_length": 25.947826087,
"ext": "agda",
"hexsha": "71e1ce24958e9176b6ce2c073b84aafb162e3223",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/CRing.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/CRing.agda",
"max_line_length": 76,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/CRing.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1111,
"size": 2984
} |
------------------------------------------------------------------------------
-- Proving properties without using pattern matching on refl
------------------------------------------------------------------------------
{-# OPTIONS --no-pattern-matching #-}
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
module FOT.PA.Inductive2Mendelson.NoPatternMatchingOnRefl where
open import PA.Inductive.Base
------------------------------------------------------------------------------
-- From PA.Inductive2Mendelson
S₁ : ∀ {m n o} → m ≡ n → m ≡ o → n ≡ o
S₁ h₁ h₂ = trans (sym h₁) h₂
S₂ : ∀ {m n} → m ≡ n → succ m ≡ succ n
S₂ {m} h = subst (λ t → succ m ≡ succ t) h refl
-- 20 May 2013. Requires the predecessor function.
-- S₄ : ∀ {m n} → succ m ≡ succ n → m ≡ n
| {
"alphanum_fraction": 0.4383078731,
"avg_line_length": 34.04,
"ext": "agda",
"hexsha": "3b9205bd403de089edd732928af8eec2a9de8a7c",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/PA/Inductive2Mendelson/NoPatternMatchingOnRefl.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/PA/Inductive2Mendelson/NoPatternMatchingOnRefl.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/PA/Inductive2Mendelson/NoPatternMatchingOnRefl.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": 211,
"size": 851
} |
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
data Three : Set -- (AAA) To fix things, move this line...
data One : Set where
one : Nat → One
data Two : Set where
two : One → Two
lemma′ : ∀ (m n : Nat) → (one m) ≡ (one n) → m ≡ n
lemma′ m .m refl = refl
lemma : ∀ (m n : Nat) → (two (one m)) ≡ (two (one n)) → m ≡ n
lemma m .m refl = refl
{- Error was:
I'm not sure if there should be a case for the constructor refl,
because I get stuck when trying to solve the following unification
problems (inferred index ≟ expected index):
two (one m) ≟ two (one n)
when checking that the pattern refl has type
two (one m) ≡ two (one n)
-}
-- (BBB) ... to here.
data Three where
three : Three
| {
"alphanum_fraction": 0.6447552448,
"avg_line_length": 23.064516129,
"ext": "agda",
"hexsha": "16fc7a5183011f20e21192cfbb3d7f5f76fd8748",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/Issue4750.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/Issue4750.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue4750.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": 231,
"size": 715
} |
open import Categories.Category
open import Categories.Category.CartesianClosed
{-
The internal language of a given cartesian closed category.
-}
module Internal {o ℓ e} (𝒞 : Category o ℓ e)
(cartesianClosed : CartesianClosed 𝒞) where
open import Relation.Binary using (Rel)
open import Data.Product using (Σ-syntax; _,_)
open import Level
open import Syntax
open import Theory
open import Categories.Category.Cartesian 𝒞
open import Categories.Category.BinaryProducts 𝒞
open import Categories.Object.Terminal 𝒞
open Category 𝒞
open CartesianClosed cartesianClosed
open Cartesian cartesian
open BinaryProducts products
module T = Terminal terminal
module _ where
open PType Obj
data F : Set (o ⊔ ℓ) where
Inherit : forall {A B : Obj} -> A ⇒ B -> F
I : Type -> F
J : Type -> F
-- The same as ⟦_⟧T in Semantics.agda.
⟦_⟧T′ : Type -> Obj
⟦ ⌊ A ⌋ ⟧T′ = A
⟦ Unit ⟧T′ = T.⊤
⟦ A * A₁ ⟧T′ = ⟦ A ⟧T′ × ⟦ A₁ ⟧T′
⟦ A => A₁ ⟧T′ = ⟦ A ⟧T′ ⇨ ⟦ A₁ ⟧T′
sorting : F -> Sorting
sorting (Inherit {A} {B} f) = record { dom = ⌊ A ⌋ ; cod = ⌊ B ⌋ }
sorting (I A) = record { dom = ⌊ ⟦ A ⟧T′ ⌋ ; cod = A }
sorting (J A) = record { dom = A ; cod = ⌊ ⟦ A ⟧T′ ⌋ }
Sg : Signature o (o ⊔ ℓ)
Sg = record { Gr = Obj ; Func = F ; sorting = sorting }
open Signature Sg
open Term Sg
open import Semantics 𝒞 cartesianClosed Sg
open I (λ x → x)
i : forall (A : Type) -> (⟦ ⌊ ⟦ A ⟧T′ ⌋ ⟧T) ⇒ (⟦ A ⟧T)
j : forall (A : Type) -> (⟦ A ⟧T) ⇒ (⟦ ⌊ ⟦ A ⟧T′ ⌋ ⟧T)
i ⌊ A ⌋ = Category.id 𝒞
i Unit = Category.id 𝒞
i (A * A₁) = (i A) ⁂ (i A₁)
i (A => A₁) = λg (i A₁ ∘ (eval′ ∘ (Category.id 𝒞 ⁂ j A)))
j ⌊ A ⌋ = Category.id 𝒞
j Unit = Category.id 𝒞
j (A * A₁) = j A ⁂ j A₁
j (A => A₁) = λg ((j A₁ ∘ (eval′ ∘ (Category.id 𝒞 ⁂ i A))))
S : Structure
S = record { ⟦_⟧G = λ x → x ; ⟦_⟧F = λ { (Inherit f) → f ; (I A) → i A ; (J A) → j A} }
open Structure S
data Ax (Γ : Context) (A : Type) : Rel (Γ ⊢ A) (o ⊔ ℓ ⊔ e) where
E : forall {e₁ e₂} -> ⟦ e₁ ⟧ ≈ ⟦ e₂ ⟧ -> Ax Γ A e₁ e₂
Th : Theory o (o ⊔ ℓ) (o ⊔ ℓ ⊔ e)
Th = record { Sg = Sg ; Ax = Ax }
M : Model 𝒞 cartesianClosed Th
M = S , λ { (E x) → x}
| {
"alphanum_fraction": 0.5750237417,
"avg_line_length": 25.3734939759,
"ext": "agda",
"hexsha": "c318186c9f3e2eeb722eeb987752c1d15060385b",
"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": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "elpinal/exsub-ccc",
"max_forks_repo_path": "Internal.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"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": "elpinal/exsub-ccc",
"max_issues_repo_path": "Internal.agda",
"max_line_length": 87,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "7541ab22debdfe9d529ac7a210e5bd102c788ad9",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "elpinal/exsub-ccc",
"max_stars_repo_path": "Internal.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T13:30:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-05T06:16:32.000Z",
"num_tokens": 894,
"size": 2106
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Examples showing how the notion of Interleaving can be used
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module README.Data.Interleaving where
open import Level
open import Data.List.Base hiding (filter)
open import Data.List.Relation.Unary.All
open import Function
open import Relation.Nullary
open import Relation.Unary
-- In its most general form, `Interleaving` is parametrised by two relations
-- `L` (for Left) and `R` (for Right). Given three lists, `xs`, `ys` and `zs`,
-- a proof of `Interleaving xs ys zs` is essentially a diagram explaining how
-- `zs` can be pulled apart into `xs` and `ys` in a way compatible with `L`
-- and `R`. For instance:
-- xs zs ys
--
-- x₁ -- L x₁ z₁ -- z₁
-- x₂ -- L x₂ z₂ -- z₂
-- z₃ -- R z₃ z₁ -- y₁
-- x₃ -- L x₃ z₄ -- z₄
-- z₅ -- R z₅ y₂ -- y₂
open import Data.List.Relation.Ternary.Interleaving.Propositional
-- The special case we will focus on here is the propositional case: both
-- `L` and ̀R` are propositional equality. Rethinking our previous example,
-- this gives us the proof that [z₁, ⋯, z₅] can be partitioned into
-- [z₁, z₂, z₄] on the one hand and [z₃, z₅] in the other.
-- One possible use case for such a relation is the definition of a very
-- precise filter function. Provided a decidable predicate `P`, it will
-- prove not only that the retained values satisfy `P` but that the ones
-- that didn't make the cut satisfy the negation of P.
-- We can make this formal by defining the following record type:
infix 3 _≡_⊎_
record Filter {a p} {A : Set a} (P : Pred A p) (xs : List A) : Set (a ⊔ p) where
constructor _≡_⊎_
field
-- The result of running filter is two lists:
-- * the elements we have kept
-- * and the ones we have thrown away
-- We leave these implicit: they can be inferred from the rest
{kept} : List A
{thrown} : List A
-- There is a way for us to recover the original
-- input by interleaving the two lists
cover : Interleaving kept thrown xs
-- Finally, the partition was made according to the predicate
allP : All P kept
all¬P : All (∁ P) thrown
-- Once we have this type written down, we can write the function.
-- We use an anonymous module to clean up the function's type.
module _ {a p} {A : Set a} {P : Pred A p} (P? : Decidable P) where
filter : ∀ xs → Filter P xs
-- If the list is empty, we are done.
filter [] = [] ≡ [] ⊎ []
filter (x ∷ xs) =
-- otherwise we start by running filter on the tail
let xs' ≡ ps ⊎ ¬ps = filter xs in
-- And depending on whether `P` holds of the head,
-- we cons it to the `kept` or `thrown` list.
case P? x of λ where -- [1]
(yes p) → consˡ xs' ≡ p ∷ ps ⊎ ¬ps
(no ¬p) → consʳ xs' ≡ ps ⊎ ¬p ∷ ¬ps
-- [1] See the following module for explanations of `case_of_` and
-- pattern-matching lambdas
import README.Case
| {
"alphanum_fraction": 0.6130798969,
"avg_line_length": 36.5176470588,
"ext": "agda",
"hexsha": "5736d95f43f65573fe9d462d79613e7022c07a96",
"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/README/Data/Interleaving.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/README/Data/Interleaving.agda",
"max_line_length": 80,
"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/README/Data/Interleaving.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": 892,
"size": 3104
} |
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.RingStructure.RingLaws where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.RingStructure.CupProduct
open import Cubical.Homotopy.Loopspace
open import Cubical.HITs.S1 hiding (_·_)
open import Cubical.HITs.Sn
open import Cubical.HITs.Susp
open import Cubical.HITs.SetTruncation renaming (elim to sElim ; elim2 to sElim2)
open import Cubical.HITs.Truncation renaming (elim to trElim)
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.Foundations.GroupoidLaws hiding (assoc)
open import Cubical.Data.Int
renaming (_+_ to _ℤ+_ ; _·_ to _ℤ∙_ ; +Comm to +ℤ-comm
; ·Comm to ∙-comm ; +Assoc to ℤ+-assoc ; -_ to -ℤ_)
hiding (_+'_ ; +'≡+)
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
private
variable
ℓ : Level
-- Some boring lemmas
·₀≡·ℤ : (x y : ℤ) → _·₀_ {n = zero} x y ≡ x ℤ∙ y
·₀≡·ℤ (pos zero) y = refl
·₀≡·ℤ (pos (suc n)) y = cong (y ℤ+_) (·₀≡·ℤ (pos n) y)
·₀≡·ℤ (negsuc zero) (pos zero) = refl
·₀≡·ℤ (negsuc zero) (pos (suc n)) = -AntiComm 0 (pos (suc n))
·₀≡·ℤ (negsuc zero) (negsuc n) = -AntiComm 0 (negsuc n)
·₀≡·ℤ (negsuc (suc n)) (pos m) =
(cong ((_ℤ+ (pos 0 - pos m))) (·₀≡·ℤ (negsuc n) (pos m))
∙ cong ((negsuc n ℤ∙ (pos m)) ℤ+_)
(-AntiComm 0 (pos m) ∙ cong (-ℤ_) (help m)))
∙ sym (+ℤ-comm (-ℤ (pos m)) (negsuc n ℤ∙ (pos m)))
where
help : (m : ℕ) → (pos m - 0) ≡ pos m
help zero = refl
help (suc m) = refl
·₀≡·ℤ (negsuc (suc n)) (negsuc m) =
+ℤ-comm (_·₀_{n = zero} (negsuc n) (negsuc m)) (pos 0 - (negsuc m))
∙∙ cong ((pos 0 - negsuc m) ℤ+_) (·₀≡·ℤ (negsuc n) (negsuc m))
∙∙ cong (_ℤ+ (negsuc n ℤ∙ negsuc m)) (help m)
where
help : (m : ℕ) → (pos 0 - negsuc m) ≡ pos (suc m)
help zero = refl
help (suc n) = cong sucℤ (help n)
comm-·₀ : (x y : ℤ) → _·₀_ {n = 0} x y ≡ y ·₀ x
comm-·₀ x y = ·₀≡·ℤ x y ∙∙ ∙-comm x y ∙∙ sym (·₀≡·ℤ y x)
+'-assoc : (n m l : ℕ) → (n +' (m +' l)) ≡ ((n +' m) +' l)
+'-assoc n m l =
(λ i → +'≡+ n (+'≡+ m l i) i)
∙∙ +-assoc n m l
∙∙ (λ i → +'≡+ (+'≡+ n m (~ i)) l (~ i))
-- Zero multiplication
⌣ₖ-0ₖ : (n m : ℕ) → (x : coHomK n)
→ x ⌣ₖ (0ₖ _) ≡ 0ₖ _
⌣ₖ-0ₖ n m x = snd (⌣ₖ∙ n m x)
0ₖ-⌣ₖ : (n m : ℕ) → (x : coHomK m) →
(0ₖ _) ⌣ₖ x ≡ 0ₖ _
0ₖ-⌣ₖ n m = funExt⁻ (cong fst (snd (⌣ₖ∙∙ n m)))
⌣ₖ-0ₖ≡0ₖ-⌣ₖ : (n m : ℕ) → ⌣ₖ-0ₖ n m (0ₖ _) ≡ 0ₖ-⌣ₖ n m (0ₖ _)
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ zero (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc n) zero = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc zero) (suc m) = refl
⌣ₖ-0ₖ≡0ₖ-⌣ₖ (suc (suc n)) (suc m) = refl
-- Left distributivity
private
⌣ₖ-distrFun : -- z ⌣ₖ (x +ₖ y)
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun n m x y) z =
z ⌣ₖ (x +ₖ y)
snd (⌣ₖ-distrFun n m x y) =
0ₖ-⌣ₖ m n (x +ₖ y)
⌣ₖ-distrFun2 : -- z ⌣ₖ x +ₖ z ⌣ₖ y
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (m +' n)
fst (⌣ₖ-distrFun2 n m x y) z =
z ⌣ₖ x +ₖ z ⌣ₖ y
snd (⌣ₖ-distrFun2 n m x y) =
cong₂ _+ₖ_ (0ₖ-⌣ₖ m n x) (0ₖ-⌣ₖ m n y) ∙ rUnitₖ _ _
leftDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n)) → ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y
leftDistr-⌣ₖ· n m =
elim2 (λ _ _ → isOfHLevelSuc (2 + n) (hLevHelp n m _ _))
main
where
hLevHelp : (n m : ℕ) (x y : _) → isOfHLevel (2 + n) ( ⌣ₖ-distrFun (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2 (suc n) (suc m) x y)
hLevHelp n m x y =
(subst (isOfHLevel (3 + n))
(λ i → (coHomK-ptd (suc m) →∙ coHomK-ptd (suc (suc (+-comm n m i)))))
(isOfHLevel↑∙ (suc n) m)) _ _
left-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ x ∣)
left-fst zero y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
left-fst (suc n) y =
(funExt (λ z → sym (lUnitₖ _ (z ⌣ₖ ∣ y ∣)) ∙ λ i → ⌣ₖ-0ₖ _ _ z (~ i) +ₖ z ⌣ₖ ∣ y ∣))
right-fst : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ (0ₖ _)) ≡
fst (⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ (0ₖ _))
right-fst n x = funExt (λ z → (cong (z ⌣ₖ_) (rUnitₖ _ ∣ x ∣) ∙∙ sym (rUnitₖ _ _) ∙∙ λ i → z ⌣ₖ ∣ x ∣ +ₖ ⌣ₖ-0ₖ _ (suc n) z (~ i)))
helper : (n : ℕ) (x : coHomK (suc n)) (p : 0ₖ _ ≡ x)
→ sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p
helper n x = J (λ x p → sym (lUnitₖ _ x) ∙ cong (_+ₖ x) p ≡ sym (rUnitₖ _ x) ∙ cong (x +ₖ_) p)
(helper' n)
where
helper' : (n : ℕ) → (λ i → lUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
≡
(λ i → rUnitₖ (suc n) (0ₖ (suc n)) (~ i)) ∙
(λ i → 0ₖ (suc n) +ₖ 0ₖ (suc n))
helper' zero = refl
helper' (suc n) = refl
left-fst≡right-fst : (n : ℕ) → left-fst n (ptSn _) ≡ right-fst n (ptSn _)
left-fst≡right-fst zero i j z = helper _ (z ⌣ₖ ∣ base ∣) (sym (⌣ₖ-0ₖ _ _ z)) i j
left-fst≡right-fst (suc n) i j z = helper _ (z ⌣ₖ ∣ north ∣) (sym (⌣ₖ-0ₖ _ (suc (suc n)) z)) i j
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2 (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2 (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (hLevHelp n m ∣ x ∣ ∣ y ∣)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (left-fst n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (right-fst n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left-fst≡right-fst n)))
-- Distributivity for 0 dimensional cases
leftDistr₀n : (n : ℕ) → (z : coHomK 0) (x y : coHomK n)
→ z ·₀ (x +[ n ]ₖ y) ≡ z ·₀ x +[ n ]ₖ (z ·₀ y)
leftDistr₀n n (pos zero) x y = sym (rUnitₖ n (0ₖ _))
leftDistr₀n n (pos (suc z)) x y =
cong ((x +ₖ y) +ₖ_) (leftDistr₀n n (pos z) x y)
∙∙ sym (assocₖ n x y (pos z ·₀ x +[ n ]ₖ (pos z ·₀ y)))
∙∙ cong (x +ₖ_) (assocₖ n y (pos z ·₀ x) (pos z ·₀ y)
∙∙ cong (_+ₖ (pos z ·₀ y)) (commₖ n y (pos z ·₀ x))
∙∙ sym (assocₖ n (pos z ·₀ x) y (pos z ·₀ y)))
∙ assocₖ n x _ _
leftDistr₀n n (negsuc zero) x y = -distrₖ n x y
leftDistr₀n n (negsuc (suc z)) x y =
cong₂ (_+ₖ_) (leftDistr₀n n (negsuc z) x y) (-distrₖ n x y)
∙∙ assocₖ n ((negsuc z ·₀ x) +ₖ (negsuc z ·₀ y)) (-ₖ x) (-ₖ y)
∙∙ cong (_-ₖ y) (sym (assocₖ n (negsuc z ·₀ x) (negsuc z ·₀ y) (-ₖ x))
∙∙ cong ((negsuc z ·₀ x) +ₖ_) (commₖ n (negsuc z ·₀ y) (-ₖ x))
∙∙ assocₖ n (negsuc z ·₀ x) (-ₖ x) (negsuc z ·₀ y))
∙ sym (assocₖ n (negsuc (suc z) ·₀ x) _ _)
leftDistrn₀ : (n : ℕ) → (z : coHomK n) (x y : coHomK 0)
→ (x ℤ+ y) ·₀ z ≡ x ·₀ z +[ n ]ₖ (y ·₀ z)
leftDistrn₀ n z x (pos zero) = sym (rUnitₖ n (x ·₀ z))
leftDistrn₀ n z x (pos (suc y)) =
lem (x +pos y)
∙∙ cong (z +ₖ_) (leftDistrn₀ n z x (pos y) ∙ commₖ n _ _)
∙∙ assocₖ n z _ _
∙ commₖ n _ _
where
lem : (a : ℤ) → (sucℤ a) ·₀ z ≡ z +ₖ (a ·₀ z)
lem (pos zero) = refl
lem (pos (suc a)) = cong (z +ₖ_) (lem (pos a))
lem (negsuc zero) = sym (rCancelₖ n z)
lem (negsuc (suc a)) = sym (-cancelLₖ n z (negsuc a ·₀ z)) ∙ sym (assocₖ n z (negsuc a ·₀ z) (-ₖ z))
leftDistrn₀ n z x (negsuc y) = main y
where
help : (x : ℤ) → predℤ x ·₀ z ≡ (x ·₀ z -ₖ z)
help (pos zero) = sym (lUnitₖ n (-ₖ z))
help (pos (suc x)) = sym (-cancelLₖ n z (pos x ·₀ z))
help (negsuc x) = refl
main : (y : _) → (x ℤ+ negsuc y) ·₀ z ≡ (x ·₀ z) +ₖ (negsuc y ·₀ z)
main zero = help x
main (suc y) =
help (x +negsuc y)
∙∙ cong (_-ₖ z) (main y)
∙∙ sym (assocₖ n _ _ _)
leftDistr-⌣ₖ : (n m : ℕ) (z : coHomK n) (x y : coHomK m)
→ z ⌣ₖ (x +ₖ y) ≡ (z ⌣ₖ x +ₖ z ⌣ₖ y)
leftDistr-⌣ₖ zero m z x y = leftDistr₀n m z x y
leftDistr-⌣ₖ (suc n) zero z x y = leftDistrn₀ (suc n) z x y
leftDistr-⌣ₖ (suc n) (suc m) z x y = funExt⁻ (cong fst (leftDistr-⌣ₖ· m n x y)) z
-- Right distributivity
private
⌣ₖ-distrFun-r : -- (x +ₖ y) ⌣ₖ z
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun-r n m x y) z =
(x +ₖ y) ⌣ₖ z
snd (⌣ₖ-distrFun-r n m x y) =
⌣ₖ-0ₖ n m (x +ₖ y) -- ⌣ₖ-0ₖ m n (x +ₖ y)
⌣ₖ-distrFun2-r :
(n m : ℕ) → (x y : coHomK n)
→ coHomK-ptd m →∙ coHomK-ptd (n +' m)
fst (⌣ₖ-distrFun2-r n m x y) z =
x ⌣ₖ z +ₖ y ⌣ₖ z
snd (⌣ₖ-distrFun2-r n m x y) =
cong₂ _+ₖ_ (⌣ₖ-0ₖ n m x) (⌣ₖ-0ₖ n m y) ∙ rUnitₖ _ _
rightDistr-⌣ₖ· : (n m : ℕ) (x y : coHomK (suc n)) → ⌣ₖ-distrFun-r (suc n) (suc m) x y ≡ ⌣ₖ-distrFun2-r (suc n) (suc m) x y
rightDistr-⌣ₖ· n m =
elim2 (λ _ _ → isOfHLevelPath (3 + n) (isOfHLevel↑∙ (suc n) m) _ _)
main
where
fst-left : (n : ℕ) (y : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ ptSn (suc n) ∣ ∣ y ∣)
fst-left n y =
funExt (λ z
→ cong (_⌣ₖ z) (lUnitₖ _ ∣ y ∣)
∙∙ sym (lUnitₖ _ (∣ y ∣ ⌣ₖ z))
∙∙ cong (_+ₖ (∣ y ∣ ⌣ₖ z)) (sym (0ₖ-⌣ₖ _ _ z)))
fst-right : (n : ℕ) (x : S₊ (suc n)) →
fst (⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣) ≡
fst (⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ ptSn (suc n) ∣)
fst-right n x =
funExt λ z
→ cong (_⌣ₖ z) (rUnitₖ _ ∣ x ∣)
∙∙ sym (rUnitₖ _ _)
∙∙ cong (∣ x ∣ ⌣ₖ z +ₖ_) (sym (0ₖ-⌣ₖ _ _ z))
left≡right : (n : ℕ) → fst-left n (ptSn (suc n)) ≡ fst-right n (ptSn (suc n))
left≡right zero = refl
left≡right (suc n) = refl
main : (a b : S₊ (suc n)) →
⌣ₖ-distrFun-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ ≡
⌣ₖ-distrFun2-r (suc n) (suc m) ∣ a ∣ₕ ∣ b ∣ₕ
main =
wedgeconFun n n
(λ x y → subst (λ l → isOfHLevel l ((⌣ₖ-distrFun-r (suc n) (suc m) ∣ x ∣ ∣ y ∣)
≡ ⌣ₖ-distrFun2-r (suc n) (suc m) ∣ x ∣ ∣ y ∣))
(+-suc n (suc n))
(isOfHLevelPlus {n = 2 + n} n (isOfHLevel↑∙ (suc n) m _ _)))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-left n x))
(λ x → →∙Homogeneous≡ (isHomogeneousKn _) (fst-right n x))
(cong (→∙Homogeneous≡ (isHomogeneousKn _)) (sym (left≡right n)))
rightDistr-⌣ₖ : (n m : ℕ) (x y : coHomK n) (z : coHomK m)
→ (x +ₖ y) ⌣ₖ z ≡ (x ⌣ₖ z +ₖ y ⌣ₖ z)
rightDistr-⌣ₖ zero zero x y z =
comm-·₀ (x ℤ+ y) z
∙∙ leftDistr-⌣ₖ zero zero z x y
∙∙ cong₂ _+ₖ_ (sym (comm-·₀ x z)) (sym (comm-·₀ y z))
rightDistr-⌣ₖ zero (suc m) x y z = leftDistr-⌣ₖ _ zero z x y
rightDistr-⌣ₖ (suc n) zero x y z = leftDistr-⌣ₖ zero (suc n) z x y
rightDistr-⌣ₖ (suc n) (suc m) x y z = (funExt⁻ (cong fst (rightDistr-⌣ₖ· n m x y))) z
-- Associativity
private
-- We need to give the two associators as (doubly) pointed functions
assocer : (n m k : ℕ) → coHomK (suc n)
→ coHomK-ptd (suc m)
→∙ (coHomK-ptd (suc k)
→∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer n m k x) y) z = x ⌣ₖ (y ⌣ₖ z)
snd (fst (assocer n m k x) y) = cong (x ⌣ₖ_) (⌣ₖ-0ₖ _ (suc k) y) ∙ ⌣ₖ-0ₖ _ _ x
snd (assocer n m k x) =
ΣPathP (funExt (λ z → cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) z) ∙ ⌣ₖ-0ₖ (suc n) _ x)
, help)
where
h : (n m k : ℕ) (x : coHomK (suc n)) → cong (_⌣ₖ_ x) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ≡
(λ i → x ⌣ₖ 0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _) i)
h zero zero k x = refl
h zero (suc m) k x = refl
h (suc n) zero k x = refl
h (suc n) (suc m) k x = refl
help : PathP (λ i → (cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) i ≡ 0ₖ _)
(cong (x ⌣ₖ_) (⌣ₖ-0ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) refl
help = compPathR→PathP
(cong (_∙ ⌣ₖ-0ₖ (suc n) ((suc m) +' (suc k)) x) (h n m k x)
∙∙ rUnit _
∙∙ cong ((cong (x ⌣ₖ_) (0ₖ-⌣ₖ (suc m) (suc k) (0ₖ _)) ∙ ⌣ₖ-0ₖ (suc n) _ x) ∙_) (rUnit refl))
assoc2-sub : (n m k : ℕ) → _ → _
assoc2-sub n m k = subst coHomK (sym (+'-assoc n m k))
assoc2-sub-0 : (n m k : ℕ) → assoc2-sub n m k (0ₖ _) ≡ 0ₖ _
assoc2-sub-0 zero zero zero = refl
assoc2-sub-0 zero zero (suc zero) = refl
assoc2-sub-0 zero zero (suc (suc k)) = refl
assoc2-sub-0 zero (suc zero) zero = refl
assoc2-sub-0 zero (suc zero) (suc k) = refl
assoc2-sub-0 zero (suc (suc m)) zero = refl
assoc2-sub-0 zero (suc (suc m)) (suc k) = refl
assoc2-sub-0 (suc zero) zero zero = refl
assoc2-sub-0 (suc zero) zero (suc k) = refl
assoc2-sub-0 (suc (suc n)) zero zero = refl
assoc2-sub-0 (suc (suc n)) zero (suc k) = refl
assoc2-sub-0 (suc zero) (suc m) zero = refl
assoc2-sub-0 (suc (suc n)) (suc m) zero = refl
assoc2-sub-0 (suc zero) (suc m) (suc k) = refl
assoc2-sub-0 (suc (suc n)) (suc m) (suc k) = refl
assocer2 : (n m k : ℕ)
→ coHomK (suc n)
→ coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd ((suc n) +' ((suc m) +' (suc k))) ∙)
fst (fst (assocer2 n m k x) y) z =
subst coHomK (sym (+'-assoc (suc n) (suc m) (suc k))) ((x ⌣ₖ y) ⌣ₖ z) --
snd (fst (assocer2 zero m k x) y) =
cong (subst coHomK (sym (+'-assoc 1 (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
snd (fst (assocer2 (suc n) m k x) y) =
cong (subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k)))) (⌣ₖ-0ₖ _ _ (x ⌣ₖ y))
fst (snd (assocer2 zero m k x) i) z =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 zero m k x) i) j =
subst coHomK (sym (+'-assoc (suc zero) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
fst (snd (assocer2 (suc n) m k x) i) z =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ x i ⌣ₖ z)
snd (snd (assocer2 (suc n) m k x) i) j =
subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (⌣ₖ-0ₖ _ _ (⌣ₖ-0ₖ _ _ x i) j)
assocer-helpFun : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun n m a) b = Kn→ΩKn+1 _ (a ⌣ₖ b)
snd (assocer-helpFun n m a) = cong (Kn→ΩKn+1 _) (⌣ₖ-0ₖ (suc n) (suc m) a) ∙ Kn→ΩKn+10ₖ _
assocer-helpFun2 : (n m : ℕ) → coHomK (suc n) → coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m)))
fst (assocer-helpFun2 n m a) b i = (Kn→ΩKn+1 _ a i) ⌣ₖ b
snd (assocer-helpFun2 n m a) i j = ⌣ₖ-0ₖ _ (suc m) (Kn→ΩKn+1 _ a j) i
-- Key lemma for associativity
assocer-helpFun≡ : (n m : ℕ) → (x : coHomK (suc n)) → assocer-helpFun n m x ≡ assocer-helpFun2 n m x
assocer-helpFun≡ n m =
trElim (λ _ → isOfHLevelPath (3 + n) (hLev-assocer-helpFun n m) _ _)
λ a → →∙Homogeneous≡ (subst isHomogeneous Kn≃ΩKn+1∙ (isHomogeneousKn _))
(funExt (main n a))
where
hLev-assocer-helpFun : (n m : ℕ) → isOfHLevel (3 + n) (coHomK-ptd (suc m) →∙ Ω (coHomK-ptd (3 + (n + m))))
hLev-assocer-helpFun n m =
subst (isOfHLevel (3 + n)) (cong (coHomK-ptd (suc m) →∙_)
(Kn≃ΩKn+1∙))
(isOfHLevel↑∙ (suc n) m)
main : (n : ℕ) (a : S₊ (suc n)) (b : _)
→ fst (assocer-helpFun n m ∣ a ∣) b ≡ fst (assocer-helpFun2 n m ∣ a ∣) b
main zero a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid base)) k i ∣ ⌣ₖ b)
main (suc n) a b k i =
hcomp
(λ r → λ {(i = i0) → 0ₖ _
; (i = i1) → ∣ rCancel (merid north) r (~ k) ∣
; (k = i0) → Kn→ΩKn+1 _ (∣ a ∣ ⌣ₖ b) i
; (k = i1) → (Kn→ΩKn+1 _ ∣ a ∣ i) ⌣ₖ b})
(∣ compPath-filler (merid a) (sym (merid north)) k i ∣ ⌣ₖ b)
assoc-helper : (n m : ℕ) (x : coHomK (suc n)) (y : coHomK (suc m))
→ Kn→ΩKn+1 _ (x ⌣ₖ y) ≡ λ i → (Kn→ΩKn+1 _ x i) ⌣ₖ y
assoc-helper n m x y = funExt⁻ (cong fst (assocer-helpFun≡ n m x)) y
assoc-⌣ₖ· : (n m k : ℕ) → (x : coHomK (suc n)) → assocer n m k x ≡ assocer2 n m k x
assoc-⌣ₖ· n m k =
trElim (λ _ → isOfHLevelPath (3 + n)
(transport (λ i → isOfHLevel (3 + n)
(coHomK-ptd (suc m) →∙ (coHomK-ptd (suc k) →∙ coHomK-ptd (h (~ i)) ∙)))
(isOfHLevel↑∙∙ m k (suc n))) _ _)
λ a → →∙Homogeneous≡ (isHomogeneous→∙ (isHomogeneousKn _))
(funExt λ b → →∙Homogeneous≡ (isHomogeneousKn _)
(funExt (main n m k a b)))
where
h : (suc n) +' ((suc m) +' (suc k)) ≡ suc (suc (suc n + m + k))
h = cong (2 +_) (+-suc n (m + k)) ∙ λ i → suc (suc (suc (+-assoc n m k i)))
main : (n m k : ℕ) (a : S₊ (suc n)) (b : coHomK (suc m)) (c : coHomK (suc k))
→ ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡
(subst coHomK (λ i → +'-assoc (suc n) (suc m) (suc k) (~ i))
((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
main zero m k a b c = goal a ∙ sym (funExt⁻ t ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
where
t : subst coHomK (λ i → +'-assoc 1 (suc m) (suc k) (~ i)) ≡ idfun _
t = cong (subst coHomK) (isSetℕ _ _ (+'-assoc 1 (suc m) (suc k)) refl) ∙ funExt transportRefl
goal : (a : _) → ∣ a ∣ ⌣ₖ b ⌣ₖ c ≡ (∣ a ∣ ⌣ₖ b) ⌣ₖ c
goal base = refl
goal (loop i) j = assoc-helper m k b c j i
main (suc n) m k north b c = refl
main (suc n) m k south b c = refl
main (suc n) m k (merid a i) b c j = help2 j i
where
transpLem : (n m : ℕ) (p : n ≡ m) → subst coHomK p (0ₖ _) ≡ 0ₖ _
transpLem zero m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc zero) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem (suc (suc n)) m = J (λ m p → subst coHomK p (0ₖ _) ≡ 0ₖ _) refl
transpLem-refl : transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) ≡ refl
transpLem-refl = transportRefl refl
moveTransports : (n m : ℕ) (x : coHomK n) (p : n ≡ m) (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x))
moveTransports n m x =
J (λ m p → (q : (suc n) ≡ suc m)
→ PathP (λ i → transpLem _ _ q (~ i) ≡ transpLem _ _ q (~ i))
(Kn→ΩKn+1 _ (subst coHomK p x))
(cong (subst coHomK q) (Kn→ΩKn+1 _ x)))
λ q → transport (λ j → PathP (λ i → transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i)
≡ transpLem (suc n) (suc n) (isSetℕ _ _ refl q j) (~ i))
(Kn→ΩKn+1 _ (subst coHomK refl x))
(cong (subst coHomK (isSetℕ _ _ refl q j)) (Kn→ΩKn+1 _ x)))
(h2 n x)
where
h2 : (n : ℕ) (x : _)
→ PathP (λ i₁ →
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁) ≡
transpLem (suc n) (suc n) (λ _ → suc n) (~ i₁))
(Kn→ΩKn+1 n (subst coHomK (λ _ → n) x))
(λ i₁ → subst coHomK (λ _ → suc n) (Kn→ΩKn+1 n x i₁))
h2 zero x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transportRefl x j) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ x i)
h2 (suc n) x k i =
hcomp (λ j → λ {(i = i0) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (i = i1) → transportRefl (refl {x = 0ₖ _}) (~ j) k
; (k = i0) → Kn→ΩKn+1 _ (transport refl x) i
; (k = i1) → transportRefl (Kn→ΩKn+1 _ x i) (~ j)})
(Kn→ΩKn+1 _ (transportRefl x k) i)
finalTransp : (n : ℕ) (a : _) → Kn→ΩKn+1 _ (subst coHomK (λ i₁ → +'-assoc (suc n) (suc m) (suc k) (~ i₁)) ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
≡ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
finalTransp n a =
rUnit _
∙∙ (λ i → (λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ j))
∙∙ moveTransports _ _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c)
(sym (+'-assoc (suc n) (suc m) (suc k)))
(sym (+'-assoc (2 + n) (suc m) (suc k))) i
∙∙ λ j → transpLem (suc (suc (suc (suc (n + m + k)))))
(suc (suc n +' (suc m +' suc k)))
(λ i₃ → +'-assoc (2 + n) (suc m) (suc k) (~ i₃)) (i ∧ ~ j))
∙∙ (λ i → transportRefl refl i
∙∙ cong (subst coHomK (λ i₁ → +'-assoc (2 + n) (suc m) (suc k) (~ i₁))) (Kn→ΩKn+1 _ ((∣ a ∣ ⌣ₖ b) ⌣ₖ c))
∙∙ transportRefl refl i)
∙ sym (rUnit _)
help2 : cong (λ x → (∣ x ∣) ⌣ₖ (b ⌣ₖ c)) (merid a) ≡ cong (assoc2-sub (2 + n) (suc m) (suc k)) (cong (λ x → (∣ x ∣ ⌣ₖ b) ⌣ₖ c) (merid a))
help2 = ((λ r → Kn→ΩKn+1 _ (main n m k a b c r)))
∙∙ finalTransp n a
∙∙ λ r i → subst coHomK (sym (+'-assoc (2 + n) (suc m) (suc k))) (assoc-helper _ _ (∣ a ∣ ⌣ₖ b) c r i)
-- Some key distributivity lemmas
-Distₗ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ (-ₖ x) ⌣ₖ y
-Distₗ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ ((-ₖ x) ⌣ₖ y) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ x) ⌣ₖ y +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ ((-ₖ x) ⌣ₖ y)
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ (-ₖ x) ⌣ₖ y +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (0ₖ-⌣ₖ _ _ y)
∙ cong (_⌣ₖ y) (sym (lCancelₖ _ x))
∙∙ rightDistr-⌣ₖ _ _ (-ₖ x) x y
-Distᵣ : (n m : ℕ) (x : coHomK n) (y : coHomK m) → (-ₖ (x ⌣ₖ y)) ≡ x ⌣ₖ (-ₖ y)
-Distᵣ n m x y =
sym (rUnitₖ _ (-ₖ (x ⌣ₖ y)))
∙∙ cong ((-ₖ (x ⌣ₖ y)) +ₖ_) (sym (rCancelₖ _ (x ⌣ₖ y)))
∙∙ assocₖ _ (-ₖ (x ⌣ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y))
∙∙ cong (_-ₖ (x ⌣ₖ y)) help
∙∙ sym (assocₖ _ (x ⌣ₖ (-ₖ y)) (x ⌣ₖ y) (-ₖ (x ⌣ₖ y)))
∙∙ cong (x ⌣ₖ (-ₖ y) +ₖ_) (rCancelₖ _ (x ⌣ₖ y))
∙∙ rUnitₖ _ (x ⌣ₖ (-ₖ y))
where
help : (-ₖ (x ⌣ₖ y)) +ₖ (x ⌣ₖ y) ≡ x ⌣ₖ (-ₖ y) +ₖ (x ⌣ₖ y)
help = lCancelₖ _ _
∙∙ sym (⌣ₖ-0ₖ _ _ x)
∙∙ cong (x ⌣ₖ_) (sym (lCancelₖ _ y))
∙ leftDistr-⌣ₖ _ _ x (-ₖ y) y
assoc₀ : (m k : ℕ) (x : ℤ) (y : coHomK m) (z : coHomK k) → _⌣ₖ_{n = zero} x (y ⌣ₖ z) ≡ (_⌣ₖ_{n = zero} {m = m} x y) ⌣ₖ z
assoc₀ m k x y z = main x
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
mainPos : (x : ℕ) → _⌣ₖ_ {n = zero} (pos x) (y ⌣ₖ z) ≡ ((_⌣ₖ_ {n = zero} {m = m} (pos x) y) ⌣ₖ z)
mainPos zero = sym (0ₖ-⌣ₖ _ _ z) ∙ cong (_⌣ₖ z) (sym (0ₖ-⌣ₖ _ _ y))
mainPos (suc n) =
cong (y ⌣ₖ z +ₖ_) (mainPos n)
∙∙ sym (rightDistr-⌣ₖ _ _ y (_⌣ₖ_ {n = zero} {m = m} (pos n) y) z)
∙∙ (λ i → (y +ₖ (_⌣ₖ_ {n = zero} {m = m} (pos n) y)) ⌣ₖ z)
main : (x : ℤ) → x ⌣ₖ y ⌣ₖ z ≡ ((_⌣ₖ_ {n = zero} {m = m} x y) ⌣ₖ z)
main (pos n) = mainPos n
main (negsuc n) =
(λ i → _⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) (y ⌣ₖ z))
∙∙ sym (-Distₗ zero _ (pos (suc n)) (y ⌣ₖ z))
∙ cong (-ₖ_) (mainPos (suc n))
∙∙ -Distₗ _ _ (pos (suc n) ⌣ₖ y) z
∙∙ cong (_⌣ₖ z) ((-Distₗ zero _ (pos (suc n)) y))
∙∙ λ i → (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 (~ i)) y) ⌣ₖ z
assoc-⌣ₖ : (n m k : ℕ) (x : coHomK n) (y : coHomK m) (z : coHomK k)
→ x ⌣ₖ y ⌣ₖ z ≡ subst coHomK (sym (+'-assoc n m k)) ((x ⌣ₖ y) ⌣ₖ z)
assoc-⌣ₖ zero m k x y z = assoc₀ _ _ x y z ∙ sym (funExt⁻ h ((x ⌣ₖ y) ⌣ₖ z))
where
h : subst coHomK (sym (+'-assoc zero m k)) ≡ idfun _
h = cong (subst coHomK) (isSetℕ _ _ _ refl) ∙ funExt transportRefl
assoc-⌣ₖ (suc n) zero k x y z =
help y
∙∙ sym (transportRefl ((x ⌣ₖ y) ⌣ₖ z))
∙∙ λ i → transport (λ j → coHomK ((isSetℕ _ _ ((sym (+'-assoc (suc n) zero k))) refl (~ i) j)))
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
where
helpPos : (y : ℕ) → x ⌣ₖ (_⌣ₖ_ {n = zero} (pos y) z) ≡
((_⌣ₖ_ {m = zero} x (pos y)) ⌣ₖ z)
helpPos zero =
(⌣ₖ-0ₖ _ _ x)
∙∙ (sym (0ₖ-⌣ₖ _ _ z))
∙∙ cong (_⌣ₖ z) (sym (⌣ₖ-0ₖ _ _ x))
helpPos (suc y) =
leftDistr-⌣ₖ _ _ x z (_⌣ₖ_{n = zero} (pos y) z)
∙∙ cong ((x ⌣ₖ z) +ₖ_) (helpPos y)
∙∙ sym (rightDistr-⌣ₖ _ _ x (_⌣ₖ_{n = zero} (pos y) x) z)
help : (y : ℤ) → x ⌣ₖ (_⌣ₖ_ {n = zero} y z) ≡
((_⌣ₖ_ {m = zero} x y) ⌣ₖ z)
help (pos n) = helpPos n
help (negsuc n) =
(λ i → x ⌣ₖ (_⌣ₖ_ {n = zero} (+ℤ-comm (negsuc n) 0 i) z))
∙∙ cong (x ⌣ₖ_) (sym (-Distₗ zero _ (pos (suc n)) z))
∙∙ sym (-Distᵣ _ _ x _)
∙∙ cong -ₖ_ (helpPos (suc n))
∙∙ -Distₗ _ _ _ z
∙∙ cong (_⌣ₖ z) (-Distᵣ _ zero x (pos (suc n)))
∙∙ λ i → (_⌣ₖ_ {m = zero} x (+ℤ-comm (negsuc n) 0 (~ i))) ⌣ₖ z
assoc-⌣ₖ (suc n) (suc m) zero x y z =
(assoc-⌣ₖ (suc n) zero (suc m) x z y)
∙∙ cong (subst coHomK (sym (+'-assoc (suc n) zero (suc m))))
(sym (assoc₀ _ _ z x y))
∙∙ (funExt⁻ (sym h) (_⌣ₖ_ {n = zero} z (x ⌣ₖ y)))
where
h : subst coHomK (sym (+'-assoc (suc n) (suc m) zero))
≡ subst coHomK (λ i → +'-assoc (suc n) zero (suc m) (~ i))
h = cong (subst coHomK) (isSetℕ _ _ _ _)
assoc-⌣ₖ (suc n) (suc m) (suc k) x y z =
funExt⁻ (cong fst (funExt⁻ (cong fst (assoc-⌣ₖ· n m k x)) y)) z
-- Ring laws for ⌣
module _ {A : Type ℓ} (n m : ℕ) where
⌣-0ₕ : (f : coHom n A) → (f ⌣ 0ₕ m) ≡ 0ₕ _
⌣-0ₕ = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
0ₕ-⌣ : (f : coHom m A) → (0ₕ n ⌣ f) ≡ 0ₕ _
0ₕ-⌣ = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ n m (f x))
leftDistr-⌣ : (f : coHom n A) (g h : coHom m A)
→ f ⌣ (g +ₕ h) ≡ f ⌣ g +ₕ f ⌣ h
leftDistr-⌣ =
sElim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ g h → cong ∣_∣₂ (funExt λ x → leftDistr-⌣ₖ n m (f x) (g x) (h x))
rightDistr-⌣ : (g h : coHom n A) (f : coHom m A) → (g +ₕ h) ⌣ f ≡ g ⌣ f +ₕ h ⌣ f
rightDistr-⌣ =
sElim2 (λ _ _ → isSetΠ (λ _ → isOfHLevelPath 2 squash₂ _ _))
λ g h → sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rightDistr-⌣ₖ n m (g x) (h x) (f x))
assoc-⌣ : (l : ℕ) (f : coHom n A) (g : coHom m A) (h : coHom l A)
→ f ⌣ g ⌣ h ≡ subst (λ x → coHom x A) (sym (+'-assoc n m l)) ((f ⌣ g) ⌣ h)
assoc-⌣ l =
sElim (λ _ → isSetΠ2 λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 squash₂ _ _)
λ g → sElim (λ _ → isOfHLevelPath 2 squash₂ _ _) λ h →
cong ∣_∣₂ ((funExt (λ x → assoc-⌣ₖ n m l (f x) (g x) (h x)
∙ cong (subst coHomK (sym (+'-assoc n m l)))
λ i → (f (transportRefl x (~ i)) ⌣ₖ g (transportRefl x (~ i)))
⌣ₖ (h (transportRefl x (~ i))))))
-- Additive unit(s)
0⌣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ x ⌣ (0ₕ m) ≡ 0ₕ _
0⌣ n m = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → ⌣ₖ-0ₖ n m (f x))
⌣0 : ∀ {ℓ} {A : Type ℓ} (n m : ℕ) (x : coHom n A)
→ (0ₕ m) ⌣ x ≡ 0ₕ _
⌣0 n m = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → 0ₖ-⌣ₖ m n (f x))
-- Multiplicative unit
1⌣ : ∀ {ℓ} {A : Type ℓ} → coHom 0 A
1⌣ = ∣ (λ _ → 1) ∣₂
private
n+'0 : (n : ℕ) → n +' 0 ≡ n
n+'0 zero = refl
n+'0 (suc n) = refl
lUnit⌣ₖ : (n : ℕ) (x : coHomK n) → _⌣ₖ_ {n = 0} (pos 1) x ≡ x
lUnit⌣ₖ zero = λ _ → refl
lUnit⌣ₖ (suc n) x = rUnitₖ _ x
lUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ x ⌣ 1⌣ ≡ subst (λ n → coHom n A) (sym (n+'0 n)) x
lUnit⌣ zero = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → comm-·₀ (f x) (pos 1))) ∙ sym (transportRefl ∣ f ∣₂)
lUnit⌣ (suc n) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt (λ x → cong (f x +ₖ_) (0ₖ-⌣ₖ zero _ (f x)) ∙ rUnitₖ _ (f x)))
∙ sym (transportRefl ∣ f ∣₂)
rUnit⌣ : ∀ {ℓ} {A : Type ℓ} (n : ℕ) (x : coHom n A)
→ 1⌣ ⌣ x ≡ x
rUnit⌣ zero = sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → refl
rUnit⌣ (suc n) =
sElim (λ _ → isOfHLevelPath 2 squash₂ _ _)
λ f → cong ∣_∣₂ (funExt λ x → rUnitₖ _ (f x))
-ₕDistᵣ : ∀ {ℓ} {A : Type ℓ} (n m : ℕ)
(x : coHom n A) (y : coHom m A) → (-ₕ (x ⌣ y)) ≡ x ⌣ (-ₕ y)
-ₕDistᵣ n m =
sElim2 (λ _ _ → isOfHLevelPath 2 squash₂ _ _)
λ f g → cong ∣_∣₂ (funExt λ x → -Distᵣ n m (f x) (g x))
-- TODO : Graded ring structure
| {
"alphanum_fraction": 0.4787601244,
"avg_line_length": 43.60804769,
"ext": "agda",
"hexsha": "c0f215de706c16344201fe1247fc85d56e2f5791",
"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": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ecavallo/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/RingStructure/RingLaws.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"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": "ecavallo/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/RingStructure/RingLaws.agda",
"max_line_length": 143,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b1d105aeeab1ba9888394c6a919b99a476390b7b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ecavallo/cubical",
"max_stars_repo_path": "Cubical/ZCohomology/RingStructure/RingLaws.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 14970,
"size": 29261
} |
data Nat : Set where
zero : Nat
suc : Nat → Nat
interleaved mutual
data Even : Nat → Set
data Odd : Nat → Set
-- base cases: 0 is Even, 1 is Odd
constructor
even-zero : Even zero
odd-one : Odd (suc zero)
-- step case: suc switches the even/odd-ness
constructor
even-suc : ∀ {n} → Odd n → Even (suc n)
odd-suc : ∀ {n} → Even n → Odd (suc n)
| {
"alphanum_fraction": 0.5868421053,
"avg_line_length": 20,
"ext": "agda",
"hexsha": "9a2b124bed86aa312bef0696f2fd8ec2629d76fc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue2858-EvenOdd.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue2858-EvenOdd.agda",
"max_line_length": 46,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2858-EvenOdd.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 132,
"size": 380
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import homotopy.Bouquet
open import homotopy.PushoutSplit
open import homotopy.DisjointlyPointedSet
open import cw.CW
module cw.WedgeOfCells {i} {n} (skel : Skeleton {i} (S n)) where
Xₙ/Xₙ₋₁ : Type i
Xₙ/Xₙ₋₁ = Cofiber (cw-incl-last skel)
⊙Xₙ/Xₙ₋₁ : Ptd i
⊙Xₙ/Xₙ₋₁ = ⊙[ Xₙ/Xₙ₋₁ , cfbase ]
private
cells : Type i
cells = cells-last skel
attaching : cells → (Sphere n → ⟦ skel ⟧₋₁)
attaching = attaching-last skel
{- this is also a cofiber -}
BigWedgeSusp : Type i
BigWedgeSusp = Attached {A = ⊤} {B = cells} {C = Sphere n} (λ _ _ → unit)
⊙BigWedgeSusp : Ptd i
⊙BigWedgeSusp = ⊙[ BigWedgeSusp , cfbase ]
private
module SphereToBigWedgeSusp (a : cells) = SuspRec {A = Sphere n}
(cfbase :> BigWedgeSusp) (cfcod a) (λ s → cfglue (a , s))
module BouquetToBigWedgeSusp =
BigWedgeRec {A = cells} {X = Bouquet-family cells (S n)}
cfbase SphereToBigWedgeSusp.f (λ _ → idp)
module BigWedgeSuspEquivQuotient = PushoutLSplit (uncurry attaching) (λ _ → unit) fst
Bouquet-to-Xₙ/Xₙ₋₁ : Bouquet cells (S n) → Xₙ/Xₙ₋₁
Bouquet-to-Xₙ/Xₙ₋₁ = BigWedgeSuspEquivQuotient.split ∘ BouquetToBigWedgeSusp.f
abstract
Bouquet-to-Xₙ/Xₙ₋₁-in-merid-β : ∀ (a : cells) x
→ ap (Bouquet-to-Xₙ/Xₙ₋₁ ∘ bwin a) (merid x)
== cfglue (attaching a x) ∙' ap cfcod (spoke a x)
Bouquet-to-Xₙ/Xₙ₋₁-in-merid-β a x =
ap-∘ BigWedgeSuspEquivQuotient.split (SphereToBigWedgeSusp.f a) (merid x)
∙ ap (ap BigWedgeSuspEquivQuotient.split) (SphereToBigWedgeSusp.merid-β a x)
∙ BigWedgeSuspEquivQuotient.split-glue-β (a , x)
private
Bouquet-to-BigWedgeSusp-is-equiv : is-equiv BouquetToBigWedgeSusp.f
Bouquet-to-BigWedgeSusp-is-equiv = is-eq to from to-from from-to
where
to = BouquetToBigWedgeSusp.f
module From = AttachedRec {A = ⊤}
(λ _ → bwbase :> Bouquet cells (S n))
(λ a → bwin a south) (λ a s → bwglue a ∙ ap (bwin a) (merid s))
from = From.f
abstract
from-to : ∀ b → from (to b) == b
from-to = BigWedge-elim
idp
(λ a → Susp-elim (bwglue a) idp
(λ s → ↓-='-from-square $
( ap-∘ from (SphereToBigWedgeSusp.f a) (merid s)
∙ ap (ap from) (SphereToBigWedgeSusp.merid-β a s)
∙ From.spoke-β a s)
∙v⊡ (tl-square (bwglue a) ⊡h vid-square)))
(λ a → ↓-∘=idf-from-square from to $
ap (ap from) (BouquetToBigWedgeSusp.glue-β a) ∙v⊡ br-square (bwglue a))
to-from : ∀ c → to (from c) == c
to-from = Attached-elim
(λ _ → idp) (λ a → idp)
(λ a s → ↓-∘=idf-in' to from $
ap (ap to) (From.spoke-β a s)
∙ ap-∙ to (bwglue a) (ap (bwin a) (merid s))
∙ ap2 _∙_ (BouquetToBigWedgeSusp.glue-β a)
( ∘-ap to (bwin a) (merid s)
∙ SphereToBigWedgeSusp.merid-β a s))
Bouquet-equiv-BigWedgeSusp : Bouquet cells (S n) ≃ BigWedgeSusp
Bouquet-equiv-BigWedgeSusp = BouquetToBigWedgeSusp.f , Bouquet-to-BigWedgeSusp-is-equiv
Bouquet-equiv-Xₙ/Xₙ₋₁ : Bouquet cells (S n) ≃ Xₙ/Xₙ₋₁
Bouquet-equiv-Xₙ/Xₙ₋₁ = BigWedgeSuspEquivQuotient.split-equiv ∘e Bouquet-equiv-BigWedgeSusp
Bouquet-⊙equiv-Xₙ/Xₙ₋₁ : ⊙Bouquet cells (S n) ⊙≃ ⊙Xₙ/Xₙ₋₁
Bouquet-⊙equiv-Xₙ/Xₙ₋₁ = ≃-to-⊙≃ Bouquet-equiv-Xₙ/Xₙ₋₁ idp
| {
"alphanum_fraction": 0.6254170458,
"avg_line_length": 34.7052631579,
"ext": "agda",
"hexsha": "0f595159cb8882a9ecb62028e2b428639d7db3c5",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/cw/WedgeOfCells.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/cw/WedgeOfCells.agda",
"max_line_length": 91,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/cw/WedgeOfCells.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-20T13:54:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T16:23:23.000Z",
"num_tokens": 1349,
"size": 3297
} |
{-# OPTIONS --without-K #-}
module hott.level.closure where
open import hott.level.closure.core public
open import hott.level.closure.lift public
open import hott.level.closure.extra public
| {
"alphanum_fraction": 0.7905759162,
"avg_line_length": 27.2857142857,
"ext": "agda",
"hexsha": "490cd3e68638ae54f270594b3c5202fe8708629f",
"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": "hott/level/closure.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/level/closure.agda",
"max_line_length": 43,
"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/level/closure.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": 40,
"size": 191
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Refinement type: a value together with an erased proof.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Refinement where
open import Level
open import Data.Erased as Erased using (Erased)
open import Function.Base
open import Relation.Unary
private
variable
a b p q : Level
A : Set a
B : Set b
record Refinement {a p} (A : Set a) (P : A → Set p) : Set (a ⊔ p) where
constructor _,_
field value : A
proof : Erased (P value)
open Refinement public
-- The syntax declaration below is meant to mimick set comprehension.
-- It is attached to Refinement-syntax, to make it easy to import
-- Data.Refinement without the special syntax.
infix 2 Refinement-syntax
Refinement-syntax = Refinement
syntax Refinement-syntax A (λ x → P) = [ x ∈ A ∣ P ]
module _ {P : A → Set p} {Q : B → Set q} where
map : (f : A → B) → ∀[ P ⇒ f ⊢ Q ] →
[ a ∈ A ∣ P a ] → [ b ∈ B ∣ Q b ]
map f prf (a , p) = f a , Erased.map prf p
module _ {P : A → Set p} {Q : A → Set q} where
refine : ∀[ P ⇒ Q ] → [ a ∈ A ∣ P a ] → [ a ∈ A ∣ Q a ]
refine = map id
| {
"alphanum_fraction": 0.5431309904,
"avg_line_length": 27.2173913043,
"ext": "agda",
"hexsha": "3cabaea29bd27da2fad7ce0651664df497f8224f",
"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/Refinement.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/Refinement.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Refinement.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": 361,
"size": 1252
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Prelude
open import LibraBFT.Impl.Consensus.Types
-- This module defines the LBFT monad used by our (fake/simple,
-- for now) "implementation", along with some utility functions
-- to facilitate reasoning about it.
module LibraBFT.Impl.Util.Util where
open import Optics.All
open import LibraBFT.Impl.Util.RWST ℓ-RoundManager public
----------------
-- LBFT Monad --
----------------
-- Global 'LBFT'; works over the whole state.
LBFT : Set → Set
LBFT = RWST Unit Output RoundManager
LBFT-run : ∀ {A} → LBFT A → RoundManager → (A × RoundManager × List Output)
LBFT-run m = RWST-run m unit
LBFT-post : ∀ {A} → LBFT A → RoundManager → RoundManager
LBFT-post m rm = proj₁ (proj₂ (LBFT-run m rm))
LBFT-outs : ∀ {A} → LBFT A → RoundManager → List Output
LBFT-outs m rm = proj₂ (proj₂ (LBFT-run m rm))
-- Local 'LBFT' monad; which operates only over the part of
-- the state that /depends/ on the ec; not the part
-- of the state that /defines/ the ec.
--
-- This is very convenient to define functions that
-- do not alter the ec.
LBFT-ec : EpochConfig → Set → Set
LBFT-ec ec = RWST Unit Output (RoundManagerWithEC ec)
-- Lifting a function that does not alter the pieces that
-- define the epoch config is easy
liftEC : {A : Set}(f : ∀ ec → LBFT-ec ec A) → LBFT A
liftEC f = rwst λ _ st
→ let ec = α-EC (₋rmEC st , ₋rmEC-correct st)
res , stec' , acts = RWST-run (f ec) unit (₋rmWithEC st)
in res , record st { ₋rmWithEC = stec' } , acts
-- Type that captures a proof that a computation in the LBFT monad
-- satisfies a given contract.
LBFT-Contract : ∀{A} → LBFT A
→ (RoundManager → Set)
→ (RoundManager → Set)
→ Set
LBFT-Contract f Pre Post =
∀ rm → Pre rm × Post (proj₁ (proj₂ (RWST-run f unit rm)))
-- Because we made RWST work for different level State types, but broke use
-- and modify' because Lens does not support different levels, we define use
-- and modify' here for RoundManager. This will work as long as we can keep
-- RoundManager in Set. If we ever need to make RoundManager at some higher
-- Level, we will have to consider making Lens level-agnostic. Preliminary
-- exploration by @cwjnkins showed this to be somewhat painful in particular
-- around composition, so we are not pursuing it for now.
use : ∀ {A} → Lens RoundManager A → LBFT A
use f = RWST-bind get (RWST-return ∘ (_^∙ f))
modify' : ∀ {A} → Lens RoundManager A → A → LBFT Unit
modify' l val = modify λ x → x [ l := val ]
| {
"alphanum_fraction": 0.6576828841,
"avg_line_length": 39.1369863014,
"ext": "agda",
"hexsha": "98da3fcbc18763504bd5de70743118f8427a40f6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Impl/Util/Util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Impl/Util/Util.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Impl/Util/Util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 839,
"size": 2857
} |
{-# OPTIONS --cubical --cumulativity #-}
module leibniz-equality where
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Function
open import Cubical.Data.Equality
open import equalities
open import leibniz
open Leibniz
liftIso : ∀ {a b} {A : Type a} {B : Type b} → Iso {a} {b} A B → Iso {ℓ-max a b} {ℓ-max a b} A B
liftIso {a} f = iso fun inv (λ x i → rightInv x i) (λ x i → leftInv x i)
where open Iso f
module FinalEquality {A : Set} where
open MainResult A
≐≅≡ : ∀ {a b} → Iso (a ≐ b) (a ≡p b)
≐≅≡ = iso j i (ptoc ∘ ji) (ptoc ∘ ij)
≐≡≡' : ∀ {a b} → (a ≐ b) ≡c (a ≡p b)
≐≡≡' = let lifted = liftIso ≐≅≡ in isoToPath lifted
≐≡≡ : _≐_ {A} ≡c _≡p_
≐≡≡ i x y = ≐≡≡' {x} {y} i
open IsEquality
open equalities
instance
≐-IsEquality : IsEquality {A = A} _≐_
≐-IsEquality = eq λ {x} {y} → ≐≡≡' ∙ λ i → ≡p-IsEquality {ℓ-zero} .≣-≡-≡ {x} {y} i
| {
"alphanum_fraction": 0.5813953488,
"avg_line_length": 25.8,
"ext": "agda",
"hexsha": "8d15692bdab2bb923376b3e1d939bc360275bce5",
"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": "e1104012d85d2072318656f6c6d31acff75c9460",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/Equality",
"max_forks_repo_path": "leibniz-equality.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/Equality",
"max_issues_repo_path": "leibniz-equality.agda",
"max_line_length": 95,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e1104012d85d2072318656f6c6d31acff75c9460",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/Equality",
"max_stars_repo_path": "leibniz-equality.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-01T06:04:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-01T06:04:21.000Z",
"num_tokens": 414,
"size": 903
} |
{-# OPTIONS --no-positivity-check #-}
module IIDr where
open import LF
open import IID
OPr : (I : Set) -> Set1
OPr I = I -> OP I One
rArgs : {I : Set}(γ : OPr I)(U : I -> Set)(i : I) -> Set
rArgs γ U i = Args (γ i) U
-- The type of IIDrs
data Ur {I : Set}(γ : OPr I)(i : I) : Set where
intror : rArgs γ (Ur γ) i -> Ur γ i
-- The elimination rule
elim-Ur : {I : Set}(γ : OPr I)(C : (i : I) -> Ur γ i -> Set) ->
((i : I)(a : rArgs γ (Ur γ) i) -> IndHyp (γ i) (Ur γ) C a -> C i (intror a)) ->
(i : I)(u : Ur γ i) -> C i u
elim-Ur γ C m i (intror a) = m i a (induction (γ i) (Ur γ) C (elim-Ur γ C m) a)
-- Large elimination
elim-Ur₁ : {I : Set}(γ : OPr I)(C : (i : I) -> Ur γ i -> Set1) ->
((i : I)(a : rArgs γ (Ur γ) i) -> IndHyp₁ (γ i) (Ur γ) C a -> C i (intror a)) ->
(i : I)(u : Ur γ i) -> C i u
elim-Ur₁ γ C m i (intror a) = m i a (induction₁ (γ i) (Ur γ) C (elim-Ur₁ γ C m) a)
| {
"alphanum_fraction": 0.5033259424,
"avg_line_length": 31.1034482759,
"ext": "agda",
"hexsha": "be3cbd8b730494a8dcbb82a9874a50ba46de3969",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/iird/IIDr.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/iird/IIDr.agda",
"max_line_length": 84,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/iird/IIDr.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": 394,
"size": 902
} |
-- Andreas, 2019-01-20, re #2597.
-- Undocumented language change introduced by patch 31a5982f38 (released in 2.5.3):
-- Hiding of argument now treated as part of name when inserting implicits.
-- Patch introduced in src/full/Agda/TypeChecking/Implicit.hs
--
-- ... | x == y && sameHiding hidingx a = impInsert $ reverse hs
-- | x == y && sameHiding hidingx a = BadImplicits
--
-- Intended was most likely
-- | x == y && not (sameHiding hidingx a) = BadImplicits
--
-- The patch makes this code legal:
test : {{X : Set}} {X : Set} → Set
test {X = X} = X
-- Succeeds in 2.5.3.
-- Fails in 2.5.2 with error:
-- Unexpected implicit argument
-- when checking that the clause test {X = X} = X has type
-- {{X : Set}} {X = X₁ : Set} → Set
| {
"alphanum_fraction": 0.6465053763,
"avg_line_length": 32.347826087,
"ext": "agda",
"hexsha": "54918f1712fae7b8422358386c8216504f5305ca",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/HidingIsPartOfArgumentNameSince2-5-3.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/HidingIsPartOfArgumentNameSince2-5-3.agda",
"max_line_length": 83,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/HidingIsPartOfArgumentNameSince2-5-3.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 240,
"size": 744
} |
{-# OPTIONS --without-K #-}
module NTypes.Coproduct where
open import NTypes
open import PathOperations
open import PathStructure.Coproduct
open import Types
⊎-isSet : ∀ {A : Set} {B : Set} →
isSet A → isSet B → isSet (A ⊎ B)
⊎-isSet {A = A} {B = B} A-set B-set x y p q =
case (λ x → (y : A ⊎ B) (p q : x ≡ y) → p ≡ q)
(λ a y p q → case
(λ y → (p q : inl a ≡ y) → p ≡ q)
(λ a′ p q
→ split-eq p ⁻¹
· ap (ap inl)
(A-set _ _
(lower (tr (F (inl a)) p (lift refl)))
(lower (tr (F (inl a)) q (lift refl)))
)
· split-eq q
)
(λ _ p q → 0-elim
(lower (split-path p)))
y p q)
(λ b y p q → case
(λ y → (p q : inr b ≡ y) → p ≡ q)
(λ _ p q → 0-elim
(lower (split-path p)))
(λ b′ p q
→ split-eq p ⁻¹
· ap (ap inr)
(B-set _ _
(lower (tr (F (inr b)) p (lift refl)))
(lower (tr (F (inr b)) q (lift refl)))
)
· split-eq q
)
y p q)
x y p q
where
split-eq : {x y : A ⊎ B} → _
split-eq {x = x} {y = y} =
π₂ (π₂ (π₂ (split-merge-eq {x = x} {y = y})))
| {
"alphanum_fraction": 0.4440465533,
"avg_line_length": 24.2826086957,
"ext": "agda",
"hexsha": "b4120f96cc779f36814a12aedc2f87eeb3553842",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/NTypes/Coproduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/NTypes/Coproduct.agda",
"max_line_length": 49,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/NTypes/Coproduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 463,
"size": 1117
} |
------------------------------------------------------------------------
-- Some results that could not be placed in Function-universe because
-- they make use of --sized-types
------------------------------------------------------------------------
{-# OPTIONS --without-K --sized-types #-}
open import Equality
module Function-universe.Size
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open Derived-definitions-and-properties eq
open import Prelude
open import Prelude.Size
import Bijection eq as B
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq
private
variable
S : Size-universe
p q : Level
P : S → Type p
k : Kind
-- Π-types with something from the size universe in the domain can be
-- expressed using something from Type in the domain.
Π-size-≃ :
((i : S) → P i) ≃
((i : S in-type) → P (size i))
Π-size-≃ = Eq.↔→≃
(λ p i → p (size i))
(λ p i → p (record { size = i }))
refl
refl
-- Implicit Π-types with something from the size universe in the
-- domain can be expressed using something from Type in the domain.
implicit-Π-size-≃ :
({i : S} → P i) ≃
({i : S in-type} → P (size i))
implicit-Π-size-≃ = Eq.↔→≃
(λ p {i} → p {size i})
(λ p {i} → p {record { size = i }})
refl
refl
-- Implicit Π-types with something from the size universe in the
-- domain are equivalent to explicit Π-types.
implicit-Π-size-≃-Π-size :
({i : S} → P i) ≃ ((i : S) → P i)
implicit-Π-size-≃-Π-size {P = P} =
(∀ {i} → P i) ↔⟨ implicit-Π-size-≃ ⟩
(∀ {i} → P (size i)) ↔⟨ B.implicit-Π↔Π ⟩
(∀ i → P (size i)) ↔⟨ inverse Π-size-≃ ⟩□
(∀ i → P i) □
-- A preservation lemma for Π-types with something from the size
-- universe in the domain.
∀-size-cong :
{P : S → Type p} {Q : S → Type q} →
Extensionality? k lzero (p ⊔ q) →
(∀ i → P i ↝[ k ] Q i) →
(∀ i → P i) ↝[ k ] (∀ i → Q i)
∀-size-cong {P = P} {Q = Q} ext P↝Q =
(∀ i → P i) ↔⟨ Π-size-≃ ⟩
(∀ i → P (size i)) ↝⟨ ∀-cong ext (λ i → P↝Q (size i)) ⟩
(∀ i → Q (size i)) ↔⟨ inverse Π-size-≃ ⟩□
(∀ i → Q i) □
-- A preservation lemma for implicit Π-types with something from the
-- size universe in the domain.
implicit-∀-size-cong :
{P : S → Type p} {Q : S → Type q} →
Extensionality? k lzero (p ⊔ q) →
(∀ {i} → P (size i) ↝[ k ] Q (size i)) →
(∀ {i} → P i) ↝[ k ] (∀ {i} → Q i)
implicit-∀-size-cong {P = P} {Q = Q} ext P↝Q =
(∀ {i} → P i) ↔⟨ implicit-Π-size-≃ ⟩
(∀ {i} → P (size i)) ↝⟨ implicit-∀-cong ext P↝Q ⟩
(∀ {i} → Q (size i)) ↔⟨ inverse implicit-Π-size-≃ ⟩□
(∀ {i} → Q i) □
| {
"alphanum_fraction": 0.5201981707,
"avg_line_length": 28.8351648352,
"ext": "agda",
"hexsha": "790a2e31138a4234b9268309b7086d569a3f6e20",
"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/Function-universe/Size.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/Function-universe/Size.agda",
"max_line_length": 72,
"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/Function-universe/Size.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": 991,
"size": 2624
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Impl.OBM.Crypto hiding (verify)
open import LibraBFT.Impl.OBM.Logging.Logging
import LibraBFT.Impl.Types.ValidatorVerifier as ValidatorVerifier
open import LibraBFT.ImplShared.Consensus.Types
open import Optics.All
open import Util.KVMap as Map
open import Util.PKCS hiding (verify)
open import Util.Prelude
module LibraBFT.Impl.Consensus.ConsensusTypes.TimeoutCertificate where
verify : TimeoutCertificate → ValidatorVerifier → Either ErrLog Unit
verify self validator =
withErrCtx' ("TimeoutCertificate" ∷ "verify" ∷ "failed" ∷ [])
(ValidatorVerifier.verifyAggregatedStructSignature
validator (self ^∙ tcTimeout) (self ^∙ tcSignatures))
verify' : Maybe TimeoutCertificate → ValidatorVerifier → Either ErrLog Unit
verify' mtc validator = maybeSMP (pure mtc) unit (` verify ` validator)
-- HC-TODO : refactor this and LedgerInfoWithSignatures
addSignature : Author → Signature → TimeoutCertificate → TimeoutCertificate
addSignature a s tc =
case Map.lookup a (tc ^∙ tcSignatures) of λ where
(just _) → tc
nothing → tc & tcSignatures ∙~ Map.kvm-insert-Haskell a s (tc ^∙ tcSignatures)
| {
"alphanum_fraction": 0.737534626,
"avg_line_length": 43.7575757576,
"ext": "agda",
"hexsha": "44f9f1db10bee91d6df81ddf6b16649cff454866",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/TimeoutCertificate.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/TimeoutCertificate.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/ConsensusTypes/TimeoutCertificate.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 360,
"size": 1444
} |
module Mystuff where
-- open import Axiom.Extensionality.Propositional as AEP
open import Categories.Category.Cartesian.Bundle
open import Categories.Category.CartesianClosed.Canonical
open import Categories.Category.Core
open import Categories.Category.Slice
-- open import Categories.Functor
open import Categories.Category.BinaryProducts
-- open import Categories.Morphism
open import Categories.Object.Exponential -- 𝒞 hiding (repack)
open import Data.Product
open import Function using (const)
open import Level
open import Relation.Binary.Core using (Rel)
open import Relation.Binary.PropositionalEquality
open Relation.Binary.PropositionalEquality.≡-Reasoning
private
variable
a b c d e : Level
-- so painful
_⋆_ : ∀ {A : Set a} {B : A → Set b} {C : {x : A} → B x → Set c} →
(∀ {x} (y : B x) → C y) → (g : (x : A) → B x) →
((x : A) → C (g x))
f ⋆ g = λ x → f (g x)
simple : Category (suc zero) zero zero
simple =
record
-- structure
{ Obj = Set × Set
; _⇒_ = _⇒_
; _≈_ = _≡_
; id = (λ z → z) , proj₁
; _∘_ = _∘_
-- properties
; assoc = refl
; sym-assoc = refl
; identityˡ = refl
; identityʳ = refl
; identity² = refl
-- whew, they're all trivial!
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = ∘-resp
}
where
_⇒_ : Rel (Set × Set) zero
(i , x) ⇒ (j , y) = (i → j) × (x × i → y)
_∘_ : {A B C : Set × Set} → B ⇒ C → A ⇒ B → A ⇒ C
_∘_ {i , x} {j , y} {_} (u , f) (v , g) =
(λ t → u (v t)) , λ t → f (g t , v (proj₂ t))
∘-resp :
{A B C : Set × Set} {f h : B ⇒ C} {g i : A ⇒ B} →
--------------------------------------------------
f ≡ h → g ≡ i → (f ∘ g) ≡ (h ∘ i)
∘-resp {A} {B} {C} {f} {h} {g} {i} x y =
trans (cong (λ t → t ∘ g) x) (cong (λ t → h ∘ t) y)
data t : Set where
⊤ : t
!-unique-lemma : ∀ (x : t) → ⊤ ≡ x
!-unique-lemma ⊤ = refl
postulate
-- I'm lazy.
respSetC : {A B C : Set} {f h : B → C} {g i : A → B} →
f ≡ h →
g ≡ i →
(λ a → f (g a)) ≡ (λ a → h (i a))
extensionality : ∀ {A B : Set} {f g : A → B} →
(∀ (x : A) → f x ≡ g x) →
f ≡ g
-- I need the category of Sets...
SetC : Category (suc zero) zero zero
SetC =
record
{ Obj = Set
; _⇒_ = λ x y → x → y
; _≈_ = _≡_
; id = λ x → x
; _∘_ = λ f g a → f (g a)
; assoc = refl
; sym-assoc = refl
; identityˡ = refl
; identityʳ = refl
; identity² = refl
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = respSetC
}
_·_ : {I : Set} {A B C : Set} → (B × I → C) → (A × I → B) → A × I → C
_·_ {I} f g (x , i) = f (g(x , i) , i)
fiber-of-simple : {I : Set} → Category (suc zero) zero zero
fiber-of-simple {I} =
record
{ Obj = Set
; _⇒_ = λ X Y → X × I → Y
; _≈_ = _≡_
; id = proj₁
; _∘_ = _·_ -- this is the Kleisli composition
; assoc = refl
; sym-assoc = refl
; identityˡ = refl
; identityʳ = refl
; identity² = refl
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = rresp
}
where
rresp : {A B C : Set} {f h : B × I → C} {g i : A × I → B} → f ≡ h → g ≡ i → (f · g) ≡ (h · i)
rresp {A} {B} {C} {f} {h} {g} {i} x y = trans (cong (λ t → t · g) x) (cong (_·_ h) y)
-- each fiber of a simple fibration is cartesian
fiber-of-simple-cart : ∀ {I : Set} → CartesianCategory (suc zero) zero zero
fiber-of-simple-cart {I} =
record
{ U = fiber-of-simple {I}
; cartesian =
record
{ terminal =
record { ⊤ = t
; ⊤-is-terminal =
record
{ ! = const ⊤
; !-unique =
λ f → extensionality (λ x → !-unique-lemma (f x))
}
}
; products =
record
{ product = λ {A} {B} →
record
{ A×B = A × B
; π₁ = λ x → proj₁ (proj₁ x)
; π₂ = λ x → proj₂ (proj₁ x)
; ⟨_,_⟩ = λ f g t → f t , g t
; project₁ = refl
; project₂ = refl
; unique = λ {refl refl → refl}
} } } }
-- but also the total category is cartesian.
simple-cart : CartesianCategory (suc zero) zero zero
simple-cart = record
{ U = simple
; cartesian = record
{ terminal = record { ⊤ = t , t
; ⊤-is-terminal =
record { ! = const ⊤ , const ⊤
; !-unique = bang-uniq
} }
; products = record { product = λ {A} {B} → record
{ A×B = (proj₁ A × proj₁ B) , (proj₂ A × proj₂ B)
; π₁ = proj₁ , λ x → proj₁ (proj₁ x)
; π₂ = proj₂ , (λ x → proj₂ (proj₁ x))
; ⟨_,_⟩ = ⟨_,_⟩
; project₁ = refl
; project₂ = refl
; unique = λ {refl refl → refl}
} } } }
where
bang-uniq :
{A : Category.Obj simple}
-------------------------
(f : (simple Category.⇒ A) (t , t)) →
--------------------------------------
(simple Category.≈ (const ⊤ , const ⊤)) f
bang-uniq {I , X} (u , k) =
cong₂ Data.Product._,_
(extensionality (λ x → !-unique-lemma (u x)))
(extensionality (λ x → !-unique-lemma (k x)))
⟨_,_⟩ :
{A B C : Set × Set} →
(simple Category.⇒ C) A →
(simple Category.⇒ C) B →
(simple Category.⇒ C) ((proj₁ A × proj₁ B) , (proj₂ A × proj₂ B))
⟨_,_⟩ {A0 , A1} {B0 , B1} {C0 , C1} (u , h) (v , k) =
(λ x → (u x) , (v x)) , λ x → (h x) , (k x)
fib-of-simple-ccc : {I : Set} → CartesianClosed (fiber-of-simple {I})
fib-of-simple-ccc {I} =
record
{ ⊤ = t
; _×_ = _×_
; ! = λ x → ⊤
; π₁ = proj₁ ⋆ proj₁
; π₂ = proj₂ ⋆ proj₁
; ⟨_,_⟩ = λ f g ci → (f ci) , (g ci)
; !-unique = λ f → extensionality λ x → !-unique-lemma (f x)
; π₁-comp = refl
; π₂-comp = refl
; ⟨,⟩-unique = λ {refl refl → refl}
; _^_ = λ A B → B → A
; eval = evev
; curry = λ f ci a → f (((proj₁ ci) , a) , (proj₂ ci))
; eval-comp = refl
; curry-resp-≈ = λ {refl → refl}
; curry-unique = λ {refl → refl}
}
where
evev : {B A : Category.Obj (fiber-of-simple {I})} → (fiber-of-simple {I} Category.⇒ ((A → B) × A)) B
evev ((f , a) , i) = f a
{-
the arrow category has objects the morphisms of `Set` and
morphisms the commutative squares
A → B
↓ ↓
C → D
-}
arrow : Category (suc zero) zero zero
arrow = record
{ Obj = Σ (Set × Set) (λ x → proj₁ x → proj₂ x)
; _⇒_ = arr
; _≈_ = _≡_
; id = (λ z → z) , λ z → z
; _∘_ = λ {A} {B} {C} f g → comp {A} {B} {C} f g
; assoc = refl
; sym-assoc = refl
; identityˡ = refl
; identityʳ = refl
; identity² = refl
; equiv = record { refl = refl ; sym = sym ; trans = trans }
; ∘-resp-≈ = λ {refl refl → refl}
}
where
arr : Rel (Σ (Set × Set) (λ x → proj₁ x → proj₂ x)) zero
arr ((a , b) , x1) ((c , d) , y1) = (a → c) × (b → d)
comp : {A B C : Σ (Set × Set) (λ x → proj₁ x → proj₂ x)} → arr B C → arr A B → arr A C
comp {A} {B} {C} (f0 , f1) (g0 , g1) = (λ x → f0 (g0 x)) , λ x → f1 (g1 x)
arrow-ccc : CartesianClosed arrow
arrow-ccc = record
{ ⊤ = (t , t) , (λ _ → ⊤)
; _×_ = prod
; ! = (λ _ → ⊤) , (λ _ → ⊤)
; π₁ = proj₁ , proj₁
; π₂ = proj₂ , proj₂
; ⟨_,_⟩ = λ {A} {B} {C} f g → pair {A} {B} {C} f g
; !-unique = λ {A} → bang-uniq {A}
; π₁-comp = refl
; π₂-comp = refl
; ⟨,⟩-unique = λ {refl refl → refl}
; _^_ = to-the
; eval = λ {B} {A} → ev {B} {A}
; curry = λ {C} {A} {B} x → cur {C} {A} {B} x
; eval-comp = refl
; curry-resp-≈ = λ {refl → refl}
; curry-unique = {! !}
}
where
prod : Category.Obj arrow → Category.Obj arrow → Category.Obj arrow
prod ((X , Y) , u) ((A , B) , v) =
((X × A) , (Y × B)) , λ x → (u (proj₁ x)) , (v (proj₂ x))
pair : {C A B : Category.Obj arrow} →
(arrow Category.⇒ C) A →
(arrow Category.⇒ C) B →
(arrow Category.⇒ C) (prod A B)
pair {(X , Y) , u} {(A , B) , v} {(E , F) , w} (f0 , f1) (g0 , g1) =
(λ x → (f0 x) , (g0 x)) , (λ x → (f1 x) , (g1 x))
bang-uniq : {A : Category.Obj arrow} →
(f : (arrow Category.⇒ A) ((t , t) , (λ _ → ⊤))) →
((λ _ → ⊤) , (λ _ → ⊤)) ≡ f
bang-uniq (f0 , f1) =
cong₂ _,_
(extensionality λ x → !-unique-lemma (f0 x))
(extensionality (λ x → !-unique-lemma (f1 x)))
to-the : Category.Obj arrow →
Category.Obj arrow →
Category.Obj arrow
to-the ((B0 , B1) , u) ((A0 , A1) , v) =
(p , (A1 → B1)) , (λ x a1 → proj₂ (proj₁ x) a1)
where
p : Set
p = Σ ((A0 → B0) × (A1 → B1)) (λ r → (λ x → u ((proj₁ r) x)) ≡ (λ x → (proj₂ r) (v x)))
-- ^ it's the pullback-hom
-- λ x → u (s x) ≡ λ x → t (v x)
ev : {B A : Category.Obj arrow} → (arrow Category.⇒ prod (to-the B A) A) B
ev {(B0 , B1) , u} {(A0 , A1) , v} = dis , dat
where
dis : proj₁ (proj₁ (prod (to-the ((B0 , B1) , u) ((A0 , A1) , v)) ((A0 , A1) , v))) → B0
dis ((d , p) , a0) = (proj₁ d) a0
dat : proj₂ (proj₁ (prod (to-the ((B0 , B1) , u) ((A0 , A1) , v)) ((A0 , A1) , v))) → B1
dat (fst , snd) = fst snd
cur : {C A B : Category.Obj arrow} →
(arrow Category.⇒ (prod C A)) B →
(arrow Category.⇒ C) (to-the B A)
cur {(C0 , C1) , u} {(A0 , A1) , v} {(B0 , B1) , w} (fst , snd) =
(λ x → ((λ t → fst (x , t)) , λ t → snd (u x , t)) , extensionality (λ a0 → {! !})) , (λ z z₁ → snd (z , z₁)) | {
"alphanum_fraction": 0.4665593129,
"avg_line_length": 31.4695945946,
"ext": "agda",
"hexsha": "8d21a07e2f0ef039b7ac1e06ff8df5ae67aa1e50",
"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": "cfa6aefd3069d4db995191b458c886edcfba8294",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tetrapharmakon/agda-categories",
"max_forks_repo_path": "src/Mystuff.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "cfa6aefd3069d4db995191b458c886edcfba8294",
"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": "tetrapharmakon/agda-categories",
"max_issues_repo_path": "src/Mystuff.agda",
"max_line_length": 113,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "cfa6aefd3069d4db995191b458c886edcfba8294",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tetrapharmakon/agda-categories",
"max_stars_repo_path": "src/Mystuff.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3687,
"size": 9315
} |
{-
Definition of the integers as a HIT inspired by slide 10 of (original
idea due to Paolo Capriotti):
http://www.cs.nott.ac.uk/~psztxa/talks/bonn18.pdf
Disclaimer: this definition is very hard to work with and I have not
been able to prove that it is equivalent to nat + nat or that it is a
set.
For a variation that relies on a different notion of equivalence
(without any 2-cell) and which seems easier to work with see:
https://github.com/RedPRL/redtt/blob/master/library/cool/biinv-int.red
It might be interesting to port that example one day.
-}
{-# OPTIONS --cubical --no-import-sorts #-}
module Cubical.Experiments.HInt where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Int
open import Cubical.Data.Nat
data ℤ : Type₀ where
zero : ℤ
suc : ℤ → ℤ
pred : ℤ → ℤ
sucpred : (n : ℤ) → suc (pred n) ≡ n
predsuc : (n : ℤ) → pred (suc n) ≡ n
-- Coherence: could also be written "sucpred (suc n) ≡ cong (suc (predsuc n))"
coh : (n : ℤ) → Path (suc (pred (suc n)) ≡ suc n)
(sucpred (suc n))
(λ i → suc (predsuc n i))
-- This is equivalent to Int:
coherence : (n : Int) → Path (Path Int (sucInt (predInt (sucInt n))) (sucInt n))
(sucPred (sucInt n))
(cong sucInt (predSuc n))
coherence (pos zero) = refl
coherence (pos (suc n)) = refl
coherence (negsuc zero) = refl
coherence (negsuc (suc zero)) = refl
coherence (negsuc (suc (suc n))) = refl
ℤ→Int : ℤ → Int
ℤ→Int zero = pos 0
ℤ→Int (suc n) = sucInt (ℤ→Int n)
ℤ→Int (pred n) = predInt (ℤ→Int n)
ℤ→Int (sucpred n i) = sucPred (ℤ→Int n) i
ℤ→Int (predsuc n i) = predSuc (ℤ→Int n) i
ℤ→Int (coh n i j) = coherence (ℤ→Int n) i j
ℕ→ℤ : ℕ → ℤ
ℕ→ℤ zero = zero
ℕ→ℤ (suc n) = suc (ℕ→ℤ n)
negsucℕ→ℤ : ℕ → ℤ
negsucℕ→ℤ zero = pred zero
negsucℕ→ℤ (suc n) = pred (negsucℕ→ℤ n)
Int→ℤ : Int → ℤ
Int→ℤ (pos n) = ℕ→ℤ n
Int→ℤ (negsuc n) = negsucℕ→ℤ n
lem1 : ∀ n → Int→ℤ (sucInt n) ≡ suc (Int→ℤ n)
lem1 (pos n) = refl
lem1 (negsuc zero) = sym (sucpred zero)
lem1 (negsuc (suc n)) = sym (sucpred (negsucℕ→ℤ n))
lem2 : ∀ n → Int→ℤ (predInt n) ≡ pred (Int→ℤ n)
lem2 (pos zero) = refl
lem2 (pos (suc n)) = sym (predsuc (ℕ→ℤ n))
lem2 (negsuc n) = refl
-- I don't see how to fill these holes, especially the last one
ℤ→Int→ℤ : ∀ (n : ℤ) → Int→ℤ (ℤ→Int n) ≡ n
ℤ→Int→ℤ zero = refl
ℤ→Int→ℤ (suc n) = (lem1 (ℤ→Int n)) ∙ (cong suc (ℤ→Int→ℤ n))
ℤ→Int→ℤ (pred n) = (lem2 (ℤ→Int n)) ∙ (cong pred (ℤ→Int→ℤ n))
ℤ→Int→ℤ (sucpred n i) = {!!}
ℤ→Int→ℤ (predsuc n i) = {!!}
ℤ→Int→ℤ (coh n i j) = {!!}
Int→ℤ→Int : ∀ n → ℤ→Int (Int→ℤ n) ≡ n
Int→ℤ→Int (pos zero) = refl
Int→ℤ→Int (pos (suc n)) = cong sucInt (Int→ℤ→Int (pos n))
Int→ℤ→Int (negsuc zero) = refl
Int→ℤ→Int (negsuc (suc n)) = cong predInt (Int→ℤ→Int (negsuc n))
Int≡ℤ : Int ≡ ℤ
Int≡ℤ = isoToPath (iso Int→ℤ ℤ→Int ℤ→Int→ℤ Int→ℤ→Int)
isSetℤ : isSet ℤ
isSetℤ = subst isSet Int≡ℤ isSetInt
| {
"alphanum_fraction": 0.620793069,
"avg_line_length": 30.01,
"ext": "agda",
"hexsha": "6d0135a851ad898f4f1c871b7b0cd5f0fe567939",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Experiments/HInt.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/Experiments/HInt.agda",
"max_line_length": 80,
"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/Experiments/HInt.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1270,
"size": 3001
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Sigma
open import lib.types.Bool
open import lib.types.Nat
open import lib.types.Fin
module lib.types.Vec where
infixr 5 _∷_
data Vec {i} (A : Type i) : ℕ → Type i where
[] : Vec A 0
_∷_ : ∀ {n} (x : A) (xs : Vec A n) → Vec A (S n)
infix 4 _[_]=_
data _[_]=_ {i} {A : Type i} : ∀ {n} → Vec A n → ℕ → A → Type i where
here : ∀ {n} {x} {xs : Vec A n} → x ∷ xs [ 0 ]= x
there : ∀ {n} {m} {x y} {xs : Vec A n}
(xs[m]=x : xs [ m ]= x) → y ∷ xs [ S m ]= x
module _ {i} {A : Type i} where
length : ∀ {n} → Vec A n → ℕ
length {n = n} _ = n
head : ∀ {n} → Vec A (S n) → A
head (x ∷ xs) = x
vtail : ∀ {n} → Vec A (S n) → Vec A n
vtail (x ∷ xs) = xs
lookup : ∀ {n} → Vec A n → Fin n → A
lookup [] ()
lookup (x ∷ xs) (O , _) = x
lookup (x ∷ xs) (S n , p) = lookup xs (n , <-cancel-S p)
updateAt : ∀ {n} → Fin n → (A → A) → Vec A n → Vec A n
updateAt (_ , _) _ [] = []
updateAt (O , _) f (x ∷ xs) = (f x) ∷ xs
updateAt (S n , p) f (x ∷ xs) = x ∷ (updateAt (n , <-cancel-S p) f xs)
| {
"alphanum_fraction": 0.4834673816,
"avg_line_length": 25.4318181818,
"ext": "agda",
"hexsha": "259d7b55e666c43435cdce168da892f32708ed5e",
"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": "01bbd8841f9b9b25666b91e65b196d8f472b9978",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "maxdore/hott-morse",
"max_forks_repo_path": "core/lib/types/Vec.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "01bbd8841f9b9b25666b91e65b196d8f472b9978",
"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": "maxdore/hott-morse",
"max_issues_repo_path": "core/lib/types/Vec.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "01bbd8841f9b9b25666b91e65b196d8f472b9978",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "maxdore/hott-morse",
"max_stars_repo_path": "core/lib/types/Vec.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 485,
"size": 1119
} |
module Data.Iterator where
import Lvl
open import Data hiding (empty)
open import Data.Boolean
open import Functional
open import Numeral.Natural
open import Type
private variable ℓ : Lvl.Level
private variable T A B : Type{ℓ}
private variable a x init : T
private variable f : A → B
private variable n : ℕ
-- TODO: Is this useful when not lazy? It cannot store data and I am not sure if the whole list is evaluated in listIterator or not (strictness)
record Iterator (T : Type{ℓ}) : Type{ℓ} where
coinductive
field
isEmpty : Bool
current : if isEmpty then Unit else T -- TODO: These are essentially `Option`s but instead of storing its state, they depend on a boolean defined somewhere else
step : if isEmpty then Unit else Iterator(T)
open Iterator
{- TODO: This is a generalization of an iterator. It could be used to define iterators for any number of dimensions or to define double-ended iterators.
-- TODO: decidable-all-step may also be ∃{Obj = (Step → Bool) → Bool}(dec ↦ ∀{P} → (IsTrue(dec(P)) ↔ ∀ₗ(IsTrue ∘ P))). Not sure if it captures that (∀{s} → atEnd s) always is decidable by the smallest amount of assumptions. An example of this is when Step is finitely enumerable.
record Stepper (Step : Type{ℓₛ}) ⦃ decidable-all-step : ∀{P : Step → Bool} → Decidable(∀ₗ(IsTrue ∘ P)) ⦄ (T : Type{ℓ}) : Type{ℓ} where
coinductive
field
atEnd : Step → Bool
current : if decide(∀ₗ(IsTrue ∘ atEnd)) then Unit else T
step : (step : Step) → if(atEnd step) then Unit else Stepper(Step)(T)
-}
open import Data.Option
open import Data.Boolean.Operators
open Data.Boolean.Operators.Programming
skip : ℕ → Iterator(T) → Iterator(T)
skip 𝟎 iter = iter
skip (𝐒 n) iter with isEmpty iter | step iter
... | 𝑇 | <> = iter
... | 𝐹 | sIter = skip n sIter
skipExact : ℕ → Iterator(T) → Option(Iterator(T))
skipExact 𝟎 iter = Some iter
skipExact (𝐒 n) iter with isEmpty iter | step iter
... | 𝑇 | <> = None
... | 𝐹 | sIter = skipExact n sIter
{- TODO: Not sure if I did not get the semantics of how codata works or whether the termination checker is wrong
{-# TERMINATING #-}
_++_ : Iterator(T) → Iterator(T) → Iterator(T)
isEmpty (a ++ b) with isEmpty a
... | 𝑇 = isEmpty b
... | 𝐹 = 𝐹
current (a ++ b) with isEmpty a | current a
... | 𝐹 | ca = ca
... | 𝑇 | <> with isEmpty b | current b
... | 𝐹 | cb = cb
... | 𝑇 | <> = <>
step (a ++ b) with isEmpty a | step a
... | 𝐹 | sa = sa ++ b
... | 𝑇 | <> with isEmpty b | step b
... | 𝐹 | sb = sb
... | 𝑇 | <> = <>
{-# TERMINATING #-}
map : (A → B) → (Iterator(A) → Iterator(B))
isEmpty (map f iter) = isEmpty iter
current (map f iter) with isEmpty iter | current iter
... | 𝑇 | <> = <>
... | 𝐹 | a = f(a)
step (map f iter) with isEmpty iter | step iter
... | 𝑇 | <> = <>
... | 𝐹 | sIter = map f sIter
-}
empty : Iterator(T)
isEmpty empty = 𝑇
current empty = <>
step empty = <>
prepend : T → Iterator(T) → Iterator(T)
isEmpty (prepend x l) = 𝐹
current (prepend x l) = x
step (prepend x l) = l
open import Data.List
listIterator : List(T) → Iterator(T)
listIterator ∅ = empty
listIterator (x ⊰ l) = prepend x (listIterator l)
| {
"alphanum_fraction": 0.6452842172,
"avg_line_length": 33.1473684211,
"ext": "agda",
"hexsha": "d4207f2e7b0463a542a77a3014e45e0dd0d34b5b",
"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": "Data/Iterator.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": "Data/Iterator.agda",
"max_line_length": 279,
"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": "Data/Iterator.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": 982,
"size": 3149
} |
-- Andreas, 2016-05-04, issue 1960 reported by Nisse
-- {-# OPTIONS -v tc.proj.amb:100 #-}
postulate
A : Set
module M (_ : Set₁) where
record R₁ : Set where
field
f : A
open R₁ public
open M Set
record R₂ : Set where
field
f : A
open R₂ public
postulate
P : A → Set
x : R₁
works : P (R₁.f x)
test : P (f x)
-- should succeed
| {
"alphanum_fraction": 0.5691489362,
"avg_line_length": 12.1290322581,
"ext": "agda",
"hexsha": "92b2b3795f9edf405a037aa4588a0ce80681a722",
"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/Issue1960.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/Issue1960.agda",
"max_line_length": 52,
"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/Issue1960.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": 138,
"size": 376
} |
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Delta-observational equivalence
------------------------------------------------------------------------
module Base.Change.Equivalence where
open import Relation.Binary.PropositionalEquality
open import Base.Change.Algebra
open import Level
open import Data.Unit
open import Data.Product
open import Function
open import Base.Change.Equivalence.Base public
open import Base.Change.Equivalence.EqReasoning public
module _
{a} {A : Set a} {{CA : ChangeAlgebra A}}
{x : A}
where
-- By update-nil, if dx = nil x, then x ⊞ dx ≡ x.
-- As a consequence, if dx ≙ nil x, then x ⊞ dx ≡ x
nil-is-⊞-unit : ∀ (dx : Δ x) → dx ≙ nil x → x ⊞ dx ≡ x
nil-is-⊞-unit dx dx≙nil-x =
begin
x ⊞ dx
≡⟨ proof dx≙nil-x ⟩
x ⊞ (nil x)
≡⟨ update-nil x ⟩
x
∎
where
open ≡-Reasoning
-- Here we prove the inverse:
⊞-unit-is-nil : ∀ (dx : Δ x) → x ⊞ dx ≡ x → dx ≙ (nil x)
⊞-unit-is-nil dx x⊞dx≡x = doe $
begin
x ⊞ dx
≡⟨ x⊞dx≡x ⟩
x
≡⟨ sym (update-nil x) ⟩
x ⊞ nil x
∎
where
open ≡-Reasoning
-- Let's show that nil x is d.o.e. to x ⊟ x
nil-x-is-x⊟x : nil x ≙ x ⊟ x
nil-x-is-x⊟x = ≙-sym (⊞-unit-is-nil (x ⊟ x) (update-diff x x))
-- TODO: we want to show that all functions of interest respect
-- delta-observational equivalence, so that two d.o.e. changes can be
-- substituted for each other freely.
--
-- * That should be be true for
-- functions using changes parametrically.
--
-- * Moreover, d.o.e. should be respected by contexts [ ] x dx and df x [ ];
-- this is proved below on both contexts at once by
-- equiv-fun-changes-respect, and its corollaries fun-change-respects and
-- equiv-fun-changes-funs.
--
-- * Finally, change algebra operations should respect d.o.e. But ⊞ respects
-- it by definition, and ⊟ doesn't take change arguments - we will only
-- need a proof for compose, when we define it.
--
-- Stating the general result, though, seems hard, we should
-- rather have lemmas proving that certain classes of functions respect this
-- equivalence.
-- This results pairs with update-diff.
diff-update : ∀ {dx : Δ x} → (x ⊞ dx) ⊟ x ≙ dx
diff-update {dx} = doe lemma
where
lemma : x ⊞ (x ⊞ dx ⊟ x) ≡ x ⊞ dx
lemma = update-diff (x ⊞ dx) x
-- \begin{lemma}[Equivalence cancellation]
-- |v2 `ominus` v1 `doe` dv| holds if and only if |v2 = v1 `oplus`
-- dv|, for any |v1, v2 `elem` V| and |dv `elem` Dt ^ v1|.
-- \end{lemma}
equiv-cancel-1 : ∀ x' dx → (x' ⊟ x) ≙ dx → x' ≡ x ⊞ dx
equiv-cancel-1 x' dx (doe x'⊟x≙dx) = trans (sym (update-diff x' x)) x'⊟x≙dx
equiv-cancel-2 : ∀ x' dx → x' ≡ x ⊞ dx → x' ⊟ x ≙ dx
equiv-cancel-2 _ dx refl = diff-update
module _
{a} {A : Set a} {{CA : ChangeAlgebra A}}
{b} {B : Set b} {{CB : ChangeAlgebra B}}
where
≙-cong₂ : ∀ {c} {C : Set c} {x y}
(f : A → B → C) {dx1 dx2 dy1 dy2} → dx1 ≙ dx2 → dy1 ≙ dy2 → f (x ⊞ dx1) (y ⊞ dy1) ≡ f (x ⊞ dx2) (y ⊞ dy2)
≙-cong₂ f dx1≙dx2 dy1≙dy2 = cong₂ f (proof dx1≙dx2) (proof dy1≙dy2)
≙-incrementalization : ∀ (f : A → B) (df : Δ f) x dx → (f ⊞ df) (x ⊞ dx) ⊟ f x ≙ apply df x dx
≙-incrementalization f df x dx = equiv-cancel-2 _ _ (incrementalization f df x dx)
equiv-fun-changes-respect : ∀ {x : A} {dx₁ dx₂ : Δ x} {f : A → B} {df₁ df₂ : Δ f} →
df₁ ≙₍ f ₎ df₂ → dx₁ ≙ dx₂ → apply df₁ x dx₁ ≙ apply df₂ x dx₂
equiv-fun-changes-respect {x} {dx₁} {dx₂} {f} {df₁} {df₂} df₁≙df₂ dx₁≙dx₂ = doe lemma
where
open ≡-Reasoning
-- This type signature just expands the goal manually a bit.
lemma : f x ⊞ apply df₁ x dx₁ ≡ f x ⊞ apply df₂ x dx₂
-- Informally: use incrementalization on both sides and then apply
-- congruence.
lemma =
begin
f x ⊞ apply df₁ x dx₁
≡⟨ sym (incrementalization f df₁ x dx₁) ⟩
(f ⊞ df₁) (x ⊞ dx₁)
≡⟨ ≙-cong (f ⊞ df₁) dx₁≙dx₂ ⟩
(f ⊞ df₁) (x ⊞ dx₂)
≡⟨ ≙-cong (λ f → f (x ⊞ dx₂)) df₁≙df₂ ⟩
(f ⊞ df₂) (x ⊞ dx₂)
≡⟨ incrementalization f df₂ x dx₂ ⟩
f x ⊞ apply df₂ x dx₂
∎
fun-change-respects : ∀ {x : A} {dx₁ dx₂} {f : A → B} (df : Δ f) →
dx₁ ≙ dx₂ → apply df x dx₁ ≙ apply df x dx₂
fun-change-respects df dx₁≙dx₂ = equiv-fun-changes-respect (≙-refl {dx = df}) dx₁≙dx₂
-- D.o.e. function changes behave like the same function (up to d.o.e.).
equiv-fun-changes-funs : ∀ {x : A} {dx} {f : A → B} {df₁ df₂} →
df₁ ≙₍ f ₎ df₂ → apply df₁ x dx ≙ apply df₂ x dx
equiv-fun-changes-funs {dx = dx} df₁≙df₂ = equiv-fun-changes-respect df₁≙df₂ (≙-refl {dx = dx})
derivative-doe-characterization : ∀ {a : A} {da : Δ a}
{f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →
df a da ≙ f (a ⊞ da) ⊟ f a
derivative-doe-characterization {a} {da} {f} {df} is-derivative = doe lemma
where
open ≡-Reasoning
lemma : f a ⊞ df a da ≡ f a ⊞ (f (a ⊞ da) ⊟ f a)
lemma =
begin
(f a ⊞ df a da)
≡⟨ is-derivative a da ⟩
(f (a ⊞ da))
≡⟨ sym (update-diff (f (a ⊞ da)) (f a)) ⟩
(f a ⊞ (f (a ⊞ da) ⊟ f a))
∎
derivative-respects-doe : ∀ {x : A} {dx₁ dx₂ : Δ x}
{f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →
dx₁ ≙ dx₂ → df x dx₁ ≙ df x dx₂
derivative-respects-doe {x} {dx₁} {dx₂} {f} {df} is-derivative dx₁≙dx₂ =
begin
df x dx₁
≙⟨ derivative-doe-characterization is-derivative ⟩
f (x ⊞ dx₁) ⊟ f x
≡⟨ cong (λ v → f v ⊟ f x) (proof dx₁≙dx₂) ⟩
f (x ⊞ dx₂) ⊟ f x
≙⟨ ≙-sym (derivative-doe-characterization is-derivative) ⟩
df x dx₂
∎
where
open ≙-Reasoning
-- This is also a corollary of fun-changes-respect
derivative-respects-doe-alt : ∀ {x : A} {dx₁ dx₂ : Δ x}
{f : A → B} {df : RawChange f} (is-derivative : IsDerivative f df) →
dx₁ ≙ dx₂ → df x dx₁ ≙ df x dx₂
derivative-respects-doe-alt {x} {dx₁} {dx₂} {f} {df} is-derivative dx₁≙dx₂ =
fun-change-respects (DerivativeAsChange is-derivative) dx₁≙dx₂
open import Postulate.Extensionality
-- An extensionality principle for delta-observational equivalence: if
-- applying two function changes to the same base value and input change gives
-- a d.o.e. result, then the two function changes are d.o.e. themselves.
delta-ext : ∀ {f : A → B} → ∀ {df dg : Δ f} → (∀ x dx → apply df x dx ≙ apply dg x dx) → df ≙ dg
delta-ext {f} {df} {dg} df-x-dx≙dg-x-dx = doe lemma₂
where
open ≡-Reasoning
-- This type signature just expands the goal manually a bit.
lemma₁ : ∀ x dx → f x ⊞ apply df x dx ≡ f x ⊞ apply dg x dx
lemma₁ x dx = proof $ df-x-dx≙dg-x-dx x dx
lemma₂ : f ⊞ df ≡ f ⊞ dg
lemma₂ = ext (λ x → lemma₁ x (nil x))
-- You could think that the function should relate equivalent changes, but
-- that's a stronger hypothesis, which doesn't give you extra guarantees. But
-- here's the statement and proof, for completeness:
delta-ext₂ : ∀ {f : A → B} → ∀ {df dg : Δ f} → (∀ x (dx₁ dx₂ : Δ x) → dx₁ ≙₍ x ₎ dx₂ → apply df x dx₁ ≙ apply dg x dx₂) → df ≙ dg
delta-ext₂ {f} {df} {dg} df-x-dx≙dg-x-dx = delta-ext (λ x dx → df-x-dx≙dg-x-dx x dx dx ≙-refl)
-- We know that IsDerivative f (apply (nil f)) (by nil-is-derivative).
-- That is, df = nil f -> IsDerivative f (apply df).
-- Now, we try to prove that if IsDerivative f (apply df) -> df = nil f.
-- But first, we prove that f ⊞ df = f.
derivative-is-⊞-unit : ∀ {f : A → B} df →
IsDerivative f (apply df) → f ⊞ df ≡ f
derivative-is-⊞-unit {f} df fdf =
begin
f ⊞ df
≡⟨⟩
(λ x → f x ⊞ apply df x (nil x))
≡⟨ ext (λ x → fdf x (nil x)) ⟩
(λ x → f (x ⊞ nil x))
≡⟨ ext (λ x → cong f (update-nil x)) ⟩
(λ x → f x)
≡⟨⟩
f
∎
where
open ≡-Reasoning
-- We can restate the above as "df is a nil change".
derivative-is-nil : ∀ {f : A → B} df →
IsDerivative f (apply df) → df ≙ nil f
derivative-is-nil df fdf = ⊞-unit-is-nil df (derivative-is-⊞-unit df fdf)
derivative-is-nil-alternative : ∀ {f : A → B} df →
(IsDerivative-f-df : IsDerivative f df) → DerivativeAsChange IsDerivative-f-df ≙ nil f
derivative-is-nil-alternative df IsDerivative-f-df = derivative-is-nil (DerivativeAsChange IsDerivative-f-df) IsDerivative-f-df
-- Theorem 2.10, appears in Base.Change.Algebra.
-- nil-is-derivative : ∀ (f : A → B) → IsDerivative f (apply (nil f))
-- If we have two derivatives, they're both nil, hence they're equivalent.
derivative-unique : ∀ {f : A → B} {df dg : Δ f} → IsDerivative f (apply df) → IsDerivative f (apply dg) → df ≙ dg
derivative-unique {f} {df} {dg} fdf fdg =
begin
df
≙⟨ derivative-is-nil df fdf ⟩
nil f
≙⟨ ≙-sym (derivative-is-nil dg fdg) ⟩
dg
∎
where
open ≙-Reasoning
equiv-derivative-is-derivative : ∀ {f : A → B} df₁ df₂ → IsDerivative f (apply df₁) → df₁ ≙₍ f ₎ df₂ → IsDerivative f (apply df₂)
equiv-derivative-is-derivative {f} df₁ df₂ IsDerivative-f-df₁ df₁≙df₂ a da =
begin
f a ⊞ apply df₂ a da
≡⟨ sym (incrementalization f df₂ a da) ⟩
(f ⊞ df₂) (a ⊞ da)
≡⟨ cong (λ □ → □ (a ⊞ da)) lemma ⟩
f (a ⊞ da)
∎
where
open ≡-Reasoning
lemma : f ⊞ df₂ ≡ f
lemma =
begin
f ⊞ df₂
≡⟨ proof (≙-sym df₁≙df₂) ⟩
f ⊞ df₁
≡⟨ derivative-is-⊞-unit df₁ IsDerivative-f-df₁ ⟩
f
∎
equiv-nil-is-derivative : ∀ {f : A → B} df → nil f ≙₍ f ₎ df → IsDerivative f (apply df)
equiv-nil-is-derivative {f} df = equiv-derivative-is-derivative (nil f) df (nil-is-derivative f)
-- This is Lemma 2.5 in the paper. Note that the statement in the paper uses
-- (incorrectly) normal equality instead of delta-observational equivalence.
deriv-zero :
∀ (f : A → B) df → IsDerivative f df →
∀ v → df v (nil v) ≙ nil (f v)
deriv-zero f df proof v = doe lemma
where
open ≡-Reasoning
lemma : f v ⊞ df v (nil v) ≡ f v ⊞ nil (f v)
lemma =
begin
f v ⊞ df v (nil v)
≡⟨ proof v (nil v) ⟩
f (v ⊞ (nil v))
≡⟨ cong f (update-nil v) ⟩
f v
≡⟨ sym (update-nil (f v)) ⟩
f v ⊞ nil (f v)
∎
module _
{a} {A : Set a} {{CA : ChangeAlgebra A}}
{b} {B : Set b} {{CB : ChangeAlgebra B}}
{c} {C : Set c} {{CC : ChangeAlgebra C}}
where
≙-cong₃ : ∀ {d} {D : Set d} {x y z}
(f : A → B → C → D) {dx1 dx2 dy1 dy2 dz1 dz2} →
dx1 ≙ dx2 → dy1 ≙ dy2 → dz1 ≙ dz2 →
f (x ⊞ dx1) (y ⊞ dy1) (z ⊞ dz1) ≡ f (x ⊞ dx2) (y ⊞ dy2) (z ⊞ dz2)
≙-cong₃ f dx1≙dx2 dy1≙dy2 dz1≙dz2 = cong₂ (λ x y → x y) (cong₂ f (proof dx1≙dx2) (proof dy1≙dy2)) (proof dz1≙dz2)
| {
"alphanum_fraction": 0.5591576614,
"avg_line_length": 36.7016949153,
"ext": "agda",
"hexsha": "640b8c97e719987169a8dec25dcb25b30dbaf02e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Base/Change/Equivalence.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Base/Change/Equivalence.agda",
"max_line_length": 131,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Base/Change/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 4198,
"size": 10827
} |
------------------------------------------------------------------------
-- A class of algebraic structures, based on non-recursive simple
-- types, satisfies the property that isomorphic instances of a
-- structure are equal (assuming univalence)
------------------------------------------------------------------------
-- In fact, isomorphism and equality are basically the same thing, and
-- the main theorem can be instantiated with several different
-- "universes", not only the one based on simple types.
-- This module has been developed in collaboration with Thierry
-- Coquand.
{-# OPTIONS --without-K --safe #-}
open import Equality
module Univalence-axiom.Isomorphism-is-equality.Simple
{reflexive} (eq : ∀ {a p} → Equality-with-J a p reflexive) where
open import Bijection eq as B using (_↔_)
open Derived-definitions-and-properties eq
renaming (lower-extensionality to lower-ext)
open import Equality.Decidable-UIP eq
open import Equality.Decision-procedures eq
open import Equivalence eq as Eq using (_≃_)
open import Function-universe eq hiding (id) renaming (_∘_ to _⊚_)
open import H-level eq
open import H-level.Closure eq
open import Injection eq using (Injective)
open import Logical-equivalence using (_⇔_; module _⇔_)
open import Nat eq
open import Preimage eq
open import Prelude as P hiding (id)
open import Univalence-axiom eq
------------------------------------------------------------------------
-- Universes with some extra stuff
-- A record type packing up some assumptions.
record Assumptions : Type₃ where
field
-- Univalence at three different levels.
univ : Univalence (# 0)
univ₁ : Univalence (# 1)
univ₂ : Univalence (# 2)
abstract
-- Extensionality.
ext : ∀ {ℓ} → Extensionality ℓ (# 1)
ext = dependent-extensionality univ₂ univ₁
ext₁ : Extensionality (# 1) (# 1)
ext₁ = ext
-- Universes with some extra stuff.
record Universe : Type₃ where
-- Parameters.
field
-- Codes for something.
U : Type₂
-- Interpretation of codes.
El : U → Type₁ → Type₁
-- El a, seen as a predicate, respects equivalences.
resp : ∀ a {B C} → B ≃ C → El a B → El a C
-- The resp function respects identities (assuming univalence).
resp-id : Assumptions → ∀ a {B} (x : El a B) → resp a Eq.id x ≡ x
-- Derived definitions.
-- A predicate that specifies what it means for an equivalence to be
-- an isomorphism between two elements.
Is-isomorphism : ∀ a {B C} → B ≃ C → El a B → El a C → Type₁
Is-isomorphism a eq x y = resp a eq x ≡ y
-- An alternative definition of Is-isomorphism, defined using
-- univalence.
Is-isomorphism′ : Assumptions →
∀ a {B C} → B ≃ C → El a B → El a C → Type₁
Is-isomorphism′ ass a eq x y = subst (El a) (≃⇒≡ univ₁ eq) x ≡ y
where open Assumptions ass
-- Every element is isomorphic to itself, transported along the
-- isomorphism.
isomorphic-to-itself :
(ass : Assumptions) → let open Assumptions ass in
∀ a {B C} (eq : B ≃ C) x →
Is-isomorphism a eq x (subst (El a) (≃⇒≡ univ₁ eq) x)
isomorphic-to-itself ass a eq x =
transport-theorem (El a) (resp a) (resp-id ass a) univ₁ eq x
where open Assumptions ass
-- Is-isomorphism and Is-isomorphism′ are isomorphic (assuming
-- univalence).
isomorphism-definitions-isomorphic :
(ass : Assumptions) →
∀ a {B C} (eq : B ≃ C) {x y} →
Is-isomorphism a eq x y ↔ Is-isomorphism′ ass a eq x y
isomorphism-definitions-isomorphic ass a eq {x} {y} =
Is-isomorphism a eq x y ↝⟨ ≡⇒↝ _ $ cong (λ z → z ≡ y) $ isomorphic-to-itself ass a eq x ⟩□
Is-isomorphism′ ass a eq x y □
------------------------------------------------------------------------
-- A universe-indexed family of classes of structures
module Class (Univ : Universe) where
open Universe Univ
-- Codes for structures.
Code : Type₃
Code =
-- A code.
Σ U λ a →
-- A proposition.
(C : Type₁) → El a C → Σ Type₁ λ P →
-- The proposition should be propositional (assuming
-- univalence).
Assumptions → Is-proposition P
-- Interpretation of the codes. The elements of "Instance c" are
-- instances of the structure encoded by c.
Instance : Code → Type₂
Instance (a , P) =
-- A carrier type.
Σ Type₁ λ C →
-- An element.
Σ (El a C) λ x →
-- The element should satisfy the proposition.
proj₁ (P C x)
-- The carrier type.
Carrier : ∀ c → Instance c → Type₁
Carrier _ X = proj₁ X
-- The "element".
element : ∀ c (X : Instance c) → El (proj₁ c) (Carrier c X)
element _ X = proj₁ (proj₂ X)
abstract
-- One can prove that two instances of a structure are equal by
-- proving that the carrier types and "elements" (suitably
-- transported) are equal (assuming univalence).
equality-pair-lemma :
Assumptions →
∀ c {X Y : Instance c} →
(X ≡ Y) ↔
∃ λ (eq : Carrier c X ≡ Carrier c Y) →
subst (El (proj₁ c)) eq (element c X) ≡ element c Y
equality-pair-lemma ass (a , P) {C , x , p} {D , y , q} =
((C , x , p) ≡ (D , y , q)) ↔⟨ inverse $ Eq.≃-≡ $ Eq.↔⇒≃ Σ-assoc ⟩
(((C , x) , p) ≡ ((D , y) , q)) ↝⟨ inverse $ ignore-propositional-component (proj₂ (P D y) ass) ⟩
((C , x) ≡ (D , y)) ↝⟨ inverse B.Σ-≡,≡↔≡ ⟩□
(∃ λ (eq : C ≡ D) → subst (El a) eq x ≡ y) □
-- Structure isomorphisms.
Isomorphic : ∀ c → Instance c → Instance c → Type₁
Isomorphic (a , _) (C , x , _) (D , y , _) =
Σ (C ≃ D) λ eq → Is-isomorphism a eq x y
-- The type of isomorphisms between two instances of a structure
-- is isomorphic to the type of equalities between the same
-- instances (assuming univalence).
--
-- In short, isomorphism is isomorphic to equality.
isomorphism-is-equality :
Assumptions →
∀ c X Y → Isomorphic c X Y ↔ (X ≡ Y)
isomorphism-is-equality ass (a , P) (C , x , p) (D , y , q) =
(∃ λ (eq : C ≃ D) → resp a eq x ≡ y) ↝⟨ ∃-cong (λ eq → isomorphism-definitions-isomorphic ass a eq) ⟩
(∃ λ (eq : C ≃ D) → subst (El a) (≃⇒≡ univ₁ eq) x ≡ y) ↝⟨ inverse $
Σ-cong (≡≃≃ univ₁) (λ eq → ≡⇒↝ _ $ sym $
cong (λ eq → subst (El a) eq x ≡ y)
(_≃_.left-inverse-of (≡≃≃ univ₁) eq)) ⟩
(∃ λ (eq : C ≡ D) → subst (El a) eq x ≡ y) ↝⟨ inverse $ equality-pair-lemma ass c ⟩□
(X ≡ Y) □
where
open Assumptions ass
c : Code
c = a , P
X : Instance c
X = C , x , p
Y : Instance c
Y = D , y , q
abstract
-- The type of (lifted) isomorphisms between two instances of a
-- structure is equal to the type of equalities between the same
-- instances (assuming univalence).
--
-- In short, isomorphism is equal to equality.
isomorphic≡≡ :
Assumptions →
∀ c {X Y} → ↑ (# 2) (Isomorphic c X Y) ≡ (X ≡ Y)
isomorphic≡≡ ass c {X} {Y} =
≃⇒≡ univ₂ $ Eq.↔⇒≃ (
↑ _ (Isomorphic c X Y) ↝⟨ B.↑↔ ⟩
Isomorphic c X Y ↝⟨ isomorphism-is-equality ass c X Y ⟩□
(X ≡ Y) □)
where open Assumptions ass
-- The "first part" of the from component of
-- isomorphism-is-equality is equal to a simple function.
proj₁-from-isomorphism-is-equality :
∀ ass c X Y →
proj₁ ∘ _↔_.from (isomorphism-is-equality ass c X Y) ≡
elim (λ {X Y} _ → proj₁ X ≃ proj₁ Y) (λ _ → Eq.id)
proj₁-from-isomorphism-is-equality ass _ _ _ = apply-ext ext λ eq →
≡⇒≃ (proj₁ (Σ-≡,≡←≡ (proj₁ (Σ-≡,≡←≡
(cong (λ { (x , (y , z)) → (x , y) , z }) eq))))) ≡⟨ cong (≡⇒≃ ∘ proj₁ ∘ Σ-≡,≡←≡) $ proj₁-Σ-≡,≡←≡ _ ⟩
≡⇒≃ (proj₁ (Σ-≡,≡←≡ (cong proj₁
(cong (λ { (x , (y , z)) → (x , y) , z }) eq)))) ≡⟨ cong (≡⇒≃ ∘ proj₁ ∘ Σ-≡,≡←≡) $
cong-∘ proj₁ (λ { (x , (y , z)) → (x , y) , z }) _ ⟩
≡⇒≃ (proj₁ (Σ-≡,≡←≡ (cong (λ { (x , (y , z)) → x , y }) eq))) ≡⟨ cong ≡⇒≃ $ proj₁-Σ-≡,≡←≡ _ ⟩
≡⇒≃ (cong proj₁ (cong (λ { (x , (y , z)) → x , y }) eq)) ≡⟨ cong ≡⇒≃ $ cong-∘ proj₁ (λ { (x , (y , z)) → x , y }) eq ⟩
≡⇒≃ (cong proj₁ eq) ≡⟨ elim-cong _≃_ proj₁ _ ⟩∎
elim (λ {X Y} _ → proj₁ X ≃ proj₁ Y) (λ _ → Eq.id) eq ∎
where open Assumptions ass
-- In fact, the entire from component of isomorphism-is-equality
-- is equal to a simple function.
--
-- The proof of this lemma is somewhat complicated. A much shorter
-- proof can be constructed if El (proj₁ c) (proj₁ J) is a set
-- (see
-- Structure-identity-principle.from-isomorphism-is-equality′).
from-isomorphism-is-equality :
∀ ass c X Y →
_↔_.from (isomorphism-is-equality ass c X Y) ≡
elim (λ {X Y} _ → Isomorphic c X Y)
(λ { (_ , x , _) → Eq.id , resp-id ass (proj₁ c) x })
from-isomorphism-is-equality ass (a , P) (C , x , p) _ =
apply-ext ext (elim¹
(λ eq → Σ-map ≡⇒≃ f (Σ-≡,≡←≡ (proj₁ (Σ-≡,≡←≡
(cong (λ { (C , (x , p)) → (C , x) , p }) eq)))) ≡
elim (λ {X Y} _ → Isomorphic (a , P) X Y)
(λ { (_ , x , _) → Eq.id , resp-id ass a x })
eq)
(Σ-map ≡⇒≃ f (Σ-≡,≡←≡ (proj₁ (Σ-≡,≡←≡
(cong (_↔_.to Σ-assoc) (refl (C , x , p)))))) ≡⟨ cong (Σ-map ≡⇒≃ f ∘ Σ-≡,≡←≡ ∘ proj₁ ∘ Σ-≡,≡←≡) $ cong-refl _ ⟩
Σ-map ≡⇒≃ f (Σ-≡,≡←≡ (proj₁ (Σ-≡,≡←≡ (refl ((C , x) , p))))) ≡⟨ cong (Σ-map ≡⇒≃ f ∘ Σ-≡,≡←≡ ∘ proj₁) Σ-≡,≡←≡-refl ⟩
Σ-map ≡⇒≃ f (Σ-≡,≡←≡ (refl (C , x))) ≡⟨ cong (Σ-map ≡⇒≃ f) Σ-≡,≡←≡-refl ⟩
(≡⇒≃ (refl C) , f (subst-refl (El a) x)) ≡⟨ Σ-≡,≡→≡ ≡⇒≃-refl lemma₄ ⟩
(Eq.id , resp-id ass a x) ≡⟨ sym $ elim-refl (λ {X Y} _ → Isomorphic (a , P) X Y) _ ⟩∎
elim (λ {X Y} _ → Isomorphic (a , P) X Y)
(λ { (_ , x , _) → Eq.id , resp-id ass a x })
(refl (C , x , p)) ∎))
where
open Assumptions ass
f : ∀ {D} {y : El a D} {eq : C ≡ D} →
subst (El a) eq x ≡ y →
resp a (≡⇒≃ eq) x ≡ y
f {y = y} {eq} eq′ =
_↔_.from (≡⇒↝ _ $ cong (λ z → z ≡ y) $
transport-theorem (El a) (resp a) (resp-id ass a)
univ₁ (≡⇒≃ eq) x)
(_↔_.to (≡⇒↝ _ $ sym $ cong (λ eq → subst (El a) eq x ≡ y)
(_≃_.left-inverse-of (≡≃≃ univ₁) eq)) eq′)
lemma₁ : ∀ {ℓ} {A B C : Type ℓ} {x} (eq₁ : B ≡ A) (eq₂ : C ≡ B) →
_↔_.from (≡⇒↝ _ eq₂) (_↔_.to (≡⇒↝ _ (sym eq₁)) x) ≡
_↔_.to (≡⇒↝ _ (sym (trans eq₂ eq₁))) x
lemma₁ {x = x} eq₁ eq₂ =
_↔_.from (≡⇒↝ _ eq₂) (_↔_.to (≡⇒↝ _ (sym eq₁)) x) ≡⟨ sym $ cong (λ f → f (_↔_.to (≡⇒↝ _ (sym eq₁)) x)) $ ≡⇒↝-sym bijection ⟩
_↔_.to (≡⇒↝ _ (sym eq₂)) (_↔_.to (≡⇒↝ _ (sym eq₁)) x) ≡⟨ sym $ cong (λ f → f x) $ ≡⇒↝-trans bijection ⟩
_↔_.to (≡⇒↝ _ (trans (sym eq₁) (sym eq₂))) x ≡⟨ sym $ cong (λ eq → _↔_.to (≡⇒↝ _ eq) x) $ sym-trans _ _ ⟩∎
_↔_.to (≡⇒↝ _ (sym (trans eq₂ eq₁))) x ∎
lemma₂ : ∀ {a} {A : Type a} {x y z : A}
(x≡y : x ≡ y) (y≡z : y ≡ z) →
_↔_.to (≡⇒↝ _ (cong (λ x → x ≡ z) (sym x≡y))) y≡z ≡
trans x≡y y≡z
lemma₂ {y = y} {z} x≡y y≡z = elim₁
(λ x≡y → _↔_.to (≡⇒↝ _ (cong (λ x → x ≡ z) (sym x≡y))) y≡z ≡
trans x≡y y≡z)
(_↔_.to (≡⇒↝ _ (cong (λ x → x ≡ z) (sym (refl y)))) y≡z ≡⟨ cong (λ eq → _↔_.to (≡⇒↝ _ (cong (λ x → x ≡ z) eq)) y≡z) sym-refl ⟩
_↔_.to (≡⇒↝ _ (cong (λ x → x ≡ z) (refl y))) y≡z ≡⟨ cong (λ eq → _↔_.to (≡⇒↝ _ eq) y≡z) $ cong-refl (λ x → x ≡ z) ⟩
_↔_.to (≡⇒↝ _ (refl (y ≡ z))) y≡z ≡⟨ cong (λ f → _↔_.to f y≡z) ≡⇒↝-refl ⟩
y≡z ≡⟨ sym $ trans-reflˡ _ ⟩∎
trans (refl y) y≡z ∎)
x≡y
lemma₃ :
sym (trans (cong (λ z → z ≡ x) $
transport-theorem (El a) (resp a) (resp-id ass a)
univ₁ (≡⇒≃ (refl C)) x)
(cong (λ eq → subst (El a) eq x ≡ x)
(_≃_.left-inverse-of (≡≃≃ univ₁) (refl C)))) ≡
cong (λ z → z ≡ x) (sym $
trans (trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x))
(sym $ subst-refl (El a) x))
lemma₃ =
sym (trans (cong (λ z → z ≡ x) _)
(cong (λ eq → subst (El a) eq x ≡ x) _)) ≡⟨ cong (λ eq → sym (trans (cong (λ z → z ≡ x)
(transport-theorem (El a) (resp a) (resp-id ass a)
univ₁ (≡⇒≃ (refl C)) x))
eq)) $ sym $
cong-∘ (λ z → z ≡ x) (λ eq → subst (El a) eq x) _ ⟩
sym (trans (cong (λ z → z ≡ x) _)
(cong (λ z → z ≡ x)
(cong (λ eq → subst (El a) eq x) _))) ≡⟨ cong sym $ sym $ cong-trans (λ z → z ≡ x) _ _ ⟩
sym (cong (λ z → z ≡ x)
(trans _ (cong (λ eq → subst (El a) eq x) _))) ≡⟨ sym $ cong-sym (λ z → z ≡ x) _ ⟩
cong (λ z → z ≡ x) (sym $
trans (transport-theorem (El a) (resp a)
(resp-id ass a) univ₁ (≡⇒≃ (refl C)) x)
(cong (λ eq → subst (El a) eq x) _)) ≡⟨ cong (λ eq → cong (λ z → z ≡ x) (sym $
trans eq (cong (λ eq → subst (El a) eq x)
(_≃_.left-inverse-of (≡≃≃ univ₁) (refl C)))))
(transport-theorem-≡⇒≃-refl (El a) (resp a) (resp-id ass a) univ₁ _) ⟩
cong (λ z → z ≡ x) (sym $
trans (trans (trans (trans (cong (λ eq → resp a eq x)
≡⇒≃-refl)
(resp-id ass a x))
(sym $ subst-refl (El a) x))
(sym $ cong (λ eq → subst (El a) eq x)
(_≃_.left-inverse-of
(≡≃≃ univ₁) (refl C))))
(cong (λ eq → subst (El a) eq x)
(_≃_.left-inverse-of (≡≃≃ univ₁) (refl C)))) ≡⟨ cong (cong (λ z → z ≡ x) ∘ sym) $
trans-[trans-sym]- _ _ ⟩∎
cong (λ z → z ≡ x) (sym $
trans (trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x))
(sym $ subst-refl (El a) x)) ∎
lemma₄ : subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(f (subst-refl (El a) x)) ≡
resp-id ass a x
lemma₄ =
subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(f (subst-refl (El a) x)) ≡⟨ cong (subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl) $ lemma₁ _ _ ⟩
subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(_↔_.to (≡⇒↝ _ (sym (trans (cong (λ z → z ≡ x) $
transport-theorem (El a)
(resp a) (resp-id ass a)
univ₁ (≡⇒≃ (refl C)) x)
(cong (λ eq → subst (El a) eq x ≡ x)
(_≃_.left-inverse-of
(≡≃≃ univ₁) (refl C))))))
(subst-refl (El a) x)) ≡⟨ cong (λ eq → subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(_↔_.to (≡⇒↝ _ eq) (subst-refl (El a) x)))
lemma₃ ⟩
subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(_↔_.to (≡⇒↝ _
(cong (λ z → z ≡ x) $ sym
(trans (trans (cong (λ eq → resp a eq x)
≡⇒≃-refl)
(resp-id ass a x))
(sym $ subst-refl (El a) x))))
(subst-refl (El a) x)) ≡⟨ cong (subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl) $ lemma₂ _ _ ⟩
subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl
(trans (trans (trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x))
(sym $ subst-refl (El a) x))
(subst-refl (El a) x)) ≡⟨ cong (λ eq → subst (λ eq → Is-isomorphism a eq x x) ≡⇒≃-refl eq)
(trans-[trans-sym]- _ _) ⟩
subst (λ eq → resp a eq x ≡ x) ≡⇒≃-refl
(trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x)) ≡⟨ subst-∘ (λ z → z ≡ x) (λ eq → resp a eq x) _ ⟩
subst (λ z → z ≡ x)
(cong (λ eq → resp a eq x) ≡⇒≃-refl)
(trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x)) ≡⟨ cong (λ eq → subst (λ z → z ≡ x) eq
(trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x))) $
sym $ sym-sym _ ⟩
subst (λ z → z ≡ x)
(sym $ sym $ cong (λ eq → resp a eq x) ≡⇒≃-refl)
(trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x)) ≡⟨ subst-trans (sym $ cong (λ eq → resp a eq x) ≡⇒≃-refl) ⟩
trans (sym $ cong (λ eq → resp a eq x) ≡⇒≃-refl)
(trans (cong (λ eq → resp a eq x) ≡⇒≃-refl)
(resp-id ass a x)) ≡⟨ sym $ trans-assoc _ _ _ ⟩
trans (trans (sym $ cong (λ eq → resp a eq x) ≡⇒≃-refl)
(cong (λ eq → resp a eq x) ≡⇒≃-refl))
(resp-id ass a x) ≡⟨ cong (λ eq → trans eq _) $ trans-symˡ _ ⟩
trans (refl (resp a Eq.id x)) (resp-id ass a x) ≡⟨ trans-reflˡ _ ⟩∎
resp-id ass a x ∎
------------------------------------------------------------------------
-- A universe of non-recursive, simple types
-- Codes for types.
infixr 20 _⊗_
infixr 15 _⊕_
infixr 10 _⇾_
data U : Type₂ where
id type : U
k : Type₁ → U
_⇾_ _⊗_ _⊕_ : U → U → U
-- Interpretation of types.
El : U → Type₁ → Type₁
El id C = C
El type C = Type
El (k A) C = A
El (a ⇾ b) C = El a C → El b C
El (a ⊗ b) C = El a C × El b C
El (a ⊕ b) C = El a C ⊎ El b C
-- El a preserves logical equivalences.
cast : ∀ a {B C} → B ⇔ C → El a B ⇔ El a C
cast id eq = eq
cast type eq = Logical-equivalence.id
cast (k A) eq = Logical-equivalence.id
cast (a ⇾ b) eq = →-cong _ (cast a eq) (cast b eq)
cast (a ⊗ b) eq = cast a eq ×-cong cast b eq
cast (a ⊕ b) eq = cast a eq ⊎-cong cast b eq
-- El a respects equivalences.
resp : ∀ a {B C} → B ≃ C → El a B → El a C
resp a eq = _⇔_.to (cast a (_≃_.logical-equivalence eq))
resp⁻¹ : ∀ a {B C} → B ≃ C → El a C → El a B
resp⁻¹ a eq = _⇔_.from (cast a (_≃_.logical-equivalence eq))
abstract
-- The cast function respects identities (assuming extensionality).
cast-id : Extensionality (# 1) (# 1) →
∀ a {B} → cast a (Logical-equivalence.id {A = B}) ≡
Logical-equivalence.id
cast-id ext id = refl _
cast-id ext type = refl _
cast-id ext (k A) = refl _
cast-id ext (a ⇾ b) = cong₂ (→-cong _) (cast-id ext a) (cast-id ext b)
cast-id ext (a ⊗ b) = cong₂ _×-cong_ (cast-id ext a) (cast-id ext b)
cast-id ext (a ⊕ b) =
cast a Logical-equivalence.id ⊎-cong cast b Logical-equivalence.id ≡⟨ cong₂ _⊎-cong_ (cast-id ext a) (cast-id ext b) ⟩
Logical-equivalence.id ⊎-cong Logical-equivalence.id ≡⟨ cong₂ (λ f g → record { to = f; from = g })
(apply-ext ext [ refl ∘ inj₁ , refl ∘ inj₂ ])
(apply-ext ext [ refl ∘ inj₁ , refl ∘ inj₂ ]) ⟩∎
Logical-equivalence.id ∎
resp-id : Extensionality (# 1) (# 1) →
∀ a {B} x → resp a (Eq.id {A = B}) x ≡ x
resp-id ext a x = cong (λ eq → _⇔_.to eq x) $ cast-id ext a
-- The universe above is a "universe with some extra stuff".
simple : Universe
simple = record
{ U = U
; El = El
; resp = resp
; resp-id = resp-id ∘ Assumptions.ext₁
}
-- Let us use this universe below.
open Universe simple using (Is-isomorphism)
open Class simple
-- An alternative definition of "being an isomorphism".
--
-- This definition is in bijective correspondence with Is-isomorphism
-- (see below).
Is-isomorphism′ : ∀ a {B C} → B ≃ C → El a B → El a C → Type₁
Is-isomorphism′ id eq = λ x y → _≃_.to eq x ≡ y
Is-isomorphism′ type eq = λ X Y → ↑ _ (X ≃ Y)
Is-isomorphism′ (k A) eq = λ x y → x ≡ y
Is-isomorphism′ (a ⇾ b) eq = Is-isomorphism′ a eq →-rel
Is-isomorphism′ b eq
Is-isomorphism′ (a ⊗ b) eq = Is-isomorphism′ a eq ×-rel
Is-isomorphism′ b eq
Is-isomorphism′ (a ⊕ b) eq = Is-isomorphism′ a eq ⊎-rel
Is-isomorphism′ b eq
-- An alternative definition of Isomorphic, using Is-isomorphism′
-- instead of Is-isomorphism.
Isomorphic′ : ∀ c → Instance c → Instance c → Type₁
Isomorphic′ (a , _) (C , x , _) (D , y , _) =
Σ (C ≃ D) λ eq → Is-isomorphism′ a eq x y
-- El a preserves equivalences (assuming extensionality).
--
-- Note that _≃_.logical-equivalence (cast≃ ext a eq) is
-- (definitionally) equal to cast a (_≃_.logical-equivalence eq); this
-- property is used below.
cast≃ : Extensionality (# 1) (# 1) →
∀ a {B C} → B ≃ C → El a B ≃ El a C
cast≃ ext a {B} {C} B≃C = Eq.↔⇒≃ record
{ surjection = record
{ logical-equivalence = cast a B⇔C
; right-inverse-of = to∘from
}
; left-inverse-of = from∘to
}
where
B⇔C = _≃_.logical-equivalence B≃C
cst : ∀ a → El a B ≃ El a C
cst id = B≃C
cst type = Eq.id
cst (k A) = Eq.id
cst (a ⇾ b) = →-cong ext (cst a) (cst b)
cst (a ⊗ b) = cst a ×-cong cst b
cst (a ⊕ b) = cst a ⊎-cong cst b
abstract
-- The projection _≃_.logical-equivalence is homomorphic with
-- respect to cast a/cst a.
casts-related : ∀ a →
cast a (_≃_.logical-equivalence B≃C) ≡
_≃_.logical-equivalence (cst a)
casts-related id = refl _
casts-related type = refl _
casts-related (k A) = refl _
casts-related (a ⇾ b) = cong₂ (→-cong _) (casts-related a)
(casts-related b)
casts-related (a ⊗ b) = cong₂ _×-cong_ (casts-related a)
(casts-related b)
casts-related (a ⊕ b) = cong₂ _⊎-cong_ (casts-related a)
(casts-related b)
to∘from : ∀ x → _⇔_.to (cast a B⇔C) (_⇔_.from (cast a B⇔C) x) ≡ x
to∘from x =
_⇔_.to (cast a B⇔C) (_⇔_.from (cast a B⇔C) x) ≡⟨ cong₂ (λ f g → f (g x)) (cong _⇔_.to $ casts-related a)
(cong _⇔_.from $ casts-related a) ⟩
_≃_.to (cst a) (_≃_.from (cst a) x) ≡⟨ _≃_.right-inverse-of (cst a) x ⟩∎
x ∎
from∘to : ∀ x → _⇔_.from (cast a B⇔C) (_⇔_.to (cast a B⇔C) x) ≡ x
from∘to x =
_⇔_.from (cast a B⇔C) (_⇔_.to (cast a B⇔C) x) ≡⟨ cong₂ (λ f g → f (g x)) (cong _⇔_.from $ casts-related a)
(cong _⇔_.to $ casts-related a) ⟩
_≃_.from (cst a) (_≃_.to (cst a) x) ≡⟨ _≃_.left-inverse-of (cst a) x ⟩∎
x ∎
private
logical-equivalence-cast≃ :
(ext : Extensionality (# 1) (# 1)) →
∀ a {B C} (eq : B ≃ C) →
_≃_.logical-equivalence (cast≃ ext a eq) ≡
cast a (_≃_.logical-equivalence eq)
logical-equivalence-cast≃ _ _ _ = refl _
-- Alternative, shorter definition of cast≃, based on univalence.
--
-- This proof does not (at the time of writing) have the property that
-- _≃_.logical-equivalence (cast≃′ ass a eq) is definitionally equal
-- to cast a (_≃_.logical-equivalence eq).
cast≃′ : Assumptions → ∀ a {B C} → B ≃ C → El a B ≃ El a C
cast≃′ ass a eq =
Eq.⟨ resp a eq
, resp-is-equivalence (El a) (resp a) (resp-id ext₁ a) univ₁ eq
⟩
where open Assumptions ass
abstract
-- The two definitions of "being an isomorphism" are "isomorphic"
-- (in bijective correspondence), assuming univalence.
is-isomorphism-isomorphic :
Assumptions →
∀ a {B C x y} (eq : B ≃ C) →
Is-isomorphism a eq x y ↔ Is-isomorphism′ a eq x y
is-isomorphism-isomorphic ass id {x = x} {y} eq =
(_≃_.to eq x ≡ y) □
is-isomorphism-isomorphic ass type {x = X} {Y} eq =
(X ≡ Y) ↔⟨ ≡≃≃ univ ⟩
(X ≃ Y) ↝⟨ inverse B.↑↔ ⟩□
↑ _ (X ≃ Y) □
where open Assumptions ass
is-isomorphism-isomorphic ass (k A) {x = x} {y} eq =
(x ≡ y) □
is-isomorphism-isomorphic ass (a ⇾ b) {x = f} {g} eq =
(resp b eq ∘ f ∘ resp⁻¹ a eq ≡ g) ↝⟨ ∘from≡↔≡∘to ext₁ (cast≃ ext₁ a eq) ⟩
(resp b eq ∘ f ≡ g ∘ resp a eq) ↔⟨ inverse $ Eq.extensionality-isomorphism ext₁ ⟩
(∀ x → resp b eq (f x) ≡ g (resp a eq x)) ↝⟨ ∀-cong ext₁ (λ x →
∀-intro (λ y _ → resp b eq (f x) ≡ g y) ext₁) ⟩
(∀ x y → resp a eq x ≡ y → resp b eq (f x) ≡ g y) ↝⟨ ∀-cong ext₁ (λ _ → ∀-cong ext₁ λ _ →
→-cong ext₁ (is-isomorphism-isomorphic ass a eq)
(is-isomorphism-isomorphic ass b eq)) ⟩□
(∀ x y → Is-isomorphism′ a eq x y →
Is-isomorphism′ b eq (f x) (g y)) □
where open Assumptions ass
is-isomorphism-isomorphic ass (a ⊗ b) {x = x , u} {y , v} eq =
((resp a eq x , resp b eq u) ≡ (y , v)) ↝⟨ inverse ≡×≡↔≡ ⟩
(resp a eq x ≡ y × resp b eq u ≡ v) ↝⟨ is-isomorphism-isomorphic ass a eq ×-cong
is-isomorphism-isomorphic ass b eq ⟩□
Is-isomorphism′ a eq x y × Is-isomorphism′ b eq u v □
where open Assumptions ass
is-isomorphism-isomorphic ass (a ⊕ b) {x = inj₁ x} {inj₁ y} eq =
(inj₁ (resp a eq x) ≡ inj₁ y) ↝⟨ inverse B.≡↔inj₁≡inj₁ ⟩
(resp a eq x ≡ y) ↝⟨ is-isomorphism-isomorphic ass a eq ⟩□
Is-isomorphism′ a eq x y □
where open Assumptions ass
is-isomorphism-isomorphic ass (a ⊕ b) {x = inj₂ x} {inj₂ y} eq =
(inj₂ (resp b eq x) ≡ inj₂ y) ↝⟨ inverse B.≡↔inj₂≡inj₂ ⟩
(resp b eq x ≡ y) ↝⟨ is-isomorphism-isomorphic ass b eq ⟩□
Is-isomorphism′ b eq x y □
where open Assumptions ass
is-isomorphism-isomorphic ass (a ⊕ b) {x = inj₁ x} {inj₂ y} eq =
(inj₁ _ ≡ inj₂ _) ↝⟨ inverse $ B.⊥↔uninhabited ⊎.inj₁≢inj₂ ⟩□
⊥ □
is-isomorphism-isomorphic ass (a ⊕ b) {x = inj₂ x} {inj₁ y} eq =
(inj₂ _ ≡ inj₁ _) ↝⟨ inverse $ B.⊥↔uninhabited (⊎.inj₁≢inj₂ ∘ sym) ⟩□
⊥ □
-- The two definitions of isomorphism are "isomorphic" (in bijective
-- correspondence), assuming univalence.
isomorphic-isomorphic :
Assumptions →
∀ c X Y →
Isomorphic c X Y ↔ Isomorphic′ c X Y
isomorphic-isomorphic ass (a , _) (C , x , _) (D , y , _) =
Σ (C ≃ D) (λ eq → Is-isomorphism a eq x y) ↝⟨ ∃-cong (λ eq → is-isomorphism-isomorphic ass a eq) ⟩
Σ (C ≃ D) (λ eq → Is-isomorphism′ a eq x y) □
------------------------------------------------------------------------
-- An example: monoids
monoid : Code
monoid =
-- Binary operation.
(id ⇾ id ⇾ id) ⊗
-- Identity.
id ,
λ { C (_∙_ , e) →
-- The carrier type is a set.
(Is-set C ×
-- Left and right identity laws.
(∀ x → (e ∙ x) ≡ x) ×
(∀ x → (x ∙ e) ≡ x) ×
-- Associativity.
(∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z))) ,
-- The laws are propositional (assuming extensionality).
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (C-set , _) →
×-closure 1 (H-level-propositional ext₁ 2)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set))) }}
-- The interpretation of the code is reasonable.
Instance-monoid :
Instance monoid
≡
Σ Type₁ λ C →
Σ ((C → C → C) × C) λ { (_∙_ , e) →
Is-set C ×
(∀ x → (e ∙ x) ≡ x) ×
(∀ x → (x ∙ e) ≡ x) ×
(∀ x y z → (x ∙ (y ∙ z)) ≡ ((x ∙ y) ∙ z)) }
Instance-monoid = refl _
-- The notion of isomorphism that we get is also reasonable.
Isomorphic-monoid :
∀ {C₁ _∙₁_ e₁ laws₁ C₂ _∙₂_ e₂ laws₂} →
Isomorphic monoid (C₁ , (_∙₁_ , e₁) , laws₁)
(C₂ , (_∙₂_ , e₂) , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
((λ x y → to (from x ∙₁ from y)) , to e₁) ≡ (_∙₂_ , e₂)
Isomorphic-monoid = refl _
-- Note that this definition of isomorphism is isomorphic to a more
-- standard one (assuming extensionality).
Isomorphism-monoid-isomorphic-to-standard :
Extensionality (# 1) (# 1) →
∀ {C₁ _∙₁_ e₁ laws₁ C₂ _∙₂_ e₂ laws₂} →
Isomorphic monoid (C₁ , (_∙₁_ , e₁) , laws₁)
(C₂ , (_∙₂_ , e₂) , laws₂)
↔
Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ x y → to (x ∙₁ y) ≡ (to x ∙₂ to y)) ×
to e₁ ≡ e₂
Isomorphism-monoid-isomorphic-to-standard ext
{C₁} {_∙₁_} {e₁} {laws₁} {C₂} {_∙₂_} {e₂} =
(Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
((λ x y → to (from x ∙₁ from y)) , to e₁) ≡ (_∙₂_ , e₂)) ↝⟨ inverse $ Σ-cong (Eq.↔↔≃ ext (proj₁ laws₁)) (λ _ → _ □) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
((λ x y → to (from x ∙₁ from y)) , to e₁) ≡ (_∙₂_ , e₂)) ↝⟨ inverse $ ∃-cong (λ _ → ≡×≡↔≡) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(λ x y → to (from x ∙₁ from y)) ≡ _∙₂_ ×
to e₁ ≡ e₂) ↔⟨ inverse $ ∃-cong (λ _ → Eq.extensionality-isomorphism ext ×-cong (_ □)) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ x → (λ y → to (from x ∙₁ from y)) ≡ _∙₂_ x) ×
to e₁ ≡ e₂) ↔⟨ inverse $ ∃-cong (λ _ →
∀-cong ext (λ _ → Eq.extensionality-isomorphism ext)
×-cong
(_ □)) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ x y → to (from x ∙₁ from y) ≡ (x ∙₂ y)) ×
to e₁ ≡ e₂) ↔⟨ inverse $ ∃-cong (λ eq →
Π-cong ext (Eq.↔⇒≃ eq) (λ x → Π-cong ext (Eq.↔⇒≃ eq) (λ y →
≡⇒≃ $ sym $ cong₂ (λ u v → _↔_.to eq (u ∙₁ v) ≡
(_↔_.to eq x ∙₂ _↔_.to eq y))
(_↔_.left-inverse-of eq x)
(_↔_.left-inverse-of eq y)))
×-cong
(_ □)) ⟩□
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ x y → to (x ∙₁ y) ≡ (to x ∙₂ to y)) ×
to e₁ ≡ e₂) □
------------------------------------------------------------------------
-- An example: posets
poset : Code
poset =
-- The ordering relation.
(id ⇾ id ⇾ type) ,
λ C _≤_ →
-- The carrier type is a set.
(Is-set C ×
-- The ordering relation is (pointwise) propositional.
(∀ x y → Is-proposition (x ≤ y)) ×
-- Reflexivity.
(∀ x → x ≤ x) ×
-- Transitivity.
(∀ x y z → x ≤ y → y ≤ z → x ≤ z) ×
-- Antisymmetry.
(∀ x y → x ≤ y → y ≤ x → x ≡ y)) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (C-set , ≤-prop , _) →
×-closure 1 (H-level-propositional ext₁ 2)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure (lower-ext (# 0) _ ext₁) 1 λ _ →
H-level-propositional (lower-ext _ _ ext₁) 1)
(×-closure 1 (Π-closure (lower-ext (# 0) _ ext₁) 1 λ _ →
≤-prop _ _)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure (lower-ext (# 0) _ ext₁) 1 λ _ →
Π-closure (lower-ext _ _ ext₁) 1 λ _ →
Π-closure (lower-ext _ _ ext₁) 1 λ _ →
≤-prop _ _)
(Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
C-set)))) }
-- The interpretation of the code is reasonable. (Except, perhaps,
-- that the carrier type lives in Type₁ but the codomain of the
-- ordering relation is Type. In the corresponding example in
-- Univalence-axiom.Isomorphism-is-equality.Simple.Variant the carrier
-- type lives in Type.)
Instance-poset :
Instance poset
≡
Σ Type₁ λ C →
Σ (C → C → Type) λ _≤_ →
Is-set C ×
(∀ x y → Is-proposition (x ≤ y)) ×
(∀ x → x ≤ x) ×
(∀ x y z → x ≤ y → y ≤ z → x ≤ z) ×
(∀ x y → x ≤ y → y ≤ x → x ≡ y)
Instance-poset = refl _
-- The notion of isomorphism that we get is also reasonable. It is the
-- usual notion of "order isomorphism", with two (main) differences:
--
-- * Equivalences are used instead of bijections. However,
-- equivalences and bijections coincide for sets (assuming
-- extensionality).
--
-- * We use equality, (λ a b → from a ≤₁ from b) ≡ _≤₂_, instead of
-- "iff", ∀ a b → (a ≤₁ b) ⇔ (to a ≤₂ to b). However, the ordering
-- relation is pointwise propositional, so these two expressions are
-- equal (assuming univalence).
Isomorphic-poset :
∀ {C₁ _≤₁_ laws₁ C₂ _≤₂_ laws₂} →
Isomorphic poset (C₁ , _≤₁_ , laws₁) (C₂ , _≤₂_ , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
(λ a b → from a ≤₁ from b) ≡ _≤₂_
Isomorphic-poset = refl _
-- We can prove that this notion of isomorphism is isomorphic to the
-- usual notion of order isomorphism (assuming univalence).
Isomorphism-poset-isomorphic-to-order-isomorphism :
Assumptions →
∀ {C₁ _≤₁_ laws₁ C₂ _≤₂_ laws₂} →
Isomorphic poset (C₁ , _≤₁_ , laws₁) (C₂ , _≤₂_ , laws₂)
↔
Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ x y → (x ≤₁ y) ⇔ (to x ≤₂ to y)
Isomorphism-poset-isomorphic-to-order-isomorphism ass
{C₁} {_≤₁_} {laws₁} {C₂} {_≤₂_} {laws₂} =
(Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
(λ a b → from a ≤₁ from b) ≡ _≤₂_) ↝⟨ inverse $ Σ-cong (Eq.↔↔≃ ext₁ (proj₁ laws₁)) (λ _ → _ □) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(λ a b → from a ≤₁ from b) ≡ _≤₂_) ↔⟨ inverse $ ∃-cong (λ _ → Eq.extensionality-isomorphism ext₁) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ a → (λ b → from a ≤₁ from b) ≡ _≤₂_ a)) ↔⟨ inverse $ ∃-cong (λ _ → ∀-cong ext₁ λ _ → Eq.extensionality-isomorphism ext₁) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ a b → (from a ≤₁ from b) ≡ (a ≤₂ b))) ↔⟨ inverse $ ∃-cong (λ eq →
Π-cong ext₁ (Eq.↔⇒≃ eq) λ a → Π-cong ext₁ (Eq.↔⇒≃ eq) λ b →
≡⇒≃ $ sym $ cong₂ (λ x y → (x ≤₁ y) ≡ (_↔_.to eq a ≤₂ _↔_.to eq b))
(_↔_.left-inverse-of eq a)
(_↔_.left-inverse-of eq b)) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ a b → (a ≤₁ b) ≡ (to a ≤₂ to b))) ↔⟨ ∃-cong (λ _ → ∀-cong ext₁ λ _ → ∀-cong ext₁ λ _ → ≡≃≃ univ) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ a b → (a ≤₁ b) ≃ (to a ≤₂ to b))) ↝⟨ inverse $ ∃-cong (λ _ → ∀-cong ext₁ λ _ → ∀-cong (lower-ext (# 0) _ ext₁) λ _ →
Eq.⇔↔≃ (lower-ext _ _ ext₁) (proj₁ (proj₂ laws₁) _ _)
(proj₁ (proj₂ laws₂) _ _)) ⟩□
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
(∀ a b → (a ≤₁ b) ⇔ (to a ≤₂ to b))) □
where open Assumptions ass
-- The previous lemma implies that we can prove that the notion of
-- isomorphism that we get is /equal/ to the usual notion of order
-- isomorphism (assuming univalence).
Isomorphism-poset-equal-to-order-isomorphism :
Assumptions →
∀ {C₁ _≤₁_ laws₁ C₂ _≤₂_ laws₂} →
Isomorphic poset (C₁ , _≤₁_ , laws₁) (C₂ , _≤₂_ , laws₂)
≡
Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ x y → (x ≤₁ y) ⇔ (to x ≤₂ to y)
Isomorphism-poset-equal-to-order-isomorphism ass
{laws₁ = laws₁} {laws₂ = laws₂} =
≃⇒≡ univ₁ $ Eq.↔⇒≃ $
Isomorphism-poset-isomorphic-to-order-isomorphism ass
{laws₁ = laws₁} {laws₂ = laws₂}
where open Assumptions ass
-- The notion of isomorphism that we get if we use Is-isomorphism′
-- instead of Is-isomorphism is also reasonable.
Isomorphic′-poset :
∀ {C₁ _≤₁_ laws₁ C₂ _≤₂_ laws₂} →
Isomorphic′ poset (C₁ , _≤₁_ , laws₁) (C₂ , _≤₂_ , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
∀ a b → to a ≡ b → ∀ c d → to c ≡ d → ↑ _ ((a ≤₁ c) ≃ (b ≤₂ d))
Isomorphic′-poset = refl _
-- If we had defined isomorphism using Is-isomorphism′ instead of
-- Is-isomorphism, then we could have proved
-- Isomorphism-poset-isomorphic-to-order-isomorphism without assuming
-- univalence, but instead assuming extensionality.
Isomorphism′-poset-isomorphic-to-order-isomorphism :
Extensionality (# 1) (# 1) →
∀ {C₁ _≤₁_ laws₁ C₂ _≤₂_ laws₂} →
Isomorphic′ poset (C₁ , _≤₁_ , laws₁) (C₂ , _≤₂_ , laws₂)
↔
Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ x y → (x ≤₁ y) ⇔ (to x ≤₂ to y)
Isomorphism′-poset-isomorphic-to-order-isomorphism ext
{C₁} {_≤₁_} {laws₁} {C₂} {_≤₂_} {laws₂} =
(Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
∀ a b → to a ≡ b → ∀ c d → to c ≡ d → ↑ _ ((a ≤₁ c) ≃ (b ≤₂ d))) ↝⟨ inverse $ Σ-cong (Eq.↔↔≃ ext (proj₁ laws₁)) (λ _ → _ □) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ a b → to a ≡ b → ∀ c d → to c ≡ d → ↑ _ ((a ≤₁ c) ≃ (b ≤₂ d))) ↝⟨ inverse $ ∃-cong (λ _ → ∀-cong ext λ _ →
∀-intro (λ _ _ → _) ext) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ a c d → to c ≡ d → ↑ _ ((a ≤₁ c) ≃ (to a ≤₂ d))) ↝⟨ inverse $ ∃-cong (λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
∀-intro (λ _ _ → _) ext) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ a c → ↑ _ ((a ≤₁ c) ≃ (to a ≤₂ to c))) ↝⟨ ∃-cong (λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
B.↑↔) ⟩
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ a c → (a ≤₁ c) ≃ (to a ≤₂ to c)) ↝⟨ inverse $ ∃-cong (λ _ →
∀-cong ext λ _ → ∀-cong (lower-ext (# 0) _ ext) λ _ →
Eq.⇔↔≃ (lower-ext _ _ ext) (proj₁ (proj₂ laws₁) _ _)
(proj₁ (proj₂ laws₂) _ _)) ⟩□
(Σ (C₁ ↔ C₂) λ eq → let open _↔_ eq in
∀ a c → (a ≤₁ c) ⇔ (to a ≤₂ to c)) □
------------------------------------------------------------------------
-- An example: discrete fields
private
-- Some lemmas used below.
0* :
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(_*_ : C → C → C)
(1# : C)
(-_ : C → C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
∀ x → (0# * x) ≡ 0#
0* _+_ 0# _*_ 1# -_ +-assoc +-comm *-comm *+ +0 *1 +- x =
(0# * x) ≡⟨ sym $ +0 _ ⟩
((0# * x) + 0#) ≡⟨ cong (_+_ _) $ sym $ +- _ ⟩
((0# * x) + (x + (- x))) ≡⟨ +-assoc _ _ _ ⟩
(((0# * x) + x) + (- x)) ≡⟨ cong (λ y → y + _) lemma ⟩
(x + (- x)) ≡⟨ +- x ⟩∎
0# ∎
where
lemma =
((0# * x) + x) ≡⟨ cong (_+_ _) $ sym $ *1 _ ⟩
((0# * x) + (x * 1#)) ≡⟨ cong (λ y → y + (x * 1#)) $ *-comm _ _ ⟩
((x * 0#) + (x * 1#)) ≡⟨ sym $ *+ _ _ _ ⟩
(x * (0# + 1#)) ≡⟨ cong (_*_ _) $ +-comm _ _ ⟩
(x * (1# + 0#)) ≡⟨ cong (_*_ _) $ +0 _ ⟩
(x * 1#) ≡⟨ *1 _ ⟩∎
x ∎
dec-lemma₁ :
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(-_ : C → C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
(∀ x → Dec (x ≡ 0#)) →
Decidable (_≡_ {A = C})
dec-lemma₁ _+_ 0# -_ +-assoc +-comm +0 +- dec-0 x y =
⊎-map (λ x-y≡0 → x ≡⟨ sym $ +0 _ ⟩
(x + 0#) ≡⟨ cong (_+_ _) $ sym $ +- _ ⟩
(x + (y + (- y))) ≡⟨ cong (_+_ _) $ +-comm _ _ ⟩
(x + ((- y) + y)) ≡⟨ +-assoc _ _ _ ⟩
((x + (- y)) + y) ≡⟨ cong (λ x → x + _) x-y≡0 ⟩
(0# + y) ≡⟨ +-comm _ _ ⟩
(y + 0#) ≡⟨ +0 _ ⟩∎
y ∎)
(λ x-y≢0 x≡y → x-y≢0 ((x + (- y)) ≡⟨ cong (_+_ _ ∘ -_) $ sym x≡y ⟩
(x + (- x)) ≡⟨ +- _ ⟩∎
0# ∎))
(dec-0 (x + (- y)))
dec-lemma₂ :
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(_*_ : C → C → C)
(1# : C)
(-_ : C → C) →
(_⁻¹ : C → ↑ (# 1) ⊤ ⊎ C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
0# ≢ 1# →
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) →
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#) →
Decidable (_≡_ {A = C})
dec-lemma₂ _+_ 0# _*_ 1# -_ _⁻¹ +-assoc +-comm *-comm
*+ +0 *1 +- 0≢1 ⁻¹₁ ⁻¹₂ =
dec-lemma₁ _+_ 0# -_ +-assoc +-comm +0 +- dec-0
where
dec-0 : ∀ z → Dec (z ≡ 0#)
dec-0 z with z ⁻¹ | ⁻¹₁ z | ⁻¹₂ z
... | inj₁ _ | hyp | _ = inj₁ (hyp (refl _))
... | inj₂ z⁻¹ | _ | hyp = inj₂ (λ z≡0 →
0≢1 (0# ≡⟨ sym $ 0* _+_ 0# _*_ 1# -_ +-assoc +-comm *-comm *+ +0 *1 +- _ ⟩
(0# * z⁻¹) ≡⟨ cong (λ x → x * _) $ sym z≡0 ⟩
(z * z⁻¹) ≡⟨ hyp z⁻¹ (refl _) ⟩∎
1# ∎))
dec-lemma₃ :
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(-_ : C → C) →
(_*_ : C → C → C)
(1# : C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
(∀ x → (∃ λ y → (x * y) ≡ 1#) Xor (x ≡ 0#)) →
Decidable (_≡_ {A = C})
dec-lemma₃ _+_ 0# -_ _*_ 1# +-assoc *-assoc +-comm *-comm +0 *1 +-
inv-xor =
dec-lemma₁ _+_ 0# -_ +-assoc +-comm +0 +-
(λ x → [ inj₂ ∘ proj₂ , inj₁ ∘ proj₂ ] (inv-xor x))
*-injective :
{C : Type₁}
(_*_ : C → C → C)
(1# : C) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x → (x * 1#) ≡ x) →
∀ x → ∃ (λ y → (x * y) ≡ 1#) → Injective (_*_ x)
*-injective _*_ 1# *-assoc *-comm *1 x (x⁻¹ , xx⁻¹≡1)
{y₁} {y₂} xy₁≡xy₂ =
y₁ ≡⟨ lemma y₁ ⟩
(x⁻¹ * (x * y₁)) ≡⟨ cong (_*_ x⁻¹) xy₁≡xy₂ ⟩
(x⁻¹ * (x * y₂)) ≡⟨ sym $ lemma y₂ ⟩∎
y₂ ∎
where
lemma : ∀ y → y ≡ (x⁻¹ * (x * y))
lemma y =
y ≡⟨ sym $ *1 _ ⟩
(y * 1#) ≡⟨ *-comm _ _ ⟩
(1# * y) ≡⟨ cong (λ x → x * y) $ sym xx⁻¹≡1 ⟩
((x * x⁻¹) * y) ≡⟨ cong (λ x → x * y) $ *-comm _ _ ⟩
((x⁻¹ * x) * y) ≡⟨ sym $ *-assoc _ _ _ ⟩∎
(x⁻¹ * (x * y)) ∎
inverse-propositional :
{C : Type₁}
(_*_ : C → C → C)
(1# : C) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x → (x * 1#) ≡ x) →
Is-set C →
∀ x → Is-proposition (∃ λ y → (x * y) ≡ 1#)
inverse-propositional _*_ 1# *-assoc *-comm *1 C-set x =
[inhabited⇒+]⇒+ 0 λ { inv →
injection⁻¹-propositional
(record { to = _*_ x
; injective = *-injective _*_ 1# *-assoc *-comm *1 x inv
})
C-set 1# }
proposition-lemma₁ :
Extensionality (# 1) (# 1) →
{C : Type₁}
(0# : C)
(_*_ : C → C → C)
(1# : C) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x → (x * 1#) ≡ x) →
Is-proposition (((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#))
proposition-lemma₁ ext 0# _*_ 1# *-assoc *-comm *1 =
[inhabited⇒+]⇒+ 0 λ { (dec , _) →
let C-set = decidable⇒set dec in
×-closure 1 (Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Dec-closure-propositional (lower-ext (# 0) _ ext)
C-set)
(Π-closure ext 1 λ x →
Π-closure ext 1 λ _ →
inverse-propositional _*_ 1# *-assoc *-comm *1
C-set x) }
proposition-lemma₂ :
Extensionality (# 1) (# 1) →
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(-_ : C → C) →
(_*_ : C → C → C)
(1# : C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
Is-proposition (∀ x → (∃ λ y → (x * y) ≡ 1#) Xor (x ≡ 0#))
proposition-lemma₂ ext _+_ 0# -_ _*_ 1# +-assoc *-assoc +-comm *-comm
+0 *1 +- =
[inhabited⇒+]⇒+ 0 λ inv-xor →
let C-set = decidable⇒set $
dec-lemma₃ _+_ 0# -_ _*_ 1# +-assoc *-assoc
+-comm *-comm +0 *1 +- inv-xor in
Π-closure ext 1 λ x →
Xor-closure-propositional (lower-ext (# 0) _ ext)
(inverse-propositional _*_ 1# *-assoc *-comm *1 C-set x)
C-set
proposition-lemma₃ :
Extensionality (# 1) (# 1) →
{C : Type₁}
(_+_ : C → C → C)
(0# : C)
(_*_ : C → C → C)
(1# : C) →
(-_ : C → C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
0# ≢ 1# →
Is-proposition (Σ (C → ↑ _ ⊤ ⊎ C) λ _⁻¹ →
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#))
proposition-lemma₃ ext {C} _+_ 0# _*_ 1# -_ +-assoc *-assoc
+-comm *-comm *+ +0 *1 +- 0≢1
(inv , inv₁ , inv₂) (inv′ , inv₁′ , inv₂′) =
_↔_.to (ignore-propositional-component
(×-closure 1 (Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
C-set)
(Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
C-set)))
(apply-ext ext inv≡inv′)
where
C-set : Is-set C
C-set = decidable⇒set $
dec-lemma₂ _+_ 0# _*_ 1# -_ inv +-assoc +-comm
*-comm *+ +0 *1 +- 0≢1 inv₁ inv₂
01-lemma : ∀ x y → x ≡ 0# → (x * y) ≡ 1# → ⊥
01-lemma x y x≡0 xy≡1 = 0≢1 (
0# ≡⟨ sym $ 0* _+_ 0# _*_ 1# -_ +-assoc +-comm *-comm *+ +0 *1 +- _ ⟩
(0# * y) ≡⟨ cong (λ x → x * _) $ sym x≡0 ⟩
(x * y) ≡⟨ xy≡1 ⟩∎
1# ∎)
inv≡inv′ : ∀ x → inv x ≡ inv′ x
inv≡inv′ x with inv x | inv₁ x | inv₂ x
| inv′ x | inv₁′ x | inv₂′ x
... | inj₁ _ | _ | _ | inj₁ _ | _ | _ = refl _
... | inj₂ x⁻¹ | _ | hyp | inj₁ _ | hyp′ | _ = ⊥-elim $ 01-lemma x x⁻¹ (hyp′ (refl _)) (hyp x⁻¹ (refl _))
... | inj₁ _ | hyp | _ | inj₂ x⁻¹ | _ | hyp′ = ⊥-elim $ 01-lemma x x⁻¹ (hyp (refl _)) (hyp′ x⁻¹ (refl _))
... | inj₂ x⁻¹ | _ | hyp | inj₂ x⁻¹′ | _ | hyp′ =
cong inj₂ $ *-injective _*_ 1# *-assoc *-comm *1 x
(x⁻¹ , hyp x⁻¹ (refl _))
((x * x⁻¹) ≡⟨ hyp x⁻¹ (refl _) ⟩
1# ≡⟨ sym $ hyp′ x⁻¹′ (refl _) ⟩∎
(x * x⁻¹′) ∎)
-- Discrete fields.
discrete-field : Code
discrete-field =
-- Addition.
(id ⇾ id ⇾ id) ⊗
-- Zero.
id ⊗
-- Multiplication.
(id ⇾ id ⇾ id) ⊗
-- One.
id ⊗
-- Minus.
(id ⇾ id) ⊗
-- Multiplicative inverse (a partial operation).
(id ⇾ k (↑ _ ⊤) ⊕ id) ,
λ { C (_+_ , 0# , _*_ , 1# , -_ , _⁻¹) →
(-- Associativity.
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
-- Commutativity.
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
-- Distributivity.
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
-- Identity laws.
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
-- Additive inverse law.
(∀ x → (x + (- x)) ≡ 0#) ×
-- Zero and one are distinct.
0# ≢ 1# ×
-- Multiplicative inverse laws.
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#)) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (+-assoc , _ , +-comm , *-comm , *+ , +0 ,
*1 , +- , 0≢1 , ⁻¹₁ , ⁻¹₂) →
let C-set : Is-set C
C-set = decidable⇒set $
dec-lemma₂ _+_ 0# _*_ 1# -_ _⁻¹ +-assoc +-comm
*-comm *+ +0 *1 +- 0≢1 ⁻¹₁ ⁻¹₂
in
×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure (lower-ext (# 0) (# 1) ext₁) 1 λ _ →
⊥-propositional)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)))))))))) }}
-- The interpretation of the code is reasonable.
Instance-discrete-field :
Instance discrete-field
≡
Σ Type₁ λ C →
Σ ((C → C → C) × C × (C → C → C) × C × (C → C) × (C → ↑ _ ⊤ ⊎ C))
λ { (_+_ , 0# , _*_ , 1# , -_ , _⁻¹) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
(∀ x → (x + (- x)) ≡ 0#) ×
0# ≢ 1# ×
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#) }
Instance-discrete-field = refl _
-- The notion of isomorphism that we get is reasonable.
Isomorphic-discrete-field :
∀ {C₁ _+₁_ 0₁ _*₁_ 1₁ -₁_ _⁻¹₁ laws₁
C₂ _+₂_ 0₂ _*₂_ 1₂ -₂_ _⁻¹₂ laws₂} →
Isomorphic discrete-field
(C₁ , (_+₁_ , 0₁ , _*₁_ , 1₁ , -₁_ , _⁻¹₁) , laws₁)
(C₂ , (_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_ , _⁻¹₂) , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
((λ x y → to (from x +₁ from y)) ,
to 0₁ ,
(λ x y → to (from x *₁ from y)) ,
to 1₁ ,
(λ x → to (-₁ from x)) ,
(λ x → ⊎-map P.id to (from x ⁻¹₁))) ≡
(_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_ , _⁻¹₂)
Isomorphic-discrete-field = refl _
-- The definitions of discrete field introduced below do not have an
-- inverse operator in their signature, so the derived notion of
-- isomorphism is perhaps not obviously identical to the one above.
-- However, the two notions of isomorphism are isomorphic (assuming
-- extensionality).
Isomorphic-discrete-field-isomorphic-to-one-without-⁻¹ :
Extensionality (# 1) (# 1) →
∀ {C₁ _+₁_ 0₁ _*₁_ 1₁ -₁_ _⁻¹₁ laws₁
C₂ _+₂_ 0₂ _*₂_ 1₂ -₂_ _⁻¹₂ laws₂} →
Isomorphic discrete-field
(C₁ , (_+₁_ , 0₁ , _*₁_ , 1₁ , -₁_ , _⁻¹₁) , laws₁)
(C₂ , (_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_ , _⁻¹₂) , laws₂)
↔
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
((λ x y → to (from x +₁ from y)) ,
to 0₁ ,
(λ x y → to (from x *₁ from y)) ,
to 1₁ ,
(λ x → to (-₁ from x))) ≡
(_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_)
Isomorphic-discrete-field-isomorphic-to-one-without-⁻¹ ext
{C₁} {_+₁_} {0₁} {_*₁_} {1₁} { -₁_} {_⁻¹₁}
{_ , _ , _ , _ , _ , _ , _ , _ , _ , ⁻¹₁₁ , ⁻¹₁₂}
{C₂} {_+₂_} {0₂} {_*₂_} {1₂} { -₂_} {_⁻¹₂}
{+₂-assoc , *₂-assoc , +₂-comm , *₂-comm , *₂+₂ , +₂0₂ , *₂1₂ , +₂-₂ ,
0₂≢1₂ , ⁻¹₂₁ , ⁻¹₂₂} =
∃-cong λ eq → let open _≃_ eq in
(((λ x y → to (from x +₁ from y)) ,
to 0₁ ,
(λ x y → to (from x *₁ from y)) ,
to 1₁ ,
(λ x → to (-₁ from x)) ,
(λ x → ⊎-map P.id to (from x ⁻¹₁))) ≡
(_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_ , _⁻¹₂)) ↝⟨ inverse (≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡))))) ⟩
((λ x y → to (from x +₁ from y)) ≡ _+₂_ ×
to 0₁ ≡ 0₂ ×
(λ x y → to (from x *₁ from y)) ≡ _*₂_ ×
to 1₁ ≡ 1₂ ×
(λ x → to (-₁ from x)) ≡ -₂_ ×
(λ x → ⊎-map P.id to (from x ⁻¹₁)) ≡ _⁻¹₂) ↝⟨ (∃-cong λ _ →
∃-cong λ 0-homo →
∃-cong λ *-homo →
∃-cong λ 1-homo →
∃-cong λ _ →
_⇔_.to contractible⇔↔⊤ $ propositional⇒inhabited⇒contractible
⁻¹-set
(⁻¹-homo eq 0-homo *-homo 1-homo)) ⟩
((λ x y → to (from x +₁ from y)) ≡ _+₂_ ×
to 0₁ ≡ 0₂ ×
(λ x y → to (from x *₁ from y)) ≡ _*₂_ ×
to 1₁ ≡ 1₂ ×
(λ x → to (-₁ from x)) ≡ -₂_ ×
⊤) ↝⟨ (_ □) ×-cong (_ □) ×-cong (_ □) ×-cong (_ □) ×-cong ×-right-identity ⟩
((λ x y → to (from x +₁ from y)) ≡ _+₂_ ×
to 0₁ ≡ 0₂ ×
(λ x y → to (from x *₁ from y)) ≡ _*₂_ ×
to 1₁ ≡ 1₂ ×
(λ x → to (-₁ from x)) ≡ -₂_) ↝⟨ ≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡ ⊚ ((_ □) ×-cong
≡×≡↔≡))) ⟩
(((λ x y → to (from x +₁ from y)) ,
to 0₁ ,
(λ x y → to (from x *₁ from y)) ,
to 1₁ ,
(λ x → to (-₁ from x))) ≡
(_+₂_ , 0₂ , _*₂_ , 1₂ , -₂_)) □
where
⁻¹-set : Is-set (C₂ → ↑ _ ⊤ ⊎ C₂)
⁻¹-set =
Π-closure ext 2 λ _ →
⊎-closure 0 (↑-closure 2 (mono (≤-step (≤-step ≤-refl))
⊤-contractible))
(decidable⇒set $
dec-lemma₂ _+₂_ 0₂ _*₂_ 1₂ -₂_ _⁻¹₂ +₂-assoc +₂-comm
*₂-comm *₂+₂ +₂0₂ *₂1₂ +₂-₂ 0₂≢1₂
⁻¹₂₁ ⁻¹₂₂)
⁻¹-homo :
(eq : C₁ ≃ C₂) → let open _≃_ eq in
to 0₁ ≡ 0₂ →
(λ x y → to (from x *₁ from y)) ≡ _*₂_ →
to 1₁ ≡ 1₂ →
(λ x → ⊎-map P.id to (from x ⁻¹₁)) ≡ _⁻¹₂
⁻¹-homo eq 0-homo *-homo 1-homo = cong proj₁ $
proposition-lemma₃
ext _+₂_ 0₂ _*₂_ 1₂ -₂_
+₂-assoc *₂-assoc +₂-comm *₂-comm
*₂+₂ +₂0₂ *₂1₂ +₂-₂ 0₂≢1₂
( (λ x → ⊎-map P.id to (from x ⁻¹₁))
, (λ x x⁻¹₁≡₁ →
let lemma =
(from x ⁻¹₁) ≡⟨ [_,_] {C = λ z → z ≡ ⊎-map P.id from (⊎-map P.id to z)}
(λ _ → refl _)
(λ _ → cong inj₂ $ sym $ left-inverse-of _)
(from x ⁻¹₁) ⟩
⊎-map P.id from (⊎-map P.id to (from x ⁻¹₁)) ≡⟨ cong (⊎-map P.id from) x⁻¹₁≡₁ ⟩∎
inj₁ (lift tt) ∎
in
x ≡⟨ sym $ right-inverse-of x ⟩
to (from x) ≡⟨ cong to (⁻¹₁₁ (from x) lemma) ⟩
to 0₁ ≡⟨ 0-homo ⟩∎
0₂ ∎)
, (λ x y x⁻¹₁≡y →
let lemma =
(from x ⁻¹₁) ≡⟨ [_,_] {C = λ z → z ≡ ⊎-map P.id from (⊎-map P.id to z)}
(λ _ → refl _)
(λ _ → cong inj₂ $ sym $ left-inverse-of _)
(from x ⁻¹₁) ⟩
⊎-map P.id from (⊎-map P.id to (from x ⁻¹₁)) ≡⟨ cong (⊎-map P.id from) x⁻¹₁≡y ⟩∎
inj₂ (from y) ∎
in
(x *₂ y) ≡⟨ sym $ cong (λ _*_ → x * y) *-homo ⟩
to (from x *₁ from y) ≡⟨ cong to $ ⁻¹₁₂ (from x) (from y) lemma ⟩
to 1₁ ≡⟨ 1-homo ⟩∎
1₂ ∎)
)
(_⁻¹₂ , ⁻¹₂₁ , ⁻¹₂₂)
where open _≃_ eq
-- In "Varieties of Constructive Mathematics" Bridges and Richman
-- define a discrete field as a commutative ring with 1, decidable
-- equality, and satisfying the property that non-zero elements are
-- invertible. What follows is—assuming that I interpreted the
-- informal definition correctly—an encoding of this definition,
-- restricted so that the discrete fields are non-trivial, and using
-- equality as the equality relation, and denial inequality as the
-- inequality relation.
discrete-field-à-la-Bridges-and-Richman : Code
discrete-field-à-la-Bridges-and-Richman =
-- Addition.
(id ⇾ id ⇾ id) ⊗
-- Zero.
id ⊗
-- Multiplication.
(id ⇾ id ⇾ id) ⊗
-- One.
id ⊗
-- Minus.
(id ⇾ id) ,
λ { C (_+_ , 0# , _*_ , 1# , -_) →
(-- Associativity.
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
-- Commutativity.
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
-- Distributivity.
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
-- Identity laws.
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
-- Additive inverse law.
(∀ x → (x + (- x)) ≡ 0#) ×
-- Zero and one are distinct.
0# ≢ 1# ×
-- Decidable equality.
((x y : C) → x ≡ y ⊎ x ≢ y) ×
-- Non-zero elements are invertible.
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#)) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (_ , *-assoc , _ , *-comm , _ , _ , *1 ,
_ , _ , dec , _) →
let C-set : Is-set C
C-set = decidable⇒set dec
in
×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure (lower-ext (# 0) (# 1) ext₁) 1 λ _ →
⊥-propositional)
(proposition-lemma₁ ext₁ 0# _*_ 1#
*-assoc *-comm *1))))))))) }}
-- The two discrete field definitions above are isomorphic (assuming
-- extensionality).
Instance-discrete-field-isomorphic-to-Bridges-and-Richman's :
Extensionality (# 1) (# 1) →
Instance discrete-field
↔
Instance discrete-field-à-la-Bridges-and-Richman
Instance-discrete-field-isomorphic-to-Bridges-and-Richman's ext =
∃-cong λ C →
(Σ ((C → C → C) × C × (C → C → C) × C × (C → C) × (C → ↑ _ ⊤ ⊎ C))
λ { (_+_ , 0# , _*_ , 1# , -_ , _⁻¹) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
(∀ x → (x + (- x)) ≡ 0#) ×
0# ≢ 1# ×
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#)}) ↝⟨ lemma₁ _ _ _ _ _ _ _ ⟩
(Σ ((C → C → C) × C × (C → C → C) × C × (C → C))
λ { (_+_ , 0# , _*_ , 1# , -_) →
Σ (C → ↑ _ ⊤ ⊎ C) λ _⁻¹ →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
(∀ x → (x + (- x)) ≡ 0#) ×
0# ≢ 1# ×
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#)}) ↝⟨ ∃-cong (λ _ → lemma₂ _ _ _ _ _ _ _ _ _ _ _) ⟩
(Σ (((C → C → C) × C × (C → C → C) × C × (C → C)))
λ { (_+_ , 0# , _*_ , 1# , -_) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
(∀ x → (x + (- x)) ≡ 0#) ×
0# ≢ 1# ×
Σ (C → ↑ _ ⊤ ⊎ C) λ _⁻¹ →
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#) }) ↝⟨ (∃-cong λ { (_+_ , 0# , _*_ , 1# , -_) →
∃-cong λ +-assoc →
∃-cong λ *-assoc →
∃-cong λ +-comm →
∃-cong λ *-comm →
∃-cong λ *+ →
∃-cong λ +0 →
∃-cong λ *1 →
∃-cong λ +- →
∃-cong λ 0≢1 →
main-lemma C _+_ 0# _*_ 1# -_
+-assoc *-assoc +-comm *-comm *+ +0 *1 +- 0≢1 }) ⟩□
(Σ ((C → C → C) × C × (C → C → C) × C × (C → C))
λ { (_+_ , 0# , _*_ , 1# , -_) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
(∀ x → (x + (- x)) ≡ 0#) ×
0# ≢ 1# ×
((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#) }) □
where
main-lemma :
(C : Type₁)
(_+_ : C → C → C)
(0# : C)
(_*_ : C → C → C)
(1# : C)
(-_ : C → C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
0# ≢ 1# →
(Σ (C → ↑ _ ⊤ ⊎ C) λ _⁻¹ →
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#))
↔
(((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#))
main-lemma C _+_ 0# _*_ 1# -_
+-assoc *-assoc +-comm *-comm *+ +0 *1 +- 0≢1 =
_≃_.bijection $
Eq.⇔→≃
(proposition-lemma₃ ext _+_ 0# _*_ 1# -_
+-assoc *-assoc +-comm *-comm
*+ +0 *1 +- 0≢1)
(proposition-lemma₁ ext 0# _*_ 1# *-assoc *-comm *1)
to
from
where
To = (((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#))
From = Σ (C → ↑ _ ⊤ ⊎ C) λ _⁻¹ →
(∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#) ×
(∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#)
to : From → To
to (_⁻¹ , ⁻¹₁ , ⁻¹₂) = (dec , inv)
where
dec : Decidable (_≡_ {A = C})
dec = dec-lemma₂ _+_ 0# _*_ 1# -_ _⁻¹ +-assoc +-comm *-comm *+
+0 *1 +- 0≢1 ⁻¹₁ ⁻¹₂
inv : ∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#
inv x x≢0 with x ⁻¹ | ⁻¹₁ x | ⁻¹₂ x
... | inj₁ _ | hyp | _ = ⊥-elim $ x≢0 (hyp (refl _))
... | inj₂ y | _ | hyp = y , hyp y (refl _)
from : To → From
from (dec , inv) = (_⁻¹ , ⁻¹₁ , ⁻¹₂)
where
_⁻¹ : C → ↑ _ ⊤ ⊎ C
x ⁻¹ = ⊎-map (λ _ → _) (proj₁ ∘ inv x) (dec x 0#)
⁻¹₁ : ∀ x → (x ⁻¹) ≡ inj₁ (lift tt) → x ≡ 0#
⁻¹₁ x x⁻¹≡₁ with dec x 0#
... | inj₁ x≡0 = x≡0
... | inj₂ x≢0 = ⊥-elim $ ⊎.inj₁≢inj₂ (sym x⁻¹≡₁)
⁻¹₂ : ∀ x y → (x ⁻¹) ≡ inj₂ y → (x * y) ≡ 1#
⁻¹₂ x y x⁻¹≡y with dec x 0#
... | inj₁ x≡0 = ⊥-elim $ ⊎.inj₁≢inj₂ x⁻¹≡y
... | inj₂ x≢0 =
(x * y) ≡⟨ cong (_*_ _) $ sym $ ⊎.cancel-inj₂ x⁻¹≡y ⟩
(x * proj₁ (inv x x≢0)) ≡⟨ proj₂ (inv x x≢0) ⟩∎
1# ∎
lemma₁ : (A B C D E F : Type₁) (G : A × B × C × D × E × F → Type₁) →
Σ (A × B × C × D × E × F) G ↔
Σ (A × B × C × D × E) λ { (a , b , c , d , e) →
Σ F λ f → G (a , b , c , d , e , f) }
lemma₁ A B C D E F G =
Σ (A × B × C × D × E × F) G ↝⟨ Σ-cong (×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚ ×-assoc) (λ _ → _ □) ⟩
(Σ (((((A × B) × C) × D) × E) × F)
λ { (((((a , b) , c) , d) , e) , f) →
G (a , b , c , d , e , f) }) ↝⟨ inverse Σ-assoc ⟩
(Σ ((((A × B) × C) × D) × E)
λ { ((((a , b) , c) , d) , e) →
Σ F λ f → G (a , b , c , d , e , f) }) ↝⟨ Σ-cong (inverse (×-assoc ⊚ ×-assoc ⊚ ×-assoc)) (λ _ → _ □) ⟩□
(Σ (A × B × C × D × E) λ { (a , b , c , d , e) →
Σ F λ f → G (a , b , c , d , e , f) }) □
lemma₂ : (A B C D E F G H I J : Type₁) (K : A → Type₁) →
(Σ A λ x → B × C × D × E × F × G × H × I × J × K x) ↔
(B × C × D × E × F × G × H × I × J × Σ A K)
lemma₂ A B C D E F G H I J K =
(Σ A λ x → B × C × D × E × F × G × H × I × J × K x) ↝⟨ ∃-cong (λ _ → ×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚
×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚ ×-assoc) ⟩
(Σ A λ x → ((((((((B × C) × D) × E) × F) × G) × H) × I) × J) × K x) ↝⟨ ∃-comm ⟩
(((((((((B × C) × D) × E) × F) × G) × H) × I) × J) × Σ A K) ↝⟨ inverse (×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚
×-assoc ⊚ ×-assoc ⊚ ×-assoc ⊚ ×-assoc) ⟩□
(B × C × D × E × F × G × H × I × J × Σ A K) □
-- nLab defines a discrete field as a commutative ring satisfying the
-- property that "an element is invertible xor it equals zero"
-- (http://ncatlab.org/nlab/show/field). This definition can also be
-- encoded in our framework (assuming that I interpreted the informal
-- definitions correctly).
discrete-field-à-la-nLab : Code
discrete-field-à-la-nLab =
-- Addition.
(id ⇾ id ⇾ id) ⊗
-- Zero.
id ⊗
-- Multiplication.
(id ⇾ id ⇾ id) ⊗
-- One.
id ⊗
-- Minus.
(id ⇾ id) ,
λ { C (_+_ , 0# , _*_ , 1# , -_) →
(-- Associativity.
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) ×
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) ×
-- Commutativity.
(∀ x y → (x + y) ≡ (y + x)) ×
(∀ x y → (x * y) ≡ (y * x)) ×
-- Distributivity.
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) ×
-- Identity laws.
(∀ x → (x + 0#) ≡ x) ×
(∀ x → (x * 1#) ≡ x) ×
-- Additive inverse law.
(∀ x → (x + (- x)) ≡ 0#) ×
-- An element is invertible xor it equals zero.
(∀ x → (∃ λ y → (x * y) ≡ 1#) Xor (x ≡ 0#))) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (+-assoc , *-assoc , +-comm , *-comm , _ ,
+0 , *1 , +- , inv-xor) →
let C-set : Is-set C
C-set = decidable⇒set $
dec-lemma₃ _+_ 0# -_ _*_ 1# +-assoc *-assoc
+-comm *-comm +0 *1 +- inv-xor
in
×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
C-set)
(proposition-lemma₂ ext₁ _+_ 0# -_ _*_ 1#
+-assoc *-assoc +-comm *-comm
+0 *1 +-)))))))) }}
-- nLab's definition of discrete fields is isomorphic to the variant
-- of Bridges and Richman's definition given above (assuming
-- extensionality, and assuming that I interpreted the informal
-- definitions correctly).
nLab's-isomorphic-to-Bridges-and-Richman's :
Extensionality (# 1) (# 1) →
Instance discrete-field-à-la-nLab
↔
Instance discrete-field-à-la-Bridges-and-Richman
nLab's-isomorphic-to-Bridges-and-Richman's ext =
∃-cong λ C →
∃-cong λ { (_+_ , 0# , _*_ , 1# , -_) →
∃-cong λ +-assoc →
∃-cong λ *-assoc →
∃-cong λ +-comm →
∃-cong λ *-comm →
∃-cong λ *+ →
∃-cong λ +0 →
∃-cong λ *1 →
∃-cong λ +- →
main-lemma C _+_ 0# _*_ 1# -_
+-assoc *-assoc +-comm *-comm *+ +0 *1 +- }
where
main-lemma :
(C : Type₁)
(_+_ : C → C → C)
(0# : C)
(_*_ : C → C → C)
(1# : C)
(-_ : C → C) →
(∀ x y z → (x + (y + z)) ≡ ((x + y) + z)) →
(∀ x y z → (x * (y * z)) ≡ ((x * y) * z)) →
(∀ x y → (x + y) ≡ (y + x)) →
(∀ x y → (x * y) ≡ (y * x)) →
(∀ x y z → (x * (y + z)) ≡ ((x * y) + (x * z))) →
(∀ x → (x + 0#) ≡ x) →
(∀ x → (x * 1#) ≡ x) →
(∀ x → (x + (- x)) ≡ 0#) →
(∀ x → (∃ λ y → (x * y) ≡ 1#) Xor (x ≡ 0#))
↔
(0# ≢ 1# ×
((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#))
main-lemma C _+_ 0# _*_ 1# -_
+-assoc *-assoc +-comm *-comm *+ +0 *1 +- =
_≃_.bijection $
Eq.⇔→≃
(proposition-lemma₂ ext _+_ 0# -_ _*_ 1#
+-assoc *-assoc +-comm *-comm
+0 *1 +-)
(×-closure 1
(¬-propositional (lower-ext (# 0) _ ext))
(proposition-lemma₁ ext 0# _*_ 1# *-assoc
*-comm *1))
to
from
where
To = 0# ≢ 1# ×
((x y : C) → x ≡ y ⊎ x ≢ y) ×
(∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#)
From = ∀ x → (∃ λ y → (x * y) ≡ 1#) Xor (x ≡ 0#)
to : From → To
to inv-xor = (0≢1 , dec , inv)
where
0≢1 : 0# ≢ 1#
0≢1 0≡1 =
[ (λ { (_ , 1≢0) → 1≢0 (sym 0≡1) })
, (λ { (∄y[1y≡1] , _) → ∄y[1y≡1] (1# , *1 1#) })
] (inv-xor 1#)
dec : Decidable (_≡_ {A = C})
dec = dec-lemma₃ _+_ 0# -_ _*_ 1# +-assoc *-assoc +-comm *-comm
+0 *1 +- inv-xor
inv : ∀ x → x ≢ 0# → ∃ λ y → (x * y) ≡ 1#
inv x x≢0 =
[ proj₁
, (λ { (_ , x≡0) → ⊥-elim (x≢0 x≡0) })
] (inv-xor x)
from : To → From
from (0≢1 , dec , inv) x =
[ (λ x≡0 → inj₂ ( (λ { (y , xy≡1) → 0≢1 (0# ≡⟨ sym $ 0* _+_ 0# _*_ 1# -_ +-assoc +-comm *-comm *+ +0 *1 +- y ⟩
(0# * y) ≡⟨ cong (λ x → x * y) $ sym x≡0 ⟩
(x * y) ≡⟨ xy≡1 ⟩∎
1# ∎) })
, x≡0
))
, (λ x≢0 → inj₁ (inv x x≢0 , x≢0))
] (dec x 0#)
------------------------------------------------------------------------
-- An example: vector spaces over discrete fields
-- Vector spaces over a particular discrete field.
vector-space : Instance discrete-field → Code
vector-space (F , (_+F_ , _ , _*F_ , 1F , _ , _) , _) =
-- Addition.
(id ⇾ id ⇾ id) ⊗
-- Scalar multiplication.
(k F ⇾ id ⇾ id) ⊗
-- Zero vector.
id ⊗
-- Additive inverse.
(id ⇾ id) ,
λ { V (_+_ , _*_ , 0V , -_) →
-- The carrier type is a set.
(Is-set V ×
-- Associativity.
(∀ u v w → (u + (v + w)) ≡ ((u + v) + w)) ×
(∀ x y v → (x * (y * v)) ≡ ((x *F y) * v)) ×
-- Commutativity.
(∀ u v → (u + v) ≡ (v + u)) ×
-- Distributivity.
(∀ x u v → (x * (u + v)) ≡ ((x * u) + (x * v))) ×
(∀ x y v → ((x +F y) * v) ≡ ((x * v) + (y * v))) ×
-- Identity laws.
(∀ v → (v + 0V) ≡ v) ×
(∀ v → (1F * v) ≡ v) ×
-- Inverse law.
(∀ v → (v + (- v)) ≡ 0V)) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (V-set , _) →
×-closure 1 (H-level-propositional ext₁ 2)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
V-set)
(×-closure 1 (Π-closure ext₁ 1 λ _ →
V-set)
(Π-closure ext₁ 1 λ _ →
V-set)))))))) }}
-- The interpretation of the code is reasonable.
Instance-vector-space :
∀ {F _+F_ 0F _*F_ 1F -F_ _⁻¹F laws} →
Instance (vector-space
(F , (_+F_ , 0F , _*F_ , 1F , -F_ , _⁻¹F) , laws))
≡
Σ Type₁ λ V →
Σ ((V → V → V) × (F → V → V) × V × (V → V))
λ { (_+_ , _*_ , 0V , -_) →
Is-set V ×
(∀ u v w → (u + (v + w)) ≡ ((u + v) + w)) ×
(∀ x y v → (x * (y * v)) ≡ ((x *F y) * v)) ×
(∀ u v → (u + v) ≡ (v + u)) ×
(∀ x u v → (x * (u + v)) ≡ ((x * u) + (x * v))) ×
(∀ x y v → ((x +F y) * v) ≡ ((x * v) + (y * v))) ×
(∀ v → (v + 0V) ≡ v) ×
(∀ v → (1F * v) ≡ v) ×
(∀ v → (v + (- v)) ≡ 0V) }
Instance-vector-space = refl _
-- The notion of isomorphism that we get is also reasonable.
Isomorphic-vector-space :
∀ {F V₁ _+₁_ _*₁_ 0₁ -₁_ laws₁
V₂ _+₂_ _*₂_ 0₂ -₂_ laws₂} →
Isomorphic (vector-space F)
(V₁ , (_+₁_ , _*₁_ , 0₁ , -₁_) , laws₁)
(V₂ , (_+₂_ , _*₂_ , 0₂ , -₂_) , laws₂)
≡
Σ (V₁ ≃ V₂) λ eq → let open _≃_ eq in
((λ u v → to (from u +₁ from v)) ,
(λ x v → to (x *₁ from v)) ,
to 0₁ ,
(λ x → to (-₁ from x))) ≡
(_+₂_ , _*₂_ , 0₂ , -₂_)
Isomorphic-vector-space = refl _
------------------------------------------------------------------------
-- An example: sets equipped with fixpoint operators
set-with-fixpoint-operator : Code
set-with-fixpoint-operator =
(id ⇾ id) ⇾ id ,
λ C fix →
-- The carrier type is a set.
(Is-set C ×
-- The fixpoint operator property.
(∀ f → f (fix f) ≡ fix f)) ,
λ ass → let open Assumptions ass in
[inhabited⇒+]⇒+ 0 λ { (C-set , _) →
×-closure 1 (H-level-propositional ext₁ 2)
(Π-closure ext₁ 1 λ _ →
C-set) }
-- Some unfolding lemmas.
Instance-set-with-fixpoint-operator :
Instance set-with-fixpoint-operator
≡
Σ Type₁ λ C →
Σ ((C → C) → C) λ fix →
Is-set C ×
(∀ f → f (fix f) ≡ fix f)
Instance-set-with-fixpoint-operator = refl _
Isomorphic-set-with-fixpoint-operator :
∀ {C₁ fix₁ laws₁ C₂ fix₂ laws₂} →
Isomorphic set-with-fixpoint-operator
(C₁ , fix₁ , laws₁) (C₂ , fix₂ , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
(λ f → to (fix₁ (λ x → from (f (to x))))) ≡ fix₂
Isomorphic-set-with-fixpoint-operator = refl _
Isomorphic′-set-with-fixpoint-operator :
∀ {C₁ fix₁ laws₁ C₂ fix₂ laws₂} →
Isomorphic′ set-with-fixpoint-operator
(C₁ , fix₁ , laws₁) (C₂ , fix₂ , laws₂)
≡
Σ (C₁ ≃ C₂) λ eq → let open _≃_ eq in
∀ f g →
(∀ x y → to x ≡ y → to (f x) ≡ g y) →
to (fix₁ f) ≡ fix₂ g
Isomorphic′-set-with-fixpoint-operator = refl _
| {
"alphanum_fraction": 0.3888344049,
"avg_line_length": 37.7136986301,
"ext": "agda",
"hexsha": "2ffdbe6b618fb95ecc544c51bbc5664e30831fff",
"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/Univalence-axiom/Isomorphism-is-equality/Simple.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/Univalence-axiom/Isomorphism-is-equality/Simple.agda",
"max_line_length": 146,
"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/Univalence-axiom/Isomorphism-is-equality/Simple.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": 31611,
"size": 82593
} |
module Structure.Topology where
open import Logic
import Lvl
open import Sets.ExtensionalPredicateSet renaming (_≡_ to _≡ₛ_) hiding (map)
open import Structure.Setoid
open import Type
-- Definition of topological spaces via open sets.
-- The interpretation is that X is the collection of points and 𝓣 is the collection of open sets of X.
-- (X,𝓣) is called a topological space.
-- 𝓣 is called a topology on X.
record TopologicalSpace {ℓ₁ ℓ₂ ℓ₃} {X : Type{ℓ₁}} ⦃ equiv : Equiv{ℓ₁ Lvl.⊔ ℓ₃}(X) ⦄ (𝓣 : PredSet{ℓ₂}(PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X))) : Type{Lvl.𝐒(Lvl.of(X)) Lvl.⊔ Lvl.of(Type.of(𝓣))} where
field
contains-empty : (∅ ∈ 𝓣)
contains-universe : (𝐔 ∈ 𝓣)
intersection-closure : ∀{A B} → (A ∈ 𝓣) → (B ∈ 𝓣) → ((A ∩ B) ∈ 𝓣)
indexed-union-closure : ∀{I : Type{ℓ₁ Lvl.⊔ ℓ₃}}{Ai : I → PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)} → (∀{i} → (Ai(i) ∈ 𝓣)) → ((⋃ᵢ Ai) ∈ 𝓣)
Open : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt
Open(A) = (A ∈ 𝓣)
Closed : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt
Closed(A) = Open(∁ A)
record Neighborhood (p : X) (N : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where
constructor intro
eta-equality
field
O : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)
⦃ open-set ⦄ : Open(O)
⦃ covers ⦄ : O ⊆ N
⦃ contains-point ⦄ : p ∈ O
open import Data
open import Data.Proofs
open import Data.Either as Either using (_‖_)
open import Data.Either.Setoid
open import Data.Boolean
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
open import Lang.Instance
open import Logic.Propositional
open import Logic.Predicate
open import Lvl.Proofs
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Relator.Proofs
open import Structure.Relator.Properties
open import Structure.Relator
open import Syntax.Function
open import Syntax.Transitivity
module _ where
open import Relator.Equals.Proofs.Equiv{T = Bool} renaming ([≡]-equiv to bool-equiv)
union-closure : ∀{A B} → (A ∈ 𝓣) → (B ∈ 𝓣) → ((A ∪ B) ∈ 𝓣)
union-closure {A}{B} pa pb = substitute₂(_∋_) (reflexivity(_≡_) {x = 𝓣}) (⋃ᵢ-of-bijection ([∃]-intro Lvl.Up.obj) 🝖 ⋃ᵢ-of-boolean) (indexed-union-closure f-proof) where
f-proof : ∀{i} → ((if i then B else A) ∈ 𝓣)
f-proof {𝐹} = pa
f-proof {𝑇} = pb
instance
Neighborhood-unaryRelator : ∀{N} → UnaryRelator(p ↦ Neighborhood p N)
UnaryRelator.substitution Neighborhood-unaryRelator xy (intro O ⦃ contains-point = p ⦄) = intro O ⦃ contains-point = substitute₁(_∈ O) xy p ⦄
-- TODO: Is it usable when defined like this?
record Base {I : Type{ℓ₁ Lvl.⊔ ℓ₃}} (Bi : I → PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) : Stmt{Lvl.𝐒(ℓ₁ Lvl.⊔ ℓ₃)} where
constructor intro
field
covers-space : (∀{x} → (x ∈ (⋃ᵢ Bi)))
generator : (x : X) → (i₁ i₂ : I) → ⦃ _ : (x ∈ (Bi(i₁) ∩ Bi(i₂))) ⦄ → I
generator-contains-point : ∀{x : X}{i₁ i₂ : I} ⦃ _ : x ∈ (Bi(i₁) ∩ Bi(i₂)) ⦄ → (x ∈ Bi(generator x i₁ i₂))
generator-subset : ∀{x : X}{i₁ i₂ : I} ⦃ _ : x ∈ (Bi(i₁) ∩ Bi(i₂)) ⦄ → (Bi(generator x i₁ i₂) ⊆ (Bi(i₁) ∩ Bi(i₂)))
record ClosurePoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where
constructor intro
field proof : ∀{N} → ⦃ _ : Neighborhood(p)(N) ⦄ → NonEmpty(A ∩ N)
instance
ClosurePoint-unaryRelator : ∀{A} → UnaryRelator(ClosurePoint(A))
ClosurePoint.proof (UnaryRelator.substitution ClosurePoint-unaryRelator xy Ax) {N} ⦃ neigh-y ⦄ = [∃]-map-proof id (ClosurePoint.proof Ax {N} ⦃ substitute₁ₗ(p ↦ Neighborhood p N) xy neigh-y ⦄)
InternalPoint = swap Neighborhood
record LimitPoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where
constructor intro
field proof : ∀{N} → ⦃ _ : Neighborhood(p)(N) ⦄ → NonEmpty(A ∩ (N ∖ (• p)))
-- TODO: Use how IsolatedPoint and LimitPoint are related to prove this
instance
postulate LimitPoint-unaryRelator : ∀{A} → UnaryRelator(LimitPoint(A))
{-LimitPoint.proof (UnaryRelator.substitution (LimitPoint-unaryRelator {A = A}) xy (intro proof)) {N} ⦃ neigh ⦄ = substitute₁(_) xy (proof ⦃ substitute₁ₗ(_) xy neigh ⦄) where
instance
inst : UnaryRelator(x ↦ NonEmpty(A ∩ (N ∖ (• x))))
inst = [∘]-unaryRelator {f = x ↦ A ∩ (N ∖ (• x))} ⦃ {!!} ⦄ {P = NonEmpty} ⦃ {!!} ⦄
-}
record IsolatedPoint (A : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)) (p : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where
constructor intro
eta-equality
field
N : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X)
⦃ neighborhood ⦄ : Neighborhood(p)(N)
proof : ((A ∩ N) ≡ₛ (• p))
instance
IsolatedPoint-unaryRelator : ∀{A} → UnaryRelator(IsolatedPoint(A))
UnaryRelator.substitution IsolatedPoint-unaryRelator xy (intro N p) = intro N ⦃ substitute₁(a ↦ Neighborhood a N) xy infer ⦄ (p 🝖 (congruence₁ (•_) ⦃ singleton-function ⦃ equiv ⦄ ⦄ xy))
Closure : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)
Closure(A) = intro(ClosurePoint(A))
Interior : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)
Interior(A) = intro(InternalPoint(A))
∂ : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → PredSet(X)
∂ A = Closure(A) ∖ Interior(A)
Discrete : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt
Discrete(A) = A ⊆ intro(IsolatedPoint(A))
Dense : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt
Dense(A) = Closure(A) ⊆ A
Perfect : PredSet{ℓ₁ Lvl.⊔ ℓ₃}(X) → Stmt
Perfect(A) = ∀{p} → (¬ IsolatedPoint(A)(p))
open import Numeral.Natural
open import Numeral.Natural.Relation.Order using (_>_)
record _converges-to_ (f : ℕ → X) (L : X) : Stmt{Lvl.𝐒(ℓ₁) Lvl.⊔ ℓ₂ Lvl.⊔ Lvl.𝐒(ℓ₃)} where
constructor intro
field
min : ∃(Neighborhood(L)) → ℕ
proof : ∀{NN@([∃]-intro N) : ∃(Neighborhood(L))}{n : ℕ} → (n > min(NN)) → (f(n) ∈ N)
lim : (f : ℕ → X) → ⦃ _ : ∃(f converges-to_) ⦄ → X
lim f ⦃ [∃]-intro L ⦄ = L
module _
{ℓₗ₁ ℓₗ₂ ℓₗ₃} {X : Type{ℓₗ₁}} ⦃ equivₗ : Equiv{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X) ⦄ (𝓣ₗ : PredSet{ℓₗ₂}(PredSet{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X)))
⦃ _ : TopologicalSpace{ℓₗ₁}{ℓₗ₂}{ℓₗ₃} (𝓣ₗ) ⦄
{ℓᵣ₁ ℓᵣ₂ ℓᵣ₃} {Y : Type{ℓᵣ₁}} ⦃ equivᵣ : Equiv{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y) ⦄ (𝓣ᵣ : PredSet{ℓᵣ₂}(PredSet{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y)))
⦃ _ : TopologicalSpace{ℓᵣ₁}{ℓᵣ₂}{ℓᵣ₃} (𝓣ᵣ) ⦄
where
open TopologicalSpace ⦃ … ⦄
open import Logic.Predicate
open import Structure.Function
record ContinuousAt (f : X → Y) ⦃ _ : Function(f) ⦄ (x : X) : Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂} where
constructor intro
field
map : ∃(Neighborhood(f(x))) → ∃(Neighborhood(x))
proof : ∀{NB@([∃]-intro B) : ∃(Neighborhood(f(x)))}
→ let ([∃]-intro A) = map(NB)
in (A ⊆ unmap f(B))
Continuous : (f : X → Y) ⦃ _ : Function(f) ⦄ → Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂}
Continuous(f) = ∀{x} → ContinuousAt f(x)
module _
{ℓₗ₁ ℓₗ₂ ℓₗ₃} {X : Type{ℓₗ₁}} ⦃ equivₗ : Equiv{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X) ⦄ (𝓣ₗ : PredSet{ℓₗ₂}(PredSet{ℓₗ₁ Lvl.⊔ ℓₗ₃}(X)))
⦃ _ : TopologicalSpace{ℓₗ₁}{ℓₗ₂}{ℓₗ₃} (𝓣ₗ) ⦄
{ℓᵣ₁ ℓᵣ₂ ℓᵣ₃} {Y : Type{ℓᵣ₁}} ⦃ equivᵣ : Equiv{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y) ⦄ (𝓣ᵣ : PredSet{ℓᵣ₂}(PredSet{ℓᵣ₁ Lvl.⊔ ℓᵣ₃}(Y)))
⦃ _ : TopologicalSpace{ℓᵣ₁}{ℓᵣ₂}{ℓᵣ₃} (𝓣ᵣ) ⦄
where
open TopologicalSpace ⦃ … ⦄
open import Function.Inverse
open import Structure.Function.Domain hiding (bijective)
open import Structure.Function
record Homeomorphism (f : X → Y) ⦃ func : Function(f) ⦄ : Stmt{Lvl.𝐒(ℓₗ₁ Lvl.⊔ ℓₗ₃ Lvl.⊔ ℓᵣ₁ Lvl.⊔ ℓᵣ₃) Lvl.⊔ ℓₗ₂ Lvl.⊔ ℓᵣ₂} where
constructor intro
field
⦃ invertible ⦄ : Invertible(f)
⦃ continuous ⦄ : Continuous(𝓣ₗ)(𝓣ᵣ) (f)
⦃ continuous-inverse ⦄ : Continuous(𝓣ᵣ)(𝓣ₗ) (inv f) ⦃ inv-function ⦄
| {
"alphanum_fraction": 0.6070115546,
"avg_line_length": 42.3111111111,
"ext": "agda",
"hexsha": "f9ab9224cde7a0c914e651fbf72454c0fc52a964",
"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/Topology.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/Topology.agda",
"max_line_length": 195,
"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/Topology.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": 3605,
"size": 7616
} |
module Issue14 where
open import Haskell.Prelude
-- Wrong name for shadowed lambda
constid : a → b → b
constid x = λ x → x
{-# COMPILE AGDA2HS constid #-}
sectionTest₁ : Nat → Nat → Nat
sectionTest₁ n = _+ n
sectionTest₂ : Nat → Nat → Nat
sectionTest₂ section = _+ section
{-# COMPILE AGDA2HS sectionTest₁ #-}
{-# COMPILE AGDA2HS sectionTest₂ #-}
| {
"alphanum_fraction": 0.6949152542,
"avg_line_length": 17.7,
"ext": "agda",
"hexsha": "517492f98f7b78627dbe0243843e7b059e3079b3",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/Issue14.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/Issue14.agda",
"max_line_length": 36,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "test/Issue14.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 108,
"size": 354
} |
module Data.Vec.Any.Membership.Propositional where
open import Relation.Binary.PropositionalEquality
open import Data.Vec
open import Data.Vec.Any hiding (map)
open import Function.Inverse using (_↔_)
open import Function using (_∘_)
open import Data.Nat
open import Data.Product hiding (map)
import Data.Vec.Any.Membership as Mem
open import Function.Related using (↔⇒)
module _ {a} {A : Set a} where
private module M = Mem (setoid A)
open M public hiding (lose′)
∈′→∈ : ∀ {n x}{xs : Vec A n} → x ∈′ xs → x ∈ xs
∈′→∈ {xs = .(_ ∷ _)} (here refl) = here
∈′→∈ {xs = .(_ ∷ _)} (there p) = there (∈′→∈ p)
∈→∈′ : ∀ {n x}{xs : Vec A n} → x ∈ xs → x ∈′ xs
∈→∈′ {xs = .(_ ∷ _)} here = here refl
∈→∈′ {xs = .(_ ∷ _)} (there p) = there (∈→∈′ p)
∈↔∈′ : ∀ {n x}{xs : Vec A n} → x ∈ xs ↔ x ∈′ xs
∈↔∈′ = record {
to = →-to-⟶ ∈→∈′
; from = →-to-⟶ ∈′→∈
; inverse-of = record {
left-inverse-of = left-inverse
; right-inverse-of = right-inverse
}
}
where
left-inverse : ∀ {n x}{xs : Vec A n}(p : x ∈ xs) → ∈′→∈ (∈→∈′ p) ≡ p
left-inverse {xs = .(_ ∷ _)} here = refl
left-inverse {xs = .(_ ∷ _)} (there p) = cong there (left-inverse p)
right-inverse : ∀ {n x}{xs : Vec A n}(p : x ∈′ xs) → ∈→∈′ (∈′→∈ p) ≡ p
right-inverse {xs = .(_ ∷ _)} (here refl) = refl
right-inverse {xs = .(_ ∷ _)} (there p) = cong there (right-inverse p)
∈′→∈-there : ∀ {n x}{xs : Vec A n}(x∈′xs : x ∈′ xs) → ∈′→∈ (there {x = x} x∈′xs) ≡ there (∈′→∈ x∈′xs)
∈′→∈-there (here refl) = refl
∈′→∈-there (there p) rewrite ∈′→∈-there p = refl
lose′ : ∀ {p}{P : A → Set p} {n x} {xs : Vec A n} →
x ∈′ xs → P x → Any P xs
lose′ {P = P} = M.lose′ (subst P)
open import Function.Related as Related public using (Kind; Symmetric-kind)
renaming (implication to subset
; reverse-implication to superset
; equivalence to set
; injection to subbag
; reverse-injection to superbag
; bijection to bag)
infix 4 _∼[_]_
_∼[_]_ : ∀ {a m n}{A : Set a} → Vec A m → Kind → Vec A n → Set _
xs ∼[ k ] ys = ∀ {x} → (x ∈′ xs) Related.∼[ k ] (x ∈′ ys)
bag-=⇒ : ∀ {k a m n} {A : Set a} {xs : Vec A m} {ys : Vec A n} →
xs ∼[ bag ] ys → xs ∼[ k ] ys
bag-=⇒ xs≈ys = ↔⇒ xs≈ys
| {
"alphanum_fraction": 0.4707766213,
"avg_line_length": 39.6507936508,
"ext": "agda",
"hexsha": "da4281e3da7c850bb96c570782d7cab88f1cb8ff",
"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": "1a60f72b9ea1dd61845311ee97dc380aa542b874",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "tizmd/agda-vector-any",
"max_forks_repo_path": "src/Data/Vec/Any/Membership/Propositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1a60f72b9ea1dd61845311ee97dc380aa542b874",
"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": "tizmd/agda-vector-any",
"max_issues_repo_path": "src/Data/Vec/Any/Membership/Propositional.agda",
"max_line_length": 105,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1a60f72b9ea1dd61845311ee97dc380aa542b874",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "tizmd/agda-vector-any",
"max_stars_repo_path": "src/Data/Vec/Any/Membership/Propositional.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 939,
"size": 2498
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use
-- Data.List.Relation.Binary.Lex.NonStrict directly.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Lex.NonStrict where
open import Data.List.Relation.Binary.Lex.NonStrict public
| {
"alphanum_fraction": 0.4891566265,
"avg_line_length": 31.9230769231,
"ext": "agda",
"hexsha": "e59f2b75d1bd53b7a3716174c2167c71ed28917e",
"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/List/Relation/Lex/NonStrict.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Lex/NonStrict.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/List/Relation/Lex/NonStrict.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 66,
"size": 415
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Indexed monads
------------------------------------------------------------------------
-- Note that currently the monad laws are not included here.
{-# OPTIONS --without-K --safe #-}
module Category.Monad.Indexed where
open import Category.Applicative.Indexed
open import Function
open import Level
record RawIMonad {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
infixl 1 _>>=_ _>>_ _>=>_
infixr 1 _=<<_ _<=<_
field
return : ∀ {i A} → A → M i i A
_>>=_ : ∀ {i j k A B} → M i j A → (A → M j k B) → M i k B
_>>_ : ∀ {i j k A B} → M i j A → M j k B → M i k B
m₁ >> m₂ = m₁ >>= λ _ → m₂
_=<<_ : ∀ {i j k A B} → (A → M j k B) → M i j A → M i k B
f =<< c = c >>= f
_>=>_ : ∀ {i j k a} {A : Set a} {B C} →
(A → M i j B) → (B → M j k C) → (A → M i k C)
f >=> g = _=<<_ g ∘ f
_<=<_ : ∀ {i j k B C a} {A : Set a} →
(B → M j k C) → (A → M i j B) → (A → M i k C)
g <=< f = f >=> g
join : ∀ {i j k A} → M i j (M j k A) → M i k A
join m = m >>= id
rawIApplicative : RawIApplicative M
rawIApplicative = record
{ pure = return
; _⊛_ = λ f x → f >>= λ f' → x >>= λ x' → return (f' x')
}
open RawIApplicative rawIApplicative public
RawIMonadT : ∀ {i f} {I : Set i} (T : IFun I f → IFun I f) → Set (i ⊔ suc f)
RawIMonadT T = ∀ {M} → RawIMonad M → RawIMonad (T M)
record RawIMonadZero {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
field
monad : RawIMonad M
applicativeZero : RawIApplicativeZero M
open RawIMonad monad public
open RawIApplicativeZero applicativeZero using (∅) public
record RawIMonadPlus {i f} {I : Set i} (M : IFun I f) :
Set (i ⊔ suc f) where
field
monad : RawIMonad M
alternative : RawIAlternative M
open RawIMonad monad public
open RawIAlternative alternative using (∅; _∣_) public
monadZero : RawIMonadZero M
monadZero = record
{ monad = monad
; applicativeZero = RawIAlternative.applicativeZero alternative
}
| {
"alphanum_fraction": 0.4997688396,
"avg_line_length": 28.0909090909,
"ext": "agda",
"hexsha": "3b9b12829ef3a2fbad1268282f739f0141365c78",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Category/Monad/Indexed.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Category/Monad/Indexed.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Category/Monad/Indexed.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 779,
"size": 2163
} |
module Logic.Operations where
import Logic.Relations as Rel
import Logic.Equivalence as Eq
open Eq using (Equivalence; module Equivalence)
BinOp : Set -> Set
BinOp A = A -> A -> A
module MonoEq {A : Set}(Eq : Equivalence A) where
module EqEq = Equivalence Eq
open EqEq
Commutative : BinOp A -> Set
Commutative _+_ = (x y : A) -> (x + y) == (y + x)
Associative : BinOp A -> Set
Associative _+_ = (x y z : A) -> (x + (y + z)) == ((x + y) + z)
LeftIdentity : A -> BinOp A -> Set
LeftIdentity z _+_ = (x : A) -> (z + x) == x
RightIdentity : A -> BinOp A -> Set
RightIdentity z _+_ = (x : A) -> (x + z) == x
module Param where
Commutative : {A : Set}(Eq : Equivalence A) -> BinOp A -> Set
Commutative Eq = Op.Commutative
where module Op = MonoEq Eq
Associative : {A : Set}(Eq : Equivalence A) -> BinOp A -> Set
Associative Eq = Op.Associative
where module Op = MonoEq Eq
LeftIdentity : {A : Set}(Eq : Equivalence A) -> A -> BinOp A -> Set
LeftIdentity Eq = Op.LeftIdentity
where module Op = MonoEq Eq
RightIdentity : {A : Set}(Eq : Equivalence A) -> A -> BinOp A -> Set
RightIdentity Eq = Op.RightIdentity
where module Op = MonoEq Eq
| {
"alphanum_fraction": 0.6170568562,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "8671cbfdeeb8c0abf148e60094aa6bcf1108f7de",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Logic/Operations.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Logic/Operations.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Logic/Operations.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": 395,
"size": 1196
} |
module _ (A : Set) (Sing : A → Set) (F : (a : A) → Sing a → Set) where
test : {a : A} → Sing a → Set
test s = F {!!} s
-- WAS: C-c C-s inserts a, which produces a scope error
-- Instead, it should insert _
| {
"alphanum_fraction": 0.5625,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "069eae8cbf9a15a8634833ffa63c90b09e571278",
"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/Issue1073.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/Issue1073.agda",
"max_line_length": 70,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue1073.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 74,
"size": 208
} |
{-# OPTIONS --cubical --no-import-sorts #-}
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Function.Base using (_∋_)
open import MorePropAlgebra.Bundles
import Cubical.Algebra.AbGroup as Std
module MorePropAlgebra.Properties.AbGroup {ℓ} (assumptions : AbGroup {ℓ}) where
open AbGroup assumptions renaming (Carrier to G)
import MorePropAlgebra.Properties.Group
module Group'Properties = MorePropAlgebra.Properties.Group (record { AbGroup assumptions })
module Group' = Group (record { AbGroup assumptions })
( Group') = Group ∋ (record { AbGroup assumptions })
stdIsAbGroup : Std.IsAbGroup 0g _+_ (-_)
stdIsAbGroup .Std.IsAbGroup.isGroup = Group'Properties.stdIsGroup
stdIsAbGroup .Std.IsAbGroup.comm = is-comm
stdAbGroup : Std.AbGroup {ℓ}
stdAbGroup = record { AbGroup assumptions ; isAbGroup = stdIsAbGroup }
| {
"alphanum_fraction": 0.7009443861,
"avg_line_length": 41.4347826087,
"ext": "agda",
"hexsha": "38ff777486a62f4f78f59eccb6a579ed3fb676a5",
"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": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mchristianl/synthetic-reals",
"max_forks_repo_path": "agda/MorePropAlgebra/Properties/AbGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"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": "mchristianl/synthetic-reals",
"max_issues_repo_path": "agda/MorePropAlgebra/Properties/AbGroup.agda",
"max_line_length": 93,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "10206b5c3eaef99ece5d18bf703c9e8b2371bde4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mchristianl/synthetic-reals",
"max_stars_repo_path": "agda/MorePropAlgebra/Properties/AbGroup.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-19T12:15:21.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-31T18:15:26.000Z",
"num_tokens": 248,
"size": 953
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Level
open import Ordinals
module ODC {n : Level } (O : Ordinals {n} ) where
open import zf
open import Data.Nat renaming ( zero to Zero ; suc to Suc ; ℕ to Nat ; _⊔_ to _n⊔_ )
open import Relation.Binary.PropositionalEquality
open import Data.Nat.Properties
open import Data.Empty
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.Core
import OrdUtil
open import logic
open import nat
import OD
import ODUtil
open inOrdinal O
open OD O
open OD.OD
open OD._==_
open ODAxiom odAxiom
open ODUtil O
open Ordinals.Ordinals O
open Ordinals.IsOrdinals isOrdinal
open Ordinals.IsNext isNext
open OrdUtil O
open HOD
open _∧_
postulate
-- mimimul and x∋minimal is an Axiom of choice
minimal : (x : HOD ) → ¬ (x =h= od∅ )→ HOD
-- this should be ¬ (x =h= od∅ )→ ∃ ox → x ∋ Ord ox ( minimum of x )
x∋minimal : (x : HOD ) → ( ne : ¬ (x =h= od∅ ) ) → odef x ( & ( minimal x ne ) )
-- minimality (may proved by ε-induction with LEM)
minimal-1 : (x : HOD ) → ( ne : ¬ (x =h= od∅ ) ) → (y : HOD ) → ¬ ( odef (minimal x ne) (& y)) ∧ (odef x (& y) )
--
-- Axiom of choice in intutionistic logic implies the exclude middle
-- https://plato.stanford.edu/entries/axiom-choice/#AxiChoLog
--
pred-od : ( p : Set n ) → HOD
pred-od p = record { od = record { def = λ x → (x ≡ o∅) ∧ p } ;
odmax = osuc o∅; <odmax = λ x → subst (λ k → k o< osuc o∅) (sym (proj1 x)) <-osuc }
ppp : { p : Set n } { a : HOD } → pred-od p ∋ a → p
ppp {p} {a} d = proj2 d
p∨¬p : ( p : Set n ) → p ∨ ( ¬ p ) -- assuming axiom of choice
p∨¬p p with is-o∅ ( & (pred-od p ))
p∨¬p p | yes eq = case2 (¬p eq) where
ps = pred-od p
eqo∅ : ps =h= od∅ → & ps ≡ o∅
eqo∅ eq = subst (λ k → & ps ≡ k) ord-od∅ ( cong (λ k → & k ) (==→o≡ eq))
lemma : ps =h= od∅ → p → ⊥
lemma eq p0 = ¬x<0 {& ps} (eq→ eq record { proj1 = eqo∅ eq ; proj2 = p0 } )
¬p : (& ps ≡ o∅) → p → ⊥
¬p eq = lemma ( subst₂ (λ j k → j =h= k ) *iso o∅≡od∅ ( o≡→== eq ))
p∨¬p p | no ¬p = case1 (ppp {p} {minimal ps (λ eq → ¬p (eqo∅ eq))} lemma) where
ps = pred-od p
eqo∅ : ps =h= od∅ → & ps ≡ o∅
eqo∅ eq = subst (λ k → & ps ≡ k) ord-od∅ ( cong (λ k → & k ) (==→o≡ eq))
lemma : ps ∋ minimal ps (λ eq → ¬p (eqo∅ eq))
lemma = x∋minimal ps (λ eq → ¬p (eqo∅ eq))
decp : ( p : Set n ) → Dec p -- assuming axiom of choice
decp p with p∨¬p p
decp p | case1 x = yes x
decp p | case2 x = no x
∋-p : (A x : HOD ) → Dec ( A ∋ x )
∋-p A x with p∨¬p ( A ∋ x ) -- LEM
∋-p A x | case1 t = yes t
∋-p A x | case2 t = no (λ x → t x)
double-neg-eilm : {A : Set n} → ¬ ¬ A → A -- we don't have this in intutionistic logic
double-neg-eilm {A} notnot with decp A -- assuming axiom of choice
... | yes p = p
... | no ¬p = ⊥-elim ( notnot ¬p )
open _⊆_
power→⊆ : ( A t : HOD) → Power A ∋ t → t ⊆ A
power→⊆ A t PA∋t = record { incl = λ {x} t∋x → double-neg-eilm (t1 t∋x) } where
t1 : {x : HOD } → t ∋ x → ¬ ¬ (A ∋ x)
t1 = power→ A t PA∋t
OrdP : ( x : Ordinal ) ( y : HOD ) → Dec ( Ord x ∋ y )
OrdP x y with trio< x (& y)
OrdP x y | tri< a ¬b ¬c = no ¬c
OrdP x y | tri≈ ¬a refl ¬c = no ( o<¬≡ refl )
OrdP x y | tri> ¬a ¬b c = yes c
open import zfc
HOD→ZFC : ZFC
HOD→ZFC = record {
ZFSet = HOD
; _∋_ = _∋_
; _≈_ = _=h=_
; ∅ = od∅
; Select = Select
; isZFC = isZFC
} where
-- infixr 200 _∈_
-- infixr 230 _∩_ _∪_
isZFC : IsZFC (HOD ) _∋_ _=h=_ od∅ Select
isZFC = record {
choice-func = choice-func ;
choice = choice
} where
-- Axiom of choice ( is equivalent to the existence of minimal in our case )
-- ∀ X [ ∅ ∉ X → (∃ f : X → ⋃ X ) → ∀ A ∈ X ( f ( A ) ∈ A ) ]
choice-func : (X : HOD ) → {x : HOD } → ¬ ( x =h= od∅ ) → ( X ∋ x ) → HOD
choice-func X {x} not X∋x = minimal x not
choice : (X : HOD ) → {A : HOD } → ( X∋A : X ∋ A ) → (not : ¬ ( A =h= od∅ )) → A ∋ choice-func X not X∋A
choice X {A} X∋A not = x∋minimal A not
| {
"alphanum_fraction": 0.5202241715,
"avg_line_length": 31.8139534884,
"ext": "agda",
"hexsha": "ad23cf4a1a6d78fc5f551cebc29ed928a4436bcc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/zf-in-agda",
"max_forks_repo_path": "src/ODC.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/zf-in-agda",
"max_issues_repo_path": "src/ODC.agda",
"max_line_length": 116,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/zf-in-agda",
"max_stars_repo_path": "src/ODC.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z",
"num_tokens": 1754,
"size": 4104
} |
-- Raw terms, weakening (renaming) and substitution.
{-# OPTIONS --without-K --safe #-}
module Definition.Untyped where
open import Tools.Nat
open import Tools.Product
open import Tools.List
import Tools.PropositionalEquality as PE
infixl 30 _∙_
infix 30 Π_▹_
infixr 22 _▹▹_
infixl 30 _ₛ•ₛ_ _•ₛ_ _ₛ•_
infix 25 _[_]
infix 25 _[_]↑
-- Typing contexts (snoc-lists, isomorphic to lists).
data Con (A : Set) : Set where
ε : Con A -- Empty context.
_∙_ : Con A → A → Con A -- Context extension.
record GenT (A : Set) : Set where
inductive
constructor ⟦_,_⟧
field
l : Nat
t : A
data Kind : Set where
Ukind : Kind
Pikind : Kind
Natkind : Kind
Lamkind : Kind
Appkind : Kind
Zerokind : Kind
Suckind : Kind
Natreckind : Kind
data Term : Set where
var : (x : Nat) → Term
gen : (k : Kind) (c : List (GenT Term)) → Term
-- The Grammar of our language.
-- We represent the expressions of our language as de Bruijn terms.
-- Variables are natural numbers interpreted as de Bruijn indices.
-- Π, lam, and natrec are binders.
-- Type constructors.
U : Term -- Universe.
U = gen Ukind []
pattern Univ u = gen (Ukind u) []
Π_▹_ : (A B : Term) → Term -- Dependent function type (B is a binder).
Π A ▹ B = gen Pikind (⟦ 0 , A ⟧ ∷ ⟦ 1 , B ⟧ ∷ [])
ℕ : Term -- Type of natural numbers.
ℕ = gen Natkind []
-- Lambda-calculus.
-- var : (x : Nat) → Term -- Variable (de Bruijn index).
-- var = var
lam : (t : Term) → Term -- Function abstraction (binder).
lam t = gen Lamkind (⟦ 1 , t ⟧ ∷ [])
_∘_ : (t u : Term) → Term -- Application.
t ∘ u = gen Appkind (⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ [])
-- Introduction and elimination of natural numbers.
zero : Term -- Natural number zero.
zero = gen Zerokind []
suc : (t : Term) → Term -- Successor.
suc t = gen Suckind (⟦ 0 , t ⟧ ∷ [])
natrec : (A t u v : Term) → Term -- Recursor (A is a binder).
natrec A t u v = gen Natreckind (⟦ 1 , A ⟧ ∷ ⟦ 0 , t ⟧ ∷ ⟦ 0 , u ⟧ ∷ ⟦ 0 , v ⟧ ∷ [])
-- Injectivity of term constructors w.r.t. propositional equality.
-- If Π F G = Π H E then F = H and G = E.
Π-PE-injectivity : ∀ {F G H E} → Π F ▹ G PE.≡ Π H ▹ E → F PE.≡ H × G PE.≡ E
Π-PE-injectivity PE.refl = PE.refl , PE.refl
-- If suc n = suc m then n = m.
suc-PE-injectivity : ∀ {n m} → suc n PE.≡ suc m → n PE.≡ m
suc-PE-injectivity PE.refl = PE.refl
-- Neutral terms.
-- A term is neutral if it has a variable in head position.
-- The variable blocks reduction of such terms.
data Neutral : Term → Set where
var : ∀ n → Neutral (var n)
∘ₙ : ∀ {k u} → Neutral k → Neutral (k ∘ u)
natrecₙ : ∀ {C c g k} → Neutral k → Neutral (natrec C c g k)
-- Weak head normal forms (whnfs).
-- These are the (lazy) values of our language.
data Whnf : Term → Set where
-- Type constructors are whnfs.
Uₙ : Whnf U
Πₙ : ∀ {A B} → Whnf (Π A ▹ B)
ℕₙ : Whnf ℕ
-- Introductions are whnfs.
lamₙ : ∀ {t} → Whnf (lam t)
zeroₙ : Whnf zero
sucₙ : ∀ {t} → Whnf (suc t)
-- Neutrals are whnfs.
ne : ∀ {n} → Neutral n → Whnf n
-- Whnf inequalities.
-- Different whnfs are trivially distinguished by propositional equality.
-- (The following statements are sometimes called "no-confusion theorems".)
U≢ℕ : U PE.≢ ℕ
U≢ℕ ()
U≢Π : ∀ {F G} → U PE.≢ Π F ▹ G
U≢Π ()
U≢ne : ∀ {K} → Neutral K → U PE.≢ K
U≢ne () PE.refl
ℕ≢Π : ∀ {F G} → ℕ PE.≢ Π F ▹ G
ℕ≢Π ()
ℕ≢ne : ∀ {K} → Neutral K → ℕ PE.≢ K
ℕ≢ne () PE.refl
Π≢ne : ∀ {F G K} → Neutral K → Π F ▹ G PE.≢ K
Π≢ne () PE.refl
zero≢suc : ∀ {n} → zero PE.≢ suc n
zero≢suc ()
zero≢ne : ∀ {k} → Neutral k → zero PE.≢ k
zero≢ne () PE.refl
suc≢ne : ∀ {n k} → Neutral k → suc n PE.≢ k
suc≢ne () PE.refl
-- Several views on whnfs (note: not recursive).
-- A whnf of type ℕ is either zero, suc t, or neutral.
data Natural : Term → Set where
zeroₙ : Natural zero
sucₙ : ∀ {t} → Natural (suc t)
ne : ∀ {n} → Neutral n → Natural n
-- A (small) type in whnf is either Π A B, ℕ, or neutral.
-- Large types could also be U.
data Type : Term → Set where
Πₙ : ∀ {A B} → Type (Π A ▹ B)
ℕₙ : Type ℕ
ne : ∀{n} → Neutral n → Type n
-- A whnf of type Π A B is either lam t or neutral.
data Function : Term → Set where
lamₙ : ∀{t} → Function (lam t)
ne : ∀{n} → Neutral n → Function n
-- These views classify only whnfs.
-- Natural, Type, and Function are a subsets of Whnf.
naturalWhnf : ∀ {n} → Natural n → Whnf n
naturalWhnf sucₙ = sucₙ
naturalWhnf zeroₙ = zeroₙ
naturalWhnf (ne x) = ne x
typeWhnf : ∀ {A} → Type A → Whnf A
typeWhnf Πₙ = Πₙ
typeWhnf ℕₙ = ℕₙ
typeWhnf (ne x) = ne x
functionWhnf : ∀ {f} → Function f → Whnf f
functionWhnf lamₙ = lamₙ
functionWhnf (ne x) = ne x
------------------------------------------------------------------------
-- Weakening
-- In the following we define untyped weakenings η : Wk.
-- The typed form could be written η : Γ ≤ Δ with the intention
-- that η transport a term t living in context Δ to a context Γ
-- that can bind additional variables (which cannot appear in t).
-- Thus, if Δ ⊢ t : A and η : Γ ≤ Δ then Γ ⊢ wk η t : wk η A.
--
-- Even though Γ is "larger" than Δ we write Γ ≤ Δ to be conformant
-- with subtyping A ≤ B. With subtyping, relation Γ ≤ Δ could be defined as
-- ``for all x ∈ dom(Δ) have Γ(x) ≤ Δ(x)'' (in the sense of subtyping)
-- and this would be the natural extension of weakenings.
data Wk : Set where
id : Wk -- η : Γ ≤ Γ.
step : Wk → Wk -- If η : Γ ≤ Δ then step η : Γ∙A ≤ Δ.
lift : Wk → Wk -- If η : Γ ≤ Δ then lift η : Γ∙A ≤ Δ∙A.
-- Composition of weakening.
-- If η : Γ ≤ Δ and η′ : Δ ≤ Φ then η • η′ : Γ ≤ Φ.
infixl 30 _•_
_•_ : Wk → Wk → Wk
id • η′ = η′
step η • η′ = step (η • η′)
lift η • id = lift η
lift η • step η′ = step (η • η′)
lift η • lift η′ = lift (η • η′)
repeat : {A : Set} → (A → A) → A → Nat → A
repeat f a 0 = a
repeat f a (1+ n) = f (repeat f a n)
-- Weakening of variables.
-- If η : Γ ≤ Δ and x ∈ dom(Δ) then wkVar ρ x ∈ dom(Γ).
wkVar : (ρ : Wk) (n : Nat) → Nat
wkVar id n = n
wkVar (step ρ) n = 1+ (wkVar ρ n)
wkVar (lift ρ) 0 = 0
wkVar (lift ρ) (1+ n) = 1+ (wkVar ρ n)
-- Weakening of terms.
-- If η : Γ ≤ Δ and Δ ⊢ t : A then Γ ⊢ wk η t : wk η A.
mutual
wkGen : (ρ : Wk) (g : List (GenT Term)) → List (GenT Term)
wkGen ρ [] = []
wkGen ρ (⟦ l , t ⟧ ∷ g) = ⟦ l , (wk (repeat lift ρ l) t) ⟧ ∷ wkGen ρ g
wk : (ρ : Wk) (t : Term) → Term
wk ρ (var x) = var (wkVar ρ x)
wk ρ (gen x c) = gen x (wkGen ρ c)
-- Adding one variable to the context requires wk1.
-- If Γ ⊢ t : B then Γ∙A ⊢ wk1 t : wk1 B.
wk1 : Term → Term
wk1 = wk (step id)
-- Weakening of a neutral term.
wkNeutral : ∀ {t} ρ → Neutral t → Neutral (wk ρ t)
wkNeutral ρ (var n) = var (wkVar ρ n)
wkNeutral ρ (∘ₙ n) = ∘ₙ (wkNeutral ρ n)
wkNeutral ρ (natrecₙ n) = natrecₙ (wkNeutral ρ n)
-- Weakening can be applied to our whnf views.
wkNatural : ∀ {t} ρ → Natural t → Natural (wk ρ t)
wkNatural ρ sucₙ = sucₙ
wkNatural ρ zeroₙ = zeroₙ
wkNatural ρ (ne x) = ne (wkNeutral ρ x)
wkType : ∀ {t} ρ → Type t → Type (wk ρ t)
wkType ρ Πₙ = Πₙ
wkType ρ ℕₙ = ℕₙ
wkType ρ (ne x) = ne (wkNeutral ρ x)
wkFunction : ∀ {t} ρ → Function t → Function (wk ρ t)
wkFunction ρ lamₙ = lamₙ
wkFunction ρ (ne x) = ne (wkNeutral ρ x)
wkWhnf : ∀ {t} ρ → Whnf t → Whnf (wk ρ t)
wkWhnf ρ Uₙ = Uₙ
wkWhnf ρ Πₙ = Πₙ
wkWhnf ρ ℕₙ = ℕₙ
wkWhnf ρ lamₙ = lamₙ
wkWhnf ρ zeroₙ = zeroₙ
wkWhnf ρ sucₙ = sucₙ
wkWhnf ρ (ne x) = ne (wkNeutral ρ x)
-- Non-dependent version of Π.
_▹▹_ : Term → Term → Term
A ▹▹ B = Π A ▹ wk1 B
------------------------------------------------------------------------
-- Substitution
-- The substitution operation subst σ t replaces the free de Bruijn indices
-- of term t by chosen terms as specified by σ.
-- The substitution σ itself is a map from natural numbers to terms.
Subst : Set
Subst = Nat → Term
-- Given closed contexts ⊢ Γ and ⊢ Δ,
-- substitutions may be typed via Γ ⊢ σ : Δ meaning that
-- Γ ⊢ σ(x) : (subst σ Δ)(x) for all x ∈ dom(Δ).
--
-- The substitution operation is then typed as follows:
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A, then Γ ⊢ subst σ t : subst σ A.
--
-- Although substitutions are untyped, typing helps us
-- to understand the operation on substitutions.
-- We may view σ as the infinite stream σ 0, σ 1, ...
-- Extract the substitution of the first variable.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ head σ : subst σ A.
head : Subst → Term
head σ = σ 0
-- Remove the first variable instance of a substitution
-- and shift the rest to accommodate.
--
-- If Γ ⊢ σ : Δ∙A then Γ ⊢ tail σ : Δ.
tail : Subst → Subst
tail σ n = σ (1+ n)
-- Substitution of a variable.
--
-- If Γ ⊢ σ : Δ then Γ ⊢ substVar σ x : (subst σ Δ)(x).
substVar : (σ : Subst) (x : Nat) → Term
substVar σ x = σ x
-- Identity substitution.
-- Replaces each variable by itself.
--
-- Γ ⊢ idSubst : Γ.
idSubst : Subst
idSubst = var
-- Weaken a substitution by one.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ wk1Subst σ : Δ.
wk1Subst : Subst → Subst
wk1Subst σ x = wk1 (σ x)
-- Lift a substitution.
--
-- If Γ ⊢ σ : Δ then Γ∙A ⊢ liftSubst σ : Δ∙A.
liftSubst : (σ : Subst) → Subst
liftSubst σ 0 = var 0
liftSubst σ (1+ x) = wk1Subst σ x
-- Transform a weakening into a substitution.
--
-- If ρ : Γ ≤ Δ then Γ ⊢ toSubst ρ : Δ.
toSubst : Wk → Subst
toSubst pr x = var (wkVar pr x)
-- Apply a substitution to a term.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ t : A then Γ ⊢ subst σ t : subst σ A.
mutual
substGen : (σ : Subst) (g : List (GenT Term)) → List (GenT Term)
substGen σ [] = []
substGen σ (⟦ l , t ⟧ ∷ g) = ⟦ l , (subst (repeat liftSubst σ l) t) ⟧ ∷ substGen σ g
subst : (σ : Subst) (t : Term) → Term
subst σ (var x) = substVar σ x
subst σ (gen x c) = gen x (substGen σ c)
-- Extend a substitution by adding a term as
-- the first variable substitution and shift the rest.
--
-- If Γ ⊢ σ : Δ and Γ ⊢ t : subst σ A then Γ ⊢ consSubst σ t : Δ∙A.
consSubst : Subst → Term → Subst
consSubst σ t 0 = t
consSubst σ t (1+ n) = σ n
-- Singleton substitution.
--
-- If Γ ⊢ t : A then Γ ⊢ sgSubst t : Γ∙A.
sgSubst : Term → Subst
sgSubst = consSubst idSubst
-- Compose two substitutions.
--
-- If Γ ⊢ σ : Δ and Δ ⊢ σ′ : Φ then Γ ⊢ σ ₛ•ₛ σ′ : Φ.
_ₛ•ₛ_ : Subst → Subst → Subst
_ₛ•ₛ_ σ σ′ x = subst σ (σ′ x)
-- Composition of weakening and substitution.
--
-- If ρ : Γ ≤ Δ and Δ ⊢ σ : Φ then Γ ⊢ ρ •ₛ σ : Φ.
_•ₛ_ : Wk → Subst → Subst
_•ₛ_ ρ σ x = wk ρ (σ x)
-- If Γ ⊢ σ : Δ and ρ : Δ ≤ Φ then Γ ⊢ σ ₛ• ρ : Φ.
_ₛ•_ : Subst → Wk → Subst
_ₛ•_ σ ρ x = σ (wkVar ρ x)
-- Substitute the first variable of a term with an other term.
--
-- If Γ∙A ⊢ t : B and Γ ⊢ s : A then Γ ⊢ t[s] : B[s].
_[_] : (t : Term) (s : Term) → Term
t [ s ] = subst (sgSubst s) t
-- Substitute the first variable of a term with an other term,
-- but let the two terms share the same context.
--
-- If Γ∙A ⊢ t : B and Γ∙A ⊢ s : A then Γ∙A ⊢ t[s]↑ : B[s]↑.
_[_]↑ : (t : Term) (s : Term) → Term
t [ s ]↑ = subst (consSubst (wk1Subst idSubst) s) t
| {
"alphanum_fraction": 0.5712753597,
"avg_line_length": 25.4874715262,
"ext": "agda",
"hexsha": "f499e9b5aea49e72bafa625c21d74567c2f2c3ff",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "loic-p/logrel-mltt",
"max_forks_repo_path": "Definition/Untyped.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "loic-p/logrel-mltt",
"max_issues_repo_path": "Definition/Untyped.agda",
"max_line_length": 86,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2251b8da423be0c6fb916f2675d7bd8537e4cd96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "loic-p/logrel-mltt",
"max_stars_repo_path": "Definition/Untyped.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4329,
"size": 11189
} |
module Productive where
open import Stream
open import Size
open import Data.Maybe
open import Data.Product
open import Relation.Binary.PropositionalEquality as P
PStream : Set → Set
PStream A = Stream (Maybe A)
mutual
record Productive {A : Set} (s : PStream A) : Set where
coinductive
field
step : EventualOutput s
data EventualOutput {A : Set} (s : PStream A) : Set where
here : (a : A) → s .hd ≡ just a → Productive (s .tl) → EventualOutput s
there : s .hd ≡ nothing → EventualOutput (s .tl) → EventualOutput s
open Productive public
ProdStr : Set → Set
ProdStr A = Σ[ s ∈ PStream A ] (Productive s)
injS : {A : Set} → Stream A → ProdStr A
injS {A} s = (toPStream s , prod s)
where
toPStream : Stream {∞} A → PStream A
toPStream s .hd = just (s .hd)
toPStream s .tl = toPStream (s .tl)
prod : (s : Stream A) → Productive (toPStream s)
prod s .step = here (s .hd) refl (prod (s .tl))
extract : {A : Set} → ProdStr A → Stream A
extract (s , p) = extr s p
where
extr : {A : Set} → (s : PStream A) → Productive s → Stream A
extrμ : {A : Set} → (s : PStream A) → EventualOutput s → Stream A
extr {A} s p = extrμ s (p .step)
extrμ {A} s (here a q p') .hd = a
extrμ {A} s (here a q p') .tl = extr (s .tl) p'
extrμ {A} s (there x p') = extrμ (s .tl) p'
zipS : ∀{A} → ProdStr A → ProdStr A → ProdStr A
zipS {A} (s , p) (t , q) = (z s t , pz p q)
where
z : PStream A → PStream A → PStream A
cz : Maybe A → PStream A → PStream A → PStream A
z s t = cz (s .hd) (s .tl) t
cz (just a) s' t .hd = just a
cz (just a) s' t .tl = z t s'
cz nothing s' t .hd = nothing
cz nothing s' t .tl = cz (s' .hd) (s' .tl) t
pz : {s t : PStream A} → Productive s → Productive t → Productive (z s t)
pcz : {s t : PStream A} → Productive s → Productive t →
Productive (cz (s .hd) (s .tl) t)
pczE : {s t : PStream A} → EventualOutput s → Productive t →
EventualOutput (cz (s .hd) (s .tl) t)
pz p q = pcz p q
pcz p q .step = pczE (p .step) q
pczE {s} (here a s₀≡a p') q with s .hd
pczE {s} (here .a refl p') q | just a = here a refl (pz q p')
pczE {s} (here a () p') q | nothing
pczE {s} (there s₀≡∗ p') q with s .hd
pczE {s} (there () p') q | just a
pczE {s} (there refl p') q | nothing = there refl (pczE p' q)
| {
"alphanum_fraction": 0.5619285121,
"avg_line_length": 31.2467532468,
"ext": "agda",
"hexsha": "7aa93d60b01051e67de96db06f99e27e0f264a3c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hbasold/Sandbox",
"max_forks_repo_path": "Streams/Productive.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hbasold/Sandbox",
"max_issues_repo_path": "Streams/Productive.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8fc7a6cd878f37f9595124ee8dea62258da28aa4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hbasold/Sandbox",
"max_stars_repo_path": "Streams/Productive.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 923,
"size": 2406
} |
{-# OPTIONS --without-K --safe #-}
module Relation.Ternary.Separation.Construct.Product where
open import Level
open import Data.Product
open import Relation.Unary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Separation
open import Data.Product.Relation.Binary.Pointwise.NonDependent
module _ {ℓ₁ ℓ₂} {C₁ : Set ℓ₁} {C₂ : Set ℓ₂} where
_×-⊎_ : RawSep C₁ → RawSep C₂ → RawSep (C₁ × C₂)
R₁ ×-⊎ R₂ =
let
module R₁ = RawSep R₁
module R₂ = RawSep R₂
in record
{ _⊎_≣_ = λ Φ₁ Φ₂ Φ →
(proj₁ Φ₁) R₁.⊎ (proj₁ Φ₂) ≣ proj₁ Φ
× (proj₂ Φ₁) R₂.⊎ (proj₂ Φ₂) ≣ proj₂ Φ }
instance ×-rawsep : ⦃ _ : RawSep C₁ ⦄ ⦃ _ : RawSep C₂ ⦄ → RawSep (C₁ × C₂)
×-rawsep ⦃ R₁ ⦄ ⦃ R₂ ⦄ = R₁ ×-⊎ R₂
module _
{ℓ₁ ℓ₂} {C₁ : Set ℓ₁} {C₂ : Set ℓ₂}
{{R₁ : RawSep C₁}} {{R₂ : RawSep C₂}}
⦃ s₁ : IsSep R₁ ⦄ ⦃ s₂ : IsSep R₂ ⦄
where
instance ×-isSep : IsSep (R₁ ×-⊎ R₂)
×-isSep = record
{ ⊎-comm = λ where (l , r) → ⊎-comm l , ⊎-comm r
; ⊎-assoc = λ where
(l₁ , r₁) (l₂ , r₂) →
let
_ , l₃ , l₄ = ⊎-assoc l₁ l₂
_ , r₃ , r₄ = ⊎-assoc r₁ r₂
in -, (l₃ , r₃) , l₄ , r₄ }
module _
{ℓ₁ ℓ₂} {C₁ : Set ℓ₁} {C₂ : Set ℓ₂}
{{R₁ : RawSep C₁}} {{R₂ : RawSep C₂}} {u₁ u₂}
⦃ s₁ : IsUnitalSep R₁ u₁ ⦄ ⦃ s₂ : IsUnitalSep R₂ u₂ ⦄
where
instance ×-isUnitalSep : IsUnitalSep ×-rawsep (u₁ , u₂)
×-isUnitalSep = record
{ isSep = ×-isSep
; ⊎-idˡ = ⊎-idˡ , ⊎-idˡ
; ⊎-id⁻ˡ = λ where
(fst , snd) → cong₂ _,_ (⊎-id⁻ˡ fst) (⊎-id⁻ˡ snd)
}
instance _×-ε-separation_ : UnitalSep _
_×-ε-separation_ = record
{ isUnitalSep = ×-isUnitalSep }
module _
{ℓ₁ ℓ₂}
⦃ s₁ : Separation ℓ₁ ⦄ ⦃ s₂ : Separation ℓ₂ ⦄
where
private
module S₁ = Separation s₁
module S₂ = Separation s₂
×-separation : Separation _
×-separation = record
{ isSep = ×-isSep {{ _ }} {{ _ }} ⦃ Separation.isSep s₁ ⦄ ⦃ Separation.isSep s₂ ⦄ }
module _
{ℓ₁ ℓ₂}
{C₁ : Set ℓ₁} {C₂ : Set ℓ₂}
⦃ sep₁ : RawSep C₁ ⦄ ⦃ sep₂ : RawSep C₂ ⦄
⦃ s₁ : IsConcattative sep₁ ⦄ ⦃ s₂ : IsConcattative sep₂ ⦄
where
private
module S₁ = IsConcattative s₁
module S₂ = IsConcattative s₂
instance ×-concat : IsConcattative ×-rawsep
×-concat = record
{ _∙_ = (λ where (a , b) (c , d) → (a S₁.∙ c , b S₂.∙ d))
; ⊎-∙ₗ = λ where (p , q) → ⊎-∙ₗ p , ⊎-∙ₗ q }
{- Some useful type-formers for this instance -}
module _ {ℓ} {A : Set ℓ} {{ r : RawSep A }} {u} {{s : IsUnitalSep r u}} where
data Π₁ {p} (P : Pred A p) : Pred (A × A) (ℓ ⊔ p) where
fst : ∀ {a} → P a → Π₁ P (a , ε)
data Π₂ {p} (P : Pred A p) : Pred (A × A) (ℓ ⊔ p) where
snd : ∀ {a} → P a → Π₂ P (ε , a)
| {
"alphanum_fraction": 0.5562913907,
"avg_line_length": 27.18,
"ext": "agda",
"hexsha": "549bdcdf61e2d87d3bcce41d7aa99e2e1730c911",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2020-05-23T00:34:36.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-01-30T14:15:14.000Z",
"max_forks_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/linear.agda",
"max_forks_repo_path": "src/Relation/Ternary/Separation/Construct/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "laMudri/linear.agda",
"max_issues_repo_path": "src/Relation/Ternary/Separation/Construct/Product.agda",
"max_line_length": 87,
"max_stars_count": 34,
"max_stars_repo_head_hexsha": "461077552d88141ac1bba044aa55b65069c3c6c0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/linear.agda",
"max_stars_repo_path": "src/Relation/Ternary/Separation/Construct/Product.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-03T15:22:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T13:57:50.000Z",
"num_tokens": 1291,
"size": 2718
} |
module syntax-util where
open import cedille-types
open import general-util
open import constants
open import json
posinfo-gen : posinfo
posinfo-gen = "generated"
pi-gen = posinfo-gen
first-position : posinfo
first-position = "1"
dummy-var : var
dummy-var = "_dummy"
id-term : term
id-term = Lam ff "x" nothing (Var "x")
tt-term = Lam ff "t" nothing (Lam ff "f" nothing (Var "t"))
ff-term = Lam ff "t" nothing (Lam ff "f" nothing (Var "f"))
compileFailType : type
compileFailType = TpAbs tt "X" (Tkk KdStar) (TpVar "X")
qualif-info : Set
qualif-info = var × args
qualif : Set
qualif = trie qualif-info
tag : Set
tag = string × json
tagged-val : Set
tagged-val = string × rope × 𝕃 tag
tags-to-json : 𝕃 tag → 𝕃 json
tags-to-json [] = []
tags-to-json ts = [ json-object ts ]
tagged-val-to-json : tagged-val → string × json
tagged-val-to-json (t , v , tags) = t , json-array (json-rope v :: tags-to-json tags)
tagged-vals-to-json : 𝕃 tagged-val → json
tagged-vals-to-json = json-object ∘ map tagged-val-to-json
make-tag : (name : string) → (values : 𝕃 tag) → (start : ℕ) → (end : ℕ) → tag
make-tag name vs start end = name , json-object (("start" , json-nat start) :: ("end" , json-nat end) :: vs)
posinfo-to-ℕ : posinfo → ℕ
posinfo-to-ℕ pi with string-to-ℕ pi
posinfo-to-ℕ pi | just n = n
posinfo-to-ℕ pi | nothing = 0 -- should not happen
posinfo-plus : posinfo → ℕ → posinfo
posinfo-plus pi n = ℕ-to-string (posinfo-to-ℕ pi + n)
posinfo-plus-str : posinfo → string → posinfo
posinfo-plus-str pi s = posinfo-plus pi (string-length s)
-- qualify variable by module name
_#_ : string → string → string
fn # v = fn ^ qual-global-str ^ v
_%_ : posinfo → var → string
pi % v = pi ^ qual-local-str ^ v
compileFail : var
compileFail = "compileFail"
compileFail-qual = "" % compileFail
tk-is-type : tpkd → 𝔹
tk-is-type = either-else (const tt) (const ff)
tT-is-term : tmtp → 𝔹
tT-is-term = either-else (const tt) (const ff)
tk-start-pos : ex-tk → posinfo
term-start-pos : ex-tm → posinfo
type-start-pos : ex-tp → posinfo
kind-start-pos : ex-kd → posinfo
term-start-pos (ExApp t x t₁) = term-start-pos t
term-start-pos (ExAppTp t tp) = term-start-pos t
term-start-pos (ExHole pi) = pi
term-start-pos (ExLam pi x _ x₁ x₂ t) = pi
term-start-pos (ExLet pi _ _ _) = pi
term-start-pos (ExOpen pi _ _ _ _) = pi
term-start-pos (ExParens pi t pi') = pi
term-start-pos (ExVar pi x₁) = pi
term-start-pos (ExBeta pi _ _) = pi
term-start-pos (ExIotaPair pi _ _ _ _) = pi
term-start-pos (ExIotaProj t _ _) = term-start-pos t
term-start-pos (ExEpsilon pi _ _ _) = pi
term-start-pos (ExPhi pi _ _ _ _) = pi
term-start-pos (ExRho pi _ _ _ _ _) = pi
term-start-pos (ExChi pi _ _) = pi
term-start-pos (ExDelta pi _ _) = pi
term-start-pos (ExSigma pi _) = pi
term-start-pos (ExTheta pi _ _ _) = pi
term-start-pos (ExMu pi _ _ _ _ _ _) = pi
type-start-pos (ExTpAbs pi _ _ _ _ _) = pi
type-start-pos (ExTpLam pi _ _ _ _) = pi
type-start-pos (ExTpIota pi _ _ _ _) = pi
type-start-pos (ExTpApp t t₁) = type-start-pos t
type-start-pos (ExTpAppt t x) = type-start-pos t
type-start-pos (ExTpArrow t _ t₁) = type-start-pos t
type-start-pos (ExTpEq pi _ _ pi') = pi
type-start-pos (ExTpParens pi _ pi') = pi
type-start-pos (ExTpVar pi x₁) = pi
type-start-pos (ExTpNoSpans t _) = type-start-pos t -- we are not expecting this on input
type-start-pos (ExTpHole pi) = pi --ACG
type-start-pos (ExTpLet pi _ _) = pi
kind-start-pos (ExKdAbs pi _ x x₁ k) = pi
kind-start-pos (ExKdArrow atk k₁) = tk-start-pos atk
kind-start-pos (ExKdHole pi) = pi
kind-start-pos (ExKdParens pi k pi') = pi
kind-start-pos (ExKdVar pi x₁ _) = pi
kind-start-pos (ExKdStar pi) = pi
tk-start-pos (ExTkt t) = type-start-pos t
tk-start-pos (ExTkk k) = kind-start-pos k
term-end-pos : ex-tm → posinfo
type-end-pos : ex-tp → posinfo
kind-end-pos : ex-kd → posinfo
tk-end-pos : ex-tk → posinfo
lterms-end-pos : posinfo → 𝕃 lterm → posinfo
args-end-pos : posinfo → ex-args → posinfo
arg-end-pos : ex-arg → posinfo
kvar-end-pos : posinfo → var → ex-args → posinfo
params-end-pos : posinfo → ex-params → posinfo
param-end-pos : ex-param → posinfo
term-end-pos (ExApp t x t') = term-end-pos t'
term-end-pos (ExAppTp t tp) = type-end-pos tp
term-end-pos (ExHole pi) = posinfo-plus pi 1
term-end-pos (ExLam pi x _ x₁ x₂ t) = term-end-pos t
term-end-pos (ExLet _ _ _ t) = term-end-pos t
term-end-pos (ExOpen pi _ _ _ t) = term-end-pos t
term-end-pos (ExParens pi t pi') = pi'
term-end-pos (ExVar pi x) = posinfo-plus-str pi x
term-end-pos (ExBeta pi _ (just (PosTm t pi'))) = pi'
term-end-pos (ExBeta pi (just (PosTm t pi')) nothing) = pi'
term-end-pos (ExBeta pi nothing nothing) = posinfo-plus pi 1
term-end-pos (ExIotaPair _ _ _ _ pi) = pi
term-end-pos (ExIotaProj _ _ pi) = pi
term-end-pos (ExEpsilon pi _ _ t) = term-end-pos t
term-end-pos (ExPhi _ _ _ _ pi) = pi
term-end-pos (ExRho pi _ _ _ t t') = term-end-pos t'
term-end-pos (ExChi pi T t') = term-end-pos t'
term-end-pos (ExDelta pi oT t) = term-end-pos t
term-end-pos (ExSigma pi t) = term-end-pos t
term-end-pos (ExTheta _ _ t ls) = lterms-end-pos (term-end-pos t) ls
term-end-pos (ExMu _ _ _ _ _ _ pi) = pi
type-end-pos (ExTpAbs pi _ _ _ _ t) = type-end-pos t
type-end-pos (ExTpLam _ _ _ _ t) = type-end-pos t
type-end-pos (ExTpIota _ _ _ _ tp) = type-end-pos tp
type-end-pos (ExTpApp t t') = type-end-pos t'
type-end-pos (ExTpAppt t x) = term-end-pos x
type-end-pos (ExTpArrow t _ t') = type-end-pos t'
type-end-pos (ExTpEq pi _ _ pi') = pi'
type-end-pos (ExTpParens pi _ pi') = pi'
type-end-pos (ExTpVar pi x) = posinfo-plus-str pi x
type-end-pos (ExTpHole pi) = posinfo-plus pi 1
type-end-pos (ExTpNoSpans t pi) = pi
type-end-pos (ExTpLet _ _ t) = type-end-pos t
kind-end-pos (ExKdAbs pi _ x x₁ k) = kind-end-pos k
kind-end-pos (ExKdArrow atk k) = kind-end-pos k
kind-end-pos (ExKdHole pi) = posinfo-plus pi 1
kind-end-pos (ExKdParens pi k pi') = pi'
kind-end-pos (ExKdVar pi x ys) = args-end-pos (posinfo-plus-str pi x) ys
kind-end-pos (ExKdStar pi) = posinfo-plus pi 1
tk-end-pos (ExTkt T) = type-end-pos T
tk-end-pos (ExTkk k) = kind-end-pos k
args-end-pos pi (x :: ys) = args-end-pos (arg-end-pos x) ys
args-end-pos pi [] = pi
arg-end-pos (ExTmArg me t) = term-end-pos t
arg-end-pos (ExTpArg T) = type-end-pos T
kvar-end-pos pi v = args-end-pos (posinfo-plus-str pi v)
params-end-pos pi [] = pi
params-end-pos pi (p :: ps) = params-end-pos (param-end-pos p) ps
param-end-pos (ExParam pi me pi' x atk pi'') = pi''
lterms-end-pos pi [] = pi
lterms-end-pos pi (Lterm _ t :: ls) = lterms-end-pos (term-end-pos t) ls
{- return the end position of the given term if it is there, otherwise
the given posinfo -}
optTerm-end-pos : posinfo → maybe pos-tm → posinfo
optTerm-end-pos pi nothing = pi
optTerm-end-pos pi (just (PosTm x x₁)) = x₁
optTerm-end-pos-beta : posinfo → maybe pos-tm → maybe pos-tm → posinfo
optTerm-end-pos-beta pi _ (just (PosTm x pi')) = pi'
optTerm-end-pos-beta pi (just (PosTm x pi')) nothing = pi'
optTerm-end-pos-beta pi nothing nothing = posinfo-plus pi 1
optAs-or : maybe import-as → posinfo → var → posinfo × var
optAs-or nothing pi x = pi , x
optAs-or (just (ImportAs pi x)) _ _ = pi , x
TpApp-tk : type → var → tpkd → type
TpApp-tk tp x (Tkk _) = TpAppTp tp (TpVar x)
TpApp-tk tp x (Tkt _) = TpAppTm tp (Var x)
-- checking-sythesizing enum
data checking-mode : Set where
checking : checking-mode
synthesizing : checking-mode
untyped : checking-mode
maybe-to-checking : {A : Set} → maybe A → checking-mode
maybe-to-checking (just _) = checking
maybe-to-checking nothing = synthesizing
eq-checking-mode : (m₁ m₂ : checking-mode) → 𝔹
eq-checking-mode checking checking = tt
eq-checking-mode synthesizing synthesizing = tt
eq-checking-mode untyped untyped = tt
eq-checking-mode _ _ = ff
------------------------------------------------------
-- functions intended for building terms for testing
------------------------------------------------------
mlam : var → term → term
mlam x t = Lam ff x nothing t
mall : var → tpkd → type → type
mall = TpAbs tt
mpi : var → tpkd → type → type
mpi = TpAbs ff
imps-to-cmds : imports → cmds
imps-to-cmds = map CmdImport
cmds-to-imps : cmds → imports
cmds-to-imps [] = []
cmds-to-imps (CmdImport i :: cs) = i :: cmds-to-imps cs
cmds-to-imps (_ :: cs) = cmds-to-imps cs
ex-cmds-to-imps : ex-cmds → ex-imports
ex-cmds-to-imps [] = []
ex-cmds-to-imps (ExCmdImport i :: cs) = i :: ex-cmds-to-imps cs
ex-cmds-to-imps (_ :: cs) = ex-cmds-to-imps cs
split-var-h : 𝕃 char → 𝕃 char × 𝕃 char
split-var-h [] = [] , []
split-var-h (qual-global-chr :: xs) = [] , xs
split-var-h (x :: xs) with split-var-h xs
... | xs' , ys = (x :: xs') , ys
split-var : var → var × var
split-var v with split-var-h (reverse (string-to-𝕃char v))
... | xs , ys = 𝕃char-to-string (reverse ys) , 𝕃char-to-string (reverse xs)
var-suffix : var → maybe var
var-suffix v with split-var v
... | "" , _ = nothing
... | _ , sfx = just sfx
-- unique qualif domain prefixes
qual-pfxs : qualif → 𝕃 var
qual-pfxs q = uniq (prefixes (trie-strings q))
where
uniq : 𝕃 var → 𝕃 var
uniq vs = stringset-strings (stringset-insert* empty-stringset vs)
prefixes : 𝕃 var → 𝕃 var
prefixes [] = []
prefixes (v :: vs) with split-var v
... | "" , sfx = vs
... | pfx , sfx = pfx :: prefixes vs
unqual-prefix : qualif → 𝕃 var → var → var → var
unqual-prefix q [] sfx v = v
unqual-prefix q (pfx :: pfxs) sfx v
with trie-lookup q (pfx # sfx)
... | just (v' , _) = if v =string v' then pfx # sfx else v
... | nothing = v
unqual-bare : qualif → var → var → var
unqual-bare q sfx v with trie-lookup q sfx
... | just (v' , _) = if v =string v' then sfx else v
... | nothing = v
unqual-local : var → var
unqual-local v = f' (string-to-𝕃char v) where
f : 𝕃 char → maybe (𝕃 char)
f [] = nothing
f ('@' :: t) = f t maybe-or just t
f (h :: t) = f t
f' : 𝕃 char → string
f' (meta-var-pfx :: t) = maybe-else' (f t) v (𝕃char-to-string ∘ _::_ meta-var-pfx)
f' t = maybe-else' (f t) v 𝕃char-to-string
unqual-all : qualif → var → string
unqual-all q v with var-suffix v
... | nothing = v
... | just sfx = unqual-bare q sfx (unqual-prefix q (qual-pfxs q) sfx v)
-- Given a qualified variable and a function that renames it,
-- we strip away the qualification prefix, call the function,
-- then prepend the prefix to the result
reprefix : (var → var) → var → var
reprefix f x =
maybe-else' (pfx (string-to-𝕃char x) [])
(f x) $ uncurry λ p s → p ^ f s where
ret : 𝕃 char → 𝕃 char → maybe (var × var)
ret pfx sfx = just (𝕃char-to-string (reverse pfx) , 𝕃char-to-string sfx)
pfx : 𝕃 char → 𝕃 char → maybe (var × var)
pfx (qual-global-chr :: xs) acc =
pfx xs (qual-global-chr :: acc) maybe-or ret (qual-global-chr :: acc) xs
pfx (qual-local-chr :: xs) acc =
pfx xs (qual-local-chr :: acc) maybe-or ret (qual-local-chr :: acc) xs
pfx (x :: xs) acc = pfx xs (x :: acc)
pfx [] pfx = nothing
data-to/ = reprefix ("to/" ^_)
data-Is/ = reprefix ("Is/" ^_)
data-is/ = reprefix ("is/" ^_)
mu-Type/ = reprefix ("Type/" ^_)
mu-isType/ = reprefix ("isType/" ^_)
mu-isType/' = reprefix ("is" ^_)
-- Generated during elaboration
data-TypeF/ = reprefix ("F/" ^_)
data-IndF/ = reprefix ("IndF/" ^_)
data-fmap/ = reprefix ("fmap/" ^_)
--
num-gt : num → ℕ → 𝕃 string
num-gt n n' = maybe-else [] (λ n'' → if n'' > n' then [ n ] else []) (string-to-ℕ n)
nums-gt : 𝕃 num → ℕ → 𝕃 string
nums-gt [] n' = []
nums-gt (n :: ns) n' =
maybe-else [] (λ n'' → if n'' > n' || iszero n'' then [ n ] else []) (string-to-ℕ n)
++ nums-gt ns n'
nums-to-stringset : 𝕃 num → stringset × 𝕃 string {- Repeated numbers -}
nums-to-stringset [] = empty-stringset , []
nums-to-stringset (n :: ns) with nums-to-stringset ns
...| ss , rs = if stringset-contains ss n
then ss , n :: rs
else stringset-insert ss n , rs
optNums-to-stringset : maybe (𝕃 num) → maybe stringset × (ℕ → maybe string)
optNums-to-stringset nothing = nothing , λ _ → nothing
optNums-to-stringset (just ns) with nums-to-stringset ns
...| ss , [] = just ss , λ n → case nums-gt ns n of λ where
[] → nothing
ns-g → just ("Occurrences not found: " ^ 𝕃-to-string id ", " ns-g ^ " (total occurrences: " ^ ℕ-to-string n ^ ")")
...| ss , rs = just ss , λ n →
just ("The list of occurrences contains the following repeats: " ^ 𝕃-to-string id ", " rs)
def-var : ex-def → var
def-var (ExDefTerm _ x _ _) = x
def-var (ExDefType _ x _ _) = x
-- expression descriptor
data exprd : Set where
TERM : exprd
TYPE : exprd
KIND : exprd
-- TPKD : exprd
⟦_⟧ : exprd → Set
⟦ TERM ⟧ = term
⟦ TYPE ⟧ = type
⟦ KIND ⟧ = kind
--⟦ TPKD ⟧ = tpkd
⟦_⟧' : exprd → Set
⟦ TERM ⟧' = ex-tm
⟦ TYPE ⟧' = ex-tp
⟦ KIND ⟧' = ex-kd
--⟦ TPKD ⟧' = ex-tk
exprd-name : exprd → string
exprd-name TERM = "term"
exprd-name TYPE = "type"
exprd-name KIND = "kind"
infixl 12 _-tk_ _-tk'_ _-tT_ _-tT'_ _-arg_ _-arg'_
_-tk_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → tpkd → tpkd
f -tk Tkt T = Tkt (f T)
f -tk Tkk k = Tkk (f k)
_-tk'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → tpkd → X
f -tk' Tkt T = f T
f -tk' Tkk k = f k
_-tT_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → tmtp → tmtp
f -tT Ttm t = Ttm (f t)
f -tT Ttp T = Ttp (f T)
_-tT'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → tmtp → X
f -tT' Ttm t = f t
f -tT' Ttp T = f T
_-arg_ : (∀ {ed} → ⟦ ed ⟧ → ⟦ ed ⟧) → arg → arg
f -arg Arg t = Arg (f t)
f -arg ArgE tT = ArgE (f -tT tT)
_-arg'_ : ∀ {X : Set} → (∀ {ed : exprd} → ⟦ ed ⟧ → X) → arg → X
f -arg' Arg t = f t
f -arg' ArgE tT = f -tT' tT
pos-tm-to-tm : pos-tm → ex-tm
pos-tm-to-tm (PosTm t pi) = t
ex-case-arg-erased : ex-case-arg-sym → erased?
ex-case-arg-erased ExCaseArgTm = ff
ex-case-arg-erased _ = tt
ex-case-ctr : ex-case → var
ex-case-ctr (ExCase pi x cas t) = x
start-modname : ex-file → string
start-modname (ExModule _ _ _ mn _ _ _) = mn
{-
traverse-internal : ∀ {ed} {X} → (∀ {ed} → X → ⟦ ed ⟧ → X × ⟦ ed ⟧) → X → ⟦ ed ⟧ → ⟦ ed ⟧
traverse-internal {_} {X} f = h (fr ff) where
fr : ∀ {ed} → 𝔹 → (X → ⟦ ed ⟧ → ⟦ ed ⟧)
fr tt = f
fr ff = λ x t → t
h : ∀ {ed} → (∀ {ed} → X → ⟦ ed ⟧ → X × ⟦ ed ⟧) → X → ⟦ ed ⟧ → ⟦ ed ⟧
h {TERM} f (App t t') = ?
h {TERM} f (AppE t tT) = ?
h {TERM} f (Beta t t') = ?
h {TERM} f (Delta T t) = ?
h {TERM} f (Hole pi) = ?
h {TERM} f (Internal r t) = ?
h {TERM} f (IotaPair t t' x T) =?
h {TERM} f (IotaProj t n) = ?
h {TERM} f (Lam me x tk t) = ?
h {TERM} f (LetTm me x T? t t') = ?
h {TERM} f (LetTp x k T t) = ?
h {TERM} f (Phi tₑ t₁ t₂) = ?
h {TERM} f (Rho t x T t') = ?
h {TERM} f (Sigma t) = ?
h {TERM} f (Mu μ t T t~ cs) = ?
h {TERM} f (Var x) = ?
h {TYPE} f (TpAbs me x tk T) = ?
h {TYPE} f (TpIota x T₁ T₂) = ?
h {TYPE} f (TpApp T tT) = ?
h {TYPE} f (TpEq t₁ t₂) = ?
h {TYPE} f (TpHole pi) = ?
h {TYPE} f (TpLam x tk T) = ?
h {TYPE} f (TpVar x) = ?
h {KIND} f KdStar = ?
h {KIND} f (KdHole pi) = ?
h {KIND} f (KdAbs x tk k) = ?
-}
| {
"alphanum_fraction": 0.619047619,
"avg_line_length": 31.2568421053,
"ext": "agda",
"hexsha": "3fcb9609604ec2f0702fc707b05187d0de9edd31",
"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": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zmthy/cedille",
"max_forks_repo_path": "src/syntax-util.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"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": "zmthy/cedille",
"max_issues_repo_path": "src/syntax-util.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9df4b85b55b57f97466242fdbb499adbd3bca893",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zmthy/cedille",
"max_stars_repo_path": "src/syntax-util.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5517,
"size": 14847
} |
module Data.Interval where
data Interval (A : Set) : Set where
[_▻_] : A -> A -> Interval A
lowerBound : {A : Set} -> Interval A -> A
lowerBound [ l ▻ u ] = l
upperBound : {A : Set} -> Interval A -> A
upperBound [ l ▻ u ] = u
| {
"alphanum_fraction": 0.5751072961,
"avg_line_length": 17.9230769231,
"ext": "agda",
"hexsha": "9ba4d85e5b98378ed83d6ce4c107267c5236881f",
"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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Interval.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": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Interval.agda",
"max_line_length": 41,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/outdated-and-incorrect/AIM6/Cat/lib/Data/Interval.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": 80,
"size": 233
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Pointed.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Structure
open import Cubical.Foundations.Structure using (typ) public
open import Cubical.Foundations.GroupoidLaws
Pointed : (ℓ : Level) → Type (ℓ-suc ℓ)
Pointed ℓ = TypeWithStr ℓ (λ x → x)
pt : ∀ {ℓ} (A∙ : Pointed ℓ) → typ A∙
pt = str
Pointed₀ = Pointed ℓ-zero
{- Pointed functions -}
_→∙_ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Type (ℓ-max ℓ ℓ')
_→∙_ A B = Σ[ f ∈ (typ A → typ B) ] f (pt A) ≡ pt B
_→∙_∙ : ∀{ℓ ℓ'} → (A : Pointed ℓ) (B : Pointed ℓ') → Pointed (ℓ-max ℓ ℓ')
A →∙ B ∙ = (A →∙ B) , (λ x → pt B) , refl
idfun∙ : ∀ {ℓ} (A : Pointed ℓ) → A →∙ A
idfun∙ A = (λ x → x) , refl
| {
"alphanum_fraction": 0.6180469716,
"avg_line_length": 28.8928571429,
"ext": "agda",
"hexsha": "0325ae714671a739259624cafc9f048a26372ce0",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"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": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_line_length": 73,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ayberkt/cubical",
"max_stars_repo_path": "Cubical/Foundations/Pointed/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 343,
"size": 809
} |
-- Andreas, 2020-01-28, issue #4399, reported by G. Brunerie
postulate
A : Set
data T : Set where
tt : T
f : {x : A} {{_ : T}} → A
f {{ p }} = {!p!}
-- Problem was:
-- Splitting on p produced pattern {{_ = tt}}
-- which was interpreted as cubical partial split.
-- Expected:
-- Splitting on p should produce an unnamed pattern.
| {
"alphanum_fraction": 0.6231454006,
"avg_line_length": 18.7222222222,
"ext": "agda",
"hexsha": "4c4e1e21ad3501de290a7a4d72dda968a5229e99",
"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/Issue4399.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/Issue4399.agda",
"max_line_length": 60,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue4399.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": 106,
"size": 337
} |
{-# OPTIONS --without-K #-}
module container.m.from-nat.cone where
open import level
open import sum
open import equality
open import function
open import sets.nat.core
open import sets.nat.struct
open import sets.unit
open import container.core
open import container.m.from-nat.core
open import hott.level
module _ {li la lb} (c : Container li la lb) where
open Container c
open import container.m.coalgebra c hiding (_≅_; module _≅_)
-- X and π play the role of the "chain" as in
-- Definition 8 in Ahrens, Capriotti and Spadotti (arXiv:1504.02949v1 [cs.LO])
module _ (Xⁱ : ℕ → I → Set (la ⊔ lb))
(πⁱ : ∀ n → Xⁱ (suc n) →ⁱ Xⁱ n) where
private
X : (i : I) → ℕ → Set (la ⊔ lb)
X i n = Xⁱ n i
π : (i : I) (n : ℕ) → X i (suc n) → X i n
π i n = πⁱ n i
module cones {ℓ} (𝓩 : Coalg ℓ) where
private
Z = proj₁ 𝓩; θ = proj₂ 𝓩
Cone₀ : Set _
Cone₀ = (n : ℕ) → Z →ⁱ Xⁱ n
Cone₁ : Cone₀ → Set _
Cone₁ u = (n : ℕ) → πⁱ n ∘ⁱ u (suc n) ≡ u n
Cone : Set _
Cone = Σ Cone₀ Cone₁
Cone₀-eq-iso : {u₁ u₂ : Cone₀}
→ ((n : ℕ)(i : I)(z : Z i) → u₁ n i z ≡ u₂ n i z)
≅ (u₁ ≡ u₂)
Cone₀-eq-iso = Π-ap-iso refl≅ (λ _ → funext-isoⁱ) ·≅ strong-funext-iso
Cone₁-eq-iso : {u : Cone₀}{q₁ q₂ : Cone₁ u}
→ ( (n : ℕ)(i : I)(z : Z i)
→ funext-invⁱ (q₁ n) i z
≡ funext-invⁱ (q₂ n) i z )
≅ (q₁ ≡ q₂)
Cone₁-eq-iso {u}{q₁}{q₂} = begin
( (n : ℕ)(i : I)(z : Z i)
→ funext-invⁱ (q₁ n) i z
≡ funext-invⁱ (q₂ n) i z )
≅⟨ (Π-ap-iso refl≅ λ n → funext-isoⁱ) ⟩
( (n : ℕ) → funext-invⁱ (q₁ n) ≡ funext-invⁱ (q₂ n) )
≅⟨ ( Π-ap-iso refl≅ λ n → sym≅ (iso≡ (sym≅ funext-isoⁱ)) ) ⟩
( (n : ℕ) → q₁ n ≡ q₂ n )
≅⟨ strong-funext-iso ⟩
(q₁ ≡ q₂)
∎
where
open ≅-Reasoning
Cone-eq : {c₁ c₂ : Cone}
→ (p : (n : ℕ)(i : I)(z : Z i)
→ proj₁ c₁ n i z ≡ proj₁ c₂ n i z)
→ ( (n : ℕ)(i : I)(z : Z i)
→ funext-invⁱ (proj₂ c₁ n) i z
≡ ap (π i n) (p (suc n) i z)
· funext-invⁱ (proj₂ c₂ n) i z
· sym (p n i z) )
→ c₁ ≡ c₂
Cone-eq {c₁}{c₂} p α = unapΣ' (p' , α')
where
subst-lem : {u₁ u₂ : Cone₀}(p : u₁ ≡ u₂)(q : Cone₁ u₂)
→ (n : ℕ)(i : I)(z : Z i)
→ funext-invⁱ (subst Cone₁ (sym p) q n) i z
≡ ap (π i n) (funext-invⁱ (funext-inv p (suc n)) i z)
· funext-invⁱ (q n) i z
· sym (funext-invⁱ (funext-inv p n) i z)
subst-lem refl q n i z = sym (left-unit _)
subst-lem' : {u₁ u₂ : Cone₀}(p : (n : ℕ)(i : I)(z : Z i) → u₁ n i z ≡ u₂ n i z)
→ (q : Cone₁ u₂)(n : ℕ)(i : I)(z : Z i)
→ funext-invⁱ (subst Cone₁ (sym (apply Cone₀-eq-iso p)) q n) i z
≡ ap (π i n) (p (suc n) i z)
· funext-invⁱ (q n) i z
· sym (p n i z)
subst-lem' {u₁}{u₂} p q n i z = subst ( λ p₁
→ funext-invⁱ (subst Cone₁ (sym (apply Cone₀-eq-iso p)) q n) i z
≡ ap (π i n) (p₁ (suc n) i z) · funext-invⁱ (q n) i z · sym (p₁ n i z) )
(_≅_.iso₁ Cone₀-eq-iso p) (subst-lem (apply Cone₀-eq-iso p) q n i z)
p' : proj₁ c₁ ≡ proj₁ c₂
p' = apply Cone₀-eq-iso p
α' : proj₂ c₁ ≡ subst Cone₁ (sym p') (proj₂ c₂)
α' = apply Cone₁-eq-iso λ n i z
→ α n i z
· sym (subst-lem' p (proj₂ c₂) n i z)
unapΣ' : ∀ {i j}{A : Set i}{B : A → Set j}
→ {a a' : A}{b : B a}{b' : B a'}
→ (Σ (a ≡ a') λ q → b ≡ subst B (sym q) b')
→ (a , b) ≡ (a' , b')
unapΣ' (refl , refl) = refl
private
module limit where
module _ (i : I) where
open Limit (X i) (π i) public
isom : Cone ≅ (Z →ⁱ L)
isom = Limit-univⁱ.univ-iso I Xⁱ πⁱ
open limit public using (isom)
| {
"alphanum_fraction": 0.4354953671,
"avg_line_length": 34.5,
"ext": "agda",
"hexsha": "fdc72ec1f6a4ce67857cd2f9ff94715fd45de993",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-02-26T06:17:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-11T17:19:12.000Z",
"max_forks_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "HoTT/M-types",
"max_forks_repo_path": "container/m/from-nat/cone.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "beebe176981953ab48f37de5eb74557cfc5402f4",
"max_issues_repo_issues_event_max_datetime": "2015-02-11T15:20:34.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-11T11:14:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "HoTT/M-types",
"max_issues_repo_path": "container/m/from-nat/cone.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": "container/m/from-nat/cone.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": 1637,
"size": 4209
} |
module LineEndings.Dos where
postulate ThisWorks : Set
| {
"alphanum_fraction": 0.7796610169,
"avg_line_length": 14.75,
"ext": "agda",
"hexsha": "7e840c644332a7ace981a96db4839ac89c216a08",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Succeed/LineEndings/Dos.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Succeed/LineEndings/Dos.agda",
"max_line_length": 29,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/LineEndings/Dos.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": 15,
"size": 59
} |
-- Classical propositional logic, de Bruijn approach, final encoding
module Bf.Cp where
open import Lib using (List; _,_; LMem; lzero; lsuc)
-- Types
infixl 2 _&&_
infixl 1 _||_
infixr 0 _=>_
data Ty : Set where
UNIT : Ty
_=>_ : Ty -> Ty -> Ty
_&&_ : Ty -> Ty -> Ty
_||_ : Ty -> Ty -> Ty
FALSE : Ty
infixr 0 _<=>_
_<=>_ : Ty -> Ty -> Ty
a <=> b = (a => b) && (b => a)
NOT : Ty -> Ty
NOT a = a => FALSE
TRUE : Ty
TRUE = FALSE => FALSE
-- Context and truth judgement
Cx : Set
Cx = List Ty
isTrue : Ty -> Cx -> Set
isTrue a tc = LMem a tc
-- Terms
TmRepr : Set1
TmRepr = Cx -> Ty -> Set
module ArrMp where
record Tm (tr : TmRepr) : Set1 where
infixl 1 _$_
infixr 0 lam=>_
field
var : forall {tc a} -> isTrue a tc -> tr tc a
lam=>_ : forall {tc a b} -> tr (tc , a) b -> tr tc (a => b)
_$_ : forall {tc a b} -> tr tc (a => b) -> tr tc a -> tr tc b
v0 : forall {tc a} -> tr (tc , a) a
v0 = var lzero
v1 : forall {tc a b} -> tr (tc , a , b) a
v1 = var (lsuc lzero)
v2 : forall {tc a b c} -> tr (tc , a , b , c) a
v2 = var (lsuc (lsuc lzero))
open Tm {{...}} public
module Mp where
record Tm (tr : TmRepr) : Set1 where
field
pair' : forall {tc a b} -> tr tc a -> tr tc b -> tr tc (a && b)
fst : forall {tc a b} -> tr tc (a && b) -> tr tc a
snd : forall {tc a b} -> tr tc (a && b) -> tr tc b
left : forall {tc a b} -> tr tc a -> tr tc (a || b)
right : forall {tc a b} -> tr tc b -> tr tc (a || b)
case' : forall {tc a b c} -> tr tc (a || b) -> tr (tc , a) c -> tr (tc , b) c -> tr tc c
isArrMp : ArrMp.Tm tr
open ArrMp.Tm isArrMp public
syntax pair' x y = [ x , y ]
syntax case' xy x y = case xy => x => y
open Tm {{...}} public
module Cp where
record Tm (tr : TmRepr) : Set1 where
infixr 0 abort=>_
field
abort=>_ : forall {tc a} -> tr (tc , NOT a) FALSE -> tr tc a
isMp : Mp.Tm tr
open Mp.Tm isMp public
open Tm {{...}} public
Thm : Ty -> Set1
Thm a = forall {tr tc} {{_ : Tm tr}} -> tr tc a
open Cp public
| {
"alphanum_fraction": 0.4811827957,
"avg_line_length": 23.7446808511,
"ext": "agda",
"hexsha": "d20f798668c962669016096bdbe890cf2daf9d7f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/formal-logic",
"max_forks_repo_path": "src/Bf/Cp.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/formal-logic",
"max_issues_repo_path": "src/Bf/Cp.agda",
"max_line_length": 94,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "2dd761bfa96ccda089888e8defa6814776fa2922",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/formal-logic",
"max_stars_repo_path": "src/Bf/Cp.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-13T12:37:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-31T09:49:52.000Z",
"num_tokens": 826,
"size": 2232
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An explanation about how data types are laid out in the standard
-- library.
------------------------------------------------------------------------
module README.Data where
-- The top-level folder `Data` contains all the definitions of datatypes
-- and their associated properties.
-- Datatypes can broadly split into two categories
-- i) "Basic" datatypes which do not take other datatypes as generic
-- arguments (Nat, String, Fin, Bool, Char etc.)
-- ii) "Container" datatypes which take other generic datatypes as
-- arguments, (List, Vec, Sum, Product, Maybe, AVL trees etc.)
------------------------------------------------------------------------
-- Basic datatypes
------------------------------------------------------------------------
-- Basic datatypes are usually organised as follows:
-- 1. A `Base` module which either contains the definition of the
-- datatype or reimports it from the builtin modules, along with common
-- functions, operations and relations over elements of the datatype.
import Data.Nat.Base
import Data.Integer.Base
import Data.Char.Base
import Data.String.Base
import Data.Bool.Base
-- Commonly these modules don't need to be imported directly as their
-- contents is re-exported by the top level module (see below).
-- 2. A `Properties` module which contains the basic properties of the
-- functions, operations and relations contained in the base module.
import Data.Nat.Properties
import Data.Integer.Properties
import Data.Char.Properties
import Data.String.Properties
import Data.Bool.Properties
-- 3. A top-level module which re-exports the contents of the base
-- module as well as various queries (i.e. decidability proofs) from the
-- properties file.
import Data.Nat
import Data.Integer
import Data.Char
import Data.String
import Data.Bool
-- 4. A `Solver` module (for those datatypes that have an algebraic solver)
-- which can be used to automatically solve equalities over the basic datatype.
import Data.Nat.Solver
import Data.Integer.Solver
import Data.Bool.Solver
-- 5. More complex operations and relations are commonly found in their
-- own module beneath the top-level directory. For example:
import Data.Nat.DivMod
import Data.Integer.Coprimality
-- Note that eventually there is a plan to re-organise the library to
-- have the top-level module export a far wider range of properties and
-- additional operations in order to minimise the number of imports
-- needed. Currently it is necessary to import each of these separately
-- however.
------------------------------------------------------------------------
-- Container datatypes
------------------------------------------------------------------------
-- 1. As with basic datatypes, a `Base` module which contains the
-- definition of the datatype, along with common functions and
-- operations over that data. Unlike basic datatypes, the `Base` module
-- for container datatypes does not export any relations or predicates
-- over the datatype (see the `Relation` section below).
import Data.List.Base
import Data.Maybe.Base
import Data.Sum.Base
-- Commonly these modules don't need to be imported directly as their
-- contents is re-exported by the top level module (see below).
-- 2. As with basic datatypes, a `Properties` module which contains the
-- basic properties of the functions, operations and contained in the
-- base module.
import Data.List.Properties
import Data.Maybe.Properties
import Data.Sum.Properties
-- 3. As with basic datatypes, a top-level module which re-exports the
-- contents of the base module. In some cases this may also contain
-- additional functions which could not be placed into the corresponding
-- Base module because of cyclic dependencies.
import Data.List
import Data.Maybe
import Data.Sum
-- 4. A `Relation.Binary` folder where binary relations over the datatypes
-- are stored. Because relations over container datatypes often depend on
-- relations over the parameter datatype, this differs from basic datatypes
-- where the binary relations are usually defined in the `Base` module, e.g.
-- equality over the type `List A` depends on equality over type `A`.
-- For example the `Pointwise` relation that takes a relation over the
-- underlying type A and lifts it to the container parameterised can be found
-- as follows:
import Data.List.Relation.Binary.Pointwise
import Data.Maybe.Relation.Binary.Pointwise
import Data.Sum.Relation.Binary.Pointwise
-- Another useful subfolder in the `Data.X.Relation.Binary` folders is the
-- `Data.X.Relation.Binary.Equality` folder which contains various forms of
-- equality over the datatype.
-- 5. A `Relation.Unary` folder where unary relations, or predicates,
-- over the datatypes are stored. These can be viewed as properties
-- over a single list.
-- For example a common, useful example is `Data.X.Relation.Unary.Any`
-- that contains the types of proofs that at least one element in the
-- container satisfies some predicate/property.
import Data.List.Relation.Unary.Any
import Data.Vec.Relation.Unary.Any
import Data.Maybe.Relation.Unary.Any
-- Alternatively the `Data.X.Relation.Unary.All` module contains the
-- type of proofs that all elements in the container satisfy some
-- property.
import Data.List.Relation.Unary.All
import Data.Vec.Relation.Unary.All
import Data.Maybe.Relation.Unary.All
-- 6. A `Categorical` module/folder that contains categorical
-- interpretations of the datatype.
import Data.List.Categorical
import Data.Maybe.Categorical
import Data.Sum.Categorical.Left
import Data.Sum.Categorical.Right
-- 7. A `Function` folder that contains lifting of various types of
-- functions (e.g. injections, surjections, bijections, inverses) to
-- the datatype.
import Data.Sum.Function.Propositional
import Data.Sum.Function.Setoid
import Data.Product.Function.Dependent.Propositional
import Data.Product.Function.Dependent.Setoid
------------------------------------------------------------------------
-- Full list of documentation for the Data folder
------------------------------------------------------------------------
-- Some examples showing where the natural numbers/integers and some
-- related operations and properties are defined, and how they can be
-- used:
import README.Data.Nat
import README.Data.Nat.Induction
import README.Data.Integer
-- Some examples showing how the AVL tree module can be used.
import README.Data.AVL
-- Some examples showing how List module can be used.
import README.Data.List
-- Some examples showing how the Fresh list can be used.
import README.Data.List.Fresh
-- Using List's Interleaving to define a fully certified filter function.
import README.Data.Interleaving
-- Example of an encoding of record types with manifest fields and "with".
import README.Data.Record
-- Example use case for a trie: a wee generic lexer
import README.Data.Trie.NonDependent
-- Examples how (indexed) containers and constructions over them (free
-- monad, least fixed point, etc.) can be used
import README.Data.Container.FreeMonad
import README.Data.Container.Indexed
| {
"alphanum_fraction": 0.7150791447,
"avg_line_length": 34.7922705314,
"ext": "agda",
"hexsha": "792f3fba719f3bdb476ecf01637610d289fb7465",
"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/README/Data.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/README/Data.agda",
"max_line_length": 79,
"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/README/Data.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": 1476,
"size": 7202
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Finite sets defined in terms of Data.Star
------------------------------------------------------------------------
module Data.Star.Fin where
open import Data.Star
open import Data.Star.Nat as ℕ using (ℕ)
open import Data.Star.Pointer
open import Data.Unit
-- Finite sets are undecorated pointers into natural numbers.
Fin : ℕ → Set
Fin = Any (λ _ → ⊤) (λ _ → ⊤)
-- "Constructors".
zero : ∀ {n} → Fin (ℕ.suc n)
zero = this tt
suc : ∀ {n} → Fin n → Fin (ℕ.suc n)
suc = that tt
| {
"alphanum_fraction": 0.5008460237,
"avg_line_length": 22.7307692308,
"ext": "agda",
"hexsha": "add8e5047e088c7a4f538e965f78623c4b241e88",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Star/Fin.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Star/Fin.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Star/Fin.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 149,
"size": 591
} |
------------------------------------------------------------------------
-- Closure properties for Compatible and Size-preserving
------------------------------------------------------------------------
{-# OPTIONS --sized-types #-}
module Up-to.Closure where
open import Equality.Propositional
open import Logical-equivalence using (_⇔_)
open import Prelude as P
open import Prelude.Size
open import Bijection equality-with-J using (_↔_)
open import Function-universe equality-with-J hiding (id; _∘_)
import Bisimilarity
open import Indexed-container hiding (Bisimilarity)
open import Indexed-container.Combinators hiding (id; _∘_)
open import Labelled-transition-system
import Labelled-transition-system.CCS
open import Relation
import Similarity
import Similarity.CCS as SC
open import Up-to
private
module CCS {ℓ} (Name : Type ℓ) where
open Labelled-transition-system.CCS Name public
open module B = Bisimilarity CCS public
open module S = Similarity CCS public using (Similarity)
------------------------------------------------------------------------
-- Closure properties for Compatible
-- The results in this section are closely related to
-- Proposition 6.3.21 in Pous and Sangiorgi's "Enhancements of the
-- bisimulation proof method".
-- The function flip Compatible F is closed under _⊗_, assuming that F
-- is monotone.
Compatible-⊗ :
∀ {ℓ} {I : Type ℓ} {C₁ C₂ : Container I I} {F : Trans ℓ I} →
Monotone F →
Compatible C₁ F → Compatible C₂ F → Compatible (C₁ ⊗ C₂) F
Compatible-⊗ {C₁ = C₁} {C₂} {F} mono comp₁ comp₂ {R = R} =
F (⟦ C₁ ⊗ C₂ ⟧ R) ⊆⟨ mono (⟦⊗⟧↔ _ C₁ C₂) ⟩
F (⟦ C₁ ⟧ R ∩ ⟦ C₂ ⟧ R) ⊆⟨ (λ x → mono proj₁ x , mono proj₂ x) ⟩
F (⟦ C₁ ⟧ R) ∩ F (⟦ C₂ ⟧ R) ⊆⟨ Σ-map comp₁ comp₂ ⟩
⟦ C₁ ⟧ (F R) ∩ ⟦ C₂ ⟧ (F R) ⊆⟨ _⇔_.from (⟦⊗⟧↔ _ C₁ C₂) ⟩∎
⟦ C₁ ⊗ C₂ ⟧ (F R) ∎
-- The function flip Compatible F is closed under reindex₁ f, assuming
-- that F is monotone and f-symmetric.
Compatible-reindex₁ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F : Trans ℓ I} {f : I → I} →
Monotone F → Symmetric f F →
Compatible C F → Compatible (reindex₁ f C) F
Compatible-reindex₁ {C = C} {F} {f} mono hyp comp {R = R} =
F (⟦ reindex₁ f C ⟧ R) ⊆⟨ mono (⟦reindex₁⟧↔ _ C) ⟩
F (⟦ C ⟧ (R ∘ f)) ⊆⟨ comp ⟩
⟦ C ⟧ (F (R ∘ f)) ⊆⟨ map C (hyp _) ⟩
⟦ C ⟧ (F R ∘ f) ⊆⟨ _⇔_.from (⟦reindex₁⟧↔ _ C) ⟩∎
⟦ reindex₁ f C ⟧ (F R) ∎
-- The function flip Compatible F is closed under reindex₂ f, assuming
-- that F is f-symmetric.
Compatible-reindex₂ :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F : Trans ℓ I} {f : I → I} →
Symmetric f F →
Compatible C F → Compatible (reindex₂ f C) F
Compatible-reindex₂ {C = C} {F} {f} hyp comp {R = R} =
F (⟦ reindex₂ f C ⟧ R) ⊆⟨⟩
F (⟦ C ⟧ R ∘ f) ⊆⟨ hyp _ ⟩
F (⟦ C ⟧ R) ∘ f ⊆⟨ comp ⟩
⟦ C ⟧ (F R) ∘ f ⊆⟨ id ⟩∎
⟦ reindex₂ f C ⟧ (F R) ∎
-- The function flip Compatible F is closed under reindex f, assuming
-- that F is monotone and f-symmetric.
Compatible-reindex :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F : Trans ℓ I} {f : I → I} →
Monotone F → Symmetric f F →
Compatible C F → Compatible (reindex f C) F
Compatible-reindex {C = C} {F} {f} mono hyp =
Compatible C F ↝⟨ Compatible-reindex₁ mono hyp ⟩
Compatible (reindex₁ f C) F ↝⟨ Compatible-reindex₂ hyp ⟩
Compatible (reindex₂ f (reindex₁ f C)) F ↔⟨⟩
Compatible (reindex f C) F □
-- The function flip Compatible F is closed under _⟷_, assuming that F
-- is monotone and symmetric.
Compatible-⟷ :
∀ {ℓ} {I : Type ℓ}
{C₁ C₂ : Container (I × I) (I × I)} {F : Trans₂ ℓ I} →
Monotone F → Symmetric swap F →
Compatible C₁ F → Compatible C₂ F → Compatible (C₁ ⟷ C₂) F
Compatible-⟷ {C₁ = C₁} {C₂} {F} mono sym = curry (
Compatible C₁ F × Compatible C₂ F ↝⟨ Σ-map id (Compatible-reindex mono sym) ⟩
Compatible C₁ F × Compatible (reindex swap C₂) F ↝⟨ uncurry (Compatible-⊗ mono) ⟩
Compatible (C₁ ⊗ reindex swap C₂) F ↔⟨⟩
Compatible (C₁ ⟷ C₂) F □)
-- An instance of the result above: If F is monotone and symmetric,
-- and compatible for strong similarity for some LTS, then F is
-- compatible for strong bisimilarity for this LTS.
compatible-for-similarity→compatible-for-bisimilarity :
∀ {ℓ} {lts : LTS ℓ} {F} →
Monotone F → Symmetric swap F →
Compatible (Similarity.StepC lts) F →
Compatible (Bisimilarity.StepC lts) F
compatible-for-similarity→compatible-for-bisimilarity mono sym comp =
Compatible-⟷ mono sym comp comp
------------------------------------------------------------------------
-- Closure properties for Size-preserving
-- The function flip Size-preserving F is closed under reindex,
-- assuming that F is f-symmetric for an involutory function f.
--
-- Note that the assumptions are different from the ones asked for in
-- Compatible-reindex: monotonicity of F has been replaced by the
-- assumption that f is an involution.
Size-preserving-reindex :
∀ {ℓ} {I : Type ℓ} {C : Container I I} {F : Trans ℓ I} {f : I → I} →
f ∘ f ≡ id → Symmetric f F →
Size-preserving C F → Size-preserving (reindex f C) F
Size-preserving-reindex {C = C} {F} {f}
inv hyp pres {R = R} {i = i} R⊆ =
F R ⊆⟨ (λ {x} → subst (λ g → F (R ∘ g) x) (sym inv)) ⟩
F (R ∘ f ∘ f) ⊆⟨ hyp _ ⟩
F (R ∘ f) ∘ f ⊆⟨ pres (
R ∘ f ⊆⟨ R⊆ ⟩
ν (reindex f C) i ∘ f ⊆⟨ _⇔_.to (ν-reindex⇔ inv) ⟩
ν C i ∘ f ∘ f ⊆⟨ (λ {x} → subst (λ g → ν C i (g x)) inv) ⟩∎
ν C i ∎) ⟩
ν C i ∘ f ⊆⟨ _⇔_.from (ν-reindex⇔ inv) ⟩∎
ν (reindex f C) i ∎
-- Some negative results:
--
-- * For inhabited name types it is not in general the case that a
-- monotone and symmetric function F that is size-preserving for
-- similarity for CCS is also size-preserving for bisimilarity for
-- CCS.
--
-- * It is not in general the case that if F is monotone and
-- symmetric, and size-preserving for strong similarity for some
-- LTS, then F is size-preserving for strong bisimilarity for this
-- LTS.
--
-- * The function flip Size-preserving F is not closed under _⟷_ for
-- all F, not even those that are monotone and symmetric.
--
-- * Furthermore flip Size-preserving F is not closed under _⊗_ for
-- all F, not even those that are monotone.
¬-Size-preserving-⟷/⊗ :
∀ {ℓ} →
({Name : Type ℓ} →
let open CCS Name in
Name →
¬ ({F : Trans₂ ℓ (Proc ∞)} →
Monotone F → Symmetric swap F →
Size-preserving S.StepC F →
Size-preserving B.StepC F))
×
¬ (∀ {lts : LTS ℓ} {F} →
Monotone F → Symmetric swap F →
Size-preserving (Similarity.StepC lts) F →
Size-preserving (Bisimilarity.StepC lts) F)
×
¬ ({I : Type ℓ} {C₁ C₂ : Container (I × I) (I × I)}
{F : Trans₂ ℓ I} →
Monotone F → Symmetric swap F →
Size-preserving C₁ F → Size-preserving C₂ F →
Size-preserving (C₁ ⟷ C₂) F)
×
¬ ({I : Type ℓ} {C₁ C₂ : Container I I} {F : Trans ℓ I} →
Monotone F →
Size-preserving C₁ F → Size-preserving C₂ F →
Size-preserving (C₁ ⊗ C₂) F)
¬-Size-preserving-⟷/⊗ {ℓ} =
Lemmas.contradiction₂
, Lemmas.contradiction₃ (lift tt)
, Lemmas.contradiction₄ (lift tt)
, Lemmas.contradiction₅ (lift tt)
where
module Lemmas {Name : Type ℓ} (a : Name) where
open CCS Name public
≤≥≁ = SC.≤≥≁ a
m₁ = proj₁ ≤≥≁
m₂ = proj₁ (proj₂ ≤≥≁)
F : Trans₂ ℓ (Proc ∞)
F R = R ∪ (_≡ (m₁ , m₂)) ∪ (_≡ (m₂ , m₁))
mono : Monotone F
mono R⊆S = ⊎-map R⊆S id
symm : Symmetric swap F
symm R =
F (R ⁻¹) ⊆⟨⟩
R ⁻¹ ∪ (_≡ (m₁ , m₂)) ∪ (_≡ (m₂ , m₁)) ⊆⟨ ⊎-map id P.[ inj₂ ∘ lemma , inj₁ ∘ lemma ] ⟩
R ⁻¹ ∪ (_≡ (m₁ , m₂)) ⁻¹ ∪ (_≡ (m₂ , m₁)) ⁻¹ ⊆⟨ id ⟩∎
F R ⁻¹ ∎
where
lemma : {p₁ p₂ : Proc ∞ × Proc ∞} → p₁ ≡ swap p₂ → swap p₁ ≡ p₂
lemma refl = refl
pres : Size-preserving S.StepC F
pres {R = R} {i = i} R⊆ =
F R ⊆⟨⟩
R ∪ (_≡ (m₁ , m₂)) ∪ (_≡ (m₂ , m₁)) ⊆⟨ [ R⊆ , helper ] ⟩∎
Similarity i ∎
where
helper : ∀ {p} → p ≡ (m₁ , m₂) ⊎ p ≡ (m₂ , m₁) → Similarity i p
helper (inj₁ refl) = proj₁ (proj₂ (proj₂ ≤≥≁))
helper (inj₂ refl) = proj₁ (proj₂ (proj₂ (proj₂ ≤≥≁)))
contradiction =
Size-preserving B.StepC F ↝⟨ (λ hyp → _⇔_.to (monotone→⇔ _ mono) hyp) ⟩
F (Bisimilarity ∞) ⊆ Bisimilarity ∞ ↝⟨ _$ inj₂ (inj₁ refl) ⟩
m₁ ∼ m₂ ↝⟨ proj₂ (proj₂ (proj₂ (proj₂ ≤≥≁))) ⟩□
⊥ □
contradiction₂ =
({F : Trans₂ ℓ (Proc ∞)} →
Monotone F → Symmetric swap F →
Size-preserving S.StepC F →
Size-preserving B.StepC F) ↝⟨ (λ closed → closed mono symm pres) ⟩
Size-preserving B.StepC F ↝⟨ contradiction ⟩□
⊥ □
contradiction₃ =
(∀ {lts : LTS ℓ} {F} →
Monotone F → Symmetric swap F →
Size-preserving (Similarity.StepC lts) F →
Size-preserving (Bisimilarity.StepC lts) F) ↝⟨ (λ closed mono sym pres → closed mono sym pres) ⟩
({F : Trans₂ ℓ (Proc ∞)} →
Monotone F → Symmetric swap F →
Size-preserving S.StepC F →
Size-preserving B.StepC F) ↝⟨ contradiction₂ ⟩□
⊥ □
contradiction₄ =
({I : Type ℓ} {C₁ C₂ : Container (I × I) (I × I)}
{F : Trans₂ ℓ I} →
Monotone F → Symmetric swap F →
Size-preserving C₁ F → Size-preserving C₂ F →
Size-preserving (C₁ ⟷ C₂) F) ↝⟨ (λ closed mono symm pres → closed mono symm pres pres) ⟩
(∀ {lts : LTS ℓ} {F} →
Monotone F → Symmetric swap F →
Size-preserving (Similarity.StepC lts) F →
Size-preserving (Bisimilarity.StepC lts) F) ↝⟨ contradiction₃ ⟩□
⊥ □
contradiction₅ =
({I : Type ℓ} {C₁ C₂ : Container I I}
{F : Trans ℓ I} →
Monotone F →
Size-preserving C₁ F → Size-preserving C₂ F →
Size-preserving (C₁ ⊗ C₂) F) ↝⟨ (λ closed → closed mono pres) ⟩
(Size-preserving (reindex swap S.StepC) F →
Size-preserving B.StepC F) ↝⟨ _$ Size-preserving-reindex refl symm pres ⟩
Size-preserving B.StepC F ↝⟨ contradiction ⟩□
⊥ □
| {
"alphanum_fraction": 0.5340655249,
"avg_line_length": 37.1764705882,
"ext": "agda",
"hexsha": "196f91f523777791d6f9b80cd5795a5397cd6a91",
"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": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/up-to",
"max_forks_repo_path": "src/Up-to/Closure.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"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/up-to",
"max_issues_repo_path": "src/Up-to/Closure.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b936ff85411baf3401ad85ce85d5ff2e9aa0ca14",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/up-to",
"max_stars_repo_path": "src/Up-to/Closure.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3787,
"size": 10744
} |
module CTL.Modalities.AG where
open import FStream.Core
open import Library
-- Certainly forever : s₀ ⊧ φ ⇔ ∀ s₀ R s₁ R ... ∀ i . sᵢ ⊧ φ
{-# NO_POSITIVITY_CHECK #-} -- Not necessary from Agda 2.6 upwards
record AG' {i : Size} {ℓ₁ ℓ₂} {C : Container ℓ₁}
(props : FStream' C (Set ℓ₂)) : Set (ℓ₁ ⊔ ℓ₂) where
coinductive
field
nowA : head props
laterA : {j : Size< i} → A (fmap AG' (inF (tail props)))
open AG' public
AG : ∀ {i : Size} {ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → Set (ℓ₁ ⊔ ℓ₂)
AG props = APred AG' (inF props)
mutual
AGₛ' : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream' C (Set ℓ₂) → FStream' {i} C (Set (ℓ₁ ⊔ ℓ₂))
head (AGₛ' props) = AG' props
tail (AGₛ' props) = AGₛ (tail props)
AGₛ : ∀ {i ℓ₁ ℓ₂} {C : Container ℓ₁}
→ FStream C (Set ℓ₂) → FStream {i} C (Set (ℓ₁ ⊔ ℓ₂))
inF (AGₛ props) = fmap AGₛ' (inF props)
| {
"alphanum_fraction": 0.5841924399,
"avg_line_length": 30.1034482759,
"ext": "agda",
"hexsha": "99f03d86335280cbd93a3f7990b0d1a52b397369",
"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/AG.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/AG.agda",
"max_line_length": 66,
"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/AG.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": 389,
"size": 873
} |
module Symmetric where
open import Level hiding ( suc ; zero )
open import Algebra
open import Algebra.Structures
open import Data.Fin hiding ( _<_ ; _≤_ ; _-_ ; _+_ )
open import Data.Fin.Properties hiding ( <-trans ; ≤-trans ) renaming ( <-cmp to <-fcmp )
open import Data.Product
open import Data.Fin.Permutation
open import Function hiding (id ; flip)
open import Function.Inverse as Inverse using (_↔_; Inverse; _InverseOf_)
open import Function.LeftInverse using ( _LeftInverseOf_ )
open import Function.Equality using (Π)
open import Data.Nat -- using (ℕ; suc; zero; s≤s ; z≤n )
open import Data.Nat.Properties -- using (<-trans)
open import Relation.Binary.PropositionalEquality
open import Data.List using (List; []; _∷_ ; length ; _++_ ; head ) renaming (reverse to rev )
open import nat
fid : {p : ℕ } → Fin p → Fin p
fid x = x
-- Data.Fin.Permutation.id
pid : {p : ℕ } → Permutation p p
pid = permutation fid fid record { left-inverse-of = λ x → refl ; right-inverse-of = λ x → refl }
-- Data.Fin.Permutation.flip
pinv : {p : ℕ } → Permutation p p → Permutation p p
pinv {p} P = permutation (_⟨$⟩ˡ_ P) (_⟨$⟩ʳ_ P ) record { left-inverse-of = λ x → inverseʳ P ; right-inverse-of = λ x → inverseˡ P }
record _=p=_ {p : ℕ } ( x y : Permutation p p ) : Set where
field
peq : ( q : Fin p ) → x ⟨$⟩ʳ q ≡ y ⟨$⟩ʳ q
open _=p=_
prefl : {p : ℕ } { x : Permutation p p } → x =p= x
peq (prefl {p} {x}) q = refl
psym : {p : ℕ } { x y : Permutation p p } → x =p= y → y =p= x
peq (psym {p} {x} {y} eq ) q = sym (peq eq q)
ptrans : {p : ℕ } { x y z : Permutation p p } → x =p= y → y =p= z → x =p= z
peq (ptrans {p} {x} {y} x=y y=z ) q = trans (peq x=y q) (peq y=z q)
peqˡ : {p : ℕ }{ x y : Permutation p p } → x =p= y → (q : Fin p) → x ⟨$⟩ˡ q ≡ y ⟨$⟩ˡ q
peqˡ {p} {x} {y} eq q = begin
x ⟨$⟩ˡ q
≡⟨ sym ( inverseˡ y ) ⟩
y ⟨$⟩ˡ (y ⟨$⟩ʳ ( x ⟨$⟩ˡ q ))
≡⟨ cong (λ k → y ⟨$⟩ˡ k ) (sym (peq eq _ )) ⟩
y ⟨$⟩ˡ (x ⟨$⟩ʳ ( x ⟨$⟩ˡ q ))
≡⟨ cong (λ k → y ⟨$⟩ˡ k ) ( inverseʳ x ) ⟩
y ⟨$⟩ˡ q
∎ where open ≡-Reasoning
presp : { p : ℕ } {x y u v : Permutation p p } → x =p= y → u =p= v → (x ∘ₚ u) =p= (y ∘ₚ v)
presp {p} {x} {y} {u} {v} x=y u=v = record { peq = λ q → lemma4 q } where
lemma4 : (q : Fin p) → ((x ∘ₚ u) ⟨$⟩ʳ q) ≡ ((y ∘ₚ v) ⟨$⟩ʳ q)
lemma4 q = trans (cong (λ k → Inverse.to u Π.⟨$⟩ k) (peq x=y q) ) (peq u=v _ )
passoc : { p : ℕ } (x y z : Permutation p p) → ((x ∘ₚ y) ∘ₚ z) =p= (x ∘ₚ (y ∘ₚ z))
passoc x y z = record { peq = λ q → refl }
p-inv : { p : ℕ } {i j : Permutation p p} → i =p= j → (q : Fin p) → pinv i ⟨$⟩ʳ q ≡ pinv j ⟨$⟩ʳ q
p-inv {p} {i} {j} i=j q = begin
i ⟨$⟩ˡ q ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (inverseʳ j) ) ⟩
i ⟨$⟩ˡ ( j ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ cong (λ k → i ⟨$⟩ˡ k) (sym (peq i=j _ )) ⟩
i ⟨$⟩ˡ ( i ⟨$⟩ʳ ( j ⟨$⟩ˡ q )) ≡⟨ inverseˡ i ⟩
j ⟨$⟩ˡ q
∎ where open ≡-Reasoning
Symmetric : ℕ → Group Level.zero Level.zero
Symmetric p = record {
Carrier = Permutation p p
; _≈_ = _=p=_
; _∙_ = _∘ₚ_
; ε = pid
; _⁻¹ = pinv
; isGroup = record { isMonoid = record { isSemigroup = record { isMagma = record {
isEquivalence = record {refl = prefl ; trans = ptrans ; sym = psym }
; ∙-cong = presp }
; assoc = passoc }
; identity = ( (λ q → record { peq = λ q → refl } ) , (λ q → record { peq = λ q → refl } )) }
; inverse = ( (λ x → record { peq = λ q → inverseʳ x} ) , (λ x → record { peq = λ q → inverseˡ x} ))
; ⁻¹-cong = λ i=j → record { peq = λ q → p-inv i=j q }
}
}
| {
"alphanum_fraction": 0.5162983425,
"avg_line_length": 41.1363636364,
"ext": "agda",
"hexsha": "3b79dd8b579ee50159a0be1a9a619dfa38a845fb",
"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": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/Galois",
"max_forks_repo_path": "src/Symmetric.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/Galois",
"max_issues_repo_path": "src/Symmetric.agda",
"max_line_length": 131,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "bf000643c139f40d5783e962bb3b63353ba3d6e4",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/Galois",
"max_stars_repo_path": "src/Symmetric.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-16T03:37:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-10-16T03:37:05.000Z",
"num_tokens": 1513,
"size": 3620
} |
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Rings.Definition
open import Rings.IntegralDomains.Definition
open import Vectors
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Numbers.Naturals.Definition
open import Sets.EquivalenceRelations
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Rings.UniqueFactorisationDomains.Lemmas {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ _*_ : A → A → A} {R : Ring S _+_ _*_} (intDom : IntegralDomain R) where
open import Rings.Units.Definition R
open import Rings.Irreducibles.Definition intDom
open import Rings.Associates.Definition intDom
open import Rings.Primes.Definition intDom
open import Rings.Divisible.Definition R
open import Rings.Divisible.Lemmas R
open import Rings.UniqueFactorisationDomains.Definition intDom
open Ring R
open Setoid S
open Equivalence eq
ufdImpliesUfd' : UFD → UFD'
UFD'.factorisation (ufdImpliesUfd' x) = UFD.factorisation x
Prime.isPrime (UFD'.irreduciblesArePrime (ufdImpliesUfd' ufd) {r} irreducible) a b (s , ab=rs) rNotDivA = {!!}
where
-- we can't factorise a, it might be a unit :(
factA : Factorisation {a} (λ p → rNotDivA (divisibleWellDefined reflexive (symmetric p) (everythingDividesZero r))) {!!}
factA = UFD.factorisation ufd {a} {!!} {!!}
fact1 : Factorisation {r} {!!} {!!}
fact1 = {!!}
fact2 : Factorisation {r} {!!} {!!}
fact2 = {!!}
Prime.nonzero (UFD'.irreduciblesArePrime (ufdImpliesUfd' x) irreducible) = Irreducible.nonzero irreducible
Prime.nonunit (UFD'.irreduciblesArePrime (ufdImpliesUfd' x) irreducible) = Irreducible.nonunit irreducible
private
lemma2 : UFD' → {r : A} → .(nonzero : (r ∼ 0R) → False) .(nonunit : (Unit r) → False) → (f1 f2 : Factorisation {r} nonzero nonunit) → factorisationEquality f1 f2
lemma2 x nonzero nonunit record { len = lenA ; factorise = factoriseA ; factoriseIsFactorisation = factoriseIsFactorisationA ; factoriseIsIrreducibles = factoriseIsIrreduciblesA ; distinct = distinctA } record { len = lenB ; factorise = factoriseB ; factoriseIsFactorisation = factoriseIsFactorisationB ; factoriseIsIrreducibles = factoriseIsIrreduciblesB ; distinct = distinctB } with ℕDecideEquality lenA lenB
lemma2 x nonzero nonunit record { len = zero ; factorise = [] ; factoriseIsFactorisation = factoriseIsFactorisationA ; factoriseIsIrreducibles = factoriseIsIrreduciblesA ; distinct = distinctA } record { len = .0 ; factorise = [] ; factoriseIsFactorisation = factoriseIsFactorisationB ; factoriseIsIrreducibles = factoriseIsIrreduciblesB ; distinct = distinctB } | inl refl = record {}
lemma2 ufd' {r} nonzero nonunit record { len = (succ len) ; factorise = (a1 ,, n1) ,- factoriseA ; factoriseIsFactorisation = factoriseIsFactorisationA ; factoriseIsIrreducibles = factoriseIsIrreduciblesA ; distinct = distinctA } record { len = .(succ len) ; factorise = factoriseB ; factoriseIsFactorisation = factoriseIsFactorisationB ; factoriseIsIrreducibles = factoriseIsIrreduciblesB ; distinct = distinctB } | inl refl = {!!}
where
a1Prime : Prime a1
a1Prime = UFD'.irreduciblesArePrime ufd' (_&&_.fst factoriseIsIrreduciblesA)
a1DivR : a1 ∣ r
a1DivR = {!!}
... | inr neq = {!!}
ufd'ImpliesUfd : UFD' → UFD
UFD.factorisation (ufd'ImpliesUfd x) = UFD'.factorisation x
UFD.uniqueFactorisation (ufd'ImpliesUfd x) {r} nonzero nonunit f1 f2 = lemma2 x nonzero nonunit f1 f2
| {
"alphanum_fraction": 0.7446991404,
"avg_line_length": 60.1724137931,
"ext": "agda",
"hexsha": "8aa666027ff1ad34342a3a30051aa80b5522c488",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/UniqueFactorisationDomains/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/UniqueFactorisationDomains/Lemmas.agda",
"max_line_length": 434,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/UniqueFactorisationDomains/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": 1086,
"size": 3490
} |
module Numeral.Matrix.Proofs where
import Lvl
open import Syntax.Number
open import Data
open import Data.Boolean
open import Data.Boolean.Stmt
open import Data.Boolean.Stmt.Proofs
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
import Functional as Fn
open import Function.Equals
open import Lang.Inspect
open import Logic.Predicate
open import Logic.Propositional
open import Logic.Propositional.Theorems
open import Numeral.Finite
open import Numeral.Finite.Bound
open import Numeral.Finite.Oper
open import Numeral.Finite.Oper.Comparisons
open import Numeral.Finite.Oper.Comparisons.Proofs
open import Numeral.Finite.Proofs
open import Numeral.Matrix as Matrix using (Matrix ; SquareMatrix)
open import Numeral.Natural
open import Numeral.CoordinateVector as Vector using (Vector)
import Numeral.CoordinateVector.Proofs as Vector
open import Relator.Equals using ([≡]-intro) renaming (_≡_ to _≡ₑ_ ; _≢_ to _≢ₑ_)
open import Relator.Equals.Proofs.Equivalence
open import Structure.Function
open import Structure.Operator.Group
open import Structure.Operator.Monoid
open import Structure.Operator.Properties
open import Structure.Operator
open import Structure.Relator.Equivalence
open import Structure.Relator.Properties
open import Structure.Setoid
open import Syntax.Function
open import Syntax.Implication
open import Syntax.Transitivity
open import Type
private variable ℓ ℓₑ : Lvl.Level
private variable T A B : Type{ℓ}
module _ ⦃ equiv : Equiv{ℓₑ}(T) ⦄ where
private variable s : ℕ ⨯ ℕ
private variable w h n : ℕ
private variable x y z : 𝕟(n)
private variable id id₁ id₂ zero elem 𝟎ₛ 𝟏ₛ : T
private variable f g inv : T → T
private variable _▫_ _▫₁_ _▫₂_ _+ₛ_ _⋅ₛ_ : T → T → T
private variable v v₁ v₂ : Vector(n)(T)
private variable M : Matrix(s)(T)
instance
matrix-equiv : Equiv(Matrix(s)(T))
Equiv._≡_ matrix-equiv (Matrix.mat proj₁) (Matrix.mat proj₂) = proj₁ ⊜ proj₂
Reflexivity.proof (Equivalence.reflexivity (Equiv.equivalence matrix-equiv)) = reflexivity(_⊜_)
Symmetry.proof (Equivalence.symmetry (Equiv.equivalence matrix-equiv)) = symmetry(_⊜_)
Transitivity.proof (Equivalence.transitivity (Equiv.equivalence matrix-equiv)) = transitivity(_⊜_)
instance
matrix-map₂-binaryOperator : ⦃ oper : BinaryOperator(_▫_) ⦄ → BinaryOperator(Matrix.map₂{s = s}(_▫_))
BinaryOperator.congruence (matrix-map₂-binaryOperator {_▫_ = _▫_} ⦃ oper ⦄) (intro p) (intro q) = intro (congruence₂(_▫_) ⦃ oper ⦄ p q)
instance
matrix-map₂-identityₗ : ⦃ ident : Identityₗ(_▫_)(id) ⦄ → Identityₗ(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
Identityₗ.proof (matrix-map₂-identityₗ {_▫_ = _▫_} {id = id}) = intro(identityₗ(_▫_)(id))
instance
matrix-map₂-identityᵣ : ⦃ ident : Identityᵣ(_▫_)(id) ⦄ → Identityᵣ(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
Identityᵣ.proof (matrix-map₂-identityᵣ {_▫_ = _▫_} {id = id}) = intro(identityᵣ(_▫_)(id))
instance
matrix-map₂-identity : ⦃ ident : Identity(_▫_)(id) ⦄ → Identity(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
matrix-map₂-identity = intro
instance
matrix-map₂-absorberₗ : ⦃ absorb : Absorberₗ(_▫_)(id) ⦄ → Absorberₗ(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
Absorberₗ.proof (matrix-map₂-absorberₗ {_▫_ = _▫_} {id = id}) = intro(absorberₗ(_▫_)(id))
instance
matrix-map₂-absorberᵣ : ⦃ absorb : Absorberᵣ(_▫_)(id) ⦄ → Absorberᵣ(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
Absorberᵣ.proof (matrix-map₂-absorberᵣ {_▫_ = _▫_} {id = id}) = intro(absorberᵣ(_▫_)(id))
instance
matrix-map₂-absorber : ⦃ absorb : Absorber(_▫_)(id) ⦄ → Absorber(Matrix.map₂{s = s}(_▫_)) (Matrix.fill(id))
matrix-map₂-absorber = intro
instance
matrix-map₂-commutativity : ⦃ comm : Commutativity(_▫_) ⦄ → Commutativity(Matrix.map₂{s = s}(_▫_))
Commutativity.proof (matrix-map₂-commutativity {_▫_ = _▫_}) = intro(commutativity(_▫_))
instance
matrix-map₂-associativity : ⦃ assoc : Associativity(_▫_) ⦄ → Associativity(Matrix.map₂{s = s}(_▫_))
Associativity.proof (matrix-map₂-associativity {_▫_ = _▫_}) = intro(associativity(_▫_))
instance
matrix-map₂-map-inverseFunctionₗ : ⦃ ident : Identityₗ(_▫_)(id) ⦄ ⦃ inver : InverseFunctionₗ(_▫_) ⦃ [∃]-intro _ ⦄ (inv) ⦄ → InverseFunctionₗ(Matrix.map₂{s = s}(_▫_)) ⦃ [∃]-intro _ ⦄ (Matrix.map inv)
InverseFunctionₗ.proof (matrix-map₂-map-inverseFunctionₗ {_▫_ = _▫_} {inv = inv}) = intro (inverseFunctionₗ(_▫_) ⦃ [∃]-intro _ ⦄ (inv))
instance
matrix-map₂-map-inverseFunctionᵣ : ⦃ ident : Identityᵣ(_▫_)(id) ⦄ ⦃ inver : InverseFunctionᵣ(_▫_) ⦃ [∃]-intro _ ⦄ (inv) ⦄ → InverseFunctionᵣ(Matrix.map₂{s = s}(_▫_)) ⦃ [∃]-intro _ ⦄ (Matrix.map inv)
InverseFunctionᵣ.proof (matrix-map₂-map-inverseFunctionᵣ {_▫_ = _▫_} {inv = inv}) = intro (inverseFunctionᵣ(_▫_) ⦃ [∃]-intro _ ⦄ (inv))
instance
matrix-map₂-map-inverseFunction : ⦃ ident : Identity(_▫_)(id) ⦄ ⦃ inver : InverseFunction(_▫_) ⦃ [∃]-intro _ ⦄ (inv) ⦄ → InverseFunction(Matrix.map₂{s = s}(_▫_)) ⦃ [∃]-intro _ ⦄ (Matrix.map inv)
matrix-map₂-map-inverseFunction = intro
instance
matrix-map-function : ⦃ func : Function(f) ⦄ → Function(Matrix.map{s = s} (f))
Function.congruence matrix-map-function (intro p) = intro(congruence₁ _ p)
instance
matrix-map₂-monoid : ⦃ monoid : Monoid(_▫_) ⦄ → Monoid(Matrix.map₂{s = s}(_▫_))
Monoid.identity-existence matrix-map₂-monoid = [∃]-intro(Matrix.fill(_))
instance
matrix-map₂-group : ⦃ group : Group(_▫_) ⦄ → Group(Matrix.map₂{s = s}(_▫_))
Group.monoid matrix-map₂-group = matrix-map₂-monoid
Group.inverse-existence matrix-map₂-group = [∃]-intro _
diagMat-element-zero : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ zero) ↔ ((x ≢ₑ y) ∨ (Vector.proj v(x) ≡ zero))
diagMat-element-zero {zero = zero}{𝐒 n}{v = v}{x = x}{y = y} =
[↔]-intro ([↔]-to-[←] [→ₗ][∨][∧]-preserving ([∧]-intro l₁ l₂)) r ⦗ [↔]-transitivity ⦘ᵣ
[∨]-mapₗ-[↔] ([↔]-transitivity false-true-opposites ([↔]-symmetry([¬]-unaryOperator [≡][≡?]-equivalence)))
where
l₁ : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ zero) ← IsFalse(x ≡? y)
l₁ p with 𝐹 ← (x ≡? y) = reflexivity(_≡_)
l₂ : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ zero) ← (Vector.proj v(x) ≡ zero)
l₂ p with (x ≡? y)
... | 𝑇 = p
... | 𝐹 = reflexivity(_≡_)
r : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ zero) → (IsFalse(x ≡? y) ∨ (Vector.proj v(x) ≡ zero))
r p with (x ≡? y)
... | 𝑇 = [∨]-introᵣ p
... | 𝐹 = [∨]-introₗ [⊤]-intro
diagMat-element-vector : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ Vector.proj v(x)) ↔ ((x ≡ₑ y) ∨ (Vector.proj v(x) ≡ zero))
diagMat-element-vector {zero = zero}{𝐒 n}{v = v}{x = x}{y = y} =
[↔]-intro ([↔]-to-[←] [→ₗ][∨][∧]-preserving ([∧]-intro l₁ l₂)) r ⦗ [↔]-transitivity ⦘ᵣ
[∨]-mapₗ-[↔] ([↔]-symmetry [≡][≡?]-equivalence)
where
l₁ : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ Vector.proj v(x)) ← IsTrue(x ≡? y)
l₁ p with 𝑇 ← (x ≡? y) = reflexivity(_≡_)
l₂ : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ Vector.proj v(x)) ← (Vector.proj v(x) ≡ zero)
l₂ p with (x ≡? y)
... | 𝑇 = reflexivity(_≡_)
... | 𝐹 = symmetry(_≡_) p
r : (Matrix.proj (SquareMatrix.diagMat zero v) (x , y) ≡ Vector.proj v(x)) → (IsTrue(x ≡? y) ∨ (Vector.proj v(x) ≡ zero))
r p with (x ≡? y)
... | 𝑇 = [∨]-introₗ [⊤]-intro
... | 𝐹 = [∨]-introᵣ (symmetry(_≡_) p)
scalarMat-element-zero : (Matrix.proj (SquareMatrix.scalarMat zero elem) (x , y) ≡ zero) ↔ ((x ≢ₑ y) ∨ (elem ≡ zero))
scalarMat-element-zero {zero = zero}{elem = elem}{x = x}{y = y} =
Matrix.proj (SquareMatrix.scalarMat zero elem) (x , y) ≡ zero ⇔-[]
Matrix.proj (SquareMatrix.diagMat zero (Vector.fill elem)) (x , y) ≡ zero ⇔-[ diagMat-element-zero ]
(x ≢ₑ y) ∨ (Vector.proj (Vector.fill elem)(x) ≡ zero) ⇔-[]
(x ≢ₑ y) ∨ (elem ≡ zero) ⇔-end
scalarMat-element-scalar : (Matrix.proj (SquareMatrix.scalarMat zero elem) (x , y) ≡ elem) ↔ ((x ≡ₑ y) ∨ (elem ≡ zero))
scalarMat-element-scalar {zero = zero}{elem = elem}{x = x}{y = y} =
Matrix.proj (SquareMatrix.scalarMat zero elem) (x , y) ≡ elem ⇔-[]
Matrix.proj (SquareMatrix.diagMat zero (Vector.fill elem)) (x , y) ≡ Vector.fill elem(x) ⇔-[ diagMat-element-vector ]
(x ≡ₑ y) ∨ (Vector.proj (Vector.fill elem)(x) ≡ zero) ⇔-[]
(x ≡ₑ y) ∨ (elem ≡ zero) ⇔-end
map₂-tail : Vector.tail(Vector.map₂(_▫_) v₁ v₂) ≡ Vector.map₂(_▫_) (Vector.tail v₁) (Vector.tail v₂)
_⊜_.proof (map₂-tail {d = 𝐒(d)}) = reflexivity(_≡_)
-- TODO: Probably not neccessary : row-tail : ∀{M : Matrix(𝐒(w) , 𝐒(h))(T)}{i} → Vector.tail(Matrix.row {s = (𝐒(w) , 𝐒(h))} M (𝐒(i))) ≡ Matrix.row {s = (w , h)}(Matrix.minor M(𝟎 , 𝟎))(i)
col-scalarMat-is-indexProject : ∀{false true : T}{i : 𝕟(n)} → (Matrix.col(SquareMatrix.scalarMat {d = n} false true)(i) ≡ Vector.indexProject i true false)
_⊜_.proof (col-scalarMat-is-indexProject {i = i}) {x} with (i ≡? x)
... | 𝑇 = reflexivity(_≡_)
... | 𝐹 = reflexivity(_≡_)
row-scalarMat-is-indexProject : ∀{false true : T}{i : 𝕟(n)} → (Matrix.row(SquareMatrix.scalarMat {d = n} false true)(i) ≡ Vector.indexProject i true false)
_⊜_.proof (row-scalarMat-is-indexProject {i = i}) {x} with (i ≡? x) | (x ≡? i) | commutativity ⦃ [≡]-equiv ⦄ (_≡?_) {i}{x}
... | 𝑇 | 𝑇 | [≡]-intro = reflexivity(_≡_)
... | 𝑇 | 𝐹 | ()
... | 𝐹 | 𝑇 | ()
... | 𝐹 | 𝐹 | [≡]-intro = reflexivity(_≡_)
module _
⦃ oper₁ : BinaryOperator(_+ₛ_) ⦄
⦃ oper₂ : BinaryOperator(_⋅ₛ_) ⦄
⦃ ident₁ : Identityᵣ(_+ₛ_)(𝟎ₛ) ⦄
⦃ ident₂ : Identityᵣ(_⋅ₛ_)(𝟏ₛ) ⦄
⦃ absor₂ : Absorberᵣ(_⋅ₛ_)(𝟎ₛ) ⦄
where
instance
postulate matrix-multPattern-identityᵣ : Identityᵣ{T₁ = Matrix(s) T}(Matrix.multPattern(_+ₛ_)(_⋅ₛ_) 𝟎ₛ) (SquareMatrix.scalarMat 𝟎ₛ 𝟏ₛ)
{-_⊜_.proof (Identityᵣ.proof (matrix-multPattern-identityᵣ ) {M}) {x , y} =
Matrix.proj (Matrix.multPattern(_+ₛ_)(_⋅ₛ_) 𝟎ₛ M (SquareMatrix.scalarMat 𝟎ₛ 𝟏ₛ)) (x , y) 🝖[ _≡_ ]-[]
Vector.foldᵣ(_+ₛ_) 𝟎ₛ (Vector.map₂(_⋅ₛ_) (Matrix.row(M)(y)) (Matrix.col(SquareMatrix.scalarMat 𝟎ₛ 𝟏ₛ)(x))) 🝖[ _≡_ ]-[ congruence₁(Vector.foldᵣ(_+ₛ_) 𝟎ₛ) (congruence₂ᵣ(Vector.map₂(_⋅ₛ_))(Matrix.row M(y)) (col-scalarMat-is-indexProject {false = 𝟎ₛ}{true = 𝟏ₛ}{i = x})) ]
Vector.foldᵣ(_+ₛ_) 𝟎ₛ (Vector.map₂(_⋅ₛ_) (Matrix.row(M)(y)) (Vector.indexProject x 𝟏ₛ 𝟎ₛ)) 🝖[ _≡_ ]-[ congruence₁(Vector.foldᵣ(_+ₛ_) 𝟎ₛ) (Vector.map₂-indexProject-identityᵣ {v = Matrix.row(M)(y)}{i = x}) ]
Vector.foldᵣ(_+ₛ_) 𝟎ₛ (Vector.indexProject x (Vector.proj(Matrix.row(M)(y))(x)) 𝟎ₛ) 🝖[ _≡_ ]-[]
Vector.foldᵣ(_+ₛ_) 𝟎ₛ (Vector.indexProject x (Matrix.proj M(x , y)) 𝟎ₛ) 🝖[ _≡_ ]-[ {!!} ]
Matrix.proj M(x , y) ⋅ₛ (Vector.foldᵣ(_+ₛ_) 𝟎ₛ (Vector.indexProject x 𝟏ₛ 𝟎ₛ)) 🝖[ _≡_ ]-[ congruence₂ᵣ(_⋅ₛ_)(_) {!!} ]
Matrix.proj M(x , y) ⋅ₛ 𝟏ₛ 🝖[ _≡_ ]-[ identityᵣ(_⋅ₛ_)(𝟏ₛ) ]
Matrix.proj M(x , y) 🝖-end
-}
module _
⦃ oper₁ : BinaryOperator(_+ₛ_) ⦄
⦃ oper₂ : BinaryOperator(_⋅ₛ_) ⦄
⦃ ident₁ : Identityₗ(_▫₁_)(id₁) ⦄
⦃ ident₂ : Identityₗ(_▫₂_)(id₂) ⦄
⦃ absor₂ : Absorberₗ(_⋅ₛ_)(𝟎ₛ) ⦄
where
instance
postulate matrix-multPattern-identityₗ : Identityₗ{T₂ = Matrix(n , n) T}(Matrix.multPattern(_▫₂_)(_▫₁_) id₁) (SquareMatrix.scalarMat id₂ id₁)
module _
⦃ oper₁ : BinaryOperator(_+ₛ_) ⦄
⦃ oper₂ : BinaryOperator(_⋅ₛ_) ⦄
⦃ ident₁ : Identity(_▫₁_)(id₁) ⦄
⦃ ident₂ : Identity(_▫₂_)(id₂) ⦄
⦃ absor₂ : Absorber(_⋅ₛ_)(𝟎ₛ) ⦄
where
instance
postulate matrix-multPattern-identity : Identity{T = Matrix(n , n) T}(Matrix.multPattern(_▫₂_)(_▫₁_) id₁) (SquareMatrix.scalarMat id₂ id₁)
{-
instance
matrix-map₂-distributivityᵣ : ⦃ dist : Distributivityᵣ(_▫₁_)(_▫₂_) ⦄ → Distributivityᵣ(Matrix.multPattern(_▫₂_)(_▫₁_) id) (Matrix.map₂{s = s}(_▫₂_))
_⊜_.proof (Distributivityᵣ.proof (matrix-map₂-distributivityᵣ {_▫₁_} {_▫₂_} {id = id}) {a} {b} {c}) {x , y} =
Matrix.proj(Matrix.multPattern(_▫₂_) (_▫₁_) id (Matrix.map₂(_▫₂_) a b) c) (x , y) 🝖[ _≡_ ]-[]
Vector.foldᵣ(_▫₂_) id (Vector.map₂ (_▫₁_) (Matrix.row(Matrix.map₂(_▫₂_) a b)(y)) (Matrix.col(c)(x))) 🝖[ _≡_ ]-[]
Vector.foldᵣ(_▫₂_) id (Vector.map₂(_▫₁_) (λ x₁ → (Matrix.proj a (x₁ , y)) ▫₂ (Matrix.proj b (x₁ , y))) (λ y₁ → Matrix.proj c (x , y₁))) 🝖[ _≡_ ]-[ {!!} ]
(Vector.foldᵣ(_▫₂_) id (Vector.map₂ _▫₁_ (λ x₁ → Matrix.proj a (x₁ , y)) (λ y₁ → Matrix.proj c (x , y₁)))) ▫₂ (Vector.foldᵣ(_▫₂_) id (Vector.map₂(_▫₁_) (λ x₁ → Matrix.proj b (x₁ , y)) (λ y₁ → Matrix.proj c (x , y₁)))) 🝖[ _≡_ ]-[]
(Vector.foldᵣ(_▫₂_) id (Vector.map₂ (_▫₁_) (Matrix.row(a)(y)) (Matrix.col(c)(x)))) ▫₂ (Vector.foldᵣ(_▫₂_) id (Vector.map₂ (_▫₁_) (Matrix.row(b)(y)) (Matrix.col(c)(x)))) 🝖[ _≡_ ]-[]
Matrix.proj(Matrix.map₂(_▫₂_) (Matrix.multPattern(_▫₂_)(_▫₁_) id a c) (Matrix.multPattern(_▫₂_)(_▫₁_) id b c)) (x , y) 🝖-end
-}
| {
"alphanum_fraction": 0.6053691275,
"avg_line_length": 56.3445378151,
"ext": "agda",
"hexsha": "1871cab6d693ae7f7be9db117b7d0e8abae540a8",
"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/Matrix/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/Matrix/Proofs.agda",
"max_line_length": 276,
"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/Matrix/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": 5296,
"size": 13410
} |
module Logic.Linear.Properties where
open import Logic.Linear using
(LinearProp; _⊢_; Proof
; _^⊥; _⊗_; _⊕_; _&_; _⅋_; _⊸_; _≡_; e!_; e?_
; ^⊥-i; ⊗-i; ⊕-i₁; ⊕-i₂; &-i; ⅋-i; e?-i₁; e?-i₂; e!-i; e?-e; swap
)
open import Data.Nat using (ℕ; zero; suc)
open import Data.Fin using (Fin; zero; suc)
open import Data.Vec using (Vec; []; _∷_; _++_; map)
one : {n : ℕ} → Fin (suc (suc n))
one = suc zero
two : {n : ℕ} → Fin (suc (suc (suc n)))
two = suc one
three : {n : ℕ} → Fin (suc (suc (suc (suc n))))
three = suc two
-- Proof of distributivity of _⊗_ over _⊕_: p ⊗ (q ⊕ r) ≡ (p ⊗ q) ⊕ (p ⊗ r).
⊕⊗-distrib : ∀ {a}
{A : Set a}
(S : LinearProp A → Set a)
{p q r : LinearProp A} →
Proof S (p ⊗ (q ⊕ r) ≡ (p ⊗ q) ⊕ (p ⊗ r))
⊕⊗-distrib {_} {_} S {p} {q} {r} = &-i left⊸right right⊸left where
left⊸right : S ⊢ (p ⊗ (q ⊕ r) ⊸ p ⊗ q ⊕ p ⊗ r ∷ [])
left⊸right = ⅋-i (⅋-i (swap zero one q&r)) where
q&r : S ⊢ (q ^⊥ & r ^⊥ ∷ p ^⊥ ∷ p ⊗ q ⊕ p ⊗ r ∷ [])
q&r = &-i q-side r-side where
q-side : S ⊢ (q ^⊥ ∷ p ^⊥ ∷ p ⊗ q ⊕ p ⊗ r ∷ [])
q-side = swap one two (swap zero one disj)
where
conj : S ⊢ (p ⊗ q ∷ p ^⊥ ∷ q ^⊥ ∷ [])
conj = ⊗-i (^⊥-i p) (^⊥-i q)
disj : S ⊢ (p ⊗ q ⊕ p ⊗ r ∷ q ^⊥ ∷ p ^⊥ ∷ [])
disj = ⊕-i₁ (swap one two conj)
r-side : S ⊢ (r ^⊥ ∷ p ^⊥ ∷ p ⊗ q ⊕ p ⊗ r ∷ [])
r-side = swap one two (swap zero one disj)
where
conj : S ⊢ (p ⊗ r ∷ p ^⊥ ∷ r ^⊥ ∷ [])
conj = ⊗-i (^⊥-i p) (^⊥-i r)
disj : S ⊢ (p ⊗ q ⊕ p ⊗ r ∷ r ^⊥ ∷ p ^⊥ ∷ [])
disj = ⊕-i₂ (swap one two conj)
right⊸left : S ⊢ (p ⊗ q ⊕ p ⊗ r ⊸ p ⊗ (q ⊕ r) ∷ [])
right⊸left = ⅋-i (&-i q-side r-side) where
q-side : S ⊢ (p ^⊥ ⅋ q ^⊥ ∷ p ⊗ (q ⊕ r) ∷ [])
q-side = ⅋-i (swap one two (swap zero one conj)) where
disj : S ⊢ (q ⊕ r ∷ q ^⊥ ∷ [])
disj = ⊕-i₁ (^⊥-i q)
conj : S ⊢ (p ⊗ (q ⊕ r) ∷ p ^⊥ ∷ q ^⊥ ∷ [])
conj = ⊗-i (^⊥-i p) disj
r-side : S ⊢ (p ^⊥ ⅋ r ^⊥ ∷ p ⊗ (q ⊕ r) ∷ [])
r-side = ⅋-i (swap one two (swap zero one conj)) where
disj : S ⊢ (q ⊕ r ∷ r ^⊥ ∷ [])
disj = ⊕-i₂ (^⊥-i r)
conj : S ⊢ (p ⊗ (q ⊕ r) ∷ p ^⊥ ∷ r ^⊥ ∷ [])
conj = ⊗-i (^⊥-i p) disj
-- Proof of isomorphism of e!_ through _&_ and _⊗_: e! (p & q) ≡ (e! p) ⊗ (e! q).
e!-iso : ∀ {a}
{A : Set a}
(S : LinearProp A → Set a)
{p q : LinearProp A} →
Proof S (e! (p & q) ≡ (e! p) ⊗ (e! q))
e!-iso {_} {_} S {p} {q} = &-i left⊸right right⊸left where
left⊸right : S ⊢ (e! (p & q) ⊸ e! p ⊗ e! q ∷ [])
left⊸right = ⅋-i (e?-e (swap zero two conj)) where
p-side : S ⊢ (p ∷ e? (p ^⊥ ⊕ q ^⊥) ∷ [])
p-side = swap zero one (e?-i₂ disj) where
disj : S ⊢ (p ^⊥ ⊕ q ^⊥ ∷ p ∷ [])
disj = ⊕-i₁ (swap zero one (^⊥-i p))
q-side : S ⊢ (q ∷ e? (p ^⊥ ⊕ q ^⊥) ∷ [])
q-side = swap zero one (e?-i₂ disj) where
disj : S ⊢ (p ^⊥ ⊕ q ^⊥ ∷ q ∷ [])
disj = ⊕-i₂ (swap zero one (^⊥-i q))
conj : S ⊢ (e! p ⊗ e! q ∷ e? (p ^⊥ ⊕ q ^⊥) ∷ e? (p ^⊥ ⊕ q ^⊥) ∷ [])
conj = ⊗-i (e!-i p-side) (e!-i q-side)
right⊸left : S ⊢ (e! p ⊗ e! q ⊸ e! (p & q) ∷ [])
right⊸left = ⅋-i (⅋-i swapped) where
p-side : S ⊢ (p ∷ e? (p ^⊥) ∷ e? (q ^⊥) ∷ [])
p-side = swap zero two (e?-i₁ init) where
init : S ⊢ (e? (p ^⊥) ∷ p ∷ [])
init = e?-i₂ (swap zero one (^⊥-i p))
q-side : S ⊢ (q ∷ e? (p ^⊥) ∷ e? (q ^⊥) ∷ [])
q-side = swap zero one (swap one two (e?-i₁ init)) where
init : S ⊢ (e? (q ^⊥) ∷ q ∷ [])
init = e?-i₂ (swap zero one (^⊥-i q))
conj : S ⊢ (p & q ∷ e? (p ^⊥) ∷ e? (q ^⊥) ∷ [])
conj = &-i p-side q-side
swapped : S ⊢ (e? (p ^⊥) ∷ e? (q ^⊥) ∷ e! (p & q) ∷ [])
swapped = swap one two (swap zero one (e!-i conj))
-- Proof of mapping of _⊗_ and _⅋_: p ⊗ (q ⅋ r) ⊸ (p ⊗ q) ⅋ r.
⊗⅋-map : ∀ {a}
{A : Set a}
(S : LinearProp A → Set a)
{p q r : LinearProp A} →
Proof S (p ⊗ (q ⅋ r) ⊸ (p ⊗ q) ⅋ r)
⊗⅋-map {_} {_} S {p} {q} {r} = ⅋-i (⅋-i (swap zero two disj)) where
pq-side : S ⊢ (q ^⊥ ∷ p ⊗ q ∷ p ^⊥ ∷ [])
pq-side = swap zero one (swap one two (⊗-i (^⊥-i p) (^⊥-i q)))
r-side : S ⊢ (r ^⊥ ∷ r ∷ [])
r-side = swap zero one (^⊥-i r)
conj : S ⊢ (q ^⊥ ⊗ r ^⊥ ∷ p ⊗ q ∷ p ^⊥ ∷ r ∷ [])
conj = ⊗-i pq-side r-side
disj : S ⊢ (p ⊗ q ⅋ r ∷ (q ^⊥ ⊗ r ^⊥) ∷ p ^⊥ ∷ [])
disj = ⅋-i (swap one two (swap zero one (swap two three conj)))
| {
"alphanum_fraction": 0.3983721456,
"avg_line_length": 40.9537037037,
"ext": "agda",
"hexsha": "5f2317feb6418b829d1ead546c7ee5038bd5a2eb",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "brunoczim/linear-logic",
"max_forks_repo_path": "src/Logic/Linear/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "brunoczim/linear-logic",
"max_issues_repo_path": "src/Logic/Linear/Properties.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "9ce2e8b0e801b3c68b7e00731f57bc322d89f222",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "brunoczim/linear-logic",
"max_stars_repo_path": "src/Logic/Linear/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2322,
"size": 4423
} |
------------------------------------------------------------------------------
-- In the Agda standard library, gcd 0 0 = 0.
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.GCD.GCD00-SL where
open import Data.Nat.GCD
open import Data.Product
open import Relation.Binary.PropositionalEquality
open GCD hiding ( refl )
------------------------------------------------------------------------------
gcd00 : proj₁ (gcd 0 0) ≡ 0
gcd00 = refl
-- A different proof.
gcd00' : GCD 0 0 0
gcd00' = base
| {
"alphanum_fraction": 0.4242424242,
"avg_line_length": 27.9230769231,
"ext": "agda",
"hexsha": "d49c8302ee8c6f6fbf871cbe100164a02531ee1f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/GCD/GCD00-SL.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/GCD/GCD00-SL.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/GCD/GCD00-SL.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 146,
"size": 726
} |
module SystemF where
open import Data.Nat using (ℕ; zero; suc; _+_)
open import Data.Fin as Fin using (Fin; zero; suc)
open import Function as Fun using (_∘_)
open import Relation.Binary.PropositionalEquality as Eq
using (_≡_; refl; cong; cong₂; cong-app; sym)
open Eq.≡-Reasoning
-- ------------------------------------------------------------------------
infixr 7 _⇒_
infix 9 `_
data Type (n : ℕ) : Set where
`_ : Fin n → Type n
_⇒_ : Type n → Type n → Type n
`∀ : Type (1 + n) → Type n
⇒-cong : ∀ { n } { τ₁¹ τ₁² τ₂¹ τ₂² : Type n }
→ τ₁¹ ≡ τ₂¹
→ τ₁² ≡ τ₂²
-- ----------------------
→ τ₁¹ ⇒ τ₁² ≡ τ₂¹ ⇒ τ₂²
⇒-cong ≡τ¹ ≡τ² = cong₂ _⇒_ ≡τ¹ ≡τ²
`∀-cong : ∀ { n } { τ₁ τ₂ : Type (1 + n) }
→ τ₁ ≡ τ₂
-- -------------
→ `∀ τ₁ ≡ `∀ τ₂
`∀-cong ≡τ = cong `∀ ≡τ
-- ------------------------------------------------------------------------
open import Sigma.Subst.Core
open import Sigma.Renaming.Base
ren-τ : ∀ { m n } → Ren m n → Type m → Type n
ren-τ ρ (` α) = ` ρ α
ren-τ ρ (τ₁ ⇒ τ₂) = ren-τ ρ τ₁ ⇒ ren-τ ρ τ₂
ren-τ ρ (`∀ τ) = `∀ (ren-τ (ρ ⇑) τ)
_⇑τ : ∀ { m n } → Sub (Type n) m → Sub (Type (1 + n)) (1 + m)
σ ⇑τ = ` zero ∷ (ren-τ ↑ ∘ σ)
sub-τ : ∀ { m n } → Sub (Type n) m → Type m → Type n
sub-τ σ (` α) = σ α
sub-τ σ (τ₁ ⇒ τ₂) = sub-τ σ τ₁ ⇒ sub-τ σ τ₂
sub-τ σ (`∀ τ) = `∀ (sub-τ (σ ⇑τ) τ)
-- ------------------------------------------------------------------------
open import Sigma.Subst.Properties using (extensionality)
open import Sigma.Renaming.Properties using (∘-⇑-distrib; ⇑-id)
-- ------------------------------------------------------------------------
-- Congruences
-- ------------------------------------------------------------------------
ren-τ-cong : ∀ { m n } { ρ₁ ρ₂ : Ren m n }
→ ρ₁ ≡ ρ₂
-- -------
→ ren-τ ρ₁ ≡ ren-τ ρ₂
ren-τ-cong ρ₁≡ρ₂ = cong ren-τ ρ₁≡ρ₂
⇑τ-cong : ∀ { m n } { σ₁ σ₂ : Sub (Type n) m }
→ σ₁ ≡ σ₂
-- ------------
→ σ₁ ⇑τ ≡ σ₂ ⇑τ
⇑τ-cong σ₁≡σ₂ = cong _⇑τ σ₁≡σ₂
-- ⇑τ✶-cong
sub-τ-cong : ∀ { m n } { σ₁ σ₂ : Sub (Type n) m }
→ σ₁ ≡ σ₂
-- --------
→ sub-τ σ₁ ≡ sub-τ σ₂
sub-τ-cong σ₁≡σ₂ = cong sub-τ σ₁≡σ₂
-- ------------------------------------------------------------------------
-- Coincidence Laws
-- ------------------------------------------------------------------------
-- Every renaming can form a subsitution
⇑τ-coincidence : ∀ { m n } (ρ : Ren m n)
→ `_ ∘ (ρ ⇑) ≡ (`_ ∘ ρ) ⇑τ
⇑τ-coincidence ρ = extensionality lemma
where
lemma : ∀ x → ` ((ρ ⇑) x) ≡ ((`_ ∘ ρ) ⇑τ) x
lemma zero = refl
lemma (suc x) = refl
ren-τ-coincidence : ∀ { m n } (ρ : Ren m n)
→ ren-τ ρ ≡ sub-τ (`_ ∘ ρ)
ren-τ-coincidence ρ = extensionality (lemma ρ)
where
lemma : ∀ { m n } (ρ : Ren m n)
→ ∀ τ → ren-τ ρ τ ≡ sub-τ (`_ ∘ ρ) τ
lemma ρ (` α) = refl
lemma ρ (τ₁ ⇒ τ₂) = ⇒-cong (lemma ρ τ₁) (lemma ρ τ₂)
lemma ρ (`∀ τ) = `∀-cong (
begin
ren-τ (ρ ⇑) τ
≡⟨ lemma (ρ ⇑) τ ⟩
sub-τ (`_ ∘ (ρ ⇑)) τ
≡⟨ cong-app (sub-τ-cong (⇑τ-coincidence ρ)) τ ⟩
sub-τ ((`_ ∘ ρ) ⇑τ) τ
∎)
-- ------------------------------------------------------------------------
-- Identity laws
-- ------------------------------------------------------------------------
⇑τ-id : ∀ { n : ℕ } → ((`_ { n }) ⇑τ) ≡ `_ { n = 1 + n }
⇑τ-id = extensionality (lemma)
where
lemma : ∀ { n : ℕ } x → ((`_ { n }) ⇑τ) x ≡ ` x
lemma zero = refl
lemma (suc x) = refl
ren-τ-idᵣ : ∀ { n } → ren-τ (id { n }) ≡ Fun.id
ren-τ-idᵣ = extensionality lemma
where
lemma : ∀ { n } τ → ren-τ (id { n }) τ ≡ τ
lemma (` α) = refl
lemma (τ₁ ⇒ τ₂) = ⇒-cong (lemma τ₁) (lemma τ₂)
lemma (`∀ τ) = `∀-cong (
begin
ren-τ (id ⇑) τ
≡⟨ cong-app (ren-τ-cong ⇑-id) τ ⟩
ren-τ id τ
≡⟨ lemma τ ⟩
τ
∎)
sub-τ-idₗ : ∀ { m n } (σ : Sub (Type n) m)
→ sub-τ σ ∘ `_ ≡ σ
sub-τ-idₗ σ = extensionality lemma
where
lemma : ∀ x → sub-τ σ (` x) ≡ σ x
lemma zero = refl
lemma (suc x) = refl
-- The functional form of the Monad Law: Right Identity
sub-τ-idᵣ : ∀ { n } → sub-τ (`_ {n}) ≡ Fun.id
sub-τ-idᵣ = extensionality lemma
where
lemma : ∀ { n } τ → sub-τ (`_ {n}) τ ≡ τ
lemma (` α) = refl
lemma (τ₁ ⇒ τ₂) = ⇒-cong (lemma τ₁) (lemma τ₂)
lemma (`∀ τ) = `∀-cong (
begin
sub-τ ((`_) ⇑τ) τ
≡⟨ cong-app (sub-τ-cong ⇑τ-id) τ ⟩
sub-τ (`_) τ
≡⟨ lemma τ ⟩
τ
∎)
-- ------------------------------------------------------------------------
-- Monad Law : Compositionality
-- ------------------------------------------------------------------------
-- Lemmas required to prove the law:
-- sub-τ σ₂ ∘ sub-τ σ₁ ≡ sub-τ (sub-τ σ₂ ∘ σ₁)
∘-ren-τ-distrib : ∀ { m n k } ( ρ₁ : Ren m n ) ( ρ₂ : Ren n k )
→ ren-τ ρ₂ ∘ ren-τ ρ₁ ≡ ren-τ (ρ₂ ∘ ρ₁)
∘-ren-τ-distrib ρ₁ ρ₂ = extensionality (lemma ρ₁ ρ₂)
where
lemma : ∀ { m n k } ( ρ₁ : Ren m n ) ( ρ₂ : Ren n k )
→ ∀ τ → ren-τ ρ₂ (ren-τ ρ₁ τ) ≡ ren-τ (ρ₂ ∘ ρ₁) τ
lemma ρ₁ ρ₂ (` α) = refl
lemma ρ₁ ρ₂ (τ₁ ⇒ τ₂) = ⇒-cong (lemma ρ₁ ρ₂ τ₁) (lemma ρ₁ ρ₂ τ₂)
lemma ρ₁ ρ₂ (`∀ τ) = `∀-cong (
begin
ren-τ (ρ₂ ⇑) (ren-τ (ρ₁ ⇑) τ)
≡⟨ lemma (ρ₁ ⇑) (ρ₂ ⇑) τ ⟩
ren-τ (ρ₂ ⇑ ∘ ρ₁ ⇑) τ
≡⟨ cong-app (ren-τ-cong (∘-⇑-distrib ρ₁ ρ₂)) τ ⟩
ren-τ ((ρ₂ ∘ ρ₁) ⇑) τ
∎)
∘-⇑-ren-τ-distrib : ∀ { m n k } (σ : Sub (Type n) m) (ρ : Ren n k)
→ ren-τ (ρ ⇑) ∘ (σ ⇑τ) ≡ (ren-τ ρ ∘ σ) ⇑τ
∘-⇑-ren-τ-distrib σ ρ = extensionality lemma
where
lemma : ∀ x → ren-τ (ρ ⇑) ((σ ⇑τ) x) ≡ ((ren-τ ρ ∘ σ) ⇑τ) x
lemma zero = refl
lemma (suc x) =
begin
ren-τ (ρ ⇑) ((σ ⇑τ) (suc x))
≡⟨⟩
ren-τ (ρ ⇑) (ren-τ ↑ (σ x))
≡⟨ cong-app (∘-ren-τ-distrib ↑ (ρ ⇑)) (σ x) ⟩
ren-τ (ρ ⇑ ∘ ↑) (σ x)
≡⟨ cong-app (sym (∘-ren-τ-distrib ρ ↑)) (σ x) ⟩
ren-τ ↑ (ren-τ ρ (σ x))
≡⟨⟩
((ren-τ ρ ∘ σ) ⇑τ) (suc x)
∎
-- ∘-⇑✶-ren-τ-distrib
∘-⇑-τ-distrib : ∀ { m n k } (σ : Sub (Type k) n) (ρ : Ren m n)
→ (σ ⇑τ) ∘ (ρ ⇑) ≡ (σ ∘ ρ) ⇑τ
∘-⇑-τ-distrib σ ρ = extensionality lemma
where
lemma : ∀ x → (σ ⇑τ) ((ρ ⇑) x) ≡ ((σ ∘ ρ) ⇑τ) x
lemma zero = refl
lemma (suc x) = refl
∘-sub-ren-τ-distrib : ∀ { m n k } (σ : Sub (Type k) n) (ρ : Ren m n)
→ sub-τ σ ∘ ren-τ ρ ≡ sub-τ (σ ∘ ρ)
∘-sub-ren-τ-distrib σ ρ = extensionality (lemma σ ρ)
where
lemma : ∀ { m n k } (σ : Sub (Type k) n) (ρ : Ren m n)
→ ∀ τ → sub-τ σ (ren-τ ρ τ) ≡ sub-τ (σ ∘ ρ) τ
lemma σ ρ (` α) = refl
lemma σ ρ (τ₁ ⇒ τ₂) = ⇒-cong (lemma σ ρ τ₁) (lemma σ ρ τ₂)
lemma σ ρ (`∀ τ) = `∀-cong (
begin
sub-τ (σ ⇑τ) (ren-τ (ρ ⇑) τ)
≡⟨ lemma (σ ⇑τ) (ρ ⇑) τ ⟩
sub-τ ((σ ⇑τ) ∘ (ρ ⇑)) τ
≡⟨ cong-app (sub-τ-cong (∘-⇑-τ-distrib σ ρ)) τ ⟩
sub-τ ((σ ∘ ρ) ⇑τ) τ
∎)
∘-ren-sub-τ-distrib : ∀ { m n k } (σ : Sub (Type n) m) (ρ : Ren n k)
→ ren-τ ρ ∘ sub-τ σ ≡ sub-τ (ren-τ ρ ∘ σ)
∘-ren-sub-τ-distrib σ ρ = extensionality (lemma σ ρ)
where
lemma : ∀ { m n k } (σ : Sub (Type n) m) (ρ : Ren n k)
→ ∀ τ → ren-τ ρ (sub-τ σ τ) ≡ sub-τ (ren-τ ρ ∘ σ) τ
lemma σ ρ (` α) = refl
lemma σ ρ (τ₁ ⇒ τ₂) = ⇒-cong (lemma σ ρ τ₁) (lemma σ ρ τ₂)
lemma σ ρ (`∀ τ) = `∀-cong (
begin
ren-τ (ρ ⇑) (sub-τ (σ ⇑τ) τ)
≡⟨ lemma (σ ⇑τ) (ρ ⇑) τ ⟩
sub-τ (ren-τ (ρ ⇑) ∘ (σ ⇑τ)) τ
≡⟨ cong-app (sub-τ-cong (∘-⇑-ren-τ-distrib σ ρ)) τ ⟩
sub-τ ((ren-τ ρ ∘ σ) ⇑τ) τ
∎)
∘-⇑-sub-τ-distrib : ∀ { m n k } (σ₁ : Sub (Type n) m) (σ₂ : Sub (Type k) n)
→ sub-τ (σ₂ ⇑τ) ∘ σ₁ ⇑τ ≡ (sub-τ σ₂ ∘ σ₁) ⇑τ
∘-⇑-sub-τ-distrib σ₁ σ₂ = extensionality lemma
where
lemma : ∀ x → sub-τ (σ₂ ⇑τ) ((σ₁ ⇑τ) x) ≡ ((sub-τ σ₂ ∘ σ₁) ⇑τ) x
lemma zero = refl
lemma (suc x) =
begin
sub-τ (σ₂ ⇑τ) ((σ₁ ⇑τ) (suc x))
≡⟨⟩
sub-τ (σ₂ ⇑τ) (ren-τ ↑ (σ₁ x))
≡⟨ cong-app (∘-sub-ren-τ-distrib (σ₂ ⇑τ) ↑) (σ₁ x) ⟩
sub-τ ((σ₂ ⇑τ) ∘ ↑) (σ₁ x)
≡⟨⟩
sub-τ (ren-τ ↑ ∘ σ₂) (σ₁ x)
≡⟨ cong-app (sym (∘-ren-sub-τ-distrib σ₂ ↑)) (σ₁ x) ⟩
ren-τ ↑ (sub-τ σ₂ (σ₁ x))
≡⟨⟩
((sub-τ σ₂ ∘ σ₁) ⇑τ) (suc x)
∎
∘-sub-τ-distrib : ∀ { m n k } ( σ₁ : Sub (Type n) m ) ( σ₂ : Sub (Type k) n )
→ sub-τ σ₂ ∘ sub-τ σ₁ ≡ sub-τ (sub-τ σ₂ ∘ σ₁)
∘-sub-τ-distrib σ₁ σ₂ = extensionality (lemma σ₁ σ₂)
where
lemma : ∀ { m n k } ( σ₁ : Sub (Type n) m ) ( σ₂ : Sub (Type k) n )
→ ∀ τ → sub-τ σ₂ (sub-τ σ₁ τ) ≡ sub-τ (sub-τ σ₂ ∘ σ₁) τ
lemma σ₁ σ₂ (` α) = refl
lemma σ₁ σ₂ (τ₁ ⇒ τ₂) = ⇒-cong (lemma σ₁ σ₂ τ₁) (lemma σ₁ σ₂ τ₂)
lemma σ₁ σ₂ (`∀ τ) = `∀-cong (
begin
sub-τ (σ₂ ⇑τ) (sub-τ (σ₁ ⇑τ) τ)
≡⟨ lemma (σ₁ ⇑τ) (σ₂ ⇑τ) τ ⟩
sub-τ (sub-τ (σ₂ ⇑τ) ∘ (σ₁ ⇑τ)) τ
≡⟨ cong-app (sub-τ-cong (∘-⇑-sub-τ-distrib σ₁ σ₂)) τ ⟩
sub-τ ((sub-τ σ₂ ∘ σ₁) ⇑τ) τ
∎)
-- ------------------------------------------------------------------------
-- Supplementary Laws
-- ------------------------------------------------------------------------
∘-sub-τ : ∀ { m n k l } ( σ₁ : Sub (Type n) m ) ( σ₂ : Sub (Type k) n ) (σ₃ : Sub (Type l) k)
→ sub-τ σ₃ ∘ (sub-τ σ₂ ∘ σ₁) ≡ sub-τ (sub-τ σ₃ ∘ σ₂) ∘ σ₁
∘-sub-τ σ₁ σ₂ σ₃ =
begin
sub-τ σ₃ ∘ (sub-τ σ₂ ∘ σ₁)
≡⟨⟩
(sub-τ σ₃ ∘ sub-τ σ₂) ∘ σ₁
≡⟨ cong (_∘ σ₁) (∘-sub-τ-distrib σ₂ σ₃) ⟩
sub-τ (sub-τ σ₃ ∘ σ₂) ∘ σ₁
∎
-- ------------------------------------------------------------------------
-- infixl 7 _·_ _[_]
-- infix 9 #_
-- data Term (n : ℕ) (m : ℕ) : Set where
-- #_ : Fin n → Term n m
-- ƛ : Term (1 + n) m → Term n m
-- _·_ : Term n m → Term n m → Term n m
-- _[_] : Term n m → Type m → Term n m
-- Λ : Term n (1 + m) → Term n m
| {
"alphanum_fraction": 0.4032641256,
"avg_line_length": 29.247734139,
"ext": "agda",
"hexsha": "1faa62943054e75ed9f3d6a3c9bcf6aaabe45527",
"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": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-sigma",
"max_forks_repo_path": "examples/SystemF.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "johnyob/agda-sigma",
"max_issues_repo_path": "examples/SystemF.agda",
"max_line_length": 93,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bb895fa8a3ccbefbd2c4a135c79744ba06895be7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-sigma",
"max_stars_repo_path": "examples/SystemF.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4393,
"size": 9681
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.types.Empty
open import lib.types.Group
open import lib.types.LoopSpace
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.TLevel
open import lib.types.Truncation
open import lib.groups.GroupProduct
open import lib.groups.Homomorphism
open import lib.groups.Isomorphism
open import lib.groups.LoopSpace
open import lib.groups.TruncationGroup
open import lib.groups.Unit
module lib.groups.HomotopyGroup where
{- Higher homotopy groups -}
module _ {i} where
πS : (n : ℕ) (X : Ptd i) → Group i
πS n X = Trunc-group (Ω^S-group-structure n X)
π'S : (n : ℕ) (X : Ptd i) → Group i
π'S n X = Trunc-group (Ω^'S-group-structure n X)
fundamental-group : (X : Ptd i) → Group i
fundamental-group X = πS 0 X
module _ {i j} (n : ℕ) {X : Ptd i} {Y : Ptd j} where
πS-fmap : X ⊙→ Y → (πS n X →ᴳ πS n Y)
πS-fmap F = Trunc-group-fmap (Ω^S-group-structure-fmap n F)
π'S-fmap : X ⊙→ Y → (π'S n X →ᴳ π'S n Y)
π'S-fmap F = Trunc-group-fmap (Ω^'S-group-structure-fmap n F)
πS-emap : (X ⊙≃ Y) → (πS n X ≃ᴳ πS n Y)
πS-emap e = Trunc-group-emap (Ω^S-group-structure-emap n e)
π'S-emap : (X ⊙≃ Y) → (π'S n X ≃ᴳ π'S n Y)
π'S-emap e = Trunc-group-emap (Ω^'S-group-structure-emap n e)
{- π_(n+1) of a space is π_n of its loop space -}
abstract
πS-Ω-split-iso : ∀ {i} (n : ℕ) (X : Ptd i)
→ πS (S n) X ≃ᴳ πS n (⊙Ω X)
πS-Ω-split-iso n X =
group-hom
(Trunc-fmap (Ω^-Ω-split (S n) X))
(Trunc-elim
(λ p → Trunc-elim
(λ q → ap [_] (Ω^S-Ω-split-∙ n X p q)))) ,
Trunc-isemap {n = 0} (Ω^-Ω-split-is-equiv (S n) X)
{- We can shift the truncation inside the loop in the definition of π -}
module _ {i} where
private
record Ω^STruncPreIso (n : ℕ) (m : ℕ₋₂) (k : ℕ₋₂) (X : Ptd i)
: Type i where
field
F : ⊙Ω^ (S n) (⊙Trunc k X) ⊙→ ⊙Trunc m (⊙Ω^ (S n) X)
pres-comp : ∀ (p q : Ω^ (S n) (⊙Trunc k X))
→ fst F (Ω^S-∙ n p q) == Trunc-fmap2 (Ω^S-∙ n) (fst F p) (fst F q)
e : is-equiv (fst F)
Ω^S-Trunc-preiso : (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ Ω^STruncPreIso n m (⟨ S n ⟩₋₂ +2+ m) X
Ω^S-Trunc-preiso O m X =
record { F = (–> (Trunc=-equiv [ pt X ] [ pt X ]) , idp);
pres-comp = Trunc=-∙-comm;
e = snd (Trunc=-equiv [ pt X ] [ pt X ]) }
Ω^S-Trunc-preiso (S n) m X =
let
r : Ω^STruncPreIso n (S m) (⟨ S n ⟩₋₂ +2+ S m) X
r = Ω^S-Trunc-preiso n (S m) X
H = (–> (Trunc=-equiv [ idp^ (S n) ] [ idp^ (S n) ]) , idp)
G = ⊙Ω-fmap (Ω^STruncPreIso.F r)
in
transport (λ k → Ω^STruncPreIso (S n) m k X)
(+2+-βr ⟨ S n ⟩₋₂ m)
(record {
F = H ⊙∘ G;
pres-comp = λ p q →
ap (fst H) (Ω^S-fmap-∙ 0 (Ω^STruncPreIso.F r) p q)
∙ (Trunc=-∙-comm (fst G p) (fst G q));
e = snd (Trunc=-equiv [ idp^ (S n) ] [ idp^ (S n) ]
∘e Ω^-emap 1 (Ω^STruncPreIso.F r , Ω^STruncPreIso.e r))})
Ω^S-group-Trunc-fuse-diag-iso : (n : ℕ) (X : Ptd i)
→ Ω^S-group n (⊙Trunc ⟨ S n ⟩ X) ≃ᴳ πS n X
Ω^S-group-Trunc-fuse-diag-iso n X = group-hom (fst F) pres-comp , e
where
r = transport (λ k → Ω^STruncPreIso n 0 k X)
(+2+0 ⟨ S n ⟩₋₂) (Ω^S-Trunc-preiso n 0 X)
open Ω^STruncPreIso r
{- favonia: the same lemma for the alternative homotopy groups is trivial. -}
Ω^'S-group-Trunc-fuse-diag-iso : (n : ℕ) (X : Ptd i)
→ Ω^'S-group n (⊙Trunc ⟨ S n ⟩ X) ≃ᴳ π'S n X
Ω^'S-group-Trunc-fuse-diag-iso O X =
≃-to-≃ᴳ (Trunc=-equiv [ pt X ] [ pt X ]) Trunc=-∙-comm
Ω^'S-group-Trunc-fuse-diag-iso (S n) X =
Ω^'S-group-Trunc-fuse-diag-iso n (⊙Ω X)
∘eᴳ Ω^'S-group-emap n {X = ⊙Ω (⊙Trunc ⟨ S (S n) ⟩ X)} (≃-to-⊙≃ (Trunc=-equiv [ pt X ] [ pt X ]) idp)
abstract
πS-Trunc-fuse-≤-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (⟨ S n ⟩ ≤T m) → πS n (⊙Trunc m X) ≃ᴳ πS n X
πS-Trunc-fuse-≤-iso n m X Sn≤m =
πS n (⊙Trunc m X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ Ω^S-group-emap n (≃-to-⊙≃ (Trunc-fuse-≤ (de⊙ X) Sn≤m) idp) ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n X ⟩
πS n X
≃ᴳ∎
π'S-Trunc-fuse-≤-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (⟨ S n ⟩ ≤T m) → π'S n (⊙Trunc m X) ≃ᴳ π'S n X
π'S-Trunc-fuse-≤-iso n m X Sn≤m =
π'S n (⊙Trunc m X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ Ω^'S-group-emap n (≃-to-⊙≃ (Trunc-fuse-≤ (de⊙ X) Sn≤m) idp) ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n X ⟩
π'S n X
≃ᴳ∎
πS-Trunc-fuse->-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → πS n (⊙Trunc m X) ≃ᴳ 0ᴳ
πS-Trunc-fuse->-iso n m X m<n =
πS n (⊙Trunc m X)
≃ᴳ⟨ Ω^S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ contr-iso-0ᴳ _ $ inhab-prop-is-contr
(Group.ident (Ω^S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))))
{{Ω^-level -1 (S n) _ $ Trunc-preserves-level ⟨ S n ⟩ $
raise-level-≤T
(transport (λ k → m ≤T k) (+2+-comm -1 ⟨ S n ⟩₋₂) (<T-to-≤T m<n))
(Trunc-level {n = m})}} ⟩
0ᴳ ≃ᴳ∎
π'S-Trunc-fuse->-iso : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → π'S n (⊙Trunc m X) ≃ᴳ 0ᴳ
π'S-Trunc-fuse->-iso n m X m<n =
π'S n (⊙Trunc m X)
≃ᴳ⟨ Ω^'S-group-Trunc-fuse-diag-iso n (⊙Trunc m X) ⁻¹ᴳ ⟩
Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))
≃ᴳ⟨ contr-iso-0ᴳ _ $ inhab-prop-is-contr
(Group.ident (Ω^'S-group n (⊙Trunc ⟨ S n ⟩ (⊙Trunc m X))))
{{Ω^'-is-prop (S n) _ $ Trunc-preserves-level ⟨ S n ⟩ $
raise-level-≤T (<T-to-≤T m<n) (Trunc-level {n = m})}} ⟩
0ᴳ ≃ᴳ∎
-- XXX Naming conventions?
πS->level-econv : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → {{_ : has-level m (de⊙ X)}}
→ πS n X ≃ᴳ 0ᴳ
πS->level-econv n m X lt =
πS n X
≃ᴳ⟨ πS-emap n (⊙unTrunc-equiv X ⊙⁻¹) ⟩
πS n (⊙Trunc m X)
≃ᴳ⟨ πS-Trunc-fuse->-iso n m X lt ⟩
0ᴳ
≃ᴳ∎
π'S->level-econv : ∀ {i} (n : ℕ) (m : ℕ₋₂) (X : Ptd i)
→ (m <T ⟨ S n ⟩) → {{_ : has-level m (de⊙ X)}}
→ π'S n X ≃ᴳ 0ᴳ
π'S->level-econv n m X lt =
π'S n X
≃ᴳ⟨ π'S-emap n (⊙unTrunc-equiv X ⊙⁻¹) ⟩
π'S n (⊙Trunc m X)
≃ᴳ⟨ π'S-Trunc-fuse->-iso n m X lt ⟩
0ᴳ
≃ᴳ∎
{- πₙ(X × Y) == πₙ(X) × πₙ(Y) -}
module _ {i j} (n : ℕ) (X : Ptd i) (Y : Ptd j) where
πS-× : πS n (X ⊙× Y) ≃ᴳ πS n X ×ᴳ πS n Y
πS-× = Trunc-group-× _ _ ∘eᴳ Trunc-group-emap (Ω^S-group-structure-× n X Y)
π'S-× : π'S n (X ⊙× Y) ≃ᴳ π'S n X ×ᴳ π'S n Y
π'S-× = Trunc-group-× _ _ ∘eᴳ Trunc-group-emap (Ω^'S-group-structure-× n X Y)
| {
"alphanum_fraction": 0.5069064748,
"avg_line_length": 35.2791878173,
"ext": "agda",
"hexsha": "ee0cc95550c3795c73ac07a2287efed4fe098b6c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/groups/HomotopyGroup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/groups/HomotopyGroup.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/groups/HomotopyGroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3449,
"size": 6950
} |
module _ where
module A where
infixl 0 _+_
data D : Set where
• : D
_+_ : D → D → D
module B where
infixr 0 _+_
data D : Set where
• : D
_+_ : D → D → D
open A
open B
Foo : A.D
Foo = • + • + •
| {
"alphanum_fraction": 0.480349345,
"avg_line_length": 9.5416666667,
"ext": "agda",
"hexsha": "a3d6e9b24c842a0df79c65490e3d33740de9a400",
"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/Issue1436-20.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/Issue1436-20.agda",
"max_line_length": 20,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Fail/Issue1436-20.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 93,
"size": 229
} |
module Oscar.Class.Substitute where
open import Oscar.Class.Substitution
open import Oscar.Data.Equality
open import Oscar.Function
open import Oscar.Relation
open import Oscar.Level
record Substitute {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) {d} (D : A → Set d) : Set (a ⊔ b ⊔ c ⊔ d) where
field
⦃ substitution ⦄ : Substitution B C
_◃_ : ∀ {m n} → (B m → C n) → m ⟨ D ⟩→ n
◃-identity : ∀ {m} → (x : D m) → ε ◃ x ≡ x
◃-associativity : ∀ {l m n} (f : B l → C m) (g : B m → C n) (t : D l) → (g ◇ f) ◃ t ≡ g ◃ (f ◃ t)
◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_
open Substitute ⦃ … ⦄ public
{-# DISPLAY Substitute._◃_ _ = _◃_ #-}
instance Substitute-id : ∀ {a} {A : Set a} {bcd} {BCD : A → Set bcd} → Substitute BCD BCD BCD
Substitute.substitution Substitute-id = Substitution-id
Substitute._◃_ Substitute-id = id
Substitute.◃-identity Substitute-id _ = refl
Substitute.◃-associativity Substitute-id _ _ _ = refl
Substitute.◃-extensionality Substitute-id f≡̇g = f≡̇g
-- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) {d} (D : A → Set d) : Set (a ⊔ b ⊔ c ⊔ d) where
-- field
-- _◃_ : ∀ {m n} → (B m → C n) → m ⟨ D ⟩→ n
-- ε : ∀ {m} → B m → C m
-- ◃-identity : ∀ {m} → (x : D m) → ε ◃ x ≡ x
-- _◇_ : ∀ {l m n} → (g : B m → C n) (f : B l → C m) → B l → C n
-- ◃-associativity : ∀ {l m n} → {f : B m → C n} {g : B l → C m} (t : D l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
-- ◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_
-- {-
-- Unifies : ∀ {m} (s t : A m) → Property m
-- Unifies s t f = f ◃ s ≡ f ◃ t
-- -}
-- open Substitution ⦃ … ⦄ public
-- -- record Substitution {a} {A : Set a} {b} (S : A → A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- field
-- -- _◃_ : ∀ {m n} → S m n → m ⟨ C ⟩→ n
-- -- ε : ∀ {m} → S m m
-- -- ◃-identity : ∀ {m} → (x : C m) → ε ◃ x ≡ x
-- -- _◇_ : ∀ {l m n} → S m n → S l m → S l n
-- -- field
-- -- ◃-associativity : ∀ {l m n} → {f : S m n} {g : S l m} (t : C l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
-- -- ◃-extensionality : ∀ {m n} {f g : S m n} → f ≡ g → f ◃_ ≡̇ g ◃_
-- -- open Substitution ⦃ … ⦄ public
-- -- -- record Substitution {a} {A : Set a} {b} (B : A → Set b) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- -- -- field
-- -- -- _◃_ : ∀ {m n} → (B m → C n) → m ⟨ C ⟩→ n
-- -- -- ε : ∀ {m} → B m → C m
-- -- -- ◃-identity : ∀ {m} → (x : C m) → ε ◃ x ≡ x
-- -- -- _◇_ : ∀ {l m n} → (f : B m → C n) (g : B l → C m) → B l → C n
-- -- -- _◇_ f g = (f ◃_) ∘ g
-- -- -- field
-- -- -- ◃-associativity : ∀ {l m n} → {f : B m → C n} {g : B l → C m} (t : C l) → (f ◇ g) ◃ t ≡ f ◃ (g ◃ t)
-- -- -- ◃-extensionality : ∀ {m n} {f g : B m → C n} → f ≡̇ g → f ◃_ ≡̇ g ◃_
-- -- -- {-
-- -- -- Unifies : ∀ {m} (s t : A m) → Property m
-- -- -- Unifies s t f = f ◃ s ≡ f ◃ t
-- -- -- -}
-- -- -- open Substitution ⦃ … ⦄ public
-- -- -- instance Substitution⋆ : ∀ {a} {A : Set a} {bc} {BC : A → Set bc} → Substitution BC BC
-- -- -- Substitution._◃_ Substitution⋆ = id
-- -- -- Substitution.ε Substitution⋆ = id
-- -- -- Substitution.◃-identity Substitution⋆ _ = refl
-- -- -- Substitution.◃-associativity Substitution⋆ _ = refl
-- -- -- Substitution.◃-extensionality Substitution⋆ f≡̇g x = f≡̇g x
| {
"alphanum_fraction": 0.4529888856,
"avg_line_length": 39.630952381,
"ext": "agda",
"hexsha": "1da84d002549e905f63b2d5bfeab67f3f266187f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-2/Oscar/Class/Substitute.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-2/Oscar/Class/Substitute.agda",
"max_line_length": 126,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-2/Oscar/Class/Substitute.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1524,
"size": 3329
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where all elements satisfy a given property
------------------------------------------------------------------------
module Data.List.All where
open import Data.List as List hiding (map; all)
open import Data.List.Any as Any using (here; there)
open Any.Membership-≡ using (_∈_; _⊆_)
open import Function
open import Level
open import Relation.Nullary
import Relation.Nullary.Decidable as Dec
open import Relation.Unary using (Decidable) renaming (_⊆_ to _⋐_)
open import Relation.Binary.PropositionalEquality
-- All P xs means that all elements in xs satisfy P.
infixr 5 _∷_
data All {a p} {A : Set a}
(P : A → Set p) : List A → Set (p ⊔ a) where
[] : All P []
_∷_ : ∀ {x xs} (px : P x) (pxs : All P xs) → All P (x ∷ xs)
head : ∀ {a p} {A : Set a} {P : A → Set p} {x xs} →
All P (x ∷ xs) → P x
head (px ∷ pxs) = px
tail : ∀ {a p} {A : Set a} {P : A → Set p} {x xs} →
All P (x ∷ xs) → All P xs
tail (px ∷ pxs) = pxs
lookup : ∀ {a p} {A : Set a} {P : A → Set p} {xs : List A} →
All P xs → (∀ {x : A} → x ∈ xs → P x)
lookup [] ()
lookup (px ∷ pxs) (here refl) = px
lookup (px ∷ pxs) (there x∈xs) = lookup pxs x∈xs
tabulate : ∀ {a p} {A : Set a} {P : A → Set p} {xs} →
(∀ {x} → x ∈ xs → P x) → All P xs
tabulate {xs = []} hyp = []
tabulate {xs = x ∷ xs} hyp = hyp (here refl) ∷ tabulate (hyp ∘ there)
map : ∀ {a p q} {A : Set a} {P : A → Set p} {Q : A → Set q} →
P ⋐ Q → All P ⋐ All Q
map g [] = []
map g (px ∷ pxs) = g px ∷ map g pxs
all : ∀ {a p} {A : Set a} {P : A → Set p} →
Decidable P → Decidable (All P)
all p [] = yes []
all p (x ∷ xs) with p x
all p (x ∷ xs) | yes px = Dec.map′ (_∷_ px) tail (all p xs)
all p (x ∷ xs) | no ¬px = no (¬px ∘ head)
| {
"alphanum_fraction": 0.4973175966,
"avg_line_length": 32.1379310345,
"ext": "agda",
"hexsha": "4ac8448d0daba9dfbdaa92a6758934084d184977",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/List/All.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/List/All.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/List/All.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 675,
"size": 1864
} |
{-# OPTIONS --universe-polymorphism #-}
module Literals where
open import Common.Nat
open import Common.Float
open import Common.Char
open import Common.String
open import Common.Unit
open import Common.IO
afloat : Float
afloat = 1.23
astring : String
astring = "abc"
achar : Char
achar = 'd'
anat : Nat
anat = 123
main : IO Unit
main =
printFloat afloat ,,
putStr astring ,,
printChar achar ,,
printNat anat ,,
putStrLn ""
| {
"alphanum_fraction": 0.6892778993,
"avg_line_length": 15.2333333333,
"ext": "agda",
"hexsha": "134368b49efd862e7101a59851a6a693de70c01d",
"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/Compiler/simple/Literals.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/Compiler/simple/Literals.agda",
"max_line_length": 39,
"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/Compiler/simple/Literals.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": 136,
"size": 457
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.