Logistic distribution

Percentage Accurate: 99.5% → 99.4%
Time: 18.5s
Alternatives: 12
Speedup: N/A×

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

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

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

Alternative 1: 99.4% accurate, 1.5× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

    \[\leadsto \frac{1}{\left(1 + \color{blue}{\frac{1}{e^{\frac{x}{s}}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
  10. Step-by-step derivation
    1. rec-exp99.0%

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

    \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{\frac{-x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
  12. Final simplification99.0%

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

Alternative 2: 99.4% accurate, 2.9× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s \cdot \left(1 + e^{\frac{x}{s}}\right)\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

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

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

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

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

Alternative 3: 99.4% accurate, 2.9× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{-x}{s}}\right) \cdot \left(s + s \cdot e^{\frac{x}{s}}\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

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

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

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

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

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

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

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

Alternative 4: 74.0% accurate, 5.4× speedup?

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

\\
\frac{1}{\left(s + s \cdot e^{\frac{x}{s}}\right) \cdot \left(2 - \frac{x}{s}\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

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

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

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

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

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

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

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

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

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

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

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

Alternative 5: 62.7% accurate, 5.5× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{x}{s}}\right) \cdot \left(s \cdot 2 - x\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

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

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 59.7% accurate, 5.5× speedup?

\[\begin{array}{l} \\ \frac{1}{2 \cdot \left(s \cdot \left(1 + {e}^{\left(\frac{x}{s}\right)}\right)\right)} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ 1.0 (* 2.0 (* s (+ 1.0 (pow E (/ x s)))))))
float code(float x, float s) {
	return 1.0f / (2.0f * (s * (1.0f + powf(((float) M_E), (x / s)))));
}
function code(x, s)
	return Float32(Float32(1.0) / Float32(Float32(2.0) * Float32(s * Float32(Float32(1.0) + (Float32(exp(1)) ^ Float32(x / s))))))
end
function tmp = code(x, s)
	tmp = single(1.0) / (single(2.0) * (s * (single(1.0) + (single(2.71828182845904523536) ^ (x / s)))));
end
\begin{array}{l}

\\
\frac{1}{2 \cdot \left(s \cdot \left(1 + {e}^{\left(\frac{x}{s}\right)}\right)\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 59.7% accurate, 5.7× speedup?

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

\\
\frac{0.5}{s \cdot \left(1 + e^{\frac{x}{s}}\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 63.9% accurate, 47.7× speedup?

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

\\
\frac{1}{\left(2 - \frac{x}{s}\right) \cdot \left(x + s \cdot 2\right)}
\end{array}
Derivation
  1. Initial program 98.8%

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    11. add-sqr-sqrt95.0%

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{-\left|x\right|} \cdot \sqrt{-\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    13. sqrt-unprod61.6%

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{\left|x\right|} \cdot \sqrt{\left|x\right|}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    16. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\left|x\right|}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    17. add-sqr-sqrt51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    18. fabs-sqr51.0%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    19. add-sqr-sqrt99.0%

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

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

      \[\leadsto \frac{1}{\left(1 + \color{blue}{e^{-\frac{x}{s}}}\right) \cdot \left(s \cdot e^{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)}\right)} \]
    2. distribute-neg-frac99.0%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 50.6% accurate, 56.4× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{2 \cdot \left(\color{blue}{\left(\frac{x}{s} + 2\right)} \cdot s\right)} \]
  10. Final simplification50.0%

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

Alternative 10: 28.9% accurate, 68.9× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
  3. Add Preprocessing
  4. Step-by-step derivation
    1. fma-udef98.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{2 \cdot \color{blue}{\left(x + s \cdot 2\right)}} \]
  10. Final simplification27.4%

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

Alternative 11: 28.4% accurate, 77.2× speedup?

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

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

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


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

    1. Initial program 98.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. *-commutative98.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999997e-7 < 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. Simplified99.8%

      \[\leadsto \color{blue}{\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Add Preprocessing
    4. Step-by-step derivation
      1. fma-udef99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{2 \cdot \left(x + \color{blue}{s \cdot 2}\right)} \]
    9. Simplified11.6%

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

      \[\leadsto \color{blue}{\frac{0.5}{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification27.7%

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

Alternative 12: 26.8% 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 98.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Reproduce

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