Top Banner
The Algorithm M 0 annot for Coq Extraction to Statically Typed Languages without Type Inference Yoshihiro Imai @yoshihiro503 IT Planning, Inc ML-Nagoya 2012 @yoshihiro503 IT Planning, Inc The Algorithm M 0 annot for Coq Extractionto Statically Typed Languageswithout Type Inference
27

The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

Feb 18, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

The AlgorithmM′annot

for Coq Extractionto Statically Typed Languages

without Type Inference

Yoshihiro Imai @yoshihiro503

IT Planning, Inc

ML-Nagoya 2012

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 2: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

Yoshihiro Imai

I Twitter: @yoshihiro503I Home Page:

http://proofcafe.org/ yoshihiro503/I Hatena: id:yoshihiro503

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 3: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

Coqすごい!

Extractionすごい!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 4: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

I 2007 LL魂@東京一ツ橋ホールI 2008 LL Future @東京なかのZEROI 2009 OSC名古屋@名古屋市立大学I 2010 Coq庵@名古屋市青少年文化センターI 2011 QCon Tokyo @東京ファッションタウンI 2011 TopSE講義@国立情報学研究所I 2011特殊研究 1後期講演@京都大学I 2012特別講義@名古屋大学I 2012 TopSE講義@国立情報学研究所

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 5: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

I Coqでアルゴリズムを定義し、証明できる

I Extraction機能でアルゴリズムからコードを自動生成

I 既存のコードと混ぜて使える!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 6: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点

Extractionの対象となる言語が限られている。

現状では次の 3種類:

I OCamlI HaskellI Scheme

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 7: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点

実は大丈夫。I 内部データでは小さな仮想言語mini-MLに一旦変換している。

I つまり対象言語の構文のためのプリンタを書けば簡単に拡張できる。

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 8: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

対象言語を増やす拡張の例

I coq-ruby: https://github.com/mzp/coq-rubyI coq-clojure: http://patch-tag.com/r/leque/coq-

clojure-ext/homeI coq2javascript: (*開発中*)

https://bitbucket.org/yoshihiro503/coq2javascriptI coq2sml: (*開発中*)

https://bitbucket.org/yoshihiro503/coq2sml

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 9: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点再び

mini-MLの特徴から、対象言語は次の機能を持た

なければならない:

I GCIラムダ式 (無名関数)I型推論

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 10: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点再び

mini-MLの特徴から、対象言語は次の機能を持た

なければならない:

I GC

Iラムダ式 (無名関数)I型推論

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 11: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点再び

mini-MLの特徴から、対象言語は次の機能を持た

なければならない:

I GCIラムダ式 (無名関数)

I型推論

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 12: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

問題点再び

mini-MLの特徴から、対象言語は次の機能を持た

なければならない:

I GCIラムダ式 (無名関数)I型推論

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 13: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 14: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 15: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 16: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

結論

I GCIラムダ式 (無名関数)I型推論

←ここを消せた!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 17: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

結論

I GCIラムダ式 (無名関数)I型推論←ここを消せた!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 18: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

ここから細かい話

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 19: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

coq-8.3pl3/plugins/extraction/extraction.ml

Coqの式 (Gallina)をmini-MLの式に変換する関数

extract_term :

env -> Mlenv.t -> ml_type ->

constr -> constr list -> ml_ast

constrがGallina, ml astはmini-MLの式,ml typeはmini-MLの型式。M′と呼ばれるアルゴリズムを使っている。

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 20: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

アルゴリズムM′

t := x| c| (fun x → t)| t t| let x = t in t| magic t

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 21: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

アルゴリズムM′annot

t := x[τ, . . . , τ]| c| (fun (x: τ) → t)| t t| let (x: τ) = t in t| magic[τ] t

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 22: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

アルゴリズムM′

[1] P. Letouzey, Certified functional programming Programextraction within Coq proof assistant, PhD thesis, 2004

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 23: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

アルゴリズムM′annot

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 24: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

結論

I GCIラムダ式 (無名関数)I型推論

←ここを消せた!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 25: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

結論

I GCIラムダ式 (無名関数)I型推論←ここを消せた!

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 26: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

Coq2Scala: ScalaへのExtractionI http://proofcafe.org/wiki/Coq2Scala

I 応用例: 証明された定理証明器のScala実装https://bitbucket.org/yoshihiro503/coqincoq scala/

I 応用例: [2]姜帆,田辺良則,本位田真一, Coqを使用したMapReduceアプリケーションの検証とScalaコードの抽出, PPL 2012

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference

Page 27: The Algorithm Mannot for Coq Extraction to Statically ...proofcafe.org/~yoshihiro503/mlnagoya.pdf · The Algorithm M0 annot for Coq Extraction to Statically Typed Languages without

Coqを学ぼう

I ソフトウェアの基礎 (日本語):http://proofcafe.org/sf/

I ProofCafe毎月第4土曜日:http://proofcafe.org/wiki/

@yoshihiro503 IT Planning, Inc

The AlgorithmM′annot for Coq Extractionto Statically Typed Languageswithout Type Inference