描述Coq中的递归类型

时间:2014-08-22 21:46:51

标签: coq

我想用以下规则定义抽象人类个体的类型:

  • 人类是男性还是女性
  • 一个人的配偶与自己有不同的性别,他们的配偶的配偶应该是他们自己。在数学术语中,forall h : Human, spouse (spouse h) = h

所以预期人类的类型为Sex -> Human -> Human

Inductive Sex := male | female.
Definition Human (sex_ : Sex) (spouse_ : Human) : Human := ???.

顺便说一句,我需要在下面定义一组函数:

man : Human -> Prop
woman : Human -> Prop
spouse : Human -> Human

我应该如何在Coq中描述它们?此外,我可以通过什么方式定义人类个体的实例或成对定义它们?非常感谢。

2 个答案:

答案 0 :(得分:1)

您可以在这里traditional外在地证明配偶的财产。我承认,它并不像我希望的那样好。

Inductive Sex := male | female.

Definition other (s:Sex) :=
  match s with
  | male => female
  | female => male
  end.

Inductive Human := stephen | stephanie | robert | roberta.

Definition sex (h:Human) : Sex :=
  match h with  
  | stephen => male
  | stephanie => female
  | robert => male 
  | roberta => female
 end.

Definition spouse' (h:Human) : {h' : Human | sex h' = other (sex h)}.
  refine (match h with  
  | stephen   => exist _ stephanie _ 
  | robert    => exist _ roberta _
  | stephanie => exist _ stephen _
  | robertra  => exist _ robert _
  end); reflexivity.
Defined.

Definition man h := sex h = male. 
Definition woman h := sex h = male. 

Definition spouse (h:Human) := let ' exist h' _ := spouse' h in h'.

Theorem traditional (h:Human) : spouse (spouse h) = h.
  compute.
  destruct h; reflexivity.
Qed.

答案 1 :(得分:0)

假设你不介意你的人类群体是有限的,(1)实现有限图,(2)将人类定义为男性或女性并给他们一个id(例如,{{1} }),(3)在图中连接那些人。如果您对可以连接人员的某些方式感到不满意,请定义谓词nat并坚持您认为可接受的人口子集acceptable : graph human -> Prop。您还要定义{g1 : graph human | acceptable g1}

如果你只是想谈论人口,无论他们可能是什么,就像我们可以谈论群体或领域,无论他们是什么,你可以将人口定义为任何一夫一妻制和异性恋的性别。

marry : forall h1 h2 : human, male h1 -> female h2 -> {g1 | acceptable g1} -> {g1 | acceptable g1}

布尔人可以构成人口。

Inductive sex : Set := male : sex | female : sex.

Definition population : Type := {human : Type & {gender : human -> sex & {spouse : human -> human | forall h1, spouse (spouse h1) = h1 /\ gender (spouse h1) <> gender h1}}}.

Definition human : population -> Type := @projT1 _ _.

假设您已经证明了人口中任何人的某些事情。

Definition gender (b1 : bool) : sex :=
  match b1 with
  | true => male
  | false => female
  end.

Theorem acceptable : forall b1, negb (negb b1) = b1 /\ gender (negb b1) <> gender b1.
Proof. destruct b1; repeat (firstorder || simpl || congruence). Qed.

Definition boolean_population : population.
Proof. unfold population. repeat refine (existT _ _ _). apply acceptable. Defined.

你也证明了它是布尔人。

Conjecture P : forall p1, human p1 -> Prop.
Conjecture fact : forall p1 h1, P p1 h1.