Average Error: 33.5 → 6.8
Time: 49.6s
Precision: 64
Internal Precision: 128
\[\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 -5.574371059116902 \cdot 10^{+91}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;-b \le -3.4735799267547486 \cdot 10^{-308}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;-b \le 6.299526501700798 \cdot 10^{+78}:\\ \;\;\;\;\frac{4}{\sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a} - b} \cdot \frac{c}{2}\\ \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.5
Target20.8
Herbie6.8
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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) < -5.574371059116902e+91

    1. Initial program 43.2

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

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

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

    if -5.574371059116902e+91 < (- b) < -3.4735799267547486e-308

    1. Initial program 9.7

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

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

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

    if -3.4735799267547486e-308 < (- b) < 6.299526501700798e+78

    1. Initial program 30.0

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

      \[\leadsto \frac{\left(-b\right) - \sqrt{\color{blue}{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}{2 \cdot a}\]
    3. Using strategy rm
    4. Applied div-inv30.0

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

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

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

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

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

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

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

    if 6.299526501700798e+78 < (- 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. Taylor expanded around -inf 2.8

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;-b \le -5.574371059116902 \cdot 10^{+91}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;-b \le -3.4735799267547486 \cdot 10^{-308}:\\ \;\;\;\;\left(\left(-b\right) - \sqrt{{b}^{2} - \left(a \cdot c\right) \cdot 4}\right) \cdot \frac{1}{2 \cdot a}\\ \mathbf{elif}\;-b \le 6.299526501700798 \cdot 10^{+78}:\\ \;\;\;\;\frac{4}{\sqrt{b \cdot b + \left(c \cdot -4\right) \cdot a} - b} \cdot \frac{c}{2}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 49.6s)Debug logProfile

herbie shell --seed 2018274 
(FPCore (a b c)
  :name "The quadratic formula (r2)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))