-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tex
242 lines (213 loc) · 4.55 KB
/
main.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
\documentclass[11pt]{article}
\usepackage[top=2cm,bottom=2cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{url}
\usepackage{hyperref}
\usepackage{xcolor}
%
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{ifthen}
\usepackage{mathpartir}
\usepackage{mathtools}
\input{macros}
%
\begin{document}
\title{CO663 \LaTeX\ template}
\date{\vspace{-5ex}}
\maketitle
% \pagenumbering{gobble}
\newcommand{\answerbox}[1]{\framebox{\parbox[c][#1]{\textwidth}{
\color{white}{h}%
}}}
\section{Syntax and typing rules (for language $\lggeE$)}
\subsection{Syntax}
There is \LaTeX\ macro for each construct, see the sources of the
table below.
\[
\begin{array}{llclll}
\TYPES & \tau & \Coloneqq & \enum{} & \enum{} & \text{numbers}
\\
&&& \estr{} & \estr{} & \text{strings}
\\
\\
%
\EXPS & e & \Coloneqq & \var{x} & \var{x} & \text{variable}
\\
&&& \enum{n} & n & \text{numeral}
\\
&&& \estr{s} & \litstr{s} & \text{literal}
\\
&&& \eplus{e_1}{e_2} & e_1 {+} e_2 & \text{addition}
\\
&&& \etimes{e_1}{e_2} & e_1 {*} e_2 & \text{multiplication}
\\
&&& \ecat{e_1}{e_2} & e_1 \concat e_2 & \text{concatenate}
\\
&&& \elen{e} & \lvert e \rvert & \text{length}
\\
&&& \elet{e_1}{x}{e_2} & \clet{e_1}{x}{e_2} & \text{definition}
\end{array}
\]
\subsection{Typing rules}
The macro for typing judgement is called \texttt{tyjudge}, it takes
three arguments: the environment $\Gamma$, the expression being typed
$e$, and its type $\tau$.
%
The macro to type-set typing rules (and trees) is called
\texttt{tyrule}, it also takes three arguments: the name of the rule,
the premises (separated by $\backslash\backslash$ or
$\backslash$\texttt{and}), and the conclusion.
\[
\tyrule
{\etyrulename{var}}
{\,}
{\tyjudge{\Gamma_1, \var{x}: \tau, \Gamma_2}{\var{x}}{\tau} }
\]
\[
\tyrule
{\etyrulename{str}}
{\,}
{\tyjudge{\Gamma}{\estr{s}}{\estr{}}}
\qquad\qquad\qquad
\tyrule
{\etyrulename{num}}
{\,}
{\tyjudge{\Gamma}{\enum{n}}{\enum{}}}
% \end{array}
\]
\[
\tyrule
{\etyrulename{plus}}
{
\tyjudge{\Gamma}{e_1}{\enum{}}
\and
\tyjudge{\Gamma}{e_2}{\enum{}}
}
{\tyjudge{\Gamma}{\eplus{e_1}{e_2}}{\enum{}}}
\qquad\qquad\qquad
\tyrule
{\etyrulename{times}}
{
\tyjudge{\Gamma}{e_1}{\enum{}}
\and
\tyjudge{\Gamma}{e_2}{\enum{}}
}
{\tyjudge{\Gamma}{\etimes{e_1}{e_2}}{\enum{}}}
%
\]
\[
\tyrule
{\etyrulename{cat}}
{
\tyjudge{\Gamma}{e_1}{\estr{}}
\and
\tyjudge{\Gamma}{e_2}{\estr{}}
}
{\tyjudge{\Gamma}{\ecat{e_1}{e_2}}{\estr{}}}
\qquad\qquad\qquad
\tyrule
{\etyrulename{len}}
{
\tyjudge{\Gamma}{e}{\estr{}}
}
{\tyjudge{\Gamma}{\elen{e}}{\enum{}}}
\]
\[
\tyrule
{\etyrulename{let}}
{
\tyjudge{\Gamma}{e_1}{\tau_1}
\and
\tyjudge{\Gamma, \var{x} : \tau_1 }{e_2}{\tau}
}
{\tyjudge{\Gamma}{\elet{e_1}{x}{e_2}}{\tau}}
\]
\section{Typing derivation}
Type-setting the typing derivation of
$\elet{\enum{42}}{z}{\eplus{\var{z}}{1}}$ (which has type $\enum{}$):
{\small
\[
\tyrule{{r1}}
{
\tyrule{{r2}}
{\,}
{
\tyjudge{\emptyset}
{\enum{42}}
{\enum{}}
}
\\
\qquad \qquad
\tyrule{{r3}}
{
\tyrule{{r2}}
{\,}
{
\tyjudge{\var{z} : \enum{}}
{\var{z}}
{\enum{}}
}
\\
\qquad \qquad
\tyrule{{r4}}
{\,}
{
\tyjudge{\var{z} : \enum{}}
{\enum{1}}
{\enum{}}
}
}
{
\tyjudge{\var{z} : \enum{}}
{\eplus{\var{z}}{\enum{1}}}
{\enum{}}
}
}
{
\tyjudge{\emptyset}
{\elet{\enum{42}}{z}{\eplus{\var{z}}{\enum{1}}}}
{\enum{}}
}
\]
}
\section{Evaluation}
The macro of evaluation steps is called \texttt{jtrans}, it takes two
arguments: the initial expression and its result.
%
The macro to typeset evaluation rules and trees is called
\texttt{semrule}, it works like \texttt{tyrule}.
%
To evaluate $\elet{\enum{42}}{z}{\eplus{\var{z}}{1}}$, we proceed in
several steps:
\begin{enumerate}
\item First apply the rule for \texttt{let}:
\[
\semrule
{r5}
{\,}
{
\jtrans
{\elet{\enum{42}}{z}{\eplus{\var{z}}{\enum{1}}}}
{
{\eplus{\enum{42}}{\enum{1}}}
}
}
\]
\item Then we apply the rule for \texttt{plus}:
\[
\semrule
{r6}
{\,}
{\jtrans
{\eplus{\enum{42}}{\enum{1}}}
{\enum{43}}
}
\]
\end{enumerate}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End: