Logistic distribution

Percentage Accurate: 99.6% → 99.7%
Time: 24.7s
Alternatives: 12
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

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

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

\\
\frac{1}{s \cdot \left(\left(2 + e^{\frac{\left|x\right|}{s}}\right) + e^{\frac{-\left|x\right|}{s}}\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. *-lft-identity99.6%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.6%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-*l*99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 97.4% accurate, 2.0× speedup?

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

\\
\frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{x}{s} \cdot \frac{x \cdot -0.25}{s}\right)}}{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. associate-*l*99.6%

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

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

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

    \[\leadsto \color{blue}{\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)}} \]
  4. Step-by-step derivation
    1. add-exp-log98.0%

      \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
    2. log-div98.0%

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

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

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

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

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

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

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

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

    \[\leadsto \frac{e^{\color{blue}{-2 \cdot \log 2 + \left(-1 \cdot \frac{\left|x\right|}{s} + \left(\frac{\left|x\right|}{s} + -1 \cdot \frac{0.5 \cdot {\left(\left|x\right|\right)}^{2} + -0.25 \cdot {\left(\left|x\right|\right)}^{2}}{{s}^{2}}\right)\right)}}}{s} \]
  9. Step-by-step derivation
    1. +-commutative56.5%

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

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

      \[\leadsto \frac{e^{\left(\color{blue}{\frac{-\left|x\right|}{s}} + \left(\frac{\left|x\right|}{s} + -1 \cdot \frac{0.5 \cdot {\left(\left|x\right|\right)}^{2} + -0.25 \cdot {\left(\left|x\right|\right)}^{2}}{{s}^{2}}\right)\right) + -2 \cdot \log 2}}{s} \]
  10. Simplified90.5%

    \[\leadsto \frac{e^{\color{blue}{\mathsf{fma}\left(-2, \log 2, \frac{-0.25 \cdot \left(x \cdot x\right)}{s \cdot s}\right)}}}{s} \]
  11. Taylor expanded in x around 0 90.5%

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

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, -0.25 \cdot \frac{\color{blue}{x \cdot x}}{{s}^{2}}\right)}}{s} \]
    2. associate-*r/90.5%

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

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{\color{blue}{\left(x \cdot x\right) \cdot -0.25}}{{s}^{2}}\right)}}{s} \]
    4. associate-*l*90.5%

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{\color{blue}{x \cdot \left(x \cdot -0.25\right)}}{{s}^{2}}\right)}}{s} \]
    5. unpow290.5%

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{x \cdot \left(x \cdot -0.25\right)}{\color{blue}{s \cdot s}}\right)}}{s} \]
    6. times-frac95.9%

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \color{blue}{\frac{x}{s} \cdot \frac{x \cdot -0.25}{s}}\right)}}{s} \]
  13. Simplified95.9%

    \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \color{blue}{\frac{x}{s} \cdot \frac{x \cdot -0.25}{s}}\right)}}{s} \]
  14. Final simplification95.9%

    \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, \frac{x}{s} \cdot \frac{x \cdot -0.25}{s}\right)}}{s} \]

Alternative 3: 95.1% accurate, 2.0× speedup?

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

\\
\frac{1}{2 \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\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. *-lft-identity99.6%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.6%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-/l*99.6%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{2} \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \]
  5. Final simplification94.3%

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

Alternative 4: 88.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 4.999999841327613 \cdot 10^{-21}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, x \cdot \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= (fabs x) 4.999999841327613e-21)
   (/ 1.0 (fma s 4.0 (* x (/ x s))))
   (/ (exp (/ (- (fabs x)) s)) s)))
