annotate slide/slide.html @ 17:61117df82f51 default tip

fix
author ryokka
date Wed, 16 Jan 2019 12:42:49 +0900
parents 07e1ccdfd844
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
1
a87fec07fd78 add slide
ryokka
parents:
diff changeset
2
a87fec07fd78 add slide
ryokka
parents:
diff changeset
3
a87fec07fd78 add slide
ryokka
parents:
diff changeset
4
a87fec07fd78 add slide
ryokka
parents:
diff changeset
5
a87fec07fd78 add slide
ryokka
parents:
diff changeset
6 <!DOCTYPE html>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
7 <html>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
8 <head>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
9 <meta http-equiv="content-type" content="text/html;charset=utf-8">
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
10 <title>GearsOS の Hoare Logic を用いた検証</title>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
11
a87fec07fd78 add slide
ryokka
parents:
diff changeset
12 <meta name="generator" content="Slide Show (S9) v4.0.1 on Ruby 2.4.1 (2017-03-22) [x86_64-darwin16]">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
13 <meta name="author" content="外間政尊 , 河野真治" >
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
14
a87fec07fd78 add slide
ryokka
parents:
diff changeset
15 <!-- style sheet links -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
16 <link rel="stylesheet" href="s6/themes/projection.css" media="screen,projection">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
17 <link rel="stylesheet" href="s6/themes/screen.css" media="screen">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
18 <link rel="stylesheet" href="s6/themes/print.css" media="print">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
19 <link rel="stylesheet" href="s6/themes/blank.css" media="screen,projection">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
20
a87fec07fd78 add slide
ryokka
parents:
diff changeset
21 <!-- JS -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
22 <script src="s6/js/jquery-1.11.3.min.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
23 <script src="s6/js/jquery.slideshow.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
24 <script src="s6/js/jquery.slideshow.counter.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
25 <script src="s6/js/jquery.slideshow.controls.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
26 <script src="s6/js/jquery.slideshow.footer.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
27 <script src="s6/js/jquery.slideshow.autoplay.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
28
a87fec07fd78 add slide
ryokka
parents:
diff changeset
29 <!-- prettify -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
30 <link rel="stylesheet" href="scripts/prettify.css">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
31 <script src="scripts/prettify.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
32
a87fec07fd78 add slide
ryokka
parents:
diff changeset
33 <script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
34 $(document).ready( function() {
a87fec07fd78 add slide
ryokka
parents:
diff changeset
35 Slideshow.init();
a87fec07fd78 add slide
ryokka
parents:
diff changeset
36
a87fec07fd78 add slide
ryokka
parents:
diff changeset
37 $('code').each(function(_, el) {
a87fec07fd78 add slide
ryokka
parents:
diff changeset
38 if (!el.classList.contains('noprettyprint')) {
a87fec07fd78 add slide
ryokka
parents:
diff changeset
39 el.classList.add('prettyprint');
a87fec07fd78 add slide
ryokka
parents:
diff changeset
40 }
a87fec07fd78 add slide
ryokka
parents:
diff changeset
41 });
a87fec07fd78 add slide
ryokka
parents:
diff changeset
42 prettyPrint();
a87fec07fd78 add slide
ryokka
parents:
diff changeset
43 } );
a87fec07fd78 add slide
ryokka
parents:
diff changeset
44
a87fec07fd78 add slide
ryokka
parents:
diff changeset
45 </script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
46
a87fec07fd78 add slide
ryokka
parents:
diff changeset
47 <!-- Better Browser Banner for Microsoft Internet Explorer (IE) -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
48 <!--[if IE]>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
49 <script src="s6/js/jquery.microsoft.js"></script>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
50 <![endif]-->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
51
a87fec07fd78 add slide
ryokka
parents:
diff changeset
52
a87fec07fd78 add slide
ryokka
parents:
diff changeset
53
a87fec07fd78 add slide
ryokka
parents:
diff changeset
54 </head>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
55 <body>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
56
a87fec07fd78 add slide
ryokka
parents:
diff changeset
57 <div class="layout">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
58 <div id="header"></div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
59 <div id="footer">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
60 <div align="right">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
61 <img src="s6/images/logo.svg" width="200px">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
62 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
63 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
64 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
65
a87fec07fd78 add slide
ryokka
parents:
diff changeset
66 <div class="presentation">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
67
a87fec07fd78 add slide
ryokka
parents:
diff changeset
68 <div class='slide cover'>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
69 <table width="90%" height="90%" border="0" align="center">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
70 <tr>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
71 <td>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
72 <div align="center">
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
73 <h1><font color="#808db5">GearsOS の Hoare Logic を用いた検証</font></h1>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
74 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
75 </td>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
76 </tr>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
77 <tr>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
78 <td>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
79 <div align="left">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
80 外間政尊 , 河野真治
17
ryokka
parents: 16
diff changeset
81 - 琉球大学 : 並列信頼研究室
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
82 <hr style="color:#ffcc00;background-color:#ffcc00;text-align:left;border:none;width:100%;height:0.2em;">
a87fec07fd78 add slide
ryokka
parents:
diff changeset
83 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
84 </td>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
85 </tr>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
86 </table>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
87 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
88
a87fec07fd78 add slide
ryokka
parents:
diff changeset
89
a87fec07fd78 add slide
ryokka
parents:
diff changeset
90
a87fec07fd78 add slide
ryokka
parents:
diff changeset
91 <div class='slide'>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
92 <!-- 発表20分、質疑応答5分 -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
93
a87fec07fd78 add slide
ryokka
parents:
diff changeset
94
a87fec07fd78 add slide
ryokka
parents:
diff changeset
95 <!-- _S9SLIDE_ -->
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
96 <h2 id="os-の検証技術としての-hoarelogic-の問題点">OS の検証技術としての HoareLogic の問題点</h2>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
97 <ul>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
98 <li>OS やアプリケーションなどの信頼性は重要な課題</li>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
99 <li>信頼性を上げるために仕様を検証する必要</li>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
100 <li>仕様検証の手法として Floyd-Hoare Logic (以下 HoareLogic) がある
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
101 <ul>
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
102 <li>事前条件(Pre Condition)が成り立つとき、関数(Command)を実行、それが停止したとき、事後条件(Post Condition)を満たす</li>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
103 </ul>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
104 </li>
17
ryokka
parents: 16
diff changeset
105 <li>OS の検証などで使われているが、実装の記述の他に実装に対応する証明が必要となる</li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
106 <li>HoareLogic の単位である代入や、WhileLoop に対応する分解が煩雑</li>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
107 </ul>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
108
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
109
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
110
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
111 </div>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
112
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
113 <div class='slide'>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
114 <!-- _S9SLIDE_ -->
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
115 <h2 id="gearsos-によるメタ計算としての-hoarelogic-の導入">GearsOS によるメタ計算としての HoareLogic の導入</h2>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
116 <ul>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
117 <li>当研究室では 処理の単位を <strong>CodeGear</strong>、データの単位を <strong>DataGear</strong> としてプログラムを記述する手法を提案</li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
118 <li>CodeGear は Input DataGear を受け取り、処理を行って Output DataGear に書き込む</li>
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
119 <li>この単位を用いて信頼性の高い OS として GearsOS を開発している</li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
120 <li>Gears OS の信頼性を高めるため、 Gears の単位を用いた HoareLogic ベースの検証手法を提案する</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
121 <li>CodeGear は CbC により、C と同等の速度で実行可能かつ Agda の継続記述にもなっている</li>
17
ryokka
parents: 16
diff changeset
122 <li>証明への変換を必要とせずに HoareLogic による証明をメタ計算として記述できるようになった</li>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
123 </ul>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
124
a87fec07fd78 add slide
ryokka
parents:
diff changeset
125
a87fec07fd78 add slide
ryokka
parents:
diff changeset
126
a87fec07fd78 add slide
ryokka
parents:
diff changeset
127 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
128
a87fec07fd78 add slide
ryokka
parents:
diff changeset
129 <div class='slide'>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
130 <!-- _S9SLIDE_ -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
131 <h2 id="gears-について">Gears について</h2>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
132 <ul>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
133 <li><strong>Gears</strong> は当研究室で提案しているプログラム記述手法</li>
17
ryokka
parents: 16
diff changeset
134 <li>処理の単位を <strong>CodeGear</strong> 、データの単位を <strong>DataGear</strong></li>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
135 <li>CodeGear は引数として Input の DataGear を受け取り、 Output の DataGear を返す</li>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
136 <li>Output の DataGear は次の CodeGear の Input として接続される
a87fec07fd78 add slide
ryokka
parents:
diff changeset
137 <!-- [fig1](file://./fig/cgdg.pdf) --></li>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
138 <li>CodeGear の接続処理は通常の計算とは異なるメタ計算として定義
a87fec07fd78 add slide
ryokka
parents:
diff changeset
139 <ul>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
140 <li>メタ計算で信頼性の検証を行う</li>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
141 </ul>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
142 </li>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
143 </ul>
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
144 <p style="text-align:center;"><img src="./pic/cgdg-small.svg" alt="" width="75%" height="75%" /></p>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
145 <!-- ![cgdg](./pic/codeGear_dataGear.pdf){} -->
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
146 <!-- <p style="text-align:center;"><img src="./pic/cgdg.svg" alt="" width="30%" height="30%"/></p> -->
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
147
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
148
a87fec07fd78 add slide
ryokka
parents:
diff changeset
149
a87fec07fd78 add slide
ryokka
parents:
diff changeset
150 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
151
a87fec07fd78 add slide
ryokka
parents:
diff changeset
152 <div class='slide'>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
153 <!-- _S9SLIDE_ -->
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
154 <h2 id="agda-での-datagear">Agda での DataGear</h2>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
155 <ul>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
156 <li><strong>DataGear</strong> は CodeGear でつかわれる引数</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
157 <li><strong>データ型</strong>と<strong>レコード型</strong>がある</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
158 <li>データ型は一つのデータ
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
159 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
160 <div class="code"><pre>data Nat : Set where
17
ryokka
parents: 16
diff changeset
161 zero : Nat
ryokka
parents: 16
diff changeset
162 suc : Nat → Nat
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
163 </pre></div>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
164 </div>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
165 </div>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
166 </li>
14
ryokka
parents: 12
diff changeset
167 <li>レコード型は複数のデータをまとめる
ryokka
parents: 12
diff changeset
168 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
ryokka
parents: 12
diff changeset
169 <div class="code"><pre>record Env : Set where
17
ryokka
parents: 16
diff changeset
170 field
ryokka
parents: 16
diff changeset
171 varn : Nat
ryokka
parents: 16
diff changeset
172 vari : Nat
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
173 </pre></div>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
174 </div>
14
ryokka
parents: 12
diff changeset
175 </div>
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
176 </li>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
177 </ul>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
178
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
179
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
180
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
181 </div>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
182
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
183 <div class='slide'>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
184 <!-- _S9SLIDE_ -->
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
185 <h2 id="agda-での-gears-の記述whiletest">Agda での Gears の記述(whileTest)</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
186 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
187 <li>Agda での CodeGear は継続渡し (CPS : Continuation Passing Style) で記述された関数</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
188 <li><strong>{}</strong> は暗黙的(推論される)</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
189 <li>継続渡しの関数は引数として継続を受け取って継続に計算結果を渡す</li>
17
ryokka
parents: 16
diff changeset
190 <li>CodeGear の型は<strong>引数 → (Code : fa → t) → t</strong></li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
191 <li><strong>t</strong> は継続(最終的に返すもの)</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
192 <li><strong>(Code : fa → t)</strong> は次の継続先
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
193 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
194 <div class="code"><pre>whileTest : {t : Set} → (c10 : Nat)
17
ryokka
parents: 16
diff changeset
195 → (Code : Env → t) → t
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
196 whileTest c10 next = next (record {varn = c10
17
ryokka
parents: 16
diff changeset
197 ; vari = 0} )
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
198 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
199 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
200 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
201 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
202 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
203
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
204
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
205
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
206 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
207
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
208 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
209 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
210 <h2 id="agda-での-gears-の記述whileloop">Agda での Gears の記述(whileLoop)</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
211 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
212 <li>関数の動作を条件で変えたいときはパターンマッチを行う</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
213 <li>whileLoop は varn が 0 より大きい間ループする</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
214 <li><strong>lt</strong> は Nat を2つ受け取って値の大小を比較する関数
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
215 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
216 <div class="code"><pre>whileLoop : {t : Set} → Env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
217 → (Code : Env → t) → t
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
218 whileLoop env next with lt 0 (varn env)
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
219 whileLoop env next | false = next env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
220 whileLoop env next | true =
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
221 whileLoop (record {varn = (varn env) - 1
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
222 ; vari = (vari env) + 1}) next
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
223 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
224 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
225 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
226 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
227 <div class="code"><pre>lt : Nat → Nat → Bool
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
228 lt x y with (suc x ) ≤? y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
229 lt x y | yes p = true
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
230 lt x y | no ¬p = false
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
231 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
232 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
233 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
234 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
235 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
236
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
237
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
238
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
239 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
240
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
241 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
242 <!-- _S9SLIDE_ -->
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
243 <h2 id="agda-での証明">Agda での証明</h2>
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
244 <ul>
17
ryokka
parents: 16
diff changeset
245 <li>関数との違いは<strong>型が証明すべき論理式</strong>で<strong>関数自体がそれを満たす導出</strong>
ryokka
parents: 16
diff changeset
246 <ul>
ryokka
parents: 16
diff changeset
247 <li><strong>refl</strong> は <strong>x == x</strong> で左右の項が等しいことの証明</li>
ryokka
parents: 16
diff changeset
248 <li><strong>cong</strong> は 関数と x ≡ y 受け取って、x ≡ y の両辺に関数を適応しても等しいことが変わらないことの証明</li>
ryokka
parents: 16
diff changeset
249 </ul>
ryokka
parents: 16
diff changeset
250 </li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
251 <li><strong>+zero</strong> は任意の自然数の右から zero を足しても元の数と等しいことの証明
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
252 <ul>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
253 <li><strong>y = zero</strong> のときは <strong>zero ≡ zero</strong> のため refl</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
254 <li><strong>y = suc y</strong> のときは cong を使い y の数を減らして再帰的に<strong>+zero</strong>を行っている</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
255 <li>y の数を減らしても大丈夫なことを cong の関数として受け取った数を suc する関数で保証している
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
256 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
257 <div class="code"><pre>+zero : { y : Nat } → y + zero ≡ y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
258 +zero {zero} = refl
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
259 +zero {suc y} = cong ( λ x → suc x ) ( +zero {y} )
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
260 </pre></div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
261 </div>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
262 </div>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
263 </li>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
264 </ul>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
265 </li>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
266 </ul>
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
267
a87fec07fd78 add slide
ryokka
parents:
diff changeset
268
a87fec07fd78 add slide
ryokka
parents:
diff changeset
269
a87fec07fd78 add slide
ryokka
parents:
diff changeset
270 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
271
a87fec07fd78 add slide
ryokka
parents:
diff changeset
272 <div class='slide'>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
273 <!-- _S9SLIDE_ -->
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
274 <h2 id="agda-での項変換による証明-13">Agda での項変換による証明 1/3</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
275 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
276 <li>次は<strong>x + y ≡ y + x</strong> の証明 <strong>+-sym</strong></li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
277 <li>項変換の例として zero, suc y のパターンをみる</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
278 <li><strong>zero + suc y</strong>を変換して<strong>suc y + zero</strong>にする</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
279 <li>begin の下の行に変形したい式を記述</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
280 <li><strong>≡⟨ ⟩</strong> に変形規則、その次の行に変換した結果、 <strong>∎</strong> が項変換終了</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
281 <li>{ }0, { }1 は ? で置いたあとコンパイルを通すと Agda が示してくれる
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
282 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
283 <div class="code"><pre>+-sym : { x y : Nat } → x + y ≡ y + x
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
284 +-sym {zero} {zero} = refl
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
285 +-sym {zero} {suc y} = let open ≡-Reasoning in
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
286 begin
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
287 zero + suc y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
288 ≡⟨ { }0 ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
289 { }1
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
290
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
291 ----------------------
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
292 ?0 : zero + suc y ≡ suc y + zero
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
293 ?1 : Nat
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
294 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
295 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
296 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
297 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
298 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
299
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
300
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
301
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
302 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
303
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
304 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
305 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
306 <h2 id="agda-での証明項変換-23">Agda での証明(項変換) 2/3</h2>
14
ryokka
parents: 12
diff changeset
307 <ul>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
308 <li>はじめの変換規則は何も書かずに簡約</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
309 <li>次に右から zero を足しても等しくなる証明規則を使いたい
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
310 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
311 <div class="code"><pre>+-sym {zero} {suc y} = let open ≡-Reasoning in
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
312 begin
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
313 zero + suc y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
314 ≡⟨⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
315 suc y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
316 ≡⟨ { }0 ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
317 { }1
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
318
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
319 ----------------------
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
320 ?0 : suc y ≡ suc y + zero
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
321 ?1 : Nat
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
322 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
323 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
324 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
325 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
326 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
327
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
328
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
329
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
330 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
331
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
332 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
333 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
334 <h2 id="agda-での証明項変換-33">Agda での証明(項変換) 3/3</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
335 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
336 <li>証明の例で使用した<strong>+zero</strong>は<strong>y + zero ≡ y</strong></li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
337 <li>これを使いたいが今回は<strong>y + zero ≡ y</strong></li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
338 <li>Agda の StandartLibrary にある sym を用いて <strong>+zero</strong> を <strong>y + zero ≡ y</strong> として適応することで証明ができる
17
ryokka
parents: 16
diff changeset
339 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
ryokka
parents: 16
diff changeset
340 <div class="code"><pre>-- +zero : { y : Nat } → y + zero ≡ y
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
341 +-sym {zero} {suc y} = let open ≡-Reasoning in
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
342 begin
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
343 zero + suc y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
344 ≡⟨⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
345 suc y
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
346 ≡⟨ sym +zero ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
347 suc y + zero
17
ryokka
parents: 16
diff changeset
348
ryokka
parents: 16
diff changeset
349 sym : Symmetric {A = A} _≡_
ryokka
parents: 16
diff changeset
350 sym refl = refl
ryokka
parents: 16
diff changeset
351 </pre></div>
ryokka
parents: 16
diff changeset
352 </div>
ryokka
parents: 16
diff changeset
353 </div>
ryokka
parents: 16
diff changeset
354 </li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
355 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
356
17
ryokka
parents: 16
diff changeset
357
ryokka
parents: 16
diff changeset
358
ryokka
parents: 16
diff changeset
359 </div>
ryokka
parents: 16
diff changeset
360
ryokka
parents: 16
diff changeset
361 <div class='slide'>
ryokka
parents: 16
diff changeset
362 <!-- _S9SLIDE_ -->
ryokka
parents: 16
diff changeset
363 <h2 id="hoarelogicをベースとした-gears-での検証手法">HoareLogicをベースとした Gears での検証手法</h2>
ryokka
parents: 16
diff changeset
364 <ul>
ryokka
parents: 16
diff changeset
365 <li>今回 HoareLogic で証明する次のようなコードを検証した</li>
ryokka
parents: 16
diff changeset
366 <li>このプログラムは変数iとnをもち、 n&gt;0 の間nの値を減らし、i の値を増やす</li>
ryokka
parents: 16
diff changeset
367 <li>n==0 のとき停止するため、終了時の変数の結果は i==10、n==0 になるはずである。
ryokka
parents: 16
diff changeset
368 <div class="language-C highlighter-coderay"><div class="CodeRay">
ryokka
parents: 16
diff changeset
369 <div class="code"><pre> n = <span style="color:#00D">10</span>;
ryokka
parents: 16
diff changeset
370 i = <span style="color:#00D">0</span>;
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
371 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
372 </div>
17
ryokka
parents: 16
diff changeset
373 </div>
ryokka
parents: 16
diff changeset
374 <div class="language-c highlighter-coderay"><div class="CodeRay">
ryokka
parents: 16
diff changeset
375 <div class="code"><pre> <span style="color:#080;font-weight:bold">while</span> (n&gt;<span style="color:#00D">0</span>)
ryokka
parents: 16
diff changeset
376 {
ryokka
parents: 16
diff changeset
377 i++;
ryokka
parents: 16
diff changeset
378 n--;
ryokka
parents: 16
diff changeset
379 }
ryokka
parents: 16
diff changeset
380 </pre></div>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
381 </div>
17
ryokka
parents: 16
diff changeset
382 </div>
ryokka
parents: 16
diff changeset
383 </li>
ryokka
parents: 16
diff changeset
384 </ul>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
385
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
386
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
387
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
388 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
389
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
390 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
391 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
392 <h2 id="gears-をベースにしたプログラム">Gears をベースにしたプログラム</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
393 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
394 <li>test は whileTest と whileLoop を使った Gears のプログラム</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
395 <li>whileTest の継続先にDataGear を受け取って whileLoop に渡す
14
ryokka
parents: 12
diff changeset
396 <ul>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
397 <li><strong>(λ 引数 → )</strong>は無名関数で引数を受け取って継続する</li>
14
ryokka
parents: 12
diff changeset
398 </ul>
ryokka
parents: 12
diff changeset
399 </li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
400 <li>説明のため whileTest と whileLoop の型を載せておく
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
401 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
402 <div class="code"><pre>test : Env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
403 test = whileTest 10 (λ env → whileLoop env (λ env1 → env1))
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
404 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
405 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
406 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
407 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
408 <div class="code"><pre>whileTest : {t : Set} → (c10 : Nat)
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
409 → (Code : Env → t) → t
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
410 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
411 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
412 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
413 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
414 <div class="code"><pre>whileLoop : {t : Set} → Env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
415 → (Code : Env → t) → t
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
416 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
417 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
418 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
419 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
420 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
421
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
422
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
423
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
424 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
425
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
426 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
427 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
428 <h2 id="gears-をベースにした-hoarelogic-と証明全体">Gears をベースにした HoareLogic と証明(全体)</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
429 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
430 <li>proofGears は HoareLogic をベースとした証明
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
431 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
432 <li>先程のプログラムと違い、引数として証明も持っている</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
433 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
434 </li>
14
ryokka
parents: 12
diff changeset
435 <li>whileTest’ の継続に conversion1、その継続に whileLoop’ が来て最後の継続に vari が c10 と等しい
ryokka
parents: 12
diff changeset
436 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
437 <div class="code"><pre>-- test = whileTest 10 (λ env → whileLoop env (λ env1 → env1))
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
438 proofGears : {c10 : Nat } → Set
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
439 proofGears {c10} = whileTest' {_} {_} {c10} (λ n p1 →
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
440 conversion1 n p1 (λ n1 p2 → whileLoop' n1 p2
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
441 (λ n2 → ( vari n2 ≡ c10 ))))
14
ryokka
parents: 12
diff changeset
442 </pre></div>
ryokka
parents: 12
diff changeset
443 </div>
ryokka
parents: 12
diff changeset
444 </div>
ryokka
parents: 12
diff changeset
445 </li>
ryokka
parents: 12
diff changeset
446 </ul>
ryokka
parents: 12
diff changeset
447
ryokka
parents: 12
diff changeset
448
ryokka
parents: 12
diff changeset
449
ryokka
parents: 12
diff changeset
450 </div>
ryokka
parents: 12
diff changeset
451
ryokka
parents: 12
diff changeset
452 <div class='slide'>
ryokka
parents: 12
diff changeset
453 <!-- _S9SLIDE_ -->
ryokka
parents: 12
diff changeset
454 <h2 id="gears-と-hoarelogic-をベースにした証明whiletest">Gears と HoareLogic をベースにした証明(whileTest)</h2>
ryokka
parents: 12
diff changeset
455 <ul>
ryokka
parents: 12
diff changeset
456 <li>最初の Command なので PreCondition がない</li>
ryokka
parents: 12
diff changeset
457 <li>proof2は Post Condition が成り立つことの証明
ryokka
parents: 12
diff changeset
458 <ul>
ryokka
parents: 12
diff changeset
459 <li><strong><em>/\</em></strong> は pi1 と pi2 のフィールドをもつレコード型</li>
17
ryokka
parents: 16
diff changeset
460 <li>これは2つのものを引数に取り、両方が同時に成り立つことを表している</li>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
461 <li><strong>refl</strong> は <strong>x == x</strong> で左右の項が等しいことの証明</li>
14
ryokka
parents: 12
diff changeset
462 </ul>
ryokka
parents: 12
diff changeset
463 </li>
ryokka
parents: 12
diff changeset
464 <li>Gears での PostCondition は <strong>引数 → (Code : fa → PostCondition → t) → t</strong>
ryokka
parents: 12
diff changeset
465 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
466 <div class="code"><pre>-- whileTest : {t : Set} → (c10 : Nat) → (Code : Env → t) → t
17
ryokka
parents: 16
diff changeset
467 whileTest' : {t : Set} → {c10 : Nat } →
14
ryokka
parents: 12
diff changeset
468 (Code : (env : Env) →
ryokka
parents: 12
diff changeset
469 ((vari env) ≡ 0) /\ ((varn env) ≡ c10) → t) → t
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
470 whileTest' {_} {_} {c10} next = next env proof2
14
ryokka
parents: 12
diff changeset
471 where
ryokka
parents: 12
diff changeset
472 env : Env
ryokka
parents: 12
diff changeset
473 env = record {vari = 0 ; varn = c10}
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
474 proof2 : ((vari env) ≡ 0) /\ ((varn env) ≡ c10)
14
ryokka
parents: 12
diff changeset
475 proof2 = record {pi1 = refl ; pi2 = refl}
ryokka
parents: 12
diff changeset
476 </pre></div>
ryokka
parents: 12
diff changeset
477 </div>
ryokka
parents: 12
diff changeset
478 </div>
ryokka
parents: 12
diff changeset
479 </li>
ryokka
parents: 12
diff changeset
480 </ul>
ryokka
parents: 12
diff changeset
481
ryokka
parents: 12
diff changeset
482
ryokka
parents: 12
diff changeset
483
ryokka
parents: 12
diff changeset
484 </div>
ryokka
parents: 12
diff changeset
485
ryokka
parents: 12
diff changeset
486 <div class='slide'>
ryokka
parents: 12
diff changeset
487 <!-- _S9SLIDE_ -->
ryokka
parents: 12
diff changeset
488 <h2 id="gears-と-hoarelogic-をベースにした証明conversion">Gears と HoareLogic をベースにした証明(conversion)</h2>
ryokka
parents: 12
diff changeset
489 <ul>
ryokka
parents: 12
diff changeset
490 <li>conversion は Condition から LoopInvaliant への変換を行う CodeGear
ryokka
parents: 12
diff changeset
491 <ul>
ryokka
parents: 12
diff changeset
492 <li>Condition の条件は Loop 内では厳しいのでゆるくする</li>
ryokka
parents: 12
diff changeset
493 </ul>
ryokka
parents: 12
diff changeset
494 </li>
ryokka
parents: 12
diff changeset
495 <li>proof4 は LoopInvaliant の証明</li>
ryokka
parents: 12
diff changeset
496 <li>Gears での HoareLogic の完全な記述は <strong>引数 → PreCondition → (Code : fa → PostCondition → t) → t</strong>
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
497 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
17
ryokka
parents: 16
diff changeset
498 <div class="code"><pre>conversion1 : {t : Set} → (env : Env) → {c10 : Nat } →
14
ryokka
parents: 12
diff changeset
499 ((vari env) ≡ 0) /\ ((varn env) ≡ c10)
ryokka
parents: 12
diff changeset
500 → (Code : (env1 : Env) → (varn env1 + vari env1 ≡ c10) → t) → t
ryokka
parents: 12
diff changeset
501 conversion1 env {c10} p1 next = next env proof4
ryokka
parents: 12
diff changeset
502 where
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
503 proof4 : varn env + vari env ≡ c10
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
504 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
505 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
506 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
507 </li>
14
ryokka
parents: 12
diff changeset
508 </ul>
ryokka
parents: 12
diff changeset
509
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
510
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
511
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
512 </div>
14
ryokka
parents: 12
diff changeset
513
16
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
514 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
515 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
516 <h2 id="hoarelogic-の証明">HoareLogic の証明</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
517 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
518 <li>HoareLogic の証明では基本的に項の書き換えを行って証明している</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
519 <li>proof4 の証明部分では論理式の<strong>varn env + vari env</strong> を 書き換えて <strong>c10</strong> に変換している</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
520 <li>変換で使っている <strong>cong</strong> は 関数と x ≡ y 受け取って両辺に関数を適応しても等しいことが変わらないことの証明</li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
521 <li>変換後の式を次の行に書いて変換を続ける
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
522 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
523 <div class="code"><pre>-- precond : ((vari env) ≡ 0) /\ ((varn env) ≡ c10)
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
524 conversion1 env {c10} precond next = next env proof4
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
525 where
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
526 proof4 : varn env + vari env ≡ c10
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
527 proof4 = let open ≡-Reasoning in
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
528 begin
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
529 varn env + vari env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
530 ≡⟨ cong ( λ n → n + vari env ) (pi2 precond ) ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
531 c10 + vari env
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
532 ≡⟨ cong ( λ n → c10 + n ) (pi1 precond ) ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
533 c10 + 0
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
534 ≡⟨ +-sym {c10} {0} ⟩
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
535 c10
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
536
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
537 -- +-sym : { x y : Nat } → x + y ≡ y + x
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
538 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
539 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
540 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
541 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
542 </ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
543
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
544
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
545
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
546 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
547
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
548 <div class='slide'>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
549 <!-- _S9SLIDE_ -->
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
550 <h2 id="gears-と-hoarelogic-をベースにした証明whileloop">Gears と HoareLogic をベースにした証明(whileLoop)</h2>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
551 <ul>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
552 <li>whileLoop も whileTest と同様に PreCondition が CodeGear に入りそれに対する証明が記述されている
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
553 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
554 <div class="code"><pre>-- whileLoop : {t : Set} → Env → (Code : Env → t) → t
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
555 whileLoop' : {t : Set} → (env : Env) → {c10 : Nat } → ((varn env) + (vari env) ≡ c10) → (Code : Env → t) → t
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
556 </pre></div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
557 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
558 </div>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
559 </li>
07e1ccdfd844 fix slide
ryokka
parents: 14
diff changeset
560 </ul>
14
ryokka
parents: 12
diff changeset
561
ryokka
parents: 12
diff changeset
562
ryokka
parents: 12
diff changeset
563
ryokka
parents: 12
diff changeset
564 </div>
ryokka
parents: 12
diff changeset
565
ryokka
parents: 12
diff changeset
566 <div class='slide'>
ryokka
parents: 12
diff changeset
567 <!-- _S9SLIDE_ -->
ryokka
parents: 12
diff changeset
568 <h2 id="gears-と-hoarelogic-をベースにした証明全体">Gears と HoareLogic をベースにした証明(全体)</h2>
ryokka
parents: 12
diff changeset
569 <ul>
ryokka
parents: 12
diff changeset
570 <li>最終状態で返ってくる i の値は c10 と一致する</li>
17
ryokka
parents: 16
diff changeset
571 <li>これにより証明が完了
14
ryokka
parents: 12
diff changeset
572 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
ryokka
parents: 12
diff changeset
573 <div class="code"><pre> proofGears : {c10 : Nat } → Set
ryokka
parents: 12
diff changeset
574 proofGears {c10} = whileTest' {_} {_} {c10} (λ n p1 → conversion1 n p1
ryokka
parents: 12
diff changeset
575 (λ n1 p2 → whileLoop' n1 p2 (λ n2 → ( vari n2 ≡ c10 ))))
ryokka
parents: 12
diff changeset
576 </pre></div>
ryokka
parents: 12
diff changeset
577 </div>
ryokka
parents: 12
diff changeset
578 </div>
ryokka
parents: 12
diff changeset
579 </li>
ryokka
parents: 12
diff changeset
580 </ul>
ryokka
parents: 12
diff changeset
581
ryokka
parents: 12
diff changeset
582
ryokka
parents: 12
diff changeset
583
ryokka
parents: 12
diff changeset
584 </div>
ryokka
parents: 12
diff changeset
585
ryokka
parents: 12
diff changeset
586 <div class='slide'>
ryokka
parents: 12
diff changeset
587 <!-- _S9SLIDE_ -->
ryokka
parents: 12
diff changeset
588 <h2 id="まとめと今後の課題">まとめと今後の課題</h2>
ryokka
parents: 12
diff changeset
589 <ul>
ryokka
parents: 12
diff changeset
590 <li>Gears を用いた HoareLogic ベースの検証方法を導入した
ryokka
parents: 12
diff changeset
591 <ul>
ryokka
parents: 12
diff changeset
592 <li>証明が引数として渡される記述のため証明とプログラムを一体化できた</li>
ryokka
parents: 12
diff changeset
593 </ul>
ryokka
parents: 12
diff changeset
594 </li>
ryokka
parents: 12
diff changeset
595 <li>今後の課題
ryokka
parents: 12
diff changeset
596 <ul>
ryokka
parents: 12
diff changeset
597 <li>RedBlackTree や SynchronizedQueue などのデータ構造の検証(HoareLogic ベースで)</li>
ryokka
parents: 12
diff changeset
598 </ul>
ryokka
parents: 12
diff changeset
599 </li>
ryokka
parents: 12
diff changeset
600 </ul>
ryokka
parents: 12
diff changeset
601
ryokka
parents: 12
diff changeset
602
ryokka
parents: 12
diff changeset
603
ryokka
parents: 12
diff changeset
604 </div>
ryokka
parents: 12
diff changeset
605
ryokka
parents: 12
diff changeset
606 <div class='slide'>
ryokka
parents: 12
diff changeset
607 <!-- _S9SLIDE_ -->
17
ryokka
parents: 16
diff changeset
608 <h2 id="agda-上での-hoarelogic-記述">Agda 上での HoareLogic 記述</h2>
12
e8fe28afe61e fix slide
ryokka
parents: 11
diff changeset
609 <ul>
17
ryokka
parents: 16
diff changeset
610 <li>Agda で構築した HoareLogic での whileProgram と Gears での whileProgram を見た目で比較</li>
ryokka
parents: 16
diff changeset
611 <li>この他に証明にコマンド、コマンドの証明の定義を記述する必要がある
ryokka
parents: 16
diff changeset
612 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
ryokka
parents: 16
diff changeset
613 <div class="code"><pre>-- HoareLogic でのwhileProgram
ryokka
parents: 16
diff changeset
614 program : ℕ → Comm
ryokka
parents: 16
diff changeset
615 program c10 =
ryokka
parents: 16
diff changeset
616 Seq ( PComm (λ env → record env {varn = c10}))
ryokka
parents: 16
diff changeset
617 $ Seq ( PComm (λ env → record env {vari = 0}))
ryokka
parents: 16
diff changeset
618 $ While (λ env → lt zero (varn env ) )
ryokka
parents: 16
diff changeset
619 (Seq (PComm (λ env → record env {vari = ((vari env) + 1)} ))
ryokka
parents: 16
diff changeset
620 $ PComm (λ env → record env {varn = ((varn env) - 1)} ))
ryokka
parents: 16
diff changeset
621 -- コマンドの証明部分
ryokka
parents: 16
diff changeset
622 proof1 : (c10 : ℕ) → HTProof initCond (program c10 ) (termCond {c10})
ryokka
parents: 16
diff changeset
623 proof1 c10 =
ryokka
parents: 16
diff changeset
624 SeqRule {λ e → true} ( PrimRule (init-case {c10} ))
ryokka
parents: 16
diff changeset
625 $ SeqRule {λ e → Equal (varn e) c10} ( PrimRule lemma1 )
ryokka
parents: 16
diff changeset
626 $ WeakeningRule {λ e → (Equal (varn e) c10) ∧ (Equal (vari e) 0)} lemma2 (
ryokka
parents: 16
diff changeset
627 WhileRule {_} {λ e → Equal ((varn e) + (vari e)) c10}
ryokka
parents: 16
diff changeset
628 $ SeqRule (PrimRule {λ e → whileInv e ∧ lt zero (varn e) } lemma3 )
ryokka
parents: 16
diff changeset
629 $ PrimRule {whileInv'} {_} {whileInv} lemma4 ) lemma5
ryokka
parents: 16
diff changeset
630 </pre></div>
ryokka
parents: 16
diff changeset
631 </div>
ryokka
parents: 16
diff changeset
632 </div>
ryokka
parents: 16
diff changeset
633 </li>
11
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
634 </ul>
17b7605a5deb add figures, some slides
ryokka
parents: 10
diff changeset
635
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
636
17
ryokka
parents: 16
diff changeset
637
ryokka
parents: 16
diff changeset
638 </div>
ryokka
parents: 16
diff changeset
639
ryokka
parents: 16
diff changeset
640 <div class='slide'>
ryokka
parents: 16
diff changeset
641 <!-- _S9SLIDE_ -->
ryokka
parents: 16
diff changeset
642 <h2 id="gears-での-hoarelogic-記述">Gears での HoareLogic 記述</h2>
ryokka
parents: 16
diff changeset
643 <ul>
ryokka
parents: 16
diff changeset
644 <li>
ryokka
parents: 16
diff changeset
645 <div class="language-AGDA highlighter-coderay"><div class="CodeRay">
ryokka
parents: 16
diff changeset
646 <div class="code"><pre>proofGears : {c10 : Nat } → Set
ryokka
parents: 16
diff changeset
647 proofGears {c10} = whileTest' {_} {_} {c10} (λ n p1 → conversion1 n p1
ryokka
parents: 16
diff changeset
648 (λ n1 p2 → whileLoop' n1 p2 (λ n2 → ( vari n2 ≡ c10 ))))
ryokka
parents: 16
diff changeset
649 </pre></div>
ryokka
parents: 16
diff changeset
650 </div>
ryokka
parents: 16
diff changeset
651 </div>
ryokka
parents: 16
diff changeset
652 </li>
ryokka
parents: 16
diff changeset
653 </ul>
ryokka
parents: 16
diff changeset
654
10
a87fec07fd78 add slide
ryokka
parents:
diff changeset
655 </div>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
656
a87fec07fd78 add slide
ryokka
parents:
diff changeset
657
a87fec07fd78 add slide
ryokka
parents:
diff changeset
658 </div><!-- presentation -->
a87fec07fd78 add slide
ryokka
parents:
diff changeset
659 </body>
a87fec07fd78 add slide
ryokka
parents:
diff changeset
660 </html>