?

Average Accuracy: 55.8% → 99.3%
Time: 16.9s
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)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}}{a \cdot 2} \]
(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)) (+ 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) {
	return ((-4.0 * (c * a)) / (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)
	return Float64(Float64(Float64(-4.0 * Float64(c * a)) / 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_] := N[(N[(N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(c * N[(-4.0 * a), $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}
\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(-4 \cdot a\right)\right)}}}{a \cdot 2}

Error?

Derivation?

  1. Initial program 55.8%

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

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

    [Start]55.8

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

    *-commutative [=>]55.8

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

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

    [Start]55.8

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

    +-commutative [=>]55.8

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

    flip-+ [=>]55.8

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

    add-sqr-sqrt [<=]57.3

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

    sqr-neg [=>]57.3

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

    associate--l- [=>]57.3

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

    +-commutative [<=]57.3

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

    fma-def [=>]57.0

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

    associate-*l* [=>]57.0

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

    add-sqr-sqrt [=>]0.0

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

    sqrt-unprod [=>]1.3

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

    sqr-neg [=>]1.3

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

    sqrt-prod [=>]1.6

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

    add-sqr-sqrt [<=]1.3

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

    unsub-neg [<=]1.3

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

    +-commutative [<=]1.3

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

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

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

Alternatives

Alternative 1
Accuracy87.8%
Cost21060
\[\begin{array}{l} t_0 := -4 \cdot \left(c \cdot a\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0015:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, t_0\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{t_0}{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 2
Accuracy87.8%
Cost15876
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0015:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-4 \cdot \left(c \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
Accuracy85.2%
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b + c \cdot \left(-4 \cdot a\right)} - b}{a \cdot 2} \leq -0.0015:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(-4 \cdot c\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{-4 \cdot \left(c \cdot a\right)}{-2 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{a \cdot 2}\\ \end{array} \]
Alternative 4
Accuracy81.8%
Cost1344
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{b + \left(b + -2 \cdot \frac{c \cdot a}{b}\right)}}{a \cdot 2} \]
Alternative 5
Accuracy81.9%
Cost1344
\[\frac{\frac{-4 \cdot \left(c \cdot a\right)}{-2 \cdot \frac{c \cdot a}{b} + b \cdot 2}}{a \cdot 2} \]
Alternative 6
Accuracy64.1%
Cost256
\[\frac{-c}{b} \]

Error

Reproduce?

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