-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtiny.tex
2424 lines (2203 loc) · 117 KB
/
tiny.tex
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
\documentclass[10pt]{article}
\usepackage{fullpage}
\thickmuskip=5mu plus 3mu minus 1mu
\medmuskip=4mu plus 2mu minus 3mu
% \usepackage{scohesion}
\usepackage{amssymb,amsthm}
\usepackage{thmtools}
\usepackage{amsmath}
\usepackage{stmaryrd}
\usepackage{wasysym}
\usepackage{mathpartir}
\usepackage{tikz-cd}
\usepackage{graphicx}
\usepackage{scalerel}
\usepackage{fontawesome}
\usepackage{xcolor}
\definecolor{darkgreen}{rgb}{0,0.45,0}
\usepackage[status=draft,inline,nomargin]{fixme}
\FXRegisterAuthor{mvr}{anmvr}{\color{blue}MVR}
\usepackage[style=alphabetic, maxbibnames=99, maxalphanames=99,
mincrossrefs=99]{biblatex}
\addbibresource{tiny.bib}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{corollary}[theorem]{Corollary}
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{example}[theorem]{Example}
\newtheorem{question}{Question}
\let\oldequiv\equiv%
\renewcommand{\equiv}{\simeq}
\newcommand{\defeq}{\oldequiv}
\newcommand{\ndefeq}{\not\defeq}
\newcommand{\rulen}[1]{\textsc{#1}}
\newcommand{\yields}{\vdash}
\newcommand{\qyields}{\Vdash}
\newcommand{\cbar}{\, | \,}
\newcommand{\judge}{\mathcal{J}}
\newcommand{\freshfor}{\mathbin{\#}}
\newcommand{\ctx}{\,\,\mathsf{ctx}}
\newcommand{\type}{\,\,\mathsf{type}}
\newcommand{\tele}{\,\,\mathsf{tele}}
% Ordinary HoTT notation
\newcommand{\Idsym}{\mathsf{Id}}
\newcommand{\Id}{\mathsf{Id}}
% \newcommand{\Id}[3]{\mathsf{Id}_{{#1}}(#2,#3)}
\newcommand*{\trunc}[2]{\mathopen{}\left\Vert #2\right\Vert_{#1}\mathclose{}}
\newcommand*{\strunc}[2]{\mathopen{}\left\Vert #2\right\Vert_{#1}^s\mathclose{}}
\newcommand*{\univ}{\mathcal{U}}
\newcommand*{\NN}{\mathbb{N}}
\newcommand*{\ZZ}{\mathbb{Z}}
% \newcommand*{\true}{\star}
\newcommand*{\id}{\mathsf{id}}
\newcommand*{\proj}{\mathsf{pr}}
\newcommand*{\pushpr}{\mathbin{\wasysquare}}
\newcommand*{\join}{\ast}
\newcommand*{\ap}{\mathsf{ap}}
\newcommand*{\transp}{\mathsf{tr}}
\newcommand*{\isContr}{\mathsf{isContr}}
\newcommand*{\isEquiv}{\mathsf{isEquiv}}
\newcommand*{\isSpace}{\mathsf{isSpace}}
\newcommand*{\isModal}{\mathsf{isModal}}
\newcommand*{\inl}{\mathsf{inl}}
\newcommand*{\inr}{\mathsf{inr}}
\newcommand*{\glue}{\mathsf{glue}}
\newcommand*{\code}{\mathsf{code}}
\newcommand*{\encode}{\mathsf{encode}}
\newcommand*{\decode}{\mathsf{decode}}
\newcommand*{\const}{\mathsf{const}}
\newcommand*{\fib}{\mathsf{fib}}
\newcommand*{\case}{\mathsf{case}}
\newcommand*{\refl}[1]{\mathsf{refl}_{#1}}
\newcommand*{\pathind}[3]{\mathsf{let} \; \refl{#2} = {#1} \,
\mathsf{in} \, {#3}}
\newcommand*{\cupann}[2]{\mathbin{\tensor*[_{#1}]{\cup}{_{#2}}}}
\newcommand{\bang}{\mathord{!}}
\newcommand{\ind}[3]{\mathsf{let} \; {#2} = {#1} \, \mathsf{in} \, {#3}}
% \makeatletter
% \newcommand{\@thesum}[1]{(#1) \times}
% \newcommand{\sm}[1]{\@ifnextchar\bgroup{\@thesum{#1}\sm}{\@thesum{#1}}}
% \newcommand{\@theprd}[1]{(#1) \to}
% \newcommand{\prd}[1]{\@ifnextchar\bgroup{\@theprd{#1}\prd}{\@theprd{#1}}}
% \makeatother
\makeatletter \def\smsym{\sum}
\newcommand{\@thesum}[1]{\smsym_{(#1)}}
\newcommand{\sm}[1]{\@ifnextchar\bgroup{\@sm{#1}\sm}{\@sm{#1}}}
\newcommand{\@sm}[1]{\mathchoice{{\textstyle\@thesum{#1}}}{\@thesum{#1}}{\@thesum{#1}}{\@thesum{#1}}}
\def\prdsym{\prod}
\newcommand{\@theprd}[1]{\prdsym_{(#1)}}
\newcommand{\prd}[1]{\@ifnextchar\bgroup{\@prd{#1}\prd}{\@prd{#1}}}
\newcommand{\@prd}[1]{\mathchoice{{\textstyle\@theprd{#1}}}{\@theprd{#1}}{\@theprd{#1}}{\@theprd{#1}}}
\makeatother
\newcommand*{\lolli}{\multimap}
% \newcommand{\lock}{\text{\faLock}}
\newcommand{\lock}{\mathchoice {\scalebox{0.8}{\text{\faLock}}}
{\scalebox{0.8}{\text{\faLock}}} {\scalebox{0.5}{\text{\faLock}}}
{\scalebox{0.4}{\text{\faLock}}} }
\newcommand{\unlock}{\text{\faUnlock}}
\newcommand{\key}{\mathchoice
{\scalebox{0.8}{\text{\faKey}}} {\scalebox{0.8}{\text{\faKey}}}
{\scalebox{0.5}{\text{\faKey}}} {\scalebox{0.4}{\text{\faKey}}} }
\newcommand{\rbindsym}{\raisebox{-0.5pt}{\scalerel*{\reflectbox{\rotatebox[origin=c]{185}{$\lambda$}}}{\lambda}}}
% \newcommand{\rbindsym}{\raisebox{-0.55pt}{\scalerel*{\rotatebox[origin=c]{185}{$\lambda$}}{\lambda}}\hspace{-0.06em}}
\newcommand{\rbind}[1]{\rbindsym{} #1.}
% lol
% \newcommand{\rbind}[1]{. #1 \rbindsym{}}
\newcommand{\Tiny}{\mathbb{T}}
\newcommand{\lockn}[1]{\mathcal{#1}}
\newcommand{\locksin}[1]{\mathsf{locks}(#1)}
\newcommand{\varkeye}[2]{\key_{#1}^{#2}}
\newcommand{\varkey}[2]{\varkeye{\lockn{#1}}{#2}}
\newcommand{\admkeye}[2]{\overrightarrow{\key}_{#1}^{#2}}
\newcommand{\admkey}[2]{\admkeye{\lockn{#1}}{#2}}
\newcommand{\ctxlocke}[1]{\lock_{#1}}
\newcommand{\ctxlock}[1]{\ctxlocke{\lockn{#1}}}
% \newcommand{\ctxopen}[2]{\unlock_{\lockn{#1}}^{\,#2}}
\newcommand{\stubra}[1]{\llbracket #1 \rrbracket}
% \newcommand{\stubra}[1]{\lfloor #1 \rfloor}
\newcommand{\admbra}[1]{[ #1 ]}
\newcommand{\subkeyoe}[2]{#1/\key_{#2}}
\newcommand{\subkeyo}[2]{\subkeyoe{#1}{\lockn{#2}}}
\newcommand{\subkeye}[2]{\admbra{\subkeyoe{#1}{#2}}}
\newcommand{\subkey}[2]{\admbra{\subkeyo{#1}{#2}}}
\newcommand{\subkeyeann}[5]{\admbra{\key(#3; #1/#2; #4; #5)}}
\newcommand{\subkeyann}[5]{\subkeyeann{#1}{\lockn{#2}}{#3}{#4}{#5}}
\newcommand{\subkeyetele}[4]{\admbra{\key(#3; #1/#2; #4)}}
\newcommand{\subkeytele}[4]{\subkeyetele{#1}{\lockn{#2}}{#3}{#4}}
\newcommand{\substucke}[2]{\stubra{#1/\key_{#2}}}
\newcommand{\substuck}[2]{\substucke{#1}{\lockn{#2}}}
% \newcommand{\sublock}[2]{\admbra{\lock_{\lockn{#1}}/#2}}
\newcommand{\sublock}[2]{\admbra{\rbindsym{} #2. /\lock_{\lockn{#1}} }}
% \newcommand{\sublock}[2]{\admbra{ .#2 \rbindsym{} /\lock_{\lockn{#1}} }}
\newcommand{\unit}[3]{\mathsf{unit}_{#1, #2, \lockn{#3}}}
\newcommand{\counit}[3]{\mathsf{counit}_{#1, \lockn{#2}, #3}}
\newcommand{\rformsym}{\surd}
\newcommand{\rformslicesym}[1]{\surd_{\mkern-6mu/#1}}
\newcommand{\rforme}[2]{\ThisStyle{\raisebox{0.07em}{$\SavedStyle \rformsym_{\hspace{-0.25em}#1}$}} #2}
\newcommand{\rform}[2]{\rforme{\lockn{#1}}{#2}}
\newcommand{\rformu}[1]{\ThisStyle{\raisebox{0.07em}{$\SavedStyle \rformsym$}} #1}
% \newcommand{\rintroe}[2]{\mathsf{root}_{#1}(#2)}
\newcommand{\rintroe}[2]{\lock_{#1}. #2}
\newcommand{\rintro}[2]{\rintroe{\lockn{#1}}{#2}}
% \newcommand{\relim}[1]{\mathsf{unroot}(#1)}
% \newcommand{\rbindsym}{\rotatebox[origin=c]{180}{$\lambda$}}
\newcommand{\relim}[1]{\rbindsym #1}
\newcommand{\retro}[1]{\mathsf{retro}\,#1}
% \newcommand{\rdepform}[2]{{\between^{#1}}#2}
\newcommand{\rdepform}[2]{{#2}^{1/#1}}
\newcommand{\rget}[1]{{#1}_{\downharpoonleft}}
% Cubical stuff
\newcommand{\Set}{\mathsf{Set}}
\newcommand{\El}{\mathsf{El}}
\newcommand{\univfib}{\mathsf{U}}
\newcommand{\Int}{\mathbb{I}}
\DeclareMathOperator{\isFib}{\mathsf{isFib}}
\DeclareMathOperator{\Fib}{\mathsf{Fib}}
\DeclareMathOperator{\isNewFib}{\mathsf{isNewFib}}
\DeclareMathOperator{\NewFib}{\mathsf{NewFib}}
\newcommand{\Compstr}{\mathsf{C}}
\usepackage{hyperref}
\usepackage{cleveref}
\hypersetup{colorlinks,citecolor=darkgreen,linkcolor=darkgreen}
\title{Tiny Object}
\author{}
\date{}
\begin{document}
\maketitle
We describe a type theory that makes a fixed type $\Tiny$ a `tiny
object': there is a type former $\rformu$ that is the amazing right
adjoint to $(\Tiny \to -)$. Of necessity this is an external right
adjoint, and so the context structure of ordinary type theory will
have to be modified to support it.
We add $\rformu$ as a `Fitch style'
modality~\cite{clouston:fitch-style}, where the type former $\rformu$
is made right-adjoint to an operation on contexts. Such modalities are
particularly nice when they are a \emph{double} right adjoint, and
FitchTT~\cite{fitchtt} investigates adding modalities of this kind to
MLTT. We are in such a situation, of course, because
\[{(- \times \Tiny) \dashv (\Tiny \to -) \dashv \rformu -},\] and so
we could use~\cite{fitchtt} directly to produce a type theory.
But there is a special feature of $\rformu$ which impels us to create
a specialised theory for it. Specifically, the leftmost adjoint
$(- \times \Tiny)$ already exists as an operation on contexts: it is
simply context extension with $i : \Tiny$. We allow $\Tiny$ to be an
\emph{ordinary type}, rather than a pre-type or special piece of
syntax. This flexibility is essential for applications in synthetic
differential geometry, where, for example, the type of (first-order)
infinitesimals defined by
$D :\defeq \{ x : \mathbb{R} \mid x^2 = 0 \}$ is tiny. The only new
context former needed is something corresponding to $(\Tiny \to -)$,
which we write as context extension with a $lock$.
To make $(-,i:\Tiny) \dashv (-,\lock)$ on contexts, we need unit
$\Gamma \to (\Gamma,i : \Tiny, \lock)$ and counit
$(\Gamma,\lock,i : \Tiny) \to \Gamma$ substitutions. In~\cite{fitchtt}
these are added axiomatically, and the type theory is presented in a
variable-free CwF style where these explicit substitutions are pushed
around manually. The downside of the approach is that figuring out how
to use a variable could be challenging: we may have to devise by hand
an explicit substitution that extracts the variable from the context.
One of our aims is to give a fully explicit variable rule which
builds in the normal forms of these `stuck substitutions'.
The reason this gets interesting is that, because $\Tiny$ is an
ordinary type, we can substitute \emph{any term} $t : \Tiny$ for $i$
in the counit substitution. And so, the admissible counit rule is
parameterised by a genuine term $t : \Tiny$. The counit rule only gets
stuck on the ordinary variable rule, so every use of a variable in
this theory can have (possibly many) attached terms of $\Tiny$
corresponding to these stuck counits. Having $\Tiny$ as an ordinary
type distinguishes this type theory from
\cite{cavallo-harper:parametricity-for-ctt,cavallo:thesis} and
\cite[Section 5]{fitchtt}, where the $\Gamma,i:\Tiny$ context
extension is a special piece of syntax, and so only special `terms'
may be substituted for it.
In contrast to \cite[Section 2]{transpension}, we only add a right
adjoint for the non-dependent function space, rather than adding a
right adjoint to the dependent product
$\Pi_\Tiny : \mathcal{E}/\Tiny \to \mathcal{E}$. This makes the rules
for the $\rformu$ type much simpler, and (conjecturally) lets us
maintain admissibility of substitution, normalisation, etc. And, maybe
surprisingly, a right adjoint to the dependent function space is
derivable internally from our simply-typed version.
In~\cite{lops}, a tiny interval $\mathbb{I}$ is used to give an
internal construction of a universe that classifies fibrations. The
$\rformu$ type former is described by a collection of axioms, and the
fact that the adjunction is external is enforced by requiring the
inputs to these axioms to be `crisp', roughly, protected by a use of
the global sections/discrete inclusion modality $\flat$. Internally,
this manifests as an equivalence
$\flat((\Tiny \to A) \to B) \equiv \flat(A \to \rformu B)$, but we
will see that this is more restrictive than necessary. Once we have
the $\rformu$ type former built-in, we can prove an equivalence
$\rformu ((\Tiny \to A) \to B) \equiv (A \to \rformu B)$, where $A$
and $B$ do not have to be `global types'. (But the dependency of $B$
is still somewhat restricted.)
Our type theory tackles a challenge set by Lawvere, to produce a
formal system for working with tiny objects: ``This possibility does
not seem to have been contemplated by combinatory logic; the formalism
should be extended to enable treatment of so basic a
situation''~\cite[Section 3]{lawvere:adjoints}.
% \mvrnote{Which cube categories have tiny intervals?
% \cite{buchholtz-morehouse:cubes}}
\section{Contexts and Variables}
The $\rformu$ type former will be added by making it right-adjoint to
a judgemental version of ``$\Tiny \to \Gamma$'' which we write as
$\Gamma, \ctxlock{L}$, where, to refer to it later, the lock is
annotated with a `lock name' $\lockn{L}$. This first section will be
spent adding the necessary rules for $\Gamma, \ctxlock{L}$ to behave
like functions into $\Gamma$.
A simple way to achieve this is to assert axiomatic unit and counit
substitutions for the $(- \times \Tiny) \dashv (\Tiny \to -)$
adjunction, as in the following
\begin{mathpar}
\inferrule*[left=tiny-form]{\Gamma \ctx}{\Gamma \yields \Tiny \type} \and
\inferrule*[left=ctx-lock]{\Gamma \ctx}{\Gamma, \ctxlock{L} \ctx} \\
\inferrule*[left=unit-sub]
{\Gamma \ctx}
{\Gamma \yields \unit{\Gamma}{i}{L} : \Gamma, i : \Tiny, \ctxlock{L}}
\and
\inferrule*[left=counit-sub]
{\Gamma \ctx}
{\Gamma, \ctxlock{L}, i : \Tiny \yields \counit{\Gamma}{L}{i} : \Gamma}
\end{mathpar}
together with equations that explain how these explicit substitutions
annihilate.
We think we can do better, however, and give normal forms for the
placement of these explicit substitutions. The examples in later
sections show that it is quite feasible to work in the resulting type
theory by hand.
Besides the context lock, we only need one additional base rule: a
modified version of the variable rule that builds in stuck instances
of the counit substitution. The rule is completely structural and
independent of the rules for types (besides the existence of $\Tiny$).
There are two new admissible rules, corresponding to precomposition
with the counit and unit substitutions.
\begin{itemize}
\item \textbf{The Tiny Type.} There is a closed type $\Tiny$.
\begin{mathpar}
\inferrule*[left=tiny-form]{\Gamma \ctx}{\Gamma \yields \Tiny \type}
\end{mathpar}
\item \textbf{Context Lock.} There is a special context extension,
\begin{mathpar}
\inferrule*[left=ctx-lock]{\Gamma \ctx}{\Gamma, \ctxlock{L} \ctx}
\and
\end{mathpar}
to be thought of as $\Tiny \to \Gamma$. We call $\lockn{L}$ a `lock
name', all lock names in a context are unique.
\item \textbf{Counit.} Because a lock on a context is just a function
into that context, we can use variables to the left of a lock if we
can provide an argument to the function: this corresponds to
precomposition with the counit substitution, with a substitution
for $\Tiny$ and some contractions built-in.
The simplest situation we can encounter is
\begin{mathpar}
\inferrule*[left=counit?,fraction={-{\,-\,}-}]
{\Gamma \yields a : A \and \Gamma, \ctxlock{L}, \Gamma' \yields t : \Tiny \and \lock \notin \Gamma'}
{\Gamma, \ctxlock{L}, \Gamma' \yields a\subkey{t}{L} : A\subkey{t}{L}}
\end{mathpar}
corresponding (non-dependently) to the composite
\begin{align*}
(\Tiny \to \Gamma) \times \Gamma'
\xrightarrow{[\id, t]} (\Tiny \to \Gamma) \times \Gamma' \times
\Tiny
\xrightarrow{\proj} (\Tiny \to \Gamma) \times \Tiny
\xrightarrow{\varepsilon} \Gamma
\xrightarrow{a} A
\end{align*}
The new piece of term syntax is a stuck instance of this
$\subkey{t}{L}$ rule, which we build into the variable rule
below. To distinguish the admissible rule from the stuck rule, we
will write the admissible rule as $\subkey{t}{L}$ and the actual
stuck syntax as $\substuck{t}{L}$. Roughly, the admissible
$\subkey{t}{L}$ will add a $\substuck{t}{L}$ to every
\emph{free} variable usage in $a$, a bit like the underlining operation in
the type theory for $\natural$.
We need to generalise this rule in a couple of ways. First, we need
to allow an additional telescope to be carried along, so that we may
go under binders in the term $a : A$.
Additionally, we may need to apply the counit to multiple locks
simultaneously. To facilitate this, for a context
$\Gamma, \Gamma' \ctx$, let $\locksin{\Gamma'}$ denote the (ordered)
list of context locks
$\ctxlocke{\lockn{L}_1}, \dots, \ctxlocke{\lockn{L}_n}$ that appear
in the telescope $\Gamma'$.
The generalised rule is then:
\begin{mathpar}
\inferrule*[left=counit-tele,fraction={-{\,-\,}-}]
{\Gamma \yields \Gamma'' \tele \and \Gamma, \Gamma' \yields t_i : \Tiny
\text{ for } \lockn{L}_i \in \locksin{\Gamma'} }
{\Gamma, \Gamma' \yields \Gamma'' \admbra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}} \tele} \and
\inferrule*[left=counit,fraction={-{\,-\,}-}]
{\Gamma, \Gamma'' \yields a : A \and \Gamma, \Gamma' \yields t_i : \Tiny
\text{ for } \lockn{L}_i \in \locksin{\Gamma'} }
{\Gamma, \Gamma', \Gamma'' \admbra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}} \yields a \admbra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}} : A \admbra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}} }
\end{mathpar}
% Formally, the contexts and telescopes used should be annotated in
% the syntax. When it is necessary to make clear which are used, we
% will write $a \subkeyann{t}{L}{\Gamma}{\Gamma'}{\Gamma''}$ and
% $\Gamma''\subkeytele{t}{L}{\Gamma}{\Gamma'}$.
\item \textbf{Variable Usage.} To use a variable $x : A$ that is
behind some context locks, we must provide a term $t_i : \Tiny$
for each lock between that variable and the front of the context.
\begin{mathpar}
\inferrule*[left=var]
{\Gamma, x : A, \Gamma' \yields t_i : \Tiny
\text{ for } \lockn{L}_i \in \locksin{\Gamma'} }
{\Gamma, x : A, \Gamma' \yields x \stubra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}} :
A \admbra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}}}
\end{mathpar}
The type of the variable usage has the admissible counit rule
applied to it: typically these counits will not be stuck on the type
$A$ unless $A$ is itself a variable.
\item \textbf{Substitution.} Ordinary substitution into a variable turns these
`stuck' counits back into admissible ones, and continues into the attached terms of $\Tiny$.
\begin{align*}
% \Gamma, x : A, \Gamma'
% &\yields x \substucke{t_1}{\lockn{L}_1} \dots
% \substucke{t_n}{\lockn{L}_n} : A\subkeye{t_1}{\lockn{L}_1} \dots \subkeye{t_n}{\lockn{L}_n} \\
\Gamma, \Gamma'[a/x]
&\yields x \stubra{\subkeyoe{t_1}{\lockn{L}_1}, \dots, \subkeyoe{t_n}{\lockn{L}_n}}[a/x] \\
&:\defeq a\admbra{\subkeyoe{t_1[a/x]}{\lockn{L}_1}, \dots, \subkeyoe{t_n[a/x]}{\lockn{L}_n}}
\end{align*}
\item \textbf{Calculating the Counit.} For now, assume that all the
terms of $\Tiny$ that are involved are closed. To evaluate
$b\subkey{t}{L}$ on a term $\Gamma \yields b : B$, induct on $b$
until we reach an instance of the variable rule, say for the
variable $x : A$.
As always, there are cases depending on where in the context $x$
lies. The typical case is when $x : A$ is in $\Gamma$, so the
context has form
\begin{align*}
\Gamma_1, x : A, \Gamma_2, \Gamma'' &\ctx \\
\locksin{\Gamma_2} &\defeq \lockn{J}_1, \dots,\lockn{J}_m \\
\locksin{\Gamma''} &\defeq \lockn{K}_{1}, \dots, \lockn{K}_n
\end{align*}
and the variable usage looks like
\begin{align*}
\Gamma_1, x : A, \Gamma_2, \Gamma''
&\yields x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}} \\
&: A \admbra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}}
\end{align*}
Then we slot the new $\subkey{t}{L}$ into place, and leave it stuck:
\begin{align*}
\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma'' \yields
(&x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}}) \subkey{t}{L} \\
:\defeq {}
&x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyo{t}{L},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}}
\end{align*}
When working informally, this means counting how many
$\ctxlocke{\lockn{K}_i}$ are created between the application of
$\subkey{t}{L}$ and the variable (by the use of some of the typing
rules), and placing $\subkeyo{t}{L}$ to the left of all the newly
created $\ctxlocke{\lockn{K}_i}$.
If instead $x : A$ is in $\Gamma''$, so
$\Gamma, \Gamma_1'', x : A, \Gamma_2'' \ctx$, suppose the locks
coming after $x$ are
$\locksin{\Gamma_2''} \defeq \lockn{K}_{1}, \dots, \lockn{K}_n$ and
the variable usage looks like
\begin{align*}
\Gamma, \Gamma_1'', x : A, \Gamma_2''
&\yields x \stubra{\subkeyoe{k_1}{\lockn{K}_{1}}, \dots, \subkeyoe{k_n}{\lockn{K}_n}} \\
&: A\admbra{\subkeyoe{k_1}{\lockn{K}_{1}}, \dots, \subkeyoe{k_n}{\lockn{K}_n}} \\
\end{align*}
Access to $x$ is not affected by the addition of the lock
$\ctxlock{L}$ (which is placed to the left of it), so the variable
usage is left unchanged.
Things are trickier with general open terms of $\Tiny$. A couple of
complications can arise: \mvrnote{These are a bit gnarly, so you
should probably skip this list on first read}
\begin{itemize}
\item When $t : \Tiny$ is not closed, so that
$\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma' \yields t : \Tiny$,
the variables used in the term $t$ itself are now locked behind the
locks in $\Gamma''$ by the time we reach the variable $x$. We
therefore need to (admissibly) apply
\begin{align*}
-\admbra{\subkeyoe{k_1}{\lockn{K}_{1}}, \dots, \subkeyoe{k_n}{\lockn{K}_n}}
\end{align*}
to the term $t$, so:
\begin{align*}
&x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}} \subkey{t}{L} \\
:\defeq {}
&x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyo{t\admbra{\subkeyoe{k_1}{\lockn{K}_{1}}, \dots, \subkeyoe{k_n}{\lockn{K}_n}}}{L},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}}
\end{align*}
\item Instead, the terms $j_i$ and $k_i$ may not closed, and so the variables
used in them might now lie behind the new lock $\ctxlock{L}$. The
term $t$ is used to unlock them:
\begin{alignat*}{2}
&x \stubra{&&\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}} \subkey{t}{L} \\
:\defeq {}
&x
\stubra{&& \subkeyoe{j_1\subkey{t}{L}}{\lockn{J}_1}, \\
&&& \dots, \\
&&& \subkeyoe{j_{m}\subkey{t}{L}}{\lockn{J}_{m}}, \\
&&& \subkeyo{t}{L}, \\
&&& \subkeyoe{k_{1}\subkey{t}{L}}{\lockn{K}_{1}}, \\
&&& \dots, \\
&&& \subkeyoe{k_n\subkey{t}{L}}{\lockn{K}_n}
}
\end{alignat*}
\item Finally, and slightly horrifyingly, the two complications can happen
at the same time, yielding the final, general definition:
\begin{alignat*}{2}
&x \stubra{&&\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}} \subkey{t}{L} \\
:\defeq {}
&x
\stubra{&& \subkeyoe{j_1\subkey{t}{L}}{\lockn{J}_1}, \\
&&& \dots, \\
&&& \subkeyoe{j_{m}\subkey{t}{L}}{\lockn{J}_{m}}, \\
&&& \subkeyo{t\admbra{\subkeyoe{k_1\subkey{t}{L}}{\lockn{K}_{1}}, \dots, \subkeyoe{k_n\subkey{t}{L}}{\lockn{K}_n}}}{L}, \\
&&& \subkeyoe{k_{1}\subkey{t}{L}}{\lockn{K}_{1}}, \\
&&& \dots, \\
&&& \subkeyoe{k_n\subkey{t}{L}}{\lockn{K}_n}
}
\end{alignat*}
\mvrnote{It's not so obvious to me that this terminates!}
\iffalse
\item The terms $k_i$ used on the other keys, however,
may themselves use variables from $\Gamma$. These variables lie
behind the new lock $\ctxlock{L}$, so we must proceed with applying
the same \rulen{counit} to the $k_i$:
\begin{align*}
\Gamma, \ctxlock{L}, \Gamma', \Gamma_1'', x : A, \Gamma_2''
&\yields x \substucke{k_1\subkey{t}{L}}{\lockn{K}_1} \dots \substucke{k_n\subkey{t}{L}}{\lockn{K}_n} \\
&: A\subkeye{k_1\subkey{t}{L}}{\lockn{K}_1} \dots \subkeye{k_n\subkey{t}{L}}{\lockn{K}_n}
\end{align*}
\fi
\end{itemize}
Let's write out typing derivation in the situation where there are
no other context locks around, making explicit the telescopes that
are used.
Given the variable
\begin{mathpar}
\inferrule*
{\Gamma_1, x : A, \Gamma_2, \Gamma_1'', \ctxlock{K}, \Gamma_2'' \yields s : \Tiny}
{\Gamma_1, x : A, \Gamma_2, \Gamma_1'', \ctxlock{K}, \Gamma_2'' \yields x\substuck{s}{K} : A}
\end{mathpar}
so that
\begin{mathpar}
\inferrule*{
\inferrule*
{\Gamma_1, x : A, \Gamma_2, \Gamma_1'', \ctxlock{K}, \Gamma_2'' \yields s : \Tiny}
{\Gamma_1, x : A, \Gamma_2, \Gamma_1'', \ctxlock{K}, \Gamma_2'' \yields x\substuck{s}{K} : A} \and
\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma' \yields t : \Tiny}
{\Gamma_1, x : A, \Gamma_2, \Gamma', \Gamma_1''\subkey{t}{L}, \ctxlock{K}, \Gamma_2''\subkey{t}{L} \yields x\substuck{s}{K}\subkey{t}{L} : A}
\end{mathpar}
Our definition sets this equal to
$x\substuck{(t\subkey{s\subkey{t}{L}}{K})}{L}\substuck{s}{K}$, where
\begin{align*}
t\subkey{s\subkey{t}{L}}{K} \defeq t\subkeyann{s\subkeyann{t}{L}{\Gamma_1, x : A, \Gamma_2}{\Gamma'}{\Gamma''_1, \ctxlock{K}, \Gamma''_2}}{K}{\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma', \Gamma_1''\subkey{t}{L}}{\Gamma_2'' \subkey{t}{L}}{\cdot}
\end{align*}
has typing derivation
\begin{mathpar}
\inferrule*
{\inferrule*
{\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma' \yields t : \Tiny}
{\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma', \Gamma_1''\subkey{t}{L} \yields t : \Tiny}
\and
\inferrule*
{\Gamma_1, x : A, \Gamma_2, \Gamma_1'', \ctxlock{K}, \Gamma_2'' \yields s : \Tiny \and
\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma' \yields t : \Tiny
}
{\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma', \Gamma_1''\subkey{t}{L}, \ctxlock{K}, \Gamma_2''\subkey{t}{L} \yields s\subkey{t}{L} : \Tiny}
}
{\Gamma_1, x : A, \Gamma_2, \ctxlock{L}, \Gamma', \Gamma_1''\subkey{t}{L}, \ctxlock{K}, \Gamma_2'' \subkey{t}{L} \yields t\subkey{s\subkey{t}{L}}{K} : \Tiny}
\end{mathpar}
\item \textbf{Unit.} To complete the implementation of the adjunction,
we have an admissible rule representing the unit map. The following
rule is precomposition with the substitution
$\Gamma \to (\Gamma,i : \Tiny, \ctxlock{L})$, suitably generalised
with a telescope $\Gamma'$:
\begin{mathpar}
\inferrule*[left=unit,fraction={-{\,-\,}-}]
{\Gamma, i : \Tiny, \ctxlock{L}, \Gamma' \yields a : A}
{\Gamma, \Gamma'\sublock{L}{i} \yields a\sublock{L}{i} : A\sublock{L}{i}} \\
\inferrule*[left=unit-tele,fraction={-{\,-\,}-}]
{\Gamma, i : \Tiny, \ctxlock{L} \yields \Gamma' \tele}
{\Gamma \yields \Gamma'\sublock{L}{i} \tele}
\end{mathpar}
Like the $\subkey{t}{L}$ operation, we use substitution-like syntax
for the unit map because it commutes past everything until it
reaches a variable. The silly $\rbind{i}$ notation is chosen to
match the syntax for the type former later, sorry!
The lock and key then `click together', yielding an ordinary
substitution. In the simplest case, when $t : \Tiny$ is closed and
$x$ has a single matching stuck \rulen{counit}.
\begin{align*}
x \substuck{t}{L}\sublock{L}{i}
:\defeq x[t/i]
\end{align*}
So if $x \defeq i$ the result is $t$, and otherwise the substitution
yields $x$ again.
If $x$ has several stuck counits, the operation needs to continue
into the associated terms. To simplify things a little, rather than
yielding an actual substitution we can immediately divide into cases
on whether the underlying variable is the one being `searched for'
by the \rulen{unit} rule.
\begin{align*}
&i \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyo{t}{L},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}}\sublock{L}{i} \\
:\defeq {}
&t\sublock{L}{i} \\
&x \stubra{\subkeyoe{j_1}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}}{\lockn{J}_{m}},
\subkeyo{t}{L},
\subkeyoe{k_1}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n}{\lockn{K}_n}} \\
:\defeq {}
&x\stubra{\subkeyoe{j_1\sublock{L}{i}}{\lockn{J}_1}, \dots,
\subkeyoe{j_{m}\sublock{L}{i}}{\lockn{J}_{m}},
\subkeyoe{k_1\sublock{L}{i}}{\lockn{K}_{1}},
\dots, \subkeyoe{k_n\sublock{L}{i}}{\lockn{K}_n}}
\end{align*}
% \begin{align*}
% &x \stubra{\subkeye{s_1}{\lockn{K}_1}, \dots,
% \subkeye{s_{i}}{\lockn{K}_{i}}, \subkey{t}{L}, \subkeye{s_{i+1}}{\lockn{K}_{i+1}},
% \dots, \subkeye{s_n}{\lockn{K}_n}}\sublock{L}{i} \\
% :\defeq {}
% &x[t\sublock{L}{i}/i]\admbra{\subkeye{s_1\sublock{L}{i}}{\lockn{K}_1}, \dots,
% \subkeye{s_{i}\sublock{L}{i}}{\lockn{K}_{i}}, \subkeye{s_{i+1}\sublock{L}{i}}{\lockn{K}_{i+1}},
% \dots, \subkeye{s_n\sublock{L}{i}}{\lockn{K}_n}}
% \end{align*}
% \begin{align*}
% (\varkey{L'}{t'} \varkeye{\lockn{K}_n}{s_n} \dots \varkeye{\lockn{K}_1}{s_1} x)[\sublock{L}{i}] &:\defeq \admkey{L'}{t'[\sublock{L}{i}]}(\varkeye{\lockn{K}_n}{s_n} \dots \varkeye{\lockn{K}_1}{s_1} x)[\sublock{L}{i}] \\
% (\varkey{L}{t} \varkeye{\lockn{K}_n}{s_n} \dots \varkeye{\lockn{K}_1}{s_1} x)[\sublock{L}{i}] &:\defeq (\varkeye{\lockn{K}_n}{s_n} \dots \varkeye{\lockn{K}_1}{s_1} x)[t[\sublock{L}{i}]/i] \\
% x[\sublock{L}{i}] &:\defeq x
% % (\admkey{L}{t} c) [a/x] &:\defeq \admkey{L}{t[a/x]} c[a/x] \\
% % (\varkey{L}{t} c)[\sublock{L}{i}] &:\defeq c[t[\sublock{L}{i}]/i] %\\
% % (\admkey{K}{t} c)[\sublock{L}{i}] &:\defeq
% % \admkey{K}{t[\sublock{L}{i}]} c[\sublock{L}{i}] &&\lockn{L}
% % \not\defeq \lockn{K}
% \end{align*}
In any application of the \rulen{unit} rule, the lock $\lockn{L}$
and the variable $i$ no longer appear in the resulting term
$a\sublock{L}{i}$.
\end{itemize}
% \begin{remark}
% To be careful, we should have proper calculus of telescopes
% $\Gamma \yields \Gamma' \tele$ that $-\subkey{t}{L}$
% and $-\sublock{L}{i}$ are defined on.
% \end{remark}
% \begin{remark}
% We do not have weakening by additional locks for arbitrary terms,
% but we do have a kind of lock weakening for closed terms:
% \begin{mathpar}
% \inferrule*[left=closed-lock-wk,fraction={-{\,-\,}-}]
% {\Gamma \yields \judge}
% {\ctxlock{L}, \Gamma \yields \judge}
% \end{mathpar}
% \end{remark}
These rules are peculiar, but if we insist on pushing the
admissible rules to the leaves I believe something like this is forced
on us by the setting we are trying to capture.
\subsection{Examples of Admissible Rules}
Some examples of applying keys to terms:
\begin{alignat*}{2}
&x : \NN, y : \NN
&&\yields x + y : \NN \\
&x : \NN, y : \NN, \ctxlock{L}, i : \Tiny
&&\yields (x + y)\subkey{i}{L} : \NN\subkey{i}{L} \\
&&&\defeq x\substuck{i}{L} + y\substuck{i}{L} : \NN \\
~\\
&x : \NN
&&\yields (\lambda y. x + y) : \NN \to \NN \\
&x : \NN,\ctxlock{L}, i : \Tiny
&&\yields (\lambda y. x + y)\subkey{i}{L} : (\NN \to \NN)\subkey{i}{L} \\
&&&\defeq (\lambda y. x\substuck{i}{L} + y) : \NN \to \NN \\
~\\
&A : \univ, B : A \to \univ, f : \prd{x : A} B(x)
&&\yields f : \prd{x : A} B(x) \\
&A : \univ, B : A \to \univ, f : \prd{x : A} B(x), \ctxlock{L}, i : \Tiny
&&\yields f\subkey{i}{L} : \left(\prd{x : A} B(x)\right)\subkey{i}{L} \\
&&&\defeq f\substuck{i}{L} : \prd{x : A\subkey{i}{L}} (B(x))\subkey{i}{L} \\
&&&\defeq f\substuck{i}{L} : \prd{x : A\substuck{i}{L}} (B\substuck{i}{L})(x)
\end{alignat*}
In this last example, $B\substuck{i}{L}$ has type
$A\substuck{i}{L} \to \univ$, so applying it to $x$ is well-formed.
Applying \rulen{counit} in various locations.
\begin{alignat*}{2}
&x : \NN,\ctxlock{K}, k : \Tiny
&&\yields a\substuck{k}{K} : \NN \\
&x : \NN,\ctxlock{K}, k : \Tiny, \ctxlock{L}, i : \Tiny
&&\yields a\substuck{k}{K} \subkey{i}{L} \\
&&&\defeq a\stubra{\subkeyo{k\subkey{i}{L}}{K}, \subkeyo{i}{L}} \\
&&&\defeq a\stubra{\subkeyo{k\substuck{i}{L}}{K}, \subkeyo{i}{L}} : \NN \\
~\\
&x : \NN, \ctxlock{K}, k : \Tiny
&&\yields a\substuck{k}{K} : \NN \\
&x : \NN, \ctxlock{K}, \ctxlock{L}, i : \Tiny, k : \Tiny
&&\yields a\substuck{k}{K} \subkey{i}{L} \\
&&&\defeq a\stubra{\subkeyo{k\subkey{i}{L}}{K}, \subkeyo{i}{L}} \\
&&&\defeq a\stubra{\subkeyo{k}{K}, \subkeyo{i}{L}} : \NN \\
~\\
&x : \NN, \ctxlock{K}, k : \Tiny
&&\yields a\substuck{k}{K} : \NN \\
&x : \NN, \ctxlock{L}, i : \Tiny, \ctxlock{K}, k : \Tiny
&&\yields a\substuck{k}{K} \subkey{i}{L} \\
&&&\defeq a\stubra{\subkeyo{i\subkey{k\subkey{i}{L}}{K}}{L}, \subkeyo{k}{K}} \\
&&&\defeq a\stubra{\subkeyo{i\subkey{k}{K}}{L}, \subkeyo{k}{K}} \\
&&&\defeq a\stubra{\subkeyo{i\substuck{k}{K}}{L}, \subkeyo{k}{K}}
\end{alignat*}
Applying \rulen{unit} in various locations:
\begin{alignat*}{2}
&t : \Tiny,\ctxlock{L}, i : \Tiny
&&\yields t\substuck{i}{L} : \Tiny \\
&i : \Tiny
&&\yields (t\substuck{i}{L})\sublock{L}{t} \\
&&&\defeq t[i/t] \\
&&&\defeq i : \Tiny \\
~\\
&x : A, i : \Tiny, \ctxlock{L}, j : \Tiny
&&\yields x\substuck{i\substuck{j}{L}}{L} : A \\
&x : A, j : \Tiny
&&\yields \left( x\substuck{i\substuck{j}{L}}{L} \right)\sublock{L}{i} \\
&&&\defeq x[i\substuck{j}{L}\sublock{L}{i}/i] \\
&&&\defeq x[i[j\sublock{L}{i}/i]/i] \\
&&&\defeq x[i[j/i]/i] \\
&&&\defeq x[j/i] : A
\end{alignat*}
Or even
\begin{alignat*}{2}
&i : \Tiny, \ctxlock{L}, j : \Tiny
&&\yields i\substuck{i\substuck{j}{L}}{L} : \Tiny \\
&j : \Tiny
&&\yields \left( i\substuck{i\substuck{j}{L}}{L} \right)\sublock{L}{i} \\
&&&\defeq i\substuck{j}{L}\sublock{L}{i} \\
&&&\defeq j\sublock{L}{i} \\
&&&\defeq j : \Tiny
\end{alignat*}
Nothing stops us from iterating this forever:
\begin{alignat*}{2}
&i : \Tiny, \ctxlock{L}, j : \Tiny
&&\yields
i\substuck{i\substuck{i\substuck{j}{L}}{L}}{L} : \Tiny
\end{alignat*}
Semantically, the context corresponds to $i : \Tiny \to \Tiny$ and
$j : \Tiny$, and the term is a version of the iterated application
$i(i(\dots i(j)))$. The lock substitution $\sublock{L}{i}$ then
replaces $i$ with the identity, and so the entire term reduces to $j$.
\iffalse
\begin{remark}
It feels a bit as though these keys are just delayed substitutions,
so let's try and make something interesting happen. Suppose we have
global elements $1, 2, 3, 4 : \Tiny$, and consider the function
\begin{align*}
f &: (\Tiny \times \Tiny) \to \rform{L} \rform{K} (\Tiny \times \Tiny) \\
f(x, y, \ctxlock{L}, \ctxlock{K}) &:\defeq (x\substuck{1}{L}\substuck{2}{K},y\substuck{3}{L}\substuck{4}{K})
\end{align*}
This can be evaluated in the following two different ways:
\begin{align*}
f(i, j, \rbind{i}, \rbind{j})
& \defeq (x\substuck{1}{L}\substuck{2}{K}, y\substuck{3}{L}\substuck{4}{K})[i/x][j/y][\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (i\substuck{1}{L}\substuck{2}{K}, j\substuck{3}{L}\substuck{4}{K})[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (i\substuck{1}{L}\substuck{2}{K}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}], j\substuck{3}{L}\substuck{4}{K}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}]) \\
& \defeq (1, 4)
\end{align*}
and
\begin{align*}
f(j, i, \rbind{i}, \rbind{j})
& \defeq (x\substuck{1}{L}\substuck{2}{K}, y\substuck{3}{L}\substuck{4}{K})[i/x][j/y][\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (j\substuck{1}{L}\substuck{2}{K}, i\substuck{3}{L}\substuck{4}{K})[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (j\substuck{1}{L}\substuck{2}{K}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}], i\substuck{3}{L}\substuck{4}{K}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}]) \\
& \defeq (2, 3)
\end{align*}
So the \emph{user} of a $\rformsym$ gets to choose which variable gets
substituted for, but doesn't get to choose the value that eventually
gets plugged in. And the values for the other $\key$s get completely
lost!
\end{remark}
\fi
\begin{remark}
It feels a bit as though these keys are just delayed substitutions,
so let's try and make something interesting happen. Suppose we have
global elements $1, 2, 3, 4 : \Tiny$, and consider a term
\begin{align*}
x : \Tiny, y : \Tiny, \ctxlock{L}, \ctxlock{K}
&\yields
(x\stubra{\subkeyo{1}{L},\subkeyo{2}{K}},y\stubra{\subkeyo{3}{L},\subkeyo{4}{K}})
: \Tiny \times \Tiny
\end{align*}
Applying two different substitutions allows us to select which of
the stuck keys to apply:
\begin{align*}
& (x\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}, y\stubra{\subkeyo{3}{L},\subkeyo{4}{K}})[i/x][j/y][\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (i\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}, j\stubra{\subkeyo{3}{L},\subkeyo{4}{K}})[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (i\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}], j\stubra{\subkeyo{3}{L},\subkeyo{4}{K}}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}]) \\
& \defeq (1, 4)
\end{align*}
and
\begin{align*}
& (x\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}, y\stubra{\subkeyo{3}{L},\subkeyo{4}{K}})[j/x][i/y][\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (j\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}, i\stubra{\subkeyo{3}{L},\subkeyo{4}{K}})[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}] \\
& \defeq (j\stubra{\subkeyo{1}{L},\subkeyo{2}{K}}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}], i\stubra{\subkeyo{3}{L},\subkeyo{4}{K}}[\rbind{i}/\ctxlock{L}][\rbind{j}/\ctxlock{K}]) \\
& \defeq (2, 3)
\end{align*}
Once we have the type former, we will be able to cause these
different substitutions to occur. So the \emph{user} of a term
containing stuck keys gets to choose which of the stuck keys is
eventually used, but doesn't get to choose the actual term that gets
plugged in. And the stored terms for the other keys are
completely lost!
\end{remark}
\subsection{Total Substitutions}
\newcommand{\wksub}[1]{\mathsf{w}(#1)}
\newcommand{\conjinv}[3]{\mathsf{inv}(#1, \lockn{#2}, #3)}
\newcommand{\varfunc}[1]{,\uparrow_{#1}}
\newcommand{\lockfunc}[1]{,\uparrow_{\lockn{#1}}}
Suppose that besides the ordinary substitution rules
\begin{mathpar}
\inferrule*{~}{\Gamma \yields \cdot : \cdot} \and
\inferrule*{\Gamma \yields \theta : \Delta \and \Gamma \yields a : A[\theta]}{\Gamma \yields (\theta, a/x) : \Delta, x : A} \and
\inferrule*{\Gamma \yields \theta : \Delta}{\Gamma, x : A \yields \wksub{\theta} : \Delta} \and
\inferrule*{\Gamma \yields \theta : \Delta \and \Delta \yields \theta' : \Xi}{\Gamma \yields (\theta' \circ \theta) : \Xi} \\
\inferrule*[fraction={-{\,-\,}-}]{\Gamma \yields \theta : \Delta}{\Gamma, x : A[\theta] \yields (\theta \varfunc{x}) : \Delta, x : A}
\end{mathpar}
we also have
\begin{mathpar}
\inferrule*{\Gamma, i : \Tiny \yields \theta : \Delta}{\Gamma \yields (\theta, i./\lockn{L}) : \Delta,\ctxlock{L}} \and
\inferrule*{~}{\Gamma, \ctxlock{L}, i : \Tiny \yields \counit{\Gamma}{L}{i} : \Gamma}
\end{mathpar}
From these, we can get functoriality, the unit substitution, and the inverse to the former rule
\begin{mathpar}
\inferrule*[fraction={-{\,-\,}-}]{\Gamma \yields \theta : \Delta}{\Gamma,\ctxlock{L} \yields \theta \lockfunc{L} : \Delta,\ctxlock{L}} \and
\inferrule*[fraction={-{\,-\,}-}]{~}{\Gamma \yields \unit{\Gamma}{i}{L} : \Gamma, i : \Tiny, \ctxlock{L}} \and
\inferrule*[fraction={-{\,-\,}-}]{\Gamma \yields \theta : \Delta,\ctxlock{L}}{\Gamma, i : \Tiny \yields \conjinv{\theta}{L}{i} : \Delta}
\end{mathpar}
defined by
\begin{align*}
\theta \lockfunc{L} &:\defeq (\theta \circ \counit{\Gamma}{L}{i}), i./\lockn{L} \\
\unit{\Gamma}{i}{L} &:\defeq (\id_\Gamma \varfunc{i}), i./\lockn{L} \\
\conjinv{\theta}{L}{i} &:\defeq \counit{\Delta}{L}{i} \circ (\theta \varfunc{i})
\end{align*}
The equations we need to assert are:
\begin{align*}
(\theta, i./\lockn{L}) \circ \theta' &\defeq (\theta \circ (\theta'\varfunc{i})), i./\lockn{L} \\
\wksub{\theta, i./\lockn{L}} &\defeq (\theta \circ (\wksub{\id_\Gamma} \varfunc{i})), i./\lockn{L} \\
% &\defeq (\theta, i./\lockn{L}) \circ \wksub{\id_\Gamma} \\
\theta \circ \counit{\Gamma}{L}{i} &\defeq \counit{\Delta}{L}{i} \circ (\theta \lockfunc{L} \varfunc{i}) \\
\counit{(\Gamma, j : \Tiny)}{L}{i} \circ (\unit{\Gamma}{i}{L} \varfunc{i}) &\defeq (\wksub{\id_\Gamma}, i/j)
\end{align*}
The last equation is one of the triangle identities. This other one:
\begin{align*}
(\counit{\Gamma}{K}{i} \lockfunc{L}) \circ \unit{\Gamma, \ctxlock{K}}{i}{L} &\defeq (\id_\Gamma \circ \counit{\Gamma}{K}{i}), i./\lockn{L}
\end{align*}
follows without being asserted separately, by expanding the definition of $-\lockfunc{L}$ and using the first equation.
% Let's expand the left side of the last one:
% \begin{align*}
% (\counit{\Gamma}{K}{i} \lockfunc{L}) \circ \unit{\Gamma, \ctxlock{K}}{i}{L}
% &\defeq ((\counit{\Gamma}{K}{i} \circ \counit{(\Gamma,\ctxlock{K},i)}{L}{j}), j./\lockn{L}) \circ \unit{\Gamma, \ctxlock{K}}{i}{L} \\
% &\defeq (\counit{\Gamma}{K}{i} \circ \counit{(\Gamma,\ctxlock{K},i)}{L}{j} \circ (\unit{\Gamma, \ctxlock{K}}{i}{L} \varfunc{j})), j./\lockn{L} \\
% \end{align*}
\section{Type}
The type former is now made right-adjoint to $\ctxlock{L}$ in the
`obvious' way, following the pattern of \cite{fitchtt}. My choice of
syntax for the term constructors may be where I lose the crowd, but I
will try to justify it in a minute.
% \begin{mathpar}
% \inferrule*[left=$\rformsym$-form]
% {\Gamma, \ctxlock{L} \yields A : \univ}
% {\Gamma \yields \rform{L} A : \univ} \and
% \inferrule*[left=$\rformsym$-intro]
% {\Gamma, \ctxlock{L} \yields a : A}
% {\Gamma \yields \rintro{L} a : \rform{L} A} \and
% \inferrule*[left=$\rformsym$-elim]
% {\Gamma, i : \Tiny \yields r : \rform{L} A}
% {\Gamma \yields \relim{i.r} : A\sublock{L}{i}} \\
% \relim{i.\rintro{L} a} \defeq a\sublock{L}{i} \and
% r \defeq \rintro{L}{\relim{i. r\subkey{i}{L}}}
% \end{mathpar}
\begin{mathpar}
\inferrule*[left=$\rformsym$-form]
{\Gamma, \ctxlock{L} \yields A : \univ}
{\Gamma \yields \rform{L} A : \univ} \and
\inferrule*[left=$\rformsym$-intro]
{\Gamma, \ctxlock{L} \yields a : A}
{\Gamma \yields \rintro{L} a : \rform{L} A} \and
\inferrule*[left=$\rformsym$-elim]
{\Gamma, i : \Tiny \yields r : \rform{L} A}
{\Gamma \yields r(\rbind{i}) : A\sublock{L}{i}} \\
(\rintro{L}{a})(\rbind{i}) \defeq a\sublock{L}{i} \and
r \defeq \rintro{L}{(r\subkey{i}{L}(\rbind{i}))}
\end{mathpar}
In words:
\begin{itemize}
\item \rulen{$\rformsym$-form} and \rulen{$\rformsym$-intro}: For any
`$\ctxlock{L}$-locked' term $a : A$, we can amazingly bind the lock
$\ctxlock{L}$ and form a term $\rintro{L} a : \rform{L} A$. The syntax
is intended to be reminiscent of an ordinary $\lambda$-binding.
Reading upwards, going under $\rform{L} - $ or $\rintro{L} -$ means
that all extant variables get locked by $\ctxlock{L}$, so every
future use of those variables in $a$ must have an attached
$-\substuck{t}{L}$ to be well formed.
If $A$ is a closed type, we will just write $\rformu A$ rather than
binding an unused lock name.
\item \rulen{$\rformsym$-elim}: If using an assumption $i : \Tiny$ we can
produce a term $r : \rform{L} A$, then we can amazingly apply $r$ to
the fresh $i$ to form $r(\rbind{i}) : A$. We are free to completely
ignore the new assumption $i$ in $r$ if we wish, just as a constant
function may ignore its argument.
The syntax is a bit insane: to keep the analogy with ordinary
function application, the variable $i$ is bound in the parentheses
on the right, but then is \emph{in scope in the body of the function
to the left}\footnote{If we took Lawvere
seriously~\cite{lawvere:adjointness-foundations} and wrote function
application as $xf$, then we would not have this problem!}.
\item \rulen{$\rformsym$-beta}: Amazingly binding a lock $\rintro{L} a$
and then amazingly applying it to $\rbind{i}$ reduces to
$a\sublock{L}{i}$, in perfect analogy with
$(\lambda x. b)(a) \defeq b[a/x]$.
\item \rulen{$\rformsym$-eta}: Any element $r : \rform{L} A$ is equal to
one where you immediately bind a lock and apply $r$ to it, in
analogy with $f \defeq (\lambda x. f(x))$.
\end{itemize}
\subsection{Basic Examples}
First, some maps that are easily definable from the rules. The functor
$\Tiny \to -$ is a monad, and its right adjoint $\rformu{}$
is therefore a comonad.
\begin{definition}
If $A$ is (for now) a closed type, define a counit map
$\varepsilon_A : \rformu{A} \to A$ by
\begin{align*}
\varepsilon_A &: \rformu{A} \to A \\
\varepsilon_A(r) &:\defeq r(\rbind{i})
\end{align*}
To get a term of $A$, we need a term of $\rformu{A}$ that we can
amazingly evaluate on an additional assumption $i : \Tiny$. But we
already have the variable $r : \rformu{A}$, so we have no
need to use the additional assumption.
\end{definition}
\begin{definition}