Harley's example

Percentage Accurate: 91.3% → 96.7%
Time: 38.4s
Alternatives: 5
Speedup: 8.7×

Specification

?
\[0 < c\_p \land 0 < c\_n\]
\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{1}{1 + e^{-t}}\\ t_2 := \frac{1}{1 + e^{-s}}\\ \frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}} \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (/ 1.0 (+ 1.0 (exp (- t))))) (t_2 (/ 1.0 (+ 1.0 (exp (- s))))))
   (/
    (* (pow t_2 c_p) (pow (- 1.0 t_2) c_n))
    (* (pow t_1 c_p) (pow (- 1.0 t_1) c_n)))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + exp(-t));
	double t_2 = 1.0 / (1.0 + exp(-s));
	return (pow(t_2, c_p) * pow((1.0 - t_2), c_n)) / (pow(t_1, c_p) * pow((1.0 - t_1), c_n));
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    real(8) :: t_1
    real(8) :: t_2
    t_1 = 1.0d0 / (1.0d0 + exp(-t))
    t_2 = 1.0d0 / (1.0d0 + exp(-s))
    code = ((t_2 ** c_p) * ((1.0d0 - t_2) ** c_n)) / ((t_1 ** c_p) * ((1.0d0 - t_1) ** c_n))
end function
public static double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + Math.exp(-t));
	double t_2 = 1.0 / (1.0 + Math.exp(-s));
	return (Math.pow(t_2, c_p) * Math.pow((1.0 - t_2), c_n)) / (Math.pow(t_1, c_p) * Math.pow((1.0 - t_1), c_n));
}
def code(c_p, c_n, t, s):
	t_1 = 1.0 / (1.0 + math.exp(-t))
	t_2 = 1.0 / (1.0 + math.exp(-s))
	return (math.pow(t_2, c_p) * math.pow((1.0 - t_2), c_n)) / (math.pow(t_1, c_p) * math.pow((1.0 - t_1), c_n))
function code(c_p, c_n, t, s)
	t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-t))))
	t_2 = Float64(1.0 / Float64(1.0 + exp(Float64(-s))))
	return Float64(Float64((t_2 ^ c_p) * (Float64(1.0 - t_2) ^ c_n)) / Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n)))
end
function tmp = code(c_p, c_n, t, s)
	t_1 = 1.0 / (1.0 + exp(-t));
	t_2 = 1.0 / (1.0 + exp(-s));
	tmp = ((t_2 ^ c_p) * ((1.0 - t_2) ^ c_n)) / ((t_1 ^ c_p) * ((1.0 - t_1) ^ c_n));
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[t$95$2, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$2), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{1}{1 + e^{-t}}\\
t_2 := \frac{1}{1 + e^{-s}}\\
\frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}
\end{array}
\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 5 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: 91.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{1}{1 + e^{-t}}\\ t_2 := \frac{1}{1 + e^{-s}}\\ \frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}} \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (/ 1.0 (+ 1.0 (exp (- t))))) (t_2 (/ 1.0 (+ 1.0 (exp (- s))))))
   (/
    (* (pow t_2 c_p) (pow (- 1.0 t_2) c_n))
    (* (pow t_1 c_p) (pow (- 1.0 t_1) c_n)))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + exp(-t));
	double t_2 = 1.0 / (1.0 + exp(-s));
	return (pow(t_2, c_p) * pow((1.0 - t_2), c_n)) / (pow(t_1, c_p) * pow((1.0 - t_1), c_n));
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    real(8) :: t_1
    real(8) :: t_2
    t_1 = 1.0d0 / (1.0d0 + exp(-t))
    t_2 = 1.0d0 / (1.0d0 + exp(-s))
    code = ((t_2 ** c_p) * ((1.0d0 - t_2) ** c_n)) / ((t_1 ** c_p) * ((1.0d0 - t_1) ** c_n))
end function
public static double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + Math.exp(-t));
	double t_2 = 1.0 / (1.0 + Math.exp(-s));
	return (Math.pow(t_2, c_p) * Math.pow((1.0 - t_2), c_n)) / (Math.pow(t_1, c_p) * Math.pow((1.0 - t_1), c_n));
}
def code(c_p, c_n, t, s):
	t_1 = 1.0 / (1.0 + math.exp(-t))
	t_2 = 1.0 / (1.0 + math.exp(-s))
	return (math.pow(t_2, c_p) * math.pow((1.0 - t_2), c_n)) / (math.pow(t_1, c_p) * math.pow((1.0 - t_1), c_n))
