Logistic distribution

Percentage Accurate: 99.6% → 99.6%
Time: 12.6s
Alternatives: 13
Speedup: 1.5×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 13 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.5× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
  3. Step-by-step derivation
    1. expm1-log1p-u97.9%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
    3. associate-/l/97.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.9% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 95.9% accurate, 2.9× speedup?

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

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

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

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

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

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

Alternative 4: 96.1% accurate, 3.0× speedup?

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

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

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

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

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

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

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

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

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

Alternative 5: 94.5% accurate, 3.0× speedup?

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

\\
\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

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

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

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

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

Alternative 6: 88.5% accurate, 5.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{s \cdot \left(4 + \frac{x \cdot x}{s \cdot s}\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{1}{s} \cdot \frac{1}{e^{\frac{x}{s}} + 3}\\


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

    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{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
    3. Step-by-step derivation
      1. expm1-log1p-u98.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)\right)} \]
      2. expm1-udef99.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
      3. associate-/l/99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
      11. times-frac77.5%

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

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

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

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

    if -2e-23 < x

    1. Initial program 99.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\frac{1}{3 + e^{\frac{\left|x\right|}{s}}}}{s}} \]
      3. div-inv96.6%

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

        \[\leadsto \frac{1}{\color{blue}{e^{\frac{\left|x\right|}{s}} + 3}} \cdot \frac{1}{s} \]
      5. add-sqr-sqrt96.6%

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

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

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

        \[\leadsto \frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}} + 3} \cdot \frac{1}{s} \]
      9. add-sqr-sqrt91.6%

        \[\leadsto \frac{1}{e^{\frac{\color{blue}{x}}{s}} + 3} \cdot \frac{1}{s} \]
    8. Applied egg-rr91.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.9999999996399175 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{s \cdot \left(4 + \frac{x \cdot x}{s \cdot s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{s} \cdot \frac{1}{e^{\frac{x}{s}} + 3}\\ \end{array} \]

Alternative 7: 88.6% accurate, 5.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.9999999996399175 \cdot 10^{-23}:\\
\;\;\;\;\frac{1}{s \cdot \left(4 + \frac{x \cdot x}{s \cdot s}\right)}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{e^{\frac{x}{s}} + 3}}{s}\\


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

    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{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
    3. Step-by-step derivation
      1. expm1-log1p-u98.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)\right)} \]
      2. expm1-udef99.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
      3. associate-/l/99.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
      11. times-frac77.5%

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

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

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

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

    if -2e-23 < x

    1. Initial program 99.6%

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

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

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

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

        \[\leadsto \frac{\frac{1}{s}}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \color{blue}{\left(2 + e^{\frac{\left|x\right|}{s}}\right)}\right)\right)} \]
    5. Applied egg-rr96.6%

      \[\leadsto \frac{\frac{1}{s}}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \left(2 + e^{\frac{\left|x\right|}{s}}\right)\right)\right)}} \]
    6. Step-by-step derivation
      1. add-exp-log94.7%

        \[\leadsto \color{blue}{e^{\log \left(\frac{\frac{1}{s}}{\mathsf{expm1}\left(\mathsf{log1p}\left(1 + \left(2 + e^{\frac{\left|x\right|}{s}}\right)\right)\right)}\right)}} \]
      2. associate-/l/94.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\frac{1}{\color{blue}{e^{\frac{\left|x\right|}{s}} + 3}}}{s} \]
      4. add-sqr-sqrt96.6%

        \[\leadsto \frac{\frac{1}{e^{\color{blue}{\sqrt{\frac{\left|x\right|}{s}} \cdot \sqrt{\frac{\left|x\right|}{s}}}} + 3}}{s} \]
      5. add-sqr-sqrt96.6%

        \[\leadsto \frac{\frac{1}{e^{\color{blue}{\frac{\left|x\right|}{s}}} + 3}}{s} \]
      6. add-sqr-sqrt76.4%

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

        \[\leadsto \frac{\frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}} + 3}}{s} \]
      8. add-sqr-sqrt91.6%

        \[\leadsto \frac{\frac{1}{e^{\frac{\color{blue}{x}}{s}} + 3}}{s} \]
    9. Applied egg-rr91.6%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq -1.9999999996399175 \cdot 10^{-23}:\\ \;\;\;\;\frac{1}{s \cdot \left(4 + \frac{x \cdot x}{s \cdot s}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{1}{e^{\frac{x}{s}} + 3}}{s}\\ \end{array} \]

Alternative 8: 77.1% accurate, 47.7× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
  3. Step-by-step derivation
    1. expm1-log1p-u97.9%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
    3. associate-/l/97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
    11. times-frac73.5%

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

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

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

Alternative 9: 78.0% accurate, 47.7× speedup?

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

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

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

    \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
  3. Step-by-step derivation
    1. expm1-log1p-u97.9%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
    3. associate-/l/97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
    11. times-frac73.5%

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

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

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

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

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

Alternative 10: 64.5% accurate, 55.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0001500000071246177 \lor \neg \left(x \leq 0.0009500000160187483\right):\\
\;\;\;\;\frac{1}{x \cdot \frac{x}{s}}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
    3. Step-by-step derivation
      1. expm1-log1p-u100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)\right)} \]
      2. expm1-udef100.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
      3. associate-/l/100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
      11. times-frac85.7%

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

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

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

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

        \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s}}} \]
    12. Simplified68.3%

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

    if -1.50000007e-4 < x < 9.50000016e-4

    1. Initial program 99.3%

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

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

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

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

Alternative 11: 66.0% accurate, 56.4× speedup?

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

\\
\frac{1}{s \cdot 4 + x \cdot \frac{x}{s}}
\end{array}
Derivation
  1. Initial program 99.6%

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

    \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
  3. Step-by-step derivation
    1. expm1-log1p-u97.9%

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
    3. associate-/l/97.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
    11. times-frac73.5%

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

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

    \[\leadsto \frac{1}{\color{blue}{4 \cdot s + \frac{{x}^{2}}{s}}} \]
  11. Step-by-step derivation
    1. unpow262.4%

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

      \[\leadsto \frac{1}{4 \cdot s + \color{blue}{x \cdot \frac{x}{s}}} \]
    3. +-commutative62.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s} + 4 \cdot s}} \]
    4. fma-def62.7%

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, 4 \cdot s\right)}} \]
    5. *-commutative62.7%

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

    \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(x, \frac{x}{s}, s \cdot 4\right)}} \]
  13. Step-by-step derivation
    1. fma-udef62.7%

      \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s} + s \cdot 4}} \]
  14. Applied egg-rr62.7%

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

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

Alternative 12: 63.3% accurate, 66.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0001500000071246177 \lor \neg \left(x \leq 0.0009500000160187483\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}} \]
    3. Step-by-step derivation
      1. expm1-log1p-u100.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)\right)} \]
      2. expm1-udef100.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}\right)} - 1} \]
      3. associate-/l/100.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{s \cdot \left(4 + \frac{x \cdot x}{\color{blue}{s \cdot s}}\right)} \]
      11. times-frac85.7%

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

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

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

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    12. Simplified67.0%

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

    if -1.50000007e-4 < x < 9.50000016e-4

    1. Initial program 99.3%

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

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

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

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

Alternative 13: 27.5% accurate, 206.7× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  4. Final simplification28.3%

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

Reproduce

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