Average Error: 33.6 → 13.5
Time: 21.9s
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 1.5809418989318178 \cdot 10^{-275}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.5872793306843375 \cdot 10^{+41}:\\ \;\;\;\;-2 \cdot \frac{c}{b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;-2 \cdot \frac{c}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.7
Herbie13.5
\[\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 < 1.5809418989318178e-275

    1. Initial program 21.4

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

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

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

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

    if 1.5809418989318178e-275 < b < 3.5872793306843375e+41

    1. Initial program 29.6

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Initial simplification29.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 flip--29.7

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

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot -4\right) \cdot c}}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac9.4

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

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

    if 3.5872793306843375e+41 < b

    1. Initial program 56.5

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

      \[\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 flip--56.6

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

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot -4\right) \cdot c}}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\]
    7. Using strategy rm
    8. Applied times-frac24.5

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

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

      \[\leadsto -2 \cdot \frac{c}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.5

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

Runtime

Time bar (total: 21.9s)Debug logProfile

herbie shell --seed 2018250 +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)))