Coq is a proof assistant based on type theory that can be used to formally verify programs and proofs. It supports program extraction to OCaml and can be used to prove properties of programs written in languages like OCaml, Java, C, and Assembly. Coq has been used to verify high assurance systems like the seL4 microkernel and TLS and JavaCard implementations. Formal verification in Coq is based on the Curry-Howard correspondence where types correspond to propositions and programs correspond to proofs. Tactics and rewriting rules are used to interactively prove goals in Coq.
This document summarizes a discussion about formalizing Kleene algebra and Brzozowski's derivatives in the Coq proof assistant. It describes how regular expressions and their derivatives were defined inductively in Coq, and how properties like Kleene's star were proved using tactics like setoid rewriting. It also provides instructions for Coq users to contribute formalizations by packaging files into a tar archive and submitting it to the Coq user contributions website.
This document discusses the Coq proof assistant. It provides examples of defining concepts like booleans, natural numbers, and functions in Coq. It demonstrates tactics for proving properties like De Morgan's laws. It also shows how to define recursive functions over natural numbers like addition and equality testing. The document aims to introduce basic concepts and usage of the Coq system through examples.
This document discusses type classes in Coq. It begins by introducing polymorphism and monads. It then defines the Monad type class in Coq, with return, bind, and other laws. Instances are given for the identity, maybe, list, and cont monads. The MonadPlus type class is also defined, with instances for maybe and list.
eq_nat is recursively defined to test equality of two natural numbers n and m by pattern matching on their constructions. It returns true if both are 0, or if their successors S n' and S m' are recursively equal; otherwise it returns false. Evaluating eq_nat 3 3 returns true since 3 is constructed by applying S twice to 0, and both arguments have the same construction.
- The document discusses several papers and tools related to parsing and regular expressions, including Brzozowski's derivative approach to parsing context-free grammars and a Scala library that implements regular expression matching in under 100 lines of code.
- It also mentions "Yacc is Dead", a paper arguing that LR parsing techniques provide a better alternative to Yacc than general parser generators due to being smaller and easier to implement.
- Additionally, the document recommends resources for learning more about formal language theory, parsing, and regular expressions.
This document defines integers as pairs of natural numbers (Z') in Coq, proves it forms a setoid, and defines addition on Z' as a morphism. Properties of addition like commutativity and identities are proven. Tactics for rewriting and replacing in setoids like setoid_rewrite and setoid_replace are introduced.
Maude is a programming language based on rewriting logic that allows both declarative and concurrent programming. It has applications in formal specification, model checking, and programming domains like DSL development. The document provides examples of defining natural numbers and a cigarette smoking simulation in Maude. It also describes using Maude's model checking capabilities to analyze a river crossing puzzle.
11. 記法を定義出来る (2)
• 単項演算子、mix-fixな演算子もOK : かなりDSLっぽくなる
Notation "~ x" := (not x) (at level 75, right associativity).
Notation "’IF’ c1 ’then’ c2 ’else’ c3" :=
(IF_then_else c1 c2 c3).
Notation "{ x : A | P }” := (sigA (fun x => P))
(at level 0, x at level 99).
• 推論して欲しい場合は@を付けないと(使用時に)エラー
Notation "x = y" := (@eq _ x y) (at level 70, no associativity).
• 定義と一緒に記法を定義出来る
Fixpoint plus (n m:nat) {struct n} : nat :=
match n with
| O => m
| S p => S (p+m)
end
where "n + m" := (plus n m).
11
12. 記法を定義出来る (3)
• パーサコンビネータと組み合わせて使っている例
http://www.seas.upenn.edu/~cis500/current/sf/html/ImpParser.html
Notation “‘DO’ ( x , y ) <-- e1 ;; e2 ‘OR’ e3” :=
(match e1 with
| SomeE (x,y) => e2
| NoneE err => e3
end) (right associativity, at level 60, e2 at next level).
• 使っている例
Fixpoint parsePrimaryExp (steps:nat) symtable (xs : list token)
: optionE (aexp * list token) :=
match steps with
| 0 => NoneE "Too many recursive calls"
| S steps' =>
DO (i, rest) <-- parseIdentifier symtable xs ;;
SomeE (AId i, rest)
OR DO (n, rest) <-- parseNumber xs ;;
SomeE (ANum n, rest)
OR (DO (e, rest) <== firstExpect "(" (parseSumExp steps' symtable) xs;;
DO (u, rest') <== expect ")" rest ;;
SomeE(e,rest'))
end 12
13. 記法を定義出来る (4)
• 繰り返しのあるパターン : .. を使って繰り返しを再帰的に表現出来る
– 可変長引数みたいなものを扱いたいときは便利
Coq < Notation "[ x ; .. ; y ]" :=
(@cons _ x .. (@cons _ y (@nil _) ) .. ).
Setting notation at level 0.
Coq < Check ([1 ; 2 ; 3]).
[1; 2; 3]
: list nat
• 実は下記でもOK
Coq < Notation "[ x ; .. ; y ]" := (cons x .. (cons y nil) ..).
Setting notation at level 0.
13
14. 記法定義の落とし穴
• えっ?定義が無いの?本当?
Coq < Locate "->".
Unknown notation
• 定義出来た!?
Notation "A -> B" := (and A B) (at level 80, right associativity).
• 本当に定義が上書きされたのか?
Coq < Lemma test : True -> True.
test < intros.
1 subgoal
============================
True -> True (* 変化が無い *)
test < split.
2 subgoals
============================
True (* and なので split される *)
subgoal 2 is:
True
• Locate信用出来ない。重要な予約語の上書きには注意。 14
15. Tacticの定義の方法
CPDTに載っているTactic定義の例 (p.217)
Coq < Ltac my_tauto :=
Coq < repeat match goal with
Coq < | [ H : ?P |- ?P ] => exact H
Coq < | [ |- True ] => constructor
Coq < | [ |- _ / _ ] => constructor
Coq < | [ |- _ -> _ ] => intro
Coq < | [ H : False |- _ ] => destruct H
Coq < | [ H : _ / _ |- _ ] => destruct H
Coq < | [ H : _ / _ |- _ ] => destruct H
Coq < | [ H1 : ?P -> ?Q, H2 : ?P |- _ ] =>
Coq < let H := fresh “H” in (* Hなんとかみたいな新しい名前をつける *)
Coq < generalize (H1 H2); clear H1; intro H
Coq < end.
my_tauto is defined
repeatを外したmy_tauto1を作って、何度も適用すると動作の具合が良く解る
…これって、DSLに使えない?
• パターンマッチとかどう見ても高機能なんだが…
15