Average Error: 33.4 → 10.0
Time: 2.7m
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 -1.4724387140230096 \cdot 10^{-17}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.6036990415127427 \cdot 10^{+143}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \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.4
Target20.8
Herbie10.0
\[\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 3 regimes
  2. if b < -1.4724387140230096e-17

    1. Initial program 54.1

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

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

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

    if -1.4724387140230096e-17 < b < 2.6036990415127427e+143

    1. Initial program 14.6

      \[\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Using strategy rm
    3. Applied *-un-lft-identity14.6

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

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

    if 2.6036990415127427e+143 < b

    1. Initial program 56.7

      \[\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{a \cdot c}{b} - 2 \cdot b}}{2 \cdot a}\]
    3. Applied simplify1.7

      \[\leadsto \color{blue}{\frac{\frac{c}{1}}{b} - \frac{b}{a}}\]
  3. Recombined 3 regimes into one program.
  4. Applied simplify10.0

    \[\leadsto \color{blue}{\begin{array}{l} \mathbf{if}\;b \le -1.4724387140230096 \cdot 10^{-17}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{if}\;b \le 2.6036990415127427 \cdot 10^{+143}:\\ \;\;\;\;\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}}\]

Runtime

Time bar (total: 2.7m)Debug logProfile

herbie shell --seed 2019053 +o rules:numerics
(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)))