Fixpoint evenb (n:nat) : bool := match n with | O => true | S O => false | S (S n') => evenb n' end. (** Inductively defined predicate *) Inductive even : nat -> Prop := | E0 : even O | E2 : forall n, even n -> even (S (S n)). Print even_ind. Theorem even_evenb : forall n, even n -> evenb n = true. Proof. intros n e. induction e as [ | n e IHe]. reflexivity. exact IHe. Qed. (** The converse is more difficult First we need to strengthen the induction to 2 consecutive numbers. Second we need to cope with n = 1. We will see later a special tactics for doing this. Here is a basic trick: using the fact that [false = true -> 1 = 0] *) Definition trick (b: bool) := match b with true => 0 | false => 1 end. Lemma false_true_01 : evenb 1 = true -> 1 = 0. Proof. intro e. change (trick (evenb 1) = trick true). rewrite e. reflexivity. Qed. Theorem evenb_even_n_and_Sn : forall n, (evenb n = true -> even n) /\ (evenb (S n) = true -> even (S n)). Proof. intros n. induction n as [ | n [IHn IHSn]]. split. intro; exact E0. intro ft. rewrite (false_true_01 ft). exact E0. split. exact IHSn. intro e. apply E2. exact (IHn e). Qed. (* --------------------------------------------------------------------- *) (** Inversion *) (** Boils down to discrimination for [evenb] *) Theorem evb1 : forall P:Prop, evenb 1 = true -> P. Proof. intros P e. simpl in e. change (match true with false => True | _ => P end). case e. trivial. Qed. Theorem evb1_simple_way : forall P:Prop, evenb 1= true -> P. Proof. intros P e. simpl in e. discriminate e. Qed. (** More complicated for [even] *) (** Simpler when the argument of [even] occurs in the conclusion *) Theorem ev1_easy : forall P: nat->Prop, P 0 -> (forall n, even n -> P (S (S n))) -> even 1 -> P 1. Proof. intros P p0 p2. intro e. destruct e as [ | n e]. exact p0. apply p2; assumption. Qed. (** Otherwise, we make an artificial conclusion with such an argument *) Theorem ev1 : forall P:Prop, even 1 -> P. Proof. intros P e. (* does not work : destruct e as [| n e]. *) assert (two_absurds: 0 = 1 \/ exists n, S (S n) = 1). - apply ev1_easy. + left; reflexivity. + intro n; right; exists n; reflexivity. + exact e. - clear e. destruct two_absurds as [e01 | [n e2]]. + change (match 1 with 0 => True | _ => P end). rewrite <- e01. trivial. + change (match 1 with S (S x) => True | _ => P end). rewrite <- e2. trivial. Qed. (** The tactics inversion does a similar work automatically *) Theorem ev1_simple_way : forall P:Prop, even 1 -> P. Proof. intros P e. inversion e. Qed.