Average Error: 0.8 → 0.8
Time: 3.4s
Precision: binary64
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[e^{a - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{a} + e^{b}\right)\right)\right)} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (exp (- a (expm1 (log1p (log (+ (exp a) (exp b))))))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	return exp((a - expm1(log1p(log((exp(a) + exp(b)))))));
}
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
public static double code(double a, double b) {
	return Math.exp((a - Math.expm1(Math.log1p(Math.log((Math.exp(a) + Math.exp(b)))))));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	return math.exp((a - math.expm1(math.log1p(math.log((math.exp(a) + math.exp(b)))))))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	return exp(Float64(a - expm1(log1p(log(Float64(exp(a) + exp(b)))))))
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := N[Exp[N[(a - N[(Exp[N[Log[1 + N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\frac{e^{a}}{e^{a} + e^{b}}
e^{a - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{a} + e^{b}\right)\right)\right)}

Error

Bits error versus a

Bits error versus b

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 0.8

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Applied egg-rr0.7

    \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
  3. Applied egg-rr0.8

    \[\leadsto e^{a - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{a} + e^{b}\right)\right)\right)}} \]
  4. Final simplification0.8

    \[\leadsto e^{a - \mathsf{expm1}\left(\mathsf{log1p}\left(\log \left(e^{a} + e^{b}\right)\right)\right)} \]

Reproduce

herbie shell --seed 2022159 
(FPCore (a b)
  :name "Quotient of sum of exps"
  :precision binary64

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

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