Logistic distribution

Percentage Accurate: 99.6% → 99.5%
Time: 15.0s
Alternatives: 9
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 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.5% accurate, 1.5× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{0}{s}\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\frac{x}{s} - \left(2 \cdot \color{blue}{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} + \log s\right)} \]
      8. *-un-lft-identity94.3%

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

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

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

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

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

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

    if 5 < (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. Applied egg-rr53.1%

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

        \[\leadsto \color{blue}{\frac{e^{\frac{x}{s}}}{s \cdot {\left(1 + e^{\frac{x}{s}}\right)}^{2}}} \]
    7. Simplified53.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. *-un-lft-identity53.1%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(0.25 + 0.25 \cdot \frac{x \cdot \log e}{s}\right) - 0.25 \cdot \frac{x}{s}}{s}} \]
    13. Taylor expanded in x around inf 31.4%

      \[\leadsto \frac{\color{blue}{x \cdot \left(0.25 \cdot \frac{\log e}{s} - 0.25 \cdot \frac{1}{s}\right)}}{s} \]
    14. Step-by-step derivation
      1. log-E100.0%

        \[\leadsto \frac{x \cdot \left(0.25 \cdot \frac{\color{blue}{1}}{s} - 0.25 \cdot \frac{1}{s}\right)}{s} \]
      2. +-inverses100.0%

        \[\leadsto \frac{x \cdot \color{blue}{0}}{s} \]
      3. metadata-eval100.0%

        \[\leadsto \frac{x \cdot \color{blue}{\left(0.25 - 0.25\right)}}{s} \]
      4. distribute-rgt-out--100.0%

        \[\leadsto \frac{\color{blue}{0.25 \cdot x - 0.25 \cdot x}}{s} \]
      5. +-inverses100.0%

        \[\leadsto \frac{\color{blue}{0}}{s} \]
    15. Simplified100.0%

      \[\leadsto \frac{\color{blue}{0}}{s} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.7%

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

Alternative 2: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\frac{\left|x\right|}{-s}}\\ t_1 := t\_0 + 1\\ \frac{t\_0}{s \cdot \left(t\_1 \cdot t\_1\right)} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (exp (/ (fabs x) (- s)))) (t_1 (+ t_0 1.0)))
   (/ t_0 (* s (* t_1 t_1)))))
