
(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:
Herbie found 14 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ (- (fabs x)) s))) (t_1 (+ t_0 1.0))) (/ t_0 (* t_1 (* s t_1)))))
float code(float x, float s) {
float t_0 = expf((-fabsf(x) / s));
float t_1 = t_0 + 1.0f;
return t_0 / (t_1 * (s * 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 = t_0 + 1.0e0
code = t_0 / (t_1 * (s * t_1))
end function
function code(x, s) t_0 = exp(Float32(Float32(-abs(x)) / s)) t_1 = Float32(t_0 + Float32(1.0)) return Float32(t_0 / Float32(t_1 * Float32(s * t_1))) end
function tmp = code(x, s) t_0 = exp((-abs(x) / s)); t_1 = t_0 + single(1.0); tmp = t_0 / (t_1 * (s * t_1)); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{-\left|x\right|}{s}}\\
t_1 := t\_0 + 1\\
\frac{t\_0}{t\_1 \cdot \left(s \cdot t\_1\right)}
\end{array}
\end{array}
Initial program 99.3%
Final simplification99.3%
(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}
Initial program 99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
distribute-lft-in99.3%
*-rgt-identity99.3%
+-commutative99.3%
Simplified99.3%
Final simplification99.3%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 2.0000000233721948e-7) (/ (exp (+ (/ x s) (* -2.0 (log1p (exp (/ x s)))))) s) (exp (/ x (- s)))))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 2.0000000233721948e-7f) {
tmp = expf(((x / s) + (-2.0f * log1pf(expf((x / s)))))) / s;
} else {
tmp = expf((x / -s));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(2.0000000233721948e-7)) tmp = Float32(exp(Float32(Float32(x / s) + Float32(Float32(-2.0) * log1p(exp(Float32(x / s)))))) / s); else tmp = exp(Float32(x / Float32(-s))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{e^{\frac{x}{s} + -2 \cdot \mathsf{log1p}\left(e^{\frac{x}{s}}\right)}}{s}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{-s}}\\
\end{array}
\end{array}
if (fabs.f32 x) < 2.00000002e-7Initial program 98.1%
fabs-neg98.1%
distribute-frac-neg98.1%
distribute-frac-neg298.1%
fabs-neg98.1%
*-commutative98.1%
fabs-neg98.1%
+-commutative98.1%
fabs-neg98.1%
Simplified98.1%
associate-/r*98.0%
div-inv98.0%
Applied egg-rr82.6%
associate-*l/82.8%
add-exp-log82.7%
prod-exp98.0%
pow-flip98.1%
log-pow97.9%
metadata-eval97.9%
log1p-define98.1%
Applied egg-rr98.1%
if 2.00000002e-7 < (fabs.f32 x) Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Taylor expanded in s around inf 100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr52.8%
unpow-152.8%
associate-*r*52.8%
*-commutative52.8%
associate-/r*52.8%
*-commutative52.8%
associate-/r*52.8%
metadata-eval52.8%
Simplified52.8%
add-exp-log52.8%
div-exp52.8%
Applied egg-rr52.8%
Taylor expanded in s around 0 52.8%
mul-1-neg52.8%
distribute-frac-neg252.8%
Simplified52.8%
Final simplification70.1%
(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}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
Final simplification95.6%
(FPCore (x s) :precision binary32 (if (<= x 1.9999999920083944e-12) (/ (+ 0.25 (* (* (/ x s) (/ x s)) -0.0625)) s) (exp (/ x (- s)))))
float code(float x, float s) {
float tmp;
if (x <= 1.9999999920083944e-12f) {
tmp = (0.25f + (((x / s) * (x / s)) * -0.0625f)) / 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 <= 1.9999999920083944e-12) then
tmp = (0.25e0 + (((x / s) * (x / s)) * (-0.0625e0))) / s
else
tmp = exp((x / -s))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.9999999920083944e-12)) tmp = Float32(Float32(Float32(0.25) + Float32(Float32(Float32(x / s) * Float32(x / s)) * Float32(-0.0625))) / 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(1.9999999920083944e-12)) tmp = (single(0.25) + (((x / s) * (x / s)) * single(-0.0625))) / s; else tmp = exp((x / -s)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.9999999920083944 \cdot 10^{-12}:\\
\;\;\;\;\frac{0.25 + \left(\frac{x}{s} \cdot \frac{x}{s}\right) \cdot -0.0625}{s}\\
\mathbf{else}:\\
\;\;\;\;e^{\frac{x}{-s}}\\
\end{array}
\end{array}
if x < 1.99999999e-12Initial program 98.9%
fabs-neg98.9%
distribute-frac-neg98.9%
distribute-frac-neg298.9%
fabs-neg98.9%
*-commutative98.9%
fabs-neg98.9%
+-commutative98.9%
fabs-neg98.9%
Simplified98.9%
Taylor expanded in s around inf 32.2%
Simplified32.9%
*-un-lft-identity32.9%
unpow232.9%
times-frac37.0%
fma-undefine37.0%
associate-*r*37.0%
distribute-rgt-out37.6%
pow237.6%
metadata-eval37.6%
metadata-eval37.6%
Applied egg-rr37.6%
Taylor expanded in s around 0 33.6%
*-commutative33.6%
unpow233.6%
unpow233.6%
times-frac38.0%
unpow238.0%
Simplified38.0%
unpow238.0%
Applied egg-rr38.0%
if 1.99999999e-12 < x Initial program 99.9%
fabs-neg99.9%
distribute-frac-neg99.9%
distribute-frac-neg299.9%
fabs-neg99.9%
*-commutative99.9%
fabs-neg99.9%
+-commutative99.9%
fabs-neg99.9%
Simplified99.9%
Taylor expanded in s around inf 99.0%
clear-num99.0%
inv-pow99.0%
Applied egg-rr99.0%
unpow-199.0%
associate-*r*99.0%
*-commutative99.0%
associate-/r*99.0%
*-commutative99.0%
associate-/r*99.0%
metadata-eval99.0%
Simplified99.0%
add-exp-log99.0%
div-exp99.0%
Applied egg-rr99.0%
Taylor expanded in s around 0 97.4%
mul-1-neg97.4%
distribute-frac-neg297.4%
Simplified97.4%
Final simplification58.9%
(FPCore (x s) :precision binary32 (/ (/ 0.25 s) (pow E (/ x s))))
float code(float x, float s) {
return (0.25f / s) / powf(((float) M_E), (x / s));
}
function code(x, s) return Float32(Float32(Float32(0.25) / s) / (Float32(exp(1)) ^ Float32(x / s))) end
function tmp = code(x, s) tmp = (single(0.25) / s) / (single(2.71828182845904523536) ^ (x / s)); end
\begin{array}{l}
\\
\frac{\frac{0.25}{s}}{{e}^{\left(\frac{x}{s}\right)}}
\end{array}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
*-un-lft-identity60.2%
exp-prod60.2%
Applied egg-rr60.2%
exp-1-e60.2%
Simplified60.2%
Final simplification60.2%
(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}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
Final simplification60.2%
(FPCore (x s) :precision binary32 (if (<= x 2.0000000233721948e-7) (/ 0.25 s) (/ (/ 0.25 s) (/ x s))))
float code(float x, float s) {
float tmp;
if (x <= 2.0000000233721948e-7f) {
tmp = 0.25f / s;
} else {
tmp = (0.25f / s) / (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 <= 2.0000000233721948e-7) then
tmp = 0.25e0 / s
else
tmp = (0.25e0 / s) / (x / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(2.0000000233721948e-7)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(0.25) / s) / Float32(x / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(2.0000000233721948e-7)) tmp = single(0.25) / s; else tmp = (single(0.25) / s) / (x / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{0.25}{s}}{\frac{x}{s}}\\
\end{array}
\end{array}
if x < 2.00000002e-7Initial program 99.0%
fabs-neg99.0%
distribute-frac-neg99.0%
distribute-frac-neg299.0%
fabs-neg99.0%
*-commutative99.0%
fabs-neg99.0%
+-commutative99.0%
fabs-neg99.0%
Simplified98.9%
Taylor expanded in s around inf 36.8%
if 2.00000002e-7 < x Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Taylor expanded in s around inf 100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
associate-*r*100.0%
*-commutative100.0%
associate-/r*100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 47.9%
+-commutative47.9%
Simplified47.9%
Taylor expanded in x around inf 47.9%
Final simplification40.3%
(FPCore (x s) :precision binary32 (* (/ 0.25 s) (/ 1.0 (+ 1.0 (/ x s)))))
float code(float x, float s) {
return (0.25f / s) * (1.0f / (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 / (1.0e0 + (x / s)))
end function
function code(x, s) return Float32(Float32(Float32(0.25) / s) * Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))) end
function tmp = code(x, s) tmp = (single(0.25) / s) * (single(1.0) / (single(1.0) + (x / s))); end
\begin{array}{l}
\\
\frac{0.25}{s} \cdot \frac{1}{1 + \frac{x}{s}}
\end{array}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 52.8%
+-commutative52.8%
Simplified52.8%
clear-num52.8%
associate-/r/52.8%
Applied egg-rr52.8%
Final simplification52.8%
(FPCore (x s) :precision binary32 (/ (/ 0.25 s) (+ (+ (/ x s) 2.0) -1.0)))
float code(float x, float s) {
return (0.25f / s) / (((x / s) + 2.0f) + -1.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (0.25e0 / s) / (((x / s) + 2.0e0) + (-1.0e0))
end function
function code(x, s) return Float32(Float32(Float32(0.25) / s) / Float32(Float32(Float32(x / s) + Float32(2.0)) + Float32(-1.0))) end
function tmp = code(x, s) tmp = (single(0.25) / s) / (((x / s) + single(2.0)) + single(-1.0)); end
\begin{array}{l}
\\
\frac{\frac{0.25}{s}}{\left(\frac{x}{s} + 2\right) + -1}
\end{array}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 52.8%
+-commutative52.8%
Simplified52.8%
expm1-log1p-u36.9%
expm1-undefine36.9%
Applied egg-rr36.9%
sub-neg36.9%
log1p-undefine36.9%
rem-exp-log52.9%
+-commutative52.9%
associate-+r+52.8%
metadata-eval52.8%
metadata-eval52.8%
Simplified52.8%
Final simplification52.8%
(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(0.25) / Float32(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{0.25}{s \cdot \left(1 + \frac{x}{s}\right)}
\end{array}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 52.8%
+-commutative52.8%
Simplified52.8%
div-inv52.5%
associate-/l*52.5%
Applied egg-rr52.5%
associate-/r*52.8%
associate-*r/52.8%
metadata-eval52.8%
+-commutative52.8%
Simplified52.8%
Final simplification52.8%
(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}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 95.6%
clear-num95.6%
inv-pow95.6%
Applied egg-rr60.2%
unpow-160.2%
associate-*r*60.2%
*-commutative60.2%
associate-/r*60.2%
*-commutative60.2%
associate-/r*60.2%
metadata-eval60.2%
Simplified60.2%
Taylor expanded in x around 0 52.8%
+-commutative52.8%
Simplified52.8%
Final simplification52.8%
(FPCore (x s) :precision binary32 (if (<= x 2.0000000233721948e-7) (/ 0.25 s) (/ 0.25 x)))
float code(float x, float s) {
float tmp;
if (x <= 2.0000000233721948e-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 <= 2.0000000233721948e-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(2.0000000233721948e-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(2.0000000233721948e-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 2.0000000233721948 \cdot 10^{-7}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{x}\\
\end{array}
\end{array}
if x < 2.00000002e-7Initial program 99.0%
fabs-neg99.0%
distribute-frac-neg99.0%
distribute-frac-neg299.0%
fabs-neg99.0%
*-commutative99.0%
fabs-neg99.0%
+-commutative99.0%
fabs-neg99.0%
Simplified98.9%
Taylor expanded in s around inf 36.8%
if 2.00000002e-7 < x Initial program 100.0%
fabs-neg100.0%
distribute-frac-neg100.0%
distribute-frac-neg2100.0%
fabs-neg100.0%
*-commutative100.0%
fabs-neg100.0%
+-commutative100.0%
fabs-neg100.0%
Simplified100.0%
Taylor expanded in s around inf 100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
associate-*r*100.0%
*-commutative100.0%
associate-/r*100.0%
*-commutative100.0%
associate-/r*100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around 0 47.9%
+-commutative47.9%
Simplified47.9%
Taylor expanded in s around 0 11.2%
Final simplification28.7%
(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}
Initial program 99.3%
fabs-neg99.3%
distribute-frac-neg99.3%
distribute-frac-neg299.3%
fabs-neg99.3%
*-commutative99.3%
fabs-neg99.3%
+-commutative99.3%
fabs-neg99.3%
Simplified99.3%
Taylor expanded in s around inf 26.6%
Final simplification26.6%
herbie shell --seed 2024089
(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))))))