?

Average Error: 0.7 → 1.1
Time: 12.2s
Precision: binary64
Cost: 13512

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;b \leq -22000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 4.3 \cdot 10^{-23}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + \left(b + 1\right)}\\ \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 (+ 1.0 (exp b)))))
   (if (<= b -22000000.0)
     t_0
     (if (<= b 4.3e-23) (/ (exp a) (+ (exp a) (+ b 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 / (1.0 + exp(b));
	double tmp;
	if (b <= -22000000.0) {
		tmp = t_0;
	} else if (b <= 4.3e-23) {
		tmp = exp(a) / (exp(a) + (b + 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 / (1.0d0 + exp(b))
    if (b <= (-22000000.0d0)) then
        tmp = t_0
    else if (b <= 4.3d-23) then
        tmp = exp(a) / (exp(a) + (b + 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 / (1.0 + Math.exp(b));
	double tmp;
	if (b <= -22000000.0) {
		tmp = t_0;
	} else if (b <= 4.3e-23) {
		tmp = Math.exp(a) / (Math.exp(a) + (b + 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 / (1.0 + math.exp(b))
	tmp = 0
	if b <= -22000000.0:
		tmp = t_0
	elif b <= 4.3e-23:
		tmp = math.exp(a) / (math.exp(a) + (b + 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(1.0 + exp(b)))
	tmp = 0.0
	if (b <= -22000000.0)
		tmp = t_0;
	elseif (b <= 4.3e-23)
		tmp = Float64(exp(a) / Float64(exp(a) + Float64(b + 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 / (1.0 + exp(b));
	tmp = 0.0;
	if (b <= -22000000.0)
		tmp = t_0;
	elseif (b <= 4.3e-23)
		tmp = exp(a) / (exp(a) + (b + 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[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -22000000.0], t$95$0, If[LessEqual[b, 4.3e-23], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[(b + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
t_0 := \frac{1}{1 + e^{b}}\\
\mathbf{if}\;b \leq -22000000:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b \leq 4.3 \cdot 10^{-23}:\\
\;\;\;\;\frac{e^{a}}{e^{a} + \left(b + 1\right)}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation?

  1. Split input into 2 regimes
  2. if b < -2.2e7 or 4.30000000000000002e-23 < b

    1. Initial program 0.9

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

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

    if -2.2e7 < b < 4.30000000000000002e-23

    1. Initial program 0.5

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

      \[\leadsto \frac{e^{a}}{\color{blue}{1 + \left(e^{a} + b\right)}} \]
    3. Simplified1.0

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(b + 1\right)}} \]
      Proof

      [Start]1.0

      \[ \frac{e^{a}}{1 + \left(e^{a} + b\right)} \]

      rational.json-simplify-41 [=>]1.0

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

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

Alternatives

Alternative 1
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 2
Error1.1
Cost13384
\[\begin{array}{l} t_0 := \frac{1}{1 + e^{b}}\\ \mathbf{if}\;b \leq -22000000:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 4.3 \cdot 10^{-23}:\\ \;\;\;\;\frac{e^{a}}{1 + e^{a}}\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 3
Error0.9
Cost13252
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 4
Error14.3
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 55000000000:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{a}{b} - \left(-1 - \frac{1}{b}\right)\right) - 1\\ \end{array} \]
Alternative 5
Error25.3
Cost836
\[\begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5 + 0.25 \cdot a\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{a}{b} - \left(-1 - \frac{1}{b}\right)\right) - 1\\ \end{array} \]
Alternative 6
Error33.0
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 310:\\ \;\;\;\;0.5 + 0.25 \cdot a\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
Alternative 7
Error33.1
Cost324
\[\begin{array}{l} \mathbf{if}\;b \leq 360:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
Alternative 8
Error38.5
Cost64
\[0.5 \]

Error

Reproduce?

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