?

Average Error: 28.6 → 0.6
Time: 18.4s
Precision: binary64
Cost: 59968

?

\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ t_1 := {\left(\mathsf{fma}\left(b, b, t_0\right)\right)}^{0.25}\\ \frac{\frac{\frac{t_0}{\sqrt{\mathsf{fma}\left(t_1, t_1, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}}}{a \cdot 2} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (* -4.0 (* c a))) (t_1 (pow (fma b b t_0) 0.25)))
   (/
    (/
     (/ t_0 (sqrt (fma t_1 t_1 b)))
     (sqrt (+ b (sqrt (fma b b (* c (* -4.0 a)))))))
    (* a 2.0))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = -4.0 * (c * a);
	double t_1 = pow(fma(b, b, t_0), 0.25);
	return ((t_0 / sqrt(fma(t_1, t_1, b))) / sqrt((b + sqrt(fma(b, b, (c * (-4.0 * a))))))) / (a * 2.0);
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(-4.0 * Float64(c * a))
	t_1 = fma(b, b, t_0) ^ 0.25
	return Float64(Float64(Float64(t_0 / sqrt(fma(t_1, t_1, b))) / sqrt(Float64(b + sqrt(fma(b, b, Float64(c * Float64(-4.0 * a))))))) / Float64(a * 2.0))
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Power[N[(b * b + t$95$0), $MachinePrecision], 0.25], $MachinePrecision]}, N[(N[(N[(t$95$0 / N[Sqrt[N[(t$95$1 * t$95$1 + b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(b + N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
t_0 := -4 \cdot \left(c \cdot a\right)\\
t_1 := {\left(\mathsf{fma}\left(b, b, t_0\right)\right)}^{0.25}\\
\frac{\frac{\frac{t_0}{\sqrt{\mathsf{fma}\left(t_1, t_1, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}}}{a \cdot 2}
\end{array}

Error?

Derivation?

  1. Initial program 28.6

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  2. Simplified28.6

    \[\leadsto \color{blue}{\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}} \]
    Proof

    [Start]28.6

    \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]

    *-commutative [=>]28.6

    \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}} \]
  3. Applied egg-rr27.8

    \[\leadsto \frac{\color{blue}{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}}{a \cdot 2} \]
  4. Taylor expanded in b around 0 0.7

    \[\leadsto \frac{\frac{\frac{\color{blue}{-4 \cdot \left(c \cdot a\right)}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]
  5. Applied egg-rr0.6

    \[\leadsto \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\color{blue}{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, b\right)}}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]
  6. Simplified0.6

    \[\leadsto \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\color{blue}{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)\right)}^{0.25}, b\right)}}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]
    Proof

    [Start]0.6

    \[ \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]

    *-commutative [=>]0.6

    \[ \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot -4}\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]

    *-commutative [=>]0.6

    \[ \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot -4}\right)\right)}^{0.25}, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}}{a \cdot 2} \]
  7. Final simplification0.6

    \[\leadsto \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{\sqrt{\mathsf{fma}\left({\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, {\left(\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)\right)}^{0.25}, b\right)}}}{\sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}}}{a \cdot 2} \]

Alternatives

Alternative 1
Error5.3
Cost41924
\[\begin{array}{l} t_0 := \mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.9:\\ \;\;\;\;\frac{\frac{b \cdot b - t_0}{\left(-b\right) - \sqrt{t_0}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.25, {\left(c \cdot a\right)}^{4} \cdot \frac{20}{a \cdot {b}^{7}}, \frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - a \cdot \left(\frac{c}{b} \cdot \frac{c}{b \cdot b}\right)\\ \end{array} \]
Alternative 2
Error0.7
Cost40256
\[\begin{array}{l} t_0 := \sqrt{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}\\ \frac{\frac{\frac{-4 \cdot \left(c \cdot a\right)}{t_0}}{t_0}}{a \cdot 2} \end{array} \]
Alternative 3
Error6.9
Cost28292
\[\begin{array}{l} t_0 := \mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\frac{\frac{b \cdot b - t_0}{\left(-b\right) - \sqrt{t_0}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - a \cdot \frac{c \cdot c}{{b}^{3}}\\ \end{array} \]
Alternative 4
Error7.0
Cost28228
\[\begin{array}{l} t_0 := c \cdot \left(-4 \cdot a\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + t_0} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - a \cdot \frac{c \cdot c}{{b}^{3}}\\ \end{array} \]
Alternative 5
Error7.0
Cost28228
\[\begin{array}{l} t_0 := \mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\frac{\frac{t_0 - b \cdot b}{b + \sqrt{t_0}}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - a \cdot \frac{c \cdot c}{{b}^{3}}\\ \end{array} \]
Alternative 6
Error7.2
Cost28164
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - a \cdot \frac{c \cdot c}{{b}^{3}}\\ \end{array} \]
Alternative 7
Error7.3
Cost22596
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(-2 \cdot \left(\frac{c \cdot c}{b \cdot b} \cdot \frac{a \cdot a}{b}\right) + \left(-4 \cdot \frac{{\left(c \cdot a\right)}^{3}}{{b}^{5}} + -2 \cdot \frac{c \cdot a}{b}\right)\right)\\ \end{array} \]
Alternative 8
Error9.7
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\ \end{array} \]
Alternative 9
Error9.7
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\ \end{array} \]
Alternative 10
Error9.7
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.06:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\ \end{array} \]
Alternative 11
Error11.9
Cost7232
\[\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}} \]
Alternative 12
Error12.1
Cost1600
\[\frac{0.5}{a} \cdot \left(-2 \cdot \left(\frac{c \cdot c}{\frac{b \cdot b}{a} \cdot \frac{b}{a}} + c \cdot \frac{a}{b}\right)\right) \]
Alternative 13
Error12.0
Cost1600
\[\frac{0.5}{a} \cdot \left(-2 \cdot \left(\frac{c \cdot c}{\frac{b \cdot b}{a} \cdot \frac{b}{a}} + a \cdot \frac{c}{b}\right)\right) \]
Alternative 14
Error22.8
Cost256
\[\frac{-c}{b} \]

Error

Reproduce?

herbie shell --seed 2023073 
(FPCore (a b c)
  :name "Quadratic roots, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))