Search is not available for this dataset
text
string | meta
dict |
---|---|
open import Agda.Builtin.Nat using (Nat; suc; zero; _+_)
module test where
data _even : Nat → Set where
ZERO : zero even
STEP : ∀ x → x even → suc (suc x) even
proof₁ : suc (suc (suc (suc zero))) even
proof₁ = ?
| {
"alphanum_fraction": 0.6380090498,
"avg_line_length": 17,
"ext": "agda",
"hexsha": "010d1280b8b88c0b8fe2648c55cab5f1975221d0",
"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": "0e729eab77eb075e175f98e521c18878be87e6a2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ixaxaar/refl",
"max_forks_repo_path": "test/test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0e729eab77eb075e175f98e521c18878be87e6a2",
"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": "ixaxaar/refl",
"max_issues_repo_path": "test/test.agda",
"max_line_length": 56,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0e729eab77eb075e175f98e521c18878be87e6a2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ixaxaar/refl",
"max_stars_repo_path": "test/test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 77,
"size": 221
} |
module Data.Char.Classifier where
open import Data.Char.Classifier.Primitive public
| {
"alphanum_fraction": 0.8470588235,
"avg_line_length": 21.25,
"ext": "agda",
"hexsha": "eab6f10b262f4e6c10d86238e584b45dbde468a9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:40:23.000Z",
"max_forks_repo_forks_event_min_datetime": "2017-08-10T06:12:54.000Z",
"max_forks_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ilya-fiveisky/agda-system-io",
"max_forks_repo_path": "src/Data/Char/Classifier.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"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": "ilya-fiveisky/agda-system-io",
"max_issues_repo_path": "src/Data/Char/Classifier.agda",
"max_line_length": 49,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "d06c219c7b7afc85aae3b1d4d66951b889aa7371",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ilya-fiveisky/agda-system-io",
"max_stars_repo_path": "src/Data/Char/Classifier.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-15T04:35:41.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T13:45:16.000Z",
"num_tokens": 17,
"size": 85
} |
module Data.Option.Equiv.Id where
import Lvl
open import Data.Option
open import Data.Option.Functions
open import Data.Option.Equiv
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
open import Structure.Function
open import Structure.Function.Domain
open import Type
private variable ℓ : Lvl.Level
private variable T A B : Type{ℓ}
private variable f : A → B
private variable o : Option T
instance
Some-injectivity : Injective {B = Option(T)} (Some)
Injective.proof Some-injectivity [≡]-intro = [≡]-intro
instance
Id-Option-extensionality : Extensionality{A = T} ([≡]-equiv)
Extensionality.cases-inequality Id-Option-extensionality ()
map-injectivity : ⦃ inj-f : Injective(f) ⦄ → Injective(map f)
Injective.proof map-injectivity {None} {None} [≡]-intro = [≡]-intro
Injective.proof (map-injectivity {f = f}) {Some x} {Some y} p = congruence₁(Some) (injective f(injective(Some) p))
-- TODO: Generalize and move
map-None : (map f o ≡ None) → (o ≡ None)
map-None {o = None} p = [≡]-intro
| {
"alphanum_fraction": 0.711409396,
"avg_line_length": 31.6060606061,
"ext": "agda",
"hexsha": "5dca841df02d0a87fd2a9e90cce886ef41a7b00a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Data/Option/Equiv/Id.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Data/Option/Equiv/Id.agda",
"max_line_length": 122,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Data/Option/Equiv/Id.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": 311,
"size": 1043
} |
{-# OPTIONS --allow-unsolved-metas #-}
open import Common.Size
-- An abuse of sized types, but as you wish...
data D (i : Size) : Set where
c : (j : Size< i) (k : Size< j) (l : Size< k) (m : Size< l) → D m → D i
c' : (j : Size< i) → D j → D i
works : ∀ i → D i → Set
works i (c j k l m d) = works j (c' k (c' l (c' m d)))
works i (c' j d) = works j d
test : ∀ i → D i → Set
test i (c j k l m d) = test ? (c' ? (c' ? (c' ? ?)))
test i (c' j d) = ?
-- Should not give a termination error as there is an instantiation
-- of meta variables that gives a terminating function.
| {
"alphanum_fraction": 0.5451448041,
"avg_line_length": 27.9523809524,
"ext": "agda",
"hexsha": "ce340f89790dccf13ac470c99a7de76e4a6d9c47",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-09-15T14:36:15.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Succeed/Issue1317a.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-04-01T19:39:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-11-14T15:31:44.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1317a.agda",
"max_line_length": 74,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1317a.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": 216,
"size": 587
} |
-- Andreas, 2011-04-07
module IrrelevantTelescope where
data Wrap .(A : Set) : Set where
wrap : A -> Wrap A
-- cannot use A, because it is declared irrelevant
| {
"alphanum_fraction": 0.6951219512,
"avg_line_length": 20.5,
"ext": "agda",
"hexsha": "25a92dcab18c9bf253207b63139437886033a410",
"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/IrrelevantTelescope.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/IrrelevantTelescope.agda",
"max_line_length": 50,
"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/IrrelevantTelescope.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": 49,
"size": 164
} |
-- Andreas, 2015-10-28 Issue 1407
-- (Issue 1023 raised its ugly head again!)
{-# OPTIONS -v term.with.inline:30 #-} --KEEP! Triggered bug on agda-2.4.2.5.
-- {-# OPTIONS -v term.with.inline:70 #-}
-- {-# OPTIONS -v tc.with.display:30 #-}
record _×_ (A B : Set) : Set where
constructor pair
field fst : A
snd : B
open _×_
data Unit : Set where
unit : Unit
data List (A : Set) : Set where
_∷_ : A → List A → List A
map : ∀ A B → (A → B) → List A → List B
map A B f (x ∷ xs) = f x ∷ map A B f xs
record Setoid : Set₁ where
field Carrier : Set
open Setoid
module Assoc (Key : Setoid) (_ : Set) where -- FAILS
-- module Assoc (_ : Set) (Key : Setoid) where -- WORKS
data _∈_ (x : Carrier Key) : List (Carrier Key) → Set where
here : ∀ xs → Unit → x ∈ xs
there : ∀ {xs} → x ∈ xs
postulate
foo : Carrier Key → Carrier Key → Unit
lem : (p : Carrier Key × Unit)
→ (ps : List (Carrier Key × Unit))
→ fst p ∈ map (Carrier Key × Unit) (Carrier Key) fst ps
→ Set
lem (pair k v) ((pair k' v') ∷ ps) (here .(k' ∷ map (Carrier Key × Unit) (Carrier Key) fst ps) u) with foo k k'
... | unit = Unit
lem p (_ ∷ ps) there = lem p ps there -- to force termination checking
-- 7 6 5 4 3 2 1 7 0
-- lem Key _ (pair k v) (pair k' v') ∷ ps) (here .(...Key...) u)
-- 8 7 6 5 4 3 2 1 0
-- lem-with Key _ k k' (w = unit) v v' ps u = Unit
{-
inlinedClauses (raw)
QNamed {qname = Issue1407.Assoc.lem, qnamed = Clause
{ clauseRange = /home/abel/agda/test/bugs/Issue1407.agda:40,3-13
, clauseTel =
ExtendTel (Def Issue1407.Setoid []) (Abs "Key"
ExtendTel (Sort (Type (Max []))) (Abs "_"
ExtendTel (Var 1 [Proj Issue1407.Setoid.Carrier]}) (Abs "k"
ExtendTel (Var 2 [Proj Issue1407.Setoid.Carrier]}) (Abs "k'"
ExtendTel (Def Issue1407.Unit []}) (Abs "v"
ExtendTel (Def Issue1407.Unit []}) (Abs "v'"
ExtendTel (Def Issue1407.List [Apply []r(Def Issue1407._×_ [Apply []r(Var 5 [Proj Issue1407.Setoid.Carrier]),Apply []r(Def Issue1407.Unit [])])]}) (Abs "ps"
ExtendTel (Def Issue1407.Unit []}) (Abs "u"
EmptyTel))))))))
, clausePerm = x0,x1,x2,x3,x4,x5,x6,x7,x8 -> x0,x1,x2,x4,x3,x5,x6,x8
, namedClausePats =
[[]r(VarP "Key")
,[]r(VarP "x")
,[]r(ConP Issue1407._×_._,_(inductive)[Issue1407._×_.fst,Issue1407._×_.snd] (ConPatternInfo {conPRecord = Nothing, conPType = Nothing}) [[]r(VarP "k"),[]r(VarP "v")])
,[]r(ConP Issue1407.List._∷_(inductive)[] (ConPatternInfo {conPRecord = Nothing, conPType = Nothing}) [[]r(ConP Issue1407._×_._,_(inductive)[Issue1407._×_.fst,Issue1407._×_.snd] (ConPatternInfo {conPRecord = Nothing, conPType = Nothing}) [[]r(VarP "k'"),[]r(VarP "v'")]),[]r(VarP "ps")])
,[]r(ConP Issue1407.Assoc._∈_.here(inductive)[] (ConPatternInfo {conPRecord = Nothing, conPType = Nothing})
[[]r{DotP (Con Issue1407.List._∷_(inductive)[]
[[]r(Var 4 [])
,[]r(Def Issue1407.map
[Apply []r{Def Issue1407._×_ [Apply []r(Def Issue1407.Assoc._.Carrier [Apply []r(Con Issue1407.Unit.unit(inductive)[] []),Apply []r(Var 3 [])])
,Apply []r(Def Issue1407.Unit [])]}
,Apply []r{Def Issue1407.Assoc._.Carrier [Apply []r(Con Issue1407.Unit.unit(inductive)[] [])
,Apply []r(Var 3 [])]}
,Apply []r(Lam (ArgInfo {argInfoHiding = NotHidden, argInfoRelevance = Relevant, argInfoColors = []}) (Abs "r" Var 0 [Proj Issue1407._×_.fst]))
,Apply []r(Var 1 [])
])
])}
,[]r(VarP "u")
])
,[]r(ConP Issue1407.Unit.unit(inductive)[] (ConPatternInfo {conPRecord = Nothing, conPType = Nothing}) [])
]
, clauseBody = Bind (Abs "h8" Bind (Abs "h7" Bind (Abs "h6" Bind (Abs "h5" Bind (Abs "h4" Bind (Abs "h3" Bind (Abs "h2" Bind (Abs "h1" Bind (Abs "h0" Body (Def Issue1407.Unit [])))))))))), clauseType = Nothing}}
-}
| {
"alphanum_fraction": 0.5746400606,
"avg_line_length": 44.9886363636,
"ext": "agda",
"hexsha": "f654c0026511e28fa0e93ebabad317c1a03a3b4d",
"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/Issue1407.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/Issue1407.agda",
"max_line_length": 291,
"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/Issue1407.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": 1405,
"size": 3959
} |
open import Type
module Graph.Walk.Properties {ℓ₁ ℓ₂} {V : Type{ℓ₁}} where
open import Lang.Instance
open import Logic
import Lvl
open import Graph{ℓ₁}{ℓ₂}(V)
open import Graph.Walk{ℓ₁}{ℓ₂}{V}
open import Relator.Equals.Proofs.Equiv
open import Type.Properties.MereProposition
module _ (_⟶_ : Graph) where
-- `Passes edge walk` states that the walk `walk` contains the edge `edge`.
-- In other words, there is a step in the walk which is `edge`.
-- Note: Passes is a generalized containment relation for paths instead of lists.
data Passes {v₁ v₂ : V} (edge : v₁ ⟶ v₂) : ∀{a b : V} → Walk(_⟶_) a b → Type{ℓ₁ Lvl.⊔ ℓ₂} where
current : ∀{c}{rest : Walk(_⟶_) v₂ c} → Passes edge (Walk.prepend edge rest)
skip : ∀{b c}{rest : Walk(_⟶_) b c} → Passes edge rest → ∀{a}{e : (a ⟶ b)} → Passes edge (Walk.prepend e rest)
-- `Visits v walk` states that the walk `walk` visits the vertex `v`.
-- In other words, one of the steps/edges in the walk mention the vertex v.
data Visits (v : V) : ∀{a b : V} → Walk(_⟶_) a b → Type{ℓ₁ Lvl.⊔ ℓ₂} where
current : ∀{b}{path : Walk(_⟶_) v b} → Visits v path
skip : ∀{a b c}{e : (a ⟶ b)}{rest : Walk(_⟶_) b c} → Visits v rest → Visits v (Walk.prepend e rest)
module _ {a b : V} (walk₁ : Walk(_⟶_) a b) {c d : V} (walk₂ : Walk(_⟶_) c d) where
record Subwalk : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{v₁ v₂ : V}{edge : v₁ ⟶ v₂} → Passes edge walk₁ → Passes edge walk₂
module _ {_⟶_ : Graph} {a b : V} (walk : Walk(_⟶_) a b) where
-- A walk that never visits the same edge twice.
-- Note: Equality on edges must respect uniqueness. In other words, one edge must not have multiple constructions.
record Trail : Type{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{v₁ v₂ : V}{edge : v₁ ⟶ v₂} → MereProposition(Passes(_⟶_) edge walk)
-- A walk that never visits the same vertex twice.
-- Also called "Simple path".
-- Note: Equality on edges must respect uniqueness. In other words, one edge must not have multiple constructions.
record Path : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{v : V} → MereProposition(Visits(_⟶_) v walk)
path = inst-fn Path.proof
-- A walk that visits every vertex in the graph.
record Traceable : Stmt{ℓ₁ Lvl.⊔ ℓ₂} where
constructor intro
field proof : ∀{v : V} → Visits(_⟶_) v walk
traceable = inst-fn Traceable.proof
| {
"alphanum_fraction": 0.6524793388,
"avg_line_length": 46.5384615385,
"ext": "agda",
"hexsha": "5209e0a166b0ed2d50e16b59a00f569cf1b6608b",
"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/Walk/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/Walk/Properties.agda",
"max_line_length": 117,
"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/Walk/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": 839,
"size": 2420
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Library.Arithmetic where
open import Light.Level using (Setω ; Level)
open import Light.Variable.Levels
record Arithmetic (Operand : Set ℓ) : Setω where
field _+_ _∗_ : Operand → Operand → Operand
open Arithmetic ⦃ ... ⦄ public
| {
"alphanum_fraction": 0.7242424242,
"avg_line_length": 30,
"ext": "agda",
"hexsha": "3c0ade5268955b543cb84ff4898e93d41284f3c0",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Library/Arithmetic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Library/Arithmetic.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Library/Arithmetic.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 83,
"size": 330
} |
open import Formalization.PredicateLogic.Signature
module Formalization.PredicateLogic.Classical.NaturalDeduction (𝔏 : Signature) where
open Signature(𝔏)
open import Data.ListSized
import Lvl
open import Formalization.PredicateLogic.Syntax(𝔏)
open import Formalization.PredicateLogic.Syntax.Substitution(𝔏)
open import Functional using (_∘_ ; _∘₂_ ; swap)
open import Numeral.Finite
open import Numeral.Natural
open import Relator.Equals.Proofs.Equiv
open import Sets.PredicateSet using (PredSet ; _∈_ ; _∉_ ; _∪_ ; _∪•_ ; _∖_ ; _⊆_ ; _⊇_ ; ∅ ; [≡]-to-[⊆] ; [≡]-to-[⊇]) renaming (•_ to · ; _≡_ to _≡ₛ_)
open import Type
private variable ℓ : Lvl.Level
private variable args vars : ℕ
private variable Γ : PredSet{ℓ}(Formula(vars))
data _⊢_ {ℓ} : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type{Lvl.𝐒(ℓₚ Lvl.⊔ ℓₒ Lvl.⊔ ℓ)} where
direct : (Γ ⊆ (Γ ⊢_))
[⊤]-intro : (Γ ⊢ ⊤)
[⊥]-elim : ∀{φ} → ((Γ ∪ ·(¬ φ)) ⊢ ⊥) → (Γ ⊢ φ)
[∧]-intro : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ ψ) → (Γ ⊢ (φ ∧ ψ))
[∧]-elimₗ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ φ)
[∧]-elimᵣ : ∀{φ ψ} → (Γ ⊢ (φ ∧ ψ)) → (Γ ⊢ ψ)
[∨]-introₗ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ∨ ψ))
[∨]-introᵣ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ∨ ψ))
[∨]-elim : ∀{φ ψ χ} → ((Γ ∪ · φ) ⊢ χ) → ((Γ ∪ · ψ) ⊢ χ) → (Γ ⊢ (φ ∨ ψ)) → (Γ ⊢ χ)
[⟶]-intro : ∀{φ ψ} → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟶ ψ))
[⟶]-elim : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟶ ψ)) → (Γ ⊢ ψ)
[Ɐ]-intro : ∀{φ} → (∀{t} → (Γ ⊢ (substitute0 t φ))) → (Γ ⊢ (Ɐ φ))
[Ɐ]-elim : ∀{φ} → (Γ ⊢ (Ɐ φ)) → ∀{t} → (Γ ⊢ (substitute0 t φ))
[∃]-intro : ∀{φ}{t} → (Γ ⊢ (substitute0 t φ)) → (Γ ⊢ (∃ φ))
[∃]-elim : ∀{φ ψ} → (∀{t} → (Γ ∪ ·(substitute0 t φ)) ⊢ ψ) → (Γ ⊢ (∃ φ)) → (Γ ⊢ ψ)
module _ where
open import Data.Either as Either
import Logic.Propositional as Meta
open import Relator.Equals
private variable Γ₁ Γ₂ : PredSet{ℓ}(Formula(vars))
private variable φ ψ : Formula(vars)
_⊬_ : PredSet{ℓ}(Formula(vars)) → Formula(vars) → Type
_⊬_ = Meta.¬_ ∘₂ (_⊢_)
[⟵]-intro : ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (ψ ⟵ φ))
[⟵]-intro = [⟶]-intro
[⟵]-elim : (Γ ⊢ φ) → (Γ ⊢ (ψ ⟵ φ)) → (Γ ⊢ ψ)
[⟵]-elim = [⟶]-elim
[¬]-intro : ((Γ ∪ · φ) ⊢ ⊥) → (Γ ⊢ (¬ φ))
[¬]-intro = [⟶]-intro
[⟷]-intro : ∀{φ ψ} → ((Γ ∪ · ψ) ⊢ φ) → ((Γ ∪ · φ) ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ))
[⟷]-intro l r = [∧]-intro ([⟶]-intro l) ([⟶]-intro r)
[⟷]-elimₗ : ∀{φ ψ} → (Γ ⊢ ψ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ φ)
[⟷]-elimₗ Γψ Γφψ = [⟶]-elim Γψ ([∧]-elimₗ Γφψ)
[⟷]-elimᵣ : ∀{φ ψ} → (Γ ⊢ φ) → (Γ ⊢ (φ ⟷ ψ)) → (Γ ⊢ ψ)
[⟷]-elimᵣ Γφ Γφψ = [⟶]-elim Γφ ([∧]-elimᵣ Γφψ)
weaken-union-singleton : (Γ₁ ⊆ Γ₂) → (((Γ₁ ∪ · φ) ⊢_) ⊆ ((Γ₂ ∪ · φ) ⊢_))
weaken : (Γ₁ ⊆ Γ₂) → ((Γ₁ ⊢_) ⊆ (Γ₂ ⊢_))
weaken Γ₁Γ₂ {φ} (direct p) = direct (Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.⊤} [⊤]-intro = [⊤]-intro
weaken Γ₁Γ₂ {φ} ([⊥]-elim p) = [⊥]-elim (weaken-union-singleton Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(_ ∧ _)} ([∧]-intro p q) = [∧]-intro (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken Γ₁Γ₂ {φ} ([∧]-elimₗ p) = [∧]-elimₗ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∧]-elimᵣ p) = [∧]-elimᵣ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introₗ p) = [∨]-introₗ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(_ ∨ _)} ([∨]-introᵣ p) = [∨]-introᵣ (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∨]-elim p q r) = [∨]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken-union-singleton Γ₁Γ₂ q) (weaken Γ₁Γ₂ r)
weaken Γ₁Γ₂ {.(_ ⟶ _)} ([⟶]-intro p) = [⟶]-intro (weaken-union-singleton Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([⟶]-elim p q) = [⟶]-elim (weaken Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken Γ₁Γ₂ {.(Ɐ _)} ([Ɐ]-intro p) = [Ɐ]-intro (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(substitute0 _ _)} ([Ɐ]-elim p) = [Ɐ]-elim (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {.(∃ _)} ([∃]-intro p) = [∃]-intro (weaken Γ₁Γ₂ p)
weaken Γ₁Γ₂ {φ} ([∃]-elim p q) = [∃]-elim (weaken-union-singleton Γ₁Γ₂ p) (weaken Γ₁Γ₂ q)
weaken-union-singleton Γ₁Γ₂ p = weaken (Either.mapLeft Γ₁Γ₂) p
weaken-union : (Γ₁ ⊢_) ⊆ ((Γ₁ ∪ Γ₂) ⊢_)
weaken-union = weaken Left
[⊥]-elim-constructive : (Γ ⊢ ⊥) → (Γ ⊢ φ)
[⊥]-elim-constructive Γ⊥ = [⊥]-elim (weaken-union Γ⊥)
[¬¬]-elim : (Γ ⊢ ¬(¬ φ)) → (Γ ⊢ φ)
[¬¬]-elim nnφ =
([⊥]-elim
([⟶]-elim
(direct(Right [≡]-intro))
(weaken-union nnφ)
)
)
[¬¬]-intro : (Γ ⊢ φ) → (Γ ⊢ ¬(¬ φ))
[¬¬]-intro Γφ =
([¬]-intro
([⟶]-elim
(weaken-union Γφ)
(direct (Right [≡]-intro))
)
)
| {
"alphanum_fraction": 0.4725226219,
"avg_line_length": 38.7264957265,
"ext": "agda",
"hexsha": "371d71507bc997130f6f0cb2ca67135d3cdbd41a",
"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": "Formalization/PredicateLogic/Classical/NaturalDeduction.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": "Formalization/PredicateLogic/Classical/NaturalDeduction.agda",
"max_line_length": 151,
"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": "Formalization/PredicateLogic/Classical/NaturalDeduction.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": 2334,
"size": 4531
} |
module Tactic.Reflection where
open import Prelude hiding (abs; _>>=_) renaming (_>>=′_ to _>>=_)
open import Builtin.Reflection public
open import Tactic.Reflection.DeBruijn public
open import Tactic.Reflection.Telescope public
open import Tactic.Reflection.Substitute public
open import Tactic.Reflection.Free public
open import Tactic.Reflection.Equality public
open import Tactic.Reflection.Meta public
set₀ : Type
set₀ = agda-sort (lit 0)
set! : Type
set! = agda-sort unknown
pattern var₀ x = var x []
pattern var₁ x a = var x (vArg a ∷ [])
pattern var₂ x a b = var x (vArg a ∷ vArg b ∷ [])
pattern var₃ x a b c = var x (vArg a ∷ vArg b ∷ vArg c ∷ [])
pattern var₄ x a b c d = var x (vArg a ∷ vArg b ∷ vArg c ∷ vArg d ∷ [])
pattern con₀ c = con c []
pattern con₁ c x = con c (vArg x ∷ [])
pattern con₂ c x y = con c (vArg x ∷ vArg y ∷ [])
pattern con₃ c x y z = con c (vArg x ∷ vArg y ∷ vArg z ∷ [])
pattern con₄ c x y z u = con c (vArg x ∷ vArg y ∷ vArg z ∷ vArg u ∷ [])
pattern def₀ f = def f []
pattern def₁ f x = def f (vArg x ∷ [])
pattern def₂ f x y = def f (vArg x ∷ vArg y ∷ [])
pattern def₃ f x y z = def f (vArg x ∷ vArg y ∷ vArg z ∷ [])
pattern def₄ f x y z u = def f (vArg x ∷ vArg y ∷ vArg z ∷ vArg u ∷ [])
infixr 4 _`→_ _`→ʰ_ _`→ⁱ_
_`→_ _`→ʰ_ _`→ⁱ_ : Type → Type → Type
_`→_ a b = pi (vArg a) (abs "_" b)
_`→ʰ_ a b = pi (hArg a) (abs "_" b)
_`→ⁱ_ a b = pi (iArg a) (abs "_" b)
`λ : Term → Term
`λ b = lam visible (abs "_" b)
infixl 9 _`∘_
_`∘_ : Term → Term → Term
_`∘_ = def₂ (quote _∘_)
infixr -20 _`$_
_`$_ : Term → Term → Term
_`$_ = def₂ (quote _$_)
_:′_ : Term → Type → TC Term
_:′_ = checkType
λ′ : ∀ {a} {A : Set a} → Arg Type → TC A → TC A
λ′ = extendContext
infix 2 _=′_
_=′_ : Term → Term → TC ⊤
_=′_ = unify
on-goal : (Type → Tactic) → Tactic
on-goal tac hole = inferNormalisedType hole >>= λ goal → tac goal hole
forceFun : Type → TC Type
forceFun a = do
dom ← newMeta set!
rng ← newMeta set!
unify a (dom `→ weaken 1 rng)
normalise a
inferFunRange : Term → TC Type
inferFunRange hole = unPi =<< forceFun =<< inferType hole where
unPi : Type → TC Type
unPi (pi _ (abs _ (meta x _))) = blockOnMeta! x
unPi (pi _ (abs _ b)) = maybe (typeError ( strErr "Must be applied in a non-dependent function position"
∷ termErr b ∷ [])) pure $ strengthen 1 b
unPi x = typeError (strErr "Invalid goal" ∷ termErr x ∷ [])
macro
runT : Tactic → Tactic
runT t = t
evalTC : ∀ {a} {A : Set a} → TC A → Tactic
evalTC {A = A} c hole = do
v ← c
`v ← quoteTC v
`A ← quoteTC A
checkedHole ← checkType hole `A
unify checkedHole `v
macro
evalT : ∀ {a} {A : Set a} → TC A → Tactic
evalT = evalTC
| {
"alphanum_fraction": 0.5918880115,
"avg_line_length": 28.7216494845,
"ext": "agda",
"hexsha": "06bc6616efb75aaf5db50b92ce6ae770c33fb09d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "lclem/agda-prelude",
"max_forks_repo_path": "src/Tactic/Reflection.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "lclem/agda-prelude",
"max_issues_repo_path": "src/Tactic/Reflection.agda",
"max_line_length": 106,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "75016b4151ed601e28f4462cd7b6b1aaf5d0d1a6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "lclem/agda-prelude",
"max_stars_repo_path": "src/Tactic/Reflection.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1040,
"size": 2786
} |
------------------------------------------------------------------------------
-- The unary numbers are LTC-PCF total natural numbers
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Data.Nat.UnaryNumbers.Totality where
open import LTC-PCF.Base
open import LTC-PCF.Data.Nat.Type
open import LTC-PCF.Data.Nat.UnaryNumbers
------------------------------------------------------------------------------
0-N : N [0]
0-N = nzero
1-N : N [1]
1-N = nsucc 0-N
2-N : N [2]
2-N = nsucc 1-N
| {
"alphanum_fraction": 0.40625,
"avg_line_length": 27.0769230769,
"ext": "agda",
"hexsha": "ab43265a5bedc3655bb8373af4c23fb12cd0391a",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/LTC-PCF/Data/Nat/UnaryNumbers/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/Data/Nat/UnaryNumbers/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/Data/Nat/UnaryNumbers/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": 143,
"size": 704
} |
{-# OPTIONS --universe-polymorphism #-}
module Issue204.Dependency where
postulate
Level : Set
zero : Level
suc : Level → Level
{-# BUILTIN LEVEL Level #-}
{-# BUILTIN LEVELZERO zero #-}
{-# BUILTIN LEVELSUC suc #-}
record R (ℓ : Level) : Set (suc ℓ) where
data D (ℓ : Level) : Set (suc ℓ) where
module M {ℓ : Level} (d : D ℓ) where
| {
"alphanum_fraction": 0.6186440678,
"avg_line_length": 18.6315789474,
"ext": "agda",
"hexsha": "630d4ec76b369c80d249d0b46c9ec82ed711eaed",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "np/agda-git-experiment",
"max_forks_repo_path": "test/succeed/Issue204/Dependency.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "20596e9dd9867166a64470dd24ea68925ff380ce",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "np/agda-git-experiment",
"max_issues_repo_path": "test/succeed/Issue204/Dependency.agda",
"max_line_length": 40,
"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/succeed/Issue204/Dependency.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": 114,
"size": 354
} |
-- Copyright: (c) 2016 Ertugrul Söylemez
-- License: BSD3
-- Maintainer: Ertugrul Söylemez <[email protected]>
module Algebra.Category where
open import Algebra.Category.Category public
open import Algebra.Category.Groupoid public
open import Algebra.Category.Semigroupoid public
| {
"alphanum_fraction": 0.7978723404,
"avg_line_length": 28.2,
"ext": "agda",
"hexsha": "3db7e2a811133b1f4c389a015dd8c88600a135f5",
"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": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "esoeylemez/agda-simple",
"max_forks_repo_path": "Algebra/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"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": "esoeylemez/agda-simple",
"max_issues_repo_path": "Algebra/Category.agda",
"max_line_length": 48,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "d9245e5a8b2e902781736de09bd17e81022f6f13",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "esoeylemez/agda-simple",
"max_stars_repo_path": "Algebra/Category.agda",
"max_stars_repo_stars_event_max_datetime": "2019-10-07T17:36:42.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-07T17:36:42.000Z",
"num_tokens": 77,
"size": 282
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.ConsensusTypes.ExecutedBlock as ExecutedBlock
import LibraBFT.Impl.Consensus.ConsensusTypes.Vote as Vote
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.Impl.OBM.Prelude
open import LibraBFT.Impl.OBM.Rust.RustTypes
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Interface.Output
open import LibraBFT.ImplShared.Util.Crypto
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.ByteString
open import Util.Hash
import Util.KVMap as Map
open import Util.PKCS
open import Util.Prelude
------------------------------------------------------------------------------
open import Data.String using (String)
module LibraBFT.Impl.Consensus.BlockStorage.BlockTree where
postulate -- TODO-2: implement linkableBlockNew
linkableBlockNew : ExecutedBlock → LinkableBlock
module addChild (lb : LinkableBlock) (hv : HashValue) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog LinkableBlock
postulate -- TODO-2: implement addChild
step₀ : VariantFor EitherD
-- addChild : LinkableBlock → HashValue → Either ErrLog LinkableBlock
-- addChild lb hv =
-- if Set.member hv (lb ^∙ lbChildren)
-- then Left fakeErr
-- else Right (lb & lbChildren %~ Set.insert hv)
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
addChild = addChild.D
new : ExecutedBlock → QuorumCert → QuorumCert → Usize → Maybe TimeoutCertificate
→ Either ErrLog BlockTree
new root0 rootQuorumCert rootLedgerInfo maxPruned mHighestTimeoutCert = do
lcheck ((root0 ^∙ ebId) == (rootLedgerInfo ^∙ qcCommitInfo ∙ biId))
("BlockTree" ∷ "newBlockTree" ∷ "inconsistent root and ledger info" ∷ [])
let idToBlock = Map.insert (root0 ^∙ ebId) (linkableBlockNew root0) Map.empty
idToQuorumCert = Map.insert (rootQuorumCert ^∙ qcCertifiedBlock ∙ biId) rootQuorumCert Map.empty
prunedBlockIds = vdNew -- TODO
in pure $ mkBlockTree
idToBlock
(root0 ^∙ ebId) -- _btRootId
(root0 ^∙ ebId) -- _btHighestCertifiedBlockId
rootQuorumCert -- _btHighestQuorumCert
mHighestTimeoutCert
rootLedgerInfo -- _btHighestCommitCert
idToQuorumCert
prunedBlockIds
maxPruned
replaceTimeoutCertM : TimeoutCertificate → LBFT Unit
replaceTimeoutCertM tc = do
lBlockStore ∙ bsInner ∙ btHighestTimeoutCert ?= tc
logInfo fakeInfo -- lTO (InfoUpdateHighestTimeoutCert (Just tc))
------------------------------------------------------------------------------
module insertBlockE (block : ExecutedBlock)(bt : BlockTree) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog (BlockTree × ExecutedBlock)
-- TODO: break into smaller steps to take advantage of the EitherD-weakestpre machinery to prove
-- the contract.
step₀ = do
let blockId = block ^∙ ebId
caseMD btGetBlock blockId bt of λ where
(just existingBlock) → pure (bt , existingBlock)
nothing → caseMD btGetLinkableBlock (block ^∙ ebParentId) bt of λ where
nothing → LeftD fakeErr
(just parentBlock) → (do
parentBlock' ← addChild parentBlock blockId
let bt' = bt & btIdToBlock ∙~ Map.kvm-insert-Haskell (block ^∙ ebParentId) parentBlock' (bt ^∙ btIdToBlock)
pure ( (bt' & btIdToBlock ∙~ Map.kvm-insert-Haskell blockId (LinkableBlock∙new block) (bt' ^∙ btIdToBlock))
, block))
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
-- We make the EitherD variant the default, because the only call in code
-- modeled is in EitherD, so it's nice to keep it exactly like the Haskell
-- code being modeled. However, insertBlockESpec.Contract and the proof of
-- executeAndInsertBlockESpec.contract' (which was written before EitherD
-- support was developed) both want an Either variant, so they use
-- insertBlockE.E. This demonstrates the flexibility of the VariantOf
-- approach, providing variants for any EitherLike, and means to convert
-- between them easily.
insertBlockE = insertBlockE.D
------------------------------------------------------------------------------
module insertQuorumCertE (qc : QuorumCert) (bt0 : BlockTree) where
VariantFor : ∀ {ℓ} EL → EL-func {ℓ} EL
VariantFor EL = EL ErrLog (BlockTree × List InfoLog)
step₁ : HashValue → VariantFor EitherD
step₂ : HashValue → ExecutedBlock → VariantFor EitherD
step₃ : HashValue → ExecutedBlock → ExecutedBlock → VariantFor EitherD
continue1 : BlockTree → HashValue → ExecutedBlock → List InfoLog → (BlockTree × List InfoLog)
continue2 : BlockTree → List InfoLog → (BlockTree × List InfoLog)
here' : List String → List String
here' t = "BlockTree" ∷ "insertQuorumCert" ∷ t
blockId = qc ^∙ qcCertifiedBlock ∙ biId
safetyInvariant = forM_ (Map.elems (bt0 ^∙ btIdToQuorumCert)) $ \x →
lcheck ( (x ^∙ qcLedgerInfo ∙ liwsLedgerInfo ∙ liConsensusDataHash
== qc ^∙ qcLedgerInfo ∙ liwsLedgerInfo ∙ liConsensusDataHash)
∨ (x ^∙ qcCertifiedBlock ∙ biRound
/= qc ^∙ qcCertifiedBlock ∙ biRound))
(here' ("failed check" ∷ "existing qc == qc || existing qc.round /= qc.round" ∷ []))
step₀ =
case safetyInvariant of λ where
(Left e) → LeftD e
(Right unit) → step₁ blockId
step₁ blockId =
maybeSD (btGetBlock blockId bt0) (LeftD fakeErr) $ step₂ blockId
step₂ blockId block =
maybeSD (bt0 ^∙ btHighestCertifiedBlock) (LeftD fakeErr) $ step₃ blockId block
step₃ blockId block hcb =
ifD ((block ^∙ ebRound) >? (hcb ^∙ ebRound))
then
(let bt = bt0 & btHighestCertifiedBlockId ∙~ block ^∙ ebId
& btHighestQuorumCert ∙~ qc
info = (fakeInfo ∷ [])
in pure (continue1 bt blockId block info))
else pure (continue1 bt0 blockId block [])
continue1 bt blockId block info =
continue2 ( bt & btIdToQuorumCert ∙~ lookupOrInsert blockId qc (bt ^∙ btIdToQuorumCert))
( (fakeInfo ∷ info) ++ (if ExecutedBlock.isNilBlock block then fakeInfo ∷ [] else [] ))
continue2 bt info =
if-dec (bt ^∙ btHighestCommitCert ∙ qcCommitInfo ∙ biRound) <? (qc ^∙ qcCommitInfo ∙ biRound)
then ((bt & btHighestCommitCert ∙~ qc) , info)
else (bt , info)
E : VariantFor Either
E = toEither step₀
D : VariantFor EitherD
D = fromEither E
insertQuorumCertE = insertQuorumCertE.E
insertQuorumCertM : QuorumCert → LBFT Unit
insertQuorumCertM qc = do
bt ← use lBlockTree
case insertQuorumCertE qc bt of λ where
(Left e) → logErr e
(Right (bt' , info)) → do
forM_ info logInfo
lBlockTree ∙= bt'
------------------------------------------------------------------------------
module pathFromRoot (blockId : HashValue) (blockTree : BlockTree) where
-- TODO-1 PROVE IT TERMINATES
{-# TERMINATING #-}
loop : ExecutedBlock → HashValue → List ExecutedBlock → Maybe (HashValue × List ExecutedBlock)
loop btr curBlockId res = case btGetBlock curBlockId blockTree of λ where
(just block) → if-dec (block ^∙ ebRound) ≤?ℕ (btr ^∙ ebRound)
then just (curBlockId , res)
else loop btr (block ^∙ ebParentId) (block ∷ res)
nothing → nothing
pathFromRoot : HashValue → BlockTree → Either ErrLog (List ExecutedBlock)
pathFromRoot blockId blockTree =
maybeS (blockTree ^∙ btRoot) (Left fakeErr) $ λ btr →
maybeS (loop btr blockId []) (pure []) (pure ∘ continue)
where
open pathFromRoot blockId blockTree
continue : (HashValue × List ExecutedBlock) → List ExecutedBlock
continue (curBlockId , res) =
if not (curBlockId /= (blockTree ^∙ btRootId))
then []
else res
------------------------------------------------------------------------------
getAllBlockIdM : LBFT (List HashValue)
getAllBlockIdM = Map.kvm-keys <$> use (lBlockTree ∙ btIdToBlock)
| {
"alphanum_fraction": 0.6524679639,
"avg_line_length": 39.5680751174,
"ext": "agda",
"hexsha": "583c32639b0dcfbf0a42b44c534e4876b4be595b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.agda",
"max_line_length": 118,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/BlockStorage/BlockTree.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2390,
"size": 8428
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2020, 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
-- This module defines an intermediate (between an implementation and Abstract) notion
-- of a system state. The goal is to enable proving for a particular implementation
-- the properties required to provide to Abstract.Properties in order to get the high
-- level correctness conditions, while moving the obligations for the implementation
-- closer to notions more directly provable for an implementation. However, as our
-- experience has developed with this, it seems that this was not a very effective
-- choice, as it leaves too much burden on the implementation (e.g., proving
-- ∈QC⇒HasBeenSent). Therefore, ...
--
-- TODO-3: Revisit assumptions of the IntermediateSystemState to enable more proof work
-- to be done under Concrete, which can be used by multiple implementations. As it
-- currently stands, we have specific notions under LibraBFT.Impl that possibly should
-- be provided as module parameters to LibraBFT.Concrete (including IsValidVote and
-- α-ValidVote)
open import LibraBFT.Prelude
open import LibraBFT.Impl.Base.Types
open import LibraBFT.Abstract.Types.EpochConfig UID NodeId
open WithAbsVote
module LibraBFT.Concrete.Intermediate
(𝓔 : EpochConfig)
(𝓥 : VoteEvidence 𝓔)
where
open import LibraBFT.Abstract.Abstract UID _≟UID_ NodeId 𝓔 𝓥
-- Since the invariants we want to specify (votes-once and preferred-round-rule),
-- are predicates over a /System State/, we must factor out the necessary
-- functionality.
--
-- An /IntermediateSystemState/ supports a few different notions; namely,
record IntermediateSystemState (ℓ : Level) : Set (ℓ+1 ℓ) where
field
-- A notion of membership of records
InSys : Record → Set ℓ
-- A predicate about whether votes have been transfered
-- amongst participants
HasBeenSent : Vote → Set ℓ
-- Such that, the votes that belong to honest participants inside a
-- QC that exists in the system must have been sent
∈QC⇒HasBeenSent : ∀{q α} → InSys (Q q) → Meta-Honest-Member α
→ (va : α ∈QC q) → HasBeenSent (∈QC-Vote q va)
| {
"alphanum_fraction": 0.7317487267,
"avg_line_length": 47.12,
"ext": "agda",
"hexsha": "fecb0865c082977b4673c41295633d581f9ca73a",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "cwjnkins/bft-consensus-agda",
"max_forks_repo_path": "LibraBFT/Concrete/Intermediate.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "cwjnkins/bft-consensus-agda",
"max_issues_repo_path": "LibraBFT/Concrete/Intermediate.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "71aa2168e4875ffdeece9ba7472ee3cee5fa9084",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "cwjnkins/bft-consensus-agda",
"max_stars_repo_path": "LibraBFT/Concrete/Intermediate.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 585,
"size": 2356
} |
------------------------------------------------------------------------
-- An implementation of tree sort, formally proved to return a
-- permutation of the input
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Equality
open import Prelude hiding (id; _∘_; List; module List; []; _∷_)
module Container.Tree-sort
{c⁺}
(eq : ∀ {a p} → Equality-with-J a p c⁺)
{A : Type}
(_≤_ : A → A → Bool) -- A comparison function.
where
open Derived-definitions-and-properties eq
open import Logical-equivalence using (module _⇔_)
open import Bijection eq using (_↔_; module _↔_)
open import Container eq
open import Container.List eq as List
open import Container.Tree eq as Tree
open import Function-universe eq
------------------------------------------------------------------------
-- Boring lemmas
private
-- The following lemma is easy to prove automatically (for
-- instance by using a ring solver).
lemma₁ : (A B C D : Type) → A ⊎ B ⊎ C ⊎ D ↔ C ⊎ A ⊎ B ⊎ D
lemma₁ A B C D =
A ⊎ B ⊎ C ⊎ D ↔⟨ id ⊎-cong ⊎-assoc ⟩
A ⊎ (B ⊎ C) ⊎ D ↔⟨ id ⊎-cong ⊎-comm ⊎-cong id ⟩
A ⊎ (C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⟩
(A ⊎ C ⊎ B) ⊎ D ↔⟨ ⊎-assoc ⊎-cong id ⟩
((A ⊎ C) ⊎ B) ⊎ D ↔⟨ (⊎-comm ⊎-cong id) ⊎-cong id ⟩
((C ⊎ A) ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⊎-cong id ⟩
(C ⊎ A ⊎ B) ⊎ D ↔⟨ inverse ⊎-assoc ⟩
C ⊎ (A ⊎ B) ⊎ D ↔⟨ id ⊎-cong inverse ⊎-assoc ⟩
C ⊎ A ⊎ B ⊎ D □
lemma₂ : {A B C D : Type} (b : Bool) →
T b × ((A ⊎ B) ⊎ C ⊎ D) ⊎ T (not b) × (B ⊎ C ⊎ A ⊎ D) ↔
A ⊎ B ⊎ C ⊎ D
lemma₂ = if-lemma (λ _ → _) (inverse ⊎-assoc) (lemma₁ _ _ _ _)
------------------------------------------------------------------------
-- Insertion into trees
-- Inserts an element into the tree.
insert : A → ⟦ Tree ⟧ A → ⟦ Tree ⟧ A
insert x = Tree.fold
(singleton x)
(λ l y r x+l x+r →
if x ≤ y then node x+l y r
else node l y x+r)
-- The insert function inserts.
Any-insert : ∀ (P : A → Type) x t →
Any P (insert x t) ↔ P x ⊎ Any P t
Any-insert P x = Tree.fold-lemma
(λ t t′ → Any P t′ ↔ P x ⊎ Any P t)
(λ t₁ t₂ t₁≈t₂ t hyp →
Any P t ↔⟨ hyp ⟩
P x ⊎ Any P t₁ ↔⟨ id ⊎-cong _⇔_.to (∼⇔∼″ t₁ t₂) t₁≈t₂ P ⟩
P x ⊎ Any P t₂ □)
(Any P (singleton x) ↔⟨ Any-singleton P ⟩
P x ↔⟨ inverse ⊎-right-identity ⟩
P x ⊎ ⊥ ↔⟨ id ⊎-cong inverse (Any-leaf P) ⟩
P x ⊎ Any P leaf □)
(λ l y r l′ r′ ih-l ih-r →
Any P (if x ≤ y then node l′ y r else node l y r′) ↔⟨ Any-if P (node l′ y r) (node l y r′) (x ≤ y) ⟩
T (x ≤ y) × Any P (node l′ y r) ⊎
T (not (x ≤ y)) × Any P (node l y r′) ↔⟨ id ×-cong Any-node P ⊎-cong
id ×-cong Any-node P ⟩
T (x ≤ y) × (Any P l′ ⊎ P y ⊎ Any P r) ⊎
T (not (x ≤ y)) × (Any P l ⊎ P y ⊎ Any P r′) ↔⟨ id ×-cong (ih-l ⊎-cong id) ⊎-cong
id ×-cong (id ⊎-cong id ⊎-cong ih-r) ⟩
T (x ≤ y) × ((P x ⊎ Any P l) ⊎ P y ⊎ Any P r) ⊎
T (not (x ≤ y)) × (Any P l ⊎ P y ⊎ P x ⊎ Any P r) ↔⟨ lemma₂ (x ≤ y) ⟩
P x ⊎ Any P l ⊎ P y ⊎ Any P r ↔⟨ id ⊎-cong inverse (Any-node P) ⟩
P x ⊎ Any P (node l y r) □)
------------------------------------------------------------------------
-- Turning a list into a search tree
-- Converts the list to a search tree.
to-search-tree : ⟦ List ⟧ A → ⟦ Tree ⟧ A
to-search-tree = List.fold leaf (λ x _ t → insert x t)
-- No elements are added or removed.
to-search-tree≈ : ∀ xs → to-search-tree xs ≈-bag xs
to-search-tree≈ = List.fold-lemma
(λ xs t → t ≈-bag xs)
(λ xs ys xs≈ys t t≈xs z →
z ∈ t ↔⟨ t≈xs z ⟩
z ∈ xs ↔⟨ xs≈ys z ⟩
z ∈ ys □)
(λ z →
z ∈ leaf ↔⟨ Any-leaf (λ x → z ≡ x) ⟩
⊥ ↔⟨ inverse $ Any-[] (λ x → z ≡ x) ⟩
z ∈ [] □)
(λ x xs t t≈xs z →
z ∈ insert x t ↔⟨ Any-insert (λ x → z ≡ x) _ _ ⟩
z ≡ x ⊎ z ∈ t ↔⟨ id ⊎-cong t≈xs z ⟩
z ≡ x ⊎ z ∈ xs ↔⟨ inverse $ Any-∷ (λ x → z ≡ x) ⟩
z ∈ x ∷ xs □)
------------------------------------------------------------------------
-- Sorting
-- Sorts a list.
sort : ⟦ List ⟧ A → ⟦ List ⟧ A
sort = flatten ∘ to-search-tree
-- The result is a permutation of the input.
sort≈ : ∀ xs → sort xs ≈-bag xs
sort≈ xs = λ z →
z ∈ sort xs ↔⟨⟩
z ∈ flatten (to-search-tree xs) ↔⟨ flatten≈ (to-search-tree xs) _ ⟩
z ∈ to-search-tree xs ↔⟨ to-search-tree≈ xs _ ⟩
z ∈ xs □
| {
"alphanum_fraction": 0.426183844,
"avg_line_length": 32.4097222222,
"ext": "agda",
"hexsha": "fa4873e74f1054aa27156c2156262a31494d644d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/equality",
"max_forks_repo_path": "src/Container/Tree-sort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/equality",
"max_issues_repo_path": "src/Container/Tree-sort.agda",
"max_line_length": 107,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "402b20615cfe9ca944662380d7b2d69b0f175200",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/equality",
"max_stars_repo_path": "src/Container/Tree-sort.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-02T17:18:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:50.000Z",
"num_tokens": 1753,
"size": 4667
} |
module Type.Identity where
import Lvl
open import Type
private variable ℓ : Lvl.Level
private variable T : Type{ℓ}
-- Identity type.
-- Also called: Propositional equality.
-- Two terms are identical/equal when their data representation are the same.
data Id {T : Type{ℓ}} : T → T → Type{ℓ} where
instance intro : ∀{x : T} → Id x x
-- Interpretation:
-- The only way to construct something of type Id is to use identical objects for both arguments.
-- When matching on the constructor, the type checker "unifies" the two terms making them the same.
-- This is how the builtin pattern matching by intro works, and therefore many propositions for identity becomes "trivial" syntactically.
{-# BUILTIN EQUALITY Id #-}
{-# BUILTIN REWRITE Id #-}
elim : (P : ∀{x y : T} → (Id x y) → Type{ℓ}) → (∀{x} → P(intro{x = x})) → (∀{x y} → (eq : (Id x y)) → P(eq))
elim _ p intro = p
| {
"alphanum_fraction": 0.6700111483,
"avg_line_length": 37.375,
"ext": "agda",
"hexsha": "29e771d39f88ed66a011206d635ca9eac3a88909",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Lolirofle/stuff-in-agda",
"max_forks_repo_path": "Type/Identity.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Type/Identity.agda",
"max_line_length": 141,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Lolirofle/stuff-in-agda",
"max_stars_repo_path": "Type/Identity.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": 255,
"size": 897
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Convenient syntax for "equational reasoning" using a partial order
------------------------------------------------------------------------
-- Example uses:
--
-- u≤x : u ≤ x
-- u≤x = begin
-- u ≈⟨ u≈v ⟩
-- v ≡⟨ v≡w ⟩
-- w <⟨ w≤x ⟩
-- x ∎
--
-- u<x : u < x
-- u<x = begin-strict
-- u ≈⟨ u≈v ⟩
-- v ≡⟨ v≡w ⟩
-- w <⟨ w≤x ⟩
-- x ∎
--
-- u<e : u < e
-- u<e = begin-strict
-- u ≈⟨ u≈v ⟩
-- v ≡⟨ v≡w ⟩
-- w <⟨ w<x ⟩
-- x ≤⟨ x≤y ⟩
-- y <⟨ y<z ⟩
-- z ≡˘⟨ d≡z ⟩
-- d ≈˘⟨ e≈d ⟩
-- e ∎
--
-- u≈w : u ≈ w
-- u≈w = begin-equality
-- u ≈⟨ u≈v ⟩
-- v ≡⟨ v≡w ⟩
-- w ∎
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Relation.Binary.Reasoning.PartialOrder
{p₁ p₂ p₃} (P : Poset p₁ p₂ p₃) where
open Poset P
import Relation.Binary.Construct.NonStrictToStrict _≈_ _≤_ as Strict
------------------------------------------------------------------------
-- Re-export contents of base module
open import Relation.Binary.Reasoning.Base.Triple
isPreorder
(Strict.trans isPartialOrder)
(Strict.<-resp-≈ isEquivalence ≤-resp-≈)
Strict.<⇒≤
(Strict.<-≤-trans Eq.sym trans antisym ≤-respʳ-≈)
(Strict.≤-<-trans trans antisym ≤-respˡ-≈)
public
------------------------------------------------------------------------
-- DEPRECATED NAMES
------------------------------------------------------------------------
-- Please use the new names as continuing support for the old names is
-- not guaranteed.
-- Version 1.0
infixr 2 _≈⟨⟩_
_≈⟨⟩_ = _≡⟨⟩_
{-# WARNING_ON_USAGE _≈⟨⟩_
"Warning: _≈⟨⟩_ was deprecated in v1.0.
Please use _≡⟨⟩_ instead."
#-}
| {
"alphanum_fraction": 0.4156059768,
"avg_line_length": 22.8734177215,
"ext": "agda",
"hexsha": "f358038ffea328364ff3cf880544c0ddafca464d",
"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/Reasoning/PartialOrder.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/Reasoning/PartialOrder.agda",
"max_line_length": 72,
"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/Reasoning/PartialOrder.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": 652,
"size": 1807
} |
{-
Homotopy colimits of graphs
-}
{-# OPTIONS --cubical --safe #-}
module Cubical.HITs.Colimit.Base where
open import Cubical.Core.Glue
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Data.Graph
-- Cones under a diagram
record Cocone ℓ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ)
: Type (ℓ-suc (ℓ-max ℓ (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))) where
field
leg : ∀ (j : Obj I) → F $ j → X
com : ∀ {j k} (f : Hom I j k) → leg k ∘ F <$> f ≡ leg j
postcomp : ∀ {ℓ'} {Y : Type ℓ'} → (X → Y) → Cocone ℓ' F Y
leg (postcomp h) j = h ∘ leg j
com (postcomp h) f = cong (h ∘_) (com f)
open Cocone public
-- Σ (Type ℓ) (Cocone ℓ F) forms a category:
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
private
-- the "lower star" functor
_* : ∀ {ℓ ℓ'} {X : Type ℓ} {Y : Type ℓ'} → (X → Y) → Cocone _ F X → Cocone _ F Y
(h *) C = postcomp C h
CoconeMor : ∀ {ℓ ℓ'} → Σ (Type ℓ) (Cocone ℓ F) → Σ (Type ℓ') (Cocone ℓ' F) → Type _
CoconeMor (X , C) (Y , D) = Σ[ h ∈ (X → Y) ] (h *) C ≡ D
idCoconeMor : ∀ {ℓ} (Cp : Σ (Type ℓ) (Cocone ℓ F)) → CoconeMor Cp Cp
idCoconeMor Cp = (λ x → x) , refl
compCoconeMor : ∀ {ℓ ℓ' ℓ''} {C : Σ (Type ℓ) (Cocone ℓ F)} {D : Σ (Type ℓ') (Cocone ℓ' F)}
{E : Σ (Type ℓ'') (Cocone ℓ'' F)}
→ CoconeMor D E → CoconeMor C D → CoconeMor C E
compCoconeMor (g , q) (f , p) = g ∘ f , (cong (g *) p) ∙ q
-- Universal cocones are initial objects in the category Σ (Type ℓ) (Cocone ℓ F)
module _ {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} where
isUniversalAt : ∀ ℓq → Cocone ℓ F X → Type (ℓ-max ℓ (ℓ-suc (ℓ-max ℓq (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd)))))
isUniversalAt ℓq C = ∀ (Y : Type ℓq) → isEquiv {A = (X → Y)} {B = Cocone ℓq F Y} (postcomp C)
-- (unfolding isEquiv, this ^ is equivalent to what one might expect:)
-- ∀ (Y : Type ℓ) (D : Cocone ℓ F Y) → isContr (Σ[ h ∈ (X → Y) ] (h *) C ≡ D)
-- (≡ isContr (CoconeMor (X , C) (Y , D)))
isPropIsUniversalAt : ∀ ℓq (C : Cocone ℓ F X) → isProp (isUniversalAt ℓq C)
isPropIsUniversalAt ℓq C = propPi (λ Y → isPropIsEquiv (postcomp C))
isUniversal : Cocone ℓ F X → Typeω
isUniversal C = ∀ ℓq → isUniversalAt ℓq C
-- Colimits are universal cocones
record isColimit {ℓ ℓd ℓv ℓe} {I : Graph ℓv ℓe} (F : Diag ℓd I) (X : Type ℓ) : Typeω where
field
cone : Cocone ℓ F X
univ : isUniversal cone
open isColimit public
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
postcomp⁻¹ : isColimit F X → Cocone ℓ' F Y → (X → Y)
postcomp⁻¹ cl = invEq (_ , univ cl _ Y)
postcomp⁻¹-inv : (cl : isColimit F X) (D : Cocone ℓ' F Y) → (postcomp (cone cl) (postcomp⁻¹ cl D)) ≡ D
postcomp⁻¹-inv cl D = retEq (_ , univ cl _ Y) D
postcomp⁻¹-mor : (cl : isColimit F X) (D : Cocone ℓ' F Y) → CoconeMor (X , cone cl) (Y , D)
postcomp⁻¹-mor cl D = (postcomp⁻¹ cl D) , (postcomp⁻¹-inv cl D)
-- Colimits are unique
module _ {ℓ ℓ' ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} {X : Type ℓ} {Y : Type ℓ'} where
uniqColimit : isColimit F X → isColimit F Y → X ≃ Y
uniqColimit cl cl'
= isoToEquiv (iso (fst fwd) (fst bwd)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl' ℓ' Y) (cone cl'))
(compCoconeMor fwd bwd)
(idCoconeMor (Y , cone cl')) i) x)
(λ x i → fst (isContr→isProp (equiv-proof (univ cl ℓ X) (cone cl))
(compCoconeMor bwd fwd)
(idCoconeMor (X , cone cl)) i) x))
where fwd : CoconeMor (X , cone cl ) (Y , cone cl')
bwd : CoconeMor (Y , cone cl') (X , cone cl )
fwd = postcomp⁻¹-mor cl (cone cl')
bwd = postcomp⁻¹-mor cl' (cone cl)
-- Colimits always exist
data colim {ℓd ℓe ℓv} {I : Graph ℓv ℓe} (F : Diag ℓd I) : Type (ℓ-suc (ℓ-max (ℓ-max ℓv ℓe) (ℓ-suc ℓd))) where
colim-leg : ∀ (j : Obj I) → F $ j → colim F
colim-com : ∀ {j k} (f : Hom I j k) → colim-leg k ∘ F <$> f ≡ colim-leg j
module _ {ℓd ℓv ℓe} {I : Graph ℓv ℓe} {F : Diag ℓd I} where
colimCone : Cocone _ F (colim F)
leg colimCone = colim-leg
com colimCone = colim-com
colim-rec : ∀ {ℓ} {X : Type ℓ} → Cocone ℓ F X → (colim F → X)
colim-rec C (colim-leg j A) = leg C j A
colim-rec C (colim-com f i A) = com C f i A
colimIsColimit : isColimit F (colim F)
cone colimIsColimit = colimCone
univ colimIsColimit ℓq Y
= isoToIsEquiv record { fun = postcomp colimCone
; inv = colim-rec
; rightInv = λ C → refl
; leftInv = λ h → funExt (eq h) }
where eq : ∀ h (x : colim _) → colim-rec (postcomp colimCone h) x ≡ h x
eq h (colim-leg j A) = refl
eq h (colim-com f i A) = refl
| {
"alphanum_fraction": 0.5379563454,
"avg_line_length": 38.0661764706,
"ext": "agda",
"hexsha": "ed14d06b0da670d4fe415a4369e5093c5ee48d69",
"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": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cj-xu/cubical",
"max_forks_repo_path": "Cubical/HITs/Colimit/Base.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"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": "cj-xu/cubical",
"max_issues_repo_path": "Cubical/HITs/Colimit/Base.agda",
"max_line_length": 109,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fd336c6d31a6e6d58a44114831aacd63f422545",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cj-xu/cubical",
"max_stars_repo_path": "Cubical/HITs/Colimit/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2087,
"size": 5177
} |
module Pos where
import Prelude
import Equiv
import Datoid
import Nat
open Prelude
open Equiv
open Datoid
abstract
Pos : Set
Pos = Nat.Nat
one : Pos
one = Nat.zero
suc : Pos -> Pos
suc = Nat.suc
suc' : Nat.Nat -> Pos
suc' n = n
_+_ : Pos -> Pos -> Pos
m + n = suc (Nat._+_ m n)
-- Returns Nothing if input is 1.
pred : Pos -> Maybe Pos
pred Nat.zero = Nothing
pred (Nat.suc n) = Just n
toNat : Pos -> Nat.Nat
toNat = suc
decidableEquiv : DecidableEquiv Pos
decidableEquiv = Nat.decidableEquiv
posDatoid : Datoid
posDatoid = datoid Pos decidableEquiv
sucPred : Maybe Pos -> Pos
sucPred Nothing = one
sucPred (Just p) = suc p
data Pred (p : Pos) (mP : Maybe Pos) : Set where
ok : datoidRel posDatoid (sucPred mP) p -> Pred p mP
abstract
-- Returns Nothing if input is 1.
predOK : (p : Pos) -> Pred p (pred p)
predOK Nat.zero = ok (dRefl posDatoid {one})
predOK (Nat.suc n) = ok (dRefl posDatoid {n})
| {
"alphanum_fraction": 0.5957854406,
"avg_line_length": 18.3157894737,
"ext": "agda",
"hexsha": "b4c2069deb5eb561caf6563fcdb9ce2eb6125976",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "examples/AIM4/bag/Pos.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "examples/AIM4/bag/Pos.agda",
"max_line_length": 56,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "examples/AIM4/bag/Pos.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": 355,
"size": 1044
} |
module Monad where
open import Level
open import Category
import Functor
import Nat
import Adjoint
open Category.Category
open Functor.Functor
open Nat.Export
open Nat.Nat
open Adjoint.Export
record Monad {c₀ c₁ ℓ} (C : Category c₀ c₁ ℓ) : Set (suc (c₀ ⊔ c₁ ⊔ ℓ)) where
field
MFunctor : Functor.Functor C C
Mjoin : Nat.Nat (Functor.exp MFunctor 2) MFunctor
Munit : Nat.Nat (Functor.identity C) MFunctor
field
join_join : {A : Obj C} → C [ C [ component Mjoin A ∘ component Mjoin (fobj MFunctor A) ] ≈ C [ component Mjoin A ∘ fmap MFunctor (component Mjoin A) ] ]
unit_MFunctor : {A : Obj C} → C [ C [ component Mjoin A ∘ component Munit (fobj MFunctor A) ] ≈ id C ]
MFunctor_unit : {A : Obj C} → C [ C [ component Mjoin A ∘ fmap MFunctor (component Munit A) ] ≈ id C ]
Adjoint-Monad : ∀ {C₀ C₁ ℓ} {C D : Category C₀ C₁ ℓ} {F : Functor.Functor C D} {G : Functor.Functor D C} → F ⊣ G → Monad C
Adjoint-Monad {C = C} {D} {F} {G} F⊣G = record {
MFunctor = T;
Mjoin = record {
component = λ X → component (G F∘N ε N∘F F) X ;
naturality = λ {a} {b} {f} → begin⟨ C ⟩
C [ component (G F∘N ε N∘F F) b ∘ fmap G (fmap (Functor.compose F T) f) ] ≈⟨ sym-hom C (preserveComp G) ⟩
fmap G (D [ component ε (fobj F b) ∘ fmap (Functor.compose F G) (fmap F f) ]) ≈⟨ Functor.preserveEq G (naturality ε) ⟩
fmap G (D [ fmap F f ∘ component ε (fobj F a) ]) ≈⟨ preserveComp G ⟩
C [ fmap T f ∘ component (G F∘N ε N∘F F) a ]
∎ };
Munit = Adjoint.unit F⊣G;
join_join = λ {A} → begin⟨ C ⟩
C [ component (G F∘N ε N∘F F) A ∘ component (G F∘N ε N∘F F) (fobj T A) ] ≈⟨ sym-hom C (preserveComp G) ⟩
fmap G (D [ component ε (fobj F A) ∘ component ε (fobj (Functor.compose F G) (fobj F A)) ]) ≈⟨ Functor.preserveEq G (sym-hom D (naturality ε)) ⟩
fmap G (D [ component ε (fobj F A) ∘ fmap (Functor.compose F G) (component ε (fobj F A)) ]) ≈⟨ preserveComp G ⟩
C [ component (G F∘N ε N∘F F) A ∘ fmap T (component (G F∘N ε N∘F F) A) ]
∎ ;
unit_MFunctor = λ {A} → begin⟨ C ⟩
C [ component (G F∘N ε N∘F F) A ∘ component η (fobj T A) ] ≈⟨ refl-hom C ⟩
C [ component (G F∘N ε) (fobj F A) ∘ component (η N∘F G) (fobj F A) ] ≈⟨ sym-hom C (≈-composite C (leftId C) (trans-hom C (leftId C) (rightId C))) ⟩
C [ C [ id C ∘ component (G F∘N ε) (fobj F A) ] ∘ C [ id C ∘ C [ component (η N∘F G) (fobj F A) ∘ id C ] ] ] ≈⟨ refl-hom C ⟩
component (Nat.compose (Nat.compose {H = G} Nat.rightIdNat→ (G F∘N ε)) (Nat.compose (Nat.assocNat→ {F = G} {F} {G}) (Nat.compose (η N∘F G) Nat.leftIdNat←))) (fobj F A) ≈⟨ Adjoint.triangularR F⊣G {fobj F A} ⟩
component (id [ D , C ] {G}) (fobj F A) ≈⟨ refl-hom C ⟩
id C
∎ ;
MFunctor_unit = λ {A} → begin⟨ C ⟩
C [ component (G F∘N ε N∘F F) A ∘ fmap T (component η A) ] ≈⟨ refl-hom C ⟩
C [ fmap G (component ε (fobj F A)) ∘ fmap G (fmap F (component η A)) ] ≈⟨ sym-hom C (preserveComp G) ⟩
fmap G (D [ component ε (fobj F A) ∘ fmap F (component η A) ]) ≈⟨ Functor.preserveEq G (≈-composite D (sym-hom D (leftId D)) (sym-hom D (trans-hom D (leftId D) (rightId D)))) ⟩
fmap G (D [ D [ id D ∘ component ε (fobj F A) ] ∘ D [ id D ∘ D [ fmap F (component η A) ∘ id D ] ] ]) ≈⟨ Functor.preserveEq G (refl-hom D) ⟩
fmap G (component (Nat.compose (Nat.compose Nat.leftIdNat→ (Adjoint.counit F⊣G N∘F F)) (Nat.compose {F = F} (Nat.assocNat← {F = F} {G} {F}) (Nat.compose {F = F} (F F∘N Adjoint.unit F⊣G) Nat.rightIdNat←))) A ) ≈⟨ Functor.preserveEq G (Adjoint.triangularL F⊣G {A}) ⟩
fmap G (component (id [ C , D ] {F}) A) ≈⟨ preserveId G ⟩
id C
∎ }
where
T = Functor.compose G F
η = Adjoint.unit F⊣G
ε = Adjoint.counit F⊣G
| {
"alphanum_fraction": 0.5880272109,
"avg_line_length": 54.0441176471,
"ext": "agda",
"hexsha": "e3ba8cfe30f93225df27dfb6db5251c55766be2b",
"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": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "myuon/agda-cate",
"max_forks_repo_path": "src/Monad.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"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": "myuon/agda-cate",
"max_issues_repo_path": "src/Monad.agda",
"max_line_length": 268,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "59004994acdbc65fb4f8abf0baa1777a8dbe758e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "myuon/agda-cate",
"max_stars_repo_path": "src/Monad.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-02T07:30:47.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-07-28T04:59:31.000Z",
"num_tokens": 1566,
"size": 3675
} |
module char where
open import bool
open import nat
open import eq
open import product
open import product-thms
----------------------------------------------------------------------
-- datatypes
----------------------------------------------------------------------
postulate
char : Set
{-# BUILTIN CHAR char #-}
----------------------------------------------------------------------
-- primitive operations
----------------------------------------------------------------------
private
primitive
primCharToNat : char → ℕ
primCharEquality : char → char → 𝔹
toNat : char → ℕ
toNat = primCharToNat
infix 4 _=char_
_=char_ : char → char → 𝔹
_=char_ = primCharEquality
postulate
≡char-to-= : (c1 c2 : char) → c1 ≡ c2 → _=char_ c1 c2 ≡ tt
=char-to-≡ : (c1 c2 : char) → _=char_ c1 c2 ≡ tt → c1 ≡ c2
=char-sym : (c1 c2 : char) → (c1 =char c2) ≡ (c2 =char c1)
=char-sym c1 c2 with keep (c1 =char c2)
=char-sym c1 c2 | tt , p rewrite =char-to-≡ c1 c2 p = refl
=char-sym c1 c2 | ff , p with keep (c2 =char c1)
=char-sym c1 c2 | ff , p | tt , p' rewrite =char-to-≡ c2 c1 p' = refl
=char-sym c1 c2 | ff , p | ff , p' rewrite p | p' = refl
postulate
_<char_ : char → char → 𝔹
{-# COMPILED _<char_ (<) #-}
----------------------------------------------------------------------
-- defined operations
----------------------------------------------------------------------
-- is a decimal digit
is-digit : char → 𝔹
is-digit '0' = tt
is-digit '1' = tt
is-digit '2' = tt
is-digit '3' = tt
is-digit '4' = tt
is-digit '5' = tt
is-digit '6' = tt
is-digit '7' = tt
is-digit '8' = tt
is-digit '9' = tt
is-digit _ = ff
| {
"alphanum_fraction": 0.454601227,
"avg_line_length": 23.9705882353,
"ext": "agda",
"hexsha": "bef728992c592b6b77facb14e4678ce4cafddf5b",
"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": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "logicshan/IAL",
"max_forks_repo_path": "char.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"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": "logicshan/IAL",
"max_issues_repo_path": "char.agda",
"max_line_length": 70,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "2ad96390a9be5c238e73709a21533c7354cedd0c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "logicshan/IAL",
"max_stars_repo_path": "char.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 494,
"size": 1630
} |
{-# OPTIONS --without-K --safe #-}
-- https://personal.cis.strath.ac.uk/conor.mcbride/pub/DepRep/DepRep.pdf
module Experiment.Outrageous.#03 where
open import Experiment.Outrageous.#02
data U : Set
El : U → Set
data U where
:Zero: :𝟏: :𝟐: :ℕ: : U
:Π: :Σ: : (S : U) → (El S → U) → U
El :Zero: = Zero
El :𝟏: = 𝟏
El :𝟐: = 𝟐
El :ℕ: = ℕ
El (:Π: S T) = (s : El S) → El (T s)
El (:Σ: S T) = Σ (El S) λ s → El (T s)
_:→:_ : U → U → U
S :→: T = :Π: S λ _ → T
_:×:_ : U → U → U
S :×: T = :Σ: S λ _ → T
:If: : 𝟐 → U → U → U
:If: tt T F = T
:If: ff T F = F
:Vec: : U → ℕ → U
:Vec: X ze = :𝟏:
:Vec: X (su n) = X :×: :Vec: X n
| {
"alphanum_fraction": 0.4710485133,
"avg_line_length": 18.2571428571,
"ext": "agda",
"hexsha": "b61b6818de36c3364af8fa2bfb0235ed0df98f4d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "rei1024/agda-misc",
"max_forks_repo_path": "Experiment/Outrageous/#03.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "rei1024/agda-misc",
"max_issues_repo_path": "Experiment/Outrageous/#03.agda",
"max_line_length": 72,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "37200ea91d34a6603d395d8ac81294068303f577",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "rei1024/agda-misc",
"max_stars_repo_path": "Experiment/Outrageous/#03.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": 323,
"size": 639
} |
------------------------------------------------------------------------------
-- Fairness of the ABP channels
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.ABP.Fair.Type where
open import FOTC.Base
open import FOTC.Base.List
open import FOTC.Data.List
open import FOTC.Program.ABP.Terms
------------------------------------------------------------------------------
-- The Fair co-inductive predicate
-- From (Dybjer and Sander 1989): al : F*T if al is a list of zero or
-- more 0's followed by a final 1.
data F*T : D → Set where
f*tnil : F*T (T ∷ [])
f*tcons : ∀ {ft} → F*T ft → F*T (F ∷ ft)
-- Functor for the Fair type.
-- FairF : (D → Set) → D → Set
-- FairF A os = ∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ A os'
-- Fair is the greatest fixed of FairF (by Fair-out and Fair-coind).
postulate Fair : D → Set
-- Fair a is post-fixed point of FairF, i.e.
--
-- Fair ≤ FairF Fair.
postulate Fair-out : ∀ {os} → Fair os →
∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ Fair os'
{-# ATP axiom Fair-out #-}
-- Fair is the greatest post-fixed point of FairF, i.e.
--
-- ∀ A. A ≤ FairF A ⇒ A ≤ Fair.
--
-- 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
Fair-coind :
(A : D → Set) →
-- A is post-fixed point of FairF.
(∀ {os} → A os → ∃[ ft ] ∃[ os' ] F*T ft ∧ os ≡ ft ++ os' ∧ A os') →
-- Fair is greater than A.
∀ {os} → A os → Fair os
------------------------------------------------------------------------------
-- References
--
-- Dybjer, Peter and Sander, Herbert P. (1989). A Functional
-- Programming Approach to the Specification and Verification of
-- Concurrent Systems. Formal Aspects of Computing 1, pp. 303–319.
| {
"alphanum_fraction": 0.4987555998,
"avg_line_length": 32.4032258065,
"ext": "agda",
"hexsha": "239dcf7d73c8cf246072308325a5d39e97027195",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/ABP/Fair/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/Program/ABP/Fair/Type.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/ABP/Fair/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": 545,
"size": 2009
} |
{-# OPTIONS --without-K --safe #-}
module Math.NumberTheory.Fibonacci.Nat where
-- agda-stdlib
open import Data.Nat
open import Data.Nat.Properties
-- agda-misc
open import Math.NumberTheory.Fibonacci.Generic +-0-commutativeMonoid 0 1
renaming
( fibRec≈fib to fibRec≡fib
; fib[2+n]≈fib[1+n]∙fib[n] to fib[2+n]≡fib[1+n]+fib[n]
; fib[1+n]∙fib[n]≈fib[2+n] to fib[1+n]+fib[n]≡fib[2+n]
; fib[n]∙fib[1+n]≈fib[2+n] to fib[n]+fib[1+n]≡fib[2+n]
) public
| {
"alphanum_fraction": 0.6652173913,
"avg_line_length": 27.0588235294,
"ext": "agda",
"hexsha": "d4637c1bcd6735d3bca15281f19774a9b397ba59",
"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": "Math/NumberTheory/Fibonacci/Nat.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": "Math/NumberTheory/Fibonacci/Nat.agda",
"max_line_length": 73,
"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": "Math/NumberTheory/Fibonacci/Nat.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": 191,
"size": 460
} |
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PushoutDef
open import Homotopy.VanKampen.Guide
module Homotopy.VanKampen.SplitCode {i} (d : pushout-diag i)
(l : legend i (pushout-diag.C d)) (a₁ : pushout-diag.A d) where
open pushout-diag d
open legend l
open import Homotopy.Truncation
open import Homotopy.PathTruncation
-- Definition.
module _ where
private
data #code-a (a₂ : A) : Set i
data #code-b (b₂ : B) : Set i
data #code-a a₂ where
#a : a₁ ≡₀ a₂ → #code-a a₂
#ba : ∀ n → #code-b (g $ loc n) → f (loc n) ≡₀ a₂ → #code-a a₂
data #code-b b₂ where
#ab : ∀ n → #code-a (f $ loc n) → g (loc n) ≡₀ b₂ → #code-b b₂
code-b : B → Set i
code-b = #code-b
code-a : A → Set i
code-a = #code-a
postulate -- HIT
code-a-is-set : ∀ a → is-set (code-a a)
code-b-is-set : ∀ b → is-set (code-b b)
a : ∀ {a₂} → a₁ ≡₀ a₂ → code-a a₂
a = #a
infixl 6 a
syntax a co = ⟧a co
ba : ∀ {a₂} n → code-b (g $ loc n) → f (loc n) ≡₀ a₂ → code-a a₂
ba = #ba
infixl 6 ba
syntax ba n co p = co b⟦ n ⟧a p
ab : ∀ {b₂} n → code-a (f $ loc n) → g (loc n) ≡₀ b₂ → code-b b₂
ab = #ab
infixl 6 ab
syntax ab n co p = co a⟦ n ⟧b p
postulate -- HIT
code-a-refl-refl : ∀ n (co : code-a (f $ loc n))
→ co a⟦ n ⟧b refl₀ b⟦ n ⟧a refl₀ ≡ co
code-b-refl-refl : ∀ n (co : code-b (g $ loc n))
→ co b⟦ n ⟧a refl₀ a⟦ n ⟧b refl₀ ≡ co
-- The other diriction is fine.
-- There's no canonical choice between two, I think.
code-ab-swap : ∀ n₁ co n₂ (r : loc n₁ ≡₀ loc n₂)
→ co a⟦ n₁ ⟧b ap₀ g r b⟦ n₂ ⟧a refl₀
≡ co a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a ap₀ f r
-- Dependent recursor.
code-rec : ∀ {j}
(P-a : ∀ {a₂} → code-a a₂ → Set j) ⦃ _ : ∀ {a₂} co → is-set $ P-a {a₂} co ⦄
(P-b : ∀ {b₂} → code-b b₂ → Set j) ⦃ _ : ∀ {b₂} co → is-set $ P-b {b₂} co ⦄
(h₀-a : ∀ {a₂} (p : _ ≡₀ a₂) → P-a (a p))
(h₀-ba : ∀ {a₂} n {co} (_ : P-b co) (p : _ ≡₀ a₂)
→ P-a (co b⟦ n ⟧a p))
(h₀-ab : ∀ {b₂} n {co} (_ : P-a co) (p : _ ≡₀ b₂)
→ P-b (co a⟦ n ⟧b p))
(h₁-a-rr : ∀ n {co} (pco : P-a co) →
transport (P-a {f $ loc n}) (code-a-refl-refl n co)
(h₀-ba n (h₀-ab n pco $ refl₀) $ refl₀)
≡ pco)
(h₁-b-rr : ∀ n {co} (pco : P-b co) →
transport (P-b {g $ loc n}) (code-b-refl-refl n co)
(h₀-ab n (h₀-ba n pco $ refl₀) $ refl₀)
≡ pco)
(h₁-ab-s : ∀ n₁ {co} (pco : P-a co) n₂ r →
transport (P-a {f $ loc n₂}) (code-ab-swap n₁ co n₂ r)
(h₀-ba n₂ (h₀-ab n₁ pco $ ap₀ g r) $ refl₀)
≡ (h₀-ba n₁ (h₀-ab n₁ pco $ refl₀) $ ap₀ f r))
→ (∀ {a₂} (co : code-a a₂) → P-a co)
× (∀ {b₂} (co : code-b b₂) → P-b co)
code-rec P-a P-b h₀-a h₀-ba h₀-ab _ _ _ = elim-a , elim-b
where
elim-a : ∀ {a₂} (co : code-a a₂) → P-a co
elim-b : ∀ {b₂} (co : code-b b₂) → P-b co
elim-a (#a p) = h₀-a p
elim-a (#ba n co p) = h₀-ba n (elim-b co) p
elim-b (#ab n co p) = h₀-ab n (elim-a co) p
-- This is actually "partially dependent".
-- P-a and P-b are indexed by the end points.
-- This is fine because they are fixed in
-- all transports in 1-cells.
code-rec-nondep : ∀ {j}
(P-a : A → Set j) ⦃ _ : ∀ a → is-set $ P-a a ⦄
(P-b : B → Set j) ⦃ _ : ∀ b → is-set $ P-b b ⦄
(h₀-a : ∀ {a₂} (p : a₁ ≡₀ a₂) → P-a a₂)
(h₀-ba : ∀ {a₂} n {co : code-b (g $ loc n)} → P-b (g $ loc n)
→ f (loc n) ≡₀ a₂ → P-a a₂)
(h₀-ab : ∀ {b₂} n {co : code-a (f $ loc n)} → P-a (f $ loc n)
→ g (loc n) ≡₀ b₂ → P-b b₂)
(h₁-a-rr : ∀ n {co} (pco : P-a (f $ loc n))
→ h₀-ba n {co a⟦ n ⟧b refl₀} (h₀-ab n {co} pco $ refl₀) refl₀ ≡ pco)
(h₁-b-rr : ∀ n {co} (pco : P-b (g $ loc n))
→ h₀-ab n {co b⟦ n ⟧a refl₀} (h₀-ba n {co} pco $ refl₀) refl₀ ≡ pco)
(h₁-ab-s : ∀ n₁ {co : code-a $ f $ loc n₁} (pco : P-a $ f $ loc n₁) n₂ (r : loc n₁ ≡₀ loc n₂) →
h₀-ba n₂ {co a⟦ n₁ ⟧b ap₀ g r} (h₀-ab n₁ {co} pco $ ap₀ g r) refl₀
≡ h₀-ba n₁ {co a⟦ n₁ ⟧b refl₀} (h₀-ab n₁ {co} pco $ refl₀) (ap₀ f r))
→ (∀ {a₂} (co : code-a a₂) → P-a a₂)
× (∀ {b₂} (co : code-b b₂) → P-b b₂)
code-rec-nondep P-a P-b h₀-a h₀-ba h₀-ab _ _ _ = elim-a , elim-b
where
elim-a : ∀ {a₂} (co : code-a a₂) → P-a a₂
elim-b : ∀ {b₂} (co : code-b b₂) → P-b b₂
elim-a (#a p) = h₀-a p
elim-a (#ba c co p) = h₀-ba c {co} (elim-b co) p
elim-b (#ab c co p) = h₀-ab c {co} (elim-a co) p
module _ where
trans-a : ∀ {y z} (q : y ≡ z) (p : a₁ ≡₀ y)
→ transport code-a q (⟧a p) ≡ ⟧a (p ∘₀ proj q)
trans-a refl p = ap a (! (refl₀-right-unit p))
trans-ba : ∀ {y z} (q : y ≡ z) n co (p : f (loc n) ≡₀ y)
→ transport code-a q (co b⟦ n ⟧a p) ≡ co b⟦ n ⟧a p ∘₀ proj q
trans-ba refl n co p = ap (ba n co) (! (refl₀-right-unit p))
trans-ab : ∀ {y b} (q : y ≡ b) n co (p : g (loc n) ≡₀ y)
→ transport code-b q (co a⟦ n ⟧b p) ≡ co a⟦ n ⟧b p ∘₀ proj q
trans-ab refl n co p = ap (ab n co) (! (refl₀-right-unit p))
module _ where
-- all-paths
abstract
code-has-all-cells₂-a : ∀ {a} {x y : code-a a} (p q : x ≡ y) → p ≡ q
code-has-all-cells₂-a = prop-has-all-paths $ code-a-is-set _ _ _
code-has-all-cells₂-b : ∀ {b} {x y : code-b b} (p q : x ≡ y) → p ≡ q
code-has-all-cells₂-b = prop-has-all-paths $ code-b-is-set _ _ _
code-a-rec : ∀ {j}
(P-a : ∀ {a₂} → code-a a₂ → Set j) ⦃ _ : ∀ {a₂} co → is-set $ P-a {a₂} co ⦄
(h₀-a : ∀ {a₂} (p : _ ≡₀ a₂) → P-a (⟧a p))
(h₀-ba : ∀ {a₂} n co (p : _ ≡₀ a₂)
→ P-a (co b⟦ n ⟧a p))
(h₁-a-rr : ∀ n {co} (pco : P-a co) →
transport (P-a {f $ loc n}) (code-a-refl-refl n co)
(h₀-ba n (co a⟦ n ⟧b refl₀) $ refl₀)
≡ pco)
→ (∀ {a₂} (co : code-a a₂) → P-a co)
code-a-rec {j} P-a ⦃ P-a-is-set ⦄ h₀-a h₀-ba h₁-a-rr = π₁ $ code-rec
P-a ⦃ P-a-is-set ⦄
(λ _ → unit) ⦃ λ _ → unit-is-set ⦄
h₀-a
(λ n {co} _ p → h₀-ba n co p)
(λ _ _ _ → tt)
h₁-a-rr
(λ _ _ → prop-has-all-paths unit-is-prop _ _)
-- FIXME This proof is too ugly.
(λ n₁ {co} (pco : P-a co) n₂ r →
transport (P-a {f $ loc n₂}) (code-ab-swap n₁ co n₂ r)
(h₀-ba n₂ (co a⟦ n₁ ⟧b ap₀ g r) $ refl₀)
≡⟨ ! $ h₁-a-rr n₂ _ ⟩
transport (P-a {f $ loc n₂}) (code-a-refl-refl n₂ _)
(h₀-ba n₂ (_ a⟦ n₂ ⟧b refl₀) $ refl₀)
≡⟨ ap (λ x → transport (P-a {f $ loc n₂}) (code-a-refl-refl n₂ _)
$ h₀-ba n₂ (_ a⟦ n₂ ⟧b refl₀) $ refl₀) $ code-ab-swap n₁ co n₂ r ⟩
transport (P-a {f $ loc n₂}) (code-a-refl-refl n₂ _)
(h₀-ba n₂ (_ a⟦ n₂ ⟧b refl₀) $ refl₀)
≡⟨ h₁-a-rr n₂ _ ⟩∎
h₀-ba n₁ (co a⟦ n₁ ⟧b refl₀) (ap₀ f r)
∎)
code-b-rec : ∀ {j}
(P-b : ∀ {b₂} → code-b b₂ → Set j) ⦃ _ : ∀ {b₂} co → is-set $ P-b {b₂} co ⦄
(h₀-ab : ∀ {b₂} n co (p : _ ≡₀ b₂)
→ P-b (co a⟦ n ⟧b p))
(h₁-b-rr : ∀ n {co} (pco : P-b co) →
transport (P-b {g $ loc n}) (code-b-refl-refl n co)
(h₀-ab n (co b⟦ n ⟧a refl₀) $ refl₀)
≡ pco)
→ (∀ {b₂} (co : code-b b₂) → P-b co)
code-b-rec {j} P-b ⦃ P-b-is-set ⦄ h₀-ab h₁-b-rr = π₂ $ code-rec
(λ _ → unit) ⦃ λ _ → unit-is-set ⦄
P-b ⦃ P-b-is-set ⦄
(λ _ → tt)
(λ _ _ _ → tt)
(λ n {co} _ p → h₀-ab n co p)
(λ _ _ → prop-has-all-paths unit-is-prop _ _)
h₁-b-rr
(λ _ _ _ _ → prop-has-all-paths unit-is-prop _ _)
-- Derived 1-cells.
module _ where
abstract
code-ba-swap : ∀ n₁ co n₂ (r : loc n₁ ≡₀ loc n₂)
→ co b⟦ n₁ ⟧a ap₀ f r a⟦ n₂ ⟧b refl₀
≡ co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b ap₀ g r
code-ba-swap n₁ co n₂ r =
co b⟦ n₁ ⟧a ap₀ f r a⟦ n₂ ⟧b refl₀
≡⟨ ap (λ x → x b⟦ n₁ ⟧a ap₀ f r a⟦ n₂ ⟧b refl₀) $ ! $ code-b-refl-refl n₁ co ⟩
co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a ap₀ f r a⟦ n₂ ⟧b refl₀
≡⟨ ap (λ x → x a⟦ n₂ ⟧b refl₀) $ ! $ code-ab-swap n₁ (co b⟦ n₁ ⟧a refl₀) n₂ r ⟩
co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b ap₀ g r b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b refl₀
≡⟨ code-b-refl-refl n₂ $ co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b ap₀ g r ⟩∎
co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b ap₀ g r
∎
abstract
-- Old (provable) rules.
code-a-merge : ∀ {a₂} n p₁ (p₂ : _ ≡₀ a₂)
→ ⟧a p₁ a⟦ n ⟧b refl₀ b⟦ n ⟧a p₂
≡ ⟧a p₁ ∘₀ p₂
code-a-merge {a₂} n p₁ = π₀-extend
⦃ λ _ → ≡-is-set $ code-a-is-set a₂ ⦄
( λ p₂ →
⟧a p₁ a⟦ n ⟧b refl₀ b⟦ n ⟧a proj p₂
≡⟨ ! $ trans-ba p₂ n (⟧a p₁ a⟦ n ⟧b refl₀) refl₀ ⟩
transport code-a p₂ (⟧a p₁ a⟦ n ⟧b refl₀ b⟦ n ⟧a refl₀)
≡⟨ ap (transport code-a p₂) $ code-a-refl-refl n (⟧a p₁) ⟩
transport code-a p₂ (⟧a p₁)
≡⟨ trans-a p₂ p₁ ⟩∎
⟧a p₁ ∘₀ proj p₂
∎)
abstract
code-ab-merge : ∀ {b₂} n₁ co n₂ p₁ (p₂ : _ ≡₀ b₂)
→ co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b p₂
≡ co a⟦ n₁ ⟧b p₁ ∘₀ p₂
code-ab-merge {b₂} n₁ co n₂ p₁ = π₀-extend
⦃ λ _ → ≡-is-set $ code-b-is-set b₂ ⦄
( λ p₂ →
co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b proj p₂
≡⟨ ! $ trans-ab p₂ n₂ (co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a refl₀) refl₀ ⟩
transport code-b p₂ (co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b refl₀)
≡⟨ ap (transport code-b p₂) $ code-b-refl-refl n₂ (co a⟦ n₁ ⟧b p₁) ⟩
transport code-b p₂ (co a⟦ n₁ ⟧b p₁)
≡⟨ trans-ab p₂ n₁ co p₁ ⟩∎
co a⟦ n₁ ⟧b p₁ ∘₀ proj p₂
∎)
abstract
code-ba-merge : ∀ {a₂} n₁ co n₂ p₁ (p₂ : _ ≡₀ a₂)
→ co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b refl₀ b⟦ n₂ ⟧a p₂
≡ co b⟦ n₁ ⟧a p₁ ∘₀ p₂
code-ba-merge {a₂} n₁ co n₂ p₁ = π₀-extend
⦃ λ _ → ≡-is-set $ code-a-is-set a₂ ⦄
( λ p₂ →
co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b refl₀ b⟦ n₂ ⟧a proj p₂
≡⟨ ! $ trans-ba p₂ n₂ (co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b refl₀) refl₀ ⟩
transport code-a p₂ (co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b refl₀ b⟦ n₂ ⟧a refl₀)
≡⟨ ap (transport code-a p₂) $ code-a-refl-refl n₂ (co b⟦ n₁ ⟧a p₁) ⟩
transport code-a p₂ (co b⟦ n₁ ⟧a p₁)
≡⟨ trans-ba p₂ n₁ co p₁ ⟩∎
co b⟦ n₁ ⟧a p₁ ∘₀ proj p₂
∎)
abstract
code-a-shift : ∀ {b₂} n₁ p₁ n₂ (r : loc n₁ ≡₀ loc n₂) (p₂ : _ ≡₀ b₂)
→ ⟧a p₁ ∘₀ ap₀ f r a⟦ n₂ ⟧b p₂
≡ ⟧a p₁ a⟦ n₁ ⟧b ap₀ g r ∘₀ p₂
code-a-shift n₁ p₁ n₂ r p₂ =
⟧a p₁ ∘₀ ap₀ f r a⟦ n₂ ⟧b p₂
≡⟨ ap (λ x → x a⟦ n₂ ⟧b p₂) $ ! $ code-a-merge n₁ p₁ (ap₀ f r) ⟩
⟧a p₁ a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a ap₀ f r a⟦ n₂ ⟧b p₂
≡⟨ ap (λ x → x a⟦ n₂ ⟧b p₂) $ ! $ code-ab-swap n₁ (⟧a p₁) n₂ r ⟩
⟧a p₁ a⟦ n₁ ⟧b ap₀ g r b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b p₂
≡⟨ code-ab-merge n₁ (⟧a p₁) n₂ (ap₀ g r) p₂ ⟩∎
⟧a p₁ a⟦ n₁ ⟧b ap₀ g r ∘₀ p₂
∎
abstract
code-ba-shift : ∀ {b₂} n₁ co n₂ p₁ n₃ (r : loc n₂ ≡₀ loc n₃) (p₂ : _ ≡₀ b₂)
→ co b⟦ n₁ ⟧a p₁ ∘₀ ap₀ f r a⟦ n₃ ⟧b p₂
≡ co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b ap₀ g r ∘₀ p₂
code-ba-shift n₁ co n₂ p₁ n₃ r p₂ =
co b⟦ n₁ ⟧a p₁ ∘₀ ap₀ f r a⟦ n₃ ⟧b p₂
≡⟨ ap (λ x → x a⟦ n₃ ⟧b p₂) $ ! $ code-ba-merge n₁ co n₂ p₁ (ap₀ f r) ⟩
co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b refl₀ b⟦ n₂ ⟧a ap₀ f r a⟦ n₃ ⟧b p₂
≡⟨ ap (λ x → x a⟦ n₃ ⟧b p₂) $ ! $ code-ab-swap n₂ (co b⟦ n₁ ⟧a p₁) n₃ r ⟩
co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b ap₀ g r b⟦ n₃ ⟧a refl₀ a⟦ n₃ ⟧b p₂
≡⟨ code-ab-merge n₂ (co b⟦ n₁ ⟧a p₁) n₃ (ap₀ g r) p₂ ⟩∎
co b⟦ n₁ ⟧a p₁ a⟦ n₂ ⟧b ap₀ g r ∘₀ p₂
∎
abstract
code-ab-shift : ∀ {a₂} n₁ co n₂ p₁ n₃ (r : loc n₂ ≡₀ loc n₃) (p₂ : _ ≡₀ a₂)
→ co a⟦ n₁ ⟧b p₁ ∘₀ ap₀ g r b⟦ n₃ ⟧a p₂
≡ co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a ap₀ f r ∘₀ p₂
code-ab-shift n₁ co n₂ p₁ n₃ r p₂ =
co a⟦ n₁ ⟧b p₁ ∘₀ ap₀ g r b⟦ n₃ ⟧a p₂
≡⟨ ap (λ x → x b⟦ n₃ ⟧a p₂) $ ! $ code-ab-merge n₁ co n₂ p₁ (ap₀ g r) ⟩
co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a refl₀ a⟦ n₂ ⟧b ap₀ g r b⟦ n₃ ⟧a p₂
≡⟨ ap (λ x → x b⟦ n₃ ⟧a p₂) $ ! $ code-ba-swap n₂ (co a⟦ n₁ ⟧b p₁) n₃ r ⟩
co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a ap₀ f r a⟦ n₃ ⟧b refl₀ b⟦ n₃ ⟧a p₂
≡⟨ code-ba-merge n₂ (co a⟦ n₁ ⟧b p₁) n₃ (ap₀ f r) p₂ ⟩∎
co a⟦ n₁ ⟧b p₁ b⟦ n₂ ⟧a ap₀ f r ∘₀ p₂
∎
-- Definition of code
module _ where
P : Set i
P = pushout d
-- Basic conversion
a⇒b : ∀ n → code-a (f $ loc n) → code-b (g $ loc n)
a⇒b n co = co a⟦ n ⟧b refl₀
b⇒a : ∀ n → code-b (g $ loc n) → code-a (f $ loc n)
b⇒a n co = co b⟦ n ⟧a refl₀
private
-- The head of the code
code-glue-eq-loc : ∀ n → code-a (f $ loc n) ≃ code-b (g $ loc n)
code-glue-eq-loc n = a⇒b n ,
iso-is-eq (a⇒b n) (b⇒a n) (code-b-refl-refl n) (code-a-refl-refl n)
abstract
trans-code-a-r : ∀ n₁ n₂ (r : loc n₁ ≡ loc n₂) (co : code-a $ f $ loc n₁)
→ transport (code-a ◯ f) r co ≡ co a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a proj (ap f r)
trans-code-a-r n₁ n₂ r co =
transport (code-a ◯ f) r co
≡⟨ ! $ trans-ap code-a f r co ⟩
transport code-a (ap f r) co
≡⟨ ap (transport code-a $ ap f r) $ ! $ code-a-refl-refl n₁ co ⟩
transport code-a (ap f r) (co a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a refl₀)
≡⟨ trans-ba (ap f r) n₁ _ refl₀ ⟩∎
co a⟦ n₁ ⟧b refl₀ b⟦ n₁ ⟧a proj (ap f r)
∎
abstract
trans-code-b-r : ∀ n₁ n₂ (r : loc n₁ ≡ loc n₂) (co : code-b $ g $ loc n₁)
→ transport (code-b ◯ g) r co ≡ co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b proj (ap g r)
trans-code-b-r n₁ n₂ r co =
transport (code-b ◯ g) r co
≡⟨ ! $ trans-ap code-b g r co ⟩
transport code-b (ap g r) co
≡⟨ ap (transport code-b $ ap g r) $ ! $ code-b-refl-refl n₁ co ⟩
transport code-b (ap g r) (co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b refl₀)
≡⟨ trans-ab (ap g r) n₁ _ refl₀ ⟩∎
co b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b proj (ap g r)
∎
private
abstract
code-glue-eq-route : ∀ n₁ n₂ r
→ transport (λ c → code-a (f c) ≃ code-b (g c)) r (code-glue-eq-loc n₁)
≡ code-glue-eq-loc n₂
code-glue-eq-route n₁ n₂ r = equiv-eq $ funext λ co →
π₁ (transport (λ c → code-a (f c) ≃ code-b (g c)) r (code-glue-eq-loc n₁)) co
≡⟨ ap (λ x → x co) $ app-trans
(λ c → code-a (f c) ≃ code-b (g c))
(λ c → code-a (f c) → code-b (g c))
(λ _ → π₁) r (code-glue-eq-loc n₁) ⟩
transport (λ c → code-a (f c) → code-b (g c)) r (a⇒b n₁) co
≡⟨ trans-→ (code-a ◯ f) (code-b ◯ g) r (a⇒b n₁) co ⟩
transport (code-b ◯ g) r (a⇒b n₁ $ transport (code-a ◯ f) (! r) co)
≡⟨ ap (transport (code-b ◯ g) r ◯ a⇒b n₁) $ trans-code-a-r _ _ (! r) co ⟩
transport (code-b ◯ g) r (co a⟦ n₂ ⟧b refl₀ b⟦ n₂ ⟧a proj (ap f $ ! r) a⟦ n₁ ⟧b refl₀)
≡⟨ ap (λ x → transport (code-b ◯ g) r $ x a⟦ n₁ ⟧b refl₀) $ ! $ code-ab-swap _ co _ (proj $ ! r) ⟩
transport (code-b ◯ g) r (co a⟦ n₂ ⟧b proj (ap g $ ! r) b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b refl₀)
≡⟨ ap (transport (code-b ◯ g) r) $ code-b-refl-refl n₁ _ ⟩
transport (code-b ◯ g) r (co a⟦ n₂ ⟧b proj (ap g $ ! r))
≡⟨ trans-code-b-r _ _ r _ ⟩
co a⟦ n₂ ⟧b proj (ap g $ ! r) b⟦ n₁ ⟧a refl₀ a⟦ n₁ ⟧b proj (ap g r)
≡⟨ code-ab-merge n₂ co n₁ _ _ ⟩
co a⟦ n₂ ⟧b proj (ap g (! r) ∘ ap g r)
≡⟨ ap (λ x → co a⟦ n₂ ⟧b proj x) $ concat-ap g (! r) r ⟩
co a⟦ n₂ ⟧b proj (ap g $ ! r ∘ r)
≡⟨ ap (λ x → co a⟦ n₂ ⟧b proj (ap g x)) $ opposite-left-inverse r ⟩∎
a⇒b n₂ co
∎
private
code-glue-eq : ∀ c → code-a (f c) ≃ code-b (g c)
code-glue-eq = visit-fiber-rec l
(λ c → code-a (f c) ≃ code-b (g c))
⦃ λ _ → ≃-is-set (code-a-is-set _) (code-b-is-set _) ⦄
code-glue-eq-loc
code-glue-eq-route
-- The data type!
code : P → Set i
code = pushout-rec-nondep (Set i) code-a code-b (eq-to-path ◯ code-glue-eq)
-- Useful lemma
abstract
trans-code-glue-loc : ∀ n₂ co → transport code (glue $ loc n₂) co ≡ a⇒b n₂ co
trans-code-glue-loc n₂ co =
transport code (glue $ loc n₂) co
≡⟨ ! $ trans-ap (λ X → X) code (glue $ loc n₂) co ⟩
transport (λ X → X) (ap code $ glue $ loc n₂) co
≡⟨ ap (λ x → transport (λ X → X) x co)
$ pushout-β-glue-nondep (Set i) code-a code-b (eq-to-path ◯ code-glue-eq) (loc n₂) ⟩
transport (λ X → X) (eq-to-path $ code-glue-eq $ loc n₂) co
≡⟨ ap (λ x → transport (λ X → X) (eq-to-path x) co)
$ visit-fiber-β-loc l
(λ c → code-a (f c) ≃ code-b (g c))
⦃ λ _ → ≃-is-set (code-a-is-set _) (code-b-is-set _) ⦄
code-glue-eq-loc
code-glue-eq-route
n₂ ⟩
transport (λ X → X) (eq-to-path $ code-glue-eq-loc n₂) co
≡⟨ trans-id-eq-to-path (code-glue-eq-loc n₂) co ⟩∎
a⇒b n₂ co
∎
abstract
trans-code-!glue-loc : ∀ n₂ co → transport code (! $ glue $ loc n₂) co ≡ b⇒a n₂ co
trans-code-!glue-loc n₂ co = move!-transp-right code (glue $ loc n₂) co (b⇒a n₂ co) $ ! $
transport code (glue $ loc n₂) (b⇒a n₂ co)
≡⟨ trans-code-glue-loc n₂ (b⇒a n₂ co) ⟩
a⇒b n₂ (b⇒a n₂ co)
≡⟨ code-b-refl-refl n₂ co ⟩∎
co
∎
-- Truncation level
abstract
code-is-set : ∀ p → is-set $ code p
code-is-set = pushout-rec
(λ p → is-set $ code p)
code-a-is-set
code-b-is-set
(λ _ → prop-has-all-paths is-set-is-prop _ _)
| {
"alphanum_fraction": 0.4499697786,
"avg_line_length": 41.9331797235,
"ext": "agda",
"hexsha": "f2dd1ca0c3be7a01e26e905fb6eaf42e31eff17d",
"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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/VanKampen/SplitCode.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"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": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/VanKampen/SplitCode.agda",
"max_line_length": 112,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/VanKampen/SplitCode.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": 8272,
"size": 18199
} |
open import Oscar.Prelude
open import Oscar.Class.IsEquivalence
module Oscar.Class.Setoid where
record Setoid 𝔬 ℓ : Ø ↑̂ (𝔬 ∙̂ ℓ) where
constructor ∁
field
{Object} : Ø 𝔬
ObjectEquivalence : Object → Object → Ø ℓ
⦃ `IsEquivalence ⦄ : IsEquivalence ObjectEquivalence
| {
"alphanum_fraction": 0.7087719298,
"avg_line_length": 21.9230769231,
"ext": "agda",
"hexsha": "64ad08d09ac011f3739e12f7ef7092e50ee66055",
"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/Setoid.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/Setoid.agda",
"max_line_length": 56,
"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/Setoid.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 98,
"size": 285
} |
module Issue4267.B where
open import Issue4267.A0
postulate
X : Set
-- Crucial for bug: omitting signature of ra,
-- letting Agda infer its type.
ra = record {A = X}
| {
"alphanum_fraction": 0.7134502924,
"avg_line_length": 15.5454545455,
"ext": "agda",
"hexsha": "c8f0f529a7afc099fd1f246452eda535cf146ee8",
"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/Issue4267/B.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue4267/B.agda",
"max_line_length": 45,
"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/Issue4267/B.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 51,
"size": 171
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.elims.SuspSmash
open import homotopy.elims.CofPushoutSection
-- Σ(X∧Y) ≃ X * Y
module homotopy.SuspSmash {i j} (X : Ptd i) (Y : Ptd j) where
private
{- path lemmas -}
private
reduce-x : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : z == y)
→ p ∙ ! q ∙ q ∙ ! p ∙ p == p
reduce-x idp idp = idp
reduce-y : ∀ {i} {A : Type i} {x y z : A} (p : x == y) (q : x == z)
→ p ∙ ! p ∙ q ∙ ! q ∙ p == p
reduce-y idp idp = idp
module Into = SuspensionRec {A = Smash X Y}
{C = fst (X ⊙* Y)}
(left (snd X))
(right (snd Y))
(CofPushoutSection.rec (λ _ → tt) (λ _ → idp)
(glue (snd X , snd Y))
(λ {(x , y) →
glue (snd X , snd Y) ∙ ! (glue (x , snd Y))
∙ glue (x , y)
∙ ! (glue (snd X , y)) ∙ glue (snd X , snd Y)})
(λ x → ! (reduce-x (glue (snd X , snd Y)) (glue (x , snd Y))))
(λ y → ! (reduce-y (glue (snd X , snd Y)) (glue (snd X , y)))))
into = Into.f
module Out = PushoutRec {d = ⊙span-out (*-⊙span X Y)}
{D = Suspension (Smash X Y)}
(λ _ → north)
(λ _ → south)
(λ {(x , y) → merid (cfcod (x , y))})
out = Out.f
into-out : (j : fst (X ⊙* Y)) → into (out j) == j
into-out = Pushout-elim
(λ x → glue (snd X , snd Y) ∙ ! (glue (x , snd Y)))
(λ y → ! (glue (snd X , snd Y)) ∙ glue (snd X , y))
(↓-∘=idf-from-square into out ∘ λ {(x , y) →
(ap (ap into) (Out.glue-β (x , y))
∙ Into.merid-β (cfcod (x , y)))
∙v⊡ lemma (glue (snd X , snd Y)) (glue (x , snd Y))
(glue (snd X , y)) (glue (x , y))})
where
lemma : ∀ {i} {A : Type i} {x y z w : A}
(p : x == y) (q : z == y) (r : x == w) (s : z == w)
→ Square (p ∙ ! q) (p ∙ ! q ∙ s ∙ ! r ∙ p) s (! p ∙ r)
lemma idp idp idp s =
vert-degen-square (∙-unit-r s)
out-into : (σ : Suspension (Smash X Y)) → out (into σ) == σ
out-into = susp-smash-elim
idp
idp
(↓-∘=idf-in out into ∘ λ {(x , y) →
ap (ap out) (Into.merid-β (cfcod (x , y)))
∙ lemma₁ out (Out.glue-β (snd X , snd Y))
(Out.glue-β (x , snd Y))
(Out.glue-β (x , y))
(Out.glue-β (snd X , y))
(Out.glue-β (snd X , snd Y))
∙ lemma₂ {p = merid (cfcod (snd X , snd Y))}
{q = merid (cfcod (x , snd Y))}
{r = merid (cfcod (x , y))}
{s = merid (cfcod (snd X , y))}
{t = merid (cfcod (snd X , snd Y))}
(ap merid (! (cfglue (winl (snd X))) ∙ cfglue (winl x)))
(ap merid (! (cfglue (winr y)) ∙ cfglue (winr (snd Y))))})
where
lemma₁ : ∀ {i j} {A : Type i} {B : Type j} (f : A → B)
{x y z u v w : A}
{p : x == y} {q : z == y} {r : z == u} {s : v == u} {t : v == w}
{p' : f x == f y} {q' : f z == f y} {r' : f z == f u}
{s' : f v == f u} {t' : f v == f w}
(α : ap f p == p') (β : ap f q == q') (γ : ap f r == r')
(δ : ap f s == s') (ε : ap f t == t')
→ ap f (p ∙ ! q ∙ r ∙ ! s ∙ t) == p' ∙ ! q' ∙ r' ∙ ! s' ∙ t'
lemma₁ f {p = idp} {q = idp} {r = idp} {s = idp} {t = idp}
idp idp idp idp idp
= idp
lemma₂ : ∀ {i} {A : Type i} {x y z u : A}
{p q : x == y} {r : x == z} {s t : u == z}
(α : p == q) (β : s == t)
→ p ∙ ! q ∙ r ∙ ! s ∙ t == r
lemma₂ {p = idp} {r = idp} {s = idp} idp idp = idp
module SuspSmash where
eq : Suspension (Smash X Y) ≃ fst (X ⊙* Y)
eq = equiv into out into-out out-into
path : Suspension (Smash X Y) == fst (X ⊙* Y)
path = ua eq
⊙path : ⊙Susp (⊙Smash X Y) == (X ⊙* Y)
⊙path = ⊙ua (⊙≃-in eq idp)
| {
"alphanum_fraction": 0.4173249796,
"avg_line_length": 33.3727272727,
"ext": "agda",
"hexsha": "bc789bba780c38588b77707d5abe8bc061db7805",
"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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/SuspSmash.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"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": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/SuspSmash.agda",
"max_line_length": 71,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/SuspSmash.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1577,
"size": 3671
} |
open import MJ.Types
import MJ.Classtable.Core as Core
module MJ.Syntax.Erase {c}(Ct : Core.Classtable c) where
open import Prelude hiding (erase)
open import Data.Maybe as Maybe using (Maybe; just; nothing)
open import Data.Maybe.All as MayAll
open import Data.Vec as Vec hiding (_∈_)
open import Data.Star as Star
open import Data.List.Most as List
open import Data.List.Properties.Extra as List+
open import Relation.Binary.PropositionalEquality
open import Relation.Nullary.Decidable
open import Data.String
import Data.Vec.All as Vec∀
open Core c
open Classtable Ct
open import MJ.Classtable.Membership Ct
open import MJ.Classtable.Code Ct
open import MJ.LexicalScope Ct
open import MJ.Syntax.Typed Ct
open import MJ.Syntax.Program Ct
import MJ.Syntax.Untyped Ct as AST
{-# TERMINATING #-}
erase-expr : ∀ {Γ a} → Expr Γ a → AST.Expr (length Γ)
erase-expr (new C x) = AST.new C (List.erase erase-expr x)
erase-expr unit = AST.unit
erase-expr null = AST.null
erase-expr (num x) = AST.num x
erase-expr (iop x e e₁) = AST.iop x (erase-expr e) (erase-expr e₁)
erase-expr (call e m x) = AST.call (erase-expr e) m (List.erase erase-expr x)
erase-expr (var x) = AST.var (index x)
erase-expr (get e f) = AST.get (erase-expr e) f
erase-expr (upcast s e) = erase-expr e
mutual
erase-stmt : ∀ {I r O} → Stmt I r O → AST.Stmt (length I) (length O)
erase-stmt (loc a) = AST.loc a
erase-stmt (asgn x e) = AST.asgn (index x) (erase-expr e)
erase-stmt (set x f e) = AST.set (erase-expr x) f (erase-expr e)
erase-stmt (do x) = AST.do (erase-expr x)
erase-stmt (ret x) = AST.ret (erase-expr x)
erase-stmt raise = AST.raise
erase-stmt (try s catch s₁) = AST.try erase-stmt s catch erase-stmt s₁
erase-stmt (while x do s) = AST.while erase-expr x do erase-stmt s
erase-stmt (block x) = AST.block (erase-stmts x)
-- this is an instance of Star.gmap, but the higher order version
-- fails to pass the termination checker
erase-stmts : ∀ {I r O} → Stmts I r O → AST.Stmts (length I) (length O)
erase-stmts ε = ε
erase-stmts (x ◅ st) = erase-stmt x ◅ erase-stmts st
erase-body : ∀ {I a} → Body I a → AST.Body (length I)
erase-body (body s* e) = AST.body (erase-stmts s*) (erase-expr e)
erase-constructor : ∀ {cid} → Constructor cid → AST.Constructor (length (Class.constr (Σ cid)))
erase-constructor (super args then b) = AST.super (List.erase erase-expr args) then (erase-body b)
erase-constructor (body x) = AST.body (erase-body x)
erase-method : ∀ {cid m as b} → Method cid m (as , b) → AST.Method (length as)
erase-method (super _ ⟨ args ⟩then b) = AST.super⟨ List.erase erase-expr args ⟩then (erase-body b)
erase-method (body x) = AST.body (erase-body x)
erase-implementation : ∀ {cid} → Implementation cid → AST.Implementation cid
erase-implementation (implementation construct mbodies) =
AST.implementation (erase-constructor construct) (map-all erase-method mbodies)
erase-prog : ∀ {a} → Prog a → AST.Prog
erase-prog (ℂ , b) = (λ cid → erase-implementation (ℂ cid)) , erase-body b
| {
"alphanum_fraction": 0.7059409227,
"avg_line_length": 40.1733333333,
"ext": "agda",
"hexsha": "fef6c4928d99b5c62493a8c759fae6f2426e1a2e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:38:05.000Z",
"max_forks_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "metaborg/mj.agda",
"max_forks_repo_path": "src/MJ/Syntax/Erase.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_issues_repo_issues_event_max_datetime": "2020-10-14T13:41:58.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:03:47.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "metaborg/mj.agda",
"max_issues_repo_path": "src/MJ/Syntax/Erase.agda",
"max_line_length": 98,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "0c096fea1716d714db0ff204ef2a9450b7a816df",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "metaborg/mj.agda",
"max_stars_repo_path": "src/MJ/Syntax/Erase.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-24T08:02:33.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-11-17T17:10:36.000Z",
"num_tokens": 930,
"size": 3013
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- This module is DEPRECATED. Please use Data.Vec.Recursive.Categorical
-- instead.
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.Product.N-ary.Categorical where
{-# WARNING_ON_IMPORT
"Data.Product.N-ary.Categorical was deprecated in v1.1.
Use Data.Vec.Recursive.Categorical instead."
#-}
open import Data.Vec.Recursive.Categorical public
| {
"alphanum_fraction": 0.5440613027,
"avg_line_length": 29,
"ext": "agda",
"hexsha": "8eccfc9ccb0dda594fef41a74a1812c198f1dadd",
"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/Product/N-ary/Categorical.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/Product/N-ary/Categorical.agda",
"max_line_length": 72,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/Product/N-ary/Categorical.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": 95,
"size": 522
} |
{-# OPTIONS --safe #-}
{- A typeclass for converting between type disciplines #-}
module CF.Transform.Compile.ToJVM where
open import Level
open import Function
open import Data.Product as P
open import Data.List as L
open import Data.List.Properties as LP
open import Data.List.Membership.Propositional
open import Data.List.Membership.Propositional.Properties
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Morphisms
open import CF.Types as CF
open import CF.Contexts.Lexical
open import JVM.Types as JVM
record To {l r} (L : Set l) (R : Set r) : Set (l ⊔ r) where
field
⟦_⟧ : L → R
open To {{...}} public
instance ⟦⟧-list : ∀ {a} {A B : Set a} {{_ : To A B}} → To (List A) (List B)
To.⟦_⟧ ⟦⟧-list = L.map ⟦_⟧
instance ⟦⟧-prod : ∀ {a} {A B C D : Set a} {{_ : To A B}} {{_ : To C D}} → To (A × C) (B × D)
To.⟦_⟧ ⟦⟧-prod = P.map ⟦_⟧ ⟦_⟧
instance cfToJvm-ty : To CF.Ty JVM.Ty
To.⟦_⟧ cfToJvm-ty = ‵_
where
‵_ : CF.Ty → JVM.Ty
‵ void = boolean
‵ int = int
‵ bool = boolean
instance cfToJvm-var : ∀ {ℓ} {A B : Set ℓ} {{_ : To A B}} {a : A} {as} →
To (a ∈ as) (⟦ a ⟧ ∈ ⟦ as ⟧)
To.⟦_⟧ cfToJvm-var = ∈-map⁺ ⟦_⟧
private
module _ {t} {T : Set t} where
open import JVM.Model T public
instance on-intf : ∀ {ℓ} {A B : Set ℓ} {{_ : To A B}} → To (Intf {T = A}) (Intf {T = B})
To.⟦ on-intf ⟧ (u ⇅ d) = ⟦ u ⟧ ⇅ ⟦ d ⟧
| {
"alphanum_fraction": 0.5951532431,
"avg_line_length": 28.06,
"ext": "agda",
"hexsha": "3d4f37abb4010a392a951db94d99f6d572433c24",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/CF/Transform/Compile/ToJVM.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"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": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/CF/Transform/Compile/ToJVM.agda",
"max_line_length": 93,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/CF/Transform/Compile/ToJVM.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 545,
"size": 1403
} |
------------------------------------------------------------------------------
-- Arithmetic properties used by the McCarthy 91 function
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOTC.Program.McCarthy91.ArithmeticATP where
open import FOTC.Base
open import FOTC.Data.Nat
open import FOTC.Data.Nat.Inequalities
open import FOTC.Data.Nat.Inequalities.PropertiesATP
using ( x≤y+x∸y
; x≤y→x≯y
; x≤y→x+k≤y+k
)
open import FOTC.Data.Nat.PropertiesATP
using ( +-N
; ∸-N
; +-comm
; [x+Sy]∸y≡Sx
)
open import FOTC.Data.Nat.UnaryNumbers
open import FOTC.Data.Nat.UnaryNumbers.TotalityATP
using ( 10-N
; 11-N
; 89-N
; 100-N
)
------------------------------------------------------------------------------
postulate 91≡100+11∸10∸10 : 91' ≡ 100' + 11' ∸ 10' ∸ 10'
{-# ATP prove 91≡100+11∸10∸10 #-}
postulate
100≡89+11 : 100' ≡ 89' + 11'
101≡90+11 : 101' ≡ 90' + 11'
102≡91+11 : 102' ≡ 91' + 11'
103≡92+11 : 103' ≡ 92' + 11'
104≡93+11 : 104' ≡ 93' + 11'
105≡94+11 : 105' ≡ 94' + 11'
106≡95+11 : 106' ≡ 95' + 11'
107≡96+11 : 107' ≡ 96' + 11'
108≡97+11 : 108' ≡ 97' + 11'
109≡98+11 : 109' ≡ 98' + 11'
110≡99+11 : 110' ≡ 99' + 11'
111≡100+11 : 111' ≡ 100' + 11'
{-# ATP prove 100≡89+11 #-}
{-# ATP prove 101≡90+11 #-}
{-# ATP prove 102≡91+11 #-}
{-# ATP prove 103≡92+11 #-}
{-# ATP prove 104≡93+11 #-}
{-# ATP prove 105≡94+11 #-}
{-# ATP prove 106≡95+11 #-}
{-# ATP prove 107≡96+11 #-}
{-# ATP prove 108≡97+11 #-}
{-# ATP prove 109≡98+11 #-}
{-# ATP prove 110≡99+11 #-}
{-# ATP prove 111≡100+11 #-}
postulate 101≡100+11∸10 : 101' ≡ 100' + 11' ∸ 10'
{-# ATP prove 101≡100+11∸10 #-}
postulate
100+11∸10>100 : 100' + 11' ∸ 10' > 100'
100+11>100 : 100' + 11' > 100'
{-# ATP prove 100+11∸10>100 101≡100+11∸10 #-}
{-# ATP prove 100+11>100 111≡100+11 #-}
postulate
99+11>100 : 99' + 11' > 100'
98+11>100 : 98' + 11' > 100'
97+11>100 : 97' + 11' > 100'
96+11>100 : 96' + 11' > 100'
95+11>100 : 95' + 11' > 100'
94+11>100 : 94' + 11' > 100'
93+11>100 : 93' + 11' > 100'
92+11>100 : 92' + 11' > 100'
91+11>100 : 91' + 11' > 100'
90+11>100 : 90' + 11' > 100'
{-# ATP prove 99+11>100 110≡99+11 #-}
{-# ATP prove 98+11>100 109≡98+11 #-}
{-# ATP prove 97+11>100 108≡97+11 #-}
{-# ATP prove 96+11>100 107≡96+11 #-}
{-# ATP prove 95+11>100 106≡95+11 #-}
{-# ATP prove 94+11>100 105≡94+11 #-}
{-# ATP prove 93+11>100 104≡93+11 #-}
{-# ATP prove 92+11>100 103≡92+11 #-}
{-# ATP prove 91+11>100 102≡91+11 #-}
{-# ATP prove 90+11>100 101≡90+11 #-}
x+11-N : ∀ {n} → N n → N (n + 11')
x+11-N Nn = +-N Nn 11-N
x+11∸10≡Sx : ∀ {n} → N n → n + 11' ∸ 10' ≡ succ₁ n
x+11∸10≡Sx Nn = [x+Sy]∸y≡Sx Nn 10-N
postulate x+1≤x∸10+11 : ∀ {n} → N n → n + 1' ≤ (n ∸ 10') + 11'
{-# ATP prove x+1≤x∸10+11 x≤y+x∸y 10-N 11-N +-N ∸-N +-comm #-}
postulate x≤89→x+11≯100 : ∀ {n} → N n → n ≤ 89' → n + 11' ≯ 100'
{-# ATP prove x≤89→x+11≯100 x≤y→x≯y x≤y→x+k≤y+k x+11-N 89-N 100-N 100≡89+11 #-}
| {
"alphanum_fraction": 0.4889717304,
"avg_line_length": 30.0841121495,
"ext": "agda",
"hexsha": "00dd8bab4c26ba465e87022aca8a275bf6987657",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/FOTC/Program/McCarthy91/ArithmeticATP.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/FOTC/Program/McCarthy91/ArithmeticATP.agda",
"max_line_length": 79,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/FOTC/Program/McCarthy91/ArithmeticATP.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": 1467,
"size": 3219
} |
{-
This second-order signature was created from the following second-order syntax description:
syntax CTLC | ΛC
type
N : 0-ary
_↣_ : 2-ary | r30
¬_ : 1-ary | r30
term
app : α ↣ β α -> β | _$_ l20
lam : α.β -> α ↣ β | ƛ_ r10
throw : α ¬ α -> β
callcc : ¬ α.α -> α
theory
(ƛβ) b : α.β a : α |> app (lam(x.b[x]), a) = b[a]
(ƛη) f : α ↣ β |> lam (x. app(f, x)) = f
-}
module CTLC.Signature where
open import SOAS.Context
-- Type declaration
data ΛCT : Set where
N : ΛCT
_↣_ : ΛCT → ΛCT → ΛCT
¬_ : ΛCT → ΛCT
infixr 30 _↣_
infixr 30 ¬_
open import SOAS.Syntax.Signature ΛCT public
open import SOAS.Syntax.Build ΛCT public
-- Operator symbols
data ΛCₒ : Set where
appₒ lamₒ throwₒ : {α β : ΛCT} → ΛCₒ
callccₒ : {α : ΛCT} → ΛCₒ
-- Term signature
ΛC:Sig : Signature ΛCₒ
ΛC:Sig = sig λ
{ (appₒ {α}{β}) → (⊢₀ α ↣ β) , (⊢₀ α) ⟼₂ β
; (lamₒ {α}{β}) → (α ⊢₁ β) ⟼₁ α ↣ β
; (throwₒ {α}{β}) → (⊢₀ α) , (⊢₀ ¬ α) ⟼₂ β
; (callccₒ {α}) → (¬ α ⊢₁ α) ⟼₁ α
}
open Signature ΛC:Sig public
| {
"alphanum_fraction": 0.5407969639,
"avg_line_length": 19.8867924528,
"ext": "agda",
"hexsha": "d5e083a5fb66f3048f61e64b90b310f072f5ad64",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2022-01-24T12:49:17.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-09T20:39:59.000Z",
"max_forks_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "JoeyEremondi/agda-soas",
"max_forks_repo_path": "out/CTLC/Signature.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_issues_repo_issues_event_max_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-11-21T12:19:32.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "JoeyEremondi/agda-soas",
"max_issues_repo_path": "out/CTLC/Signature.agda",
"max_line_length": 91,
"max_stars_count": 39,
"max_stars_repo_head_hexsha": "ff1a985a6be9b780d3ba2beff68e902394f0a9d8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "JoeyEremondi/agda-soas",
"max_stars_repo_path": "out/CTLC/Signature.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-19T17:33:12.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-11-09T20:39:55.000Z",
"num_tokens": 516,
"size": 1054
} |
open import DeBruijn
infix 8 _*
_* : ∀ {n} → Term n → Term n
(# x) * = # x
(ƛ M) * = ƛ M *
((ƛ M) · N) * = M * [ N * ]
(L · N) * = L * · N *
| {
"alphanum_fraction": 0.325,
"avg_line_length": 14.5454545455,
"ext": "agda",
"hexsha": "69cc855453bdea0440411b5bef3835c02cfe06bb",
"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": "Takahashi.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": "Takahashi.agda",
"max_line_length": 28,
"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": "Takahashi.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": 76,
"size": 160
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.NType2
open import lib.PathFunctor
open import lib.PathGroupoid
open import lib.types.Bool
open import lib.types.IteratedSuspension
open import lib.types.LoopSpace
open import lib.types.Nat
open import lib.types.Paths
open import lib.types.Pi
open import lib.types.Pointed
open import lib.types.Sigma
open import lib.types.Suspension
open import lib.types.TLevel
open import lib.types.Unit
open import nicolai.pseudotruncations.Preliminary-definitions
open import nicolai.pseudotruncations.Liblemmas
open import nicolai.pseudotruncations.SeqColim
open import nicolai.pseudotruncations.wconstSequence
module nicolai.pseudotruncations.PseudoTruncs where
{- Definition of the Pseudo-truncation -}
module _ {i} where
private
data #Pseudotrunc-aux (n : ℕ) (A : Type i) : Type i where
#point : A → #Pseudotrunc-aux n A
#hub : (r : Sphere' n → A) → #Pseudotrunc-aux n A
data #Pseudotrunc (n : ℕ) (A : Type i) : Type i where
#trick-aux : #Pseudotrunc-aux n A → (Unit → Unit) → #Pseudotrunc n A
Pseudo_-1-trunc : (n : ℕ) (A : Type i) → Type i
Pseudo_-1-trunc = #Pseudotrunc
point_-1 : {A : Type i} → (n : ℕ) → A → Pseudo n -1-trunc A
point_-1 {A} n a = #trick-aux (#point a) _
hub_-1 : {A : Type i} (n : ℕ) (r : Sphere' n → A) → Pseudo n -1-trunc A
hub_-1 {A} n r = #trick-aux (#hub r) _
postulate
spoke_-1 : {A : Type i} (n : ℕ) (r : Sphere' n → A) (x : Sphere' n)
→ point n -1 (r x) == hub n -1 r
{- The induction principle -}
module PseudotruncInduction
{A : Type i} (n : ℕ) {j}
{P : Pseudo n -1-trunc A → Type j}
(Point-1 : (a : A) → P (point n -1 a))
(Hub-1 : (r : Sphere' n → A) → P (hub n -1 r))
(Spoke-1 : (r : Sphere' n → A) → (x : Sphere' n)
→ Point-1 (r x) == Hub-1 r [ P ↓ spoke n -1 r x ])
where
f : Π (Pseudo n -1-trunc A) P
f = f-aux phantom where
f-aux : Phantom Spoke-1 → Π (Pseudo n -1-trunc A) P
f-aux phantom (#trick-aux (#point x) _) = Point-1 x
f-aux phantom (#trick-aux (#hub r) _) = Hub-1 r
postulate
pathβ : (r : Sphere' {i} n → A)
→ (x : Sphere' {i} n)
→ apd f (spoke n -1 r x) == Spoke-1 r x
open PseudotruncInduction public renaming
(f to Pseudotrunc-ind ; pathβ to Pseudotrunc-ind-pathβ)
{- We derive the recursion principle from the induction principle -}
module PseudotruncRecursion
{i j} {A : Type i}
{P : Type j} (n : ℕ)
(Point-1 : A → P)
(Hub-1 : (r : Sphere' {i} n → A) → P)
(Spoke-1 : (r : Sphere' n → A) (x : Sphere' n) → Point-1 (r x) == Hub-1 r)
where
rec : Pseudo n -1-trunc A → P
rec = Pseudotrunc-ind n {P = λ _ → P} Point-1 Hub-1
(λ r x → from-transp
(λ _ → P)
(spoke n -1 r x)
((transport (λ _ → P) (spoke n -1 r x) (Point-1 (r x)))
=⟨ transport-const-fam (spoke n -1 r x) (Point-1 (r x)) ⟩
Point-1 (r x)
=⟨ Spoke-1 r x ⟩
Hub-1 r
∎))
open PseudotruncRecursion public renaming (rec to Pseudotrunc-rec)
{- A lemma that will be important later: any map from
the sphere, composed with the points constructor,
is null. -}
open import nicolai.pseudotruncations.pointed-O-Sphere
open import nicolai.pseudotruncations.LoopsAndSpheres
open null
module _ {i} {A : Type i} (n : ℕ) where
from-sphere-null : (g : Sphere' {i} n → A)
→ isNull (point n -1 (g (nor' n))) ((point n -1) ∘ g)
from-sphere-null g x = point n -1 (g x)
=⟨ spoke n -1 g x ⟩
hub n -1 g
=⟨ ! (spoke n -1 g (nor' n)) ⟩
point n -1 (g (nor' n))
∎
module cmp-nll {i} {Â : Ptd i} (n : ℕ) (g : ⊙Sphere' {i} n →̇ Â) where
{- Pointed version of first constructor -}
-- points∙ : Â →̇ (Pseudo n -1-trunc (fst Â) , point n -1 (snd Â))
-- points∙ = point n -1 , idp
from-sphere-null∙ : isNulld ((point n -1 , idp) ⊙∘ g)
from-sphere-null∙ = λ x →
point n -1 ((fst g) x)
=⟨ spoke n -1 (fst g) x ⟩
hub n -1 (fst g)
=⟨ ! (spoke n -1 (fst g) (nor' n)) ⟩
point n -1 ((fst g) (nor' n))
=⟨ ap (point n -1) (snd g) ⟩
point n -1 (snd Â)
∎
{- Unfortunately, we will need this lemma not for maps
g : Sphere' (S n) → A,
but we will need it for maps
g : Susp (Sphere' n) → A,
and Sphere' (S n) is NOT judgmentally equal to Susp (Sphere' n).
We have to give a second proof. -}
module cmp-nll' {i} {Â : Ptd i} (n : ℕ) (g : ⊙Susp (⊙Sphere' {i} n) →̇ Â) where
{- "translate" equivalence -}
tr≃⊙ : ⊙Sphere' {i} (S n) ⊙≃ ⊙Susp (⊙Sphere' {i} n)
tr≃⊙ = coe-equiv∙ (susp'-switch n)
tr≃ : Sphere' {i} (S n) ≃ fst (⊙Susp (⊙Sphere' {i} n))
tr≃ = fst (fst tr≃⊙) , snd tr≃⊙
tr–̇> : (⊙Sphere' {i} (S n)) →̇ ⊙Susp (⊙Sphere' {i} n)
tr–̇> = fst tr≃⊙ -- –> (fst (fst tr-eq) , snd tr-eq) , {!!}
from-sphere-null'∙ : isNulld ((point S n -1 , idp) ⊙∘ g)
from-sphere-null'∙ = λ x →
fst ((point S n -1 , idp) ⊙∘ g) x
=⟨ ap (fst ((point S n -1 , idp) ⊙∘ g)) (! (<–-inv-r tr≃ x)) ⟩
fst ((point S n -1 , idp) ⊙∘ g) (–> tr≃ (<– tr≃ x))
=⟨ cmp-nll.from-sphere-null∙ {i} {Â} (S n) (g ⊙∘ tr–̇>) (<– tr≃ x) ⟩
point S n -1 (snd Â)
∎
| {
"alphanum_fraction": 0.5198151768,
"avg_line_length": 33.1,
"ext": "agda",
"hexsha": "1a7a8510aedc9237aa5a4907dcac17c749ab89f8",
"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": "nicolai/pseudotruncations/PseudoTruncs.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": "nicolai/pseudotruncations/PseudoTruncs.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nicolaikraus/HoTT-Agda",
"max_stars_repo_path": "nicolai/pseudotruncations/PseudoTruncs.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": 2085,
"size": 5627
} |
-- Jesper, 2019-05-28: test case for #3812
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
record Box (A : Set) : Set where
constructor box
field unbox : A
open Box
postulate
A : Set
r s : Box A
rew₂ : r .unbox ≡ s .unbox
{-# REWRITE rew₂ #-}
Box-η : {x y : Box A} → x .unbox ≡ y .unbox → x ≡ y
Box-η refl = refl
-- WAS: `ext` reduces to `refl`, but giving `ext = refl` directly
-- leads to a type error.
ext : r ≡ s
ext = Box-η refl
ext' : r ≡ s
ext' = refl
| {
"alphanum_fraction": 0.6235955056,
"avg_line_length": 17.2258064516,
"ext": "agda",
"hexsha": "07ea9142460890232c71be15f09869cbc3f5c63a",
"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/RewritingEtaContract.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/RewritingEtaContract.agda",
"max_line_length": 65,
"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/RewritingEtaContract.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": 197,
"size": 534
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.HSpace
open import homotopy.PushoutComm using (flip; Pushout-comm)
module homotopy.HopfConstruction {i} (A : Type i) (c : is-connected 0 A)
(hA : HSpaceStructure A) where
open HSpaceStructure hA
open ConnectedHSpace A c hA
{-
Using the fact that [μ a] is an equivalence, we define a fibration over the
suspension of [A] with fiber [A] and applying [μ a] when you move along
[merid a].
-}
module H = SuspensionRecType A A μ-e-r-equiv
{-
The total space of the previous fibration is the pushout of the following span
(thanks to the flattening lemma).
-}
s : Span
s = span (⊤ × A) (⊤ × A) (A × A)
(λ cc' → (tt , snd cc')) (λ cc' → (tt , uncurry μ cc'))
lemma : Σ (Suspension A) H.f == Pushout s
lemma = H.flattening
{-
But that span is equal to the following span, which is almost the same as
the span for the join.
-}
x : s == flip (*-span A A)
x = span= (equiv snd (_,_ tt) (λ b → idp) (λ a → idp))
(equiv snd (_,_ tt) (λ b → idp) (λ a → idp))
eq (λ a → idp) (λ a → idp) where
eq : (A × A) ≃ (A × A)
eq = equiv to from to-from from-to where
to : A × A → A × A
to (a , a') = (μ a a' , a')
from : A × A → A × A
from (a , a') = (<– (μ-e-l-equiv a') a , a')
to-from : (a : A × A) → to (from a) == a
to-from (a , a') = pair×= (<–-inv-r (μ-e-l-equiv a') a) idp
from-to : (a : A × A) → from (to a) == a
from-to (a , a') = pair×= (<–-inv-l (μ-e-l-equiv a') a) idp
lemma2 : (A * A) ≃ (Pushout (flip (*-span A A)))
lemma2 = Pushout-comm (*-span A A)
theorem : Σ (Suspension A) H.f == (A * A)
theorem = lemma ∙ ap Pushout x ∙ ! (ua lemma2)
-- record FibSeq {i j k ℓ} (A : Type i) (B : Type j) (C : Type k) (c : C)
-- : Type (lmax (lmax i j) (lmax k (lsucc ℓ))) where
-- constructor fibSeq
-- field
-- fibration : C → Type ℓ
-- fiber : fibration c ≃ A
-- total : Σ C fibration ≃ B
| {
"alphanum_fraction": 0.5673027334,
"avg_line_length": 27.3098591549,
"ext": "agda",
"hexsha": "5f9c988a180c714d4eec79ea8e7cdcc86a039d48",
"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": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cmknapp/HoTT-Agda",
"max_forks_repo_path": "theorems/homotopy/HopfConstruction.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"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": "cmknapp/HoTT-Agda",
"max_issues_repo_path": "theorems/homotopy/HopfConstruction.agda",
"max_line_length": 78,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "bc849346a17b33e2679a5b3f2b8efbe7835dc4b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cmknapp/HoTT-Agda",
"max_stars_repo_path": "theorems/homotopy/HopfConstruction.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 718,
"size": 1939
} |
module WarningOnImport.Impo where
B = Set
A = B
{-# WARNING_ON_USAGE A "Deprecated: Use B instead" #-}
{-# WARNING_ON_IMPORT "Deprecated: Use Impossible instead" #-}
| {
"alphanum_fraction": 0.7202380952,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "03927ba96a43a877c174398651aff853ca361d67",
"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/WarningOnImport/Impo.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/WarningOnImport/Impo.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/WarningOnImport/Impo.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": 41,
"size": 168
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
open import LibraBFT.Impl.Consensus.PersistentLivenessStorage
open import LibraBFT.Impl.Properties.Util
open import LibraBFT.ImplShared.Base.Types
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Prelude
module LibraBFT.Impl.Consensus.PersistentLivenessStorage.Properties where
module saveVoteMSpec (vote : Vote) where
open OutputProps
postulate -- TODO-2: refine and prove
contract
: ∀ P pre
→ (∀ outs → NoMsgs outs → NoErrors outs → P (inj₁ fakeErr) pre outs)
→ (∀ outs → NoMsgs outs → NoErrors outs
→ P (inj₂ unit) pre outs)
→ RWS-weakestPre (saveVoteM vote) P unit pre
| {
"alphanum_fraction": 0.75,
"avg_line_length": 36.5925925926,
"ext": "agda",
"hexsha": "0ccf38583d06f6e5817cb860485ade502b4d773d",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/Consensus/PersistentLivenessStorage/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/Consensus/PersistentLivenessStorage/Properties.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/Consensus/PersistentLivenessStorage/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 272,
"size": 988
} |
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Exactness
open import cohomology.Theory
module cohomology.Sn {i} (OT : OrdinaryTheory i) where
open OrdinaryTheory OT
C-Sphere-≠ : (n : ℤ) (m : ℕ) → (n ≠ ℕ-to-ℤ m)
→ C n (⊙Sphere m) == LiftUnit-Group
C-Sphere-≠ n O neq = C-dimension n neq
C-Sphere-≠ n (S m) neq =
ap (λ k → C k (⊙Sphere (S m))) (! (succ-pred n))
∙ C-Susp (pred n) (⊙Sphere m)
∙ C-Sphere-≠ (pred n) m (λ p → neq (pred-injective n (pos m) p))
C-Sphere-diag : (m : ℕ) → C (ℕ-to-ℤ m) (⊙Sphere m) == C O (⊙Sphere O)
C-Sphere-diag O = idp
C-Sphere-diag 1 = C-Susp O (⊙Sphere O)
C-Sphere-diag (S (S m)) =
C-Susp (pos m) (⊙Sphere (S m)) ∙ C-Sphere-diag (S m)
| {
"alphanum_fraction": 0.5977175464,
"avg_line_length": 29.2083333333,
"ext": "agda",
"hexsha": "959fd34d113a96bc9a441570b5d3892f05724609",
"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": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danbornside/HoTT-Agda",
"max_forks_repo_path": "cohomology/Sn.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"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": "danbornside/HoTT-Agda",
"max_issues_repo_path": "cohomology/Sn.agda",
"max_line_length": 69,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "1695a7f3dc60177457855ae846bbd86fcd96983e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danbornside/HoTT-Agda",
"max_stars_repo_path": "cohomology/Sn.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 308,
"size": 701
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the heterogeneous sublist relation
-- This is a generalisation of what is commonly known as Order
-- Preserving Embeddings (OPE).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (REL)
module Data.List.Relation.Binary.Sublist.Heterogeneous
{a b r} {A : Set a} {B : Set b} {R : REL A B r}
where
open import Level using (_⊔_)
open import Data.List.Base using (List; []; _∷_; [_])
open import Data.List.Relation.Unary.Any using (Any; here; there)
open import Function
open import Relation.Unary using (Pred)
open import Relation.Binary
open import Relation.Binary.PropositionalEquality as P using (_≡_)
------------------------------------------------------------------------
-- Re-export core definitions
open import Data.List.Relation.Binary.Sublist.Heterogeneous.Core public
------------------------------------------------------------------------
-- Type and basic combinators
module _ {s} {S : REL A B s} where
map : R ⇒ S → Sublist R ⇒ Sublist S
map f [] = []
map f (y ∷ʳ rs) = y ∷ʳ map f rs
map f (r ∷ rs) = f r ∷ map f rs
minimum : Min (Sublist R) []
minimum [] = []
minimum (x ∷ xs) = x ∷ʳ minimum xs
------------------------------------------------------------------------
-- Conversion to and from Any
toAny : ∀ {a bs} → Sublist R [ a ] bs → Any (R a) bs
toAny (y ∷ʳ rs) = there (toAny rs)
toAny (r ∷ rs) = here r
fromAny : ∀ {a bs} → Any (R a) bs → Sublist R [ a ] bs
fromAny (here r) = r ∷ minimum _
fromAny (there p) = _ ∷ʳ fromAny p
------------------------------------------------------------------------
-- Generalised lookup based on a proof of Any
module _ {p q} {P : Pred A p} {Q : Pred B q} (resp : P ⟶ Q Respects R) where
lookup : ∀ {xs ys} → Sublist R xs ys → Any P xs → Any Q ys
lookup [] ()
lookup (y ∷ʳ p) k = there (lookup p k)
lookup (rxy ∷ p) (here px) = here (resp rxy px)
lookup (rxy ∷ p) (there k) = there (lookup p k)
| {
"alphanum_fraction": 0.5086247086,
"avg_line_length": 33,
"ext": "agda",
"hexsha": "ed6b8b7d4924d7efc701a0258da98442d873bfc9",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "omega12345/agda-mode",
"max_forks_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "omega12345/agda-mode",
"max_stars_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/Heterogeneous.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 569,
"size": 2145
} |
open import Relation.Binary.Core
module PLRTree.Drop.Complete {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.Sum
open import PLRTree {A}
open import PLRTree.Complete {A}
open import PLRTree.Compound {A}
open import PLRTree.Drop _≤_ tot≤
open import PLRTree.DropLast.Complete _≤_ tot≤
open import PLRTree.Equality {A}
open import PLRTree.Order.Properties {A}
open import PLRTree.Push.Complete _≤_ tot≤
lemma-setRoot-complete : {t : PLRTree}(x : A) → Complete t → Complete (setRoot x t)
lemma-setRoot-complete x leaf = leaf
lemma-setRoot-complete x (perfect _ cl cr l≃r) = perfect x cl cr l≃r
lemma-setRoot-complete x (left _ cl cr l⋘r) = left x cl cr l⋘r
lemma-setRoot-complete x (right _ cl cr l⋙r) = right x cl cr l⋙r
lemma-drop-complete : {t : PLRTree} → Complete t → Complete (drop t)
lemma-drop-complete leaf = leaf
lemma-drop-complete (perfect _ _ _ ≃lf) = leaf
lemma-drop-complete (perfect {node perfect x' l' r'} {node perfect x'' l'' r''} x (perfect .x' cl' cr' _) (perfect .x'' cl'' cr'' _) (≃nd .x' .x'' l'≃r' l''≃r'' l'≃l'')) =
let z = last (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;
t' = dropLast (node perfect x (node perfect x' l' r') (node perfect x'' l'' r'')) ;
ct' = right x (perfect x' cl' cr' l'≃r') (lemma-dropLast-complete (perfect x'' cl'' cr'' l''≃r'')) (lemma-dropLast-≃ (≃nd x' x'' l'≃r' l''≃r'' l'≃l'') compound)
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left {l} {r} x cl cr l⋘r)
with l | r | l⋘r | lemma-dropLast-⋘ l⋘r
... | leaf | _ | () | _
... | node perfect x' l' r' | _ | () | _
... | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₁ ld⋘r
with dropLast (node left x' l' r') | ld⋘r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect _ _ _ | () | _
... | node left x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node right x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node left x' l' r' | node perfect x'' l'' r'' | l⋘ .x' .x'' l'⋘r' l''≃r'' r'≃l'' | inj₂ ld≃r
with dropLast (node left x' l' r') | ld≃r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect x''' l''' r''' | ld≃r' | cld =
let z = last (node left x (node left x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | () | _
... | node right _ _ _ | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | leaf | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₁ ()
lemma-drop-complete (left x cl cr l⋘r) | node right x' (node perfect x'' leaf leaf) leaf | node perfect x''' leaf leaf | x⋘ .x' .x'' .x''' | inj₂ x'≃x''' =
let z = last (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) compound ;
t' = dropLast (node left x (node right x' (node perfect x'' leaf leaf) leaf) (node perfect x''' leaf leaf)) ;
ct' = perfect x (perfect x' leaf leaf ≃lf) cr x'≃x'''
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₁ ld⋘r
with dropLast (node right x' l' r') | ld⋘r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect _ _ _ | () | _
... | node left x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node left x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node right x''' l''' r''' | ld⋘r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node left x (node right x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = left x cld cr ld⋘r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node perfect x'' l'' r'' | r⋘ .x' .x'' l⋙r l''≃r'' l'⋗l'' | inj₂ ld≃r
with dropLast (node right x' l' r') | ld≃r | lemma-dropLast-complete cl
... | leaf | () | _
... | node perfect x''' l''' r''' | ld≃r' | cld =
let z = last (node left x (node right x' l' r') (node perfect x'' l'' r'')) compound ;
t' = node perfect x (node perfect x''' l''' r''') (node perfect x'' l'' r'') ;
ct' = perfect x cld cr ld≃r'
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | () | _
... | node right _ _ _ | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node left x'' l'' r'' | () | _
lemma-drop-complete (left x cl cr l⋘r) | node right x' l' r' | node right x'' l'' r'' | () | _
lemma-drop-complete (right {l} {r} x cl cr l⋙r)
with l | r | l⋙r | lemma-dropLast-⋙ l⋙r
... | leaf | leaf | ⋙p () | _
... | node perfect x' leaf leaf | leaf | ⋙p (⋗lf .x') | _ = cl
... | node perfect _ _ (node _ _ _ _) | leaf | ⋙p () | _
... | node perfect _ (node _ _ _ _) _ | leaf | ⋙p () | _
... | node left _ _ _ | leaf | ⋙p () | _
... | node right _ _ _ | leaf | ⋙p () | _
... | leaf | node perfect _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node perfect x'' l'' r'' | ⋙p (⋗nd .x' .x'' l'≃r' l''≃r'' l'⋗l'') | _ =
let z = last (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node perfect x'' l'' r'')) ;
ct' = left x (lemma-dropLast-complete cl) cr (lemma-dropLast-⋗ (⋗nd x' x'' l'≃r' l''≃r'' l'⋗l'') compound)
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node left _ _ _ | node perfect _ _ _ | ⋙p () | _
... | node right _ _ _ | node perfect _ _ _ | ⋙p () | _
... | leaf | node left _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node left x'' l'' r'' | _ | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node left x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node left x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node perfect _ _ _ | node left _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node left _ _ _ | ⋙p () | _
... | node right _ _ _ | node left _ _ _ | ⋙p () | _
... | leaf | node right _ _ _ | ⋙p () | _
... | node perfect x' l' r' | node right x'' l'' r'' | _ | inj₁ l⋙rd =
let z = last (node right x (node perfect x' l' r') (node right x'' l'' r'')) compound ;
t' = dropLast (node right x (node perfect x' l' r') (node right x'' l'' r'')) ;
ct' = right x cl (lemma-dropLast-complete cr) l⋙rd
in lemma-push-complete (lemma-setRoot-complete z ct') (≺-wf (setRoot z t'))
... | node perfect _ _ _ | node right _ _ _ | _ | inj₂ ()
... | node left _ _ _ | node right _ _ _ | ⋙p () | _
... | node right _ _ _ | node right _ _ _ | ⋙p () | _
| {
"alphanum_fraction": 0.5097262667,
"avg_line_length": 68.1349206349,
"ext": "agda",
"hexsha": "23cd1fa90ad8819501191f3f8e0afa103fefa2c5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/PLRTree/Drop/Complete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/PLRTree/Drop/Complete.agda",
"max_line_length": 183,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/PLRTree/Drop/Complete.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 2963,
"size": 8585
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Categories.Equivalence.Base where
open import Cubical.Foundations.Prelude
open import Cubical.Categories.Category
open import Cubical.Categories.Functor
open import Cubical.Categories.NaturalTransformation
open Precategory
open Functor
private
variable
ℓC ℓC' ℓD ℓD' : Level
-- Definition
record isEquivalence {C : Precategory ℓC ℓC'} {D : Precategory ℓD ℓD'}
(func : Functor C D) : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
field
invFunc : Functor D C
η : 𝟙⟨ C ⟩ ≅ᶜ invFunc ∘F func
ε : func ∘F invFunc ≅ᶜ 𝟙⟨ D ⟩
record _≃ᶜ_ (C : Precategory ℓC ℓC') (D : Precategory ℓD ℓD') : Type (ℓ-max (ℓ-max ℓC ℓC') (ℓ-max ℓD ℓD')) where
field
func : Functor C D
isEquiv : isEquivalence func
| {
"alphanum_fraction": 0.6740467405,
"avg_line_length": 25.40625,
"ext": "agda",
"hexsha": "a5177b6a1272c429e7ecacc78e825832c060e4b4",
"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/Categories/Equivalence/Base.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/Categories/Equivalence/Base.agda",
"max_line_length": 112,
"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/Categories/Equivalence/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 300,
"size": 813
} |
-- Let-definitions cannot pattern match (or be recursive). Use where for that.
module NotAValidLetBinding where
data N : Set where
z : N
s : N -> N
bad = let pred : N -> N
pred z = z
pred (s n) = n
in pred (s (s z))
| {
"alphanum_fraction": 0.5634920635,
"avg_line_length": 21,
"ext": "agda",
"hexsha": "2d6f52f2d7fcf71b661c53fac7f4a902c0ae8436",
"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/NotAValidLetBinding.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/NotAValidLetBinding.agda",
"max_line_length": 78,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/NotAValidLetBinding.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": 77,
"size": 252
} |
{-# OPTIONS --without-K --safe #-}
open import Categories.Category
module Categories.Diagram.Equalizer.Properties {o ℓ e} (C : Category o ℓ e) where
open import Categories.Diagram.Equalizer C
open import Categories.Morphism C
open import Categories.Morphism.Reasoning C
private
module C = Category C
open C
variable
X Y Z : Obj
f g : X ⇒ Y
module _ (equalizer : Equalizer f g) where
open Equalizer equalizer
open HomReasoning
equalizer-≈⇒≈ : ∀ {h} → arr ∘ h ≈ id → f ≈ g
equalizer-≈⇒≈ {h} eq = begin
f ≈⟨ introʳ eq ⟩
f ∘ arr ∘ h ≈⟨ pullˡ equality ⟩
(g ∘ arr) ∘ h ≈⟨ cancelʳ eq ⟩
g ∎
section-equalizer : ∀ {X Y} {f : Y ⇒ X} {g : X ⇒ Y} → f SectionOf g → IsEqualizer f (f ∘ g) id
section-equalizer {X = X} {Y = Y} {f = f} {g = g} g∘f≈id = record
{ equality = equality
; equalize = equalize
; universal = λ {_} {_} {eq} → universal {eq = eq}
; unique = unique
}
where
open HomReasoning
equality : (f ∘ g) ∘ f ≈ id ∘ f
equality = begin
(f ∘ g) ∘ f ≈⟨ pullʳ g∘f≈id ⟩
f ∘ id ≈⟨ id-comm ⟩
id ∘ f ∎
equalize : ∀ {Z} {h : Z ⇒ X} → (f ∘ g) ∘ h ≈ id ∘ h → Z ⇒ Y
equalize {h = h} _ = g ∘ h
universal : ∀ {Z} {h : Z ⇒ X} {eq : (f ∘ g) ∘ h ≈ id ∘ h} → h ≈ f ∘ g ∘ h
universal {h = h} {eq = eq} = begin
h ≈˘⟨ identityˡ ⟩
id ∘ h ≈˘⟨ eq ⟩
(f ∘ g) ∘ h ≈⟨ assoc ⟩
f ∘ g ∘ h ∎
unique : ∀ {Z} {h : Z ⇒ X} {i : Z ⇒ Y} → h ≈ f ∘ i → i ≈ g ∘ h
unique {h = h} {i = i} h≈g∘i = begin
i ≈⟨ introˡ g∘f≈id ⟩
(g ∘ f) ∘ i ≈⟨ pullʳ (⟺ h≈g∘i) ⟩
g ∘ h ∎
| {
"alphanum_fraction": 0.4851244687,
"avg_line_length": 27,
"ext": "agda",
"hexsha": "301c2131654ace3b2c9bb83fea497455df3fbb01",
"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": "8f3c844d929508040dfa21f681fa260056214b73",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "maxsnew/agda-categories",
"max_forks_repo_path": "src/Categories/Diagram/Equalizer/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "8f3c844d929508040dfa21f681fa260056214b73",
"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": "maxsnew/agda-categories",
"max_issues_repo_path": "src/Categories/Diagram/Equalizer/Properties.agda",
"max_line_length": 94,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "8f3c844d929508040dfa21f681fa260056214b73",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "maxsnew/agda-categories",
"max_stars_repo_path": "src/Categories/Diagram/Equalizer/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 722,
"size": 1647
} |
-- Andreas, 2011-10-02
module IrrelevantLet where
postulate
A : Set
test : (.A → A) → .A → A
test = λ f a →
let .b : A
b = f a
in f a
| {
"alphanum_fraction": 0.4593023256,
"avg_line_length": 14.3333333333,
"ext": "agda",
"hexsha": "768623e898e07f11bb4882e599543313eb95eee4",
"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/IrrelevantLet.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/IrrelevantLet.agda",
"max_line_length": 26,
"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/succeed/IrrelevantLet.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": 65,
"size": 172
} |
data Size : Set where
↑ : Size → Size
↑ ()
data N : Size → Set where
suc : ∀{i} (a : N i) → N (↑ i)
data Val : ∀{i} (t : N i) → Set where
val : ∀{i} (n : N i) → Val (suc n)
record R (j : Size) : Set where
field num : N j
data W {j} (ft : R j) : Set where
immed : (v : Val (R.num ft)) → W ft
postulate
E : ∀{j} (ft : R j) (P : (w : W ft) → Set) → Set
test : ∀ {j} (ft : R j) → Set
test {j} ft = E {j} ft testw
where
testw : ∀ {ft : R _} (w : W ft) → Set
testw (immed (val a)) = test record{ num = a }
-- testw passes without quantification over ft
-- or with _ := j
{- OLD ERROR
Cannot instantiate the metavariable _35 to solution ↑ i since it
contains the variable i which is not in scope of the metavariable
or irrelevant in the metavariable but relevant in the solution
when checking that the pattern val a has type Val (R.num ft₁)
-}
| {
"alphanum_fraction": 0.594438007,
"avg_line_length": 23.3243243243,
"ext": "agda",
"hexsha": "eb521bb97c885b561f2937a67ce51afd8f32d212",
"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/Issue2056.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/Issue2056.agda",
"max_line_length": 65,
"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/Issue2056.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": 308,
"size": 863
} |
{-# OPTIONS --sized-types #-}
open import Relation.Binary.Core
module BubbleSort {A : Set}
(_≤_ : A → A → Set)
(tot≤ : Total _≤_) where
open import Data.List
open import Data.Product
open import Data.Sum
open import Size
open import SList
swap* : {ι : Size} → A → SList A {ι} → SList A {ι} × A
swap* x snil = (snil , x)
swap* x (y ∙ ys)
with tot≤ x y
... | inj₁ x≤y
with swap* y ys
swap* x (y ∙ ys) | inj₁ x≤y | (zs , z) = (x ∙ zs , z)
swap* x (y ∙ ys) | inj₂ y≤x
with swap* x ys
swap* x (y ∙ ys) | inj₂ y≤x | (zs , z) = (y ∙ zs , z)
bubbleSort : {ι : Size} → SList A {ι} → SList A
bubbleSort snil = snil
bubbleSort (x ∙ xs)
with swap* x xs
... | (ys , y) = _⊕_ A (bubbleSort ys) (y ∙ snil)
| {
"alphanum_fraction": 0.5378486056,
"avg_line_length": 25.1,
"ext": "agda",
"hexsha": "5f8e9230e5be6545495b78a0d8de3ac81ff006a5",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "bgbianchi/sorting",
"max_forks_repo_path": "agda/BubbleSort.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "bgbianchi/sorting",
"max_issues_repo_path": "agda/BubbleSort.agda",
"max_line_length": 54,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "b8d428bccbdd1b13613e8f6ead6c81a8f9298399",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "bgbianchi/sorting",
"max_stars_repo_path": "agda/BubbleSort.agda",
"max_stars_repo_stars_event_max_datetime": "2021-08-24T22:11:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-05-21T12:50:35.000Z",
"num_tokens": 300,
"size": 753
} |
module Issue2649-2 where
open import Issue2649-1
open module M (A : Set) (a : A) = MyModule A a public
| {
"alphanum_fraction": 0.7047619048,
"avg_line_length": 17.5,
"ext": "agda",
"hexsha": "942bb4115c66220c941f8efc3466b2e2b313acb8",
"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/customised/Issue2649-2.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/customised/Issue2649-2.agda",
"max_line_length": 53,
"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/customised/Issue2649-2.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": 36,
"size": 105
} |
open import Data.String using (String)
open import Data.List using (List; []; _∷_)
open import Data.Nat using (ℕ)
open import Data.Product
open import Data.Bool
open import Data.Maybe
open import Data.Vec as V using (Vec; []; _∷_)
open import Data.Fin as F using (Fin; zero; suc)
open import Reflection using (TC)
open import Reflection.Name using (Names)
import Reflection.TypeChecking.Monad.Categorical as RCat
open import Category.Monad.State using (State; StateT; StateMonad; StateTMonad)
open import Category.Monad using (RawMonad)
--open import Relation.Binary.PropositionalEquality hiding ([_])
open import Relation.Nullary
import Relation.Unary as UR
open import Relation.Nullary.Negation using (contradiction)
open import Function
-- This is a `Maybe`-like data type except that nothing
-- is extended with a string argument, to carry around the error.
data Err {a} (A : Set a) : Set a where
error : String → Err A
ok : A → Err A
-- Our representation for programs: it is either a string containing
-- textual representation of the extracted program or an error that
-- happened during extraction.
Prog = Err String
-- Simply for convenience
Strings = List String
-- We define a custom RawMonoid to add `_++/_` (list join)
-- an its overloadings.
record RawMonoid {a}(A : Set a) : Set a where
field
_++_ : A → A → A
ε : A
_++/_ : (delim : A) → List A → A
d ++/ [] = ε
d ++/ (x ∷ []) = x
d ++/ (x ∷ xs) = x ++ d ++ d ++/ xs
infixr 5 _++_
open RawMonoid {{...}} public
instance
monoidLst : ∀ {a}{A : Set a} → RawMonoid (List A)
monoidLst {A = A} = record {
_++_ = λ a b → (Data.List._++_ $! a) $! b ;
ε = []
}
monoidStr : RawMonoid String
monoidStr = record {
_++_ = λ a b → (Data.String._++_ $! a) $! b;
ε = ""
}
monoidErrStr : RawMonoid (Err String)
monoidErrStr = record {
_++_ = λ where
(error s) _ → error s
_ (error s) → error s
(ok s₁) (ok s₂) → ok (s₁ ++ s₂)
;
ε = ok ""
}
-- Simplify handling concatenation of `Prog`s and `String`s
data Err++Ty : Set → Set → Set where
instance
s-s : Err++Ty String String
e-s : Err++Ty Prog String
s-e : Err++Ty String Prog
e-e : Err++Ty Prog Prog
infixr 5 _⊕_
_⊕_ : ∀ {A B}{{t : Err++Ty A B}} → A → B → Prog
_⊕_ {{t = s-s}} a b = ok $! (a ++ b)
_⊕_ {{t = e-s}} (error x) b = error $! x
_⊕_ {{t = e-s}} (ok x) b = ok $! (x ++ b)
_⊕_ {{t = s-e}} a (error x) = error $! x
_⊕_ {{t = s-e}} a (ok x) = ok $! (a ++ x)
_⊕_ {{t = e-e}} a b = id $! (a ++ b)
-- The state used at the top-most and term-level compilation.
record KS : Set where
constructor ks
field funs : Names -- Functions to compile
base : Names -- Atomic functions that we do not traverse into.
done : Names -- Functions that we have processed.
defs : Prog -- Definitions such as lifted functions, function declarations, etc.
cnt : ℕ -- Source of fresh variables
defaultKS = ks [] [] [] ε 1
SKS = State KS
TCS = StateT KS TC
instance
monadTC = RCat.monad
monadTCS : RawMonad TCS
monadTCS = StateTMonad KS monadTC
monadSKS : ∀ {S : Set} → RawMonad (State S)
monadSKS {S} = StateMonad S
monadErr : ∀ {f} → RawMonad {f} Err
monadErr = record {
return = ok ;
_>>=_ = λ { (error s) f → error s ; (ok a) f → f a }
}
lift-state : ∀ {f}{M}{RM : RawMonad {f} M}{A}{S} → M A → StateT S M A
lift-state {RM = RM} x = λ s → return (_, s) ⊛ x
where open RawMonad RM
lift-mstate : ∀ {f}{M}{RM : RawMonad {f} M}{A}{S} → State S A → StateT S M A
lift-mstate {RM = RM}{S = S} sa = λ s → return (sa s)
where open RawMonad RM
-- Modify error message in Prog, in case Prog is error.
err-modify : Prog → (String → String) → Prog
err-modify (error s) f = error (f s)
err-modify p _ = p
-- Check if there exists an element in the list that satisfies the predicate P.
list-has-el : ∀ {a b}{A : Set a}{P : UR.Pred A b} → UR.Decidable P → List A → Bool
list-has-el P? [] = false
list-has-el P? (x ∷ xs) with P? x
... | yes _ = true
... | no _ = list-has-el P? xs
-- Check if there exists an element in the list that satisfies the predicate P.
list-find-el : ∀ {a b}{A : Set a}{P : UR.Pred A b} → UR.Decidable P → List A → Maybe A
list-find-el P? [] = nothing
list-find-el P? (x ∷ xs) with P? x
... | yes _ = just x
... | no _ = list-find-el P? xs
list-update-fst : ∀ {a b}{A : Set a}{P : UR.Pred A b} → UR.Decidable P → List A → (A → A) → List A
list-update-fst P? [] f = []
list-update-fst P? (x ∷ xs) f with P? x
... | yes _ = f x ∷ xs
... | no _ = x ∷ list-update-fst P? xs f
list-filter : ∀ {a b}{A : Set a}{P : UR.Pred A b} → UR.Decidable P → List A → List A
list-filter P? [] = []
list-filter P? (x ∷ xs) with P? x
... | yes _ = x ∷ list-filter P? xs
... | no _ = list-filter P? xs
dec-neg : ∀ {a b}{A : Set a}{P : UR.Pred A b} → UR.Decidable P → UR.Decidable (UR._∉ P)
dec-neg P? x with P? x
... | yes p = no λ ¬p → contradiction p ¬p
... | no ¬p = yes ¬p
vec-find-el-idx : ∀ {a b}{A : Set a}{n}{P : UR.Pred A b} → UR.Decidable P → Vec A n → Maybe (Fin n × A)
vec-find-el-idx P? [] = nothing
vec-find-el-idx P? (x ∷ xs) with P? x
... | yes _ = just (zero , x)
... | no _ with vec-find-el-idx P? xs
... | just (i , x′) = just (suc i , x′)
... | nothing = nothing
| {
"alphanum_fraction": 0.5885212189,
"avg_line_length": 29.7166666667,
"ext": "agda",
"hexsha": "be364f9fc19351dc30e2254aa0beba8879a4f7fd",
"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": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "ashinkarov/agda-extractor",
"max_forks_repo_path": "Structures.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "ashinkarov/agda-extractor",
"max_issues_repo_path": "Structures.agda",
"max_line_length": 103,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "c8954c8acd8089ced82af9e05084fbbc7fedb36c",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "ashinkarov/agda-extractor",
"max_stars_repo_path": "Structures.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-11T14:52:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-01-11T14:52:59.000Z",
"num_tokens": 1846,
"size": 5349
} |
{-# OPTIONS --without-K --rewriting #-}
open import HoTT
open import stash.modalities.gbm.GbmUtil
open import stash.modalities.GbmCodes
module stash.modalities.Gbm {ℓ} (M : Modality ℓ)
{A : Type ℓ} {B : Type ℓ}
(Q : A → B → Type ℓ)
(H : BM-Relation M Q) where
open Modality M
import stash.modalities.gbm.Pushout
open import stash.modalities.gbm.PushoutMono
open import stash.modalities.gbm.PullbackSplit
open import homotopy.PushoutSplit
private
A' : Type ℓ
A' = Σ A (λ a → Trunc (S ⟨-2⟩) (Σ B (λ b → Q a b)))
Q' : A' → B → Type ℓ
Q' (a , _) b = Q a b
Q'-pth-ovr-lemma : {a₀ a₁ : A'} {b : B} (q₀ : Q' a₀ b) (q₁ : Q' a₁ b) (p : a₀ == a₁)
→ (q₀ == q₁ [ (λ a → Q' a b) ↓ p ]) ≃ (q₀ == q₁ [ (λ a → Q a b) ↓ fst= p ])
Q'-pth-ovr-lemma q₀ q₁ idp = ide (q₀ == q₁)
Q'-is-BM-Relation : BM-Relation M Q'
Q'-is-BM-Relation {a₀} {b₀} q₀ {a₁} q₁ {b₁} q₂ =
equiv-preserves-◯-conn (*-emap eqv (ide _))
(H {fst a₀} {b₀} q₀ {fst a₁} q₁ {b₁} q₂)
where eqv = =Σ-econv (a₀ , q₀) (a₁ , q₁)
∘e (Σ-emap-r (Q'-pth-ovr-lemma q₀ q₁)) ⁻¹
∘e (Σ-emap-l (λ p → q₀ == q₁ [ (λ a → Q a b₀) ↓ p ])
(Subtype=-econv ((λ a → Trunc -1 (Σ B λ b → Q a b)), λ a → Trunc-level) a₀ a₁ ⁻¹)) ⁻¹
∘e (=Σ-econv (fst a₀ , q₀) (fst a₁ , q₁)) ⁻¹
module W = stash.modalities.gbm.Pushout Q
module W' = stash.modalities.gbm.Pushout Q'
W = W.BMPushout
W' = W'.BMPushout
Z = (Σ A λ a → Σ B λ b → Q a b)
Z' = (Σ A' λ a → Σ B λ b → Q (fst a) b)
Z-to-Z' : Z → Z'
Z-to-Z' (a , b , q) = (a , [ b , q ]) , b , q
Z'-to-Z : Z' → Z
Z'-to-Z ((a , e) , b , q) = a , b , q
Z≃Z' : is-equiv Z-to-Z'
Z≃Z' = is-eq Z-to-Z' Z'-to-Z to-from from-to
where to-from : (z : Z') → Z-to-Z' (Z'-to-Z z) == z
to-from ((a , e) , b , q) = pair= (pair= idp (prop-has-all-paths Trunc-level _ e))
(↓-cst2-in idp (prop-has-all-paths Trunc-level _ e) idp)
from-to : (z : Z) → Z'-to-Z (Z-to-Z' z) == z
from-to (a , b , q) = idp
W-span = span A B Z fst (fst ∘ snd)
W''-span = span A B Z' (fst ∘ fst) (fst ∘ snd)
W'' = Pushout W''-span
W≃W'' : W ≃ W''
W≃W'' = Pushout-emap span-eqv
where span-eqv : SpanEquiv W-span W''-span
span-eqv = (span-map (idf A) (idf B) Z-to-Z'
(comm-sqr (λ a → idp))
(comm-sqr (λ b → idp))) ,
( idf-is-equiv A
, idf-is-equiv B
, Z≃Z')
--
-- But the PushoutSplit lemma, we find that
--
-- Z' ---------> B
-- | |
-- | |
-- v v
-- A' ---------> W'
-- | |
-- | |
-- v v
-- A ----------> W'' ≃ X
--
X = Pushout (span A W' A' fst left)
W''≃X : W'' ≃ X
W''≃X = PS.split-equiv
where module PS = PushoutLSplit {A = A'} {B = A} {C = B} {D = Z'} fst fst (fst ∘ snd)
--
-- Now we switch gears and take pullbacks. We
-- have the following diagram:
--
-- U'' ≃ U' ≃ U ---------> B
-- | |
-- | |
-- v v
-- A' ≃ V ---------> W' outer = cospan₀
-- | |
-- | cospan₂ |
-- v v
-- A ---------> X ≃ W''
V = Pullback (cospan A W' X left right)
U = Pullback (cospan A B X left (right ∘ W'.bmright))
U' = Pullback (cospan A B W'' left right)
U'' = Pullback (cospan V B W' Pullback.b right)
U≃U'' : U ≃ U''
U≃U'' = PBSplit.split-equiv
where module PBSplit = PullbackLSplit {A = W'} {B = B} {C = A} {D = X} right right left
--
-- The map A' --> A is a mono. Hence by
-- the PushoutMono lemma we get that it
-- is also a pullback and consequently
-- equivalent to V
--
V≃A' : V ≃ A'
V≃A' = (ML.pushout-mono-is-pullback) ⁻¹ ∘e (pullback-decomp-equiv (cospan A W' X left right))
where module ML = MonoLemma
(span A W' A' fst left)
(λ b → equiv-preserves-level ((hfiber-fst b) ⁻¹) Trunc-level)
-- We need this for commutivity below
V≃A'-coh : (v : V) → Pullback.b v == left (fst V≃A' v)
V≃A'-coh (pullback a b h) = ! (ML.witness-for-coh₀ h)
where module ML = MonoLemma
(span A W' A' fst left)
(λ b → equiv-preserves-level ((hfiber-fst b) ⁻¹) Trunc-level)
--
-- Now on to the main theorem
--
A×WB = Pullback (cospan A B W left right)
A'×W'B = Pullback (cospan A' B W' left right)
U''≃A'×W'B : U'' ≃ A'×W'B
U''≃A'×W'B = Pullback-emap cospan-eqv
where cospan-eqv : CospanEquiv (cospan V B W' Pullback.b right)
(cospan A' B W' left right)
cospan-eqv = (cospan-map (fst (V≃A')) (idf B) (idf W')
(comm-sqr V≃A'-coh)
(comm-sqr (λ b → idp))) ,
snd (V≃A') ,
idf-is-equiv B ,
idf-is-equiv W'
A×WB≃U : A×WB ≃ U
A×WB≃U = Pullback-emap cospan-eqv
where cospan-eqv : CospanEquiv (cospan A B W left right) (cospan A B X left (right ∘ W'.bmright))
cospan-eqv = (cospan-map (idf A) (idf B) (fst (W''≃X ∘e W≃W''))
(comm-sqr (λ a → idp))
(comm-sqr (λ b → idp))) ,
idf-is-equiv A ,
(idf-is-equiv B) ,
(snd (W''≃X ∘e W≃W''))
Pb = Σ A (λ a → Σ B (λ b → W.bmleft a == W.bmright b))
Pb' = Σ A' (λ a → Σ B (λ b → W'.bmleft a == W'.bmright b))
Pb≃Pb' = Pb ≃⟨ Σ-assoc ⁻¹ ⟩
Σ (A × B) (λ ab → W.bmleft (fst ab) == W.bmright (snd ab)) ≃⟨ (pullback-decomp-equiv (cospan A B W left right)) ⁻¹ ⟩
A×WB ≃⟨ A×WB≃U ⟩
U ≃⟨ U≃U'' ⟩
U'' ≃⟨ U''≃A'×W'B ⟩
A'×W'B ≃⟨ pullback-decomp-equiv (cospan A' B W' left right) ⟩
Σ (A' × B) (λ ab → W'.bmleft (fst ab) == W'.bmright (snd ab)) ≃⟨ Σ-assoc ⟩
Pb' ≃∎
bm-map : Z → Pb
bm-map (a , b , q) = a , b , W.bmglue q
bm-map' : Z' → Pb'
bm-map' (a' , b , q) = a' , b , W'.bmglue q
bm-map'-is-◯-equiv : is-◯-equiv bm-map'
bm-map'-is-◯-equiv =
total-◯-equiv
(λ a' → λ { (b , q) → b , W'.bmglue q})
(λ a' → total-◯-equiv (λ b q → W'.bmglue q)
(λ b r → Trunc-rec (prop-has-level-S is-◯-connected-is-prop)
(λ{(_ , q₀₀) → code-contr M Q' Q'-is-BM-Relation q₀₀ r}) (snd a')))
--
-- We have a commutative diagram with top and bottom
-- maps equivalences. This induces an equivalence on
-- homotopy fibers, from which the theorem follows
-- ~
-- Z --------> Z'
-- | |
-- s | | t
-- | |
-- v v
-- Pb -------> Pb'
-- ~
--
sq-coh : (z : Z) → (fst Pb≃Pb' (bm-map z)) == bm-map' (Z-to-Z' z)
sq-coh (a , b , q) = {!!}
where test = fst Pb≃Pb' (a , b , W.bmglue q) =⟨ idp ⟩
(–> Σ-assoc) (–> (pullback-decomp-equiv (cospan A' B W' left right)) {!–> U''≃A'×W'B ?!} ) =⟨ idp ⟩
fst Pb≃Pb' (a , b , W.bmglue q) ∎
-- Pb≃Pb' = Pb ≃⟨ Σ-assoc ⁻¹ ⟩
-- Σ (A × B) (λ ab → W.bmleft (fst ab) == W.bmright (snd ab)) ≃⟨ (pullback-decomp-equiv (cospan A B W left right)) ⁻¹ ⟩
-- A×WB ≃⟨ A×WB≃U ⟩
-- U ≃⟨ U≃U'' ⟩
-- U'' ≃⟨ U''≃A'×W'B ⟩
-- A'×W'B ≃⟨ pullback-decomp-equiv (cospan A' B W' left right) ⟩
-- Σ (A' × B) (λ ab → W'.bmleft (fst ab) == W'.bmright (snd ab)) ≃⟨ Σ-assoc ⟩
-- Pb' ≃∎
-- fst Pb≃Pb' (a , b , W.bmglue q) =⟨ {!!} ⟩
-- (a , [ b , q ]) , (b , W'.bmglue q) ∎
generalized-blakers-massey : is-◯-equiv bm-map
generalized-blakers-massey pb = equiv-preserves-◯-conn (lemma ⁻¹) (bm-map'-is-◯-equiv (fst Pb≃Pb' pb))
where
lemma : hfiber bm-map pb ≃ hfiber bm-map' (fst Pb≃Pb' pb)
lemma = hfiber-sq-eqv bm-map bm-map' Z-to-Z' (fst Pb≃Pb')
(comm-sqr sq-coh) Z≃Z' (snd Pb≃Pb') pb
| {
"alphanum_fraction": 0.4213162493,
"avg_line_length": 34.0674603175,
"ext": "agda",
"hexsha": "83637e6d363689b57f5f4e1211b5ed42ddd62025",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "theorems/stash/modalities/Gbm.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "theorems/stash/modalities/Gbm.agda",
"max_line_length": 133,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "theorems/stash/modalities/Gbm.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": 3238,
"size": 8585
} |
------------------------------------------------------------------------
-- Traditional non-dependent lenses with erased lens laws
------------------------------------------------------------------------
-- At the time of writing there are counterparts in this file of more
-- or less everything in Lens.Non-dependent.Traditional, except for
-- the section called "A category".
{-# OPTIONS --cubical --safe #-}
import Equality.Path as P
module Lens.Non-dependent.Traditional.Erased
{e⁺} (eq : ∀ {a p} → P.Equality-with-paths a p e⁺) where
open P.Derived-definitions-and-properties eq
open import Logical-equivalence using (_⇔_)
open import Prelude as P hiding (id; [_,_]) renaming (_∘_ to _⊚_)
import Bi-invertibility.Erased
open import Bijection equality-with-J as Bij using (_↔_)
open import Equality.Path.Isomorphisms eq hiding (univ)
open import Equivalence equality-with-J as Eq
using (_≃_; Is-equivalence)
open import Equivalence.Erased equality-with-J as EEq
using (_≃ᴱ_; Is-equivalenceᴱ; Contractibleᴱ)
open import Erased.Cubical eq
open import Function-universe equality-with-J as F
hiding (id; _∘_)
open import H-level equality-with-J as H-level
open import H-level.Closure equality-with-J
open import Surjection equality-with-J as Surjection using (_↠_)
open import Univalence-axiom equality-with-J
open import Lens.Non-dependent eq as Non-dependent
hiding (no-first-projection-lens)
import Lens.Non-dependent.Traditional eq as T
private
variable
a b c p : Level
A B C D : Set a
u v x₁ x₂ y₁ y₂ : A
------------------------------------------------------------------------
-- Traditional lenses
-- Lenses with erased lens laws.
record Lens (A : Set a) (B : Set b) : Set (a ⊔ b) where
field
-- Getter and setter.
get : A → B
set : A → B → A
-- Lens laws.
@0 get-set : ∀ a b → get (set a b) ≡ b
@0 set-get : ∀ a → set a (get a) ≡ a
@0 set-set : ∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂
-- A combination of get and set.
modify : (B → B) → A → A
modify f x = set x (f (get x))
instance
-- Traditional lenses with erased laws have getters and setters.
has-getter-and-setter :
Has-getter-and-setter (Lens {a = a} {b = b})
has-getter-and-setter = record
{ get = Lens.get
; set = Lens.set
}
-- Lens A B is isomorphic to a nested Σ-type.
Lens-as-Σ :
Lens A B ↔
∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
Lens-as-Σ = record
{ surjection = record
{ logical-equivalence = record
{ to = λ l → get l , set l
, [ get-set l , set-get l , set-set l ]
; from = λ { (get , set , [ get-set , set-get , set-set ]) →
record
{ get = get
; set = set
; get-set = get-set
; set-get = set-get
; set-set = set-set
}
}
}
; right-inverse-of = refl
}
; left-inverse-of = refl
}
where
open Lens
-- Lenses without erased proofs can be turned into lenses with erased
-- proofs.
Traditional-lens→Lens : T.Lens A B → Lens A B
Traditional-lens→Lens {A = A} {B = B} =
T.Lens A B ↔⟨ T.Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → [_]→) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ inverse Lens-as-Σ ⟩□
Lens A B □
-- In erased contexts Lens A B is equivalent to T.Lens A B.
@0 Lens≃Traditional-lens : Lens A B ≃ T.Lens A B
Lens≃Traditional-lens {A = A} {B = B} =
Lens A B ↔⟨ Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ _ → erased Erased↔) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)) ↔⟨ inverse T.Lens-as-Σ ⟩□
T.Lens A B □
private
-- The forward direction of Lens≃Traditional-lens.
@0 trad : Lens A B → T.Lens A B
trad = _≃_.to Lens≃Traditional-lens
private
variable
l₁ l₂ : Lens A B
------------------------------------------------------------------------
-- Somewhat coherent lenses
-- Traditional lenses with erased lens laws that satisfy some extra
-- coherence properties (that are also erased).
record Coherent-lens (A : Set a) (B : Set b) : Set (a ⊔ b) where
field
lens : Lens A B
open Lens lens public
field
@0 get-set-get : ∀ a → cong get (set-get a) ≡ get-set a (get a)
@0 get-set-set :
∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))
instance
-- Somewhat coherent lenses have getters and setters.
coherent-has-getter-and-setter :
Has-getter-and-setter (Coherent-lens {a = a} {b = b})
coherent-has-getter-and-setter = record
{ get = Coherent-lens.get
; set = Coherent-lens.set
}
-- Coherent-lens A B is equivalent to a nested Σ-type.
Coherent-lens-as-Σ :
Coherent-lens A B ≃
∃ λ (l : Lens A B) →
let open Lens l in
Erased
((∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))
Coherent-lens-as-Σ = Eq.↔→≃
(λ l → lens l , [ get-set-get l , get-set-set l ])
(λ (l , [ get-set-get , get-set-set ]) → record
{ lens = l
; get-set-get = get-set-get
; get-set-set = get-set-set
})
refl
refl
where
open Coherent-lens
-- Somewhat coherent lenses without erased proofs can be turned into
-- somewhat coherent lenses with erased proofs.
Traditional-coherent-lens→Coherent-lens :
T.Coherent-lens A B → Coherent-lens A B
Traditional-coherent-lens→Coherent-lens {A = A} {B = B} =
T.Coherent-lens A B ↔⟨ T.Coherent-lens-as-Σ ⟩
(∃ λ (l : T.Lens A B) →
let open T.Lens l in
(∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) ↝⟨ Σ-map Traditional-lens→Lens [_]→ ⟩
(∃ λ (l : Lens A B) →
let open Lens l in
Erased
((∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))) ↔⟨ inverse Coherent-lens-as-Σ ⟩□
Coherent-lens A B □
-- In erased contexts Coherent-lens A B is equivalent to
-- T.Coherent-lens A B.
@0 Coherent-lens≃Traditional-coherent-lens :
Coherent-lens A B ≃ T.Coherent-lens A B
Coherent-lens≃Traditional-coherent-lens {A = A} {B = B} =
Coherent-lens A B ↔⟨ Coherent-lens-as-Σ ⟩
(∃ λ (l : Lens A B) →
let open Lens l in
Erased
((∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂))))) ↔⟨ (Σ-cong Lens≃Traditional-lens λ _ → erased Erased↔) ⟩
(∃ λ (l : T.Lens A B) →
let open T.Lens l in
(∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
(∀ a b₁ b₂ →
cong get (set-set a b₁ b₂) ≡
trans (get-set (set a b₁) b₂) (sym (get-set a b₂)))) ↔⟨ inverse T.Coherent-lens-as-Σ ⟩
T.Coherent-lens A B □
------------------------------------------------------------------------
-- Some lemmas
-- If two lenses have equal setters, then they also have equal
-- getters (in erased contexts).
@0 getters-equal-if-setters-equal :
let open Lens in
(l₁ l₂ : Lens A B) →
set l₁ ≡ set l₂ →
get l₁ ≡ get l₂
getters-equal-if-setters-equal l₁ l₂ =
Lens.set l₁ ≡ Lens.set l₂ ↔⟨⟩
T.Lens.set (trad l₁) ≡ T.Lens.set (trad l₂) ↝⟨ T.getters-equal-if-setters-equal (trad l₁) (trad l₂) ⟩
T.Lens.get (trad l₁) ≡ T.Lens.get (trad l₂) ↔⟨⟩
Lens.get l₁ ≡ Lens.get l₂ □
-- If the forward direction of an equivalence with erased proofs is
-- Lens.get l, then the setter of l can be expressed using the other
-- direction of the equivalence (in erased contexts).
@0 from≡set :
∀ (l : Lens A B) is-equiv →
let open Lens
A≃B = EEq.⟨ get l , is-equiv ⟩
in
∀ a b → _≃ᴱ_.from A≃B b ≡ set l a b
from≡set l is-equiv =
T.from≡set (trad l) (EEq.Is-equivalenceᴱ→Is-equivalence is-equiv)
------------------------------------------------------------------------
-- Some lens isomorphisms
-- If B is a proposition, then Lens A B is isomorphic to
-- (A → B) × something.
lens-to-proposition↔ :
Is-proposition B →
Lens A B ↔
(A → B) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased (∀ a → a ≡ a)
lens-to-proposition↔ {B = B} {A = A} B-prop =
Lens A B ↝⟨ Lens-as-Σ ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))) ↝⟨ (∃-cong λ get → ∃-cong λ set → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒↝ _ (
(set (set a b₁) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a b) b₂ ≡ _) (B-prop _ _) ⟩
(set (set a (get a)) b₂ ≡ set a b₂) ≡⟨ cong (λ b → set (set a (get a)) b ≡ _) (B-prop _ _) ⟩
(set (set a (get a)) (get (set a (get a))) ≡ set a b₂) ≡⟨ cong (λ b → _ ≡ set a b) (B-prop _ _) ⟩∎
(set (set a (get a)) (get (set a (get a))) ≡ set a (get a)) ∎))) ⟩
(∃ λ (get : A → B) →
∃ λ (set : A → B → A) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a → B → B →
set (set a (get a)) (get (set a (get a))) ≡
set a (get a)))) ↝⟨ (∃-cong λ get →
Σ-cong (A→B→A↔A→A get) λ set →
Erased-cong (
drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ $
Π-closure ext 0 λ _ →
Π-closure ext 0 λ _ →
+⇒≡ B-prop)) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
((∀ a → f a ≡ a) ×
(∀ a → B → B → f (f a) ≡ f a))) ↝⟨ (∃-cong λ get → ∃-cong λ _ → Erased-cong (∃-cong λ _ →
∀-cong ext λ a →
drop-⊤-left-Π ext (B↔⊤ (get a)))) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
((∀ a → f a ≡ a) ×
(∀ a → B → f (f a) ≡ f a))) ↝⟨ (∃-cong λ get → ∃-cong λ _ → Erased-cong (∃-cong λ _ →
∀-cong ext λ a →
drop-⊤-left-Π ext (B↔⊤ (get a)))) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
((∀ a → f a ≡ a) ×
(∀ a → f (f a) ≡ f a))) ↝⟨ (∃-cong λ _ → ∃-cong λ f → Erased-cong (
Σ-cong (Eq.extensionality-isomorphism ext) λ f≡id →
∀-cong ext λ a →
≡⇒↝ _ (cong₂ _≡_ (trans (f≡id (f a)) (f≡id a)) (f≡id a )))) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased
(f ≡ P.id ×
(∀ a → a ≡ a))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-Σ↔Σ) ⟩
((A → B) ×
∃ λ (f : A → A) →
Erased (f ≡ P.id) ×
Erased (∀ a → a ≡ a)) ↝⟨ (∃-cong λ _ → Σ-assoc) ⟩□
(A → B) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased (∀ a → a ≡ a) □
where
B↔⊤ : B → B ↔ ⊤
B↔⊤ b =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible B-prop b
A→B→A↔A→A : (A → B) → (A → B → A) ↔ (A → A)
A→B→A↔A→A get =
(A → B → A) ↝⟨ ∀-cong ext (λ a → drop-⊤-left-Π ext $ B↔⊤ (get a)) ⟩□
(A → A) □
-- If equality is very stable for A and B is a proposition, then
-- Lens A B is isomorphic to (A → B) × Erased ((a : A) → a ≡ a).
Very-stable-≡→lens-to-proposition↔ :
Very-stable-≡ A →
Is-proposition B →
Lens A B ↔ (A → B) × Erased ((a : A) → a ≡ a)
Very-stable-≡→lens-to-proposition↔ {A = A} {B = B} A-s B-prop =
Lens A B ↝⟨ lens-to-proposition↔ B-prop ⟩
(A → B) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased (∀ a → a ≡ a) ↝⟨ (∃-cong λ _ → drop-⊤-left-× λ _ →
_⇔_.to contractible⇔↔⊤ $
erased-singleton-contractible (Very-stable-Πⁿ ext 1 λ _ → A-s)) ⟩□
(A → B) × Erased (∀ a → a ≡ a) □
-- Lens A ⊤ is isomorphic to something × Erased ((a : A) → a ≡ a).
lens-to-⊤↔ :
Lens A ⊤ ↔
(∃ λ (f : A → A) → Erased (f ≡ P.id)) × Erased ((a : A) → a ≡ a)
lens-to-⊤↔ {A = A} =
Lens A ⊤ ↝⟨ lens-to-proposition↔ (mono₁ 0 ⊤-contractible) ⟩
(A → ⊤) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased ((a : A) → a ≡ a) ↝⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased ((a : A) → a ≡ a) □
-- If equality is very stable for A, then Lens A ⊤ is isomorphic to
-- Erased ((a : A) → a ≡ a).
Very-stable-≡→lens-to-⊤↔ :
Very-stable-≡ A →
Lens A ⊤ ↔ Erased ((a : A) → a ≡ a)
Very-stable-≡→lens-to-⊤↔ {A = A} A-s =
Lens A ⊤ ↝⟨ Very-stable-≡→lens-to-proposition↔ A-s (mono₁ 0 ⊤-contractible) ⟩
(A → ⊤) × Erased ((a : A) → a ≡ a) ↝⟨ drop-⊤-left-× (λ _ → →-right-zero) ⟩□
Erased ((a : A) → a ≡ a) □
-- Lens A ⊥ is isomorphic to ¬ A.
lens-to-⊥↔ : Lens A (⊥ {ℓ = b}) ↔ ¬ A
lens-to-⊥↔ {A = A} =
Lens A ⊥ ↝⟨ lens-to-proposition↔ ⊥-propositional ⟩
(A → ⊥) ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased ((a : A) → a ≡ a) ↝⟨ (×-cong₁ λ _ → →-cong ext F.id (Bij.⊥↔uninhabited ⊥-elim)) ⟩
¬ A ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ×
Erased ((a : A) → a ≡ a) ↝⟨ (∃-cong λ ¬a → drop-⊤-right λ _ → lemma₁ ¬a) ⟩
¬ A ×
(∃ λ (f : A → A) → Erased (f ≡ P.id)) ↝⟨ drop-⊤-right lemma₂ ⟩□
¬ A □
where
lemma₁ : ¬ A → Erased ((a : A) → a ≡ a) ↔ ⊤
lemma₁ ¬a =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(H-level-Erased 1
(Π-closure ext 1 λ a →
⊥-elim (¬a a)))
[ refl ]
lemma₂ : ¬ A → (∃ λ (f : A → A) → Erased (f ≡ P.id)) ↔ ⊤
lemma₂ ¬a =
_⇔_.to contractible⇔↔⊤ $
propositional⇒inhabited⇒contractible
(Σ-closure 1 →-prop λ _ →
H-level-Erased 1
(mono₁ 1 →-prop))
(P.id , [ refl _ ])
where
→-prop = Π-closure ext 1 λ a → ⊥-elim (¬a a)
-- See also lens-from-⊥↔⊤ and
-- lens-from-contractible↔codomain-contractible below.
------------------------------------------------------------------------
-- Some lens results related to h-levels
-- If the domain of a lens is inhabited and has h-level n, then the
-- codomain also has h-level n (in erased contexts).
@0 h-level-respects-lens-from-inhabited :
∀ n → Lens A B → A → H-level n A → H-level n B
h-level-respects-lens-from-inhabited n l =
T.h-level-respects-lens-from-inhabited n (trad l)
-- Lenses with contractible domains have contractible codomains (in
-- erased contexts).
@0 contractible-to-contractible :
Lens A B → Contractible A → Contractible B
contractible-to-contractible l =
T.contractible-to-contractible (trad l)
-- A variant for Contractibleᴱ.
Contractibleᴱ→Contractibleᴱ :
Lens A B → Contractibleᴱ A → Contractibleᴱ B
Contractibleᴱ→Contractibleᴱ l c@(a , _) =
EEq.Contractibleᴱ-respects-surjection
(Lens.get l)
(λ b → Lens.set l a b
, (Lens.get l (Lens.set l a b) ≡⟨ Lens.get-set l _ _ ⟩∎
b ∎))
c
-- If A and B have h-level n given the assumption that A is inhabited,
-- then Lens A B also has h-level n.
lens-preserves-h-level :
∀ n → (A → H-level n A) → (A → H-level n B) →
H-level n (Lens A B)
lens-preserves-h-level n hA hB =
H-level.respects-surjection (_↔_.surjection (inverse Lens-as-Σ)) n $
Σ-closure n (Π-closure ext n λ a →
hB a) λ _ →
Σ-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
hA a) λ _ →
H-level-Erased n
(×-closure n (Π-closure ext n λ a →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hB a)) $
×-closure n (Π-closure ext n λ a →
+⇒≡ $ mono₁ n (hA a))
(Π-closure ext n λ a →
Π-closure ext n λ _ →
Π-closure ext n λ _ →
+⇒≡ $ mono₁ n (hA a)))
-- If A has positive h-level n, then Lens A B also has h-level n (in
-- erased contexts).
@0 lens-preserves-h-level-of-domain :
∀ n → H-level (1 + n) A → H-level (1 + n) (Lens A B)
lens-preserves-h-level-of-domain {A = A} {B = B} n =
H-level (1 + n) A ↝⟨ T.lens-preserves-h-level-of-domain n ⟩
H-level (1 + n) (T.Lens A B) ↝⟨ H-level-cong _ (1 + n) (inverse Lens≃Traditional-lens) ⟩□
H-level (1 + n) (Lens A B) □
-- There is a type A such that Lens A ⊤ is not propositional (assuming
-- univalence).
¬-lens-to-⊤-propositional :
Univalence (# 0) →
∃ λ (A : Set a) → ¬ Is-proposition (Lens A ⊤)
¬-lens-to-⊤-propositional univ =
A′
, Stable-¬ _
[ Is-proposition (Lens A′ ⊤) ↝⟨ H-level-cong _ 1 Lens≃Traditional-lens ⟩
Is-proposition (T.Lens A′ ⊤) ↝⟨ proj₂ $ T.¬-lens-to-⊤-propositional univ ⟩□
⊥₀ □
]
where
A′ = _
------------------------------------------------------------------------
-- A conversion function
-- If A is a set, then Lens A B is equivalent to Coherent-lens A B.
≃coherent : @0 Is-set A → Lens A B ≃ Coherent-lens A B
≃coherent {A = A} {B = B} A-set = Eq.↔→≃
to
Coherent-lens.lens
(λ l → let l′ = Coherent-lens.lens l in
$⟨ H-level-Erased 1
(×-closure 1
(Π-closure ext 1 λ a →
mono₁ 2 (B-set l′ a))
(Π-closure ext 1 λ a →
Π-closure ext 1 λ _ →
Π-closure ext 1 λ _ →
mono₁ 2 (B-set l′ a))) ⟩
Is-proposition _ ↝⟨ (λ p → cong (l′ ,_) (p _ _)) ⦂ (_ → _) ⟩
(l′ , _) ≡ (l′ , _) ↔⟨ Eq.≃-≡ Coherent-lens-as-Σ ⟩□
to l′ ≡ l □)
refl
where
@0 B-set : Lens A B → A → Is-set B
B-set l a =
h-level-respects-lens-from-inhabited 2 l a A-set
to : Lens A B → Coherent-lens A B
to l = record
{ lens = l
; get-set-get = λ a → B-set l a _ _
; get-set-set = λ a _ _ → B-set l a _ _
}
-- The conversion preserves getters and setters.
≃coherent-preserves-getters-and-setters :
{A : Set a}
(@0 s : Is-set A) →
Preserves-getters-and-setters-⇔ A B
(_≃_.logical-equivalence (≃coherent s))
≃coherent-preserves-getters-and-setters _ =
(λ _ → refl _ , refl _)
, (λ _ → refl _ , refl _)
------------------------------------------------------------------------
-- Some equality characterisation lemmas
abstract
-- An equality characterisation lemma.
equality-characterisation₁ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))
equality-characterisation₁ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Lens-as-Σ)) ⟩
l₁′ ≡ l₂′ ↔⟨ Eq.≃-≡ (Eq.↔⇒≃ (inverse Σ-assoc)) ⟩
((get l₁ , set l₁) , proj₂ (proj₂ l₁′))
≡
((get l₂ , set l₂) , proj₂ (proj₂ l₂′)) ↝⟨ inverse Bij.Σ-≡,≡↔≡ ⟩
(∃ λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
gs (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ Σ-cong (inverse ≡×≡↔≡) (λ gs → ≡⇒↝ _ $
cong (λ (gs : (get l₁ , set l₁) ≡ (get l₂ , set l₂)) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
gs (proj₂ (proj₂ l₁′))
≡
proj₂ (proj₂ l₂′))
(sym $ _↔_.right-inverse-of ≡×≡↔≡ gs)) ⟩
(∃ λ (gs : get l₁ ≡ get l₂ × set l₁ ≡ set l₂) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
(_↔_.to ≡×≡↔≡ gs) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ inverse Σ-assoc ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
subst (λ (get , set) →
Erased
((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂)))
(_↔_.to ≡×≡↔≡ (g , s)) (proj₂ (proj₂ l₁′)) ≡
proj₂ (proj₂ l₂′)) ↝⟨ (∃-cong λ g → ∃-cong λ s → ≡⇒↝ _ $ cong (_≡ _) $
push-subst-[] {x≡y = _↔_.to ≡×≡↔≡ (g , s)}) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
[ subst (λ (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
(_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ] ≡
[ erased (proj₂ (proj₂ l₂′)) ]) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → inverse Erased-≡↔[]≡[]) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ (get , set) →
(∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))
(_↔_.to ≡×≡↔≡ (g , s)) (erased (proj₂ (proj₂ l₁′))) ≡
erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (≡⇒↝ _ $
cong (λ x → x ≡ erased (proj₂ (proj₂ l₂′)))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(( subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁)
, subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s))
(proj₂ (erased (proj₂ (proj₂ l₁′))))
) ≡
erased (proj₂ (proj₂ l₂′)))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (inverse ≡×≡↔≡)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) →
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂) })
(_↔_.to ≡×≡↔≡ (g , s))
(proj₂ (erased (proj₂ (proj₂ l₁′)))) ≡
proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ≡⇒↝ _ $
cong (λ x → x ≡ proj₂ (erased (proj₂ (proj₂ l₂′))))
(push-subst-, {y≡z = _↔_.to ≡×≡↔≡ (g , s)} _ _))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
( subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁)
, subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁)
) ≡
proj₂ (erased (proj₂ (proj₂ l₂′))))) ↝⟨ (∃-cong λ _ → ∃-cong λ _ → Erased-cong (∃-cong λ _ → inverse ≡×≡↔≡)) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
(subst (λ { (get , set) → ∀ a b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁) ≡
get-set l₂
×
subst (λ { (get , set) → ∀ a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁) ≡
set-get l₂
×
subst (λ { (get , set) →
∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁) ≡
set-set l₂)) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
lemma₁ (λ { (get , set) a → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s))
×-cong
lemma₁ (λ { (get , set) a → ∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a → subst (λ { (get , set) → ∀ b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a) ≡
get-set l₂ a)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a → subst (λ { (get , set) →
∀ b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a) ≡
set-set l₂ a))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)))
×-cong
F.id
×-cong
(∀-cong ext λ a →
lemma₁ (λ { (get , set) b₁ → ∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s))))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ → subst (λ { (get , set) →
∀ b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁) ≡
set-set l₂ a b₁))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ →
lemma₁ (λ { (get , set) b₂ → set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ { (get , set) → get (set a b) ≡ b })
(_↔_.to ≡×≡↔≡ (g , s)) (get-set l₁ a b) ≡
get-set l₂ a b)
×
(∀ a → subst (λ { (get , set) → set a (get a) ≡ a })
(_↔_.to ≡×≡↔≡ (g , s)) (set-get l₁ a) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ { (get , set) →
set (set a b₁) b₂ ≡ set a b₂ })
(_↔_.to ≡×≡↔≡ (g , s)) (set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b →
lemma₂ (λ { (get , set) → get (set a b) ≡ b }) g s)
×-cong
(∀-cong ext λ a →
lemma₂ (λ { (get , set) → set a (get a) ≡ a }) g s)
×-cong
(∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
lemma₂ (λ { (get , set) → set (set a b₁) b₂ ≡ set a b₂ }) g s))) ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ →
subst (λ get → set l₂ (set l₂ a b₁) b₂ ≡ set l₂ a b₂) g
(subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂)) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ x → x ≡ _) $ subst-const g)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) □
where
open Lens
l₁′ = _↔_.to Lens-as-Σ l₁
l₂′ = _↔_.to Lens-as-Σ l₂
abstract
lemma₁ :
∀ (C : A → B → Set c) (eq : u ≡ v) {f g} →
(subst (λ x → ∀ y → C x y) eq f ≡ g)
↔
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y)
lemma₁ C eq {f} {g} =
subst (λ x → ∀ y → C x y) eq f ≡ g ↔⟨ inverse $ Eq.extensionality-isomorphism ext ⟩
(∀ y → subst (λ x → ∀ y → C x y) eq f y ≡ g y) ↝⟨ (∀-cong ext λ y → ≡⇒↝ _ $
cong (λ x → x ≡ _) (sym $ push-subst-application eq _)) ⟩□
(∀ y → subst (λ x → C x y) eq (f y) ≡ g y) □
lemma₂ :
∀ (P : A × B → Set p) (x₁≡x₂ : x₁ ≡ x₂) (y₁≡y₂ : y₁ ≡ y₂) {p p′} →
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡ p′)
↔
(subst (λ x → P (x , y₂)) x₁≡x₂ (subst (λ y → P (x₁ , y)) y₁≡y₂ p)
≡
p′)
lemma₂ P x₁≡x₂ y₁≡y₂ {p = p} = ≡⇒↝ _ $ cong (_≡ _) $ elim¹
(λ y₁≡y₂ →
subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , y₁≡y₂)) p ≡
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) y₁≡y₂ p))
(subst P (_↔_.to ≡×≡↔≡ (x₁≡x₂ , refl _)) p ≡⟨⟩
subst P (cong₂ _,_ x₁≡x₂ (refl _)) p ≡⟨⟩
subst P (trans (cong (_, _) x₁≡x₂) (cong (_ ,_) (refl _))) p ≡⟨ cong (λ eq → subst P (trans (cong (_, _) x₁≡x₂) eq) p) $ cong-refl _ ⟩
subst P (trans (cong (_, _) x₁≡x₂) (refl _)) p ≡⟨ cong (λ eq → subst P eq p) $ trans-reflʳ _ ⟩
subst P (cong (_, _) x₁≡x₂) p ≡⟨ sym $ subst-∘ _ _ _ ⟩
subst (λ x → P (x , _)) x₁≡x₂ p ≡⟨ cong (subst (λ x → P (x , _)) x₁≡x₂) $ sym $ subst-refl _ _ ⟩∎
subst (λ x → P (x , _)) x₁≡x₂
(subst (λ y → P (_ , y)) (refl _) p) ∎)
_
-- Another equality characterisation lemma.
equality-characterisation₂ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))
equality-characterisation₂ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₁ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡
get-set l₂ a b)
×
(∀ a → subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡
set-get l₂ a)
×
(∀ a b₁ b₂ → subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b → ≡⇒↝ _ $ cong (_≡ _) $
lemma₁ g s a b)
×-cong
(∀-cong ext λ a → ≡⇒↝ _ $ cong (_≡ _) $
lemma₂ g s a)
×-cong
F.id)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) □
where
open Lens
@0 lemma₁ : ∀ _ _ _ _ → _
lemma₁ g s a b =
subst (λ get → get (set l₂ a b) ≡ b) g
(subst (λ set → get l₁ (set a b) ≡ b) s
(get-set l₁ a b)) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g eq) $
subst-in-terms-of-trans-and-cong
{f = λ set → get l₁ (set a b)} {g = λ _ → b}
{x≡y = s} {fx≡gx = (get-set l₁ a b)} ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (cong (const b) s))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(trans (get-set l₁ a b) (refl _))) ≡⟨ cong (λ eq → subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s)) eq)) $
trans-reflʳ _ ⟩
subst (λ get → get (set l₂ a b) ≡ b) g
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans _ (get-set l₁ a b)} ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(cong (const b) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → get (set l₂ a b)) g))
(trans (sym (cong (λ set → get l₁ (set a b)) s))
(get-set l₁ a b)) ≡⟨ sym $ trans-assoc _ _ (get-set l₁ a b) ⟩
trans (trans (sym (cong (λ get → get (set l₂ a b)) g))
(sym (cong (λ set → get l₁ (set a b)) s)))
(get-set l₁ a b) ≡⟨ cong (λ eq → trans eq (get-set l₁ a b)) $ sym $
sym-trans _ (cong (λ get → get (set l₂ a b)) g) ⟩
trans (sym (trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g)))
(get-set l₁ a b) ≡⟨⟩
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ∎
@0 lemma₂ : ∀ _ _ _ → _
lemma₂ g s a =
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(subst (λ set → set a (get l₁ a) ≡ a) s
(set-get l₁ a)) ≡⟨ cong (subst (λ get → set l₂ a (get a) ≡ a) g) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-get l₁ a} ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (cong (const a) s))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans _ eq))) $
cong-const s ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(trans (set-get l₁ a) (refl _))) ≡⟨ cong (λ eq → subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s)) eq)) $
trans-reflʳ _ ⟩
subst (λ get → set l₂ a (get a) ≡ a) g
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ subst-in-terms-of-trans-and-cong {x≡y = g}
{fx≡gx = trans (sym (cong (λ set → set a (get l₁ a)) s)) (set-get l₁ a)} ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(cong (const a) g)) ≡⟨ cong (λ eq → trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
eq)) $
cong-const g ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a))
(refl _)) ≡⟨ cong (trans _) $
trans-reflʳ _ ⟩
trans (sym (cong (λ get → set l₂ a (get a)) g))
(trans (sym (cong (λ set → set a (get l₁ a)) s))
(set-get l₁ a)) ≡⟨ sym $ trans-assoc _ _ (set-get l₁ a) ⟩
trans (trans (sym (cong (λ get → set l₂ a (get a)) g))
(sym (cong (λ set → set a (get l₁ a)) s)))
(set-get l₁ a) ≡⟨ cong (λ eq → trans eq (set-get l₁ a)) $ sym $
sym-trans _ (cong (λ get → set l₂ a (get a)) g) ⟩
trans (sym (trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g)))
(set-get l₁ a) ≡⟨⟩
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ∎
-- And another one.
equality-characterisation₃ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b →
trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))
equality-characterisation₃ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₂ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ → ≡⇒↝ _ $
lemma g s a b₁ b₂)) ⟩□
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))) □
where
open Lens
@0 lemma : ∀ _ _ _ _ _ → _
lemma g s a b₁ b₂ =
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) s
(set-set l₁ a b₁ b₂) ≡
set-set l₂ a b₁ b₂ ≡⟨ cong (_≡ _) $
subst-in-terms-of-trans-and-cong {x≡y = s} {fx≡gx = set-set l₁ a b₁ b₂} ⟩
trans (sym (cong (λ set → set (set a b₁) b₂) s))
(trans (set-set l₁ a b₁ b₂)
(cong (λ set → set a b₂) s)) ≡
set-set l₂ a b₁ b₂ ≡⟨ [trans≡]≡[≡trans-symˡ] _ _ _ ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (sym (sym (cong (λ set → set (set a b₁) b₂) s)))
(set-set l₂ a b₁ b₂) ≡⟨ cong (λ eq → trans _ (cong (λ set → set a b₂) s) ≡
trans eq (set-set l₂ a b₁ b₂)) $
sym-sym (cong (λ set → set (set a b₁) b₂) s) ⟩
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂) ∎
-- And yet another one.
equality-characterisation₄ :
let open Lens in
l₁ ≡ l₂
↔
∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
Erased
((∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(set-set l₂ a b₁ b₂)))
equality-characterisation₄ {l₁ = l₁} {l₂ = l₂} =
l₁ ≡ l₂ ↝⟨ equality-characterisation₃ ⟩
(∃ λ (g : get l₁ ≡ get l₂) →
∃ λ (s : set l₁ ≡ set l₂) →
Erased
((∀ a b → trans (sym (cong₂ (λ set get → get (set a b)) s g))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a → trans (sym (cong₂ (λ set get → set a (get a)) s g))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (cong (λ set → set a b₂) s) ≡
trans (cong (λ set → set (set a b₁) b₂) s)
(set-set l₂ a b₁ b₂)))) ↝⟨ (Σ-cong (inverse $ Eq.extensionality-isomorphism ext) λ g →
Σ-cong (inverse $
Eq.extensionality-isomorphism ext F.∘
∀-cong ext λ _ → Eq.extensionality-isomorphism ext) λ s →
Erased-cong (
(∀-cong ext λ a → ∀-cong ext λ b →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (get-set l₁ a b) ≡ _) (
cong₂ (λ set get → get (set a b)) s g ≡⟨⟩
trans (cong (λ set → get l₁ (set a b)) s)
(cong (λ get → get (set l₂ a b)) g) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ s ⟩
trans (cong (get l₁ ⊚ (_$ b)) (ext⁻¹ s a))
(ext⁻¹ g (set l₂ a b)) ≡⟨ cong (λ eq → trans eq (ext⁻¹ g (set l₂ a b))) $ sym $
cong-∘ _ _ (ext⁻¹ s a) ⟩∎
trans (cong (get l₁) (ext⁻¹ (ext⁻¹ s a) b))
(ext⁻¹ g (set l₂ a b)) ∎))
×-cong
(∀-cong ext λ a →
≡⇒↝ _ $ cong (λ eq → trans (sym eq) (set-get l₁ a) ≡ _) (
cong₂ (λ set get → set a (get a)) s g ≡⟨⟩
trans (cong (λ set → set a (get l₁ a)) s)
(cong (λ get → set l₂ a (get a)) g) ≡⟨ sym $ cong₂ trans (cong-∘ _ _ s) (cong-∘ _ _ g) ⟩
trans (ext⁻¹ (ext⁻¹ s a) (get l₁ a))
(cong (set l₂ a) (ext⁻¹ g a)) ∎))
×-cong
∀-cong ext λ a → ∀-cong ext λ b₁ → ∀-cong ext λ b₂ →
≡⇒↝ _ $
cong₂ (λ p q → trans _ p ≡
trans (cong (λ set → set (set a b₁) b₂) q)
(set-set l₂ a b₁ b₂)) (
cong (λ set → set a b₂) s ≡⟨ sym $ cong-∘ _ _ s ⟩∎
ext⁻¹ (ext⁻¹ s a) b₂ ∎)
(
s ≡⟨ sym $ _≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _ ⟩
⟨ext⟩ (ext⁻¹ s) ≡⟨ (cong ⟨ext⟩ $ ⟨ext⟩ λ _ → sym $
_≃_.right-inverse-of
(Eq.extensionality-isomorphism bad-ext) _) ⟩∎
⟨ext⟩ (⟨ext⟩ ⊚ ext⁻¹ ⊚ ext⁻¹ s) ∎))) ⟩□
(∃ λ (g : ∀ a → get l₁ a ≡ get l₂ a) →
∃ λ (s : ∀ a b → set l₁ a b ≡ set l₂ a b) →
Erased
((∀ a b →
trans (sym (trans (cong (get l₁) (s a b))
(g (set l₂ a b))))
(get-set l₁ a b) ≡
get-set l₂ a b) ×
(∀ a →
trans (sym (trans (s a (get l₁ a))
(cong (set l₂ a) (g a))))
(set-get l₁ a) ≡
set-get l₂ a) ×
(∀ a b₁ b₂ →
trans (set-set l₁ a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(set-set l₂ a b₁ b₂)))) □
where
open Lens
-- A lemma that can be used to prove that two lenses with
-- definitionally equal getters and setters are equal.
equal-laws→≡ :
{get : A → B} {set : A → B → A}
{l₁′ l₂′ : Erased ((∀ a b → get (set a b) ≡ b) ×
(∀ a → set a (get a) ≡ a) ×
(∀ a b₁ b₂ → set (set a b₁) b₂ ≡ set a b₂))} →
let l₁ = _↔_.from Lens-as-Σ (get , set , l₁′)
l₂ = _↔_.from Lens-as-Σ (get , set , l₂′)
open Lens
in
@0 (∀ a b → get-set l₁ a b ≡ get-set l₂ a b) →
@0 (∀ a → set-get l₁ a ≡ set-get l₂ a) →
@0 (∀ a b₁ b₂ → set-set l₁ a b₁ b₂ ≡ set-set l₂ a b₁ b₂) →
l₁ ≡ l₂
equal-laws→≡ {l₁′ = l₁′} {l₂′ = l₂′} hyp₁ hyp₂ hyp₃ =
_↔_.from equality-characterisation₂
( refl _
, refl _
, [ (λ a b →
trans (sym (cong₂ (λ set get → get (set a b))
(refl _) (refl _)))
(get-set l₁″ a b) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (get-set l₁″ a b) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (get-set l₁″ a b) ≡⟨ trans-reflˡ _ ⟩
get-set l₁″ a b ≡⟨ hyp₁ _ _ ⟩∎
get-set l₂″ a b ∎)
, (λ a →
trans (sym (cong₂ (λ set get → set a (get a))
(refl _) (refl _)))
(set-get l₁″ a) ≡⟨ cong (λ eq → trans (sym eq) _) $ cong₂-refl _ ⟩
trans (sym (refl _)) (set-get l₁″ a) ≡⟨ cong (flip trans _) sym-refl ⟩
trans (refl _) (set-get l₁″ a) ≡⟨ trans-reflˡ _ ⟩
set-get l₁″ a ≡⟨ hyp₂ _ ⟩∎
set-get l₂″ a ∎)
, (λ a b₁ b₂ →
subst (λ set → set (set a b₁) b₂ ≡ set a b₂) (refl _)
(set-set l₁″ a b₁ b₂) ≡⟨ subst-refl _ _ ⟩
set-set l₁″ a b₁ b₂ ≡⟨ hyp₃ _ _ _ ⟩∎
set-set l₂″ a b₁ b₂ ∎)
]
)
where
open Lens
l₁″ = _↔_.from Lens-as-Σ (_ , _ , l₁′)
l₂″ = _↔_.from Lens-as-Σ (_ , _ , l₂′)
-- An equality characterisation lemma for lenses from sets.
@0 equality-characterisation-for-sets :
let open Lens in
{l₁ l₂ : Lens A B} →
Is-set A →
l₁ ≡ l₂
↔
set l₁ ≡ set l₂
equality-characterisation-for-sets
{A = A} {B = B} {l₁ = l₁} {l₂ = l₂} A-set =
l₁ ≡ l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Traditional-lens ⟩
trad l₁ ≡ trad l₂ ↝⟨ T.equality-characterisation-for-sets A-set ⟩□
set l₁ ≡ set l₂ □
where
open Lens
------------------------------------------------------------------------
-- More lens isomorphisms
-- Lens ⊥ B is isomorphic to the unit type.
lens-from-⊥↔⊤ : Lens (⊥ {ℓ = a}) B ↔ ⊤
lens-from-⊥↔⊤ =
_⇔_.to contractible⇔↔⊤ $
record
{ get = ⊥-elim
; set = ⊥-elim
; get-set = λ a → ⊥-elim a
; set-get = λ a → ⊥-elim a
; set-set = λ a → ⊥-elim a
} ,
λ l → _↔_.from equality-characterisation₁
( ⟨ext⟩ (λ a → ⊥-elim a)
, ⟨ext⟩ (λ a → ⊥-elim a)
, [ (λ a → ⊥-elim a)
, (λ a → ⊥-elim a)
, (λ a → ⊥-elim a)
]
)
-- If A is contractible with erased proofs, then there is an
-- equivalence with erased proofs between Lens A B and
-- Contractibleᴱ B.
Lens-Contractibleᴱ↔Contractibleᴱ :
Contractibleᴱ A →
Lens A B ≃ᴱ Contractibleᴱ B
Lens-Contractibleᴱ↔Contractibleᴱ cA@(a , [ irrA ]) = EEq.⇔→≃ᴱ
(lens-preserves-h-level-of-domain 0
(mono₁ 0 (EEq.Contractibleᴱ→Contractible cA)))
(EEq.Contractibleᴱ-propositional ext)
(flip Contractibleᴱ→Contractibleᴱ cA)
(λ (b , [ irrB ]) → record
{ get = λ _ → b
; set = λ _ _ → a
; get-set = λ _ → irrB
; set-get = irrA
; set-set = λ _ _ _ → irrA a
})
------------------------------------------------------------------------
-- Lens combinators
private
module TLC = T.Lens-combinators
module Lens-combinators where
-- If two types are isomorphic, then there is a lens between them.
↔→lens : A ↔ B → Lens A B
↔→lens A↔B = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = left-inverse-of
; set-set = λ _ _ _ → refl _
}
where
open _↔_ A↔B
-- If there is an equivalence with erased proofs between two types,
-- then there is a lens between them.
≃ᴱ→lens : A ≃ᴱ B → Lens A B
≃ᴱ→lens A≃B = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = left-inverse-of
; set-set = λ _ _ _ → refl _
}
where
open _≃ᴱ_ A≃B
-- Identity lens.
id : Lens A A
id = Traditional-lens→Lens TLC.id
-- The identity lens is equal to the one obtained from the
-- traditional identity lens without erased proofs.
Traditional-lens-id≡id :
Traditional-lens→Lens TLC.id ≡ id {A = A}
Traditional-lens-id≡id = refl _
-- Composition of lenses.
infixr 9 _∘_
_∘_ : Lens B C → Lens A B → Lens A C
l₁ ∘ l₂ = record
{ get = λ a → get l₁ (get l₂ a)
; set = λ a c →
let b = set l₁ (get l₂ a) c in
set l₂ a b
; get-set = T.Lens.get-set l₁∘l₂
; set-get = T.Lens.set-get l₁∘l₂
; set-set = T.Lens.set-set l₁∘l₂
}
where
open Lens
@0 l₁∘l₂ : _
l₁∘l₂ = trad l₁ TLC.∘ trad l₂
-- Traditional-lens→Lens commutes with composition.
Traditional-lens-∘≡∘ :
{l₁ : T.Lens B C} {l₂ : T.Lens A B} →
Traditional-lens→Lens (l₁ TLC.∘ l₂) ≡
Traditional-lens→Lens l₁ ∘ Traditional-lens→Lens l₂
Traditional-lens-∘≡∘ = refl _
-- Note that composition can be defined in several different ways.
-- Here is one alternative implementation.
infixr 9 _∘′_
_∘′_ : Lens B C → Lens A B → Lens A C
l₁ ∘′ l₂ = record (l₁ ∘ l₂)
{ set-set = T.Lens.set-set l₁∘′l₂
}
where
@0 l₁∘′l₂ : _
l₁∘′l₂ = trad l₁ TLC.∘′ trad l₂
-- This implementation is pointwise equal to the other one. However,
-- I don't know if there is some other definition that is distinct
-- from these two (if we require that the definitions are
-- polymorphic, that get and set are implemented in the same way as
-- for _∘_, and that the three composition laws below hold).
∘≡∘′ : l₁ ∘ l₂ ≡ l₁ ∘′ l₂
∘≡∘′ {l₁ = l₁} {l₂ = l₂} = equal-laws→≡
(λ _ _ → refl _)
(λ _ → refl _)
(λ a c₁ c₂ →
let b₁ = set l₁ (get l₂ a) c₁
b₂ = set l₁ (get l₂ a) c₂
a′ = set l₂ a b₁
b′ = set l₁ (get l₂ a′) c₂
eq : b′ ≡ b₂
eq = trans (cong (λ x → set l₁ x c₂)
(get-set l₂ a b₁))
(set-set l₁ (get l₂ a) c₁ c₂)
in
set-set (l₁ ∘ l₂) a c₁ c₂ ≡⟨⟩
trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡⟨ elim¹
(λ {b₂} eq → trans (set-set l₂ a b₁ b′) (cong (set l₂ a) eq) ≡
trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂))
(
trans (set-set l₂ a b₁ b′) (cong (set l₂ a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩
trans (set-set l₂ a b₁ b′) (refl _) ≡⟨ trans-reflʳ _ ⟩
set-set l₂ a b₁ b′ ≡⟨ sym $ trans-reflˡ _ ⟩
trans (refl _) (set-set l₂ a b₁ b′) ≡⟨ cong (flip trans _) $ sym $ cong-refl _ ⟩∎
trans (cong (set l₂ a′) (refl _)) (set-set l₂ a b₁ b′) ∎)
eq ⟩
trans (cong (set l₂ a′) eq) (set-set l₂ a b₁ b₂) ≡⟨⟩
set-set (l₁ ∘′ l₂) a c₁ c₂ ∎)
where
open Lens
-- id is a left identity of _∘_.
left-identity : (l : Lens A B) → id ∘ l ≡ l
left-identity l = equal-laws→≡
(λ a b →
trans (cong P.id (get-set a b)) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong P.id (get-set a b) ≡⟨ sym $ cong-id _ ⟩∎
get-set a b ∎)
(λ a →
trans (cong (set a) (refl _)) (set-get a) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (set-get a) ≡⟨ trans-reflˡ _ ⟩∎
set-get a ∎)
(λ a b₁ b₂ →
trans (set-set a b₁ b₂)
(cong (set a)
(trans (cong (λ _ → b₂) (get-set a b₁)) (refl _))) ≡⟨ cong (λ eq → trans _ (cong (set a) eq)) $ trans-reflʳ _ ⟩
trans (set-set a b₁ b₂)
(cong (set a) (cong (λ _ → b₂) (get-set a b₁))) ≡⟨ cong (λ eq → trans _ (cong (set a) eq)) $ cong-const _ ⟩
trans (set-set a b₁ b₂) (cong (set a) (refl _)) ≡⟨ cong (trans _) $ cong-refl _ ⟩
trans (set-set a b₁ b₂) (refl _) ≡⟨ trans-reflʳ _ ⟩∎
set-set a b₁ b₂ ∎)
where
open Lens l
-- id is a right identity of _∘_.
right-identity : (l : Lens A B) → l ∘ id ≡ l
right-identity l = equal-laws→≡
(λ a b →
trans (cong get (refl _)) (get-set a b) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (get-set a b) ≡⟨ trans-reflˡ _ ⟩∎
get-set a b ∎)
(λ a →
trans (cong P.id (set-get a)) (refl _) ≡⟨ trans-reflʳ _ ⟩
cong P.id (set-get a) ≡⟨ sym $ cong-id _ ⟩∎
set-get a ∎)
(λ a b₁ b₂ →
trans (refl _) (cong P.id (trans (cong (λ a → set a b₂) (refl _))
(set-set a b₁ b₂))) ≡⟨ trans-reflˡ _ ⟩
cong P.id (trans (cong (λ a → set a b₂) (refl _))
(set-set a b₁ b₂)) ≡⟨ sym $ cong-id _ ⟩
trans (cong (λ a → set a b₂) (refl _)) (set-set a b₁ b₂) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (set-set a b₁ b₂) ≡⟨ trans-reflˡ _ ⟩∎
set-set a b₁ b₂ ∎)
where
open Lens l
-- _∘_ is associative.
associativity :
(l₁ : Lens C D) (l₂ : Lens B C) (l₃ : Lens A B) →
l₁ ∘ (l₂ ∘ l₃) ≡ (l₁ ∘ l₂) ∘ l₃
associativity l₁ l₂ l₃ = equal-laws→≡ lemma₁ lemma₂ lemma₃
where
open Lens
@0 lemma₁ : _
lemma₁ = λ a d →
let
f = get l₁
g = get l₂
b = get l₃ a
c = g b
c′ = set l₁ c d
x = get-set l₃ a (set l₂ b c′)
y = get-set l₂ b c′
z = get-set l₁ c d
in
trans (cong f $ trans (cong g x) y) z ≡⟨ cong (λ x → trans x z) (cong-trans f _ y) ⟩
trans (trans (cong f $ cong g x) (cong f y)) z ≡⟨ trans-assoc _ _ z ⟩
trans (cong f $ cong g x) (trans (cong f y) z) ≡⟨ cong (λ x → trans x (trans (cong f y) z)) (cong-∘ f g x) ⟩∎
trans (cong (f ⊚ g) x) (trans (cong f y) z) ∎
@0 lemma₂ : _
lemma₂ = λ a →
let
b = get l₃ a
f = set l₃ a
g = set l₂ b
x = set-get l₁ (get l₂ b)
y = set-get l₂ b
z = set-get l₃ a
in
trans (cong (f ⊚ g) x) (trans (cong f y) z) ≡⟨ sym $ trans-assoc _ _ z ⟩
trans (trans (cong (f ⊚ g) x) (cong f y)) z ≡⟨ cong (λ x → trans (trans x (cong f y)) z) (sym $ cong-∘ f g x) ⟩
trans (trans (cong f (cong g x)) (cong f y)) z ≡⟨ cong (λ x → trans x z) (sym $ cong-trans f _ y) ⟩∎
trans (cong f $ trans (cong g x) y) z ∎
@0 lemma₃ : _
lemma₃ = λ a d₁ d₂ →
let
f = set l₃ a
g = set l₂ (get l₃ a)
h = λ x → set l₁ x d₂
i = get l₂
c₁ = set l₁ (get (l₂ ∘ l₃) a) d₁
c₂ = h (i (get l₃ a))
c₂′ = h (i (get l₃ (set (l₂ ∘ l₃) a c₁)))
c₂″ = h (i (set l₂ (get l₃ a) c₁))
b₁ = set l₂ (get l₃ a) c₁
b₁′ = get l₃ (set l₃ a b₁)
x = set-set l₃ a b₁ (set l₂ b₁′ c₂′)
y = get-set l₃ a b₁
z = set-set l₂ (get l₃ a) c₁
u = get-set l₂ (get l₃ a) c₁
v = set-set l₁ (get (l₂ ∘ l₃) a) d₁ d₂
c₂′≡c₂″ =
c₂′ ≡⟨ cong (h ⊚ i) y ⟩∎
c₂″ ∎
lemma₁₀ =
trans (sym (cong (h ⊚ i) y)) (cong h (cong i y)) ≡⟨ cong (trans _) (cong-∘ h i y) ⟩
trans (sym (cong (h ⊚ i) y)) (cong (h ⊚ i) y) ≡⟨ trans-symˡ (cong (h ⊚ i) y) ⟩∎
refl _ ∎
lemma₉ =
trans (cong (λ x → set l₂ x c₂′) y) (cong (set l₂ b₁) c₂′≡c₂″) ≡⟨ cong (trans (cong (λ x → set l₂ x c₂′) y))
(cong-∘ (set l₂ b₁) (h ⊚ i) y) ⟩
trans (cong (λ x → set l₂ x (h (i b₁′))) y)
(cong (λ x → set l₂ b₁ (h (i x ))) y) ≡⟨ trans-cong-cong (λ x y → set l₂ x (h (i y))) y ⟩∎
cong (λ x → set l₂ x (h (i x))) y ∎
lemma₈ =
sym (cong (set l₂ b₁) (sym c₂′≡c₂″)) ≡⟨ sym $ cong-sym (set l₂ b₁) (sym c₂′≡c₂″) ⟩
cong (set l₂ b₁) (sym (sym c₂′≡c₂″)) ≡⟨ cong (cong (set l₂ b₁)) (sym-sym c₂′≡c₂″) ⟩∎
cong (set l₂ b₁) c₂′≡c₂″ ∎
lemma₇ =
trans (cong g (sym c₂′≡c₂″)) (cong g (cong h (cong i y))) ≡⟨ sym $ cong-trans g _ (cong h (cong i y)) ⟩
cong g (trans (sym c₂′≡c₂″) (cong h (cong i y))) ≡⟨ cong (cong g) lemma₁₀ ⟩
cong g (refl _) ≡⟨ cong-refl _ ⟩∎
refl _ ∎
lemma₆ =
trans (cong (λ x → set l₂ x c₂′) y)
(trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″)))) ≡⟨ sym $ trans-assoc _ _ (trans _ (cong g (sym c₂′≡c₂″))) ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y)
(cong (set l₂ b₁) c₂′≡c₂″))
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₉ ⟩
trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ sym $ trans-assoc _ _ (cong g (sym c₂′≡c₂″)) ⟩∎
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(cong g (sym c₂′≡c₂″)) ∎
lemma₅ =
z c₂′ ≡⟨ sym $ dcong z (sym c₂′≡c₂″) ⟩
subst (λ x → set l₂ b₁ x ≡ g x) (sym c₂′≡c₂″) (z c₂″) ≡⟨ subst-in-terms-of-trans-and-cong {f = set l₂ b₁} {g = g} {x≡y = sym c₂′≡c₂″} ⟩
trans (sym (cong (set l₂ b₁) (sym c₂′≡c₂″)))
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ≡⟨ cong (λ e → trans e (trans (z c₂″) (cong g (sym c₂′≡c₂″)))) lemma₈ ⟩∎
trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″))) ∎
lemma₄ =
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans (trans (cong (λ x → set l₂ x c₂′) y) e)
(cong g (cong h (cong i y))))
lemma₅ ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y)
(trans (cong (set l₂ b₁) c₂′≡c₂″)
(trans (z c₂″) (cong g (sym c₂′≡c₂″)))))
(cong g (cong h (cong i y))) ≡⟨ cong (λ e → trans e (cong g (cong h (cong i y)))) lemma₆ ⟩
trans (trans (trans (cong (λ x → set l₂ x (h (i x))) y)
(z c₂″))
(cong g (sym c₂′≡c₂″)))
(cong g (cong h (cong i y))) ≡⟨ trans-assoc _ _ (cong g (cong h (cong i y))) ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(trans (cong g (sym c₂′≡c₂″))
(cong g (cong h (cong i y)))) ≡⟨ cong (trans (trans _ (z c₂″))) lemma₇ ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(refl _) ≡⟨ trans-reflʳ _ ⟩∎
trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″) ∎
lemma₃ =
cong g (trans (cong h (trans (cong i y) u)) v) ≡⟨ cong (λ e → cong g (trans e v)) (cong-trans h _ u) ⟩
cong g (trans (trans (cong h (cong i y)) (cong h u)) v) ≡⟨ cong (cong g) (trans-assoc _ _ v) ⟩
cong g (trans (cong h (cong i y)) (trans (cong h u) v)) ≡⟨ cong-trans g _ (trans _ v) ⟩∎
trans (cong g (cong h (cong i y)))
(cong g (trans (cong h u) v)) ∎
lemma₂ =
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (trans (trans _ (z c₂′))) lemma₃ ⟩
trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(trans (cong g (cong h (cong i y)))
(cong g (trans (cong h u) v))) ≡⟨ sym $ trans-assoc _ _ (cong g (trans _ v)) ⟩
trans (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (cong h (cong i y))))
(cong g (trans (cong h u) v)) ≡⟨ cong (λ e → trans e (cong g (trans (cong h u) v))) lemma₄ ⟩
trans (trans (cong (λ x → set l₂ x (h (i x))) y) (z c₂″))
(cong g (trans (cong h u) v)) ≡⟨ trans-assoc _ _ (cong g (trans _ v)) ⟩∎
trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (trans (cong h u) v))) ∎
lemma₁ =
trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))
(cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ cong (λ e → trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))
e)
(sym $ cong-∘ f g (trans _ v)) ⟩
trans (cong f (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′)))
(cong f (cong g (trans (cong h (trans (cong i y) u))
v))) ≡⟨ sym $ cong-trans f (trans _ (z c₂′)) (cong g (trans _ v)) ⟩
cong f (trans (trans (cong (λ x → set l₂ x c₂′) y) (z c₂′))
(cong g (trans (cong h (trans (cong i y) u))
v))) ≡⟨ cong (cong f) lemma₂ ⟩∎
cong f (trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″) (cong g (trans (cong h u) v)))) ∎
in
trans (trans x (cong f (trans (cong (λ x → set l₂ x c₂′) y)
(z c₂′))))
(cong (f ⊚ g) (trans (cong h (trans (cong i y) u)) v)) ≡⟨ trans-assoc _ _ (cong (f ⊚ g) (trans _ v)) ⟩
trans x (trans (cong f (trans (cong (λ x → set l₂ x c₂′) y)
(z c₂′)))
(cong (f ⊚ g)
(trans (cong h (trans (cong i y) u)) v))) ≡⟨ cong (trans x) lemma₁ ⟩∎
trans x (cong f (trans (cong (λ x → set l₂ x (h (i x))) y)
(trans (z c₂″)
(cong g (trans (cong h u) v))))) ∎
-- Every lens of type Lens A A that satisfies a certain right
-- identity law is equal to the identity lens.
id-unique :
(id′ : Lens A A) →
((l : Lens A A) → l ∘ id′ ≡ l) →
id′ ≡ id
id-unique id′ right-identity =
id′ ≡⟨ sym $ left-identity _ ⟩
id ∘ id′ ≡⟨ right-identity _ ⟩∎
id ∎
-- An equality characterisation lemma that can be used when one of
-- the lenses is the identity.
equality-characterisation-id :
{l : Lens A A} → let open Lens l in
l ≡ id
↔
∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))
equality-characterisation-id {l = l} =
l ≡ id ↝⟨ equality-characterisation₄ ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b →
trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡
refl _) ×
(∀ a →
trans (sym (trans (s a (get a)) (cong P.id (g a))))
(set-get a) ≡
refl _) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
trans (cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)))
(refl _)))) ↝⟨ (∃-cong λ g → ∃-cong λ _ → Erased-cong (∃-cong λ _ →
(∀-cong ext λ _ →
≡⇒↝ _ $ cong (λ eq → trans (sym (trans _ eq)) (set-get _) ≡ _) $ sym $
cong-id (g _))
×-cong
∀-cong ext λ _ → ∀-cong ext λ _ → ∀-cong ext λ _ →
≡⇒↝ _ $ cong (_ ≡_) $ trans-reflʳ _)) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b →
trans (sym (trans (cong get (s a b)) (g b))) (get-set a b) ≡
refl _) ×
(∀ a →
trans (sym (trans (s a (get a)) (g a))) (set-get a) ≡
refl _) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↝⟨ (∃-cong λ g → ∃-cong λ s → Erased-cong (
(∀-cong ext λ _ → ∀-cong ext λ _ →
≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘
≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm)
×-cong
(∀-cong ext λ _ →
≡-comm F.∘ ≡⇒↝ _ (cong (_≡ _) $ trans-reflʳ _) F.∘
≡⇒↝ _ (sym $ [trans≡]≡[≡trans-symˡ] _ _ _) F.∘ ≡-comm)
×-cong
F.id)) ⟩□
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a b → set a b ≡ b) →
Erased
((∀ a b → get-set a b ≡ trans (cong get (s a b)) (g b)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a b₁ b₂ →
trans (set-set a b₁ b₂) (s a b₂) ≡
cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) □
where
open Lens l
-- A lemma that can be used to show that a lens with a constant
-- setter (such as the ones produced by getter-equivalence→lens
-- below) is equal to the identity lens.
constant-setter→≡id :
{l′ : ∃ λ (get : A → A) →
∃ λ (set : A → A) →
Erased
((A → ∀ a → get (set a) ≡ a) ×
(∀ a → set (get a) ≡ a) ×
(A → A → ∀ a → set a ≡ set a))} →
let l = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′)
set = proj₁ (proj₂ l′)
open Lens l hiding (set)
in
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) →
l ≡ id
constant-setter→≡id {A = A} {l′ = l′} =
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → set-set a a₁ a₂ ≡ refl _))) ↝⟨ (Σ-map P.id $ Σ-map P.id λ {s} → Erased-cong (
Σ-map P.id $ Σ-map P.id λ hyp a a₁ a₂ →
trans (set-set a a₁ a₂) (s a₂) ≡⟨ cong (λ eq → trans eq (s a₂)) $ hyp _ _ _ ⟩
trans (refl _) (s a₂) ≡⟨ trans-reflˡ (s _) ⟩∎
s a₂ ∎)) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ → trans (set-set a a₁ a₂) (s a₂) ≡ s a₂))) ↔⟨ (∃-cong λ _ → ∃-cong λ s → Erased-cong (∃-cong λ _ → ∃-cong λ _ →
∀-cong ext λ a → ∀-cong ext λ a₁ → ∀-cong ext λ a₂ →
≡⇒↝ F.equivalence $ cong (trans _ (s _) ≡_) (
s a₂ ≡⟨ sym $ cong-ext s ⟩
cong (λ set → set a₂) (⟨ext⟩ s) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ s) ⟩
cong (λ set → set (set a a₁) a₂) (cong const (⟨ext⟩ s)) ≡⟨ cong (cong (λ set → set (set a a₁) a₂)) $ sym $
ext-const (⟨ext⟩ s) ⟩∎
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s) ∎))) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s (get a)) (g a)) ×
(∀ a a₁ a₂ →
trans (set-set a a₁ a₂) (s a₂) ≡
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ λ _ → ⟨ext⟩ s)))) ↝⟨ Σ-map P.id (Σ-map const P.id) ⟩
(∃ λ (g : ∀ a → get a ≡ a) →
∃ λ (s : A → ∀ a → set a ≡ a) →
Erased
((∀ a₁ a₂ → get-set a₁ a₂ ≡ trans (cong get (s a₁ a₂)) (g a₂)) ×
(∀ a → set-get a ≡ trans (s a (get a)) (g a)) ×
(∀ a a₁ a₂ →
trans (set-set a a₁ a₂) (s a a₂) ≡
cong (λ set → set (set a a₁) a₂) (⟨ext⟩ (⟨ext⟩ ⊚ s))))) ↔⟨ inverse equality-characterisation-id ⟩□
l″ ≡ id □
where
l″ = _↔_.from Lens-as-Σ (Σ-map P.id (Σ-map const P.id) l′)
set = proj₁ (proj₂ l′)
open Lens l″ hiding (set)
-- An identity function for lenses for which the forward direction
-- is an equivalence (with erased proofs).
--
-- Note that the setter of the resulting lens is definitionally
-- equal to a constant function returning the right-to-left
-- direction of the equivalence.
--
-- Note also that two proofs, set-get and set-set, have been
-- "obfuscated". They could have been shorter, but then it might not
-- have been possible to prove getter-equivalence→lens≡.
getter-equivalence→lens :
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) →
Lens A B
getter-equivalence→lens l is-equiv = record
{ get = to
; set = const from
; get-set = const right-inverse-of
; set-get = λ a →
from (to a) ≡⟨ cong from (sym (get-set a (to a))) ⟩
from (get (set a (to a))) ≡⟨⟩
from (to (set a (get a))) ≡⟨ cong (from ⊚ to) (set-get a) ⟩
from (to a) ≡⟨ left-inverse-of _ ⟩∎
a ∎
; set-set = λ a b₁ b₂ →
let s = from≡set l is-equiv in
from b₂ ≡⟨ cong (λ set → set (set a b₁) b₂) (⟨ext⟩ (⟨ext⟩ ⊚ s)) ⟩
set (set a b₁) b₂ ≡⟨ set-set a b₁ b₂ ⟩
set a b₂ ≡⟨ sym (s a b₂) ⟩∎
from b₂ ∎
}
where
A≃B = EEq.⟨ _ , is-equiv ⟩
open _≃ᴱ_ A≃B
open Lens l
-- In erased contexts it can be proved that the function
-- getter-equivalence→lens returns its input.
@0 getter-equivalence→lens≡ :
∀ (l : Lens A B) is-equiv →
getter-equivalence→lens l is-equiv ≡ l
getter-equivalence→lens≡ l is-equiv = $⟨ TLC.getter-equivalence→lens≡
(trad l) is-equiv′ ⟩
TLC.getter-equivalence→lens (trad l) is-equiv′ ≡
trad l ↝⟨ cong Traditional-lens→Lens ⟩□
getter-equivalence→lens l is-equiv ≡ l □
where
is-equiv′ = EEq.Is-equivalenceᴱ→Is-equivalence is-equiv
------------------------------------------------------------------------
-- Some existence results
-- There is, in general, no lens for the first projection from a
-- Σ-type.
no-first-projection-lens :
∃ λ (A : Set a) → ∃ λ (B : A → Set b) →
¬ Lens (Σ A B) A
no-first-projection-lens =
Non-dependent.no-first-projection-lens
Lens contractible-to-contractible
-- There are two lenses with equal setters that are not equal
-- (assuming univalence).
equal-setters-but-not-equal :
Univalence lzero →
∃ λ (A : Set) →
∃ λ (B : Set) →
∃ λ (l₁ : Lens A B) →
∃ λ (l₂ : Lens A B) →
Lens.set l₁ ≡ Lens.set l₂ ×
l₁ ≢ l₂
equal-setters-but-not-equal univ =
let A , B , l₁ , l₂ , set≡set , l₁≢l₂ =
T.equal-setters-but-not-equal univ
in
A
, B
, Traditional-lens→Lens l₁
, Traditional-lens→Lens l₂
, set≡set
, Stable-¬ _
[ Traditional-lens→Lens l₁ ≡ Traditional-lens→Lens l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Traditional-lens ⟩
l₁ ≡ l₂ ↝⟨ l₁≢l₂ ⟩□
⊥ □
]
-- There is a lens, for which the getter is an equivalence, that does
-- not satisfy either of the coherence laws that Coherent-lens lenses
-- must satisfy (assuming univalence).
getter-equivalence-but-not-coherent :
Univalence lzero →
∃ λ (A : Set) →
∃ λ (l : Lens A A) →
let open Lens l in
Is-equivalence get ×
¬ (∀ a → cong get (set-get a) ≡ get-set a (get a)) ×
¬ (∀ a₁ a₂ a₃ →
cong get (set-set a₁ a₂ a₃) ≡
trans (get-set (set a₁ a₂) a₃) (sym (get-set a₁ a₃)))
getter-equivalence-but-not-coherent univ =
let A , l , rest = T.getter-equivalence-but-not-coherent univ in
A , Traditional-lens→Lens l , rest
-- There are two distinct lenses with equal setters that have
-- equivalences as getters (assuming univalence).
equal-setters-and-equivalences-as-getters-but-not-equal :
Univalence lzero →
∃ λ (A : Set) →
∃ λ (l₁ : Lens A A) →
∃ λ (l₂ : Lens A A) →
Is-equivalence (Lens.get l₁) ×
Is-equivalence (Lens.get l₂) ×
Lens.set l₁ ≡ Lens.set l₂ ×
l₁ ≢ l₂
equal-setters-and-equivalences-as-getters-but-not-equal univ =
let A , l₁ , l₂ , is-equiv₁ , is-equiv₂ , set≡set , l₁≢l₂ =
T.equal-setters-and-equivalences-as-getters-but-not-equal univ
in
A
, Traditional-lens→Lens l₁
, Traditional-lens→Lens l₂
, is-equiv₁
, is-equiv₂
, set≡set
, Stable-¬ _
[ Traditional-lens→Lens l₁ ≡ Traditional-lens→Lens l₂ ↔⟨ inverse $ Eq.≃-≡ Lens≃Traditional-lens ⟩
l₁ ≡ l₂ ↝⟨ l₁≢l₂ ⟩□
⊥ □
]
-- There is in general no split surjection from equivalences with
-- erased proofs to lenses with getters that are equivalences with
-- erased proofs, if the right-to-left direction of the split
-- surjection is required to return the lens's getter plus some proof
-- (assuming univalence).
¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get :
Univalence lzero →
∃ λ (A : Set) →
¬ ∃ λ (f : (A ≃ᴱ A) ↠
(∃ λ (l : Lens A A) → Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)
¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ =
let A , l₁ , l₂ , is-equiv₁′ , is-equiv₂′ , setters-equal , l₁≢l₂ =
equal-setters-and-equivalences-as-getters-but-not-equal univ
is-equiv₁ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₁′
is-equiv₂ = EEq.Is-equivalence→Is-equivalenceᴱ is-equiv₂′
in
A
, Stable-¬ _
[ (λ (f , hyp) → $⟨ setters-equal ⟩
Lens.set l₁ ≡ Lens.set l₂ ↝⟨ getters-equal-if-setters-equal l₁ l₂ ⟩
Lens.get l₁ ≡ Lens.get l₂ ↝⟨ (λ eq → trans (hyp _) (trans eq (sym (hyp _)))) ⟩
_≃ᴱ_.to (_↠_.from f (l₁ , is-equiv₁)) ≡
_≃ᴱ_.to (_↠_.from f (l₂ , is-equiv₂)) ↝⟨ EEq.to≡to→≡ ext ⟩
_↠_.from f (l₁ , is-equiv₁) ≡
_↠_.from f (l₂ , is-equiv₂) ↝⟨ _↠_.to (Surjection.↠-≡ f) ⟩
(l₁ , is-equiv₁) ≡ (l₂ , is-equiv₂) ↝⟨ cong proj₁ ⟩
l₁ ≡ l₂ ↝⟨ l₁≢l₂ ⟩□
⊥ □)
]
-- There is in general no equivalence with erased proofs from
-- equivalences with erased proofs to lenses with getters that are
-- equivalences with erased proofs, if the right-to-left direction of
-- the equivalence is required to return the lens's getter plus some
-- proof (assuming univalence).
¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get :
Univalence lzero →
∃ λ (A : Set) →
¬ ∃ λ (f : (A ≃ᴱ A) ≃ᴱ
(∃ λ (l : Lens A A) → Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p)
¬-≃ᴱ-≃ᴱ-Σ-Lens-Is-equivalence-get univ =
let A , ∄ = ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ in
A
, Stable-¬ _
[ (∃ λ (f : (A ≃ᴱ A) ≃ᴱ
(∃ λ (l : Lens A A) → Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_≃ᴱ_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩
(∃ λ (f : (A ≃ᴱ A) ↠
(∃ λ (l : Lens A A) → Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ∄ ⟩□
⊥ □
]
------------------------------------------------------------------------
-- Isomorphisms expressed using lens quasi-inverses
private
module B {a} =
Bi-invertibility.Erased
equality-with-J (Set a) Lens
Lens-combinators.id Lens-combinators._∘_
module BM {a} =
B.More {a = a}
Lens-combinators.left-identity
Lens-combinators.right-identity
Lens-combinators.associativity
-- A form of isomorphism between types, expressed using lenses.
open B public using (_≅ᴱ_; Has-quasi-inverseᴱ)
-- T.Has-quasi-inverse l implies
-- Has-quasi-inverseᴱ (Traditional-lens→Lens l).
Has-quasi-inverse→Has-quasi-inverseᴱ :
(l : T.Lens A B) →
T.Has-quasi-inverse l → Has-quasi-inverseᴱ (Traditional-lens→Lens l)
Has-quasi-inverse→Has-quasi-inverseᴱ l =
(∃ λ l⁻¹ → l TLC.∘ l⁻¹ ≡ TLC.id × l⁻¹ TLC.∘ l ≡ TLC.id ) ↝⟨ Σ-map Traditional-lens→Lens
(Σ-map (cong Traditional-lens→Lens)
(cong Traditional-lens→Lens)) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ Σ-map P.id [_]→ ⟩□
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id)) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts Has-quasi-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to T.Has-quasi-inverse l.
@0 Has-quasi-inverseᴱ≃Has-quasi-inverse :
(l : T.Lens A B) →
Has-quasi-inverseᴱ (Traditional-lens→Lens l) ≃ T.Has-quasi-inverse l
Has-quasi-inverseᴱ≃Has-quasi-inverse l =
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id × l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ →
inverse (Eq.≃-≡ Lens≃Traditional-lens)
×-cong
inverse (Eq.≃-≡ Lens≃Traditional-lens)) ⟩□
(∃ λ l⁻¹ → l TLC.∘ l⁻¹ ≡ TLC.id × l⁻¹ TLC.∘ l ≡ TLC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- A T.≅ B implies A ≅ᴱ B.
≅→≅ᴱ : A T.≅ B → A ≅ᴱ B
≅→≅ᴱ {A = A} {B = B} =
(∃ λ (l : T.Lens A B) → T.Has-quasi-inverse l) ↝⟨ Σ-map Traditional-lens→Lens (λ {l} → Has-quasi-inverse→Has-quasi-inverseᴱ l) ⟩□
(∃ λ (l : Lens A B) → Has-quasi-inverseᴱ l) □
-- In erased contexts A ≅ᴱ B is equivalent to A T.≅ B.
@0 ≅ᴱ≃≅ : (A ≅ᴱ B) ≃ (A T.≅ B)
≅ᴱ≃≅ {A = A} {B = B} =
(∃ λ (l : Lens A B) → Has-quasi-inverseᴱ l) ↝⟨ Σ-cong-contra (inverse Lens≃Traditional-lens) Has-quasi-inverseᴱ≃Has-quasi-inverse ⟩□
(∃ λ (l : T.Lens A B) → T.Has-quasi-inverse l) □
-- An equality characterisation lemma for A ≅ B that applies when A is
-- a set.
@0 equality-characterisation-for-sets-≅ᴱ :
let open Lens in
{f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≅ᴱ B} →
Is-set A →
f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂
equality-characterisation-for-sets-≅ᴱ
{f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set =
f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≅ᴱ≃≅ ⟩
_≃_.to ≅ᴱ≃≅ f₁ ≡ _≃_.to ≅ᴱ≃≅ f₂ ↝⟨ T.equality-characterisation-for-sets-≅ A-set ⟩□
set l₁₁ ≡ set l₁₂ □
where
open Lens
-- There is a logical equivalence between A ≃ᴱ B and A ≅ᴱ B.
≃ᴱ⇔≅ᴱ : (A ≃ᴱ B) ⇔ (A ≅ᴱ B)
≃ᴱ⇔≅ᴱ {A = A} {B = B} = record
{ to = λ A≃B → ≃ᴱ→lens A≃B
, ≃ᴱ→lens (inverse A≃B)
, [ lemma A≃B
, (≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B ≡⟨ cong {x = A≃B} {y = inverse $ inverse A≃B}
(λ A≃B′ → ≃ᴱ→lens (inverse A≃B) ∘ ≃ᴱ→lens A≃B′) $
sym $ EEq.to≡to→≡ ext (refl _) ⟩
≃ᴱ→lens (inverse A≃B) ∘
≃ᴱ→lens (inverse $ inverse A≃B) ≡⟨ lemma (inverse A≃B) ⟩∎
id ∎)
]
; from = λ (l₁ , l₂ , [ eq₁ , eq₂ ]) → EEq.↔→≃ᴱ
(get l₁)
(get l₂)
(ext⁻¹ $
getters-equal-if-setters-equal (l₁ ∘ l₂) id
(cong set eq₁))
(ext⁻¹ $
getters-equal-if-setters-equal (l₂ ∘ l₁) id
(cong set eq₂))
}
where
open Lens
open Lens-combinators
@0 lemma :
(C≃D : C ≃ᴱ D) → ≃ᴱ→lens C≃D ∘ ≃ᴱ→lens (inverse C≃D) ≡ id
lemma C≃D = _↔_.from equality-characterisation₂
( ⟨ext⟩ (_≃ᴱ_.right-inverse-of C≃D)
, (⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
, [ lemma₁
, lemma₂
, lemma₃
]
)
where
@0 lemma₁ : _
lemma₁ = λ d₁ d₂ →
let lemma =
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))) $
ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₂)))
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ sym $ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)
(cong (λ set → set d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)) $ cong-ext _ ⟩
cong (_≃ᴱ_.to C≃D ⊚ _≃ᴱ_.from C≃D)
(_≃ᴱ_.right-inverse-of C≃D _) ≡⟨ sym $ cong-∘ _ _ (_≃ᴱ_.right-inverse-of C≃D _) ⟩
cong (_≃ᴱ_.to C≃D)
(cong (_≃ᴱ_.from C≃D) (_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong (cong (_≃ᴱ_.to C≃D)) $ _≃ᴱ_.right-left-lemma C≃D _ ⟩∎
cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _) ∎
in
trans (sym
(trans (cong (λ set → _≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D (set d₁ d₂)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))
(cong (λ get → get d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ cong₂ (λ p q → trans (sym (trans p q))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)))
lemma
(cong-ext _) ⟩
trans (sym
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)))
(trans (cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎
refl _ ∎
@0 lemma₂ : _
lemma₂ = λ d →
let lemma =
cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))) $
ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
cong (λ set → set (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ≡⟨ cong-ext _ ⟩∎
_≃ᴱ_.right-inverse-of C≃D _ ∎
in
trans (sym
(trans (cong (λ set → set d (_≃ᴱ_.to C≃D (_≃ᴱ_.from C≃D d)))
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))
(cong (λ get → get d)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))))
(trans
(cong (_≃ᴱ_.to C≃D) (_≃ᴱ_.left-inverse-of C≃D _))
(_≃ᴱ_.left-inverse-of (inverse C≃D) _)) ≡⟨ cong₂ (λ p q → trans (sym p) q)
(cong₂ trans lemma (cong-ext _))
(cong₂ trans
(_≃ᴱ_.left-right-lemma C≃D _)
(EEq.left-inverse-of∘inverse C≃D)) ⟩
trans (sym (trans (_≃ᴱ_.right-inverse-of C≃D _)
(_≃ᴱ_.right-inverse-of C≃D _)))
(trans (_≃ᴱ_.right-inverse-of C≃D _)
(_≃ᴱ_.right-inverse-of C≃D _)) ≡⟨ trans-symˡ (trans _ (_≃ᴱ_.right-inverse-of C≃D _)) ⟩∎
refl _ ∎
@0 lemma₃ : _
lemma₃ = λ d d₁ d₂ →
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(trans (refl _)
(cong (_≃ᴱ_.to C≃D)
(trans
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁)))
(refl _)))) ≡⟨ cong (λ eq → subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(trans (refl _) (cong (_≃ᴱ_.to C≃D) eq))) $
trans-reflʳ _ ⟩
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(⟨ext⟩ λ _ → ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(trans (refl _)
(cong (_≃ᴱ_.to C≃D)
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁))))) ≡⟨ cong₂ (λ p q → subst (λ set → set (set d d₁) d₂ ≡ set d d₂) p q)
(ext-const (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D))
(trans-reflˡ _) ⟩
subst (λ set → set (set d d₁) d₂ ≡ set d d₂)
(cong const $ ⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(cong (_≃ᴱ_.to C≃D)
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁)))) ≡⟨ sym $ subst-∘ _ _ (⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D) ⟩
subst (λ set → set d₂ ≡ set d₂)
(⟨ext⟩ $ _≃ᴱ_.right-inverse-of C≃D)
(cong (_≃ᴱ_.to C≃D)
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁)))) ≡⟨ subst-ext _ _ ⟩
subst (λ set → set ≡ set)
(_≃ᴱ_.right-inverse-of C≃D d₂)
(cong (_≃ᴱ_.to C≃D)
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁)))) ≡⟨ ≡⇒↝ _ (sym [subst≡]≡[trans≡trans]) (
trans
(cong (_≃ᴱ_.to C≃D)
(cong (λ _ → _≃ᴱ_.from C≃D d₂)
(_≃ᴱ_.right-inverse-of (inverse C≃D)
(_≃ᴱ_.from C≃D d₁))))
(_≃ᴱ_.right-inverse-of C≃D d₂) ≡⟨ cong (λ eq → trans (cong (_≃ᴱ_.to C≃D) eq)
(_≃ᴱ_.right-inverse-of C≃D d₂)) $
cong-const (_≃ᴱ_.right-inverse-of (inverse C≃D) _) ⟩
trans
(cong (_≃ᴱ_.to C≃D) (refl _))
(_≃ᴱ_.right-inverse-of C≃D d₂) ≡⟨ cong (flip trans _) $ cong-refl _ ⟩
trans (refl _) (_≃ᴱ_.right-inverse-of C≃D d₂) ≡⟨ trans-reflˡ _ ⟩
_≃ᴱ_.right-inverse-of C≃D d₂ ≡⟨ sym $ trans-reflʳ _ ⟩
trans (_≃ᴱ_.right-inverse-of C≃D d₂) (refl _) ∎) ⟩
refl _ ∎
-- In erased contexts the left-to-right direction of ≃ᴱ⇔≅ᴱ is a right
-- inverse of the right-to-left direction.
@0 ≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ :
(A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≅ᴱ (_⇔_.to ≃ᴱ⇔≅ᴱ A≃B) ≡ A≃B
≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ _ = EEq.to≡to→≡ ext (refl _)
-- The forward direction of ≃ᴱ⇔≅ᴱ maps identity to an isomorphism for
-- which the first projection is the identity.
≃ᴱ⇔≅ᴱ-id≡id :
let open Lens-combinators in
proj₁ (_⇔_.to ≃ᴱ⇔≅ᴱ F.id) ≡ id {A = A}
≃ᴱ⇔≅ᴱ-id≡id = equal-laws→≡
(λ _ _ → refl _)
(λ a →
_≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩
cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩
cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎
refl _ ∎)
(λ _ _ _ → refl _)
where
open Lens-combinators
-- If A is a set, then there is an equivalence with erased proofs
-- between A ≃ᴱ B and A ≅ᴱ B.
≃ᴱ≃ᴱ≅ᴱ :
@0 Is-set A →
(A ≃ᴱ B) ≃ᴱ (A ≅ᴱ B)
≃ᴱ≃ᴱ≅ᴱ A-set = EEq.↔→≃ᴱ
(_⇔_.to ≃ᴱ⇔≅ᴱ)
(_⇔_.from ≃ᴱ⇔≅ᴱ)
(λ (l₁ , l₂ , [ eq₁ , eq₂ ]) →
_↔_.from (equality-characterisation-for-sets-≅ᴱ A-set) $
⟨ext⟩ λ a → ⟨ext⟩ λ b →
get l₂ b ≡⟨ sym $ ext⁻¹ (ext⁻¹ (cong set eq₂) _) _ ⟩
set l₁ (set l₁ a b)
(set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ set-set l₁ _ _ _ ⟩
set l₁ a (set l₂ (get l₁ (set l₁ a b)) (get l₂ b)) ≡⟨ cong (λ b′ → set l₁ a (set l₂ b′ (get l₂ b))) $ get-set l₁ _ _ ⟩
set l₁ a (set l₂ b (get l₂ b)) ≡⟨ cong (set l₁ a) $ set-get l₂ _ ⟩∎
set l₁ a b ∎)
≃ᴱ⇔≅ᴱ∘≃ᴱ⇔≅ᴱ
where
open Lens
open Lens-combinators
-- The equivalence maps identity to an isomorphism for which the first
-- projection is the identity.
≃ᴱ≃ᴱ≅ᴱ-id≡id :
let open Lens-combinators in
(@0 A-set : Is-set A) →
proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≅ᴱ A-set) F.id) ≡ id
≃ᴱ≃ᴱ≅ᴱ-id≡id _ = ≃ᴱ⇔≅ᴱ-id≡id
-- There is not necessarily a split surjection from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ :
Univalence a →
¬ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l)
¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ {a = a} univ =
Stable-¬ _
[ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp l →
from-equivalence (Has-quasi-inverseᴱ≃Has-quasi-inverse l) F.∘
hyp (Traditional-lens→Lens l) F.∘
EEq.Is-equivalence≃Is-equivalenceᴱ ext) ⟩
({A B : Set a}
(l : T.Lens A B) →
Is-equivalence (T.Lens.get l) ↠ T.Has-quasi-inverse l) ↝⟨ T.¬Is-equivalence↠Has-quasi-inverse univ ⟩□
⊥ □
]
-- There is not necessarily an equivalence with erased proofs from
-- Is-equivalenceᴱ (Lens.get l) to Has-quasi-inverseᴱ l, if l is a
-- lens between types in the same universe (assuming univalence).
¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ :
Univalence a →
¬ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l)
¬Is-equivalenceᴱ≃Has-quasi-inverseᴱ {a = a} univ =
Stable-¬ _
[ ({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ≃ᴱ Has-quasi-inverseᴱ l) ↝⟨ (λ hyp → _≃_.surjection ⊚ EEq.≃ᴱ→≃ ⊚ hyp) ⟩
({A B : Set a}
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) ↠ Has-quasi-inverseᴱ l) ↝⟨ ¬Is-equivalenceᴱ↠Has-quasi-inverseᴱ univ ⟩□
⊥ □
]
------------------------------------------------------------------------
-- Isomorphisms expressed using bi-invertibility for lenses
-- A form of isomorphism between types, expressed using lenses.
open B public
using (_≊ᴱ_; Has-left-inverseᴱ; Has-right-inverseᴱ; Is-bi-invertibleᴱ)
-- T.Has-left-inverse l implies
-- Has-left-inverseᴱ (Traditional-lens→Lens l).
Has-left-inverse→Has-left-inverseᴱ :
(l : T.Lens A B) →
T.Has-left-inverse l → Has-left-inverseᴱ (Traditional-lens→Lens l)
Has-left-inverse→Has-left-inverseᴱ l =
(∃ λ l⁻¹ → l⁻¹ TLC.∘ l ≡ TLC.id ) ↝⟨ Σ-map Traditional-lens→Lens (cong Traditional-lens→Lens) ⟩
(∃ λ l⁻¹ → l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ Σ-map P.id [_]→ ⟩□
(∃ λ l⁻¹ → Erased (l⁻¹ LC.∘ l′ ≡ LC.id)) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts Has-left-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to T.Has-left-inverse l.
@0 Has-left-inverseᴱ≃Has-left-inverse :
(l : T.Lens A B) →
Has-left-inverseᴱ (Traditional-lens→Lens l) ≃ T.Has-left-inverse l
Has-left-inverseᴱ≃Has-left-inverse l =
(∃ λ l⁻¹ → Erased (l⁻¹ LC.∘ l′ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l⁻¹ LC.∘ l′ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□
(∃ λ l⁻¹ → l⁻¹ TLC.∘ l ≡ TLC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- T.Has-right-inverse l implies
-- Has-right-inverseᴱ (Traditional-lens→Lens l).
Has-right-inverse→Has-right-inverseᴱ :
(l : T.Lens A B) →
T.Has-right-inverse l → Has-right-inverseᴱ (Traditional-lens→Lens l)
Has-right-inverse→Has-right-inverseᴱ l =
(∃ λ l⁻¹ → l TLC.∘ l⁻¹ ≡ TLC.id ) ↝⟨ Σ-map Traditional-lens→Lens (cong Traditional-lens→Lens) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id ) ↝⟨ Σ-map P.id [_]→ ⟩□
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id)) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- In erased contexts Has-right-inverseᴱ (Traditional-lens→Lens l) is
-- equivalent to T.Has-right-inverse l.
@0 Has-right-inverseᴱ≃Has-right-inverse :
(l : T.Lens A B) →
Has-right-inverseᴱ (Traditional-lens→Lens l) ≃ T.Has-right-inverse l
Has-right-inverseᴱ≃Has-right-inverse l =
(∃ λ l⁻¹ → Erased (l′ LC.∘ l⁻¹ ≡ LC.id)) ↔⟨ (∃-cong λ _ → erased Erased↔) ⟩
(∃ λ l⁻¹ → l′ LC.∘ l⁻¹ ≡ LC.id ) ↝⟨ (Σ-cong Lens≃Traditional-lens λ _ → inverse $ Eq.≃-≡ Lens≃Traditional-lens) ⟩□
(∃ λ l⁻¹ → l TLC.∘ l⁻¹ ≡ TLC.id ) □
where
module LC = Lens-combinators
l′ = Traditional-lens→Lens l
-- T.Is-bi-invertible l implies
-- Is-bi-invertibleᴱ (Traditional-lens→Lens l).
Is-bi-invertible→Is-bi-invertibleᴱ :
(l : T.Lens A B) →
T.Is-bi-invertible l → Is-bi-invertibleᴱ (Traditional-lens→Lens l)
Is-bi-invertible→Is-bi-invertibleᴱ l =
T.Is-bi-invertible l ↔⟨⟩
T.Has-left-inverse l × T.Has-right-inverse l ↝⟨ Σ-map (Has-left-inverse→Has-left-inverseᴱ l)
(Has-right-inverse→Has-right-inverseᴱ l) ⟩
Has-left-inverseᴱ l′ × Has-right-inverseᴱ l′ ↔⟨⟩
Is-bi-invertibleᴱ l′ □
where
l′ = Traditional-lens→Lens l
-- In erased contexts Is-bi-invertibleᴱ (Traditional-lens→Lens l) is
-- equivalent to T.Is-bi-invertible l.
@0 Is-bi-invertibleᴱ≃Is-bi-invertible :
(l : T.Lens A B) →
Is-bi-invertibleᴱ (Traditional-lens→Lens l) ≃ T.Is-bi-invertible l
Is-bi-invertibleᴱ≃Is-bi-invertible l =
Is-bi-invertibleᴱ l′ ↔⟨⟩
Has-left-inverseᴱ l′ × Has-right-inverseᴱ l′ ↝⟨ Has-left-inverseᴱ≃Has-left-inverse l ×-cong
Has-right-inverseᴱ≃Has-right-inverse l ⟩
T.Has-left-inverse l × T.Has-right-inverse l ↔⟨⟩
T.Is-bi-invertible l □
where
l′ = Traditional-lens→Lens l
-- A T.≊ B implies A ≊ᴱ B.
≊→≊ᴱ : A T.≊ B → A ≊ᴱ B
≊→≊ᴱ {A = A} {B = B} =
(∃ λ (l : T.Lens A B) → T.Is-bi-invertible l) ↝⟨ Σ-map Traditional-lens→Lens (λ {l} → Is-bi-invertible→Is-bi-invertibleᴱ l) ⟩□
(∃ λ (l : Lens A B) → Is-bi-invertibleᴱ l) □
-- In erased contexts A ≊ᴱ B is equivalent to A T.≊ B.
@0 ≊ᴱ≃≊ : (A ≊ᴱ B) ≃ (A T.≊ B)
≊ᴱ≃≊ {A = A} {B = B} =
(∃ λ (l : Lens A B) → Is-bi-invertibleᴱ l) ↝⟨ (inverse $
Σ-cong (inverse Lens≃Traditional-lens) λ l →
inverse $ Is-bi-invertibleᴱ≃Is-bi-invertible l) ⟩□
(∃ λ (l : T.Lens A B) → T.Is-bi-invertible l) □
-- An equality characterisation lemma for A ≊ᴱ B that applies when A
-- is a set.
@0 equality-characterisation-for-sets-≊ᴱ :
let open Lens in
{f₁@(l₁₁ , _) f₂@(l₁₂ , _) : A ≊ᴱ B} →
Is-set A →
f₁ ≡ f₂ ↔ set l₁₁ ≡ set l₁₂
equality-characterisation-for-sets-≊ᴱ
{f₁ = f₁@(l₁₁ , _)} {f₂ = f₂@(l₁₂ , _)} A-set =
f₁ ≡ f₂ ↔⟨ inverse $ Eq.≃-≡ ≊ᴱ≃≊ ⟩
_≃_.to ≊ᴱ≃≊ f₁ ≡ _≃_.to ≊ᴱ≃≊ f₂ ↝⟨ T.equality-characterisation-for-sets-≊ A-set ⟩□
set l₁₁ ≡ set l₁₂ □
where
open Lens
-- There is a logical equivalence between A ≃ᴱ B and A ≊ᴱ B.
≃ᴱ⇔≊ᴱ : (A ≃ᴱ B) ⇔ (A ≊ᴱ B)
≃ᴱ⇔≊ᴱ = record
{ to = _⇔_.to BM.≅ᴱ⇔≊ᴱ ⊚ _⇔_.to ≃ᴱ⇔≅ᴱ
; from = _⇔_.from ≃ᴱ⇔≅ᴱ ⊚ _⇔_.from BM.≅ᴱ⇔≊ᴱ
}
-- In erased contexts the left-to-right direction of ≃ᴱ⇔≊ᴱ is a right
-- inverse of the right-to-left direction.
@0 ≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ :
(A≃B : A ≃ᴱ B) → _⇔_.from ≃ᴱ⇔≊ᴱ (_⇔_.to ≃ᴱ⇔≊ᴱ A≃B) ≡ A≃B
≃ᴱ⇔≊ᴱ∘≃ᴱ⇔≊ᴱ _ = EEq.to≡to→≡ ext (refl _)
-- The forward direction of ≃ᴱ⇔≊ᴱ maps identity to an isomorphism for
-- which the first projection is the identity.
≃ᴱ⇔≊ᴱ-id≡id :
let open Lens-combinators in
proj₁ (_⇔_.to ≃ᴱ⇔≊ᴱ F.id) ≡ id {A = A}
≃ᴱ⇔≊ᴱ-id≡id = equal-laws→≡
(λ _ _ → refl _)
(λ a →
_≃ᴱ_.left-inverse-of F.id a ≡⟨ sym $ _≃ᴱ_.right-left-lemma F.id _ ⟩
cong P.id (_≃ᴱ_.right-inverse-of F.id a) ≡⟨⟩
cong P.id (refl _) ≡⟨ sym $ cong-id _ ⟩∎
refl _ ∎)
(λ _ _ _ → refl _)
where
open Lens-combinators
-- If A is a set, then there is an equivalence between A ≃ᴱ B and
-- A ≊ᴱ B.
≃ᴱ≃ᴱ≊ᴱ : @0 Is-set A → (A ≃ᴱ B) ≃ᴱ (A ≊ᴱ B)
≃ᴱ≃ᴱ≊ᴱ {A = A} {B = B} A-set =
A ≃ᴱ B ↝⟨ ≃ᴱ≃ᴱ≅ᴱ A-set ⟩
A ≅ᴱ B ↝⟨ inverse $ BM.≊ᴱ≃ᴱ≅ᴱ-domain (lens-preserves-h-level-of-domain 1 A-set) ⟩□
A ≊ᴱ B □
-- The equivalence ≃ᴱ≃ᴱ≊ᴱ maps identity to an isomorphism for which the
-- first projection is the identity.
≃ᴱ≃ᴱ≊ᴱ-id≡id :
let open Lens-combinators in
(@0 A-set : Is-set A) →
proj₁ (_≃ᴱ_.to (≃ᴱ≃ᴱ≊ᴱ A-set) F.id) ≡ id
≃ᴱ≃ᴱ≊ᴱ-id≡id _ = ≃ᴱ⇔≊ᴱ-id≡id
where
open Lens-combinators
-- The right-to-left direction of ≃ᴱ≃ᴱ≊ᴱ maps bi-invertible lenses to
-- their getter functions.
to-from-≃ᴱ≃ᴱ≊ᴱ≡get :
(@0 A-set : Is-set A) (A≊B@(l , _) : A ≊ᴱ B) →
_≃ᴱ_.to (_≃ᴱ_.from (≃ᴱ≃ᴱ≊ᴱ A-set) A≊B) ≡ Lens.get l
to-from-≃ᴱ≃ᴱ≊ᴱ≡get _ _ = refl _
-- The getter function of a bi-invertible lens is an equivalence (with
-- erased proofs).
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get :
(l : Lens A B) →
Is-bi-invertibleᴱ l → Is-equivalenceᴱ (Lens.get l)
Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l is-bi-inv =
_≃ᴱ_.is-equivalence (_⇔_.from ≃ᴱ⇔≊ᴱ (l , is-bi-inv))
-- If the getter function is an equivalence (with erased proofs), then
-- the lens is bi-invertible (with erased proofs).
Is-equivalenceᴱ-get→Is-bi-invertibleᴱ :
(l : Lens A B) →
Is-equivalenceᴱ (Lens.get l) → Is-bi-invertibleᴱ l
Is-equivalenceᴱ-get→Is-bi-invertibleᴱ {A = A} {B = B} l′ is-equiv =
block λ b →
$⟨ l⁻¹′ b , [ l∘l⁻¹≡id b , l⁻¹∘l≡id b ] ⟩
Has-quasi-inverseᴱ l ↝⟨ B.Has-quasi-inverseᴱ→Is-bi-invertibleᴱ l ⟩
Is-bi-invertibleᴱ l ↝⟨ subst (λ l → Is-bi-invertibleᴱ (erased l)) ([]-cong [ getter-equivalence→lens≡ l′ is-equiv ]) ⟩□
Is-bi-invertibleᴱ l′ □
where
open Lens
open Lens-combinators
-- A lens that is equal to l′.
l : Lens A B
l = getter-equivalence→lens l′ is-equiv
A≃B = EEq.⟨ get l , is-equiv ⟩
open _≃ᴱ_ A≃B
-- An inverse of l.
--
-- Note that the set-get and set-set proofs have been "obfuscated".
-- They could have been shorter, but then it might not have been
-- possible to prove l∘l⁻¹≡id and l⁻¹∘l≡id.
l⁻¹ : Lens B A
l⁻¹ = record
{ get = from
; set = λ _ → get l
; get-set = λ _ a →
from (get l a) ≡⟨ left-inverse-of a ⟩∎
a ∎
; set-get = λ b →
get l (from b) ≡⟨ sym $ cong (get l) $ set-get l (from b) ⟩
get l (from (get l (from b))) ≡⟨ right-inverse-of (get l (from b)) ⟩
get l (from b) ≡⟨ right-inverse-of b ⟩∎
b ∎
; set-set = λ b a₁ a₂ →
get l a₂ ≡⟨ sym $ right-inverse-of _ ⟩
get l (from (get l a₂)) ≡⟨ sym $ cong (get l) (set-set l (from b) (get l a₁) (get l a₂)) ⟩
get l (from (get l a₂)) ≡⟨ right-inverse-of _ ⟩∎
get l a₂ ∎
}
-- A blocked variant of l⁻¹.
l⁻¹′ : Block "l⁻¹" → Lens B A
l⁻¹′ ⊠ = l⁻¹
-- The lens l⁻¹ is a right inverse of l.
@0 l∘l⁻¹≡id : ∀ b → l ∘ l⁻¹′ b ≡ id
l∘l⁻¹≡id ⊠ = constant-setter→≡id
( right-inverse-of
, right-inverse-of
, [ (λ b₁ b₂ →
get-set (l ∘ l⁻¹) b₁ b₂ ≡⟨⟩
trans (cong (get l) (get-set l⁻¹ b₁ (from b₂)))
(get-set l (from b₁) b₂) ≡⟨⟩
trans (cong (get l) (left-inverse-of (from b₂)))
(right-inverse-of b₂) ≡⟨ cong (λ eq → trans (cong (get l) eq) (right-inverse-of b₂)) $ sym $
right-left-lemma _ ⟩
trans (cong (get l) (cong from (right-inverse-of b₂)))
(right-inverse-of b₂) ≡⟨ cong (λ eq → trans eq (right-inverse-of b₂)) $
cong-∘ _ _ (right-inverse-of b₂) ⟩
trans (cong (get l ⊚ from) (right-inverse-of b₂))
(right-inverse-of b₂) ≡⟨⟩
trans (cong (get (l ∘ l⁻¹)) (right-inverse-of b₂))
(right-inverse-of b₂) ∎)
, (λ b →
set-get (l ∘ l⁻¹) b ≡⟨⟩
trans (cong (get l) (set-get l (from b)))
(set-get l⁻¹ b) ≡⟨⟩
trans (cong (get l) (set-get l (from b)))
(trans (sym (cong (get l) (set-get l (from b))))
(trans (right-inverse-of (get l (from b)))
(right-inverse-of b))) ≡⟨ trans--[trans-sym] _ _ ⟩
trans (right-inverse-of (get l (from b)))
(right-inverse-of b) ≡⟨⟩
trans (right-inverse-of (get (l ∘ l⁻¹) b))
(right-inverse-of b) ∎)
, (λ b b₁ b₂ →
set-set (l ∘ l⁻¹) b b₁ b₂ ≡⟨⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l)
(trans (cong (λ _ → from b₂)
(get-set l⁻¹ b (from b₁)))
(set-set l (from b) b₁ b₂))) ≡⟨⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l)
(trans (cong (λ _ → from b₂)
(left-inverse-of (from b₁)))
(set-set l (from b) b₁ b₂))) ≡⟨ cong (λ eq → trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l) (trans eq (set-set l (from b) b₁ b₂)))) $
cong-const (left-inverse-of (from b₁)) ⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l) (trans (refl _) (set-set l (from b) b₁ b₂))) ≡⟨ cong (λ eq → trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l) eq)) $
trans-reflˡ (set-set l (from b) b₁ b₂) ⟩
trans (set-set l⁻¹ b (from b₁) (from b₂))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨⟩
trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) (get l (from b₁))
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ b′ → trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) b′
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂))) $
right-inverse-of _ ⟩
trans (trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(right-inverse-of _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ cong (λ f → trans (trans (sym (f _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(f _)))
(cong (get l) (set-set l (from b) b₁ b₂))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
right-inverse-of ⟩
trans (trans (sym (ext⁻¹ (⟨ext⟩ right-inverse-of) _))
(trans (sym (cong (get l)
(set-set l (from b) b₁
(get l (from b₂)))))
(ext⁻¹ (⟨ext⟩ right-inverse-of) _)))
(cong (get l) (set-set l (from b) b₁ b₂)) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : ∀ b → f b ≡ f b) →
trans (trans (sym (ext⁻¹ p (f b₂)))
(trans (sym (q (f b₂))) (ext⁻¹ p (f b₂))))
(q b₂) ≡
refl _)
(λ q →
trans (trans (sym (ext⁻¹ (refl P.id) _))
(trans (sym (q _)) (ext⁻¹ (refl P.id) _)))
(q _) ≡⟨ cong (λ eq → trans (trans (sym eq) (trans (sym (q _)) eq))
(q _)) $
ext⁻¹-refl _ ⟩
trans (trans (sym (refl _))
(trans (sym (q _)) (refl _)))
(q _) ≡⟨ cong₂ (λ p r → trans (trans p r) (q _))
sym-refl
(trans-reflʳ _) ⟩
trans (trans (refl _) (sym (q _))) (q _) ≡⟨ cong (λ eq → trans eq (q _)) $ trans-reflˡ (sym (q _)) ⟩
trans (sym (q _)) (q _) ≡⟨ trans-symˡ (q _) ⟩∎
refl _ ∎)
(⟨ext⟩ right-inverse-of)
(cong (get l) ⊚ set-set l (from b) b₁) ⟩
refl _ ∎)
]
)
-- The lens l⁻¹ is a left inverse of l.
@0 l⁻¹∘l≡id : ∀ b → l⁻¹′ b ∘ l ≡ id
l⁻¹∘l≡id ⊠ = constant-setter→≡id
( left-inverse-of
, left-inverse-of
, [ (λ a₁ a₂ →
get-set (l⁻¹ ∘ l) a₁ a₂ ≡⟨⟩
trans (cong from (get-set l a₁ (to a₂)))
(get-set l⁻¹ (get l a₁) a₂) ≡⟨⟩
trans (cong from (right-inverse-of (to a₂)))
(left-inverse-of a₂) ≡⟨ cong (λ eq → trans (cong from eq) (left-inverse-of _)) $ sym $
left-right-lemma _ ⟩
trans (cong from (cong (get l) (left-inverse-of a₂)))
(left-inverse-of a₂) ≡⟨ cong (λ eq → trans eq (left-inverse-of _)) $
cong-∘ _ _ (left-inverse-of _) ⟩
trans (cong (from ⊚ get l) (left-inverse-of a₂))
(left-inverse-of a₂) ≡⟨⟩
trans (cong (get (l⁻¹ ∘ l)) (left-inverse-of a₂))
(left-inverse-of a₂) ∎)
, (λ a →
let lemma₁ =
cong from
(trans (sym (cong (get l)
(set-get l (from (get l a)))))
(trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong-trans _ _ (trans _ (right-inverse-of _)) ⟩
trans (cong from (sym (cong (get l)
(set-get l (from (get l a))))))
(cong from (trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong (λ eq → trans (cong from eq)
(cong from (trans (right-inverse-of _)
(right-inverse-of _)))) $ sym $
cong-sym _ (set-get l (from (get l a))) ⟩
trans (cong from (cong (get l)
(sym (set-get l (from (get l a))))))
(cong from (trans (right-inverse-of _)
(right-inverse-of _))) ≡⟨ cong₂ trans
(cong-∘ _ _ (sym (set-get l (from (get l a)))))
(cong-trans _ _ (right-inverse-of _)) ⟩
trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans (cong from (right-inverse-of _))
(cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p q → trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans p q))
(right-left-lemma _)
(right-left-lemma _) ⟩∎
trans (cong (from ⊚ get l)
(sym (set-get l (from (get l a)))))
(trans (left-inverse-of _)
(left-inverse-of _)) ∎
f = from ⊚ get l
lemma₂ : ∀ _ → _
lemma₂ = λ a →
trans (left-inverse-of (f a))
(left-inverse-of a) ≡⟨ cong (λ g → trans (g (f a)) (g a)) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
left-inverse-of ⟩∎
trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))
(ext⁻¹ (⟨ext⟩ left-inverse-of) a) ∎
lemma₃ =
trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ≡⟨ cong₂ trans (ext⁻¹-refl _) (ext⁻¹-refl _) ⟩
trans (refl _) (refl _) ≡⟨ trans-refl-refl ⟩∎
refl _ ∎
in
trans (cong from (set-get l⁻¹ (get l a)))
(set-get l a) ≡⟨⟩
trans (cong from
(trans (sym (cong (get l)
(set-get l (from (get l a)))))
(trans (right-inverse-of _)
(right-inverse-of _))))
(set-get l a) ≡⟨ cong (λ eq → trans eq (set-get l a)) lemma₁ ⟩
trans (trans (cong f (sym (set-get l (f a))))
(trans (left-inverse-of (f (f a)))
(left-inverse-of (f a))))
(set-get l a) ≡⟨ cong (λ eq → trans (trans (cong f (sym (set-get l (f a)))) eq)
(set-get l a)) $
lemma₂ _ ⟩
trans (trans (cong f (sym (set-get l (f a))))
(trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f (f a)))
(ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))))
(set-get l a) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : ∀ a → f a ≡ a) →
trans (trans (cong f (sym (q (f a))))
(trans (ext⁻¹ p (f (f a))) (ext⁻¹ p (f a))))
(q a) ≡
trans (ext⁻¹ p (f a)) (ext⁻¹ p a))
(λ q →
trans (trans (cong P.id (sym (q a)))
(trans (ext⁻¹ (refl P.id) a)
(ext⁻¹ (refl P.id) a)))
(q a) ≡⟨ cong₂ (λ p r → trans (trans p r) (q a))
(sym $ cong-id _)
lemma₃ ⟩
trans (trans (sym (q a)) (refl _)) (q a) ≡⟨ cong (flip trans _) $ trans-reflʳ _ ⟩
trans (sym (q a)) (q a) ≡⟨ trans-symˡ (q a) ⟩
refl _ ≡⟨ sym lemma₃ ⟩∎
trans (ext⁻¹ (refl P.id) a) (ext⁻¹ (refl P.id) a) ∎)
(⟨ext⟩ left-inverse-of)
(set-get l) ⟩
trans (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a))
(ext⁻¹ (⟨ext⟩ left-inverse-of) a) ≡⟨ sym $ lemma₂ _ ⟩
trans (left-inverse-of (f a))
(left-inverse-of a) ≡⟨⟩
trans (left-inverse-of (get (l⁻¹ ∘ l) a))
(left-inverse-of a) ∎)
, (λ a a₁ a₂ →
let q = set-set l a (get l a₁) (get l a₂)
lemma =
cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l) q))
(right-inverse-of _))) ≡⟨ cong-trans _ _ (trans (sym (cong (get l) q)) (right-inverse-of _)) ⟩
trans (cong from (sym (right-inverse-of _)))
(cong from (trans (sym (cong (get l) q))
(right-inverse-of _))) ≡⟨ cong₂ trans
(cong-sym _ (right-inverse-of _))
(cong-trans _ _ (right-inverse-of _)) ⟩
trans (sym (cong from (right-inverse-of _)))
(trans (cong from (sym (cong (get l) q)))
(cong from (right-inverse-of _))) ≡⟨ cong₂ (λ p r → trans (sym p) (trans (cong from (sym (cong (get l) q))) r))
(right-left-lemma _)
(right-left-lemma _) ⟩
trans (sym (left-inverse-of _))
(trans (cong from (sym (cong (get l) q)))
(left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _))
(trans eq (left-inverse-of _))) $
cong-sym _ (cong (get l) q) ⟩
trans (sym (left-inverse-of _))
(trans (sym (cong from (cong (get l) q)))
(left-inverse-of _)) ≡⟨ cong (λ eq → trans (sym (left-inverse-of _))
(trans (sym eq) (left-inverse-of _))) $
cong-∘ _ _ q ⟩
trans (sym (left-inverse-of _))
(trans (sym (cong (from ⊚ get l) q))
(left-inverse-of _)) ≡⟨ cong (λ g → trans (sym (g _))
(trans (sym (cong (from ⊚ get l) q)) (g _))) $ sym $
_≃_.left-inverse-of (Eq.extensionality-isomorphism bad-ext)
left-inverse-of ⟩∎
trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) _))
(trans (sym (cong (from ⊚ get l) q))
(ext⁻¹ (⟨ext⟩ left-inverse-of) _)) ∎
f = from ⊚ get l
in
set-set (l⁻¹ ∘ l) a a₁ a₂ ≡⟨⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from
(trans (cong (λ _ → get l a₂)
(right-inverse-of (get l a₁)))
(set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (λ eq → trans (set-set l a (get l a₁) _)
(cong from (trans eq (set-set l⁻¹ (get l a) a₁ _)))) $
cong-const (right-inverse-of (get l a₁)) ⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from (trans (refl _) (set-set l⁻¹ (get l a) a₁ a₂))) ≡⟨ cong (λ eq → trans (set-set l a (get l a₁) _) (cong from eq)) $
trans-reflˡ (set-set l⁻¹ (get l a) a₁ _) ⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from (set-set l⁻¹ (get l a) a₁ a₂)) ≡⟨⟩
trans (set-set l a (get l a₁) (get l a₂))
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l (from (get l a))
(get l a₁) (get l a₂))))
(right-inverse-of _)))) ≡⟨ cong (λ a′ → trans q
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l)
(set-set l a′ (get l a₁) (get l a₂))))
(right-inverse-of _))))) $
left-inverse-of _ ⟩
trans q
(cong from
(trans (sym (right-inverse-of _))
(trans (sym (cong (get l) q))
(right-inverse-of _)))) ≡⟨ cong (trans q) lemma ⟩
trans q
(trans (sym (ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))
(trans (sym (cong f q))
(ext⁻¹ (⟨ext⟩ left-inverse-of) (f a₂)))) ≡⟨ elim₁
(λ {f} (p : f ≡ P.id) →
(q : f a₂ ≡ f a₂) →
trans q
(trans (sym (ext⁻¹ p (f a₂)))
(trans (sym (cong f q))
(ext⁻¹ p (f a₂)))) ≡
refl _)
(λ q →
trans q
(trans (sym (ext⁻¹ (refl P.id) a₂))
(trans (sym (cong P.id q))
(ext⁻¹ (refl P.id) a₂))) ≡⟨ cong (λ eq → trans q (trans (sym eq)
(trans (sym (cong P.id q)) eq))) $
ext⁻¹-refl _ ⟩
trans q (trans (sym (refl _))
(trans (sym (cong P.id q)) (refl _))) ≡⟨ cong₂ (λ p r → trans q (trans p r))
sym-refl
(trans-reflʳ _) ⟩
trans q (trans (refl _) (sym (cong P.id q))) ≡⟨ cong (trans q) $ trans-reflˡ (sym (cong P.id q)) ⟩
trans q (sym (cong P.id q)) ≡⟨ cong (λ eq → trans q (sym eq)) $ sym $ cong-id q ⟩
trans q (sym q) ≡⟨ trans-symʳ q ⟩∎
refl _ ∎)
(⟨ext⟩ left-inverse-of)
q ⟩
refl _ ∎)
]
)
-- There is an equivalence with erased proofs between "l is
-- bi-invertible (with erased proofs) " and "the getter of l is an
-- equivalence (with erased proofs)".
Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get :
(l : Lens A B) →
Is-bi-invertibleᴱ l ≃ᴱ Is-equivalenceᴱ (Lens.get l)
Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l = EEq.⇔→≃ᴱ
(BM.Is-bi-invertibleᴱ-propositional l)
(EEq.Is-equivalenceᴱ-propositional ext _)
(Is-bi-invertibleᴱ→Is-equivalenceᴱ-get l)
(Is-equivalenceᴱ-get→Is-bi-invertibleᴱ l)
-- There is in general no split surjection from equivalences (with
-- erased proofs) to lenses that are bi-invertible (with erased
-- proofs), if the right-to-left direction of the split surjection is
-- required to map bi-invertible lenses to their getter functions
-- (assuming univalence).
¬≃ᴱ↠≊ᴱ :
Univalence lzero →
∃ λ (A : Set) →
¬ ∃ λ (≃ᴱ↠≊ᴱ : (A ≃ᴱ A) ↠ (A ≊ᴱ A)) →
(A≊ᴱA@(l , _) : A ≊ᴱ A) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ A≊ᴱA) ≡ Lens.get l
¬≃ᴱ↠≊ᴱ univ =
let A , ¬≃ᴱ↠ = ¬-≃ᴱ-↠-Σ-Lens-Is-equivalenceᴱ-get univ in
A
, Stable-¬ _
[ (∃ λ (≃ᴱ↠≊ᴱ : (A ≃ᴱ A) ↠ (A ≊ᴱ A)) →
(A≊ᴱA@(l , _) : A ≊ᴱ A) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ A≊ᴱA) ≡ Lens.get l) ↝⟨ Σ-map
((∃-cong λ l → _≃_.surjection $ EEq.≃ᴱ→≃ $ Is-bi-invertibleᴱ≃ᴱIs-equivalenceᴱ-get l) F.∘_)
(λ hyp _ → hyp _) ⟩
(∃ λ (f : (A ≃ᴱ A) ↠
(∃ λ (l : Lens A A) → Is-equivalenceᴱ (Lens.get l))) →
∀ p → _≃ᴱ_.to (_↠_.from f p) ≡ Lens.get (proj₁ p)) ↝⟨ ¬≃ᴱ↠ ⟩□
⊥ □
]
-- There is in general no equivalence with erased proofs between
-- equivalences (with erased proofs) and lenses that are bi-invertible
-- (with erased proofs), if the right-to-left direction of the
-- equivalence is required to map bi-invertible lenses to their getter
-- functions (assuming univalence).
¬≃ᴱ≃ᴱ≊ᴱ :
Univalence lzero →
∃ λ (A : Set) →
¬ ∃ λ (≃ᴱ≃ᴱ≊ᴱ : (A ≃ᴱ A) ≃ᴱ (A ≊ᴱ A)) →
(A≊ᴱA@(l , _) : A ≊ᴱ A) →
_≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ A≊ᴱA) ≡ Lens.get l
¬≃ᴱ≃ᴱ≊ᴱ univ =
let A , ¬≃ᴱ↠ = ¬≃ᴱ↠≊ᴱ univ in
A
, Stable-¬ _
[ (∃ λ (≃ᴱ≃ᴱ≊ᴱ : (A ≃ᴱ A) ≃ᴱ (A ≊ᴱ A)) →
(A≊ᴱA@(l , _) : A ≊ᴱ A) →
_≃ᴱ_.to (_≃ᴱ_.from ≃ᴱ≃ᴱ≊ᴱ A≊ᴱA) ≡ Lens.get l) ↝⟨ Σ-map (_≃_.surjection ⊚ EEq.≃ᴱ→≃) P.id ⟩
(∃ λ (≃ᴱ↠≊ᴱ : (A ≃ᴱ A) ↠ (A ≊ᴱ A)) →
(A≊ᴱA@(l , _) : A ≊ᴱ A) →
_≃ᴱ_.to (_↠_.from ≃ᴱ↠≊ᴱ A≊ᴱA) ≡ Lens.get l) ↝⟨ ¬≃ᴱ↠ ⟩□
⊥ □
]
| {
"alphanum_fraction": 0.374027919,
"avg_line_length": 45.8180673591,
"ext": "agda",
"hexsha": "a2e2f54a7ca6551f9518511ad6b32ec84834ee07",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Saizan/dependent-lenses",
"max_forks_repo_path": "src/Lens/Non-dependent/Traditional/Erased.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Saizan/dependent-lenses",
"max_issues_repo_path": "src/Lens/Non-dependent/Traditional/Erased.agda",
"max_line_length": 168,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b7921cc6b52858cd7d8a52c183c7a6544d1a4062",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Saizan/dependent-lenses",
"max_stars_repo_path": "src/Lens/Non-dependent/Traditional/Erased.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 48260,
"size": 145564
} |
------------------------------------------------------------------------------
-- LTC-PCF terms properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module LTC-PCF.Base.Properties where
open import LTC-PCF.Base
------------------------------------------------------------------------------
-- Congruence properties
·-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
succCong : ∀ {m n} → m ≡ n → succ₁ m ≡ succ₁ n
succCong refl = refl
predCong : ∀ {m n} → m ≡ n → pred₁ m ≡ pred₁ n
predCong refl = refl
------------------------------------------------------------------------------
S≢0 : ∀ {n} → succ₁ n ≢ zero
S≢0 S≡0 = 0≢S (sym S≡0)
-- We added Common.Relation.Binary.PropositionalEquality.cong, so this
-- theorem is not necessary.
-- x≡y→Sx≡Sy : ∀ {m n} → m ≡ n → succ₁ m ≡
-- succ₁ n x≡y→Sx≡Sy refl = refl
| {
"alphanum_fraction": 0.409455843,
"avg_line_length": 29.5,
"ext": "agda",
"hexsha": "cb42725ccb89e4e1ee0f6e590e1610bcc6f8d9bb",
"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/Base/Properties.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/Base/Properties.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/Base/Properties.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": 305,
"size": 1121
} |
{-# OPTIONS --safe #-}
module README where
-- Formalization for "Decidability of Conversion for Setoid Type Theory"
-- Git repository: https://github.com/CoqHott/logrel-mltt/
------------------
-- INTRODUCTION --
------------------
-- A minimal library necessary for formalization:
-- The empty type and its elimination rule.
import Tools.Empty
-- The unit type.
import Tools.Unit
-- Sum type.
import Tools.Sum
-- Product type.
import Tools.Product
-- Identity function and composition.
import Tools.Function
-- Negation and decidability type.
import Tools.Nullary
-- Propositional equality and its properties.
import Tools.PropositionalEquality
-- Natural numbers and decidability of equality.
import Tools.Nat
-- Lists definition
import Tools.List
---------------------------
-- LANGUAGE INTRODUCTION --
---------------------------
-- Syntax and semantics of weakening and substitution.
import Definition.Untyped
-- Propositional equality properties: Equalities between expressions,
-- weakenings, substitutions and their combined composition.
-- (These lemmas are not in the paper.)
import Definition.Untyped.Properties
-- Judgements: Typing rules, conversion, reduction rules
-- and well-formed substitutions and respective equality.
import Definition.Typed
-- Well-formed context extraction and reduction properties.
import Definition.Typed.Properties
-- Well-formed weakening and its properties.
import Definition.Typed.Weakening
------------------------------
-- KRIPKE LOGICAL RELATIONS --
------------------------------
-- Generic equality relation definition.
import Definition.Typed.EqualityRelation
-- The judgemental instance of the generic equality.
import Definition.Typed.EqRelInstance
-- Logical relations definitions.
import Definition.LogicalRelation
-- Properties of logical relation:
-- Reflexivity of the logical relation.
import Definition.LogicalRelation.Properties.Reflexivity
-- Escape lemma for the logical relation.
import Definition.LogicalRelation.Properties.Escape
-- Shape view of two or more types.
import Definition.LogicalRelation.ShapeView
-- Proof irrelevance for the logical relation.
import Definition.LogicalRelation.Irrelevance
-- Weakening of logical relation judgements.
import Definition.LogicalRelation.Weakening
-- Conversion of the logical relation.
import Definition.LogicalRelation.Properties.Conversion
-- Symmetry of the logical relation.
import Definition.LogicalRelation.Properties.Symmetry
-- Transitvity of the logical relation.
import Definition.LogicalRelation.Properties.Transitivity
-- Neutral introduction in the logical relation.
import Definition.LogicalRelation.Properties.Neutral
-- Weak head expansion of the logical relation.
import Definition.LogicalRelation.Properties.Reduction
-- Application in the logical relation.
import Definition.LogicalRelation.Application
-- Validity judgements definitions
import Definition.LogicalRelation.Substitution
-- Properties of validity judgements:
-- Proof irrelevance for the validity judgements.
import Definition.LogicalRelation.Substitution.Irrelevance
-- Properties about valid substitutions:
-- * Substitution well-formedness.
-- * Substitution weakening.
-- * Substitution lifting.
-- * Identity substitution.
-- * Reflexivity, symmetry and transitivity of substitution equality.
import Definition.LogicalRelation.Substitution.Properties
-- Single term substitution of validity judgements.
import Definition.LogicalRelation.Substitution.Introductions.SingleSubst
-- The fundamental theorem.
import Definition.LogicalRelation.Fundamental
-- Certain cases of the fundamental theorem
-- Validity of the universes
import Definition.LogicalRelation.Substitution.Introductions.Universe
-- Validity of the empty type and its eliminator
import Definition.LogicalRelation.Substitution.Introductions.Empty
import Definition.LogicalRelation.Substitution.Introductions.Emptyrec
-- Validity of natural numbers and its eliminator
import Definition.LogicalRelation.Substitution.Introductions.Nat
import Definition.LogicalRelation.Substitution.Introductions.Natrec
-- Validity of Π-types, abstractions and applications
import Definition.LogicalRelation.Substitution.Introductions.Pi
import Definition.LogicalRelation.Substitution.Introductions.Application
import Definition.LogicalRelation.Substitution.Introductions.Lambda
-- Validity of ∃-types, pairs and projections
import Definition.LogicalRelation.Substitution.Introductions.Sigma
import Definition.LogicalRelation.Substitution.Introductions.Pair
import Definition.LogicalRelation.Substitution.Introductions.Fst
import Definition.LogicalRelation.Substitution.Introductions.Snd
-- Validity of type casting and proof-irrelevant transport
import Definition.LogicalRelation.Substitution.Introductions.Castlemmas
import Definition.LogicalRelation.Substitution.Introductions.Cast
import Definition.LogicalRelation.Substitution.Introductions.CastPi
import Definition.LogicalRelation.Substitution.Introductions.Transp
-- Validity of identity types, and reflexivity
import Definition.LogicalRelation.Substitution.Introductions.Idlemmas
import Definition.LogicalRelation.Substitution.Introductions.IdUniv
import Definition.LogicalRelation.Substitution.Introductions.IdNat
import Definition.LogicalRelation.Substitution.Introductions.IdPi
import Definition.LogicalRelation.Substitution.Introductions.IdUPiPi
import Definition.LogicalRelation.Substitution.Introductions.IdRefl
-- Reducibility of well-formedness.
import Definition.LogicalRelation.Fundamental.Reducibility
-- Consequences of the fundamental theorem:
-- Consistency (no proof of False in the empty context) implies
-- canonicity of the system.
import Definition.Typed.Consequences.Canonicity
-- Injectivity of Π-types.
import Definition.Typed.Consequences.Injectivity
-- Syntactic validitiy of the system.
import Definition.Typed.Consequences.Syntactic
-- All types and terms fully reduce to WHNF.
import Definition.Typed.Consequences.Reduction
-- Strong equality of types.
import Definition.Typed.Consequences.Equality
-- Syntactic inequality of types.
import Definition.Typed.Consequences.Inequality
-- Substitution in judgements and substitution composition.
import Definition.Typed.Consequences.Substitution
-- Uniqueness of the types of neutral terms.
import Definition.Typed.Consequences.NeTypeEq
-- Consistency (0 is not judgementally equal to 1) of the type theory.
import Definition.Typed.Consequences.Consistency
-- Types can only belong to one universe (because of annotations)
-- also various inequalities for conversion
import Definition.Typed.Consequences.PiNorm
import Definition.Typed.Consequences.RelevanceUnicity
-- Terms can only admit one type
import Definition.Typed.Consequences.TypeUnicity
-- Various inversion results
import Definition.Typed.Consequences.TypeUnicity
------------------
-- DECIDABILITY --
------------------
-- Conversion algorithm definition.
import Definition.Conversion
-- Properties of conversion algorithm:
-- Context equality and its properties:
-- * Context conversion of typing judgements.
-- * Context conversion of reductions and algorithmic equality.
-- * Reflexivity and symmetry of context equality.
import Definition.Conversion.Stability
-- Soundness of the conversion algorithm.
import Definition.Conversion.Soundness
-- Results around normalisation of reflexive terms
import Definition.Conversion.FullReduction
-- Conversion property of algorithmic equality.
import Definition.Conversion.Conversion
-- Decidability of the conversion algorithm.
import Definition.Conversion.Decidable
-- Symmetry of the conversion algorithm.
import Definition.Conversion.Symmetry
-- Transitivity of the conversion algorithm.
import Definition.Conversion.Transitivity
-- Weakening of the conversion algorithm.
import Definition.Conversion.Weakening
-- WHNF and neutral lifting of the conversion algorithm.
import Definition.Conversion.Lift
-- Generic equality relation instance for the conversion algorithm.
import Definition.Conversion.EqRelInstance
-- Completeness of conversion algorithm.
import Definition.Conversion.Consequences.Completeness
-- Decidability of judgemental conversion.
import Definition.Conversion.HelperDecidable
import Definition.Typed.Decidable
| {
"alphanum_fraction": 0.8130502955,
"avg_line_length": 31.2867924528,
"ext": "agda",
"hexsha": "abc12859b4a0ff21ac2d004ace82d6f5f3033bb9",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2022-02-15T19:42:19.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-01-26T14:55:51.000Z",
"max_forks_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "CoqHott/logrel-mltt",
"max_forks_repo_path": "README.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "CoqHott/logrel-mltt",
"max_issues_repo_path": "README.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e0eeebc4aa5ed791ce3e7c0dc9531bd113dfcc04",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "CoqHott/logrel-mltt",
"max_stars_repo_path": "README.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-17T16:13:53.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-06-21T08:39:01.000Z",
"num_tokens": 1577,
"size": 8291
} |
open import Data.Nat using (suc)
open import Substitution using (rename-subst-commute; subst-commute)
open import DeBruijn
infix 3 _—→_
data _—→_ : ∀ {n} → Term n → Term n → Set where
—→-ξₗ : ∀ {n} {M M′ N : Term n}
→ M —→ M′
---------------
→ M · N —→ M′ · N
—→-ξᵣ : ∀ {n} {M N N′ : Term n}
→ N —→ N′
---------------
→ M · N —→ M · N′
—→-ƛ : ∀ {n} {M M′ : Term (suc n)}
→ M —→ M′
-----------
→ ƛ M —→ ƛ M′
—→-β : ∀ {n} {M : Term (suc n)} {N : Term n}
--------------------
→ (ƛ M) · N —→ M [ N ]
infix 3 _—↠_
infixr 3 _—→⟨_⟩_
infix 4 _∎
data _—↠_ : ∀ {n} → Term n → Term n → Set where
_∎ : ∀ {n} (M : Term n)
------
→ M —↠ M
_—→⟨_⟩_ : ∀ {n} {L N : Term n} (M : Term n)
→ M —→ L
→ L —↠ N
------
→ M —↠ N
—↠-trans : ∀ {n} {M L N : Term n}
→ M —↠ L
→ L —↠ N
------
→ M —↠ N
—↠-trans (M ∎) M—↠M = M—↠M
—↠-trans (M —→⟨ M—→L′ ⟩ L′—↠L) L—↠N = M —→⟨ M—→L′ ⟩ (—↠-trans L′—↠L L—↠N )
—↠-congₗ : ∀ {n} {M M′ R : Term n}
→ M —↠ M′
---------------
→ M · R —↠ M′ · R
—↠-congₗ {M = M}{R = R} (M ∎) = M · R ∎
—↠-congₗ {M = M}{R = R} (M —→⟨ M—→L ⟩ L—↠M′) = M · R —→⟨ —→-ξₗ M—→L ⟩ —↠-congₗ L—↠M′
—↠-congᵣ : ∀ {n} {M M′ L : Term n}
→ M —↠ M′
---------------
→ L · M —↠ L · M′
—↠-congᵣ {M = M}{L = L} (M ∎) = L · M ∎
—↠-congᵣ {M = M}{L = L} (M —→⟨ M—→L ⟩ L—↠M′) = L · M —→⟨ —→-ξᵣ M—→L ⟩ —↠-congᵣ L—↠M′
—↠-cong-ƛ : ∀ {n} {M M′ : Term (suc n)}
→ M —↠ M′
-----------
→ ƛ M —↠ ƛ M′
—↠-cong-ƛ (M ∎) = ƛ M ∎
—↠-cong-ƛ (M —→⟨ M—→L ⟩ L—↠N′) = ƛ M —→⟨ —→-ƛ M—→L ⟩ —↠-cong-ƛ L—↠N′
—↠-cong : ∀ {n} {M M′ N N′ : Term n}
→ M —↠ M′
→ N —↠ N′
----------------
→ M · N —↠ M′ · N′
—↠-cong M—↠M′ N—↠N′ = —↠-trans (—↠-congₗ M—↠M′) (—↠-congᵣ N—↠N′)
| {
"alphanum_fraction": 0.3076502732,
"avg_line_length": 21.0344827586,
"ext": "agda",
"hexsha": "ff41060106ec9473ece7d8ffc241235a73bdf59c",
"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": "Beta.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": "Beta.agda",
"max_line_length": 84,
"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": "Beta.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": 1059,
"size": 1830
} |
------------------------------------------------------------------------
-- Instantiates the ring solver with two copies of the same ring
------------------------------------------------------------------------
open import Algebra.RingSolver.AlmostCommutativeRing
module Algebra.RingSolver.Simple (r : AlmostCommutativeRing) where
open AlmostCommutativeRing r
import Algebra.RingSolver as R
open R rawRing r (-raw-almostCommutative⟶ r) public
| {
"alphanum_fraction": 0.5538116592,
"avg_line_length": 37.1666666667,
"ext": "agda",
"hexsha": "faa5ed3d88c6bfb8f43693ed5fa072de8ebe2447",
"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/Algebra/RingSolver/Simple.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/Algebra/RingSolver/Simple.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/Algebra/RingSolver/Simple.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": 82,
"size": 446
} |
{-# OPTIONS --omega-in-omega --no-termination-check --overlapping-instances #-}
module Light.Literals where
module Definition where
module Natural where open import Light.Literals.Definition.Natural public
module Negative where open import Light.Literals.Definition.Negative public
module Natural where open import Light.Literals.Natural public
module Level where open import Light.Literals.Level public
module Integer where open import Light.Literals.Integer public
| {
"alphanum_fraction": 0.8091286307,
"avg_line_length": 40.1666666667,
"ext": "agda",
"hexsha": "058c0effaeecb12834432f9b9fc1c10a4a58873f",
"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": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_forks_repo_licenses": [
"0BSD"
],
"max_forks_repo_name": "Zambonifofex/lightlib",
"max_forks_repo_path": "Light/Literals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"0BSD"
],
"max_issues_repo_name": "Zambonifofex/lightlib",
"max_issues_repo_path": "Light/Literals.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "44b1c724f2de95d3a9effe87ca36ef9eca8b4756",
"max_stars_repo_licenses": [
"0BSD"
],
"max_stars_repo_name": "zamfofex/lightlib",
"max_stars_repo_path": "Light/Literals.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-20T21:33:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-12-20T21:33:05.000Z",
"num_tokens": 92,
"size": 482
} |
module Eq.LogicalTheory where
open import Prelude
open import T
open import DynTheory
open import SubstTheory
open import Contexts
open import Eq.Defs
open import Eq.KleeneTheoryEarly
-- Closed equivalence is contained in open
closed-logical-imp-open : ∀{A} → LogicalEq A ⊆ OLogicalEq [] A
closed-logical-imp-open {A} {e} {e'} leq {γ} {γ'} η =
ID.coe2 (LogicalEq A) (symm (closed-subst γ e)) (symm (closed-subst γ' e')) leq
-- Theory about logical equivalence
logical-sym : ∀{A} → Symmetric (LogicalEq A)
logical-sym {nat} eq = kleene-sym eq
logical-sym {A ⇒ B} equiv = λ e₁ e₁' x → logical-sym {B}
(equiv e₁' e₁ (logical-sym {A} x))
logical-trans : ∀{A} → Transitive (LogicalEq A)
logical-trans {nat} eq1 eq2 = kleene-trans eq1 eq2
logical-trans {A ⇒ B} {e} {e'} {e''} eq1 eq2 =
λ e₁ e₁' x → logical-trans (eq1 e₁ e₁ (logical-trans x (logical-sym x))) (eq2 e₁ e₁' x)
logicalγ-sym : ∀{Γ} → Symmetric (LogicalEqΓ Γ)
logicalγ-sym η n = logical-sym (η n)
logicalγ-trans : ∀{Γ} → Transitive (LogicalEqΓ Γ)
logicalγ-trans η η' n = logical-trans (η n) (η' n)
-- Open logical theory
ological-sym : ∀{Γ} {A} → Symmetric (OLogicalEq Γ A)
ological-sym eq η = logical-sym (eq (logicalγ-sym η))
-- This uses the trick where, despite not having reflexivity yet,
-- we show that some element x is reflexive by using symmetry and
-- transitivity on a proof of x ~ y that we have.
-- I find this trick hilarious.
ological-trans : ∀{Γ} {A} → Transitive (OLogicalEq Γ A)
ological-trans eq eq' η = logical-trans (eq η)
(eq' (logicalγ-trans (logicalγ-sym η) η))
logical-converse-evaluation-1 : ∀{A} {e e' d : TCExp A} →
e ~ e' :: A →
d ~>* e →
d ~ e' :: A
logical-converse-evaluation-1 {nat} eq eval = kleene-converse-evaluation eq eval
logical-converse-evaluation-1 {A ⇒ B} eq eval =
λ e₁ e₁' x → logical-converse-evaluation-1 (eq e₁ e₁' x)
(eval-compat step-app-l eval)
logical-converse-evaluation : ∀{A} {e e' d d' : TCExp A} →
e ~ e' :: A →
d ~>* e →
d' ~>* e' →
d ~ d' :: A
logical-converse-evaluation eq eval1 eval2 with logical-converse-evaluation-1 eq eval1
... | eq1 with logical-converse-evaluation-1 (logical-sym eq1) eval2
... | eq2 = logical-sym eq2
-- This is the hard one.
ological-refl : ∀{Γ} {A} → (e : TExp Γ A) → Γ ⊢ e ~ e :: A
ological-refl (var x) η = η x
ological-refl {Γ} {A ⇒ B} (Λ e) {γ = γ} {γ' = γ'} η = lam-case
where lam-case : (e₁ e₁' : TExp [] A) → LogicalEq A e₁ e₁' →
LogicalEq B (Λ (ssubst (liftγ γ) e) $ e₁) (Λ (ssubst (liftγ γ') e) $ e₁')
lam-case e₁ e₁' arg-eq with ological-refl e (extendLogicalEQΓ η arg-eq)
... | equiv with combine-subst-noob γ e e₁ | combine-subst-noob γ' e e₁'
... | eq1 | eq2 with ID.coe2 (LogicalEq B) eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step step-beta) (eval-step step-beta)
ological-refl (e $ e') η with ological-refl e η | ological-refl e' η
... | eq-e | eq-e' = eq-e _ _ eq-e'
ological-refl zero η = kleeneq zero val-zero eval-refl eval-refl
ological-refl (suc e) η with ological-refl e η
... | kleeneq n val S1 S2 = kleeneq (suc n) (val-suc val)
(eval-compat step-suc S1) (eval-compat step-suc S2)
ological-refl {Γ} {A} (rec e e0 es) {γ = γ} {γ' = γ'} η with ological-refl e η
... | kleeneq n val E1 E2 = logical-converse-evaluation (inner val)
(eval-compat step-rec E1) (eval-compat step-rec E2)
where inner : {n : TNat} (val : TVal n) →
((rec n (ssubst γ e0) (ssubst (liftγ γ) es)) ~
(rec n (ssubst γ' e0) (ssubst (liftγ γ') es)) :: A)
inner val-zero = logical-converse-evaluation (ological-refl e0 η)
(eval-step step-rec-z) (eval-step step-rec-z)
inner (val-suc val) with ological-refl es (extendLogicalEQΓ η (inner val))
... | equiv with combine-subst-noob γ es _ | combine-subst-noob γ' es _
... | eq1 | eq2 with ID.coe2 (LogicalEq A) eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step (step-rec-s val)) (eval-step (step-rec-s val))
ological-refl' : ∀{Γ} {A} → Reflexive (OLogicalEq Γ A)
ological-refl' {x = x} = ological-refl x
-- Extend it back to closed terms and to substitutions
logical-refl : ∀{A} → Reflexive (LogicalEq A)
logical-refl {x = e} with ological-refl e (emptyLogicalEqΓ {γ = emptyγ} {γ' = emptyγ})
... | leq = ID.coe2 (LogicalEq _) (subid e) (subid e) leq
logicalγ-refl : ∀{Γ} → Reflexive (LogicalEqΓ Γ)
logicalγ-refl n = logical-refl
logical-is-equivalence : ∀{A : TTp} → IsEquivalence (LogicalEq A)
logical-is-equivalence = record { refl_ = logical-refl
; sym_ = logical-sym
; trans_ = logical-trans }
logicalγ-is-equivalence : ∀{Γ : Ctx} → IsEquivalence (LogicalEqΓ Γ)
logicalγ-is-equivalence = record { refl_ = λ {γ} → logicalγ-refl {_} {γ}
; sym_ = logicalγ-sym
; trans_ = logicalγ-trans }
-- I do not understand why these need to be eta expanded
ological-is-equivalence : ∀{Γ : Ctx} {A : TTp} → IsEquivalence (OLogicalEq Γ A)
ological-is-equivalence = record { refl_ = λ {e} → ological-refl' {_} {_} {e}
; sym_ = λ {e e'} → ological-sym {_} {_} {e} {e'}
; trans_ = λ {e e' e''} → ological-trans {_} {_} {e} {e'} {e''}}
-- This is basically the same proof as reflexivity...?
-- That's weird.
ological-is-congruence : Congruence OLogicalEq
ological-is-congruence leq ∘ η = leq η
ological-is-congruence leq (e₁ e$ C) η with ological-is-congruence leq C η | ological-refl e₁ η
... | equiv-rhs | equiv-lhs = equiv-lhs _ _ equiv-rhs
ological-is-congruence leq (C $e e₂) η with ological-is-congruence leq C η | ological-refl e₂ η
... | equiv-lhs | equiv-rhs = equiv-lhs _ _ equiv-rhs
ological-is-congruence {e = e} {e' = e'} leq (Λ C) {γ = γ} {γ' = γ'} η = body
where -- I feel like I shouldn't have to give so much type information here.
body : (e₁ e₁' : TExp [] _) →
LogicalEq _ e₁ e₁' →
LogicalEq _ (Λ (ssubst (liftγ _) (C < e >)) $ e₁)
(Λ (ssubst (liftγ _) (C < e' >)) $ e₁')
body e₁ e₁' arg-eq with ological-is-congruence {e = e} {e' = e'} leq C (extendLogicalEQΓ η arg-eq)
... | equiv with combine-subst-noob γ (C < e >) e₁ | combine-subst-noob γ' (C < e' >) e₁'
... | eq1 | eq2 with ID.coe2 (LogicalEq _) eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step step-beta) (eval-step step-beta)
ological-is-congruence leq (suc C) η with ological-is-congruence leq C η
... | kleeneq n val S1 S2 = kleeneq (suc n) (val-suc val)
(eval-compat step-suc S1) (eval-compat step-suc S2)
-- Is there a way to abstract out all the shit in these three bits?
ological-is-congruence {e = e} {e' = e'} leq {A' = A'} (rec1 C e0 es) {γ = γ} {γ' = γ'} η
with ological-is-congruence leq C η
... | kleeneq n val E1 E2 = logical-converse-evaluation (inner val)
(eval-compat step-rec E1) (eval-compat step-rec E2)
where inner : {n : TNat} (val : TVal n) →
((rec n (ssubst γ e0) (ssubst (liftγ γ) es)) ~
(rec n (ssubst γ' e0) (ssubst (liftγ γ') es)) :: A')
inner val-zero = logical-converse-evaluation (ological-refl e0 η)
(eval-step step-rec-z) (eval-step step-rec-z)
inner (val-suc val) with ological-refl es (extendLogicalEQΓ η (inner val))
... | equiv with combine-subst-noob γ es _ | combine-subst-noob γ' es _
... | eq1 | eq2 with ID.coe2 (LogicalEq A') eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step (step-rec-s val)) (eval-step (step-rec-s val))
ological-is-congruence {e = e} {e' = e'} leq {A' = A'} (rec2 en C es) {γ = γ} {γ' = γ'} η
with ological-refl en η
... | kleeneq n val E1 E2 = logical-converse-evaluation (inner val)
(eval-compat step-rec E1) (eval-compat step-rec E2)
where inner : {n : TNat} (val : TVal n) →
((rec n (ssubst γ (C < e >)) (ssubst (liftγ γ) es)) ~
(rec n (ssubst γ' (C < e' >)) (ssubst (liftγ γ') es)) :: A')
inner val-zero = logical-converse-evaluation (ological-is-congruence leq C η)
(eval-step step-rec-z) (eval-step step-rec-z)
inner (val-suc val) with ological-refl es (extendLogicalEQΓ η (inner val))
... | equiv with combine-subst-noob γ es _ | combine-subst-noob γ' es _
... | eq1 | eq2 with ID.coe2 (LogicalEq A') eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step (step-rec-s val)) (eval-step (step-rec-s val))
ological-is-congruence {e = e} {e' = e'} leq {A' = A'} (rec3 en e0 C) {γ = γ} {γ' = γ'} η
with ological-refl en η
... | kleeneq n val E1 E2 = logical-converse-evaluation (inner val)
(eval-compat step-rec E1) (eval-compat step-rec E2)
where inner : {n : TNat} (val : TVal n) →
((rec n (ssubst γ e0) (ssubst (liftγ γ) (C < e >))) ~
(rec n (ssubst γ' e0) (ssubst (liftγ γ') (C < e' >))) :: A')
inner val-zero = logical-converse-evaluation (ological-refl e0 η)
(eval-step step-rec-z) (eval-step step-rec-z)
inner (val-suc val) with ological-is-congruence leq C (extendLogicalEQΓ η (inner val))
... | equiv with combine-subst-noob γ (C < e >) _ | combine-subst-noob γ' (C < e' >) _
... | eq1 | eq2 with ID.coe2 (LogicalEq A') eq1 eq2 equiv
... | equiv' = logical-converse-evaluation equiv'
(eval-step (step-rec-s val)) (eval-step (step-rec-s val))
ological-consistent : Consistent OLogicalEq
ological-consistent leq with leq (emptyLogicalEqΓ {γ = emptyγ} {γ' = emptyγ})
... | keq = ID.coe2 KleeneEq (subid _) (subid _) keq
ological-equiv-nat-val : (e : TNat) → Σ[ n :: TNat ] (TVal n × ([] ⊢ e ~ n :: nat))
ological-equiv-nat-val e with ological-consistent {e = e} {e' = e} (ological-refl e)
... | kleeneq n val E1 E2 = n , (val , (closed-logical-imp-open (kleeneq n val E1 eval-refl)))
log-is-con-congruence : IsConsistentCongruence OLogicalEq
log-is-con-congruence = record { equiv = ological-is-equivalence
; cong = ological-is-congruence
; consistent = ological-consistent
}
| {
"alphanum_fraction": 0.5736185056,
"avg_line_length": 51.8761904762,
"ext": "agda",
"hexsha": "7bed748c6f1b5e70aecb36cc4a6062eba0b723bf",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-05-04T22:37:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-04-26T11:39:14.000Z",
"max_forks_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "msullivan/godels-t",
"max_forks_repo_path": "Eq/LogicalTheory.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"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": "msullivan/godels-t",
"max_issues_repo_path": "Eq/LogicalTheory.agda",
"max_line_length": 106,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "7412725cf27873b2b23f7e411a236a97dd99ef91",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "msullivan/godels-t",
"max_stars_repo_path": "Eq/LogicalTheory.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T00:28:03.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-12-25T01:52:57.000Z",
"num_tokens": 3549,
"size": 10894
} |
-- Pattern matching on a datatype in Prop is disallowed
{-# OPTIONS --enable-prop #-}
open import Agda.Builtin.Bool
data TestProp : Prop where
p₁ p₂ : TestProp
toBool : TestProp → Bool
toBool p₁ = true
toBool p₂ = false
| {
"alphanum_fraction": 0.7168141593,
"avg_line_length": 17.3846153846,
"ext": "agda",
"hexsha": "abc91d589482672bf7d083f35bf70ddbdf7f0525",
"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": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "asr/eagda",
"max_forks_repo_path": "test/Fail/Prop-NoMatch.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"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": "asr/eagda",
"max_issues_repo_path": "test/Fail/Prop-NoMatch.agda",
"max_line_length": 55,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "7220bebfe9f64297880ecec40314c0090018fdd0",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "asr/eagda",
"max_stars_repo_path": "test/Fail/Prop-NoMatch.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": 64,
"size": 226
} |
{-# OPTIONS --safe #-}
module Cubical.Algebra.DirectSum.DirectSumFun.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Data.Nat renaming (_+_ to _+n_ ; _·_ to _·n_)
open import Cubical.Data.Nat.Order
open import Cubical.Data.Sigma
open import Cubical.HITs.PropositionalTruncation as PT
open import Cubical.Algebra.Group
open import Cubical.Algebra.AbGroup
open import Cubical.Algebra.DirectSum.DirectSumFun.Base
private variable
ℓ : Level
open GroupTheory
open AbGroupStr
-----------------------------------------------------------------------------
-- AbGroup Properties
module DSF-properties
(G : ℕ → Type ℓ)
(Gstr : (n : ℕ) → AbGroupStr (G n))
where
private
GG : ℕ → Group ℓ
GG n = AbGroup→Group ((G n) , (Gstr n))
isSet⊕Fun : isSet (⊕Fun G Gstr)
isSet⊕Fun = isSetΣSndProp (isSetΠ (λ n → is-set (Gstr n))) (λ _ → squash₁)
-- Object
0⊕Fun : ⊕Fun G Gstr
0⊕Fun = (λ n → 0g (Gstr n)) , ∣ (0 , λ n p → refl) ∣₁
_+⊕Fun_ : ⊕Fun G Gstr → ⊕Fun G Gstr → ⊕Fun G Gstr
_+⊕Fun_ (f , Anf) (g , Ang) = f+g , Anf+g Anf Ang
where
f+g = λ n → Gstr n ._+_ (f n) (g n)
Anf+g : AlmostNullP G Gstr f → AlmostNullP G Gstr g → AlmostNullP G Gstr f+g
Anf+g = PT.rec2 squash₁
(λ { (k , nf) → λ { (l , ng) →
∣ ((k +n l) ,
(λ n p → cong₂ ((Gstr n)._+_) (nf n (<-+k-trans p)) (ng n (<-k+-trans p))
∙ +IdR (Gstr n) (0g (Gstr n)))) ∣₁ } })
Inv⊕Fun : ⊕Fun G Gstr → ⊕Fun G Gstr
Inv⊕Fun (f , Anf) = f- , Anf- Anf
where
f- = λ n → (Gstr n).-_ (f n)
Anf- : AlmostNullP G Gstr f → AlmostNullP G Gstr f-
Anf- = PT.rec squash₁
(λ { (k , nf) →
∣ (k , λ n p → cong ((Gstr n).-_) (nf n p) ∙ inv1g (GG n)) ∣₁})
-- AbGroup Properties
+⊕FunAssoc : (x y z : ⊕Fun G Gstr) → x +⊕Fun (y +⊕Fun z) ≡ (x +⊕Fun y) +⊕Fun z
+⊕FunAssoc (f , Anf) (g , Ang) (h , Anh) =
ΣPathTransport→PathΣ _ _
(funExt (λ n → Gstr n .+Assoc _ _ _) , (squash₁ _ _))
+⊕FunRid : (x : ⊕Fun G Gstr) → x +⊕Fun 0⊕Fun ≡ x
+⊕FunRid (f , Anf) = ΣPathTransport→PathΣ _ _
((funExt (λ n → +IdR (Gstr n) _)) , squash₁ _ _)
+⊕FunInvR : (x : ⊕Fun G Gstr) → x +⊕Fun Inv⊕Fun x ≡ 0⊕Fun
+⊕FunInvR (f , Anf) = ΣPathTransport→PathΣ _ _
((funExt (λ n → +InvR (Gstr n) _)) , (squash₁ _ _))
+⊕FunComm : (x y : ⊕Fun G Gstr) → x +⊕Fun y ≡ y +⊕Fun x
+⊕FunComm (f , Anf) (g , Ang) = ΣPathTransport→PathΣ _ _
((funExt (λ n → Gstr n .+Comm _ _)) , (squash₁ _ _))
| {
"alphanum_fraction": 0.5278725825,
"avg_line_length": 32.1585365854,
"ext": "agda",
"hexsha": "91e8792d78781273fa9348ed0bfc04e17e3cf59c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "thomas-lamiaux/cubical",
"max_forks_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "thomas-lamiaux/cubical",
"max_issues_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Properties.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "58c0b83bb0fed0dc683f3d29b1709effe51c1689",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "thomas-lamiaux/cubical",
"max_stars_repo_path": "Cubical/Algebra/DirectSum/DirectSumFun/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1077,
"size": 2637
} |
{-# OPTIONS --safe #-}
module Issue2487-2 where
import Issue2487.A
| {
"alphanum_fraction": 0.7058823529,
"avg_line_length": 13.6,
"ext": "agda",
"hexsha": "d4cef607b47b622f56a61f159942e18e61a7e017",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/interaction/Issue2487-2.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/interaction/Issue2487-2.agda",
"max_line_length": 24,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/interaction/Issue2487-2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 19,
"size": 68
} |
{-# OPTIONS --erased-cubical --safe #-}
module MakeTracks where
open import Data.Fin using (Fin; #_; toℕ)
open import Data.List using (List; _∷_; []; map; concat; _++_; replicate; zip; length; take; drop)
open import Data.Nat using (_*_; ℕ; suc; _+_)
open import Data.Nat.Show using (show)
open import Data.Product using (_,_; uncurry)
open import Data.Vec using (fromList; toList; Vec; _∷_; []; lookup) renaming (replicate to rep; zip to vzip; map to vmap; concat to vconcat; _++_ to _+v_)
open import Instruments
open import Interval
open import Note
open import Pitch
open import MidiEvent
open import Util using (fins')
open import Transformation
velocity : Velocity
velocity = # 60
makeTrack : InstrumentNumber-1 → ℕ → Channel-1 → List Note → MidiTrack
makeTrack inst tempo n notes = track (show (suc (toℕ n))) inst n tempo (notes→events velocity notes)
makeTracks : {k : Fin maxChannels} → Vec InstrumentNumber-1 maxChannels → ℕ → Vec (List Note) (toℕ k) → Vec MidiTrack (toℕ k)
makeTracks {k} insts tempo lines =
vmap (λ (i , ns) → makeTrack (lookup insts i) tempo i ns)
(vzip (fins' maxChannels k) lines)
makeTrackList : {k : Fin maxChannels} → Vec InstrumentNumber-1 maxChannels → ℕ → Vec (List Note) (toℕ k) → List MidiTrack
makeTrackList insts tempo lines = toList (makeTracks insts tempo lines)
| {
"alphanum_fraction": 0.6976573939,
"avg_line_length": 41.3939393939,
"ext": "agda",
"hexsha": "a784e465919cd683e135f2bfb7b6de751fa744ce",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2020-11-10T04:04:40.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-01-12T17:02:36.000Z",
"max_forks_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "halfaya/MusicTools",
"max_forks_repo_path": "agda/MakeTracks.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_issues_repo_issues_event_max_datetime": "2020-11-17T00:58:55.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-11-13T01:26:20.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "halfaya/MusicTools",
"max_issues_repo_path": "agda/MakeTracks.agda",
"max_line_length": 161,
"max_stars_count": 28,
"max_stars_repo_head_hexsha": "04896c61b603d46011b7d718fcb47dd756e66021",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "halfaya/MusicTools",
"max_stars_repo_path": "agda/MakeTracks.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-04T18:04:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-21T09:08:52.000Z",
"num_tokens": 396,
"size": 1366
} |
{-# OPTIONS --allow-unsolved-metas #-}
module Oscar.Data.Term.ThickAndThin {𝔣} (FunctionName : Set 𝔣) where
open import Oscar.Class.ThickAndThin
open import Oscar.Data.Term FunctionName
import Oscar.Data.Term.ThickAndThin.internal FunctionName as ⋆
instance ThickAndThinTerm : ThickAndThin Term
ThickAndThin.thin ThickAndThinTerm = ⋆.thin
ThickAndThin.thin-injective ThickAndThinTerm = ⋆.thin-injective
ThickAndThin.thick ThickAndThinTerm = ⋆.thick
ThickAndThin.thick∘thin=id ThickAndThinTerm = {!!}
ThickAndThin.check ThickAndThinTerm = {!!}
ThickAndThin.thin-check-id ThickAndThinTerm = {!!}
instance ThickAndThinTerms : ∀ {N} → ThickAndThin (Terms N)
ThickAndThin.thin ThickAndThinTerms x = ⋆.thins x
ThickAndThin.thin-injective ThickAndThinTerms y = ⋆.thins-injective y
ThickAndThin.thick ThickAndThinTerms = ⋆.thicks
ThickAndThin.thick∘thin=id ThickAndThinTerms = {!!}
ThickAndThin.check ThickAndThinTerms = {!!}
ThickAndThin.thin-check-id ThickAndThinTerms = {!!}
open import Oscar.Data.Fin
open import Oscar.Data.Fin.ThickAndThin
open import Oscar.Data.Maybe.properties
open import Oscar.Data.Nat
_for_ : ∀ {n} → Term n → Fin (suc n) → suc n ⊸ n
(t' for x) y = maybe i t' ((check x y))
| {
"alphanum_fraction": 0.774624374,
"avg_line_length": 38.6451612903,
"ext": "agda",
"hexsha": "c07acf64b752530a4e6f5a82d374a12c2075644d",
"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/Data/Term/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/Data/Term/ThickAndThin.agda",
"max_line_length": 69,
"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/Data/Term/ThickAndThin.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 374,
"size": 1198
} |
open import dynamics-core
module focus-formation where
-- every ε is an evaluation context -- trivially, here, since we don't
-- include any of the premises in red brackets about finality
focus-formation : ∀{d d' ε} → d == ε ⟦ d' ⟧ → ε evalctx
focus-formation (FHPlus1 sub) = ECPlus1 (focus-formation sub)
focus-formation (FHPlus2 sub) = ECPlus2 (focus-formation sub)
focus-formation FHOuter = ECDot
focus-formation (FHAp1 sub) = ECAp1 (focus-formation sub)
focus-formation (FHAp2 sub) = ECAp2 (focus-formation sub)
focus-formation (FHInl sub) = ECInl (focus-formation sub)
focus-formation (FHInr sub) = ECInr (focus-formation sub)
focus-formation (FHCase sub) = ECCase (focus-formation sub)
focus-formation (FHFst sub) = ECFst
focus-formation (FHSnd sub) = ECSnd
focus-formation (FHPair1 sub) = ECPair1 (focus-formation sub)
focus-formation (FHPair2 sub) = ECPair2 (focus-formation sub)
focus-formation (FHNEHole sub) = ECNEHole (focus-formation sub)
focus-formation (FHCast sub) = ECCast (focus-formation sub)
focus-formation (FHFailedCast x) = ECFailedCast (focus-formation x)
| {
"alphanum_fraction": 0.733213966,
"avg_line_length": 50.7727272727,
"ext": "agda",
"hexsha": "086263b71a49012699652154d457073d8d205964",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-agda",
"max_forks_repo_path": "focus-formation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-agda",
"max_issues_repo_path": "focus-formation.agda",
"max_line_length": 72,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a3640d7b0f76cdac193afd382694197729ed6d57",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-agda",
"max_stars_repo_path": "focus-formation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 355,
"size": 1117
} |
{- This file describes properties of computable relations. -}
open import bool
open import level
open import eq
open import product
open import product-thms
module bool-relations {ℓ : level}{A : Set ℓ} (_≤A_ : A → A → 𝔹) where
reflexive : Set (ℓ)
reflexive = ∀ {a : A} → a ≤A a ≡ tt
transitive : Set (ℓ)
transitive = ∀ {a b c : A} → a ≤A b ≡ tt → b ≤A c ≡ tt → a ≤A c ≡ tt
total : Set ℓ
total = ∀ {a b : A} → a ≤A b ≡ ff → b ≤A a ≡ tt
total-reflexive : total → reflexive
total-reflexive tot {a} with keep (a ≤A a)
total-reflexive tot {a} | tt , p = p
total-reflexive tot {a} | ff , p = tot p
_iso𝔹_ : A → A → 𝔹
d iso𝔹 d' = d ≤A d' && d' ≤A d
iso𝔹-intro : ∀{x y : A} → x ≤A y ≡ tt → y ≤A x ≡ tt → x iso𝔹 y ≡ tt
iso𝔹-intro p1 p2 rewrite p1 | p2 = refl
| {
"alphanum_fraction": 0.5913272011,
"avg_line_length": 23.78125,
"ext": "agda",
"hexsha": "809e02d6d7c82ba45c34726dc99bc872feae2f7e",
"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": "bool-relations.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": "bool-relations.agda",
"max_line_length": 69,
"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": "bool-relations.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 321,
"size": 761
} |
{-# OPTIONS --without-K #-}
open import lib.Basics
open import lib.types.Truncation
open import lib.types.Groupoid
open import lib.types.PathSet
module lib.types.FundamentalGroupoid {i} (A : Type i) where
fundamental-groupoid : Groupoid
fundamental-groupoid = record
{ El = A
; Arr = _=₀_ {A = A}
; Arr-level = λ _ _ → Trunc-level
; groupoid-struct = record
{ id = idp₀
; inv = !₀
; comp = _∙₀_
; unit-l = ∙₀-unit-l
; unit-r = ∙₀-unit-r
; assoc = ∙₀-assoc
; inv-l = !₀-inv-l
; inv-r = !₀-inv-r
}
}
| {
"alphanum_fraction": 0.5699481865,
"avg_line_length": 22.2692307692,
"ext": "agda",
"hexsha": "105f8c2c9617253bab2eb82db3d3e97aa504b00b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "lib/types/FundamentalGroupoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "lib/types/FundamentalGroupoid.agda",
"max_line_length": 59,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "lib/types/FundamentalGroupoid.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": 189,
"size": 579
} |
module _ where
open import Agda.Builtin.Equality
open import Agda.Builtin.Nat
module Vars (A : Set) where
variable
x : A
-- Was
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Reduce/Fast.hs:148
-- Should be
-- Cannot use generalized variable from let-opened module
record R : Set₁ where
field
A : Set
open Vars A
field
f : x ≡ x
| {
"alphanum_fraction": 0.6946386946,
"avg_line_length": 19.5,
"ext": "agda",
"hexsha": "749b082e5c6b66299b47493a748c142ec396e355",
"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/Issue3292b.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/Issue3292b.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/Issue3292b.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": 130,
"size": 429
} |
module Data.Logic where
open import Haskell.Prelude renaming (zero to Z; suc to S)
open import Relation.Nullary.Decidable
open import Data.Nat.DivMod
open import Data.Nat.Properties
open import Agda.Primitive
{-# FOREIGN AGDA2HS
import Data.Nat
#-}
---- Equational reasoning
useEq : {x y : Bool} -> x ≡ y -> .(IsTrue x) -> IsTrue y
useEq {true} {true} eq is = IsTrue.itsTrue
useEqFalse : {x y : Bool} -> x ≡ y -> .(IsFalse x) -> IsFalse y
useEqFalse {false} {false} eq is = IsFalse.itsFalse
isTrueToEquiv : {c : Bool} -> IsTrue c -> c ≡ true
isTrueToEquiv {true} p = refl
isFalseToEquiv : {c : Bool} -> IsFalse c -> c ≡ false
isFalseToEquiv {false} p = refl
-- symmetry of equality
sym : {u : Level} {A : Set u} {x y : A} → x ≡ y → y ≡ x
sym refl = refl
-- transitivity of equality
trans : {u : Level} {A : Set u} {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
-- congruence of equality
cong : {u v : Level} {A : Set u} {B : Set v} {x y : A} → (f : A → B) → x ≡ y → f x ≡ f y
cong f refl = refl
cong2 : {A B T : Set} {a1 a2 : A} {b1 b2 : B} → (f : A → B -> T) → a1 ≡ a2 -> b1 ≡ b2 → f a1 b1 ≡ f a2 b2
cong2 f refl refl = refl
cong3 : {A B C T : Set} {a1 a2 : A} {b1 b2 : B} {c1 c2 : C} → (f : A → B -> C -> T) → a1 ≡ a2 -> b1 ≡ b2 -> c1 ≡ c2 → f a1 b1 c1 ≡ f a2 b2 c2
cong3 f refl refl refl = refl
cong4 : {A B C D T : Set} {a1 a2 : A} {b1 b2 : B} {c1 c2 : C} {d1 d2 : D} → (f : A → B -> C -> D -> T) → a1 ≡ a2 -> b1 ≡ b2 → c1 ≡ c2 -> d1 ≡ d2 -> f a1 b1 c1 d1 ≡ f a2 b2 c2 d2
cong4 f refl refl refl refl = refl
begin_ : {u : Level} {A : Set u} → {x y : A} → x ≡ y → x ≡ y
begin p = p
_end : {u : Level} {A : Set u} → (x : A) → x ≡ x
x end = refl
_=⟨_⟩_ : {u : Level} {A : Set u} → (x : A) → {y z : A}
→ x ≡ y → y ≡ z → x ≡ z
x =⟨ p ⟩ q = trans p q
_=⟨⟩_ : {u : Level} {A : Set u} → (x : A) → {y : A} → x ≡ y → x ≡ y
x =⟨⟩ q = x =⟨ refl ⟩ q
infix 1 begin_
infix 3 _end
infixr 2 _=⟨_⟩_
infixr 2 _=⟨⟩_
---- General purpose proofs
propZeroImpliesLtOne : (x : Nat) -> IsFalse (x == 0) -> IsFalse (x < 1)
propZeroImpliesLtOne Z notZ = notZ
propZeroImpliesLtOne (S x) notZ = IsFalse.itsFalse
propFnIf : {a b : Set} -> {c : Bool} {x y : a} (f : a -> b) -> (if c then f x else f y) ≡ f (if c then x else y)
propFnIf {c = false} f = refl
propFnIf {c = true} f = refl
propMaxSuc : (x y : Nat) -> max (S x) (S y) ≡ S (max x y)
propMaxSuc Z Z = refl
propMaxSuc Z (S y) = refl
propMaxSuc (S x) Z = refl
propMaxSuc (S x) (S y) =
begin
max (S $ S x) (S $ S y)
=⟨⟩
(if x < y then (S $ S y) else (S $ S x))
=⟨ propFnIf S ⟩
(S $ (if x < y then (S y) else (S x)))
=⟨⟩
S (max (S x) (S y))
end
propMaxRefl : (x y : Nat) -> max x y ≡ max y x
propMaxRefl Z Z = refl
propMaxRefl Z (S y) = refl
propMaxRefl (S x) Z = refl
propMaxRefl (S x) (S y) =
begin
max (S x) (S y)
=⟨ propMaxSuc x y ⟩
S (max x y)
=⟨ cong S (propMaxRefl x y) ⟩
S (max y x)
=⟨ sym $ propMaxSuc y x ⟩
max (S y) (S x)
end
propIsTrueCombine2 : {a b : Bool} -> IsTrue a -> IsTrue b -> IsTrue (a && b)
propIsTrueCombine2 {true} {true} ta tb = IsTrue.itsTrue
propIsTrueCombine4 : {a b c d : Bool} -> IsTrue a -> IsTrue b -> IsTrue c -> IsTrue d -> IsTrue ((a && b) && (c && d))
propIsTrueCombine4 {true} {true} {true} {true} ta tb tc td = IsTrue.itsTrue
propIsTrueCombine4Alt : {a b c d : Bool} -> IsTrue a -> IsTrue b -> IsTrue c -> IsTrue d -> IsTrue (a && b && c && d)
propIsTrueCombine4Alt {true} {true} {true} {true} ta tb tc td = IsTrue.itsTrue
andRefl : (a b : Bool) -> (a && b) ≡ (b && a)
andRefl false false = refl
andRefl false true = refl
andRefl true false = refl
andRefl true true = refl
orFst : {a b : Bool} -> IsTrue a -> IsTrue (a || b)
orFst {true} {b} ap = IsTrue.itsTrue
andFst : {a b : Bool} -> IsTrue (a && b) -> IsTrue a
andFst {true} {true} ab = IsTrue.itsTrue
andSnd : {a b : Bool} -> IsTrue (a && b) -> IsTrue b
andSnd {true} {true} ab = IsTrue.itsTrue
andSndI : {a b : Bool} -> .(IsTrue (a && b)) -> IsTrue b
andSndI {true} {true} ab = IsTrue.itsTrue
and1 : {a b c d : Bool} -> IsTrue (a && b && c && d) -> IsTrue a
and1 {true} {true} {true} {true} abcd = IsTrue.itsTrue
and2 : {a b c d : Bool} -> IsTrue (a && b && c && d) -> IsTrue b
and2 {true} {true} {true} {true} abcd = IsTrue.itsTrue
and3 : {a b c d : Bool} -> IsTrue (a && b && c && d) -> IsTrue c
and3 {true} {true} {true} {true} abcd = IsTrue.itsTrue
and4 : {a b c d : Bool} -> IsTrue (a && b && c && d) -> IsTrue d
and4 {true} {true} {true} {true} abcd = IsTrue.itsTrue
andCombine : {a b : Bool} -> IsTrue a -> IsTrue b -> IsTrue (a && b)
andCombine {true} {true} ta tb = IsTrue.itsTrue
boolAndTrue : (a : Bool) -> (a && true) ≡ a
boolAndTrue false = refl
boolAndTrue true = refl
ifTrue : {u : Level} {t : Set u} {a b : t} (c : Bool) -> IsTrue c -> (if c then a else b) ≡ a
ifTrue true tc = refl
ifFalse : {t : Set} {a b : t} (c : Bool) -> IsFalse c -> (if c then a else b) ≡ b
ifFalse false fc = refl
infix -2 ifc_then_else_
ifc_then_else_ : {u : Level} {a : Set u} → (c : Bool) → ({{IsTrue c}} → a) → ({{IsFalse c}} → a) → a
ifc false then x else y = y {{IsFalse.itsFalse}}
ifc true then x else y = x {{IsTrue.itsTrue}}
{-# COMPILE AGDA2HS ifc_then_else_ #-}
ifcTrue : {u : Level} {t : Set u} -> (c : Bool) {a : {{.(IsTrue c)}} -> t} {b : {{.(IsFalse c)}} -> t} -> .(ct : IsTrue c) -> (ifc c then (λ {{p}} -> a) else (λ {{p}} -> b)) ≡ (a {{ct}})
ifcTrue true {a} {b} ct = refl
ifcFalse : {u : Level} {t : Set u} -> (c : Bool) {a : {{.(IsTrue c)}} -> t} {b : {{.(IsFalse c)}} -> t} -> .(ct : IsFalse c) -> (ifc c then (λ {{p}} -> a) else (λ {{p}} -> b)) ≡ (b {{ct}})
ifcFalse false {a} {b} ct = refl
propFnIfc : {a b : Set} -> (c : Bool) {x : {{IsTrue c}} -> a} {y : {{IsFalse c}} -> a} (f : a -> b)
-> (ifc c then f x else f y) ≡ f (ifc c then x else y)
propFnIfc false f = refl
propFnIfc true f = refl
propFnDistributeIfc2 : {a b : Set} -> (c1 c2 : Bool) {w x y z : a} (f : a -> b)
-> f (ifc c1 then (ifc c2 then w else x) else (ifc c2 then y else z))
≡ (ifc c1 then (ifc c2 then f w else f x) else (ifc c2 then f y else f z))
propFnDistributeIfc2 false false f = refl
propFnDistributeIfc2 false true f = refl
propFnDistributeIfc2 true false f = refl
propFnDistributeIfc2 true true f = refl
propIfcBranchesSame : {t : Set} -> {c : Bool} (v : t)
-> (ifc c then v else v) ≡ v
propIfcBranchesSame {c = false} v = refl
propIfcBranchesSame {c = true} v = refl
propIfBranchesSame : {t : Set} -> {c : Bool} (v : t)
-> (if c then v else v) ≡ v
propIfBranchesSame {c = false} v = refl
propIfBranchesSame {c = true} v = refl
ifToIfc : {t : Set} {c : Bool} {a b : t} -> (if c then a else b) ≡ (ifc c then a else b)
ifToIfc {c = false} = refl
ifToIfc {c = true} = refl
ifTrueMap : {t : Set} -> {c : Bool} {a a2 b : t} -> (IsTrue c -> a ≡ a2) -> (if c then a else b) ≡ (if c then a2 else b)
ifTrueMap {c = false} aa2 = refl
ifTrueMap {c = true} {a} {a2} aa2 =
begin
a
=⟨ aa2 IsTrue.itsTrue ⟩
a2
end
ifcTrueMap : {t : Set} -> {c : Bool} {a a2 b : t} -> (IsTrue c -> a ≡ a2) -> (ifc c then a else b) ≡ (ifc c then a2 else b)
ifcTrueMap {c = false} aa2 = refl
ifcTrueMap {c = true} {a} {a2} aa2 =
begin
a
=⟨ aa2 IsTrue.itsTrue ⟩
a2
end
ifTrueNested : {t : Set} -> {c1 c2 : Bool} {a b c : t} -> (c1 ≡ c2) -> (if c1 then (if c2 then a else b) else c) ≡ (if c1 then a else c)
ifTrueNested {t} {false} {false} {a} {b} {c} c1eqc2 = refl
ifTrueNested {t} {true} {true} {a} {b} {c} c1eqc2 = refl
ifFalseNested : {t : Set} -> {c1 c2 : Bool} {a b c : t} -> (c1 ≡ c2) -> (if c1 then a else (if c2 then b else c)) ≡ (if c1 then a else c)
ifFalseNested {t} {false} {false} {a} {b} {c} c1eqc2 = refl
ifFalseNested {t} {true} {true} {a} {b} {c} c1eqc2 = refl
---- Useful functions
div : Nat -> (divisor : Nat) -> {≢0 : False (divisor ≟ 0)} -> Nat
div a b {p} = _/_ a b {p}
-- Does not need compile, since it is already defined in haskell
mod : Nat -> (divisor : Nat) -> {≢0 : False (divisor ≟ 0)} -> Nat
mod a b {p} = _%_ a b {p}
-- Does not need compile, since it is already defined in haskell
addLte : (a b c : Nat) -> IsTrue (c == a + b) -> IsTrue (a <= c)
addLte Z Z Z abc = IsTrue.itsTrue
addLte Z (S b) (S c) abc = IsTrue.itsTrue
addLte (S a) Z (S c) abc = addLte a Z c abc
addLte (S a) (S b) (S c) abc = addLte a (S b) c abc
0+n : (n : Nat) -> IsTrue (n == 0 + n)
0+n Z = IsTrue.itsTrue
0+n (S n) = 0+n n
addSuc : (a b c : Nat) -> IsTrue (c == a + S b) -> IsTrue (c == S a + b)
addSuc Z Z (S c) abc = abc
addSuc Z (S b) (S c) abc = abc
addSuc (S a) Z (S c) abc = addSuc a Z c abc
addSuc (S a) (S b) (S c) abc = addSuc a (S b) c abc
-- m = k + j ==> mod-helper k m n j = (n + k) mod (1 + m).
modHelperLt : (k m n j : Nat)
-> IsTrue (m == k + j)
-> IsTrue (mod-helper k m n j <= m)
modHelperLt k m Z j i1 = addLte k j m i1
modHelperLt k m (S n) Z i1 = modHelperLt 0 m n m (0+n m)
modHelperLt k m (S n) (S j) i1 = modHelperLt (S k) m n j (addSuc k j m i1)
lteToLt : (a b : Nat) -> (a <= b) ≡ (a < S b)
lteToLt Z Z = refl
lteToLt Z (S b) = refl
lteToLt (S a) Z = refl
lteToLt (S a) (S b) = lteToLt a b
modLt : (a b : Nat) {≢0 : False (b ≟ 0)} -> IsTrue ((mod a b {≢0}) < b)
modLt a b@(S bs) =
let
pgoal : IsTrue (mod a b <= bs)
pgoal = modHelperLt 0 bs a bs (0+n bs)
in useEq (lteToLt (mod a b) bs) pgoal
pow : Nat -> Nat -> Nat
pow b Z = 1
pow b (S e) = b * pow b e
{-# COMPILE AGDA2HS pow #-}
mul_not_zero : {a b : Nat} -> IsFalse (a == 0) -> IsFalse (b == 0) -> IsFalse (a * b == 0)
mul_not_zero {S a} {S b} az bz = IsFalse.itsFalse
pow_not_zero : (n : Nat) -> IsFalse (pow 2 n == 0)
pow_not_zero Z = IsFalse.itsFalse
pow_not_zero (S sn) = mul_not_zero {2} {pow 2 sn} IsFalse.itsFalse (pow_not_zero sn)
false_convert : (n : Nat) -> IsFalse (n == 0) -> False (n ≟ 0)
false_convert (S n) if = tt
pow_not_zero_cv : (n : Nat) -> False (pow 2 n ≟ 0)
pow_not_zero_cv n = false_convert (pow 2 n) $ pow_not_zero n
zeroLteAny : (a : Nat) -> IsTrue (0 <= a)
zeroLteAny Z = IsTrue.itsTrue
zeroLteAny (S a) = IsTrue.itsTrue
lteSum : (a b s : Nat) -> (a <= b) ≡ (s + a <= s + b)
lteSum a b Z = refl
lteSum a b (S s) = lteSum a b s
lteSumOne : (a b s : Nat) -> IsTrue (a <= b) -> IsTrue (a <= s + b)
lteSumOne a b Z ab = ab
lteSumOne Z b (S n) ab = IsTrue.itsTrue
lteSumOne (S Z) Z (S Z) ab = IsTrue.itsTrue
lteSumOne (S (S n)) Z (S Z) ab = ab
lteSumOne (S n₁) (S n) (S Z) ab = lteSumOne n₁ n 1 ab
lteSumOne (S n₁) b (S (S n)) ab = lteSumOne n₁ (n + b) 1 (lteSumOne (S n₁) b (S n) ab)
anyGteZero : (a : Nat) -> IsTrue (a >= 0)
anyGteZero Z = IsTrue.itsTrue
anyGteZero (S a) = IsTrue.itsTrue
{-# TERMINATING #-}
log2up : Nat -> Nat
-- UNSAFE: This terminates since x/2 always decreases if x > 1
log2up 0 = 0
log2up 1 = 0
log2up (S (S x)) = S (log2up (div (S (S (S x))) 2))
{-# COMPILE AGDA2HS log2up #-}
divHelperReduce : (x a b c : Nat) -> div-helper (S x) a b c ≡ S (div-helper x a b c)
divHelperReduce x a Z c = refl
divHelperReduce x a (S b) Z =
begin
div-helper (S (S x)) a b a
=⟨ divHelperReduce (S x) a b a ⟩
S (div-helper (S x) a b a)
end
divHelperReduce x a (S b) (S c) = divHelperReduce x a b c
div2Reduce : (x : Nat) -> div (2 + x) 2 ≡ S (div x 2)
div2Reduce Z = refl
div2Reduce x@(S sx) =
begin
div (2 + x) 2
=⟨⟩
div-helper 1 1 sx 0
=⟨ divHelperReduce 0 1 sx 0 ⟩
S (div-helper 0 1 sx 0)
=⟨⟩
S (div x 2)
end
isTrueEquiv : {b : Bool} -> IsTrue b -> true ≡ b
isTrueEquiv {true} t = refl
plusGteOne : (a b : Nat) -> IsTrue (a >= 1) -> IsTrue (a + b >= 1)
plusGteOne (S a) b p = anyGteZero (a + b)
multGteOne : (a b : Nat) -> IsTrue (a >= 1) -> IsTrue (b >= 1) -> IsTrue (a * b >= 1)
multGteOne (S a) (S b) pa pb = plusGteOne (S b) (a * (S b)) pb
powGteOne : (n : Nat) -> IsTrue (pow 2 n >= 1)
powGteOne Z = IsTrue.itsTrue
powGteOne (S n) = multGteOne 2 (pow 2 n) IsTrue.itsTrue (powGteOne n)
add-assoc : (a b c : Nat) → (a + b) + c ≡ a + (b + c)
add-assoc Z b c = refl
add-assoc (S a) b c = cong S (add-assoc a b c)
add-n-zero : (n : Nat) → n + Z ≡ n
add-n-zero Z = refl
add-n-zero (S n) = cong S (add-n-zero n)
add-n-suc : (m n : Nat) → m + (S n) ≡ S (m + n)
add-n-suc Z n = refl
add-n-suc (S m) n = cong S (add-n-suc m n)
add-comm : (m n : Nat) → m + n ≡ n + m
add-comm m Z = add-n-zero m
add-comm m (S n) =
begin
m + (S n)
=⟨ add-n-suc m n ⟩
S (m + n)
=⟨ cong S (add-comm m n) ⟩
(S n) + m
end
mul-n-zero : (a : Nat) -> a * Z ≡ Z
mul-n-zero Z = refl
mul-n-zero (S a) = mul-n-zero a
mul-n-suc : (a b : Nat) -> a * (S b) ≡ a + a * b
mul-n-suc Z b = refl
mul-n-suc (S a) b =
begin
(S a) * (S b)
=⟨⟩
(S b) + a * (S b)
=⟨ cong (λ q -> (S b) + q) (mul-n-suc a b) ⟩
S (b + (a + a * b))
=⟨ cong S (sym $ add-assoc b a (a * b)) ⟩
S ((b + a) + a * b)
=⟨ cong (λ q -> S (q + a * b)) (add-comm b a) ⟩
S ((a + b) + a * b)
=⟨ cong S (add-assoc a b (a * b)) ⟩
S (a + (b + a * b) )
=⟨⟩
(S a) + (S a) * b
end
mul-comm : (a b : Nat) -> a * b ≡ b * a
mul-comm a Z = mul-n-zero a
mul-comm a (S b) =
begin
a * (S b)
=⟨ mul-n-suc a b ⟩
a + a * b
=⟨ cong (λ q -> a + q) (mul-comm a b) ⟩
(S b) * a
end
gteDouble : (a b : Nat) -> (a >= b) ≡ (a + a >= b + b)
gteDouble Z Z = refl
gteDouble Z (S b) = refl
gteDouble (S a) Z = refl
gteDouble (S a) (S b) =
begin
a >= b
=⟨ gteDouble a b ⟩
(S a) + a >= (S b) + b
=⟨ cong (λ q -> q >= (S b) + b) (add-comm (S a) a) ⟩
a + S a >= S b + b
=⟨ cong (λ q -> a + S a >= q) (add-comm (S b) b) ⟩
a + S a >= b + S b
end
gteMultBoth : (a b : Nat) -> (a >= b) ≡ (2 * a >= 2 * b)
gteMultBoth a b =
begin
a >= b
=⟨ gteDouble a b ⟩
a + a >= b + b
=⟨ cong (λ q -> a + q >= b + b) (sym $ add-comm a 0) ⟩
a + (a + 0) >= b + b
=⟨ cong (λ q -> a + (a + 0) >= b + q) (sym $ add-comm b 0) ⟩
a + (a + 0) >= b + (b + 0)
end
gteTransitive : (a b c : Nat) -> IsTrue (a >= b) -> IsTrue (b >= c) -> IsTrue (a >= c)
gteTransitive Z Z Z ab bc = IsTrue.itsTrue
gteTransitive (S a) Z Z ab bc = IsTrue.itsTrue
gteTransitive (S a) (S b) Z ab bc = IsTrue.itsTrue
gteTransitive (S a) (S b) (S c) ab bc = gteTransitive a b c ab bc
mul-div : (x : Nat) -> IsTrue (2 * (div (1 + x) 2) >= x)
mul-div Z = IsTrue.itsTrue
mul-div (S Z) = IsTrue.itsTrue
mul-div (S (S x)) =
let
p1 : IsTrue (2 + 2 * (div (1 + x) 2) >= 2 + x)
p1 = mul-div x
p2 : IsTrue (S (div (1 + x) 2) * 2 >= 2 + x)
p2 = useEq (cong (λ q -> 2 + q >= 2 + x) (mul-comm 2 (div (1 + x) 2))) p1
p3 : IsTrue (2 * S (div (1 + x) 2) >= 2 + x)
p3 = useEq (cong (λ q -> q >= 2 + x) (mul-comm (S (div (1 + x) 2)) 2)) p2
goal : IsTrue (2 * (div (3 + x) 2) >= 2 + x)
goal = useEq (cong (λ q -> 2 * q >= 2 + x) (sym $ div2Reduce (1 + x))) p3
in goal
log2upPow : (a b : Nat) -> .(IsTrue (a >= log2up b)) -> IsTrue (pow 2 a >= b)
log2upPow Z Z p = IsTrue.itsTrue
log2upPow Z (S Z) p = IsTrue.itsTrue
log2upPow (S a) Z p = anyGteZero (pow 2 (S a))
log2upPow (S a) (S Z) p = useEq
(begin
(S a) >= 0
=⟨ isTrueEquiv $ anyGteZero (S a) ⟩
true
=⟨ isTrueEquiv $ powGteOne (S a) ⟩
pow 2 (S a) >= 1
end) p
log2upPow (S a) (S (S b)) p =
let
p1 : IsTrue ( pow 2 a >= div (3 + b) 2 )
p1 = log2upPow a (div (3 + b) 2) p
p2 : IsTrue ( pow 2 (S a) >= 2 * (div (3 + b) 2) )
p2 = useEq (gteMultBoth (pow 2 a) (div (3 + b) 2)) p1
in gteTransitive (pow 2 (S a)) (2 * (div (3 + b) 2)) (2 + b) p2 ((mul-div (2 + b)))
eqToGte : (a b : Nat) -> IsTrue (a == b) -> IsTrue (a >= b)
eqToGte Z b ab = ab
eqToGte (S a) (S b) ab = eqToGte a b ab
gteInvert : (a b : Nat) -> IsTrue (a >= b) -> IsTrue (b <= a)
gteInvert Z Z ab = IsTrue.itsTrue
gteInvert (S a) Z ab = IsTrue.itsTrue
gteInvert (S a) (S b) ab = gteInvert a b ab
ltLteTransitive : (a b c : Nat) -> IsTrue (a < b) -> IsTrue (b <= c) -> IsTrue (a < c)
ltLteTransitive Z (S b) (S c) ab bc = IsTrue.itsTrue
ltLteTransitive (S a) (S b) (S c) ab bc = ltLteTransitive a b c ab bc
lteTransitive : (a b c : Nat) -> IsTrue (a <= b) -> IsTrue (b <= c) -> IsTrue (a <= c)
lteTransitive Z Z c ab bc = bc
lteTransitive Z (S b) (S c) ab bc = IsTrue.itsTrue
lteTransitive (S a) (S b) (S c) ab bc = lteTransitive a b c ab bc
incrLte : (a b : Nat) -> IsTrue (a <= b) -> IsTrue (a <= S b)
incrLte Z Z altb = IsTrue.itsTrue
incrLte Z (S b) altb = IsTrue.itsTrue
incrLte (S a) (S b) altb = incrLte a b altb
natPlusMinNat : (x : Nat) -> {{p : IsFalse (x < 1)}} -> x ≡ (S (x - 1))
natPlusMinNat (S x) = refl
transformLteRight : {a b c : Nat} -> b ≡ c -> IsTrue (a <= b) -> IsTrue (a <= c)
transformLteRight {a} {b} {.b} refl ab = ab
lteSelf : (v : Nat) -> IsTrue (v <= v)
lteSelf Z = IsTrue.itsTrue
lteSelf (S v) = lteSelf v
falseToNotTrue : {b : Bool} -> IsFalse (b) -> IsTrue (not b)
falseToNotTrue {false} if = IsTrue.itsTrue
notFalseToTrue : {b : Bool} -> IsFalse (not b) -> IsTrue b
notFalseToTrue {true} if = IsTrue.itsTrue
trueToNotFalse : {b : Bool} -> IsTrue (b) -> IsFalse (not b)
trueToNotFalse {true} if = IsFalse.itsFalse
notTrueToFalse : {b : Bool} -> IsTrue (not b) -> IsFalse (b)
notTrueToFalse {false} if = IsFalse.itsFalse
-- Law of reflexivity for equality
postulate
eqReflexivity : {t : Set} {{eqT : Eq t}} (v : t) -> IsTrue (v == v)
eqToEquiv : {t : Set} {{eqT : Eq t}} (a b : t) -> IsTrue (a == b) -> a ≡ b
botToAny : {t : Set} -> ⊥ -> t
botToAny ()
max4 : (a b c d : Nat) -> Nat
max4 a b c d = max (max a b) (max c d)
{-# COMPILE AGDA2HS max4 #-}
sub : (a b : Nat) -> {{ .( IsTrue (b <= a) ) }} -> Nat
sub a Z {{ab}} = a
sub (S a) (S b) {{ab}} = sub a b
{-# COMPILE AGDA2HS sub #-}
diff : (a b : Nat) -> Nat
diff a Z = a
diff Z b = b
diff (S a) (S b) = diff a b
{-# COMPILE AGDA2HS diff #-} | {
"alphanum_fraction": 0.5446782038,
"avg_line_length": 32.3846153846,
"ext": "agda",
"hexsha": "5ae40e07a4745d6a99fb7d9839ced46611106718",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "JonathanBrouwer/research-project",
"max_forks_repo_path": "src/Data/Logic.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Unlicense"
],
"max_issues_repo_name": "JonathanBrouwer/research-project",
"max_issues_repo_path": "src/Data/Logic.agda",
"max_line_length": 188,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "4959a3c9cd8563a1726e0e968e6a179008cd4d9f",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "JonathanBrouwer/research-project",
"max_stars_repo_path": "src/Data/Logic.agda",
"max_stars_repo_stars_event_max_datetime": "2021-05-25T09:10:20.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-05-25T09:10:20.000Z",
"num_tokens": 7806,
"size": 17682
} |
module Languages.ILL.Intermediate where
open import Utils.HaskellTypes
open import Utils.HaskellFunctions
open import Languages.ILL.TypeSyntax
{-# IMPORT Languages.ILL.Intermediate #-}
data IPattern : Set where
PTriv : IPattern
PVar : String → IPattern
PTensor : IPattern → IPattern → IPattern
{-# COMPILED_DATA IPattern Languages.ILL.Intermediate.IPattern
Languages.ILL.Intermediate.PTriv
Languages.ILL.Intermediate.PVar
Languages.ILL.Intermediate.PTensor #-}
data ITerm : Set where
Var : String → ITerm
Triv : ITerm
TTensor : ITerm → ITerm → ITerm
Lam : String → Type → ITerm → ITerm
Let : ITerm → Type → IPattern → ITerm → ITerm
App : ITerm → ITerm → ITerm
Promote : List (Triple ITerm String Type) → ITerm → ITerm
Discard : ITerm → ITerm → ITerm
Copy : ITerm → String → String → ITerm → ITerm
Derelict : ITerm → ITerm
{-# COMPILED_DATA ITerm Languages.ILL.Intermediate.ITerm
Languages.ILL.Intermediate.Var
Languages.ILL.Intermediate.Triv
Languages.ILL.Intermediate.TTensor
Languages.ILL.Intermediate.Lam
Languages.ILL.Intermediate.Let
Languages.ILL.Intermediate.App
Languages.ILL.Intermediate.Promote
Languages.ILL.Intermediate.Discard
Languages.ILL.Intermediate.Copy
Languages.ILL.Intermediate.Derelict #-}
| {
"alphanum_fraction": 0.6106870229,
"avg_line_length": 39.3,
"ext": "agda",
"hexsha": "7dc737bf7e9f0b9def5bdae1cf5abd0eaa78e81b",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "heades/Agda-LLS",
"max_forks_repo_path": "Source/ALL/Languages/ILL/Intermediate.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_issues_repo_issues_event_max_datetime": "2017-04-05T17:30:16.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-03-27T14:52:46.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "heades/Agda-LLS",
"max_issues_repo_path": "Source/ALL/Languages/ILL/Intermediate.agda",
"max_line_length": 65,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c83f5d8201362b26a749138f6dbff2dd509f85b1",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "heades/Agda-LLS",
"max_stars_repo_path": "Source/ALL/Languages/ILL/Intermediate.agda",
"max_stars_repo_stars_event_max_datetime": "2019-08-02T23:41:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-04-09T20:53:53.000Z",
"num_tokens": 359,
"size": 1572
} |
open import Level using (0ℓ)
open import Function using (_$_; _∘_)
open import Relation.Nullary using (yes; no)
open import Relation.Nullary.Decidable using (False; True)
open import Relation.Nullary.Negation using (contradiction)
open import Relation.Binary
using (Reflexive; Transitive; Trans; Antisymmetric; Asymmetric; Irreflexive; Decidable; Total; IsPreorder; IsPartialOrder; IsTotalOrder; TotalOrder; _Preserves₂_⟶_⟶_; Trichotomous; Tri; Irrelevant; Connex)
open Tri
open import Relation.Binary.PropositionalEquality
using (_≡_; _≢_; refl; sym; trans; cong; resp₂; module ≡-Reasoning)
renaming (isEquivalence to ≡-isEquivalence)
open import Relation.Binary.PropositionalEquality.WithK using (≡-erase)
open import Data.Bool using (T)
open import Data.Bool.Properties using (T?)
open import Data.Unit using (tt)
open import Data.List using (List)
open List
open import Data.Sum using (_⊎_)
open _⊎_
module AKS.Nat.Properties where
open import Data.Nat.Properties using (+-assoc; +-suc; +-comm; *-identityʳ; +-identityʳ; m+n≡0⇒m≡0; +-cancelʳ-≡; +-cancelˡ-≡; 1+n≢0; suc-injective) public
open import Data.Nat.Properties using (n∸n≡0; ∸-+-assoc) public
open import Data.Nat.Properties using (*-comm; *-1-commutativeMonoid) public
open import Polynomial.Simple.AlmostCommutativeRing using (AlmostCommutativeRing)
open import Polynomial.Simple.AlmostCommutativeRing.Instances using (module Nat)
open import Polynomial.Simple.Reflection using (solveOver)
open Nat.Reflection using (∀⟨_⟩)
open import AKS.Nat.Base using (ℕ; _+_; _*_; _∸_; lte; _≤_; _≥_; _≰_; _≱_; _<_; _≮_; _>_; _≯_; _<ᵇ_; _≟_; ℕ⁺; ℕ+; ⟅_⇓⟆; ⟅_⇑⟆; pred)
open ℕ
open import Algebra.Definitions {A = ℕ} _≡_ using (_DistributesOverˡ_)
≢⇒¬≟ : ∀ {n m} → n ≢ m → False (n ≟ m)
≢⇒¬≟ {n} {m} n≢m with n ≟ m
... | yes n≡m = contradiction n≡m n≢m
... | no _ = tt
¬≟⇒≢ : ∀ {n m} → False (n ≟ m) → n ≢ m
¬≟⇒≢ {n} {m} ¬n≟m n≡m with n ≟ m
... | no n≢m = contradiction n≡m n≢m
ℕ→ℕ⁺→ℕ : ∀ n {n≢0} → ⟅ ⟅ n ⇑⟆ {n≢0} ⇓⟆ ≡ n
ℕ→ℕ⁺→ℕ (suc n) {n≢0} = refl
⟅⇓⟆-injective : ∀ {n m} → pred ⟅ n ⇓⟆ ≡ pred ⟅ m ⇓⟆ → n ≡ m
⟅⇓⟆-injective {ℕ+ n} {ℕ+ m} refl = refl
n≢0∧m≢0⇒n*m≢0 : ∀ {n m} → n ≢ 0 → m ≢ 0 → n * m ≢ 0
n≢0∧m≢0⇒n*m≢0 {zero} {m} n≢0 m≢0 = contradiction refl n≢0
n≢0∧m≢0⇒n*m≢0 {suc n} {zero} n≢0 m≢0 = contradiction refl m≢0
n≢0∧m≢0⇒n*m≢0 {suc n} {suc m} n≢0 m≢0 ()
suc-injective-≡ : ∀ {n m} → suc n ≡ suc m → n ≡ m
suc-injective-≡ refl = refl
------------ _≤_ --------------
0≤n : ∀ {n} → 0 ≤ n
0≤n {n} = lte n refl
≤-refl : Reflexive _≤_
≤-refl {x} = lte 0 (≡-erase ∀⟨ x ∷ [] ⟩)
≤-reflexive : ∀ {n m} → n ≡ m → n ≤ m
≤-reflexive refl = ≤-refl
≤-trans : Transitive _≤_
≤-trans {x} (lte k₁ refl) (lte k₂ refl) = lte (k₁ + k₂) (≡-erase ∀⟨ x ∷ k₁ ∷ k₂ ∷ [] ⟩)
n+m≡n⇒m≡0 : ∀ {n m} → n + m ≡ n → m ≡ 0
n+m≡n⇒m≡0 {n} {m} n+m≡n = m≡0
where
open ≡-Reasoning
m≡0 : m ≡ 0
m≡0 = +-cancelˡ-≡ n $ begin
n + m ≡⟨ n+m≡n ⟩
n ≡⟨ sym (+-identityʳ n) ⟩
n + 0 ∎
≤-antisym : Antisymmetric _≡_ _≤_
≤-antisym {x} {y} (lte k₁ x+k₁≡y) (lte k₂ y+k₂≡x) = ≡-erase (+-cancelʳ-≡ x y x+k₁≡y+k₁)
where
open ≡-Reasoning
k₁+k₂≡0 : k₁ + k₂ ≡ 0
k₁+k₂≡0 = n+m≡n⇒m≡0 $ begin
x + (k₁ + k₂) ≡⟨ sym (+-assoc x k₁ k₂) ⟩
(x + k₁) + k₂ ≡⟨ cong (λ t → t + k₂) x+k₁≡y ⟩
y + k₂ ≡⟨ y+k₂≡x ⟩
x ∎
x+k₁≡y+k₁ : x + k₁ ≡ y + k₁
x+k₁≡y+k₁ = begin
x + k₁ ≡⟨ x+k₁≡y ⟩
y ≡⟨ sym (+-identityʳ y) ⟩
y + 0 ≡⟨ cong (λ t → y + t) (sym (m+n≡0⇒m≡0 k₁ k₁+k₂≡0)) ⟩
y + k₁ ∎
suc-mono-≤ : ∀ {n m} → n ≤ m → suc n ≤ suc m
suc-mono-≤ (lte k₁ refl) = lte k₁ refl
suc-injective-≤ : ∀ {n m} → suc n ≤ suc m → n ≤ m
suc-injective-≤ (lte k refl) = lte k refl
m≤m+n : ∀ {m n} → m ≤ m + n
m≤m+n {m} {n} = lte n refl
m≤n+m : ∀ {m n} → m ≤ n + m
m≤n+m {m} {n} = lte n (+-comm m n)
≤-erase : ∀ {n m} → n ≤ m → n ≤ m
≤-erase (lte k ≤-proof) = lte k (≡-erase ≤-proof)
≤-isPreorder : IsPreorder _≡_ _≤_
≤-isPreorder = record
{ isEquivalence = ≡-isEquivalence
; reflexive = ≤-reflexive
; trans = ≤-trans
}
≤-isPartialOrder : IsPartialOrder _≡_ _≤_
≤-isPartialOrder = record
{ isPreorder = ≤-isPreorder
; antisym = ≤-antisym
}
------------ _<_ --------------
<-trans : Transitive _<_
<-trans {x} (lte k₁ refl) (lte k₂ refl) = lte (suc (k₁ + k₂)) (≡-erase ∀⟨ x ∷ k₁ ∷ k₂ ∷ [] ⟩)
<-≤-trans : Trans _<_ _≤_ _<_
<-≤-trans x<y y≤z = ≤-trans x<y y≤z
≤-<-trans : Trans _≤_ _<_ _<_
≤-<-trans {x} (lte k₁ refl) (lte k₂ refl) = lte (k₁ + k₂) (≡-erase ∀⟨ x ∷ k₁ ∷ k₂ ∷ [] ⟩)
n≮n : ∀ {n} → n ≮ n
n≮n {n} (lte k n+1+k≡n) rewrite sym (+-suc n k) = 1+n≢0 (n+m≡n⇒m≡0 n+1+k≡n)
<-irrefl : Irreflexive _≡_ _<_
<-irrefl refl x<x = n≮n x<x
<-asym : Asymmetric _<_
<-asym x<y y<x = n≮n (<-trans x<y y<x)
<⇒≯ : ∀ {n m} → n < m → n ≯ m
<⇒≯ n<m n>m = <-asym n<m n>m
n<1+n : ∀ {n} → n < 1 + n
n<1+n = ≤-refl
0<1+n : ∀ {n} → 0 < 1 + n
0<1+n {n} = lte n refl
n≮0 : ∀ {n} → n ≮ 0
n≮0 ()
suc-mono-< : ∀ {n m} → n < m → suc n < suc m
suc-mono-< (lte k₁ refl) = lte k₁ refl
+-mono-≤ : _+_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
+-mono-≤ {x} {_} {u} (lte k refl) (lte m refl) = lte (k + m) (≡-erase (solveOver (x ∷ u ∷ k ∷ m ∷ []) Nat.ring))
+-mono-< : _+_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
+-mono-< {x} {_} {u} (lte k refl) (lte m refl) = lte (suc (k + m)) (≡-erase (solveOver (x ∷ u ∷ k ∷ m ∷ []) Nat.ring))
private
a+b∸a≡b+[a∸a] : ∀ a b → a + b ∸ a ≡ b + (a ∸ a)
a+b∸a≡b+[a∸a] zero b = sym (+-identityʳ b)
a+b∸a≡b+[a∸a] (suc a) b = a+b∸a≡b+[a∸a] a b
m+[n∸m]≡n : ∀ {m n} → m ≤ n → m + (n ∸ m) ≡ n
m+[n∸m]≡n {m} {n} (lte k refl) = begin
m + (m + k ∸ m) ≡⟨ cong (λ x → m + x) (a+b∸a≡b+[a∸a] m k) ⟩
m + (k + (m ∸ m)) ≡⟨ cong (λ x → m + (k + x)) (n∸n≡0 m) ⟩
m + (k + 0) ≡⟨ cong (λ x → m + x) (+-identityʳ k) ⟩
m + k ∎
where
open ≡-Reasoning
[n∸m]+m≡n : ∀ {m n} → m ≤ n → (n ∸ m) + m ≡ n
[n∸m]+m≡n {m} {n} rewrite +-comm (n ∸ m) m = m+[n∸m]≡n
m<n⇒n∸m≢0 : ∀ {m n} → m < n → n ∸ m ≢ 0
m<n⇒n∸m≢0 {zero} {n} m<n n∸m≡0 = <-irrefl (sym n∸m≡0) m<n
m<n⇒n∸m≢0 {suc m} {suc n} m<n n∸m≡0 = m<n⇒n∸m≢0 (suc-injective-≤ m<n) n∸m≡0
∸-mono-<ˡ : ∀ {x b t} → x ≤ b → b < t → b ∸ x < t ∸ x
∸-mono-<ˡ {x} (lte k₁ refl) (lte k₂ refl) = lte k₂ (≡-erase ≤-proof)
where
open ≡-Reasoning
lemma₁ : ∀ a → 1 + (k₁ + a) + k₂ ≡ 1 + k₁ + k₂ + a
lemma₁ a = ∀⟨ a ∷ k₁ ∷ k₂ ∷ [] ⟩
lemma₂ : x + (1 + k₁ + k₂) ≡ 1 + (x + k₁ + k₂)
lemma₂ = ∀⟨ x ∷ k₁ ∷ k₂ ∷ [] ⟩
≤-proof : suc (x + k₁ ∸ x) + k₂ ≡ suc (x + k₁) + k₂ ∸ x
≤-proof = begin
suc (x + k₁ ∸ x) + k₂ ≡⟨ cong (λ t → suc t + k₂) (a+b∸a≡b+[a∸a] x k₁) ⟩
suc (k₁ + (x ∸ x)) + k₂ ≡⟨ lemma₁ (x ∸ x) ⟩
suc k₁ + k₂ + (x ∸ x) ≡⟨ sym (a+b∸a≡b+[a∸a] x (suc k₁ + k₂)) ⟩
x + (suc k₁ + k₂) ∸ x ≡⟨ cong (λ t → t ∸ x) lemma₂ ⟩
suc (x + k₁) + k₂ ∸ x ∎
∸-mono-<ʳ : ∀ {x b t} → t ≤ x → b < t → x ∸ t < x ∸ b
∸-mono-<ʳ {b = b} (lte k₁ refl) (lte k₂ refl) = lte k₂ (≡-erase ≤-proof)
where
open ≡-Reasoning
LHS : suc (suc b + k₂ + k₁ ∸ (suc b + k₂) + k₂) ≡ suc (k₂ + k₁)
LHS = cong suc $ begin
suc b + k₂ + k₁ ∸ (suc b + k₂) + k₂ ≡⟨ cong (λ t → t + k₂) (sym (∸-+-assoc (b + k₂ + k₁) b k₂)) ⟩
suc b + k₂ + k₁ ∸ suc b ∸ k₂ + k₂ ≡⟨ cong (λ t → t ∸ suc b ∸ k₂ + k₂) (+-assoc (suc b) k₂ k₁) ⟩
suc b + (k₂ + k₁) ∸ suc b ∸ k₂ + k₂ ≡⟨ cong (λ t → t ∸ k₂ + k₂) (a+b∸a≡b+[a∸a] (suc b) (k₂ + k₁)) ⟩
k₂ + k₁ + (suc b ∸ suc b) ∸ k₂ + k₂ ≡⟨ cong (λ t → k₂ + k₁ + t ∸ k₂ + k₂) (n∸n≡0 (suc b)) ⟩
k₂ + k₁ + 0 ∸ k₂ + k₂ ≡⟨ cong (λ t → t ∸ k₂ + k₂) (+-identityʳ (k₂ + k₁)) ⟩
k₂ + k₁ ∸ k₂ + k₂ ≡⟨ cong (λ t → t + k₂) (a+b∸a≡b+[a∸a] k₂ k₁) ⟩
k₁ + (k₂ ∸ k₂) + k₂ ≡⟨ cong (λ t → k₁ + t + k₂) (n∸n≡0 k₂) ⟩
k₁ + 0 + k₂ ≡⟨ cong (λ t → t + k₂) (+-identityʳ k₁) ⟩
k₁ + k₂ ≡⟨ +-comm k₁ k₂ ⟩
k₂ + k₁ ∎
lemma₁ : 1 + (b + k₂ + k₁) ≡ b + (1 + (k₂ + k₁))
lemma₁ = ∀⟨ b ∷ k₂ ∷ k₁ ∷ [] ⟩
RHS : suc (b + k₂ + k₁) ∸ b ≡ suc (k₂ + k₁)
RHS = begin
suc (b + k₂ + k₁) ∸ b ≡⟨ cong (λ t → t ∸ b) lemma₁ ⟩
b + suc (k₂ + k₁) ∸ b ≡⟨ a+b∸a≡b+[a∸a] b (suc (k₂ + k₁)) ⟩
suc (k₂ + k₁) + (b ∸ b) ≡⟨ cong (λ t → suc (k₂ + k₁) + t) (n∸n≡0 b) ⟩
suc (k₂ + k₁) + 0 ≡⟨ +-identityʳ (suc (k₂ + k₁)) ⟩
suc (k₂ + k₁) ∎
≤-proof : suc (suc b + k₂ + k₁ ∸ (suc b + k₂) + k₂) ≡ suc (b + k₂ + k₁) ∸ b
≤-proof = trans LHS (sym RHS)
∸-mono-≤ˡ : ∀ {x b t} → x ≤ b → b ≤ t → b ∸ x ≤ t ∸ x
∸-mono-≤ˡ {x} {b} {t} (lte k₁ refl) (lte k₂ refl) = lte k₂ ≤-proof
where
open ≡-Reasoning
lemma₁ : ∀ a → k₁ + a + k₂ ≡ k₁ + k₂ + a
lemma₁ a = ∀⟨ a ∷ k₁ ∷ k₂ ∷ [] ⟩
≤-proof : x + k₁ ∸ x + k₂ ≡ x + k₁ + k₂ ∸ x
≤-proof = begin
x + k₁ ∸ x + k₂ ≡⟨ cong (λ t → t + k₂) (a+b∸a≡b+[a∸a] x k₁) ⟩
k₁ + (x ∸ x) + k₂ ≡⟨ lemma₁ (x ∸ x) ⟩
k₁ + k₂ + (x ∸ x) ≡⟨ sym (a+b∸a≡b+[a∸a] x (k₁ + k₂)) ⟩
x + (k₁ + k₂) ∸ x ≡⟨ cong (λ t → t ∸ x) (sym (+-assoc x k₁ k₂)) ⟩
x + k₁ + k₂ ∸ x ∎
*-mono-< : _*_ Preserves₂ _<_ ⟶ _<_ ⟶ _<_
*-mono-< {x} {_} {u} (lte k refl) (lte m refl) =
lte (k * m + k * u + k + m * x + m + u + x) (≡-erase ∀⟨ x ∷ u ∷ k ∷ m ∷ [] ⟩)
*-mono-≤ : _*_ Preserves₂ _≤_ ⟶ _≤_ ⟶ _≤_
*-mono-≤ {x} {_} {u} (lte k refl) (lte m refl) = lte (k * m + k * u + m * x) (≡-erase ∀⟨ x ∷ u ∷ k ∷ m ∷ [] ⟩)
+-lower-≤ : ∀ x {n m} → n + x ≤ m → n ≤ m
+-lower-≤ x {n} {m} (lte q refl) = lte (x + q) (sym (+-assoc n x q))
<⇒≤ : ∀ {n m} → n < m → n ≤ m
<⇒≤ {n} (lte k refl) = lte (suc k) (≡-erase (+-suc n k))
module ≤-Reasoning where
open import Relation.Binary.Reasoning.Base.Triple
≤-isPreorder <-trans (resp₂ _<_) <⇒≤ <-≤-trans ≤-<-trans
public
n≤m⇒n<m⊎n≡m : ∀ {n m} → n ≤ m → n < m ⊎ n ≡ m
n≤m⇒n<m⊎n≡m {n} (lte zero ≤-proof) rewrite ≡-erase (+-identityʳ n) = inj₂ ≤-proof
n≤m⇒n<m⊎n≡m {n} (lte (suc k) ≤-proof) rewrite ≡-erase (+-suc n k) = inj₁ (lte k ≤-proof)
≤∧≢⇒< : ∀ {m n} → m ≤ n → m ≢ n → m < n
≤∧≢⇒< m≤n m≢n with n≤m⇒n<m⊎n≡m m≤n
... | inj₁ m<n = m<n
... | inj₂ m≡n = contradiction m≡n m≢n
≮⇒≥ : ∀ {m n} → m ≮ n → m ≥ n
≮⇒≥ {_} {zero} m≮n = 0≤n
≮⇒≥ {zero} {suc n} m≮n = contradiction 0<1+n m≮n
≮⇒≥ {suc m} {suc n} m≮n = suc-mono-≤ (≮⇒≥ (m≮n ∘ suc-mono-<))
<⇒≱ : ∀ {m n} → m < n → m ≱ n
<⇒≱ {m} {n} m<n m≥n with n≤m⇒n<m⊎n≡m m≥n
... | inj₁ m>n = <-asym m<n m>n
... | inj₂ m≡n = <-irrefl (sym m≡n) m<n
<ᵇ⇒< : ∀ m n → T (m <ᵇ n) → m < n
<ᵇ⇒< zero (suc n) m<n = 0<1+n
<ᵇ⇒< (suc m) (suc n) m<n = suc-mono-< (<ᵇ⇒< m n m<n)
<⇒<ᵇ : ∀ m n → m < n → T (m <ᵇ n)
<⇒<ᵇ zero (suc n) m<n = tt
<⇒<ᵇ (suc m) (suc n) m<n = <⇒<ᵇ m n (suc-injective-≤ m<n)
0≢⇒0< : ∀ {n} → 0 ≢ n → 0 < n
0≢⇒0< {zero} 0≢n = contradiction refl 0≢n
0≢⇒0< {suc n} 0≢n = 0<1+n
-- TODO change to does/proof
<-cmp : Trichotomous _≡_ _<_
<-cmp m n with m ≟ n | T? (m <ᵇ n)
... | yes m≡n | _ = tri≈ (<-irrefl m≡n) m≡n (<-irrefl (sym m≡n))
... | no m≢n | yes m<n = tri< (<ᵇ⇒< m n m<n) m≢n (<⇒≯ (<ᵇ⇒< m n m<n))
... | no m≢n | no m≮n = tri> (m≮n ∘ <⇒<ᵇ m n) m≢n (≤∧≢⇒< (≮⇒≥ (m≮n ∘ <⇒<ᵇ m n)) (m≢n ∘ sym))
_<?_ : Decidable _<_
a <? b with <-cmp a b
... | tri< a<b _ _ = yes a<b
... | tri≈ _ refl _ = no λ a<b → n≮n a<b
... | tri> _ _ a>b = no λ a<b → <-asym a>b a<b
<-≤-connex : Connex _<_ _≤_
<-≤-connex m n with <-cmp m n
... | tri< n<m _ _ = inj₁ n<m
... | tri≈ _ refl _ = inj₂ ≤-refl
... | tri> _ _ n>m = inj₂ (<⇒≤ n>m)
<-irrelevant : Irrelevant _<_
<-irrelevant {x} (lte k₁ 1+x+k₁≡y) (lte k₂ 1+x+k₂≡y) with +-cancelˡ-≡ (1 + x) (trans 1+x+k₁≡y (sym 1+x+k₂≡y))
<-irrelevant {x} (lte k₁ refl) (lte .k₁ refl) | refl = refl
≤-total : Total _≤_
≤-total n m with <-cmp n m
... | tri< n<m _ _ = inj₁ (<⇒≤ n<m)
... | tri≈ _ refl _ = inj₁ ≤-refl
... | tri> _ _ n>m = inj₂ (<⇒≤ n>m)
≤-isTotalOrder : IsTotalOrder _≡_ _≤_
≤-isTotalOrder = record
{ isPartialOrder = ≤-isPartialOrder
; total = ≤-total
}
≤-totalOrder : TotalOrder 0ℓ 0ℓ 0ℓ
≤-totalOrder = record { isTotalOrder = ≤-isTotalOrder }
open import Algebra.Construct.NaturalChoice.Max ≤-totalOrder public
+-distribˡ-⊔ : _+_ DistributesOverˡ _⊔_
+-distribˡ-⊔ x y z with ≤-total z y
+-distribˡ-⊔ x y z | inj₁ z≤y with ≤-total (x + z) (x + y)
+-distribˡ-⊔ x y z | inj₁ z≤y | inj₁ x+z≤x+y = refl
+-distribˡ-⊔ x y z | inj₁ z≤y | inj₂ x+y≤x+z = ≤-antisym x+y≤x+z (+-mono-≤ ≤-refl z≤y)
+-distribˡ-⊔ x y z | inj₂ y≤z with ≤-total (x + z) (x + y)
+-distribˡ-⊔ x y z | inj₂ y≤z | inj₁ x+z≤x+y = ≤-antisym x+z≤x+y (+-mono-≤ ≤-refl y≤z)
+-distribˡ-⊔ x y z | inj₂ y≤z | inj₂ x+y≤x+z = refl
⊔-least-≤ : ∀ n m o → n ≤ o → m ≤ o → n ⊔ m ≤ o
⊔-least-≤ n m o n≤o m≤o with ≤-total m n
... | inj₁ _ = n≤o
... | inj₂ _ = m≤o
⊔-least-< : ∀ n m o → n < o → m < o → n ⊔ m < o
⊔-least-< n m o n<o m<o with ≤-total m n
... | inj₁ _ = n<o
... | inj₂ _ = m<o
m≤n⇒m⊔n≡n : ∀ {m n} → m ≤ n → m ⊔ n ≡ n
m≤n⇒m⊔n≡n {m} {n} m≤n with ≤-total n m
... | inj₁ n≤m = ≤-antisym m≤n n≤m
... | inj₂ _ = refl
auto-≤ : ∀ {n m} {{ pf : True (n + (m ∸ n) ≟ m) }} → n ≤ m
auto-≤ {n} {m} with n + (m ∸ n) ≟ m
... | yes pf = lte (m ∸ n) pf
| {
"alphanum_fraction": 0.4911284599,
"avg_line_length": 34.3658536585,
"ext": "agda",
"hexsha": "f02bbd5b21f95b45c4ffddff9ec5a8428e99c40f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mckeankylej/thesis",
"max_forks_repo_path": "proofs/AKS/Nat/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "mckeankylej/thesis",
"max_issues_repo_path": "proofs/AKS/Nat/Properties.agda",
"max_line_length": 207,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "ddad4c0d5f384a0219b2177461a68dae06952dde",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mckeankylej/thesis",
"max_stars_repo_path": "proofs/AKS/Nat/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-12-01T22:38:27.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-12-01T22:38:27.000Z",
"num_tokens": 7105,
"size": 12681
} |
module localInstances where
open import Agda.Builtin.Nat renaming (Nat to ℕ)
open import Agda.Builtin.Bool
open import Common.String
open import Common.List
record Eq (A : Set) : Set where
field eq : A → A → Bool
strlen : String → ℕ
strlen s = length (stringToList s)
if_then_else_ : {A : Set} → Bool → A → A → A
if true then x else y = x
if false then x else y = y
open Eq {{...}}
instance
eqℕ : Eq ℕ
eqℕ = record { eq = λ x x' → x == x' }
eqString₁ : String → String → Bool
eqString₁ s₁ s₂ = strEq s₁ s₂
eqString₂ : String → String → Bool
eqString₂ s₁ s₂ = eq (strlen s₁) (strlen s₂)
testWhere : Bool → Bool
testWhere lengthEq = if eq "abcd" "dcba" then false else true
where
instance
eqLocal : Eq String
eqLocal = record { eq = if lengthEq then eqString₂ else eqString₁ }
testLet : Bool → Bool
testLet lengthEq =
let instance
eqLocal : Eq String
eqLocal = record { eq = if lengthEq then eqString₂ else eqString₁ }
in if eq "abcd" "dcba" then false else true
test1 : Bool
test1 = testWhere true
test2 : Bool
test2 = testLet true
| {
"alphanum_fraction": 0.6727941176,
"avg_line_length": 22.2040816327,
"ext": "agda",
"hexsha": "5e30dffe3d22c976fbfe64a3774035b0d76a95b2",
"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/localInstances.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/localInstances.agda",
"max_line_length": 75,
"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/localInstances.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": 341,
"size": 1088
} |
{-# OPTIONS --without-K --rewriting #-}
open import lib.Base
open import lib.PathGroupoid
module lib.PathFunctor where
{- Nondependent stuff -}
module _ {i j} {A : Type i} {B : Type j} (f : A → B) where
!-ap : {x y : A} (p : x == y)
→ ! (ap f p) == ap f (! p)
!-ap idp = idp
ap-! : {x y : A} (p : x == y)
→ ap f (! p) == ! (ap f p)
ap-! idp = idp
∙-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙ ap f q == ap f (p ∙ q)
∙-ap idp q = idp
ap-∙ : {x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∙ q) == ap f p ∙ ap f q
ap-∙ idp q = idp
∙∙-ap : {x y z w : A} (p : x == y) (q : y == z) (r : z == w)
→ ap f p ∙ ap f q ∙ ap f r == ap f (p ∙ q ∙ r)
∙∙-ap idp idp r = idp
ap-∙∙ : {x y z w : A} (p : x == y) (q : y == z) (r : z == w)
→ ap f (p ∙ q ∙ r) == ap f p ∙ ap f q ∙ ap f r
ap-∙∙ idp idp r = idp
ap-∙∙∙ : {x y z w t : A} (p : x == y) (q : y == z) (r : z == w) (s : w == t)
→ ap f (p ∙ q ∙ r ∙ s) == ap f p ∙ ap f q ∙ ap f r ∙ ap f s
ap-∙∙∙ idp idp idp s = idp
∙'-ap : {x y z : A} (p : x == y) (q : y == z)
→ ap f p ∙' ap f q == ap f (p ∙' q)
∙'-ap p idp = idp
ap-∙' : {x y z : A} (p : x == y) (q : y == z)
→ ap f (p ∙' q) == ap f p ∙' ap f q
ap-∙' p idp = idp
{- Dependent stuff -}
module _ {i j} {A : Type i} {B : A → Type j} (f : Π A B) where
apd-∙ : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙ q) == apd f p ∙ᵈ apd f q
apd-∙ idp idp = idp
apd-∙' : {x y z : A} (p : x == y) (q : y == z)
→ apd f (p ∙' q) == apd f p ∙'ᵈ apd f q
apd-∙' idp idp = idp
apd-! : {x y : A} (p : x == y)
→ apd f (! p) == !ᵈ (apd f p)
apd-! idp = idp
{- Over stuff -}
module _ {i j k} {A : Type i} {B : A → Type j} {C : A → Type k}
(f : {a : A} → B a → C a) where
ap↓-◃ : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : y == z} (q : u == v [ B ↓ p ]) (r : v == w [ B ↓ p' ])
→ ap↓ f (q ◃ r) == ap↓ f q ◃ ap↓ f r
ap↓-◃ {p = idp} {p' = idp} idp idp = idp
ap↓-▹! : {x y z : A} {u : B x} {v : B y} {w : B z}
{p : x == y} {p' : z == y} (q : u == v [ B ↓ p ]) (r : w == v [ B ↓ p' ])
→ ap↓ f (q ▹! r) == ap↓ f q ▹! ap↓ f r
ap↓-▹! {p = idp} {p' = idp} idp idp = idp
{- Fuse and unfuse -}
∘-ap : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) → ap g (ap f p) == ap (g ∘ f) p
∘-ap f g idp = idp
ap-∘ : ∀ {i j k} {A : Type i} {B : Type j} {C : Type k} (g : B → C) (f : A → B)
{x y : A} (p : x == y) → ap (g ∘ f) p == ap g (ap f p)
ap-∘ f g idp = idp
ap-cst : ∀ {i j} {A : Type i} {B : Type j} (b : B) {x y : A} (p : x == y)
→ ap (cst b) p == idp
ap-cst b idp = idp
ap-idf : ∀ {i} {A : Type i} {u v : A} (p : u == v) → ap (idf A) p == p
ap-idf idp = idp
{- Functoriality of [coe] -}
coe-∙ : ∀ {i} {A B C : Type i} (p : A == B) (q : B == C) (a : A)
→ coe (p ∙ q) a == coe q (coe p a)
coe-∙ idp q a = idp
coe-! : ∀ {i} {A B : Type i} (p : A == B) (b : B) → coe (! p) b == coe! p b
coe-! idp b = idp
coe!-inv-r : ∀ {i} {A B : Type i} (p : A == B) (b : B)
→ coe p (coe! p b) == b
coe!-inv-r idp b = idp
coe!-inv-l : ∀ {i} {A B : Type i} (p : A == B) (a : A)
→ coe! p (coe p a) == a
coe!-inv-l idp a = idp
coe-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (a : A) →
ap (coe p) (coe!-inv-l p a) == coe!-inv-r p (coe p a)
coe-inv-adj idp a = idp
coe!-inv-adj : ∀ {i} {A B : Type i} (p : A == B) (b : B) →
ap (coe! p) (coe!-inv-r p b) == coe!-inv-l p (coe! p b)
coe!-inv-adj idp b = idp
coe-ap-! : ∀ {i j} {A : Type i} (P : A → Type j) {a b : A} (p : a == b)
(x : P b)
→ coe (ap P (! p)) x == coe! (ap P p) x
coe-ap-! P idp x = idp
{- Functoriality of transport -}
transp-∙ : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙ q) b == transport B q (transport B p b)
transp-∙ idp _ _ = idp
transp-∙' : ∀ {i j} {A : Type i} {B : A → Type j} {x y z : A}
(p : x == y) (q : y == z) (b : B x)
→ transport B (p ∙' q) b == transport B q (transport B p b)
transp-∙' _ idp _ = idp
{- Naturality of homotopies -}
-- One should use [↓-='-out] and [apd] together, or even lib.cubical,
-- for homotopy naturality.
{- for functions with two arguments -}
module _ {i j k} {A : Type i} {B : Type j} {C : Type k} (f : A → B → C) where
ap2 : {x y : A} {w z : B}
→ (x == y) → (w == z) → f x w == f y z
ap2 idp idp = idp
ap2-out : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 p q == ap (λ u → f u w) p ∙ ap (λ v → f y v) q
ap2-out idp idp = idp
ap2-idp-l : {x : A} {w z : B} (q : w == z)
→ ap2 (idp {a = x}) q == ap (f x) q
ap2-idp-l idp = idp
ap2-idp-r : {x y : A} {w : B} (p : x == y)
→ ap2 p (idp {a = w}) == ap (λ z → f z w) p
ap2-idp-r idp = idp
{- ap2 lemmas -}
module _ {i j} {A : Type i} {B : Type j} where
ap2-fst : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry fst) p q == p
ap2-fst idp idp = idp
ap2-snd : {x y : A} {w z : B} (p : x == y) (q : w == z)
→ ap2 (curry snd) p q == q
ap2-snd idp idp = idp
ap-ap2 : ∀ {k l} {C : Type k} {D : Type l}
(g : C → D) (f : A → B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap g (ap2 f p q) == ap2 (λ a b → g (f a b)) p q
ap-ap2 g f idp idp = idp
ap2-ap-l : ∀ {k l} {C : Type k} {D : Type l}
(g : B → C → D) (f : A → B) {x y : A} {w z : C}
(p : x == y) (q : w == z)
→ ap2 g (ap f p) q == ap2 (λ a c → g (f a) c) p q
ap2-ap-l g f idp idp = idp
ap2-ap-r : ∀ {k l} {C : Type k} {D : Type l}
(g : A → C → D) (f : B → C) {x y : A} {w z : B}
(p : x == y) (q : w == z)
→ ap2 g p (ap f q) == ap2 (λ a b → g a (f b)) p q
ap2-ap-r g f idp idp = idp
ap2-diag : (f : A → A → B)
{x y : A} (p : x == y)
→ ap2 f p p == ap (λ x → f x x) p
ap2-diag f idp = idp
-- unsure where this belongs
transp-cst=idf : ∀ {i} {A : Type i} {a x y : A} (p : x == y) (q : a == x)
→ transport (λ x → a == x) p q == q ∙ p
transp-cst=idf idp q = ! (∙-unit-r q)
{- for functions with more arguments -}
module _ {i₀ i₁ i₂ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂}
{B : Type j} (f : A₀ → A₁ → A₂ → B) where
ap3 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → f x₀ x₁ x₂ == f y₀ y₁ y₂
ap3 idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{B : Type j} (f : A₀ → A₁ → A₂ → A₃ → B) where
ap4 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → f x₀ x₁ x₂ x₃ == f y₀ y₁ y₂ y₃
ap4 idp idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ i₄ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{A₄ : Type i₄} {B : Type j} (f : A₀ → A₁ → A₂ → A₃ → A₄ → B) where
ap5 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃} {x₄ y₄ : A₄}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → (x₄ == y₄)
→ f x₀ x₁ x₂ x₃ x₄ == f y₀ y₁ y₂ y₃ y₄
ap5 idp idp idp idp idp = idp
module _ {i₀ i₁ i₂ i₃ i₄ i₅ j} {A₀ : Type i₀} {A₁ : Type i₁} {A₂ : Type i₂} {A₃ : Type i₃}
{A₄ : Type i₄} {A₅ : Type i₅} {B : Type j} (f : A₀ → A₁ → A₂ → A₃ → A₄ → A₅ → B) where
ap6 : {x₀ y₀ : A₀} {x₁ y₁ : A₁} {x₂ y₂ : A₂} {x₃ y₃ : A₃} {x₄ y₄ : A₄} {x₅ y₅ : A₅}
→ (x₀ == y₀) → (x₁ == y₁) → (x₂ == y₂) → (x₃ == y₃) → (x₄ == y₄) → (x₅ == y₅)
→ f x₀ x₁ x₂ x₃ x₄ x₅ == f y₀ y₁ y₂ y₃ y₄ y₅
ap6 idp idp idp idp idp idp = idp
| {
"alphanum_fraction": 0.4177043855,
"avg_line_length": 32.8355555556,
"ext": "agda",
"hexsha": "706aed2a78bb78c3862f1b323478546f5708b44c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "timjb/HoTT-Agda",
"max_forks_repo_path": "core/lib/PathFunctor.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/PathFunctor.agda",
"max_line_length": 90,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "core/lib/PathFunctor.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3916,
"size": 7388
} |
{-# OPTIONS --rewriting #-}
open import Agda.Builtin.Bool
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
open import Agda.Builtin.Equality.Rewrite
record R : Set where
constructor mkR
field
f : Nat
data Box : Set → Set₁ where
box : (A : Set) → Box A
data D (A : Set) : Set₁ where
c : Box A → R → D A
postulate
r : R
dr : ∀ {A} → D A
rew : ∀ {A} {x} → c {A} (box A) (mkR x) ≡ dr
{-# REWRITE rew #-}
test : c {Bool} (box Bool) r ≡ dr
test = refl
| {
"alphanum_fraction": 0.6036960986,
"avg_line_length": 18.037037037,
"ext": "agda",
"hexsha": "2a7cc5863ea29042821e153da13f3e5ddd97a278",
"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/Issue4755a.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/Issue4755a.agda",
"max_line_length": 46,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/Issue4755a.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": 180,
"size": 487
} |
{-# OPTIONS -v tc.unquote:30 #-}
open import Common.Prelude
open import Common.Reflection
open import Agda.Builtin.Sigma
data Box : Bool → Set where
box : (b : Bool) → Box b
works : (b : Bool) → Box b → Bool
works b (box .b) = unquote (give (var 0 []))
works₂ : (b : Bool) → Box b → Bool
unquoteDef works₂ = defineFun works₂ (clause
( ("b" , arg (argInfo visible relevant) unknown) ∷ [])
( arg (argInfo visible relevant) (var 0)
∷ arg (argInfo visible relevant) (con (quote box)
(arg (argInfo visible relevant) (dot unknown) ∷ []))
∷ [])
(var 0 []) ∷ [])
works₃ : (b : Bool) → Box b → (x y : Bool) → Bool
unquoteDef works₃ = defineFun works₃ (clause
( ("y" , arg (argInfo visible relevant) unknown)
∷ ("x" , arg (argInfo visible relevant) unknown)
∷ ("b" , arg (argInfo visible relevant) unknown)
∷ [])
( arg (argInfo visible relevant) (var 2)
∷ arg (argInfo visible relevant) (con (quote box)
(arg (argInfo visible relevant) (dot unknown) ∷ []))
∷ arg (argInfo visible relevant) (var 1)
∷ arg (argInfo visible relevant) (var 0)
∷ [])
(var 2 []) ∷ [])
| {
"alphanum_fraction": 0.6195652174,
"avg_line_length": 32.4705882353,
"ext": "agda",
"hexsha": "4edf2deeace410c7209de474d29bc0e248b886bc",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue1344.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Succeed/Issue1344.agda",
"max_line_length": 60,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue1344.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 364,
"size": 1104
} |
open import Level
open import Ordinals
module Topology {n : Level } (O : Ordinals {n}) where
open import zf
open import logic
open _∧_
open _∨_
open Bool
import OD
open import Relation.Nullary
open import Data.Empty
open import Relation.Binary.Core
open import Relation.Binary.PropositionalEquality
import BAlgbra
open BAlgbra O
open inOrdinal O
open OD O
open OD.OD
open ODAxiom odAxiom
import OrdUtil
import ODUtil
open Ordinals.Ordinals O
open Ordinals.IsOrdinals isOrdinal
open Ordinals.IsNext isNext
open OrdUtil O
open ODUtil O
import ODC
open ODC O
open import filter
record Toplogy ( L : HOD ) : Set (suc n) where
field
OS : HOD
OS⊆PL : OS ⊆ Power L
o∪ : { P : HOD } → P ⊆ OS → OS ∋ Union P
o∩ : { p q : HOD } → OS ∋ p → OS ∋ q → OS ∋ (p ∩ q)
open Toplogy
record _covers_ ( P q : HOD ) : Set (suc n) where
field
cover : {x : HOD} → q ∋ x → HOD
P∋cover : {x : HOD} → {lt : q ∋ x} → P ∋ cover lt
isCover : {x : HOD} → {lt : q ∋ x} → cover lt ∋ x
-- Base
-- The elements of B cover X ; For any U , V ∈ B and any point x ∈ U ∩ V there is a W ∈ B such that
-- W ⊆ U ∩ V and x ∈ W .
data genTop (P : HOD) : HOD → Set (suc n) where
gi : {x : HOD} → P ∋ x → genTop P x
g∩ : {x y : HOD} → genTop P x → genTop P y → genTop P (x ∩ y)
g∪ : {Q x : HOD} → Q ⊆ P → genTop P (Union Q)
-- Limit point
record LP ( L S x : HOD ) (top : Toplogy L) (S⊆PL : S ⊆ Power L ) ( S∋x : S ∋ x ) : Set (suc n) where
field
neip : {y : HOD} → OS top ∋ y → y ∋ x → HOD
isNeip : {y : HOD} → (o∋y : OS top ∋ y ) → (y∋x : y ∋ x ) → ¬ ( x ≡ neip o∋y y∋x) ∧ ( y ∋ neip o∋y y∋x )
-- Finite Intersection Property
data Finite-∩ (S : HOD) : HOD → Set (suc n) where
fin-∩e : {x : HOD} → S ∋ x → Finite-∩ S x
fin-∩ : {x y : HOD} → Finite-∩ S x → Finite-∩ S y → Finite-∩ S (x ∩ y)
record FIP ( L P : HOD ) : Set (suc n) where
field
fipS⊆PL : P ⊆ Power L
fip≠φ : { x : HOD } → Finite-∩ P x → ¬ ( x ≡ od∅ )
-- Compact
data Finite-∪ (S : HOD) : HOD → Set (suc n) where
fin-∪e : {x : HOD} → S ∋ x → Finite-∪ S x
fin-∪ : {x y : HOD} → Finite-∪ S x → Finite-∪ S y → Finite-∪ S (x ∪ y)
record Compact ( L P : HOD ) : Set (suc n) where
field
finCover : {X y : HOD} → X covers P → P ∋ y → HOD
isFinCover : {X y : HOD} → (xp : X covers P ) → (P∋y : P ∋ y ) → finCover xp P∋y ∋ y
isFininiteCover : {X y : HOD} → (xp : X covers P ) → (P∋y : P ∋ y ) → Finite-∪ X (finCover xp P∋y )
-- FIP is Compact
FIP→Compact : {L P : HOD} → Tolopogy L → FIP L P → Compact L P
FIP→Compact = ?
Compact→FIP : {L P : HOD} → Tolopogy L → Compact L P → FIP L P
Compact→FIP = ?
-- Product Topology
_Top⊗_ : {P Q : HOD} → Topology P → Tolopogy Q → Topology ( P ⊗ Q )
_Top⊗_ = ?
-- existence of Ultra Filter
-- Ultra Filter has limit point
-- FIP is UFL
-- Product of UFL has limit point (Tychonoff)
| {
"alphanum_fraction": 0.5475143727,
"avg_line_length": 26.8818181818,
"ext": "agda",
"hexsha": "d6ac8fa25ba7d5552dd799121fa8a9a9f6252a64",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "shinji-kono/zf-in-agda",
"max_forks_repo_path": "src/Topology.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "shinji-kono/zf-in-agda",
"max_issues_repo_path": "src/Topology.agda",
"max_line_length": 110,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "031f1ea3a3037cd51eb022dbfb5c75b037bf8aa0",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "shinji-kono/zf-in-agda",
"max_stars_repo_path": "src/Topology.agda",
"max_stars_repo_stars_event_max_datetime": "2021-01-10T13:27:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-10-02T13:46:23.000Z",
"num_tokens": 1224,
"size": 2957
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- Lists where all elements satisfy a given property
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Relation.Unary.All where
open import Category.Applicative
open import Category.Monad
open import Data.Empty using (⊥)
open import Data.List.Base as List using (List; []; _∷_)
open import Data.List.Relation.Unary.Any as Any using (Any; here; there)
open import Data.List.Membership.Propositional using (_∈_)
open import Data.Product as Prod
using (∃; -,_; _×_; _,_; proj₁; proj₂; uncurry)
open import Function
open import Level
open import Relation.Nullary hiding (Irrelevant)
import Relation.Nullary.Decidable as Dec
open import Relation.Nullary.Product using (_×-dec_)
open import Relation.Unary hiding (_∈_)
open import Relation.Binary.PropositionalEquality as P
private
variable
a b p q r : Level
A : Set a
B : Set b
------------------------------------------------------------------------
-- Definitions
-- Given a predicate P, then All P xs means that every element in xs
-- satisfies P. See `Relation.Unary` for an explanation of predicates.
infixr 5 _∷_
data All {A : Set a} (P : Pred A p) : Pred (List A) (a ⊔ p) where
[] : All P []
_∷_ : ∀ {x xs} (px : P x) (pxs : All P xs) → All P (x ∷ xs)
-- All P xs is a finite map from indices x ∈ xs to content P x.
-- Relation pxs [ i ]= px states that, in map pxs, key i : x ∈ xs points to value px.
infix 4 _[_]=_
data _[_]=_ {A : Set a} {P : Pred A p} :
∀ {x xs} → All P xs → x ∈ xs → P x → Set (a ⊔ p) where
here : ∀ {x xs} {px : P x} {pxs : All P xs} →
px ∷ pxs [ here refl ]= px
there : ∀ {x xs y} {px : P x} {pxs : All P xs} {py : P y} {i : x ∈ xs} →
pxs [ i ]= px →
py ∷ pxs [ there i ]= px
-- A list is empty if having an element is impossible.
Null : Pred (List A) _
Null = All (λ _ → ⊥)
------------------------------------------------------------------------
-- Operations on All
module _ {P : Pred A p} where
uncons : ∀ {x xs} → All P (x ∷ xs) → P x × All P xs
uncons (px ∷ pxs) = px , pxs
head : ∀ {x xs} → All P (x ∷ xs) → P x
head = proj₁ ∘ uncons
tail : ∀ {x xs} → All P (x ∷ xs) → All P xs
tail = proj₂ ∘ uncons
tabulate : ∀ {xs} → (∀ {x} → x ∈ xs → P x) → All P xs
tabulate {xs = []} hyp = []
tabulate {xs = x ∷ xs} hyp = hyp (here refl) ∷ tabulate (hyp ∘ there)
reduce : (f : ∀ {x} → P x → B) → ∀ {xs} → All P xs → List B
reduce f [] = []
reduce f (px ∷ pxs) = f px ∷ reduce f pxs
construct : (f : B → ∃ P) (xs : List B) → ∃ (All P)
construct f [] = [] , []
construct f (x ∷ xs) = Prod.zip _∷_ _∷_ (f x) (construct f xs)
fromList : (xs : List (∃ P)) → All P (List.map proj₁ xs)
fromList [] = []
fromList ((x , p) ∷ xps) = p ∷ fromList xps
toList : ∀ {xs} → All P xs → List (∃ P)
toList pxs = reduce (λ {x} px → x , px) pxs
module _ {P : Pred A p} {Q : Pred A q} where
map : P ⊆ Q → All P ⊆ All Q
map g [] = []
map g (px ∷ pxs) = g px ∷ map g pxs
module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
zipWith : P ∩ Q ⊆ R → All P ∩ All Q ⊆ All R
zipWith f ([] , []) = []
zipWith f (px ∷ pxs , qx ∷ qxs) = f (px , qx) ∷ zipWith f (pxs , qxs)
unzipWith : R ⊆ P ∩ Q → All R ⊆ All P ∩ All Q
unzipWith f [] = [] , []
unzipWith f (rx ∷ rxs) = Prod.zip _∷_ _∷_ (f rx) (unzipWith f rxs)
module _ {P : Pred A p} {Q : Pred A q} where
zip : All P ∩ All Q ⊆ All (P ∩ Q)
zip = zipWith id
unzip : All (P ∩ Q) ⊆ All P ∩ All Q
unzip = unzipWith id
self : ∀ {xs : List A} → All (const A) xs
self = tabulate (λ {x} _ → x)
------------------------------------------------------------------------
-- (weak) updateAt
module _ {P : Pred A p} where
infixl 6 _[_]%=_ _[_]≔_
updateAt : ∀ {x xs} → x ∈ xs → (P x → P x) → All P xs → All P xs
updateAt () f []
updateAt (here refl) f (px ∷ pxs) = f px ∷ pxs
updateAt (there i) f (px ∷ pxs) = px ∷ updateAt i f pxs
_[_]%=_ : ∀ {x xs} → All P xs → x ∈ xs → (P x → P x) → All P xs
pxs [ i ]%= f = updateAt i f pxs
_[_]≔_ : ∀ {x xs} → All P xs → x ∈ xs → P x → All P xs
pxs [ i ]≔ px = pxs [ i ]%= const px
------------------------------------------------------------------------
-- Traversable-like functions
module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
{F : Set (a ⊔ p) → Set (a ⊔ p)}
(App : RawApplicative F)
where
open RawApplicative App
sequenceA : All (F ∘′ P) ⊆ F ∘′ All P
sequenceA [] = pure []
sequenceA (x ∷ xs) = _∷_ <$> x ⊛ sequenceA xs
mapA : ∀ {Q : Pred A q} → (Q ⊆ F ∘′ P) → All Q ⊆ (F ∘′ All P)
mapA f = sequenceA ∘′ map f
forA : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ F ∘′ P) → F (All P xs)
forA qxs f = mapA f qxs
module _ (p : Level) {A : Set a} {P : Pred A (a ⊔ p)}
{M : Set (a ⊔ p) → Set (a ⊔ p)}
(Mon : RawMonad M)
where
private App = RawMonad.rawIApplicative Mon
sequenceM : All (M ∘′ P) ⊆ M ∘′ All P
sequenceM = sequenceA p App
mapM : ∀ {Q : Pred A q} → (Q ⊆ M ∘′ P) → All Q ⊆ (M ∘′ All P)
mapM = mapA p App
forM : ∀ {Q : Pred A q} {xs} → All Q xs → (Q ⊆ M ∘′ P) → M (All P xs)
forM = forA p App
------------------------------------------------------------------------
-- Generalised lookup based on a proof of Any
module _ {P : Pred A p} {Q : Pred A q} where
lookupAny : ∀ {xs} → All P xs → (i : Any Q xs) → (P ∩ Q) (Any.lookup i)
lookupAny (px ∷ pxs) (here qx) = px , qx
lookupAny (px ∷ pxs) (there i) = lookupAny pxs i
module _ {P : Pred A p} {Q : Pred A q} {R : Pred A r} where
lookupWith : ∀[ P ⇒ Q ⇒ R ] → ∀ {xs} → All P xs → (i : Any Q xs) →
R (Any.lookup i)
lookupWith f pxs i = Prod.uncurry f (lookupAny pxs i)
module _ {P : Pred A p} where
lookup : ∀ {xs} → All P xs → (∀ {x} → x ∈ xs → P x)
lookup pxs = lookupWith (λ { px refl → px }) pxs
------------------------------------------------------------------------
-- Properties of predicates preserved by All
module _ {P : Pred A p} where
all : Decidable P → Decidable (All P)
all p [] = yes []
all p (x ∷ xs) = Dec.map′ (uncurry _∷_) uncons (p x ×-dec all p xs)
universal : Universal P → Universal (All P)
universal u [] = []
universal u (x ∷ xs) = u x ∷ universal u xs
irrelevant : Irrelevant P → Irrelevant (All P)
irrelevant irr [] [] = P.refl
irrelevant irr (px₁ ∷ pxs₁) (px₂ ∷ pxs₂) =
P.cong₂ _∷_ (irr px₁ px₂) (irrelevant irr pxs₁ pxs₂)
satisfiable : Satisfiable (All P)
satisfiable = [] , []
| {
"alphanum_fraction": 0.495687091,
"avg_line_length": 30.703196347,
"ext": "agda",
"hexsha": "36d1f59755b4ed900f3566d67748c0a799c0a4ac",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-04T06:54:45.000Z",
"max_forks_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "DreamLinuxer/popl21-artifact",
"max_forks_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/All.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "DreamLinuxer/popl21-artifact",
"max_issues_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/All.agda",
"max_line_length": 85,
"max_stars_count": 5,
"max_stars_repo_head_hexsha": "fb380f2e67dcb4a94f353dbaec91624fcb5b8933",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "DreamLinuxer/popl21-artifact",
"max_stars_repo_path": "agda-stdlib/src/Data/List/Relation/Unary/All.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": 2359,
"size": 6724
} |
{-# OPTIONS --without-K #-}
{--
Make a version of this file with plain PI and ℕ as a model
Make another version with PI+NEG+FRAC (meadow style) and ℚ as a model
Keep extending; add imaginary numbers and try ℂ as a model
then add square roots and try algebraic numbers as a model
An orthogonal direction is to try other models that are not numbers: in
particular groupoid-based models like we started in F2.agda and F2a.agda
--}
module HP where
-- Pi as a higher-order inductive type
open import Agda.Prim
open import Data.Empty
open import Data.Unit
open import Data.Unit.Core
open import Data.Maybe hiding (map)
open import Data.Nat renaming (_⊔_ to _⊔ℕ_)
open import Data.Integer hiding (_⊔_)
open import Data.Sum renaming (map to _⊎→_)
open import Data.Product renaming (map to _×→_)
open import Data.List
open import Data.Rational hiding (_≃_)
open import Function renaming (_∘_ to _○_)
infixr 8 _∘_ -- path composition
infix 4 _≡_ -- propositional equality
infix 4 _∼_ -- homotopy between two functions
infix 4 _≃_ -- type of equivalences
infix 2 _∎ -- equational reasoning
infixr 2 _≡⟨_⟩_ -- equational reasoning
infix 2 _∎≃ -- equational reasoning for equivalences
infixr 2 _≃⟨_⟩_ -- equational reasoning for equivalences
------------------------------------------------------------------------------
-- Identity types and path induction principles
-- Our own version of refl that makes 'a' explicit
data _≡_ {ℓ} {A : Set ℓ} : (a b : A) → Set ℓ where
refl : (a : A) → (a ≡ a)
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
------------------------------------------------------------------------------
-- Ch. 2
-- Lemma 2.1.1
! : ∀ {u} → {A : Set u} {x y : A} → (x ≡ y) → (y ≡ x)
! = pathInd (λ {x} {y} _ → y ≡ x) refl
-- Lemma 2.1.2
_∘_ : ∀ {u} → {A : Set u} → {x y z : A} → (x ≡ y) → (y ≡ z) → (x ≡ z)
_∘_ {u} {A} {x} {y} {z} p q =
pathInd
(λ {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
-- Lemma 2.1.4
-- 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
-- ! p ∘ p ≡ refl
invTransL : {A : Set} {x y : A} → (p : x ≡ y) → (! p ∘ p ≡ refl y)
invTransL {A} {x} {y} p =
pathInd
(λ {x} {y} p → ! p ∘ p ≡ refl y)
(λ x → refl (refl x))
{x} {y} p
-- p ∘ ! p ≡ refl
invTransR : ∀ {ℓ} {A : Set ℓ} {x y : A} → (p : x ≡ y) → (p ∘ ! p ≡ refl x)
invTransR {ℓ} {A} {x} {y} p =
pathInd
(λ {x} {y} p → p ∘ ! p ≡ refl x)
(λ x → refl (refl x))
{x} {y} p
-- ! (! p) ≡ p
invId : {A : Set} {x y : A} → (p : x ≡ y) → (! (! p) ≡ p)
invId {A} {x} {y} p =
pathInd
(λ {x} {y} p → ! (! p) ≡ p)
(λ x → refl (refl x))
{x} {y} p
-- p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r
assocP : {A : Set} {x y z w : A} → (p : x ≡ y) → (q : y ≡ z) → (r : z ≡ w) →
(p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r)
assocP {A} {x} {y} {z} {w} p q r =
pathInd
(λ {x} {y} p → (z : A) → (w : A) → (q : y ≡ z) → (r : z ≡ w) →
p ∘ (q ∘ r) ≡ (p ∘ q) ∘ r)
(λ x z w q r →
pathInd
(λ {x} {z} q → (w : A) → (r : z ≡ w) →
(refl x) ∘ (q ∘ r) ≡ ((refl x) ∘ q) ∘ r)
(λ x w r →
pathInd
(λ {x} {w} r →
(refl x) ∘ ((refl x) ∘ r) ≡
((refl x) ∘ (refl x)) ∘ r)
(λ x → (refl (refl x)))
{x} {w} r)
{x} {z} q w r)
{x} {y} p z w q r
-- ! (p ∘ q) ≡ ! q ∘ ! p
invComp : {A : Set} {x y z : A} → (p : x ≡ y) → (q : y ≡ z) →
! (p ∘ q) ≡ ! q ∘ ! p
invComp {A} {x} {y} {z} p q =
pathInd
(λ {x} {y} p → (z : A) → (q : y ≡ z) → ! (p ∘ q) ≡ ! q ∘ ! p)
(λ x z q →
pathInd
(λ {x} {z} q → ! (refl x ∘ q) ≡ ! q ∘ ! (refl x))
(λ x → refl (refl x))
{x} {z} q)
{x} {y} p z q
-- Introduce equational reasoning syntax to simplify proofs
_≡⟨_⟩_ : ∀ {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
------------------------------------------------------------------------------
-- Functions are functors
-- Lemma 2.2.1
-- computation rule: ap f (refl x) = refl (f x)
ap : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {x y : A} →
(f : A → B) → (x ≡ y) → (f x ≡ f y)
ap f p =
pathInd
(λ {x} {y} _ → f x ≡ f y)
(λ x → refl (f x))
p
ap₂ : ∀ {ℓ ℓ' ℓ''} → {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₂)
ap₂ {ℓ} {ℓ'} {ℓ''} {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₁
-- Lemma 2.2.2
-- f (p ∘ q) ≡ f p ∘ f q
apfTrans : ∀ {u} → {A B : Set u} {x y z : A} →
(f : A → B) → (p : x ≡ y) → (q : y ≡ z) → ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q)
apfTrans {u} {A} {B} {x} {y} {z} f p q =
pathInd {u}
(λ {x} {y} p → (z : A) → (q : y ≡ z) →
ap f (p ∘ q) ≡ (ap f p) ∘ (ap f q))
(λ x z q →
pathInd {u}
(λ {x} {z} q →
ap f (refl x ∘ q) ≡ (ap f (refl x)) ∘ (ap f q))
(λ x → refl (refl (f x)))
{x} {z} q)
{x} {y} p z q
-- f (! p) ≡ ! (f p)
apfInv : ∀ {u} → {A B : Set u} {x y : A} → (f : A → B) → (p : x ≡ y) →
ap f (! p) ≡ ! (ap f p)
apfInv f p =
pathInd
(λ p → ap f (! p) ≡ ! (ap f p))
(λ x → refl (ap f (refl x)))
p
-- g (f p) ≡ (g ○ f) p
apfComp : {A B C : Set} {x y : A} → (f : A → B) → (g : B → C) → (p : x ≡ y) →
ap g (ap f p) ≡ ap (g ○ f) p
apfComp {A} {B} {C} {x} {y} f g p =
pathInd
(λ {x} {y} p → ap g (ap f p) ≡ ap (g ○ f) p)
(λ x → refl (ap g (ap f (refl x))))
{x} {y} p
-- id p ≡ p
apfId : {A : Set} {x y : A} → (p : x ≡ y) → ap id p ≡ p
apfId {A} {x} {y} p =
pathInd
(λ {x} {y} p → ap id p ≡ p)
(λ x → refl (refl x))
{x} {y} p
-- Transport
-- Lemma 2.3.1
transport : ∀ {ℓ ℓ'} → {A : Set ℓ} {x y : A} →
(P : A → Set ℓ') → (p : x ≡ y) → P x → P y
transport {x = x} {y} P p =
pathInd
(λ {x'} {y'} _ → (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
-- Thm 2.11.3
transportId : {A B : Set} {y z : A} → (f g : A → B) →
(p : y ≡ z) → (q : f y ≡ g y) →
transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ q ∘ (ap g p)
transportId {A} {B} {y} {z} f g p q =
pathInd
(λ {y} {z} p → (q : f y ≡ g y) →
transport (λ x → f x ≡ g x) p q ≡ ! (ap f p) ∘ q ∘ (ap g p))
(λ y q → q
≡⟨ unitTransR q ⟩
q ∘ refl (g y)
≡⟨ unitTransL (q ∘ refl (g y)) ⟩
refl (f y) ∘ q ∘ refl (g y) ∎)
{y} {z} p q
-------------------------------------------------------------------------------
-- Homotopies and equivalences
_∼_ : ∀ {ℓ ℓ'} → {A : Set ℓ} {P : A → Set ℓ'} →
(f g : (x : A) → P x) → Set (_⊔_ ℓ ℓ')
_∼_ {ℓ} {ℓ'} {A} {P} f g = (x : A) → f x ≡ g x
-- Quasi-inverses
record qinv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (_⊔_ ℓ ℓ') where
constructor mkqinv
field
g : B → A
α : (f ○ g) ∼ id
β : (g ○ f) ∼ id
-- Example 2.4.7
idqinv : ∀ {ℓ} → {A : Set ℓ} → qinv {ℓ} {ℓ} {A} {A} id
idqinv = record {
g = id ;
α = λ b → refl b ;
β = λ a → refl a
}
-- Equivalences
record isequiv {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} (f : A → B) :
Set (_⊔_ ℓ ℓ') where
constructor mkisequiv
field
g : B → A
α : (f ○ g) ∼ id
h : B → A
β : (h ○ f) ∼ id
equiv₁ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → qinv f → isequiv f
equiv₁ (mkqinv qg qα qβ) = mkisequiv qg qα qg qβ
equiv₂ : ∀ {ℓ ℓ'} → {A : Set ℓ} {B : Set ℓ'} {f : A → B} → isequiv f → qinv f
equiv₂ {f = f} (mkisequiv ig iα ih iβ) =
record {
g = ig ;
α = iα ;
β = λ x → ig (f x)
≡⟨ ! (iβ (ig (f x))) ⟩
ih (f (ig (f x)))
≡⟨ ap ih (iα (f x)) ⟩
ih (f x)
≡⟨ iβ x ⟩
x ∎
}
_≃_ : ∀ {ℓ ℓ'} (A : Set ℓ) (B : Set ℓ') → Set (_⊔_ ℓ ℓ')
A ≃ B = Σ (A → B) isequiv
id≃ : ∀ {ℓ} {A : Set ℓ} → A ≃ A
id≃ = (id , equiv₁ idqinv)
sym≃ : ∀ {ℓ ℓ'} {A : Set ℓ} {B : Set ℓ'} → (A ≃ B) → B ≃ A
sym≃ (A→B , equiv) with equiv₂ equiv
... | mkqinv g α β = g , equiv₁ (mkqinv A→B β α)
trans≃ : {A B C : Set} → A ≃ B → B ≃ C → A ≃ C
trans≃ (f , feq) (g , geq) with equiv₂ feq | equiv₂ geq
... | mkqinv ff fα fβ | mkqinv gg gα gβ =
(g ○ f , equiv₁ (mkqinv
(ff ○ gg)
(λ c → g (f (ff (gg c)))
≡⟨ ap g (fα (gg c)) ⟩
g (gg c)
≡⟨ gα c ⟩
c ∎)
(λ a → ff (gg (g (f a)))
≡⟨ ap ff (gβ (f a)) ⟩
ff (f a)
≡⟨ fβ a ⟩
a ∎)))
-- identities are equivalences
idtoeqv : {A B : Set} → (A ≡ B) → (A ≃ B)
idtoeqv {A} {B} p =
pathInd
(λ {A'} {B'} _ → A' ≃ B')
(λ _ → id≃)
{A} {B} p
-- equivalences are injective
_⋆_ : {A B : Set} → (A ≃ B) → (x : A) → B
(f , _) ⋆ x = f x
inj≃ : {A B : Set} → (eq : A ≃ B) → (x y : A) → (eq ⋆ x ≡ eq ⋆ y → x ≡ y)
inj≃ (f , mkisequiv g α h β) x y p = ! (β x) ∘ (ap h p ∘ β y)
-- equivalences 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) ()
codeqinv : {A B : Set} {a₀ : A} {x : A ⊎ B} → qinv (encode a₀ x)
codeqinv {A} {B} {a₀} {x} = record {
g = decode a₀ x ;
α = indCP
(λ x → (c : code a₀ x) → encode a₀ x (decode a₀ x c) ≡ c)
(λ a c → encode a₀ (inj₁ a) (decode a₀ (inj₁ a) c)
≡⟨ bydef ⟩
encode a₀ (inj₁ a) (ap inj₁ c)
≡⟨ bydef ⟩
transport (code a₀) (ap inj₁ c) (refl a₀)
≡⟨ ! (transport-f inj₁ (code a₀) c (refl a₀)) ⟩
transport (λ a → code {A} {B} a₀ (inj₁ a)) c (refl a₀)
≡⟨ bydef ⟩
transport (λ a → a₀ ≡ a) c (refl a₀)
≡⟨ transportIdR c (refl a₀) ⟩
(refl a₀) ∘ c
≡⟨ ! (unitTransL c) ⟩
c ∎)
(λ b ())
x ;
β = λ p → basedPathInd
(inj₁ a₀)
(λ x p → decode a₀ x (encode a₀ x p) ≡ p)
(decode a₀ (inj₁ a₀)
(encode {A} {B} a₀ (inj₁ a₀) (refl (inj₁ a₀)))
≡⟨ bydef ⟩
(decode a₀ (inj₁ a₀)
(transport (code {A} {B} a₀) (refl (inj₁ a₀)) (refl a₀)))
≡⟨ bydef ⟩
(decode a₀ (inj₁ a₀) (refl a₀))
≡⟨ bydef ⟩
(ap inj₁ (refl a₀))
≡⟨ bydef ⟩
refl (inj₁ a₀) ∎)
x p }
thm2-12-5 : {A B : Set} → (a₀ : A) → (x : A ⊎ B) → (inj₁ a₀ ≡ x) ≃ code a₀ x
thm2-12-5 {A} {B} a₀ x = (encode a₀ x , equiv₁ codeqinv)
inj₁₁path : {A B : Set} → (a₁ a₂ : A) →
(inj₁ {A = A} {B = B} a₁ ≡ inj₁ a₂) ≃ (a₁ ≡ a₂)
inj₁₁path a₁ a₂ = thm2-12-5 a₁ (inj₁ a₂)
inj₁₂path : {A B : Set} → (a : A) (b : B) → (inj₁ a ≡ inj₂ b) ≃ ⊥
inj₁₂path a b = thm2-12-5 a (inj₂ b)
-- Abbreviations for equivalence compositions
_≃⟨_⟩_ : (A : Set) {B C : Set} → (A ≃ B) → (B ≃ C) → (A ≃ C)
_ ≃⟨ p ⟩ q = trans≃ p q
_∎≃ : {ℓ : Level} {A : Set ℓ} → A ≃ A
_∎≃ {ℓ} {A} = id≃ {ℓ} {A}
------------------------------------------------------------------------------
-- Type equivalences
-- unite₊ and uniti₊
unite₊ : {A : Set} → ⊥ ⊎ A → A
unite₊ (inj₁ ())
unite₊ (inj₂ y) = y
uniti₊ : {A : Set} → A → ⊥ ⊎ A
uniti₊ a = inj₂ a
uniti₊∘unite₊ : {A : Set} → uniti₊ ○ unite₊ ∼ id {A = ⊥ ⊎ A}
uniti₊∘unite₊ (inj₁ ())
uniti₊∘unite₊ (inj₂ y) = refl (inj₂ y)
unite₊∙uniti₊ : {A : Set} → unite₊ ○ uniti₊ ∼ id {A = A}
unite₊∙uniti₊ = refl
unite₊≃ : {A : Set} → (⊥ ⊎ A) ≃ A
unite₊≃ = (unite₊ , mkisequiv uniti₊ refl uniti₊ uniti₊∘unite₊)
uniti₊≃ : {A : Set} → A ≃ (⊥ ⊎ A)
uniti₊≃ = uniti₊ , mkisequiv unite₊ uniti₊∘unite₊ unite₊ unite₊∙uniti₊
-- swap₊
swap₊ : {A B : Set} → A ⊎ B → B ⊎ A
swap₊ (inj₁ a) = inj₂ a
swap₊ (inj₂ b) = inj₁ b
swapswap₊ : {A B : Set} → swap₊ ○ swap₊ {A} {B} ∼ id
swapswap₊ (inj₁ a) = refl (inj₁ a)
swapswap₊ (inj₂ b) = refl (inj₂ b)
swap₊≃ : {A B : Set} → (A ⊎ B) ≃ (B ⊎ A)
swap₊≃ = (swap₊ , equiv₁ (mkqinv swap₊ swapswap₊ swapswap₊))
-- assocl₊ and assocr₊
assocl₊ : {A B C : Set} → (A ⊎ (B ⊎ C)) → ((A ⊎ B) ⊎ C)
assocl₊ (inj₁ a) = inj₁ (inj₁ a)
assocl₊ (inj₂ (inj₁ b)) = inj₁ (inj₂ b)
assocl₊ (inj₂ (inj₂ c)) = inj₂ c
assocr₊ : {A B C : Set} → ((A ⊎ B) ⊎ C) → (A ⊎ (B ⊎ C))
assocr₊ (inj₁ (inj₁ a)) = inj₁ a
assocr₊ (inj₁ (inj₂ b)) = inj₂ (inj₁ b)
assocr₊ (inj₂ c) = inj₂ (inj₂ c)
assocl₊∘assocr₊ : {A B C : Set} → assocl₊ ○ assocr₊ ∼ id {A = ((A ⊎ B) ⊎ C)}
assocl₊∘assocr₊ (inj₁ (inj₁ a)) = refl (inj₁ (inj₁ a))
assocl₊∘assocr₊ (inj₁ (inj₂ b)) = refl (inj₁ (inj₂ b))
assocl₊∘assocr₊ (inj₂ c) = refl (inj₂ c)
assocr₊∘assocl₊ : {A B C : Set} → assocr₊ ○ assocl₊ ∼ id {A = (A ⊎ (B ⊎ C))}
assocr₊∘assocl₊ (inj₁ a) = refl (inj₁ a)
assocr₊∘assocl₊ (inj₂ (inj₁ b)) = refl (inj₂ (inj₁ b))
assocr₊∘assocl₊ (inj₂ (inj₂ c)) = refl (inj₂ (inj₂ c))
assocl₊≃ : {A B C : Set} → (A ⊎ (B ⊎ C)) ≃ ((A ⊎ B) ⊎ C)
assocl₊≃ =
assocl₊ , mkisequiv assocr₊ assocl₊∘assocr₊ assocr₊ assocr₊∘assocl₊
assocr₊≃ : {A B C : Set} → ((A ⊎ B) ⊎ C) ≃ (A ⊎ (B ⊎ C))
assocr₊≃ =
assocr₊ , mkisequiv assocl₊ assocr₊∘assocl₊ assocl₊ assocl₊∘assocr₊
-- unite⋆ and uniti⋆
unite⋆ : {A : Set} → ⊤ × A → A
unite⋆ (tt , x) = x
uniti⋆ : {A : Set} → A → ⊤ × A
uniti⋆ x = tt , x
uniti⋆∘unite⋆ : {A : Set} → uniti⋆ ○ unite⋆ ∼ id {A = ⊤ × A}
uniti⋆∘unite⋆ (tt , x) = refl (tt , x)
unite⋆≃ : {A : Set} → (⊤ × A) ≃ A
unite⋆≃ = unite⋆ , mkisequiv uniti⋆ refl uniti⋆ uniti⋆∘unite⋆
uniti⋆≃ : {A : Set} → A ≃ (⊤ × A)
uniti⋆≃ = uniti⋆ , mkisequiv unite⋆ uniti⋆∘unite⋆ unite⋆ refl
-- swap⋆
swap⋆ : {A B : Set} → A × B → B × A
swap⋆ (a , b) = (b , a)
swapswap⋆ : {A B : Set} → swap⋆ ○ swap⋆ ∼ id {A = A × B}
swapswap⋆ (a , b) = refl (a , b)
swap⋆≃ : {A B : Set} → (A × B) ≃ (B × A)
swap⋆≃ = swap⋆ , mkisequiv swap⋆ swapswap⋆ swap⋆ swapswap⋆
-- assocl⋆ and assocr⋆
assocl⋆ : {A B C : Set} → (A × (B × C)) → ((A × B) × C)
assocl⋆ (a , (b , c)) = ((a , b) , c)
assocr⋆ : {A B C : Set} → ((A × B) × C) → (A × (B × C))
assocr⋆ ((a , b) , c) = (a , (b , c))
assocl⋆∘assocr⋆ : {A B C : Set} → assocl⋆ ○ assocr⋆ ∼ id {A = ((A × B) × C)}
assocl⋆∘assocr⋆ x = refl x
assocr⋆∘assocl⋆ : {A B C : Set} → assocr⋆ ○ assocl⋆ ∼ id {A = (A × (B × C))}
assocr⋆∘assocl⋆ x = refl x
assocl⋆≃ : {A B C : Set} → (A × (B × C)) ≃ ((A × B) × C)
assocl⋆≃ =
assocl⋆ , mkisequiv assocr⋆ assocl⋆∘assocr⋆ assocr⋆ assocr⋆∘assocl⋆
assocr⋆≃ : {A B C : Set} → ((A × B) × C) ≃ (A × (B × C))
assocr⋆≃ =
assocr⋆ , mkisequiv assocl⋆ assocr⋆∘assocl⋆ assocl⋆ assocl⋆∘assocr⋆
-- distz and factorz
distz : { A : Set} → (⊥ × A) → ⊥
distz (() , _)
factorz : {A : Set} → ⊥ → (⊥ × A)
factorz ()
distz∘factorz : {A : Set} → distz ○ factorz {A} ∼ id
distz∘factorz ()
factorz∘distz : {A : Set} → factorz {A} ○ distz ∼ id
factorz∘distz (() , proj₂)
distz≃ : {A : Set} → (⊥ × A) ≃ ⊥
distz≃ {A} =
distz , mkisequiv factorz (distz∘factorz {A}) factorz factorz∘distz
factorz≃ : {A : Set} → ⊥ ≃ (⊥ × A)
factorz≃ {A} =
factorz , mkisequiv distz factorz∘distz distz (distz∘factorz {A})
-- dist and factor
dist : {A B C : Set} → ((A ⊎ B) × C) → (A × C) ⊎ (B × C)
dist (inj₁ x , c) = inj₁ (x , c)
dist (inj₂ y , c) = inj₂ (y , c)
factor : {A B C : Set} → (A × C) ⊎ (B × C) → ((A ⊎ B) × C)
factor (inj₁ (a , c)) = inj₁ a , c
factor (inj₂ (b , c)) = inj₂ b , c
dist∘factor : {A B C : Set} → dist {A} {B} {C} ○ factor ∼ id
dist∘factor (inj₁ x) = refl (inj₁ x)
dist∘factor (inj₂ y) = refl (inj₂ y)
factor∘dist : {A B C : Set} → factor {A} {B} {C} ○ dist ∼ id
factor∘dist (inj₁ x , c) = refl (inj₁ x , c)
factor∘dist (inj₂ y , c) = refl (inj₂ y , c)
dist≃ : {A B C : Set} → ((A ⊎ B) × C) ≃ ((A × C) ⊎ (B × C))
dist≃ = dist , mkisequiv factor dist∘factor factor factor∘dist
factor≃ : {A B C : Set} → ((A × C) ⊎ (B × C)) ≃ ((A ⊎ B) × C)
factor≃ = factor , (mkisequiv dist factor∘dist dist dist∘factor)
-- congruence
-- ⊕
_⊎∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} →
(α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) →
(f ⊎→ g) ○ (finv ⊎→ ginv) ∼ id {A = C ⊎ D}
_⊎∼_ α β (inj₁ x) = ap inj₁ (α x)
_⊎∼_ α β (inj₂ y) = ap inj₂ (β y)
path⊎ : {A B C D : Set} → A ≃ C → B ≃ D → (A ⊎ B) ≃ (C ⊎ D)
path⊎ (fp , eqp) (fq , eqq) =
Data.Sum.map fp fq ,
mkisequiv (P.g ⊎→ Q.g) (P.α ⊎∼ Q.α) (P.h ⊎→ Q.h) (P.β ⊎∼ Q.β)
where module P = isequiv eqp
module Q = isequiv eqq
-- ⊗
_×∼_ : {A B C D : Set} {f : A → C} {finv : C → A} {g : B → D} {ginv : D → B} →
(α : f ○ finv ∼ id) → (β : g ○ ginv ∼ id) →
(f ×→ g) ○ (finv ×→ ginv) ∼ id {A = C × D}
_×∼_ α β (x , y) = ap₂ _,_ (α x) (β y)
path× : {A B C D : Set} → A ≃ C → B ≃ D → (A × B) ≃ (C × D)
path× {A} {B} {C} {D} (fp , eqp) (fq , eqq) =
Data.Product.map fp fq ,
mkisequiv
(P.g ×→ Q.g)
(_×∼_ {A} {B} {C} {D} {fp} {P.g} {fq} {Q.g} P.α Q.α)
(P.h ×→ Q.h)
(_×∼_ {C} {D} {A} {B} {P.h} {fp} {Q.h} {fq} P.β Q.β)
where module P = isequiv eqp
module Q = isequiv eqq
------------------------------------------------------------------------------
-- Pi as a higher-order inductive type
module PI where
-- hidden
private
data FT* : Set where
ZERO* : FT*
ONE* : FT*
PLUS* : FT* → FT* → FT*
TIMES* : FT* → FT* → FT*
NEG* : FT* → FT*
RECIP* : FT* → FT*
-- exported
FT : Set
FT = FT*
ZERO : FT
ZERO = ZERO*
ONE : FT
ONE = ONE*
PLUS : FT → FT → FT
PLUS = PLUS*
TIMES : FT → FT → FT
TIMES = TIMES*
NEG : FT → FT
NEG = NEG*
RECIP : FT → FT
RECIP = RECIP*
postulate
-- additive structure
unite₊≡ : { b : FT } → PLUS ZERO b ≡ b
uniti₊≡ : { b : FT } → b ≡ PLUS ZERO b
swap₊≡ : { b₁ b₂ : FT } → PLUS b₁ b₂ ≡ PLUS b₂ b₁
assocl₊≡ : { b₁ b₂ b₃ : FT } → PLUS b₁ (PLUS b₂ b₃) ≡ PLUS (PLUS b₁ b₂) b₃
assocr₊≡ : { b₁ b₂ b₃ : FT } → PLUS (PLUS b₁ b₂) b₃ ≡ PLUS b₁ (PLUS b₂ b₃)
-- multiplicative structure
unite⋆≡ : { b : FT } → TIMES ONE b ≡ b
uniti⋆≡ : { b : FT } → b ≡ TIMES ONE b
swap⋆≡ : { b₁ b₂ : FT } → TIMES b₁ b₂ ≡ TIMES b₂ b₁
assocl⋆≡ : { b₁ b₂ b₃ : FT } →
TIMES b₁ (TIMES b₂ b₃) ≡ TIMES (TIMES b₁ b₂) b₃
assocr⋆≡ : { b₁ b₂ b₃ : FT } →
TIMES (TIMES b₁ b₂) b₃ ≡ TIMES b₁ (TIMES b₂ b₃)
-- distributivity
distz≡ : { b : FT } → TIMES ZERO b ≡ ZERO
factorz≡ : { b : FT } → ZERO ≡ TIMES ZERO b
dist≡ : { b₁ b₂ b₃ : FT } →
TIMES (PLUS b₁ b₂) b₃ ≡ PLUS (TIMES b₁ b₃) (TIMES b₂ b₃)
factor≡ : { b₁ b₂ b₃ : FT } →
PLUS (TIMES b₁ b₃) (TIMES b₂ b₃) ≡ TIMES (PLUS b₁ b₂) b₃
-- negatives and fractionals
η₊ : { b : FT } → ZERO ≡ PLUS (NEG b) b
ε₊ : { b : FT } → PLUS (NEG b) b ≡ ZERO
refe⋆ : { b : FT } → RECIP (RECIP b) ≡ b
refi⋆ : { b : FT } → b ≡ RECIP (RECIP b)
rile⋆ : { b : FT } → TIMES b (TIMES b (RECIP b)) ≡ b
rili⋆ : { b : FT } → b ≡ TIMES b (TIMES b (RECIP b))
-- no need to postulate congruence; it will be provable
-- Any function mapping PI to a type C must produce one of the following
-- records that shows how both points and paths are mapped
record PIR {ℓ : Level} (C : Set ℓ) : Set (lsuc ℓ) where
field
czero : C
cone : C
cplus : C → C → C
ctimes : C → C → C
cneg : C → C
crecip : C → C
cunite₊≡ : { c : C } → cplus czero c ≡ c
cuniti₊≡ : { c : C } → c ≡ cplus czero c
cswap₊≡ : { c₁ c₂ : C } → cplus c₁ c₂ ≡ cplus c₂ c₁
cassocl₊≡ : { c₁ c₂ c₃ : C } →
cplus c₁ (cplus c₂ c₃) ≡ cplus (cplus c₁ c₂) c₃
cassocr₊≡ : { c₁ c₂ c₃ : C } →
cplus (cplus c₁ c₂) c₃ ≡ cplus c₁ (cplus c₂ c₃)
cunite⋆≡ : { c : C } → ctimes cone c ≡ c
cuniti⋆≡ : { c : C } → c ≡ ctimes cone c
cswap⋆≡ : { c₁ c₂ : C } → ctimes c₁ c₂ ≡ ctimes c₂ c₁
cassocl⋆≡ : { c₁ c₂ c₃ : C } →
ctimes c₁ (ctimes c₂ c₃) ≡ ctimes (ctimes c₁ c₂) c₃
cassocr⋆≡ : { c₁ c₂ c₃ : C } →
ctimes (ctimes c₁ c₂) c₃ ≡ ctimes c₁ (ctimes c₂ c₃)
cdistz≡ : { c : C } → ctimes czero c ≡ czero
cfactorz≡ : { c : C } → czero ≡ ctimes czero c
cdist≡ : { c₁ c₂ c₃ : C } →
ctimes (cplus c₁ c₂) c₃ ≡ cplus (ctimes c₁ c₃) (ctimes c₂ c₃)
cfactor≡ : { c₁ c₂ c₃ : C } →
cplus (ctimes c₁ c₃) (ctimes c₂ c₃) ≡ ctimes (cplus c₁ c₂) c₃
cη₊ : { c : C } → czero ≡ cplus (cneg c) c
cε₊ : { c : C } → cplus (cneg c) c ≡ czero
crefe⋆ : { c : C } → crecip (crecip c) ≡ c
crefi⋆ : { c : C } → c ≡ crecip (crecip c)
crile⋆ : { c : C } → ctimes c (ctimes c (crecip c)) ≡ c
crili⋆ : { c : C } → c ≡ ctimes c (ctimes c (crecip c))
open PIR
-- recursion principle for PI: given a target type C and a target record as
-- above that has appropriate points and paths, recPI shows how points are
-- mapped to points; the postulates assert that paths are transported as
-- expected
recPI : {ℓ : Level} {C : Set ℓ} → (PIR C) → FT → C
recPI pir ZERO* = czero pir
recPI pir ONE* = cone pir
recPI pir (PLUS* B₁ B₂) = cplus pir (recPI pir B₁) (recPI pir B₂)
recPI pir (TIMES* B₁ B₂) = ctimes pir (recPI pir B₁) (recPI pir B₂)
recPI pir (NEG* B) = cneg pir (recPI pir B)
recPI pir (RECIP* B) = crecip pir (recPI pir B)
postulate
βreccunite₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (unite₊≡ {b}) ≡ cunite₊≡ pir
βreccuniti₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (uniti₊≡ {b}) ≡ cuniti₊≡ pir
βreccswap₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ : FT} → ap (recPI pir) (swap₊≡ {b₁} {b₂}) ≡ cswap₊≡ pir
βreccassocl₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocl₊≡ {b₁} {b₂} {b₃}) ≡
cassocl₊≡ pir
βreccassocr₊≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocr₊≡ {b₁} {b₂} {b₃}) ≡
cassocr₊≡ pir
βreccunite⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (unite⋆≡ {b}) ≡ cunite⋆≡ pir
βreccuniti⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (uniti⋆≡ {b}) ≡ cuniti⋆≡ pir
βreccswap⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ : FT} → ap (recPI pir) (swap⋆≡ {b₁} {b₂}) ≡ cswap⋆≡ pir
βreccassocl⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocl⋆≡ {b₁} {b₂} {b₃}) ≡
cassocl⋆≡ pir
βreccassocr⋆≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (assocr⋆≡ {b₁} {b₂} {b₃}) ≡
cassocr⋆≡ pir
βreccdistz≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (distz≡ {b}) ≡ cdistz≡ pir
βreccfactorz≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b : FT} → ap (recPI pir) (factorz≡ {b}) ≡ cfactorz≡ pir
βreccdist≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (dist≡ {b₁} {b₂} {b₃}) ≡
cdist≡ pir
βreccfactor≡ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{b₁ b₂ b₃ : FT} → ap (recPI pir) (factor≡ {b₁} {b₂} {b₃}) ≡
cfactor≡ pir
βreccη₊ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (η₊ {b}) ≡ cη₊ pir
βreccε₊ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (ε₊ {b}) ≡ cε₊ pir
βreccrefe⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (refe⋆ {b}) ≡ crefe⋆ pir
βreccrefi⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (refi⋆ {b}) ≡ crefi⋆ pir
βreccrile⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (rile⋆ {b}) ≡ crile⋆ pir
βreccrili⋆ : {ℓ : Level} {C : Set ℓ} → (pir : PIR C) →
{ b : FT } → ap (recPI pir) (rili⋆ {b}) ≡ crili⋆ pir
open PI public
------------------------------------------------------------------------------
-- Semantics I
-- The rationals are a model of PI
{--
unitPlus : (n : ℕ) -> (n + 0) ≡ n
unitPlus 0 = refl 0
unitPlus (suc m) = ap suc (unitPlus m)
sPlus : (n m : ℕ) -> suc (n + m) ≡ (n + suc m)
sPlus 0 m = refl (suc m)
sPlus (suc n) m = ap suc (sPlus n m)
commPlus : (m n : ℕ) -> (m + n) ≡ (n + m)
commPlus 0 n = ! (unitPlus n)
commPlus (suc m) n = (ap suc (commPlus m n)) ∘ (sPlus n m)
assocPlus : (m n o : ℕ) ->((m + n) + o) ≡ (m + (n + o))
assocPlus 0 n o = refl (n + o)
assocPlus (suc m) n o = ap suc (assocPlus m n o)
--
unitMult : (i : ℕ) → 1 * i ≡ i
unitMult 0 = refl 0
unitMult (suc i) = ap suc (unitMult i)
mulSuc : (m n : ℕ) → m * suc n ≡ m + m * n
mulSuc 0 n = refl 0
mulSuc (suc m) n = ap (λ x → suc n + x) (mulSuc m n) ∘
ap suc (! (assocPlus n m (m * n))) ∘
ap (λ x → suc (x + m * n)) (commPlus n m) ∘
ap suc (assocPlus m n (m * n))
annMult : (i : ℕ) → i * 0 ≡ 0
annMult 0 = refl 0
annMult (suc i) = annMult i
commMult : (i j : ℕ) → i * j ≡ j * i
commMult 0 j = ! (annMult j)
commMult (suc i) j = ap (λ x → j + x) (commMult i j) ∘
(! (mulSuc j i))
distrib : (i j k : ℕ) → (j + k) * i ≡ j * i + k * i
distrib i 0 k = refl (k * i)
distrib i (suc j) k = ap (_+_ i) (distrib i j k) ∘
(! (assocPlus i (j * i) (k * i)))
assocMult : (i j k : ℕ) → (i * j) * k ≡ i * (j * k)
assocMult 0 j k = refl 0
assocMult (suc i) j k = distrib k j (i * j) ∘
ap (λ x → j * k + x) (assocMult i j k)
--}
--
toℚ : FT → ℚ
toℚ b = recPI (record {
czero = + 0 ÷ 1 ;
cone = + 1 ÷ 1 ;
cplus = {!!} ; --_+_ ;
ctimes = {!!} ; --_*_ ;
cneg = {!!} ;
crecip = {!!} ;
cunite₊≡ = {!!} ; --λ {c} → refl c ;
cuniti₊≡ = {!!} ; --λ {c} → refl c ;
cswap₊≡ = {!!} ; --λ {a b} → commPlus a b ;
cassocl₊≡ = {!!} ; --λ {a b c} → ! (assocPlus a b c) ;
cassocr₊≡ = {!!} ; --λ {a b c} → assocPlus a b c ;
cunite⋆≡ = {!!} ; --λ {a} → unitMult a ;
cuniti⋆≡ = {!!} ; --λ {a} → ! (unitMult a) ;
cswap⋆≡ = {!!} ; --λ {a b} → commMult a b ;
cassocl⋆≡ = {!!} ; --λ {a b c} → ! (assocMult a b c) ;
cassocr⋆≡ = {!!} ; --λ {a b c} → assocMult a b c ;
cdistz≡ = {!!} ; --refl 0 ;
cfactorz≡ = {!!} ; --refl 0 ;
cdist≡ = {!!} ; --λ {a b c} → distrib c a b ;
cfactor≡ = {!!} ; --λ {a b c} → ! (distrib c a b) ;
cη₊ = {!!} ;
cε₊ = {!!} ;
crefe⋆ = {!!} ;
crefi⋆ = {!!} ;
crile⋆ = {!!} ;
crili⋆ = {!!}
}) b
------------------------------------------------------------------------------
| {
"alphanum_fraction": 0.4243626624,
"avg_line_length": 31.5688935282,
"ext": "agda",
"hexsha": "d0074e91f192fa2aa94f767c685f34c49a4b8b0d",
"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": "HP.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": "HP.agda",
"max_line_length": 79,
"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": "HP.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": 14386,
"size": 30243
} |
module is-free where
open import lib
open import cedille-types
open import ctxt-types
open import syntax-util
open import general-util
are-free-e = 𝔹
check-erased = tt
skip-erased = ff
are-free-in-t : Set → Set₁
are-free-in-t T = ∀{A} → are-free-e → trie A → T → 𝔹
are-free-in-term : are-free-in-t term
are-free-in-type : are-free-in-t type
are-free-in-kind : are-free-in-t kind
are-free-in-optClass : are-free-in-t optClass
-- are-free-in-optType : are-free-in-t optType
are-free-in-optTerm : are-free-in-t optTerm
are-free-in-optGuide : are-free-in-t optGuide
are-free-in-tk : are-free-in-t tk
are-free-in-liftingType : are-free-in-t liftingType
are-free-in-optType : are-free-in-t optType
are-free-in-args : are-free-in-t args
are-free-in-cases : are-free-in-t cases
are-free-in-varargs : are-free-in-t varargs
are-free-in-term ce x (App t Erased t') = are-free-in-term ce x t || (ce && are-free-in-term ce x t')
are-free-in-term ce x (App t NotErased t') = are-free-in-term ce x t || are-free-in-term ce x t'
are-free-in-term ce x (AppTp t tp) = are-free-in-term ce x t || (ce && are-free-in-type ce x tp)
are-free-in-term ce x (Hole x₁) = ff
are-free-in-term ce x (Lam _ b _ x' oc t) =
(ce && are-free-in-optClass ce x oc)
|| are-free-in-term ce (trie-remove x x') t
are-free-in-term ce x (Let _ (DefTerm _ x' m t) t') =
(ce && are-free-in-optType ce x m)
|| (are-free-in-term ce x t)
|| are-free-in-term ce (trie-remove x x') t'
are-free-in-term ce x (Let _ (DefType _ x' k t) t') =
(ce && (are-free-in-kind ce x k || are-free-in-type ce x t))
|| are-free-in-term ce (trie-remove x x') t'
are-free-in-term ce x (Open _ _ t) = are-free-in-term ce x t -- return the same answer as the erasure of (Open ...)
are-free-in-term ce x (Parens x₁ t x₂) = are-free-in-term ce x t
are-free-in-term ce x (Var _ "_") = ff
are-free-in-term ce x (Var _ x') = trie-contains x x'
are-free-in-term ce x (Beta _ ot ot') = are-free-in-optTerm ce x ot' || (ce && are-free-in-optTerm ce x ot)
are-free-in-term ce x (IotaPair _ t1 t2 ot _) = are-free-in-term ce x t1 || (ce && (are-free-in-term ce x t2 || are-free-in-optGuide ce x ot))
are-free-in-term ce x (IotaProj t n _) = are-free-in-term ce x t
are-free-in-term ce x (Epsilon _ _ _ t) = are-free-in-term ce x t
are-free-in-term ce x (Sigma _ t) = are-free-in-term ce x t
are-free-in-term ce x (Phi _ t t₁ t₂ _) = (ce && are-free-in-term ce x t) || (ce && are-free-in-term ce x t₁) || are-free-in-term ce x t₂
are-free-in-term ce x (Rho _ _ _ t ot t') = (ce && (are-free-in-term ce x t || are-free-in-optGuide ce x ot)) || are-free-in-term ce x t'
are-free-in-term ce x (Chi _ T t') = (ce && are-free-in-optType ce x T) || are-free-in-term ce x t'
are-free-in-term ce x (Delta _ T t') = ce && (are-free-in-optType ce x T || are-free-in-term ce x t')
are-free-in-term ce x (Theta _ _ t ls) = are-free-in-term ce x t || are-free-in-lterms ce x ls
where are-free-in-lterms : ∀{A} → are-free-e → trie A → lterms → 𝔹
are-free-in-lterms ce x (LtermsNil _) = ff
are-free-in-lterms ce x (LtermsCons Erased t ls) = (ce && are-free-in-term ce x t) || are-free-in-lterms ce x ls
are-free-in-lterms ce x (LtermsCons NotErased t ls) = are-free-in-term ce x t || are-free-in-lterms ce x ls
are-free-in-term ce x (Mu _ x' t ot _ cs _) = (ce && are-free-in-optType ce x ot) || are-free-in-term ce (trie-remove x x') t || are-free-in-cases ce x cs
are-free-in-term ce x (Mu' _ t ot _ cs _) = (ce && are-free-in-optType ce x ot) || are-free-in-term ce x t || are-free-in-cases ce x cs
are-free-in-cases _ _ NoCase = ff
are-free-in-cases ce x (SomeCase _ c varargs t cs) = are-free-in-varargs ce x varargs || are-free-in-term ce x t || are-free-in-cases ce x cs
are-free-in-varargs ce x NoVarargs = ff
are-free-in-varargs ce x (NormalVararg x' args) = trie-contains x x' || are-free-in-varargs ce x args
are-free-in-varargs ce x (ErasedVararg x' args) = (ce && trie-contains x x') || are-free-in-varargs ce x args
are-free-in-varargs ce x (TypeVararg x' args) = (ce && trie-contains x x') || are-free-in-varargs ce x args
{-# TERMINATING #-}
are-free-in-type ce x (Abs _ _ _ x' atk t) = are-free-in-tk ce x atk || are-free-in-type ce (trie-remove x x') t
are-free-in-type ce x (TpLambda _ _ x' atk t) = are-free-in-tk ce x atk || are-free-in-type ce (trie-remove x x') t
are-free-in-type ce x (Iota _ _ x' m t) = are-free-in-type ce x m || are-free-in-type ce (trie-remove x x') t
are-free-in-type ce x (Lft _ _ X t l) = are-free-in-liftingType ce x l || are-free-in-term ce (trie-remove x X) t
are-free-in-type ce x (TpApp t t') = are-free-in-type ce x t || are-free-in-type ce x t'
are-free-in-type ce x (TpAppt t t') = are-free-in-type ce x t || are-free-in-term ce x t'
are-free-in-type ce x (TpArrow t _ t') = are-free-in-type ce x t || are-free-in-type ce x t'
are-free-in-type ce x (TpEq _ t t' _) = are-free-in-term ce x t || are-free-in-term ce x t'
are-free-in-type ce x (TpParens x₁ t x₂) = are-free-in-type ce x t
are-free-in-type ce x (TpVar _ "_") = ff
are-free-in-type ce x (TpVar _ x') = trie-contains x x'
are-free-in-type ce x (NoSpans t _) = are-free-in-type ce x t
are-free-in-type ce x (TpHole _) = ff
are-free-in-type ce x (TpLet _ (DefTerm _ x' m t) T) =
(ce && are-free-in-optType ce x m)
|| (are-free-in-term ce x t)
|| are-free-in-type ce (trie-remove x x') T
are-free-in-type ce x (TpLet _ (DefType _ x' k T) T') =
(ce && (are-free-in-kind ce x k || are-free-in-type ce x T))
|| are-free-in-type ce (trie-remove x x') T'
are-free-in-kind ce x (KndArrow k k') = are-free-in-kind ce x k || are-free-in-kind ce x k'
are-free-in-kind ce x (KndParens x₁ k x₂) = are-free-in-kind ce x k
are-free-in-kind ce x (KndPi _ _ x' atk k) = are-free-in-tk ce x atk || are-free-in-kind ce (trie-remove x x') k
are-free-in-kind ce x (KndTpArrow t k) = are-free-in-type ce x t || are-free-in-kind ce x k
are-free-in-kind ce x (KndVar _ x' ys) = trie-contains x x' || are-free-in-args ce x ys
are-free-in-kind ce x (Star x₁) = ff
are-free-in-args ce x (ArgsCons (TermArg _ y) ys) = are-free-in-term ce x y || are-free-in-args ce x ys
are-free-in-args ce x (ArgsCons (TypeArg y) ys) = are-free-in-type ce x y || are-free-in-args ce x ys
are-free-in-args ce x ArgsNil = ff
are-free-in-optClass ce x NoClass = ff
are-free-in-optClass ce x (SomeClass atk) = are-free-in-tk ce x atk
are-free-in-optType ce x NoType = ff
are-free-in-optType ce x (SomeType t) = are-free-in-type ce x t
are-free-in-optTerm ce x NoTerm = ff
are-free-in-optTerm ce x (SomeTerm t _) = are-free-in-term ce x t
are-free-in-optGuide ce x NoGuide = ff
are-free-in-optGuide ce x (Guide _ v tp) = are-free-in-type ce (trie-remove x v) tp
are-free-in-tk ce x (Tkt t) = are-free-in-type ce x t
are-free-in-tk ce x (Tkk k) = are-free-in-kind ce x k
are-free-in-liftingType ce x (LiftArrow l l') = are-free-in-liftingType ce x l || are-free-in-liftingType ce x l'
are-free-in-liftingType ce x (LiftParens x₁ l x₂) = are-free-in-liftingType ce x l
are-free-in-liftingType ce x (LiftPi _ x' t l) =
are-free-in-type ce x t || are-free-in-liftingType ce (trie-remove x x') l
are-free-in-liftingType ce x (LiftStar x₁) = ff
are-free-in-liftingType ce x (LiftTpArrow t l) = are-free-in-type ce x t || are-free-in-liftingType ce x l
are-free-in : {ed : exprd} → are-free-e → stringset → ⟦ ed ⟧ → 𝔹
are-free-in{TERM} e x t = are-free-in-term e x t
are-free-in{ARG} e x (TermArg _ t) = are-free-in-term e x t
are-free-in{TYPE} e x t = are-free-in-type e x t
are-free-in{ARG} e x (TypeArg t) = are-free-in-type e x t
are-free-in{KIND} e x t = are-free-in-kind e x t
are-free-in{TK} e x t = are-free-in-tk e x t
are-free-in{LIFTINGTYPE} e x t = are-free-in-liftingType e x t
are-free-in{QUALIF} e x (x' , as) = trie-contains x x' || are-free-in-args e x as
is-free-in : {ed : exprd} → are-free-e → var → ⟦ ed ⟧ → 𝔹
is-free-in{TERM} e x t = are-free-in-term e (stringset-singleton x) t
is-free-in{ARG} e x (TermArg _ t) = are-free-in-term e (stringset-singleton x) t
is-free-in{TYPE} e x t = are-free-in-type e (stringset-singleton x) t
is-free-in{ARG} e x (TypeArg t) = are-free-in-type e (stringset-singleton x) t
is-free-in{KIND} e x t = are-free-in-kind e (stringset-singleton x) t
is-free-in{LIFTINGTYPE} e x t = are-free-in-liftingType e (stringset-singleton x) t
is-free-in{QUALIF} e x (x' , as) = x =string x' || are-free-in-args e (stringset-singleton x) as
is-free-in{TK} e x t = are-free-in-tk e (stringset-singleton x) t
abs-tk : maybeErased → var → tk → type → type
abs-tk me x (Tkk k) tp = Abs posinfo-gen Erased posinfo-gen x (Tkk k) tp
abs-tk me x (Tkt tp') tp with are-free-in check-erased (stringset-singleton x) tp
abs-tk me x (Tkt tp') tp | tt = Abs posinfo-gen me posinfo-gen x (Tkt tp') tp
abs-tk me x (Tkt tp') tp | ff = TpArrow tp' me tp
absk-tk : var → tk → kind → kind
absk-tk x atk k with are-free-in check-erased (stringset-singleton x) k
absk-tk x atk k | tt = KndPi posinfo-gen posinfo-gen x atk k
absk-tk x (Tkt tp) k | ff = KndTpArrow tp k
absk-tk x (Tkk k') k | ff = KndArrow k' k
data abs : Set where
mk-abs : maybeErased → var → tk → (var-free-in-body : 𝔹) → type → abs
to-abs : type → maybe abs
to-abs (Abs _ me _ x atk tp) = just (mk-abs me x atk (are-free-in check-erased (stringset-singleton x) tp) tp)
to-abs (TpArrow tp1 me tp2) = just (mk-abs me dummy-var (Tkt tp1) ff tp2)
to-abs _ = nothing
record is-tpabs : Set where
constructor mk-tpabs
field
is-tpabs-e? : maybeErased
is-tpabs-var : var
is-tpabs-kind : kind
is-tpabs-body : type
open is-tpabs public
is-tpabs? = type ∨ is-tpabs
pattern yes-tpabs e? x k tp = inj₂ (mk-tpabs e? x k tp)
pattern not-tpabs tp = inj₁ tp
to-is-tpabs : type → is-tpabs?
to-is-tpabs tp with to-abs tp
... | nothing =
not-tpabs tp
... | just (mk-abs _ _ (Tkt _) _ _)
= not-tpabs tp
... | just (mk-abs e? x (Tkk k) var-free-in-body tp') =
yes-tpabs e? x k tp'
data absk : Set where
mk-absk : var → tk → (var-free-in-body : 𝔹) → kind → absk
to-absk : kind → maybe absk
to-absk (KndPi _ _ x atk k) = just (mk-absk x atk (are-free-in check-erased (stringset-singleton x) k) k)
to-absk (KndArrow k1 k2) = just (mk-absk dummy-var (Tkk k1) ff k2)
to-absk (KndTpArrow tp k) = just (mk-absk dummy-var (Tkt tp) ff k)
to-absk _ = nothing
record is-tmabs : Set where
constructor mk-tmabs
field
is-tmabs-binder : maybeErased
is-tmabs-var : var
is-tmabs-dom : type
is-tmabs-var-in-body : 𝔹
is-tmabs-cod : type
open is-tmabs public
is-tmabs? = type ∨ is-tmabs
pattern yes-tmabs e? x dom occurs cod = inj₂ (mk-tmabs e? x dom occurs cod)
pattern not-tmabs tp = inj₁ tp
to-is-tmabs : type → is-tmabs?
to-is-tmabs (Abs _ e? _ x (Tkt dom) cod) =
yes-tmabs e? x dom (is-free-in check-erased x cod) cod
to-is-tmabs (TpArrow dom e? cod) =
yes-tmabs e? "_" dom ff cod
to-is-tmabs tp = not-tmabs tp
from-is-tmabs : is-tmabs → type
from-is-tmabs (mk-tmabs b x dom occ cod) =
Abs posinfo-gen b posinfo-gen x (Tkt dom) cod
| {
"alphanum_fraction": 0.6541903987,
"avg_line_length": 48.7268722467,
"ext": "agda",
"hexsha": "b573ec5d16a289b8cebc2ccc2e12130c2a0f721d",
"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": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "xoltar/cedille",
"max_forks_repo_path": "src/is-free.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"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": "xoltar/cedille",
"max_issues_repo_path": "src/is-free.agda",
"max_line_length": 154,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "acf691e37210607d028f4b19f98ec26c4353bfb5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "xoltar/cedille",
"max_stars_repo_path": "src/is-free.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3855,
"size": 11061
} |
open import AEff
open import EffectAnnotations
open import Types hiding (``)
open import Relation.Binary.PropositionalEquality hiding ([_] ; Extensionality)
--open ≡-Reasoning
module Renamings where
-- SET OF RENAMINGS BETWEEN CONTEXTS
Ren : Ctx → Ctx → Set
Ren Γ Γ' = {X : VType} → X ∈ Γ → X ∈ Γ'
-- IDENTITY, COMPOSITION, AND EXCHANGE RENAMINGS
id-ren : {Γ : Ctx} → Ren Γ Γ
id-ren {X} x = x
comp-ren : {Γ Γ' Γ'' : Ctx} → Ren Γ' Γ'' → Ren Γ Γ' → Ren Γ Γ''
comp-ren f g x = f (g x)
exchange : {Γ : Ctx} {X Y : VType} → Ren (Γ ∷ X ∷ Y) (Γ ∷ Y ∷ X)
exchange Hd = Tl Hd
exchange (Tl Hd) = Hd
exchange (Tl (Tl x)) = Tl (Tl x)
-- WEAKENING OF RENAMINGS
wk₁ : {Γ : Ctx} {X : VType} → Ren Γ (Γ ∷ X)
wk₁ = Tl
wk₂ : {Γ Γ' : Ctx} {X : VType} → Ren Γ Γ' → Ren (Γ ∷ X) (Γ' ∷ X)
wk₂ f Hd = Hd
wk₂ f (Tl v) = Tl (f v)
wk₃ : {Γ : Ctx} {X Y Z : VType} → Ren (Γ ∷ Y ∷ Z) (Γ ∷ X ∷ Y ∷ Z)
wk₃ Hd = Hd
wk₃ (Tl Hd) = Tl Hd
wk₃ (Tl (Tl x)) = Tl (Tl (Tl x))
-- ACTION OF RENAMING ON WELL-TYPED VALUES AND COMPUTATIONS
mutual
V-rename : {X : VType} {Γ Γ' : Ctx} → Ren Γ Γ' → Γ ⊢V⦂ X → Γ' ⊢V⦂ X
V-rename f (` x) = ` f x
V-rename f (`` c) = `` c
V-rename f (ƛ M) = ƛ (M-rename (wk₂ f) M)
V-rename f ⟨ V ⟩ = ⟨ V-rename f V ⟩
M-rename : {C : CType} {Γ Γ' : Ctx} → Ren Γ Γ' → Γ ⊢M⦂ C → Γ' ⊢M⦂ C
M-rename f (return V) =
return (V-rename f V)
M-rename f (let= M `in N) =
let= M-rename f M `in M-rename (wk₂ f) N
M-rename f (letrec M `in N) =
letrec M-rename (wk₂ (wk₂ f)) M `in M-rename (wk₂ f) N
M-rename f (V · W) =
V-rename f V · V-rename f W
M-rename f (↑ op p V M) =
↑ op p (V-rename f V) (M-rename f M)
M-rename f (↓ op V M) =
↓ op (V-rename f V) (M-rename f M)
M-rename f (promise op ∣ p ↦ M `in N) =
promise op ∣ p ↦ M-rename (wk₂ f) M `in M-rename (wk₂ f) N
M-rename f (await V until M) =
await (V-rename f V) until (M-rename (wk₂ f) M)
M-rename f (coerce p q M) =
coerce p q (M-rename f M)
-- ACTION OF RENAMING ON WELL-TYPED PROCESSES
P-rename : {o : O} {PP : PType o} {Γ Γ' : Ctx} → Ren Γ Γ' → Γ ⊢P⦂ PP → Γ' ⊢P⦂ PP
P-rename f (run M) =
run (M-rename f M)
P-rename f (P ∥ Q) =
P-rename f P ∥ P-rename f Q
P-rename f (↑ op p V P) =
↑ op p (V-rename f V) (P-rename f P)
P-rename f (↓ op V P) =
↓ op (V-rename f V) (P-rename f P)
| {
"alphanum_fraction": 0.5474231269,
"avg_line_length": 25.3736263736,
"ext": "agda",
"hexsha": "9f3a5fc28393c8eb2a7c91fbef4c1c0402e4fc83",
"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": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "danelahman/aeff-agda",
"max_forks_repo_path": "Renamings.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"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": "danelahman/aeff-agda",
"max_issues_repo_path": "Renamings.agda",
"max_line_length": 80,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "71ebed9f90a3eb37ae6cd209457bae23a4d122d1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "danelahman/aeff-agda",
"max_stars_repo_path": "Renamings.agda",
"max_stars_repo_stars_event_max_datetime": "2021-03-22T22:48:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-07-17T00:15:00.000Z",
"num_tokens": 1053,
"size": 2309
} |
module Numeral.Natural.Oper.Proofs.Multiplication where
open import Logic.Propositional
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Oper.Proofs.Order
open import Numeral.Natural.Relation
open import Numeral.Natural.Relation.Order
open import Numeral.Natural.Relation.Order.Classical
open import Numeral.Natural.Relation.Order.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Operator
import Structure.Operator.Names as Names
open import Structure.Operator.Properties
open import Structure.Relator.Properties
open import Syntax.Transitivity
instance
[⋅][−₀]-distributivityᵣ : Distributivityᵣ(_⋅_)(_−₀_)
Distributivityᵣ.proof([⋅][−₀]-distributivityᵣ) {x}{y}{z} = p{x}{y}{z} where
p : ∀{x y z : ℕ} → ((x −₀ y) ⋅ z) ≡ (x ⋅ z) −₀ (y ⋅ z)
p {x} {y} {𝟎} = [≡]-intro
p {x} {y} {𝐒 z} with [≥]-or-[<] {x}{y}
... | [∨]-introₗ gt =
(x −₀ y) ⋅ 𝐒(z) 🝖[ _≡_ ]-[]
(x −₀ y) + ((x −₀ y) ⋅ z) 🝖[ _≡_ ]-[ congruence₂ᵣ(_+_)(x −₀ y) (p {x}{y}{z}) ]
(x −₀ y) + ((x ⋅ z) −₀ (y ⋅ z)) 🝖[ _≡_ ]-[ [+][−₀]-almost-associativity {x −₀ y} ([≤]-with-[⋅]ᵣ {c = z} gt) ]-sym
((x −₀ y) + (x ⋅ z)) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) (commutativity(_+_) {x −₀ y}{x ⋅ z}) ]
((x ⋅ z) + (x −₀ y)) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) ([+][−₀]-almost-associativity {x ⋅ z} gt) ]-sym
(((x ⋅ z) + x) −₀ y) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ congruence₂ₗ(_−₀_)(y ⋅ z) (congruence₂ₗ(_−₀_)(y) (commutativity(_+_) {x ⋅ z}{x})) ]
((x + (x ⋅ z)) −₀ y) −₀ (y ⋅ z) 🝖[ _≡_ ]-[ [−₀][−₀]-to-[−₀][+] {x + (x ⋅ z)}{y}{y ⋅ z} ]
(x + (x ⋅ z)) −₀ (y + (y ⋅ z)) 🝖[ _≡_ ]-[]
(x ⋅ 𝐒(z)) −₀ (y ⋅ 𝐒(z)) 🝖-end
... | [∨]-introᵣ lt =
(x −₀ y) ⋅ 𝐒(z) 🝖[ _≡_ ]-[ congruence₂ₗ(_⋅_)(𝐒(z)) ([↔]-to-[→] [−₀]-when-0 (sub₂(_<_)(_≤_) lt)) ]
𝟎 ⋅ 𝐒(z) 🝖[ _≡_ ]-[ absorberₗ(_⋅_)(𝟎) {𝐒(z)} ]
𝟎 🝖[ _≡_ ]-[ [↔]-to-[→] [−₀]-when-0 ([≤]-with-[+] ⦃ sub₂(_<_)(_≤_) lt ⦄ ⦃ [≤]-with-[⋅]ᵣ {c = z} (sub₂(_<_)(_≤_) lt) ⦄) ]-sym
(x + (x ⋅ z)) −₀ (y + (y ⋅ z)) 🝖-end
-- TODO: This is a specialized distributivity-equivalence-by-commutativity
instance
[⋅][−₀]-distributivityₗ : Distributivityₗ(_⋅_)(_−₀_)
Distributivityₗ.proof([⋅][−₀]-distributivityₗ) {x}{y}{z} = p{x}{y}{z} where
p : ∀{x y z : ℕ} → (x ⋅ (y −₀ z)) ≡ (x ⋅ y) −₀ (x ⋅ z)
p{x}{y}{z} =
x ⋅ (y −₀ z) 🝖[ _≡_ ]-[ commutativity(_⋅_) {x}{y −₀ z} ]
(y −₀ z) ⋅ x 🝖[ _≡_ ]-[ distributivityᵣ(_⋅_)(_−₀_) {y}{z}{x} ]
(y ⋅ x) −₀ (z ⋅ x) 🝖[ _≡_ ]-[ congruence₂(_−₀_) (commutativity(_⋅_) {y}{x}) (commutativity(_⋅_) {z}{x}) ]
(x ⋅ y) −₀ (x ⋅ z) 🝖-end
[⋅]-cancellationₗ : ∀{x} → ⦃ pos : Positive(x) ⦄ → (Names.CancellationOnₗ(_⋅_)(x))
[⋅]-cancellationₗ {𝐒 a}{b}{c} p with [<]-trichotomy {b}{c}
... | [∨]-introₗ ([∨]-introₗ lt) with () ← [<]-to-[≢] ([<]-with-[⋅]ₗ {a = a} lt) p
... | [∨]-introₗ ([∨]-introᵣ eq) = eq
... | [∨]-introᵣ gt with () ← [>]-to-[≢] ([<]-with-[⋅]ₗ {a = a} gt) p
[⋅]-cancellationᵣ : ∀{x} → ⦃ pos : Positive(x) ⦄ → (Names.CancellationOnᵣ(_⋅_)(x))
[⋅]-cancellationᵣ {𝐒 c}{a}{b} p with [<]-trichotomy {a}{b}
... | [∨]-introₗ ([∨]-introₗ lt) with () ← [<]-to-[≢] ([<]-with-[⋅]ᵣ {c = c} lt) p
... | [∨]-introₗ ([∨]-introᵣ eq) = eq
... | [∨]-introᵣ gt with () ← [>]-to-[≢] ([<]-with-[⋅]ᵣ {c = c} gt) p
| {
"alphanum_fraction": 0.4906903466,
"avg_line_length": 54.546875,
"ext": "agda",
"hexsha": "106bbf45d16dfafa4673b19f5eb8aefff1ec2dbd",
"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/Proofs/Multiplication.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/Proofs/Multiplication.agda",
"max_line_length": 159,
"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/Proofs/Multiplication.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": 1778,
"size": 3491
} |
{-# OPTIONS --safe --warning=error #-}
open import Sets.EquivalenceRelations
open import Setoids.Setoids
open import Groups.FreeGroup.Definition
open import Groups.Homomorphisms.Definition
open import Groups.Definition
open import Decidable.Sets
open import Numbers.Naturals.Order
open import LogicalFormulae
open import Semirings.Definition
open import Functions.Definition
open import Groups.Isomorphisms.Definition
open import Boolean.Definition
open import Boolean.Lemmas
module Groups.FreeGroup.Parity {a : _} {A : Set a} (decA : DecidableSet A) where
open import Groups.FreeGroup.Word decA
open import Groups.FreeGroup.Group decA
C2 : Group (reflSetoid Bool) xor
Group.+WellDefined C2 refl refl = refl
Group.0G C2 = BoolFalse
Group.inverse C2 = id
Group.+Associative C2 {BoolTrue} {BoolTrue} {BoolTrue} = refl
Group.+Associative C2 {BoolTrue} {BoolTrue} {BoolFalse} = refl
Group.+Associative C2 {BoolTrue} {BoolFalse} {z} = refl
Group.+Associative C2 {BoolFalse} {y} {z} = refl
Group.identRight C2 {BoolTrue} = refl
Group.identRight C2 {BoolFalse} = refl
Group.identLeft C2 {x} = refl
Group.invLeft C2 {BoolTrue} = refl
Group.invLeft C2 {BoolFalse} = refl
Group.invRight C2 {BoolTrue} = refl
Group.invRight C2 {BoolFalse} = refl
parity : (x : A) → ReducedWord → Bool
parity x empty = BoolFalse
parity x (prependLetter (ofLetter y) w _) with decA x y
parity x (prependLetter (ofLetter y) w _) | inl _ = not (parity x w)
parity x (prependLetter (ofLetter y) w _) | inr _ = parity x w
parity x (prependLetter (ofInv y) w _) with decA x y
parity x (prependLetter (ofInv y) w _) | inl _ = not (parity x w)
parity x (prependLetter (ofInv y) w _) | inr _ = parity x w
private
parityPrepend : (a : A) (w : ReducedWord) (l : A) → ((a ≡ l) → False) → parity a (prepend w (ofLetter l)) ≡ parity a w
parityPrepend a empty l notEq with decA a l
parityPrepend a empty l notEq | inl x = exFalso (notEq x)
parityPrepend a empty l notEq | inr x = refl
parityPrepend a (prependLetter (ofLetter r) w x) l notEq with decA a l
parityPrepend a (prependLetter (ofLetter r) w x) l notEq | inl m = exFalso (notEq m)
parityPrepend a (prependLetter (ofLetter r) w x) l notEq | inr _ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r with decA l r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inl l=r = exFalso (notEq (transitivity a=r (equalityCommutative l=r)))
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r with decA a l
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inl x₁ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inr bad = exFalso (bad a=r)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r with decA l r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl x₁ = refl
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r with decA a l
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l with decA a r
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inl a=r = exFalso (a!=r a=r)
parityPrepend a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inr x₁ = refl
parityPrepend' : (a : A) (w : ReducedWord) (l : A) → ((a ≡ l) → False) → parity a (prepend w (ofInv l)) ≡ parity a w
parityPrepend' a empty l notEq with decA a l
parityPrepend' a empty l notEq | inl x = exFalso (notEq x)
parityPrepend' a empty l notEq | inr x = refl
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq with decA l r
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq | inl m with decA a r
... | inl a=r = exFalso (notEq (transitivity a=r (equalityCommutative m)))
... | inr a!=r = refl
parityPrepend' a (prependLetter (ofLetter r) w x) l notEq | inr l!=r with decA a l
... | inl a=l = exFalso (notEq a=l)
... | inr a!=l = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r with decA l r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inl l=r = exFalso (notEq (transitivity a=r (equalityCommutative l=r)))
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inl x₁ = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inl a=r | inr l!=r | inr a!=l | inr bad = exFalso (bad a=r)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r with decA l r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inl l=r | inr a!=l with decA a r
... | inl a=r = exFalso (a!=r a=r)
... | inr _ = refl
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r with decA a l
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inl a=l = exFalso (notEq a=l)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l with decA a r
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inl a=r = exFalso (a!=r a=r)
parityPrepend' a (prependLetter (ofInv r) w x) l notEq | inr a!=r | inr l!=r | inr a!=l | inr x₁ = refl
parityPrepend'' : (a : A) (w : ReducedWord) → parity a (prepend w (ofLetter a)) ≡ not (parity a w)
parityPrepend'' a empty with decA a a
... | inl _ = refl
... | inr bad = exFalso (bad refl)
parityPrepend'' a (prependLetter (ofLetter l) w x) with decA a a
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ with decA a l
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ | inl a=l = refl
parityPrepend'' a (prependLetter (ofLetter l) w x) | inl _ | inr a!=l = refl
parityPrepend'' a (prependLetter (ofLetter l) w x) | inr bad = exFalso (bad refl)
parityPrepend'' a (prependLetter (ofInv l) w x) with decA a l
... | inl a=l = equalityCommutative (notNot (parity a w))
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l with decA a a
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l | inl _ with decA a l
... | inl a=l = exFalso (a!=l a=l)
... | inr _ = refl
parityPrepend'' a (prependLetter (ofInv l) w x) | inr a!=l | inr bad = exFalso (bad refl)
parityPrepend''' : (a : A) (w : ReducedWord) → parity a (prepend w (ofInv a)) ≡ not (parity a w)
parityPrepend''' a empty with decA a a
... | inl _ = refl
... | inr bad = exFalso (bad refl)
parityPrepend''' a (prependLetter (ofLetter l) w x) with decA a l
... | inl a=l = equalityCommutative (notNot _)
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l with decA a a
... | inl _ with decA a l
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inl _ | inl a=l = exFalso (a!=l a=l)
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inl _ | inr _ = refl
parityPrepend''' a (prependLetter (ofLetter l) w x) | inr a!=l | inr bad = exFalso (bad refl)
parityPrepend''' a (prependLetter (ofInv l) w x) with decA a a
parityPrepend''' a (prependLetter (ofInv l) w x) | inl _ with decA a l
... | inl a=l = refl
... | inr a!=l = refl
parityPrepend''' a (prependLetter (ofInv l) w x) | inr bad = exFalso (bad refl)
parityHomIsHom : (a : A) → (x y : ReducedWord) → parity a (_+W_ x y) ≡ xor (parity a x) (parity a y)
parityHomIsHom a empty y = refl
parityHomIsHom a (prependLetter (ofLetter l) x _) y with decA a l
parityHomIsHom a (prependLetter (ofLetter .a) x _) y | inl refl = transitivity (parityPrepend'' a (x +W y)) (transitivity (applyEquality not (parityHomIsHom a x y)) (notXor (parity a x) (parity a y)))
parityHomIsHom a (prependLetter (ofLetter l) x _) y | inr a!=l = transitivity (parityPrepend a (_+W_ x y) l a!=l) (parityHomIsHom a x y)
parityHomIsHom a (prependLetter (ofInv l) x _) y with decA a l
parityHomIsHom a (prependLetter (ofInv .a) x _) y | inl refl = transitivity (parityPrepend''' a (x +W y)) (transitivity (applyEquality not (parityHomIsHom a x y)) (notXor (parity a x) (parity a y)))
parityHomIsHom a (prependLetter (ofInv l) x _) y | inr a!=l = transitivity (parityPrepend' a (x +W y) l a!=l) (parityHomIsHom a x y)
parityHom : (x : A) → GroupHom (freeGroup) C2 (parity x)
GroupHom.groupHom (parityHom x) {y} {z} = parityHomIsHom x y z
GroupHom.wellDefined (parityHom x) refl = refl
| {
"alphanum_fraction": 0.6697534188,
"avg_line_length": 62.75,
"ext": "agda",
"hexsha": "202e7da9127667a1b6afa1b17c681bbd575da1da",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Groups/FreeGroup/Parity.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/FreeGroup/Parity.agda",
"max_line_length": 202,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Groups/FreeGroup/Parity.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": 3434,
"size": 9287
} |
module _ where
postulate
A : Set
_,_ : A → A → A
module M where
module Mx (x : A) where
module M where
module My (y : A) where
f : A
f = x , y
postulate
a b c : A
module M′ = M
module Ma = M′.Mx.M a
module Mab = Ma.My b
g : A
g = Mab.f
-- Original bug report --
record I (A : Set) : Set where
field
i : A → A
record R (A : Set) : Set where
field
f : A → A
open R public
module C (A : Set) where
I₀ : I A
I₀ = record { i = λ x → x }
open I I₀
r : (B : Set) → R B
r B = record { f = λ x → x }
g1 : (B : Set) → B → B
g1 B = f′
where
open R (r B) renaming (f to f′)
| {
"alphanum_fraction": 0.4885496183,
"avg_line_length": 13.6458333333,
"ext": "agda",
"hexsha": "e9c1e2d314ce6be5d4be390e5e52b6ac23068049",
"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/Issue1396.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/Issue1396.agda",
"max_line_length": 37,
"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/Issue1396.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": 265,
"size": 655
} |
{-# OPTIONS --without-K #-}
open import Base
module Spaces.LoopSpaceDecidableWedgeCircles {i} (A : Set i) (eq : has-dec-eq A)
where
open import Spaces.WedgeCircles A renaming (wedge-circles to WA; base to baseWA)
open import Algebra.FreeGroup A renaming (freegroup to FA)
open import Algebra.FreeGroupProps A
open import Algebra.FreeGroupAsReducedWords A eq
open import Spaces.FlatteningLoopSpaceWedgeCircles A (dec-eq-is-set eq)
-- We can now prove that [tot-cover] is contractible using [CA-rec]
-- (because [CA-rec] means that [tot-cover] is the Cayley graph of FA)
P-CA-contr : (x : tot-cover) → Set _
P-CA-contr x = x ≡ CA-z e
-- We first prove it on points coming from reduced words
CA-contr-base-reduced-word : (w : reduced-word)
→ P-CA-contr (CA-z (reduced-to-freegroup w))
CA-contr-base-reduced-word (ε , red) = refl
CA-contr-base-reduced-word ((x ∷ w) , red) =
! (CA-e x _)
∘ CA-contr-base-reduced-word (w , tail-is-reduced x w red)
CA-contr-base-reduced-word ((x ′∷ w) , red) =
(CA-e x _ ∘ ap CA-z (right-inverse-· x _))
∘ CA-contr-base-reduced-word (w , tail'-is-reduced x w red)
-- Then on every point
CA-contr-base : (u : FA) → P-CA-contr (CA-z u)
CA-contr-base u =
ap CA-z (! (inv₂ u)) ∘ (CA-contr-base-reduced-word (freegroup-to-reduced u))
-- Now we prove that it’s true on paths, coming from reduced words
abstract
CA-contr-loop-reduced-word : (t : A) (w : reduced-word) →
(ap CA-z (reduced-to-freegroup-mul-reduce t w)
∘ ! (CA-e t (reduced-to-freegroup w)))
∘ (CA-contr-base-reduced-word w)
≡ CA-contr-base-reduced-word (mul-reduce t w)
CA-contr-loop-reduced-word t (ε , red) = refl
CA-contr-loop-reduced-word t ((x ∷ w) , red) = refl
CA-contr-loop-reduced-word t ((x ′∷ w) , red) with (eq t x)
CA-contr-loop-reduced-word x ((.x ′∷ w) , red) | inl refl =
-- With the notations below, what we have to prove
-- is [ (ap CA-z (! p) ∘ ! q) ∘ ((q ∘ ap CA-z p) ∘ r) ≡ r ]
concat-assoc (ap CA-z (! p)) _ _
∘ (ap (λ t₁ → t₁ ∘ (! q ∘ ((q ∘ ap CA-z p) ∘ r))) (ap-opposite CA-z p)
∘ move!-right-on-left (ap CA-z p) (! q ∘ ((q ∘ ap CA-z p) ∘ r)) r
(move!-right-on-left q ((q ∘ ap CA-z p) ∘ r) (ap CA-z p ∘ r)
(concat-assoc q _ _))) where
fw : FA
fw = reduced-to-freegroup (w , tail'-is-reduced x w red)
p : x · (x ⁻¹· fw) ≡ fw
p = right-inverse-· x fw
q : CA-z (x ⁻¹· fw) ≡ CA-z (x · (x ⁻¹· fw))
q = CA-e x (x ⁻¹· fw)
r : CA-z fw ≡ CA-z e
r = CA-contr-base-reduced-word (w , tail'-is-reduced x w red)
CA-contr-loop-reduced-word t ((x ′∷ w) , red) | inr different = refl
-- And finally for every path
CA-contr-loop : (t : A) (u : FA)
→ transport P-CA-contr (CA-e t u) (CA-contr-base u) ≡ (CA-contr-base (t · u))
CA-contr-loop t u =
-- Idea:
--
-- We need to prove
-- [p u ∘ (ap CA-z (q u) ∘ for-red u)
-- ≡ ap CA-z (q (t · u)) ∘ for-red (t · u)]
--
-- [CA-contr-loop-reduced-word] gives
-- that [(ap CA-z comp ∘ p (k u)) ∘ for-red u ≡ for-red (t · u)]
trans-id≡cst (CA-e t u) (CA-contr-base u)
∘ (! (concat-assoc (p u) (ap CA-z (q u)) (for-red u))
∘ (whisker-right (for-red u) {q = p u ∘ ap CA-z (q u)}
{r = ap CA-z (q (t · u)) ∘ (ap CA-z comp ∘ p (k u))}
(! (homotopy-naturality f g p (q u))
∘ (whisker-right (p (k u)) {q = ap f (q u)}
{r = ap CA-z (q (t · u)) ∘ ap CA-z comp}
(ap-compose CA-z (λ u₁ → t · u₁) (q u)
∘ (ap (ap CA-z) (π₁ (freegroup-is-set _ _ _ _))
∘ ap-concat CA-z (q (t · u)) comp))
∘ concat-assoc (ap CA-z (q (t · u))) (ap CA-z comp) (p (k u))))
∘ (concat-assoc (ap CA-z (q (t · u))) (ap CA-z comp ∘ p (k u))
(for-red u)
∘ whisker-left (ap CA-z (q (t · u)))
auie))) where
f : FA → tot-cover
f u = CA-z (t · u)
g : FA → tot-cover
g u = CA-z u
p : (u : FA) → f u ≡ g u
p u = ! (CA-e t u)
k : FA → FA
k u = reduced-to-freegroup (freegroup-to-reduced u)
q : (u : FA) → u ≡ k u
q u = ! (inv₂ u)
for-red : (u : FA) → CA-z (k u) ≡ CA-z e
for-red u = CA-contr-base-reduced-word (freegroup-to-reduced u)
comp : k (t · u) ≡ t · (k u)
comp = reduced-to-freegroup-mul-reduce t (freegroup-to-reduced u)
auie : (ap CA-z comp ∘ p (k u)) ∘ for-red u ≡ for-red (t · u)
auie = CA-contr-loop-reduced-word t (freegroup-to-reduced u)
-- Hence, [CA] is contractible
CA-contr : (x : tot-cover) → P-CA-contr x
CA-contr = equivCA.CA-rec P-CA-contr CA-contr-base CA-contr-loop
abstract
tot-cover-is-contr : is-contr tot-cover
tot-cover-is-contr = (CA-z e , λ x → CA-contr x)
-- We define now a fiberwise map between the two fibrations [path-fib]
-- and [universal-cover]
fiberwise-map : (x : WA) → (path-fib x → universal-cover x)
fiberwise-map x q = transport universal-cover (! q) e
-- This induces an equivalence on the total spaces, because both total spaces
-- are contractible
total-equiv : is-equiv (total-map fiberwise-map)
total-equiv = contr-to-contr-is-equiv (total-map fiberwise-map)
tot-path-fib-is-contr
tot-cover-is-contr
-- Hence an equivalence fiberwise
fiberwise-map-is-equiv : (x : WA) → is-equiv (fiberwise-map x)
fiberwise-map-is-equiv x = fiberwise-is-equiv fiberwise-map total-equiv x
-- We can then conclude that the based loop space of the wedge of circles on [A]
-- is equivalent to the free group on [A], where [A] is any discrete set (i.e.
-- with decidable equality)
ΩWA≃FA : (baseWA ≡ baseWA) ≃ FA
ΩWA≃FA = (fiberwise-map baseWA , fiberwise-map-is-equiv baseWA)
| {
"alphanum_fraction": 0.5916561315,
"avg_line_length": 37.4121621622,
"ext": "agda",
"hexsha": "84ec70c51627ca3046776733d47086aad89c1f1b",
"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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Spaces/LoopSpaceDecidableWedgeCircles.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"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": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Spaces/LoopSpaceDecidableWedgeCircles.agda",
"max_line_length": 80,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "timjb/HoTT-Agda",
"max_stars_repo_path": "old/Spaces/LoopSpaceDecidableWedgeCircles.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": 1992,
"size": 5537
} |
{-# OPTIONS --without-K --exact-split --safe #-}
module Fragment.Equational.Theory.Bundles where
open import Fragment.Algebra.Signature
open import Fragment.Equational.Theory.Base
open import Fragment.Equational.Theory.Combinators
open import Data.Nat using (ℕ)
module _ where
data MagmaOp : ℕ → Set where
• : MagmaOp 2
Σ-magma : Signature
Σ-magma = record { ops = MagmaOp }
import Fragment.Equational.Theory.Laws Σ-magma as L
data MagmaEq : ℕ → Set where
magma-eqs : ∀ {n} → MagmaEq n → Eq Σ-magma n
magma-eqs ()
data SemigroupEq : ℕ → Set where
assoc : SemigroupEq 3
semigroup-eqs : ∀ {n} → SemigroupEq n → Eq Σ-magma n
semigroup-eqs assoc = L.assoc •
data CSemigroupEq : ℕ → Set where
comm : CSemigroupEq 2
assoc : CSemigroupEq 3
csemigroup-eqs : ∀ {n} → CSemigroupEq n → Eq Σ-magma n
csemigroup-eqs comm = L.comm •
csemigroup-eqs assoc = L.assoc •
Θ-magma : Theory
Θ-magma = record { Σ = Σ-magma
; eqs = MagmaEq
; _⟦_⟧ₑ = magma-eqs
}
Θ-semigroup : Theory
Θ-semigroup = record { Σ = Σ-magma
; eqs = SemigroupEq
; _⟦_⟧ₑ = semigroup-eqs
}
Θ-csemigroup : Theory
Θ-csemigroup = record { Σ = Σ-magma
; eqs = CSemigroupEq
; _⟦_⟧ₑ = csemigroup-eqs
}
Θ-monoid : Theory
Θ-monoid = AddId Θ-semigroup •
Θ-cmonoid : Theory
Θ-cmonoid = AddId Θ-csemigroup •
| {
"alphanum_fraction": 0.5897945659,
"avg_line_length": 23.9523809524,
"ext": "agda",
"hexsha": "de3694eff24782578045ed3d674031cae5119c5b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-06-16T08:04:31.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-06-15T15:34:50.000Z",
"max_forks_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "yallop/agda-fragment",
"max_forks_repo_path": "src/Fragment/Equational/Theory/Bundles.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_issues_repo_issues_event_max_datetime": "2021-06-16T10:24:15.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-06-16T09:44:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "yallop/agda-fragment",
"max_issues_repo_path": "src/Fragment/Equational/Theory/Bundles.agda",
"max_line_length": 56,
"max_stars_count": 18,
"max_stars_repo_head_hexsha": "f2a6b1cf4bc95214bd075a155012f84c593b9496",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "yallop/agda-fragment",
"max_stars_repo_path": "src/Fragment/Equational/Theory/Bundles.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": 502,
"size": 1509
} |
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.Relation.Unary where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Univalence
open import Cubical.Classes
import Cubical.Foundations.Logic as L
open import Cubical.Data.Sigma
open import Cubical.Data.Empty using (⊥)
open import Cubical.Data.Sum.Base using (_⊎_; rec)
open import Cubical.Foundations.Function
open import Cubical.Relation.Nullary
open import Cubical.Relation.Nullary.Decidable using (IsYes)
private
variable
a b c ℓ ℓ₁ ℓ₂ : Level
A : Type a
B : Type b
C : Type c
------------------------------------------------------------------------
-- Definition
-- Unary relations are known as predicates and `Pred A ℓ` can be viewed
-- as some property that elements of type A might satisfy.
-- Consequently `P : Pred A ℓ` can also be seen as a subset of A
-- containing all the elements of A that satisfy property P. This view
-- informs much of the notation used below.
RawPred : Type a → (ℓ : Level) → Type _
RawPred A ℓ = A → Type ℓ
Pred : Type a → (ℓ : Level) → Type _
Pred A ℓ = A → hProp ℓ
isPropValued : RawPred A ℓ → Type _
isPropValued P = ∀ x → isProp (P x)
instance
PredCast : Cast (Pred A ℓ) (RawPred A ℓ)
PredCast = record { [_] = λ P x → P x .fst }
isProp[_] : (P : Pred A ℓ) → isPropValued [ P ]
isProp[ P ] x = P x .snd
fromRaw : (P : RawPred A ℓ) → isPropValued P → Pred A ℓ
fromRaw P isPropP x .fst = P x
fromRaw P isPropP x .snd = isPropP x
------------------------------------------------------------------------
-- Special sets
-- The empty set.
∅ : Pred A _
∅ _ = L.⊥
-- The singleton set.
{_} : A → Pred A _
{ x } = L._≡ₚ x
-- The universal set.
U : Pred A _
U _ = L.⊤
open import Cubical.Data.Unit public using (tt)
------------------------------------------------------------------------
-- Membership
infix 6 _∈_ _∉_
_∈_ : A → Pred A ℓ → Type _
x ∈ P = ⟨ P x ⟩
_∉_ : A → Pred A ℓ → Type _
x ∉ P = ¬ x ∈ P
------------------------------------------------------------------------
-- Subset relations
infix 6 _⊆_ _⊇_ _⊈_ _⊉_ _⊂_ _⊃_ _⊄_ _⊅_
_⊆_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊆ Q = ∀ {x} → x ∈ P → x ∈ Q
_⊇_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊇ Q = Q ⊆ P
_⊈_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊈ Q = ¬ (P ⊆ Q)
_⊉_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊉ Q = ¬ (P ⊇ Q)
_⊂_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊂ Q = P ⊆ Q × Q ⊈ P
_⊃_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊃ Q = Q ⊂ P
_⊄_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊄ Q = ¬ (P ⊂ Q)
_⊅_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⊅ Q = ¬ (P ⊃ Q)
------------------------------------------------------------------------
-- Properties of sets
infix 10 Satisfiable Universal IUniversal
-- Emptiness - no element satisfies P.
Empty : Pred A ℓ → Type _
Empty P = ∀ x → x ∉ P
-- Satisfiable - at least one element satisfies P.
Satisfiable : Pred A ℓ → Type _
Satisfiable {A = A} P = ∃[ x ∈ A ] x ∈ P
syntax Satisfiable P = ∃⟨ P ⟩
-- Universality - all elements satisfy P.
Universal : Pred A ℓ → Type _
Universal P = ∀ x → x ∈ P
syntax Universal P = Π[ P ]
-- Implicit universality - all elements satisfy P.
IUniversal : Pred A ℓ → Type _
IUniversal P = ∀ {x} → x ∈ P
syntax IUniversal P = ∀[ P ]
-- Decidability - it is possible to determine if an arbitrary element
-- satisfies P.
Decidable : Pred A ℓ → Type _
Decidable P = ∀ x → Dec (x ∈ P)
-- Disjointness - Any element satifsying both P and Q is contradictory.
_⊃⊂_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
_⊃⊂_ P Q = ∀ {x} → x ∈ P → x ∈ Q → ⊥
-- Positive version of non-disjointness, dual to inclusion.
_≬_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
_≬_ {A = A} P Q = ∃[ x ∈ A ] x ∈ P × x ∈ Q
------------------------------------------------------------------------
-- Operations on sets
infix 10 ⋃ ⋂
infixr 9 _⊢_ _⊣_
infixr 8 _⇒_
infixr 7 _∩_
infixr 6 _∪_
infix 5 _≬_
-- Complement.
∁ : Pred A ℓ → Pred A ℓ
∁ P = λ x → L.¬ P x
-- Implication.
_⇒_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ⇒ Q = λ x → P x L.⇒ Q x
-- Union.
_∪_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∪ Q = λ x → P x L.⊔ Q x
-- Intersection.
_∩_ : Pred A ℓ₁ → Pred A ℓ₂ → Pred A _
P ∩ Q = λ x → P x L.⊓ Q x
-- Infinitary union.
⋃ : ∀ {i} (I : Type i) → (I → Pred A ℓ) → Pred A _
⋃ I P = λ x → L.∃[ i ∶ I ] P i x
syntax ⋃ I (λ i → P) = ⋃[ i ∶ I ] P
-- Infinitary intersection.
⋂ : ∀ {i} (I : Type i) → (I → Pred A ℓ) → Pred A _
⋂ I P = λ x → ((i : I) → x ∈ P i) , isPropΠ λ i → isProp[ P i ] x
syntax ⋂ I (λ i → P) = ⋂[ i ∶ I ] P
-- Preimage.
_⊢_ : (A → B) → Pred B ℓ → Pred A ℓ
f ⊢ P = λ x → P (f x)
-- Image.
_⊣_ : (A → B) → Pred A ℓ → Pred B _
f ⊣ P = λ x → L.∥ Σ[ (y , _) ∈ Σ _ (_∈ P) ] (f y ≡ x) ∥ₚ
------------------------------------------------------------------------
-- Preservation under operations
_Preserves_⟶_ : (A → B) → Pred A ℓ₁ → Pred B ℓ₂ → Type _
f Preserves P ⟶ Q = P ⊆ f ⊢ Q
_Preserves_ : (A → A) → Pred A ℓ → Type _
f Preserves P = f Preserves P ⟶ P
-- A binary variant of _Preserves_⟶_.
_Preserves₂_⟶_⟶_ : (A → B → C) → Pred A ℓ₁ → Pred B ℓ₂ → Pred C ℓ → Type _
_∙_ Preserves₂ P ⟶ Q ⟶ R = ∀ {x y} → x ∈ P → y ∈ Q → x ∙ y ∈ R
_Preserves₂_ : (A → A → A) → Pred A ℓ → Type _
_∙_ Preserves₂ P = _∙_ Preserves₂ P ⟶ P ⟶ P
------------------------------------------------------------------------
-- Logical equivalence
infix 8 _⇔_ _⇚⇛_
_⇔_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⇔ Q = P ⊆ Q × P ⊇ Q
-- Direct logical equivalence (more useful for proofs)
_⇚⇛_ : Pred A ℓ₁ → Pred A ℓ₂ → Type _
P ⇚⇛ Q = ∀ x → x ∈ P ≃ x ∈ Q
module _ (P : Pred A ℓ₁) (Q : Pred A ℓ₂) where
⇔-⇚⇛ : P ⇔ Q → P ⇚⇛ Q
⇔-⇚⇛ (P⊆Q , Q⊆P) x = isPropEquiv→Equiv (P x .snd) (Q x .snd) P⊆Q Q⊆P
⇚⇛-⇔ : P ⇚⇛ Q → P ⇔ Q
⇚⇛-⇔ P⇚⇛Q = equivFun (P⇚⇛Q _) , invEq (P⇚⇛Q _)
equiv≃ : P ⇔ Q ≃ P ⇚⇛ Q
equiv≃ = isPropEquiv→Equiv (isProp× (isPropImplicitΠ λ _ → isPropΠ λ _ → (Q _ .snd)) (isPropImplicitΠ λ _ → isPropΠ λ _ → (P _ .snd)))
(isPropΠ λ _ → isPropΣ (isPropΠ λ _ → Q _ .snd) (λ _ → isPropIsEquiv _)) ⇔-⇚⇛ ⇚⇛-⇔
equiv≡ : _⇔_ ≡ _⇚⇛_ {ℓ₁} {A} {ℓ₂} {ℓ}
equiv≡ = funExt (λ P → funExt (λ Q → ua (equiv≃ P Q)))
module _ (P Q : Pred A ℓ) where
⇚⇛toPath : P ⇚⇛ Q → P ≡ Q
⇚⇛toPath P⇚⇛Q = funExt (λ x → L.hProp≡ (ua (P⇚⇛Q x)))
⇔toPath : P ⇔ Q → P ≡ Q
⇔toPath P⇔Q = ⇚⇛toPath (⇔-⇚⇛ P Q P⇔Q)
------------------------------------------------------------------------
-- Predicate combinators
-- These differ from the set operations above, as the carrier set of the
-- resulting predicates are not the same as the carrier set of the
-- component predicates.
infixr 2 _⟨×⟩_
infixr 2 _⟨⊙⟩_
infixr 1 _⟨⊎⟩_
infixr 0 _⟨→⟩_
infixl 9 _⟨·⟩_
infix 10 _~
infixr 9 _⟨∘⟩_
infixr 2 _//_ _\\_
-- Product.
_⟨×⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨×⟩ Q) (x , y) = P x L.⊓ Q y
-- Sum over one element.
_⟨⊎⟩_ : Pred A ℓ → Pred B ℓ → Pred (A ⊎ B) _
P ⟨⊎⟩ Q = rec P Q
-- Sum over two elements.
_⟨⊙⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A × B) _
(P ⟨⊙⟩ Q) (x , y) = P x L.⊔ Q y
-- Implication.
_⟨→⟩_ : Pred A ℓ₁ → Pred B ℓ₂ → Pred (A → B) _
(P ⟨→⟩ Q) f = (∀ {x} → x ∈ P → f x ∈ Q) , isPropImplicitΠ λ _ → isPropΠ
λ _ → isProp[ Q ] _
-- Product.
_⟨·⟩_ : (P : Pred A ℓ₁) (Q : Pred B ℓ₂) →
(P ⟨×⟩ (P ⟨→⟩ Q)) ⊆ uncurry (flip _$_) ⊢ Q
(P ⟨·⟩ Q) (p , f) = f p
-- Converse.
_~ : Pred (A × B) ℓ → Pred (B × A) ℓ
P ~ = P ∘ λ { (x , y) → y , x }
-- Composition.
_⟨∘⟩_ : Pred (A × B) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × C) _
_⟨∘⟩_ {B = B} P Q (x , z) = L.∃[ y ∶ B ] P (x , y) L.⊓ Q (y , z)
-- Post-division.
_//_ : Pred (A × C) ℓ₁ → Pred (B × C) ℓ₂ → Pred (A × B) _
(P // Q) (x , y) = (∀ {z} → (y , z) ∈ Q → (x , z) ∈ P) ,
isPropImplicitΠ λ _ → isPropΠ
λ _ → isProp[ P ] _
-- Pre-division.
_\\_ : Pred (A × C) ℓ₁ → Pred (A × B) ℓ₂ → Pred (B × C) _
P \\ Q = (P ~ // Q ~) ~
| {
"alphanum_fraction": 0.5062865679,
"avg_line_length": 23.6264705882,
"ext": "agda",
"hexsha": "ff3e84eb9e5a29161c3fdc1befac247d54c0610a",
"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/Unary.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/Unary.agda",
"max_line_length": 136,
"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/Unary.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 3332,
"size": 8033
} |
{-# OPTIONS --safe --warning=error #-}
open import Boolean.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import LogicalFormulae
open import Logic.PropositionalLogic
open import Functions.Definition
open import Numbers.Naturals.Order
open import Vectors
module Logic.PropositionalLogicExamples where
emptySubset : {a : _} (A : Set a) → IsSubset False A
emptySubset A = record { ofElt = λ () }
emptyEntailment : {a b : _} {A : Set a} {P : Propositions A} → Entails (emptySubset (Propositions A)) P → Tautology P
emptyEntailment {a} {b} {A} {P} entails v = entails {v} λ {s} → exFalso s
emptyEntailment' : {a b : _} {A : Set a} {P : Propositions A} → Tautology P → Entails (emptySubset (Propositions A)) P
emptyEntailment' isTaut {v} _ = isTaut v
data TwoElements : Set where
One : TwoElements
Two : TwoElements
twoElementSubset : {a : _} {A : Set a} → {P Q R : Propositions A} → TwoElements → Propositions A
twoElementSubset {P = P} {Q} {R} One = implies P Q
twoElementSubset {P = P} {Q} {R} Two = implies Q R
twoElementSubsetInj : {a : _} {A : Set a} {P Q R : Propositions A} → (P ≡ Q → False) → Injection (twoElementSubset {P = P} {Q} {R})
twoElementSubsetInj {P = P} {Q} {R} p!=q {One} {One} refl = refl
twoElementSubsetInj {P = P} {Q} {R} p!=q {One} {Two} pr with impliesInjective pr
twoElementSubsetInj {P = P} {Q} {R} p!=q {One} {Two} pr | fst ,, snd = exFalso (p!=q fst)
twoElementSubsetInj {P = P} {Q} {R} p!=q {Two} {One} pr with impliesInjective pr
twoElementSubsetInj {P = P} {Q} {R} p!=q {Two} {One} pr | fst ,, snd = exFalso (p!=q (equalityCommutative fst))
twoElementSubsetInj {P = P} {Q} {R} p!=q {Two} {Two} refl = refl
badBool : BoolFalse ≡ BoolTrue → False
badBool ()
semanticEntailmentTransitive : {a : _} {A : Set a} {P Q R : Propositions A} → (p!=q : P ≡ Q → False) → Entails record { ofElt = twoElementSubset } (implies P R)
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr with inspect (Valuation.v v P)
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolTrue with≡ pT with inspect (Valuation.v v Q)
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolTrue with≡ pT | BoolTrue with≡ qT with inspect (Valuation.v v R)
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolTrue with≡ pT | BoolTrue with≡ qT | BoolTrue with≡ rT = Valuation.vImplicationT v rT
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolTrue with≡ pT | BoolTrue with≡ qT | BoolFalse with≡ rF = exFalso (badBool (transitivity (equalityCommutative (Valuation.vImplicationF v qT rF)) (pr {Two})))
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolTrue with≡ pT | BoolFalse with≡ qF = exFalso (badBool (transitivity (equalityCommutative (Valuation.vImplicationF v pT qF)) (pr {One})))
semanticEntailmentTransitive {P = P} {Q} {R} p!=q {v} pr | BoolFalse with≡ pF = Valuation.vImplicationVacuous v pF
-- Subset {p -> q, q -> r}
pQQR : {a : _} {A : Set a} {P Q R : Propositions A} → TwoElements → Propositions A
pQQR {P = P} {Q} {R} One = implies P Q
pQQR {P = P} {Q} {R} Two = implies Q R
pQQRSubsetInj : {a : _} {A : Set a} {P Q R : Propositions A} → (P ≡ Q → False) → Injection (pQQR {P = P} {Q} {R})
pQQRSubsetInj {P = P} {Q} {R} p!=q {One} {One} refl = refl
pQQRSubsetInj {P = P} {Q} {R} p!=q {One} {Two} pr with impliesInjective pr
pQQRSubsetInj {P = P} {Q} {R} p!=q {One} {Two} pr | p=q ,, _ = exFalso (p!=q p=q)
pQQRSubsetInj {P = P} {Q} {R} p!=q {Two} {One} pr with impliesInjective pr
pQQRSubsetInj {P = P} {Q} {R} p!=q {Two} {One} pr | q=p ,, _ = exFalso (p!=q (equalityCommutative q=p))
pQQRSubsetInj {P = P} {Q} {R} p!=q {Two} {Two} refl = refl
syntacticEntailmentExample : {a : _} {A : Set a} {P Q R : Propositions A} → (p!=q : P ≡ Q → False) → Proof propositionalAxioms (record { ofElt = pQQR {P = P} {Q} {R} }) 7
syntacticEntailmentExample {P = P} {Q} {R} p!=q = nextStep 6 (nextStep 5 (nextStep 4 (nextStep 3 (nextStep 2 (nextStep 1 (nextStep 0 empty (axiom (Two , record { one = P ; two = Q ; three = R }))) (given Two)) (axiom (One , ((implies Q R) ,, P)))) (modusPonens (record { element = implies (implies Q R) (implies P (implies Q R)) ; position = 0 ; pos<N = le 2 refl ; elementIsAt = refl }) (record { element = implies Q R ; position = 1 ; elementIsAt = refl ; pos<N = le 1 refl }) (implies P (implies Q R)) refl)) (modusPonens (record { element = implies (implies P (implies Q R)) (implies (implies P Q) (implies P R)) ; position = 3 ; pos<N = le 0 refl ; elementIsAt = refl }) (record { element = implies P (implies Q R) ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (implies (implies P Q) (implies P R)) refl)) (given One)) (modusPonens (record { element = implies (implies P Q) (implies P R) ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = refl }) (record { element = implies P Q ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (implies P R) refl)
pQQRProof : {a : _} {A : Set a} {P Q R : Propositions A} → (p!=q : P ≡ Q → False) → Proves propositionalAxioms (record { ofElt = pQQR {P = P} {Q} {R} }) (implies P R)
pQQRProof p!=q = record { n = 6 ; proof = syntacticEntailmentExample p!=q ; ofStatement = refl }
-- Subset {p}
pSubset : {a : _} {A : Set a} {P : Propositions A} → True → Propositions A
pSubset {P = P} record {} = implies P P
pSubsetInj : {a : _} {A : Set a} {P : Propositions A} → Injection (pSubset {P = P})
pSubsetInj {P = P} {record {}} {record {}} refl = refl
syntacticEntailmentPP : {a : _} {A : Set a} {P : Propositions A} → Proof propositionalAxioms record { ofElt = pSubset {P = P} } 5
syntacticEntailmentPP {P = P} = nextStep 4 (nextStep 3 (nextStep 2 (nextStep 1 (nextStep 0 empty (axiom (One , (P ,, (implies P P))))) (axiom (Two , record { one = P ; two = implies P P ; three = P }))) (modusPonens (record { element = implies (implies P (implies (implies P P) P)) (implies (implies P (implies P P)) (implies P P)) ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (record { element = implies P (implies (implies P P) P) ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = refl }) (implies (implies P (implies P P)) (implies P P)) refl)) (axiom (One , (P ,, P)))) (modusPonens (record { element = implies (implies P (implies P P)) (implies P P) ; position = 1 ; pos<N = succPreservesInequality (succIsPositive _) ; elementIsAt = refl }) (record { element = implies P (implies P P) ; position = 0 ; pos<N = succIsPositive _ ; elementIsAt = refl }) (implies P P) refl)
pImpliesP : {a : _} {A : Set a} {P : Propositions A} → Proves propositionalAxioms record { ofElt = pSubset {P = P} } (implies P P)
Proves.n (pImpliesP {P = P}) = 4
Proves.proof (pImpliesP {P = P}) = syntacticEntailmentPP {P = P}
Proves.ofStatement (pImpliesP {P = P}) = refl
| {
"alphanum_fraction": 0.6506889475,
"avg_line_length": 82.1927710843,
"ext": "agda",
"hexsha": "323e714f5dc2107b7c1fb468a8e732fe70489241",
"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": "Logic/PropositionalLogicExamples.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": "Logic/PropositionalLogicExamples.agda",
"max_line_length": 1122,
"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": "Logic/PropositionalLogicExamples.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": 2546,
"size": 6822
} |
{-# OPTIONS --type-in-type --guardedness #-}
module IO.Exts where
import IO.Primitive as Prim
open import Class.Monad
open import Class.Functor
open import Data.List
open import Data.Nat using (ℕ)
open import Data.String
open import Data.Sum
open import Data.Unit
open import Function
open import IO using (IO; run; readFiniteFile; lift)
open import IO.Instance
open import Level
private
variable
A : Set
{-#
FOREIGN GHC
import Data.Text
import System.CPUTime
import System.Environment
import System.Exit
import System.IO
import System.IO.Error
import System.Process
#-}
postulate
flushStdoutPrim : Prim.IO ⊤
getCPUTimePrim : Prim.IO ℕ
putStrErrPrim : String → Prim.IO ⊤
runShellCmdPrim : String → List String → Prim.IO String
catchIOErrorPrim : Prim.IO A → (String → Prim.IO A) → Prim.IO A
{-# COMPILE GHC flushStdoutPrim = hFlush stdout #-}
{-# COMPILE GHC getCPUTimePrim = getCPUTime #-}
{-# COMPILE GHC putStrErrPrim = hPutStr stderr . unpack #-}
{-# COMPILE GHC runShellCmdPrim = \ s t -> pack <$> (readProcess (unpack s) (fmap unpack t) "") #-} -- use haskell proc
{-# COMPILE GHC catchIOErrorPrim = \ _ a f -> catchIOError a (f . pack . show) #-}
flushStdout : IO ⊤
flushStdout = lift flushStdoutPrim
getCPUTime : IO ℕ
getCPUTime = lift getCPUTimePrim
putStrErr : String → IO ⊤
putStrErr s = lift (putStrErrPrim s)
runShellCmd : String → List String → IO String
runShellCmd s args = lift (runShellCmdPrim s args)
catchIOError : IO A → (String → IO A) → IO A
catchIOError a f = lift $ catchIOErrorPrim (run a) (run ∘ f)
readFiniteFileError : String → IO (String ⊎ String)
readFiniteFileError name =
catchIOError (inj₂ <$> readFiniteFile name) (return ∘ inj₁)
| {
"alphanum_fraction": 0.7194623027,
"avg_line_length": 26.734375,
"ext": "agda",
"hexsha": "72116caedcb03a2f85b8d0377b6536fc45798234",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-10-20T10:46:20.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-27T23:12:48.000Z",
"max_forks_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "WhatisRT/meta-cedille",
"max_forks_repo_path": "stdlib-exts/IO/Exts.agda",
"max_issues_count": 10,
"max_issues_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_issues_repo_issues_event_max_datetime": "2020-04-25T15:29:17.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-13T17:44:43.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "WhatisRT/meta-cedille",
"max_issues_repo_path": "stdlib-exts/IO/Exts.agda",
"max_line_length": 119,
"max_stars_count": 35,
"max_stars_repo_head_hexsha": "62fa6f36e4555360d94041113749bbb6d291691c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "WhatisRT/meta-cedille",
"max_stars_repo_path": "stdlib-exts/IO/Exts.agda",
"max_stars_repo_stars_event_max_datetime": "2021-10-12T22:59:10.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-13T07:44:50.000Z",
"num_tokens": 495,
"size": 1711
} |
{-# OPTIONS --no-qualified-instances #-}
open import Data.List
open import Relation.Unary
open import Relation.Ternary.Core
open import Relation.Ternary.Structures
open import Relation.Ternary.Structures.Syntax
import JVM.Printer.Printer as Printer
import JVM.Model as Model
module JVM.Syntax.Bytecode.Printer {ℓ T}
(⟨_⇒_⟩ : T → T → List T → Set ℓ)
(let open Model T)
(let open Printer T)
(print : ∀ {τ₁ τ₂} → ∀[ Down ⟨ τ₁ ⇒ τ₂ ⟩ ⇒ Printer Emp ] ) where
open import JVM.Syntax.Bytecode T ⟨_⇒_⟩
open import Relation.Binary.PropositionalEquality
open import Relation.Ternary.Data.ReflexiveTransitive
open import Relation.Ternary.Monad
{-# TERMINATING #-}
pretty : ∀ {ψ₁ ψ₂} → ∀[ ⟪ ψ₁ ↝ ψ₂ ⟫ ⇒ Printer Emp ]
pretty nil = do
return refl
pretty (instr i ▹⟨ σ ⟩ is) = do
is ← ✴-id⁻ʳ ⟨$⟩ (print i &⟨ ⟪ _ ↝ _ ⟫ # ∙-comm σ ⟩ is)
pretty is
pretty (labeled l∙i ▹⟨ σ₂ ⟩ is) = do
let l ∙⟨ σ ⟩ i∙is = ✴-assocᵣ (l∙i ∙⟨ σ₂ ⟩ is)
i ∙⟨ σ ⟩ is ← ✴-id⁻ʳ ⟨$⟩ (print-labels l &⟨ _ ✴ ⟪ _ ↝ _ ⟫ # ∙-comm σ ⟩ i∙is)
is ← ✴-id⁻ʳ ⟨$⟩ (print i &⟨ ∙-comm σ ⟩ is)
pretty is
| {
"alphanum_fraction": 0.6040744021,
"avg_line_length": 33.2058823529,
"ext": "agda",
"hexsha": "27c3d95380e65fc26b7c8a3c0ec13ef12763988e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-12-28T17:37:15.000Z",
"max_forks_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "ajrouvoet/jvm.agda",
"max_forks_repo_path": "src/JVM/Syntax/Bytecode/Printer.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"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": "ajrouvoet/jvm.agda",
"max_issues_repo_path": "src/JVM/Syntax/Bytecode/Printer.agda",
"max_line_length": 84,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "c84bc6b834295ac140ff30bfc8e55228efbf6d2a",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "ajrouvoet/jvm.agda",
"max_stars_repo_path": "src/JVM/Syntax/Bytecode/Printer.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-28T21:49:08.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-07T14:07:17.000Z",
"num_tokens": 438,
"size": 1129
} |
-- Discrete category over a type A
-- A must be an h-groupoid for the homs to be sets
{-# OPTIONS --safe #-}
module Cubical.Categories.Instances.Discrete where
open import Cubical.Categories.Category.Base
open import Cubical.Categories.Functor.Base
open import Cubical.Foundations.GroupoidLaws
open import Cubical.Foundations.HLevels
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Transport
private
variable
ℓ ℓC ℓC' : Level
open Category
-- Discrete category
DiscreteCategory : hGroupoid ℓ → Category ℓ ℓ
DiscreteCategory A .ob = A .fst
DiscreteCategory A .Hom[_,_] a a' = a ≡ a'
DiscreteCategory A .id = refl
DiscreteCategory A ._⋆_ = _∙_
DiscreteCategory A .⋆IdL f = sym (lUnit f)
DiscreteCategory A .⋆IdR f = sym (rUnit f)
DiscreteCategory A .⋆Assoc f g h = sym (assoc f g h)
DiscreteCategory A .isSetHom {x} {y} = A .snd x y
module _ {A : hGroupoid ℓ}
{C : Category ℓC ℓC'} where
open Functor
-- Functions f: A → ob C give functors F: DiscreteCategory A → C
DiscFunc : (fst A → ob C) → Functor (DiscreteCategory A) C
DiscFunc f .F-ob = f
DiscFunc f .F-hom {x} p = subst (λ z → C [ f x , f z ]) p (id C)
DiscFunc f .F-id {x} = substRefl {B = λ z → C [ f x , f z ]} (id C)
-- Preserves composition
DiscFunc f .F-seq {x} {y} p q =
let open Category C using () renaming (_⋆_ to _●_) in
let Hom[fx,f—] = (λ (w : A .fst) → C [ f x , f w ]) in
let Hom[fy,f—] = (λ (w : A .fst) → C [ f y , f w ]) in
let id-fx = id C {f x} in
let id-fy = id C {f y} in
let Fp = (subst Hom[fx,f—] (p) id-fx) in
subst Hom[fx,f—] (p ∙ q) id-fx ≡⟨ substComposite Hom[fx,f—] _ _ _ ⟩
subst Hom[fx,f—] (q) (Fp) ≡⟨ cong (subst _ q) (sym (⋆IdR C _)) ⟩
subst Hom[fx,f—] (q) (Fp ● id-fy) ≡⟨ substCommSlice _ _ (λ _ → Fp ●_) q _ ⟩
Fp ● (subst Hom[fy,f—] (q) id-fy) ∎
| {
"alphanum_fraction": 0.6104986877,
"avg_line_length": 34.0178571429,
"ext": "agda",
"hexsha": "8fff2527cb891245511bb02b9b9e9c8fed84c862",
"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": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Seanpm2001-web/cubical",
"max_forks_repo_path": "Cubical/Categories/Instances/Discrete.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "58f2d0dd07e51f8aa5b348a522691097b6695d1c",
"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": "Seanpm2001-web/cubical",
"max_issues_repo_path": "Cubical/Categories/Instances/Discrete.agda",
"max_line_length": 89,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9acdecfa6437ec455568be4e5ff04849cc2bc13b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "FernandoLarrain/cubical",
"max_stars_repo_path": "Cubical/Categories/Instances/Discrete.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:28:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:28:39.000Z",
"num_tokens": 707,
"size": 1905
} |
------------------------------------------------------------------------
-- The Agda standard library
--
-- A categorical view of Colist
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe --sized-types #-}
module Codata.Colist.Categorical where
open import Codata.Conat using (infinity)
open import Codata.Colist
open import Category.Functor
open import Category.Applicative
functor : ∀ {ℓ i} → RawFunctor {ℓ} (λ A → Colist A i)
functor = record { _<$>_ = map }
applicative : ∀ {ℓ i} → RawApplicative {ℓ} (λ A → Colist A i)
applicative = record
{ pure = replicate infinity
; _⊛_ = ap
}
| {
"alphanum_fraction": 0.5330261137,
"avg_line_length": 27.125,
"ext": "agda",
"hexsha": "d20ae27f768682d339315edaace2b65ffeb3f75d",
"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/Codata/Colist/Categorical.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/Colist/Categorical.agda",
"max_line_length": 72,
"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/Codata/Colist/Categorical.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": 159,
"size": 651
} |
-- Fixed on AIM XIV 2011-09-09 AA, UN
-- {-# OPTIONS -v tc.lhs.unify:50 #-}
module Issue292 where
data ⊥ : Set where
infix 3 ¬_
¬_ : Set → Set
¬ P = P → ⊥
infix 4 _≅_
data _≅_ {A : Set} (x : A) : ∀ {B : Set} → B → Set where
refl : x ≅ x
record Σ (A : Set) (B : A → Set) : Set where
constructor _,_
field
proj₁ : A
proj₂ : B proj₁
open Σ public
data Bool : Set where true false : Bool
data D : Bool -> Set where
tt : D true
ff : D false
P : Set -> Set
P S = Σ S (\s → s ≅ tt)
pbool : P (D true)
pbool = tt , refl
¬pbool2 : ¬ P (D false)
¬pbool2 ( ff , () )
-- Andreas, 2011-09-13 fix of fix: should work again
{- WAS: expected error
ff ≅ tt should be empty, but that's not obvious to me
when checking that the clause ¬pbool2 (ff , ()) has type
¬ P (D false)
-}
| {
"alphanum_fraction": 0.582278481,
"avg_line_length": 17.5555555556,
"ext": "agda",
"hexsha": "2ef0cc10a98e74390a5fa8f801b220633c38c2ed",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/succeed/Issue292.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/Issue292.agda",
"max_line_length": 56,
"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/succeed/Issue292.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": 301,
"size": 790
} |
{-# OPTIONS --universe-polymorphism #-}
module Categories.Bicategory.Helpers where
-- quite a bit of the code below is taken from Categories.2-Category
open import Data.Nat using (_+_)
open import Function using (flip)
open import Data.Product using (_,_; curry)
open import Categories.Category
open import Categories.Categories using (Categories)
import Categories.Functor
open import Categories.Terminal using (OneC; One; unit)
open import Categories.Object.Terminal using (module Terminal)
open import Categories.Bifunctor hiding (identityˡ; identityʳ; assoc) renaming (id to idF; _≡_ to _≡F_; _∘_ to _∘F_)
open import Categories.NaturalIsomorphism
open import Categories.NaturalTransformation using (NaturalTransformation) renaming (_≡_ to _≡ⁿ_; id to idⁿ)
open import Categories.Product using (Product; assocʳ; πˡ; πʳ)
module BicategoryHelperFunctors {o ℓ t e} (Obj : Set o) (_⇒_ : (A B : Obj) → Category ℓ t e)
(—⊗— : {A B C : Obj} → Bifunctor (B ⇒ C) (A ⇒ B) (A ⇒ C))
(id : {A : Obj} → Functor {ℓ} {t} {e} OneC (A ⇒ A)) where
open Terminal (One {ℓ} {t} {e})
_∘_ : {A B C : Obj} {L R : Category ℓ t e} → Functor L (B ⇒ C) → Functor R (A ⇒ B) → Bifunctor L R (A ⇒ C)
_∘_ {A} {B} {C} F G = reduce-× {D₁ = B ⇒ C} {D₂ = A ⇒ B} —⊗— F G
-- convenience!
module _⇒_ (A B : Obj) = Category (A ⇒ B)
open _⇒_ public using () renaming (Obj to _⇒₁_)
private module imp⇒ {X Y : Obj} = Category (X ⇒ Y)
open imp⇒ public using () renaming (_⇒_ to _⇒₂_; id to id₂; _∘_ to _•_; _≡_ to _≡₂_)
id₁ : ∀ {A} → A ⇒₁ A
id₁ {A} = Functor.F₀ (id {A}) unit
id₁₂ : ∀ {A} → id₁ {A} ⇒₂ id₁ {A}
id₁₂ {A} = id₂ {A = id₁ {A}}
infixr 9 _∘₁_
_∘₁_ : ∀ {A B C} → B ⇒₁ C → A ⇒₁ B → A ⇒₁ C
_∘₁_ = curry (Functor.F₀ —⊗—)
-- horizontal composition
infixr 9 _∘₂_
_∘₂_ : ∀ {A B C} {g g′ : B ⇒₁ C} {f f′ : A ⇒₁ B} (β : g ⇒₂ g′) (α : f ⇒₂ f′) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f′)
_∘₂_ = curry (Functor.F₁ —⊗—)
-- left whiskering
infixl 9 _◃_
_◃_ : ∀ {A B C} {g g′ : B ⇒₁ C} → g ⇒₂ g′ → (f : A ⇒₁ B) → (g ∘₁ f) ⇒₂ (g′ ∘₁ f)
β ◃ f = β ∘₂ id₂
-- right whiskering
infixr 9 _▹_
_▹_ : ∀ {A B C} (g : B ⇒₁ C) → {f f′ : A ⇒₁ B} → f ⇒₂ f′ → (g ∘₁ f) ⇒₂ (g ∘₁ f′)
g ▹ α = id₂ ∘₂ α
module Coherence
(identityˡ : {A B : Obj} → NaturalIsomorphism (id ∘ idF {C = A ⇒ B}) (πʳ {C = ⊤} {A ⇒ B}))
(identityʳ : {A B : Obj} → NaturalIsomorphism (idF {C = A ⇒ B} ∘ id) (πˡ {C = A ⇒ B}))
(assoc : {A B C D : Obj} → NaturalIsomorphism (idF ∘ —⊗—) ((—⊗— ∘ idF) ∘F assocʳ (C ⇒ D) (B ⇒ C) (A ⇒ B)) ) where
open Categories.NaturalTransformation.NaturalTransformation
-- left/right are inverted between in certain situations!
-- private so as to not clash with the ones in Bicategory itself
private
ρᵤ : {A B : Obj} (f : A ⇒₁ B) → (id₁ ∘₁ f) ⇒₂ f
ρᵤ f = η (NaturalIsomorphism.F⇒G identityˡ) (unit , f)
λᵤ : {A B : Obj} (f : A ⇒₁ B) → (f ∘₁ id₁) ⇒₂ f
λᵤ f = η (NaturalIsomorphism.F⇒G identityʳ) (f , unit)
α : {A B C D : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) (h : C ⇒₁ D) →
(h ∘₁ (g ∘₁ f)) ⇒₂ ((h ∘₁ g) ∘₁ f)
α f g h = η (NaturalIsomorphism.F⇒G assoc) (h , g , f)
-- Triangle identity. Look how closely it matches with the one on
-- http://ncatlab.org/nlab/show/bicategory
Triangle : {A B C : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) → Set e
Triangle f g = (g ▹ ρᵤ f) ≡₂ ((λᵤ g ◃ f) • (α f id₁ g))
-- Pentagon identity. Ditto.
Pentagon : {A B C D E : Obj} (f : A ⇒₁ B) (g : B ⇒₁ C) (h : C ⇒₁ D) (i : D ⇒₁ E) → Set e
Pentagon f g h i = ((α g h i ◃ f) • (α f (h ∘₁ g) i)) • (i ▹ α f g h) ≡₂ (α f g (i ∘₁ h) • α (g ∘₁ f) h i)
| {
"alphanum_fraction": 0.5578250069,
"avg_line_length": 41.1704545455,
"ext": "agda",
"hexsha": "c595b2b8a2a89196e67ed2a761fba4904b804cb6",
"lang": "Agda",
"max_forks_count": 23,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T13:50:56.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-05T13:03:09.000Z",
"max_forks_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "copumpkin/categories",
"max_forks_repo_path": "Categories/Bicategory/Helpers.agda",
"max_issues_count": 19,
"max_issues_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_issues_repo_issues_event_max_datetime": "2019-08-09T16:31:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-05-23T06:47:10.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "copumpkin/categories",
"max_issues_repo_path": "Categories/Bicategory/Helpers.agda",
"max_line_length": 120,
"max_stars_count": 98,
"max_stars_repo_head_hexsha": "36f4181d751e2ecb54db219911d8c69afe8ba892",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/categories",
"max_stars_repo_path": "Categories/Bicategory/Helpers.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-08T05:20:36.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-04-15T14:57:33.000Z",
"num_tokens": 1566,
"size": 3623
} |
-- Andreas, 2015-08-11, issue reported by Martin Stone Davis
-- {-# OPTIONS -v impossible:10 -v interaction.give:20 #-}
open import Data.AVL using (Tree; empty)
open import Data.Vec using (Vec)
open import Data.String using (String)
open import Relation.Binary using (StrictTotalOrder)
open import Data.Nat.Properties using (<-strictTotalOrder)
empty' : Tree (StrictTotalOrder.isStrictTotalOrder <-strictTotalOrder) (Vec String)
empty' = empty {!!}
-- ERROR WAS:
-- An internal error has occurred. Please report this as a bug.
-- Location of the error: src/full/Agda/TypeChecking/Monad/Trace.hs:56
-- Currently Agsy gives nothing, which is also a weird.
-- It does not report "No solutions found".
-- Somehow, some parts of the solution are not in scope, which might
-- give an internal error that is caught, causing Agsy to discard
-- the solution.
| {
"alphanum_fraction": 0.7485380117,
"avg_line_length": 37.1739130435,
"ext": "agda",
"hexsha": "0089be73fb0dd9e1eea983090ff17d6e60b33f6f",
"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": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "alhassy/agda",
"max_forks_repo_path": "test/lib-interaction/Issue1623.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/lib-interaction/Issue1623.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "6043e77e4a72518711f5f808fb4eb593cbf0bb7c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "alhassy/agda",
"max_stars_repo_path": "test/lib-interaction/Issue1623.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 212,
"size": 855
} |
{- Byzantine Fault Tolerant Consensus Verification in Agda, version 0.9.
Copyright (c) 2021, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://opensource.oracle.com/licenses/upl
-}
open import LibraBFT.Base.Types
import LibraBFT.Impl.Consensus.Network as Network
import LibraBFT.Impl.Consensus.RoundManager as RoundManager
open import LibraBFT.Impl.OBM.Logging.Logging
open import LibraBFT.ImplShared.Consensus.Types
open import LibraBFT.ImplShared.Util.Dijkstra.All
open import Optics.All
open import Util.Prelude
-- This module defines the handler for our implementation. For most message types, it does some
-- initial validation before passing the message on to the proper handlers.
module LibraBFT.Impl.IO.OBM.InputOutputHandlers where
epvv : LBFT (Epoch × ValidatorVerifier)
epvv = _,_ <$> gets (_^∙ rmSafetyRules ∙ srPersistentStorage ∙ pssSafetyData ∙ sdEpoch)
<*> gets (_^∙ rmEpochState ∙ esVerifier)
module handleProposal (now : Instant) (pm : ProposalMsg) where
step₀ : LBFT Unit
step₁ : Epoch → ValidatorVerifier → LBFT Unit
step₀ = do
(myEpoch , vv) ← epvv
step₁ myEpoch vv
step₁ myEpoch vv = do
case⊎D Network.processProposal {- {!!} -} pm myEpoch vv of λ where
(Left (Left e)) → logErr e
(Left (Right i)) → logInfo i
(Right _) → RoundManager.processProposalMsgM now pm
handleProposal : Instant → ProposalMsg → LBFT Unit
handleProposal = handleProposal.step₀
module handleVote (now : Instant) (vm : VoteMsg) where
step₀ : LBFT Unit
step₁ : Epoch → ValidatorVerifier → LBFT Unit
step₀ = do
(myEpoch , vv) ← epvv
step₁ myEpoch vv
step₁ myEpoch vv = do
case Network.processVote vm myEpoch vv of λ where
(Left (Left e)) → logErr e
(Left (Right i)) → logInfo i
(Right _) → RoundManager.processVoteMsgM now vm
abstract
handleVote = handleVote.step₀
handleVote≡ : handleVote ≡ handleVote.step₀
handleVote≡ = refl
handle : NodeId → NetworkMsg → Instant → LBFT Unit
handle _self msg now =
case msg of λ where
(P pm) → handleProposal now pm
(V vm) → handleVote now vm
(C cm) → pure unit -- We don't do anything with commit messages, they are just for defining Correctness.
| {
"alphanum_fraction": 0.7123585727,
"avg_line_length": 33.7941176471,
"ext": "agda",
"hexsha": "0db681b5d1b4ce0eab43f4b06b10ebf58d9f3dcf",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_forks_repo_licenses": [
"UPL-1.0"
],
"max_forks_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_forks_repo_path": "src/LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"UPL-1.0"
],
"max_issues_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_issues_repo_path": "src/LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda",
"max_line_length": 111,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a4674fc473f2457fd3fe5123af48253cfb2404ef",
"max_stars_repo_licenses": [
"UPL-1.0"
],
"max_stars_repo_name": "LaudateCorpus1/bft-consensus-agda",
"max_stars_repo_path": "src/LibraBFT/Impl/IO/OBM/InputOutputHandlers.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 644,
"size": 2298
} |
module DivMod where
-- From examples/simple-lib
open import Lib.Vec
open import Lib.Nat
open import Lib.Id
open import Lib.Logic
open import Lib.Fin
-- Certified implementation of division and modulo
module Direct where
data DivMod : Nat -> Nat -> Set where
dm : forall {b} q (r : Fin b) -> DivMod (toNat r + q * b) b
getQ : forall {a b} -> DivMod a b -> Nat
getQ (dm q _) = q
getR : forall {a b} -> DivMod a b -> Nat
getR (dm _ r) = toNat r
divModˢ : (a b : Nat) -> DivMod a (suc b)
divModˢ zero b = dm 0 zero
divModˢ (suc a) b with divModˢ a b
divModˢ (suc ._) b | dm q r with maxView r
divModˢ (suc ._) b | dm q .(fromNat b) | theMax
with toNat (fromNat b) | lem-toNat-fromNat b
... | .b | refl = dm {suc b} (suc q) zero
divModˢ (suc ._) b | dm q .(weaken i) | notMax i
with toNat (weaken i) | lem-toNat-weaken i
... | .(toNat i) | refl = dm q (suc i)
divMod : (a b : Nat){nz : NonZero b} -> DivMod a b
divMod a zero {}
divMod a (suc b) = divModˢ a b
-- Let's try the inductive version. Less obvious that this one is correct.
module Inductive where
data DivMod : Nat -> Nat -> Set where
dmZ : forall {b} (i : Fin b) -> DivMod (toNat i) b
dmS : forall {a b} -> DivMod a b -> DivMod (b + a) b
getQ : forall {a b} -> DivMod a b -> Nat
getQ (dmZ _) = 0
getQ (dmS d) = suc (getQ d)
getR : forall {a b} -> DivMod a b -> Nat
getR (dmZ r) = toNat r
getR (dmS d) = getR d
data BoundView (n : Nat) : Nat -> Set where
below : (i : Fin n) -> BoundView n (toNat i)
above : forall a -> BoundView n (n + a)
boundView : (a b : Nat) -> BoundView a b
boundView zero b = above b
boundView (suc a) zero = below zero
boundView (suc a) (suc b) with boundView a b
boundView (suc a) (suc .(toNat i)) | below i = below (suc i)
boundView (suc a) (suc .(a + k)) | above k = above k
data _≤_ : Nat -> Nat -> Set where
leqZ : forall {n} -> zero ≤ n
leqS : forall {n m} -> n ≤ m -> suc n ≤ suc m
≤-suc : forall {a b} -> a ≤ b -> a ≤ suc b
≤-suc leqZ = leqZ
≤-suc (leqS p) = leqS (≤-suc p)
plus-≤ : forall a {b c} -> a + b ≤ c -> b ≤ c
plus-≤ zero p = p
plus-≤ (suc a) (leqS p) = ≤-suc (plus-≤ a p)
≤-refl : forall {a} -> a ≤ a
≤-refl {zero} = leqZ
≤-refl {suc n} = leqS ≤-refl
-- Recursion over a bound on a (needed for termination).
divModˢ : forall {size} a b -> a ≤ size -> DivMod a (suc b)
divModˢ a b prf with boundView (suc b) a
divModˢ .(toNat r) b _ | below r = dmZ r
divModˢ .(suc b + k) b (leqS prf) | above k = dmS (divModˢ k b (plus-≤ b prf))
divMod : forall a b {nz : NonZero b} -> DivMod a b
divMod a zero {}
divMod a (suc b) = divModˢ a b ≤-refl
-- We ought to prove that the inductive version behaves the same as the
-- direct version... but that's more work than we're willing to spend.
open Inductive
_div_ : (a b : Nat){nz : NonZero b} -> Nat
_div_ a b {nz} = getQ (divMod a b {nz})
_mod_ : (a b : Nat){nz : NonZero b} -> Nat
_mod_ a b {nz} = getR (divMod a b {nz})
| {
"alphanum_fraction": 0.5758957655,
"avg_line_length": 30.396039604,
"ext": "agda",
"hexsha": "fa60f64646419a5aa865920524f3e50af2872fdf",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "larrytheliquid/agda",
"max_forks_repo_path": "examples/arith/DivMod.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "larrytheliquid/agda",
"max_issues_repo_path": "examples/arith/DivMod.agda",
"max_line_length": 80,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "477c8c37f948e6038b773409358fd8f38395f827",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "larrytheliquid/agda",
"max_stars_repo_path": "examples/arith/DivMod.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1221,
"size": 3070
} |
{-# OPTIONS -v 2 #-}
module Leftovers.Junk where
open import Data.Bool
open import Relation.Binary.PropositionalEquality
id : ∀ {X : Set} → X → X
id x = x
the : ∀ X → X → X
the X = id {X}
badEq :
let f = the (Bool -> Bool -> Bool) (λ x → λ {true → false ; false → true})
in f true ≡ f false
badEq = {!!} -- refl does not typecheck
goodEq :
let f = the (Bool -> Bool -> Bool) (λ x → id λ {true → false ; false → true})
in f true ≡ f false
goodEq = {!!}
| {
"alphanum_fraction": 0.5790598291,
"avg_line_length": 18.72,
"ext": "agda",
"hexsha": "d8c00a0d706b45b52b36e49a21dbfd3922e7ee27",
"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": "01b60b405009feaada181af175f019ceb89e42b2",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_forks_repo_path": "src/Leftovers/Junk.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_issues_repo_path": "src/Leftovers/Junk.agda",
"max_line_length": 79,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "01b60b405009feaada181af175f019ceb89e42b2",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "JoeyEremondi/AgdaLeftovers",
"max_stars_repo_path": "src/Leftovers/Junk.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 156,
"size": 468
} |
module Integer.Difference.Properties where
open import Data.Product as Σ
open import Data.Product.Relation.Pointwise.NonDependent
open import Data.Unit
open import Equality
open import Integer.Difference
open import Natural as ℕ using (ℕ; zero; suc)
open import Quotient as /
open import Relation.Binary
open import Syntax
open Equality.FunctionProperties
+-comm : Commutative {A = ℤ} _+_
+-comm =
⟦⟧-≗₂ uip _ _ λ where
(a – b) (c – d) →
cong ⟦_⟧ (cong₂ _–_ (⟨ ℕ.+-comm a c ⟩) (⟨ ℕ.+-comm d b ⟩))
+-identityˡ : LeftIdentity {A = ℤ} 0 _+_
+-identityˡ =
⟦⟧-≗ uip _ _ λ where
(a – b) →
cong (λ z → ⟦ a – z ⟧) ⟨ ℕ.+-identityʳ b ⟩
+-identityʳ : RightIdentity {A = ℤ} 0 _+_
+-identityʳ =
⟦⟧-≗ uip _ _ λ where
(a – b) →
cong (λ z → ⟦ z – b ⟧) ⟨ ℕ.+-identityʳ a ⟩
+-assoc : Associative {A = ℤ} _+_
+-assoc =
⟦⟧-≗₃ uip _ _
λ where
(a – b) (c – d) (e – f) →
cong ⟦_⟧ (cong₂ _–_ (sym (ℕ.+-assoc a _ _)) (ℕ.+-assoc f _ _))
| {
"alphanum_fraction": 0.5899280576,
"avg_line_length": 24.9487179487,
"ext": "agda",
"hexsha": "236350e5e7da8d87a297770766f564b57f3997a9",
"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": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "kcsmnt0/numbers",
"max_forks_repo_path": "src/Integer/Difference/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"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": "kcsmnt0/numbers",
"max_issues_repo_path": "src/Integer/Difference/Properties.agda",
"max_line_length": 70,
"max_stars_count": 9,
"max_stars_repo_head_hexsha": "67ea7b96228c592daf79e800ebe4a7c12ed7221e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "kcsmnt0/numbers",
"max_stars_repo_path": "src/Integer/Difference/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2020-01-16T07:16:26.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-05-20T01:29:41.000Z",
"num_tokens": 393,
"size": 973
} |
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PullbackDef
-- We only consider the universal property internally to a fixed
-- universe [Set i]. If we don’t, we would have to consider an universe
-- polymorphic [P] and I don’t want to quantify over universe polymorphic things
module Homotopy.PullbackUP {i} (d : pullback-diag i)
(P : Set i → Set i) ⦃ PA : P (pullback-diag.A d) ⦄
⦃ PB : P (pullback-diag.B d) ⦄ ⦃ PC : P (pullback-diag.C d) ⦄ where
open pullback-diag d
record cone (top : Set i) : Set i where
constructor _,_,_
field
top→A : top → A
top→B : top → B
h : (t : top) → f (top→A t) ≡ g (top→B t)
top→D : (top : Set i) → pullback-diag i
top→D top = diag (top → A), (top → B), (top → C), (λ h → f ◯ h), (λ h → g ◯ h)
pullback-to-cone : (top : Set i) → (pullback (top→D top) → cone top)
pullback-to-cone top (top→A , top→B , h) = (top→A , top→B , happly h)
cone-to-pullback : (top : Set i) → (cone top → pullback (top→D top))
cone-to-pullback top (a , b , h) = (a , b , funext h)
pullback-to-cone-equiv : (top : Set i) → is-equiv (pullback-to-cone top)
pullback-to-cone-equiv top = iso-is-eq _ (cone-to-pullback top)
(λ y → ap (λ u → _ , _ , u) (happly-funext _))
(λ x → ap (λ u → _ , _ , u) (funext-happly _))
cone-to-pullback-equiv : (top : Set i) → is-equiv (cone-to-pullback top)
cone-to-pullback-equiv top = iso-is-eq _ (pullback-to-cone top)
(λ x → ap (λ u → _ , _ , u) (funext-happly _))
(λ y → ap (λ u → _ , _ , u) (happly-funext _))
compose-cone-map : (D E : Set i) (Dcone : cone D)
→ ((f : E → D) → cone E)
compose-cone-map D E (top→A , top→B , h) f =
((top→A ◯ f) , (top→B ◯ f) , λ x → h (f x))
is-pullback : (D : Set i) ⦃ PD : P D ⦄ (Dcone : cone D) → Set _
is-pullback D Dcone = (E : Set i) ⦃ PE : P E ⦄
→ is-equiv (compose-cone-map D E Dcone)
| {
"alphanum_fraction": 0.5836933045,
"avg_line_length": 37.7959183673,
"ext": "agda",
"hexsha": "e23ccd2152a53abc3f7ab1217f1fd46416a88b25",
"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": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nicolaikraus/HoTT-Agda",
"max_forks_repo_path": "old/Homotopy/PullbackUP.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "939a2d83e090fcc924f69f7dfa5b65b3b79fe633",
"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": "nicolaikraus/HoTT-Agda",
"max_issues_repo_path": "old/Homotopy/PullbackUP.agda",
"max_line_length": 80,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "f8fa68bf753d64d7f45556ca09d0da7976709afa",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "UlrikBuchholtz/HoTT-Agda",
"max_stars_repo_path": "old/Homotopy/PullbackUP.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": 717,
"size": 1852
} |
{-# OPTIONS --cubical --safe #-}
module BCK where
open import Prelude hiding (B; C)
infixl 4 _$$_
data BCK : Type where
_$$_ : BCK → BCK → BCK
B C K : BCK
open import Data.List
stack : BCK → Maybe BCK
stack xs = go xs []
where
go : BCK → List BCK → Maybe BCK
go (f $$ x) xs = go f (x ∷ xs)
go B (f ∷ g ∷ x ∷ xs) = just (foldl _$$_ (f $$ (g $$ x)) xs)
go C (f ∷ x ∷ y ∷ xs) = just (foldl _$$_ (f $$ y $$ x) xs)
go K (x ∷ y ∷ xs) = just (foldl _$$_ x xs)
go _ _ = nothing
| {
"alphanum_fraction": 0.528340081,
"avg_line_length": 20.5833333333,
"ext": "agda",
"hexsha": "3178f22185ab1c2035e1a7dd129a26bbfe224bfb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "BCK.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "BCK.agda",
"max_line_length": 62,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "BCK.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-16T08:11:34.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-09-11T17:45:41.000Z",
"num_tokens": 205,
"size": 494
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.