?

Average Accuracy: 56.0% → 99.3%
Time: 24.1s
Precision: binary64
Cost: 20416

?

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

Error?

Derivation?

  1. Initial program 56.0%

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

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

    [Start]56.0

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

    *-commutative [=>]56.0

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

    +-commutative [=>]56.0

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

    unsub-neg [=>]56.0

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

    fma-neg [=>]56.1

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

    associate-*l* [=>]56.1

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

    *-commutative [=>]56.1

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

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

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

    metadata-eval [=>]56.1

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

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

    [Start]56.1

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

    fma-udef [=>]56.0

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

    flip-+ [=>]55.8

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

    pow2 [=>]55.8

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

    associate-*l* [=>]55.8

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

    associate-*l* [=>]55.8

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

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

    [Start]55.8

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

    unpow2 [=>]55.8

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

    associate-*r* [=>]55.8

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

    associate-*r* [=>]55.8

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

    swap-sqr [=>]55.8

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

    metadata-eval [=>]55.8

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

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

    [Start]55.8

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

    flip-- [=>]55.8

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

    div-inv [=>]55.8

    \[ \frac{\color{blue}{\left(\sqrt{\frac{\left(b \cdot b\right) \cdot \left(b \cdot b\right) - \left(\left(a \cdot c\right) \cdot \left(a \cdot c\right)\right) \cdot 16}{b \cdot b - a \cdot \left(c \cdot -4\right)}} \cdot \sqrt{\frac{\left(b \cdot b\right) \cdot \left(b \cdot b\right) - \left(\left(a \cdot c\right) \cdot \left(a \cdot c\right)\right) \cdot 16}{b \cdot b - a \cdot \left(c \cdot -4\right)}} - b \cdot b\right) \cdot \frac{1}{\sqrt{\frac{\left(b \cdot b\right) \cdot \left(b \cdot b\right) - \left(\left(a \cdot c\right) \cdot \left(a \cdot c\right)\right) \cdot 16}{b \cdot b - a \cdot \left(c \cdot -4\right)}} + b}}}{a \cdot 2} \]
  6. Simplified99.3%

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

    [Start]57.2

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

    associate-*r/ [=>]57.2

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

    *-rgt-identity [=>]57.2

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

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

Alternatives

Alternative 1
Accuracy85.0%
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2} \leq -1.1:\\ \;\;\;\;\frac{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b} - a \cdot \frac{c}{\frac{{b}^{3}}{c}}\\ \end{array} \]
Alternative 2
Accuracy84.5%
Cost13764
\[\begin{array}{l} \mathbf{if}\;b \leq 90:\\ \;\;\;\;\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} - a \cdot \frac{c}{\left(b \cdot b\right) \cdot \frac{b}{c}}\\ \end{array} \]
Alternative 3
Accuracy84.4%
Cost7492
\[\begin{array}{l} \mathbf{if}\;b \leq 90:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b} - a \cdot \frac{c}{\left(b \cdot b\right) \cdot \frac{b}{c}}\\ \end{array} \]
Alternative 4
Accuracy81.2%
Cost7232
\[\frac{-c}{b} - a \cdot \frac{c}{\frac{{b}^{3}}{c}} \]
Alternative 5
Accuracy81.2%
Cost1024
\[\frac{-c}{b} - a \cdot \frac{c}{\left(b \cdot b\right) \cdot \frac{b}{c}} \]
Alternative 6
Accuracy63.9%
Cost256
\[\frac{-c}{b} \]
Alternative 7
Accuracy1.6%
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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