Average Error: 33.3 → 6.6
Time: 2.1m
Precision: 64
Internal Precision: 3200
\[\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 -2.8554295294908104 \cdot 10^{+18}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{if}\;-b \le 1.509106255236428 \cdot 10^{-303}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{if}\;-b \le 3.56580878367139 \cdot 10^{+95}:\\ \;\;\;\;\frac{1}{2} \cdot \frac{4 \cdot c}{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + \left(-b\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{4 \cdot c}{2}}{\left(-b\right) + (\left(\frac{c}{b}\right) \cdot \left(a + a\right) + \left(-b\right))_*}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.3
Herbie6.6
\[\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 4 regimes
  2. if (- b) < -2.8554295294908104e+18

    1. Initial program 32.9

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

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

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

    if -2.8554295294908104e+18 < (- b) < 1.509106255236428e-303

    1. Initial program 9.2

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

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

    if 1.509106255236428e-303 < (- b) < 3.56580878367139e+95

    1. Initial program 31.8

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

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

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

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

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

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

    if 3.56580878367139e+95 < (- b)

    1. Initial program 58.4

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

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

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

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

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

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

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

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

Runtime

Time bar (total: 2.1m)Debug logProfile

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