Average Error: 33.9 → 10.4
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 -3.036685890383162 \cdot 10^{+86} \lor b \le -8.277092716474864 \cdot 10^{-140}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.5335288230570397 \cdot 10^{+150}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right))_*}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{c}{b}\right) \cdot \left(a \cdot 2\right) + \left(-b\right))_* - b}{a \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.9
Target20.8
Herbie10.4
\[\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 < -3.036685890383162e+86

    1. Initial program 58.5

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

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

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

    if -3.036685890383162e+86 < b < -8.277092716474864e-140

    1. Initial program 40.5

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

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

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

    if -8.277092716474864e-140 < b < 2.5335288230570397e+150

    1. Initial program 10.7

      \[\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-cbrt11.0

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

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

    if 2.5335288230570397e+150 < b

    1. Initial program 59.6

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

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

      \[\leadsto \color{blue}{\frac{(\left(\frac{c}{b}\right) \cdot \left(2 \cdot a\right) + \left(-b\right))_* - b}{2 \cdot a}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify10.4

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -3.036685890383162 \cdot 10^{+86} \lor b \le -8.277092716474864 \cdot 10^{-140}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.5335288230570397 \cdot 10^{+150}:\\ \;\;\;\;\frac{(\left(\sqrt[3]{-b} \cdot \sqrt[3]{-b}\right) \cdot \left(\sqrt[3]{-b}\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}\right))_*}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{(\left(\frac{c}{b}\right) \cdot \left(a \cdot 2\right) + \left(-b\right))_* - b}{a \cdot 2}\\ \end{array}}\]

Runtime

Time bar (total: 2.6m)Debug logProfile

herbie shell --seed '#(1072330854 3074818769 591214268 3603999196 3863745332 3332387116)' +o rules:numerics
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :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)))