Average Error: 33.7 → 7.3
Time: 1.5m
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.4179539573507906 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -2.689070205918387 \cdot 10^{-289}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.269164629607323 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(-4\right) \cdot \frac{c}{2}}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-4\right) \cdot \frac{c}{2}}{b + \left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\\ \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
Target20.6
Herbie7.3
\[\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.4179539573507906e+153

    1. Initial program 60.6

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

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

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

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

    if -2.4179539573507906e+153 < b < -2.689070205918387e-289

    1. Initial program 8.0

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

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

    if -2.689070205918387e-289 < b < 6.269164629607323e+152

    1. Initial program 33.4

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

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

      \[\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/37.4

      \[\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. Simplified19.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-out19.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-neg19.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. Simplified8.5

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

    if 6.269164629607323e+152 < b

    1. Initial program 62.7

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Initial simplification62.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--62.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/62.7

      \[\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. Simplified37.2

      \[\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-out37.2

      \[\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-neg37.2

      \[\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. Simplified36.9

      \[\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 6.8

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -2.4179539573507906 \cdot 10^{+153}:\\ \;\;\;\;-\frac{b}{a}\\ \mathbf{elif}\;b \le -2.689070205918387 \cdot 10^{-289}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{2 \cdot a}\\ \mathbf{elif}\;b \le 6.269164629607323 \cdot 10^{+152}:\\ \;\;\;\;\frac{\left(-4\right) \cdot \frac{c}{2}}{b + \sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(-4\right) \cdot \frac{c}{2}}{b + \left(b - 2 \cdot \frac{c \cdot a}{b}\right)}\\ \end{array}\]

Runtime

Time bar (total: 1.5m)Debug logProfile

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