Average Error: 34.0 → 10.5
Time: 4.6s
Precision: binary64
\[\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.887155650852303 \cdot 10^{94}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.07893083320297934 \cdot 10^{-91}:\\ \;\;\;\;\frac{1}{a} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original34.0
Target21.1
Herbie10.5
\[\begin{array}{l} \mathbf{if}\;b \lt 0.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 < -1.887155650852303e94

    1. Initial program 45.7

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

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

      \[\leadsto \color{blue}{1 \cdot \frac{c}{b} - 1 \cdot \frac{b}{a}}\]
    4. Simplified3.9

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

    if -1.887155650852303e94 < b < 1.07893083320297934e-91

    1. Initial program 13.2

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

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

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

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

    if 1.07893083320297934e-91 < b

    1. Initial program 52.1

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -1.887155650852303 \cdot 10^{94}:\\ \;\;\;\;1 \cdot \left(\frac{c}{b} - \frac{b}{a}\right)\\ \mathbf{elif}\;b \le 1.07893083320297934 \cdot 10^{-91}:\\ \;\;\;\;\frac{1}{a} \cdot \frac{\sqrt{b \cdot b - 4 \cdot \left(c \cdot a\right)} - b}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} \cdot -1\\ \end{array}\]

Reproduce

herbie shell --seed 2020179 
(FPCore (a b c)
  :name "quadp (p42, positive)"
  :precision binary64

  :herbie-target
  (if (< b 0.0) (/ (+ (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))

  (/ (+ (neg b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))