使用coq对自动机进行模型化

时间:2014-03-18 09:39:48

标签: logic coq automaton

我在coq proof assisstant中定义自动机时遇到问题,当我创建此代码时显示错误:

(*automate*)

Record automaton :Type:=
mk_auto {
   states : Set;
   actions :Set;
   initial : states;
   transitions : states -> actions -> list states
}.
(*States*)
Inductive st :Set:= q0 | q1 |q2 .
Inductive acts:Set:=pred(p:nat)|event(e:bool).
Definition a :acts:=pred(0).
Definition b:acts:=pred(1).
Definition c:acts:=event(true).
Function trans (q:st)(x:acts) :list st :=
match q, x with
  | q0, a =>  cons q1 nil
  | q1, b =>  cons q0 nil
  | q1, c =>  cons q2 nil
  | _,_ =>    nil (A:=_)
end.

错误是: 错误:此子句是多余的。 (强调本条" | q1,c => cons q2 nil")

感谢您的关注。

1 个答案:

答案 0 :(得分:1)

当您执行模式匹配时,模式中有两种可能性:构造函数或类似于绑定器的自由变量。 例如,您的匹配的第一种情况显示为“如果q已使用q0构建,并且x的任何值都将被命名为a分支,做......'''

此分支中的a与您之前定义的Definition a之间没有任何关系。

因此,第2行和第3行是多余的,它们都捕获qq1构成且x具有任何值的情况。

我想你想要写一些类似的东西:

match q, x with
  | q0, pred 0 => cons q1 nil
  | q1, pred 1 => cons q0 nil
  | q1, event true => cons q2 nil
  | _, _ => nil (A := _)
end.

您可以在模式匹配分支中使用Definition创建别名。据我所知,执行此类别名的唯一方法是使用Notation

如果您将a bc的定义替换为:

Notation "'a'" := (pred 0).
Notation "'b'" := (pred 1).
Notation "'c'" := (event true).

那么你的代码就像(我认为)你想要的那样。我建议你阅读Coq手册的this部分来了解符号。

最佳, 诉