Logistic distribution

Percentage Accurate: 99.4% → 99.4%
Time: 13.7s
Alternatives: 11
Speedup: 1.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 11 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.4% accurate, 1.0× speedup?

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

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

Alternative 1: 99.4% accurate, 1.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left|x\_m\right| \leq 1:\\
\;\;\;\;\frac{e^{\frac{x\_m}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x\_m}{s}}\right)}}{s}\\

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


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

    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. fabs-neg99.5%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.5%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg99.5%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-commutative99.5%

        \[\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)}} \]
      6. fabs-neg99.5%

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

        \[\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)} \]
      8. fabs-neg99.5%

        \[\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)} \]
    3. Simplified99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1 < (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. fabs-neg100.0%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg100.0%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg100.0%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-commutative100.0%

        \[\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)}} \]
      6. fabs-neg100.0%

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

        \[\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)} \]
      8. fabs-neg100.0%

        \[\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)} \]
    3. Simplified100.0%

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{s \cdot 4}{e^{\frac{\left|x\right|}{-s}}}}} \]
      2. inv-pow100.0%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
    9. Simplified56.1%

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

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

        \[\leadsto e^{\color{blue}{-\log \left(s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)\right)}} \]
      3. associate-*r*56.1%

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 1.0× speedup?

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

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

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

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

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

Alternative 3: 87.1% accurate, 5.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 7.199999771511762 \cdot 10^{-21}:\\
\;\;\;\;\frac{0.25}{s}\\

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


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

    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. fabs-neg99.6%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.6%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg99.6%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-commutative99.6%

        \[\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)}} \]
      6. fabs-neg99.6%

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

        \[\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)} \]
      8. fabs-neg99.6%

        \[\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)} \]
    3. Simplified99.7%

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

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

    if 7.1999998e-21 < x

    1. Initial program 99.8%

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

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.8%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg99.8%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-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)}} \]
      6. fabs-neg99.8%

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

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

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

        \[\leadsto \color{blue}{\frac{1}{\frac{s \cdot 4}{e^{\frac{\left|x\right|}{-s}}}}} \]
      2. inv-pow93.5%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
    9. Simplified93.5%

      \[\leadsto \color{blue}{\frac{1}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
    10. Step-by-step derivation
      1. add-exp-log93.3%

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

        \[\leadsto e^{\color{blue}{-\log \left(s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)\right)}} \]
      3. associate-*r*93.3%

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

        \[\leadsto e^{-\color{blue}{\left(\log \left(s \cdot 4\right) + \log \left(e^{\frac{x}{s}}\right)\right)}} \]
      5. add-log-exp93.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 7.199999771511762 \cdot 10^{-21}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;e^{\frac{x}{-s}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 94.8% accurate, 5.7× speedup?

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

\\
\frac{\frac{0.5}{s}}{1 + e^{\frac{x\_m}{s}}}
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

    \[\leadsto \color{blue}{\frac{1}{1 + e^{\frac{x}{s}}} \cdot \frac{e^{\frac{x}{s}}}{\mathsf{fma}\left(s, e^{\frac{x}{s}}, s\right)}} \]
  6. Step-by-step derivation
    1. associate-*l/63.9%

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{0.5}{s}}}{1 + e^{\frac{x}{s}}} \]
  9. Final simplification64.5%

    \[\leadsto \frac{\frac{0.5}{s}}{1 + e^{\frac{x}{s}}} \]
  10. Add Preprocessing

Alternative 5: 94.6% accurate, 5.8× speedup?

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

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

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  10. Taylor expanded in s around 0 63.7%

    \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
  11. Final simplification63.7%

    \[\leadsto \frac{0.25}{s \cdot e^{\frac{x}{s}}} \]
  12. Add Preprocessing

Alternative 6: 62.7% accurate, 47.7× speedup?

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

