Average Error: 33.2 → 9.0
Time: 2.9m
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 -1.410133816448586 \cdot 10^{+92}:\\ \;\;\;\;\frac{\left(-b\right) + b}{a + a} - \frac{c}{b}\\ \mathbf{if}\;b \le -2.6983419874853703 \cdot 10^{-256}:\\ \;\;\;\;\frac{\frac{1}{\frac{\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + \left(-b\right)}{\left(4 \cdot c\right) \cdot a}}}{2 \cdot a}\\ \mathbf{if}\;b \le 4.645202501114693 \cdot 10^{+112}:\\ \;\;\;\;\frac{1}{\frac{2 \cdot a}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\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.2
Target20.4
Herbie9.0
\[\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 < -1.410133816448586e+92

    1. Initial program 57.4

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

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify2.9

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

      \[\leadsto \frac{\left(-b\right) + b}{a + a} - \color{blue}{\frac{c}{b}}\]

    if -1.410133816448586e+92 < b < -2.6983419874853703e-256

    1. Initial program 33.3

      \[\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--33.4

      \[\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 simplify16.7

      \[\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 add-sqr-sqrt16.7

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

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

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

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

    if -2.6983419874853703e-256 < b < 4.645202501114693e+112

    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 clear-num9.4

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

    if 4.645202501114693e+112 < b

    1. Initial program 47.3

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

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

      \[\leadsto \color{blue}{\frac{\frac{c}{b}}{1} - \frac{b}{a}}\]
    4. Applied simplify3.0

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

Runtime

Time bar (total: 2.9m)Debug logProfile

herbie shell --seed '#(1063185673 2139736501 2393378123 1907444849 1070993796 1007244912)' 
(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)))