Average Error: 33.4 → 11.2
Time: 51.7s
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 -1.414097958926068 \cdot 10^{+52}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -3.3495933623292597 \cdot 10^{+24}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)\\ \mathbf{elif}\;b \le -3.0952147242065757 \cdot 10^{-27}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -5.048430376004428 \cdot 10^{-61}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot 4\right)}{\left(\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)\right) \cdot \left(2 \cdot a\right)}\\ \mathbf{elif}\;b \le -1.8507836106114313 \cdot 10^{-103}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 1.069932557471162 \cdot 10^{+80}:\\ \;\;\;\;\frac{1}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \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.4
Target20.7
Herbie11.2
\[\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 5 regimes
  2. if b < -1.414097958926068e+52 or -3.3495933623292597e+24 < b < -3.0952147242065757e-27 or -5.048430376004428e-61 < b < -1.8507836106114313e-103

    1. Initial program 52.3

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{c}{b}}\]
    6. Simplified9.2

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

    if -1.414097958926068e+52 < b < -3.3495933623292597e+24

    1. Initial program 46.3

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification46.3

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num46.3

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

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

    if -3.0952147242065757e-27 < b < -5.048430376004428e-61

    1. Initial program 38.0

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification38.0

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num38.0

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

      \[\leadsto \color{blue}{\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)}\]
    9. Using strategy rm
    10. Applied flip--38.1

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

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

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

    if -1.8507836106114313e-103 < b < 1.069932557471162e+80

    1. Initial program 12.4

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

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied clear-num12.6

      \[\leadsto \color{blue}{\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}}}}\]
    7. Using strategy rm
    8. Applied div-inv12.6

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

    if 1.069932557471162e+80 < b

    1. Initial program 40.7

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification40.7

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.414097958926068 \cdot 10^{+52}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -3.3495933623292597 \cdot 10^{+24}:\\ \;\;\;\;\frac{1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}\right)\\ \mathbf{elif}\;b \le -3.0952147242065757 \cdot 10^{-27}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le -5.048430376004428 \cdot 10^{-61}:\\ \;\;\;\;\frac{a \cdot \left(c \cdot 4\right)}{\left(\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} + \left(-b\right)\right) \cdot \left(2 \cdot a\right)}\\ \mathbf{elif}\;b \le -1.8507836106114313 \cdot 10^{-103}:\\ \;\;\;\;-\frac{c}{b}\\ \mathbf{elif}\;b \le 1.069932557471162 \cdot 10^{+80}:\\ \;\;\;\;\frac{1}{\left(2 \cdot a\right) \cdot \frac{1}{\left(-b\right) - \sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 51.7s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes33.511.25.827.780.6%
herbie shell --seed 2018290 +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)))