2017-09-22 142 views

回答

3

你需要证明平等是可判定为ty(这是可以做到自动使用decide equality),然后在if ... then ... else ...语句中使用该定义。具体来说:

Inductive ty: Set := 
| I 
| O. 

Definition ty_eq_dec : forall (x y : ty), { x = y } + { x <> y }. 
Proof. 
decide equality. 
Defined. 

Definition f (x: ty) (y: ty): nat := 
    if ty_eq_dec x y then 0 else 1. 
+0

你能告诉我更多关于{} + {}的信息吗?我认为它就像Proposition1或Prop2。但是这种方式不行。有没有像他们分裂? – abhishek

+0

@abhishek请参阅[sumbool](https://coq.inria.fr/library/Coq.Bool.Sumbool.html)。例如,更多解释[本博客文章](http://seb.mondet.org/blog/post/coqtests-02-sumbools.html) – gallais

1

您可以使用match来感应数据类型的元素进行比较。

Definition f x y := match x,y with I, I | O, O => 0 | _,_ => 1 end. 

decide equality是一个更普遍的策略,并适用于无限集,但它是很好的知道,这是match是做实际工作。

+0

你可以通过注意到这个函数满足所有xy,fxy = 0 <-> x = y在这种情况下可以很容易地证明这一点。 – Yves

相关问题