?

Average Error: 1.02% → 1.4%
Time: 8.8s
Precision: binary64
Cost: 6980

?

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original1.02%
Target0.02%
Herbie1.4%
\[\frac{1}{1 + e^{b - a}} \]

Derivation?

  1. Split input into 2 regimes
  2. if a < -13000

    1. Initial program 1.14

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + b}} \]
    4. Simplified96.07

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

      [Start]96.07

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

      +-commutative [=>]96.07

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

      \[\leadsto \color{blue}{\left(1 + \frac{1}{b + 2}\right) - 1} \]
    6. Simplified66.58

      \[\leadsto \color{blue}{1 + \left(\frac{1}{b + 2} - 1\right)} \]
      Proof

      [Start]66.58

      \[ \left(1 + \frac{1}{b + 2}\right) - 1 \]

      associate--l+ [=>]66.58

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

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

    if -13000 < a

    1. Initial program 0.98

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
    3. Applied egg-rr1.7

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

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

      [Start]1.7

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

      sub-neg [=>]1.7

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

      associate-+r+ [=>]1.7

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

      metadata-eval [=>]1.7

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

      metadata-eval [=>]1.7

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

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

Alternatives

Alternative 1
Error1.1%
Cost32448
\[\frac{e^{a}}{{\left({\left(e^{a} + e^{b}\right)}^{3}\right)}^{0.3333333333333333}} \]
Alternative 2
Error1.02%
Cost19520
\[\frac{e^{a}}{e^{a} + e^{b}} \]
Alternative 3
Error1.39%
Cost6852
\[\begin{array}{l} \mathbf{if}\;a \leq -13000:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
Alternative 4
Error17.22%
Cost6724
\[\begin{array}{l} \mathbf{if}\;b \leq 340:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 5
Error36.75%
Cost717
\[\begin{array}{l} \mathbf{if}\;a \leq -0.000108:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -1.06 \cdot 10^{-150} \lor \neg \left(a \leq -1.75 \cdot 10^{-218}\right):\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]
Alternative 6
Error20.38%
Cost708
\[\begin{array}{l} \mathbf{if}\;a \leq -7.5 \cdot 10^{-5}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;1 + \left(-1 + \frac{1}{b + 2}\right)\\ \end{array} \]
Alternative 7
Error37.11%
Cost460
\[\begin{array}{l} \mathbf{if}\;a \leq -8 \cdot 10^{-5}:\\ \;\;\;\;0\\ \mathbf{elif}\;a \leq -4 \cdot 10^{-151}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;a \leq -2.15 \cdot 10^{-218}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;0.5\\ \end{array} \]
Alternative 8
Error60.57%
Cost64
\[0.5 \]

Error

Reproduce?

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