float code(float x, float s) {
	float t_0 = expf((fabsf(x) / -s));
	float t_1 = t_0 + 1.0f;
	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 = t_0 + 1.0e0
    code = t_0 / (s * (t_1 * t_1))
end function
function code(x, s)
	t_0 = exp(Float32(abs(x) / Float32(-s)))
	t_1 = Float32(t_0 + Float32(1.0))
	return Float32(t_0 / Float32(s * Float32(t_1 * t_1)))
end
function tmp = code(x, s)
	t_0 = exp((abs(x) / -s));
	t_1 = t_0 + single(1.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 := t\_0 + 1\\
\frac{t\_0}{s \cdot \left(t\_1 \cdot t\_1\right)}
\end{array}
\end{array}
Derivation
  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. Final simplification99.7%

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

Alternative 3: 99.6% accurate, 1.0× speedup?

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

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

    \[\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 4: 97.3% accurate, 1.2× speedup?

\[\begin{array}{l} \\ e^{\mathsf{fma}\left(x, \frac{1}{s}, \left(-\log s\right) - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)} \end{array} \]
(FPCore (x s)
 :precision binary32
 (exp (fma x (/ 1.0 s) (- (- (log s)) (* 2.0 (log1p (exp (/ x s))))))))
float code(float x, float s) {
	return expf(fmaf(x, (1.0f / s), (-logf(s) - (2.0f * log1pf(expf((x / s)))))));
}
function code(x, s)
	return exp(fma(x, Float32(Float32(1.0) / s), Float32(Float32(-log(s)) - Float32(Float32(2.0) * log1p(exp(Float32(x / s)))))))
end
\begin{array}{l}

\\
e^{\mathsf{fma}\left(x, \frac{1}{s}, \left(-\log s\right) - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)}
\end{array}
Derivation
  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. Applied egg-rr87.0%

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

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

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

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

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

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

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

      \[\leadsto e^{\mathsf{fma}\left(x, \frac{1}{s}, -\color{blue}{\mathsf{fma}\left(2, \mathsf{log1p}\left(e^{\frac{x}{s}}\right), \log s\right)}\right)} \]
  7. Applied egg-rr97.1%

    \[\leadsto e^{\color{blue}{\mathsf{fma}\left(x, \frac{1}{s}, -\mathsf{fma}\left(2, \mathsf{log1p}\left(e^{\frac{x}{s}}\right), \log s\right)\right)}} \]
  8. Step-by-step derivation
    1. fma-undefine97.1%

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

    \[\leadsto e^{\mathsf{fma}\left(x, \frac{1}{s}, -\color{blue}{\left(2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right) + \log s\right)}\right)} \]
  10. Final simplification97.1%

    \[\leadsto e^{\mathsf{fma}\left(x, \frac{1}{s}, \left(-\log s\right) - 2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)\right)} \]
  11. Add Preprocessing

Alternative 5: 94.9% accurate, 3.0× speedup?

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

\\
\frac{e^{\frac{\left|x\right|}{-s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.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 94.3%

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

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

Alternative 6: 77.7% accurate, 31.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 6.000000212225132 \cdot 10^{-6}:\\ \;\;\;\;\frac{\frac{0.25 \cdot \left(x + s\right)}{s} - \frac{x}{s} \cdot 0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 6.000000212225132e-6)
   (/ (- (/ (* 0.25 (+ x s)) s) (* (/ x s) 0.25)) s)
   (/ 0.0 s)))
float code(float x, float s) {
	float tmp;
	if (x <= 6.000000212225132e-6f) {
		tmp = (((0.25f * (x + s)) / s) - ((x / s) * 0.25f)) / s;
	} else {
		tmp = 0.0f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if (x <= 6.000000212225132e-6) then
        tmp = (((0.25e0 * (x + s)) / s) - ((x / s) * 0.25e0)) / s
    else
        tmp = 0.0e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(6.000000212225132e-6))
		tmp = Float32(Float32(Float32(Float32(Float32(0.25) * Float32(x + s)) / s) - Float32(Float32(x / s) * Float32(0.25))) / s);
	else
		tmp = Float32(Float32(0.0) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(6.000000212225132e-6))
		tmp = (((single(0.25) * (x + s)) / s) - ((x / s) * single(0.25))) / s;
	else
		tmp = single(0.0) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.000000212225132 \cdot 10^{-6}:\\
\;\;\;\;\frac{\frac{0.25 \cdot \left(x + s\right)}{s} - \frac{x}{s} \cdot 0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{0}{s}\\


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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(0.25 + 0.25 \cdot \frac{x \cdot \log e}{s}\right) - 0.25 \cdot \frac{x}{s}}{s}} \]
    13. Taylor expanded in s around 0 37.5%

      \[\leadsto \frac{\color{blue}{\frac{0.25 \cdot s + 0.25 \cdot \left(x \cdot \log e\right)}{s}} - 0.25 \cdot \frac{x}{s}}{s} \]
    14. Step-by-step derivation
      1. +-commutative37.5%

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

        \[\leadsto \frac{\frac{0.25 \cdot \left(x \cdot \color{blue}{1}\right) + 0.25 \cdot s}{s} - 0.25 \cdot \frac{x}{s}}{s} \]
      3. associate-*r*67.9%

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

        \[\leadsto \frac{\frac{\color{blue}{0.25 \cdot x} + 0.25 \cdot s}{s} - 0.25 \cdot \frac{x}{s}}{s} \]
      5. distribute-lft-out67.9%

        \[\leadsto \frac{\frac{\color{blue}{0.25 \cdot \left(x + s\right)}}{s} - 0.25 \cdot \frac{x}{s}}{s} \]
    15. Simplified67.9%

      \[\leadsto \frac{\color{blue}{\frac{0.25 \cdot \left(x + s\right)}{s}} - 0.25 \cdot \frac{x}{s}}{s} \]

    if 6.00000021e-6 < 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. Applied egg-rr2.8%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(0.25 + 0.25 \cdot \frac{x \cdot \log e}{s}\right) - 0.25 \cdot \frac{x}{s}}{s}} \]
    13. Taylor expanded in x around inf 31.8%

      \[\leadsto \frac{\color{blue}{x \cdot \left(0.25 \cdot \frac{\log e}{s} - 0.25 \cdot \frac{1}{s}\right)}}{s} \]
    14. Step-by-step derivation
      1. log-E96.3%

        \[\leadsto \frac{x \cdot \left(0.25 \cdot \frac{\color{blue}{1}}{s} - 0.25 \cdot \frac{1}{s}\right)}{s} \]
      2. +-inverses96.3%

        \[\leadsto \frac{x \cdot \color{blue}{0}}{s} \]
      3. metadata-eval96.3%

        \[\leadsto \frac{x \cdot \color{blue}{\left(0.25 - 0.25\right)}}{s} \]
      4. distribute-rgt-out--96.3%

        \[\leadsto \frac{\color{blue}{0.25 \cdot x - 0.25 \cdot x}}{s} \]
      5. +-inverses96.3%

        \[\leadsto \frac{\color{blue}{0}}{s} \]
    15. Simplified96.3%

      \[\leadsto \frac{\color{blue}{0}}{s} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification75.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 6.000000212225132 \cdot 10^{-6}:\\ \;\;\;\;\frac{\frac{0.25 \cdot \left(x + s\right)}{s} - \frac{x}{s} \cdot 0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0}{s}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 56.2% accurate, 77.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.999999936531045 \cdot 10^{-20}:\\
\;\;\;\;\frac{0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{0}{s}\\


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

    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.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 34.9%

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

    if 1.99999994e-20 < x

    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-rr12.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\left(0.25 + 0.25 \cdot \frac{x \cdot \log e}{s}\right) - 0.25 \cdot \frac{x}{s}}{s}} \]
    13. Taylor expanded in x around inf 33.7%

      \[\leadsto \frac{\color{blue}{x \cdot \left(0.25 \cdot \frac{\log e}{s} - 0.25 \cdot \frac{1}{s}\right)}}{s} \]
    14. Step-by-step derivation
      1. log-E87.0%

        \[\leadsto \frac{x \cdot \left(0.25 \cdot \frac{\color{blue}{1}}{s} - 0.25 \cdot \frac{1}{s}\right)}{s} \]
      2. +-inverses87.0%

        \[\leadsto \frac{x \cdot \color{blue}{0}}{s} \]
      3. metadata-eval87.0%

        \[\leadsto \frac{x \cdot \color{blue}{\left(0.25 - 0.25\right)}}{s} \]
      4. distribute-rgt-out--87.0%

        \[\leadsto \frac{\color{blue}{0.25 \cdot x - 0.25 \cdot x}}{s} \]
      5. +-inverses87.0%

        \[\leadsto \frac{\color{blue}{0}}{s} \]
    15. Simplified87.0%

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

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

