Search is not available for this dataset
text
string | meta
dict |
---|---|
{-# OPTIONS --without-K #-}
open import Base
open import Homotopy.PushoutDef
module Homotopy.PushoutUP {m} (D : pushout-diag m) (P : Set m → Set m)
⦃ PA : P (pushout-diag.A D) ⦄ ⦃ PB : P (pushout-diag.B D) ⦄
⦃ PC : P (pushout-diag.C D) ⦄ where
open pushout-diag D
-- Idea : [cocone E = (A → E) ×_(C → E) (B → E)]
record cocone (top : Set m) : Set m where
constructor _,_,_
field
A→top : A → top
B→top : B → top
h : (c : C) → (A→top (f c)) ≡ (B→top (g c))
open cocone public
cocone-eq-raw : (top : Set m) {a1 a2 : A → top} {b1 b2 : B → top}
{h1 : (c : C) → a1 (f c) ≡ b1 (g c)} {h2 : (c : C) → a2 (f c) ≡ b2 (g c)}
(p1 : a1 ≡ a2) (p2 : b1 ≡ b2) (p3 : transport _ p1 (transport _ p2 h1) ≡ h2)
→ (a1 , b1 , h1) ≡ (a2 , b2 , h2)
cocone-eq-raw top refl refl refl = refl
cocone-eq : (top : Set m) {a1 a2 : A → top} {b1 b2 : B → top}
{h1 : (c : C) → a1 (f c) ≡ b1 (g c)} {h2 : (c : C) → a2 (f c) ≡ b2 (g c)}
(p1 : a1 ≡ a2) (p2 : b1 ≡ b2)
(p3 : (c : C) → happly p1 (f c) ∘ h2 c ≡ h1 c ∘ happly p2 (g c))
→ (a1 , b1 , h1) ≡ (a2 , b2 , h2)
cocone-eq top refl refl p3 =
cocone-eq-raw top refl refl
(funext (λ c → ! (refl-right-unit _) ∘ ! (p3 c)))
open import Homotopy.PullbackDef
D→top : (top : Set m) → pullback-diag m
D→top top = diag (A → top) , (B → top) , (C → top)
, (λ u → u ◯ f) , (λ u → u ◯ g)
cocone-to-pullback : (top : Set m) → cocone top → pullback (D→top top)
cocone-to-pullback top (a , b , h) = (a , b , funext h)
pullback-to-cocone : (top : Set m)
→ pullback (D→top top)
→ cocone top
pullback-to-cocone top (a , b , h) = (a , b , happly h)
cocone-equiv-pullback : (top : Set m) → cocone top ≃ pullback (D→top top)
cocone-equiv-pullback top = (cocone-to-pullback top
, iso-is-eq _
(pullback-to-cocone top)
(λ p → ap (λ u → _ , _ , u) (funext-happly _))
(λ c → ap (λ u → _ , _ , u) (happly-funext _)))
pullback-equiv-cocone : (top : Set m) → pullback (D→top top) ≃ cocone top
pullback-equiv-cocone top = (pullback-to-cocone top
, iso-is-eq _
(cocone-to-pullback top)
(λ c → ap (λ u → _ , _ , u) (happly-funext _))
(λ p → ap (λ u → _ , _ , u) (funext-happly _)))
compose-cocone-map : (D E : Set m) (Dcocone : cocone D)
→ ((f : D → E) → cocone E)
compose-cocone-map D E (A→top , B→top , h) f =
((f ◯ A→top) , (f ◯ B→top) , (λ c → ap f (h c)))
is-pushout : (D : Set m) ⦃ PD : P D ⦄ (Dcocone : cocone D) → Set _
is-pushout D Dcocone = (E : Set m) ⦃ PE : P E ⦄
→ is-equiv (compose-cocone-map D E Dcocone)
compose-cocone-map-compose : (D E F : Set m) (Dcocone : cocone D) (f : D → E)
(g : E → F)
→ compose-cocone-map E F (compose-cocone-map D E Dcocone f) g
≡ compose-cocone-map D F Dcocone (g ◯ f)
compose-cocone-map-compose D E F Dcocone f g =
ap (λ u → ((g ◯ (f ◯ cocone.A→top Dcocone))
, (g ◯ (f ◯ cocone.B→top Dcocone)) , u))
(funext (λ c → compose-ap g f (cocone.h Dcocone c)))
module _ (D : Set m) ⦃ PD : P D ⦄ (Dcocone : cocone D)
(Dpushout : is-pushout D Dcocone) (E : Set m) ⦃ PE : P E ⦄
(Ecocone : cocone E) (Epushout : is-pushout E Ecocone) where
private
DE-eq : (D → E) ≃ cocone E
DE-eq = (compose-cocone-map D E Dcocone , Dpushout E)
ED-eq : (E → D) ≃ cocone D
ED-eq = (compose-cocone-map E D Ecocone , Epushout D)
DD-eq : (D → D) ≃ cocone D
DD-eq = (compose-cocone-map D D Dcocone , Dpushout D)
EE-eq : (E → E) ≃ cocone E
EE-eq = (compose-cocone-map E E Ecocone , Epushout E)
D→E : D → E
D→E = (DE-eq ⁻¹) ☆ Ecocone
E→D : E → D
E→D = (ED-eq ⁻¹) ☆ Dcocone
abstract
D→E→D : (λ x → E→D (D→E x)) ≡ (λ x → x)
D→E→D = equiv-is-inj (compose-cocone-map D D Dcocone , Dpushout D) _ _
(! (compose-cocone-map-compose D E D Dcocone D→E E→D)
∘ (ap (λ u → compose-cocone-map E D u E→D)
(inverse-right-inverse DE-eq Ecocone)
∘ (inverse-right-inverse ED-eq Dcocone
∘ ap (λ u → _ , _ , u) (funext (λ c → ! (ap-id _))))))
E→D→E : (λ x → D→E (E→D x)) ≡ (λ x → x)
E→D→E = equiv-is-inj (compose-cocone-map E E Ecocone , Epushout E) _ _
(! (compose-cocone-map-compose E D E Ecocone E→D D→E)
∘ (ap (λ u → compose-cocone-map D E u D→E)
(inverse-right-inverse ED-eq Dcocone)
∘ (inverse-right-inverse DE-eq Ecocone
∘ ap (λ u → _ , _ , u) (funext (λ c → ! (ap-id _))))))
pushout-equiv-pushout : D ≃ E
pushout-equiv-pushout = (D→E , iso-is-eq _ E→D (happly E→D→E) (happly D→E→D))
|
{
"alphanum_fraction": 0.53730352,
"avg_line_length": 36.4274193548,
"ext": "agda",
"hexsha": "04b4746d05a3bd121add166430251177730bc9f5",
"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/PushoutUP.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/PushoutUP.agda",
"max_line_length": 79,
"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/Homotopy/PushoutUP.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": 1913,
"size": 4517
}
|
open import Categories
open import Monads
module Monads.CatofAdj.TermAdjObj {a b}{C : Cat {a}{b}}(M : Monad C) where
open import Library
open import Functors
open import Naturals
open import Adjunctions
open import Monads.CatofAdj M
open import Categories.Terminal
open import Monads.EM M
open import Monads.EM.Adjunction M
open import Adjunctions.Adj2Mon
open Cat
open Fun
open Monad M
open NatT
open Adj
lemX : R EMAdj ○ L EMAdj ≅ TFun M
lemX = FunctorEq _ _ refl refl
EMObj : Obj CatofAdj
EMObj = record {
D = EM;
adj = EMAdj;
law = lemX;
ηlaw = idl C;
bindlaw = λ{X Y f} →
cong bind
(stripsubst (Hom C X) f (fcong Y (cong OMap (sym lemX))))}
open ObjAdj
open Adj
alaw1lem : ∀{c d}{D : Cat {c}{d}}
(T : Fun C C)(L : Fun C D)(R : Fun D C)
(p : R ○ L ≅ T)
(η : ∀ {X} → Hom C X (OMap T X)) →
(right : ∀ {X Y} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(left : ∀ {X Y} → Hom D (OMap L X) Y → Hom C X (OMap R Y)) →
(ηlaw : ∀ {X} → left (iden D {OMap L X}) ≅ η {X}) →
∀ {X}{Z}{f : Hom C Z (OMap R X)} →
(nat : comp C (HMap R (right f)) (comp C (left (iden D)) (iden C))
≅
left (comp D (right f) (comp D (iden D) (HMap L (iden C))))) →
(lawb : left (right f) ≅ f) →
f
≅
comp C (subst (λ Z₁ → Hom C Z₁ (OMap R X))
(fcong Z (cong OMap p))
(HMap R (right f)))
η
alaw1lem {D = D} .(R ○ L) L R refl η right left ηlaw {X}{Z}{f} nat lawb =
trans (trans (trans (sym lawb)
(cong left
(trans (sym (idr D))
(cong (comp D (right f))
(trans (sym (fid L))
(sym (idl D)))))))
(trans (sym nat)
(cong (comp C (HMap R (right f)))
(idr C))))
(cong (comp C (HMap R (right f))) ηlaw)
alaw2lem : ∀{c d}{D : Cat {c}{d}}
(T : Fun C C)(L : Fun C D)(R : Fun D C)
(p : R ○ L ≅ T) →
(right : ∀ {X Y} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(bind : ∀ {X Y} → Hom C X (OMap T Y) → Hom C (OMap T X) (OMap T Y)) →
(natright : {X₁ X' : Obj C} {Y Y' : Obj D} (f₁ : Hom C X' X₁)
(g : Hom D Y Y') (h : Hom C X₁ (OMap R Y)) →
right (comp C (HMap R g) (comp C h f₁))
≅
comp D g (comp D (right h) (HMap L f₁))) →
∀ {X}{Z} {W} {k : Hom C Z (OMap T W)}{f : Hom C W (OMap R X)} →
(bindlaw : HMap R (right (subst (Hom C Z) (fcong W (cong OMap (sym p))) k))
≅ bind k) →
subst (λ Z → Hom C Z (OMap R X))
(fcong Z (cong OMap p))
(HMap R
(right
(comp C
(subst (λ Z → Hom C Z (OMap R X))
(fcong W (cong OMap p)) (HMap R (right f)))
k)))
≅
comp C
(subst (λ Z → Hom C Z (OMap R X))
(fcong W (cong OMap p)) (HMap R (right f)))
(bind k)
alaw2lem {D = D} .(R ○ L) L R refl right bind natright {X}{Z}{W}{k}{f} bindlaw =
trans (trans (cong (HMap R)
(trans (cong (λ k₁ → right (comp C (HMap R (right f)) k₁))
(sym (idr C)))
(trans (natright (iden C) (right f) k)
(trans (cong (λ h → comp D
(right f)
(comp D
(right k)
h))
(fid L))
(trans (sym (ass D))
(idr D))))))
(fcomp R))
(cong (comp C (HMap R (right f))) bindlaw)
ahomlem : ∀{c d}{D : Cat {c}{d}}
(T : Fun C C)(L : Fun C D)(R : Fun D C)(p : R ○ L ≅ T) →
(right : ∀ {X Y} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(natright : {X₁ X' : Obj C} {Y Y' : Obj D} (f₁ : Hom C X' X₁)
(g : Hom D Y Y') (h : Hom C X₁ (OMap R Y)) →
right (comp C (HMap R g) (comp C h f₁))
≅
comp D g (comp D (right h) (HMap L f₁))) →
{X : Obj D}{Y : Obj D}{f : Hom D X Y} →
{Z : Obj C} {f₁ : Hom C Z (OMap R X)} →
comp C (HMap R f)
(subst (λ Z₁ → Hom C Z₁ (OMap R X))
(fcong Z (cong OMap p))
(HMap R (right f₁)))
≅
subst (λ Z₁ → Hom C Z₁ (OMap R Y))
(fcong Z (cong OMap p))
(HMap R (right (comp C (HMap R f) f₁)))
ahomlem {D = D} .(R ○ L) L R refl right natright {X}{Y}{f}{Z}{g} =
trans (sym (fcomp R))
(cong (HMap R)
(sym
(trans (cong (λ g₁ → right (comp C (HMap R f) g₁)) (sym (idr C)))
(trans (natright (iden C) f g)
(trans (cong (λ h → comp D f (comp D (right g) h)) (fid L))
(trans (sym (ass D)) (idr D)))))))
Llawlem : ∀{c d}{D : Cat {c}{d}}
(T : Fun C C)(L : Fun C D)(R : Fun D C)(p : R ○ L ≅ T) →
(right : ∀ {X Y} → Hom C X (OMap R Y) → Hom D (OMap L X) Y) →
(bind : ∀ {X Y} → Hom C X (OMap T Y) → Hom C (OMap T X) (OMap T Y)) →
(bindlaw : {X Y : Obj C} {f : Hom C X (OMap T Y)} →
HMap R
(right
(subst (Hom C X) (fcong Y (cong OMap (sym p))) f))
≅ bind f) →
∀{X Z} →
{f : Hom C Z (OMap R (OMap L X))}
{f' : Hom C Z (OMap T X)} → (q : f ≅ f') →
subst (λ Z₁ → Hom C Z₁ (OMap R (OMap L X)))
(fcong Z (cong OMap p)) (HMap R (right f))
≅ bind f'
Llawlem .(R ○ L) L R refl right bind bindlaw {X}{Z}{f}{.f} refl = bindlaw
|
{
"alphanum_fraction": 0.4359489051,
"avg_line_length": 35.1282051282,
"ext": "agda",
"hexsha": "fe1c90c4353df997cdefc5e1d7733a6d7ad77d20",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-11-04T21:33:13.000Z",
"max_forks_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "jmchapman/Relative-Monads",
"max_forks_repo_path": "Monads/CatofAdj/TermAdjObj.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_issues_repo_issues_event_max_datetime": "2019-05-29T09:50:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-13T13:12:33.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "jmchapman/Relative-Monads",
"max_issues_repo_path": "Monads/CatofAdj/TermAdjObj.agda",
"max_line_length": 80,
"max_stars_count": 21,
"max_stars_repo_head_hexsha": "74707d3538bf494f4bd30263d2f5515a84733865",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "jmchapman/Relative-Monads",
"max_stars_repo_path": "Monads/CatofAdj/TermAdjObj.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T18:02:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-07-30T01:25:12.000Z",
"num_tokens": 2096,
"size": 5480
}
|
{-# OPTIONS --without-K #-}
module NTypes.Product where
open import NTypes
open import PathOperations
open import PathStructure.Product
open import Types
×-isSet : ∀ {a b} {A : Set a} {B : Set b} →
isSet A → isSet B → isSet (A × B)
×-isSet A-set B-set x y p q
= split-eq p ⁻¹
· ap (λ y → ap₂ _,_ y (ap π₂ p))
(A-set _ _ (ap π₁ p) (ap π₁ q))
· ap (λ y → ap₂ _,_ (ap π₁ q) y)
(B-set _ _ (ap π₂ p) (ap π₂ q))
· split-eq q
where
split-eq : (p : x ≡ y) → ap₂ _,_ (ap π₁ p) (ap π₂ p) ≡ p
split-eq = π₂ (π₂ (π₂ split-merge-eq))
|
{
"alphanum_fraction": 0.5703839122,
"avg_line_length": 26.0476190476,
"ext": "agda",
"hexsha": "1db86558239b2c150e8a7127d080f1257080f47c",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/NTypes/Product.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/NTypes/Product.agda",
"max_line_length": 58,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/NTypes/Product.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 231,
"size": 547
}
|
{-# OPTIONS --without-K #-}
module sets.int.utils where
open import sum
open import equality
open import function
open import sets.nat.core
open import sets.int.definition
open import hott.level
module _ {i}{X : Set i}(hX : h 2 X)
(f : ℕ → ℕ → ℕ → ℕ → X)
(u : ∀ n n' d m m' e → f n n' m m' ≡ f (d + n) (d + n') (e + m) (e + m')) where
private
g : ℕ → ℕ → ℤ → X
g n n' = elim-ℤ hX (f n n' , u n n' 0)
lem : (n n' d m m' : ℕ) → g n n' (m [-] m') ≡ g (d + n) (d + n') (m [-] m')
lem n n' d m m' = u n n' d m m' 0
v : (n n' d : ℕ) → g n n' ≡ g (d + n) (d + n')
v n n' d = funext λ m → elim-prop-ℤ
(λ m → hX (g n n' m) (g (d + n) (d + n') m))
(lem n n' d) m
hX' : h 2 (ℤ → X)
hX' = Π-level λ _ → hX
elim₂-ℤ : ℤ → ℤ → X
elim₂-ℤ = elim-ℤ hX' (g , v)
elim₂-prop-ℤ : ∀ {i}{X : ℤ → ℤ → Set i} → (∀ n m → h 1 (X n m))
→ ((n n' m m' : ℕ) → X (n [-] n') (m [-] m'))
→ ∀ n m → X n m
elim₂-prop-ℤ {i}{X} hX f = elim-prop-ℤ hX' g
where
g : (n n' : ℕ) → ∀ m → X (n [-] n') m
g n n' = elim-prop-ℤ (hX (n [-] n')) (f n n')
hX' : ∀ n → h 1 (∀ m → X n m)
hX' n = Π-level λ m → hX n m
elim₃-prop-ℤ : ∀ {i}{X : ℤ → ℤ → ℤ → Set i} → (∀ n m p → h 1 (X n m p))
→ ((n n' m m' p p' : ℕ) → X (n [-] n') (m [-] m') (p [-] p'))
→ ∀ n m p → X n m p
elim₃-prop-ℤ {i}{X} hX f = elim-prop-ℤ hX' g
where
g : (n n' : ℕ) → ∀ m p → X (n [-] n') m p
g n n' = elim₂-prop-ℤ (hX (n [-] n')) (f n n')
hX' : ∀ n → h 1 (∀ m p → X n m p)
hX' n = Π-level λ m → Π-level λ p → hX n m p
|
{
"alphanum_fraction": 0.4006289308,
"avg_line_length": 28.9090909091,
"ext": "agda",
"hexsha": "c79988714b1e3b49fb174545a05e11b9850746f4",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2019-05-04T19:31:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-02-02T12:17:00.000Z",
"max_forks_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "pcapriotti/agda-base",
"max_forks_repo_path": "src/sets/int/utils.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_issues_repo_issues_event_max_datetime": "2016-10-26T11:57:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-02-02T14:32:16.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "pcapriotti/agda-base",
"max_issues_repo_path": "src/sets/int/utils.agda",
"max_line_length": 81,
"max_stars_count": 20,
"max_stars_repo_head_hexsha": "bbbc3bfb2f80ad08c8e608cccfa14b83ea3d258c",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "pcapriotti/agda-base",
"max_stars_repo_path": "src/sets/int/utils.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-01T11:25:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-06-12T12:20:17.000Z",
"num_tokens": 770,
"size": 1590
}
|
module Generic.Lib.Category where
open import Category.Functor public
open import Category.Applicative public
open import Category.Monad public
open RawFunctor {{...}} public
open RawApplicative {{...}} hiding (_<$>_; _<&>_; _<$_; zip; zipWith) renaming (_⊛_ to _<*>_) public
open RawMonad {{...}} hiding (pure; _<$>_; _<&>_; _<$_; _⊛_; _<⊛_; _⊛>_; _⊗_; rawFunctor; zip; zipWith) public
fmap = _<$>_
|
{
"alphanum_fraction": 0.6749379653,
"avg_line_length": 33.5833333333,
"ext": "agda",
"hexsha": "51d3a4883410207e356cc32bf8dd34dc9ac16859",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "turion/Generic",
"max_forks_repo_path": "src/Generic/Lib/Category.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "turion/Generic",
"max_issues_repo_path": "src/Generic/Lib/Category.agda",
"max_line_length": 110,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e102b0ec232f2796232bd82bf8e3906c1f8a93fe",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "turion/Generic",
"max_stars_repo_path": "src/Generic/Lib/Category.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 136,
"size": 403
}
|
module Issue4835.ModA where
data A : Set where
a : A -> A
|
{
"alphanum_fraction": 0.6557377049,
"avg_line_length": 12.2,
"ext": "agda",
"hexsha": "447b27a85e10e6807cad48883ac27b59f22673f6",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue4835/ModA.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue4835/ModA.agda",
"max_line_length": 27,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue4835/ModA.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": 21,
"size": 61
}
|
-- Andreas, 2014-12-03 Issue reported by Fabien Renaud
postulate A : Set
f : A → A
g : A → A
f x = g x
ok : A → A
ok x = x
g x = f x
-- Only `f` and `g` should be colored red, not `ok`.
|
{
"alphanum_fraction": 0.5647668394,
"avg_line_length": 11.3529411765,
"ext": "agda",
"hexsha": "381fe55c5b86ab7a6682d80b7209c68494ba7961",
"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/Issue1084.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/Issue1084.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Fail/Issue1084.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": 193
}
|
postulate
X Y Z A : Set
record R : Set where
field
x : X
y : Y
z : Z
module M where
postulate
x : X
y : Y
r : R
r = record { M; z = zz } where postulate zz : Z
-- Record update. Same as: record r { y = ... }
r2 : R
r2 = record { R r; y = y } where postulate y : Y
module M2 (a : A) where
postulate
w : Y
z : Z
r3 : A → R
r3 a = record { M hiding (y); M2 a renaming (w to y) }
|
{
"alphanum_fraction": 0.5278450363,
"avg_line_length": 14.2413793103,
"ext": "agda",
"hexsha": "6789e9365356d2194cd4612476e07ae0ce8e8e92",
"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/RecordFromModule2.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/RecordFromModule2.agda",
"max_line_length": 54,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Succeed/RecordFromModule2.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 163,
"size": 413
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- The reflexive transitive closures of McBride, Norell and Jansson
------------------------------------------------------------------------
-- This module could be placed under Relation.Binary. However, since
-- its primary purpose is to be used for _data_ it has been placed
-- under Data instead.
module Data.Star where
open import Relation.Binary
open import Function
open import Level
infixr 5 _◅_
-- Reflexive transitive closure.
data Star {i t} {I : Set i} (T : Rel I t) : Rel I (i ⊔ t) where
ε : Reflexive (Star T)
_◅_ : ∀ {i j k} (x : T i j) (xs : Star T j k) → Star T i k
-- The type of _◅_ is Trans T (Star T) (Star T); I expanded
-- the definition in order to be able to name the arguments (x
-- and xs).
-- Append/transitivity.
infixr 5 _◅◅_
_◅◅_ : ∀ {i t} {I : Set i} {T : Rel I t} → Transitive (Star T)
ε ◅◅ ys = ys
(x ◅ xs) ◅◅ ys = x ◅ (xs ◅◅ ys)
-- Sometimes you want to view cons-lists as snoc-lists. Then the
-- following "constructor" is handy. Note that this is _not_ snoc for
-- cons-lists, it is just a synonym for cons (with a different
-- argument order).
infixl 5 _▻_
_▻_ : ∀ {i t} {I : Set i} {T : Rel I t} {i j k} →
Star T j k → T i j → Star T i k
_▻_ = flip _◅_
-- A corresponding variant of append.
infixr 5 _▻▻_
_▻▻_ : ∀ {i t} {I : Set i} {T : Rel I t} {i j k} →
Star T j k → Star T i j → Star T i k
_▻▻_ = flip _◅◅_
-- A generalised variant of map which allows the index type to change.
gmap : ∀ {i j t u} {I : Set i} {T : Rel I t} {J : Set j} {U : Rel J u} →
(f : I → J) → T =[ f ]⇒ U → Star T =[ f ]⇒ Star U
gmap f g ε = ε
gmap f g (x ◅ xs) = g x ◅ gmap f g xs
map : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
T ⇒ U → Star T ⇒ Star U
map = gmap id
-- A generalised variant of fold.
gfold : ∀ {i j t p} {I : Set i} {J : Set j} {T : Rel I t}
(f : I → J) (P : Rel J p) →
Trans T (P on f) (P on f) →
TransFlip (Star T) (P on f) (P on f)
gfold f P _⊕_ ∅ ε = ∅
gfold f P _⊕_ ∅ (x ◅ xs) = x ⊕ gfold f P _⊕_ ∅ xs
fold : ∀ {i t p} {I : Set i} {T : Rel I t} (P : Rel I p) →
Trans T P P → Reflexive P → Star T ⇒ P
fold P _⊕_ ∅ = gfold id P _⊕_ ∅
gfoldl : ∀ {i j t p} {I : Set i} {J : Set j} {T : Rel I t}
(f : I → J) (P : Rel J p) →
Trans (P on f) T (P on f) →
Trans (P on f) (Star T) (P on f)
gfoldl f P _⊕_ ∅ ε = ∅
gfoldl f P _⊕_ ∅ (x ◅ xs) = gfoldl f P _⊕_ (∅ ⊕ x) xs
foldl : ∀ {i t p} {I : Set i} {T : Rel I t} (P : Rel I p) →
Trans P T P → Reflexive P → Star T ⇒ P
foldl P _⊕_ ∅ = gfoldl id P _⊕_ ∅
concat : ∀ {i t} {I : Set i} {T : Rel I t} → Star (Star T) ⇒ Star T
concat {T = T} = fold (Star T) _◅◅_ ε
-- If the underlying relation is symmetric, then the reflexive
-- transitive closure is also symmetric.
revApp : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
Sym T U → ∀ {i j k} → Star T j i → Star U j k → Star U i k
revApp rev ε ys = ys
revApp rev (x ◅ xs) ys = revApp rev xs (rev x ◅ ys)
reverse : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
Sym T U → Sym (Star T) (Star U)
reverse rev xs = revApp rev xs ε
-- Reflexive transitive closures form a (generalised) monad.
-- return could also be called singleton.
return : ∀ {i t} {I : Set i} {T : Rel I t} → T ⇒ Star T
return x = x ◅ ε
-- A generalised variant of the Kleisli star (flip bind, or
-- concatMap).
kleisliStar : ∀ {i j t u}
{I : Set i} {J : Set j} {T : Rel I t} {U : Rel J u}
(f : I → J) → T =[ f ]⇒ Star U → Star T =[ f ]⇒ Star U
kleisliStar f g = concat ∘′ gmap f g
_⋆ : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} →
T ⇒ Star U → Star T ⇒ Star U
_⋆ = kleisliStar id
infixl 1 _>>=_
_>>=_ : ∀ {i t u} {I : Set i} {T : Rel I t} {U : Rel I u} {i j} →
Star T i j → T ⇒ Star U → Star U i j
m >>= f = (f ⋆) m
-- Note that the monad-like structure above is not an indexed monad
-- (as defined in Category.Monad.Indexed). If it were, then _>>=_
-- would have a type similar to
--
-- ∀ {I} {T U : Rel I t} {i j k} →
-- Star T i j → (T i j → Star U j k) → Star U i k.
-- ^^^^^
-- Note, however, that there is no scope for applying T to any indices
-- in the definition used in Category.Monad.Indexed.
|
{
"alphanum_fraction": 0.5192481884,
"avg_line_length": 31.7697841727,
"ext": "agda",
"hexsha": "b85e442ff8e890e098d410149a2f21e4acf69c1f",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "qwe2/try-agda",
"max_forks_repo_path": "agda-stdlib-0.9/src/Data/Star.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "qwe2/try-agda",
"max_issues_repo_path": "agda-stdlib-0.9/src/Data/Star.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "9d4c43b1609d3f085636376fdca73093481ab882",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "qwe2/try-agda",
"max_stars_repo_path": "agda-stdlib-0.9/src/Data/Star.agda",
"max_stars_repo_stars_event_max_datetime": "2016-10-20T15:52:05.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-10-20T15:52:05.000Z",
"num_tokens": 1696,
"size": 4416
}
|
open import Data.Nat using (ℕ)
module Data.BitVector.Properties.LatticeProperties (n : ℕ) where
open import Data.BitVector
open import Algebra.Structures
open import Relation.Binary.PropositionalEquality
open import Data.Vec
open import Data.Product hiding (map)
import Data.Bool.Properties as Bool
private
module BitProperties = IsBooleanAlgebra Bool.isBooleanAlgebra
-- All these properties follow trivially from the bit properties. TODO: generalize the pattern to just reuse the bitproperties
∨-comm : ∀ {n} (x y : BitVector n) → bitwise-or x y ≡ bitwise-or y x
∨-comm [] [] = refl
∨-comm (x ∷ xs) (y ∷ ys) rewrite BitProperties.∨-comm x y | ∨-comm xs ys = refl
∧-comm : ∀ {n} (x y : BitVector n) → bitwise-and x y ≡ bitwise-and y x
∧-comm [] [] = refl
∧-comm (x ∷ xs) (y ∷ ys) rewrite BitProperties.∧-comm x y | ∧-comm xs ys = refl
∨-assoc : ∀ {n} (x y z : BitVector n) → bitwise-or (bitwise-or x y) z ≡ bitwise-or x (bitwise-or y z)
∨-assoc [] [] [] = refl
∨-assoc (x ∷ xs) (y ∷ ys) (z ∷ zs) rewrite BitProperties.∨-assoc x y z | ∨-assoc xs ys zs = refl
∧-assoc : ∀ {n} (x y z : BitVector n) → bitwise-and (bitwise-and x y) z ≡ bitwise-and x (bitwise-and y z)
∧-assoc [] [] [] = refl
∧-assoc (x ∷ xs) (y ∷ ys) (z ∷ zs) rewrite BitProperties.∧-assoc x y z | ∧-assoc xs ys zs = refl
∨∧-absorb : ∀ {n} (x y : BitVector n) → bitwise-or x (bitwise-and x y) ≡ x
∨∧-absorb [] [] = refl
∨∧-absorb (x ∷ xs) (y ∷ ys) rewrite proj₁ BitProperties.absorptive x y | ∨∧-absorb xs ys = refl
∧∨-absorb : ∀ {n} (x y : BitVector n) → bitwise-and x (bitwise-or x y) ≡ x
∧∨-absorb [] [] = refl
∧∨-absorb (x ∷ xs) (y ∷ ys) rewrite proj₂ BitProperties.absorptive x y | ∧∨-absorb xs ys = refl
∨-cong : ∀ {n} {x y u v : BitVector n} → x ≡ y → u ≡ v → bitwise-or x u ≡ bitwise-or y v
∨-cong refl refl = refl
∧-cong : ∀ {n} {x y u v : BitVector n} → x ≡ y → u ≡ v → bitwise-and x u ≡ bitwise-and y v
∧-cong refl refl = refl
isLattice : ∀ {n} → IsLattice _≡_ (bitwise-or {n}) bitwise-and
isLattice = record
{ isEquivalence = isEquivalence
; ∨-comm = ∨-comm
; ∨-assoc = ∨-assoc
; ∨-cong = ∨-cong
; ∧-comm = ∧-comm
; ∧-assoc = ∧-assoc
; ∧-cong = ∧-cong
; absorptive = ∨∧-absorb , ∧∨-absorb
}
∨∧-distribʳ : ∀ {n} (x y z : BitVector n) → bitwise-or (bitwise-and y z) x ≡ bitwise-and (bitwise-or y x) (bitwise-or z x)
∨∧-distribʳ [] [] [] = refl
∨∧-distribʳ (x ∷ xs) (y ∷ ys) (z ∷ zs) rewrite BitProperties.∨-∧-distribʳ x y z | ∨∧-distribʳ xs ys zs = refl
isDistributiveLattice : ∀ {n} → IsDistributiveLattice _≡_ (bitwise-or {n}) bitwise-and
isDistributiveLattice = record
{ isLattice = isLattice
; ∨-∧-distribʳ = ∨∧-distribʳ
}
∨-complementʳ : ∀ {n} (x : BitVector n) → bitwise-or x (bitwise-negation x) ≡ ones n
∨-complementʳ [] = refl
∨-complementʳ (x ∷ xs) rewrite BitProperties.∨-complementʳ x | ∨-complementʳ xs = refl
∧-complementʳ : ∀ {n} (x : BitVector n) → bitwise-and x (bitwise-negation x) ≡ zero n
∧-complementʳ [] = refl
∧-complementʳ (x ∷ xs) rewrite BitProperties.∧-complementʳ x | ∧-complementʳ xs = refl
¬-cong : ∀ {n} {i j : BitVector n} → i ≡ j → bitwise-negation i ≡ bitwise-negation j
¬-cong refl = refl
isBooleanAlgebra : ∀ {n} → IsBooleanAlgebra _≡_ bitwise-or bitwise-and bitwise-negation (ones n) (zero n)
isBooleanAlgebra = record
{ isDistributiveLattice = isDistributiveLattice
; ∨-complementʳ = ∨-complementʳ
; ∧-complementʳ = ∧-complementʳ
; ¬-cong = ¬-cong
}
|
{
"alphanum_fraction": 0.6177639047,
"avg_line_length": 39.1555555556,
"ext": "agda",
"hexsha": "00ee8d7974418fec6a37be61c72696ea3c16e4f7",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2021-11-12T01:40:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-25T00:15:43.000Z",
"max_forks_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "copumpkin/bitvector",
"max_forks_repo_path": "Data/BitVector/Properties/LatticeProperties.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_issues_repo_issues_event_max_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-05-25T02:00:59.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "copumpkin/bitvector",
"max_issues_repo_path": "Data/BitVector/Properties/LatticeProperties.agda",
"max_line_length": 128,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "6902f4bce0330f1b58f48395dac4406056713687",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "copumpkin/bitvector",
"max_stars_repo_path": "Data/BitVector/Properties/LatticeProperties.agda",
"max_stars_repo_stars_event_max_datetime": "2021-11-12T01:41:07.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-04T07:19:55.000Z",
"num_tokens": 1402,
"size": 3524
}
|
------------------------------------------------------------------------------
-- Well-founded induction on the relation TreeT
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module FOT.FOTC.Program.Mirror.TreeR.Induction.Acc.WellFoundedInduction
where
open import FOTC.Base
open import FOT.FOTC.Program.Mirror.Induction.Acc.WellFounded
open import FOT.FOTC.Program.Mirror.TreeR
open import FOTC.Program.Mirror.Type
------------------------------------------------------------------------------
-- The relation TreeR is well-founded.
postulate wf-TreeR : WellFounded TreeR
-- Well-founded induction on the relation TreeT.
wfInd-TreeR :
(P : D → Set) →
(∀ {t} → Tree t → (∀ {t'} → Tree t' → TreeR t' t → P t') → P t) →
∀ {t} → Tree t → P t
wfInd-TreeR P = WellFoundedInduction wf-TreeR
|
{
"alphanum_fraction": 0.50499002,
"avg_line_length": 34.5517241379,
"ext": "agda",
"hexsha": "7721b15a75dff253fabe6de05daf8edb2d8f549b",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR/Induction/Acc/WellFoundedInduction.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR/Induction/Acc/WellFoundedInduction.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "notes/FOT/FOTC/Program/Mirror/TreeR/Induction/Acc/WellFoundedInduction.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": 230,
"size": 1002
}
|
{-# OPTIONS --cubical --no-import-sorts --no-exact-split --safe #-}
module Cubical.Data.Queue.1List where
open import Cubical.Foundations.Everything
open import Cubical.Structures.Queue
open import Cubical.Data.Empty as ⊥
open import Cubical.Data.Maybe
open import Cubical.Data.List
open import Cubical.Data.Sigma
module 1List {ℓ} (A : Type ℓ) (Aset : isSet A) where
open Queues-on A Aset
Q = List A
emp : Q
emp = []
enq : A → Q → Q
enq = _∷_
deq : Q → Maybe (Q × A)
deq [] = nothing
deq (x ∷ []) = just ([] , x)
deq (x ∷ x' ∷ xs) = deqMap (enq x) (deq (x' ∷ xs))
Raw : RawQueue
Raw = (Q , emp , enq , deq)
WithLaws : Queue
WithLaws = (Q , S , isSetQ , refl , deq-enq , isInjEnq , isInjDeq)
where
S = str Raw
isSetQ : isSet Q
isSetQ = isOfHLevelList 0 Aset
deq-enq : ∀ a q → deq (enq a q) ≡ just (returnOrEnq S a (deq q))
deq-enq a [] = refl
deq-enq a (x ∷ []) = refl
deq-enq a (x ∷ x' ∷ xs) =
subst
(λ t →
deqMap (enq a) (deqMap (enq x) t)
≡ just (returnOrEnq S a (deqMap (enq x) t)))
(deq-enq x' xs ⁻¹)
refl
isInjEnq : ∀ a a' q q' → enq a q ≡ enq a' q' → (a ≡ a') × (q ≡ q')
isInjEnq _ _ _ _ p = fst c , ListPath.decode _ _ (snd c)
where
c = ListPath.encode _ _ p
isInjReturnOrEnq : ∀ a a' qr qr'
→ returnOrEnq S a qr ≡ returnOrEnq S a' qr'
→ (a ≡ a') × (qr ≡ qr')
isInjReturnOrEnq a a' nothing nothing p = cong snd p , refl
isInjReturnOrEnq a a' nothing (just (q' , b')) p =
⊥.rec (lower (ListPath.encode _ _ (cong fst p)))
isInjReturnOrEnq a a' (just (q , b)) nothing p =
⊥.rec (lower (ListPath.encode _ _ (cong fst p)))
isInjReturnOrEnq a a' (just (q , b)) (just (q' , b')) p =
fst c , cong just (ΣPathP (ListPath.decode _ _ (snd c) , cong snd p))
where
c = ListPath.encode _ _ (cong fst p)
isInjDeq-lemma : ∀ q q' → MaybePath.Cover (deq q) (deq q') → q ≡ q'
isInjDeq-lemma [] [] _ = refl
isInjDeq-lemma [] (y ∷ q') c =
⊥.rec (lower (subst (MaybePath.Cover nothing) (deq-enq y q') c))
isInjDeq-lemma (x ∷ q) [] c =
⊥.rec (lower (subst (λ r → MaybePath.Cover r nothing) (deq-enq x q) c))
isInjDeq-lemma (x ∷ q) (y ∷ q') c =
cong₂ _∷_ (fst p) (isInjDeq-lemma q q' (MaybePath.encode _ _ (snd p)))
where
p : (x ≡ y) × (deq q ≡ deq q')
p =
isInjReturnOrEnq _ _ _ _
(subst (uncurry MaybePath.Cover) (ΣPathP (deq-enq x q , deq-enq y q')) c)
isInjDeq : ∀ q q' → deq q ≡ deq q' → q ≡ q'
isInjDeq _ _ p = isInjDeq-lemma _ _ (MaybePath.encode _ _ p)
Finite : FiniteQueue
Finite = (Q , str WithLaws , subst isEquiv (sym (funExt foldrCons)) (idIsEquiv _))
|
{
"alphanum_fraction": 0.5736665423,
"avg_line_length": 30.4659090909,
"ext": "agda",
"hexsha": "3a9ac6bb969b52dea10b307e5beac2f49a14948d",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/Data/Queue/1List.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Data/Queue/1List.agda",
"max_line_length": 83,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dan-iel-lee/cubical",
"max_stars_repo_path": "Cubical/Data/Queue/1List.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1068,
"size": 2681
}
|
module Common.Context where
open import Common public
-- Contexts.
data Cx (U : Set) : Set where
∅ : Cx U
_,_ : Cx U → U → Cx U
-- Vector contexts.
data VCx (U : Set) : ℕ → Set where
∅ : VCx U zero
_,_ : ∀ {n} → VCx U n → U → VCx U (suc n)
-- Inversion principles for contexts.
module _ {U : Set} where
inv,₁ : ∀ {Γ Γ′ : Cx U} {A A′ : U} → (Γ Cx., A) ≡ (Γ′ , A′) → Γ ≡ Γ′
inv,₁ refl = refl
inv,₂ : ∀ {Γ Γ′ : Cx U} {A A′ : U} → (Γ Cx., A) ≡ (Γ′ , A′) → A ≡ A′
inv,₂ refl = refl
-- Decidable equality for contexts.
module ContextEquality {U : Set} (_≟ᵁ_ : (A A′ : U) → Dec (A ≡ A′)) where
_≟ᵀ⋆_ : (Γ Γ′ : Cx U) → Dec (Γ ≡ Γ′)
∅ ≟ᵀ⋆ ∅ = yes refl
∅ ≟ᵀ⋆ (Γ′ , A′) = no λ ()
(Γ , A) ≟ᵀ⋆ ∅ = no λ ()
(Γ , A) ≟ᵀ⋆ (Γ′ , A′) with Γ ≟ᵀ⋆ Γ′ | A ≟ᵁ A′
(Γ , A) ≟ᵀ⋆ (.Γ , .A) | yes refl | yes refl = yes refl
(Γ , A) ≟ᵀ⋆ (Γ′ , A′) | no Γ≢Γ′ | _ = no (Γ≢Γ′ ∘ inv,₁)
(Γ , A) ≟ᵀ⋆ (Γ′ , A′) | _ | no A≢A′ = no (A≢A′ ∘ inv,₂)
-- Context membership, or nameless typed de Bruijn indices.
module _ {U : Set} where
infix 3 _∈_
data _∈_ (A : U) : Cx U → Set where
instance
top : ∀ {Γ} → A ∈ Γ , A
pop : ∀ {B Γ} → A ∈ Γ → A ∈ Γ , B
pop² : ∀ {A B C Γ} → A ∈ Γ → A ∈ Γ , B , C
pop² = pop ∘ pop
i₀ : ∀ {A Γ} → A ∈ Γ , A
i₀ = top
i₁ : ∀ {A B Γ} → A ∈ Γ , A , B
i₁ = pop top
i₂ : ∀ {A B C Γ} → A ∈ Γ , A , B , C
i₂ = pop² top
[_]ⁱ : ∀ {A Γ} → A ∈ Γ → ℕ
[ top ]ⁱ = zero
[ pop i ]ⁱ = suc [ i ]ⁱ
-- Context inclusion, or order-preserving embedding.
module _ {U : Set} where
infix 3 _⊆_
data _⊆_ : Cx U → Cx U → Set where
instance
done : ∅ ⊆ ∅
skip : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ Γ′ , A
keep : ∀ {A Γ Γ′} → Γ ⊆ Γ′ → Γ , A ⊆ Γ′ , A
skip² : ∀ {A B Γ Γ′} → Γ ⊆ Γ′ → Γ ⊆ Γ′ , B , A
skip² = skip ∘ skip
keep² : ∀ {A B Γ Γ′} → Γ ⊆ Γ′ → Γ , B , A ⊆ Γ′ , B , A
keep² = keep ∘ keep
instance
refl⊆ : ∀ {Γ} → Γ ⊆ Γ
refl⊆ {∅} = done
refl⊆ {Γ , A} = keep refl⊆
trans⊆ : ∀ {Γ Γ′ Γ″} → Γ ⊆ Γ′ → Γ′ ⊆ Γ″ → Γ ⊆ Γ″
trans⊆ η done = η
trans⊆ η (skip η′) = skip (trans⊆ η η′)
trans⊆ (skip η) (keep η′) = skip (trans⊆ η η′)
trans⊆ (keep η) (keep η′) = keep (trans⊆ η η′)
unskip⊆ : ∀ {A Γ Γ′} → Γ , A ⊆ Γ′ → Γ ⊆ Γ′
unskip⊆ (skip η) = skip (unskip⊆ η)
unskip⊆ (keep η) = skip η
unkeep⊆ : ∀ {A Γ Γ′} → Γ , A ⊆ Γ′ , A → Γ ⊆ Γ′
unkeep⊆ (skip η) = unskip⊆ η
unkeep⊆ (keep η) = η
weak⊆ : ∀ {A Γ} → Γ ⊆ Γ , A
weak⊆ = skip refl⊆
weak²⊆ : ∀ {A B Γ} → Γ ⊆ Γ , A , B
weak²⊆ = skip² refl⊆
bot⊆ : ∀ {Γ} → ∅ ⊆ Γ
bot⊆ {∅} = done
bot⊆ {Γ , A} = skip bot⊆
-- Monotonicity of context membership with respect to context inclusion.
module _ {U : Set} where
mono∈ : ∀ {A : U} {Γ Γ′} → Γ ⊆ Γ′ → A ∈ Γ → A ∈ Γ′
mono∈ done ()
mono∈ (skip η) i = pop (mono∈ η i)
mono∈ (keep η) top = top
mono∈ (keep η) (pop i) = pop (mono∈ η i)
reflmono∈ : ∀ {A Γ} → (i : A ∈ Γ) → i ≡ mono∈ refl⊆ i
reflmono∈ top = refl
reflmono∈ (pop i) = cong pop (reflmono∈ i)
transmono∈ : ∀ {A Γ Γ′ Γ″} → (η : Γ ⊆ Γ′) (η′ : Γ′ ⊆ Γ″) (i : A ∈ Γ)
→ mono∈ η′ (mono∈ η i) ≡ mono∈ (trans⊆ η η′) i
transmono∈ done η′ ()
transmono∈ η (skip η′) i = cong pop (transmono∈ η η′ i)
transmono∈ (skip η) (keep η′) i = cong pop (transmono∈ η η′ i)
transmono∈ (keep η) (keep η′) top = refl
transmono∈ (keep η) (keep η′) (pop i) = cong pop (transmono∈ η η′ i)
-- Concatenation of contexts.
module _ {U : Set} where
_⧺_ : Cx U → Cx U → Cx U
Γ ⧺ ∅ = Γ
Γ ⧺ (Γ′ , A) = (Γ ⧺ Γ′) , A
id⧺₁ : ∀ {Γ} → Γ ⧺ ∅ ≡ Γ
id⧺₁ = refl
id⧺₂ : ∀ {Γ} → ∅ ⧺ Γ ≡ Γ
id⧺₂ {∅} = refl
id⧺₂ {Γ , A} = cong² _,_ id⧺₂ refl
weak⊆⧺₁ : ∀ {Γ} Γ′ → Γ ⊆ Γ ⧺ Γ′
weak⊆⧺₁ ∅ = refl⊆
weak⊆⧺₁ (Γ′ , A) = skip (weak⊆⧺₁ Γ′)
weak⊆⧺₂ : ∀ {Γ Γ′} → Γ′ ⊆ Γ ⧺ Γ′
weak⊆⧺₂ {Γ} {∅} = bot⊆
weak⊆⧺₂ {Γ} {Γ′ , A} = keep weak⊆⧺₂
-- Thinning of contexts.
module _ {U : Set} where
_∖_ : ∀ {A} → (Γ : Cx U) → A ∈ Γ → Cx U
∅ ∖ ()
(Γ , A) ∖ top = Γ
(Γ , B) ∖ pop i = (Γ ∖ i) , B
thin⊆ : ∀ {A Γ} → (i : A ∈ Γ) → Γ ∖ i ⊆ Γ
thin⊆ top = weak⊆
thin⊆ (pop i) = keep (thin⊆ i)
-- Decidable equality of context membership.
module _ {U : Set} where
data _=∈_ {A : U} {Γ} (i : A ∈ Γ) : ∀ {B} → B ∈ Γ → Set where
same : i =∈ i
diff : ∀ {B} → (j : B ∈ Γ ∖ i) → i =∈ mono∈ (thin⊆ i) j
_≟∈_ : ∀ {A B : U} {Γ} → (i : A ∈ Γ) (j : B ∈ Γ) → i =∈ j
top ≟∈ top = same
top ≟∈ pop j rewrite reflmono∈ j = diff j
pop i ≟∈ top = diff top
pop i ≟∈ pop j with i ≟∈ j
pop i ≟∈ pop .i | same = same
pop i ≟∈ pop ._ | diff j = diff (pop j)
|
{
"alphanum_fraction": 0.4339062168,
"avg_line_length": 25.2032085561,
"ext": "agda",
"hexsha": "484db1dd499ee51f8eb2247470b69eb08bf1e2fe",
"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": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/hilbert-gentzen",
"max_forks_repo_path": "Common/Context.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_issues_repo_issues_event_max_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-06-10T09:11:22.000Z",
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/hilbert-gentzen",
"max_issues_repo_path": "Common/Context.agda",
"max_line_length": 73,
"max_stars_count": 29,
"max_stars_repo_head_hexsha": "fcd187db70f0a39b894fe44fad0107f61849405c",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/hilbert-gentzen",
"max_stars_repo_path": "Common/Context.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-01T10:29:18.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-07-03T18:51:56.000Z",
"num_tokens": 2509,
"size": 4713
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Definition
open import Rings.Definition
open import Rings.IntegralDomains.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
module Fields.FieldOfFractions.Ring {a b : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} (I : IntegralDomain R) where
open import Fields.FieldOfFractions.Setoid I
open import Fields.FieldOfFractions.Addition I
open import Fields.FieldOfFractions.Group I
open import Fields.FieldOfFractions.Multiplication I
fieldOfFractionsRing : Ring fieldOfFractionsSetoid fieldOfFractionsPlus fieldOfFractionsTimes
Ring.additiveGroup fieldOfFractionsRing = fieldOfFractionsGroup
Ring.*WellDefined fieldOfFractionsRing {a} {b} {c} {d} = fieldOfFractionsTimesWellDefined {a} {b} {c} {d}
Ring.1R fieldOfFractionsRing = record { num = Ring.1R R ; denom = Ring.1R R ; denomNonzero = IntegralDomain.nontrivial I }
Ring.groupIsAbelian fieldOfFractionsRing {record { num = a ; denom = b }} {record { num = c ; denom = d }} = Equivalence.transitive (Setoid.eq S) (Ring.*Commutative R) (Ring.*WellDefined R (Ring.*Commutative R) (Equivalence.transitive (Setoid.eq S) (Group.+WellDefined (Ring.additiveGroup R) (Ring.*Commutative R) (Ring.*Commutative R)) (Ring.groupIsAbelian R)))
Ring.*Associative fieldOfFractionsRing {record { num = a ; denom = b }} {record { num = c ; denom = d }} {record { num = e ; denom = f }} = Equivalence.transitive (Setoid.eq S) (Ring.*WellDefined R (Ring.*Associative R) (Ring.*Associative' R)) (Ring.*Commutative R)
Ring.*Commutative fieldOfFractionsRing {record { num = a ; denom = b }} {record { num = c ; denom = d }} = Equivalence.transitive (Setoid.eq S) (Ring.*Commutative R) (Ring.*WellDefined R (Ring.*Commutative R) (Ring.*Commutative R))
Ring.*DistributesOver+ fieldOfFractionsRing {record { num = a ; denom = b }} {record { num = c ; denom = d }} {record { num = e ; denom = f }} = need
where
open Setoid S
open Ring R
open Equivalence eq
inter : b * (a * ((c * f) + (d * e))) ∼ (((a * c) * (b * f)) + ((b * d) * (a * e)))
inter = transitive *Associative (transitive *DistributesOver+ (Group.+WellDefined additiveGroup (transitive *Associative (transitive (*WellDefined (transitive (*WellDefined (*Commutative) reflexive) (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative))) reflexive) (symmetric *Associative))) (transitive *Associative (transitive (*WellDefined (transitive (symmetric *Associative) (transitive (*WellDefined reflexive *Commutative) *Associative)) reflexive) (symmetric *Associative)))))
need : ((a * ((c * f) + (d * e))) * ((b * d) * (b * f))) ∼ ((b * (d * f)) * (((a * c) * (b * f)) + ((b * d) * (a * e))))
need = transitive (Ring.*WellDefined R reflexive (Ring.*WellDefined R reflexive (Ring.*Commutative R))) (transitive (Ring.*WellDefined R reflexive (Ring.*Associative R)) (transitive (Ring.*Commutative R) (transitive (Ring.*WellDefined R (Ring.*WellDefined R (symmetric (Ring.*Associative R)) reflexive) reflexive) (transitive (symmetric (Ring.*Associative R)) (Ring.*WellDefined R reflexive inter)))))
Ring.identIsIdent fieldOfFractionsRing {record { num = a ; denom = b }} = need
where
open Setoid S
open Equivalence eq
need : (((Ring.1R R) * a) * b) ∼ (((Ring.1R R * b)) * a)
need = transitive (Ring.*WellDefined R (Ring.identIsIdent R) reflexive) (transitive (Ring.*Commutative R) (Ring.*WellDefined R (symmetric (Ring.identIsIdent R)) reflexive))
|
{
"alphanum_fraction": 0.7027252503,
"avg_line_length": 92.2051282051,
"ext": "agda",
"hexsha": "05c20a00e1de7414cb215425d8de9e7c0b6b4e6a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Fields/FieldOfFractions/Ring.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Fields/FieldOfFractions/Ring.agda",
"max_line_length": 536,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Fields/FieldOfFractions/Ring.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": 1098,
"size": 3596
}
|
module Oscar.Category.Semigroup where
open import Oscar.Category.Setoid
open import Oscar.Level
module _ {𝔬 𝔮} (setoid : Setoid 𝔬 𝔮) where
open Setoid setoid
record IsSemigroup (_∙_ : ⋆ → ⋆ → ⋆) : Set (𝔬 ⊔ 𝔮) where
field
extensionality : ∀ {f₁ f₂} → f₁ ≋ f₂ → ∀ {g₁ g₂} → g₁ ≋ g₂ → g₁ ∙ f₁ ≋ g₂ ∙ f₂
associativity : ∀ f g h → (h ∙ g) ∙ f ≋ h ∙ (g ∙ f)
open IsSemigroup ⦃ … ⦄ public
record Semigroup 𝔬 𝔮 : Set (lsuc (𝔬 ⊔ 𝔮)) where
field
setoid : Setoid 𝔬 𝔮
open Setoid setoid public
infixl 7 _∙_
field
_∙_ : ⋆ → ⋆ → ⋆
⦃ isSemigroup ⦄ : IsSemigroup setoid _∙_
|
{
"alphanum_fraction": 0.5933884298,
"avg_line_length": 23.2692307692,
"ext": "agda",
"hexsha": "e98a416278cac575920953964db3e9769ce179e1",
"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/Category/Semigroup.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/Category/Semigroup.agda",
"max_line_length": 84,
"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/Category/Semigroup.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 283,
"size": 605
}
|
{-# OPTIONS --rewriting #-}
open import Luau.Type using (Type; Scalar; nil; number; string; boolean; never; unknown; _⇒_; _∪_; _∩_)
open import Properties.Equality using (_≢_)
module Luau.Subtyping where
-- An implementation of semantic subtyping
-- We think of types as languages of trees
data Tree : Set where
scalar : ∀ {T} → Scalar T → Tree
function : Tree
function-ok : Tree → Tree
function-err : Tree → Tree
data Language : Type → Tree → Set
data ¬Language : Type → Tree → Set
data Language where
scalar : ∀ {T} → (s : Scalar T) → Language T (scalar s)
function : ∀ {T U} → Language (T ⇒ U) function
function-ok : ∀ {T U u} → (Language U u) → Language (T ⇒ U) (function-ok u)
function-err : ∀ {T U t} → (¬Language T t) → Language (T ⇒ U) (function-err t)
scalar-function-err : ∀ {S t} → (Scalar S) → Language S (function-err t)
left : ∀ {T U t} → Language T t → Language (T ∪ U) t
right : ∀ {T U u} → Language U u → Language (T ∪ U) u
_,_ : ∀ {T U t} → Language T t → Language U t → Language (T ∩ U) t
unknown : ∀ {t} → Language unknown t
data ¬Language where
scalar-scalar : ∀ {S T} → (s : Scalar S) → (Scalar T) → (S ≢ T) → ¬Language T (scalar s)
scalar-function : ∀ {S} → (Scalar S) → ¬Language S function
scalar-function-ok : ∀ {S u} → (Scalar S) → ¬Language S (function-ok u)
function-scalar : ∀ {S T U} (s : Scalar S) → ¬Language (T ⇒ U) (scalar s)
function-ok : ∀ {T U u} → (¬Language U u) → ¬Language (T ⇒ U) (function-ok u)
function-err : ∀ {T U t} → (Language T t) → ¬Language (T ⇒ U) (function-err t)
_,_ : ∀ {T U t} → ¬Language T t → ¬Language U t → ¬Language (T ∪ U) t
left : ∀ {T U t} → ¬Language T t → ¬Language (T ∩ U) t
right : ∀ {T U u} → ¬Language U u → ¬Language (T ∩ U) u
never : ∀ {t} → ¬Language never t
-- Subtyping as language inclusion
_<:_ : Type → Type → Set
(T <: U) = ∀ t → (Language T t) → (Language U t)
-- For warnings, we are interested in failures of subtyping,
-- which is whrn there is a tree in T's language that isn't in U's.
data _≮:_ (T U : Type) : Set where
witness : ∀ t →
Language T t →
¬Language U t →
-----------------
T ≮: U
|
{
"alphanum_fraction": 0.5905511811,
"avg_line_length": 34.2698412698,
"ext": "agda",
"hexsha": "943f459b747346ecd2e6d006ef810f5d3a8c7ead",
"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": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "EtiTheSpirit/luau",
"max_forks_repo_path": "prototyping/Luau/Subtyping.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"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": "EtiTheSpirit/luau",
"max_issues_repo_path": "prototyping/Luau/Subtyping.agda",
"max_line_length": 103,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "d37d0c857ba543ea47f0b8fce5678f7aadf5239e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "EtiTheSpirit/luau",
"max_stars_repo_path": "prototyping/Luau/Subtyping.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 731,
"size": 2159
}
|
{-# OPTIONS --cubical --guarded -W ignore #-}
module combinations-of-lift-and-list where
open import Clocked.Primitives
open import Cubical.Foundations.Prelude
open import Cubical.Data.List as List
open import Cubical.Data.List.Properties
open import Cubical.Data.Sum using (_⊎_; inl; inr)
--**********************************************************************--
--**********************************************************************--
-- Combining the monads Lift and List freely and via a distributive law --
--**********************************************************************--
--**********************************************************************--
-- In this document I want to define a monad, called ListLift, that is the free combination of the Lift monad and the List monad.
-- In order to do so, I will first define the Lift monad and the List monad, and check that they are indeed monads (Step 1 and 2).
-- Then I define the LiftList monad, check that it is a monad (Step 3), and finally check that it is the free monad on the algebra
-- structures of a delay algebra and a monoid (Step 4).
-- In addition to the free combination of the List and the Lift monads, I also compose the two monads to form the monad
-- LcL : A → Lift(List A). This composition uses a distributive law, which I prove does indeed satisfy all the axioms for a
-- distributive law.
--************************--
-- Step 1: The Lift monad --
--************************--
-- Defining the monad myLift.
--(note that the return/unit is just x → nowL x)
data myLift (A : Set) (κ : Cl) : Set where
nowL : A → (myLift A κ)
stepL : ▹ κ (myLift A κ) → (myLift A κ)
bindL : {A B : Set} (κ : Cl) → (A → (myLift B κ)) → myLift A κ → myLift B κ
bindL κ f (nowL a) = f a
bindL κ f (stepL x) = stepL \(α) → bindL κ f (x α)
identity : {A : Set} → A → A
identity x = x
MultL : {A : Set} (κ : Cl) → (myLift (myLift A κ) κ) → (myLift A κ)
MultL κ = bindL κ identity
mapL : {A B : Set} (κ : Cl) → (A → B) → (myLift A κ) → (myLift B κ)
mapL κ f (nowL x) = nowL (f x)
mapL κ f (stepL x) = stepL (\ α → mapL κ f (x α))
--checking that it is indeed a monad
-- needs to satisfy three monad laws:
-- unit is a left-identity for bind: bind (f, return) = f
-- unit is a right-identity for bind: bind (return, x) = x
-- bind is associative: bind (\x > bind (g, f(x)), x) = bind(g,bind(f, x))
-- The first of these is satisfied by definition
-- The other two laws we check here below
-- unit law, two versions to learn and remember to ways of doing guarded recursion in agda:
unitlawL : {A : Set}(κ : Cl) → ∀(x : (myLift A κ)) → (bindL {A} κ nowL x) ≡ x
unitlawL κ (nowL x) = refl
unitlawL κ (stepL x) = cong stepL (later-ext (\ α → unitlawL κ (x α)))
unitlawL' : {A : Set}(κ : Cl) → ∀(x : (myLift A κ)) → (bindL {A} κ nowL x) ≡ x
unitlawL' κ (nowL x) = refl
unitlawL' κ (stepL x) = \ i → stepL (\ α → unitlawL' κ (x α) i )
-- associative law:
associativelawL : {A B C : Set}(κ : Cl) → ∀(f : A → (myLift B κ)) → ∀ (g : B → (myLift C κ)) →
∀ (y : (myLift A κ)) → (bindL κ (\ x → (bindL κ g (f x))) y) ≡ (bindL κ g (bindL κ f y))
associativelawL κ f g (nowL x) = refl
associativelawL κ f g (stepL x) = cong stepL (((later-ext (\ α → associativelawL κ f g (x α)))))
-- Some properties that will be useful later:
-- interaction of mapL and MultL:
MultMap : {A B : Set} (κ : Cl) → ∀(x : myLift (myLift A κ) κ) → ∀(f : A → B) → mapL κ f (MultL κ x) ≡ MultL κ (mapL κ (mapL κ f) x)
MultMap κ (nowL x) f = refl
MultMap κ (stepL x) f = \ i → stepL (\ α → MultMap κ (x α) f i)
-- mapmap for mapL
mapmapL : {A B C : Set} (κ : Cl) → ∀(f : A → B) → ∀(g : B → C) → ∀(x : myLift A κ) → mapL κ g (mapL κ f x) ≡ mapL κ (\ y → g(f y)) x
mapmapL κ f g (nowL x) = refl
mapmapL κ f g (stepL x) = (\ i → stepL (\ α → mapmapL κ f g (x α) i ))
--************************--
-- Step 2: The List monad --
--************************--
-- Defining the monad List
--List is already defined, but we define a unit and multiplication for it, so it becomes a monad
List-unit : {A : Set} → A → List A
List-unit x = [ x ]
List-mult : {A : Set} → List (List A) → List A
List-mult {A} = foldr _++_ []
List-bind : {A B : Set} → (A → List B) → List A → List B
List-bind f [] = []
List-bind f (x ∷ xs) = (f x) ++ (List-bind f xs)
-- and some other useful functions for later
safe-head : {A : Set} → A → List A → A
safe-head x [] = x
safe-head _ (x ∷ _) = x
tail : {A : Set} → List A → List A
tail [] = []
tail (x ∷ xs) = xs
-- Proving that this forms a monad
-- satisfying the laws:
-- List-mult (List-unit L) = L
-- List-mult (map List-unit L) = L
-- List-mult (List-Mult L) = List-mult (map List-mult L)
-- and both the unit and the multiplication are natural transformations
-- List-mult (List-unit L) = L
List-unitlaw1 : {A : Set} → ∀(L : List A) → List-mult (List-unit L) ≡ L
List-unitlaw1 [] = refl
List-unitlaw1 (x ∷ L) = cong (_++_ [ x ]) (List-unitlaw1 L)
-- List-mult (map List-unit L) = L
List-unitlaw2 : {A : Set} → ∀(L : List A) → List-mult (map List-unit L) ≡ L
List-unitlaw2 [] = refl
List-unitlaw2 (x ∷ L) = cong (_++_ [ x ]) (List-unitlaw2 L )
-- List-mult (List-Mult L) = List-mult (map List-mult L)
lemma : {A : Set} → ∀(L₁ L₂ : List (List A)) -> List-mult (L₁ ++ L₂) ≡ (List-mult L₁) ++ (List-mult L₂)
lemma [] L₂ = refl
lemma (L₁ ∷ L₃) L₂ = L₁ ++ List-mult (L₃ ++ L₂)
≡⟨ cong (L₁ ++_) (lemma L₃ L₂) ⟩
L₁ ++ ((List-mult L₃) ++ (List-mult L₂))
≡⟨ sym (++-assoc L₁ (List-mult L₃) (List-mult L₂)) ⟩
(L₁ ++ List-mult L₃) ++ List-mult L₂
≡⟨ refl ⟩
(List-mult (L₁ ∷ L₃)) ++ (List-mult L₂) ∎
List-multlaw : {A : Set} -> ∀(L : List (List (List A))) -> List-mult (List-mult L) ≡ List-mult (map List-mult L)
List-multlaw [] = refl
List-multlaw (L ∷ L₁) = List-mult (L ++ List-mult L₁)
≡⟨ lemma L (List-mult L₁) ⟩
(List-mult L ++ List-mult (List-mult L₁))
≡⟨ cong (List-mult L ++_) (List-multlaw L₁) ⟩
List-mult L ++ List-mult (map List-mult L₁) ∎
-- the unit is a natural transformation:
nattrans-Listunit : {A B : Set} → ∀(f : A → B) → ∀(x : A) → map f (List-unit x) ≡ List-unit (f x)
nattrans-Listunit f x = refl
-- the multiplication is a natural transformation:
lemma-map++ : {A B : Set} → ∀(f : A → B) → ∀(xs ys : List A) → map f (xs ++ ys) ≡ (map f xs) ++ (map f ys)
lemma-map++ f [] ys = refl
lemma-map++ f (x ∷ xs) ys = cong ((f x) ∷_) (lemma-map++ f xs ys)
nattrans-Listmult : {A B : Set} → ∀(f : A → B) → ∀(xss : List (List A)) → map f (List-mult xss) ≡ List-mult (map (map f) xss)
nattrans-Listmult f [] = refl
nattrans-Listmult f (xs ∷ xss) = map f (xs ++ List-mult xss)
≡⟨ lemma-map++ f xs (List-mult xss) ⟩
map f xs ++ map f (List-mult xss)
≡⟨ cong (map f xs ++_) (nattrans-Listmult f xss) ⟩
map f xs ++ List-mult (map (map f) xss) ∎
--****************************--
-- Step 3: The ListLift monad --
--****************************--
--Now that we have a list monad and a lift monad, I want to show that the following combination of the two is again a monad:
--ListLift : (A : Set) → (κ : Cl) → Set
--ListLift A κ = List (A ⊎ (▹ κ (ListLift A κ)))
data ListLift (A : Set) (κ : Cl) : Set where
conLL : List (A ⊎ (▹ κ (ListLift A κ))) -> ListLift A κ
--***algebraic structure for ListLift***--
--nowLL and stepLL turn ListLift into a delay algebra structure:
nowLL : {A : Set} (κ : Cl) → A → (ListLift A κ)
nowLL κ a = conLL [ (inl a) ]
stepLL : {A : Set} (κ : Cl) → ▹ κ (ListLift A κ) → (ListLift A κ)
stepLL κ a = conLL [ (inr a) ]
--union, derived from list concatenation, turns ListLift into a monoid:
_∪_ : {A : Set} {κ : Cl} → (ListLift A κ) → (ListLift A κ) → (ListLift A κ)
_∪_ {A} {κ} (conLL x) (conLL y) = conLL (x ++ y)
--proof that this union does indeed provide a monoid structure:
conLLempty-rightunit : {A : Set} (κ : Cl) → ∀ (xs : (ListLift A κ)) → xs ∪ conLL [] ≡ xs
conLLempty-rightunit κ (conLL x) = conLL (x ++ []) ≡⟨ cong conLL (++-unit-r x) ⟩ conLL x ∎
conLLempty-leftunit : {A : Set} (κ : Cl) → ∀ (xs : (ListLift A κ)) → conLL [] ∪ xs ≡ xs
conLLempty-leftunit κ (conLL x) = refl
assoc∪ : {A : Set} {κ : Cl} → ∀(xs ys zs : (ListLift A κ)) → (xs ∪ ys) ∪ zs ≡ xs ∪ (ys ∪ zs)
assoc∪ {A} {κ} (conLL x) (conLL x₁) (conLL x₂) = cong conLL (++-assoc x x₁ x₂)
--a bind operator to make ListLift into a monad
bindLL : {A B : Set} (κ : Cl) → (A → (ListLift B κ)) → ListLift A κ → ListLift B κ
bindLL κ f (conLL []) = conLL []
bindLL κ f (conLL (inl x ∷ x₁)) = (f x) ∪ bindLL κ f (conLL x₁)
bindLL κ f (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → bindLL κ f (x α))) ∪ bindLL κ f (conLL x₁)
--bind commutes with ∪
bindLL∪ : {A B : Set} (κ : Cl) → ∀(f : A → (ListLift B κ)) → ∀(xs ys : (ListLift A κ)) → bindLL κ f (xs ∪ ys) ≡ (bindLL κ f xs) ∪ (bindLL κ f ys)
bindLL∪ κ f xs (conLL []) = bindLL κ f (xs ∪ conLL []) ≡⟨ cong (bindLL κ f) (conLLempty-rightunit κ xs) ⟩
bindLL κ f xs ≡⟨ sym (conLLempty-rightunit κ (bindLL κ f xs)) ⟩
(bindLL κ f xs ∪ conLL [])∎
bindLL∪ κ f (conLL []) (conLL (x ∷ x₁)) = bindLL κ f (conLL (x ∷ x₁))
≡⟨ sym (conLLempty-leftunit κ (bindLL κ f (conLL (x ∷ x₁)))) ⟩
(conLL [] ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
bindLL∪ κ f (conLL (inl x₂ ∷ x₃)) (conLL (x ∷ x₁)) = (f x₂ ∪ bindLL κ f ((conLL x₃) ∪ (conLL (x ∷ x₁)))) ≡⟨ cong (f x₂ ∪_) (bindLL∪ κ f (conLL x₃) (conLL (x ∷ x₁))) ⟩
(f x₂ ∪ (bindLL κ f (conLL x₃) ∪ bindLL κ f (conLL (x ∷ x₁))))
≡⟨ sym (assoc∪ (f x₂) (bindLL κ f (conLL x₃)) (bindLL κ f (conLL (x ∷ x₁)))) ⟩
((f x₂ ∪ bindLL κ f (conLL x₃)) ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
bindLL∪ κ f (conLL (inr x₂ ∷ x₃)) (conLL (x ∷ x₁)) = (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ bindLL κ f ((conLL x₃) ∪ (conLL (x ∷ x₁))))
≡⟨ cong (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪_) (bindLL∪ κ f (conLL x₃) (conLL (x ∷ x₁))) ⟩
(conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ ((bindLL κ f (conLL x₃) ∪ bindLL κ f (conLL (x ∷ x₁)))))
≡⟨ sym (assoc∪ (conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ [])) (bindLL κ f (conLL x₃)) (bindLL κ f (conLL (x ∷ x₁)))) ⟩
((conLL (inr (λ α → bindLL κ f (x₂ α)) ∷ []) ∪ bindLL κ f (conLL x₃)) ∪ bindLL κ f (conLL (x ∷ x₁))) ∎
--and a map function to prove naturality of bind and now
mapLL : {A B : Set} (κ : Cl) → (f : A → B) → (ListLift A κ) → (ListLift B κ)
mapLL κ f (conLL []) = conLL []
mapLL κ f (conLL (inl x ∷ x₁)) = conLL ([ inl (f x) ]) ∪ mapLL κ f (conLL x₁)
mapLL κ f (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → mapLL κ f (x α))) ∪ mapLL κ f (conLL x₁)
--***proving that ListLift is a monad***--
--bindLL and nowLL need to be natural transformations
nattrans-nowLL : {A B : Set} (κ : Cl) → ∀(f : A → B) → ∀(x : A) → mapLL κ f (nowLL κ x) ≡ nowLL κ (f x)
nattrans-nowLL {A}{B} κ f x = refl
--TODO: bind is a natural transformation
-- bindLL and nowLL also need to satisfy three monad laws:
-- unit is a left-identity for bind: bind (f, nowLL) = f
-- unit is a right-identity for bind: bind (nowLL, x) = x
-- bind is associative: bind (\x > bind (g, f(x)), x) = bind(g,bind(f, x))
-- unit is a left-identity for bind
unitlawLL1 : {A B : Set} (κ : Cl) → ∀ (f : A → (ListLift B κ)) → ∀ (x : A) → (bindLL {A} κ f (nowLL κ x)) ≡ f x
unitlawLL1 κ f x = (f x ∪ conLL []) ≡⟨ conLLempty-rightunit κ (f x) ⟩ f x ∎
-- unit is a right-identity for bind
unitlawLL2 : {A : Set}(κ : Cl) → ∀(x : (ListLift A κ)) → (bindLL κ (nowLL κ) x) ≡ x
unitlawLL2 κ (conLL []) = refl
unitlawLL2 κ (conLL (inl x ∷ x₁)) = (conLL ([ inl x ]) ∪ bindLL κ (nowLL κ) (conLL x₁)) ≡⟨ cong (conLL ([ inl x ]) ∪_ ) (unitlawLL2 κ (conLL x₁)) ⟩
(conLL ([ inl x ]) ∪ conLL x₁) ≡⟨ refl ⟩
conLL (inl x ∷ x₁) ∎
unitlawLL2 κ (conLL (inr x ∷ x₁)) = (stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪ bindLL κ (nowLL κ) (conLL x₁)
≡⟨ cong ((stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪_) (unitlawLL2 κ (conLL x₁)) ⟩
(stepLL κ (\ α → bindLL κ (nowLL κ) (x α))) ∪ conLL x₁
≡⟨ cong (_∪ conLL x₁) (\ i → stepLL κ (\ α → unitlawLL2 κ (x α) i ) ) ⟩
conLL ([ inr x ]) ∪ conLL x₁
≡⟨ refl ⟩
conLL (inr x ∷ x₁) ∎
-- bind is associative
assoclawLL : {A B C : Set}(κ : Cl) → ∀(f : A → (ListLift B κ)) → ∀ (g : B → (ListLift C κ)) → ∀ (x : (ListLift A κ))
→ (bindLL κ (\ y → (bindLL κ g (f y))) x) ≡ (bindLL κ g (bindLL κ f x))
assoclawLL {A} {B} {C} κ f g (conLL []) = refl
assoclawLL {A} {B} {C} κ f g (conLL (inl x ∷ x₁)) = (bindLL κ g (f x) ∪ bindLL κ (λ y → bindLL κ g (f y)) (conLL x₁))
≡⟨ cong (bindLL κ g (f x) ∪_) (assoclawLL κ f g (conLL x₁)) ⟩
(bindLL κ g (f x) ∪ bindLL κ g (bindLL κ f (conLL x₁)))
≡⟨ sym (bindLL∪ κ g (f x) (bindLL κ f (conLL x₁))) ⟩
bindLL κ g (f x ∪ bindLL κ f (conLL x₁)) ∎
assoclawLL {A} {B} {C} κ f g (conLL (inr x ∷ x₁)) = (conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪ bindLL κ (λ y → bindLL κ g (f y)) (conLL x₁))
≡⟨ cong (conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪_) (assoclawLL κ f g (conLL x₁)) ⟩
(conLL (inr (λ α → bindLL κ (λ y → bindLL κ g (f y)) (x α)) ∷ []) ∪ (bindLL κ g (bindLL κ f (conLL x₁))))
≡⟨ cong (_∪ (bindLL κ g (bindLL κ f (conLL x₁)))) (\ i → stepLL κ (\ α → assoclawLL κ f g (x α) i ) ) ⟩
((bindLL κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ []))) ∪ (bindLL κ g (bindLL κ f (conLL x₁))) )
≡⟨ sym (bindLL∪ κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ [])) (bindLL κ f (conLL x₁))) ⟩
bindLL κ g (conLL (inr (λ α → bindLL κ f (x α)) ∷ []) ∪ bindLL κ f (conLL x₁)) ∎
-- If I want to do it via fixpoints instead:
module WithFix where
LiftList : (A : Set) → (κ : Cl) → Set
LiftList A κ = fix (\ (X : ▹ κ Set) → List(A ⊎ (▸ κ \ α → (X α))))
nowLLfix : {A : Set} (κ : Cl) → A → (LiftList A κ)
nowLLfix κ a = [ (inl a) ]
stepLLfix : {A : Set} (κ : Cl) → ▹ κ (LiftList A κ) → (LiftList A κ)
stepLLfix {A} κ a = transport
(λ i →
fix-eq (λ (X : ▹ κ Type) → List (A ⊎ (▸ κ (λ α → X α)))) (~ i))
[ (inr a) ]
--***********************************************************************--
-- Step 4: The ListLift monad as the free delay-algebra and monoid monad --
--***********************************************************************--
-- We already know that (ListLift, stepLL) forms a delay algebra structure
-- and (Listlift, conLL [], _∪_) forms a monoid.
-- What we need to show is that ListLift is the free monad with these properties.
-- That is, for a set A, and any other structure (B, δ, ε, _·_) where (B, δ) is a delay algebra and (B, ε, _·_) a monoid
-- given a function f : A → B, there is a unique function ListLift A → B extending f that preserves the algebra structures.
record IsDelayalg {A : Set}(κ : Cl)(nextA : ▹ κ A → A) : Set where
constructor isdelayalg
record IsMonoid {A : Set} (ε : A) (_·_ : A → A → A) : Set where
constructor ismonoid
field
assoc : (x y z : A) → (x · y) · z ≡ x · (y · z)
leftid : (x : A) → ε · x ≡ x
rightid : (x : A) → x · ε ≡ x
record DelayMonoidData (A : Set) (κ : Cl) : Set where
constructor dmdata
field
nextA : ▹ κ A → A
ε : A
_·_ : A → A → A
record IsDelayMonoid {A : Set}(κ : Cl) (dm : DelayMonoidData A κ) : Set where
constructor isdelaymonoid
open DelayMonoidData dm
field
isMonoid : IsMonoid (ε) (_·_)
isDelayalg : IsDelayalg κ (nextA)
open IsMonoid isMonoid public
open IsDelayalg isDelayalg public
record IsPreservingDM {A B : Set}(κ : Cl) dmA dmB (g : A → B) : Set where
constructor ispreservingDM
open DelayMonoidData dmA renaming (ε to εA)
open DelayMonoidData dmB renaming (ε to εB; nextA to nextB; _·_ to _*_)
field
unit-preserve : g (εA) ≡ εB
next-preserve : (x : ▹ κ A) → g (nextA x) ≡ nextB (\ α → g (x α))
union-preserve : (x y : A) → g (x · y) ≡ (g x) * (g y)
record IsExtending {A B : Set}{κ : Cl} (f : A → B) (h : (ListLift A κ) → B) : Set where
constructor isextending
field
extends : (x : A) → h (nowLL κ x) ≡ (f x)
--fold defines the function we are after
fold : {A B : Set}{κ : Cl} → isSet A → isSet B → ∀ dm → IsDelayMonoid {B} κ dm → (A → B) → (ListLift A κ) → B
fold setA setB (dmdata nextB ε _·_) isDMB f (conLL []) = ε
fold setA setB dm@(dmdata nextB ε _·_) isDMB f (conLL (inl x ∷ x₁)) = (f x) · fold setA setB dm isDMB f (conLL x₁)
fold setA setB dm@(dmdata nextB ε _·_) isDMB f (conLL (inr x ∷ x₁)) = (nextB (\ α → fold setA setB dm isDMB f (x α))) · fold setA setB dm isDMB f (conLL x₁)
--fold extends the function f : A → B
-- direct proof:
fold-extends-f : {A B : Set}{κ : Cl} → ∀(setA : isSet A) → ∀(setB : isSet B) → ∀ dm → ∀(isDMB : IsDelayMonoid {B} κ dm) →
∀ (f : A → B) → ∀ (x : A) → fold setA setB dm isDMB f (nowLL κ x) ≡ f x
fold-extends-f setA setB dm isDMB f x = IsDelayMonoid.rightid isDMB (f x)
-- or via the record "IsExtending":
fold-extends : {A B : Set}{κ : Cl} → ∀(setA : isSet A) → ∀(setB : isSet B) → ∀ dm → ∀(isDMB : IsDelayMonoid {B} κ dm) →
∀ (f : A → B) → IsExtending f (fold setA setB dm isDMB f)
IsExtending.extends (fold-extends setA setB dm isDMB f) x = IsDelayMonoid.rightid isDMB (f x)
module _ {A B : Set}{κ : Cl} (setA : isSet A) (setB : isSet B) (dm : _) (isDMB : IsDelayMonoid {B} κ dm)
(f : A → B)
where
open IsPreservingDM
open DelayMonoidData dm renaming (nextA to nextB)
--fold preseves the DelayMonoid structure
fold-preserves : IsPreservingDM {ListLift A κ}{B} κ (dmdata (stepLL κ) (conLL []) _∪_) dm (fold setA setB dm isDMB f)
unit-preserve fold-preserves = refl
next-preserve fold-preserves x = IsDelayMonoid.rightid isDMB (nextB (λ α → fold setA setB dm isDMB f (x α)))
union-preserve fold-preserves (conLL xs) (conLL ys) = lemma-union xs ys
where
lemma-union : ∀ xs ys → fold setA setB dm isDMB f (conLL xs ∪ conLL ys) ≡
(fold setA setB dm isDMB f (conLL xs) ·
fold setA setB dm isDMB f (conLL ys))
lemma-union [] y = sym (IsDelayMonoid.leftid isDMB
(fold setA setB dm isDMB f (conLL y)))
lemma-union (inl x ∷ x₁) y = (f x · fold setA setB dm isDMB f (conLL (x₁ ++ y)))
≡⟨ cong (f x ·_) (lemma-union x₁ y) ⟩
((f x · (fold setA setB dm isDMB f (conLL x₁) ·
fold setA setB dm isDMB f (conLL y))))
≡⟨ sym (IsDelayMonoid.assoc isDMB (f x)
(fold setA setB dm isDMB f (conLL x₁))
(fold setA setB dm isDMB f (conLL y))) ⟩
((f x · fold setA setB dm isDMB f (conLL x₁)) ·
fold setA setB dm isDMB f (conLL y)) ∎
lemma-union (inr x ∷ x₁) y =
(nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL (x₁ ++ y)))
≡⟨ cong (nextB (λ α → fold setA setB dm isDMB f (x α)) ·_)
(lemma-union
x₁ y) ⟩
( (nextB (λ α → fold setA setB dm isDMB f (x α)) ·
(fold setA setB dm isDMB f (conLL x₁) ·
fold setA setB dm isDMB f (conLL y))))
≡⟨ sym (IsDelayMonoid.assoc isDMB
(nextB (λ α → fold setA setB dm isDMB f (x α)))
(fold setA setB dm isDMB f (conLL x₁))
(fold setA setB dm isDMB f (conLL y))) ⟩
((nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL x₁)) ·
fold setA setB dm isDMB f (conLL y)) ∎
--and fold is unique in doing so. That is, for any function h that both preserves the algebra structure and extends the function f : A → B,
-- h is equivalent to fold.
module _ {A B : Set} {κ : Cl} (h : ListLift A κ → B)
(setA : isSet A) (setB : isSet B) (dm : _) (isDMB : IsDelayMonoid {B} κ dm)
(f : A → B) (isPDM : IsPreservingDM {ListLift A κ}{B} κ (dmdata (stepLL κ) (conLL []) _∪_ ) dm h)
(isExt : IsExtending f h) where
open DelayMonoidData dm renaming (nextA to nextB)
fold-uniquenessLL : (x : (ListLift A κ)) → h x ≡ (fold setA setB dm isDMB f x)
fold-uniquenessLL (conLL []) = h (conLL [])
≡⟨ IsPreservingDM.unit-preserve isPDM ⟩
ε
≡⟨ refl ⟩
fold setA setB dm isDMB f (conLL []) ∎
fold-uniquenessLL (conLL (inl x ∷ x₁)) = h (conLL (inl x ∷ x₁))
≡⟨ refl ⟩
h ((conLL [ inl x ]) ∪ (conLL x₁))
≡⟨ IsPreservingDM.union-preserve isPDM (conLL [ inl x ]) (conLL x₁) ⟩
((h (conLL [ inl x ])) ·
(h (conLL x₁)) )
≡⟨ cong (_· (h (conLL x₁)) ) (IsExtending.extends isExt x) ⟩
(f x · (h (conLL x₁)))
≡⟨ cong (f x ·_)(fold-uniquenessLL (conLL x₁)) ⟩
(f x · fold setA setB dm isDMB f (conLL x₁)) ∎
fold-uniquenessLL (conLL (inr x ∷ x₁)) = h (conLL (inr x ∷ x₁))
≡⟨ cong (h ) refl ⟩
h ((conLL [ inr x ]) ∪ (conLL x₁))
≡⟨ IsPreservingDM.union-preserve isPDM (conLL [ inr x ]) (conLL x₁) ⟩
(h (conLL [ inr x ])) ·
(h (conLL x₁))
≡⟨ cong (_· h (conLL x₁)) refl ⟩
((h (stepLL κ x)) ·
(h (conLL x₁)) )
≡⟨ cong (_· h (conLL x₁)) (IsPreservingDM.next-preserve isPDM x) ⟩
(((nextB (λ α → h (x α))) · (h (conLL x₁))))
≡⟨ cong (_· h (conLL x₁)) (cong (nextB)
(later-ext (\ α → fold-uniquenessLL (x α)))) ⟩
((nextB (λ α → fold setA setB dm isDMB f (x α))) · (h (conLL x₁)))
≡⟨ cong (nextB (λ α → fold setA setB dm isDMB f (x α)) ·_)
(fold-uniquenessLL (conLL x₁)) ⟩
(nextB (λ α → fold setA setB dm isDMB f (x α)) ·
fold setA setB dm isDMB f (conLL x₁)) ∎
--************************************************--
-- Composing Lift and List via a distributive law --
--************************************************--
--We now define a composite monad of the List and Lift monads, formed via a distributive law.
LcL : (A : Set) → (κ : Cl) → Set
LcL A κ = myLift (List A) κ
-- the unit of this monad is simply the composit of the units for Lift (nowL x) and List ([x])
nowLcL : {A : Set} {κ : Cl} → A → (LcL A κ)
nowLcL x = nowL [ x ]
-- LcL is a monad via a distributive law, distributing List over Lift.
-- Here is the distributive law:
distlawLcL : {A : Set} (κ : Cl) → List (myLift A κ) → (LcL A κ)
distlawLcL κ [] = nowL []
distlawLcL κ (nowL x ∷ xs) = MultL κ (nowL (mapL κ (([ x ]) ++_) (distlawLcL κ xs)))
distlawLcL κ (stepL x ∷ xs) = stepL (\ α → distlawLcL κ ((x α) ∷ xs))
--proof that distlawLcL is indeed a distributive law:
--unit laws:
unitlawLcL1 : {A : Set} (κ : Cl) → ∀(x : myLift A κ) → (distlawLcL κ (List-unit x )) ≡ mapL κ List-unit x
unitlawLcL1 κ (nowL x) = refl
unitlawLcL1 κ (stepL x) = (\ i → stepL (\ α → unitlawLcL1 κ (x α) i ))
unitlawLcL2 : {A : Set} (κ : Cl) → ∀(xs : List A) → (distlawLcL κ (map nowL xs)) ≡ nowL xs
unitlawLcL2 κ [] = refl
unitlawLcL2 κ (x ∷ xs) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (map nowL xs))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (unitlawLcL2 κ xs) ⟩
mapL κ (λ ys → x ∷ ys) (nowL xs)
≡⟨ refl ⟩
nowL (x ∷ xs) ∎
--multiplication laws:
-- In the proof of the first multiplication law, I need a lemma about list concatenation,
-- namely that putting a singleton list in front of a list of lists, and concatening the result
-- yields the same list as putting the element of the signleton in front of the first list in the list of lists,
-- and then concatenating the result.
-- The lemma is split into two parts, first the general result as described in words here,
-- followed by the specific situation in which I need it in the proofs below.
lemma7a : {A : Set} → ∀(x : A) → ∀(xss : (List (List A))) → List-mult ((x ∷ safe-head [] xss) ∷ tail xss ) ≡ List-mult (([ x ]) ∷ xss)
lemma7a x [] = refl
lemma7a x (xs ∷ xss) = refl
lemma7b : {A : Set} (κ : Cl) → ∀(y : myLift (List (List A)) κ) → ∀(x : A) →
mapL κ (λ xss → List-mult ((x ∷ safe-head [] xss) ∷ tail xss)) y ≡ mapL κ (λ xss → List-mult (([ x ]) ∷ xss)) y
lemma7b κ (nowL xss) x = cong nowL (lemma7a x xss)
lemma7b κ (stepL xss) x = (\ i → stepL (\ α → lemma7b κ (xss α) x i ))
-- in addition, I need this rather technical lemma that allows me to pull a mapL through the distributive law.
-- without it, I could not finish the proof.
lemma8 : {A : Set} (κ : Cl) → ∀(x : A) → ∀(xs : myLift (List A) κ) → ∀(xss : List (myLift (List A) κ)) →
mapL κ (λ yss → ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (xs ∷ xss)) ≡ distlawLcL κ (mapL κ (λ ys → x ∷ ys) xs ∷ xss)
lemma8 κ x (nowL ys) [] = refl
lemma8 κ x (stepL ys) [] = (\ i → stepL (λ α → lemma8 κ x (ys α) [] i ))
lemma8 κ x (nowL []) (zs ∷ xss) = mapL κ (λ yss → (x ∷ safe-head [] yss) ∷ tail yss) (mapL κ (λ zss → [] ∷ zss) (distlawLcL κ (zs ∷ xss)))
≡⟨ mapmapL κ ((λ zss → [] ∷ zss)) ((λ yss → (x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (zs ∷ xss)) ⟩
mapL κ (λ yss → (x ∷ safe-head [] ([] ∷ yss)) ∷ tail ([] ∷ yss)) (distlawLcL κ (zs ∷ xss))
≡⟨ refl ⟩
mapL κ (λ yss → (x ∷ []) ∷ yss) (distlawLcL κ (zs ∷ xss)) ∎
lemma8 κ x (nowL (y ∷ ys)) (zs ∷ xss) = mapL κ (λ yss → (x ∷ safe-head [] yss) ∷ tail yss) (mapL κ (λ zss → (y ∷ ys) ∷ zss) (distlawLcL κ (zs ∷ xss)))
≡⟨ mapmapL κ ((λ zss → (y ∷ ys) ∷ zss)) ((λ yss → (x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (zs ∷ xss)) ⟩
mapL κ (λ yss → (x ∷ safe-head []((y ∷ ys) ∷ yss)) ∷ tail((y ∷ ys) ∷ yss)) (distlawLcL κ (zs ∷ xss))
≡⟨ refl ⟩
mapL κ (λ yss → (x ∷ y ∷ ys) ∷ yss) (distlawLcL κ (zs ∷ xss)) ∎
lemma8 κ x (stepL ys) (zs ∷ xss) = (\ i → stepL (λ α → lemma8 κ x (ys α) (zs ∷ xss) i ))
--now we are ready to prove the multiplication laws:
multlawLcL1 : {A : Set} (κ : Cl) → ∀(xss : List (List (myLift A κ))) → distlawLcL κ (List-mult xss) ≡
mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss))
multlawLcL1 κ [] = refl
multlawLcL1 κ ([] ∷ xss) = distlawLcL κ (List-mult xss)
≡⟨ multlawLcL1 κ xss ⟩
mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ ys → List-mult ([] ∷ ys)) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ sym (mapmapL κ (\ ys → [] ∷ ys) List-mult ((distlawLcL κ (map (distlawLcL κ) xss)))) ⟩
mapL κ List-mult (mapL κ (λ ys → [] ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((nowL x ∷ []) ∷ xss) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (List-mult xss))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL1 κ xss) ⟩
mapL κ (λ ys → x ∷ ys) (mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) xss)))
≡⟨ mapmapL κ List-mult (λ ys → x ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss)) ⟩
mapL κ (λ ys → x ∷ List-mult ys) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ ys → List-mult (([ x ]) ∷ ys)) (distlawLcL κ (map (distlawLcL κ) xss))
≡⟨ sym( mapmapL κ (λ ys → ([ x ]) ∷ ys) List-mult (distlawLcL κ (map (distlawLcL κ) xss))) ⟩
mapL κ List-mult (mapL κ (λ ys → ([ x ]) ∷ ys) (distlawLcL κ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((nowL x ∷ y ∷ xs) ∷ xss) = mapL κ (λ ys → x ∷ ys) (distlawLcL κ (List-mult ((y ∷ xs) ∷ xss)))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL1 κ ((y ∷ xs) ∷ xss)) ⟩
mapL κ (λ ys → x ∷ ys) (mapL κ List-mult (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss))))
≡⟨ mapmapL κ List-mult (λ ys → x ∷ ys) (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss))) ⟩
mapL κ (λ yss → x ∷ (List-mult yss)) (distlawLcL κ (map (distlawLcL κ) ((y ∷ xs) ∷ xss)))
≡⟨ refl ⟩
mapL κ (λ yss → x ∷ List-mult yss) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ refl ⟩
mapL κ (λ yss → List-mult (([ x ]) ∷ yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ sym (lemma7b κ ((distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))) x) ⟩
mapL κ (λ yss → List-mult ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss))
≡⟨ sym (mapmapL κ ((λ yss → ((x ∷ safe-head [] yss) ∷ tail yss))) List-mult
((distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss)))) ⟩
mapL κ List-mult (mapL κ (λ yss → ((x ∷ safe-head [] yss) ∷ tail yss)) (distlawLcL κ (distlawLcL κ (y ∷ xs) ∷ map (distlawLcL κ) xss)))
≡⟨ cong (mapL κ List-mult) (lemma8 κ x ((distlawLcL κ (y ∷ xs))) ((map (distlawLcL κ) xss))) ⟩
mapL κ List-mult (distlawLcL κ (mapL κ (λ ys → x ∷ ys) (distlawLcL κ (y ∷ xs)) ∷ (map (distlawLcL κ) xss))) ∎
multlawLcL1 κ ((stepL x ∷ xs) ∷ xss) = (\ i → stepL (\ α → multlawLcL1 κ ((x α ∷ xs) ∷ xss) i ))
lemma9a : {A : Set} (κ : Cl) → ∀(x : ▹ κ (myLift A κ)) → ∀(y : ▹ κ (myLift (List (myLift A κ)) κ)) →
MultL κ (stepL (λ α → stepL (λ β → mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β)))) ≡
MultL κ (stepL (λ β → stepL (λ α → mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
lemma9a κ x y = cong (MultL κ) (cong stepL (later-ext λ α → cong stepL (later-ext λ β →
cong₂ (mapL κ) (funExt (λ ys → cong (distlawLcL _) (cong₂ _∷_ (tick-irr x α β) refl)))
(sym (tick-irr y α β)))))
lemma9 : {A : Set} (κ : Cl) → ∀(x : ▹ κ (myLift A κ)) → ∀(y : myLift (List (myLift A κ)) κ) →
MultL κ (stepL (λ α → (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) y))) ≡ MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) y)
lemma9 κ x (nowL y) = refl
lemma9 κ x (stepL y) = stepL (λ α → stepL (λ β → MultL κ (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
≡⟨ lemma9a κ x y ⟩
stepL (λ β → stepL (λ α → MultL κ (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (y β))))
≡⟨ ( (\ i → stepL (\ β → lemma9 κ x (y β) i ))) ⟩
stepL (λ β → MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) (y β))) ∎
multlawLcL2 : {A : Set} (κ : Cl) → ∀(xs : List (myLift (myLift A κ) κ)) → distlawLcL κ (map (MultL κ) xs) ≡
MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ xs))
multlawLcL2 κ [] = refl
multlawLcL2 κ (nowL (nowL x) ∷ xs) = distlawLcL κ ((nowL x) ∷ map (MultL κ) xs)
≡⟨ refl ⟩
mapL κ (λ ys → x ∷ ys) (distlawLcL κ (map (MultL κ) xs))
≡⟨ cong (mapL κ (λ ys → x ∷ ys)) (multlawLcL2 κ xs) ⟩
mapL κ (λ ys → x ∷ ys) (MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ xs)))
≡⟨ MultMap κ (mapL κ (distlawLcL κ) (distlawLcL κ xs)) (λ ys → x ∷ ys) ⟩
MultL κ (mapL κ (mapL κ (λ ys → x ∷ ys)) (mapL κ (distlawLcL κ) (distlawLcL κ xs)) )
≡⟨ cong (MultL κ) (mapmapL κ ((distlawLcL κ)) (mapL κ (λ ys → x ∷ ys)) ((distlawLcL κ xs))) ⟩
MultL κ (mapL κ (λ ys → mapL κ (λ zs → x ∷ zs) (distlawLcL κ ys)) (distlawLcL κ xs))
≡⟨ refl ⟩
MultL κ (mapL κ (λ ys → (distlawLcL κ) ((nowL x) ∷ ys)) (distlawLcL κ xs))
≡⟨ cong (MultL κ) (sym (mapmapL κ ((λ ys → (nowL x) ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs)))) ⟩
MultL κ (mapL κ (distlawLcL κ) (mapL κ (λ ys → (nowL x) ∷ ys) (distlawLcL κ xs))) ∎
multlawLcL2 κ (nowL (stepL x) ∷ xs) = distlawLcL κ ((stepL x) ∷ map (MultL κ) xs)
≡⟨ refl ⟩
stepL (λ α → distlawLcL κ (x α ∷ map (MultL κ) xs))
≡⟨ refl ⟩
stepL (λ α → distlawLcL κ (map (MultL κ) ((nowL (x α)) ∷ xs)))
≡⟨ (\ i → stepL (\ α → multlawLcL2 κ (((nowL (x α)) ∷ xs)) i )) ⟩
stepL (λ α → MultL κ (mapL κ (distlawLcL κ) (distlawLcL κ ((nowL (x α) ∷ xs)))) )
≡⟨ refl ⟩
MultL κ (stepL (λ α → (mapL κ (distlawLcL κ) (distlawLcL κ ((nowL (x α) ∷ xs))))))
≡⟨ refl ⟩
MultL κ (stepL (λ α → (mapL κ (distlawLcL κ) (mapL κ (λ ys → x α ∷ ys) (distlawLcL κ xs)))))
≡⟨ cong (MultL κ) ((λ i → stepL (\ α → (mapmapL κ ((λ ys → x α ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs))) i ))) ⟩
MultL κ (stepL (λ α → (mapL κ (λ ys → distlawLcL κ (x α ∷ ys)) (distlawLcL κ xs))))
≡⟨ lemma9 κ x (distlawLcL κ xs) ⟩
MultL κ (mapL κ (λ ys → stepL (λ α → distlawLcL κ (x α ∷ ys))) (distlawLcL κ xs))
≡⟨ refl ⟩
MultL κ (mapL κ (λ ys → (distlawLcL κ) ((stepL x) ∷ ys)) (distlawLcL κ xs))
≡⟨ cong (MultL κ) (sym (mapmapL κ ((λ ys → (stepL x) ∷ ys)) ((distlawLcL κ)) ((distlawLcL κ xs)))) ⟩
MultL κ (mapL κ (distlawLcL κ) (mapL κ (λ ys → (stepL x) ∷ ys) (distlawLcL κ xs))) ∎
multlawLcL2 κ (stepL x ∷ xs) = (\ i → stepL (\ α → multlawLcL2 κ ((x α ∷ xs)) i ))
-- Bonusmaterial:
-- we define a union on LcL.
_l∪l_ : {A : Set} {κ : Cl} → (LcL A κ) → (LcL A κ) → (LcL A κ)
nowL x l∪l nowL y = nowL (x ++ y)
nowL x l∪l stepL y = stepL (\ α → (nowL x l∪l (y α)))
stepL x l∪l y = stepL (\ α → ((x α) l∪l y))
--nowL [] is a unit for l∪l
left-unitl∪l : {A : Set} {κ : Cl} → ∀(x : LcL A κ) → (nowL []) l∪l x ≡ x
left-unitl∪l (nowL x) = refl
left-unitl∪l (stepL x) = stepL (λ α → nowL [] l∪l x α)
≡⟨ ((\ i → stepL (\ α → left-unitl∪l (x α) i ))) ⟩
stepL (λ α → x α)
≡⟨ refl ⟩
stepL x ∎
right-unitl∪l : {A : Set} {κ : Cl} → ∀(x : LcL A κ) → x l∪l (nowL []) ≡ x
right-unitl∪l (nowL x) = cong nowL (++-unit-r x)
right-unitl∪l (stepL x) = stepL (λ α → x α l∪l nowL [])
≡⟨ ((\ i → stepL (\ α → right-unitl∪l (x α) i ))) ⟩
stepL (λ α → x α)
≡⟨ refl ⟩
stepL x ∎
--mapL κ f distributes over l∪l if f distributes over ++
dist-mapL-l∪l : {A B : Set} (κ : Cl) → ∀(f : (List A) → (List B)) → ∀(fcom : ∀(xs : List A) → ∀(ys : List A) → f (xs ++ ys) ≡ f xs ++ f ys) →
∀(x : (LcL A κ)) → ∀(y : LcL A κ) → mapL κ f (x l∪l y) ≡ (mapL κ f x) l∪l (mapL κ f y)
dist-mapL-l∪l κ f fcom (nowL x) (nowL y) = cong nowL (fcom x y)
dist-mapL-l∪l κ f fcom (nowL x) (stepL y) = (\ i → stepL (\ α → dist-mapL-l∪l κ f fcom (nowL x) (y α) i ))
dist-mapL-l∪l κ f fcom (stepL x) y = \ i → stepL (\ α → dist-mapL-l∪l κ f fcom (x α) y i )
|
{
"alphanum_fraction": 0.4619460501,
"avg_line_length": 59.2252252252,
"ext": "agda",
"hexsha": "c5d1d8a5c7048a2269ad44c6867cd7b42563c4eb",
"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": "add34af6c5c0c106c7aaa2d9612d54e041ab5d3b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Saizan/Agda-proofs",
"max_forks_repo_path": "combinations-of-lift-and-list.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "add34af6c5c0c106c7aaa2d9612d54e041ab5d3b",
"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/Agda-proofs",
"max_issues_repo_path": "combinations-of-lift-and-list.agda",
"max_line_length": 179,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "add34af6c5c0c106c7aaa2d9612d54e041ab5d3b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Saizan/Agda-proofs",
"max_stars_repo_path": "combinations-of-lift-and-list.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 13840,
"size": 39444
}
|
{-# OPTIONS --warning=error --safe --without-K #-}
open import LogicalFormulae
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Categories.Definition
module Categories.Functor.Definition where
record Functor {a b c d : _} (C : Category {a} {b}) (D : Category {c} {d}) : Set (a ⊔ b ⊔ c ⊔ d) where
field
onObj : Category.objects C → Category.objects D
onArrow : {S T : Category.objects C} → Category.arrows C S T → Category.arrows D (onObj S) (onObj T)
mapId : {T : Category.objects C} → onArrow (Category.id C T) ≡ Category.id D (onObj T)
mapCompose : {X Y Z : Category.objects C} → (f : Category.arrows C X Y) (g : Category.arrows C Y Z) → onArrow (Category._∘_ C g f) ≡ Category._∘_ D (onArrow g) (onArrow f)
|
{
"alphanum_fraction": 0.6653386454,
"avg_line_length": 50.2,
"ext": "agda",
"hexsha": "663546f348297e0ae3378abd5879ec509c41155f",
"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": "Categories/Functor/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Categories/Functor/Definition.agda",
"max_line_length": 175,
"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": "Categories/Functor/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 244,
"size": 753
}
|
module Stuck where
postulate
I : Set
i j : I
data D : I → I → Set where
d : D i i
e : D j j
f : ∀ {x} → D i x → Set₁
f d = Set
|
{
"alphanum_fraction": 0.4928571429,
"avg_line_length": 10.7692307692,
"ext": "agda",
"hexsha": "32bcea23ba0616deedaaab827769f9db5886a4cb",
"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/Stuck.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/Stuck.agda",
"max_line_length": 26,
"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/Stuck.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": 63,
"size": 140
}
|
module SetOmega where
postulate
IsType : ∀ {a} → Set a → Set
Bad : IsType (∀ a → Set a)
|
{
"alphanum_fraction": 0.5773195876,
"avg_line_length": 13.8571428571,
"ext": "agda",
"hexsha": "f8b5139e4aab3dfd5aae3b6e645cae963d4da8b4",
"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/SetOmega.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/SetOmega.agda",
"max_line_length": 31,
"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/SetOmega.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": 97
}
|
open import Agda.Builtin.Bool
data Test : Set where
CTest : Bool -> {Bool} -> Test
{-# COMPILE AGDA2HS Test #-}
getTest : Test → Bool
getTest (CTest b) = b
{-# COMPILE AGDA2HS getTest #-}
putTest : Bool → Test → Test
putTest b (CTest _ {b'}) = CTest b {b'}
{-# COMPILE AGDA2HS putTest #-}
|
{
"alphanum_fraction": 0.6372881356,
"avg_line_length": 19.6666666667,
"ext": "agda",
"hexsha": "1a7e035c73e8412830568f4f6147d65c2c8c6a01",
"lang": "Agda",
"max_forks_count": 18,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:42:52.000Z",
"max_forks_repo_forks_event_min_datetime": "2020-10-21T22:19:09.000Z",
"max_forks_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "seanpm2001/agda2hs",
"max_forks_repo_path": "test/Datatypes.agda",
"max_issues_count": 63,
"max_issues_repo_head_hexsha": "160478a51bc78b0fdab07b968464420439f9fed6",
"max_issues_repo_issues_event_max_datetime": "2022-02-25T15:47:30.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-10-22T05:19:27.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "seanpm2001/agda2hs",
"max_issues_repo_path": "test/Datatypes.agda",
"max_line_length": 39,
"max_stars_count": 55,
"max_stars_repo_head_hexsha": "8c8f24a079ed9677dbe6893cf786e7ed52dfe8b6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "dxts/agda2hs",
"max_stars_repo_path": "test/Datatypes.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-26T21:57:56.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-20T13:36:25.000Z",
"num_tokens": 97,
"size": 295
}
|
open import Relation.Binary.Core using (Rel)
module GGT.Definitions
{a b ℓ₁ ℓ₂}
{G : Set a} -- The underlying group carrier
{Ω : Set b} -- The underlying space
(_≈_ : Rel G ℓ₁) -- The underlying group equality
(_≋_ : Rel Ω ℓ₂) -- The underlying space equality
where
open import Level
open import Algebra.Core
open import Relation.Unary
open import Algebra.Bundles using (Group)
open import Algebra.Definitions _≋_ using (Congruent₁)
ActAssoc : Opᵣ G Ω → Op₂ G → Set _
ActAssoc _·_ _∙_ = ∀ (o : Ω) (g : G) (h : G) → (o · (g ∙ h)) ≋ ((o · g) · h)
ActLeftIdentity : G → Opᵣ G Ω → Set _
ActLeftIdentity ε _·_ = ∀ (o : Ω) → (o · ε) ≋ o
·-≋-Congruence : Opᵣ G Ω → Set _
·-≋-Congruence _·_ = ∀ (g : G) → Congruent₁ (_· g)
-- ∀ (o1 o2 : Ω) (g : G) → o1 ≋ o2 → (o1 · g) ≋ (o2 · g)
≈-Ext : Opᵣ G Ω → Set _
≈-Ext _·_ = ∀ {g h : G} → ∀ {o : Ω} → g ≈ h → (o · g) ≋ (o · h)
|
{
"alphanum_fraction": 0.5731981982,
"avg_line_length": 30.6206896552,
"ext": "agda",
"hexsha": "7243b15d1e3c55e77a0f3a8c3d3e6d7d4c61e5ca",
"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": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "zampino/ggt",
"max_forks_repo_path": "src/ggt/Definitions.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"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": "zampino/ggt",
"max_issues_repo_path": "src/ggt/Definitions.agda",
"max_line_length": 76,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "e2d6b5f9bea15dd67817bf67e273f6b9a14335af",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "zampino/ggt",
"max_stars_repo_path": "src/ggt/Definitions.agda",
"max_stars_repo_stars_event_max_datetime": "2020-11-28T05:48:39.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-17T11:10:00.000Z",
"num_tokens": 381,
"size": 888
}
|
module MJ.Examples.Exceptions where
open import Prelude
open import Data.Star
import Data.Vec.All as Vec∀
open import Data.List
open import Data.List.Any
open import Data.List.Membership.Propositional
open import Data.List.All hiding (lookup)
open import Data.Product hiding (Σ)
open import Relation.Binary.PropositionalEquality
open import MJ.Examples.Integer
open import MJ.Types
open import MJ.Classtable
open import MJ.Classtable.Code Σ
open import MJ.Syntax Σ
open import MJ.Syntax.Program Σ
open import MJ.Semantics Σ Lib
open import MJ.Semantics.Values Σ
-- Integer class body
caught : Prog int
caught = Lib , let
x = (here refl)
y = (there (here refl))
v = (there (there (here refl)))
in body
(
loc int
◅ loc (ref INT)
◅ loc (ref INT)
◅ asgn v (num 0)
◅ asgn x (new INT (num 9 ∷ []))
◅ asgn y (new INT (num 18 ∷ []))
◅ (try (block (
-- perform a side effect on the heap: writing 18 to x's int field
run (call (var x) "set" {_}{void} (var y ∷ []))
-- raise the exception
◅ raise
◅ ε
)) catch (block (
-- read the 18 from x's field
asgn v (call (var x) "get" [])
◅ ε
)))
◅ ε
)
(var v)
uncaught : Prog int
uncaught = Lib , let
x = (here refl)
y = (there (here refl))
v = (there (there (here refl)))
in body
(
loc int
◅ loc (ref INT)
◅ loc (ref INT)
◅ asgn v (num 0)
◅ asgn x (new INT (num 9 ∷ []))
◅ asgn y (new INT (num 18 ∷ []))
◅ asgn v (call (var x) "get" [])
◅ raise
◅ ε
)
(var v)
test : caught ⇓⟨ 100 ⟩ (λ v → v ≡ num 18)
test = refl
test₂ : uncaught ⇓⟨ 100 ⟩! (λ μ e → e ≡ other)
test₂ = refl
|
{
"alphanum_fraction": 0.5677821894,
"avg_line_length": 22.8961038961,
"ext": "agda",
"hexsha": "198a0f14dd3e85319ae7eb32dc62844f9c0b795a",
"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/Examples/Exceptions.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/Examples/Exceptions.agda",
"max_line_length": 75,
"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/Examples/Exceptions.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": 570,
"size": 1763
}
|
module STLC.Type.Relation where
open import Data.Nat using (ℕ)
open import Data.Fin using (Fin)
open import STLC.Term
open import STLC.Type
open import STLC.Type.Context using (Ctxt)
open import Data.Vec using (_∷_; lookup)
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality as Eq
using (refl; _≡_; sym; cong)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; step-≡; _∎)
infix 4 _⊢_⦂_
data _⊢_⦂_ { m n } (Γ : Ctxt m n) : Term m -> Type n -> Set where
⊢# : ∀ { x : Fin m }
-- ---------------
-> Γ ⊢ # x ⦂ lookup Γ x
⊢ƛ : ∀ { t τ₁ τ₂ }
-> τ₁ ∷ Γ ⊢ t ⦂ τ₂
-- -----------------
-> Γ ⊢ ƛ t ⦂ τ₁ ⇒ τ₂
⊢_·_ : ∀ { t₁ t₂ τ₁ τ₂ }
-> Γ ⊢ t₁ ⦂ τ₁ ⇒ τ₂
-> Γ ⊢ t₂ ⦂ τ₁
-- ------------------
-> Γ ⊢ t₁ · t₂ ⦂ τ₂
_⊬_⦂_ : ∀ { m n } -> Ctxt m n -> Term m -> Type n -> Set
Γ ⊬ t ⦂ τ = ¬ (Γ ⊢ t ⦂ τ)
module Lemmas₀ where
⊢-subst : ∀ { m n } { Γ₁ Γ₂ : Ctxt m n } { t₁ t₂ : Term m } { τ₁ τ₂ : Type n }
-> Γ₁ ≡ Γ₂ -> t₁ ≡ t₂ -> τ₁ ≡ τ₂ -> Γ₁ ⊢ t₁ ⦂ τ₁ -> Γ₂ ⊢ t₂ ⦂ τ₂
⊢-subst refl refl refl hyp = hyp
⊢-Γ-subst : ∀ { m n } { Γ₁ Γ₂ : Ctxt m n } { t : Term m } { τ : Type n }
-> Γ₁ ≡ Γ₂ -> Γ₁ ⊢ t ⦂ τ -> Γ₂ ⊢ t ⦂ τ
⊢-Γ-subst ≡-Γ hyp = ⊢-subst ≡-Γ refl refl hyp
⊢-τ-subst : ∀ { m n } { Γ : Ctxt m n } { t : Term m } { τ₁ τ₂ : Type n }
-> τ₁ ≡ τ₂ -> Γ ⊢ t ⦂ τ₁ -> Γ ⊢ t ⦂ τ₂
⊢-τ-subst ≡-τ hyp = ⊢-subst refl refl ≡-τ hyp
-- TODO: Substitutions on typing derivations
-- TODO: Equivalent for Value e.g. value ⦂ τ relation w/ some lemmas :)
|
{
"alphanum_fraction": 0.4967532468,
"avg_line_length": 25.6666666667,
"ext": "agda",
"hexsha": "22006800de83af86f9d3e258bb447593fb46cc7d",
"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": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "johnyob/agda-types",
"max_forks_repo_path": "src/STLC/Type/Relation.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "johnyob/agda-types",
"max_issues_repo_path": "src/STLC/Type/Relation.agda",
"max_line_length": 81,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aeb2be63381d891fabe5317e3c27553deb6bca6d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "johnyob/agda-types",
"max_stars_repo_path": "src/STLC/Type/Relation.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 678,
"size": 1540
}
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
data Ix : Set where
ix : .(i : Nat) (n : Nat) → Ix
data D : Ix → Set where
mkD : ∀ n → D (ix n n)
data ΣD : Set where
_,_ : ∀ i → D i → ΣD
foo : ΣD → Nat
foo (i , mkD n) = n
d : ΣD
d = ix 0 6 , mkD 6
-- Check that we pick the right (the non-irrelevant) `n` when binding
-- the forced argument.
check : foo d ≡ 6
check = refl
|
{
"alphanum_fraction": 0.5970149254,
"avg_line_length": 16.75,
"ext": "agda",
"hexsha": "299da8dcde60772bc2d13a6465631fa15279f1e3",
"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/ForcingRelevance.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/ForcingRelevance.agda",
"max_line_length": 69,
"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/ForcingRelevance.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": 165,
"size": 402
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Reverse view
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
module Data.List.Reverse where
open import Data.List.Base as L hiding (reverse)
open import Data.List.Properties
open import Function
open import Relation.Binary.PropositionalEquality
-- If you want to traverse a list from the end, then you can use the
-- reverse view of it.
infixl 5 _∶_∶ʳ_
data Reverse {a} {A : Set a} : List A → Set a where
[] : Reverse []
_∶_∶ʳ_ : ∀ xs (rs : Reverse xs) (x : A) → Reverse (xs ∷ʳ x)
module _ {a} {A : Set a} where
reverse : (xs : List A) → Reverse (L.reverse xs)
reverse [] = []
reverse (x ∷ xs) = cast $ _ ∶ reverse xs ∶ʳ x where
cast = subst Reverse (sym $ unfold-reverse x xs)
reverseView : (xs : List A) → Reverse xs
reverseView xs = cast $ reverse (L.reverse xs) where
cast = subst Reverse (reverse-involutive xs)
|
{
"alphanum_fraction": 0.559454191,
"avg_line_length": 29.3142857143,
"ext": "agda",
"hexsha": "3d973c37d8f3c5ed2d2af1b312e0cf7b4181f7bf",
"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/Data/List/Reverse.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/Reverse.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/Data/List/Reverse.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": 270,
"size": 1026
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- Decidable propositional membership over vectors
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary using (Decidable)
open import Relation.Binary.PropositionalEquality using (_≡_; decSetoid)
module Data.Vec.Membership.DecPropositional
{a} {A : Set a} (_≟_ : Decidable (_≡_ {A = A})) where
------------------------------------------------------------------------
-- Re-export contents of propositional membership
open import Data.Vec.Membership.Propositional {A = A} public
open import Data.Vec.Membership.DecSetoid (decSetoid _≟_) public
using (_∈?_)
|
{
"alphanum_fraction": 0.5279255319,
"avg_line_length": 35.8095238095,
"ext": "agda",
"hexsha": "a30532192626eaf5ccf6766ff7b18af88797ca02",
"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/Data/Vec/Membership/DecPropositional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/Vec/Membership/DecPropositional.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/Data/Vec/Membership/DecPropositional.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": 149,
"size": 752
}
|
------------------------------------------------------------------------
-- Encodings and properties of higher-order extrema and intervals in
-- Fω with interval kinds
------------------------------------------------------------------------
{-# OPTIONS --safe --without-K #-}
module FOmegaInt.Typing.Encodings where
open import Data.Fin using (zero)
open import Data.Fin.Substitution using (Sub; Lift; TermSubst)
open import Data.Fin.Substitution.ExtraLemmas
open import Data.Nat using (suc)
open import Data.Product using (_,_; proj₁; proj₂; _×_)
open import Relation.Binary.PropositionalEquality hiding ([_])
open import FOmegaInt.Syntax
open import FOmegaInt.Typing
open import FOmegaInt.Typing.Validity
open Syntax
open TermCtx
open Substitution hiding (subst; _/_; _Kind/_)
open Typing
open TypedSubstitution
open TypedNarrowing
----------------------------------------------------------------------
-- Injection of shapes into kinds.
-- For every shape `k' there is a kind `⌈ k ⌉' that erases/simplifies
-- back to `k', i.e. `⌈_⌉' is a right inverse of kind erasure `⌊_⌋'.
--
-- NOTE. The definition of the injection `⌈_⌉' is rather intuitive,
-- but it is neither the only right inverse of `⌊_⌋', nor even the
-- "most canonical" one. Below we define two alternatives `⌈_⌉↓' and
-- `⌈_⌉↑' which, in addition to being right-inverse to `⌊_⌋', have
-- some appealing order-theoretic properties.
⌈_⌉ : ∀ {n} → SKind → Kind Term n
⌈ ★ ⌉ = *
⌈ j ⇒ k ⌉ = Π ⌈ j ⌉ ⌈ k ⌉
⌊⌋∘⌈⌉-id : ∀ {n} k → ⌊ ⌈_⌉ {n} k ⌋ ≡ k
⌊⌋∘⌈⌉-id ★ = refl
⌊⌋∘⌈⌉-id (j ⇒ k) = cong₂ _⇒_ (⌊⌋∘⌈⌉-id j) (⌊⌋∘⌈⌉-id k)
-- The kind `⌈ k ⌉' is well-formed (in any well-formed context).
⌈⌉-kd : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉ kd
⌈⌉-kd ★ Γ-ctx = *-kd Γ-ctx
⌈⌉-kd (j ⇒ k) Γ-ctx =
let ⌈j⌉-kd = ⌈⌉-kd j Γ-ctx
in kd-Π ⌈j⌉-kd (⌈⌉-kd k (wf-kd ⌈j⌉-kd ∷ Γ-ctx))
----------------------------------------------------------------------
-- Encodings and properties of extremal kinds.
-- The empty interval (note the use of absurd bounds).
∅ : ∀ {n} → Kind Term n
∅ = ⊤ ⋯ ⊥
-- Well-formedness of the empty interval kind.
∅-kd : ∀ {n} {Γ : Ctx n} → Γ ctx → Γ ⊢ ∅ kd
∅-kd Γ-ctx = kd-⋯ (∈-⊤-f Γ-ctx) (∈-⊥-f Γ-ctx)
-- Right-inverses of kind simplification: for every shape `k' there
-- are two canonical kinds `⌈ k ⌉↓' and `⌈ k ⌉↑', such that
--
-- 1. `⌈_⌉↓' and `⌈_⌉↑' are right-inverses for `⌊_⌋', i.e. `⌈ k ⌉↓'
-- and `⌈ k ⌉↑' both simplify to `k',
--
-- 2. `⌈ k ⌉↓' and `⌈ k ⌉↑' are limits, i.e. they are the least
-- resp. greatest kinds for which 1 holds.
--
-- NOTE. Rather than thinking of `⌈_⌉↓' and `⌈_⌉↑' as right-inverses
-- of kind simplifications, one may instead think of `⌊_⌋' as defining
-- a "kind space" `S(k, Γ) = { j | ⌊ j ⌋ ≡ k, Γ ⊢ j kd }' ordered by
-- subkinding, and interpret `⌈ k ⌉↓' and `⌈ k ⌉↑' as the extrema of
-- the space `S(k, Γ)' associated with `k'.
mutual
⌈_⌉↓ : ∀ {n} → SKind → Kind Term n
⌈ ★ ⌉↓ = ∅
⌈ j ⇒ k ⌉↓ = Π ⌈ j ⌉↑ ⌈ k ⌉↓
⌈_⌉↑ : ∀ {n} → SKind → Kind Term n
⌈ ★ ⌉↑ = *
⌈ j ⇒ k ⌉↑ = Π ⌈ j ⌉↓ ⌈ k ⌉↑
mutual
-- Proof of point 1 above: `⌈_⌉↓' and `⌈_⌉↑' are right-inverses of
-- `⌊_⌋'.
⌊⌋∘⌈⌉↓-id : ∀ {n} k → ⌊ ⌈_⌉↓ {n} k ⌋ ≡ k
⌊⌋∘⌈⌉↓-id ★ = refl
⌊⌋∘⌈⌉↓-id (j ⇒ k) = cong₂ _⇒_ (⌊⌋∘⌈⌉↑-id j) (⌊⌋∘⌈⌉↓-id k)
⌊⌋∘⌈⌉↑-id : ∀ {n} k → ⌊ ⌈_⌉↑ {n} k ⌋ ≡ k
⌊⌋∘⌈⌉↑-id ★ = refl
⌊⌋∘⌈⌉↑-id (j ⇒ k) = cong₂ _⇒_ (⌊⌋∘⌈⌉↓-id j) (⌊⌋∘⌈⌉↑-id k)
mutual
-- `⌈ k ⌉↓' and `⌈ k ⌉↑' are well-formed (in any well-formed
-- context).
⌈⌉↓-kd : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉↓ kd
⌈⌉↓-kd ★ Γ-ctx = ∅-kd Γ-ctx
⌈⌉↓-kd (j ⇒ k) Γ-ctx =
let ⌈j⌉↑-kd = ⌈⌉↑-kd j Γ-ctx
in kd-Π ⌈j⌉↑-kd (⌈⌉↓-kd k (wf-kd ⌈j⌉↑-kd ∷ Γ-ctx))
⌈⌉↑-kd : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉↑ kd
⌈⌉↑-kd ★ Γ-ctx = *-kd Γ-ctx
⌈⌉↑-kd (j ⇒ k) Γ-ctx =
let ⌈j⌉↓-kd = ⌈⌉↓-kd j Γ-ctx
in kd-Π ⌈j⌉↓-kd (⌈⌉↑-kd k (wf-kd ⌈j⌉↓-kd ∷ Γ-ctx))
mutual
-- Proof of point 2 above: `⌈ k ⌉↓' and `⌈ k ⌉↑' are the least
-- resp. greatest (well-formed) kinds that have shape `k'.
⌈⌉↑-maximum : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ ⌈ ⌊ k ⌋ ⌉↑
⌈⌉↑-maximum (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-⊥ a∈*) (<:-⊤ b∈*)
⌈⌉↑-maximum (kd-Π {j} j-kd k-kd) =
let ⌈⌊j⌋⌉↓<∷j = ⌈⌉↓-minimum j-kd
in <∷-Π ⌈⌊j⌋⌉↓<∷j (⌈⌉↑-maximum (⇓-kd ⌈⌊j⌋⌉↓<∷j k-kd))
(kd-Π j-kd k-kd)
⌈⌉↓-minimum : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ ⌈ ⌊ k ⌋ ⌉↓ <∷ k
⌈⌉↓-minimum (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-⊤ a∈*) (<:-⊥ b∈*)
⌈⌉↓-minimum (kd-Π {j} {k} j-kd k-kd) =
<∷-Π (⌈⌉↑-maximum j-kd) (⌈⌉↓-minimum k-kd) (⌈⌉↓-kd ⌊ Π j k ⌋ (kd-ctx j-kd))
-- Some corollaries.
-- Minima are subkinds of maxima.
⌈⌉↓<∷⌈⌉↑ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉↓ <∷ ⌈ k ⌉↑
⌈⌉↓<∷⌈⌉↑ k Γ-ctx =
subst (_ ⊢ ⌈ k ⌉↓ <∷_) (cong ⌈_⌉↑ (⌊⌋∘⌈⌉↓-id k))
(⌈⌉↑-maximum (⌈⌉↓-kd k Γ-ctx))
-- Minima are subkinds of the "intuitively" injected shapes.
⌈⌉↓<∷⌈⌉ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉↓ <∷ ⌈ k ⌉
⌈⌉↓<∷⌈⌉ k Γ-ctx =
subst (_ ⊢_<∷ ⌈ k ⌉) (cong ⌈_⌉↓ (⌊⌋∘⌈⌉-id k))
(⌈⌉↓-minimum (⌈⌉-kd k Γ-ctx))
-- Maxima are superkinds of the "intuitively" injected shapes.
⌈⌉<∷⌈⌉↑ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢ ⌈ k ⌉ <∷ ⌈ k ⌉↑
⌈⌉<∷⌈⌉↑ k Γ-ctx =
subst (_ ⊢ ⌈ k ⌉ <∷_) (cong ⌈_⌉↑ (⌊⌋∘⌈⌉-id k))
(⌈⌉↑-maximum (⌈⌉-kd k Γ-ctx))
-- Every well-kinded type inhabits the maximum kind associated with
-- its shape.
∈-⇑-⌈⌉↑ : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢Tp a ∈ ⌈ ⌊ k ⌋ ⌉↑
∈-⇑-⌈⌉↑ a∈k = ∈-⇑ a∈k (⌈⌉↑-maximum (Tp∈-valid a∈k))
----------------------------------------------------------------------
-- Encodings and properties of higher-order extrema
-- Higher-order extremal types, indexed by shapes.
--
-- NOTE. We will define a variant of the higher-order extrema indexed
-- by possibly dependent kinds below.
⊥⟨_⟩ : ∀ {n} → SKind → Term n
⊥⟨ ★ ⟩ = ⊥
⊥⟨ j ⇒ k ⟩ = Λ ⌈ j ⌉ ⊥⟨ k ⟩
⊤⟨_⟩ : ∀ {n} → SKind → Term n
⊤⟨ ★ ⟩ = ⊤
⊤⟨ j ⇒ k ⟩ = Λ ⌈ j ⌉ ⊤⟨ k ⟩
-- ⊥⟨ k ⟩ and ⊤⟨ k ⟩ inhabit ⌈ k ⌉.
∈-⊥⟨⟩ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢Tp ⊥⟨ k ⟩ ∈ ⌈ k ⌉
∈-⊥⟨⟩ ★ Γ-ctx = ∈-⊥-f Γ-ctx
∈-⊥⟨⟩ (j ⇒ k) Γ-ctx =
let ⌈j⌉-kd = ⌈⌉-kd j Γ-ctx
⌈j⌉∷Γ = wf-kd ⌈j⌉-kd ∷ Γ-ctx
in ∈-Π-i ⌈j⌉-kd (∈-⊥⟨⟩ k ⌈j⌉∷Γ)
∈-⊤⟨⟩ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢Tp ⊤⟨ k ⟩ ∈ ⌈ k ⌉
∈-⊤⟨⟩ ★ Γ-ctx = ∈-⊤-f Γ-ctx
∈-⊤⟨⟩ (j ⇒ k) Γ-ctx =
let ⌈j⌉-kd = ⌈⌉-kd j Γ-ctx
⌈j⌉∷Γ = wf-kd ⌈j⌉-kd ∷ Γ-ctx
in ∈-Π-i ⌈j⌉-kd (∈-⊤⟨⟩ k ⌈j⌉∷Γ)
-- ⊥⟨ k ⟩ and ⊤⟨ k ⟩ are extremal types in ⌈ k ⌉.
⊥⟨⟩-minimum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ ⌈ k ⌉ → Γ ⊢ ⊥⟨ k ⟩ <: a ∈ ⌈ k ⌉
⊥⟨⟩-minimum {k = ★ } a∈* = <:-⊥ a∈*
⊥⟨⟩-minimum {k = j ⇒ k} a∈⌈j⇒k⌉ =
<:-trans (<:-λ (⊥⟨⟩-minimum a·z∈⌈k⌉) (∈-⊥⟨⟩ (j ⇒ k) Γ-ctx) Λa·z∈⌈j⇒k⌉)
(<:-η₁ a∈⌈j⇒k⌉)
where
Γ-ctx = Tp∈-ctx a∈⌈j⇒k⌉
Λa·z∈⌈j⇒k⌉ = Tp∈-η a∈⌈j⇒k⌉
a·z∈⌈k⌉ = proj₂ (Tp∈-Λ-inv Λa·z∈⌈j⇒k⌉)
⊤⟨⟩-maximum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ ⌈ k ⌉ → Γ ⊢ a <: ⊤⟨ k ⟩ ∈ ⌈ k ⌉
⊤⟨⟩-maximum {k = ★ } a∈* = <:-⊤ a∈*
⊤⟨⟩-maximum {k = j ⇒ k} a∈⌈j⇒k⌉ =
<:-trans (<:-η₂ a∈⌈j⇒k⌉)
(<:-λ (⊤⟨⟩-maximum a·z∈⌈k⌉) Λa·z∈⌈j⇒k⌉ (∈-⊤⟨⟩ (j ⇒ k) Γ-ctx))
where
Γ-ctx = Tp∈-ctx a∈⌈j⇒k⌉
Λa·z∈⌈j⇒k⌉ = Tp∈-η a∈⌈j⇒k⌉
a·z∈⌈k⌉ = proj₂ (Tp∈-Λ-inv Λa·z∈⌈j⇒k⌉)
-- An alternate pair of higher-order extremal types inhabiting the
-- family of kinds ⌈ k ⌉↑, rather than ⌈ k ⌉.
⊥↑⟨_⟩ : ∀ {n} → SKind → Term n
⊥↑⟨ ★ ⟩ = ⊥
⊥↑⟨ j ⇒ k ⟩ = Λ ⌈ j ⌉↑ ⊥↑⟨ k ⟩
⊤↑⟨_⟩ : ∀ {n} → SKind → Term n
⊤↑⟨ ★ ⟩ = ⊤
⊤↑⟨ j ⇒ k ⟩ = Λ ⌈ j ⌉↑ ⊤↑⟨ k ⟩
-- ⊥↑⟨ k ⟩ and ⊤↑⟨ k ⟩ inhabit ⌈ k ⌉↑.
∈-⊥↑⟨⟩ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢Tp ⊥↑⟨ k ⟩ ∈ ⌈ k ⌉↑
∈-⊥↑⟨⟩ ★ Γ-ctx = ∈-⊥-f Γ-ctx
∈-⊥↑⟨⟩ (j ⇒ k) Γ-ctx =
let ⌈j⌉↑-kd = ⌈⌉↑-kd j Γ-ctx
⌈j⌉↑∷Γ = wf-kd ⌈j⌉↑-kd ∷ Γ-ctx
⌈k⌉↑-kd = ⌈⌉↑-kd k ⌈j⌉↑∷Γ
in ∈-⇑ (∈-Π-i ⌈j⌉↑-kd (∈-⊥↑⟨⟩ k ⌈j⌉↑∷Γ))
(<∷-Π (⌈⌉↓<∷⌈⌉↑ j Γ-ctx)
(<∷-refl (⌈⌉↑-kd k ((wf-kd (⌈⌉↓-kd j Γ-ctx)) ∷ Γ-ctx)))
(kd-Π ⌈j⌉↑-kd ⌈k⌉↑-kd))
∈-⊤↑⟨⟩ : ∀ {n} {Γ : Ctx n} k → Γ ctx → Γ ⊢Tp ⊤↑⟨ k ⟩ ∈ ⌈ k ⌉↑
∈-⊤↑⟨⟩ ★ Γ-ctx = ∈-⊤-f Γ-ctx
∈-⊤↑⟨⟩ (j ⇒ k) Γ-ctx =
let ⌈j⌉↑-kd = ⌈⌉↑-kd j Γ-ctx
⌈j⌉↑∷Γ = wf-kd ⌈j⌉↑-kd ∷ Γ-ctx
⌈k⌉↑-kd = ⌈⌉↑-kd k ⌈j⌉↑∷Γ
in ∈-⇑ (∈-Π-i ⌈j⌉↑-kd (∈-⊤↑⟨⟩ k ⌈j⌉↑∷Γ))
(<∷-Π (⌈⌉↓<∷⌈⌉↑ j Γ-ctx)
(<∷-refl (⌈⌉↑-kd k ((wf-kd (⌈⌉↓-kd j Γ-ctx)) ∷ Γ-ctx)))
(kd-Π ⌈j⌉↑-kd ⌈k⌉↑-kd))
-- ⊥↑⟨ k ⟩ and ⊤↑⟨ k ⟩ are extremal types in ⌈ k ⌉↑.
⊥↑⟨⟩-minimum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ k → Γ ⊢ ⊥↑⟨ ⌊ k ⌋ ⟩ <: a ∈ ⌈ ⌊ k ⌋ ⌉↑
⊥↑⟨⟩-minimum {k = b ⋯ c} a∈b⋯c = <:-⊥ a∈b⋯c
⊥↑⟨⟩-minimum {k = Π j k} a∈Πjk with Tp∈-valid a∈Πjk
... | kd-Π j-kd k-kd =
<:-trans (<:-λ (⊥↑⟨⟩-minimum a·z∈k′) (∈-⊥↑⟨⟩ ⌊ Π j k ⌋ Γ-ctx)
(∈-⇑ Λa·z∈Πjk Πjk<∷⌈Πjk⌉↑))
(<:-⇑ (<:-η₁ a∈Πjk) Πjk<∷⌈Πjk⌉↑)
where
Πjk<∷⌈Πjk⌉↑ = ⌈⌉↑-maximum (kd-Π j-kd k-kd)
Γ-ctx = Tp∈-ctx a∈Πjk
⌈⌊j⌋⌉↓<∷j = ⌈⌉↓-minimum j-kd
Λa·z∈Πjk = Tp∈-η a∈Πjk
a·z∈k = proj₂ (Tp∈-Λ-inv Λa·z∈Πjk)
a·z∈k′ = ⇓-Tp∈ ⌈⌊j⌋⌉↓<∷j a·z∈k
⊤↑⟨⟩-maximum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ k → Γ ⊢ a <: ⊤↑⟨ ⌊ k ⌋ ⟩ ∈ ⌈ ⌊ k ⌋ ⌉↑
⊤↑⟨⟩-maximum {k = b ⋯ c} a∈b⋯c = <:-⊤ a∈b⋯c
⊤↑⟨⟩-maximum {k = Π j k} a∈Πjk with Tp∈-valid a∈Πjk
... | kd-Π j-kd k-kd =
<:-trans (<:-⇑ (<:-η₂ a∈Πjk) Πjk<∷⌈Πjk⌉↑)
(<:-λ (⊤↑⟨⟩-maximum a·z∈k′) (∈-⇑ Λa·z∈Πjk Πjk<∷⌈Πjk⌉↑)
(∈-⊤↑⟨⟩ ⌊ Π j k ⌋ Γ-ctx))
where
Πjk<∷⌈Πjk⌉↑ = ⌈⌉↑-maximum (kd-Π j-kd k-kd)
Γ-ctx = Tp∈-ctx a∈Πjk
⌈⌊j⌋⌉↓<∷j = ⌈⌉↓-minimum j-kd
Λa·z∈Πjk = Tp∈-η a∈Πjk
a·z∈k = proj₂ (Tp∈-Λ-inv Λa·z∈Πjk)
a·z∈k′ = ⇓-Tp∈ ⌈⌊j⌋⌉↓<∷j a·z∈k
-- Yet another variant of higher-order extremal types, this time
-- indexed by possibly dependent kinds.
⊥′⟨_⟩ : ∀ {n} → Kind Term n → Term n
⊥′⟨ a ⋯ b ⟩ = ⊥
⊥′⟨ Π j k ⟩ = Λ j ⊥′⟨ k ⟩
⊤′⟨_⟩ : ∀ {n} → Kind Term n → Term n
⊤′⟨ a ⋯ b ⟩ = ⊤
⊤′⟨ Π j k ⟩ = Λ j ⊤′⟨ k ⟩
-- A higher-order variant of *.
*⟨_⟩ : ∀ {n} → Kind Term n → Kind Term n
*⟨ a ⋯ b ⟩ = *
*⟨ Π j k ⟩ = Π j *⟨ k ⟩
-- Substitution commutes with ⊥′⟨_⟩, ⊤′⟨_⟩ and *⟨_⟩.
module EncSubstLemmas {T} (l : Lift T Term) where
open SubstApp l
open Lift l hiding (var)
⊥′⟨⟩-/ : ∀ {n m} {σ : Sub T m n} k → ⊥′⟨ k ⟩ / σ ≡ ⊥′⟨ k Kind/ σ ⟩
⊥′⟨⟩-/ (a ⋯ b) = refl
⊥′⟨⟩-/ (Π j k) = cong (Λ _) (⊥′⟨⟩-/ k)
⊤′⟨⟩-/ : ∀ {n m} {σ : Sub T m n} k → ⊤′⟨ k ⟩ / σ ≡ ⊤′⟨ k Kind/ σ ⟩
⊤′⟨⟩-/ (a ⋯ b) = refl
⊤′⟨⟩-/ (Π j k) = cong (Λ _) (⊤′⟨⟩-/ k)
*⟨⟩-/ : ∀ {n m} {σ : Sub T m n} k → *⟨ k ⟩ Kind/ σ ≡ *⟨ k Kind/ σ ⟩
*⟨⟩-/ (a ⋯ b) = refl
*⟨⟩-/ (Π j k) = cong (Π _) (*⟨⟩-/ k)
open EncSubstLemmas (TermSubst.termLift termSubst) public
open EncSubstLemmas (TermSubst.varLift termSubst) public
renaming (⊥′⟨⟩-/ to ⊥′⟨⟩-/Var; ⊤′⟨⟩-/ to ⊤′⟨⟩-/Var; *⟨⟩-/ to *⟨⟩-/Var)
-- Well-formedness of higher-order star kinds.
kd-*⟨⟩ : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ *⟨ k ⟩ kd
kd-*⟨⟩ (kd-⋯ a∈* b∈*) = *-kd (Tp∈-ctx a∈*)
kd-*⟨⟩ (kd-Π j-kd k-kd) = kd-Π j-kd (kd-*⟨⟩ k-kd)
-- ⊥′⟨ k ⟩ and ⊤′⟨ k ⟩ inhabit *⟨ k ⟩.
∈-⊥′⟨⟩ : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢Tp ⊥′⟨ k ⟩ ∈ *⟨ k ⟩
∈-⊥′⟨⟩ (kd-⋯ a∈* b∈*) = ∈-⊥-f (Tp∈-ctx a∈*)
∈-⊥′⟨⟩ (kd-Π j-kd k-kd) = ∈-Π-i j-kd (∈-⊥′⟨⟩ k-kd)
∈-⊤′⟨⟩ : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢Tp ⊤′⟨ k ⟩ ∈ *⟨ k ⟩
∈-⊤′⟨⟩ (kd-⋯ a∈* b∈*) = ∈-⊤-f (Tp∈-ctx a∈*)
∈-⊤′⟨⟩ (kd-Π j-kd k-kd) = ∈-Π-i j-kd (∈-⊤′⟨⟩ k-kd)
-- A helper: any well-formed kind k is a subkind of *⟨ k ⟩.
*⟨⟩-maximum : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd → Γ ⊢ k <∷ *⟨ k ⟩
*⟨⟩-maximum (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-⊥ a∈*) (<:-⊤ b∈*)
*⟨⟩-maximum (kd-Π j-kd k-kd) =
<∷-Π (<∷-refl j-kd) (*⟨⟩-maximum k-kd) (kd-Π j-kd k-kd)
-- ⊥′⟨ k ⟩ and ⊤′⟨ k ⟩ are extremal types in *⟨ k ⟩.
⊥′⟨⟩-minimum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ k → Γ ⊢ ⊥′⟨ k ⟩ <: a ∈ *⟨ k ⟩
⊥′⟨⟩-minimum {k = b ⋯ c} a∈b⋯c = <:-⊥ a∈b⋯c
⊥′⟨⟩-minimum {k = Π j k} a∈Πjk =
<:-trans (<:-λ (⊥′⟨⟩-minimum a·z∈k) (∈-⊥′⟨⟩ Πjk-kd)
(∈-⇑ Λa·z∈Πjk Πjk-kd<∷*⟨Πjk⟩))
(<:-η₁ (∈-⇑ a∈Πjk Πjk-kd<∷*⟨Πjk⟩))
where
Λa·z∈Πjk = Tp∈-η a∈Πjk
a·z∈k = proj₂ (Tp∈-Λ-inv Λa·z∈Πjk)
Πjk-kd = Tp∈-valid a∈Πjk
Πjk-kd<∷*⟨Πjk⟩ = *⟨⟩-maximum Πjk-kd
⊤′⟨⟩-maximum : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ k → Γ ⊢ a <: ⊤′⟨ k ⟩ ∈ *⟨ k ⟩
⊤′⟨⟩-maximum {k = b ⋯ c} a∈b⋯c = <:-⊤ a∈b⋯c
⊤′⟨⟩-maximum {k = Π j k} a∈Πjk =
<:-trans (<:-η₂ (∈-⇑ a∈Πjk Πjk-kd<∷*⟨Πjk⟩))
(<:-λ (⊤′⟨⟩-maximum a·z∈k) (∈-⇑ Λa·z∈Πjk Πjk-kd<∷*⟨Πjk⟩)
(∈-⊤′⟨⟩ Πjk-kd))
where
Λa·z∈Πjk = Tp∈-η a∈Πjk
a·z∈k = proj₂ (Tp∈-Λ-inv Λa·z∈Πjk)
Πjk-kd = Tp∈-valid a∈Πjk
Πjk-kd<∷*⟨Πjk⟩ = *⟨⟩-maximum Πjk-kd
-- Applications of higher-order extrema result in lower-order extrema.
≃-⊥′⟨⟩-· : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ Π j k kd → Γ ⊢Tp a ∈ j →
Γ ⊢ ⊥′⟨ Π j k ⟩ · a ≃ ⊥′⟨ k Kind[ a ] ⟩ ∈ *⟨ k Kind[ a ] ⟩
≃-⊥′⟨⟩-· (kd-Π {j} {k} j-kd k-kd) a∈j =
subst₂ (_ ⊢ ⊥′⟨ Π j k ⟩ · _ ≃_∈_) (⊥′⟨⟩-/ _) (*⟨⟩-/ _)
(≃-β′ ⊥⟨k⟩ a∈j ⊥⟨Πjk⟩)
where
⊥⟨Πjk⟩ = ∈-⊥′⟨⟩ (kd-Π j-kd k-kd)
⊥⟨k⟩ = ∈-⊥′⟨⟩ k-kd
≃-⊤′⟨⟩-· : ∀ {n} {Γ : Ctx n} {a j k} → Γ ⊢ Π j k kd → Γ ⊢Tp a ∈ j →
Γ ⊢ ⊤′⟨ Π j k ⟩ · a ≃ ⊤′⟨ k Kind[ a ] ⟩ ∈ *⟨ k Kind[ a ] ⟩
≃-⊤′⟨⟩-· (kd-Π {j} {k} j-kd k-kd) a∈j =
subst₂ (_ ⊢ ⊤′⟨ Π j k ⟩ · _ ≃_∈_) (⊤′⟨⟩-/ _) (*⟨⟩-/ _)
(≃-β′ ⊤⟨k⟩ a∈j ⊤⟨Πjk⟩)
where
⊤⟨Πjk⟩ = ∈-⊤′⟨⟩ (kd-Π j-kd k-kd)
⊤⟨k⟩ = ∈-⊤′⟨⟩ k-kd
----------------------------------------------------------------------
-- Encodings and properties of higher-order intervals
infix 6 _⋯⟨_⟩_
-- Higher-order interval kinds.
_⋯⟨_⟩_ : ∀ {n} → Term n → Kind Term n → Term n → Kind Term n
a ⋯⟨ c ⋯ d ⟩ b = a ⋯ b
a ⋯⟨ Π j k ⟩ b = Π j (weaken a · var zero ⋯⟨ k ⟩ weaken b · var zero)
-- Higher order interval kinds have the same shape as their
-- kind-indices.
⌊⌋-⋯⟨⟩ : ∀ {n} {a b : Term n} k → ⌊ a ⋯⟨ k ⟩ b ⌋ ≡ ⌊ k ⌋
⌊⌋-⋯⟨⟩ (a ⋯ b) = refl
⌊⌋-⋯⟨⟩ (Π j k) = cong (⌊ j ⌋ ⇒_) (⌊⌋-⋯⟨⟩ k)
-- "Idempotence" of higher order interval kinds.
⋯⟨⟩-idempotent : ∀ {n} {a b : Term n} k → a ⋯⟨ a ⋯⟨ k ⟩ b ⟩ b ≡ a ⋯⟨ k ⟩ b
⋯⟨⟩-idempotent (a ⋯ b) = refl
⋯⟨⟩-idempotent (Π j k) = cong (Π j) (⋯⟨⟩-idempotent k)
-- Well-formedness of higher-order interval kinds.
kd-⋯⟨⟩ : ∀ {n} {Γ : Ctx n} {a b k} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → Γ ⊢ a ⋯⟨ k ⟩ b kd
kd-⋯⟨⟩ a∈k b∈k with Tp∈-valid a∈k
kd-⋯⟨⟩ a∈c⋯d b∈c⋯d | kd-⋯ _ _ = kd-⋯ (Tp∈-⋯-* a∈c⋯d) (Tp∈-⋯-* b∈c⋯d)
kd-⋯⟨⟩ a∈Πjk b∈Πjk | kd-Π j-kd k-kd =
kd-Π j-kd (kd-⋯⟨⟩ a·z∈k b·z∈k)
where
a·z∈k = proj₂ (Tp∈-Λ-inv (Tp∈-η a∈Πjk))
b·z∈k = proj₂ (Tp∈-Λ-inv (Tp∈-η b∈Πjk))
-- NOTE. We would like to show that the inverse of the above also
-- holds, i.e. that given a well-formed higher-order interval kind `a
-- ⋯⟨ k ⟩ b', we have `a ∈ k' and `b ∈ k'. Unfortunately this is not
-- true because the definition of `a ⋯⟨ k ⟩ b' is a bit too forgetful
-- when the kind-index `k' is itself an interval `k = c ⋯ d', that is,
-- when `a' and `b' are proper types. E.g. the kind `⊥ ⋯⟨ ∅ ⟩ ⊤' is
-- well-formed, but clearly `⊥ , ⊤ ∉ ø'.
--
-- However, as the following lemma illustrates, we can invert some
-- judgments about higher-order intervals with "sensible" kind
-- indices, such as those resulting from shapes via ⌈_⌉. Still, a
-- proper inversion lemma would require more work, in particular one
-- has to contract the kinding derivations of the η-expanded bounds
-- `a' and `b' back into their non-expanded form.
-- Higher-order interval kinds indexed by `⌈ k ⌉' for some `k' are
-- subkinds of `⌈ k ⌉'.
⋯⟨⌈⌉⟩-<∷-⌈⌉ : ∀ {n} {Γ : Ctx n} {a b k} →
Γ ⊢ a ⋯⟨ ⌈ k ⌉ ⟩ b kd → Γ ⊢ a ⋯⟨ ⌈ k ⌉ ⟩ b <∷ ⌈ k ⌉
⋯⟨⌈⌉⟩-<∷-⌈⌉ {k = ★ } (kd-⋯ a∈* b∈*) = <∷-⋯ (<:-⊥ a∈*) (<:-⊤ b∈*)
⋯⟨⌈⌉⟩-<∷-⌈⌉ {k = j ⇒ k} (kd-Π ⌈j⌉-kd a·z⋯⟨⌈k⌉⟩b·z-kd) =
<∷-Π (<∷-refl ⌈j⌉-kd) (⋯⟨⌈⌉⟩-<∷-⌈⌉ a·z⋯⟨⌈k⌉⟩b·z-kd)
(kd-Π ⌈j⌉-kd a·z⋯⟨⌈k⌉⟩b·z-kd)
-- Two corollaries.
-- Types inhabiting a type interval indexed by a shape `k' also
-- inhabit `⌈ k ⌉`.
Tp∈-⋯⟨⌈⌉⟩-inv : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢Tp a ∈ b ⋯⟨ ⌈ k ⌉ ⟩ c → Γ ⊢Tp a ∈ ⌈ k ⌉
Tp∈-⋯⟨⌈⌉⟩-inv a∈b⋯⟨⌈k⌉⟩c =
∈-⇑ a∈b⋯⟨⌈k⌉⟩c (⋯⟨⌈⌉⟩-<∷-⌈⌉ (Tp∈-valid a∈b⋯⟨⌈k⌉⟩c))
-- Types related in a type interval indexed by a shape `k' are also
-- related in `⌈ k ⌉`.
<:-⋯⟨⌈⌉⟩-inv : ∀ {n} {Γ : Ctx n} {a b c d k} →
Γ ⊢ a <: b ∈ c ⋯⟨ ⌈ k ⌉ ⟩ d → Γ ⊢ a <: b ∈ ⌈ k ⌉
<:-⋯⟨⌈⌉⟩-inv a<:b∈c⋯⟨⌈k⌉⟩d =
<:-⇑ a<:b∈c⋯⟨⌈k⌉⟩d (⋯⟨⌈⌉⟩-<∷-⌈⌉ (<:-valid-kd a<:b∈c⋯⟨⌈k⌉⟩d))
-- Subkinding of higher-order interval kinds.
<∷-⋯⟨⟩ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂ k} →
Γ ⊢ a₂ <: a₁ ∈ k → Γ ⊢ b₁ <: b₂ ∈ k → Γ ⊢ a₁ ⋯⟨ k ⟩ b₁ <∷ a₂ ⋯⟨ k ⟩ b₂
<∷-⋯⟨⟩ a₂<:a₁∈k b₁<:b₂∈k with <:-valid-kd a₂<:a₁∈k
<∷-⋯⟨⟩ a₂<:a₁∈c⋯d b₁<:b₂∈c⋯d | kd-⋯ _ _ =
<∷-⋯ (<:-⋯-* a₂<:a₁∈c⋯d) (<:-⋯-* b₁<:b₂∈c⋯d)
<∷-⋯⟨⟩ a₂<:a₁∈Πjk b₁<:b₂∈Πjk | kd-Π j-kd k-kd =
let a₂∈Πjk , a₁∈Πjk = <:-valid a₂<:a₁∈Πjk
b₁∈Πjk , b₂∈Πjk = <:-valid b₁<:b₂∈Πjk
Γ-ctx = kd-ctx j-kd
j-wf = wf-kd j-kd
j∷Γ-ctx = j-wf ∷ Γ-ctx
z∈k = ∈-var zero j∷Γ-ctx refl
z≃z∈k = ≃-refl z∈k
a₂<:a₁∈Πjk′ = <:-weaken j-wf a₂<:a₁∈Πjk
b₁<:b₂∈Πjk′ = <:-weaken j-wf b₁<:b₂∈Πjk
k[z]≡k = Kind-wk↑-sub-zero-vanishes _
a₂·z<:a₁·z∈k[z] = <:-· a₂<:a₁∈Πjk′ z≃z∈k
b₁·z<:b₂·z∈k[z] = <:-· b₁<:b₂∈Πjk′ z≃z∈k
a₂·z<:a₁·z∈k = subst (_ ⊢ _ <: _ ∈_) k[z]≡k a₂·z<:a₁·z∈k[z]
b₁·z<:b₂·z∈k = subst (_ ⊢ _ <: _ ∈_) k[z]≡k b₁·z<:b₂·z∈k[z]
in <∷-Π (<∷-refl j-kd)
(<∷-⋯⟨⟩ a₂·z<:a₁·z∈k b₁·z<:b₂·z∈k)
(kd-⋯⟨⟩ a₁∈Πjk b₁∈Πjk)
-- A corollary: equality of higher-order interval kinds.
≅-⋯⟨⟩ : ∀ {n} {Γ : Ctx n} {a₁ a₂ b₁ b₂ k} →
Γ ⊢ a₁ ≃ a₂ ∈ k → Γ ⊢ b₁ ≃ b₂ ∈ k → Γ ⊢ a₁ ⋯⟨ k ⟩ b₁ ≅ a₂ ⋯⟨ k ⟩ b₂
≅-⋯⟨⟩ (<:-antisym a₁<:a₂∈k a₂<:a₁∈k) (<:-antisym b₁<:b₂∈k b₂<:b₁∈k) =
<∷-antisym (<∷-⋯⟨⟩ a₂<:a₁∈k b₁<:b₂∈k) (<∷-⋯⟨⟩ a₁<:a₂∈k b₂<:b₁∈k)
-- A variant of kind-driven η-expansion that only expands the head.
η-exp : ∀ {n} → Kind Term n → Term n → Term n
η-exp (_ ⋯ _) a = a
η-exp (Π j k) a = Λ j (η-exp k (weaken a · var zero))
-- Soundness of η-expansion.
≃-η-exp : ∀ {n} {Γ : Ctx n} {a k} → Γ ⊢Tp a ∈ k → Γ ⊢ a ≃ η-exp k a ∈ k
≃-η-exp {_} {_} {_} {b ⋯ c} a∈b⋯c = ≃-refl a∈b⋯c
≃-η-exp {_} {_} {a} {Π j k} a∈Πjk with Tp∈-valid a∈Πjk
... | kd-Π j-kd k-kd = begin
a ≃⟨ ≃-sym (≃-η a∈Πjk) ⟩
Λ j (weaken a · var zero) ≃⟨ ≃-λ′ (≅-refl j-kd) (≃-η-exp a·z∈k) ⟩
Λ j (η-exp k (weaken a · var zero)) ∎
where
open ≃-Reasoning
a·z∈k = proj₂ (Tp∈-Λ-inv (Tp∈-η a∈Πjk))
-- A singleton introduction rule for higher-order interval kinds.
∈-s⟨⟩-i : ∀ {n} {Γ : Ctx n} {a k} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp η-exp k a ∈ a ⋯⟨ k ⟩ a
∈-s⟨⟩-i a∈k with Tp∈-valid a∈k
∈-s⟨⟩-i a∈b⋯c | kd-⋯ _ _ = ∈-s-i a∈b⋯c
∈-s⟨⟩-i a∈Πjk | kd-Π j-kd k-kd =
∈-Π-i j-kd (∈-s⟨⟩-i a·z∈k)
where
a·z∈k = proj₂ (Tp∈-Λ-inv (Tp∈-η a∈Πjk))
-- A corollary: we can kind (the η-expansion of) a type with explicit
-- lower and uper bounds in the interval defined by these bounds.
Tp∈-<:-⋯ : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢ b <: a ∈ k → Γ ⊢ a <: c ∈ k → Γ ⊢Tp η-exp k a ∈ b ⋯⟨ k ⟩ c
Tp∈-<:-⋯ b<:a∈k a<:c∈k =
∈-⇑ (∈-s⟨⟩-i (proj₁ (<:-valid a<:c∈k))) (<∷-⋯⟨⟩ b<:a∈k a<:c∈k)
-- Bound projection rules for higher-order intervals.
--
-- NOTE. These lemmas are a bit weaker than one might like. In
-- particular, the additional premises `Γ ⊢ a , b , c ∈ k' might seem
-- redundant. But recall that we cannot, in general, invert
-- well-formed higher-order intervals, i.e. `Γ ⊢ b ⋯⟨ k ⟩ c kd' does
-- *not* imply `Γ ⊢ b ∈ k' and `Γ ⊢ c ∈ k'. Similarly, `Γ ⊢ a ∈ b ⋯⟨
-- k ⟩ c' does *not* imply `Γ ⊢ a ∈ k'. To see this, consider again
-- the kind `⊥ ⋯⟨ ∅ ⟩ ⊤', which is well-formed and inhabited by both
-- `⊥' and `⊤', yet clearly `⊥ , ⊤ ∉ ø'.
<:-⋯⟨⟩-⟨|⟩ : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → Γ ⊢Tp c ∈ k →
Γ ⊢Tp a ∈ b ⋯⟨ k ⟩ c → Γ ⊢ b <: a ∈ k × Γ ⊢ a <: c ∈ k
<:-⋯⟨⟩-⟨|⟩ {k = _ ⋯ _} a∈d⋯e b∈d⋯e c∈d⋯e a∈b⋯c =
<:-⇑ (<:-⋯-i (<:-⟨| a∈b⋯c)) (<∷-⋯ (<:-⟨| b∈d⋯e) (<:-|⟩ a∈d⋯e)) ,
<:-⇑ (<:-⋯-i (<:-|⟩ a∈b⋯c)) (<∷-⋯ (<:-⟨| a∈d⋯e) (<:-|⟩ c∈d⋯e))
<:-⋯⟨⟩-⟨|⟩ {k = Π _ _} a∈Πjk b∈Πjk c∈Πjk a∈Πjb·z⋯⟨k⟩c·z =
let Λa·z∈Πjk = Tp∈-η a∈Πjk
Λb·z∈Πjk = Tp∈-η b∈Πjk
Λc·z∈Πjk = Tp∈-η c∈Πjk
_ , a·z∈k = Tp∈-Λ-inv Λa·z∈Πjk
_ , b·z∈k = Tp∈-Λ-inv Λb·z∈Πjk
_ , c·z∈k = Tp∈-Λ-inv Λc·z∈Πjk
Λa·z∈Πjb·z⋯⟨k⟩c·z = Tp∈-η a∈Πjb·z⋯⟨k⟩c·z
_ , a·z∈b·z⋯⟨k⟩c·z = Tp∈-Λ-inv Λa·z∈Πjb·z⋯⟨k⟩c·z
b·z<:a·z∈k , a·z<:c·z∈k = <:-⋯⟨⟩-⟨|⟩ a·z∈k b·z∈k c·z∈k a·z∈b·z⋯⟨k⟩c·z
Λjb·z<:Λja·z∈Πjk = <:-λ b·z<:a·z∈k Λb·z∈Πjk Λa·z∈Πjk
Λja·z<:Λjc·z∈Πjk = <:-λ a·z<:c·z∈k Λa·z∈Πjk Λc·z∈Πjk
Λja·z<:a∈kΠjk = <:-η₁ a∈Πjk
a<:Λja·z∈kΠjk = <:-η₂ a∈Πjk
Λjc·z<:c∈kΠjk = <:-η₁ c∈Πjk
b<:Λjb·z∈kΠjk = <:-η₂ b∈Πjk
in <:-trans (<:-trans b<:Λjb·z∈kΠjk Λjb·z<:Λja·z∈Πjk) Λja·z<:a∈kΠjk ,
<:-trans (<:-trans a<:Λja·z∈kΠjk Λja·z<:Λjc·z∈Πjk) Λjc·z<:c∈kΠjk
<:-⋯⟨⟩-⟨| : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → Γ ⊢Tp c ∈ k →
Γ ⊢Tp a ∈ b ⋯⟨ k ⟩ c → Γ ⊢ b <: a ∈ k
<:-⋯⟨⟩-⟨| a∈k b∈k c∈k a∈b⋯⟨k⟩c = proj₁ (<:-⋯⟨⟩-⟨|⟩ a∈k b∈k c∈k a∈b⋯⟨k⟩c)
<:-⋯⟨⟩-|⟩ : ∀ {n} {Γ : Ctx n} {a b c k} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → Γ ⊢Tp c ∈ k →
Γ ⊢Tp a ∈ b ⋯⟨ k ⟩ c → Γ ⊢ a <: c ∈ k
<:-⋯⟨⟩-|⟩ a∈k b∈k c∈k a∈b⋯⟨k⟩c = proj₂ (<:-⋯⟨⟩-⟨|⟩ a∈k b∈k c∈k a∈b⋯⟨k⟩c)
-- An interval introduction rule for subtypes inhabiting higher-order
-- interval kinds.
<:-⋯⟨⟩-i : ∀ {n} {Γ : Ctx n} {a b k} →
Γ ⊢ a <: b ∈ k → Γ ⊢ η-exp k a <: η-exp k b ∈ a ⋯⟨ k ⟩ b
<:-⋯⟨⟩-i a<:b∈k with <:-valid-kd a<:b∈k
<:-⋯⟨⟩-i a<:b∈c⋯d | kd-⋯ _ _ = <:-⋯-i a<:b∈c⋯d
<:-⋯⟨⟩-i a<:b∈Πjk | kd-Π j-kd _ =
let j-wf = wf-kd j-kd
Γ-ctx = <:-ctx a<:b∈Πjk
j∷Γ-ctx = j-wf ∷ Γ-ctx
a∈Πjk , b∈Πjk = <:-valid a<:b∈Πjk
a<:b∈Πjk′ = <:-weaken j-wf a<:b∈Πjk
a·z<:b·z∈k[z] = <:-· a<:b∈Πjk′ (≃-refl (∈-var zero j∷Γ-ctx refl))
a·z<:b·z∈k = subst (_ ⊢ _ <: _ ∈_) (Kind-wk↑-sub-zero-vanishes _)
a·z<:b·z∈k[z]
a·z<:b·z∈a·z⋯⟨k⟩b·z = <:-⋯⟨⟩-i a·z<:b·z∈k
in <:-λ a·z<:b·z∈a·z⋯⟨k⟩b·z
(∈-⇑ (∈-s⟨⟩-i a∈Πjk) (<∷-⋯⟨⟩ (<:-refl a∈Πjk) a<:b∈Πjk))
(∈-⇑ (∈-s⟨⟩-i b∈Πjk) (<∷-⋯⟨⟩ a<:b∈Πjk (<:-refl b∈Πjk)))
-- Any interval indexed by *⟨ k ⟩ can be re-indexed by k
*⟨⟩-⋯⟨⟩ : ∀ {n} {a b : Term n} k → a ⋯⟨ *⟨ k ⟩ ⟩ b ≡ a ⋯⟨ k ⟩ b
*⟨⟩-⋯⟨⟩ (a ⋯ b) = refl
*⟨⟩-⋯⟨⟩ (Π j k) = cong (Π j) (*⟨⟩-⋯⟨⟩ k)
-- *⟨ k ⟩ is equal to the HO interval bounded by ⊥′⟨ k ⟩ and ⊤′⟨ k ⟩.
*⟨⟩-⊥⟨⟩⋯⟨⟩⊤⟨⟩ : ∀ {n} {Γ : Ctx n} {k} → Γ ⊢ k kd →
Γ ⊢ *⟨ k ⟩ ≅ ⊥′⟨ k ⟩ ⋯⟨ k ⟩ ⊤′⟨ k ⟩
*⟨⟩-⊥⟨⟩⋯⟨⟩⊤⟨⟩ (kd-⋯ a∈* b∈*) = ≅-refl (*-kd (Tp∈-ctx a∈*))
*⟨⟩-⊥⟨⟩⋯⟨⟩⊤⟨⟩ {_} {Γ} (kd-Π {j} {k} j-kd k-kd) =
≅-Π (≅-refl j-kd)
(≅-trans (*⟨⟩-⊥⟨⟩⋯⟨⟩⊤⟨⟩ k-kd)
(subst₂ (_ ⊢_≅_) (*⟨⟩-⋯⟨⟩ k) (*⟨⟩-⋯⟨⟩ k)
(≅-⋯⟨⟩ ⊥⟨k⟩≃Λ⊥⟨k⟩·z ⊤⟨k⟩≃Λ⊤⟨k⟩·z)))
where
module KL = TermLikeLemmas termLikeLemmasKind
Γ-ctx = kd-ctx j-kd
z∈j = ∈-var zero (wf-kd j-kd ∷ Γ-ctx) refl
Πjk-kd′ = kd-weaken (wf-kd j-kd) (kd-Π j-kd k-kd)
eq₁ = cong (λ k → (Λ (weakenKind j) k) · var zero) (sym (⊥′⟨⟩-/Var k))
eq₂ = cong (λ k → (Λ (weakenKind j) k) · var zero) (sym (⊤′⟨⟩-/Var k))
k′[z] = (k Kind/Var _) Kind[ var zero ]
⊥⟨k⟩≃Λ⊥⟨k⟩·z = subst₂ (_ ⊢_≃ weaken (Λ j ⊥′⟨ k ⟩) · var zero ∈_)
(cong ⊥′⟨_⟩ (Kind-wk↑-sub-zero-vanishes k))
(cong *⟨_⟩ (Kind-wk↑-sub-zero-vanishes k))
(subst (kd j ∷ Γ ⊢ ⊥′⟨ k′[z] ⟩ ≃_∈ *⟨ k′[z] ⟩) eq₁
(≃-sym (≃-⊥′⟨⟩-· Πjk-kd′ z∈j)))
⊤⟨k⟩≃Λ⊤⟨k⟩·z = subst₂ (_ ⊢_≃ weaken (Λ j ⊤′⟨ k ⟩) · var zero ∈_)
(cong ⊤′⟨_⟩ (Kind-wk↑-sub-zero-vanishes k))
(cong *⟨_⟩ (Kind-wk↑-sub-zero-vanishes k))
(subst (kd j ∷ Γ ⊢ ⊤′⟨ k′[z] ⟩ ≃_∈ *⟨ k′[z] ⟩) eq₂
(≃-sym (≃-⊤′⟨⟩-· Πjk-kd′ z∈j)))
----------------------------------------------------------------------
-- Encodings and admissible kinding rules of bounded quantifiers and
-- operators
-- Bounded operator kind.
Π′ : ∀ {n} → Term n → Term n → Kind Term n → Kind Term (suc n) → Kind Term n
Π′ a b j k = Π (a ⋯⟨ j ⟩ b) k
-- Bounded universal quantifiers.
∀′ : ∀ {n} → Term n → Term n → Kind Term n → Term (suc n) → Term n
∀′ a b k c = Π (a ⋯⟨ k ⟩ b) c
-- Bounded type abstraction.
Λ′ : ∀ {n} → Term n → Term n → Kind Term n → Term (suc n) → Term n
Λ′ a b k c = Λ (a ⋯⟨ k ⟩ b) c
-- A formation rule for bounded operator kinds.
∈-Π′-f : ∀ {n} {Γ : Ctx n} {a b j k} →
Γ ⊢Tp a ∈ j → Γ ⊢Tp b ∈ j → kd (a ⋯⟨ j ⟩ b) ∷ Γ ⊢ k kd →
Γ ⊢ Π′ a b j k kd
∈-Π′-f a∈j b∈j k-kd = kd-Π (kd-⋯⟨⟩ a∈j b∈j) k-kd
-- An introduction rule for bounded universal quantifiers.
∈-Π′-i : ∀ {n} {Γ : Ctx n} {a b j c k} →
Γ ⊢Tp a ∈ j → Γ ⊢Tp b ∈ j → kd (a ⋯⟨ j ⟩ b) ∷ Γ ⊢Tp c ∈ k →
Γ ⊢Tp Λ′ a b j c ∈ Π′ a b j k
∈-Π′-i a∈j b∈j c∈k = ∈-Π-i (kd-⋯⟨⟩ a∈j b∈j) c∈k
-- An elimination rule for bounded universal quantifiers.
∈-Π′-e : ∀ {n} {Γ : Ctx n} {a b c j k d} →
Γ ⊢Tp a ∈ Π′ b c j k → Γ ⊢ b <: d ∈ j → Γ ⊢ d <: c ∈ j →
Γ ⊢Tp a · η-exp j d ∈ k Kind[ η-exp j d ]
∈-Π′-e a∈Πbcjk b<:d∈j d<:c∈j =
let d∈j , _ = <:-valid d<:c∈j
in ∈-Π-e a∈Πbcjk (Tp∈-<:-⋯ b<:d∈j d<:c∈j)
-- A formation rule for bounded universal quantifiers.
∈-∀′-f : ∀ {n} {Γ : Ctx n} {a b k c} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → kd (a ⋯⟨ k ⟩ b) ∷ Γ ⊢Tp c ∈ * →
Γ ⊢Tp ∀′ a b k c ∈ *
∈-∀′-f a∈k b∈k c∈* = ∈-∀-f (kd-⋯⟨⟩ a∈k b∈k) c∈*
-- An introduction rule for bounded universal quantifiers.
∈-∀′-i : ∀ {n} {Γ : Ctx n} {a b k c d} →
Γ ⊢Tp a ∈ k → Γ ⊢Tp b ∈ k → kd (a ⋯⟨ k ⟩ b) ∷ Γ ⊢Tm c ∈ d →
Γ ⊢Tm Λ′ a b k c ∈ ∀′ a b k d
∈-∀′-i a∈k b∈k c∈d = ∈-∀-i (kd-⋯⟨⟩ a∈k b∈k) c∈d
-- An elimination rule for bounded universal quantifiers.
∈-∀′-e : ∀ {n} {Γ : Ctx n} {a b c k d e} →
Γ ⊢Tm a ∈ ∀′ b c k d → Γ ⊢ b <: e ∈ k → Γ ⊢ e <: c ∈ k →
Γ ⊢Tm a ⊡ η-exp k e ∈ d [ η-exp k e ]
∈-∀′-e a∈∀bckd b<:e∈k e<:c∈k =
let e∈k , _ = <:-valid e<:c∈k
in ∈-∀-e a∈∀bckd (Tp∈-<:-⋯ b<:e∈k e<:c∈k)
------------------------------------------------------------------------
-- Stone and Harper's singleton (sub)kinding rules.
--
-- See p. 3 (216) of C. A. Stone and R. Harper, Deciding Type
-- Equivalence in a Language with Singleton Kinds, proc. POPL'00, ACM,
-- 2000.
-- An encoding of Stone and Harper's singleton kinds.
S : ∀ {n} → Term n → Kind Term n
S a = a ⋯ a
-- Singleton kind formation.
kd-s : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢Tp a ∈ * → Γ ⊢ S a kd
kd-s a∈* = kd-⋯ a∈* a∈*
-- Singleton introduction for kinding is exactly the `∈-s-i' kinding rule.
-- Singleton introduction for equality.
--
-- NOTE. This is just a weaker version of `≃-s-i'.
≃-s-i′ : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ≃ b ∈ * → Γ ⊢ a ≃ b ∈ S a
≃-s-i′ a≃b∈* = ≃-s-i a≃b∈*
-- Singleton elimination.
≃-s-e : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tp a ∈ S b → Γ ⊢ a ≃ b ∈ *
≃-s-e a∈b⋯b = <:-antisym (<:-|⟩ a∈b⋯b) (<:-⟨| a∈b⋯b)
-- Subkinding of singletons.
<∷-s-* : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢Tp a ∈ * → Γ ⊢ S a <∷ *
<∷-s-* a∈* = <∷-⋯ (<:-⊥ a∈*) (<:-⊤ a∈*)
<∷-s-s : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ≃ b ∈ * → Γ ⊢ S a <∷ S b
<∷-s-s (<:-antisym a<:b∈* b<:a∈*) = <∷-⋯ b<:a∈* a<:b∈*
-- Equality of singleton kinds.
--
-- NOTE. This is just a weaker version of `≅-⋯'.
≅-s : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a ≃ b ∈ * → Γ ⊢ S a ≅ S b
≅-s a≃b∈* = ≅-⋯ a≃b∈* a≃b∈*
------------------------------------------------------------------------
-- Cardelli and Longo's power (sub)kinding rules.
--
-- See p. 8 (424) of L. Cardelli, G. Longo, A Semantic Basis for
-- Quest, JFP 1(4), Cambridge University Press, 1991.
-- An encoding of Cardelli and Longo's power kinds.
P : ∀ {n} → Term n → Kind Term n
P a = ⊥ ⋯ a
-- Power kind formation.
kd-p : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢Tp a ∈ * → Γ ⊢ P a kd
kd-p a∈* = kd-⋯ (∈-⊥-f (Tp∈-ctx a∈*)) a∈*
-- Power kind introduction.
∈-p-i : ∀ {n} {Γ : Ctx n} {a} → Γ ⊢Tp a ∈ * → Γ ⊢Tp a ∈ P a
∈-p-i a∈* = ∈-⇑ (∈-s-i a∈*) (<∷-⋯ (<:-⊥ a∈*) (<:-refl a∈*))
-- Subkinding of power kinds.
<∷-p : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a <: b ∈ * → Γ ⊢ P a <∷ P b
<∷-p a<:b∈* = <∷-⋯ (<:-⊥ (∈-⊥-f (<:-ctx a<:b∈*))) a<:b∈*
-- Power kinding is equivalent to subtyping of proper types.
∈P⇒<: : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢Tp a ∈ P b → Γ ⊢ a <: b ∈ *
∈P⇒<: a∈Pb = <:-|⟩ a∈Pb
<:⇒∈P : ∀ {n} {Γ : Ctx n} {a b} → Γ ⊢ a <: b ∈ * → Γ ⊢Tp a ∈ P b
<:⇒∈P a<:b∈* = ∈-⇑ (∈-p-i (proj₁ (<:-valid a<:b∈*))) (<∷-p a<:b∈*)
|
{
"alphanum_fraction": 0.4216097254,
"avg_line_length": 35.4282178218,
"ext": "agda",
"hexsha": "28314b21e1556c00b30de982f8b6c4dc88917684",
"lang": "Agda",
"max_forks_count": 2,
"max_forks_repo_forks_event_max_datetime": "2021-05-14T10:25:05.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-05-13T22:29:48.000Z",
"max_forks_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Blaisorblade/f-omega-int-agda",
"max_forks_repo_path": "src/FOmegaInt/Typing/Encodings.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_issues_repo_issues_event_max_datetime": "2021-05-14T08:54:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2021-05-14T08:09:40.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Blaisorblade/f-omega-int-agda",
"max_issues_repo_path": "src/FOmegaInt/Typing/Encodings.agda",
"max_line_length": 79,
"max_stars_count": 12,
"max_stars_repo_head_hexsha": "ae20dac2a5e0c18dff2afda4c19954e24d73a24f",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Blaisorblade/f-omega-int-agda",
"max_stars_repo_path": "src/FOmegaInt/Typing/Encodings.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-27T05:53:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2017-06-13T16:05:35.000Z",
"num_tokens": 17635,
"size": 28626
}
|
module Ex6Edit where -- git would rather indicate that nothing has happened 0/15
{- This is the file where you should work. -}
open import CS410-Prelude
open import CS410-Nat
open import Ex6AgdaSetup
-- the setup gives you a nondependent pair type _**_
-- because that's what the compiler can exchange with Haskell code
{- The key editor data structure is the cursor. A Cursor M X represents
being somewhere in the middle of a sequence of X values, holding an M. -}
record Cursor (M X : Set) : Set where
constructor _<[_]>_
field
beforeMe : Bwd X
atMe : M
afterMe : List X
infix 2 _<[_]>_
{- An editor buffer is a nested cursor: we're in the middle of a bunch of
*lines*, holding a cursor for the current line, which puts us in the
middle of a bunch of characters, holding the element of One. -}
Buffer : Set
Buffer = Cursor (Cursor One Char) (List Char)
{- This operator, called "chips", shuffles the elements from a backward list
on to the start of a forward list, keeping them in the same order. -}
_<>>_ : {X : Set} -> Bwd X -> List X -> List X
[] <>> xs = xs
(xz <: x) <>> xs = xz <>> (x :: xs)
{- The "fish" operator goes the other way. -}
_<><_ : {X : Set} -> Bwd X -> List X -> Bwd X
xz <>< [] = xz
xz <>< (x :: xs) = (xz <: x) <>< xs
{- You can turn a buffer into a list of lines, preserving its text. -}
bufText : Buffer -> List (List Char)
bufText
(sz <[
cz <[ <> ]> cs
]> ss)
= sz <>> ((cz <>> cs) :: ss)
{- Here's an example of a proof of a fact about fish and chips. -}
firstFishFact : {X : Set} -> (xz : Bwd X)(xs : List X) ->
(xz <>< xs) <>> [] == xz <>> xs
firstFishFact xz [] = refl
firstFishFact xz (x :: xs) = firstFishFact (xz <: x) xs
{- You will need more such facts. -}
{- EXERCISE 6.1 -}
{- When we start the editor with the command
./Edit foo.txt
the contents of foo.txt will be turned into a list of lines.
Your (not so tricky) mission is to turn the file contents into a buffer which
contains the same text.
(1 mark)
-}
initBuf : List (List Char) -> Buffer
initBuf ss =
[] <[
[] <[ <> ]> []
]> []
{- As you can see, the current version will run, but it always gives the empty
buffer, which is not what we want unless the input is empty. -}
{- Next comes the heart of the editor. You get a keystroke and the current buffer,
and you have to say what is the new buffer. You also have to say what is the
extent of the change.
The tricky part is this: you have to be honest enough about your change
report, so that we don't underestimate the amount of updating the screen needs.
-}
Honest : Buffer -> Change ** Buffer -> Set
Honest b (allQuiet , b') = b == b'
Honest b (cursorMove , b') = bufText b == bufText b'
Honest (sz <[ _ ]> ss) (lineEdit , (sz' <[ _ ]> ss')) = (sz == sz') ** (ss == ss')
Honest _ (bigChange , _) = One
record UpdateFrom (b : Buffer) : Set where -- b is the starting buffer
constructor _///_
field
update : Change ** Buffer -- change and new buffer
honest : Honest b update
open UpdateFrom
infix 2 _///_
{- EXERCISE 6.2 -}
{- Implement the appropriate behaviour for as many keystrokes as you can.
I have done a couple for you, but I don't promise to have done them
correctly. -}
keystroke : Key -> (b : Buffer) -> UpdateFrom b
keystroke (char c)
(sz <[
cz <[ <> ]> cs
]> ss)
= lineEdit ,
(sz <[
cz <[ <> ]> c :: cs
]> ss)
/// refl , refl -- see? same above and below
keystroke (arrow normal right)
(sz <: s <[
[] <[ <> ]> cs
]> ss)
= cursorMove ,
(sz <[ ([] <>< s) <[ <> ]> [] ]> cs :: ss)
/// within (\ x -> sz <>> (x :: cs :: ss)) turn s into ([] <>< s) <>> []
because sym (firstFishFact [] s)
keystroke k b = allQuiet , b /// refl
{- Please expect to need to invent extra functions, e.g., to measure where you
are, so that up and down arrow work properly. -}
{- Remember also that you can always overestimate the change by saying bigChange,
which needs only a trivial proof. But you may find that the display will flicker
badly if you do. -}
{- (char c) 1 mark
enter 2 marks
backspace delete 2 marks for the pair
left right 2 marks for the pair (with cursorMove change)
up down 2 marks for the pair (with cursorMove change)
-}
{- EXERCISE 6.3 -}
{- You will need to improve substantially on my implementation of the next component,
whose purpose is to update the window. Mine displays only one line! -}
render :
Nat ** Nat -> -- height and width of window -- CORRECTION! width and height
Nat ** Nat -> -- first visible row, first visible column
Change ** Buffer -> -- what just happened
List Action ** -- how to update screen
(Nat ** Nat) -- new first visible row, first visible column
render _ tl (allQuiet , _) = ([] , tl)
render _ tl (_ , (_ <[ cz <[ <> ]> cs ]> _))
= (goRowCol 0 0 :: sendText (cz <>> cs) :: []) , tl
{- The editor window gives you a resizable rectangular viewport onto the editor buffer.
You get told
the current size of the viewport
which row and col of the buffer are at the top left of the viewport
(so you can handle documents which are taller or wider than the window)
the most recent change report and buffer
You need to figure out whether you need to move the viewport
(by finding out if the cursor is still within the viewport)
and if so, where to.
You need to figure out what to redisplay. If the change report says
lineEdit and the viewport has not moved, you need only repaint the
current line. If the viewport has moved or the change report says
bigChange, you need to repaint the whole buffer.
You will need to be able to grab a rectangular region of text from the
buffer, but you do know how big and where from.
Remember to put the cursor in the right place, relative to where in
the buffer the viewport is supposed to be. The goRowCol action takes
*viewport* coordinates, not *buffer* coordinates! You will need to
invent subtraction!
-}
{- Your code does not need to worry about resizing the window. My code does
that. On detecting a size change, my code just calls your code with a
bigChange report and the same buffer, so if you are doing a proper repaint,
the right thing will happen. -}
{- 2 marks for ensuring that a buffer smaller than the viewport displays
correctly, with the cursor in the right place, if nobody changes
the viewport size
2 marks for ensuring that the cursor remains within the viewport even if
the viewport needs to move
1 mark for ensuring that lineEdit changes need only affect one line of
the display (provided the cursor stays in the viewport)
-}
{- Your code then hooks into mine to produce a top level executable! -}
main : IO One
main = mainLoop initBuf (\ k b -> update (keystroke k b)) render
{- To build the editor, just do
make Ex6Edit
in a shell window.
To run the editor, once compiled, do
make edit
in the shell window, which should become the editor window.
To quit the editor, do
ctrl-C
like an old-fashioned soul.
-}
{- There is no one right way to do this exercise, and there is some scope for
extension. It's important that you get in touch if you need help, either in
achieving the basic deliverable, or in finding ways to explore beyond it.
-}
|
{
"alphanum_fraction": 0.6414846012,
"avg_line_length": 38.3737373737,
"ext": "agda",
"hexsha": "4096d093cd6b6f3e1b0340e5ae9fcf334ef7e5e7",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "clarkdm/CS410",
"max_forks_repo_path": "Ex6Edit.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "clarkdm/CS410",
"max_issues_repo_path": "Ex6Edit.agda",
"max_line_length": 87,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "523a8749f49c914bcd28402116dcbe79a78dbbf4",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "clarkdm/CS410",
"max_stars_repo_path": "Ex6Edit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2053,
"size": 7598
}
|
{-
Defines different notions of morphisms and properties of morphisms of
groups:
- GroupHom (homomorphisms)
- GroupEquiv (equivs which are homomorphisms)
- GroupIso (isos which are homomorphisms)
- Image
- Kernel
- Surjective
- Injective
- Mono
- BijectionIso (surjective + injective)
-}
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Morphisms where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Structure
open import Cubical.Algebra.Group.Base
open import Cubical.Algebra.Group.DirProd
open import Cubical.Data.Sigma
open import Cubical.Reflection.RecordEquiv
private
variable
ℓ ℓ' ℓ'' ℓ''' : Level
record IsGroupHom {A : Type ℓ} {B : Type ℓ'}
(M : GroupStr A) (f : A → B) (N : GroupStr B)
: Type (ℓ-max ℓ ℓ')
where
-- Shorter qualified names
private
module M = GroupStr M
module N = GroupStr N
field
pres· : (x y : A) → f (x M.· y) ≡ f x N.· f y
pres1 : f M.1g ≡ N.1g
presinv : (x : A) → f (M.inv x) ≡ N.inv (f x)
unquoteDecl IsGroupHomIsoΣ = declareRecordIsoΣ IsGroupHomIsoΣ (quote IsGroupHom)
GroupHom : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupHom G H = Σ[ f ∈ (G .fst → H .fst) ] IsGroupHom (G .snd) f (H .snd)
GroupIso : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupIso G H = Σ[ e ∈ Iso (G .fst) (H .fst) ] IsGroupHom (G .snd) (e .Iso.fun) (H .snd)
IsGroupEquiv : {A : Type ℓ} {B : Type ℓ'}
(M : GroupStr A) (e : A ≃ B) (N : GroupStr B) → Type (ℓ-max ℓ ℓ')
IsGroupEquiv M e N = IsGroupHom M (e .fst) N
GroupEquiv : (G : Group ℓ) (H : Group ℓ') → Type (ℓ-max ℓ ℓ')
GroupEquiv G H = Σ[ e ∈ (G .fst ≃ H .fst) ] IsGroupEquiv (G .snd) e (H .snd)
groupEquivFun : {G : Group ℓ} {H : Group ℓ'} → GroupEquiv G H → G .fst → H .fst
groupEquivFun e = e .fst .fst
-- Image, kernel, surjective, injective, and bijections
open IsGroupHom
open GroupStr
private
variable
G H : Group ℓ
isInIm : GroupHom G H → ⟨ H ⟩ → Type _
isInIm {G = G} ϕ h = ∃[ g ∈ ⟨ G ⟩ ] ϕ .fst g ≡ h
isInKer : GroupHom G H → ⟨ G ⟩ → Type _
isInKer {H = H} ϕ g = ϕ .fst g ≡ 1g (snd H)
Ker : GroupHom G H → Type _
Ker {G = G} ϕ = Σ[ x ∈ ⟨ G ⟩ ] isInKer ϕ x
Im : GroupHom G H → Type _
Im {H = H} ϕ = Σ[ x ∈ ⟨ H ⟩ ] isInIm ϕ x
isSurjective : GroupHom G H → Type _
isSurjective {H = H} ϕ = (x : ⟨ H ⟩) → isInIm ϕ x
isInjective : GroupHom G H → Type _
isInjective {G = G} ϕ = (x : ⟨ G ⟩) → isInKer ϕ x → x ≡ 1g (snd G)
isMono : GroupHom G H → Type _
isMono {G = G} f = {x y : ⟨ G ⟩} → f .fst x ≡ f .fst y → x ≡ y
-- Group bijections
record BijectionIso (G : Group ℓ) (H : Group ℓ') : Type (ℓ-max ℓ ℓ') where
constructor bijIso
field
fun : GroupHom G H
inj : isInjective fun
surj : isSurjective fun
|
{
"alphanum_fraction": 0.6261682243,
"avg_line_length": 26,
"ext": "agda",
"hexsha": "38ff0c7d44177b63928104cc0edf30a62e7f93ab",
"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/Algebra/Group/Morphisms.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/Algebra/Group/Morphisms.agda",
"max_line_length": 87,
"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/Algebra/Group/Morphisms.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-05T00:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-03-05T00:30:17.000Z",
"num_tokens": 1088,
"size": 2782
}
|
-- Showing that destroy-guardedness in Issue1209-4 indeed does
-- destroy guardedness
{-# OPTIONS --safe --guardedness --no-sized-types #-}
record Stream (A : Set) : Set where
coinductive
field
head : A
tail : Stream A
open Stream
destroy-guardedness : ∀ {A} → Stream A → Stream A
destroy-guardedness xs .head = xs .head
destroy-guardedness xs .tail = xs .tail
repeat : ∀ {A} → A → Stream A
repeat x .head = x
repeat x .tail = destroy-guardedness (repeat x)
|
{
"alphanum_fraction": 0.6842105263,
"avg_line_length": 22.619047619,
"ext": "agda",
"hexsha": "57119ee0b5bf2c0cee612da09b1832809832d86a",
"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/Issue1209-4-2.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/Issue1209-4-2.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/Fail/Issue1209-4-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": 138,
"size": 475
}
|
open import Nat
open import Prelude
open import contexts
open import core
open import canonical-value-forms
module canonical-boxed-forms where
canonical-boxed-forms-b : ∀{Δ d} →
Δ , ∅ ⊢ d :: b →
d boxedval →
d == c
canonical-boxed-forms-b (TAVar _) (BVVal ())
canonical-boxed-forms-b wt (BVVal v) = canonical-value-forms-b wt v
-- this type gives somewhat nicer syntax for the output of the canonical
-- forms lemma for boxed values at arrow type
data cbf-arr : (Δ : hctx) (d : ihexp) (τ1 τ2 : htyp) → Set where
CBFLam : ∀{Δ d τ1 τ2} →
(Σ[ x ∈ Nat ] Σ[ d' ∈ ihexp ]
(d == (·λ x [ τ1 ] d') × Δ , ■ (x , τ1) ⊢ d' :: τ2))
→ cbf-arr Δ d τ1 τ2
CBFCastArr : ∀{Δ d τ1 τ2} →
(Σ[ d' ∈ ihexp ] Σ[ τ1' ∈ htyp ] Σ[ τ2' ∈ htyp ]
(d == (d' ⟨ τ1' ==> τ2' ⇒ τ1 ==> τ2 ⟩) ×
(τ1' ==> τ2' ≠ τ1 ==> τ2) ×
(Δ , ∅ ⊢ d' :: τ1' ==> τ2')))
→ cbf-arr Δ d τ1 τ2
canonical-boxed-forms-arr : ∀{Δ d τ1 τ2 } →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d boxedval →
cbf-arr Δ d τ1 τ2
canonical-boxed-forms-arr (TAVar x₁) (BVVal ())
canonical-boxed-forms-arr (TALam f wt) (BVVal v) = CBFLam (canonical-value-forms-arr (TALam f wt) v)
canonical-boxed-forms-arr (TAAp wt wt₁) (BVVal ())
canonical-boxed-forms-arr (TAEHole x x₁) (BVVal ())
canonical-boxed-forms-arr (TANEHole x wt x₁) (BVVal ())
canonical-boxed-forms-arr (TACast wt x) (BVVal ())
canonical-boxed-forms-arr (TACast wt x) (BVArrCast x₁ bv) = CBFCastArr (_ , _ , _ , refl , x₁ , wt)
canonical-boxed-forms-arr (TAFailedCast x x₁ x₂ x₃) (BVVal ())
canonical-boxed-forms-hole : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇-⦈ →
d boxedval →
Σ[ d' ∈ ihexp ] Σ[ τ' ∈ htyp ]
((d == d' ⟨ τ' ⇒ ⦇-⦈ ⟩) ×
(τ' ground) ×
(Δ , ∅ ⊢ d' :: τ'))
canonical-boxed-forms-hole (TAVar x₁) (BVVal ())
canonical-boxed-forms-hole (TAAp wt wt₁) (BVVal ())
canonical-boxed-forms-hole (TAEHole x x₁) (BVVal ())
canonical-boxed-forms-hole (TANEHole x wt x₁) (BVVal ())
canonical-boxed-forms-hole (TACast wt x) (BVVal ())
canonical-boxed-forms-hole (TACast wt x) (BVHoleCast x₁ bv) = _ , _ , refl , x₁ , wt
canonical-boxed-forms-hole (TAFailedCast x x₁ x₂ x₃) (BVVal ())
canonical-boxed-forms-coverage : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d boxedval →
τ ≠ b →
((τ1 : htyp) (τ2 : htyp) → τ ≠ (τ1 ==> τ2)) →
τ ≠ ⦇-⦈ →
⊥
canonical-boxed-forms-coverage TAConst (BVVal x) nb na nh = nb refl
canonical-boxed-forms-coverage (TAVar x₁) (BVVal ()) nb na nh
canonical-boxed-forms-coverage (TALam _ wt) (BVVal x₁) nb na nh = na _ _ refl
canonical-boxed-forms-coverage (TAAp wt wt₁) (BVVal ()) nb na nh
canonical-boxed-forms-coverage (TAEHole x x₁) (BVVal ()) nb na nh
canonical-boxed-forms-coverage (TANEHole x wt x₁) (BVVal ()) nb na nh
canonical-boxed-forms-coverage (TACast wt x) (BVVal ()) nb na nh
canonical-boxed-forms-coverage (TACast wt x) (BVArrCast x₁ bv) nb na nh = na _ _ refl
canonical-boxed-forms-coverage (TACast wt x) (BVHoleCast x₁ bv) nb na nh = nh refl
canonical-boxed-forms-coverage (TAFailedCast x x₁ x₂ x₃) (BVVal ())
|
{
"alphanum_fraction": 0.5141745414,
"avg_line_length": 47.9733333333,
"ext": "agda",
"hexsha": "ab748ba77a8d9b8a1a41da39769080df8ca94b75",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-09-13T18:20:02.000Z",
"max_forks_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_forks_repo_path": "canonical-boxed-forms.agda",
"max_issues_count": 54,
"max_issues_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_issues_repo_issues_event_max_datetime": "2018-11-29T16:32:40.000Z",
"max_issues_repo_issues_event_min_datetime": "2017-06-29T20:53:34.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_issues_repo_path": "canonical-boxed-forms.agda",
"max_line_length": 102,
"max_stars_count": 16,
"max_stars_repo_head_hexsha": "229dfb06ea51ebe91cb3b1c973c2f2792e66797c",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazelnut-dynamics-agda",
"max_stars_repo_path": "canonical-boxed-forms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T02:50:23.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-03-12T14:32:03.000Z",
"num_tokens": 1242,
"size": 3598
}
|
{-# OPTIONS --no-termination-check #-}
module Data.Bin.BinDivNt where
open import Data.Bin
open import Data.Bin.Properties
open import Data.Product
open import Relation.Binary
open StrictTotalOrder <-strictTotalOrder
open import Relation.Nullary
open import Data.Bin.Utils
open import Data.Bin.Minus
_divMod-nt_ : Bin → Bin → (Bin × Bin)
a divMod-nt b with a <? b
... | yes _ = (fromℕ 0 , a)
... | no _ with a divMod-nt (b *2)
... | (d , m) with m <? b
... | yes _ = (d *2 , m)
... | no _ = (fromℕ 1 + (d *2) , m - b)
|
{
"alphanum_fraction": 0.6126126126,
"avg_line_length": 25.2272727273,
"ext": "agda",
"hexsha": "e71bc3f41a2a6bc3788e116978a5d8984b56bf0c",
"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": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Data/Bin/BinDivNt.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"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": "Rotsor/BinDivMod",
"max_issues_repo_path": "Data/Bin/BinDivNt.agda",
"max_line_length": 42,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Data/Bin/BinDivNt.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 190,
"size": 555
}
|
data Unit : Set where
unit : Unit
test : Unit
test = {!!}
|
{
"alphanum_fraction": 0.5901639344,
"avg_line_length": 10.1666666667,
"ext": "agda",
"hexsha": "87fc1390e0d32551855519cc79e0e1797bccd519",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Interactive/Issue1430.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Interactive/Issue1430.agda",
"max_line_length": 21,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Interactive/Issue1430.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": 19,
"size": 61
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Group
open import lib.groups.Homomorphism
open import lib.types.TwoSemiCategory
open import lib.two-semi-categories.Functor
module lib.two-semi-categories.GroupToCategory where
group-to-cat : ∀ {i} → Group i → TwoSemiCategory lzero i
group-to-cat G =
record
{ El = ⊤
; Arr = λ _ _ → G.El
; Arr-level = λ _ _ → raise-level 0 G.El-level
; two-semi-cat-struct =
record
{ comp = G.comp
; assoc = G.assoc
; pentagon-identity = λ _ _ _ _ → =ₛ-in (prop-path (has-level-apply G.El-level _ _) _ _)
}
}
where
module G = Group G
homomorphism-to-functor : ∀ {i j} {G : Group i} {H : Group j}
→ G →ᴳ H
→ TwoSemiFunctor (group-to-cat G) (group-to-cat H)
homomorphism-to-functor {G = G} {H = H} φ =
record
{ F₀ = idf ⊤
; F₁ = φ.f
; pres-comp = φ.pres-comp
; pres-comp-coh = λ _ _ _ → =ₛ-in $ prop-path (has-level-apply H.El-level _ _) _ _
}
where
module G = Group G
module H = Group H
module φ = GroupHom φ
|
{
"alphanum_fraction": 0.627264061,
"avg_line_length": 25.5853658537,
"ext": "agda",
"hexsha": "3ca5cd671d52a77406d698ee71ade6ba1c88b5a5",
"lang": "Agda",
"max_forks_count": 50,
"max_forks_repo_forks_event_max_datetime": "2022-02-14T03:03:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-10T01:48:08.000Z",
"max_forks_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "AntoineAllioux/HoTT-Agda",
"max_forks_repo_path": "core/lib/two-semi-categories/GroupToCategory.agda",
"max_issues_count": 31,
"max_issues_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_issues_repo_issues_event_max_datetime": "2021-10-03T19:15:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-03-05T20:09:00.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "AntoineAllioux/HoTT-Agda",
"max_issues_repo_path": "core/lib/two-semi-categories/GroupToCategory.agda",
"max_line_length": 92,
"max_stars_count": 294,
"max_stars_repo_head_hexsha": "1037d82edcf29b620677a311dcfd4fc2ade2faa6",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "AntoineAllioux/HoTT-Agda",
"max_stars_repo_path": "core/lib/two-semi-categories/GroupToCategory.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": 359,
"size": 1049
}
|
open import AbstractInterfaces public
module OrdersAndEqualities {{_ : IsProc}} {{_ : IsTime}} {{_ : IsMsg}} {{_ : IsEvent}} where
-- _≡ₑ_ is a decidable equality on events within one process.
data _≡ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set where
refl≡ₑ : ∀ {P T} {a b : Event P T} →
a ≡ₑ b
_≢ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set
a ≢ₑ b = ¬ (a ≡ₑ b)
≡→≡ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →
T ≡ T′ → a ≡ₑ b
≡→≡ₑ refl = refl≡ₑ
≢→≢ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →
T ≢ T′ → a ≢ₑ b
≢→≢ₑ T≢T′ refl≡ₑ = refl ↯ T≢T′
_≡ₑ?_ : ∀ {T T′ P} → (a : Event P T) (b : Event P T′) → Dec (a ≡ₑ b)
_≡ₑ?_ {T} {T′} a b with T ≡ₜ? T′
a ≡ₑ? b | yes T≡T′ = yes (≡→≡ₑ T≡T′)
a ≡ₑ? b | no T≢T′ = no (≢→≢ₑ T≢T′)
-- _≅ₑ_ is a decidable equality on events across all processes.
data _≅ₑ_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set where
refl≅ₑ : ∀ {P T} {a : Event P T} {b : Event P T} →
a ≅ₑ b
_≇ₑ_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set
a ≇ₑ b = ¬ (a ≅ₑ b)
≡ₑ→≅ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →
a ≡ₑ b → a ≅ₑ b
≡ₑ→≅ₑ refl≡ₑ = refl≅ₑ
≢ₑ→≇ₑ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →
a ≢ₑ b → a ≇ₑ b
≢ₑ→≇ₑ a≢b refl≅ₑ = refl≡ₑ ↯ a≢b
≢ₚ→≇ₑ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
Pᵢ ≢ Pⱼ → a ≇ₑ b
≢ₚ→≇ₑ P≢P′ refl≅ₑ = refl ↯ P≢P′
≢ₜ→≇ₑ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
Tᵢ ≢ Tⱼ → a ≇ₑ b
≢ₜ→≇ₑ T≢T′ refl≅ₑ = refl ↯ T≢T′
_≅ₑ?_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → (a : Event Pᵢ Tᵢ) (b : Event Pⱼ Tⱼ) → Dec (a ≅ₑ b)
_≅ₑ?_ {Pᵢ} {Pⱼ} a b with Pᵢ ≡ₚ? Pⱼ
a ≅ₑ? b | yes refl with a ≡ₑ? b
a ≅ₑ? b | yes refl | yes a≡b = yes (≡ₑ→≅ₑ a≡b)
a ≅ₑ? b | yes refl | no a≢b = no (≢ₑ→≇ₑ a≢b)
a ≅ₑ? b | no Pᵢ≢Pⱼ = no (≢ₚ→≇ₑ Pᵢ≢Pⱼ)
-- _<ₑ_ is a decidable strict total order on events within one process.
_<ₑ_ : ∀ {T T′ P} → Event P T → Event P T′ → Set
_<ₑ_ {T} {T′} a b = T <ₜ T′
_≮ₑ_ : ∀ {P T T′} → Event P T → Event P T′ → Set
a ≮ₑ b = ¬ (a <ₑ b)
trans<ₑ : ∀ {P T T′ T″} {a : Event P T} {b : Event P T′} {c : Event P T″} →
a <ₑ b → b <ₑ c → a <ₑ c
trans<ₑ = trans<ₜ
tri<ₑ : ∀ {T T′ P} → (a : Event P T) (b : Event P T′) →
Tri (a <ₑ b) (a ≡ₑ b) (b <ₑ a)
tri<ₑ {T} {T′} a b with tri<ₜ T T′
tri<ₑ a b | τ₍ T<T′ T≢T′ T′≮T = τ₍ T<T′ (≢→≢ₑ T≢T′) T′≮T
tri<ₑ a b | τ₌ T≮T′ T≡T′ T′≮T = τ₌ T≮T′ (≡→≡ₑ T≡T′) T′≮T
tri<ₑ a b | τ₎ T≮T′ T≢T′ T′<T = τ₎ T≮T′ (≢→≢ₑ T≢T′) T′<T
irrefl<ₑ : ∀ {P T} {a : Event P T} → a ≮ₑ a
irrefl<ₑ {a = a} with tri<ₑ a a
irrefl<ₑ | τ₍ a<a a≢a a≮a = a≮a
irrefl<ₑ | τ₌ a≮a a≡a _ = a≮a
irrefl<ₑ | τ₎ a≮a a≢a a<a = a≮a
_<ₑ?_ : ∀ {P T T′} → (a : Event P T) (b : Event P T′) → Dec (a <ₑ b)
a <ₑ? b with tri<ₑ a b
a <ₑ? b | τ₍ a<b a≢b b≮a = yes a<b
a <ₑ? b | τ₌ a≮b a≡b b≮a = no a≮b
a <ₑ? b | τ₎ a≮b a≢b b<a = no a≮b
-- _⊳_ is a strict partial order on events across all processes.
data _⊳_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set where
lift⊳ : ∀ {P T T′} {a : Event P T} {b : Event P T′} →
a <ₑ b → a ⊳ b
pass⊳ : ∀ {Cᵢ Cⱼ Pᵢ Pⱼ Tₘ Tⱼ} {{_ : Tₘ ≡ sucₜ Cᵢ}} {{_ : Tⱼ ≡ sucₜ (Tₘ ⊔ₜ Cⱼ)}} →
{m : Msg Pᵢ Pⱼ Tₘ} {a : Event Pᵢ Tₘ} {b : Event Pⱼ Tⱼ} →
isSendₑ {Cᵢ} m a → isRecvₑ {Cⱼ} m b → a ⊳ b
trans⊳ : ∀ {Pᵢ Pⱼ Pₖ Tᵢ Tⱼ Tₖ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} {c : Event Pₖ Tₖ} →
a ⊳ b → b ⊳ c → a ⊳ c
_⋫_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set
a ⋫ b = ¬ (a ⊳ b)
clock⊳ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
a ⊳ b → Tᵢ <ₜ Tⱼ
clock⊳ (lift⊳ Tᵢ<Tⱼ) = Tᵢ<Tⱼ
clock⊳ (pass⊳ {Cᵢ} {Cⱼ} {{refl}} {{refl}} _ _) = n<s[n⊔m]ₜ (sucₜ Cᵢ) Cⱼ
clock⊳ (trans⊳ a⊳b b⊳c) = trans<ₜ (clock⊳ a⊳b) (clock⊳ b⊳c)
irrefl⊳ : ∀ {P T} {a : Event P T} → a ⋫ a
irrefl⊳ (lift⊳ {a = a} a<a) = a<a ↯ irrefl<ₑ {a = a}
irrefl⊳ (pass⊳ x y) = (x , y) ↯ absurdₑ
irrefl⊳ (trans⊳ {Tᵢ = Tᵢ} {Tⱼ} a⊳b b⊳a) with tri<ₜ Tᵢ Tⱼ
irrefl⊳ (trans⊳ a⊳b b⊳a) | τ₍ Tᵢ<Tⱼ Tᵢ≢Tⱼ Tⱼ≮Tᵢ = clock⊳ b⊳a ↯ Tⱼ≮Tᵢ
irrefl⊳ (trans⊳ a⊳b b⊳a) | τ₌ Tᵢ≮Tⱼ Tᵢ≡Tⱼ Tⱼ≮Tᵢ = clock⊳ a⊳b ↯ Tᵢ≮Tⱼ
irrefl⊳ (trans⊳ a⊳b b⊳a) | τ₎ Tᵢ≮Tⱼ Tᵢ≢Tⱼ Tⱼ<Tᵢ = clock⊳ a⊳b ↯ Tᵢ≮Tⱼ
asym⊳ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} → a ⊳ b → b ⋫ a
asym⊳ a⊳b b⊳a = irrefl⊳ (trans⊳ a⊳b b⊳a)
-- _⇒_ is a decidable strict total order on events across all processes.
data _⇒_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set where
diff⇒ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
Tᵢ <ₜ Tⱼ → a ⇒ b
same⇒ : ∀ {Pᵢ Pⱼ T} {a : Event Pᵢ T} {b : Event Pⱼ T} →
Pᵢ <ₚ Pⱼ → a ⇒ b
_⇏_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → Event Pᵢ Tᵢ → Event Pⱼ Tⱼ → Set
a ⇏ b = ¬ (a ⇒ b)
lift⇒ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
a ⊳ b → a ⇒ b
lift⇒ = diff⇒ ∘ clock⊳
trans⇒ : ∀ {Pᵢ Pⱼ Pₖ Tᵢ Tⱼ Tₖ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} {c : Event Pₖ Tₖ} →
a ⇒ b → b ⇒ c → a ⇒ c
trans⇒ (diff⇒ Tᵢ<Tⱼ) (diff⇒ Tⱼ<Tₖ) = diff⇒ (trans<ₜ Tᵢ<Tⱼ Tⱼ<Tₖ)
trans⇒ (diff⇒ Tᵢ<Tⱼ) (same⇒ Pⱼ<Pₖ) = diff⇒ Tᵢ<Tⱼ
trans⇒ (same⇒ Pᵢ<Pⱼ) (diff⇒ Tⱼ<Tₖ) = diff⇒ Tⱼ<Tₖ
trans⇒ (same⇒ Pᵢ<Pⱼ) (same⇒ Pⱼ<Pₖ) = same⇒ (trans<ₚ Pᵢ<Pⱼ Pⱼ<Pₖ)
≮→⇏ : ∀ {Pᵢ Pⱼ T} {a : Event Pᵢ T} {b : Event Pⱼ T} →
Pᵢ ≮ₚ Pⱼ → a ⇏ b
≮→⇏ Pᵢ≮Pⱼ (diff⇒ T<T) = T<T ↯ irrefl<ₜ
≮→⇏ Pᵢ≮Pⱼ (same⇒ Pᵢ<Pⱼ) = Pᵢ<Pⱼ ↯ Pᵢ≮Pⱼ
≮×≮→⇏ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
Tᵢ ≮ₜ Tⱼ → Pᵢ ≮ₚ Pⱼ → a ⇏ b
≮×≮→⇏ Tᵢ≮Tⱼ Pᵢ≮Pⱼ (diff⇒ Tᵢ<Tⱼ) = Tᵢ<Tⱼ ↯ Tᵢ≮Tⱼ
≮×≮→⇏ Tᵢ≮Tⱼ Pᵢ≮Pⱼ (same⇒ Pᵢ<Pⱼ) = Pᵢ<Pⱼ ↯ Pᵢ≮Pⱼ
≮×≢→⇏ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} {a : Event Pᵢ Tᵢ} {b : Event Pⱼ Tⱼ} →
Tᵢ ≮ₜ Tⱼ → Tᵢ ≢ Tⱼ → a ⇏ b
≮×≢→⇏ Tᵢ≮Tⱼ Tᵢ≢Tⱼ (diff⇒ Tᵢ<Tⱼ) = Tᵢ<Tⱼ ↯ Tᵢ≮Tⱼ
≮×≢→⇏ Tᵢ≮Tⱼ Tᵢ≢Tⱼ (same⇒ Pᵢ<Pⱼ) = refl ↯ Tᵢ≢Tⱼ
tri⇒₌ : ∀ {Pᵢ Pⱼ T} → (a : Event Pᵢ T) (b : Event Pⱼ T) →
Tri (a ⇒ b) (a ≅ₑ b) (b ⇒ a)
tri⇒₌ {Pᵢ} {Pⱼ} a b with tri<ₚ Pᵢ Pⱼ
tri⇒₌ a b | τ₍ Pᵢ<Pⱼ Pᵢ≢Pⱼ Pⱼ≮Pᵢ = τ₍ (same⇒ Pᵢ<Pⱼ) (≢ₚ→≇ₑ Pᵢ≢Pⱼ) (≮→⇏ Pⱼ≮Pᵢ)
tri⇒₌ a b | τ₌ Pᵢ≮Pⱼ refl Pⱼ≮Pᵢ = τ₌ (≮→⇏ Pᵢ≮Pⱼ) refl≅ₑ (≮→⇏ Pⱼ≮Pᵢ)
tri⇒₌ a b | τ₎ Pᵢ≮Pⱼ Pᵢ≢Pⱼ Pⱼ<Pᵢ = τ₎ (≮→⇏ Pᵢ≮Pⱼ) (≢ₚ→≇ₑ Pᵢ≢Pⱼ) (same⇒ Pⱼ<Pᵢ)
tri⇒ : ∀ {Tᵢ Tⱼ Pᵢ Pⱼ} → (a : Event Pᵢ Tᵢ) (b : Event Pⱼ Tⱼ) →
Tri (a ⇒ b) (a ≅ₑ b) (b ⇒ a)
tri⇒ {Tᵢ} {Tⱼ} a b with tri<ₜ Tᵢ Tⱼ
tri⇒ a b | τ₍ Tᵢ<Tⱼ Tᵢ≢Tⱼ Tⱼ≮Tᵢ = τ₍ (diff⇒ Tᵢ<Tⱼ) (≢ₜ→≇ₑ Tᵢ≢Tⱼ) (≮×≢→⇏ Tⱼ≮Tᵢ (sym≢ Tᵢ≢Tⱼ))
tri⇒ a b | τ₌ Tᵢ≮Tⱼ refl Tⱼ≮Tᵢ = tri⇒₌ a b
tri⇒ a b | τ₎ Tᵢ≮Tⱼ Tᵢ≢Tⱼ Tⱼ<Tᵢ = τ₎ (≮×≢→⇏ Tᵢ≮Tⱼ Tᵢ≢Tⱼ) (≢ₜ→≇ₑ Tᵢ≢Tⱼ) (diff⇒ Tⱼ<Tᵢ)
irrefl⇒ : ∀ {P T} {a : Event P T} → a ⇏ a
irrefl⇒ {a = a} with tri⇒ a a
irrefl⇒ | τ₍ a⇒a a≢a a⇏a = a⇏a
irrefl⇒ | τ₌ a⇏a a≢a _ = a⇏a
irrefl⇒ | τ₎ a⇏a a≢a a⇒a = a⇏a
_⇒?_ : ∀ {Pᵢ Pⱼ Tᵢ Tⱼ} → (a : Event Pᵢ Tᵢ) (b : Event Pⱼ Tⱼ) → Dec (a ⇒ b)
a ⇒? b with tri⇒ a b
a ⇒? b | τ₍ a⇒b a≇b b⇏a = yes a⇒b
a ⇒? b | τ₌ a⇏b a≅b b⇏a = no a⇏b
a ⇒? b | τ₎ a⇏b a≇b b⇒a = no a⇏b
|
{
"alphanum_fraction": 0.4693514954,
"avg_line_length": 34.4591836735,
"ext": "agda",
"hexsha": "698f122d9077f5fe0c2915fc7e4957d7fe1c6c8a",
"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": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_forks_repo_licenses": [
"X11"
],
"max_forks_repo_name": "mietek/lamport-timestamps",
"max_forks_repo_path": "OrdersAndEqualities.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"X11"
],
"max_issues_repo_name": "mietek/lamport-timestamps",
"max_issues_repo_path": "OrdersAndEqualities.agda",
"max_line_length": 92,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "b685baa99230c3d5fd1e41c66d325575b70308c4",
"max_stars_repo_licenses": [
"X11"
],
"max_stars_repo_name": "mietek/lamport-timestamps",
"max_stars_repo_path": "OrdersAndEqualities.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 5158,
"size": 6754
}
|
{-# OPTIONS --without-K --allow-unsolved-metas --exact-split #-}
module 17-cubical-diagrams where
import 16-pushouts
open 16-pushouts public
-- Section 15.1 Commuting cubes
-- Cubes
{-
We specify the type of the homotopy witnessing that a cube commutes.
Imagine that the cube is presented as a lattice
*
/ | \
/ | \
/ | \
* * *
|\ / \ /|
| \ / |
|/ \ / \|
* * *
\ | /
\ | /
\ | /
*
with all maps pointing in the downwards direction. Presented in this way, a
cube of maps has a top face, a back-left face, a back-right face, a
front-left face, a front-right face, and a bottom face, all of which are
homotopies.
A term of type coherence-cube is a homotopy filling the cube.
-}
coherence-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
UU _
coherence-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(((h ·l back-left) ∙h (front-left ·r f')) ∙h (hD ·l top)) ~
((bottom ·r hA) ∙h ((k ·l back-right) ∙h (front-right ·r g')))
coherence-hexagon :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) → UU l
coherence-hexagon α β γ δ ε ζ = Id ((α ∙ β) ∙ γ) (δ ∙ (ε ∙ ζ))
hexagon-rotate-120 :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv ε) (inv δ) α ζ (inv γ) (inv β)
hexagon-rotate-120 refl refl refl refl refl .refl refl = refl
hexagon-rotate-240 :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon γ (inv ζ) (inv ε) (inv β) (inv α) δ
hexagon-rotate-240 refl refl refl refl refl .refl refl = refl
hexagon-mirror-A :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon ε ζ (inv γ) (inv δ) α β
hexagon-mirror-A refl refl refl refl refl .refl refl = refl
hexagon-mirror-B :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv α) δ ε β γ (inv ζ)
hexagon-mirror-B refl refl refl refl refl .refl refl = refl
hexagon-mirror-C :
{l : Level} {A : UU l} {x u u' v v' y : A}
(α : Id x u) (β : Id u u') (γ : Id u' y)
(δ : Id x v) (ε : Id v v') (ζ : Id v' y) →
coherence-hexagon α β γ δ ε ζ →
coherence-hexagon (inv γ) (inv β) (inv α) (inv ζ) (inv ε) (inv δ)
hexagon-mirror-C refl refl refl refl refl .refl refl = refl
{- Since the specification of a cube is rather lengthy, we use Agda's
parametrized module system in order to avoid having to specify the same
variables multiple times.
-}
module Cubes
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)
where
{-
The symmetry group D_3 acts on a cube. However, the coherence filling a
a cube needs to be modified to show that the rotated/reflected cube again
commutes. In the following definitions we provide the homotopies witnessing
that the rotated/reflected cubes again commute.
Note: although in principle it ought to be enough to show this for the
generators of the symmetry group D_3, in practice it is more
straightforward to just do the work for each of the symmetries separately.
One reason is that some of the homotopies witnessing that the faces
commute will be inverted as the result of an application of a symmetry.
Inverting a homotopy twice results in a new homotopy that is only
homotopic to the original homotopy.
We first provide some constructions involving homotopies that will help us
manipulating coherences of cubes.
-}
-- We show that a rotation of a commuting cube again commutes.
coherence-cube-rotate-120 :
coherence-cube
hC k' k hD hA f' f hB g' g h' h
back-left
(htpy-inv back-right) (htpy-inv top)
(htpy-inv bottom) (htpy-inv front-left)
front-right
coherence-cube-rotate-120 a' =
( ap (λ t → t ∙ (ap h (back-left a')))
( ap (λ t' → t' ∙ inv (bottom (hA a')))
( ap-inv k (back-right a')))) ∙
( ( hexagon-rotate-120
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap (λ t → (front-right (g' a')) ∙ t)
( ap (λ t' → t' ∙ inv (front-left (f' a')))
( ap-inv hD (top a'))))))
coherence-cube-rotate-240 :
coherence-cube
h' hB hD h g' hA hC g f' k' f k
(htpy-inv back-right)
top (htpy-inv back-left)
(htpy-inv front-right) bottom
(htpy-inv front-left)
coherence-cube-rotate-240 a' =
( ap (λ t → _ ∙ t) (ap-inv k (back-right a'))) ∙
( ( hexagon-rotate-240
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap
( λ t → inv (front-left (f' a')) ∙ t)
( ap (λ t' → t' ∙ _) (ap-inv h (back-left a'))))))
{-
We show that a reflection through the plane spanned by the vertices
A', A, and D of a commuting cube again commutes.
Note: Since the vertices A' and D must always be fixed, the vertex A
determines the mirror symmetry.
-}
coherence-cube-mirror-A :
coherence-cube g f k h g' f' k' h' hA hC hB hD
(htpy-inv top) back-right back-left front-right front-left (htpy-inv bottom)
coherence-cube-mirror-A a' =
( ap (λ t → _ ∙ t) (ap-inv hD (top a'))) ∙
( hexagon-mirror-A
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a'))
coherence-cube-mirror-B :
coherence-cube hB h' h hD hA g' g hC f' f k' k
back-right (htpy-inv back-left) top bottom (htpy-inv front-right) front-left
coherence-cube-mirror-B a' =
( ap (λ t → t ∙ (ap k (back-right a')))
( ap (λ t → t ∙ _) (ap-inv h (back-left a')))) ∙
( hexagon-mirror-B
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a'))
coherence-cube-mirror-C :
coherence-cube k' hC hD k f' hA hB f g' h' g h
(htpy-inv back-left) (htpy-inv top) (htpy-inv back-right)
(htpy-inv front-left) (htpy-inv bottom) (htpy-inv front-right)
coherence-cube-mirror-C a' =
( ap
( λ t → (t ∙ inv (front-left (f' a'))) ∙ (ap h (inv (back-left a'))))
( ap-inv hD (top a'))) ∙
( ( ap (λ t → _ ∙ t) (ap-inv h (back-left a'))) ∙
( ( hexagon-mirror-C
( ap h (back-left a'))
( front-left (f' a'))
( ap hD (top a'))
( bottom (hA a'))
( ap k (back-right a'))
( front-right (g' a'))
( c a')) ∙
( inv
( ap
( λ t → inv (front-right (g' a')) ∙ t)
( ap (λ t' → t' ∙ _) (ap-inv k (back-right a')))))))
open Cubes public
rectangle-back-left-front-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ f) ∘ hA) ~ (hD ∘ (h' ∘ f'))
rectangle-back-left-front-left-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(h ·l back-left) ∙h (front-left ·r f')
rectangle-back-right-front-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((k ∘ g) ∘ hA) ~ (hD ∘ (k' ∘ g'))
rectangle-back-right-front-right-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(k ·l back-right) ∙h (front-right ·r g')
coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( bottom)
( htpy-refl' hD)
( pair hA
( pair
( h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair hA
( pair
( k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( htpy-refl' hA)
( top)
coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c =
( λ a' →
( ap
( concat
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom a')
( hD (k' (g' a'))))
( right-unit))) ∙h
( c)
rectangle-top-front-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ hB) ∘ f') ~ ((hD ∘ k') ∘ g')
rectangle-top-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(front-left ·r f') ∙h (hD ·l top)
rectangle-back-right-bottom-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((h ∘ f) ∘ hA) ~ ((k ∘ hC) ∘ g')
rectangle-back-right-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
( bottom ·r hA) ∙h (k ·l back-right)
{-
coherence-htpy-square-rectangle-top-fl-rectangle-br-bot-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( htpy-inv front-right)
( htpy-refl' h)
( pair g' (pair (hB ∘ f')
( htpy-inv (rectangle-top-front-left-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))))
( pair g' (pair (f ∘ hA)
( htpy-inv
( rectangle-back-right-bottom-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))))
( htpy-refl' g')
( htpy-inv back-left)
coherence-htpy-square-rectangle-top-fl-rectangle-br-bot-cube = {!!}
-}
rectangle-top-front-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
((hD ∘ h') ∘ f') ~ ((k ∘ hC) ∘ g')
rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(hD ·l top) ∙h (htpy-inv (front-right) ·r g')
rectangle-back-left-bottom-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g))→
((h ∘ hB) ∘ f') ~ ((k ∘ g) ∘ hA)
rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom =
(h ·l (htpy-inv back-left)) ∙h (bottom ·r hA)
is-pullback-back-left-is-pullback-back-right-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f : A → B} {g : A → C} {h : B → D} {k : C → D}
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
{f' : A' → B'} {g' : A' → C'} {h' : B' → D'} {k' : C' → D'}
{hA : A' → A} {hB : B' → B} {hC : C' → C} {hD : D' → D}
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-pullback h hD (pair hB (pair h' front-left)) →
is-pullback k hD (pair hC (pair k' front-right)) →
is-pullback g hC (pair hA (pair g' back-right)) →
is-pullback f hB (pair hA (pair f' back-left))
is-pullback-back-left-is-pullback-back-right-cube
{f = f} {g} {h} {k} {f' = f'} {g'} {h'} {k'} {hA = hA} {hB} {hC} {hD}
top back-left back-right front-left front-right bottom c
is-pb-front-left is-pb-front-right is-pb-back-right =
is-pullback-left-square-is-pullback-rectangle f h hD
( pair hB (pair h' front-left))
( pair hA (pair f' back-left))
( is-pb-front-left)
( is-pullback-htpy
{ f = h ∘ f}
( k ∘ g)
( bottom)
{ g = hD}
( hD)
( htpy-refl)
{ c = pair hA (pair (h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair hA (pair (k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair
( htpy-refl)
( pair top
( coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square g k hD
( pair hC (pair k' front-right))
( pair hA (pair g' back-right))
( is-pb-front-right)
( is-pb-back-right)))
is-pullback-back-right-is-pullback-back-left-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
{f : A → B} {g : A → C} {h : B → D} {k : C → D}
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
{f' : A' → B'} {g' : A' → C'} {h' : B' → D'} {k' : C' → D'}
{hA : A' → A} {hB : B' → B} {hC : C' → C} {hD : D' → D}
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-pullback h hD (pair hB (pair h' front-left)) →
is-pullback k hD (pair hC (pair k' front-right)) →
is-pullback f hB (pair hA (pair f' back-left)) →
is-pullback g hC (pair hA (pair g' back-right))
is-pullback-back-right-is-pullback-back-left-cube
{f = f} {g} {h} {k} {f' = f'} {g'} {h'} {k'} {hA = hA} {hB} {hC} {hD}
top back-left back-right front-left front-right bottom c
is-pb-front-left is-pb-front-right is-pb-back-left =
is-pullback-left-square-is-pullback-rectangle g k hD
( pair hC (pair k' front-right))
( pair hA (pair g' back-right))
( is-pb-front-right)
( is-pullback-htpy'
( h ∘ f)
{ f' = k ∘ g}
( bottom)
( hD)
{ g' = hD}
( htpy-refl)
( pair hA (pair (h' ∘ f')
( rectangle-back-left-front-left-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
{ c' = pair hA (pair (k' ∘ g')
( rectangle-back-right-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair
( htpy-refl)
( pair top
( coherence-htpy-square-rectangle-bl-fl-rectangle-br-fr-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square f h hD
( pair hB (pair h' front-left))
( pair hA (pair f' back-left))
( is-pb-front-left)
( is-pb-back-left)))
descent-is-equiv :
{l1 l2 l3 l4 l5 l6 : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {X : UU l4} {Y : UU l5} {Z : UU l6}
(i : X → Y) (j : Y → Z) (h : C → Z)
(c : cone j h B) (d : cone i (pr1 c) A) →
is-equiv i → is-equiv (pr1 (pr2 d)) →
is-pullback (j ∘ i) h (cone-comp-horizontal i j h c d) →
is-pullback j h c
descent-is-equiv i j h c d
is-equiv-i is-equiv-k is-pb-rectangle =
is-pullback-is-fiberwise-equiv-fib-square j h c
( ind-is-equiv
( λ y → is-equiv (fib-square j h c y))
( i)
( is-equiv-i)
( λ x → is-equiv-left-factor
( fib-square (j ∘ i) h
( cone-comp-horizontal i j h c d) x)
( fib-square j h c (i x))
( fib-square i (pr1 c) d x)
( fib-square-comp-horizontal i j h c d x)
( is-fiberwise-equiv-fib-square-is-pullback (j ∘ i) h
( cone-comp-horizontal i j h c d)
( is-pb-rectangle)
( x))
( is-fiberwise-equiv-fib-square-is-pullback i (pr1 c) d
( is-pullback-is-equiv' i (pr1 c) d is-equiv-i is-equiv-k) x)))
coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
coherence-htpy-square
( front-left)
( htpy-refl' k)
( pair f'
( pair
( g ∘ hA)
( rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair f'
( pair
( hC ∘ g')
( rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( htpy-refl' f')
( back-right)
coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c =
( htpy-inv
( htpy-inv
( htpy-assoc
( h ·l (htpy-inv back-left))
( bottom ·r hA)
( (k ·l back-right) ∙h (htpy-refl' (k ∘ (hC ∘ g'))))))) ∙h
( ( htpy-ap-concat'
( h ·l (htpy-inv back-left))
( htpy-inv (h ·l back-left))
( _)
( htpy-left-whisk-htpy-inv h back-left)) ∙h
( htpy-inv (htpy-inv-con (h ·l back-left) _ _
( ( ( htpy-inv (htpy-assoc (h ·l back-left) (front-left ·r f') _)) ∙h
( ( htpy-inv
( htpy-assoc
( (h ·l back-left) ∙h (front-left ·r f'))
( hD ·l top)
( (htpy-inv front-right) ·r g'))) ∙h
htpy-inv
( htpy-con-inv _ (front-right ·r g') _
( (htpy-assoc (bottom ·r hA) _ _) ∙h (htpy-inv (c)))))) ∙h
( htpy-inv
( htpy-ap-concat (bottom ·r hA) _ _ htpy-right-unit))))))
is-pullback-bottom-is-pullback-top-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv hA → is-equiv hB → is-equiv hC → is-equiv hD →
is-pullback h' k' (pair f' (pair g' top)) →
is-pullback h k (pair f (pair g bottom))
is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-hA is-equiv-hB is-equiv-hC is-equiv-hD is-pb-top =
descent-is-equiv hB h k
( pair f (pair g bottom))
( pair f' (pair hA (htpy-inv (back-left))))
( is-equiv-hB)
( is-equiv-hA)
( is-pullback-htpy
{f = h ∘ hB}
( hD ∘ h')
( front-left)
{g = k}
( k)
( htpy-refl' k)
{ c = pair f'
( pair
( g ∘ hA)
( rectangle-back-left-bottom-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom))}
( pair
( f')
( pair
( hC ∘ g')
( rectangle-top-front-right-cube
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom)))
( pair
( htpy-refl' f')
( pair
( back-right)
( coherence-htpy-square-is-pullback-bottom-is-pullback-top-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)))
( is-pullback-rectangle-is-pullback-left-square
( h')
( hD)
( k)
( pair k' (pair hC (htpy-inv front-right)))
( pair f' (pair g' top))
( is-pullback-is-equiv' hD k
( pair k' (pair hC (htpy-inv front-right)))
( is-equiv-hD)
( is-equiv-hC))
( is-pb-top)))
is-pullback-top-is-pullback-bottom-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv hA → is-equiv hB → is-equiv hC → is-equiv hD →
is-pullback h k (pair f (pair g bottom)) →
is-pullback h' k' (pair f' (pair g' top))
is-pullback-top-is-pullback-bottom-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-hA is-equiv-hB is-equiv-hC is-equiv-hD is-pb-bottom =
is-pullback-top-is-pullback-rectangle h hD k'
( pair hB (pair h' front-left))
( pair f' (pair g' top))
( is-pullback-is-equiv h hD
( pair hB (pair h' front-left))
is-equiv-hD is-equiv-hB)
( is-pullback-htpy' h htpy-refl (k ∘ hC) front-right
( cone-comp-vertical h k hC
( pair f (pair g bottom))
( pair hA (pair g' back-right)))
{ c' = cone-comp-vertical h hD k'
( pair hB (pair h' front-left))
( pair f' (pair g' top))}
( pair back-left
( pair
( htpy-refl)
( ( ( ( htpy-assoc
( bottom ·r hA) (k ·l back-right) (front-right ·r g')) ∙h
( htpy-inv c)) ∙h
( htpy-assoc
( h ·l back-left) (front-left ·r f') (hD ·l top))) ∙h
( htpy-ap-concat'
( h ·l back-left)
( (h ·l back-left) ∙h htpy-refl)
( (front-left ·r f') ∙h (hD ·l top))
( htpy-inv htpy-right-unit)))))
( is-pullback-rectangle-is-pullback-top h k hC
( pair f (pair g bottom))
( pair hA (pair g' back-right))
( is-pb-bottom)
( is-pullback-is-equiv g hC
( pair hA (pair g' back-right))
is-equiv-hC is-equiv-hA)))
is-pullback-front-left-is-pullback-back-right-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv f' → is-equiv f → is-equiv k' → is-equiv k →
is-pullback g hC (pair hA (pair g' back-right)) →
is-pullback h hD (pair hB (pair h' front-left))
is-pullback-front-left-is-pullback-back-right-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-f' is-equiv-f is-equiv-k' is-equiv-k is-pb-back-right =
is-pullback-bottom-is-pullback-top-cube-is-equiv
hB h' h hD hA g' g hC f' f k' k
back-right (htpy-inv back-left) top bottom (htpy-inv front-right) front-left
( coherence-cube-mirror-B f g h k f' g' h' k' hA hB hC hD top
back-left back-right front-left front-right bottom c)
is-equiv-f' is-equiv-f is-equiv-k' is-equiv-k is-pb-back-right
is-pullback-front-right-is-pullback-back-left-cube-is-equiv :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
is-equiv g' → is-equiv h' → is-equiv g → is-equiv h →
is-pullback f hB (pair hA (pair f' back-left)) →
is-pullback k hD (pair hC (pair k' front-right))
is-pullback-front-right-is-pullback-back-left-cube-is-equiv
f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
is-equiv-g' is-equiv-h' is-equiv-g is-equiv-h is-pb-back-left =
is-pullback-bottom-is-pullback-top-cube-is-equiv
hC k' k hD hA f' f hB g' g h' h
back-left (htpy-inv back-right) (htpy-inv top)
( htpy-inv bottom) (htpy-inv front-left) front-right
( coherence-cube-rotate-120 f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c)
is-equiv-g' is-equiv-g is-equiv-h' is-equiv-h is-pb-back-left
-- Section 15.2 Fiberwise pullbacks.
{- We show that if we have a square of families, such that the base square is
a pullback square, then each square of fibers is a pullback square if and
only if the square of total spaces is a pullback square. -}
cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
cone f g C → (C → UU l8) → UU (l4 ⊔ (l5 ⊔ (l6 ⊔ (l7 ⊔ l8))))
cone-family {C = C} PX f' g' c PC =
(x : C) →
cone ((tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x))) (g' (pr1 (pr2 c) x)) (PC x)
htpy-toto :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {P : A → UU l3} (Q : B → UU l4)
{f f' : A → B} (H : f ~ f') (g : (x : A) → P x → Q (f x)) {g' : (x : A) → P x → Q (f' x)} (K : (x : A) → ((tr Q (H x)) ∘ (g x)) ~ (g' x)) →
(toto Q f g) ~ (toto Q f' g')
htpy-toto Q H g K t = eq-pair (H (pr1 t)) (K (pr1 t) (pr2 t))
tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) → cone-family PX f' g' c PC →
cone (toto PX f f') (toto PX g g') (Σ C PC)
tot-cone-cone-family PX f' g' c c' =
pair
( toto _ (pr1 c) (λ x → pr1 (c' x)))
( pair
( toto _ (pr1 (pr2 c)) (λ x → (pr1 (pr2 (c' x)))))
( htpy-toto PX
( pr2 (pr2 c))
( λ z → (f' (pr1 c z)) ∘ (pr1 (c' z)))
( λ z → pr2 (pr2 (c' z)))))
map-canpb-tot-cone-cone-fam-right-factor :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
Σ ( canonical-pullback f g)
( λ t → canonical-pullback ((tr PX (π₃ t)) ∘ (f' (π₁ t))) (g' (π₂ t))) →
Σ ( Σ A PA)
( λ aa' → Σ (Σ B (λ b → Id (f (pr1 aa')) (g b)))
( λ bα → Σ (PB (pr1 bα))
( λ b' → Id
( tr PX (pr2 bα) (f' (pr1 aa') (pr2 aa')))
( g' (pr1 bα) b'))))
map-canpb-tot-cone-cone-fam-right-factor
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
swap-total-Eq-structure
( λ a → Σ B (λ b → Id (f a) (g b)))
( PA)
( λ a bα a' → Σ (PB (pr1 bα))
( λ b' → Id (tr PX (pr2 bα) (f' a a')) (g' (pr1 bα) b')))
map-canpb-tot-cone-cone-fam-left-factor :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) → (aa' : Σ A PA) →
Σ (Σ B (λ b → Id (f (pr1 aa')) (g b)))
( λ bα → Σ (PB (pr1 bα))
( λ b' → Id
( tr PX (pr2 bα) (f' (pr1 aa') (pr2 aa')))
( g' (pr1 bα) b'))) →
Σ ( Σ B PB)
( λ bb' → Σ (Id (f (pr1 aa')) (g (pr1 bb')))
( λ α → Id (tr PX α (f' (pr1 aa') (pr2 aa'))) (g' (pr1 bb') (pr2 bb'))))
map-canpb-tot-cone-cone-fam-left-factor
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' aa' =
( swap-total-Eq-structure
( λ b → Id (f (pr1 aa')) (g b))
( PB)
( λ b α b' → Id (tr PX α (f' (pr1 aa') (pr2 aa'))) (g' b b')))
map-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
Σ ( canonical-pullback f g)
( λ t → canonical-pullback ((tr PX (π₃ t)) ∘ (f' (π₁ t))) (g' (π₂ t))) →
canonical-pullback (toto PX f f') (toto PX g g')
map-canonical-pullback-tot-cone-cone-family
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
( tot (λ aa' →
( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa'))) ∘
( map-canpb-tot-cone-cone-fam-right-factor PX f' g' c c')
is-equiv-map-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-equiv (map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
is-equiv-map-canonical-pullback-tot-cone-cone-family
{X = X} {A} {B} {C} PX {PA} {PB} {PC} {f} {g} f' g' c c' =
is-equiv-comp
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( tot (λ aa' →
( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa')))
( map-canpb-tot-cone-cone-fam-right-factor PX f' g' c c')
( htpy-refl)
( is-equiv-swap-total-Eq-structure
( λ a → Σ B (λ b → Id (f a) (g b)))
( PA)
( λ a bα a' → Σ (PB (pr1 bα))
( λ b' → Id (tr PX (pr2 bα) (f' a a')) (g' (pr1 bα) b'))))
( is-equiv-tot-is-fiberwise-equiv (λ aa' → is-equiv-comp
( ( tot (λ bb' → eq-pair')) ∘
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa'))
( tot (λ bb' → eq-pair'))
( map-canpb-tot-cone-cone-fam-left-factor PX f' g' c c' aa')
( htpy-refl)
( is-equiv-swap-total-Eq-structure _ _ _)
( is-equiv-tot-is-fiberwise-equiv (λ bb' → is-equiv-eq-pair
( pair (f (pr1 aa')) (f' (pr1 aa') (pr2 aa')))
( pair (g (pr1 bb')) (g' (pr1 bb') (pr2 bb')))))))
triangle-canonical-pullback-tot-cone-cone-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c')) ~
( ( map-canonical-pullback-tot-cone-cone-family PX f' g' c c') ∘
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))))
triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c' (pair x y) =
refl
is-pullback-family-is-pullback-tot :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-pullback f g c →
is-pullback
(toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c') →
(x : C) →
is-pullback
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)
is-pullback-family-is-pullback-tot
PX {PA} {PB} {PC} {f} {g} f' g' c c' is-pb-c is-pb-tot =
is-fiberwise-equiv-is-equiv-toto-is-equiv-base-map _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))
( is-pb-c)
( is-equiv-right-factor
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c'))
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)))
( triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-equiv-map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-pb-tot))
is-pullback-tot-is-pullback-family :
{l1 l2 l3 l4 l5 l6 l7 l8 : Level}
{X : UU l1} {A : UU l2} {B : UU l3} {C : UU l4}
(PX : X → UU l5) {PA : A → UU l6} {PB : B → UU l7} {PC : C → UU l8}
{f : A → X} {g : B → X} →
(f' : (a : A) → PA a → PX (f a)) (g' : (b : B) → PB b → PX (g b)) →
(c : cone f g C) (c' : cone-family PX f' g' c PC) →
is-pullback f g c →
( (x : C) →
is-pullback
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)) →
is-pullback
(toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c')
is-pullback-tot-is-pullback-family
PX {PA} {PB} {PC} {f} {g} f' g' c c' is-pb-c is-pb-c' =
is-equiv-comp
( gap (toto PX f f') (toto PX g g') (tot-cone-cone-family PX f' g' c c'))
( map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( toto _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x)))
( triangle-canonical-pullback-tot-cone-cone-family PX f' g' c c')
( is-equiv-toto-is-fiberwise-equiv-is-equiv-base-map _
( gap f g c)
( λ x → gap
( (tr PX (pr2 (pr2 c) x)) ∘ (f' (pr1 c x)))
( g' (pr1 (pr2 c) x))
( c' x))
( is-pb-c)
( is-pb-c'))
( is-equiv-map-canonical-pullback-tot-cone-cone-family PX f' g' c c')
{- We show that identity types commute with pullbacks. -}
cone-ap :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) (c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
cone
( λ (α : Id (p c1) (p c2)) → (ap f α) ∙ (H c2))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( Id c1 c2)
cone-ap f g (pair p (pair q H)) c1 c2 =
pair
( ap p)
( pair
( ap q)
( λ γ →
( ap (λ t → t ∙ (H c2)) (inv (ap-comp f p γ))) ∙
( ( inv (htpy-nat H γ)) ∙
( ap (λ t → (H c1) ∙ t) (ap-comp g q γ)))))
tr-id-right :
{l1 : Level} {A : UU l1} {a b c : A} (q : Id b c) (p : Id a b) →
Id (tr (λ y → Id a y) q p) (p ∙ q)
tr-id-right refl refl = refl
cone-ap' :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) (c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
cone
( λ (α : Id (p c1) (p c2)) → tr (λ t → Id (f (p c1)) t) (H c2) (ap f α))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( Id c1 c2)
cone-ap' f g (pair p (pair q H)) c1 c2 =
pair
( ap p)
( pair
( ap q)
( λ γ →
( tr-id-right (H c2) (ap f (ap p γ))) ∙
( ( ap (λ t → t ∙ (H c2)) (inv (ap-comp f p γ))) ∙
( ( inv (htpy-nat H γ)) ∙
( ap (λ t → (H c1) ∙ t) (ap-comp g q γ))))))
is-pullback-cone-ap :
{l1 l2 l3 l4 : Level} {A : UU l1} {B : UU l2} {X : UU l3} {C : UU l4}
(f : A → X) (g : B → X) (c : cone f g C) → is-pullback f g c →
(c1 c2 : C) →
let p = pr1 c
q = pr1 (pr2 c)
H = pr2 (pr2 c)
in
is-pullback
( λ (α : Id (p c1) (p c2)) → (ap f α) ∙ (H c2))
( λ (β : Id (q c1) (q c2)) → (H c1) ∙ (ap g β))
( cone-ap f g c c1 c2)
is-pullback-cone-ap f g (pair p (pair q H)) is-pb-c c1 c2 =
is-pullback-htpy'
( λ α → tr (λ x → Id (f (p c1)) x) (H c2) (ap f α))
( λ α → tr-id-right (H c2) (ap f α))
( λ β → (H c1) ∙ (ap g β))
( htpy-refl)
( cone-ap' f g (pair p (pair q H)) c1 c2)
{ c' = cone-ap f g (pair p (pair q H)) c1 c2}
( pair htpy-refl (pair htpy-refl htpy-right-unit))
( is-pullback-family-is-pullback-tot
( λ x → Id (f (p c1)) x)
( λ a → ap f {x = p c1} {y = a})
( λ b β → (H c1) ∙ (ap g β))
( pair p (pair q H))
( cone-ap' f g (pair p (pair q H)) c1)
( is-pb-c)
( is-pullback-is-equiv
( toto _ f (λ a α → ap f α))
( toto _ g (λ b β → (H c1) ∙ (ap g β)))
( tot-cone-cone-family
( Id (f (p c1)))
( λ a → ap f)
( λ b β → (H c1) ∙ (ap g β))
( pair p (pair q H))
( cone-ap' f g (pair p (pair q H)) c1))
( is-equiv-is-contr _
( is-contr-total-path (q c1))
( is-contr-total-path (f (p c1))))
( is-equiv-is-contr _
( is-contr-total-path c1)
( is-contr-total-path (p c1))))
( c2))
{- Next we show that for any commuting cube, if the bottom and top squares are
pullback squares, then so is the square of fibers of the vertical maps in
cube. -}
{-
square-fib-cube :
{l1 l2 l3 l4 l1' l2' l3' l4' : Level}
{A : UU l1} {B : UU l2} {C : UU l3} {D : UU l4}
(f : A → B) (g : A → C) (h : B → D) (k : C → D)
{A' : UU l1'} {B' : UU l2'} {C' : UU l3'} {D' : UU l4'}
(f' : A' → B') (g' : A' → C') (h' : B' → D') (k' : C' → D')
(hA : A' → A) (hB : B' → B) (hC : C' → C) (hD : D' → D)
(top : (h' ∘ f') ~ (k' ∘ g'))
(back-left : (f ∘ hA) ~ (hB ∘ f'))
(back-right : (g ∘ hA) ~ (hC ∘ g'))
(front-left : (h ∘ hB) ~ (hD ∘ h'))
(front-right : (k ∘ hC) ~ (hD ∘ k'))
(bottom : (h ∘ f) ~ (k ∘ g)) →
(c : coherence-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom) →
(a : A) →
( ( tot (λ d' p → p ∙ (bottom a)) ∘
( fib-square h hD (pair hB (pair h' front-left)) (f a))) ∘
( fib-square f hB (pair hA (pair f' back-left)) a)) ~
( ( fib-square k hD (pair hC (pair k' front-right)) (g a)) ∘
( fib-square g hC (pair hA (pair g' back-right)) a))
square-fib-cube f g h k f' g' h' k' hA hB hC hD
top back-left back-right front-left front-right bottom c
.(hA a') (pair a' refl) =
eq-pair
( pair
( top a')
( ( tr-id-left-subst
( top a')
( k (g (hA a')))
( ( ( inv (front-left (f' a'))) ∙
( ap h ((inv (back-left a')) ∙ refl))) ∙
( bottom (hA a')))) ∙
( ( ( assoc (inv (ap hD (top a'))) _ (bottom (hA a'))) ∙
{!!}) ∙
( distributive-inv-concat (ap k (back-right a')) (front-right (g' a')) ∙
( ( ap
( concat (inv (front-right (g' a'))) ?)
( inv (ap-inv k (back-right a')))) ∙
( ap
( concat (inv (front-right (g' a'))) ?)
( ap (ap k) (inv right-unit))))))))
-}
|
{
"alphanum_fraction": 0.4823027161,
"avg_line_length": 38.6131202691,
"ext": "agda",
"hexsha": "fbd108bb73a5a6f2879648d3ed0cab41afc55c56",
"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": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"max_forks_repo_licenses": [
"CC-BY-4.0"
],
"max_forks_repo_name": "tadejpetric/HoTT-Intro",
"max_forks_repo_path": "Agda/17-cubical-diagrams.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"CC-BY-4.0"
],
"max_issues_repo_name": "tadejpetric/HoTT-Intro",
"max_issues_repo_path": "Agda/17-cubical-diagrams.agda",
"max_line_length": 141,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "f4228d6ecfc6cdb119c6e8b0e711fea05b98b2d5",
"max_stars_repo_licenses": [
"CC-BY-4.0"
],
"max_stars_repo_name": "tadejpetric/HoTT-Intro",
"max_stars_repo_path": "Agda/17-cubical-diagrams.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 19698,
"size": 45911
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Setoids.Setoids
open import Functions.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Sets.FinSet.Definition
open import Groups.Definition
open import Groups.SymmetricGroups.Definition
open import Decidable.Sets
open import Boolean.Definition
module Groups.FreeGroup.Definition where
data FreeCompletion {a : _} (A : Set a) : Set a where
ofLetter : A → FreeCompletion A
ofInv : A → FreeCompletion A
freeCompletionMap : {a b : _} {A : Set a} {B : Set b} (f : A → B) (w : FreeCompletion A) → FreeCompletion B
freeCompletionMap f (ofLetter x) = ofLetter (f x)
freeCompletionMap f (ofInv x) = ofInv (f x)
freeInverse : {a : _} {A : Set a} (l : FreeCompletion A) → FreeCompletion A
freeInverse (ofLetter x) = ofInv x
freeInverse (ofInv x) = ofLetter x
ofLetterInjective : {a : _} {A : Set a} {x y : A} → (ofLetter x ≡ ofLetter y) → x ≡ y
ofLetterInjective refl = refl
ofInvInjective : {a : _} {A : Set a} {x y : A} → (ofInv x ≡ ofInv y) → x ≡ y
ofInvInjective refl = refl
ofLetterOfInv : {a : _} {A : Set a} {x y : A} → ofLetter x ≡ ofInv y → False
ofLetterOfInv ()
decidableFreeCompletion : {a : _} {A : Set a} → DecidableSet A → DecidableSet (FreeCompletion A)
decidableFreeCompletion {A = A} dec = pr
where
pr : (a b : FreeCompletion A) → (a ≡ b) || (a ≡ b → False)
pr (ofLetter x) (ofLetter y) with dec x y
... | inl refl = inl refl
... | inr x!=y = inr λ p → x!=y (ofLetterInjective p)
pr (ofLetter x) (ofInv y) = inr λ ()
pr (ofInv x) (ofLetter y) = inr λ ()
pr (ofInv x) (ofInv y) with dec x y
... | inl refl = inl refl
... | inr x!=y = inr λ p → x!=y (ofInvInjective p)
freeCompletionEqual : {a : _} {A : Set a} (dec : DecidableSet A) (x y : FreeCompletion A) → Bool
freeCompletionEqual dec x y with decidableFreeCompletion dec x y
freeCompletionEqual dec x y | inl x₁ = BoolTrue
freeCompletionEqual dec x y | inr x₁ = BoolFalse
freeCompletionEqualFalse : {a : _} {A : Set a} (dec : DecidableSet A) {x y : FreeCompletion A} → ((x ≡ y) → False) → (freeCompletionEqual dec x y) ≡ BoolFalse
freeCompletionEqualFalse dec {x = x} {y} x!=y with decidableFreeCompletion dec x y
freeCompletionEqualFalse dec {x} {y} x!=y | inl x=y = exFalso (x!=y x=y)
freeCompletionEqualFalse dec {x} {y} x!=y | inr _ = refl
freeCompletionEqualFalse' : {a : _} {A : Set a} (dec : DecidableSet A) {x y : FreeCompletion A} → .((freeCompletionEqual dec x y) ≡ BoolFalse) → (x ≡ y) → False
freeCompletionEqualFalse' dec {x} {y} pr with decidableFreeCompletion dec x y
freeCompletionEqualFalse' dec {x} {y} () | inl x₁
freeCompletionEqualFalse' dec {x} {y} pr | inr ans = ans
|
{
"alphanum_fraction": 0.6778451659,
"avg_line_length": 42.4696969697,
"ext": "agda",
"hexsha": "61d2691d87f0b91fe74356b57b751c382003c759",
"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/Definition.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/FreeGroup/Definition.agda",
"max_line_length": 160,
"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/Definition.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 951,
"size": 2803
}
|
{-# OPTIONS --without-K #-}
module PathStructure.Id.Tr {a b} {A : Set a} {B : Set b} where
open import Equivalence
open import PathOperations
open import Types
tr-split : {a a′ : A} {b b′ : B} (p : a ≡ a′) →
tr (λ _ → B) p b ≡ b′ → b ≡ b′
tr-split {b = b} {b′ = b′} = J
(λ _ _ p → tr (λ _ → B) p b ≡ b′ → b ≡ b′)
(λ _ p → p) _ _
tr-merge : {a a′ : A} {b b′ : B} (p : a ≡ a′) →
b ≡ b′ → tr (λ _ → B) p b ≡ b′
tr-merge {b = b} {b′ = b′} = J
(λ _ _ p → b ≡ b′ → tr (λ _ → B) p b ≡ b′)
(λ _ p → p) _ _
tr-eq : {a a′ : A} {b b′ : B} (p : a ≡ a′) →
(tr (λ _ → B) p b ≡ b′) ≃ (b ≡ b′)
tr-eq p
= tr-split p
, (tr-merge p , λ q → J
(λ _ _ p → tr-split p (tr-merge p q) ≡ q)
(λ _ → refl) _ _ p)
, (tr-merge p , λ q → J
(λ _ _ p → (b b′ : B) (q : tr (λ _ → B) p b ≡ b′) →
tr-merge p (tr-split p q) ≡ q)
(λ _ _ _ _ → refl) _ _ p _ _ q)
-- In presence of univalence axiom, this statement
-- can also be proven from tr-eq.
tr-≡ : {a a′ : A} {b b′ : B} (p : a ≡ a′) →
(tr (λ _ → B) p b ≡ b′) ≡ (b ≡ b′)
tr-≡ {b = b} {b′ = b′} = J
(λ _ _ p → (tr (λ _ → B) p b ≡ b′) ≡ (b ≡ b′))
(λ _ → refl) _ _
|
{
"alphanum_fraction": 0.4220665499,
"avg_line_length": 29.2820512821,
"ext": "agda",
"hexsha": "868c79239d4b16ca25ad72628d3f186b1a0e0ac0",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/PathStructure/Id/Tr.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/PathStructure/Id/Tr.agda",
"max_line_length": 62,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/PathStructure/Id/Tr.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 574,
"size": 1142
}
|
{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.Ints.DiffInt.Properties where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.HITs.Ints.DiffInt.Base
open import Cubical.Data.Nat
open import Cubical.Data.Sigma
open import Cubical.Data.Bool
open import Cubical.Relation.Binary.Base
open import Cubical.Relation.Nullary
open import Cubical.HITs.SetQuotients
open BinaryRelation
relIsEquiv : isEquivRel rel
relIsEquiv = equivRel {A = ℕ × ℕ} relIsRefl relIsSym relIsTrans
where
relIsRefl : isRefl rel
relIsRefl (a0 , a1) = refl
relIsSym : isSym rel
relIsSym (a0 , a1) (b0 , b1) p = sym p
relIsTrans : isTrans rel
relIsTrans (a0 , a1) (b0 , b1) (c0 , c1) p0 p1 =
inj-m+ {m = (b0 + b1)} ((b0 + b1) + (a0 + c1) ≡⟨ +-assoc (b0 + b1) a0 c1 ⟩
((b0 + b1) + a0) + c1 ≡[ i ]⟨ +-comm b0 b1 i + a0 + c1 ⟩
((b1 + b0) + a0) + c1 ≡[ i ]⟨ +-comm (b1 + b0) a0 i + c1 ⟩
(a0 + (b1 + b0)) + c1 ≡[ i ]⟨ +-assoc a0 b1 b0 i + c1 ⟩
(a0 + b1) + b0 + c1 ≡⟨ sym (+-assoc (a0 + b1) b0 c1) ⟩
(a0 + b1) + (b0 + c1) ≡⟨ cong (λ p → p . fst + p .snd) (transport ΣPath≡PathΣ (p0 , p1))⟩
(b0 + a1) + (c0 + b1) ≡⟨ sym (+-assoc b0 a1 (c0 + b1))⟩
b0 + (a1 + (c0 + b1)) ≡[ i ]⟨ b0 + (a1 + +-comm c0 b1 i) ⟩
b0 + (a1 + (b1 + c0)) ≡[ i ]⟨ b0 + +-comm a1 (b1 + c0) i ⟩
b0 + ((b1 + c0) + a1) ≡[ i ]⟨ b0 + +-assoc b1 c0 a1 (~ i) ⟩
b0 + (b1 + (c0 + a1)) ≡⟨ +-assoc b0 b1 (c0 + a1)⟩
(b0 + b1) + (c0 + a1) ∎ )
relIsProp : BinaryRelation.isPropValued rel
relIsProp a b x y = isSetℕ _ _ _ _
discreteℤ : Discrete ℤ
discreteℤ = discreteSetQuotients (discreteΣ discreteℕ λ _ → discreteℕ) relIsProp relIsEquiv (λ _ _ → discreteℕ _ _)
private
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 6) ]) ≡ true
_ = refl
_ : Dec→Bool (discreteℤ [ (3 , 5) ] [ (4 , 7) ]) ≡ false
_ = refl
|
{
"alphanum_fraction": 0.5514112903,
"avg_line_length": 36.0727272727,
"ext": "agda",
"hexsha": "f81847ecfc36122da21017898431c7a0c2eb0303",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Edlyr/cubical",
"max_forks_repo_path": "Cubical/HITs/Ints/DiffInt/Properties.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Edlyr/cubical",
"max_issues_repo_path": "Cubical/HITs/Ints/DiffInt/Properties.agda",
"max_line_length": 115,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "5de11df25b79ee49d5c084fbbe6dfc66e4147a2e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Edlyr/cubical",
"max_stars_repo_path": "Cubical/HITs/Ints/DiffInt/Properties.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 873,
"size": 1984
}
|
postulate FunctorOps : Set
module FunctorOps (ops : FunctorOps) where
postulate map : Set
postulate IsFunctor : Set
module IsFunctor (fun : IsFunctor) where
postulate ops : FunctorOps
open FunctorOps ops public
-- inside here `FunctorOps.map ops` gets printed as `map`
open IsFunctor
-- out here it should too
test : (F : IsFunctor) → FunctorOps.map (ops F)
test F = F
-- EXPECTED: IsFunctor !=< map F
|
{
"alphanum_fraction": 0.7228915663,
"avg_line_length": 21.8421052632,
"ext": "agda",
"hexsha": "5378698c9d8e6d55e7afa1a0035fb4063efb49b0",
"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/Issue958.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/Issue958.agda",
"max_line_length": 59,
"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/Issue958.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-30T18:20:48.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-01-09T23:51:16.000Z",
"num_tokens": 125,
"size": 415
}
|
module Issue208 where
record R : Set where
foo : Set
foo = {!!}
|
{
"alphanum_fraction": 0.6323529412,
"avg_line_length": 13.6,
"ext": "agda",
"hexsha": "7b29324f8d3ed5139b6635c9a08a7900d31e06ef",
"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/interaction/Issue208.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/interaction/Issue208.agda",
"max_line_length": 21,
"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/interaction/Issue208.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": 21,
"size": 68
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import cohomology.Exactness
open import cohomology.Theory
module cohomology.Unit {i} (CT : CohomologyTheory i) where
open CohomologyTheory CT
module _ (n : ℤ) where
private
⊙LU = ⊙Lift {j = i} ⊙Unit
Cof-Unit-is-Unit : ⊙Cof (⊙idf ⊙LU) == ⊙LU
Cof-Unit-is-Unit = ⊙ua (⊙≃-in {X = _ , cfbase} e idp)
where
e : Cofiber (idf (Lift {j = i} Unit)) ≃ Lift Unit
e = equiv (λ _ → lift unit)
(λ _ → cfbase)
(λ _ → idp)
(Cofiber-elim {f = idf _}
{P = λ c → cfbase == c}
idp
(λ _ → cfglue (lift unit))
(λ _ → ↓-cst=idf-in idp))
C-Unit-is-contr : is-contr (CEl n ⊙LU)
C-Unit-is-contr =
(Cid n ⊙LU , λ x → lemma₂ x ∙ app= (ap GroupHom.f (CF-ident n)) x)
where
lemma₁ : (x : CEl n (⊙Cof (⊙idf _)))
→ Cid n ⊙LU == CF n (⊙cfcod' (⊙idf _)) x
lemma₁ x = ! (itok (C-exact n (⊙idf _)) _ [ x , idp ])
∙ app= (ap GroupHom.f (CF-ident n))
(CF n (⊙cfcod' (⊙idf _)) x)
lemma₂ : (x : CEl n ⊙LU) → Cid n ⊙LU == CF n (⊙idf _) x
lemma₂ = transport
{A = Σ (Ptd i) (λ X → fst (⊙LU ⊙→ X))}
(λ {(X , H) → (c : CEl n X) → Cid n ⊙LU == CF n H c})
(pair= Cof-Unit-is-Unit
(prop-has-all-paths-↓ (⊙→-level (Lift-level Unit-is-prop))))
lemma₁
C-Unit : C n ⊙LU == 0ᴳ
C-Unit = contr-is-0ᴳ _ C-Unit-is-contr
|
{
"alphanum_fraction": 0.4860068259,
"avg_line_length": 29.8979591837,
"ext": "agda",
"hexsha": "01695d42215c72f0931233c21e5ea46712afbff6",
"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/cohomology/Unit.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/cohomology/Unit.agda",
"max_line_length": 73,
"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/cohomology/Unit.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 603,
"size": 1465
}
|
module Numeral.Natural.Decidable where
open import Data
open import Data.Boolean
open import Functional
open import Lang.Inspect
open import Logic.Propositional
open import Numeral.Natural
open import Structure.Function
open import Structure.Function.Domain
open import Structure.Relator.Properties
open import Type.Properties.Decidable
module _ where
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
instance
[≡?]-decider : Decider(2)(_≡_)(_≡?_)
[≡?]-decider {𝟎} {𝟎} = true [≡]-intro
[≡?]-decider {𝟎} {𝐒 y} = false \()
[≡?]-decider {𝐒 x} {𝟎} = false \()
[≡?]-decider {𝐒 x} {𝐒 y} with (x ≡? y) | [≡?]-decider {x} {y}
... | 𝑇 | true xy = true (congruence₁(𝐒) xy)
... | 𝐹 | false nxy = false (nxy ∘ injective(𝐒))
zero?-decider : Decider(1)(_≡ 𝟎)(zero?)
zero?-decider {𝟎} = true [≡]-intro
zero?-decider {𝐒 x} = false \()
module _ where
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Oper.Divisibility
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs
open import Numeral.Natural.Relation.Divisibility
open import Numeral.Natural.Relation.Divisibility.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs.Equiv
instance
[∣]-decider : Decider(2)(_∣_)(_∣₀?_)
[∣]-decider {𝟎} {𝟎} = true Div𝟎
[∣]-decider {𝟎} {𝐒 y} = false [0]-divides-not
[∣]-decider {𝐒 x} {y} with y mod 𝐒(x) | inspect(\x → y mod 𝐒(x)) x
... | 𝟎 | intro eq = true ([↔]-to-[→] mod-divisibility eq)
... | 𝐒 _ | intro eq = false ([𝐒]-not-0 ∘ transitivity(_≡_) (symmetry(_≡_) eq) ∘ [↔]-to-[←] mod-divisibility)
module _ where
open import Data.Boolean.Stmt
open import Data.Boolean.Stmt.Proofs
open import Data.List
open import Data.List.Decidable as List
open import Data.List.Equiv.Id
open import Lang.Inspect
open import Logic.Classical
open import Logic.Predicate
open import Numeral.Natural.LinearSearch
open import Numeral.Natural.Oper.Divisibility
open import Numeral.Natural.Prime
open import Numeral.Natural.Prime.Proofs
open import Numeral.Natural.Relation.Divisibility
open import Numeral.Natural.Relation.Divisibility.Proofs
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.Equiv
open import Type.Properties.Decidable.Proofs
open import Syntax.Implication.Dependent
open import Syntax.Implication using (•_•_⇒₂-[_]_)
-- A naive primality test using bruteforce.
-- It checks if there are any divisors between 2 and p.
-- Note: The performance and space should be terrible on this implementation because it checks whether the list of all divisors is empty.
prime? : ℕ → Bool
prime? 0 = 𝐹
prime? 1 = 𝐹
prime? n@(𝐒(𝐒 _)) = decide(2)(_≡_) ⦃ [∃]-intro _ ⦃ List.[≡]-decider ⦃ dec = [≡?]-decider ⦄ ⦄ ⦄ (findBoundedAll 2 n (_∣₀? n)) ∅
instance
Prime-decider : Decider(1)(Prime)(prime?)
Prime-decider {𝟎} = false \()
Prime-decider {𝐒 𝟎} = false \()
Prime-decider {n@(𝐒(𝐒 x))} with prime? n | inspect prime? n
... | 𝑇 | intro eq = true $
eq ⇒
(prime? n ≡ 𝑇) ⇒-[ [↔]-to-[←] IsTrue.is-𝑇 ]
IsTrue(prime? n) ⇒-[ [↔]-to-[←] (decider-true ⦃ List.[≡]-decider ⦃ dec = [≡?]-decider ⦄ ⦄) ]
findBoundedAll 2 n (_∣₀? n) ≡ ∅ ⇒-[ (\empty {_} → [↔]-to-[←] (findBoundedAll-emptyness{f = _∣₀? n}) empty) ]
(∀{d} → (2 ≤ d) → (d < n) → IsFalse(d ∣₀? n)) ⇒-[ (\p {i} → [↔]-to-[←] (decider-false ⦃ [∣]-decider ⦄) ∘₂ p) ]
(∀{d} → (2 ≤ d) → (d < n) → ¬(d ∣ n)) ⇒-[]
(∀{d} → (2 ≤ d) → (d < 𝐒(𝐒(x))) → ¬(d ∣ 𝐒(𝐒(x)))) ⇒-[ (\p {d} div 2d dx → p{d} 2d (succ dx) div) ]
(∀{d} → (d ∣ 𝐒(𝐒(x))) → (2 ≤ d) → ¬(d ≤ 𝐒(x))) ⇒-[ (\p {d} div → [¬→]-disjunctive-formᵣ ⦃ decider-to-classical ⦃ [≡?]-decider ⦄ ⦄ \ nd0 → antisymmetry(_≤_)(_≡_) ([≤]-without-[𝐒] (divides-upper-limit div)) (sub₂(_≯_)(_≤_) (p{𝐒 d} div (succ ([≢]-to-[<]-of-0ᵣ nd0))))) ]
(∀{d} → (𝐒(d) ∣ 𝐒(𝐒(x))) → ((d ≡ 0) ∨ (d ≡ 𝐒(x)))) ⇒-[ intro ]
Prime n ⇒-end
... | 𝐹 | intro eq = false \p →
• (
p ⇒
Prime(n) ⇒-[ prime-only-divisors ]
(∀{d} → (d ∣ n) → ((d ≡ 1) ∨ (d ≡ n))) ⇒-[ (\p {d} 2d dn div → [∨]-elim (\{[≡]-intro → [≤][0]ᵣ-negation ([≤]-without-[𝐒] 2d)}) (\{[≡]-intro → irreflexivity(_<_) dn}) (p div)) ]
(∀{d} → (2 ≤ d) → (d < n) → ¬(d ∣ n)) ⇒-[ ((\p {i} → [↔]-to-[→] (decider-false ⦃ [∣]-decider ⦄) ∘₂ p)) ]
(∀{d} → (2 ≤ d) → (d < n) → IsFalse(d ∣₀? n)) ⇒-[ [↔]-to-[→] findBoundedAll-emptyness ]
findBoundedAll 2 n (_∣₀? n) ≡ ∅ ⇒-[ [↔]-to-[→] (decider-true ⦃ List.[≡]-decider ⦃ dec = [≡?]-decider ⦄ ⦄) ]
IsTrue(prime? n) ⇒-end
)
• (
eq ⇒
(prime? n ≡ 𝐹) ⇒-[ [↔]-to-[←] IsFalse.is-𝐹 ]
IsFalse(prime? n) ⇒-end
)
⇒₂-[ disjointness ]
Empty ⇒-end
import Data.Either as Either
open import Data.List.Relation.Membership using (_∈_)
open import Data.List.Relation.Membership.Proofs
open import Data.Tuple as Tuple using (_⨯_ ; _,_)
open import Logic.Propositional.Theorems
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Proofs
open import Numeral.Natural.Relation.Order.Existence using ([≤]-equivalence)
open import Structure.Function.Domain
open import Structure.Operator
open import Structure.Operator.Properties
open import Syntax.Transitivity
prime-composite-not : ∀{n} → Prime(n) → Composite(n) → ⊥
prime-composite-not {.(𝐒(𝐒(a)) ⋅ 𝐒(𝐒(b)))} p (intro a b) =
Either.map1
(\())
((\()) ∘ cancellationₗ(_+_) {x = a} ∘ injective(𝐒) ∘ injective(𝐒))
(prime-only-divisors p {𝐒(𝐒(a))} (divides-with-[⋅] {c = 𝐒(𝐒(b))} ([∨]-introₗ divides-reflexivity)))
-- Using Numeral.Natural.Decidable.prime?, when it is false, there is a divisor d between 2 and n for n. This means that (d ∣ n). Equivalently ∃(k ↦ d ⋅ k ≡ n). The proof of Composite uses these d and k.
prime-or-composite : ∀{n} → Prime(𝐒(𝐒(n))) ∨ Composite(𝐒(𝐒(n)))
prime-or-composite{n} = [¬→]-disjunctive-formᵣ ⦃ decider-to-classical ⦃ Prime-decider ⦄ ⦄ $
¬ Prime(𝐒(𝐒(n))) ⇒-[ [↔]-to-[→] (decider-false ⦃ Prime-decider ⦄) ]
IsFalse(prime? (𝐒(𝐒(n)))) ⇒-[ [↔]-to-[←] (decider-false ⦃ List.[≡]-decider ⦃ dec = [≡?]-decider ⦄ ⦄) ]
findBoundedAll 2 (𝐒(𝐒(n))) (_∣₀? 𝐒(𝐒(n))) ≢ ∅ ⇒-[ non-empty-inclusion-existence ]
∃(_∈ findBoundedAll 2 (𝐒(𝐒(n))) (_∣₀? 𝐒(𝐒(n)))) ⇒-[ [∃]-map-proof ([↔]-to-[→] (findBoundedAll-membership {f = _∣₀? 𝐒(𝐒(n))})) ]
∃(d ↦ (2 ≤ d) ∧ (d < 𝐒(𝐒(n))) ∧ IsTrue(d ∣₀? 𝐒(𝐒(n)))) ⇒-[ [∃]-map-proof ([∧]-map id ([↔]-to-[←] (decider-true ⦃ [∣]-decider ⦄))) ]
∃(d ↦ (2 ≤ d) ∧ (d < 𝐒(𝐒(n))) ∧ (d ∣ 𝐒(𝐒(n)))) ⇒-[ (\{([∃]-intro (𝐒 𝟎) ⦃ [∧]-intro ([∧]-intro (succ()) _) _ ⦄) ; ([∃]-intro (𝐒(𝐒 d)) ⦃ [∧]-intro ([∧]-intro d2 dn) div ⦄) → [∃]-intro d ⦃ [∧]-intro dn div ⦄}) ]
∃(d ↦ (𝐒(𝐒(d)) < 𝐒(𝐒(n))) ∧ (𝐒(𝐒(d)) ∣ 𝐒(𝐒(n)))) ⇒-[ (\{([∃]-intro d ⦃ [∧]-intro dn div ⦄) → [∃]-intro d ⦃ [∧]-intro dn ([∃]-intro div ⦃ divides-quotient-correctness {yx = div} ⦄) ⦄}) ]
∃(d ↦ (𝐒(𝐒(d)) < 𝐒(𝐒(n))) ∧ ∃{Obj = 𝐒(𝐒(d)) ∣ 𝐒(𝐒(n))}(q ↦ (𝐒(𝐒(d)) ⋅ divides-quotient q ≡ 𝐒(𝐒(n))))) ⇒-[ (\{([∃]-intro d ⦃ [∧]-intro dn ([∃]-intro q ⦃ prod ⦄) ⦄) → [∃]-intro (d , [∃]-witness ([↔]-to-[←] [≤]-equivalence (divides-quotient-composite (succ (succ min)) dn {q}))) ⦃ congruence₂ᵣ(_⋅_)(𝐒(𝐒(d))) (([∃]-proof ([↔]-to-[←] [≤]-equivalence (divides-quotient-composite (succ (succ min)) dn {q})))) 🝖 prod ⦄}) ]
∃{Obj = ℕ ⨯ ℕ}(\(a , b) → (𝐒(𝐒(a)) ⋅ 𝐒(𝐒(b)) ≡ 𝐒(𝐒(n)))) ⇒-[ [↔]-to-[←] composite-existence ]
Composite(𝐒(𝐒 n)) ⇒-end
prime-xor-composite : ∀{n} → Prime(𝐒(𝐒(n))) ⊕ Composite(𝐒(𝐒(n)))
prime-xor-composite {n} = [⊕]-or-not-both prime-or-composite (Tuple.uncurry prime-composite-not)
open import Data.Tuple
-- open import Numeral.Natural.Inductions
{-# TERMINATING #-}
-- TODO: Use strong induction. (a < n) because (a ⋅ b = n).
prime-factor-existence : ∀{n} → ∃(PrimeFactor(𝐒(𝐒(n))))
prime-factor-existence {n} with prime-or-composite{n}
... | Either.Left p = [∃]-intro (𝐒(𝐒(n))) ⦃ intro ⦃ p ⦄ ⦄
... | Either.Right c
with [∃]-intro(a , b) ⦃ p ⦄ ← [↔]-to-[→] composite-existence c
with [∃]-intro d ⦃ pa ⦄ ← prime-factor-existence{a}
= [∃]-intro d ⦃ divisor-primeFactors ([↔]-to-[→] divides-[⋅]-existence ([∃]-intro (𝐒 (𝐒 b)) ⦃ p ⦄)) pa ⦄
|
{
"alphanum_fraction": 0.5379049676,
"avg_line_length": 55.119047619,
"ext": "agda",
"hexsha": "b371d33f9a9e26b1b16306ebb4793d399e0a6256",
"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/Decidable.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/Decidable.agda",
"max_line_length": 418,
"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/Decidable.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": 3734,
"size": 9260
}
|
open import Level using (0ℓ)
open import Function using (_$_)
open import Relation.Binary.PropositionalEquality using (_≡_; _≢_; refl; sym; trans; cong; cong₂; isEquivalence; setoid; module ≡-Reasoning)
open import Relation.Binary.PropositionalEquality.WithK using (≡-irrelevant)
open import Relation.Nullary.Negation using (contradiction)
open ≡-Reasoning
open import Data.Unit using (⊤; tt)
open import Agda.Builtin.FromNat using (Number)
open import Data.Product using (_,_)
open import AKS.Primality using (IsPrime; Prime; bézout-prime)
module AKS.Modular.Quotient.Properties {P : Prime} where
open Prime P using () renaming (prime to p; isPrime to p-isPrime)
open IsPrime p-isPrime using (1<p)
open import AKS.Nat using (ℕ; zero; suc; _<_; _≤_; _∸_) renaming (_+_ to _+ℕ_; _*_ to _*ℕ_; _≟_ to _≟ℕ_)
open import AKS.Nat using (<⇒≤; [n∸m]+m≡n; suc-mono-≤; *-mono-≤; ≤-refl)
import AKS.Nat as Nat
import Data.Nat.Properties as Nat
open import AKS.Nat.Divisibility using (_%_; %-distribˡ-+; %-distribˡ-∸; %-distribˡ-*; m%n%n≡m%n; n<m⇒n%m≡n; n%m<m; n%n≡0; 0%m≡0; 1%m≡1; [m+kn]%n≡m%n)
open import AKS.Nat.GCD using (+ʳ; +ˡ)
open import AKS.Modular.Quotient.Base using (ℤ/[_]; ℤ✓; mod; mod<p; module Operations)
open Operations {P} using ([_]; _+_; _*_; -_; _⁻¹; _/_; _≟_; p≢0; ℤ/[]-irrelevance; n≢0⇒mod[n]≢0)
open import Algebra.Structures {A = ℤ/[ P ]} _≡_ using
( IsCommutativeRing; IsRing; IsAbelianGroup
; IsGroup; IsMonoid; IsSemigroup; IsMagma
)
open import Algebra.Definitions {A = ℤ/[ P ]} _≡_ using
( _DistributesOver_; _DistributesOverʳ_; _DistributesOverˡ_
; RightIdentity; LeftIdentity; Identity; Associative; Commutative
; RightInverse; LeftInverse; Inverse
)
open import AKS.Algebra.Structures (ℤ/[ P ]) _≡_ using (IsNonZeroCommutativeRing; IsIntegralDomain; IsGCDDomain; IsDecField)
open import Algebra.Bundles using (Ring; CommutativeRing)
open import AKS.Algebra.Bundles using (NonZeroCommutativeRing; DecField)
open import AKS.Unsafe using (≢-irrelevant)
+-isMagma : IsMagma _+_
+-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _+_
}
mod≡mod%p : ∀ (x : ℤ/[ P ]) → mod x ≡ (mod x % p) {p≢0}
mod≡mod%p (ℤ✓ x x<p) = sym (n<m⇒n%m≡n x<p)
mod≡mod%p%p : ∀ (x : ℤ/[ P ]) → mod x ≡ ((mod x % p) {p≢0} % p) {p≢0}
mod≡mod%p%p x = begin
mod x ≡⟨ mod≡mod%p x ⟩
mod x % p ≡⟨ sym (m%n%n≡m%n (mod x) p) ⟩
mod x % p % p ∎
+-assoc : Associative _+_
+-assoc x y z = ℤ/[]-irrelevance $ begin
((mod x +ℕ mod y) % p +ℕ mod z) % p ≡⟨ cong₂ (λ a b → (a +ℕ b) % p) (%-distribˡ-+ (mod x) (mod y) p {p≢0}) (mod≡mod%p z) ⟩
((mod x % p +ℕ mod y % p) % p +ℕ mod z % p) % p ≡⟨ sym (%-distribˡ-+ (mod x % p +ℕ mod y % p) (mod z) p) ⟩
((mod x % p +ℕ mod y % p) +ℕ mod z) % p ≡⟨ cong (λ a → (a % p) {p≢0}) (Nat.+-assoc (mod x % p) (mod y % p) (mod z)) ⟩
(mod x % p +ℕ (mod y % p +ℕ mod z)) % p ≡⟨ %-distribˡ-+ (mod x % p) (mod y % p +ℕ mod z) p ⟩
(mod x % p % p +ℕ (mod y % p +ℕ mod z) % p) % p ≡⟨ cong₂ (λ a b → (a +ℕ (b +ℕ mod z) % p) % p) (sym (mod≡mod%p%p x)) (sym (mod≡mod%p y)) ⟩
(mod x +ℕ (mod y +ℕ mod z) % p) % p ∎
+-isSemigroup : IsSemigroup _+_
+-isSemigroup = record
{ isMagma = +-isMagma
; assoc = +-assoc
}
+-comm : Commutative _+_
+-comm x y = ℤ/[]-irrelevance $ begin
(mod x +ℕ mod y) % p ≡⟨ cong (λ a → (a % p) {p≢0}) (Nat.+-comm (mod x) (mod y)) ⟩
(mod y +ℕ mod x) % p ∎
+-identityˡ : LeftIdentity 0 _+_
+-identityˡ x = ℤ/[]-irrelevance $ begin
(0 % p +ℕ mod x) % p ≡⟨ cong (λ a → (0 % p +ℕ a) % p) (mod≡mod%p x) ⟩
(0 % p +ℕ mod x % p) % p ≡⟨ sym (%-distribˡ-+ 0 (mod x) p) ⟩
(0 +ℕ mod x) % p ≡⟨ sym (mod≡mod%p x) ⟩
mod x ∎
open import Algebra.FunctionProperties.Consequences.Propositional using (comm+idˡ⇒idʳ; comm+invˡ⇒invʳ; comm+distrˡ⇒distrʳ)
+-identityʳ : RightIdentity 0 _+_
+-identityʳ = comm+idˡ⇒idʳ +-comm {0} +-identityˡ
+-identity : Identity 0 _+_
+-identity = +-identityˡ , +-identityʳ
+-isMonoid : IsMonoid _+_ 0
+-isMonoid = record
{ isSemigroup = +-isSemigroup
; identity = +-identity
}
-‿inverseˡ : LeftInverse 0 -_ _+_
-‿inverseˡ (ℤ✓ zero x<p) = refl
-‿inverseˡ (ℤ✓ (suc x) x<p) = ℤ/[]-irrelevance $ begin
((p ∸ suc x) +ℕ suc x) % p ≡⟨ cong (λ a → (a % p) {p≢0}) ([n∸m]+m≡n (<⇒≤ x<p)) ⟩
p % p ≡⟨ n%n≡0 p ⟩
0 ≡⟨ sym (0%m≡0 p {p≢0}) ⟩
0 % p ∎
-‿inverseʳ : RightInverse 0 -_ _+_
-‿inverseʳ = comm+invˡ⇒invʳ {_⁻¹ = -_} +-comm -‿inverseˡ
-‿inverse : Inverse 0 -_ _+_
-‿inverse = -‿inverseˡ , -‿inverseʳ
+-isGroup : IsGroup _+_ 0 -_
+-isGroup = record
{ isMonoid = +-isMonoid
; inverse = -‿inverse
; ⁻¹-cong = cong -_
}
+-isAbelianGroup : IsAbelianGroup _+_ 0 -_
+-isAbelianGroup = record
{ isGroup = +-isGroup
; comm = +-comm
}
*-isMagma : IsMagma _*_
*-isMagma = record
{ isEquivalence = isEquivalence
; ∙-cong = cong₂ _*_
}
*-assoc : Associative _*_
*-assoc x y z = ℤ/[]-irrelevance $ begin
((mod x *ℕ mod y) % p *ℕ mod z) % p ≡⟨ cong₂ (λ a b → (a *ℕ b) % p) (%-distribˡ-* (mod x) (mod y) p {p≢0}) (mod≡mod%p z) ⟩
(((mod x % p) *ℕ (mod y % p)) % p *ℕ (mod z % p)) % p ≡⟨ sym (%-distribˡ-* ((mod x % p) *ℕ (mod y % p)) (mod z) p) ⟩
(((mod x % p) *ℕ (mod y % p)) *ℕ mod z) % p ≡⟨ cong (λ a → (a % p) {p≢0}) (Nat.*-assoc (mod x % p) (mod y % p) (mod z)) ⟩
((mod x % p) *ℕ ((mod y % p) *ℕ mod z)) % p ≡⟨ %-distribˡ-* (mod x % p) ((mod y % p) *ℕ mod z) p ⟩
((mod x % p % p) *ℕ (((mod y % p) *ℕ mod z) % p)) % p ≡⟨ cong₂ (λ a b → (a *ℕ ((b *ℕ mod z) % p)) % p) (sym (mod≡mod%p%p x)) (sym (mod≡mod%p y)) ⟩
(mod x *ℕ ((mod y *ℕ mod z) % p)) % p ∎
*-isSemigroup : IsSemigroup _*_
*-isSemigroup = record
{ isMagma = *-isMagma
; assoc = *-assoc
}
*-comm : Commutative _*_
*-comm x y = ℤ/[]-irrelevance $ begin
(mod x *ℕ mod y) % p ≡⟨ cong (λ a → (a % p) {p≢0}) (Nat.*-comm (mod x) (mod y)) ⟩
(mod y *ℕ mod x) % p ∎
*-identityˡ : LeftIdentity 1 _*_
*-identityˡ x = ℤ/[]-irrelevance $ begin
(1 % p *ℕ mod x) % p ≡⟨ cong (λ a → ((a *ℕ mod x) % p) {p≢0}) (1%m≡1 1<p) ⟩
(1 *ℕ mod x) % p ≡⟨ cong (λ a → a % p) (Nat.*-identityˡ (mod x)) ⟩
mod x % p ≡⟨ sym (mod≡mod%p x) ⟩
mod x ∎
*-identityʳ : RightIdentity 1 _*_
*-identityʳ = comm+idˡ⇒idʳ *-comm {1} *-identityˡ
*-identity : Identity 1 _*_
*-identity = *-identityˡ , *-identityʳ
*-isMonoid : IsMonoid _*_ 1
*-isMonoid = record
{ isSemigroup = *-isSemigroup
; identity = *-identity
}
*-distribˡ-+ : _*_ DistributesOverˡ _+_
*-distribˡ-+ r x y = ℤ/[]-irrelevance $ begin
(mod r *ℕ ((mod x +ℕ mod y) % p)) % p ≡⟨ cong (λ a → (a *ℕ ((mod x +ℕ mod y) % p)) % p) (mod≡mod%p r) ⟩
(mod r % p *ℕ ((mod x +ℕ mod y) % p)) % p ≡⟨ sym (%-distribˡ-* (mod r) (mod x +ℕ mod y) p) ⟩
(mod r *ℕ (mod x +ℕ mod y)) % p ≡⟨ cong (λ a → (a % p) {p≢0}) (Nat.*-distribˡ-+ (mod r) (mod x) (mod y)) ⟩
(mod r *ℕ mod x +ℕ mod r *ℕ mod y) % p ≡⟨ %-distribˡ-+ (mod r *ℕ mod x) (mod r *ℕ mod y) p ⟩
((mod r *ℕ mod x) % p +ℕ (mod r *ℕ mod y) % p) % p ∎
*-distribʳ-+ : _*_ DistributesOverʳ _+_
*-distribʳ-+ = comm+distrˡ⇒distrʳ {_} {_} {_*_} {_+_} *-comm *-distribˡ-+
*-distrib-+ : _*_ DistributesOver _+_
*-distrib-+ = *-distribˡ-+ , *-distribʳ-+
+-*-isRing : IsRing _+_ _*_ -_ 0 1
+-*-isRing = record
{ +-isAbelianGroup = +-isAbelianGroup
; *-isMonoid = *-isMonoid
; distrib = *-distrib-+
}
+-*-isCommutativeRing : IsCommutativeRing _+_ _*_ -_ 0 1
+-*-isCommutativeRing = record
{ isRing = +-*-isRing
; *-comm = *-comm
}
open import Data.Empty using (⊥)
0≢1 : [ 0 ] ≢ [ 1 ]
0≢1 [0]≡[1] = false
where
0≡1 : zero ≡ 1
0≡1 = begin
0 ≡⟨ sym (0%m≡0 p {p≢0}) ⟩
0 % p ≡⟨ cong mod [0]≡[1] ⟩
1 % p ≡⟨ 1%m≡1 1<p ⟩
1 ∎
false : ⊥
false with 0≡1
... | ()
+-*-isNonZeroCommutativeRing : IsNonZeroCommutativeRing _+_ _*_ -_ 0 1
+-*-isNonZeroCommutativeRing = record
{ isCommutativeRing = +-*-isCommutativeRing
; 0#≉1# = 0≢1
}
+-*-nonZeroCommutativeRing : NonZeroCommutativeRing 0ℓ 0ℓ
+-*-nonZeroCommutativeRing = record { isNonZeroCommutativeRing = +-*-isNonZeroCommutativeRing }
⁻¹-inverse-lemma₁ : ∀ (n : ℤ/[ P ]) x y → 1 +ℕ x *ℕ mod n ≡ y *ℕ p → ((mod n *ℕ (p ∸ (x % p) {p≢0})) % p) {p≢0} ≡ (1 % p) {p≢0}
⁻¹-inverse-lemma₁ n x y 1+x*n≡y*p = begin
(mod n *ℕ (p ∸ x % p)) % p ≡⟨ cong (λ t → (t % p) {p≢0}) (Nat.*-distribˡ-∸ (mod n) p (x % p)) ⟩
((1 +ℕ mod n *ℕ p) ∸ (1 +ℕ mod n *ℕ (x % p))) % p ≡⟨ %-distribˡ-∸ (1 +ℕ mod n *ℕ p) (1 +ℕ mod n *ℕ (x % p)) p 1+n*x%p≤1+n*p ⟩
((1 +ℕ mod n *ℕ p) ∸ (1 +ℕ mod n *ℕ (x % p)) % p) % p ≡⟨ cong (λ t → ((1 +ℕ mod n *ℕ p) ∸ t) % p) lemma ⟩
((1 +ℕ mod n *ℕ p) ∸ 0) % p ≡⟨ [m+kn]%n≡m%n 1 (mod n) p ⟩
1 % p ∎
where
lemma : ((1 +ℕ mod n *ℕ (x % p) {p≢0}) % p) {p≢0} ≡ 0
lemma = begin
(1 +ℕ mod n *ℕ (x % p)) % p ≡⟨ cong (λ t → ((1 +ℕ t *ℕ (x % p) {p≢0}) % p) {p≢0}) (mod≡mod%p n) ⟩
(1 +ℕ (mod n % p) *ℕ (x % p)) % p ≡⟨ %-distribˡ-+ 1 ((mod n % p) *ℕ (x % p)) p ⟩
(1 % p +ℕ ((mod n % p) *ℕ (x % p)) % p) % p ≡⟨ cong (λ t → (1 % p +ℕ t) % p) (sym (%-distribˡ-* (mod n) x p)) ⟩
(1 % p +ℕ (mod n *ℕ x) % p) % p ≡⟨ sym (%-distribˡ-+ 1 (mod n *ℕ x) p) ⟩
(1 +ℕ mod n *ℕ x) % p ≡⟨ cong (λ t → ((1 +ℕ t) % p) {p≢0}) (Nat.*-comm (mod n) x) ⟩
(1 +ℕ x *ℕ mod n) % p ≡⟨ cong (λ t → (t % p) {p≢0}) 1+x*n≡y*p ⟩
(y *ℕ p) % p ≡⟨ [m+kn]%n≡m%n 0 y p ⟩
0 % p ≡⟨ 0%m≡0 p ⟩
0 ∎
1+n*x%p≤1+n*p : 1 +ℕ mod n *ℕ (x % p) {p≢0} ≤ 1 +ℕ mod n *ℕ p
1+n*x%p≤1+n*p = suc-mono-≤ (*-mono-≤ {mod n} ≤-refl (<⇒≤ (n%m<m x p)))
⁻¹-inverse-lemma₂ : ∀ (n : ℤ/[ P ]) x y → 1 +ℕ y *ℕ p ≡ x *ℕ mod n → ((mod n *ℕ (x % p) {p≢0}) % p) {p≢0} ≡ (1 % p) {p≢0}
⁻¹-inverse-lemma₂ n x y 1+y*p≡x*n = begin
(mod n *ℕ (x % p)) % p ≡⟨ cong (λ t → (t *ℕ (x % p)) % p) (mod≡mod%p n) ⟩
((mod n % p) *ℕ (x % p)) % p ≡⟨ sym (%-distribˡ-* (mod n) x p) ⟩
(mod n *ℕ x) % p ≡⟨ cong (λ t → (t % p) {p≢0}) (Nat.*-comm (mod n) x) ⟩
(x *ℕ mod n) % p ≡⟨ cong (λ t → (t % p) {p≢0}) (sym 1+y*p≡x*n) ⟩
(1 +ℕ y *ℕ p) % p ≡⟨ [m+kn]%n≡m%n 1 y p ⟩
1 % p ∎
⁻¹-inverse : ∀ n {n≢0} → n * (n ⁻¹) {n≢0} ≡ 1
⁻¹-inverse n {n≢0} with bézout-prime (mod n) p (n≢0⇒mod[n]≢0 n≢0) (mod<p n) p-isPrime
... | +ʳ x y 1+x*n≡y*p = ℤ/[]-irrelevance (⁻¹-inverse-lemma₁ n x y 1+x*n≡y*p)
... | +ˡ x y 1+y*p≡x*n = ℤ/[]-irrelevance (⁻¹-inverse-lemma₂ n x y 1+y*p≡x*n)
/-inverse : ∀ x y {y≢0} → x ≡ y * (x / y) {y≢0}
/-inverse x y {y≢0} = begin
x ≡⟨ sym (*-identityʳ x) ⟩
x * 1 ≡⟨ cong (λ a → x * a) (sym (⁻¹-inverse y {y≢0})) ⟩
x * (y * (y ⁻¹) {y≢0}) ≡⟨ sym (*-assoc x y ((y ⁻¹) {y≢0})) ⟩
(x * y) * (y ⁻¹) {y≢0} ≡⟨ cong (λ a → a * (y ⁻¹) {y≢0}) (*-comm x y) ⟩
(y * x) * (y ⁻¹) {y≢0} ≡⟨ *-assoc y x ((y ⁻¹) {y≢0}) ⟩
y * (x / y) {y≢0} ∎
open import AKS.Algebra.Consequences +-*-nonZeroCommutativeRing using (module Inverse⇒Field)
open Inverse⇒Field _≟_ ≡-irrelevant ≢-irrelevant _/_ /-inverse
using (gcd)
renaming (isField to +-*-/-isField; [field] to +-*-/-field) public
+-*-/-isDecField : IsDecField _≟_ _+_ _*_ -_ 0 1 _/_ gcd
+-*-/-isDecField = record { isField = +-*-/-isField }
+-*-/-decField : DecField 0ℓ 0ℓ
+-*-/-decField = record { isDecField = +-*-/-isDecField }
|
{
"alphanum_fraction": 0.5135393992,
"avg_line_length": 40.5830388693,
"ext": "agda",
"hexsha": "987ae01c3b3dfc19a4243e8a65df42354bbf951a",
"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/Modular/Quotient/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/Modular/Quotient/Properties.agda",
"max_line_length": 150,
"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/Modular/Quotient/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": 5547,
"size": 11485
}
|
-- {-# OPTIONS -v tc.term.exlam:100 -v extendedlambda:100 -v int2abs.reifyterm:100 #-}
-- Andreas, 2013-02-26
module Issue778 (Param : Set) where
open import Common.Prelude
works : Nat → Nat
works with zero
... | zero = λ { zero → zero; (suc x) → suc x }
... | suc _ = λ { x → x }
test : Nat → Nat
test = λ { zero → zero; (suc x) → aux x }
where aux : Nat → Nat
aux x with works x
... | zero = zero
... | suc y = works y
-- There was a internal error in connection to extended lambda and
-- where blocks in parametrized modules.
|
{
"alphanum_fraction": 0.6064400716,
"avg_line_length": 27.95,
"ext": "agda",
"hexsha": "510318a99615a0ca0167d871719c95a136eed7a8",
"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/Issue778.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/Issue778.agda",
"max_line_length": 86,
"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/Issue778.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": 173,
"size": 559
}
|
{-# OPTIONS --cubical --no-import-sorts --safe --postfix-projections #-}
open import Cubical.Core.Everything
open import Cubical.Functions.Embedding
open import Cubical.Foundations.Equiv
open import Cubical.Foundations.Function
open import Cubical.Foundations.Isomorphism
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Univalence
open import Cubical.Foundations.Transport
-- A helper module for deriving univalence for a higher inductive-recursive
-- universe.
--
-- U is the type of codes
-- El is the decoding
-- un is a higher constructor that requires paths between codes to exist
-- for equivalences of decodings
-- comp is intended to be the computational behavior of El on un, although
-- it seems that being a path is sufficient.
--
-- Given a universe defined as above, it's possible to show that the path
-- space of the code type is equivalent to the path space of the actual
-- decodings, which are themselves determined by equivalences.
--
-- The levels are left independent, but of course it will generally be
-- impossible to define this sort of universe unless ℓ' < ℓ, because El will
-- be too big to go in a constructor of U. The exception would be if U could
-- be defined independently of El, though it might be tricky to get the right
-- higher structure in such a case.
module Cubical.Foundations.Univalence.Universe {ℓ ℓ'}
(U : Type ℓ)
(El : U → Type ℓ')
(un : ∀ s t → El s ≃ El t → s ≡ t)
(comp : ∀{s t} (e : El s ≃ El t) → cong El (un s t e) ≡ ua e)
where
private
variable
A : Type ℓ'
module UU-Lemmas where
reg : transport (λ _ → A) ≡ idfun A
reg {A} i z = transp (λ _ → A) i z
nu : ∀ x y → x ≡ y → El x ≃ El y
nu x y p = transportEquiv (cong El p)
cong-un-te
: ∀ x y (p : El x ≡ El y)
→ cong El (un x y (transportEquiv p)) ≡ p
cong-un-te x y p
= comp (transportEquiv p) ∙ uaTransportη p
nu-un : ∀ x y (e : El x ≃ El y) → nu x y (un x y e) ≡ e
nu-un x y e
= equivEq {e = nu x y (un x y e)} {f = e} λ i z
→ (cong (λ p → transport p z) (comp e) ∙ uaβ e z) i
El-un-equiv : ∀ x i → El (un x x (idEquiv _) i) ≃ El x
El-un-equiv x i = λ where
.fst → transp (λ j → p j) (i ∨ ~ i)
.snd → transp (λ j → isEquiv (transp (λ k → p (j ∧ k)) (~ j ∨ i ∨ ~ i)))
(i ∨ ~ i) (idIsEquiv T)
where
T = El (un x x (idEquiv _) i)
p : T ≡ El x
p j = (comp (idEquiv _) ∙ uaIdEquiv {A = El x}) j i
un-refl : ∀ x → un x x (idEquiv (El x)) ≡ refl
un-refl x i j
= hcomp (λ k → λ where
(i = i0) → un x x (idEquiv (El x)) j
(i = i1) → un x x (idEquiv (El x)) (j ∨ k)
(j = i0) → un x x (idEquiv (El x)) (~ i ∨ k)
(j = i1) → x)
(un (un x x (idEquiv (El x)) (~ i)) x (El-un-equiv x (~ i)) j)
nu-refl : ∀ x → nu x x refl ≡ idEquiv (El x)
nu-refl x = equivEq {e = nu x x refl} {f = idEquiv (El x)} reg
un-nu : ∀ x y (p : x ≡ y) → un x y (nu x y p) ≡ p
un-nu x y p
= J (λ z q → un x z (nu x z q) ≡ q) (cong (un x x) (nu-refl x) ∙ un-refl x) p
open UU-Lemmas
open Iso
equivIso : ∀ s t → Iso (s ≡ t) (El s ≃ El t)
equivIso s t .fun = nu s t
equivIso s t .inv = un s t
equivIso s t .rightInv = nu-un s t
equivIso s t .leftInv = un-nu s t
pathIso : ∀ s t → Iso (s ≡ t) (El s ≡ El t)
pathIso s t .fun = cong El
pathIso s t .inv = un s t ∘ transportEquiv
pathIso s t .rightInv = cong-un-te s t
pathIso s t .leftInv = un-nu s t
minivalence : ∀{s t} → (s ≡ t) ≃ (El s ≃ El t)
minivalence {s} {t} = isoToEquiv (equivIso s t)
path-reflection : ∀{s t} → (s ≡ t) ≃ (El s ≡ El t)
path-reflection {s} {t} = isoToEquiv (pathIso s t)
isEmbeddingEl : isEmbedding El
isEmbeddingEl s t = snd path-reflection
|
{
"alphanum_fraction": 0.6042059854,
"avg_line_length": 34.0275229358,
"ext": "agda",
"hexsha": "ac7c847361e1bf335603ec5ac61cf7c5484eae53",
"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/Foundations/Univalence/Universe.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/Foundations/Univalence/Universe.agda",
"max_line_length": 81,
"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/Foundations/Univalence/Universe.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 1353,
"size": 3709
}
|
open import Agda.Builtin.FromNat
open import Data.Nat.Base as ℕ using (ℕ; suc; zero; _>_; _≤?_)
open import Data.List.Base as L using (List; _∷_; []; _++_)
open import Relation.Nullary.Decidable using (True)
open import Relation.Binary.PropositionalEquality as P using (_≡_)
module Data.Pos where
open import Data.Nat.FromNat public
data ℕ⁺ : Set where
suc : ℕ → ℕ⁺
instance
NumberPos : Number ℕ⁺
NumberPos = record { Constraint = Pos; fromNat = fromℕ }
where
Pos : ℕ → Set
Pos n = True (suc zero ≤? n)
fromℕ : (n : ℕ) {{p : Pos n}} → ℕ⁺
fromℕ zero {{()}}
fromℕ (suc zero) = suc zero
fromℕ (suc (suc n)) = suc (suc n)
toℕ : ℕ⁺ → ℕ
toℕ (suc n) = suc n
_+_ : ℕ⁺ → ℕ⁺ → ℕ⁺
suc m + n = suc (m ℕ.+ toℕ n)
toℕ-+ : (m {n} : ℕ⁺) → toℕ m ℕ.+ toℕ n ≡ toℕ (m + n)
toℕ-+ (suc m) = P.refl
replicate⁺ : ∀ {a} {A : Set a} → ℕ⁺ → A → List A
replicate⁺ (suc n) x = x ∷ L.replicate n x
replicate⁺-++-commute : ∀ {a} {A : Set a} {x : A} (m n : ℕ⁺) →
replicate⁺ m x ++ replicate⁺ n x ≡ replicate⁺ (m + n) x
replicate⁺-++-commute (suc m) (suc n)
= P.cong (_ ∷_) (replicate-++-commute m (suc n))
where
replicate-++-commute : ∀ {a} {A : Set a} {x : A} (m n : ℕ) →
L.replicate m x ++ L.replicate n x ≡ L.replicate (m ℕ.+ n) x
replicate-++-commute zero n = P.refl
replicate-++-commute (suc m) n = P.cong (_ ∷_) (replicate-++-commute m n)
|
{
"alphanum_fraction": 0.5675482487,
"avg_line_length": 30.4130434783,
"ext": "agda",
"hexsha": "15e5de43ac57d8b1a22014b7d0efae462cef7b22",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-09-05T08:58:13.000Z",
"max_forks_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "pepijnkokke/nodcap",
"max_forks_repo_path": "src/cpnd1/Data/Pos.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "pepijnkokke/nodcap",
"max_issues_repo_path": "src/cpnd1/Data/Pos.agda",
"max_line_length": 77,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "fb5e78d6182276e4d93c4c0e0d563b6b027bc5c2",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "wenkokke/nodcap",
"max_stars_repo_path": "src/cpnd1/Data/Pos.agda",
"max_stars_repo_stars_event_max_datetime": "2019-09-24T20:16:35.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-09-05T08:58:11.000Z",
"num_tokens": 582,
"size": 1399
}
|
-- Andreas, 2011-09-12
-- eta for records in unifier
-- {-# OPTIONS -v tc.lhs.unify:25 #-}
module Issue455 where
postulate
A : Set
a : A
record Fork : Set where
constructor pair
field fst : A
snd : A
open Fork
data D : Fork -> Set where
c : (x y : A) -> D (pair x y)
postulate p : Fork
f : D p -> Set
f (c .(fst p) .(snd p)) = A -- should work!
{- Unifier gives up on:
f z = {!z!}
Cannot decide whether there should be a case for the constructor c,
since the unification gets stuck on unifying the inferred indices
[pair x y] with the expected indices [p]
-}
record ⊤ : Set where
constructor tt
data E : ⊤ -> Set where
e : E tt
postulate q : ⊤
g : E q -> Set
g e = ⊤
|
{
"alphanum_fraction": 0.6161473088,
"avg_line_length": 15.6888888889,
"ext": "agda",
"hexsha": "775195e1b4d0e073d78d644fa35b49aed0fa168f",
"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/Issue455.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/Issue455.agda",
"max_line_length": 67,
"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/Issue455.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": 233,
"size": 706
}
|
open import Nat
open import Prelude
open import contexts
open import core
module canonical-value-forms where
canonical-value-forms-b : ∀{Δ d} →
Δ , ∅ ⊢ d :: b →
d val →
d == c
canonical-value-forms-b TAConst VConst = refl
canonical-value-forms-b (TAVar x₁) ()
canonical-value-forms-b (TAAp wt wt₁) ()
canonical-value-forms-b (TAEHole x x₁) ()
canonical-value-forms-b (TANEHole x wt x₁) ()
canonical-value-forms-b (TACast wt x) ()
canonical-value-forms-b (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-b (TAFst wt) ()
canonical-value-forms-b (TASnd wt) ()
canonical-value-forms-arr : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ==> τ2) →
d val →
Σ[ x ∈ Nat ] Σ[ d' ∈ iexp ]
((d == (·λ x [ τ1 ] d')) ×
(Δ , ■ (x , τ1) ⊢ d' :: τ2))
canonical-value-forms-arr (TAVar x₁) ()
canonical-value-forms-arr (TALam _ wt) VLam = _ , _ , refl , wt
canonical-value-forms-arr (TAAp wt wt₁) ()
canonical-value-forms-arr (TAEHole x x₁) ()
canonical-value-forms-arr (TANEHole x wt x₁) ()
canonical-value-forms-arr (TACast wt x) ()
canonical-value-forms-arr (TAFailedCast x x₁ x₂ x₃) ()
canonical-value-forms-arr (TAFst wt) ()
canonical-value-forms-arr (TASnd wt) ()
canonical-value-forms-prod : ∀{Δ d τ1 τ2} →
Δ , ∅ ⊢ d :: (τ1 ⊗ τ2) →
d val →
Σ[ d1 ∈ iexp ] Σ[ d2 ∈ iexp ]
((d == ⟨ d1 , d2 ⟩ ) ×
(Δ , ∅ ⊢ d1 :: τ1) ×
(Δ , ∅ ⊢ d2 :: τ2))
canonical-value-forms-prod (TAVar x₁) ()
canonical-value-forms-prod (TAAp wt wt₁) ()
canonical-value-forms-prod (TAEHole x x₁) ()
canonical-value-forms-prod (TANEHole x wt x₁) ()
canonical-value-forms-prod (TACast wt x) ()
canonical-value-forms-prod (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-prod (TAFst wt) ()
canonical-value-forms-prod (TASnd wt) ()
canonical-value-forms-prod (TAPair wt wt₁) (VPair dv dv₁) = _ , _ , refl , wt , wt₁
-- this argues (somewhat informally, because you still have to inspect
-- the types of the theorems above and manually verify this property)
-- that we didn't miss any cases above; this intentionally will make this
-- file fail to typecheck if we added more types, hopefully forcing us to
-- remember to add canonical forms lemmas as appropriate
canonical-value-forms-coverage1 : ∀{Δ d τ} →
Δ , ∅ ⊢ d :: τ →
d val →
τ ≠ b →
((τ1 : typ) (τ2 : typ) → τ ≠ (τ1 ==> τ2)) →
((τ1 : typ) (τ2 : typ) → τ ≠ (τ1 ⊗ τ2)) →
⊥
canonical-value-forms-coverage1 TAConst VConst = λ z _ _ → z refl
canonical-value-forms-coverage1 (TAVar x₁) ()
canonical-value-forms-coverage1 (TALam _ wt) VLam = λ _ z _ → z _ _ refl
canonical-value-forms-coverage1 (TAAp wt wt₁) ()
canonical-value-forms-coverage1 (TAEHole x x₁) ()
canonical-value-forms-coverage1 (TANEHole x wt x₁) ()
canonical-value-forms-coverage1 (TACast wt x) ()
canonical-value-forms-coverage1 (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-coverage1 (TAFst wt) ()
canonical-value-forms-coverage1 (TASnd wt) ()
canonical-value-forms-coverage1 (TAPair wt wt₁) (VPair dv dv₁) ne h = λ z → z _ _ refl
canonical-value-forms-coverage2 : ∀{Δ d} →
Δ , ∅ ⊢ d :: ⦇·⦈ →
d val →
⊥
canonical-value-forms-coverage2 (TAVar x₁) ()
canonical-value-forms-coverage2 (TAAp wt wt₁) ()
canonical-value-forms-coverage2 (TAEHole x x₁) ()
canonical-value-forms-coverage2 (TANEHole x wt x₁) ()
canonical-value-forms-coverage2 (TACast wt x) ()
canonical-value-forms-coverage2 (TAFailedCast wt x x₁ x₂) ()
canonical-value-forms-coverage2 (TAFst wt) ()
canonical-value-forms-coverage2 (TASnd wt) ()
|
{
"alphanum_fraction": 0.5433703616,
"avg_line_length": 47.0111111111,
"ext": "agda",
"hexsha": "6dccea372d1f0f4b655c24ec1f0ef367e70ce48a",
"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": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "hazelgrove/hazelnut-livelits-agda",
"max_forks_repo_path": "canonical-value-forms.agda",
"max_issues_count": 9,
"max_issues_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_issues_repo_issues_event_max_datetime": "2020-10-20T20:44:13.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-09-30T20:27:56.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "hazelgrove/hazel-palette-agda",
"max_issues_repo_path": "canonical-value-forms.agda",
"max_line_length": 88,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "c3225acc3c94c56376c6842b82b8b5d76912df2a",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "hazelgrove/hazel-palette-agda",
"max_stars_repo_path": "canonical-value-forms.agda",
"max_stars_repo_stars_event_max_datetime": "2021-12-19T15:38:31.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-10-04T06:45:06.000Z",
"num_tokens": 1291,
"size": 4231
}
|
module Arith where
open import Common.IO
open import Common.Nat renaming (_∸_ to _-_) -- workaround for #1855
open import Common.Unit
test : Nat
test = 4
foobar : Nat -> Nat
foobar zero = zero
foobar (suc n) = suc (suc n)
main : IO Unit
main =
-- n <- readNat ,
printNat 0 ,,
printNat (0 + 1) ,,
printNat (1 * 2) ,,
printNat (suc (suc (suc (suc zero))) - suc zero) ,,
printNat test ,,
printNat (foobar 4) ,,
-- printNat n ,,
return unit
|
{
"alphanum_fraction": 0.6225596529,
"avg_line_length": 18.44,
"ext": "agda",
"hexsha": "7f76215dc47f0b17eba683e48a3c2138b90c6925",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/Compiler/simple/Arith.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/Compiler/simple/Arith.agda",
"max_line_length": 69,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/Compiler/simple/Arith.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": 164,
"size": 461
}
|
module SafeFlagPostulate where
data Empty : Set where
postulate inhabitant : Empty
|
{
"alphanum_fraction": 0.8117647059,
"avg_line_length": 14.1666666667,
"ext": "agda",
"hexsha": "c1b0ca201799f28d4d6f5e64839cd963d01db79d",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Fail/SafeFlagPostulate.agda",
"max_issues_count": 3,
"max_issues_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"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": "hborum/agda",
"max_issues_repo_path": "test/Fail/SafeFlagPostulate.agda",
"max_line_length": 30,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "aac88412199dd4cbcb041aab499d8a6b7e3f4a2e",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "hborum/agda",
"max_stars_repo_path": "test/Fail/SafeFlagPostulate.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": 20,
"size": 85
}
|
module Data.Bin.NatHelpers where
open import Relation.Binary.PropositionalEquality
open import Data.Empty
open import Data.Fin using (Fin; zero; suc) renaming (toℕ to finToℕ)
open import Data.Nat using(ℕ; zero; suc; _≤_; _+_; _*_; s≤s; z≤n; ≤′-step; ≤′-refl; _<_; _∸_)
open import Data.Nat.Properties using(_*-mono_; ≤′⇒≤; ≤⇒≤′)
open import Function using (_∘_)
open import Relation.Nullary
≤-step : ∀ {a b} → a ≤ b → a ≤ suc b
≤-step = ≤′⇒≤ ∘ ≤′-step ∘ ≤⇒≤′
*2-mono : ∀ x → x ≤ x * 2
*2-mono zero = z≤n
*2-mono (suc x) = s≤s (≤-step (*2-mono x))
kojojo : ∀ (b : Fin 2) x → x ≢ 0 → suc x ≤ finToℕ b + x * 2
kojojo b zero nz = ⊥-elim (nz refl)
kojojo zero (suc y) nz = s≤s (s≤s (*2-mono y))
kojojo (suc zero) (suc y) nz = s≤s (s≤s (≤-step (*2-mono y)))
kojojo (suc (suc ())) (suc y) nz
*2-gives-space : ∀ {x y z} → (x < y) → z < 2 → x * 2 + z < y * 2
*2-gives-space {suc x} {suc (suc y)} (s≤s (s≤s less)) zz = s≤s (s≤s (*2-gives-space {x} {suc y} (s≤s less) zz))
*2-gives-space (s≤s z≤n) (s≤s (s≤s z≤n)) = s≤s (s≤s z≤n)
*2-gives-space (s≤s z≤n) (s≤s z≤n) = s≤s z≤n
open import Data.Product
x≮z→x≡z+y : ∀ {x z} → ¬ x < z → ∃ λ y → x ≡ z + y
x≮z→x≡z+y {zero} {zero} x≮z = zero , refl
x≮z→x≡z+y {suc x} {zero} x≮z = suc x , refl
x≮z→x≡z+y {zero} {suc z} x≮z = ⊥-elim (x≮z (s≤s z≤n))
x≮z→x≡z+y {suc x} {suc z} x≮z with x≮z→x≡z+y {x} {z} (λ z' → x≮z (s≤s z'))
x≮z→x≡z+y {suc .(z + y)} {suc z} x≮z | y , refl = y , refl
+-elim₁ : ∀ {x y z} → z + x < z + y → x < y
+-elim₁ {x} {y} {zero} lt = lt
+-elim₁ {x} {y} {suc z} (s≤s lt) = +-elim₁ {x} {y} {z} lt
import Data.Nat.Properties
open import Algebra.Structures
open IsCommutativeSemiring (Data.Nat.Properties.isCommutativeSemiring)
+-elim₂ : ∀ {x y z} → x + z < y + z → x < y
+-elim₂ {x} {y} {z} lt rewrite +-comm x z | +-comm y z = +-elim₁ {x} {y} {z} lt
|
{
"alphanum_fraction": 0.5069124424,
"avg_line_length": 40.6875,
"ext": "agda",
"hexsha": "8d7eb939ed6d0446b823e7c0515a92dd476b0ebf",
"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": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_forks_repo_licenses": [
"Unlicense"
],
"max_forks_repo_name": "Rotsor/BinDivMod",
"max_forks_repo_path": "Data/Bin/NatHelpers.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"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": "Rotsor/BinDivMod",
"max_issues_repo_path": "Data/Bin/NatHelpers.agda",
"max_line_length": 115,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "09cc5104421e88da82f9fead5a43f0028f77810d",
"max_stars_repo_licenses": [
"Unlicense"
],
"max_stars_repo_name": "Rotsor/BinDivMod",
"max_stars_repo_path": "Data/Bin/NatHelpers.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-18T13:58:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-18T13:58:14.000Z",
"num_tokens": 974,
"size": 1953
}
|
{-# OPTIONS --safe #-}
module Cubical.Algebra.Group.Base where
{-
Defines groups and adds the smart constructors [makeGroup-right] and [makeGroup-left]
for constructing groups from less data than the standard [makeGroup] constructor.
-}
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Structure
open import Cubical.Data.Sigma
open import Cubical.Algebra.Monoid
open import Cubical.Algebra.Semigroup
open import Cubical.Reflection.RecordEquiv
private
variable
ℓ : Level
record IsGroup {G : Type ℓ}
(1g : G) (_·_ : G → G → G) (inv : G → G) : Type ℓ where
constructor isgroup
field
isMonoid : IsMonoid 1g _·_
·InvR : (x : G) → x · inv x ≡ 1g
·InvL : (x : G) → inv x · x ≡ 1g
open IsMonoid isMonoid public
unquoteDecl IsGroupIsoΣ = declareRecordIsoΣ IsGroupIsoΣ (quote IsGroup)
record GroupStr (G : Type ℓ) : Type ℓ where
constructor groupstr
field
1g : G
_·_ : G → G → G
inv : G → G
isGroup : IsGroup 1g _·_ inv
infixr 7 _·_
open IsGroup isGroup public
Group : ∀ ℓ → Type (ℓ-suc ℓ)
Group ℓ = TypeWithStr ℓ GroupStr
Group₀ : Type₁
Group₀ = Group ℓ-zero
group : (G : Type ℓ) (1g : G) (_·_ : G → G → G) (inv : G → G) (h : IsGroup 1g _·_ inv) → Group ℓ
group G 1g _·_ inv h = G , groupstr 1g _·_ inv h
isSetGroup : (G : Group ℓ) → isSet ⟨ G ⟩
isSetGroup G = GroupStr.isGroup (snd G) .IsGroup.isMonoid .IsMonoid.isSemigroup .IsSemigroup.is-set
makeIsGroup : {G : Type ℓ} {e : G} {_·_ : G → G → G} { inv : G → G}
(is-setG : isSet G)
(·Assoc : (x y z : G) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : G) → x · e ≡ x)
(·IdL : (x : G) → e · x ≡ x)
(·InvR : (x : G) → x · inv x ≡ e)
(·InvL : (x : G) → inv x · x ≡ e)
→ IsGroup e _·_ inv
IsGroup.isMonoid (makeIsGroup is-setG ·Assoc ·IdR ·IdL ·InvR ·InvL) = makeIsMonoid is-setG ·Assoc ·IdR ·IdL
IsGroup.·InvR (makeIsGroup is-setG ·Assoc ·IdR ·IdL ·InvR ·InvL) = ·InvR
IsGroup.·InvL (makeIsGroup is-setG ·Assoc ·IdR ·IdL ·InvR ·InvL) = ·InvL
makeGroup : {G : Type ℓ} (1g : G) (_·_ : G → G → G) (inv : G → G)
(is-setG : isSet G)
(·Assoc : (x y z : G) → x · (y · z) ≡ (x · y) · z)
(·IdR : (x : G) → x · 1g ≡ x)
(·IdL : (x : G) → 1g · x ≡ x)
(·InvR : (x : G) → x · inv x ≡ 1g)
(·InvL : (x : G) → inv x · x ≡ 1g)
→ Group ℓ
makeGroup 1g _·_ inv is-setG ·Assoc ·IdR ·IdL ·InvR ·InvL = _ , helper
where
helper : GroupStr _
GroupStr.1g helper = 1g
GroupStr._·_ helper = _·_
GroupStr.inv helper = inv
GroupStr.isGroup helper = makeIsGroup is-setG ·Assoc ·IdR ·IdL ·InvR ·InvL
Group→Monoid : Group ℓ → Monoid ℓ
Group→Monoid (A , groupstr _ _ _ G) = A , monoidstr _ _ (IsGroup.isMonoid G)
makeGroup-right : {A : Type ℓ}
→ (1g : A)
→ (_·_ : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (·Assoc : ∀ a b c → a · (b · c) ≡ (a · b) · c)
→ (·IdR : ∀ a → a · 1g ≡ a)
→ (·InvR : ∀ a → a · inv a ≡ 1g)
→ Group ℓ
makeGroup-right 1g _·_ inv set ·Assoc ·IdR ·InvR =
makeGroup 1g _·_ inv set ·Assoc ·IdR ·IdL ·InvR ·InvL
where
abstract
·InvL : ∀ a → inv a · a ≡ 1g
·InvL a =
inv a · a
≡⟨ sym (·IdR _) ⟩
(inv a · a) · 1g
≡⟨ cong (_·_ _) (sym (·InvR (inv a))) ⟩
(inv a · a) · (inv a · (inv (inv a)))
≡⟨ ·Assoc _ _ _ ⟩
((inv a · a) · (inv a)) · (inv (inv a))
≡⟨ cong (λ □ → □ · _) (sym (·Assoc _ _ _)) ⟩
(inv a · (a · inv a)) · (inv (inv a))
≡⟨ cong (λ □ → (inv a · □) · (inv (inv a))) (·InvR a) ⟩
(inv a · 1g) · (inv (inv a))
≡⟨ cong (λ □ → □ · (inv (inv a))) (·IdR (inv a)) ⟩
inv a · (inv (inv a))
≡⟨ ·InvR (inv a) ⟩
1g
∎
·IdL : ∀ a → 1g · a ≡ a
·IdL a =
1g · a
≡⟨ cong (λ b → b · a) (sym (·InvR a)) ⟩
(a · inv a) · a
≡⟨ sym (·Assoc _ _ _) ⟩
a · (inv a · a)
≡⟨ cong (a ·_) (·InvL a) ⟩
a · 1g
≡⟨ ·IdR a ⟩
a
∎
makeGroup-left : {A : Type ℓ}
→ (1g : A)
→ (_·_ : A → A → A)
→ (inv : A → A)
→ (set : isSet A)
→ (·Assoc : ∀ a b c → a · (b · c) ≡ (a · b) · c)
→ (·IdL : ∀ a → 1g · a ≡ a)
→ (·InvL : ∀ a → (inv a) · a ≡ 1g)
→ Group ℓ
makeGroup-left 1g _·_ inv set ·Assoc ·IdL ·InvL =
makeGroup 1g _·_ inv set ·Assoc ·IdR ·IdL ·InvR ·InvL
where
abstract
·InvR : ∀ a → a · inv a ≡ 1g
·InvR a =
a · inv a
≡⟨ sym (·IdL _) ⟩
1g · (a · inv a)
≡⟨ cong (λ b → b · (a · inv a)) (sym (·InvL (inv a))) ⟩
(inv (inv a) · inv a) · (a · inv a)
≡⟨ sym (·Assoc (inv (inv a)) (inv a) _) ⟩
inv (inv a) · (inv a · (a · inv a))
≡⟨ cong (inv (inv a) ·_) (·Assoc (inv a) a (inv a)) ⟩
(inv (inv a)) · ((inv a · a) · (inv a))
≡⟨ cong (λ b → (inv (inv a)) · (b · (inv a))) (·InvL a) ⟩
inv (inv a) · (1g · inv a)
≡⟨ cong (inv (inv a) ·_) (·IdL (inv a)) ⟩
inv (inv a) · inv a
≡⟨ ·InvL (inv a) ⟩
1g
∎
·IdR : ∀ a → a · 1g ≡ a
·IdR a =
a · 1g
≡⟨ cong (a ·_) (sym (·InvL a)) ⟩
a · (inv a · a)
≡⟨ ·Assoc a (inv a) a ⟩
(a · inv a) · a
≡⟨ cong (λ b → b · a) (·InvR a) ⟩
1g · a
≡⟨ ·IdL a ⟩
a
∎
|
{
"alphanum_fraction": 0.4654792508,
"avg_line_length": 30.0883977901,
"ext": "agda",
"hexsha": "b209bc5d1470a8fe77acd2073a65ffcc860a1082",
"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/Group/Base.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/Group/Base.agda",
"max_line_length": 107,
"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/Group/Base.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2296,
"size": 5446
}
|
{-# OPTIONS --without-K #-}
module NTypes.Id where
open import GroupoidStructure
open import NTypes
open import PathOperations
open import Transport
open import Types
-- This should also be derivable from hLevel-suc from
-- HomotopyTypes.HLevel module.
Id-isSet : ∀ {a} {A : Set a} {x y : A} →
isSet A → isSet (x ≡ y)
Id-isSet {x = x} {y = y} A-set _ _ pp qq
= path pp ⁻¹ · path qq
where
split-path : {p q : x ≡ y} (pp : p ≡ q) →
A-set _ _ p q ≡ pp · A-set _ _ q q
split-path pp = J
(λ p q pp → A-set _ _ p q ≡ pp · A-set _ _ q q)
(λ _ → refl) _ _ pp
path : {p q : x ≡ y} (pp : p ≡ q) →
A-set _ _ p q ≡ pp
path pp = J
(λ p q pp → A-set _ _ p q ≡ pp)
(λ p → split-path (A-set _ _ p p ⁻¹) · p⁻¹·p (A-set _ _ p p))
_ _ pp
-- From the lectures.
Id-isSet-alt : ∀ {a} {A : Set a} {u v : A} →
isSet A → isSet (u ≡ v)
Id-isSet-alt {u = u} {v = v} H r s α β
= id·p α ⁻¹
· ap (λ z → z · α)
(p⁻¹·p (H′ r)) ⁻¹
· p·q·r (H′ r ⁻¹) (H′ r) α ⁻¹
· ap (λ z → H′ r ⁻¹ · z)
( tr-post r α (H′ r) ⁻¹
· apd H′ α
· apd H′ β ⁻¹
· tr-post r β (H′ r)
)
· p·q·r (H′ r ⁻¹) (H′ r) β
· ap (λ z → z · β)
(p⁻¹·p (H′ r))
· id·p β
where
H′ = λ q → H u v r q
|
{
"alphanum_fraction": 0.4917898194,
"avg_line_length": 24.36,
"ext": "agda",
"hexsha": "39dc0ce27cad3f60eb441c1dc187d82f27a55275",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "vituscze/HoTT-lectures",
"max_forks_repo_path": "src/NTypes/Id.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "vituscze/HoTT-lectures",
"max_issues_repo_path": "src/NTypes/Id.agda",
"max_line_length": 65,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7730385adfdbdda38ee8b124be3cdeebb7312c65",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "vituscze/HoTT-lectures",
"max_stars_repo_path": "src/NTypes/Id.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 561,
"size": 1218
}
|
{-# OPTIONS --cubical #-}
module Data.Binary.PerformanceTests.Conversion where
open import Prelude
open import Data.Binary.Definition
open import Data.Binary.Conversion using (⟦_⇓⟧)
-- open import Data.Binary.Conversion.Strict
open import Data.Binary.Conversion.Fast
-- one-thousand : 𝔹
-- one-thousand = 2ᵇ 1ᵇ 1ᵇ 2ᵇ 1ᵇ 2ᵇ 2ᵇ 2ᵇ 2ᵇ 0ᵇ
-- f : 𝔹
-- f = one-thousand
n : ℕ
n = 5000000
-- The actual performance test (uncomment and time how long it takes to type-check)
-- _ : ⟦ ⟦ n ⇑⟧ ⇓⟧ ≡ n
-- _ = refl
|
{
"alphanum_fraction": 0.6982248521,
"avg_line_length": 22.0434782609,
"ext": "agda",
"hexsha": "94409fb50cf6f657e3dc9e02bbddf85df6bb85bb",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Binary/PerformanceTests/Conversion.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Binary/PerformanceTests/Conversion.agda",
"max_line_length": 83,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Binary/PerformanceTests/Conversion.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": 196,
"size": 507
}
|
module ModuleArgs where
open import Common.Nat
open import Common.IO
open import Common.Unit
module X (y : Nat) where
addTo : Nat -> Nat
addTo x = y + x
open X 23
-- should return 35
main : IO Unit
main = printNat (addTo 12)
|
{
"alphanum_fraction": 0.6995708155,
"avg_line_length": 14.5625,
"ext": "agda",
"hexsha": "40d969a5cc92f76b6a197deafd7de7b2dc706187",
"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": "231d6ad8e77b67ff8c4b1cb35a6c31ccd988c3e9",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "Agda-zh/agda",
"max_forks_repo_path": "test/Compiler/simple/ModuleArgs.agda",
"max_issues_count": 16,
"max_issues_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_issues_repo_issues_event_max_datetime": "2019-09-08T13:47:04.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-10-08T00:32:04.000Z",
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "shlevy/agda",
"max_issues_repo_path": "test/Compiler/simple/ModuleArgs.agda",
"max_line_length": 26,
"max_stars_count": 7,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Compiler/simple/ModuleArgs.agda",
"max_stars_repo_stars_event_max_datetime": "2018-11-06T16:38:43.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-11-05T22:13:36.000Z",
"num_tokens": 70,
"size": 233
}
|
open import Nat
open import Prelude
open import Hazelnut-core
module Hazelnut-declarative where
-- declarative type checking judgement for ė
data _⊢_::_ : (Γ : ·ctx) → (e : ė) → (t : τ̇) → Set where
DVar : {Γ : ·ctx} {t : τ̇} {n : Nat} →
(n , t) ∈ Γ →
Γ ⊢ X n :: t
DAp : {Γ : ·ctx} {e1 e2 : ė} {t t2 : τ̇} →
Γ ⊢ e1 :: (t2 ==> t) →
Γ ⊢ e2 :: t2 →
Γ ⊢ (e1 ∘ e2) :: t
DNum : {Γ : ·ctx} {n : Nat} →
Γ ⊢ N n :: num
DPlus : {Γ : ·ctx} {e1 e2 : ė} →
Γ ⊢ e1 :: num →
Γ ⊢ e2 :: num →
Γ ⊢ (e1 ·+ e2) :: num
DEHole : {Γ : ·ctx} → Γ ⊢ <||> :: <||>
DFHole : {Γ : ·ctx} {e : ė} {t : τ̇} →
Γ ⊢ e :: t →
Γ ⊢ <| e |> :: <||>
DApHole : {Γ : ·ctx} {e1 e2 : ė} →
Γ ⊢ e1 :: <||> →
Γ ⊢ e2 :: <||> →
Γ ⊢ (e1 ∘ e2) :: <||>
DLam : {Γ : ·ctx} {e : ė} {t1 t2 : τ̇} {n : Nat} →
n # Γ →
(Γ ,, (n , t1)) ⊢ e :: t2 →
Γ ⊢ (·λ n e) :: (t1 ==> t2)
-- erasure of ascriptions, following the 312 notes.
data ||_|| : {e : ė} → ė → Set where
-- EraseAsc : {e : ė} {x : Nat} →
-- ||_|| : ė → ė
-- || e ·: x || = || e ||
-- || X x || = X x
-- || ·λ x e || = ·λ x || e ||
-- || N n || = N n
-- || e1 ·+ e2 || = || e1 || ·+ || e2 ||
-- || <||> || = <||>
-- || <| e |> || = <| || e || |>
-- || e1 ∘ e2 || = || e1 || ∘ || e2 ||
decbidir : {Γ : ·ctx} {e : ė} {t : τ̇}
→ Γ ⊢ e :: t
→ (Γ ⊢ e => t) + (Γ ⊢ e <= t)
-- synthesis cases
decbidir (DVar x) = Inl (SVar x)
decbidir (DAp d1 d2) with decbidir d1 | decbidir d2
... | Inl s1 | Inl s2 = Inl (SAp s1 (ASubsume s2 TCRefl))
... | Inl s1 | Inr a2 = Inl (SAp s1 a2)
... | Inr a1 | Inl s2 = Inl (SAp {!!} (ASubsume s2 TCRefl))
... | Inr a1 | Inr a2 = Inl (SAp {!!} a2)
decbidir DNum = Inl SNum
decbidir (DPlus d1 d2) with decbidir d1 | decbidir d2
... | Inl s1 | Inl s2 = Inl (SPlus (ASubsume s1 TCRefl) (ASubsume s2 TCRefl))
... | Inl s1 | Inr a2 = Inl (SPlus (ASubsume s1 TCRefl) a2)
... | Inr a1 | Inl s1 = Inl (SPlus a1 (ASubsume s1 TCRefl))
... | Inr a1 | Inr a2 = Inl (SPlus a1 a2)
decbidir DEHole = Inl SEHole
decbidir (DFHole d) with decbidir d
... | Inl synth = Inl (SFHole synth)
... | Inr (ASubsume d' _) = Inl (SFHole d')
... | Inr (ALam x ana) = Inl {!!}
decbidir (DApHole d1 d2) with decbidir d1 | decbidir d2
... | Inl s1 | Inl s2 = Inl (SApHole s1 (ASubsume s2 TCRefl))
... | Inl s1 | Inr a2 = Inl (SApHole s1 a2)
... | Inr a1 | Inl s2 = Inl (SApHole {!!} (ASubsume s2 TCRefl))
... | Inr a1 | Inr a2 = Inl (SApHole {!!} a2)
-- analysis case
decbidir (DLam x d) = Inr (ALam {!!} {!!})
bidirdec : {Γ : ·ctx} {e : ė} {t : τ̇}
→ (Γ ⊢ e => t) + (Γ ⊢ e <= t)
→ Γ ⊢ e :: t
-- synthesis cases
bidirdec (Inl (SAsc d)) = {!!}
bidirdec (Inl (SVar x)) = DVar x
bidirdec (Inl (SAp d1 d2)) = DAp (bidirdec (Inl d1)) (bidirdec (Inr d2))
bidirdec (Inl SNum) = DNum
bidirdec (Inl (SPlus d1 d2)) = DPlus (bidirdec (Inr d1)) (bidirdec (Inr d2))
bidirdec (Inl SEHole) = DEHole
bidirdec (Inl (SFHole d)) = DFHole (bidirdec (Inl d))
bidirdec (Inl (SApHole d1 d2)) = DApHole (bidirdec (Inl d1)) (bidirdec (Inr d2))
--analysis cases
bidirdec (Inr (ASubsume x x₁)) = {!synthunicity!}
bidirdec (Inr (ALam x d)) = DLam x (bidirdec (Inr d))
-- to be an isomoprhism you have to preserve structure.
-- to : {Γ : ·ctx} {e : ė} {t : τ̇} →
-- (d : Γ ⊢ e :: t) →
-- (bidirdec (decbidir d)) == d
-- to d = {!!}
-- from : {Γ : ·ctx} {e : ė} {t : τ̇} →
-- (dd : (Γ ⊢ e => t) + (Γ ⊢ e <= t)) →
-- (decbidir (bidirdec dd)) == dd
-- from dd = {!!}
|
{
"alphanum_fraction": 0.4224747475,
"avg_line_length": 38.4466019417,
"ext": "agda",
"hexsha": "a76797dda0670a8ecc58ec8685f040a7e1d8ccb8",
"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": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "ivoysey/agda-tfp16",
"max_forks_repo_path": "Hazelnut-declarative.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"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": "ivoysey/agda-tfp16",
"max_issues_repo_path": "Hazelnut-declarative.agda",
"max_line_length": 82,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "86a755ca6749e080f9a03287e34d1cda889f1edb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "ivoysey/agda-tfp16",
"max_stars_repo_path": "Hazelnut-declarative.agda",
"max_stars_repo_stars_event_max_datetime": "2016-04-14T02:19:58.000Z",
"max_stars_repo_stars_event_min_datetime": "2016-04-09T13:35:22.000Z",
"num_tokens": 1787,
"size": 3960
}
|
{-# OPTIONS --cubical --safe #-}
module Data.Integer.Literals where
open import Data.Integer
open import Literals.Number
open import Data.Unit
instance
numberNat : Number ℤ
numberNat = record
{ Constraint = λ _ → ⊤
; fromNat = λ n → ⁺ n
}
|
{
"alphanum_fraction": 0.6590038314,
"avg_line_length": 17.4,
"ext": "agda",
"hexsha": "8bff814f1eb6fd1dbcfbd48503d2c53bb0fcf39a",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-11T12:30:21.000Z",
"max_forks_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "oisdk/agda-playground",
"max_forks_repo_path": "Data/Integer/Literals.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "oisdk/agda-playground",
"max_issues_repo_path": "Data/Integer/Literals.agda",
"max_line_length": 34,
"max_stars_count": 6,
"max_stars_repo_head_hexsha": "97a3aab1282b2337c5f43e2cfa3fa969a94c11b7",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "oisdk/agda-playground",
"max_stars_repo_path": "Data/Integer/Literals.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": 73,
"size": 261
}
|
module plfa-exercises.Practice where
--------------------------------------- Naturals ---------------------------------------
-- Inductive definition of Numbers (new datatype)
data ℕ : Set where
-- Judgements (two in total for this case)
zero : ℕ -- No hypothesis and one conclusion
suc : ℕ → ℕ -- One hypothesis and one conclusion
seven : ℕ
seven = suc (suc (suc (suc (suc (suc (suc zero))))))
--seven′ = --7
pred : ℕ → ℕ
pred zero = zero
pred (suc n) = n
---
-- Gives us the power of writing 3 to signify suc (suc (suc zero)) :)
{-# BUILTIN NATURAL ℕ #-}
import Relation.Binary.PropositionalEquality as Eq
open Eq using (_≡_; _≢_; refl; cong; sym; trans)
open Eq.≡-Reasoning using (begin_; _≡⟨⟩_; _≡⟨_⟩_; _∎)
open import Function.Base using (flip)
open import Relation.Nullary using (¬_)
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Product using (_×_; ∃-syntax) renaming (_,_ to ⟨_,_⟩)
open import Data.Sum using (_⊎_; inj₁; inj₂)
_+_ : ℕ → ℕ → ℕ
zero + n = n -- +-def₀
(suc m) + n = suc (m + n) -- +-def₁
--_ : (suc (suc zero)) + (suc (suc (suc zero))) ≡ (suc (suc (suc (suc (suc zero)))))
--_ =
-- begin
-- (suc (suc zero)) + (suc (suc (suc zero)))
-- ≡⟨⟩ -- inductive case
-- suc ((suc zero) + (suc (suc (suc zero))))
-- ≡⟨⟩ -- inductive case
-- suc (suc (zero + (suc (suc (suc zero)))))
-- ≡⟨⟩ -- base case
-- suc (suc (suc (suc (suc zero))))
-- ∎
--
--_ : 2 + 3 ≡ 5
--_ =
-- begin
-- 2 + 3
-- (suc 1) + 3
-- ≡⟨⟩
-- suc (1 + 3)
-- ≡⟨⟩
-- suc (suc 0 + 3)
-- ≡⟨⟩
-- suc (suc (0 + 3))
-- ≡⟨⟩
-- suc (suc 3)
-- ≡⟨⟩
-- suc 4
-- ≡⟨⟩
-- 5
-- ∎
--
--
--_ : (suc (suc zero)) + (suc (suc (suc zero))) ≡ (suc (suc (suc (suc (suc zero)))))
--_ = refl
_*_ : ℕ → ℕ → ℕ
zero * n = zero
(suc m) * n = n + (m * n)
_^_ : ℕ → ℕ → ℕ
n ^ zero = suc zero
n ^ (suc m) = n * (n ^ m)
-- Monus
_∸_ : ℕ → ℕ → ℕ
m ∸ zero = m
zero ∸ suc n = zero
suc m ∸ suc n = m ∸ n
infixl 6 _+_ _∸_
infixl 7 _*_
infixr 8 _^_
-- Superfun binary numbers :D
data Bin : Set where
⟨⟩ : Bin
_O : Bin → Bin
_I : Bin → Bin
inc : Bin → Bin
inc ⟨⟩ = ⟨⟩ I
inc (b O) = b I
inc (b I) = (inc b) O
_ : inc (⟨⟩ I O I I) ≡ ⟨⟩ I I O O
_ = refl
toᵇ : ℕ → Bin
toᵇ zero = ⟨⟩ O
toᵇ (suc n) = inc (toᵇ n)
fromᵇ : Bin → ℕ
fromᵇ ⟨⟩ = zero
fromᵇ (b O) = let n = fromᵇ b in n + n
fromᵇ (b I) = let n = fromᵇ b in suc (n + n)
_ : toᵇ 11 ≡ (⟨⟩ I O I I)
_ = refl
_ : fromᵇ (inc (⟨⟩ I O I I)) ≡ 12
_ = refl
--_ = begin
-- (fromᵇ (⟨⟩ I I O O))
-- ≡⟨ 12 ≡⟨⟩ 12 ∎ ⟩
-- 12
-- ∎
--_ : Set₉₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁₁
--_ : Set₀
_ : Set
_ = suc 11 ≡ 12
_+ᵇ_ : Bin → Bin → Bin
⟨⟩ +ᵇ b = b
b +ᵇ ⟨⟩ = b
--(b O) +ᵇ ⟨⟩ = b O
(b O) +ᵇ (d O) = (b +ᵇ d) O
(b O) +ᵇ (d I) = (b +ᵇ d) I
--(b I) +ᵇ ⟨⟩ = b I
(b I) +ᵇ (d O) = (b +ᵇ d) I
(b I) +ᵇ (d I) = (inc (b +ᵇ d)) O
-- Proving the following is trivial
mod-left : ∀ {b : Bin} → ⟨⟩ +ᵇ b ≡ b
mod-left = refl
-- But not its complement. This is due to "case trees" (or how Agda implements
-- functions under the hood)
-- https://agda.readthedocs.io/en/v2.6.0.1/language/function-definitions.html#case-trees
mod-right : ∀ {b : Bin} → b +ᵇ ⟨⟩ ≡ b
mod-right {⟨⟩} = refl
mod-right {b O} = refl
mod-right {b I} = refl
-- Also, I'm confused on the implications of improper "case trees". If the
-- second rule wasn't reachable, the following code would run even
-- if the rule was nonesense (eg, changing `b +ᵇ ⟨⟩ = b O O`) but it doesn't
-- work! The rule must make sense. So, Agda is applying the rule after all and
-- not ignoring it even thought it can't be reached directly in proofs
_ : (⟨⟩ I O I I I) +ᵇ (⟨⟩ O O I) ≡ ⟨⟩ I I O O O
_ = refl
---proppre : ∀ (n : ℕ) → zero + suc n ≡ suc (zero + n)
---proppre zero = refl
---proppre (suc n) =
--- begin
--- zero + suc (suc n)
--- ≡⟨⟩
--- zero + suc (zero + suc n)
--- ≡⟨⟩
--- suc (zero + suc n)
--- ∎
--≡⟨ cong suc (proppre n) ⟩
-- Taken it from book
assoc-+ : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p)
assoc-+ zero n p = refl
assoc-+ (suc m) n p rewrite assoc-+ m n p = refl
comm-+₀ : ∀ (m : ℕ) → m + zero ≡ m
comm-+₀ zero = refl
comm-+₀ (suc n) rewrite comm-+₀ n = refl
--comm-+₀ (suc n) =
-- begin
-- zero + suc n
-- ≡⟨⟩
-- zero + suc (zero + n)
-- ≡⟨⟩
-- suc (zero + n)
-- ≡⟨ cong suc (comm-+₀ n) ⟩
-- suc (n + zero)
-- ≡⟨⟩
-- suc n + zero
-- ∎
succ_right : ∀ (n m : ℕ) → suc (n + m) ≡ n + suc m
succ_right zero m = refl
succ_right (suc n) m rewrite succ_right n m = refl
--succ_right (suc n) m = cong suc (succ_right n m)
--succ_right (suc n) m =
-- begin
-- suc (suc n + m)
-- ≡⟨⟩
-- suc (suc (n + m))
-- ≡⟨ cong suc (succ_right n m) ⟩
-- suc (n + suc m)
-- ≡⟨⟩
-- suc n + suc m
-- ∎
comm-+ : ∀ (n m : ℕ) → n + m ≡ m + n
comm-+ zero n = sym (comm-+₀ n)
comm-+ (suc n) m rewrite comm-+ n m | succ_right m n = refl
--comm-+ (suc n) m = trans (cong suc (comm-+ n m)) (succ_right m n)
--comm-+ (suc n) m =
-- begin
-- suc n + m
-- ≡⟨⟩ -- +-def₁
-- suc (n + m)
-- ≡⟨ cong suc (comm-+ n m) ⟩
-- suc (m + n)
-- ≡⟨ succ_right m n ⟩
-- m + suc n
-- ∎
-- Try evaluating and type-checking the following expressions:
-- comm-+ zero
-- (flip comm-+) zero
-- λ n m → cong suc (comm-+ n m)
-- λ m n → succ_right m n
-- λ m n → sym (succ_right m n)
-- λ n m → trans (cong suc (comm-+ n m)) (succ_right m n)
monus : ∀ (n : ℕ) → zero ∸ n ≡ zero
monus zero = refl
monus (suc n) = refl
--monus : ∀ {n : ℕ} → zero ∸ n ≡ zero
--monus {zero} = refl
--monus {suc n} = refl
inc≡suc : ∀ (b : Bin) → fromᵇ (inc b) ≡ suc (fromᵇ b)
inc≡suc ⟨⟩ = refl
inc≡suc (b O) rewrite sym (comm-+₀ (fromᵇ b)) = refl
inc≡suc (b I)
rewrite
comm-+₀ (fromᵇ (inc b))
| inc≡suc b
| succ_right (fromᵇ b) (fromᵇ b)
| comm-+₀ (fromᵇ b)
| succ_right (fromᵇ b) (fromᵇ b) = refl
-- `toᵇ (fromᵇ b) ≡ b` doesn't hold for all values, just for some.
-- So the following is false
--tofromb≢b : ∀ (b : Bin) → ¬ (toᵇ (fromᵇ b) ≡ b)
--tofromb≢b ⟨⟩ = λ()
--tofromb≢b = ? -- impossible to prove
_ : ¬ (toᵇ (fromᵇ ⟨⟩) ≡ ⟨⟩)
_ = λ()
--from∘toᵇ₀ : ∀ (n : ℕ) → fromᵇ ((toᵇ n) O) ≡ fromᵇ (toᵇ n) + fromᵇ (toᵇ n)
--from∘toᵇ₀ zero = refl
--from∘toᵇ₀ (suc n) = refl
--
--from∘toᵇ₁ : ∀ (n : ℕ) → fromᵇ ((toᵇ n) I) ≡ suc (fromᵇ (toᵇ n) + fromᵇ (toᵇ n))
--from∘toᵇ₁ zero = refl
--from∘toᵇ₁ (suc n) = refl
monobin₀ : ∀ (b : Bin) → inc (inc (b +ᵇ b)) ≡ (inc b +ᵇ inc b)
monobin₀ ⟨⟩ = refl
monobin₀ (b O) = refl
monobin₀ (b I) rewrite monobin₀ b = refl
monobin : ∀ (n : ℕ) → toᵇ (n + n) ≡ (toᵇ n) +ᵇ (toᵇ n)
monobin zero = refl
monobin (suc n) rewrite
sym (succ_right n n)
| monobin n
| monobin₀ (toᵇ n) = refl
--mononat₀ : ∀ (a : Bin) → a +ᵇ ⟨⟩ ≡ a
--mononat₀ ⟨⟩ = refl
--mononat₀ (b O) = refl
--mononat₀ (b I) = refl
--
--mononat₁ : ∀ (a b : Bin) → fromᵇ (inc (a +ᵇ b)) ≡ suc (fromᵇ a + fromᵇ b)
--mononat₁ ⟨⟩ b rewrite inc≡suc b = refl
--mononat₁ a ⟨⟩ rewrite mononat₀ a | comm-+₀ (fromᵇ a) | inc≡suc a = refl
--mononat₁ = ?
---- λ a → fromᵇ (inc (a +ᵇ ⟨⟩)) ≡ suc (fromᵇ a + fromᵇ ⟨⟩)
---- fromᵇ (inc b) ≡ suc (fromᵇ b)
--
--mononat : ∀ (a b : Bin) → fromᵇ (a +ᵇ b) ≡ fromᵇ a + fromᵇ b
--mononat ⟨⟩ _ = refl
--mononat a ⟨⟩ rewrite mononat₀ a | comm-+₀ (fromᵇ a) = refl
----mononat a ⟨⟩ =
---- begin
---- fromᵇ (a +ᵇ ⟨⟩)
---- ≡⟨ cong fromᵇ (mononat₀ a) ⟩
---- fromᵇ (a)
---- ≡⟨ sym (comm-+₀ (fromᵇ a)) ⟩
---- fromᵇ a + zero
---- ≡⟨⟩
---- fromᵇ a + fromᵇ ⟨⟩
---- ∎
--mononat (a O) (b O) rewrite
-- mononat a b
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | comm-+ (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ a) (fromᵇ b + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ b)
-- = refl
--mononat (a I) (b O) rewrite
-- mononat a b
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | comm-+ (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ a) (fromᵇ b + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ b)
-- = refl
--mononat (a O) (b I) rewrite
-- mononat a b
-- | sym (succ_right (fromᵇ a + fromᵇ a) (fromᵇ b + fromᵇ b))
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | comm-+ (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ a) (fromᵇ b + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ b)
-- = refl
--mononat (a I) (b I) rewrite
-- mononat₁ a b
-- | sym (succ_right (fromᵇ a + fromᵇ a) (fromᵇ b + fromᵇ b))
-- | sym (succ_right (fromᵇ a + fromᵇ b) (fromᵇ a + fromᵇ b))
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | comm-+ (fromᵇ b) (fromᵇ a + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ a) (fromᵇ b + fromᵇ b)
-- | assoc-+ (fromᵇ a) (fromᵇ b) (fromᵇ b)
-- = refl
-- Really hard!! Keep working on it!
-- IT WASN'T HARD!!! I JUST COULDN'T SEE THE RIGHT REWRITE!!
from∘toᵇ : ∀ (n : ℕ) → fromᵇ (toᵇ n) ≡ n
from∘toᵇ zero = refl
from∘toᵇ (suc n) rewrite inc≡suc (toᵇ n) | from∘toᵇ n = refl
--from∘toᵇ (suc n) =
-- begin
-- fromᵇ (toᵇ (suc n))
-- ≡⟨⟩
-- fromᵇ (inc (toᵇ n))
-- ≡⟨ inc≡suc (toᵇ n) ⟩
-- suc (fromᵇ (toᵇ n))
-- ≡⟨ cong suc (from∘toᵇ n) ⟩
-- suc n
-- ∎
swap-m-n-+ : ∀ (m n p) → m + (n + p) ≡ n + (m + p)
swap-m-n-+ m n p rewrite
sym (assoc-+ m n p)
| sym (assoc-+ n m p)
| comm-+ m n
= refl
right-zero-* : ∀ (n : ℕ) → n * 0 ≡ 0
right-zero-* zero = refl
right-zero-* (suc n) rewrite right-zero-* n = refl
suc-right-* : ∀ (m n) → m * suc n ≡ m + m * n
suc-right-* zero n = refl
suc-right-* (suc m) n
rewrite
suc-right-* m n
| sym (assoc-+ n m (m * n))
| comm-+ n m
| assoc-+ m n (m * n)
= refl
comm-* : ∀ (m n : ℕ) → m * n ≡ n * m
comm-* zero n rewrite right-zero-* n = refl
comm-* (suc m) n
rewrite
comm-* m n
| suc-right-* n m
= refl
distr-*-+ : ∀ (m n p) → (m + n) * p ≡ m * p + n * p
distr-*-+ zero _ _ = refl
distr-*-+ (suc m) n p rewrite distr-*-+ m n p | assoc-+ p (m * p) (n * p) = refl
distl-*-+ : ∀ (p m n) → p * (m + n) ≡ p * m + p * n
distl-*-+ zero _ _ = refl
distl-*-+ (suc p) m n
rewrite
distl-*-+ p m n
| sym (assoc-+ (m + n) (p * m) (p * n))
| sym (assoc-+ (m + p * m) n (p * n))
| assoc-+ m n (p * m)
| comm-+ n (p * m)
| assoc-+ m (p * m) n
= refl
assoc-* : ∀ (m n p : ℕ) → (m * n) * p ≡ m * (n * p)
assoc-* zero n p = refl
assoc-* (suc m) n p
rewrite
assoc-* m n p
| distr-*-+ n (m * n) p
| assoc-* m n p
= refl
swap-m-n-* : ∀ (m n p) → m * (n * p) ≡ n * (m * p)
swap-m-n-* m n p rewrite
sym (assoc-* m n p)
| sym (assoc-* n m p)
| comm-* m n
= refl
distr-^-* : ∀ (m n p) → (m * n) ^ p ≡ (m ^ p) * (n ^ p)
--distr-^-* m n zero =
-- begin
-- (m * n) ^ zero
-- ≡⟨⟩
-- (m * n) ^ 0
-- ≡⟨⟩
-- suc 0
-- ≡⟨⟩
-- 1
-- ≡⟨⟩
-- 1 + 0
-- ≡⟨⟩
-- 1 + 0 * 1
-- ≡⟨⟩
-- (suc 0) * 1
-- ≡⟨⟩
-- (suc 0) * 1
-- ≡⟨⟩
-- 1 * 1
-- ≡⟨⟩
-- 1 * (n ^ 0)
-- ≡⟨⟩
-- (m ^ zero) * (n ^ zero)
-- ≡⟨⟩
-- (m ^ 0) * (n ^ 0)
-- ∎
distr-^-* _ _ zero = refl
distr-^-* zero zero (suc p) = refl
distr-^-* zero (suc n) (suc p) = refl
distr-^-* (suc m) zero (suc p)
rewrite
right-zero-* (suc m ^ suc p)
| right-zero-* m
= refl
distr-^-* (suc m) (suc n) (suc p)
rewrite
-- (suc m * suc n) ^ suc p ≡ suc m ^ suc p * suc n ^ suc p
--
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡ (suc m ^ p + m * suc m ^ p) * (suc n ^ p + n * suc n ^ p)
distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * suc m ^ p * (suc n ^ p + n * suc n ^ p)
| assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * (suc n ^ p + n * suc n ^ p)
-- + m * (suc m ^ p * (suc n ^ p + n * suc n ^ p))
| distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- suc (n + m * suc n) ^ p + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* m (suc n)
-- suc (n + (m + n * m)) ^ p
-- + (n + (m + n * m)) * suc (n + (m + n * m)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| comm-* n m
-- suc (n + (m + m * n)) ^ p
-- + (n + (m + m * n)) * suc (n + (m + m * n)) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| sym (suc-right-* m n)
-- suc (n + m * suc n) ^ p
-- + (n + m * suc n) * suc (n + m * suc n) ^ p
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-^-* (suc m) (suc n) p
-- suc m ^ p * suc n ^ p + (n + m * suc n) * (suc m ^ p * suc n ^ p)
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + m * (suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p))
| distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + m * suc n * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| comm-* m (suc n)
-- suc m ^ p * suc n ^ p + (n * (suc m ^ p * suc n ^ p)
-- + (m + n * m) * (suc m ^ p * suc n ^ p))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p)
-- + (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + suc m ^ p * (n * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (suc m ^ p * (n * suc n ^ p)))
| swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * (n * (suc m ^ p * suc n ^ p)))
| sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + m * n * (suc m ^ p * suc n ^ p))
| comm-* m n
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p + n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
| assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
(m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- ≡
-- suc m ^ p * suc n ^ p +
-- (n * (suc m ^ p * suc n ^ p) +
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p)))
-- QED
= refl
--distr-^-* (suc m) (suc n) (suc p)
-- rewrite
-- distr-*-+ (suc m ^ p) (m * suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | assoc-* m (suc m ^ p) (suc n ^ p + n * suc n ^ p)
-- | distl-*-+ (suc m ^ p) (suc n ^ p) (n * suc n ^ p)
-- | comm-* m (suc n)
-- | comm-* n m
-- | sym (suc-right-* m n)
-- | distr-^-* (suc m) (suc n) p
-- | distr-*-+ n (m * suc n) (suc m ^ p * suc n ^ p)
-- | distl-*-+ m (suc m ^ p * suc n ^ p) (suc m ^ p * (n * suc n ^ p))
-- | comm-* m (suc n)
-- | distr-*-+ m (n * m) (suc m ^ p * suc n ^ p)
-- | swap-m-n-* n (suc m ^ p) (suc n ^ p)
-- | swap-m-n-* (suc m ^ p) n (suc n ^ p)
-- | sym (assoc-* m n (suc m ^ p * suc n ^ p))
-- | comm-* m n
-- | assoc-+ (suc m ^ p * suc n ^ p) (n * (suc m ^ p * suc n ^ p))
-- (m * (suc m ^ p * suc n ^ p) + n * m * (suc m ^ p * suc n ^ p))
-- = refl
--------------------------------------- Relations ---------------------------------------
data _≤_ : ℕ → ℕ → Set where
z≤n : ∀ {n : ℕ} → zero ≤ n
s≤s : ∀ {m n : ℕ} → m ≤ n → suc m ≤ suc n
_ : 2 ≤ 4
_ = s≤s (s≤s z≤n)
--_ = s≤s {1} {3} (s≤s {0} {2} (z≤n {2}))
inv-s≤s : ∀ {m n : ℕ} → suc m ≤ suc n → m ≤ n
inv-s≤s (s≤s m≤n) = m≤n
inv-z≤n : ∀ {m : ℕ} → m ≤ zero → m ≡ zero
inv-z≤n z≤n = refl
refl-≤ : ∀ {n : ℕ} → n ≤ n
refl-≤ {zero} = z≤n
refl-≤ {suc o} = s≤s refl-≤
trans-≤ : ∀ {m n p : ℕ} → m ≤ n → n ≤ p → m ≤ p
trans-≤ z≤n _ = z≤n
trans-≤ (s≤s m≤n) (s≤s n≤p) = s≤s (trans-≤ m≤n n≤p)
antisym-≤ : ∀ {m n : ℕ} → m ≤ n → n ≤ m → m ≡ n
antisym-≤ z≤n n≤m = sym (inv-z≤n n≤m)
antisym-≤ (s≤s m≤n) (s≤s n≤m) = cong suc (antisym-≤ m≤n n≤m)
open import Data.Sum using (_⊎_; inj₁; inj₂) renaming ([_,_] to case-⊎)
--data Total (m n : ℕ) : Set where
-- forward : m ≤ n → Total m n
-- flipped : n ≤ m → Total m n
--
--total-≤ : ∀ (m n : ℕ) → Total m n
--total-≤ zero _ = forward z≤n
--total-≤ (suc m) zero = flipped z≤n
--total-≤ (suc m) (suc n) with total-≤ m n
--... | forward m≤n = forward (s≤s m≤n)
--... | flipped n≤m = flipped (s≤s n≤m)
total-≤` : ∀ (m n : ℕ) → m ≤ n ⊎ n ≤ m
total-≤` zero _ = inj₁ z≤n
total-≤` _ zero = inj₂ z≤n
total-≤` (suc m) (suc n) with total-≤` m n
... | inj₁ m≤n = inj₁ (s≤s m≤n)
... | inj₂ n≤m = inj₂ (s≤s n≤m)
--+-monoʳ-≤ : ∀ (n p q : ℕ) → p ≤ q → (n + p) ≤ (n + q)
--+-monoʳ-≤ zero _ _ p≤q = p≤q
--+-monoʳ-≤ (suc n) p q p≤q = s≤s (+-monoʳ-≤ n p q p≤q)
+-monoʳ-≤ : ∀ {n p q : ℕ} → p ≤ q → (n + p) ≤ (n + q)
+-monoʳ-≤ {zero} p≤q = p≤q
+-monoʳ-≤ {suc n} p≤q = s≤s (+-monoʳ-≤ {n} p≤q)
+-monoˡ-≤ : ∀ {m n p : ℕ} → m ≤ n → (m + p) ≤ (n + p)
+-monoˡ-≤ {m} {n} {p} m≤n rewrite comm-+ m p | comm-+ n p = +-monoʳ-≤ m≤n
-- From book
≤-trans : ∀ {m n p : ℕ} → m ≤ n → n ≤ p → m ≤ p
≤-trans z≤n _ = z≤n
≤-trans (s≤s m≤n) (s≤s n≤p) = s≤s (≤-trans m≤n n≤p)
+-mono-≤ : ∀ {m n p q : ℕ} → m ≤ n → p ≤ q → (m + p) ≤ (n + q)
+-mono-≤ m≤n p≤q = ≤-trans (+-monoˡ-≤ m≤n) (+-monoʳ-≤ p≤q)
-- Exercises
*-monoʳ-≤ : ∀ {n p q : ℕ} → p ≤ q → (n * p) ≤ (n * q)
*-monoʳ-≤ {zero} p≤q = z≤n
*-monoʳ-≤ {suc n} p≤q = +-mono-≤ p≤q (*-monoʳ-≤ {n} p≤q)
*-monoˡ-≤ : ∀ {m n p : ℕ} → m ≤ n → (m * p) ≤ (n * p)
*-monoˡ-≤ {m} {n} {p} m≤n rewrite comm-* m p | comm-* n p = *-monoʳ-≤ {p} {m} {n} m≤n
*-mono-≤ : ∀ {m n p q : ℕ} → m ≤ n → p ≤ q → (m * p) ≤ (n * q)
*-mono-≤ {_} {n} m≤n p≤q = ≤-trans (*-monoˡ-≤ m≤n) (*-monoʳ-≤ {n} p≤q)
infix 4 _<_
data _<_ : ℕ → ℕ → Set where
z<s : ∀ {n : ℕ} → zero < suc n
s<s : ∀ {m n : ℕ} → m < n → suc m < suc n
<-trans : ∀ {m n p} → m < n → n < p → m < p
--<-trans {m} {suc n} {suc p} z<s (s<s n<p) = z<s {p}
--<-trans {suc m} {suc n} {suc p} (s<s m<n) (s<s n<p) = s<s (<-trans m<n n<p)
<-trans z<s (s<s n<p) = z<s
<-trans (s<s m<n) (s<s n<p) = s<s (<-trans m<n n<p)
trichotomy : ∀ (m n) → (m ≡ n) ⊎ (m < n) ⊎ (n < m)
trichotomy zero zero = inj₁ refl
trichotomy zero (suc n) = inj₂ (inj₁ z<s)
trichotomy (suc m) zero = inj₂ (inj₂ z<s)
trichotomy (suc m) (suc n) with trichotomy m n
... | inj₁ m≡n = inj₁ (cong suc m≡n)
... | inj₂ (inj₁ m<n) = inj₂ (inj₁ (s<s m<n))
... | inj₂ (inj₂ n<m) = inj₂ (inj₂ (s<s n<m))
+-monoʳ-< : ∀ {n p q} → p < q → (n + p) < (n + q)
+-monoʳ-< {zero} p<q = p<q
+-monoʳ-< {suc n} p<q = s<s (+-monoʳ-< p<q)
+-monoˡ-< : ∀ {m n p} → m < n → (m + p) < (n + p)
+-monoˡ-< {m} {n} {p} m<n rewrite comm-+ m p | comm-+ n p = +-monoʳ-< m<n
+-mono-< : ∀ {m n p q} → m < n → p < q → (m + p) < (n + q)
+-mono-< m<n p<q = <-trans (+-monoˡ-< m<n) (+-monoʳ-< p<q)
-- From Software Verification Class (nice exercises but the two first are
-- unnecessary in Agda because the proofs are basically the relation
-- definition)
≡0 : ∀ {n : ℕ} → ¬( 0 < n ) → n ≡ 0
≡0 {zero} _ = refl
≡0 {suc n} ¬0<n = ⊥-elim (¬0<n z<s)
--0< : ∀ {n : ℕ} → n ≢ 0 → 0 < n
0< : ∀ {n : ℕ} → ¬( n ≡ 0 ) → 0 < n
0< {zero} 0≢0 = ⊥-elim (0≢0 refl)
0< {suc n} s≢0 = z<s
¬n<z : ∀ {n : ℕ} → ¬( n < 0 )
¬n<z ()
m<sn→m<n⊎m≡n : {m n : ℕ} → (m < suc n) → (m < n) ⊎ (m ≡ n)
m<sn→m<n⊎m≡n {zero} {zero} _ = inj₂ refl
m<sn→m<n⊎m≡n {zero} {suc n} _ = inj₁ z<s
m<sn→m<n⊎m≡n {suc m} {zero} (s<s ())
m<sn→m<n⊎m≡n {suc m} {suc n} (s<s m<sn) with m<sn→m<n⊎m≡n {m} {n} m<sn
... | inj₁ m<n = inj₁ (s<s m<n)
... | inj₂ m≡n = inj₂ (cong suc m≡n)
suc-step : {m n : ℕ} → (m < suc n) × (m ≢ n) → m < n
suc-step {zero} {zero} ⟨ 0<1 , 0≢0 ⟩ = 0< 0≢0
suc-step {zero} {suc n} ⟨ 0<ssn , 0≢sn ⟩ = z<s
suc-step {suc m} {zero} ⟨ s<s m<0 , sm≢0 ⟩ = ⊥-elim (¬n<z m<0)
suc-step {suc m} {suc n} ⟨ s<s m<sn , sm≢sn ⟩ with m<sn→m<n⊎m≡n m<sn
... | inj₁ m<n = s<s m<n
... | inj₂ m≡n = ⊥-elim (sm≢sn (cong suc m≡n))
-- This idea of using returning ∃ in Athena might be fundamental but it is
-- clumsy or cumbersome in Agda
discrete : ∀ {n : ℕ} → ¬ (∃[ m ] (n < m × m < suc n))
discrete {zero} ⟨ _ , ⟨ z<s , s<s () ⟩ ⟩
discrete {suc n} ⟨ zero , ⟨ () , _ ⟩ ⟩
discrete {suc n} ⟨ suc m , ⟨ s<s n<m , s<s m<sn ⟩ ⟩ = discrete ⟨ m , ⟨ n<m , m<sn ⟩ ⟩
-- This is unnecessary because it is the same as pred n
-- proj₁ (S4 {_} {n} _) ≡ pred n
--S4 : ∀ {m n : ℕ} → suc m < n → ∃[ n' ] ( n ≡ suc n' )
S4 : ∀ {m n : ℕ} → m < n → ∃[ n' ] ( n ≡ suc n' )
S4 {_} {zero} ()
S4 {_} {suc n} _ = ⟨ n , refl ⟩
-- more interesting is:
S4' : ∀ {m n : ℕ} → suc m ≤ n → ∃[ n' ] ( n ≡ suc n' )
S4' {_} {zero} ()
S4' {_} {suc n} _ = ⟨ n , refl ⟩
-- It is more interesting because, this is not true:
-- S4' : ∀ {m n : ℕ} → m ≤ n → ∃[ n' ] ( n ≡ suc n' )
-- as opposed to S4.
-- But still, it's something that isn't necessary in Agda
irreflexive : ∀ {m : ℕ} → ¬(m < m)
irreflexive {zero} ()
irreflexive {suc m} (s<s m<m) = irreflexive m<m
trichotomy₂ : ∀ (m n) → (m ≡ n × ¬(m < n) × ¬(n < m))
⊎ (m < n × m ≢ n × ¬(n < m))
⊎ (n < m × m ≢ n × ¬(m < n))
trichotomy₂ zero zero = inj₁ ⟨ refl , ⟨ irreflexive , irreflexive ⟩ ⟩
trichotomy₂ zero (suc n) = inj₂ (inj₁ ⟨ z<s , ⟨ (λ()) , (λ()) ⟩ ⟩)
trichotomy₂ (suc m) zero = inj₂ (inj₂ ⟨ z<s , ⟨ (λ()) , (λ()) ⟩ ⟩)
trichotomy₂ (suc m) (suc n) with trichotomy₂ m n
... | inj₁ ⟨ m≡n , ⟨ ¬m<n , ¬n<m ⟩ ⟩ =
inj₁ ⟨ cong suc m≡n , ⟨ (λ{(s<s m<n) → ¬m<n m<n}) , (λ{(s<s n<m) → ¬n<m n<m}) ⟩ ⟩
... | inj₂ (inj₁ ⟨ m<n , ⟨ m≢n , ¬n<m ⟩ ⟩) =
inj₂ (inj₁ ⟨ s<s m<n , ⟨ (λ{sm≡sn → m≢n (cong pred sm≡sn)}) , (λ{(s<s n<m) → ¬n<m n<m}) ⟩ ⟩)
... | inj₂ (inj₂ ⟨ n<m , ⟨ m≢n , ¬m<n ⟩ ⟩) =
inj₂ (inj₂ ⟨ s<s n<m , ⟨ (λ{sm≡sn → m≢n (cong pred sm≡sn)}) , (λ{(s<s m<n) → ¬m<n m<n}) ⟩ ⟩)
--open import Function.Equivalence using (_⇔_)
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
open _⇔_
<-if-≤ : ∀ {m n} → suc m ≤ n → m < n
<-if-≤ {zero} {suc n} z≤s = z<s
<-if-≤ {suc m} {suc n} (s≤s sm≤n) = s<s (<-if-≤ sm≤n)
≤-if-< : ∀ {m n} → m < n → suc m ≤ n
≤-if-< {zero} {suc n} z<s = s≤s z≤n
≤-if-< {suc m} {suc n} (s<s m<n) = s≤s (≤-if-< m<n)
≤-iff-< : ∀ {m n} → (suc m ≤ n) ⇔ (m < n)
≤-iff-< = record
{ to = <-if-≤
; from = ≤-if-<
}
pred-smaller : ∀ {m n} → suc m ≤ n → m ≤ n
pred-smaller {zero} _ = z≤n
pred-smaller {suc m} {suc n} (s≤s sm≤n) = s≤s (pred-smaller sm≤n)
<-trans-revisited : ∀ {m n p} → m < n → n < p → m < p
<-trans-revisited {m} {n} {p} m<n n<p
= <-if-≤ (≤-trans (≤-if-< m<n) (pred-smaller (≤-if-< n<p)))
---
data even : ℕ → Set
data odd : ℕ → Set
data even where
zero-e : even zero
suc-e : ∀ {n : ℕ} → odd n → even (suc n)
data odd where
suc-o : ∀ {n : ℕ} → even n → odd (suc n)
---
data Can : Bin → Set
data One : Bin → Set
data Can where
zero-C : Can (⟨⟩ O)
one-C : ∀ {b : Bin} → One b → Can b
data One where
oneO : One (⟨⟩ I)
oneO-O : ∀ {b : Bin} → One b → One (b O)
oneO-I : ∀ {b : Bin} → One b → One (b I)
_ : Can (⟨⟩ I)
_ = one-C oneO
inc-Bin : ∀ {b : Bin} → One b → One (inc b)
inc-Bin oneO = oneO-O oneO
inc-Bin (oneO-O ob) = oneO-I ob
inc-Bin (oneO-I ob) = oneO-O (inc-Bin ob)
inc-Can : ∀ {b : Bin} → Can b → Can (inc b)
inc-Can zero-C = one-C oneO
inc-Can (one-C ob) = one-C (inc-Bin ob)
to-Can : ∀ (n : ℕ) → Can (toᵇ n)
to-Can zero = zero-C
to-Can (suc n) = inc-Can (to-Can n)
twicebinisO : ∀ {b : Bin} → One b → b +ᵇ b ≡ b O
twicebinisO {⟨⟩ I} _ = refl
twicebinisO {b O} (oneO-O ob) rewrite twicebinisO ob = refl
twicebinisO {b I} (oneO-I ob) rewrite twicebinisO ob = refl
to∘from-Can : ∀ {b : Bin} → Can b → toᵇ (fromᵇ b) ≡ b
to∘from-Can zero-C = refl
to∘from-Can (one-C oneO) = refl
to∘from-Can {b O} (one-C (oneO-O ob))
rewrite monobin (fromᵇ b)
| to∘from-Can (one-C ob)
| twicebinisO ob = refl
to∘from-Can {b I} (one-C (oneO-I ob))
rewrite monobin (fromᵇ b)
| to∘from-Can (one-C ob)
| twicebinisO ob = refl
--------------------------------------- Equality ---------------------------------------
module ≤-Reasoning where
infix 1 begin≤_
infixr 2 _≤⟨⟩_ _≤⟨_⟩_
infix 3 _∎≤
begin≤_ : ∀ {x y : ℕ} → x ≤ y → x ≤ y
begin≤ x≤y = x≤y
_≤⟨⟩_ : ∀ (x : ℕ) {y : ℕ} → x ≤ y → x ≤ y
x ≤⟨⟩ x≤y = x≤y
_≤⟨_⟩_ : ∀ (x : ℕ) {y z : ℕ} → x ≤ y → y ≤ z → x ≤ z
x ≤⟨ x≤y ⟩ y≤z = trans-≤ x≤y y≤z
_∎≤ : ∀ (x : ℕ) → x ≤ x
x ∎≤ = refl-≤
open ≤-Reasoning
+-monoʳ-≤` : ∀ {n p q : ℕ} → p ≤ q → (n + p) ≤ (n + q)
+-monoʳ-≤` {zero} p≤q = p≤q
+-monoʳ-≤` {suc n} {p} {q} p≤q =
begin≤
suc n + p
≤⟨⟩
suc (n + p)
≤⟨ s≤s (+-monoʳ-≤` p≤q) ⟩
suc (n + q)
≤⟨⟩
suc n + q
∎≤
pred≡ : ∀ {m n : ℕ} → suc m ≡ suc n → m ≡ n
pred≡ = cong pred
≡to≤ : ∀ {m n : ℕ} → m ≡ n → m ≤ n
≡to≤ {zero} {zero} _ = refl-≤
≡to≤ {suc m} {suc n} sm≡sn = s≤s (≡to≤ (cong pred sm≡sn))
+-monoˡ-≤` : ∀ {m n p : ℕ} → m ≤ n → (m + p) ≤ (n + p)
+-monoˡ-≤` {m} {n} {p} m≤n =
begin≤
m + p
≤⟨ ≡to≤ (comm-+ m p) ⟩
p + m
≤⟨ +-monoʳ-≤` {p} {m} {n} m≤n ⟩
p + n
≤⟨ ≡to≤ (comm-+ p n) ⟩
n + p
∎≤
+-mono-≤` : ∀ {m n p q : ℕ} → m ≤ n → p ≤ q → (m + p) ≤ (n + q)
+-mono-≤` {m} {n} {p} {q} m≤n p≤q =
begin≤
m + p
≤⟨ +-monoˡ-≤` m≤n ⟩
n + p
≤⟨ +-monoʳ-≤` p≤q ⟩
n + q
∎≤
--even-comm′ : ∀ (m n : ℕ)
-- → even (m + n)
-- ------------
-- → even (n + m)
--even-comm′ m n ev with m + n | comm-+ m n
--... | .(n + m) | refl = ev
--------------------------------------- Isomorphism ---------------------------------------
postulate
extensionality : ∀ {A B : Set} {f g : A → B}
→ (∀ (x : A) → f x ≡ g x)
-----------------------
→ f ≡ g
_+′_ : ℕ → ℕ → ℕ
m +′ zero = m
m +′ suc n = suc (m +′ n)
same-app : ∀ (m n : ℕ) → m +′ n ≡ m + n
same-app m n rewrite comm-+ m n = helper m n
where
helper : ∀ (m n : ℕ) → m +′ n ≡ n + m
helper _ zero = refl
helper m (suc n) = cong suc (helper m n)
same-+-+′ : _+′_ ≡ _+_
same-+-+′ = extensionality (λ m → extensionality (λ n → same-app m n))
--open import Level using (Level; _⊔_) renaming (zero to lzero; suc to lsuc)
--
--private
-- variable
-- ℓ ℓ₁ : Level
--infix 0 _≃_
--record _≃_ (A : Set ℓ) (B : Set ℓ₁) : Set (ℓ ⊔ ℓ₁) where
record _≃_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
to∘from : ∀ (y : B) → to (from y) ≡ y
open _≃_
≃-refl : ∀ {A : Set} → A ≃ A
≃-refl =
record
{ to = λ x → x
; from = λ y → y
; from∘to = λ x → refl
; to∘from = λ y → refl
}
≃-sym : ∀ {A B : Set} → A ≃ B → B ≃ A
≃-sym A≃B =
record
{ to = from A≃B
; from = to A≃B
; from∘to = to∘from A≃B
; to∘from = from∘to A≃B
}
open import Function.Base using (_∘_)
≃-trans : ∀ {A B C : Set} → A ≃ B → B ≃ C → A ≃ C
≃-trans A≃B B≃C =
record
{ to = to B≃C ∘ to A≃B
; from = from A≃B ∘ from B≃C
; from∘to = λ{x →
begin
from A≃B (from B≃C (to B≃C (to A≃B x)))
≡⟨ cong (from A≃B) (from∘to B≃C (to A≃B x)) ⟩
from A≃B (to A≃B x)
≡⟨ from∘to A≃B x ⟩
x
∎
}
; to∘from = λ{y →
begin
to B≃C (to A≃B (from A≃B (from B≃C y)))
≡⟨ cong (to B≃C) (to∘from A≃B (from B≃C y)) ⟩
to B≃C (from B≃C y)
≡⟨ to∘from B≃C y ⟩
y
∎
}
}
infix 0 _≲_
record _≲_ (A B : Set) : Set where
field
to : A → B
from : B → A
from∘to : ∀ (x : A) → from (to x) ≡ x
open _≲_
≃-implies-≲ : ∀ {A B : Set} → A ≃ B → A ≲ B
≃-implies-≲ A≃B =
record
{ to = to A≃B
; from = from A≃B
; from∘to = from∘to A≃B
}
-- Idea: Prove that (ℕ) is isomorph to (Can)
-- Idea: Prove that (+, ℕ) is isomorph to (+ᵇ, Can)
--record _⇔_ (A B : Set) : Set where
-- field
-- to : A → B
-- from : B → A
-- Exercise: implement reflexive, symetric and transitive properties on _⇔_
ℕ≲Bin : ℕ ≲ Bin
ℕ≲Bin =
record
{ to = toᵇ
; from = fromᵇ
; from∘to = from∘toᵇ
}
data Dec-Can : Set where
num : ∀ (b : Bin) → Can b → Dec-Can
toᵈᶜ : ℕ → Dec-Can
toᵈᶜ n = num (toᵇ n) (to-Can n)
--toᵈᶜ n = num (to-Can n)
fromᵈᶜ : Dec-Can → ℕ
fromᵈᶜ (num b _) = fromᵇ b
--from∘toᵈᶜ (suc n) = ?
-- λ n → fromᵈᶜ (toᵈᶜ (suc n)) ≡ suc n
-- λ cb → toᵈᶜ (fromᵈᶜ (num cb)) ≡ num cb
-- λ b ob → toᵈᶜ (fromᵈᶜ (num (b O) (one-C (oneO-O ob))))
--to∘fromᵈᶜ : ∀ (y : Dec-Can) → toᵈᶜ (fromᵈᶜ y) ≡ y
--to∘fromᵈᶜ (num (⟨⟩ O) zero-C) = refl
--to∘fromᵈᶜ (num (⟨⟩ I) (one-C oneO)) = refl
--to∘fromᵈᶜ (num (b O) (one-C (oneO-O {b} ob))) rewrite monobin (fromᵇ b) = ?
---- λ b ob → toᵈᶜ (fromᵈᶜ (num (b O) (one-C (oneO-O ob))))
---- λ b ob → λ b ob → num (toᵇ (fromᵇ b + fromᵇ b)) (to-Can (fromᵇ b + fromᵇ b))
--to∘fromᵈᶜ = ?
----to∘fromᵈᶜ (num b cb) =
---- begin
---- toᵈᶜ (fromᵈᶜ (num b cb))
---- ≡⟨⟩
---- toᵈᶜ (fromᵇ b)
---- ≡⟨⟩
---- num (toᵇ (fromᵇ b)) (to-Can (fromᵇ b))
---- ≡⟨ ? ⟩
---- num b cb
---- ∎
--ℕ≃Can : ℕ ≃ Dec-Can
--ℕ≃Can =
-- record
-- { to = toᵈᶜ
-- ; from = fromᵈᶜ
-- ; from∘to = from∘toᵇ
-- ; to∘from = ? -- to∘fromᵈᶜ -- to∘from-Can
-- }
--num (zero-C)
--------------------------------------- Decidable ---------------------------------------
-- Use `Dec` to create elements for `Can`. Look if this is enough to prove `ℕ ≃ Can`
-- Ans: NO. Decidables don't do what you thought they do
--------------------------------------- Last ---------------------------------------
-- Prove that `sqrt 2` is irrational
-- Stuff to take into account and add to agda neovim:
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_load "plfa/part1/Naturals.agda" [])
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_compute_toplevel DefaultCompute "2 + suc 3") # Already done by plugin
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_infer_toplevel AsIs "2 + suc 3") # THIS SHOULD BE PART OF THE STUFF IN MAGDA
--
-- Other stuff:
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_show_module_contents_toplevel AsIs "Eq")
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_why_in_scope_toplevel "Eq")
-- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_why_in_scope (InteractionId 1) (Range (Just "plfa/part1/Naturals.agda") (Interval (Pn () 1 76 1) (Pn () 1 76 19))) "Eq")
---- IOTCM "plfa/part1/Naturals.agda" None Direct (Cmd_autoOne (InteractionId 1) noRange "")
---- IOTCM "plfa/part1/Naturals.agda" NonInteractive Indirect (Cmd_infer Simplified 103992 (intervalsToRange (Just (mkAbsolute "plfa/part1/Naturals.agda")) [Interval (Pn () 50 75 1) (Pn () 52 79 1)]) "3 + suc 2")
|
{
"alphanum_fraction": 0.4476735199,
"avg_line_length": 29.5388127854,
"ext": "agda",
"hexsha": "f0cc33c8df8e4996f9c39df5a70268b8fd86a957",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_forks_repo_licenses": [
"CC0-1.0"
],
"max_forks_repo_name": "helq/old_code",
"max_forks_repo_path": "proglangs-learning/Agda/plfa-exercises/Practice.agda",
"max_issues_count": 4,
"max_issues_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_issues_repo_issues_event_max_datetime": "2021-06-07T15:39:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-03-10T19:20:21.000Z",
"max_issues_repo_licenses": [
"CC0-1.0"
],
"max_issues_repo_name": "helq/old_code",
"max_issues_repo_path": "proglangs-learning/Agda/plfa-exercises/Practice.agda",
"max_line_length": 212,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "a432faf1b340cb379190a2f2b11b997b02d1cd8d",
"max_stars_repo_licenses": [
"CC0-1.0"
],
"max_stars_repo_name": "helq/old_code",
"max_stars_repo_path": "proglangs-learning/Agda/plfa-exercises/Practice.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 15718,
"size": 32345
}
|
module Impure.STLCRef.Properties.Soundness where
open import Data.Nat
open import Data.Sum
open import Data.Product as Pr
open import Data.List
open import Data.Vec hiding (_∷ʳ_)
open import Data.Star
open import Function
open import Extensions.List
open import Relation.Binary.PropositionalEquality as P
open import Relation.Binary.Core using (REL; Reflexive)
open import Relation.Binary.List.Pointwise as PRel hiding (refl)
open import Impure.STLCRef.Syntax hiding (id)
open import Impure.STLCRef.Welltyped
open import Impure.STLCRef.Eval
ref-value-lemma : ∀ {n A Γ Σ} {e : Exp n} → Γ , Σ ⊢ e ∶ Ref A → Val e → ∃ λ i → e ≡ (loc i)
ref-value-lemma (var x) ()
ref-value-lemma (loc p) (loc i) = i , refl
ref-value-lemma (p · p₁) ()
ref-value-lemma (ref p) ()
ref-value-lemma (! p) ()
progress : ∀ {Γ Σ A} {e : Exp 0} {μ} →
Γ , Σ ⊢ μ →
Γ , Σ ⊢ e ∶ A →
--------------------------------------
Val e ⊎ ∃₂ λ e' μ' → (e , μ ≻ e' , μ')
progress p unit = inj₁ unit
progress p (var ())
progress p (loc {i = i} q) = inj₁ (loc i)
progress p (ƛ wt) = inj₁ (ƛ _ _)
progress p (f · e) with progress p f
progress p (() · e) | inj₁ unit
progress p (() · e) | inj₁ (loc i)
progress p (ƛ f · e) | inj₁ (ƛ _ _) = inj₂ (_ , (_ , AppAbs))
progress p (f · e) | inj₂ (_ , _ , f≻f') = inj₂ (_ , (_ , (Appₗ f≻f')))
progress p (ref wt) with progress p wt
progress p (ref wt) | inj₁ v = inj₂ (_ , (_ , (RefVal v)))
progress p (ref wt) | inj₂ (_ , _ , wt≻wt') = inj₂ (_ , _ , Ref wt≻wt')
progress p (! wt) with progress p wt
progress p (! wt) | inj₁ v with ref-value-lemma wt v
progress p (! loc q) | inj₁ (loc .i) | (i , refl) =
inj₂ (_ , (_ , (DerefLoc (P.subst (_<_ _) (pointwise-length p) ([]=-length q)))))
progress p (! wt) | inj₂ (_ , _ , wt≻wt') = inj₂ (_ , (_ , (Deref wt≻wt')))
progress p (wt ≔ x) with progress p wt | progress p x
progress p (wt ≔ x) | _ | inj₂ (_ , _ , x≻x') = inj₂ (_ , (_ , (Assign₂ x≻x')))
progress p (wt ≔ x) | inj₂ (_ , _ , wt≻wt') | _ = inj₂ (_ , _ , Assign₁ wt≻wt')
progress p (wt ≔ x) | inj₁ v | inj₁ w with ref-value-lemma wt v
progress p (loc q ≔ x) | inj₁ (loc .i) | inj₁ w | (i , refl) =
inj₂ (_ , (_ , Assign (P.subst (_<_ _) (pointwise-length p) ([]=-length q)) w))
postulate
sub-preserves : ∀ {n Γ Σ A B x} {e : Exp (suc n)} →
(B ∷ Γ) , Σ ⊢ e ∶ A →
Γ , Σ ⊢ x ∶ B →
Γ , Σ ⊢ (e / sub x) ∶ A
!!-loc : ∀ {n Σ Σ' A μ i} {Γ : Ctx n} →
Rel (λ A x → Γ , Σ ⊢ proj₁ x ∶ A) Σ' μ →
Σ' ⊢loc i ∶ A → (l : i < length μ) → Γ , Σ ⊢ proj₁ (μ !! l) ∶ A
!!-loc [] ()
!!-loc (x∼y ∷ p) here (s≤s z≤n) = x∼y
!!-loc (x∼y ∷ p) (there q) (s≤s l) = !!-loc p q l
-- extending the store preserves expression typings
⊒-preserves : ∀ {n Γ Σ Σ' A} {e : Exp n} → Σ' ⊒ Σ → Γ , Σ ⊢ e ∶ A → Γ , Σ' ⊢ e ∶ A
⊒-preserves ext unit = unit
⊒-preserves ext (var x) = var x
⊒-preserves ext (loc x) = loc (xs⊒ys[i] x ext)
⊒-preserves ext (ƛ p) = ƛ (⊒-preserves ext p)
⊒-preserves ext (p · q) = (⊒-preserves ext p) · ⊒-preserves ext q
⊒-preserves ext (ref p) = ref (⊒-preserves ext p)
⊒-preserves ext (! p) = ! (⊒-preserves ext p)
⊒-preserves ext (p ≔ q) = (⊒-preserves ext p) ≔ (⊒-preserves ext q)
≻-preserves : ∀ {n Γ Σ A} {e : Exp n} {e' μ' μ} →
Γ , Σ ⊢ e ∶ A →
Γ , Σ ⊢ μ → e , μ ≻ e' , μ' →
---------------------------------
∃ λ Σ' → Γ , Σ' ⊢ e' ∶ A × Σ' ⊒ Σ × Γ , Σ' ⊢ μ'
≻-preserves unit p ()
≻-preserves (var x) p ()
≻-preserves (loc p) p₁ ()
≻-preserves (ƛ wt) p ()
≻-preserves {Σ = Σ} (ƛ wt · wt₁) p AppAbs = Σ , sub-preserves wt wt₁ , ⊑-refl , p
≻-preserves {Σ = Σ} (ref {x = x} {A} wt) p (RefVal v) = let ext = ∷ʳ-⊒ A Σ in
Σ ∷ʳ A ,
loc (P.subst (λ i → _ ⊢loc i ∶ _) (pointwise-length p) (∷ʳ[length] Σ A)) ,
ext ,
pointwise-∷ʳ (PRel.map (⊒-preserves ext) p) (⊒-preserves ext wt)
≻-preserves {Σ = Σ₁} (! loc x) p (DerefLoc l) =
Σ₁ , !!-loc p x l , ⊑-refl , p
≻-preserves {Σ = Σ₁} (loc x ≔ y) p (Assign l v) =
Σ₁ , unit , ⊑-refl , pointwise-[]≔ p x l y
-- contextual closure
≻-preserves {Σ = Σ} (wt-f · wt-x) p (Appₗ r) =
Pr.map
id
(λ{ (wt-f' , ext , q) → wt-f' · ⊒-preserves ext wt-x , ext , q})
(≻-preserves wt-f p r)
≻-preserves (f · x) p (Appᵣ r) =
Pr.map
id
(λ{ (x' , ext , q) → ⊒-preserves ext f · x' , ext , q})
(≻-preserves x p r)
≻-preserves (ref wt) p (Ref r) = Pr.map id (λ{ (wt' , ext) → ref wt' , ext}) (≻-preserves wt p r)
≻-preserves (! wt) p (Deref r) = Pr.map id (λ{ (wt' , ext) → ! wt' , ext}) (≻-preserves wt p r)
≻-preserves (y ≔ x) p (Assign₁ r) =
Pr.map
id
(λ{ (y' , ext , q) → y' ≔ ⊒-preserves ext x , ext , q})
(≻-preserves y p r)
≻-preserves (y ≔ x) p (Assign₂ r) =
Pr.map
id
(λ{ (x' , ext , q) → ⊒-preserves ext y ≔ x' , ext , q})
(≻-preserves x p r)
-- preservation for multistep reductions
preservation : ∀ {n} {e : Exp n} {Γ Σ A μ μ' e'} →
Γ , Σ ⊢ e ∶ A →
Γ , Σ ⊢ μ →
e , μ ≻* e' , μ' →
-----------------------------------------------
∃ λ Σ' → Γ , Σ' ⊢ e' ∶ A × Σ' ⊒ Σ × Γ , Σ' ⊢ μ'
preservation wt ok ε = _ , wt , ⊑-refl , ok
preservation wt ok (x ◅ r) with ≻-preserves wt ok x
... | Σ₂ , wt' , Σ₂⊒Σ , μ₂ok with preservation wt' μ₂ok r
... | Σ₃ , wt'' , Σ₃⊒Σ₂ , μ₃ = Σ₃ , wt'' , ⊑-trans Σ₂⊒Σ Σ₃⊒Σ₂ , μ₃
-- fueled evaluation
open import Data.Maybe
eval : ∀ {e : Exp zero} {Σ A μ} ℕ →
[] , Σ ⊢ e ∶ A →
[] , Σ ⊢ μ →
---------------------------------------
Maybe (∃ λ Σ' → ∃ λ e' → ∃ λ μ' →
(e , μ ≻* e' , μ') × Val e' × ([] , Σ' ⊢ e' ∶ A))
eval 0 _ _ = nothing
eval (suc n) p q with progress q p
eval (suc n) p q | inj₁ x = just (_ , _ , _ , ε , x , p)
eval (suc n) p q | inj₂ (e' , μ' , step) with ≻-preserves p q step
... | (Σ₂ , wte' , ext , μ'-ok) with eval n wte' μ'-ok
... | nothing = nothing
... | just (Σ₃ , e'' , μ'' , steps , v , wte'') = just (Σ₃ , e'' , μ'' , step ◅ steps , v , wte'')
|
{
"alphanum_fraction": 0.4984063077,
"avg_line_length": 37.25625,
"ext": "agda",
"hexsha": "5cc4dde581af12e33d9e184a3fa3d145a44c510f",
"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": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "metaborg/ts.agda",
"max_forks_repo_path": "src/Impure/STLCRef/Properties/Soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"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": "metaborg/ts.agda",
"max_issues_repo_path": "src/Impure/STLCRef/Properties/Soundness.agda",
"max_line_length": 98,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "7fe638b87de26df47b6437f5ab0a8b955384958d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "metaborg/ts.agda",
"max_stars_repo_path": "src/Impure/STLCRef/Properties/Soundness.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2562,
"size": 5961
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.Adjoint.Alternatives where
open import Level
open import Categories.Adjoint
open import Categories.Category
open import Categories.Functor renaming (id to idF)
open import Categories.NaturalTransformation
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ e : Level
C D : Category o ℓ e
module _ (L : Functor C D) (R : Functor D C) where
private
module C = Category C
module D = Category D
module L = Functor L
module R = Functor R
record FromUnit : Set (levelOfTerm L ⊔ levelOfTerm R) where
field
unit : NaturalTransformation idF (R ∘F L)
module unit = NaturalTransformation unit
field
θ : ∀ {X Y} → C [ X , R.₀ Y ] → D [ L.₀ X , Y ]
commute : ∀ {X Y} (g : C [ X , R.₀ Y ]) → g C.≈ R.₁ (θ g) C.∘ unit.η X
unique : ∀ {X Y} {f : D [ L.₀ X , Y ]} {g : C [ X , R.₀ Y ]} →
g C.≈ R.₁ f C.∘ unit.η X → θ g D.≈ f
module _ where
open C.HomReasoning
open MR C
θ-natural : ∀ {X Y Z} (f : D [ Y , Z ]) (g : C [ X , R.₀ Y ]) → θ (R.₁ f C.∘ g) D.≈ θ (R.₁ f) D.∘ L.₁ g
θ-natural {X} {Y} f g = unique eq
where eq : R.₁ f C.∘ g C.≈ R.₁ (θ (R.₁ f) D.∘ L.₁ g) C.∘ unit.η X
eq = begin
R.₁ f C.∘ g ≈⟨ commute (R.₁ f) ⟩∘⟨refl ⟩
(R.₁ (θ (R.₁ f)) C.∘ unit.η (R.F₀ Y)) C.∘ g ≈⟨ C.assoc ⟩
R.₁ (θ (R.₁ f)) C.∘ unit.η (R.₀ Y) C.∘ g ≈⟨ pushʳ (unit.commute g) ⟩
(R.₁ (θ (R.₁ f)) C.∘ R.₁ (L.₁ g)) C.∘ unit.η X ≈˘⟨ R.homomorphism ⟩∘⟨refl ⟩
R.₁ (θ (R.₁ f) D.∘ L.₁ g) C.∘ unit.η X ∎
θ-cong : ∀ {X Y} {f g : C [ X , R.₀ Y ]} → f C.≈ g → θ f D.≈ θ g
θ-cong eq = unique (eq ○ commute _)
θ-natural′ : ∀ {X Y} (g : C [ X , R.₀ Y ]) → θ g D.≈ θ C.id D.∘ L.₁ g
θ-natural′ g = θ-cong (introˡ R.identity) ○ θ-natural D.id g ○ D.∘-resp-≈ˡ (θ-cong R.identity)
where open D.HomReasoning
open MR C
counit : NaturalTransformation (L ∘F R) idF
counit = ntHelper record
{ η = λ d → θ C.id
; commute = λ f → begin
θ C.id D.∘ L.₁ (R.₁ f) ≈˘⟨ θ-natural′ (R.₁ f) ⟩
θ (R.₁ f) ≈⟨ unique (CH.⟺ (MR.cancelʳ C (CH.⟺ (commute C.id))) CH.○ CH.⟺ (C.∘-resp-≈ˡ R.homomorphism)) ⟩
f D.∘ θ C.id ∎
}
where open D.HomReasoning
module CH = C.HomReasoning
unique′ : ∀ {X Y} {f g : D [ L.₀ X , Y ]} (h : C [ X , R.₀ Y ]) →
h C.≈ R.₁ f C.∘ unit.η X →
h C.≈ R.₁ g C.∘ unit.η X → f D.≈ g
unique′ _ eq₁ eq₂ = ⟺ (unique eq₁) ○ unique eq₂
where open D.HomReasoning
zig : ∀ {A} → θ C.id D.∘ L.F₁ (unit.η A) D.≈ D.id
zig {A} = unique′ (unit.η A)
(commute (unit.η A) ○ (C.∘-resp-≈ˡ (R.F-resp-≈ (θ-natural′ (unit.η A)))))
(introˡ R.identity)
where open C.HomReasoning
open MR C
L⊣R : L ⊣ R
L⊣R = record
{ unit = unit
; counit = counit
; zig = zig
; zag = C.Equiv.sym (commute C.id)
}
record FromCounit : Set (levelOfTerm L ⊔ levelOfTerm R) where
field
counit : NaturalTransformation (L ∘F R) idF
module counit = NaturalTransformation counit
field
θ : ∀ {X Y} → D [ L.₀ X , Y ] → C [ X , R.₀ Y ]
commute : ∀ {X Y} (g : D [ L.₀ X , Y ]) → g D.≈ counit.η Y D.∘ L.₁ (θ g)
unique : ∀ {X Y} {f : C [ X , R.₀ Y ]} {g : D [ L.₀ X , Y ]} →
g D.≈ counit.η Y D.∘ L.₁ f → θ g C.≈ f
module _ where
open D.HomReasoning
open MR D
θ-natural : ∀ {X Y Z} (f : C [ X , Y ]) (g : D [ L.₀ Y , Z ]) → θ (g D.∘ L.₁ f) C.≈ R.₁ g C.∘ θ (L.₁ f)
θ-natural {X} {Y} {Z} f g = unique eq
where eq : g D.∘ L.₁ f D.≈ counit.η Z D.∘ L.₁ (R.₁ g C.∘ θ (L.₁ f))
eq = begin
g D.∘ L.₁ f ≈⟨ pushʳ (commute (L.₁ f)) ⟩
(g D.∘ counit.η (L.F₀ Y)) D.∘ L.F₁ (θ (L.F₁ f)) ≈⟨ pushˡ (counit.sym-commute g) ⟩
counit.η Z D.∘ L.₁ (R.₁ g) D.∘ L.₁ (θ (L.₁ f)) ≈˘⟨ refl⟩∘⟨ L.homomorphism ⟩
counit.η Z D.∘ L.₁ (R.₁ g C.∘ θ (L.₁ f)) ∎
θ-cong : ∀ {X Y} {f g : D [ L.₀ X , Y ]} → f D.≈ g → θ f C.≈ θ g
θ-cong eq = unique (eq ○ commute _)
θ-natural′ : ∀ {X Y} (g : D [ L.₀ X , Y ]) → θ g C.≈ R.₁ g C.∘ θ D.id
θ-natural′ g = θ-cong (introʳ L.identity) ○ θ-natural C.id g ○ C.∘-resp-≈ʳ (θ-cong L.identity)
where open C.HomReasoning
open MR D
unit : NaturalTransformation idF (R ∘F L)
unit = ntHelper record
{ η = λ _ → θ D.id
; commute = λ f → begin
θ D.id C.∘ f ≈˘⟨ unique (DH.⟺ (cancelˡ (DH.⟺ (commute D.id))) DH.○ D.∘-resp-≈ʳ (DH.⟺ L.homomorphism)) ⟩
θ (L.₁ f) ≈⟨ θ-natural′ (L.₁ f) ⟩
R.₁ (L.₁ f) C.∘ θ D.id ∎
}
where open C.HomReasoning
module DH = D.HomReasoning
open MR D
unique′ : ∀ {X Y} {f g : C [ X , R.₀ Y ]} (h : D [ L.₀ X , Y ]) →
h D.≈ counit.η Y D.∘ L.₁ f →
h D.≈ counit.η Y D.∘ L.₁ g →
f C.≈ g
unique′ _ eq₁ eq₂ = ⟺ (unique eq₁) ○ unique eq₂
where open C.HomReasoning
zag : ∀ {B} → R.F₁ (counit.η B) C.∘ θ D.id C.≈ C.id
zag {B} = unique′ (counit.η B)
(⟺ (cancelʳ (⟺ (commute D.id))) ○ pushˡ (counit.sym-commute (counit.η B)) ○ D.∘-resp-≈ʳ (⟺ L.homomorphism))
(introʳ L.identity)
where open D.HomReasoning
open MR D
L⊣R : L ⊣ R
L⊣R = record
{ unit = unit
; counit = counit
; zig = D.Equiv.sym (commute D.id)
; zag = zag
}
module _ {L : Functor C D} {R : Functor D C} where
fromUnit : FromUnit L R → L ⊣ R
fromUnit = FromUnit.L⊣R
fromCounit : FromCounit L R → L ⊣ R
fromCounit = FromCounit.L⊣R
|
{
"alphanum_fraction": 0.4376493072,
"avg_line_length": 37.375,
"ext": "agda",
"hexsha": "4b6336843edd74997942d3a1af4cee2650bdb5c8",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/Adjoint/Alternatives.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/Adjoint/Alternatives.agda",
"max_line_length": 131,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/Adjoint/Alternatives.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 2580,
"size": 6279
}
|
-- Trying to define ≤ as a datatype in Prop doesn't work very well:
{-# OPTIONS --enable-prop #-}
open import Agda.Builtin.Nat
data _≤'_ : Nat → Nat → Prop where
zero : (y : Nat) → zero ≤' y
suc : (x y : Nat) → x ≤' y → suc x ≤' suc y
≤'-ind : (P : (m n : Nat) → Set)
→ (pzy : (y : Nat) → P zero y)
→ (pss : (x y : Nat) → P x y → P (suc x) (suc y))
→ (m n : Nat) → m ≤' n → P m n
≤'-ind P pzy pss .0 y (zero .y) = ?
≤'-ind P pzy pss .(suc x) .(suc y) (suc x y pf) = ?
|
{
"alphanum_fraction": 0.4799196787,
"avg_line_length": 29.2941176471,
"ext": "agda",
"hexsha": "79db398669d30bc098687243a5d17f2ab5ed31d4",
"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-LeqNoEliminator.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-LeqNoEliminator.agda",
"max_line_length": 67,
"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-LeqNoEliminator.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": 209,
"size": 498
}
|
module Lookup where
data Bool : Set where
false : Bool
true : Bool
data IsTrue : Bool -> Set where
isTrue : IsTrue true
data List (A : Set) : Set where
[] : List A
_::_ : A -> List A -> List A
data _×_ (A B : Set) : Set where
_,_ : A -> B -> A × B
module Map
(Key : Set)
(_==_ : Key -> Key -> Bool)
(Code : Set)
(Val : Code -> Set) where
infixr 40 _⟼_,_
infix 20 _∈_
data Map : List Code -> Set where
ε : Map []
_⟼_,_ : forall {c cs} ->
Key -> Val c -> Map cs -> Map (c :: cs)
_∈_ : forall {cs} -> Key -> Map cs -> Bool
k ∈ ε = false
k ∈ (k' ⟼ _ , m) with k == k'
... | true = true
... | false = k ∈ m
Lookup : forall {cs} -> (k : Key)(m : Map cs) -> IsTrue (k ∈ m) -> Set
Lookup k ε ()
Lookup k (_⟼_,_ {c} k' _ m) p with k == k'
... | true = Val c
... | false = Lookup k m p
lookup : {cs : List Code}(k : Key)(m : Map cs)(p : IsTrue (k ∈ m)) ->
Lookup k m p
lookup k ε ()
lookup k (k' ⟼ v , m) p with k == k'
... | true = v
... | false = lookup k m p
|
{
"alphanum_fraction": 0.4595086442,
"avg_line_length": 22.4285714286,
"ext": "agda",
"hexsha": "7a95d920f432f11566f575675375514294ca1677",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "examples/Lookup.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "masondesu/agda",
"max_issues_repo_path": "examples/Lookup.agda",
"max_line_length": 72,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "examples/Lookup.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": 407,
"size": 1099
}
|
-- Andreas, 2014-03-05, reported by xcycl.xoo, Mar 30, 2009
-- {-# OPTIONS -v tc.with:60 #-}
open import Common.Prelude renaming (Nat to ℕ; module Nat to ℕ)
data Nat : ℕ → Set where
i : (k : ℕ) → Nat k
toNat : (n : ℕ) → Nat n
toNat n = i n
fun : (n : ℕ) → ℕ
fun n with toNat n
fun .m | i m with toNat m
fun .Set | i .l | i l = 0
-- 'Set' is ill-typed here and should trigger an error
FORCE_FAIL_HERE_UNTIL_ISSUE_142_IS_REALLY_FIXED
|
{
"alphanum_fraction": 0.6431818182,
"avg_line_length": 22,
"ext": "agda",
"hexsha": "e3d143d6f72542a310398692bebedc75c5e291d4",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_forks_event_min_datetime": "2022-03-12T11:35:18.000Z",
"max_forks_repo_head_hexsha": "70c8a575c46f6a568c7518150a1a64fcd03aa437",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "masondesu/agda",
"max_forks_repo_path": "test/fail/Issue142.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/Issue142.agda",
"max_line_length": 63,
"max_stars_count": 3,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue142.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": 164,
"size": 440
}
|
id : Set → Set
id A = A
|
{
"alphanum_fraction": 0.5,
"avg_line_length": 8,
"ext": "agda",
"hexsha": "398748dcb3eda8d2d87374ee6dc9898d3571588b",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/Issue2536-1.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/Issue2536-1.agda",
"max_line_length": 14,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/Issue2536-1.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": 11,
"size": 24
}
|
------------------------------------------------------------------------
-- INCREMENTAL λ-CALCULUS
--
-- Correctness of differentiation with the Nehemiah plugin.
------------------------------------------------------------------------
module Nehemiah.Change.Correctness where
-- The denotational properties of the `derive` transformation
-- for Calculus Nehemiah. In particular, the main theorem
-- about it producing the correct incremental behavior.
open import Nehemiah.Syntax.Type
open import Nehemiah.Syntax.Term
open import Nehemiah.Denotation.Value
open import Nehemiah.Denotation.Evaluation
open import Nehemiah.Change.Type
open import Nehemiah.Change.Term
open import Nehemiah.Change.Value
open import Nehemiah.Change.Evaluation
open import Nehemiah.Change.Validity
open import Nehemiah.Change.Derive
open import Nehemiah.Change.Implementation
open import Base.Denotation.Notation
open import Relation.Binary.PropositionalEquality
open import Data.Integer
open import Theorem.Groups-Nehemiah
open import Postulate.Extensionality
import Parametric.Change.Correctness
Const ⟦_⟧Base ⟦_⟧Const ΔBase
apply-base diff-base nil-base
⟦apply-base⟧ ⟦diff-base⟧ ⟦nil-base⟧
meaning-⊕-base meaning-⊝-base meaning-onil-base
derive-const implementation-structure as Correctness
open import Algebra.Structures
private
flatmap-funarg-equal : ∀ (f : ℤ → Bag) (Δf : Δ₍ int ⇒ bag ₎ f) Δf′ (Δf≈Δf′ : Δf ≈₍ int ⇒ bag ₎ Δf′) →
(f ⊞₍ int ⇒ bag ₎ Δf) ≡ (f ⟦⊕₍ int ⇒ bag ₎⟧ Δf′)
flatmap-funarg-equal f Δf Δf′ Δf≈Δf′ = ext lemma
where
lemma : ∀ v → f v ++ FunctionChange.apply Δf v (+ 0) ≡ f v ++ Δf′ v (+ 0)
lemma v rewrite Δf≈Δf′ v (+ 0) (+ 0) refl = refl
derive-const-correct : Correctness.Structure
derive-const-correct (intlit-const n) = refl
derive-const-correct add-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl
rewrite mn·pq=mp·nq {w} {Δw} {w₁} {Δw₁}
| associative-int (w + w₁) (Δw + Δw₁) (- (w + w₁))
= n+[m-n]=m {w + w₁} {Δw + Δw₁}
derive-const-correct minus-const w Δw .Δw refl
rewrite sym (-m·-n=-mn {w} {Δw})
| associative-int (- w) (- Δw) (- (- w)) = n+[m-n]=m { - w} { - Δw}
derive-const-correct empty-const = refl
derive-const-correct insert-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl = refl
derive-const-correct union-const w Δw .Δw refl w₁ Δw₁ .Δw₁ refl
rewrite ab·cd=ac·bd {w} {Δw} {w₁} {Δw₁}
| associative-bag (w ++ w₁) (Δw ++ Δw₁) (negateBag (w ++ w₁))
= a++[b\\a]=b {w ++ w₁} {Δw ++ Δw₁}
derive-const-correct negate-const w Δw .Δw refl
rewrite sym (-a·-b=-ab {w} {Δw})
| associative-bag (negateBag w) (negateBag Δw) (negateBag (negateBag w))
= a++[b\\a]=b {negateBag w} {negateBag Δw}
derive-const-correct flatmap-const w Δw Δw′ Δw≈Δw′ w₁ Δw₁ .Δw₁ refl
rewrite flatmap-funarg-equal w Δw Δw′ Δw≈Δw′ = refl
derive-const-correct sum-const w Δw .Δw refl
rewrite homo-sum {w} {Δw}
| associative-int (sumBag w) (sumBag Δw) (- sumBag w)
= n+[m-n]=m {sumBag w} {sumBag Δw}
open Correctness.Structure derive-const-correct public
|
{
"alphanum_fraction": 0.6667786362,
"avg_line_length": 39.6933333333,
"ext": "agda",
"hexsha": "7689cdf22c5497a98e5666bdd47cb61a592c9280",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-02-18T12:26:44.000Z",
"max_forks_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "inc-lc/ilc-agda",
"max_forks_repo_path": "Nehemiah/Change/Correctness.agda",
"max_issues_count": 6,
"max_issues_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_issues_repo_issues_event_max_datetime": "2017-05-04T13:53:59.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-07-01T18:09:31.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "inc-lc/ilc-agda",
"max_issues_repo_path": "Nehemiah/Change/Correctness.agda",
"max_line_length": 103,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "39bb081c6f192bdb87bd58b4a89291686d2d7d03",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "inc-lc/ilc-agda",
"max_stars_repo_path": "Nehemiah/Change/Correctness.agda",
"max_stars_repo_stars_event_max_datetime": "2019-07-19T07:06:59.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-03-04T06:09:20.000Z",
"num_tokens": 1056,
"size": 2977
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import Groups.Definition
open import Setoids.Setoids
open import Sets.EquivalenceRelations
open import Groups.Homomorphisms.Definition
open import Groups.Homomorphisms.Lemmas
open import Groups.Subgroups.Definition
open import Groups.Lemmas
open import Groups.Abelian.Definition
open import Groups.Subgroups.Normal.Definition
open import Agda.Primitive using (Level; lzero; lsuc; _⊔_)
module Groups.Subgroups.Normal.Lemmas where
data GroupKernelElement {a} {b} {c} {d} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) : Set (a ⊔ b ⊔ c ⊔ d) where
kerOfElt : (x : A) → (Setoid._∼_ T (f x) (Group.0G H)) → GroupKernelElement G hom
groupKernel : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Setoid (GroupKernelElement G hom)
Setoid._∼_ (groupKernel {S = S} G {H} {f} fHom) (kerOfElt x fx=0) (kerOfElt y fy=0) = Setoid._∼_ S x y
Equivalence.reflexive (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x x₁} = Equivalence.reflexive (Setoid.eq S)
Equivalence.symmetric (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x prX} {kerOfElt y prY} = Equivalence.symmetric (Setoid.eq S)
Equivalence.transitive (Setoid.eq (groupKernel {S = S} G {H} {f} fHom)) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt z prZ} = Equivalence.transitive (Setoid.eq S)
groupKernelGroupOp : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → (GroupKernelElement G hom) → (GroupKernelElement G hom) → (GroupKernelElement G hom)
groupKernelGroupOp {T = T} {_·A_ = _+A_} G {H = H} hom (kerOfElt x prX) (kerOfElt y prY) = kerOfElt (x +A y) (transitive (GroupHom.groupHom hom) (transitive (Group.+WellDefined H prX prY) (Group.identLeft H)))
where
open Setoid T
open Equivalence eq
groupKernelGroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Group (groupKernel G hom) (groupKernelGroupOp G hom)
Group.+WellDefined (groupKernelGroup G fHom) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt a prA} {kerOfElt b prB} = Group.+WellDefined G
Group.0G (groupKernelGroup G fHom) = kerOfElt (Group.0G G) (imageOfIdentityIsIdentity fHom)
Group.inverse (groupKernelGroup {T = T} G {H = H} fHom) (kerOfElt x prX) = kerOfElt (Group.inverse G x) (transitive (homRespectsInverse fHom) (transitive (inverseWellDefined H prX) (invIdent H)))
where
open Setoid T
open Equivalence eq
Group.+Associative (groupKernelGroup {S = S} {_·A_ = _·A_} G fHom) {kerOfElt x prX} {kerOfElt y prY} {kerOfElt z prZ} = Group.+Associative G
Group.identRight (groupKernelGroup G fHom) {kerOfElt x prX} = Group.identRight G
Group.identLeft (groupKernelGroup G fHom) {kerOfElt x prX} = Group.identLeft G
Group.invLeft (groupKernelGroup G fHom) {kerOfElt x prX} = Group.invLeft G
Group.invRight (groupKernelGroup G fHom) {kerOfElt x prX} = Group.invRight G
injectionFromKernelToG : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → GroupKernelElement G hom → A
injectionFromKernelToG G hom (kerOfElt x _) = x
injectionFromKernelToGIsHom : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → GroupHom (groupKernelGroup G hom) G (injectionFromKernelToG G hom)
GroupHom.groupHom (injectionFromKernelToGIsHom {S = S} G hom) {kerOfElt x prX} {kerOfElt y prY} = Equivalence.reflexive (Setoid.eq S)
GroupHom.wellDefined (injectionFromKernelToGIsHom G hom) {kerOfElt x prX} {kerOfElt y prY} i = i
groupKernelGroupPred : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → A → Set d
groupKernelGroupPred {T = T} G {H = H} {f = f} hom a = Setoid._∼_ T (f a) (Group.0G H)
groupKernelGroupPredWd : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → {x y : A} → (Setoid._∼_ S x y) → (groupKernelGroupPred G hom x → groupKernelGroupPred G hom y)
groupKernelGroupPredWd {S = S} {T = T} G hom {x} {y} x=y fx=0 = Equivalence.transitive (Setoid.eq T) (GroupHom.wellDefined hom (Equivalence.symmetric (Setoid.eq S) x=y)) fx=0
groupKernelGroupIsSubgroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → Subgroup G (groupKernelGroupPred G hom)
Subgroup.closedUnderPlus (groupKernelGroupIsSubgroup {S = S} {T = T} G {H = H} hom) g=0 h=0 = Equivalence.transitive (Setoid.eq T) (GroupHom.groupHom hom) (Equivalence.transitive (Setoid.eq T) (Group.+WellDefined H g=0 h=0) (Group.identLeft H))
Subgroup.containsIdentity (groupKernelGroupIsSubgroup G hom) = imageOfIdentityIsIdentity hom
Subgroup.closedUnderInverse (groupKernelGroupIsSubgroup {S = S} {T = T} G {H = H} hom) g=0 = Equivalence.transitive (Setoid.eq T) (homRespectsInverse hom) (Equivalence.transitive (Setoid.eq T) (inverseWellDefined H g=0) (invIdent H))
Subgroup.isSubset (groupKernelGroupIsSubgroup G hom) = groupKernelGroupPredWd G hom
groupKernelGroupIsNormalSubgroup : {a b c d : _} {A : Set a} {B : Set c} {S : Setoid {a} {b} A} {T : Setoid {c} {d} B} {_·A_ : A → A → A} {_·B_ : B → B → B} (G : Group S _·A_) {H : Group T _·B_} {f : A → B} (hom : GroupHom G H f) → normalSubgroup G (groupKernelGroupIsSubgroup G hom)
groupKernelGroupIsNormalSubgroup {T = T} G {H = H} hom k=0 = transitive groupHom (transitive (+WellDefined reflexive groupHom) (transitive (+WellDefined reflexive (transitive (+WellDefined k=0 reflexive) identLeft)) (transitive (symmetric groupHom) (transitive (wellDefined (Group.invRight G)) (imageOfIdentityIsIdentity hom)))))
where
open Setoid T
open Group H
open Equivalence eq
open GroupHom hom
abelianGroupSubgroupIsNormal : {a b c : _} {A : Set a} {S : Setoid {a} {b} A} {_+_ : A → A → A} {G : Group S _+_} {pred : A → Set c} → (s : Subgroup G pred) → AbelianGroup G → normalSubgroup G s
abelianGroupSubgroupIsNormal {S = S} {_+_ = _+_} {G = G} record { isSubset = predWd ; closedUnderPlus = respectsPlus ; containsIdentity = respectsId ; closedUnderInverse = respectsInv } abelian {k} {l} prK = predWd (transitive (transitive (transitive (symmetric identLeft) (+WellDefined (symmetric invRight) reflexive)) (symmetric +Associative)) (+WellDefined reflexive commutative)) prK
where
open Group G
open AbelianGroup abelian
open Setoid S
open Equivalence eq
|
{
"alphanum_fraction": 0.6575886137,
"avg_line_length": 92.4936708861,
"ext": "agda",
"hexsha": "9179619497335ad84fd545b2d23825722f321e2d",
"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/Subgroups/Normal/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Groups/Subgroups/Normal/Lemmas.agda",
"max_line_length": 387,
"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/Subgroups/Normal/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 2828,
"size": 7307
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Bool
open import lib.types.Empty
open import lib.types.Lift
open import lib.types.Sigma
open import lib.types.Pi
module lib.types.Coproduct where
module _ {i j} {A : Type i} {B : Type j} where
Coprod-elim : ∀ {k} {C : A ⊔ B → Type k}
→ ((a : A) → C (inl a)) → ((b : B) → C (inr b))
→ Π (A ⊔ B) C
Coprod-elim f g (inl a) = f a
Coprod-elim f g (inr b) = g b
⊔-elim = Coprod-elim
Coprod-rec : ∀ {k} {C : Type k}
→ (A → C) → (B → C) → (A ⊔ B → C)
Coprod-rec {C = C} = Coprod-elim {C = λ _ → C}
⊔-rec = Coprod-rec
Coprod= : Coprod A B → Coprod A B → Type (lmax i j)
Coprod= (inl a₁) (inl a₂) = Lift {j = (lmax i j)} $ a₁ == a₂
Coprod= (inl a₁) (inr b₂) = Lift Empty
Coprod= (inr b₁) (inl a₂) = Lift Empty
Coprod= (inr b₁) (inr b₂) = Lift {j = (lmax i j)} $ b₁ == b₂
Coprod=-in : {x y : Coprod A B} → (x == y) → Coprod= x y
Coprod=-in {inl _} idp = lift idp
Coprod=-in {inr _} idp = lift idp
Coprod=-out : {x y : Coprod A B} → Coprod= x y → (x == y)
Coprod=-out {inl _} {inl _} c = ap inl $ lower c
Coprod=-out {inl _} {inr _} c = Empty-rec $ lower c
Coprod=-out {inr _} {inl _} c = Empty-rec $ lower c
Coprod=-out {inr _} {inr _} c = ap inr (lower c)
Coprod=-in-equiv : (x y : Coprod A B) → (x == y) ≃ Coprod= x y
Coprod=-in-equiv x y = equiv Coprod=-in Coprod=-out (f-g x y) (g-f x y)
where f-g : ∀ x' y' → ∀ c → Coprod=-in (Coprod=-out {x'} {y'} c) == c
f-g (inl a₁) (inl .a₁) (lift idp) = idp
f-g (inl a₁) (inr b₂) b = Empty-rec $ lower b
f-g (inr b₁) (inl a₂) b = Empty-rec $ lower b
f-g (inr b₁) (inr .b₁) (lift idp) = idp
g-f : ∀ x' y' → ∀ p → Coprod=-out (Coprod=-in {x'} {y'} p) == p
g-f (inl _) .(inl _) idp = idp
g-f (inr _) .(inr _) idp = idp
inl=inl-equiv : (a₁ a₂ : A) → (inl a₁ == inl a₂) ≃ (a₁ == a₂)
inl=inl-equiv a₁ a₂ = lower-equiv ∘e Coprod=-in-equiv (inl a₁) (inl a₂)
inr=inr-equiv : (b₁ b₂ : B) → (inr b₁ == inr b₂) ≃ (b₁ == b₂)
inr=inr-equiv b₁ b₂ = lower-equiv ∘e Coprod=-in-equiv (inr b₁) (inr b₂)
inl≠inr : (a₁ : A) (b₂ : B) → (inl a₁ ≠ inr b₂)
inl≠inr a₁ b₂ p = lower $ Coprod=-in p
inr≠inl : (b₁ : B) (a₂ : A) → (inr b₁ ≠ inl a₂)
inr≠inl a₁ b₂ p = lower $ Coprod=-in p
instance
⊔-level : ∀ {n} → has-level (S (S n)) A → has-level (S (S n)) B
→ has-level (S (S n)) (Coprod A B)
⊔-level {n} pA pB = has-level-in (⊔-level-aux pA pB) where
instance _ = pA; _ = pB
⊔-level-aux : has-level (S (S n)) A → has-level (S (S n)) B
→ has-level-aux (S (S n)) (Coprod A B)
⊔-level-aux _ _ (inl a₁) (inl a₂) = equiv-preserves-level (inl=inl-equiv a₁ a₂ ⁻¹)
⊔-level-aux _ _ (inl a₁) (inr b₂) = has-level-in (λ p → Empty-rec (inl≠inr a₁ b₂ p))
⊔-level-aux _ _ (inr b₁) (inl a₂) = has-level-in (λ p → Empty-rec (inr≠inl b₁ a₂ p))
⊔-level-aux _ _ (inr b₁) (inr b₂) = equiv-preserves-level ((inr=inr-equiv b₁ b₂)⁻¹)
Coprod-level = ⊔-level
module _ {i j} {A : Type i} {B : Type j} where
Coprod-rec-post∘ : ∀ {k l} {C : Type k} {D : Type l}
→ (h : C → D) (f : A → C) (g : B → C)
→ h ∘ Coprod-rec f g ∼ Coprod-rec (h ∘ f) (h ∘ g)
Coprod-rec-post∘ h f g (inl _) = idp
Coprod-rec-post∘ h f g (inr _) = idp
⊔-rec-post∘ = Coprod-rec-post∘
module _ {i i' j j'} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'}
(f : A → A') (g : B → B') where
⊔-fmap : A ⊔ B → A' ⊔ B'
⊔-fmap (inl a) = inl (f a)
⊔-fmap (inr b) = inr (g b)
infix 80 _⊙⊔_
_⊙⊔_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊙⊔ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inl (pt X) ]
_⊔⊙_ : ∀ {i j} → Ptd i → Ptd j → Ptd (lmax i j)
X ⊔⊙ Y = ⊙[ Coprod (de⊙ X) (de⊙ Y) , inr (pt Y) ]
module _ {i j k} {X : Ptd i} {Y : Ptd j} {Z : Ptd k}
(f : X ⊙→ Z) (g : Y ⊙→ Z) where
⊙⊔-rec : X ⊙⊔ Y ⊙→ Z
⊙⊔-rec = Coprod-rec (fst f) (fst g) , snd f
⊔⊙-rec : X ⊔⊙ Y ⊙→ Z
⊔⊙-rec = Coprod-rec (fst f) (fst g) , snd g
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'}
(f : X ⊙→ X') (g : Y ⊙→ Y') where
⊙⊔-fmap : X ⊙⊔ Y ⊙→ X' ⊙⊔ Y'
⊙⊔-fmap = ⊔-fmap (fst f) (fst g) , ap inl (snd f)
⊔⊙-fmap : X ⊔⊙ Y ⊙→ X' ⊔⊙ Y'
⊔⊙-fmap = ⊔-fmap (fst f) (fst g) , ap inr (snd g)
codiag : ∀ {i} {A : Type i} → A ⊔ A → A
codiag = Coprod-rec (idf _) (idf _)
⊙codiag : ∀ {i} {X : Ptd i} → X ⊙⊔ X ⊙→ X
⊙codiag = (codiag , idp)
-- A binary sigma is a coproduct
ΣBool-equiv-⊔ : ∀ {i} (Pick : Bool → Type i)
→ Σ Bool Pick ≃ Pick true ⊔ Pick false
ΣBool-equiv-⊔ Pick = equiv into out into-out out-into
where
into : Σ _ Pick → Pick true ⊔ Pick false
into (true , a) = inl a
into (false , b) = inr b
out : (Pick true ⊔ Pick false) → Σ _ Pick
out (inl a) = (true , a)
out (inr b) = (false , b)
abstract
into-out : ∀ c → into (out c) == c
into-out (inl a) = idp
into-out (inr b) = idp
out-into : ∀ s → out (into s) == s
out-into (true , a) = idp
out-into (false , b) = idp
⊔₁-Empty : ∀ {i} (A : Type i) → Empty ⊔ A ≃ A
⊔₁-Empty A = equiv (λ{(inl ()); (inr a) → a}) inr (λ _ → idp) (λ{(inl ()); (inr _) → idp})
module _ {i j k} {A : Type i} {B : Type j} (P : A ⊔ B → Type k) where
Π₁-⊔-equiv-× : Π (A ⊔ B) P ≃ Π A (P ∘ inl) × Π B (P ∘ inr)
Π₁-⊔-equiv-× = equiv to from to-from from-to
where
to : Π (A ⊔ B) P → Π A (P ∘ inl) × Π B (P ∘ inr)
to f = (λ a → f (inl a)) , (λ b → f (inr b))
from : Π A (P ∘ inl) × Π B (P ∘ inr) → Π (A ⊔ B) P
from (f , g) (inl a) = f a
from (f , g) (inr b) = g b
abstract
to-from : ∀ fg → to (from fg) == fg
to-from _ = idp
from-to : ∀ fg → from (to fg) == fg
from-to fg = λ= λ where (inl _) → idp
(inr _) → idp
|
{
"alphanum_fraction": 0.4950751685,
"avg_line_length": 33.0685714286,
"ext": "agda",
"hexsha": "78f9e16db0954ec35912ec51832db2bc0e153e2b",
"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/types/Coproduct.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "66f800adef943afdf08c17b8ecfba67340fead5e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "timjb/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Coproduct.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/types/Coproduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2782,
"size": 5787
}
|
module nat-to-string where
open import bool
open import char
open import eq
open import list
open import maybe
open import nat
open import nat-division
open import nat-thms
open import product
open import string
open import termination
ℕ-to-digitsh : (base : ℕ) → 1 < base ≡ tt → (x : ℕ) → ↓𝔹 _>_ x → 𝕃 ℕ
ℕ-to-digitsh _ _ 0 _ = []
ℕ-to-digitsh base bp (suc x) (pf↓ fx) with (suc x) ÷ base ! (<=ℕff2 base bp)
... | q , r , p , _ = r :: (ℕ-to-digitsh base bp q (fx (÷<{base}{q}{r}{x} bp p)))
ℕ-to-digits : ℕ → 𝕃 ℕ
ℕ-to-digits x = reverse (ℕ-to-digitsh 10 refl x (↓-> x))
digit-to-string : ℕ → string
digit-to-string 0 = "0"
digit-to-string 1 = "1"
digit-to-string 2 = "2"
digit-to-string 3 = "3"
digit-to-string 4 = "4"
digit-to-string 5 = "5"
digit-to-string 6 = "6"
digit-to-string 7 = "7"
digit-to-string 8 = "8"
digit-to-string 9 = "9"
digit-to-string _ = "unexpected-digit"
digits-to-string : 𝕃 ℕ → string
digits-to-string [] = ""
digits-to-string (d :: ds) = (digit-to-string d) ^ (digits-to-string ds)
ℕ-to-string : ℕ → string
ℕ-to-string 0 = "0"
ℕ-to-string (suc x) = digits-to-string (ℕ-to-digits (suc x))
string-to-digit : char → maybe ℕ
string-to-digit '0' = just 0
string-to-digit '1' = just 1
string-to-digit '2' = just 2
string-to-digit '3' = just 3
string-to-digit '4' = just 4
string-to-digit '5' = just 5
string-to-digit '6' = just 6
string-to-digit '7' = just 7
string-to-digit '8' = just 8
string-to-digit '9' = just 9
string-to-digit _ = nothing
-- the digits are in order from least to most significant
digits-to-ℕh : ℕ → ℕ → 𝕃 ℕ → ℕ
digits-to-ℕh multiplier sum [] = sum
digits-to-ℕh multiplier sum (x :: xs) = digits-to-ℕh (10 * multiplier) (x * multiplier + sum) xs
digits-to-ℕ : 𝕃 ℕ → ℕ
digits-to-ℕ digits = digits-to-ℕh 1 0 digits
string-to-ℕ : string → maybe ℕ
string-to-ℕ s with 𝕃maybe-map string-to-digit (reverse (string-to-𝕃char s))
... | nothing = nothing
... | just ds = just (digits-to-ℕ ds)
|
{
"alphanum_fraction": 0.650129199,
"avg_line_length": 28.0434782609,
"ext": "agda",
"hexsha": "db05bf422ebdaf27a13686a7d65a1762322ef5cc",
"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": "nat-to-string.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "b33c6a59d664aed46cac8ef77d34313e148fecc2",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "heades/AUGL",
"max_issues_repo_path": "nat-to-string.agda",
"max_line_length": 96,
"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": "nat-to-string.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 697,
"size": 1935
}
|
{-# OPTIONS --type-in-type #-}
module Compilation.Encode.Examples where
open import Context
open import Type.Core
open import Compilation.Data
open import Compilation.Encode.Core
open import Function
open import Data.Product
open import Data.List.Base
module ProdTreeTreeExample where
open ProdTreeTree
open prodTreeTree
ProdTreeTree′ = ⟦ prodTreeTree ⟧ᵈ
ProdTree′ : Set -> Set -> Set
ProdTree′ with ProdTreeTree′
... | ø ▶ PT′ ▶ T′ = PT′
Tree′ : Set -> Set
Tree′ with ProdTreeTree′
... | ø ▶ PT′ ▶ T′ = T′
mutual
fromProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree A B -> ProdTree′ A′ B′
fromProdTree f g (Prod tree) =
Wrap λ R h -> h $ fromTree (λ{ (x , y) _ k -> k (f x) (g y) }) tree
fromTree : ∀ {A A′} -> (A -> A′) -> Tree A -> Tree′ A′
fromTree f (Leaf x) = Wrap λ R g h -> g $ f x
fromTree f (Fork prod) = Wrap λ R g h -> h $ fromProdTree f f prod
{-# TERMINATING #-}
mutual
toProdTree : ∀ {A B A′ B′} -> (A -> A′) -> (B -> B′) -> ProdTree′ A B -> ProdTree A′ B′
toProdTree f g (Wrap k) =
k _ λ tree -> Prod $ toTree (λ k -> k _ λ x y -> f x , g y) tree
toTree : ∀ {A A′} -> (A -> A′) -> Tree′ A -> Tree A′
toTree f (Wrap k) = k _ (Leaf ∘ f) (Fork ∘ toProdTree f f)
module ListExample where
list : Data⁺ (ε ▻ (ε ▻ ⋆))
list
= PackData
$ ø
▶ ( endᶜ
∷ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ
∷ []
)
List′ : Set -> Set
List′ with ⟦ list ⟧ᵈ
... | ø ▶ L′ = L′
fromList : ∀ {A} -> List A -> List′ A
fromList [] = Wrap λ R z f -> z
fromList (x ∷ xs) = Wrap λ R z f -> f x $ fromList xs
{-# TERMINATING #-}
toList : ∀ {A} -> List′ A -> List A
toList (Wrap k) = k _ [] λ x xs -> x ∷ toList xs
module InterListExample where
data InterList (A B : Set) : Set where
InterNil : InterList A B
InterCons : A -> B -> InterList B A -> InterList A B
interlist : Data⁺ (ε ▻ (ε ▻ ⋆ ▻ ⋆))
interlist
= PackData
$ ø
▶ ( endᶜ
∷ Var (vs vz) ⇒ᶜ Var vz ⇒ᶜ Var (vs vs vz) ∙ Var vz ∙ Var (vs vz) ⇒ᶜ endᶜ
∷ []
)
InterList′ : Set -> Set -> Set
InterList′ with ⟦ interlist ⟧ᵈ
... | ø ▶ IL′ = IL′
fromInterList : ∀ {A B} -> InterList A B -> InterList′ A B
fromInterList InterNil = Wrap λ R z f -> z
fromInterList (InterCons x y yxs) = Wrap λ R z f -> f x y $ fromInterList yxs
{-# TERMINATING #-}
toInterList : ∀ {A B} -> InterList′ A B -> InterList A B
toInterList (Wrap k) = k _ InterNil λ x y yxs -> InterCons x y $ toInterList yxs
module TreeForestExample where
mutual
data Tree (A : Set) : Set where
node : A -> Forest A -> Tree A
data Forest (A : Set) : Set where
nil : Forest A
cons : Tree A -> Forest A -> Forest A
treeForest : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ (ε ▻ ⋆))
treeForest
= PackData
$ ø
▶ ( Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ
∷ []
)
▶ ( endᶜ
∷ Var (vs vs vz) ∙ Var vz ⇒ᶜ Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ
∷ []
)
TreeForest′ = ⟦ treeForest ⟧ᵈ
Tree′ : Set -> Set
Tree′ with TreeForest′
... | ø ▶ T′ ▶ F′ = T′
Forest′ : Set -> Set
Forest′ with TreeForest′
... | ø ▶ T′ ▶ F′ = F′
mutual
fromTree : ∀ {A} -> Tree A -> Tree′ A
fromTree (node x forest) = Wrap λ R f -> f x $ fromForest forest
fromForest : ∀ {A} -> Forest A -> Forest′ A
fromForest nil = Wrap λ R z f -> z
fromForest (cons tree forest) = Wrap λ R z f -> f (fromTree tree) (fromForest forest)
{-# TERMINATING #-}
mutual
toTree : ∀ {A} -> Tree′ A -> Tree A
toTree (Wrap k) = k _ λ x forest -> node x $ toForest forest
toForest : ∀ {A} -> Forest′ A -> Forest A
toForest (Wrap k) = k _ nil λ tree forest -> cons (toTree tree) (toForest forest)
module MNExample where
mutual
data M (A : Set) : Set where
p : A -> M A
n : N -> M A
data N : Set where
m : M N -> N
mn : Data⁺ (ε ▻ (ε ▻ ⋆) ▻ ε)
mn
= PackData
$ ø
▶ ( Var vz ⇒ᶜ endᶜ
∷ Var (vs vz) ⇒ᶜ endᶜ
∷ []
)
▶ ( Var (vs vz) ∙ Var vz ⇒ᶜ endᶜ
∷ []
)
MN′ = ⟦ mn ⟧ᵈ
M′ : Set -> Set
M′ with MN′
... | ø ▶ M′ ▶ N′ = M′
N′ : Set
N′ with MN′
... | ø ▶ M′ ▶ N′ = N′
{-# TERMINATING #-}
mutual
fromM : ∀ {A B} -> (A -> B) -> M A -> M′ B
fromM f (p x) = Wrap λ R g h -> g $ f x
fromM f (n x) = Wrap λ R g h -> h $ fromN x
fromN : N -> N′
fromN (m x) = Wrap λ R f -> f $ fromM fromN x
{-# TERMINATING #-}
mutual
toM : ∀ {A B} -> (A -> B) -> M′ A -> M B
toM f (Wrap k) = k _ (λ x -> p (f x)) (λ x -> n (toN x))
toN : N′ -> N
toN (Wrap k) = k _ λ x -> m (toM toN x)
|
{
"alphanum_fraction": 0.5086556957,
"avg_line_length": 24.8882978723,
"ext": "agda",
"hexsha": "9a11f5e406990bfe3a08d0c6f7c1eb10bd151fe0",
"lang": "Agda",
"max_forks_count": 399,
"max_forks_repo_forks_event_max_datetime": "2022-03-31T11:18:25.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-10-05T09:36:10.000Z",
"max_forks_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_forks_repo_licenses": [
"Apache-2.0"
],
"max_forks_repo_name": "AriFordsham/plutus",
"max_forks_repo_path": "papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda",
"max_issues_count": 2493,
"max_issues_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T15:31:31.000Z",
"max_issues_repo_issues_event_min_datetime": "2018-09-28T19:28:17.000Z",
"max_issues_repo_licenses": [
"Apache-2.0"
],
"max_issues_repo_name": "AriFordsham/plutus",
"max_issues_repo_path": "papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda",
"max_line_length": 93,
"max_stars_count": 1299,
"max_stars_repo_head_hexsha": "f7d34336cd3d65f62b0da084a16f741dc9156413",
"max_stars_repo_licenses": [
"Apache-2.0"
],
"max_stars_repo_name": "AriFordsham/plutus",
"max_stars_repo_path": "papers/unraveling-recursion/code/src/Compilation/Encode/Examples.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-28T01:10:02.000Z",
"max_stars_repo_stars_event_min_datetime": "2018-10-02T13:41:39.000Z",
"num_tokens": 1848,
"size": 4679
}
|
module FFI.Data.Bool where
{-# FOREIGN GHC import qualified Data.Bool #-}
data Bool : Set where
false : Bool
true : Bool
{-# COMPILE GHC Bool = data Data.Bool.Bool (Data.Bool.False|Data.Bool.True) #-}
|
{
"alphanum_fraction": 0.690821256,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "4b04b0339c0950d9864beeaad9f90327100591a9",
"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": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "FreakingBarbarians/luau",
"max_forks_repo_path": "prototyping/FFI/Data/Bool.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "5187e64f88953f34785ffe58acd0610ee5041f5f",
"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": "FreakingBarbarians/luau",
"max_issues_repo_path": "prototyping/FFI/Data/Bool.agda",
"max_line_length": 79,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "cd18adc20ecb805b8eeb770a9e5ef8e0cd123734",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Tr4shh/Roblox-Luau",
"max_stars_repo_path": "prototyping/FFI/Data/Bool.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-11T21:30:17.000Z",
"max_stars_repo_stars_event_min_datetime": "2022-02-11T21:30:17.000Z",
"num_tokens": 51,
"size": 207
}
|
module test where
|
{
"alphanum_fraction": 0.8333333333,
"avg_line_length": 9,
"ext": "agda",
"hexsha": "b27246cacf819429f33043126f3a010afdf20a73",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test.agda",
"max_line_length": 17,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 4,
"size": 18
}
|
module Data.Either.Equiv where
import Lvl
open import Data.Either as Either
open import Structure.Function.Domain
open import Structure.Function
open import Structure.Operator
open import Structure.Setoid
open import Type
private variable ℓ ℓₑ ℓₑ₁ ℓₑ₂ : Lvl.Level
private variable A B : Type{ℓ}
record Extensionality ⦃ equiv-A : Equiv{ℓₑ₁}(A) ⦄ ⦃ equiv-B : Equiv{ℓₑ₂}(B) ⦄ (equiv : Equiv{ℓₑ}(A ‖ B)) : Type{Lvl.of(A) Lvl.⊔ Lvl.of(B) Lvl.⊔ ℓₑ₁ Lvl.⊔ ℓₑ₂ Lvl.⊔ ℓₑ} where
constructor intro
private instance _ = equiv
field
⦃ Left-function ⦄ : Function Left
⦃ Right-function ⦄ : Function Right
⦃ Left-injective ⦄ : Injective Left
⦃ Right-injective ⦄ : Injective Right
Left-Right-inequality : ∀{x : A}{y : B} → (Left x ≢ Right y)
|
{
"alphanum_fraction": 0.6875,
"avg_line_length": 33.3913043478,
"ext": "agda",
"hexsha": "b4572dc7b1dcde98cf39b02ae61e0fccc441e7ca",
"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/Either/Equiv.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/Either/Equiv.agda",
"max_line_length": 173,
"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/Either/Equiv.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": 293,
"size": 768
}
|
{-# OPTIONS --without-K #-}
open import HoTT
open import homotopy.SuspProduct
open import homotopy.SuspSmash
open import homotopy.JoinSusp
open import cohomology.Theory
module cohomology.SphereProduct {i} (CT : CohomologyTheory i) where
open CohomologyTheory CT
open import cohomology.Wedge CT
module _ (n : ℤ) (m : ℕ) (X : Ptd i) where
private
space-path : ⊙Susp (⊙Lift {j = i} (⊙Sphere m) ⊙× X)
== ⊙Susp (⊙Lift (⊙Sphere m)) ⊙∨ (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)
space-path =
SuspProduct.⊙path (⊙Lift (⊙Sphere m)) X
∙ ap (λ Z → ⊙Susp (⊙Lift (⊙Sphere m)) ⊙∨ (⊙Susp X ⊙∨ Z))
(SuspSmash.⊙path (⊙Lift (⊙Sphere m)) X
∙ ⊙*-⊙Lift-⊙Sphere m X)
C-Sphere× : C n (⊙Lift {j = i} (⊙Sphere m) ⊙× X)
== C n (⊙Lift (⊙Sphere m)) ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X))
C-Sphere× =
! (group-ua (C-Susp n (⊙Lift {j = i} (⊙Sphere m) ⊙× X)))
∙ ap (C (succ n)) space-path
∙ CWedge.path (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) (⊙Susp X ⊙∨ ⊙Susp^ (S m) X)
∙ ap (λ H → C (succ n) (⊙Susp (⊙Lift (⊙Sphere m))) ×ᴳ H)
(CWedge.path (succ n) (⊙Susp X) (⊙Susp^ (S m) X)
∙ ap2 _×ᴳ_ (group-ua (C-Susp n X))
(group-ua (C-Susp n (⊙Susp^ m X))))
∙ ap (λ H → H ×ᴳ (C n X ×ᴳ C n (⊙Susp^ m X)))
(group-ua (C-Susp n (⊙Lift (⊙Sphere m))))
|
{
"alphanum_fraction": 0.5244544771,
"avg_line_length": 34.9736842105,
"ext": "agda",
"hexsha": "f9fc04be0ed30ba77fcbeb4f42cc241ee31fa18f",
"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/cohomology/SphereProduct.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/cohomology/SphereProduct.agda",
"max_line_length": 82,
"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/cohomology/SphereProduct.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 624,
"size": 1329
}
|
------------------------------------------------------------------------
-- A type soundness result
------------------------------------------------------------------------
module Lambda.Closure.Functional.Type-soundness where
import Category.Monad.Partiality as Partiality
open import Category.Monad.Partiality.All as All
using (All; now; later)
open import Codata.Musical.Notation
open import Data.Fin using (Fin; zero; suc)
open import Data.Maybe using (Maybe; just; nothing)
open import Data.Maybe.Relation.Unary.Any as Maybe using (just)
open import Data.Nat
open import Data.Vec using (Vec; []; _∷_; lookup)
open import Relation.Binary.PropositionalEquality using (_≡_)
open import Relation.Nullary
open All.Alternative
private
open module E {A : Set} = Partiality.Equality (_≡_ {A = A})
using (_≈_; now; laterˡ)
open import Lambda.Closure.Functional
open Lambda.Closure.Functional.PF using (fail)
open Lambda.Closure.Functional.Workaround using (⟪_⟫P)
open import Lambda.Syntax
open Lambda.Syntax.Closure Tm
-- WF-Value, WF-Env and WF-MV specify when a
-- value/environment/potential value is well-formed with respect to a
-- given context (and type).
mutual
data WF-Value : Ty → Value → Set where
con : ∀ {i} → WF-Value nat (con i)
ƛ : ∀ {n Γ σ τ} {t : Tm (1 + n)} {ρ}
(t∈ : ♭ σ ∷ Γ ⊢ t ∈ ♭ τ) (ρ-wf : WF-Env Γ ρ) →
WF-Value (σ ⇾ τ) (ƛ t ρ)
infixr 5 _∷_
data WF-Env : ∀ {n} → Ctxt n → Env n → Set where
[] : WF-Env [] []
_∷_ : ∀ {n} {Γ : Ctxt n} {ρ σ v}
(v-wf : WF-Value σ v) (ρ-wf : WF-Env Γ ρ) →
WF-Env (σ ∷ Γ) (v ∷ ρ)
WF-MV : Ty → Maybe Value → Set
WF-MV σ = Maybe.Any (WF-Value σ)
-- Variables pointing into a well-formed environment refer to
-- well-formed values.
lookup-wf : ∀ {n Γ ρ} (x : Fin n) → WF-Env Γ ρ →
WF-Value (lookup Γ x) (lookup ρ x)
lookup-wf zero (v-wf ∷ ρ-wf) = v-wf
lookup-wf (suc x) (v-wf ∷ ρ-wf) = lookup-wf x ρ-wf
-- If we can prove All (WF-MV σ) x, then x does not "go wrong".
does-not-go-wrong : ∀ {σ x} → All (WF-MV σ) x → ¬ x ≈ fail
does-not-go-wrong (now (just _)) (now ())
does-not-go-wrong (later x-wf) (laterˡ x↯) =
does-not-go-wrong (♭ x-wf) x↯
-- Well-typed programs do not "go wrong".
mutual
⟦⟧-wf : ∀ {n Γ} (t : Tm n) {σ} → Γ ⊢ t ∈ σ →
∀ {ρ} → WF-Env Γ ρ → AllP (WF-MV σ) (⟦ t ⟧ ρ)
⟦⟧-wf (con i) con ρ-wf = now (just con)
⟦⟧-wf (var x) var ρ-wf = now (just (lookup-wf x ρ-wf))
⟦⟧-wf (ƛ t) (ƛ t∈) ρ-wf = now (just (ƛ t∈ ρ-wf))
⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) {ρ} ρ-wf =
⟦ t₁ · t₂ ⟧ ρ ≅⟨ ·-comp t₁ t₂ ⟩P
⟦ t₁ ⟧ ρ ⟦·⟧ ⟦ t₂ ⟧ ρ ⟨ (⟦⟧-wf t₁ t₁∈ ρ-wf >>=-congP λ { .{_} (just f-wf) →
⟦⟧-wf t₂ t₂∈ ρ-wf >>=-congP λ { .{_} (just v-wf) →
∙-wf f-wf v-wf }}) ⟩P
∙-wf : ∀ {σ τ f v} →
WF-Value (σ ⇾ τ) f → WF-Value (♭ σ) v →
AllP (WF-MV (♭ τ)) ⟪ f ∙ v ⟫P
∙-wf (ƛ t₁∈ ρ₁-wf) v₂-wf = later (♯ ⟦⟧-wf _ t₁∈ (v₂-wf ∷ ρ₁-wf))
type-soundness : ∀ {t : Tm 0} {σ} → [] ⊢ t ∈ σ → ¬ ⟦ t ⟧ [] ≈ fail
type-soundness t∈ =
does-not-go-wrong (All.Alternative.sound (⟦⟧-wf _ t∈ []))
|
{
"alphanum_fraction": 0.5302648172,
"avg_line_length": 34.8571428571,
"ext": "agda",
"hexsha": "32a483cf7896676cfbb36280a58e1debec47fae1",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Closure/Functional/Type-soundness.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Lambda/Closure/Functional/Type-soundness.agda",
"max_line_length": 81,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Closure/Functional/Type-soundness.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1248,
"size": 3172
}
|
{-# OPTIONS --no-termination-check #-}
-- Testing how the pragmas are saved in the agda interface files (using
-- the program dump-agdai).
-- 13 July 2012. Because for example the --no-termination-check is a
-- PragmaOption it is saved as:
--
-- iPragmaOptions = [["--no-termination-check"]]
module OptionPragma where
|
{
"alphanum_fraction": 0.7133956386,
"avg_line_length": 26.75,
"ext": "agda",
"hexsha": "3d3369edfd6b96bd62c1798a3b9a4f7acf497ebb",
"lang": "Agda",
"max_forks_count": 4,
"max_forks_repo_forks_event_max_datetime": "2016-08-03T03:54:55.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-05-10T23:06:19.000Z",
"max_forks_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/apia",
"max_forks_repo_path": "notes/agda-interface/OptionPragma.agda",
"max_issues_count": 121,
"max_issues_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_issues_repo_issues_event_max_datetime": "2018-04-22T06:01:44.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-25T13:22:12.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/apia",
"max_issues_repo_path": "notes/agda-interface/OptionPragma.agda",
"max_line_length": 71,
"max_stars_count": 10,
"max_stars_repo_head_hexsha": "a66c5ddca2ab470539fd68c42c4fbd45f720d682",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/apia",
"max_stars_repo_path": "notes/agda-interface/OptionPragma.agda",
"max_stars_repo_stars_event_max_datetime": "2019-12-03T13:44:25.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:54:16.000Z",
"num_tokens": 81,
"size": 321
}
|
F : (A A : Set) → Set
F A _ = A
|
{
"alphanum_fraction": 0.3939393939,
"avg_line_length": 8.25,
"ext": "agda",
"hexsha": "da80f82800e3f736b61056fda3bca5cb4c9b002e",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_forks_repo_licenses": [
"BSD-2-Clause"
],
"max_forks_repo_name": "cagix/agda",
"max_forks_repo_path": "test/interaction/Issue5250/Issue5250.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"BSD-2-Clause"
],
"max_issues_repo_name": "cagix/agda",
"max_issues_repo_path": "test/interaction/Issue5250/Issue5250.agda",
"max_line_length": 21,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "cc026a6a97a3e517bb94bafa9d49233b067c7559",
"max_stars_repo_licenses": [
"BSD-2-Clause"
],
"max_stars_repo_name": "cagix/agda",
"max_stars_repo_path": "test/interaction/Issue5250/Issue5250.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": 18,
"size": 33
}
|
-- Andreas, 2020-02-10, issue 4429, reported by Nisse
--
-- Injectivity analysis can make type checker loop (or slow down)
-- since it reduces the rhs of definitions.
--
-- Try to be smarter and do not needlessly invoke the injectivity
-- analysis. For instance, do not consider a projection pattern
-- a proper match for the sake of injectivity, since a metavariable
-- cannot occupy its position (unlike for constructor and literal patterns).
-- {-# OPTIONS -v tc.inj.check:45 #-}
record _⇔_ (A B : Set) : Set where
field
to : A → B
from : B → A
postulate
A : Set
{-# TERMINATING #-}
to : A → A
to = to -- An approximation of slow but terminating code.
{-# TERMINATING #-}
from : A → A
from = from -- An approximation of slow but terminating code.
works : A ⇔ A
works = record
{ to = to
; from = from
}
test : A ⇔ A
test ._⇔_.to = to
test ._⇔_.from = from
-- WAS: Definition by copatterns loops, because the injectivity
-- checker tries to reduce the rhs.
-- Should pass, since now injectivity checker does not consider
-- a projection pattern as proper match.
-- Thus, injectivity for this function would be pointless.
|
{
"alphanum_fraction": 0.6853448276,
"avg_line_length": 24.6808510638,
"ext": "agda",
"hexsha": "db0c7827969cd7453e62983e0e53131992178ca3",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "shlevy/agda",
"max_forks_repo_path": "test/Succeed/Issue4429Injectivity.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/Issue4429Injectivity.agda",
"max_line_length": 76,
"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/Issue4429Injectivity.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": 316,
"size": 1160
}
|
-- Andreas, 2014-05-22
module _ where
module M where
f : Set
f = f
module N where
f : Set
f = f
-- OUTPUT IS:
--
-- Termination checking failed for the following functions:
-- f, f
-- Problematic calls:
-- f (at /home/abel/tmp/bla/Agda/test/bugs/TerminationReportQualified.agda:7,7-8)
-- f (at /home/abel/tmp/bla/Agda/test/bugs/TerminationReportQualified.agda:11,7-8)
-- Expected: Qualified names M.f and N.f
|
{
"alphanum_fraction": 0.6822429907,
"avg_line_length": 19.4545454545,
"ext": "agda",
"hexsha": "a6cbffe88d11c7a4e94818a7b0a6edbbbca29685",
"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/Issue1140.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/Issue1140.agda",
"max_line_length": 84,
"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/Issue1140.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": 144,
"size": 428
}
|
{-# OPTIONS --cubical #-}
module Cubical.Codata.Stream where
open import Cubical.Codata.Stream.Base public
open import Cubical.Codata.Stream.Properties public
|
{
"alphanum_fraction": 0.7950310559,
"avg_line_length": 23,
"ext": "agda",
"hexsha": "0e22ce71af8b408961e50544a8b0bc9c35d41438",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "limemloh/cubical",
"max_forks_repo_path": "Cubical/Codata/Stream.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "limemloh/cubical",
"max_issues_repo_path": "Cubical/Codata/Stream.agda",
"max_line_length": 51,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "df4ef7edffd1c1deb3d4ff342c7178e9901c44f1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "limemloh/cubical",
"max_stars_repo_path": "Cubical/Codata/Stream.agda",
"max_stars_repo_stars_event_max_datetime": "2020-03-23T23:52:11.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-03-23T23:52:11.000Z",
"num_tokens": 35,
"size": 161
}
|
open import Agda.Builtin.Nat
data D : Set where
c : D → D
record R : Set where
constructor mkR
field f : Nat
f : D → R
f (c x) = mkR zero
f' : D → Nat → R
f' (c x) n = mkR n
postulate
P : (A : Set) → A → Set
g : (x : D) → P R (f x) → P D x
g' : (n : Nat) (x : D) → P R (f' x n) → P D x
h : (x : D) → P R (mkR zero) → P D (c x)
h x = g _
h' : (n : Nat) (x : D) → P R (mkR n) → P D (c x)
h' n x = g' n _
|
{
"alphanum_fraction": 0.4504716981,
"avg_line_length": 15.7037037037,
"ext": "agda",
"hexsha": "95c5e3d970f51be2ff500335c82796ef22a57c7e",
"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/Issue2944.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/Issue2944.agda",
"max_line_length": 48,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "ed8ac6f4062ea8a20fa0f62d5db82d4e68278338",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "shlevy/agda",
"max_stars_repo_path": "test/Succeed/Issue2944.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": 207,
"size": 424
}
|
------------------------------------------------------------------------
-- Functional semantics and type soundness proof for an untyped
-- λ-calculus with constants
------------------------------------------------------------------------
module Lambda.Substitution.Functional where
open import Category.Monad.Partiality as Partiality using (_⊥; never)
open import Category.Monad.Partiality.All as All
using (All; now; later)
open import Codata.Musical.Notation
open import Data.Maybe as Maybe using (Maybe)
open import Data.Maybe.Relation.Unary.Any as Maybe using (just)
open import Data.Vec using ([])
open import Relation.Binary.PropositionalEquality as P using (_≡_)
open import Relation.Nullary
open All.Alternative
private
open module E {A : Set} = Partiality.Equality (_≡_ {A = A})
open module R {A : Set} =
Partiality.Reasoning (P.isEquivalence {A = A})
open import Lambda.Syntax
open WHNF
open import Lambda.Substitution
open import Lambda.Closure.Functional
using (module PF; module Workaround)
open Workaround hiding (_>>=_)
------------------------------------------------------------------------
-- Semantics
infix 5 _∙_
-- Note that this definition gives us determinism "for free".
mutual
⟦_⟧′ : Tm 0 → Maybe (Value 0) ⊥P
⟦ con i ⟧′ = return (con i)
⟦ var () ⟧′
⟦ ƛ t ⟧′ = return (ƛ t)
⟦ t₁ · t₂ ⟧′ = ⟦ t₁ ⟧′ >>= λ v₁ →
⟦ t₂ ⟧′ >>= λ v₂ →
v₁ ∙ v₂
where open Workaround
_∙_ : Value 0 → Value 0 → Maybe (Value 0) ⊥P
con i ∙ v₂ = fail
ƛ t₁ ∙ v₂ = later (♯ ⟦ t₁ / sub ⌜ v₂ ⌝ ⟧′)
⟦_⟧ : Tm 0 → Maybe (Value 0) ⊥
⟦ t ⟧ = ⟪ ⟦ t ⟧′ ⟫P
------------------------------------------------------------------------
-- Example
Ω-loops : ⟦ Ω ⟧ ≈ never
Ω-loops = later (♯ Ω-loops)
------------------------------------------------------------------------
-- Some lemmas
open PF hiding (_>>=_)
-- An abbreviation.
infix 5 _⟦·⟧_
_⟦·⟧_ : Maybe (Value 0) ⊥ → Maybe (Value 0) ⊥ → Maybe (Value 0) ⊥
v₁ ⟦·⟧ v₂ = v₁ >>= λ v₁ → v₂ >>= λ v₂ → ⟪ v₁ ∙ v₂ ⟫P
where open PF
-- _⟦·⟧_ preserves equality.
_⟦·⟧-cong_ : ∀ {k v₁₁ v₁₂ v₂₁ v₂₂} →
Rel k v₁₁ v₂₁ → Rel k v₁₂ v₂₂ →
Rel k (v₁₁ ⟦·⟧ v₁₂) (v₂₁ ⟦·⟧ v₂₂)
v₁₁≈v₂₁ ⟦·⟧-cong v₁₂≈v₂₂ =
v₁₁≈v₂₁ >>=-cong λ v₁ →
v₁₂≈v₂₂ >>=-cong λ v₂ →
⟪ v₁ ∙ v₂ ⟫P ∎
-- The semantics of application is compositional (with respect to the
-- syntactic equality which is used).
·-comp : (t₁ t₂ : Tm 0) →
⟦ t₁ · t₂ ⟧ ≅ ⟦ t₁ ⟧ ⟦·⟧ ⟦ t₂ ⟧
·-comp t₁ t₂ =
⟦ t₁ · t₂ ⟧ ≅⟨ >>=-hom ⟦ t₁ ⟧′ _ ⟩
PF._>>=_ ⟦ t₁ ⟧ (λ v₁ →
⟪ Workaround._>>=_ ⟦ t₂ ⟧′ (λ v₂ →
v₁ ∙ v₂) ⟫P) ≅⟨ ((⟦ t₁ ⟧ ∎) >>=-cong λ _ →
>>=-hom ⟦ t₂ ⟧′ _) ⟩
⟦ t₁ ⟧ ⟦·⟧ ⟦ t₂ ⟧ ∎
------------------------------------------------------------------------
-- Type soundness
-- WF-Value and WF-MV specify when a (potential) value is well-formed
-- with respect to a given type.
WF-Value : Ty → Value 0 → Set
WF-Value σ v = [] ⊢ ⌜ v ⌝ ∈ σ
WF-MV : Ty → Maybe (Value 0) → Set
WF-MV σ = Maybe.Any (WF-Value σ)
-- If we can prove All (WF-MV σ) x, then x does not "go wrong".
does-not-go-wrong : ∀ {σ x} → All (WF-MV σ) x → ¬ x ≈ PF.fail
does-not-go-wrong (now (just _)) (now ())
does-not-go-wrong (later x-wf) (laterˡ x↯) =
does-not-go-wrong (♭ x-wf) x↯
-- Well-typed programs do not "go wrong".
mutual
⟦⟧-wf : ∀ (t : Tm 0) {σ} → [] ⊢ t ∈ σ →
AllP (WF-MV σ) ⟦ t ⟧
⟦⟧-wf (con i) con = now (just con)
⟦⟧-wf (var ()) var
⟦⟧-wf (ƛ t) (ƛ t∈) = now (just (ƛ t∈))
⟦⟧-wf (t₁ · t₂) (t₁∈ · t₂∈) =
⟦ t₁ · t₂ ⟧ ≅⟨ ·-comp t₁ t₂ ⟩P
⟦ t₁ ⟧ ⟦·⟧ ⟦ t₂ ⟧ ⟨ (⟦⟧-wf t₁ t₁∈ >>=-congP λ { .{_} (just f-wf) →
⟦⟧-wf t₂ t₂∈ >>=-congP λ { .{_} (just v-wf) →
∙-wf f-wf v-wf }}) ⟩P
∙-wf : ∀ {σ τ f v} →
WF-Value (σ ⇾ τ) f → WF-Value (♭ σ) v →
AllP (WF-MV (♭ τ)) ⟪ f ∙ v ⟫P
∙-wf {f = con _} () _
∙-wf {f = ƛ t₁} (ƛ t₁∈) v₂∈ =
later (♯ ⟦⟧-wf _ (/-preserves t₁∈ (sub-preserves v₂∈)))
type-soundness : ∀ {t σ} → [] ⊢ t ∈ σ → ¬ ⟦ t ⟧ ≈ PF.fail
type-soundness t∈ =
does-not-go-wrong (All.Alternative.sound (⟦⟧-wf _ t∈))
|
{
"alphanum_fraction": 0.4650675361,
"avg_line_length": 30.027972028,
"ext": "agda",
"hexsha": "e4b368a3b4ca7a5e4a2bd586f30aa8d7af045258",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/codata",
"max_forks_repo_path": "Lambda/Substitution/Functional.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/codata",
"max_issues_repo_path": "Lambda/Substitution/Functional.agda",
"max_line_length": 76,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "1b90445566df0d3b4ba6e31bd0bac417b4c0eb0e",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/codata",
"max_stars_repo_path": "Lambda/Substitution/Functional.agda",
"max_stars_repo_stars_event_max_datetime": "2021-02-13T14:48:45.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-02-13T14:48:45.000Z",
"num_tokens": 1670,
"size": 4294
}
|
{-# OPTIONS --without-K --safe #-}
module Cham.Name where
open import Data.String
Name : Set
Name = String
|
{
"alphanum_fraction": 0.6818181818,
"avg_line_length": 12.2222222222,
"ext": "agda",
"hexsha": "fb62ebea2bf70d9cfd2e34c790a0654d814cea12",
"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": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "riz0id/chemical-abstract-machine",
"max_forks_repo_path": "agda/Cham/Name.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"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": "riz0id/chemical-abstract-machine",
"max_issues_repo_path": "agda/Cham/Name.agda",
"max_line_length": 34,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "292023fc36fa67ca4a81cff9a875a325a79b9d6f",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "riz0id/chemical-abstract-machine",
"max_stars_repo_path": "agda/Cham/Name.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 26,
"size": 110
}
|
------------------------------------------------------------------------------
-- Axiomatic PA properties
------------------------------------------------------------------------------
{-# OPTIONS --exact-split #-}
{-# OPTIONS --no-sized-types #-}
{-# OPTIONS --no-universe-polymorphism #-}
{-# OPTIONS --without-K #-}
module PA.Axiomatic.Mendelson.PropertiesI where
open import PA.Axiomatic.Mendelson.Base
open import PA.Axiomatic.Mendelson.Relation.Binary.EqReasoning
open import PA.Axiomatic.Mendelson.Relation.Binary.PropositionalEqualityI
using ( ≈-sym )
------------------------------------------------------------------------------
succCong : ∀ {m n} → m ≈ n → succ m ≈ succ n
succCong = S₂
+-leftIdentity : ∀ n → zero + n ≈ n
+-leftIdentity = S₅
+-rightIdentity : ∀ n → n + zero ≈ n
+-rightIdentity = S₉ A A0 is
where
A : ℕ → Set
A i = i + zero ≈ i
A0 : A zero
A0 = +-leftIdentity zero
is : ∀ i → A i → A (succ i)
is i ih = succ i + zero ≈⟨ S₆ i zero ⟩
succ (i + zero) ≈⟨ S₂ ih ⟩
succ i ∎
x+Sy≈S[x+y] : ∀ m n → m + succ n ≈ succ (m + n)
x+Sy≈S[x+y] m n = S₉ A A0 is m
where
A : ℕ → Set
A i = i + succ n ≈ succ (i + n)
A0 : A zero
A0 = zero + succ n ≈⟨ +-leftIdentity (succ n) ⟩
succ n ≈⟨ S₂ (≈-sym (+-leftIdentity n)) ⟩
succ (zero + n) ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + succ n ≈⟨ S₆ i (succ n) ⟩
succ (i + succ n) ≈⟨ S₂ ih ⟩
succ (succ (i + n)) ≈⟨ S₂ (≈-sym (S₆ i n)) ⟩
succ (succ i + n) ∎
+-rightCong : ∀ {m n p} → n ≈ p → m + n ≈ m + p
+-rightCong {m} {n} {p} h = S₉ A A0 is m
where
A : ℕ → Set
A i = i + n ≈ i + p
A0 : A zero
A0 = zero + n ≈⟨ S₅ n ⟩
n ≈⟨ h ⟩
p ≈⟨ ≈-sym (S₅ p) ⟩
zero + p ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + n ≈⟨ S₆ i n ⟩
succ (i + n) ≈⟨ S₂ ih ⟩
succ (i + p) ≈⟨ ≈-sym (S₆ i p) ⟩
succ i + p ∎
+-leftCong : ∀ {m n p} → m ≈ n → m + p ≈ n + p
+-leftCong {m} {n} {p} h = S₉ A A0 is p
where
A : ℕ → Set
A i = m + i ≈ n + i
A0 : A zero
A0 = m + zero ≈⟨ +-rightIdentity m ⟩
m ≈⟨ h ⟩
n ≈⟨ ≈-sym (+-rightIdentity n) ⟩
n + zero ∎
is : ∀ i → A i → A (succ i)
is i ih = m + succ i ≈⟨ x+Sy≈S[x+y] m i ⟩
succ (m + i) ≈⟨ S₂ ih ⟩
succ (n + i) ≈⟨ ≈-sym (x+Sy≈S[x+y] n i) ⟩
n + succ i ∎
+-asocc : ∀ m n o → m + n + o ≈ m + (n + o)
+-asocc m n o = S₉ A A0 is m
where
A : ℕ → Set
A i = i + n + o ≈ i + (n + o)
A0 : A zero
A0 = zero + n + o ≈⟨ +-leftCong (+-leftIdentity n) ⟩
n + o ≈⟨ ≈-sym (+-leftIdentity (n + o)) ⟩
zero + (n + o) ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + n + o ≈⟨ +-leftCong (S₆ i n) ⟩
succ (i + n) + o ≈⟨ S₆ (i + n) o ⟩
succ (i + n + o) ≈⟨ S₂ ih ⟩
succ (i + (n + o)) ≈⟨ ≈-sym (S₆ i (n + o)) ⟩
succ i + (n + o) ∎
+-comm : ∀ m n → m + n ≈ n + m
+-comm m n = S₉ A A0 is m
where
A : ℕ → Set
A i = i + n ≈ n + i
A0 : A zero
A0 = zero + n ≈⟨ +-leftIdentity n ⟩
n ≈⟨ ≈-sym (+-rightIdentity n) ⟩
n + zero ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i + n ≈⟨ S₆ i n ⟩
succ (i + n) ≈⟨ S₂ ih ⟩
succ (n + i) ≈⟨ ≈-sym (x+Sy≈S[x+y] n i) ⟩
n + succ i ∎
*-leftZero : ∀ n → zero * n ≈ zero
*-leftZero = S₇
*-rightZero : ∀ n → n * zero ≈ zero
*-rightZero n = S₉ A A0 is n
where
A : ℕ → Set
A i = i * zero ≈ zero
A0 : A zero
A0 = *-leftZero zero
is : ∀ i → A i → A (succ i)
is i ih = succ i * zero ≈⟨ S₈ i zero ⟩
zero + i * zero ≈⟨ +-leftIdentity (i * zero) ⟩
i * zero ≈⟨ ih ⟩
zero ∎
x*Sy≈x+[x*y] : ∀ m n → m * succ n ≈ m + m * n
x*Sy≈x+[x*y] m n = S₉ A A0 is m
where
A : ℕ → Set
A i = i * succ n ≈ i + i * n
A0 : A zero
A0 = zero * succ n ≈⟨ *-leftZero (succ n) ⟩
zero ≈⟨ ≈-sym (S₅ zero) ⟩
zero + zero ≈⟨ +-rightCong (≈-sym (*-leftZero n)) ⟩
zero + zero * n ∎
is : ∀ i → A i → A (succ i)
is i ih =
succ i * succ n ≈⟨ S₈ i (succ n) ⟩
succ n + (i * succ n) ≈⟨ +-rightCong ih ⟩
succ n + (i + i * n) ≈⟨ S₆ n (i + i * n) ⟩
succ (n + (i + i * n)) ≈⟨ succCong (≈-sym (+-asocc n i (i * n))) ⟩
succ (n + i + (i * n)) ≈⟨ succCong (+-leftCong (+-comm n i)) ⟩
succ (i + n + (i * n)) ≈⟨ succCong (+-asocc i n (i * n)) ⟩
succ (i + (n + i * n)) ≈⟨ succCong (+-rightCong (≈-sym (S₈ i n))) ⟩
succ (i + succ i * n) ≈⟨ ≈-sym (S₆ i (succ i * n)) ⟩
succ i + succ i * n ∎
*-rightCong : ∀ {m n p} → n ≈ p → m * n ≈ m * p
*-rightCong {m} {n} {p} h = S₉ A A0 is m
where
A : ℕ → Set
A i = i * n ≈ i * p
A0 : A zero
A0 = zero * n ≈⟨ *-leftZero n ⟩
zero ≈⟨ ≈-sym (*-leftZero p) ⟩
zero * p ∎
is : ∀ i → A i → A (succ i)
is i ih = succ i * n ≈⟨ S₈ i n ⟩
n + i * n ≈⟨ +-rightCong ih ⟩
n + i * p ≈⟨ +-leftCong h ⟩
p + i * p ≈⟨ ≈-sym (S₈ i p) ⟩
succ i * p ∎
*-leftCong : ∀ {m n p} → m ≈ n → m * p ≈ n * p
*-leftCong {m} {n} {p} h = S₉ A A0 is p
where
A : ℕ → Set
A i = m * i ≈ n * i
A0 : A zero
A0 = m * zero ≈⟨ *-rightZero m ⟩
zero ≈⟨ ≈-sym (*-rightZero n) ⟩
n * zero ∎
is : ∀ i → A i → A (succ i)
is i ih = m * succ i ≈⟨ x*Sy≈x+[x*y] m i ⟩
m + m * i ≈⟨ +-leftCong h ⟩
n + m * i ≈⟨ +-rightCong ih ⟩
n + n * i ≈⟨ ≈-sym (x*Sy≈x+[x*y] n i) ⟩
n * succ i ∎
|
{
"alphanum_fraction": 0.3933298041,
"avg_line_length": 27.7794117647,
"ext": "agda",
"hexsha": "89e3ed3eaefe8fd801bc744bc49148865901a508",
"lang": "Agda",
"max_forks_count": 3,
"max_forks_repo_forks_event_max_datetime": "2018-03-14T08:50:00.000Z",
"max_forks_repo_forks_event_min_datetime": "2016-09-19T14:18:30.000Z",
"max_forks_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/fotc",
"max_forks_repo_path": "src/fot/PA/Axiomatic/Mendelson/PropertiesI.agda",
"max_issues_count": 2,
"max_issues_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_issues_repo_issues_event_max_datetime": "2017-01-01T14:34:26.000Z",
"max_issues_repo_issues_event_min_datetime": "2016-10-12T17:28:16.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "asr/fotc",
"max_issues_repo_path": "src/fot/PA/Axiomatic/Mendelson/PropertiesI.agda",
"max_line_length": 78,
"max_stars_count": 11,
"max_stars_repo_head_hexsha": "2fc9f2b81052a2e0822669f02036c5750371b72d",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/fotc",
"max_stars_repo_path": "src/fot/PA/Axiomatic/Mendelson/PropertiesI.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-12T16:09:54.000Z",
"max_stars_repo_stars_event_min_datetime": "2015-09-03T20:53:42.000Z",
"num_tokens": 2514,
"size": 5667
}
|
{-# OPTIONS --safe --warning=error --without-K #-}
open import LogicalFormulae
open import Groups.Lemmas
open import Groups.Definition
open import Setoids.Orders.Partial.Definition
open import Setoids.Orders.Total.Definition
open import Setoids.Setoids
open import Functions.Definition
open import Sets.EquivalenceRelations
open import Rings.Definition
open import Rings.Orders.Total.Definition
open import Rings.Orders.Partial.Definition
open import Numbers.Naturals.Semiring
open import Numbers.Naturals.Order
open import Orders.Total.Definition
open import Rings.IntegralDomains.Definition
module Rings.Orders.Total.Lemmas {n m p : _} {A : Set n} {S : Setoid {n} {m} A} {_+_ : A → A → A} {_*_ : A → A → A} {R : Ring S _+_ _*_} {_<_ : Rel {_} {p} A} {pOrder : SetoidPartialOrder S _<_} {pOrderRing : PartiallyOrderedRing R pOrder} (order : TotallyOrderedRing pOrderRing) where
open Ring R
open Group additiveGroup
open Setoid S
open SetoidPartialOrder pOrder
open TotallyOrderedRing order
open SetoidTotalOrder total
open PartiallyOrderedRing pOrderRing
open import Rings.Lemmas R
open import Rings.Orders.Partial.Lemmas pOrderRing
abstract
lemm2 : (a : A) → a < 0G → 0G < inverse a
lemm2 a a<0 with totality 0R (inverse a)
lemm2 a a<0 | inl (inl 0<-a) = 0<-a
lemm2 a a<0 | inl (inr -a<0) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder (<WellDefined (invLeft {a}) (identLeft {a}) (orderRespectsAddition -a<0 a)) a<0))
lemm2 a a<0 | inr 0=-a = exFalso (irreflexive {0G} (<WellDefined (Equivalence.transitive eq (Equivalence.symmetric eq identRight) t) (Equivalence.reflexive eq) a<0))
where
t : a + 0G ∼ 0G
t = Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) 0=-a) (invRight {a})
lemm2' : (a : A) → 0G < a → inverse a < 0G
lemm2' a 0<a with totality 0R (inverse a)
lemm2' a 0<a | inl (inl 0<-a) = exFalso (irreflexive {0G} (SetoidPartialOrder.<Transitive pOrder 0<a (<WellDefined (identLeft {a}) (invLeft {a}) (orderRespectsAddition 0<-a a))))
lemm2' a 0<a | inl (inr -a<0) = -a<0
lemm2' a 0<a | inr 0=-a = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (Equivalence.symmetric eq identRight) t) 0<a))
where
t : a + 0G ∼ 0G
t = Equivalence.transitive eq (+WellDefined (Equivalence.reflexive eq) 0=-a) (invRight {a})
ringMinusFlipsOrder : {x : A} → (Ring.0R R) < x → (Group.inverse (Ring.additiveGroup R) x) < (Ring.0R R)
ringMinusFlipsOrder {x = x} 0<x with totality (Ring.0R R) (Group.inverse (Ring.additiveGroup R) x)
ringMinusFlipsOrder {x} 0<x | inl (inl 0<inv) = exFalso (SetoidPartialOrder.irreflexive pOrder bad')
where
bad : (Group.0G (Ring.additiveGroup R) + Group.0G (Ring.additiveGroup R)) < (x + Group.inverse (Ring.additiveGroup R) x)
bad = ringAddInequalities 0<x 0<inv
bad' : (Group.0G (Ring.additiveGroup R)) < (Group.0G (Ring.additiveGroup R))
bad' = SetoidPartialOrder.<WellDefined pOrder (Group.identRight (Ring.additiveGroup R)) (Group.invRight (Ring.additiveGroup R)) bad
ringMinusFlipsOrder {x} 0<x | inl (inr inv<0) = inv<0
ringMinusFlipsOrder {x} 0<x | inr 0=inv = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (Equivalence.reflexive (Setoid.eq S)) (groupLemmaMove0G (Ring.additiveGroup R) 0=inv) 0<x))
ringMinusFlipsOrder' : {x : A} → (Group.inverse (Ring.additiveGroup R) x) < (Ring.0R R) → (Ring.0R R) < x
ringMinusFlipsOrder' {x} -x<0 with totality (Ring.0R R) x
ringMinusFlipsOrder' {x} -x<0 | inl (inl 0<x) = 0<x
ringMinusFlipsOrder' {x} -x<0 | inl (inr x<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (Group.invLeft (Ring.additiveGroup R)) (Group.identRight (Ring.additiveGroup R)) bad))
where
bad : ((Group.inverse (Ring.additiveGroup R) x) + x) < (Group.0G (Ring.additiveGroup R) + Group.0G (Ring.additiveGroup R))
bad = ringAddInequalities -x<0 x<0
ringMinusFlipsOrder' {x} -x<0 | inr 0=x = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (symmetric (groupLemmaMove0G' (Ring.additiveGroup R) (symmetric 0=x))) (Equivalence.reflexive (Setoid.eq S)) -x<0))
where
open Equivalence eq
ringMinusFlipsOrder'' : {x : A} → x < (Ring.0R R) → (Ring.0R R) < Group.inverse (Ring.additiveGroup R) x
ringMinusFlipsOrder'' {x} x<0 = ringMinusFlipsOrder' (SetoidPartialOrder.<WellDefined pOrder {x} {Group.inverse (Ring.additiveGroup R) (Group.inverse (Ring.additiveGroup R) x)} {Ring.0R R} {Ring.0R R} (Equivalence.symmetric (Setoid.eq S) (invInv (Ring.additiveGroup R))) (Equivalence.reflexive (Setoid.eq S)) x<0)
ringMinusFlipsOrder''' : {x : A} → (Ring.0R R) < (Group.inverse (Ring.additiveGroup R) x) → x < (Ring.0R R)
ringMinusFlipsOrder''' {x} 0<-x = SetoidPartialOrder.<WellDefined pOrder (invInv (Ring.additiveGroup R)) (Equivalence.reflexive (Setoid.eq S)) (ringMinusFlipsOrder 0<-x)
ringCanCancelPositive : {x y c : A} → (Ring.0R R) < c → (x * c) < (y * c) → x < y
ringCanCancelPositive {x} {y} {c} 0<c xc<yc = SetoidPartialOrder.<WellDefined pOrder (Group.identLeft additiveGroup) (Equivalence.transitive eq (symmetric (Group.+Associative additiveGroup)) (Equivalence.transitive eq (Group.+WellDefined additiveGroup reflexive (Group.invLeft additiveGroup)) (Group.identRight additiveGroup))) q''
where
open Equivalence (Setoid.eq S)
have : 0R < ((y * c) + (Group.inverse additiveGroup (x * c)))
have = SetoidPartialOrder.<WellDefined pOrder (Group.invRight additiveGroup) reflexive (orderRespectsAddition xc<yc (Group.inverse additiveGroup _))
p1 : 0R < ((y * c) + ((Group.inverse additiveGroup x) * c))
p1 = SetoidPartialOrder.<WellDefined pOrder reflexive (Group.+WellDefined additiveGroup reflexive (symmetric (Equivalence.transitive eq (*Commutative) (Equivalence.transitive eq ringMinusExtracts (inverseWellDefined additiveGroup *Commutative))))) have
q : 0R < ((y + Group.inverse additiveGroup x) * c)
q = SetoidPartialOrder.<WellDefined pOrder reflexive (Equivalence.transitive eq (Equivalence.transitive eq (Group.+WellDefined additiveGroup *Commutative *Commutative) (symmetric *DistributesOver+)) *Commutative) p1
q' : 0R < (y + Group.inverse additiveGroup x)
q' with totality 0R (y + Group.inverse additiveGroup x)
q' | inl (inl pr) = pr
q' | inl (inr y-x<0) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder reflexive (Equivalence.transitive eq *Commutative (Ring.timesZero R)) k))
where
f : ((y + inverse x) + (inverse (y + inverse x))) < (0G + inverse (y + inverse x))
f = orderRespectsAddition y-x<0 _
g : 0G < inverse (y + inverse x)
g = SetoidPartialOrder.<WellDefined pOrder invRight identLeft f
h : (0G * c) < ((inverse (y + inverse x)) * c)
h = ringCanMultiplyByPositive 0<c g
i : (0R + (0G * c)) < (((y + inverse x) * c) + ((inverse (y + inverse x)) * c))
i = ringAddInequalities q h
j : 0R < (((y + inverse x) + (inverse (y + inverse x))) * c)
j = SetoidPartialOrder.<WellDefined pOrder (Equivalence.transitive eq identLeft (Equivalence.transitive eq *Commutative (Ring.timesZero R))) (symmetric (Equivalence.transitive eq *Commutative (Equivalence.transitive eq *DistributesOver+ (Group.+WellDefined additiveGroup *Commutative *Commutative)))) i
k : 0R < (0R * c)
k = SetoidPartialOrder.<WellDefined pOrder reflexive (*WellDefined invRight reflexive) j
q' | inr 0=y-x = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (*WellDefined x=y reflexive) reflexive xc<yc))
where
f : inverse 0G ∼ inverse (y + inverse x)
f = inverseWellDefined additiveGroup 0=y-x
g : 0G ∼ (inverse y) + x
g = Equivalence.transitive eq (symmetric (invIdent additiveGroup)) (Equivalence.transitive eq f (Equivalence.transitive eq (Equivalence.transitive eq (invContravariant additiveGroup) groupIsAbelian) (+WellDefined reflexive (invInv additiveGroup))))
x=y : x ∼ y
x=y = transferToRight additiveGroup (symmetric (Equivalence.transitive eq g groupIsAbelian))
q'' : (0R + x) < ((y + Group.inverse additiveGroup x) + x)
q'' = orderRespectsAddition q' x
ringCanCancelNegative : {x y c : A} → c < (Ring.0R R) → (x * c) < (y * c) → y < x
ringCanCancelNegative {x} {y} {c} c<0 xc<yc = r
where
open Equivalence eq
p0 : 0R < ((y * c) + inverse (x * c))
p0 = SetoidPartialOrder.<WellDefined pOrder invRight reflexive (orderRespectsAddition xc<yc (inverse (x * c)))
p1 : 0R < ((y * c) + ((inverse x) * c))
p1 = SetoidPartialOrder.<WellDefined pOrder reflexive (Group.+WellDefined additiveGroup reflexive (Equivalence.transitive eq (inverseWellDefined additiveGroup *Commutative) (Equivalence.transitive eq (symmetric ringMinusExtracts) *Commutative))) p0
p2 : 0R < ((y + inverse x) * c)
p2 = SetoidPartialOrder.<WellDefined pOrder reflexive (Equivalence.transitive eq (Group.+WellDefined additiveGroup *Commutative *Commutative) (Equivalence.transitive eq (symmetric *DistributesOver+) *Commutative)) p1
q : (y + inverse x) < 0R
q with totality 0R (y + inverse x)
q | inl (inl pr) = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<Transitive pOrder bad c<0))
where
bad : 0R < c
bad = ringCanCancelPositive pr (SetoidPartialOrder.<WellDefined pOrder (symmetric (Equivalence.transitive eq *Commutative (Ring.timesZero R))) *Commutative p2)
q | inl (inr pr) = pr
q | inr 0=y-x = exFalso (SetoidPartialOrder.irreflexive pOrder (SetoidPartialOrder.<WellDefined pOrder (*WellDefined x=y reflexive) reflexive xc<yc))
where
x=y : x ∼ y
x=y = Equivalence.transitive eq (symmetric identLeft) (Equivalence.transitive eq (Group.+WellDefined additiveGroup 0=y-x reflexive) (Equivalence.transitive eq (symmetric (Group.+Associative additiveGroup)) (Equivalence.transitive eq (Group.+WellDefined additiveGroup reflexive invLeft) identRight)))
r : y < x
r = SetoidPartialOrder.<WellDefined pOrder (Equivalence.transitive eq (symmetric (Group.+Associative additiveGroup)) (Equivalence.transitive eq (Group.+WellDefined additiveGroup reflexive (invLeft)) identRight)) (Group.identLeft additiveGroup) (orderRespectsAddition q x)
posTimesNeg : (a b : A) → (0G < a) → (b < 0G) → (a * b) < 0G
posTimesNeg a b 0<a b<0 with orderRespectsMultiplication 0<a (lemm2 _ b<0)
... | bl = <WellDefined (invTwice additiveGroup _) (Equivalence.reflexive eq) (lemm2' _ (<WellDefined (Equivalence.reflexive eq) ringMinusExtracts bl))
negTimesPos : (a b : A) → (a < 0G) → (b < 0G) → 0G < (a * b)
negTimesPos a b a<0 b<0 with orderRespectsMultiplication (lemm2 _ a<0) (lemm2 _ b<0)
... | bl = <WellDefined (Equivalence.reflexive eq) twoNegativesTimes bl
halvePositive : (a : A) → 0R < (a + a) → 0R < a
halvePositive a 0<2a with totality 0R a
halvePositive a 0<2a | inl (inl x) = x
halvePositive a 0<2a | inl (inr a<0) = exFalso (irreflexive {a + a} (SetoidPartialOrder.<Transitive pOrder (<WellDefined (Equivalence.reflexive eq) identRight (ringAddInequalities a<0 a<0)) 0<2a))
halvePositive a 0<2a | inr x = exFalso (irreflexive {0G} (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (+WellDefined (Equivalence.symmetric eq x) (Equivalence.symmetric eq x)) identRight) 0<2a))
halvePositive' : {a b : A} → (a + a) ∼ b → 0R < b → 0R < a
halvePositive' {a} {b} pr 0<b = halvePositive a (<WellDefined (Equivalence.reflexive eq) (Equivalence.symmetric eq pr) 0<b)
0<1 : (0R ∼ 1R → False) → 0R < 1R
0<1 0!=1 with totality 0R 1R
0<1 0!=1 | inl (inl x) = x
0<1 0!=1 | inl (inr x) = <WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq twoNegativesTimes identIsIdent) (orderRespectsMultiplication (lemm2 1R x) (lemm2 1R x))
0<1 0!=1 | inr x = exFalso (0!=1 x)
1<0False : (1R < 0R) → False
1<0False 1<0 with orderRespectsMultiplication (lemm2 _ 1<0) (lemm2 _ 1<0)
... | bl = exFalso (irreflexive (SetoidPartialOrder.<Transitive pOrder 1<0 (<WellDefined (Equivalence.reflexive eq) (Equivalence.transitive eq (twoNegativesTimes) identIsIdent) bl)))
orderedImpliesCharNot2 : (0R ∼ 1R → False) → 1R + 1R ∼ 0R → False
orderedImpliesCharNot2 0!=1 x = irreflexive (<WellDefined (identRight {0R}) x (ringAddInequalities (0<1 0!=1) (0<1 0!=1)))
open import Rings.InitialRing R
open Equivalence eq
fromNPreservesOrder' : (0R ∼ 1R → False) → {a b : ℕ} → (fromN a) < (fromN b) → a <N b
fromNPreservesOrder' nontrivial {a} {b} a<b with TotalOrder.totality ℕTotalOrder a b
... | inl (inl x) = x
... | inl (inr x) = exFalso (irreflexive (<Transitive a<b (fromNPreservesOrder (0<1 nontrivial) x)))
... | inr x = exFalso (irreflexive (<WellDefined (fromNWellDefined x) reflexive a<b))
reciprocalPositive : (a b : A) → .(0<a : 0R < a) → (a * b ∼ 1R) → 0R < b
reciprocalPositive a 1/a 0<a ab=1 with totality 0G 1/a
... | inl (inl x) = x
... | inl (inr x) = exFalso (1<0False (<WellDefined (transitive *Commutative ab=1) timesZero' (ringCanMultiplyByPositive 0<a x)))
... | inr x = exFalso (anyComparisonImpliesNontrivial 0<a (transitive (transitive (symmetric timesZero) (*WellDefined reflexive x)) ab=1))
reciprocalPositive' : (a b : A) → .(0<a : 0R < a) → (b * a ∼ 1R) → 0R < b
reciprocalPositive' a 1/a 0<a ab=1 = reciprocalPositive a 1/a 0<a (transitive *Commutative ab=1)
reciprocal<1 : (a b : A) → .(1<a : 1R < a) → (a * b ∼ 1R) → b < 1R
reciprocal<1 a b 0<a ab=1 with totality b 1R
... | inl (inl x) = x
... | inr b=1 = exFalso (irreflexive (<WellDefined (symmetric ab=1) (transitive (symmetric identIsIdent) (transitive *Commutative ((*WellDefined reflexive (symmetric b=1))))) 0<a))
... | inl (inr x) = exFalso (irreflexive (<WellDefined identIsIdent ab=1 (ringMultiplyPositives (0<1 (anyComparisonImpliesNontrivial 0<a)) (0<1 (anyComparisonImpliesNontrivial 0<a)) 0<a x)))
isIntDom : (nonempty : 1R ∼ 0R → False) → IntegralDomain R
IntegralDomain.intDom (isIntDom n) {a} {b} ab=0 a!=0 with totality 0R b
... | inr 0=b = symmetric 0=b
IntegralDomain.intDom (isIntDom n) {a} {b} ab=0 a!=0 | inl (inl 0<b) with totality 0R a
... | inl (inl x) = exFalso (irreflexive (<WellDefined reflexive ab=0 (orderRespectsMultiplication x 0<b)))
... | inl (inr x) = exFalso (irreflexive (<WellDefined ab=0 timesZero' (ringCanMultiplyByPositive 0<b x)))
... | inr x = exFalso (a!=0 (symmetric x))
IntegralDomain.intDom (isIntDom n) {a} {b} ab=0 a!=0 | inl (inr b<0) with totality 0R a
... | inl (inl x) = exFalso (irreflexive (<WellDefined (transitive *Commutative ab=0) timesZero' (ringCanMultiplyByPositive x b<0)))
... | inl (inr x) = exFalso (irreflexive (<WellDefined reflexive (transitive twoNegativesTimes ab=0) (orderRespectsMultiplication (lemm2 a x) (lemm2 b b<0))))
... | inr x = exFalso (a!=0 (symmetric x))
IntegralDomain.nontrivial (isIntDom n) = n
|
{
"alphanum_fraction": 0.6942768088,
"avg_line_length": 72.1483253589,
"ext": "agda",
"hexsha": "ddd13feafeca480830a01a54b2b71efc75927c2f",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-29T13:23:07.000Z",
"max_forks_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Smaug123/agdaproofs",
"max_forks_repo_path": "Rings/Orders/Total/Lemmas.agda",
"max_issues_count": 14,
"max_issues_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_issues_repo_issues_event_max_datetime": "2020-04-11T11:03:39.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-01-06T21:11:59.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Smaug123/agdaproofs",
"max_issues_repo_path": "Rings/Orders/Total/Lemmas.agda",
"max_line_length": 333,
"max_stars_count": 4,
"max_stars_repo_head_hexsha": "0f4230011039092f58f673abcad8fb0652e6b562",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Smaug123/agdaproofs",
"max_stars_repo_path": "Rings/Orders/Total/Lemmas.agda",
"max_stars_repo_stars_event_max_datetime": "2022-01-28T06:04:15.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-08-08T12:44:19.000Z",
"num_tokens": 5189,
"size": 15079
}
|
{-# OPTIONS --without-K --safe #-}
-- This is a utility module.
module Utils where
open import Induction.WellFounded as Wf
open import Data.List as List
open import Data.List.All
open import Data.Nat
open import Data.Maybe
open import Data.Product as ,
open import Data.Empty
open import Function
open import Relation.Nullary
open import Relation.Binary
open import Relation.Binary.PropositionalEquality
infix 6 _!
_! : ∀ {a} {A : Set a} → A → List A
a ! = a ∷ []
infixl 5 _‣_
_‣_ : ∀ {a} {A : Set a} → List A → List A → List A
l₁ ‣ l₂ = l₂ ++ l₁
lookupOpt : ∀ {a} {A : Set a} → List A → ℕ → Maybe A
lookupOpt [] n = nothing
lookupOpt (x ∷ l) zero = just x
lookupOpt (x ∷ l) (suc n) = lookupOpt l n
module _ {a} {A : Set a} where
lookupOpt-map-inv : ∀ {b} {B : Set b} {f : A → B} l {n e} →
lookupOpt (List.map f l) n ≡ just e →
∃[ e' ] (e ≡ f e' × lookupOpt l n ≡ just e')
lookupOpt-map-inv [] {n} ()
lookupOpt-map-inv (x ∷ l) {zero} refl = x , refl , refl
lookupOpt-map-inv (x ∷ l) {suc n} eq = lookupOpt-map-inv l eq
lookupOpt-map : ∀ {b} {B : Set b} l (f : A → B) {n e} →
lookupOpt l n ≡ just e →
lookupOpt (List.map f l) n ≡ just (f e)
lookupOpt-map [] f ()
lookupOpt-map (x ∷ l) f {zero} refl = refl
lookupOpt-map (x ∷ l) f {suc n} eq = lookupOpt-map l f eq
lookupOpt-All : ∀ {b} {P : A → Set b} {l n e} →
lookupOpt l n ≡ just e →
All P l →
P e
lookupOpt-All {n = n} () []
lookupOpt-All {n = zero} refl (px ∷ all) = px
lookupOpt-All {n = suc n} eq (px ∷ all) = lookupOpt-All eq all
lookupOpt-app₁ : ∀ (l₁ l₂ : List A) {n} →
n < length l₁ →
lookupOpt (l₁ ++ l₂) n ≡ lookupOpt l₁ n
lookupOpt-app₁ [] l₂ {n} ()
lookupOpt-app₁ (x ∷ l₁) l₂ {zero} (s≤s n<l) = refl
lookupOpt-app₁ (x ∷ l₁) l₂ {suc n} (s≤s n<l) = lookupOpt-app₁ l₁ l₂ n<l
lookupOpt-app₂ : ∀ (l₁ l₂ : List A) n →
lookupOpt (l₁ ++ l₂) (length l₁ + n) ≡ lookupOpt l₂ n
lookupOpt-app₂ [] l₂ n = refl
lookupOpt-app₂ (x ∷ l₁) l₂ n = lookupOpt-app₂ l₁ l₂ n
repeat : ∀ {a} {A : Set a} → ℕ → (f : A → A) → A → A
repeat zero f = id
repeat (suc n) f = f ∘ (repeat n f)
≤?-yes : ∀ {m n} (m≤n : m ≤ n) → (m ≤? n) ≡ yes m≤n
≤?-yes z≤n = refl
≤?-yes (s≤s m≤n)
rewrite ≤?-yes m≤n = refl
≤?-no : ∀ {m n} (m>n : ¬ m ≤ n) → ∃ λ ¬p → (m ≤? n) ≡ no ¬p
≤?-no {m} {n} m>n with m ≤? n
... | yes p = ⊥-elim $ m>n p
... | no _ = -, refl
module Measure {a b ℓ} {A : Set a} {B : Set b} {_≺_ : Rel A ℓ}
(≺-wf : WellFounded _≺_)
(m : B → A) where
open import Level using () renaming (zero to lzero)
import Relation.Binary.Reasoning.Base.Triple as Triple
open Wf.Inverse-image {_<_ = _≺_} m using (wellFounded)
open Wf.All (wellFounded ≺-wf) lzero using (wfRec) public
module LexicographicMeasure {a b c d ℓ₁ ℓ₂}
{A : Set a} {B : A → Set b}
{C : Set c} {D : C → Set d}
{_≺A_ : Rel A ℓ₁}
{[_]_≺B_ : ∀ x → Rel (B x) ℓ₂}
(≺A-wf : WellFounded _≺A_)
(≺B-wf : ∀ {x} → WellFounded ([ x ]_≺B_))
(mC : C → A)
(mD : ∀ {c} → D c → B (mC c)) where
open import Level using () renaming (zero to lzero)
module Lex = Wf.Lexicographic _≺A_ [_]_≺B_
open Lex renaming (wellFounded to lex-wf ; _<_ to _≺′_)
open Lex using (left ; right) public
open Wf.Inverse-image renaming (wellFounded to m-wf)
measure : Σ C D → Σ A B
measure (c , d) = mC c , mD d
ΣAB-wf : WellFounded _≺′_
ΣAB-wf = lex-wf ≺A-wf ≺B-wf
infix 3 _≺_
_≺_ = _≺′_ on ,.map mC mD
measure-wf : WellFounded _≺_
measure-wf = m-wf measure ΣAB-wf
open Wf.All measure-wf lzero using (wfRec) public
|
{
"alphanum_fraction": 0.5116981132,
"avg_line_length": 33.4033613445,
"ext": "agda",
"hexsha": "426b148fd77c89730e95791091c8dd3f05509a81",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "HuStmpHrrr/popl20-artifact",
"max_forks_repo_path": "agda/Utils.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "HuStmpHrrr/popl20-artifact",
"max_issues_repo_path": "agda/Utils.agda",
"max_line_length": 74,
"max_stars_count": 1,
"max_stars_repo_head_hexsha": "48214a55ebb484fd06307df4320813d4a002535b",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "HuStmpHrrr/popl20-artifact",
"max_stars_repo_path": "agda/Utils.agda",
"max_stars_repo_stars_event_max_datetime": "2021-09-23T08:40:28.000Z",
"max_stars_repo_stars_event_min_datetime": "2021-09-23T08:40:28.000Z",
"num_tokens": 1488,
"size": 3975
}
|
-- Andreas, 2015-02-24
data N : Set where
zero : N
suc : N → N
data Sing : (n : N) → Set where
sing : ∀ n → Sing n
data D : Set → Set where
c : ∀ n → D (Sing n)
test : (A : Set) → D A → N
test .(Sing n) (c n) = n
-- this should crash Epic as long as n is considered forced in constructor c
-- should succeed now
|
{
"alphanum_fraction": 0.5779816514,
"avg_line_length": 17.2105263158,
"ext": "agda",
"hexsha": "fe70bfeb47ed4a08795acb6131f55077afc3cb21",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_forks_repo_licenses": [
"BSD-3-Clause"
],
"max_forks_repo_name": "redfish64/autonomic-agda",
"max_forks_repo_path": "test/Fail/Issue1441-4.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"BSD-3-Clause"
],
"max_issues_repo_name": "redfish64/autonomic-agda",
"max_issues_repo_path": "test/Fail/Issue1441-4.agda",
"max_line_length": 76,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "c0ae7d20728b15d7da4efff6ffadae6fe4590016",
"max_stars_repo_licenses": [
"BSD-3-Clause"
],
"max_stars_repo_name": "redfish64/autonomic-agda",
"max_stars_repo_path": "test/Fail/Issue1441-4.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 117,
"size": 327
}
|
{- Cubical Agda with K
This file demonstrates the incompatibility of the --cubical
and --with-K flags, relying on the well-known incosistency of K with
univalence.
The --safe flag can be used to prevent accidentally mixing such
incompatible flags.
-}
{-# OPTIONS --cubical --no-import-sorts --with-K #-}
module Cubical.WithK where
open import Cubical.Data.Equality
open import Cubical.Data.Bool
open import Cubical.Data.Empty
private
variable
ℓ : Level
A : Type ℓ
x y : A
uip : (prf : x ≡p x) → prf ≡c reflp
uip reflp i = reflp
transport-uip : (prf : A ≡p A) → transport (ptoc prf) x ≡c x
transport-uip {x = x} prf =
cong (λ m → transport (ptoc m) x) (uip prf) ∙ transportRefl x
transport-not : transport (ptoc (ctop notEq)) true ≡c false
transport-not = cong (λ a → transport a true) (ptoc-ctop notEq)
false-true : false ≡c true
false-true = sym transport-not ∙ transport-uip (ctop notEq)
absurd : (X : Type) → X
absurd X = transport (cong sel false-true) true
where
sel : Bool → Type
sel false = Bool
sel true = X
inconsistency : ⊥
inconsistency = absurd ⊥
|
{
"alphanum_fraction": 0.6916058394,
"avg_line_length": 22.3673469388,
"ext": "agda",
"hexsha": "180ca8484684ee5226c5f2d92646f50268782a40",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_forks_event_min_datetime": "2021-11-22T02:02:01.000Z",
"max_forks_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dan-iel-lee/cubical",
"max_forks_repo_path": "Cubical/WithK.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "fd8059ec3eed03f8280b4233753d00ad123ffce8",
"max_issues_repo_issues_event_max_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_issues_event_min_datetime": "2022-01-27T02:07:48.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dan-iel-lee/cubical",
"max_issues_repo_path": "Cubical/WithK.agda",
"max_line_length": 68,
"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/WithK.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 357,
"size": 1096
}
|
{-# OPTIONS --without-K --rewriting #-}
open import lib.Basics
open import lib.types.Paths
open import lib.types.Pointed
open import lib.types.Pushout
open import lib.types.PushoutFmap
open import lib.types.Sigma
open import lib.types.Span
module lib.types.Join where
module _ {i j} (A : Type i) (B : Type j) where
*-span : Span
*-span = span A B (A × B) fst snd
infix 80 _*_
_*_ : Type _
_*_ = Pushout *-span
module JoinElim {i j} {A : Type i} {B : Type j} {k} {P : A * B → Type k}
(left* : (a : A) → P (left a)) (right* : (b : B) → P (right b))
(glue* : (ab : A × B) → left* (fst ab) == right* (snd ab) [ P ↓ glue ab ])
= PushoutElim left* right* glue*
open JoinElim public using () renaming (f to Join-elim)
module JoinRec {i j} {A : Type i} {B : Type j} {k} {D : Type k}
(left* : (a : A) → D) (right* : (b : B) → D)
(glue* : (ab : A × B) → left* (fst ab) == right* (snd ab))
= PushoutRec left* right* glue*
open JoinRec public using () renaming (f to Join-rec)
module _ {i j} (X : Ptd i) (Y : Ptd j) where
⊙*-span : ⊙Span
⊙*-span = ⊙span X Y (X ⊙× Y) ⊙fst ⊙snd
infix 80 _⊙*_
_⊙*_ : Ptd _
_⊙*_ = ⊙Pushout ⊙*-span
module _ {i i' j j'} {A : Type i} {A' : Type i'} {B : Type j} {B' : Type j'}
(eqA : A ≃ A') (eqB : B ≃ B') where
*-span-emap : SpanEquiv (*-span A B) (*-span A' B')
*-span-emap = ( span-map (fst eqA) (fst eqB) (×-fmap (fst eqA) (fst eqB)) (comm-sqr λ _ → idp) (comm-sqr λ _ → idp)
, snd eqA , snd eqB , ×-isemap (snd eqA) (snd eqB))
*-emap : A * B ≃ A' * B'
*-emap = Pushout-emap *-span-emap
module _ {i i' j j'} {X : Ptd i} {X' : Ptd i'} {Y : Ptd j} {Y' : Ptd j'} where
⊙*-emap : X ⊙≃ X' → Y ⊙≃ Y' → X ⊙* Y ⊙≃ X' ⊙* Y'
⊙*-emap ⊙eqX ⊙eqY = ≃-to-⊙≃ (*-emap (⊙≃-to-≃ ⊙eqX) (⊙≃-to-≃ ⊙eqY)) (ap left (snd (⊙–> ⊙eqX)))
|
{
"alphanum_fraction": 0.5342541436,
"avg_line_length": 30.6779661017,
"ext": "agda",
"hexsha": "29a472d7239454c61c85fb2410c62319807ba89e",
"lang": "Agda",
"max_forks_count": 1,
"max_forks_repo_forks_event_max_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_forks_event_min_datetime": "2018-12-26T21:31:57.000Z",
"max_forks_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "mikeshulman/HoTT-Agda",
"max_forks_repo_path": "core/lib/types/Join.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"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": "mikeshulman/HoTT-Agda",
"max_issues_repo_path": "core/lib/types/Join.agda",
"max_line_length": 117,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "e7d663b63d89f380ab772ecb8d51c38c26952dbb",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "mikeshulman/HoTT-Agda",
"max_stars_repo_path": "core/lib/types/Join.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 790,
"size": 1810
}
|
module Auto.Prelude where
open import Agda.Primitive public
using (Level)
data ⊥ : Set where
¬ : Set → Set
¬ A = A → ⊥
⊥-e : (A : Set) → ⊥ → A
⊥-e A ()
record ⊤ : Set where
record _∧_ (A B : Set) : Set where
constructor ∧-i
field fst : A
snd : B
data _∨_ (A B : Set) : Set where
∨-i₁ : A → A ∨ B
∨-i₂ : B → A ∨ B
∨-e : (A B C : Set) → A ∨ B → (A → C) → (B → C) → C
∨-e A B C (∨-i₁ x) h₁ h₂ = h₁ x
∨-e A B C (∨-i₂ x) h₁ h₂ = h₂ x
data Π (A : Set) (F : A → Set) : Set where
fun : ((a : A) → F a) → Π A F
record Σ (X : Set) (P : X → Set) : Set where
constructor Σ-i
field wit : X
prf : P wit
data ℕ : Set where
zero : ℕ
succ : ℕ → ℕ
_+_ : ℕ → ℕ → ℕ
zero + n = n
succ m + n = succ (m + n)
data Fin : ℕ → Set where
zero : ∀ {n} → Fin (succ n)
suc : ∀ {n} → Fin n → Fin (succ n)
data List (X : Set) : Set where
[] : List X
_∷_ : X → List X → List X
_++_ : {X : Set} → List X → List X → List X
[] ++ ys = ys
(x ∷ xs) ++ ys = x ∷ (xs ++ ys)
data Vec (X : Set) : ℕ → Set where
[] : Vec X zero
_∷_ : ∀ {n} → X → Vec X n → Vec X (succ n)
-- -----------------------------------
data _≡_ {a} {A : Set a} (x : A) : A → Set where
refl : x ≡ x
subst : {i j : Level} {X : Set i} → (P : X → Set j) → (x y : X) → y ≡ x → P x → P y
subst P x .x refl h = h
trans : ∀ {a} {A : Set a} → {x y z : A} → x ≡ y → y ≡ z → x ≡ z
trans refl refl = refl
sym : ∀ {a} {A : Set a} → {x y : A} → x ≡ y → y ≡ x
sym refl = refl
cong : ∀ {a b} {A : Set a} {B : Set b}
(f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
data _IsRelatedTo_ {a : Level} {Carrier : Set a} (x y : Carrier) : Set a where
relTo : (x∼y : x ≡ y) → x IsRelatedTo y
begin_ : {a : Level} {Carrier : Set a} → {x y : Carrier} → x IsRelatedTo y → x ≡ y
begin relTo x∼y = x∼y
_∎ : {a : Level} {Carrier : Set a} → (x : Carrier) → x IsRelatedTo x
_∎ _ = relTo refl
_≡⟨_⟩_ : {a : Level} {Carrier : Set a} → (x : Carrier) {y z : Carrier} → x ≡ y → y IsRelatedTo z → x IsRelatedTo z
_ ≡⟨ x∼y ⟩ relTo y∼z = relTo (trans x∼y y∼z)
-- -----------------------------------
|
{
"alphanum_fraction": 0.4641148325,
"avg_line_length": 20.6930693069,
"ext": "agda",
"hexsha": "adf68ce6285d47bd5b8424f3ee8b9b965263be4c",
"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/Auto/Prelude.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/Auto/Prelude.agda",
"max_line_length": 114,
"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/Auto/Prelude.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": 927,
"size": 2090
}
|
------------------------------------------------------------------------
-- A specification of the language χ
------------------------------------------------------------------------
open import Atom
-- The specification is parametrised by an instance of χ-atoms.
module Chi (atoms : χ-atoms) where
open import Equality.Propositional
open import Prelude hiding (const)
open χ-atoms atoms
-- Abstract syntax.
mutual
data Exp : Type where
apply : Exp → Exp → Exp
lambda : Var → Exp → Exp
case : Exp → List Br → Exp
rec : Var → Exp → Exp
var : Var → Exp
const : Const → List Exp → Exp
data Br : Type where
branch : Const → List Var → Exp → Br
-- Substitution.
mutual
infix 6 _[_←_] _[_←_]B _[_←_]⋆ _[_←_]B⋆
_[_←_] : Exp → Var → Exp → Exp
apply e₁ e₂ [ x ← e′ ] = apply (e₁ [ x ← e′ ]) (e₂ [ x ← e′ ])
lambda y e [ x ← e′ ] = lambda y (if x V.≟ y
then e
else e [ x ← e′ ])
case e bs [ x ← e′ ] = case (e [ x ← e′ ]) (bs [ x ← e′ ]B⋆)
rec y e [ x ← e′ ] = rec y (if x V.≟ y
then e
else e [ x ← e′ ])
var y [ x ← e′ ] = if x V.≟ y then e′ else var y
const c es [ x ← e′ ] = const c (es [ x ← e′ ]⋆)
_[_←_]B : Br → Var → Exp → Br
branch c xs e [ x ← e′ ]B with V.member x xs
... | yes _ = branch c xs e
... | no _ = branch c xs (e [ x ← e′ ])
_[_←_]⋆ : List Exp → Var → Exp → List Exp
[] [ x ← e′ ]⋆ = []
(e ∷ es) [ x ← e′ ]⋆ = e [ x ← e′ ] ∷ es [ x ← e′ ]⋆
_[_←_]B⋆ : List Br → Var → Exp → List Br
[] [ x ← e′ ]B⋆ = []
(b ∷ bs) [ x ← e′ ]B⋆ = b [ x ← e′ ]B ∷ bs [ x ← e′ ]B⋆
infix 5 ∷_
infix 4 _[_←_]↦_
data _[_←_]↦_ (e : Exp) : List Var → List Exp → Exp → Type where
[] : e [ [] ← [] ]↦ e
∷_ : ∀ {x xs e′ es′ e″} →
e [ xs ← es′ ]↦ e″ → e [ x ∷ xs ← e′ ∷ es′ ]↦ e″ [ x ← e′ ]
-- Operational semantics.
data Lookup (c : Const) : List Br → List Var → Exp → Type where
here : ∀ {xs e bs} → Lookup c (branch c xs e ∷ bs) xs e
there : ∀ {c′ xs′ e′ bs xs e} →
c ≢ c′ → Lookup c bs xs e →
Lookup c (branch c′ xs′ e′ ∷ bs) xs e
infixr 5 _∷_
infix 4 _⇓_ _⇓⋆_
mutual
data _⇓_ : Exp → Exp → Type where
apply : ∀ {e₁ e₂ x e v₂ v} →
e₁ ⇓ lambda x e → e₂ ⇓ v₂ → e [ x ← v₂ ] ⇓ v →
apply e₁ e₂ ⇓ v
case : ∀ {e bs c es xs e′ e″ v} →
e ⇓ const c es → Lookup c bs xs e′ →
e′ [ xs ← es ]↦ e″ → e″ ⇓ v →
case e bs ⇓ v
rec : ∀ {x e v} → e [ x ← rec x e ] ⇓ v → rec x e ⇓ v
lambda : ∀ {x e} → lambda x e ⇓ lambda x e
const : ∀ {c es vs} → es ⇓⋆ vs → const c es ⇓ const c vs
data _⇓⋆_ : List Exp → List Exp → Type where
[] : [] ⇓⋆ []
_∷_ : ∀ {e es v vs} → e ⇓ v → es ⇓⋆ vs → e ∷ es ⇓⋆ v ∷ vs
|
{
"alphanum_fraction": 0.4134214186,
"avg_line_length": 29.0505050505,
"ext": "agda",
"hexsha": "561e36cea39d6d82c3a59608292274c017038a26",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "nad/chi",
"max_forks_repo_path": "src/Chi.agda",
"max_issues_count": 1,
"max_issues_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_issues_repo_issues_event_max_datetime": "2020-06-08T11:08:25.000Z",
"max_issues_repo_issues_event_min_datetime": "2020-05-21T23:29:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "nad/chi",
"max_issues_repo_path": "src/Chi.agda",
"max_line_length": 72,
"max_stars_count": 2,
"max_stars_repo_head_hexsha": "30966769b8cbd46aa490b6964a4aa0e67a7f9ab1",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "nad/chi",
"max_stars_repo_path": "src/Chi.agda",
"max_stars_repo_stars_event_max_datetime": "2020-10-20T16:27:00.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-05-21T22:58:07.000Z",
"num_tokens": 1124,
"size": 2876
}
|
------------------------------------------------------------------------
-- The Agda standard library
--
-- An inductive definition of the sublist relation with respect to a
-- setoid which is decidable. This is a generalisation of what is
-- commonly known as Order Preserving Embeddings (OPE).
------------------------------------------------------------------------
{-# OPTIONS --without-K --safe #-}
open import Relation.Binary
module Data.List.Relation.Binary.Sublist.DecSetoid
{c ℓ} (S : DecSetoid c ℓ) where
import Data.List.Relation.Binary.Equality.DecSetoid as DecSetoidEquality
import Data.List.Relation.Binary.Sublist.Setoid as SetoidSublist
import Data.List.Relation.Binary.Sublist.Heterogeneous.Properties
as HeterogeneousProperties
open import Level using (_⊔_)
open DecSetoid S
open DecSetoidEquality S
------------------------------------------------------------------------
-- Re-export core definitions
open SetoidSublist setoid public
------------------------------------------------------------------------
-- Additional relational properties
_⊆?_ : Decidable _⊆_
_⊆?_ = HeterogeneousProperties.sublist? _≟_
⊆-isDecPartialOrder : IsDecPartialOrder _≋_ _⊆_
⊆-isDecPartialOrder = record
{ isPartialOrder = ⊆-isPartialOrder
; _≟_ = _≋?_
; _≤?_ = _⊆?_
}
⊆-decPoset : DecPoset c (c ⊔ ℓ) (c ⊔ ℓ)
⊆-decPoset = record
{ isDecPartialOrder = ⊆-isDecPartialOrder
}
|
{
"alphanum_fraction": 0.5857946554,
"avg_line_length": 30.2553191489,
"ext": "agda",
"hexsha": "9b8287eef9e0de81aca2a87641d1001c54350209",
"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/Data/List/Relation/Binary/Sublist/DecSetoid.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "0debb886eb5dbcd38dbeebd04b34cf9d9c5e0e71",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "omega12345/agda-mode",
"max_issues_repo_path": "test/asset/agda-stdlib-1.0/Data/List/Relation/Binary/Sublist/DecSetoid.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/Data/List/Relation/Binary/Sublist/DecSetoid.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": 360,
"size": 1422
}
|
module DifferentArities where
data Nat : Set where
zero : Nat
suc : Nat -> Nat
f : Nat -> Nat -> Nat
f zero = \x -> x
f (suc n) m = f n (suc m)
|
{
"alphanum_fraction": 0.5506329114,
"avg_line_length": 13.1666666667,
"ext": "agda",
"hexsha": "e07cf9a5834820332c025a0411d25f0aa6a9c071",
"lang": "Agda",
"max_forks_count": null,
"max_forks_repo_forks_event_max_datetime": null,
"max_forks_repo_forks_event_min_datetime": null,
"max_forks_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "dagit/agda",
"max_forks_repo_path": "test/fail/DifferentArities.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "4383a3d20328a6c43689161496cee8eb479aca08",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "dagit/agda",
"max_issues_repo_path": "test/fail/DifferentArities.agda",
"max_line_length": 29,
"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/DifferentArities.agda",
"max_stars_repo_stars_event_max_datetime": "2019-11-27T07:26:06.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-11-27T07:26:06.000Z",
"num_tokens": 59,
"size": 158
}
|
-- This file derives some of the Cartesian Kan operations using transp
{-# OPTIONS --cubical --safe #-}
module Cubical.Foundations.CartesianKanOps where
open import Cubical.Core.Everything
open import Cubical.Foundations.Prelude
coe0→1 : ∀ {ℓ} (A : I → Type ℓ) → A i0 → A i1
coe0→1 A a = transp A i0 a
-- "coe filler"
coe0→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i0 → A i
coe0→i A i a = transp (λ j → A (i ∧ j)) (~ i) a
-- Check the equations for the coe filler
coe0→i1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coe0→i A i1 a ≡ coe0→1 A a
coe0→i1 A a = refl
coe0→i0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coe0→i A i0 a ≡ a
coe0→i0 A a = refl
-- coe backwards
coe1→0 : ∀ {ℓ} (A : I → Type ℓ) → A i1 → A i0
coe1→0 A a = transp (λ i → A (~ i)) i0 a
-- coe backwards filler
coe1→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i1 → A i
coe1→i A i a = transp (λ j → A (i ∨ ~ j)) i a
-- Check the equations for the coe backwards filler
coe1→i0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coe1→i A i0 a ≡ coe1→0 A a
coe1→i0 A a = refl
coe1→i1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coe1→i A i1 a ≡ a
coe1→i1 A a = refl
-- "squeezeNeg"
coei→0 : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i → A i0
coei→0 A i a = transp (λ j → A (i ∧ ~ j)) (~ i) a
coei0→0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coei→0 A i0 a ≡ a
coei0→0 A a = refl
coei1→0 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coei→0 A i1 a ≡ coe1→0 A a
coei1→0 A a = refl
-- "master coe"
-- defined as the filler of coei→0, coe0→i, and coe1→i
-- unlike in cartesian cubes, we don't get coei→i = id definitionally
coei→j : ∀ {ℓ} (A : I → Type ℓ) (i j : I) → A i → A j
coei→j A i j a =
fill A
(λ j → λ { (i = i0) → coe0→i A j a
; (i = i1) → coe1→i A j a
})
(inS (coei→0 A i a))
j
-- "squeeze"
-- this is just defined as the composite face of the master coe
coei→1 : ∀ {ℓ} (A : I → Type ℓ) (i : I) → A i → A i1
coei→1 A i a = coei→j A i i1 a
coei0→1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i0) → coei→1 A i0 a ≡ coe0→1 A a
coei0→1 A a = refl
coei1→1 : ∀ {ℓ} (A : I → Type ℓ) (a : A i1) → coei→1 A i1 a ≡ a
coei1→1 A a = refl
-- equations for "master coe"
coei→i0 : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i0 a ≡ coei→0 A i a
coei→i0 A i a = refl
coei0→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i0) → coei→j A i0 i a ≡ coe0→i A i a
coei0→i A i a = refl
coei→i1 : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i1 a ≡ coei→1 A i a
coei→i1 A i a = refl
coei1→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i1) → coei→j A i1 i a ≡ coe1→i A i a
coei1→i A i a = refl
-- only non-definitional equation
coei→i : ∀ {ℓ} (A : I → Type ℓ) (i : I) (a : A i) → coei→j A i i a ≡ a
coei→i A i = coe0→i (λ i → (a : A i) → coei→j A i i a ≡ a) i (λ _ → refl)
-- do the same for fill
fill1→i : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u1 : A i1 [ φ ↦ u i1 ])
---------------------------
(i : I) → A i
fill1→i A {φ = φ} u u1 i =
comp (λ j → A (i ∨ ~ j))
(λ j → λ { (φ = i1) → u (i ∨ ~ j) 1=1
; (i = i1) → outS u1 })
(outS u1)
filli→0 : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(i : I)
(ui : A i [ φ ↦ u i ])
---------------------------
→ A i0
filli→0 A {φ = φ} u i ui =
comp (λ j → A (i ∧ ~ j))
(λ j → λ { (φ = i1) → u (i ∧ ~ j) 1=1
; (i = i0) → outS ui })
(outS ui)
filli→j : ∀ {ℓ} (A : ∀ i → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(i : I)
(ui : A i [ φ ↦ u i ])
---------------------------
(j : I) → A j
filli→j A {φ = φ} u i ui j =
fill A
(λ j → λ { (φ = i1) → u j 1=1
; (i = i0) → fill A u ui j
; (i = i1) → fill1→i A u ui j
})
(inS (filli→0 A u i ui))
j
-- We can reconstruct fill from hfill, coei→j, and the path coei→i ≡ id.
-- The definition does not rely on the computational content of the coei→i path.
fill' : ∀ {ℓ} (A : I → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ])
---------------------------
(i : I) → A i [ φ ↦ u i ]
fill' A {φ = φ} u u0 i =
inS (hcomp (λ j → λ {(φ = i1) → coei→i A i (u i 1=1) j; (i = i0) → coei→i A i (outS u0) j}) t)
where
t : A i
t = hfill {φ = φ} (λ j v → coei→j A j i (u j v)) (inS (coe0→i A i (outS u0))) i
fill'-cap : ∀ {ℓ} (A : I → Type ℓ)
{φ : I}
(u : ∀ i → Partial φ (A i))
(u0 : A i0 [ φ ↦ u i0 ])
---------------------------
→ outS (fill' A u u0 i0) ≡ outS (u0)
fill'-cap A u u0 = refl
|
{
"alphanum_fraction": 0.4465640581,
"avg_line_length": 30.3486842105,
"ext": "agda",
"hexsha": "a54f2f9d7127620f5279a6408d26b5a851ca8ea5",
"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/Foundations/CartesianKanOps.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/Foundations/CartesianKanOps.agda",
"max_line_length": 96,
"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/Foundations/CartesianKanOps.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 2144,
"size": 4613
}
|
module Numeral.Natural.Oper.DivMod.Proofs where
import Lvl
open import Data
open import Data.Boolean.Stmt
open import Logic.Predicate
open import Numeral.Finite
open import Numeral.Natural
open import Numeral.Natural.Oper
open import Numeral.Natural.Oper.Comparisons
open import Numeral.Natural.Oper.FlooredDivision
open import Numeral.Natural.Oper.FlooredDivision.Proofs.DivisibilityWithRemainder
open import Numeral.Natural.Oper.Modulo
open import Numeral.Natural.Oper.Modulo.Proofs.DivisibilityWithRemainder
open import Numeral.Natural.Oper.Proofs
open import Numeral.Natural.Relation.DivisibilityWithRemainder
open import Numeral.Natural.Relation.DivisibilityWithRemainder.Proofs
open import Relator.Equals
open import Relator.Equals.Proofs
open import Structure.Operator
open import Structure.Operator.Proofs.Util
open import Structure.Operator.Properties
open import Syntax.Transitivity
-- The division theorem.
[⌊/⌋][mod]-is-division-with-remainder : ∀{x y} → (((x ⌊/⌋ 𝐒(y)) ⋅ 𝐒(y)) + (x mod 𝐒(y)) ≡ x)
[⌊/⌋][mod]-is-division-with-remainder {x}{y} with [∃]-intro r ⦃ p ⦄ ← [∣ᵣₑₘ]-existence-alt {x}{y} =
((x ⌊/⌋ 𝐒(y)) ⋅ 𝐒(y)) + (x mod 𝐒(y)) 🝖[ _≡_ ]-[ congruence₂(_+_) (congruence₂ₗ(_⋅_)(𝐒(y)) ([⌊/⌋][∣ᵣₑₘ]-quotient-equality {x}{y}{r}{p})) ([mod][∣ᵣₑₘ]-remainder-equality {x}{y}{r}{p}) ]
(([∣ᵣₑₘ]-quotient p) ⋅ 𝐒(y)) + (𝕟-to-ℕ ([∣ᵣₑₘ]-remainder p)) 🝖[ _≡_ ]-[ [∣ᵣₑₘ]-is-division-with-remainder {x}{𝐒(y)}{r} p ]
x 🝖-end
[⌊/⌋][mod]-is-division-with-remainder-pred-commuted : ∀{x y} ⦃ _ : IsTrue(positive?(y)) ⦄ → ((y ⋅ (x ⌊/⌋ y)) + (x mod y) ≡ x)
[⌊/⌋][mod]-is-division-with-remainder-pred-commuted {x} {𝐒 y} = [≡]-with(_+ (x mod 𝐒(y))) (commutativity(_⋅_) {𝐒(y)}{x ⌊/⌋ 𝐒(y)}) 🝖 [⌊/⌋][mod]-is-division-with-remainder {x}{y}
-- Floored division and multiplication is not inverse operators for all numbers.
-- This shows why it is not exactly.
[⌊/⌋][⋅]-semiInverseOperatorᵣ : ∀{a b} → ((a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b) ≡ a −₀ (a mod 𝐒(b)))
[⌊/⌋][⋅]-semiInverseOperatorᵣ {a}{b} =
(a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b) 🝖[ _≡_ ]-[ OneTypeTwoOp.moveᵣ-to-invOp {b = a mod 𝐒(b)}{c = a} (([⌊/⌋][mod]-is-division-with-remainder {y = b})) ]
a −₀ (a mod 𝐒(b)) 🝖-end
-- Floored division and multiplication is not inverse operators for all numbers.
-- This theorem shows that modulo is the error term (difference between the actual value for it to be inverse and value of the operation).
[⌊/⌋][⋅]-inverseOperatorᵣ-error : ∀{a b} → (a mod 𝐒(b) ≡ a −₀ (a ⌊/⌋ 𝐒(b) ⋅ 𝐒(b)))
[⌊/⌋][⋅]-inverseOperatorᵣ-error {a}{b} =
(a mod 𝐒(b)) 🝖[ _≡_ ]-[ OneTypeTwoOp.moveᵣ-to-invOp {a = a mod 𝐒(b)}{b = (a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b)}{c = a} (commutativity(_+_) {a mod 𝐒(b)}{(a ⌊/⌋ 𝐒(b)) ⋅ 𝐒(b)} 🝖 [⌊/⌋][mod]-is-division-with-remainder {y = b}) ]
a −₀ (a ⌊/⌋ 𝐒(b) ⋅ 𝐒(b)) 🝖-end
|
{
"alphanum_fraction": 0.6338526912,
"avg_line_length": 58.8333333333,
"ext": "agda",
"hexsha": "c8e6532287da60d411a339ae80f5f911b75079bb",
"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/DivMod/Proofs.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "70f4fba849f2fd779c5aaa5af122ccb6a5b271ba",
"max_issues_repo_issues_event_max_datetime": null,
"max_issues_repo_issues_event_min_datetime": null,
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Lolirofle/stuff-in-agda",
"max_issues_repo_path": "Numeral/Natural/Oper/DivMod/Proofs.agda",
"max_line_length": 219,
"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/DivMod/Proofs.agda",
"max_stars_repo_stars_event_max_datetime": "2022-02-05T06:53:22.000Z",
"max_stars_repo_stars_event_min_datetime": "2020-04-07T17:58:13.000Z",
"num_tokens": 1235,
"size": 2824
}
|
open import Agda.Builtin.Nat
open import Agda.Builtin.Equality
cong : {A B : Set} (f : A → B)
→ {x y : A} → x ≡ y → f x ≡ f y
cong f refl = refl
+-identityʳ : (x : Nat) → x + 0 ≡ x
+-identityʳ zero = refl
+-identityʳ (suc n) = cong suc (+-identityʳ n)
+-assoc : (x y z : Nat) → (x + y) + z ≡ x + (y + z)
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
data Bin : Set where
nil : Bin
x0_ : Bin → Bin
x1_ : Bin → Bin
inc : Bin → Bin
inc nil = x1 nil
inc (x0 x) = x1 x
inc (x1 x) = x0 (inc x)
to : Nat → Bin
to zero = (x0 nil)
to (suc x) = inc (to x)
postulate
from : Bin → Nat
data Can : Bin → Set where
Can- : ∀ {n} → from (to n) ≡ n → Can (to n)
data Σ (A : Set) (B : A → Set) : Set where
⟨_,_⟩ : (x : A) → B x → Σ A B
postulate
to'' : (x : Nat) → Σ Bin Can
to∘from' : (a : Bin) → (b : Can a) → to'' (from a) ≡ ⟨ a , b ⟩
to∘from' .(to _) (Can- x) = {!!}
|
{
"alphanum_fraction": 0.5082146769,
"avg_line_length": 20.75,
"ext": "agda",
"hexsha": "7e99d65d5190319f03df495f902b320107f963c0",
"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/Issue3813.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/Issue3813.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/Fail/Issue3813.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": 405,
"size": 913
}
|
-- Andreas, 2017-09-03, issue #2730:
-- Skip termination check when giving.
-- C-c C-SPC fails because of termination problems, but
-- C-u C-c C-SPC should succeed here.
f : Set
f = {! f !}
|
{
"alphanum_fraction": 0.6614583333,
"avg_line_length": 21.3333333333,
"ext": "agda",
"hexsha": "46b64184449a1336de25fc7553c220c4eae4562d",
"lang": "Agda",
"max_forks_count": 371,
"max_forks_repo_forks_event_max_datetime": "2022-03-30T19:00:30.000Z",
"max_forks_repo_forks_event_min_datetime": "2015-01-03T14:04:08.000Z",
"max_forks_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "cruhland/agda",
"max_forks_repo_path": "test/interaction/GiveWithForce.agda",
"max_issues_count": 4066,
"max_issues_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_issues_repo_issues_event_max_datetime": "2022-03-31T21:14:49.000Z",
"max_issues_repo_issues_event_min_datetime": "2015-01-10T11:24:51.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "cruhland/agda",
"max_issues_repo_path": "test/interaction/GiveWithForce.agda",
"max_line_length": 55,
"max_stars_count": 1989,
"max_stars_repo_head_hexsha": "7f58030124fa99dfbf8db376659416f3ad8384de",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "cruhland/agda",
"max_stars_repo_path": "test/interaction/GiveWithForce.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": 61,
"size": 192
}
|
module Prelude.IO where
open import Prelude.Bool
open import Prelude.Char
open import Prelude.Nat
open import Prelude.String
open import Prelude.Unit
open import Prelude.Vec
open import Prelude.Float
postulate
IO : Set → Set
{-# COMPILED_TYPE IO IO #-}
infixl 1 _>>=_
postulate
return : ∀ {A} → A → IO A
_>>=_ : ∀ {A B} → IO A → (A → IO B) → IO B
numArgs : Nat
getArg : Nat -> String
args : Vec String numArgs
args = buildArgs numArgs
where
buildArgs : (n : Nat) -> Vec String n
buildArgs Z = []
buildArgs (S n) = snoc (buildArgs n) (getArg n)
{-# COMPILED_EPIC return (u1 : Unit, a : Any) -> Any = ioreturn(a) #-}
{-# COMPILED_EPIC _>>=_ (u1 : Unit, u2 : Unit, x : Any, f : Any) -> Any = iobind(x,f) #-}
{-# COMPILED_EPIC numArgs () -> BigInt = foreign BigInt "numArgsBig" () #-}
{-# COMPILED_EPIC getArg (n : BigInt) -> Any = foreign Any "getArgBig" (n : BigInt) #-}
postulate
natToString : Nat -> String
readNat : IO Nat
readStr : IO String
putStr : String -> IO Unit
printChar : Char -> IO Unit
putStrLn : String -> IO Unit
putStrLn s = putStr s >>= \_ -> putStr "\n"
printFloat : Float -> IO Unit
printFloat f = putStr (floatToString f)
printNat : Nat -> IO Unit
printNat n = putStr (natToString n)
printBool : Bool -> IO Unit
printBool true = putStr "true"
printBool false = putStr "false"
{-# COMPILED_EPIC natToString (n : Any) -> String = bigToStr(n) #-}
{-# COMPILED_EPIC readNat (u : Unit) -> Any = strToBig(readStr(u)) #-}
{-# COMPILED_EPIC putStr (a : String, u : Unit) -> Unit = foreign Int "wputStr" (mkString(a) : String); primUnit #-}
-- {-# COMPILED_EPIC putStrLn (a : String, u : Unit) -> Unit = putStrLn (a) #-}
{-# COMPILED_EPIC readStr (u : Unit) -> Data = readStr(u) #-}
{-# COMPILED_EPIC printChar (c : Int, u : Unit) -> Unit = printChar(c) #-}
infixr 2 _<$>_
_<$>_ : {A B : Set}(f : A -> B)(m : IO A) -> IO B
f <$> x = x >>= λ y -> return (f y)
infixr 0 bind
bind : ∀ {A B} → IO A → (A → IO B) → IO B
bind m f = m >>= f
infixr 0 then
then : ∀ {A B} -> IO A -> IO B -> IO B
then m f = m >>= λ _ -> f
syntax bind e (\ x -> f) = x <- e , f
syntax then e f = e ,, f
|
{
"alphanum_fraction": 0.5984360626,
"avg_line_length": 27.8717948718,
"ext": "agda",
"hexsha": "d3aa51d55aea69b3cb91c23d041c3092bf70729e",
"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": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "asr/agda-kanso",
"max_forks_repo_path": "test/epic/Prelude/IO.agda",
"max_issues_count": null,
"max_issues_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"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": "asr/agda-kanso",
"max_issues_repo_path": "test/epic/Prelude/IO.agda",
"max_line_length": 116,
"max_stars_count": null,
"max_stars_repo_head_hexsha": "aa10ae6a29dc79964fe9dec2de07b9df28b61ed5",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "asr/agda-kanso",
"max_stars_repo_path": "test/epic/Prelude/IO.agda",
"max_stars_repo_stars_event_max_datetime": null,
"max_stars_repo_stars_event_min_datetime": null,
"num_tokens": 737,
"size": 2174
}
|
{-# OPTIONS --without-K --safe #-}
module Categories.NaturalTransformation.Properties where
open import Level
open import Data.Product using (Σ; _,_)
open import Function.Equality using (Π)
open import Categories.Category
open import Categories.Category.Product
open import Categories.Category.Instance.Setoids
open import Categories.Functor
open import Categories.Functor.Construction.Constant
open import Categories.Functor.Construction.LiftSetoids
open import Categories.Functor.Bifunctor
open import Categories.NaturalTransformation renaming (id to idN)
open import Categories.NaturalTransformation.NaturalIsomorphism
open import Categories.NaturalTransformation.Dinatural hiding (_≃_)
import Categories.Morphism.Reasoning as MR
private
variable
o ℓ ℓ′ e : Level
C D E : Category o ℓ e
module _ {F G : Functor C D} where
private
module C = Category C
module D = Category D
open D
open MR D
open HomReasoning
open Functor
F′ : Bifunctor C.op C D
F′ = F ∘F πʳ
G′ : Bifunctor C.op C D
G′ = G ∘F πʳ
NT⇒Dinatural : NaturalTransformation F G → DinaturalTransformation F′ G′
NT⇒Dinatural β = dtHelper record
{ α = η
; commute = λ f → ∘-resp-≈ʳ (elimʳ (identity F)) ○ ⟺ (commute f) ○ introˡ (identity G)
}
where open NaturalTransformation β
Dinatural⇒NT : DinaturalTransformation F′ G′ → NaturalTransformation F G
Dinatural⇒NT θ = ntHelper record
{ η = α
; commute = λ f → introˡ (identity G) ○ ⟺ (commute f) ○ ∘-resp-≈ʳ (elimʳ (identity F))
}
where open DinaturalTransformation θ
replaceˡ : ∀ {F′} → NaturalTransformation F G → F ≃ F′ → NaturalTransformation F′ G
replaceˡ {F′} α F≃F′ = ntHelper record
{ η = λ X → η X ∘ ⇐.η X
; commute = λ {X Y} f → begin
(η Y ∘ ⇐.η Y) ∘ F₁ F′ f ≈⟨ pullʳ (⇐.commute f) ⟩
η Y ∘ F₁ F f ∘ ⇐.η X ≈⟨ pullˡ (commute f) ○ assoc ⟩
F₁ G f ∘ η X ∘ ⇐.η X ∎
}
where open NaturalIsomorphism F≃F′
open NaturalTransformation α
replaceʳ : ∀ {G′} → NaturalTransformation F G → G ≃ G′ → NaturalTransformation F G′
replaceʳ {G′} α G≃G′ = ntHelper record
{ η = λ X → ⇒.η X ∘ η X
; commute = λ {X Y} f → begin
(⇒.η Y ∘ η Y) ∘ F₁ F f ≈⟨ pullʳ (commute f) ⟩
⇒.η Y ∘ F₁ G f ∘ η X ≈⟨ pullˡ (⇒.commute f) ○ assoc ⟩
F₁ G′ f ∘ ⇒.η X ∘ η X ∎
}
where open NaturalIsomorphism G≃G′
open NaturalTransformation α
module _ (F : Bifunctor C D E) where
-- there is natural transformation between two partially applied bifunctors.
appˡ-nat : ∀ {X Y} → (f : Category._⇒_ C X Y) → NaturalTransformation (appˡ F X) (appˡ F Y)
appˡ-nat f = F ∘ˡ (constNat f ※ⁿ idN)
appʳ-nat : ∀ {X Y} → (f : Category._⇒_ D X Y) → NaturalTransformation (appʳ F X) (appʳ F Y)
appʳ-nat f = F ∘ˡ (idN ※ⁿ constNat f)
module _ {F G : Bifunctor C D E} (α : NaturalTransformation F G) where
private
module C = Category C
module D = Category D
module E = Category E
appˡ′ : ∀ X → NaturalTransformation (appˡ F X) (appˡ G X)
appˡ′ X = α ∘ₕ idN
appʳ′ : ∀ X → NaturalTransformation (appʳ F X) (appʳ G X)
appʳ′ X = α ∘ₕ idN
-- unlift universe level
module _ {c ℓ ℓ′ e} {F G : Functor C (Setoids c ℓ)} (α : NaturalTransformation (LiftSetoids ℓ′ e ∘F F) (LiftSetoids ℓ′ e ∘F G)) where
open NaturalTransformation α
open Π
unlift-nat : NaturalTransformation F G
unlift-nat = ntHelper record
{ η = λ X → record
{ _⟨$⟩_ = λ x → lower (η X ⟨$⟩ lift x)
; cong = λ eq → lower (cong (η X) (lift eq))
}
; commute = λ f eq → lower (commute f (lift eq))
}
|
{
"alphanum_fraction": 0.6329009108,
"avg_line_length": 32.0619469027,
"ext": "agda",
"hexsha": "fd38778622d8de28aae8c4989a5aa92cd02dd5a8",
"lang": "Agda",
"max_forks_count": 64,
"max_forks_repo_forks_event_max_datetime": "2022-03-14T02:00:59.000Z",
"max_forks_repo_forks_event_min_datetime": "2019-06-02T16:58:15.000Z",
"max_forks_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_forks_repo_licenses": [
"MIT"
],
"max_forks_repo_name": "Code-distancing/agda-categories",
"max_forks_repo_path": "src/Categories/NaturalTransformation/Properties.agda",
"max_issues_count": 236,
"max_issues_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_issues_repo_issues_event_max_datetime": "2022-03-28T14:31:43.000Z",
"max_issues_repo_issues_event_min_datetime": "2019-06-01T14:53:54.000Z",
"max_issues_repo_licenses": [
"MIT"
],
"max_issues_repo_name": "Code-distancing/agda-categories",
"max_issues_repo_path": "src/Categories/NaturalTransformation/Properties.agda",
"max_line_length": 133,
"max_stars_count": 279,
"max_stars_repo_head_hexsha": "d9e4f578b126313058d105c61707d8c8ae987fa8",
"max_stars_repo_licenses": [
"MIT"
],
"max_stars_repo_name": "Trebor-Huang/agda-categories",
"max_stars_repo_path": "src/Categories/NaturalTransformation/Properties.agda",
"max_stars_repo_stars_event_max_datetime": "2022-03-22T00:40:14.000Z",
"max_stars_repo_stars_event_min_datetime": "2019-06-01T14:36:40.000Z",
"num_tokens": 1317,
"size": 3623
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.