Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 12.2s
Alternatives: 9
Speedup: 1.5×

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 9 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.6% 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.6% accurate, 1.5× speedup?

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

\\
\frac{1}{s \cdot \left(e^{\frac{\left|x\right|}{-s}} + \left(e^{\frac{\left|x\right|}{s}} + 2\right)\right)}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 94.0% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 1.000000031374395 \cdot 10^{-22}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-0.5 \cdot \frac{x \cdot \left(x \cdot 1.5 - x\right)}{s \cdot s}}}{s \cdot 4}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 1.000000031374395e-22)
   (/ 1.0 (fma x (/ x s) (* s 4.0)))
   (/ (exp (* -0.5 (/ (* x (- (* x 1.5) x)) (* s s)))) (* s 4.0))))
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 1.000000031374395e-22f) {
		tmp = 1.0f / fmaf(x, (x / s), (s * 4.0f));
	} else {
		tmp = expf((-0.5f * ((x * ((x * 1.5f) - x)) / (s * s)))) / (s * 4.0f);
	}
	return tmp;
}
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(1.000000031374395e-22))
		tmp = Float32(Float32(1.0) / fma(x, Float32(x / s), Float32(s * Float32(4.0))));
	else
		tmp = Float32(exp(Float32(Float32(-0.5) * Float32(Float32(x * Float32(Float32(x * Float32(1.5)) - x)) / Float32(s * s)))) / Float32(s * Float32(4.0)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1.000000031374395 \cdot 10^{-22}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{-0.5 \cdot \frac{x \cdot \left(x \cdot 1.5 - x\right)}{s \cdot s}}}{s \cdot 4}\\


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

    1. Initial program 99.4%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. 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. Step-by-step derivation
      1. expm1-log1p-u92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s} + \left(4 \cdot s + 0\right)} \]
      10. sqr-abs87.5%

        \[\leadsto \frac{1}{\frac{\color{blue}{x \cdot x}}{s} + \left(4 \cdot s + 0\right)} \]
      11. associate-*l/89.1%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{s} \cdot x} + \left(4 \cdot s + 0\right)} \]
      12. associate-/r/89.1%

        \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}} + \left(4 \cdot s + 0\right)} \]
      13. *-commutative89.1%

        \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(\color{blue}{s \cdot 4} + 0\right)} \]
      14. metadata-eval89.1%

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

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

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

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

        \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \color{blue}{\mathsf{fma}\left(s, 4, -1 \cdot \left(-1 \cdot \left|x\right| + \left|x\right|\right)\right)}} \]
      19. distribute-lft1-in89.1%

        \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \left|x\right|\right)}\right)} \]
      20. metadata-eval89.1%

        \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \left(\color{blue}{0} \cdot \left|x\right|\right)\right)} \]
      21. mul0-lft89.1%

        \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{0}\right)} \]
    9. Simplified89.1%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, 0\right)}} \]
    10. Taylor expanded in x around 0 87.5%

      \[\leadsto \frac{1}{\color{blue}{4 \cdot s + \frac{{x}^{2}}{s}}} \]
    11. Step-by-step derivation
      1. unpow287.5%

        \[\leadsto \frac{1}{4 \cdot s + \frac{\color{blue}{x \cdot x}}{s}} \]
      2. associate-*r/89.1%

        \[\leadsto \frac{1}{4 \cdot s + \color{blue}{x \cdot \frac{x}{s}}} \]
      3. +-commutative89.1%

        \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s} + 4 \cdot s}} \]
      4. fma-def89.1%

        \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, 4 \cdot s\right)}} \]
      5. *-commutative89.1%

        \[\leadsto \frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, \color{blue}{s \cdot 4}\right)} \]
    12. Simplified89.1%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}} \]

    if 1.00000003e-22 < (fabs.f32 x)

    1. Initial program 99.4%

      \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
    2. Step-by-step derivation
      1. add-exp-log98.7%

        \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
      2. log-div98.7%

        \[\leadsto e^{\color{blue}{\log \left(e^{\frac{-\left|x\right|}{s}}\right) - \log \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)}} \]
      3. add-log-exp99.0%

        \[\leadsto e^{\color{blue}{\frac{-\left|x\right|}{s}} - \log \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)} \]
      4. associate-*l*99.0%

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

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

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

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

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

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

      \[\leadsto e^{\color{blue}{\frac{-0.5}{s} \cdot \frac{1.5 \cdot \left(x \cdot x\right) - x \cdot x}{s} - \left(\log 4 + \log s\right)}} \]
    7. Step-by-step derivation
      1. expm1-log1p-u62.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(e^{\frac{-0.5}{s} \cdot \frac{1.5 \cdot \left(x \cdot x\right) - x \cdot x}{s} - \left(\log 4 + \log s\right)}\right)\right)} \]
      2. expm1-udef62.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(e^{\frac{-0.5}{s} \cdot \frac{1.5 \cdot \left(x \cdot x\right) - x \cdot x}{s} - \left(\log 4 + \log s\right)}\right)} - 1} \]
      3. exp-diff62.4%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{e^{\frac{-0.5}{s} \cdot \frac{1.5 \cdot \left(x \cdot x\right) - x \cdot x}{s}}}{e^{\log 4 + \log s}}}\right)} - 1 \]
      4. frac-times62.4%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{e^{\color{blue}{\frac{-0.5 \cdot \left(1.5 \cdot \left(x \cdot x\right) - x \cdot x\right)}{s \cdot s}}}}{e^{\log 4 + \log s}}\right)} - 1 \]
      5. associate-*r*62.4%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{e^{\frac{-0.5 \cdot \left(\color{blue}{\left(1.5 \cdot x\right) \cdot x} - x \cdot x\right)}{s \cdot s}}}{e^{\log 4 + \log s}}\right)} - 1 \]
      6. sum-log62.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{e^{\frac{-0.5 \cdot \left(\left(1.5 \cdot x\right) \cdot x - x \cdot x\right)}{s \cdot s}}}{e^{\color{blue}{\log \left(4 \cdot s\right)}}}\right)} - 1 \]
      7. add-exp-log62.5%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{e^{\frac{-0.5 \cdot \left(\left(1.5 \cdot x\right) \cdot x - x \cdot x\right)}{s \cdot s}}}{\color{blue}{4 \cdot s}}\right)} - 1 \]
    8. Applied egg-rr62.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{e^{\frac{-0.5 \cdot \left(\left(1.5 \cdot x\right) \cdot x - x \cdot x\right)}{s \cdot s}}}{4 \cdot s}\right)} - 1} \]
    9. Step-by-step derivation
      1. expm1-def62.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{e^{\frac{-0.5 \cdot \left(\left(1.5 \cdot x\right) \cdot x - x \cdot x\right)}{s \cdot s}}}{4 \cdot s}\right)\right)} \]
      2. expm1-log1p63.1%

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

        \[\leadsto \frac{e^{\frac{-0.5 \cdot \left(\left(1.5 \cdot x\right) \cdot x - x \cdot x\right)}{s \cdot s}}}{\color{blue}{s \cdot 4}} \]
    10. Simplified98.5%

      \[\leadsto \color{blue}{\frac{e^{-0.5 \cdot \frac{x \cdot \left(x \cdot 1.5 - x\right)}{s \cdot s}}}{s \cdot 4}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 1.000000031374395 \cdot 10^{-22}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-0.5 \cdot \frac{x \cdot \left(x \cdot 1.5 - x\right)}{s \cdot s}}}{s \cdot 4}\\ \end{array} \]

