Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 11.5s
Alternatives: 9
Speedup: 0.9×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 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, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ \frac{t\_0}{\left(t\_0 + 1\right) \cdot \mathsf{fma}\left(s, t\_0, s\right)} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s)))) (/ t_0 (* (+ t_0 1.0) (fma s t_0 s)))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	return t_0 / ((t_0 + 1.0f) * fmaf(s, t_0, s));
}
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	return Float32(t_0 / Float32(Float32(t_0 + Float32(1.0)) * fma(s, t_0, s)))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{\left(t\_0 + 1\right) \cdot \mathsf{fma}\left(s, t\_0, s\right)}
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

Alternative 2: 63.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := t\_0 + 1\\ \mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\ \;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{s}{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ t_0 1.0)))
   (if (<= (/ t_0 (* t_1 (* s t_1))) 2.0000000063421537e-28)
     (/ (exp (/ (exp (log x)) (- s))) (* s 4.0))
     (/ 1.0 (/ s (exp (- (/ x s) (* 2.0 (log1p (exp (/ x s)))))))))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = t_0 + 1.0f;
	float tmp;
	if ((t_0 / (t_1 * (s * t_1))) <= 2.0000000063421537e-28f) {
		tmp = expf((expf(logf(x)) / -s)) / (s * 4.0f);
	} else {
		tmp = 1.0f / (s / expf(((x / s) - (2.0f * log1pf(expf((x / s)))))));
	}
	return tmp;
}
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(t_0 + Float32(1.0))
	tmp = Float32(0.0)
	if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(2.0000000063421537e-28))
		tmp = Float32(exp(Float32(exp(log(x)) / Float32(-s))) / Float32(s * Float32(4.0)));
	else
		tmp = Float32(Float32(1.0) / Float32(s / exp(Float32(Float32(x / s) - Float32(Float32(2.0) * log1p(exp(Float32(x / s))))))));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\
\;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{s}{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 2.00000001e-28

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt55.7%

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

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

        \[\leadsto \frac{e^{\frac{-\color{blue}{x}}{s}}}{s \cdot 4} \]
      4. add-exp-log55.7%

        \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]
    9. Applied egg-rr55.7%

      \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]

    if 2.00000001e-28 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))))

    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. *-commutative99.2%

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

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

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

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

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

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

        \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{1 + e^{\frac{-\left|x\right|}{s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right)}} \]
      6. associate-/r*99.3%

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

        \[\leadsto \color{blue}{e^{\frac{-\left|x\right|}{s}} \cdot \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right)}} \]
      8. *-commutative99.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)} \cdot e^{\frac{-\left|x\right|}{s}}} \]
    6. Applied egg-rr97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{\frac{-\left|x\right|}{s}}}{\left(e^{\frac{-\left|x\right|}{s}} + 1\right) \cdot \left(s \cdot \left(e^{\frac{-\left|x\right|}{s}} + 1\right)\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\ \;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{s}{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 63.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{-\left|x\right|}{s}}\\ t_1 := t\_0 + 1\\ \mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\ \;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{x}{s} + \mathsf{log1p}\left(e^{\frac{x}{s}}\right) \cdot -2}}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ t_0 1.0)))
   (if (<= (/ t_0 (* t_1 (* s t_1))) 2.0000000063421537e-28)
     (/ (exp (/ (exp (log x)) (- s))) (* s 4.0))
     (/ (exp (+ (/ x s) (* (log1p (exp (/ x s))) -2.0))) s))))
float code(float x, float s) {
	float t_0 = expf((-fabsf(x) / s));
	float t_1 = t_0 + 1.0f;
	float tmp;
	if ((t_0 / (t_1 * (s * t_1))) <= 2.0000000063421537e-28f) {
		tmp = expf((expf(logf(x)) / -s)) / (s * 4.0f);
	} else {
		tmp = expf(((x / s) + (log1pf(expf((x / s))) * -2.0f))) / s;
	}
	return tmp;
}
function code(x, s)
	t_0 = exp(Float32(Float32(-abs(x)) / s))
	t_1 = Float32(t_0 + Float32(1.0))
	tmp = Float32(0.0)
	if (Float32(t_0 / Float32(t_1 * Float32(s * t_1))) <= Float32(2.0000000063421537e-28))
		tmp = Float32(exp(Float32(exp(log(x)) / Float32(-s))) / Float32(s * Float32(4.0)));
	else
		tmp = Float32(exp(Float32(Float32(x / s) + Float32(log1p(exp(Float32(x / s))) * Float32(-2.0)))) / s);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\mathbf{if}\;\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\
