]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/tactics/doc/main.tex
added constraing on non-empty context for tactic application
[helm.git] / helm / ocaml / tactics / doc / main.tex
1 \documentclass[a4paper]{article}
2
3 \usepackage{a4wide}
4 \usepackage{pifont}
5 \usepackage{semantic}
6 \usepackage{stmaryrd}
7
8 \newcommand{\MATITA}{\ding{46}\textsf{\textbf{Matita}}}
9
10 \title{Continuationals semantics for \MATITA}
11 \author{Claudio Sacerdoti Coen \quad Enrico Tassi \quad Stefano Zacchiroli \\
12 \small Department of Computer Science, University of Bologna \\
13 \small Mura Anteo Zamboni, 7 -- 40127 Bologna, ITALY \\
14 \small \{\texttt{sacerdot}, \texttt{tassi}, \texttt{zacchiro}\}\texttt{@cs.unibo.it}}
15
16 \newcommand{\MATHIT}[1]{\ensuremath{\mathit{#1}}}
17 \newcommand{\MATHTT}[1]{\ensuremath{\mathtt{#1}}}
18
19 \newcommand{\DOT}{\ensuremath{\mbox{\textbf{.}}}}
20 \newcommand{\SEMICOLON}{\ensuremath{\mbox{\textbf{;}}}}
21 \newcommand{\BRANCH}{\ensuremath{\mbox{\textbf{[}}}}
22 \newcommand{\SHIFT}{\ensuremath{\mbox{\textbf{\textbar}}}}
23 \newcommand{\POS}[1]{\ensuremath{#1\mbox{\textbf{:}}}}
24 \newcommand{\MERGE}{\ensuremath{\mbox{\textbf{]}}}}
25 \newcommand{\FOCUS}[1]{\ensuremath{\mathtt{focus}~#1}}
26 \newcommand{\UNFOCUS}{\ensuremath{\mathtt{unfocus}}}
27 \newcommand{\SKIP}{\MATHTT{skip}}
28 \newcommand{\TACTIC}[1]{\ensuremath{\mathtt{tactic}~#1}}
29
30 \newcommand{\APPLY}[1]{\ensuremath{\mathtt{apply}~\mathit{#1}}}
31
32 \newcommand{\GOAL}{\MATHIT{goal}}
33 \newcommand{\SWITCH}{\MATHIT{switch}}
34 \newcommand{\LIST}{\MATHTT{list}}
35 \newcommand{\INT}{\MATHTT{int}}
36 \newcommand{\OPEN}{\MATHTT{Open}}
37 \newcommand{\CLOSED}{\MATHTT{Closed}}
38
39 \newcommand{\SEMOP}[1]{|[#1|]}
40 \newcommand{\TSEMOP}[1]{{}_t|[#1|]}
41 \newcommand{\SEM}[3][\xi]{\SEMOP{#2}_{{#1},{#3}}}
42 \newcommand{\ENTRY}[4]{\langle#1,#2,#3,#4\rangle}
43 \newcommand{\TSEM}[3]{\TSEMOP{#1}_{#2,#3}}
44
45 \newcommand{\GIN}[1][1]{\ensuremath{[l_{#1};\cdots;l_n]}}
46
47 \newcommand{\ZEROPOS}{\MATHIT{zero\_pos}}
48 \newcommand{\INITPOS}{\MATHIT{init\_pos}}
49 \newcommand{\ISFRESH}{\MATHIT{is\_fresh}}
50 \newcommand{\FILTER}{\MATHIT{filter}}
51 \newcommand{\FILTEROPEN}{\MATHIT{filter\_open}}
52 \newcommand{\ISOPEN}{\MATHIT{is\_open}}
53 \newcommand{\DEEPCLOSE}{\MATHIT{deep\_close}}
54 \newcommand{\REMOVEGOALS}{\MATHIT{remove\_goals}}
55 \newcommand{\GOALS}{\MATHIT{goals}}
56
57 \newcommand{\BRANCHTAG}{\ensuremath{\mathtt{B}}}
58 \newcommand{\FOCUSTAG}{\ensuremath{\mathtt{F}}}
59
60 \newlength{\sidecondlen}
61 \setlength{\sidecondlen}{2cm}
62
63 \begin{document}
64 \maketitle
65
66 \section{Semantics}
67
68 \subsection{Language}
69
70 \[
71 \begin{array}{rcll}
72  S & ::= & & \mbox{(\textbf{continuationals})}\\
73    &     & \TACTIC{T} & \mbox{(tactic)}\\[2ex]
74    &  |  & \DOT & \mbox{(dot)} \\
75    &  |  & \SEMICOLON & \mbox{(semicolon)} \\
76    &  |  & \BRANCH & \mbox{(branch)} \\
77    &  |  & \SHIFT & \mbox{(shift)} \\
78    &  |  & \POS{i} & \mbox{(relative positioning)} \\
79    &  |  & \MERGE & \mbox{(merge)} \\[2ex]
80    &  |  & \FOCUS{g_1,\dots,g_n} & \mbox{(absolute positioning)} \\
81    &  |  & \UNFOCUS & \mbox{(unfocus)} \\[2ex]
82    &  |  & S ~ S & \mbox{(sequential composition)} \\[2ex]
83    T & : := & & \mbox{(\textbf{tactics})}\\
84      &   & \SKIP & \mbox{(skip)} \\
85      & | & \mathtt{reflexivity} & \\
86      & | & \mathtt{apply}~t & \\
87      & | & \dots &
88 \end{array}
89 \]
90
91 \subsection{Status}
92
93 \[
94 \begin{array}{rcll}
95  \xi & & & \mbox{(proof status)} \\
96  \mathit{goal} & & & \mbox{(proof goal)} \\[2ex]
97
98  \SWITCH & = & \OPEN~\mathit{goal} ~ | ~ \CLOSED~\mathit{goal} & \\
99  \mathit{locator} & = & \INT\times\SWITCH & \\
100  \mathit{tag} & = & \BRANCHTAG ~ | ~ \FOCUSTAG \\[2ex]
101
102  \Gamma & = & \mathit{locator}~\LIST & \mbox{(context)} \\
103  \tau & = & \mathit{locator}~\LIST & \mbox{(todo)} \\
104  \kappa & = & \mathit{locator}~\LIST & \mbox{(dot's future)} \\[2ex]
105
106  \mathit{stack} & = & (\Gamma\times\tau\times\kappa\times\mathit{tag})~\LIST
107  \\[2ex]
108
109  \mathit{status} & = & \xi\times\mathit{stack} \\
110 \end{array}
111 \]
112
113 \paragraph{Utilities}
114 \begin{itemize}
115  \item $\ZEROPOS([g_1;\cdots;g_n]) =
116   [\langle 0,\OPEN~g_1\rangle;\cdots;\langle 0,\OPEN~g_n\rangle]$
117  \item $\INITPOS([\langle i_1,s_1\rangle;\cdots;\langle i_n,s_n\rangle]) =
118   [\langle 1,\OPEN~s_1\rangle;\cdots;\langle n,\OPEN~s_n\rangle]$
119  \item $\ISFRESH(s) =
120   \left\{
121   \begin{array}{ll}
122    \mathit{true} & \mathrm{if} ~ s = \langle n, \OPEN~g\rangle\land n > 0 \\
123    \mathit{false} & \mathrm{otherwise} \\
124   \end{array}
125   \right.$
126  \item $\FILTEROPEN(\mathit{locs})=
127   \left\{
128   \begin{array}{ll}
129    [] & \mathrm{if}~\mathit{locs} = [] \\
130    \langle i,\OPEN~g\rangle :: \FILTEROPEN(\mathit{tl})
131    & \mathrm{if}~\mathit{locs} = \langle i,\OPEN~g\rangle :: \mathit{tl} \\
132    \FILTEROPEN(\mathit{tl})
133    & \mathrm{if}~\mathit{locs} = \mathit{hd} :: \mathit{tl} \\
134   \end{array}
135   \right.$
136  \item $\REMOVEGOALS(G,\mathit{locs}) =
137   \left\{
138   \begin{array}{ll}
139    [] & \mathrm{if}~\mathit{locs} = [] \\
140    \REMOVEGOALS(G,\mathit{tl})
141    & \mathrm{if}~\mathit{locs} = \langle i,\OPEN~g\rangle :: \mathit{tl}
142      \land g\in G\\
143    hd :: \REMOVEGOALS(G,\mathit{tl})
144    & \mathrm{if}~\mathit{locs} = \mathit{hd} :: \mathit{tl} \\
145   \end{array}
146   \right.$
147  \item $\DEEPCLOSE(G,S)$: (intuition) given a set of goals $G$ and a stack $S$
148   it returns a new stack $S'$ identical to the given one with the exceptions
149   that each locator whose goal is in $G$ is marked as closed in $\Gamma$ stack
150   components and removed from $\tau$ and $\kappa$ components.
151  \item $\GOALS(S)$: (inutition) return all goals appearing in whatever position
152   on a given stack $S$.
153 \end{itemize}
154
155 \paragraph{Invariants}
156 \begin{itemize}
157  \item $\forall~\mathrm{entry}~\ENTRY{\Gamma}{\tau}{\kappa}{t}, \forall s
158   \in\tau\cup\kappa, \exists g, s = \OPEN~g$ (each locator on the stack in
159   $\tau$ and $\kappa$ components has an \OPEN~switch).
160  \item Unless \FOCUS{} is used the stack contains no duplicate goals.
161 \end{itemize}
162
163 \subsection{Semantics}
164
165 \[
166 \begin{array}{rcll}
167  \SEMOP{\cdot} & : & C -> \mathit{status} -> \mathit{status} &
168   \mbox{(continuationals semantics)} \\
169  \TSEMOP{\cdot} & : & T -> \xi -> \SWITCH ->
170   \xi\times\GOAL~\LIST\times\GOAL~\LIST & \mbox{(tactics semantics)} \\
171 \end{array}
172 \]
173
174 \[
175 \begin{array}{rcl}
176  \mathit{apply\_tac} & : & T -> \xi -> \GOAL ->
177   \xi\times\GOAL~\LIST\times\GOAL~\LIST
178 \end{array}
179 \]
180
181 \[
182 \begin{array}{rlcc}
183  \TSEM{T}{\xi}{\OPEN~g} & = & \mathit{apply\_tac}(T,\xi,n) & T\neq\SKIP\\
184  \TSEM{\SKIP}{\xi}{\CLOSED~g} & = & \langle \xi, [], [g]\rangle &
185 \end{array}
186 \]
187
188 \[
189 \begin{array}{rcl}
190
191  \SEM{\TACTIC{T}}{\ENTRY{\GIN}{\tau}{\kappa}{t}::S}
192  & =
193  & \langle
194    \xi_n,
195    \ENTRY{\Gamma'}{\tau'}{\kappa'}{t}
196 %    \ENTRY{\ZEROPOS(G^o_n)}{\tau\setminus G^c_n}{\kappa\setminus G^o_n}{t}
197    :: \DEEPCLOSE(G^c_n,S)
198    \rangle
199  \\[1ex]
200  \multicolumn{3}{l}{\hspace{\sidecondlen}\mathit{where} ~ n\geq 1}
201  \\[1ex]
202  \multicolumn{3}{l}{\hspace{\sidecondlen}\mathit{and} ~
203   \Gamma' = \ZEROPOS(G^o_n)
204   \land \tau' = \REMOVEGOALS(G^c_n,\tau)
205   \land \kappa' = \REMOVEGOALS(G^o_n,\kappa)
206  }
207  \\[1ex]
208  \multicolumn{3}{l}{\hspace{\sidecondlen}\mathit{and} ~
209  \left\{
210  \begin{array}{rcll}
211   \langle\xi_0, G^o_0, G^c_0\rangle & = & \langle\xi, [], []\rangle \\
212   \langle\xi_{i+1}, G^o_{i+1}, G^c_{i+1}\rangle
213   & =
214   & \langle\xi_i, G^o_i, G^c_i\rangle
215   & l_{i+1}\in G^c_i \\
216   \langle\xi_{i+1}, G^o_{i+1}, G^c_{i+1}\rangle
217   & =
218   & \langle\xi, (G^o_i\setminus G^c)\cup G^o, G^c_i\cup G^c\rangle
219   & l_{i+1}\not\in G^c_i \\[1ex]
220   & & \mathit{where} ~ \langle\xi,G^o,G^c\rangle=\TSEM{T}{\xi_i}{l_{i+1}} \\
221  \end{array}
222  \right.
223  }
224  \\[6ex]
225
226  \SEM{~\DOT~}{\ENTRY{\Gamma}{\tau}{\kappa}{t}::S}
227  & =
228  & \langle \xi, \ENTRY{l_1}{\tau}{\GIN[2]\cup\kappa}{t}::S \rangle
229  \\[1ex]
230  & & \mathrm{where} ~ \FILTEROPEN(\Gamma)=\GIN \land n\geq 1
231  \\[2ex]
232
233  \SEM{~\DOT~}{\ENTRY{\Gamma}{\tau}{l::\kappa}{t}::S}
234  & =
235  & \langle \xi, \ENTRY{[l]}{\tau}{\kappa}{t}::S \rangle
236  \\[1ex]
237  & & \mathrm{where} ~ \FILTEROPEN(\Gamma)=[]
238  \\[2ex]
239
240  \SEM{~\SEMICOLON~}{S} & = & \langle \xi, S \rangle \\[1ex]
241
242  \SEM{~\BRANCH~}{\ENTRY{\GIN}{\tau}{\kappa}{t}::S}
243  \quad 
244  & =
245  & \langle\xi, \ENTRY{[l_1']}{[]}{[]}{\BRANCHTAG}
246    ::\ENTRY{[l_2';\cdots;l_n']}{\tau}{\kappa}{t}::S
247  \\[1ex]
248  & & \mathrm{where} ~ n\geq 2 ~ \land ~ \INITPOS(\GIN)=[l_1';\cdots;l_n']
249  \\[2ex]
250
251  \SEM{~\SHIFT~}
252   {\ENTRY{\Gamma}{\tau}{\kappa}{\BRANCHTAG}::\ENTRY{\GIN}{\tau'}{\kappa'}{t'}
253   ::S}
254  & =
255  & \langle
256    \xi, \ENTRY{[l_1]}{\tau\cup\FILTEROPEN(\Gamma)}{[]}{\BRANCHTAG}
257         ::\ENTRY{\GIN[2]}{\tau'}{\kappa'}{t'}::S
258    \rangle
259  \\[1ex]
260  & & \mathrm{where} ~ n\geq 1
261  \\[2ex]
262
263  \SEM{~\POS{i}~}
264   {\ENTRY{[l]}{[]}{[]}{\BRANCHTAG}::\ENTRY{\Gamma'}{\tau'}{\kappa'}{t'}::S}
265  & =
266  & \langle \xi, \ENTRY{[l_i]}{[]}{[]}{\BRANCHTAG}
267    ::\ENTRY{l :: (\Gamma'\setminus [l_i])}{\tau'}{\kappa'}{t'}::S \rangle
268  \\[1ex]
269  & & \mathrm{where} ~ \langle i,l'\rangle = l_i\in \Gamma'~\land~\ISFRESH(l)
270  \\[2ex]
271
272  \SEM{~\POS{i}~}
273   {\ENTRY{\Gamma}{\tau}{\kappa}{\BRANCHTAG}
274   ::\ENTRY{\Gamma'}{\tau'}{\kappa'}{t'}::S}
275  & =
276  & \langle \xi, \ENTRY{[l_i]}{[]}{[]}{\BRANCHTAG}
277  ::\ENTRY{\Gamma'\setminus [l_i]}{\tau'\cup\FILTEROPEN(\Gamma)}{\kappa'}{t'}::S
278    \rangle
279  \\[1ex]
280  & & \mathrm{where} ~ \langle i, l'\rangle = l_i\in \Gamma'
281  \\[2ex]
282
283  \SEM{~\MERGE~}
284   {\ENTRY{\Gamma}{\tau}{\kappa}{\BRANCHTAG}::\ENTRY{\Gamma'}{\tau'}{\kappa'}{t'}
285   ::S}
286  & =
287  & \langle \xi,
288    \ENTRY{\tau\cup\FILTEROPEN(\Gamma)\cup\Gamma'\cup\kappa}{\tau'}{\kappa'}{t'}
289    :: S
290    \rangle
291  \\[2ex]
292
293  \SEM{\FOCUS{g_1,\dots,g_n}}{S}
294  & = 
295  & \langle \xi, \ENTRY{[\OPEN~g_1;\cdots;\OPEN~g_n]}{[]}{[]}{\FOCUSTAG}
296    ::\DEEPCLOSE(S)
297    \rangle
298  \\[1ex]
299  & & \mathrm{where} ~
300  \forall i=1,\dots,n,~g_i\in\GOALS(S)
301  \\[2ex]
302
303  \SEM{\UNFOCUS}{\ENTRY{[]}{[]}{[]}{\FOCUSTAG}::S}
304  & = 
305  & \langle \xi, S\rangle \\[2ex]
306
307 \end{array}
308 \]
309
310 \end{document}
311