Alternative 3: 97.3% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \frac{e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2}}}{s \cdot 4} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ (exp (* -0.25 (pow (/ x s) 2.0))) (* s 4.0)))
float code(float x, float s) {
	return expf((-0.25f * powf((x / s), 2.0f))) / (s * 4.0f);
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = exp(((-0.25e0) * ((x / s) ** 2.0e0))) / (s * 4.0e0)
end function
function code(x, s)
	return Float32(exp(Float32(Float32(-0.25) * (Float32(x / s) ^ Float32(2.0)))) / Float32(s * Float32(4.0)))
end
function tmp = code(x, s)
	tmp = exp((single(-0.25) * ((x / s) ^ single(2.0)))) / (s * single(4.0));
end
\begin{array}{l}

\\
\frac{e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Step-by-step derivation
    1. add-exp-log97.4%

      \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
    2. log-div97.4%

      \[\leadsto e^{\color{blue}{\log \left(e^{\frac{-\left|x\right|}{s}}\right) - \log \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)}} \]
    3. add-log-exp97.6%

      \[\leadsto e^{\color{blue}{\frac{-\left|x\right|}{s}} - \log \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)} \]
    4. associate-*l*97.6%

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

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

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

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

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

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

    \[\leadsto e^{\color{blue}{\frac{-0.5}{s} \cdot \frac{1.5 \cdot \left(x \cdot x\right) - x \cdot x}{s} - \left(\log 4 + \log s\right)}} \]
  7. Taylor expanded in x around 0 91.7%

    \[\leadsto e^{\color{blue}{-0.25 \cdot \frac{{x}^{2}}{{s}^{2}}} - \left(\log 4 + \log s\right)} \]
  8. Step-by-step derivation
    1. unpow291.7%

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

      \[\leadsto e^{-0.25 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}} - \left(\log 4 + \log s\right)} \]
    3. times-frac96.0%

      \[\leadsto e^{-0.25 \cdot \color{blue}{\left(\frac{x}{s} \cdot \frac{x}{s}\right)} - \left(\log 4 + \log s\right)} \]
  9. Simplified96.0%

    \[\leadsto e^{\color{blue}{-0.25 \cdot \left(\frac{x}{s} \cdot \frac{x}{s}\right)} - \left(\log 4 + \log s\right)} \]
  10. Step-by-step derivation
    1. exp-diff96.0%

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

      \[\leadsto \frac{e^{-0.25 \cdot \color{blue}{{\left(\frac{x}{s}\right)}^{2}}}}{e^{\log 4 + \log s}} \]
    3. sum-log96.3%

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

      \[\leadsto \frac{e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2}}}{\color{blue}{4 \cdot s}} \]
  11. Applied egg-rr98.2%

    \[\leadsto \color{blue}{\frac{e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2}}}{4 \cdot s}} \]
  12. Final simplification98.2%

    \[\leadsto \frac{e^{-0.25 \cdot {\left(\frac{x}{s}\right)}^{2}}}{s \cdot 4} \]

