Average Error: 0.6 → 0.3
Time: 9.1s
Precision: binary64
Cost: 20232
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;b \leq -151859839.3628064:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq -3.6426014530627585 \cdot 10^{-23}:\\ \;\;\;\;\frac{e^{a}}{0.5 \cdot {a}^{2} + \left(1 + \left(a + e^{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + e^{b}}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= b -151859839.3628064)
   (+ (exp b) 1.0)
   (if (<= b -3.6426014530627585e-23)
     (/ (exp a) (+ (* 0.5 (pow a 2.0)) (+ 1.0 (+ a (exp b)))))
     (/ (exp a) (+ (exp a) (exp b))))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if (b <= -151859839.3628064) {
		tmp = exp(b) + 1.0;
	} else if (b <= -3.6426014530627585e-23) {
		tmp = exp(a) / ((0.5 * pow(a, 2.0)) + (1.0 + (a + exp(b))));
	} else {
		tmp = exp(a) / (exp(a) + exp(b));
	}
	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 <= (-151859839.3628064d0)) then
        tmp = exp(b) + 1.0d0
    else if (b <= (-3.6426014530627585d-23)) then
        tmp = exp(a) / ((0.5d0 * (a ** 2.0d0)) + (1.0d0 + (a + exp(b))))
    else
        tmp = exp(a) / (exp(a) + exp(b))
    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 <= -151859839.3628064) {
		tmp = Math.exp(b) + 1.0;
	} else if (b <= -3.6426014530627585e-23) {
		tmp = Math.exp(a) / ((0.5 * Math.pow(a, 2.0)) + (1.0 + (a + Math.exp(b))));
	} else {
		tmp = Math.exp(a) / (Math.exp(a) + Math.exp(b));
	}
	return tmp;
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	tmp = 0
	if b <= -151859839.3628064:
		tmp = math.exp(b) + 1.0
	elif b <= -3.6426014530627585e-23:
		tmp = math.exp(a) / ((0.5 * math.pow(a, 2.0)) + (1.0 + (a + math.exp(b))))
	else:
		tmp = math.exp(a) / (math.exp(a) + math.exp(b))
	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 <= -151859839.3628064)
		tmp = Float64(exp(b) + 1.0);
	elseif (b <= -3.6426014530627585e-23)
		tmp = Float64(exp(a) / Float64(Float64(0.5 * (a ^ 2.0)) + Float64(1.0 + Float64(a + exp(b)))));
	else
		tmp = Float64(exp(a) / Float64(exp(a) + exp(b)));
	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 <= -151859839.3628064)
		tmp = exp(b) + 1.0;
	elseif (b <= -3.6426014530627585e-23)
		tmp = exp(a) / ((0.5 * (a ^ 2.0)) + (1.0 + (a + exp(b))));
	else
		tmp = exp(a) / (exp(a) + exp(b));
	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[b, -151859839.3628064], N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[b, -3.6426014530627585e-23], N[(N[Exp[a], $MachinePrecision] / N[(N[(0.5 * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 + N[(a + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;b \leq -151859839.3628064:\\
\;\;\;\;e^{b} + 1\\

\mathbf{elif}\;b \leq -3.6426014530627585 \cdot 10^{-23}:\\
\;\;\;\;\frac{e^{a}}{0.5 \cdot {a}^{2} + \left(1 + \left(a + e^{b}\right)\right)}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original0.6
Target0.0
Herbie0.3
\[\frac{1}{1 + e^{b - a}} \]

Derivation

  1. Split input into 3 regimes
  2. if b < -151859839.36280641

    1. Initial program 1.6

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

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

      \[\leadsto e^{\color{blue}{-1 \cdot \log \left(1 + e^{b}\right)}} \]
    4. Simplified0

      \[\leadsto e^{\color{blue}{-\mathsf{log1p}\left(e^{b}\right)}} \]
      Proof
      (neg.f64 (log1p.f64 (exp.f64 b))): 0 points increase in error, 0 points decrease in error
      (neg.f64 (Rewrite<= log1p-def_binary64 (log.f64 (+.f64 1 (exp.f64 b))))): 2 points increase in error, 5 points decrease in error
      (Rewrite=> neg-mul-1_binary64 (*.f64 -1 (log.f64 (+.f64 1 (exp.f64 b))))): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr0

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

    if -151859839.36280641 < b < -3.6426014530627585e-23

    1. Initial program 2.3

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

      \[\leadsto \frac{e^{a}}{\color{blue}{0.5 \cdot {a}^{2} + \left(1 + \left(a + e^{b}\right)\right)}} \]

    if -3.6426014530627585e-23 < b

    1. Initial program 0.4

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.3

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -151859839.3628064:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq -3.6426014530627585 \cdot 10^{-23}:\\ \;\;\;\;\frac{e^{a}}{0.5 \cdot {a}^{2} + \left(1 + \left(a + e^{b}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + e^{b}}\\ \end{array} \]

Alternatives

Alternative 1
Error0.9
Cost26184
\[\begin{array}{l} t_0 := e^{b} + 1\\ \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.0002:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 2
Error0.6
Cost25920
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
Alternative 3
Error1.3
Cost19912
\[\begin{array}{l} t_0 := e^{b} + 1\\ \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.0002:\\ \;\;\;\;\frac{e^{a}}{1 + \left(a + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 4
Error1.4
Cost19784
\[\begin{array}{l} t_0 := e^{b} + 1\\ \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.0002:\\ \;\;\;\;\frac{e^{a}}{a + 2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 5
Error0.8
Cost19780
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;e^{b} + 1\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{1 + \left(a + e^{b}\right)}\\ \end{array} \]
Alternative 6
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 7
Error17.4
Cost7124
\[\begin{array}{l} t_0 := \left(1 + \frac{1}{b + 2}\right) + -1\\ \mathbf{if}\;a \leq -29.28056150470826:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq -2.0321481986222426 \cdot 10^{-183}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq -1.0905320485522875 \cdot 10^{-225}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq 3.808894912299725 \cdot 10^{-167}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;a \leq 7.292825838122975 \cdot 10^{-60}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 8
Error15.3
Cost7124
\[\begin{array}{l} \mathbf{if}\;b \leq -126267.37383466595:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq -1.279527201993866 \cdot 10^{-106}:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{elif}\;b \leq -4.982003841986741 \cdot 10^{-182}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -1.635690114652294 \cdot 10^{-299}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 3.771975112665823 \cdot 10^{-223}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 9
Error2.1
Cost6984
\[\begin{array}{l} \mathbf{if}\;b \leq -126267.37383466595:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq 14162400.611620152:\\ \;\;\;\;\frac{e^{a}}{a + 2}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 10
Error22.3
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 3.2228892508414333 \cdot 10^{-166}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 11
Error38.3
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 12
Error38.4
Cost64
\[0.5 \]

Error

Reproduce

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