Average Error: 33.4 → 7.0
Time: 2.2m
Precision: 64
Internal Precision: 3392
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
\[\begin{array}{l} \mathbf{if}\;-b \le -1.2583082401548985 \cdot 10^{+157}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(\left(-b\right) - b\right) - \frac{c \cdot 2}{\frac{b}{a}}}\\ \mathbf{if}\;-b \le 3.908892434646583 \cdot 10^{-231}:\\ \;\;\;\;\frac{c \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} \cdot \frac{1}{2}\\ \mathbf{if}\;-b \le 7.245894423181754 \cdot 10^{+109}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a} - \frac{c}{b}\\ \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.4
Target21.1
Herbie7.0
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}}\\ \end{array}\]

Derivation

  1. Split input into 4 regimes
  2. if (- b) < -1.2583082401548985e+157

    1. Initial program 62.9

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

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

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

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

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

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

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

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

    if -1.2583082401548985e+157 < (- b) < 3.908892434646583e-231

    1. Initial program 32.1

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

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

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

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

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

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

    if 3.908892434646583e-231 < (- b) < 7.245894423181754e+109

    1. Initial program 8.4

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

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

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

    if 7.245894423181754e+109 < (- b)

    1. Initial program 47.9

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

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

      \[\leadsto \color{blue}{\left(-\frac{b}{a}\right) - \frac{\frac{c}{b}}{1}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify7.0

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -1.2583082401548985 \cdot 10^{+157}:\\ \;\;\;\;\frac{\frac{4}{2} \cdot c}{\left(\left(-b\right) - b\right) - \frac{c \cdot 2}{\frac{b}{a}}}\\ \mathbf{if}\;-b \le 3.908892434646583 \cdot 10^{-231}:\\ \;\;\;\;\frac{c \cdot 4}{\left(-b\right) - \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}} \cdot \frac{1}{2}\\ \mathbf{if}\;-b \le 7.245894423181754 \cdot 10^{+109}:\\ \;\;\;\;\frac{1}{\frac{a \cdot 2}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} - b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a} - \frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.2m)Debug logProfile

herbie shell --seed 2018195 
(FPCore (a b c)
  :name "The quadratic formula (r1)"

  :herbie-target
  (if (< b 0) (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))))

  (/ (+ (- b) (sqrt (- (* b b) (* (* 4 a) c)))) (* 2 a)))