Quotient of sum of exps

Percentage Accurate: 99.1% → 97.8%
Time: 5.9s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
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
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
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
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}

Alternative 1: 97.8% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -4 \cdot 10^{+18}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a -4e+18) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	double tmp;
	if (a <= -4e+18) {
		tmp = exp(a);
	} else {
		tmp = 1.0 / (exp(b) + 1.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (a <= (-4d+18)) then
        tmp = exp(a)
    else
        tmp = 1.0d0 / (exp(b) + 1.0d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (a <= -4e+18) {
		tmp = Math.exp(a);
	} else {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if a <= -4e+18:
		tmp = math.exp(a)
	else:
		tmp = 1.0 / (math.exp(b) + 1.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (a <= -4e+18)
		tmp = exp(a);
	else
		tmp = Float64(1.0 / Float64(exp(b) + 1.0));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -4e+18)
		tmp = exp(a);
	else
		tmp = 1.0 / (exp(b) + 1.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[a, -4e+18], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -4 \cdot 10^{+18}:\\
\;\;\;\;e^{a}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{e^{b} + 1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -4e18

    1. Initial program 100.0%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Step-by-step derivation
      1. add-cbrt-cube100.0%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}}} \]
      2. pow1/3100.0%

        \[\leadsto \color{blue}{{\left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right)}^{0.3333333333333333}} \]
      3. pow-to-exp100.0%

        \[\leadsto \color{blue}{e^{\log \left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot 0.3333333333333333}} \]
      4. pow3100.0%

        \[\leadsto e^{\log \color{blue}{\left({\left(\frac{e^{a}}{e^{a} + e^{b}}\right)}^{3}\right)} \cdot 0.3333333333333333} \]
      5. log-pow100.0%

        \[\leadsto e^{\color{blue}{\left(3 \cdot \log \left(\frac{e^{a}}{e^{a} + e^{b}}\right)\right)} \cdot 0.3333333333333333} \]
      6. log-div100.0%

        \[\leadsto e^{\left(3 \cdot \color{blue}{\left(\log \left(e^{a}\right) - \log \left(e^{a} + e^{b}\right)\right)}\right) \cdot 0.3333333333333333} \]
      7. add-log-exp100.0%

        \[\leadsto e^{\left(3 \cdot \left(\color{blue}{a} - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333} \]
    3. Applied egg-rr100.0%

      \[\leadsto \color{blue}{e^{\left(3 \cdot \left(a - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333}} \]
    4. Taylor expanded in a around inf 100.0%

      \[\leadsto e^{\color{blue}{a}} \]

    if -4e18 < a

    1. Initial program 98.4%

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

      \[\leadsto \color{blue}{\frac{1}{1 + e^{b}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -4 \cdot 10^{+18}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]

Alternative 2: 99.3% accurate, 0.8× speedup?

\[\begin{array}{l} \\ e^{a - \log \left(e^{a} + e^{b}\right)} \end{array} \]
(FPCore (a b) :precision binary64 (exp (- a (log (+ (exp a) (exp b))))))
double code(double a, double b) {
	return exp((a - log((exp(a) + exp(b)))));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = exp((a - log((exp(a) + exp(b)))))
end function
public static double code(double a, double b) {
	return Math.exp((a - Math.log((Math.exp(a) + Math.exp(b)))));
}
def code(a, b):
	return math.exp((a - math.log((math.exp(a) + math.exp(b)))))
function code(a, b)
	return exp(Float64(a - log(Float64(exp(a) + exp(b)))))
end
function tmp = code(a, b)
	tmp = exp((a - log((exp(a) + exp(b)))));
end
code[a_, b_] := N[Exp[N[(a - N[Log[N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
e^{a - \log \left(e^{a} + e^{b}\right)}
\end{array}
Derivation
  1. Initial program 98.8%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Step-by-step derivation
    1. add-exp-log98.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{\log \left(e^{a} + e^{b}\right)}}} \]
    2. div-exp98.9%

      \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
  3. Applied egg-rr98.9%

    \[\leadsto \color{blue}{e^{a - \log \left(e^{a} + e^{b}\right)}} \]
  4. Final simplification98.9%

    \[\leadsto e^{a - \log \left(e^{a} + e^{b}\right)} \]

Alternative 3: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{e^{a}}{e^{a} + e^{b}} \end{array} \]
(FPCore (a b) :precision binary64 (/ (exp a) (+ (exp a) (exp b))))
double code(double a, double b) {
	return exp(a) / (exp(a) + exp(b));
}
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
public static double code(double a, double b) {
	return Math.exp(a) / (Math.exp(a) + Math.exp(b));
}
def code(a, b):
	return math.exp(a) / (math.exp(a) + math.exp(b))
function code(a, b)
	return Float64(exp(a) / Float64(exp(a) + exp(b)))
end
function tmp = code(a, b)
	tmp = exp(a) / (exp(a) + exp(b));
end
code[a_, b_] := N[(N[Exp[a], $MachinePrecision] / N[(N[Exp[a], $MachinePrecision] + N[Exp[b], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{e^{a}}{e^{a} + e^{b}}
\end{array}
Derivation
  1. Initial program 98.8%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Final simplification98.8%

    \[\leadsto \frac{e^{a}}{e^{a} + e^{b}} \]

Alternative 4: 78.2% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 + a \cdot 0.25\\ \mathbf{if}\;b \leq -2.15 \cdot 10^{-7}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -1.9 \cdot 10^{-143}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-188}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-164}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 3.1 \cdot 10^{-146}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-22}:\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (+ 0.5 (* a 0.25))))
   (if (<= b -2.15e-7)
     (exp a)
     (if (<= b -1.9e-143)
       t_0
       (if (<= b -1.6e-188)
         (exp a)
         (if (<= b 9e-164)
           0.5
           (if (<= b 3.1e-146) (exp a) (if (<= b 2.3e-22) t_0 0.0))))))))
double code(double a, double b) {
	double t_0 = 0.5 + (a * 0.25);
	double tmp;
	if (b <= -2.15e-7) {
		tmp = exp(a);
	} else if (b <= -1.9e-143) {
		tmp = t_0;
	} else if (b <= -1.6e-188) {
		tmp = exp(a);
	} else if (b <= 9e-164) {
		tmp = 0.5;
	} else if (b <= 3.1e-146) {
		tmp = exp(a);
	} else if (b <= 2.3e-22) {
		tmp = t_0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
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 = 0.5d0 + (a * 0.25d0)
    if (b <= (-2.15d-7)) then
        tmp = exp(a)
    else if (b <= (-1.9d-143)) then
        tmp = t_0
    else if (b <= (-1.6d-188)) then
        tmp = exp(a)
    else if (b <= 9d-164) then
        tmp = 0.5d0
    else if (b <= 3.1d-146) then
        tmp = exp(a)
    else if (b <= 2.3d-22) then
        tmp = t_0
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double t_0 = 0.5 + (a * 0.25);
	double tmp;
	if (b <= -2.15e-7) {
		tmp = Math.exp(a);
	} else if (b <= -1.9e-143) {
		tmp = t_0;
	} else if (b <= -1.6e-188) {
		tmp = Math.exp(a);
	} else if (b <= 9e-164) {
		tmp = 0.5;
	} else if (b <= 3.1e-146) {
		tmp = Math.exp(a);
	} else if (b <= 2.3e-22) {
		tmp = t_0;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(a, b):
	t_0 = 0.5 + (a * 0.25)
	tmp = 0
	if b <= -2.15e-7:
		tmp = math.exp(a)
	elif b <= -1.9e-143:
		tmp = t_0
	elif b <= -1.6e-188:
		tmp = math.exp(a)
	elif b <= 9e-164:
		tmp = 0.5
	elif b <= 3.1e-146:
		tmp = math.exp(a)
	elif b <= 2.3e-22:
		tmp = t_0
	else:
		tmp = 0.0
	return tmp
function code(a, b)
	t_0 = Float64(0.5 + Float64(a * 0.25))
	tmp = 0.0
	if (b <= -2.15e-7)
		tmp = exp(a);
	elseif (b <= -1.9e-143)
		tmp = t_0;
	elseif (b <= -1.6e-188)
		tmp = exp(a);
	elseif (b <= 9e-164)
		tmp = 0.5;
	elseif (b <= 3.1e-146)
		tmp = exp(a);
	elseif (b <= 2.3e-22)
		tmp = t_0;
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(a, b)
	t_0 = 0.5 + (a * 0.25);
	tmp = 0.0;
	if (b <= -2.15e-7)
		tmp = exp(a);
	elseif (b <= -1.9e-143)
		tmp = t_0;
	elseif (b <= -1.6e-188)
		tmp = exp(a);
	elseif (b <= 9e-164)
		tmp = 0.5;
	elseif (b <= 3.1e-146)
		tmp = exp(a);
	elseif (b <= 2.3e-22)
		tmp = t_0;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[a_, b_] := Block[{t$95$0 = N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.15e-7], N[Exp[a], $MachinePrecision], If[LessEqual[b, -1.9e-143], t$95$0, If[LessEqual[b, -1.6e-188], N[Exp[a], $MachinePrecision], If[LessEqual[b, 9e-164], 0.5, If[LessEqual[b, 3.1e-146], N[Exp[a], $MachinePrecision], If[LessEqual[b, 2.3e-22], t$95$0, 0.0]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 + a \cdot 0.25\\
\mathbf{if}\;b \leq -2.15 \cdot 10^{-7}:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;b \leq -1.9 \cdot 10^{-143}:\\
\;\;\;\;t_0\\

\mathbf{elif}\;b \leq -1.6 \cdot 10^{-188}:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;b \leq 9 \cdot 10^{-164}:\\
\;\;\;\;0.5\\

\mathbf{elif}\;b \leq 3.1 \cdot 10^{-146}:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;b \leq 2.3 \cdot 10^{-22}:\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;0\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if b < -2.1500000000000001e-7 or -1.89999999999999991e-143 < b < -1.60000000000000011e-188 or 8.9999999999999995e-164 < b < 3.0999999999999998e-146

    1. Initial program 97.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Step-by-step derivation
      1. add-cbrt-cube97.3%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}}} \]
      2. pow1/397.4%

        \[\leadsto \color{blue}{{\left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right)}^{0.3333333333333333}} \]
      3. pow-to-exp97.3%

        \[\leadsto \color{blue}{e^{\log \left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot 0.3333333333333333}} \]
      4. pow397.3%

        \[\leadsto e^{\log \color{blue}{\left({\left(\frac{e^{a}}{e^{a} + e^{b}}\right)}^{3}\right)} \cdot 0.3333333333333333} \]
      5. log-pow97.3%

        \[\leadsto e^{\color{blue}{\left(3 \cdot \log \left(\frac{e^{a}}{e^{a} + e^{b}}\right)\right)} \cdot 0.3333333333333333} \]
      6. log-div97.3%

        \[\leadsto e^{\left(3 \cdot \color{blue}{\left(\log \left(e^{a}\right) - \log \left(e^{a} + e^{b}\right)\right)}\right) \cdot 0.3333333333333333} \]
      7. add-log-exp97.4%

        \[\leadsto e^{\left(3 \cdot \left(\color{blue}{a} - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333} \]
    3. Applied egg-rr97.4%

      \[\leadsto \color{blue}{e^{\left(3 \cdot \left(a - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333}} \]
    4. Taylor expanded in a around inf 91.4%

      \[\leadsto e^{\color{blue}{a}} \]

    if -2.1500000000000001e-7 < b < -1.89999999999999991e-143 or 3.0999999999999998e-146 < b < 2.2999999999999998e-22

    1. Initial program 98.1%

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

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

      \[\leadsto \color{blue}{0.5 + 0.25 \cdot a} \]
    4. Step-by-step derivation
      1. *-commutative80.4%

        \[\leadsto 0.5 + \color{blue}{a \cdot 0.25} \]
    5. Simplified80.4%

      \[\leadsto \color{blue}{0.5 + a \cdot 0.25} \]

    if -1.60000000000000011e-188 < b < 8.9999999999999995e-164

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.5} \]

    if 2.2999999999999998e-22 < b

    1. Initial program 100.0%

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + b}} \]
    4. Step-by-step derivation
      1. +-commutative6.9%

        \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    5. Simplified6.9%

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    6. Step-by-step derivation
      1. add-log-exp86.5%

        \[\leadsto \color{blue}{\log \left(e^{\frac{1}{b + 2}}\right)} \]
    7. Applied egg-rr86.5%

      \[\leadsto \color{blue}{\log \left(e^{\frac{1}{b + 2}}\right)} \]
    8. Taylor expanded in b around inf 97.2%

      \[\leadsto \log \color{blue}{1} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification86.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2.15 \cdot 10^{-7}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq -1.9 \cdot 10^{-143}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq -1.6 \cdot 10^{-188}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 9 \cdot 10^{-164}:\\ \;\;\;\;0.5\\ \mathbf{elif}\;b \leq 3.1 \cdot 10^{-146}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 2.3 \cdot 10^{-22}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 5: 66.6% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -9.2 \cdot 10^{-32}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{-180}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\ \mathbf{elif}\;a \leq 5.8 \cdot 10^{-125}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq 4.3 \cdot 10^{-95}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;e^{a}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= a -9.2e-32)
   (exp a)
   (if (<= a 1.7e-180)
     (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))
     (if (<= a 5.8e-125) (exp a) (if (<= a 4.3e-95) 0.5 (exp a))))))
double code(double a, double b) {
	double tmp;
	if (a <= -9.2e-32) {
		tmp = exp(a);
	} else if (a <= 1.7e-180) {
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	} else if (a <= 5.8e-125) {
		tmp = exp(a);
	} else if (a <= 4.3e-95) {
		tmp = 0.5;
	} else {
		tmp = exp(a);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (a <= (-9.2d-32)) then
        tmp = exp(a)
    else if (a <= 1.7d-180) then
        tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
    else if (a <= 5.8d-125) then
        tmp = exp(a)
    else if (a <= 4.3d-95) then
        tmp = 0.5d0
    else
        tmp = exp(a)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (a <= -9.2e-32) {
		tmp = Math.exp(a);
	} else if (a <= 1.7e-180) {
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	} else if (a <= 5.8e-125) {
		tmp = Math.exp(a);
	} else if (a <= 4.3e-95) {
		tmp = 0.5;
	} else {
		tmp = Math.exp(a);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if a <= -9.2e-32:
		tmp = math.exp(a)
	elif a <= 1.7e-180:
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)))
	elif a <= 5.8e-125:
		tmp = math.exp(a)
	elif a <= 4.3e-95:
		tmp = 0.5
	else:
		tmp = math.exp(a)
	return tmp
function code(a, b)
	tmp = 0.0
	if (a <= -9.2e-32)
		tmp = exp(a);
	elseif (a <= 1.7e-180)
		tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b))));
	elseif (a <= 5.8e-125)
		tmp = exp(a);
	elseif (a <= 4.3e-95)
		tmp = 0.5;
	else
		tmp = exp(a);
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (a <= -9.2e-32)
		tmp = exp(a);
	elseif (a <= 1.7e-180)
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	elseif (a <= 5.8e-125)
		tmp = exp(a);
	elseif (a <= 4.3e-95)
		tmp = 0.5;
	else
		tmp = exp(a);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[a, -9.2e-32], N[Exp[a], $MachinePrecision], If[LessEqual[a, 1.7e-180], N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[a, 5.8e-125], N[Exp[a], $MachinePrecision], If[LessEqual[a, 4.3e-95], 0.5, N[Exp[a], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -9.2 \cdot 10^{-32}:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;a \leq 1.7 \cdot 10^{-180}:\\
\;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\

\mathbf{elif}\;a \leq 5.8 \cdot 10^{-125}:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;a \leq 4.3 \cdot 10^{-95}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;e^{a}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a < -9.2000000000000002e-32 or 1.69999999999999991e-180 < a < 5.8000000000000004e-125 or 4.29999999999999997e-95 < a

    1. Initial program 97.5%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Step-by-step derivation
      1. add-cbrt-cube97.3%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}}} \]
      2. pow1/397.5%

        \[\leadsto \color{blue}{{\left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right)}^{0.3333333333333333}} \]
      3. pow-to-exp97.3%

        \[\leadsto \color{blue}{e^{\log \left(\left(\frac{e^{a}}{e^{a} + e^{b}} \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot \frac{e^{a}}{e^{a} + e^{b}}\right) \cdot 0.3333333333333333}} \]
      4. pow397.3%

        \[\leadsto e^{\log \color{blue}{\left({\left(\frac{e^{a}}{e^{a} + e^{b}}\right)}^{3}\right)} \cdot 0.3333333333333333} \]
      5. log-pow97.3%

        \[\leadsto e^{\color{blue}{\left(3 \cdot \log \left(\frac{e^{a}}{e^{a} + e^{b}}\right)\right)} \cdot 0.3333333333333333} \]
      6. log-div97.3%

        \[\leadsto e^{\left(3 \cdot \color{blue}{\left(\log \left(e^{a}\right) - \log \left(e^{a} + e^{b}\right)\right)}\right) \cdot 0.3333333333333333} \]
      7. add-log-exp97.4%

        \[\leadsto e^{\left(3 \cdot \left(\color{blue}{a} - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333} \]
    3. Applied egg-rr97.4%

      \[\leadsto \color{blue}{e^{\left(3 \cdot \left(a - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 0.3333333333333333}} \]
    4. Taylor expanded in a around inf 82.4%

      \[\leadsto e^{\color{blue}{a}} \]

    if -9.2000000000000002e-32 < a < 1.69999999999999991e-180

    1. Initial program 100.0%

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(b + 0.5 \cdot {b}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+68.9%

        \[\leadsto \frac{1}{\color{blue}{\left(2 + b\right) + 0.5 \cdot {b}^{2}}} \]
      2. +-commutative68.9%

        \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right)} + 0.5 \cdot {b}^{2}} \]
      3. unpow268.9%

        \[\leadsto \frac{1}{\left(b + 2\right) + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}} \]
    5. Simplified68.9%

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

    if 5.8000000000000004e-125 < a < 4.29999999999999997e-95

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{0.5} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -9.2 \cdot 10^{-32}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq 1.7 \cdot 10^{-180}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\ \mathbf{elif}\;a \leq 5.8 \cdot 10^{-125}:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;a \leq 4.3 \cdot 10^{-95}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;e^{a}\\ \end{array} \]

Alternative 6: 53.9% accurate, 23.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b -2.0) 0.5 (/ 1.0 (+ (+ b 2.0) (* 0.5 (* b b))))))
double code(double a, double b) {
	double tmp;
	if (b <= -2.0) {
		tmp = 0.5;
	} else {
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= (-2.0d0)) then
        tmp = 0.5d0
    else
        tmp = 1.0d0 / ((b + 2.0d0) + (0.5d0 * (b * b)))
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= -2.0) {
		tmp = 0.5;
	} else {
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= -2.0:
		tmp = 0.5
	else:
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)))
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= -2.0)
		tmp = 0.5;
	else
		tmp = Float64(1.0 / Float64(Float64(b + 2.0) + Float64(0.5 * Float64(b * b))));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= -2.0)
		tmp = 0.5;
	else
		tmp = 1.0 / ((b + 2.0) + (0.5 * (b * b)));
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, -2.0], 0.5, N[(1.0 / N[(N[(b + 2.0), $MachinePrecision] + N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -2:\\
\;\;\;\;0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < -2

    1. Initial program 96.7%

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

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

      \[\leadsto \color{blue}{0.5} \]

    if -2 < b

    1. Initial program 99.5%

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(b + 0.5 \cdot {b}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+62.9%

        \[\leadsto \frac{1}{\color{blue}{\left(2 + b\right) + 0.5 \cdot {b}^{2}}} \]
      2. +-commutative62.9%

        \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right)} + 0.5 \cdot {b}^{2}} \]
      3. unpow262.9%

        \[\leadsto \frac{1}{\left(b + 2\right) + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}} \]
    5. Simplified62.9%

      \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}\\ \end{array} \]

