Average Error: 33.6 → 10.3
Time: 2.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.3743925292749844 \cdot 10^{-101}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le 7.11835192838466 \cdot 10^{+59}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} + \left(-b\right)}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.4
Herbie10.3
\[\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.3743925292749844e-101

    1. Initial program 51.3

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

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

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

    if -3.3743925292749844e-101 < (- b) < 7.11835192838466e+59

    1. Initial program 12.7

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

    if 7.11835192838466e+59 < (- b)

    1. Initial program 36.4

      \[\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 simplify5.6

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b + b}{2 \cdot a}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify10.3

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

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed '#(1072361757 3390613284 2339397988 1175251238 145061547 3101881848)' 
(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)))