Advertisement
Guest User

test-newExporter.tex

a guest
Aug 31st, 2015
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 9.24 KB | None | 0 0
  1. % Created 2015-08-31 Mon 12:25
  2. \documentclass[compress,notes=hide]{beamer}
  3. \mode<presentation>
  4. {
  5.  \usetheme{Madrid}\useinnertheme{default}
  6.  \setbeamercovered{transparent}}
  7. \makeatletter
  8. \setbeamertemplate{footline}
  9. {
  10.   \leavevmode%
  11.   \hbox{%
  12.   \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
  13.     \usebeamerfont{author in head/foot}\insertsection
  14.  \end{beamercolorbox}%
  15.   \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
  16.     \usebeamerfont{title in head/foot}\insertsubsection
  17.  \end{beamercolorbox}%
  18.   \begin{beamercolorbox}[wd=.333333\paperwidth,ht=2.25ex,dp=1ex,right]{date in head/foot}%
  19.     \usebeamerfont{date in head/foot}\insertshortdate{}\hspace*{2em}
  20.    \insertframenumber{} / \inserttotalframenumber\hspace*{2ex}
  21.  \end{beamercolorbox}}%
  22.   \vskip0pt%
  23. }
  24. \makeatother
  25. \usepackage[english]{babel}
  26. \usepackage{times}
  27. \usepackage{pgf}
  28. \usepackage[utf8]{inputenc}
  29. \usepackage[T1]{fontenc}
  30. \usepackage{fixltx2e}
  31. \usepackage{graphicx}
  32. \usepackage{longtable}
  33. \usepackage{float}
  34. \usepackage{wrapfig}
  35. \usepackage{rotating}
  36. \usepackage[normalem]{ulem}
  37. \usepackage{amsmath}
  38. \usepackage{textcomp}
  39. \usepackage{marvosym}
  40. \usepackage{wasysym}
  41. \usepackage{amssymb}
  42. \usepackage{hyperref}
  43. \tolerance=1000
  44. \usepackage{colonequals}
  45. \usepackage[noend]{algorithmic}
  46. \usepackage{bussproofs}
  47. \usepackage{nicefrac}
  48. \institute{Department of Mathematical Sciences\\University of Puerto Rico at Mayagüez\\Mayagüez, PR}
  49. \author{Marko Schütz-Schmuck}
  50. \date{\today}
  51. \title{Example Correctness Proofs}
  52. \hypersetup{
  53.  pdfkeywords={},
  54.  pdfsubject={},
  55.  pdfcreator={Emacs 24.3.1 (Org mode 8.2.4)}}
  56. \begin{document}
  57.  
  58. \maketitle
  59.  
  60. \include{extra-setup}
  61.  
  62. \section{linear search}
  63. \label{sec-1}
  64. \begin{itemize}
  65. \item sought: smallest index \(i\) with \(a_i = x\)
  66. \item precondition: \(V \equiv n \in \naturals_0\)
  67. \item postcondition:
  68. \begin{align*}
  69. P \equiv & n \in \naturals_0 \land k \in \naturals \land k \le n+1
  70. \land \textmath{found} \in \booleans \\
  71. & \land \forall 1 \le i < k.a_i \neq x \\
  72. & \land (k \le n \land a_k = x \land \textmath{found} \lor k = n+1 \land \neg \textmath{found})
  73. \end{align*}
  74. \end{itemize}
  75.  
  76. \begin{enumerate}
  77. \item verify\hfill{}\textsc{BMCOL:B_block}
  78. \label{sec-1-1}
  79.  
  80. \begin{minipage}{.9\linewidth}
  81. \(
  82. \begin{Condition}
  83. V
  84. \end{Condition}\)\endgraf
  85. \begin{Pseudocode}
  86. \STATE \(k \isassigned 1\)
  87. \WHILE{\(k \le n \land a_k \neq x\)} \STATE \(k \isassigned k+1\) \ENDWHILE
  88. \STATE \(\textmath{found} \isassigned k \le n\)
  89. \end{Pseudocode}
  90. \(
  91. \begin{Condition}
  92. P
  93. \end{Condition}\)
  94. \end{minipage}
  95. \item invariant\hfill{}\textsc{B_block:BMCOL}
  96. \label{sec-1-2}
  97. \begin{align*}
  98. & n \in \naturals_0 \land k \in \naturals_0 \land k \le n+1 \\
  99. & \land \forall 1\le i<k. a_i
  100. \neq x
  101. \end{align*}
  102. \end{enumerate}
  103. \section{proof overview}
  104. \label{sec-2}
  105. \(
  106. \begin{Condition}
  107. V
  108. \end{Condition}\)\endgraf
  109. \begin{Pseudocode}
  110. \STATE \(k \isassigned 1\)
  111. \WHILE{\(k \le n \land a_k \neq x\)} \STATE \(k \isassigned k+1\) \ENDWHILE
  112. \STATE \(\textmath{found} \isassigned k \le n\)
  113. \end{Pseudocode}
  114. \(
  115. \begin{Condition}
  116. P
  117. \end{Condition}\)
  118.  
  119. {\tiny
  120. \begin{prooftree}
  121. \AxiomC{\(V \implies I\substitute{1}{k}\)}
  122. \RightLabel{A2}
  123. \UnaryInfC{\hoareTriple{V}{\(S_i\)}{I}}
  124. \AxiomC{\(I \land B \implies I\substitute{k+1}{k}\)}
  125. \RightLabel{A2}
  126. \UnaryInfC{\hoareTriple{I \land B}{\(S_W\)}{I}}
  127. \AxiomC{\(I \land \neg B \implies P_1\)}
  128. \RightLabel{W2}
  129. \TrinaryInfC{\hoareTriple{V}{\(S_i\ \algorithmicseq\ W\)}{P_1}}
  130. \AxiomC{\hoareTriple{P\substitute{k\le n}{\textmath{found}}}{\(S_f\)}{P}}
  131. \RightLabel{A1}
  132. \UnaryInfC{\hoareTriple{P_1}{\(S_f\)}{P}}
  133. \RightLabel{S1}
  134. \BinaryInfC{\hoareTriple{V}{\(S_i\ \algorithmicseq\ W\ \algorithmicseq\ S_f\)}{P}}
  135. \end{prooftree}
  136. }
  137.  
  138. termination: distance \(n+1 - k\)
  139. \section{strengthen postcondition of loop body}
  140. \label{sec-3}
  141. \begin{itemize}
  142. \item rule (P1) allows strengthening postcondition
  143. \item may make proving easier
  144. \end{itemize}
  145.  
  146. \section{merge sorted sub-sequences}
  147. \label{sec-4}
  148. \begin{itemize}
  149. \item given: arrays \(a, b, c\) with \(a, b\) sorted by value
  150. \item merge the sorted sequences of values into a sorted sequence of values in \(c\)
  151. \item precondition:
  152. \begin{align*}
  153. V \equiv & n_a \in \naturals_0 \land \forall 1 \le i < n_a . a_i \le a_{i+1} \\
  154.  \land & n_b \in \naturals_0\land \forall 1 \le i < n_b . b_i \le b_{i+1}
  155. \end{align*}
  156. \item predicate for permutations: \([] \perm []\), \(a \& b \& c \perm d \& b \& e \iff a \&
  157.    c \perm d \& e\) where \(\&\) has precedence over \(\perm\)
  158. \item postcondition:
  159. \begin{align*}
  160. P \equiv & \appendop_{i=1}^{n_a+n_b} [c_{i}] \perm \appendop_{i=1}^{n_a} [a_i] \&
  161. \appendop_{i=1}^{n_b} [b_i]\\
  162. \land & \forall 1 \le i < n_a+n_b . c_i \le c_{i+1}
  163. \end{align*}
  164. \end{itemize}
  165.  
  166. \section{proof obligations: black-box view}
  167. \label{sec-5}
  168. \begin{enumerate}
  169. \item \hoareTriple{V}\{\(\textmath{merge}\)\}\{P\}
  170. \item \(\textmath{merge}(d)\) is structurally like \(d\)
  171. \item \(\textmath{merge}\) will not modify any program variables other than \(c_i\) where
  172.     \(1 \le i \le n_a+n_b\)
  173. \item \(\textmath{merge}\) terminates
  174. \end{enumerate}
  175.  
  176. \section{merge subprogram}
  177. \label{sec-6}
  178. \begin{algorithmic}
  179. \DECLARE \((i_a, \naturals, 1), (i_b, \naturals, 1), (i_c, \naturals, 1)\)
  180. \WHILE{\(i_a \le n_a \lor i_b \le n_b\)}
  181. \IF{\(i_b > n_b \lor i_a \le n_a \land a_{i_a} \le b_{i_b}\)}
  182. \STATE \(c_{i_c} \isassigned a_{i_a}\)
  183. \STATE \(i_a \isassigned i_a + 1\)
  184. \ELSE
  185. \STATE \(c_{i_c} \isassigned b_{i_b}\)
  186. \STATE \(i_b \isassigned i_b + 1\)
  187. \ENDIF
  188. \STATE \(i_c \isassigned i_c +1\)
  189. \ENDWHILE
  190. \RELEASE \(i_a, i_b, i_c\)
  191. \end{algorithmic}
  192. \section{proof obligations: looking under the hood}
  193. \label{sec-7}
  194. \begin{enumerate}
  195. \item $\backslash$(
  196. \begin{Condition}
  197. V
  198. \end{Condition}$\backslash$)
  199. \begin{Pseudocode}
  200. \DECLARE \((i_a, \naturals, 1), (i_b, \naturals, 1), (i_c, \naturals,
  201. 1)\)
  202. \WHILE{\(i_a \le n_a \lor i_b \le n_b\)}
  203. \IF{\(i_b > n_b \lor i_a \le n_a \land a_{i_a} \le b_{i_b}\)}
  204. \STATE \(c_{i_c} \isassigned a_{i_a}\)
  205. \STATE \(i_a \isassigned i_a + 1\)
  206. \ELSE
  207. \STATE \(c_{i_c} \isassigned b_{i_b}\)
  208. \STATE \(i_b \isassigned i_b + 1\)
  209. \ENDIF
  210. \STATE \(i_c \isassigned i_c +1\)
  211. \ENDWHILE
  212. \RELEASE \(i_a, i_b, i_c\)
  213. \end{Pseudocode}
  214. $\backslash$(
  215. \begin{Condition}
  216. P
  217. \end{Condition}$\backslash$)
  218.  
  219. \item maintains structure
  220.  
  221. \item only modifies \(c_i\) where \(1 \le i \le n_a+n_b\)
  222. \end{enumerate}
  223. \section{proving \hoareTriple{V}\{\(\textmath{merge}\)\}\{P\}}
  224. \label{sec-8}
  225. \begin{itemize}
  226. \item invariant: \(I \equiv \bigvee_{i=0}^8 I_i\) where
  227. \begin{description}
  228. \item[{\(I_0 \equiv\)}] \(n_a \in \naturals_0 \land n_b \in \naturals_0\)
  229. \item[{\(I_1 \equiv\)}] \(i_a \in \naturals_0 \land 1\le i_a\le n_a+1\)
  230. \item[{\(I_2 \equiv\)}] \(i_b \in \naturals_0 \land 1\le i_b\le n_b+1\)
  231. \item[{\(I_3 \equiv\)}] \(i_c-1 = i_a - 1 + i_b - 1\)
  232. \item[{\(I_4 \equiv\)}] \(\appendop_{i=1}^{i_c-1} [c_{i}] \perm \appendop_{i=1}^{i_a-1} [a_i] \&
  233.      \appendop_{i=1}^{i_b - 1} [b_i]\)
  234. \item[{\(I_5 \equiv\)}] \((1 < i_c \land i_a \le n_a) \implies c_{i_c-1} \le a_{i_a}\)
  235. \item[{\(I_6 \equiv\)}] \((1 < i_c \land i_b \le n_b) \implies c_{i_c-1} \le b_{i_b}\)
  236. \item[{\(I_7 \equiv\)}] \(\forall 1 \le i < i_c-1 . c_i \le c_{i+1}\)
  237. \item[{\(I_8 \equiv\)}] \(\forall 1 \le i < n_a . a_i \le a_{i+1} \land \forall 1
  238.                        \le i < n_b . b_i \le b_{i+1}\)
  239. \end{description}
  240. \item symmetric wrt. renaming \(a \leftrightarrow b\)
  241. \end{itemize}
  242. \section{proof overview}
  243. \label{sec-9}
  244. {\tiny
  245. \begin{prooftree}
  246. \AxiomC{\(V \implies I\substitute{1,1,1}{i_c,i_b,i_a}\)}
  247. \RightLabel{S1\(^+\), D1}
  248. \UnaryInfC{\hoareTriple{V}{\(\textmath{init}\)}{I}}
  249. \end{prooftree}
  250. }
  251. \begin{itemize}
  252. \item \(B_1 \land B_2 \iff i_a\le n_a \land (i_b > n_b \lor a_{i_a}\le b_{i_b})\) and \(B_1
  253.    \land \neg B_2 \iff i_b\le n_b \land (i_a > n_a \lor b_{i_b} < a_{i_a})\)
  254. \end{itemize}
  255. {\tiny
  256. \begin{prooftree}
  257. \AxiomC{\(\vdots\)}
  258. \UnaryInfC{\hoareTriple{I \land B_1 \land B_2}{\(S_1\)}{I\substitute{i_c+1}{i_c}}}
  259. \AxiomC{\(I \land i_b\le n_b \land (i_a > n_a \lor b_{i_b} \le a_{i_a}) \implies I\substitute{i_c+1,i_b+1,b_{i_b}}{i_c,i_b,c_{i_c}}\)}
  260. \RightLabel{S1, A1, A2}
  261. \UnaryInfC{\hoareTriple{I \land i_b\le n_b \land (i_a > n_a \lor b_{i_b} \le a_{i_a})}{\(S_1\)}{I\substitute{i_c+1}{i_c}}}
  262. \RightLabel{P1}
  263. \UnaryInfC{\hoareTriple{I \land i_b\le n_b \land (i_a > n_a \lor b_{i_b} < a_{i_a})}{\(S_1\)}{I\substitute{i_c+1}{i_c}}}
  264. \UnaryInfC{\hoareTriple{I \land B_1 \land \neg B_2}{\(S_2\)}{I\substitute{i_c+1}{i_c}}}
  265. \RightLabel{IF1}
  266. \BinaryInfC{\hoareTriple{I \land B_1}{\(S\)}{I\substitute{i_c+1}{i_c}}}
  267. \end{prooftree}
  268. }
  269. {\tiny
  270. \begin{prooftree}
  271. \AxiomC{\hoareTriple{V}{\(\textmath{init}\)}{I}}
  272. \AxiomC{\hoareTriple{I \land B_1}{\(S\)}{I\substitute{i_c+1}{i_c}}}
  273. \RightLabel{S1, A1}
  274. \UnaryInfC{\hoareTriple{I \land B_1}{\(S\ \algorithmicseq\ i_c \isassigned i_c + 1\)}{I}}
  275. \AxiomC{\(I \land \neg B_1 \implies P\)}
  276. \RightLabel{W2}
  277. \TrinaryInfC{\hoareTriple{V}{\(\textmath{init}\ \algorithmicseq\ W\)}{P}}
  278. \AxiomC{}
  279. \RightLabel{SP1}
  280. \UnaryInfC{\hoareTriple{P}{\(R\)}{P}}
  281. \RightLabel{S1}
  282. \BinaryInfC{\hoareTriple{V}{\(\textmath{init}\ \algorithmicseq\ W\ \algorithmicseq\ R\)}{P}}
  283. \end{prooftree}
  284. }
  285. % Emacs 24.3.1 (Org mode 8.2.4)
  286. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement