Logistic distribution

Percentage Accurate: 99.5% → 99.3%
Time: 12.1s
Alternatives: 10
Speedup: 1.2×

Specification

?
\[0 \leq s \land s \leq 1.0651631\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := 1 + t_0\\ \frac{t_0}{\left(s \cdot t_1\right) \cdot t_1} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0)))
   (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = 1.0f + t_0;
	return t_0 / ((s * t_1) * t_1);
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: t_1
    t_0 = exp((-abs(x) / s))
    t_1 = 1.0e0 + t_0
    code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(Float32(1.0) + t_0)
	return Float32(t_0 / Float32(Float32(s * t_1) * t_1))
end
function tmp = code(x, s)
	t_0 = exp((-abs(x) / s));
	t_1 = single(1.0) + t_0;
	tmp = t_0 / ((s * t_1) * t_1);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\end{array}

Sampling outcomes in binary32 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 10 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := 1 + t_0\\ \frac{t_0}{\left(s \cdot t_1\right) \cdot t_1} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ 1.0 t_0)))
   (/ t_0 (* (* s t_1) t_1))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = 1.0f + t_0;
	return t_0 / ((s * t_1) * t_1);
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: t_1
    t_0 = exp((-abs(x) / s))
    t_1 = 1.0e0 + t_0
    code = t_0 / ((s * t_1) * t_1)
end function
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(Float32(1.0) + t_0)
	return Float32(t_0 / Float32(Float32(s * t_1) * t_1))
end
function tmp = code(x, s)
	t_0 = exp((-abs(x) / s));
	t_1 = single(1.0) + t_0;
	tmp = t_0 / ((s * t_1) * t_1);
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := 1 + t_0\\
\frac{t_0}{\left(s \cdot t_1\right) \cdot t_1}
\end{array}
\end{array}

Alternative 1: 99.3% accurate, 1.5× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.004000000189989805:\\ \;\;\;\;\frac{e^{\frac{x}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{e^{\frac{-x}{s}}}{s}}{4}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 0.004000000189989805)
   (/ (exp (+ (/ x s) (* -2.0 (log1p (exp (/ x s)))))) s)
   (/ (/ (exp (/ (- x) s)) s) 4.0)))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 0.004000000189989805f) {
		tmp = expf(((x / s) + (-2.0f * log1pf(expf((x / s)))))) / s;
	} else {
		tmp = (expf((-x / s)) / s) / 4.0f;
	}
	return tmp;
}
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(0.004000000189989805))
		tmp = Float32(exp(Float32(Float32(x / s) + Float32(Float32(-2.0) * log1p(exp(Float32(x / s)))))) / s);
	else
		tmp = Float32(Float32(exp(Float32(Float32(-x) / s)) / s) / Float32(4.0));
	end
	return tmp
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.004000000189989805:\\
\;\;\;\;\frac{e^{\frac{x}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{e^{\frac{-x}{s}}}{s}}{4}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (fabs.f32 x) < 0.00400000019

    1. Initial program 98.4%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*98.7%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified98.7%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Step-by-step derivation
      1. *-un-lft-identity98.7%

        \[\leadsto \frac{\color{blue}{1 \cdot e^{\frac{-\left|x\right|}{s}}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \]
      2. *-commutative98.7%

        \[\leadsto \frac{1 \cdot e^{\frac{-\left|x\right|}{s}}}{\color{blue}{\left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot s}} \]
      3. times-frac98.5%

        \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \cdot \frac{e^{\frac{-\left|x\right|}{s}}}{s}} \]
    5. Applied egg-rr82.2%

      \[\leadsto \color{blue}{\frac{1}{{\left(e^{\frac{x}{s}} + 1\right)}^{2}} \cdot \frac{e^{\frac{x}{s}}}{s}} \]
    6. Step-by-step derivation
      1. associate-*r/82.4%

        \[\leadsto \color{blue}{\frac{\frac{1}{{\left(e^{\frac{x}{s}} + 1\right)}^{2}} \cdot e^{\frac{x}{s}}}{s}} \]
      2. add-exp-log82.4%

        \[\leadsto \frac{\color{blue}{e^{\log \left(\frac{1}{{\left(e^{\frac{x}{s}} + 1\right)}^{2}}\right)}} \cdot e^{\frac{x}{s}}}{s} \]
      3. prod-exp97.8%

        \[\leadsto \frac{\color{blue}{e^{\log \left(\frac{1}{{\left(e^{\frac{x}{s}} + 1\right)}^{2}}\right) + \frac{x}{s}}}}{s} \]
      4. pow-flip97.8%

        \[\leadsto \frac{e^{\log \color{blue}{\left({\left(e^{\frac{x}{s}} + 1\right)}^{\left(-2\right)}\right)} + \frac{x}{s}}}{s} \]
      5. log-pow98.7%

        \[\leadsto \frac{e^{\color{blue}{\left(-2\right) \cdot \log \left(e^{\frac{x}{s}} + 1\right)} + \frac{x}{s}}}{s} \]
      6. metadata-eval98.7%

        \[\leadsto \frac{e^{\color{blue}{-2} \cdot \log \left(e^{\frac{x}{s}} + 1\right) + \frac{x}{s}}}{s} \]
      7. +-commutative98.7%

        \[\leadsto \frac{e^{-2 \cdot \log \color{blue}{\left(1 + e^{\frac{x}{s}}\right)} + \frac{x}{s}}}{s} \]
      8. log1p-udef98.7%

        \[\leadsto \frac{e^{-2 \cdot \color{blue}{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} + \frac{x}{s}}}{s} \]
    7. Applied egg-rr98.7%

      \[\leadsto \color{blue}{\frac{e^{-2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right) + \frac{x}{s}}}{s}} \]

    if 0.00400000019 < (fabs.f32 x)

    1. Initial program 100.0%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Taylor expanded in x around 0 100.0%

      \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s \cdot {\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
    5. Step-by-step derivation
      1. associate-/r*100.0%

        \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
      2. associate-*r/100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
      3. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
      4. +-commutative100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)}}^{2}} \]
      5. associate-*r/100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}} + 1\right)}^{2}} \]
      6. mul-1-neg100.0%

        \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{\color{blue}{-\left|x\right|}}{s}} + 1\right)}^{2}} \]
    6. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{-\left|x\right|}{s}} + 1\right)}^{2}}} \]
    7. Taylor expanded in s around inf 100.0%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{\color{blue}{4}} \]
    8. Step-by-step derivation
      1. distribute-frac-neg100.0%

        \[\leadsto \frac{\frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{s}}{4} \]
      2. exp-neg100.0%

        \[\leadsto \frac{\frac{\color{blue}{\frac{1}{e^{\frac{\left|x\right|}{s}}}}}{s}}{4} \]
      3. add-sqr-sqrt53.1%

        \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}}{s}}{4} \]
      4. fabs-sqr53.1%

        \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}}{s}}{4} \]
      5. add-sqr-sqrt54.6%

        \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\color{blue}{x}}{s}}}}{s}}{4} \]
    9. Applied egg-rr54.6%

      \[\leadsto \frac{\frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s}}{4} \]
    10. Step-by-step derivation
      1. rec-exp54.6%

        \[\leadsto \frac{\frac{\color{blue}{e^{-\frac{x}{s}}}}{s}}{4} \]
      2. distribute-neg-frac54.6%

        \[\leadsto \frac{\frac{e^{\color{blue}{\frac{-x}{s}}}}{s}}{4} \]
    11. Simplified54.6%

      \[\leadsto \frac{\frac{\color{blue}{e^{\frac{-x}{s}}}}{s}}{4} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.004000000189989805:\\ \;\;\;\;\frac{e^{\frac{x}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{e^{\frac{-x}{s}}}{s}}{4}\\ \end{array} \]

Alternative 2: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := t_0 + 1\\ \frac{t_0}{s \cdot \left(t_1 \cdot t_1\right)} \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ t_0 1.0)))
   (/ t_0 (* s (* t_1 t_1)))))
