Average Error: 33.7 → 9.4
Time: 59.5s
Precision: 64
Internal Precision: 2368
\[\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 -1.7555105886550257 \cdot 10^{+22}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.9496534374670056 \cdot 10^{-159}:\\ \;\;\;\;\frac{\frac{c}{\frac{1}{2}}}{a} \cdot \frac{a}{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 7.393033154911188 \cdot 10^{+137}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}\\ \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
Target21.1
Herbie9.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 < -1.7555105886550257e+22

    1. Initial program 55.4

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    3. Simplified4.5

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

    if -1.7555105886550257e+22 < b < -3.9496534374670056e-159

    1. Initial program 31.9

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

      \[\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 associate-/l/36.5

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}}\]
    5. Simplified21.3

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

      \[\leadsto \frac{\left(c \cdot 4\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}\right)}\]
    7. Simplified21.3

      \[\leadsto \frac{\left(c \cdot 4\right) \cdot a}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}\right)}\]
    8. Using strategy rm
    9. Applied times-frac20.0

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

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

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

    if -3.9496534374670056e-159 < b < 7.393033154911188e+137

    1. Initial program 11.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity11.3

      \[\leadsto \frac{\left(-b\right) - \color{blue}{1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Applied *-un-lft-identity11.3

      \[\leadsto \frac{\color{blue}{1 \cdot \left(-b\right)} - 1 \cdot \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    5. Applied distribute-lft-out--11.3

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

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

    if 7.393033154911188e+137 < b

    1. Initial program 55.9

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.7555105886550257 \cdot 10^{+22}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -3.9496534374670056 \cdot 10^{-159}:\\ \;\;\;\;\frac{\frac{c}{\frac{1}{2}}}{a} \cdot \frac{a}{\sqrt{(-4 \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}\\ \mathbf{elif}\;b \le 7.393033154911188 \cdot 10^{+137}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 59.5s)Debug logProfile

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