Alternative 7: 53.4% accurate, 27.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 1.25:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{b + b \cdot \left(b \cdot 0.5\right)}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 1.25) 0.5 (/ 1.0 (+ b (* b (* b 0.5))))))
double code(double a, double b) {
	double tmp;
	if (b <= 1.25) {
		tmp = 0.5;
	} else {
		tmp = 1.0 / (b + (b * (b * 0.5)));
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 1.25d0) then
        tmp = 0.5d0
    else
        tmp = 1.0d0 / (b + (b * (b * 0.5d0)))
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 1.25) {
		tmp = 0.5;
	} else {
		tmp = 1.0 / (b + (b * (b * 0.5)));
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 1.25:
		tmp = 0.5
	else:
		tmp = 1.0 / (b + (b * (b * 0.5)))
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 1.25)
		tmp = 0.5;
	else
		tmp = Float64(1.0 / Float64(b + Float64(b * Float64(b * 0.5))));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 1.25)
		tmp = 0.5;
	else
		tmp = 1.0 / (b + (b * (b * 0.5)));
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 1.25], 0.5, N[(1.0 / N[(b + N[(b * N[(b * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.25:\\
\;\;\;\;0.5\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 1.25

    1. Initial program 98.4%

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

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

      \[\leadsto \color{blue}{0.5} \]

    if 1.25 < b

    1. Initial program 100.0%

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(b + 0.5 \cdot {b}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+55.1%

        \[\leadsto \frac{1}{\color{blue}{\left(2 + b\right) + 0.5 \cdot {b}^{2}}} \]
      2. +-commutative55.1%

        \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right)} + 0.5 \cdot {b}^{2}} \]
      3. unpow255.1%

        \[\leadsto \frac{1}{\left(b + 2\right) + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}} \]
    5. Simplified55.1%

      \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}} \]
    6. Taylor expanded in b around inf 55.1%

      \[\leadsto \frac{1}{\color{blue}{b + 0.5 \cdot {b}^{2}}} \]
    7. Step-by-step derivation
      1. unpow255.1%

        \[\leadsto \frac{1}{b + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}} \]
      2. *-commutative55.1%

        \[\leadsto \frac{1}{b + \color{blue}{\left(b \cdot b\right) \cdot 0.5}} \]
      3. associate-*r*55.1%

        \[\leadsto \frac{1}{b + \color{blue}{b \cdot \left(b \cdot 0.5\right)}} \]
    8. Simplified55.1%

      \[\leadsto \frac{1}{\color{blue}{b + b \cdot \left(b \cdot 0.5\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 1.25:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{b + b \cdot \left(b \cdot 0.5\right)}\\ \end{array} \]

Alternative 8: 53.4% accurate, 43.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \end{array} \]
(FPCore (a b) :precision binary64 (if (<= b 2.0) 0.5 (/ 2.0 (* b b))))
double code(double a, double b) {
	double tmp;
	if (b <= 2.0) {
		tmp = 0.5;
	} else {
		tmp = 2.0 / (b * b);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= 2.0d0) then
        tmp = 0.5d0
    else
        tmp = 2.0d0 / (b * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 2.0) {
		tmp = 0.5;
	} else {
		tmp = 2.0 / (b * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 2.0:
		tmp = 0.5
	else:
		tmp = 2.0 / (b * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 2.0)
		tmp = 0.5;
	else
		tmp = Float64(2.0 / Float64(b * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 2.0)
		tmp = 0.5;
	else
		tmp = 2.0 / (b * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 2.0], 0.5, N[(2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 2:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{2}{b \cdot b}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if b < 2

    1. Initial program 98.4%

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

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

      \[\leadsto \color{blue}{0.5} \]

    if 2 < b

    1. Initial program 100.0%

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

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

      \[\leadsto \frac{1}{\color{blue}{2 + \left(b + 0.5 \cdot {b}^{2}\right)}} \]
    4. Step-by-step derivation
      1. associate-+r+55.1%

        \[\leadsto \frac{1}{\color{blue}{\left(2 + b\right) + 0.5 \cdot {b}^{2}}} \]
      2. +-commutative55.1%

        \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right)} + 0.5 \cdot {b}^{2}} \]
      3. unpow255.1%

        \[\leadsto \frac{1}{\left(b + 2\right) + 0.5 \cdot \color{blue}{\left(b \cdot b\right)}} \]
    5. Simplified55.1%

      \[\leadsto \frac{1}{\color{blue}{\left(b + 2\right) + 0.5 \cdot \left(b \cdot b\right)}} \]
    6. Taylor expanded in b around inf 55.1%

      \[\leadsto \color{blue}{\frac{2}{{b}^{2}}} \]
    7. Step-by-step derivation
      1. unpow255.1%

        \[\leadsto \frac{2}{\color{blue}{b \cdot b}} \]
    8. Simplified55.1%

      \[\leadsto \color{blue}{\frac{2}{b \cdot b}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 2:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{2}{b \cdot b}\\ \end{array} \]

Alternative 9: 39.6% accurate, 305.0× speedup?

\[\begin{array}{l} \\ 0.5 \end{array} \]
(FPCore (a b) :precision binary64 0.5)
double code(double a, double b) {
	return 0.5;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = 0.5d0
end function
public static double code(double a, double b) {
	return 0.5;
}
def code(a, b):
	return 0.5
function code(a, b)
	return 0.5
end
function tmp = code(a, b)
	tmp = 0.5;
end
code[a_, b_] := 0.5
\begin{array}{l}

\\
0.5
\end{array}
Derivation
  1. Initial program 98.8%

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

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

    \[\leadsto \color{blue}{0.5} \]
  4. Final simplification39.6%

    \[\leadsto 0.5 \]

Developer target: 100.0% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \frac{1}{1 + e^{b - a}} \end{array} \]
(FPCore (a b) :precision binary64 (/ 1.0 (+ 1.0 (exp (- b a)))))
double code(double a, double b) {
	return 1.0 / (1.0 + exp((b - a)));
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = 1.0d0 / (1.0d0 + exp((b - a)))
end function
public static double code(double a, double b) {
	return 1.0 / (1.0 + Math.exp((b - a)));
}
def code(a, b):
	return 1.0 / (1.0 + math.exp((b - a)))
function code(a, b)
	return Float64(1.0 / Float64(1.0 + exp(Float64(b - a))))
end
function tmp = code(a, b)
	tmp = 1.0 / (1.0 + exp((b - a)));
end
code[a_, b_] := N[(1.0 / N[(1.0 + N[Exp[N[(b - a), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{1 + e^{b - a}}
\end{array}

Reproduce

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