float code(float x, float s) {
	float tmp;
	if (fabsf(x) <= 4.999999841327613e-21f) {
		tmp = 1.0f / fmaf(s, 4.0f, (x * (x / s)));
	} else {
		tmp = expf((-fabsf(x) / s)) / s;
	}
	return tmp;
}
function code(x, s)
	tmp = Float32(0.0)
	if (abs(x) <= Float32(4.999999841327613e-21))
		tmp = Float32(Float32(1.0) / fma(s, Float32(4.0), Float32(x * Float32(x / s))));
	else
		tmp = Float32(exp(Float32(Float32(-abs(x)) / s)) / s);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.999999841327613 \cdot 10^{-21}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, x \cdot \frac{x}{s}\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\


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

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      6. sqr-abs76.7%

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{\color{blue}{x \cdot x}}{s}\right)} \]
      7. unpow276.7%

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{\color{blue}{{x}^{2}}}{s}\right)} \]
      8. remove-double-neg76.7%

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{\color{blue}{-\left(-{x}^{2}\right)}}{s}\right)} \]
      9. mul-1-neg76.7%

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

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

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{-{x}^{2} \cdot \color{blue}{\left(-2 - -1\right)}}{s}\right)} \]
      12. distribute-rgt-out--76.7%

        \[\leadsto \frac{1}{0 + \left(4 \cdot s + \frac{-\color{blue}{\left(-2 \cdot {x}^{2} - -1 \cdot {x}^{2}\right)}}{s}\right)} \]
      13. neg-mul-176.7%

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(s, 4, \frac{x}{s} \cdot x\right)}} \]

    if 4.99999984e-21 < (fabs.f32 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. associate-*l*99.7%

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

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

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

      \[\leadsto \color{blue}{\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)}} \]
    4. Step-by-step derivation
      1. add-exp-log99.4%

        \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
      2. log-div99.4%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)}}{s}} \]
    8. Taylor expanded in s around 0 94.9%

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

        \[\leadsto \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{s} \]
      2. distribute-frac-neg94.9%

        \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s} \]
    10. Simplified94.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 4.999999841327613 \cdot 10^{-21}:\\ \;\;\;\;\frac{1}{\mathsf{fma}\left(s, 4, x \cdot \frac{x}{s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\ \end{array} \]

Alternative 5: 94.7% accurate, 2.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;s \leq 4.999999999099794 \cdot 10^{-24}:\\
\;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{e^{-2 \cdot \log 2 + \frac{-0.25}{\frac{s \cdot s}{x \cdot x}}}}{s}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if s < 5e-24

    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. associate-*l*99.6%

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

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

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

      \[\leadsto \color{blue}{\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)}} \]
    4. Step-by-step derivation
      1. add-exp-log98.6%

        \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
      2. log-div98.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{-\left|x\right|}{s}}\right)}}{s}} \]
    8. Taylor expanded in s around 0 93.0%

      \[\leadsto \frac{e^{\color{blue}{-1 \cdot \frac{\left|x\right|}{s}}}}{s} \]
    9. Step-by-step derivation
      1. mul-1-neg93.0%

        \[\leadsto \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{s} \]
      2. distribute-frac-neg93.0%

        \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s} \]
    10. Simplified93.0%

      \[\leadsto \frac{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}{s} \]

    if 5e-24 < s

    1. Initial program 99.5%

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

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

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

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

      \[\leadsto \color{blue}{\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)}} \]
    4. Step-by-step derivation
      1. add-exp-log97.6%

        \[\leadsto \color{blue}{e^{\log \left(\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)}\right)}} \]
      2. log-div97.6%

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\color{blue}{-2 \cdot \log 2 + \left(-1 \cdot \frac{\left|x\right|}{s} + \left(\frac{\left|x\right|}{s} + -1 \cdot \frac{0.5 \cdot {\left(\left|x\right|\right)}^{2} + -0.25 \cdot {\left(\left|x\right|\right)}^{2}}{{s}^{2}}\right)\right)}}}{s} \]
    9. Step-by-step derivation
      1. +-commutative67.9%

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

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

        \[\leadsto \frac{e^{\left(\color{blue}{\frac{-\left|x\right|}{s}} + \left(\frac{\left|x\right|}{s} + -1 \cdot \frac{0.5 \cdot {\left(\left|x\right|\right)}^{2} + -0.25 \cdot {\left(\left|x\right|\right)}^{2}}{{s}^{2}}\right)\right) + -2 \cdot \log 2}}{s} \]
    10. Simplified96.5%

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

        \[\leadsto \frac{e^{\color{blue}{-2 \cdot \log 2 + \frac{-0.25 \cdot \left(x \cdot x\right)}{s \cdot s}}}}{s} \]
      2. associate-/l*96.5%

        \[\leadsto \frac{e^{-2 \cdot \log 2 + \color{blue}{\frac{-0.25}{\frac{s \cdot s}{x \cdot x}}}}}{s} \]
    12. Applied egg-rr96.5%

      \[\leadsto \frac{e^{\color{blue}{-2 \cdot \log 2 + \frac{-0.25}{\frac{s \cdot s}{x \cdot x}}}}}{s} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;s \leq 4.999999999099794 \cdot 10^{-24}:\\ \;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{-2 \cdot \log 2 + \frac{-0.25}{\frac{s \cdot s}{x \cdot x}}}}{s}\\ \end{array} \]

Alternative 6: 78.2% accurate, 47.7× speedup?

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

\\
\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot 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. *-lft-identity99.6%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.6%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-*l*99.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\left(\frac{{\left(\left|x\right|\right)}^{2}}{{s}^{2}} + 4\right) + \color{blue}{0}} \]
    5. associate-+r+79.4%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{{\left(\left|x\right|\right)}^{2}}{{s}^{2}} + \left(4 + 0\right)}} \]
    6. unpow279.4%

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

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

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

      \[\leadsto \frac{\frac{1}{s}}{\frac{x \cdot x}{s \cdot s} + \color{blue}{4}} \]
  6. Simplified79.4%

    \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\frac{x \cdot x}{s \cdot s} + 4}} \]
  7. Final simplification79.4%

    \[\leadsto \frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}} \]

