Average Error: 0.7 → 0.0
Time: 4.6s
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)))))): 1 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))))): 62 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))))): 3 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))))): 1 points increase in error, 62 points decrease in error
    (/.f64 1 (*.f64 (Rewrite<= rec-exp_binary64 (/.f64 1 (exp.f64 a))) (+.f64 (exp.f64 a) (exp.f64 b)))): 1 points increase in error, 3 points decrease in error
    (/.f64 1 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 1 (+.f64 (exp.f64 a) (exp.f64 b))) (exp.f64 a)))): 0 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
Error1.3
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.9995:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 2
Error1.3
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.9995:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{2 + \mathsf{expm1}\left(b\right)}\\ \end{array} \]
Alternative 3
Error0.8
Cost7048
\[\begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;b \leq -110000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 0.00041:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 4
Error16.3
Cost6920
\[\begin{array}{l} \mathbf{if}\;b \leq 700:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 5
Error17.2
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 6 \cdot 10^{+149}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + \left(b \cdot b\right) \cdot 0.5}\\ \end{array} \]
Alternative 6
Error29.4
Cost836
\[\begin{array}{l} \mathbf{if}\;b \leq 2.7 \cdot 10^{-21}:\\ \;\;\;\;\frac{1}{2 - a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + \left(b \cdot b\right) \cdot 0.5}\\ \end{array} \]
Alternative 7
Error29.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.25 \cdot 10^{+62}:\\ \;\;\;\;\frac{1}{2 - a}\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 8
Error38.6
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 9
Error38.3
Cost320
\[\frac{1}{2 - a} \]
Alternative 10
Error38.8
Cost64
\[0.5 \]

Error

Reproduce

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