needs "Library/analysis.ml";;
needs "Library/transc.ml";;
let cheb = define
`(!x. cheb 0 x = &1) /\
(!x. cheb 1 x = x) /\
(!n x. cheb (n + 2) x = &2 * x * cheb (n + 1) x - cheb n x)`;;
let CHEB_INDUCT = prove
(`!P. P 0 /\ P 1 /\ (!n. P n /\ P(n + 1) ==> P(n + 2)) ==> !n. P n`,
GEN_TAC THEN STRIP_TAC THEN
SUBGOAL_THEN `!n. P n /\ P(n + 1)` (fun th -> MESON_TAC[th]) THEN
INDUCT_TAC THEN ASM_SIMP_TAC[
ADD1; GSYM
ADD_ASSOC] THEN
ASM_SIMP_TAC[ARITH]);;
let NUM_ADD2_CONV =
let add_tm = `(+):num->num->num`
and two_tm = `2` in
fun tm ->
let m = mk_numeral(dest_numeral tm -/ Int 2) in
let tm' = mk_comb(mk_comb(add_tm,m),two_tm) in
SYM(NUM_ADD_CONV tm');;
let CHEB_CONV =
let [pth0;pth1;pth2] = CONJUNCTS cheb in
let rec conv tm =
(GEN_REWRITE_CONV I [pth0; pth1] ORELSEC
(LAND_CONV NUM_ADD2_CONV THENC
GEN_REWRITE_CONV I [pth2] THENC
COMB2_CONV
(funpow 3 RAND_CONV ((LAND_CONV NUM_ADD_CONV) THENC conv))
conv THENC
REAL_POLY_CONV)) tm in
conv;;
CHEB_CONV `cheb 8 x`;;
let CHEB_2N1 = prove
(`!n x. ((x - &1) * (cheb (2 * n + 1) x - &1) =
(cheb (n + 1) x - cheb n x) pow 2) /\
(&2 * (x pow 2 - &1) * (cheb (2 * n + 2) x - &1) =
(cheb (n + 2) x - cheb n x) pow 2)`,
ONCE_REWRITE_TAC[
SWAP_FORALL_THM] THEN GEN_TAC THEN
MATCH_MP_TAC
CHEB_INDUCT THEN
REWRITE_TAC[ARITH; cheb; CHEB_CONV `cheb 2 x`; CHEB_CONV `cheb 3 x`] THEN
REPEAT(CHANGED_TAC
(REWRITE_TAC[GSYM
ADD_ASSOC;
LEFT_ADD_DISTRIB; ARITH] THEN
REWRITE_TAC[ARITH_RULE `n + 5 = (n + 3) + 2`;
ARITH_RULE `n + 4 = (n + 2) + 2`;
ARITH_RULE `n + 3 = (n + 1) + 2`;
cheb])) THEN
CONV_TAC REAL_RING);;
let IVT_LEMMA1 = prove
(`!f. (!x. f contl x)
==> !x y. f(x) <= &0 /\ &0 <= f(y) ==> ?x. f(x) = &0`,
let IVT_LEMMA2 = prove
(`!f. (!x. f contl x) /\ (?x. f(x) <= x) /\ (?y. y <= f(y)) ==> ?x. f(x) = x`,
let SARKOVSKII_TRIVIAL = prove
(`!f:real->real. (!x. f contl x) /\ (?x. f(f(f(x))) = x) ==> ?x. f(x) = x`,
REPEAT STRIP_TAC THEN MATCH_MP_TAC
IVT_LEMMA2 THEN ASM_REWRITE_TAC[] THEN
CONJ_TAC THEN MATCH_MP_TAC
(MESON[] `P x \/ P (f x) \/ P (f(f x)) ==> ?x:real. P x`) THEN
FIRST_ASSUM(UNDISCH_TAC o check is_eq o concl) THEN REAL_ARITH_TAC);;