Average Error: 33.7 → 6.5
Time: 2.6m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;-b \le -2.1552327750082125 \cdot 10^{+125}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le -1.4366882589701953 \cdot 10^{-306}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{if}\;-b \le 2.7000409482843524 \cdot 10^{+122}:\\ \;\;\;\;\frac{c \cdot 4}{\sqrt{(\left(-a\right) \cdot \left(c \cdot 4\right) + \left(b \cdot b\right))_*} - b} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.8
Herbie6.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if (- b) < -2.1552327750082125e+125

    1. Initial program 51.1

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

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

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

    if -2.1552327750082125e+125 < (- b) < -1.4366882589701953e-306

    1. Initial program 9.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied add-cube-cbrt9.8

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\right) \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}{2 \cdot a}\]
    4. Applied add-cube-cbrt10.0

      \[\leadsto \frac{\color{blue}{\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \sqrt[3]{-b}} - \left(\sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}} \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}\right) \cdot \sqrt[3]{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    5. Applied prod-diff10.1

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

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

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

    if -1.4366882589701953e-306 < (- b) < 2.7000409482843524e+122

    1. Initial program 33.6

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

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

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

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

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

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

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

    if 2.7000409482843524e+122 < (- b)

    1. Initial program 60.0

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

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

      \[\leadsto \color{blue}{\frac{-c}{\frac{b}{1}}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify6.5

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.1552327750082125 \cdot 10^{+125}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;-b \le -1.4366882589701953 \cdot 10^{-306}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{(\left(4 \cdot a\right) \cdot \left(-c\right) + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{if}\;-b \le 2.7000409482843524 \cdot 10^{+122}:\\ \;\;\;\;\frac{c \cdot 4}{\sqrt{(\left(-a\right) \cdot \left(c \cdot 4\right) + \left(b \cdot b\right))_*} - b} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed '#(1071215679 2002590028 935158157 1944352234 2656991306 2955288481)' +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))