Debian Codegraph @

doc/binspect/binspect.tex

raw
1 % !TEX TS-program = xelatex
2 % !TEX encoding = UTF-8
3 % 2016/2/29: binspect
4 % [email protected]
5 %
6 \documentclass[a4paper,oneside,10pt,here]{memoir}
7 \usepackage[hscale=0.76,vscale=0.76]{geometry}
8 \setlength{\parindent}{0.0cm}
9 \setlength{\parskip}{1.4ex}
10 \usepackage{graphicx}
11 \usepackage{proof}
12 \usepackage{fancyvrb}
13 \usepackage{amssymb}
14 \usepackage{bussproofs}
15 %%% Japanese
16 \usepackage{fontspec}
17 \usepackage{indentfirst}
18 \setmainfont[Mapping=tex-text]{M+ 2p}
19 \setsansfont[Mapping=tex-text]{M+ 2c}
20 \setmonofont[Mapping=tex-text]{M+ 2m medium}
21 % \setmainfont[Ligatures=TeX]{Meiryo}
22 % \setsansfont[Ligatures=TeX]{Hiragino Kaku Gothic ProN W3}
23 % \setmonofont[Ligatures=TeX]{Osaka-Mono}
24 \XeTeXlinebreaklocale "ja_JP"
25 \XeTeXlinebreakskip=0em plus 0.1em minus 0.01em
26 \XeTeXlinebreakpenalty=0
27 \renewcommand{\baselinestretch}{1.4}
28 \settowidth{\parindent}{あ}
29 %%%%
30 \usepackage{dcolumn,hhline,colortbl}
31 \usepackage[table]{xcolor}
32 %%%%% 色付表
33 \newcolumntype{G}{%
34 >{\columncolor[gray]{0.9}}c}
35 \newcolumntype{O}{%
36 >{\columncolor{orange}}c}
37 \newcolumntype{M}{%
38 >{\columncolor{green}}c}
39 \newcolumntype{Y}{%
40 >{\columncolor{yellow}}c}
41 \newcolumntype{C}{%
42 >{\columncolor{cyan}}c}
43 %%%% hyperref
44 %\usepackage[dvipdfm,colorlinks=true,linkcolor=blue]{hyperref}
45 \usepackage[colorlinks=true,linkcolor=blue]{hyperref}
46
47 \usepackage{tikz}
48 \usetikzlibrary{arrows}
49
50 %%%%%%%%%%syntax
51 \makeatletter
52 % terminal - used for terminal symbols, argument is characters appear in sf.
53 \def\sym#1{\textsf{#1}\null}
54 % nonterm - used for non terminal symbols, argument is characters typed with
55 % italic face.
56 \def\nonterm#1{\textit{#1}\null}
57 %%%%%
58 % syntax ... endsyntax
59 \def\xstrut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
60 \def\syntax{\syntaxoutnonbox\halign\bgroup
61 \xstrut$\@lign##$\hfil &\hfil$\@lign{}##{}$\hfil
62 &$\@lign##$\hfil &\qquad\@lign-- ##\hfil\cr}
63 \def\endsyntax{\crcr\egroup$$
64 \global\@ignoretrue
65 }
66 \def\syntaxoutnonbox{\xleavevmode$$
67 \parskip=0pt\lineskip=0pt
68 \def\\{\crcr}% Must have \def and not \let for nested alignments.
69 \everycr={\noalign{\penalty10000}}
70 \tabskip=0pt}
71 \def\xleavevmode{\ifvmode\if@inlabel\indent\else\if@noskipsec\indent\else
72 \if@nobreak\global\@nobreakfalse\everypar={}\fi
73 {\parskip=0pt\noindent}\fi\fi\fi}
74 \def\@but{\noalign{\nointerlineskip}}
75 \def\alt{{\;|\;}}
76 \def\seqof#1{\mbox{\textbf{\{}}\;{#1}\;\mbox{\textbf{\}}}}
77 \def\optn#1{\textbf{[}\;{#1}\;\textbf{]}}
78 \def\synindent{\;\;\;}
79 %%%%
80 \def\SP{\mathit{SP}}
81 \def\PR{\mathtt{PR}}
82 \def\Sig{\mathbb{S}\mathit{ig}}
83 \def\tr{\mathtt{true}}
84 \def\fs{\mathtt{false}}
85 \makeatother
86 %%%
87 %%%% numbering
88 %%% ToC down to susubsections
89 \settocdepth{subsubsection}
90 %%% Numbering down to sections
91 \setsecnumdepth{subsection}
92 %%% 名前定義を適当に
93 \def\figurename{{図}}
94 \def\tablename{表}
95 \def\contentsname{目次}
96 \def\listfigurename{図目次}
97 \def\listtablename{表目次}
98 \def\refname{参考文献}
99 \def\bibname{参考文献}
100 \def\indexname{索引}
101 \def\appendixname{付録}
102 %%%%%%%%%% Verbatim
103 \DefineVerbatimEnvironment%
104 {simplev}{Verbatim}
105 {fontsize=\small}
106 \DefineVerbatimEnvironment%
107 {examplev}{Verbatim}
108 {frame=leftline,fontsize=\small}
109 %%%%%%%%%%
110 \definecolor{shadecolor}{gray}{0.9}
111 \newenvironment{vvtm}%
112 {\parskip=0pt\lineskip=0pt\begin{center}\begin{minipage}{0.8\textwidth}\begin{snugshade}}%
113 {\end{snugshade}\end{minipage}\end{center}}
114 %%%
115 \usepackage{float}
116 \begin{document}
117 \headstyles{default}
118 \tightlists
119 %\midsloppy
120 \sloppy
121 \raggedbottom
122 \chapterstyle{ell}
123 %%%%%%%%
124 \frontmatter
125 \pagestyle{empty}
126 % 表紙 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 \title{補題発見支援機構利用手引き \\
128 ver. 0.1}
129 \vfill
130 \author{澤田 寿実\\
131 (株) 考作舎\\
132 [email protected]}
133 \date{2016/2/29}
134 \maketitle
135 \vfill
136 \begin{center}
137 %\includegraphics[scale=0.2]{../etc/kosakusha-logo-gray.pdf}
138 \includegraphics[scale=0.4]{../etc/kosakusha-logo-gray.png}
139 \end{center}
140 \vfill
141 \thispagestyle{empty}
142 \newpage
143 %%%%%%
144 \mainmatter
145 \pagestyle{plain}
146 \pagenumbering{arabic}
147 % 構成 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 \tableofcontents
149 \EnableBpAbbreviations
150 \newpage
151 \chapter{補題発見支援機構の概要}
152 CafeOBJ 言語による仕様記述では,通常組み込みモジュール\verb|BOOL|
153 で定義されているソート \verb|Bool| の \verb|true| および \verb|false|
154 を用いて真偽値を表現する.モジュール \verb|BOOL| はそのような使い方を
155 想定して様々な論理演算子(\verb|and|, \verb|or|, \verb|xor|, \verb|imply|
156 など)を導入しており,これらの論理演算子を用いて表現された項は,
157 $C_1 \mbox{xor} \ldots C_n$ の形をした標準形(XOR標準形)の形に
158 (BOOLモジュールの等式によって)変換される(ここで $b_n$ は,$b_1 \mbox{and}\ldots b_m$ である.)
159
160 たとえば,\verb|(B1:Bool or B2:Bool and B3:Bool) implies B4:Bool| という形の項は
161 \begin{verbatim}
162 ((B2 and B3) xor (B1 xor ((B1 and (B3 and B2))
163 xor
164 (true xor ((B1 and (B2 and (B3 and B4)))
165 xor ((B1 and B4) xor (B3 and (B2 and B4))))))))
166 \end{verbatim}
167 のような形の標準形に変換される.見ての通り元の項に比べて
168 意味的に同等ではあるが,XOR標準形は人間にとってその構造や
169 意味を直感的に把握するのが困難である.
170
171 証明過程においては,途中出現するさまざまな Bool 項について
172 その真偽が想定したものとなっているかどうかが調べられるが,
173 \verb|true| や \verb|false| に簡約されず,
174 上記のXOR標準形のままに残ることがある.
175 多くが何らかの仮定が不足だったり,想定していないケース漏れで
176 あったりする.
177 そのような場合,\verb|true| や \verb|false| に簡約されなかった
178 項を観察し,必要とされている前提条件を推測するのが一般に取られる
179 手段である.
180 それらの仮定をうまく補題として取り出すことができると以降の証明が先まで進んで行く.
181 その場合に障害となるのが,上で見た通りXOR標準形は項のサイズが
182 大きくなる傾向があること,また人間の日常的に慣れ親しんでいる
183 真偽判定のやり方と乖離があり,何を仮定すれば全体の Bool 項をより
184 簡略化できるかが了解しにくいということである.
185
186 この問題を解決するための支援機構として,Bool項検査開始コマンド(\verb|binspect|)
187 ならびに \verb|binspect| で指定された項の真偽値が,それらを構成する
188 部分項の真偽値によりどのようになるかを調べるためのコマンド(\verb|bresolve|,
189 \verb|bguess|)などを導入した.
190 以下ではこれらのコマンドについてその使用方法を説明する.
191
192 \chapter{補題発見支援機構コマンド}
193 \section{bispect コマンド}
194 \begin{itemize}
195 \item \verb|binspect| コマンドは与えられたBool項を抽象化し,見やすい形にするとともに
196 その項を \verb|bresolve| や \verb|bguess| コマンドの適用対象として設定する.
197 \item 構文
198 \begin{vvtm}
199 \begin{simplev}
200 binspectコマンド ::= binspect [in <ModuleName>]: <term> .
201 \end{simplev}
202 \end{vvtm}
203 ここで,\verb|<term>| は組み込みモジュールBOOLで定義されたソート Bool の項でなければならない.
204 \item 実行例-1
205 %\begin{vvtm}
206 \begin{simplev}
207 binspect in NAT : (N1:Nat * N2:Nat) = (N1:Nat * N3:Nat) implies N2 = N3 .
208
209 (((N1 * N2) = (N1 * N3)) implies (N2 = N3)):Bool
210 --> (((N2:Nat * N1:Nat) = (N3:Nat * N1)) xor (true xor ((N2 = N3) and ((N2 * N1) = (N3 * N1)))))
211 ** Abstracted boolean term:
212 ((`P-1:Bool and `P-2:Bool) xor (`P-1 xor true))
213 where
214 `P-1 = ((N2:Nat * N1:Nat) = (N3:Nat * N1))
215 `P-2 = (N2:Nat = N3:Nat)
216 \end{simplev}
217 %\end{vvtm}
218 \item もとの項が \verb|(`P-1:Bool and `P-2:Bool) xor (`P-1 xor true)| という
219 XOR 標準形に変換され,また \verb|N2:Nat = N3:Nat| のような部分項は
220 \verb|`P-1| という擬似定数に変換され全体の構造がより視認されやすいようになっている.
221 \item 実行例-2
222 \begin{simplev}
223 CafeOBJ> binspect in NAT : (N1:Nat = N2:Nat) and (N2:Nat = N3:Nat + 1)
224 implies (N1 = N3 + 1) or (N2 = N1) .
225
226 (((N1 = N2) and (N2 = (1 + N3))) implies ((N1 = (1 + N3)) or (N2 = N1))):Bool
227 --> true
228 ** Abstracted boolean term:
229 true
230 \end{simplev}
231 \item 上の例のように,変換結果が \verb|true| または \verb|false| となる場合は
232  その旨表示される.
233
234 \item 実行例-3
235 \begin{simplev}
236 CafeOBJ> binspect in NAT : (N1:Nat * N2:Nat) = 0 or (N2 * N1) = 0 implies (N1 = 0 or N2 = 0) .
237
238 ((((N1 * N2) = 0) or ((N2 * N1) = 0)) implies ((N1 = 0) or (N2 = 0))):Bool
239 --> (((N2:Nat * N1:Nat) = 0) xor (true xor (((N1 = 0) and ((N2 = 0) and ((N1 * N2) = 0)))
240 xor (((N1 = 0) and ((N2 * N1) = 0)) xor ((N2 = 0) and ((N2 * N1) = 0))))))
241 ** Abstracted boolean term:
242 ((`P-1:Bool and `P-3:Bool) xor ((`P-1 and `P-2:Bool) xor ((`P-1 and (`P-3 and `P-2)) xor (`P-1 xor true))))
243 where
244 `P-1 = ((N2:Nat * N1:Nat) = 0)
245 `P-2 = (N1:Nat = 0)
246 `P-3 = (N2:Nat = 0)
247 \end{simplev}
248 \item 同じ部分項は同じ擬似定数(上例では \verb|N1:Nat * N2:Nat = 0|に対して\verb|`P-1|)で抽象化される.
249 \end{itemize}
250
251 \section{bshow コマンド}\label{sec:bshow}
252 \begin{itemize}
253 \item \verb|bshow| コマンドは \verb|binspect| コマンドで指定した項を印字する.
254 \item 構文
255 \begin{vvtm}
256 \begin{simplev}
257 bshowコマンド ::= bshow [{ grind | tree }]
258 \end{simplev}
259 \end{vvtm}
260 \item 実行例-1 \\
261 bshow は先に binspet で指定したBool項を表示する.
262 \begin{simplev}
263 CafeOBJ> bshow
264 ((`P-1:Bool and `P-3:Bool) xor ((`P-1 and `P-2:Bool) xor ((`P-1 and (`P-3 and `P-2)) xor (`P-1 xor true))))
265 where
266 `P-1 = ((N2:Nat * N1:Nat) = 0)
267 `P-2 = (N1:Nat = 0)
268 `P-3 = (N2:Nat = 0)
269 \end{simplev}
270 \item 実行例-2\\
271 オプション引数 \verb|grind| を指定すると,XOR 標準形の部分項を構成する and で結ばれた項を集約して表示する.
272 大きなサイズの項の構造を把握するために便利である.
273 \begin{simplev}
274 CafeOBJ> bshow grind
275
276 >> xor ***>
277 true
278 >> and --->
279 `P-1 = ((N1:Nat * N2:Nat) = 0)
280 `P-2 = (N1:Nat = 0)
281 `P-3 = (N2:Nat = 0)
282 <----------
283 >> and --->
284 `P-1 = ((N2:Nat * N1:Nat) = 0)
285 `P-2 = (N1:Nat = 0)
286 <----------
287 >> and --->
288 `P-1 = ((N2:Nat * N1:Nat) = 0)
289 `P-3 = (N2:Nat = 0)
290 <----------
291 `P-1 = ((N2:Nat * N1:Nat) = 0)
292 <**********
293 \end{simplev}
294 \item 実行例-3\\
295 オプション引数の \verb|tree| を指定すると,抽象化したBool項の木構造を
296 把握しやすい形式で印字する.
297 \begin{simplev}
298 bshow tree
299
300 _xor_
301 _and_
302 `P-1:Bool
303 `P-3:Bool
304 _xor_
305 _and_
306 `P-1:Bool
307 `P-2:Bool
308 _xor_
309 _and_
310 `P-1:Bool
311 _and_
312 `P-3:Bool
313 `P-2:Bool
314 _xor_
315 `P-1:Bool
316 true
317 where
318 `P-1 = ((N2:Nat * N1:Nat) = 0)
319 `P-2 = (N1:Nat = 0)
320 `P-3 = (N2:Nat = 0)
321 \end{simplev}
322 \end{itemize}
323
324 \section{bresolveコマンド}
325 \begin{itemize}
326 \item \verb|bresolve| は \verb|binspect| コマンドで解析対象として指定した項の xor の各部分項に
327 \verb|true| と\verb|false| の組み合わせを代入し,結果として \verb|true| となるような組み合わせを
328 探索し,その結果を表示する.
329 \item 構文
330 \begin{vvtm}
331 \begin{simplev}
332 bresolveコマンド ::= bresolve [ <number> | all ]
333 \end{simplev}
334 \end{vvtm}
335 \item 実行例-1 \\
336 オプション引数 <number> は true または false を割振る擬似定数の組み合わせの個数を指定する.
337 指定しない場合のデフォルトは1であり,この場合抽象化されたBool項に出現する個々の擬似定数にたいして true または
338 false を代入し,全体の結果が true となるものを探す.
339 \begin{simplev}
340 CafeOBJ> bresolve
341
342 ** (1) The following assignment(s) makes the term to be 'true'.
343 [1] { `P-1:Bool |-> false }
344 where
345 `P-1 = ((N2:Nat * N1:Nat) = 0)
346
347 [2] { `P-2:Bool |-> true }
348 where
349 `P-2 = (N1:Nat = 0)
350
351 [3] { `P-3:Bool |-> true }
352 where
353 `P-3 = (N2:Nat = 0)
354 \end{simplev}
355
356 \item 実行例-2 \\
357 オプション引数 <number> に all を指定すると,全ての可能な
358 true/false の組み合わせについて評価し,結果が true となる代入を探す.
359 \begin{simplev}
360 bresolve all
361
362 ** (1) The following assignment(s) makes the term to be 'true'.
363 [1] { `P-1:Bool |-> false }
364 where
365 `P-1 = ((N2:Nat * N1:Nat) = 0)
366
367 [2] { `P-2:Bool |-> true }
368 where
369 `P-2 = (N1:Nat = 0)
370
371 [3] { `P-3:Bool |-> true }
372 where
373 `P-3 = (N2:Nat = 0)
374
375 ** (2) The following assignment(s) makes the term to be 'true'.
376 [1] { `P-1:Bool |-> true, `P-2:Bool |-> true }
377 [2] { `P-1:Bool |-> false, `P-2:Bool |-> true }
378 [3] { `P-1:Bool |-> false, `P-2:Bool |-> false }
379 where
380 `P-1 = ((N2:Nat * N1:Nat) = 0)
381 `P-2 = (N1:Nat = 0)
382
383 [4] { `P-1:Bool |-> true, `P-3:Bool |-> true }
384 [5] { `P-1:Bool |-> false, `P-3:Bool |-> true }
385 [6] { `P-1:Bool |-> false, `P-3:Bool |-> false }
386 where
387 `P-1 = ((N2:Nat * N1:Nat) = 0)
388 `P-3 = (N2:Nat = 0)
389
390 [7] { `P-2:Bool |-> true, `P-3:Bool |-> true }
391 [8] { `P-2:Bool |-> false, `P-3:Bool |-> true }
392 [9] { `P-2:Bool |-> true, `P-3:Bool |-> false }
393 where
394 `P-2 = (N1:Nat = 0)
395 `P-3 = (N2:Nat = 0)
396
397 ** (3) The following assignment(s) makes the term to be 'true'.
398 [1] { `P-1:Bool |-> true, `P-2:Bool |-> true, `P-3:Bool |-> true }
399 [2] { `P-1:Bool |-> false, `P-2:Bool |-> true, `P-3:Bool |-> true }
400 [3] { `P-1:Bool |-> true, `P-2:Bool |-> false, `P-3:Bool |-> true }
401 [4] { `P-1:Bool |-> false, `P-2:Bool |-> false, `P-3:Bool |-> true }
402 [5] { `P-1:Bool |-> true, `P-2:Bool |-> true, `P-3:Bool |-> false }
403 [6] { `P-1:Bool |-> false, `P-2:Bool |-> true, `P-3:Bool |-> false }
404 [7] { `P-1:Bool |-> false, `P-2:Bool |-> false, `P-3:Bool |-> false }
405 where
406 `P-1 = ((N2:Nat * N1:Nat) = 0)
407 `P-2 = (N1:Nat = 0)
408 `P-3 = (N2:Nat = 0)
409 \end{simplev}
410 \end{itemize}
411
412
413 \section{bguessコマンド}
414 \begin{itemize}
415 \item \verb|bguess| コマンドは \verb|binspect| コマンドによって指定された Bool 項に対して
416 経験から得られている幾つかの有用な推測方法を適用し結果を調べる.
417 \item 構文
418 \begin{vvtm}
419 \begin{simplev}
420 bguessコマンド ::= bguess { imply | and | or }
421 \end{simplev}
422 \end{vvtm}
423 \item 実行例-1 \\
424 引数 \verb|imply| を指定した場合,抽象化した Bool 項に含まれる
425 擬似定数 p, q について\verb|p implies q = true| が成立すると仮定した時に
426 結果がどうなるかを調べ,true となる場合その仮定を公理の形式で印字して示す.
427 \begin{simplev}
428 CafeOBJ> bg imply
429
430 ** (1) each of the following equations makes the inspected term 'true'
431 [1] eq [:bimply]: (`P-1:Bool and `P-3:Bool) = `P-1 .
432 where
433 `P-1 = ((N2:Nat * N1:Nat) = 0)
434 `P-3 = (N2:Nat = 0)
435
436 [2] eq [:bimply]: (`P-1:Bool and `P-2:Bool) = `P-1 .
437 where
438 `P-1 = ((N2:Nat * N1:Nat) = 0)
439 `P-2 = (N1:Nat = 0)
440 \end{simplev}
441 \item 上の例のように \verb|bguess| は \verb|bg| と略称することができる.
442 \item \verb|p implies q = true| は XOR 標準形を用いた \verb|p and q = p| に論理的に等価である.
443 結果の印字では XOR 標準形を用いた形式で印字する.
444 \item and \\
445 bguess の引数として \verb|and| を指定した場合は,\verb|p and q = false| という形の
446 仮定を導入した場合に結果がどうなるかを調べる.
447 \item or \\
448 bguess の引数として \verb|or| を指定した場合は,\verb|p or q = true| という形の
449 仮定を導入した場合に結果がどうなるかを調べる.
450 \item 現在までのところ,引数 and や or により有用な補題の発見ができた例は存在しない.
451 \end{itemize}
452
453 \end{document}
454 %%% Local Variables:
455 %%% mode: latex
456 %%% TeX-master: t
457 %%% End: