Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 9.9s
Alternatives: 13
Speedup: 2.9×

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 13 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.5% accurate, 2.0× speedup?

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

    \[\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. *-lft-identity99.8%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.8%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.8%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \cdot e^{\frac{\left|x\right|}{s}}} \]
    8. associate-*l*99.8%

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
  5. Step-by-step derivation
    1. mul-1-neg99.8%

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

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

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    4. expm1-udef99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  6. Applied egg-rr99.8%

    \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Step-by-step derivation
    1. expm1-def99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    2. expm1-log1p99.8%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \color{blue}{\left(s \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  10. Step-by-step derivation
    1. +-commutative98.1%

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

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

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

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

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{{x}^{1}}\right|}{s}}, s\right)} \]
    6. sqr-pow49.9%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{s}}, s\right)} \]
    7. fabs-sqr49.9%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}, s\right)} \]
    8. sqr-pow99.8%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{{x}^{1}}}{s}}, s\right)} \]
    9. unpow199.8%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)} \]
  11. Simplified99.8%

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

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

Alternative 2: 97.3% accurate, 2.0× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\ \;\;\;\;{\left(\frac{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}{\frac{1}{s}}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 0.4000000059604645)
   (pow (/ (+ 3.0 (- (exp (/ x s)) (/ x s))) (/ 1.0 s)) -1.0)
   (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 0.4000000059604645f) {
		tmp = powf(((3.0f + (expf((x / s)) - (x / s))) / (1.0f / s)), -1.0f);
	} else {
		tmp = -0.25f * (expf((-x / s)) / x);
	}
	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 (abs(x) <= 0.4000000059604645e0) then
        tmp = ((3.0e0 + (exp((x / s)) - (x / s))) / (1.0e0 / s)) ** (-1.0e0)
    else
        tmp = (-0.25e0) * (exp((-x / s)) / x)
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(0.4000000059604645))
		tmp = Float32(Float32(Float32(3.0) + Float32(exp(Float32(x / s)) - Float32(x / s))) / Float32(Float32(1.0) / s)) ^ Float32(-1.0);
	else
		tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (abs(x) <= single(0.4000000059604645))
		tmp = ((single(3.0) + (exp((x / s)) - (x / s))) / (single(1.0) / s)) ^ single(-1.0);
	else
		tmp = single(-0.25) * (exp((-x / s)) / x);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\
\;\;\;\;{\left(\frac{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}{\frac{1}{s}}\right)}^{-1}\\

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


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

    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. Simplified99.7%

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{\left|x\right|}{s}}\right) - \frac{\left|x\right|}{s}}} \]
    7. Step-by-step derivation
      1. associate--l+95.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{\color{blue}{{x}^{1}}}{s}\right)} \]
      11. unpow168.9%

        \[\leadsto \frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{\color{blue}{x}}{s}\right)} \]
    8. Simplified68.9%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}} \]
    9. Step-by-step derivation
      1. associate-+r-68.9%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}} \]
    10. Applied egg-rr68.9%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}} \]
    11. Step-by-step derivation
      1. clear-num69.0%

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

        \[\leadsto \color{blue}{{\left(\frac{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}{\frac{1}{s}}\right)}^{-1}} \]
      3. associate--l+69.0%

        \[\leadsto {\left(\frac{\color{blue}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}}{\frac{1}{s}}\right)}^{-1} \]
    12. Applied egg-rr69.0%

      \[\leadsto \color{blue}{{\left(\frac{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}{\frac{1}{s}}\right)}^{-1}} \]

    if 0.400000006 < (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. Taylor expanded in s around inf 100.0%

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

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

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{\left|x\right|} \]
      3. distribute-frac-neg100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      4. mul-1-neg100.0%

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{\left|x\right|} \]
      6. neg-mul-1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{\left|x\right|} \]
      7. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{1}}\right|}{s}}}{\left|x\right|} \]
      8. sqr-pow43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{s}}}{\left|x\right|} \]
      9. fabs-sqr43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}}{\left|x\right|} \]
      10. sqr-pow44.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{1}}}{s}}}{\left|x\right|} \]
      11. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{x}}{s}}}{\left|x\right|} \]
      12. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{1}}\right|} \]
      13. sqr-pow43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|} \]
      14. fabs-sqr43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}} \]
      15. sqr-pow44.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{1}}} \]
      16. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{x}} \]
    5. Simplified44.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\ \;\;\;\;{\left(\frac{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}{\frac{1}{s}}\right)}^{-1}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \]

