?

Average Error: 28.3 → 0.3
Time: 21.2s
Precision: binary64
Cost: 14016

?

\[\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} \]
\[\frac{\frac{4 \cdot \left(c \cdot a\right)}{a}}{-2 \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}\right)} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (/ (/ (* 4.0 (* c a)) a) (* -2.0 (+ b (sqrt (fma b b (* -4.0 (* c 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 ((4.0 * (c * a)) / a) / (-2.0 * (b + sqrt(fma(b, b, (-4.0 * (c * 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(Float64(Float64(4.0 * Float64(c * a)) / a) / Float64(-2.0 * Float64(b + sqrt(fma(b, b, Float64(-4.0 * Float64(c * 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[(N[(N[(4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / N[(-2.0 * N[(b + N[Sqrt[N[(b * b + N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\frac{\frac{4 \cdot \left(c \cdot a\right)}{a}}{-2 \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}\right)}

Error?

Derivation?

  1. Initial program 28.3

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

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

    [Start]28.3

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

    +-commutative [=>]28.3

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

    unsub-neg [=>]28.3

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

    fma-neg [=>]28.3

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

    *-commutative [=>]28.3

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

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

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

    distribute-lft-neg-in [=>]28.3

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

    *-commutative [<=]28.3

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

    metadata-eval [=>]28.3

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

    *-commutative [=>]28.3

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

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

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

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

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

    [Start]27.6

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

    associate-*r/ [=>]27.6

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

    associate-*l* [=>]27.6

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

    associate-/r* [=>]27.6

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

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

Alternatives

Alternative 1
Error6.8
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -1.5:\\ \;\;\;\;\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{1}{\left(\frac{a}{b} - \frac{b}{c}\right) + c \cdot \frac{a \cdot a}{{b}^{3}}}\\ \end{array} \]
Alternative 2
Error6.8
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -1.5:\\ \;\;\;\;\frac{0.5}{\frac{a}{\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{a}{b} - \frac{b}{c}\right) + c \cdot \frac{a \cdot a}{{b}^{3}}}\\ \end{array} \]
Alternative 3
Error6.8
Cost21060
\[\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 -1.5:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{a}{b} - \frac{b}{c}\right) + c \cdot \frac{a \cdot a}{{b}^{3}}}\\ \end{array} \]
Alternative 4
Error6.8
Cost14980
\[\begin{array}{l} t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{if}\;t_0 \leq -1.5:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(\frac{a}{b} - \frac{b}{c}\right) + c \cdot \frac{a \cdot a}{{b}^{3}}}\\ \end{array} \]
Alternative 5
Error9.5
Cost14788
\[\begin{array}{l} t_0 := \frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2}\\ \mathbf{if}\;t_0 \leq -0.01:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\ \end{array} \]
Alternative 6
Error0.4
Cost14016
\[\begin{array}{l} t_0 := c \cdot \left(-4 \cdot a\right)\\ \frac{t_0}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}\right)} \end{array} \]
Alternative 7
Error9.4
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 16.5:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + -4 \cdot \left(c \cdot a\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{a}{b} - \frac{b}{c}}\\ \end{array} \]
Alternative 8
Error11.6
Cost576
\[\frac{1}{\frac{a}{b} - \frac{b}{c}} \]
Alternative 9
Error22.9
Cost256
\[\frac{-c}{b} \]
Alternative 10
Error63.0
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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