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

\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{1}{e^{b} + 1}\right) + -1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b))) < 0.599999999999999978

    1. Initial program 0.0

      \[\frac{e^{a}}{e^{a} + e^{b}} \]

    if 0.599999999999999978 < (/.f64 (exp.f64 a) (+.f64 (exp.f64 a) (exp.f64 b)))

    1. Initial program 3.3

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

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{1 + e^{b}}\right)} - 1 \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{a}}{e^{a} + e^{b}} \leq 0.6:\\ \;\;\;\;\frac{e^{a}}{e^{a} + e^{b}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{e^{b} + 1}\right) + -1\\ \end{array} \]

Alternatives

Alternative 1
Error0.7
Cost26312
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.6:\\ \;\;\;\;\left(1 + t_0\right) + -1\\ \mathbf{elif}\;e^{b} \leq 1.000002:\\ \;\;\;\;\frac{e^{a}}{e^{a} + \left(b + 1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 2
Error0.8
Cost26184
\[\begin{array}{l} t_0 := \frac{1}{e^{b} + 1}\\ \mathbf{if}\;e^{b} \leq 0.6:\\ \;\;\;\;\left(1 + t_0\right) + -1\\ \mathbf{elif}\;e^{b} \leq 1.000000005:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error1.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -13111326.671473132:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error25.2
Cost1376
\[\begin{array}{l} \mathbf{if}\;a \leq -29.865202000468962:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -9.676835304439497 \cdot 10^{-222}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;a \leq -1.2204010151244642 \cdot 10^{-257}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 2.082802020257218 \cdot 10^{-263}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 7.933027014547591 \cdot 10^{-215}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 1.788982764330052 \cdot 10^{-154}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 7.780091078854733 \cdot 10^{-99}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 5.142742043405975 \cdot 10^{-51}:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error25.3
Cost1120
\[\begin{array}{l} \mathbf{if}\;a \leq -1134.2530607568654:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -9.676835304439497 \cdot 10^{-222}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq -1.2204010151244642 \cdot 10^{-257}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 2.082802020257218 \cdot 10^{-263}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 7.933027014547591 \cdot 10^{-215}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 1.788982764330052 \cdot 10^{-154}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 1.4994810814086305 \cdot 10^{-109}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 5.142742043405975 \cdot 10^{-51}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error25.1
Cost1120
\[\begin{array}{l} \mathbf{if}\;a \leq -29.865202000468962:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -9.676835304439497 \cdot 10^{-222}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;a \leq -1.2204010151244642 \cdot 10^{-257}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 2.082802020257218 \cdot 10^{-263}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 7.933027014547591 \cdot 10^{-215}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 1.788982764330052 \cdot 10^{-154}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq 1.4994810814086305 \cdot 10^{-109}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq 5.142742043405975 \cdot 10^{-51}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 7
Error12.8
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -1.1127435327369119 \cdot 10^{-5}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 8
Error38.6
Cost64
\[0.5 \]

Error

Reproduce

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