Average Error: 0.6 → 0.9
Time: 4.7s
Precision: binary64
Cost: 26184
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 5 \cdot 10^{-55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (/ 1.0 (+ (exp b) 1.0))))
   (if (<= (exp b) 5e-55)
     t_0
     (if (<= (exp b) 2.0) (/ (exp a) (+ (exp a) 1.0)) t_0))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double t_0 = 1.0 / (exp(b) + 1.0);
	double tmp;
	if (exp(b) <= 5e-55) {
		tmp = t_0;
	} else if (exp(b) <= 2.0) {
		tmp = exp(a) / (exp(a) + 1.0);
	} else {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = 1.0d0 / (exp(b) + 1.0d0)
    if (exp(b) <= 5d-55) then
        tmp = t_0
    else if (exp(b) <= 2.0d0) then
        tmp = exp(a) / (exp(a) + 1.0d0)
    else
        tmp = t_0
    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 t_0 = 1.0 / (Math.exp(b) + 1.0);
	double tmp;
	if (Math.exp(b) <= 5e-55) {
		tmp = t_0;
	} else if (Math.exp(b) <= 2.0) {
		tmp = Math.exp(a) / (Math.exp(a) + 1.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
def code(a, b):
	t_0 = 1.0 / (math.exp(b) + 1.0)
	tmp = 0
	if math.exp(b) <= 5e-55:
		tmp = t_0
	elif math.exp(b) <= 2.0:
		tmp = math.exp(a) / (math.exp(a) + 1.0)
	else:
		tmp = t_0
	return tmp
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function code(a, b)
	t_0 = Float64(1.0 / Float64(exp(b) + 1.0))
	tmp = 0.0
	if (exp(b) <= 5e-55)
		tmp = t_0;
	elseif (exp(b) <= 2.0)
		tmp = Float64(exp(a) / Float64(exp(a) + 1.0));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
function tmp_2 = code(a, b)
	t_0 = 1.0 / (exp(b) + 1.0);
	tmp = 0.0;
	if (exp(b) <= 5e-55)
		tmp = t_0;
	elseif (exp(b) <= 2.0)
		tmp = exp(a) / (exp(a) + 1.0);
	else
		tmp = t_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_] := Block[{t$95$0 = N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Exp[b], $MachinePrecision], 5e-55], t$95$0, If[LessEqual[N[Exp[b], $MachinePrecision], 2.0], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{1}{e^{b} + 1}\\
\mathbf{if}\;e^{b} \leq 5 \cdot 10^{-55}:\\
\;\;\;\;t_0\\

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

\mathbf{else}:\\
\;\;\;\;t_0\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (exp.f64 b) < 5.0000000000000002e-55 or 2 < (exp.f64 b)

    1. Initial program 0.8

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

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

    if 5.0000000000000002e-55 < (exp.f64 b) < 2

    1. Initial program 0.4

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{b} \leq 5 \cdot 10^{-55}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 2:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error0.5
Cost25920
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
Alternative 2
Error1.1
Cost19912
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 5 \cdot 10^{-55}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.00001:\\ \;\;\;\;e^{a} \cdot \left(0.5 + a \cdot -0.25\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 4
Error13.3
Cost6860
\[\begin{array}{l} t_0 := 0.5 + a \cdot 0.25\\ \mathbf{if}\;b \leq -4 \cdot 10^{-10}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 8.5 \cdot 10^{-193}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.15 \cdot 10^{-166}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 1.8:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{2}{b \cdot b}\right) + -1\\ \end{array} \]
Alternative 5
Error0.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -25000000:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 6
Error23.0
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 5.9 \cdot 10^{-65}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error22.6
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq 1.9:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{2}{b \cdot b}\right) + -1\\ \end{array} \]
Alternative 8
Error23.1
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 1.5:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b}\right) + -1\\ \end{array} \]
Alternative 9
Error30.6
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 1.75:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 10
Error39.2
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 11
Error39.3
Cost64
\[0.5 \]

Error

Reproduce

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