(* ========================================================================== *)
(* FLYSPECK - BOOK FORMALIZATION *)
(* *)
(* A bound for the number pi *)
(* Chapter: Tame *)
(* Author: Vu Quang Thanh *)
(* Date: 2010-02-13 *)
(* ========================================================================== *)
(* ========================================================================= *)
(* Quick derivation of a pi approximation (could do this more nicely). *)
(* ========================================================================= *)
module Pishort = struct
let TAYLOR_SIN = prove
(`!n x. abs(
sin x -
sum(0..n) (\i. (if i MOD 4 = 0 then &0
else if i MOD 4 = 1 then &1
else if i MOD 4 = 2 then &0
else -- &1) * x pow i / &(
FACT i)))
<= abs x pow (n + 1) / &(
FACT (n + 1))`,
REPEAT STRIP_TAC THEN
MP_TAC(ISPECL [`\n. if n MOD 4 = 0 then
sin
else if n MOD 4 = 1 then
cos
else if n MOD 4 = 2 then \x. --(
sin x)
else \x. --(
cos x)`;
`n:num`;
`
real_interval[--(abs x),abs x]`; `&1`]
REAL_TAYLOR) THEN
REWRITE_TAC[] THEN ANTS_TAC THENL
[REPEAT CONJ_TAC THENL
[REWRITE_TAC[
is_realinterval;
IN_REAL_INTERVAL] THEN REAL_ARITH_TAC;
ALL_TAC;
MESON_TAC[
REAL_ABS_NEG;
SIN_BOUND;
COS_BOUND]] THEN
ONCE_REWRITE_TAC[GSYM(MATCH_MP
MOD_ADD_MOD (ARITH_RULE `~(4 = 0)`))] THEN
REPEAT STRIP_TAC THEN REPEAT_TCL DISJ_CASES_THEN SUBST1_TAC (ARITH_RULE
`i MOD 4 = 0 \/ i MOD 4 = 1 \/ i MOD 4 = 2 \/ i MOD 4 = 3`) THEN
CONV_TAC NUM_REDUCE_CONV THEN
GEN_REWRITE_TAC (RATOR_CONV o LAND_CONV) [GSYM ETA_AX] THEN
REWRITE_TAC[] THEN REAL_DIFF_TAC THEN REAL_ARITH_TAC;
CONV_TAC NUM_REDUCE_CONV THEN REWRITE_TAC[
COND_RATOR] THEN
DISCH_THEN(MP_TAC o SPECL [`&0:real`; `x:real`]) THEN
REWRITE_TAC[
IN_REAL_INTERVAL] THEN ANTS_TAC THENL
[REAL_ARITH_TAC; ALL_TAC] THEN
REWRITE_TAC[
REAL_SUB_RZERO;
COS_0;
SIN_0;
REAL_NEG_0; REAL_MUL_LID]]);;
let PI_APPROX = prove
(`abs(
pi - &13493037705 / &4294967296) <= inv(&2 pow 32)`,
REWRITE_TAC[REAL_ARITH `abs(x - a) <= e <=> a - e <= x /\ x <= a + e`] THEN
MATCH_MP_TAC
SIN_PI6_STRADDLE THEN CONV_TAC REAL_RAT_REDUCE_CONV THEN
CONJ_TAC THENL
[W(MP_TAC o PART_MATCH (lhand o rand o lhand) (SPEC `12`
TAYLOR_SIN) o
lhand o snd);
W(MP_TAC o PART_MATCH (lhand o rand o lhand) (SPEC `12`
TAYLOR_SIN) o
rand o snd)] THEN
REWRITE_TAC[TOP_DEPTH_CONV num_CONV `12`] THEN
REPLICATE_TAC 13
(ONCE_REWRITE_TAC[
SUM_CLAUSES_NUMSEG] THEN REWRITE_TAC[
LE_0]) THEN
CONV_TAC NUM_REDUCE_CONV THEN CONV_TAC REAL_RAT_REDUCE_CONV THEN
REAL_ARITH_TAC);;
let bound_for_pi = prove (`!n. &n * (&852 / &1000) <= &2 *
pi ==> n <= 7`,
REPEAT STRIP_TAC THEN ASSUME_TAC (
PI_APPROX) THEN SUBGOAL_THEN `abs (
pi - &13493037705 / &4294967296) < &1 / &128` ASSUME_TAC THENL[ASM_REAL_ARITH_TAC; MP_TAC (SPECL [`
pi`; `&13493037705 / &4294967296`; `&1 / &128`]
REAL_ABS_BOUND) THEN ASM_REWRITE_TAC[] THEN DISCH_TAC THEN SUBGOAL_THEN `&n < &8` ASSUME_TAC THENL[ASM_REAL_ARITH_TAC ; MP_TAC (SPECL [`n:num`; `8`]
REAL_OF_NUM_LT) THEN ASM_REWRITE_TAC[] THEN ARITH_TAC]]);;
end;;