Average Error: 0.5 → 1.0
Time: 4.2s
Precision: binary64
Cost: 6852
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;a \leq -740:\\ \;\;\;\;0\\ \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 -740.0) 0.0 (/ 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 <= -740.0) {
		tmp = 0.0;
	} 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 <= (-740.0d0)) then
        tmp = 0.0d0
    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 <= -740.0) {
		tmp = 0.0;
	} 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 <= -740.0:
		tmp = 0.0
	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 <= -740.0)
		tmp = 0.0;
	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 <= -740.0)
		tmp = 0.0;
	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, -740.0], 0.0, 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 -740:\\
\;\;\;\;0\\

\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.5
Target0.0
Herbie1.0
\[\frac{1}{1 + e^{b - a}} \]

Derivation

  1. Split input into 2 regimes
  2. if a < -740

    1. Initial program 0.9

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + b}} \]
    4. Simplified61.6

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
      Proof
      (+.f64 b 2): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 2 b)): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr42.9

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

      \[\leadsto \color{blue}{1} - 1 \]

    if -740 < a

    1. Initial program 0.4

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

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

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

Alternatives

Alternative 1
Error12.0
Cost19848
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 1:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.000000001:\\ \;\;\;\;\frac{1}{1 + e^{-a}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.5
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error24.4
Cost980
\[\begin{array}{l} \mathbf{if}\;b \leq -1.6 \cdot 10^{-193}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-284}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 5.2 \cdot 10^{-184}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 8 \cdot 10^{-151}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.54:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 4
Error24.4
Cost980
\[\begin{array}{l} \mathbf{if}\;b \leq -1.5 \cdot 10^{-193}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-284}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 7.5 \cdot 10^{-184}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{-151}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.27:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error24.5
Cost724
\[\begin{array}{l} \mathbf{if}\;b \leq -1.6 \cdot 10^{-193}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-284}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 7.5 \cdot 10^{-184}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 6.8 \cdot 10^{-151}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-11}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error13.4
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -350:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error38.6
Cost64
\[0.5 \]

Error

Reproduce

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