Assume P: nat -> T -> Prop is a proposition that for any given t: T,
- either there exists a
k: natsuch thatPholds for all numbers greater than or equal tokand no number less thank. - or
P k tis false for allk : nat.
I want to define min_k : T -> nat + undef to be the minimum number k such that P k t holds, and undef otherwise.
Is that even possible? I tried to define something like
Definition halts (t : T) := exists k : nat, P k t.
Or maybe
Definition halts (t : T) := exists! k : nat, (~ P k t /\ P (S k) t).
and then use it like
Definition min_k (t : T) := match halts T with
| True => ??
| False => undef
end.
but I don't know how to go further from there.
Any ideas would be appreciated.
You can't
matchon aProp. If you want to do case analysis then you need something inType, typicallyboolor something likesumboolorsumor. In other words, you can do what you want as long as you have a pretty strong hypothesis.Crucially, this wouldn't have worked if
PPropertywas aPropdisjunction, i.e., if it was of the form_ \/ _instead of the form_ + { _ }.By the way, the idiomatic way of describing
foo + undefin Coq is to useoption foo, which is what I did above, but you can adapt it as you wish.