?

Average Error: 17.9% → 99.9%
Time: 23.9s
Precision: binary64
Cost: 13632.00

?

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

Error?

Derivation?

  1. Initial program 17.9

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

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

    [Start]17.9

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

    *-commutative [=>]17.9

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

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

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

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

    [Start]18.3

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

    fma-def [<=]18.4

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

    +-commutative [<=]18.4

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

    *-commutative [=>]18.4

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

    fma-def [=>]18.4

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

    fma-def [<=]18.4

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

    +-commutative [<=]18.4

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

    *-commutative [=>]18.4

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

    fma-def [=>]18.4

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

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

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

    [Start]18.4

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

    *-commutative [<=]18.4

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

    associate-*r/ [=>]18.4

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

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

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

Alternatives

Alternative 1
Error99.5%
Cost7744.00
\[\frac{\frac{-0.5}{a} \cdot \left(a \cdot \left(c \cdot 4\right)\right)}{b + \sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)}} \]
Alternative 2
Error95.5%
Cost1024.00
\[\frac{-c}{b} - a \cdot \frac{\frac{c}{\frac{b}{c}}}{b \cdot b} \]
Alternative 3
Error90.4%
Cost256.00
\[-\frac{c}{b} \]

Error

Reproduce?

herbie shell --seed 2023093 
(FPCore (a b c)
  :name "Quadratic roots, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))