2017-09-22 138 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

相關問題