?

Average Error: 43.8 → 0.4
Time: 13.4s
Precision: binary64
Cost: 14016

?

\[\left(\left(1.1102230246251565 \cdot 10^{-16} < a \land a < 9007199254740992\right) \land \left(1.1102230246251565 \cdot 10^{-16} < b \land b < 9007199254740992\right)\right) \land \left(1.1102230246251565 \cdot 10^{-16} < c \land c < 9007199254740992\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\frac{\frac{c \cdot \left(a \cdot -4\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
 (/ (/ (* c (* a -4.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 ((c * (a * -4.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(Float64(c * Float64(a * -4.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]), $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{c \cdot \left(a \cdot -4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}

Error?

Derivation?

  1. Initial program 43.8

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

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

    [Start]43.8

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

    *-commutative [=>]43.8

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

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

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

    [Start]45.0

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

    associate-/r* [<=]45.0

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

    associate-*r/ [=>]45.0

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

    *-commutative [=>]45.0

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

    *-commutative [=>]45.0

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

    fma-def [<=]44.9

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

    +-commutative [=>]44.9

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

    fma-def [=>]44.9

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

    fma-def [<=]45.0

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

    +-commutative [=>]45.0

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

    fma-def [=>]45.0

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

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

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

    [Start]43.5

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

    sub-neg [<=]43.5

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

    div-sub [<=]43.3

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

    fma-udef [=>]43.2

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

    associate--r+ [=>]0.4

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

    +-inverses [=>]0.4

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

    neg-sub0 [<=]0.4

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

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

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

    metadata-eval [=>]0.4

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

    associate-*r* [<=]0.4

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

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

Alternatives

Alternative 1
Error5.9
Cost1024
\[\frac{-c}{b} - a \cdot \left(\frac{c}{b \cdot b} \cdot \frac{c}{b}\right) \]
Alternative 2
Error12.0
Cost256
\[\frac{-c}{b} \]
Alternative 3
Error63.0
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023045 
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :precision binary64
  :pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))