Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Object.Terminal.Limit {o ℓ e} (C : Category o ℓ e) where
open import Categories.Category.Lift
open import Categories.Category.Finite.Fin.Construction.Discrete
open import Categories.Object.Terminal C
open import Categories.Diagram.Limit
open import Categories.Functor.Core
import Categories.Category.Construction.Cones as Co
private
module C = Category C
open C
module _ {o′ ℓ′ e′} {F : Functor (liftC o′ ℓ′ e′ (Discrete 0)) C} where
limit⇒⊥ : Limit F → Terminal
limit⇒⊥ L = record
{ ⊤ = apex
; ! = rep record
{ apex = record
{ ψ = λ ()
; commute = λ { {()} }
}
}
; !-unique = λ f → terminal.!-unique record
{ arr = f
; commute = λ { {()} }
}
}
where open Limit L
module _ o′ ℓ′ e′ where
⊥⇒limit-F : Functor (liftC o′ ℓ′ e′ (Discrete 0)) C
⊥⇒limit-F = record
{ F₀ = λ ()
; F₁ = λ { {()} }
; identity = λ { {()} }
; homomorphism = λ { {()} }
; F-resp-≈ = λ { {()} }
}
⊥⇒limit : Terminal → Limit ⊥⇒limit-F
⊥⇒limit t = record
{ terminal = record
{ ⊤ = record
{ N = ⊤
; apex = record
{ ψ = λ ()
; commute = λ { {()} }
}
}
; ! = λ {K} →
let open Co.Cone ⊥⇒limit-F K
in record
{ arr = !
; commute = λ { {()} }
}
; !-unique = λ f →
let module f = Co.Cone⇒ ⊥⇒limit-F f
in !-unique f.arr
}
}
where open Terminal t
|
{
"alphanum_fraction": 0.4841269841,
"avg_line_length": 23.7391304348,
"ext": "agda",
"hexsha": "2cc0adc915f1439c6e3b544f64dc4a21f64420e9",
"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": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "laMudri/agda-categories",
"max_forks_repo_path": "src/Categories/Object/Terminal/Limit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"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/agda-categories",
"max_issues_repo_path": "src/Categories/Object/Terminal/Limit.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5a49c6ac87cbb7e20511c28f28205163fe69f48f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "laMudri/agda-categories",
"max_stars_repo_path": "src/Categories/Object/Terminal/Limit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 530,
"size": 1638
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Booleans
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Bool where
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as PropEq
using (_≡_; refl)
------------------------------------------------------------------------
-- The boolean type and some operations
open import Data.Bool.Base public
------------------------------------------------------------------------
-- Publicly re-export queries
open import Data.Bool.Properties public
using (_≟_)
------------------------------------------------------------------------
-- Some properties
decSetoid : DecSetoid _ _
decSetoid = PropEq.decSetoid _≟_
|
{
"alphanum_fraction": 0.4287396938,
"avg_line_length": 26.53125,
"ext": "agda",
"hexsha": "4a4a7b7af19dbe28e19be9416da15caa1ed26920",
"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/Bool.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/Bool.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/Bool.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 128,
"size": 849
}
|
-- 2010-09-29
module IllegalUseOfIrrelevantDeclaration where
import Common.Irrelevance
record Subset (A : Set) (P : A -> Set) : Set where
constructor _#_
field
elem : A
.certificate : P elem
postulate
.irrelevant : {A : Set} -> .A -> A
certificate : {A : Set}{P : A -> Set} -> (x : Subset A P) -> P (Subset.elem x)
certificate (a # p) = irrelevant p
-- since certificate is not declared irrelevant, cannot use irrelevant postulate here
|
{
"alphanum_fraction": 0.6551724138,
"avg_line_length": 25.7777777778,
"ext": "agda",
"hexsha": "44badc7de8623b88342695b7e52d1a2958aae4b9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/IllegalUseOfIrrelevantDeclaration.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/IllegalUseOfIrrelevantDeclaration.agda",
"max_line_length": 85,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/IllegalUseOfIrrelevantDeclaration.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": 135,
"size": 464
}
|
{-# OPTIONS --without-K #-}
open import lib.Base
open import lib.PathGroupoid
open import lib.cubical.Square
module lib.cubical.Cube where
{- Coordinates are yzx, where
x : left -> right
y : back -> front
z : top -> bottom
-}
data Cube {i} {A : Type i} {a₀₀₀ : A} :
{a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
(sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀) -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
(sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁) -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
(sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁) -- back
(sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁) -- top
(sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁) -- bottom
(sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁) -- front
→ Type i
where
idc : Cube ids ids ids ids ids ids
{- Just transport, but less clutter to use -}
module _ {i} {A : Type i} {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
where
cube-shift-left : {sq₋₋₀' : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀}
→ sq₋₋₀ == sq₋₋₀'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀' sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
cube-shift-left idp cu = cu
cube-shift-right : {sq₋₋₁' : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁}
→ sq₋₋₁ == sq₋₋₁'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀ sq₋₋₁' sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
cube-shift-right idp cu = cu
cube-shift-back : {sq₀₋₋' : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁}
→ sq₀₋₋ == sq₀₋₋'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋' sq₋₀₋ sq₋₁₋ sq₁₋₋
cube-shift-back idp cu = cu
cube-shift-top : {sq₋₀₋' : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁}
→ sq₋₀₋ == sq₋₀₋'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋' sq₋₁₋ sq₁₋₋
cube-shift-top idp cu = cu
cube-shift-bot : {sq₋₁₋' : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁}
→ sq₋₁₋ == sq₋₁₋'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋' sq₁₋₋
cube-shift-bot idp cu = cu
cube-shift-front : {sq₁₋₋' : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁}
→ sq₁₋₋ == sq₁₋₋'
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋'
cube-shift-front idp cu = cu
{- A cube where two opposite squares are both [ids] is a square -}
module _ {i} {A : Type i} where
x-id-cube-in : {a₀ a₁ : A} {p₀₀ p₀₁ p₁₀ p₁₁ : a₀ == a₁}
{α₀₋ : p₀₀ == p₁₀} {α₁₋ : p₀₁ == p₁₁}
{α₋₀ : p₀₀ == p₀₁} {α₋₁ : p₁₀ == p₁₁}
→ Square α₀₋ α₋₀ α₋₁ α₁₋
→ Cube ids ids (vert-degen-square α₀₋) (vert-degen-square α₋₀)
(vert-degen-square α₋₁) (vert-degen-square α₁₋)
x-id-cube-in {p₀₀ = idp} ids = idc
y-id-cube-in : {a₀ a₁ : A} {p₀₀ p₀₁ p₁₀ p₁₁ : a₀ == a₁}
{α₀₋ : p₀₀ == p₁₀} {α₁₋ : p₀₁ == p₁₁}
{α₋₀ : p₀₀ == p₀₁} {α₋₁ : p₁₀ == p₁₁}
→ Square α₀₋ α₋₀ α₋₁ α₁₋
→ Cube (vert-degen-square α₀₋) (vert-degen-square α₁₋)
ids (horiz-degen-square α₋₀) (horiz-degen-square α₋₁) ids
y-id-cube-in {p₀₀ = idp} ids = idc
z-id-cube-in : {a₀ a₁ : A} {p₀₀ p₁₀ p₀₁ p₁₁ : a₀ == a₁}
{α₀₋ : p₀₀ == p₁₀} {α₁₋ : p₀₁ == p₁₁}
{α₋₀ : p₀₀ == p₀₁} {α₋₁ : p₁₀ == p₁₁}
→ Square α₀₋ α₋₀ α₋₁ α₁₋
→ Cube (horiz-degen-square α₀₋) (horiz-degen-square α₁₋)
(horiz-degen-square α₋₀) ids ids (horiz-degen-square α₋₁)
z-id-cube-in {p₀₀ = idp} ids = idc
{- Cube fillers -}
module _ {i} {A : Type i} where
fill-cube-left : {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
-- missing left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
(sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁) -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
(sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁) -- back
(sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁) -- top
(sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁) -- bottom
(sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁) -- front
→ Σ (Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀)
(λ sq₋₋₀ → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋)
fill-cube-left {p₋₀₀ = p₋₀₀} {p₋₁₀ = p₋₁₀} sq₋₋₁ ids sq₋₀₋ sq₋₁₋ ids =
(_ ,
cube-shift-right (vert-degen-square-β sq₋₋₁)
(cube-shift-top (horiz-degen-square-β sq₋₀₋)
(cube-shift-bot (horiz-degen-square-β sq₋₁₋)
cu)))
where
fill-sq : Σ (p₋₀₀ == p₋₁₀) (λ α₋₋₀ →
Square α₋₋₀ (horiz-degen-path sq₋₀₋)
(horiz-degen-path sq₋₁₋) (vert-degen-path sq₋₋₁))
fill-sq = fill-square-left _ _ _
cu : Cube (vert-degen-square (fst fill-sq))
(vert-degen-square (vert-degen-path sq₋₋₁)) ids
(horiz-degen-square (horiz-degen-path sq₋₀₋))
(horiz-degen-square (horiz-degen-path sq₋₁₋)) ids
cu = y-id-cube-in (snd fill-sq)
fill-cube-right : {a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
(sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀) -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
-- missing right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
(sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁) -- back
(sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁) -- top
(sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁) -- bottom
(sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁) -- front
→ Σ (Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁)
(λ sq₋₋₁ → Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋)
fill-cube-right sq₋₋₀ {p₋₀₁ = p₋₀₁} {p₋₁₁ = p₋₁₁} ids sq₋₀₋ sq₋₁₋ ids =
(_ ,
cube-shift-left (vert-degen-square-β sq₋₋₀)
(cube-shift-top (horiz-degen-square-β sq₋₀₋)
(cube-shift-bot (horiz-degen-square-β sq₋₁₋)
cu)))
where
fill-sq : Σ (p₋₀₁ == p₋₁₁) (λ α₋₋₁ →
Square (vert-degen-path sq₋₋₀) (horiz-degen-path sq₋₀₋)
(horiz-degen-path sq₋₁₋) α₋₋₁)
fill-sq = fill-square-right _ _ _
cu : Cube (vert-degen-square (vert-degen-path sq₋₋₀))
(vert-degen-square (fst fill-sq)) ids
(horiz-degen-square (horiz-degen-path sq₋₀₋))
(horiz-degen-square (horiz-degen-path sq₋₁₋)) ids
cu = y-id-cube-in (snd fill-sq)
fill-cube-left-unique : ∀ {i} {A : Type i} {a₀₀₀ : A}
{a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ sq₋₋₀ == fst (fill-cube-left sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋)
fill-cube-left-unique idc = idp
fill-cube-right-unique : ∀ {i} {A : Type i} {a₀₀₀ : A}
{a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ sq₋₋₁ == fst (fill-cube-right sq₋₋₀ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋)
fill-cube-right-unique idc = idp
{- Paths as degenerate cubes -}
module _ {i} {A : Type i} where
x-degen-cube : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq₋₋₀ sq₋₋₁ : Square p₀₋ p₋₀ p₋₁ p₁₋}
→ sq₋₋₀ == sq₋₋₁
→ Cube sq₋₋₀ sq₋₋₁ hid-square hid-square hid-square hid-square
x-degen-cube {sq₋₋₀ = ids} idp = idc
y-degen-cube : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq₀₋₋ sq₁₋₋ : Square p₀₋ p₋₀ p₋₁ p₁₋}
→ sq₀₋₋ == sq₁₋₋
→ Cube hid-square hid-square sq₀₋₋ vid-square vid-square sq₁₋₋
y-degen-cube {sq₀₋₋ = ids} idp = idc
z-degen-cube : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq₋₀₋ sq₋₁₋ : Square p₀₋ p₋₀ p₋₁ p₁₋}
→ sq₋₀₋ == sq₋₁₋
→ Cube vid-square vid-square vid-square sq₋₀₋ sq₋₁₋ vid-square
z-degen-cube {sq₋₀₋ = ids} idp = idc
x-degen-cube-out : {a₀₀ a₀₁ a₁₀ a₁₁ : A}
{p₀₋ : a₀₀ == a₀₁} {p₋₀ : a₀₀ == a₁₀}
{p₋₁ : a₀₁ == a₁₁} {p₁₋ : a₁₀ == a₁₁}
{sq₋₋₀ sq₋₋₁ : Square p₀₋ p₋₀ p₋₁ p₁₋}
→ Cube sq₋₋₀ sq₋₋₁ hid-square hid-square hid-square hid-square
→ sq₋₋₀ == sq₋₋₁
x-degen-cube-out cu =
fill-cube-left-unique cu ∙ ! (fill-cube-left-unique (x-degen-cube idp))
{- A pathover between squares can be represented as a cube -}
module _ {i j} {A : Type i} {B : Type j} {b₀₀ b₀₁ b₁₀ b₁₁ : A → B}
{p₀₋ : (a : A) → b₀₀ a == b₀₁ a} {p₋₀ : (a : A) → b₀₀ a == b₁₀ a}
{p₋₁ : (a : A) → b₀₁ a == b₁₁ a} {p₁₋ : (a : A) → b₁₀ a == b₁₁ a}
where
↓-square-to-cube : {x y : A} {q : x == y}
{u : Square (p₀₋ x) (p₋₀ x) (p₋₁ x) (p₁₋ x)}
{v : Square (p₀₋ y) (p₋₀ y) (p₋₁ y) (p₁₋ y)}
→ u == v [ (λ z → Square (p₀₋ z) (p₋₀ z) (p₋₁ z) (p₁₋ z)) ↓ q ]
→ Cube u v (natural-square p₀₋ q ) (natural-square p₋₀ q)
(natural-square p₋₁ q) (natural-square p₁₋ q)
↓-square-to-cube {q = idp} r = x-degen-cube r
cube-to-↓-square : {x y : A} {q : x == y}
{sqx : Square (p₀₋ x) (p₋₀ x) (p₋₁ x) (p₁₋ x)}
{sqy : Square (p₀₋ y) (p₋₀ y) (p₋₁ y) (p₁₋ y)}
→ Cube sqx sqy (natural-square p₀₋ q) (natural-square p₋₀ q)
(natural-square p₋₁ q) (natural-square p₁₋ q)
→ sqx == sqy [ (λ z → Square (p₀₋ z) (p₋₀ z) (p₋₁ z) (p₁₋ z)) ↓ q ]
cube-to-↓-square {q = idp} cu = x-degen-cube-out cu
module _ {i j} {A : Type i} {B : Type j} {b₀₀ b₀₁ b₁₀ b₁₁ : B}
{p₀₋ : (a : A) → b₀₀ == b₀₁} {p₋₀ : (a : A) → b₀₀ == b₁₀}
{p₋₁ : (a : A) → b₀₁ == b₁₁} {p₁₋ : (a : A) → b₁₀ == b₁₁}
where
cube-to-disc-square : {x y : A} {q : x == y}
{sqx : Square (p₀₋ x) (p₋₀ x) (p₋₁ x) (p₁₋ x)}
{sqy : Square (p₀₋ y) (p₋₀ y) (p₋₁ y) (p₁₋ y)}
→ Cube sqx sqy (natural-square p₀₋ q) (natural-square p₋₀ q)
(natural-square p₋₁ q) (natural-square p₁₋ q)
→ Square (square-to-disc sqx) (ap (λ z → p₀₋ z ∙ p₋₁ z) q)
(ap (λ z → p₋₀ z ∙ p₁₋ z) q) (square-to-disc sqy)
cube-to-disc-square cu =
↓-='-to-square (ap↓ square-to-disc (cube-to-↓-square cu))
ap-cube : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube (ap-square f sq₋₋₀) (ap-square f sq₋₋₁) (ap-square f sq₀₋₋)
(ap-square f sq₋₀₋) (ap-square f sq₋₁₋) (ap-square f sq₁₋₋)
ap-cube f idc = idc
natural-cube : ∀ {i j} {A : Type i} {B : Type j}
{f₀₀ f₀₁ f₁₀ f₁₁ : A → B}
{p₀₋ : (a : A) → f₀₀ a == f₀₁ a} {p₋₀ : (a : A) → f₀₀ a == f₁₀ a}
{p₋₁ : (a : A) → f₀₁ a == f₁₁ a} {p₁₋ : (a : A) → f₁₀ a == f₁₁ a}
(sq : ∀ a → Square (p₀₋ a) (p₋₀ a) (p₋₁ a) (p₁₋ a))
{x y : A} (q : x == y)
→ Cube (sq x) (sq y)
(natural-square p₀₋ q) (natural-square p₋₀ q)
(natural-square p₋₁ q) (natural-square p₁₋ q)
natural-cube sq idp = x-degen-cube idp
cube-rotate-x→z : ∀ {i} {A : Type i}
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube (square-symmetry sq₀₋₋) (square-symmetry sq₁₋₋)
(square-symmetry sq₋₀₋) sq₋₋₀ sq₋₋₁ (square-symmetry sq₋₁₋)
cube-rotate-x→z idc = idc
cube-symmetry-x : ∀ {i} {A : Type i}
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube (square-symmetry sq₋₋₀) (square-symmetry sq₋₋₁)
sq₋₀₋ sq₀₋₋ sq₁₋₋ sq₋₁₋
cube-symmetry-x idc = idc
cube-!-x : ∀ {i} {A : Type i}
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- right
{p₀₀₋ : a₀₀₀ == a₀₀₁} {p₀₁₋ : a₀₁₀ == a₀₁₁}
{p₁₀₋ : a₁₀₀ == a₁₀₁} {p₁₁₋ : a₁₁₀ == a₁₁₁}
{sq₀₋₋ : Square p₀₋₀ p₀₀₋ p₀₁₋ p₀₋₁} -- back
{sq₋₀₋ : Square p₋₀₀ p₀₀₋ p₁₀₋ p₋₀₁} -- top
{sq₋₁₋ : Square p₋₁₀ p₀₁₋ p₁₁₋ p₋₁₁} -- bottom
{sq₁₋₋ : Square p₁₋₀ p₁₀₋ p₁₁₋ p₁₋₁} -- front
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋₋ sq₋₀₋ sq₋₁₋ sq₁₋₋
→ Cube sq₋₋₁ sq₋₋₀ (!□h sq₀₋₋) (!□h sq₋₀₋) (!□h sq₋₁₋) (!□h sq₁₋₋)
cube-!-x idc = idc
_∙³x_ : ∀ {i} {A : Type i}
{a₀₀₀ a₀₁₀ a₁₀₀ a₁₁₀ a₀₀₁ a₀₁₁ a₁₀₁ a₁₁₁ a₀₀₂ a₀₁₂ a₁₀₂ a₁₁₂ : A}
{p₀₋₀ : a₀₀₀ == a₀₁₀} {p₋₀₀ : a₀₀₀ == a₁₀₀}
{p₋₁₀ : a₀₁₀ == a₁₁₀} {p₁₋₀ : a₁₀₀ == a₁₁₀}
{sq₋₋₀ : Square p₀₋₀ p₋₀₀ p₋₁₀ p₁₋₀} -- left
{p₀₋₁ : a₀₀₁ == a₀₁₁} {p₋₀₁ : a₀₀₁ == a₁₀₁}
{p₋₁₁ : a₀₁₁ == a₁₁₁} {p₁₋₁ : a₁₀₁ == a₁₁₁}
{sq₋₋₁ : Square p₀₋₁ p₋₀₁ p₋₁₁ p₁₋₁} -- middle
{p₀₋₂ : a₀₀₂ == a₀₁₂} {p₋₀₂ : a₀₀₂ == a₁₀₂}
{p₋₁₂ : a₀₁₂ == a₁₁₂} {p₁₋₂ : a₁₀₂ == a₁₁₂}
{sq₋₋₂ : Square p₀₋₂ p₋₀₂ p₋₁₂ p₁₋₂} -- right
{p₀₀l : a₀₀₀ == a₀₀₁} {p₀₁l : a₀₁₀ == a₀₁₁}
{p₁₀l : a₁₀₀ == a₁₀₁} {p₁₁l : a₁₁₀ == a₁₁₁}
{sq₀₋l : Square p₀₋₀ p₀₀l p₀₁l p₀₋₁} -- backl
{sq₋₀l : Square p₋₀₀ p₀₀l p₁₀l p₋₀₁} -- topl
{sq₋₁l : Square p₋₁₀ p₀₁l p₁₁l p₋₁₁} -- bottoml
{sq₁₋l : Square p₁₋₀ p₁₀l p₁₁l p₁₋₁} -- frontl
{p₀₀r : a₀₀₁ == a₀₀₂} {p₀₁r : a₀₁₁ == a₀₁₂}
{p₁₀r : a₁₀₁ == a₁₀₂} {p₁₁r : a₁₁₁ == a₁₁₂}
{sq₀₋r : Square p₀₋₁ p₀₀r p₀₁r p₀₋₂} -- backr
{sq₋₀r : Square p₋₀₁ p₀₀r p₁₀r p₋₀₂} -- topr
{sq₋₁r : Square p₋₁₁ p₀₁r p₁₁r p₋₁₂} -- bottomr
{sq₁₋r : Square p₁₋₁ p₁₀r p₁₁r p₁₋₂} -- frontr
→ Cube sq₋₋₀ sq₋₋₁ sq₀₋l sq₋₀l sq₋₁l sq₁₋l
→ Cube sq₋₋₁ sq₋₋₂ sq₀₋r sq₋₀r sq₋₁r sq₁₋r
→ Cube sq₋₋₀ sq₋₋₂ (sq₀₋l ⊡h sq₀₋r) (sq₋₀l ⊡h sq₋₀r)
(sq₋₁l ⊡h sq₋₁r) (sq₁₋l ⊡h sq₁₋r)
idc ∙³x cu = cu
infixr 8 _∙³x_
|
{
"alphanum_fraction": 0.5220473387,
"avg_line_length": 38.4434180139,
"ext": "agda",
"hexsha": "d8c5053a8af246c82bd4baaa5babcc406cc76878",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/cubical/Cube.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/cubical/Cube.agda",
"max_line_length": 75,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/cubical/Cube.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-30T00:17:55.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-06-30T00:17:55.000Z",
"num_tokens": 10347,
"size": 16646
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
open import Categories.Monad
module Categories.Adjoint.Construction.EilenbergMoore {o ℓ e} {C : Category o ℓ e} (M : Monad C) where
open import Categories.Category.Construction.EilenbergMoore M
open import Categories.Adjoint
open import Categories.Functor
open import Categories.Functor.Properties
open import Categories.NaturalTransformation
open import Categories.NaturalTransformation.NaturalIsomorphism using (_≃_)
open import Categories.Morphism.Reasoning C
private
module C = Category C
module M = Monad M
open M.F
open C
open HomReasoning
Forgetful : Functor EilenbergMoore C
Forgetful = record
{ F₀ = λ X → Module.A X
; F₁ = λ f → Module⇒.arr f
; identity = refl
; homomorphism = refl
; F-resp-≈ = λ eq → eq
}
Free : Functor C EilenbergMoore
Free = record
{ F₀ = λ A → record
{ A = F₀ A
; action = M.μ.η A
; commute = M.assoc
; identity = M.identityʳ
}
; F₁ = λ f → record
{ arr = F₁ f
; commute = ⟺ (M.μ.commute f)
}
; identity = identity
; homomorphism = homomorphism
; F-resp-≈ = F-resp-≈
}
FF≃F : Forgetful ∘F Free ≃ M.F
FF≃F = record
{ F⇒G = record
{ η = λ X → F₁ C.id
; commute = λ f → [ M.F ]-resp-square id-comm-sym
; sym-commute = λ f → [ M.F ]-resp-square id-comm
}
; F⇐G = record
{ η = λ X → F₁ C.id
; commute = λ f → [ M.F ]-resp-square id-comm-sym
; sym-commute = λ f → [ M.F ]-resp-square id-comm
}
; iso = λ X → record
{ isoˡ = elimˡ identity ○ identity
; isoʳ = elimˡ identity ○ identity
}
}
Free⊣Forgetful : Free ⊣ Forgetful
Free⊣Forgetful = record
{ unit = record
{ η = M.η.η
; commute = M.η.commute
; sym-commute = M.η.sym-commute
}
; counit = record
{ η = λ X →
let module X = Module X
in record
{ arr = X.action
; commute = ⟺ X.commute
}
; commute = λ f → ⟺ (Module⇒.commute f)
; sym-commute = Module⇒.commute
}
; zig = M.identityˡ
; zag = λ {B} → Module.identity B
}
|
{
"alphanum_fraction": 0.5768880801,
"avg_line_length": 25.2643678161,
"ext": "agda",
"hexsha": "0307fab2ff4eaad35892fa4f445cda3b4bbd82b3",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Construction/EilenbergMoore.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Construction/EilenbergMoore.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Construction/EilenbergMoore.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 737,
"size": 2198
}
|
open import Data.Product using ( _×_ ; _,_ )
open import Relation.Binary.PropositionalEquality using ( refl )
open import Relation.Unary using ( _∈_ )
open import Web.Semantic.DL.ABox using ( ABox ; ⟨ABox⟩ )
open import Web.Semantic.DL.ABox.Interp using ( Interp ; Surjective ; _,_ ; ⌊_⌋ ; ind ; _*_ ; emp )
open import Web.Semantic.DL.ABox.Interp.Morphism using ( _≲_ ; _,_ ; ≲⌊_⌋ ; ≲-resp-ind ; _≋_ ; _**_ )
open import Web.Semantic.DL.ABox.Model using ( _⊨a_ ; ⟨ABox⟩-resp-⊨ ; *-resp-⟨ABox⟩ ; ⊨a-resp-≡ )
open import Web.Semantic.DL.Integrity using ( _⊕_⊨_ ; Initial ; Mediator ; Mediated ; _,_ )
open import Web.Semantic.DL.KB using ( KB ; _,_ )
open import Web.Semantic.DL.KB.Model using ( _⊨_ )
open import Web.Semantic.DL.Signature using ( Signature )
open import Web.Semantic.DL.TBox.Interp using ( _⊨_≈_ ; ≈-refl )
open import Web.Semantic.DL.TBox.Interp.Morphism using ( morph ; ≲-image )
open import Web.Semantic.Util using ( False ; _∘_ ; _⊕_⊕_ ; bnode ; inode ; enode )
module Web.Semantic.DL.Integrity.Closed {Σ : Signature} {X : Set} where
infix 2 _⊨₀_ sur_⊨₀_
infixr 4 _,_
-- A closed-world variant on integrity constraints.
data Mediated₀ (I J : Interp Σ X) : Set where
_,_ : (I≲J : I ≲ J) → (∀ (I≲₁J I≲₂J : I ≲ J) → (I≲₁J ≋ I≲₂J)) → Mediated₀ I J
data Initial₀ KB (I : Interp Σ X) : Set₁ where
_,_ : (I ⊨ KB) → (∀ J → (J ⊨ KB) → Mediated₀ I J) → (I ∈ Initial₀ KB)
data _⊨₀_ (KB₁ KB₂ : KB Σ X) : Set₁ where
_,_ : ∀ I → ((I ∈ Initial₀ KB₁) × (I ⊨ KB₂)) → (KB₁ ⊨₀ KB₂)
-- Surjective variant
data sur_⊨₀_ (KB₁ KB₂ : KB Σ X) : Set₁ where
_,_ : ∀ I → ((I ∈ Surjective) × (I ∈ Initial₀ KB₁) × (I ⊨ KB₂)) → (sur KB₁ ⊨₀ KB₂)
-- Closed-world ICs are given by specializing the open-world case
-- to the empty imported interpretion.
exp : KB Σ X → KB Σ (False ⊕ False ⊕ X)
exp (T , A) = (T , ⟨ABox⟩ enode A)
enode⁻¹ : (False ⊕ False ⊕ X) → X
enode⁻¹ (inode ())
enode⁻¹ (bnode ())
enode⁻¹ (enode x) = x
emp-≲ : ∀ (I : Interp Σ False) → (emp ≲ I)
emp-≲ I = (morph (λ ()) (λ {}) (λ ()) (λ {r} → λ {}) , λ ())
⊨₀-impl-⊨ : ∀ KB₁ KB₂ → (KB₁ ⊨₀ KB₂) → (emp ⊕ exp KB₁ ⊨ KB₂)
⊨₀-impl-⊨ (T , A) (U , B) (I , ((I⊨T , I⊨A) , I-med) , I⊨U , I⊨B) =
(I′ , I′-init , I⊨U , ⊨a-resp-≡ I (ind I) refl B I⊨B) where
A′ : ABox Σ (False ⊕ False ⊕ X)
A′ = ⟨ABox⟩ enode A
I′ : Interp Σ (False ⊕ False ⊕ X)
I′ = enode⁻¹ * I
emp≲I′ : emp ≲ inode * I′
emp≲I′ = emp-≲ (inode * I′)
I′-med : Mediator emp I′ emp≲I′ (T , A′)
I′-med J′ emp≲J′ (J′⊨T , J′⊨A′) = lemma (I-med J (J′⊨T , J⊨A)) where
J : Interp Σ X
J = enode * J′
J⊨A : J ⊨a A
J⊨A = *-resp-⟨ABox⟩ enode J′ A J′⊨A′
lemma : Mediated₀ I J → Mediated emp I′ J′ emp≲I′ emp≲J′
lemma ((I≲J , i≲j) , I≲J-uniq) = ((I≲J , i′≲j′) , (λ ()) , I′≲J′-uniq) where
i′≲j′ : ∀ x → ⌊ J′ ⌋ ⊨ ≲-image I≲J (ind I (enode⁻¹ x)) ≈ ind J′ x
i′≲j′ (inode ())
i′≲j′ (bnode ())
i′≲j′ (enode x) = i≲j x
I′≲J′-uniq : ∀ (I≲₁J I≲₂J : I′ ≲ J′)_ _ → I≲₁J ≋ I≲₂J
I′≲J′-uniq I≲₁J I≲₂J _ _ = I≲J-uniq
(≲⌊ I≲₁J ⌋ , λ x → ≲-resp-ind I≲₁J (enode x))
(≲⌊ I≲₂J ⌋ , λ x → ≲-resp-ind I≲₂J (enode x))
I′⊨A′ : I′ ⊨a A′
I′⊨A′ = ⟨ABox⟩-resp-⊨ enode (λ x → ≈-refl ⌊ I ⌋) A I⊨A
I′-init : I′ ∈ Initial emp (T , A′)
I′-init = ( emp-≲ (inode * I′) , (I⊨T , I′⊨A′) , I′-med )
⊨-impl-⊨₀ : ∀ KB₁ KB₂ → (emp ⊕ exp KB₁ ⊨ KB₂) → (KB₁ ⊨₀ KB₂)
⊨-impl-⊨₀ (T , A) (U , B)
(I′ , (emp≲I′ , (I′⊨T , I′⊨A) , I′-med) , I′⊨U , I′⊨B) =
(I , ((I′⊨T , I⊨A) , I-med) , I′⊨U , I′⊨B) where
I : Interp Σ X
I = enode * I′
I⊨A : I ⊨a A
I⊨A = *-resp-⟨ABox⟩ enode I′ A I′⊨A
I-med : ∀ J → (J ⊨ T , A) → Mediated₀ I J
I-med J (J⊨T , J⊨A) = lemma (I′-med J′ emp≲J′ (J⊨T , J′⊨A)) where
J′ : Interp Σ (False ⊕ False ⊕ X)
J′ = enode⁻¹ * J
emp≲J′ : emp ≲ inode * J′
emp≲J′ = emp-≲ (inode * J′)
J′⊨A : J′ ⊨a ⟨ABox⟩ enode A
J′⊨A = ⟨ABox⟩-resp-⊨ enode (λ x → ≈-refl ⌊ J ⌋) A J⊨A
I≲J-impl-I′≲J′ : (I ≲ J) → (I′ ≲ J′)
I≲J-impl-I′≲J′ I≲J = (≲⌊ I≲J ⌋ , i≲j) where
i≲j : ∀ x → ⌊ J ⌋ ⊨ ≲-image ≲⌊ I≲J ⌋ (ind I′ x) ≈ ind J (enode⁻¹ x)
i≲j (inode ())
i≲j (bnode ())
i≲j (enode x) = ≲-resp-ind I≲J x
lemma : Mediated emp I′ J′ emp≲I′ emp≲J′ → Mediated₀ I J
lemma (I≲J , _ , I≲J-uniq) =
( (≲⌊ I≲J ⌋ , λ x → ≲-resp-ind I≲J (enode x))
, λ I≲₁J I≲₂J x → I≲J-uniq
(I≲J-impl-I′≲J′ I≲₁J) (I≲J-impl-I′≲J′ I≲₂J) (λ ()) (λ ()) x)
|
{
"alphanum_fraction": 0.5111010421,
"avg_line_length": 34.484375,
"ext": "agda",
"hexsha": "fa1557478963df1a323022aef3163185f2165235",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:03.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-12-03T14:52:09.000Z",
"max_forks_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-web-semantic",
"max_forks_repo_path": "src/Web/Semantic/DL/Integrity/Closed.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "38fbc3af7062ba5c3d7d289b2b4bcfb995d99057",
"max_issues_repo_issues_event_max_datetime": "2021-01-04T20:57:19.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T02:32:28.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-web-semantic",
"max_issues_repo_path": "src/Web/Semantic/DL/Integrity/Closed.agda",
"max_line_length": 101,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "8ddbe83965a616bff6fc7a237191fa261fa78bab",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/agda-web-semantic",
"max_stars_repo_path": "src/Web/Semantic/DL/Integrity/Closed.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-14T14:21:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-13T17:46:41.000Z",
"num_tokens": 2325,
"size": 4414
}
|
-- The natural numbers.
{-# OPTIONS --without-K --safe #-}
module Tools.Nat where
open import Tools.PropositionalEquality
open import Tools.Nullary
-- We reexport Agda's built-in type of natural numbers.
open import Agda.Builtin.Nat using (zero; suc)
open import Agda.Builtin.Nat using (Nat) public
pattern 1+ n = suc n
infix 4 _≟_
-- Predecessor, cutting off at 0.
pred : Nat → Nat
pred zero = zero
pred (suc n) = n
-- Decision of number equality.
_≟_ : (m n : Nat) → Dec (m ≡ n)
zero ≟ zero = yes refl
suc m ≟ suc n with m ≟ n
suc m ≟ suc .m | yes refl = yes refl
suc m ≟ suc n | no prf = no (λ x → prf (subst (λ y → m ≡ pred y) x refl))
zero ≟ suc n = no λ()
suc m ≟ zero = no λ()
|
{
"alphanum_fraction": 0.6402266289,
"avg_line_length": 20.7647058824,
"ext": "agda",
"hexsha": "bfcb59889addfbf9176175882d0da967b9076c13",
"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": "Tools/Nat.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": "Tools/Nat.agda",
"max_line_length": 76,
"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": "Tools/Nat.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 245,
"size": 706
}
|
------------------------------------------------------------------------
-- A counterexample: The number of steps taken by the uninstrumented
-- interpreter is not, in general, linear in the number of steps taken
-- by the virtual machine for the corresponding compiled program
------------------------------------------------------------------------
open import Prelude
import Lambda.Syntax
module Lambda.Interpreter.Steps.Counterexample
{Name : Type}
(open Lambda.Syntax Name)
(def : Name → Tm 1)
where
import Equality.Propositional as E
open import Prelude.Size
open import Conat E.equality-with-J as Conat
hiding ([_]_∼_; step-∼) renaming (_+_ to _⊕_; _*_ to _⊛_)
open import Monad E.equality-with-J hiding (_⊛_)
import Nat E.equality-with-J as Nat
open import Vec.Data E.equality-with-J
open import Delay-monad
open import Delay-monad.Bisimilarity
open import Lambda.Delay-crash
open import Lambda.Interpreter def
open import Lambda.Compiler def
open import Lambda.Virtual-machine comp-name
open import Lambda.Virtual-machine.Instructions Name hiding (crash)
open Closure Tm
-- The uninstrumented interpreter does not provide a suitable cost
-- measure, in the sense that there is a family of programs for which
-- the running "time" (number of steps) of the corresponding compiled
-- programs on the virtual machine is not linear in the running time
-- on the interpreter.
not-suitable-cost-measure :
∃ λ (t : ℕ → Tm 0) →
¬ ∃ λ k₁ → ∃ λ k₂ → ∀ n →
[ ∞ ] steps (exec ⟨ comp₀ (t n) , [] , [] ⟩) ≤
⌜ k₁ ⌝ ⊕ ⌜ k₂ ⌝ ⊛ steps (⟦ t n ⟧ [])
not-suitable-cost-measure =
t , λ { (k₁ , k₂ , hyp) → Nat.+≮ 2 $ ⌜⌝-mono⁻¹ (
⌜ 3 + k₁ ⌝ ∼⟨ symmetric-∼ (steps-exec-t∼ k₁) ⟩≤
steps (exec ⟨ comp₀ (t k₁) , [] , [] ⟩) ≤⟨ hyp k₁ ⟩
⌜ k₁ ⌝ ⊕ ⌜ k₂ ⌝ ⊛ steps (⟦ t k₁ ⟧ []) ∼⟨ (⌜ k₁ ⌝ ∎∼) +-cong (_ ∎∼) *-cong steps⟦t⟧∼0 k₁ ⟩≤
⌜ k₁ ⌝ ⊕ ⌜ k₂ ⌝ ⊛ zero ∼⟨ (_ ∎∼) +-cong *-right-zero ⟩≤
⌜ k₁ ⌝ ⊕ zero ∼⟨ +-right-identity _ ⟩≤
⌜ k₁ ⌝ ∎≤) }
where
-- A family of programs.
t : ℕ → Tm 0
t zero = con true · con true
t (suc n) = con true · t n
-- The semantics of every program in this family is strongly
-- bisimilar to crash.
⟦t⟧∼crash : ∀ {i} n → [ i ] ⟦ t n ⟧ [] ∼ crash
⟦t⟧∼crash zero = crash ∎
⟦t⟧∼crash (suc n) =
⟦ t (suc n) ⟧ [] ∼⟨⟩
⟦ t n ⟧ [] >>= con true ∙_ ∼⟨ ⟦t⟧∼crash n >>=-cong (λ _ → _ ∎) ⟩
crash >>= con true ∙_ ∼⟨⟩
crash ∎
-- Thus these programs all terminate (unsuccessfully) in zero steps.
steps⟦t⟧∼0 : ∀ {i} n → Conat.[ i ] steps (⟦ t n ⟧ []) ∼ zero
steps⟦t⟧∼0 = steps-cong ∘ ⟦t⟧∼crash
-- However, running the compiled program corresponding to t n on the
-- virtual machine takes 3 + n steps.
steps-exec-t∼ :
∀ {i} n →
Conat.[ i ] steps (exec ⟨ comp₀ (t n) , [] , [] ⟩) ∼ ⌜ 3 + n ⌝
steps-exec-t∼ = lemma
where
lemma :
∀ {i c s} n →
Conat.[ i ] steps (exec ⟨ comp false (t n) c , s , [] ⟩) ∼
⌜ 3 + n ⌝
lemma zero = suc λ { .force →
suc λ { .force →
suc λ { .force →
zero }}}
lemma (suc n) = suc λ { .force → lemma n }
|
{
"alphanum_fraction": 0.5282392027,
"avg_line_length": 34.4895833333,
"ext": "agda",
"hexsha": "555c11ff7fd050f34623bbc97ed369d00eddc009",
"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": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/definitional-interpreters",
"max_forks_repo_path": "src/Lambda/Interpreter/Steps/Counterexample.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"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/definitional-interpreters",
"max_issues_repo_path": "src/Lambda/Interpreter/Steps/Counterexample.agda",
"max_line_length": 97,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "dec8cd2d2851340840de25acb0feb78f7b5ffe96",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/definitional-interpreters",
"max_stars_repo_path": "src/Lambda/Interpreter/Steps/Counterexample.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1157,
"size": 3311
}
|
open import Common.Prelude
test : Bool → Nat
test = if_then 4 Common.Prelude.else 5
|
{
"alphanum_fraction": 0.7529411765,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "5033e93236024db121737029deab4ae6eb93ef3b",
"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/Sections-15.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/Sections-15.agda",
"max_line_length": 38,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Sections-15.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": 26,
"size": 85
}
|
------------------------------------------------------------------------------
-- Totality properties of the division
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Program.Division.Totality where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat
open import LTC-PCF.Data.Nat.Inequalities
open import LTC-PCF.Program.Division.ConversionRules
open import LTC-PCF.Program.Division.Division
open import LTC-PCF.Program.Division.Specification
------------------------------------------------------------------------------
-- The division is total when the dividend is less than the divisor.
div-x<y-N : ∀ {i j} → i < j → N (div i j)
div-x<y-N i<j = subst N (sym (div-x<y i<j)) nzero
-- The division is total when the dividend is greater or equal than
-- the divisor.
-- N (div (i ∸ j) j) i ≮ j → div i j ≡ succ (div (i ∸ j) j)
------------------------------------------------------------------
-- N (div i j)
div-x≮y-N : ∀ {i j} →
(divSpec (i ∸ j) j (div (i ∸ j) j)) →
i ≮ j →
N (div i j)
div-x≮y-N ih i≮j = subst N (sym (div-x≮y i≮j)) (nsucc (∧-proj₁ ih))
|
{
"alphanum_fraction": 0.4605654762,
"avg_line_length": 37.3333333333,
"ext": "agda",
"hexsha": "5c2f181587a3925774a50df6addcfc8eed0ffe0e",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Program/Division/Totality.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/LTC-PCF/Program/Division/Totality.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/LTC-PCF/Program/Division/Totality.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": 333,
"size": 1344
}
|
module sn-calculus where
open import utility
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Lang.Properties
open import Esterel.Lang.CanFunction
using (Canθₛ ; Canθₛₕ ; [S]-env)
open import Esterel.Environment as Env
using (Env ; Θ ; _←_ ; sig ; []env ; module SigMap ; module ShrMap ; module VarMap)
open import Esterel.Context
using (EvaluationContext ; EvaluationContext1 ; _⟦_⟧e ; _≐_⟦_⟧e ;
Context ; Context1 ; _⟦_⟧c ; _≐_⟦_⟧c)
open import Esterel.Variable.Signal as Signal
using (Signal)
open import Esterel.Variable.Shared as SharedVar
using (SharedVar)
open import Esterel.Variable.Sequential as SeqVar
using (SeqVar)
open import Esterel.Context.Properties
open import Relation.Nullary
using (¬_)
open import Relation.Binary.PropositionalEquality
using (_≡_ ; refl ; cong ; sym)
open import Data.Empty
using (⊥ ; ⊥-elim)
import Data.FiniteMap
open import Data.List
using (List ; _∷_ ; [])
open import Data.List.All as All
using (All ; _∷_ ; [])
open import Data.Nat
using (ℕ ; zero ; suc ; _+_)
open import Data.Product
using (Σ-syntax ; Σ ; _,_ ; proj₁ ; proj₂ ; _×_ ; _,′_)
open import Data.Sum
using (_⊎_ ; inj₁ ; inj₂)
open _≐_⟦_⟧e
open _≐_⟦_⟧c
open EvaluationContext1
open Context1
infix 4 _sn⟶₁_
infix 4 _sn⟶_
infix 4 _sn⟶*_
-- The environment created by rraise-signal rule
-- [S]-env, is defined in Esterel.Lang.CanFunction
-- It's simply Θ SigMap.[ S ↦ Signal.unknown ] ShrMap.empty VarMap.empty
-- The environment created by rraise-shared rule
[s,δe]-env : (s : SharedVar) → (v : ℕ) → Env
[s,δe]-env s δe' =
Θ SigMap.empty
ShrMap.[ s ↦ (SharedVar.old ,′ δe') ]
VarMap.empty
-- The environment created by rraise-var rule
[x,δe]-env : (x : SeqVar) → (v : ℕ) → Env
[x,δe]-env x δe' =
Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δe' ]
[s,δe-new]-env : (s : SharedVar) → (v : ℕ) → Env
[s,δe-new]-env s δe' =
Θ SigMap.empty
ShrMap.[ s ↦ (SharedVar.new ,′ δe') ]
VarMap.empty
data bound-ready : Env → s/l → Set where
brnum : ∀{θ n} → bound-ready θ (num n)
brseq : ∀{θ x} → (Env.isVar∈ x θ) → bound-ready θ (seq-ref x)
brshr : ∀{θ s} →
(s∈ : (Env.isShr∈ s θ)) →
Env.shr-stats{s} θ s∈ ≡ SharedVar.ready →
bound-ready θ (shr-ref s)
data all-ready : Expr → Env → Set where
aplus : ∀{θ operators} → All (bound-ready θ) operators → all-ready (plus operators) θ
δ : ∀{e θ} → all-ready e θ → ℕ
δ {(plus [])} {θ} (aplus []) = 0
δ {(plus (num n ∷ _))} {θ} (aplus (brnum ∷ ops)) = n + δ (aplus ops)
δ {(plus (seq-ref x ∷ _))} {θ} (aplus (brseq x∈ ∷ ops)) = Env.var-vals{x} θ x∈ + δ (aplus ops)
δ {(plus (shr-ref s ∷ _))} {θ} (aplus (brshr s∈ _ ∷ ops)) = Env.shr-vals{s} θ s∈ + δ (aplus ops)
δ-e-irr : ∀{e θ} → (e' : all-ready e θ) → (e'' : all-ready e θ) → δ e' ≡ δ e''
δ-e-irr {plus []} (aplus []) (aplus []) = refl
δ-e-irr {plus ((num n) ∷ x₁)} (aplus (brnum ∷ x₂)) (aplus (brnum ∷ x₃))
= cong (_+_ n) (δ-e-irr (aplus x₂) (aplus x₃))
δ-e-irr {plus ((seq-ref x) ∷ x₁)}{θ} (aplus (brseq x₂ ∷ x₃)) (aplus (brseq x₄ ∷ x₅))
with Env.var-vals-∈-irr{x}{θ} x₂ x₄
... | k rewrite sym k = (cong (_+_ (Env.var-vals{x} θ x₂)) (δ-e-irr (aplus x₃) (aplus x₅)))
δ-e-irr {plus ((shr-ref s) ∷ x₁)}{θ} (aplus (brshr s∈ x ∷ x₂)) (aplus (brshr s∈₁ x₃ ∷ x₄))
with Env.shr-vals-∈-irr{s}{θ} s∈ s∈₁
... | k rewrite sym k = cong (_+_ (Env.shr-vals{s} θ s∈)) (δ-e-irr (aplus x₂) (aplus x₄))
{-
In the current formalization, for reduction rules involving evaluation
contexts, we will write them in the following form to enable pattern
matching on p:
(r ≐ E ⟦ p ⟧e) → (something r sn⟶₁ something E ⟦ p'⟧)
-}
{- this relation is the strongly normalizing subset of
the calculus. It is just like _⟶₁_ in calculus.agda,
but without the [par-swap] constructor. -}
data _sn⟶₁_ : Term → Term → Set where
rpar-done-right : ∀{p q} →
(p' : halted p) →
(q' : done q) →
(p ∥ q) sn⟶₁ (value-max (dhalted p') q' (inj₁ p'))
rpar-done-left : ∀{p q} →
(p' : done p) →
(q' : halted q) →
(p ∥ q) sn⟶₁ (value-max p' (dhalted q') (inj₂ q'))
ris-present : ∀{θ S r p q E A} →
(S∈ : (Env.isSig∈ S θ)) →
Env.sig-stats{S} θ S∈ ≡ Signal.present →
r ≐ E ⟦ present S ∣⇒ p ∣⇒ q ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁ (ρ⟨ θ , A ⟩· E ⟦ p ⟧e)
ris-absent : ∀{θ S r p q E A} →
(S∈ : (Env.isSig∈ S θ)) →
Env.sig-stats{S} θ S∈ ≡ Signal.absent →
r ≐ E ⟦ present S ∣⇒ p ∣⇒ q ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁ (ρ⟨ θ , A ⟩· E ⟦ q ⟧e)
remit : ∀{θ r S E} →
(S∈ : (Env.isSig∈ S θ)) →
(¬S≡a : ¬ (Env.sig-stats{S} θ S∈) ≡ Signal.absent) →
r ≐ E ⟦ emit S ⟧e →
(ρ⟨ θ , GO ⟩· r) sn⟶₁
(ρ⟨ (Env.set-sig{S} θ S∈ Signal.present) , GO ⟩·
E ⟦ nothin ⟧e)
rloop-unroll : ∀{p} →
(loop p)
sn⟶₁
(loopˢ p p)
rseq-done : ∀{q} →
(nothin >> q) sn⟶₁ q
rseq-exit : ∀{q n} →
(exit n >> q) sn⟶₁ (exit n)
rloopˢ-exit : ∀{q n} →
(loopˢ (exit n) q) sn⟶₁ (exit n)
rsuspend-done : ∀{p S} →
halted p →
(suspend p S) sn⟶₁ p
-- traps
rtrap-done : ∀{p} →
(p' : halted p) →
(trap p) sn⟶₁ (↓ p')
-- lifting signals
rraise-signal : ∀{p S} →
(signl S p) sn⟶₁
(ρ⟨ (Θ SigMap.[ S ↦ Signal.unknown ] ShrMap.empty VarMap.empty) , WAIT ⟩·
p)
-- shared state
rraise-shared : ∀{θ r s e p E A} →
(e' : all-ready e θ) →
r ≐ E ⟦ shared s ≔ e in: p ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁
(ρ⟨ θ , A ⟩·
E ⟦ (ρ⟨ [s,δe]-env s (δ e') , WAIT ⟩· p) ⟧e)
rset-shared-value-old : ∀{θ r s e E} →
(e' : all-ready e θ) →
(s∈ : (Env.isShr∈ s θ)) →
Env.shr-stats{s} θ s∈ ≡ SharedVar.old →
r ≐ E ⟦ s ⇐ e ⟧e →
(ρ⟨ θ , GO ⟩· r) sn⟶₁
(ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.new) (δ e')) , GO ⟩·
E ⟦ nothin ⟧e)
rset-shared-value-new : ∀{θ r s e E} →
(e' : all-ready e θ) →
(s∈ : (Env.isShr∈ s θ)) →
Env.shr-stats{s} θ s∈ ≡ SharedVar.new →
r ≐ E ⟦ s ⇐ e ⟧e →
(ρ⟨ θ , GO ⟩· r) sn⟶₁
(ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.new) (Env.shr-vals{s} θ s∈ + δ e')) , GO ⟩·
E ⟦ nothin ⟧e)
-- unshared state
rraise-var : ∀{θ r x p e E A} →
(e' : all-ready e θ) →
r ≐ E ⟦ var x ≔ e in: p ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁
(ρ⟨ θ , A ⟩·
E ⟦ (ρ⟨ [x,δe]-env x (δ e') , WAIT ⟩· p) ⟧e)
rset-var : ∀{θ r x e E A} →
(x∈ : (Env.isVar∈ x θ)) →
(e' : all-ready e θ) →
r ≐ E ⟦ x ≔ e ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁
(ρ⟨ (Env.set-var{x} θ x∈ (δ e')) , A ⟩·
E ⟦ nothin ⟧e)
-- if
rif-false : ∀{θ r p q x E A} →
(x∈ : (Env.isVar∈ x θ)) →
Env.var-vals{x} θ x∈ ≡ zero →
r ≐ E ⟦ if x ∣⇒ p ∣⇒ q ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁ (ρ⟨ θ , A ⟩· E ⟦ q ⟧e)
rif-true : ∀{θ r p q x E n A} →
(x∈ : (Env.isVar∈ x θ)) →
Env.var-vals{x} θ x∈ ≡ suc n →
r ≐ E ⟦ if x ∣⇒ p ∣⇒ q ⟧e →
(ρ⟨ θ , A ⟩· r) sn⟶₁ (ρ⟨ θ , A ⟩· E ⟦ p ⟧e)
-- progression
{-
Thoughts:
* These two rules are expressed differently to the definition in model/shared.rkt
for simplicity. Instead of being more 'computative', the definition here is
more 'declarative'. Keep an eye on the original definition to make sure that
they are equivalent.
-}
rabsence : ∀{θ p S A} →
(S∈ : (Env.isSig∈ S θ)) →
Env.sig-stats{S} θ S∈ ≡ Signal.unknown →
(Signal.unwrap S) ∉ Canθₛ (sig θ) 0 p []env →
(ρ⟨ θ , A ⟩· p) sn⟶₁
(ρ⟨ (Env.set-sig{S} θ S∈ (Signal.absent)) , A ⟩·
p)
rreadyness : ∀{θ p s A} →
(s∈ : (Env.isShr∈ s θ)) →
(Env.shr-stats{s} θ s∈ ≡ SharedVar.old) ⊎ (Env.shr-stats{s} θ s∈ ≡ SharedVar.new) →
(SharedVar.unwrap s) ∉ Canθₛₕ (sig θ) 0 p []env →
(ρ⟨ θ , A ⟩· p) sn⟶₁
(ρ⟨ (Env.set-shr{s} θ s∈ (SharedVar.ready) (Env.shr-vals{s} θ s∈)) , A ⟩·
p)
rmerge : ∀{θ₁ θ₂ r p E A₁ A₂} →
r ≐ E ⟦ ρ⟨ θ₂ , A₂ ⟩· p ⟧e →
(ρ⟨ θ₁ , A₁ ⟩· r) sn⟶₁ (ρ⟨ (θ₁ ← θ₂) , (A-max A₁ A₂) ⟩· E ⟦ p ⟧e)
-- The compatible closure of _sn⟶₁_.
data _sn⟶_ : Term → Term → Set where
rcontext : ∀{r p p'} →
(C : Context) →
(dc : r ≐ C ⟦ p ⟧c) →
(psn⟶₁p' : p sn⟶₁ p') →
r sn⟶ (C ⟦ p' ⟧c)
sn⟶-inclusion : ∀{p q} → p sn⟶₁ q → p sn⟶ q
sn⟶-inclusion psn⟶₁q = rcontext [] dchole psn⟶₁q
data _sn⟶*_ : Term → Term → Set where
rrefl : ∀{p} → (p sn⟶* p)
rstep : ∀{p q r} → (psn⟶q : p sn⟶ q) → (qsn⟶*r : q sn⟶* r) → (p sn⟶* r)
sn⟶*-inclusion : ∀{p q} → p sn⟶ q → p sn⟶* q
sn⟶*-inclusion psn⟶q = rstep psn⟶q rrefl
data _sn≡ₑ_ : Term → Term → Set where
rstp : ∀{p q} → (psn⟶q : p sn⟶ q) → p sn≡ₑ q
rsym : ∀{p q BV FV} → (psn≡ₑq : p sn≡ₑ q) → (CBp : CorrectBinding p BV FV) → q sn≡ₑ p
rref : ∀{p} → p sn≡ₑ p
rtrn : ∀{p q r} → (psn≡ₑr : p sn≡ₑ r) → (rsn≡ₑq : r sn≡ₑ q) → p sn≡ₑ q
-- rstep, reversed: walk many steps first then walk one step
rpets : ∀ {p q r} → p sn⟶* q → q sn⟶ r → p sn⟶* r
rpets rrefl qsn⟶r = sn⟶*-inclusion qsn⟶r
rpets (rstep psn⟶s ssn⟶*q) qsn⟶r = rstep psn⟶s (rpets ssn⟶*q qsn⟶r)
{-
Properties relating halted, paused, done programs and the reduction relation.
* Halted, paused and done programs do not reduce under the original reduction relation _sn⟶₁_.
halted-¬sn⟶₁ : ∀{p p'} → halted p → ¬ p sn⟶₁ p'
paused-¬sn⟶₁ : ∀{p p'} → paused p → ¬ p sn⟶₁ p'
done-¬sn⟶₁ : ∀{p p'} → done p → ¬ p sn⟶₁ p'
* Halted programs do not reduce under the compatible closure relation _sn⟶_.
halted-¬sn⟶ : ∀{p p'} → halted p → ¬ p sn⟶ p'
* Paused programs remain paused under the compatible closure relation _sn⟶_.
paused-sn⟶ : ∀{p p'} → paused p → p sn⟶ p' → paused p'
-}
halted-¬sn⟶₁ : ∀{p p'} → halted p → ¬ p sn⟶₁ p'
halted-¬sn⟶₁ hnothin ()
halted-¬sn⟶₁ (hexit n) ()
paused-¬sn⟶₁ : ∀{p p'} → paused p → ¬ p sn⟶₁ p'
paused-¬sn⟶₁ ppause ()
paused-¬sn⟶₁ (pseq ()) rseq-done
paused-¬sn⟶₁ (pseq ()) rseq-exit
paused-¬sn⟶₁ (ploopˢ ppause) ()
paused-¬sn⟶₁ (ploopˢ (pseq a)) ()
paused-¬sn⟶₁ (ploopˢ (ppar a a₁)) ()
paused-¬sn⟶₁ (ploopˢ (psuspend a)) ()
paused-¬sn⟶₁ (ploopˢ (ptrap a)) ()
paused-¬sn⟶₁ (ploopˢ (ploopˢ a)) ()
paused-¬sn⟶₁ (ppar paused₁ paused₂) (rpar-done-right p' q') =
halted-paused-disjoint p' paused₁
paused-¬sn⟶₁ (ppar paused₁ paused₂) (rpar-done-left p' q') =
halted-paused-disjoint q' paused₂
paused-¬sn⟶₁ (psuspend paused) (rsuspend-done halted) =
halted-paused-disjoint halted paused
paused-¬sn⟶₁ (ptrap paused) (rtrap-done halted) =
halted-paused-disjoint halted paused
done-¬sn⟶₁ : ∀{p p'} → done p → ¬ p sn⟶₁ p'
done-¬sn⟶₁ (dhalted halted) psn⟶₁p' = halted-¬sn⟶₁ halted psn⟶₁p'
done-¬sn⟶₁ (dpaused paused) psn⟶₁p' = paused-¬sn⟶₁ paused psn⟶₁p'
halted-¬sn⟶ : ∀{p p'} → halted p → ¬ p sn⟶ p'
halted-¬sn⟶ halted (rcontext C dc psn⟶₁p') =
halted-¬sn⟶₁ (halted-⟦⟧c halted dc) psn⟶₁p'
paused-sn⟶ : ∀{p p'} → paused p → p sn⟶ p' → paused p'
paused-sn⟶ ppause (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ ppause psn⟶₁p')
paused-sn⟶ (pseq paused) (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ (pseq paused) psn⟶₁p')
paused-sn⟶ (ppar paused₁ paused₂) (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ (ppar paused₁ paused₂) psn⟶₁p')
paused-sn⟶ (psuspend paused) (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ (psuspend paused) psn⟶₁p')
paused-sn⟶ (ptrap paused) (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ (ptrap paused) psn⟶₁p')
paused-sn⟶ (ploopˢ paused) (rcontext _ dchole psn⟶₁p') =
⊥-elim (paused-¬sn⟶₁ (ploopˢ paused) psn⟶₁p')
paused-sn⟶ (ploopˢ paused) (rcontext _ (dcloopˢ₁ dc) psn⟶₁p') =
ploopˢ (paused-sn⟶ paused (rcontext _ dc psn⟶₁p'))
paused-sn⟶ (ploopˢ paused) (rcontext _ (dcloopˢ₂ dc) psn⟶₁p') =
ploopˢ paused
paused-sn⟶ (pseq paused) (rcontext _ (dcseq₁ dc) psn⟶₁p') =
pseq (paused-sn⟶ paused (rcontext _ dc psn⟶₁p'))
paused-sn⟶ (pseq paused) (rcontext _ (dcseq₂ dc) psn⟶₁p') =
pseq paused
paused-sn⟶ (ppar paused₁ paused₂) (rcontext _ (dcpar₁ dc) psn⟶₁p') =
ppar (paused-sn⟶ paused₁ (rcontext _ dc psn⟶₁p')) paused₂
paused-sn⟶ (ppar paused₁ paused₂) (rcontext _ (dcpar₂ dc) psn⟶₁p') =
ppar paused₁ (paused-sn⟶ paused₂ (rcontext _ dc psn⟶₁p'))
paused-sn⟶ (psuspend paused) (rcontext _ (dcsuspend dc) psn⟶₁p') =
psuspend (paused-sn⟶ paused (rcontext _ dc psn⟶₁p'))
paused-sn⟶ (ptrap paused) (rcontext _ (dctrap dc) psn⟶₁p') =
ptrap (paused-sn⟶ paused (rcontext _ dc psn⟶₁p'))
done-sn⟶ : ∀{p q} → done p → p sn⟶ q → done q
done-sn⟶ (dhalted p/halted) psn⟶q = ⊥-elim (halted-¬sn⟶ p/halted psn⟶q)
done-sn⟶ (dpaused p/paused) psn⟶q = dpaused (paused-sn⟶ p/paused psn⟶q)
Context1-sn⟶ : ∀{p p'} → (C1 : Context1) → p sn⟶ p' → (C1 ∷ []) ⟦ p ⟧c sn⟶ (C1 ∷ []) ⟦ p' ⟧c
Context1-sn⟶ (ceval (epar₁ q)) (rcontext C dc psn⟶₁p') =
rcontext (ceval (epar₁ q) ∷ C) (dcpar₁ dc) psn⟶₁p'
Context1-sn⟶ (ceval (epar₂ p₁)) (rcontext C dc psn⟶₁p') =
rcontext (ceval (epar₂ p₁) ∷ C) (dcpar₂ dc) psn⟶₁p'
Context1-sn⟶ (ceval (eseq q)) (rcontext C dc psn⟶₁p') =
rcontext (ceval (eseq q) ∷ C) (dcseq₁ dc) psn⟶₁p'
Context1-sn⟶ (ceval (eloopˢ q)) (rcontext C dc psn⟶₁p') =
rcontext (ceval (eloopˢ q) ∷ C) (dcloopˢ₁ dc) psn⟶₁p'
Context1-sn⟶ (ceval (esuspend S)) (rcontext C dc psn⟶₁p') =
rcontext (ceval (esuspend S) ∷ C) (dcsuspend dc) psn⟶₁p'
Context1-sn⟶ (ceval etrap) (rcontext C dc psn⟶₁p') =
rcontext (ceval etrap ∷ C) (dctrap dc) psn⟶₁p'
Context1-sn⟶ (csignl S) (rcontext C dc psn⟶₁p') =
rcontext (csignl S ∷ C) (dcsignl dc) psn⟶₁p'
Context1-sn⟶ (cpresent₁ S q)(rcontext C dc psn⟶₁p') =
rcontext (cpresent₁ S q ∷ C) (dcpresent₁ dc) psn⟶₁p'
Context1-sn⟶ (cpresent₂ S p') (rcontext C dc psn⟶₁p') =
rcontext (cpresent₂ S p' ∷ C) (dcpresent₂ dc) psn⟶₁p'
Context1-sn⟶ (cloop) (rcontext C dc psn⟶₁p') =
rcontext (cloop ∷ C) (dcloop dc) psn⟶₁p'
Context1-sn⟶ (cloopˢ₂ p) (rcontext C dc psn⟶₁p') =
rcontext (cloopˢ₂ p ∷ C) (dcloopˢ₂ dc) psn⟶₁p'
Context1-sn⟶ (cseq₂ p') (rcontext C dc psn⟶₁p') =
rcontext (cseq₂ p' ∷ C) (dcseq₂ dc) psn⟶₁p'
Context1-sn⟶ (cshared s e) (rcontext C dc psn⟶₁p') =
rcontext (cshared s e ∷ C) (dcshared dc) psn⟶₁p'
Context1-sn⟶ (cvar x e) (rcontext C dc psn⟶₁p') =
rcontext (cvar x e ∷ C) (dcvar dc) psn⟶₁p'
Context1-sn⟶ (cif₁ x q) (rcontext C dc psn⟶₁p') =
rcontext (cif₁ x q ∷ C) (dcif₁ dc) psn⟶₁p'
Context1-sn⟶ (cif₂ x p') (rcontext C dc psn⟶₁p') =
rcontext (cif₂ x p' ∷ C) (dcif₂ dc) psn⟶₁p'
Context1-sn⟶ (cenv θ A) (rcontext C dc psn⟶₁p') =
rcontext (cenv θ A ∷ C) (dcenv dc) psn⟶₁p'
Context1-sn⟶* : ∀{p p'} → (C1 : Context1) → p sn⟶* p' → (C1 ∷ []) ⟦ p ⟧c sn⟶* (C1 ∷ []) ⟦ p' ⟧c
Context1-sn⟶* C1 rrefl = rrefl
Context1-sn⟶* C1 (rstep psn⟶p' p'sn⟶*p'') = rstep (Context1-sn⟶ C1 psn⟶p') (Context1-sn⟶* C1 p'sn⟶*p'')
-- Unused helper function: compatible context append for _sn⟶_
-- We can't just give r sn⟶ C ⟦ p' ⟧c as the result since we can't pattern match on it
Context-sn⟶ : ∀{r p p'} →
(C : Context) → r ≐ C ⟦ p ⟧c → p sn⟶ p' →
Σ[ r' ∈ Term ] (r' ≐ C ⟦ p' ⟧c) × (r sn⟶ r')
Context-sn⟶ [] dchole psn⟶p' =
_ , dchole ,′ psn⟶p'
Context-sn⟶ (_ ∷ C) (dcpar₁ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcpar₁ dc₂ ,′ rcontext _ (dcpar₁ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcpar₂ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcpar₂ dc₂ ,′ rcontext _ (dcpar₂ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcseq₁ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcseq₁ dc₂ ,′ rcontext _ (dcseq₁ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcseq₂ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcseq₂ dc₂ ,′ rcontext _ (dcseq₂ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcsuspend dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcsuspend dc₂ ,′ rcontext _ (dcsuspend dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dctrap dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dctrap dc₂ ,′ rcontext _ (dctrap dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcsignl dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcsignl dc₂ ,′ rcontext _ (dcsignl dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcpresent₁ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcpresent₁ dc₂ ,′ rcontext _ (dcpresent₁ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcpresent₂ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcpresent₂ dc₂ ,′ rcontext _ (dcpresent₂ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcloop dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcloop dc₂ ,′ rcontext _ (dcloop dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcloopˢ₁ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcloopˢ₁ dc₂ ,′ rcontext _ (dcloopˢ₁ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcloopˢ₂ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcloopˢ₂ dc₂ ,′ rcontext _ (dcloopˢ₂ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcshared dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcshared dc₂ ,′ rcontext _ (dcshared dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcvar dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcvar dc₂ ,′ rcontext _ (dcvar dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcif₁ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcif₁ dc₂ ,′ rcontext _ (dcif₁ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcif₂ dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcif₂ dc₂ ,′ rcontext _ (dcif₂ dc') psn⟶₁p'
Context-sn⟶ (_ ∷ C) (dcenv dc₁) psn⟶p' with Context-sn⟶ C dc₁ psn⟶p'
... | _ , dc₂ , rcontext _ dc' psn⟶₁p' =
_ , dcenv dc₂ ,′ rcontext _ (dcenv dc') psn⟶₁p'
Context-sn⟶⟦⟧ : ∀{p q} → (C : Context) → p sn⟶ q → ((C ⟦ p ⟧c) sn⟶ (C ⟦ q ⟧c))
Context-sn⟶⟦⟧{p} C psn⟶q with Context-sn⟶{r = C ⟦ p ⟧c} C Crefl psn⟶q
... | (r' , r=C⟦q⟧ , rsn⟶r') rewrite unplugc r=C⟦q⟧ = rsn⟶r'
Context-sn⟶* : ∀{p q} → (C : Context) → p sn⟶* q → (C ⟦ p ⟧c) sn⟶* (C ⟦ q ⟧c)
Context-sn⟶* C rrefl = rrefl
Context-sn⟶* C₁ (rstep C→ psn⟶*q) = (rstep (Context-sn⟶⟦⟧ C₁ C→) (Context-sn⟶* C₁ psn⟶*q))
sn⟶*+ : ∀{p q r} → p sn⟶* r → r sn⟶* q → p sn⟶* q
sn⟶*+ rrefl rsn⟶*q = rsn⟶*q
sn⟶*+ (rstep x psn⟶*r) rsn⟶*q = rstep x (sn⟶*+ psn⟶*r rsn⟶*q)
ρ-stays-ρ-sn⟶₁ : ∀{θ p q A} → (ρ⟨ θ , A ⟩· p) sn⟶₁ q → Σ[ θ' ∈ Env.Env ] Σ[ qin ∈ Term ] Σ[ A' ∈ Ctrl ] q ≡ (ρ⟨ θ' , A' ⟩· qin)
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (ris-present{p = p}{E = E} S∈ x x₁) = θ , E ⟦ p ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (ris-absent{q = q}{E = E} S∈ x x₁) = θ , E ⟦ q ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (remit{S = S}{E = E} S∈ _ x) = (Env.set-sig{S} θ S∈ Signal.present) , E ⟦ nothin ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rraise-shared{s = s}{p = p}{E = E} e' x) = θ , (E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.[ s ↦ (SharedVar.old ,′ (δ e'))] VarMap.empty) , WAIT ⟩· p) ⟧e) , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rset-shared-value-old{s = s}{E = E} e' s∈ x x₁) = (Env.set-shr{s} θ s∈ (SharedVar.new) (δ e')) , E ⟦ nothin ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rset-shared-value-new{s = s}{E = E} e' s∈ x x₁) = (Env.set-shr{s} θ s∈ (SharedVar.new) (Env.shr-vals{s} θ s∈ + δ e')) , E ⟦ nothin ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rraise-var{x = x}{p = p}{E = E} e' x₁) = θ , (E ⟦ (ρ⟨ (Θ SigMap.empty ShrMap.empty VarMap.[ x ↦ δ e' ]) , WAIT ⟩· p) ⟧e) , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rset-var{x = x}{E = E} x∈ e' x₁) = (Env.set-var{x} θ x∈ (δ e')) , E ⟦ nothin ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rif-false{q = q}{E = E} x∈ x₁ x₂) = θ , E ⟦ q ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rif-true{p = p}{E = E} x∈ x₁ x₂) = θ , E ⟦ p ⟧e , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rabsence{.θ}{p}{S} S∈ x x₁) = (Env.set-sig{S} θ S∈ (Signal.absent)) , p , A , refl
ρ-stays-ρ-sn⟶₁ {θ} {A = A} (rreadyness{.θ}{p}{s} s∈ x x₁) = (Env.set-shr{s} θ s∈ (SharedVar.ready) (Env.shr-vals{s} θ s∈)) , p , A , refl
ρ-stays-ρ-sn⟶₁ {θ} (rmerge{θ₁}{θ₂}{r}{p}{E}{A₁}{A₂} x) = (θ₁ ← θ₂) , E ⟦ p ⟧e , (A-max A₁ A₂) , refl
ρ-stays-ρ-sn⟶ : ∀{θ p q A} → (ρ⟨ θ , A ⟩· p) sn⟶ q → Σ[ θ' ∈ Env.Env ] Σ[ qin ∈ Term ] Σ[ A' ∈ Ctrl ] q ≡ (ρ⟨ θ' , A' ⟩· qin)
ρ-stays-ρ-sn⟶ (rcontext .[] dchole psn⟶₁p') = ρ-stays-ρ-sn⟶₁ psn⟶₁p'
ρ-stays-ρ-sn⟶ (rcontext .(cenv _ _ ∷ _) (dcenv dc) psn⟶₁p') = _ , _ , _ , refl
ρ-stays-ρ-sn⟶* : ∀{θ p q A} → (ρ⟨ θ , A ⟩· p) sn⟶* q → Σ[ θ' ∈ Env.Env ] Σ[ qin ∈ Term ] Σ[ A ∈ Ctrl ] q ≡ (ρ⟨ θ' , A ⟩· qin)
ρ-stays-ρ-sn⟶* rrefl = _ , _ , _ , refl
ρ-stays-ρ-sn⟶* (rstep x psn⟶*q) rewrite proj₂ (proj₂ (proj₂ (ρ-stays-ρ-sn⟶ x))) = ρ-stays-ρ-sn⟶* psn⟶*q
|
{
"alphanum_fraction": 0.5635609756,
"avg_line_length": 41.2474849095,
"ext": "agda",
"hexsha": "8c36c85106d7b53eb7a37514d456079f4d494b87",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/sn-calculus.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/sn-calculus.agda",
"max_line_length": 181,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/sn-calculus.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 9943,
"size": 20500
}
|
module Lambda where
open import Prelude
-- Simply typed λ-calculus
infixr 70 _⟶_
data Type : Set where
ι : Type
_⟶_ : Type -> Type -> Type
Ctx : Set
Ctx = List Type
infixl 80 _•_
infix 20 ƛ_
data Term : Ctx -> Type -> Set where
vz : forall {Γ τ } -> Term (Γ , τ) τ
wk : forall {Γ σ τ} -> Term Γ τ -> Term (Γ , σ) τ
_•_ : forall {Γ σ τ} -> Term Γ (σ ⟶ τ) -> Term Γ σ -> Term Γ τ
ƛ_ : forall {Γ σ τ} -> Term (Γ , σ) τ -> Term Γ (σ ⟶ τ)
Terms : Ctx -> Ctx -> Set
Terms Γ Δ = All (Term Γ) Δ
infixl 60 _◄_
infixr 70 _⇒_
_⇒_ : Ctx -> Type -> Type
ε ⇒ τ = τ
(Δ , σ) ⇒ τ = Δ ⇒ σ ⟶ τ
infixl 80 _•ˢ_
_•ˢ_ : {Γ Δ : Ctx}{τ : Type} -> Term Γ (Δ ⇒ τ) -> Terms Γ Δ -> Term Γ τ
t •ˢ ∅ = t
t •ˢ (us ◄ u) = t •ˢ us • u
Var : Ctx -> Type -> Set
Var Γ τ = τ ∈ Γ
var : forall {Γ τ} -> Var Γ τ -> Term Γ τ
var hd = vz
var (tl x) = wk (var x)
vzero : forall {Γ τ} -> Var (Γ , τ) τ
vzero = hd
vsuc : forall {Γ σ τ} -> Var Γ τ -> Var (Γ , σ) τ
vsuc = tl
|
{
"alphanum_fraction": 0.5091649695,
"avg_line_length": 18.5283018868,
"ext": "agda",
"hexsha": "89c50c494878f99039d9101afa214a643f2f4627",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/outdated-and-incorrect/tait/Lambda.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/tait/Lambda.agda",
"max_line_length": 71,
"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/tait/Lambda.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": 450,
"size": 982
}
|
-- Andreas, 2016-06-13 issue #2027: Unbound variables in pattern synonyms
-- Quiz by Ulf
postulate Nat : Set
pattern hm = x
-- This pattern synonym should fail with a message like
-- Unbound variables in pattern synonym: x
quiz₁ : Nat → Nat → Nat
quiz₁ hm hm = hm
quiz₂ : Nat → Nat
quiz₂ x = hm
quiz₃ : Nat → Nat
quiz₃ hm = x
-- OLD ERROR: Not in scope: x
|
{
"alphanum_fraction": 0.6906077348,
"avg_line_length": 19.0526315789,
"ext": "agda",
"hexsha": "6f1945b5f562326d9d79e2fd517aca21f7c0c65a",
"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/Issue2027.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/Issue2027.agda",
"max_line_length": 73,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue2027.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": 115,
"size": 362
}
|
-- This is the preferred version of the integers in the library. Other
-- versions can be found in the MoreInts directory.
{-# OPTIONS --safe #-}
module Cubical.Data.Int where
open import Cubical.Data.Int.Base public
open import Cubical.Data.Int.Properties public
|
{
"alphanum_fraction": 0.7735849057,
"avg_line_length": 33.125,
"ext": "agda",
"hexsha": "57147d57961de8e1cd1047de435d7f96edef6b23",
"lang": "Agda",
"max_forks_count": 134,
"max_forks_repo_forks_event_max_datetime": "2022-03-23T16:22:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-11-16T06:11:03.000Z",
"max_forks_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "marcinjangrzybowski/cubical",
"max_forks_repo_path": "Cubical/Data/Int.agda",
"max_issues_count": 584,
"max_issues_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T12:09:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-15T09:49:02.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "marcinjangrzybowski/cubical",
"max_issues_repo_path": "Cubical/Data/Int.agda",
"max_line_length": 70,
"max_stars_count": 301,
"max_stars_repo_head_hexsha": "53e159ec2e43d981b8fcb199e9db788e006af237",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "marcinjangrzybowski/cubical",
"max_stars_repo_path": "Cubical/Data/Int.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-24T02:10:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-17T18:00:24.000Z",
"num_tokens": 57,
"size": 265
}
|
-- Andreas, 2014-05-08
-- Reported by guillaume.brunerie, Yesterday
{-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v tc.cc:25 -v reduce.compiled:95 #-}
-- {-# OPTIONS --show-implicit -v tc.inj:30 -v tc.conv:20 -v tc.meta.assign:10 #-}
-- The code below gives the following odd error:
-- > Incomplete pattern matching when applying Cubical._.C
-- The definition of [C] by pattern matching does not seem incomplete, but even if it were, it should be detected when type checking [C], not when using it (!).
-- The last definition [test] is the one triggering the error, if you comment it then everything typechecks.
record Unit : Set where
constructor unit
data _==_ {i} {A : Set i} (a : A) : A → Set where
idp : a == a
data Nat : Set where
O : Nat
S : Nat → Nat
record BS (B : Set) (C : B → Set) : Set where
constructor bs
field
{b₁ b₂} : B
c₁ : C b₁
c₂ : C b₂
p : b₁ == b₂
postulate A : Set
B : Nat → Set
C : (n : Nat) → B n → Set
B O = Unit
B (S n) = BS (B n) (C n)
-- No bug if no match on unit
-- C O _ = A
C O unit = A
C (S n) (bs {b₁} c₁ c₂ idp) = _==_ {A = _} c₁ c₂
-- Due to a bug in TypeChecking.Patterns.Match
-- a failed match of (C n b) against (C O unit)
-- turned into (C n unit).
-- This was because all patterns were matched in
-- parallel, and evaluations of successfull matches
-- (and a record constructor like unit can always
-- be successfully matched) were returned, leading
-- to a reassembly of (C n b) as (C n unit) which is
-- illtyped.
-- Now patterns are matched left to right and
-- upon failure, no further matching is performed.
record _×_ (A B : Set) : Set where
constructor _,_
field
fst : A
snd : B
open _×_ public
PathOver : {A : Set} (B : A → Set)
{x y : A} (p : x == y) (u : B x) (v : B y) → Set
PathOver B idp u v = (u == v)
syntax PathOver B p u v =
u == v [ B ↓ p ]
pair×= : {A B : Set} {a a' : A} (p : a == a') {b b' : B} (q : b == b') → (a , b) == (a' , b')
pair×= idp idp = idp
bs= : {B : Set} {C : B → Set}
{b₁ b₁' : B} {pb₁ : b₁ == b₁'}
{b₂ b₂' : B} {pb₂ : b₂ == b₂'}
{c₁ : C b₁} {c₁' : C b₁'} (pc₁ : c₁ == c₁' [ C ↓ pb₁ ])
{c₂ : C b₂} {c₂' : C b₂'} (pc₂ : c₂ == c₂' [ C ↓ pb₂ ])
{p : b₁ == b₂} {p' : b₁' == b₂'} (α : p == p' [ (λ u → fst u == snd u) ↓ pair×= pb₁ pb₂ ])
→ bs c₁ c₂ p == bs c₁' c₂' p'
bs= {pb₁ = idp} {pb₂ = idp} idp idp idp = idp
_=□^[_]_ : {a b c d : A} (p : a == b) (qr : (a == c) × (b == d)) (s : c == d) → Set
p =□^[ qr ] s = C (S (S O)) (bs {b₁ = bs _ _ idp} p s (bs= {pb₁ = idp} {pb₂ = idp} (fst qr) (snd qr) idp))
test : {a b : A} (p q : a == b) → (p =□^[ idp , idp ] q) == (p == q)
test p q = idp
{-
compareTerm (C n unit) =< (?0 n {b₁} c₁ c₂) : Set
term (?0 n {b₁} c₁ c₂) :>= (C n unit)
term (?0 n {b₁} c₁ c₂) :>= (C n unit)
solving _111 := (λ n {b₁} c₁ c₂ → C n unit)
-}
|
{
"alphanum_fraction": 0.5443037975,
"avg_line_length": 29.3195876289,
"ext": "agda",
"hexsha": "1567c07dd2767e09e10c6889f6c84f8ea2fdf7c0",
"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/Issue1124.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/Issue1124.agda",
"max_line_length": 160,
"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/Issue1124.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": 1126,
"size": 2844
}
|
module Equality where
postulate _==_ : {A : Set} -> A -> A -> Set
refl : {A : Set}{x : A} -> x == x
{-# BUILTIN EQUAL _==_ #-}
{-# BUILTIN REFL refl #-}
private
primitive
primEqElim : {A : Set}(x : A)(C : (y : A) -> x == y -> Set) ->
C x refl -> (y : A) -> (p : x == y) -> C y p
elim-== = \{A : Set} -> primEqElim {A}
subst : {A : Set}(C : A -> Set){x y : A} -> x == y -> C y -> C x
subst C {x}{y} p Cy = elim-== x (\z _ -> C z -> C x) (\Cx -> Cx) y p Cy
sym : {A : Set}{x y : A} -> x == y -> y == x
sym {x = x}{y = y} p = subst (\z -> y == z) p refl
trans : {A : Set}{x y z : A} -> x == y -> y == z -> x == z
trans {x = x}{y = y}{z = z} xy yz = subst (\w -> w == z) xy yz
cong : {A B : Set}{x y : A}(f : A -> B) -> x == y -> f x == f y
cong {y = y} f xy = subst (\ ∙ -> f ∙ == f y) xy refl
|
{
"alphanum_fraction": 0.3926453144,
"avg_line_length": 29.0689655172,
"ext": "agda",
"hexsha": "5803c31d8e4df21be828c24c4c9c12060c8fc9ab",
"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/clowns/Equality.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/clowns/Equality.agda",
"max_line_length": 73,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/clowns/Equality.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": 362,
"size": 843
}
|
{-
Proof of the standard formulation of the univalence theorem and
various consequences of univalence
- Re-exports Glue types from Cubical.Core.Glue
- The ua constant and its computation rule (up to a path)
- Proof of univalence using that unglue is an equivalence ([EquivContr])
- Equivalence induction ([EquivJ], [elimEquiv])
- Univalence theorem ([univalence])
- The computation rule for ua ([uaβ])
- Isomorphism induction ([elimIso])
-}
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Univalence where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Data.Sigma.Base
open import Cubical.Core.Glue public
using ( Glue ; glue ; unglue ; lineToEquiv )
open import Cubical.Reflection.StrictEquiv
private
variable
ℓ ℓ' : Level
-- The ua constant
ua : ∀ {A B : Type ℓ} → A ≃ B → A ≡ B
ua {A = A} {B = B} e i = Glue B (λ { (i = i0) → (A , e)
; (i = i1) → (B , idEquiv B) })
uaIdEquiv : {A : Type ℓ} → ua (idEquiv A) ≡ refl
uaIdEquiv {A = A} i j = Glue A {φ = i ∨ ~ j ∨ j} (λ _ → A , idEquiv A)
-- Propositional extensionality
hPropExt : {A B : Type ℓ} → isProp A → isProp B → (A → B) → (B → A) → A ≡ B
hPropExt Aprop Bprop f g = ua (propBiimpl→Equiv Aprop Bprop f g)
-- the unglue and glue primitives specialized to the case of ua
ua-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i)
→ B {- [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → x }) ] -}
ua-unglue e i x = unglue (i ∨ ~ i) x
ua-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A)
(y : B [ _ ↦ (λ { (i = i0) → e .fst (x 1=1) }) ])
→ ua e i {- [ _ ↦ (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) ] -}
ua-glue e i x y = glue {φ = i ∨ ~ i} (λ { (i = i0) → x 1=1 ; (i = i1) → outS y }) (outS y)
module _ {A B : Type ℓ} (e : A ≃ B) {x : A} {y : B} where
-- sometimes more useful are versions of these functions with the (i : I) factored in
ua-ungluePath : PathP (λ i → ua e i) x y → e .fst x ≡ y
ua-ungluePath p i = ua-unglue e i (p i)
ua-gluePath : e .fst x ≡ y → PathP (λ i → ua e i) x y
ua-gluePath p i = ua-glue e i (λ { (i = i0) → x }) (inS (p i))
-- ua-ungluePath and ua-gluePath are definitional inverses
ua-ungluePath-Equiv : (PathP (λ i → ua e i) x y) ≃ (e .fst x ≡ y)
unquoteDef ua-ungluePath-Equiv =
defStrictEquiv ua-ungluePath-Equiv ua-ungluePath ua-gluePath
-- ua-unglue and ua-glue are also definitional inverses, in a way
-- strengthening the types of ua-unglue and ua-glue gives a nicer formulation of this, see below
ua-unglue-glue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : Partial (~ i) A) (y : B [ _ ↦ _ ])
→ ua-unglue e i (ua-glue e i x y) ≡ outS y
ua-unglue-glue _ _ _ _ = refl
ua-glue-unglue : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : ua e i)
→ ua-glue e i (λ { (i = i0) → x }) (inS (ua-unglue e i x)) ≡ x
ua-glue-unglue _ _ _ = refl
-- mainly for documentation purposes, ua-unglue and ua-glue wrapped in cubical subtypes
ua-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
→ ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ]
→ B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ]
ua-unglueS e i x y s = inS (ua-unglue e i (outS s))
ua-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
→ B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ]
→ ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ]
ua-glueS e i x y s = inS (ua-glue e i (λ { (i = i0) → x }) (inS (outS s)))
ua-unglueS-glueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
(s : B [ _ ↦ (λ { (i = i0) → e .fst x ; (i = i1) → y }) ])
→ outS (ua-unglueS e i x y (ua-glueS e i x y s)) ≡ outS s
ua-unglueS-glueS _ _ _ _ _ = refl
ua-glueS-unglueS : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A) (y : B)
(s : ua e i [ _ ↦ (λ { (i = i0) → x ; (i = i1) → y }) ])
→ outS (ua-glueS e i x y (ua-unglueS e i x y s)) ≡ outS s
ua-glueS-unglueS _ _ _ _ _ = refl
-- a version of ua-glue with a single endpoint, identical to `ua-gluePath e {x} refl i`
ua-gluePt : ∀ {A B : Type ℓ} (e : A ≃ B) (i : I) (x : A)
→ ua e i {- [ _ ↦ (λ { (i = i0) → x ; (i = i1) → e .fst x }) ] -}
ua-gluePt e i x = ua-glue e i (λ { (i = i0) → x }) (inS (e .fst x))
-- Proof of univalence using that unglue is an equivalence:
-- unglue is an equivalence
unglueIsEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
isEquiv {A = Glue A f} (unglue φ)
equiv-proof (unglueIsEquiv A φ f) = λ (b : A) →
let u : I → Partial φ A
u i = λ{ (φ = i1) → equivCtr (f 1=1 .snd) b .snd (~ i) }
ctr : fiber (unglue φ) b
ctr = ( glue (λ { (φ = i1) → equivCtr (f 1=1 .snd) b .fst }) (hcomp u b)
, λ j → hfill u (inS b) (~ j))
in ( ctr
, λ (v : fiber (unglue φ) b) i →
let u' : I → Partial (φ ∨ ~ i ∨ i) A
u' j = λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .snd (~ j)
; (i = i0) → hfill u (inS b) j
; (i = i1) → v .snd (~ j) }
in ( glue (λ { (φ = i1) → equivCtrPath (f 1=1 .snd) b v i .fst }) (hcomp u' b)
, λ j → hfill u' (inS b) (~ j)))
-- Any partial family of equivalences can be extended to a total one
-- from Glue [ φ ↦ (T,f) ] A to A
unglueEquiv : ∀ (A : Type ℓ) (φ : I)
(f : PartialP φ (λ o → Σ[ T ∈ Type ℓ ] T ≃ A)) →
(Glue A f) ≃ A
unglueEquiv A φ f = ( unglue φ , unglueIsEquiv A φ f )
-- The following is a formulation of univalence proposed by Martín Escardó:
-- https://groups.google.com/forum/#!msg/homotopytypetheory/HfCB_b-PNEU/Ibb48LvUMeUJ
-- See also Theorem 5.8.4 of the HoTT Book.
--
-- The reason we have this formulation in the core library and not the
-- standard one is that this one is more direct to prove using that
-- unglue is an equivalence. The standard formulation can be found in
-- Cubical/Basics/Univalence.
--
EquivContr : ∀ (A : Type ℓ) → ∃![ T ∈ Type ℓ ] (T ≃ A)
EquivContr {ℓ = ℓ} A =
( (A , idEquiv A)
, idEquiv≡ )
where
idEquiv≡ : (y : Σ (Type ℓ) (λ T → T ≃ A)) → (A , idEquiv A) ≡ y
idEquiv≡ w = \ { i .fst → Glue A (f i)
; i .snd .fst → unglueEquiv _ _ (f i) .fst
; i .snd .snd .equiv-proof → unglueEquiv _ _ (f i) .snd .equiv-proof
}
where
f : ∀ i → PartialP (~ i ∨ i) (λ x → Σ[ T ∈ Type ℓ ] T ≃ A)
f i = λ { (i = i0) → A , idEquiv A ; (i = i1) → w }
contrSinglEquiv : {A B : Type ℓ} (e : A ≃ B) → (B , idEquiv B) ≡ (A , e)
contrSinglEquiv {A = A} {B = B} e =
isContr→isProp (EquivContr B) (B , idEquiv B) (A , e)
-- Equivalence induction
EquivJ : {A B : Type ℓ} (P : (A : Type ℓ) → (e : A ≃ B) → Type ℓ')
→ (r : P B (idEquiv B)) → (e : A ≃ B) → P A e
EquivJ P r e = subst (λ x → P (x .fst) (x .snd)) (contrSinglEquiv e) r
-- Assuming that we have an inverse to ua we can easily prove univalence
module Univalence (au : ∀ {ℓ} {A B : Type ℓ} → A ≡ B → A ≃ B)
(aurefl : ∀ {ℓ} {A B : Type ℓ} → au refl ≡ idEquiv A) where
ua-au : {A B : Type ℓ} (p : A ≡ B) → ua (au p) ≡ p
ua-au {B = B} = J (λ _ p → ua (au p) ≡ p)
(cong ua (aurefl {B = B}) ∙ uaIdEquiv)
au-ua : {A B : Type ℓ} (e : A ≃ B) → au (ua e) ≡ e
au-ua {B = B} = EquivJ (λ _ f → au (ua f) ≡ f)
(subst (λ r → au r ≡ idEquiv _) (sym uaIdEquiv) (aurefl {B = B}))
isoThm : ∀ {ℓ} {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B)
isoThm .Iso.fun = au
isoThm .Iso.inv = ua
isoThm .Iso.rightInv = au-ua
isoThm .Iso.leftInv = ua-au
thm : ∀ {ℓ} {A B : Type ℓ} → isEquiv au
thm {A = A} {B = B} = isoToIsEquiv {B = A ≃ B} isoThm
pathToEquiv : {A B : Type ℓ} → A ≡ B → A ≃ B
pathToEquiv p = lineToEquiv (λ i → p i)
pathToEquivRefl : {A : Type ℓ} → pathToEquiv refl ≡ idEquiv A
pathToEquivRefl {A = A} = equivEq (λ i x → transp (λ _ → A) i x)
pathToEquiv-ua : {A B : Type ℓ} (e : A ≃ B) → pathToEquiv (ua e) ≡ e
pathToEquiv-ua = Univalence.au-ua pathToEquiv pathToEquivRefl
ua-pathToEquiv : {A B : Type ℓ} (p : A ≡ B) → ua (pathToEquiv p) ≡ p
ua-pathToEquiv = Univalence.ua-au pathToEquiv pathToEquivRefl
-- Univalence
univalenceIso : {A B : Type ℓ} → Iso (A ≡ B) (A ≃ B)
univalenceIso = Univalence.isoThm pathToEquiv pathToEquivRefl
univalence : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalence = ( pathToEquiv , Univalence.thm pathToEquiv pathToEquivRefl )
-- The original map from UniMath/Foundations
eqweqmap : {A B : Type ℓ} → A ≡ B → A ≃ B
eqweqmap {A = A} e = J (λ X _ → A ≃ X) (idEquiv A) e
eqweqmapid : {A : Type ℓ} → eqweqmap refl ≡ idEquiv A
eqweqmapid {A = A} = JRefl (λ X _ → A ≃ X) (idEquiv A)
univalenceStatement : {A B : Type ℓ} → isEquiv (eqweqmap {ℓ} {A} {B})
univalenceStatement = Univalence.thm eqweqmap eqweqmapid
univalenceUAH : {A B : Type ℓ} → (A ≡ B) ≃ (A ≃ B)
univalenceUAH = ( _ , univalenceStatement )
univalencePath : {A B : Type ℓ} → (A ≡ B) ≡ Lift (A ≃ B)
univalencePath = ua (compEquiv univalence LiftEquiv)
-- The computation rule for ua. Because of "ghcomp" it is now very
-- simple compared to cubicaltt:
-- https://github.com/mortberg/cubicaltt/blob/master/examples/univalence.ctt#L202
uaβ : {A B : Type ℓ} (e : A ≃ B) (x : A) → transport (ua e) x ≡ equivFun e x
uaβ e x = transportRefl (equivFun e x)
uaη : ∀ {A B : Type ℓ} → (P : A ≡ B) → ua (pathToEquiv P) ≡ P
uaη = J (λ _ q → ua (pathToEquiv q) ≡ q) (cong ua pathToEquivRefl ∙ uaIdEquiv)
-- Lemmas for constructing and destructing dependent paths in a function type where the domain is ua.
ua→ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'}
{f₀ : A₀ → B i0} {f₁ : A₁ → B i1}
→ ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a)))
→ PathP (λ i → ua e i → B i) f₀ f₁
ua→ {e = e} {f₀ = f₀} {f₁} h i a =
hcomp
(λ j → λ
{ (i = i0) → f₀ a
; (i = i1) → f₁ (lem a j)
})
(h (transp (λ j → ua e (~ j ∧ i)) (~ i) a) i)
where
lem : ∀ a₁ → e .fst (transport (sym (ua e)) a₁) ≡ a₁
lem a₁ = retEq e _ ∙ transportRefl _
ua→⁻ : ∀ {ℓ ℓ'} {A₀ A₁ : Type ℓ} {e : A₀ ≃ A₁} {B : (i : I) → Type ℓ'}
{f₀ : A₀ → B i0} {f₁ : A₁ → B i1}
→ PathP (λ i → ua e i → B i) f₀ f₁
→ ((a : A₀) → PathP B (f₀ a) (f₁ (e .fst a)))
ua→⁻ {e = e} {f₀ = f₀} {f₁} p a i =
hcomp
(λ k → λ
{ (i = i0) → f₀ a
; (i = i1) → f₁ (uaβ e a k)
})
(p i (transp (λ j → ua e (j ∧ i)) (~ i) a))
-- Useful lemma for unfolding a transported function over ua
-- If we would have regularity this would be refl
transportUAop₁ : ∀ {A B : Type ℓ} → (e : A ≃ B) (f : A → A) (x : B)
→ transport (λ i → ua e i → ua e i) f x ≡ equivFun e (f (invEq e x))
transportUAop₁ e f x i = transportRefl (equivFun e (f (invEq e (transportRefl x i)))) i
-- Binary version
transportUAop₂ : ∀ {ℓ} {A B : Type ℓ} → (e : A ≃ B) (f : A → A → A) (x y : B)
→ transport (λ i → ua e i → ua e i → ua e i) f x y ≡
equivFun e (f (invEq e x) (invEq e y))
transportUAop₂ e f x y i =
transportRefl (equivFun e (f (invEq e (transportRefl x i))
(invEq e (transportRefl y i)))) i
-- Alternative version of EquivJ that only requires a predicate on functions
elimEquivFun : {A B : Type ℓ} (P : (A : Type ℓ) → (A → B) → Type ℓ')
→ (r : P B (idfun B)) → (e : A ≃ B) → P A (e .fst)
elimEquivFun P r e = subst (λ x → P (x .fst) (x .snd .fst)) (contrSinglEquiv e) r
-- Isomorphism induction
elimIso : {B : Type ℓ} → (Q : {A : Type ℓ} → (A → B) → (B → A) → Type ℓ') →
(h : Q (idfun B) (idfun B)) → {A : Type ℓ} →
(f : A → B) → (g : B → A) → section f g → retract f g → Q f g
elimIso {ℓ} {ℓ'} {B} Q h {A} f g sfg rfg = rem1 f g sfg rfg
where
P : (A : Type ℓ) → (f : A → B) → Type (ℓ-max ℓ' ℓ)
P A f = (g : B → A) → section f g → retract f g → Q f g
rem : P B (idfun B)
rem g sfg rfg = subst (Q (idfun B)) (λ i b → (sfg b) (~ i)) h
rem1 : {A : Type ℓ} → (f : A → B) → P A f
rem1 f g sfg rfg = elimEquivFun P rem (f , isoToIsEquiv (iso f g sfg rfg)) g sfg rfg
uaInvEquiv : ∀ {A B : Type ℓ} → (e : A ≃ B) → ua (invEquiv e) ≡ sym (ua e)
uaInvEquiv {B = B} = EquivJ (λ _ e → ua (invEquiv e) ≡ sym (ua e))
(cong ua (invEquivIdEquiv B))
uaCompEquiv : ∀ {A B C : Type ℓ} → (e : A ≃ B) (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f
uaCompEquiv {B = B} {C} = EquivJ (λ _ e → (f : B ≃ C) → ua (compEquiv e f) ≡ ua e ∙ ua f)
(λ f → cong ua (compEquivIdEquiv f)
∙ sym (cong (λ x → x ∙ ua f) uaIdEquiv
∙ sym (lUnit (ua f))))
|
{
"alphanum_fraction": 0.5250502551,
"avg_line_length": 41.7225806452,
"ext": "agda",
"hexsha": "ab75a70a925fe2fedcc813280f090b8d609d4a6f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Foundations/Univalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Foundations/Univalence.agda",
"max_line_length": 101,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Foundations/Univalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5369,
"size": 12934
}
|
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.List using (List; []; _∷_; [_]; _++_)
open import Data.List.Any using (Any; here; there)
open import Data.List.Any.Membership.Propositional using (_∈_)
open import Data.Nat using (ℕ)
open import Relation.Binary.PropositionalEquality using (_≡_; refl)
-- open import Data.List.Any.Membership.Propositional.Properties using (∈-++⁺ˡ; ∈-++⁺ʳ; ∈-++⁻)
Id = ℕ
_⊆_ : List Id → List Id → Set
xs ⊆ ys = ∀ {w} → w ∈ xs → w ∈ ys
lemma : ∀ {x : Id} → x ∈ [ x ]
lemma = here refl
|
{
"alphanum_fraction": 0.6534839925,
"avg_line_length": 33.1875,
"ext": "agda",
"hexsha": "697dca35087c7711af76b2f0b8a5f7493fd1c802",
"lang": "Agda",
"max_forks_count": 304,
"max_forks_repo_forks_event_max_datetime": "2022-03-28T11:35:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-07-16T18:24:59.000Z",
"max_forks_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "manikdv/plfa.github.io",
"max_forks_repo_path": "extra/extra/Membership.agda",
"max_issues_count": 323,
"max_issues_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_issues_repo_issues_event_max_datetime": "2022-03-30T07:42:57.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-07-05T22:34:34.000Z",
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "manikdv/plfa.github.io",
"max_issues_repo_path": "extra/extra/Membership.agda",
"max_line_length": 94,
"max_stars_count": 1003,
"max_stars_repo_head_hexsha": "8a2c2ace545092fd0e04bf5831ed458267f18ae4",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "manikdv/plfa.github.io",
"max_stars_repo_path": "extra/extra/Membership.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-27T07:03:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-05T18:15:14.000Z",
"num_tokens": 178,
"size": 531
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Unsafe Float operations
------------------------------------------------------------------------
{-# OPTIONS --with-K #-}
module Data.Float.Unsafe where
open import Data.Float
open import Data.Bool.Base using (false; true)
open import Relation.Nullary using (Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Relation.Binary.PropositionalEquality.TrustMe
------------------------------------------------------------------------
-- Equality testing
infix 4 _≟_
_≟_ : (x y : Float) → Dec (x ≡ y)
x ≟ y with primFloatEquality x y
... | true = yes trustMe
... | false = no whatever
where postulate whatever : _
|
{
"alphanum_fraction": 0.5144356955,
"avg_line_length": 28.2222222222,
"ext": "agda",
"hexsha": "db49288f260da400b8f4f35578b22a74e07ea35c",
"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/Float/Unsafe.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/Float/Unsafe.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/Float/Unsafe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 151,
"size": 762
}
|
------------------------------------------------------------------------
-- Subsets of finite sets
------------------------------------------------------------------------
module Data.Fin.Subset where
open import Data.Nat
open import Data.Vec hiding (_∈_)
open import Data.Fin
open import Data.Product
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
infixr 2 _∈_ _∉_ _⊆_ _⊈_
------------------------------------------------------------------------
-- Definitions
data Side : Set where
inside : Side
outside : Side
-- Partitions a finite set into two parts, the inside and the outside.
Subset : ℕ → Set
Subset = Vec Side
------------------------------------------------------------------------
-- Membership and subset predicates
_∈_ : ∀ {n} → Fin n → Subset n → Set
x ∈ p = p [ x ]= inside
_∉_ : ∀ {n} → Fin n → Subset n → Set
x ∉ p = ¬ (x ∈ p)
_⊆_ : ∀ {n} → Subset n → Subset n → Set
p₁ ⊆ p₂ = ∀ {x} → x ∈ p₁ → x ∈ p₂
_⊈_ : ∀ {n} → Subset n → Subset n → Set
p₁ ⊈ p₂ = ¬ (p₁ ⊆ p₂)
------------------------------------------------------------------------
-- Some specific subsets
all : ∀ {n} → Side → Subset n
all {zero} _ = []
all {suc n} s = s ∷ all s
------------------------------------------------------------------------
-- Properties
Nonempty : ∀ {n} (p : Subset n) → Set
Nonempty p = ∃ λ f → f ∈ p
Empty : ∀ {n} (p : Subset n) → Set
Empty p = ¬ Nonempty p
-- Point-wise lifting of properties.
Lift : ∀ {n} → (Fin n → Set) → (Subset n → Set)
Lift P p = ∀ {x} → x ∈ p → P x
|
{
"alphanum_fraction": 0.4299674267,
"avg_line_length": 24.3650793651,
"ext": "agda",
"hexsha": "3cb707e4c9ee5399e3728359028d532ba1a5aed9",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Data/Fin/Subset.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Data/Fin/Subset.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Data/Fin/Subset.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": 418,
"size": 1535
}
|
------------------------------------------------------------------------
-- Operations on nullary relations (like negation and decidability)
------------------------------------------------------------------------
-- Some operations on/properties of nullary relations, i.e. sets.
module Relation.Nullary where
open import Data.Product
import Relation.Nullary.Core as Core
open import Relation.Binary
open import Relation.Binary.FunctionSetoid
import Relation.Binary.EqReasoning as EqReasoning
------------------------------------------------------------------------
-- Negation
open Core public using (¬_)
------------------------------------------------------------------------
-- Equivalence
infix 3 _⇔_
_⇔_ : Set → Set → Set
P ⇔ Q = (P → Q) × (Q → P)
------------------------------------------------------------------------
-- Decidable relations
open Core public using (Dec; yes; no)
------------------------------------------------------------------------
-- Injections
Injective : ∀ {A B} → A ⟶ B → Set
Injective {A} {B} f = ∀ {x y} → f ⟨$⟩ x ≈₂ f ⟨$⟩ y → x ≈₁ y
where
open Setoid A renaming (_≈_ to _≈₁_)
open Setoid B renaming (_≈_ to _≈₂_)
_LeftInverseOf_ : ∀ {A B} → B ⟶ A → A ⟶ B → Set
_LeftInverseOf_ {A} f g = ∀ x → f ⟨$⟩ (g ⟨$⟩ x) ≈₁ x
where open Setoid A renaming (_≈_ to _≈₁_)
record Injection (From To : Setoid) : Set where
field
to : From ⟶ To
injective : Injective to
record LeftInverse (From To : Setoid) : Set where
field
to : From ⟶ To
from : To ⟶ From
left-inverse : from LeftInverseOf to
open Setoid From
open EqReasoning From
injective : Injective to
injective {x} {y} eq = begin
x ≈⟨ sym (left-inverse x) ⟩
from ⟨$⟩ (to ⟨$⟩ x) ≈⟨ pres from eq ⟩
from ⟨$⟩ (to ⟨$⟩ y) ≈⟨ left-inverse y ⟩
y ∎
injection : Injection From To
injection = record { to = to; injective = injective }
|
{
"alphanum_fraction": 0.4750898819,
"avg_line_length": 28.2173913043,
"ext": "agda",
"hexsha": "7b1ddc54dfc35b68071e5c3cee04edfe7ef50f76",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:54:10.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-07-21T16:37:58.000Z",
"max_forks_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "isabella232/Lemmachine",
"max_forks_repo_path": "vendor/stdlib/src/Relation/Nullary.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_issues_repo_issues_event_max_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-12T12:17:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/Lemmachine",
"max_issues_repo_path": "vendor/stdlib/src/Relation/Nullary.agda",
"max_line_length": 72,
"max_stars_count": 56,
"max_stars_repo_head_hexsha": "8ef786b40e4a9ab274c6103dc697dcb658cf3db3",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "isabella232/Lemmachine",
"max_stars_repo_path": "vendor/stdlib/src/Relation/Nullary.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": 520,
"size": 1947
}
|
-- Andreas, 2019-09-13, AIM XXX, test for #4050 by gallais
-- Jesper, 2019-12-19, moved to test/Fail after unfix of #3823
record Wrap : Set₂ where
field wrapped : Set₁
f : Wrap
f = record { M }
module M where
wrapped : Set₁
wrapped = Set
-- Should be accepted.
|
{
"alphanum_fraction": 0.6606498195,
"avg_line_length": 18.4666666667,
"ext": "agda",
"hexsha": "ab0f74192da1714f1496ba220450acd1b02c3829",
"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/Issue4050.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/Issue4050.agda",
"max_line_length": 62,
"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/Issue4050.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": 277
}
|
{-# OPTIONS --without-K #-}
module SimpleHoTT where
open import Data.Empty
open import Data.Sum renaming (map to _⊎→_)
open import Function renaming (_∘_ to _○_)
infixr 8 _∘_ -- path composition
infix 4 _≡_ -- propositional equality
infix 2 _∎ -- equational reasoning for paths
infixr 2 _≡⟨_⟩_ -- equational reasoning for paths
------------------------------------------------------------------------------
-- Equivalences a la HoTT (using HoTT paths and path induction)
-- Our own version of refl that makes 'a' explicit
data _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where
refl : (a : A) → (a ≡ a)
-- not sure where else to put this [Z]
hetType : {A B : Set} → (a : A) → A ≡ B → B
hetType a (refl _) = a
-- J
pathInd : ∀ {u ℓ} → {A : Set u} →
(C : {x y : A} → x ≡ y → Set ℓ) →
(c : (x : A) → C (refl x)) →
({x y : A} (p : x ≡ y) → C p)
pathInd C c (refl x) = c x
basedPathInd : {A : Set} → (a : A) → (C : (x : A) → (a ≡ x) → Set) →
C a (refl a) → ((x : A) (p : a ≡ x) → C x p)
basedPathInd a C c .a (refl .a) = c
! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x)
! = pathInd (λ {x} {y} _ → y ≡ x) refl
_∘_ : ∀ {u} → {A : Set u} → {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
_∘_ {u} {A} {x} {y} {z} p q =
pathInd {u}
(λ {x} {y} p → ((z : A) → (q : y ≡ z) → (x ≡ z)))
(λ x z q → pathInd (λ {x} {z} _ → x ≡ z) refl {x} {z} q)
{x} {y} p z q
-- p = p . refl
unitTransR : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ p ∘ refl y)
unitTransR {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ≡ p ∘ (refl y))
(λ x → refl (refl x))
{x} {y} p
-- p = refl . p
unitTransL : {A : Set} {x y : A} → (p : x ≡ y) → (p ≡ refl x ∘ p)
unitTransL {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ≡ (refl x) ∘ p)
(λ x → refl (refl x))
{x} {y} p
ap : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {x y : A} →
(f : A → B) → (x ≡ y) → (f x ≡ f y)
ap {ℓ} {ℓ'} {A} {B} {x} {y} f p =
pathInd -- on p
(λ {x} {y} p → f x ≡ f y)
(λ x → refl (f x))
{x} {y} p
ap2 : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {C : Set ℓ''}
{x₁ y₁ : A} {x₂ y₂ : B} →
(f : A → B → C) → (x₁ ≡ y₁) → (x₂ ≡ y₂) → (f x₁ x₂ ≡ f y₁ y₂)
ap2 {ℓ} {ℓ'} {ℓ''} {A} {B} {C} {x₁} {y₁} {x₂} {y₂} f p₁ p₂ =
pathInd -- on p₁
(λ {x₁} {y₁} p₁ → f x₁ x₂ ≡ f y₁ y₂)
(λ x →
pathInd -- on p₂
(λ {x₂} {y₂} p₂ → f x x₂ ≡ f x y₂)
(λ y → refl (f x y))
{x₂} {y₂} p₂)
{x₁} {y₁} p₁
-- Abbreviations for path compositions
_≡⟨_⟩_ : ∀ {u} → {A : Set u} (x : A) {y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
_ ≡⟨ p ⟩ q = p ∘ q
bydef : ∀ {u} → {A : Set u} {x : A} → (x ≡ x)
bydef {u} {A} {x} = refl x
_∎ : ∀ {u} → {A : Set u} (x : A) → x ≡ x
_∎ x = refl x
-- Transport; Lifting
transport : ∀ {ℓ ℓ'} → {A : Set ℓ} {x y : A} →
(P : A → Set ℓ') → (p : x ≡ y) → P x → P y
transport {ℓ} {ℓ'} {A} {x} {y} P p =
pathInd -- on p
(λ {x} {y} p → (P x → P y))
(λ _ → id)
{x} {y} p
-- Lemma 2.3.10
transport-f : ∀ {ℓ ℓ' ℓ''} → {A : Set ℓ} {B : Set ℓ'} {x y : A} →
(f : A → B) → (P : B → Set ℓ'') →
(p : x ≡ y) → (u : P (f x)) →
transport (P ○ f) p u ≡ transport P (ap f p) u
transport-f {ℓ} {ℓ'} {ℓ''} {A} {B} {x} {y} f P p u =
pathInd -- on p
(λ {x} {y} p → (u : P (f x)) →
transport (P ○ f) p u ≡ transport P (ap f p) u)
(λ x u → refl u)
{x} {y} p u
-- Lemma 2.11.2
transportIdR : {A : Set} {a y z : A} → (p : y ≡ z) → (q : a ≡ y) →
transport (λ x → a ≡ x) p q ≡ q ∘ p
transportIdR {A} {a} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : a ≡ y) → transport (λ x → a ≡ x) p q ≡ q ∘ p)
(λ y q → transport (λ x → a ≡ x) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransR q ⟩
q ∘ refl y ∎)
{y} {z} p q
transportIdL : {A : Set} {a y z : A} → (p : y ≡ z) → (q : y ≡ a) →
transport (λ x → x ≡ a) p q ≡ ! p ∘ q
transportIdL {A} {a} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : y ≡ a) → transport (λ x → x ≡ a) p q ≡ ! p ∘ q)
(λ y q → transport (λ x → x ≡ a) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransL q ⟩
! (refl y) ∘ q ∎)
{y} {z} p q
transportIdRefl : {A : Set} {y z : A} → (p : y ≡ z) → (q : y ≡ y) →
transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p
transportIdRefl {A} {y} {z} p q =
pathInd
(λ {y} {z} p → (q : y ≡ y) → transport (λ x → x ≡ x) p q ≡ ! p ∘ q ∘ p)
(λ y q → transport (λ x → x ≡ x) (refl y) q
≡⟨ bydef ⟩
q
≡⟨ unitTransR q ⟩
q ∘ refl y
≡⟨ unitTransL (q ∘ refl y) ⟩
! (refl y) ∘ q ∘ refl y ∎)
{y} {z} p q
-- tools for coproducts (Sec. 2.12)
indCP : {A B : Set} → (C : A ⊎ B → Set) →
((a : A) → C (inj₁ a)) → ((b : B) → C (inj₂ b)) → ((x : A ⊎ B) → C x)
indCP C f g (inj₁ a) = f a
indCP C f g (inj₂ b) = g b
code : {A B : Set} → (a₀ : A) → A ⊎ B → Set
code a₀ (inj₁ a) = a₀ ≡ a
code a₀ (inj₂ b) = ⊥
encode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (p : inj₁ a₀ ≡ x) → code a₀ x
encode {A} {B} a₀ x p = transport (code a₀) p (refl a₀)
decode : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (c : code a₀ x) → inj₁ a₀ ≡ x
decode a₀ (inj₁ a) c = ap inj₁ c
decode a₀ (inj₂ b) ()
|
{
"alphanum_fraction": 0.4003433149,
"avg_line_length": 29.96,
"ext": "agda",
"hexsha": "7391211816b721681a5face2901feb93eba0c14f",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda",
"max_line_length": 78,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/OldUnivalence/SimpleHoTT.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 2592,
"size": 5243
}
|
module Oscar.Class.ThickAndThin where
open import Oscar.Data.Fin
open import Oscar.Data.Equality
open import Oscar.Data.Nat
open import Oscar.Data.Maybe
record ThickAndThin {a} (A : Nat → Set a) : Set a where
field
thin : ∀ {m} → Fin (suc m) → A m → A (suc m)
thin-injective : ∀ {m} (x : Fin (suc m)) {y₁ y₂ : A m} → thin x y₁ ≡ thin x y₂ → y₁ ≡ y₂
thick : ∀ {m} → A (suc m) → Fin m → A m
thick∘thin=id : ∀ {m} (x : Fin m) (y : A m) → thick (thin (suc x) y) x ≡ y
check : ∀ {m} → Fin (suc m) → A (suc m) → Maybe (A m)
thin-check-id : ∀ {m} (x : Fin (suc m)) y → ∀ y' → thin x y' ≡ y → check x y ≡ just y'
open ThickAndThin ⦃ … ⦄ public
-- open import Oscar.Level
-- record ThickAndThin' {a} {A : Set a} (f : A → A) {b} (B : A → Set b) (g : ∀ {x} → B x → B (f x)) {c} (C : A → Set c) : Set (a ⊔ b ⊔ c) where
-- field
-- thin : ∀ {n} → B (f n) → C n → C (f n)
-- thick : ∀ {n} → C (f n) → B n → C n
-- thin-injective : ∀ {n} (z : B (f n)) {x y : C n} → thin z x ≡ thin z y → x ≡ y
-- thick∘thin=id : ∀ {n} (x : B n) (y : C n) → thick (thin (g x) y) x ≡ y
-- check : ∀ {n} → B (f n) → C (f n) → Maybe (C n)
-- thin-check-id : ∀ {n} (x : B (f n)) y → ∀ y' → thin x y' ≡ y → check x y ≡ just y'
-- --open ThickAndThin' ⦃ … ⦄ public
|
{
"alphanum_fraction": 0.4906687403,
"avg_line_length": 40.1875,
"ext": "agda",
"hexsha": "5f9b6cbdf5380036f85813e0d90f6600b8d791bd",
"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/ThickAndThin.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/ThickAndThin.agda",
"max_line_length": 143,
"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/ThickAndThin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 558,
"size": 1286
}
|
open import Mockingbird.Forest using (Forest)
module Mockingbird.Forest.Combination.Base {b ℓ} (forest : Forest {b} {ℓ}) where
open import Level using (Level; _⊔_)
open import Relation.Unary using (Pred; _∈_)
open Forest forest
private
variable
p : Level
x y z : Bird
P : Pred Bird p
-- If P is a set of birds, we can think of ⟨ P ⟩ as the set of birds ‘generated
-- by’ P.
data ⟨_⟩ (P : Pred Bird p) : Pred Bird (p ⊔ b ⊔ ℓ) where
[_] : (x∈P : x ∈ P) → x ∈ ⟨ P ⟩
_⟨∙⟩_∣_ :
(x∈⟨P⟩ : x ∈ ⟨ P ⟩)
→ (y∈⟨P⟩ : y ∈ ⟨ P ⟩)
→ (xy≈z : x ∙ y ≈ z)
→ z ∈ ⟨ P ⟩
infixl 6 _⟨∙⟩_
_⟨∙⟩_ : x ∈ ⟨ P ⟩ → y ∈ ⟨ P ⟩ → x ∙ y ∈ ⟨ P ⟩
_⟨∙⟩_ = _⟨∙⟩_∣ refl
|
{
"alphanum_fraction": 0.5215453195,
"avg_line_length": 22.4333333333,
"ext": "agda",
"hexsha": "07367cb192b9c61cbe99879641a589fc8a23d1ab",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "splintah/combinatory-logic",
"max_forks_repo_path": "Mockingbird/Forest/Combination/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "splintah/combinatory-logic",
"max_issues_repo_path": "Mockingbird/Forest/Combination/Base.agda",
"max_line_length": 80,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df8bf877e60b3059532c54a247a36a3d83cd55b0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "splintah/combinatory-logic",
"max_stars_repo_path": "Mockingbird/Forest/Combination/Base.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-28T23:44:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-28T23:44:42.000Z",
"num_tokens": 306,
"size": 673
}
|
{-# OPTIONS --without-K --safe #-}
-- In this module, we define the syntax of D<:
module DsubDef where
open import Data.List as List
open import Data.List.All
open import Data.Nat as ℕ
open import Data.Maybe as Maybe
open import Data.Product
open import Data.Sum
open import Data.Empty renaming (⊥ to False)
open import Function
open import Data.Nat.Properties as ℕₚ
open import Data.Maybe.Properties as Maybeₚ
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
open import Utils
infix 8 _∙A
infix 6 Π_∙_ ⟨A:_⋯_⟩
-- Types
--
-- Notations in Agda should be more readable than in Coq.
-- * ⊤ is a supertype of all types.
-- * ⊥ is a subtype of all types.
-- * (x ∙A) represents a path dependent type (x.A).
-- * (Π S ∙ U) represents a dependent function type (∀(x : S)U).
-- * (⟨A: S ⋯ U ⟩) represents a type declaration ({A : S .. U}).
data Typ : Set where
⊤ : Typ
⊥ : Typ
_∙A : (n : ℕ) → Typ
Π_∙_ : (S U : Typ) → Typ
⟨A:_⋯_⟩ : (S U : Typ) → Typ
-- typing context
Env : Set
Env = List Typ
-- shifting operation of de Bruijn indices
infixl 7 _↑_
_↑_ : Typ → ℕ → Typ
⊤ ↑ n = ⊤
⊥ ↑ n = ⊥
(x ∙A) ↑ n with n ≤? x
... | yes n≤x = suc x ∙A
... | no n>x = x ∙A
(Π S ∙ U) ↑ n = Π S ↑ n ∙ U ↑ suc n
⟨A: S ⋯ U ⟩ ↑ n = ⟨A: S ↑ n ⋯ U ↑ n ⟩
-- The remaining are technical setup.
infix 4 _↦_∈_
data _↦_∈_ : ℕ → Typ → Env → Set where
hd : ∀ {T Γ} → 0 ↦ T ↑ 0 ∈ T ∷ Γ
tl : ∀ {n T T′ Γ} → n ↦ T ∈ Γ → suc n ↦ T ↑ 0 ∈ T′ ∷ Γ
env-lookup : Env → ℕ → Maybe Typ
env-lookup Γ n = Maybe.map (repeat (suc n) (_↑ 0)) (lookupOpt Γ n)
↦∈⇒lookup : ∀ {x T Γ} → x ↦ T ∈ Γ → env-lookup Γ x ≡ just T
↦∈⇒lookup hd = refl
↦∈⇒lookup {x} {_} {Γ} (tl T∈Γ) with lookupOpt Γ x | ↦∈⇒lookup T∈Γ
... | just T′ | eq = cong (just ∘ (_↑ zero)) (just-injective eq)
... | nothing | ()
lookup⇒↦∈ : ∀ {x T Γ} → env-lookup Γ x ≡ just T → x ↦ T ∈ Γ
lookup⇒↦∈ {x} {_} {[]} ()
lookup⇒↦∈ {zero} {_} {T ∷ Γ} refl = hd
lookup⇒↦∈ {suc x} {_} {T ∷ Γ} eq with lookupOpt Γ x | λ {T} → lookup⇒↦∈ {x} {T} {Γ}
lookup⇒↦∈ refl | just T′ | rec = tl $ rec refl
lookup⇒↦∈ () | nothing | _
⟨A:⟩-injective : ∀ {S U S′ U′} → ⟨A: S ⋯ U ⟩ ≡ ⟨A: S′ ⋯ U′ ⟩ → S ≡ S′ × U ≡ U′
⟨A:⟩-injective refl = refl , refl
↑-idx : ℕ → ℕ → ℕ
↑-idx x n with n ≤? x
... | yes p = suc x
... | no ¬p = x
↑-var : ∀ x n → x ∙A ↑ n ≡ ↑-idx x n ∙A
↑-var x n with n ≤? x
... | yes p = refl
... | no ¬p = refl
↑-↑-comm : ∀ T m n → m ≤ n → T ↑ m ↑ suc n ≡ T ↑ n ↑ m
↑-↑-comm ⊤ m n m≤n = refl
↑-↑-comm ⊥ m n m≤n = refl
↑-↑-comm (x ∙A) m n m≤n with n ≤? x
... | yes n≤x
rewrite ≤?-yes (≤-trans m≤n n≤x)
| ≤?-yes n≤x
| ≤?-yes (≤-step (≤-trans m≤n n≤x)) = refl
... | no n>x with m ≤? x
... | yes m≤x rewrite proj₂ $ ≤?-no n>x = refl
... | no m>x with suc n ≤? x
... | yes 1+n≤x = ⊥-elim (m>x (≤-trans (≤-step m≤n) 1+n≤x))
... | no 1+n>x = refl
↑-↑-comm (Π S ∙ U) m n m≤n
rewrite ↑-↑-comm S m n m≤n
| ↑-↑-comm U (suc m) (suc n) (s≤s m≤n) = refl
↑-↑-comm ⟨A: S ⋯ U ⟩ m n m≤n
rewrite ↑-↑-comm S m n m≤n | ↑-↑-comm U m n m≤n = refl
-- These two judgments are about to capture the characteristics of the image of
-- interpretation functions from F<:⁻ to D<:.
--
-- Covar quantifies the types in D<: which appears in the covariant positions in the
-- image of the interpretation function.
data Covar : Typ → Set where
cv⊤ : Covar ⊤
cv∙A : ∀ n → Covar (n ∙A)
cvΠ : ∀ {S U} → Covar S → Covar U → Covar (Π ⟨A: ⊥ ⋯ S ⟩ ∙ U)
-- Contra quantifies the types in D<: which appears in the contravariant positions in
-- the image of the interpretation function.
data Contra : Typ → Set where
ctt : ∀ {T} → Covar T → Contra ⟨A: ⊥ ⋯ T ⟩
ContraEnv : Env → Set
ContraEnv = All Contra
↑-Covar : ∀ {T} n → Covar T → Covar (T ↑ n)
↑-Covar n cv⊤ = cv⊤
↑-Covar n (cv∙A x)
rewrite ↑-var x n = cv∙A _
↑-Covar n (cvΠ S U) = cvΠ (↑-Covar n S) (↑-Covar (suc n) U)
↑-Contra : ∀ {T} n → Contra T → Contra (T ↑ n)
↑-Contra n (ctt T) = ctt (↑-Covar n T)
↑-injective : ∀ {S U n} → S ↑ n ≡ U ↑ n → S ≡ U
↑-injective {⊤} {⊤} {n} eq = refl
↑-injective {⊤} {⊥} {n} ()
↑-injective {⊤} {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {⊤} {Π S ∙ U} {n} ()
↑-injective {⊤} {⟨A: S ⋯ U ⟩} {n} ()
↑-injective {⊥} {⊤} {n} ()
↑-injective {⊥} {⊥} {n} eq = refl
↑-injective {⊥} {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {⊥} {Π S ∙ U} {n} ()
↑-injective {⊥} {⟨A: S ⋯ U ⟩} {n} ()
↑-injective {x ∙A} {⊤} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {x ∙A} {⊥} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {x ∙A} {y ∙A} {n} eq
with n ≤? x | n ≤? y
↑-injective {x ∙A} {y ∙A} {n} refl
| yes n≤x | yes n≤y = refl
↑-injective {x ∙A} {y ∙A} {n} refl
| yes n≤x | no n>y = ⊥-elim (n>y (≤-step n≤x))
↑-injective {x ∙A} {y ∙A} {n} refl
| no n>x | yes n≤y = ⊥-elim (n>x (≤-step n≤y))
↑-injective {x ∙A} {y ∙A} {n} refl
| no n>x | no n>y = refl
↑-injective {x ∙A} {Π S ∙ U} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {x ∙A} {⟨A: S ⋯ U ⟩} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {Π S ∙ U} {⊤} {n} ()
↑-injective {Π S ∙ U} {⊥} {n} ()
↑-injective {Π S ∙ U} {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {Π S ∙ U} {Π S′ ∙ U′} {n} eq
with S ↑ n | U ↑ suc n | S′ ↑ n | U′ ↑ suc n
| ↑-injective {S} {S′} {n} | ↑-injective {U} {U′} {suc n}
... | _ | _ | _ | _ | rec₁ | rec₂
with eq
... | refl = cong₂ Π_∙_ (rec₁ refl) (rec₂ refl)
↑-injective {Π S ∙ U} {⟨A: _ ⋯ _ ⟩} {n} ()
↑-injective {⟨A: S ⋯ U ⟩} {⊤} {n} ()
↑-injective {⟨A: S ⋯ U ⟩} {⊥} {n} ()
↑-injective {⟨A: S ⋯ U ⟩} {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-injective {⟨A: S ⋯ U ⟩} {Π _ ∙ _} {n} ()
↑-injective {⟨A: S ⋯ U ⟩} {⟨A: S′ ⋯ U′ ⟩} {n} eq
with S ↑ n | U ↑ n | S′ ↑ n | U′ ↑ n
| ↑-injective {S} {S′} {n} | ↑-injective {U} {U′} {n}
... | _ | _ | _ | _ | rec₁ | rec₂
with eq
... | refl = cong₂ ⟨A:_⋯_⟩ (rec₁ refl) (rec₂ refl)
↑-⊥-inv : ∀ {S n} → S ↑ n ≡ ⊥ → S ≡ ⊥
↑-⊥-inv {⊤} {n} ()
↑-⊥-inv {⊥} {n} refl = refl
↑-⊥-inv {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
↑-⊥-inv {Π _ ∙ _} {n} ()
↑-⊥-inv {⟨A: _ ⋯ _ ⟩} {n} ()
⟨A:⟩-↑-inv : ∀ {T n S U} → ⟨A: S ⋯ U ⟩ ≡ T ↑ n → ∃₂ λ S′ U′ → T ≡ ⟨A: S′ ⋯ U′ ⟩ × S ≡ S′ ↑ n × U ≡ U′ ↑ n
⟨A:⟩-↑-inv {⊤} ()
⟨A:⟩-↑-inv {⊥} ()
⟨A:⟩-↑-inv {x ∙A} {n} eq
rewrite ↑-var x n = case eq of λ ()
⟨A:⟩-↑-inv {Π _ ∙ _} ()
⟨A:⟩-↑-inv {⟨A: S′ ⋯ U′ ⟩} refl = S′ , U′ , refl , refl , refl
↦∈ContraEnv : ∀ {Γ n T} → n ↦ T ∈ Γ → ContraEnv Γ → Contra T
↦∈ContraEnv hd (T ∷ cT) = ↑-Contra 0 T
↦∈ContraEnv (tl T∈Γ) (_ ∷ cT) = ↑-Contra 0 (↦∈ContraEnv T∈Γ cT)
lookupContraEnv : ∀ {Γ n T} → env-lookup Γ n ≡ just T → ContraEnv Γ → Contra T
lookupContraEnv lk cT = ↦∈ContraEnv (lookup⇒↦∈ lk) cT
lookupContraBot : ∀ {Γ n} → ContraEnv Γ → ¬ env-lookup Γ n ≡ just ⊥
lookupContraBot all eq with lookupContraEnv eq all
... | ()
lookupContraBndBot : ∀ {Γ n S} → ContraEnv Γ → ¬ env-lookup Γ n ≡ just ⟨A: S ⋯ ⊥ ⟩
lookupContraBndBot all eq with lookupContraEnv eq all
... | ctt ()
lookupContraBndBnd : ∀ {Γ n T S U} → ContraEnv Γ →
¬ env-lookup Γ n ≡ just ⟨A: T ⋯ ⟨A: S ⋯ U ⟩ ⟩
lookupContraBndBnd all eq with lookupContraEnv eq all
... | ctt ()
lookupContra⊥Lb : ∀ {Γ n S U} → ContraEnv Γ →
env-lookup Γ n ≡ just ⟨A: S ⋯ U ⟩ → S ≡ ⊥
lookupContra⊥Lb all eq with lookupContraEnv eq all
... | ctt _ = refl
Typ-measure : Typ → ℕ
Typ-measure ⊤ = 1
Typ-measure ⊥ = 1
Typ-measure (_ ∙A) = 2
Typ-measure (Π S ∙ U) = 1 + Typ-measure S + Typ-measure U
Typ-measure ⟨A: S ⋯ U ⟩ = 1 + Typ-measure S + Typ-measure U
Typ-measure-↑ : ∀ T n → Typ-measure (T ↑ n) ≡ Typ-measure T
Typ-measure-↑ ⊤ n = refl
Typ-measure-↑ ⊥ n = refl
Typ-measure-↑ (x ∙A) n
rewrite ↑-var x n = refl
Typ-measure-↑ (Π S ∙ U) n
rewrite Typ-measure-↑ S n
| Typ-measure-↑ U (suc n) = refl
Typ-measure-↑ ⟨A: S ⋯ U ⟩ n
rewrite Typ-measure-↑ S n
| Typ-measure-↑ U n = refl
-- Definition of Invertible Contexts
--
-- As per Definition 9, we define a predicate for invertible contexts.
record InvertibleEnv (P : Env → Set) : Set where
field
no-⊥ : ∀ {Γ n} → P Γ → ¬ env-lookup Γ n ≡ just ⊥
no-bnd-⊥ : ∀ {Γ n S} → P Γ → ¬ env-lookup Γ n ≡ just ⟨A: S ⋯ ⊥ ⟩
no-bnd-bnd : ∀ {Γ n T S U} → P Γ → ¬ env-lookup Γ n ≡ just ⟨A: T ⋯ ⟨A: S ⋯ U ⟩ ⟩
⊥-lb : ∀ {Γ n S U} → P Γ → env-lookup Γ n ≡ just ⟨A: S ⋯ U ⟩ → S ≡ ⊥
contraInvertible : InvertibleEnv ContraEnv
contraInvertible = record
{ no-⊥ = lookupContraBot
; no-bnd-⊥ = lookupContraBndBot
; no-bnd-bnd = lookupContraBndBnd
; ⊥-lb = lookupContra⊥Lb
}
-- Properties of Invertible Contexts
--
-- Just by knowing the contexts being invertible, we can already derive many
-- properties of D<:. In the following module, we show that in invertible contexts,
-- inversion properties are recovered. For technical reasons, we leave the subtyping
-- judgment open in order to accomodate multiple definition of subtyping in D<:.
--
-- These properties are discussed in Section 4.4.
module InvertibleProperties {P : Env → Set}
(invertible : InvertibleEnv P)
(_⊢_<:_ : Env → Typ → Typ → Set) where
open InvertibleEnv invertible public
-- We define <:ᵢ to describe a fragment of <: under the restriction of invertible contexts.
infix 4 _⊢ᵢ_<:_
data _⊢ᵢ_<:_ : Env → Typ → Typ → Set where
ditop : ∀ {Γ T} → Γ ⊢ᵢ T <: ⊤
dibot : ∀ {Γ T} → Γ ⊢ᵢ ⊥ <: T
direfl : ∀ {Γ T} → Γ ⊢ᵢ T <: T
ditrans : ∀ {Γ S U} T →
(S<:T : Γ ⊢ᵢ S <: T) →
(T<:U : Γ ⊢ᵢ T <: U) →
Γ ⊢ᵢ S <: U
dibnd : ∀ {Γ S U S′ U′} →
(S′<:S : Γ ⊢ᵢ S′ <: S) →
(U<:U′ : Γ ⊢ᵢ U <: U′) →
Γ ⊢ᵢ ⟨A: S ⋯ U ⟩ <: ⟨A: S′ ⋯ U′ ⟩
diall : ∀ {Γ S U S′ U′} →
(S′<:S : Γ ⊢ᵢ S′ <: S) →
(U<:U′ : (Γ ‣ S′ !) ⊢ U <: U′) →
Γ ⊢ᵢ Π S ∙ U <: Π S′ ∙ U′
disel : ∀ {Γ n U} →
(T∈Γ : env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ U ⟩) →
Γ ⊢ᵢ n ∙A <: U
module _ where
⊤<: : ∀ {Γ T} → Γ ⊢ᵢ ⊤ <: T → T ≡ ⊤
⊤<: ditop = refl
⊤<: direfl = refl
⊤<: (ditrans T S<:T T<:U) with ⊤<: S<:T
... | refl = ⊤<: T<:U
<:⊥ : ∀ {Γ T} → Γ ⊢ᵢ T <: ⊥ → P Γ → T ≡ ⊥
<:⊥ dibot pΓ = refl
<:⊥ direfl pΓ = refl
<:⊥ (ditrans T S<:T T<:U) pΓ with <:⊥ T<:U pΓ
... | refl = <:⊥ S<:T pΓ
<:⊥ (disel T∈Γ) pΓ = ⊥-elim (no-bnd-⊥ pΓ T∈Γ)
⟨A:⟩<: : ∀ {Γ T S U} → Γ ⊢ᵢ ⟨A: S ⋯ U ⟩ <: T → T ≡ ⊤ ⊎ ∃₂ (λ S′ U′ → T ≡ ⟨A: S′ ⋯ U′ ⟩)
⟨A:⟩<: ditop = inj₁ refl
⟨A:⟩<: direfl = inj₂ (-, -, refl)
⟨A:⟩<: (ditrans T S<:T T<:U) with ⟨A:⟩<: S<:T
... | inj₁ refl = inj₁ (⊤<: T<:U)
... | inj₂ (_ , _ , refl) with ⟨A:⟩<: T<:U
... | inj₁ eq = inj₁ eq
... | inj₂ (_ , _ , eq) = inj₂ (-, -, eq)
⟨A:⟩<: (dibnd D₁ D₂) = inj₂ (-, -, refl)
<:⟨A:⟩ : ∀ {Γ T S U} → Γ ⊢ᵢ T <: ⟨A: S ⋯ U ⟩ → P Γ →
T ≡ ⊥ ⊎ ∃₂ (λ S′ U′ → T ≡ ⟨A: S′ ⋯ U′ ⟩)
<:⟨A:⟩ dibot pΓ = inj₁ refl
<:⟨A:⟩ direfl pΓ = inj₂ (-, -, refl)
<:⟨A:⟩ (ditrans T S<:T T<:U) pΓ with <:⟨A:⟩ T<:U pΓ
... | inj₁ refl = inj₁ (<:⊥ S<:T pΓ)
... | inj₂ (S′ , U′ , refl) with <:⟨A:⟩ S<:T pΓ
... | inj₁ eq = inj₁ eq
... | inj₂ (S″ , U″ , eq) = inj₂ (S″ , U″ , eq)
<:⟨A:⟩ (dibnd D₁ D₂) pΓ = inj₂ (-, -, refl)
<:⟨A:⟩ (disel T∈Γ) pΓ = ⊥-elim (no-bnd-bnd pΓ T∈Γ)
⟨A:⟩<:⟨A:⟩ : ∀ {Γ S S′ U U′} → Γ ⊢ᵢ ⟨A: S ⋯ U ⟩ <: ⟨A: S′ ⋯ U′ ⟩ → P Γ →
Γ ⊢ᵢ S′ <: S × Γ ⊢ᵢ U <: U′
⟨A:⟩<:⟨A:⟩ direfl pΓ = direfl , direfl
⟨A:⟩<:⟨A:⟩ (ditrans T S<:T T<:U) pΓ with ⟨A:⟩<: S<:T
... | inj₁ refl with ⊤<: T<:U
... | ()
⟨A:⟩<:⟨A:⟩ (ditrans T S<:T T<:U) pΓ | inj₂ (_ , _ , refl)
with ⟨A:⟩<:⟨A:⟩ S<:T pΓ | ⟨A:⟩<:⟨A:⟩ T<:U pΓ
... | S″<:S , U<:U″ | S′<:S″ , U″<:U′ = ditrans _ S′<:S″ S″<:S , ditrans _ U<:U″ U″<:U′
⟨A:⟩<:⟨A:⟩ (dibnd D₁ D₂) pΓ = D₁ , D₂
infix 4 _reach_from_
data _reach_from_ : Env → Typ → ℕ → Set where
/_/ : ∀ {Γ n T} →
env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ T ⟩ →
Γ reach T from n
_∷_ : ∀ {Γ n m T} →
env-lookup Γ n ≡ just ⟨A: ⊥ ⋯ m ∙A ⟩ →
Γ reach T from m →
Γ reach T from n
rf-concat : ∀ {Γ T m n} → Γ reach T from m → Γ reach m ∙A from n → Γ reach T from n
rf-concat m↝T / B∈Γ / = B∈Γ ∷ m↝T
rf-concat m↝T (B∈Γ ∷ n↝m∙A) = B∈Γ ∷ rf-concat m↝T n↝m∙A
∙A<: : ∀ {Γ n T} → Γ ⊢ᵢ n ∙A <: T →
T ≡ ⊤ ⊎ T ≡ n ∙A ⊎ ∃ λ T′ → Γ reach T′ from n × Γ ⊢ᵢ T′ <: T
∙A<: ditop = inj₁ refl
∙A<: direfl = inj₂ (inj₁ refl)
∙A<: (ditrans T S<:T T<:U) with ∙A<: S<:T
... | inj₁ refl = inj₁ (⊤<: T<:U)
... | inj₂ (inj₁ refl) = ∙A<: T<:U
... | inj₂ (inj₂ (T′ , n↝T′ , T′<:T)) = inj₂ (inj₂ (T′ , n↝T′ , ditrans _ T′<:T T<:U))
∙A<: (disel T∈Γ) = inj₂ (inj₂ (-, / T∈Γ / , direfl))
<:∙A : ∀ {Γ n T} → Γ ⊢ᵢ T <: n ∙A → P Γ →
T ≡ ⊥ ⊎
T ≡ n ∙A ⊎
∃ (λ m → T ≡ m ∙A × Γ reach n ∙A from m)
<:∙A dibot pΓ = inj₁ refl
<:∙A direfl pΓ = inj₂ (inj₁ refl)
<:∙A (ditrans T S<:T T<:U) pΓ with <:∙A T<:U pΓ
... | inj₁ refl = inj₁ (<:⊥ S<:T pΓ)
... | inj₂ (inj₁ refl) = <:∙A S<:T pΓ
... | inj₂ (inj₂ (m , refl , m↝n∙A))
with <:∙A S<:T pΓ
... | inj₁ refl = inj₁ refl
... | inj₂ (inj₁ refl) = inj₂ (inj₂ (-, refl , m↝n∙A))
... | inj₂ (inj₂ (m′ , refl , m′↝m∙A)) = inj₂ (inj₂ (-, refl , rf-concat m↝n∙A m′↝m∙A))
<:∙A (disel T∈Γ) pΓ = inj₂ (inj₂ (-, refl , / T∈Γ /))
Π<: : ∀ {Γ S U T} → Γ ⊢ᵢ Π S ∙ U <: T →
T ≡ ⊤ ⊎ ∃₂ (λ S′ U′ → T ≡ Π S′ ∙ U′)
Π<: ditop = inj₁ refl
Π<: direfl = inj₂ (-, -, refl)
Π<: (ditrans T S<:T T<:U) with Π<: S<:T
... | inj₁ refl = inj₁ (⊤<: T<:U)
... | inj₂ (_ , _ , refl) = Π<: T<:U
Π<: (diall D₁ D₂) = inj₂ (-, -, refl)
<:Π : ∀ {Γ S U T} → Γ ⊢ᵢ T <: Π S ∙ U → P Γ →
T ≡ ⊥ ⊎
∃ (λ n → T ≡ n ∙A) ⊎
∃₂ (λ S′ U′ → T ≡ Π S′ ∙ U′)
<:Π dibot pΓ = inj₁ refl
<:Π direfl pΓ = inj₂ (inj₂ (-, -, refl))
<:Π (ditrans T S<:T T<:U) pΓ with <:Π T<:U pΓ
... | inj₁ refl = inj₁ (<:⊥ S<:T pΓ)
... | inj₂ (inj₁ (_ , refl)) with <:∙A S<:T pΓ
... | inj₁ eq = inj₁ eq
... | inj₂ (inj₁ eq) = inj₂ (inj₁ (-, eq))
... | inj₂ (inj₂ (_ , eq , _)) = inj₂ (inj₁ (-, eq))
<:Π (ditrans T S<:T T<:U) pΓ | inj₂ (inj₂ (_ , _ , refl))
= <:Π S<:T pΓ
<:Π (diall D₁ D₂) pΓ = inj₂ (inj₂ (-, -, refl))
<:Π (disel T∈Γ) pΓ = inj₂ (inj₁ (-, refl))
-- Terms and Values
infix 6 var_ val_
infix 6 ⟨A=_⟩ _$$_
infixr 7 lt_inn_
infixr 6 Λ_∙_
mutual
-- Values
--
-- * (⟨A= T ⟩) represents a type tag ({A = T}).
-- * (Λ T ∙ t) represents a lambda expression (λ(x : T)t)
data Val : Set where
⟨A=_⟩ : (T : Typ) → Val
Λ_∙_ : (T : Typ) → (t : Trm) → Val
-- Terms
--
-- * (var x) represents a variable.
-- * (val v) represents a value as a term.
-- * (x $$ y) is an application of two variables.
-- * (lt t inn u) represents let binding (let x = t in u).
data Trm : Set where
var_ : ℕ → Trm
val_ : (v : Val) → Trm
_$$_ : (x y : ℕ) → Trm
lt_inn_ : Trm → Trm → Trm
-- substitution operation
record Subst (T : Set) : Set where
infixl 5 _[_/_]
field
_[_/_] : T → ℕ → ℕ → T
open Subst {{...}} public
infixl 5 _[_/_]ᵥ _[_/_]ₜ _[_/_]T
ℕsubst : ℕ → ℕ → ℕ → ℕ
ℕsubst x n m with x ≟ m
... | yes x≡m = n
... | no x≢m = x
instance
substℕ : Subst ℕ
substℕ = record { _[_/_] = ℕsubst }
_[_/_]T : Typ → ℕ → ℕ → Typ
⊤ [ n / m ]T = ⊤
⊥ [ n / m ]T = ⊥
x ∙A [ n / m ]T = (x [ n / m ]) ∙A
Π S ∙ U [ n / m ]T = Π S [ n / m ]T ∙ (U [ suc n / suc m ]T)
⟨A: S ⋯ U ⟩ [ n / m ]T = ⟨A: S [ n / m ]T ⋯ U [ n / m ]T ⟩
instance
substTyp : Subst Typ
substTyp = record { _[_/_] = _[_/_]T }
mutual
_[_/_]ᵥ : Val → ℕ → ℕ → Val
⟨A= T ⟩ [ n / m ]ᵥ = ⟨A= T [ n / m ] ⟩
Λ T ∙ t [ n / m ]ᵥ = Λ T [ n / m ] ∙ (t [ suc n / suc m ]ₜ)
_[_/_]ₜ : Trm → ℕ → ℕ → Trm
var x [ n / m ]ₜ = var (x [ n / m ])
val v [ n / m ]ₜ = val (v [ n / m ]ᵥ)
x $$ y [ n / m ]ₜ = (x [ n / m ]) $$ (y [ n / m ])
lt t inn u [ n / m ]ₜ = lt (t [ n / m ]ₜ) inn (u [ suc n / suc m ]ₜ)
instance
substVal : Subst Val
substVal = record { _[_/_] = _[_/_]ᵥ }
substTrm : Subst Trm
substTrm = record { _[_/_] = _[_/_]ₜ }
data Closed : ℕ → Typ → Set where
cl-⊤ : ∀ {n} → Closed n ⊤
cl-⊥ : ∀ {n} → Closed n ⊥
cl-∙A : ∀ {n m} (m≥n : m ≥ n) → Closed n (m ∙A)
cl-Π : ∀ {n S U} → Closed n S → Closed (suc n) U → Closed n (Π S ∙ U)
cl-⟨A⟩ : ∀ {n S U} → Closed n S → Closed n U → Closed n ⟨A: S ⋯ U ⟩
infix 7 _↓
_↓ : ∀ {n T} → Closed (suc n) T → Typ
cl-⊤ ↓ = ⊤
cl-⊥ ↓ = ⊥
cl-∙A {_} {m} m≥n ↓ = pred m ∙A
cl-Π S U ↓ = Π S ↓ ∙ (U ↓)
cl-⟨A⟩ S U ↓ = ⟨A: S ↓ ⋯ U ↓ ⟩
|
{
"alphanum_fraction": 0.4382298709,
"avg_line_length": 35.3695652174,
"ext": "agda",
"hexsha": "a11265ecda977d52e778f2e5299321a35daa7fc6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "HuStmpHrrr/popl20-artifact",
"max_forks_repo_path": "agda/DsubDef.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "HuStmpHrrr/popl20-artifact",
"max_issues_repo_path": "agda/DsubDef.agda",
"max_line_length": 105,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "HuStmpHrrr/popl20-artifact",
"max_stars_repo_path": "agda/DsubDef.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z",
"num_tokens": 8429,
"size": 17897
}
|
{-# OPTIONS --safe --cubical-compatible --no-universe-polymorphism --no-sized-types --no-guardedness #-}
module Issue2487-1 where
import Issue2487.Coinfective
|
{
"alphanum_fraction": 0.7577639752,
"avg_line_length": 26.8333333333,
"ext": "agda",
"hexsha": "358a48954ce55146b6e377989002c288ac2c6f7e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "KDr2/agda",
"max_forks_repo_path": "test/Succeed/Issue2487-1.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_issues_repo_issues_event_max_datetime": "2021-11-24T08:31:10.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-10-18T08:12:24.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "KDr2/agda",
"max_issues_repo_path": "test/Succeed/Issue2487-1.agda",
"max_line_length": 104,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "98c9382a59f707c2c97d75919e389fc2a783ac75",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "KDr2/agda",
"max_stars_repo_path": "test/Succeed/Issue2487-1.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 43,
"size": 161
}
|
-- Andreas, 2012-01-11
module Issue551b where
data Box (A : Set) : Set where
[_] : .A → Box A
implicit : {A : Set}{{a : A}} -> A
implicit {{a}} = a
postulate
A B : Set
instance a : A
a' : Box A
a' = [ implicit ]
-- this should succeed
f : Box B → Box (Box B)
f [ x ] = [ [ x ] ]
-- this as well
|
{
"alphanum_fraction": 0.5392156863,
"avg_line_length": 14.5714285714,
"ext": "agda",
"hexsha": "1ae76563b36b4851a63792301bb7e63d4f823e76",
"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/Issue551b.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/Issue551b.agda",
"max_line_length": 34,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue551b.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": 117,
"size": 306
}
|
------------------------------------------------------------------------
-- Yet another implementation of the Fibonacci sequence using tail
------------------------------------------------------------------------
module LargeCombinators where
open import Codata.Musical.Notation
open import Codata.Musical.Stream as S using (Stream; _∷_; _≈_)
open import Data.Nat
import Relation.Binary.PropositionalEquality as P
-- Stream programs. Note that the destructor tail is encapsulated in a
-- larger combinator, which also incorporates a constructor. This
-- ensures that the combinator can be used freely, with no risk of
-- destroying productivity.
--
-- Note that, in the general case, the implementation of whnf for the
-- "large combinator" may be quite tricky. In this case the
-- implementation turns out to be very simple, though.
--
-- The idea to use a "large combinator" is due to Thorsten Altenkirch.
infixr 5 _∷_
data StreamP (A : Set) : Set where
_∷_ : (x : A) (xs : ∞ (StreamP A)) → StreamP A
zipWith : (f : A → A → A) (xs ys : StreamP A) → StreamP A
-- The intention is that ⟦ x ∷zipWith f · xs [tail ys ] ⟧P should be
-- equal to x ∷ ♯ S.zipWith f ⟦ xs ⟧P (S.tail ⟦ ys ⟧P).
_∷zipWith_·_[tail_] :
(x : A) (f : A → A → A) (xs ys : StreamP A) → StreamP A
-- WHNFs.
data StreamW (A : Set) : Set where
_∷_ : (x : A) (xs : StreamP A) → StreamW A
-- Stream programs can be turned into streams.
whnf : ∀ {A} → StreamP A → StreamW A
whnf (x ∷ xs) = x ∷ ♭ xs
whnf (x ∷zipWith f · xs′ [tail ys ]) with whnf ys
... | _ ∷ ys′ = x ∷ zipWith f xs′ ys′
whnf (zipWith f xs ys) with whnf xs | whnf ys
... | x ∷ xs′ | y ∷ ys′ = f x y ∷ zipWith f xs′ ys′
mutual
⟦_⟧W : ∀ {A} → StreamW A → Stream A
⟦ x ∷ xs ⟧W = x ∷ ♯ ⟦ xs ⟧P
⟦_⟧P : ∀ {A} → StreamP A → Stream A
⟦ xs ⟧P = ⟦ whnf xs ⟧W
-- The Fibonacci sequence.
fib : StreamP ℕ
fib = 0 ∷ ♯ (1 ∷zipWith _+_ · fib [tail fib ])
-- ⟦_⟧P is homomorphic with respect to zipWith/S.zipWith.
zipWith-hom :
∀ {A} (f : A → A → A) (xs ys : StreamP A) →
⟦ zipWith f xs ys ⟧P ≈ S.zipWith f ⟦ xs ⟧P ⟦ ys ⟧P
zipWith-hom f xs ys with whnf xs | whnf ys
... | x ∷ xs′ | y ∷ ys′ = P.refl ∷ ♯ zipWith-hom f xs′ ys′
-- The stream ⟦ fib ⟧P satisfies its intended defining equation.
fib-correct :
⟦ fib ⟧P ≈ 0 ∷ ♯ (1 ∷ ♯ (S.zipWith _+_ ⟦ fib ⟧P (S.tail ⟦ fib ⟧P)))
fib-correct =
P.refl ∷ ♯ (P.refl ∷ ♯
zipWith-hom _+_ fib (1 ∷zipWith _+_ · fib [tail fib ]))
-- For completeness, let us show that _∷zipWith_·_[tail_] is correctly
-- implemented.
open import Relation.Binary.PropositionalEquality as P using (_≡_; [_])
_∷zipWith_·_[tail_]-hom :
∀ {A} (x : A) (f : A → A → A) (xs ys : StreamP A) →
⟦ x ∷zipWith f · xs [tail ys ] ⟧P ≈
x ∷ ♯ S.zipWith f ⟦ xs ⟧P (S.tail ⟦ ys ⟧P)
x ∷zipWith f · xs [tail ys ]-hom with whnf ys | P.inspect whnf ys
... | y ∷ ys′ | [ eq ] = P.refl ∷ ♯ helper eq
where
helper : whnf ys ≡ y ∷ ys′ →
⟦ zipWith f xs ys′ ⟧P ≈
S.zipWith f ⟦ xs ⟧P (S.tail ⟦ ys ⟧P)
helper eq rewrite eq = zipWith-hom f xs ys′
|
{
"alphanum_fraction": 0.5810588622,
"avg_line_length": 32.3510638298,
"ext": "agda",
"hexsha": "58cb4a2b1ba8c42a7d15c67bac8a4aa738b63cb6",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "LargeCombinators.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "LargeCombinators.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "LargeCombinators.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1134,
"size": 3041
}
|
------------------------------------------------------------------------------
-- Inductive PA properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Inductive.PropertiesI where
open import PA.Inductive.Base
open import PA.Inductive.Relation.Binary.EqReasoning
------------------------------------------------------------------------------
-- Congruence properties
succCong : ∀ {m n} → m ≡ n → succ m ≡ succ n
succCong refl = refl
+-leftCong : ∀ {m n o} → m ≡ n → m + o ≡ n + o
+-leftCong refl = refl
+-rightCong : ∀ {m n o} → n ≡ o → m + n ≡ m + o
+-rightCong refl = refl
------------------------------------------------------------------------------
-- Peano's third axiom.
P₃ : ∀ {m n} → succ m ≡ succ n → m ≡ n
P₃ refl = refl
-- Peano's fourth axiom.
P₄ : ∀ {n} → zero ≢ succ n
P₄ ()
x≢Sx : ∀ {n} → n ≢ succ n
x≢Sx {zero} ()
x≢Sx {succ n} h = x≢Sx (P₃ h)
+-leftIdentity : ∀ n → zero + n ≡ n
+-leftIdentity n = refl
-- Adapted from the Agda standard library 0.8.1 (see
-- Data.Nat.Properties.Simple.+-rightIdentity).
+-rightIdentity : ∀ n → n + zero ≡ n
+-rightIdentity zero = refl
+-rightIdentity (succ n) = succCong (+-rightIdentity n)
-- Adapted from the Agda standard library_0.8.1 (see
-- Data.Nat.Properties.Simple.+-assoc).
+-assoc : ∀ m n o → m + n + o ≡ m + (n + o)
+-assoc zero _ _ = refl
+-assoc (succ m) n o = succCong (+-assoc m n o)
-- Adapted from the Agda standard library 0.8.1 (see
-- Data.Nat.Properties.Simple.+-suc).
x+Sy≡S[x+y] : ∀ m n → m + succ n ≡ succ (m + n)
x+Sy≡S[x+y] zero _ = refl
x+Sy≡S[x+y] (succ m) n = succCong (x+Sy≡S[x+y] m n)
-- Adapted from the Agda standard library 0.8.1 (see
-- Data.Nat.Properties.Simple.+-comm).
+-comm : ∀ m n → m + n ≡ n + m
+-comm zero n = sym (+-rightIdentity n)
+-comm (succ m) n = succ (m + n) ≡⟨ succCong (+-comm m n) ⟩
succ (n + m) ≡⟨ sym (x+Sy≡S[x+y] n m) ⟩
n + succ m ∎
|
{
"alphanum_fraction": 0.4857008908,
"avg_line_length": 31.3676470588,
"ext": "agda",
"hexsha": "e3e49b172bfc2261fefff8dca461596804f0b4e7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/PA/Inductive/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/PA/Inductive/PropertiesI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/PA/Inductive/PropertiesI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 672,
"size": 2133
}
|
open import Relation.Binary.Core
open import Level using (Level; _⊔_; suc)
open import Data.Product using (Σ; _×_; _,_; Σ-syntax; ∃-syntax; proj₁; proj₂)
open import Function
open import DeBruijn
open import Beta
open import Takahashi
open import Z
open import ConfluenceTakahashi using (lemma3-3; lemma3-5)
star-left : ∀ {n} {M L N : Term n}
→ M —→ L
→ Star _—→_ L N
-------------
→ Star _—→_ M N
star-left ML ε = ε ▻ ML
star-left ML (L*N′ ▻ N′N) =
star-left ML L*N′ ▻ N′N
betas-star : ∀ {n} {M N : Term n}
→ M —↠ N
-------------
→ Star _—→_ M N
betas-star (M ∎) = ε
betas-star (M —→⟨ M—→M′ ⟩ M′—↠N) =
star-left M—→M′ (betas-star M′—↠N)
z-confluence-beta : ∀ {n} → Confluence (_—→_ {n})
z-confluence-beta = z-confluence ( _*
, betas-star ∘ lemma3-3
, betas-star ∘ lemma3-5)
|
{
"alphanum_fraction": 0.5481651376,
"avg_line_length": 24.2222222222,
"ext": "agda",
"hexsha": "259554fdfa0af87a3868009398738bc74d809dce",
"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": "2fa17f7738cc7da967375be928137adc4be38696",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "iwilare/church-rosser",
"max_forks_repo_path": "ConfluenceZ.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696",
"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": "iwilare/church-rosser",
"max_issues_repo_path": "ConfluenceZ.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "2fa17f7738cc7da967375be928137adc4be38696",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "iwilare/church-rosser",
"max_stars_repo_path": "ConfluenceZ.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-22T01:43:09.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-06-02T07:27:54.000Z",
"num_tokens": 321,
"size": 872
}
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Values for standard evaluation with the Nehemiah plugin.
------------------------------------------------------------------------
module Nehemiah.Denotation.Value where
open import Nehemiah.Syntax.Type public
open import Nehemiah.Change.Type public
open import Base.Denotation.Notation public
open import Structure.Bag.Nehemiah
open import Data.Integer
import Parametric.Denotation.Value Base as Value
⟦_⟧Base : Value.Structure
⟦ base-int ⟧Base = ℤ
⟦ base-bag ⟧Base = Bag
open Value.Structure ⟦_⟧Base public
|
{
"alphanum_fraction": 0.605815832,
"avg_line_length": 26.9130434783,
"ext": "agda",
"hexsha": "7ad544b4cfe3b9943ad5a6d408bab8f6a5f8dec9",
"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": "Nehemiah/Denotation/Value.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": "Nehemiah/Denotation/Value.agda",
"max_line_length": 72,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Nehemiah/Denotation/Value.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": 132,
"size": 619
}
|
import Everything
open import Prelude
open import Container.Traversable
open import Container.Foldable
open import Container.List
open import Text.Parse
open import Text.Lex
open import Text.Printf
open import Control.Monad.State
open import Control.Monad.Transformer
open import Control.WellFounded
open import Builtin.Size
open import Builtin.Coinduction
open import Builtin.Float
open import Builtin.Reflection
open import Tactic.Reflection.DeBruijn
open import Tactic.Reflection.Equality
open import Tactic.Reflection.Free
open import Tactic.Reflection.Quote
open import Tactic.Reflection.Telescope
open import Tactic.Deriving.Eq
open import Tactic.Nat
open import Numeric.Nat.DivMod
open import Numeric.Nat.Divide
open import Numeric.Nat.GCD
open import Numeric.Nat.Prime
open import Numeric.Rational
open import Numeric.Nat.Modulo
open import Numeric.Nat.Pow
open import MonoidTactic
-- open import DeriveEqTest
Hello = printf "%c%s" 'H' "ello"
World = printf "%-7s(%.6f)" "World" π
M = StateT Nat IO
putStrI : String → StateT Nat IO Unit
putStrI s = do
n ← get
put (suc n)
lift (putStr (printf "[%d] %s\n" n s))
main : IO ⊤
main = do
runStateT (mapM putStrI (Hello ∷ World ∷ " " ∷ [])) 0
putStr (show (432429 divmod 41))
putStr ("\n" & show (gcd! (19 * 17 * 31) (31 * 5)))
putStrLn ""
downFrom : Nat → List Nat
downFrom zero = []
downFrom (suc n) = suc n ∷ downFrom n
thm : ∀ n → 6 * sumR (map (_^ 2) (downFrom n)) ≡ n * (n + 1) * (2 * n + 1)
thm = induction
thm₂ : (a b : Nat) → (a - b) * (a + b) ≡ a ^ 2 - b ^ 2
thm₂ a b = auto
data N : Set where
z : N
s : N → N
unquoteDecl eqN = deriveEq eqN (quote N)
|
{
"alphanum_fraction": 0.7113402062,
"avg_line_length": 22.9027777778,
"ext": "agda",
"hexsha": "46c410447a9e605e6f01d0bc9853ca79f91fbebe",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "test/Main.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "test/Main.agda",
"max_line_length": 74,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "test/Main.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 528,
"size": 1649
}
|
module Syntax.Number where
import Lvl
open import Logic.Propositional
open import Numeral.Natural
open import Type
record Numeral {ℓ} (T : Type{ℓ}) : Typeω where
field
{restriction-ℓ} : Lvl.Level
restriction : ℕ → Type{restriction-ℓ}
num : (n : ℕ) → ⦃ _ : restriction(n) ⦄ → T
open Numeral ⦃ ... ⦄ public using (num)
{-# BUILTIN FROMNAT num #-}
InfiniteNumeral = Numeral
module InfiniteNumeral {ℓ} {T : Type{ℓ}} where
intro : (ℕ → T) → InfiniteNumeral(T)
Numeral.restriction-ℓ (intro(_)) = Lvl.𝟎
Numeral.restriction (intro(_)) _ = ⊤
Numeral.num (intro(f)) n ⦃ _ ⦄ = f(n)
-- record InfiniteNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- record InfiniteNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- field
-- num : ℕ → T
-- instance
-- Numeral-from-InfiniteNumeral : ∀{ℓ}{T} → ⦃ _ : InfiniteNumeral{ℓ}(T) ⦄ → Numeral{ℓ}(T)
-- Numeral.restriction-ℓ ( Numeral-from-InfiniteNumeral ) = Lvl.𝟎
-- Numeral.restriction ( Numeral-from-InfiniteNumeral ) (_) = ⊤
-- num ⦃ Numeral-from-InfiniteNumeral ⦃ infNum ⦄ ⦄ (n) ⦃ _ ⦄ = InfiniteNumeral.num(infNum) (n)
instance
ℕ-InfiniteNumeral : InfiniteNumeral (ℕ)
ℕ-InfiniteNumeral = InfiniteNumeral.intro(id) where
id : ℕ → ℕ
id x = x
instance
Level-InfiniteNumeral : InfiniteNumeral (Lvl.Level)
Level-InfiniteNumeral = InfiniteNumeral.intro(f) where
f : ℕ → Lvl.Level
f(ℕ.𝟎) = Lvl.𝟎
f(ℕ.𝐒(n)) = Lvl.𝐒(f(n))
record NegativeNumeral {ℓ} (T : Type{ℓ}) : Typeω where
field
{restriction-ℓ} : Lvl.Level
restriction : ℕ → Type{restriction-ℓ}
num : (n : ℕ) → ⦃ _ : restriction(n) ⦄ → T
open NegativeNumeral ⦃ ... ⦄ public using () renaming (num to -num)
{-# BUILTIN FROMNEG -num #-}
InfiniteNegativeNumeral = NegativeNumeral
module InfiniteNegativeNumeral {ℓ} {T : Type{ℓ}} where
intro : (ℕ → T) → InfiniteNegativeNumeral(T)
NegativeNumeral.restriction-ℓ (intro(_)) = Lvl.𝟎
NegativeNumeral.restriction (intro(_)) _ = ⊤
NegativeNumeral.num (intro(f)) n ⦃ _ ⦄ = f(n)
-- record InfiniteNegativeNumeral {ℓ} (T : Type{ℓ}) : Type{ℓ} where
-- field
-- num : ℕ → T
-- open InfiniteNegativeNumeral ⦃ ... ⦄ public
-- instance
-- NegativeNumeral-from-InfiniteNegativeNumeral : ∀{ℓ}{T} → ⦃ _ : InfiniteNegativeNumeral{ℓ}(T) ⦄ → NegativeNumeral{ℓ}(T)
-- NegativeNumeral.restriction-ℓ ( NegativeNumeral-from-InfiniteNegativeNumeral ) = Lvl.𝟎
-- NegativeNumeral.restriction ( NegativeNumeral-from-InfiniteNegativeNumeral ) (_) = ⊤
-- -num ⦃ NegativeNumeral-from-InfiniteNegativeNumeral ⦃ infNegNum ⦄ ⦄ (n) ⦃ _ ⦄ = InfiniteNegativeNumeral.num(infNegNum) (n)
|
{
"alphanum_fraction": 0.6500948767,
"avg_line_length": 35.6081081081,
"ext": "agda",
"hexsha": "0d2281c71c10ca617259b49a2213bcd5318e1872",
"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": "Syntax/Number.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": "Syntax/Number.agda",
"max_line_length": 127,
"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": "Syntax/Number.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": 961,
"size": 2635
}
|
{-# OPTIONS --cubical --no-import-sorts --allow-unsolved-metas #-}
module Number.Operations.Specification where
open import Cubical.Foundations.Everything renaming (_⁻¹ to _⁻¹ᵖ; assoc to ∙-assoc)
open import Cubical.Data.Unit.Base -- Unit
open import Number.Postulates
open import Number.Base
open ℕⁿ
open ℤᶻ
open ℚᶠ
open ℝʳ
open ℂᶜ
open PatternsType
-- workflow:
-- 1. split on the both positivities at once
-- 2. add a general clause on top
-- 3. check file
-- 4. remove all unreachable clauses and goto 2.
-- feel free to remove too many clauses and let agda display the missing ones
+-Positivityᵒʳ : PositivityKindOrderedRing → PositivityKindOrderedRing → PositivityKindOrderedRing
+-Positivityᵒʳ _ X = X
+-Positivityᵒʳ X _ = X
+-Positivityᵒʳ _ X⁺⁻ = X
+-Positivityᵒʳ X⁺⁻ _ = X
-- clauses with same sign
+-Positivityᵒʳ X₀⁺ X₀⁺ = X₀⁺
+-Positivityᵒʳ X₀⁻ X₀⁻ = X₀⁻
+-Positivityᵒʳ X₀⁺ X⁺ = X⁺
+-Positivityᵒʳ X⁺ X₀⁺ = X⁺
+-Positivityᵒʳ X⁺ X⁺ = X⁺
+-Positivityᵒʳ X₀⁻ X⁻ = X⁻
+-Positivityᵒʳ X⁻ X⁻ = X⁻
+-Positivityᵒʳ X⁻ X₀⁻ = X⁻
-- remaining clauses with alternating sign
+-Positivityᵒʳ X₀⁻ X₀⁺ = X
+-Positivityᵒʳ X₀⁺ X₀⁻ = X
+-Positivityᵒʳ X⁻ X₀⁺ = X
+-Positivityᵒʳ X₀⁺ X⁻ = X
+-Positivityᵒʳ X⁻ X⁺ = X
+-Positivityᵒʳ X⁺ X⁻ = X
+-Positivityᵒʳ X₀⁻ X⁺ = X
+-Positivityᵒʳ X⁺ X₀⁻ = X
+-Positivityᶠ : PositivityKindField → PositivityKindField → PositivityKindField
-- positivity information is lost after _+_ on a field
+-Positivityᶠ x y = X
+-Positivityʰ : (l : NumberKind) → PositivityKindType l → PositivityKindType l → PositivityKindType l
+-Positivityʰ isNat = +-Positivityᵒʳ
+-Positivityʰ isInt = +-Positivityᵒʳ
+-Positivityʰ isRat = +-Positivityᵒʳ
+-Positivityʰ isReal = +-Positivityᵒʳ
+-Positivityʰ isComplex = +-Positivityᶠ
·-Positivityᵒʳ : PositivityKindOrderedRing → PositivityKindOrderedRing → PositivityKindOrderedRing
·-Positivityᵒʳ _ X = X
·-Positivityᵒʳ X _ = X
·-Positivityᵒʳ X₀⁺ X⁺⁻ = X
·-Positivityᵒʳ X⁺⁻ X₀⁺ = X
·-Positivityᵒʳ X₀⁻ X⁺⁻ = X
·-Positivityᵒʳ X⁺⁻ X₀⁻ = X
-- multiplying nonzero numbers gives a nonzero number
·-Positivityᵒʳ X⁺⁻ X⁺⁻ = X⁺⁻
·-Positivityᵒʳ X⁺ X⁺⁻ = X⁺⁻
·-Positivityᵒʳ X⁺⁻ X⁺ = X⁺⁻
·-Positivityᵒʳ X⁻ X⁺⁻ = X⁺⁻
·-Positivityᵒʳ X⁺⁻ X⁻ = X⁺⁻
-- multiplying positive numbers gives a positive number
·-Positivityᵒʳ X₀⁺ X₀⁺ = X₀⁺
·-Positivityᵒʳ X₀⁺ X⁺ = X₀⁺
·-Positivityᵒʳ X⁺ X₀⁺ = X₀⁺
·-Positivityᵒʳ X⁺ X⁺ = X⁺
-- multiplying negative numbers gives a positive number
·-Positivityᵒʳ X₀⁻ X⁻ = X₀⁺
·-Positivityᵒʳ X⁻ X₀⁻ = X₀⁺
·-Positivityᵒʳ X₀⁻ X₀⁻ = X₀⁺
·-Positivityᵒʳ X⁻ X⁻ = X⁺
-- multiplying a positive and a negative number gives a negative number
·-Positivityᵒʳ X⁻ X₀⁺ = X₀⁻
·-Positivityᵒʳ X₀⁺ X⁻ = X₀⁻
·-Positivityᵒʳ X₀⁻ X⁺ = X₀⁻
·-Positivityᵒʳ X⁺ X₀⁻ = X₀⁻
·-Positivityᵒʳ X₀⁻ X₀⁺ = X₀⁻
·-Positivityᵒʳ X₀⁺ X₀⁻ = X₀⁻
·-Positivityᵒʳ X⁻ X⁺ = X⁻
·-Positivityᵒʳ X⁺ X⁻ = X⁻
·-Positivityᶠ : PositivityKindField → PositivityKindField → PositivityKindField
·-Positivityᶠ X X = X
·-Positivityᶠ X X⁺⁻ = X
·-Positivityᶠ X⁺⁻ X = X
-- multiplying nonzero numbers gives a nonzero number
·-Positivityᶠ X⁺⁻ X⁺⁻ = X⁺⁻
·-Positivityʰ : (l : NumberKind) → PositivityKindType l → PositivityKindType l → PositivityKindType l
·-Positivityʰ isNat = ·-Positivityᵒʳ
·-Positivityʰ isInt = ·-Positivityᵒʳ
·-Positivityʰ isRat = ·-Positivityᵒʳ
·-Positivityʰ isReal = ·-Positivityᵒʳ
·-Positivityʰ isComplex = ·-Positivityᶠ
min-Positivityᵒʳ : PositivityKindOrderedRing → PositivityKindOrderedRing → PositivityKindOrderedRing
min-Positivityᵒʳ X X = X
min-Positivityᵒʳ X X⁺⁻ = X
min-Positivityᵒʳ X X₀⁺ = X
min-Positivityᵒʳ X X⁺ = X
min-Positivityᵒʳ X X⁻ = X⁻
min-Positivityᵒʳ X X₀⁻ = X₀⁻
min-Positivityᵒʳ X⁺⁻ X = X
min-Positivityᵒʳ X⁺⁻ X⁺⁻ = X⁺⁻
min-Positivityᵒʳ X⁺⁻ X₀⁺ = X
min-Positivityᵒʳ X⁺⁻ X⁺ = X⁺⁻
min-Positivityᵒʳ X⁺⁻ X⁻ = X⁻
min-Positivityᵒʳ X⁺⁻ X₀⁻ = X₀⁻
min-Positivityᵒʳ X₀⁺ X = X
min-Positivityᵒʳ X₀⁺ X⁺⁻ = X
min-Positivityᵒʳ X₀⁺ X₀⁺ = X₀⁺
min-Positivityᵒʳ X₀⁺ X⁺ = X₀⁺
min-Positivityᵒʳ X₀⁺ X⁻ = X⁻
min-Positivityᵒʳ X₀⁺ X₀⁻ = X₀⁻
min-Positivityᵒʳ X⁺ X = X
min-Positivityᵒʳ X⁺ X⁺⁻ = X⁺⁻
min-Positivityᵒʳ X⁺ X₀⁺ = X₀⁺
min-Positivityᵒʳ X⁺ X⁺ = X⁺
min-Positivityᵒʳ X⁺ X⁻ = X⁻
min-Positivityᵒʳ X⁺ X₀⁻ = X₀⁻
min-Positivityᵒʳ X⁻ X = X⁻
min-Positivityᵒʳ X⁻ X⁺⁻ = X⁻
min-Positivityᵒʳ X⁻ X₀⁺ = X⁻
min-Positivityᵒʳ X⁻ X⁺ = X⁻
min-Positivityᵒʳ X⁻ X⁻ = X⁻
min-Positivityᵒʳ X⁻ X₀⁻ = X⁻
min-Positivityᵒʳ X₀⁻ X = X₀⁻
min-Positivityᵒʳ X₀⁻ X⁺⁻ = X₀⁻
min-Positivityᵒʳ X₀⁻ X₀⁺ = X₀⁻
min-Positivityᵒʳ X₀⁻ X⁺ = X₀⁻
min-Positivityᵒʳ X₀⁻ X⁻ = X⁻
min-Positivityᵒʳ X₀⁻ X₀⁻ = X₀⁻
max-Positivityᵒʳ : PositivityKindOrderedRing → PositivityKindOrderedRing → PositivityKindOrderedRing
max-Positivityᵒʳ X X = X
max-Positivityᵒʳ X X⁺⁻ = X
max-Positivityᵒʳ X X₀⁺ = X₀⁺
max-Positivityᵒʳ X X⁺ = X⁺
max-Positivityᵒʳ X X⁻ = X
max-Positivityᵒʳ X X₀⁻ = X
max-Positivityᵒʳ X⁺⁻ X = X
max-Positivityᵒʳ X⁺⁻ X⁺⁻ = X⁺⁻
max-Positivityᵒʳ X⁺⁻ X₀⁺ = X₀⁺
max-Positivityᵒʳ X⁺⁻ X⁺ = X⁺
max-Positivityᵒʳ X⁺⁻ X⁻ = X⁺⁻
max-Positivityᵒʳ X⁺⁻ X₀⁻ = X
max-Positivityᵒʳ X₀⁺ X = X₀⁺
max-Positivityᵒʳ X₀⁺ X⁺⁻ = X₀⁺
max-Positivityᵒʳ X₀⁺ X₀⁺ = X₀⁺
max-Positivityᵒʳ X₀⁺ X⁺ = X⁺
max-Positivityᵒʳ X₀⁺ X⁻ = X₀⁺
max-Positivityᵒʳ X₀⁺ X₀⁻ = X₀⁺
max-Positivityᵒʳ X⁺ X = X⁺
max-Positivityᵒʳ X⁺ X⁺⁻ = X⁺
max-Positivityᵒʳ X⁺ X₀⁺ = X⁺
max-Positivityᵒʳ X⁺ X⁺ = X⁺
max-Positivityᵒʳ X⁺ X⁻ = X⁺
max-Positivityᵒʳ X⁺ X₀⁻ = X⁺
max-Positivityᵒʳ X⁻ X = X
max-Positivityᵒʳ X⁻ X⁺⁻ = X⁺⁻
max-Positivityᵒʳ X⁻ X₀⁺ = X₀⁺
max-Positivityᵒʳ X⁻ X⁺ = X⁺
max-Positivityᵒʳ X⁻ X⁻ = X⁻
max-Positivityᵒʳ X⁻ X₀⁻ = X₀⁻
max-Positivityᵒʳ X₀⁻ X = X
max-Positivityᵒʳ X₀⁻ X⁺⁻ = X
max-Positivityᵒʳ X₀⁻ X₀⁺ = X₀⁺
max-Positivityᵒʳ X₀⁻ X⁺ = X⁺
max-Positivityᵒʳ X₀⁻ X⁻ = X₀⁻
max-Positivityᵒʳ X₀⁻ X₀⁻ = X₀⁻
min-Positivityʰ : (l : NumberKind) → PositivityKindType l → PositivityKindType l → PositivityKindType l
min-Positivityʰ isNat = min-Positivityᵒʳ
min-Positivityʰ isInt = min-Positivityᵒʳ
min-Positivityʰ isRat = min-Positivityᵒʳ
min-Positivityʰ isReal = min-Positivityᵒʳ
min-Positivityʰ isComplex = λ _ _ → X -- doesn't matter since `min` is undefined for ℂ
max-Positivityʰ : (l : NumberKind) → PositivityKindType l → PositivityKindType l → PositivityKindType l
max-Positivityʰ isNat = max-Positivityᵒʳ
max-Positivityʰ isInt = max-Positivityᵒʳ
max-Positivityʰ isRat = max-Positivityᵒʳ
max-Positivityʰ isReal = max-Positivityᵒʳ
max-Positivityʰ isComplex = λ _ _ → X -- doesn't matter since `max` is undefined for ℂ
+-Types : NumberProp → NumberProp → NumberProp
+-Types (level₀ , pos₀) (level₁ , pos₁) =
let level = maxₙₗ level₀ level₁
in level , +-Positivityʰ level (coerce-PositivityKind level₀ level pos₀) (coerce-PositivityKind level₁ level pos₁)
·-Types : NumberProp → NumberProp → NumberProp
·-Types (level₀ , pos₀) (level₁ , pos₁) =
let level = maxₙₗ level₀ level₁
in level , ·-Positivityʰ level (coerce-PositivityKind level₀ level pos₀) (coerce-PositivityKind level₁ level pos₁)
⁻¹-Types : ∀{l p} → Number (l , p) → Type (ℓ-max (NumberLevel (maxₙₗ l isRat)) (NumberKindProplevel l))
-- numbers that can be zero need an additional apartness proof
⁻¹-Types {isNat } {X } (x ,, p) = ∀{{ q : x #ⁿ 0ⁿ }} → Number (isRat , X⁺⁻)
⁻¹-Types {isInt } {X } (x ,, p) = ∀{{ q : x #ᶻ 0ᶻ }} → Number (isRat , X⁺⁻)
⁻¹-Types {isRat } {X } (x ,, p) = ∀{{ q : x #ᶠ 0ᶠ }} → Number (isRat , X⁺⁻)
⁻¹-Types {isReal } {X } (x ,, p) = ∀{{ q : x #ʳ 0ʳ }} → Number (isReal , X⁺⁻)
⁻¹-Types {isComplex} {X } (x ,, p) = ∀{{ q : x #ᶜ 0ᶜ }} → Number (isComplex , X⁺⁻)
⁻¹-Types {isNat } {X₀⁺} (x ,, p) = ∀{{ q : x #ⁿ 0ⁿ }} → Number (isRat , X⁺ )
⁻¹-Types {isInt } {X₀⁺} (x ,, p) = ∀{{ q : x #ᶻ 0ᶻ }} → Number (isRat , X⁺ )
⁻¹-Types {isRat } {X₀⁺} (x ,, p) = ∀{{ q : x #ᶠ 0ᶠ }} → Number (isRat , X⁺ )
⁻¹-Types {isReal } {X₀⁺} (x ,, p) = ∀{{ q : x #ʳ 0ʳ }} → Number (isReal , X⁺ )
⁻¹-Types {isNat } {X₀⁻} (x ,, p) = ∀{{ q : x #ⁿ 0ⁿ }} → Number (isRat , X⁻ )
⁻¹-Types {isInt } {X₀⁻} (x ,, p) = ∀{{ q : x #ᶻ 0ᶻ }} → Number (isRat , X⁻ )
⁻¹-Types {isRat } {X₀⁻} (x ,, p) = ∀{{ q : x #ᶠ 0ᶠ }} → Number (isRat , X⁻ )
⁻¹-Types {isReal } {X₀⁻} (x ,, p) = ∀{{ q : x #ʳ 0ʳ }} → Number (isReal , X⁻ )
-- positive, negative and nonzero numbers are already apart from zero
⁻¹-Types {isNat } {X⁺⁻} (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isNat } Unit }} → Number (isRat , X⁺⁻)
⁻¹-Types {isNat } {X⁺ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isNat } Unit }} → Number (isRat , X⁺ )
⁻¹-Types {isInt } {X⁺⁻} (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isInt } Unit }} → Number (isRat , X⁺⁻)
⁻¹-Types {isInt } {X⁺ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isInt } Unit }} → Number (isRat , X⁺ )
⁻¹-Types {isInt } {X⁻ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isInt } Unit }} → Number (isRat , X⁻ )
⁻¹-Types {isRat } {X⁺⁻} (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isRat } Unit }} → Number (isRat , X⁺⁻)
⁻¹-Types {isRat } {X⁺ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isRat } Unit }} → Number (isRat , X⁺ )
⁻¹-Types {isRat } {X⁻ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isRat } Unit }} → Number (isRat , X⁻ )
⁻¹-Types {isReal } {X⁺⁻} (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isReal } Unit }} → Number (isReal , X⁺⁻)
⁻¹-Types {isReal } {X⁺ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isReal } Unit }} → Number (isReal , X⁺ )
⁻¹-Types {isReal } {X⁻ } (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isReal } Unit }} → Number (isReal , X⁻ )
⁻¹-Types {isComplex} {X⁺⁻} (x ,, p) = ∀{{ q : Lift {j = NumberKindProplevel isComplex} Unit }} → Number (isComplex , X⁺⁻)
-Types : ∀{l p} → Number (l , p) → Type (NumberLevel (maxₙₗ l isInt))
-Types {isInt } {X } (x ,, p) = Number (isInt , X)
-Types {isRat } {X } (x ,, p) = Number (isRat , X)
-Types {isReal } {X } (x ,, p) = Number (isReal , X)
-Types {isComplex} {X } (x ,, p) = Number (isComplex , X)
-- the negative of a natural number is a Nonpositive integer
-Types {isNat } {X } (x ,, p) = Number (isInt , X₀⁻)
-- the negative of a nonzero number is a nonzero number
-Types {isNat } {X⁺⁻} (x ,, p) = Number (isInt , X⁺⁻)
-Types {isInt } {X⁺⁻} (x ,, p) = Number (isInt , X⁺⁻)
-Types {isRat } {X⁺⁻} (x ,, p) = Number (isRat , X⁺⁻)
-Types {isReal } {X⁺⁻} (x ,, p) = Number (isReal , X⁺⁻)
-Types {isComplex} {X⁺⁻} (x ,, p) = Number (isComplex , X⁺⁻)
-- the negative of a positive number is a negative number
-Types {isNat } {X₀⁺} (x ,, p) = Number (isInt , X₀⁻)
-Types {isInt } {X₀⁺} (x ,, p) = Number (isInt , X₀⁻)
-Types {isRat } {X₀⁺} (x ,, p) = Number (isRat , X₀⁻)
-Types {isReal } {X₀⁺} (x ,, p) = Number (isReal , X₀⁻)
-Types {isNat } {X⁺ } (x ,, p) = Number (isInt , X⁻ )
-Types {isInt } {X⁺ } (x ,, p) = Number (isInt , X⁻ )
-Types {isRat } {X⁺ } (x ,, p) = Number (isRat , X⁻ )
-Types {isReal } {X⁺ } (x ,, p) = Number (isReal , X⁻ )
-- the negative of a negative number is a positive number
-Types {isNat } {X₀⁻} (x ,, p) = Number (isInt , X₀⁺)
-Types {isInt } {X₀⁻} (x ,, p) = Number (isInt , X₀⁺)
-Types {isRat } {X₀⁻} (x ,, p) = Number (isRat , X₀⁺)
-Types {isReal } {X₀⁻} (x ,, p) = Number (isReal , X₀⁺)
-Types {isInt } {X⁻ } (x ,, p) = Number (isInt , X⁺ )
-Types {isRat } {X⁻ } (x ,, p) = Number (isRat , X⁺ )
-Types {isReal } {X⁻ } (x ,, p) = Number (isReal , X⁺ )
abs-Types : ∀{l p} → Number (l , p) → Type (NumberLevel (minₙₗ l isReal))
abs-Types {isNat } {X } (x ,, p) = Number (isNat , X₀⁺)
abs-Types {isNat } {X⁺⁻} (x ,, p) = Number (isNat , X⁺ )
abs-Types {isNat } {X₀⁺} (x ,, p) = Number (isNat , X₀⁺)
abs-Types {isNat } {X⁺ } (x ,, p) = Number (isNat , X⁺ )
abs-Types {isNat } {X₀⁻} (x ,, p) = Number (isNat , X₀⁺)
abs-Types {isInt } {X } (x ,, p) = Number (isInt , X₀⁺)
abs-Types {isInt } {X⁺⁻} (x ,, p) = Number (isInt , X⁺ )
abs-Types {isInt } {X₀⁺} (x ,, p) = Number (isInt , X₀⁺)
abs-Types {isInt } {X⁺ } (x ,, p) = Number (isInt , X⁺ )
abs-Types {isInt } {X⁻ } (x ,, p) = Number (isInt , X⁺ )
abs-Types {isInt } {X₀⁻} (x ,, p) = Number (isInt , X₀⁺)
abs-Types {isRat } {X } (x ,, p) = Number (isRat , X₀⁺)
abs-Types {isRat } {X⁺⁻} (x ,, p) = Number (isRat , X⁺ )
abs-Types {isRat } {X₀⁺} (x ,, p) = Number (isRat , X₀⁺)
abs-Types {isRat } {X⁺ } (x ,, p) = Number (isRat , X⁺ )
abs-Types {isRat } {X⁻ } (x ,, p) = Number (isRat , X⁺ )
abs-Types {isRat } {X₀⁻} (x ,, p) = Number (isRat , X₀⁺)
abs-Types {isReal } {X } (x ,, p) = Number (isReal , X₀⁺)
abs-Types {isReal } {X⁺⁻} (x ,, p) = Number (isReal , X⁺ )
abs-Types {isReal } {X₀⁺} (x ,, p) = Number (isReal , X₀⁺)
abs-Types {isReal } {X⁺ } (x ,, p) = Number (isReal , X⁺ )
abs-Types {isReal } {X⁻ } (x ,, p) = Number (isReal , X⁺ )
abs-Types {isReal } {X₀⁻} (x ,, p) = Number (isReal , X₀⁺)
abs-Types {isComplex} {X } (x ,, p) = Number (isReal , X₀⁺)
abs-Types {isComplex} {X⁺⁻} (x ,, p) = Number (isReal , X⁺ )
|
{
"alphanum_fraction": 0.589893977,
"avg_line_length": 45.3890784983,
"ext": "agda",
"hexsha": "04ed442343906bbba934b24050f0868e2c6dd7d6",
"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/Number/Operations/Specification.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/Number/Operations/Specification.agda",
"max_line_length": 121,
"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/Number/Operations/Specification.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": 6660,
"size": 13299
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Category.Equivalence where
-- Strong equivalence of categories. Same as ordinary equivalence in Cat.
-- May not include everything we'd like to think of as equivalences, namely
-- the full, faithful functors that are essentially surjective on objects.
open import Level
open import Relation.Binary using (IsEquivalence; Setoid)
open import Categories.Adjoint.Equivalence
open import Categories.Category
import Categories.Morphism.Reasoning as MR
import Categories.Morphism.Properties as MP
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Properties
open import Categories.NaturalTransformation using (ntHelper; _∘ᵥ_; _∘ˡ_; _∘ʳ_)
open import Categories.NaturalTransformation.NaturalIsomorphism as NI
using (NaturalIsomorphism ; unitorˡ; unitorʳ; associator; _ⓘᵥ_; _ⓘˡ_; _ⓘʳ_)
renaming (sym to ≃-sym)
open import Categories.NaturalTransformation.NaturalIsomorphism.Properties
private
variable
o ℓ e : Level
C D E : Category o ℓ e
record WeakInverse (F : Functor C D) (G : Functor D C) : Set (levelOfTerm F ⊔ levelOfTerm G) where
field
F∘G≈id : NaturalIsomorphism (F ∘F G) idF
G∘F≈id : NaturalIsomorphism (G ∘F F) idF
module F∘G≈id = NaturalIsomorphism F∘G≈id
module G∘F≈id = NaturalIsomorphism G∘F≈id
private
module C = Category C
module D = Category D
module F = Functor F
module G = Functor G
-- adjoint equivalence
F⊣G : ⊣Equivalence F G
F⊣G = record
{ unit = ≃-sym G∘F≈id
; counit =
let open D
open HomReasoning
open MR D
open MP D
in record
{ F⇒G = ntHelper record
{ η = λ X → F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
; commute = λ {X Y} f → begin
(F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ Y))) ∘ F.F₁ (G.F₁ f)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G.F₁ f))) ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X)))
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ Y) C.∘ G.F₁ (F.F₁ (G.F₁ f))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G.F₁ f)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η Y ∘ F.F₁ (G.F₁ f C.∘ G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ refl ⟩∘⟨ F.homomorphism ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η Y ∘ (F.F₁ (G.F₁ f) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ center⁻¹ (F∘G≈id.⇒.commute f) refl ⟩
(f ∘ F∘G≈id.⇒.η X) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
≈⟨ assoc ⟩
f ∘ F∘G≈id.⇒.η X ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ X)) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ X))
∎
}
; F⇐G = ntHelper record
{ η = λ X → (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
; commute = λ {X Y} f → begin
((F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F∘G≈id.⇐.η Y) ∘ f
≈⟨ pullʳ (F∘G≈id.⇐.commute f) ⟩
(F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y))) ∘ F.F₁ (G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ center (⟺ F.homomorphism) ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ Y) C.∘ G.F₁ f) ∘ F∘G≈id.⇐.η X
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇐.commute (G.F₁ f)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ F.F₁ (G.F₁ (F.F₁ (G.F₁ f)) C.∘ G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ refl ⟩∘⟨ F.homomorphism ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ (G.F₀ Y)) ∘ (F.F₁ (G.F₁ (F.F₁ (G.F₁ f))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
≈⟨ center⁻¹ (F∘G≈id.⇒.commute _) refl ⟩
(F.F₁ (G.F₁ f) ∘ F∘G≈id.⇒.η (F.F₀ (G.F₀ X))) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X)) ∘ F∘G≈id.⇐.η X
≈⟨ center refl ⟩
F.F₁ (G.F₁ f) ∘ (F∘G≈id.⇒.η (F.F₀ (G.F₀ X)) ∘ F.F₁ (G∘F≈id.⇐.η (G.F₀ X))) ∘ F∘G≈id.⇐.η X
∎
}
; iso = λ X → Iso-∘ (Iso-∘ (Iso-swap (F∘G≈id.iso _)) ([ F ]-resp-Iso (G∘F≈id.iso _)))
(F∘G≈id.iso X)
}
; zig = λ {A} →
let open D
open HomReasoning
open MR D
in begin
(F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘ F∘G≈id.⇐.η (F.F₀ (G.F₀ (F.F₀ A))))
∘ F.F₁ (G∘F≈id.⇐.η A)
≈⟨ pull-last (F∘G≈id.⇐.commute (F.F₁ (G∘F≈id.⇐.η A))) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A))) ∘
F.F₁ (G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈˘⟨ refl⟩∘⟨ pushˡ F.homomorphism ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇒.η (G.F₀ (F.F₀ A)) C.∘ G.F₁ (F.F₁ (G∘F≈id.⇐.η A))) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl ⟩∘⟨ F.F-resp-≈ (G∘F≈id.⇒.commute (G∘F≈id.⇐.η A)) ⟩∘⟨ refl ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F.F₁ (G∘F≈id.⇐.η A C.∘ G∘F≈id.⇒.η A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ refl ⟩∘⟨ elimˡ ((F.F-resp-≈ (G∘F≈id.iso.isoˡ _)) ○ F.identity) ⟩
F∘G≈id.⇒.η (F.F₀ A) ∘ F∘G≈id.⇐.η (F.F₀ A)
≈⟨ F∘G≈id.iso.isoʳ _ ⟩
id
∎
}
module F⊣G = ⊣Equivalence F⊣G
record StrongEquivalence {o ℓ e o′ ℓ′ e′} (C : Category o ℓ e) (D : Category o′ ℓ′ e′) : Set (o ⊔ ℓ ⊔ e ⊔ o′ ⊔ ℓ′ ⊔ e′) where
field
F : Functor C D
G : Functor D C
weak-inverse : WeakInverse F G
open WeakInverse weak-inverse public
refl : StrongEquivalence C C
refl = record
{ F = idF
; G = idF
; weak-inverse = record
{ F∘G≈id = unitorˡ
; G∘F≈id = unitorˡ
}
}
sym : StrongEquivalence C D → StrongEquivalence D C
sym e = record
{ F = G
; G = F
; weak-inverse = record
{ F∘G≈id = G∘F≈id
; G∘F≈id = F∘G≈id
}
}
where open StrongEquivalence e
trans : StrongEquivalence C D → StrongEquivalence D E → StrongEquivalence C E
trans {C = C} {D = D} {E = E} e e′ = record
{ F = e′.F ∘F e.F
; G = e.G ∘F e′.G
; weak-inverse = record
{ F∘G≈id = let module S = Setoid (NI.Functor-NI-setoid E E)
in S.trans (S.trans (associator (e.G ∘F e′.G) e.F e′.F)
(e′.F ⓘˡ (unitorˡ ⓘᵥ (e.F∘G≈id ⓘʳ e′.G) ⓘᵥ NI.sym (associator e′.G e.G e.F))))
e′.F∘G≈id
; G∘F≈id = let module S = Setoid (NI.Functor-NI-setoid C C)
in S.trans (S.trans (associator (e′.F ∘F e.F) e′.G e.G)
(e.G ⓘˡ (unitorˡ ⓘᵥ (e′.G∘F≈id ⓘʳ e.F) ⓘᵥ NI.sym (associator e.F e′.F e′.G))))
e.G∘F≈id
}
}
where module e = StrongEquivalence e
module e′ = StrongEquivalence e′
isEquivalence : ∀ {o ℓ e} → IsEquivalence (StrongEquivalence {o} {ℓ} {e})
isEquivalence = record
{ refl = refl
; sym = sym
; trans = trans
}
setoid : ∀ o ℓ e → Setoid _ _
setoid o ℓ e = record
{ Carrier = Category o ℓ e
; _≈_ = StrongEquivalence
; isEquivalence = isEquivalence
}
|
{
"alphanum_fraction": 0.4899929028,
"avg_line_length": 40.2571428571,
"ext": "agda",
"hexsha": "d19830b7765e29cdd8d9547bb5e698fdd16f44fc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Taneb/agda-categories",
"max_forks_repo_path": "Categories/Category/Equivalence.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Taneb/agda-categories",
"max_issues_repo_path": "Categories/Category/Equivalence.agda",
"max_line_length": 125,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6ebc1349ee79669c5c496dcadd551d5bbefd1972",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Taneb/agda-categories",
"max_stars_repo_path": "Categories/Category/Equivalence.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3575,
"size": 7045
}
|
module nodcap.LocalChoice where
open import Algebra
open import Data.Nat as ℕ using (ℕ; suc; zero)
open import Data.Pos as ℕ⁺
open import Data.List as L using (List; []; _∷_; _++_)
open import Data.List.Any as LA using (Any; here; there)
open import Data.List.Any.BagAndSetEquality as B
open import Data.Product as PR using (∃; _×_; _,_; proj₁; proj₂)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Function using (_$_; flip)
open import Function.Equality using (_⟨$⟩_)
open import Function.Inverse as I using ()
open import Relation.Binary.PropositionalEquality as P using (_≡_; _≢_)
open import Data.Environment
open import nodcap.Base
open import nodcap.Typing
open I.Inverse using (to; from)
private module ++ {a} {A : Set a} = Monoid (L.monoid A)
-- We define local choice as follows:
_or_ : {A : Type} → ⊢ A ∷ [] → ⊢ A ∷ [] → ⊢ A ∷ []
x or y = cut (pool (in? x) (in? y)) out
where
in? : ∀ {A} → ⊢ A ∷ [] → ⊢ ![ suc 0 ] (𝟏 & A) ∷ []
in? x = mk!₁ $ case halt x
out : ∀ {A} → ⊢ ?[ suc 1 ] (⊥ ⊕ (A ^)) ∷ A ∷ []
out = cont $ mk?₁ $ sel₁ $ wait $ mk?₁ $ sel₂ $ exch (bbl []) $ ax
-- However, Luís Caires defines local choice with contexts. For this to work we
-- need an additional trick: conversion between contexts and types.
-- We can represent a context as a sequence of pars.
⅋[_] : Environment → Type
⅋[ [] ] = ⊥
⅋[ A ∷ Γ ] = A ⅋ ⅋[ Γ ]
-- See:
recv⋆ : {Γ Δ : Environment} →
⊢ Γ ++ Δ →
------------
⊢ ⅋[ Γ ] ∷ Δ
recv⋆ {[]} x = wait x
recv⋆ {A ∷ Γ} x = recv $ exch (bbl []) $ recv⋆ $ exch (bwd [] Γ) $ x
-- In order to reverse this, we need to show that the `recv` rule is invertible.
-- Fortunately, it is:
recv⁻¹ : {Γ : Environment} {A B : Type} →
⊢ A ⅋ B ∷ Γ →
-------------
⊢ A ∷ B ∷ Γ
recv⁻¹ {Γ} {A} {B} x
= exch (swp₂ (A ∷ B ∷ []))
$ cut {Γ} {A ∷ B ∷ []} x
$ send
( exch (bbl []) ax )
( exch (bbl []) ax )
-- It should come as no surprise that the repeated application of `recv` is also
-- invertible.
recv⋆⁻¹ : {Γ Δ : Environment} →
⊢ ⅋[ Γ ] ∷ Δ →
--------------
⊢ Γ ++ Δ
recv⋆⁻¹ {[]} x = cut halt x
recv⋆⁻¹ {A ∷ Γ} x = exch (fwd [] Γ) $ recv⋆⁻¹ {Γ} $ exch (bbl []) $ recv⁻¹ x
-- Using these additional derivable operators, we can represent the version of
-- local choice as used by Luís Caires:
_or⋆_ : {Γ : Environment} → ⊢ Γ → ⊢ Γ → ⊢ Γ
_or⋆_ {Γ} x y
= P.subst ⊢_ (proj₂ ++.identity Γ)
$ recv⋆⁻¹ {Γ}
$ ( recv⋆ $ P.subst ⊢_ (P.sym $ proj₂ ++.identity Γ) x )
or ( recv⋆ $ P.subst ⊢_ (P.sym $ proj₂ ++.identity Γ) y )
-- -}
-- -}
-- -}
-- -}
-- -}
|
{
"alphanum_fraction": 0.5650470219,
"avg_line_length": 28.043956044,
"ext": "agda",
"hexsha": "6b796591f67c270ce69c8bf28f0a0a4caf675e41",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/nodcap/LocalChoice.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/nodcap/LocalChoice.agda",
"max_line_length": 80,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/nodcap/LocalChoice.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 992,
"size": 2552
}
|
-- In this file we consider the special of localising at a single
-- element f : R (or rather the set of powers of f). This is also
-- known as inverting f.
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Localisation.InvertingElements where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Powerset
open import Cubical.Foundations.Transport
open import Cubical.Functions.FunExtEquiv
import Cubical.Data.Empty as ⊥
open import Cubical.Data.Bool
open import Cubical.Data.Nat renaming ( _+_ to _+ℕ_ ; _·_ to _·ℕ_
; +-comm to +ℕ-comm ; +-assoc to +ℕ-assoc
; ·-assoc to ·ℕ-assoc ; ·-comm to ·ℕ-comm)
open import Cubical.Data.Vec
open import Cubical.Data.Sigma.Base
open import Cubical.Data.Sigma.Properties
open import Cubical.Data.FinData
open import Cubical.Relation.Nullary
open import Cubical.Relation.Binary
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.CommRing.Localisation.Base
open import Cubical.Algebra.CommRing.Localisation.UniversalProperty
open import Cubical.HITs.SetQuotients as SQ
open import Cubical.HITs.PropositionalTruncation as PT
open Iso
private
variable
ℓ ℓ' : Level
A : Type ℓ
module _(R' : CommRing {ℓ}) where
open isMultClosedSubset
private R = R' .fst
-- open CommRingStr ⦃...⦄
open CommRingStr (R' .snd)
open Exponentiation R'
[_ⁿ|n≥0] : R → ℙ R
[ f ⁿ|n≥0] g = (∃[ n ∈ ℕ ] g ≡ f ^ n) , propTruncIsProp
-- Σ[ n ∈ ℕ ] (s ≡ f ^ n) × (∀ m → s ≡ f ^ m → n ≤ m) maybe better, this isProp:
-- (n,s≡fⁿ,p) (m,s≡fᵐ,q) then n≤m by p and m≤n by q => n≡m
powersFormMultClosedSubset : (f : R) → isMultClosedSubset R' [ f ⁿ|n≥0]
powersFormMultClosedSubset f .containsOne = ∣ zero , refl ∣
powersFormMultClosedSubset f .multClosed =
PT.map2 λ (m , p) (n , q) → (m +ℕ n) , (λ i → (p i) · (q i)) ∙ ·-of-^-is-^-of-+ f m n
R[1/_] : R → Type ℓ
R[1/ f ] = Loc.S⁻¹R R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
R[1/_]AsCommRing : R → CommRing {ℓ}
R[1/ f ]AsCommRing = Loc.S⁻¹RAsCommRing R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
-- A useful lemma: (gⁿ/1)≡(g/1)ⁿ in R[1/f]
^-respects-/1 : {f g : R} (n : ℕ) → [ (g ^ n) , 1r , ∣ 0 , (λ _ → 1r) ∣ ] ≡
Exponentiation._^_ R[1/ f ]AsCommRing [ g , 1r , powersFormMultClosedSubset _ .containsOne ] n
^-respects-/1 zero = refl
^-respects-/1 {f} {g} (suc n) = eq/ _ _ ( (1r , powersFormMultClosedSubset f .containsOne)
, cong (1r · (g · (g ^ n)) ·_) (·-lid 1r))
∙ cong (CommRingStr._·_ (R[1/ f ]AsCommRing .snd)
[ g , 1r , powersFormMultClosedSubset f .containsOne ]) (^-respects-/1 n)
-- A slight improvement for eliminating into propositions
InvElPropElim : {f : R} {P : R[1/ f ] → Type ℓ'}
→ (∀ x → isProp (P x))
→ (∀ (r : R) (n : ℕ) → P [ r , (f ^ n) , ∣ n , refl ∣ ])
----------------------------------------------------------
→ (∀ x → P x)
InvElPropElim {f = f} {P = P} PisProp base = elimProp (λ _ → PisProp _) []-case
where
S[f] = Loc.S R' [ f ⁿ|n≥0] (powersFormMultClosedSubset f)
[]-case : (a : R × S[f]) → P [ a ]
[]-case (r , s , s∈S[f]) = PT.rec (PisProp _) Σhelper s∈S[f]
where
Σhelper : Σ[ n ∈ ℕ ] s ≡ f ^ n → P [ r , s , s∈S[f] ]
Σhelper (n , p) = subst P (cong [_] (≡-× refl (Σ≡Prop (λ _ → propTruncIsProp) (sym p)))) (base r n)
|
{
"alphanum_fraction": 0.6123188406,
"avg_line_length": 39.8350515464,
"ext": "agda",
"hexsha": "2af1a491f0b1a5cdb9634d82cbfc085cfd7367a8",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Schippmunk/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Schippmunk/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_line_length": 102,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c345dc0c49d3950dc57f53ca5f7099bb53a4dc3a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Schippmunk/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Localisation/InvertingElements.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1342,
"size": 3864
}
|
module IIDg where
open import LF
-- Codes for indexed inductive types
data OPg (I : Set) : Set1 where
ι : I -> OPg I
σ : (A : Set)(γ : A -> OPg I) -> OPg I
δ : (H : Set)(i : H -> I)(γ : OPg I) -> OPg I
-- The top-level structure of values in an IIDg
Args : {I : Set}(γ : OPg I)(U : I -> Set) -> Set
Args (ι _) U = One
Args (σ A γ) U = A × \a -> Args (γ a) U
Args (δ H i γ) U = ((x : H) -> U (i x)) × \_ -> Args γ U
-- The index of a value in an IIDg
Index : {I : Set}(γ : OPg I)(U : I -> Set) -> Args γ U -> I
Index (ι i) U _ = i
Index (σ A γ) U < a | b > = Index (γ a) U b
Index (δ _ _ γ) U < _ | b > = Index γ U b
-- The assumptions of a particular inductive occurrence.
IndArg : {I : Set}(γ : OPg I)(U : I -> Set) -> Args γ U -> Set
IndArg (ι _) U _ = Zero
IndArg (σ A γ) U < a | b > = IndArg (γ a) U b
IndArg (δ H i γ) U < _ | b > = H + IndArg γ U b
-- The index of an inductive occurrence.
IndIndex : {I : Set}(γ : OPg I)(U : I -> Set)(a : Args γ U) -> IndArg γ U a -> I
IndIndex (ι _) U _ ()
IndIndex (σ A γ) U < a | b > h = IndIndex (γ a) U b h
IndIndex (δ A i γ) U < g | b > (inl h) = i h
IndIndex (δ A i γ) U < g | b > (inr h) = IndIndex γ U b h
-- An inductive occurrence.
Ind : {I : Set}(γ : OPg I)(U : I -> Set)(a : Args γ U)(h : IndArg γ U a) -> U (IndIndex γ U a h)
Ind (ι _) U _ ()
Ind (σ A γ) U < a | b > h = Ind (γ a) U b h
Ind (δ H i γ) U < g | b > (inl h) = g h
Ind (δ H i γ) U < _ | b > (inr h) = Ind γ U b h
-- The type of induction hypotheses.
IndHyp : {I : Set}(γ : OPg I)(U : I -> Set)(C : (i : I) -> U i -> Set)(a : Args γ U) -> Set
IndHyp γ U C a = (hyp : IndArg γ U a) -> C (IndIndex γ U a hyp) (Ind γ U a hyp)
-- Large induction hypostheses.
IndHyp₁ : {I : Set}(γ : OPg I)(U : I -> Set)(C : (i : I) -> U i -> Set1)(a : Args γ U) -> Set1
IndHyp₁ γ U C a = (hyp : IndArg γ U a) -> C (IndIndex γ U a hyp) (Ind γ U a hyp)
|
{
"alphanum_fraction": 0.5083857442,
"avg_line_length": 37.4117647059,
"ext": "agda",
"hexsha": "d3397b26d20f285420913837302c7643689cb366",
"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/IIDg.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/IIDg.agda",
"max_line_length": 96,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/outdated-and-incorrect/iird/IIDg.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": 796,
"size": 1908
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Fresh lists, a proof relevant variant of Catarina Coquand's contexts in
-- "A Formalised Proof of the Soundness and Completeness of a Simply Typed
-- Lambda-Calculus with Explicit Substitutions"
------------------------------------------------------------------------
-- See README.Data.List.Fresh and README.Data.Trie.NonDependent for
-- examples of how to use fresh lists.
{-# OPTIONS --without-K --safe #-}
module Data.List.Fresh where
open import Level using (Level; _⊔_; Lift)
open import Data.Bool.Base using (true; false)
open import Data.Unit.Base
open import Data.Product using (∃; _×_; _,_; -,_; proj₁; proj₂)
open import Data.List.Relation.Unary.All using (All; []; _∷_)
open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_)
open import Data.Maybe.Base as Maybe using (Maybe; just; nothing)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Function using (_∘′_; flip; id; _on_)
open import Relation.Nullary using (does)
open import Relation.Unary as U using (Pred)
open import Relation.Binary as B using (Rel)
open import Relation.Nary
private
variable
a b p r s : Level
A : Set a
B : Set b
------------------------------------------------------------------------
-- Basic type
-- If we pick an R such that (R a b) means that a is different from b
-- then we have a list of distinct values.
module _ {a} (A : Set a) (R : Rel A r) where
data List# : Set (a ⊔ r)
fresh : (a : A) (as : List#) → Set r
data List# where
[] : List#
cons : (a : A) (as : List#) → fresh a as → List#
-- Whenever R can be reconstructed by η-expansion (e.g. because it is
-- the erasure ⌊_⌋ of a decidable predicate, cf. Relation.Nary) or we
-- do not care about the proof, it is convenient to get back list syntax.
-- We use a different symbol to avoid conflict when importing both Data.List
-- and Data.List.Fresh.
infixr 5 _∷#_
pattern _∷#_ x xs = cons x xs _
fresh a [] = Lift _ ⊤
fresh a (x ∷# xs) = R a x × fresh a xs
-- Convenient notation for freshness making A and R implicit parameters
infix 5 _#_
_#_ : {R : Rel A r} (a : A) (as : List# A R) → Set r
_#_ = fresh _ _
------------------------------------------------------------------------
-- Operations for modifying fresh lists
module _ {R : Rel A r} {S : Rel B s} (f : A → B) (R⇒S : ∀[ R ⇒ (S on f) ]) where
map : List# A R → List# B S
map-# : ∀ {a} as → a # as → f a # map as
map [] = []
map (cons a as ps) = cons (f a) (map as) (map-# as ps)
map-# [] _ = _
map-# (a ∷# as) (p , ps) = R⇒S p , map-# as ps
module _ {R : Rel B r} (f : A → B) where
map₁ : List# A (R on f) → List# B R
map₁ = map f id
module _ {R : Rel A r} {S : Rel A s} (R⇒S : ∀[ R ⇒ S ]) where
map₂ : List# A R → List# A S
map₂ = map id R⇒S
------------------------------------------------------------------------
-- Views
data Empty {A : Set a} {R : Rel A r} : List# A R → Set (a ⊔ r) where
[] : Empty []
data NonEmpty {A : Set a} {R : Rel A r} : List# A R → Set (a ⊔ r) where
cons : ∀ x xs pr → NonEmpty (cons x xs pr)
------------------------------------------------------------------------
-- Operations for reducing fresh lists
length : {R : Rel A r} → List# A R → ℕ
length [] = 0
length (_ ∷# xs) = suc (length xs)
------------------------------------------------------------------------
-- Operations for constructing fresh lists
pattern [_] a = a ∷# []
fromMaybe : {R : Rel A r} → Maybe A → List# A R
fromMaybe nothing = []
fromMaybe (just a) = [ a ]
module _ {R : Rel A r} (R-refl : B.Reflexive R) where
replicate : ℕ → A → List# A R
replicate-# : (n : ℕ) (a : A) → a # replicate n a
replicate zero a = []
replicate (suc n) a = cons a (replicate n a) (replicate-# n a)
replicate-# zero a = _
replicate-# (suc n) a = R-refl , replicate-# n a
------------------------------------------------------------------------
-- Operations for deconstructing fresh lists
uncons : {R : Rel A r} → List# A R → Maybe (A × List# A R)
uncons [] = nothing
uncons (a ∷# as) = just (a , as)
head : {R : Rel A r} → List# A R → Maybe A
head = Maybe.map proj₁ ∘′ uncons
tail : {R : Rel A r} → List# A R → Maybe (List# A R)
tail = Maybe.map proj₂ ∘′ uncons
take : {R : Rel A r} → ℕ → List# A R → List# A R
take-# : {R : Rel A r} → ∀ n a (as : List# A R) → a # as → a # take n as
take zero xs = []
take (suc n) [] = []
take (suc n) (cons a as ps) = cons a (take n as) (take-# n a as ps)
take-# zero a xs _ = _
take-# (suc n) a [] ps = _
take-# (suc n) a (x ∷# xs) (p , ps) = p , take-# n a xs ps
drop : {R : Rel A r} → ℕ → List# A R → List# A R
drop zero as = as
drop (suc n) [] = []
drop (suc n) (a ∷# as) = drop n as
module _ {P : Pred A p} (P? : U.Decidable P) where
takeWhile : {R : Rel A r} → List# A R → List# A R
takeWhile-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # takeWhile as
takeWhile [] = []
takeWhile (cons a as ps) with does (P? a)
... | true = cons a (takeWhile as) (takeWhile-# a as ps)
... | false = []
takeWhile-# a [] _ = _
takeWhile-# a (x ∷# xs) (p , ps) with does (P? x)
... | true = p , takeWhile-# a xs ps
... | false = _
dropWhile : {R : Rel A r} → List# A R → List# A R
dropWhile [] = []
dropWhile aas@(a ∷# as) with does (P? a)
... | true = dropWhile as
... | false = aas
filter : {R : Rel A r} → List# A R → List# A R
filter-# : ∀ {R : Rel A r} a (as : List# A R) → a # as → a # filter as
filter [] = []
filter (cons a as ps) with does (P? a)
... | true = cons a (filter as) (filter-# a as ps)
... | false = filter as
filter-# a [] _ = _
filter-# a (x ∷# xs) (p , ps) with does (P? x)
... | true = p , filter-# a xs ps
... | false = filter-# a xs ps
------------------------------------------------------------------------
-- Relationship to List and AllPairs
toList : {R : Rel A r} → List# A R → ∃ (AllPairs R)
toAll : ∀ {R : Rel A r} {a} as → fresh A R a as → All (R a) (proj₁ (toList as))
toList [] = -, []
toList (cons x xs ps) = -, toAll xs ps ∷ proj₂ (toList xs)
toAll [] ps = []
toAll (a ∷# as) (p , ps) = p ∷ toAll as ps
fromList : ∀ {R : Rel A r} {xs} → AllPairs R xs → List# A R
fromList-# : ∀ {R : Rel A r} {x xs} (ps : AllPairs R xs) →
All (R x) xs → x # fromList ps
fromList [] = []
fromList (r ∷ rs) = cons _ (fromList rs) (fromList-# rs r)
fromList-# [] _ = _
fromList-# (p ∷ ps) (r ∷ rs) = r , fromList-# ps rs
|
{
"alphanum_fraction": 0.4985220219,
"avg_line_length": 31.9150943396,
"ext": "agda",
"hexsha": "a73ccf5b7fdf281767c8926fe978229bd7b226ce",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Fresh.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Fresh.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/src/Data/List/Fresh.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": 2201,
"size": 6766
}
|
{-
This file contains:
- Definition of propositional truncation
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.PropositionalTruncation.Base where
open import Cubical.Core.Primitives
-- Propositional truncation as a higher inductive type:
data ∥_∥ {ℓ} (A : Type ℓ) : Type ℓ where
∣_∣ : A → ∥ A ∥
squash : ∀ (x y : ∥ A ∥) → x ≡ y
|
{
"alphanum_fraction": 0.6628242075,
"avg_line_length": 19.2777777778,
"ext": "agda",
"hexsha": "e5802ab1c3274babd54cc7ee4a6cf2c962bdb04e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/HITs/PropositionalTruncation/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/HITs/PropositionalTruncation/Base.agda",
"max_line_length": 55,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/HITs/PropositionalTruncation/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 118,
"size": 347
}
|
-- Reported by stevan.andjelkovic, 2014-10-23
-- Case splitting on n in the goal g produces the wrong output, it
-- seems like {n} in f is the problem...
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
f : {_ : ℕ} → Set₁
f {n} = Set
where
g : ℕ → Set
g n = {!n!}
|
{
"alphanum_fraction": 0.5830258303,
"avg_line_length": 16.9375,
"ext": "agda",
"hexsha": "c590af0fad3bdb605cbfb3fdec8ae8a5dafa9578",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue1325.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue1325.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue1325.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": 102,
"size": 271
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Foundations.Equiv.Base where
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Core.Glue public
using ( isEquiv ; equiv-proof ; _≃_ ; equivFun ; equivProof )
fiber : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
-- Helper function for constructing equivalences from pairs (f,g) that cancel each other up to definitional
-- equality. For such (f,g), the result type simplifies to isContr (fiber f b).
strictContrFibers : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {f : A → B} (g : B → A) (b : B)
→ Σ[ t ∈ fiber f (f (g b)) ]
((t' : fiber f b) → Path (fiber f (f (g b))) t (g (f (t' .fst)) , cong (f ∘ g) (t' .snd)))
strictContrFibers {f = f} g b .fst = (g b , refl)
strictContrFibers {f = f} g b .snd (a , p) i = (g (p (~ i)) , λ j → f (g (p (~ i ∨ j))))
-- The identity equivalence
idIsEquiv : ∀ {ℓ} (A : Type ℓ) → isEquiv (idfun A)
idIsEquiv A .equiv-proof = strictContrFibers (idfun A)
idEquiv : ∀ {ℓ} (A : Type ℓ) → A ≃ A
idEquiv A .fst = idfun A
idEquiv A .snd = idIsEquiv A
|
{
"alphanum_fraction": 0.6040955631,
"avg_line_length": 41.8571428571,
"ext": "agda",
"hexsha": "3bd44d5fe237611688290e41c9225a9dc9bc206d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/Foundations/Equiv/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/Foundations/Equiv/Base.agda",
"max_line_length": 107,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/Foundations/Equiv/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 454,
"size": 1172
}
|
module par-swap.properties where
open import par-swap
open import Esterel.Lang
open import Esterel.Lang.Binding
open import Esterel.Context
open import Data.List using ([] ; [_] ; _∷_ ; List ; _++_)
open import Data.Product
Context1-∥R : ∀{p p'} → (C1 : Context1) → p ∥R p' → ((C1 ∷ []) ⟦ p ⟧c) ∥R ((C1 ∷ []) ⟦ p' ⟧c)
Context1-∥R (ceval (epar₁ q₁)) (∥Rstep dc) = ∥Rstep (dcpar₁ dc)
Context1-∥R (ceval (epar₂ p₂)) (∥Rstep dc) = ∥Rstep (dcpar₂ dc)
Context1-∥R (ceval (eseq q₁)) (∥Rstep dc) = ∥Rstep (dcseq₁ dc)
Context1-∥R (ceval (eloopˢ q₁)) (∥Rstep dc) = ∥Rstep (dcloopˢ₁ dc)
Context1-∥R (ceval (esuspend S)) (∥Rstep dc) = ∥Rstep (dcsuspend dc)
Context1-∥R (ceval etrap) (∥Rstep dc) = ∥Rstep (dctrap dc)
Context1-∥R (csignl S) (∥Rstep dc) = ∥Rstep (dcsignl dc)
Context1-∥R (cpresent₁ S q₁) (∥Rstep dc) = ∥Rstep (dcpresent₁ dc)
Context1-∥R (cpresent₂ S p₂) (∥Rstep dc) = ∥Rstep (dcpresent₂ dc)
Context1-∥R cloop (∥Rstep dc) = ∥Rstep (dcloop dc)
Context1-∥R (cloopˢ₂ p₂) (∥Rstep dc) = ∥Rstep (dcloopˢ₂ dc)
Context1-∥R (cseq₂ p₂) (∥Rstep dc) = ∥Rstep (dcseq₂ dc)
Context1-∥R (cshared s e) (∥Rstep dc) = ∥Rstep (dcshared dc)
Context1-∥R (cvar x e) (∥Rstep dc) = ∥Rstep (dcvar dc)
Context1-∥R (cif₁ x q₁) (∥Rstep dc) = ∥Rstep (dcif₁ dc)
Context1-∥R (cif₂ x p₂) (∥Rstep dc) = ∥Rstep (dcif₂ dc)
Context1-∥R (cenv θ A) (∥Rstep dc) = ∥Rstep (dcenv dc)
Context1-∥R* : ∀ {p q} -> (C1 : Context1) -> p ∥R* q -> ((C1 ∷ []) ⟦ p ⟧c) ∥R* ((C1 ∷ []) ⟦ q ⟧c)
Context1-∥R* C1 ∥R0 = ∥R0
Context1-∥R* C1 (∥Rn p∥Rq q∥R*r) = ∥Rn (Context1-∥R C1 p∥Rq) (Context1-∥R* C1 q∥R*r)
|
{
"alphanum_fraction": 0.6218649518,
"avg_line_length": 48.59375,
"ext": "agda",
"hexsha": "ea0c2b1e25ebc8053412fc39a5b9990f7e292d37",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-04-15T20:02:49.000Z",
"max_forks_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "florence/esterel-calculus",
"max_forks_repo_path": "agda/par-swap/properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "florence/esterel-calculus",
"max_issues_repo_path": "agda/par-swap/properties.agda",
"max_line_length": 97,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "4340bef3f8df42ab8167735d35a4cf56243a45cd",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "florence/esterel-calculus",
"max_stars_repo_path": "agda/par-swap/properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-01T03:59:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-16T10:58:53.000Z",
"num_tokens": 777,
"size": 1555
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Quotients for Heterogeneous equality
------------------------------------------------------------------------
{-# OPTIONS --with-K --safe #-}
module Relation.Binary.HeterogeneousEquality.Quotients where
open import Function
open import Level hiding (lift)
open import Relation.Binary
open import Relation.Binary.HeterogeneousEquality
open ≅-Reasoning
record Quotient {c ℓ} (S : Setoid c ℓ) : Set (suc (c ⊔ ℓ)) where
open Setoid S renaming (Carrier to A)
field
Q : Set c
abs : A → Q
compat : (B : Q → Set c) (f : ∀ a → B (abs a)) → Set (c ⊔ ℓ)
compat _ f = {a a′ : A} → a ≈ a′ → f a ≅ f a′
field
compat-abs : compat _ abs
lift : (B : Q → Set c) (f : ∀ a → B (abs a)) → compat B f → ∀ q → B q
lift-conv : {B : Q → Set c} (f : ∀ a → B (abs a)) (p : compat B f) →
∀ a → lift B f p (abs a) ≅ f a
Quotients : ∀ c ℓ → Set (suc (c ⊔ ℓ))
Quotients c ℓ = (S : Setoid c ℓ) → Quotient S
module Properties {c ℓ} {S : Setoid c ℓ} (Qu : Quotient S) where
open Setoid S renaming (Carrier to A) hiding (refl; sym; trans)
open Quotient Qu
module _ {B B′ : Q → Set c} {f : ∀ a → B (abs a)} {p : compat B f} where
lift-unique : {g : ∀ q → B′ q} → (∀ a → g (abs a) ≅ f a) →
∀ x → lift B f p x ≅ g x
lift-unique {g} ext = lift _ liftf≅g liftf≅g-ext where
liftf≅g : ∀ a → lift B f p (abs a) ≅ g (abs a)
liftf≅g x = begin
lift _ f p (abs x) ≅⟨ lift-conv f p x ⟩
f x ≅⟨ sym (ext x) ⟩
g (abs x) ∎
liftf≅g-ext : ∀ {a a′} → a ≈ a′ → liftf≅g a ≅ liftf≅g a′
liftf≅g-ext eq = ≅-heterogeneous-irrelevantˡ _ _
$ cong (lift B f p) (compat-abs eq)
lift-ext : {g : ∀ a → B′ (abs a)} {p′ : compat B′ g} → (∀ x → f x ≅ g x) →
∀ x → lift B f p x ≅ lift B′ g p′ x
lift-ext {g} {p′} h = lift-unique $ λ a → begin
lift B′ g p′ (abs a) ≅⟨ lift-conv g p′ a ⟩
g a ≅⟨ sym (h a) ⟩
f a ∎
lift-conv-abs : ∀ a → lift (const Q) abs compat-abs a ≅ a
lift-conv-abs = lift-unique (λ _ → refl)
lift-fold : {B : Q → Set c} (f : ∀ q → B q) →
∀ a → lift B (f ∘ abs) (cong f ∘ compat-abs) a ≅ f a
lift-fold f = lift-unique (λ _ → refl)
abs-epimorphism : {B : Q → Set c} {f g : ∀ q → B q} →
(∀ x → f (abs x) ≅ g (abs x)) → ∀ q → f q ≅ g q
abs-epimorphism {B} {f} {g} p q = begin
f q ≅⟨ sym (lift-fold f q) ⟩
lift B (f ∘ abs) (cong f ∘ compat-abs) q ≅⟨ lift-ext p q ⟩
lift B (g ∘ abs) (cong g ∘ compat-abs) q ≅⟨ lift-fold g q ⟩
g q ∎
------------------------------------------------------------------------
-- Properties provable with extensionality
module _ (ext : ∀ {a b} {A : Set a} {B₁ B₂ : A → Set b} {f₁ : ∀ a → B₁ a}
{f₂ : ∀ a → B₂ a} → (∀ a → f₁ a ≅ f₂ a) → f₁ ≅ f₂) where
module Properties₂
{c ℓ} {S₁ S₂ : Setoid c ℓ} (Qu₁ : Quotient S₁) (Qu₂ : Quotient S₂)
where
module S₁ = Setoid S₁
module S₂ = Setoid S₂
module Qu₁ = Quotient Qu₁
module Qu₂ = Quotient Qu₂
module _ {B : _ → _ → Set c} (f : ∀ s₁ s₂ → B (Qu₁.abs s₁) (Qu₂.abs s₂)) where
compat₂ : Set _
compat₂ = ∀ {a b a′ b′} → a S₁.≈ a′ → b S₂.≈ b′ → f a b ≅ f a′ b′
lift₂ : compat₂ → ∀ q q′ → B q q′
lift₂ p = Qu₁.lift _ g (ext ∘ g-ext) module Lift₂ where
g : ∀ a q → B (Qu₁.abs a) q
g a = Qu₂.lift (B (Qu₁.abs a)) (f a) (p S₁.refl)
g-ext : ∀ {a a′} → a S₁.≈ a′ → ∀ q → g a q ≅ g a′ q
g-ext a≈a′ = Properties.lift-ext Qu₂ (λ _ → p a≈a′ S₂.refl)
lift₂-conv : (p : compat₂) → ∀ a a′ → lift₂ p (Qu₁.abs a) (Qu₂.abs a′) ≅ f a a′
lift₂-conv p a a′ = begin
lift₂ p (Qu₁.abs a) (Qu₂.abs a′)
≅⟨ cong (_$ (Qu₂.abs a′)) (Qu₁.lift-conv (Lift₂.g p) (ext ∘ Lift₂.g-ext p) a) ⟩
Lift₂.g p a (Qu₂.abs a′)
≡⟨⟩
Qu₂.lift (B (Qu₁.abs a)) (f a) (p S₁.refl) (Qu₂.abs a′)
≅⟨ Qu₂.lift-conv (f a) (p S₁.refl) a′ ⟩
f a a′
∎
module Properties₃ {c ℓ} {S₁ S₂ S₃ : Setoid c ℓ}
(Qu₁ : Quotient S₁) (Qu₂ : Quotient S₂) (Qu₃ : Quotient S₃)
where
module S₁ = Setoid S₁
module S₂ = Setoid S₂
module S₃ = Setoid S₃
module Qu₁ = Quotient Qu₁
module Qu₂ = Quotient Qu₂
module Qu₃ = Quotient Qu₃
module _ {B : _ → _ → _ → Set c}
(f : ∀ s₁ s₂ s₃ → B (Qu₁.abs s₁) (Qu₂.abs s₂) (Qu₃.abs s₃)) where
compat₃ : Set _
compat₃ = ∀ {a b c a′ b′ c′} → a S₁.≈ a′ → b S₂.≈ b′ → c S₃.≈ c′ →
f a b c ≅ f a′ b′ c′
lift₃ : compat₃ → ∀ q₁ q₂ q₃ → B q₁ q₂ q₃
lift₃ p = Qu₁.lift _ h (ext ∘ h-ext) module Lift₃ where
g : ∀ a b q → B (Qu₁.abs a) (Qu₂.abs b) q
g a b = Qu₃.lift (B (Qu₁.abs a) (Qu₂.abs b)) (f a b) (p S₁.refl S₂.refl)
g-ext : ∀ {a a′ b b′} → a S₁.≈ a′ → b S₂.≈ b′ → ∀ c → g a b c ≅ g a′ b′ c
g-ext a≈a′ b≈b′ = Properties.lift-ext Qu₃ (λ _ → p a≈a′ b≈b′ S₃.refl)
h : ∀ a q₂ q₃ → B (Qu₁.abs a) q₂ q₃
h a = Qu₂.lift (λ b → ∀ q → B (Qu₁.abs a) b q) (g a) (ext ∘ g-ext S₁.refl)
h-ext : ∀ {a a′} → a S₁.≈ a′ → ∀ b → h a b ≅ h a′ b
h-ext a≈a′ = Properties.lift-ext Qu₂ $ λ _ → ext (g-ext a≈a′ S₂.refl)
|
{
"alphanum_fraction": 0.4610557401,
"avg_line_length": 36.12,
"ext": "agda",
"hexsha": "a429dafe8fb1d442a8fff7a859c86b5e13302418",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality/Quotients.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality/Quotients.agda",
"max_line_length": 89,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Relation/Binary/HeterogeneousEquality/Quotients.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": 2219,
"size": 5418
}
|
-- Reasoning with both a strict and non-strict relation.
{-# OPTIONS --cubical --no-import-sorts --safe #-}
open import Cubical.Core.Everything
open import Cubical.Relation.Binary.Raw
module Cubical.Relation.Binary.Reasoning.Base.Double {a ℓ₁ ℓ₂} {A : Type a}
{_≤_ : RawRel A ℓ₁} {_<_ : RawRel A ℓ₂}
(≤-isPreorder : IsPreorder _≤_)
(<-transitive : Transitive _<_) (<⇒≤ : _<_ ⇒ _≤_)
(<-≤-transitive : Trans _<_ _≤_ _<_) (≤-<-transitive : Trans _≤_ _<_ _<_)
where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Prod using (proj₁; proj₂)
open import Cubical.Foundations.Function using (case_of_; id)
open import Cubical.Relation.Nullary using (Dec; yes; no; IsYes; toWitness)
open IsPreorder ≤-isPreorder
renaming
( reflexive to ≤-reflexive
; transitive to ≤-transitive
)
------------------------------------------------------------------------
-- A datatype to abstract over the current relation
infix 4 _IsRelatedTo_
data _IsRelatedTo_ (x y : A) : Type (ℓ-max a (ℓ-max ℓ₁ ℓ₂)) where
strict : (x<y : x < y) → x IsRelatedTo y
nonstrict : (x≤y : x ≤ y) → x IsRelatedTo y
------------------------------------------------------------------------
-- Types that are used to ensure that the final relation proved by the
-- chain of reasoning can be converted into the required relation.
data IsStrict {x y} : x IsRelatedTo y → Type (ℓ-max a (ℓ-max ℓ₁ ℓ₂)) where
isStrict : ∀ x<y → IsStrict (strict x<y)
IsStrict? : ∀ {x y} (x≲y : x IsRelatedTo y) → Dec (IsStrict x≲y)
IsStrict? (strict x<y) = yes (isStrict x<y)
IsStrict? (nonstrict _) = no λ()
extractStrict : ∀ {x y} {x≲y : x IsRelatedTo y} → IsStrict x≲y → x < y
extractStrict (isStrict x<y) = x<y
------------------------------------------------------------------------
-- Reasoning combinators
infix 0 begin_ begin-strict_
infixr 1 _<⟨_⟩_ _≤⟨_⟩_ _≡⟨_⟩_ _≡˘⟨_⟩_ _≡⟨⟩_
infix 2 _∎
-- Beginnings of various types of proofs
begin_ : ∀ {x y} → x IsRelatedTo y → x ≤ y
begin strict x<y = <⇒≤ x<y
begin nonstrict x≤y = x≤y
begin-strict_ : ∀ {x y} (r : x IsRelatedTo y) → {s : IsYes (IsStrict? r)} → x < y
begin-strict_ r {s} = extractStrict (toWitness s)
-- Step with the strict relation
_<⟨_⟩_ : ∀ (x : A) {y z} → x < y → y IsRelatedTo z → x IsRelatedTo z
x <⟨ x<y ⟩ strict y<z = strict (<-transitive x<y y<z)
x <⟨ x<y ⟩ nonstrict y≤z = strict (<-≤-transitive x<y y≤z)
-- Step with the non-strict relation
_≤⟨_⟩_ : ∀ (x : A) {y z} → x ≤ y → y IsRelatedTo z → x IsRelatedTo z
x ≤⟨ x≤y ⟩ strict y<z = strict (≤-<-transitive x≤y y<z)
x ≤⟨ x≤y ⟩ nonstrict y≤z = nonstrict (≤-transitive x≤y y≤z)
-- Step with non-trivial propositional equality
_≡⟨_⟩_ : ∀ (x : A) {y z} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_≡⟨_⟩_ x {_} {z} x≡y y≲z = J (λ w _ → w IsRelatedTo z) y≲z (sym x≡y)
-- Flipped step with non-trivial propositional equality
_≡˘⟨_⟩_ : ∀ x {y z} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z
x ≡˘⟨ y≡x ⟩ y≲z = x ≡⟨ sym y≡x ⟩ y≲z
-- Step with trivial propositional equality
_≡⟨⟩_ : ∀ (x : A) {y} → x IsRelatedTo y → x IsRelatedTo y
x ≡⟨⟩ x≲y = x≲y
-- Syntax for path definition
≡⟨⟩-syntax : ∀ x {y z : A} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
≡⟨⟩-syntax = _≡⟨_⟩_
infixr 1 ≡⟨⟩-syntax
syntax ≡⟨⟩-syntax x (λ i → B) y = x ≡[ i ]⟨ B ⟩ y
≡˘⟨⟩-syntax : ∀ x {y z : A} → y ≡ x → y IsRelatedTo z → x IsRelatedTo z
≡˘⟨⟩-syntax = _≡˘⟨_⟩_
infixr 1 ≡˘⟨⟩-syntax
syntax ≡˘⟨⟩-syntax x (λ i → B) y = x ≡˘[ i ]⟨ B ⟩ y
-- Termination step
_∎ : ∀ x → x IsRelatedTo x
x ∎ = nonstrict ≤-reflexive
|
{
"alphanum_fraction": 0.5870491338,
"avg_line_length": 32.6018518519,
"ext": "agda",
"hexsha": "db890f040f346a5bcf92c3dbaab5162c7915c64a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bijan2005/univalent-foundations",
"max_forks_repo_path": "Cubical/Relation/Binary/Reasoning/Base/Double.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bijan2005/univalent-foundations",
"max_issues_repo_path": "Cubical/Relation/Binary/Reasoning/Base/Double.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "737f922d925da0cd9a875cb0c97786179f1f4f61",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bijan2005/univalent-foundations",
"max_stars_repo_path": "Cubical/Relation/Binary/Reasoning/Base/Double.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1400,
"size": 3521
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Propertiers of any for containers
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Container.Relation.Unary.Any.Properties where
open import Level
open import Algebra
open import Data.Product as Prod using (∃; _×_; ∃₂; _,_; proj₂)
open import Data.Product.Function.NonDependent.Propositional using (_×-cong_)
import Data.Product.Function.Dependent.Propositional as Σ
open import Data.Sum using (_⊎_; inj₁; inj₂; [_,_])
open import Function
open import Function.Equality using (_⟨$⟩_)
open import Function.Equivalence using (equivalence)
open import Function.HalfAdjointEquivalence using (_≃_; ↔→≃)
open import Function.Inverse as Inv using (_↔_; inverse; module Inverse)
open import Function.Related as Related using (Related; SK-sym)
open import Function.Related.TypeIsomorphisms
open import Relation.Unary using (Pred ; _∪_ ; _∩_)
open import Relation.Binary using (REL)
open import Relation.Binary.PropositionalEquality as P
using (_≡_; _≗_; refl)
open Related.EquationalReasoning hiding (_≡⟨_⟩_)
private
module ×⊎ {k ℓ} = CommutativeSemiring (×-⊎-commutativeSemiring k ℓ)
open import Data.Container.Core
import Data.Container.Combinator as C
open import Data.Container.Combinator.Properties
open import Data.Container.Related
open import Data.Container.Relation.Unary.Any as Any using (◇; any)
open import Data.Container.Membership
module _ {s p} (C : Container s p) {x} {X : Set x} {ℓ} {P : Pred X ℓ} where
-- ◇ can be unwrapped to reveal the Σ type
↔Σ : ∀ {xs : ⟦ C ⟧ X} → ◇ C P xs ↔ ∃ λ p → P (proj₂ xs p)
↔Σ {xs} = inverse ◇.proof any (λ _ → P.refl) (λ _ → P.refl)
-- ◇ can be expressed using _∈_.
↔∈ : ∀ {xs : ⟦ C ⟧ X} → ◇ C P xs ↔ (∃ λ x → x ∈ xs × P x)
↔∈ {xs} = inverse to from (λ _ → P.refl) (to∘from) where
to : ◇ C P xs → ∃ λ x → x ∈ xs × P x
to (any (p , Px)) = (proj₂ xs p , (any (p , P.refl)) , Px)
from : (∃ λ x → x ∈ xs × P x) → ◇ C P xs
from (.(proj₂ xs p) , (any (p , refl)) , Px) = any (p , Px)
to∘from : to ∘ from ≗ id
to∘from (.(proj₂ xs p) , any (p , refl) , Px) = P.refl
module _ {s p} {C : Container s p} {x} {X : Set x}
{ℓ₁ ℓ₂} {P₁ : Pred X ℓ₁} {P₂ : Pred X ℓ₂} where
-- ◇ is a congruence for bag and set equality and related preorders.
cong : ∀ {k} {xs₁ xs₂ : ⟦ C ⟧ X} →
(∀ x → Related k (P₁ x) (P₂ x)) → xs₁ ∼[ k ] xs₂ →
Related k (◇ C P₁ xs₁) (◇ C P₂ xs₂)
cong {k} {xs₁} {xs₂} P₁↔P₂ xs₁≈xs₂ =
◇ C P₁ xs₁ ↔⟨ ↔∈ C ⟩
(∃ λ x → x ∈ xs₁ × P₁ x) ∼⟨ Σ.cong Inv.id (xs₁≈xs₂ ×-cong P₁↔P₂ _) ⟩
(∃ λ x → x ∈ xs₂ × P₂ x) ↔⟨ SK-sym (↔∈ C) ⟩
◇ C P₂ xs₂ ∎
-- Nested occurrences of ◇ can sometimes be swapped.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x y} {X : Set x} {Y : Set y} {r} {P : REL X Y r} where
swap : {xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
let ◈ : ∀ {s p} {C : Container s p} {x} {X : Set x} {ℓ} → ⟦ C ⟧ X → Pred X ℓ → Set (p ⊔ ℓ)
◈ = λ {_} {_} → flip (◇ _) in
◈ xs (◈ ys ∘ P) ↔ ◈ ys (◈ xs ∘ flip P)
swap {xs} {ys} =
◇ _ (λ x → ◇ _ (P x) ys) xs ↔⟨ ↔∈ C₁ ⟩
(∃ λ x → x ∈ xs × ◇ _ (P x) ys) ↔⟨ Σ.cong Inv.id $ Σ.cong Inv.id $ ↔∈ C₂ ⟩
(∃ λ x → x ∈ xs × ∃ λ y → y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {x} → ∃∃↔∃∃ (λ _ y → y ∈ ys × P x y)) ⟩
(∃₂ λ x y → x ∈ xs × y ∈ ys × P x y) ↔⟨ ∃∃↔∃∃ (λ x y → x ∈ xs × y ∈ ys × P x y) ⟩
(∃₂ λ y x → x ∈ xs × y ∈ ys × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → Σ.cong Inv.id (λ {x} →
(x ∈ xs × y ∈ ys × P x y) ↔⟨ SK-sym Σ-assoc ⟩
((x ∈ xs × y ∈ ys) × P x y) ↔⟨ Σ.cong (×-comm _ _) Inv.id ⟩
((y ∈ ys × x ∈ xs) × P x y) ↔⟨ Σ-assoc ⟩
(y ∈ ys × x ∈ xs × P x y) ∎)) ⟩
(∃₂ λ y x → y ∈ ys × x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (λ {y} → ∃∃↔∃∃ {B = y ∈ ys} (λ x _ → x ∈ xs × P x y)) ⟩
(∃ λ y → y ∈ ys × ∃ λ x → x ∈ xs × P x y) ↔⟨ Σ.cong Inv.id (Σ.cong Inv.id (SK-sym (↔∈ C₁))) ⟩
(∃ λ y → y ∈ ys × ◇ _ (flip P y) xs) ↔⟨ SK-sym (↔∈ C₂) ⟩
◇ _ (λ y → ◇ _ (flip P y) xs) ys ∎
-- Nested occurrences of ◇ can sometimes be flattened.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
flatten : ∀ (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
◇ C₁ (◇ C₂ P) xss ↔
◇ (C₁ C.∘ C₂) P (Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss)
flatten xss = inverse t f (λ _ → P.refl) (λ _ → P.refl) where
◇₁ = ◇ C₁; ◇₂ = ◇ C₂; ◇₁₂ = ◇ (C₁ C.∘ C₂)
open Inverse
t : ◇₁ (◇₂ P) xss → ◇₁₂ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss)
t (any (p₁ , (any (p₂ , p)))) = any (any (p₁ , p₂) , p)
f : ◇₁₂ P (from (Composition.correct C₁ C₂) ⟨$⟩ xss) → ◇₁ (◇₂ P) xss
f (any (any (p₁ , p₂) , p)) = any (p₁ , any (p₂ , p))
-- Sums commute with ◇ (for a fixed instance of a given container).
module _ {s p} {C : Container s p} {x} {X : Set x}
{ℓ ℓ′} {P : Pred X ℓ} {Q : Pred X ℓ′} where
◇⊎↔⊎◇ : ∀ {xs : ⟦ C ⟧ X} → ◇ C (P ∪ Q) xs ↔ (◇ C P xs ⊎ ◇ C Q xs)
◇⊎↔⊎◇ {xs} = inverse to from from∘to to∘from
where
to : ◇ C (λ x → P x ⊎ Q x) xs → ◇ C P xs ⊎ ◇ C Q xs
to (any (pos , inj₁ p)) = inj₁ (any (pos , p))
to (any (pos , inj₂ q)) = inj₂ (any (pos , q))
from : ◇ C P xs ⊎ ◇ C Q xs → ◇ C (λ x → P x ⊎ Q x) xs
from = [ Any.map₂ inj₁ , Any.map₂ inj₂ ]
from∘to : from ∘ to ≗ id
from∘to (any (pos , inj₁ p)) = P.refl
from∘to (any (pos , inj₂ q)) = P.refl
to∘from : to ∘ from ≗ id
to∘from = [ (λ _ → P.refl) , (λ _ → P.refl) ]
-- Products "commute" with ◇.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x y} {X : Set x} {Y : Set y} {ℓ ℓ′} {P : Pred X ℓ} {Q : Pred Y ℓ′} where
×◇↔◇◇× : ∀ {xs : ⟦ C₁ ⟧ X} {ys : ⟦ C₂ ⟧ Y} →
◇ C₁ (λ x → ◇ C₂ (λ y → P x × Q y) ys) xs ↔ (◇ C₁ P xs × ◇ C₂ Q ys)
×◇↔◇◇× {xs} {ys} = inverse to from (λ _ → P.refl) (λ _ → P.refl)
where
◇₁ = ◇ C₁; ◇₂ = ◇ C₂
to : ◇₁ (λ x → ◇₂ (λ y → P x × Q y) ys) xs → ◇₁ P xs × ◇₂ Q ys
to (any (p₁ , any (p₂ , p , q))) = (any (p₁ , p) , any (p₂ , q))
from : ◇₁ P xs × ◇₂ Q ys → ◇₁ (λ x → ◇₂ (λ y → P x × Q y) ys) xs
from (any (p₁ , p) , any (p₂ , q)) = any (p₁ , any (p₂ , p , q))
-- map can be absorbed by the predicate.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
map↔∘ : ∀ {xs : ⟦ C ⟧ X} (f : X → Y) → ◇ C P (map f xs) ↔ ◇ C (P ∘′ f) xs
map↔∘ {xs} f =
◇ C P (map f xs) ↔⟨ ↔Σ C ⟩
∃ (P ∘′ proj₂ (map f xs)) ↔⟨⟩
∃ (P ∘′ f ∘′ proj₂ xs) ↔⟨ SK-sym (↔Σ C) ⟩
◇ C (P ∘′ f) xs ∎
-- Membership in a mapped container can be expressed without reference
-- to map.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
∈map↔∈×≡ : ∀ {f : X → Y} {xs : ⟦ C ⟧ X} {y} →
y ∈ map f xs ↔ (∃ λ x → x ∈ xs × y ≡ f x)
∈map↔∈×≡ {f = f} {xs} {y} =
y ∈ map f xs ↔⟨ map↔∘ C (y ≡_) f ⟩
◇ C (λ x → y ≡ f x) xs ↔⟨ ↔∈ C ⟩
∃ (λ x → x ∈ xs × y ≡ f x) ∎
-- map is a congruence for bag and set equality and related preorders.
module _ {s p} (C : Container s p) {x y} {X : Set x} {Y : Set y}
{ℓ} (P : Pred Y ℓ) where
map-cong : ∀ {k} {f₁ f₂ : X → Y} {xs₁ xs₂ : ⟦ C ⟧ X} →
f₁ ≗ f₂ → xs₁ ∼[ k ] xs₂ →
map f₁ xs₁ ∼[ k ] map f₂ xs₂
map-cong {f₁ = f₁} {f₂} {xs₁} {xs₂} f₁≗f₂ xs₁≈xs₂ {x} =
x ∈ map f₁ xs₁ ↔⟨ map↔∘ C (_≡_ x) f₁ ⟩
◇ C (λ y → x ≡ f₁ y) xs₁ ∼⟨ cong (Related.↔⇒ ∘ helper) xs₁≈xs₂ ⟩
◇ C (λ y → x ≡ f₂ y) xs₂ ↔⟨ SK-sym (map↔∘ C (_≡_ x) f₂) ⟩
x ∈ map f₂ xs₂ ∎
where
helper : ∀ y → (x ≡ f₁ y) ↔ (x ≡ f₂ y)
helper y rewrite f₁≗f₂ y = Inv.id
-- Uses of linear morphisms can be removed.
module _ {s₁ s₂ p₁ p₂} {C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
remove-linear : ∀ {xs : ⟦ C₁ ⟧ X} (m : C₁ ⊸ C₂) → ◇ C₂ P (⟪ m ⟫⊸ xs) ↔ ◇ C₁ P xs
remove-linear {xs} m = Inv.inverse t f f∘t t∘f
where
open _≃_
open P.≡-Reasoning renaming (_∎ to _∎′)
position⊸m : ∀ {s} → Position C₂ (shape⊸ m s) ≃ Position C₁ s
position⊸m = ↔→≃ (position⊸ m)
◇₁ = ◇ C₁; ◇₂ = ◇ C₂
t : ◇₂ P (⟪ m ⟫⊸ xs) → ◇₁ P xs
t = Any.map₁ (_⊸_.morphism m)
f : ◇₁ P xs → ◇₂ P (⟪ m ⟫⊸ xs)
f (any (x , p)) =
any $ from position⊸m x
, P.subst (P ∘′ proj₂ xs) (P.sym (right-inverse-of position⊸m _)) p
f∘t : f ∘ t ≗ id
f∘t (any (p₂ , p)) = P.cong any $ Inverse.to Σ-≡,≡↔≡ ⟨$⟩
( left-inverse-of position⊸m p₂
, (P.subst (P ∘ proj₂ xs ∘ to position⊸m)
(left-inverse-of position⊸m p₂)
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.subst-∘ (left-inverse-of position⊸m _) ⟩
P.subst (P ∘ proj₂ xs)
(P.cong (to position⊸m)
(left-inverse-of position⊸m p₂))
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m _)) _))
(_≃_.left-right position⊸m _) ⟩
P.subst (P ∘ proj₂ xs)
(right-inverse-of position⊸m
(to position⊸m p₂))
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
p) ≡⟨ P.subst-subst (P.sym (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs)
(P.trans
(P.sym (right-inverse-of position⊸m
(to position⊸m p₂)))
(right-inverse-of position⊸m
(to position⊸m p₂)))
p ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq p)
(P.trans-symˡ (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs) P.refl p ≡⟨⟩
p ∎′)
)
t∘f : t ∘ f ≗ id
t∘f (any (p₁ , p)) = P.cong any $ Inverse.to Σ-≡,≡↔≡ ⟨$⟩
( right-inverse-of position⊸m p₁
, (P.subst (P ∘ proj₂ xs)
(right-inverse-of position⊸m p₁)
(P.subst (P ∘ proj₂ xs)
(P.sym (right-inverse-of position⊸m p₁))
p) ≡⟨ P.subst-subst (P.sym (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs)
(P.trans
(P.sym (right-inverse-of position⊸m p₁))
(right-inverse-of position⊸m p₁))
p ≡⟨ P.cong (λ eq → P.subst (P ∘ proj₂ xs) eq p)
(P.trans-symˡ (right-inverse-of position⊸m _)) ⟩
P.subst (P ∘ proj₂ xs) P.refl p ≡⟨⟩
p ∎′)
)
-- Linear endomorphisms are identity functions if bag equality is used.
module _ {s p} {C : Container s p} {x} {X : Set x} where
linear-identity : ∀ {xs : ⟦ C ⟧ X} (m : C ⊸ C) → ⟪ m ⟫⊸ xs ∼[ bag ] xs
linear-identity {xs} m {x} =
x ∈ ⟪ m ⟫⊸ xs ↔⟨ remove-linear (_≡_ x) m ⟩
x ∈ xs ∎
-- If join can be expressed using a linear morphism (in a certain
-- way), then it can be absorbed by the predicate.
module _ {s₁ s₂ s₃ p₁ p₂ p₃}
{C₁ : Container s₁ p₁} {C₂ : Container s₂ p₂} {C₃ : Container s₃ p₃}
{x} {X : Set x} {ℓ} (P : Pred X ℓ) where
join↔◇ : (join′ : (C₁ C.∘ C₂) ⊸ C₃) (xss : ⟦ C₁ ⟧ (⟦ C₂ ⟧ X)) →
let join : ∀ {X} → ⟦ C₁ ⟧ (⟦ C₂ ⟧ X) → ⟦ C₃ ⟧ X
join = λ {_} → ⟪ join′ ⟫⊸ ∘
_⟨$⟩_ (Inverse.from (Composition.correct C₁ C₂)) in
◇ C₃ P (join xss) ↔ ◇ C₁ (◇ C₂ P) xss
join↔◇ join xss =
◇ C₃ P (⟪ join ⟫⊸ xss′) ↔⟨ remove-linear P join ⟩
◇ (C₁ C.∘ C₂) P xss′ ↔⟨ SK-sym $ flatten P xss ⟩
◇ C₁ (◇ C₂ P) xss ∎
where xss′ = Inverse.from (Composition.correct C₁ C₂) ⟨$⟩ xss
|
{
"alphanum_fraction": 0.4461070844,
"avg_line_length": 41.2572347267,
"ext": "agda",
"hexsha": "2facd10a82fdc951a0525739f9b040747c529a68",
"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/Container/Relation/Unary/Any/Properties.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/Container/Relation/Unary/Any/Properties.agda",
"max_line_length": 130,
"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/Container/Relation/Unary/Any/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5213,
"size": 12831
}
|
module Highlighting.M where
|
{
"alphanum_fraction": 0.8571428571,
"avg_line_length": 14,
"ext": "agda",
"hexsha": "89b037dd3a54fee814ab1526a1b531b76c1f38e7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/interaction/Highlighting/M.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/interaction/Highlighting/M.agda",
"max_line_length": 27,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/interaction/Highlighting/M.agda",
"max_stars_repo_stars_event_max_datetime": "2015-12-07T20:14:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-28T14:51:03.000Z",
"num_tokens": 6,
"size": 28
}
|
module Sized.CounterCell where
open import Data.Product
open import Data.Nat.Base
open import Data.Nat.Show
open import Data.String.Base using (String; _++_)
open import SizedIO.Object
open import SizedIO.IOObject
open import SizedIO.Base
open import SizedIO.Console hiding (main)
open import SizedIO.ConsoleObject
open import NativeIO
open import Sized.SimpleCell hiding (program; main)
open import Size
data CounterMethod A : Set where
super : (m : CellMethod A) → CounterMethod A
stats : CounterMethod A
pattern getᶜ = super get
pattern putᶜ x = super (put x)
-- CounterResult : ∀{A} →
counterI : (A : Set) → Interface
Method (counterI A) = CounterMethod A
Result (counterI A) (super m) = Result (cellJ A) m
Result (counterI A) stats = Unit
CounterC : (i : Size) → Set
CounterC i = ConsoleObject i (counterI String)
-- counterP is constructor for the consoleObject for interface counterI
counterP : ∀{i} (c : CellC i) (ngets nputs : ℕ) → CounterC i
method (counterP c ngets nputs) getᶜ =
method c get >>= λ { (s , c') →
return (s , counterP c' (1 + ngets) nputs) }
method (counterP c ngets nputs) (putᶜ x) =
method c (put x) >>= λ { (_ , c') →
return (_ , counterP c' ngets (1 + nputs)) }
method (counterP c ngets nputs) stats =
exec (putStrLn ("Counted "
++ show ngets ++ " calls to get and "
++ show nputs ++ " calls to put.")) λ _ →
return (_ , counterP c ngets nputs)
program : String → IOConsole ∞ Unit
program arg =
let c₀ = counterP (cellP "Start") 0 0 in
method c₀ getᶜ >>= λ{ (s , c₁) →
exec1 (putStrLn s) >>
method c₁ (putᶜ arg) >>= λ{ (_ , c₂) →
method c₂ getᶜ >>= λ{ (s' , c₃) →
exec1 (putStrLn s') >>
method c₃ (putᶜ "Over!") >>= λ{ (_ , c₄) →
method c₄ stats >>= λ{ (_ , c₅) →
return _ }}}}}
main : NativeIO Unit
main = translateIOConsole (program "Hello")
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
-- -}
|
{
"alphanum_fraction": 0.5886627907,
"avg_line_length": 27.1578947368,
"ext": "agda",
"hexsha": "c58e8de704e9b49a95e8de304577807f8def9918",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/Sized/CounterCell.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/Sized/CounterCell.agda",
"max_line_length": 71,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/Sized/CounterCell.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 646,
"size": 2064
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.Wedge where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.MayerVietorisUnreduced
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Function
open import Cubical.HITs.Wedge
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; ∣_∣ to ∣_∣₁)
open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)
open import Cubical.Data.Nat
open import Cubical.Algebra.Group
open import Cubical.ZCohomology.Groups.Unit
open import Cubical.ZCohomology.Groups.Sn
open import Cubical.HITs.Pushout
open import Cubical.Data.Sigma
open import Cubical.Foundations.Isomorphism
open import Cubical.Homotopy.Connected
open import Cubical.HITs.Susp
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.Foundations.Equiv
module _ {ℓ ℓ'} (A : Pointed ℓ) (B : Pointed ℓ') where
module I = MV (typ A) (typ B) Unit (λ _ → pt A) (λ _ → pt B)
Hⁿ-⋁ : (n : ℕ) → GroupIso (coHomGr (suc n) (A ⋁ B)) (×coHomGr (suc n) (typ A) (typ B))
Hⁿ-⋁ zero = BijectionIsoToGroupIso bijIso
where
surj-helper : (x : coHom 0 Unit) → isInIm _ _ (I.Δ 0) x
surj-helper =
sElim (λ _ → isOfHLevelSuc 1 propTruncIsProp)
λ f → ∣ (∣ (λ _ → f tt) ∣₂ , 0ₕ 0) , cong ∣_∣₂ (funExt λ _ → -rUnitₖ 0 (f tt)) ∣₁
helper : (x : coHom 1 (A ⋁ B)) → isInIm _ _ (I.d 0) x → x ≡ 0ₕ 1
helper x inim =
pRec (setTruncIsSet _ _)
(λ p → sym (snd p) ∙
MV.Im-Δ⊂Ker-d _ _ Unit (λ _ → pt A) (λ _ → pt B) 0 (fst p) (surj-helper (fst p)))
inim
bijIso : BijectionIso (coHomGr 1 (A ⋁ B)) (×coHomGr 1 (typ A) (typ B))
BijectionIso.map' bijIso = I.i 1
BijectionIso.inj bijIso =
sElim (λ _ → isSetΠ λ _ → isProp→isSet (setTruncIsSet _ _))
λ f inker → helper ∣ f ∣₂ (I.Ker-i⊂Im-d 0 ∣ f ∣₂ inker)
BijectionIso.surj bijIso p = I.Ker-Δ⊂Im-i 1 p (isContr→isProp (isContrHⁿ-Unit 0) _ _)
Hⁿ-⋁ (suc n) = Iso+Hom→GrIso mainIso
(sElim2 (λ _ _ → isOfHLevelPath 2 (isOfHLevel× 2 setTruncIsSet setTruncIsSet) _ _)
λ _ _ → refl)
where
helpIso : ∀ {ℓ'''} {C : Type ℓ'''} → Iso (A ⋁ B → C) (Σ[ f ∈ (typ A → C) × (typ B → C) ] (fst f) (pt A) ≡ (snd f) (pt B))
Iso.fun helpIso f = ((λ x → f (inl x)) , λ x → f (inr x)) , cong f (push tt)
Iso.inv helpIso ((f , g) , p) (inl x) = f x
Iso.inv helpIso ((f , g) , p) (inr x) = g x
Iso.inv helpIso ((f , g) , p) (push a i) = p i
Iso.rightInv helpIso ((f , g) , p) = ΣPathP (ΣPathP (refl , refl) , refl)
Iso.leftInv helpIso f = funExt λ {(inl a) → refl ; (inr a) → refl ; (push a i) → refl}
mainIso : Iso (coHom (2 + n) (A ⋁ B))
(coHom (2 + n) (typ A) × coHom (2 + n) (typ B))
mainIso = compIso (setTruncIso helpIso) (compIso theIso setTruncOfProdIso)
where
forget : ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂
→ ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂
forget = sMap (λ {((f , g) , _) → f , g})
isEq : (f : ∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂) → isContr (fiber forget f)
isEq = sElim (λ _ → isOfHLevelSuc 1 isPropIsContr) (uncurry λ f g → helper f g (f (pt A)) (g (pt B)) refl refl)
where
helper : (f : (typ A → coHomK (2 + n))) (g : (typ B → coHomK (2 + n))) (x y : coHomK (2 + n))
→ f (pt A) ≡ x
→ g (pt B) ≡ y
→ isContr (fiber forget ∣ f , g ∣₂)
helper f g = trElim2 (λ _ _ → isProp→isOfHLevelSuc (3 + n)
(isPropΠ2 λ _ _ → isPropIsContr))
(suspToPropElim2 (ptSn (suc n))
(λ _ _ → isPropΠ2 λ _ _ → isPropIsContr)
λ p q → (∣ (f , g) , (p ∙ sym q) ∣₂
, refl)
, uncurry (sElim (λ _ → isSetΠ λ _ → isOfHLevelPath 2 (isOfHLevelΣ 2 setTruncIsSet λ _ → isOfHLevelPath 2 setTruncIsSet _ _) _ _)
λ { ((f' , g') , id1) y →
Σ≡Prop (λ _ → setTruncIsSet _ _)
(pRec (setTruncIsSet _ _)
(λ id2 → trRec (setTruncIsSet _ _)
(λ pathp → cong ∣_∣₂ (ΣPathP ((sym id2) , pathp)))
(isConnectedPathP 1
{A = λ i → (fst (id2 (~ i)) (pt A) ≡ snd (id2 (~ i)) (pt B))}
(isConnectedPath 2 (isConnectedSubtr 3 n
(subst (λ m → isConnected m (coHomK (2 + n))) (+-comm 3 n)
(isConnectedKn (suc n)))) _ _)
(p ∙ sym q) id1 .fst))
(Iso.fun PathIdTrunc₀Iso y))}))
theIso : Iso ∥ (Σ[ f ∈ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ] (fst f) (pt A) ≡ (snd f) (pt B)) ∥₂
∥ (typ A → coHomK (2 + n)) × (typ B → coHomK (2 + n)) ∥₂
theIso = equivToIso (forget , record { equiv-proof = isEq })
{- Alternative, less direct proof :
vSES→GroupIso _ _
(ses (isOfHLevelSuc 0 (isContrHⁿ-Unit n))
(isOfHLevelSuc 0 (isContrHⁿ-Unit (suc n)))
(I.d (suc n))
(I.Δ (suc (suc n)))
(I.i (suc (suc n)))
(I.Ker-i⊂Im-d (suc n))
(I.Ker-Δ⊂Im-i (suc (suc n))))
-}
wedgeConnected : ((x : typ A) → ∥ pt A ≡ x ∥) → ((x : typ B) → ∥ pt B ≡ x ∥) → (x : A ⋁ B) → ∥ inl (pt A) ≡ x ∥
wedgeConnected conA conB =
PushoutToProp (λ _ → propTruncIsProp)
(λ a → pRec propTruncIsProp (λ p → ∣ cong inl p ∣₁) (conA a))
λ b → pRec propTruncIsProp (λ p → ∣ push tt ∙ cong inr p ∣₁) (conB b)
|
{
"alphanum_fraction": 0.49595975,
"avg_line_length": 53.325203252,
"ext": "agda",
"hexsha": "21767844e61b004b4cb871a036c3c19cd59f3169",
"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": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ayberkt/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f25b8479fe8160fa4ddbb32e288ba26be6cc242f",
"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": "ayberkt/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Groups/Wedge.agda",
"max_line_length": 154,
"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/ZCohomology/Groups/Wedge.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2314,
"size": 6559
}
|
module Generic.Test.Data.W where
open import Generic.Main
data W′ {α β} (A : Set α) (B : A -> Set β) : Set (α ⊔ β) where
sup′ : ∀ {x} -> (B x -> W′ A B) -> W′ A B
W : ∀ {α β} -> (A : Set α) -> (A -> Set β) -> Set (α ⊔ β)
W = readData W′
pattern sup x g = !#₀ (relv x , g , lrefl)
elimW : ∀ {α β π} {A : Set α} {B : A -> Set β}
-> (P : W A B -> Set π)
-> (∀ {x} {g : B x -> W A B} -> (∀ y -> P (g y)) -> P (sup x g))
-> ∀ w
-> P w
elimW {B = B} P h (sup x g) = h (λ y -> elimW {B = B} P h (g y))
|
{
"alphanum_fraction": 0.4087452471,
"avg_line_length": 27.6842105263,
"ext": "agda",
"hexsha": "779810c2a4754ec7122cf17a83f556b940428533",
"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/Test/Data/W.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/Test/Data/W.agda",
"max_line_length": 70,
"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/Test/Data/W.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": 234,
"size": 526
}
|
{-# OPTIONS --safe --warning=error #-}
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Logic.PropositionalLogic
module ExampleSheets.LogicAndSets.Sheet1 where
q1i : {a : _} {A : Set a} → (p1 p2 p3 : Propositions A) → Tautology (implies (implies p1 (implies p2 p3)) (implies p2 (implies p1 p3)))
Tautology.isTaut (q1i p1 p2 p3) {v} with inspect (Valuation.v v p3)
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolTrue with≡ p3T = Valuation.vImplicationT v (Valuation.vImplicationT v (Valuation.vImplicationT v p3T))
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolFalse with≡ p3F with inspect (Valuation.v v p2)
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolFalse with≡ p3F | BoolTrue with≡ p2T with inspect (Valuation.v v p1)
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolFalse with≡ p3F | BoolTrue with≡ p2T | BoolTrue with≡ p1T = Valuation.vImplicationVacuous v (Valuation.vImplicationF v p1T (Valuation.vImplicationF v p2T p3F))
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolFalse with≡ p3F | BoolTrue with≡ p2T | BoolFalse with≡ p1F = Valuation.vImplicationT v (Valuation.vImplicationT v (Valuation.vImplicationVacuous v p1F))
Tautology.isTaut (q1i p1 p2 p3) {v} | BoolFalse with≡ p3F | BoolFalse with≡ p2F = Valuation.vImplicationT v (Valuation.vImplicationVacuous v p2F)
|
{
"alphanum_fraction": 0.7375189107,
"avg_line_length": 77.7647058824,
"ext": "agda",
"hexsha": "fff8104f3877172783bb2223e95dcc30b4a7b1f5",
"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": "ExampleSheets/LogicAndSets/Sheet1.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": "ExampleSheets/LogicAndSets/Sheet1.agda",
"max_line_length": 203,
"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": "ExampleSheets/LogicAndSets/Sheet1.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": 516,
"size": 1322
}
|
module Numeral.Natural.Oper.Modulo.Proofs.Elim where
import Lvl
open import Data.Boolean.Stmt
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Inductions
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.DivMod.Proofs
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Relator
open import Structure.Relator.Ordering
open import Structure.Relator.Properties
open import Type
mod-elim : ∀{ℓ} → (P : {ℕ} → ℕ → Type{ℓ}) → ∀{b} ⦃ _ : IsTrue(positive?(b)) ⦄ → (∀{a n} → (a < b) → P{a + (n ⋅ b)}(a)) → (∀{a} → P{a}(a mod b))
mod-elim P {𝐒 b} proof {a} with [<][≥]-dichotomy {a}{𝐒 b}
... | [∨]-introₗ lt = substitute₂(\x y → P{x}(y))
(reflexivity(_≡_))
(symmetry(_≡_) (mod-lesser-than-modulus ⦃ [≤]-without-[𝐒] lt ⦄))
(proof{a}{0} lt)
... | [∨]-introᵣ ge = substitute₂(\x y → P{x}(y))
([↔]-to-[→] ([−₀][+]-nullify2ᵣ {(a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b)}{a}) (subtransitivityᵣ(_≤_)(_≡_) ([≤]-of-[+]ₗ {(a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b)}{a mod 𝐒(b)}) ([⌊/⌋][mod]-is-division-with-remainder {a}{b})))
(symmetry(_≡_) ([⌊/⌋][⋅]-inverseOperatorᵣ-error {a}{b}))
(proof{a −₀ ((a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b))}{a ⌊/⌋ 𝐒(b)} (subtransitivityₗ(_<_)(_≡_) (symmetry(_≡_) ([⌊/⌋][⋅]-inverseOperatorᵣ-error {a}{b})) (mod-maxᵣ{a}{𝐒 b})))
|
{
"alphanum_fraction": 0.6622641509,
"avg_line_length": 46.7647058824,
"ext": "agda",
"hexsha": "649a77b72714143a4900b221733ad648d9f4492c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Numeral/Natural/Oper/Modulo/Proofs/Elim.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Oper/Modulo/Proofs/Elim.agda",
"max_line_length": 183,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Numeral/Natural/Oper/Modulo/Proofs/Elim.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": 668,
"size": 1590
}
|
module Structure.Container.Iterable where
import Lvl
open import Data
open import Data.Boolean
open import Data.Option
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Functional
import Structure.Container.IndexedIterable
open import Type
private variable ℓ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
private variable T : Type{ℓ}
private variable Elem : Type{ℓₑ}
open Structure.Container.IndexedIterable{Index = Unit{Lvl.𝟎}} hiding (Iterable ; module Iterable)
module Iterable{ℓ}{Iter} = Structure.Container.IndexedIterable.Iterable{Index = Unit{Lvl.𝟎}}{ℓ}{Iter = const Iter}
Iterable : ∀{ℓ} → Type{ℓ} → ∀{ℓₑ} → Type
Iterable{ℓ} Iter {ℓₑ} = Structure.Container.IndexedIterable.Iterable{Index = Unit{Lvl.𝟎}}{ℓ}(const Iter){ℓₑ}
module _ {Iter : Type{ℓ}} (iterator : Iterable(Iter){ℓₑ}) where
open Iterable(iterator)
next : Iter → Option(Element ⨯ Iter)
next(i) with isEmpty(i) | indexStep i | current i | step i
... | 𝑇 | <> | <> | <> = None
... | 𝐹 | _ | x | is = Some(x , is)
head : Iter → Option(Element)
head(i) with isEmpty(i) | indexStep i | current i
... | 𝑇 | <> | <> = None
... | 𝐹 | _ | x = Some(x)
tail : Iter → Option(Iter)
tail(i) with isEmpty(i) | indexStep i | step i
... | 𝑇 | <> | <> = None
... | 𝐹 | _ | is = Some(is)
tail₀ : Iter → Iter
tail₀(i) with isEmpty(i) | indexStep i | step i
... | 𝑇 | <> | <> = i
... | 𝐹 | _ | is = is
{-
record Finite : Type{ℓ} where
field
length : I → ℕ
field
length-proof : LengthCriteria(length)
--field
-- length-when-empty : ∀{i} → IsTrue (isEmpty(i)) → (length(i) ≡ 𝟎)
-- length-when-nonempty : ∀{i} → IsFalse(isEmpty(i)) → ∃(n ↦ length(i) ≡ 𝐒(n))
-- length-of-step : ∀{i} → IsFalse(isEmpty(i)) → (𝐒(length(step i)) ≡ length(i)))
-- empty-on-length-step : ∀{i} → IsTrue(isEmpty₊(length(i)) i)
-- length-minimal-empty-step : ∀{n}{i} → (n < length(i)) → IsFalse(isEmpty₊(n) i)
open Finite ⦃ … ⦄ public
-}
-- TODO: It is possible for Finite and the constructions to be from different iterables
module _
⦃ fin : Finite ⦄
{prepend : (x : Element) → (iter : Iter) → Iter}
⦃ prepend-construction : PrependConstruction(prepend) ⦄
where
_++_ : Iter → Iter → Iter
_++_ = swap(foldᵣ prepend)
module _
⦃ fin : Finite ⦄
{empty}
⦃ empty-construciton : EmptyConstruction(empty) ⦄
{prepend : (x : Element) → (iter : Iter) → Iter}
⦃ prepend-construction : PrependConstruction(prepend) ⦄
where
map : (Element → Element) → (Iter → Iter)
map f = foldᵣ (prepend ∘ f) empty
filter : (Element → Bool) → Iter → Iter
filter f = foldᵣ (x ↦ if f(x) then (prepend x) else id) empty
reverse : Iter → Iter
reverse = foldₗ (swap prepend) empty
postpend : Element → Iter → Iter
postpend = foldᵣ prepend ∘ singleton
open import Numeral.Natural
repeat : Element → ℕ → Iter
repeat x 𝟎 = empty
repeat x (𝐒(n)) = prepend x (repeat x n)
|
{
"alphanum_fraction": 0.6069635085,
"avg_line_length": 32.1182795699,
"ext": "agda",
"hexsha": "f583d12d1720cec4429439e2481553cfc048bf0c",
"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/Container/Iterable.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/Container/Iterable.agda",
"max_line_length": 114,
"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/Container/Iterable.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": 1024,
"size": 2987
}
|
-- Private signatures
module Issue476d where
module M where
private
record R : Set₁
record R where
field X : Set
Q : Set₁
Q = M.R
|
{
"alphanum_fraction": 0.6666666667,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "599b9ca688f61742380e796b404d3d2af04adb9c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue476d.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/fail/Issue476d.agda",
"max_line_length": 22,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/fail/Issue476d.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": 44,
"size": 144
}
|
-- {-# OPTIONS --show-implicit #-}
-- {-# OPTIONS -v term:20 -v term.function:30 #-}
-- Andreas, 2015-05-31, issue reported by Bruno Bianchi
module Issue1530 {A : Set}(_<=_ : A -> A -> Set) where
open import Common.List
open import Issue1530.Bound _<=_
data OList : Bound -> Set where
nil : {b : Bound} -> OList b
cons : {b : Bound}{x : A} -> LeB b (val x) -> OList (val x) -> OList b
forget : {b : Bound} -> OList b -> List A
forget nil = []
forget (cons {x = x} _ xs) = x ∷ forget xs
data Sorted : List A -> Set where
empty : Sorted []
single : (x : A) -> Sorted (x ∷ [])
step : {x y : A}{ys : List A} -> x <= y -> Sorted (y ∷ ys) -> Sorted (x ∷ y ∷ ys)
olist-sorted : {b : Bound}(xs : OList b) -> Sorted (forget xs)
olist-sorted nil = empty
olist-sorted (cons {x = x} _ nil) = single x
olist-sorted (cons b<=x (cons (lexy x<=y) ys)) = step x<=y (olist-sorted (cons (lexy x<=y) ys))
-- should termination check
-- problem WAS: TermCheck did not *deeply* resolve constructor names on rhs in last clause.
-- TermCheck.reduceCon did not reduce the lexy on the rhs, as it was deep inside.
|
{
"alphanum_fraction": 0.6130198915,
"avg_line_length": 33.5151515152,
"ext": "agda",
"hexsha": "d8d630eb5c95eef9ce9396893b2aea1a232af9fc",
"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/Issue1530.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/Issue1530.agda",
"max_line_length": 95,
"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/Issue1530.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": 367,
"size": 1106
}
|
-- Andreas, 2019-08-17, issue #1346
open import Issue1346
-- Repeating the definitions of Issue1346.agda
private
test₁ : List⁺ Bool
test₁ = true ∷ false ∷ [] -- mixing _∷_ of _×_ and List
test₂ : ∀{A : Set} → A → List A × List⁺ A × List⁺ A
test₂ a = [] , a ∷ [] , a ∷ a ∷ [] -- mixing _,_ and _∷_ of _×_
|
{
"alphanum_fraction": 0.5817610063,
"avg_line_length": 24.4615384615,
"ext": "agda",
"hexsha": "c29ec7ec94800ddc99ee7bae4fd38a5a9093ee1d",
"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/Issue1346Import.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/Issue1346Import.agda",
"max_line_length": 66,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1346Import.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 129,
"size": 318
}
|
firstTrue : (f : ℕ → Bool) → ∃ (λ n → f n ≡ true) → ℕ
firstTrue f prf = mp-ℕ
firstTrue-true : firstTrue f prf ≡ n → f n ≡ true
firstTrue-true = ?
firstTrue-false : firstTrue f prf ≡ n → ∀ m → m < n → f m ≡ false
firstTrue-false = ?
|
{
"alphanum_fraction": 0.5897435897,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "743f305dd37374a8d92ba50399b13e4a334ee0ce",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Search.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Search.agda",
"max_line_length": 65,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Search.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 96,
"size": 234
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --experimental-lossy-unification #-}
module Cubical.ZCohomology.Groups.RP2 where
open import Cubical.ZCohomology.Base
open import Cubical.ZCohomology.GroupStructure
open import Cubical.ZCohomology.Properties
open import Cubical.ZCohomology.Groups.KleinBottle
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.GroupoidLaws
open import Cubical.HITs.SetTruncation renaming (rec to sRec ; rec2 to pRec2 ; elim to sElim ; elim2 to sElim2 ; map to sMap)
open import Cubical.HITs.PropositionalTruncation renaming (rec to pRec ; elim to pElim) hiding (map)
open import Cubical.HITs.Truncation renaming (elim to trElim ; rec to trRec ; elim2 to trElim2)
open import Cubical.Algebra.Group
open import Cubical.Foundations.Equiv.HalfAdjoint
open import Cubical.Foundations.Transport
open import Cubical.ZCohomology.Groups.Connected
open import Cubical.Data.Sigma
open import Cubical.Foundations.Isomorphism
open import Cubical.HITs.S1
open import Cubical.HITs.Sn
open import Cubical.Foundations.Equiv
open import Cubical.Homotopy.Connected
open import Cubical.HITs.RPn.Base
open GroupIso renaming (map to map')
open GroupHom
open import Cubical.Data.Empty renaming (rec to ⊥-rec)
open import Cubical.Data.Bool
open import Cubical.Data.Int
open import Cubical.Foundations.Path
private
variable
ℓ : Level
A : Type ℓ
funSpaceIso-RP² : Iso (RP² → A) (Σ[ x ∈ A ] Σ[ p ∈ x ≡ x ] p ≡ sym p)
Iso.fun funSpaceIso-RP² f = f point , (cong f line , λ i j → f (square i j))
Iso.inv funSpaceIso-RP² (x , p , P) point = x
Iso.inv funSpaceIso-RP² (x , p , P) (line i) = p i
Iso.inv funSpaceIso-RP² (x , p , P) (square i j) = P i j
Iso.rightInv funSpaceIso-RP² (x , p , P) i = x , p , P
Iso.leftInv funSpaceIso-RP² f _ point = f point
Iso.leftInv funSpaceIso-RP² f _ (line i) = f (line i)
Iso.leftInv funSpaceIso-RP² f _ (square i j) = f (square i j)
private
pathIso : {x : A} {p : x ≡ x} → Iso (p ≡ sym p) (p ∙ p ≡ refl)
pathIso {p = p} = compIso (congIso (equivToIso (_ , compPathr-isEquiv p)))
(pathToIso (cong (p ∙ p ≡_) (lCancel p)))
--- H⁰(RP²) ≅ ℤ ----
H⁰-RP²≅ℤ : GroupIso (coHomGr 0 RP²) intGroup
H⁰-RP²≅ℤ = H⁰-connected point connectedRP¹
where
connectedRP¹ : (x : RP²) → ∥ point ≡ x ∥
connectedRP¹ point = ∣ refl ∣
connectedRP¹ (line i) =
isOfHLevel→isOfHLevelDep 1 {B = λ x → ∥ point ≡ x ∥}
(λ _ → propTruncIsProp) ∣ refl ∣ ∣ refl ∣ line i
connectedRP¹ (square i j) = helper i j
where
helper : SquareP (λ i j → ∥ point ≡ square i j ∥)
(isOfHLevel→isOfHLevelDep 1 {B = λ x → ∥ point ≡ x ∥}
(λ _ → propTruncIsProp) ∣ refl ∣ ∣ refl ∣ line)
(symP (isOfHLevel→isOfHLevelDep 1 {B = λ x → ∥ point ≡ x ∥}
(λ _ → propTruncIsProp) ∣ refl ∣ ∣ refl ∣ line))
refl refl
helper = toPathP (isOfHLevelPathP 1 propTruncIsProp _ _ _ _)
--- H¹(RP²) ≅ 0 ----
isContr-H¹-RP²-helper : isContr ∥ Σ[ x ∈ coHomK 1 ] Σ[ p ∈ x ≡ x ] p ∙ p ≡ refl ∥₂
fst isContr-H¹-RP²-helper = ∣ 0ₖ 1 , refl , sym (rUnit refl) ∣₂
snd isContr-H¹-RP²-helper =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry
(trElim (λ _ → isGroupoidΠ λ _ → isOfHLevelPlus {n = 1} 2 (setTruncIsSet _ _))
(toPropElim (λ _ → isPropΠ (λ _ → setTruncIsSet _ _))
λ {(p , nilp)
→ cong ∣_∣₂ (ΣPathP (refl , Σ≡Prop (λ _ → isOfHLevelTrunc 3 _ _ _ _)
(rUnit refl
∙∙ cong (Kn→ΩKn+1 0) (sym (nilpotent→≡0 (ΩKn+1→Kn 0 p)
(sym (ΩKn+1→Kn-hom 0 p p)
∙ cong (ΩKn+1→Kn 0) nilp)))
∙∙ Iso.rightInv (Iso-Kn-ΩKn+1 0) p)))})))
H¹-RP²≅0 : GroupIso (coHomGr 1 RP²) trivialGroup
H¹-RP²≅0 =
IsoContrGroupTrivialGroup
(isOfHLevelRetractFromIso 0
(setTruncIso (compIso funSpaceIso-RP²
(Σ-cong-iso-snd (λ _ → Σ-cong-iso-snd λ _ → pathIso))))
isContr-H¹-RP²-helper)
--- H²(RP²) ≅ ℤ/2ℤ ----
Iso-H²-RP²₁ : Iso ∥ Σ[ x ∈ coHomK 2 ] Σ[ p ∈ x ≡ x ] p ≡ sym p ∥₂
∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ≡ sym p ∥₂
Iso.fun Iso-H²-RP²₁ =
sRec setTruncIsSet
(uncurry
(trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 2} 2 setTruncIsSet)
(sphereElim _ (λ _ → isSetΠ (λ _ → setTruncIsSet))
λ p → ∣ fst p , snd p ∣₂)))
Iso.inv Iso-H²-RP²₁ = sMap λ p → (0ₖ 2) , p
Iso.rightInv Iso-H²-RP²₁ = sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
λ _ → refl
Iso.leftInv Iso-H²-RP²₁ =
sElim (λ _ → isOfHLevelPath 2 setTruncIsSet _ _)
(uncurry (trElim (λ _ → is2GroupoidΠ λ _ → isOfHLevelPlus {n = 1} 3 (setTruncIsSet _ _))
(sphereToPropElim _ (λ _ → isPropΠ (λ _ → setTruncIsSet _ _))
λ p → refl)))
Iso-H²-RP²₂ : Iso ∥ Σ[ p ∈ 0ₖ 2 ≡ 0ₖ 2 ] p ≡ sym p ∥₂ Bool
Iso-H²-RP²₂ = compIso (setTruncIso (Σ-cong-iso-snd λ _ → pathIso))
(compIso Iso-H²-𝕂²₂ testIso)
H²-RP²≅Bool : GroupIso (coHomGr 2 RP²) BoolGroup
H²-RP²≅Bool = invGroupIso (≅Bool (compIso
(compIso (setTruncIso funSpaceIso-RP²)
Iso-H²-RP²₁)
Iso-H²-RP²₂))
|
{
"alphanum_fraction": 0.597538907,
"avg_line_length": 41.8636363636,
"ext": "agda",
"hexsha": "40de8a2bfe5b7cd618f62d7c10272a8ec135dc77",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/ZCohomology/Groups/RP2.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"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": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/ZCohomology/Groups/RP2.agda",
"max_line_length": 125,
"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/ZCohomology/Groups/RP2.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2017,
"size": 5526
}
|
{-# OPTIONS --without-K --safe #-}
module Definition.Typed.Consequences.Consistency where
open import Definition.Untyped
open import Definition.Typed
open import Definition.Typed.Properties
open import Definition.Typed.EqRelInstance
open import Definition.LogicalRelation
open import Definition.LogicalRelation.Irrelevance
open import Definition.LogicalRelation.ShapeView
open import Definition.LogicalRelation.Fundamental.Reducibility
open import Tools.Embedding
open import Tools.Empty
open import Tools.Product
import Tools.PropositionalEquality as PE
zero≢one′ : ∀ {Γ l} ([ℕ] : Γ ⊩⟨ l ⟩ℕ ℕ)
→ Γ ⊩⟨ l ⟩ zero ≡ suc zero ∷ ℕ / ℕ-intr [ℕ] → ⊥
zero≢one′ (noemb x) (ιx (ℕₜ₌ .(suc _) .(suc _) d d′ k≡k′ (sucᵣ x₁))) =
zero≢suc (whnfRed*Term (redₜ d) zeroₙ)
zero≢one′ (noemb x) (ιx (ℕₜ₌ .zero .zero d d′ k≡k′ zeroᵣ)) =
zero≢suc (PE.sym (whnfRed*Term (redₜ d′) sucₙ))
zero≢one′ (noemb x) (ιx (ℕₜ₌ k k′ d d′ k≡k′ (ne (neNfₜ₌ neK neM k≡m)))) =
zero≢ne neK (whnfRed*Term (redₜ d) zeroₙ)
zero≢one′ (emb 0<1 [ℕ]) (ιx n) = zero≢one′ [ℕ] n
-- Zero cannot be judgmentally equal to one.
zero≢one : ∀ {Γ} → Γ ⊢ zero ≡ suc zero ∷ ℕ → ⊥
zero≢one 0≡1 =
let [ℕ] , [0≡1] = reducibleEqTerm 0≡1
in zero≢one′ (ℕ-elim [ℕ]) (irrelevanceEqTerm [ℕ] (ℕ-intr (ℕ-elim [ℕ])) [0≡1])
|
{
"alphanum_fraction": 0.6784037559,
"avg_line_length": 36.5142857143,
"ext": "agda",
"hexsha": "825ecc5a83c7559653512e2c63b5ddb57df73f60",
"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/Consequences/Consistency.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/Consequences/Consistency.agda",
"max_line_length": 80,
"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/Consequences/Consistency.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 526,
"size": 1278
}
|
{-# OPTIONS --cubical #-}
open import Agda.Builtin.Nat
open import Agda.Builtin.Cubical.Path
postulate
admit : ∀ {A : Set} → A
data Z : Set where
pos : Nat → Z
neg : Nat → Z
sameZero : pos 0 ≡ neg 0
_+Z_ : Z → Z → Z
pos x +Z pos y = admit
pos x +Z neg y = admit
pos x +Z sameZero y = admit
neg x +Z z = admit
sameZero x +Z z = admit
|
{
"alphanum_fraction": 0.5260545906,
"avg_line_length": 20.15,
"ext": "agda",
"hexsha": "c0ba30eb02b8584834947a1418861ccdcff6dc98",
"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": "5953ce337eb6b77b29ace7180478f49c541aea1c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "zgrannan/agda",
"max_forks_repo_path": "test/Succeed/Issue3314.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5953ce337eb6b77b29ace7180478f49c541aea1c",
"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": "zgrannan/agda",
"max_issues_repo_path": "test/Succeed/Issue3314.agda",
"max_line_length": 37,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5953ce337eb6b77b29ace7180478f49c541aea1c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "zgrannan/agda",
"max_stars_repo_path": "test/Succeed/Issue3314.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 141,
"size": 403
}
|
module Stable where
open import Data.Product using (_×_; proj₁; proj₂) renaming (_,_ to ⟨_,_⟩)
open import Negation using (¬_; ¬¬¬-elim)
Stable : Set → Set
Stable A = ¬ ¬ A → A
¬-stable : ∀ {A : Set} → Stable (¬ A)
¬-stable = λ ¬¬¬a → (λ a → ¬¬¬a (λ ¬a → ¬a a))
-- ¬-stable = ¬¬¬-elim
×-stable : ∀ {A B : Set} → Stable A → Stable B → Stable (A × B)
×-stable sa sb = λ ¬¬a×b →
⟨ (sa λ{ ¬a → ¬¬a×b λ{ a×b → ¬a (proj₁ a×b) }})
, (sb λ{ ¬b → ¬¬a×b λ{ a×b → ¬b (proj₂ a×b) }})
⟩
|
{
"alphanum_fraction": 0.4948453608,
"avg_line_length": 25.5263157895,
"ext": "agda",
"hexsha": "6fc9ff43ee052fffa2f319793320c65b9eb0476f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "akiomik/plfa-solutions",
"max_forks_repo_path": "part1/negation/Stable.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "akiomik/plfa-solutions",
"max_issues_repo_path": "part1/negation/Stable.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df7722b88a9b3dfde320a690b78c4c1ef8c7c547",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "akiomik/plfa-solutions",
"max_stars_repo_path": "part1/negation/Stable.agda",
"max_stars_repo_stars_event_max_datetime": "2020-07-07T09:42:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-07T09:42:22.000Z",
"num_tokens": 216,
"size": 485
}
|
data Term (V : Set) : Set where
App : Term V -> Term V -> Term V
Abs : (V -> Term V) -> Term V -- ouch, posititity.
|
{
"alphanum_fraction": 0.55,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "139bcf833dd28a815f97acbedcc0db5f513760b4",
"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": "src/Sigma.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": "src/Sigma.agda",
"max_line_length": 52,
"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": "src/Sigma.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 44,
"size": 120
}
|
{-# OPTIONS --without-K --safe #-}
module Fragment.Examples.Semigroup.Arith.Atomic where
open import Fragment.Examples.Semigroup.Arith.Base
-- Fully dynamic associativity
dyn-assoc₁ : ∀ {m n o} → (m + n) + o ≡ m + (n + o)
dyn-assoc₁ = fragment SemigroupFrex +-semigroup
dyn-assoc₂ : ∀ {m n o p} → ((m + n) + o) + p ≡ m + (n + (o + p))
dyn-assoc₂ = fragment SemigroupFrex +-semigroup
dyn-assoc₃ : ∀ {m n o p q} → (m + n) + o + (p + q) ≡ m + (n + o + p) + q
dyn-assoc₃ = fragment SemigroupFrex +-semigroup
-- Partially static associativity
sta-assoc₁ : ∀ {m n} → (m + 2) + (3 + n) ≡ m + (5 + n)
sta-assoc₁ = fragment SemigroupFrex +-semigroup
sta-assoc₂ : ∀ {m n o p} → (((m + n) + 5) + o) + p ≡ m + (n + (2 + (3 + (o + p))))
sta-assoc₂ = fragment SemigroupFrex +-semigroup
sta-assoc₃ : ∀ {m n o p} → ((m + n) + 2) + (3 + (o + p)) ≡ m + ((n + 1) + (4 + o)) + p
sta-assoc₃ = fragment SemigroupFrex +-semigroup
|
{
"alphanum_fraction": 0.5747001091,
"avg_line_length": 32.75,
"ext": "agda",
"hexsha": "e18c5069c984ff739325cc7c2b31a4274263cbe7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Examples/Semigroup/Arith/Atomic.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Examples/Semigroup/Arith/Atomic.agda",
"max_line_length": 86,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Examples/Semigroup/Arith/Atomic.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": 364,
"size": 917
}
|
-- Andreas, 2012-11-18 see issue 761
module AbstractMutual where
module MA where
mutual
abstract -- accepted
S : Set₁
S = T
T : Set₁
T = Set
module AM where
abstract -- rejected before, should also be accepted
mutual
S : Set₁
S = T
T : Set₁
T = Set
|
{
"alphanum_fraction": 0.5646687697,
"avg_line_length": 12.68,
"ext": "agda",
"hexsha": "25b41c9023f688c5f6928525745c4d2b1457d5ef",
"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/AbstractMutual.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/AbstractMutual.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/AbstractMutual.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": 317
}
|
{-# OPTIONS --safe --warning=error #-}
open import LogicalFormulae
open import Orders
open import Groups.Groups
open import Numbers.Naturals.Naturals
open import Numbers.Naturals.WithK
open import Numbers.Primes.PrimeNumbers
open import Rings.Definition
open import Setoids.Setoids
open import Numbers.Modulo.IntegersModN
open import Semirings.Definition
module IntegersModNRing where
modNToℕ : {n : ℕ} {pr : 0 <N n} → (a : ℤn n pr) → ℕ
modNToℕ record { x = x ; xLess = xLess } = x
*nhelper : {n : ℕ} {pr : 0 <N n} → (max : ℕ) → (a : ℤn n pr) → ℤn n pr → (max ≡ modNToℕ a) → ℤn n pr
*nhelper {zero} {()}
*nhelper {succ n} zero a b pr2 = record { x = 0 ; xLess = succIsPositive n }
*nhelper {succ n} (succ max) record { x = zero ; xLess = xLess } b ()
*nhelper {succ n} (succ max) record { x = (succ x) ; xLess = xLess } b pr2 = (*nhelper max record { x = x ; xLess = xLess2 } b (succInjective pr2)) +n b
where
xLess2 : x <N succ n
xLess2 = PartialOrder.transitive (TotalOrder.order ℕTotalOrder) (a<SuccA x) xLess
_*n_ : {n : ℕ} {pr : 0 <N n} → ℤn n pr → ℤn n pr → ℤn n pr
_*n_ {0} {()}
_*n_ {succ n} {_} record { x = a ; xLess = aLess } b = *nhelper a record { x = a ; xLess = aLess } b refl
ℤnIdent : (n : ℕ) → (pr : 0 <N n) → ℤn n pr
ℤnIdent 0 ()
ℤnIdent 1 pr = record { x = 0 ; xLess = pr }
ℤnIdent (succ (succ n)) _ = record { x = 1 ; xLess = succPreservesInequality (succIsPositive n) }
ℤnMult0Right : {n : ℕ} {pr : 0 <N n} → (max : ℕ) → (a : ℤn n pr) → (modNToℕ a ≡ max) → (a *n record { x = 0 ; xLess = pr }) ≡ record { x = 0 ; xLess = pr }
ℤnMult0Right {0} {()}
ℤnMult0Right {succ n} .zero record { x = zero ; xLess = xLess } refl = equalityZn _ _ refl
ℤnMult0Right {succ n} {pr} (.succ x) record { x = (succ x) ; xLess = xLess } refl rewrite ℤnMult0Right {succ n} {pr} x record { x = x ; xLess = PartialOrder.transitive (TotalOrder.order ℕTotalOrder) (a<SuccA x) xLess } refl = equalityZn _ _ refl
ℤnMultCommutative : {n : ℕ} {pr : 0 <N n} → (a b : ℤn n pr) → (a *n b) ≡ (b *n a)
ℤnMultCommutative {0} {()}
ℤnMultCommutative {succ n} {pr} record { x = zero ; xLess = xLess } b with <NRefl pr xLess
... | refl rewrite ℤnMult0Right (modNToℕ b) b refl = equalityZn _ _ refl
ℤnMultCommutative {succ n} record { x = (succ x) ; xLess = xLess } b = {!!}
ℤnMultIdent : {n : ℕ} {pr : 0 <N n} → (a : ℤn n pr) → (ℤnIdent n pr) *n a ≡ a
ℤnMultIdent {zero} {()}
ℤnMultIdent {succ zero} {pr} record { x = zero ; xLess = (le diff proof) } = equalityZn _ _ refl
ℤnMultIdent {succ zero} {pr} record { x = (succ a) ; xLess = (le diff proof) } = exFalso f
where
f : False
f rewrite Semiring.commutative ℕSemiring diff (succ a) = naughtE (succInjective (equalityCommutative proof))
ℤnMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } with orderIsTotal a (succ (succ n))
ℤnMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } | inl (inl a<ssn) = equalityZn _ _ refl
ℤnMultIdent {succ (succ n)} {pr} record { x = a ; xLess = aLess } | inl (inr ssn<a) = exFalso (PartialOrder.irreflexive (TotalOrder.order ℕTotalOrder) (PartialOrder.transitive (TotalOrder.order ℕTotalOrder) aLess ssn<a))
ℤnMultIdent {succ (succ n)} {pr} record { x = .(succ (succ n)) ; xLess = aLess } | inr refl = exFalso (PartialOrder.irreflexive (TotalOrder.order ℕTotalOrder) aLess)
ℤnRing : (n : ℕ) → (pr : 0 <N n) → Ring (reflSetoid (ℤn n pr)) (_+n_) (_*n_)
Ring.additiveGroup (ℤnRing n 0<n) = (ℤnGroup n 0<n)
Ring.multWellDefined (ℤnRing n 0<n) = reflGroupWellDefined
Ring.1R (ℤnRing n pr) = ℤnIdent n pr
Ring.groupIsAbelian (ℤnRing n 0<n) = AbelianGroup.commutative (ℤnAbGroup n 0<n)
Ring.multAssoc (ℤnRing n 0<n) = {!!}
Ring.multCommutative (ℤnRing n 0<n) {a} {b} = ℤnMultCommutative a b
Ring.multDistributes (ℤnRing n 0<n) = {!!}
Ring.multIdentIsIdent (ℤnRing n 0<n) {a} = ℤnMultIdent a
|
{
"alphanum_fraction": 0.6330510649,
"avg_line_length": 57.3088235294,
"ext": "agda",
"hexsha": "bc88234178098ab362458cf4de4fa6fe31894365",
"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": "IntegersModNRing.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": "IntegersModNRing.agda",
"max_line_length": 247,
"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": "IntegersModNRing.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": 1560,
"size": 3897
}
|
open import Type
module Graph.Properties where
open import Functional
open import Function.Equals
open import Lang.Instance
open import Logic
open import Logic.Propositional
import Lvl
open import Graph
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Setoid.Uniqueness
open import Structure.Relator.Properties
open import Type.Properties.MereProposition
module _ {ℓ₁ ℓ₂} {V : Type{ℓ₁}} (_⟶_ : Graph{ℓ₁}{ℓ₂}(V)) where
-- An undirected graph always have for every edge an edge in the other direction which is the same edge.
record Undirected : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ reversable ⦄ : Symmetry(_⟶_)
reverse = symmetry(_⟶_)
field
reverse-involution : ∀{a b} → (reverse ∘ reverse ⊜ (id {T = a ⟶ b}))
undirected-reverse = inst-fn Undirected.reverse
-- Construction of an undirected graph from any graph.
undirect : Graph{ℓ₁}{ℓ₂}(V)
undirect a b = (b ⟶ a) ∨ (a ⟶ b)
-- A graph is singular when there is at most one edge between every pair of vertices.
-- In other words, when it is not a multigraph.
-- Note: Equality on edges must respect uniqueness. In other words, one edge must not have multiple constructions.
record Singular : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{a b : V} → MereProposition(a ⟶ b)
singular = inst-fn(\inst {a}{b}{x}{y} → MereProposition.uniqueness(Singular.proof inst {a}{b}) {x}{y})
-- A complete graph have an edge for each pair of vertices from V. Loops are allowed.
record Complete : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x y : V} → (x ⟶ y) ↔ (x ≢ y)
complete = inst-fn Complete.proof
record CompleteWithLoops : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x y : V} → (x ⟶ y)
completeWithLoops = inst-fn CompleteWithLoops.proof
-- A linear graph contains vertices with a maximum of one outgoing edge and a maximum of one ingoing edge.
record Linear : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
unique-start-vertex : ∀{y} → Unique(x ↦ (x ⟶ y))
unique-end-vertex : ∀{x} → Unique(y ↦ (x ⟶ y))
module _ (v : V) where
-- An initial vertex have no ingoing edges pointing towards it.
record InitialVertex : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x} → ¬(x ⟶ v)
initialVertex = inst-fn InitialVertex.proof
-- A final vertex have no outgoing edges pointing from it.
record FinalVertex : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x} → ¬(v ⟶ x)
finalVertex = inst-fn FinalVertex.proof
-- A graph is a list when it is linear and has an unique initial vertex and an unique final vertex.
-- The linearity guarantees so that if there are preceding and succeding elements of the list, they are unique.
-- The initial vertex represents the first element of the list.
-- The final vertex represents the last element of the list.
record IsList : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ linear ⦄ : Linear
unique-initial-vertex : Unique(InitialVertex)
unique-final-vertex : Unique(FinalVertex)
-- A graph is a cycle when it is linear and do not have initial or final vertices.
-- The linearity guarantees so that if there are preceding and succeding elements of the list, they are unique.
-- The non-existence of initial vertices and final vertices means no first and last elements.
record IsCycle : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ linear ⦄ : Linear
no-initial-vertex : ∀{v} → ¬(InitialVertex v)
no-final-vertex : ∀{v} → ¬(FinalVertex v)
module _ where
open import Graph.Walk
open import Graph.Walk.Properties
-- A graph is a tree when it has an unique path between every pair of vertices.
-- The existence of a path means that it is always possible to traverse the tree from every vertex along the edges to every vertex.
record IsTree : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x y : V} → ∃!{Obj = Walk(_⟶_) x y}(Path)
isTree = inst-fn IsTree.proof
record IsForest : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{x y : V} → Unique{Obj = Walk(_⟶_) x y}(Path)
isForest = inst-fn IsForest.proof
record IsOutwardRootedTree : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ tree ⦄ : IsTree
unique-initial-vertex : ∃!(InitialVertex)
-- TODO: Should not this be defined as ∃!(root ↦ InitialVertex(root) ∧ (∀{x : V} → ∃!{T = Walk(_⟶_) root x}(Path))) ?
record IsInwardRootedTree : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field
⦃ tree ⦄ : IsTree
unique-initial-vertex : ∃!(FinalVertex)
module _ {ℓ₁ ℓ₂} {V : Type{ℓ₁}} (_⟶_ : Graph{ℓ₁}{ℓ₂}(V)) where
open import Graph.Walk
-- A connected graph have walks from every vertex to any vertex.
-- For undirected graphs, this can be visually interpreted as disconnected islands of vertices.
-- Note: Equality on edges must respect uniqueness. In other words, one edge must not have multiple constructions.
Connected = CompleteWithLoops(Walk(_⟶_))
connected = completeWithLoops(Walk(_⟶_))
|
{
"alphanum_fraction": 0.6818008394,
"avg_line_length": 40.0152671756,
"ext": "agda",
"hexsha": "44557c8b9067ac6a2044db8f466b929f8c752be9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Graph/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Graph/Properties.agda",
"max_line_length": 135,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Graph/Properties.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": 1575,
"size": 5242
}
|
open import Oscar.Prelude
open import Oscar.Class
open import Oscar.Class.Unit
module Oscar.Class.Surjection where
module Surjection
{𝔬₁} (𝔒₁ : Ø 𝔬₁)
{𝔬₂} (𝔒₂ : Ø 𝔬₂)
= ℭLASS (𝔒₁ , 𝔒₂) (𝔒₁ → 𝔒₂)
module _
{𝔬₁} {𝔒₁ : Ø 𝔬₁}
{𝔬₂} {𝔒₂ : Ø 𝔬₂}
where
surjection = Surjection.method 𝔒₁ 𝔒₂
instance
Surjection-toUnit : ⦃ _ : Surjection.class 𝔒₁ 𝔒₂ ⦄ → Unit.class (Surjection.type 𝔒₁ 𝔒₂)
Surjection-toUnit .⋆ = surjection
|
{
"alphanum_fraction": 0.6659090909,
"avg_line_length": 20.9523809524,
"ext": "agda",
"hexsha": "6550384532ac705bfa992314e015d9b531b5700d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-3/src/Oscar/Class/Surjection.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-3/src/Oscar/Class/Surjection.agda",
"max_line_length": 91,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-3/src/Oscar/Class/Surjection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 212,
"size": 440
}
|
-- 2014-09-19
-- Reported by Mateusz Kowalczyk.
good : Set₁
good = let -- F : _ -- worked if you added the type signature
F X = X
in F Set
-- Now works without the type signature.
|
{
"alphanum_fraction": 0.615,
"avg_line_length": 22.2222222222,
"ext": "agda",
"hexsha": "ded4c08d4fb74ac1750c0a944ee71a771e6b1209",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue1028.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "test/succeed/Issue1028.agda",
"max_line_length": 62,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "masondesu/agda",
"max_stars_repo_path": "test/succeed/Issue1028.agda",
"max_stars_repo_stars_event_max_datetime": "2018-10-10T17:08:44.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-10T17:08:44.000Z",
"num_tokens": 61,
"size": 200
}
|
{-# OPTIONS --safe --experimental-lossy-unification #-}
module Cubical.Algebra.CommRing.Instances.MultivariatePoly where
open import Cubical.Foundations.Prelude
open import Cubical.Data.Nat renaming(_+_ to _+n_; _·_ to _·n_)
open import Cubical.Data.Vec
open import Cubical.Algebra.Ring
open import Cubical.Algebra.CommRing
open import Cubical.Algebra.Polynomials.Multivariate.Base
open import Cubical.Algebra.Polynomials.Multivariate.Properties
private variable
ℓ ℓ' : Level
module _ (A' : CommRing ℓ) (n : ℕ) where
private
A = fst A'
Ar = CommRing→Ring A'
open CommRingStr
open RingTheory Ar
open Nth-Poly-structure A' n
PolyCommRing : CommRing ℓ
fst PolyCommRing = Poly A' n
0r (snd PolyCommRing) = 0P
1r (snd PolyCommRing) = 1P
_+_ (snd PolyCommRing) = _Poly+_
_·_ (snd PolyCommRing) = _Poly*_
- snd PolyCommRing = Poly-inv
isCommRing (snd PolyCommRing) = makeIsCommRing
trunc
Poly+-assoc
Poly+-Rid
Poly+-rinv
Poly+-comm
Poly*-assoc
Poly*-Rid
Poly*-Rdist
Poly*-comm
|
{
"alphanum_fraction": 0.5704545455,
"avg_line_length": 28.6956521739,
"ext": "agda",
"hexsha": "35bb8eb45ef58aa65e00bd17313a559c3a1fcd7e",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "howsiyu/cubical",
"max_forks_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "howsiyu/cubical",
"max_issues_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda",
"max_line_length": 64,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1b9c97a2140fe96fe636f4c66beedfd7b8096e8f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "howsiyu/cubical",
"max_stars_repo_path": "Cubical/Algebra/CommRing/Instances/MultivariatePoly.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 335,
"size": 1320
}
|
test = forall _0_ → Set
|
{
"alphanum_fraction": 0.6666666667,
"avg_line_length": 12,
"ext": "agda",
"hexsha": "2b38f7d2f51fe8a36800eb314785fc9c9c6ee1a9",
"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/InvalidNamePartLiteral.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/InvalidNamePartLiteral.agda",
"max_line_length": 23,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/InvalidNamePartLiteral.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": 9,
"size": 24
}
|
module Human.List where
open import Human.Nat
infixr 5 _,_
data List {a} (A : Set a) : Set a where
end : List A
_,_ : (x : A) (xs : List A) → List A
{-# BUILTIN LIST List #-}
{-# COMPILE JS List = function(x,v) { if (x.length < 1) { return v["[]"](); } else { return v["_∷_"](x[0], x.slice(1)); } } #-}
{-# COMPILE JS end = Array() #-}
{-# COMPILE JS _,_ = function (x) { return function(y) { return Array(x).concat(y); }; } #-}
foldr : ∀ {A : Set} {B : Set} → (A → B → B) → B → List A → B
foldr c n end = n
foldr c n (x , xs) = c x (foldr c n xs)
length : ∀ {A : Set} → List A → Nat
length = foldr (λ a n → suc n) zero
|
{
"alphanum_fraction": 0.5290423862,
"avg_line_length": 28.9545454545,
"ext": "agda",
"hexsha": "f83121ae1befbe9c6db4fba920d81f077b94ca04",
"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": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MaisaMilena/AgdaCalculator",
"max_forks_repo_path": "src/Human/List.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"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": "MaisaMilena/AgdaCalculator",
"max_issues_repo_path": "src/Human/List.agda",
"max_line_length": 128,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "e977a5f2a005682cee123568b49462dd7d7b11ad",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MaisaMilena/AgdaCalculator",
"max_stars_repo_path": "src/Human/List.agda",
"max_stars_repo_stars_event_max_datetime": "2019-03-29T02:30:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-03-29T02:30:10.000Z",
"num_tokens": 236,
"size": 637
}
|
module Auxiliary where
open import Agda.Primitive
open import Data.List
open import Data.Nat renaming (_+_ to _+ᴺ_ ; _≤_ to _≤ᴺ_ ; _≥_ to _≥ᴺ_ ; _<_ to _<ᴺ_ ; _>_ to _>ᴺ_)
open import Data.Nat.Properties
open import Data.Integer renaming (_+_ to _+ᶻ_ ; _≤_ to _≤ᶻ_ ; _≥_ to _≥ᶻ_ ; _<_ to _<ᶻ_ ; _>_ to _>ᶻ_)
import Data.Integer.Properties
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary
open import Relation.Nullary.Negation
open import Data.Product
open import Data.Sum
-- natural numbers
n≢m⇒sucn≢sucm : {n m : ℕ} → n ≢ m → ℕ.suc n ≢ ℕ.suc m
n≢m⇒sucn≢sucm {n} {m} neq = λ x → contradiction (cong Data.Nat.pred x) neq
sucn≢sucm⇒n≢m : {n m : ℕ} → ℕ.suc n ≢ ℕ.suc m → n ≢ m
sucn≢sucm⇒n≢m {n} {m} neq = λ x → contradiction (cong ℕ.suc x) neq
n+1≡sucn : {n : ℕ} → n +ᴺ 1 ≡ ℕ.suc n
n+1≡sucn {zero} = refl
n+1≡sucn {ℕ.suc n} = cong ℕ.suc (n+1≡sucn{n})
n≤sucn : {n : ℕ} → n ≤ᴺ ℕ.suc n
n≤sucn {zero} = z≤n
n≤sucn {ℕ.suc n} = s≤s n≤sucn
n<sucn : {n : ℕ} → n <ᴺ ℕ.suc n
n<sucn {zero} = s≤s z≤n
n<sucn {ℕ.suc n} = s≤s n<sucn
m<n⇒m+o<n+o : {m n o : ℕ} → m <ᴺ n → m +ᴺ o <ᴺ n +ᴺ o
m<n⇒m+o<n+o {zero} {n} {o} le = m<n+m o le
m<n⇒m+o<n+o {ℕ.suc m} {ℕ.suc n} {o} (s≤s le) = s≤s (m<n⇒m+o<n+o le)
m≤n⇒m+o≤n+o : {m n o : ℕ} → m ≤ᴺ n → m +ᴺ o ≤ᴺ n +ᴺ o
m≤n⇒m+o≤n+o {zero} {n} {o} le = m≤n+m o n
m≤n⇒m+o≤n+o {ℕ.suc m} {ℕ.suc n} {o} (s≤s le) = s≤s (m≤n⇒m+o≤n+o le)
≤-refl-+-comm : {m n : ℕ} → m +ᴺ n ≤ᴺ n +ᴺ m
≤-refl-+-comm {m} {n} rewrite (+-comm m n) = ≤-refl
a<b≤c⇒a<c : {a b c : ℕ} → a <ᴺ b → b ≤ᴺ c → a <ᴺ c
a<b≤c⇒a<c {a} {b} {c} lt le = ≤-trans lt le
a≤b<c⇒a<c : {a b c : ℕ} → a ≤ᴺ b → b <ᴺ c → a <ᴺ c
a≤b<c⇒a<c {.0} {zero} {c} z≤n lt = lt
a≤b<c⇒a<c {.0} {ℕ.suc b} {ℕ.suc c} z≤n (s≤s lt) = s≤s z≤n
a≤b<c⇒a<c {.(ℕ.suc _)} {.(ℕ.suc _)} {ℕ.suc c} (s≤s le) (s≤s lt) = s≤s (a≤b<c⇒a<c le lt)
m≤n∧m≡q⇒q≤n : {m n q : ℕ} → m ≤ᴺ n → m ≡ q → q ≤ᴺ n
m≤n∧m≡q⇒q≤n {m} {n} {q} le eq rewrite eq = le
m≤n∧n≡q⇒m≤q : {m n q : ℕ} → m ≤ᴺ n → n ≡ q → m ≤ᴺ q
m≤n∧n≡q⇒m≤q le eq rewrite eq = le
n≤m⇒n≤sucm : {n m : ℕ} → n ≤ᴺ m → n ≤ᴺ ℕ.suc m
n≤m⇒n≤sucm {.0} {m} z≤n = z≤n
n≤m⇒n≤sucm {.(ℕ.suc _)} {.(ℕ.suc _)} (s≤s le) = s≤s (n≤m⇒n≤sucm le)
n≤m⇒n<sucm : {n m : ℕ} → n ≤ᴺ m → n <ᴺ ℕ.suc m
n≤m⇒n<sucm {n} {m} le = s≤s le
sucn≤m⇒n≤m : {n m : ℕ} → ℕ.suc n ≤ᴺ m → n ≤ᴺ m
sucn≤m⇒n≤m {n} {.(ℕ.suc _)} (s≤s le) = ≤-trans le n≤sucn
[k<x]⇒[k<x+1] : {x : ℕ} {k : ℕ} → (k <ᴺ x) → (k <ᴺ x +ᴺ 1)
[k<x]⇒[k<x+1]{x} {k} le = <-trans le (m<m+n x (s≤s z≤n))
[k<x]⇒[k<sucx] : {x : ℕ} {k : ℕ} → (k <ᴺ x) → (k <ᴺ ℕ.suc (x))
[k<x]⇒[k<sucx] {x} {k} le = <-trans le (s≤s ≤-refl)
¬[x≤k]⇒¬[sucx≤k] : {x : ℕ} {k : ℕ} → ¬ (x ≤ᴺ k) → ¬ ((x +ᴺ 1) ≤ᴺ k)
¬[x≤k]⇒¬[sucx≤k] {x} {k} nle = <⇒≱ ([k<x]⇒[k<x+1] (≰⇒> nle))
n+m≤n+q+m : {n m q : ℕ} → n +ᴺ m ≤ᴺ n +ᴺ (q +ᴺ m)
n+m≤n+q+m {n} {m} {q} rewrite (+-comm q m) | (sym (+-assoc n m q)) = m≤m+n (n +ᴺ m) q
m>n⇒m∸n≥1 : {m n : ℕ} → n <ᴺ m → m ∸ n ≥ᴺ 1
m>n⇒m∸n≥1 {ℕ.suc m} {zero} le = s≤s z≤n
m>n⇒m∸n≥1 {ℕ.suc m} {ℕ.suc n} (s≤s le) = m>n⇒m∸n≥1 le
m∸n≥q⇒m≥q : {m n q : ℕ} → m ∸ n ≥ᴺ q → m ≥ᴺ q
m∸n≥q⇒m≥q {m} {n} {q} ge = ≤-trans ge (m∸n≤m m n)
-- lists & length
++-assoc : {a : Level} {s : Set a} {Δ ∇ Γ : List s} → ((Δ ++ ∇) ++ Γ) ≡ (Δ ++ (∇ ++ Γ))
++-assoc {a} {s} {[]} {∇} {Γ} = refl
++-assoc {a} {s} {x ∷ Δ} {∇} {Γ} = cong (_∷_ x) (++-assoc{a}{s}{Δ}{∇}{Γ})
length[A]≥0 : {a : Level} {s : Set a} {A : List s} → length A ≥ᴺ 0
length[A]≥0 {a} {s} {A} = z≤n
A++[]≡A : {a : Level} {s : Set a} {A : List s} → A ++ [] ≡ A
A++[]≡A {a} {s} {[]} = refl
A++[]≡A {a} {s} {x ∷ A} = cong (_∷_ x) (A++[]≡A {a} {s} {A})
n+length[]≡n : {a : Level} {A : Set a} {n : ℕ} → n +ᴺ length{a}{A} [] ≡ n
n+length[]≡n {a} {A} {zero} = refl
n+length[]≡n {a} {A} {ℕ.suc n} = cong ℕ.suc (n+length[]≡n{a}{A})
length[A∷B]≡suc[length[B]] : {a : Level} {s : Set a} {A : s} {B : List s} → length (A ∷ B) ≡ ℕ.suc (length B)
length[A∷B]≡suc[length[B]] {a} {s} {A} {B} = refl
length[A∷B]≥1 : {a : Level} {s : Set a} {A : s} {B : List s} → length (A ∷ B) ≥ᴺ 1
length[A∷B]≥1 {a} {s} {A} {B} = s≤s z≤n
length[A++B]≡length[A]+length[B] : {a : Level} {s : Set a} {A B : List s} → length (A ++ B) ≡ length A +ᴺ length B
length[A++B]≡length[A]+length[B] {a} {s} {[]} {B} = refl
length[A++B]≡length[A]+length[B] {a} {s} {x ∷ A} {B} rewrite length[A∷B]≡suc[length[B]]{a}{s}{x}{A ++ B} = cong ℕ.suc (length[A++B]≡length[A]+length[B]{a}{s}{A}{B})
length[A++B∷[]]≡suc[length[A]] : {a : Level} {s : Set a} {A : List s} {B : s} → length (A ++ B ∷ []) ≡ ℕ.suc (length A)
length[A++B∷[]]≡suc[length[A]] {a} {s} {A} {B} rewrite (length[A++B]≡length[A]+length[B]{a}{s}{A}{B ∷ []}) = n+1≡sucn
A++B∷[]++C≡A++B∷C : {a : Level} {s : Set a} {A C : List s} {B : s} → ((A ++ B ∷ []) ++ C) ≡ (A ++ B ∷ C)
A++B∷[]++C≡A++B∷C {a} {s} {[]} {C} {B} = refl
A++B∷[]++C≡A++B∷C {a} {s} {x ∷ A} {C} {B} = cong (_∷_ x) A++B∷[]++C≡A++B∷C
A++B++D∷[]++C≡A++B++D∷C : {a : Level} {s : Set a} { A B C : List s} {D : s} → (A ++ B ++ D ∷ []) ++ C ≡ (A ++ B ++ D ∷ C)
A++B++D∷[]++C≡A++B++D∷C {a} {s} {[]} {B} {C} {D} = A++B∷[]++C≡A++B∷C
A++B++D∷[]++C≡A++B++D∷C {a} {s} {x ∷ A} {B} {C} {D} = cong (_∷_ x) (A++B++D∷[]++C≡A++B++D∷C{a}{s}{A}{B}{C}{D})
-- integers
m≥0⇒n+m≥0 : {n : ℕ} {m : ℤ} → m ≥ᶻ +0 → + n +ᶻ m ≥ᶻ +0
m≥0⇒n+m≥0 {n} {+_ m} ge = +≤+ z≤n
n>0⇒n>∣n⊖1∣ : {n : ℕ} → n ≥ᴺ 1 → n >ᴺ ∣ n ⊖ 1 ∣
n>0⇒n>∣n⊖1∣ {.(ℕ.suc _)} (s≤s le) = n<sucn
∣nℕ+1⊖1∣≡n : {n : ℕ} → ∣ n +ᴺ 1 ⊖ 1 ∣ ≡ n
∣nℕ+1⊖1∣≡n {zero} = refl
∣nℕ+1⊖1∣≡n {ℕ.suc n} = n+1≡sucn
m≥0⇒∣n+m∣≥n : {n : ℕ} {m : ℤ} → m ≥ᶻ +0 → ∣ +_ n +ᶻ m ∣ ≥ᴺ n
m≥0⇒∣n+m∣≥n {n} {+_ m} ge = m≤m+n n m
m>0⇒∣n+m∣>n : {n : ℕ} {m : ℤ} → m >ᶻ +0 → ∣ +_ n +ᶻ m ∣ >ᴺ n
m>0⇒∣n+m∣>n {n} {(+ m)} (+<+ m<n) = m<m+n n m<n
∣n∣≥n : {n : ℤ} → + ∣ n ∣ ≥ᶻ n
∣n∣≥n {+_ n} = +≤+ ≤-refl
∣n∣≥n { -[1+_] n} = -≤+
+a≤b⇒a≤∣b∣ : {a : ℕ} {b : ℤ} → + a ≤ᶻ b → a ≤ᴺ ∣ b ∣
+a≤b⇒a≤∣b∣ {zero} {b} le = z≤n
+a≤b⇒a≤∣b∣ {ℕ.suc a} {(+ b)} (+≤+ m≤n) = m≤n
+[1+q]≡q+1 : {q : ℕ} → +[1+ q ] ≡ + q +ᶻ + 1
+[1+q]≡q+1 {zero} = refl
+[1+q]≡q+1 {ℕ.suc q} = cong +[1+_] (sym n+1≡sucn)
+q≤+c+l⇒+1q≤+1c+l : {q c : ℕ} {l : ℤ} → + q ≤ᶻ + c +ᶻ l → +[1+ q ] ≤ᶻ +[1+ c ] +ᶻ l
+q≤+c+l⇒+1q≤+1c+l {q} {c} {l} le
rewrite (+[1+q]≡q+1{q})
| (+[1+q]≡q+1{c})
| (Data.Integer.Properties.+-assoc (+ c) (+ 1) l)
| (Data.Integer.Properties.+-comm (+ 1) l)
| (sym (Data.Integer.Properties.+-assoc (+ c) (l) (+ 1)))
= Data.Integer.Properties.+-monoˡ-≤ (+ 1) le
ℤ-m≤n⇒m+o≤n+o : {m n o : ℤ} → m ≤ᶻ n → m +ᶻ o ≤ᶻ n +ᶻ o
ℤ-m≤n⇒m+o≤n+o {m} {n} {o} le = Data.Integer.Properties.+-monoˡ-≤ o le
minus-1 : {y x : ℕ} {lt : x <ᴺ y} → ∣ y ∸ x ⊖ 1 ∣ +ᴺ x ≡ ∣ y ⊖ 1 ∣
minus-1 {y} {x} {lt}
rewrite (Data.Integer.Properties.⊖-≥{y ∸ x}{1} (m>n⇒m∸n≥1 lt))
| (sym (+-∸-comm {y ∸ x} x {1} (m>n⇒m∸n≥1 lt)))
| (m∸n+n≡m {y} {x} (sucn≤m⇒n≤m lt))
| (Data.Integer.Properties.⊖-≥{y}{1} ((m∸n≥q⇒m≥q{y}{x} (m>n⇒m∸n≥1{y}{x} lt))))
= refl
k≥0⇒∣+x+k∣≡x+k : {x k : ℕ} → ∣ + x +ᶻ + k ∣ ≡ x +ᴺ k
k≥0⇒∣+x+k∣≡x+k {x} {k} = refl
-- products & sums
-- deMorgan on products and sums
dm1 : {P Q : Set} → (¬ P × ¬ Q) → ¬ (P ⊎ Q)
dm1 {P} {Q} (fst , snd) (inj₁ x) = contradiction x fst
dm1 {P} {Q} (fst , snd) (inj₂ y) = contradiction y snd
dm2 : {P Q : Set} → ¬ (P ⊎ Q) → (¬ P × ¬ Q)
dm2 {P} {Q} d = (λ x → contradiction (inj₁ x) d) , λ x → contradiction (inj₂ x) d
|
{
"alphanum_fraction": 0.4459776459,
"avg_line_length": 37.3556701031,
"ext": "agda",
"hexsha": "8f0a03dd516775163e440eaf64e9c999e3366301",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-14T17:52:29.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-14T17:52:29.000Z",
"max_forks_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "kcaliban/ldlc",
"max_forks_repo_path": "src/llc/Auxiliary.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "kcaliban/ldlc",
"max_issues_repo_path": "src/llc/Auxiliary.agda",
"max_line_length": 164,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a87fb6402639c3d2bb393cc5466426c28e7a0398",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "kcaliban/ldlc",
"max_stars_repo_path": "src/llc/Auxiliary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4716,
"size": 7247
}
|
{-# OPTIONS --experimental-irrelevance #-}
module ShapeIrrelevantParameterNoBecauseOfRecursion where
data ⊥ : Set where
record ⊤ : Set where
data Bool : Set where
true false : Bool
True : Bool → Set
True false = ⊥
True true = ⊤
data D ..(b : Bool) : Set where
c : True b → D b -- should fail
-- Jesper, 2017-09-14: I think the definition of D is fine, but the definition
-- of cast below should fail since `D a` and `D b` are different types.
fromD : {b : Bool} → D b → True b
fromD (c p) = p
cast : .(a b : Bool) → D a → D b
cast _ _ x = x
bot : ⊥
bot = fromD (cast true false (c _))
|
{
"alphanum_fraction": 0.6416666667,
"avg_line_length": 20.6896551724,
"ext": "agda",
"hexsha": "a6a694172b7c38692ab807df499cd4840177d53b",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.agda",
"max_line_length": 78,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/ShapeIrrelevantParameterNoBecauseOfRecursion.agda",
"max_stars_repo_stars_event_max_datetime": "2016-03-17T01:45:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-03-17T01:45:59.000Z",
"num_tokens": 200,
"size": 600
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
-- Definition of Monoidal Category
-- Big design decision that differs from the previous version:
-- Do not go through "Functor.Power" to encode variables and work
-- at the level of NaturalIsomorphisms, instead work at the object/morphism
-- level, via the more direct _⊗₀_ _⊗₁_ _⊗- -⊗_.
-- The original design needed quite a few contortions to get things working,
-- but these are simply not needed when working directly with the morphisms.
--
-- Smaller design decision: export some items with long names
-- (unitorˡ, unitorʳ and associator), but internally work with the more classical
-- short greek names (λ, ρ and α respectively).
module Categories.Category.Monoidal.Core {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Function using (_$_)
open import Data.Product using (_×_; _,_; curry′)
open import Categories.Category.Product
open import Categories.Functor renaming (id to idF)
open import Categories.Functor.Bifunctor using (Bifunctor; appˡ; appʳ)
open import Categories.Functor.Properties using ([_]-resp-≅)
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
hiding (unitorˡ; unitorʳ; associator; _≃_)
open import Categories.Morphism C using (_≅_; module ≅)
open import Categories.Morphism.IsoEquiv C using (_≃_; ⌞_⌟)
open import Categories.Morphism.Isomorphism C using (_∘ᵢ_; lift-triangle′; lift-pentagon′)
open import Categories.Morphism.Reasoning C
private
module C = Category C
open C hiding (id; identityˡ; identityʳ; assoc)
open Commutation
private
variable
X Y Z W A B : Obj
f g h i a b : X ⇒ Y
record Monoidal : Set (o ⊔ ℓ ⊔ e) where
infixr 10 _⊗₀_ _⊗₁_
field
⊗ : Bifunctor C C C
unit : Obj
open Functor ⊗
_⊗₀_ : Obj → Obj → Obj
_⊗₀_ = curry′ F₀
-- this is also 'curry', but a very-dependent version
_⊗₁_ : X ⇒ Y → Z ⇒ W → X ⊗₀ Z ⇒ Y ⊗₀ W
f ⊗₁ g = F₁ (f , g)
_⊗- : Obj → Functor C C
X ⊗- = appˡ ⊗ X
-⊗_ : Obj → Functor C C
-⊗ X = appʳ ⊗ X
field
unitorˡ : unit ⊗₀ X ≅ X
unitorʳ : X ⊗₀ unit ≅ X
associator : (X ⊗₀ Y) ⊗₀ Z ≅ X ⊗₀ (Y ⊗₀ Z)
module unitorˡ {X} = _≅_ (unitorˡ {X = X})
module unitorʳ {X} = _≅_ (unitorʳ {X = X})
module associator {X} {Y} {Z} = _≅_ (associator {X} {Y} {Z})
-- for exporting, it makes sense to use the above long names, but for
-- internal consumption, the traditional (short!) categorical names are more
-- convenient. However, they are not symmetric, even though the concepts are, so
-- we'll use ⇒ and ⇐ arrows to indicate that
private
λ⇒ = unitorˡ.from
λ⇐ = unitorˡ.to
ρ⇒ = unitorʳ.from
ρ⇐ = unitorʳ.to
-- eta expansion fixes a problem in 2.6.1, will be reported
α⇒ = λ {X} {Y} {Z} → associator.from {X} {Y} {Z}
α⇐ = λ {X} {Y} {Z} → associator.to {X} {Y} {Z}
field
unitorˡ-commute-from : CommutativeSquare (C.id ⊗₁ f) λ⇒ λ⇒ f
unitorˡ-commute-to : CommutativeSquare f λ⇐ λ⇐ (C.id ⊗₁ f)
unitorʳ-commute-from : CommutativeSquare (f ⊗₁ C.id) ρ⇒ ρ⇒ f
unitorʳ-commute-to : CommutativeSquare f ρ⇐ ρ⇐ (f ⊗₁ C.id)
assoc-commute-from : CommutativeSquare ((f ⊗₁ g) ⊗₁ h) α⇒ α⇒ (f ⊗₁ (g ⊗₁ h))
assoc-commute-to : CommutativeSquare (f ⊗₁ (g ⊗₁ h)) α⇐ α⇐ ((f ⊗₁ g) ⊗₁ h)
triangle : [ (X ⊗₀ unit) ⊗₀ Y ⇒ X ⊗₀ Y ]⟨
α⇒ ⇒⟨ X ⊗₀ (unit ⊗₀ Y) ⟩
C.id ⊗₁ λ⇒
≈ ρ⇒ ⊗₁ C.id
⟩
pentagon : [ ((X ⊗₀ Y) ⊗₀ Z) ⊗₀ W ⇒ X ⊗₀ Y ⊗₀ Z ⊗₀ W ]⟨
α⇒ ⊗₁ C.id ⇒⟨ (X ⊗₀ Y ⊗₀ Z) ⊗₀ W ⟩
α⇒ ⇒⟨ X ⊗₀ (Y ⊗₀ Z) ⊗₀ W ⟩
C.id ⊗₁ α⇒
≈ α⇒ ⇒⟨ (X ⊗₀ Y) ⊗₀ Z ⊗₀ W ⟩
α⇒
⟩
|
{
"alphanum_fraction": 0.5876549456,
"avg_line_length": 35.9363636364,
"ext": "agda",
"hexsha": "c7b035d7a9772cfa2fe12b5809254600aad53267",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Monoidal/Core.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Monoidal/Core.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Monoidal/Core.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1441,
"size": 3953
}
|
module Prelude.Show where
open import Prelude.Unit
open import Prelude.String
open import Prelude.Char
open import Prelude.Nat
open import Prelude.Int
open import Prelude.Word
open import Prelude.Function
open import Prelude.List
open import Prelude.Fin
open import Prelude.Vec
open import Prelude.Maybe
open import Prelude.Sum
open import Prelude.Product
open import Prelude.Bool
open import Prelude.Ord
open import Prelude.Semiring
--- Class ---
ShowS = String → String
showString : String → ShowS
showString s r = s & r
showParen : Bool → ShowS → ShowS
showParen false s = s
showParen true s = showString "(" ∘ s ∘ showString ")"
record Show {a} (A : Set a) : Set a where
field
showsPrec : Nat → A → ShowS
show : A → String
show x = showsPrec 0 x ""
shows : A → ShowS
shows = showsPrec 0
open Show {{...}} public
simpleShowInstance : ∀ {a} {A : Set a} → (A → String) → Show A
showsPrec {{simpleShowInstance s}} _ x = showString (s x)
ShowBy : ∀ {a b} {A : Set a} {B : Set b} {{ShowB : Show B}} → (A → B) → Show A
showsPrec {{ShowBy f}} p = showsPrec p ∘ f
--- Instances ---
-- Bool --
instance
ShowBool : Show Bool
ShowBool = simpleShowInstance λ b → if b then "true" else "false"
-- Int --
instance
ShowInt : Show Int
ShowInt = simpleShowInstance primShowInteger
-- Nat --
instance
ShowNat : Show Nat
ShowNat = simpleShowInstance (primShowInteger ∘ pos)
-- Word64 --
instance
ShowWord64 : Show Word64
ShowWord64 = simpleShowInstance (show ∘ word64ToNat)
-- Char --
instance
ShowChar : Show Char
ShowChar = simpleShowInstance primShowChar
-- String --
instance
ShowString : Show String
ShowString = simpleShowInstance primShowString
-- List --
instance
ShowList : ∀ {a} {A : Set a} {{ShowA : Show A}} → Show (List A)
showsPrec {{ShowList}} _ [] = showString "[]"
showsPrec {{ShowList}} _ (x ∷ xs) =
showString "["
∘ foldl (λ r x → r ∘ showString ", " ∘ showsPrec 2 x) (showsPrec 2 x) xs
∘ showString "]"
-- Fin --
instance
ShowFin : ∀ {n} → Show (Fin n)
ShowFin = simpleShowInstance (show ∘ finToNat)
-- Vec --
instance
ShowVec : ∀ {a} {A : Set a} {n} {{ShowA : Show A}} → Show (Vec A n)
ShowVec = ShowBy vecToList
-- Maybe --
instance
ShowMaybe : ∀ {a} {A : Set a} {{ShowA : Show A}} → Show (Maybe A)
showsPrec {{ShowMaybe}} p nothing = showString "nothing"
showsPrec {{ShowMaybe}} p (just x) = showParen (p >? 9) (showString "just " ∘ showsPrec 10 x)
-- Either --
instance
ShowEither : ∀ {a b} {A : Set a} {B : Set b} {{ShowA : Show A}} {{ShowB : Show B}} → Show (Either A B)
showsPrec {{ShowEither}} p (left x) = showParen (p >? 9) $ showString "left " ∘ showsPrec 10 x
showsPrec {{ShowEither}} p (right x) = showParen (p >? 9) $ showString "right " ∘ showsPrec 10 x
-- Sigma --
instance
ShowSigma : ∀ {a b} {A : Set a} {B : A → Set b} {{ShowA : Show A}} {{ShowB : ∀ {x} → Show (B x)}} →
Show (Σ A B)
showsPrec {{ShowSigma}} p (x , y) = showParen (p >? 1) $ showsPrec 2 x ∘ showString ", " ∘ showsPrec 1 y
|
{
"alphanum_fraction": 0.6388343157,
"avg_line_length": 23.4923076923,
"ext": "agda",
"hexsha": "dccfa37a9b3252958a7ed0dc7f142c7a791e33a4",
"lang": "Agda",
"max_forks_count": 24,
"max_forks_repo_forks_event_max_datetime": "2021-04-22T06:10:41.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-03-12T18:03:45.000Z",
"max_forks_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "t-more/agda-prelude",
"max_forks_repo_path": "src/Prelude/Show.agda",
"max_issues_count": 59,
"max_issues_repo_head_hexsha": "da4fca7744d317b8843f2bc80a923972f65548d3",
"max_issues_repo_issues_event_max_datetime": "2022-01-14T07:32:36.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-02-09T05:36:44.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "t-more/agda-prelude",
"max_issues_repo_path": "src/Prelude/Show.agda",
"max_line_length": 106,
"max_stars_count": 111,
"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/Show.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-12T23:29:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-05T11:28:15.000Z",
"num_tokens": 978,
"size": 3054
}
|
{-# OPTIONS --prop #-}
open import Agda.Builtin.Reflection
open import Agda.Builtin.List
open import Agda.Builtin.Unit
_>>=_ = bindTC
return = returnTC
postulate
X : Prop
x₀ : X
f : X
f = x₀
macro
getValue : Name → Term → TC ⊤
getValue s _ = do
function (clause _ _ t ∷ []) ← getDefinition s
where _ → typeError (strErr "Not a defined name" ∷ [])
typeError (strErr "The value of " ∷ nameErr s ∷ strErr " is " ∷ termErr t ∷ [])
test = getValue f
|
{
"alphanum_fraction": 0.6355932203,
"avg_line_length": 19.6666666667,
"ext": "agda",
"hexsha": "952cf1987a058f020adc3ffce115af3aecc6b981",
"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/Fail/Issue3553.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/Fail/Issue3553.agda",
"max_line_length": 83,
"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/Fail/Issue3553.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": 153,
"size": 472
}
|
------------------------------------------------------------------------------
-- Equality on Conat
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.Conat.Equality.Type where
open import FOTC.Base
infix 4 _≈_
------------------------------------------------------------------------------
-- Functional for the relation _≈_ (adapted from (Sander 1992,
-- p. 58)).
--
-- ≈-F : (D → D → Set) → D → D → Set
-- ≈-F R m n =
-- (m ≡ zero ∧ n ≡ zero) ∨ (∃[ m' ] ∃[ n' ] m ≡ succ m' ∧ n ≡ succ n' ∧ R m' n')
-- The relation _≈_ is the greatest post-fixed point of the functional
-- ≈-F (by ≈-out and ≈-coind).
-- The equality on Conat.
postulate _≈_ : D → D → Set
-- The relation _≈_ is a post-fixed point of the functional ≈-F,
-- i.e.
--
-- _≈_ ≤ ≈-F _≈_.
postulate ≈-out : ∀ {m n} → m ≈ n →
m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ m' ≈ n')
{-# ATP axiom ≈-out #-}
-- The relation _N≈_ is the greatest post-fixed point of _N≈_, i.e.
--
-- ∀ R. R ≤ ≈-F R ⇒ R ≤ _N≈_.
--
-- N.B. This is an axiom schema. Because in the automatic proofs we
-- *must* use an instance, we do not add this postulate as an ATP
-- axiom.
postulate
≈-coind :
(R : D → D → Set) →
-- R is a post-fixed point of the functional ≈-F.
(∀ {m n} → R m n → m ≡ zero ∧ n ≡ zero
∨ (∃[ m' ] ∃[ n' ] m ≡ succ₁ m' ∧ n ≡ succ₁ n' ∧ R m' n')) →
-- _≈_ is greater than R.
∀ {m n} → R m n → m ≈ n
------------------------------------------------------------------------------
-- References
--
-- Sander, Herbert P. (1992). A Logic of Functional Programs with an
-- Application to Concurrency. PhD thesis. Department of Computer
-- Sciences: Chalmers University of Technology and University of
-- Gothenburg.
|
{
"alphanum_fraction": 0.4573016675,
"avg_line_length": 31.9193548387,
"ext": "agda",
"hexsha": "3faed2c71a1b11f7a694341018feed792dda82a0",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/Conat/Equality/Type.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/Conat/Equality/Type.agda",
"max_line_length": 80,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/Conat/Equality/Type.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 607,
"size": 1979
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.NType2
open import lib.Equivalence2
open import lib.path-seq.Rotations
open import lib.types.Unit
open import lib.types.Nat
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.Paths
open import lib.types.TLevel
open import lib.types.Truncation
module lib.NConnected where
is-connected : ∀ {i} → ℕ₋₂ → Type i → Type i
is-connected n A = is-contr (Trunc n A)
has-conn-fibers : ∀ {i j} {A : Type i} {B : Type j} → ℕ₋₂ → (A → B) → Type (lmax i j)
has-conn-fibers {A = A} {B = B} n f =
Π B (λ b → is-connected n (hfiber f b))
{- all types are -2-connected -}
-2-conn : ∀ {i} (A : Type i) → is-connected -2 A
-2-conn A = Trunc-level
{- all inhabited types are -1-connected -}
inhab-conn : ∀ {i} {A : Type i} (a : A) → is-connected -1 A
inhab-conn a = has-level-in ([ a ] , prop-has-all-paths [ a ])
{- connectedness is a prop -}
is-connected-is-prop : ∀ {i} {n : ℕ₋₂} {A : Type i}
→ is-prop (is-connected n A)
is-connected-is-prop = is-contr-is-prop
{- "induction principle" for n-connected maps (where codomain is n-type) -}
module ConnExtend {i j k} {A : Type i} {B : Type j} {n : ℕ₋₂}
{h : A → B} (c : has-conn-fibers n h)
(P : B → n -Type k) where
private
helper : Π A (fst ∘ P ∘ h)
→ (b : B) → Trunc n (Σ A (λ a → h a == b)) → (fst (P b))
helper t b r =
Trunc-rec {{snd (P b)}}
(λ x → transport (λ y → fst (P y)) (snd x) (t (fst x)))
r
restr : Π B (fst ∘ P) → Π A (fst ∘ P ∘ h)
restr t = t ∘ h
abstract
ext : Π A (fst ∘ P ∘ h) → Π B (fst ∘ P)
ext f b = helper f b (contr-center (c b))
private
abstract
ext-β' : (f : Π A (fst ∘ P ∘ h)) (a : A) → restr (ext f) a == f a
ext-β' f a =
transport
(λ r → Trunc-rec {{snd (P (h a))}} _ r == f a)
(! (contr-path(c (h a)) [ (a , idp) ]))
idp
abstract
restr-β : (t : Π B (fst ∘ P)) (b : B) → ext (restr t) b == t b
restr-β t b =
Trunc-elim
{{λ r → =-preserves-level {x = helper (t ∘ h) b r} (snd (P b))}}
(λ x → lemma (fst x) b (snd x))
(contr-center (c b))
where
lemma : ∀ xl → ∀ b → (p : h xl == b) →
helper (t ∘ h) b [ (xl , p) ] == t b
lemma xl ._ idp = idp
restr-is-equiv : is-equiv restr
restr-is-equiv = is-eq restr ext (λ= ∘ ext-β') (λ= ∘ restr-β)
restr-equiv : Π B (fst ∘ P) ≃ Π A (fst ∘ P ∘ h)
restr-equiv = restr , restr-is-equiv
ext-β : (f : Π A (fst ∘ P ∘ h)) (a : A) → restr (ext f) a == f a
ext-β f = app= (is-equiv.f-g restr-is-equiv f)
abstract
restr-β-ext-β-adj : (t : Π B (fst ∘ P)) (a : A)
→ ext-β (restr t) a == restr-β t (h a)
restr-β-ext-β-adj t a =
ext-β (restr t) a
=⟨ ! (ap (λ s → app= s a) (is-equiv.adj restr-is-equiv t)) ⟩
app= (ap restr (λ= (restr-β t))) a
=⟨ ∘-ap (_$ a) restr (λ= (restr-β t)) ⟩
app= (λ= (restr-β t)) (h a)
=⟨ app=-β (restr-β t) (h a) ⟩
restr-β t (h a) =∎
open ConnExtend using () renaming
(ext to conn-extend;
ext-β to conn-extend-β;
restr-is-equiv to pre∘-conn-is-equiv) public
module ⊙ConnExtend {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k} {n : ℕ₋₂}
(h : X ⊙→ Y) (c : has-conn-fibers n (fst h))
(Z-level : has-level n (de⊙ Z)) where
open ConnExtend c (λ _ → de⊙ Z , Z-level) public
⊙restr : Y ⊙→ Z → X ⊙→ Z
⊙restr = _⊙∘ h
ext-pt-seq : (f : X ⊙→ Z) → ext (fst f) (pt Y) =-= pt Z
ext-pt-seq f =
ext (fst f) (pt Y)
=⟪ ! (ap (ext (fst f)) (snd h)) ⟫
ext (fst f) (fst h (pt X))
=⟪ ext-β (fst f) (pt X) ⟫
fst f (pt X)
=⟪ snd f ⟫
pt Z ∎∎
ext-pt : (f : X ⊙→ Z) → ext (fst f) (pt Y) == pt Z
ext-pt f = ↯ (ext-pt-seq f)
⊙ext : X ⊙→ Z → Y ⊙→ Z
⊙ext f = ext (fst f) , ext-pt f
abstract
⊙ext-β : (f : X ⊙→ Z) → ⊙restr (⊙ext f) == f
⊙ext-β f =
⊙λ=' (ext-β (fst f)) $
↓-idf=cst-in $ =ₛ-out $
ap (fst (⊙ext f)) (snd h) ◃∙ ext-pt-seq f
=ₛ⟨ 0 & 2 & seq-!-inv-r (ap (fst (⊙ext f)) (snd h) ◃∎) ⟩
ext-β (fst f) (pt X) ◃∙ snd f ◃∎ ∎ₛ
⊙restr-β : (t : Y ⊙→ Z) → ⊙ext (⊙restr t) == t
⊙restr-β t =
⊙λ=' (restr-β (fst t)) $
↓-idf=cst-in $ =ₛ-out $
ext-pt-seq (⊙restr t)
=ₛ₁⟨ 1 & 1 & restr-β-ext-β-adj (fst t) (pt X) ⟩
! (ap (ext (fst (⊙restr t))) (snd h)) ◃∙
restr-β (fst t) (fst h (pt X)) ◃∙
snd (⊙restr t) ◃∎
=ₛ⟨ 2 & 1 & expand (ap (fst t) (snd h) ◃∙ snd t ◃∎) ⟩
! (ap (ext (fst (⊙restr t))) (snd h)) ◃∙
restr-β (fst t) (fst h (pt X)) ◃∙
ap (fst t) (snd h) ◃∙
snd t ◃∎
=ₛ⟨ 0 & 3 & !ₛ $ pre-rotate-in $
homotopy-naturality
(ext (fst (⊙restr t)))
(fst t)
(restr-β (fst t))
(snd h) ⟩
restr-β (fst t) (pt Y) ◃∙ snd t ◃∎ ∎ₛ
⊙restr-is-equiv : is-equiv ⊙restr
⊙restr-is-equiv = is-eq ⊙restr ⊙ext ⊙ext-β ⊙restr-β
⊙restr-equiv : (Y ⊙→ Z) ≃ (X ⊙→ Z)
⊙restr-equiv = ⊙restr , ⊙restr-is-equiv
open ⊙ConnExtend using () renaming
(⊙ext to ⊙conn-extend;
⊙restr-is-equiv to pre⊙∘-conn-is-equiv) public
{- generalized "almost induction principle" for maps into ≥n-types
TODO: rearrange this to use ≤T? -}
conn-extend-general : ∀ {i j} {A : Type i} {B : Type j} {n k : ℕ₋₂}
→ {f : A → B} → has-conn-fibers n f
→ ∀ {l} (P : B → (k +2+ n) -Type l)
→ ∀ t → has-level k (Σ (Π B (fst ∘ P)) (λ s → (s ∘ f) == t))
conn-extend-general {k = ⟨-2⟩} c P t =
equiv-is-contr-map (pre∘-conn-is-equiv c P) t
conn-extend-general {B = B} {n = n} {k = S k'} {f = f} c P t = has-level-in
λ {(g , p) (h , q) →
equiv-preserves-level (e g h p q)
{{conn-extend-general {k = k'} c (Q g h) (app= (p ∙ ! q))}} }
where
Q : (g h : Π B (fst ∘ P)) → B → (k' +2+ n) -Type _
Q g h b = ((g b == h b) , has-level-apply (snd (P b)) _ _)
app=-pre∘ : ∀ {i j k} {A : Type i} {B : Type j} {C : B → Type k}
(f : A → B) {g h : Π B C} (p : g == h)
→ app= (ap (λ k → k ∘ f) p) == app= p ∘ f
app=-pre∘ f idp = idp
move-right-on-right-econv : ∀ {i} {A : Type i} {x y z : A}
(p : x == y) (q : x == z) (r : y == z)
→ (p == q ∙ ! r) ≃ (p ∙ r == q)
move-right-on-right-econv {x = x} p idp idp =
(_ , pre∙-is-equiv (∙-unit-r p))
lemma : ∀ g h p q → (H : g ∼ h)
→ ((H ∘ f) == app= (p ∙ ! q))
≃ (ap (λ v → v ∘ f) (λ= H) ∙ q == p)
lemma g h p q H =
move-right-on-right-econv (ap (λ v → v ∘ f) (λ= H)) p q
∘e transport (λ w → (w == app= (p ∙ ! q))
≃ (ap (λ v → v ∘ f) (λ= H) == p ∙ ! q))
(app=-pre∘ f (λ= H) ∙ ap (λ k → k ∘ f) (λ= $ app=-β H))
(ap-equiv app=-equiv _ _ ⁻¹)
e : ∀ g h p q →
(Σ (g ∼ h) (λ r → (r ∘ f) == app= (p ∙ ! q)))
≃ ((g , p) == (h , q))
e g h p q =
((=Σ-econv _ _ ∘e Σ-emap-r (λ u → ↓-app=cst-econv ∘e !-equiv))
∘e (Σ-emap-l _ λ=-equiv)) ∘e Σ-emap-r (lemma g h p q)
conn-in : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} {h : A → B}
→ (∀ (P : B → n -Type (lmax i j))
→ Σ (Π A (fst ∘ P ∘ h) → Π B (fst ∘ P))
(λ u → ∀ (t : Π A (fst ∘ P ∘ h)) → u t ∘ h ∼ t))
→ has-conn-fibers n h
conn-in {A = A} {B = B} {h = h} sec b =
let s = sec (λ b → (Trunc _ (hfiber h b) , Trunc-level))
in has-level-in (fst s (λ a → [ a , idp ]) b ,
Trunc-elim (λ k → transport
(λ v → fst s (λ a → [ a , idp ]) (fst v) == [ fst k , snd v ])
(contr-path (pathfrom-is-contr (h (fst k))) (b , snd k))
(snd s (λ a → [ a , idp ]) (fst k))))
abstract
pointed-conn-in : ∀ {i} {n : ℕ₋₂} (A : Type i) (a₀ : A)
→ has-conn-fibers {A = ⊤} n (cst a₀) → is-connected (S n) A
pointed-conn-in {n = n} A a₀ c = has-level-in
([ a₀ ] ,
Trunc-elim
(λ a → Trunc-rec
(λ x → ap [_] (snd x)) (contr-center $ c a)))
abstract
pointed-conn-out : ∀ {i} {n : ℕ₋₂} (A : Type i) (a₀ : A)
{{_ : is-connected (S n) A}} → has-conn-fibers {A = ⊤} n (cst a₀)
pointed-conn-out {n = n} A a₀ {{c}} a = has-level-in
(point ,
λ y → ! (cancel point)
∙ (ap out $ contr-has-all-paths (into point) (into y))
∙ cancel y)
where
into-aux : Trunc n (Σ ⊤ (λ _ → a₀ == a)) → Trunc n (a₀ == a)
into-aux = Trunc-fmap snd
into : Trunc n (Σ ⊤ (λ _ → a₀ == a))
→ [_] {n = S n} a₀ == [ a ]
into = <– (=ₜ-equiv [ a₀ ] [ a ]) ∘ into-aux
out-aux : Trunc n (a₀ == a) → Trunc n (Σ ⊤ (λ _ → a₀ == a))
out-aux = Trunc-fmap (λ p → (tt , p))
out : [_] {n = S n} a₀ == [ a ] → Trunc n (Σ ⊤ (λ _ → a₀ == a))
out = out-aux ∘ –> (=ₜ-equiv [ a₀ ] [ a ])
cancel : (x : Trunc n (Σ ⊤ (λ _ → a₀ == a))) → out (into x) == x
cancel x =
out (into x)
=⟨ ap out-aux (<–-inv-r (=ₜ-equiv [ a₀ ] [ a ]) (into-aux x)) ⟩
out-aux (into-aux x)
=⟨ Trunc-fmap-∘ _ _ x ⟩
Trunc-fmap (λ q → (tt , (snd q))) x
=⟨ Trunc-elim {P = λ x → Trunc-fmap (λ q → (tt , snd q)) x == x}
(λ _ → idp) x ⟩
x =∎
point : Trunc n (Σ ⊤ (λ _ → a₀ == a))
point = out $ contr-has-all-paths [ a₀ ] [ a ]
prop-over-connected : ∀ {i j} {A : Type i} {a : A} {{p : is-connected 0 A}}
→ (P : A → hProp j)
→ fst (P a) → Π A (fst ∘ P)
prop-over-connected P x = conn-extend (pointed-conn-out _ _) P (λ _ → x)
{- Connectedness of a truncated type -}
instance
Trunc-preserves-conn : ∀ {i} {A : Type i} {n : ℕ₋₂} {m : ℕ₋₂}
→ is-connected n A → is-connected n (Trunc m A)
Trunc-preserves-conn {n = ⟨-2⟩} _ = Trunc-level
Trunc-preserves-conn {A = A} {n = S n} {m} c = lemma (contr-center c) (contr-path c)
where
lemma : (x₀ : Trunc (S n) A) → (∀ x → x₀ == x) → is-connected (S n) (Trunc m A)
lemma = Trunc-elim
(λ a → λ p → has-level-in ([ [ a ] ] ,
Trunc-elim
(Trunc-elim
{{λ _ → =-preserves-level
(Trunc-preserves-level (S n) Trunc-level)}}
(λ x → <– (=ₜ-equiv [ [ a ] ] [ [ x ] ])
(Trunc-fmap (ap [_])
(–> (=ₜ-equiv [ a ] [ x ]) (p [ x ])))))))
{- Connectedness of a Σ-type -}
abstract
instance
Σ-conn : ∀ {i} {j} {A : Type i} {B : A → Type j} {n : ℕ₋₂}
→ is-connected n A → (∀ a → is-connected n (B a))
→ is-connected n (Σ A B)
Σ-conn {A = A} {B = B} {n = ⟨-2⟩} cA cB = -2-conn (Σ A B)
Σ-conn {A = A} {B = B} {n = S m} cA cB =
Trunc-elim
{P = λ ta → (∀ tx → ta == tx) → is-connected (S m) (Σ A B)}
(λ a₀ pA →
Trunc-elim
{P = λ tb → (∀ ty → tb == ty) → is-connected (S m) (Σ A B)}
(λ b₀ pB → has-level-in
([ a₀ , b₀ ] ,
Trunc-elim
{P = λ tp → [ a₀ , b₀ ] == tp}
(λ {(r , s) →
Trunc-rec
(λ pa → Trunc-rec
(λ pb → ap [_] (pair= pa (from-transp! B pa pb)))
(–> (=ₜ-equiv [ b₀ ] [ transport! B pa s ])
(pB [ transport! B pa s ])))
(–> (=ₜ-equiv [ a₀ ] [ r ]) (pA [ r ]))})))
(contr-center (cB a₀)) (contr-path (cB a₀)))
(contr-center cA) (contr-path cA)
×-conn : ∀ {i} {j} {A : Type i} {B : Type j} {n : ℕ₋₂}
→ is-connected n A → is-connected n B
→ is-connected n (A × B)
×-conn cA cB = Σ-conn cA (λ _ → cB)
{- connectedness of a path space -}
abstract
instance
path-conn : ∀ {i} {A : Type i} {x y : A} {n : ℕ₋₂}
→ is-connected (S n) A → is-connected n (x == y)
path-conn {x = x} {y = y} cA =
equiv-preserves-level (=ₜ-equiv [ x ] [ y ])
{{has-level-apply (contr-is-prop cA) [ x ] [ y ]}}
{- an n-Type which is n-connected is contractible -}
connected-at-level-is-contr : ∀ {i} {A : Type i} {n : ℕ₋₂}
{{pA : has-level n A}} {{cA : is-connected n A}} → is-contr A
connected-at-level-is-contr {{pA}} {{cA}} =
equiv-preserves-level (unTrunc-equiv _) {{cA}}
{- if A is n-connected and m ≤ n, then A is m-connected -}
connected-≤T : ∀ {i} {m n : ℕ₋₂} {A : Type i}
→ m ≤T n → {{_ : is-connected n A}} → is-connected m A
connected-≤T {m = m} {n = n} {A = A} leq =
transport is-contr (ua (Trunc-fuse-≤ A leq)) (Trunc-preserves-level m ⟨⟩)
{- Equivalent types have the same connectedness -}
equiv-preserves-conn : ∀ {i j} {A : Type i} {B : Type j} {n : ℕ₋₂} (e : A ≃ B)
{{_ : is-connected n A}} → is-connected n B
equiv-preserves-conn {n = n} e = equiv-preserves-level (Trunc-emap e)
trunc-proj-conn : ∀ {i} (A : Type i) (n : ℕ₋₂)
→ has-conn-fibers n ([_] {n = n} {A = A})
trunc-proj-conn A n =
conn-in $ λ P →
Trunc-elim {P = fst ∘ P} {{snd ∘ P}} , λ t a → idp
{- Composite of two connected functions is connected -}
∘-conn : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k}
→ {n : ℕ₋₂} → (f : A → B) → (g : B → C)
→ has-conn-fibers n f
→ has-conn-fibers n g
→ has-conn-fibers n (g ∘ f)
∘-conn {n = n} f g cf cg =
conn-in (λ P → conn-extend cg P ∘ conn-extend cf (P ∘ g) , lemma P)
where
lemma : ∀ P h x → conn-extend cg P (conn-extend cf (P ∘ g) h) (g (f x)) == h x
lemma P h x =
conn-extend cg P (conn-extend cf (P ∘ g) h) (g (f x))
=⟨ conn-extend-β cg P (conn-extend cf (P ∘ g) h) (f x) ⟩
conn-extend cf (P ∘ g) h (f x)
=⟨ conn-extend-β cf (P ∘ g) h x ⟩
h x
=∎
|
{
"alphanum_fraction": 0.4621318893,
"avg_line_length": 35.664021164,
"ext": "agda",
"hexsha": "946160265f2f020ebc856fb97b47fbccd70e6601",
"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/NConnected.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/NConnected.agda",
"max_line_length": 86,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/NConnected.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": 5602,
"size": 13481
}
|
{-# OPTIONS --without-K #-}
module FiniteType where
open import Equiv using (_≃_)
open import Data.Product using (Σ; _,_)
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
--------------------------------------------------------------------------
--
-- A finite type is a type which is equivalent to Fin n
--
FiniteType : ∀ {ℓ} → (A : Set ℓ) → (n : ℕ) → Set ℓ
FiniteType A n = A ≃ Fin n
--------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4460580913,
"avg_line_length": 25.3684210526,
"ext": "agda",
"hexsha": "0d74afdb4f065bab48d7b8170e28acd4ea6da472",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/FiniteType.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/FiniteType.agda",
"max_line_length": 74,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/FiniteType.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 107,
"size": 482
}
|
{-# OPTIONS --copatterns #-}
module IOExampleGraphicsDrawingProgramWhenJust where
open import Data.Bool.Base
open import Data.Char.Base renaming (primCharEquality to charEquality)
open import Data.Nat.Base hiding (_≟_;_⊓_; _+_; _*_)
open import Data.List.Base hiding (_++_)
open import Data.Integer.Base hiding (suc)
open import Data.String.Base
open import Data.Maybe.Base
open import Function
open import SizedIO.Base
open import SizedIO.IOGraphicsLib
open import NativeInt --PrimTypeHelpers
open import NativeIO
integerLess : ℤ → ℤ → Bool
integerLess x y with ∣(y - (x ⊓ y))∣
... | zero = true
... | z = false
line : Point → Point → Graphic
line p newpoint = withColor red (polygon
(point x y
∷ point a b
∷ point (a + xAddition) (b + yAddition)
∷ point (x + xAddition) (y + yAddition)
∷ [] ) )
where
x = proj1Point p
y = proj2Point p
a = proj1Point newpoint
b = proj2Point newpoint
diffx = + ∣ (a - x) ∣
diffy = + ∣ (b - y) ∣
diffx*3 = diffx * (+ 3)
diffy*3 = diffy * (+ 3)
condition = (integerLess diffx diffy*3) ∧ (integerLess diffy diffx*3)
xAddition = if condition then + 2 else + 1
yAddition = if condition then + 2 else + 1
State = Maybe Point
loop : ∀{i} → Window → State → IOGraphics i Unit
force (loop w s) = exec' (getWindowEvent w)
λ{ (Key c t) → if charEquality c 'x' then return _ else loop w s
; (MouseMove p₂) → whenJust s (λ p₁ → exec1 (drawInWindow w (line p₁ p₂))) >>= λ _ →
loop w (just p₂)
; _ → loop w s
}
myProgram : ∀{i} → IOGraphics i Unit
myProgram =
exec (openWindow "Drawing Program" nothing
(just (size (+ 1000) (+ 1000))) nativeDrawGraphic nothing) λ window →
loop window nothing
main : NativeIO Unit
main = nativeRunGraphics (translateIOGraphics myProgram)
|
{
"alphanum_fraction": 0.6082949309,
"avg_line_length": 27.125,
"ext": "agda",
"hexsha": "867eb1b19fe00e7e0443d0a8be3937e5be9cb2b1",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:41:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-01T15:02:37.000Z",
"max_forks_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "agda/ooAgda",
"max_forks_repo_path": "examples/DrawingProgram/IOExampleGraphicsDrawingProgramWhenJust.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "agda/ooAgda",
"max_issues_repo_path": "examples/DrawingProgram/IOExampleGraphicsDrawingProgramWhenJust.agda",
"max_line_length": 89,
"max_stars_count": 23,
"max_stars_repo_head_hexsha": "7cc45e0148a4a508d20ed67e791544c30fecd795",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "agda/ooAgda",
"max_stars_repo_path": "examples/DrawingProgram/IOExampleGraphicsDrawingProgramWhenJust.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-12T23:15:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-06-19T12:57:55.000Z",
"num_tokens": 590,
"size": 1953
}
|
module Miscellaneous.associative-side where
private variable T : Set
private variable _▫_ : T → T → T
private variable id : T
data _≡_ {ℓ}{T : Set(ℓ)} : T → T → Set(ℓ) where
[≡]-intro : ∀{x : T} → (x ≡ x)
Associativity : (T → T → T) → Set
Associativity(_▫_) = ∀{a b c} → ((a ▫ (b ▫ c)) ≡ ((a ▫ b) ▫ c))
Identityₗ : (T → T → T) → T → Set
Identityₗ(_▫_)(id) = ∀{a} → ((id ▫ a) ≡ a)
Identityᵣ : (T → T → T) → T → Set
Identityᵣ(_▫_)(id) = ∀{a} → ((a ▫ id) ≡ a)
right-op₂-associativity : Associativity{T}(\x y → y)
right-op₂-associativity = [≡]-intro
right-op₂-identityₗ : Identityₗ{T}(\x y → y)(id)
right-op₂-identityₗ {a = a} = [≡]-intro
right-op₂-when-identityᵣₗ : (∀{a} → (id ≡ a)) → Identityᵣ{T}(\x y → y)(id)
right-op₂-when-identityᵣₗ p = p
right-op₂-when-identityᵣᵣ : Identityᵣ{T}(\x y → y)(id) → (∀{a} → (id ≡ a))
right-op₂-when-identityᵣᵣ p = p
|
{
"alphanum_fraction": 0.5679442509,
"avg_line_length": 28.7,
"ext": "agda",
"hexsha": "b4aabc510d9cebf0ea571f56561e42aefe4e8328",
"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": "Miscellaneous/associative-side.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": "Miscellaneous/associative-side.agda",
"max_line_length": 75,
"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": "Miscellaneous/associative-side.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": 401,
"size": 861
}
|
open import Common.Level
postulate
ℓ : Level
data D : Set (lsuc ℓ) where
c : (ℓ : Level) → Set ℓ → D
-- Bad error:
-- The type of the constructor does not fit in the sort of the
-- datatype, since Set (lsuc ℓ) is not less or equal than Set (lsuc ℓ)
-- when checking the constructor c in the declaration of D
|
{
"alphanum_fraction": 0.6857142857,
"avg_line_length": 24.2307692308,
"ext": "agda",
"hexsha": "4705a87e13987203575df1894e537429006966f7",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-03-05T20:02:38.000Z",
"max_forks_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/Fail/Issue998e.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "alhassy/agda",
"max_issues_repo_path": "test/Fail/Issue998e.agda",
"max_line_length": 70,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/Fail/Issue998e.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": 97,
"size": 315
}
|
------------------------------------------------------------------------
-- Typing of pure type systems (PTS)
------------------------------------------------------------------------
module Pts.Typing where
open import Data.Fin using (Fin; zero)
open import Data.Fin.Substitution
open import Data.Fin.Substitution.Lemmas
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Fin.Substitution.Typed
open import Data.Nat using (ℕ; _+_)
open import Data.Product using (_,_; ∃; _×_; proj₂)
open import Data.Star using (ε; _◅_)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Vec.All using (lookup₂)
open import Function using (flip)
open import Relation.Binary
import Relation.Binary.PropositionalEquality as PropEq
open import Pts.Core public
open import Pts.Syntax using (module SubstApp)
open import Pts.Reduction.Full
------------------------------------------------------------------------
-- Typing derivations.
--
-- The presentation of the typing rules below follows that of Pollak
-- (1994) rather than that of Barendregt (1992) in that it uses a
-- separate well-formedness judgment "Γ wf" for contexts in favor of
-- an explicit weakening rule. The well-formedness judgment is used
-- to strengthen the variable and sort typing rules. For the
-- remaining rules, well-formedness of contexts is an invariant (as e
-- witnessed by the "wt-wf" Lemma below).
--
-- References:
--
-- * H. P. Barendregt, Lambda Calculi with Types, chapter 2 of the
-- Handbook of Logic in Computer Science (vol. 2), Oxford
-- University Press, 1992.
--
-- * R. Pollack, The Theory of LEGO: A Proof Checker for the Extended
-- Calculus of Constructions, Ph.D. thesis, University of
-- Edinburgh, 1994
-- Definitions and lemmas are parametrized by a given PTS instance.
module Typing (pts : PTS) where
open PTS pts
open Ctx
open Syntax
open Substitution using (_[_])
infixl 9 _·_
infix 4 _wf _⊢_∈_
mutual
-- Well-formed contexts.
_wf : ∀ {n} → Ctx n → Set
Γ wf = WfCtx._wf _⊢_∈_ Γ
-- Typing derivations.
data _⊢_∈_ {n} (Γ : Ctx n) : Term n → Term n → Set where
var : ∀ x → Γ wf → Γ ⊢ var x ∈ lookup x Γ
axiom : ∀ {s₁ s₂} (a : Axiom s₁ s₂) → Γ wf → Γ ⊢ sort s₁ ∈ sort s₂
Π : ∀ {s₁ s₂ s₃ a b} (r : Rule s₁ s₂ s₃) →
Γ ⊢ a ∈ sort s₁ → a ∷ Γ ⊢ b ∈ sort s₂ → Γ ⊢ Π a b ∈ sort s₃
ƛ : ∀ {a t b s} →
a ∷ Γ ⊢ t ∈ b → Γ ⊢ Π a b ∈ sort s → Γ ⊢ ƛ a t ∈ Π a b
_·_ : ∀ {f a b t} →
Γ ⊢ f ∈ Π a b → Γ ⊢ t ∈ a → Γ ⊢ f · t ∈ b [ t ]
conv : ∀ {t a b s} → Γ ⊢ t ∈ a →
Γ ⊢ b ∈ sort s → a ≡β b → Γ ⊢ t ∈ b
open WfCtx _⊢_∈_ public hiding (_wf; _⊢_wf)
------------------------------------------------------------------------
-- Properties of typings
module _ {pts} where
open PTS pts
open Syntax
open Ctx
open Typing pts
-- Contexts of typings are well-formed.
wt-wf : ∀ {n} {Γ : Ctx n} {t a} → Γ ⊢ t ∈ a → Γ wf
wt-wf (var x Γ-wf) = Γ-wf
wt-wf (axiom a Γ-wf) = Γ-wf
wt-wf (Π r a∈s₁ b∈s₂) = wt-wf a∈s₁
wt-wf (ƛ t∈b Πab∈s) = wt-wf Πab∈s
wt-wf (f∈Πab · t∈a) = wt-wf f∈Πab
wt-wf (conv t∈a b∈s a≡b) = wt-wf t∈a
-- Contexts of well-formed types are well-formed.
wf-wf : ∀ {n} {Γ : Ctx n} {a} → (∃ λ s → Γ ⊢ a ∈ sort s) → Γ wf
wf-wf (_ , a∈s) = wt-wf a∈s
private
module Sβ {n} where
open Setoid (≡β-setoid {Sort} {n}) public using (refl; trans; sym)
-- A generation lemma for sorts.
sort-gen : ∀ {n} {Γ : Ctx n} {s a} → Γ ⊢ sort s ∈ a →
∃ λ s′ → Axiom s s′ × a ≡β sort s′
sort-gen (axiom ax Γ-wf) = _ , ax , Sβ.refl
sort-gen (conv s∈a b∈s₁ a≡b) =
let s₂ , ax , a≡s₂ = sort-gen s∈a
in s₂ , ax , Sβ.trans (Sβ.sym a≡b) a≡s₂
-- A generation lemma for product typings.
Π-gen : ∀ {n} {Γ : Ctx n} {a b c} → Γ ⊢ Π a b ∈ c →
∃ λ s₁ → ∃ λ s₂ → ∃ λ s₃ → Rule s₁ s₂ s₃ ×
Γ ⊢ a ∈ sort s₁ × a ∷ Γ ⊢ b ∈ sort s₂ × c ≡β sort s₃
Π-gen (Π r a∈s₁ b∈s₂) = _ , _ , _ , r , a∈s₁ , b∈s₂ , Sβ.refl
Π-gen (conv Πab∈c₁ c₂∈s c₁≡c₂) =
let s₁ , s₂ , s₃ , r , a∈s₁ , b∈s₂ , c₁≡s₃ = Π-gen Πab∈c₁
in s₁ , s₂ , s₃ , r , a∈s₁ , b∈s₂ , Sβ.trans (Sβ.sym c₁≡c₂) c₁≡s₃
-- A generation lemma for abstractions.
ƛ-gen : ∀ {n} {Γ : Ctx n} {a t c} → Γ ⊢ ƛ a t ∈ c →
∃ λ s → ∃ λ b → Γ ⊢ Π a b ∈ sort s × a ∷ Γ ⊢ t ∈ b × c ≡β Π a b
ƛ-gen (ƛ t∈b Πab∈s) = _ , _ , Πab∈s , t∈b , Sβ.refl
ƛ-gen (conv λat∈c₁ c₂∈s c₁≡c₂) =
let s , b , Πab∈s , t∈b , c₁≡Πab = ƛ-gen λat∈c₁
in s , b , Πab∈s , t∈b , Sβ.trans (Sβ.sym c₁≡c₂) c₁≡Πab
----------------------------------------------------------------------
-- Well-typed substitutions (i.e. substitution lemmas)
-- A shorthand for typings of Ts.
TermTyping : (ℕ → Set) → Set₁
TermTyping T = Typing Term T Term
-- Term-typed substitutions.
module TermTypedSub {T} (l : Lift T Term) (_⊢T_∈_ : TermTyping T) where
typedSub : TypedSub Term Term T
typedSub = record
{ _⊢_∈_ = _⊢T_∈_
; _⊢_wf = WfCtx._⊢_wf _⊢_∈_
; application = record { _/_ = SubstApp._/_ Sort l }
; weakenOps = record { weaken = Substitution.weaken }
}
open TypedSub typedSub public hiding (_⊢_∈_)
-- Typed liftings from Ts to Terms.
LiftToTermTyped : ∀ {T} → Lift T Term → TermTyping T → Set
LiftToTermTyped l _⊢T_∈_ = LiftTyped l typedSub _⊢_∈_
where open TermTypedSub l _⊢T_∈_ using (typedSub)
-- Application of well-typed substitutions to terms.
record TypedSubstApp {T} l {_⊢T_∈_ : TermTyping T}
(lt : LiftToTermTyped l _⊢T_∈_) : Set where
open LiftTyped lt
open Substitution using (_[_])
open PropEq hiding ([_])
private
module A = SubstApp Sort l
module L = Lift l
-- Substitutions commute.
field /-sub-↑ : ∀ {m n} a b (σ : Sub T m n) →
a [ b ] A./ σ ≡ (a A./ σ L.↑) [ b A./ σ ]
open BetaSubstApp (record { /-sub-↑ = /-sub-↑ }) hiding (/-sub-↑)
open TermTypedSub l _⊢T_∈_ hiding (_/_)
infixl 8 _/_
-- Substitutions preserve well-typedness of terms.
_/_ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {t a σ} →
Γ ⊢ t ∈ a → Γ ⇒ Δ ⊢ σ → Δ ⊢ t A./ σ ∈ a A./ σ
var x Γ-wf / (σ-wt , _) = lift (lookup₂ x σ-wt)
axiom a Γ-wf / (_ , Δ-wf) = axiom a Δ-wf
Π r a∈s₁ b∈s₂ / σ-wt =
Π r (a∈s₁ / σ-wt) (b∈s₂ / σ-wt ↑ (_ , a∈s₁ / σ-wt))
ƛ t∈b Πab∈s / σ-wt =
let _ , _ , _ , _ , a/σ∈s , _ = Π-gen (Πab∈s / σ-wt) in
ƛ (t∈b / σ-wt ↑ (_ , a/σ∈s)) (Πab∈s / σ-wt)
_·_ {b = b} f∈Πab t∈a / σ-wt =
subst (_⊢_∈_ _ _) (sym (/-sub-↑ b _ _)) ((f∈Πab / σ-wt) · (t∈a / σ-wt))
conv t∈a b∈s a≡b / σ-wt = conv (t∈a / σ-wt) (b∈s / σ-wt) (a≡b /≡β _)
-- Typed variable substitutions (renamings).
module TypedRenaming where
open Substitution
using (termSubst; varLiftAppLemmas; varLiftSubLemmas)
open TermSubst termSubst using (varLift)
open LiftAppLemmas varLiftAppLemmas hiding (lift)
typedVarSubst : TypedVarSubst (WfCtx._⊢_wf _⊢_∈_)
typedVarSubst = record
{ application = AppLemmas.application appLemmas
; weakenOps = Ctx.weakenOps
; id-vanishes = id-vanishes
; /-⊙ = /-⊙
; /-wk = PropEq.refl
; wf-wf = wf-wf
}
open TypedVarSubst typedVarSubst public
-- Liftings from variables to typed terms.
liftTyped : LiftTyped varLift typedSub _⊢_∈_
liftTyped = record
{ simpleTyped = simpleTyped
; lift = lift
}
where
lift : ∀ {n} {Γ : Ctx n} {x a} → Γ ⊢Var x ∈ a → Γ ⊢ var x ∈ a
lift (var x Γ-wf) = var x Γ-wf
open LiftSubLemmas varLiftSubLemmas
typedSubstApp : TypedSubstApp varLift liftTyped
typedSubstApp = record { /-sub-↑ = /-sub-↑ }
-- Typed term substitutions in terms.
module TypedSubstitution where
open Substitution using (simple; termSubst)
open SimpleExt simple using (extension)
open TermSubst termSubst using (termLift)
open TermTypedSub termLift _⊢_∈_ public using (typedSub; _⇒_⊢_)
open TypedRenaming using (_⇒_⊢Var_)
private
module U = Substitution
module V = TypedRenaming
module L = ExtAppLemmas U.appLemmas
infixl 8 _/Var_ _/_
-- Renaming preserves well-typedness.
_/Var_ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ∈ b → Γ ⇒ Δ ⊢Var σ → Δ ⊢ a U./Var σ ∈ b U./Var σ
_/Var_ = TypedSubstApp._/_ V.typedSubstApp
-- Weakening preserves well-typedness.
weaken : ∀ {n} {Γ : Ctx n} {a b c s} → Γ ⊢ a ∈ b → Γ ⊢ c ∈ sort s →
(c ∷ Γ) ⊢ (U.weaken a) ∈ (U.weaken b)
weaken a∈b c∈s = a∈b /Var V.wk (_ , c∈s)
-- Extensions of typed term substitutions.
extensionTyped : ExtensionTyped extension typedSub
extensionTyped = record
{ weaken = λ { (_ , c∈s) a∈b → weaken a∈b c∈s }
; weaken-/ = ExtLemmas₄.weaken-/ L.lemmas₄
; wt-wf = wt-wf
}
-- Simple typed term substitutions.
simpleTyped : SimpleTyped simple typedSub
simpleTyped = record
{ extensionTyped = extensionTyped
; var = var
; id-vanishes = L.id-vanishes
; /-wk = λ {_ a} → L./-wk {t = a}
; wk-sub-vanishes = L.wk-sub-vanishes
; wf-wf = wf-wf
}
-- Liftings from terms to terms.
liftTyped : LiftTyped termLift typedSub _⊢_∈_
liftTyped = record
{ simpleTyped = simpleTyped
; lift = Function.id
}
open LiftTyped liftTyped public
hiding (var; weaken; extensionTyped; simpleTyped; wt-wf; wf-wf)
typedSubstApp : TypedSubstApp termLift liftTyped
typedSubstApp = record { /-sub-↑ = λ a _ _ → L.sub-commutes a }
-- Substitutions preserve well-typedness.
_/_ : ∀ {m n} {Γ : Ctx m} {Δ : Ctx n} {a b σ} →
Γ ⊢ a ∈ b → Γ ⇒ Δ ⊢ σ → Δ ⊢ a U./ σ ∈ b U./ σ
_/_ = TypedSubstApp._/_ typedSubstApp
infix 10 _[_]
-- Single-variable substitutions preserve well-typedness.
_[_] : ∀ {n} {Γ : Ctx n} {t a u b} →
b ∷ Γ ⊢ t ∈ a → Γ ⊢ u ∈ b → Γ ⊢ t U.[ u ] ∈ a U.[ u ]
t∈a [ u∈b ] = t∈a / sub u∈b
-- Conversion of the first type in a context preserves
-- well-typedness.
conv-⊢ : ∀ {n} {Γ : Ctx n} {a₁ a₂ t b s} →
a₁ ∷ Γ ⊢ t ∈ b → Γ ⊢ a₂ ∈ sort s → a₁ ≡β a₂ → a₂ ∷ Γ ⊢ t ∈ b
conv-⊢ t∈b a₂∈s a₁≡a₂ =
subst₂ (_⊢_∈_ _) (L.id-vanishes _) (L.id-vanishes _) (t∈b / csub)
where
open PropEq using (subst₂)
open BetaSubstitution using (weaken-≡β)
open Setoid ≡β-setoid using (sym)
a₁∷Γ-wf = wt-wf t∈b
a₁∈s′ = proj₂ (wf-∷₁ a₁∷Γ-wf)
a₂∷Γ-wf = (_ , a₂∈s) ∷ (wf-∷₂ a₁∷Γ-wf)
csub = tsub (conv (var zero a₂∷Γ-wf) (weaken a₁∈s′ a₂∈s)
(weaken-≡β (sym a₁≡a₂)))
open TypedSubstitution
-- Operations on well-formed contexts that require weakening of
-- well-formedness judgments.
module WfCtxOps where
private module E = ExtensionTyped extensionTyped
wfWeakenOps : WfWeakenOps weakenOps
wfWeakenOps = record
{ weaken = λ { a-wk (_ , b∈s) → (_ , E.weaken a-wk b∈s) }
}
open WfWeakenOps wfWeakenOps public
----------------------------------------------------------------------
-- Preservation of types under reduction (aka subject reduction)
open Sβ
open PropEq using (_≡_)
-- Every well-typed term is either a type or an element.
tp-or-el : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ∈ b →
∃ λ s → b ≡ sort s ⊎ Γ ⊢ b ∈ sort s
tp-or-el (var x Γ-wf) = _ , inj₂ (proj₂ (WfCtxOps.lookup x Γ-wf))
tp-or-el (axiom a Γ-wf) = _ , inj₁ PropEq.refl
tp-or-el (Π r a∈s₁ b∈s₂) = _ , inj₁ PropEq.refl
tp-or-el (ƛ t∈b Πab∈s) = _ , inj₂ Πab∈s
tp-or-el (f∈Πab · t∈a) with tp-or-el f∈Πab
tp-or-el (f∈Πab · t∈a) | _ , inj₁ ()
tp-or-el (f∈Πab · t∈a) | _ , inj₂ Πab∈s =
let _ , s , _ , _ , _ , b∈s , _ = Π-gen Πab∈s
in s , inj₂ (b∈s [ t∈a ])
tp-or-el (conv t∈a b∈s a≡b) = _ , inj₂ b∈s
-- An inversion lemma for product typings.
Π-inv : ∀ {n} {Γ : Ctx n} {f a b} → Γ ⊢ f ∈ Π a b →
∃ λ s₁ → ∃ λ s₂ → Γ ⊢ a ∈ sort s₁ × a ∷ Γ ⊢ b ∈ sort s₂
Π-inv f∈Πab with tp-or-el f∈Πab
Π-inv f∈Πab | _ , inj₁ ()
Π-inv f∈Πab | _ , inj₂ Πab∈s =
let s₁ , s₂ , _ , _ , a∈s₁ , b∈s₂ , _ = Π-gen Πab∈s
in s₁ , s₂ , a∈s₁ , b∈s₂
-- An inversion lemma for abstractions.
ƛ-inv : ∀ {n} {Γ : Ctx n} {a t b c} → Γ ⊢ ƛ a t ∈ Π b c →
∃ λ s → Γ ⊢ a ∈ sort s × b ≡β a × a ∷ Γ ⊢ t ∈ c
ƛ-inv λat∈Πbc =
let _ , _ , Πad∈s , t∈d , Πbc≡Πad = ƛ-gen λat∈Πbc
s₁ , _ , _ , _ , a∈s₁ , _ = Π-gen Πad∈s
_ , _ , _ , c∈s₂ = Π-inv λat∈Πbc
b≡a , c≡d = Π-inj Πbc≡Πad
in s₁ , a∈s₁ , b≡a , conv t∈d (conv-⊢ c∈s₂ a∈s₁ b≡a) (sym c≡d)
-- Preservation of types under one-step reduction.
pres : ∀ {n} {Γ : Ctx n} {a a′ b} → Γ ⊢ a ∈ b → a →β a′ → Γ ⊢ a′ ∈ b
pres (var _ _) ()
pres (axiom _ _) ()
pres (Π r a∈s₁ b∈s₂) (Π₁ a→a′ b) =
Π r a′∈s₂ (conv-⊢ b∈s₂ a′∈s₂ (→β⇒≡β a→a′))
where a′∈s₂ = pres a∈s₁ a→a′
pres (Π r a∈s₁ b∈s₂) (Π₂ a b→b′) = Π r a∈s₁ (pres b∈s₂ b→b′)
pres (ƛ t∈b Πab∈s) (ƛ₁ a→a′ t) =
let _ , _ , _ , _ , a′∈s , _ = Π-gen (pres Πab∈s (Π₁ a→a′ _))
Πab→Πa′b = Π₁ a→a′ _
in conv (ƛ (conv-⊢ t∈b a′∈s (→β⇒≡β a→a′)) (pres Πab∈s Πab→Πa′b))
Πab∈s (sym (→β⇒≡β Πab→Πa′b))
pres (ƛ t∈b Πab∈s) (ƛ₂ a t→t′) = ƛ (pres t∈b t→t′) Πab∈s
pres (λat∈Πbc · u∈b) (cont a t u) =
let _ , a∈s , b≡a , t∈c = ƛ-inv λat∈Πbc
in t∈c [ conv u∈b a∈s b≡a ]
pres (f∈Πab · t∈a) (f→f′ ·₁ t) = pres f∈Πab f→f′ · t∈a
pres (_·_ {b = b} f∈Πab t∈a) (f ·₂ t→t′) =
let _ , _ , _ , b∈s = Π-inv f∈Πab
in conv (f∈Πab · pres t∈a t→t′) (b∈s [ t∈a ])
(sym (→β*⇒≡β (b [→β t→t′ ])))
pres (conv a∈b₁ b₂∈s b₁≡b₂) a→a′ = conv (pres a∈b₁ a→a′) b₂∈s b₁≡b₂
-- Preservation of types under reduction (aka subject reduction).
pres* : ∀ {n} {Γ : Ctx n} {a a′ b} → Γ ⊢ a ∈ b → a →β* a′ → Γ ⊢ a′ ∈ b
pres* a∈b ε = a∈b
pres* a₁∈b (a₁→a₂ ◅ a₂→*a₃) = pres* (pres a₁∈b a₁→a₂) a₂→*a₃
|
{
"alphanum_fraction": 0.5231727807,
"avg_line_length": 36.7197943445,
"ext": "agda",
"hexsha": "6ccaff7a5019de7daaef31406653378942d8ef6f",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-08-11T23:28:33.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-20T10:29:44.000Z",
"max_forks_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/pts-agda",
"max_forks_repo_path": "src/Pts/Typing.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_issues_repo_issues_event_max_datetime": "2017-08-21T16:01:50.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-08-21T14:48:09.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "asr/pts-agda",
"max_issues_repo_path": "src/Pts/Typing.agda",
"max_line_length": 77,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "d701c2688e4a88eb81bdd9d458f9a2fcf81d5a43",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/pts-agda",
"max_stars_repo_path": "src/Pts/Typing.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-31T10:47:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-05-13T12:11:10.000Z",
"num_tokens": 5997,
"size": 14284
}
|
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Category.Complete.Finitely {o ℓ e} (C : Category o ℓ e) where
open import Level
open import Categories.Category.Cartesian C
open import Categories.Diagram.Equalizer C
open import Categories.Diagram.Pullback C
open Category C
record FinitelyComplete : Set (levelOfTerm C) where
field
cartesian : Cartesian
equalizer : ∀ {A B} (f g : A ⇒ B) → Equalizer f g
module cartesian = Cartesian cartesian
module equalizer {A B} (f g : A ⇒ B) = Equalizer (equalizer f g)
open cartesian public
pullback : ∀ {X Y Z} (f : X ⇒ Z) (g : Y ⇒ Z) → Pullback f g
pullback f g = Product×Equalizer⇒Pullback product (equalizer _ _)
module pullback {X Y Z} (f : X ⇒ Z) (g : Y ⇒ Z) = Pullback (pullback f g)
|
{
"alphanum_fraction": 0.6900878294,
"avg_line_length": 28.4642857143,
"ext": "agda",
"hexsha": "61ec0f59fc6e28cec23cc7223d7a78c2df0b4d20",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bblfish/agda-categories",
"max_forks_repo_path": "src/Categories/Category/Complete/Finitely.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bblfish/agda-categories",
"max_issues_repo_path": "src/Categories/Category/Complete/Finitely.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "7672b7a3185ae77467cc30e05dbe50b36ff2af8a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bblfish/agda-categories",
"max_stars_repo_path": "src/Categories/Category/Complete/Finitely.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": 236,
"size": 797
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Functor where
open import Level
open import Data.Product using (_×_; Σ)
open import Function.Surjection using (Surjective)
open import Function.Equality using (_⟶_)
open import Relation.Nullary
open import Categories.Category
open import Categories.Functor.Core public
import Categories.Morphism as Morphism
private
variable
o ℓ e o′ ℓ′ e′ : Level
C D : Category o ℓ e
Contravariant : ∀ (C : Category o ℓ e) (D : Category o′ ℓ′ e′) → Set _
Contravariant C D = Functor (Category.op C) D
Faithful : Functor C D → Set _
Faithful {C = C} {D = D} F = ∀ {X Y} → (f g : C [ X , Y ]) → D [ F₁ f ≈ F₁ g ] → C [ f ≈ g ]
where open Functor F
Full : Functor C D → Set _
Full {C = C} {D = D} F = ∀ {X Y} → Surjective {To = D.hom-setoid {F₀ X} {F₀ Y}} G
where
module C = Category C
module D = Category D
open Functor F
G : ∀ {X Y} → (C.hom-setoid {X} {Y}) ⟶ D.hom-setoid {F₀ X} {F₀ Y}
G = record { _⟨$⟩_ = F₁ ; cong = F-resp-≈ }
FullyFaithful : Functor C D → Set _
FullyFaithful F = Full F × Faithful F
-- Note that this is a constructive version of Essentially Surjective, which is
-- quite a strong assumption.
EssentiallySurjective : Functor C D → Set _
EssentiallySurjective {C = C} {D = D} F = (d : Obj) → Σ C.Obj (λ c → Functor.F₀ F c ≅ d)
where
open Morphism D
open Category D
module C = Category C
|
{
"alphanum_fraction": 0.6451612903,
"avg_line_length": 30.3260869565,
"ext": "agda",
"hexsha": "c01b9fb28953d24fe548555e21ebe3bd9b33b5ea",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "MirceaS/agda-categories",
"max_forks_repo_path": "src/Categories/Functor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "MirceaS/agda-categories",
"max_issues_repo_path": "src/Categories/Functor.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58e5ec015781be5413bdf968f7ec4fdae0ab4b21",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "MirceaS/agda-categories",
"max_stars_repo_path": "src/Categories/Functor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 466,
"size": 1395
}
|
{-# OPTIONS --safe --without-K #-}
open import Relation.Binary.PropositionalEquality using (_≡_; refl; sym; cong)
open import Relation.Nullary using (Dec; yes; no)
import Data.Product as Product
import Data.Sum as Sum
import Data.Nat as ℕ
import Data.Nat.Properties as ℕₚ
open Product using (∃-syntax; _,_)
open Sum using (inj₁)
open ℕ using (ℕ; _+_; zero; suc)
open import PiCalculus.LinearTypeSystem.Algebras
module PiCalculus.LinearTypeSystem.Algebras.Graded where
_≔_∙_ : ℕ → ℕ → ℕ → Set
x ≔ y ∙ z = x ≡ (y + z)
computeʳ : (x y : ℕ) → Dec (∃[ z ] (x ≔ y ∙ z))
computeʳ x y with y ℕₚ.≤″? x
computeʳ x y | yes (ℕ.less-than-or-equal proof) = yes (_ , (sym proof))
computeʳ x y | no ¬p = no λ where
(_ , p) → ¬p (ℕ.less-than-or-equal (sym p))
Graded : Algebra ℕ
Algebra.0∙ Graded = 0
Algebra.1∙ Graded = 1
Algebra._≔_∙_ Graded = _≔_∙_
Algebra.∙-computeʳ Graded = computeʳ
Algebra.∙-unique Graded refl refl = refl
Algebra.∙-uniqueˡ Graded refl = ℕₚ.+-cancelʳ-≡ _ _
Algebra.0∙-minˡ Graded {zero} {zero} refl = refl
Algebra.∙-idˡ Graded = refl
Algebra.∙-comm Graded {y = y} refl = ℕₚ.+-comm y _
Algebra.∙-assoc Graded {z = z} {v = v} refl refl = v + z , (ℕₚ.+-assoc _ v z , refl)
|
{
"alphanum_fraction": 0.6672283067,
"avg_line_length": 30.4358974359,
"ext": "agda",
"hexsha": "602bb9bcc7fb1663519f32d3b6ba2d46578b85fc",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T16:24:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-01-25T13:57:13.000Z",
"max_forks_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "guilhermehas/typing-linear-pi",
"max_forks_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Graded.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_issues_repo_issues_event_max_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-03-15T09:16:14.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "guilhermehas/typing-linear-pi",
"max_issues_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Graded.agda",
"max_line_length": 84,
"max_stars_count": 26,
"max_stars_repo_head_hexsha": "0fc3cf6bcc0cd07d4511dbe98149ac44e6a38b1a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "guilhermehas/typing-linear-pi",
"max_stars_repo_path": "src/PiCalculus/LinearTypeSystem/Algebras/Graded.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-14T15:18:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-02T23:32:11.000Z",
"num_tokens": 467,
"size": 1187
}
|
{-
Types Summer School 2007
Bertinoro
Aug 19 - 31, 2007
Agda
Ulf Norell
-}
module Parity where
open import Nat
-- Parity n tells us whether n is even or odd.
data Parity : Nat -> Set where
even : (k : Nat) -> Parity (2 * k)
odd : (k : Nat) -> Parity (2 * k + 1)
-- Every number is either even or odd.
parity : (n : Nat) -> Parity n
parity zero = even zero
parity (suc n) with parity n
parity (suc .(2 * k)) | even k = {! !}
parity (suc .(2 * k + 1)) | odd k = {! !}
half : Nat -> Nat
half n with parity n
half .(2 * k) | even k = k
half .(2 * k + 1) | odd k = k
|
{
"alphanum_fraction": 0.4919472914,
"avg_line_length": 17.9736842105,
"ext": "agda",
"hexsha": "6390ff69f1f0a3db573f3e3b2e5037fc6ed760df",
"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/SummerSchool07/Lecture/Parity.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/SummerSchool07/Lecture/Parity.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "examples/SummerSchool07/Lecture/Parity.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 229,
"size": 683
}
|
{-# OPTIONS --without-K #-}
module Util.HoTT.HLevel where
open import Util.HoTT.HLevel.Core public
open import Util.HoTT.Equiv
open import Util.HoTT.FunctionalExtensionality
open import Util.HoTT.Homotopy
open import Util.HoTT.Univalence.Axiom
open import Util.Prelude
open import Util.Relation.Binary.PropositionalEquality using
( Σ-≡⁺ ; Σ-≡⁻ ; Σ-≡⁺∘Σ-≡⁻ )
open import Util.Relation.Binary.LogicalEquivalence
private
variable
α β γ : Level
A B C : Set α
infixr 0 _→-HProp_
-- Note that A and B must be at the same level. A more direct proof could
-- probably avoid this.
≃-pres-IsOfHLevel : ∀ {A B : Set α} n → A ≃ B → IsOfHLevel n A → IsOfHLevel n B
≃-pres-IsOfHLevel n A≃B = subst (IsOfHLevel n) (≃→≡ A≃B)
≅-pres-IsOfHLevel : ∀ {A B : Set α} n → A ≅ B → IsOfHLevel n A → IsOfHLevel n B
≅-pres-IsOfHLevel n A≅B = ≃-pres-IsOfHLevel n (≅→≃ A≅B)
∀-IsProp : {B : A → Set β} → (∀ a → IsProp (B a)) → IsProp (∀ a → B a)
∀-IsProp B-prop f g = funext λ a → B-prop _ _ _
∀∙-IsProp : {B : A → Set β} → (∀ a → IsProp (B a)) → IsProp (∀ {a} → B a)
∀∙-IsProp B-prop f g = funext∙ (B-prop _ _ _)
→-IsProp : IsProp B → IsProp (A → B)
→-IsProp B-prop = ∀-IsProp λ _ → B-prop
∀-HProp : (A : Set α) → ((a : A) → HProp β) → HProp (α ⊔ℓ β)
∀-HProp A B = HLevel⁺ (∀ a → B a .type) (∀-IsProp (λ a → B a .level))
∀∙-HProp : {A : Set α} → ((a : A) → HProp β) → HProp (α ⊔ℓ β)
∀∙-HProp B = HLevel⁺ (∀ {a} → B a .type) (∀∙-IsProp (λ a → B a .level))
_→-HProp_ : Set α → HProp β → HProp (α ⊔ℓ β)
A →-HProp B = HLevel⁺ (A → B .type) (→-IsProp (B .level))
_→-HProp′_ : HProp α → HProp β → HProp (α ⊔ℓ β)
A →-HProp′ B = A .type →-HProp B
IsContr-IsProp : IsProp (IsContr A)
IsContr-IsProp (x , x-unique) (y , y-unique)
= Σ-≡⁺ (x-unique y , eq-prop _ _)
where
eq-prop : IsProp (∀ y′ → y ≡ y′)
eq-prop = ∀-IsProp λ γ′ → IsOfHLevel-suc 1 (IsOfHLevel-suc 0 (x , x-unique))
IsProp-IsProp : IsProp (IsProp A)
IsProp-IsProp A-prop A-prop′
= ∀-IsProp (λ x → ∀-IsProp λ y → IsOfHLevel-suc 1 A-prop) A-prop A-prop′
IsOfHLevel-IsProp : ∀ n → IsProp (IsOfHLevel n A)
IsOfHLevel-IsProp {A = A} zero = IsContr-IsProp
IsOfHLevel-IsProp (suc zero) = IsProp-IsProp
IsOfHLevel-IsProp (suc (suc n))
= ∀∙-IsProp λ x → ∀∙-IsProp λ y → IsOfHLevel-IsProp (suc n)
IsSet-IsProp : IsProp (IsSet A)
IsSet-IsProp = IsOfHLevel-IsProp 2
∀-IsSet : {A : Set α} {B : A → Set β}
→ (∀ a → IsSet (B a))
→ IsSet (∀ a → B a)
∀-IsSet B-set {f} {g} p q = let open ≡-Reasoning in
begin
p
≡˘⟨ funext∘≡→~ p ⟩
funext (≡→~ p)
≡⟨ cong funext (funext λ a → B-set a (≡→~ p a) (≡→~ q a)) ⟩
funext (≡→~ q)
≡⟨ funext∘≡→~ q ⟩
q
∎
∀∙-IsSet : {A : Set α} {B : A → Set β}
→ (∀ a → IsSet (B a))
→ IsSet (∀ {a} → B a)
∀∙-IsSet {A = A} {B = B} B-set = ≅-pres-IsOfHLevel 2 iso (∀-IsSet B-set)
where
iso : (∀ a → B a) ≅ (∀ {a} → B a)
iso = record
{ forth = λ f {a} → f a
; isIso = record
{ back = λ f a → f {a}
; back∘forth = λ _ → refl
; forth∘back = λ _ → refl
}
}
→-IsSet : IsSet B → IsSet (A → B)
→-IsSet B-set = ∀-IsSet (λ _ → B-set)
∀-HSet : (A : Set α) → (A → HSet β) → HSet (α ⊔ℓ β)
∀-HSet A B = HLevel⁺ (∀ a → B a .type) (∀-IsSet (λ a → B a .level))
∀∙-HSet : {A : Set α} → (A → HSet β) → HSet (α ⊔ℓ β)
∀∙-HSet B = HLevel⁺ (∀ {a} → B a .type) (∀∙-IsSet (λ a → B a .level))
HLevel-≡⁺ : ∀ {n} (A B : HLevel α n)
→ A .type ≡ B .type
→ A ≡ B
HLevel-≡⁺ (HLevel⁺ A A-level) (HLevel⁺ B B-level) refl
= cong (HLevel⁺ A) (IsOfHLevel-IsProp _ _ _)
IsContr-≅⁺ : IsContr A → IsContr B → A ≅ B
IsContr-≅⁺ (a , a-uniq) (b , b-uniq) = record
{ forth = λ _ → b
; isIso = record
{ back = λ _ → a
; back∘forth = λ _ → a-uniq _
; forth∘back = λ _ → b-uniq _
}
}
HContr-≡⁺ : (A B : HContr α) → A ≡ B
HContr-≡⁺ A B = HLevel-≡⁺ A B (≅→≡ (IsContr-≅⁺ (A .level) (B .level)))
IsProp-≅⁺ : IsProp A → IsProp B → A ↔ B → A ≅ B
IsProp-≅⁺ A-prop B-prop A↔B = record
{ forth = A↔B .forth
; isIso = record
{ back = A↔B .back
; back∘forth = λ _ → A-prop _ _
; forth∘back = λ _ → B-prop _ _
}
}
HProp-≡⁺ : (A B : HProp α) → A .type ↔ B .type → A ≡ B
HProp-≡⁺ A B A↔B = HLevel-≡⁺ A B (≅→≡ (IsProp-≅⁺ (A .level) (B .level) A↔B))
|
{
"alphanum_fraction": 0.5425129901,
"avg_line_length": 25.6606060606,
"ext": "agda",
"hexsha": "6db53e6e7797c396ad122224dd0c54af466923e1",
"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": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JLimperg/msc-thesis-code",
"max_forks_repo_path": "src/Util/HoTT/HLevel.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JLimperg/msc-thesis-code",
"max_issues_repo_path": "src/Util/HoTT/HLevel.agda",
"max_line_length": 79,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "104cddc6b65386c7e121c13db417aebfd4b7a863",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JLimperg/msc-thesis-code",
"max_stars_repo_path": "src/Util/HoTT/HLevel.agda",
"max_stars_repo_stars_event_max_datetime": "2021-06-26T06:37:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-04-13T21:31:17.000Z",
"num_tokens": 1993,
"size": 4234
}
|
{-# OPTIONS --without-K --safe #-}
module Experiment.FingerTree where
open import Level renaming (zero to lzero ; suc to lsuc)
open import Algebra
open import Experiment.FingerTree.Common
data Digit {a} (A : Set a) : Set a where
one : (a : A) → Digit A
two : (a b : A) → Digit A
three : (a b c : A) → Digit A
four : (a b c d : A) → Digit A
data Node {v a} (V : Set v) (A : Set a) : Set (a ⊔ v) where
:node2 : (v : V) → (a b : A) → Node V A
:node3 : (v : V) → (a b c : A) → Node V A
nodeToDigit : ∀ {v a} {V : Set v} {A : Set a} → Node V A → Digit A
nodeToDigit (:node2 v a b ) = two a b
nodeToDigit (:node3 v a b c) = three a b c
data FingerTree {v a} (V : Set v) (A : Set a) : Set (a ⊔ v) where
:empty : FingerTree V A
:single : A → FingerTree V A
:deep : V → Digit A → FingerTree V (Node V A) → Digit A → FingerTree V A
Digit-foldr : ∀ {a b} {A : Set a} {B : Set b} → (A → B → B) → B → Digit A → B
Digit-foldr _<>_ e (one a) = a <> e
Digit-foldr _<>_ e (two a b) = a <> (b <> e)
Digit-foldr _<>_ e (three a b c) = a <> (b <> (c <> e))
Digit-foldr _<>_ e (four a b c d) = a <> (b <> (c <> (d <> e)))
Node-foldr : ∀ {v a b} {V : Set v} {A : Set a} {B : Set b} →
(A → B → B) → B → Node V A → B
Node-foldr _<>_ e (:node2 v a b ) = a <> (b <> e)
Node-foldr _<>_ e (:node3 v a b c) = a <> (b <> (c <> e))
Node-measure : ∀ {v a} {V : Set v} {A : Set a} → Node V A → V
Node-measure (:node2 v a b ) = v
Node-measure (:node3 v a b c) = v
record IsMeasured {c e a} (M : Monoid c e) (A : Set a) : Set (a ⊔ c ⊔ e) where
open Monoid M
field
measure : A → Carrier
module Constructor {c e a} {A : Set a} {M : Monoid c e} (MS : IsMeasured M A) where
open Monoid M renaming (Carrier to V)
open IsMeasured MS
empty : FingerTree V A
empty = :empty
single : A → FingerTree V A
single = :single
deep : Digit A → FingerTree V (Node V A) → Digit A → FingerTree V A
deep pr m sf = :deep {! (Node-measure pr ∙ measure m) ∙ Node-measure sf !} pr m sf
|
{
"alphanum_fraction": 0.5426739023,
"avg_line_length": 33.7833333333,
"ext": "agda",
"hexsha": "d8896d707682006084ba7ed8882b5eed022d81a0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/FingerTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/FingerTree.agda",
"max_line_length": 85,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/FingerTree.agda",
"max_stars_repo_stars_event_max_datetime": "2020-04-21T00:03:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:49:42.000Z",
"num_tokens": 798,
"size": 2027
}
|
module string where
open import bool
open import eq
open import char
open import list
open import nat
open import unit
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
postulate
string : Set
{-# BUILTIN STRING string #-}
private
primitive
primStringToList : string → 𝕃 char
primStringAppend : string → string → string
primStringFromList : 𝕃 char → string
primStringEquality : string → string → 𝔹
-- see string-thms.agda for some axioms about the above primitive functions
----------------------------------------------------------------------
-- syntax
----------------------------------------------------------------------
infixr 6 _^_
infix 8 _=string_
----------------------------------------------------------------------
-- operations
----------------------------------------------------------------------
_^_ : string → string → string
_^_ = primStringAppend
string-to-𝕃char : string → 𝕃 char
string-to-𝕃char = primStringToList
𝕃char-to-string : 𝕃 char → string
𝕃char-to-string = primStringFromList
_=string_ : string → string → 𝔹
_=string_ = primStringEquality
char-to-string : char → string
char-to-string c = 𝕃char-to-string [ c ]
string-append-t : ℕ → Set
string-append-t 0 = string → string
string-append-t (suc n) = string → (string-append-t n)
string-append-h : (n : ℕ) → string → string-append-t n
string-append-h 0 ret = λ x → ret ^ x
string-append-h (suc n) ret = λ x → (string-append-h n (ret ^ x))
string-append : (n : ℕ) → string-append-t n
string-append n = string-append-h n ""
string-concat : 𝕃 string → string
string-concat [] = ""
string-concat (s :: ss) = s ^ (string-concat ss)
string-concat-sep : (separator : string) → 𝕃 string → string
string-concat-sep sep [] = ""
string-concat-sep sep (s1 :: ss) with ss
... | [] = s1
... | s2 :: ss' = s1 ^ sep ^ (string-concat-sep sep ss)
string-concat-sep-map : ∀{A : Set} → (separator : string) → (A → string) → 𝕃 A → string
string-concat-sep-map sep f l = string-concat-sep sep (map f l)
escape-string-h : 𝕃 char → 𝕃 char
escape-string-h ('\n' :: cs) = '\\' :: 'n' :: (escape-string-h cs)
escape-string-h ('"' :: cs) = '\\' :: '"' :: (escape-string-h cs)
escape-string-h (c :: cs) = c :: escape-string-h cs
escape-string-h [] = []
escape-string : string → string
escape-string s = 𝕃char-to-string( escape-string-h( string-to-𝕃char s ) )
string-length : string → ℕ
string-length s = length (string-to-𝕃char s)
|
{
"alphanum_fraction": 0.5537974684,
"avg_line_length": 27.4782608696,
"ext": "agda",
"hexsha": "455b66eecf7ebb4d74017d63d501b1e59e921ca1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "heades/AUGL",
"max_forks_repo_path": "string.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "string.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "heades/AUGL",
"max_stars_repo_path": "string.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 665,
"size": 2528
}
|
-- Andreas, 2019-02-23, issue #3586, reported by mcoblenz shrunk by G. Allais
-- WAS: Internal error in ConcreteToAbstract.
-- {-# OPTIONS -v scope.pat:60 #-}
infixl 5 ^_
data D : Set where
^_ : D → D
postulate
_^_ : D → D → D
foo : D → Set
foo x@(y ^ z) = D
-- The term "y ^ z" is parsed as operator pattern (_^_ y z)
-- with _^_ being a variable name.
-- That is nonsense the scope checker did not expect and crashed.
-- Now, we report instead:
--
-- y ^ z is not a valid pattern
|
{
"alphanum_fraction": 0.6356275304,
"avg_line_length": 21.4782608696,
"ext": "agda",
"hexsha": "a7fcb5f259d6d5558f3a544ecbbe06809d0255b7",
"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/Issue3586.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/Issue3586.agda",
"max_line_length": 77,
"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/Issue3586.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": 163,
"size": 494
}
|
------------------------------------------------------------------------------
-- Lists
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Data.List where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List.Type public
infixr 5 _++_
------------------------------------------------------------------------------
-- Basic functions
postulate
length : D → D
length-[] : length [] ≡ zero
length-∷ : ∀ x xs → length (x ∷ xs) ≡ succ₁ (length xs)
{-# ATP axioms length-[] length-∷ #-}
postulate
_++_ : D → D → D
++-[] : ∀ ys → [] ++ ys ≡ ys
++-∷ : ∀ x xs ys → (x ∷ xs) ++ ys ≡ x ∷ (xs ++ ys)
{-# ATP axioms ++-[] ++-∷ #-}
-- List transformations
postulate
map : D → D → D
map-[] : ∀ f → map f [] ≡ []
map-∷ : ∀ f x xs → map f (x ∷ xs) ≡ f · x ∷ map f xs
{-# ATP axioms map-[] map-∷ #-}
postulate
rev : D → D → D
rev-[] : ∀ ys → rev [] ys ≡ ys
rev-∷ : ∀ x xs ys → rev (x ∷ xs) ys ≡ rev xs (x ∷ ys)
{-# ATP axioms rev-[] rev-∷ #-}
reverse : D → D
reverse xs = rev xs []
{-# ATP definition reverse #-}
postulate
reverse' : D → D
reverse'-[] : reverse' [] ≡ []
reverse'-∷ : ∀ x xs → reverse' (x ∷ xs) ≡ reverse' xs ++ (x ∷ [])
postulate
replicate : D → D → D
replicate-0 : ∀ x → replicate zero x ≡ []
replicate-S : ∀ n x → replicate (succ₁ n) x ≡ x ∷ replicate n x
{-# ATP axioms replicate-0 replicate-S #-}
-- Reducing lists
postulate
foldr : D → D → D → D
foldr-[] : ∀ f n → foldr f n [] ≡ n
foldr-∷ : ∀ f n x xs → foldr f n (x ∷ xs) ≡ f · x · (foldr f n xs)
{-# ATP axioms foldr-[] foldr-∷ #-}
-- Building lists
postulate
iterate : D → D → D
iterate-eq : ∀ f x → iterate f x ≡ x ∷ iterate f (f · x)
{-# ATP axiom iterate-eq #-}
|
{
"alphanum_fraction": 0.4304733728,
"avg_line_length": 26.6842105263,
"ext": "agda",
"hexsha": "a5f3c0f66d351a13b3139c538fd3beb6f91e28a6",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Data/List.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Data/List.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Data/List.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": 639,
"size": 2028
}
|
-- Andrea(s), 2018-11-23, issue #3378
--
-- WAS: internal error in coverage checker and clause compiler
-- for missing hcomp clauses triggered by non-exact splitting.
{-# OPTIONS --cubical #-}
-- {-# OPTIONS -v tc.cover:10 #-}
open import Agda.Builtin.Cubical.Path
open import Agda.Builtin.Unit
data Interval : Set where
pos : Interval
neg : Interval
zeroes-identified : pos ≡ neg
test : Interval → Interval → ⊤
test pos pos = tt
test neg pos = tt
test (zeroes-identified i) pos = tt
test x neg = tt
test x (zeroes-identified j) = tt
-- Should pass (with non-exact splitting).
|
{
"alphanum_fraction": 0.6977928693,
"avg_line_length": 22.6538461538,
"ext": "agda",
"hexsha": "1f14375f02217bd2c971576af7fcf35cf4229e84",
"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/Issue3378.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/Issue3378.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue3378.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": 589
}
|
{-# OPTIONS --show-implicit #-}
data Bool : Set where
true : Bool
false : Bool
data D : Set where
d : D
data E : Set where
e : E
HSet : Set₁
HSet = {b : Bool} → Set
-- Here HA is HSet
-- The output of this function is the set E, for input HSet G.
⊨_ : HSet → Set
⊨_ HA = HA {true}
G : HSet
G {true} = E
G {false} = D
noo : ⊨ G {false}
noo = {!!}
boo : ⊨ λ {b} → G {b}
boo = {!!}
|
{
"alphanum_fraction": 0.546835443,
"avg_line_length": 13.1666666667,
"ext": "agda",
"hexsha": "12a28add40ad5648cd3ef98c0392a376f11ae551",
"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/Issue4160.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/Issue4160.agda",
"max_line_length": 62,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue4160.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 156,
"size": 395
}
|
{-# OPTIONS --without-K #-}
module Perm where
-- Definitions for permutations in the Cauchy representation
open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
open import Relation.Unary using (Pred)
renaming (Decidable to UnaryDecidable)
open import Relation.Binary.PropositionalEquality
using (_≡_; refl; sym; trans; subst; subst₂; cong; cong₂; setoid;
proof-irrelevance; module ≡-Reasoning)
open import Relation.Binary.PropositionalEquality.TrustMe
using (trustMe)
open import Relation.Nullary using (Dec; yes; no; ¬_)
open import Data.Nat.Properties
using (cancel-+-left; n∸n≡0; +-∸-assoc; m+n∸n≡m; 1+n≰n; m≤m+n;
n≤m+n; n≤1+n; cancel-*-right-≤; ≰⇒>; ¬i+1+j≤i)
open import Data.Nat.Properties.Simple
using (+-right-identity; +-suc; +-assoc; +-comm;
*-assoc; *-comm; *-right-zero; distribʳ-*-+; +-*-suc)
open import Data.Nat.DivMod using (DivMod; result; _divMod_; _div_; _mod_)
open import Relation.Binary using (Rel; Decidable; Setoid)
open import Relation.Binary.Core using (REL; Transitive; _⇒_)
open import Data.String using (String)
renaming (_++_ to _++S_)
open import Data.Nat.Show using (show)
open import Data.Bool using (Bool; false; true)
open import Data.Nat using (ℕ; suc; _+_; _∸_; _*_; _<_; _≮_; _≤_; _≰_;
_≥_; z≤n; s≤s; _≟_; _≤?_; ≤-pred; module ≤-Reasoning)
open import Data.Fin
using (Fin; zero; suc; toℕ; fromℕ; fromℕ≤; _ℕ-_; _≺_; reduce≥;
raise; inject+; inject₁; inject≤; _≻toℕ_)
renaming (_+_ to _F+_)
open import Data.Fin.Properties
using (bounded; to-from; inject+-lemma; inject≤-lemma; toℕ-injective;
toℕ-raise; toℕ-fromℕ≤)
open import Data.Vec.Properties
using (lookup∘tabulate; tabulate∘lookup; lookup-allFin; tabulate-∘;
tabulate-allFin; allFin-map; lookup-++-inject+; lookup-++-≥;
lookup-++-<)
open import Data.Product using (Σ; swap)
open import Data.List
using (List; []; _∷_; _∷ʳ_; foldl; replicate; reverse; downFrom;
concatMap; gfilter; initLast; InitLast; _∷ʳ'_)
renaming (_++_ to _++L_; map to mapL; concat to concatL; zip to zipL)
open import Data.List.NonEmpty
using (List⁺; [_]; _∷⁺_; head; last; _⁺++_)
renaming (toList to nonEmptyListtoList; _∷ʳ_ to _n∷ʳ_; tail to ntail)
open import Data.List.Any using (Any; here; there; any; module Membership)
open import Data.Maybe using (Maybe; nothing; just; maybe′)
open import Data.Vec
using (Vec; tabulate; []; _∷_; tail; lookup; zip; zipWith; splitAt;
_[_]≔_; allFin; toList)
renaming (_++_ to _++V_; map to mapV; concat to concatV)
open import Function using (id; _∘_; _$_; flip)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Unit using (⊤; tt)
open import Data.Sum using (_⊎_; inj₁; inj₂)
open import Data.Product using (_×_; _,_; proj₁; proj₂)
open import Proofs
open import Cauchy
------------------------------------------------------------------------------
-- What JC thinks will actually work
-- we need injectivity. surjectivity ought to be provable.
Permutation : ℕ → Set
Permutation n = Σ (Cauchy n) (λ v → ∀ {i j} → lookup i v ≡ lookup j v → i ≡ j)
------------------------------------------------------------------------------
-- Iso between Fin (m * n) and Fin m × Fin n
absurd-quotient : (m n q : ℕ) (r : Fin (suc n)) (k : Fin (suc (n + m * suc n)))
(k≡r+q*sn : toℕ k ≡ toℕ r + q * suc n) (p : suc m ≤ q) → ⊥
absurd-quotient m n q r k k≡r+q*sn p = ¬i+1+j≤i (toℕ k) {toℕ r} k≥k+sr
where k≥k+sr : toℕ k ≥ toℕ k + suc (toℕ r)
k≥k+sr = begin (toℕ k + suc (toℕ r)
≡⟨ +-suc (toℕ k) (toℕ r) ⟩
suc (toℕ k) + toℕ r
≤⟨ cong+r≤ (bounded k) (toℕ r) ⟩
(suc n + m * suc n) + toℕ r
≡⟨ +-comm (suc n + m * suc n) (toℕ r) ⟩
toℕ r + (suc n + m * suc n)
≡⟨ refl ⟩
toℕ r + suc m * suc n
≤⟨ cong+l≤ (cong*r≤ p (suc n)) (toℕ r) ⟩
toℕ r + q * suc n
≡⟨ sym k≡r+q*sn ⟩
toℕ k ∎)
where open ≤-Reasoning
Fin0-⊥ : Fin 0 → ⊥
Fin0-⊥ ()
fin-project : (m n : ℕ) → Fin (m * n) → Fin m × Fin n
fin-project 0 n ()
fin-project (suc m) 0 k = ⊥-elim (Fin0-⊥ (subst Fin (*-right-zero (suc m)) k))
fin-project (suc m) (suc n) k with (toℕ k) divMod (suc n)
... | result q r k≡r+q*sn = (fromℕ≤ {q} {suc m} (s≤s q≤m) , r)
where q≤m : q ≤ m
q≤m with suc m ≤? q
... | yes p = ⊥-elim (absurd-quotient m n q r k k≡r+q*sn p)
... | no ¬p = ≤-pred (≰⇒> ¬p)
fin-proj-lem : (m n : ℕ) (k : Fin (m * n)) →
k ≡ let (b , d) = fin-project m n k in
inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)
fin-proj-lem 0 n ()
fin-proj-lem (suc m) 0 k = ⊥-elim (Fin0-⊥ (subst Fin (*-right-zero (suc m)) k))
fin-proj-lem (suc m) (suc n) k with _divMod_ (toℕ k) (suc n) {_}
... | result q r k≡r+q*sn with suc m ≤? q
... | yes p = ⊥-elim (absurd-quotient m n q r k k≡r+q*sn p)
... | no ¬p = toℕ-injective toℕk≡
where q≡ : (m : ℕ) (q : ℕ) (¬p : ¬ suc m ≤ q) →
q ≡ toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p))))
q≡ m q ¬p = sym (toℕ-fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p))))
toℕk≡ = begin (toℕ k
≡⟨ k≡r+q*sn ⟩
toℕ r + q * suc n
≡⟨ +-comm (toℕ r) (q * suc n) ⟩
q * suc n + toℕ r
≡⟨ cong
(λ x → x * suc n + toℕ r)
(q≡ m q ¬p) ⟩
toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) * suc n + toℕ r
≡⟨ sym (to-from
(toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) * suc n + toℕ r)) ⟩
toℕ (fromℕ
(toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) * suc n + toℕ r))
≡⟨ sym
(inject≤-lemma
(fromℕ
(toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) * suc n + toℕ r))
(i*n+k≤m*n (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) r)) ⟩
toℕ
(inject≤
(fromℕ
(toℕ (fromℕ≤ (s≤s (≤-pred (≰⇒> ¬p)))) * suc n + toℕ r))
(i*n+k≤m*n
(fromℕ≤ {q} {suc m} (s≤s (≤-pred (≰⇒> ¬p)))) r)) ∎)
where open ≡-Reasoning
fin-proj-lem2 : (m n : ℕ) (b : Fin m) (d : Fin n) →
(b , d) ≡ fin-project m n
(inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d))
fin-proj-lem2 m 0 b ()
fin-proj-lem2 0 (suc n) () d
fin-proj-lem2 (suc m) (suc n) b d with
(toℕ (inject≤ (fromℕ (toℕ b * suc n + toℕ d)) (i*n+k≤m*n b d))) divMod (suc n)
... | result q r eq =
begin ((b , d)
≡⟨ cong₂ _,_
(toℕ-injective
(sym
(trans
(toℕ-fromℕ≤ (s≤s (trans≤ (refl′ (proj₁ eq')) (bounded' m b))))
(proj₁ eq'))) )
(sym (proj₂ eq')) ⟩
(fromℕ≤ (s≤s (trans≤ (refl′ (proj₁ eq')) (bounded' m b))) , r)
≡⟨ cong₂ _,_ (cong fromℕ≤ (≤-proof-irrelevance _ _)) refl ⟩
(fromℕ≤ _ , r) ∎)
where open ≡-Reasoning
eq' : q ≡ toℕ b × r ≡ d
eq' = swap
(addMul-lemma′ q (toℕ b) n r d
(trans
(trans (+-comm (q * suc n) (toℕ r)) (sym eq))
(trans (inject≤-lemma _ _) (to-from _))))
-- The actual isomorphism
record Fin-Product-Iso (m n : ℕ) : Set where
constructor iso
field
split : Fin (m * n) → Fin m × Fin n
combine : Fin m × Fin n → Fin (m * n)
inv : (i : Fin (m * n)) → combine (split i) ≡ i
inv' : (bd : Fin m × Fin n) → split (combine bd) ≡ bd
fin-product-iso : (m n : ℕ) → Fin-Product-Iso m n
fin-product-iso m n =
iso
(fin-project m n)
(λ {(b , d) → inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)})
(λ k → sym (fin-proj-lem m n k))
((λ {(b , d) → sym (fin-proj-lem2 m n b d)}))
record Fin-DivMod (m n : ℕ) (i : Fin (m * n)) : Set where
constructor fin-result
field
b : Fin m
d : Fin n
dec : toℕ i ≡ toℕ d + toℕ b * n
dec' : i ≡ inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d)
fin-divMod : (m n : ℕ) (i : Fin (m * n)) → Fin-DivMod m n i
fin-divMod m n i = fin-result b d dec dec'
where
bd = Fin-Product-Iso.split (fin-product-iso m n) i
b = proj₁ bd
d = proj₂ bd
dec' = sym (Fin-Product-Iso.inv (fin-product-iso m n) i)
dec = begin (toℕ i
≡⟨ cong toℕ (sym (inv (fin-product-iso m n) i)) ⟩
toℕ (inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d))
≡⟨ inject≤-lemma (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d) ⟩
toℕ (fromℕ (toℕ b * n + toℕ d))
≡⟨ to-from (toℕ b * n + toℕ d) ⟩
toℕ b * n + toℕ d
≡⟨ +-comm (toℕ b * n) (toℕ d) ⟩
toℕ d + toℕ b * n ∎)
where open ≡-Reasoning
open Fin-Product-Iso
fin-addMul-lemma : (m n : ℕ) (b b' : Fin m) (d d' : Fin n) →
toℕ b * n + toℕ d ≡ toℕ b' * n + toℕ d' → b ≡ b' × d ≡ d'
fin-addMul-lemma m 0 _ _ ()
fin-addMul-lemma m (suc n) b b' d d' p =
let (d≡ , b≡) = addMul-lemma′ (toℕ b) (toℕ b') n d d' p
in (toℕ-injective b≡ , d≡)
------------------------------------------------------------------------------
-- Vec lemmas
fi≡fj : {m : ℕ} → (i j : Fin m) (f : Fin m → Fin m) →
(p : lookup i (tabulate f) ≡ lookup j (tabulate f)) → (f i ≡ f j)
fi≡fj i j f p = trans
(sym (lookup∘tabulate f i))
(trans p (lookup∘tabulate f j))
lookup-bounded : (m n : ℕ) (i : Fin n) (v : Vec (Fin m) n) → toℕ (lookup i v) < m
lookup-bounded m 0 () v
lookup-bounded m (suc n) zero (x ∷ v) = bounded x
lookup-bounded m (suc n) (suc i) (x ∷ v) = lookup-bounded m n i v
lookup-concat-left : ∀ {ℓ} {A : Set ℓ} {m n : ℕ} →
(d : Fin n) (leq : suc (toℕ d) ≤ n + m) (vs : Vec A n) (ws : Vec A m) →
lookup (inject≤ (fromℕ (toℕ d)) leq) (vs ++V ws) ≡ lookup d vs
lookup-concat-left zero (s≤s z≤n) (x ∷ vs) ws = refl
lookup-concat-left (suc d) (s≤s leq) (x ∷ vs) ws = lookup-concat-left d leq vs ws
lookup-concat-right : ∀ {ℓ} {A : Set ℓ} {m n : ℕ} →
(j : ℕ) (leq : suc (n + j) ≤ n + m) (leq' : suc j ≤ m)
(vs : Vec A n) (ws : Vec A m) →
lookup (inject≤ (fromℕ (n + j)) leq) (vs ++V ws) ≡
lookup (inject≤ (fromℕ j) leq') ws
lookup-concat-right {n = 0} j leq leq' [] ws =
cong
(λ x → lookup (inject≤ (fromℕ j) x) ws)
(≤-proof-irrelevance leq leq')
lookup-concat-right {n = suc n} j (s≤s leq) leq' (v ∷ vs) ws =
lookup-concat-right j leq leq' vs ws
lookup-concat-right' : ∀ {ℓ} {A : Set ℓ} {m n : ℕ} →
(j k : ℕ) (leq : suc ((n + j) + k) ≤ n + m) (leq' : suc (j + k) ≤ m)
(vs : Vec A n) (ws : Vec A m) →
lookup (inject≤ (fromℕ ((n + j) + k)) leq) (vs ++V ws) ≡
lookup (inject≤ (fromℕ (j + k)) leq') ws
lookup-concat-right' {n = 0} j k leq leq' [] ws =
cong
(λ x → lookup (inject≤ (fromℕ (j + k)) x) ws)
(≤-proof-irrelevance leq leq')
lookup-concat-right' {n = suc n} j k (s≤s leq) leq' (v ∷ vs) ws =
lookup-concat-right' j k leq leq' vs ws
helper-leq : (m n : ℕ) → (b : Fin m) →
suc (n + toℕ b * suc n) ≤ n + m * suc n
helper-leq m n b =
begin (suc (n + toℕ b * suc n)
≡⟨ cong suc (+-comm n (toℕ b * suc n)) ⟩
suc (toℕ b * suc n + n)
≡⟨ cong (λ x → suc (toℕ b * suc n + x)) (sym (to-from n)) ⟩
suc (toℕ b * suc n + toℕ (fromℕ n))
≤⟨ i*n+k≤m*n b (fromℕ n) ⟩
m * suc n
≤⟨ n≤m+n n (m * suc n) ⟩
n + m * suc n ∎)
where open ≤-Reasoning
helper-leq' : (m n : ℕ) → (b : Fin m) →
suc (toℕ b * suc n) ≤ m * suc n
helper-leq' 0 n ()
helper-leq' (suc m) n zero = s≤s z≤n
helper-leq' (suc m) n (suc b) = s≤s (helper-leq m n b)
lookup-concat-inner : {ℓ₁ ℓ₂ ℓ₃ : Level} {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃} →
(m n : ℕ) (b : Fin m) (j : B)
(leq : suc (toℕ b * suc n) ≤ m * suc n)
(f : A × B → C) (pm : Vec A m) (pn : Vec B n) →
lookup
(inject≤ (fromℕ (toℕ b * suc n)) leq)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡ f (lookup b pm , j)
lookup-concat-inner 0 n () j leq f pm pn
lookup-concat-inner (suc m) n zero j (s≤s z≤n) f (i ∷ pm) pn = refl
lookup-concat-inner (suc m) n (suc b) j (s≤s leq) f (i ∷ pm) pn =
begin (lookup
(inject≤ (fromℕ (n + toℕ b * suc n)) leq)
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat-right (toℕ b * suc n) leq (helper-leq' m n b)
(mapV (λ d → f (i , d)) pn)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm)) ⟩
lookup
(inject≤ (fromℕ (toℕ b * suc n)) (helper-leq' m n b))
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat-inner m n b j (helper-leq' m n b) f pm pn ⟩
f (lookup b pm , j) ∎)
where open ≡-Reasoning
lookup-concat' : ∀ {ℓ₁ ℓ₂ ℓ₃} {A : Set ℓ₁} {B : Set ℓ₂} {C : Set ℓ₃} →
(m n : ℕ) (b : Fin m) (d : Fin n) →
(leq : suc (toℕ b * n + toℕ d) ≤ m * n) →
(f : A × B → C) (pm : Vec A m) (pn : Vec B n) →
lookup
(inject≤ (fromℕ (toℕ b * n + toℕ d)) leq)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) pn) pm)) ≡
f (lookup b pm , lookup d pn)
lookup-concat' 0 n () d leq f pm pn
lookup-concat' (suc m) n zero d leq f (i ∷ pm) pn =
begin (lookup
(inject≤ (fromℕ (toℕ d)) leq)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) pn) (i ∷ pm)))
≡⟨ refl ⟩
lookup
(inject≤ (fromℕ (toℕ d)) leq)
(concatV (mapV (λ d → f (i , d)) pn ∷
mapV (λ b → mapV (λ d → f (b , d)) pn) pm))
≡⟨ refl ⟩
lookup
(inject≤ (fromℕ (toℕ d)) leq)
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) pn) pm))
≡⟨ lookup-concat-left d leq
(mapV (λ d → f (i , d)) pn)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) pn) pm)) ⟩
lookup d (mapV (λ d → f (i , d)) pn)
≡⟨ lookup-map d (λ d → f (i , d)) pn ⟩
f (i , lookup d pn) ∎)
where open ≡-Reasoning
lookup-concat' (suc m) 0 (suc b) () leq f (i ∷ pm) pn
lookup-concat' (suc m) (suc n) (suc b) zero (s≤s leq) f (i ∷ pm) (j ∷ pn) =
begin (lookup
(inject≤ (fromℕ ((n + toℕ b * suc n) + 0)) leq)
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ cong₂D!
(λ x y →
lookup
(inject≤ (fromℕ x) y)
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm)))
(sym (+-right-identity (n + toℕ b * suc n)))
(≤-proof-irrelevance
(subst
(λ z → suc z ≤ n + m * suc n)
(sym (+-right-identity (n + toℕ b * suc n)))
(helper-leq m n b))
leq) ⟩
lookup
(inject≤
(fromℕ (n + toℕ b * suc n))
(helper-leq m n b))
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat-right
(toℕ b * suc n)
(helper-leq m n b)
(helper-leq' m n b)
(mapV (λ d → f (i , d)) pn)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm)) ⟩
lookup
(inject≤ (fromℕ (toℕ b * suc n)) (helper-leq' m n b))
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat-inner m n b j (helper-leq' m n b) f pm pn ⟩
f (lookup b pm , j) ∎)
where open ≡-Reasoning
lookup-concat' (suc m) (suc n) (suc b) (suc d) (s≤s leq) f (i ∷ pm) (j ∷ pn) =
begin (lookup
(inject≤ (fromℕ ((n + toℕ b * suc n) + toℕ (suc d))) leq)
(mapV (λ d → f (i , d)) pn ++V
concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat-right' (toℕ b * suc n) (toℕ (suc d)) leq (i*n+k≤m*n b (suc d))
(mapV (λ d → f (i , d)) pn)
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm)) ⟩
lookup
(inject≤ (fromℕ (toℕ b * suc n + toℕ (suc d))) (i*n+k≤m*n b (suc d)))
(concatV (mapV (λ b → mapV (λ d → f (b , d)) (j ∷ pn)) pm))
≡⟨ lookup-concat' m (suc n) b (suc d) (i*n+k≤m*n b (suc d)) f pm (j ∷ pn) ⟩
f (lookup b pm , lookup d pn) ∎)
where open ≡-Reasoning
lookup-2d : (m n : ℕ) (i : Fin (m * n)) (α : Cauchy m) (β : Cauchy n) →
(h : (Fin m × Fin n) → Fin (m * n)) →
lookup i (concatV (mapV (λ b → mapV (λ d → h (b , d)) β) α)) ≡
let fin-result b d _ _ = fin-divMod m n i in h (lookup b α , lookup d β)
lookup-2d m n i α β h =
let fin-result b d dec dec' = fin-divMod m n i in
begin (lookup i (concatV (mapV (λ b → mapV (λ d → h (b , d)) β) α))
≡⟨ cong
(λ x → lookup x (concatV (mapV (λ b → mapV (λ d → h (b , d)) β) α)))
dec' ⟩
lookup
(inject≤ (fromℕ (toℕ b * n + toℕ d)) (i*n+k≤m*n b d))
(concatV (mapV (λ b → mapV (λ d → h (b , d)) β) α))
≡⟨ lookup-concat' m n b d (i*n+k≤m*n b d) h α β ⟩
h (lookup b α , lookup d β) ∎)
where open ≡-Reasoning
------------------------------------------------------------------------------
-- Elementary permutations in the Cauchy representation
emptyperm : Permutation 0
emptyperm = (emptycauchy , f)
where f : {i j : Fin 0} → (lookup i emptycauchy ≡ lookup j emptycauchy) → (i ≡ j)
f {()}
idperm : (n : ℕ) → Permutation n
idperm n = (idcauchy n , λ {i} {j} p → fi≡fj i j id p)
-- Sequential composition
scompperm : ∀ {n} → Permutation n → Permutation n → Permutation n
scompperm {n} (α , f) (β , g) =
(scompcauchy α β ,
λ {i} {j} p → f (g (fi≡fj i j (λ i → lookup (lookup i α) β) p)))
-- swap the first m elements with the last n elements
-- [ v₀ , v₁ , v₂ , ... , vm-1 , vm , vm₊₁ , ... , vm+n-1 ]
-- ==>
-- [ vm , vm₊₁ , ... , vm+n-1 , v₀ , v₁ , v₂ , ... , vm-1 ]
swap+cauchy< : (m n : ℕ) (i : Fin (m + n)) (i< : toℕ i < m) →
lookup i (swap+cauchy m n) ≡ id+ {m} (raise n (fromℕ≤ i<))
swap+cauchy< m n i i< =
let j = fromℕ≤ i< in
let eq = inj₁-≡ i i< in
begin
(lookup i (splitVOp+ {m} {n} {f = id+ {m}})
≡⟨ cong (flip lookup (splitVOp+ {m} {n} {f = id+ {m}})) eq ⟩
lookup (inject+ n j) (splitVOp+ {m} {n} {f = id+ {m}})
≡⟨ lookup-++-inject+ (tabulate (id+ {m} ∘ raise n)) (tabulate (id+ {m} ∘ inject+ m)) j ⟩
lookup j (tabulate {m} (id+ {m} ∘ raise n))
≡⟨ lookup∘tabulate (id+ {m} ∘ raise n) j ⟩
id+ {m} (raise n j) ∎)
where open ≡-Reasoning
swap+cauchy≥ : (m n : ℕ) (i : Fin (m + n)) (i≥ : m ≤ toℕ i) →
lookup i (swap+cauchy m n) ≡ subst Fin (+-comm n m) (inject+ m (reduce≥ i i≥))
swap+cauchy≥ m n i i≥ =
let j = reduce≥ i i≥ in
let eq = inj₂-≡ i i≥ in
let v = splitVOp+ {m} {f = id+ {m}} in
begin (
lookup i v
≡⟨ cong (flip lookup v) eq ⟩
lookup (raise m j) v
≡⟨ lookup-++-raise (tabulate (id+ {m} ∘ raise n)) (tabulate (id+ {m} ∘ inject+ m)) j ⟩
lookup j (tabulate (id+ {m} ∘ inject+ m))
≡⟨ lookup∘tabulate (id+ {m} ∘ inject+ m) j ⟩
id+ {m} (inject+ m j) ∎)
where open ≡-Reasoning
swap+perm' : (m n : ℕ) (i j : Fin (m + n))
(p : lookup i (swap+cauchy m n) ≡ lookup j (swap+cauchy m n)) → (i ≡ j)
swap+perm' m n i j p with toℕ i <? m | toℕ j <? m
... | yes i< | yes j< = toℕ-injective (cancel-+-left n {toℕ i} {toℕ j} ni≡nj)
where ni≡nj = begin (n + toℕ i
≡⟨ sym (raise< m n i i<) ⟩
toℕ (subst Fin (+-comm n m) (raise n (fromℕ≤ i<)))
≡⟨ cong toℕ (sym (swap+cauchy< m n i i<)) ⟩
toℕ (lookup i (swap+cauchy m n))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (swap+cauchy m n))
≡⟨ cong toℕ (swap+cauchy< m n j j<) ⟩
toℕ (subst Fin (+-comm n m) (raise n (fromℕ≤ j<)))
≡⟨ raise< m n j j< ⟩
n + toℕ j ∎)
where open ≡-Reasoning
... | yes i< | no j≥ = ⊥-elim (1+n≰n contra')
where contra : n + toℕ i ≡ toℕ j ∸ m
contra = begin (n + toℕ i
≡⟨ sym (raise< m n i i<) ⟩
toℕ (subst Fin (+-comm n m) (raise n (fromℕ≤ i<)))
≡⟨ cong toℕ (sym (swap+cauchy< m n i i<)) ⟩
toℕ (lookup i (swap+cauchy m n))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (swap+cauchy m n))
≡⟨ cong toℕ (swap+cauchy≥ m n j (≤-pred (≰⇒> j≥))) ⟩
toℕ (subst Fin (+-comm n m)
(inject+ m (reduce≥ j (≤-pred (≰⇒> j≥)))))
≡⟨ inject≥ m n j (≤-pred (≰⇒> j≥)) ⟩
toℕ j ∸ m ∎)
where open ≡-Reasoning
contra' : suc (m + n) ≤ m + n
contra' = begin (suc (m + n)
≤⟨ m≤m+n (suc (m + n)) (toℕ i) ⟩
suc (m + n) + toℕ i
≡⟨ +-assoc (suc m) n (toℕ i) ⟩
suc (m + (n + toℕ i))
≡⟨ cong (λ x → suc m + x) contra ⟩
suc (m + (toℕ j ∸ m))
≡⟨ cong suc (sym (+-∸-assoc m (≤-pred (≰⇒> j≥)))) ⟩
suc ((m + toℕ j) ∸ m)
≡⟨ cong (λ x → suc (x ∸ m)) (+-comm m (toℕ j)) ⟩
suc ((toℕ j + m) ∸ m)
≡⟨ cong suc (m+n∸n≡m (toℕ j) m) ⟩
suc (toℕ j)
≤⟨ bounded j ⟩
m + n ∎)
where open ≤-Reasoning
... | no i≥ | yes j< = ⊥-elim (1+n≰n contra')
where contra : n + toℕ j ≡ toℕ i ∸ m
contra = begin (n + toℕ j
≡⟨ sym (raise< m n j j<) ⟩
toℕ (subst Fin (+-comm n m) (raise n (fromℕ≤ j<)))
≡⟨ cong toℕ (sym (swap+cauchy< m n j j<)) ⟩
toℕ (lookup j (swap+cauchy m n))
≡⟨ cong toℕ (sym p) ⟩
toℕ (lookup i (swap+cauchy m n))
≡⟨ cong toℕ (swap+cauchy≥ m n i (≤-pred (≰⇒> i≥))) ⟩
toℕ (subst Fin (+-comm n m)
(inject+ m (reduce≥ i (≤-pred (≰⇒> i≥)))))
≡⟨ inject≥ m n i (≤-pred (≰⇒> i≥)) ⟩
toℕ i ∸ m ∎)
where open ≡-Reasoning
contra' : suc (m + n) ≤ m + n
contra' = begin (suc (m + n)
≤⟨ m≤m+n (suc (m + n)) (toℕ j) ⟩
suc (m + n) + toℕ j
≡⟨ +-assoc (suc m) n (toℕ j) ⟩
suc (m + (n + toℕ j))
≡⟨ cong (λ x → suc m + x) contra ⟩
suc (m + (toℕ i ∸ m))
≡⟨ cong suc (sym (+-∸-assoc m (≤-pred (≰⇒> i≥)))) ⟩
suc ((m + toℕ i) ∸ m)
≡⟨ cong (λ x → suc (x ∸ m)) (+-comm m (toℕ i)) ⟩
suc ((toℕ i + m) ∸ m)
≡⟨ cong suc (m+n∸n≡m (toℕ i) m) ⟩
suc (toℕ i)
≤⟨ bounded i ⟩
m + n ∎)
where open ≤-Reasoning
... | no i≥ | no j≥ = ∸≡ m n i j (≤-pred (≰⇒> i≥)) (≤-pred (≰⇒> j≥)) ri≡rj
where ri≡rj = begin (toℕ i ∸ m
≡⟨ sym (inject≥ m n i (≤-pred (≰⇒> i≥))) ⟩
toℕ (subst Fin (+-comm n m)
(inject+ m (reduce≥ i (≤-pred (≰⇒> i≥)))))
≡⟨ cong toℕ (sym (swap+cauchy≥ m n i (≤-pred (≰⇒> i≥)))) ⟩
toℕ (lookup i (swap+cauchy m n))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (swap+cauchy m n))
≡⟨ cong toℕ (swap+cauchy≥ m n j (≤-pred (≰⇒> j≥))) ⟩
toℕ (subst Fin (+-comm n m)
(inject+ m (reduce≥ j (≤-pred (≰⇒> j≥)))))
≡⟨ inject≥ m n j (≤-pred (≰⇒> j≥)) ⟩
toℕ j ∸ m ∎)
where open ≡-Reasoning
swap+perm : (m n : ℕ) → Permutation (m + n)
swap+perm m n = (swap+cauchy m n , λ {i} {j} p → swap+perm' m n i j p)
-- Parallel additive composition
-- append both permutations but adjust the indices in the second
-- permutation by the size of the first type so that it acts on the
-- second part of the vector
pcompperm' : (m n : ℕ) (i j : Fin (m + n))
(α : Cauchy m) (β : Cauchy n)
(p : lookup i (pcompcauchy α β) ≡ lookup j (pcompcauchy α β))
(f : {i j : Fin m} → lookup i α ≡ lookup j α → i ≡ j)
(g : {i j : Fin n} → lookup i β ≡ lookup j β → i ≡ j) → i ≡ j
pcompperm' m n i j α β p f g with toℕ i <? m | toℕ j <? m
... | yes i< | yes j< = fromℕ≤-inj m (m + n) i j i< j< (f (toℕ-injective li≡lj))
where li≡lj = begin (toℕ (lookup (fromℕ≤ i<) α)
≡⟨ inject+-lemma n (lookup (fromℕ≤ i<) α) ⟩
toℕ (inject+ n (lookup (fromℕ≤ i<) α))
≡⟨ cong toℕ (sym (lookup-map (fromℕ≤ i<) (inject+ n) α)) ⟩
toℕ (lookup (fromℕ≤ i<) (mapV (inject+ n) α))
≡⟨ cong toℕ (sym (lookup-++-<
(mapV (inject+ n) α)
(mapV (raise m) β)
i i<)) ⟩
toℕ (lookup i (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ (lookup-++-<
(mapV (inject+ n) α)
(mapV (raise m) β)
j j<) ⟩
toℕ (lookup (fromℕ≤ j<) (mapV (inject+ n) α))
≡⟨ cong toℕ (lookup-map (fromℕ≤ j<) (inject+ n) α) ⟩
toℕ (inject+ n (lookup (fromℕ≤ j<) α))
≡⟨ sym (inject+-lemma n (lookup (fromℕ≤ j<) α)) ⟩
toℕ (lookup (fromℕ≤ j<) α) ∎)
where open ≡-Reasoning
... | yes i< | no j≥ = ⊥-elim (1+n≰n contra')
where contra = begin (toℕ (lookup (fromℕ≤ i<) α)
≡⟨ inject+-lemma n (lookup (fromℕ≤ i<) α) ⟩
toℕ (inject+ n (lookup (fromℕ≤ i<) α))
≡⟨ cong toℕ (sym (lookup-map (fromℕ≤ i<) (inject+ n) α)) ⟩
toℕ (lookup (fromℕ≤ i<) (mapV (inject+ n) α))
≡⟨ cong toℕ (sym (lookup-++-<
(mapV (inject+ n) α)
(mapV (raise m) β)
i i<)) ⟩
toℕ (lookup i (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ (lookup-++-≥
(mapV (inject+ n) α)
(mapV (raise m) β)
j (≤-pred (≰⇒> j≥))) ⟩
toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) (mapV (raise m) β))
≡⟨ cong toℕ
(lookup-map (reduce≥ j (≤-pred (≰⇒> j≥))) (raise m) β) ⟩
toℕ (raise m (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β))
≡⟨ toℕ-raise m (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β) ⟩
m + toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β) ∎)
where open ≡-Reasoning
contra' = begin (suc (toℕ (lookup (fromℕ≤ i<) α))
≤⟨ lookup-bounded m m (fromℕ≤ i<) α ⟩
m
≤⟨ m≤m+n m (toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β)) ⟩
m + toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β)
≡⟨ sym contra ⟩
toℕ (lookup (fromℕ≤ i<) α) ∎)
where open ≤-Reasoning
... | no i≥ | yes j< = ⊥-elim (1+n≰n contra')
where contra = begin (m + toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)
≡⟨ sym (toℕ-raise m (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)) ⟩
toℕ (raise m (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β))
≡⟨ cong toℕ
(sym (lookup-map (reduce≥ i (≤-pred (≰⇒> i≥))) (raise m) β)) ⟩
toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) (mapV (raise m) β))
≡⟨ cong toℕ (sym (lookup-++-≥
(mapV (inject+ n) α)
(mapV (raise m) β)
i (≤-pred (≰⇒> i≥)))) ⟩
toℕ (lookup i (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ (lookup-++-<
(mapV (inject+ n) α)
(mapV (raise m) β)
j j<) ⟩
toℕ (lookup (fromℕ≤ j<) (mapV (inject+ n) α))
≡⟨ cong toℕ (lookup-map (fromℕ≤ j<) (inject+ n) α) ⟩
toℕ (inject+ n (lookup (fromℕ≤ j<) α))
≡⟨ sym (inject+-lemma n (lookup (fromℕ≤ j<) α)) ⟩
toℕ (lookup (fromℕ≤ j<) α) ∎)
where open ≡-Reasoning
contra' = begin (suc (toℕ (lookup (fromℕ≤ j<) α))
≤⟨ lookup-bounded m m (fromℕ≤ j<) α ⟩
m
≤⟨ m≤m+n m (toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)) ⟩
m + toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)
≡⟨ contra ⟩
toℕ (lookup (fromℕ≤ j<) α) ∎)
where open ≤-Reasoning
... | no i≥ | no j≥ =
reduce≥-inj m n i j (≤-pred (≰⇒> i≥)) (≤-pred (≰⇒> j≥))
(g (toℕ-injective (cancel-+-left m li≡lj)))
where li≡lj = begin (m + toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)
≡⟨ sym (toℕ-raise m (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β)) ⟩
toℕ (raise m (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) β))
≡⟨ cong toℕ
(sym (lookup-map (reduce≥ i (≤-pred (≰⇒> i≥))) (raise m) β)) ⟩
toℕ (lookup (reduce≥ i (≤-pred (≰⇒> i≥))) (mapV (raise m) β))
≡⟨ cong toℕ (sym (lookup-++-≥
(mapV (inject+ n) α)
(mapV (raise m) β)
i (≤-pred (≰⇒> i≥)))) ⟩
toℕ (lookup i (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (mapV (inject+ n) α ++V mapV (raise m) β))
≡⟨ cong toℕ (lookup-++-≥
(mapV (inject+ n) α)
(mapV (raise m) β)
j (≤-pred (≰⇒> j≥))) ⟩
toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) (mapV (raise m) β))
≡⟨ cong toℕ
(lookup-map (reduce≥ j (≤-pred (≰⇒> j≥))) (raise m) β) ⟩
toℕ (raise m (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β))
≡⟨ toℕ-raise m (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β) ⟩
m + toℕ (lookup (reduce≥ j (≤-pred (≰⇒> j≥))) β) ∎)
where open ≡-Reasoning
pcompperm : ∀ {m n} → Permutation m → Permutation n → Permutation (m + n)
pcompperm {m} {n} (α , f) (β , g) =
(pcompcauchy α β , λ {i} {j} p → pcompperm' m n i j α β p f g)
-- Tensor multiplicative composition
-- Transpositions in α correspond to swapping entire rows
-- Transpositions in β correspond to swapping entire columns
tcompperm' : (m n : ℕ) (i j : Fin (m * n)) (α : Cauchy m) (β : Cauchy n)
(f : {i j : Fin m} → lookup i α ≡ lookup j α → i ≡ j)
(g : {i j : Fin n} → lookup i β ≡ lookup j β → i ≡ j)
(p : lookup i (tcompcauchy α β) ≡ lookup j (tcompcauchy α β)) → (i ≡ j)
tcompperm' m n i j α β f g p =
let fin-result bi di deci deci' = fin-divMod m n i
fin-result bj dj decj decj' = fin-divMod m n j
(lookb≡ , lookd≡) = fin-addMul-lemma
m n (lookup bi α) (lookup bj α)
(lookup di β) (lookup dj β) sp
(b≡ , d≡) = (f {bi} {bj} lookb≡ , g {di} {dj} lookd≡)
bn+d≡ = cong₂ (λ b d → toℕ d + toℕ b * n) b≡ d≡
in toℕ-injective (trans deci (trans bn+d≡ (sym decj)))
where sp = let fin-result bi di deci deci' = fin-divMod m n i
fin-result bj dj decj decj' = fin-divMod m n j in
begin (let b' = lookup bi α
d' = lookup di β
in toℕ b' * n + toℕ d'
≡⟨ sym (to-from _) ⟩
toℕ
(let b' = lookup bi α
d' = lookup di β
in fromℕ (toℕ b' * n + toℕ d'))
≡⟨ sym (inject≤-lemma _ _) ⟩
toℕ
(let b' = lookup bi α
d' = lookup di β
in inject≤
(fromℕ (toℕ b' * n + toℕ d'))
(i*n+k≤m*n b' d'))
≡⟨ cong toℕ
(sym (lookup-2d m n i α β
(λ {(b , d) → inject≤
(fromℕ (toℕ b * n + toℕ d))
(i*n+k≤m*n b d)}))) ⟩
toℕ (lookup i (tcompcauchy α β))
≡⟨ cong toℕ p ⟩
toℕ (lookup j (tcompcauchy α β))
≡⟨ cong toℕ
(lookup-2d m n j α β
(λ {(b , d) → inject≤
(fromℕ (toℕ b * n + toℕ d))
(i*n+k≤m*n b d)})) ⟩
toℕ
(let b' = lookup bj α
d' = lookup dj β
in inject≤
(fromℕ (toℕ b' * n + toℕ d'))
(i*n+k≤m*n b' d'))
≡⟨ inject≤-lemma _ _ ⟩
toℕ
(let b' = lookup bj α
d' = lookup dj β
in fromℕ (toℕ b' * n + toℕ d'))
≡⟨ to-from _ ⟩
let b' = lookup bj α
d' = lookup dj β
in toℕ b' * n + toℕ d' ∎)
where open ≡-Reasoning
tcompperm : ∀ {m n} → Permutation m → Permutation n → Permutation (m * n)
tcompperm {m} {n} (α , f) (β , g) =
(tcompcauchy α β , λ {i} {j} p → tcompperm' m n i j α β f g p)
-- swap⋆
--
-- This is essentially the classical problem of in-place matrix transpose:
-- "http://en.wikipedia.org/wiki/In-place_matrix_transposition"
-- Given m and n, the desired permutation in Cauchy representation is:
-- P(i) = m*n-1 if i=m*n-1
-- = m*i mod m*n-1 otherwise
transpose≡ : (m n : ℕ) (i j : Fin (m * n)) (bi bj : Fin m) (di dj : Fin n)
(deci : toℕ i ≡ toℕ di + toℕ bi * n)
(decj : toℕ j ≡ toℕ dj + toℕ bj * n)
(tpr : transposeIndex m n bi di ≡ transposeIndex m n bj dj) → (i ≡ j)
transpose≡ m n i j bi bj di dj deci decj tpr =
let (d≡ , b≡) = fin-addMul-lemma n m di dj bi bj stpr
d+bn≡ = cong₂ (λ x y → toℕ x + toℕ y * n) d≡ b≡
in toℕ-injective (trans deci (trans d+bn≡ (sym decj)))
where stpr = begin (toℕ di * m + toℕ bi
≡⟨ sym (to-from _) ⟩
toℕ (fromℕ (toℕ di * m + toℕ bi))
≡⟨ sym (inject≤-lemma _ _) ⟩
toℕ (inject≤
(fromℕ (toℕ di * m + toℕ bi))
(trans≤
(i*n+k≤m*n di bi)
(refl′ (*-comm n m))))
≡⟨ cong toℕ tpr ⟩
toℕ (inject≤
(fromℕ (toℕ dj * m + toℕ bj))
(trans≤
(i*n+k≤m*n dj bj)
(refl′ (*-comm n m))))
≡⟨ inject≤-lemma _ _ ⟩
toℕ (fromℕ (toℕ dj * m + toℕ bj))
≡⟨ to-from _ ⟩
toℕ dj * m + toℕ bj ∎)
where open ≡-Reasoning
swap⋆perm' : (m n : ℕ) (i j : Fin (m * n))
(p : lookup i (swap⋆cauchy m n) ≡ lookup j (swap⋆cauchy m n)) → (i ≡ j)
swap⋆perm' m n i j p =
let fin-result bi di deci _ = fin-divMod m n i
fin-result bj dj decj _ = fin-divMod m n j
in transpose≡ m n i j bi bj di dj deci decj pr
where pr = let fin-result bi di _ _ = fin-divMod m n i
fin-result bj dj _ _ = fin-divMod m n j in
begin (transposeIndex m n bi di
≡⟨ cong₂ (transposeIndex m n)
(sym (lookup-allFin bi)) (sym (lookup-allFin di)) ⟩
transposeIndex m n (lookup bi (allFin m)) (lookup di (allFin n))
≡⟨ sym (lookup-2d m n i (allFin m) (allFin n)
(λ {(b , d) → transposeIndex m n b d})) ⟩
lookup i
(concatV (mapV
(λ b → mapV (λ d → transposeIndex m n b d) (allFin n))
(allFin m)))
≡⟨ p ⟩
lookup j
(concatV (mapV
(λ b → mapV (λ d → transposeIndex m n b d) (allFin n))
(allFin m)))
≡⟨ lookup-2d m n j (allFin m) (allFin n)
(λ {(b , d) → transposeIndex m n b d}) ⟩
transposeIndex m n (lookup bj (allFin m)) (lookup dj (allFin n))
≡⟨ cong₂ (transposeIndex m n)
(lookup-allFin bj) (lookup-allFin dj) ⟩
transposeIndex m n bj dj ∎)
where open ≡-Reasoning
swap⋆perm : (m n : ℕ) → Permutation (m * n)
swap⋆perm m n = (swap⋆cauchy m n , λ {i} {j} p → swap⋆perm' m n i j p)
------------------------------------------------------------------------------
|
{
"alphanum_fraction": 0.4154708635,
"avg_line_length": 46.2928571429,
"ext": "agda",
"hexsha": "d3ac86f7b652b313e47816060873f66225a638d1",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2019-09-10T09:47:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-29T01:56:33.000Z",
"max_forks_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "JacquesCarette/pi-dual",
"max_forks_repo_path": "Univalence/Obsolete/Perm.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_issues_repo_issues_event_max_datetime": "2021-10-29T20:41:23.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-07T16:27:41.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "JacquesCarette/pi-dual",
"max_issues_repo_path": "Univalence/Obsolete/Perm.agda",
"max_line_length": 98,
"max_stars_count": 14,
"max_stars_repo_head_hexsha": "003835484facfde0b770bc2b3d781b42b76184c1",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "JacquesCarette/pi-dual",
"max_stars_repo_path": "Univalence/Obsolete/Perm.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-05T01:07:57.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-08-18T21:40:15.000Z",
"num_tokens": 14815,
"size": 38886
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Pointwise lifting of relations to lists
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Binary.Pointwise where
open import Function.Base
open import Function.Inverse using (Inverse)
open import Data.Bool.Base using (true; false)
open import Data.Product hiding (map)
open import Data.List.Base as List hiding (map; head; tail; uncons)
open import Data.List.Properties using (≡-dec; length-++)
open import Data.List.Relation.Unary.All as All using (All; []; _∷_)
open import Data.List.Relation.Unary.AllPairs using (AllPairs; []; _∷_)
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Data.Fin.Base using (Fin) renaming (zero to fzero; suc to fsuc)
open import Data.Nat.Base using (ℕ; zero; suc)
open import Data.Nat.Properties
open import Level
open import Relation.Nullary hiding (Irrelevant)
open import Relation.Nullary.Negation using (contradiction)
import Relation.Nullary.Decidable as Dec using (map′)
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Unary as U using (Pred)
open import Relation.Binary renaming (Rel to Rel₂)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
private
variable
a b c d p q r ℓ ℓ₁ ℓ₂ ℓ₃ : Level
A : Set a
B : Set b
C : Set c
D : Set d
------------------------------------------------------------------------
-- Definition
infixr 5 _∷_
data Pointwise {A : Set a} {B : Set b} (_∼_ : REL A B ℓ)
: List A → List B → Set (a ⊔ b ⊔ ℓ) where
[] : Pointwise _∼_ [] []
_∷_ : ∀ {x xs y ys} (x∼y : x ∼ y) (xs∼ys : Pointwise _∼_ xs ys) →
Pointwise _∼_ (x ∷ xs) (y ∷ ys)
------------------------------------------------------------------------
-- Operations
module _ {_∼_ : REL A B ℓ} where
head : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) → x ∼ y
head (x∼y ∷ xs∼ys) = x∼y
tail : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) →
Pointwise _∼_ xs ys
tail (x∼y ∷ xs∼ys) = xs∼ys
uncons : ∀ {x y xs ys} → Pointwise _∼_ (x ∷ xs) (y ∷ ys) →
x ∼ y × Pointwise _∼_ xs ys
uncons = < head , tail >
rec : ∀ (P : ∀ {xs ys} → Pointwise _∼_ xs ys → Set c) →
(∀ {x y xs ys} {xs∼ys : Pointwise _∼_ xs ys} →
(x∼y : x ∼ y) → P xs∼ys → P (x∼y ∷ xs∼ys)) →
P [] →
∀ {xs ys} (xs∼ys : Pointwise _∼_ xs ys) → P xs∼ys
rec P c n [] = n
rec P c n (x∼y ∷ xs∼ys) = c x∼y (rec P c n xs∼ys)
map : ∀ {_≈_ : REL A B ℓ₂} → _≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_
map ≈⇒∼ [] = []
map ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ map ≈⇒∼ xs≈ys
------------------------------------------------------------------------
-- Relational properties
reflexive : ∀ {_≈_ : REL A B ℓ₁} {_∼_ : REL A B ℓ₂} →
_≈_ ⇒ _∼_ → Pointwise _≈_ ⇒ Pointwise _∼_
reflexive ≈⇒∼ [] = []
reflexive ≈⇒∼ (x≈y ∷ xs≈ys) = ≈⇒∼ x≈y ∷ reflexive ≈⇒∼ xs≈ys
refl : ∀ {_∼_ : Rel₂ A ℓ} → Reflexive _∼_ → Reflexive (Pointwise _∼_)
refl rfl {[]} = []
refl rfl {x ∷ xs} = rfl ∷ refl rfl
symmetric : ∀ {_≈_ : REL A B ℓ₁} {_∼_ : REL B A ℓ₂} →
Sym _≈_ _∼_ → Sym (Pointwise _≈_) (Pointwise _∼_)
symmetric sym [] = []
symmetric sym (x∼y ∷ xs∼ys) = sym x∼y ∷ symmetric sym xs∼ys
transitive : ∀ {_≋_ : REL A B ℓ₁} {_≈_ : REL B C ℓ₂} {_∼_ : REL A C ℓ₃} →
Trans _≋_ _≈_ _∼_ →
Trans (Pointwise _≋_) (Pointwise _≈_) (Pointwise _∼_)
transitive trans [] [] = []
transitive trans (x∼y ∷ xs∼ys) (y∼z ∷ ys∼zs) =
trans x∼y y∼z ∷ transitive trans xs∼ys ys∼zs
antisymmetric : ∀ {_≤_ : REL A B ℓ₁} {_≤′_ : REL B A ℓ₂} {_≈_ : REL A B ℓ₃} →
Antisym _≤_ _≤′_ _≈_ →
Antisym (Pointwise _≤_) (Pointwise _≤′_) (Pointwise _≈_)
antisymmetric antisym [] [] = []
antisymmetric antisym (x∼y ∷ xs∼ys) (y∼x ∷ ys∼xs) =
antisym x∼y y∼x ∷ antisymmetric antisym xs∼ys ys∼xs
respects₂ : ∀ {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} →
_∼_ Respects₂ _≈_ → (Pointwise _∼_) Respects₂ (Pointwise _≈_)
respects₂ {_≈_ = _≈_} {_∼_} resp = respʳ , respˡ
where
respʳ : (Pointwise _∼_) Respectsʳ (Pointwise _≈_)
respʳ [] [] = []
respʳ (x≈y ∷ xs≈ys) (z∼x ∷ zs∼xs) =
proj₁ resp x≈y z∼x ∷ respʳ xs≈ys zs∼xs
respˡ : (Pointwise _∼_) Respectsˡ (Pointwise _≈_)
respˡ [] [] = []
respˡ (x≈y ∷ xs≈ys) (x∼z ∷ xs∼zs) =
proj₂ resp x≈y x∼z ∷ respˡ xs≈ys xs∼zs
module _ {_∼_ : REL A B ℓ} (dec : Decidable _∼_) where
decidable : Decidable (Pointwise _∼_)
decidable [] [] = yes []
decidable [] (y ∷ ys) = no (λ ())
decidable (x ∷ xs) [] = no (λ ())
decidable (x ∷ xs) (y ∷ ys) =
Dec.map′ (uncurry _∷_) uncons (dec x y ×-dec decidable xs ys)
module _ {_≈_ : Rel₂ A ℓ} where
isEquivalence : IsEquivalence _≈_ → IsEquivalence (Pointwise _≈_)
isEquivalence eq = record
{ refl = refl Eq.refl
; sym = symmetric Eq.sym
; trans = transitive Eq.trans
} where module Eq = IsEquivalence eq
isDecEquivalence : IsDecEquivalence _≈_ → IsDecEquivalence (Pointwise _≈_)
isDecEquivalence eq = record
{ isEquivalence = isEquivalence DE.isEquivalence
; _≟_ = decidable DE._≟_
} where module DE = IsDecEquivalence eq
module _ {_≈_ : Rel₂ A ℓ₁} {_∼_ : Rel₂ A ℓ₂} where
isPreorder : IsPreorder _≈_ _∼_ → IsPreorder (Pointwise _≈_) (Pointwise _∼_)
isPreorder pre = record
{ isEquivalence = isEquivalence Pre.isEquivalence
; reflexive = reflexive Pre.reflexive
; trans = transitive Pre.trans
} where module Pre = IsPreorder pre
isPartialOrder : IsPartialOrder _≈_ _∼_ →
IsPartialOrder (Pointwise _≈_) (Pointwise _∼_)
isPartialOrder po = record
{ isPreorder = isPreorder PO.isPreorder
; antisym = antisymmetric PO.antisym
} where module PO = IsPartialOrder po
setoid : Setoid a ℓ → Setoid a (a ⊔ ℓ)
setoid s = record
{ isEquivalence = isEquivalence (Setoid.isEquivalence s)
}
decSetoid : DecSetoid a ℓ → DecSetoid a (a ⊔ ℓ)
decSetoid d = record
{ isDecEquivalence = isDecEquivalence (DecSetoid.isDecEquivalence d)
}
preorder : Preorder a ℓ₁ ℓ₂ → Preorder _ _ _
preorder p = record
{ isPreorder = isPreorder (Preorder.isPreorder p)
}
poset : Poset a ℓ₁ ℓ₂ → Poset _ _ _
poset p = record
{ isPartialOrder = isPartialOrder (Poset.isPartialOrder p)
}
------------------------------------------------------------------------
-- Relationships to other predicates
module _ {_∼_ : Rel₂ A ℓ} {P : Pred A p} where
All-resp-Pointwise : P Respects _∼_ → (All P) Respects (Pointwise _∼_)
All-resp-Pointwise resp [] [] = []
All-resp-Pointwise resp (x∼y ∷ xs) (px ∷ pxs) =
resp x∼y px ∷ All-resp-Pointwise resp xs pxs
Any-resp-Pointwise : P Respects _∼_ → (Any P) Respects (Pointwise _∼_)
Any-resp-Pointwise resp (x∼y ∷ xs) (here px) = here (resp x∼y px)
Any-resp-Pointwise resp (x∼y ∷ xs) (there pxs) = there (Any-resp-Pointwise resp xs pxs)
module _ {_∼_ : Rel₂ A ℓ} {R : Rel₂ A r} where
AllPairs-resp-Pointwise : R Respects₂ _∼_ → (AllPairs R) Respects (Pointwise _∼_)
AllPairs-resp-Pointwise _ [] [] = []
AllPairs-resp-Pointwise resp@(respₗ , respᵣ) (x∼y ∷ xs) (px ∷ pxs) =
All-resp-Pointwise respₗ xs (All.map (respᵣ x∼y) px) ∷ (AllPairs-resp-Pointwise resp xs pxs)
------------------------------------------------------------------------
-- length
module _ {_∼_ : REL A B ℓ} where
Pointwise-length : ∀ {xs ys} → Pointwise _∼_ xs ys →
length xs ≡ length ys
Pointwise-length [] = P.refl
Pointwise-length (x∼y ∷ xs∼ys) = P.cong ℕ.suc (Pointwise-length xs∼ys)
------------------------------------------------------------------------
-- tabulate
module _ {_∼_ : REL A B ℓ} where
tabulate⁺ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
(∀ i → f i ∼ g i) → Pointwise _∼_ (tabulate f) (tabulate g)
tabulate⁺ {zero} f∼g = []
tabulate⁺ {suc n} f∼g = f∼g fzero ∷ tabulate⁺ (f∼g ∘ fsuc)
tabulate⁻ : ∀ {n} {f : Fin n → A} {g : Fin n → B} →
Pointwise _∼_ (tabulate f) (tabulate g) → (∀ i → f i ∼ g i)
tabulate⁻ {suc n} (x∼y ∷ xs∼ys) fzero = x∼y
tabulate⁻ {suc n} (x∼y ∷ xs∼ys) (fsuc i) = tabulate⁻ xs∼ys i
------------------------------------------------------------------------
-- _++_
module _ {_∼_ : REL A B ℓ} where
++⁺ : ∀ {ws xs ys zs} → Pointwise _∼_ ws xs → Pointwise _∼_ ys zs →
Pointwise _∼_ (ws ++ ys) (xs ++ zs)
++⁺ [] ys∼zs = ys∼zs
++⁺ (w∼x ∷ ws∼xs) ys∼zs = w∼x ∷ ++⁺ ws∼xs ys∼zs
module _ {_∼_ : Rel₂ A ℓ} where
++-cancelˡ : ∀ xs {ys zs : List A} → Pointwise _∼_ (xs ++ ys) (xs ++ zs) → Pointwise _∼_ ys zs
++-cancelˡ [] ys∼zs = ys∼zs
++-cancelˡ (x ∷ xs) (_ ∷ xs++ys∼xs++zs) = ++-cancelˡ xs xs++ys∼xs++zs
++-cancelʳ : ∀ {xs : List A} ys zs → Pointwise _∼_ (ys ++ xs) (zs ++ xs) → Pointwise _∼_ ys zs
++-cancelʳ [] [] _ = []
++-cancelʳ (y ∷ ys) (z ∷ zs) (y∼z ∷ ys∼zs) = y∼z ∷ (++-cancelʳ ys zs ys∼zs)
-- Impossible cases
++-cancelʳ {xs} [] (z ∷ zs) eq =
contradiction (P.trans (Pointwise-length eq) (length-++ (z ∷ zs))) (m≢1+n+m (length xs))
++-cancelʳ {xs} (y ∷ ys) [] eq =
contradiction (P.trans (P.sym (length-++ (y ∷ ys))) (Pointwise-length eq)) (m≢1+n+m (length xs) ∘ P.sym)
------------------------------------------------------------------------
-- concat
module _ {_∼_ : REL A B ℓ} where
concat⁺ : ∀ {xss yss} → Pointwise (Pointwise _∼_) xss yss →
Pointwise _∼_ (concat xss) (concat yss)
concat⁺ [] = []
concat⁺ (xs∼ys ∷ xss∼yss) = ++⁺ xs∼ys (concat⁺ xss∼yss)
------------------------------------------------------------------------
-- reverse
module _ {R : REL A B ℓ} where
reverseAcc⁺ : ∀ {as bs as′ bs′} → Pointwise R as′ bs′ → Pointwise R as bs →
Pointwise R (reverseAcc as′ as) (reverseAcc bs′ bs)
reverseAcc⁺ rs′ [] = rs′
reverseAcc⁺ rs′ (r ∷ rs) = reverseAcc⁺ (r ∷ rs′) rs
ʳ++⁺ : ∀ {as bs as′ bs′} →
Pointwise R as bs →
Pointwise R as′ bs′ →
Pointwise R (as ʳ++ as′) (bs ʳ++ bs′)
ʳ++⁺ rs rs′ = reverseAcc⁺ rs′ rs
reverse⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (reverse as) (reverse bs)
reverse⁺ = reverseAcc⁺ []
------------------------------------------------------------------------
-- map
module _ {R : REL C D ℓ} where
map⁺ : ∀ {as bs} (f : A → C) (g : B → D) →
Pointwise (λ a b → R (f a) (g b)) as bs →
Pointwise R (List.map f as) (List.map g bs)
map⁺ f g [] = []
map⁺ f g (r ∷ rs) = r ∷ map⁺ f g rs
map⁻ : ∀ {as bs} (f : A → C) (g : B → D) →
Pointwise R (List.map f as) (List.map g bs) →
Pointwise (λ a b → R (f a) (g b)) as bs
map⁻ {as = []} {[]} f g [] = []
map⁻ {as = []} {b ∷ bs} f g rs = contradiction (Pointwise-length rs) λ()
map⁻ {as = a ∷ as} {[]} f g rs = contradiction (Pointwise-length rs) λ()
map⁻ {as = a ∷ as} {b ∷ bs} f g (r ∷ rs) = r ∷ map⁻ f g rs
------------------------------------------------------------------------
-- filter
module _ {R : REL A B ℓ} {P : Pred A p} {Q : Pred B q}
(P? : U.Decidable P) (Q? : U.Decidable Q)
(P⇒Q : ∀ {a b} → R a b → P a → Q b)
(Q⇒P : ∀ {a b} → R a b → Q b → P a)
where
filter⁺ : ∀ {as bs} → Pointwise R as bs → Pointwise R (filter P? as) (filter Q? bs)
filter⁺ [] = []
filter⁺ {a ∷ _} {b ∷ _} (r ∷ rs) with P? a | Q? b
... | true because _ | true because _ = r ∷ filter⁺ rs
... | false because _ | false because _ = filter⁺ rs
... | yes p | no ¬q = contradiction (P⇒Q r p) ¬q
... | no ¬p | yes q = contradiction (Q⇒P r q) ¬p
------------------------------------------------------------------------
-- replicate
module _ {R : REL A B ℓ} where
replicate⁺ : ∀ {a b} → R a b → ∀ n → Pointwise R (replicate n a) (replicate n b)
replicate⁺ r 0 = []
replicate⁺ r (suc n) = r ∷ replicate⁺ r n
------------------------------------------------------------------------
-- Irrelevance
module _ {R : REL A B ℓ} where
irrelevant : Irrelevant R → Irrelevant (Pointwise R)
irrelevant R-irr [] [] = P.refl
irrelevant R-irr (r ∷ rs) (r₁ ∷ rs₁) =
P.cong₂ _∷_ (R-irr r r₁) (irrelevant R-irr rs rs₁)
------------------------------------------------------------------------
-- Properties of propositional pointwise
Pointwise-≡⇒≡ : Pointwise {A = A} _≡_ ⇒ _≡_
Pointwise-≡⇒≡ [] = P.refl
Pointwise-≡⇒≡ (P.refl ∷ xs∼ys) with Pointwise-≡⇒≡ xs∼ys
... | P.refl = P.refl
≡⇒Pointwise-≡ : _≡_ ⇒ Pointwise {A = A} _≡_
≡⇒Pointwise-≡ P.refl = refl P.refl
Pointwise-≡↔≡ : Inverse (setoid (P.setoid A)) (P.setoid (List A))
Pointwise-≡↔≡ = record
{ to = record { _⟨$⟩_ = id; cong = Pointwise-≡⇒≡ }
; from = record { _⟨$⟩_ = id; cong = ≡⇒Pointwise-≡ }
; inverse-of = record
{ left-inverse-of = λ _ → refl P.refl
; right-inverse-of = λ _ → P.refl
}
}
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 0.15
Rel = Pointwise
{-# WARNING_ON_USAGE Rel
"Warning: Rel was deprecated in v0.15.
Please use Pointwise instead."
#-}
Rel≡⇒≡ = Pointwise-≡⇒≡
{-# WARNING_ON_USAGE Rel≡⇒≡
"Warning: Rel≡⇒≡ was deprecated in v0.15.
Please use Pointwise-≡⇒≡ instead."
#-}
≡⇒Rel≡ = ≡⇒Pointwise-≡
{-# WARNING_ON_USAGE ≡⇒Rel≡
"Warning: ≡⇒Rel≡ was deprecated in v0.15.
Please use ≡⇒Pointwise-≡ instead."
#-}
Rel↔≡ = Pointwise-≡↔≡
{-# WARNING_ON_USAGE Rel↔≡
"Warning: Rel↔≡ was deprecated in v0.15.
Please use Pointwise-≡↔≡ instead."
#-}
-- Version 1.0
decidable-≡ = ≡-dec
{-# WARNING_ON_USAGE decidable-≡
"Warning: decidable-≡ was deprecated in v1.0.
Please use ≡-dec from `Data.List.Properties` instead."
#-}
|
{
"alphanum_fraction": 0.5120180447,
"avg_line_length": 35.8257575758,
"ext": "agda",
"hexsha": "b3df9abd0e9740bf9ad206166b10e99214655fed",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Pointwise.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Pointwise.agda",
"max_line_length": 108,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Binary/Pointwise.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": 5292,
"size": 14187
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Functions.Definition
open import Orders.WellFounded.Definition
module Orders.WellFounded.Induction {a b : _} {A : Set a} {_<_ : Rel {a} {b} A} (wf : WellFounded _<_) where
private
foldAcc :
{c : _}
(P : A → Set c) →
(∀ x → (∀ y → y < x → P y) → P x) →
∀ z → Accessible _<_ z →
P z
foldAcc P inductionProof = go
where
go : (z : A) → (Accessible _<_ z) → P z
go z (access prf) = inductionProof z (λ y yLessZ → go y (prf y yLessZ))
rec :
{c : _}
(P : A → Set c) →
(∀ x → (∀ y → y < x → P y) → P x) → (∀ z → P z)
rec P inductionProof z = foldAcc P inductionProof _ (wf z)
|
{
"alphanum_fraction": 0.5491923642,
"avg_line_length": 27.24,
"ext": "agda",
"hexsha": "2911314cd50ac61892f1607c1c1214779d257db1",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Orders/WellFounded/Induction.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Orders/WellFounded/Induction.agda",
"max_line_length": 108,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Orders/WellFounded/Induction.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": 252,
"size": 681
}
|
module DecidableMembership where
open import OscarPrelude
open import Membership
open import Successor
record DecidableMembership {ℓ} (m : Set ℓ) (M : Set ℓ) ⦃ _ : Membership m M ⦄ : Set (⊹ ℓ)
where
field _∈?_ : (x : m) → (X : M) → Dec $ x ∈ X
field _∉?_ : (x : m) → (X : M) → Dec $ x ∉ X
open DecidableMembership ⦃ … ⦄ public
instance DecidableMembershipList : ∀ {ℓ} {A : Set ℓ} ⦃ _ : Eq A ⦄ → DecidableMembership A $ List A
DecidableMembership._∈?_ (DecidableMembershipList {ℓ} {A}) = _∈List?_
where
_∈List?_ : (a : A) → (xs : List A) → Dec (a ∈ xs)
a ∈List? [] = no λ ()
a ∈List? (x ∷ xs) with a ≟ x
… | yes a≡x rewrite a≡x = yes zero
… | no a≢x with a ∈List? xs
… | yes a∈xs = yes (⊹ a∈xs)
… | no a∉xs = no (λ {zero → a≢x refl ; (suc a∈xs) → a∉xs a∈xs})
DecidableMembership._∉?_ (DecidableMembershipList {ℓ} {A}) x X with x ∈? X
DecidableMembership._∉?_ (DecidableMembershipList {ℓ} {A}) x X | yes x∈X = no (λ x∉X → x∉X x∈X)
DecidableMembership._∉?_ (DecidableMembershipList {ℓ} {A}) x X | no x∉X = yes x∉X
|
{
"alphanum_fraction": 0.6052123552,
"avg_line_length": 37,
"ext": "agda",
"hexsha": "e0fa54ead15d3b772ed888369d864c17da5f98c7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_forks_repo_licenses": [
"RSA-MD"
],
"max_forks_repo_name": "m0davis/oscar",
"max_forks_repo_path": "archive/agda-1/DecidableMembership.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_issues_repo_issues_event_max_datetime": "2019-05-11T23:33:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-04-29T00:35:04.000Z",
"max_issues_repo_licenses": [
"RSA-MD"
],
"max_issues_repo_name": "m0davis/oscar",
"max_issues_repo_path": "archive/agda-1/DecidableMembership.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "52e1cdbdee54d9a8eaee04ee518a0d7f61d25afb",
"max_stars_repo_licenses": [
"RSA-MD"
],
"max_stars_repo_name": "m0davis/oscar",
"max_stars_repo_path": "archive/agda-1/DecidableMembership.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 451,
"size": 1036
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The Delay type and some operations
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Delay where
open import Size
open import Codata.Thunk using (Thunk; force)
open import Codata.Conat using (Conat; zero; suc; Finite)
open import Data.Empty
open import Relation.Nullary
open import Data.Nat.Base
open import Data.Maybe.Base hiding (map ; fromMaybe ; zipWith ; alignWith ; zip ; align)
open import Data.Product as P hiding (map ; zip)
open import Data.Sum as S hiding (map)
open import Data.These as T using (These; this; that; these)
open import Function
------------------------------------------------------------------------
-- Definition
data Delay {ℓ} (A : Set ℓ) (i : Size) : Set ℓ where
now : A → Delay A i
later : Thunk (Delay A) i → Delay A i
module _ {ℓ} {A : Set ℓ} where
length : ∀ {i} → Delay A i → Conat i
length (now _) = zero
length (later d) = suc λ where .force → length (d .force)
never : ∀ {i} → Delay A i
never = later λ where .force → never
fromMaybe : Maybe A → Delay A ∞
fromMaybe = maybe now never
runFor : ℕ → Delay A ∞ → Maybe A
runFor zero d = nothing
runFor (suc n) (now a) = just a
runFor (suc n) (later d) = runFor n (d .force)
module _ {ℓ ℓ′} {A : Set ℓ} {B : Set ℓ′} where
map : (A → B) → ∀ {i} → Delay A i → Delay B i
map f (now a) = now (f a)
map f (later d) = later λ where .force → map f (d .force)
bind : ∀ {i} → Delay A i → (A → Delay B i) → Delay B i
bind (now a) f = f a
bind (later d) f = later λ where .force → bind (d .force) f
unfold : (A → A ⊎ B) → A → ∀ {i} → Delay B i
unfold next seed with next seed
... | inj₁ seed′ = later λ where .force → unfold next seed′
... | inj₂ b = now b
module _ {a b c} {A : Set a} {B : Set b} {C : Set c} where
zipWith : (A → B → C) → ∀ {i} → Delay A i → Delay B i → Delay C i
zipWith f (now a) d = map (f a) d
zipWith f d (now b) = map (λ a → f a b) d
zipWith f (later a) (later b) = later λ where .force → zipWith f (a .force) (b .force)
alignWith : (These A B → C) → ∀ {i} → Delay A i → Delay B i → Delay C i
alignWith f (now a) (now b) = now (f (these a b))
alignWith f (now a) (later _) = now (f (this a))
alignWith f (later _) (now b) = now (f (that b))
alignWith f (later a) (later b) = later λ where
.force → alignWith f (a .force) (b .force)
module _ {a b} {A : Set a} {B : Set b} where
zip : ∀ {i} → Delay A i → Delay B i → Delay (A × B) i
zip = zipWith _,_
align : ∀ {i} → Delay A i → Delay B i → Delay (These A B) i
align = alignWith id
------------------------------------------------------------------------
-- Finite Delays
module _ {ℓ} {A : Set ℓ} where
infix 3 _⇓
data _⇓ : Delay A ∞ → Set ℓ where
now : ∀ a → now a ⇓
later : ∀ {d} → d .force ⇓ → later d ⇓
extract : ∀ {d} → d ⇓ → A
extract (now a) = a
extract (later d) = extract d
¬never⇓ : ¬ (never ⇓)
¬never⇓ (later p) = ¬never⇓ p
length-⇓ : ∀ {d} → d ⇓ → Finite (length d)
length-⇓ (now a) = zero
length-⇓ (later d⇓) = suc (length-⇓ d⇓)
module _ {ℓ ℓ′} {A : Set ℓ} {B : Set ℓ′} where
map-⇓ : ∀ (f : A → B) {d} → d ⇓ → map f d ⇓
map-⇓ f (now a) = now (f a)
map-⇓ f (later d) = later (map-⇓ f d)
bind-⇓ : ∀ {m} (m⇓ : m ⇓) {f : A → Delay B ∞} → f (extract m⇓) ⇓ → bind m f ⇓
bind-⇓ (now a) fa⇓ = fa⇓
bind-⇓ (later p) fa⇓ = later (bind-⇓ p fa⇓)
|
{
"alphanum_fraction": 0.5205749718,
"avg_line_length": 30.852173913,
"ext": "agda",
"hexsha": "f92a9cfe1ce84deb6102c2a67ef1a6dae0bf5477",
"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/Codata/Delay.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/Codata/Delay.agda",
"max_line_length": 88,
"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/Codata/Delay.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1265,
"size": 3548
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.