Harley's example

Percentage Accurate: 91.4% → 96.0%
Time: 1.4min
Alternatives: 4
Speedup: N/A×

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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(c_p, c_n, t, s)
use fmin_fmax_functions
    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 4 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.4% 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));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(c_p, c_n, t, s)
use fmin_fmax_functions
    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.0% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{1}{1 + e^{-1 \cdot s}}\\ t_2 := \frac{c\_n}{2} + \frac{c\_n}{2}\\ t_3 := {\left(e^{t}\right)}^{-1}\\ \mathbf{if}\;-1 \cdot s \leq 10000000:\\ \;\;\;\;\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{t\_2}}{{\left(1 - {\left(t\_3 + 1\right)}^{-1}\right)}^{t\_2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left(t\_3\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-1 \cdot t}}\right)}^{c\_n}}\\ \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (/ 1.0 (+ 1.0 (exp (* -1.0 s)))))
        (t_2 (+ (/ c_n 2.0) (/ c_n 2.0)))
        (t_3 (pow (exp t) -1.0)))
   (if (<= (* -1.0 s) 10000000.0)
     (/
      (pow (- 1.0 (pow (+ (pow (exp s) -1.0) 1.0) -1.0)) t_2)
      (pow (- 1.0 (pow (+ t_3 1.0) -1.0)) t_2))
     (/
      (* (pow t_1 c_p) (pow (- 1.0 t_1) c_n))
      (*
       (fma (* -1.0 (log1p t_3)) c_p 1.0)
       (pow (- 1.0 (/ 1.0 (+ 1.0 (exp (* -1.0 t))))) c_n))))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = 1.0 / (1.0 + exp((-1.0 * s)));
	double t_2 = (c_n / 2.0) + (c_n / 2.0);
	double t_3 = pow(exp(t), -1.0);
	double tmp;
	if ((-1.0 * s) <= 10000000.0) {
		tmp = pow((1.0 - pow((pow(exp(s), -1.0) + 1.0), -1.0)), t_2) / pow((1.0 - pow((t_3 + 1.0), -1.0)), t_2);
	} else {
		tmp = (pow(t_1, c_p) * pow((1.0 - t_1), c_n)) / (fma((-1.0 * log1p(t_3)), c_p, 1.0) * pow((1.0 - (1.0 / (1.0 + exp((-1.0 * t))))), c_n));
	}
	return tmp;
}
function code(c_p, c_n, t, s)
	t_1 = Float64(1.0 / Float64(1.0 + exp(Float64(-1.0 * s))))
	t_2 = Float64(Float64(c_n / 2.0) + Float64(c_n / 2.0))
	t_3 = exp(t) ^ -1.0
	tmp = 0.0
	if (Float64(-1.0 * s) <= 10000000.0)
		tmp = Float64((Float64(1.0 - (Float64((exp(s) ^ -1.0) + 1.0) ^ -1.0)) ^ t_2) / (Float64(1.0 - (Float64(t_3 + 1.0) ^ -1.0)) ^ t_2));
	else
		tmp = Float64(Float64((t_1 ^ c_p) * (Float64(1.0 - t_1) ^ c_n)) / Float64(fma(Float64(-1.0 * log1p(t_3)), c_p, 1.0) * (Float64(1.0 - Float64(1.0 / Float64(1.0 + exp(Float64(-1.0 * t))))) ^ c_n)));
	end
	return tmp
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(1.0 / N[(1.0 + N[Exp[N[(-1.0 * s), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(c$95$n / 2.0), $MachinePrecision] + N[(c$95$n / 2.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Exp[t], $MachinePrecision], -1.0], $MachinePrecision]}, If[LessEqual[N[(-1.0 * s), $MachinePrecision], 10000000.0], N[(N[Power[N[(1.0 - N[Power[N[(N[Power[N[Exp[s], $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], t$95$2], $MachinePrecision] / N[Power[N[(1.0 - N[Power[N[(t$95$3 + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], t$95$2], $MachinePrecision]), $MachinePrecision], N[(N[(N[Power[t$95$1, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$1), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(-1.0 * N[Log[1 + t$95$3], $MachinePrecision]), $MachinePrecision] * c$95$p + 1.0), $MachinePrecision] * N[Power[N[(1.0 - N[(1.0 / N[(1.0 + N[Exp[N[(-1.0 * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\frac{{t\_1}^{c\_p} \cdot {\left(1 - t\_1\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left(t\_3\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-1 \cdot t}}\right)}^{c\_n}}\\


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

    1. Initial program 92.0%

      \[\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}{\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. Step-by-step derivation
      1. lower-/.f64N/A

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

      \[\leadsto \color{blue}{\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}} \]

    if 1e7 < (neg.f64 s)

    1. Initial program 50.0%

      \[\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 \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\color{blue}{\left(1 + c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)\right)} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\left(c\_p \cdot \log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) + \color{blue}{1}\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      2. *-commutativeN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\left(\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right) \cdot c\_p + 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      3. lower-fma.f64N/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(\log \left(\frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right), \color{blue}{c\_p}, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      4. inv-powN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(\log \left({\left(1 + e^{\mathsf{neg}\left(t\right)}\right)}^{-1}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      5. log-powN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \log \left(1 + e^{\mathsf{neg}\left(t\right)}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      6. lower-*.f64N/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \log \left(1 + e^{\mathsf{neg}\left(t\right)}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      7. lower-log1p.f64N/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left(e^{\mathsf{neg}\left(t\right)}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      8. exp-negN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left(\frac{1}{e^{t}}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      9. inv-powN/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left({\left(e^{t}\right)}^{-1}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      10. lower-pow.f64N/A

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left({\left(e^{t}\right)}^{-1}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
      11. lower-exp.f64100.0

        \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left({\left(e^{t}\right)}^{-1}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
    5. Applied rewrites100.0%

      \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\color{blue}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left({\left(e^{t}\right)}^{-1}\right), c\_p, 1\right)} \cdot {\left(1 - \frac{1}{1 + e^{-t}}\right)}^{c\_n}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;-1 \cdot s \leq 10000000:\\ \;\;\;\;\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{{\left(\frac{1}{1 + e^{-1 \cdot s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-1 \cdot s}}\right)}^{c\_n}}{\mathsf{fma}\left(-1 \cdot \mathsf{log1p}\left({\left(e^{t}\right)}^{-1}\right), c\_p, 1\right) \cdot {\left(1 - \frac{1}{1 + e^{-1 \cdot t}}\right)}^{c\_n}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 94.2% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\\ t_2 := \mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\\ t_3 := {0.5}^{c\_p} \cdot {0.5}^{c\_n}\\ t_4 := -1 \cdot \log 2\\ t_5 := \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\\ t_6 := t\_5 - t\_1\\ t_7 := \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\\ t_8 := t\_1 \cdot t\_1\\ t_9 := \mathsf{fma}\left(0.5, t\_8, t\_1 \cdot t\_6\right)\\ t_10 := \frac{1}{1 + e^{-1 \cdot s}}\\ t_11 := t\_5 \cdot t\_5\\ \mathbf{if}\;t \leq 1.9 \cdot 10^{-301}:\\ \;\;\;\;\frac{{t\_10}^{c\_p} \cdot {\left(1 - t\_10\right)}^{c\_n}}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, t\_3, \mathsf{fma}\left(\mathsf{fma}\left(-0.25 \cdot c\_n, \left(c\_p \cdot {0.5}^{c\_n}\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(c\_n, \mathsf{fma}\left(-0.125, {0.5}^{c\_p}, \mathsf{fma}\left(t, \mathsf{fma}\left(-0.5, t\_7, \mathsf{fma}\left(-0.0625, c\_p \cdot {0.5}^{c\_p}, t\_4 \cdot t\_2\right)\right), t\_4 \cdot t\_7\right)\right), \mathsf{fma}\left(t, t\_2, t\_7\right)\right)\right), t, \left(0.5 \cdot c\_p\right) \cdot t\_3\right)\right), t, t\_3\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + c\_n \cdot \left(\left(t\_5 + c\_n \cdot \left(\mathsf{fma}\left(0.5, t\_11, c\_n \cdot \left(0.16666666666666666 \cdot \left(t\_11 \cdot t\_5\right) - \mathsf{fma}\left(0.16666666666666666, t\_1 \cdot t\_8, 0.5 \cdot \left(t\_8 \cdot t\_6\right) + t\_1 \cdot \left(0.5 \cdot t\_11 - t\_9\right)\right)\right)\right) - t\_9\right)\right) - t\_1\right)\\ \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (log (- 1.0 (pow (+ 1.0 (pow (exp t) -1.0)) -1.0))))
        (t_2
         (*
          (fma
           -0.0625
           (* c_p c_p)
           (* 0.020833333333333332 (* (* c_p c_p) c_p)))
          (pow 0.5 c_p)))
        (t_3 (* (pow 0.5 c_p) (pow 0.5 c_n)))
        (t_4 (* -1.0 (log 2.0)))
        (t_5 (log (- 1.0 (pow (+ 1.0 (pow (exp s) -1.0)) -1.0))))
        (t_6 (- t_5 t_1))
        (t_7 (* (fma -0.125 c_p (* 0.125 (* c_p c_p))) (pow 0.5 c_p)))
        (t_8 (* t_1 t_1))
        (t_9 (fma 0.5 t_8 (* t_1 t_6)))
        (t_10 (/ 1.0 (+ 1.0 (exp (* -1.0 s)))))
        (t_11 (* t_5 t_5)))
   (if (<= t 1.9e-301)
     (/
      (* (pow t_10 c_p) (pow (- 1.0 t_10) c_n))
      (fma
       (fma
        (* -0.5 c_n)
        t_3
        (fma
         (fma
          (* -0.25 c_n)
          (* (* c_p (pow 0.5 c_n)) (pow 0.5 c_p))
          (fma
           c_n
           (fma
            -0.125
            (pow 0.5 c_p)
            (fma
             t
             (fma -0.5 t_7 (fma -0.0625 (* c_p (pow 0.5 c_p)) (* t_4 t_2)))
             (* t_4 t_7)))
           (fma t t_2 t_7)))
         t
         (* (* 0.5 c_p) t_3)))
       t
       t_3))
     (+
      1.0
      (*
       c_n
       (-
        (+
         t_5
         (*
          c_n
          (-
           (fma
            0.5
            t_11
            (*
             c_n
             (-
              (* 0.16666666666666666 (* t_11 t_5))
              (fma
               0.16666666666666666
               (* t_1 t_8)
               (+ (* 0.5 (* t_8 t_6)) (* t_1 (- (* 0.5 t_11) t_9)))))))
           t_9)))
        t_1))))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = log((1.0 - pow((1.0 + pow(exp(t), -1.0)), -1.0)));
	double t_2 = fma(-0.0625, (c_p * c_p), (0.020833333333333332 * ((c_p * c_p) * c_p))) * pow(0.5, c_p);
	double t_3 = pow(0.5, c_p) * pow(0.5, c_n);
	double t_4 = -1.0 * log(2.0);
	double t_5 = log((1.0 - pow((1.0 + pow(exp(s), -1.0)), -1.0)));
	double t_6 = t_5 - t_1;
	double t_7 = fma(-0.125, c_p, (0.125 * (c_p * c_p))) * pow(0.5, c_p);
	double t_8 = t_1 * t_1;
	double t_9 = fma(0.5, t_8, (t_1 * t_6));
	double t_10 = 1.0 / (1.0 + exp((-1.0 * s)));
	double t_11 = t_5 * t_5;
	double tmp;
	if (t <= 1.9e-301) {
		tmp = (pow(t_10, c_p) * pow((1.0 - t_10), c_n)) / fma(fma((-0.5 * c_n), t_3, fma(fma((-0.25 * c_n), ((c_p * pow(0.5, c_n)) * pow(0.5, c_p)), fma(c_n, fma(-0.125, pow(0.5, c_p), fma(t, fma(-0.5, t_7, fma(-0.0625, (c_p * pow(0.5, c_p)), (t_4 * t_2))), (t_4 * t_7))), fma(t, t_2, t_7))), t, ((0.5 * c_p) * t_3))), t, t_3);
	} else {
		tmp = 1.0 + (c_n * ((t_5 + (c_n * (fma(0.5, t_11, (c_n * ((0.16666666666666666 * (t_11 * t_5)) - fma(0.16666666666666666, (t_1 * t_8), ((0.5 * (t_8 * t_6)) + (t_1 * ((0.5 * t_11) - t_9))))))) - t_9))) - t_1));
	}
	return tmp;
}
function code(c_p, c_n, t, s)
	t_1 = log(Float64(1.0 - (Float64(1.0 + (exp(t) ^ -1.0)) ^ -1.0)))
	t_2 = Float64(fma(-0.0625, Float64(c_p * c_p), Float64(0.020833333333333332 * Float64(Float64(c_p * c_p) * c_p))) * (0.5 ^ c_p))
	t_3 = Float64((0.5 ^ c_p) * (0.5 ^ c_n))
	t_4 = Float64(-1.0 * log(2.0))
	t_5 = log(Float64(1.0 - (Float64(1.0 + (exp(s) ^ -1.0)) ^ -1.0)))
	t_6 = Float64(t_5 - t_1)
	t_7 = Float64(fma(-0.125, c_p, Float64(0.125 * Float64(c_p * c_p))) * (0.5 ^ c_p))
	t_8 = Float64(t_1 * t_1)
	t_9 = fma(0.5, t_8, Float64(t_1 * t_6))
	t_10 = Float64(1.0 / Float64(1.0 + exp(Float64(-1.0 * s))))
	t_11 = Float64(t_5 * t_5)
	tmp = 0.0
	if (t <= 1.9e-301)
		tmp = Float64(Float64((t_10 ^ c_p) * (Float64(1.0 - t_10) ^ c_n)) / fma(fma(Float64(-0.5 * c_n), t_3, fma(fma(Float64(-0.25 * c_n), Float64(Float64(c_p * (0.5 ^ c_n)) * (0.5 ^ c_p)), fma(c_n, fma(-0.125, (0.5 ^ c_p), fma(t, fma(-0.5, t_7, fma(-0.0625, Float64(c_p * (0.5 ^ c_p)), Float64(t_4 * t_2))), Float64(t_4 * t_7))), fma(t, t_2, t_7))), t, Float64(Float64(0.5 * c_p) * t_3))), t, t_3));
	else
		tmp = Float64(1.0 + Float64(c_n * Float64(Float64(t_5 + Float64(c_n * Float64(fma(0.5, t_11, Float64(c_n * Float64(Float64(0.16666666666666666 * Float64(t_11 * t_5)) - fma(0.16666666666666666, Float64(t_1 * t_8), Float64(Float64(0.5 * Float64(t_8 * t_6)) + Float64(t_1 * Float64(Float64(0.5 * t_11) - t_9))))))) - t_9))) - t_1)));
	end
	return tmp
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[Log[N[(1.0 - N[Power[N[(1.0 + N[Power[N[Exp[t], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[(-0.0625 * N[(c$95$p * c$95$p), $MachinePrecision] + N[(0.020833333333333332 * N[(N[(c$95$p * c$95$p), $MachinePrecision] * c$95$p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[0.5, c$95$p], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[Power[0.5, c$95$p], $MachinePrecision] * N[Power[0.5, c$95$n], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(-1.0 * N[Log[2.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Log[N[(1.0 - N[Power[N[(1.0 + N[Power[N[Exp[s], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$6 = N[(t$95$5 - t$95$1), $MachinePrecision]}, Block[{t$95$7 = N[(N[(-0.125 * c$95$p + N[(0.125 * N[(c$95$p * c$95$p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[0.5, c$95$p], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$8 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Block[{t$95$9 = N[(0.5 * t$95$8 + N[(t$95$1 * t$95$6), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$10 = N[(1.0 / N[(1.0 + N[Exp[N[(-1.0 * s), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$11 = N[(t$95$5 * t$95$5), $MachinePrecision]}, If[LessEqual[t, 1.9e-301], N[(N[(N[Power[t$95$10, c$95$p], $MachinePrecision] * N[Power[N[(1.0 - t$95$10), $MachinePrecision], c$95$n], $MachinePrecision]), $MachinePrecision] / N[(N[(N[(-0.5 * c$95$n), $MachinePrecision] * t$95$3 + N[(N[(N[(-0.25 * c$95$n), $MachinePrecision] * N[(N[(c$95$p * N[Power[0.5, c$95$n], $MachinePrecision]), $MachinePrecision] * N[Power[0.5, c$95$p], $MachinePrecision]), $MachinePrecision] + N[(c$95$n * N[(-0.125 * N[Power[0.5, c$95$p], $MachinePrecision] + N[(t * N[(-0.5 * t$95$7 + N[(-0.0625 * N[(c$95$p * N[Power[0.5, c$95$p], $MachinePrecision]), $MachinePrecision] + N[(t$95$4 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t$95$4 * t$95$7), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t * t$95$2 + t$95$7), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t + N[(N[(0.5 * c$95$p), $MachinePrecision] * t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * t + t$95$3), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(c$95$n * N[(N[(t$95$5 + N[(c$95$n * N[(N[(0.5 * t$95$11 + N[(c$95$n * N[(N[(0.16666666666666666 * N[(t$95$11 * t$95$5), $MachinePrecision]), $MachinePrecision] - N[(0.16666666666666666 * N[(t$95$1 * t$95$8), $MachinePrecision] + N[(N[(0.5 * N[(t$95$8 * t$95$6), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(N[(0.5 * t$95$11), $MachinePrecision] - t$95$9), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$9), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\\
t_2 := \mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\\
t_3 := {0.5}^{c\_p} \cdot {0.5}^{c\_n}\\
t_4 := -1 \cdot \log 2\\
t_5 := \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\\
t_6 := t\_5 - t\_1\\
t_7 := \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\\
t_8 := t\_1 \cdot t\_1\\
t_9 := \mathsf{fma}\left(0.5, t\_8, t\_1 \cdot t\_6\right)\\
t_10 := \frac{1}{1 + e^{-1 \cdot s}}\\
t_11 := t\_5 \cdot t\_5\\
\mathbf{if}\;t \leq 1.9 \cdot 10^{-301}:\\
\;\;\;\;\frac{{t\_10}^{c\_p} \cdot {\left(1 - t\_10\right)}^{c\_n}}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, t\_3, \mathsf{fma}\left(\mathsf{fma}\left(-0.25 \cdot c\_n, \left(c\_p \cdot {0.5}^{c\_n}\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(c\_n, \mathsf{fma}\left(-0.125, {0.5}^{c\_p}, \mathsf{fma}\left(t, \mathsf{fma}\left(-0.5, t\_7, \mathsf{fma}\left(-0.0625, c\_p \cdot {0.5}^{c\_p}, t\_4 \cdot t\_2\right)\right), t\_4 \cdot t\_7\right)\right), \mathsf{fma}\left(t, t\_2, t\_7\right)\right)\right), t, \left(0.5 \cdot c\_p\right) \cdot t\_3\right)\right), t, t\_3\right)}\\

\mathbf{else}:\\
\;\;\;\;1 + c\_n \cdot \left(\left(t\_5 + c\_n \cdot \left(\mathsf{fma}\left(0.5, t\_11, c\_n \cdot \left(0.16666666666666666 \cdot \left(t\_11 \cdot t\_5\right) - \mathsf{fma}\left(0.16666666666666666, t\_1 \cdot t\_8, 0.5 \cdot \left(t\_8 \cdot t\_6\right) + t\_1 \cdot \left(0.5 \cdot t\_11 - t\_9\right)\right)\right)\right) - t\_9\right)\right) - t\_1\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if t < 1.89999999999999998e-301

    1. Initial program 89.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 t around 0

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

      \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, {0.5}^{c\_p} \cdot {0.5}^{c\_n}, \mathsf{fma}\left(\mathsf{fma}\left(-0.25 \cdot c\_n, \left(c\_p \cdot {0.5}^{c\_n}\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, \mathsf{fma}\left(c\_p \cdot c\_p, 0.125, -0.125 \cdot c\_p\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right), \mathsf{fma}\left(0.5 \cdot c\_p, \mathsf{fma}\left(c\_n \cdot c\_n, 0.125, -0.125 \cdot c\_n\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right), \mathsf{fma}\left(\mathsf{fma}\left(0.0625, c\_n \cdot c\_n, \left(\left(c\_n \cdot c\_n\right) \cdot c\_n\right) \cdot -0.020833333333333332\right), {0.5}^{c\_p} \cdot {0.5}^{c\_n}, \mathsf{fma}\left(\left(c\_p \cdot c\_p\right) \cdot c\_p, 0.020833333333333332, -0.0625 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)\right)\right)\right), t, \mathsf{fma}\left(\mathsf{fma}\left(c\_p \cdot c\_p, 0.125, -0.125 \cdot c\_p\right), {0.5}^{c\_p} \cdot {0.5}^{c\_n}, \mathsf{fma}\left(c\_n \cdot c\_n, 0.125, -0.125 \cdot c\_n\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)\right)\right)\right), t, \left(0.5 \cdot c\_p\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)\right)\right), t, {0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)}} \]
    5. Taylor expanded in c_n around 0

      \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{2} \cdot c\_n, {\frac{1}{2}}^{c\_p} \cdot {\frac{1}{2}}^{c\_n}, \mathsf{fma}\left(\mathsf{fma}\left(\frac{-1}{4} \cdot c\_n, \left(c\_p \cdot {\frac{1}{2}}^{c\_n}\right) \cdot {\frac{1}{2}}^{c\_p}, c\_n \cdot \left(\frac{-1}{8} \cdot {\frac{1}{2}}^{c\_p} + \left(t \cdot \left(\frac{-1}{2} \cdot \left(\left(\frac{-1}{8} \cdot c\_p + \frac{1}{8} \cdot {c\_p}^{2}\right) \cdot {\frac{1}{2}}^{c\_p}\right) + \left(\frac{-1}{16} \cdot \left(c\_p \cdot {\frac{1}{2}}^{c\_p}\right) + \log \frac{1}{2} \cdot \left(\left(\frac{-1}{16} \cdot {c\_p}^{2} + \frac{1}{48} \cdot {c\_p}^{3}\right) \cdot {\frac{1}{2}}^{c\_p}\right)\right)\right) + \log \frac{1}{2} \cdot \left(\left(\frac{-1}{8} \cdot c\_p + \frac{1}{8} \cdot {c\_p}^{2}\right) \cdot {\frac{1}{2}}^{c\_p}\right)\right)\right) + \left(t \cdot \left(\left(\frac{-1}{16} \cdot {c\_p}^{2} + \frac{1}{48} \cdot {c\_p}^{3}\right) \cdot {\frac{1}{2}}^{c\_p}\right) + \left(\frac{-1}{8} \cdot c\_p + \frac{1}{8} \cdot {c\_p}^{2}\right) \cdot {\frac{1}{2}}^{c\_p}\right)\right), t, \left(\frac{1}{2} \cdot c\_p\right) \cdot \left({\frac{1}{2}}^{c\_p} \cdot {\frac{1}{2}}^{c\_n}\right)\right)\right), t, {\frac{1}{2}}^{c\_p} \cdot {\frac{1}{2}}^{c\_n}\right)} \]
    6. Applied rewrites95.1%

      \[\leadsto \frac{{\left(\frac{1}{1 + e^{-s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-s}}\right)}^{c\_n}}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, {0.5}^{c\_p} \cdot {0.5}^{c\_n}, \mathsf{fma}\left(\mathsf{fma}\left(-0.25 \cdot c\_n, \left(c\_p \cdot {0.5}^{c\_n}\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(c\_n, \mathsf{fma}\left(-0.125, {0.5}^{c\_p}, \mathsf{fma}\left(t, \mathsf{fma}\left(-0.5, \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(-0.0625, c\_p \cdot {0.5}^{c\_p}, \left(-1 \cdot \log 2\right) \cdot \left(\mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), \left(-1 \cdot \log 2\right) \cdot \left(\mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), \mathsf{fma}\left(t, \mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), t, \left(0.5 \cdot c\_p\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)\right)\right), t, {0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)} \]

    if 1.89999999999999998e-301 < t

    1. Initial program 93.1%

      \[\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}{\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. Step-by-step derivation
      1. lower-/.f64N/A

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

      \[\leadsto \color{blue}{\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}} \]
    6. Taylor expanded in c_n around 0

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

      \[\leadsto 1 + \color{blue}{c\_n \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) + c\_n \cdot \left(\mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right), c\_n \cdot \left(0.16666666666666666 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.16666666666666666, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right), 0.5 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right) + \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(0.5 \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \leq 1.9 \cdot 10^{-301}:\\ \;\;\;\;\frac{{\left(\frac{1}{1 + e^{-1 \cdot s}}\right)}^{c\_p} \cdot {\left(1 - \frac{1}{1 + e^{-1 \cdot s}}\right)}^{c\_n}}{\mathsf{fma}\left(\mathsf{fma}\left(-0.5 \cdot c\_n, {0.5}^{c\_p} \cdot {0.5}^{c\_n}, \mathsf{fma}\left(\mathsf{fma}\left(-0.25 \cdot c\_n, \left(c\_p \cdot {0.5}^{c\_n}\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(c\_n, \mathsf{fma}\left(-0.125, {0.5}^{c\_p}, \mathsf{fma}\left(t, \mathsf{fma}\left(-0.5, \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(-0.0625, c\_p \cdot {0.5}^{c\_p}, \left(-1 \cdot \log 2\right) \cdot \left(\mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), \left(-1 \cdot \log 2\right) \cdot \left(\mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), \mathsf{fma}\left(t, \mathsf{fma}\left(-0.0625, c\_p \cdot c\_p, 0.020833333333333332 \cdot \left(\left(c\_p \cdot c\_p\right) \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}, \mathsf{fma}\left(-0.125, c\_p, 0.125 \cdot \left(c\_p \cdot c\_p\right)\right) \cdot {0.5}^{c\_p}\right)\right)\right), t, \left(0.5 \cdot c\_p\right) \cdot \left({0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)\right)\right), t, {0.5}^{c\_p} \cdot {0.5}^{c\_n}\right)}\\ \mathbf{else}:\\ \;\;\;\;1 + c\_n \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) + c\_n \cdot \left(\mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right), c\_n \cdot \left(0.16666666666666666 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.16666666666666666, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right), 0.5 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right) + \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(0.5 \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 94.0% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{c\_n}{2} + \frac{c\_n}{2}\\ \frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{t\_1}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{t\_1}} \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (+ (/ c_n 2.0) (/ c_n 2.0))))
   (/
    (pow (- 1.0 (pow (+ (pow (exp s) -1.0) 1.0) -1.0)) t_1)
    (pow (- 1.0 (pow (+ (pow (exp t) -1.0) 1.0) -1.0)) t_1))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = (c_n / 2.0) + (c_n / 2.0);
	return pow((1.0 - pow((pow(exp(s), -1.0) + 1.0), -1.0)), t_1) / pow((1.0 - pow((pow(exp(t), -1.0) + 1.0), -1.0)), t_1);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(c_p, c_n, t, s)
use fmin_fmax_functions
    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
    t_1 = (c_n / 2.0d0) + (c_n / 2.0d0)
    code = ((1.0d0 - (((exp(s) ** (-1.0d0)) + 1.0d0) ** (-1.0d0))) ** t_1) / ((1.0d0 - (((exp(t) ** (-1.0d0)) + 1.0d0) ** (-1.0d0))) ** t_1)
end function
public static double code(double c_p, double c_n, double t, double s) {
	double t_1 = (c_n / 2.0) + (c_n / 2.0);
	return Math.pow((1.0 - Math.pow((Math.pow(Math.exp(s), -1.0) + 1.0), -1.0)), t_1) / Math.pow((1.0 - Math.pow((Math.pow(Math.exp(t), -1.0) + 1.0), -1.0)), t_1);
}
def code(c_p, c_n, t, s):
	t_1 = (c_n / 2.0) + (c_n / 2.0)
	return math.pow((1.0 - math.pow((math.pow(math.exp(s), -1.0) + 1.0), -1.0)), t_1) / math.pow((1.0 - math.pow((math.pow(math.exp(t), -1.0) + 1.0), -1.0)), t_1)
function code(c_p, c_n, t, s)
	t_1 = Float64(Float64(c_n / 2.0) + Float64(c_n / 2.0))
	return Float64((Float64(1.0 - (Float64((exp(s) ^ -1.0) + 1.0) ^ -1.0)) ^ t_1) / (Float64(1.0 - (Float64((exp(t) ^ -1.0) + 1.0) ^ -1.0)) ^ t_1))
end
function tmp = code(c_p, c_n, t, s)
	t_1 = (c_n / 2.0) + (c_n / 2.0);
	tmp = ((1.0 - (((exp(s) ^ -1.0) + 1.0) ^ -1.0)) ^ t_1) / ((1.0 - (((exp(t) ^ -1.0) + 1.0) ^ -1.0)) ^ t_1);
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[(N[(c$95$n / 2.0), $MachinePrecision] + N[(c$95$n / 2.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(1.0 - N[Power[N[(N[Power[N[Exp[s], $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], t$95$1], $MachinePrecision] / N[Power[N[(1.0 - N[Power[N[(N[Power[N[Exp[t], $MachinePrecision], -1.0], $MachinePrecision] + 1.0), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], t$95$1], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{c\_n}{2} + \frac{c\_n}{2}\\
\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{t\_1}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{t\_1}}
\end{array}
\end{array}
Derivation
  1. Initial program 91.1%

    \[\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}{\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. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{\color{blue}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
  5. Applied rewrites95.0%

    \[\leadsto \color{blue}{\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}} \]
  6. Add Preprocessing

Alternative 4: 93.6% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\\ t_2 := t\_1 \cdot t\_1\\ t_3 := \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\\ t_4 := t\_3 \cdot t\_3\\ t_5 := t\_1 - t\_3\\ t_6 := \mathsf{fma}\left(0.5, t\_4, t\_3 \cdot t\_5\right)\\ 1 + c\_n \cdot \left(\left(t\_1 + c\_n \cdot \left(\mathsf{fma}\left(0.5, t\_2, c\_n \cdot \left(0.16666666666666666 \cdot \left(t\_2 \cdot t\_1\right) - \mathsf{fma}\left(0.16666666666666666, t\_3 \cdot t\_4, 0.5 \cdot \left(t\_4 \cdot t\_5\right) + t\_3 \cdot \left(0.5 \cdot t\_2 - t\_6\right)\right)\right)\right) - t\_6\right)\right) - t\_3\right) \end{array} \end{array} \]
(FPCore (c_p c_n t s)
 :precision binary64
 (let* ((t_1 (log (- 1.0 (pow (+ 1.0 (pow (exp s) -1.0)) -1.0))))
        (t_2 (* t_1 t_1))
        (t_3 (log (- 1.0 (pow (+ 1.0 (pow (exp t) -1.0)) -1.0))))
        (t_4 (* t_3 t_3))
        (t_5 (- t_1 t_3))
        (t_6 (fma 0.5 t_4 (* t_3 t_5))))
   (+
    1.0
    (*
     c_n
     (-
      (+
       t_1
       (*
        c_n
        (-
         (fma
          0.5
          t_2
          (*
           c_n
           (-
            (* 0.16666666666666666 (* t_2 t_1))
            (fma
             0.16666666666666666
             (* t_3 t_4)
             (+ (* 0.5 (* t_4 t_5)) (* t_3 (- (* 0.5 t_2) t_6)))))))
         t_6)))
      t_3)))))
double code(double c_p, double c_n, double t, double s) {
	double t_1 = log((1.0 - pow((1.0 + pow(exp(s), -1.0)), -1.0)));
	double t_2 = t_1 * t_1;
	double t_3 = log((1.0 - pow((1.0 + pow(exp(t), -1.0)), -1.0)));
	double t_4 = t_3 * t_3;
	double t_5 = t_1 - t_3;
	double t_6 = fma(0.5, t_4, (t_3 * t_5));
	return 1.0 + (c_n * ((t_1 + (c_n * (fma(0.5, t_2, (c_n * ((0.16666666666666666 * (t_2 * t_1)) - fma(0.16666666666666666, (t_3 * t_4), ((0.5 * (t_4 * t_5)) + (t_3 * ((0.5 * t_2) - t_6))))))) - t_6))) - t_3));
}
function code(c_p, c_n, t, s)
	t_1 = log(Float64(1.0 - (Float64(1.0 + (exp(s) ^ -1.0)) ^ -1.0)))
	t_2 = Float64(t_1 * t_1)
	t_3 = log(Float64(1.0 - (Float64(1.0 + (exp(t) ^ -1.0)) ^ -1.0)))
	t_4 = Float64(t_3 * t_3)
	t_5 = Float64(t_1 - t_3)
	t_6 = fma(0.5, t_4, Float64(t_3 * t_5))
	return Float64(1.0 + Float64(c_n * Float64(Float64(t_1 + Float64(c_n * Float64(fma(0.5, t_2, Float64(c_n * Float64(Float64(0.16666666666666666 * Float64(t_2 * t_1)) - fma(0.16666666666666666, Float64(t_3 * t_4), Float64(Float64(0.5 * Float64(t_4 * t_5)) + Float64(t_3 * Float64(Float64(0.5 * t_2) - t_6))))))) - t_6))) - t_3)))
end
code[c$95$p_, c$95$n_, t_, s_] := Block[{t$95$1 = N[Log[N[(1.0 - N[Power[N[(1.0 + N[Power[N[Exp[s], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 * t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[Log[N[(1.0 - N[Power[N[(1.0 + N[Power[N[Exp[t], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[(t$95$3 * t$95$3), $MachinePrecision]}, Block[{t$95$5 = N[(t$95$1 - t$95$3), $MachinePrecision]}, Block[{t$95$6 = N[(0.5 * t$95$4 + N[(t$95$3 * t$95$5), $MachinePrecision]), $MachinePrecision]}, N[(1.0 + N[(c$95$n * N[(N[(t$95$1 + N[(c$95$n * N[(N[(0.5 * t$95$2 + N[(c$95$n * N[(N[(0.16666666666666666 * N[(t$95$2 * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(0.16666666666666666 * N[(t$95$3 * t$95$4), $MachinePrecision] + N[(N[(0.5 * N[(t$95$4 * t$95$5), $MachinePrecision]), $MachinePrecision] + N[(t$95$3 * N[(N[(0.5 * t$95$2), $MachinePrecision] - t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$6), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$3), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\\
t_2 := t\_1 \cdot t\_1\\
t_3 := \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\\
t_4 := t\_3 \cdot t\_3\\
t_5 := t\_1 - t\_3\\
t_6 := \mathsf{fma}\left(0.5, t\_4, t\_3 \cdot t\_5\right)\\
1 + c\_n \cdot \left(\left(t\_1 + c\_n \cdot \left(\mathsf{fma}\left(0.5, t\_2, c\_n \cdot \left(0.16666666666666666 \cdot \left(t\_2 \cdot t\_1\right) - \mathsf{fma}\left(0.16666666666666666, t\_3 \cdot t\_4, 0.5 \cdot \left(t\_4 \cdot t\_5\right) + t\_3 \cdot \left(0.5 \cdot t\_2 - t\_6\right)\right)\right)\right) - t\_6\right)\right) - t\_3\right)
\end{array}
\end{array}
Derivation
  1. Initial program 91.1%

    \[\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}{\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. Step-by-step derivation
    1. lower-/.f64N/A

      \[\leadsto \frac{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(s\right)}}\right)}^{c\_n}}{\color{blue}{{\left(1 - \frac{1}{1 + e^{\mathsf{neg}\left(t\right)}}\right)}^{c\_n}}} \]
  5. Applied rewrites95.0%

    \[\leadsto \color{blue}{\frac{{\left(1 - {\left({\left(e^{s}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}{{\left(1 - {\left({\left(e^{t}\right)}^{-1} + 1\right)}^{-1}\right)}^{\left(\frac{c\_n}{2} + \frac{c\_n}{2}\right)}}} \]
  6. Taylor expanded in c_n around 0

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

    \[\leadsto 1 + \color{blue}{c\_n \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) + c\_n \cdot \left(\mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right), c\_n \cdot \left(0.16666666666666666 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.16666666666666666, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right), 0.5 \cdot \left(\left(\log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right) + \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(0.5 \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right)\right)\right) - \mathsf{fma}\left(0.5, \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right), \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right) \cdot \left(\log \left(1 - {\left(1 + {\left(e^{s}\right)}^{-1}\right)}^{-1}\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)\right)\right)\right) - \log \left(1 - {\left(1 + {\left(e^{t}\right)}^{-1}\right)}^{-1}\right)\right)} \]
  8. Add Preprocessing

Reproduce

?
herbie shell --seed 2025065 
(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 c (* (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))))