Average Error: 33.1 → 7.1
Time: 1.3m
Precision: 64
Internal Precision: 3392
\[\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 -6.76223481168814 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -2.1097631082543147 \cdot 10^{-305}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}{a}\\ \mathbf{elif}\;b \le 1.645760677557775 \cdot 10^{+50}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{(\left(\frac{a}{b}\right) \cdot c + \left(-b\right))_* \cdot 2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.1
Target20.3
Herbie7.1
\[\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 < -6.76223481168814e+153

    1. Initial program 60.7

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified2.8

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

    if -6.76223481168814e+153 < b < -2.1097631082543147e-305

    1. Initial program 8.8

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

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

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

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

    if -2.1097631082543147e-305 < b < 1.645760677557775e+50

    1. Initial program 29.5

      \[\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-+29.6

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

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

      \[\leadsto \frac{\color{blue}{4 \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*16.9

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

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

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

    if 1.645760677557775e+50 < b

    1. Initial program 55.7

      \[\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-+55.7

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

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

      \[\leadsto \frac{\color{blue}{4 \cdot \left(c \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}\]
    6. Using strategy rm
    7. Applied associate-/r*26.4

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

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

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

      \[\leadsto \frac{\frac{4}{2} \cdot c}{\color{blue}{2 \cdot \frac{a \cdot c}{b} - 2 \cdot b}}\]
    12. Simplified4.4

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -6.76223481168814 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -2.1097631082543147 \cdot 10^{-305}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{\sqrt{(\left(-4\right) \cdot \left(a \cdot c\right) + \left(b \cdot b\right))_*} - b}{a}\\ \mathbf{elif}\;b \le 1.645760677557775 \cdot 10^{+50}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{(\left(\frac{a}{b}\right) \cdot c + \left(-b\right))_* \cdot 2}\\ \end{array}\]

Runtime

Time bar (total: 1.3m)Debug logProfile

herbie shell --seed 2018219 +o rules:numerics
(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)))