Average Error: 33.5 → 7.3
Time: 2.4m
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.800251176774122 \cdot 10^{+150}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -2.0635978357930732 \cdot 10^{-191}:\\ \;\;\;\;\sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}\right)}}} \cdot \left(\sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}} \cdot \sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}}\right)\\ \mathbf{if}\;-b \le 2.9419353265912683 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target21.4
Herbie7.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 4 regimes
  2. if (- b) < -3.800251176774122e+150

    1. Initial program 62.7

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

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

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

    if -3.800251176774122e+150 < (- b) < -2.0635978357930732e-191

    1. Initial program 37.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied flip-+37.6

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

      \[\leadsto \frac{\frac{\color{blue}{c \cdot \left(a \cdot 4\right)}}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied add-cube-cbrt15.9

      \[\leadsto \color{blue}{\left(\sqrt[3]{\frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}} \cdot \sqrt[3]{\frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}}\right) \cdot \sqrt[3]{\frac{\frac{c \cdot \left(a \cdot 4\right)}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}}}\]
    7. Applied simplify15.8

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

      \[\leadsto \left(\sqrt[3]{\frac{\left(c \cdot 4\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}}} \cdot \sqrt[3]{\frac{\left(c \cdot 4\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*}}}\right) \cdot \color{blue}{\sqrt[3]{\frac{\frac{1}{2} \cdot \left(c \cdot 4\right)}{\left(-b\right) - \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}}}\]
    9. Using strategy rm
    10. Applied add-exp-log8.6

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

    if -2.0635978357930732e-191 < (- b) < 2.9419353265912683e+86

    1. Initial program 10.7

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

    if 2.9419353265912683e+86 < (- b)

    1. Initial program 42.8

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Applied simplify4.4

      \[\leadsto \color{blue}{\frac{-b}{a}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify7.3

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -3.800251176774122 \cdot 10^{+150}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -2.0635978357930732 \cdot 10^{-191}:\\ \;\;\;\;\sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - e^{\log \left(\sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}\right)}}} \cdot \left(\sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}} \cdot \sqrt[3]{\frac{\left(4 \cdot c\right) \cdot \frac{1}{2}}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}}\right)\\ \mathbf{if}\;-b \le 2.9419353265912683 \cdot 10^{+86}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.4m)Debug logProfile

herbie shell --seed '#(1072330854 3074818769 591214268 3603999196 3863745332 3332387116)' +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)))