Quotient of sum of exps

Percentage Accurate: 99.1% → 99.2%
Time: 7.1s
Alternatives: 14
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 14 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.2% 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 99.6%

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

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

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

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

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

Alternative 2: 65.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{e^{a} + \left(b + 1\right)}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{e^{a}}{\color{blue}{1 + \left(e^{a} + b\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+67.9%

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

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(e^{a} + 1\right)} + b} \]
      3. associate-+l+67.9%

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    4. Simplified67.9%

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

    if 1 < (exp.f64 a)

    1. Initial program 88.7%

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

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

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

Alternative 3: 67.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{e^{a} + 1}\\

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


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

    1. Initial program 100.0%

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

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

    if 1 < (exp.f64 a)

    1. Initial program 88.7%

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

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

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

Alternative 4: 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 5: 64.8% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;e^{a} \cdot \frac{1}{a + \left(b + 2\right)}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{e^{a}}{\color{blue}{1 + \left(e^{a} + b\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+67.9%

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

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(e^{a} + 1\right)} + b} \]
      3. associate-+l+67.9%

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    4. Simplified67.9%

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Taylor expanded in a around 0 67.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{2 + \left(a + b\right)}} \]
    6. Step-by-step derivation
      1. associate-+r+67.8%

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(2 + a\right) + b}} \]
    7. Simplified67.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{\left(2 + a\right) + b}} \]
    8. Step-by-step derivation
      1. clear-num67.8%

        \[\leadsto \color{blue}{\frac{1}{\frac{\left(2 + a\right) + b}{e^{a}}}} \]
      2. associate-/r/67.8%

        \[\leadsto \color{blue}{\frac{1}{\left(2 + a\right) + b} \cdot e^{a}} \]
      3. +-commutative67.8%

        \[\leadsto \frac{1}{\color{blue}{\left(a + 2\right)} + b} \cdot e^{a} \]
      4. associate-+l+67.8%

        \[\leadsto \frac{1}{\color{blue}{a + \left(2 + b\right)}} \cdot e^{a} \]
    9. Applied egg-rr67.8%

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

    if 1 < (exp.f64 a)

    1. Initial program 88.7%

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

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

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

Alternative 6: 64.8% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{b + \left(a + 2\right)}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{e^{a}}{\color{blue}{1 + \left(e^{a} + b\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+67.9%

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

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(e^{a} + 1\right)} + b} \]
      3. associate-+l+67.9%

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    4. Simplified67.9%

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Taylor expanded in a around 0 67.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{2 + \left(a + b\right)}} \]
    6. Step-by-step derivation
      1. associate-+r+67.8%

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(2 + a\right) + b}} \]
    7. Simplified67.8%

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

    if 1 < (exp.f64 a)

    1. Initial program 88.7%

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

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

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

Alternative 7: 98.7% accurate, 1.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;e^{a} \leq 0:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= (exp a) 0.0) (exp a) (/ 1.0 (+ (exp b) 1.0))))
double code(double a, double b) {
	double tmp;
	if (exp(a) <= 0.0) {
		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) <= 0.0d0) 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) <= 0.0) {
		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) <= 0.0:
		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) <= 0.0)
		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) <= 0.0)
		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], 0.0], 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 0:\\
\;\;\;\;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) < 0.0

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto e^{a - \color{blue}{\log \left(1 + e^{a}\right)}} \]
    5. Step-by-step derivation
      1. log1p-def100.0%

        \[\leadsto e^{a - \color{blue}{\mathsf{log1p}\left(e^{a}\right)}} \]
    6. Simplified100.0%

      \[\leadsto e^{a - \color{blue}{\mathsf{log1p}\left(e^{a}\right)}} \]
    7. Taylor expanded in a around inf 100.0%

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

    if 0.0 < (exp.f64 a)

    1. Initial program 99.4%

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

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

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