Alternative 3: 97.4% accurate, 2.9× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\ \;\;\;\;\frac{1}{s \cdot \left(2 + \left(e^{\frac{x}{s}} + \left(1 - \frac{x}{s}\right)\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 0.4000000059604645)
   (/ 1.0 (* s (+ 2.0 (+ (exp (/ x s)) (- 1.0 (/ x s))))))
   (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 0.4000000059604645f) {
		tmp = 1.0f / (s * (2.0f + (expf((x / s)) + (1.0f - (x / s)))));
	} else {
		tmp = -0.25f * (expf((-x / s)) / x);
	}
	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 (abs(x) <= 0.4000000059604645e0) then
        tmp = 1.0e0 / (s * (2.0e0 + (exp((x / s)) + (1.0e0 - (x / s)))))
    else
        tmp = (-0.25e0) * (exp((-x / s)) / x)
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(0.4000000059604645))
		tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(exp(Float32(x / s)) + Float32(Float32(1.0) - Float32(x / s))))));
	else
		tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (abs(x) <= single(0.4000000059604645))
		tmp = single(1.0) / (s * (single(2.0) + (exp((x / s)) + (single(1.0) - (x / s)))));
	else
		tmp = single(-0.25) * (exp((-x / s)) / x);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.4000000059604645:\\
\;\;\;\;\frac{1}{s \cdot \left(2 + \left(e^{\frac{x}{s}} + \left(1 - \frac{x}{s}\right)\right)\right)}\\

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


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

    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. Simplified99.7%

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(1 - \frac{\left|x\right|}{s}\right)} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)} \]
    6. Step-by-step derivation
      1. expm1-log1p-u93.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{\left(1 - \frac{\left|x\right|}{s}\right) + \left(e^{\frac{\left|x\right|}{s}} + 2\right)}\right)\right)} \]
      2. expm1-udef93.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{\left(1 - \frac{\left|x\right|}{s}\right) + \left(e^{\frac{\left|x\right|}{s}} + 2\right)}\right)} - 1} \]
      3. associate-/l/93.5%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{1}{\left(\left(1 - \frac{\left|x\right|}{s}\right) + \left(e^{\frac{\left|x\right|}{s}} + 2\right)\right) \cdot s}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-def93.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\left(\left(1 - \frac{\left|x\right|}{s}\right) + \left(e^{\frac{\left|x\right|}{s}} + 2\right)\right) \cdot s}\right)\right)} \]
      2. expm1-log1p95.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.400000006 < (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. Taylor expanded in s around inf 100.0%

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

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

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{\left|x\right|} \]
      3. distribute-frac-neg100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      4. mul-1-neg100.0%

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{\left|x\right|} \]
      6. neg-mul-1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{\left|x\right|} \]
      7. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{1}}\right|}{s}}}{\left|x\right|} \]
      8. sqr-pow43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{s}}}{\left|x\right|} \]
      9. fabs-sqr43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}}{\left|x\right|} \]
      10. sqr-pow44.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{1}}}{s}}}{\left|x\right|} \]
      11. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{x}}{s}}}{\left|x\right|} \]
      12. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{1}}\right|} \]
      13. sqr-pow43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|} \]
      14. fabs-sqr43.1%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}} \]
      15. sqr-pow44.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{1}}} \]
      16. unpow144.9%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{x}} \]
    5. Simplified44.9%

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

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

Alternative 4: 99.5% accurate, 2.9× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* (+ 1.0 (exp (/ (- x) s))) (+ s (* s (exp (/ x s)))))))
x = abs(x);
float code(float x, float s) {
	return 1.0f / ((1.0f + expf((-x / s))) * (s + (s * expf((x / s)))));
}
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 = 1.0e0 / ((1.0e0 + exp((-x / s))) * (s + (s * exp((x / s)))))
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))) * Float32(s + Float32(s * exp(Float32(x / s))))))
end
x = abs(x)
function tmp = code(x, s)
	tmp = single(1.0) / ((single(1.0) + exp((-x / s))) * (s + (s * exp((x / s)))));
