The Dottie Number
Machine Logic
At the junction of computation, logic and mathematics
The Dottie Number
26 Jun 2026
examples
Isar
AI
locales
Archive of Formal Proofs
Once upon a time, goes the story,<br>a lady named Dottie got bored and started playing with her calculator,<br>pressing the cosine key over and over again.<br>At first the numbers fluctuated wildly,<br>but over time they always settled down to approximately 0.739085.<br>(This only works if your calculator is set to radians, not degrees.)<br>She had discovered the unique fixed point of the cosine function.<br>The Dottie number has several further properties: it is a global attractor,<br>meaning the limit is the same no matter what number you start with,<br>and it is transcendental.<br>It is a great example for showing off a range of computer algebra techniques in Isabelle,<br>such as differentiation and unlimited precision real computations.<br>Let’s prove those properties just mentioned<br>and calculate (by proof!) its value to 12 decimal places.
Getting started
We begin by defining dottie to be the unique fixed point of cos.<br>But this definition, using the definite descriptor THE, will be good for nothing<br>until both existence and uniqueness of a fixed point have been proved.
definition dottie :: real where<br>"dottie ≡ THE x. cos x = x"
Those claims will be proved with the help of the function $g(x)=\cos x - x$.<br>Note that it slopes downwards.
We can see that it has a unique root near $\frac{\pi}{4}$, but now we have to prove it.<br>Several different theorems need facts about $g$,<br>so to avoid duplication we create a locale where we can work with $g$.
locale Dottie =<br>fixes g :: "real ⇒ real"<br>defines "g ≡ λx::real. cos x - x"
begin
Thanks to the begin, we are now working inside the locale.<br>We have access to the function $g$ and can accumulate facts about it.<br>Our first task is to investigate its derivative.
lemma g_has_negative_deriv:<br>assumes "¦t¦ ≤ 1"<br>shows "∃d. (g has_real_derivative d) (at t) ∧ d 0"<br>proof (intro exI conjI)<br>show "(g has_real_derivative (- sin t - 1)) (at t)"<br>unfolding g_def by (auto intro!: derivative_eq_intros)<br>show "- sin t - 1 0"<br>using assms pi_gt3 le_arcsin_iff [of _ t] by fastforce<br>qed
Isabelle is capable of calculating derivatives automatically.<br>The trick, as we see above, is to hit the goal repeatedly with derivative_eq_intros,<br>which is a collection of facts about derivatives of various operators.<br>The effect is practically the same as the schoolbook method.<br>If you know the derivative already, as here, it makes things easier to mention it.<br>Here we prove that the derivative of $g(t)$, which is $-\sin t-1$,<br>is strictly negative over the given interval $[-1,1]$.
Although computer algebra systems are not always sound,<br>we can use them to write correct Isabelle proofs.<br>Via the fundamental theorem of calculus, we can handle tough integrals.<br>We give the hard work to the computer algebra system;<br>Isabelle merely has to take the derivative of the claimed integral<br>and compare that with the original integrand.
Existence
Existence is proved using the intermediate value theorem,<br>which states that<br>a function $g$ that is continuous on a given closed interval $[a,b]$<br>attains all the points between $g(a)$ and $g(b)$.<br>Our $g$ is continuous. Since $g(0) = 1$ and $g(1) = \cos 1 - 1<br>lemma dottie_exists: "∃x::real. 0 x ∧ x 1 ∧ cos x = x"<br>proof -<br>have g_cont: "continuous_on {0..1} g"<br>unfolding g_def by (intro continuous_intros)<br>obtain "g 0 = 1" "g 1 0" using cos_1_lt_1 by (simp add: g_def)<br>with IVT2'[of g 1 0 0] g_cont<br>obtain x where hx: "0 ≤ x" "x ≤ 1" "g x = 0"<br>by (metis less_eq_real_def zero_le_one)<br>hence cos_eq: "cos x = x" by (simp add: g_def)<br>with hx show ?thesis<br>by (metis cos_1_lt_1 cos_zero order_less_le)<br>qed
In the proof above, we see a trick for proving continuity.<br>It resembles the trick for taking derivatives,<br>only we hit the goal with a different list of theorems, namely continuous_intros.<br>Then we show the $g$ crosses 0 to prove the existence of a fixed point<br>satisfying $0We proved above that the derivative of $g(x) = \cos x - x$<br>is strictly negative for $x \in [-1,1]$, i.e. $g$ is strictly decreasing,<br>so $g$ can have at most one zero on that interval.<br>And since $[-1,1]$, is the range of the cosine function,<br>uniqueness over the entire real line immediately follows.
lemma dottie_unique:<br>fixes x y :: real<br>assumes "cos x = x" "cos y = y"<br>shows "x = y"<br>proof (rule ccontr)<br>assume "x ≠ y"<br>have gx: "g x = 0" and gy: "g y = 0" using assms by (auto simp: g_def)<br>show False<br>proof (cases "¦x¦ > 1 ∨ ¦y¦ > 1")<br>case True<br>then show ?thesis<br>by (metis assms abs_cos_le_one not_less)<br>next<br>case False<br>then have "¦x¦ ≤ 1 ∧ ¦y¦ ≤ 1"<br>by simp<br>moreover have "x y ∨ y x" using ‹x ≠ y› by linarith<br>ultimately show ?thesis<br>using DERIV_neg_imp_decreasing [OF _ g_has_negative_deriv] gx gy<br>by force<br>qed<br>qed
More precisely, given the two claimed fixed points, $x$ and $y$, we first trivially establish that both must lie within the interval $[-1,1]$.<br>Then, assuming for contradiction that...