Logistic distribution

Percentage Accurate: 99.5% → 99.4%
Time: 17.2s
Alternatives: 8
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 8 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.4% accurate, 1.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \frac{1}{\left(1 + e^{\frac{-\left|x\_m\right|}{s}}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \left(1 + {\left(e^{2}\right)}^{\left(\frac{x\_m}{s \cdot 2}\right)}\right)\right)\right)} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (/
  1.0
  (*
   (+ 1.0 (exp (/ (- (fabs x_m)) s)))
   (expm1 (log1p (* s (+ 1.0 (pow (exp 2.0) (/ x_m (* s 2.0))))))))))
x_m = fabs(x);
float code(float x_m, float s) {
	return 1.0f / ((1.0f + expf((-fabsf(x_m) / s))) * expm1f(log1pf((s * (1.0f + powf(expf(2.0f), (x_m / (s * 2.0f))))))));
}
x_m = abs(x)
function code(x_m, s)
	return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(Float32(-abs(x_m)) / s))) * expm1(log1p(Float32(s * Float32(Float32(1.0) + (exp(Float32(2.0)) ^ Float32(x_m / Float32(s * Float32(2.0))))))))))
end
\begin{array}{l}
x_m = \left|x\right|

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} \cdot e^{\log s}}\right)\right)} \]
    3. add-exp-log58.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot \left(1 + {\left(e^{2}\right)}^{\left(\frac{x}{s \cdot 2}\right)}\right)\right)\right)} \]
  13. Add Preprocessing