end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\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. *-lft-identity99.8%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.8%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.8%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \cdot e^{\frac{\left|x\right|}{s}}} \]
    8. associate-*l*99.8%

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
  5. Step-by-step derivation
    1. mul-1-neg99.8%

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

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

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    4. expm1-udef99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  6. Applied egg-rr99.8%

    \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Step-by-step derivation
    1. expm1-def99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    2. expm1-log1p99.8%

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

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

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

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

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

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

    \[\leadsto \frac{1}{\left(\color{blue}{e^{\frac{-x}{s}}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  9. Step-by-step derivation
    1. expm1-log1p-u98.1%

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

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

    \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \left(s + \color{blue}{\left(e^{\mathsf{log1p}\left(s \cdot e^{\frac{\left|x\right|}{s}}\right)} - 1\right)}\right)} \]
  11. Step-by-step derivation
    1. expm1-def98.1%

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

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

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

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

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}\right)} \]
    6. sqr-pow99.8%

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

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

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

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

Alternative 5: 99.5% accurate, 2.9× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{1}{\left(1 + e^{\frac{x}{s}}\right) \cdot \left(s \cdot \left(1 + e^{\frac{-x}{s}}\right)\right)} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* (+ 1.0 (exp (/ x s))) (* s (+ 1.0 (exp (/ (- x) s)))))))
x = abs(x);
float code(float x, float s) {
	return 1.0f / ((1.0f + expf((x / s))) * (s * (1.0f + expf((-x / s)))));
}
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 = 1.0e0 / ((1.0e0 + exp((x / s))) * (s * (1.0e0 + exp((-x / s)))))
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(x / s))) * Float32(s * Float32(Float32(1.0) + exp(Float32(Float32(-x) / s))))))
end
x = abs(x)
function tmp = code(x, s)
	tmp = single(1.0) / ((single(1.0) + exp((x / s))) * (s * (single(1.0) + exp((-x / s)))));
end
\begin{array}{l}
x = |x|\\
\\
\frac{1}{\left(1 + e^{\frac{x}{s}}\right) \cdot \left(s \cdot \left(1 + e^{\frac{-x}{s}}\right)\right)}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\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. *-lft-identity99.8%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.8%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.8%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \cdot e^{\frac{\left|x\right|}{s}}} \]
    8. associate-*l*99.8%

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(e^{-1 \cdot \frac{\left|x\right|}{s}} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)}} \]
  5. Step-by-step derivation
    1. mul-1-neg99.8%

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

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

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    4. expm1-udef99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  6. Applied egg-rr99.8%

    \[\leadsto \frac{1}{\left(\color{blue}{\left(e^{\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)} - 1\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
  7. Step-by-step derivation
    1. expm1-def99.8%

      \[\leadsto \frac{1}{\left(\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)\right)} + 1\right) \cdot \left(s + s \cdot e^{\frac{\left|x\right|}{s}}\right)} \]
    2. expm1-log1p99.8%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \color{blue}{\left(s \cdot \left(1 + e^{\frac{\left|x\right|}{s}}\right)\right)}} \]
  10. Step-by-step derivation
    1. +-commutative98.1%

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

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

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

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

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{{x}^{1}}\right|}{s}}, s\right)} \]
    6. sqr-pow49.9%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{s}}, s\right)} \]
    7. fabs-sqr49.9%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}, s\right)} \]
    8. sqr-pow99.8%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{{x}^{1}}}{s}}, s\right)} \]
    9. unpow199.8%

      \[\leadsto \frac{1}{\left(e^{\frac{-x}{s}} + 1\right) \cdot \mathsf{fma}\left(s, e^{\frac{\color{blue}{x}}{s}}, s\right)} \]
  11. Simplified99.8%

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

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

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

Alternative 6: 97.4% accurate, 5.4× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 0.4000000059604645:\\ \;\;\;\;\frac{1}{s \cdot \left(3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= x 0.4000000059604645)
   (/ 1.0 (* s (+ 3.0 (- (exp (/ x s)) (/ x s)))))
   (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (x <= 0.4000000059604645f) {
		tmp = 1.0f / (s * (3.0f + (expf((x / s)) - (x / s))));
	} else {
		tmp = -0.25f * (expf((-x / s)) / x);
	}
	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 <= 0.4000000059604645e0) then
        tmp = 1.0e0 / (s * (3.0e0 + (exp((x / s)) - (x / s))))
    else
        tmp = (-0.25e0) * (exp((-x / s)) / x)
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(0.4000000059604645))
		tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(3.0) + Float32(exp(Float32(x / s)) - Float32(x / s)))));
	else
		tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(0.4000000059604645))
		tmp = single(1.0) / (s * (single(3.0) + (exp((x / s)) - (x / s))));
	else
		tmp = single(-0.25) * (exp((-x / s)) / x);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.4000000059604645:\\
