Average Error: 0.6 → 0.5
Time: 4.1s
Precision: 64
\[\frac{e^{a}}{e^{a} + e^{b}}\]
\[e^{a - \log \left(\mathsf{fma}\left(\sqrt{e^{a}}, \sqrt{e^{a}}, e^{b}\right)\right)}\]
\frac{e^{a}}{e^{a} + e^{b}}
e^{a - \log \left(\mathsf{fma}\left(\sqrt{e^{a}}, \sqrt{e^{a}}, e^{b}\right)\right)}
double f(double a, double b) {
        double r154230 = a;
        double r154231 = exp(r154230);
        double r154232 = b;
        double r154233 = exp(r154232);
        double r154234 = r154231 + r154233;
        double r154235 = r154231 / r154234;
        return r154235;
}

double f(double a, double b) {
        double r154236 = a;
        double r154237 = exp(r154236);
        double r154238 = sqrt(r154237);
        double r154239 = b;
        double r154240 = exp(r154239);
        double r154241 = fma(r154238, r154238, r154240);
        double r154242 = log(r154241);
        double r154243 = r154236 - r154242;
        double r154244 = exp(r154243);
        return r154244;
}

Error

Bits error versus a

Bits error versus b

Target

Original0.6
Target0.0
Herbie0.5
\[\frac{1}{1 + e^{b - a}}\]

Derivation

  1. Initial program 0.6

    \[\frac{e^{a}}{e^{a} + e^{b}}\]
  2. Using strategy rm
  3. Applied add-exp-log0.6

    \[\leadsto \frac{e^{a}}{\color{blue}{e^{\log \left(e^{a} + e^{b}\right)}}}\]
  4. Applied div-exp0.5

    \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}}\]
  5. Using strategy rm
  6. Applied add-sqr-sqrt0.5

    \[\leadsto e^{a - \log \left(\color{blue}{\sqrt{e^{a}} \cdot \sqrt{e^{a}}} + e^{b}\right)}\]
  7. Applied fma-def0.5

    \[\leadsto e^{a - \log \color{blue}{\left(\mathsf{fma}\left(\sqrt{e^{a}}, \sqrt{e^{a}}, e^{b}\right)\right)}}\]
  8. Final simplification0.5

    \[\leadsto e^{a - \log \left(\mathsf{fma}\left(\sqrt{e^{a}}, \sqrt{e^{a}}, e^{b}\right)\right)}\]

Reproduce

herbie shell --seed 2020065 +o rules:numerics
(FPCore (a b)
  :name "Quotient of sum of exps"
  :precision binary64

  :herbie-target
  (/ 1 (+ 1 (exp (- b a))))

  (/ (exp a) (+ (exp a) (exp b))))