I have the following Definition in my spec file in Coq. I need to have a proposition comparing two "int" type values. These two are 't' and 'Int.repr (i.(period1))'.(i.period1) and (i.period2) have type 'Z'.
This is my code snippet:
Definition trans_uni_r_reject (i: invariant) (om os: block) (rid roff rval t: int) (m: mem) :=
( t > (Int.repr (i.(period1)))
/\ t < (Int.repr (i.(period2)))
/\ master_eval_reject i om os rid roff rval m).
This gives me the error below:
The term "t" has type "int" while it is expected to have type "Z".
I also tried:
(Int.cmpu Cgt t (Int.repr (i.(period1))))
/\ (Int.cmpu Clt t (Int.repr (i.(period2))))
/\ (master_eval_reject i om os rid roff rval m).
but it gives me this error:
The term "Int.cmpu Cgt t (Int.repr (period1 i))" has type "bool" while it is expected to have type "Prop".
Is there any way I can compare these two 'int' types or convert them to something else and return 'prop' type?
Thanks,
Any
bool
can be converted to aProp
by equating it totrue
. In your example, this would lead to:If you search results on the
Int.cmpu
operator, you'll probably find many lemmas in theInt
module that are stated in terms ofInt.cmpu Cgt x y = true
. For this, you can use theSearchAbout
command:Coercions
Equating booleans to
true
is so common that people often declare a coercion to use booleans as if they were propositions:Now, you can use any boolean in a context where a proposition is expected:
Behind the scenes, Coq inserts invisible calls to
is_true
around those occurrences. You should be aware, though, that the coercions still appear in your terms. You can see this by issuing a special command,which would show you the above snippet as Coq sees it:
(To undo the previous step, just run
Unset Printing Coercions
.)Because coercions are not printed by default, it can take you some time to use them effectively. The Ssreflect and MathComp Coq libraries make heavy use of
is_true
as a coercion, and have special support for making it simpler to use. If you're interested, I suggest you have a look at them!