在Coq中描述递归类型

在Coq中描述递归类型,coq,Coq,我想用以下规则定义抽象人类个体的类型: 人不是男性就是女性 一个人有一个和自己性别不同的配偶,而他们配偶的配偶应该是他们自己。在数学术语中,对于所有h:Human,配偶(配偶h)=h 因此,人类应该具有Sex->human->human类型 Inductive Sex := male | female. Definition Human (sex_ : Sex) (spouse_ : Human) : Human := ???. 顺便说一下,我需要在下面定义一组函数: man : Huma

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

  • 人不是男性就是女性
  • 一个人有一个和自己性别不同的配偶,而他们配偶的配偶应该是他们自己。在数学术语中,
    对于所有h:Human,配偶(配偶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描述它们?此外,我可以用什么方式定义人类个体的实例或成对定义它们?非常感谢。

您可以从外部证明配偶的属性,这里是传统的
。不过我承认,这并不像我希望的那么好

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)实现一个有限图,(2)将人类定义为男性或女性,并给他们一个id(例如,
nat
),(3)在一个图中连接这些人类。如果您不满意人们之间可能存在的某些联系方式,请定义一个谓词
acceptable:graph human->Prop
,并坚持使用您认为可以接受的人群子集,
{g1:graph human | acceptable g1}
。您还需要定义
marry:forallh1h2:human,雄h1->雌h2->{g1 |可接受g1}->{g1 |可接受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 _ _.
你也为布尔人证明了这一点

Theorem boolean_fact : forall b1, P boolean_population b1.
Proof. apply fact. Qed.

谢谢,但我想我在描述中遗漏了什么。实际上,人的第二个属性应该有一个约束。我已经更新了这个问题。这个约束应该如何定义?我反对非规范程序!您不能定义
人类
,因为您已经指定为归纳类型,因为
配偶(配偶h)=h
的条件意味着该类型没有充分的依据。使用
共导式
可以做到这一点,尽管在Coq中很难使用这些方法。
Conjecture P : forall p1, human p1 -> Prop.
Conjecture fact : forall p1 h1, P p1 h1.
Theorem boolean_fact : forall b1, P boolean_population b1.
Proof. apply fact. Qed.