\;\;\;\;\frac{1}{s \cdot \left(3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 0.400000006

    1. Initial program 99.7%

      \[\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.3%

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{\left|x\right|}{s}}\right) - \frac{\left|x\right|}{s}}} \]
    7. Step-by-step derivation
      1. associate--l+83.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{\color{blue}{{x}^{1}}}{s}\right)} \]
      11. unpow158.9%

        \[\leadsto \frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{\color{blue}{x}}{s}\right)} \]
    8. Simplified58.9%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}} \]
    9. Step-by-step derivation
      1. associate-+r-58.9%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}} \]
    10. Applied egg-rr58.9%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}} \]
    11. Step-by-step derivation
      1. expm1-log1p-u57.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}\right)\right)} \]
      2. expm1-udef70.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{\left(3 + e^{\frac{x}{s}}\right) - \frac{x}{s}}\right)} - 1} \]
      3. associate--l+70.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{\color{blue}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}}\right)} - 1 \]
    12. Applied egg-rr70.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}\right)} - 1} \]
    13. Step-by-step derivation
      1. expm1-def57.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}\right)\right)} \]
      2. expm1-log1p58.9%

        \[\leadsto \color{blue}{\frac{\frac{1}{s}}{3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)}} \]
      3. associate-/l/59.4%

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

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

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

    if 0.400000006 < 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. Taylor expanded in s around inf 100.0%

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

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

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{\left|x\right|} \]
      3. distribute-frac-neg100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      4. mul-1-neg100.0%

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

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{\left|x\right|} \]
      6. neg-mul-1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{\left|x\right|} \]
      7. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{1}}\right|}{s}}}{\left|x\right|} \]
      8. sqr-pow100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{s}}}{\left|x\right|} \]
      9. fabs-sqr100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{s}}}{\left|x\right|} \]
      10. sqr-pow100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{1}}}{s}}}{\left|x\right|} \]
      11. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{x}}{s}}}{\left|x\right|} \]
      12. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{1}}\right|} \]
      13. sqr-pow100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|} \]
      14. fabs-sqr100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}} \]
      15. sqr-pow100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{1}}} \]
      16. unpow1100.0%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{x}} \]
    5. Simplified100.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.4000000059604645:\\ \;\;\;\;\frac{1}{s \cdot \left(3 + \left(e^{\frac{x}{s}} - \frac{x}{s}\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \]

Alternative 7: 85.7% accurate, 5.6× speedup?

\[\begin{array}{l} x = |x|\\ \\ \begin{array}{l} \mathbf{if}\;x \leq 3.999999999279835 \cdot 10^{-23}:\\ \;\;\;\;\frac{\frac{1}{s}}{\frac{1}{\frac{s}{x} \cdot \frac{s}{x}} + 4}\\ \mathbf{else}:\\ \;\;\;\;-0.25 \cdot \frac{e^{\frac{-x}{s}}}{x}\\ \end{array} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s)
 :precision binary32
 (if (<= x 3.999999999279835e-23)
   (/ (/ 1.0 s) (+ (/ 1.0 (* (/ s x) (/ s x))) 4.0))
   (* -0.25 (/ (exp (/ (- x) s)) x))))
x = abs(x);
float code(float x, float s) {
	float tmp;
	if (x <= 3.999999999279835e-23f) {
		tmp = (1.0f / s) / ((1.0f / ((s / x) * (s / x))) + 4.0f);
	} else {
		tmp = -0.25f * (expf((-x / s)) / x);
	}
	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 <= 3.999999999279835e-23) then
        tmp = (1.0e0 / s) / ((1.0e0 / ((s / x) * (s / x))) + 4.0e0)
    else
        tmp = (-0.25e0) * (exp((-x / s)) / x)
    end if
    code = tmp
end function
x = abs(x)
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(3.999999999279835e-23))
		tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(Float32(1.0) / Float32(Float32(s / x) * Float32(s / x))) + Float32(4.0)));
	else
		tmp = Float32(Float32(-0.25) * Float32(exp(Float32(Float32(-x) / s)) / x));
	end
	return tmp