\\
\frac{0.25}{s + x\_m \cdot \left(1 + \frac{x\_m}{s} \cdot 0.5\right)}
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  10. Taylor expanded in s around 0 63.7%

    \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
  11. Taylor expanded in x around 0 61.3%

    \[\leadsto \frac{0.25}{\color{blue}{s + x \cdot \left(1 + 0.5 \cdot \frac{x}{s}\right)}} \]
  12. Step-by-step derivation
    1. *-commutative61.3%

      \[\leadsto \frac{0.25}{s + x \cdot \left(1 + \color{blue}{\frac{x}{s} \cdot 0.5}\right)} \]
  13. Simplified61.3%

    \[\leadsto \frac{0.25}{\color{blue}{s + x \cdot \left(1 + \frac{x}{s} \cdot 0.5\right)}} \]
  14. Final simplification61.3%

    \[\leadsto \frac{0.25}{s + x \cdot \left(1 + \frac{x}{s} \cdot 0.5\right)} \]
  15. Add Preprocessing

Alternative 7: 51.3% accurate, 56.4× speedup?

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

\\
\frac{1}{s \cdot \left(4 + \frac{x\_m}{s} \cdot 4\right)}
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

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

    \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 + 4 \cdot \frac{x}{s}\right)}} \]
  11. Final simplification51.8%

    \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x}{s} \cdot 4\right)} \]
  12. Add Preprocessing

Alternative 8: 50.6% accurate, 68.9× speedup?

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

\\
\frac{0.25}{s \cdot \left(1 + \frac{x\_m}{s}\right)}
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  10. Taylor expanded in s around 0 63.7%

    \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
  11. Taylor expanded in s around inf 51.1%

    \[\leadsto \frac{0.25}{\color{blue}{s \cdot \left(1 + \frac{x}{s}\right)}} \]
  12. Final simplification51.1%

    \[\leadsto \frac{0.25}{s \cdot \left(1 + \frac{x}{s}\right)} \]
  13. Add Preprocessing

Alternative 9: 28.6% accurate, 124.0× speedup?

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

\\
\frac{0.25}{x\_m + s}
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

    \[\leadsto \color{blue}{\frac{1}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  10. Taylor expanded in s around 0 63.7%

    \[\leadsto \color{blue}{\frac{0.25}{s \cdot e^{\frac{x}{s}}}} \]
  11. Taylor expanded in x around 0 32.7%

    \[\leadsto \frac{0.25}{\color{blue}{s + x}} \]
  12. Final simplification32.7%

    \[\leadsto \frac{0.25}{x + s} \]
  13. Add Preprocessing

Alternative 10: 26.6% accurate, 206.7× speedup?

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

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

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

Alternative 11: 8.2% accurate, 620.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 99.7%

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

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.7%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.7%

      \[\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)}} \]
    6. fabs-neg99.7%

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

      \[\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)} \]
    8. fabs-neg99.7%

      \[\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)} \]
  3. Simplified99.7%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)}} \]
  9. Simplified63.7%

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

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

      \[\leadsto e^{\color{blue}{-\log \left(s \cdot \left(4 \cdot e^{\frac{x}{s}}\right)\right)}} \]
    3. associate-*r*62.1%

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

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

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

    \[\leadsto \color{blue}{e^{-\left(\log \left(s \cdot 4\right) + \frac{x}{s}\right)}} \]
  12. Step-by-step derivation
    1. neg-sub062.1%

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

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

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

      \[\leadsto e^{\log 1 - \color{blue}{\log \left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)}} \]
    5. expm1-log1p-u62.1%

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

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

      \[\leadsto \color{blue}{\frac{1}{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)\right)}} \]
    8. add-sqr-sqrt63.3%

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)\right)} \cdot \sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)\right)}}} \]
    9. associate-/r*63.3%

      \[\leadsto \color{blue}{\frac{\frac{1}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)\right)}}}{\sqrt{\mathsf{expm1}\left(\mathsf{log1p}\left(\left(s \cdot 4\right) \cdot e^{\frac{x}{s}}\right)\right)}}} \]
  13. Applied egg-rr4.3%

    \[\leadsto \color{blue}{\frac{\frac{0.5}{\sqrt{s \cdot e^{\frac{x}{s}}}}}{\frac{0.5}{\sqrt{s \cdot e^{\frac{x}{s}}}}}} \]
  14. Step-by-step derivation
    1. *-inverses8.5%

      \[\leadsto \color{blue}{1} \]
  15. Simplified8.5%

    \[\leadsto \color{blue}{1} \]
  16. Final simplification8.5%

    \[\leadsto 1 \]
  17. Add Preprocessing

Reproduce

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