Average Error: 33.6 → 8.2
Time: 1.7m
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 -3.9035910367662003 \cdot 10^{+56}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \le -3.9974034204694203 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.14338207405497 \cdot 10^{+85}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b \cdot 2 - 2 \cdot \frac{c \cdot a}{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.6
Target21.1
Herbie8.2
\[\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 < -3.9035910367662003e+56

    1. Initial program 36.5

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{b}{a}}\]
    4. Simplified5.4

      \[\leadsto \color{blue}{\frac{-b}{a}}\]

    if -3.9035910367662003e+56 < b < -3.9974034204694203e-305

    1. Initial program 10.1

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

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

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

    if -3.9974034204694203e-305 < b < 2.14338207405497e+85

    1. Initial program 31.7

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(-c\right) \cdot \left(4 \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}\]
    7. Using strategy rm
    8. Applied distribute-lft-neg-out21.9

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

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

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

    if 2.14338207405497e+85 < b

    1. Initial program 57.5

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(-c\right) \cdot \left(4 \cdot a\right)}}{\left(2 \cdot a\right) \cdot \left(\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + b\right)}\]
    7. Using strategy rm
    8. Applied distribute-lft-neg-out32.1

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.9035910367662003 \cdot 10^{+56}:\\ \;\;\;\;\frac{-b}{a}\\ \mathbf{elif}\;b \le -3.9974034204694203 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b} \cdot \sqrt{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}}{a \cdot 2}\\ \mathbf{elif}\;b \le 2.14338207405497 \cdot 10^{+85}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{c}{2} \cdot \left(-4\right)}{b \cdot 2 - 2 \cdot \frac{c \cdot a}{b}}\\ \end{array}\]

Runtime

Time bar (total: 1.7m)Debug logProfile

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