-
Notifications
You must be signed in to change notification settings - Fork 1
/
groupoid.lagda
1529 lines (1307 loc) · 64.5 KB
/
groupoid.lagda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\section{From Sets to Groupoids}
\label{sec:groupoids}
From a denotational perspective, a $\Pi$ type $\tau$ denotes a finite set, a
$\Pi$ 1-combinator denotes a permutation on finite sets, and the 2-combinators
denote coherence conditions on these permutations~\cite{Carette2016}. Formally,
the language $\Pi$ is a \emph{categorification}~\cite{math/9802029} of the
natural numbers as a \emph{symmetric rig groupoid}~\cite{nlabrig}. This
structure is a \emph{symmetric bimonoidal category} or a \emph{commutative rig
category} in which every morphism is invertible. The underlying category
consists of two symmetric monoidal structures~\cite{nla.cat-vn1051288}
separately induced by the properties of addition and multiplication of the
natural numbers. The monoidal structures are then augmented with distributivity
and absorption natural isomorphisms~\cite{laplaza} to model the full commutative
semiring (aka, commutative rig) of the natural numbers. Despite this rich
structure, the individual objects in the category for $\Pi$ are just plain sets
with no interesting structure. In this section we introduce, in the denotation
of $\Pi$, some non-trivial groupoids which we call \emph{iteration groupoids}
and \emph{symmetry groupoids}. Under certain conditions, sums and products of
these groupoids behave as expected which ensures that a sensible compositional
programming language can be designed around them.
% \noindent\jc{I still despise the name ``division groupoid''. After thinking
% about it for a while, I think that ``up to groupoid'' might be better,
% as in ``p up to q''. I would be fine with ``conjugation groupoid'' or even
% ``coset groupoid'' (coset from group theory). I am
% very afraid that ``division groupoid'' will set up all sorts of potentially
% incorrect connotations in the readers' mind, and will lead them astray (and
% thence potentially to reject the paper).}
%%%%%
\subsection{$\Pi$ Types as Sets (Discrete Groupoids)}
Each $\Pi$ type $\tau$ denotes a (structured) finite set $\sem{\tau}$ as follows:
\[\begin{array}{rcl}
\sem{\zt} &=& \bot \\
\sem{\ot} &=& \top \\
\sem{\tau_1 \oplus \tau_2} &=& \sem{\tau_1} \uplus \sem{\tau_2} \\
\sem{\tau_1 \otimes \tau_2} &=& \sem{\tau_1} \times \sem{\tau_2}
\end{array}\]
\noindent where we use $\bot$ to denote the empty set, $\top$ to denote a set
with one element, and $\uplus$ and~$\times$ to denote the disjoint union of sets
and the cartesian product of sets respectively. Each set can be viewed as a
groupoid whose objects are the set elements and with only identity morphisms on
each object. Nevertheless, the denotations of $\ot \oplus (\ot \oplus \ot)$ of
$(\ot \oplus \ot) \oplus \ot$ are not in fact equal, although they are
trivially isomorphic.
By only being able to express types whose denotations are trivial
groupoids, $\Pi$ leaves untapped an enormous amount of combinatorial structure
that is expressible in type theory. We show that with a small but deep technical
insight, it is possible to extend~$\Pi$ with types whose denotations are
not discrete.
%%%%%
\subsection{Groupoids and Groupoid Cardinality}
There are many definitions of groupoids that provide complementary perspectives
and insights. Perhaps the simplest definition to state, and the one which is
most immediately useful for our work, is that a groupoid is a category
in which every morphism has an inverse. Intuitively, such a category consists of
clusters of connected objects where each cluster is equivalent (in the
category-theoretic sense) to a group, viewed as a $1$-object category. Thus an
alternative definition of a groupoid is as a generalization of a group that
allows for individual elements
to have ``internal symmetries''~\cite{groupoidintro}. Baez et
al.~\cite{2009arXiv0908.4305B} associate with each groupoid a cardinality that
counts the elements up to these ``internal symmetries''.
\begin{definition}[Groupoid Cardinality~\cite{2009arXiv0908.4305B}]
The cardinality of a groupoid $G$ is the (positive) real number:
\[
|G| = \sum_{[x]} \frac{1}{|\textsf{Aut}(x)|}
\]
provided the sum converges. The summation is over \emph{isomorphism classes}
$[x]$ of objects $x$ and $|\textsf{Aut}(x)|$ is the number of \emph{distinct}
automorphisms of $x$.
\end{definition}
\begin{figure}[t]
\begin{center}
\begin{tikzpicture}[scale=0.6,every node/.style={scale=0.8}]
\draw[dashed] (0,-0.3) ellipse (1.5cm and 2.1cm);
\node[below] (A) at (-0.5,0) {$a$};
\node[below] (C) at (0.5,0) {$c$};
\path (A) edge [loop below] node[below] {\texttt{id}} (A);
\path (C) edge [loop below] node[below] {\texttt{id}} (C);
\path (C) edge [out=140, in=40, looseness=4] (C);
\end{tikzpicture}
\qquad \qquad \qquad
\begin{tikzpicture}[scale=0.6,every node/.style={scale=0.8}]
\draw[dashed] (0,-0.3) ellipse (3cm and 2.5cm);
\node[below] (A) at (-2,0) {$a$};
\node[below] (B) at (0,0) {$b$};
\node[below] (C) at (1.5,0) {$c$};
\path (A) edge [bend left=50] (B);
\path (C) edge [out=140, in=40, looseness=4] (C);
\path (A) edge [loop below] node[below] {\texttt{id}} (A);
\path (B) edge [loop below] node[below] {\texttt{id}} (B);
\path (C) edge [loop below] node[below] {\texttt{id}} (C);
\end{tikzpicture}
\qquad \qquad \qquad
\begin{tikzpicture}[scale=0.6,every node/.style={scale=0.8}]
\draw[dashed] (0,-0.3) ellipse (2.8cm and 2.5cm);
\node[below] (A) at (-1.6,0) {$a$};
\node[below] (B) at (0,0) {$b$};
\node[below] (C) at (1.6,0) {$c$};
\path (A) edge [loop below] node[below] {\texttt{id}} (A);
\path (B) edge [loop below] node[below] {\texttt{id}} (B);
\path (C) edge [loop below] node[below] {\texttt{id}} (C);
\path (A) edge [loop above, looseness=3, in=48, out=132] (A);
\path (B) edge [loop above, looseness=3, in=48, out=132] (B);
\path (C) edge [loop above, looseness=3, in=48, out=132] (C);
\end{tikzpicture}
\end{center}
\caption{\label{fig:groupoids2}Example groupoids $G_1$, $G_2$, and $G_3$.}
\end{figure}
For plain sets, the definition just counts the elements as each element is its
own equivalence class and has exactly one automorphism (the identity). Without
quite formalizing them and relying on the informal diagrams until the next
section, we argue that each of the groupoids $G_1$, $G_2$, and $G_3$ in
Fig.~\ref{fig:groupoids2} has cardinality $\frac{3}{2}$. Groupoid~$G_1$ consists
of two isomorphism classes: class~$a$ has one object with one automorphism (the
identity) and class~$c$ has one object with two distinct automorphisms; the
cardinality is $\frac{1}{1} + \frac{1}{2} = \frac{3}{2}$. For groupoid~$G_2$, we
also have two isomorphism classes with representatives $a$ and $c$; the class
containing $a$ has two automorphisms starting from $a$: the identity and the
loop going from $a$ to~$b$ and back. By the groupoid axioms, this loop is
equivalent to the identity which means that the class containing $a$ has just
one automorphism. The isomorphism class of $c$ has two non-equivalent
automorphisms on it and hence the cardinality of $G_2$ is also
$\frac{1}{1} + \frac{1}{2} = \frac{3}{2}$. For~$G_3$, we have three isomorphism
classes, each with two non-equivalent automorphisms, and hence the cardinality
of $G_3$ is $\frac{1}{2} + \frac{1}{2} + \frac{1}{2} = \frac{3}{2}$.
It is important to note that $G_1$ and $G_2$ are (categorically) equivalent
groupoids, but that $G_3$ is not equivalent to either $G_1$ or $G_2$.
Roughly speaking this is because the number of connected components is also
an invariant of a groupoid, and here $G_1$ and $G_2$ have $2$ whilst $G_3$ has
$3$.
%%%%%%%%%%%%%%%%%%%%%%%
\subsection{$\Pi$-Combinators as Automorphism Classes}
To formalize the counting above, we need, in the context of $\Pi$, a precise
definition of what it means for automorphisms to be ``distinct''. We start with
an example. Recall the type $\mathbb{3}$ with its three elements
$ll=\inl{\inl{\unitv}}$, $lr=\inl{\inr{\unitv}}$, and $r=\inr{\unitv}$. One of
the combinators of type $\mathbb{3} \iso \mathbb{3}$ is $\permtwo$. Observing
the results of applying the iterates $(\permtwo)^k$ for $k \in \Z$ on the three
elements we find:
\[\begin{array}{c@{\qquad\qquad}c}
\begin{array}{rcl}
\evalone{(\permtwo)^{2k}}{ll} &=& ll \\
\evalone{(\permtwo)^{2k}}{lr} &=& lr \\
\evalone{(\permtwo)^{2k}}{r} &=& r
\end{array} &
\begin{array}{rcl}
\evalone{(\permtwo)^{2k+1}}{ll} &=& lr \\
\evalone{(\permtwo)^{2k+1}}{lr} &=& ll \\
\evalone{(\permtwo)^{2k+1}}{r} &=& r
\end{array}
\end{array}\]
Furthermore, Lem.~\ref{lem:ordercancel} gives us the following families of
2-combinators $\alpha_{2k} : \idiso \isotwo (\permtwo)^{2k}$ and
$\alpha_{2k+1} : \permtwo \isotwo (\permtwo)^{2k+1}$. We can put these facts together to
construct a groupoid whose objects are the elements of $\mathbb{3}$, whose
1-morphisms relate $v_i$ and~$v_j$ if $\evalone{(\permtwo)^k}{v_i} = v_j$ for some
$k \in \Z$, and whose 2-morphisms are the families $\alpha_{2k}$ and
$\alpha_{2k+1}$ above. Such a construction produces the following groupoid where
each family of 1-morphisms that are identified by a family of 2-morphisms is
drawn using a thick line:
\begin{center}
\begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
\draw[dashed] (0,-0.3) ellipse (3cm and 2.5cm);
\node[below] (A) at (-2,0) {$ll$};
\node[below] (B) at (0,0) {$lr$};
\node[below] (C) at (1.5,0) {$r$};
\path[ultra thick] (A) edge [bend left=50] node[above] {$\permtwo$} (B);
\path[ultra thick] (C) edge [out=140, in=40, looseness=4] node[above] {$\permtwo$} (C);
\path[ultra thick] (A) edge [my loop] node[below] {\texttt{id}} (A);
\path[ultra thick] (B) edge [my loop] node[below] {\texttt{id}} (B);
\path[ultra thick] (C) edge [my loop] node[below] {\texttt{id}} (C);
\end{tikzpicture}
\end{center}
Clearly, the resulting groupoid is a reconstruction of $G_2$ in
Fig.~\ref{fig:groupoids2} using $\Pi$ types and combinators. As analyzed
earlier, this groupoid has cardinality $\frac{3}{2}$. From the perspective
of~$\Pi$, this cardinality corresponds to the number of elements in the
underlying set which is $3$ divided by the order of the combinator $\permtwo$
which is 2. It is important to note that, as Def.~\ref{def:order} states, the
calculation of the order of a 1-combinator is defined up to the equivalence
induced by 2-combinators.
%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Iteration Groupoids $\order{p}$}
The previous construction is quite useful: it allows us to take a set of
cardinality $N$ and a permutation on that set of order $P$ to construct a
groupoid of cardinality $\frac{N}{P}$. Although this idea allows us to construct
a groupoid of cardinality $\frac{3}{2}$ as shown above, it is not expressive
enough to construct a groupoid of cardinality $\frac{1}{3}$. Indeed if the
underlying set has only one element, the only permutation is the identity and
$P$ must be 1. The construction, however, already contains the main ingredient
needed for the construction of more general groupoids with fractional
cardinality. This key piece is the set of iterates of a combinator which we will
use in two different ways: (i) a perspective of combinators-as-data in which the
iterates of a combinator $p$ become the objects of groupoid $\order{p}$ of
cardinality $\ord{p}$, and (ii) a perspective of combinators-as-symmetries in
which the iterates of a combinator $p$ become the internal symmetries of a
one-element groupoid $\iorder{p}$ of cardinality $\frac{1}{\ord{p}}$. We explain
these two perspectives in this section and the next.
We define the $k^{\text{th}}$ iterate of $p$ as:
\AgdaHide{
\begin{code}
open import Data.Nat using (ℕ; suc)
open import Data.Integer as ℤ
open import Data.Unit
open import Data.Product hiding (<_,_>;,_)
open import Function
open import Categories.Category
open import Categories.Groupoid
data U : Set where
𝟘 : U
𝟙 : U
_⊕_ : U → U → U
_⊗_ : U → U → U
data Prim⟷ : U → U → Set where
id⟷ : {t : U} → Prim⟷ t t
-- rest elided
data _⟷_ : U → U → Set where
Prim : {t₁ t₂ : U} → (Prim⟷ t₁ t₂) → (t₁ ⟷ t₂)
_◎_ : {t₁ t₂ t₃ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₃) → (t₁ ⟷ t₃)
-- rest elided
! : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₂ ⟷ t₁)
! = {!!} -- definition elided
data _⇔_ : {t₁ t₂ : U} → (t₁ ⟷ t₂) → (t₁ ⟷ t₂) → Set where
id⇔ : ∀ {t₁ t₂} {c : t₁ ⟷ t₂} → c ⇔ c
_●_ : ∀ {t₁ t₂} {c₁ c₂ c₃ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₃) → (c₁ ⇔ c₃)
idl◎r : ∀ {t₁ t₂} {c : t₁ ⟷ t₂} → c ⇔ (Prim id⟷ ◎ c)
idr◎l : ∀ {t₁ t₂} {c : t₁ ⟷ t₂} → (c ◎ Prim id⟷) ⇔ c
idr◎r : ∀ {t₁ t₂} {c : t₁ ⟷ t₂} → c ⇔ (c ◎ Prim id⟷)
-- rest elided
2! : {t₁ t₂ : U} {c₁ c₂ : t₁ ⟷ t₂} → (c₁ ⇔ c₂) → (c₂ ⇔ c₁)
2! = {!!} -- definition elided
infix 40 _^_
infixr 60 _●_
\end{code}}
\begin{code}
_^_ : {τ : U} → (p : τ ⟷ τ) → (k : ℤ) → (τ ⟷ τ)
p ^ (+ 0) = Prim id⟷
p ^ (+ (suc k)) = p ◎ (p ^ (+ k))
p ^ -[1+ 0 ] = ! p
p ^ (-[1+ (suc k) ]) = (! p) ◎ (p ^ -[1+ k ])
\end{code}
\noindent and then collect all such iterates into a type
\begin{code}
record Iter {τ : U} (p : τ ⟷ τ) : Set where
constructor <_,_,_>
field
k : ℤ
q : τ ⟷ τ
α : q ⇔ p ^ k
\end{code}
\noindent For example, the zeroth and first iterate of a combinator are represented as
\begin{code}
zeroth iter : {τ : U} → (p : τ ⟷ τ) → Iter p
zeroth p = < + 0 , Prim id⟷ , id⇔ >
iter p = < + 1 , p , idr◎r >
\end{code}
These ingredients are sufficient to construct a groupoid $\order{p}$ from the
iterates of a 1-combinator $p : \tau\iso\tau$. The objects will be
the triples $\triple{k}{q}{\alpha}$ indexed by integers $k$, 1-combinators $q :
\tau\iso\tau$, and 2-combinators $\alpha : q \isotwo p^k$. This triple encodes
our knowledge that we have some (arbitrary) iterate $q$ of $p$; we do not have
any a priori knowledge of the actual syntactic structure of $q$, but we do
know that it is equivalent to $p ^ k$.
We then add (reversible!) morphisms between any iterates related by
2-combinators; categorically, this will make any such objects equivalent.
If $p$ has order $o$, Lem.~\ref{lem:ordercancel} gives us a
2-combinator $\alpha$ which witnesses that $p^i \isotwo p^{i+o}$.
Thus given two iterates $\triple{i}{q_i}{\alpha_i}$ and
$\triple{i+o}{q_j}{\alpha_j}$, they must be equivalent since
$\alpha_i~\bullet~\alpha~\bullet~!\,\alpha_j$ shows that $q_i \isotwo q_j$.
In other words $p^j$ will be equivalent to $p^k$ exactly when $j$ and $k$
differ by $o$. This informal description formalizes straightforwardly:
\begin{code}
iterationC : {τ : U} → (p : τ ⟷ τ) → Category _ _ _
iterationC {τ} p = record {
Obj = Iter p
; _⇒_ = λ p^i p^j → Iter.q p^i ⇔ Iter.q p^j
; _≡_ = λ _ _ → ⊤
; id = id⇔
; _∘_ = flip _●_
-- rest elided
}
\end{code}
Despite its involved internal structure, the groupoid $\order{p}$ is essentially
a set of cardinality $\ord{p}$.
% This lemma is, as far as I can tell, not provable in Agda.
\begin{lemma}
$|\order{p}| = \ord{p}$
\end{lemma}
\begin{proof}
Let $o = \ord{p}$. There are $o$ isomorphism classes of
objects. Consider an object $x = \triple{k}{q}{\alpha}$, its
isomorphism class $[x] = \triple{k+io}{q_i}{\alpha_i}$ where
$i \in \Z$. The group $\textsf{Aut}(x)$ is the group generated by
$\idisotwo$ and has order 1. Hence
$|\order{p}| = \sum\limits_{1}^{o}\frac{1}{1} = o$.
\end{proof}
As an example, the groupoid $\order{(\permtwo)}$ can be represented as follows. Up to equivalence, this groupoid is indeed equivalent to a set with two elements $\idiso$ and $\permtwo$.
\begin{center}
\begin{tikzpicture}[scale=0.6,every node/.style={scale=0.6}]
\draw[dashed] (0,-0.3) ellipse (9cm and 2.5cm);
\node[below] at (-8,0) {$\ldots$};
\node[below] (A) at (-6,0) {$< -2 , \idiso , \ldots >$};
\node[below] (B) at (-3,0) {$< -1 , \permtwo , \ldots >$};
\node[below] (C) at (0,0) {$< 0, \idiso, \idisotwo >$};
\node[below] (D) at (3,0) {$< 1 , \permtwo , \ldots >$};
\node[below] (E) at (6,0) {$< 2 , \idiso , \ldots >$};
\node[below] at (8,0) {$\ldots$};
\path[ultra thick] (A) edge [my loop] node[below] {\texttt{id}} (A);
\path[ultra thick] (B) edge [my loop] node[above] {\texttt{id}} (B);
\path[ultra thick] (C) edge [my loop] node[below] {\texttt{id}} (C);
\path[ultra thick] (D) edge [my loop] node[above] {\texttt{id}} (D);
\path[ultra thick] (E) edge [my loop] node[below] {\texttt{id}} (E);
\path[ultra thick] (A) edge [bend left=50] node[above] {$\alpha_{-2,0}$} (C);
\path[ultra thick] (C) edge [bend left=50] node[above] {$\alpha_{0,2}$} (E);
\path[ultra thick] (B) edge [bend left=-50] node[below] {$\alpha_{-1,1}$} (D);
\end{tikzpicture}
\end{center}
%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Symmetry Groupoids $\iorder{p}$}
The elements of $\iter{p}$ form a group under the following operation:
\[
\triple{k_1}{p_1}{\alpha_1} ~\circ~ \triple{k_2}{p_2}{\alpha_2} =
\triple{k_1+k_2}{p_1 \odot p_2}{(\alpha_1 ~\respstwo~
\alpha_2)~\transtwo~(\distiterplus{p}{k_1}{k_2})}
\]
where $\distiterplus{p}{k_1}{k_2}$ is defined in
Lem.~\ref{lem:distiterplus}. The common categorical representation of
a group is a category with one trivial object and the group elements
as morphisms on that trivial object. Our construction is essentially
the same except that the trivial object is represented as the iterates
of the identity over a singleton type.
Formally, given a 1-combinator $p : \tau\iso\tau$, the groupoid
$\iorder{p}$ is the groupoid (2-groupoid technically) whose objects
are the iterates in $\iter{\idiso_{\top}}$. Every pair of objects is
connected by the morphisms in $\iter{p}$. To capture the relationship
between these morphisms, we also have 2-morphisms relating the
distinct iterates as in the previous section.
\begin{code}
symC : (τ : U) → (τ ⟷ τ) → Category _ _ _
symC τ pp = record {
Obj = Iter {τ} (Prim id⟷)
; _⇒_ = λ _ _ → Iter pp
; _≡_ = λ p q → Iter.q p ⇔ Iter.q q
; id = zeroth pp
; _∘_ = {!!}; assoc = {!!}; identityˡ = {!!}; identityʳ = {!!}
; equiv = record { refl = id⇔ ; sym = 2! ; trans = _●_ }
; ∘-resp-≡ = {!!}
}
\end{code}
\begin{lemma}
$|\iorder{p}| = \frac{1}{\ord{p}}$
\end{lemma}
\begin{proof}
Let $o = \ord{p}$. The objects form one isomorphism class
$[p]$. There are, up to equivalence, exactly $\ord{p}$ distinct
morphisms on this equivalence class. Hence, the group
$\textsf{Aut}([p])$ is the group generated by
$p^0, p^1 \dots p^{o-1}$, and the cardinality $|\iorder{p}|$ is
$\frac{1}{o}$.
\end{proof}
Note that for each power $p ^ i$ of $p$, there is a morphism
$\triple{k}{q}{\alpha}$ in $\iter{p}$ such that $q$ annihilates $p^i$
to the identity. Note also that everything is well-defined even if we
choose $p : \zt\iso\zt$. In that case, the cardinality is 1.
\begin{center}
\begin{tikzpicture}[scale=0.6,every node/.style={scale=0.6}]
\draw[dashed] (0,-0.3) ellipse (9cm and 2.5cm);
\node[below] at (-8,0) {$\ldots$};
\node[below] (A) at (-6,0) {$< -2 , \idiso , \ldots >$};
\node[below] (B) at (-3,0) {$< -1 , \idiso , \ldots >$};
\node[below] (C) at (0,0) {$< 0, \idiso, \idisotwo >$};
\node[below] (D) at (3,0) {$< 1 , \idiso , \ldots >$};
\node[below] (E) at (6,0) {$< 2 , \idiso , \ldots >$};
\node[below] at (8,0) {$\ldots$};
\path[ultra thick] (A) edge [my loop] node[below] {$\idiso$} (A);
\path[ultra thick] (A) edge [out=-140, in=-40, looseness=20] node[below] {$\permtwo$} (A);
\path[ultra thick] (A) edge [bend left=50] node[above] {$\alpha_{-2,0}$} (B);
\path[ultra thick] (B) edge [bend left=50] node[above] {$\alpha_{0,2}$} (C);
\path[ultra thick] (C) edge [bend left=50] node[above] {$\alpha_{0,2}$} (D);
\path[ultra thick] (D) edge [bend left=50] node[above] {$\alpha_{0,2}$} (E);
\end{tikzpicture}
\end{center}
% %%%%%%%%%%%%%%%%%%%%%%%
% \subsection{\DG{s} $\divgl{p}{q}$ and $\divgr{p}{q}$}
% By considering \emph{two} combinators $p$ and $q$ of the same type, we can
% modify the above construction to construct a groupoid whose
% cardinality will be $\frac{\ord{p}}{\ord{q}}$. The basic idea is to consider
% the iterates of $p$ \emph{modulo} those of $q$. Above, we considered
% $p^i$ and $p^j$ equivalent exactly when $p^i \Leftrightarrow p^j$.
% Now we consider $p^i$ equivalent to $p^j$ whenever there exists a $k$
% such that $p^i$ is equivalent to $p^j$ up to an iterate of $q$. This
% concept naturally comes in two versions, a left-handed conjugate,
% $\divgl{p}{q}$ where $p^i \Leftrightarrow q^k \circledcirc p^j$; and
% a right-handed conjugate,
% $\divgr{p}{q}$ where $p^i \Leftrightarrow p^j \circledcirc q^k$.
% In other words, we can use some iterate of $q$ to ``mediate'' the equivalence.
% Of course, if we pick $q$ to be the identity, this reduces to the previous
% definition.
% A bit more formally, the objects of this groupoid will be the same as
% the objects of~$\order{p}$. Then two such arbitrary objects
% $\triple{k_1}{r_1}{\alpha_1}$ and $\triple{k_2}{r_2}{\alpha_2}$ will
% be (left) related if there exists an iterate $\triple{k}{r_k}{\alpha}$ in
% $\iter{q}$, such that $r_1 \isotwo (r_k \odot r_2)$, and right related
% if $r_1 \isotwo (r_2 \odot r_k)$. This
% is the first groupoid we define which has a non-trivial identification
% of morphisms, and thus is a \emph{weak} groupoid. The important parts
% of this can be rendered in Agda as follows.
% \begin{code}
% conjlC : {τ : U} → (p q : τ ⟷ τ) → Category _ _ _
% conjlC {τ} p q = record {
% Obj = Iter p
% ; _⇒_ = λ s t → Σ[ iq ∈ Iter q ]
% (Iter.q s ⇔ (Iter.q iq ◎ Iter.q t))
% ; _≡_ = λ { (iter₁ , _) (iter₂ , _) → Iter.q iter₁ ⇔ Iter.q iter₂ }
% ; id = λ {A} → zeroth q , idl◎r
% ; _∘_ = {!!}; assoc = {!!}; identityˡ = {!!}; identityʳ = {!!} -- elided
% ; equiv = record { refl = id⇔ ; sym = 2! ; trans = _●_ }
% ; ∘-resp-≡ = {!!} -- elided
% }
% \end{code}
% \noindent and right conjugacy is similar.
% \begin{lemma}
% $|\divgl{p}{q}∣ = \frac{\ord{p}}{\ord{q}}$
% \end{lemma}
% \begin{proof}
% Let $m = \ord{p}$ and $n = \ord{q}$. \amr{sketch proof}
% \end{proof}
% As an example, the groupoid $\divgl{\permtwo}{\permfive}$ can be represented as follows:
% \begin{center}
% \begin{tikzpicture}[scale=0.8,every node/.style={scale=0.8}]
% \draw[dashed] (0,-0.3) ellipse (9cm and 2.5cm);
% \node[below] at (-8,0) {$\ldots$};
% \node[below] (A) at (-6,0) {$< -2 , \idiso , \ldots >$};
% \node[below] (B) at (-3,0) {$< -1 , \permtwo , \ldots >$};
% \node[below] (C) at (0,0) {$< 0, \idiso, \idisotwo >$};
% \node[below] (D) at (3,0) {$< 1 , \permtwo , \ldots >$};
% \node[below] (E) at (6,0) {$< 2 , \idiso , \ldots >$};
% \node[below] at (8,0) {$\ldots$};
% \path[ultra thick] (A) edge [bend left=50] node[above] {$\alpha_{-2,0}$} (C);
% \path[ultra thick] (C) edge [bend left=50] node[above] {$\alpha_{0,2}$} (E);
% \path[ultra thick] (B) edge [bend left=-50] node[below] {$\alpha_{-1,1}$} (D);
% \end{tikzpicture}
% \end{center}
% % The groupoid $\order{p}$ can be thought of as
% % $\divg{p}{\idiso}$. Similarly the groupoid $\iorder{p}$ can be thought
% % of as $\divg{\idiso}{p}$. The two previous constructions can therefore
% % be generalized to allow arbitrary combinators in both the numerator
% % and denominator.
% % Formally, given two 1-combinators $p, r : \tau\iso\tau$, the objects
% % of $\divg{p}{r}$ are all the iterates $\iter{p}$, the numerator. There
% % is a morphism between $\triple{k_1}{q_1}{\alpha_1}$ and
% % $\triple{k_2}{q_2}{\alpha_2}$ if there exists an iterate
% % $\triple{k}{q}{\alpha}$ in $\iter{r}$, the denominator, such that
% % $(q_1 \odot q) \isotwo (q \odot q_2)$. As before, the morphisms are
% % not all independent: two morphisms are identified if their $q$
% % components are related by $\isotwo$.
% % When $r$ is $\idiso$, this construction reduces to $\order{p}$. When $p$
% % is $\idiso$, this construction reduces to $\iorder{r}$. Generally, the
% % cardinality of $\divg{p}{r}$ is $\frac{\ord{p}}{\ord{r}}$. (See Appendix
% % for the Agda construction.)
%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Sums and Products of Iteration and Symmetry Groupoids}
If we are to build a compositional programming language around iteration and
symmetry groupoids, we need to ensure that they compose sensibly with the
existing type formers. Groupoids, viewed as categories, come associated with
natural notions of sums and products, and one might expect or hope that
identities which hold for rational numbers lift to identities in our
situation. The most prominent and important identity we seek is:
such as:
\[
\order{p} \otimes \iorder{p} \simeq \mathbb{1}
\]
The groupoids on either side are not categorically equivalent but they
do have the same cardinality. Thus if we focus on
cardinality-preserving morphisms, it is sensible to consider them
equivalent. The situation is subtle, however, and studied in detail in
the next section.
% %%%%%%%%%%%%%%%%%%%%%%%
% \subsection{Expanded Unit Groupoids $\oneg{p}$}
% For each combinator $p : \tau\iso\tau$, we also construct a groupoid
% $\oneg{p}$ of cardinality $\frac{\ord{p}}{\ord{p}} = 1$. (Recall that
% the order of a combinator can never be 0.) The objects of this
% groupoid as the iterates in $\iter{p}$. There is morphism between
% $\triple{k_1}{q_1}{\alpha_1}$ and $\triple{k_2}{q_2}{\alpha_2}$ if
% there exists a $\triple{k}{q}{\alpha}$ such that $q_1 ~\odot~ !q_2
% \isotwo q$.
%% Talk about monad/comonad ????
% %%%%%
% \subsection{Old stuff to clean up or throw away}
% \amr{from popl 12 paper: adapt}
% We want our computations to be information-preserving. Since the
% amount of information in each state is just the log of the cardinality
% of the space, computation just needs to be between spaces of the same
% cardinality.
% Now consider the \ensuremath{\mathit{bool} \rightarrow \mathit{bool}}
% function \ensuremath{\mathit{not}}. Let $p_F$ and $p_T$ be the
% probabilities that the input is \ensuremath{\mathit{false}} or
% \ensuremath{\mathit{true}} respectively. The outputs occur with the
% reverse probabilities, i.e., $p_T$ is the probability that the output
% is \ensuremath{\mathit{false}} and $p_F$ is the probability that t he
% output is \ensuremath{\mathit{true}}. Hence the output entropy of the
% function is $- p_F \log{p_F} - p_T \log{p_T}$ which is the same as the
% input entropy and the function is information-preserving. As another
% example, consider the \ensuremath{\mathit{bool} \rightarrow
% \mathit{bool}} function \ensuremath{\mathit{constT}(x) =
% \mathit{true}} which discards its input. The output of the function
% is always \ensuremath{\mathit{true}} with no uncertainty, which means
% tha t the output entropy is 0, and that the function is not
% information-preserving. As a third example, consider the
% function~\ensuremath{\mathit{and}} and let the inputs occur with equal
% probabilities, i.e., let the entropy of the input be 2. The output is
% \ensuremath{\mathit{false}} with probability $3/4$ and
% \ensuremath{\mathit{true}} with probability $1/4$, which means that
% the output entropy is about 0.8 and the function is not
% information-preserving. As a final example, consider the
% \ensuremath{\mathit{bool} \rightarrow \mathit{bool}\times
% \mathit{bool}} function \ensuremath{\mathit{fanout} ~(x) = (x,x)}
% which duplicates its input. Let the input be
% \ensuremath{\mathit{false}} with probability $p_F$ and
% \ensuremath{\mathit{true}} be probability $p_T$. The output is
% \ensuremath{(\mathit{false},\mathit{false})} with probability $p_F$
% and \ensuremath{(\mathit{true},\mathit{true})} with probability $p_T$
% which means that the output entropy is the same as the input entropy
% and the function is information-preserving.
% We are now ready to formalize the connection between reversibility and
% entropy, once we define logical reversibility of computations.
% \begin{definition}[Logical reversibility~\cite{Zuliani:2001:LR}]
% A function $f : b_1 \rightarrow b_2$ is logically reversible if there exists
% an inverse function $g : b_2 \rightarrow b_1$ such that for all values $v_1
% \in b_1$ and $v_2 \in b_2$, we have: $f(v_1) = v_2$ iff $g(v_2) = v_1$.
% \end{definition}
% \noindent The main proposition that motivates and justifies our approach is that
% logically reversible functions are information-preserving.
% \begin{proposition}
% A function is logically reversible iff it is information-preserving.
% \end{proposition}
% Looking at the examples above, we argued that \ensuremath{\mathit{constT}}, \ensuremath{\mathit{and}} are
% not information-preserving and that \ensuremath{\mathit{not}}, \ensuremath{\mathit{fanout}} are
% information-preserving. As expected, neither \ensuremath{\mathit{constT}} nor \ensuremath{\mathit{and}}
% are logically reversible and \ensuremath{\mathit{not}} is logically reversible. The
% situation with \ensuremath{\mathit{fanout}} is however subtle and deserves some
% explanation. First, note that the definition of logical reversibility
% does not require the functions to be total, and hence it is possible
% to define a \emph{partial} function \ensuremath{\mathit{fanin}} that is the logical
% inverse of \ensuremath{\mathit{fanout}}. The function \ensuremath{\mathit{fanin}} maps \ensuremath{(\mathit{false},\mathit{false})}
% to \ensuremath{\mathit{false}}, \ensuremath{(\mathit{true},\mathit{true})} to \ensuremath{\mathit{true}} and is undefined
% otherwise. Arguing that partial functions like \ensuremath{\mathit{fanin}} are
% information-preserving requires some care. Let the inputs to \ensuremath{\mathit{fanin}}
% occur with equal probabilities, i.e., let the entropy of the input
% be~2. Disregarding the partiality of \ensuremath{\mathit{fanin}}, one might reason that
% the output is \ensuremath{\mathit{false}} with probability $1/4$ and \ensuremath{\mathit{true}} with
% probability $1/4$ and hence that the output entropy is~1 which
% contradicts the fact that \ensuremath{\mathit{fanin}} is logically reversible. The
% subtlety is that entropy is defined with respect to observing some
% probabilistic event: an infinite loop is not an event that can be
% observed and hence the entropy analysis, just like the definition of
% logical reversibility, only applies to the pairs of inputs and outputs
% on which the function is defined. In the case of \ensuremath{\mathit{fanin}} this means
% that the only inputs that can be considered are \ensuremath{(\mathit{false},\mathit{false})} and
% \ensuremath{(\mathit{true},\mathit{true})} and in this case it is clear that the function is
% information-preserving as expected.
% \amr{end of popl 12 quote}
% %%%%%
% \subsection{Constraints}
% If we have the type $\mathsf{Bool} \times \mathsf{Bool}$ the
% information in each state is 2 bits. But if our system also has a
% constraint that the state must be of the form $(b,b)$, then there are
% only possible states in the system and the information contained in
% each is just one bit. There is a neat way to express the constraint
% using an equivalence generated by a pi-program.
% %%%%%
% \subsection{Information Equivalence}
% We need to show coherence of the definition of cardinalities on the
% universe syntax with the Euler characteristic of the category which in
% our case also corresponds to the groupoid cardinality. There are
% several formulations and explanations. The following is quite simple
% to implement: first collapse all the isomorphic objects. Then fix a
% particular order of the objects and write a matrix whose $ij$'s entry
% is the number of morphisms from $i$ to $j$. Invert the matrix. The
% cardinality is the sum of the elements in the matrix.
% Our notion of information equivalence is coarser than the conventional
% notion of equivalence of categories (groupoids). This is fine as there
% are several competing notions of equivalence of groupoids that are
% coarser than strict categorical equivalence.
% There are however other notions of equivalence of groupoids like
% Morita equivalence and weak equivalence that we explore later. The
% intuition of these weaker notions of equivalence is that two groupoids
% can be considered equivalent if it is not possible to distinguish them
% using certain observations. This informally corresponds to the notion
% of ``observational equivalence'' in programming language
% semantics. Note that negative entropy can only make sense locally in
% an open system but that in a closed system, i.e., in a complete
% computation, entropy cannot be negative. Thus we restrict
% observational contexts to those in which fractional types do not
% occur. Note that two categories can have the same cardinality but not
% be equivalent or even Morita equivalent but the converse is
% guaranteed. So it is necessary to have a separate notion of
% equivalence and check that whenever we have the same cardinality, the
% particular categories in question are equivalent.
% \begin{code}
% -- Conjecture: p ⇔ q implies order p = order q
% -- Corollary: p ⇔ !q implies order p = order (! q)
% -- The opposite is not true.
% -- Example
% -- p = (1 2 3 4)
% -- compose p 0 = compose !p 0 = compose p 4 = compose !p 4
% -- 1 -> 1
% -- 2 -> 2
% -- 3 -> 3
% -- 4 -> 4
% -- compose p 1 *** compose !p 1
% -- 1 -> 2 *** 1 -> 4
% -- 2 -> 3 *** 2 -> 1
% -- 3 -> 4 *** 3 -> 2
% -- 4 -> 1 *** 4 -> 3
% -- compose p 2 *** compose !p 2
% -- 1 -> 3 *** 1 -> 3
% -- 2 -> 4 *** 2 -> 4
% -- 3 -> 1 *** 3 -> 1
% -- 4 -> 2 *** 4 -> 2
% -- compose p 3 *** compose !p 3
% -- 1 -> 4 *** 1 -> 2
% -- 2 -> 1 *** 2 -> 3
% -- 3 -> 2 *** 3 -> 4
% -- 4 -> 3 *** 4 -> 1
% -- there is a morphism 1 -> 2 using
% -- (compose p 1) and (compose !p 3)
% -- p¹ is the same as !p³
% -- p² is the same as !p²
% -- p³ is the same as !p¹
% data FT/ : Set where
% ⇑ : FT → FT/
% # : {τ : FT} → (p : τ ⟷ τ) → FT/
% 1/# : {τ : FT} → (p : τ ⟷ τ) → FT/
% _⊞_ : FT/ → FT/ → FT/
% _⊠_ : FT/ → FT/ → FT/
% UG : Universe l0 (lsuc l0)
% UG = record {
% U = FT/
% ; El = λ T → Σ[ ℂ ∈ Category l0 l0 l0 ] (Groupoid ℂ)
% }
% card : FT/ → ℚ
% card (⇑ τ) = mkRational ∣ τ ∣ 1 {tt}
% card (# p) = mkRational (order p) 1 {tt}
% card (1/# p) = mkRational 1 (order p) {order-nz}
% card (T₁ ⊞ T₂) = (card T₁) ℚ+ (card T₂)
% card (T₁ ⊠ T₂) = (card T₁) ℚ* (card T₂)
% \end{code}
% %%%%%
% \subsection{Groupoids from $\Pi$-Combinators}
% The goal is to define a function that takes a $T$ in $FT/$ and
% produces something of type $Universe.El~UG~T$, i.e., a particular
% groupoid.
% \begin{code}
% -- First each p is an Agda type
% -- Perm p i is the type that contains the i^th iterate
% -- of p, i.e p^i up to <=>.
% -- the parens in the definition of ^ need to be there!
% _^_ : {τ : FT} → (p : τ ⟷ τ) → (k : ℤ) → (τ ⟷ τ)
% p ^ (+ 0) = id⟷
% p ^ (+ (suc k)) = p ◎ (p ^ (+ k))
% p ^ -[1+ 0 ] = ! p
% p ^ (-[1+ (suc k) ]) = (! p) ◎ (p ^ -[1+ k ])
% -- i.e. Perm is: for all i, any p' such that
% -- p' ⇔ p ^ i
% record Perm {τ : FT} (p : τ ⟷ τ) : Set where
% constructor perm
% field
% iter : ℤ
% p' : τ ⟷ τ
% p'⇔p^i : p' ⇔ p ^ iter
% cong^ : {τ : FT} → {p q : τ ⟷ τ} → (k : ℤ) → (eq : p ⇔ q) →
% p ^ k ⇔ q ^ k
% cong^ (+_ ℕ.zero) eq = id⇔
% cong^ (+_ (suc n)) eq = eq ⊡ cong^ (+ n) eq
% cong^ (-[1+_] ℕ.zero) eq = ⇔! eq
% cong^ (-[1+_] (suc n)) eq = (⇔! eq) ⊡ cong^ (-[1+ n ]) eq
% -- this should go into PiLevel1
% !!⇔id : {t₁ t₂ : FT} → (p : t₁ ⟷ t₂) → p ⇔ ! (! p)
% !!⇔id _⟷_.unite₊l = id⇔
% !!⇔id _⟷_.uniti₊l = id⇔
% !!⇔id _⟷_.unite₊r = id⇔
% !!⇔id _⟷_.uniti₊r = id⇔
% !!⇔id _⟷_.swap₊ = id⇔
% !!⇔id _⟷_.assocl₊ = id⇔
% !!⇔id _⟷_.assocr₊ = id⇔
% !!⇔id _⟷_.unite⋆l = id⇔
% !!⇔id _⟷_.uniti⋆l = id⇔
% !!⇔id _⟷_.unite⋆r = id⇔
% !!⇔id _⟷_.uniti⋆r = id⇔
% !!⇔id _⟷_.swap⋆ = id⇔
% !!⇔id _⟷_.assocl⋆ = id⇔
% !!⇔id _⟷_.assocr⋆ = id⇔
% !!⇔id _⟷_.absorbr = id⇔
% !!⇔id _⟷_.absorbl = id⇔
% !!⇔id _⟷_.factorzr = id⇔
% !!⇔id _⟷_.factorzl = id⇔
% !!⇔id _⟷_.dist = id⇔
% !!⇔id _⟷_.factor = id⇔
% !!⇔id _⟷_.distl = id⇔
% !!⇔id _⟷_.factorl = id⇔
% !!⇔id id⟷ = id⇔
% !!⇔id (p ◎ q) = !!⇔id p ⊡ !!⇔id q
% !!⇔id (p _⟷_.⊕ q) = resp⊕⇔ (!!⇔id p) (!!⇔id q)
% !!⇔id (p _⟷_.⊗ q) = resp⊗⇔ (!!⇔id p) (!!⇔id q)
% -- because ^ is iterated composition of the same thing,
% -- then by associativity, we can hive off compositions
% -- from left or right
% assoc1 : {τ : FT} → {p : τ ⟷ τ} → (m : ℕ) →
% (p ◎ (p ^ (+ m))) ⇔ ((p ^ (+ m)) ◎ p)
% assoc1 ℕ.zero = trans⇔ idr◎l idl◎r
% assoc1 (suc m) = trans⇔ (id⇔ ⊡ assoc1 m) assoc◎l
% assoc1- : {τ : FT} → {p : τ ⟷ τ} → (m : ℕ) →
% ((! p) ◎ (p ^ -[1+ m ])) ⇔ ((p ^ -[1+ m ]) ◎ (! p))
% assoc1- ℕ.zero = id⇔
% assoc1- (suc m) = trans⇔ (id⇔ ⊡ assoc1- m) assoc◎l
% -- Property of ^: negating exponent is same as
% -- composing in the other direction, then reversing.
% ^⇔! : {τ : FT} → {p : τ ⟷ τ} → (k : ℤ) →
% (p ^ (ℤ- k)) ⇔ ! (p ^ k)
% ^⇔! (+_ ℕ.zero) = id⇔
% -- need to dig deeper, as we end up negating
% ^⇔! (+_ (suc ℕ.zero)) = idl◎r
% ^⇔! (+_ (suc (suc n))) = trans⇔ (assoc1- n) (^⇔! (+ suc n) ⊡ id⇔)
% ^⇔! {p = p} (-[1+_] ℕ.zero) = trans⇔ idr◎l (!!⇔id p)
% ^⇔! {p = p} (-[1+_] (suc n)) =
% trans⇔ (assoc1 (suc n)) ((^⇔! -[1+ n ]) ⊡ (!!⇔id p))
% -- first match on m, n, then proof is purely PiLevel1
% lower : {τ : FT} {p : τ ⟷ τ} (m n : ℤ) →
% p ^ (m ℤ+ n) ⇔ ((p ^ m) ◎ (p ^ n))
% lower (+_ ℕ.zero) (+_ n) = idl◎r
% lower (+_ ℕ.zero) (-[1+_] n) = idl◎r
% lower (+_ (suc m)) (+_ n) =
% trans⇔ (id⇔ ⊡ lower (+ m) (+ n)) assoc◎l
% lower {p = p} (+_ (suc m)) (-[1+_] ℕ.zero) =
% trans⇔ idr◎r (trans⇔ (id⇔ ⊡ linv◎r) (
% trans⇔ assoc◎l (2! (assoc1 m) ⊡ id⇔))) -- p ^ ((m + 1) -1)
% lower (+_ (suc m)) (-[1+_] (suc n)) = -- p ^ ((m + 1) -(1+1+n)
% trans⇔ (lower (+ m) (-[1+ n ])) (
% trans⇔ ((trans⇔ idr◎r (id⇔ ⊡ linv◎r)) ⊡ id⇔) (
% trans⇔ assoc◎r (trans⇔ (id⇔ ⊡ assoc◎r) (
% trans⇔ assoc◎l (2! (assoc1 m) ⊡ id⇔)))))
% lower (-[1+_] m) (+_ ℕ.zero) = idr◎r
% lower (-[1+_] ℕ.zero) (+_ (suc n)) = 2! (trans⇔ assoc◎l (
% trans⇔ (rinv◎l ⊡ id⇔) idl◎l))
% lower (-[1+_] (suc m)) (+_ (suc n)) = -- p ^ (-(1+m) + (n+1))
% trans⇔ (lower (-[1+ m ]) (+ n)) (
% trans⇔ ((trans⇔ idr◎r (id⇔ ⊡ rinv◎r)) ⊡ id⇔) (
% trans⇔ assoc◎r (trans⇔ (id⇔ ⊡ assoc◎r) (
% trans⇔ assoc◎l ((2! (assoc1- m)) ⊡ id⇔)))))
% lower (-[1+_] ℕ.zero) (-[1+_] n) = id⇔
% lower (-[1+_] (suc m)) (-[1+_] n) = -- p ^ (-(1+1+m) - (1+n))
% trans⇔ (id⇔ ⊡ lower (-[1+ m ]) (-[1+ n ])) assoc◎l
% -- orderC is the groupoid with objects p^i
% orderC : {τ : FT} → (p : τ ⟷ τ) → Category _ _ _
% orderC {τ} p = record {
% Obj = Perm p
% ; _⇒_ = λ { (perm i p₁ _) (perm j p₂ _) → p₁ ⇔ p₂ }
% ; _≡_ = λ _ _ → ⊤
% ; id = id⇔
% ; _∘_ = λ α β → trans⇔ β α
% ; assoc = tt
% ; identityˡ = tt
% ; identityʳ = tt
% ; equiv = record { refl = tt; sym = λ _ → tt; trans = λ _ _ → tt }
% ; ∘-resp-≡ = λ _ _ → tt
% }
% where open Perm
% orderG : {τ : FT} → (p : τ ⟷ τ) → Groupoid (orderC p)
% orderG {τ} p = record {
% _⁻¹ = 2!
% ; iso = record {
% isoˡ = tt
% ; isoʳ = tt
% }
% }
% -- discrete groupoids corresponding to plain pi types
% discreteC : Set → Category _ _ _
% discreteC S = record {
% Obj = S
% ; _⇒_ = _≡_
% ; _≡_ = λ _ _ → ⊤
% ; id = refl
% ; _∘_ = λ { {A} {.A} {.A} refl refl → refl }
% ; assoc = tt
% ; identityˡ = tt
% ; identityʳ = tt
% ; equiv = record { refl = tt; sym = λ _ → tt; trans = λ _ _ → tt }
% ; ∘-resp-≡ = λ _ _ → tt
% }
% discreteG : (S : Set) → Groupoid (discreteC S)
% discreteG S = record
% { _⁻¹ = λ { {A} {.A} refl → refl }
% ; iso = record { isoˡ = tt; isoʳ = tt }
% }
% -- fractional groupoid
% 1/orderC : {τ : FT} (p : τ ⟷ τ) → Category _ _ _
% 1/orderC {τ} pp = record {
% Obj = ⊤
% ; _⇒_ = λ _ _ → Perm pp
% ; _≡_ = λ { (perm m p _) (perm n q _) → p ⇔ q } -- pp ^ m ⇔ pp ^ n
% ; id = perm (+ 0) id⟷ id⇔
% ; _∘_ = λ { (perm m p α) (perm n q β) →
% perm (m ℤ+ n) (p ◎ q) (trans⇔ (α ⊡ β) (2! (lower m n))) }
% ; assoc = assoc◎r
% ; identityˡ = idl◎l
% ; identityʳ = idr◎l
% ; equiv = record { refl = id⇔; sym = 2!; trans = trans⇔ }
% ; ∘-resp-≡ = _⊡_
% }
% 1/orderG : {τ : FT} (p : τ ⟷ τ) → Groupoid (1/orderC p)
% 1/orderG p = record {
% _⁻¹ = λ { (perm i q eq) →
% perm (ℤ- i) (! q) (trans⇔ (⇔! eq) (2! (^⇔! {p = p} i)))}
% ; iso = record { isoˡ = rinv◎l ; isoʳ = linv◎l }
% }
% \end{code}
% %% _//_ : (τ : FT) → (p : τ ⟷ τ) → Category _ _ _
% %% τ // p = Product (discreteC (El τ)) (1/orderC p)
% %% where open Universe.Universe UFT
% %%
% %% quotientG : (τ : FT) → (p : τ ⟷ τ) → Groupoid (τ // p)
% %% quotientG = {!!}
% So now we can finally define our denotations:
% \begin{code}
% ⟦_⟧/ : (T : FT/) → Universe.El UG T
% ⟦ ⇑ S ⟧/ = , discreteG (Universe.El UFT S)
% ⟦ # p ⟧/ = , orderG p
% ⟦ 1/# p ⟧/ = , 1/orderG p
% ⟦ T₁ ⊞ T₂ ⟧/ with ⟦ T₁ ⟧/ | ⟦ T₂ ⟧/
% ... | (_ , G₁) | (_ , G₂) = , GSum G₁ G₂
% ⟦ T₁ ⊠ T₂ ⟧/ with ⟦ T₁ ⟧/ | ⟦ T₂ ⟧/
% ... | (_ , G₁) | (_ , G₂) = , GProduct G₁ G₂
% \end{code}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% -- p is a monad on (order p)
% ^suc : {τ : FT} {p : τ ⟷ τ} {i : ℤ} → p ^ ℤsuc i ⇔ p ◎ p ^ i
% ^suc = {!!}
% ^resp : {τ : FT} {p q : τ ⟷ τ} {i : ℤ} → (q ^ i ⇔ p ^ i) → (q ◎ q ^ i ⇔ p ◎ p ^ i)
% ^resp = {!!}
% orderM : {τ : FT} → (p : τ ⟷ τ) → Monad (orderC p)
% orderM {τ} p = record {
% F = record {
% F₀ = λ { (i , (q , α)) →
% (ℤsuc i , (q , trans⇔ (^suc {p = q} {i = i})
% (trans⇔ (^resp {p = p} {q = q} {i = i} α)
% (2! (^suc {p = p} {i = i})))))}
% ; F₁ = {!!}
% }
% ; η = record {
% η = {!!}
% ; commute = λ _ → tt
% }
% ; μ = record {
% η = {!!}
% ; commute = λ _ → tt
% }
% ; assoc = tt
% ; identityˡ = tt
% ; identityʳ = tt
% }
% -- ! p is a comonad on (order p)
% orderCom : {τ : FT} → (p : τ ⟷ τ) → Comonad (orderC p)