Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You probably want to define the following function (even if you annotate it properly you [le_S m n x] does not have the type you want) :</p> <pre><code> Fixpoint lesseq (m n : nat) : option (m &lt;= n) := match n with | 0 =&gt; match m with | 0 =&gt; Some (le_n 0) | S m0 =&gt; None end | S p =&gt; match lesseq m p with | Some l =&gt; Some (le_S m p l) | None =&gt; None end end. </code></pre> <p>But as you've noticed, the typechecker is not clever enough to guess the new context when you destruct a variable appearing in the type of the result. You have to annotate the match in the following way : </p> <pre><code> Fixpoint lesseq (m n : nat) : option (m &lt;= n) := match n return (option (m &lt;= n)) with | 0 =&gt; match m return (option (m &lt;= 0)) with | 0 =&gt; Some (le_n 0) | S m0 =&gt; None end | S p =&gt; match lesseq m p with | Some l =&gt; Some (le_S m p l) | None =&gt; None end end. </code></pre> <p>See the reference manual if you really want to understand how pattern matching works with dependent types. If you don't feel brave enough for that, you'd rather use tactics mechanisms to build your proof (the "refine" tactic is a great tool for that). </p> <pre><code> Definition lesseq m n : option (m &lt;= n). refine (fix lesseq (m : nat) (n : nat) {struct n} := _). destruct n. destruct m. apply Some; apply le_n. apply None. destruct (lesseq m n). apply Some. apply le_S. assumption. apply None. Defined. </code></pre> <p>By the way, I don't think your function will be really helpfull (even if it is a good idea), because you will need to prove the following lemma : Lemma lesseq_complete: forall m n, lesseq m n &lt;> None -> m > n. </p> <p>This is why people use Coq.Arith.Compare_dec. Have fun. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload