?

Average Error: 0.8 → 1.2
Time: 7.8s
Precision: binary64
Cost: 6852

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;a \leq -120000000:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= a -120000000.0) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if (a <= -120000000.0) {
		tmp = exp(a);
	} else {
		tmp = 1.0 / (exp(b) + 1.0);
	}
	return tmp;
}
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
    real(8) :: tmp
    if (a <= (-120000000.0d0)) then
        tmp = exp(a)
    else
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    end if
    code = tmp
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) {
	double tmp;
	if (a <= -120000000.0) {
		tmp = Math.exp(a);
	} else {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	}
	return tmp;
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	tmp = 0
	if a <= -120000000.0:
		tmp = math.exp(a)
	else:
		tmp = 1.0 / (math.exp(b) + 1.0)
	return tmp
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	tmp = 0.0
	if (a <= -120000000.0)
		tmp = exp(a);
	else
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	end
	return tmp
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -120000000.0)
		tmp = exp(a);
	else
		tmp = 1.0 / (exp(b) + 1.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, b_] := If[LessEqual[a, -120000000.0], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;a \leq -120000000:\\
\;\;\;\;e^{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 2 regimes
  2. if a < -1.2e8

    1. Initial program 0.4

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

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

      \[\leadsto e^{\color{blue}{a}} \]

    if -1.2e8 < a

    1. Initial program 1.0

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Taylor expanded in a around 0 1.6

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification1.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -120000000:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost25920
\[e^{a - \mathsf{log1p}\left(e^{a} + \mathsf{expm1}\left(b\right)\right)} \]
Alternative 2
Error0.7
Cost25920
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
Alternative 3
Error0.8
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 4
Error13.2
Cost6860
\[\begin{array}{l} \mathbf{if}\;b \leq -9.5 \cdot 10^{-6}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 1.16 \cdot 10^{-260}:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-233}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 2.8:\\ \;\;\;\;0.5 + b \cdot \left(-0.25 + 0.020833333333333332 \cdot \left(b \cdot b\right)\right)\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{2}{b \cdot b} + -1\right)\\ \end{array} \]
Alternative 5
Error22.5
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;1 + \left(\frac{2}{b \cdot b} + -1\right)\\ \end{array} \]
Alternative 6
Error30.1
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 7
Error38.5
Cost64
\[0.5 \]

Error

Reproduce?

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