These are the human proofs of Quadratic formula, at full length.
The stable quadratic formula returns the roots, each with relative error at most 7u/2 + O(u^2) full
This proof shows: correctness, error-bound.
Write h=b/2, D=h2−ac and p(x)=ax2+bx+c with a=0. In floating point, fl(x∘y)=(x∘y)(1+δ) and fl(x)=x(1+δ) with ∣δ∣≤u when no underflow or overflow occurs (the standard model; see floating-point arithmetic).
Claim 1 (exact arithmetic). QUADRATIC returns the two roots of p, with multiplicity.
Proof. Line L2 multiplies a,b,c by the same nonzero number, which does not change the roots. Completing the square gives p(x)=a((x+h/a)2−D/a2), so the roots are x=(−h±D)/a, real and distinct if D>0, a double root −h/a if D=0, and the complex pair (−h±i−D)/a if D<0, which lines L5 and L6 return. Let D≥0 and σ=1 if h≥0, σ=−1 otherwise. Line L7 sets q=−(h+σD), so x1=q/a is one of the two roots. The product of the roots is c/a (expand a(x−x1)(x−x2)). If q=0, the other root is (c/a)/(q/a)=c/q, which line L9 returns. If q=0, then h+σD=0; both terms have the sign σ or are zero, so h=0 and D=0, hence ac=0, so c=0 and p(x)=ax2 has the double root 0 of line L8. □
Claim 2 (floating point). Assume binary64 with round to nearest and that, after line L2, no operation underflows or overflows. Let x1,x2 be the exact roots of the stored scaled coefficients. Then the computed D has the sign of D, the computed real roots are xi(1+θi), and the computed real and imaginary parts in the complex case are the exact ones times 1+θ, with every ∣θ∣≤27u+O(u2).
Proof. Line L2 multiplies by a power of two, which is exact. In line L3, h=b/2 is exact, and D^=D(1+δ1) because D is formed exactly and rounded once; in particular D^ and D have the same sign, and D^=0 only if D=0.
Real case.s^=fl(D^)=D(1+δ1)1/2(1+δ2)=D(1+ϵs) with ∣ϵs∣≤23u+O(u2). Say h≥0 (the other case is the same with signs changed). Then q^=−fl(h+s^)=−(h+D+Dϵs)(1+δ3). Since h≥0 and D≥0, ∣Dϵs∣≤∣h+D∣∣ϵs∣, so q^=q(1+ϵq) with ∣ϵq∣≤25u+O(u2). Then fl(q^/a)=(q/a)(1+ϵq)(1+δ4) and fl(c/q^)=(c/q)(1+δ5)/(1+ϵq), and both factors are 1+θ with ∣θ∣≤27u+O(u2). If q^=0 then q=0, and line L8 is exact.
Complex case.fl(−h/a)=(−h/a)(1+δ6), and fl(−D^/a)=(−D/a)(1+δ1)1/2(1+δ7)(1+δ8), whose factor is 1+θ with ∣θ∣≤25u+O(u2). □
Remark (no cancellation is essential). The step ∣Dϵs∣≤∣h+D∣∣ϵs∣ uses that h and σD have the same sign. With the other sign, ∣h−D∣ can be much smaller than D, and the same computation only gives an absolute error of about uD; this is the failure of the textbook formula. ■