Alternative 2: 99.5% accurate, 1.5× speedup?

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

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

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.5% accurate, 2.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef93.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 63.0% accurate, 3.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;\left|x\_m\right| \leq 9.999999717180685 \cdot 10^{-10}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{{x\_m}^{2}}\\ \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (if (<= (fabs x_m) 9.999999717180685e-10) (/ 0.25 s) (/ s (pow x_m 2.0))))
x_m = fabs(x);
float code(float x_m, float s) {
	float tmp;
	if (fabsf(x_m) <= 9.999999717180685e-10f) {
		tmp = 0.25f / s;
	} else {
		tmp = s / powf(x_m, 2.0f);
	}
	return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
    real(4), intent (in) :: x_m
    real(4), intent (in) :: s
    real(4) :: tmp
    if (abs(x_m) <= 9.999999717180685e-10) then
        tmp = 0.25e0 / s
    else
        tmp = s / (x_m ** 2.0e0)
    end if
    code = tmp
end function
x_m = abs(x)
function code(x_m, s)
	tmp = Float32(0.0)
	if (abs(x_m) <= Float32(9.999999717180685e-10))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(s / (x_m ^ Float32(2.0)));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, s)
	tmp = single(0.0);
	if (abs(x_m) <= single(9.999999717180685e-10))
		tmp = single(0.25) / s;
	else
		tmp = s / (x_m ^ single(2.0));
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\frac{0.25}{s}\\

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


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

    1. Initial program 98.1%

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

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

    if 9.99999972e-10 < (fabs.f32 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{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Add Preprocessing
    4. Taylor expanded in s around inf 98.6%

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

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

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

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

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

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

        \[\leadsto \frac{1}{2 \cdot \left(\left|x\right| + \color{blue}{\mathsf{fma}\left(s, 2, -0.5 \cdot \frac{{\left(\left|x\right|\right)}^{2}}{s} + \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)}\right)} \]
      6. distribute-lft1-in66.2%

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

        \[\leadsto \frac{1}{2 \cdot \left(\left|x\right| + \mathsf{fma}\left(s, 2, \color{blue}{0.5} \cdot \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)\right)} \]
      8. associate-*r/66.2%

        \[\leadsto \frac{1}{2 \cdot \left(\left|x\right| + \mathsf{fma}\left(s, 2, \color{blue}{\frac{0.5 \cdot {\left(\left|x\right|\right)}^{2}}{s}}\right)\right)} \]
      9. unpow266.2%

        \[\leadsto \frac{1}{2 \cdot \left(\left|x\right| + \mathsf{fma}\left(s, 2, \frac{0.5 \cdot \color{blue}{\left(\left|x\right| \cdot \left|x\right|\right)}}{s}\right)\right)} \]
      10. sqr-abs66.2%

        \[\leadsto \frac{1}{2 \cdot \left(\left|x\right| + \mathsf{fma}\left(s, 2, \frac{0.5 \cdot \color{blue}{\left(x \cdot x\right)}}{s}\right)\right)} \]
    7. Simplified66.2%

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(\left|x\right| + \mathsf{fma}\left(s, 2, \frac{0.5 \cdot \left(x \cdot x\right)}{s}\right)\right)}} \]
    8. Taylor expanded in x around inf 64.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 9.999999717180685 \cdot 10^{-10}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{{x}^{2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 29.8% accurate, 3.0× speedup?

\[\begin{array}{l} x_m = \left|x\right| \\ \begin{array}{l} \mathbf{if}\;\left|x\_m\right| \leq 9.999999717180685 \cdot 10^{-10}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\left|x\_m\right|}\\ \end{array} \end{array} \]
x_m = (fabs.f32 x)
(FPCore (x_m s)
 :precision binary32
 (if (<= (fabs x_m) 9.999999717180685e-10) (/ 0.25 s) (/ 0.5 (fabs x_m))))
x_m = fabs(x);
float code(float x_m, float s) {
	float tmp;
	if (fabsf(x_m) <= 9.999999717180685e-10f) {
		tmp = 0.25f / s;
	} else {
		tmp = 0.5f / fabsf(x_m);
	}
	return tmp;
}
x_m = abs(x)
real(4) function code(x_m, s)
    real(4), intent (in) :: x_m
    real(4), intent (in) :: s
    real(4) :: tmp
    if (abs(x_m) <= 9.999999717180685e-10) then
        tmp = 0.25e0 / s
    else
        tmp = 0.5e0 / abs(x_m)
    end if
    code = tmp
end function
x_m = abs(x)
function code(x_m, s)
	tmp = Float32(0.0)
	if (abs(x_m) <= Float32(9.999999717180685e-10))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(Float32(0.5) / abs(x_m));
	end
	return tmp
end
x_m = abs(x);
function tmp_2 = code(x_m, s)
	tmp = single(0.0);
	if (abs(x_m) <= single(9.999999717180685e-10))
		tmp = single(0.25) / s;
	else
		tmp = single(0.5) / abs(x_m);
	end
	tmp_2 = tmp;
end
\begin{array}{l}
x_m = \left|x\right|

\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 9.999999717180685 \cdot 10^{-10}:\\
\;\;\;\;\frac{0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\left|x\_m\right|}\\


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

    1. Initial program 98.1%

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

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

    if 9.99999972e-10 < (fabs.f32 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{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Add Preprocessing
    4. Taylor expanded in s around inf 98.6%

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

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

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

      \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(\left|x\right| + s \cdot 2\right)}} \]
    8. Taylor expanded in s around 0 10.2%

      \[\leadsto \color{blue}{\frac{0.5}{\left|x\right|}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification26.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 9.999999717180685 \cdot 10^{-10}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.5}{\left|x\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 95.2% accurate, 5.6× speedup?

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{2} \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \]
  5. Step-by-step derivation
    1. fma-udef93.6%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{2 \cdot \left(s \cdot \left(1 + e^{\frac{x}{s}}\right)\right)} \]
  8. Add Preprocessing

Alternative 7: 94.8% accurate, 5.7× speedup?

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

\\
\frac{\frac{e^{\frac{-x\_m}{s}}}{s}}{4}
\end{array}
Derivation
  1. Initial program 99.1%

    \[\frac{e^{\frac{-\left|x\right|}{s}}}{\left(s \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)} \]
  2. Add Preprocessing
  3. Taylor expanded in x around 0 99.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\frac{e^{\frac{-x}{s}}}{s}}{4} \]
  12. Add Preprocessing

Alternative 8: 27.2% accurate, 206.7× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  4. Final simplification23.0%

    \[\leadsto \frac{0.25}{s} \]
  5. Add Preprocessing

Reproduce

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