x = abs(x);
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = t_0 + 1.0f;
	return t_0 / (s * (t_1 * t_1));
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    real(4) :: t_1
    t_0 = exp((-abs(x) / s))
    t_1 = t_0 + 1.0e0
    code = t_0 / (s * (t_1 * t_1))
end function
x = abs(x)
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(t_0 + Float32(1.0))
	return Float32(t_0 / Float32(s * Float32(t_1 * t_1)))
end
x = abs(x)
function tmp = code(x, s)
	t_0 = exp((-abs(x) / s));
	t_1 = t_0 + single(1.0);
	tmp = t_0 / (s * (t_1 * t_1));
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := t_0 + 1\\
\frac{t_0}{s \cdot \left(t_1 \cdot t_1\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Step-by-step derivation
    1. associate-*l*99.4%

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  3. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  4. Final simplification99.4%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(e^{\frac{-\left|x\right|}{s}} + 1\right) \cdot \left(e^{\frac{-\left|x\right|}{s}} + 1\right)\right)} \]

Alternative 3: 99.5% accurate, 1.2× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* (fma s (exp (/ (fabs x) (- s))) s) (+ 1.0 (exp (/ (fabs x) s))))))
x = abs(x);
float code(float x, float s) {
	return 1.0f / (fmaf(s, expf((fabsf(x) / -s)), s) * (1.0f + expf((fabsf(x) / s))));
}
x = abs(x)
function code(x, s)
	return Float32(Float32(1.0) / Float32(fma(s, exp(Float32(abs(x) / Float32(-s))), s) * Float32(Float32(1.0) + exp(Float32(abs(x) / s)))))
end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}
\end{array}
Derivation
  1. Initial program 99.3%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Simplified99.4%

    \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
  3. Final simplification99.4%

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)} \]

Alternative 4: 99.5% accurate, 1.2× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ \frac{\frac{t_0}{s}}{{\left(t_0 + 1\right)}^{2}} \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ (/ t_0 s) (pow (+ t_0 1.0) 2.0))))
x = abs(x);
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	return (t_0 / s) / powf((t_0 + 1.0f), 2.0f);
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: t_0
    t_0 = exp((-abs(x) / s))
    code = (t_0 / s) / ((t_0 + 1.0e0) ** 2.0e0)
end function
x = abs(x)
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	return Float32(Float32(t_0 / s) / (Float32(t_0 + Float32(1.0)) ^ Float32(2.0)))
end
x = abs(x)
function tmp = code(x, s)
	t_0 = exp((-abs(x) / s));
	tmp = (t_0 / s) / ((t_0 + single(1.0)) ^ single(2.0));
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{\frac{t_0}{s}}{{\left(t_0 + 1\right)}^{2}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.3%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Step-by-step derivation
    1. associate-*l*99.4%

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  3. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  4. Taylor expanded in x around 0 99.4%

    \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s \cdot {\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. associate-/r*99.4%

      \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
    2. associate-*r/99.4%

      \[\leadsto \frac{\frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
    3. mul-1-neg99.4%

      \[\leadsto \frac{\frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
    4. +-commutative99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)}}^{2}} \]
    5. associate-*r/99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}} + 1\right)}^{2}} \]
    6. mul-1-neg99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{\color{blue}{-\left|x\right|}}{s}} + 1\right)}^{2}} \]
  6. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{-\left|x\right|}{s}} + 1\right)}^{2}}} \]
  7. Final simplification99.4%

    \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{-\left|x\right|}{s}} + 1\right)}^{2}} \]

Alternative 5: 73.5% accurate, 5.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{elif}\;x \leq 20000000000:\\ \;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{{x}^{2}}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= x 1.000000031374395e-22)
   (/ 0.25 s)
   (if (<= x 20000000000.0)
     (* 4.0 (/ (/ 1.0 (* (/ 1.0 s) (/ 1.0 s))) s))
     (/ s (pow x 2.0)))))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (x <= 1.000000031374395e-22f) {
		tmp = 0.25f / s;
	} else if (x <= 20000000000.0f) {
		tmp = 4.0f * ((1.0f / ((1.0f / s) * (1.0f / s))) / s);
	} else {
		tmp = s / powf(x, 2.0f);
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 1.000000031374395e-22) then
        tmp = 0.25e0 / s
    else if (x <= 20000000000.0e0) then
        tmp = 4.0e0 * ((1.0e0 / ((1.0e0 / s) * (1.0e0 / s))) / s)
    else
        tmp = s / (x ** 2.0e0)
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(1.000000031374395e-22))
		tmp = Float32(Float32(0.25) / s);
	elseif (x <= Float32(20000000000.0))
		tmp = Float32(Float32(4.0) * Float32(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / s))) / s));
	else
		tmp = Float32(s / (x ^ Float32(2.0)));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(1.000000031374395e-22))
		tmp = single(0.25) / s;
	elseif (x <= single(20000000000.0))
		tmp = single(4.0) * ((single(1.0) / ((single(1.0) / s) * (single(1.0) / s))) / s);
	else
		tmp = s / (x ^ single(2.0));
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{0.25}{s}\\

