Average Error: 0.7 → 2.0
Time: 5.9s
Precision: binary64
Cost: 19912
\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 10^{+106}:\\ \;\;\;\;\frac{e^{a}}{a + \left(b + 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= (exp b) 0.0)
   (/ 1.0 (+ (exp b) 1.0))
   (if (<= (exp b) 1e+106)
     (/ (exp a) (+ a (+ b 2.0)))
     (+ (+ 1.0 (/ 1.0 (+ b 2.0))) -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(b) <= 0.0) {
		tmp = 1.0 / (exp(b) + 1.0);
	} else if (exp(b) <= 1e+106) {
		tmp = exp(a) / (a + (b + 2.0));
	} else {
		tmp = (1.0 + (1.0 / (b + 2.0))) + -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(b) <= 0.0d0) then
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    else if (exp(b) <= 1d+106) then
        tmp = exp(a) / (a + (b + 2.0d0))
    else
        tmp = (1.0d0 + (1.0d0 / (b + 2.0d0))) + (-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(b) <= 0.0) {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	} else if (Math.exp(b) <= 1e+106) {
		tmp = Math.exp(a) / (a + (b + 2.0));
	} else {
		tmp = (1.0 + (1.0 / (b + 2.0))) + -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(b) <= 0.0:
		tmp = 1.0 / (math.exp(b) + 1.0)
	elif math.exp(b) <= 1e+106:
		tmp = math.exp(a) / (a + (b + 2.0))
	else:
		tmp = (1.0 + (1.0 / (b + 2.0))) + -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(b) <= 0.0)
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	elseif (exp(b) <= 1e+106)
		tmp = Float64(exp(a) / Float64(a + Float64(b + 2.0)));
	else
		tmp = Float64(Float64(1.0 + Float64(1.0 / Float64(b + 2.0))) + -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(b) <= 0.0)
		tmp = 1.0 / (exp(b) + 1.0);
	elseif (exp(b) <= 1e+106)
		tmp = exp(a) / (a + (b + 2.0));
	else
		tmp = (1.0 + (1.0 / (b + 2.0))) + -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[b], $MachinePrecision], 0.0], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Exp[b], $MachinePrecision], 1e+106], N[(N[Exp[a], $MachinePrecision] / N[(a + N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 + N[(1.0 / N[(b + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -1.0), $MachinePrecision]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 0:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\

\mathbf{elif}\;e^{b} \leq 10^{+106}:\\
\;\;\;\;\frac{e^{a}}{a + \left(b + 2\right)}\\

\mathbf{else}:\\
\;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

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

Derivation

  1. Split input into 3 regimes
  2. if (exp.f64 b) < 0.0

    1. Initial program 1.8

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

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

    if 0.0 < (exp.f64 b) < 1.00000000000000009e106

    1. Initial program 0.5

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

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

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
      Proof
      (+.f64 (exp.f64 a) (+.f64 1 b)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (exp.f64 a) 1) b)): 1 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= +-commutative_binary64 (+.f64 1 (exp.f64 a))) b): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+r+_binary64 (+.f64 1 (+.f64 (exp.f64 a) b))): 0 points increase in error, 1 points decrease in error
    4. Taylor expanded in a around 0 2.0

      \[\leadsto \frac{e^{a}}{\color{blue}{2 + \left(a + b\right)}} \]
    5. Simplified2.0

      \[\leadsto \frac{e^{a}}{\color{blue}{2 + \left(b + a\right)}} \]
      Proof
      (+.f64 2 (+.f64 b a)): 0 points increase in error, 0 points decrease in error
      (+.f64 2 (Rewrite<= +-commutative_binary64 (+.f64 a b))): 0 points increase in error, 0 points decrease in error
    6. Applied egg-rr2.0

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

    if 1.00000000000000009e106 < (exp.f64 b)

    1. Initial program 0.3

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

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

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

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
      Proof
      (+.f64 b 2): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 2 b)): 0 points increase in error, 0 points decrease in error
    5. Applied egg-rr2.9

      \[\leadsto \color{blue}{\left(1 + \frac{1}{b + 2}\right) - 1} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification2.0

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

Alternatives

Alternative 1
Error2.0
Cost19912
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 0:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \mathbf{elif}\;e^{b} \leq 10^{+106}:\\ \;\;\;\;\frac{e^{a}}{2 + \left(a + b\right)}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 2
Error1.1
Cost19652
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0.999:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 3
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 4
Error13.1
Cost13124
\[\begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;\frac{e^{a}}{b}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 5
Error1.2
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -92000000000:\\ \;\;\;\;\frac{e^{a}}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 6
Error11.9
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 243.6817491012524:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 7
Error22.9
Cost708
\[\begin{array}{l} \mathbf{if}\;b \leq -5.3292848264969346 \cdot 10^{-108}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\left(1 + \frac{1}{b + 2}\right) + -1\\ \end{array} \]
Alternative 8
Error32.9
Cost452
\[\begin{array}{l} \mathbf{if}\;b \leq 0.01594305247736646:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
Alternative 9
Error33.1
Cost324
\[\begin{array}{l} \mathbf{if}\;b \leq 0.01594305247736646:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
Alternative 10
Error38.8
Cost64
\[0.5 \]

Error

Reproduce

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