Average Error: 32.9 → 6.3
Time: 24.7s
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 -3.628278339169478 \cdot 10^{+149}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.5161853332160458 \cdot 10^{-263}:\\ \;\;\;\;\frac{4 \cdot c}{2 \cdot \left(\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} - b\right)}\\ \mathbf{elif}\;b \le 6.959770719239994 \cdot 10^{+151}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Error

Bits error versus a

Bits error versus b

Bits error versus c

Target

Original32.9
Target19.9
Herbie6.3
\[\begin{array}{l} \mathbf{if}\;b \lt 0:\\ \;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}\\ \mathbf{else}:\\ \;\;\;\;\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 4 regimes
  2. if b < -3.628278339169478e+149

    1. Initial program 62.6

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

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

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

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

    if -3.628278339169478e+149 < b < 1.5161853332160458e-263

    1. Initial program 32.7

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

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

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

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

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

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

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

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

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

    if 1.5161853332160458e-263 < b < 6.959770719239994e+151

    1. Initial program 8.1

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

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

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

    if 6.959770719239994e+151 < b

    1. Initial program 59.6

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \le -3.628278339169478 \cdot 10^{+149}:\\ \;\;\;\;\frac{-c}{b}\\ \mathbf{elif}\;b \le 1.5161853332160458 \cdot 10^{-263}:\\ \;\;\;\;\frac{4 \cdot c}{2 \cdot \left(\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*} - b\right)}\\ \mathbf{elif}\;b \le 6.959770719239994 \cdot 10^{+151}:\\ \;\;\;\;\frac{-b}{a \cdot 2} - \frac{\sqrt{(\left(-4 \cdot a\right) \cdot c + \left(b \cdot b\right))_*}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{c}{b} - \frac{b}{a}\\ \end{array}\]

Runtime

Time bar (total: 24.7s)Debug logProfile

BaselineHerbieOracleSpan%
Regimes28.76.35.623.197.1%
herbie shell --seed 2018296 +o rules:numerics
(FPCore (a b c)
  :name "quadm (p42, negative)"

  :herbie-target
  (if (< b 0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))

  (/ (- (- b) (sqrt (- (* b b) (* 4 (* a c))))) (* 2 a)))