\;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{x}{s} + \mathsf{log1p}\left(e^{\frac{x}{s}}\right) \cdot -2}}{s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s))))) < 2.00000001e-28

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
    8. Step-by-step derivation
      1. add-sqr-sqrt55.7%

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

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

        \[\leadsto \frac{e^{\frac{-\color{blue}{x}}{s}}}{s \cdot 4} \]
      4. add-exp-log55.7%

        \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]
    9. Applied egg-rr55.7%

      \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]

    if 2.00000001e-28 < (/.f32 (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)) (*.f32 (*.f32 s (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))) (+.f32 #s(literal 1 binary32) (exp.f32 (/.f32 (neg.f32 (fabs.f32 x)) s)))))

    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. *-commutative99.2%

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

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

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

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

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

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

        \[\leadsto \frac{\frac{e^{\frac{-\left|x\right|}{s}}}{1 + e^{\frac{-\left|x\right|}{s}}}}{\color{blue}{\mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right)}} \]
      6. associate-/r*99.3%

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

        \[\leadsto \color{blue}{e^{\frac{-\left|x\right|}{s}} \cdot \frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{-\left|x\right|}{s}}, s\right)}} \]
      8. *-commutative99.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)} \cdot e^{\frac{-\left|x\right|}{s}}} \]
    6. Applied egg-rr97.9%

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

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

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

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

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

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

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{\color{blue}{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} \cdot 2} \cdot s} \]
      6. *-commutative98.0%

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{\color{blue}{2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}} \cdot s} \]
      7. rem-exp-log90.9%

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)} \cdot \color{blue}{e^{\log s}}} \]
      8. exp-sum91.6%

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

        \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right) + \log s\right)}} \]
      10. associate--r+91.1%

        \[\leadsto e^{\color{blue}{\left(\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right) - \log s}} \]
      11. exp-diff92.1%

        \[\leadsto \color{blue}{\frac{e^{\frac{x}{s} - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{e^{\log s}}} \]
    9. Simplified99.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{e^{\frac{-\left|x\right|}{s}}}{\left(e^{\frac{-\left|x\right|}{s}} + 1\right) \cdot \left(s \cdot \left(e^{\frac{-\left|x\right|}{s}} + 1\right)\right)} \leq 2.0000000063421537 \cdot 10^{-28}:\\ \;\;\;\;\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{x}{s} + \mathsf{log1p}\left(e^{\frac{x}{s}}\right) \cdot -2}}{s}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 62.8% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{x}{-s}}\\
\frac{\frac{t\_0}{s}}{{\left(1 + t\_0\right)}^{2}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

    \[\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}}} \]
  6. Step-by-step derivation
    1. associate-/r*99.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{{\left({\left(e^{-1}\right)}^{\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}\right)} + 1\right)}^{2}} \]
    13. rem-square-sqrt67.3%

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

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

      \[\leadsto \frac{\frac{e^{\frac{x}{-s}}}{s}}{{\left(e^{\color{blue}{-\frac{x}{s}}} + 1\right)}^{2}} \]
    16. distribute-neg-frac267.4%

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

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

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

Alternative 5: 47.9% accurate, 2.0× speedup?

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

\\
\frac{e^{\frac{e^{\log x}}{-s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{x}}{s}}}{s \cdot 4} \]
    4. add-exp-log52.8%

      \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]
  9. Applied egg-rr52.8%

    \[\leadsto \frac{e^{\frac{-\color{blue}{e^{\log x}}}{s}}}{s \cdot 4} \]
  10. Final simplification52.8%

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

Alternative 6: 59.6% accurate, 5.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{e^{\color{blue}{x \cdot \frac{1}{-s}}}}{s \cdot 4} \]
  10. Taylor expanded in s around 0 64.2%

    \[\leadsto \frac{e^{x \cdot \color{blue}{\frac{-1}{s}}}}{s \cdot 4} \]
  11. Add Preprocessing

