Average Error: 33.4 → 8.2
Time: 2.3m
Precision: 64
Internal Precision: 3200
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -5.621268925987888 \cdot 10^{+88}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 8.295686654973578 \cdot 10^{-275}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.2305310758297228 \cdot 10^{+74}:\\ \;\;\;\;\frac{\frac{c}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{4 \cdot a}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.4
Target20.0
Herbie8.2
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if b < -5.621268925987888e+88

    1. Initial program 41.4

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Applied simplify4.6

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

    if -5.621268925987888e+88 < b < 8.295686654973578e-275

    1. Initial program 9.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]

    if 8.295686654973578e-275 < b < 1.2305310758297228e+74

    1. Initial program 32.2

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

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

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

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

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

    if 1.2305310758297228e+74 < b

    1. Initial program 57.4

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

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

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.2

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -5.621268925987888 \cdot 10^{+88}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{if}\;b \le 8.295686654973578 \cdot 10^{-275}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}{2 \cdot a}\\ \mathbf{if}\;b \le 1.2305310758297228 \cdot 10^{+74}:\\ \;\;\;\;\frac{\frac{c}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}} \cdot \sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}} \cdot \frac{4 \cdot a}{\sqrt[3]{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

herbie shell --seed '#(1070833653 108281690 3330367898 3632331308 3494323072 43156186)' 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))