Logistic distribution

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\left|x\right| \cdot \frac{1}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    4. exp-prod62.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    13. sqrt-unprod63.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    14. sqr-neg63.6%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\sqrt{\color{blue}{\left|x\right| \cdot \left|x\right|}}}{s}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    15. sqrt-unprod65.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    16. add-sqr-sqrt65.3%

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

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

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

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

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

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

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

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

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

Alternative 2: 99.5% accurate, 2.9× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\left|x\right| \cdot \frac{1}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    4. exp-prod62.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    13. sqrt-unprod63.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    14. sqr-neg63.6%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\sqrt{\color{blue}{\left|x\right| \cdot \left|x\right|}}}{s}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    15. sqrt-unprod65.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    16. add-sqr-sqrt65.3%

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

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

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

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

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

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

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

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

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

Alternative 3: 95.0% accurate, 5.6× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 94.7% accurate, 5.7× speedup?

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

\\
\frac{e^{\frac{-x_m}{s}}}{s \cdot 4}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\left|x\right| \cdot \frac{1}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    4. exp-prod62.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    13. sqrt-unprod63.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    14. sqr-neg63.6%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\sqrt{\color{blue}{\left|x\right| \cdot \left|x\right|}}}{s}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    15. sqrt-unprod65.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    16. add-sqr-sqrt65.3%

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

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  8. Step-by-step derivation
    1. rec-exp99.5%

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

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

    \[\leadsto \frac{\color{blue}{e^{\frac{-x}{s}}}}{s \cdot 4} \]
  10. Final simplification61.5%

    \[\leadsto \frac{e^{\frac{-x}{s}}}{s \cdot 4} \]
  11. Add Preprocessing

Alternative 5: 94.7% accurate, 5.8× speedup?

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

\\
\frac{\frac{0.25}{e^{\frac{x_m}{s}}}}{s}
\end{array}
Derivation
  1. Initial program 99.4%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\left|x\right| \cdot \frac{1}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    4. exp-prod62.5%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    13. sqrt-unprod63.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    14. sqr-neg63.6%

      \[\leadsto \frac{1}{\left(1 + \frac{1}{e^{\frac{\sqrt{\color{blue}{\left|x\right| \cdot \left|x\right|}}}{s}}}\right) \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    15. sqrt-unprod65.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(\mathsf{expm1}\left(\mathsf{log1p}\left(s \cdot e^{\frac{x}{s}}\right)\right) + s\right)} \]
    16. add-sqr-sqrt65.3%

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

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

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

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

    \[\leadsto \frac{\color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s \cdot 4} \]
  8. Step-by-step derivation
    1. rec-exp99.5%

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

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

    \[\leadsto \frac{\color{blue}{e^{\frac{-x}{s}}}}{s \cdot 4} \]
  10. Taylor expanded in x around inf 61.5%

    \[\leadsto \color{blue}{0.25 \cdot \frac{e^{-1 \cdot \frac{x}{s}}}{s}} \]
  11. Step-by-step derivation
    1. associate-*r/61.5%

      \[\leadsto \color{blue}{\frac{0.25 \cdot e^{-1 \cdot \frac{x}{s}}}{s}} \]
    2. mul-1-neg61.5%

      \[\leadsto \frac{0.25 \cdot e^{\color{blue}{-\frac{x}{s}}}}{s} \]
    3. rec-exp61.5%

      \[\leadsto \frac{0.25 \cdot \color{blue}{\frac{1}{e^{\frac{x}{s}}}}}{s} \]
    4. associate-*r/61.5%

      \[\leadsto \frac{\color{blue}{\frac{0.25 \cdot 1}{e^{\frac{x}{s}}}}}{s} \]
    5. metadata-eval61.5%

      \[\leadsto \frac{\frac{\color{blue}{0.25}}{e^{\frac{x}{s}}}}{s} \]
  12. Simplified61.5%

    \[\leadsto \color{blue}{\frac{\frac{0.25}{e^{\frac{x}{s}}}}{s}} \]
  13. Final simplification61.5%

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

Alternative 6: 63.0% accurate, 51.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.999999987845058 \cdot 10^{-8}:\\
\;\;\;\;\frac{0.25}{s}\\