Alternative 8: 66.9% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 1:\\
\;\;\;\;\frac{e^{a}}{a + 2}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \frac{e^{a}}{\color{blue}{1 + \left(e^{a} + b\right)}} \]
    3. Step-by-step derivation
      1. associate-+r+67.9%

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

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(e^{a} + 1\right)} + b} \]
      3. associate-+l+67.9%

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    4. Simplified67.9%

      \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Taylor expanded in a around 0 67.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{2 + \left(a + b\right)}} \]
    6. Step-by-step derivation
      1. associate-+r+67.8%

        \[\leadsto \frac{e^{a}}{\color{blue}{\left(2 + a\right) + b}} \]
    7. Simplified67.8%

      \[\leadsto \frac{e^{a}}{\color{blue}{\left(2 + a\right) + b}} \]
    8. Taylor expanded in b around 0 69.2%

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

    if 1 < (exp.f64 a)

    1. Initial program 88.7%

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

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

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

Alternative 9: 72.3% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;e^{a} \leq 0:\\
\;\;\;\;e^{a}\\

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


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

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto e^{a - \color{blue}{\log \left(1 + e^{a}\right)}} \]
    5. Step-by-step derivation
      1. log1p-def100.0%

        \[\leadsto e^{a - \color{blue}{\mathsf{log1p}\left(e^{a}\right)}} \]
    6. Simplified100.0%

      \[\leadsto e^{a - \color{blue}{\mathsf{log1p}\left(e^{a}\right)}} \]
    7. Taylor expanded in a around inf 100.0%

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

    if 0.0 < (exp.f64 a)

    1. Initial program 99.4%

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

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

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

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

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

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

Alternative 10: 60.4% accurate, 14.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 0.5 \cdot \left(b \cdot b\right)\\ \mathbf{if}\;b \leq 390:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 4.7 \cdot 10^{+100}:\\ \;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\frac{t_0 - b}{b \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{b \cdot b}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (let* ((t_0 (* 0.5 (* b b))))
   (if (<= b 390.0)
     (+ 0.5 (* a 0.25))
     (if (<= b 4.7e+100)
       (* (* a (* a a)) -0.020833333333333332)
       (if (<= b 1.35e+154) (/ (- t_0 b) (* b t_0)) (/ -2.0 (* b b)))))))
double code(double a, double b) {
	double t_0 = 0.5 * (b * b);
	double tmp;
	if (b <= 390.0) {
		tmp = 0.5 + (a * 0.25);
	} else if (b <= 4.7e+100) {
		tmp = (a * (a * a)) * -0.020833333333333332;
	} else if (b <= 1.35e+154) {
		tmp = (t_0 - b) / (b * t_0);
	} 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) :: t_0
    real(8) :: tmp
    t_0 = 0.5d0 * (b * b)
    if (b <= 390.0d0) then
        tmp = 0.5d0 + (a * 0.25d0)
    else if (b <= 4.7d+100) then
        tmp = (a * (a * a)) * (-0.020833333333333332d0)
    else if (b <= 1.35d+154) then
        tmp = (t_0 - b) / (b * t_0)
    else
        tmp = (-2.0d0) / (b * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double t_0 = 0.5 * (b * b);
	double tmp;
	if (b <= 390.0) {
		tmp = 0.5 + (a * 0.25);
	} else if (b <= 4.7e+100) {
		tmp = (a * (a * a)) * -0.020833333333333332;
	} else if (b <= 1.35e+154) {
		tmp = (t_0 - b) / (b * t_0);
	} else {
		tmp = -2.0 / (b * b);
	}
	return tmp;
}
def code(a, b):
	t_0 = 0.5 * (b * b)
	tmp = 0
	if b <= 390.0:
		tmp = 0.5 + (a * 0.25)
	elif b <= 4.7e+100:
		tmp = (a * (a * a)) * -0.020833333333333332
	elif b <= 1.35e+154:
		tmp = (t_0 - b) / (b * t_0)
	else:
		tmp = -2.0 / (b * b)
	return tmp
