SlideShare a Scribd company logo
1 of 35
Download to read offline
はじめに                 ゼミ             授業      おわりに



 



         にわとりかんさつにっき in お茶大

              ますこ もえ (twitter ID: @MoCo7)


                      August 29, 2010



にわとりかんさつにっき in お茶大                            1/24
はじめに                 ゼミ   授業      おわりに



自己紹介




       お茶大の学生 (M2)
       所属: shift/reset 推進委員会
       好きなもの: OCaml,Coq,圏論,ect.




にわとりかんさつにっき in お茶大                  2/24
はじめに                 ゼミ   授業   おわりに



 




                      研究室


にわとりかんさつにっき in お茶大               3/24
はじめに                 ゼミ   授業   おわりに



ボス: ProofGeneral




にわとりかんさつにっき in お茶大               4/24
はじめに                 ゼミ   授業   おわりに



ボス: ProofGeneral
      浅井先生




にわとりかんさつにっき in お茶大               4/24
はじめに                 ゼミ   授業   おわりに



ボス: ProofGeneral
      浅井先生




       昨日の
 OCaml Meeting の
   talker の 1 人




にわとりかんさつにっき in お茶大               4/24
はじめに                 ゼミ   授業            おわりに



ボス: ProofGeneral
      浅井先生




       昨日の
 OCaml Meeting の
   talker の 1 人                   ⇑
                               この本の筆者




にわとりかんさつにっき in お茶大                        4/24
はじめに                 ゼミ   授業   おわりに



学生


   D1 1 人


   M2 4 人

   M1 2 人

   B4 1 人


にわとりかんさつにっき in お茶大               5/24
はじめに                  ゼミ                     授業   おわりに



Coq ゼミ

       2008 年前期開催
       Coq を勉強しよう ! というゼミでした
       内容:
          1   install,関数,大域的変数,Specification の定義
          2   命題論理
          3   関数の拡張,述語論理
          4   implication 以外の論理演算,等式の証明
          5   帰納的なデータ型,再帰関数の定義,帰納法
          6   リスト,帰納的な命題の定義
          7   演習 (TAPL 8 章,soundness)
       http://pllab.is.ocha.ac.jp/lab.html


にわとりかんさつにっき in お茶大                                  6/24
はじめに                 ゼミ   授業   おわりに



ゼミで学んだこと




                 型 = 命題
               プログラム = 証明



にわとりかんさつにっき in お茶大               7/24
はじめに                 ゼミ       授業      おわりに