\mathbf{elif}\;x \leq 20000000000:\\
\;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{s}{{x}^{2}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if x < 1.00000003e-22

    1. Initial program 99.0%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.2%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.2%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Taylor expanded in s around inf 34.6%

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]

    if 1.00000003e-22 < x < 2e10

    1. Initial program 99.6%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.7%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Applied egg-rr90.4%

      \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(\log s + 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}} \]
    5. Taylor expanded in x around 0 22.1%

      \[\leadsto \color{blue}{e^{-\left(\log s + 2 \cdot \log 2\right)}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt19.3%

        \[\leadsto e^{\color{blue}{\sqrt{-\left(\log s + 2 \cdot \log 2\right)} \cdot \sqrt{-\left(\log s + 2 \cdot \log 2\right)}}} \]
      2. sqrt-unprod20.6%

        \[\leadsto e^{\color{blue}{\sqrt{\left(-\left(\log s + 2 \cdot \log 2\right)\right) \cdot \left(-\left(\log s + 2 \cdot \log 2\right)\right)}}} \]
      3. sqr-neg20.6%

        \[\leadsto e^{\sqrt{\color{blue}{\left(\log s + 2 \cdot \log 2\right) \cdot \left(\log s + 2 \cdot \log 2\right)}}} \]
      4. sqrt-unprod0.7%

        \[\leadsto e^{\color{blue}{\sqrt{\log s + 2 \cdot \log 2} \cdot \sqrt{\log s + 2 \cdot \log 2}}} \]
      5. add-sqr-sqrt12.9%

        \[\leadsto e^{\color{blue}{\log s + 2 \cdot \log 2}} \]
      6. exp-sum12.9%

        \[\leadsto \color{blue}{e^{\log s} \cdot e^{2 \cdot \log 2}} \]
      7. add-exp-log12.9%

        \[\leadsto \color{blue}{s} \cdot e^{2 \cdot \log 2} \]
      8. *-commutative12.9%

        \[\leadsto s \cdot e^{\color{blue}{\log 2 \cdot 2}} \]
      9. exp-to-pow12.9%

        \[\leadsto s \cdot \color{blue}{{2}^{2}} \]
      10. metadata-eval12.9%

        \[\leadsto s \cdot \color{blue}{4} \]
      11. +-lft-identity12.9%

        \[\leadsto \color{blue}{0 + s \cdot 4} \]
      12. mul0-rgt12.9%

        \[\leadsto \color{blue}{\left|x\right| \cdot 0} + s \cdot 4 \]
      13. flip-+51.9%

        \[\leadsto \color{blue}{\frac{\left(\left|x\right| \cdot 0\right) \cdot \left(\left|x\right| \cdot 0\right) - \left(s \cdot 4\right) \cdot \left(s \cdot 4\right)}{\left|x\right| \cdot 0 - s \cdot 4}} \]
    7. Applied egg-rr51.9%

      \[\leadsto \color{blue}{\frac{0}{-s \cdot 4} - \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    8. Step-by-step derivation
      1. div051.9%

        \[\leadsto \color{blue}{0} - \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      2. neg-sub051.9%

        \[\leadsto \color{blue}{-\frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      3. neg-mul-151.9%

        \[\leadsto \color{blue}{-1 \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      4. metadata-eval51.9%

        \[\leadsto \color{blue}{\frac{1}{-1}} \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      5. times-frac51.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left({s}^{2} \cdot 16\right)}{-1 \cdot \left(-s \cdot 4\right)}} \]
      6. neg-mul-151.9%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{-\left(-s \cdot 4\right)}} \]
      7. remove-double-neg51.9%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{s \cdot 4}} \]
      8. *-lft-identity51.9%

        \[\leadsto \frac{\color{blue}{{s}^{2} \cdot 16}}{s \cdot 4} \]
      9. *-commutative51.9%

        \[\leadsto \frac{\color{blue}{16 \cdot {s}^{2}}}{s \cdot 4} \]
      10. *-commutative51.9%

        \[\leadsto \frac{16 \cdot {s}^{2}}{\color{blue}{4 \cdot s}} \]
      11. times-frac51.9%

        \[\leadsto \color{blue}{\frac{16}{4} \cdot \frac{{s}^{2}}{s}} \]
      12. metadata-eval51.9%

        \[\leadsto \color{blue}{4} \cdot \frac{{s}^{2}}{s} \]
    9. Simplified51.9%

      \[\leadsto \color{blue}{4 \cdot \frac{{s}^{2}}{s}} \]
    10. Step-by-step derivation
      1. pow151.9%

        \[\leadsto 4 \cdot \frac{{\color{blue}{\left({s}^{1}\right)}}^{2}}{s} \]
      2. metadata-eval51.9%

        \[\leadsto 4 \cdot \frac{{\left({s}^{\color{blue}{\left(2 - 1\right)}}\right)}^{2}}{s} \]
      3. pow-div51.9%

        \[\leadsto 4 \cdot \frac{{\color{blue}{\left(\frac{{s}^{2}}{{s}^{1}}\right)}}^{2}}{s} \]
      4. pow151.9%

        \[\leadsto 4 \cdot \frac{{\left(\frac{{s}^{2}}{\color{blue}{s}}\right)}^{2}}{s} \]
      5. metadata-eval51.9%

        \[\leadsto 4 \cdot \frac{{\left(\frac{{s}^{2}}{s}\right)}^{\color{blue}{\left(1 + 1\right)}}}{s} \]
      6. pow-prod-up51.9%

        \[\leadsto 4 \cdot \frac{\color{blue}{{\left(\frac{{s}^{2}}{s}\right)}^{1} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}}{s} \]
      7. pow151.9%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{{s}^{2}}{s}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      8. clear-num51.9%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1}{\frac{s}{{s}^{2}}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      9. pow151.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{\color{blue}{{s}^{1}}}{{s}^{2}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      10. pow-div51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\color{blue}{{s}^{\left(1 - 2\right)}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      11. metadata-eval51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{{s}^{\color{blue}{-1}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      12. inv-pow51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\color{blue}{\frac{1}{s}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      13. pow151.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \color{blue}{\frac{{s}^{2}}{s}}}{s} \]
      14. clear-num51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \color{blue}{\frac{1}{\frac{s}{{s}^{2}}}}}{s} \]
      15. pow151.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\frac{\color{blue}{{s}^{1}}}{{s}^{2}}}}{s} \]
      16. pow-div51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\color{blue}{{s}^{\left(1 - 2\right)}}}}{s} \]
      17. metadata-eval51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{{s}^{\color{blue}{-1}}}}{s} \]
      18. inv-pow51.9%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\color{blue}{\frac{1}{s}}}}{s} \]
      19. frac-times61.4%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1 \cdot 1}{\frac{1}{s} \cdot \frac{1}{s}}}}{s} \]
      20. metadata-eval61.4%

        \[\leadsto 4 \cdot \frac{\frac{\color{blue}{1}}{\frac{1}{s} \cdot \frac{1}{s}}}{s} \]
    11. Applied egg-rr61.4%

      \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}}{s} \]

    if 2e10 < x

    1. Initial program 100.0%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Simplified100.0%

      \[\leadsto \color{blue}{\frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)}} \]
    3. Taylor expanded in s around -inf 30.3%

      \[\leadsto \frac{1}{\color{blue}{-2 \cdot \left|x\right| + \left(-1 \cdot \frac{-2 \cdot {\left(\left|x\right|\right)}^{2} + {\left(\left|x\right|\right)}^{2}}{s} + \left(2 \cdot \left|x\right| + 4 \cdot s\right)\right)}} \]
    4. Step-by-step derivation
      1. +-commutative30.3%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \color{blue}{\left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + -1 \cdot \frac{-2 \cdot {\left(\left|x\right|\right)}^{2} + {\left(\left|x\right|\right)}^{2}}{s}\right)}} \]
      2. mul-1-neg30.3%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \color{blue}{\left(-\frac{-2 \cdot {\left(\left|x\right|\right)}^{2} + {\left(\left|x\right|\right)}^{2}}{s}\right)}\right)} \]
      3. distribute-lft1-in95.7%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \left(-\frac{\color{blue}{\left(-2 + 1\right) \cdot {\left(\left|x\right|\right)}^{2}}}{s}\right)\right)} \]
      4. metadata-eval95.7%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \left(-\frac{\color{blue}{-1} \cdot {\left(\left|x\right|\right)}^{2}}{s}\right)\right)} \]
      5. associate-*r/95.7%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \left(-\color{blue}{-1 \cdot \frac{{\left(\left|x\right|\right)}^{2}}{s}}\right)\right)} \]
      6. mul-1-neg95.7%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \left(-\color{blue}{\left(-\frac{{\left(\left|x\right|\right)}^{2}}{s}\right)}\right)\right)} \]
      7. remove-double-neg95.7%

        \[\leadsto \frac{1}{-2 \cdot \left|x\right| + \left(\left(2 \cdot \left|x\right| + 4 \cdot s\right) + \color{blue}{\frac{{\left(\left|x\right|\right)}^{2}}{s}}\right)} \]
      8. associate-+r+95.7%

        \[\leadsto \frac{1}{\color{blue}{\left(-2 \cdot \left|x\right| + \left(2 \cdot \left|x\right| + 4 \cdot s\right)\right) + \frac{{\left(\left|x\right|\right)}^{2}}{s}}} \]
    5. Simplified95.7%

      \[\leadsto \frac{1}{\color{blue}{\left(\left|x\right| \cdot 0 + s \cdot 4\right) + \frac{x \cdot x}{s}}} \]
    6. Taylor expanded in x around inf 94.1%

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification52.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 1.000000031374395 \cdot 10^{-22}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{elif}\;x \leq 20000000000:\\ \;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{{x}^{2}}\\ \end{array} \]

