?

Average Error: 0.7 → 1.0
Time: 6.9s
Precision: binary64
Cost: 32392

?

\[\frac{e^{a}}{e^{a} + e^{b}} \]
\[\begin{array}{l} \mathbf{if}\;e^{b} \leq 10^{-27}:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;e^{b} \leq 1.00000000005:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;e^{-\mathsf{log1p}\left(e^{b}\right)}\\ \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
(FPCore (a b)
 :precision binary64
 (if (<= (exp b) 1e-27)
   (+ (exp b) 1.0)
   (if (<= (exp b) 1.00000000005)
     (/ (exp a) (+ (exp a) 1.0))
     (exp (- (log1p (exp 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) <= 1e-27) {
		tmp = exp(b) + 1.0;
	} else if (exp(b) <= 1.00000000005) {
		tmp = exp(a) / (exp(a) + 1.0);
	} else {
		tmp = exp(-log1p(exp(b)));
	}
	return tmp;
}
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) <= 1e-27) {
		tmp = Math.exp(b) + 1.0;
	} else if (Math.exp(b) <= 1.00000000005) {
		tmp = Math.exp(a) / (Math.exp(a) + 1.0);
	} else {
		tmp = Math.exp(-Math.log1p(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 math.exp(b) <= 1e-27:
		tmp = math.exp(b) + 1.0
	elif math.exp(b) <= 1.00000000005:
		tmp = math.exp(a) / (math.exp(a) + 1.0)
	else:
		tmp = math.exp(-math.log1p(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 (exp(b) <= 1e-27)
		tmp = Float64(exp(b) + 1.0);
	elseif (exp(b) <= 1.00000000005)
		tmp = Float64(exp(a) / Float64(exp(a) + 1.0));
	else
		tmp = exp(Float64(-log1p(exp(b))));
	end
	return 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], 1e-27], N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision], If[LessEqual[N[Exp[b], $MachinePrecision], 1.00000000005], N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision], N[Exp[(-N[Log[1 + N[Exp[b], $MachinePrecision]], $MachinePrecision])], $MachinePrecision]]]
\frac{e^{a}}{e^{a} + e^{b}}
\begin{array}{l}
\mathbf{if}\;e^{b} \leq 10^{-27}:\\
\;\;\;\;e^{b} + 1\\

\mathbf{elif}\;e^{b} \leq 1.00000000005:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\

\mathbf{else}:\\
\;\;\;\;e^{-\mathsf{log1p}\left(e^{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 3 regimes
  2. if (exp.f64 b) < 1e-27

    1. Initial program 2.0

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

      \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
    3. Taylor expanded in a around 0 0.9

      \[\leadsto e^{\color{blue}{-1 \cdot \log \left(1 + e^{b}\right)}} \]
    4. Simplified0.9

      \[\leadsto e^{\color{blue}{-\mathsf{log1p}\left(e^{b}\right)}} \]
      Proof

      [Start]0.9

      \[ e^{-1 \cdot \log \left(1 + e^{b}\right)} \]

      mul-1-neg [=>]0.9

      \[ e^{\color{blue}{-\log \left(1 + e^{b}\right)}} \]

      log1p-def [=>]0.9

      \[ e^{-\color{blue}{\mathsf{log1p}\left(e^{b}\right)}} \]
    5. Applied egg-rr0.9

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

    if 1e-27 < (exp.f64 b) < 1.00000000005

    1. Initial program 0.4

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

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

    if 1.00000000005 < (exp.f64 b)

    1. Initial program 0.2

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

      \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
    3. Taylor expanded in a around 0 1.0

      \[\leadsto e^{\color{blue}{-1 \cdot \log \left(1 + e^{b}\right)}} \]
    4. Simplified1.0

      \[\leadsto e^{\color{blue}{-\mathsf{log1p}\left(e^{b}\right)}} \]
      Proof

      [Start]1.0

      \[ e^{-1 \cdot \log \left(1 + e^{b}\right)} \]

      mul-1-neg [=>]1.0

      \[ e^{\color{blue}{-\log \left(1 + e^{b}\right)}} \]

      log1p-def [=>]1.0

      \[ e^{-\color{blue}{\mathsf{log1p}\left(e^{b}\right)}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.0

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

Alternatives

Alternative 1
Error1.0
Cost26184
\[\begin{array}{l} t_0 := e^{b} + 1\\ \mathbf{if}\;e^{b} \leq 10^{-27}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;e^{b} \leq 1.00000000005:\\ \;\;\;\;\frac{e^{a}}{e^{a} + 1}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{t_0}\\ \end{array} \]
Alternative 2
Error0.6
Cost25920
\[e^{a - \log \left(e^{a} + e^{b}\right)} \]
Alternative 3
Error0.7
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 4
Error15.4
Cost7124
\[\begin{array}{l} t_0 := 0.5 + a \cdot 0.25\\ \mathbf{if}\;b \leq -0.28:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -5.4 \cdot 10^{-132}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -2.15 \cdot 10^{-192}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -3.4 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{-207}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(-1 + \frac{1}{b + 2}\right)\\ \end{array} \]
Alternative 5
Error15.0
Cost7124
\[\begin{array}{l} t_0 := 0.5 + a \cdot 0.25\\ \mathbf{if}\;b \leq -0.29:\\ \;\;\;\;e^{b} + 1\\ \mathbf{elif}\;b \leq -3.9 \cdot 10^{-129}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-192}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -3.5 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{-207}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;1 + \left(-1 + \frac{1}{b + 2}\right)\\ \end{array} \]
Alternative 6
Error1.1
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -7300000000:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 7
Error24.0
Cost980
\[\begin{array}{l} \mathbf{if}\;b \leq -3.6 \cdot 10^{-132}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -5 \cdot 10^{-158}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{-273}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{-207}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.032:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 8
Error25.1
Cost980
\[\begin{array}{l} t_0 := 0.5 + a \cdot 0.25\\ \mathbf{if}\;b \leq -3.6 \cdot 10^{-132}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -1.72 \cdot 10^{-192}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq -3.4 \cdot 10^{-301}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq 1.12 \cdot 10^{-207}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 0.112:\\ \;\;\;\;0.5 + b \cdot -0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 9
Error24.4
Cost724
\[\begin{array}{l} \mathbf{if}\;b \leq -2.05 \cdot 10^{-131}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq -1.35 \cdot 10^{-159}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 3.55 \cdot 10^{-273}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 2 \cdot 10^{-207}:\\ \;\;\;\;0\\ \mathbf{elif}\;b \leq 9.5 \cdot 10^{-24}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 10
Error13.3
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -1.45 \cdot 10^{-8}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;1 + \left(-1 + \frac{1}{b + 2}\right)\\ \end{array} \]
Alternative 11
Error39.0
Cost64
\[0.5 \]

Error

Reproduce?

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