Average Error: 33.3 → 9.7
Time: 4.0m
Precision: 64
\[\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 -3.779652854255884 \cdot 10^{-77}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 8.254268362687441 \cdot 10^{+86}:\\ \;\;\;\;\frac{1}{\frac{a}{\frac{\left(-b\right) - \sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*}}{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.5
Herbie9.7
\[\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 3 regimes
  2. if b < -3.779652854255884e-77

    1. Initial program 52.4

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    4. Simplified8.8

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

    if -3.779652854255884e-77 < b < 8.254268362687441e+86

    1. Initial program 12.7

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

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

      \[\leadsto \frac{\frac{\left(-b\right) - \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{\color{blue}{1 \cdot 2}}}{a}\]
    5. Applied *-un-lft-identity12.7

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

      \[\leadsto \frac{\frac{\left(-\color{blue}{1 \cdot b}\right) - 1 \cdot \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}{1 \cdot 2}}{a}\]
    7. Applied distribute-rgt-neg-in12.7

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

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

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

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

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

    if 8.254268362687441e+86 < b

    1. Initial program 41.0

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} - \frac{b}{a}}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.7

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

Reproduce

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