Average Error: 33.5 → 9.5
Time: 4.7m
Precision: 64
Internal Precision: 3456
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -2.0385768799294215 \cdot 10^{-30}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le -1.446199048995873 \cdot 10^{-72}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}\\ \mathbf{if}\;b \le -5.050014877910474 \cdot 10^{-110}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le 3.2436990905620275 \cdot 10^{+112}:\\ \;\;\;\;\frac{-b}{a + a} - \frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a + a} - \left(\frac{b}{a + a} - \frac{c}{b}\right)\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.8
Herbie9.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -2.0385768799294215e-30 or -1.446199048995873e-72 < b < -5.050014877910474e-110

    1. Initial program 52.4

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify9.9

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

    if -2.0385768799294215e-30 < b < -1.446199048995873e-72

    1. Initial program 35.0

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

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

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

    if -5.050014877910474e-110 < b < 3.2436990905620275e+112

    1. Initial program 11.5

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

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

    if 3.2436990905620275e+112 < b

    1. Initial program 48.5

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

      \[\leadsto \color{blue}{\frac{-b}{2 \cdot a} - \frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\]
    4. Taylor expanded around inf 10.0

      \[\leadsto \frac{-b}{2 \cdot a} - \frac{\color{blue}{b - 2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
    5. Applied simplify3.2

      \[\leadsto \color{blue}{\frac{-b}{a + a} - \left(\frac{b}{a + a} - \frac{\frac{c}{b}}{1}\right)}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions.
  5. Applied simplify9.5

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -2.0385768799294215 \cdot 10^{-30}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le -1.446199048995873 \cdot 10^{-72}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}\\ \mathbf{if}\;b \le -5.050014877910474 \cdot 10^{-110}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le 3.2436990905620275 \cdot 10^{+112}:\\ \;\;\;\;\frac{-b}{a + a} - \frac{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}}{a + a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a + a} - \left(\frac{b}{a + a} - \frac{c}{b}\right)\\ \end{array}}\]

Runtime

Time bar (total: 4.7m)Debug log

herbie shell --seed '#(3622638036 3041702260 3649696288 21285302 1742518495 296600799)' 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))