?

Average Error: 44.0 → 0.2
Time: 19.7s
Precision: binary64
Cost: 20416

?

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

Error?

Derivation?

  1. Initial program 44.0

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

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

    [Start]44.0

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

    /-rgt-identity [<=]44.0

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

    metadata-eval [<=]44.0

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

    *-commutative [=>]44.0

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

    associate-/l* [=>]44.0

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

    associate-/l* [<=]44.0

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

    associate-*r/ [<=]44.0

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

    /-rgt-identity [<=]44.0

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

    metadata-eval [<=]44.0

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

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

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

    [Start]44.6

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

    associate-/r/ [=>]44.6

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

    +-commutative [=>]44.6

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

    fma-def [<=]44.6

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

    +-commutative [<=]44.6

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

    fma-def [=>]44.6

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

    fma-def [<=]44.6

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

    +-commutative [<=]44.6

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

    fma-def [=>]44.6

    \[ \frac{\sqrt{b} + {\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}^{0.25}}{\frac{a}{0.5}} \cdot \left({\color{blue}{\left(\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)\right)}}^{0.25} - \sqrt{b}\right) \]
  5. Applied egg-rr44.0

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

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

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

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

    [Start]52.0

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

    expm1-def [=>]49.7

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

    expm1-log1p [=>]43.5

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

    associate-/r* [=>]43.5

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

    fma-udef [=>]43.5

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

    associate-+r- [<=]0.2

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

    fma-def [=>]0.2

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

    *-commutative [=>]0.2

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

    +-inverses [=>]0.2

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

    *-commutative [=>]0.2

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

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

Alternatives

Alternative 1
Error0.5
Cost14144
\[\frac{1}{\frac{a \cdot 2}{\frac{-4 \cdot \left(a \cdot c\right)}{b + \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}}}} \]
Alternative 2
Error0.4
Cost14016
\[\frac{\left(-4 \cdot \left(a \cdot c\right)\right) \cdot \frac{0.5}{a}}{b + \sqrt{\mathsf{fma}\left(a, -4 \cdot c, b \cdot b\right)}} \]
Alternative 3
Error3.8
Cost7552
\[\frac{1}{\frac{a}{b} + \left(\frac{c}{\frac{{b}^{3}}{a \cdot a}} - \frac{b}{c}\right)} \]
Alternative 4
Error5.7
Cost576
\[\frac{1}{\frac{a}{b} - \frac{b}{c}} \]
Alternative 5
Error11.9
Cost256
\[\frac{-c}{b} \]
Alternative 6
Error63.0
Cost192
\[\frac{c}{b} \]

Error

Reproduce?

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