?

Average Accuracy: 99.1% → 98.7%
Time: 3.8s
Precision: binary64
Cost: 13385.00

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -15500 \lor \neg \left(b \leq 1.46 \cdot 10^{-5}\right):\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (or (<= b -15500.0) (not (<= b 1.46e-5)))
   (/ 1.0 (+ (exp b) 1.0))
   (/ (exp a) (+ (exp a) 1.0))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if ((b <= -15500.0) || !(b <= 1.46e-5)) {
		tmp = 1.0 / (exp(b) + 1.0);
	} else {
		tmp = exp(a) / (exp(a) + 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 ((b <= (-15500.0d0)) .or. (.not. (b <= 1.46d-5))) then
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    else
        tmp = exp(a) / (exp(a) + 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 ((b <= -15500.0) || !(b <= 1.46e-5)) {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	} else {
		tmp = Math.exp(a) / (Math.exp(a) + 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 (b <= -15500.0) or not (b <= 1.46e-5):
		tmp = 1.0 / (math.exp(b) + 1.0)
	else:
		tmp = math.exp(a) / (math.exp(a) + 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 ((b <= -15500.0) || !(b <= 1.46e-5))
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	else
		tmp = Float64(exp(a) / Float64(exp(a) + 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 ((b <= -15500.0) || ~((b <= 1.46e-5)))
		tmp = 1.0 / (exp(b) + 1.0);
	else
		tmp = exp(a) / (exp(a) + 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[Or[LessEqual[b, -15500.0], N[Not[LessEqual[b, 1.46e-5]], $MachinePrecision]], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;b \leq -15500 \lor \neg \left(b \leq 1.46 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{1}{e^{b} + 1}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original99.1%
Target100.0%
Herbie98.7%
\[\frac{1}{1 + e^{b - a}} \]

Derivation?

  1. Split input into 2 regimes
  2. if b < -15500 or 1.46000000000000008e-5 < b

    1. Initial program 98.7%

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]

    if -15500 < b < 1.46000000000000008e-5

    1. Initial program 99.5%

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

      \[\leadsto \color{blue}{\frac{e^{a}}{1 + e^{a}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -15500 \lor \neg \left(b \leq 1.46 \cdot 10^{-5}\right):\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.1%
Cost19520.00
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 2
Accuracy98.5%
Cost13252.00
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.8:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 3
Accuracy68.3%
Cost6788.00
\[\begin{array}{l} \mathbf{if}\;b \leq 720:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\ \end{array} \]
Alternative 4
Accuracy65.4%
Cost6592.00
\[\frac{e^{a}}{2} \]
Alternative 5
Accuracy39.4%
Cost320.00
\[0.5 + a \cdot 0.25 \]
Alternative 6
Accuracy39.2%
Cost64.00
\[0.5 \]

Error

Reproduce?

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