function code(c_p, c_n, t, s)
	t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-t))))
	t_2 = Float64(1.0 / Float64(1.0 + exp(Float64(-s))))
	return Float64(Float64((t_2 ^ c_p) * (Float64(1.0 - t_2) ^ c_n)) / Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n)))
end
function tmp = code(c_p, c_n, t, s)
	t_1 = 1.0 / (1.0 + exp(-t));
	t_2 = 1.0 / (1.0 + exp(-s));
	tmp = ((t_2 ^ c_p) * ((1.0 - t_2) ^ c_n)) / ((t_1 ^ c_p) * ((1.0 - t_1) ^ c_n));
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[(N[Power[t$95$2, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$2), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{1}{1 + e^{-t}}\\
t_2 := \frac{1}{1 + e^{-s}}\\
\frac{{t\_2}^{c\_p} \cdot {\left(1 - t\_2\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}
\end{array}
\end{array}

Alternative 1: 96.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{1}{1 + e^{-t}}\\ t_2 := e^{-s}\\ t_3 := \frac{1}{1 + t\_2}\\ t_4 := \frac{{t\_3}^{c\_p} \cdot {\left(1 - t\_3\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}\\ \mathbf{if}\;t\_4 \leq 2:\\ \;\;\;\;t\_4\\ \mathbf{else}:\\ \;\;\;\;t\_2\\ \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (/ 1.0 (+ 1.0 (exp (- t)))))
        (t_2 (exp (- s)))
        (t_3 (/ 1.0 (+ 1.0 t_2)))
        (t_4
         (/
          (* (pow t_3 c_p) (pow (- 1.0 t_3) c_n))
          (* (pow t_1 c_p) (pow (- 1.0 t_1) c_n)))))
   (if (<= t_4 2.0) t_4 t_2)))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + exp(-t));
	double t_2 = exp(-s);
	double t_3 = 1.0 / (1.0 + t_2);
	double t_4 = (pow(t_3, c_p) * pow((1.0 - t_3), c_n)) / (pow(t_1, c_p) * pow((1.0 - t_1), c_n));
	double tmp;
	if (t_4 <= 2.0) {
		tmp = t_4;
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: tmp
    t_1 = 1.0d0 / (1.0d0 + exp(-t))
    t_2 = exp(-s)
    t_3 = 1.0d0 / (1.0d0 + t_2)
    t_4 = ((t_3 ** c_p) * ((1.0d0 - t_3) ** c_n)) / ((t_1 ** c_p) * ((1.0d0 - t_1) ** c_n))
    if (t_4 <= 2.0d0) then
        tmp = t_4
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + Math.exp(-t));
	double t_2 = Math.exp(-s);
	double t_3 = 1.0 / (1.0 + t_2);
	double t_4 = (Math.pow(t_3, c_p) * Math.pow((1.0 - t_3), c_n)) / (Math.pow(t_1, c_p) * Math.pow((1.0 - t_1), c_n));
	double tmp;
	if (t_4 <= 2.0) {
		tmp = t_4;
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(c_p, c_n, t, s):
	t_1 = 1.0 / (1.0 + math.exp(-t))
	t_2 = math.exp(-s)
	t_3 = 1.0 / (1.0 + t_2)
	t_4 = (math.pow(t_3, c_p) * math.pow((1.0 - t_3), c_n)) / (math.pow(t_1, c_p) * math.pow((1.0 - t_1), c_n))
	tmp = 0
	if t_4 <= 2.0:
		tmp = t_4
	else:
		tmp = t_2
	return tmp
function code(c_p, c_n, t, s)
	t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-t))))
	t_2 = exp(Float64(-s))
	t_3 = Float64(1.0 / Float64(1.0 + t_2))
	t_4 = Float64(Float64((t_3 ^ c_p) * (Float64(1.0 - t_3) ^ c_n)) / Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n)))
	tmp = 0.0
	if (t_4 <= 2.0)
		tmp = t_4;
	else
		tmp = t_2;
	end
	return tmp
