Average Error: 33.5 → 7.0
Time: 2.3m
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}\;\frac{2}{b} \le -1.3884055312110023 \cdot 10^{-98}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{if}\;\frac{2}{b} \le 3.01328267130535 \cdot 10^{-309}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{a \cdot 2}\\ \mathbf{if}\;\frac{2}{b} \le 1.6156984818371083 \cdot 10^{-23}:\\ \;\;\;\;\frac{\frac{-4}{2} \cdot \frac{c}{2}}{b - \frac{c}{\frac{b}{a}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b} \cdot \frac{-4}{2}\\ \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.5
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 (/ 2 b) < -1.3884055312110023e-98

    1. Initial program 8.2

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

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

    if -1.3884055312110023e-98 < (/ 2 b) < 3.01328267130535e-309

    1. Initial program 44.9

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot 1 - \frac{b + b}{2 \cdot a}}\]

    if 3.01328267130535e-309 < (/ 2 b) < 1.6156984818371083e-23

    1. Initial program 55.9

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

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

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

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

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

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

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

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

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

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

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

    if 1.6156984818371083e-23 < (/ 2 b)

    1. Initial program 27.5

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}\]
    2. Applied simplify27.5

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;\frac{2}{b} \le -1.3884055312110023 \cdot 10^{-98}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(c \cdot 4\right) \cdot a} - b}{a \cdot 2}\\ \mathbf{if}\;\frac{2}{b} \le 3.01328267130535 \cdot 10^{-309}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{a \cdot 2}\\ \mathbf{if}\;\frac{2}{b} \le 1.6156984818371083 \cdot 10^{-23}:\\ \;\;\;\;\frac{\frac{-4}{2} \cdot \frac{c}{2}}{b - \frac{c}{\frac{b}{a}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{\sqrt{b \cdot b - \left(a \cdot c\right) \cdot 4} + b} \cdot \frac{-4}{2}\\ \end{array}}\]

Runtime

Time bar (total: 2.3m)Debug logProfile

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