Mercurial > hg > Papers > 2018 > nozomi-master
annotate paper/agda.tex @ 62:a40033d3e10f
Add Meta CodeSegment description
author | atton <atton@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 03 Feb 2017 10:29:28 +0900 |
parents | 70bea06ebdf3 |
children | 10a550bf7e4a |
rev | line source |
---|---|
49 | 1 \chapter{証明支援系言語 Agda による証明手法} |
2 \label{chapter:agda} | |
50
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
3 第~\ref{chapter:type}章では形無し算術式と型付き算術式による型システムの定義、ラムダ計算によるプログラミング言語の抽象化、部分型の導入とCbCの型が部分型で示せることを確認した。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
4 部分型を用いて具体的なCbCの型システムを定義する前に、型システムの一方のメリットである証明について触れる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
5 依存型という型を持つ証明支援系言語 Agda を用いて証明が行なえることを示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
6 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
7 % {{{ Natural Deduction |
49 | 8 \section{Natural Deduction} |
55 | 9 \label{section:natural_deduction} |
50
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
10 まず始めに証明を行なうためにNatural Deduction(自然演繹)を示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
11 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
12 証明には natural deduction(自然演繹)を用いる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
13 natural deduction は Gentzen によって作られた論理と、その証明システムである~\cite{Girard:1989:PT:64805}。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
14 命題変数と記号を用いた論理式で論理を記述し、推論規則により変形することで求める論理式を導く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
15 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
16 natural deduction において |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
17 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
18 \begin{eqnarray} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
19 \vdots \\ \nonumber |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
20 A \\ \nonumber |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
21 \end{eqnarray} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
22 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
23 と書いた時、最終的に命題Aを証明したことを意味する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
24 証明は木構造で表わされ、葉の命題は仮定となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
25 仮定には dead か alive の2つの状態が存在する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
26 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
27 \begin{eqnarray} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
28 \label{exp:a_implies_b} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
29 A \\ \nonumber |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
30 \vdots \\ \nonumber |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
31 B \\ \nonumber |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
32 \end{eqnarray} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
33 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
34 式\ref{exp:a_implies_b}のように A を仮定して B を導いたとする。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
35 この時 A は alive な仮定であり、証明された B は A の仮定に依存していることを意味する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
36 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
37 ここで、推論規則により記号 $ \Rightarrow $ を導入する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
38 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
39 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
40 \AxiomC{[$ A $]} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
41 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
42 \UnaryInfC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
43 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
44 \UnaryInfC{ $ B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
45 \RightLabel{ $ \Rightarrow \mathcal{I} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
46 \UnaryInfC{$ A \Rightarrow B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
47 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
48 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
49 $ \Rightarrow \mathcal{I} $ を適用することで仮定 A は dead となり、新たな命題 $ A \Rightarrow B $ を導くことができる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
50 A という仮定に依存して B を導く証明から、「A が存在すれば B が存在する」という証明を導いたこととなる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
51 このように、仮定から始めて最終的に全ての仮定を dead とすることで、仮定に依存しない証明を導ける。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
52 なお、dead な仮定は \verb/[A]/ のように \verb/[]/ で囲んで書く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
53 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
54 alive な仮定を dead にすることができるのは $ \Rightarrow \mathcal{I} $ 規則のみである。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
55 それを踏まえ、 natural deduction には以下のような規則が存在する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
56 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
57 \begin{itemize} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
58 \item Hypothesis |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
59 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
60 仮定。葉にある式が仮定となるため、論理式A を仮定する場合に以下のように書く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
61 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
62 $ A $ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
63 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
64 \item Introductions |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
65 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
66 導入。証明された論理式に対して記号を導入することで新たな証明を導く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
67 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
68 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
69 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
70 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
71 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
72 \UnaryInfC{ $ A $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
73 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
74 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
75 \UnaryInfC{ $ B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
76 \RightLabel{ $ \land \mathcal{I} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
77 \BinaryInfC{$ A \land B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
78 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
79 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
80 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
81 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
82 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
83 \UnaryInfC{ $ A $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
84 \RightLabel{ $ \lor 1 \mathcal{I} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
85 \UnaryInfC{$ A \lor B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
86 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
87 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
88 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
89 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
90 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
91 \UnaryInfC{ $ B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
92 \RightLabel{ $ \lor 2 \mathcal{I} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
93 \UnaryInfC{$ A \lor B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
94 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
95 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
96 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
97 \AxiomC{[$ A $]} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
98 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
99 \UnaryInfC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
100 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
101 \UnaryInfC{ $ B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
102 \RightLabel{ $ \Rightarrow \mathcal{I} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
103 \UnaryInfC{$ A \Rightarrow B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
104 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
105 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
106 \item Eliminations |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
107 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
108 除去。ある論理記号で構成された証明から別の証明を導く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
109 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
110 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
111 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
112 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
113 \UnaryInfC{ $ A \land B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
114 \RightLabel{ $ \land 1 \mathcal{E} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
115 \UnaryInfC{$ A $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
116 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
117 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
118 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
119 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
120 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
121 \UnaryInfC{ $ A \land B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
122 \RightLabel{ $ \land 2 \mathcal{E} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
123 \UnaryInfC{$ B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
124 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
125 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
126 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
127 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
128 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
129 \UnaryInfC{ $ A \lor B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
130 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
131 \AxiomC{[$A$]} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
132 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
133 \UnaryInfC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
134 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
135 \UnaryInfC{ $ C $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
136 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
137 \AxiomC{[$B$]} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
138 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
139 \UnaryInfC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
140 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
141 \UnaryInfC{ $ C $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
142 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
143 \RightLabel{ $ \lor \mathcal{E} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
144 \TrinaryInfC{ $ C $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
145 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
146 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
147 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
148 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
149 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
150 \UnaryInfC{ $ A $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
151 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
152 \AxiomC{ $ \vdots $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
153 \noLine |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
154 \UnaryInfC{ $ A \Rightarrow B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
155 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
156 \RightLabel{ $ \Rightarrow \mathcal{E} $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
157 \BinaryInfC{$ B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
158 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
159 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
160 \end{itemize} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
161 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
162 記号 $ \lor, \land, \Rightarrow $ の導入の除去規則について述べた。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
163 natural deduction には他にも $ \forall, \exists, \bot $ といった記号が存在するが、ここでは解説を省略する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
164 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
165 それぞれの記号は以下のような意味を持つ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
166 \begin{itemize} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
167 \item $ \land $ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
168 conjunction。2つの命題が成り立つことを示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
169 $ A \land B $ と記述すると A かつ B と考えることができる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
170 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
171 \item $ \lor $ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
172 disjunction。2つの命題のうちどちらかが成り立つことを示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
173 $ A \lor B $ と記述すると A または B と考えることができる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
174 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
175 \item $ \Rightarrow $ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
176 implication。左側の命題が成り立つ時、右側の命題が成り立つことを示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
177 $ A \Rightarrow B $ と記述すると A ならば B と考えることができる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
178 \end{itemize} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
179 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
180 例として、natural deduction で三段論法を証明する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
181 なお、三段論法とは「A は B であり、 B は C である。よって A は C である」といった文を示す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
182 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
183 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
184 \AxiomC{ $ [A] $ $_{(1)}$} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
185 \AxiomC{ [$ (A \Rightarrow B) \land (B \Rightarrow C)$] $_{(2)}$ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
186 \RightLabel{ $ \land 1 \mathcal{E} $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
187 \UnaryInfC{ $ (A \Rightarrow B) $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
188 \BinaryInfC{ $ B $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
189 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
190 \AxiomC{ [$ (A \Rightarrow B) \land (B \Rightarrow C)$] $_{(2)}$ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
191 \RightLabel{ $ \land 2 \mathcal{E} $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
192 \UnaryInfC{ $ (B \Rightarrow C) $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
193 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
194 \BinaryInfC{ $ C $ } |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
195 \RightLabel{ $ \Rightarrow \mathcal{I} _{(1)}$} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
196 \UnaryInfC{ $ A \Rightarrow C $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
197 \RightLabel{ $ \Rightarrow \mathcal{I} _{(2)}$} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
198 \UnaryInfC{ $ ((A \Rightarrow B) \land (B \Rightarrow C)) \Rightarrow (A \Rightarrow C) $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
199 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
200 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
201 まず、三段論法を論理式で表す。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
202 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
203 「A は B であり、 B は C である。よって A は C である」 が証明するべき命題である。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
204 まず、「A は B であり」から、Aから性質Bが導けることが分かる。これが $ A \Rightarrow B $ となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
205 次に、「B は C である」から、Bから性質Cが導けることが分かる。これが $ B \Rightarrow C $ となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
206 そしてこの2つは同時に成り立つ。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
207 よって $ (A \Rightarrow B) \land (B \Rightarrow C)$ が仮定となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
208 この仮定が成り立つ時に「Aは Cである」を示せば良い。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
209 仮定と同じように「A は C である」は、 $ A \Rightarrow C $ と書けるため、証明するべき論理式は $ ((A \Rightarrow B) \land (B \Rightarrow C)) \Rightarrow (A \Rightarrow C) $ となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
210 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
211 証明の手順はこうである。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
212 まず条件$ (A \Rightarrow B) \land (B \Rightarrow C)$とAの2つを仮定する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
213 条件を $ \land 1 \mathcal{E} $ $ \land 2 \mathcal{E} $ により分解する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
214 A と $ A \Rightarrow B$ から B を、 B と $ B \Rightarrow C $ から C を導く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
215 ここで $ \Rightarrow \mathcal{I} $ により $ A \Rightarrow C $ を導く。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
216 この際に dead にする仮定は A である。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
217 数回仮定を dead にする際は $_{(1)} $ のように対応する \verb/[]/の記号に数値を付ける。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
218 これで残る alive な仮定は $ (A \Rightarrow B) \land (B \Rightarrow C)$ となり、これから $ A \Rightarrow C $ を導くことができたためにさらに $ \Rightarrow \mathcal{I} $ を適用する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
219 結果、証明すべき論理式$ ((A \Rightarrow B) \land (B \Rightarrow C)) \Rightarrow (A \Rightarrow C) $ が導けたために証明終了となる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
220 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
221 % }}} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
222 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
223 % {{{ Curry-Howard Isomorphism |
49 | 224 \section{Curry-Howard Isomorphism} |
50
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
225 \label{section:curry_howard_isomorphism} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
226 \ref{section:natural_deduction}節では natural deduction における証明手法について述べた。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
227 natural deduction における証明はほとんど型付き $ \lambda $ 計算のような形をしている。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
228 実際、Curry-Howard Isomorphism により Natural Deduction と型付き $ \lambda $ 計算は対応している。% ref TaPL 104 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
229 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
230 型構築子 $ \rightarrow $ のみに注目した時 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
231 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
232 \begin{enumerate} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
233 \item 導入規則(T-ABS) は、その型の要素がどのように作られるかを記述する |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
234 \item 除去規則(T-APP) は、その型の要素がどのように作られるかを記述する |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
235 \end{enumerate} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
236 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
237 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
238 例えば命題Aが成り立つためには A という型を持つ値が存在すれば良い。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
239 しかしこの命題は A という alive な仮定に依存している。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
240 natural deduction では A の仮定を dead にするために $ \Rightarrow \mathcal{I} $ により $ \Rightarrow $ を導入する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
241 これが $ \lambda $ による抽象化(T-ABS)に対応している。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
242 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
243 \begin{eqnarray*} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
244 x : A \\ |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
245 \lambda x . x : A \rightarrow A |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
246 \end{eqnarray*} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
247 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
248 プログラムにおいて、変数 x は内部の値により型が決定される。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
249 特に、x の値が未定である場合は未定義の変数としてエラーが発生する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
250 しかし、 x を取って x を返す関数は定義することはできる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
251 これは natural deduction の $ \Rightarrow \mathcal{I} $ により仮定を discharge することに相当する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
252 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
253 また、仮定Aが成り立つ時に結論Bを得ることは、関数適用(T-APP)に相当している。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
254 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
255 \begin{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
256 \AxiomC{$A$} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
257 \AxiomC{$A \rightarrow B $} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
258 \RightLabel{T-APP} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
259 \BinaryInfC{$B$} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
260 \end{prooftree} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
261 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
262 このように、 natural deduction における証明はそのまま 型付き $ \lambda $ 計算に変換することができる。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
263 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
264 それぞれの詳細な対応は省略するが、表\ref{tbl:curry_howard_isomorphism} のような対応が存在する。 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
265 |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
266 \begin{center} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
267 \begin{table}[htbp] |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
268 \begin{tabular}{|c||c|c|} \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
269 & natural deduction & 型付き $ \lambda $ 計算 \\ \hline \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
270 hypothesis & $ A $ & 型 A を持つ変数 x \\ \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
271 conjunction & $ A \land B $ & 型 A と型 B の直積型 を持つ変数 x \\ \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
272 disjunction & $ A \lor B $ & 型 A と型 B の直和型 を持つ変数 x \\ \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
273 implication & $ A \Rightarrow B $ & 型 A を取り型 B の変数を返す関数 f \\ \hline |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
274 \end{tabular} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
275 \caption{natural deuction と 型付き $ \lambda $ 計算との対応} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
276 \label{tbl:curry_howard_isomorphism} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
277 \end{table} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
278 \end{center} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
279 % }}} |
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
280 |
55 | 281 % {{{ 依存型を持つ証明支援系言語 Agda |
282 | |
50
451c510825de
Add natural deduction and curry-howard isomorphism
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
49
diff
changeset
|
283 \section{依存型を持つ証明支援系言語 Agda} |
51 | 284 型システムを用いて証明を行なうことができる言語に Agda が存在する。% ref Agda のref |
285 Agda は依存型という強力な型システムを持っている。 | |
286 依存型とは型も第一級オブジェクトとする型であり、型を引数に取る関数や値を取って型を返す関数、型の型などが記述できる。 | |
52 | 287 この節では Agda の文法的な紹介を行なう~\cite{agda-documentation}。 % ref pdf のアレ |
51 | 288 |
289 まず Agda のプログラムは全てモジュールの内部に記述されるため、まずはトップレベルにモジュールを定義する必要がある。 | |
290 トップレベルのモジュールはファイル名と同一となる。 | |
291 例えば \verb/AgdaBasics.agda/ のモジュール名定義はリスト~\ref{src:agda-module}のようになる。 | |
292 | |
293 \lstinputlisting[label=src:agda-module, caption=Agdaのモジュールの定義する] {src/AgdaBasics.agda} | |
294 | |
295 また、Agda はインデントに意味を持つ言語であるため、インデントはきちんと揃える必要がある。 | |
296 | |
297 まず Agda におけるデータ型について触れていく。 | |
298 Agda における型指定は $:$ を用いて行なう。 | |
299 例えば、変数xが型Aを持つ、ということを表すには \verb/x : A/ と記述する。 | |
300 | |
301 データ型は Haskell や ML に似て代数的なデータ構造のパターンマッチを扱うことができる | |
302 データ型の定義は \verb/data/ キーワードを用いる。 | |
303 \verb/data/キーワードの後に \verb/where/ 句を書きインデントを深くした後、値にコンストラクタとその型を列挙する。 | |
304 例えば Bool 型を定義するとリスト~\ref{src:agda-bool}のようになる。 | |
305 | |
306 \lstinputlisting[label=src:agda-bool, caption=Agdaにおけるデータ型 Bool の定義] {src/AgdaBool.agda} | |
307 | |
308 Bool はコンストラクタ \verb/true/ か \verb/false/ を持つデータ型である。 | |
309 Bool 自身の型は \verb/Set/ であり、これは Agda が組み込みで持つ「型の型」である。 | |
310 Set は階層構造を持ち、型の型の型を指定するには Set1 と書く。 | |
311 | |
312 関数の定義は Haskell に近い。 | |
313 関数名と型を記述した後に関数の本体を \verb/=/ の後に指定する。 | |
314 関数の型は単純型付き $ \lambda$ 計算と同様に $ \rightarrow $ を用いる。 | |
315 なお、$\rightarrow$に対しては糖衣構文 \verb/->/ も用意されている。 | |
316 引数は変数名で受けることもできるが、具体的なコンストラクタを指定することでそのコンストラクタが渡された時の挙動を定義できる。 | |
317 これはパターンマッチと呼ばれ、コンストラクタで case 文を行なっているようなものである。 | |
318 例えば Bool 型の値を反転する \verb/not/ 関数を書くとリスト~\ref{src:agda-not}のようになる。 | |
319 | |
320 \lstinputlisting[label=src:agda-not, caption=Agdaにおける関数 not の定義] {src/AgdaNot.agda} | |
321 | |
322 パターンマッチは全てのコンストラクタのパターンを含まなくてはならない。 | |
323 パターンマッチは上からマッチされていくため、優先順位が存在する。 | |
324 なお、コンストラクタをいくつか指定した後に変数で受けると、変数が持ちうる値は指定したコンストラクタ以外となる。 | |
325 例えばリスト~\ref{src:agda-pattern}のnot は x には true しか入ることは無い。 | |
326 | |
327 \lstinputlisting[label=src:agda-pattern, caption=Agdaにおけるパターンマッチ] {src/AgdaPattern.agda} | |
328 | |
329 なお、マッチした値を変数として利用しない場合は \verb/_/ を用いて捨てることもできる。 | |
330 | |
331 単純型で利用した自然数もデータ型として定義できる(リスト~\ref{src:agda-nat})。 | |
332 自然数のコンストラクタは2つあり、片方は自然数ゼロ、片方は自然数を取って後続数を返すものである。 | |
333 例えば3は \verb/suc (suc (suc zero))/ となる。 | |
334 | |
335 \lstinputlisting[label=src:agda-nat, caption=Agdaにおける自然数の定義] {src/AgdaNat.agda} | |
336 | |
337 自然数に対する演算は再帰関数として定義できる。 | |
338 例えば自然数どうしの加算は二項演算子\verb/+/としてリスト~\ref{src:agda-plus}のように書ける。 | |
339 | |
340 この二項演算子は正確には中置関数である。 | |
341 前置や後置で定義できる部分を関数名に \verb/_/ として埋め込んでおくことで、関数を呼ぶ時にあたかも前置演算子のように振る舞う。 | |
342 また、Agda は関数が停止するかを判定できる。 | |
343 この加算の二項演算子は左側がゼロに対しては明かに停止する。 | |
344 左側が1以上の時の再帰時には \verb/suc n/ から \verb/n/へと減っているため、再帰で繰り返し減らすことでいつかは停止する。 | |
345 | |
346 \lstinputlisting[label=src:agda-plus, caption=Agda における自然数の加算の定義] {src/AgdaPlus.agda} | |
347 | |
52 | 348 次に依存型について見ていく。 |
349 依存型で最も基本的なものは関数型である。 | |
350 依存型を利用した関数は引数の型に依存して返す型を決定できる。 | |
351 | |
352 Agda で \verb/(x : A) -> B/ と書くと関数は型 A を持つx を受け取り、Bを返す。 | |
353 ここで B の中で x を扱っても良い。 | |
354 例えば任意の型に対する恒等関数はリスト~\ref{src:agda-id}のように書ける。 | |
355 | |
356 \lstinputlisting[label=src:agda-id, caption=依存型を持つ関数の定義] {src/AgdaId.agda} | |
357 | |
358 この恒等関数 \verb/identitiy/ は任意の型に適用可能である。 | |
359 実際に Nat へ適用した例が \verb/id-zero/ である。 | |
360 | |
361 依存型を用いることで任意の型に適用可能な多相の恒等関数を定義した。 | |
362 しかし型を明示的に指定せずとも \verb/zero/ を渡された場合は恒等関数の型は自明に \verb/Nat -> Nat/である。 | |
363 その場合、型を推論することで実際に引数として渡さないようにできる。 | |
364 これを暗黙的な引数(implicit arguments) と言い、記号 \verb/{}/ でくくる。 | |
365 | |
366 例えば恒等関数の型を暗黙的な引数にするとリスト~\ref{src:agda-implicit-id}のようになる。 | |
367 この恒等関数を利用する際は値を渡すだけで型が自動的に推論される。 | |
368 よって関数を利用する際は \verb/id-true/ のように記述できる。 | |
369 なお、関数の本体で暗黙的な引数を利用したい場合は \verb/{variableName}/ で束縛することもできる。 | |
370 | |
371 \lstinputlisting[label=src:agda-implicit-id, caption=Agdaにおける暗黙的な引数を持つ関数] {src/AgdaImplicitId.agda} | |
372 | |
373 Agda にはレコード型も存在する。 | |
374 定義を行なう際は \verb/record/キーワードの後にレコード名、型、\verb/where/ の後に \verb/field/ キーワードを入れた後、フィールド名と型名を列挙する。 | |
375 例えば x と y の二つの自然数からなるレコード \verb/Point/ を定義するとリスト~\ref{src:agda-record}のようになる。 | |
376 レコードを構築する際は \verb/record/ キーワードの後の \verb/{}/ の内部に \verb/fieldName = value/ の形で値を列挙していく。 | |
377 複数の値を列挙する際は \verb/;/ で区切る。 | |
378 | |
379 \lstinputlisting[label=src:agda-record, caption=Agdaにおけるレコード型の定義] {src/AgdaRecord.agda} | |
380 | |
381 構築されたレコードから値を取得する際には \verb/RecordName.fieldName/ という名前の関数を適用する(リスト~\ref{src:agda-record-proj} 内2行目) 。 | |
382 なお、レコードにもパターンマッチが利用できる(リスト~\ref{src:agda-record-proj} 内5行目)。 | |
383 また、値を更新する際は \verb/record oldRecord {field = value ; ... }/ という構文を利用する。 | |
384 Point の中の x の値を5増やす関数 \verb/xPlus5/ はリスト~\ref{src:agda-record-proj}の 7,8行目のように書ける。 | |
385 | |
386 \lstinputlisting[label=src:agda-record-proj, caption=Agda におけるレコードの射影、パターンマッチ、値の更新] {src/AgdaRecordProj.agda} | |
387 | |
388 Agda における部分型のように振る舞う機能として Instance Arguments が存在する。 | |
389 とあるデータ型が、ある型と名前を持つ関数を持つことを保証する。 | |
390 これは Haskell における型クラスや Java におけるインターフェースに相当する。 | |
391 Agda における部分型の制約は、必要な関数を定義した record に相当し、その制約を保証するにはその record を instance として登録することになる。 | |
392 例えば、同じ型と比較することができる、という性質を表すとリスト~\ref{src:agda-type-class}のようになる。 | |
393 具体的にはとある型 A における中置関数 \verb/_==_/ を定義することに相当する。 | |
394 | |
395 \lstinputlisting[label=src:agda-type-class, caption=Agdaにおける部分型制約] {src/AgdaTypeClass.agda} | |
396 | |
397 ある型 T がこの部分型制約を満たすことを示すには、型 T でこのレコードを作成できることを示し、それを instance 構文で登録する。 | |
55 | 398 型Nat が Eq の上位型であることを記述するとリスト~\ref{src:agda-instance}のようになる。 |
52 | 399 |
400 \lstinputlisting[label=src:agda-instance, caption=Agdaにおける部分型関係の構築] {src/AgdaInstance.agda} | |
401 | |
402 これで \verb/Eq/ が要求される関数に対して Nat が適用できるようになる。 | |
403 例えば型 A の要素を持つ List A から要素を探してくる elem を定義する。 | |
404 部分型のインスタンスは \verb/{{}}/ 内部に名前と型名で記述する。 | |
405 なお、名前部分は必須である。 | |
406 仮に変数として受けても利用しない場合は \verb/_/ で捨てると良い。 | |
407 部分型として登録した record は関数本体において \verb/{{variableName}}/ という構文で変数に束縛できる。 | |
408 | |
409 \lstinputlisting[label=src:agda-use-instance, caption=Agdaにおける部分型を使う関数の定義] {src/AgdaElem.agda.replaced} | |
410 | |
411 この \verb/elem/ 関数はリスト~\ref{src:agda-elem-apply} のように利用できる。 | |
412 Nat型の要素を持つリストの内部に4が含まれるか確認している。 | |
413 この \verb/listHas4/ は \verb/true/ に評価される。 | |
414 なお、 \verb/--/ の後はコメントである。 | |
415 | |
416 \lstinputlisting[label=src:agda-elem-apply, caption=部分型を持つ関数の適用] {src/AgdaElemApply.agda.replaced} | |
417 | |
53
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
418 最後にモジュールについて述べる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
419 モジュールはほとんど名前空間として作用する。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
420 なお、依存型の解決はモジュールのインポート時に行なわれる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
421 モジュールをインポートする時は \verb/import/ キーワードを指定する。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
422 また、インポートを行なう際に名前を別名に変更することもでき、その際は \verb/as/ キーワードを用いる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
423 モジュールから特定の関数のみをインポートする場合は \verb/using/ キーワードを、関数の名前を変える時は \verb/renaming/キーワードを、特定の関数のみを隠す場合は \verb/hiding/ キーワードを用いる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
424 なお、モジュールに存在する関数をトップレベルで用いる場合は \verb/open/ キーワードを使うことで展開できる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
425 モジュールをインポートする例をリスト~\ref{src:agda-import}に示す。 |
52 | 426 |
53
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
427 \lstinputlisting[label=src:agda-import, caption=Agdaにおけるモジュールのインポート] {src/AgdaImport.agda} |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
428 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
429 また、モジュールには値を渡すことができる。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
430 そのようなモジュールは Parameterized Module と呼ばれ、渡された値はそのモジュール内部で一貫して扱える。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
431 例えば要素の型と比較する二項演算子を使って並べ替えをするモジュール\verb/Sort/ を考える。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
432 そのモジュールは引数に型Aと二項演算子 \verb/</を取り、ソートする関数を提供する。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
433 \verb/Sort/モジュールを \verb/Nat/ と \verb/Bool/ で利用した例がリスト~\ref{src:agda-parameterized-module}である。 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
434 |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
435 \lstinputlisting[label=src:agda-parameterized-module, caption=Agda における Parameterized Module] {src/AgdaParameterizedModule.agda} |
9902994fbd1a
Writing agda description ...
atton <atton@cr.ie.u-ryukyu.ac.jp>
parents:
52
diff
changeset
|
436 |
55 | 437 % }}} |
438 | |
439 % {{{ Reasoning | |
51 | 440 |
49 | 441 \section{Reasoning} |
55 | 442 次に Agda における証明を記述していく。 |
443 例題として、自然数の加法の可換法則を示す。 | |
49 | 444 |
55 | 445 証明を行なうためにまずは自然数を定義する。 |
446 今回用いる自然数の定義は以下のようなものである。 | |
447 | |
448 \begin{itemize} | |
449 \item 0 は自然数である | |
450 \item 任意の自然数には後続数が存在する | |
451 \item 0 はいかなる自然数の後続数でもない | |
452 \item 異なる自然数どうしの後続数は異なる ($ n \neq m \rightarrow S n \neq S m $) | |
453 \item 0がある性質を満たし、aがある性質を満たせばその後続数 S(n) も自然数である | |
454 \end{itemize} | |
455 | |
456 この定義は peano arithmetic における自然数の定義である。 | |
457 | |
458 Agda で自然数型 Nat を定義するとリスト \ref{src:agda-nat-2} のようになる。 | |
459 | |
460 \lstinputlisting[label=src:agda-nat-2, caption=Agda における自然数型 Nat の定義] {src/Nat.agda} | |
461 | |
462 自然数型 Nat は2つのコンストラクタを持つ。 | |
463 | |
464 \begin{itemize} | |
465 \item O | |
466 | |
467 引数を持たないコンストラクタ。これが0に相当する。 | |
468 | |
469 \item S | |
470 | |
471 Nat を引数に取るコンストラクタ。これが後続数に相当する。 | |
472 | |
473 \end{itemize} | |
474 | |
475 よって、数値の 3 は \verb/S (S (S O))/ のように表現される。 | |
476 Sの個数が数値に対応する。 | |
477 | |
478 次に加算を定義する(リスト\ref{src:agda-nat-add})。 | |
479 | |
480 \lstinputlisting[label=src:agda-nat-add, caption=Agdaにおける自然数型に対する加算の定義] {src/NatAdd.agda} | |
481 | |
482 加算は中置関数 \verb/_+_/ として定義する。 | |
483 2つの Nat を取り、Natを返す。 | |
484 関数 \verb/_+_/ はパターンマッチにより処理を変える。 | |
485 0に対して m 加算する場合は m であり、 n の後続数に対して m 加算する場合は n に m 加算した数の後続数とする。 | |
486 S を左の数から右の数へ1つずつ再帰的に移していくような加算である。 | |
487 | |
488 例えば 3 + 1 といった計算は (S (S (S O))) + (S O) のように記述される。 | |
489 ここで 3 + 1 が 4と等しいことの証明を行なう。 | |
490 | |
491 等式の証明には agda の standard library における Relation.Binary.Core の定義を用いる。 | |
492 | |
493 \lstinputlisting[label=src:agda-equiv, caption= Relation.Binary.Core による等式を示す型 $ \equiv $] {src/Equiv.agda.replaced} | |
494 Agda において等式は、等式を示すデータ型 $ \equiv $ により定義される。 | |
495 $ \equiv $ は同じ両辺が同じ項に簡約される時にコンストラクタ refl で構築できる。 | |
496 | |
497 実際に 3 + 1 = 4 の証明は refl で構成できる(リスト\ref{src:agda-three-plus-one})。 | |
498 | |
499 \lstinputlisting[label=src:agda-three-plus-one, caption= Agda における 3 + 1 の結果が 4 と等しい証明] {src/ThreePlusOne.agda} | |
500 | |
501 3+1 という関数を定義し、その型として証明すべき式を記述し、証明を関数の定義として定義する。 | |
502 証明する式は \verb/(S (S (S O))) + (S O)≡(S (S (S (S O))))/ である。 | |
503 今回は \verb/_+_/ 関数の定義により \verb/ (S (S (S (S O)))) / に簡約されるためにコンストラクタ refl が証明となる。 | |
504 | |
505 $ \equiv $ によって証明する際、必ず同じ式に簡約されるとは限らないため、いくつかの操作が Relation.Binary.PropositionalEquality に定義されている。 | |
506 | |
507 \begin{itemize} | |
508 \item sym : $ x \equiv y \rightarrow y \equiv x $ | |
509 | |
510 等式が証明できればその等式の左辺と右辺を反転しても等しい。 | |
511 | |
512 \item cong : $ f \rightarrow x \equiv y \rightarrow f x \equiv f y $ | |
513 | |
514 証明した等式に同じ関数を与えても等式は保たれる。 | |
515 | |
516 \item trans : $ x \equiv y \rightarrow y \equiv z \rightarrow x \equiv z $ | |
517 | |
518 2つの等式に表れた同じ項を用いて2つの等式を繋げた等式は等しい。 | |
519 \end{itemize} | |
520 | |
521 ではこれから nat の加法の交換法則を証明していく(リスト\ref{src:agda-nat-add-sym})。 | |
522 | |
523 \lstinputlisting[label=src:agda-nat-add-sym, caption= Agda における加法の交換法則の証明] {src/NatAddSym.agda} | |
524 | |
525 証明する式は $ n + m \equiv m + n $ である。 | |
526 n と m は Nat であるため、それぞれがコンストラクタ O か S により構成される。 | |
527 そのためにパターンは4通りある。 | |
528 | |
529 \begin{itemize} | |
530 \item n = O, m = O | |
531 | |
532 + の定義により、 O に簡約されるため refl で証明できる。 | |
533 | |
534 \item n = O, m = S m | |
535 | |
536 $ O + (S m) \equiv (S m) + O $ を証明することになる。 | |
537 この等式は + の定義により $ O + (S m) \equiv S (m + O) $ と変形できる。 | |
538 $ S (m + O) $ は $ m + O $ に S を加えたものであるため、 cong を用いて再帰的に \verb/addSym/ を実行することで証明できる。 | |
539 | |
540 この2つの証明はこのような意味を持つ。 | |
541 n が 0 であるとき、 m も 0 なら簡約により等式が成立する。 | |
542 n が 0 であり、 m が 0 でないとき、 m は後続数である。 | |
543 よって m が (S x) と書かれる時、 x は m の前の値である。 | |
544 前の値による交換法則を用いてからその結果の後続数も + の定義により等しい。 | |
545 | |
546 ここで、 \verb/addSym/ に渡される m は1つ値が減っているため、最終的には n = 0, m = 0 である refl にまで簡約され、等式が得られる。 | |
547 | |
548 \item n = S n, m = O | |
549 | |
550 $ (S n) + O \equiv O + (S n) $ を証明する。 | |
551 この等式は + の定義により $ S (n + O) \equiv (S n) $ と変形できる。 | |
552 さらに変形すれば $ S (n + O) \equiv S (O + n) $ となる。 | |
553 よって \verb/addSym/ により O と n を変換した後に cong で S を加えることで証明ができる。 | |
554 | |
555 ここで、 $ O + n \equiv n $ は + の定義により自明であるが、$ n + O \equiv n $ をそのまま導出できないことに注意して欲しい。 | |
556 + の定義は左側の項から S を右側の項への移すだけであるため、右側の項への演算はしない。 | |
557 | |
558 \item n = S n, m = S m | |
559 | |
560 3つのパターンは証明したが、このパターンは少々長くなるため別に解説することとする。 | |
561 \end{itemize} | |
562 | |
563 3 つのパターンにおいては refl や cong といった単純な項で証明を行なうことができた。 | |
564 しかし長い証明になると refl や cong といった式を trans で大量に繋げていく必要性がある。 | |
565 長い証明を分かりやすく記述するために $ \equiv $-Reasoning を用いる。 | |
566 | |
567 $ \equiv $-Reasoning では等式の左辺を begin の後に記述し、等式の変形を $ \equiv \langle expression \rangle $ に記述することで変形していく。 | |
568 最終的に等式の左辺を $ \blacksquare $ の項へと変形することで等式の証明が得られる。 | |
569 | |
570 自然数の加法の交換法則を $ \equiv $-Reasoning を用いて証明した例がリスト\ref{src:agda-reasoning}である。 | |
571 特に n と m が1以上である時の証明に注目する。 | |
572 | |
573 \lstinputlisting[label=src:agda-reasoning, caption= $ \equiv $ - Reasoning を用いた証明の例] {src/Reasoning.agda.replaced} | |
574 | |
575 まず \verb/ (S n) + (S m)/ は + の定義により \verb/ S (n + (S m)) / に等しい。 | |
576 よって refl で導かれる。 | |
577 なお、基本的に定義などで同じ項に簡約される時は refl によって記述することが多い。 | |
578 | |
579 次に \verb/S (n + (S m)) / に対して addSym を用いて交換し、 cong によって S を追加することで \verb/ S ((S m) + n) / を得る。 | |
580 これは、前3パターンにおいて + の右辺の項が 1以上であっても上手く交換法則が定義できたことを利用して項を変形している。 | |
581 このように同じ法則の中でも、違うパターンで証明できた部分を用いて別パターンの証明を行なうこともある。 | |
582 | |
583 最後に \verb/S ((S m) + n)/ から \verb/(S m) + (S n)/を得なくてはならない。 | |
584 しかし、 + の定義には右辺に対して S を移動する演算が含まれていない。 | |
585 よってこのままでは証明することができない。 | |
586 そのため、等式 $ S (m + n) \equiv m + (S n) $ を addToRight として定義する。 | |
587 addToRight の証明の解説は省略する。 | |
588 addToRight を用いることで \verb/S ((S m) + n)/ から \verb/(S m) + (S n)/を得られた。 | |
589 これで等式 $ (S m) + (S n) \equiv (S n) + (S m) $ の証明が完了した。 | |
590 | |
591 自然数に対する + の演算を考えた時にありえるコンストラクタの組み合せ4パターンのいずれかでも交換法則の等式が成り立つことが分かった。 | |
592 このように、Agda における等式の証明は、定義や等式を用いて右辺と左辺を同じ項に変形することで行なわれる。 | |
593 | |
594 % }}} |