\mathbf{else}:\\
\;\;\;\;\frac{s}{x_m} \cdot \frac{1}{x_m}\\


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

    1. Initial program 99.2%

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

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

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

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

    if 1.99999999e-8 < 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{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. Taylor expanded in s around -inf 24.1%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{s}{{x}^{2}}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity58.4%

        \[\leadsto \frac{\color{blue}{1 \cdot s}}{{x}^{2}} \]
      2. unpow258.4%

        \[\leadsto \frac{1 \cdot s}{\color{blue}{x \cdot x}} \]
      3. times-frac58.4%

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

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

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

Alternative 7: 66.1% accurate, 56.4× speedup?

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

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

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

    \[\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. Taylor expanded in s around -inf 37.4%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(\left|x\right| \cdot 0 + s \cdot 4\right)}} \]
  7. Step-by-step derivation
    1. add-sqr-sqrt63.9%

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

      \[\leadsto \frac{1}{\color{blue}{\mathsf{fma}\left(\sqrt{\frac{x \cdot x}{s}}, \sqrt{\frac{x \cdot x}{s}}, \left|x\right| \cdot 0 + s \cdot 4\right)}} \]
    3. sqrt-div63.9%

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{\sqrt{s}}, \sqrt{\frac{x \cdot x}{s}}, \left|x\right| \cdot 0 + s \cdot 4\right)} \]
    5. add-sqr-sqrt63.9%

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

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

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{x}{\sqrt{s}}, \frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{\sqrt{s}}, \left|x\right| \cdot 0 + s \cdot 4\right)} \]
    8. add-sqr-sqrt64.5%

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{x}{\sqrt{s}}, \frac{\color{blue}{x}}{\sqrt{s}}, \left|x\right| \cdot 0 + s \cdot 4\right)} \]
    9. mul0-rgt64.5%

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{x}{\sqrt{s}}, \frac{x}{\sqrt{s}}, \color{blue}{0} + s \cdot 4\right)} \]
    10. +-lft-identity64.5%

      \[\leadsto \frac{1}{\mathsf{fma}\left(\frac{x}{\sqrt{s}}, \frac{x}{\sqrt{s}}, \color{blue}{s \cdot 4}\right)} \]
  8. Applied egg-rr64.5%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\sqrt{s}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4}} \]
    2. unpow264.5%

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{x}{\sqrt{s}} \cdot \frac{x}{\sqrt{s}}} + s \cdot 4} \]
    2. frac-2neg64.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{-x}{-\sqrt{s}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    3. clear-num64.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\frac{-\sqrt{s}}{-x}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    4. frac-2neg64.5%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\frac{\sqrt{s}}{x}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    5. add-sqr-sqrt34.4%

      \[\leadsto \frac{1}{\frac{1}{\frac{\sqrt{s}}{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    6. sqrt-prod63.9%

      \[\leadsto \frac{1}{\frac{1}{\frac{\sqrt{s}}{\color{blue}{\sqrt{x \cdot x}}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    7. unpow263.9%

      \[\leadsto \frac{1}{\frac{1}{\frac{\sqrt{s}}{\sqrt{\color{blue}{{x}^{2}}}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    8. sqrt-div63.9%

      \[\leadsto \frac{1}{\frac{1}{\color{blue}{\sqrt{\frac{s}{{x}^{2}}}}} \cdot \frac{x}{\sqrt{s}} + s \cdot 4} \]
    9. frac-times63.9%

      \[\leadsto \frac{1}{\color{blue}{\frac{1 \cdot x}{\sqrt{\frac{s}{{x}^{2}}} \cdot \sqrt{s}}} + s \cdot 4} \]
    10. *-un-lft-identity63.9%

      \[\leadsto \frac{1}{\frac{\color{blue}{x}}{\sqrt{\frac{s}{{x}^{2}}} \cdot \sqrt{s}} + s \cdot 4} \]
    11. sqrt-div63.9%

      \[\leadsto \frac{1}{\frac{x}{\color{blue}{\frac{\sqrt{s}}{\sqrt{{x}^{2}}}} \cdot \sqrt{s}} + s \cdot 4} \]
    12. unpow263.9%

      \[\leadsto \frac{1}{\frac{x}{\frac{\sqrt{s}}{\sqrt{\color{blue}{x \cdot x}}} \cdot \sqrt{s}} + s \cdot 4} \]
    13. sqrt-prod34.4%

      \[\leadsto \frac{1}{\frac{x}{\frac{\sqrt{s}}{\color{blue}{\sqrt{x} \cdot \sqrt{x}}} \cdot \sqrt{s}} + s \cdot 4} \]
    14. add-sqr-sqrt64.5%

      \[\leadsto \frac{1}{\frac{x}{\frac{\sqrt{s}}{\color{blue}{x}} \cdot \sqrt{s}} + s \cdot 4} \]
  12. Applied egg-rr64.5%

    \[\leadsto \frac{1}{\color{blue}{\frac{x}{\frac{\sqrt{s}}{x} \cdot \sqrt{s}}} + s \cdot 4} \]
  13. Step-by-step derivation
    1. associate-*l/64.5%

      \[\leadsto \frac{1}{\frac{x}{\color{blue}{\frac{\sqrt{s} \cdot \sqrt{s}}{x}}} + s \cdot 4} \]
    2. rem-square-sqrt64.5%

      \[\leadsto \frac{1}{\frac{x}{\frac{\color{blue}{s}}{x}} + s \cdot 4} \]
  14. Simplified64.5%

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

    \[\leadsto \frac{1}{s \cdot 4 + \frac{x}{\frac{s}{x}}} \]
  16. Add Preprocessing

Alternative 8: 27.5% accurate, 206.7× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{e^{\frac{-\left|x\right|}{s}}}{s \cdot \left(\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \left(1 + e^{\frac{-\left|x\right|}{s}}\right)\right)}} \]
  4. Add Preprocessing
  5. 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 2024019 
(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))))))