1、Section Loc. End Loc. Print ident 打印定义,ident 可以是本段定义的任何对象,类型以及本段所包括的库中定义的对象和类型。Example:Print R. Check ident 检查类型,check 可以检查本段定义的对象和类型。Variable tab:Type. Check tab. Definition ident :type := define 定义一个对象,可以选择性声明其类型,但是必须要有定义体,即:=后的内容。Definition setiod:=nat. Variable ident :type 声明一个局部变量,只需给出类型,不需要定义体
2、。当没有 section 包围时,顶级的局部变量等价于全局变量。Variable ck: nat. Parameter ident :声明一个全局变量,只需给出类型,不需要定义体。Parameter ck:nat. Inductive ident := | constru : type1typ2| . 定义一个归纳体,可以包含若干个构造子(constru),但是每个构造子的类型的最后必须是归纳体类型。Inductive expr : Type : | Evar : ident expr | Econst : Z | Eadd : expr | Esub :. Lemma em:定义一个猜想,其
3、类型为 type。通常需要给出证明 Lemma not_all_not_ex :forall P:U Prop, (forall n:U, P n) exists n :U, P n. Fixpoint fun (A:type)(B:type):type:= tail. fixpoint 可以定义递归函数,其中括号中的是传入参数。在 tail 中常使用 match 结构可以对归纳结构进行拆分。Fixpoint tail_plus n m:nat: match n with | 0=m | S n=tail_plus n (S m) end. Compute expr 归纳演算 expr 的值。
4、Compute 1+1. Structure exp := dom1:typ1; dom2:typ2; dom3:typ3:=value 定义结构体,可以包含若干个域,域的名字不能重复,通过 dom1 exp 来访问域的值,利用Build_exp 来构造。Structure person:= name:string; age:nat . Coercion Rela: typ1typ2 建立从 typ1 到 typ2 的强制子类型约束,Rela 是之前定义的转换关系。Variable dog:Type. Variable husky:Variable belong:huskydog. Coerc
5、ion belong:huskySearch keyword 搜索关键字的定义 Search nat. SearchAbout keyword 搜索所有关键字相关的定义 SearchAbout nat. SearchPattern exp 搜索指定形式的定义式。SearchAbout ( _ nat). 特殊库的使用 String:打开字符串库符之后字符串的表述 :“Ser” Check “Ds”. 构造子有 nil 和 n:l 两个,可用+连接两个列表。Ensemble 需要先定义元素类型,然后可以声明集合。Variable I:Variable set1:Ensemble I. Check
6、 Union I set1 set2. Check Intersection I set1 set2 证明相关 Proof. 开始证明 Qed. 证明结束 Hint Resolve lem 将 lem 加入 auto 库 证明策略:intros/intro 用于 goal 里面有 forall,Pintros P H0. intros. unfold 展开非递归函数 unfold is_ture. unfold is_true in H. rewrite H 将 H 的右边当作左边带入 goal 或者指定的目标 rewrite H. rewrite H in H0. rewrite H 将 H
7、 的左边当作右边带入 goal 或指定目标 H. rewrite Q). 高级技法: 证明即程序: Definition half(n:nat):p:nat & n = 2*p +n = S(2*p). induction n. exists 0;left; destruct IHn as x Hx | Hx. exists x;right; exists (S x); Require Import Arith. rewrite Hx; ring. Defined. Print sigT. Compute half 3. Check existT. Definition half(n: nat
8、): nat := match half n with existT p _ = p end. 附录 1:Ensemble 定义:Library Coq.Sets.Ensembles Section Ensembles. Variable U : Type. Definition Ensemble := U Prop. Definition In (A:Ensemble) (x:U) : Prop := A x. Definition Included (B C:Ensemble) := forall x:U, In B x In C x. Inductive Empty_set : Ense
9、mble :=. Inductive Full_set : Full_intro : forall x:U, In Full_set x. NB: The following definition buildsin equality of elements in U as Leibniz equality. This may have to be changed if we replace U by a Setoid on U with its own equality eqs, with In_singleton: (y: U)(eqs x y) (In (Singleton x) y).
10、Inductive Singleton (x: In_singleton : In (Singleton x) x. Inductive Union (B C: | Union_introl : In (Union B C) x | Union_intror :U, In C x In (Union B C) x. Definition Add (B:= Union B (Singleton x). Inductive Intersection (B C: Intersection_intro : In C x In (Intersection B C) x. Inductive Couple
11、 (x y: | Couple_l : In (Couple x y) x | Couple_r : In (Couple x y) y. Inductive Triple (x y z: | Triple_l : In (Triple x y z) x | Triple_m : In (Triple x y z) y | Triple_r : In (Triple x y z) z. Definition Complement (A:= fun x:U = In A x. Definition Setminus (B C: fun x: In B x / In C x. Definition
12、 Subtract (B:= Setminus B (Singleton x). Inductive Disjoint (B C: Disjoint_intro : (forall x:U, In (Intersection B C) x) Disjoint B C. Inductive Inhabited (B: Inhabited_intro : Inhabited B. Definition Strict_Included (B C:= Included B C / B C. Definition Same_set (B C:= Included B C / Included C B.
13、Extensionality Axiom Axiom Extensionality_Ensembles : forall A B:Ensemble, Same_set A B A = B. End Ensembles. Hint Unfold In Included Same_set Strict_Included Add Setminus Subtract: sets v62. Hint Resolve Union_introl Union_intror Intersection_intro In_singleton Couple_l Couple_r Triple_l Triple_m Triple_r Disjoint_intro Extensionality_Ensembles: sets v62.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1