Average Error: 32.8 → 9.1
Time: 1.2m
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.4418812687735028 \cdot 10^{+162}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(2 \cdot \frac{a \cdot c}{b} - b \cdot 2\right)}\\ \mathbf{elif}\;b \le 5.10631632091719 \cdot 10^{-309}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}\\ \mathbf{elif}\;b \le 1.2367652643144536 \cdot 10^{+136}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{2}}{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

Original32.8
Target20.4
Herbie9.1
\[\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.4418812687735028e+162

    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 + -4 \cdot \left(a \cdot c\right)}}{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 + -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}\]
    5. Applied associate-/l/62.9

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    6. Simplified39.1

      \[\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 + -4 \cdot \left(a \cdot c\right)}\right)}\]
    7. Taylor expanded around -inf 14.6

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

    if -1.4418812687735028e+162 < b < 5.10631632091719e-309

    1. Initial program 33.6

      \[\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 + -4 \cdot \left(a \cdot c\right)}}{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 + -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}\]
    5. Applied associate-/l/37.5

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    6. Simplified19.2

      \[\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 + -4 \cdot \left(a \cdot c\right)}\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*14.0

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

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

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

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

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

    if 5.10631632091719e-309 < b < 1.2367652643144536e+136

    1. Initial program 9.3

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

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

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

    if 1.2367652643144536e+136 < b

    1. Initial program 53.8

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

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

      \[\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}\]
    5. Applied associate-/l/62.1

      \[\leadsto \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(2 \cdot a\right) \cdot \left(\left(-b\right) + \sqrt{b \cdot b + -4 \cdot \left(a \cdot c\right)}\right)}}\]
    6. Simplified62.3

      \[\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 + -4 \cdot \left(a \cdot c\right)}\right)}\]
    7. Using strategy rm
    8. Applied associate-/r*62.3

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

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

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

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

      \[\leadsto \frac{2 \cdot \color{blue}{c}}{\sqrt{a \cdot \left(-4 \cdot c\right) + b \cdot b} - b}\]
    14. Taylor expanded around 0 2.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.4418812687735028 \cdot 10^{+162}:\\ \;\;\;\;\frac{4 \cdot \left(a \cdot c\right)}{\left(a \cdot 2\right) \cdot \left(2 \cdot \frac{a \cdot c}{b} - b \cdot 2\right)}\\ \mathbf{elif}\;b \le 5.10631632091719 \cdot 10^{-309}:\\ \;\;\;\;\frac{2 \cdot c}{\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b}\\ \mathbf{elif}\;b \le 1.2367652643144536 \cdot 10^{+136}:\\ \;\;\;\;\frac{\frac{\left(-b\right) - \sqrt{b \cdot b + \left(a \cdot c\right) \cdot -4}}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Runtime

Time bar (total: 1.2m)Debug logProfile

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