Average Error: 33.9 → 8.7
Time: 44.2s
Precision: 64
Internal Precision: 2368
\[\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 -3.835485963993344 \cdot 10^{+141}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.7609896923513245 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.2066041974631788 \cdot 10^{+30}:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{a} \cdot \left(\left(c \cdot 4\right) \cdot a\right)}{\left(-b\right) - \sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 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.9
Target20.9
Herbie8.7
\[\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 < -3.835485963993344e+141

    1. Initial program 55.6

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

      \[\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-inv55.6

      \[\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. Taylor expanded around -inf 55.6

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

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

    if -3.835485963993344e+141 < b < 4.7609896923513245e-147

    1. Initial program 11.3

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

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

    if 4.7609896923513245e-147 < b < 1.2066041974631788e+30

    1. Initial program 36.9

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

      \[\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-inv36.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}}\]
    5. Taylor expanded around -inf 36.9

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

      \[\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}\]
    8. Applied associate-*l/37.0

      \[\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 \frac{1}{2 \cdot a}}{\left(-b\right) - \sqrt{{b}^{2} - 4 \cdot \left(a \cdot c\right)}}}\]
    9. Simplified16.2

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

    if 1.2066041974631788e+30 < b

    1. Initial program 55.7

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.835485963993344 \cdot 10^{+141}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 4.7609896923513245 \cdot 10^{-147}:\\ \;\;\;\;\frac{\sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4} + \left(-b\right)}{a \cdot 2}\\ \mathbf{elif}\;b \le 1.2066041974631788 \cdot 10^{+30}:\\ \;\;\;\;\frac{\frac{\frac{1}{2}}{a} \cdot \left(\left(c \cdot 4\right) \cdot a\right)}{\left(-b\right) - \sqrt{{b}^{2} - \left(c \cdot a\right) \cdot 4}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Runtime

Time bar (total: 44.2s)Debug logProfile

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