Logistic distribution

Percentage Accurate: 99.5% → 99.5%
Time: 16.1s
Alternatives: 12
Speedup: N/A×

Specification

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

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

Sampling outcomes in binary32 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 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, 2.0× speedup?

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

\\
\frac{\frac{1}{1 + e^{\frac{\left|x_m\right|}{s}}}}{s + s \cdot e^{\frac{-x_m}{s}}}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 99.5% accurate, 2.0× speedup?

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

\\
\frac{1}{\left(1 + e^{\frac{\left|x_m\right|}{s}}\right) \cdot \left(s + s \cdot e^{\frac{-x_m}{s}}\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 96.1% accurate, 2.9× speedup?

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

\\
\frac{\frac{1}{1 + e^{\frac{\left|x_m\right|}{s}}}}{s + \left(s - x_m\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 95.2% accurate, 3.0× speedup?

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

\\
\frac{0.5}{s \cdot \left(1 + e^{\frac{\left|x_m\right|}{s}}\right)}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 95.1% accurate, 5.7× speedup?

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

\\
\frac{\frac{0.5}{s}}{1 + e^{\frac{x_m}{s}}}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 78.6% accurate, 47.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;s \leq 7.99999974612418 \cdot 10^{-21}:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{s}}{s}}\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 65.4% accurate, 55.1× speedup?

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

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

\mathbf{elif}\;x_m \leq 5000000136282112:\\
\;\;\;\;\frac{1}{\frac{\frac{1}{s}}{s}}\\

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 69.4% accurate, 61.2× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x_m}{s \cdot \left(-s\right)}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 53.6% accurate, 87.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 51.0% accurate, 121.0× speedup?

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

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

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


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 27.1% accurate, 206.7× speedup?

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

\\
\frac{0.25}{s}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 8.3% accurate, 620.0× speedup?

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

\\
1
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

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