Average Error: 33.0 → 6.2
Time: 2.1m
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.184855009194371 \cdot 10^{+99}:\\ \;\;\;\;\frac{\frac{\frac{c}{2}}{2} \cdot 4}{\frac{a}{\frac{b}{c}} - b}\\ \mathbf{if}\;-b \le 1.283865567620366 \cdot 10^{-259}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{c \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}}\\ \mathbf{if}\;-b \le 5.212416467940643 \cdot 10^{+55}:\\ \;\;\;\;\left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.0
Target19.8
Herbie6.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.184855009194371e+99

    1. Initial program 59.3

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

      \[\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 simplify31.2

      \[\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 *-un-lft-identity31.2

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

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

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

      \[\leadsto \frac{1}{2} \cdot \frac{c \cdot 4}{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}\]
    10. Applied simplify2.5

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

    if -5.184855009194371e+99 < (- b) < 1.283865567620366e-259

    1. Initial program 29.9

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

      \[\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 simplify14.9

      \[\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 *-un-lft-identity14.9

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

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

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

    if 1.283865567620366e-259 < (- b) < 5.212416467940643e+55

    1. Initial program 7.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 div-inv7.9

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

    if 5.212416467940643e+55 < (- b)

    1. Initial program 36.5

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

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

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

Runtime

Time bar (total: 2.1m)Debug logProfile

herbie shell --seed '#(1070355188 2193211668 3977393919 3454156579 3755371326 1656365382)' 
(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)))