Average Error: 0.7 → 0.0
Time: 4.0s
Precision: binary64
Cost: 6848
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\frac{1}{1 + e^{b - a}} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp(a) / (exp(a) + exp(b))
end function
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
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 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	return Float64(1.0 / Float64(1.0 + exp(Float64(b - a))))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
function tmp = code(a, b)
	tmp = 1.0 / (1.0 + exp((b - a)));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{e^{a}}{e^{a} + e^{b}}
\frac{1}{1 + e^{b - a}}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Initial program 0.7

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

    \[\leadsto \color{blue}{{\left(\frac{e^{a} + e^{b}}{e^{a}}\right)}^{-1}} \]
  3. Taylor expanded in a around inf 0.7

    \[\leadsto \color{blue}{\frac{e^{a}}{e^{a} + e^{b}}} \]
  4. Simplified0.0

    \[\leadsto \color{blue}{\frac{1}{1 + e^{b - a}}} \]
    Proof
    (/.f64 1 (+.f64 1 (exp.f64 (-.f64 b a)))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (+.f64 1 (exp.f64 (Rewrite<= unsub-neg_binary64 (+.f64 b (neg.f64 a)))))): 0 points increase in error, 0 points decrease in error
    (/.f64 1 (+.f64 1 (Rewrite<= prod-exp_binary64 (*.f64 (exp.f64 b) (exp.f64 (neg.f64 a)))))): 2 points increase in error, 0 points decrease in error
    (/.f64 1 (+.f64 (Rewrite<= rgt-mult-inverse_binary64 (*.f64 (exp.f64 a) (/.f64 1 (exp.f64 a)))) (*.f64 (exp.f64 b) (exp.f64 (neg.f64 a))))): 71 points increase in error, 0 points decrease in error
    (/.f64 1 (+.f64 (*.f64 (exp.f64 a) (Rewrite=> rec-exp_binary64 (exp.f64 (neg.f64 a)))) (*.f64 (exp.f64 b) (exp.f64 (neg.f64 a))))): 4 points increase in error, 0 points decrease in error
    (/.f64 1 (Rewrite<= distribute-rgt-in_binary64 (*.f64 (exp.f64 (neg.f64 a)) (+.f64 (exp.f64 a) (exp.f64 b))))): 0 points increase in error, 70 points decrease in error
    (/.f64 1 (*.f64 (Rewrite<= rec-exp_binary64 (/.f64 1 (exp.f64 a))) (+.f64 (exp.f64 a) (exp.f64 b)))): 0 points increase in error, 4 points decrease in error
    (/.f64 1 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1 (+.f64 (exp.f64 a) (exp.f64 b))) (exp.f64 a)))): 1 points increase in error, 1 points decrease in error
    (/.f64 1 (/.f64 (Rewrite=> *-lft-identity_binary64 (+.f64 (exp.f64 a) (exp.f64 b))) (exp.f64 a))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-/l*_binary64 (/.f64 (*.f64 1 (exp.f64 a)) (+.f64 (exp.f64 a) (exp.f64 b)))): 1 points increase in error, 1 points decrease in error
    (/.f64 (Rewrite=> *-lft-identity_binary64 (exp.f64 a)) (+.f64 (exp.f64 a) (exp.f64 b))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.0

    \[\leadsto \frac{1}{1 + e^{b - a}} \]

Alternatives

Alternative 1
Error0.9
Cost13316
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.999988:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 2
Error0.9
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 2 \cdot 10^{-150}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 3
Error22.1
Cost6860
\[\begin{array}{l} \mathbf{if}\;a \leq -1.2 \cdot 10^{-15}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq -3.5 \cdot 10^{-75}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq -2 \cdot 10^{-90}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
Alternative 4
Error38.8
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 5
Error38.3
Cost320
\[\frac{1}{2 - a} \]
Alternative 6
Error38.8
Cost64
\[0.5 \]

Error

Reproduce

herbie shell --seed 2022329 
(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))))