Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 11.1s
Alternatives: 16
Speedup: 1.0×

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 16 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.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{\left|x\right|}{-s}}\\
\frac{t_0}{s + \frac{s \cdot \left(t_0 + 2\right)}{e^{\frac{\left|x\right|}{s}}}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

Alternative 2: 99.4% accurate, 1.0× speedup?

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

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

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

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

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

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

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

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

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

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

Alternative 3: 99.4% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 99.5% accurate, 1.5× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 97.3% accurate, 1.5× speedup?

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

\\
\frac{e^{\mathsf{fma}\left(-2, \log 2, 0\right)} \cdot e^{\frac{x}{\frac{s}{x}} \cdot \frac{-0.25}{s}}}{s}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

    \[\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. Step-by-step derivation
    1. add-exp-log98.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\mathsf{fma}\left(-2, \log 2, 0\right)} \cdot e^{\color{blue}{\frac{x}{\frac{s}{x}}} \cdot \frac{-0.25}{s}}}{s} \]
  12. Applied egg-rr97.4%

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

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

Alternative 6: 97.3% accurate, 2.0× speedup?

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

\\
\frac{e^{\mathsf{fma}\left(\frac{x}{s} \cdot \frac{x}{s}, -0.25, -2 \cdot \log 2\right)}}{s}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

    \[\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. Step-by-step derivation
    1. add-exp-log98.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{e^{\frac{x}{\frac{s}{x}} \cdot \frac{-0.25}{s}} \cdot e^{\mathsf{fma}\left(-2, \log 2, 0\right)}}}{s} \]
    15. exp-sum97.4%

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

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

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

Alternative 7: 88.0% accurate, 2.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4.999999943633011 \cdot 10^{-27}:\\
\;\;\;\;\frac{1}{s \cdot 4 + x \cdot \frac{1}{\frac{s}{x}}}\\

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


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

    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{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in x around 0 99.7%

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

      \[\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. +-commutative88.8%

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

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

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

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

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

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

        \[\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+88.8%

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

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

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

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

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

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

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

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

    if 4.99999994e-27 < (fabs.f32 x)

    1. Initial program 99.8%

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

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

      \[\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. Step-by-step derivation
      1. add-exp-log99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 4.999999943633011 \cdot 10^{-27}:\\ \;\;\;\;\frac{1}{s \cdot 4 + x \cdot \frac{1}{\frac{s}{x}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{e^{\frac{-\left|x\right|}{s}}}{s}\\ \end{array} \]

Alternative 8: 95.1% accurate, 2.0× speedup?

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

\\
\frac{0.5}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

    \[\leadsto \frac{\color{blue}{0.5}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)} \]
  4. Final simplification95.8%

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

Alternative 9: 80.4% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{s}{x \cdot x}\\ \mathbf{if}\;\left|x\right| \leq 0.004999999888241291:\\ \;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \frac{x}{s} + 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ s (* x x))))
   (if (<= (fabs x) 0.004999999888241291)
     (/ 1.0 (* s (+ (* (/ x s) (/ x s)) 4.0)))
     (cbrt (* t_0 (* t_0 t_0))))))
float code(float x, float s) {
	float t_0 = s / (x * x);
	float tmp;
	if (fabsf(x) <= 0.004999999888241291f) {
		tmp = 1.0f / (s * (((x / s) * (x / s)) + 4.0f));
	} else {
		tmp = cbrtf((t_0 * (t_0 * t_0)));
	}
	return tmp;
}
function code(x, s)
	t_0 = Float32(s / Float32(x * x))
	tmp = Float32(0.0)
	if (abs(x) <= Float32(0.004999999888241291))
		tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(Float32(x / s) * Float32(x / s)) + Float32(4.0))));
	else
		tmp = cbrt(Float32(t_0 * Float32(t_0 * t_0)));
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{s}{x \cdot x}\\
\mathbf{if}\;\left|x\right| \leq 0.004999999888241291:\\
\;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \frac{x}{s} + 4\right)}\\