Alternative 8: 74.3% accurate, 206.7× speedup?

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

\\
\frac{0}{s}
\end{array}
Derivation
  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. Applied egg-rr65.3%

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\left(0.25 + 0.25 \cdot \frac{x \cdot \log e}{s}\right) - 0.25 \cdot \frac{x}{s}}{s}} \]
  13. Taylor expanded in x around inf 27.2%

    \[\leadsto \frac{\color{blue}{x \cdot \left(0.25 \cdot \frac{\log e}{s} - 0.25 \cdot \frac{1}{s}\right)}}{s} \]
  14. Step-by-step derivation
    1. log-E73.0%

      \[\leadsto \frac{x \cdot \left(0.25 \cdot \frac{\color{blue}{1}}{s} - 0.25 \cdot \frac{1}{s}\right)}{s} \]
    2. +-inverses73.0%

      \[\leadsto \frac{x \cdot \color{blue}{0}}{s} \]
    3. metadata-eval73.0%

      \[\leadsto \frac{x \cdot \color{blue}{\left(0.25 - 0.25\right)}}{s} \]
    4. distribute-rgt-out--73.0%

      \[\leadsto \frac{\color{blue}{0.25 \cdot x - 0.25 \cdot x}}{s} \]
    5. +-inverses73.0%

      \[\leadsto \frac{\color{blue}{0}}{s} \]
  15. Simplified73.0%

    \[\leadsto \frac{\color{blue}{0}}{s} \]
  16. Final simplification73.0%

    \[\leadsto \frac{0}{s} \]
  17. Add Preprocessing

Alternative 9: 8.2% accurate, 620.0× speedup?

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

\\
1
\end{array}
Derivation
  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. Applied egg-rr87.0%

    \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right) + \log s\right)}} \]
  6. Taylor expanded in x around inf 42.2%

    \[\leadsto e^{\color{blue}{\frac{x}{s}}} \]
  7. Taylor expanded in x around 0 8.2%

    \[\leadsto \color{blue}{1} \]
  8. Final simplification8.2%

    \[\leadsto 1 \]
  9. Add Preprocessing

Reproduce

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