Average Error: 33.3 → 8.7
Time: 2.0m
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.7844874579804934 \cdot 10^{+138}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;-b \le 2.6179464065815588 \cdot 10^{-83}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \mathbf{if}\;-b \le 4.451662349375344 \cdot 10^{+61}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}\\ \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.3
Target20.5
Herbie8.7
\[\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) < -2.7844874579804934e+138

    1. Initial program 54.3

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

      \[\leadsto \frac{\color{blue}{2 \cdot \frac{c \cdot a}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify2.1

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

    if -2.7844874579804934e+138 < (- b) < 2.6179464065815588e-83

    1. Initial program 11.8

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

    if 2.6179464065815588e-83 < (- b) < 4.451662349375344e+61

    1. Initial program 42.3

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

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

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

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

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

    if 4.451662349375344e+61 < (- 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 42.1

      \[\leadsto \frac{\left(-b\right) - \color{blue}{\left(2 \cdot \frac{c \cdot a}{b} - b\right)}}{2 \cdot a}\]
    3. Applied simplify3.5

      \[\leadsto \color{blue}{\left(-1\right) \cdot \frac{c}{b}}\]
  3. Recombined 4 regimes into one program.
  4. Applied simplify8.7

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;-b \le -2.7844874579804934 \cdot 10^{+138}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{if}\;-b \le 2.6179464065815588 \cdot 10^{-83}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a \cdot 2}\\ \mathbf{if}\;-b \le 4.451662349375344 \cdot 10^{+61}:\\ \;\;\;\;\frac{1}{a \cdot 2} \cdot \frac{4 \cdot \left(a \cdot c\right)}{\sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)} - b}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}}\]

Runtime

Time bar (total: 2.0m)Debug logProfile

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