Alternative 7: 59.6% accurate, 5.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Step-by-step derivation
    1. add-sqr-sqrt95.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\sqrt{\left|x\right| \cdot \left|x\right|}}}{s}}}{s \cdot 4} \]
    3. sqr-abs93.8%

      \[\leadsto \frac{e^{\frac{-\sqrt{\color{blue}{x \cdot x}}}{s}}}{s \cdot 4} \]
    4. sqr-neg93.8%

      \[\leadsto \frac{e^{\frac{-\sqrt{\color{blue}{\left(-x\right) \cdot \left(-x\right)}}}{s}}}{s \cdot 4} \]
    5. add-sqr-sqrt51.8%

      \[\leadsto \frac{e^{\frac{-\sqrt{\left(-\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right) \cdot \left(-x\right)}}{s}}}{s \cdot 4} \]
    6. fabs-sqr51.8%

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

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

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

      \[\leadsto \frac{e^{\frac{-\sqrt{\left(-\left|x\right|\right) \cdot \left(-\color{blue}{\left|\sqrt{x} \cdot \sqrt{x}\right|}\right)}}{s}}}{s \cdot 4} \]
    10. add-sqr-sqrt93.8%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}{s \cdot 4} \]
    12. add-sqr-sqrt24.3%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\left(0 - \left|x\right|\right)}}{s}}}{s \cdot 4} \]
    14. add-sqr-sqrt12.9%

      \[\leadsto \frac{e^{\frac{-\left(0 - \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)}{s}}}{s \cdot 4} \]
    15. fabs-sqr12.9%

      \[\leadsto \frac{e^{\frac{-\left(0 - \color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)}{s}}}{s \cdot 4} \]
    16. add-sqr-sqrt55.8%

      \[\leadsto \frac{e^{\frac{-\left(0 - \color{blue}{x}\right)}{s}}}{s \cdot 4} \]
    17. sub-neg55.8%

      \[\leadsto \frac{e^{\frac{-\color{blue}{\left(0 + \left(-x\right)\right)}}{s}}}{s \cdot 4} \]
    18. add-sqr-sqrt12.9%

      \[\leadsto \frac{e^{\frac{-\left(0 + \left(-\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right)\right)}{s}}}{s \cdot 4} \]
    19. fabs-sqr12.9%

      \[\leadsto \frac{e^{\frac{-\left(0 + \left(-\color{blue}{\left|\sqrt{x} \cdot \sqrt{x}\right|}\right)\right)}{s}}}{s \cdot 4} \]
    20. add-sqr-sqrt24.3%

      \[\leadsto \frac{e^{\frac{-\left(0 + \left(-\left|\color{blue}{x}\right|\right)\right)}{s}}}{s \cdot 4} \]
    21. add-sqr-sqrt-0.0%

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

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

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

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

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

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

Alternative 8: 59.6% accurate, 5.8× speedup?

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

\\
\frac{\frac{0.25}{e^{\frac{x}{s}}}}{s}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{e^{\color{blue}{x \cdot \frac{1}{-s}}}}{s \cdot 4} \]
  10. Taylor expanded in x around inf 64.2%

    \[\leadsto \color{blue}{0.25 \cdot \frac{e^{-1 \cdot \frac{x}{s}}}{s}} \]
  11. Step-by-step derivation
    1. associate-*r/64.2%

      \[\leadsto \color{blue}{\frac{0.25 \cdot e^{-1 \cdot \frac{x}{s}}}{s}} \]
    2. mul-1-neg64.2%

      \[\leadsto \frac{0.25 \cdot e^{\color{blue}{-\frac{x}{s}}}}{s} \]
    3. rec-exp64.1%

      \[\leadsto \frac{0.25 \cdot \color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s} \]
    4. associate-*r/64.1%

      \[\leadsto \frac{\color{blue}{\frac{0.25 \cdot 1}{e^{\frac{x}{s}}}}}{s} \]
    5. metadata-eval64.1%

      \[\leadsto \frac{\frac{\color{blue}{0.25}}{e^{\frac{x}{s}}}}{s} \]
  12. Simplified64.1%

    \[\leadsto \color{blue}{\frac{\frac{0.25}{e^{\frac{x}{s}}}}{s}} \]
  13. Add Preprocessing

Alternative 9: 27.0% 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.8%

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  6. Add Preprocessing

Reproduce

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