Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 11.9s
Alternatives: 11
Speedup: 1.2×

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 11 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.2× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Derivation
  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.7%

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

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

Alternative 2: 62.8% accurate, 1.5× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{-\left|x\right|}{s}}\right) \cdot \mathsf{fma}\left(s, {e}^{\left(\frac{x}{s}\right)}, s\right)}
\end{array}
Derivation
  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.7%

    \[\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. *-un-lft-identity96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, e^{\color{blue}{1 \cdot \frac{\left|x\right|}{s}}}, s\right)} \]
    2. exp-prod96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{\left(e^{1}\right)}^{\left(\frac{\left|x\right|}{s}\right)}}, s\right)} \]
    3. add-sqr-sqrt49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}\right)}, s\right)} \]
    4. fabs-sqr49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}\right)}, s\right)} \]
    5. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{x}}{s}\right)}, s\right)} \]
  5. Applied egg-rr63.6%

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

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\color{blue}{e}}^{\left(\frac{x}{s}\right)}, s\right)} \]
  7. Simplified63.6%

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

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

Alternative 3: 60.7% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \frac{0.5}{s + s \cdot e^{\frac{x \cdot \log e}{s}}} \end{array} \]
(FPCore (x s)
 :precision binary32
 (/ 0.5 (+ s (* s (exp (/ (* x (log E)) s))))))
float code(float x, float s) {
	return 0.5f / (s + (s * expf(((x * logf(((float) M_E))) / s))));
}
function code(x, s)
	return Float32(Float32(0.5) / Float32(s + Float32(s * exp(Float32(Float32(x * log(Float32(exp(1)))) / s)))))
end
function tmp = code(x, s)
	tmp = single(0.5) / (s + (s * exp(((x * log(single(2.71828182845904523536))) / s))));
end
\begin{array}{l}

\\
\frac{0.5}{s + s \cdot e^{\frac{x \cdot \log e}{s}}}
\end{array}
Derivation
  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.7%

    \[\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 96.9%

    \[\leadsto \frac{1}{\color{blue}{2} \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \]
  5. Step-by-step derivation
    1. *-un-lft-identity96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, e^{\color{blue}{1 \cdot \frac{\left|x\right|}{s}}}, s\right)} \]
    2. exp-prod96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{\left(e^{1}\right)}^{\left(\frac{\left|x\right|}{s}\right)}}, s\right)} \]
    3. add-sqr-sqrt49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}\right)}, s\right)} \]
    4. fabs-sqr49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}\right)}, s\right)} \]
    5. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{x}}{s}\right)}, s\right)} \]
  6. Applied egg-rr62.3%

    \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}, s\right)} \]
  7. Step-by-step derivation
    1. exp-1-e62.3%

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

    \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{e}^{\left(\frac{x}{s}\right)}}, s\right)} \]
  9. Taylor expanded in x around inf 62.3%

    \[\leadsto \color{blue}{\frac{0.5}{s + s \cdot e^{\frac{x \cdot \log e}{s}}}} \]
  10. Final simplification62.3%

    \[\leadsto \frac{0.5}{s + s \cdot e^{\frac{x \cdot \log e}{s}}} \]
  11. Add Preprocessing

Alternative 4: 60.7% accurate, 3.0× speedup?

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

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

    \[\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 96.9%

    \[\leadsto \frac{1}{\color{blue}{2} \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \]
  5. Step-by-step derivation
    1. *-un-lft-identity96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, e^{\color{blue}{1 \cdot \frac{\left|x\right|}{s}}}, s\right)} \]
    2. exp-prod96.9%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{\left(e^{1}\right)}^{\left(\frac{\left|x\right|}{s}\right)}}, s\right)} \]
    3. add-sqr-sqrt49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|}{s}\right)}, s\right)} \]
    4. fabs-sqr49.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}\right)}, s\right)} \]
    5. add-sqr-sqrt62.3%

      \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, {\left(e^{1}\right)}^{\left(\frac{\color{blue}{x}}{s}\right)}, s\right)} \]
  6. Applied egg-rr62.3%

    \[\leadsto \frac{1}{2 \cdot \mathsf{fma}\left(s, \color{blue}{{\left(e^{1}\right)}^{\left(\frac{x}{s}\right)}}, s\right)} \]
  7. Step-by-step derivation
    1. exp-1-e62.3%

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

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

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

Alternative 5: 60.7% accurate, 5.5× speedup?

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

\\
\frac{1}{2 \cdot \left(s + s \cdot {e}^{\left(\frac{x}{s}\right)}\right)}
\end{array}
Derivation
  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.7%

    \[\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 96.9%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 60.7% accurate, 5.7× speedup?

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

\\
\frac{0.5}{s + s \cdot e^{\frac{x}{s}}}
\end{array}
Derivation
  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.7%

    \[\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 96.9%

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{0.5}{s + s \cdot e^{\frac{x}{s}}}} \]
  8. Final simplification62.3%

    \[\leadsto \frac{0.5}{s + s \cdot e^{\frac{x}{s}}} \]
  9. Add Preprocessing

Alternative 7: 45.8% accurate, 51.5× speedup?

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

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

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


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

    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{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 36.2%

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

    if 1.99999999e-6 < x

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 66.3% 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.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.7%

    \[\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 40.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{x \cdot x}{s}} \cdot \sqrt{\frac{x \cdot x}{s}}} + \left(s \cdot 4 + 0\right)} \]
    3. fma-def65.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{x \cdot \left(\frac{1}{\sqrt{s}} \cdot \frac{x}{\sqrt{s}}\right)} + s \cdot 4} \]
    4. times-frac65.9%

      \[\leadsto \frac{1}{x \cdot \color{blue}{\frac{1 \cdot x}{\sqrt{s} \cdot \sqrt{s}}} + s \cdot 4} \]
    5. *-un-lft-identity65.9%

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

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

    \[\leadsto \frac{1}{\color{blue}{x \cdot \frac{x}{s}} + s \cdot 4} \]
  13. Final simplification65.9%

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

Alternative 9: 66.3% accurate, 56.4× speedup?

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

\\
\frac{1}{\frac{x}{\frac{s}{x}} + s \cdot 4}
\end{array}
Derivation
  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.7%

    \[\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 40.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{x \cdot x}{s}} \cdot \sqrt{\frac{x \cdot x}{s}}} + \left(s \cdot 4 + 0\right)} \]
    3. fma-def65.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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/65.9%

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

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

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

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

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

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

Alternative 10: 45.8% accurate, 61.8× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{s}{x \cdot x}\\


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

    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{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 36.2%

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

    if 1.99999999e-6 < x

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 28.3% 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.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.7%

    \[\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 25.5%

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

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

Reproduce

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