Average Error: 33.3 → 23.0
Time: 20.6s
Precision: 64
Internal Precision: 3136
\[\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.9618312106014605 \cdot 10^{-111}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a} \cdot \frac{1}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c \cdot \left(a \cdot -4\right)}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*}\right)}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.3
Target20.7
Herbie23.0
\[\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 2 regimes
  2. if b < 1.9618312106014605e-111

    1. Initial program 20.9

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

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

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

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

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

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

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

    if 1.9618312106014605e-111 < b

    1. Initial program 50.6

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{\left(a \cdot -4\right) \cdot c}}{\left(2 \cdot a\right) \cdot \left(\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} + b\right)}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification23.0

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

Runtime

Time bar (total: 20.6s)Debug logProfile

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