Alternative 4: 94.7% accurate, 3.0× speedup?

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

\\
\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.4%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Taylor expanded in s around inf 95.4%

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

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

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  5. Final simplification95.4%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot 4} \]

Alternative 5: 66.1% accurate, 5.7× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(4, s, x \cdot \frac{x}{s}\right)} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (fma 4.0 s (* x (/ x s)))))
float code(float x, float s) {
	return 1.0f / fmaf(4.0f, s, (x * (x / s)));
}
function code(x, s)
	return Float32(Float32(1.0) / fma(Float32(4.0), s, Float32(x * Float32(x / s))))
end
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(4, s, x \cdot \frac{x}{s}\right)}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s} + \left(4 \cdot s + 0\right)} \]
    10. sqr-abs70.6%

      \[\leadsto \frac{1}{\frac{\color{blue}{x \cdot x}}{s} + \left(4 \cdot s + 0\right)} \]
    11. associate-*l/70.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{s} \cdot x} + \left(4 \cdot s + 0\right)} \]
    12. associate-/r/70.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}} + \left(4 \cdot s + 0\right)} \]
    13. *-commutative70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(\color{blue}{s \cdot 4} + 0\right)} \]
    14. metadata-eval70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(s \cdot 4 + \color{blue}{-1 \cdot 0}\right)} \]
    15. mul0-lft70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(s \cdot 4 + -1 \cdot \color{blue}{\left(0 \cdot \left|x\right|\right)}\right)} \]
    16. metadata-eval70.9%

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

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

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \color{blue}{\mathsf{fma}\left(s, 4, -1 \cdot \left(-1 \cdot \left|x\right| + \left|x\right|\right)\right)}} \]
    19. distribute-lft1-in70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \left|x\right|\right)}\right)} \]
    20. metadata-eval70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \left(\color{blue}{0} \cdot \left|x\right|\right)\right)} \]
    21. mul0-lft70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{0}\right)} \]
  9. Simplified70.9%

    \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, 0\right)}} \]
  10. Taylor expanded in x around 0 70.6%

    \[\leadsto \frac{1}{\color{blue}{4 \cdot s + \frac{{x}^{2}}{s}}} \]
  11. Step-by-step derivation
    1. fma-def70.6%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(4, s, \frac{{x}^{2}}{s}\right)}} \]
    2. unpow270.6%

      \[\leadsto \frac{1}{\mathsf{fma}\left(4, s, \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    3. associate-*r/70.9%

      \[\leadsto \frac{1}{\mathsf{fma}\left(4, s, \color{blue}{x \cdot \frac{x}{s}}\right)} \]
  12. Simplified70.9%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(4, s, x \cdot \frac{x}{s}\right)}} \]
  13. Final simplification70.9%

    \[\leadsto \frac{1}{\mathsf{fma}\left(4, s, x \cdot \frac{x}{s}\right)} \]

