Average Error: 33.6 → 13.5
Time: 26.6s
Precision: 64
Internal Precision: 3392
\[\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.5809418989318178 \cdot 10^{-275}:\\ \;\;\;\;\frac{\sqrt{(\left(a \cdot -4\right) \cdot c + \left(b \cdot b\right))_*} - b}{a \cdot 2}\\ \mathbf{elif}\;b \le 3.5872793306843375 \cdot 10^{+41}:\\ \;\;\;\;\frac{-4 \cdot \left(c \cdot \frac{1}{2}\right)}{b + \sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-4 \cdot \left(c \cdot \frac{1}{2}\right)}{b + b}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original33.6
Target20.7
Herbie13.5
\[\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.5809418989318178e-275

    1. Initial program 21.4

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

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

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

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

    if 1.5809418989318178e-275 < b < 3.5872793306843375e+41

    1. Initial program 29.6

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot c\right)} \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    10. Using strategy rm
    11. Applied associate-*r/9.4

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

    if 3.5872793306843375e+41 < b

    1. Initial program 56.5

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\frac{1}{2} \cdot c\right)} \cdot \frac{-4}{\sqrt{(\left(a \cdot c\right) \cdot -4 + \left(b \cdot b\right))_*} + b}\]
    10. Using strategy rm
    11. Applied associate-*r/24.5

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

      \[\leadsto \frac{\left(\frac{1}{2} \cdot c\right) \cdot -4}{\color{blue}{b} + b}\]
  3. Recombined 3 regimes into one program.
  4. Final simplification13.5

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

Runtime

Time bar (total: 26.6s)Debug logProfile

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