end
function tmp_2 = code(c_p, c_n, t, s)
	t_1 = 1.0 / (1.0 + exp(-t));
	t_2 = exp(-s);
	t_3 = 1.0 / (1.0 + t_2);
	t_4 = ((t_3 ^ c_p) * ((1.0 - t_3) ^ c_n)) / ((t_1 ^ c_p) * ((1.0 - t_1) ^ c_n));
	tmp = 0.0;
	if (t_4 <= 2.0)
		tmp = t_4;
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Exp[(-s)], $MachinePrecision]}, Block[{t$95$3 = N[(1.0 / N[(1.0 + t$95$2), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[(N[Power[t$95$3, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$3), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, 2.0], t$95$4, t$95$2]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{1}{1 + e^{-t}}\\
t_2 := e^{-s}\\
t_3 := \frac{1}{1 + t\_2}\\
t_4 := \frac{{t\_3}^{c\_p} \cdot {\left(1 - t\_3\right)}^{c\_n}}{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}\\
\mathbf{if}\;t\_4 \leq 2:\\
\;\;\;\;t\_4\\

\mathbf{else}:\\
\;\;\;\;t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (*.f64 (pow.f64 (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 s)))) c_p) (pow.f64 (-.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 s))))) c_n)) (*.f64 (pow.f64 (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 t)))) c_p) (pow.f64 (-.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 t))))) c_n))) < 2

    1. Initial program 98.4%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing

    if 2 < (/.f64 (*.f64 (pow.f64 (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 s)))) c_p) (pow.f64 (-.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 s))))) c_n)) (*.f64 (pow.f64 (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 t)))) c_p) (pow.f64 (-.f64 #s(literal 1 binary64) (/.f64 #s(literal 1 binary64) (+.f64 #s(literal 1 binary64) (exp.f64 (neg.f64 t))))) c_n)))

    1. Initial program 0.2%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing
    3. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    4. Applied rewrites56.9%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
    5. Taylor expanded in c_p around 0

      \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
    6. Applied rewrites80.3%

      \[\leadsto e^{-s} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 2: 96.2% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := e^{-s}\\ \mathbf{if}\;-s \leq 2 \cdot 10^{-53}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;{\left(\frac{1}{1 + t\_1}\right)}^{c\_p}\\ \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (exp (- s))))
   (if (<= (- s) 2e-53) t_1 (pow (/ 1.0 (+ 1.0 t_1)) c_p))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = exp(-s);
	double tmp;
	if (-s <= 2e-53) {
		tmp = t_1;
	} else {
		tmp = pow((1.0 / (1.0 + t_1)), c_p);
	}
	return tmp;
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    real(8) :: t_1
    real(8) :: tmp
    t_1 = exp(-s)
    if (-s <= 2d-53) then
        tmp = t_1
    else
        tmp = (1.0d0 / (1.0d0 + t_1)) ** c_p
    end if
    code = tmp
end function
public static double code(double c_p, double c_n, double t, double s) {
	double t_1 = Math.exp(-s);
	double tmp;
	if (-s <= 2e-53) {
		tmp = t_1;
	} else {
		tmp = Math.pow((1.0 / (1.0 + t_1)), c_p);
	}
	return tmp;
}
def code(c_p, c_n, t, s):
	t_1 = math.exp(-s)
	tmp = 0
	if -s <= 2e-53:
		tmp = t_1
	else:
		tmp = math.pow((1.0 / (1.0 + t_1)), c_p)
	return tmp
function code(c_p, c_n, t, s)
	t_1 = exp(Float64(-s))
	tmp = 0.0
	if (Float64(-s) <= 2e-53)
		tmp = t_1;
	else
		tmp = Float64(1.0 / Float64(1.0 + t_1)) ^ c_p;
	end
	return tmp
end
function tmp_2 = code(c_p, c_n, t, s)
	t_1 = exp(-s);
	tmp = 0.0;
	if (-s <= 2e-53)
		tmp = t_1;
	else
		tmp = (1.0 / (1.0 + t_1)) ^ c_p;
	end
	tmp_2 = tmp;
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[Exp[(-s)], $MachinePrecision]}, If[LessEqual[(-s), 2e-53], t$95$1, N[Power[N[(1.0 / N[(1.0 + t$95$1), $MachinePrecision]), $MachinePrecision], c$95$p], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := e^{-s}\\
\mathbf{if}\;-s \leq 2 \cdot 10^{-53}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;{\left(\frac{1}{1 + t\_1}\right)}^{c\_p}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (neg.f64 s) < 2.00000000000000006e-53

    1. Initial program 93.7%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing
    3. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    4. Applied rewrites93.0%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
    5. Taylor expanded in c_p around 0

      \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
    6. Applied rewrites96.7%

      \[\leadsto e^{-s} \]

    if 2.00000000000000006e-53 < (neg.f64 s)

    1. Initial program 80.3%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing
    3. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    4. Applied rewrites90.3%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 3: 93.5% accurate, 8.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;-t \leq 4 \cdot 10^{-37}:\\ \;\;\;\;e^{-t}\\ \mathbf{else}:\\ \;\;\;\;e^{-s}\\ \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (if (<= (- t) 4e-37) (exp (- t)) (exp (- s))))
double code(double c_p, double c_n, double t, double s) {
	double tmp;
	if (-t <= 4e-37) {
		tmp = exp(-t);
	} else {
		tmp = exp(-s);
	}
	return tmp;
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    real(8) :: tmp
    if (-t <= 4d-37) then
        tmp = exp(-t)
    else
        tmp = exp(-s)
    end if
    code = tmp
end function
public static double code(double c_p, double c_n, double t, double s) {
	double tmp;
	if (-t <= 4e-37) {
		tmp = Math.exp(-t);
	} else {
		tmp = Math.exp(-s);
	}
	return tmp;
}
def code(c_p, c_n, t, s):
	tmp = 0
	if -t <= 4e-37:
		tmp = math.exp(-t)
	else:
		tmp = math.exp(-s)
	return tmp
function code(c_p, c_n, t, s)
	tmp = 0.0
	if (Float64(-t) <= 4e-37)
		tmp = exp(Float64(-t));
	else
		tmp = exp(Float64(-s));
	end
	return tmp
end
function tmp_2 = code(c_p, c_n, t, s)
	tmp = 0.0;
	if (-t <= 4e-37)
		tmp = exp(-t);
	else
		tmp = exp(-s);
	end
	tmp_2 = tmp;
end
code[c$95$p_, c$95$n_, t_, s_] := If[LessEqual[(-t), 4e-37], N[Exp[(-t)], $MachinePrecision], N[Exp[(-s)], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;-t \leq 4 \cdot 10^{-37}:\\
\;\;\;\;e^{-t}\\

\mathbf{else}:\\
\;\;\;\;e^{-s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (neg.f64 t) < 4.00000000000000027e-37

    1. Initial program 92.8%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing
    3. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    4. Applied rewrites93.6%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
    5. Taylor expanded in c_p around 0

      \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
    6. Applied rewrites93.0%

      \[\leadsto e^{-s} \]
    7. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + c\_p \cdot \left(\frac{1}{6} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{3} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{6} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{3} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \left(\frac{1}{2} \cdot \left({\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right) + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right)\right)\right)\right)\right) - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    8. Applied rewrites3.6%

      \[\leadsto \color{blue}{-s} \]
    9. Taylor expanded in c_n around 0

      \[\leadsto \color{blue}{\frac{{\left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_p}}{{\left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_p}}} \]
    10. Applied rewrites95.8%

      \[\leadsto \color{blue}{e^{-t}} \]

    if 4.00000000000000027e-37 < (neg.f64 t)

    1. Initial program 91.4%

      \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    2. Add Preprocessing
    3. Taylor expanded in c_p around 0

      \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
    4. Applied rewrites84.4%

      \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
    5. Taylor expanded in c_p around 0

      \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
    6. Applied rewrites95.1%

      \[\leadsto e^{-s} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 92.9% accurate, 8.7× speedup?

\[\begin{array}{l} \\ e^{-s} \end{array} \]
(FPCore (c_p c_n t s) :precision binary64 (exp (- s)))
double code(double c_p, double c_n, double t, double s) {
	return exp(-s);
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    code = exp(-s)
end function
public static double code(double c_p, double c_n, double t, double s) {
	return Math.exp(-s);
}
def code(c_p, c_n, t, s):
	return math.exp(-s)
function code(c_p, c_n, t, s)
	return exp(Float64(-s))
end
function tmp = code(c_p, c_n, t, s)
	tmp = exp(-s);
end
code[c$95$p_, c$95$n_, t_, s_] := N[Exp[(-s)], $MachinePrecision]
\begin{array}{l}

\\
e^{-s}
\end{array}
Derivation
  1. Initial program 92.6%

    \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
  2. Add Preprocessing
  3. Taylor expanded in c_p around 0

    \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
  4. Applied rewrites92.8%

    \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
  5. Taylor expanded in c_p around 0

    \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
  6. Applied rewrites93.2%

    \[\leadsto e^{-s} \]
  7. Add Preprocessing

Alternative 5: 3.9% accurate, 298.7× speedup?

\[\begin{array}{l} \\ -s \end{array} \]
(FPCore (c_p c_n t s) :precision binary64 (- s))
double code(double c_p, double c_n, double t, double s) {
	return -s;
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    code = -s
end function
public static double code(double c_p, double c_n, double t, double s) {
	return -s;
}
def code(c_p, c_n, t, s):
	return -s
function code(c_p, c_n, t, s)
	return Float64(-s)
end
function tmp = code(c_p, c_n, t, s)
	tmp = -s;
end
code[c$95$p_, c$95$n_, t_, s_] := (-s)
\begin{array}{l}

\\
-s
\end{array}
Derivation
  1. Initial program 92.6%

    \[\frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{{\left(\frac{1}{1 + e^{-t}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
  2. Add Preprocessing
  3. Taylor expanded in c_p around 0

    \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
  4. Applied rewrites92.8%

    \[\leadsto \color{blue}{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p}} \]
  5. Taylor expanded in c_p around 0

    \[\leadsto 1 + \color{blue}{c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)} \]
  6. Applied rewrites93.2%

    \[\leadsto e^{-s} \]
  7. Taylor expanded in c_p around 0

    \[\leadsto \color{blue}{c\_p \cdot \left(\left(c\_p \cdot \left(\left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + c\_p \cdot \left(\frac{1}{6} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{3} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{6} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{3} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \left(\frac{1}{2} \cdot \left({\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right) + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right)\right)\right)\right)\right) - \left(\frac{1}{2} \cdot \frac{{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{2} \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} + \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot \left(\frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}} - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right)\right)\right) + \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) - \frac{\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot {\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}\right) + \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
  8. Applied rewrites3.6%

    \[\leadsto \color{blue}{-s} \]
  9. Add Preprocessing

Developer Target 1: 97.0% accurate, 1.4× speedup?

\[\begin{array}{l} \\ {\left(\frac{1 + e^{-t}}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(\frac{1 + e^{t}}{1 + e^{s}}\right)}^{c\_n} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (*
  (pow (/ (+ 1.0 (exp (- t))) (+ 1.0 (exp (- s)))) c_p)
  (pow (/ (+ 1.0 (exp t)) (+ 1.0 (exp s))) c_n)))
double code(double c_p, double c_n, double t, double s) {
	return pow(((1.0 + exp(-t)) / (1.0 + exp(-s))), c_p) * pow(((1.0 + exp(t)) / (1.0 + exp(s))), c_n);
}
real(8) function code(c_p, c_n, t, s)
    real(8), intent (in) :: c_p
    real(8), intent (in) :: c_n
    real(8), intent (in) :: t
    real(8), intent (in) :: s
    code = (((1.0d0 + exp(-t)) / (1.0d0 + exp(-s))) ** c_p) * (((1.0d0 + exp(t)) / (1.0d0 + exp(s))) ** c_n)
end function
public static double code(double c_p, double c_n, double t, double s) {
	return Math.pow(((1.0 + Math.exp(-t)) / (1.0 + Math.exp(-s))), c_p) * Math.pow(((1.0 + Math.exp(t)) / (1.0 + Math.exp(s))), c_n);
}
def code(c_p, c_n, t, s):
	return math.pow(((1.0 + math.exp(-t)) / (1.0 + math.exp(-s))), c_p) * math.pow(((1.0 + math.exp(t)) / (1.0 + math.exp(s))), c_n)
function code(c_p, c_n, t, s)
	return Float64((Float64(Float64(1.0 + exp(Float64(-t))) / Float64(1.0 + exp(Float64(-s)))) ^ c_p) * (Float64(Float64(1.0 + exp(t)) / Float64(1.0 + exp(s))) ^ c_n))
end
function tmp = code(c_p, c_n, t, s)
	tmp = (((1.0 + exp(-t)) / (1.0 + exp(-s))) ^ c_p) * (((1.0 + exp(t)) / (1.0 + exp(s))) ^ c_n);
end
code[c$95$p_, c$95$n_, t_, s_] := N[(N[Power[N[(N[(1.0 + N[Exp[(-t)], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Exp[(-s)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], c$95$p], $MachinePrecision] * N[Power[N[(N[(1.0 + N[Exp[t], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Exp[s], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
{\left(\frac{1 + e^{-t}}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(\frac{1 + e^{t}}{1 + e^{s}}\right)}^{c\_n}
\end{array}

Reproduce

?
herbie shell --seed 2024313 
(FPCore (c_p c_n t s)
  :name "Harley's example"
  :precision binary64
  :pre (and (< 0.0 c_p) (< 0.0 c_n))

  :alt
  (! :herbie-platform default (* (pow (/ (+ 1 (exp (- t))) (+ 1 (exp (- s)))) c_p) (pow (/ (+ 1 (exp t)) (+ 1 (exp s))) c_n)))

  (/ (* (pow (/ 1.0 (+ 1.0 (exp (- s)))) c_p) (pow (- 1.0 (/ 1.0 (+ 1.0 (exp (- s))))) c_n)) (* (pow (/ 1.0 (+ 1.0 (exp (- t)))) c_p) (pow (- 1.0 (/ 1.0 (+ 1.0 (exp (- t))))) c_n))))