Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 12.4s
Alternatives: 8
Speedup: 2.0×

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

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

\mathbf{else}:\\
\;\;\;\;\frac{0.5}{s \cdot \left(1 + t_0\right)}\\


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

    1. Initial program 99.1%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{x}{s}}}{s \cdot {\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity77.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 40 < (fabs.f32 x)

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \color{blue}{\frac{0.5}{s}} \cdot \frac{1}{1 + e^{\frac{x}{s}}} \]
    6. Step-by-step derivation
      1. *-commutative47.4%

        \[\leadsto \color{blue}{\frac{1}{1 + e^{\frac{x}{s}}} \cdot \frac{0.5}{s}} \]
      2. +-commutative47.4%

        \[\leadsto \frac{1}{\color{blue}{e^{\frac{x}{s}} + 1}} \cdot \frac{0.5}{s} \]
      3. frac-times47.4%

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

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

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

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

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

Alternative 2: 99.5% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + 1 \cdot e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}\right)} \]
    19. fabs-sqr47.8%

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + \color{blue}{1 \cdot e^{\frac{x}{s}}}\right)} \]
  5. Step-by-step derivation
    1. *-lft-identity61.9%

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

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

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

Alternative 3: 99.6% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + 1 \cdot e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}\right)} \]
    19. fabs-sqr47.8%

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

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

    \[\leadsto \frac{1}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{-s}}, s\right) \cdot \left(1 + \color{blue}{1 \cdot e^{\frac{x}{s}}}\right)} \]
  5. Step-by-step derivation
    1. *-lft-identity61.9%

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

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

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

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

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

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

Alternative 4: 95.2% accurate, 5.7× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{s}} \cdot \frac{1}{1 + e^{\frac{x}{s}}} \]
  6. Step-by-step derivation
    1. *-commutative58.9%

      \[\leadsto \color{blue}{\frac{1}{1 + e^{\frac{x}{s}}} \cdot \frac{0.5}{s}} \]
    2. +-commutative58.9%

      \[\leadsto \frac{1}{\color{blue}{e^{\frac{x}{s}} + 1}} \cdot \frac{0.5}{s} \]
    3. frac-times58.9%

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

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

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

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

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

Alternative 5: 51.7% accurate, 55.7× speedup?

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

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


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

    1. Initial program 99.5%

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

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

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

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

    if 0.119999997 < x

    1. Initial program 99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{0.5}{s}} \cdot \frac{1}{1 + e^{\frac{x}{s}}} \]
    6. Taylor expanded in x around 0 43.6%

      \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{2 + \frac{x}{s}}} \]
    7. Step-by-step derivation
      1. +-commutative43.6%

        \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
    8. Simplified43.6%

      \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
    9. Taylor expanded in x around inf 43.6%

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

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

Alternative 6: 44.7% accurate, 67.9× speedup?

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

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


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

    1. Initial program 99.5%

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

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

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

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

    if 0.119999997 < x

    1. Initial program 99.6%

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

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

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

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

      \[\leadsto \color{blue}{\frac{0.5}{s}} \cdot \frac{1}{1 + e^{\frac{x}{s}}} \]
    6. Taylor expanded in x around 0 43.6%

      \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{2 + \frac{x}{s}}} \]
    7. Step-by-step derivation
      1. +-commutative43.6%

        \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
    8. Simplified43.6%

      \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
    9. Taylor expanded in x around inf 34.3%

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

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

Alternative 7: 50.4% accurate, 68.9× speedup?

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{s}} \cdot \frac{1}{1 + e^{\frac{x}{s}}} \]
  6. Taylor expanded in x around 0 49.4%

    \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{2 + \frac{x}{s}}} \]
  7. Step-by-step derivation
    1. +-commutative49.4%

      \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
  8. Simplified49.4%

    \[\leadsto \frac{0.5}{s} \cdot \frac{1}{\color{blue}{\frac{x}{s} + 2}} \]
  9. Step-by-step derivation
    1. frac-times49.4%

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

      \[\leadsto \frac{\color{blue}{0.5}}{s \cdot \left(\frac{x}{s} + 2\right)} \]
  10. Applied egg-rr49.4%

    \[\leadsto \color{blue}{\frac{0.5}{s \cdot \left(\frac{x}{s} + 2\right)}} \]
  11. Final simplification49.4%

    \[\leadsto \frac{0.5}{s \cdot \left(\frac{x}{s} + 2\right)} \]

Alternative 8: 27.0% accurate, 206.7× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  5. Final simplification31.0%

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

Reproduce

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