Alternative 6: 95.0% accurate, 5.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{\frac{e^{\frac{-x}{s}}}{s}}{4} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s) :precision binary32 (/ (/ (exp (/ (- x) s)) s) 4.0))
x = abs(x);
float code(float x, float s) {
	return (expf((-x / s)) / s) / 4.0f;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = (exp((-x / s)) / s) / 4.0e0
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(exp(Float32(Float32(-x) / s)) / s) / Float32(4.0))
end
x = abs(x)
function tmp = code(x, s)
	tmp = (exp((-x / s)) / s) / single(4.0);
end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{e^{\frac{-x}{s}}}{s}}{4}
\end{array}
Derivation
  1. Initial program 99.3%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Step-by-step derivation
    1. associate-*l*99.4%

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  3. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  4. Taylor expanded in x around 0 99.4%

    \[\leadsto \color{blue}{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s \cdot {\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
  5. Step-by-step derivation
    1. associate-/r*99.4%

      \[\leadsto \color{blue}{\frac{\frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}}} \]
    2. associate-*r/99.4%

      \[\leadsto \frac{\frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
    3. mul-1-neg99.4%

      \[\leadsto \frac{\frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{s}}{{\left(1 + e^{-1 \cdot \frac{\left|x\right|}{s}}\right)}^{2}} \]
    4. +-commutative99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\color{blue}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right)}}^{2}} \]
    5. associate-*r/99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}} + 1\right)}^{2}} \]
    6. mul-1-neg99.4%

      \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{\color{blue}{-\left|x\right|}}{s}} + 1\right)}^{2}} \]
  6. Simplified99.4%

    \[\leadsto \color{blue}{\frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{{\left(e^{\frac{-\left|x\right|}{s}} + 1\right)}^{2}}} \]
  7. Taylor expanded in s around inf 95.1%

    \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{s}}{\color{blue}{4}} \]
  8. Step-by-step derivation
    1. distribute-frac-neg95.1%

      \[\leadsto \frac{\frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{s}}{4} \]
    2. exp-neg95.1%

      \[\leadsto \frac{\frac{\color{blue}{\frac{1}{e^{\frac{\left|x\right|}{s}}}}}{s}}{4} \]
    3. add-sqr-sqrt46.9%

      \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}}{s}}{4} \]
    4. fabs-sqr46.9%

      \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}}{s}}{4} \]
    5. add-sqr-sqrt58.3%

      \[\leadsto \frac{\frac{\frac{1}{e^{\frac{\color{blue}{x}}{s}}}}{s}}{4} \]
  9. Applied egg-rr58.3%

    \[\leadsto \frac{\frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s}}{4} \]
  10. Step-by-step derivation
    1. rec-exp58.4%

      \[\leadsto \frac{\frac{\color{blue}{e^{-\frac{x}{s}}}}{s}}{4} \]
    2. distribute-neg-frac58.4%

      \[\leadsto \frac{\frac{e^{\color{blue}{\frac{-x}{s}}}}{s}}{4} \]
  11. Simplified58.4%

    \[\leadsto \frac{\frac{\color{blue}{e^{\frac{-x}{s}}}}{s}}{4} \]
  12. Final simplification58.4%

    \[\leadsto \frac{\frac{e^{\frac{-x}{s}}}{s}}{4} \]

