Average Error: 34.6 → 6.7
Time: 27.6s
Precision: 64
Internal precision: 2944
\[\frac{\left(-b\right) + \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;b \le -4.072401843866691 \cdot 10^{+122}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;b \le 1.5649298756640125 \cdot 10^{-189}:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{if}\;b \le 9.141549925217606 \cdot 10^{+73}:\\ \;\;\;\;\frac{\frac{a}{1} \cdot \frac{c \cdot 4}{\left(-b\right) - \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot \frac{-2}{2}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.6
Comparison21.6
Herbie6.7
\[ \begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array} \]

Derivation

  1. Split input into 4 regimes.
  2. if b < -4.072401843866691e+122

    1. Initial program 51.3

      \[\frac{\left(-b\right) + \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Applied taylor 12.7

      \[\leadsto \frac{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}{2 \cdot a}\]
    3. Taylor expanded around -inf 12.7

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
    4. Applied simplify 0.0

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
    5. Applied simplify 0.0

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

    if -4.072401843866691e+122 < b < 1.5649298756640125e-189

    1. Initial program 10.3

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

    if 1.5649298756640125e-189 < b < 9.141549925217606e+73

    1. Initial program 35.9

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

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

      \[\leadsto \frac{\frac{\color{blue}{a \cdot \left(c \cdot 4\right)}}{\left(-b\right) - \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}}{2 \cdot a}\]
    5. Using strategy rm
    6. Applied *-un-lft-identity 16.7

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

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

    if 9.141549925217606e+73 < b

    1. Initial program 58.3

      \[\frac{\left(-b\right) + \sqrt{{b}^2 - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Applied taylor 14.4

      \[\leadsto \frac{-2 \cdot \frac{c \cdot a}{b}}{2 \cdot a}\]
    3. Taylor expanded around inf 14.4

      \[\leadsto \frac{\color{blue}{-2 \cdot \frac{c \cdot a}{b}}}{2 \cdot a}\]
    4. Applied simplify 0

      \[\leadsto \color{blue}{\frac{c}{b} \cdot \frac{-2}{2}}\]
  3. Recombined 4 regimes into one program.
  4. Removed slow pow expressions

Runtime

Time bar (total: 27.6s) Debug logProfile

Please include this information when filing a bug report:

herbie shell --seed '#(1064524629 4159152179 2999149171 575749698 4006532819 692958815)'
(FPCore (a b c)
  :name "The quadratic formula (r1)"

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

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