\mathbf{else}:\\
\;\;\;\;\sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}\\


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

    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{\frac{1}{1 + e^{\frac{\left|x\right|}{-s}}}}{\mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}} \]
    3. Taylor expanded in s around 0 99.4%

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

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

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

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

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

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

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

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

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

    if 0.00499999989 < (fabs.f32 x)

    1. Initial program 100.0%

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

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

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

      \[\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. +-commutative26.8%

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

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

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

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

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

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

        \[\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+71.3%

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

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

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

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

      \[\leadsto \color{blue}{\frac{s}{x \cdot x}} \]
    10. Step-by-step derivation
      1. add-cbrt-cube96.2%

        \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{s}{x \cdot x} \cdot \frac{s}{x \cdot x}\right) \cdot \frac{s}{x \cdot x}}} \]
    11. Applied egg-rr96.2%

      \[\leadsto \color{blue}{\sqrt[3]{\left(\frac{s}{x \cdot x} \cdot \frac{s}{x \cdot x}\right) \cdot \frac{s}{x \cdot x}}} \]
    12. Step-by-step derivation
      1. associate-*l*96.2%

        \[\leadsto \sqrt[3]{\color{blue}{\frac{s}{x \cdot x} \cdot \left(\frac{s}{x \cdot x} \cdot \frac{s}{x \cdot x}\right)}} \]
    13. Simplified96.2%

      \[\leadsto \color{blue}{\sqrt[3]{\frac{s}{x \cdot x} \cdot \left(\frac{s}{x \cdot x} \cdot \frac{s}{x \cdot x}\right)}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification81.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\left|x\right| \leq 0.004999999888241291:\\ \;\;\;\;\frac{1}{s \cdot \left(\frac{x}{s} \cdot \frac{x}{s} + 4\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt[3]{\frac{s}{x \cdot x} \cdot \left(\frac{s}{x \cdot x} \cdot \frac{s}{x \cdot x}\right)}\\ \end{array} \]

Alternative 10: 94.8% accurate, 3.0× speedup?

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

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

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

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

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

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

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

Alternative 11: 79.3% accurate, 5.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{x}{\frac{s}{x}}\\ \frac{1}{s \cdot 4 + \sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}} \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (let* ((t_0 (/ x (/ s x)))) (/ 1.0 (+ (* s 4.0) (cbrt (* t_0 (* t_0 t_0)))))))
float code(float x, float s) {
	float t_0 = x / (s / x);
	return 1.0f / ((s * 4.0f) + cbrtf((t_0 * (t_0 * t_0))));
}
function code(x, s)
	t_0 = Float32(x / Float32(s / x))
	return Float32(Float32(1.0) / Float32(Float32(s * Float32(4.0)) + cbrt(Float32(t_0 * Float32(t_0 * t_0)))))
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{x}{\frac{s}{x}}\\
\frac{1}{s \cdot 4 + \sqrt[3]{t_0 \cdot \left(t_0 \cdot t_0\right)}}
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

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

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

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

    \[\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. +-commutative39.2%

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

      \[\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-in64.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-eval64.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/64.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-neg64.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-neg64.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+64.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.0%

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

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

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

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

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

    \[\leadsto \frac{1}{\left(s \cdot 4 + 0\right) + \color{blue}{\sqrt[3]{\left(\frac{x}{\frac{s}{x}} \cdot \frac{x}{\frac{s}{x}}\right) \cdot \frac{x}{\frac{s}{x}}}}} \]
  9. Final simplification81.8%

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

Alternative 12: 76.4% accurate, 47.7× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\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. +-commutative39.2%

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

      \[\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-in64.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-eval64.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/64.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-neg64.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-neg64.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+64.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.0%

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\left(s \cdot 4 + 0\right) + \frac{x \cdot x}{s}}\right)\right)} \]
    2. expm1-udef82.7%

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

      \[\leadsto e^{\mathsf{log1p}\left(\frac{1}{\color{blue}{\frac{x \cdot x}{s} + \left(s \cdot 4 + 0\right)}}\right)} - 1 \]
    4. associate-/l*83.0%

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

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

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\frac{x}{\frac{s}{x}} + s \cdot 4}\right)\right)} \]
    2. expm1-log1p65.3%

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

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

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

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

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

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

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

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

    \[\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. +-commutative39.2%

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

      \[\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-in64.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-eval64.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/64.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-neg64.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-neg64.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+64.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.0%

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

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

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

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

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

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

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

Alternative 15: 45.7% accurate, 87.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.00011999999696854502:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{x \cdot x}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 0.00011999999696854502) (/ 0.25 s) (/ s (* x x))))
float code(float x, float s) {
	float tmp;
	if (x <= 0.00011999999696854502f) {
		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 <= 0.00011999999696854502e0) 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(0.00011999999696854502))
		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(0.00011999999696854502))
		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 0.00011999999696854502:\\
\;\;\;\;\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.19999997e-4

    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{e^{\frac{\left|x\right|}{-s}}}{s + \frac{s \cdot \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}{e^{\frac{\left|x\right|}{s}}}}} \]
    3. Taylor expanded in s around inf 36.5%

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

    if 1.19999997e-4 < x

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

        \[\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+66.7%

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

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

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

        \[\leadsto \frac{s}{\color{blue}{x \cdot x}} \]
    9. Simplified67.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.00011999999696854502:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{s}{x \cdot x}\\ \end{array} \]

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

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

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

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

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

Reproduce

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