Alternative 7: 62.6% accurate, 41.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;s \leq 3.99999987306209 \cdot 10^{-20}:\\ \;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= s 3.99999987306209e-20)
   (* 4.0 (/ (/ 1.0 (* (/ 1.0 s) (/ 1.0 s))) s))
   (/ 0.25 s)))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (s <= 3.99999987306209e-20f) {
		tmp = 4.0f * ((1.0f / ((1.0f / s) * (1.0f / s))) / s);
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (s <= 3.99999987306209e-20) then
        tmp = 4.0e0 * ((1.0e0 / ((1.0e0 / s) * (1.0e0 / s))) / s)
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (s <= Float32(3.99999987306209e-20))
		tmp = Float32(Float32(4.0) * Float32(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / s))) / s));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (s <= single(3.99999987306209e-20))
		tmp = single(4.0) * ((single(1.0) / ((single(1.0) / s) * (single(1.0) / s))) / s);
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;s \leq 3.99999987306209 \cdot 10^{-20}:\\
\;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 3.99999987e-20

    1. Initial program 99.1%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.2%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.2%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Applied egg-rr70.1%

      \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(\log s + 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}} \]
    5. Taylor expanded in x around 0 9.6%

      \[\leadsto \color{blue}{e^{-\left(\log s + 2 \cdot \log 2\right)}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt9.4%

        \[\leadsto e^{\color{blue}{\sqrt{-\left(\log s + 2 \cdot \log 2\right)} \cdot \sqrt{-\left(\log s + 2 \cdot \log 2\right)}}} \]
      2. sqrt-unprod9.6%

        \[\leadsto e^{\color{blue}{\sqrt{\left(-\left(\log s + 2 \cdot \log 2\right)\right) \cdot \left(-\left(\log s + 2 \cdot \log 2\right)\right)}}} \]
      3. sqr-neg9.6%

        \[\leadsto e^{\sqrt{\color{blue}{\left(\log s + 2 \cdot \log 2\right) \cdot \left(\log s + 2 \cdot \log 2\right)}}} \]
      4. sqrt-unprod-0.0%

        \[\leadsto e^{\color{blue}{\sqrt{\log s + 2 \cdot \log 2} \cdot \sqrt{\log s + 2 \cdot \log 2}}} \]
      5. add-sqr-sqrt12.9%

        \[\leadsto e^{\color{blue}{\log s + 2 \cdot \log 2}} \]
      6. exp-sum12.9%

        \[\leadsto \color{blue}{e^{\log s} \cdot e^{2 \cdot \log 2}} \]
      7. add-exp-log12.9%

        \[\leadsto \color{blue}{s} \cdot e^{2 \cdot \log 2} \]
      8. *-commutative12.9%

        \[\leadsto s \cdot e^{\color{blue}{\log 2 \cdot 2}} \]
      9. exp-to-pow12.9%

        \[\leadsto s \cdot \color{blue}{{2}^{2}} \]
      10. metadata-eval12.9%

        \[\leadsto s \cdot \color{blue}{4} \]
      11. +-lft-identity12.9%

        \[\leadsto \color{blue}{0 + s \cdot 4} \]
      12. mul0-rgt12.9%

        \[\leadsto \color{blue}{\left|x\right| \cdot 0} + s \cdot 4 \]
      13. flip-+73.4%

        \[\leadsto \color{blue}{\frac{\left(\left|x\right| \cdot 0\right) \cdot \left(\left|x\right| \cdot 0\right) - \left(s \cdot 4\right) \cdot \left(s \cdot 4\right)}{\left|x\right| \cdot 0 - s \cdot 4}} \]
    7. Applied egg-rr76.3%

      \[\leadsto \color{blue}{\frac{0}{-s \cdot 4} - \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    8. Step-by-step derivation
      1. div076.3%

        \[\leadsto \color{blue}{0} - \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      2. neg-sub076.3%

        \[\leadsto \color{blue}{-\frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      3. neg-mul-176.3%

        \[\leadsto \color{blue}{-1 \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      4. metadata-eval76.3%

        \[\leadsto \color{blue}{\frac{1}{-1}} \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      5. times-frac76.3%

        \[\leadsto \color{blue}{\frac{1 \cdot \left({s}^{2} \cdot 16\right)}{-1 \cdot \left(-s \cdot 4\right)}} \]
      6. neg-mul-176.3%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{-\left(-s \cdot 4\right)}} \]
      7. remove-double-neg76.3%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{s \cdot 4}} \]
      8. *-lft-identity76.3%

        \[\leadsto \frac{\color{blue}{{s}^{2} \cdot 16}}{s \cdot 4} \]
      9. *-commutative76.3%

        \[\leadsto \frac{\color{blue}{16 \cdot {s}^{2}}}{s \cdot 4} \]
      10. *-commutative76.3%

        \[\leadsto \frac{16 \cdot {s}^{2}}{\color{blue}{4 \cdot s}} \]
      11. times-frac76.3%

        \[\leadsto \color{blue}{\frac{16}{4} \cdot \frac{{s}^{2}}{s}} \]
      12. metadata-eval76.3%

        \[\leadsto \color{blue}{4} \cdot \frac{{s}^{2}}{s} \]
    9. Simplified76.3%

      \[\leadsto \color{blue}{4 \cdot \frac{{s}^{2}}{s}} \]
    10. Step-by-step derivation
      1. pow176.3%

        \[\leadsto 4 \cdot \frac{{\color{blue}{\left({s}^{1}\right)}}^{2}}{s} \]
      2. metadata-eval76.3%

        \[\leadsto 4 \cdot \frac{{\left({s}^{\color{blue}{\left(2 - 1\right)}}\right)}^{2}}{s} \]
      3. pow-div76.3%

        \[\leadsto 4 \cdot \frac{{\color{blue}{\left(\frac{{s}^{2}}{{s}^{1}}\right)}}^{2}}{s} \]
      4. pow176.3%

        \[\leadsto 4 \cdot \frac{{\left(\frac{{s}^{2}}{\color{blue}{s}}\right)}^{2}}{s} \]
      5. metadata-eval76.3%

        \[\leadsto 4 \cdot \frac{{\left(\frac{{s}^{2}}{s}\right)}^{\color{blue}{\left(1 + 1\right)}}}{s} \]
      6. pow-prod-up76.3%

        \[\leadsto 4 \cdot \frac{\color{blue}{{\left(\frac{{s}^{2}}{s}\right)}^{1} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}}{s} \]
      7. pow176.3%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{{s}^{2}}{s}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      8. clear-num76.3%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1}{\frac{s}{{s}^{2}}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      9. pow176.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{\color{blue}{{s}^{1}}}{{s}^{2}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      10. pow-div76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\color{blue}{{s}^{\left(1 - 2\right)}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      11. metadata-eval76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{{s}^{\color{blue}{-1}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      12. inv-pow76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\color{blue}{\frac{1}{s}}} \cdot {\left(\frac{{s}^{2}}{s}\right)}^{1}}{s} \]
      13. pow176.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \color{blue}{\frac{{s}^{2}}{s}}}{s} \]
      14. clear-num76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \color{blue}{\frac{1}{\frac{s}{{s}^{2}}}}}{s} \]
      15. pow176.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\frac{\color{blue}{{s}^{1}}}{{s}^{2}}}}{s} \]
      16. pow-div76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\color{blue}{{s}^{\left(1 - 2\right)}}}}{s} \]
      17. metadata-eval76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{{s}^{\color{blue}{-1}}}}{s} \]
      18. inv-pow76.3%

        \[\leadsto 4 \cdot \frac{\frac{1}{\frac{1}{s}} \cdot \frac{1}{\color{blue}{\frac{1}{s}}}}{s} \]
      19. frac-times91.6%

        \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1 \cdot 1}{\frac{1}{s} \cdot \frac{1}{s}}}}{s} \]
      20. metadata-eval91.6%

        \[\leadsto 4 \cdot \frac{\frac{\color{blue}{1}}{\frac{1}{s} \cdot \frac{1}{s}}}{s} \]
    11. Applied egg-rr91.6%

      \[\leadsto 4 \cdot \frac{\color{blue}{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}}{s} \]

    if 3.99999987e-20 < s

    1. Initial program 99.5%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.7%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Taylor expanded in s around inf 40.5%

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification65.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 3.99999987306209 \cdot 10^{-20}:\\ \;\;\;\;4 \cdot \frac{\frac{1}{\frac{1}{s} \cdot \frac{1}{s}}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 8: 58.5% accurate, 67.9× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;s \leq 2.5000000784359874 \cdot 10^{-23}:\\ \;\;\;\;4 \cdot \frac{s \cdot s}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= s 2.5000000784359874e-23) (* 4.0 (/ (* s s) s)) (/ 0.25 s)))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (s <= 2.5000000784359874e-23f) {
		tmp = 4.0f * ((s * s) / s);
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (s <= 2.5000000784359874e-23) then
        tmp = 4.0e0 * ((s * s) / s)
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (s <= Float32(2.5000000784359874e-23))
		tmp = Float32(Float32(4.0) * Float32(Float32(s * s) / s));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (s <= single(2.5000000784359874e-23))
		tmp = single(4.0) * ((s * s) / s);
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;s \leq 2.5000000784359874 \cdot 10^{-23}:\\
\;\;\;\;4 \cdot \frac{s \cdot s}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 2.50000008e-23

    1. Initial program 98.9%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.0%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.0%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Applied egg-rr68.2%

      \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(\log s + 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}} \]
    5. Taylor expanded in x around 0 8.3%

      \[\leadsto \color{blue}{e^{-\left(\log s + 2 \cdot \log 2\right)}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt8.0%

        \[\leadsto e^{\color{blue}{\sqrt{-\left(\log s + 2 \cdot \log 2\right)} \cdot \sqrt{-\left(\log s + 2 \cdot \log 2\right)}}} \]
      2. sqrt-unprod8.3%

        \[\leadsto e^{\color{blue}{\sqrt{\left(-\left(\log s + 2 \cdot \log 2\right)\right) \cdot \left(-\left(\log s + 2 \cdot \log 2\right)\right)}}} \]
      3. sqr-neg8.3%

        \[\leadsto e^{\sqrt{\color{blue}{\left(\log s + 2 \cdot \log 2\right) \cdot \left(\log s + 2 \cdot \log 2\right)}}} \]
      4. sqrt-unprod-0.0%

        \[\leadsto e^{\color{blue}{\sqrt{\log s + 2 \cdot \log 2} \cdot \sqrt{\log s + 2 \cdot \log 2}}} \]
      5. add-sqr-sqrt13.8%

        \[\leadsto e^{\color{blue}{\log s + 2 \cdot \log 2}} \]
      6. exp-sum13.8%

        \[\leadsto \color{blue}{e^{\log s} \cdot e^{2 \cdot \log 2}} \]
      7. add-exp-log13.8%

        \[\leadsto \color{blue}{s} \cdot e^{2 \cdot \log 2} \]
      8. *-commutative13.8%

        \[\leadsto s \cdot e^{\color{blue}{\log 2 \cdot 2}} \]
      9. exp-to-pow13.8%

        \[\leadsto s \cdot \color{blue}{{2}^{2}} \]
      10. metadata-eval13.8%

        \[\leadsto s \cdot \color{blue}{4} \]
      11. +-lft-identity13.8%

        \[\leadsto \color{blue}{0 + s \cdot 4} \]
      12. mul0-rgt13.8%

        \[\leadsto \color{blue}{\left|x\right| \cdot 0} + s \cdot 4 \]
      13. flip-+88.8%

        \[\leadsto \color{blue}{\frac{\left(\left|x\right| \cdot 0\right) \cdot \left(\left|x\right| \cdot 0\right) - \left(s \cdot 4\right) \cdot \left(s \cdot 4\right)}{\left|x\right| \cdot 0 - s \cdot 4}} \]
    7. Applied egg-rr92.4%

      \[\leadsto \color{blue}{\frac{0}{-s \cdot 4} - \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    8. Step-by-step derivation
      1. div092.4%

        \[\leadsto \color{blue}{0} - \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      2. neg-sub092.4%

        \[\leadsto \color{blue}{-\frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      3. neg-mul-192.4%

        \[\leadsto \color{blue}{-1 \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      4. metadata-eval92.4%

        \[\leadsto \color{blue}{\frac{1}{-1}} \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      5. times-frac92.4%

        \[\leadsto \color{blue}{\frac{1 \cdot \left({s}^{2} \cdot 16\right)}{-1 \cdot \left(-s \cdot 4\right)}} \]
      6. neg-mul-192.4%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{-\left(-s \cdot 4\right)}} \]
      7. remove-double-neg92.4%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{s \cdot 4}} \]
      8. *-lft-identity92.4%

        \[\leadsto \frac{\color{blue}{{s}^{2} \cdot 16}}{s \cdot 4} \]
      9. *-commutative92.4%

        \[\leadsto \frac{\color{blue}{16 \cdot {s}^{2}}}{s \cdot 4} \]
      10. *-commutative92.4%

        \[\leadsto \frac{16 \cdot {s}^{2}}{\color{blue}{4 \cdot s}} \]
      11. times-frac92.4%

        \[\leadsto \color{blue}{\frac{16}{4} \cdot \frac{{s}^{2}}{s}} \]
      12. metadata-eval92.4%

        \[\leadsto \color{blue}{4} \cdot \frac{{s}^{2}}{s} \]
    9. Simplified92.4%

      \[\leadsto \color{blue}{4 \cdot \frac{{s}^{2}}{s}} \]
    10. Step-by-step derivation
      1. unpow292.4%

        \[\leadsto 4 \cdot \frac{\color{blue}{s \cdot s}}{s} \]
    11. Applied egg-rr92.4%

      \[\leadsto 4 \cdot \frac{\color{blue}{s \cdot s}}{s} \]

    if 2.50000008e-23 < s

    1. Initial program 99.5%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.7%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Taylor expanded in s around inf 36.8%

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification58.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 2.5000000784359874 \cdot 10^{-23}:\\ \;\;\;\;4 \cdot \frac{s \cdot s}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 9: 30.4% accurate, 121.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 5.000000058430487 \cdot 10^{-8}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;s \cdot 4\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= x 5.000000058430487e-8) (/ 0.25 s) (* s 4.0)))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (x <= 5.000000058430487e-8f) {
		tmp = 0.25f / s;
	} else {
		tmp = s * 4.0f;
	}
	return tmp;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 5.000000058430487e-8) then
        tmp = 0.25e0 / s
    else
        tmp = s * 4.0e0
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(5.000000058430487e-8))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(s * Float32(4.0));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(5.000000058430487e-8))
		tmp = single(0.25) / s;
	else
		tmp = s * single(4.0);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5.000000058430487 \cdot 10^{-8}:\\
