Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 13.6s
Alternatives: 12
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 12 alternatives:

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

Initial Program: 99.5% accurate, 1.0× speedup?

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

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

Alternative 1: 99.5% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
\frac{t\_0}{\left(t\_0 + 1\right) \cdot \left(s + \frac{s}{e^{\frac{\left|x\right|}{s}}}\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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

Alternative 2: 57.5% accurate, 5.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.999999999279835 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25 + -0.0625 \cdot \frac{\frac{x}{s}}{\frac{s}{x}}}{s}\\

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


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

    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. fabs-neg99.8%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.8%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg99.8%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-commutative99.8%

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

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

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

        \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\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. Add Preprocessing
    5. Step-by-step derivation
      1. *-un-lft-identity99.8%

        \[\leadsto \color{blue}{1 \cdot \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)}} \]
      2. associate-/r*99.8%

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

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

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

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

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

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{\color{blue}{\mathsf{log1p}\left(e^{\frac{x}{s}}\right)} \cdot 2} \cdot s} \]
      5. *-commutative98.5%

        \[\leadsto \frac{e^{\frac{x}{s}}}{e^{\color{blue}{2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}} \cdot s} \]
      6. rem-exp-log95.8%

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

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

        \[\leadsto \color{blue}{e^{\frac{x}{s} - \left(2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right) + \log s\right)}} \]
      9. associate--r+96.6%

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

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

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

      \[\leadsto \frac{\color{blue}{0.25 + -0.0625 \cdot \frac{{x}^{2}}{{s}^{2}}}}{s} \]
    10. Step-by-step derivation
      1. unpow230.7%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \frac{\color{blue}{x \cdot x}}{{s}^{2}}}{s} \]
      2. unpow230.7%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \frac{x \cdot x}{\color{blue}{s \cdot s}}}{s} \]
      3. times-frac35.9%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \color{blue}{\left(\frac{x}{s} \cdot \frac{x}{s}\right)}}{s} \]
      4. unpow235.9%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \color{blue}{{\left(\frac{x}{s}\right)}^{2}}}{s} \]
    11. Simplified35.9%

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

        \[\leadsto \frac{0.25 + -0.0625 \cdot \color{blue}{\left(\frac{x}{s} \cdot \frac{x}{s}\right)}}{s} \]
      2. clear-num35.9%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \left(\frac{x}{s} \cdot \color{blue}{\frac{1}{\frac{s}{x}}}\right)}{s} \]
      3. un-div-inv35.9%

        \[\leadsto \frac{0.25 + -0.0625 \cdot \color{blue}{\frac{\frac{x}{s}}{\frac{s}{x}}}}{s} \]
    13. Applied egg-rr35.9%

      \[\leadsto \frac{0.25 + -0.0625 \cdot \color{blue}{\frac{\frac{x}{s}}{\frac{s}{x}}}}{s} \]

    if 4e-23 < 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. *-commutative99.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
    8. Applied egg-rr97.5%

      \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
    9. Step-by-step derivation
      1. unpow-197.5%

        \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
    10. Simplified97.5%

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

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

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

        \[\leadsto e^{\log \color{blue}{\left(\left(4 \cdot s\right) \cdot e^{\frac{x}{s}}\right)} \cdot -1} \]
      4. *-commutative97.3%

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

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

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

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

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

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

Alternative 3: 59.7% accurate, 5.7× speedup?

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

\\
\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

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

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

Alternative 4: 59.7% accurate, 5.7× speedup?

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