end
x = abs(x)
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(3.999999999279835e-23))
		tmp = (single(1.0) / s) / ((single(1.0) / ((s / x) * (s / x))) + single(4.0));
	else
		tmp = single(-0.25) * (exp((-x / s)) / x);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.999999999279835 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{\frac{1}{\frac{s}{x} \cdot \frac{s}{x}} + 4}\\

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


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

    1. Initial program 99.8%

      \[\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.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs68.8%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow268.8%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified68.8%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
    6. Step-by-step derivation
      1. clear-num68.8%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{1}{\frac{s \cdot s}{x \cdot x}}} + 4} \]
      2. inv-pow68.8%

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{{\left(\frac{s \cdot s}{x \cdot x}\right)}^{-1}} + 4} \]
    8. Step-by-step derivation
      1. unpow-168.8%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{1}{\frac{s \cdot s}{x \cdot x}}} + 4} \]
      2. times-frac70.8%

        \[\leadsto \frac{\frac{1}{s}}{\frac{1}{\color{blue}{\frac{s}{x} \cdot \frac{s}{x}}} + 4} \]
    9. Simplified70.8%

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

    if 4e-23 < x

    1. Initial program 99.8%

      \[\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. Taylor expanded in s around inf 97.1%

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

      \[\leadsto \color{blue}{-0.25 \cdot \frac{e^{-1 \cdot \frac{\left|x\right|}{s}}}{\left|x\right|}} \]
    4. Step-by-step derivation
      1. mul-1-neg89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      2. distribute-frac-neg89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{\left|x\right|} \]
      3. distribute-frac-neg89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      4. mul-1-neg89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{-1 \cdot \frac{\left|x\right|}{s}}}}{\left|x\right|} \]
      5. associate-*r/89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\color{blue}{\frac{-1 \cdot \left|x\right|}{s}}}}{\left|x\right|} \]
      6. neg-mul-189.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{\color{blue}{-\left|x\right|}}{s}}}{\left|x\right|} \]
      7. unpow189.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\left|\color{blue}{{x}^{1}}\right|}{s}}}{\left|x\right|} \]
      8. sqr-pow89.4%

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

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

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{{x}^{1}}}{s}}}{\left|x\right|} \]
      11. unpow189.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-\color{blue}{x}}{s}}}{\left|x\right|} \]
      12. unpow189.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\left|\color{blue}{{x}^{1}}\right|} \]
      13. sqr-pow89.4%

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

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}} \]
      15. sqr-pow89.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{{x}^{1}}} \]
      16. unpow189.4%

        \[\leadsto -0.25 \cdot \frac{e^{\frac{-x}{s}}}{\color{blue}{x}} \]
    5. Simplified89.4%

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

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

Alternative 8: 82.1% accurate, 36.2× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\


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

    1. Initial program 99.8%

      \[\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.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs68.6%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow268.6%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified68.6%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
    6. Step-by-step derivation
      1. clear-num68.6%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{1}{\frac{s \cdot s}{x \cdot x}}} + 4} \]
      2. inv-pow68.6%

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

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{{\left(\frac{s \cdot s}{x \cdot x}\right)}^{-1}} + 4} \]
    8. Step-by-step derivation
      1. unpow-168.6%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{1}{\frac{s \cdot s}{x \cdot x}}} + 4} \]
      2. times-frac70.6%

        \[\leadsto \frac{\frac{1}{s}}{\frac{1}{\color{blue}{\frac{s}{x} \cdot \frac{s}{x}}} + 4} \]
    9. Simplified70.6%

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

    if 1.28000003e-23 < x

    1. Initial program 99.8%

      \[\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.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs82.4%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow282.4%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified82.4%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.3%

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

Alternative 9: 82.1% accurate, 41.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\


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

    1. Initial program 99.8%

      \[\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.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs68.6%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow268.6%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified68.6%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
    6. Step-by-step derivation
      1. times-frac70.6%

        \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x}{s} \cdot \frac{x}{s}} + 4} \]
    7. Applied egg-rr70.6%

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

    if 1.28000003e-23 < x

    1. Initial program 99.8%

      \[\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.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs82.4%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow282.4%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified82.4%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.3%

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

Alternative 10: 76.6% accurate, 47.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (/ x s)))))
x = abs(x);
float code(float x, float s) {
	return (1.0f / s) / (4.0f + ((x / s) * (x / s)));
}
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 = (1.0e0 / s) / (4.0e0 + ((x / s) * (x / s)))
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s))))
end
x = abs(x)
function tmp = code(x, s)
	tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (x / s)));
