?

Average Error: 0.6 → 0.8
Time: 10.8s
Precision: binary64
Cost: 19652

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.9:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \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 (<= (exp a) 0.9) (/ (exp a) (+ (exp a) 1.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 (exp(a) <= 0.9) {
		tmp = exp(a) / (exp(a) + 1.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 (exp(a) <= 0.9d0) then
        tmp = exp(a) / (exp(a) + 1.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 (Math.exp(a) <= 0.9) {
		tmp = Math.exp(a) / (Math.exp(a) + 1.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 math.exp(a) <= 0.9:
		tmp = math.exp(a) / (math.exp(a) + 1.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 (exp(a) <= 0.9)
		tmp = Float64(exp(a) / Float64(exp(a) + 1.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 (exp(a) <= 0.9)
		tmp = exp(a) / (exp(a) + 1.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[N[Exp[a], $MachinePrecision], 0.9], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0.9:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\

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

Derivation?

  1. Split input into 2 regimes
  2. if (exp.f64 a) < 0.900000000000000022

    1. Initial program 0.8

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

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

    if 0.900000000000000022 < (exp.f64 a)

    1. Initial program 0.5

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

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

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

Alternatives

Alternative 1
Error0.6
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 2
Error1.0
Cost13632
\[\frac{e^{a}}{\left(\left(a + e^{b}\right) + 0.5 \cdot \left(a \cdot a\right)\right) + 1} \]
Alternative 3
Error0.9
Cost6980
\[\begin{array}{l} \mathbf{if}\;a \leq -400:\\ \;\;\;\;\frac{e^{a}}{a \cdot \left(a \cdot 0.5\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error11.6
Cost6720
\[\frac{1}{e^{b} + 1} \]
Alternative 5
Error21.6
Cost1092
\[\begin{array}{l} \mathbf{if}\;b \leq -0.029:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\right) + -1\\ \end{array} \]
Alternative 6
Error22.1
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq -0.029:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error29.7
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]
Alternative 8
Error37.8
Cost64
\[0.5 \]

Error

Reproduce?

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