Coq中归纳集的归纳子集

时间:2016-02-09 10:47:25

标签: coq

我有一个由三个构造函数构建的归纳集:

Inductive MF : Set :=
| D : MF
| cn : MF -> MF -> MF
| dn : Z -> MF -> MF.

我想以某种方式定义新的归纳集B,使得B是MF的子集,其仅包含从D和dn获得的元素。此外,如果需要,B中的所有内容都应解释为MF类型。

我尝试定义第一个B然后MF如下:

Inductive B : Set :=
| D : B
| dn : Z -> B -> B.

Inductive MF : Set :=
| m : B -> MF
| cn : MF -> MF -> MF
| Dn : Z -> MF -> MF.
Axiom m_inj : forall (a b : B), m a = m b -> a = b.
Coercion m : B >-> MF.
Axiom dnDn : forall (a : B)(i : Z), (m (dn i a)) = (Dn i (m a)).

这里的问题是我必须构造者(dn和Dn)应该可以互换B中的元素。这给了我很多进一步发展的问题,我不得不继续添加公理以获得预期的行为。

2 个答案:

答案 0 :(得分:4)

请注意,您必须证明isB mf在您的设置中享有不相关的证据,否则Coq不会知道投影mf是单射的。通常,您希望MF中的平等意味着您的子类型B中的平等。

我建议以下变体:

Require Import Bool ZArith Eqdep_dec.

Inductive MF : Set :=
  | D : MF
  | cn : MF -> MF -> MF
  | dn : Z -> MF -> MF.

Inductive isB : MF -> Prop :=
  | DIsOK  : isB D
  | dnIsOK : forall z mf, isB mf -> isB (dn z mf).

Fixpoint isBb (mf : MF) : bool :=
  match mf with
  | D       => true
  | dn _ mf => isBb mf
  | _       => false
  end.

Lemma mfP mf : reflect (isB mf) (isBb mf).
Proof.
apply iff_reflect; split.
+ elim mf; auto; simpl; intros mf1 ihmf1 mf2 ihmf2.
  - now intros hisB; inversion hisB.
  - now inversion ihmf2; rewrite mf2.
+ now elim mf; simpl; try repeat (auto||constructor||congruence).
Qed.

Record B := mkB
  { mf  : MF
  ; prf : isBb mf = true
  }.

Coercion mf : B >-> MF.

(* From http://cstheory.stackexchange.com/questions/5158/prove-proof-irrelevance-in-coq *)
Theorem bool_pirrel : forall (b : bool) (p1 p2 : b = true), p1 = p2.
Proof.
intros; apply Eqdep_dec.eq_proofs_unicity; intros.
now destruct (Bool.bool_dec x y); tauto.
Qed.

Lemma valB b1 b2 : mf b1 = mf b2 -> b1 = b2.
Proof.
destruct b1, b2; simpl; intros ->.
now rewrite (bool_pirrel (isBb mf1) prf0 prf1).
Qed.

math-comp库对布尔谓词的子类型有很好的系统支持,如果你发现自己处理了许多子类型,你可能想要试一试。

答案 1 :(得分:1)

您可以将B定义为打包MF元素的记录以及仅使用Ddn构建的证明。为此,您需要首先定义谓词isB : MF -> Prop,该谓词描述MF的{​​{1}}元素。

B
相关问题