Alternative 6: 66.1% accurate, 5.7× speedup?

\[\begin{array}{l} \\ \frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)} \end{array} \]
(FPCore (x s) :precision binary32 (/ 1.0 (fma x (/ x s) (* s 4.0))))
float code(float x, float s) {
	return 1.0f / fmaf(x, (x / s), (s * 4.0f));
}
function code(x, s)
	return Float32(Float32(1.0) / fma(x, Float32(x / s), Float32(s * Float32(4.0))))
end
\begin{array}{l}

\\
\frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s} + \left(4 \cdot s + 0\right)} \]
    10. sqr-abs70.6%

      \[\leadsto \frac{1}{\frac{\color{blue}{x \cdot x}}{s} + \left(4 \cdot s + 0\right)} \]
    11. associate-*l/70.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{s} \cdot x} + \left(4 \cdot s + 0\right)} \]
    12. associate-/r/70.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}} + \left(4 \cdot s + 0\right)} \]
    13. *-commutative70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(\color{blue}{s \cdot 4} + 0\right)} \]
    14. metadata-eval70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(s \cdot 4 + \color{blue}{-1 \cdot 0}\right)} \]
    15. mul0-lft70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \left(s \cdot 4 + -1 \cdot \color{blue}{\left(0 \cdot \left|x\right|\right)}\right)} \]
    16. metadata-eval70.9%

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

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

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \color{blue}{\mathsf{fma}\left(s, 4, -1 \cdot \left(-1 \cdot \left|x\right| + \left|x\right|\right)\right)}} \]
    19. distribute-lft1-in70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{\left(\left(-1 + 1\right) \cdot \left|x\right|\right)}\right)} \]
    20. metadata-eval70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \left(\color{blue}{0} \cdot \left|x\right|\right)\right)} \]
    21. mul0-lft70.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, -1 \cdot \color{blue}{0}\right)} \]
  9. Simplified70.9%

    \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}} + \mathsf{fma}\left(s, 4, 0\right)}} \]
  10. Taylor expanded in x around 0 70.6%

    \[\leadsto \frac{1}{\color{blue}{4 \cdot s + \frac{{x}^{2}}{s}}} \]
  11. Step-by-step derivation
    1. unpow270.6%

      \[\leadsto \frac{1}{4 \cdot s + \frac{\color{blue}{x \cdot x}}{s}} \]
    2. associate-*r/70.9%

      \[\leadsto \frac{1}{4 \cdot s + \color{blue}{x \cdot \frac{x}{s}}} \]
    3. +-commutative70.9%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s} + 4 \cdot s}} \]
    4. fma-def70.9%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, 4 \cdot s\right)}} \]
    5. *-commutative70.9%

      \[\leadsto \frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, \color{blue}{s \cdot 4}\right)} \]
  12. Simplified70.9%

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}} \]
  13. Final simplification70.9%

    \[\leadsto \frac{1}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)} \]

