Quotient of sum of exps

Percentage Accurate: 98.8% → 99.0%
Time: 7.8s
Alternatives: 8
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 8 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: 98.8% 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.0% accurate, 0.7× speedup?

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

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

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. add-cube-cbrt97.8%

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

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

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

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

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

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

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

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

    \[\leadsto e^{\left(0.3333333333333333 \cdot \left(a - \log \left(e^{a} + e^{b}\right)\right)\right) \cdot 3} \]
  6. Add Preprocessing

Alternative 2: 98.8% 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.4%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Final simplification98.4%

    \[\leadsto \frac{e^{a}}{e^{a} + e^{b}} \]
  4. Add Preprocessing

Alternative 3: 66.4% accurate, 1.5× speedup?

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

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

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


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

    1. Initial program 98.6%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt98.5%

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

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

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

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

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

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

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

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

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

    if 0.050000000000000003 < (exp.f64 a)

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 57.5%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{a} \leq 0.05:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 98.3% accurate, 2.8× speedup?

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

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


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

    1. Initial program 100.0%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. add-cube-cbrt100.0%

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

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

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

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

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

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

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

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

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

    if -7.2e11 < a

    1. Initial program 97.9%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 97.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;a \leq -720000000000:\\ \;\;\;\;e^{a}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{e^{b} + 1}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 52.0% accurate, 14.5× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \left(-b\right) - b}{b \cdot \left(-b\right)}\\


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

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 79.1%

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

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

        \[\leadsto 0.5 + \color{blue}{a \cdot 0.25} \]
    6. Simplified54.9%

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

    if 260 < b < 1.35000000000000003e154

    1. Initial program 100.0%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 36.8%

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

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

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Simplified36.8%

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

      \[\leadsto \color{blue}{\frac{e^{a}}{b}} \]
    7. Taylor expanded in a around 0 3.4%

      \[\leadsto \color{blue}{\frac{1}{b} + \frac{a}{b}} \]
    8. Taylor expanded in a around inf 18.7%

      \[\leadsto \color{blue}{\frac{a}{b}} \]

    if 1.35000000000000003e154 < b

    1. Initial program 96.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 36.8%

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

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

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Simplified36.8%

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

      \[\leadsto \color{blue}{\frac{e^{a}}{b}} \]
    7. Taylor expanded in a around 0 6.1%

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

        \[\leadsto \color{blue}{\frac{-1}{-b}} + \frac{a}{b} \]
      2. metadata-eval6.1%

        \[\leadsto \frac{\color{blue}{-1}}{-b} + \frac{a}{b} \]
      3. frac-add75.0%

        \[\leadsto \color{blue}{\frac{-1 \cdot b + \left(-b\right) \cdot a}{\left(-b\right) \cdot b}} \]
      4. neg-mul-175.0%

        \[\leadsto \frac{\color{blue}{\left(-b\right)} + \left(-b\right) \cdot a}{\left(-b\right) \cdot b} \]
    9. Applied egg-rr75.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 260:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{elif}\;b \leq 1.35 \cdot 10^{+154}:\\ \;\;\;\;\frac{a}{b}\\ \mathbf{else}:\\ \;\;\;\;\frac{a \cdot \left(-b\right) - b}{b \cdot \left(-b\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 48.8% accurate, 30.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{a}{b}\\


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

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 79.1%

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

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

        \[\leadsto 0.5 + \color{blue}{a \cdot 0.25} \]
    6. Simplified54.9%

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

    if 320 < b

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 36.8%

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

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

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Simplified36.8%

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

      \[\leadsto \color{blue}{\frac{e^{a}}{b}} \]
    7. Taylor expanded in a around 0 4.6%

      \[\leadsto \color{blue}{\frac{1}{b} + \frac{a}{b}} \]
    8. Taylor expanded in a around inf 30.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 320:\\ \;\;\;\;0.5 + a \cdot 0.25\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 48.6% accurate, 38.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.35 \cdot 10^{+28}:\\
\;\;\;\;0.5\\

\mathbf{else}:\\
\;\;\;\;\frac{a}{b}\\


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

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in a around 0 74.2%

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

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

    if 1.3500000000000001e28 < b

    1. Initial program 98.4%

      \[\frac{e^{a}}{e^{a} + e^{b}} \]
    2. Add Preprocessing
    3. Taylor expanded in b around 0 34.7%

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

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

        \[\leadsto \frac{e^{a}}{\color{blue}{e^{a} + \left(1 + b\right)}} \]
    5. Simplified34.7%

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

      \[\leadsto \color{blue}{\frac{e^{a}}{b}} \]
    7. Taylor expanded in a around 0 4.7%

      \[\leadsto \color{blue}{\frac{1}{b} + \frac{a}{b}} \]
    8. Taylor expanded in a around inf 31.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq 1.35 \cdot 10^{+28}:\\ \;\;\;\;0.5\\ \mathbf{else}:\\ \;\;\;\;\frac{a}{b}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 40.3% 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.4%

    \[\frac{e^{a}}{e^{a} + e^{b}} \]
  2. Add Preprocessing
  3. Taylor expanded in a around 0 80.3%

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

    \[\leadsto \color{blue}{0.5} \]
  5. Final simplification41.9%

    \[\leadsto 0.5 \]
  6. Add Preprocessing

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 2024017 
(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))))