Average Error: 33.5 → 6.8
Time: 48.2s
Precision: 64
Internal Precision: 128
\[\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 -5.923995356212318 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.21680597614298 \cdot 10^{-309}:\\ \;\;\;\;\frac{4}{\sqrt{\left(-4 \cdot c\right) \cdot a + b \cdot b} - b} \cdot \frac{c}{2}\\ \mathbf{elif}\;b \le 1.3586174053149808 \cdot 10^{+85}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original33.5
Target20.8
Herbie6.8
\[\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 < -5.923995356212318e+84

    1. Initial program 57.9

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv57.9

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

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

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

    if -5.923995356212318e+84 < b < -1.21680597614298e-309

    1. Initial program 30.2

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv30.2

      \[\leadsto \color{blue}{\left(\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}}\]
    6. Using strategy rm
    7. Applied flip--30.3

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

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

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

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

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

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

    if -1.21680597614298e-309 < b < 1.3586174053149808e+85

    1. Initial program 9.7

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv9.8

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

    if 1.3586174053149808e+85 < b

    1. Initial program 42.0

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

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    4. Using strategy rm
    5. Applied div-inv42.1

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -5.923995356212318 \cdot 10^{+84}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le -1.21680597614298 \cdot 10^{-309}:\\ \;\;\;\;\frac{4}{\sqrt{\left(-4 \cdot c\right) \cdot a + b \cdot b} - b} \cdot \frac{c}{2}\\ \mathbf{elif}\;b \le 1.3586174053149808 \cdot 10^{+85}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 48.2s)Debug logProfile

herbie shell --seed 2018274 
(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)))