?

Average Error: 0.9 → 1.2
Time: 6.9s
Precision: binary64
Cost: 6852

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;a \leq -650000:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= a -650000.0) 0.0 (/ 1.0 (+ 1.0 (exp b)))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if (a <= -650000.0) {
		tmp = 0.0;
	} else {
		tmp = 1.0 / (1.0 + 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 (a <= (-650000.0d0)) then
        tmp = 0.0d0
    else
        tmp = 1.0d0 / (1.0d0 + 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 (a <= -650000.0) {
		tmp = 0.0;
	} else {
		tmp = 1.0 / (1.0 + 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 a <= -650000.0:
		tmp = 0.0
	else:
		tmp = 1.0 / (1.0 + 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 (a <= -650000.0)
		tmp = 0.0;
	else
		tmp = Float64(1.0 / Float64(1.0 + 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 (a <= -650000.0)
		tmp = 0.0;
	else
		tmp = 1.0 / (1.0 + 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[a, -650000.0], 0.0, N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;a \leq -650000:\\
\;\;\;\;0\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 2 regimes
  2. if a < -6.5e5

    1. Initial program 0.9

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
    3. Taylor expanded in b around 0 61.5

      \[\leadsto \frac{1}{\color{blue}{2 + b}} \]
    4. Simplified61.5

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
      Proof

      [Start]61.5

      \[ \frac{1}{2 + b} \]

      +-commutative [=>]61.5

      \[ \frac{1}{\color{blue}{b + 2}} \]
    5. Applied egg-rr42.3

      \[\leadsto \color{blue}{\left(1 + \frac{1}{b + 2}\right) - 1} \]
    6. Taylor expanded in b around inf 0.2

      \[\leadsto \color{blue}{1} - 1 \]

    if -6.5e5 < a

    1. Initial program 0.9

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

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

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

Alternatives

Alternative 1
Error1.7
Cost13120
\[\frac{e^{a}}{1 + e^{b}} \]
Alternative 2
Error11.2
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 360:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 3
Error23.3
Cost980
\[\begin{array}{l} \mathbf{if}\;b \leq -5 \cdot 10^{-39}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -2.8 \cdot 10^{-64}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 1.18 \cdot 10^{-150}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 8.4 \cdot 10^{-77}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.23:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 4
Error23.4
Cost724
\[\begin{array}{l} \mathbf{if}\;b \leq -4 \cdot 10^{-39}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -2.9 \cdot 10^{-64}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-150}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 8.4 \cdot 10^{-77}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.0047:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error13.7
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -1.5 \cdot 10^{-26}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error37.9
Cost64
\[0.5 \]

Error

Reproduce?

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