?

Average Error: 0.7 → 0.4
Time: 7.7s
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 1:\\ \;\;\;\;t_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
 (let* ((t_0 (/ (exp a) (+ (exp a) (exp b)))))
   (if (<= t_0 1.0) t_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 t_0 = exp(a) / (exp(a) + exp(b));
	double tmp;
	if (t_0 <= 1.0) {
		tmp = t_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) :: t_0
    real(8) :: tmp
    t_0 = exp(a) / (exp(a) + exp(b))
    if (t_0 <= 1.0d0) then
        tmp = t_0
    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 t_0 = Math.exp(a) / (Math.exp(a) + Math.exp(b));
	double tmp;
	if (t_0 <= 1.0) {
		tmp = t_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):
	t_0 = math.exp(a) / (math.exp(a) + math.exp(b))
	tmp = 0
	if t_0 <= 1.0:
		tmp = t_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)
	t_0 = Float64(exp(a) / Float64(exp(a) + exp(b)))
	tmp = 0.0
	if (t_0 <= 1.0)
		tmp = t_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)
	t_0 = exp(a) / (exp(a) + exp(b));
	tmp = 0.0;
	if (t_0 <= 1.0)
		tmp = t_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_] := 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, 1.0], t$95$0, N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $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 1:\\
\;\;\;\;t_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.7
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))) < 1

    1. Initial program 0.0

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

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

    1. Initial program 64.0

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
  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 1:\\ \;\;\;\;\frac{e^{a}}{e^{a} + e^{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]

Alternatives

Alternative 1
Error11.6
Cost26185
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 1 \lor \neg \left(e^{b} \leq 2\right):\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \end{array} \]
Alternative 2
Error1.0
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -8600000:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 3
Error11.9
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 9 \cdot 10^{+15}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b}\right) + -1\\ \end{array} \]
Alternative 4
Error21.3
Cost1604
\[\begin{array}{l} \mathbf{if}\;a \leq -720:\\ \;\;\;\;\frac{1}{\left(\frac{-4}{b} + \frac{-8}{b \cdot b}\right) - b \cdot \left(\frac{b}{2 - b} + b \cdot -0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 5
Error22.7
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq -1.05 \cdot 10^{-183}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error23.4
Cost580
\[\begin{array}{l} \mathbf{if}\;b \leq 5.2 \cdot 10^{-28}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b}\right) + -1\\ \end{array} \]
Alternative 7
Error30.5
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 5.2 \cdot 10^{-28}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 8
Error38.3
Cost320
\[0.5 + a \cdot 0.25 \]
Alternative 9
Error38.4
Cost64
\[0.5 \]

Error

Reproduce?

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