Skip to Content.
Sympa Menu

coq-club - Re: [Coq-Club] Newbie question on dependent well founded recursion

coq-club AT inria.fr

Subject: The Coq mailing list

List archive

Re: [Coq-Club] Newbie question on dependent well founded recursion


chronological Thread 
  • From: Jean-Francois Monin <jean-francois.monin AT imag.fr>
  • To: Sidi <Sidi.Ould_Biha AT inria.fr>
  • Cc: coq-club AT inria.fr
  • Subject: Re: [Coq-Club] Newbie question on dependent well founded recursion
  • Date: Tue, 29 Jun 2010 15:27:14 +0800
  • Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=sTaJAuD0t6DGlGvekj+gf87tLfjkU99OR/Yod4c3mymZ72UScjOPM8RGM6kttbNN1t PJzku1sIQI43IUCrrHfGwx+xyC3vnmqntA4i1WBbUjEiIyREdIPlvRj8IKyiostVxDBU CXNcmrFnwT8vi+NoSoz+lW4IqWeu+8wiyxb7Q=

Like this:

Proof.
intros. case H. simpl. reflexivity.
Qed.

Bottom line: eliminate H since it is the engine (better: the fuel)
of your function.

Hope this helps,
JF

On Tue, Jun 29, 2010 at 02:52:28PM +0800, Sidi wrote:
> Hi,
> 
> I have some problems with proving some basic proprieties on a function
> defined recursively on a well founded predicate. Using the example given
> in the "Rec Coq Tutorial", the function I defined looks like :
> 
> Fixpoint div_aux (x y : nat) (H : Acc lt x) {struct H} : nat :=
>   match x as n return (x = n -> nat) with
>   | 0 => fun _ : x = 0 => 0
>   | S n => fun H0 : x = S n =>
>       match eq_nat_dec y 0 with
>       | left _ => y
>       | right T => S (div_aux (x - y) y (minus_decrease x y H
>                      (eq_ind_r (fun x0 => x0 <> 0) (sym_not_eq (O_S n))
> H0) T))
>       end
>   end (refl_equal x).
> 
> I understand that this is not the better way to define the division, but
> i do a pattern matching on x since in my original function i need to do
> a recursive call on a subterm of x and H.
> 
> With this definition of div_aux, my question is how can I proof this
> simple lemma :
> 
> Lemma div0 : forall y (H : Acc lt 0), div_aux 0 y H = 0.
> Proof.
> intros. unfold div_aux.
> 
> PS : The .v source file is the following
> 
> Require Import Minus.
> Require Import Arith.
> 
> Lemma minus_smaller_S : forall x y : nat, x - y < S x.
> Proof.
> intros x y; pattern y, x; elim x using nat_double_ind.
> destruct n; auto with arith.
> simpl; auto with arith.
> simpl; auto with arith.
> Qed.
> 
> Lemma minus_smaller_positive : forall x y : nat, x <> 0 -> y <> 0 -> x -
> y < x.
> Proof.
> destruct x; destruct y; simpl; intros; try tauto. apply minus_smaller_S.
> Qed.
> 
> Definition minus_decrease : forall x y:nat, Acc lt x -> x <> 0 -> y <> 0
> ->
> Acc lt (x - y).
> Proof.
> intros x y H; case H.
> intros Hz posz posy.
> apply Hz; apply minus_smaller_positive; assumption.
> Defined.
> 
> Fixpoint div_aux (x y : nat) (H : Acc lt x) {struct H} : nat :=
>   match x as n return (x = n -> nat) with
>   | 0 => fun _ : x = 0 => 0
>   | S n => fun H0 : x = S n =>
>       match eq_nat_dec y 0 with
>       | left _ => y
>       | right T => S (div_aux (x - y) y (minus_decrease x y H
>                      (eq_ind_r (fun x0 => x0 <> 0) (sym_not_eq (O_S n))
> H0) T))
>       end
>   end (refl_equal x).
> 
> Lemma div0 : forall y (H : Acc lt 0), div_aux 0 y H = 0.
> Proof.
> intros. unfold div_aux.
> 
> ---
> 
> Sidi
> 
> 
> 
> 
> 

-- 
Jean-Francois Monin
CNRS-LIAMA, Project FORMES  &  Universite de Grenoble 1

Office 3-605, FIT, Tsinghua University
Haidian District, Beijing 100084, CHINA
Tel: +86 10 62 79 69 79 ext 605
Fax@LIAMA:
 +86 10 6264 7458



Archive powered by MhonArc 2.6.16.

Top of Page