Average Error: 33.0 → 6.6
Time: 48.3s
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}\;b \le -4.5574647268420826 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.4060449925563067 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 8.558214290723834 \cdot 10^{+125}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \frac{c}{\frac{-1}{4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{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.0
Target20.6
Herbie6.6
\[\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 b < -4.5574647268420826e+106

    1. Initial program 46.4

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

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

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

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

    if -4.5574647268420826e+106 < b < -2.4060449925563067e-305

    1. Initial program 9.0

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

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

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

    if -2.4060449925563067e-305 < b < 8.558214290723834e+125

    1. Initial program 33.1

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\frac{-4 \cdot \left(c \cdot a\right) + 0}{\frac{a}{\frac{1}{2}}}}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b}\]
    9. Using strategy rm
    10. Applied *-un-lft-identity14.7

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

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

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

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

    if 8.558214290723834e+125 < b

    1. Initial program 60.2

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

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

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

      \[\leadsto \color{blue}{\frac{-c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Final simplification6.6

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -4.5574647268420826 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le -2.4060449925563067 \cdot 10^{-305}:\\ \;\;\;\;\frac{\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 8.558214290723834 \cdot 10^{+125}:\\ \;\;\;\;\frac{\frac{1}{2}}{\sqrt{b \cdot b - \left(c \cdot a\right) \cdot 4} + b} \cdot \frac{c}{\frac{-1}{4}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Runtime

Time bar (total: 48.3s)Debug logProfile

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