[英]Prop and bool in Coq
How can I use a comparison of to rational numbers in an if-statement? 如何在if语句中使用有理数的比较?
if 1 = 2 then 1 else 2
1 = 2
is of course Prop
and not bool
. 1 = 2
当然是Prop
而不是bool
。
I don't understand how dfan's answer is related to the question... 我不明白dfan的答案是如何与这个问题相关的......
Of course, 1 = 2
is a Prop
, it is the statement that 1 is equal to 2. Hopefully you don't have a proof of this statement... 当然, 1 = 2
是一个Prop
,它是1等于2的陈述。希望你没有这个陈述的证据......
What you want is a function that, given two natural numbers, 1
and 2
, returns true
if they are equal, and false
if they aren't. 你想要的是一个函数,给定两个自然数1
和2
,如果它们相等则返回true
如果不相等则返回false
。
The library Coq.Arith.EqNat
gives you such a function, named beq_nat
. 库Coq.Arith.EqNat
为您提供了一个名为beq_nat
的函数。
In fact, you might want something even better, a function that returns a proof of equality or a proof of difference: 事实上,你可能想要更好的东西,一个返回相等证明或差异证明的函数:
(* In Coq.Arith.Peano_dec *)
Theorem eq_nat_dec : forall n m, {n = m} + {n <> m}.
(* ^ a proof that n = m
^ or a proof that n <> m *)
if
is overloaded to work with such things, so you can even write: if
超载来处理这些事情,那么你甚至可以写:
if eq_nat_dec 2 3 then ... else ...
Qeq_bool
indeed takes two rationals and produces a bool. Qeq_bool
确实需要两个理性并产生一个bool。
Require Export QArith_base.
Eval compute in Qeq_bool (3#2) (3#2). = true: bool
Eval compute in Qeq_bool (3#2) (5#2). = false: bool
Eval compute in (if Qeq_bool (3#2) (5#2) then 7 else 9). = 9: nat
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.