Average Error: 33.7 → 6.6
Time: 2.3m
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 -4.207600430425723 \cdot 10^{+141}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 2.755441077459983 \cdot 10^{-239}:\\ \;\;\;\;\left(\frac{c}{2} \cdot 4\right) \cdot \frac{1}{\sqrt{(\left(c \cdot a\right) \cdot \left(-4\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{if}\;b \le 5.55792967233871 \cdot 10^{+119}:\\ \;\;\;\;\frac{-(\left(\left|\sqrt[3]{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}\right|\right) \cdot \left(\sqrt{\sqrt[3]{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\right) + b)_*}{2 \cdot a}\\ \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.7
Target20.9
Herbie6.6
\[\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 < -4.207600430425723e+141

    1. Initial program 62.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.5

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

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

    if -4.207600430425723e+141 < b < 2.755441077459983e-239

    1. Initial program 31.2

      \[\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--31.3

      \[\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 simplify15.7

      \[\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 simplify15.7

      \[\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-identity15.7

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

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

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

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

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

    if 2.755441077459983e-239 < b < 5.55792967233871e+119

    1. Initial program 8.5

      \[\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-cbrt8.9

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

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

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

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

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

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

    if 5.55792967233871e+119 < b

    1. Initial program 50.0

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify3.4

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -4.207600430425723 \cdot 10^{+141}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{if}\;b \le 2.755441077459983 \cdot 10^{-239}:\\ \;\;\;\;\left(\frac{c}{2} \cdot 4\right) \cdot \frac{1}{\sqrt{(\left(c \cdot a\right) \cdot \left(-4\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{if}\;b \le 5.55792967233871 \cdot 10^{+119}:\\ \;\;\;\;\frac{-(\left(\left|\sqrt[3]{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}\right|\right) \cdot \left(\sqrt{\sqrt[3]{(\left(-4\right) \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*}}\right) + b)_*}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1072107073 2127697367 3936270018 2300570620 2134894798 4023771849)' +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)))