Average Error: 34.0 → 11.6
Time: 4.5m
Precision: 64
Internal Precision: 3456
\[\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 -6.5156527474267875 \cdot 10^{+59}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le -1.079410454829395 \cdot 10^{-273}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a + a}\\ \mathbf{if}\;b \le 2.256490684090334 \cdot 10^{+112}:\\ \;\;\;\;\frac{\frac{c}{a + a} \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{2} \cdot \frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target21.1
Herbie11.6
\[\begin{array}{l} \mathbf{if}\;b \lt 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 < -6.5156527474267875e+59

    1. Initial program 37.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Applied simplify5.8

      \[\leadsto \color{blue}{\frac{-b}{a}}\]

    if -6.5156527474267875e+59 < b < -1.079410454829395e-273

    1. Initial program 9.6

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

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

    if -1.079410454829395e-273 < b < 2.256490684090334e+112

    1. Initial program 31.7

      \[\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-+31.8

      \[\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. Applied simplify16.1

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

    if 2.256490684090334e+112 < b

    1. Initial program 59.8

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

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions.
  5. Applied simplify11.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -6.5156527474267875 \cdot 10^{+59}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;b \le -1.079410454829395 \cdot 10^{-273}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{a + a}\\ \mathbf{if}\;b \le 2.256490684090334 \cdot 10^{+112}:\\ \;\;\;\;\frac{\frac{c}{a + a} \cdot \left(4 \cdot a\right)}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{2} \cdot \frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 4.5m)Debug log

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

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

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