Average Error: 33.8 → 9.8
Time: 4.2m
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 -3.450673941298755 \cdot 10^{+137}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \mathbf{if}\;b \le 4.6083221305510133 \cdot 10^{-76}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.8
Target20.8
Herbie9.8
\[\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 < -3.450673941298755e+137

    1. Initial program 55.1

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

      \[\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}}\]
    4. Taylor expanded around -inf 11.9

      \[\leadsto \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - 2 \cdot b\right)} \cdot \frac{1}{2 \cdot a}\]
    5. Applied simplify2.7

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

    if -3.450673941298755e+137 < b < 4.6083221305510133e-76

    1. Initial program 12.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-inv12.8

      \[\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 4.6083221305510133e-76 < b

    1. Initial program 52.8

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.450673941298755 \cdot 10^{+137}:\\ \;\;\;\;\frac{\frac{c}{\frac{b}{a}}}{a} - \frac{b}{a}\\ \mathbf{if}\;b \le 4.6083221305510133 \cdot 10^{-76}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 4.2m)Debug logProfile

herbie shell --seed '#(376638549 3830080768 3905278455 3542335916 3807831211 3252027093)' 
(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)))