26. その他有用なコマンド
assert P 命題Pを新たな目標として追加する
cut P 命題Pを新たな目標として追加した上で現在の目標Gを P→Gに書き換える
discriminate 前提に間違った等式(「2=3」等)がある場合直ちに全体を真とする
replace a with b 目標のaをbに変えた上で「b=a」を新たな目標として追加する
simpl 目標の式をベータ簡約する
simpl in H 前提Hをベータ簡約する
auto 可能な限り自動で証明を行う
tauto
Require Import M モジュールMで定義されている物を使用可能にする
実はさっきの例程度の証明だったら tauto というコマンド
で自動的にやってくれる
28. 関数とデータ型の定義
Inductive name : Type :=
データ型の定義
cName:Type [ | cName:type ]*
Definition name : [param]* : Type := exp 非再帰関数や定理の定義
(停止性が明らかな)再帰関数の
Fixpoint name : [param]* : Type := exp
定義
(停止性が明らかでない)再帰関
Function name : [param]*
数の定義(Recdefのインポートが
{measure exp1} : Type := exp2
必要)
「measure exp1」の exp1 にはこの関数が停止する根拠を書かな
ければいけない. Functionで関数を定義しようとすると即座に停
止性についての証明が要求される
29. 定義の例 : リストとその演算
Inductive list (A : Type) : Type :=
| nil : list A
| cons : A -> list A -> list A.
Fixpoint app (A : Type)(l l' : list A) : list A :=
match l with
| nil => l'
| cons x xs => cons x (app A xs l')
end.
match v with … end
vについてのパターンマッチをするための構文
30. 定義の例 : 自然数とその演算
module Plus where
Inductive nat : Set :=
| O : nat
import qualified Prelude
| S : nat -> nat.
data Nat =
Fixpoint plus (n m : nat) : nat :=
O
match n with
| S Nat
| O => m
| S p => S (plus p m)
plus :: Nat -> Nat -> Nat
end.
plus n m =
Coqでの定義 case n of {
O -> m;
S p -> S (plus p m)}
(Haskell用に出力した場合)
39. 参考資料
Yves Bertot. Coq in a hurry.
池淵未来. プログラミングCoq
(http://www.iij-ii.co.jp/lab/techdoc/coqt/)
Gerard Huet and Christine Paulim Mohring.
Interactive Theorem Proving and Program
Development