Average Error: 33.7 → 10.3
Time: 24.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 -1.836394958733996 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.571257464516749 \cdot 10^{-99}:\\ \;\;\;\;\frac{\frac{1}{a}}{\frac{2}{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.7
Target20.5
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 < -1.836394958733996e+106

    1. Initial program 44.7

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

      \[\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 4.0

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

    if -1.836394958733996e+106 < b < 1.571257464516749e-99

    1. Initial program 12.4

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

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

      \[\leadsto \frac{\color{blue}{1 \cdot \frac{\sqrt{(b \cdot b + \left(\left(a \cdot c\right) \cdot -4\right))_*} - b}{2}}}{a}\]
    5. Applied associate-/l*12.5

      \[\leadsto \color{blue}{\frac{1}{\frac{a}{\frac{\sqrt{(b \cdot b + \left(\left(a \cdot c\right) \cdot -4\right))_*} - b}{2}}}}\]
    6. Using strategy rm
    7. Applied div-inv12.5

      \[\leadsto \frac{1}{\color{blue}{a \cdot \frac{1}{\frac{\sqrt{(b \cdot b + \left(\left(a \cdot c\right) \cdot -4\right))_*} - b}{2}}}}\]
    8. Applied associate-/r*12.5

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

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

    if 1.571257464516749e-99 < b

    1. Initial program 52.0

      \[\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}\]
    2. Simplified52.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 10.1

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

      \[\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 -1.836394958733996 \cdot 10^{+106}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.571257464516749 \cdot 10^{-99}:\\ \;\;\;\;\frac{\frac{1}{a}}{\frac{2}{\sqrt{(-4 \cdot \left(c \cdot a\right) + \left(b \cdot b\right))_*} - b}}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Reproduce

herbie shell --seed 2019051 +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)))