Average Error: 33.4 → 16.3
Time: 35.2s
Precision: 64
Internal Precision: 128
\[\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 1.6240650833627339 \cdot 10^{-65}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.2
Herbie16.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 2 regimes
  2. if b < 1.6240650833627339e-65

    1. Initial program 21.0

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

      \[\leadsto \frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-sub21.0

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

    if 1.6240650833627339e-65 < b

    1. Initial program 52.6

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

      \[\leadsto \frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied *-un-lft-identity52.6

      \[\leadsto \frac{\color{blue}{1 \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b\right)}}{2 \cdot a}\]
    5. Applied associate-/l*52.6

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}}}\]
    6. Taylor expanded around 0 9.1

      \[\leadsto \frac{1}{\color{blue}{-1 \cdot \frac{b}{c}}}\]
    7. Simplified9.1

      \[\leadsto \frac{1}{\color{blue}{\frac{-b}{c}}}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification16.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le 1.6240650833627339 \cdot 10^{-65}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}{2 \cdot a} - \frac{b}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{-\frac{b}{c}}\\ \end{array}\]

Runtime

Time bar (total: 35.2s)Debug logProfile

herbie shell --seed 2018348 +o rules:numerics
(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)))