Average Error: 33.6 → 7.3
Time: 58.1s
Precision: 64
Internal Precision: 3392
\[\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.3541633968562655 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot c}{\left(\frac{a \cdot c}{b} \cdot 2 - b\right) - b}\\ \mathbf{elif}\;b \le 7.567387309621116 \cdot 10^{-268}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\ \mathbf{elif}\;b \le 1.1420827307329462 \cdot 10^{+137}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\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.6
Target20.8
Herbie7.3
\[\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.3541633968562655e+154

    1. Initial program 62.9

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

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

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

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

      \[\leadsto \frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*38.8

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

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

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

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

    if -1.3541633968562655e+154 < b < 7.567387309621116e-268

    1. Initial program 33.5

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

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

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

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

      \[\leadsto \frac{\color{blue}{4 \cdot \left(a \cdot c\right)}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a}\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*14.5

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

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

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

    if 7.567387309621116e-268 < b < 1.1420827307329462e+137

    1. Initial program 8.4

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

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

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

    if 1.1420827307329462e+137 < b

    1. Initial program 54.7

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified2.2

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.3541633968562655 \cdot 10^{+154}:\\ \;\;\;\;\frac{2 \cdot c}{\left(\frac{a \cdot c}{b} \cdot 2 - b\right) - b}\\ \mathbf{elif}\;b \le 7.567387309621116 \cdot 10^{-268}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\ \mathbf{elif}\;b \le 1.1420827307329462 \cdot 10^{+137}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 58.1s)Debug logProfile

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