end
\begin{array}{l}
x = |x|\\
\\
\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\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.5%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
    8. sqr-abs74.1%

      \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
    9. unpow274.1%

      \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
  5. Simplified74.1%

    \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
  6. Step-by-step derivation
    1. times-frac71.7%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x}{s} \cdot \frac{x}{s}} + 4} \]
  7. Applied egg-rr71.7%

    \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x}{s} \cdot \frac{x}{s}} + 4} \]
  8. Final simplification71.7%

    \[\leadsto \frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}} \]

Alternative 11: 63.3% accurate, 87.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\


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

    1. Initial program 99.7%

      \[\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. *-lft-identity99.7%

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.8%

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \cdot e^{\frac{\left|x\right|}{s}}} \]
      8. associate-*l*99.7%

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

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

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

    if 2.49999999e-7 < 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{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
    3. Taylor expanded in s around inf 43.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{{s}^{2}} + 4} \]
      8. sqr-abs88.0%

        \[\leadsto \frac{\frac{1}{s}}{\frac{\color{blue}{x \cdot x}}{{s}^{2}} + 4} \]
      9. unpow288.0%

        \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{\color{blue}{s \cdot s}} + 4} \]
    5. Simplified88.0%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
    6. Taylor expanded in s around 0 61.3%

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    7. Step-by-step derivation
      1. unpow261.3%

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    8. Simplified61.3%

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

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

Alternative 12: 7.1% accurate, 206.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{-1}{x} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s) :precision binary32 (/ -1.0 x))
x = abs(x);
float code(float x, float s) {
	return -1.0f / x;
}
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 = (-1.0e0) / x
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(-1.0) / x)
end
x = abs(x)
function tmp = code(x, s)
	tmp = single(-1.0) / x;
end
\begin{array}{l}
x = |x|\\
\\
\frac{-1}{x}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\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.5%

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-1}{\left|x\right|}} \]
  7. Step-by-step derivation
    1. unpow16.9%

      \[\leadsto \frac{-1}{\left|\color{blue}{{x}^{1}}\right|} \]
    2. sqr-pow3.2%

      \[\leadsto \frac{-1}{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|} \]
    3. fabs-sqr3.2%

      \[\leadsto \frac{-1}{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}} \]
    4. sqr-pow7.8%

      \[\leadsto \frac{-1}{\color{blue}{{x}^{1}}} \]
    5. unpow17.8%

      \[\leadsto \frac{-1}{\color{blue}{x}} \]
  8. Simplified7.8%

    \[\leadsto \color{blue}{\frac{-1}{x}} \]
  9. Final simplification7.8%

    \[\leadsto \frac{-1}{x} \]

Alternative 13: 27.6% accurate, 206.7× speedup?

\[\begin{array}{l} x = |x|\\ \\ \frac{0.25}{s} \end{array} \]
NOTE: x should be positive before calling this function
(FPCore (x s) :precision binary32 (/ 0.25 s))
x = abs(x);
float code(float x, float s) {
	return 0.25f / s;
}
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 = 0.25e0 / s
end function
x = abs(x)
function code(x, s)
	return Float32(Float32(0.25) / s)
end
x = abs(x)
function tmp = code(x, s)
	tmp = single(0.25) / s;
end
\begin{array}{l}
x = |x|\\
\\
\frac{0.25}{s}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\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. *-lft-identity99.8%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.8%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.8%

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\left(\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)} \cdot e^{\frac{\left|x\right|}{s}}} \]
    8. associate-*l*99.8%

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  5. Final simplification21.4%

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

Reproduce

?
herbie shell --seed 2023238 
(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))))))