%% Proof that every natural number is even or odd
%%
%% This is a simple example where induction is needed at a nested rather
%% than immediate recursive call.
Kind nat type.
Type z nat.
Type s nat -> nat.
Define nat : nat -> prop by
nat z ;
nat (s N) := nat N.
Define even : nat -> prop by
even z ;
even (s (s N)) := even N.
Define odd : nat -> prop by
odd (s z) ;
odd (s (s N)) := odd N.
Theorem even_or_odd : forall N, nat N -> even N \/ odd N.
IH : induction on 1. intros HnatN. case HnatN.
- search.
- HnatN1 => case HnatN1.
+ search.
+ HnatN2 => Hdisj : apply IH to HnatN2. case Hdisj.
* search.
* search.
%% An example of mutual induction
Define
even' : nat -> prop,
odd' : nat -> prop
by
even' z ;
odd' (s N) := even' N ;
even' (s N) := odd' N.
Theorem even'_nat : forall N, even' N -> nat N.
IH : induction on 1. intros Heven. case Heven.
- search.
- Hodd => HevenPred : case Hodd. apply IH to HevenPred. search.
Theorem odd'_nat : forall N, odd' N -> nat N.
IH : induction on 1. intros Hodd. Heven : case Hodd. case Heven.
- search.
- HoddPred => apply IH to HoddPred. search.