?

Average Error: 0.7 → 1.0
Time: 5.1s
Precision: binary64
Cost: 26184

?

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

\mathbf{elif}\;e^{b} \leq 1.000000000005:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 3 regimes
  2. if (exp.f64 b) < 0.99995999999999996

    1. Initial program 1.4

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

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

    if 0.99995999999999996 < (exp.f64 b) < 1.000000000005

    1. Initial program 0.4

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

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

    if 1.000000000005 < (exp.f64 b)

    1. Initial program 0.6

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
    3. Taylor expanded in b around 0 59.5

      \[\leadsto \frac{1}{\color{blue}{2 + b}} \]
    4. Simplified59.5

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
      Proof

      [Start]59.5

      \[ \frac{1}{2 + b} \]

      +-commutative [=>]59.5

      \[ \frac{1}{\color{blue}{b + 2}} \]
    5. Applied egg-rr4.3

      \[\leadsto \color{blue}{\left(1 + \frac{1}{b + 2}\right) - 1} \]
    6. Taylor expanded in b around inf 1.6

      \[\leadsto \color{blue}{1} - 1 \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{b} \leq 0.99996:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 1.000000000005:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternatives

Alternative 1
Error0.8
Cost19848
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0.99996:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 1.000000000005:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 2
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error0.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -780000:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error23.1
Cost844
\[\begin{array}{l} \mathbf{if}\;a \leq -0.001:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -6.2 \cdot 10^{-249}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;a \leq -1.9 \cdot 10^{-269}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{-1}{-1 + \left(a + -1\right)}\\ \end{array} \]
Alternative 5
Error13.9
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -2.4:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error23.2
Cost584
\[\begin{array}{l} \mathbf{if}\;a \leq -0.00068:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -1.15 \cdot 10^{-249}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;a \leq -1.6 \cdot 10^{-269}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 7
Error23.4
Cost460
\[\begin{array}{l} \mathbf{if}\;a \leq -1.85 \cdot 10^{-11}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -7 \cdot 10^{-250}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq -1.7 \cdot 10^{-269}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 8
Error39.1
Cost64
\[0.5 \]

Error

Reproduce?

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