Average Error: 28.4 → 0.3
Time: 19.8s
Precision: binary64
Cost: 13760
\[\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} \]
\[0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -4\right) \cdot a\right)}} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (* 0.5 (/ (* c -4.0) (+ b (sqrt (fma b b (* (* c -4.0) a)))))))
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) {
	return 0.5 * ((c * -4.0) / (b + sqrt(fma(b, b, ((c * -4.0) * a)))));
}
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)
	return Float64(0.5 * Float64(Float64(c * -4.0) / Float64(b + sqrt(fma(b, b, Float64(Float64(c * -4.0) * a))))))
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_] := N[(0.5 * N[(N[(c * -4.0), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(N[(c * -4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -4\right) \cdot a\right)}}

Error

Derivation

  1. Initial program 28.4

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

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

    [Start]28.4

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

    *-commutative [=>]28.4

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

    \[\leadsto \frac{\color{blue}{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}}{a \cdot 2} \]
  4. Applied egg-rr15.0

    \[\leadsto \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\color{blue}{\frac{c \cdot \left(a \cdot -4\right)}{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}}}{a \cdot 2} \]
  5. Simplified15.0

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

    [Start]15.0

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

    associate-/l* [=>]15.0

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

    *-commutative [=>]15.0

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

    associate-*r* [<=]15.0

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

    fma-neg [=>]15.0

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

    *-commutative [=>]15.0

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

    distribute-rgt-neg-in [=>]15.0

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

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

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

    [Start]15.0

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

    associate-*l/ [=>]15.0

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

    *-lft-identity [=>]15.0

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

    associate-*r/ [=>]15.0

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

    associate-*l/ [<=]14.9

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

    associate-/r/ [=>]14.9

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

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

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

    [Start]24.8

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

    expm1-def [=>]10.5

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

    expm1-log1p [=>]0.4

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

    *-commutative [=>]0.4

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

    associate-/r* [=>]0.4

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

    associate-/l* [=>]0.5

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

    associate-/r/ [=>]0.4

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

    metadata-eval [=>]0.4

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

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

Alternatives

Alternative 1
Error0.4
Cost13632
\[\frac{-2}{\frac{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -4\right) \cdot a\right)}}{c}} \]
Alternative 2
Error7.0
Cost8964
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right) + b \cdot b\\ \mathbf{if}\;b \leq 48:\\ \;\;\;\;\frac{t_0 - b \cdot b}{\frac{b + \sqrt{t_0}}{\frac{0.5}{a}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{b \cdot \left(b - b\right) + c \cdot \left(-4 \cdot a\right)}{b + \left(b + -2 \cdot \left(a \cdot \frac{c}{b} + \frac{c}{\frac{{b}^{3}}{c}} \cdot \left(a \cdot a\right)\right)\right)}}{a \cdot 2}\\ \end{array} \]
Alternative 3
Error9.1
Cost8388
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ t_1 := t_0 + b \cdot b\\ \mathbf{if}\;b \leq 51:\\ \;\;\;\;\frac{0.5}{a} \cdot \frac{t_1 - b \cdot b}{b + \sqrt{t_1}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 4
Error9.1
Cost8388
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ t_1 := t_0 + b \cdot b\\ \mathbf{if}\;b \leq 51:\\ \;\;\;\;\frac{\left(t_1 - b \cdot b\right) \cdot \frac{0.5}{a}}{b + \sqrt{t_1}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 5
Error9.1
Cost8388
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ t_1 := t_0 + b \cdot b\\ \mathbf{if}\;b \leq 54:\\ \;\;\;\;\frac{t_1 - b \cdot b}{\frac{b + \sqrt{t_1}}{\frac{0.5}{a}}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 6
Error9.4
Cost7748
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;b \leq 56:\\ \;\;\;\;\frac{0.5}{a} \cdot \frac{1}{\frac{1}{\sqrt{t_0 + b \cdot b} - b}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 7
Error9.4
Cost7748
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;b \leq 51:\\ \;\;\;\;\frac{1}{\left(a \cdot 2\right) \cdot \frac{1}{\sqrt{t_0 + b \cdot b} - b}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 8
Error9.4
Cost7620
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;b \leq 51:\\ \;\;\;\;\frac{\frac{0.5}{a}}{\frac{1}{\sqrt{t_0 + b \cdot b} - b}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 9
Error9.4
Cost7492
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;b \leq 51:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{t_0 + b \cdot b} - b\right)\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 10
Error9.4
Cost7492
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;b \leq 56:\\ \;\;\;\;\frac{0.5}{\frac{a}{\sqrt{t_0 + b \cdot b} - b}}\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot \frac{t_0}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)}\\ \end{array} \]
Alternative 11
Error11.6
Cost1344
\[0.5 \cdot \frac{-4 \cdot \left(c \cdot a\right)}{a \cdot \left(b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)\right)} \]
Alternative 12
Error22.9
Cost256
\[\frac{-c}{b} \]

Error

Reproduce

herbie shell --seed 2023011 
(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)))