?

Average Error: 52.4 → 0.4
Time: 13.3s
Precision: binary64
Cost: 14016

?

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

Error?

Derivation?

  1. Initial program 52.4

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

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

    [Start]52.4

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

    *-commutative [=>]52.4

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

    \[\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} \]
  4. Taylor expanded in b around 0 0.4

    \[\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. Simplified0.4

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

    [Start]0.4

    \[ \frac{\frac{-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} \]

    *-commutative [=>]0.4

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

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

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

    [Start]0.5

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

    pow-sqr [=>]0.4

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

    metadata-eval [=>]0.4

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

    unpow1/2 [=>]0.4

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

    fma-def [<=]0.4

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

    +-commutative [=>]0.4

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

    fma-def [=>]0.4

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

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

Alternatives

Alternative 1
Error0.4
Cost14016
\[\frac{\frac{\left(c \cdot a\right) \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2} \]
Alternative 2
Error2.1
Cost8448
\[\frac{\frac{\left(c \cdot a\right) \cdot -4}{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} \]
Alternative 3
Error3.0
Cost1024
\[\frac{-c}{b} - \frac{\frac{a \cdot \left(c \cdot c\right)}{b \cdot b}}{b} \]
Alternative 4
Error6.2
Cost256
\[\frac{-c}{b} \]
Alternative 5
Error62.9
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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