Average Error: 33.2 → 10.0
Time: 1.5m
Precision: 64
Internal Precision: 3392
\[\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 -9.064261811055599 \cdot 10^{+144}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.6793350272357014 \cdot 10^{-79}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.4
Herbie10.0
\[\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 3 regimes
  2. if b < -9.064261811055599e+144

    1. Initial program 57.6

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b + b}{2 \cdot a}}\]

    if -9.064261811055599e+144 < b < 1.6793350272357014e-79

    1. Initial program 11.6

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

    if 1.6793350272357014e-79 < b

    1. Initial program 52.1

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

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

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify10.0

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -9.064261811055599 \cdot 10^{+144}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \mathbf{if}\;b \le 1.6793350272357014 \cdot 10^{-79}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 1.5m)Debug logProfile

herbie shell --seed '#(1071821486 549052472 3784827256 1559736200 3548510075 881134285)' 
(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)))