Average Error: 19.3 → 11.8
Time: 1.2m
Precision: 64
Internal Precision: 576
\[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
\[\begin{array}{l} \mathbf{if}\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\frac{4 \cdot \left(c \cdot a\right)}{\sqrt{(\left(c \cdot a\right) \cdot \left(-4\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array} \le -4.3047340354700463 \cdot 10^{+306}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{b}{a}\\ \end{array}\\ \mathbf{if}\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\frac{4 \cdot \left(c \cdot a\right)}{\sqrt{(\left(c \cdot a\right) \cdot \left(-4\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array} \le 1.7800453673821206 \cdot 10^{+308}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \left(\sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}} \cdot \sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\right) \cdot \sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\\ \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Derivation

  1. Split input into 2 regimes
  2. if (if (>= b 0) (/ (* 2 c) (/ (* 4 (* c a)) (- (sqrt (fma (* c a) (- 4) (* b b))) b))) (/ (- (sqrt (fma (- 4) (* c a) (* b b))) b) (* 2 a))) < -4.3047340354700463e+306 or 1.7800453673821206e+308 < (if (>= b 0) (/ (* 2 c) (/ (* 4 (* c a)) (- (sqrt (fma (* c a) (- 4) (* b b))) b))) (/ (- (sqrt (fma (- 4) (* c a) (* b b))) b) (* 2 a)))

    1. Initial program 44.8

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Applied simplify44.7

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}}\]
    3. Taylor expanded around 0 28.3

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]
    4. Taylor expanded around -inf 25.8

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{2} \cdot \frac{b}{a}\\ \end{array}\]

    if -4.3047340354700463e+306 < (if (>= b 0) (/ (* 2 c) (/ (* 4 (* c a)) (- (sqrt (fma (* c a) (- 4) (* b b))) b))) (/ (- (sqrt (fma (- 4) (* c a) (* b b))) b) (* 2 a))) < 1.7800453673821206e+308

    1. Initial program 1.6

      \[\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \end{array}\]
    2. Applied simplify1.5

      \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}}\]
    3. Using strategy rm
    4. Applied add-cube-cbrt2.0

      \[\leadsto \begin{array}{l} \mathbf{if}\;b \ge 0:\\ \;\;\;\;\frac{2 \cdot c}{\left(-b\right) - \color{blue}{\left(\sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}} \cdot \sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\right) \cdot \sqrt[3]{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sqrt{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}{2 \cdot a}\\ \end{array}\]
  3. Recombined 2 regimes into one program.

Runtime

Time bar (total: 1.2m)Debug logProfile

herbie shell --seed 2019053 +o rules:numerics
(FPCore (a b c)
  :name "jeff quadratic root 2"
  (if (>= b 0) (/ (* 2 c) (- (- b) (sqrt (- (* b b) (* (* 4 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a))))