问题
I would like to declare a structure in coq which represents a digraph which is well colored. I declared a Register which is accepted by coq if I don't have a condition. However I tried many ways of writing the condition wellColored
in coq without exit. Each time I get a new error message:
The condition wellColored is the following:
for every pair of vertices $v1$, $v2$ and every edge $e$, if the source of $e$ is $v1$,
the target of $e$ is $v2$ and the color of $v1$ is $a$ then there is a color $b$ such that $b$ is different from $a$ and the color of $v2$ is $b$.
My attempt is written below. What are the mistakes in the condition wellColored
and what is the correct definition?
Record dirgraph:={
V:Set;
E:Set;
s:E->V; (* source function *)
t:E->V; (* target function *)
l:V->nat;
wellColored: forall (v1:V) (v2:V) (e:E) (a:nat),
In V v1 /\ In V v2 /\ In E e /\ s e v1 /\ t e v2 /\ l v1 a-> (exists b, b<>a /\ l v2 b)
}.
For the moment I'm not interested in using packages with formalization of graphs. My main interest is to understand how to define structures and prove things about them. So I would like to define the graph precisely as it is above except with the correct condition.
回答1:
The problem with your definition is that some conditions that you impose on wellColored
do not need to be expressed, or simply cannot be expressed, in Coq's formalism:
I assume that by
In V v1
you mean thatv1
should be a member ofV
. Coq (as well as most type theories) is very different from usual set theory in this respect, because it doesn't make sense to assert that an object has some type as a proposition -- types in Coq (including things of typeSet
, likeV
in your definition) are not like sets in set theory. Instead, each object in the theory has its own type once and for all, and that type cannot change. When you writeforall (v1 : V), ...
, it is already assumed thatv1
is a member ofV
.If you want to say that some object of type
T
has some special property that not all objects of that type have (e.g., some numbern
is prime), you would express that with a predicate on that type (i.e., something of typeT -> Prop
), and not as a "subset" ofT
, as you would do in set theory.You defined
s
,t
andl
as functions of one argument, but used them as two-argument functions, as ins e v1
. I suppose you wanted to say something likev1 = s e
, i.e.v1
is the source of edgee
. However, there's no need to say that:s e
is an expression of typeV
like any other, and can be used directly, with no need to declare additional variables (see below). Likewise, you don't need to say that there exists some colorb
that is different froma
: you can just refer to the color of that node directly.
Here's a version of your type that avoids those problems:
Record dirgraph:={
V:Set;
E:Set;
s:E->V; (* source function *)
t:E->V; (* target function *)
color: V->nat;
wellColored:
forall e : E, color (s e) <> color (t e)
}.
来源:https://stackoverflow.com/questions/26893423/declaring-a-well-colored-digraph-in-coq