ゼミで学んだこと



                 /)◦∀◦( yay! /)◦∀◦(
                 型 = 命題
               プログラム = 証明
                 (◦∀◦)/ yay! (◦∀◦)/


にわとりかんさつにっき in お茶大                      7/24
はじめに                 ゼミ   授業   おわりに



ゼミで学んだこと



       Coq 楽しそう
       証明に良さそうだ




にわとりかんさつにっき in お茶大               7/24
はじめに                 ゼミ    授業          おわりに



ゼミで学んだこと



       Coq 楽しそう
       証明に良さそうだ
       後期: CPDT をやって転覆
       M2 は研究に Coq を使えていない ... ! (使いたい !)




にわとりかんさつにっき in お茶大                       7/24
はじめに                 ゼミ              授業              おわりに



Coq 楽しいよ Coq

       ICFP2009 の B. C. Pierce の招待講演
       “Lambda, the Ultimate TA: Using a Proof Assistant
       to Teach Programming Language Foundations”
            from
               Theory of PL for PL geeks
            to
               Software Foundation to the masses
       http://www.cis.upenn.edu/~bcpierce/sf



にわとりかんさつにっき in お茶大                                     9/24
はじめに                 ゼミ     授業            おわりに



今年の大学院の授業




       大学院の授業: 先生達が好きなことをやる
       浅井先生は ...
          functional derivation の手法で色々な
          セマンティクスのインタプリタを導く




にわとりかんさつにっき in お茶大                          10/24
はじめに                  ゼミ               授業   おわりに



時折出る課題


       { 引き算,四則演算 } インタプリタを ...
             普通に書く
             reduction semantics で書く
             CPS 変換
             非関数化
       factorial 関数や fibonacci 関数を ...
             CPS 変換
             非関数化




にわとりかんさつにっき in お茶大                            11/24
はじめに                 ゼミ              授業              おわりに



factorial 関数 (CPS)


       let rec fac n =
         if n <= 0 then 1
         else n * fac ( n - 1 )
       let rec fac_cps n k =
         if n <= 0 then k 1
         else
           fac_cps ( n - 1 ) ( fun x - > k ( n * x ) )
       let main n = fac_cps n ( fun x - > x )




にわとりかんさつにっき in お茶大                                       12/24
はじめに                 ゼミ             授業               おわりに



factorial 関数 (非関数化)



       type cont = C0 | C1 of int * cont
       let rec apply k x = match k with
         | C0 - > x
         | C1 (n , k ) - > apply k ( n * x )
       let rec fac_defunc n k =
         if n <= 0 then apply k 1
         else fac_defunc ( n - 1 ) ( C1 (n , k ) )
       let main n = fac_defunc n C0




にわとりかんさつにっき in お茶大                                     13/24
y
はじめに                 ゼミ   授業       おわりに



時折出る無茶振り (?)



                               ~
                          じゃ、正当性の
                          証明は Coq で。




にわとりかんさつにっき in お茶大                     14/24
はじめに                 ゼミ   授業   おわりに



 




            売られた喧嘩は買いましょう !!




にわとりかんさつにっき in お茶大               15/24
はじめに                 ゼミ          授業   おわりに



 




            売られた喧嘩は買いましょう !!
            出さ        定理   証明し




にわとりかんさつにっき in お茶大                      15/24
はじめに                 ゼミ               授業        おわりに



CPS 変換の正当性 (factorial)


 Theorem
   ∀n ∈ N,            f acds n = f accps n id




にわとりかんさつにっき in お茶大                                16/24
はじめに                 ゼミ               授業        おわりに



CPS 変換の正当性 (factorial)


 Theorem
   ∀n ∈ N,            f acds n = f accps n id

 Lemma
   ∀n ∈ N, k ∈ N → N,
               k (f acds n) = f accps n k
 証明: n に関する帰納法



にわとりかんさつにっき in お茶大                                16/24
はじめに                 ゼミ               授業        おわりに



CPS 変換の正当性 (factorial)


 Theorem
   ∀n ∈ N,            f acds n = f accps n id

 Lemma
   ∀n ∈ N, k ∈ N → N,
               k (f acds n) = f accps n k
 証明: n に関する帰納法
 上の定理は k = id にすれば示せる

にわとりかんさつにっき in お茶大                                16/24
はじめに                  ゼミ                授業             おわりに



非関数化の正当性 (factorial)

 Theorem
   ∀n ∈ N,           f accps n id = f acdef unc n C0




にわとりかんさつにっき in お茶大                                       17/24
はじめに                  ゼミ                授業             おわりに



非関数化の正当性 (factorial)

 Theorem
   ∀n ∈ N,           f accps n id = f acdef unc n C0

 Lemma
   ∀n ∈ N, k ∈ N → N, c ∈ cont,
 (∀a ∈ N, k a = apply c a) → f accps n k = f acdef unc n c
 証明: n に関する帰納法



にわとりかんさつにっき in お茶大                                       17/24
はじめに                  ゼミ                授業             おわりに



非関数化の正当性 (factorial)

 Theorem
   ∀n ∈ N,           f accps n id = f acdef unc n C0

 Lemma
   ∀n ∈ N, k ∈ N → N, c ∈ cont,
 (∀a ∈ N, k a = apply c a) → f accps n k = f acdef unc n c
 証明: n に関する帰納法
 上の定理は k = id,c = C0 に
 すれば示せる
にわとりかんさつにっき in お茶大                                       17/24
はじめに                 ゼミ             授業        おわりに



CPS 変換 & 非関数化の正当性 (fibonacci)


       let rec fib n =
         if n <= 1 then 1
         else fib ( n - 1 ) + fib ( n - 2 )

       定式化: ほぼ factorial と同じ格好
       証明: well founded induction で頑張る




にわとりかんさつにっき in お茶大                              18/24
はじめに                 ゼミ             授業        おわりに



CPS 変換 & 非関数化の正当性 (fibonacci)


       let rec fib n =
         if n <= 1 then 1
         else fib ( n - 1 ) + fib ( n - 2 )

      定式化: ほぼ factorial と同じ格好
      証明: well founded induction で頑張る
   ?? 非関数化すると apply 関数と相互再帰の形になり
      Coq で上手く定義出来ない ... (証明も美しくない)



にわとりかんさつにっき in お茶大                              18/24
はじめに                 ゼミ              授業               おわりに



fibonacci (CPS, OCaml)




       let rec fib_cps n k =
         if n < 2 then k 1
         else
           fib_cps ( n - 1 ) ( fun x - >
           fib_cps ( n - 2 ) ( fun y - > k ( x + y ) ) )




にわとりかんさつにっき in お茶大                                         19/24
はじめに                 ゼミ              授業              おわりに



fibonacci (defunctionalized, OCaml)

       type cont =
         | C0
         | C1 of int * cont_t
         | C2 of int * cont_t
       let rec apply k x = match k with
         | C0 - > x
         | C1 (n , k ) - >
             fib_defunc ( n - 2 ) ( C2 (x , k ) )
         | C2 ( n1 , k ) - > apply k ( n1 + x )
       and fib_defunc n k =
         if n < 2 then apply k 1
         else fib_defunc ( n - 1 ) ( C1 (n , k ) )

にわとりかんさつにっき in お茶大                                     20/24
はじめに                     ゼミ                     授業                     おわりに



fibonacci (Coq)
     Fixpoint app ( k : cont_fib ) ( x : nat ) ( count : nat )
       { struct count } : option nat : =
       match count with
          | O = > None
          | S count ’ = >
              match k with
                 | C0_fib = > Some x
                 | C1_fib n k = >
                     fib_defunc ( minus n 1 ) ( C2_fib x k ) count ’
                 | C2_fib n1 k = > app k ( plus n1 x ) count ’
              end
       end
     with fib_defunc ( n : nat ) ( k : cont_fib ) ( count : nat )
       { struct count } : option nat : =
       match count with
          | O = > None
          | S count ’ = >
              match n with
                 | O | S O = > app k 1 count ’
                 | S m = > fib_defunc m ( C1_fib m k ) count ’
              end
       end .


にわとりかんさつにっき in お茶大                                                       21/24
はじめに                 ゼミ           授業              おわりに



真面目な研究もやっています




        D1 の先輩: Coqer
  · · · 強正規化性の証明,プログラム抽出
        M1 の後輩: Coqer / Agdar
  · · · functional derivation の証明 (今は Agda 勉強中)




にわとりかんさつにっき in お茶大                                  22/24
はじめに                 ゼミ            授業              おわりに



ちなみに



       私の研究: shift/reset の直接実装
       最近は
             Caml Light に shift/reset 導入
             functional derivation の手法を利用して,
             definitional interpreter =⇒ ZINC の証明
             怪しい変換の部分に Coq を使いたい ... かも ?
             圏論の方で Coq を使いたい ... かも ??




にわとりかんさつにっき in お茶大                                   23/24
はじめに                 ゼミ         授業           おわりに



 




                          おわり
                                     
                                     u u
                                       h
                                     
                                      ¤ h
                                     ¤   h




にわとりかんさつにっき in お茶大                             24/24

More Related Content

Viewers also liked

coqun
coquncoqun
coqunMoCo7
 
coqun
coquncoqun
coqunMoCo7
 
Prototyping is an attitude
Prototyping is an attitudePrototyping is an attitude
Prototyping is an attitudeWith Company
 
10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer ExperienceYuan Wang
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanPost Planner
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionIn a Rocket
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting PersonalKirsty Hulse
 

Viewers also liked (7)

coqun
coquncoqun
coqun
 
coqun
coquncoqun
coqun
 
Prototyping is an attitude
Prototyping is an attitudePrototyping is an attitude
Prototyping is an attitude
 
10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience10 Insightful Quotes On Designing A Better Customer Experience
10 Insightful Quotes On Designing A Better Customer Experience
 
How to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media PlanHow to Build a Dynamic Social Media Plan
How to Build a Dynamic Social Media Plan
 
Learn BEM: CSS Naming Convention
Learn BEM: CSS Naming ConventionLearn BEM: CSS Naming Convention
Learn BEM: CSS Naming Convention
 
SEO: Getting Personal
SEO: Getting PersonalSEO: Getting Personal
SEO: Getting Personal
 

Recently uploaded

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 

Recently uploaded (9)

論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 

coqun

  • 1. はじめに ゼミ 授業 おわりに   にわとりかんさつにっき in お茶大 ますこ もえ (twitter ID: @MoCo7) August 29, 2010 にわとりかんさつにっき in お茶大 1/24
  • 2. はじめに ゼミ 授業 おわりに 自己紹介 お茶大の学生 (M2) 所属: shift/reset 推進委員会 好きなもの: OCaml,Coq,圏論,ect. にわとりかんさつにっき in お茶大 2/24
  • 3. はじめに ゼミ 授業 おわりに   研究室 にわとりかんさつにっき in お茶大 3/24
  • 4. はじめに ゼミ 授業 おわりに ボス: ProofGeneral にわとりかんさつにっき in お茶大 4/24
  • 5. はじめに ゼミ 授業 おわりに ボス: ProofGeneral 浅井先生 にわとりかんさつにっき in お茶大 4/24
  • 6. はじめに ゼミ 授業 おわりに ボス: ProofGeneral 浅井先生 昨日の OCaml Meeting の talker の 1 人 にわとりかんさつにっき in お茶大 4/24
  • 7. はじめに ゼミ 授業 おわりに ボス: ProofGeneral 浅井先生 昨日の OCaml Meeting の talker の 1 人 ⇑ この本の筆者 にわとりかんさつにっき in お茶大 4/24
  • 8. はじめに ゼミ 授業 おわりに 学生 D1 1 人 M2 4 人 M1 2 人 B4 1 人 にわとりかんさつにっき in お茶大 5/24
  • 9. はじめに ゼミ 授業 おわりに Coq ゼミ 2008 年前期開催 Coq を勉強しよう ! というゼミでした 内容: 1 install,関数,大域的変数,Specification の定義 2 命題論理 3 関数の拡張,述語論理 4 implication 以外の論理演算,等式の証明 5 帰納的なデータ型,再帰関数の定義,帰納法 6 リスト,帰納的な命題の定義 7 演習 (TAPL 8 章,soundness) http://pllab.is.ocha.ac.jp/lab.html にわとりかんさつにっき in お茶大 6/24
  • 10. はじめに ゼミ 授業 おわりに ゼミで学んだこと 型 = 命題 プログラム = 証明 にわとりかんさつにっき in お茶大 7/24
  • 11. はじめに ゼミ 授業 おわりに ゼミで学んだこと /)◦∀◦( yay! /)◦∀◦( 型 = 命題 プログラム = 証明 (◦∀◦)/ yay! (◦∀◦)/ にわとりかんさつにっき in お茶大 7/24
  • 12. はじめに ゼミ 授業 おわりに ゼミで学んだこと Coq 楽しそう 証明に良さそうだ にわとりかんさつにっき in お茶大 7/24
  • 13. はじめに ゼミ 授業 おわりに ゼミで学んだこと Coq 楽しそう 証明に良さそうだ 後期: CPDT をやって転覆 M2 は研究に Coq を使えていない ... ! (使いたい !) にわとりかんさつにっき in お茶大 7/24
  • 14. はじめに ゼミ 授業 おわりに Coq 楽しいよ Coq ICFP2009 の B. C. Pierce の招待講演 “Lambda, the Ultimate TA: Using a Proof Assistant to Teach Programming Language Foundations” from Theory of PL for PL geeks to Software Foundation to the masses http://www.cis.upenn.edu/~bcpierce/sf にわとりかんさつにっき in お茶大 9/24
  • 15. はじめに ゼミ 授業 おわりに 今年の大学院の授業 大学院の授業: 先生達が好きなことをやる 浅井先生は ... functional derivation の手法で色々な セマンティクスのインタプリタを導く にわとりかんさつにっき in お茶大 10/24
  • 16. はじめに ゼミ 授業 おわりに 時折出る課題 { 引き算,四則演算 } インタプリタを ... 普通に書く reduction semantics で書く CPS 変換 非関数化 factorial 関数や fibonacci 関数を ... CPS 変換 非関数化 にわとりかんさつにっき in お茶大 11/24
  • 17. はじめに ゼミ 授業 おわりに factorial 関数 (CPS) let rec fac n = if n <= 0 then 1 else n * fac ( n - 1 ) let rec fac_cps n k = if n <= 0 then k 1 else fac_cps ( n - 1 ) ( fun x - > k ( n * x ) ) let main n = fac_cps n ( fun x - > x ) にわとりかんさつにっき in お茶大 12/24
  • 18. はじめに ゼミ 授業 おわりに factorial 関数 (非関数化) type cont = C0 | C1 of int * cont let rec apply k x = match k with | C0 - > x | C1 (n , k ) - > apply k ( n * x ) let rec fac_defunc n k = if n <= 0 then apply k 1 else fac_defunc ( n - 1 ) ( C1 (n , k ) ) let main n = fac_defunc n C0 にわとりかんさつにっき in お茶大 13/24
  • 19. y はじめに ゼミ 授業 おわりに 時折出る無茶振り (?) ~ じゃ、正当性の 証明は Coq で。 にわとりかんさつにっき in お茶大 14/24
  • 20. はじめに ゼミ 授業 おわりに   売られた喧嘩は買いましょう !! にわとりかんさつにっき in お茶大 15/24
  • 21. はじめに ゼミ 授業 おわりに   売られた喧嘩は買いましょう !! 出さ 定理 証明し にわとりかんさつにっき in お茶大 15/24
  • 22. はじめに ゼミ 授業 おわりに CPS 変換の正当性 (factorial) Theorem ∀n ∈ N, f acds n = f accps n id にわとりかんさつにっき in お茶大 16/24
  • 23. はじめに ゼミ 授業 おわりに CPS 変換の正当性 (factorial) Theorem ∀n ∈ N, f acds n = f accps n id Lemma ∀n ∈ N, k ∈ N → N, k (f acds n) = f accps n k 証明: n に関する帰納法 にわとりかんさつにっき in お茶大 16/24
  • 24. はじめに ゼミ 授業 おわりに CPS 変換の正当性 (factorial) Theorem ∀n ∈ N, f acds n = f accps n id Lemma ∀n ∈ N, k ∈ N → N, k (f acds n) = f accps n k 証明: n に関する帰納法 上の定理は k = id にすれば示せる にわとりかんさつにっき in お茶大 16/24
  • 25. はじめに ゼミ 授業 おわりに 非関数化の正当性 (factorial) Theorem ∀n ∈ N, f accps n id = f acdef unc n C0 にわとりかんさつにっき in お茶大 17/24
  • 26. はじめに ゼミ 授業 おわりに 非関数化の正当性 (factorial) Theorem ∀n ∈ N, f accps n id = f acdef unc n C0 Lemma ∀n ∈ N, k ∈ N → N, c ∈ cont, (∀a ∈ N, k a = apply c a) → f accps n k = f acdef unc n c 証明: n に関する帰納法 にわとりかんさつにっき in お茶大 17/24
  • 27. はじめに ゼミ 授業 おわりに 非関数化の正当性 (factorial) Theorem ∀n ∈ N, f accps n id = f acdef unc n C0 Lemma ∀n ∈ N, k ∈ N → N, c ∈ cont, (∀a ∈ N, k a = apply c a) → f accps n k = f acdef unc n c 証明: n に関する帰納法 上の定理は k = id,c = C0 に すれば示せる にわとりかんさつにっき in お茶大 17/24
  • 28. はじめに ゼミ 授業 おわりに CPS 変換 & 非関数化の正当性 (fibonacci) let rec fib n = if n <= 1 then 1 else fib ( n - 1 ) + fib ( n - 2 ) 定式化: ほぼ factorial と同じ格好 証明: well founded induction で頑張る にわとりかんさつにっき in お茶大 18/24
  • 29. はじめに ゼミ 授業 おわりに CPS 変換 & 非関数化の正当性 (fibonacci) let rec fib n = if n <= 1 then 1 else fib ( n - 1 ) + fib ( n - 2 ) 定式化: ほぼ factorial と同じ格好 証明: well founded induction で頑張る ?? 非関数化すると apply 関数と相互再帰の形になり Coq で上手く定義出来ない ... (証明も美しくない) にわとりかんさつにっき in お茶大 18/24
  • 30. はじめに ゼミ 授業 おわりに fibonacci (CPS, OCaml) let rec fib_cps n k = if n < 2 then k 1 else fib_cps ( n - 1 ) ( fun x - > fib_cps ( n - 2 ) ( fun y - > k ( x + y ) ) ) にわとりかんさつにっき in お茶大 19/24
  • 31. はじめに ゼミ 授業 おわりに fibonacci (defunctionalized, OCaml) type cont = | C0 | C1 of int * cont_t | C2 of int * cont_t let rec apply k x = match k with | C0 - > x | C1 (n , k ) - > fib_defunc ( n - 2 ) ( C2 (x , k ) ) | C2 ( n1 , k ) - > apply k ( n1 + x ) and fib_defunc n k = if n < 2 then apply k 1 else fib_defunc ( n - 1 ) ( C1 (n , k ) ) にわとりかんさつにっき in お茶大 20/24
  • 32. はじめに ゼミ 授業 おわりに fibonacci (Coq) Fixpoint app ( k : cont_fib ) ( x : nat ) ( count : nat ) { struct count } : option nat : = match count with | O = > None | S count ’ = > match k with | C0_fib = > Some x | C1_fib n k = > fib_defunc ( minus n 1 ) ( C2_fib x k ) count ’ | C2_fib n1 k = > app k ( plus n1 x ) count ’ end end with fib_defunc ( n : nat ) ( k : cont_fib ) ( count : nat ) { struct count } : option nat : = match count with | O = > None | S count ’ = > match n with | O | S O = > app k 1 count ’ | S m = > fib_defunc m ( C1_fib m k ) count ’ end end . にわとりかんさつにっき in お茶大 21/24
  • 33. はじめに ゼミ 授業 おわりに 真面目な研究もやっています D1 の先輩: Coqer · · · 強正規化性の証明,プログラム抽出 M1 の後輩: Coqer / Agdar · · · functional derivation の証明 (今は Agda 勉強中) にわとりかんさつにっき in お茶大 22/24
  • 34. はじめに ゼミ 授業 おわりに ちなみに 私の研究: shift/reset の直接実装 最近は Caml Light に shift/reset 導入 functional derivation の手法を利用して, definitional interpreter =⇒ ZINC の証明 怪しい変換の部分に Coq を使いたい ... かも ? 圏論の方で Coq を使いたい ... かも ?? にわとりかんさつにっき in お茶大 23/24
  • 35. はじめに ゼミ 授業 おわりに   おわり u u h ¤ h ¤ h にわとりかんさつにっき in お茶大 24/24