\;\;\;\;\frac{0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;s \cdot 4\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 5.00000006e-8

    1. Initial program 99.0%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*99.2%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified99.2%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Taylor expanded in s around inf 35.5%

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]

    if 5.00000006e-8 < x

    1. Initial program 100.0%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

        \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
    4. Applied egg-rr48.1%

      \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(\log s + 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}} \]
    5. Taylor expanded in x around 0 4.9%

      \[\leadsto \color{blue}{e^{-\left(\log s + 2 \cdot \log 2\right)}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt4.7%

        \[\leadsto e^{\color{blue}{\sqrt{-\left(\log s + 2 \cdot \log 2\right)} \cdot \sqrt{-\left(\log s + 2 \cdot \log 2\right)}}} \]
      2. sqrt-unprod4.9%

        \[\leadsto e^{\color{blue}{\sqrt{\left(-\left(\log s + 2 \cdot \log 2\right)\right) \cdot \left(-\left(\log s + 2 \cdot \log 2\right)\right)}}} \]
      3. sqr-neg4.9%

        \[\leadsto e^{\sqrt{\color{blue}{\left(\log s + 2 \cdot \log 2\right) \cdot \left(\log s + 2 \cdot \log 2\right)}}} \]
      4. sqrt-unprod0.2%

        \[\leadsto e^{\color{blue}{\sqrt{\log s + 2 \cdot \log 2} \cdot \sqrt{\log s + 2 \cdot \log 2}}} \]
      5. add-sqr-sqrt11.6%

        \[\leadsto e^{\color{blue}{\log s + 2 \cdot \log 2}} \]
      6. exp-sum11.6%

        \[\leadsto \color{blue}{e^{\log s} \cdot e^{2 \cdot \log 2}} \]
      7. add-exp-log11.6%

        \[\leadsto \color{blue}{s} \cdot e^{2 \cdot \log 2} \]
      8. *-commutative11.6%

        \[\leadsto s \cdot e^{\color{blue}{\log 2 \cdot 2}} \]
      9. exp-to-pow11.6%

        \[\leadsto s \cdot \color{blue}{{2}^{2}} \]
      10. metadata-eval11.6%

        \[\leadsto s \cdot \color{blue}{4} \]
      11. +-lft-identity11.6%

        \[\leadsto \color{blue}{0 + s \cdot 4} \]
      12. mul0-rgt11.6%

        \[\leadsto \color{blue}{\left|x\right| \cdot 0} + s \cdot 4 \]
      13. flip-+54.8%

        \[\leadsto \color{blue}{\frac{\left(\left|x\right| \cdot 0\right) \cdot \left(\left|x\right| \cdot 0\right) - \left(s \cdot 4\right) \cdot \left(s \cdot 4\right)}{\left|x\right| \cdot 0 - s \cdot 4}} \]
    7. Applied egg-rr55.9%

      \[\leadsto \color{blue}{\frac{0}{-s \cdot 4} - \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    8. Step-by-step derivation
      1. div055.9%

        \[\leadsto \color{blue}{0} - \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      2. neg-sub055.9%

        \[\leadsto \color{blue}{-\frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      3. neg-mul-155.9%

        \[\leadsto \color{blue}{-1 \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
      4. metadata-eval55.9%

        \[\leadsto \color{blue}{\frac{1}{-1}} \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
      5. times-frac55.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left({s}^{2} \cdot 16\right)}{-1 \cdot \left(-s \cdot 4\right)}} \]
      6. neg-mul-155.9%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{-\left(-s \cdot 4\right)}} \]
      7. remove-double-neg55.9%

        \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{s \cdot 4}} \]
      8. *-lft-identity55.9%

        \[\leadsto \frac{\color{blue}{{s}^{2} \cdot 16}}{s \cdot 4} \]
      9. *-commutative55.9%

        \[\leadsto \frac{\color{blue}{16 \cdot {s}^{2}}}{s \cdot 4} \]
      10. *-commutative55.9%

        \[\leadsto \frac{16 \cdot {s}^{2}}{\color{blue}{4 \cdot s}} \]
      11. times-frac55.9%

        \[\leadsto \color{blue}{\frac{16}{4} \cdot \frac{{s}^{2}}{s}} \]
      12. metadata-eval55.9%

        \[\leadsto \color{blue}{4} \cdot \frac{{s}^{2}}{s} \]
    9. Simplified55.9%

      \[\leadsto \color{blue}{4 \cdot \frac{{s}^{2}}{s}} \]
    10. Taylor expanded in s around 0 11.6%

      \[\leadsto 4 \cdot \color{blue}{s} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 5.000000058430487 \cdot 10^{-8}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;s \cdot 4\\ \end{array} \]

Alternative 10: 10.9% accurate, 206.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ s \cdot 4 \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s) :precision binary32 (* s 4.0))
x = abs(x);
float code(float x, float s) {
	return s * 4.0f;
}
NOTE: x should be positive before calling this function
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = s * 4.0e0
end function
x = abs(x)
function code(x, s)
	return Float32(s * Float32(4.0))
end
x = abs(x)
function tmp = code(x, s)
	tmp = s * single(4.0);
end
\begin{array}{l}
x = |x|\\
\\
s \cdot 4
\end{array}
Derivation
  1. Initial program 99.3%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Step-by-step derivation
    1. associate-*l*99.4%

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  3. Simplified99.4%

    \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  4. Applied egg-rr81.2%

    \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(\log s + 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}} \]
  5. Taylor expanded in x around 0 24.4%

    \[\leadsto \color{blue}{e^{-\left(\log s + 2 \cdot \log 2\right)}} \]
  6. Step-by-step derivation
    1. add-sqr-sqrt22.8%

      \[\leadsto e^{\color{blue}{\sqrt{-\left(\log s + 2 \cdot \log 2\right)} \cdot \sqrt{-\left(\log s + 2 \cdot \log 2\right)}}} \]
    2. sqrt-unprod23.6%

      \[\leadsto e^{\color{blue}{\sqrt{\left(-\left(\log s + 2 \cdot \log 2\right)\right) \cdot \left(-\left(\log s + 2 \cdot \log 2\right)\right)}}} \]
    3. sqr-neg23.6%

      \[\leadsto e^{\sqrt{\color{blue}{\left(\log s + 2 \cdot \log 2\right) \cdot \left(\log s + 2 \cdot \log 2\right)}}} \]
    4. sqrt-unprod0.4%

      \[\leadsto e^{\color{blue}{\sqrt{\log s + 2 \cdot \log 2} \cdot \sqrt{\log s + 2 \cdot \log 2}}} \]
    5. add-sqr-sqrt11.1%

      \[\leadsto e^{\color{blue}{\log s + 2 \cdot \log 2}} \]
    6. exp-sum11.1%

      \[\leadsto \color{blue}{e^{\log s} \cdot e^{2 \cdot \log 2}} \]
    7. add-exp-log11.1%

      \[\leadsto \color{blue}{s} \cdot e^{2 \cdot \log 2} \]
    8. *-commutative11.1%

      \[\leadsto s \cdot e^{\color{blue}{\log 2 \cdot 2}} \]
    9. exp-to-pow11.1%

      \[\leadsto s \cdot \color{blue}{{2}^{2}} \]
    10. metadata-eval11.1%

      \[\leadsto s \cdot \color{blue}{4} \]
    11. +-lft-identity11.1%

      \[\leadsto \color{blue}{0 + s \cdot 4} \]
    12. mul0-rgt11.1%

      \[\leadsto \color{blue}{\left|x\right| \cdot 0} + s \cdot 4 \]
    13. flip-+40.5%

      \[\leadsto \color{blue}{\frac{\left(\left|x\right| \cdot 0\right) \cdot \left(\left|x\right| \cdot 0\right) - \left(s \cdot 4\right) \cdot \left(s \cdot 4\right)}{\left|x\right| \cdot 0 - s \cdot 4}} \]
  7. Applied egg-rr41.9%

    \[\leadsto \color{blue}{\frac{0}{-s \cdot 4} - \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
  8. Step-by-step derivation
    1. div041.9%

      \[\leadsto \color{blue}{0} - \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
    2. neg-sub041.9%

      \[\leadsto \color{blue}{-\frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    3. neg-mul-141.9%

      \[\leadsto \color{blue}{-1 \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4}} \]
    4. metadata-eval41.9%

      \[\leadsto \color{blue}{\frac{1}{-1}} \cdot \frac{{s}^{2} \cdot 16}{-s \cdot 4} \]
    5. times-frac41.9%

      \[\leadsto \color{blue}{\frac{1 \cdot \left({s}^{2} \cdot 16\right)}{-1 \cdot \left(-s \cdot 4\right)}} \]
    6. neg-mul-141.9%

      \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{-\left(-s \cdot 4\right)}} \]
    7. remove-double-neg41.9%

      \[\leadsto \frac{1 \cdot \left({s}^{2} \cdot 16\right)}{\color{blue}{s \cdot 4}} \]
    8. *-lft-identity41.9%

      \[\leadsto \frac{\color{blue}{{s}^{2} \cdot 16}}{s \cdot 4} \]
    9. *-commutative41.9%

      \[\leadsto \frac{\color{blue}{16 \cdot {s}^{2}}}{s \cdot 4} \]
    10. *-commutative41.9%

      \[\leadsto \frac{16 \cdot {s}^{2}}{\color{blue}{4 \cdot s}} \]
    11. times-frac41.9%

      \[\leadsto \color{blue}{\frac{16}{4} \cdot \frac{{s}^{2}}{s}} \]
    12. metadata-eval41.9%

      \[\leadsto \color{blue}{4} \cdot \frac{{s}^{2}}{s} \]
  9. Simplified41.9%

    \[\leadsto \color{blue}{4 \cdot \frac{{s}^{2}}{s}} \]
  10. Taylor expanded in s around 0 11.1%

    \[\leadsto 4 \cdot \color{blue}{s} \]
  11. Final simplification11.1%

    \[\leadsto s \cdot 4 \]

Reproduce

?
herbie shell --seed 2023310 
(FPCore (x s)
  :name "Logistic distribution"
  :precision binary32
  :pre (and (<= 0.0 s) (<= s 1.0651631))
  (/ (exp (/ (- (fabs x)) s)) (* (* s (+ 1.0 (exp (/ (- (fabs x)) s)))) (+ 1.0 (exp (/ (- (fabs x)) s))))))