Average Error: 0.7 → 1.0
Time: 7.1s
Precision: binary64
Cost: 26441
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0.9999998 \lor \neg \left(e^{b} \leq 1\right):\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \mathbf{else}:\\ \;\;\;\;e^{a} \cdot \frac{1}{e^{a} + \left(1 + b\right)}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (or (<= (exp b) 0.9999998) (not (<= (exp b) 1.0)))
   (/ 1.0 (+ 1.0 (exp b)))
   (* (exp a) (/ 1.0 (+ (exp a) (+ 1.0 b))))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
double code(double a, double b) {
	double tmp;
	if ((exp(b) <= 0.9999998) || !(exp(b) <= 1.0)) {
		tmp = 1.0 / (1.0 + exp(b));
	} else {
		tmp = exp(a) * (1.0 / (exp(a) + (1.0 + 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 ((exp(b) <= 0.9999998d0) .or. (.not. (exp(b) <= 1.0d0))) then
        tmp = 1.0d0 / (1.0d0 + exp(b))
    else
        tmp = exp(a) * (1.0d0 / (exp(a) + (1.0d0 + 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 ((Math.exp(b) <= 0.9999998) || !(Math.exp(b) <= 1.0)) {
		tmp = 1.0 / (1.0 + Math.exp(b));
	} else {
		tmp = Math.exp(a) * (1.0 / (Math.exp(a) + (1.0 + b)));
	}
	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(b) <= 0.9999998) or not (math.exp(b) <= 1.0):
		tmp = 1.0 / (1.0 + math.exp(b))
	else:
		tmp = math.exp(a) * (1.0 / (math.exp(a) + (1.0 + 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 ((exp(b) <= 0.9999998) || !(exp(b) <= 1.0))
		tmp = Float64(1.0 / Float64(1.0 + exp(b)));
	else
		tmp = Float64(exp(a) * Float64(1.0 / Float64(exp(a) + Float64(1.0 + 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 ((exp(b) <= 0.9999998) || ~((exp(b) <= 1.0)))
		tmp = 1.0 / (1.0 + exp(b));
	else
		tmp = exp(a) * (1.0 / (exp(a) + (1.0 + 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[Or[LessEqual[N[Exp[b], $MachinePrecision], 0.9999998], N[Not[LessEqual[N[Exp[b], $MachinePrecision], 1.0]], $MachinePrecision]], N[(1.0 / N[(1.0 + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Exp[a], $MachinePrecision] * N[(1.0 / N[(N[Exp[a], $MachinePrecision] + N[(1.0 + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 0.9999998 \lor \neg \left(e^{b} \leq 1\right):\\
\;\;\;\;\frac{1}{1 + e^{b}}\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 2 regimes
  2. if (exp.f64 b) < 0.999999799999999994 or 1 < (exp.f64 b)

    1. Initial program 1.1

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

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

    if 0.999999799999999994 < (exp.f64 b) < 1

    1. Initial program 0.3

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

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

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

      \[\leadsto \frac{1}{\color{blue}{e^{a} + \left(1 + b\right)}} \cdot e^{a} \]
      Proof
      (*.f64 (/.f64 1 (+.f64 (exp.f64 a) (+.f64 1 b))) (exp.f64 a)): 0 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1 (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (exp.f64 a) 1) b))) (exp.f64 a)): 4 points increase in error, 0 points decrease in error
      (*.f64 (/.f64 1 (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (exp.f64 a))) b)) (exp.f64 a)): 0 points increase in error, 4 points decrease in error
      (*.f64 (/.f64 1 (Rewrite<= associate-+r+_binary64 (+.f64 1 (+.f64 (exp.f64 a) b)))) (exp.f64 a)): 0 points increase in error, 4 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification1.0

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

Alternatives

Alternative 1
Error1.0
Cost26313
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0.9999998 \lor \neg \left(e^{b} \leq 1\right):\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{e^{a} + \left(1 + b\right)}\\ \end{array} \]
Alternative 2
Error1.0
Cost26185
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0.9999998 \lor \neg \left(e^{b} \leq 1\right):\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{1 + e^{a}}\\ \end{array} \]
Alternative 3
Error0.7
Cost19648
\[e^{a} \cdot \frac{1}{e^{a} + e^{b}} \]
Alternative 4
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 5
Error14.0
Cost6861
\[\begin{array}{l} \mathbf{if}\;a \leq -2.7 \cdot 10^{-8} \lor \neg \left(a \leq -1.1 \cdot 10^{-67}\right) \land a \leq -2.9 \cdot 10^{-100}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 6
Error0.9
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -360000000:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{1 + e^{b}}\\ \end{array} \]
Alternative 7
Error12.8
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -360:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 8
Error22.0
Cost452
\[\begin{array}{l} \mathbf{if}\;a \leq -0.1:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
Alternative 9
Error22.3
Cost196
\[\begin{array}{l} \mathbf{if}\;a \leq -36:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 10
Error39.0
Cost64
\[0.5 \]

Error

Reproduce

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