Average Error: 33.7 → 8.1
Time: 1.4m
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.5035807776383027 \cdot 10^{+150}:\\ \;\;\;\;\frac{4 \cdot \frac{c}{2}}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}\\ \mathbf{elif}\;-b \le 1.4186422616593875 \cdot 10^{-264}:\\ \;\;\;\;\frac{4 \cdot \frac{c}{2}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;-b \le 2.3420845656192757 \cdot 10^{+74}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)\right)\\ \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.7
Target21.0
Herbie8.1
\[\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.5035807776383027e+150

    1. Initial program 62.7

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

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

      \[\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)}}\]
    5. Simplified37.4

      \[\leadsto \frac{\color{blue}{\left(a \cdot c\right) \cdot 4}}{\left(2 \cdot a\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}\]
    6. Using strategy rm
    7. Applied times-frac37.2

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

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

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

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

    if -2.5035807776383027e+150 < (- b) < 1.4186422616593875e-264

    1. Initial program 33.5

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

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

      \[\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)}}\]
    5. Simplified20.7

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

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

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

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

    if 1.4186422616593875e-264 < (- b) < 2.3420845656192757e+74

    1. Initial program 9.2

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

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

    if 2.3420845656192757e+74 < (- b)

    1. Initial program 40.1

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    3. Simplified4.3

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-b \le -2.5035807776383027 \cdot 10^{+150}:\\ \;\;\;\;\frac{4 \cdot \frac{c}{2}}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}\\ \mathbf{elif}\;-b \le 1.4186422616593875 \cdot 10^{-264}:\\ \;\;\;\;\frac{4 \cdot \frac{c}{2}}{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)}}\\ \mathbf{elif}\;-b \le 2.3420845656192757 \cdot 10^{+74}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \left(\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} + \left(-b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{-b}{a}\\ \end{array}\]

Runtime

Time bar (total: 1.4m)Debug logProfile

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