Alternative 7: 64.8% accurate, 55.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001)))
   (/ 1.0 (* x (/ x s)))
   (/ 0.25 s)))
float code(float x, float s) {
	float tmp;
	if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
		tmp = 1.0f / (x * (x / s));
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
        tmp = 1.0e0 / (x * (x / s))
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001)))
		tmp = Float32(Float32(1.0) / Float32(x * Float32(x / s)));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001))))
		tmp = single(1.0) / (x * (x / s));
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.00000006e-8 or 7.9999998e-4 < x

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{s}, 4 \cdot s\right) - \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)} \]
      10. *-commutative4.6%

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      12. sqr-abs4.6%

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    6. Simplified4.6%

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(2 \cdot \frac{\color{blue}{x \cdot x}}{s} - \frac{x \cdot x}{s}\right)} \]
      2. associate-/l*4.4%

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

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

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

        \[\leadsto \color{blue}{1 \cdot \frac{1}{\left|x\right| \cdot 0 + \left(2 \cdot \left(\frac{x}{s} \cdot x\right) - \frac{x \cdot x}{s}\right)}} \]
      2. mul0-rgt4.4%

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

        \[\leadsto 1 \cdot \frac{1}{\color{blue}{\left(0 + 2 \cdot \left(\frac{x}{s} \cdot x\right)\right) - \frac{x \cdot x}{s}}} \]
      4. associate-*r*4.4%

        \[\leadsto 1 \cdot \frac{1}{\left(0 + \color{blue}{\left(2 \cdot \frac{x}{s}\right) \cdot x}\right) - \frac{x \cdot x}{s}} \]
      5. associate-*l/4.4%

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

        \[\leadsto 1 \cdot \frac{1}{\left(0 + \left(2 \cdot \frac{x}{s}\right) \cdot x\right) - \color{blue}{x \cdot \frac{x}{s}}} \]
    11. Applied egg-rr4.4%

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

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

        \[\leadsto \frac{1}{\color{blue}{\left(2 \cdot \frac{x}{s}\right) \cdot x} - x \cdot \frac{x}{s}} \]
      3. *-lft-identity4.4%

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

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

        \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(x \cdot \frac{x}{s}\right)} - 1 \cdot \left(x \cdot \frac{x}{s}\right)} \]
      6. distribute-rgt-out--71.9%

        \[\leadsto \frac{1}{\color{blue}{\left(x \cdot \frac{x}{s}\right) \cdot \left(2 - 1\right)}} \]
      7. metadata-eval71.9%

        \[\leadsto \frac{1}{\left(x \cdot \frac{x}{s}\right) \cdot \color{blue}{1}} \]
      8. *-rgt-identity71.9%

        \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s}}} \]
    13. Simplified71.9%

      \[\leadsto \color{blue}{\frac{1}{x \cdot \frac{x}{s}}} \]

    if -5.00000006e-8 < x < 7.9999998e-4

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 8: 64.8% accurate, 55.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001)))
   (/ 1.0 (/ x (/ s x)))
   (/ 0.25 s)))
float code(float x, float s) {
	float tmp;
	if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
		tmp = 1.0f / (x / (s / x));
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
        tmp = 1.0e0 / (x / (s / x))
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001)))
		tmp = Float32(Float32(1.0) / Float32(x / Float32(s / x)));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001))))
		tmp = single(1.0) / (x / (s / x));
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.00000006e-8 or 7.9999998e-4 < x

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{s}, 4 \cdot s\right) - \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)} \]
      10. *-commutative4.6%

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      12. sqr-abs4.6%

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    6. Simplified4.6%

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

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. unpow270.1%

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified70.1%

      \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
    10. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    11. Applied egg-rr70.1%

      \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    12. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
      2. associate-/r*70.1%

        \[\leadsto \color{blue}{\frac{\frac{s}{x}}{x}} \]
      3. clear-num71.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{s}{x}}}} \]
    13. Applied egg-rr71.9%

      \[\leadsto \color{blue}{\frac{1}{\frac{x}{\frac{s}{x}}}} \]

    if -5.00000006e-8 < x < 7.9999998e-4

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 9: 64.8% accurate, 55.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001)))
   (/ 1.0 (/ (* x x) s))
   (/ 0.25 s)))
