Average Error: 33.1 → 6.6
Time: 3.6m
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 -2.6763214650448188 \cdot 10^{+138}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -6.248469593546225 \cdot 10^{-273}:\\ \;\;\;\;\frac{1}{\sqrt{b + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}} \cdot \left(\frac{\frac{2}{c}}{-4} \cdot \sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\right)}\\ \mathbf{if}\;-b \le 6.0685917336100174 \cdot 10^{+94}:\\ \;\;\;\;\left(\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot 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.1
Target20.7
Herbie6.6
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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) < -2.6763214650448188e+138

    1. Initial program 61.1

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

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

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

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

    if -2.6763214650448188e+138 < (- b) < -6.248469593546225e-273

    1. Initial program 34.1

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

      \[\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 clear-num34.1

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

      \[\leadsto \frac{1}{\frac{2 \cdot a}{\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}}}}\]
    7. Applied associate-/r/34.3

      \[\leadsto \frac{1}{\color{blue}{\frac{2 \cdot a}{\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} \cdot \left(\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b\right)}}\]
    8. Applied simplify8.1

      \[\leadsto \frac{1}{\color{blue}{\frac{2}{\frac{-4}{\frac{1}{c}}}} \cdot \left(\sqrt{b \cdot b - \left(4 \cdot c\right) \cdot a} + b\right)}\]
    9. Using strategy rm
    10. Applied add-sqr-sqrt8.3

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

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

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

    if -6.248469593546225e-273 < (- b) < 6.0685917336100174e+94

    1. Initial program 9.3

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

      \[\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 div-inv9.4

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

    if 6.0685917336100174e+94 < (- b)

    1. Initial program 44.0

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

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

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

      \[\leadsto \color{blue}{\frac{c}{b} \cdot 1 - \frac{b + b}{2 \cdot a}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify6.6

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.6763214650448188 \cdot 10^{+138}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;-b \le -6.248469593546225 \cdot 10^{-273}:\\ \;\;\;\;\frac{1}{\sqrt{b + \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}} \cdot \left(\frac{\frac{2}{c}}{-4} \cdot \sqrt{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\right)}\\ \mathbf{if}\;-b \le 6.0685917336100174 \cdot 10^{+94}:\\ \;\;\;\;\left(\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b + b}{2 \cdot a}\\ \end{array}}\]

Runtime

Time bar (total: 3.6m)Debug logProfile

herbie shell --seed 2018178 
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :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)))