969

1 
(* Title: HOL/ex/puzzle.ML


2 
ID: $Id$


3 
Author: Tobias Nipkow


4 
Copyright 1993 TU Muenchen


5 


6 
For puzzle.thy. A question from "Bundeswettbewerb Mathematik"


7 


8 
Proof due to Herbert Ehler


9 
*)


10 


11 
(*specialized form of induction needed below*)


12 
val prems = goal Nat.thy "[ P(0); !!n. P(Suc(n)) ] ==> !n.P(n)";


13 
by (EVERY1 [rtac (nat_induct RS allI), resolve_tac prems, resolve_tac prems]);


14 
qed "nat_exh";


15 


16 
goal Puzzle.thy "! n. k=f(n) > n <= f(n)";


17 
by (res_inst_tac [("n","k")] less_induct 1);


18 
by (rtac nat_exh 1);


19 
by (simp_tac nat_ss 1);


20 
by (rtac impI 1);


21 
by (rtac classical 1);


22 
by (dtac not_leE 1);


23 
by (subgoal_tac "f(na) <= f(f(na))" 1);


24 
by (best_tac (HOL_cs addIs [lessD,Puzzle.f_ax,le_less_trans,le_trans]) 1);


25 
by (fast_tac (HOL_cs addIs [Puzzle.f_ax]) 1);


26 
bind_thm("lemma", result() RS spec RS mp);


27 


28 
goal Puzzle.thy "n <= f(n)";


29 
by (fast_tac (HOL_cs addIs [lemma]) 1);


30 
qed "lemma1";


31 


32 
goal Puzzle.thy "f(n) < f(Suc(n))";


33 
by (fast_tac (HOL_cs addIs [Puzzle.f_ax,le_less_trans,lemma1]) 1);


34 
qed "lemma2";


35 


36 
val prems = goal Puzzle.thy "(!!n.f(n) <= f(Suc(n))) ==> m<n > f(m) <= f(n)";


37 
by (res_inst_tac[("n","n")]nat_induct 1);


38 
by (simp_tac nat_ss 1);


39 
by (simp_tac nat_ss 1);


40 
by (fast_tac (HOL_cs addIs (le_trans::prems)) 1);


41 
bind_thm("mono_lemma1", result() RS mp);


42 


43 
val [p1,p2] = goal Puzzle.thy


44 
"[ !! n. f(n)<=f(Suc(n)); m<=n ] ==> f(m) <= f(n)";


45 
by (rtac (p2 RS le_imp_less_or_eq RS disjE) 1);


46 
by (etac (p1 RS mono_lemma1) 1);


47 
by (fast_tac (HOL_cs addIs [le_refl]) 1);


48 
qed "mono_lemma";


49 


50 
val prems = goal Puzzle.thy "m <= n ==> f(m) <= f(n)";


51 
by (fast_tac (HOL_cs addIs ([mono_lemma,less_imp_le,lemma2]@prems)) 1);


52 
qed "f_mono";


53 


54 
goal Puzzle.thy "f(n) = n";


55 
by (rtac le_anti_sym 1);


56 
by (rtac lemma1 2);


57 
by (fast_tac (HOL_cs addIs [Puzzle.f_ax,leI] addDs [leD,f_mono,lessD]) 1);


58 
result();
