├── .gitattributes
├── .gitignore
├── CNAME
├── LEAN.md
├── LICENSE
├── README.md
├── agda
├── Hopf.agda
└── src
│ └── Mahlo.agda
├── axio.html
├── cubicaltt
├── .travis.yml
├── HOPF.md
├── LICENSE
├── README.md
├── doc
│ └── ctt.syntax
└── src
│ ├── adj.ctt
│ ├── algebra.ctt
│ ├── bishop.ctt
│ ├── bool.ctt
│ ├── bool_theory.ctt
│ ├── buddhism.ctt
│ ├── bundle.ctt
│ ├── cat.ctt
│ ├── category.ctt
│ ├── coeq.ctt
│ ├── complex.ctt
│ ├── cones.ctt
│ ├── control.ctt
│ ├── csystem.ctt
│ ├── cw.ctt
│ ├── cwf.ctt
│ ├── em.ctt
│ ├── eq.ctt
│ ├── equiv.ctt
│ ├── eqv.ctt
│ ├── etale.ctt
│ ├── fun.ctt
│ ├── functor.ctt
│ ├── hedberg.ctt
│ ├── helix.ctt
│ ├── homology.ctt
│ ├── homotopy.ctt
│ ├── hopf.ctt
│ ├── hubspokes.ctt
│ ├── hvec.ctt
│ ├── impredicative.ctt
│ ├── infinitesimal.ctt
│ ├── infinity.ctt
│ ├── int.ctt
│ ├── interval.ctt
│ ├── iso.ctt
│ ├── iso_pi.ctt
│ ├── iso_sigma.ctt
│ ├── join.ctt
│ ├── k_theory.ctt
│ ├── lambek.ctt
│ ├── list.ctt
│ ├── list_theory.ctt
│ ├── localization.ctt
│ ├── logic.ctt
│ ├── manifold.ctt
│ ├── maybe.ctt
│ ├── maybe_nat.ctt
│ ├── maybe_theory.ctt
│ ├── mltt.ctt
│ ├── modality.ctt
│ ├── model.htt
│ ├── nat.ctt
│ ├── nat_theory.ctt
│ ├── null.ctt
│ ├── ordinal.ctt
│ ├── path.ctt
│ ├── pi.ctt
│ ├── pointed.ctt
│ ├── process.ctt
│ ├── prop.ctt
│ ├── proto.ctt
│ ├── pullback.ctt
│ ├── pushout.ctt
│ ├── quot.ctt
│ ├── quotient.ctt
│ ├── real.ctt
│ ├── recursion.ctt
│ ├── retract.ctt
│ ├── s1.ctt
│ ├── s2.ctt
│ ├── seq.ctt
│ ├── set.ctt
│ ├── sigma.ctt
│ ├── sip.ctt
│ ├── stream.ctt
│ ├── stream_theory.ctt
│ ├── subtype.ctt
│ ├── suspension.ctt
│ ├── swaptrans.ctt
│ ├── topos.ctt
│ ├── trunc.ctt
│ ├── ump.ctt
│ ├── univ.ctt
│ └── vector.ctt
├── doc
├── bsc.pdf
├── bsc.tex
├── msc.pdf
├── msc.tex
└── pl1.pdf
├── footer.pug
├── framework.js
├── header.pug
├── index.html
├── index.pug
├── main.css
├── package.json
└── theorems
└── Fermat's Last Theorem.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.js linguist-detectable=false
2 | *.css linguist-detectable=false
3 | *.scss linguist-detectable=false
4 | *.tex linguist-detectable=false
5 | *.sh linguist-detectable=false
6 | *.html linguist-detectable=false
7 | *.htm linguist-detectable=false
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 | package-lock.json
3 | header.html
4 | footer.html
5 | *.aux
6 | *.bbl
7 | *.blg
8 | *.log
9 | *.out
10 | *.toc
11 |
--------------------------------------------------------------------------------
/CNAME:
--------------------------------------------------------------------------------
1 | axio.groupoid.space
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | DHARMA License
2 |
3 | Copyright (c) 2016—2022 Groupoid Infinity
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | YOU CANNOT USE THIS SOFTWARE IN ANY (PROVABLE BY MONEY TRACE)
10 | PROCESS CHAIN OF EXTERMINATING UKRAINIANS BY ANY MEANS OF FASCIST
11 | ACTIONS AGAINST OUR TERRITORIAL INTEGRITY, CULTURAL DIVERSITY BY
12 | APPLYING MILITARY INVASIONS, ECONOMICAL WARS, HUMANITARIAN DISASTERS,
13 | ARTFICIAL HOLODOMORS, GENOCIDE, RAPING, LOOTING, ROBBERIES, SPREADING
14 | FAKE INFORMATION, AND OTHER CONTEMPORARY WEAPONS OF WAR AT SCALE
15 | OR IN INVIDIVUAL MANNER.
16 |
17 | YOU CANNOT USE THIS SOFTWARE BY ANY MEANS IN INTEREST OF LEGAL
18 | ENTITIES OR INDIVIDUALS WHO IS SUPPORTING NOW OR WAS SUPPORTING
19 | BACK THEN FASCISM, RUSCISM, COMMUNISM, CHAUVINISM, HUMILIATION,
20 | AND OTHER SUPPRESSIVE IDEOLOGIES IN DIFFERENT EXPRESSIONS.
21 |
22 | STOP KILLING UKRAINIANS,
23 | THE COUNTER RENDERS TENS OF MILLIONS.
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 |
--------------------------------------------------------------------------------
/agda/Hopf.agda:
--------------------------------------------------------------------------------
1 | {-# OPTIONS --cubical --safe #-}
2 |
3 | module Hopf where
4 |
5 | open import Cubical.Core.Everything
6 | open import Cubical.Foundations.Prelude
7 |
8 | -- S¹: Circle
9 | data S¹ : Set where
10 | base : S¹
11 | loop : base ≡ base
12 |
13 | -- S²: 2-Sphere
14 | data S² : Set where
15 | base : S²
16 | surf : PathP (λ i → base ≡ base) refl refl
17 |
18 | -- S³: 3-Sphere (simplified with a point and a 3D generator)
19 | data S³ : Set where
20 | base : S³
21 | loop3 : PathP (λ i → PathP (λ j → base ≡ base) refl refl) refl refl
22 |
23 | -- S⁴: 4-Sphere
24 | data S⁴ : Set where
25 | base : S⁴
26 | surf4 : PathP (λ i → PathP (λ j → PathP (λ k → base ≡ base) refl refl) refl refl) refl refl
27 |
28 | -- H₁: Hopf fibration total space (S³)
29 | data H₁ : Set where
30 | h₁ : S² → S¹ → H₁
31 | twist₁ : (b : S²) (f : S¹) → h₁ b f ≡ h₁ b f
32 | twist₁-coh : (b : S²) → twist₁ b base ≡ λ j → h₁ b (loop j)
33 |
34 | loop3-path : (i j : I) → S³
35 | loop3-path i j = loop3 i j j
36 |
37 | -- H₂: Complex Hopf fibration total space (S⁷)
38 | data H₂ : Set where
39 | h₂ : S⁴ → S³ → H₂
40 | twist₂ : (b : S⁴) (f : S³) → h₂ b f ≡ h₂ b f
41 | twist₂-coh : (b : S⁴) → Square (twist₂ b base) (twist₂ b base) refl (λ j → h₂ b (loop3-path i1 j))
42 |
43 | -- Projection
44 | π₁ : H₁ → S²
45 | π₁ (h₁ b f) = b
46 | π₁ (twist₁ b f i) = b
47 | π₁ (twist₁-coh b i j) = b
48 |
49 | -- Projection
50 | π₂ : H₂ → S⁴
51 | π₂ (h₂ b f) = b
52 | π₂ (twist₂ b f i) = b
53 | π₂ (twist₂-coh b i j) = b
54 |
55 | -- Hopf path in H₁
56 | hopf-path : h₁ base base ≡ h₁ base base
57 | hopf-path = twist₁ base base
58 |
59 | -- Projected loop in S²
60 | hopf-loop : base ≡ base
61 | hopf-loop = cong π₁ hopf-path
62 |
63 | -- Hopf path in H₂ (1D path over S³’s loop)
64 | hopf-path-2 : h₂ base base ≡ h₂ base base
65 | hopf-path-2 = twist₂ base base
66 |
67 | -- Element of π₂(S²) using S²’s surf
68 | π₂-s₂-elem : PathP (λ i → base ≡ base) refl refl
69 | π₂-s₂-elem = surf
70 |
71 | record Real-Hopf-Fib-Rules : Set where
72 | -- Formation: Fib₁ is a type family over S²
73 | field
74 | Fib₁ : S² → Set
75 |
76 | -- Introduction Rules (Constructors for the fiber)
77 | field
78 | fib₁-intro : (b : S²) → S¹ → Fib₁ b
79 | twist₁-fib : (b : S²) (f : S¹) → fib₁-intro b f ≡ fib₁-intro b f
80 | twist₁-coh-fib : (b : S²) (i : I) → twist₁-fib b base i ≡ fib₁-intro b (loop i)
81 |
82 | -- Elimination Rule (Dependent elimination over the fibration)
83 | field
84 | Fib₁-elim : {C : (b : S²) → Fib₁ b → Set}
85 | → (c-h₁ : (b : S²) (f : S¹) → C b (fib₁-intro b f))
86 | → (c-twist₁ : (b : S²) (f : S¹) → PathP (λ i → C b (twist₁-fib b f i)) (c-h₁ b f) (c-h₁ b f))
87 | → (c-twist₁-coh : (b : S²) → PathP (λ i → C b (fib₁-intro b (loop i))) (c-h₁ b base) (c-h₁ b (loop i1)))
88 | → (b : S²) (x : Fib₁ b) → C b x
89 |
90 | -- Computation Rules
91 | field
92 | Fib₁-comp : {C : (b : S²) → Fib₁ b → Set}
93 | → (c-h₁ : (b : S²) (f : S¹) → C b (fib₁-intro b f))
94 | → (c-twist₁ : (b : S²) (f : S¹) → PathP (λ i → C b (twist₁-fib b f i)) (c-h₁ b f) (c-h₁ b f))
95 | → (c-twist₁-coh : (b : S²) → PathP (λ i → C b (fib₁-intro b (loop i))) (c-h₁ b base) (c-h₁ b (loop i1)))
96 | → (b : S²) (f : S¹)
97 | → Fib₁-elim c-h₁ c-twist₁ c-twist₁-coh b (fib₁-intro b f) ≡ c-h₁ b f
98 |
--------------------------------------------------------------------------------
/agda/src/Mahlo.agda:
--------------------------------------------------------------------------------
1 | open import Agda.Primitive
2 |
3 | mutual
4 | data V : Set₁ where
5 | pi_ : (x : V) → (Elv x → V) → V
6 | uni_ : (f : (x : V) → (Elv x → V) → V)
7 | (g : (x : V) → (y : Elv x → V) → (Elv (f x y) → V) → V) → V
8 |
9 | Elv : V → Set₁ -- Changed from Set to Set₁
10 | Elv (pi_ a b) = (x : Elv a) → Elv (b x)
11 | Elv (uni_ f g) = Universe f g
12 |
13 | data Universe (F : (x : V) → (Elv x → V) → V) (G : (x : V) → (y : Elv x → V) → (Elv (F x y) → V) → V)
14 | : Set₁ where -- Changed to Set₁
15 | fun_ : (x : Universe F G) → (V → Universe F G) → Universe F G
16 | f_ : (x : Universe F G) → (V → Universe F G) → Universe F G
17 | g_ : (x : Universe F G) (y : Elv (Elt F G x) → V)
18 | (z : Elv (F (Elt F G x) (λ (a : Elv (Elt F G x)) → y a))) → Universe F G
19 |
20 | data Elt (f : (x : V) → (Elv x → V) → V) (g : (x : V) → (y : Elv x → V) → (Elv (f x y) → V) → V)
21 | : Universe f g → Set₁ where -- Changed to Set₁
22 | elt : {u : Universe f g} → V → Elt f g u
23 |
--------------------------------------------------------------------------------
/cubicaltt/.travis.yml:
--------------------------------------------------------------------------------
1 | language: generic
2 |
3 | notifications:
4 | email:
5 | - maxim@synrc.com
6 | webhooks:
7 | on_success: change
8 | on_failure: change
9 | on_start: always
10 |
11 | cache:
12 | directories:
13 | - $HOME/.stack
14 |
15 | addons:
16 | apt:
17 | packages:
18 | - libgmp-dev
19 |
20 | before_install:
21 | - mkdir -p ~/.local/bin
22 | - export PATH=$HOME/.local/bin:$PATH
23 | - ARCH=https://www.stackage.org/stack/linux-x86_64
24 | - travis_retry curl -L $ARCH | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'
25 |
26 | install:
27 | - git clone git://github.com/mortberg/cubicaltt && cd cubicaltt
28 | - stack build
29 | - CUBICAL=$(stack path --local-install-root)/bin/cubical
30 | - cd ..
31 | - for i in src/*.ctt; do $CUBICAL -b $i; done
32 |
--------------------------------------------------------------------------------
/cubicaltt/HOPF.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.org/groupoid/hopf)
2 |
3 | Groupoid Infinity
4 | =================
5 |
6 | The Groupoid Infinity Cubical Base Library is compatible with `hcomptrans` branch of `cubicaltt` that fully supports recursive HITs. As example Hopf fibration is given formally due to Guillaume Brunerie:
7 |
8 | ```
9 | rot: (x : S1) -> Path S1 x x = split
10 | base -> loop1
11 | loop @ i -> constSquare S1 base loop1 @ i
12 |
13 | mu : S1 -> equiv S1 S1 = split
14 | base -> idEquiv S1
15 | loop @ i -> equivPath S1 S1 (idEquiv S1)
16 | (idEquiv S1) ( \(x : S1) -> rot x @ j) @ i
17 |
18 | H : S2 -> U = split
19 | north -> S1
20 | south -> S1
21 | merid x @ i -> ua S1 S1 (mu x) @ i
22 |
23 | total : U = (c : S2) * H c
24 | ```
25 |
26 | Credits
27 | -------
28 |
29 | * Maxim Sokhatsky
30 |
31 |
--------------------------------------------------------------------------------
/cubicaltt/LICENSE:
--------------------------------------------------------------------------------
1 | DHARMA License
2 |
3 | Copyright (c) 2016—2022 Groupoid Infinity
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any
6 | purpose with or without fee is hereby granted, provided that the above
7 | copyright notice and this permission notice appear in all copies.
8 |
9 | YOU CANNOT USE THIS SOFTWARE IN ANY (PROVABLE BY MONEY TRACE)
10 | PROCESS CHAIN OF EXTERMINATING UKRAINIANS BY ANY MEANS OF FASCIST
11 | ACTIONS AGAINST OUR TERRITORIAL INTEGRITY, CULTURAL DIVERSITY BY
12 | APPLYING MILITARY INVASIONS, ECONOMICAL WARS, HUMANITARIAN DISASTERS,
13 | ARTFICIAL HOLODOMORS, GENOCIDE, RAPING, LOOTING, ROBBERIES, SPREADING
14 | FAKE INFORMATION, AND OTHER CONTEMPORARY WEAPONS OF WAR AT SCALE
15 | OR IN INVIDIVUAL MANNER.
16 |
17 | YOU CANNOT USE THIS SOFTWARE BY ANY MEANS IN INTEREST OF LEGAL
18 | ENTITIES OR INDIVIDUALS WHO IS SUPPORTING NOW OR WAS SUPPORTING
19 | BACK THEN FASCISM, RUSCISM, COMMUNISM, CHAUVINISM, HUMILIATION,
20 | AND OTHER SUPPRESSIVE IDEOLOGIES IN DIFFERENT EXPRESSIONS.
21 |
22 | STOP KILLING UKRAINIANS,
23 | THE COUNTER RENDERS TENS OF MILLIONS.
24 |
25 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
26 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
27 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
28 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
29 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
30 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
31 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
32 |
--------------------------------------------------------------------------------
/cubicaltt/README.md:
--------------------------------------------------------------------------------
1 | CCHM
2 | ====
3 |
4 | The Groupoid Infinity CCHM cubical base library
5 | is dedicated to [cubical](https://github.com/mortberg/cubicaltt)-compatible
6 | type checkers based on homotopy interval [0,1] and MLTT as a core.
7 | The library follows HoTT foundation and mathematics partitioning: the `Foundations`
8 | chapter covers the very basics of the cubical programming language; the `Mathematics`
9 | chapter covers the formal mathematics library of models and theorems.
10 | This library is best to read with HoTT book at http://groupoid.space/misc/library/
11 |
12 |
--------------------------------------------------------------------------------
/cubicaltt/doc/ctt.syntax:
--------------------------------------------------------------------------------
1 | # Cubical Syntax for Midnight Commander
2 |
3 | context default
4 | keyword whole Pi white
5 | keyword whole lam white
6 | keyword whole app white
7 | keyword whole ap white
8 | keyword whole fiber white
9 | keyword whole subst white
10 | keyword whole contr white
11 | keyword whole inv white
12 | keyword whole isContr white
13 | keyword whole transport white
14 | keyword whole cong white
15 | keyword whole Sigma white
16 | keyword whole pi1 white
17 | keyword whole pi2 white
18 | keyword whole pr1 white
19 | keyword whole pr2 white
20 | keyword whole fst white
21 | keyword whole snd white
22 | keyword whole funext white
23 | keyword whole happly white
24 | keyword whole Path white
25 | keyword whole PathP white
26 | keyword whole J white
27 | keyword whole refl white
28 | keyword whole sym white
29 | keyword whole trans white
30 | keyword whole isSet white
31 | keyword whole isProp white
32 | keyword whole isGroupoid white
33 | keyword whole propQuot white
34 | keyword whole setQuot white
35 | keyword whole grpdQuot white
36 | keyword whole propTrunc white
37 | keyword whole setTrunc white
38 | keyword whole grpdTrunc white
39 | keyword whole diff white
40 | keyword whole conjugate white
41 | keyword whole empty white
42 | keyword whole unit white
43 | keyword whole data cyan
44 | keyword whole split cyan
45 | keyword whole opaque cyan
46 | keyword whole import cyan
47 | keyword whole module cyan
48 | keyword whole where cyan
49 | keyword .1 cyan
50 | keyword .2 cyan
51 | keyword whole comp cyan
52 | keyword whole fill cyan
53 | keyword > cyan
54 | keyword < cyan
55 | keyword * cyan
56 | keyword | cyan
57 | keyword - cyan
58 | keyword whole /\\ cyan
59 | keyword whole \\/ cyan
60 | keyword @ cyan
61 | keyword = cyan
62 | keyword [ cyan
63 | keyword ] cyan
64 | keyword ( cyan
65 | keyword ) cyan
66 | keyword { cyan
67 | keyword } cyan
68 | keyword , cyan
69 | keyword : cyan
70 | keyword ; cyan
71 |
72 | context exclusive -- \n brightred
73 | context exclusive {- -} brightred
74 |
75 | # context exclusive -- \n yellow
76 | # context exclusive {- -} yellow
77 |
--------------------------------------------------------------------------------
/cubicaltt/src/adj.ctt:
--------------------------------------------------------------------------------
1 | {- Category Theory:
2 | - Natural Transformations;
3 | - Kan Extensions;
4 | - Limits;
5 | - Adjunctions.
6 | Copyright (c) Groupoid Infinity, 2017-2018.
7 |
8 | HoTT 9.3 Adjunctions. -}
9 |
10 | module adj where
11 | import cat
12 | import fun
13 |
14 | unitCat: precategory = ((Ob,Hom),id,c,HomSet,L,R,Q) where
15 | Ob: U = unit
16 | Hom (A B: Ob): U = unit
17 | id (A: Ob): Hom A A = tt
18 | c (A B C: Ob) (f: Hom A B) (g: Hom B C): Hom A C = tt
19 | HomSet (A B: Ob): isSet (Hom A B) = setUnit
20 | L (A B: Ob): (f: unit) -> Path unit (c A A B (id A) f) f = split tt -> tt
21 | R (A B: Ob): (f: unit) -> Path unit (c A B B f (id B)) f = split tt -> tt
22 | Q (A B C D: Ob) (f: Hom A B) (g: Hom B C) (h: Hom C D)
23 | : Path (Hom A D) (c A C D (c A B C f g) h) (c A B D f (c B C D g h)) = refl unit tt
24 |
25 | isNaturalTrans (C D: precategory)
26 | (F G: catfunctor C D)
27 | (eta: (x: carrier C) -> hom D (F.1 x) (G.1 x)): U
28 | = (x y: carrier C) (h: hom C x y) ->
29 | Path (hom D (F.1 x) (G.1 y))
30 | (compose D (F.1 x) (F.1 y) (G.1 y) (F.2.1 x y h) (eta y))
31 | (compose D (F.1 x) (G.1 x) (G.1 y) (eta x) (G.2.1 x y h))
32 |
33 | -- Awodey CT 7.6. Natural transformation
34 | -- Natural Transformation
35 | ntrans (C D: precategory) (F G: catfunctor C D): U
36 | = (eta: (x: carrier C) -> hom D (F.1 x) (G.1 x))
37 | * (isNaturalTrans C D F G eta)
38 |
39 | -- Kan Extensions
40 | extension (A B C: precategory) (K: catfunctor A B) (G: catfunctor A C) : U
41 | = (F: catfunctor B C)
42 | * (counit: ntrans A C (compFunctor A B C K F) G)
43 | * unit
44 |
45 | -- Functor to Unit Category
46 | unitFunc (C: precategory): catfunctor C unitCat
47 | = undefined
48 |
49 | -- Cone as Kan Extension
50 | cone (J C: precategory) (D: catfunctor J C): U
51 | = extension J unitCat C (unitFunc J) D
52 |
53 | -- universality of Kan Extension
54 | universality (A B C: precategory)
55 | (K: catfunctor A B) (G: catfunctor A C)
56 | (s t: extension A B C K G) : U
57 | = undefined
58 |
59 | -- Right Kan Extension
60 | ran (A B C: precategory) (K: catfunctor A B) (G: catfunctor A C) : U
61 | = (x: extension A B C K G) * ((y: extension A B C K G)
62 | -> isContr (universality A B C K G x y))
63 |
64 | -- Limit
65 | limit (J C: precategory) (D: catfunctor J C): U
66 | = ran J unitCat C (unitFunc J) D
67 |
68 | -- ExtUniv : Extension K G → Set _
69 | -- ExtUniv (extension S (nt α _)) = Σ (S ⇒ F) λ { (nt β _) → (∀ X → ε X ∘ β (apply K X) ≡ α X) }
70 |
71 | ntransL (C D: precategory) (F G: catfunctor C D) (f: ntrans C D F G) (B: precategory) (H: catfunctor B C)
72 | : ntrans B D (compFunctor B C D H F) (compFunctor B C D H G)
73 | = (eta, p) where
74 | F': catfunctor B D = compFunctor B C D H F
75 | G': catfunctor B D = compFunctor B C D H G
76 | eta (x: carrier B): hom D (F'.1 x) (G'.1 x) = f.1 (H.1 x)
77 | p (x y: carrier B) (h: hom B x y): Path (hom D (F'.1 x) (G'.1 y))
78 | (compose D (F'.1 x) (F'.1 y) (G'.1 y) (F'.2.1 x y h) (eta y))
79 | (compose D (F'.1 x) (G'.1 x) (G'.1 y) (eta x) (G'.2.1 x y h))
80 | = f.2 (H.1 x) (H.1 y) (H.2.1 x y h)
81 |
82 | ntransR (C D: precategory) (F G: catfunctor C D) (f: ntrans C D F G) (E: precategory) (H: catfunctor D E)
83 | : ntrans C E (compFunctor C D E F H) (compFunctor C D E G H)
84 | = (eta, p) where
85 | F': catfunctor C E = compFunctor C D E F H
86 | G': catfunctor C E = compFunctor C D E G H
87 | eta (x: carrier C): hom E (F'.1 x) (G'.1 x) = H.2.1 (F.1 x) (G.1 x) (f.1 x)
88 | p (x y: carrier C) (h: hom C x y): Path (hom E (F'.1 x) (G'.1 y))
89 | (compose E (F'.1 x) (F'.1 y) (G'.1 y) (F'.2.1 x y h) (eta y))
90 | (compose E (F'.1 x) (G'.1 x) (G'.1 y) (eta x) (G'.2.1 x y h))
91 | = comp (<_> hom E (F'.1 x) (G'.1 y)) (H.2.1 (F.1 x) (G.1 y) (f.2 x y h @ i))
92 | [ (i = 0) -> H.2.2.2 (F.1 x) (F.1 y) (G.1 y) (F.2.1 x y h) (f.1 y),
93 | (i = 1) -> H.2.2.2 (F.1 x) (G.1 x) (G.1 y) (f.1 x) (G.2.1 x y h) ]
94 |
95 | hom3 (C D: precategory)
96 | (F: catfunctor C D)
97 | (G: catfunctor C D)
98 | (left: ntrans C D F G)
99 | (right: ntrans C D F G): U = undefined
100 |
101 | -- Adjointness Property
102 | -- NOTE: Adjunction is a special case of signature class of 3-morphisms
103 | areAdjoint (C D: precategory)
104 | (F: catfunctor D C)
105 | (G: catfunctor C D)
106 | (unit: ntrans D D (idFunctor D) (compFunctor D C D F G))
107 | (counit: ntrans C C (compFunctor C D C G F) (idFunctor C)): U
108 | = prod ((x: carrier C) -> Path (hom D (G.1 x) (G.1 x)) (path D (G.1 x)) (h0 x))
109 | ((x: carrier D) -> Path (hom C (F.1 x) (F.1 x)) (path C (F.1 x)) (h1 x)) where
110 | h0 (x: carrier C) : hom D (G.1 x) (G.1 x) = compose D (G.1 x) (G.1 (F.1 (G.1 x))) (G.1 x)
111 | ((ntransL D D (idFunctor D) (compFunctor D C D F G) unit C G).1 x)
112 | ((ntransR C C (compFunctor C D C G F) (idFunctor C) counit D G).1 x)
113 | h1 (x: carrier D) : hom C (F.1 x) (F.1 x) = compose C (F.1 x) (F.1 (G.1 (F.1 x))) (F.1 x)
114 | ((ntransR D D (idFunctor D) (compFunctor D C D F G) unit C F).1 x)
115 | ((ntransL C C (compFunctor C D C G F) (idFunctor C) counit D F).1 x)
116 |
117 | -- Adjoint of two Natural Transformations
118 | adjoint (C D: precategory) (F: catfunctor D C) (G: catfunctor C D): U
119 | = (unit: ntrans D D (idFunctor D) (compFunctor D C D F G))
120 | * (counit: ntrans C C (compFunctor C D C G F) (idFunctor C))
121 | * areAdjoint C D F G unit counit
122 |
123 |
--------------------------------------------------------------------------------
/cubicaltt/src/bishop.ctt:
--------------------------------------------------------------------------------
1 | {- Bishop Equivalence:
2 | - Equivalence Classes.
3 | Copyright (c) Groupoid Infinity, 2017-2018. -}
4 |
5 | module bishop where
6 | import proto
7 | import subtype
8 | import path
9 |
10 | -- Propositional Equality By Errett Bishop
11 | hrel (X: U): U = X -> X -> PROP
12 | isrefl (X: U) (R: hrel X): U = (x: X) -> (R x x).1
13 | issymm (X: U) (R: hrel X): U = (x1 x2: X) -> (R x1 x2).1 -> (R x2 x1).1
14 | istrans (X: U) (R: hrel X): U = (x1 x2 x3: X) -> (R x1 x2).1 -> (R x2 x3).1 -> (R x1 x3).1
15 | ispreorder (X: U) (R: hrel X): U = prod (istrans X R) (isrefl X R)
16 | iseqrel (X: U) (R: hrel X): U = prod (ispreorder X R) (issymm X R)
17 | eqrel (X: U) : U = (R: hrel X) * (iseqrel X R)
18 | eqrelrefl (X: U) (R: eqrel X): isrefl X R.1 = R.2.1.2
19 | eqrelsymm (X: U) (R: eqrel X): issymm X R.1 = R.2.2
20 | eqreltrans (X: U) (R: eqrel X): istrans X R.1 = R.2.1.1
21 |
22 | iseqrelpair (A B: U) (R0: hrel A) (R1: hrel B) (E0: iseqrel A R0) (E1: iseqrel B R1): iseqrel (prod A B) (hrelpair A B R0 R1)
23 | = ((tax, rax), sax) where
24 | T : U = prod A B
25 | R : hrel T = hrelpair A B R0 R1
26 | rax : isrefl T R = \ (t0 : T) -> (E0.1.2 t0.1, E1.1.2 t0.2)
27 | sax : issymm T R = \ (t0 t1 : T) (e : (R t0 t1).1) -> (E0.2 t0.1 t1.1 e.1, E1.2 t0.2 t1.2 e.2)
28 | tax : istrans T R = \ (t0 t1 t2 : T) (e0 : (R t0 t1).1) (e1 : (R t1 t2).1) ->
29 | (E0.1.1 t0.1 t1.1 t2.1 e0.1 e1.1, E1.1.1 t0.2 t1.2 t2.2 e0.2 e1.2)
30 |
31 | eqrelpair (A B : U) (R0 : eqrel A) (R1 : eqrel B) : eqrel (prod A B)
32 | = (hrelpair A B R0.1 R1.1, iseqrelpair A B R0.1 R1.1 R0.2 R1.2)
33 |
34 | iseqclasspair (A B : U) (R0 : hrel A) (R1 : hrel B) (H0 : hsubtypes A)
35 | (H1 : hsubtypes B) (E0 : iseqclass A R0 H0) (E1 : iseqclass B R1 H1)
36 | : iseqclass (prod A B) (hrelpair A B R0 R1) (hsubtypespair A B H0 H1)
37 | = let
38 | H : hsubtypes (prod A B) = hsubtypespair A B H0 H1
39 | a (P : PROP) (f : carr (prod A B) H -> P.1) : P.1
40 | = let
41 | g (x0 : carr A H0) : P.1 = let h (x1 : carr B H1) : P.1 = f ((x0.1, x1.1), (x0.2, x1.2)) in E1.1.1 P h
42 | in E0.1.1 P g
43 | b (x0 x1 : prod A B) (r : (hrelpair A B R0 R1 x0 x1).1) (h0 : (H x0).1) : (H x1).1
44 | = (E0.1.2 x0.1 x1.1 r.1 h0.1, E1.1.2 x0.2 x1.2 r.2 h0.2)
45 | c (x0 x1 : prod A B) (h0 : (H x0).1) (h1 : (H x1).1) : (hrelpair A B R0 R1 x0 x1).1
46 | = (E0.2 x0.1 x1.1 h0.1 h1.1, E1.2 x0.2 x1.2 h0.2 h1.2)
47 | in ((a, b), c)
48 |
--------------------------------------------------------------------------------
/cubicaltt/src/bool.ctt:
--------------------------------------------------------------------------------
1 | {- Run-time Bool Type:
2 | - Bool type.
3 | - Theorems are in bool_theory module.
4 | Copyright (c) Groupoid Infinity, 2014-2018.
5 |
6 | HoTT 1.8 The type of booleans -}
7 |
8 | module bool where
9 | import proto
10 |
11 | data bool = false | true
12 |
13 | negation: bool -> bool = split { false -> true ; true -> false }
14 | or: bool -> bool -> bool = split { false -> idfun bool ; true -> lambda bool bool true }
15 | and: bool -> bool -> bool = split { false -> lambda bool bool false ; true -> idfun bool }
16 |
17 | boolEq: bool -> bool -> bool = lambda bool (bool -> bool) negation
18 | boolRec (A: U) (f t: A): bool -> A = split { false -> f ; true -> t }
19 | boolInd (A:bool->U) (f:A false) (t: A true): (n:bool) -> A n = split { false -> f ; true -> t }
20 |
--------------------------------------------------------------------------------
/cubicaltt/src/buddhism.ctt:
--------------------------------------------------------------------------------
1 | module buddhism where
2 | import path
3 |
4 | -- from Favonia's PhD
5 |
6 | concept (o: U): U = o -> U
7 | allpaths (o: U): U = (x y: o) -> Path o x y
8 | nondual (o: U) (p: concept o): U = (x y: o) -> Path U (p x) (p y)
9 |
10 | encode (o:U): ((p: concept o) -> nondual o p) -> allpaths o
11 | = \(nd: (p: concept o) -> nondual o p) (a b: o)
12 | -> coerce (Path o a a) (Path o a b) (nd (\(z:o)->Path o a z) a b) (refl o a)
13 |
14 | decode (o:U): allpaths o -> ((p: concept o) -> nondual o p)
15 | = \(all: allpaths o)(p: concept o)(x y: o) -> cong o U p x y (all x y)
16 |
--------------------------------------------------------------------------------
/cubicaltt/src/bundle.ctt:
--------------------------------------------------------------------------------
1 | {- Fiber Bundle: https://groupoid.space/mltt/types/bundle/
2 | - Fiber Bundle;
3 | - Trivial Fiber Bundle, Trivial = Pi;
4 | - Local F-Bundle (4 definitions).
5 | Copyright (c) Groupoid Infinity, 2014-2018. -}
6 |
7 | module bundle where
8 | import iso
9 | import infinitesimal
10 | import pullback
11 | import trunc
12 |
13 | -- Fiber Bundle
14 |
15 | -- A fiber bundle p : E -> B is required to be locally trivial,
16 | -- which might be witnessed by a pullback square like this:
17 |
18 | -- V × F ------> E
19 | -- |_| |
20 | -- v*p | (pb) | p
21 | -- | |
22 | -- v v
23 | -- V ---v--> B
24 |
25 | -- NOTE: there is twisted hidden structure in p
26 | -- U = neighborhood in base B
27 | -- fibers locally behave like a products, but could be twisted
28 |
29 | -- h
30 | -- |
31 | -- p-inv (V) -> V * F
32 | -- | /
33 | -- p --| /-- pi1
34 | -- v /
35 | -- V
36 | --
37 | -- pr_1 o h = p
38 |
39 | -- F_B -> E -> B -- fiber bundle (F_B,E,p,B),
40 | -- F: B -> U -- fiber, ex. Vector Space, Section Space, Dependent Product
41 | -- E -- total topological space
42 | -- B -- base space
43 | -- h: F -> E -- homeomorphism
44 | -- p: E -> B -- surjective projection map
45 | -- p^-1: B -> E -- section (y: B) = (x: E) * p (x) = y
46 | -- E=(y:B)*p^-1 y -- total space
47 | -- p^-1 = F -- fiber is iso F_B
48 | -- T. E = B * F_B -- fiber bundle called trivial if total space is a cartesian product
49 |
50 | Family (B: U): U = B -> U
51 | Fibration (B: U): U = (X: U) * (X -> B)
52 |
53 | -- Trivial Fiber Bundle (F,B*F,pi1,B) equals Dependent Family F:B->U
54 | --
55 | -- Agda Syntax:
56 | -- https://paolocapriotti.com/blog/2013/02/20/families-and-fibrations/
57 | --
58 | -- F y = fiber (total B F) B (trivial B F) y (A)
59 | -- = (z: E) * Path B z.1 y
60 | -- = (z: B) * (k: F z) * Path B z y (B)
61 | -- = (x y: B) * (_: Path B x y) * (F y)
62 | -- = (_: isContr B) * (F y) (C)
63 | -- = F y (D)
64 |
65 | fiber (A B: U) (f: A -> B) (y: B)
66 | : U
67 | = (x: A) * Path B (f x) y
68 |
69 | encode (B: U) (F: B -> U) (y: B)
70 | : fiber (Sigma B F) B (pi1 B F) y -> F y
71 | = \ (x: fiber (Sigma B F) B (pi1 B F) y)
72 | -> subst B F x.1.1 y x.2 x.1.2
73 |
74 | decode (B: U) (F: B -> U) (y: B)
75 | : F y -> fiber (Sigma B F) B (pi1 B F) y
76 | = \ (x: F y) -> ((y,x),refl B y)
77 |
78 |
79 | lem2 (B: U) (F: B -> U) (y: B) (x: F y)
80 | : Path (F y) (comp (F (refl B y @ i)) x []) x
81 | = comp (F (refl B y @ j/\i)) x [(j=1) -> x]
82 |
83 | lem3 (B: U) (F: B -> U) (y: B) (x: fiber (Sigma B F) B (pi1 B F) y)
84 | : Path (fiber (Sigma B F) B (pi1 B F) y) ((y,encode B F y x),refl B y) x
85 | = ((x.2 @ -i,comp ( F (x.2 @ -i /\ j))
86 | x.1.2 [(i=1) -> <_> x.1.2 ]), x.2 @ -i \/ j)
87 |
88 | TrivialEqualsPi (B: U) (F: B -> U) (y: B)
89 | : Path U (fiber (Sigma B F) B (pi1 B F) y) (F y)
90 | = isoPath T A f g s t where
91 | T: U = fiber (Sigma B F) B (pi1 B F) y
92 | A: U = F y
93 | f: T -> A = encode B F y
94 | g: A -> T = decode B F y
95 | s (x: A): Path A (f (g x)) x = lem2 B F y x
96 | t (x: T): Path T (g (f x)) x = lem3 B F y x
97 |
98 | -- Local F-Bundle
99 |
100 | -- Definition (1) Dependent
101 | isFBundle1 (B: U) (p: B -> U) (F: U): U
102 | = (_: (b: B) -> isContr (Path U (p b) F))
103 | * ((x: Sigma B p) -> B)
104 |
105 | -- Definition (2) Dependent
106 | isFBundle2 (B: U) (p: B -> U) (F: U): U
107 | = (V: U)
108 | * (v: surjective V B)
109 | * ((x: V) -> Path U (p (v.1 x)) F)
110 |
111 | -- Definition (3) Non-Dependent
112 | im1 (A B: U) (f: A -> B): U = (b: B) * propTrunc ((a:A) * Path B (f a) b)
113 | BAut (F: U): U = im1 unit U (\(x: unit) -> F)
114 | unitIm1 (A B: U) (f: A -> B): im1 A B f -> B = \(x: im1 A B f) -> x.1
115 | unitBAut (F: U): BAut F -> U = unitIm1 unit U (\(x: unit) -> F)
116 | isFBundle3 (E B: U) (p: E -> B) (F: U): U
117 | = (X: B -> BAut F)
118 | * (classify B (BAut F) (\(b: B) -> fiber E B p b) (unitBAut F) X) where
119 | classify (A' A: U) (E': A' -> U) (E: A -> U) (f: A' -> A): U
120 | = (x: A') -> Path U (E'(x)) (E(f(x)))
121 |
122 | -- Definition (4) Non-Dependent
123 | isFBundle4 (E B: U) (p: E -> B) (F: U): U
124 | = (V: U)
125 | * (v: surjective V B)
126 | * (v': prod V F -> E)
127 | * pullbackSq (prod V F) E V B p v.1 v' (\(x: prod V F) -> x.1)
128 |
129 | -- Theorem 4.3.7
130 | unifamOverBAut (F: U): U = (x: BAut F) * U
131 | FBundle (E B: U) (p: E -> B) (F: U) (x: isFBundle3 E B p F) (b: B)
132 | : pullbackSq E B (unifamOverBAut F) (BAut F)
133 | x.1 (\(x: unifamOverBAut F) -> x.1)
134 | p (\(y: E) -> (x.1 (p y),F))
135 | = undefined
136 |
137 |
--------------------------------------------------------------------------------
/cubicaltt/src/coeq.ctt:
--------------------------------------------------------------------------------
1 | module coeq where
2 | import nat
3 |
4 | data coeq (A B: U) (f g: A -> B)
5 | = inC (_: B)
6 | | glueC (a: A) [(i=0) -> inC (f a), (i=1) -> inC (g a) ]
7 |
8 | coequRec (A B C : U) (f g : A -> B) (h: B -> C) (y: (x : A) -> Path C (h (f x)) (h (g x)))
9 | : (z : coeq A B f g) -> C
10 | = split@((z : coeq A B f g) -> C) with { inC x -> h x ; glueC x @ i -> y x @ i }
11 |
12 | coequInd (A B : U) (f g : A -> B) (C : coeq A B f g -> U) (ix : (b : B) -> C (inC b))
13 | (y: (x : A) -> PathP ( C (glueC {coeq A B f g} x @ i)) (ix (f x)) (ix (g x)))
14 | : (z : coeq A B f g) -> C z
15 | = split@((z : coeq A B f g) -> C z) with { inC x -> ix x ; glueC x @ i -> y x @ i }
16 |
17 | data coeqP (A B: U) (p : A -> (b1 b2: B) * (_: Path B b1 b2) * (Path B b1 b2))
18 | = inP (b: B)
19 | | glueP (a:A) [(i=0) -> inP (((p a).2.2.1) @ 0), (i=1) -> inP (((p a).2.2.2) @ 1) ]
20 |
21 | data pushout (A B C: U) (f: A -> B) (g: A -> C)
22 | = inl (_: B)
23 | | inr (_: C)
24 | | push (a: A) [ (i=0) -> inl (f a), (i=1) -> inr (g a) ]
25 |
26 | data colimit (A : nat -> U) (f : (n : nat) -> A n -> A (succ n))
27 | = inc (n : nat) (x: A n)
28 | | com (n : nat) (a: A n) [ (i=0) -> inc (succ n) (f n a), (i=1) -> inc n a]
29 |
--------------------------------------------------------------------------------
/cubicaltt/src/complex.ctt:
--------------------------------------------------------------------------------
1 | {- Simplicial Comlexes:
2 | - Simple, Complex, Simplicial Set.
3 | Copyright (c) Groupoid Infinity, 2016-2018. -}
4 |
5 | module complex where
6 |
--------------------------------------------------------------------------------
/cubicaltt/src/cones.ctt:
--------------------------------------------------------------------------------
1 | {- Category Theory:
2 | - Cones;
3 | - Pullbacks.
4 | Copyright (c) Groupoid Infinity, 2014-2018. -}
5 |
6 | module cones where
7 | import sip
8 | import set
9 | import algebra
10 |
11 | isCospanConeHomProp (C: precategory) (D: cospan C) (E1 E2: cospanCone C D) (h: hom C E1.1 E2.1)
12 | : isProp (isCospanConeHom C D E1 E2 h)
13 | = propAnd (Path (hom C E1.1 D.2.1.1) (compose C E1.1 E2.1 D.2.1.1 h E2.2.1) E1.2.1)
14 | (Path (hom C E1.1 D.2.2.1) (compose C E1.1 E2.1 D.2.2.1 h E2.2.2.1) E1.2.2.1)
15 | (homSet C E1.1 D.2.1.1 (compose C E1.1 E2.1 D.2.1.1 h E2.2.1) E1.2.1)
16 | (homSet C E1.1 D.2.2.1 (compose C E1.1 E2.1 D.2.2.1 h E2.2.2.1) E1.2.2.1)
17 |
18 | cospanConePath (C: precategory) (D: cospan C) (E: cospanCone C D)
19 | : cospanConeHom C D E E
20 | = (path C E.1, pathL C E.1 D.2.1.1 E.2.1, pathL C E.1 D.2.2.1 E.2.2.1)
21 |
22 | cospanConeComp (C: precategory) (D: cospan C) (X Y Z: cospanCone C D)
23 | (F: cospanConeHom C D X Y) (G: cospanConeHom C D Y Z)
24 | : cospanConeHom C D X Z
25 | = (compose C X.1 Y.1 Z.1 F.1 G.1,
26 | composition (hom C X.1 D.2.1.1)
27 | (compose C X.1 Z.1 D.2.1.1 (compose C X.1 Y.1 Z.1 F.1 G.1) Z.2.1)
28 | (compose C X.1 Y.1 D.2.1.1 F.1 (compose C Y.1 Z.1 D.2.1.1 G.1 Z.2.1))
29 | X.2.1
30 | (pathC C X.1 Y.1 Z.1 D.2.1.1 F.1 G.1 Z.2.1)
31 | (composition (hom C X.1 D.2.1.1)
32 | (compose C X.1 Y.1 D.2.1.1 F.1 (compose C Y.1 Z.1 D.2.1.1 G.1 Z.2.1))
33 | (compose C X.1 Y.1 D.2.1.1 F.1 Y.2.1)
34 | X.2.1
35 | ( compose C X.1 Y.1 D.2.1.1 F.1 (G.2.1 @ i))
36 | F.2.1),
37 | composition (hom C X.1 D.2.2.1)
38 | (compose C X.1 Z.1 D.2.2.1 (compose C X.1 Y.1 Z.1 F.1 G.1) Z.2.2.1)
39 | (compose C X.1 Y.1 D.2.2.1 F.1 (compose C Y.1 Z.1 D.2.2.1 G.1 Z.2.2.1))
40 | X.2.2.1
41 | (pathC C X.1 Y.1 Z.1 D.2.2.1 F.1 G.1 Z.2.2.1)
42 | (composition (hom C X.1 D.2.2.1)
43 | (compose C X.1 Y.1 D.2.2.1 F.1 (compose C Y.1 Z.1 D.2.2.1 G.1 Z.2.2.1))
44 | (compose C X.1 Y.1 D.2.2.1 F.1 Y.2.2.1)
45 | X.2.2.1
46 | ( compose C X.1 Y.1 D.2.2.1 F.1 (G.2.2 @ i))
47 | F.2.2))
48 |
49 |
50 | isPullbackProp (C : precategory) (D : cospan C) (E : cospanCone C D)
51 | : isProp (isPullback C D E)
52 | = propPi (cospanCone C D) (\(h : cospanCone C D) -> isContr (cospanConeHom C D h E))
53 | (\(h : cospanCone C D) -> propIsContr (cospanConeHom C D h E))
54 |
55 | cospanConeStructure (C: precategory) (D: cospan C)
56 | : structure C
57 | = (hasCospanCone C D
58 | ,\(x y: carrier C) (a: hasCospanCone C D x) (b: hasCospanCone C D y) -> isCospanConeHom C D (x, a) (y, b)
59 | ,\(x y: carrier C) (a: hasCospanCone C D x) (b: hasCospanCone C D y) -> isCospanConeHomProp C D (x, a) (y, b)
60 | ,\(x: carrier C) (a: hasCospanCone C D x) -> (cospanConePath C D (x, a)).2
61 | ,\(x y z: carrier C) (a: hasCospanCone C D x) (b: hasCospanCone C D y) (c: hasCospanCone C D z)
62 | (f: hom C x y) (g: hom C y z)
63 | (Hf: isCospanConeHom C D (x, a) (y, b) f)
64 | (Hg: isCospanConeHom C D (y, b) (z, c) g) -> (cospanConeComp C D (x, a) (y, b) (z, c) (f, Hf) (g, Hg)).2
65 | )
66 |
67 | cospanConePrecategory (C: precategory) (D: cospan C)
68 | : precategory
69 | = sipPrecategory C (cospanConeStructure C D)
70 |
71 | isCategoryCospanCone (C: precategory) (D: cospan C) (isC: isCategory C)
72 | : isCategory (cospanConePrecategory C D)
73 | = sip C isC (cospanConeStructure C D) hole
74 | where
75 | hole: isStandardStructure C (cospanConeStructure C D)
76 | = \(x: carrier C) (a b: hasCospanCone C D x)
77 | (c: isCospanConeHom C D (x, a) (x, b) (path C x))
78 | (d: isCospanConeHom C D (x, b) (x, a) (path C x)) ->
79 | (composition (hom C x D.2.1.1) a.1 (compose C x x D.2.1.1 (path C x) a.1) b.1 (pathL C x D.2.1.1 a.1 @-i) d.1 @ i
80 | ,composition (hom C x D.2.2.1) a.2.1 (compose C x x D.2.2.1 (path C x) a.2.1) b.2.1 (pathL C x D.2.2.1 a.2.1 @-i) d.2 @ i
81 | ,lemPathPProp (Path (hom C x D.1) (compose C x D.2.1.1 D.1 a.1 D.2.1.2) (compose C x D.2.2.1 D.1 a.2.1 D.2.2.2))
82 | (Path (hom C x D.1) (compose C x D.2.1.1 D.1 b.1 D.2.1.2) (compose C x D.2.2.1 D.1 b.2.1 D.2.2.2))
83 | (homSet C x D.1 (compose C x D.2.1.1 D.1 a.1 D.2.1.2) (compose C x D.2.2.1 D.1 a.2.1 D.2.2.2))
84 | (Path (hom C x D.1)
85 | (compose C x D.2.1.1 D.1 (composition (hom C x D.2.1.1) a.1 (compose C x x D.2.1.1 (path C x) a.1) b.1
86 | (pathL C x D.2.1.1 a.1 @-i) d.1 @ i) D.2.1.2)
87 | (compose C x D.2.2.1 D.1 (composition (hom C x D.2.2.1) a.2.1 (compose C x x D.2.2.1 (path C x) a.2.1) b.2.1
88 | (pathL C x D.2.2.1 a.2.1 @-i) d.2 @ i) D.2.2.2))
89 | a.2.2 b.2.2 @ i)
90 |
91 | hasPullbackProp (C: precategory) (isC: isCategory C) (D: cospan C)
92 | : isProp (hasPullback C D)
93 | = terminalProp (cospanConePrecategory C D) (isCategoryCospanCone C D isC)
94 |
95 | -- f g
96 | -- A ---> B ---> C
97 | -- j | k | l |
98 | -- v v v
99 | -- D ---> E ---> F
100 | -- h i
101 |
102 | pullbackPasting
103 | (X: precategory)
104 | (A B C D E F: carrier X)
105 | (f: hom X A B) (g: hom X B C)
106 | (h: hom X D E) (i: hom X E F)
107 | (j: hom X A D) (k: hom X B E) (l: hom X C F)
108 | (cc1: isComm X A B D E f h j k)
109 | (cc2: isComm X B C E F g i k l)
110 | (cc3: isComm X A C D F (compose X A B C f g) (compose X D E F h i) j l)
111 | (pb2: isPullback X (F, (E, i), (C, l)) (B, k, g, cc2))
112 | (pb3: isPullback X (F, (D, compose X D E F h i), (C, l)) (A, j, compose X A B C f g, cc3))
113 | : isPullback X (E, (D, h), (B, k)) (A, j, f, cc1)
114 | = undefined
115 |
116 |
--------------------------------------------------------------------------------
/cubicaltt/src/control.ctt:
--------------------------------------------------------------------------------
1 | {- Control Structures:
2 | - Pure;
3 | - Applicative;
4 | - Monad.
5 | Copyright (c) Groupoid Infinity, 2014-2018. -}
6 |
7 | module control where
8 | import proto
9 | import path
10 |
11 | -- Signature equations
12 | pure_sig (F:U->U):U= (A: U) -> A -> F A
13 | extract_sig (F:U->U):U= (A: U) -> F A -> A
14 | extend_sig (F:U->U):U= (A B: U) -> (F A -> B) -> F A -> F B
15 | appl_sig (F:U->U):U= (A B: U) -> F (A -> B) -> F A -> F B
16 | fmap_sig (F:U->U):U= (A B: U) -> (A -> B) -> F A -> F B
17 | unmap_sig (F:U->U):U= (A B: U) -> (F A -> F B) -> (A -> B)
18 | contra_sig (F:U->U):U= (A B: U) -> (B -> A) -> F A -> F B
19 | uncontra_sig (F:U->U):U= (A B: U) -> (F A -> F B) -> (B -> A)
20 | cofmap_sig (F:U->U):U= (A B: U) -> (B -> A) -> F B -> F A
21 | uncofmap_sig (F:U->U):U= (A B: U) -> (F B -> F A) -> (B -> A)
22 | cocontra_sig (F:U->U):U= (A B: U) -> (A -> B) -> F B -> F A
23 | uncocontra_sig (F:U->U):U= (A B: U) -> (F B -> F A) -> (A -> B)
24 | join_sig (F:U->U):U= (A: U) -> F (F A) -> F A
25 | dup_sig (F:U->U):U= (A: U) -> F A -> F (F A)
26 | bind_sig (F:U->U):U= (A B: U) -> F A ->(A -> F B)-> F B
27 |
28 | {- The signatures are made external for code compactification.
29 | Then we select F: U -> U functor as common head for sigma types.
30 | All quantifiers for members and laws are carried within projections.
31 | Projections contains full signature except F.
32 | These types could be considered for run-time.
33 | Also you may read Oleg Kiselev Type-Classes in ML.
34 | Here is we encode type-classes with Sigma and instances with nested tuples.
35 | -}
36 |
37 | pure: U = (F: U -> U)
38 | * pure_sig F
39 |
40 | functor: U = (F: U -> U)
41 | * fmap_sig F
42 |
43 | applicative: U = (F: U -> U)
44 | * (_: pure_sig F)
45 | * (_: fmap_sig F)
46 | * appl_sig F
47 |
48 | monad: U = (F: U -> U)
49 | * (_: pure_sig F)
50 | * (_: fmap_sig F)
51 | * (_: appl_sig F)
52 | * bind_sig F
53 |
54 | {- Accessor are common technique in Type Refinement approach
55 | for beautifying the code. -}
56 |
57 | -- Accessors
58 | fmap (a: functor): fmap_sig a.1 = a.2
59 | apure (a: applicative): pure_sig a.1 = a.2.1
60 | amap (a: applicative): fmap_sig a.1 = a.2.2.1
61 | ap (a: applicative): appl_sig a.1 = a.2.2.2
62 | mpure (a: monad): pure_sig a.1 = a.2.1
63 | bind (a: monad): bind_sig a.1 = a.2.2.2.2
64 |
65 | kleisli_compose (A B C: U)
66 | (M: monad)
67 | (f: B -> M.1 C)
68 | (g: A -> M.1 B)
69 | (x: A): M.1 C = bind M B C (g x) f
70 |
71 | -- Theorems. Erased in run-time.
72 |
73 | -- fmap(id(x)) = id(x)
74 | -- fmap(o(g,h)) = o(fmap(g),fmap(h))
75 |
76 | isFunctor (F: functor): U
77 | = (id: (A: U) -> (x: F.1 A) -> Path (F.1 A) (fmap F A A (idfun A) x) x)
78 | * (compose: (A B C: U) (f: B -> C) (g: A -> B) (x: F.1 A) ->
79 | Path (F.1 C) (F.2 A C (o A B C f g) x)
80 | ((o (F.1 A) (F.1 B) (F.1 C)
81 | (F.2 B C f) (F.2 A B g)) x)) * unit
82 |
83 | -- ap(pure(id),x) = id(x)
84 | -- ap(pure(f),pure(x)) = pure(f(x))
85 | -- ap(ap(ap(pure(o),u),v),w) = ap(u,ap(v,w))
86 | -- ap(u,pure(y)) == ap(pure(\f.f(y)),u)
87 |
88 | isApplicative (F: applicative): U
89 | = (id: (A:U) -> (x: F.1 A) ->
90 | Path (F.1 A) x (ap F A A (apure F (id A) (idfun A)) x))
91 | * (hom: (A B:U)(f:A->B)(x: A) ->
92 | Path (F.1 B) (apure F B (f x)) (ap F A B (apure F (A->B) f) (apure F A x)))
93 | * (cmp: (A B C:U)(v: F.1(A->B))(u:F.1(B->C))(w:F.1 A) ->
94 | Path (F.1 C) (ap F B C u (ap F A B v w))
95 | (ap F A C (ap F (A->B) (A->C) (ap F(B->C)((A->B)->(A->C))
96 | (apure F (ot A B C) (o A B C)) u) v) w))
97 | * (xchg: (A B:U)(x:A)(u:F.1(A->B))(f:A->B) ->
98 | Path (F.1 B) (ap F A B u ((apure F) A x))
99 | (ap F (A->B) B (apure F ((A->B)->B) (\(f:A->B)->f(x))) u)) * unit
100 |
101 | isMonad (F: monad): U
102 | = (one: (A B:U) (f:A->F.1 B)(x:A) -> Path (F.1 B) (bind F A B (mpure F A x) f) (f x))
103 | * (coone: (A:U) (m: F.1 A) -> Path (F.1 A) (bind F A A m (mpure F A)) m)
104 | * (assoc: (A B C: U) (f: A -> F.1 B) (g: B -> F.1 C) (m: F.1 A) ->
105 | Path (F.1 C) (bind F B C (bind F A B m f) g)
106 | (bind F A C m (\(x: A) -> bind F B C (f x) g))) * unit
107 |
108 | FUNCTOR: U = (f: functor)
109 | * isFunctor f
110 |
111 | APPLICATIVE: U = (f: applicative)
112 | * (_: isFunctor (f.1,f.2.2.1))
113 | * isApplicative f
114 |
115 | MONAD: U = (f: monad)
116 | * (_: isFunctor (f.1,f.2.2.1))
117 | * (_: isApplicative (f.1,f.2.1,f.2.2.1,f.2.2.2.1))
118 | * isMonad f
119 |
120 |
--------------------------------------------------------------------------------
/cubicaltt/src/cw.ctt:
--------------------------------------------------------------------------------
1 | {- CW-Comlexes
2 | Copyright (c) Groupoid Infinity, 2014-2020.
3 |
4 | HoTT 6.6 Cell Complexes -}
5 |
6 | module cw where
7 | import suspension
8 | import nat
9 | import pushout
10 |
11 | -- Cell complexes as attachment cells
12 | attaching (A B C: U): U = B -> C -> A
13 | attached (A B C: U) (a: attaching A B C): U
14 | = pushout A B (prod B C) (\(x: prod B C) -> a x.1 x.2)
15 | (\(x: prod B C) -> x.1)
16 |
17 |
--------------------------------------------------------------------------------
/cubicaltt/src/cwf.ctt:
--------------------------------------------------------------------------------
1 | module cwf where
2 |
3 | {-
4 |
5 | Here is a short informal description of
6 | categorical semantics of dependent type theory given by Peter Dybjer.
7 | The code is by Thierry Coquand ported to cubical by 5HT.
8 |
9 | http://www.cse.chalmers.se/~peterd/papers/Ise2008.pdf
10 |
11 | Another good intro to LCCC was a 80-514 course at CMU:
12 |
13 | http://math.cmu.edu/~cnewstea/talks/20170301.pdf
14 |
15 | Definition (Fam). The Fam is the category of families
16 | of sets where objects are dependent function
17 | spaces (x:A)->B(x) and morphisms with domain
18 | Pi(A,B) and codomain Pi(A',B') are pairs of
19 | functions A',g(x:A):B(x)->B'(f(x))>.
20 |
21 | Definition (Derivability). Ctx|-A = (c:Ctx) -> A(c).
22 | Definition (Comprehension). Ctx;A = (c:Ctx) * A(c).
23 | Statement. Comprehension is not assoc.
24 |
25 | G;A;B =/= G;B;A
26 |
27 | Definition (Context).The C is context category where
28 | objects are contexts and morphisms are substitutions.
29 | Terminal object G=0 in C is called empty context.
30 | Context comprehension operation G;A = (x:G)*A(x) and
31 | its eliminators: p:G;A |- G, q: G;A |- A(p) such that
32 | universal property holds: for any D:ob(C), morphism g:D->G,
33 | and term a:D->A there is a unique morphism s=:D->G;A
34 | such that p.s=g and q(s)=a. Statement. Subst is assoc.
35 |
36 | g(g(G,x,a),y,b) = g(g(G,y,b),x,a)
37 |
38 | Definition (CwF-object). A CwF-object is a Sigma(C,C->Fam)
39 | of context category C with contexts as objects and
40 | substitutions as morphisms and functor T:C->Fam where
41 | object part is a map from a context G of C to famility
42 | of sets of terms G |- A and morphism part is a map from
43 | substitution g:D->G to a pair of functions which perform
44 | substitutions of g in terms and types respectively.
45 |
46 | Definition (CwF-morphism). Let (C,T):ob(C) where T:C->Fam.
47 | A CwF-morphism m: (C,T)->(C',T') is a pair C',s:T->T'(F)>
48 | where F is a functor and s is a natural transformation.
49 |
50 | Definition (Category of Types). Let we have CwF with (C,T) objects
51 | and (C,T)->(C',T') mophisms. For a given context G in Ob(C) we can
52 | construct a Type(G) -- the category of types in context G with
53 | set of types in contexts as objects as and functions f:G;A->B(p) as morphisms.
54 |
55 | Definition (Local Cartesian Closed Category).
56 |
57 | LCCC(C) = Sigma(C,(A:ob C)->CCC(C/A)).
58 |
59 | [1]. Alexandre Buisse, Peter Dybjer.
60 | The Interpretation of Intuitionistic Type Theory
61 | in Locally Cartesian Closed Categories -- an Intuitionistic Perspective.
62 | [2]. Martin Hofmann, Thomas Streicher.
63 | The groupoid interpretation of type theory.
64 | [3]. Pierre Clairambault.
65 | From Categories with Families to Locally Cartesian Closed Categories.
66 | [4]. Andreas Abel, Thierry Coquand, Peter Dybjer.
67 | On the Algebraic Foundation of Proof Assistants for Intuitionistic Type Theory.
68 | [5]. R.A.G. Seely.
69 | Locally cartesian closed categories and type theory.
70 | [6]. Pierre-Louis Curien, Richard Garner, Martin Hofmann.
71 | Revisiting the categorical interpretation of dependent type theory.
72 | [7]. Simon Castellan.
73 | Dependent type theory as the initial category with families.
74 | [8]. Peter Dybjer.
75 | Internal Type Theory.
76 | -}
77 |
78 | import cat
79 | import fun
80 | import nat
81 | import list
82 | import bool
83 | import maybe
84 |
85 | {-
86 |
87 | The type checker based on Categories with Families (CwF) model.
88 | The contexts modeled as lists of initial objects of internal language.
89 | Here is example of two contexts and substitution between them.
90 |
91 | Ctx: Vec Exp 3 = [ A:U, B:A->U, Pi(A,B) ]
92 | Ctx: Vec Exp 5 = [ A:U, B:A->U, Pi(A,B), Sigma(A,B), A->A ]
93 | Subst: Vec Exp 2 = [ Sigma (Var 1) (Var 2), Pi (Var 1) (Var 1) ]
94 |
95 | -}
96 |
97 | data Exp = Star (_: nat)
98 | | Var (_: nat)
99 | | Pi (_ _: Exp)
100 | | Lam (_: Exp)
101 | | App (_ _: Exp)
102 |
103 | Ty: U = Exp
104 | Ctx: U = list Ty
105 | Subst: U = list Exp
106 |
107 | seq (start: nat): list Exp = cons (Var start) (seq (succ start))
108 |
109 | mutual
110 |
111 | p: Subst = seq one
112 | q: Exp = Var zero
113 | ide: Subst = seq zero
114 | cmp: Subst -> Subst -> Subst = split
115 | nil -> \(ts: Subst) -> nil
116 | cons x xs -> \(ts: Subst) -> cons (sub ts x) (cmp xs ts)
117 |
118 | lift (ts: Subst): Subst = cons q (cmp ts p)
119 | unwrap: maybe Exp -> Exp = split { nothing -> q ; just x -> x }
120 | shift (t: Exp) (i: nat): Exp = sub (seq i) t
121 |
122 | isCo: Ctx -> bool = split
123 | nil -> true
124 | cons x xs -> and (isCo xs) (isTy xs x)
125 |
126 | isU (c:Ctx)(a b:Exp): Exp -> bool = split
127 | Star i -> (and (isTm c (Star i) a) (isTm (cons a c) (Star i) b))
128 | Var i -> false
129 | Pi a b -> false
130 | Lam x -> false
131 | App a b -> false
132 |
133 | isPi (c:Ctx)(e:Exp): Exp -> bool = split
134 | Star i -> false
135 | Var i -> false
136 | Pi a b -> isTm (cons a c) b e
137 | Lam x -> false
138 | App a b -> false
139 |
140 | isTy (c:Ctx): Ty -> bool = split
141 | Star i -> true
142 | Var i -> isTm c (Star zero) (Var i)
143 | Pi a b -> and (isTy c a) (isTy (cons a c) b)
144 | Lam x -> isTm c (Star zero) (Lam x)
145 | App a b -> isTm c (Star zero) (App a b)
146 |
147 | isTm (c:Ctx)(e:Exp): Ty -> bool = split
148 | Star i -> false
149 | Var i -> false
150 | Pi a b -> isU c a b e
151 | Lam x -> isPi c x e
152 | App a b -> false
153 |
154 | app (s: Exp): Exp -> Exp = split
155 | Star i -> App (Star i) s
156 | Var i -> App (Var i) s
157 | Pi a b -> App (Pi a b) s
158 | Lam x -> sub (cons s ide) x
159 | App a b -> App (App a b) s
160 |
161 | sub (ts: Subst): Exp -> Exp = split
162 | Star i -> Star i
163 | Var i -> unwrap (nth Exp i ts)
164 | Pi a b -> Pi (sub ts a) (sub (lift ts) b)
165 | Lam x -> Lam (sub (lift ts) x)
166 | App s t -> app (sub ts t) (sub ts s)
167 |
168 | inferTy (c: Ctx): Exp -> maybe Ty = split
169 | Star i -> just (Star i)
170 | Var i -> just (shift (unwrap (nth Exp i c)) (succ i))
171 | Pi a b -> just (Star one) -- implement
172 | Lam x -> just (Star zero) -- implement
173 | App s t -> just (Star zero) -- implement
174 |
175 | Fam: precategory = undefined
176 | isContext (C: precategory): U = undefined
177 | isTerminal (C: precategory): U = undefined
178 | isComprehension(C: precategory)(T: catfunctor C Fam): U = undefined
179 |
180 | CwF: U
181 | = (C: precategory)
182 | * (T: catfunctor C Fam)
183 | * (context: isContext C)
184 | * (terminal: isTerminal C)
185 | * (pullback: isComprehension C T)
186 | * unit
187 |
--------------------------------------------------------------------------------
/cubicaltt/src/em.ctt:
--------------------------------------------------------------------------------
1 | {- Eilenberg-MacLane Spaces:
2 | Copyright (c) Groupoid Infinity, 2014-2020.
3 |
4 | HoTT 8.10.3 K(G,n) Spaces -}
5 |
6 | module em where
7 | import algebra
8 | import trunc
9 | import pointed
10 | import suspension
11 | import hubspokes
12 | import nat
13 |
14 | -- K0' is a group G with the discrete toplogy
15 | discreteTopology (G: abgroup): U = group --
16 |
17 | -- K1' is not yet truncated K(G,1)
18 | data K1' (G : group)
19 | = pt
20 | | id (x : G.1.1)
21 | [ (i = 0) -> pt ,
22 | (i = 1) -> pt ]
23 | | mul (a b : G.1.1)
24 | [ (i = 0) -> composition (K1' G) pt pt pt ( id {K1' G} a @ k) ( id {K1' G} b @ k) @ j ,
25 | (i = 1) -> id {K1' G} (opGroup G a b) @ j ,
26 | (j = 0) -> pt ,
27 | (j = 1) -> pt ]
28 |
29 | -- Nat-indexed Abelian K(G,n) suitable for EM-spectrum HZ, n≥1
30 | -- Properties: π_{n}(K(G,n))=G \/ π_{k/=n}(K(G,n))=1
31 | KGn (G: abgroup)
32 | : nat -> U
33 | = split
34 | zero -> discreteTopology G
35 | succ n -> nTrunc (suspension (K1' (G.1,G.2.1)) n) (succ n)
36 |
37 | -- Direct Encoding
38 | K1 (G: group): U = grpdTrunc (K1' G)
39 | K2 (G: group): U = grpd2Trunc (susp (K1' G))
40 | K3 (G: group): U = grpd3Trunc (susp (susp (K1' G)))
41 |
42 | baseK1 (G : group) : K1 G = inc pt
43 | loopSpaceK1 (G : group) : U = Path (K1 G) (baseK1 G) (baseK1 G)
44 | loopK1 (G : group) (x : G.1.1) : loopSpaceK1 G = inc (id {K1' G} x @ i)
45 |
46 | multK1 (G : group) (a b : loopSpaceK1 G)
47 | : loopSpaceK1 G
48 | = composition (K1 G) (baseK1 G) (baseK1 G) (baseK1 G) a b
49 |
50 | loopMulK1 (G : group) (a b : G.1.1)
51 | : Path (loopSpaceK1 G) (multK1 G (loopK1 G a) (loopK1 G b)) (loopK1 G (opGroup G a b))
52 | = composition
53 | (loopSpaceK1 G)
54 | (multK1 G (loopK1 G a) (loopK1 G b))
55 | ( inc (composition (K1' G) pt pt pt ( id {K1' G} a @ j) ( id {K1' G} b @ j) @ i))
56 | (loopK1 G (opGroup G a b))
57 | (mapOverComp (K1' G) (K1 G) (\(x:K1' G)->inc x) pt pt pt ( id {K1' G} a @ j) ( id {K1' G} b @ j))
58 | ( inc (mul{K1' G} a b @ i @ j))
59 |
--------------------------------------------------------------------------------
/cubicaltt/src/eq.ctt:
--------------------------------------------------------------------------------
1 | module eq where
2 | import bool
3 |
4 | eq_: U = (type: U) * (type -> type -> bool)
5 | eq (type: U): U = type -> type -> bool
6 |
7 |
--------------------------------------------------------------------------------
/cubicaltt/src/eqv.ctt:
--------------------------------------------------------------------------------
1 | module eqv where
2 |
3 | idfun (A: U) (a: A): A = a
4 | Path (A: U) (a b: A): U = PathP ( A) a b
5 | HPath (A B: U) (a: A) (b: B) (P: Path U A B) : U = PathP P a b
6 | refl (A: U) (a: A): Path A a a = a
7 | singl (A: U) (a: A): U = (x: A) * Path A a x
8 | eta (A: U) (a: A): singl A a = (a,refl A a)
9 | contr (A: U) (a b: A) (p: Path A a b): Path (singl A a) (eta A a) (b,p) = (p @ i, p @ i/\j)
10 | subst (A: U) (P: A->U) (a b: A) (p: Path A a b) (e: P a): P b = comp ( P (p @ i)) e []
11 | isContr (A: U): U = (x: A) * ((y: A) -> Path A x y)
12 | fiber (A B: U) (f: A -> B) (y: B): U = (x: A) * Path B y (f x)
13 | isSingleton (X:U): U = (c:X) * ((x:X) -> Path X c x)
14 | isEquiv (A B: U) (f: A -> B): U = (y: B) -> isContr (fiber A B f y)
15 | equiv (A B: U): U = (f: A -> B) * isEquiv A B f
16 | isContrSingl (A:U) (a:A): isContr (singl A a) = ((a,refl A a),\ (z:singl A a) -> contr A a z.1 z.2)
17 | idIsEquiv (A: U): isEquiv A A (idfun A) = \(a: A) -> ((a, refl A a),\(z: fiber A A (idfun A) a) -> contr A a z.1 z.2)
18 | idEquiv (A:U): equiv A A = (\ (x:A) -> x, isContrSingl A)
19 | equivPath (T A: U) (f: T -> A) (p: isEquiv T A f): Path U T A = Glue A [ (i=0) -> (T,f,p), (i=1) -> (A,idfun A, idIsEquiv A)]
20 | invEq (A B:U)(w:equiv A B)(y:B): A = (w.2 y).1.1
21 | retEq (A B:U)(w:equiv A B)(y:B): Path B (w.1 (invEq A B w y)) y = (w.2 y).1.2@-i
22 | secEq (A B:U)(w:equiv A B)(x:A): Path A (invEq A B w (w.1 x)) x = ((w.2(w.1 x)).2(x,w.1 x)@i).1
23 |
24 | univ_Formation (A B: U): U = equiv A B -> Path U A B
25 | equivToPath (A B: U): univ_Formation A B = \(p: equiv A B) -> Glue B [(i=0) -> (A,p), (i=1) -> (B, subst U (equiv B) B B (<_>B) (idEquiv B)) ]
26 | pathToEquiv (A B: U) (p: Path U A B): equiv A B = subst U (equiv A) A B p (idEquiv A)
27 | eqToEq (A B : U) (p : Path U A B) : Path (Path U A B) (equivToPath A B (pathToEquiv A B p)) p
28 | = let Ai: U = p@i in Glue B [ (i=0) -> (A,pathToEquiv A B p),
29 | (i=1) -> (B,pathToEquiv B B ( B)),
30 | (j=1) -> (p@i,pathToEquiv Ai B ( p @ (i \/ k))) ]
31 |
--------------------------------------------------------------------------------
/cubicaltt/src/etale.ctt:
--------------------------------------------------------------------------------
1 | {- Étale Maps:
2 | - Etale.
3 | Copyright (c) Groupoid Infinity, 2014-2018.
4 |
5 | EGA4 4.1 Etale maps -}
6 |
7 | module etale where
8 | import path
9 | import pullback
10 | import infinitesimal
11 |
12 | -- w
13 | -- A ----> Im A
14 | -- f | | x
15 | -- V V
16 | -- B ----> Im B
17 | -- y
18 |
19 | isÉtaleMap (A B: U) (f: A -> B): U
20 | = isPullbackSq A iA B (Im B) x y w f h where
21 | iA : U = Im A
22 | iB : U = Im B
23 | x: iA -> iB = ImApp A B f
24 | y: B -> iB = ImUnit B
25 | w: A -> iA = ImUnit A
26 | c1: A -> iB = o A iA iB x w
27 | c2: A -> iB = o A B iB y f
28 | T2: U = (a:A) -> Path iB (c1 a) (c2 a)
29 | h: T2 = \(a : A) -> ImNaturality A B f a @ -i
30 |
31 | EtaleMap (A B: U): U
32 | = (f: A -> B)
33 | * isÉtaleMap A B f
34 |
--------------------------------------------------------------------------------
/cubicaltt/src/functor.ctt:
--------------------------------------------------------------------------------
1 | {- Control Structures. Functor Instances:
2 | - Identity;
3 | - Id;
4 | - Compose;
5 | - Higher Order Compose.
6 | Copyright (c) Groupoid Infinity, 2014-2018. -}
7 |
8 | module functor where
9 | import proto
10 | import path
11 | import pi
12 | import control
13 |
14 | functor_id: FUNCTOR = ((\(A:U)->A,apply),(id,compose,tt)) where
15 | id: (A: U) -> (a: A) -> Path A a a = refl
16 | compose (A B C: U) (f: B->C) (g: A->B) (x: A):
17 | Path C (f(g(x))) (f(g(x))) = refl C (o A B C f g x)
18 |
19 | functor_const (A: U): FUNCTOR = ((const A,fmap),(id,compose,tt)) where
20 | fmap (B C: U) (_: B -> C): A -> A = idfun A
21 | id (_ : U): (x : A) -> Path A x x = refl A
22 | compose (X B C: U) (f: B->C) (g: X->B): (x: A) -> Path A x x = refl A
23 |
24 | functor_fun (T: U): FUNCTOR = ((\(B:U)->T->B,fmap),(id,compose,tt)) where
25 | fmap (A B: U) (map: A -> B): (T -> A) -> (T -> B) = o T A B map
26 | id (A: U): (x: T->A) -> Path (T->A) x x = refl (T->A)
27 | compose (A B C: U) (f: B->C) (g: A->B) (x: T->A):
28 | Path (T->C) (\(y: T) -> f (g (x y)))
29 | (\(y: T) -> f (g (x y)))
30 | = refl (T->C) (\(y: T) -> f (g (x y)))
31 |
32 | functor_comptype (f g: FUNCTOR): FUNCTOR = ((O F G,fmap),(id,compose,tt)) where
33 | F: U -> U = f.1.1
34 | G: U -> U = g.1.1
35 | T: U -> U = O F G
36 | functorIdFunExt (x: FUNCTOR) (A: U): Path (x.1.1 A -> x.1.1 A) (x.1.2 A A (idfun A)) (idfun (x.1.1 A))
37 | = funext (x.1.1 A) (x.1.1 A) (x.1.2 A A (idfun A)) (idfun (x.1.1 A)) (x.2.1 A)
38 | functorComposeFunExt (x: FUNCTOR) (A B C: U) (fx: B -> C) (gy: A -> B):
39 | Path (x.1.1 A -> x.1.1 C) (x.1.2 A C (o A B C fx gy))
40 | (o (x.1.1 A) (x.1.1 B) (x.1.1 C) (x.1.2 B C fx) (x.1.2 A B gy))
41 | = funext (x.1.1 A) (x.1.1 C) (x.1.2 A C (o A B C fx gy))
42 | ((o (x.1.1 A) (x.1.1 B) (x.1.1 C) (x.1.2 B C fx) (x.1.2 A B gy))) (x.2.2.1 A B C fx gy)
43 | lemma1 (A B: U) (g: A -> B) (x y: A) (z: B) (pxy: Path A x y) (pgyz: Path B (g y) z): Path B (g x) z
44 | = substInv A (\(X: A) -> Path B (g X) z) x y pxy pgyz
45 | fmapF: (A B: U) -> (A -> B) -> F A -> F B = f.1.2
46 | fmapG: (A B: U) -> (A -> B) -> G A -> G B = g.1.2
47 | idF: (A: U) -> (x: F A) -> Path (F A) (fmapF A A (idfun A) x) x = f.2.1
48 | idG: (A: U) -> (x: G A) -> Path (G A) (fmapG A A (idfun A) x) x = g.2.1
49 | fmap (A B: U) (arg: A -> B): F (G A) -> F (G B) = fmapF (G A) (G B) (fmapG A B arg)
50 | id (A: U) (x: F (G A)) : Path (F (G A)) (fmapF (G A) (G A) (fmapG A A (idfun A)) x) x
51 | = lemma1 (G A -> G A) (F (G A)) lemma1g (fmapG A A (idfun A)) (idfun (G A)) x (functorIdFunExt g A) (idF (G A) x)
52 | where lemma1g (y: G A -> G A): F (G A) = fmapF (G A) (G A) y x
53 | compose (A B C: U) (ff: B -> C) (gg: A -> B) (x: T A):
54 | Path (F (G C)) (fmapF (G A) (G C) (fmapG A C ((\(y : A) -> ff (gg y)))) x)
55 | (fmapF (G B) (G C) (fmapG B C ff) (fmapF (G A) (G B) (fmapG A B gg) x))
56 | = substInv (G A -> G C) P AAA BBB compGinst compFinst where
57 | fff : G B -> G C = fmapG B C ff
58 | ggg : G A -> G B = fmapG A B gg
59 | AAA: G A -> G C = fmapG A C (o A B C ff gg)
60 | BBB: G A -> G C = o (G A) (G B) (G C) fff ggg
61 | P (aaa: G A -> G C): U = Path (F (G C))
62 | (fmapF (G A) (G C) aaa x)
63 | (fmapF (G B) (G C) fff (fmapF (G A) (G B) ggg x))
64 | compFinst: P BBB = f.2.2.1 (G A) (G B) (G C) fff ggg x
65 | compGinst : Path (G A -> G C) AAA BBB = functorComposeFunExt g A B C ff gg
66 |
--------------------------------------------------------------------------------
/cubicaltt/src/hedberg.ctt:
--------------------------------------------------------------------------------
1 | {- Set Theory:
2 | - Stability and Discretness leads to Set
3 | Copyright (c) Groupoid Infinity, 2014-2018. -}
4 |
5 | module hedberg where
6 | import proto
7 | import path
8 | import iso
9 |
10 | hedbergLemma (A: U) (a b:A) (f: (x: A) -> Path A a x -> Path A a x) (p: Path A a b):
11 | Square A a a a b (refl A a) p (f a (refl A a)) (f b p) =
12 | comp ( Square A a a a (p @ i) (<_> a) ( p @ i /\ j)
13 | (f a (<_> a)) (f (p @ i) ( p @ i /\ j))) ( f a (<_> a)) []
14 |
15 | hedbergStable (A: U) (a b: A) (h: (x: A) -> stable (Path A a x))
16 | (p q: Path A a b): Path (Path A a b) p q =
17 | comp (<_> A) a [ (j = 0) -> (hedbergLemma A a b f p) @ i,
18 | (j = 1) -> (hedbergLemma A a b f q) @ i,
19 | (i = 0) -> ((rem1 a).1) (refl A a),
20 | (i = 1) -> (fConst b p q) @ j ] where
21 | rem1 (x: A): exConst (Path A a x) = stableConst (Path A a x) (h x)
22 | f (x: A): Path A a x -> Path A a x = (rem1 x).1
23 | fConst (x: A): isConst (Path A a x) (f x) = (rem1 x).2
24 |
25 | hedbergS (A:U) (h: (a x:A) -> stable (Path A a x)): isSet A
26 | = \ (a b: A) -> hedbergStable A a b (h a)
27 |
28 | hedberg (A:U) (h: discrete A): isSet A
29 | = \ (a b: A) -> hedbergStable A a b (\(b : A) -> decStable (Path A a b) (h a b))
30 |
31 |
--------------------------------------------------------------------------------
/cubicaltt/src/homology.ctt:
--------------------------------------------------------------------------------
1 | {- Homology Theory:
2 | - Chain Complexes.
3 | - Ker, Im, B, Z, H;
4 | - Isomorphism theorems;
5 | - Homology Group.
6 | Copyright (c) Groupoid Infinity, 2016-2020. -}
7 |
8 | module homology where
9 | import int
10 | import algebra
11 |
12 | isGroupHom (G H: group) (f: G.1.1 -> H.1.1): U
13 | = (g1 g2: G.1.1) -> Path H.1.1 (f ((opGroup G) g1 g2)) ((opGroup H) (f g1) (f g2))
14 |
15 | isGroupKer (G H: group) (f: G.1.1 -> H.1.1) (x: G.1.1): U
16 | = Path H.1.1 (f x) (idGroup H)
17 |
18 | isGroupIm (G H: group) (f: G.1.1 -> H.1.1) (g: H.1.1): U
19 | = propTrunc (fiber G.1.1 H.1.1 f g)
20 |
21 | kerProp (G H: group) (phi: grouphom G H)
22 | : subgroupProp G
23 | = (prop,level,ident,inv,op) where
24 | prop (x: G.1.1): U = isGroupKer G H phi.1 x
25 | ident: prop (idGroup G) = phi.2.2
26 | level (x: G.1.1): isProp (prop x) = \(p q: prop x) -> H.1.2 (phi.1 x) (idGroup H) p q
27 | inv (x: G.1.1) (p : prop x) : prop ((invGroup G) x) =
28 | comp (<_> H.1.1) ((invGroup H) (p @ i))
29 | [ (i = 0) -> lem_grouphom_inv G H phi x @ -j
30 | , (i = 1) -> lemma_group_inv_id H ]
31 | op (g1 g2: G.1.1) (p : prop g1) (q : prop g2) : prop ((opGroup G) g1 g2) =
32 | comp (<_> H.1.1) ((opGroup H) (p @ i) (q @ i))
33 | [ (i = 0) -> phi.2.1 g1 g2 @ -j
34 | , (i = 1) -> (hasIdGroup H).1 (idGroup H) ]
35 |
36 | imProp (G H: group) (phi: grouphom G H)
37 | : subgroupProp H
38 | = (prop, level, ident, inv, op) where
39 | prop (x: H.1.1): U = isGroupIm G H phi.1 x
40 | ident: prop (idGroup H) = inc ((idGroup G), phi.2.2 @ -i)
41 | level (x: H.1.1): isProp (prop x) = propTruncIsProp (fiber G.1.1 H.1.1 phi.1 x)
42 | fib (x : H.1.1) : U = fiber G.1.1 H.1.1 phi.1 x
43 | inv (x: H.1.1) : prop x -> prop ((invGroup H) x) =
44 | propTruncLift (fib x) (fib ((invGroup H) x))
45 | (\(u : fib x) ->
46 | ((invGroup G) u.1,
47 | comp (<_> H.1.1) ((invGroup H) (u.2 @ i))
48 | [ (i = 0) -> <_> (invGroup H) x
49 | , (i = 1) -> lem_grouphom_inv G H phi u.1 @ -j ]))
50 | op (g1 g2: H.1.1) : prop g1 -> prop g2 -> prop ((opGroup H) g1 g2) =
51 | propTruncBinLift (fib g1) (fib g2) (fib ((opGroup H) g1 g2))
52 | (\(u : fib g1) (v : fib g2) ->
53 | ((opGroup G) u.1 v.1,
54 | comp (<_> H.1.1) (phi.2.1 u.1 v.1 @ -i)
55 | [ (i = 0) -> (opGroup H) (u.2 @ -j) (v.2 @ -j)
56 | , (i = 1) -> <_> phi.1 ((opGroup G) u.1 v.1) ]))
57 |
58 | kerGroup (G: group) (H: group) (phi: grouphom G H): group
59 | = subgroup G (kerProp G H phi)
60 |
61 | imGroup (G: group) (H: group) (psi: grouphom G H): group
62 | = subgroup H (imProp G H psi)
63 |
64 | relKerIm (G H: group) (phi: grouphom G H) (x y: H.1.1): U
65 | = propTrunc (fiber G.1.1 H.1.1 phi.1 (rdiv H x y))
66 |
67 | elKerIm (G H: group) (phi: grouphom G H): U
68 | = quot H.1.1 (relKerIm G H phi)
69 |
70 | -- Theorems
71 |
72 | -- phiUnfold
73 | -- φ (g1 * g2 * g1⁻¹) - - - - - - > φ g1 * φ g2 * (φ g1)⁻¹
74 | -- ^ ^
75 | -- | |
76 | -- | |
77 | -- | |
78 | -- φ (g1 * g2) * φ g1⁻¹ ------------> φ g1 * φ g2 * φ g1⁻¹
79 |
80 | phiUnfold (G H : group) (phi : grouphom G H) (g1 g2 : G.1.1) :
81 | Path H.1.1 (phi.1 (conjugate G g1 g2)) ((opGroup H) ((opGroup H) (phi.1 g1) (phi.1 g2)) ((invGroup H) (phi.1 g1))) =
82 | comp (<_> H.1.1) ((opGroup H) (phi.2.1 g1 g2 @ i) (phi.1 ((invGroup G) g1)))
83 | [ (i = 0) -> phi.2.1 ((opGroup G) g1 g2) ((invGroup G) g1) @ -j
84 | , (i = 1) -> ((opGroup H) ((opGroup H) (phi.1 g1) (phi.1 g2)) (lem_grouphom_inv G H phi g1 @ j)) ]
85 |
86 | -- conjOne
87 | -- φ g1 * φ g2 * (φ g1)⁻¹ - - - - - - > 1
88 | -- ^ ^
89 | -- | |
90 | -- | |
91 | -- | |
92 | -- φ g1 * 1 * (φ g1)⁻¹ --------> φ g1 * (φ g1)⁻¹
93 |
94 | conjOne (G H : group) (phi : grouphom G H) (g1 g2 : G.1.1) (p : Path H.1.1 (phi.1 g2) (idGroup H)) :
95 | Path H.1.1 ((opGroup H) ((opGroup H) (phi.1 g1) (phi.1 g2)) ((invGroup H) (phi.1 g1))) (idGroup H) =
96 | comp (<_> H.1.1) ((opGroup H) ((hasIdGroup H).2 (phi.1 g1) @ i) ((invGroup H) (phi.1 g1)))
97 | [ (i = 0) -> (opGroup H) ((opGroup H) (phi.1 g1) (p @ -j)) ((invGroup H) (phi.1 g1))
98 | , (i = 1) -> (hasInvGroup H).2 (phi.1 g1) ]
99 |
100 | kernelIsNormalSubgroup (G H : group) (phi : grouphom G H)
101 | : normalSubgroupProp G
102 | = (ker, cond) where
103 | ker: subgroupProp G = kerProp G H phi
104 | phiConj (g1 g2: G.1.1) (p : Path H.1.1 (phi.1 g2) (idGroup H)) :
105 | Path H.1.1 (phi.1 (conjugate G g1 g2)) (idGroup H)
106 | = comp (<_> H.1.1) (conjOne G H phi g1 g2 p @ i)
107 | [ (i = 0) -> phiUnfold G H phi g1 g2 @ -j
108 | , (i = 1) -> <_> idGroup H ]
109 | cond: isNormal G ker = (G, phiConj)
110 |
111 | chainComplex : U
112 | = (K : nat -> abgroup)
113 | * (hom : (n : nat) -> abgrouphom (K (succ n)) (K n))
114 | * ((n : nat) -> Path (abgrouphom (K (succ2 n)) (K n))
115 | (abgrouphomcomp (K (succ2 n)) (K (succ n)) (K n) (hom (succ n)) (hom n))
116 | (trivabgrouphom (K (succ2 n)) (K n)))
117 |
118 | K (C : chainComplex) : nat -> abgroup = C.1
119 | K' (C : chainComplex) (n : nat) : group = abgroup' (K C n)
120 |
121 | hom (C : chainComplex) : (n : nat) -> abgrouphom (K C (succ n)) (K C n) = C.2.1
122 |
123 | propZ (C : chainComplex) (n : nat) : subgroupProp (K' C (succ n))
124 | = kerProp (K' C (succ n)) (K' C n) (hom C n)
125 |
126 | Z (C : chainComplex) (n : nat) : group = subgroup (K' C (succ n)) (propZ C n)
127 |
128 | B (C : chainComplex) (n : nat) : normalSubgroupProp (Z C n)
129 | = abelianSubgroupIsNormal (abelianSubgroupIsAbelian (K C (succ n)) (propZ C n))
130 | (subgroupSubgroup (K' C (succ n))
131 | (imProp (K' C (succ (succ n))) (K' C (succ n)) (hom C (succ n))) (propZ C n))
132 |
133 | H (C : chainComplex) (n : nat) : group = factorGroup (Z C n) (B C n)
--------------------------------------------------------------------------------
/cubicaltt/src/homotopy.ctt:
--------------------------------------------------------------------------------
1 | {- Homotopy Theory:
2 | - Homotopy Groups of Spheres;
3 | - Loop Space of S1 equals to Z.
4 | Copyright (c) Groupoid Infinity, 2016-2018 -}
5 |
6 | module homotopy where
7 | import s1
8 | import trunc
9 | import pointed
10 | import suspension
11 |
12 | -- Homogeneous Structure on A = (A)
13 | homogeneous (A: U): U
14 | = (e: A)
15 | * (translationsFamily: (x: A) -> Path U A A) -- could be non-trivial
16 | * ((x: A) -> Path A (transport (translationsFamily x) e) x)
17 |
18 | -- Definition. Homotopy Groups of Spheres : \pi_{n}S^{m} = ||\Omega^{n}(S^{m})||_0
19 | piS (n: nat): (m: nat) -> U = split
20 | zero -> setTrunc (space (omega n (bool,false)))
21 | succ x -> setTrunc (space (omega n (Sn (succ x),north)))
22 |
23 | -- Theorem. Loop Space of S1 equals to Z : \Omega^{1}(S^{1}) = Z
24 | encode (x:S1) (p:Path S1 base x)
25 | : helix x
26 | = subst S1 helix base x p zeroZ
27 |
28 | decode : (x:S1) -> helix x -> Path S1 base x = split
29 | base -> loopIt
30 | loop @ i -> rem @ i where
31 | p : Path U (Z -> loopS1) (Z -> loopS1)
32 | = helix (loop1@j) -> Path S1 base (loop1@j)
33 | rem : PathP p loopIt loopIt
34 | = corFib1 S1 helix (\(x:S1)->Path S1 base x) base
35 | loopIt loopIt loop1 (\(n:Z) ->
36 | comp ( Path loopS1 (oneTurn (loopIt n))
37 | (loopIt (testIsoPath Z Z sucZ predZ
38 | sucpredZ predsucZ n @ i)))
39 | ((lem1It n)@-i) [])
40 |
41 | lemTurn (n: nat): (b: bool) -> Path Z (comp (hlx b) (ze n b) []) (ze (succ n) b) = split
42 | false -> inl (succ (comp (<_>nat) (comp (<_>nat) n [(i=1) -> <_>n]) [(i=1) -> <_>n]))
43 | true -> inr (succ (comp (<_>nat) (comp (<_>nat) n [(i=1) -> <_>n]) [(i=1) -> <_>n]))
44 |
45 | encodeNeg: (n: nat)-> Path Z (comp ( helix (loopZ n false @ x)) zeroZ []) (ze n false) = split
46 | zero -> refl Z (ze zero false)
47 | succ n -> (comp ( Path Z (htz n false) (lemTurn n false @ i))
48 | (comp ( Path Z (htz n false) (comp (hlx false) (encodeNeg n @ i) []))
49 | ( lemFib2 S1 helix base base (lnb n false) zeroZ base (inversion false) @ -i) []) [])
50 |
51 | encodePos: (n: nat)-> Path Z (comp ( helix (loopZ n true @ x)) zeroZ []) (ze n true) = split
52 | zero -> refl Z (ze zero true)
53 | succ n -> (comp ( Path Z (htz n true) (lemTurn n true @ i))
54 | (comp ( Path Z (htz n true) (comp (hlx true) (encodePos n @ i) []))
55 | ( lemFib2 S1 helix base base (lnb n true) zeroZ base (inversion true) @ -i) []) [])
56 |
57 | retractBaseZ : (n : Z) -> Path Z (encode base (decode base n)) n = split
58 | inl n -> encodeNeg n
59 | inr n -> encodePos n
60 |
61 | encodeDecode : U
62 | = (n : Z) -> Path Z (encode base (decode base n)) n
63 |
64 | encodeDecodeLoop : Path U encodeDecode encodeDecode
65 | = (n : helix (loop{S1} @ i)) ->
66 | Path (helix (loop{S1} @ i))
67 | (encode (loop{S1} @ i) (decode (loop{S1} @ i) n)) n
68 |
69 | retractBaseLoop : (n : Z) -> Path Z (encode base (decode base n)) n
70 | = transport encodeDecodeLoop retractBaseZ
71 |
72 | retractTransport : Path encodeDecode retractBaseLoop retractBaseZ
73 | = \(n : Z) -> ZSet (encode base (decode base n)) n (retractBaseLoop n) (retractBaseZ n) @ i
74 |
75 | retractZ : (x : S1) -> (n : helix x) -> Path (helix x) (encode x (decode x n)) n = split
76 | base -> retractBaseZ
77 | loop @ i -> \(n : helix (loop{S1} @ i)) ->
78 | (substPathP encodeDecode encodeDecode encodeDecodeLoop
79 | retractBaseZ retractBaseZ retractTransport @ i) n
80 |
81 | sectionZ (x : S1) (p: Path S1 base x) : Path (Path S1 base x) (decode x (encode x p)) p
82 | = comp (Path (Path S1 base (p@i)) (decode (p@i) (encode (p@i) (p@(i/\j)))) (p@(i/\j)))
83 | (refl loopS1 triv) []
84 |
85 | helixFamily (x : S1) : Path U (helix x) (Path S1 base x)
86 | = isoPath (helix x) (Path S1 base x) (decode x) (encode x) (sectionZ x) (retractZ x)
87 |
88 | loopS1eqZ : Path U Z loopS1
89 | = helixFamily base
90 |
91 |
--------------------------------------------------------------------------------
/cubicaltt/src/hubspokes.ctt:
--------------------------------------------------------------------------------
1 | {- Hub and Spokes:
2 | - Total, Groupoid Truncations.
3 | Copyright (c) Groupoid Infinity, 2014-2020.
4 |
5 | HoTT 6.7 Hub and Spokes
6 | HoTT 7.3 Truncations -}
7 |
8 | module hubspokes where
9 | import suspension
10 | import nat
11 |
12 | -- 2-disc aka Hub and Spokes
13 | -- Eq constructors are redundant when n≥1 but give contractibility when n=0.
14 | data hubSpokes (S A: U)
15 | = base (x: A)
16 | | hub (f: S -> hubSpokes S A)
17 | | spoke (f: S -> hubSpokes S A) (s:S)
18 | [ (i=0) -> hub {hubSpokes S A} f @ i , (i=1) -> f s ]
19 | | hubEq (x y: A) (p: S -> Path A x y)
20 | [ (i=0) -> base x , (i=1) -> base y ]
21 | | spokeEq (x y: A) (p: S -> Path A x y) (s: S)
22 | [ (i=0) -> hubEq {hubSpokes S A} x y p @ i , (i=1) -> base (p s @ i) ]
23 |
24 | nTruncTotal (A: U) (n: nat): U = hubSpokes (Sn n) A
25 |
26 | -- Simple direct n-truncation as HIT (n≥-1)
27 | data nTrunc (A : U) (n : nat)
28 | = base (x: A)
29 | | hub (f : (Sn (succ n)) -> nTrunc A n)
30 | | spoke (f : (Sn (succ n)) -> nTrunc A n) (x : Sn (succ n))
31 | [ (i=0) -> hub f , (i=1) -> f x ]
32 |
33 | gTrunc1 (A: U) (n: nat): U = nTrunc A three
34 | gTrunc2 (A: U) (n: nat): U = nTrunc A five
35 | gTrunc3 (A: U) (n: nat): U = nTrunc A six
36 | gTrunc4 (A: U) (n: nat): U = nTrunc A seven
37 |
--------------------------------------------------------------------------------
/cubicaltt/src/hvec.ctt:
--------------------------------------------------------------------------------
1 | module hvec where
2 | import nat
3 | import suspension
4 |
5 | data HVec (n: nat)
6 | = hvnil
7 | | hvcons (A: U) (x: A) (xs: HVec (pred n))
8 |
9 | e1 : HVec zero = hvnil
10 | e2 : HVec one = hvcons U S1 e1
11 | e3 : HVec two = hvcons U S2 e2
12 | e4 : HVec three = hvcons U S2 e3
13 |
--------------------------------------------------------------------------------
/cubicaltt/src/impredicative.ctt:
--------------------------------------------------------------------------------
1 | {- Impredicative Encoding of Inductive Types:
2 | - Unit.
3 | Copyright (c) Groupoid Infinity, 2014-2018. -}
4 |
5 | module impredicative where
6 | import proto
7 | import path
8 | -- import iso_pi
9 | -- iso_sigma
10 |
11 | {-
12 | Church Encoding Nat:
13 |
14 | Nat = (X: U) -> (X -> X) -> X -> X
15 |
16 | Impredicative Encoding Unit:
17 |
18 | Unit = (X: U) -> isSet X -> X -> X
19 | Unit_Encoding = (one: Unit)
20 | * ((X Y: U) (x: isSet X) (y:isSet Y) (f:X->Y)
21 | -> naturality X Y f (one X x) (one Y y))
22 |
23 | Impredicative Encoding Nat:
24 |
25 | Nat = (X: U) -> isSet X -> (X -> X) -> (X -> X)
26 | Nat_Encoding = (one: Nat)
27 | * ((X Y: U) (x: isSet X) (y:isSet Y) (f:X->Y)
28 | -> naturality X Y f (one X x) (one Y y))
29 |
30 | Motivation is to have algebra structure that could be used with any coherent carrier.
31 | Impredicativity means that we can land inductive type in any universe.
32 | E.g. one can change the predicate from isSet to isProp for truncations or to higher n-types.
33 | You can also model HIT using impredicative encoding. Universes could be impredicative
34 | and univalent at the same time.
35 |
36 | Truncation ||A|| parametrized by (A:U) type = (X: U) -> isProp X -> (A -> X) -> X
37 | S^1 = (X:U) -> isGroupoid X -> (x:X) -> Path X x x -> X
38 | Arbitrary (A:U) type = (X: U) -> isSet X -> (A -> X) -> X
39 | -}
40 |
41 | -- (1) Signature
42 | unitEnc': U = (X: U) -> isSet X -> X -> X
43 |
44 | -- (2) Property
45 | naturality (X Y:U)(f:X->Y)(a:X->X)(b:Y->Y): U = Path (X->Y)(o X X Y f a)(o X Y Y b f)
46 | isUnitEnc (one: unitEnc'): U = (X Y:U)(x:isSet X)(y:isSet Y)(f:X->Y)->naturality X Y f (one X x)(one Y y)
47 |
48 | -- (3) Former/Intro/Elim/Beta/Eta Full-pack
49 | unitEnc: U = (x: unitEnc') * isUnitEnc x
50 | unitEncStar: unitEnc = (\(X:U)(_:isSet X)->idfun X,\(X Y: U)(_:isSet X)(_:isSet Y)->refl(X->Y))
51 | unitEncRec (C: U) (s: isSet C) (c: C): unitEnc -> C = \(z: unitEnc) -> z.1 C s c
52 | unitEncBeta (C: U) (s: isSet C) (c: C): Path C (unitEncRec C s c unitEncStar) c = refl C c
53 | unitEncEta (z: unitEnc): Path unitEnc unitEncStar z = undefined
54 | unitEncInd (P: unitEnc -> U) (a: unitEnc): P unitEncStar -> P a
55 | = subst unitEnc P unitEncStar a (unitEncEta a)
56 | unitEncCondition (n: unitEnc'): isProp (isUnitEnc n)
57 | = \ (f g: isUnitEnc n) -> \ (x y: U) -> \ (X: isSet x) -> \ (Y: isSet y)
58 | -> \ (F: x -> y) -> \ (R: x) -> Y (F (n x X R)) (n y Y (F R))
59 | ( (f x y X Y F @ j) R) ( (g x y X Y F @ j) R) @ h @ i
60 |
61 | {-
62 | [1]. https://github.com/sspeight93/Papers/
63 | [2]. https://homotopytypetheory.org/2017/10/11/impredicative-encodings-of-inductive-types-in-hott/
64 | [3]. https://www.newton.ac.uk/files/seminar/20170711090010001-1009680.pdf
65 | -}
66 |
--------------------------------------------------------------------------------
/cubicaltt/src/infinitesimal.ctt:
--------------------------------------------------------------------------------
1 | {- The modality of shape infinitesimal in cohesive infinity topos.
2 | - \Im modality type.
3 | Copyright (c) Groupoid Infinity, 2014-2018.
4 |
5 | HoTT 7.7 Modalities
6 | https://ncatlab.org/schreiber/show/thesis+Wellen
7 | https://arxiv.org/pdf/1806.05966.pdf
8 | -}
9 |
10 | module infinitesimal where
11 | import path
12 | import equiv
13 | import trunc
14 |
15 | -- Infinitesimal modality, represents infinitesimal shape constructions
16 |
17 | -- Formation
18 | Im : U -> U = undefined
19 |
20 | -- Introduction
21 | ImUnit (A: U) : A -> Im A = undefined
22 |
23 | isCoreduced (A:U): U = isEquiv A (Im A) (ImUnit A)
24 | ImCoreduced (A:U): isCoreduced (Im A) = undefined
25 |
26 | ImRecursion (A B: U) (c: isCoreduced B) (f: A -> B)
27 | : Im A -> B
28 | = undefined
29 |
30 | ImComputeRecursion (A B: U) (c: isCoreduced B) (f: A -> B) (a: A)
31 | : PathP ( B) ((ImRecursion A B c f) (ImUnit A a)) (f a)
32 | = undefined
33 |
34 | ImApp (A B: U) (f: A -> B)
35 | : Im A -> Im B
36 | = ImRecursion A (Im B) (ImCoreduced B) (o A B (Im B) (ImUnit B) f)
37 |
38 | ImNaturality (A B: U) (f: A -> B)
39 | : (a: A) -> Path (Im B) ((ImUnit B) (f a)) ((ImApp A B f) (ImUnit A a))
40 | = undefined
41 |
42 | -- Elimination
43 | ImInduction (A: U) (B: Im A -> U) (x: (a: Im A) -> isCoreduced (B a)) (y: (a: A) -> B (ImUnit A a))
44 | : (a: Im A) -> B a
45 | = undefined
46 |
47 | -- Beta
48 | ImComputeInduction (A: U) (B: Im A -> U) (c: (a: Im A) -> isCoreduced (B a)) (f: (a:A) -> B (ImUnit A a))(a:A)
49 | : Path (B (ImUnit A a)) (f a) ((ImInduction A B c f) (ImUnit A a))
50 | = undefined
51 |
52 | -- Formal Disk Bundle
53 |
54 | isInfinitesimalClose (X: U) (a x': X): U = Path (Im X) (ImUnit X a) (ImUnit X x')
55 | formalDisc (X: U) (a: X): U = (x': X) * isInfinitesimalClose X a x'
56 | unitDisc (X: U) (x: Im X): U = (x': X) * Path (Im X) x (ImUnit X x')
57 | starDisc (X: U) (x: X): formalDisc X x = (x, refl (Im X) (ImUnit X x))
58 | differential (X Y: U) (f: X -> Y) (x: X) : formalDisc X x -> formalDisc Y (f x) = undefined
59 | formalDiscBundle (A: U): U = (a: A) * formalDisc A a -- T_\infty(A) := \Sigma_{a:A}\mathbb{D}_a
60 |
61 | lemma45 (A B C: U) (f: A -> B) (g: B -> C) (x: A)
62 | : Path (formalDisc A x -> formalDisc C ((o A B C g f) x))
63 | (differential A C (o A B C g f) x)
64 | (o (formalDisc A x) (formalDisc B (f x)) (formalDisc C ((o A B C g f) x))
65 | (differential B C g (f x)) (differential A B f x)) = undefined
66 |
67 | preservesInifinitesimalProximity (X Y: U) (x x': X) (f: X -> Y)
68 | : isInfinitesimalClose X x x' -> isInfinitesimalClose Y (f x) (f x')
69 | = undefined
70 |
--------------------------------------------------------------------------------
/cubicaltt/src/infinity.ctt:
--------------------------------------------------------------------------------
1 | {- Infinity Language:
2 | - Syntax.
3 | Copyright (c) Groupoid Infinity, 2014-2018. -}
4 |
5 | module infinity where
6 | import list
7 | import control
8 | import path
9 | import pi
10 |
11 | name: U = list nat
12 | data alg = z | o | v (_: name) | max (a b: alg)
13 | | min (a b: alg) | inv (a: alg)
14 |
15 | data pts (lang: U)
16 | = star (n: nat)
17 | | var (x: name) (l: nat)
18 | | pi (x: name) (l: nat) (f: lang)
19 | | lambda (x: name) (l: nat) (f: lang)
20 | | app (f a: lang)
21 |
22 | data PTS
23 | = ppure (_: pts PTS)
24 |
25 | data exists (lang: U)
26 | = sigma (n: name) (a b: lang)
27 | | pair (a b: lang)
28 | | fst (p: lang)
29 | | snd (p: lang)
30 |
31 | data identity (lang: U)
32 | = id (t a b: lang)
33 | | idpair (a b: lang)
34 | | idelim (a b c d e: lang)
35 |
36 | data MLTT
37 | = mpure (_: pts MLTT)
38 | | msigma (_: exists MLTT)
39 | | mid (_: identity MLTT)
40 |
41 | data tele (A: U) = emp | tel (n: name) (b: A) (t: tele A)
42 | data branch (A: U) = br (n: name) (args: list name) (term: A)
43 | data label (A: U) = lab (n: name) (t: tele A)
44 | | com (n: name) (t: tele A) (dim: list name)
45 | (str: list (prod (prod name bool) A))
46 |
47 | data ind (lang: U)
48 | = data_ (n: name) (t: tele lang) (labels: list (label lang))
49 | | case (n: name) (t: lang) (branches: list (branch lang))
50 | | ctor (n: name) (args: list lang)
51 |
52 | data IND
53 | = ipure (_: pts IND)
54 | | isigma (_: exists IND)
55 | | iid (_: identity IND)
56 | | iind (_: ind IND)
57 |
58 | data hts (lang: U)
59 | = path (t a b: lang)
60 | | plam (n: name) (a: alg) (b: lang)
61 | | papp (f: name) (a: lang) (p: alg)
62 | | comp_ (a b: lang)
63 | | fill_ (a b c: lang)
64 | | glue_ (a b c: lang)
65 | | glue_elem (a b: lang)
66 | | unglue_elem (a b: lang)
67 |
68 | data HTS
69 | = hpure (_: pts HTS)
70 | | hsigma (_: exists HTS)
71 | | hid (_: identity HTS)
72 | | hind (_: ind HTS)
73 | | homotopy (_: hts HTS)
74 |
--------------------------------------------------------------------------------
/cubicaltt/src/int.ctt:
--------------------------------------------------------------------------------
1 | {- Integers:
2 | - Z=N+N, Z=Z.
3 | Copyright (c) Groupoid Infinity, 2014-2018 -}
4 |
5 | module int where
6 | import nat_theory
7 | import hedberg
8 |
9 | Z : U = either nat nat
10 |
11 | {- +2 = inr (succ (succ zero))
12 | +1 = inr (succ zero)
13 | 0 = inr zero
14 | -1 = inl zero
15 | -2 = inl (succ zero) -}
16 |
17 | zeroZ : Z = inr zero
18 |
19 | sucZ : Z -> Z = split
20 | inl u -> auxsucZ u where
21 | auxsucZ : nat -> Z = split
22 | zero -> inr zero
23 | succ n -> inl n
24 | inr v -> inr (succ v)
25 |
26 | predZ : Z -> Z = split
27 | inl u -> inl (succ u)
28 | inr v -> auxpredZ v where
29 | auxpredZ : nat -> Z = split
30 | zero -> inl zero
31 | succ n -> inr n
32 |
33 | sucpredZ : (x : Z) -> Path Z (sucZ (predZ x)) x = split
34 | inl u -> refl Z (inl u)
35 | inr v -> lem v where
36 | lem : (u : nat) -> Path Z (sucZ (predZ (inr u))) (inr u) = split
37 | zero -> refl Z (inr zero)
38 | succ n -> refl Z (inr (succ n))
39 |
40 | predsucZ : (x : Z) -> Path Z (predZ (sucZ x)) x = split
41 | inl u -> lem u where
42 | lem : (u : nat) -> Path Z (predZ (sucZ (inl u))) (inl u) = split
43 | zero -> refl Z (inl zero)
44 | succ n -> refl Z (inl (succ n))
45 | inr v -> refl Z (inr v)
46 |
47 | -- Non-trivial Equality Z=Z
48 | sucPathZ : Path U Z Z = isoPath Z Z sucZ predZ sucpredZ predsucZ
49 |
50 | -- We can transport along the proof forward and backwards:
51 | testOneZ : Z = transport sucPathZ zeroZ
52 | testNOneZ : Z = transport ( sucPathZ @ - i) zeroZ
53 |
54 | -----------
55 |
56 | inlNotinr (A B:U) (a:A) (b:B) (h: Path (either A B) (inl a) (inr b)) : empty =
57 | subst (either A B) T (inl a) (inr b) h tt
58 | where
59 | T : either A B -> U = split
60 | inl _ -> unit
61 | inr _ -> empty
62 |
63 | inrNotinl (A B:U) (a:A) (b:B) (h : Path (either A B) (inr b) (inl a)) : empty =
64 | subst (either A B) T (inr b) (inl a) h tt
65 | where
66 | T : either A B -> U = split
67 | inl _ -> empty
68 | inr _ -> unit
69 |
70 | injInl (A B :U) (x0 x1:A) (h : Path (either A B) (inl x0) (inl x1)) : Path A x0 x1 =
71 | subst (either A B) T (inl x0) (inl x1) h (refl A x0)
72 | where
73 | T : either A B -> U = split
74 | inl x -> Path A x0 x
75 | inr _ -> empty
76 |
77 | injInr (A B :U) (x0 x1:B) (h: Path (either A B) (inr x0) (inr x1)) : Path B x0 x1 =
78 | subst (either A B) T (inr x0) (inr x1) h (refl B x0)
79 | where
80 | T : either A B -> U = split
81 | inl _ -> empty
82 | inr x -> Path B x0 x
83 |
84 | -- If A and B are discrete then "A either B" is discrete
85 | orDisc (A B : U) (dA : discrete A) (dB : discrete B) :
86 | (z z1 : either A B) -> dec (Path (either A B) z z1) = split
87 | inl a -> rem1
88 | where rem1 : (z1:either A B) -> dec (Path (either A B) (inl a) z1) = split
89 | inl a1 -> rem (dA a a1)
90 | where rem : dec (Path A a a1) -> dec (Path (either A B) (inl a) (inl a1)) = split
91 | inl p -> inl ( inl (p @ i))
92 | inr h -> inr (\ (p:Path (either A B) (inl a) (inl a1)) -> h (injInl A B a a1 p))
93 | inr b -> inr (inlNotinr A B a b)
94 | inr b -> rem1
95 | where rem1 : (z1:either A B) -> dec (Path (either A B) (inr b) z1) = split
96 | inl a -> inr (inrNotinl A B a b)
97 | inr b1 -> rem (dB b b1)
98 | where rem : dec (Path B b b1) -> dec (Path (either A B) (inr b) (inr b1)) = split
99 | inl p -> inl ( inr (p @ i))
100 | inr h -> inr (\ (p:Path (either A B) (inr b) (inr b1)) -> h (injInr A B b b1 p))
101 |
102 |
103 | ZSet : isSet Z = hedberg Z (orDisc nat nat natDec natDec)
104 |
--------------------------------------------------------------------------------
/cubicaltt/src/interval.ctt:
--------------------------------------------------------------------------------
1 | {- Interval Type:
2 | Copyright (c) Groupoid Infinity, 2014-2018.
3 |
4 | HoTT 6.3 The interval -}
5 |
6 | module interval where
7 | import equiv
8 | import iso
9 | import prop
10 |
11 | -- I = (X:U) -> isSet X -> (x y: X) -> Path X x y -> X
12 |
13 | data I = i0
14 | | i1
15 | | seg [(i=0) -> i0,
16 | (i=1) -> i1]
17 |
18 | pathToHtpy (A: U) (x y: A) (p: Path A x y): I -> A
19 | = split { i0 -> x; i1 -> y; seg @ i -> p @ i }
20 |
21 | -- H_{f,g:X→Y}: X × [0,1] → Y, f(x)=g(x)
22 | homotopy (X Y: U)
23 | (f g: X -> Y)
24 | (p: (x: X) -> Path Y (f x) (g x))
25 | (x: X): I -> Y = pathToHtpy Y (f x) (g x) (p x)
26 |
27 | -- Proof of funext from the interval
28 | fext (A B: U) (f g: A -> B) (p: (x: A) -> Path B (f x) (g x)): Path (A -> B) f g
29 | = (\(x : A) -> homotopy A B f g p x (seg{I} @ j))
30 |
31 | toUnit : I -> unit = split { i0 -> tt; i1 -> tt; seg @ i -> tt }
32 | fromUnit : unit -> I = split tt -> i0
33 | toUnitK : (a : unit) -> Path unit (toUnit (fromUnit a)) a = split tt -> tt
34 | fromUnitK : (a : I) -> Path I (fromUnit (toUnit a)) a
35 | = split { i0 -> i0; i1 -> seg {I} @ i; seg @ i -> seg {I} @ i /\ j }
36 |
37 | unitEqI: Path U unit I = isoPath unit I fromUnit toUnit fromUnitK toUnitK
38 | propI: isProp I = subst U isProp unit I unitEqI propUnit
39 |
40 | T: U = Path I i0 i0
41 | p0: T = refl I i0
42 | test: T = propI i0 i0
43 |
--------------------------------------------------------------------------------
/cubicaltt/src/iso.ctt:
--------------------------------------------------------------------------------
1 | {- Iso Type:
2 | - Commutative Square
3 | - Iso To Path
4 | Copyright (c) Groupoid Infinity, 2014-2018. -}
5 |
6 | module iso where
7 | import retract
8 | import equiv
9 | import set
10 |
11 | -- u
12 | -- a ------> b
13 | -- | |
14 | -- p | | q
15 | -- | |
16 | -- V V
17 | -- c ------> d
18 | -- v
19 |
20 | Square (A: U)(a b c d: A)(u: Path A a b)(v: Path A c d)(p: Path A a c)(q: Path A b d): U
21 | = PathP ( (PathP ( A) (u @ i) (v @ i))) p q
22 |
23 | constSquare (A: U) (a: A) (p: Path A a a): Square A a a a a p p p p
24 | = comp (<_> A) a [ (i = 0) -> p @ j \/ - k,
25 | (i = 1) -> p @ j /\ k,
26 | (j = 0) -> p @ i \/ - k,
27 | (j = 1) -> p @ i /\ k ]
28 |
29 | isIso (A B: U): U
30 | = (f: A -> B)
31 | * (g: B -> A)
32 | * (s: section A B f g)
33 | * ( retract A B f g)
34 |
35 | ISO: U
36 | = (A: U)
37 | * (B: U)
38 | * isIso A B
39 |
40 | lemIso (A B: U) (f: A -> B) (g: B -> A) (s: section A B f g) (t: retract A B f g)
41 | (y: B) (x0 x1: A) (p0: Path B y (f x0)) (p1: Path B y (f x1))
42 | : Path (fiber A B f y) (x0,p0) (x1,p1) = (p @ i,sq1 @ i) where
43 | rem0: Path A (g y) x0 = comp ( A) (g (p0 @ i)) [ (i = 1) -> t x0, (i = 0) -> g y ]
44 | rem1: Path A (g y) x1 = comp ( A) (g (p1 @ i)) [ (i = 1) -> t x1, (i = 0) -> g y ]
45 | p: Path A x0 x1 = comp ( A) (g y) [ (i = 0) -> rem0, (i = 1) -> rem1 ]
46 | fill0: Square A (g y)(g (f x0)) (g y) x0 ( g (p0 @ i)) rem0 ( g y) (t x0) =
47 | comp ( A) (g (p0 @ i)) [ (i = 1) -> t x0 @ j /\ k,
48 | (i = 0) -> g y,
49 | (j = 0) -> g (p0 @ i) ]
50 | fill1: Square A(g y)(g(f x1))(g y) x1 (g (p1@i)) rem1 ( g y) (t x1) =
51 | comp ( A) (g (p1 @ i)) [ (i = 1) -> t x1 @ j /\ k,
52 | (i = 0) -> g y,
53 | (j = 0) -> g (p1 @ i) ]
54 | fill2: Square A (g y) (g y) x0 x1 ( g y) p rem0 rem1 =
55 | comp ( A) (g y) [ (i = 0) -> rem0 @ j /\ k,
56 | (i = 1) -> rem1 @ j /\ k,
57 | (j = 0) -> g y ]
58 | sq: Square A(g y)(g y)(g(f x0))(g(f x1))(g y) (g (f(p@i)))(g(p0@j))(g(p1@j)) =
59 | comp ( A) (fill2 @ i @ j) [ (i = 0) -> fill0 @ j @ -k,
60 | (i = 1) -> fill1 @ j @ -k,
61 | (j = 0) -> g y,
62 | (j = 1) -> t (p @ i) @ -k ]
63 | sq1: Square B y y (f x0) (f x1) (y) ( f (p @ i)) p0 p1 =
64 | comp ( B) (f (sq @ i @j)) [ (i = 0) -> s (p0 @ j),
65 | (i = 1) -> s (p1 @ j),
66 | (j = 1) -> s (f (p @ i)),
67 | (j = 0) -> s y ]
68 |
69 | isoToEquiv (A B: U) (f: A -> B) (g: B -> A) (s: section A B f g) (t: retract A B f g): isEquiv A B f
70 | = \(y:B) -> ((g y,s y@-i),\ (z:fiber A B f y) -> lemIso A B f g s t y (g y) z.1 (s y@-i) z.2)
71 |
72 | equivProp (A B: U) (a: isProp A) (b: isProp B) (f: A -> B) (g: B -> A): equiv A B
73 | = (f, isoToEquiv A B f g (\(y:B)->b(f(g y))y) (\(x:A)->a(g(f x))x))
74 |
75 | -- pi version of isoPath
76 | isoPath (A B: U) (f: A -> B) (g: B -> A)
77 | (s: section A B f g) (t: retract A B f g): Path U A B
78 | = Glue B [ (i = 0) -> (A,f,isoToEquiv A B f g s t),
79 | (i = 1) -> (B,idfun B,idIsEquiv B) ]
80 |
81 | testIsoPath (A B : U) (f : A -> B) (g : B -> A)
82 | (s : (y : B) -> Path B (f (g y)) y)
83 | (t : (x : A) -> Path A (g (f x)) x) (a:A)
84 | : Path B (f a) (trans A B (isoPath A B f g s t) a) =
85 | comp (<_>B) (comp (<_>B) (f a) [(i=0) -> <_> f a]) [(i=0) -> <_> f a]
86 |
87 | -- sigma version of isoPath
88 | isoToPath (i: ISO): Path U i.1 i.2.1
89 | = isoPath i.1 i.2.1 i.2.2.1 i.2.2.2.1 i.2.2.2.2.1 i.2.2.2.2.2
90 |
91 | -- A proof that two propositions with maps between them can be identified with each other
92 | propPath (A B: U) (f: A -> B) (g: B -> A) (pa: isProp A) (pb: isProp B): Path U A B
93 | = isoToPath (A,B,f,g,(\ (b: B) -> pb (f (g b)) b),(\ (a: A) -> pa (g (f a)) a))
94 |
95 | iso_Form (A B: U)
96 | : U
97 | = isIso A B -> Path U A B
98 |
99 | iso_Intro (A B: U)
100 | : iso_Form A B
101 | = \(x: isIso A B) -> isoToPath (A,B,x)
102 |
103 |
104 | iso_Elim (A B: U)
105 | : Path U A B -> isIso A B
106 | = \(p: Path U A B) ->
107 | (coerce A B p,coerce B A (p@-i), x p,y p) where
108 | x (p: Path U A B): section A B (coerce A B p) (coerce B A (p@-i)) = undefined
109 | y (p: Path U A B): retract A B (coerce A B p) (coerce B A (p@-i)) = undefined
110 |
111 | iso_Comp (A B : U) (p : Path U A B)
112 | : Path (Path U A B) (iso_Intro A B (iso_Elim A B p)) p
113 | = undefined
114 |
115 | iso_Uniq (A B : U) (p: isIso A B)
116 | : Path (isIso A B) (iso_Elim A B (iso_Intro A B p)) p
117 | = undefined
118 |
119 | IsoPathType (A B: U): isIso (isIso A B) (Path U A B)
120 | = (iso_Intro A B,iso_Elim A B,iso_Comp A B,iso_Uniq A B)
121 |
122 | PiType (A: U) (B: A -> U): isIso (Pi A B) (Pi A B)
123 | = (app A B,app A B,Pi_Eta A B,Pi_Eta A B)
124 |
125 | UnivType (A B: U): isIso (equiv A B) (Path U A B)
126 | = (equivToPath A B, pathToEquiv A B,eqToEq A B,idToPath A B)
127 |
--------------------------------------------------------------------------------
/cubicaltt/src/iso_pi.ctt:
--------------------------------------------------------------------------------
1 | module iso_pi where
2 |
3 | import pi
4 | import iso
5 |
6 | pathPi (A:U) (B:A->U) (f g : Pi A B)
7 | : Path U (Path (Pi A B) f g) ((x:A) -> Path (B x) (f x) (g x))
8 | = isoPath (Path (Pi A B) f g) ((x:A) -> Path (B x) (f x) (g x)) F G S T where
9 | T0 : U = Path (Pi A B) f g
10 | T1 : U = (x:A) -> Path (B x) (f x) (g x)
11 | F (p:T0) : T1 = \ (x:A) -> p@i x
12 | G (p:T1) : T0 = \ (x:A) -> p x @ i
13 | S (p:T1) : Path T1 (F (G p)) p = refl T1 p
14 | T (p:T0) : Path T0 (G (F p)) p = refl T0 p
15 |
16 | groupoidPi (A: U) (B: A -> U) (h: (x: A) -> isGroupoid (B x)) (f g: Pi A B)
17 | : isSet (Path (Pi A B) f g)
18 | = subst U isSet T (Path (Pi A B) f g) ( pathPi A B f g @ -i) rem where
19 | T: U = (x:A) -> Path (B x) (f x) (g x)
20 | rem: isSet T = setPi A (\ (x:A) -> Path (B x) (f x) (g x)) (\ (x:A) -> h x (f x) (g x))
21 |
22 |
--------------------------------------------------------------------------------
/cubicaltt/src/iso_sigma.ctt:
--------------------------------------------------------------------------------
1 | module iso_sigma where
2 | import path
3 | import pi
4 | import sigma
5 | import iso
6 |
7 | -- used in grothedieck.ctt and below
8 | pathSig (A:U) (B : A -> U) (t u : Sigma A B) :
9 | Path U (Path (Sigma A B) t u) ((p : Path A t.1 u.1) * PathP ( B (p @ i)) t.2 u.2)
10 | = isoPath T0 T1 f g s t where
11 | T0 : U = Path (Sigma A B) t u
12 | T1 : U = (p:Path A t.1 u.1) * PathP ( B (p@i)) t.2 u.2
13 | f (q:T0) : T1 = ( (q@i).1, (q@i).2)
14 | g (z:T1) : T0 = (z.1 @i,z.2 @i)
15 | s (z:T1) : Path T1 (f (g z)) z = refl T1 z
16 | t (q:T0) : Path T0 (g (f q)) q = refl T0 q
17 |
18 | -- used in algstruct
19 | setSig (A:U) (B: A-> U) (sA: isSet A) (sB : (x:A) -> isSet (B x)): isSet (Sigma A B) = goal where
20 | goal (t u : Sigma A B) : isProp (Path (Sigma A B) t u)
21 | = substInv U isProp (Path (Sigma A B) t u) ((p:T) * C p) rem3 rem2 where
22 | T : U = Path A t.1 u.1
23 | C (p:T) : U = PathP ( B (p@i)) t.2 u.2
24 | rem (p : T) : isProp (C p) = corSigSet A B sB t u p
25 | rem1 : isProp T = sA t.1 u.1
26 | rem2 : isProp ((p:T) * C p) = propSig T C rem1 rem
27 | rem3 : Path U (Path (Sigma A B) t u) ((p:T) * C p) = pathSig A B t u
28 |
29 | pathSig2 (A:U) (P: A -> U) (t u: Sigma A P)
30 | (p: Path A t.1 u.1)
31 | (s: PathP ( P (p @ i)) t.2 u.2)
32 | : Path (Sigma A P) t u
33 | = comp ( pathSig A P t u @ -i) (p,s) []
34 |
35 | pathSig3 (A:U) (P : A -> U) (t u : Sigma A P) (pp: (p : Path A t.1 u.1) * Path (P u.1) (transport (P (p @ i)) t.2) u.2): Path (Sigma A P) t u
36 | = pathSig2 A P t u (pp.1, transport foo pp.2) where
37 | p: Path A t.1 u.1 = pp.1
38 | P' : Path U (P t.1) (P u.1) = P (p@i)
39 | T0 : U = PathP P' t.2 u.2
40 | T1 : U = Path (P u.1) (transport P' t.2) u.2
41 | foo : Path U T1 T0 = sym U T0 T1 (pathSig0 A P t u p)
42 | pathSig2 (A:U) (P : A -> U) (t u : Sigma A P) (pp: (p : Path A t.1 u.1) * PathP ( P (p @ i)) t.2 u.2): Path (Sigma A P) t u
43 | = comp ( pathSig A P t u @ -i) pp []
44 |
45 | pathSigHoTT (A: U) (P: A -> U) (t u: Sigma A P) (p: Path A t.1 u.1)
46 | (s: Path (P u.1) (transport ( P (p @ i)) t.2) u.2)
47 | : Path (Sigma A P) t u
48 | = pathSig2 A P t u p (transport f s) where
49 | P': Path U (P t.1) (P u.1) = P (p@i)
50 | T0: U = PathP P' t.2 u.2
51 | T1: U = Path (P u.1) (transport P' t.2) u.2
52 | f: Path U T1 T0 = sym U T0 T1 (pathSig0 A P t u p)
53 |
54 | lemContr (A:U) (pA:isProp A) (a:A) : isContr A = (a,rem)
55 | where rem (y:A) : Path A a y = pA a y
56 |
57 | lem3 (A:U) (B:A-> U) (pB : (x:A) -> isProp (B x)) (t u : Sigma A B) (p:Path A t.1 u.1) :
58 | isContr (PathP (B (p@i)) t.2 u.2) = lemContr T0 (substInv U isProp T0 T1 rem rem1) rem2
59 | where P : Path U (B t.1) (B u.1) = B (p@i)
60 | T0 : U = PathP P t.2 u.2
61 | T1 : U = Path (B u.1) (transport P t.2) u.2
62 | rem : Path U T0 T1 = pathSig0 A B t u p
63 | v2 : B u.1 = transport P t.2
64 | rem1 : isProp T1 = propSet (B u.1) (pB u.1) v2 u.2
65 | rem2 : T0 = transport (rem@-i) (pB u.1 v2 u.2)
66 |
67 | lem6 (A:U) (P:A-> U) (cA:(x:A) -> isContr (P x)) : Path U ((x:A)*P x) A = isoPath T A f g t s
68 | where
69 | T : U = (x:A) * P x
70 | f (z:T) : A = z.1
71 | g (x:A) : T = (x,(cA x).1)
72 | s (z:T) : Path T (g (f z)) z = (z.1,((cA z.1).2 z.2)@ i)
73 | t (x:A) : Path A (f (g x)) x = refl A x
74 |
75 | lemSigProp (A:U) (B:A-> U) (pB : (x:A) -> isProp (B x)) (t u : Sigma A B) : Path U (Path (Sigma A B) t u) (Path A t.1 u.1) =
76 | composition U (Path (Sigma A B) t u) ((p:Path A t.1 u.1) * PathP ( B (p@i)) t.2 u.2) (Path A t.1 u.1) rem2 rem1
77 | where
78 | T : U = Path A t.1 u.1
79 | C (p:T) : U = PathP ( B (p@i)) t.2 u.2
80 | rem (p : T) : isContr (C p) = lem3 A B pB t u p
81 | rem1 : Path U ((p:T) * C p) T = lem6 T C rem
82 | rem2 : Path U (Path (Sigma A B) t u) ((p:T) * C p) = pathSig A B t u
83 |
84 | flipfunIso (A B C: U): Path U (A -> B -> C) (B -> A -> C)
85 | = isoPath AB BA from to toK fromK where
86 | AB: U = A -> B -> C
87 | BA: U = B -> A -> C
88 | from: AB -> BA = flip A B C
89 | to: BA -> AB = flip B A C
90 | fromK: (f: AB) -> Path AB (to (from f)) f = refl AB
91 | toK: (f: BA) -> Path BA (from (to f)) f = refl BA
92 |
--------------------------------------------------------------------------------
/cubicaltt/src/join.ctt:
--------------------------------------------------------------------------------
1 | module join where
2 | import proto
3 | import iso
4 | import s1
5 | import pointed
6 | import suspension
7 |
8 | data join (A B : U) = inl (a : A)
9 | | inr (b : B)
10 | | pushC (a : A) (b : B) [ (i = 0) -> inl a
11 | , (i = 1) -> inr b ]
12 |
13 | pushP (A B : U) (a : A) (b : B) : Path (join A B) (inl a) (inr b) =
14 | pushC {join A B} a b @ i
15 |
16 | joinpt (A : pointed) (B : U) : pointed = (join A.1 B,inl (point A))
17 |
18 | r2lInr (A B C : U) : join B C -> join (join A B) C = split
19 | inl b -> inl (inr b)
20 | inr c -> inr c
21 | pushC b c @ i -> pushP (join A B) C (inr b) c @ i
22 |
23 | r2lPushInl (A B C : U) (a : A) (b : B) :
24 | Path (join (join A B) C) (inl (inl a)) (inl (inr b)) = inl (pushP A B a b @ i)
25 |
26 | r2lSquare (A B C : U) (a : A) (b : B) (c : C) :
27 | PathP ( Path (join (join A B) C) (inl (pushP A B a b @ i)) (inr c))
28 | (pushP (join A B) C (inl a) c) (pushP (join A B) C (inr b) c)
29 | = pushP (join A B) C (pushP A B a b @ i) c @ j
30 |
31 | opr2l (A : U) (a b c : A) (p : Path A a c) (q : Path A a b) (r : Path A b c)
32 | (sq : Square A a b c c q (<_> c) p r) :
33 | Square A a a b c (<_> a) r q p =
34 | comp (<_> A) (p @ i) [ (i = 0) -> q @ j /\ k
35 | , (i = 1) -> p @ j \/ -k
36 | , (j = 0) -> p @ i /\ -k
37 | , (j = 1) -> sq @ k @ i ]
38 |
39 | r2lPushPush (A B C : U) (a : A) (b : B) (c : C) :
40 | Square (join (join A B) C) (inl (inl a)) (inl (inl a)) (inl (inr b)) (inr c)
41 | (<_> inl (inl a)) (pushP (join A B) C (inr b) c)
42 | (r2lPushInl A B C a b) (pushP (join A B) C (inl a) c) =
43 | opr2l (join (join A B) C) (inl (inl a)) (inl (inr b)) (inr c)
44 | (pushP (join A B) C (inl a) c) (r2lPushInl A B C a b)
45 | (pushP (join A B) C (inr b) c) (r2lSquare A B C a b c)
46 |
47 | r2lPush (A B C : U) (a : A) :
48 | (bc : join B C) -> Path (join (join A B) C) (inl (inl a)) (r2lInr A B C bc) = split
49 | inl b -> r2lPushInl A B C a b
50 | inr c -> pushP (join A B) C (inl a) c
51 | pushC b c @ i -> r2lPushPush A B C a b c @ i
52 |
53 | joinassoc1 (A B C : U) : join A (join B C) -> join (join A B) C = split
54 | inl a -> inl (inl a)
55 | inr bc -> r2lInr A B C bc
56 | pushC a bc @ i -> r2lPush A B C a bc @ i
57 |
58 | mapJoin (A A' B B' : U) (f : A -> A') (g : B -> B') : join A B -> join A' B' = split
59 | inl a -> inl (f a)
60 | inr b -> inr (g b)
61 | pushC a b @ i -> pushP A' B' (f a) (g b) @ i
62 |
63 | psi (A : U) : susp A -> join bool A = split
64 | north -> inl true
65 | south -> inl false
66 | merid a @ i -> composition (join bool A) (inl true) (inr a) (inl false)
67 | (pushP bool A true a) ( pushP bool A false a @ -i) @ i
68 |
69 | psiinv (A : U) : join bool A -> susp A = split
70 | inl b ->
71 | let case : (b : bool) -> susp A = split
72 | false -> south
73 | true -> north
74 | in case b
75 | inr a -> south
76 | pushC b a @ i ->
77 | let case (a : A) : (b : bool) -> Path (susp A) (psiinv A (inl b)) south = split
78 | false -> <_> south
79 | true -> merid1 A a
80 | in case a b @ i
81 |
82 | c (x : join bool bool) : S1 = suspS1 (psiinv bool x)
83 |
84 | cinv (x : S1) : join bool bool = psi bool (S1susp x)
85 |
86 | -- The map e
87 | e (x : S3) : join S1 S1 =
88 | let x1 : join bool S2 = psi S2 x
89 | x2 : join bool (join bool S1) =
90 | mapJoin bool bool S2 (join bool S1) (idfun bool) (psi S1) x1
91 | x3 : join (join bool bool) S1 = joinassoc1 bool bool S1 x2
92 | res : join S1 S1 = mapJoin (join bool bool) S1 S1 S1 c (idfun S1) x3
93 | in res
94 |
95 | prealpha : join S1 S1 -> S2 = split
96 | inl x -> north
97 | inr y -> north
98 | pushC x y @ i -> composition S2 north south north (merid1 S1 x) ( merid1 S1 y @ -i) @ i
99 |
100 | alpha : pmap (joinpt S1pt S1) S2pt = (prealpha, <_> north)
101 |
--------------------------------------------------------------------------------
/cubicaltt/src/lambek.ctt:
--------------------------------------------------------------------------------
1 | {- Lambek Encoding:
2 | Copyright (c) Groupoid Infinity, 2014-2018
3 |
4 | see HoTT 5.4 Inductive types are initial algebras -}
5 |
6 | module lambek where
7 | import proto
8 | import path
9 | import nat
10 | import set
11 | import iso_sigma
12 | import iso_pi
13 |
14 | {- Definition 5.4.1. A Nat-algebra
15 | Definition 5.4.2. Nat Homomorphism -}
16 |
17 | natOb: U
18 | = (X: U)
19 | * (zero: X)
20 | * (succ: X -> X)
21 | * unit
22 |
23 | natHom (x1 x2: natOb): U
24 | = (map: x1.1 -> x2.1)
25 | * (mapZero: Path x2.1 (map (x1.2.1)) (x2.2.1))
26 | * (mapSucc: (x: x1.1) -> Path x2.1 (map (x1.2.2.1 x)) (x2.2.2.1 (map x)))
27 | * unit
28 |
29 | isHomotopyInitialNat (I: natOb): U
30 | = (C: natOb)
31 | * (x: natHom I C)
32 | * ((y: natHom I C) -> Path (natHom I C) x y)
33 |
34 | listOb (A: U): U = (X: U) * (nil: X) * (cons: A -> X -> X) * unit
35 | listHom (A: U) (x1 x2: listOb A): U
36 | = (map: x1.1 -> x2.1)
37 | * (mapNil: Path x2.1 (map (x1.2.1)) (x2.2.1))
38 | * (mapCons: (a:A) (x: x1.1) -> Path x2.1 (map (x1.2.2.1 a x)) (x2.2.2.1 a (map x))) * unit
39 |
40 | isHomotopyInitialList (A: U) (I: listOb A): U = (C: listOb A) -> isContr(listHom A I C)
41 |
42 |
--------------------------------------------------------------------------------
/cubicaltt/src/list.ctt:
--------------------------------------------------------------------------------
1 | {- Run-Time List Type:
2 | - List;
3 | - Polymorphic funtions.
4 | Copyright (c) Groupoid Infinity, 2014-2018. -}
5 |
6 | module list where
7 |
8 | import eq
9 | import nat
10 | import maybe
11 | import proto
12 |
13 | data list (A: U) = nil | cons (a: A) (as: list A)
14 |
15 | listCase (A C:U) (a b: C): list A -> C
16 | = split { nil -> a ; cons x xs -> b }
17 |
18 | listRec (A C:U) (z: C) (s: A->list A->C->C): (n:list A) -> C
19 | = split { nil -> z ; cons x xs -> s x xs (listRec A C z s xs) }
20 |
21 | listElim (A: U) (C:list A->U) (z: C nil) (s: (x:A)(xs:list A)->C(cons x xs)): (n:list A) -> C(n)
22 | = split { nil -> z ; cons x xs -> s x xs }
23 |
24 | listInd (A: U) (C:list A->U) (z: C nil) (s: (x:A)(xs:list A)->C(xs)->C(cons x xs)): (n:list A) -> C(n)
25 | = split { nil -> z ; cons x xs -> s x xs (listInd A C z s xs) }
26 |
27 | null (A: U): list A -> bool = split
28 | nil -> true
29 | cons x xs -> false
30 |
31 | head (A: U): list A -> maybe A = split
32 | nil -> nothing
33 | cons x xs -> just x
34 |
35 | tail (A: U): list A -> maybe (list A) = split
36 | nil -> nothing
37 | cons x xs -> just xs
38 |
39 | nth (A: U): nat -> list A -> maybe A = split
40 | zero -> split@(list A -> maybe A) with
41 | nil -> nothing
42 | cons x xs -> just x
43 | succ i -> split@(list A -> maybe A) with
44 | nil -> nothing
45 | cons x xs -> nth A (pred i) xs
46 |
47 | append (A: U): list A -> list A -> list A = split
48 | nil -> idfun (list A)
49 | cons x xs -> \(ys: list A) -> cons x (append A xs ys)
50 |
51 | reverse (A: U): list A -> list A = rev nil where
52 | rev (acc: list A): list A -> list A = split
53 | nil -> acc
54 | cons x xs -> rev (cons x acc) xs
55 |
56 | map (A B: U) (f: A -> B) : list A -> list B = split
57 | nil -> nil
58 | cons x xs -> cons (f x) (map A B f xs)
59 |
60 | zipWith (A B C: U) (f: A -> B -> C): list A -> list B -> list C = go where
61 | go: list A -> list B -> list C = split
62 | nil -> split@(list B->list C) with { nil -> nil ; cons y ys -> nil }
63 | cons x xs -> split@(list B->list C) with { nil->nil ; cons y ys -> cons (f x y) (go xs ys) }
64 |
65 | zip (A B: U): list A -> list B -> list (tuple A B)
66 | = zipWith A B (tuple A B) (\(x:A)(y:B) -> pair x y)
67 |
68 | foldr (A B: U) (f: A -> B -> B) (Z: B): list A -> B = split
69 | nil -> Z
70 | cons x xs -> f x (foldr A B f Z xs)
71 |
72 | foldl (A B: U) (f: B -> A -> B) (Z: B): list A -> B = split
73 | nil -> Z
74 | cons x xs -> foldl A B f (f Z x) xs
75 |
76 | switch (A: U) (a b: unit -> list A) : bool -> list A = split
77 | false -> b tt
78 | true -> a tt
79 |
80 | filter (A: U) (p: A -> bool) : list A -> list A = split
81 | nil -> nil
82 | cons x xs -> switch A (\(_:unit) -> cons x (filter A p xs))
83 | (\(_:unit) -> filter A p xs) (p x)
84 |
85 | uncons (A: U): list A -> maybe ((a: A) * (list A)) = split
86 | nil -> nothing
87 | cons x xs -> just (x,xs)
88 |
89 | length (A: U): list A -> nat = split
90 | nil -> zero
91 | cons x xs -> add one (length A xs)
92 |
93 | list_eq (A: eq_): list A.1 -> list A.1 -> bool = split
94 | nil -> split@(list A.1 -> bool) with
95 | nil -> true
96 | cons b bs -> false
97 | cons x xs -> split@(list A.1 -> bool) with
98 | nil -> false
99 | cons a as -> or (A.2 a x) (list_eq A xs as)
100 |
101 |
--------------------------------------------------------------------------------
/cubicaltt/src/list_theory.ctt:
--------------------------------------------------------------------------------
1 | {- List Theorems:
2 | - Functor and Inductive instances
3 | Copyright (c) Groupoid Infinity, 2014-2018. -}
4 |
5 | module list_theory where
6 |
7 | import proto
8 | import list
9 | import control
10 | import recursion
11 | import nat_theory
12 |
13 | -- theorems
14 | assoc (A:U) : (xs ys zs : list A) ->
15 | Path (list A) (append A (append A xs ys) zs) (append A xs (append A ys zs)) = split
16 | nil -> \ (ys zs:list A) -> append A ys zs
17 | cons x xs -> \ (ys zs:list A) -> cons x (assoc A xs ys zs@i)
18 |
19 | lem (A B C:U) (f:A->B) (g:B -> C) : (xs:list A) ->
20 | Path (list C) (map B C g (map A B f xs)) (map A C (\ (x:A) -> g (f x)) xs) = split
21 | nil -> nil
22 | cons x xs -> cons (g (f x)) (lem A B C f g xs@i)
23 |
24 | lem2 (A:U) : (xs:list A) -> Path (list A) (append A xs nil) xs = split
25 | nil -> nil
26 | cons x xs -> cons x (lem2 A xs@i)
27 |
28 | list_id (A:U) : (xs:list A) -> Path (list A) (map A A (idfun A) xs) xs = split
29 | nil -> nil
30 | cons x xs -> cons x (list_id A xs@i)
31 |
32 | list_compose (A B C: U) (f: B->C) (g: A->B): (x: list A) ->
33 | Path (list C) (map A C (o A B C f g) x)
34 | ((o (list A) (list B) (list C) (map B C f) (map A B g)) x) = split
35 | nil -> nil
36 | cons x xs -> cons ((o A B C f g) x) (list_compose A B C f g xs@i)
37 |
38 | -- Type-class instances
39 | eq_list_nat: eq_ = (list nat, list_eq eq_nat)
40 | eq_list_list_nat: eq_ = (list (list nat), list_eq eq_list_nat)
41 | pure_list: pure = (list,\(A:U)(x:A)->cons x nil)
42 | functor_list: functor = (list,map)
43 | functor_laws: FUNCTOR = (functor_list,list_id,list_compose,tt)
44 | ind_list (T:U): ind list T = inductive (list,map) T
45 | coind_list (T:U): coind list T = coinductive (list,map) T
46 |
47 |
--------------------------------------------------------------------------------
/cubicaltt/src/localization.ctt:
--------------------------------------------------------------------------------
1 | module localization where
2 | import proto
3 | import path
4 |
5 | -- This definition of localization is internal, stronger than
6 | -- standard sort of localization in homotopy theory;
7 | - but remains equivalent.
8 |
9 | -- Localization Modality (S=B, T=C)
10 |
11 | data Localize (A X: U) (S T: A -> U) (F : (x:A) -> S x -> T x)
12 | = center (x: X)
13 | | ext (a: A) (f: S a -> Localize A X S T F) (t: T a)
14 | | isExt (a: A) (f: S a -> Localize A X S T F) (s: S a)
15 | [ (i=0) -> ext a f (F a s) , (i=1) -> f s ]
16 | | extEq (a: A) (g h: T a -> Localize A X S T F)
17 | (p: (s : S a) -> Path (Localize A X S T F) (g (F a s)) (h (F a s)))
18 | (t : T a) [ (i=0) -> g t , (i=1) -> h t ]
19 | | isExtEq (a: A) (g h : T a -> Localize A X S T F)
20 | (p: (s : S a) -> Path (Localize A X S T F) (g (F a s)) (h (F a s)))
21 | (s : S a) [ (i=0) -> extEq {Localize A X S T F} a g h p (F a s) @ i, (i=1) -> p s @ i]
22 |
23 | isLocal (A X: U) (S T: A -> U) (F : (x:A) -> S x -> T x) : U = undefined
24 |
25 | LocalizationRec (A X: U) (S T: A -> U) (F : (x:A) -> S x -> T x)
26 | (Y : U)
27 | (locality : isLocal A Y S T F)
28 | (f: X -> Y)
29 | : Localize A X S T F -> Y
30 | = undefined
31 |
32 | LocalizationInd (A X : U) (S T : A -> U) (F : (x:A) -> S x -> T x)
33 | (P : Localize A X S T F -> U)
34 | (n : (x : X) -> P (center x))
35 | (r : (a : A) (f: S a -> Localize A X S T F)
36 | (g: (b: S a) -> P (f b))
37 | (t: T a) -> P (ext a f t))
38 | (s : (a : A) (f: S a -> Localize A X S T F)
39 | (g: (b: S a) -> P (f b))
40 | (b: S a) -> PathP ( P (isExt {Localize A X S T F} a f b @ i))
41 | (r a f g (F a b)) (g b))
42 | : (x : Localize A X S T F) -> P x
43 | = undefined
44 |
45 |
--------------------------------------------------------------------------------
/cubicaltt/src/logic.ctt:
--------------------------------------------------------------------------------
1 | module logic where
2 |
3 | -- https://github.com/jonaprieto/agda-prop
4 | -- Cai, L., Kaposi, A., & Altenkirch, T. (2015)
5 | -- Formalising the Completeness Theorem of Classical Propositional Logic in Agda.
6 | -- Retrieved from https://akaposi.github.io/proplogic.pdf
7 |
8 | -- data PropFormula : Set where
9 | -- Var : Fin n → PropFormula
10 | -- ⊤ : PropFormula
11 | -- ⊥ : PropFormula
12 | -- _∧_ _∨_ _⊃_ _⇔_ : (φ ψ : PropFormula) → PropFormula
13 | -- ¬_ : (φ : PropFormula) → PropFormula
14 |
15 | -- _,_ : Ctxt → PropFormula → Ctxt
16 | -- Γ , φ = Γ ++ [ φ ]
17 |
18 | -- ∅ : Ctxt
19 | -- ∅ = []
20 |
21 | -- infix 30 _⨆_
22 | -- _⨆_ : Ctxt → Ctxt → Ctxt
23 | -- Γ ⨆ Δ = Γ ++ Δ
24 |
25 | -- Ctxt : Set
26 | -- Ctxt = List PropFormula
27 |
28 | -- infix 11 ¬_
29 | -- infixl 8 _∧_ _∨_
30 | -- infixr 7 _⊃_ _⇔_
31 |
32 | -- data _⊢_ : Ctxt → PropFormula → Set where
33 | -- assume : ∀ {Γ} → (φ : PropFormula) → Γ , φ ⊢ φ
34 | -- axiom : ∀ {Γ} → (φ : PropFormula) → φ ∈ Γ → Γ ⊢ φ
35 | -- weaken : ∀ {Γ} {φ} → (ψ : PropFormula) → Γ ⊢ φ → Γ , ψ ⊢ φ
36 | -- weaken₂ : ∀ {Γ} {φ} → (ψ : PropFormula) → Γ ⊢ φ → ψ ∷ Γ ⊢ φ
37 | -- ⊤-intro : ∀ {Γ} → Γ ⊢ ⊤
38 | -- ⊥-elim : ∀ {Γ} → (φ : PropFormula) → Γ ⊢ ⊥ → Γ ⊢ φ
39 | -- ¬-intro : ∀ {Γ} {φ} → Γ , φ ⊢ ⊥ → Γ ⊢ ¬ φ
40 | -- ¬-elim : ∀ {Γ} {φ} → Γ ⊢ ¬ φ → Γ ⊢ φ → Γ ⊢ ⊥
41 | -- ∧-intro : ∀ {Γ} {φ ψ} → Γ ⊢ φ → Γ ⊢ ψ → Γ ⊢ φ ∧ ψ
42 | -- ∧-proj₁ : ∀ {Γ} {φ ψ} → Γ ⊢ φ ∧ ψ → Γ ⊢ φ
43 | -- ∧-proj₂ : ∀ {Γ} {φ ψ} → Γ ⊢ φ ∧ ψ → Γ ⊢ ψ
44 | -- ∨-intro₁ : ∀ {Γ} {φ} → (ψ : PropFormula) → Γ ⊢ φ → Γ ⊢ φ ∨ ψ
45 | -- ∨-intro₂ : ∀ {Γ} {ψ} → (φ : PropFormula) → Γ ⊢ ψ → Γ ⊢ φ ∨ ψ
46 | -- ∨-elim : ∀ {Γ} {φ ψ χ} → Γ , φ ⊢ χ → Γ , ψ ⊢ χ → Γ , φ ∨ ψ ⊢ χ
47 | -- ⊃-intro : ∀ {Γ} {φ ψ} → Γ , φ ⊢ ψ → Γ ⊢ φ ⊃ ψ
48 | -- ⊃-elim : ∀ {Γ} {φ ψ} → Γ ⊢ φ ⊃ ψ → Γ ⊢ φ → Γ ⊢ ψ
49 | -- ⇔-intro : ∀ {Γ} {φ ψ} → Γ , φ ⊢ ψ → Γ , ψ ⊢ φ → Γ ⊢ φ ⇔ ψ
50 | -- ⇔-elim₁ : ∀ {Γ} {φ ψ} → Γ ⊢ φ → Γ ⊢ φ ⇔ ψ → Γ ⊢ ψ
51 | -- ⇔-elim₂ : ∀ {Γ} {φ ψ} → Γ ⊢ ψ → Γ ⊢ φ ⇔ ψ → Γ ⊢ φ
52 |
53 |
--------------------------------------------------------------------------------
/cubicaltt/src/manifold.ctt:
--------------------------------------------------------------------------------
1 | module manifold where
2 | import etale
3 |
4 | HomogeneousStructure (V: U): U = undefined
5 | et (A B: U): EtaleMap A B -> (A -> B) = undefined
6 | isSurjective (A B: U) (f: A -> B): U = undefined
7 |
8 | manifold (V': U) (V: HomogeneousStructure V'): U
9 | = (M: U)
10 | * (W: U)
11 | * (w: EtaleMap W M)
12 | * (covers: isSurjective W M (et W M w))
13 | * ( EtaleMap W V')
14 |
15 |
--------------------------------------------------------------------------------
/cubicaltt/src/maybe.ctt:
--------------------------------------------------------------------------------
1 | {- Run-time Maybe Type:
2 | Copyright (c) Groupoid Infinity, 2014-2018. -}
3 |
4 | module maybe where
5 | import proto
6 | import path
7 |
8 | data maybe (A: U) = nothing | just (a: A)
9 |
10 | fromMaybe (A: U) (n: A): maybe A->A = split { nothing -> n; just a -> a}
11 | maybeMap (A B: U) (f: A->B): maybe A->maybe B = split { nothing -> nothing; just x -> just (f x) }
12 | maybeRec (A P: U) (n: P) (j: A->P): maybe A->P = split { nothing -> n; just a -> j a}
13 | maybeInd (A: U) (P: maybe A -> U) (n: P nothing) (j: (a: A) -> P (just a)):
14 | (a: maybe A) -> P a = split { nothing -> n ; just x -> j x }
15 |
16 | maybeId (A: U): maybe A->maybe A = maybeMap A A (idfun A)
17 | maybeRefl (A: U) (a: maybe A): Path (maybe A) a a = refl (maybe A) a
18 | maybeIsElim (A: U): (a: maybe A) -> Path (maybe A) a (maybeRec A (maybe A) nothing (\(a:A) -> just a) a)
19 | = split { nothing -> maybeRefl A nothing ; just x -> maybeRefl A (just x) }
20 | -- usage
21 | -- maybeElim nat nat zero (\ (x: nat) -> x) (just zero)
22 | -- law of maybeElim
23 | -- maybe_ nothing just a == a
24 |
--------------------------------------------------------------------------------
/cubicaltt/src/maybe_nat.ctt:
--------------------------------------------------------------------------------
1 | module maybe_nat where
2 | -- by @esmolanka
3 | -- here is simple one tweet equality sample with transport
4 |
5 | -- Nat ~ Fix Maybe
6 | -- Z ~ Nothing
7 | -- S ~ Fix . Just
8 |
9 | import nat
10 | import maybe
11 | import control
12 | import recursion
13 | import proto
14 | import path
15 | import set
16 | import iso
17 |
18 | three: fix maybe = Fix (just (Fix (just (Fix (just (Fix nothing))))))
19 |
20 | natToMaybe: nat -> fix maybe = split
21 | zero -> Fix nothing
22 | succ n -> Fix (just (natToMaybe n))
23 |
24 | maybeToNat: fix maybe -> nat = split
25 | Fix m -> go m where go: maybe (fix maybe) -> nat = split
26 | nothing -> zero
27 | just f -> succ (maybeToNat f)
28 |
29 | natMaybeIso: (a: nat) -> Path nat (maybeToNat (natToMaybe a)) a = split
30 | zero -> zero
31 | succ n -> succ (natMaybeIso n @ i)
32 |
33 | maybeNatIso : (a : fix maybe) -> Path (fix maybe) (natToMaybe (maybeToNat a)) a = split
34 | Fix m -> go m where go: (a: maybe (fix maybe)) -> Path (fix maybe) (natToMaybe (maybeToNat (Fix a))) (Fix a) = split
35 | nothing -> Fix nothing
36 | just f -> Fix (just (maybeNatIso f @ i))
37 |
38 | maybenat: Path U (fix maybe) nat = isoPath (fix maybe) nat maybeToNat natToMaybe natMaybeIso maybeNatIso
39 |
40 | HeteroEqu (A B:U)(a:A)(b:B)(P:Path U A B):U = PathP P a b
41 |
42 | -- > HeteroEqu (fix maybe) nat (Fix nothing) zero maybenat
43 |
44 | -- > transNeg (fix maybe) (nat) maybenat (succ (succ zero))
45 | -- EVAL: Fix (just (Fix (just (Fix nothing))))
46 | -- > trans (fix maybe) (nat) maybenat (Fix nothing)
47 | -- EVAL: zero
48 |
49 | -- import univalence
50 |
51 | -- natEquiv : isEquiv nat (fix maybe) natToMaybe =
52 | -- isoToEquiv
53 | -- nat (fix maybe)
54 | -- natToMaybe maybeToNat
55 | -- maybeNatIso natMaybeIso
56 |
57 | -- natEq : Path U nat (fix maybe) =
58 | -- ua nat (fix maybe) (natToMaybe, natEquiv)
59 |
60 | -- > transport natEq (succ (succ zero))
61 | -- EVAL: Fix (just (Fix (just (Fix nothing))))
62 | -- > transport ( natEq @ -i) (Fix (just (Fix (just (Fix (just (Fix nothing)))))))
63 | -- EVAL: succ (succ (succ zero))
64 |
--------------------------------------------------------------------------------
/cubicaltt/src/maybe_theory.ctt:
--------------------------------------------------------------------------------
1 | module maybe_theory where
2 |
3 | import functor
4 | import maybe
5 |
6 | -- maybeMap idfun a == a
7 | functorMaybeId (A: U): (a: maybe A) -> Path (maybe A) (maybeId A a) a
8 | = split { nothing -> maybeRefl A nothing ; just x -> maybeRefl A (just x) }
9 |
10 | -- maybeMap id == id
11 | functorMaybeIdFunExt (A: U): Path (maybe A -> maybe A) (maybeId A) (idfun (maybe A))
12 | = funext (maybe A) (maybe A) (maybeId A) (idfun (maybe A)) (functorMaybeId A)
13 |
14 | -- an alternative proof of functorMaybeId using maybeDElim
15 | functorMaybeId2 (A: U): (a: maybe A) -> Path (maybe A) (maybeId A a) a
16 | = maybeInd A P (maybeRefl A nothing) (\(c:A) -> maybeRefl A (just c)) where
17 | P (x: maybe A): U = Path (maybe A) (maybeId A x) x
18 |
19 | functorMaybeComp (A B C: U) (f: B -> C) (g: A -> B):
20 | (x: maybe A) -> Path (maybe C) (maybeMap A C (o A B C f g) x)
21 | ((o (maybe A) (maybe B) (maybe C) (maybeMap B C f) (maybeMap A B g)) x)
22 | = split { nothing -> maybeRefl C ((maybeMap A C (o A B C f g)) nothing) ;
23 | just x -> maybeRefl C ((maybeMap A C (o A B C f g)) (just x)) }
24 |
25 | functor_maybe: FUNCTOR = ((maybe,maybeMap),(functorMaybeId,functorMaybeComp,tt))
26 |
27 |
--------------------------------------------------------------------------------
/cubicaltt/src/mltt.ctt:
--------------------------------------------------------------------------------
1 | {- MLTT Reality Check:
2 | - Empty, Pi, Sigma, Equ, W.
3 | Copyright (c) Groupoid Infinity, 2014-2018. -}
4 |
5 | module mltt where
6 |
7 |
8 | -- Pi built-in type (axioms)
9 | Pi (A: U) (B: A -> U): U = (x: A) -> B x
10 | lambda (A: U) (B: A -> U) (b: Pi A B): Pi A B = \(x: A) -> b x
11 | app (A: U) (B: A -> U) (f: Pi A B) (a: A): B a = f a
12 |
13 | -- Sigma built-in type (optional)
14 | Sigma (A: U) (B: A -> U): U = (x: A) * B x
15 | pair (A: U) (B: A -> U) (a: A) (b: B a): Sigma A B = (a,b)
16 | pr1 (A: U) (B: A -> U) (x: Sigma A B): A = x.1
17 | pr2 (A: U) (B: A -> U) (x: Sigma A B): B (pr1 A B x) = x.2
18 |
19 | -- W-Types (Well Founded Trees)
20 | W (A:U) (B:A->U): U = (x:A) * (B(x) -> W A B)
21 | Wrec (A:U) (B:A->U) (P:U) (alg: (a:A) -> (B(a)->W A B) -> ((b:B(a))->P) -> P)
22 | : (w: W A B) -> P = \(w:W A B) -> alg w.1 w.2 (\(b:B(w.1)) -> Wrec A B P alg (w.2 b))
23 | Wind (A:U) (B:A->U) (P:W A B -> U) (alg: (a:A) (f:B(a)->W A B) -> ((b:B(a))->P (f b)) -> P (a,f))
24 | : (w: W A B) -> P w = \(w:W A B) -> alg w.1 w.2 (\(b:B(w.1)) -> Wind A B P alg (w.2 b))
25 |
26 | -- Heterogeneous built-in type (Path formation axioms)
27 | Path (A: U) (a b: A): U = PathP (A) a b
28 | HeteroEqu (A B: U) (a: A) (b: B) (P: Path U A B) : U = PathP P a b
29 |
30 | -- Equality Type, mostly built-in (trans, subst, refl, cong, contr axioms)
31 | Equ (A: U) (x y: A): U = HeteroEqu A A x y (A)
32 | reflect (A: U) (a: A): Equ A a a = a
33 | D (A: U) : U = (x y: A) -> Equ A x y -> U
34 | singl (A: U) (a: A): U = (x: A) * Equ A a x
35 | ap (A B: U) (f: A->B) (a b: A) (p: Equ A a b): Equ B (f a) (f b) = f (p @ i)
36 | eta (A: U) (a: A): singl A a = (a,reflect A a)
37 | contr (A: U) (a b: A) (p: Equ A a b): Equ (singl A a) (eta A a) (b,p) = (p@i,p@i/\j)
38 | subst (A: U) (P: A->U) (a b: A) (p: Equ A a b) (e: P a): P b = transport (ap A U P a b p) e
39 | trans (A B: U) (p: Path U A B) (a : A): B = comp p a []
40 |
41 | -- Theorems:
42 | -- 1) Diagonal Version of J
43 | J (A: U) (x: A) (C: D A) (d: C x x (reflect A x)) (y: A) (p: Equ A x y) : C x y p
44 | = subst (singl A x) (\(z: singl A x) -> C x (z.1) (z.2)) (eta A x) (y, p) (contr A x y p) d
45 | -- T (z: singl A x): U = C x (z.1) (z.2)
46 |
47 | -- 2) Computational Rules
48 | trans_comp (A:U)(a:A): Path A a (trans A A ( A) a) = fill ( A) a []
49 | subst_comp (A:U)(P:A->U)(a:A)(e:P(a)): Path (P a) e (subst A P a a (reflect A a) e) = trans_comp (P a) e
50 |
51 | comp1 (A:U)(B:A->U)(a:A)(f: Pi A B): Equ (B a) (app A B (lambda A B f) a) (f a) = reflect (B a) (f a) -- beta
52 | comp2 (A:U)(B:A->U)(a:A)(f: Pi A B): Equ (Pi A B) f (\(x:A) -> f x) = reflect (Pi A B) f -- eta
53 | comp3 (A:U)(B:A->U)(a:A)(b: B a): Equ A a (pr1 A B (a,b)) = reflect A a -- 1
54 | comp4 (A:U)(B:A->U)(a:A)(b: B a): Equ (B a) b (pr2 A B (a,b)) = reflect (B a) b -- 2
55 | comp5 (A:U)(B:A->U)(p: Sigma A B): Equ (Sigma A B) p (pr1 A B p,pr2 A B p) = reflect (Sigma A B) p -- 3
56 | comp6 (A:U)(a:A)(C: D A) (d: C a a (reflect A a))
57 | : Path (C a a (reflect A a)) d (J A a C d a (reflect A a))
58 | = subst_comp (singl A a) T (eta A a) d where T (z: singl A a) : U = C a (z.1) (z.2)
59 |
60 | -- 3a) MLTT Model
61 | MLTT (A: U): U
62 | = (Pi_Former: (A -> U) -> U)
63 | * (Pi_Intro: (B: A -> U) -> Pi A B -> Pi A B)
64 | * (Pi_Elim: (B: A -> U) -> Pi A B -> Pi A B)
65 | * (Pi_Comp1: (B: A -> U) (a: A) (f: Pi A B) -> Equ (B a) (Pi_Elim B (Pi_Intro B f) a) (f a))
66 | * (Pi_Comp2: (B: A -> U) (a: A) (f: Pi A B) -> Equ (Pi A B) f (\(x:A) -> f x))
67 | * (Sigma_Former: (A -> U) -> U)
68 | * (Sigma_Intro: (B: A -> U) (a: A) -> (b: B a) -> Sigma A B)
69 | * (Sigma_Elim1: (B: A -> U) (_: Sigma A B) -> A)
70 | * (Sigma_Elim2: (B: A -> U) (x: Sigma A B) -> B (pr1 A B x))
71 | * (Sigma_Comp1: (B: A -> U) (a: A) (b: B a) -> Equ A a (Sigma_Elim1 B (Sigma_Intro B a b)))
72 | * (Sigma_Comp2: (B: A -> U) (a: A) (b: B a) -> Equ (B a) b (Sigma_Elim2 B (a,b)))
73 | * (Sigma_Comp3: (B: A -> U) (p: Sigma A B) -> Equ (Sigma A B) p (pr1 A B p,pr2 A B p))
74 | * (Id_Former: A -> A -> U)
75 | * (Id_Intro: (a: A) -> Equ A a a)
76 | * (Id_Elim: (x: A) (C: D A) (d: C x x (Id_Intro x)) (y: A) (p: Equ A x y) -> C x y p)
77 | * (Id_Comp: (a:A)(C: D A) (d: C a a (Id_Intro a)) ->
78 | Path (C a a (Id_Intro a)) d (Id_Elim a C d a (Id_Intro a))) * U
79 |
80 | -- 3b) MLTT Instantiation
81 | instance (A: U): MLTT A
82 | = (Pi A, lambda A, app A, comp1 A, comp2 A,
83 | Sigma A, pair A, pr1 A, pr2 A, comp3 A, comp4 A, comp5 A,
84 | Equ A, reflect A, J A, comp6 A, A)
85 |
--------------------------------------------------------------------------------
/cubicaltt/src/modality.ctt:
--------------------------------------------------------------------------------
1 | module modality where
2 | import proto
3 | import path
4 |
5 | Modality : U
6 | = (isModal : U -> U)
7 | * (isPropIsModal : (A : U) -> isProp (isModal A))
8 | * (modality: U -> U)
9 | * (modalityIsModal : (A : U) -> isModal (modality A))
10 | * (eta: (A : U) -> A -> modality A)
11 | * (elim: (A : U) (B : modality A -> U)
12 | (BModal : (x : modality A) -> isModal (B x))
13 | (f: (x : A) -> (B (eta A x))) -> ((x : modality A) -> B x))
14 | * (elimBeta : (A : U) (B : modality A -> U)
15 | (BModal : (x : modality A) -> isModal (B x))
16 | (f : (x : A) -> (B (eta A x)))
17 | (a : A) -> Path (B (eta A a)) (elim A B BModal f (eta A a)) (f a))
18 | * (isModal: (A : U) (x y : modality A) -> isModal (Path (modality A) x y))
19 | * unit
20 |
21 | -- MODALITIES IN HOMOTOPY TYPE THEORY
22 | -- Egbert Rijke, Michael Shulman, Bas Spitters
23 | -- https://arxiv.org/pdf/1706.07526v4.pdf
24 |
--------------------------------------------------------------------------------
/cubicaltt/src/model.htt:
--------------------------------------------------------------------------------
1 | {- Homotopical Algebra:
2 | - Model Categories
3 | - Model Structures
4 | Copyright (c) Groupoid Infinity, 2020. -}
5 |
6 | module model where
7 | import category
8 |
9 | -- https://www.matem.unam.mx/~omar/notes/modelcatsets.html
10 | -- https://web.math.rochester.edu/people/faculty/doug/otherpapers/pshmain.pdf
11 | -- https://www.uio.no/studier/emner/matnat/math/MAT9580/v18/documents/modcat.pdf
12 |
13 | -- Definition. (Quillen) model structure.
14 | -- By a model category we mean a category C
15 | -- with three classes of maps:
16 | -- 1) fibrations,
17 | -- 2) cofibrations,
18 | -- 3) weak equivalences.
19 |
20 | modelStructure (C: U): U
21 | = (fibrations: fib C)
22 | * (cofibrations: cofib C)
23 | * (weakEqivalences: weak C)
24 | * unit
25 |
26 | -- 5 out of 9 model structures on category of sets
27 |
28 | set0: modelStructure Set = (any,any,bijections)
29 | set1: modelStructure Set = (bijections,any,any)
30 | set2: modelStructure Set = (any,bijections,any)
31 | set3: modelStructure Set = (surjections,injections,any)
32 | set4: modelStructure Set = (injections,surjections,any)
33 |
34 | -- 2 model structures on category of topological spaces
35 |
36 | quillen67: modelStructure Top = (serreFibrations,retractsCW,weakHomotopyEquivalence)
37 | strom1972: modelStructure Top = (hurewiczFibrations,cofibrations,strongHomotopyEquivalence)
38 |
39 | -- Simplicial model structure
40 |
41 | simplicial: modelStructure sSet = (kanComplexes,monos,simplicialBijections)
42 |
--------------------------------------------------------------------------------
/cubicaltt/src/nat.ctt:
--------------------------------------------------------------------------------
1 | {- Run-Time Nat Type:
2 | - Nat and Fin;
3 | - Polymorphic funtions.
4 | Copyright (c) Groupoid Infinity, 2014-2018.
5 |
6 | HoTT 1.9 The natural numbers
7 | HoTT 2.13 Natural numbers -}
8 |
9 | module nat where
10 |
11 | import maybe
12 | import bool
13 | import proto
14 | import sigma
15 |
16 | data nat -- ℕ
17 | = zero
18 | | succ (n: nat)
19 |
20 | data natinf -- ℕ-∞
21 | = zero
22 | | succ (n: natinf)
23 | | inf
24 | | succ_inf
25 | [ (i=0) -> inf {natinf} @ i ,
26 | (i=1) -> succ {natinf} inf @ i ]
27 |
28 | one : nat = succ zero
29 | two : nat = succ one
30 | three : nat = succ two
31 | four : nat = succ three
32 | five : nat = succ four
33 | six : nat = succ five
34 | seven : nat = succ six
35 |
36 | natCase (C:U) (a b: C): nat -> C
37 | = split { zero -> a ; succ n -> b }
38 |
39 | natRec (C:U) (z: C) (s: nat->C->C): (n:nat) -> C
40 | = split { zero -> z ; succ n -> s n (natRec C z s n) }
41 |
42 | natElim (C:nat->U) (z: C zero) (s: (n:nat)->C(succ n)): (n:nat) -> C(n)
43 | = split { zero -> z ; succ n -> s n }
44 |
45 | natInd (C:nat->U) (z: C zero) (s: (n:nat)->C(n)->C(succ n)): (n:nat) -> C(n)
46 | = split { zero -> z ; succ n -> s n (natInd C z s n) }
47 |
48 | natEq: nat -> nat -> bool = split
49 | zero -> split@(nat -> bool) with { zero -> true; succ n -> false }
50 | succ m -> split@(nat -> bool) with { zero -> false; succ n -> natEq m n }
51 |
52 | pred: nat -> nat = split { zero -> zero ; succ n -> n }
53 | add (m: nat): nat -> nat = split { zero -> m; succ n -> succ (add m n) }
54 |
55 | mult: nat -> nat -> nat
56 | = natRec (nat->nat) (\(_:nat) -> zero)
57 | (\(_:nat) (mult_:nat->nat) (m:nat) -> add m (mult_ m))
58 |
59 | exponent : nat -> nat -> nat =
60 | \(x:nat) (power:nat) ->
61 | (natRec (nat->nat) (\(_:nat) -> one)
62 | (\(_:nat) (exponent_:nat->nat) (m:nat) -> mult m (exponent_ m)))
63 | power x
64 |
65 | succ2 (x : nat) : nat = succ (succ x)
66 | succ3 (x : nat) : nat = succ (succ2 x)
67 | succ4 (x : nat) : nat = succ (succ3 x)
68 | succ5 (x : nat) : nat = succ (succ4 x)
69 |
70 | n0 : nat = zero
71 | n1 : nat = succ n0
72 | n2 : nat = succ n1
73 | n3 : nat = succ n2
74 | n4 : nat = succ n3
75 | n5 : nat = succ n4
76 | n6 : nat = succ n5
77 | n7 : nat = succ n6
78 | n8 : nat = succ n7
79 | n9 : nat = succ n8
80 | n10 : nat = succ n9
81 | n11 : nat = succ n10
82 | n12 : nat = succ n11
83 | n13 : nat = succ n12
84 | n14 : nat = succ n13
85 | n15 : nat = succ n14
86 | n16 : nat = succ n15
87 | n17 : nat = succ n16
88 | n18 : nat = succ n17
89 | n19 : nat = succ n18
90 | n20 : nat = succ n19
91 |
92 | {- Finite Set Datatype -}
93 |
94 | data Fin (n: nat) = fzero | fsucc (_: Fin (pred n))
95 | fz (n: nat): Fin (succ n) = fzero
96 | fs (n: nat): Fin n -> Fin (succ n) = \(x: Fin n) -> fsucc x
97 |
98 | opaque Fin
99 |
100 | fin11: Fin one = fz zero
101 | fin21: Fin two = fz one
102 | fin22: Fin two = fs one fin11
103 | fin31: Fin three = fz two
104 | fin32: Fin three = fs two fin21
105 | fin33: Fin three = fs two fin22
106 |
107 | -- realityCheck : Equ nat (add n4 n5) n0 = refl nat n9
108 |
--------------------------------------------------------------------------------
/cubicaltt/src/nat_theory.ctt:
--------------------------------------------------------------------------------
1 | {- Nat Theory:
2 | Copyright (c) Groupoid Infinity, 2014-2018. -}
3 |
4 | module nat_theory where
5 | import path
6 | import prop
7 | import pi
8 | import iso
9 | import nat
10 | import eq
11 | import hedberg
12 |
13 | add_zero : (n : nat) -> Path nat (add zero n) n = split
14 | zero -> zero
15 | succ n -> succ (add_zero n @ i)
16 |
17 | add_succ (a:nat) : (n : nat) -> Path nat (add (succ a) n) (succ (add a n)) = split
18 | zero -> succ a
19 | succ m -> succ (add_succ a m @ i)
20 |
21 | add_comm (a : nat) : (n : nat) -> Path nat (add a n) (add n a) = split
22 | zero -> add_zero a @ -i
23 | succ m -> comp (<_> nat) (succ (add_comm a m @ i))
24 | [ (i = 0) -> succ (add a m)
25 | , (i = 1) -> add_succ m a @ -j ]
26 |
27 | assocAdd (a b:nat) : (c:nat) -> Path nat (add a (add b c)) (add (add a b) c) = split
28 | zero -> add a b
29 | succ c1 -> succ (assocAdd a b c1@i)
30 |
31 | add' : nat -> nat -> nat = split
32 | zero -> \(x : nat) -> x
33 | succ n -> \(x : nat) -> succ (add' n x)
34 |
35 | sucInj (n m : nat) (p : Path nat (succ n) (succ m)) : Path nat n m =
36 | pred (p @ i)
37 |
38 | addZero : (a : nat) -> Path nat (add zero a) a = split
39 | zero -> zero
40 | succ a' -> succ (addZero a' @ i)
41 |
42 | add_comm3 (a b c : nat) : Path nat (add a (add b c)) (add c (add b a)) =
43 | let rem : Path nat (add a (add b c)) (add a (add c b)) = add a (add_comm b c @ i)
44 | rem1 : Path nat (add a (add c b)) (add (add c b) a) = add_comm a (add c b)
45 | rem2 : Path nat (add (add c b) a) (add c (add b a)) = assocAdd c b a @ -i
46 | in comp (<_> nat) (rem1 @ i) [ (i = 0) -> rem @ -j, (i = 1) -> rem2 ]
47 |
48 | natcancelr (a b : nat) : (x : nat) -> Path nat (add a x) (add b x) -> Path nat a b = split
49 | zero -> \(h : Path nat a b) -> h
50 | succ x' -> \(h : Path nat (succ (add a x')) (succ (add b x'))) ->
51 | natcancelr a b x' (sucInj (add a x') (add b x') h)
52 |
53 | idnat : nat -> nat = split
54 | zero -> zero
55 | succ n -> succ (idnat n)
56 |
57 | test : Path (nat -> nat) idnat (idfun nat) = piext nat (\(_ : nat) -> nat) idnat (idfun nat) rem
58 | where rem : (n : nat) -> Path nat (idnat n) n = split
59 | zero -> refl nat zero
60 | succ n -> mapOnPath nat nat (\(x : nat) -> succ x) (idnat n) n (rem n)
61 |
62 | znots (n : nat) : neg (Path nat zero (succ n)) =
63 | \ (h:Path nat zero (succ n)) -> subst nat (natCase U nat empty) zero (succ n) h zero
64 |
65 | snotz (n : nat) : neg (Path nat (succ n) zero) =
66 | \ (h:Path nat (succ n) zero) -> znots n (inv nat (succ n) zero h)
67 |
68 | natDec : (n m:nat) -> dec (Path nat n m) = split
69 | zero -> natElim (\ (m:nat) -> dec (Path nat zero m)) (inl (refl nat zero)) (\ (m:nat) -> inr (znots m))
70 | succ n -> natElim (\ (m:nat) -> dec (Path nat (succ n) m)) (inr (snotz n))
71 | (\ (m:nat) -> decEqCong (Path nat n m) (Path nat (succ n) (succ m)) (\ (p:Path nat n m) -> succ (p @ i))
72 | (sucInj n m) (natDec n m))
73 |
74 | natSet : isSet nat = hedberg nat natDec
75 |
76 | eq_nat : eq_ = (nat, natEq)
77 | eq_nat_ : eq nat = natEq
78 |
79 | mutual
80 | even : nat -> bool = split
81 | zero -> true
82 | succ n -> odd n
83 |
84 | odd : nat -> bool = split
85 | zero -> false
86 | succ n -> even n
87 |
88 | mutual
89 | evenodd : (n : nat) -> Path bool (even n) (odd (succ n)) = split
90 | zero -> true
91 | succ x -> (oddeven x) @ i
92 | oddeven : (n :nat) -> Path bool (odd n) (even (succ n)) = split
93 | zero -> false
94 | succ x -> (evenodd x) @ i
95 |
96 | -- examples 1.9.1 and 1.9.2
97 | double_via_rec_nat : nat -> nat = natRec nat zero (\(_:nat) (y:nat) -> succ (succ y))
98 | add_via_rec_nat : nat -> nat -> nat = natRec (nat->nat) (\(x:nat)->x) (\(_:nat) (add_:nat->nat) (m:nat) -> succ(add_ m))
99 |
100 | -- exercise 1.9: Define the type family Fin : N → U mentioned at the end of §1.3, and the dependent
101 | -- function fmax : ∏(n:N) Fin(n + 1) mentioned in §1.4.
102 |
103 | fmax: (n:nat) -> Fin (succ n) = split { zero -> fz zero ; succ n -> fs (succ n) (fmax n) }
104 |
105 | -- exercise 1.10: Show that the Ackermann function ack : N → N → N is definable using only rec_nat
106 | -- satisfying the following equations:
107 | -- ack(0, n) ≡ succ(n),
108 | -- ack(succ(m), 0) ≡ ack(m, 1),
109 | -- ack(succ(m),succ(n)) ≡ ack(m, ack(succ(m), n)).
110 |
111 | ack : nat -> nat -> nat =
112 | natRec (nat->nat) (\(n:nat) -> succ n)
113 | (\(m:nat) (_:nat->nat) (n:nat) -> natRec nat (ack m one)
114 | (\(p:nat) (_:nat) -> ack m (ack (succ m) p)) n)
115 |
116 | -- As a lead-in to exercice 1.8, part three (prove that nat is a semi-ring)
117 | -- lets prove that double x = add x x
118 |
119 | double : nat -> nat = split
120 | zero -> zero
121 | succ n -> succ (succ (double n))
122 |
123 | double_n_is_add_n_n : (n:nat) -> Path nat (double n) (add n n) = split
124 | zero -> zero
125 | succ x -> composition nat (succ (succ (double x)))
126 | (succ (succ (add x x)))
127 | (succ (add (succ x) x))
128 | ( (succ (succ (double_n_is_add_n_n x @ j))))
129 | ( succ (add_succ x x @ -k))
130 |
131 | -- Same result, but with cryptic comp application obtained by expanding composition
132 | -- Note the empty third argument to comp
133 | double_n_is_add_n_n_via_cryptic_comp : (n:nat) -> Path nat (double n) (add n n) = split
134 | zero ->