-
Notifications
You must be signed in to change notification settings - Fork 15
/
tones.tex
1617 lines (1309 loc) · 55.4 KB
/
tones.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{rntz}
%% Laptop-oriented 4:5 fantasy paper. Other options: tablet, phone.
\usepackage{fantasy}
\usepackage{rntzfont}
%% \usepackage[b5]{rntzgeometry}
%% \usepackage[fullwidth=15cm,width=345pt,width=365pt]{narrow}
%% \usepackage[scaled=1.0625]{rntzfont}
%% \usepackage[a5]{rntzgeometry}
%% \usepackage[fullwidth=140mm,width=115mm]{narrow}
%% \usepackage[scaled=1.01]{rntzfont}
%% \documentclass{article}
%% \usepackage[b5paper]{geometry}
%% \usepackage[dvipsnames]{xcolor}
%% \definecolor[named]{ACMBlue}{cmyk}{1,0.1,0,0.1}
%% \definecolor[named]{ACMYellow}{cmyk}{0,0.16,1,0}
%% \definecolor[named]{ACMOrange}{cmyk}{0,0.42,1,0.01}
%% \definecolor[named]{ACMRed}{cmyk}{0,0.90,0.86,0}
%% \definecolor[named]{ACMLightBlue}{cmyk}{0.49,0.01,0,0}
%% \definecolor[named]{ACMGreen}{cmyk}{0.20,0,1,0.19}
%% \definecolor[named]{ACMPurple}{cmyk}{0.55,1,0,0.15}
%% \definecolor[named]{ACMDarkBlue}{cmyk}{1,0.58,0,0.21}
%% \usepackage{amsmath,amsthm}
%% \usepackage{hyperref,url,cleveref}
%% \theoremstyle{definition}
%% \newtheorem{theorem}{Theorem}
%% \newtheorem{conjecture}[theorem]{Conjecture}
%% \newtheorem{lemma}[theorem]{Lemma}
%% \theoremstyle{definition}
%% \newtheorem{definition}[theorem]{Definition}
%% \theoremstyle{remark}
%% \newtheorem*{corollary}{Corollary}
%% \theoremstyle{plain} %back to default
%% ---- Packages ----
%\usepackage{adjustbox} % aligning tikz diagrams vertically w/ tables.
\usepackage{amsmath,amssymb} % basic math formatting & symbols
%\usepackage{anyfontsize} % avoid font size warnings from stmaryrd
\usepackage{booktabs} % \midrule
\usepackage{mathpartir} % \mathpar, \infer
\usepackage{mathtools} % for \dblcolon, \prescript
\usepackage{multirow} % \multirow, \multicolumn
\usepackage{stmaryrd} % \llbracket, \rrbracket, \oast
\usepackage{tikz,tikz-cd} % Hasse & commutative diagrams.
\usepackage[b]{esvect} % Wide vector via \vv.
\usepackage{nccmath} % Fix spacing issues.
%% vectors with subscripts. \vv* doesn't look quite right.
\newcommand{\vvsub}[2]{\vv*{#1}{\!#2}}
\usepackage[skip=.5\baselineskip,labelfont=it,textfont=it,labelsep=period,format=hang]{caption}
%\usepackage[skip=.5\baselineskip,labelfont=sc,labelsep=period,format=hang]{caption}
% List styling: No extra separation between items (aside from \parsep). Indent
% lists to match paragraph indentation.
\usepackage{enumitem}
\setlist{itemsep=0pt,labelindent=\parindent,leftmargin=*}
%\setlist{labelindent=0em,labelsep=.75em,leftmargin=*}
% typographic improvements
% TODO: put these in rntzfont.sty or rntz.cls?
\usepackage[spacing=true,stretch=15,tracking=true,letterspace=15]{microtype}
\frenchspacing
%% ---- Commands ----
\newcommand{\todo}[1]{{\color{Purple}#1}}
\newcommand{\fapremise}[1]{(\forall #1)~\,}
\newcommand{\bnfeq}{\dblcolon=}
%\newcommand{\bnfeq}{\ni}
\newcommand{\bnfcont}{}
\newcommand{\pipe}{~\,|\,~}
\newcommand{\mb}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\mi}[1]{\ensuremath{\mathit{#1}}}
\newcommand{\mc}[1]{\ensuremath{\mathcal{#1}}}
\newcommand\defeq{\triangleq}
\newcommand{\emptycx}{\varepsilon}
\newcommand{\G}{\Gamma}
\newcommand{\N}{\mathbb{N}}
\newcommand{\x}{\times}
\newcommand{\fn}{\lambda}
\newcommand{\binder}{.~}
\newcommand{\bind}[1]{{#1}\binder}
\newcommand{\fnof}[1]{\fn\bind{#1}}
\newcommand{\sub}[1]{\{{#1}\}}
\newcommand{\fix}{\textsf{fix}}
\newcommand{\den}[1]{\llbracket{#1}\rrbracket}
\newcommand{\subtype}{\le}
\newcommand{\ein}[2]{\textsf{in}_{#1}\:{#2}}
\newcommand{\cto}{\shortrightarrow}
\newcommand{\ecase}[1]{\mb{case}~{#1}~\mb{of}~\,}
%% Category & preorder theory
\newcommand{\cat}[1]{\textsc{#1}} %category name
\newcommand{\Pre}{\cat{preord}}
\newcommand{\Set}{\cat{set}}
\newcommand{\Tone}{\cat{tone}}
\newcommand{\Cat}{\cat{cat}}
\newcommand\idfn{\mi{id}}
\newcommand\isoto{\simeq}
\newcommand\pathto{\sim}
%% Tone functors. \textsf? \textrm? \textit? \textsc?
\newcommand\opcolor{\color{ForestGreen}}
\newcommand\isocolor{\color{NavyBlue}}
\newcommand\pathcolor{\color{Bittersweet}}
\newcommand\id{\ensuremath{\mathrm{id}}}
\newcommand\op{\ensuremath{\mathrm{\opcolor op}}}
\newcommand\iso{\texorpdfstring{\ensuremath{{\isocolor\Box}}}{iso}}
\renewcommand\path{\texorpdfstring{\ensuremath{{\pathcolor\lozenge}}}{path}}
\newcommand\idof[1]{\ensuremath{\id\,#1}}
\newcommand\opof[1]{\ensuremath{\op\,#1}}
\newcommand\isof[1]{\ensuremath{\iso #1}}
\newcommand\pathof[1]{\ensuremath{\path #1}}
\newcommand\tc{\circ} % tone composition
\newcommand\tmeet{\wedge} % tone meet
\newcommand\bigmeet{\bigwedge} % tone meet
%% TODO: get rid of \T.
\newcommand{\T}[1]{#1}
%% "moded" things: hypothesis, types, contexts. mode/tone comes first.
\newcommand{\mtp}[2]{\left[#1\right] #2}
\newcommand{\mcx}[2]{#1 #2}
\newcommand{\extend}[2]{{#1},\, {#2}}
\newcommand{\tpcolor}{}%\color{Green}}
\newcommand{\tmcolor}{}%\color{ACMDarkBlue}}
\newcommand{\cxcolor}{}%\color{ACMPurple}}
\newcommand{\strips}{\prec}
\newcommand{\uh}[2]{#1 : #2} % unmoded/toneless hypothesis
\newcommand{\h}[3]{\uh{#1}{\mtp{#2}{#3}}}
\newcommand{\infers}[3]{{\tmcolor#1} \Rightarrow {\cxcolor#2} \vdash {\tpcolor#3}}
\newcommand{\checks}[3]{{\tmcolor#1} \Leftarrow {\cxcolor#2} \vdash {\tpcolor#3}}
\newcommand{\mdist}[2]{#1 \equiv #2}
\newcommand{\mbinop}{\oast}
\newcommand{\adjoint}[2]{#1 \dashv #2}
%% \renewcommand{\infers}[3]{#2 \vdash #1 \Rightarrow #3}
%% \renewcommand{\checks}[3]{#2 \vdash #1 \Leftarrow #3}
%% \renewcommand{\infers}[3]{#1 \Rightarrow {#3} \dashv {#2}}
%% \renewcommand{\checks}[3]{#1 \Leftarrow {#3} \dashv {#2}}
%% \renewcommand{\extend}[2]{{#2},\, {#1}}
%% \renewcommand{\uh}[2]{#2\,#1}
%% ---- Front matter ----
\title{Tones and Types}
\author{{\scshape Michael Arntzenius}, %
\href{mailto:daekharel@gmail.com}{daekharel@gmail.com}}
% Date format: "25 March 2018"
\usepackage[en-GB]{datetime2}
\DTMlangsetup[en-GB]{ord=omit}
\date{\today}
\begin{document}
%% \makeatletter \noindent
%% baseline skip: \the\baselineskip\\
%% ex/em: \the\fontdimen5\font{} / \the\fontdimen6\font\\
%% \makeatother
\maketitle
\begin{abstract}
Certain properties of maps between preorders (e.g.\ preserving equivalence)
reduce to monotonicity with respect to an altered domain ordering. I dub such
alterations ``tones'', and explore their theory. I sketch a typed
$\lambda$-calculus of monotone functions, using tones to allow selective
non-mono\-tonicity.
\end{abstract}
\section{Preorders}
A preorder is a relation $a \le b$ satisfying:
\begin{enumerate}
\item \textbf{Reflexivity:} $a \le a$.
\item \textbf{Transitivity:} If $a \le b$ and $b \le c$ then $a \le c$.
\end{enumerate}
Preorders generalize partial orders by not requiring antisymmetry. Let
$a \equiv b$ iff $a \le b$ and $b \le a$. Antisymmetry means $a \equiv b$
implies $a = b$.
%
A good example preorder is ``lists under containment'', where $a \le b$ iff
every element of $a$ is also in $b$. Note that $[0,1] \equiv [1,0]$, but $[0,1]
\ne [1,0]$.
To a category theorist, a preorder is a ``thin'' category: between any two
objects there is at most one morphism. I suspect much of the ``tone theory'' in
this document, ostensibly about maps between preorders, extends to functors
between categories.
\section{Tones}\label{sec:tones}
Tones are ways a function $f$ may respect a preorder. I will consider four
tones: \id, \op, \iso{} (pronounced ``iso''), and \path{} (pronounced ``path'').
\begin{center}
\begin{tabular}{clc@{\hskip 0.25em}c@{\hskip 0.25em}c}
\multicolumn{1}{c}{\textit{Tone}}
& \multicolumn{1}{c}{\textit{Name}}
%% & \multicolumn{1}{c}{\textbf{Respects}}
& \multicolumn{3}{c}{\textit{Property of $f$}}
\\\midrule
\id & \text{Monotone}
%% & \text{ordering}
& $x \le y$ &$\implies$& $f(x) \le f(y)$
\\
\op & \text{Antitone}
%% & \text{opposite ordering}
& $x \ge y$ &$\implies$& $f(x) \le f(y)$
\\
\iso & \text{Invariant}
%% & \text{induced equivalence or ``isomorphisms''}
& $x \le y \wedge y \le x$ &$\implies$& $f(x) \le f(y)$
\\
\path & \text{Bivariant}
%% & \text{equivalence closure or ``paths''}
& $x \le y \vee y \le x$ &$\implies$& $f(x) \le f(y)$
\end{tabular}
\end{center}
\noindent Informally,
\begin{enumerate}
\item $\id$ is monotone (order-preserving).
\item $\op$ is antitone (order-inverting).
\item $\iso$ is invariant, preserving only equivalence.
\item $\path$ is bivariant: both monotone and antitone.
\end{enumerate}
%% In posets, antisymmetry trivializes invariance (because $x \le y \wedge y \le x
%% \implies x = y \implies f(x) = f(y)$), so we sometimes call $\iso$ the
%% ``discrete'' tone, because it respects only the discrete ordering.
\subsection{Tones transform orders}
Fix preorders $A, B$. Let $\opof A$ be $A$, ordered oppositely. Now, observe
that
%
\begin{center}
$f : A \to B$ is antitone
\nopagebreak \emph{iff} \nopagebreak
$f : \opof A \to B$ is monotone
\end{center}
So ``antitone'' is a special case of ``monotone''! This observation generalizes:
every tone is really monotonicity with a transformation applied to the domain's
ordering. So \textbf{tones transform orders}. I write $TA$ for
the preorder $A$ transformed by the tone $T$, defined:
\begin{center}
\begin{tabular}{clc@{\hskip 0.25em}c@{\hskip 0.25em}ll}
{\textit{Tone}}
& {\textit{Meaning}}
& \multicolumn{3}{c}{\textit{Transformation on $A$}}
\\\midrule
\id & \text{same ordering}
& $a \le b : A$ &$\iff$& $a \le b : \idof A$
\\
\op
& \text{opposite ordering}
& $a \ge b : A$ &$\iff$& $a \le b : \opof A$
\\
\iso
& \text{induced equivalence}
& $a \le b \wedge b \le a : A$ &$\iff$& $a \le b : \isof A$\\
\path{}
& \text{equivalence closure}
& $a \le b \vee b \le a : A$ &$\ \implies$& $a \le b : \pathof A$
%% & {\small\itshape see \ref{sec:defining-path}}
\end{tabular}
\end{center}
With this, we can state the theorem generalizing our observation:
\begin{theorem}[Tones transform orders]\label{thm:tones-transform-orders}%
%% For any function $f : A \to B$ between preorders $A$, $B$:
~\nopagebreak
\begin{center}
$f : A \to B$ has tone $T$
\nopagebreak\emph{iff}\nopagebreak
$f : TA \to B$ is monotone
\end{center}
\end{theorem}
From this point on, when I write $f : A \to B$, I mean implicitly that $f$ is
monotone; and therefore $f : TA \to B$ means that $f$ has tone $T$.
%
Here are a few more useful properties of tones, which I invite you to verify:
\begin{theorem}[Functoriality of tones]\label{thm:tone-functoriality}
If $f : A \to B$ then $f : TA \to TB$.
\end{theorem}
\begin{theorem}[Tones distribute over $\x$ and $+$]\label{thm:tones-monoidal}
\(T(A \x B) = TA \x TB\) and \(T(A + B) = TA + TB\), where $A \x B$ and $A +
B$ are the product and coproduct preorders respectively.
\end{theorem}
\subsection{Understanding tone transformations}
\begin{figure*}
\begin{mathpar}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node (a) at (0, 0) {a};
\node (b) at (.33, 1) {b};
\node (c) at (.67, 0) {c};
\node (d) at (1.33, 0) {e};
\node (e) at (1.33, 1) {d};
\draw [-Latex] (a) -- (b);
\draw [-Latex] (c) -- (b);
\draw [Latex-Latex] (d) -- (e);
\draw (-.4, -.4) -- (-.4, 1.4) -- (1.81, 1.4) -- (1.81, -.4) -- cycle;
\node [above] at (.705, 1.45) {$A = \idof A$};
\end{tikzpicture}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node (a) at (0, 0) {a};
\node (b) at (.33, 1) {b};
\node (c) at (.67, 0) {c};
\node (d) at (1.33, 0) {e};
\node (e) at (1.33, 1) {d};
\draw [-Latex] (b) -- (a);
\draw [-Latex] (b) -- (c);
\draw [Latex-Latex] (d) -- (e);
\draw (-.4, -.4) -- (-.4, 1.4) -- (1.81, 1.4) -- (1.81, -.4) -- cycle;
\node [above] at (.705, 1.45) {$\opof{A}$};
\end{tikzpicture}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node (a) at (0, 0) {a};
\node (b) at (.33, 1) {b};
\node (c) at (.67, 0) {c};
\node (d) at (1.33, 0) {e};
\node (e) at (1.33, 1) {d};
\draw [Latex-Latex] (d) -- (e);
\draw (-.4, -.4) -- (-.4, 1.4) -- (1.81, 1.4) -- (1.81, -.4) -- cycle;
\node [above] at (.705, 1.45) {$\isof A$};
\end{tikzpicture}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node (a) at (-.1, 0) {a};
\node (b) at (.35, 1) {b};
\node (c) at (.8, 0) {c};
\node (d) at (1.33, 0) {e};
\node (e) at (1.33, 1) {d};
\draw [Latex-Latex] (a) -- (b);
\draw [Latex-Latex] (b) -- (c);
\draw [Latex-Latex] (a) -- (c);
\draw [Latex-Latex] (d) -- (e);
\draw (-.48, -.4) -- (-.48, 1.4) -- (1.8, 1.4) -- (1.8, -.4) -- cycle;
\node [above] at (.66, 1.45) {$\pathof A$};
\end{tikzpicture}
\end{mathpar}
\caption{Tones applied to an example preorder}
\label{fig:tone-example}
\end{figure*}
\Cref{fig:tone-example} illustrates how each tone transforms the graph of a
simple preorder: $\idof A$ is identical to $A$; $\opof A$ inverts arrows'
directions; $\isof A$ isolates the strongly connected components of $A$; and
$\pathof A$ makes weakly connected components strong. Arrows in $\isof A$ and
$\pathof A$ are always bidirectional, as their preorders are symmetric (and thus
equivalence relations).
$\pathof{A}$ is a symmetric, transitive closure, the smallest preorder such that
\(a \le b \vee b \le a : A\) implies \(a \le b : \pathof{A}\).
%
Unlike every other tones' definition, this implication is not reversible. In
\cref{fig:tone-example}, for example, $\text{a} \le \text{c} : \pathof{A}$, but
$\text{a} \not\le \text{c} \wedge \text{c} \not\le \text{a} : A$.
\subsection{Tone operators}
\begin{figure*}
\begin{mathpar}
%% "baseline=(current bounding box.center)" incantation taken from
%% https://tex.stackexchange.com/questions/220531/how-to-align-tikzpicture-and-text-in-a-table/220543#220543
\begin{tikzpicture}[scale=1,baseline=(current bounding box.center)]
\node (top) at ( 0, 1) {$\path$};
\node (bot) at ( 0,-1) {$\iso$};
\node (-1) at (-1, 0) {$\id$};
\node (1) at ( 1, 0) {$\op$};
\draw (top) -- (-1) -- (bot) -- (1) -- (top);
\end{tikzpicture}
\begin{array}{r|cccc}
T \tmeet U
& \id & \path & \op & \iso\\\hline
\id & \id & \id & \iso & \iso\\
\path & \id & \path & \op & \iso\\
\op & \iso & \op & \op & \iso\\
\iso & \iso & \iso & \iso & \iso
\end{array}
\begin{array}{cr|cccc}
\multicolumn{2}{c|}{\multirow{2}{*}{$UT$}}
& \multicolumn{4}{c}{T}\\
&& \id & \op & \iso & \path\\\hline
\multirow{4}{*}{$U$}
& \id & \id & \op & \iso & \path\\
& \op & \op & \id & \iso & \path\\
& \iso & \iso & \iso & \iso & \path\\
& \path & \path & \path & \iso & \path
\end{array}
\end{mathpar}
\caption{Tone lattice, meet, and composition}
\label{fig:tone-ops}
\end{figure*}
\Cref{fig:tone-ops} defines two operators on tones:
\begin{enumerate}
\item Meet $T \tmeet U$ is the greatest lower bound in the lattice ordered $\iso
< \{\id, \op\} < \path$. This finds the tone of the pairing $\langle f, g\rangle
: (T \tmeet U)A \to B \times C$ of two functions $f : TA \to B$ and $g : UA
\to C$.
%% TODO: Double-check the ordering of tone composition I use everywhere.
\item Composition $UT$ gives the tone of a composed function $g \circ f : UTA
\to C$ when $f : TA \to B$ and $g : UB \to C$. Equivalently, $(UT)A = U(TA)$
for any preorder $A$.
\end{enumerate}
I sometimes write $TU$ as $T \tc U$ for clarity. Composition binds tighter than
meet, so $TU \tmeet V = (T \circ U) \tmeet V$.
%
Together, $\tmeet$ and $\tc$ form a semiring whose properties are given in
\cref{fig:tone-op-laws}.
%% TODO: check the distribution laws hold.
%% TODO: Reference all those other works with semiring annotations.
\begin{figure*}
\begin{mathpar}
\begin{array}{lr@{\hskip 0.5em}c@{\hskip 0.5em}l}
\multicolumn{4}{c}{\textit{\normalsize Properties of ${}\tmeet{}$}}
\vspace{2pt}\\
\text{Associativity} & (T \tmeet U) \tmeet V &=& T \tmeet (U \tmeet V)\\
\text{Commutativity} & T \tmeet U &=& U \tmeet T\\
\text{Idempotence} & T \tmeet T &=& T\\
\path~\text{is identity} & \path \tmeet T &=& T\\
\iso~\text{absorbs} & \iso \tmeet T &=& \iso\\
\end{array}
\begin{array}{lr@{\hskip 0.5em}c@{\hskip 0.5em}l}
\multicolumn{4}{c}{\textit{\normalsize Properties of ${}\tc{}$}}
\vspace{2pt}\\
\text{Associativity} & (TU)V &=& T(UV)\\
\text{Identity} & \multicolumn{3}{c}{\id \tc T = T = T \tc \id}\\
\path~ \text{right-absorbs} & T\path &=& \path\\
\iso~ \text{right-absorbs} & T\iso &=& \iso\\
\op~ \text{involutive} & \op \tc \op &=& \id\\
\end{array}
\begin{array}{lr@{\hskip 0.5em}c@{\hskip 0.5em}l}
\text{Left distribution} & T (U \tmeet V) &=& TU \tmeet TV\\
\text{Right distribution} & (T \tmeet U) V &=& TV \tmeet UV
\end{array}
\end{mathpar}
\caption{Properties of tone operators}
\label{fig:tone-op-laws}
\end{figure*}
%% TODO: maybe have a section talking about related work:
%% 1. coeffects / graded comonads
%% 2. context-constrained-computing
%% 3. monotonicity types
%%
%% and then also mention all those works that use semiring annotations.
%% \subsection{Monotonicity Types}
%% \href{https://infoscience.epfl.ch/record/231867/files/monotonicity-types.pdf}{\emph{Monotonicity
%% Types}} by Clancy, Miller, and Meiklejohn has similar tables for their
%% composition $\circ$ and ``contraction'' $+$ operators! However, instead of
%% bivariance they have constancy, a stricter condition.
%% %
%% Constancy corresponds to respecting the \emph{indiscrete ordering} (which sets
%% $a \le b$ for all $a,b$).\footnote{Indiscreteness and its dual, discreteness,
%% are also tones --- that is, functorial transformations on the ordering
%% component of a preorder --- but they complicate things, so I omit them.
%% Note also that discreteness and $\iso$ coincide on posets; many intuitions
%% transfer from one to the other.}
%% %
%% Interestingly, because constancy is so much stricter than bivariance, their
%% composition operator is commutative.
%% They write $\uparrow$ for $\id$, $\downarrow$ for $\op$, $?$ for $\iso$, and
%% $\sim$ for constancy. They also add $=$ for the ``tone'' that \emph{only the
%% identity function} has. This doesn't fit my framework; it cannot be phrased as
%% a transformation on orderings. However, it seems related to subtyping.
\section{Semantics of tones}
\newcommand{\elems}[1]{\ensuremath{|{#1}|}}
\newcommand{\elemsfn}[0]{\elems{-}}
%% \renewcommand{\elemsfn}{\mathbold{E}}
%% \renewcommand{\elems}[1]{\elemsfn(#1)}
Let's change perspective. \Cref{sec:tones} defines tones as function
pro\-per\-ties, then gives corresponding pre\-order trans\-form\-ations. Now,
let's define tones as preorder transformations, and derive corresponding
function properties.
\begin{definition}
$\elemsfn : \Pre \to \Set$ is the functor taking a preorder to its set of
elements.
\end{definition}
\begin{definition}[Tones]\label{def:tone}
A tone is a functor $T : \Pre \to \Pre$ such that $\elems{T-} =
\elemsfn$.\footnote{A more categorical approach might require only a natural
isomorphism \(\iota : \elems{T-} \isoto \elemsfn\). I'm not yet comfortable
generalizing that far.} That is, for any preorder $A$ and monotone map $f$,
\begin{enumerate}
\item $\elems{TA} = \elems{A}$: tones alter a preorder's
\emph{ordering}, not its elements.
\item $\elems{Tf} = \elems{f}$: tones do not alter functions'
behavior.
\end{enumerate}
\end{definition}
%% We say a function $f$ from $A$ to $B$ has tone $T$ iff $f : TA \to B$ is
%% monotone.
%% It's also unclear how to generalize this definition to tones of functors on
%% \Cat{}.
%% \subsection{Tone composition}
\begin{theorem}
Tones are closed under functor composition.
\end{theorem}
\begin{proof} Applying \cref{def:tone}, we have
\( \elems{U(T-)} = \elems{T-} = \elemsfn \).
\end{proof}
\subsection{The tone lattice}
Preorders have a natural \emph{subpreorder} relationship, $A \subtype B$, given
by:
\begin{align*}
A \subtype B
&\iff {\le_A} \subseteq {\le_B}
\\ &\iff \fnof{x} x : A \to B
\\ &\iff A \subseteq B \wedge \forall(x,y)~ x \le y : A \implies x \le y : B
\end{align*}
\noindent This lifts pointwise to a partial order on tones:
\[ T \le U \iff (\forall A)~ TA \subtype UA \]
\newcommand{\setfor}[2]{\{#1 ~|~ #2\}}
\begin{theorem}\label{thm:subpreorder-lattice}
Preorders over a set $A$ form a lattice.
\end{theorem}
\begin{proof}
Let $P,Q,R \subseteq A \x A$ stand for preorder relations on $A$. Let $S^*$ be
the transitive closure of $S$. Then our preorder lattice is given by:
\begin{align*}
P \wedge Q &= P \cap Q & \bot &= \setfor{(x,x)}{x \in A} \\
P \vee Q &= (P \cup Q)^* & \top &= A \x A
\end{align*}
By construction, $\bot$ is the least preorder; $\top$ the greatest; $P \wedge
Q$ the greatest lower bound of $P, Q$; and $P \vee Q$ their least upper bound
(as the least transitive relation such that $P \cup Q \subseteq P \vee
Q$).\footnote{Interestingly, this lattice is not distributive. Let $A =
\{1,2,3,4\}$ and consider the preorders $P = \{1 < 2 < 4\}$, $Q = \{1 <
3\}$, and $R = \{3 < 4\}$. Then $P \wedge (Q \vee R) = \{1 < 4\}$ but $(P
\wedge Q) \vee (P \wedge R)$ is discrete. \todo{TODO: is there a
counterexample for the other distributive law?}}
\end{proof}
\begin{theorem}
Tones form a lattice.\footnote{Since the preorder lattice is not distributive,
I expect that the tone lattice isn't either, but have yet to find a
counterexample.}
\end{theorem}
\begin{proof}
Since tones are ordered pointwise, they inherit the lattice on preorders from
\cref{thm:subpreorder-lattice}, so long as the lattice operations
are functorial. Restating their definitions in logical notation, given tones
$T,U$, the tone functors $\bot$, $\top$, $T \wedge U$, and $T \vee U$
construct the smallest preorders satisfying:
\begin{align*}
x \le y : \bot A &\iff x = y\\
x \le y : \top A &\iff \top\\
x \le y : (T \wedge U)A &\iff x \le y : TA \wedge x \le y : UA\\
x \le y : (T \vee U)A &\impliedby\hspace{2.5pt} x \le y : TA \vee x \le y : UA
\end{align*}
$\bot$ and $\top$ are functorial because \emph{all} maps $\bot A \to \bot B$
or $\top A \to \top B$ are monotone. $T \wedge U$ is functorial \todo{by
functoriality of $T$, $U$, and $\wedge$}.
%
$T \vee U$ is functorial as follows:
%
Suppose $f : A \to B$. We wish to show $f : (T \vee U)A \to (T \vee U)B$.
Suppose $x \le y : (T \vee U)A$. Since $(T \vee U)A$ is a transitive closure,
there exists a path $x_0, ..., x_n$ such that $x_0 = x$, $x_n = y$, and $x_i
\le x_{i+1} : TA \vee x_i \le x_{i+1} : UA$. Fix $i$. Without loss of
generality, let $x_i \le x_{i+1} : TA$. Then $f(x_i) \le f(x_{i+1}) : TA$ by
functoriality of $T$. Thus $f(x_i) \le f(x_{i+1}) : (T \vee U)A$. By
transitivity $f(x) \le f(y) : (T \vee U)A$.
\end{proof}
\begin{conjecture}
The syntactic definitions of $\tmeet$ and $\tc$ in \cref{fig:tone-ops} agree
with their semantic counterparts when applied to $\id$, $\op$, $\path$, and
$\iso$.
\end{conjecture}
\subsection{The \Tone{} category}
%% Preorders have a natural partial order, letting $A \le B$ iff $A$ is a
%% \emph{subpreorder} of $B$ --- that is, if $\fnof{x} x : A \to B$.\footnote{In
%% other words, if $A \subseteq B$ and $x \le y : A \implies x \le y : B$.}
%% %
%% This lifts pointwise to a partial order on tones: let $T \le U$ iff
%% $TA \le UA$ for all $A$.
%% %
Let \Tone{} be the category whose objects are tones and whose morphisms are
natural transformations. \Tone{} is isomorphic to the tone lattice:
\begin{theorem} \label{thm:tone-poset} The following are equivalent:
\[T \le U \iff \exists \eta : \Tone(T, U) \iff \exists! \eta : \Tone(T,U)\]
\end{theorem}
\begin{proof}
Expanding definitions, $T \le U$ means $\fnof{x} x : TA \to
UA$ for all $A : \Pre$. By \cref{lem:tone-transformations-are-id},
any $\eta : \Tone(T,U)$ is of the form $\eta_A = \fnof{x} x : TA
\to UA$.
\end{proof}
The crux here is that natural transformations between tones are \emph{boring}:
\begin{lemma}\label{lem:tone-transformations-are-id}
For any natural transformation $\eta : T \to U$, we have $\eta_A = \fnof{x}
x$.
\end{lemma}
\begin{proof}
Let $\mb{1}$ be the singleton preorder $\{\star\}$. Fix some $x : A$. Let $f :
\mb{1} \to A = \fnof{\star}{x}$. Then by naturality of $\eta$, this square
commutes:
%
\[\tikzset{
no line/.style={draw=none,
commutative diagrams/every label/.append style={/tikz/auto=false}}}
\begin{tikzcd}[sep=3.3em]
\mb{1} \arrow[r,"\textstyle \eta_{\mb{1}}"] \arrow[d,"\textstyle Tf"]
& \mb{1} \arrow[d,"\textstyle Uf"]
\\ TA \arrow[r,"\textstyle\eta_A"]
& UA
\end{tikzcd}\]
From \cref{def:tone}, $Tf = f = Uf$; and since $\mb{1}$ is
a singleton, $\eta_{\mb{1}} = \idfn$, thus:
\[\begin{array}{rlcl}
& \eta_A \circ Tf &=& Uf \circ \eta_{\mb{1}}\\
\implies & \eta_A \circ f &=& f\\
\implies & \eta_A(x) &=& x
\end{array}\]
\end{proof}
\section{An aside on overline notation}
%% TODO: determine whether to use overbar or (E(i))_i notation.
\newcommand{\xbar}[2]{{\overline{#2}^{\hspace{.5pt}#1}}}
%\renewcommand{\xbar}[2]{\prescript{#1}{}{\vv{#2}}}
%\renewcommand{\xbar}[2]{{\color{blue}{\left(#2\right)}_{#1}}}
\newcommand{\Expr}{\Phi}
\newcommand{\Ix}[1]{#1}
\newcommand{\Ex}{{x}}
\newcommand{\Ay}{{A}}
An overlined and superscripted meta-expression $\xbar{i}{\Expr(i)}$ represents a
sequence (of unspecified length) indexed by $i$. The index $i$ clarifies which
bits are repeated \emph{with variation}, and which \emph{without}. For example:
\begin{center}
\begin{tabular}{ccl}
$\xbar{\Ix{i}}{\Ex_{\Ix{i}} : \Ay_{\Ix{i}}}$
& stands for
& $\Ex_{\Ix{1}} : \Ay_{\Ix{1}},\, \Ex_{\Ix{2}} : \Ay_{\Ix{2}},\, ...,\, \Ex_{\Ix{n}} : \Ay_{\Ix{n}}$
\vspace{.5em}\\
$\xbar{\Ix{i}}{\Ex_{\Ix{i}} : \Ay}$
& stands for
& $\Ex_{\Ix{1}} : \Ay,\hspace{0.6em} \Ex_{\Ix{2}} : \Ay,\hspace{0.6em} ...,\, \Ex_{\Ix{n}} : \Ay$
\end{tabular}
\end{center}
This resembles the usual notation for sums of sequences, but with the bounds
left implicit. For example, $\sum_{i} x_i y^i$ can be written
$\sum\xbar{i}{x_iy^i}$ if we take $\sum$ to be a function from sequences of
numbers to numbers.%
%
\footnote{This convention is inspired by Guy Steele's talk on Computer Science
Metanotation. There are videos of the talk at
\href{https://www.youtube.com/watch?v=dCuZkaaou0Q}{Clojure/conj 2017},
\href{https://www.youtube.com/watch?v=7HKbjYqqPPQ}{PPoPP 2017}, and
\href{https://www.youtube.com/watch?v=8fCfkGFF7X8&feature=youtu.be&t=37m46s}{Harvard
University}. There are also
\href{http://s3.amazonaws.com/erlang-conferences-production/media/files/000/000/755/original/Guy_L._Steele_-_A_Cobbler's_Child.pdf?1510053539}{slides
from Code Mesh 2017}.}
\section{A bidirectional \texorpdfstring{$\lambda$}{lambda}-calculus with tone inference}
\begin{figure}
\begin{mathpar}
\mcx{T}{\xbar{i}{\mtp{U_i}{A_i}}} = \xbar{i}{\mtp{TU_i}{A_i}}\\
\infer[Hypothesis]{T \le \id}{\extend{\G}{\mtp{T}{A}} \vdash A}
\infer[$T$-Right]{\G \vdash A}{\mcx{T}{\G} \vdash \T{T} A}
\infer[$T$-Left]
{\extend{\G}{\mtp{TU}{A}} \vdash C}
{\extend{\G}{\mtp{T}{\T{U}A}} \vdash C}
\infer[Weakening]{U \le T \\ \extend{\G}{\mtp{T}{A}} \vdash C}
{\extend{\G}{\mtp{U}{A}} \vdash C}
\infer[Contraction]
{\extend{\G}{\mtp{T}{A},\, \mtp{U}{A}} \vdash C}
{\extend{\G}{\mtp{T \tmeet U}{A}} \vdash C}
\infer[Cut]{\G \vdash A \\ \extend{\Delta}{\mtp{T}{A}} \vdash C}
{\extend{\mcx{T}{\G}}{\Delta} \vdash C}
\end{mathpar}
\caption{Tonal sequent calculus}
\label{fig:tonal-sequent-calculus}
\end{figure}
\begin{figure*}
\[\begin{array}{rcclr}
\text{variables} & x\vspace{1pt}\\
\text{base types} & P
\vspace{0.5em}\\
\text{tones} & T,U,V & \bnfeq & \id \pipe \op \pipe \path \pipe \iso
\vspace{1pt}\\
\text{cartesian ops} & \mbinop &\bnfeq& {+} \pipe {\x}
\vspace{1pt}\\
\text{types} & A,B,C
&\bnfeq& P \pipe \isof{A} \pipe \opof{A} \pipe A \to B \pipe A \mbinop B
\vspace{0.5em}\\
\text{inferred terms} & e
&\bnfeq& x \pipe e\;m \pipe \pi_i\;e \pipe m : A \vspace{1pt}\\
\text{checked terms} & m,n
&\bnfeq& e \pipe \fnof{x} m \pipe (m,n) \pipe \ein{i}{m}\\
&&\bnfcont& \mb{let}~x = e~\mb{in}~ m\\
&&\bnfcont& \ecase{e} \xbar{i}{\ein{i}{x} \cto m_i}
\vspace{0.5em}\\
\text{contexts} & \G
&\bnfeq& \emptycx \pipe \extend{\G}{\h{x}{T}{A}}
%% \vspace{1pt}\\
%% \text{judgments} & J
%% &\bnfeq& \checks{m}{\G}{A} & \text{type checking}\\
%% &&\bnfcont& \infers{e}{\G}{A} & \text{type inference}\\
%% &&\bnfcont& \adjoint{T}{U} \pipe T \le U & \text{tone relations}
%% \\
%% &&\bnfcont& \mtp{T}{A} \subtype B
%% \pipe \mtp{T}{A} \strips B
%% & \text{subtyping}
\end{array}\]
\caption{Syntax for the bidirectional tonal $\lambda$-calculus}
\label{fig:tonal-lambda-calculus}
\end{figure*}
\begin{figure}
\begin{mathpar}
\infer[Type Checking]{\checks{m}{\G}{A}}{}
\infer[Type Inference]{\infers m \G A}{}
\infer[Tone Adjunction]{\adjoint T U}{}
\infer[Subtoning]{T \le U}{}
\infer[Subtyping]{\mtp{T}{A} \subtype B}{}
\infer[Mode Stripping]{\mtp{T}{A} \strips B}{}
\end{mathpar}
\caption{Typing judgments for the tonal $\fn$-calculus}
\label{fig:judgments}
\end{figure}
\Cref{fig:tonal-sequent-calculus} gives rules\footnote{Sent to me by Jason
Reed.} for a tonal sequent calculus with a type $\T{T} A$ representing the
tone functor $T$ applied to the type $A$. I adapt this into a tonal
$\lambda$-calculus with bidirectional type inference. I give its syntax in
\cref{fig:tonal-lambda-calculus} and its typing judgment forms in
\cref{fig:judgments}. \todo{TODO: explain my various abuses of notation, e.g.
$\mcx{T}{\G}$ and $\G_1 \tmeet \G_2$.}
\subsection{Typing rules}
\subsubsection{Inferred forms}
%
\begin{mathpar}
%% ---- inferring forms ----
%% checking -> inferring by annotation
\infer{\checks{m}{\G}{A}}{\infers{m : A}{\G}{A}}
%% variables
\infer{ }{\infers{x}{\h{x}{\id}{A}}{A}}
%% projection
\infer{\infers{e}{\G}{A} \\ \mtp{T}{A} \strips B_1 \x B_2}
{\infers{\pi_i\;e}{\mcx{T}{\G}}{B_i}}
%% application
\infer{\infers{e}{\G_1}{A}
\\ \mtp{T}{A} \strips B \to C
\\ \checks{m}{\G_2}{B}}
{\infers{e\; m}{\mcx{T}{\G_1} \tmeet \G_2}{C}}
\end{mathpar}
\subsubsection{Checking forms}
%
\begin{mathpar}
%% ---- checking forms ----
%% inferring -> checking by subtyping
\infer{\infers{e}{\G}{A} \\ \mtp{T}{A} \subtype B}
{\checks{e}{\mcx{T}{\G}}{B}}
%% mode introduction
\infer{\checks{m}{\G}{A} \\ T \in \{\iso,\op\}}
{\checks{m}{\mcx{T}{\G}}{\T{T} A}}
%% let-binding
\infer{\infers{e}{\G_1}{A} \\ \checks{m}{\extend{\G_2}{\h{x}{T}{A}}}{C}}
{\checks{\mb{let}~x = e~\mb{in}~m}{\mcx{T}{\G_1} \tmeet \G_2}{C}}
%% lambdas
\infer{\checks{m}{\extend{\G}{\h{x}{T}{A}}}{B} \\ \id \le T}
{\checks{\fnof{x} m}{\G}{A \to B}}
%% pairs
\infer{\checks{m}{\G_1}{A_1} \\ \checks{n}{\G_2}{A_2}}
{\checks{(m,n)}{\G_1 \tmeet \G_2}{A_1 \x A_2}}
%% injection
\infer{\checks{m}{\G}{A_i}}
{\checks{\ein{i}{m}}{\G}{A_1 + A_2}}
%% case analysis
\infer{\infers{e}{\G}{A} \\
\mtp{T}{A} \strips B_1 + B_2 \\
\fapremise{i}
\checks{m_i}{\extend{\G_i}{\h{x}{U_i}{B_i}}}{C}}
{\checks{\ecase{e} \xbar{i}{\ein{i}{x} \cto m_i}}
{\textstyle\bigmeet_i\left( \mcx{U_iT}{\G} \tmeet \G_i \right)}
{C}}
\end{mathpar}
\subsection{Tone judgments}
\todo{TODO: Explain judgment $T \le U$, for tone ordering, and $\adjoint{T}{U}$,
for tone adjunction.}
%
\begin{mathpar}
\adjoint{\id}{\id}
\adjoint{\op}{\op}
\adjoint{\path}{\iso}
\infer{}{T \le T}
\infer{}{\iso \le T}
\infer{}{T \le \path}
\end{mathpar}
\subsection{Subtyping}
\todo{TODO: Explain why we use tone-annotated subtyping.}
\todo{TODO: Explain the intended algorithmic reading here. Note that we
case-analyse both $A$ and $B$, and argue that the order we apply the rules in
shouldn't matter. Eventually I'll want to prove soundness (wrt semantics) \&
completeness (wrt some more declarative system).}
\newcommand{\focus}[1]{{\color{Rhodamine}#1}}
In $\mtp{T}{A} \subtype {B}$, the types $A$ and $B$ are inputs, and the tone $T$
is output. In each rule I've marked the connective being analysed in
\focus{pink}.
%
\begin{mathpar}
\infer[refl]{}{\mtp{\id}{A} \subtype {A}}
\infer[t-right]
{\mtp{T}{A} \subtype B}
{\mtp{UT}{A} \subtype \T{\focus{U}} B}
\infer[t-left]
{\mtp{T}{A} \subtype B \\ \adjoint{U}{V}}
{\mtp{TU}{\T{\focus{V}} A} \subtype B}
%% Products and sums
\infer[cartesian distribution]
{\mtp{T}{A_1} \subtype A_2 \\ \mtp{U}{B_1} \subtype B_2}
{\mtp{T \tmeet U}{A_1 \mathop{\focus\mbinop} B_1}
\subtype A_2 \mathop{\focus\mbinop} B_2}
\end{mathpar}
The semantic justification for \textsc{t-left} is as follows.
%
Note that $\fnof{x} x : VA \to VA$. Applying $U \dashv V$ we have $\fnof{x} x :
UVA \to A$, thus $UVA \le A$, and so finally $TUVA \le TA \le B$. \todo{Clean up
this explanation. Explain that we use adjunction rather than $TU \le \id$
directly because adjunction gives us the \emph{most informative} result; $TU
\le \id$ is declarative, $\adjoint{T}{U}$ is algorithmic. Give explanations
for each other rule as well.}
Function subtyping, $\mtp{T}{A_1 \mathrel{\focus{\to}} B_1} \subtype A_2
\mathrel{\focus{\to}} B_2$, has four rules, one for each tone $T$ produced by
$\mtp{T}{B_1} \subtype B_2$:
%
\begin{mathpar}
\infer{\id \le T \\ \mtp{T}{A_2} \subtype A_1 \\ \mtp{\id}{B_1} \subtype B_2}
{\mtp{\id}{A_1 \to B_1} \subtype A_2 \to B_2}
\infer{\op \le T \\ \mtp{T}{A_2} \subtype A_1 \\ \mtp{\op}{B_1} \subtype B_2}
{\mtp{\op}{A_1 \to B_1} \subtype A_2 \to B_2}
\infer{\path T = \path \\ \mtp{T}{A_2} \subtype A_1 \\ \mtp{\path}{B_1} \subtype B_2}
{\mtp{\path}{A_1 \to B_1} \subtype A_2 \to B_2}
\infer{\mtp{\path}{A_2} \subtype A_1 \\ \mtp{\iso}{B_1} \subtype B_2}
{\mtp{\iso}{A_1 \to B_1} \subtype A_2 \to B_2}
\end{mathpar}
The premise $\path T = \path$ of the third rule holds for $T \ne \iso$ in our system;
however, $\path T = \path$ captures more exactly \emph{why} the rule is valid.
\todo{TODO: Give proofs each of these rules are valid.}
%% This forms a Kleene algebra, with T* = id ∧ T. Laws:
%%
%% 1. T* = id ∧ TT* holds!
%% 2. T∧T = T holds!
%% 3. UT∧T=T implies U*T∧T = T holds!
%% 4. TU∧T=T implies TU*∧T = T holds!
%%
%% T* = □ is also a *-semiring, but not a Kleene algebra.
%%
%% Does (∨,∘) form a semiring? A Kleene algebra?
%%