Alternative 7: 46.2% accurate, 55.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.014999999664723873:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{\frac{x}{\frac{s}{x}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 0.014999999664723873) (/ 0.25 s) (* 2.0 (/ 1.0 (/ x (/ s x))))))
float code(float x, float s) {
	float tmp;
	if (x <= 0.014999999664723873f) {
		tmp = 0.25f / s;
	} else {
		tmp = 2.0f * (1.0f / (x / (s / x)));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 0.014999999664723873e0) then
        tmp = 0.25e0 / s
    else
        tmp = 2.0e0 * (1.0e0 / (x / (s / x)))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(0.014999999664723873))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(Float32(2.0) * Float32(Float32(1.0) / Float32(x / Float32(s / x))));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(0.014999999664723873))
		tmp = single(0.25) / s;
	else
		tmp = single(2.0) * (single(1.0) / (x / (s / x)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.014999999664723873:\\
\;\;\;\;\frac{0.25}{s}\\

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


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

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

      \[\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 39.7%

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

    if 0.0149999997 < 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. Simplified98.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 50.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{x \cdot x}} \]
      2. sqr-abs80.3%

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{\left|x\right| \cdot \left|x\right|}} \]
      3. unpow280.3%

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

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{\left|x\right| \cdot \left|x\right|}} \]
      5. sqr-abs80.3%

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

      \[\leadsto \color{blue}{2 \cdot \frac{s}{x \cdot x}} \]
    9. Step-by-step derivation
      1. clear-num80.9%

        \[\leadsto 2 \cdot \color{blue}{\frac{1}{\frac{x \cdot x}{s}}} \]
      2. inv-pow80.9%

        \[\leadsto 2 \cdot \color{blue}{{\left(\frac{x \cdot x}{s}\right)}^{-1}} \]
    10. Applied egg-rr80.9%

      \[\leadsto 2 \cdot \color{blue}{{\left(\frac{x \cdot x}{s}\right)}^{-1}} \]
    11. Step-by-step derivation
      1. unpow-180.9%

        \[\leadsto 2 \cdot \color{blue}{\frac{1}{\frac{x \cdot x}{s}}} \]
      2. associate-/l*80.9%

        \[\leadsto 2 \cdot \frac{1}{\color{blue}{\frac{x}{\frac{s}{x}}}} \]
    12. Simplified80.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.014999999664723873:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{1}{\frac{x}{\frac{s}{x}}}\\ \end{array} \]

Alternative 8: 45.5% accurate, 67.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.014999999664723873:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 0.014999999664723873) (/ 0.25 s) (* 2.0 (/ s (* x x)))))
float code(float x, float s) {
	float tmp;
	if (x <= 0.014999999664723873f) {
		tmp = 0.25f / s;
	} else {
		tmp = 2.0f * (s / (x * x));
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 0.014999999664723873e0) then
        tmp = 0.25e0 / s
    else
        tmp = 2.0e0 * (s / (x * x))
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(0.014999999664723873))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(Float32(2.0) * Float32(s / Float32(x * x)));
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(0.014999999664723873))
		tmp = single(0.25) / s;
	else
		tmp = single(2.0) * (s / (x * x));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.014999999664723873:\\
\;\;\;\;\frac{0.25}{s}\\

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


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

    1. Initial program 99.2%

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

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

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

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

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

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

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

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

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

      \[\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 39.7%

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

    if 0.0149999997 < 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. Simplified98.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 50.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{x \cdot x}} \]
      2. sqr-abs80.3%

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{\left|x\right| \cdot \left|x\right|}} \]
      3. unpow280.3%

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

        \[\leadsto 2 \cdot \frac{s}{\color{blue}{\left|x\right| \cdot \left|x\right|}} \]
      5. sqr-abs80.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.014999999664723873:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;2 \cdot \frac{s}{x \cdot x}\\ \end{array} \]

Alternative 9: 27.5% accurate, 206.7× speedup?

\[\begin{array}{l} \\ \frac{0.25}{s} \end{array} \]
(FPCore (x s) :precision binary32 (/ 0.25 s))
float code(float x, float s) {
	return 0.25f / s;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    code = 0.25e0 / s
end function
function code(x, s)
	return Float32(Float32(0.25) / s)
end
function tmp = code(x, s)
	tmp = single(0.25) / s;
end
\begin{array}{l}

\\
\frac{0.25}{s}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

    \[\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 30.6%

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  5. Final simplification30.6%

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

Reproduce

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