(`!f g f' g' c L d.
&0 < d /\
(!x. &0 < abs(x - c) /\ abs(x - c) < d
==> (f diffl f'(x)) x /\ (g diffl g'(x)) x /\ ~(g'(x) = &0)) /\
f(c) = &0 /\ g(c) = &0 /\ (f --> &0) c /\ (g --> &0) c /\
((\x. f'(x) / g'(x)) --> L) c
==> ((\x. f(x) / g(x)) --> L) c`,
REPEAT STRIP_TAC THEN SUBGOAL_THEN
`!x. &0 < abs(x - c) /\ abs(x - c) < d
==> ?z. &0 < abs(z - c) /\ abs(z - c) < abs(x - c) /\
f(x) * g'(z) = f'(z) * g(x)`
(LABEL_TAC "*") THENL
[X_GEN_TAC `x:real` THEN DISCH_THEN(MP_TAC o MATCH_MP (REAL_ARITH
`&0 < abs(x - c) /\ abs(x - c) < d
==> c < x /\ x < c + d \/ c - d < x /\ x < c`)) THEN
STRIP_TAC THENL
[MP_TAC(SPECL
[`f:real->real`; `g:real->real`; `c:real`; `x:real`]
MVT2) THEN
ANTS_TAC THENL
[ASM_REWRITE_TAC[] THEN
GEN_REWRITE_TAC (LAND_CONV o BINDER_CONV o funpow 2 LAND_CONV)
[
REAL_LE_LT] THEN
ASM_MESON_TAC[
CONTL_LIM;
DIFF_CONT;
REAL_LT_IMP_LE; differentiable;
REAL_ARITH
`c < z /\ z <= x /\ x < c + d ==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
ASM_REWRITE_TAC[
REAL_SUB_RZERO] THEN MATCH_MP_TAC
MONO_EXISTS THEN
GEN_TAC THEN GEN_REWRITE_TAC (funpow 4 RAND_CONV) [REAL_MUL_SYM] THEN
REPEAT STRIP_TAC THENL
[ASM_REAL_ARITH_TAC;
ASM_REAL_ARITH_TAC;
FIRST_X_ASSUM(fun th -> MP_TAC th THEN
MATCH_MP_TAC EQ_IMP THEN BINOP_TAC) THEN
ASM_MESON_TAC[
DIFF_UNIQ; REAL_ARITH
`c < z /\ z < x /\ x < c + d ==> &0 < abs(z - c) /\ abs(z - c) < d`]];
MP_TAC(SPECL
[`f:real->real`; `g:real->real`; `x:real`; `c:real`]
MVT2) THEN
ANTS_TAC THENL
[ASM_REWRITE_TAC[] THEN
GEN_REWRITE_TAC (LAND_CONV o BINDER_CONV o LAND_CONV o RAND_CONV)
[
REAL_LE_LT] THEN
ASM_MESON_TAC[
CONTL_LIM;
DIFF_CONT;
REAL_LT_IMP_LE; differentiable;
REAL_ARITH
`c - d < x /\ x <= z /\ z < c ==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
ASM_REWRITE_TAC[
REAL_SUB_LZERO;
REAL_MUL_LNEG;
REAL_EQ_NEG2] THEN
MATCH_MP_TAC
MONO_EXISTS THEN GEN_TAC THEN
GEN_REWRITE_TAC (funpow 4 RAND_CONV) [REAL_MUL_SYM] THEN
REPEAT STRIP_TAC THENL
[ASM_REAL_ARITH_TAC;
ASM_REAL_ARITH_TAC;
FIRST_X_ASSUM(fun th -> MP_TAC th THEN
MATCH_MP_TAC EQ_IMP THEN BINOP_TAC) THEN
ASM_MESON_TAC[
DIFF_UNIQ; REAL_ARITH
`c - d < x /\ x < z /\ z < c
==> &0 < abs(z - c) /\ abs(z - c) < d`]]];
ALL_TAC] THEN
REWRITE_TAC[
LIM] THEN X_GEN_TAC `e:real` THEN DISCH_TAC THEN
UNDISCH_TAC `((\x. f' x / g' x) --> L) c` THEN REWRITE_TAC[
LIM] THEN
DISCH_THEN(MP_TAC o SPEC `e:real`) THEN ASM_REWRITE_TAC[] THEN
DISCH_THEN(X_CHOOSE_THEN `r:real` STRIP_ASSUME_TAC) THEN
MP_TAC(SPECL [`d:real`; `r:real`]
REAL_DOWN2) THEN ASM_REWRITE_TAC[] THEN
MATCH_MP_TAC
MONO_EXISTS THEN X_GEN_TAC `k:real` THEN STRIP_TAC THEN
ASM_REWRITE_TAC[] THEN X_GEN_TAC `x:real` THEN STRIP_TAC THEN
UNDISCH_TAC
`!x. &0 < abs(x - c) /\ abs(x - c) < r ==> abs(f' x / g' x - L) < e` THEN
REMOVE_THEN "*" (MP_TAC o SPEC `x:real`) THEN
ANTS_TAC THENL [ASM_REAL_ARITH_TAC; ALL_TAC] THEN
DISCH_THEN(X_CHOOSE_THEN `z:real` STRIP_ASSUME_TAC) THEN
DISCH_THEN(MP_TAC o SPEC `z:real`) THEN
ANTS_TAC THENL [ASM_REAL_ARITH_TAC; ALL_TAC] THEN
MATCH_MP_TAC(REAL_ARITH `x = y ==> abs(x - l) < e ==> abs(y - l) < e`) THEN
MATCH_MP_TAC(REAL_FIELD
`~(gz = &0) /\ ~(gx = &0) /\ fx * gz = fz * gx ==> fz / gz = fx / gx`) THEN
ASM_REWRITE_TAC[] THEN CONJ_TAC THENL
[ASM_MESON_TAC[
REAL_LT_TRANS]; ALL_TAC] THEN
MP_TAC(ASSUME `&0 < abs(x - c)`) THEN DISCH_THEN(MP_TAC o MATCH_MP
(REAL_ARITH `&0 < abs(x - c) ==> c < x \/ x < c`)) THEN
REPEAT STRIP_TAC THENL
[MP_TAC(SPECL [`g:real->real`; `c:real`; `x:real`]
ROLLE) THEN
ASM_REWRITE_TAC[NOT_IMP; GSYM
CONJ_ASSOC] THEN CONJ_TAC THENL
[GEN_TAC THEN GEN_REWRITE_TAC (funpow 2 LAND_CONV) [
REAL_LE_LT] THEN
ASM_MESON_TAC[
CONTL_LIM;
DIFF_CONT;
REAL_LT_TRANS; REAL_ARITH
`c < z /\ z <= x /\ abs(x - c) < d
==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
CONJ_TAC THENL
[ASM_MESON_TAC[differentiable;
REAL_LT_TRANS; REAL_ARITH
`c < z /\ z < x /\ abs(x - c) < d
==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
REWRITE_TAC[
NOT_EXISTS_THM] THEN X_GEN_TAC `w:real` THEN STRIP_TAC THEN
FIRST_X_ASSUM(MP_TAC o SPEC `w:real`) THEN
ANTS_TAC THENL [ASM_REAL_ARITH_TAC; ALL_TAC] THEN
ASM_MESON_TAC[
DIFF_UNIQ];
MP_TAC(SPECL [`g:real->real`; `x:real`; `c:real`]
ROLLE) THEN
ASM_REWRITE_TAC[NOT_IMP; GSYM
CONJ_ASSOC] THEN CONJ_TAC THENL
[GEN_TAC THEN GEN_REWRITE_TAC (LAND_CONV o RAND_CONV) [
REAL_LE_LT] THEN
ASM_MESON_TAC[
CONTL_LIM;
DIFF_CONT;
REAL_LT_TRANS; REAL_ARITH
`x <= z /\ z < c /\ z < c /\ abs(x - c) < d
==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
CONJ_TAC THENL
[ASM_MESON_TAC[differentiable;
REAL_LT_TRANS; REAL_ARITH
`x < z /\ z < c /\ abs(x - c) < d
==> &0 < abs(z - c) /\ abs(z - c) < d`];
ALL_TAC] THEN
REWRITE_TAC[
NOT_EXISTS_THM] THEN X_GEN_TAC `w:real` THEN STRIP_TAC THEN
FIRST_X_ASSUM(MP_TAC o SPEC `w:real`) THEN
ANTS_TAC THENL [ASM_REAL_ARITH_TAC; ALL_TAC] THEN
ASM_MESON_TAC[
DIFF_UNIQ]]);;