Quotient of sum of exps

Percentage Accurate: 99.1% → 99.1%
Time: 6.7s
Alternatives: 7
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 7 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: 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 99.6%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Final simplification99.6%

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

Alternative 2: 98.5% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 10^{-206}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 1e-206) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 1e-206) {
		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 (exp(a) <= 1d-206) 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 (Math.exp(a) <= 1e-206) {
		tmp = Math.exp(a);
	} else {
		tmp = 1.0 / (Math.exp(b) + 1.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if math.exp(a) <= 1e-206:
		tmp = math.exp(a)
	else:
		tmp = 1.0 / (math.exp(b) + 1.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (exp(a) <= 1e-206)
		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 (exp(a) <= 1e-206)
		tmp = exp(a);
	else
		tmp = 1.0 / (exp(b) + 1.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[N[Exp[a], $MachinePrecision], 1e-206], N[Exp[a], $MachinePrecision], N[(1.0 / N[(N[Exp[b], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (exp.f64 a) < 1.00000000000000003e-206

    1. Initial program 100.0%

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

        \[\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/398.7%

        \[\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-exp98.7%

        \[\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. pow398.7%

        \[\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 1.00000000000000003e-206 < (exp.f64 a)

    1. Initial program 99.4%

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

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

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

Alternative 3: 82.0% accurate, 2.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq -1.1:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 2500 \lor \neg \left(b \leq 1.45 \cdot 10^{+118}\right) \land b \leq 3 \cdot 10^{+202}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b -1.1)
   (exp a)
   (if (or (<= b 2500.0) (and (not (<= b 1.45e+118)) (<= b 3e+202)))
     (/ (exp a) 2.0)
     (* -0.020833333333333332 (pow a 3.0)))))
double code(double a, double b) {
	double tmp;
	if (b <= -1.1) {
		tmp = exp(a);
	} else if ((b <= 2500.0) || (!(b <= 1.45e+118) && (b <= 3e+202))) {
		tmp = exp(a) / 2.0;
	} else {
		tmp = -0.020833333333333332 * pow(a, 3.0);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if (b <= (-1.1d0)) then
        tmp = exp(a)
    else if ((b <= 2500.0d0) .or. (.not. (b <= 1.45d+118)) .and. (b <= 3d+202)) then
        tmp = exp(a) / 2.0d0
    else
        tmp = (-0.020833333333333332d0) * (a ** 3.0d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= -1.1) {
		tmp = Math.exp(a);
	} else if ((b <= 2500.0) || (!(b <= 1.45e+118) && (b <= 3e+202))) {
		tmp = Math.exp(a) / 2.0;
	} else {
		tmp = -0.020833333333333332 * Math.pow(a, 3.0);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= -1.1:
		tmp = math.exp(a)
	elif (b <= 2500.0) or (not (b <= 1.45e+118) and (b <= 3e+202)):
		tmp = math.exp(a) / 2.0
	else:
		tmp = -0.020833333333333332 * math.pow(a, 3.0)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= -1.1)
		tmp = exp(a);
	elseif ((b <= 2500.0) || (!(b <= 1.45e+118) && (b <= 3e+202)))
		tmp = Float64(exp(a) / 2.0);
	else
		tmp = Float64(-0.020833333333333332 * (a ^ 3.0));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= -1.1)
		tmp = exp(a);
	elseif ((b <= 2500.0) || (~((b <= 1.45e+118)) && (b <= 3e+202)))
		tmp = exp(a) / 2.0;
	else
		tmp = -0.020833333333333332 * (a ^ 3.0);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, -1.1], N[Exp[a], $MachinePrecision], If[Or[LessEqual[b, 2500.0], And[N[Not[LessEqual[b, 1.45e+118]], $MachinePrecision], LessEqual[b, 3e+202]]], N[(N[Exp[a], $MachinePrecision] / 2.0), $MachinePrecision], N[(-0.020833333333333332 * N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1:\\
\;\;\;\;e^{a}\\

\mathbf{elif}\;b \leq 2500 \lor \neg \left(b \leq 1.45 \cdot 10^{+118}\right) \land b \leq 3 \cdot 10^{+202}:\\
\;\;\;\;\frac{e^{a}}{2}\\

\mathbf{else}:\\
\;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\


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

    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 95.9%

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

    if -1.1000000000000001 < b < 2500 or 1.45000000000000008e118 < b < 3.0000000000000001e202

    1. Initial program 99.3%

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

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

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

    if 2500 < b < 1.45000000000000008e118 or 3.0000000000000001e202 < b

    1. Initial program 100.0%

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

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

      \[\leadsto \color{blue}{-0.020833333333333332 \cdot {a}^{3} + \left(0.5 + 0.25 \cdot a\right)} \]
    4. Taylor expanded in a around inf 55.4%

      \[\leadsto \color{blue}{-0.020833333333333332 \cdot {a}^{3}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification85.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.1:\\ \;\;\;\;e^{a}\\ \mathbf{elif}\;b \leq 2500 \lor \neg \left(b \leq 1.45 \cdot 10^{+118}\right) \land b \leq 3 \cdot 10^{+202}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \mathbf{else}:\\ \;\;\;\;-0.020833333333333332 \cdot {a}^{3}\\ \end{array} \]

Alternative 4: 63.8% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a \leq -5.2 \cdot 10^{-12} \lor \neg \left(a \leq -2.45 \cdot 10^{-30}\right) \land a \leq -6.5 \cdot 10^{-81}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (or (<= a -5.2e-12) (and (not (<= a -2.45e-30)) (<= a -6.5e-81)))
   (exp a)
   (+ 0.5 (* a 0.25))))
double code(double a, double b) {
	double tmp;
	if ((a <= -5.2e-12) || (!(a <= -2.45e-30) && (a <= -6.5e-81))) {
		tmp = exp(a);
	} else {
		tmp = 0.5 + (a * 0.25);
	}
	return tmp;
}
real(8) function code(a, b)
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: tmp
    if ((a <= (-5.2d-12)) .or. (.not. (a <= (-2.45d-30))) .and. (a <= (-6.5d-81))) then
        tmp = exp(a)
    else
        tmp = 0.5d0 + (a * 0.25d0)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if ((a <= -5.2e-12) || (!(a <= -2.45e-30) && (a <= -6.5e-81))) {
		tmp = Math.exp(a);
	} else {
		tmp = 0.5 + (a * 0.25);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if (a <= -5.2e-12) or (not (a <= -2.45e-30) and (a <= -6.5e-81)):
		tmp = math.exp(a)
	else:
		tmp = 0.5 + (a * 0.25)
	return tmp
function code(a, b)
	tmp = 0.0
	if ((a <= -5.2e-12) || (!(a <= -2.45e-30) && (a <= -6.5e-81)))
		tmp = exp(a);
	else
		tmp = Float64(0.5 + Float64(a * 0.25));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if ((a <= -5.2e-12) || (~((a <= -2.45e-30)) && (a <= -6.5e-81)))
		tmp = exp(a);
	else
		tmp = 0.5 + (a * 0.25);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[Or[LessEqual[a, -5.2e-12], And[N[Not[LessEqual[a, -2.45e-30]], $MachinePrecision], LessEqual[a, -6.5e-81]]], N[Exp[a], $MachinePrecision], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a \leq -5.2 \cdot 10^{-12} \lor \neg \left(a \leq -2.45 \cdot 10^{-30}\right) \land a \leq -6.5 \cdot 10^{-81}:\\
\;\;\;\;e^{a}\\

\mathbf{else}:\\
\;\;\;\;0.5 + a \cdot 0.25\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if a < -5.19999999999999965e-12 or -2.44999999999999985e-30 < a < -6.5000000000000002e-81

    1. Initial program 100.0%

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

        \[\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/399.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-exp98.9%

        \[\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. pow398.9%

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

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

        \[\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-exp99.9%

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

      \[\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 93.9%

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

    if -5.19999999999999965e-12 < a < -2.44999999999999985e-30 or -6.5000000000000002e-81 < a

    1. Initial program 99.3%

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

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

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

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

      \[\leadsto \color{blue}{0.5 + a \cdot 0.25} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification66.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -5.2 \cdot 10^{-12} \lor \neg \left(a \leq -2.45 \cdot 10^{-30}\right) \land a \leq -6.5 \cdot 10^{-81}:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]

Alternative 5: 79.7% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.1:\\
\;\;\;\;e^{a}\\

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


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

    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 95.9%

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

    if -1.1000000000000001 < b

    1. Initial program 99.5%

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

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

      \[\leadsto \frac{e^{a}}{\color{blue}{2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification80.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -1.1:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{a}}{2}\\ \end{array} \]

Alternative 6: 39.4% accurate, 61.0× speedup?

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

\\
0.5 + a \cdot 0.25
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

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

    \[\leadsto \color{blue}{0.5 + a \cdot 0.25} \]
  6. Final simplification35.5%

    \[\leadsto 0.5 + a \cdot 0.25 \]

Alternative 7: 39.2% 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 99.6%

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

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

    \[\leadsto \color{blue}{0.5} \]
  4. Final simplification35.2%

    \[\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 2023189 
(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))))