Average Error: 34.5 → 6.9
Time: 5.2s
Precision: binary64
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.7868277875676773 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -6.542684670484036 \cdot 10^{-309}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.30179638498777366 \cdot 10^{102}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.5
Target21.5
Herbie6.9
\[\begin{array}{l} \mathbf{if}\;b \lt 0.0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -4.7868277875676773e101

    1. Initial program 47.1

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around -inf 4.1

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    3. Simplified4.1

      \[\leadsto \color{blue}{1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)}\]

    if -4.7868277875676773e101 < b < -6.542684670484036e-309

    1. Initial program 9.7

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

    if -6.542684670484036e-309 < b < 3.30179638498777366e102

    1. Initial program 32.3

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+32.3

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

      \[\leadsto \frac{\frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Simplified16.3

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    6. Using strategy rm
    7. Applied *-un-lft-identity16.3

      \[\leadsto \frac{\frac{4 \cdot \left(a \cdot c\right)}{\color{blue}{1 \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}}{2 \cdot a}\]
    8. Applied times-frac16.3

      \[\leadsto \frac{\color{blue}{\frac{4}{1} \cdot \frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    9. Applied times-frac16.3

      \[\leadsto \color{blue}{\frac{\frac{4}{1}}{2} \cdot \frac{\frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}}\]
    10. Simplified16.3

      \[\leadsto \color{blue}{\frac{4}{2}} \cdot \frac{\frac{a \cdot c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{a}\]
    11. Simplified8.8

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

    if 3.30179638498777366e102 < b

    1. Initial program 59.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Taylor expanded around inf 2.7

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.9

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.7868277875676773 \cdot 10^{101}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le -6.542684670484036 \cdot 10^{-309}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.30179638498777366 \cdot 10^{102}:\\ \;\;\;\;\frac{4}{2} \cdot \frac{c}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

herbie shell --seed 2020182 
(FPCore (a b c)
  :name "The quadratic formula (r1)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (neg b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ c (* a (/ (- (neg b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))))

  (/ (+ (neg b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))