function code(a, b)
	t_0 = Float64(0.5 * Float64(b * b))
	tmp = 0.0
	if (b <= 390.0)
		tmp = Float64(0.5 + Float64(a * 0.25));
	elseif (b <= 4.7e+100)
		tmp = Float64(Float64(a * Float64(a * a)) * -0.020833333333333332);
	elseif (b <= 1.35e+154)
		tmp = Float64(Float64(t_0 - b) / Float64(b * t_0));
	else
		tmp = Float64(-2.0 / Float64(b * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	t_0 = 0.5 * (b * b);
	tmp = 0.0;
	if (b <= 390.0)
		tmp = 0.5 + (a * 0.25);
	elseif (b <= 4.7e+100)
		tmp = (a * (a * a)) * -0.020833333333333332;
	elseif (b <= 1.35e+154)
		tmp = (t_0 - b) / (b * t_0);
	else
		tmp = -2.0 / (b * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := Block[{t$95$0 = N[(0.5 * N[(b * b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 390.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4.7e+100], N[(N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] * -0.020833333333333332), $MachinePrecision], If[LessEqual[b, 1.35e+154], N[(N[(t$95$0 - b), $MachinePrecision] / N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(b \cdot b\right)\\
\mathbf{if}\;b \leq 390:\\
\;\;\;\;0.5 + a \cdot 0.25\\

\mathbf{elif}\;b \leq 4.7 \cdot 10^{+100}:\\
\;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\

\mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\frac{t_0 - b}{b \cdot t_0}\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 390 < b < 4.7e100

    1. Initial program 100.0%

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

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

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

      \[\leadsto \color{blue}{-0.020833333333333332 \cdot {a}^{3}} \]
    5. Step-by-step derivation
      1. *-commutative26.9%

        \[\leadsto \color{blue}{{a}^{3} \cdot -0.020833333333333332} \]
    6. Simplified26.9%

      \[\leadsto \color{blue}{{a}^{3} \cdot -0.020833333333333332} \]
    7. Step-by-step derivation
      1. unpow326.9%

        \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right)} \cdot -0.020833333333333332 \]
    8. Applied egg-rr26.9%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right)} \cdot -0.020833333333333332 \]

    if 4.7e100 < b < 1.35000000000000003e154

    1. Initial program 92.3%

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

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

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

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    6. Taylor expanded in b around inf 4.3%

      \[\leadsto \color{blue}{\frac{1}{b} - 2 \cdot \frac{1}{{b}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/4.3%

        \[\leadsto \frac{1}{b} - \color{blue}{\frac{2 \cdot 1}{{b}^{2}}} \]
      2. metadata-eval4.3%

        \[\leadsto \frac{1}{b} - \frac{\color{blue}{2}}{{b}^{2}} \]
      3. unpow24.3%

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

      \[\leadsto \color{blue}{\frac{1}{b} - \frac{2}{b \cdot b}} \]
    9. Step-by-step derivation
      1. clear-num4.3%

        \[\leadsto \frac{1}{b} - \color{blue}{\frac{1}{\frac{b \cdot b}{2}}} \]
      2. frac-sub92.6%

        \[\leadsto \color{blue}{\frac{1 \cdot \frac{b \cdot b}{2} - b \cdot 1}{b \cdot \frac{b \cdot b}{2}}} \]
      3. *-un-lft-identity92.6%

        \[\leadsto \frac{\color{blue}{\frac{b \cdot b}{2}} - b \cdot 1}{b \cdot \frac{b \cdot b}{2}} \]
      4. div-inv92.6%

        \[\leadsto \frac{\color{blue}{\left(b \cdot b\right) \cdot \frac{1}{2}} - b \cdot 1}{b \cdot \frac{b \cdot b}{2}} \]
      5. metadata-eval92.6%

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

        \[\leadsto \frac{\left(b \cdot b\right) \cdot 0.5 - \color{blue}{1 \cdot b}}{b \cdot \frac{b \cdot b}{2}} \]
      7. *-un-lft-identity92.6%

        \[\leadsto \frac{\left(b \cdot b\right) \cdot 0.5 - \color{blue}{b}}{b \cdot \frac{b \cdot b}{2}} \]
      8. div-inv92.6%

        \[\leadsto \frac{\left(b \cdot b\right) \cdot 0.5 - b}{b \cdot \color{blue}{\left(\left(b \cdot b\right) \cdot \frac{1}{2}\right)}} \]
      9. metadata-eval92.6%

        \[\leadsto \frac{\left(b \cdot b\right) \cdot 0.5 - b}{b \cdot \left(\left(b \cdot b\right) \cdot \color{blue}{0.5}\right)} \]
    10. Applied egg-rr92.6%

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

    if 1.35000000000000003e154 < 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 8.1%

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

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

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    6. Taylor expanded in b around inf 8.1%

      \[\leadsto \color{blue}{\frac{1}{b} - 2 \cdot \frac{1}{{b}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/8.1%

        \[\leadsto \frac{1}{b} - \color{blue}{\frac{2 \cdot 1}{{b}^{2}}} \]
      2. metadata-eval8.1%

        \[\leadsto \frac{1}{b} - \frac{\color{blue}{2}}{{b}^{2}} \]
      3. unpow28.1%

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

      \[\leadsto \color{blue}{\frac{1}{b} - \frac{2}{b \cdot b}} \]
    9. Taylor expanded in b around 0 100.0%

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

        \[\leadsto \frac{-2}{\color{blue}{b \cdot b}} \]
    11. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 390:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 4.7 \cdot 10^{+100}:\\ \;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\frac{0.5 \cdot \left(b \cdot b\right) - b}{b \cdot \left(0.5 \cdot \left(b \cdot b\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{b \cdot b}\\ \end{array} \]

Alternative 11: 58.0% accurate, 27.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 390:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{+152}:\\ \;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{b \cdot b}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 390.0)
   (+ 0.5 (* a 0.25))
   (if (<= b 1.8e+152)
     (* (* a (* a a)) -0.020833333333333332)
     (/ -2.0 (* b b)))))
double code(double a, double b) {
	double tmp;
	if (b <= 390.0) {
		tmp = 0.5 + (a * 0.25);
	} else if (b <= 1.8e+152) {
		tmp = (a * (a * a)) * -0.020833333333333332;
	} 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 <= 390.0d0) then
        tmp = 0.5d0 + (a * 0.25d0)
    else if (b <= 1.8d+152) then
        tmp = (a * (a * a)) * (-0.020833333333333332d0)
    else
        tmp = (-2.0d0) / (b * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 390.0) {
		tmp = 0.5 + (a * 0.25);
	} else if (b <= 1.8e+152) {
		tmp = (a * (a * a)) * -0.020833333333333332;
	} else {
		tmp = -2.0 / (b * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 390.0:
		tmp = 0.5 + (a * 0.25)
	elif b <= 1.8e+152:
		tmp = (a * (a * a)) * -0.020833333333333332
	else:
		tmp = -2.0 / (b * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 390.0)
		tmp = Float64(0.5 + Float64(a * 0.25));
	elseif (b <= 1.8e+152)
		tmp = Float64(Float64(a * Float64(a * a)) * -0.020833333333333332);
	else
		tmp = Float64(-2.0 / Float64(b * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 390.0)
		tmp = 0.5 + (a * 0.25);
	elseif (b <= 1.8e+152)
		tmp = (a * (a * a)) * -0.020833333333333332;
	else
		tmp = -2.0 / (b * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 390.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.8e+152], N[(N[(a * N[(a * a), $MachinePrecision]), $MachinePrecision] * -0.020833333333333332), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 390:\\
\;\;\;\;0.5 + a \cdot 0.25\\

\mathbf{elif}\;b \leq 1.8 \cdot 10^{+152}:\\
\;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 390 < b < 1.7999999999999999e152

    1. Initial program 96.8%

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

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

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

      \[\leadsto \color{blue}{-0.020833333333333332 \cdot {a}^{3}} \]
    5. Step-by-step derivation
      1. *-commutative27.9%

        \[\leadsto \color{blue}{{a}^{3} \cdot -0.020833333333333332} \]
    6. Simplified27.9%

      \[\leadsto \color{blue}{{a}^{3} \cdot -0.020833333333333332} \]
    7. Step-by-step derivation
      1. unpow327.9%

        \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right)} \cdot -0.020833333333333332 \]
    8. Applied egg-rr27.9%

      \[\leadsto \color{blue}{\left(\left(a \cdot a\right) \cdot a\right)} \cdot -0.020833333333333332 \]

    if 1.7999999999999999e152 < 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 7.9%

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

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

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    6. Taylor expanded in b around inf 7.9%

      \[\leadsto \color{blue}{\frac{1}{b} - 2 \cdot \frac{1}{{b}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/7.9%

        \[\leadsto \frac{1}{b} - \color{blue}{\frac{2 \cdot 1}{{b}^{2}}} \]
      2. metadata-eval7.9%

        \[\leadsto \frac{1}{b} - \frac{\color{blue}{2}}{{b}^{2}} \]
      3. unpow27.9%

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

      \[\leadsto \color{blue}{\frac{1}{b} - \frac{2}{b \cdot b}} \]
    9. Taylor expanded in b around 0 96.2%

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

        \[\leadsto \frac{-2}{\color{blue}{b \cdot b}} \]
    11. Simplified96.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 390:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 1.8 \cdot 10^{+152}:\\ \;\;\;\;\left(a \cdot \left(a \cdot a\right)\right) \cdot -0.020833333333333332\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{b \cdot b}\\ \end{array} \]

Alternative 12: 52.7% accurate, 43.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;b \leq 600:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{-2}{b \cdot b}\\ \end{array} \end{array} \]
(FPCore (a b)
 :precision binary64
 (if (<= b 600.0) (+ 0.5 (* a 0.25)) (/ -2.0 (* b b))))
double code(double a, double b) {
	double tmp;
	if (b <= 600.0) {
		tmp = 0.5 + (a * 0.25);
	} 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 <= 600.0d0) then
        tmp = 0.5d0 + (a * 0.25d0)
    else
        tmp = (-2.0d0) / (b * b)
    end if
    code = tmp
end function
public static double code(double a, double b) {
	double tmp;
	if (b <= 600.0) {
		tmp = 0.5 + (a * 0.25);
	} else {
		tmp = -2.0 / (b * b);
	}
	return tmp;
}
def code(a, b):
	tmp = 0
	if b <= 600.0:
		tmp = 0.5 + (a * 0.25)
	else:
		tmp = -2.0 / (b * b)
	return tmp
function code(a, b)
	tmp = 0.0
	if (b <= 600.0)
		tmp = Float64(0.5 + Float64(a * 0.25));
	else
		tmp = Float64(-2.0 / Float64(b * b));
	end
	return tmp
end
function tmp_2 = code(a, b)
	tmp = 0.0;
	if (b <= 600.0)
		tmp = 0.5 + (a * 0.25);
	else
		tmp = -2.0 / (b * b);
	end
	tmp_2 = tmp;
end
code[a_, b_] := If[LessEqual[b, 600.0], N[(0.5 + N[(a * 0.25), $MachinePrecision]), $MachinePrecision], N[(-2.0 / N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;b \leq 600:\\
\;\;\;\;0.5 + a \cdot 0.25\\

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


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

    1. Initial program 100.0%

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

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

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

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

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

    if 600 < b

    1. Initial program 98.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 6.3%

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

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

      \[\leadsto \frac{1}{\color{blue}{b + 2}} \]
    6. Taylor expanded in b around inf 6.3%

      \[\leadsto \color{blue}{\frac{1}{b} - 2 \cdot \frac{1}{{b}^{2}}} \]
    7. Step-by-step derivation
      1. associate-*r/6.3%

        \[\leadsto \frac{1}{b} - \color{blue}{\frac{2 \cdot 1}{{b}^{2}}} \]
      2. metadata-eval6.3%

        \[\leadsto \frac{1}{b} - \frac{\color{blue}{2}}{{b}^{2}} \]
      3. unpow26.3%

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

      \[\leadsto \color{blue}{\frac{1}{b} - \frac{2}{b \cdot b}} \]
    9. Taylor expanded in b around 0 59.0%

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

        \[\leadsto \frac{-2}{\color{blue}{b \cdot b}} \]
    11. Simplified59.0%

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

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

Alternative 13: 38.9% 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 68.0%

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

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

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

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

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

Alternative 14: 38.8% 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 a around 0 82.7%

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

    \[\leadsto \color{blue}{0.5} \]
  4. Final simplification40.9%

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