Average Error: 33.5 → 10.3
Time: 15.5s
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 -7.016796193946308 \cdot 10^{+56}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.688109615052416 \cdot 10^{-33}:\\ \;\;\;\;\frac{\frac{\sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.5
Target20.4
Herbie10.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{a \cdot \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 < -7.016796193946308e+56

    1. Initial program 36.0

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

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

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

    if -7.016796193946308e+56 < b < 1.688109615052416e-33

    1. Initial program 15.2

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{(b \cdot b + \left(\left(a \cdot c\right) \cdot -4\right))_*} - b}{2}}{a}}\]
    3. Taylor expanded around 0 15.2

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

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

    if 1.688109615052416e-33 < b

    1. Initial program 55.0

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -7.016796193946308 \cdot 10^{+56}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.688109615052416 \cdot 10^{-33}:\\ \;\;\;\;\frac{\frac{\sqrt{(\left(c \cdot a\right) \cdot -4 + \left(b \cdot b\right))_*} - b}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{-c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019093 +o rules:numerics
(FPCore (a b c)
  :name "quadp (p42, positive)"

  :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)))