Average Error: 32.8 → 9.6
Time: 18.8s
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 -3.585646687489005 \cdot 10^{+153}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \mathbf{elif}\;b \le 1.878245103047456 \cdot 10^{-48}:\\ \;\;\;\;\frac{\frac{(\left(\sqrt{\sqrt{(b \cdot b + \left(\left(c \cdot a\right) \cdot -4\right))_*}}\right) \cdot \left(\sqrt{\sqrt{(b \cdot b + \left(\left(c \cdot a\right) \cdot -4\right))_*}}\right) + \left(-b\right))_*}{2}}{a}\\ \mathbf{else}:\\ \;\;\;\;-\frac{c}{b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original32.8
Target20.3
Herbie9.6
\[\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 < -3.585646687489005e+153

    1. Initial program 60.6

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

      \[\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 div-inv60.6

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

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

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

    if -3.585646687489005e+153 < b < 1.878245103047456e-48

    1. Initial program 12.5

      \[\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 div-inv12.6

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

      \[\leadsto \color{blue}{\frac{\frac{\sqrt{(b \cdot b + \left(\left(a \cdot c\right) \cdot -4\right))_*} - b}{2}}{a}}\]
    7. Using strategy rm
    8. Applied add-sqr-sqrt12.7

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

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

    if 1.878245103047456e-48 < b

    1. Initial program 53.5

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

      \[\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 div-inv53.6

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

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

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

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

Reproduce

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