\\
\frac{e^{\frac{x}{-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. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

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

      \[\leadsto \frac{e^{\color{blue}{-\frac{\left|x\right|}{s}}}}{s \cdot 4} \]
    2. exp-neg96.8%

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

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

      \[\leadsto \frac{\frac{1}{e^{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s}}}}{s \cdot 4} \]
    5. add-sqr-sqrt62.7%

      \[\leadsto \frac{\frac{1}{e^{\frac{\color{blue}{x}}{s}}}}{s \cdot 4} \]
    6. add-sqr-sqrt52.0%

      \[\leadsto \frac{\frac{1}{e^{\color{blue}{\sqrt{\frac{x}{s}} \cdot \sqrt{\frac{x}{s}}}}}}{s \cdot 4} \]
    7. sqrt-unprod96.8%

      \[\leadsto \frac{\frac{1}{e^{\color{blue}{\sqrt{\frac{x}{s} \cdot \frac{x}{s}}}}}}{s \cdot 4} \]
    8. add-sqr-sqrt52.0%

      \[\leadsto \frac{\frac{1}{e^{\sqrt{\frac{\color{blue}{\sqrt{x} \cdot \sqrt{x}}}{s} \cdot \frac{x}{s}}}}}{s \cdot 4} \]
    9. fabs-sqr52.0%

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

      \[\leadsto \frac{\frac{1}{e^{\sqrt{\frac{\left|\color{blue}{x}\right|}{s} \cdot \frac{x}{s}}}}}{s \cdot 4} \]
    11. add-sqr-sqrt52.0%

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

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

      \[\leadsto \frac{\frac{1}{e^{\sqrt{\frac{\left|x\right|}{s} \cdot \frac{\left|\color{blue}{x}\right|}{s}}}}}{s \cdot 4} \]
    14. sqr-neg96.8%

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

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

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

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

      \[\leadsto \frac{\frac{1}{e^{\color{blue}{\frac{-\left|x\right|}{s}}}}}{s \cdot 4} \]
  9. Applied egg-rr62.7%

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

      \[\leadsto \frac{\color{blue}{e^{-\frac{x}{s}}}}{s \cdot 4} \]
    2. mul-1-neg62.7%

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

      \[\leadsto \frac{e^{\color{blue}{\frac{-1 \cdot x}{s}}}}{s \cdot 4} \]
    4. mul-1-neg62.7%

      \[\leadsto \frac{e^{\frac{\color{blue}{-x}}{s}}}{s \cdot 4} \]
  11. Simplified62.7%

    \[\leadsto \frac{\color{blue}{e^{\frac{-x}{s}}}}{s \cdot 4} \]
  12. Final simplification62.7%

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

Alternative 5: 59.7% accurate, 5.8× speedup?

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

\\
\frac{\frac{0.25}{s}}{e^{\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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

    \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
  11. Taylor expanded in s around 0 62.7%

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

      \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  13. Simplified62.7%

    \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  14. Final simplification62.7%

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

Alternative 6: 63.5% accurate, 41.3× speedup?

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

\\
\frac{1}{4 \cdot \left(s + x \cdot \left(1 + \frac{x}{s} \cdot 0.5\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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

    \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
  11. Taylor expanded in x around 0 65.4%

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

      \[\leadsto \frac{1}{4 \cdot \left(s + x \cdot \left(1 + \color{blue}{\frac{x}{s} \cdot 0.5}\right)\right)} \]
  13. Simplified65.4%

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

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

Alternative 7: 50.2% accurate, 56.4× speedup?

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

\\
\frac{1}{4 \cdot \left(s \cdot \left(1 + \frac{x}{s}\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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

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

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

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

Alternative 8: 50.2% accurate, 68.9× speedup?

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

\\
\frac{\frac{0.25}{s}}{1 + \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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

    \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
  11. Taylor expanded in s around 0 62.7%

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

      \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  13. Simplified62.7%

    \[\leadsto \color{blue}{\frac{\frac{0.25}{s}}{e^{\frac{x}{s}}}} \]
  14. Taylor expanded in x around 0 52.7%

    \[\leadsto \frac{\frac{0.25}{s}}{\color{blue}{1 + \frac{x}{s}}} \]
  15. Final simplification52.7%

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

Alternative 9: 29.2% accurate, 77.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 1.0000000116860974 \cdot 10^{-7}:\\ \;\;\;\;\frac{0.25}{s}\\ \mathbf{else}:\\ \;\;\;\;\frac{0.25}{x}\\ \end{array} \end{array} \]
(FPCore (x s)
 :precision binary32
 (if (<= x 1.0000000116860974e-7) (/ 0.25 s) (/ 0.25 x)))
float code(float x, float s) {
	float tmp;
	if (x <= 1.0000000116860974e-7f) {
		tmp = 0.25f / s;
	} else {
		tmp = 0.25f / 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.0000000116860974e-7) then
        tmp = 0.25e0 / s
    else
        tmp = 0.25e0 / x
    end if
    code = tmp
end function
function code(x, s)
	tmp = Float32(0.0)
	if (x <= Float32(1.0000000116860974e-7))
		tmp = Float32(Float32(0.25) / s);
	else
		tmp = Float32(Float32(0.25) / x);
	end
	return tmp
end
function tmp_2 = code(x, s)
	tmp = single(0.0);
	if (x <= single(1.0000000116860974e-7))
		tmp = single(0.25) / s;
	else
		tmp = single(0.25) / x;
	end
	tmp_2 = tmp;
end
\begin{array}{l}

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

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


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

    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. fabs-neg99.8%

        \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.8%

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

        \[\leadsto \frac{e^{\color{blue}{\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)} \]
      4. fabs-neg99.8%

        \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
      5. *-commutative99.8%

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

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

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

        \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\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. Add Preprocessing
    5. Taylor expanded in s around inf 37.0%

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

    if 1.00000001e-7 < 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. *-commutative99.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
    9. Step-by-step derivation
      1. unpow-199.1%

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

      \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
    11. Taylor expanded in x around 0 12.1%

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

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

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

Alternative 10: 29.7% accurate, 88.6× speedup?

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

\\
\frac{1}{4 \cdot \left(x + 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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

    \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
  11. Taylor expanded in x around 0 29.0%

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

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

Alternative 11: 29.2% accurate, 124.0× speedup?

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

\\
\frac{0.25}{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. Step-by-step derivation
    1. *-commutative99.8%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  7. Simplified96.8%

    \[\leadsto \frac{e^{\frac{-\left|x\right|}{s}}}{\color{blue}{s \cdot 4}} \]
  8. Applied egg-rr62.7%

    \[\leadsto \color{blue}{{\left(4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)\right)}^{-1}} \]
  9. Step-by-step derivation
    1. unpow-162.7%

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

    \[\leadsto \color{blue}{\frac{1}{4 \cdot \left(s \cdot e^{\frac{x}{s}}\right)}} \]
  11. Taylor expanded in x around 0 29.0%

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

      \[\leadsto \color{blue}{{\left(4 \cdot \left(s + x\right)\right)}^{-1}} \]
    2. unpow-prod-down28.5%

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

      \[\leadsto \color{blue}{0.25} \cdot {\left(s + x\right)}^{-1} \]
  13. Applied egg-rr28.5%

    \[\leadsto \color{blue}{0.25 \cdot {\left(s + x\right)}^{-1}} \]
  14. Step-by-step derivation
    1. unpow-128.5%

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

      \[\leadsto \color{blue}{\frac{0.25 \cdot 1}{s + x}} \]
    3. metadata-eval28.5%

      \[\leadsto \frac{\color{blue}{0.25}}{s + x} \]
  15. Simplified28.5%

    \[\leadsto \color{blue}{\frac{0.25}{s + x}} \]
  16. Final simplification28.5%

    \[\leadsto \frac{0.25}{x + s} \]
  17. Add Preprocessing

Alternative 12: 27.6% 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. Step-by-step derivation
    1. fabs-neg99.8%

      \[\leadsto \frac{e^{\frac{-\color{blue}{\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. distribute-frac-neg99.8%

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

      \[\leadsto \frac{e^{\color{blue}{\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)} \]
    4. fabs-neg99.8%

      \[\leadsto \frac{e^{\frac{\color{blue}{\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)} \]
    5. *-commutative99.8%

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

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

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

      \[\leadsto \frac{e^{\frac{\left|x\right|}{-s}}}{\left(1 + e^{\frac{-\left|-x\right|}{s}}\right) \cdot \left(s \cdot \left(e^{\frac{-\color{blue}{\left|-x\right|}}{s}} + 1\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. Add Preprocessing
  5. Taylor expanded in s around inf 26.2%

    \[\leadsto \color{blue}{\frac{0.25}{s}} \]
  6. Final simplification26.2%

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

Reproduce

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