float code(float x, float s) {
	float tmp;
	if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
		tmp = 1.0f / ((x * x) / s);
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
        tmp = 1.0e0 / ((x * x) / s)
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001)))
		tmp = Float32(Float32(1.0) / Float32(Float32(x * x) / s));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001))))
		tmp = single(1.0) / ((x * x) / s);
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.00000006e-8 or 7.9999998e-4 < x

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{s}, 4 \cdot s\right) - \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)} \]
      10. *-commutative4.6%

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      12. sqr-abs4.6%

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    6. Simplified4.6%

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

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. unpow270.1%

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified70.1%

      \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
    10. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    11. Applied egg-rr70.1%

      \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    12. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
      2. clear-num71.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x}{s}}} \]
    13. Applied egg-rr71.9%

      \[\leadsto \color{blue}{\frac{1}{\frac{x \cdot x}{s}}} \]

    if -5.00000006e-8 < x < 7.9999998e-4

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 10: 63.5% accurate, 66.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{s}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001)))
   (/ s (* x x))
   (/ 0.25 s)))
float code(float x, float s) {
	float tmp;
	if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
		tmp = s / (x * x);
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
        tmp = s / (x * x)
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001)))
		tmp = Float32(s / Float32(x * x));
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001))))
		tmp = s / (x * x);
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.00000006e-8 or 7.9999998e-4 < x

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{s}, 4 \cdot s\right) - \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)} \]
      10. *-commutative4.6%

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      12. sqr-abs4.6%

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    6. Simplified4.6%

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

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. unpow270.1%

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified70.1%

      \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]

    if -5.00000006e-8 < x < 7.9999998e-4

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{s}{x \cdot x}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 11: 63.4% accurate, 66.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{\frac{s}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (or (<= x -5.000000058430487e-8) (not (<= x 0.0007999999797903001)))
   (/ (/ s x) x)
   (/ 0.25 s)))
float code(float x, float s) {
	float tmp;
	if ((x <= -5.000000058430487e-8f) || !(x <= 0.0007999999797903001f)) {
		tmp = (s / x) / x;
	} else {
		tmp = 0.25f / s;
	}
	return tmp;
}
real(4) function code(x, s)
    real(4), intent (in) :: x
    real(4), intent (in) :: s
    real(4) :: tmp
    if ((x <= (-5.000000058430487e-8)) .or. (.not. (x <= 0.0007999999797903001e0))) then
        tmp = (s / x) / x
    else
        tmp = 0.25e0 / s
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if ((x <= Float32(-5.000000058430487e-8)) || !(x <= Float32(0.0007999999797903001)))
		tmp = Float32(Float32(s / x) / x);
	else
		tmp = Float32(Float32(0.25) / s);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if ((x <= single(-5.000000058430487e-8)) || ~((x <= single(0.0007999999797903001))))
		tmp = (s / x) / x;
	else
		tmp = single(0.25) / s;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\
\;\;\;\;\frac{\frac{s}{x}}{x}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < -5.00000006e-8 or 7.9999998e-4 < x

    1. Initial program 99.9%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-/l*99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{\color{blue}{x \cdot x}}{s}, 4 \cdot s\right) - \frac{{\left(\left|x\right|\right)}^{2}}{s}\right)} \]
      10. *-commutative4.6%

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

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{\left|x\right| \cdot \left|x\right|}}{s}\right)} \]
      12. sqr-abs4.6%

        \[\leadsto \frac{1}{\left|x\right| \cdot 0 + \left(\mathsf{fma}\left(2, \frac{x \cdot x}{s}, s \cdot 4\right) - \frac{\color{blue}{x \cdot x}}{s}\right)} \]
    6. Simplified4.6%

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

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. unpow270.1%

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified70.1%

      \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
    10. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    11. Applied egg-rr70.1%

      \[\leadsto \color{blue}{s \cdot \frac{1}{x \cdot x}} \]
    12. Step-by-step derivation
      1. div-inv70.1%

        \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
      2. associate-/r*70.1%

        \[\leadsto \color{blue}{\frac{\frac{s}{x}}{x}} \]
    13. Applied egg-rr70.1%

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

    if -5.00000006e-8 < x < 7.9999998e-4

    1. Initial program 99.1%

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

        \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.1%

        \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
      3. associate-*l*99.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification63.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -5.000000058430487 \cdot 10^{-8} \lor \neg \left(x \leq 0.0007999999797903001\right):\\ \;\;\;\;\frac{\frac{s}{x}}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{s}\\ \end{array} \]

Alternative 12: 27.7% accurate, 206.7× speedup?

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

\\
\frac{0.25}{s}
\end{array}
Derivation
  1. Initial program 99.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. *-lft-identity99.6%

      \[\leadsto \color{blue}{1 \cdot \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. associate-*r/99.6%

      \[\leadsto \color{blue}{\frac{1 \cdot 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)}} \]
    3. associate-*l*99.6%

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

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

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

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

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

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

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

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

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

Reproduce

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