<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Calibri, sans-serif;"><div>Using the inductive definition allows you to pattern match over the elements instead needing to match the index first.</div><div><br></div><div>Another reason to prefer inductive definitions is that they easier generalise, e.g. You could index Fin with coNats without having to change the code. The recursive definition doesn’t work with them.</div><div><br></div><div>Moreover in many cases we have to use inductive definitions, e.g. Have you tried to define typed lambda terms by recursion over the type?</div><div><br></div><div>Having said this, you are right there is this overhead. So in some cases the recursive definition has advantages.</div><div>Also I am more of an Agda user – in Coq the station may be different because the native support for dependently typed pattern matching isn’t so good.</div><div><br></div><div>Cheers,</div><div>Thorsten</div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> Cedric Auger &lt;<a href="mailto:sedrikov@gmail.com">sedrikov@gmail.com</a>&gt;<br><span style="font-weight:bold">Reply-To: </span> &quot;<a href="mailto:coq-club@inria.fr">coq-club@inria.fr</a>&quot; &lt;<a href="mailto:coq-club@inria.fr">coq-club@inria.fr</a>&gt;<br><span style="font-weight:bold">Date: </span> Tue, 16 Sep 2014 10:11:19 &#43;0100<br><span style="font-weight:bold">To: </span> &quot;<a href="mailto:coq-club@inria.fr">coq-club@inria.fr</a>&quot; &lt;<a href="mailto:coq-club@inria.fr">coq-club@inria.fr</a>&gt;<br><span style="font-weight:bold">Subject: </span> Re: [Coq-Club] Questions about two theorems<br></div><div><br></div><blockquote id="MAC_OUTLOOK_ATTRIBUTION_BLOCKQUOTE" style="BORDER-LEFT: #b5c4df 5 solid; PADDING:0 0 0 5; MARGIN:0 0 0 5;"><div dir="ltr"><div class="gmail_default" style="font-family:courier new,monospace">Yes, that is clever.<br>By the way, I do not know why people use this definition of &quot;fin&quot; which I find rather inconvenient.<br><br>Inductive emptySet : Type := .<br><br>Fixpoint fin2 (n : nat) : Type := match n with O =&gt; emptySet | S n =&gt; option (fin2 n) end.<br><br>is a lot more convenient from my point of view.<br>Here, we do not have to do all these inversion stuff when inspecting an element.<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2014-09-15 18:06 GMT&#43;02:00 Daniel Schepler <span dir="ltr">&lt;<a href="mailto:dschepler@gmail.com" target="_blank">dschepler@gmail.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Mon, Sep 15, 2014 at 8:50 AM, John Wiegley &lt;<a href="mailto:johnw@newartisans.com">johnw@newartisans.com</a>&gt; wrote:<br>
&gt; Thanks to you and Daniel, I am now much closer.&nbsp; However, I'm still having<br>
&gt; difficulty with the above statement: what about the case where hd is not the<br>
&gt; greatest element of fin (S n)?&nbsp; Then the fact that x &lt;&gt; hd doesn't help me,<br>
&gt; since hd could be an element which *should* be in y, rather than x.&nbsp; It seems<br>
&gt; like your proof assumes an ordered set from greatest to last, when the<br>
&gt; original statement requires no ordering.&nbsp; Daniel did make reference to the<br>
&gt; fact that having a sorting property could make things easier.<br><br>
OK, here's a complete solution.&nbsp; As opposed to what Auger suggested,<br>
my proof essentially proceeds by cases depending on whether or not<br>
FinO is in the list.&nbsp; That makes it easier to define the injection {<br>
x:Fin (S n) | x &lt;&gt; FinO } -&gt; Fin n.<br><br>
Require Import List.<br>
Require Import Arith.<br><br>
Inductive Fin : nat -&gt; Set :=<br>
| FinO : forall {n:nat}, Fin (S n)<br>
| FinS : forall {n:nat}, Fin n -&gt; Fin (S n).<br><br>
Definition Fin_0_inv (P : Fin 0 -&gt; Type) :<br>
&nbsp; forall x:Fin 0, P x :=<br>
fun x =&gt;<br>
match x in (Fin z) return<br>
&nbsp; (match z return (Fin z -&gt; Type) with<br>
&nbsp; &nbsp;| 0 =&gt; P<br>
&nbsp; &nbsp;| S _ =&gt; fun _ =&gt; unit<br>
&nbsp; &nbsp;end x) with<br>
| FinO _ =&gt; tt<br>
| FinS _ _ =&gt; tt<br>
end.<br><br>
Definition Fin_Sn_inv {n:nat} (P : Fin (S n) -&gt; Type)<br>
&nbsp; (PO : P FinO) (PS : forall y:Fin n, P (FinS y)) :<br>
&nbsp; forall x:Fin (S n), P x :=<br>
fun x =&gt;<br>
match x in (Fin Sn) return<br>
&nbsp; (match Sn return (Fin Sn -&gt; Type) with<br>
&nbsp; &nbsp;| 0 =&gt; fun _ =&gt; unit<br>
&nbsp; &nbsp;| S n' =&gt; fun x =&gt; forall (P : Fin (S n') -&gt; Type),<br>
&nbsp; &nbsp; &nbsp;P FinO -&gt; (forall y:Fin n', P (FinS y)) -&gt;<br>
&nbsp; &nbsp; &nbsp;P x<br>
&nbsp; &nbsp;end x) with<br>
| FinO _ =&gt; fun P PO PS =&gt; PO<br>
| FinS _ y =&gt; fun P PO PS =&gt; PS y<br>
end P PO PS.<br><br>
Definition FinS_inv {n:nat} (x:Fin (S n)) :<br>
&nbsp; option (Fin n) :=<br>
Fin_Sn_inv (fun _ =&gt; option (Fin n)) None (@Some _) x.<br><br>
Fixpoint map_FinS_inv {n:nat} (l : list (Fin (S n))) :<br>
&nbsp; list (Fin n) :=<br>
match l with<br>
| nil =&gt; nil<br>
| cons x l' =&gt;<br>
&nbsp; let recval := map_FinS_inv l' in<br>
&nbsp; match FinS_inv x with<br>
&nbsp; | Some y =&gt; cons y recval<br>
&nbsp; | None =&gt; recval<br>
&nbsp; end<br>
end.<br><br>
Lemma map_FinS_inv_len_noO :<br>
&nbsp; forall {n:nat} (l : list (Fin (S n))),<br>
&nbsp; ~ In FinO l -&gt; length (map_FinS_inv l) = length l.<br>
Proof.<br>
induction l; simpl.<br>
&#43; reflexivity.<br>
&#43; destruct a using Fin_Sn_inv; simpl; intuition.<br>
Qed.<br><br>
Lemma map_FinS_inv_len_NoDup :<br>
&nbsp; forall {n:nat} (l : list (Fin (S n))),<br>
&nbsp; NoDup l -&gt; length l &lt;= S (length (map_FinS_inv l)).<br>
Proof.<br>
induction 1; simpl.<br>
&#43; repeat constructor.<br>
&#43; destruct x using Fin_Sn_inv; simpl; intros.<br>
&nbsp; - rewrite map_FinS_inv_len_noO; trivial.<br>
&nbsp; - auto with arith.<br>
Qed.<br><br>
Lemma in_map_FinS_inv : forall {n:nat} (l : list (Fin (S n)))<br>
&nbsp; (y : Fin n), In y (map_FinS_inv l) -&gt; In (FinS y) l.<br>
Proof.<br>
induction l; simpl.<br>
&#43; trivial.<br>
&#43; destruct a using Fin_Sn_inv; simpl.<br>
&nbsp; - auto.<br>
&nbsp; - destruct 1.<br>
&nbsp; &nbsp; * left; f_equal; trivial.<br>
&nbsp; &nbsp; * right; auto.<br>
Qed.<br><br>
Lemma map_FinS_inv_NoDup : forall {n:nat} (l : list (Fin (S n))),<br>
&nbsp; NoDup l -&gt; NoDup (map_FinS_inv l).<br>
Proof.<br>
induction 1; simpl.<br>
&#43; constructor.<br>
&#43; destruct x using Fin_Sn_inv; simpl.<br>
&nbsp; - trivial.<br>
&nbsp; - constructor; trivial. contradict H. apply in_map_FinS_inv; trivial.<br>
Qed.<br><br>
Theorem fin_list : forall {n:nat} (l : list (Fin n)),<br>
&nbsp; NoDup l -&gt; length l &lt;= n.<br>
Proof.<br>
induction n.<br>
&#43; destruct l.<br>
&nbsp; - trivial.<br>
&nbsp; - destruct f using Fin_0_inv.<br>
&#43; intros. apply le_trans with (1 := map_FinS_inv_len_NoDup l H).<br>
&nbsp; auto using le_n_S, map_FinS_inv_NoDup.<br>
Qed.<br><span class="HOEnZb"><font color="#888888">--<br>
Daniel Schepler<br></font></span></blockquote></div><br><br clear="all"><br>-- <br>.../Sedrikov\...
</div></blockquote></span>
<br><p>This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.&nbsp;&nbsp; Please do not use, copy or disclose the information contained in this message or in any attachment.&nbsp; Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.</p><p>This message has been checked for viruses but the contents of an attachment may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.</p>
<br></body></html>