Mercurial > hg > Papers > 2018 > ryokka-thesis
view slide/slide.html @ 13:b7106f1dcc38
fix slide
author | ryokka |
---|---|
date | Wed, 21 Feb 2018 15:27:37 +0900 |
parents | 9af6c3636ea0 |
children | 5d7eb0f27fb0 |
line wrap: on
line source
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>「Agda による継続を用いたプログラムの検証」</title> <meta name="generator" content="Slide Show (S9) v2.5.0 on Ruby 2.4.1 (2017-03-22) [x86_64-darwin16]"> <meta name="author" content="外間 政尊" > <!-- style sheet links --> <link rel="stylesheet" href="s6/themes/projection.css" media="screen,projection"> <link rel="stylesheet" href="s6/themes/screen.css" media="screen"> <link rel="stylesheet" href="s6/themes/print.css" media="print"> <link rel="stylesheet" href="s6/themes/blank.css" media="screen,projection"> <!-- JS --> <script src="s6/js/jquery-1.11.3.min.js"></script> <script src="s6/js/jquery.slideshow.js"></script> <script src="s6/js/jquery.slideshow.counter.js"></script> <script src="s6/js/jquery.slideshow.controls.js"></script> <script src="s6/js/jquery.slideshow.footer.js"></script> <script src="s6/js/jquery.slideshow.autoplay.js"></script> <!-- prettify --> <link rel="stylesheet" href="scripts/prettify.css"> <script src="scripts/prettify.js"></script> <script> $(document).ready( function() { Slideshow.init(); $('code').each(function(_, el) { if (!el.classList.contains('noprettyprint')) { el.classList.add('prettyprint'); } }); prettyPrint(); } ); </script> <!-- Better Browser Banner for Microsoft Internet Explorer (IE) --> <!--[if IE]> <script src="s6/js/jquery.microsoft.js"></script> <![endif]--> </head> <body> <div class="layout"> <div id="header"></div> <div id="footer"> <div align="right"> <img src="s6/images/logo.svg" width="200px"> </div> </div> </div> <div class="presentation"> <div class='slide cover'> <table width="90%" height="90%" border="0" align="center"> <tr> <td> <div align="center"> <h1><font color="#808db5">「Agda による継続を用いたプログラムの検証」</font></h1> </div> </td> </tr> <tr> <td> <div align="left"> 外間 政尊 @並列信頼研 <hr style="color:#ffcc00;background-color:#ffcc00;text-align:left;border:none;width:100%;height:0.2em;"> </div> </td> </tr> </table> </div> <div class='slide '> <!-- === begin markdown block === generated by markdown/1.2.0 on Ruby 2.4.1 (2017-03-22) [x86_64-darwin16] on 2018-02-21 15:26:02 +0900 with Markdown engine kramdown (1.15.0) using options {} --> <!-- _S9SLIDE_ --> <h2 id="section">プログラムの信頼性の保証</h2> <ul> <li>動作するプログラムの信頼性を保証したい</li> <li>プログラムの仕様を検証するには<strong>モデル検査</strong>と<strong>定理証明</strong>の2つの手法がある <ul> <li>モデル検査 はプログラムの持つ状態を数え上げて仕様を満たしているかを確認する</li> <li>定理証明 はプログラムの性質を論理式で記述しそれが常に正しいことを証明する</li> </ul> </li> <li>また、当研究室では検証しやすい単位として CodeGear、DataGearという単位を用いてプログラムを記述する手法を提案している</li> </ul> <!-- * 処理の単位である CodeGear はメタ計算によって接続され、メタ計算部分を切り替えることで CodeGear に一切の変更なくプログラムの性質を検証することができる --> <!-- * 本研究では CodeGear 、 DataGear を用いて記述する言語、 Continuation based C (CbC) を用いてプログラムを記述し、それを証明することで信頼性を上げることを目標としている --> <!-- * CbC での記述を Agda にマッピングし、その性質の一部を証明した --> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="codegear--datagear">CodeGear と DataGear</h2> <ul> <li>CodeGear とはプログラムを記述する際の処理の単位である。</li> <li>DataGear は CodeGear で扱うデータの単位であり、処理に必要なデータが全て入っている。</li> <li>CodeGear はメタ計算によって CodeGear へ接続される</li> <li>接続はメタ計算で行われ、メタ計算を切り替えることで処理に変更を加えることなくプログラムの性質を検証できる</li> <li>CodeGear は入力として DataGear を受け取り、 DataGear に変更を加えて次に指定された CodeGear へ継続する</li> </ul> <div style="text-align: center;"> <img src="./fig/csds.svg" alt="goto" width="800" /> </div> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="continuation-based-c-cbc">Continuation based C (CbC)</h2> <ul> <li>当研究室で開発している言語</li> <li>基本的な構文は C 言語と同じ</li> <li>CodeGear、 DataGear という単位を用いてプログラムを記述する</li> <li>CbC では 通常計算とメタ計算を分離している</li> <li>CodeGear を継続し、 DataGear を変更しながらプログラムが進んでいく</li> <li>CodeGear は関数の定義前に__codeがつく</li> <li>関数末尾の goto により次の CodeGear に継続する</li> </ul> <pre lang="C"><code>__code cg0(int a, int b){ goto cg1(a+b); } __code cg1(int c){ goto cg2(c); } </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="context">Context</h2> <ul> <li>CodeGear や DataGear をリストとして、 Context と呼ばれる Meta DataGear の中で定義している</li> <li>しかし Context は Meta DataGear のため、通常レベルである CodeGear で直接扱うのは避けたい</li> <li>その為、 stub CodeGear という Meta CodeGear を定義している。</li> <li>stub CodeGear は Context を通して必要なデータを取り出し、次の CodeGear に接続する</li> <li>stub CodeGear は CodeGear 毎に生成される</li> </ul> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="interface">Interface</h2> <ul> <li>CbC で実装していくにつれて stub CodeGear の記述が煩雑になることがわかった</li> <li>そこで Interface というモジュール化の仕組みを導入した</li> <li>Interface は CodeGear とそこで扱われている DataGear の集合を抽象的に表現した Meta DataGear として定義されている</li> <li><strong>__code next(…)</strong> は継続を表していて <strong>…</strong>部分は後続の引数に相当する</li> </ul> <pre lang="C"><code>typedef struct Stack<Type, Impl>{ // DataGear union Data* stack; union Data* data; union Data* data1; // CodeGear __code whenEmpty(...); __code clear(Impl* stack,__code next(...)); __code push(Impl* stack,Type* data, __code next(...)); // 省略 __code next(...); } Stack; </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="interface-1">Interface</h2> <ul> <li>Interface を表す DataGear は次のような関数で生成される</li> <li><strong>stack->push</strong> のようにしてコード中で使うことができる</li> </ul> <pre lang="C"><code>Stack* createSingleLinkedStack(struct Context* context) { struct Stack* stack = new Stack(); struct SingleLinkedStack* singleLinkedStack = new SingleLinkedStack(); stack->stack = (union Data*)singleLinkedStack; singleLinkedStack->top = NULL; stack->push = C_pushSingleLinkedStack; stack->pop = C_popSingleLinkedStack; // 省略 return stack; </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="agda">Agda</h2> <ul> <li>Agda とは定理証明支援器で、型システムを用いて証明を記述できる。</li> <li>Agda では関数の型を明示する必要がある</li> </ul> <pre lang="AGDA"><code>-- Booleanの定義(データの定義例) data Bool : Set where true : Bool false : Bool -- Bool値を反転する関数の例 not : Bool → Bool not true = false not false = true -- xor(複数の引数を取る例) xor : Bool → Bool → Bool xor true true = false xor false false = false xor _ _ = true </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="agda-1">AGDA</h2> <ul> <li>Agda 上で CodeGear、 DataGear の単位と継続を定義した</li> <li>DataGear はレコード型として定義し、 CodeGear は通常の関数。</li> </ul> <pre lang="AGDA"><code>// CbC __code cg0(int a, int b){ goto cg1(a+b); } </code></pre> <pre><code>-- agda DataGear record dg0 : Set where field a : Int b : Int -- agda CodeGear define data CodeGear (A B : Set) : Set where cg : (A -> B) -> CodeGear A B -- agda CodeGear example cg0 : CodeGear dg0 dg1 cg0 = cg (\d -> goto cg1 (record {c = (dg0.a d) + (dg0.b d)})) </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="agda-">Agda での証明</h2> <ul> <li>型で論理を書き、関数部分で導出</li> </ul> <pre lang="AGDA"><code>ex : 1 + 2 ≡ 3 ex = refl </code></pre> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="agda--interface-">Agda での Interface の定義</h2> <ul> <li>Agda上でも CbC の Interface と同様のものを定義した。</li> </ul> <pre lang="AGDA"><code>record StackMethods {n m : Level } (a : Set n ) {t : Set m }(stackImpl : Set n ) : Set (m Level.⊔ n) where field push : stackImpl -> a -> (stackImpl -> t) -> t pop : stackImpl -> (stackImpl -> Maybe a -> t) -> t -- 省略 open StackMethods record Stack {n m : Level } (a : Set n ) {t : Set m } (si : Set n ) : Set (m Level.⊔ n) where field stack : si stackMethods : StackMethods {n} {m} a {t} si pushStack : a -> (Stack a si -> t) -> t pushStack d next = push (stackMethods ) (stack ) d (\s1 -> next (record {stack = s1 ; stackMethods = stackMethods } )) popStack : (Stack a si -> Maybe a -> t) -> t popStack next = pop (stackMethods ) (stack ) (\s1 d1 -> next (record {stack = s1 ; stackMethods = stackMethods }) d1 ) -- 省略 </code></pre> <ul lang="AGDA"> <li>インスタンス生成</li> </ul> <pre><code>singleLinkedStackSpec : {n m : Level } {t : Set m } {a : Set n} -> StackMethods {n} {m} a {t} (SingleLinkedStack a) singleLinkedStackSpec = record { push = pushSingleLinkedStack ; pop = popSingleLinkedStack -- 省略 } createSingleLinkedStack : {n m : Level } {t : Set m } {a : Set n} -> Stack {n} {m} a {t} (SingleLinkedStack a) createSingleLinkedStack = record { stack = emptySingleLinkedStack ; stackMethods = singleLinkedStackSpec } </code></pre> <!-- ## Tree の Interface --> <!-- ```AGDA --> <!-- record TreeMethods {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where --> <!-- field --> <!-- putImpl : treeImpl -> a -> (treeImpl -> t) -> t --> <!-- getImpl : treeImpl -> (treeImpl -> Maybe a -> t) -> t --> <!-- open TreeMethods --> <!-- record Tree {n m : Level } {a : Set n } {t : Set m } (treeImpl : Set n ) : Set (m Level.⊔ n) where --> <!-- field --> <!-- tree : treeImpl --> <!-- treeMethods : TreeMethods {n} {m} {a} {t} treeImpl --> <!-- putTree : a -> (Tree treeImpl -> t) -> t --> <!-- putTree d next = putImpl (treeMethods ) tree d (\t1 -> next (record {tree = t1 ; treeMethods = treeMethods} )) --> <!-- getTree : (Tree treeImpl -> Maybe a -> t) -> t --> <!-- getTree next = getImpl (treeMethods ) tree (\t1 d -> next (record {tree = t1 ; treeMethods = treeMethods} ) d ) --> <!-- ``` --> <!-- * インスタンス生成 --> <!-- ```AGDA --> <!-- ``` --> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="agda--interface-stack-">Agda での Interface を含めた部分的な証明(Stack の例)</h2> <ul> <li>不定な Stack を作成し、そこに push し、直後に pop した値が push した値と等しいことを示している</li> </ul> <pre lang="AGDA"><code>stackInSomeState : {l m : Level } {D : Set l} {t : Set m } (s : SingleLinkedStack D ) -> Stack {l} {m} D {t} ( SingleLinkedStack D ) stackInSomeState s = record { stack = s ; stackMethods = singleLinkedStackSpec } </code></pre> <p lang="AGDA">実際の証明</p> <pre><code>push->push->pop2 : {l : Level } {D : Set l} (x y : D ) (s : SingleLinkedStack D ) -> pushStack ( stackInSomeState s ) x ( \s1 -> pushStack s1 y ( \s2 -> pop2Stack s2 ( \s3 y1 x1 -> (Just x ≡ x1 ) ∧ (Just y ≡ y1 ) ) )) push->push->pop2 {l} {D} x y s = record { pi1 = refl ; pi2 = refl } </code></pre> <!-- ## Agda での Interface の部分的な証明と課題(Tree の例) --> <!-- ```AGDA --> <!-- ``` --> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="hoare-logic">Hoare Logic</h2> <ul> <li>Hoare Logic は Tony Hoare によって提案されたプログラムの部分的な正当性を検証するための手法</li> <li>前の状態を{P}(Pre-Condition)、後の状態を{Q}(Post-Condition)とし、前状態を C (Command) によって変更する</li> <li>この {P} C {Q} でプログラムを部分的に表すことができるp</li> </ul> <div style="text-align: center;"> <img src="./fig/hoare.svg" alt="hoare" width="1000" /> </div> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="hoare-logic--cbc">Hoare Logic と CbC</h2> <ul> <li>Hoare Logic の状態と処理を CodeGear、 DataGear の単位で考えることができると考えている</li> </ul> <div style="text-align: center;"> <img src="./fig/hoare-cbc.svg" alt="cbc-hoare" width="800" /> </div> </div> <div class='slide '> <!-- _S9SLIDE_ --> <h2 id="section-1">今後の課題</h2> <ul> <li>本研究では Agda での Interface の記述及び Interface を含めた一部の証明を行った。</li> <li>これにより、 Interface を経由しても一部の性質は実装と同様の働きをすることが証明できた。</li> <li>また、これにより CbC での Interface 記述では考えられていなかった細かな記述が明らかになった。</li> <li>今後の課題としては Hoare Logic を継続を用いた Agda で表現し、その Hoare Logic をベースとして証明を行えるかを確認する。</li> </ul> <!-- === end markdown block === --> </div> </div><!-- presentation --> </body> </html>