Average Error: 33.2 → 10.0
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 -8.228832331933044 \cdot 10^{-84}:\\ \;\;\;\;\frac{\frac{\frac{1}{\frac{1}{c}}}{\frac{2}{4}}}{\frac{2 \cdot c}{\frac{b}{a}} - \left(b + b\right)}\\ \mathbf{if}\;b \le 6.19795767294399 \cdot 10^{+153}:\\ \;\;\;\;\frac{(\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}\\ \mathbf{else}:\\ \;\;\;\;\frac{(a \cdot \left(\frac{c}{b}\right) + \left(-b\right))_*}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.2
Target20.7
Herbie10.0
\[\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 < -8.228832331933044e-84

    1. Initial program 52.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 clear-num52.0

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Using strategy rm
    5. Applied flip--52.1

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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)}}}}}\]
    6. Applied associate-/r/52.1

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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)}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    7. Applied simplify24.3

      \[\leadsto \frac{1}{\color{blue}{\frac{a \cdot 2}{\left(a \cdot c\right) \cdot 4}} \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    8. Taylor expanded around -inf 16.3

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

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

    if -8.228832331933044e-84 < b < 6.19795767294399e+153

    1. Initial program 12.1

      \[\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-cbrt12.4

      \[\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-neg12.4

      \[\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 6.19795767294399e+153 < b

    1. Initial program 60.8

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

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}}\]
    4. Taylor expanded around inf 10.7

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}}\]
    5. Applied simplify2.2

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

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1071501266 3581234924 1086666455 2685055582 1243441566 1802958749)' +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)))