?

Average Error: 43.8 → 0.2
Time: 15.8s
Precision: binary64
Cost: 13760

?

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

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.7

    \[\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]43.8

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

    /-rgt-identity [<=]43.8

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

    metadata-eval [<=]43.8

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

    *-commutative [=>]43.8

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

    associate-/l* [=>]43.8

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

    associate-/l* [<=]43.8

    \[ \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/ [<=]43.8

    \[ \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 [<=]43.8

    \[ \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 [<=]43.8

    \[ \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-rr43.2

    \[\leadsto \color{blue}{\frac{0.5}{\frac{a \cdot \left(b + \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}\right)}{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right) - b \cdot b}}} \]
  4. Applied egg-rr49.3

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

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

    [Start]49.3

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

    log-pow [=>]43.2

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

    associate-/r* [=>]43.2

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

    associate-*l/ [=>]43.2

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

    fma-udef [=>]43.1

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

    +-commutative [<=]43.1

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

    associate-+r- [<=]0.2

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

    *-commutative [<=]0.2

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

    fma-def [=>]0.2

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

    +-inverses [=>]0.2

    \[ \frac{\frac{\mathsf{fma}\left(c \cdot a, -4, \color{blue}{0}\right)}{a} \cdot \log \left(e^{0.5}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)}} \]
  6. Applied egg-rr39.9

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

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

    [Start]39.9

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

    expm1-def [=>]10.6

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

    expm1-log1p [=>]0.2

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

    associate-/l* [=>]0.2

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

    *-commutative [=>]0.2

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

    associate-*r* [<=]0.2

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

    *-commutative [=>]0.2

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

    rem-log-exp [=>]0.2

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

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

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

Alternatives

Alternative 1
Error5.8
Cost15684
\[\begin{array}{l} t_0 := b \cdot b + c \cdot \left(-4 \cdot a\right)\\ t_1 := \sqrt{t_0}\\ \mathbf{if}\;\frac{t_1 - b}{a \cdot 2} \leq -300:\\ \;\;\;\;\frac{\frac{t_0 - b \cdot b}{b + t_1}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\mathsf{fma}\left(c \cdot a, -4, 0\right)}{a}}{\frac{-2 \cdot \frac{c \cdot a}{b} + b \cdot 2}{0.5}}\\ \end{array} \]
Alternative 2
Error4.1
Cost8320
\[\frac{\frac{0.5}{a}}{\frac{c \cdot a + \left(c \cdot a\right) \cdot -0.5}{{b}^{3}} + \left(-0.5 \cdot \frac{b}{c \cdot a} + 0.5 \cdot \frac{1}{b}\right)} \]
Alternative 3
Error5.9
Cost7744
\[\frac{\frac{\mathsf{fma}\left(c \cdot a, -4, 0\right)}{a}}{\frac{-2 \cdot \frac{c \cdot a}{b} + b \cdot 2}{0.5}} \]
Alternative 4
Error5.9
Cost7104
\[\frac{0.5}{\mathsf{fma}\left(0.5, \frac{a}{b}, \frac{-0.5}{\frac{c}{b}}\right)} \]
Alternative 5
Error6.0
Cost832
\[\frac{0.5}{0.5 \cdot \frac{a}{b} + -0.5 \cdot \frac{b}{c}} \]
Alternative 6
Error12.1
Cost256
\[\frac{-c}{b} \]

Error

Reproduce?

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