
(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 16 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 (/ 1.0 (* (+ 1.0 (exp (/ (fabs x) (- s)))) (fma s (exp (/ (fabs x) s)) s))))
float code(float x, float s) {
return 1.0f / ((1.0f + expf((fabsf(x) / -s))) * fmaf(s, expf((fabsf(x) / s)), s));
}
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + exp(Float32(abs(x) / Float32(-s)))) * fma(s, exp(Float32(abs(x) / s)), s))) end
\begin{array}{l}
\\
\frac{1}{\left(1 + e^{\frac{\left|x\right|}{-s}}\right) \cdot \mathsf{fma}\left(s, e^{\frac{\left|x\right|}{s}}, s\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.8%
associate-/r/99.8%
/-rgt-identity99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) (+ (exp (/ (fabs x) (- s))) 2.0))))
float code(float x, float s) {
return (1.0f / s) / (expf((fabsf(x) / s)) + (expf((fabsf(x) / -s)) + 2.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (exp((abs(x) / s)) + (exp((abs(x) / -s)) + 2.0e0))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(abs(x) / s)) + Float32(exp(Float32(abs(x) / Float32(-s))) + Float32(2.0)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((abs(x) / s)) + (exp((abs(x) / -s)) + single(2.0))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(e^{\frac{\left|x\right|}{-s}} + 2\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.8%
times-frac98.9%
associate-*r/99.0%
associate-/l*98.9%
distribute-frac-neg98.9%
exp-neg99.0%
Simplified99.1%
Final simplification99.1%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) (+ 2.0 (exp (/ x s))))))
float code(float x, float s) {
return (1.0f / s) / (expf((fabsf(x) / s)) + (2.0f + expf((x / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (exp((abs(x) / s)) + (2.0e0 + exp((x / s))))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(abs(x) / s)) + Float32(Float32(2.0) + exp(Float32(x / s))))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (exp((abs(x) / s)) + (single(2.0) + exp((x / s)))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + \left(2 + e^{\frac{x}{s}}\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.8%
times-frac98.9%
associate-*r/99.0%
associate-/l*98.9%
distribute-frac-neg98.9%
exp-neg99.0%
Simplified99.1%
expm1-log1p-u99.1%
expm1-udef99.1%
log1p-udef99.1%
+-commutative99.1%
add-exp-log99.1%
add-sqr-sqrt53.1%
fabs-sqr53.1%
add-sqr-sqrt97.2%
add-sqr-sqrt-0.0%
sqrt-unprod94.5%
sqr-neg94.5%
sqrt-unprod97.2%
add-sqr-sqrt97.2%
Applied egg-rr97.2%
associate--l+97.2%
metadata-eval97.2%
+-rgt-identity97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -1.000000023742228e-33)
(pow (/ (* s 4.0) t_0) -1.0)
(/ 1.0 (* s (+ t_0 3.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -1.000000023742228e-33f) {
tmp = powf(((s * 4.0f) / t_0), -1.0f);
} else {
tmp = 1.0f / (s * (t_0 + 3.0f));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = exp((x / s))
if (x <= (-1.000000023742228e-33)) then
tmp = ((s * 4.0e0) / t_0) ** (-1.0e0)
else
tmp = 1.0e0 / (s * (t_0 + 3.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-1.000000023742228e-33)) tmp = Float32(Float32(s * Float32(4.0)) / t_0) ^ Float32(-1.0); else tmp = Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-1.000000023742228e-33)) tmp = ((s * single(4.0)) / t_0) ^ single(-1.0); else tmp = single(1.0) / (s * (t_0 + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -1.000000023742228 \cdot 10^{-33}:\\
\;\;\;\;{\left(\frac{s \cdot 4}{t_0}\right)}^{-1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(t_0 + 3\right)}\\
\end{array}
\end{array}
if x < -1.00000002e-33Initial program 99.6%
clear-num99.6%
inv-pow99.6%
Applied egg-rr99.7%
Taylor expanded in x around 0 95.4%
if -1.00000002e-33 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-*l*99.8%
times-frac99.2%
associate-*r/99.2%
associate-/l*99.1%
distribute-frac-neg99.1%
exp-neg99.2%
Simplified99.3%
expm1-log1p-u99.3%
expm1-udef99.2%
log1p-udef99.3%
+-commutative99.3%
add-exp-log99.3%
add-sqr-sqrt92.5%
fabs-sqr92.5%
add-sqr-sqrt99.0%
add-sqr-sqrt-0.0%
sqrt-unprod91.3%
sqr-neg91.3%
sqrt-unprod96.0%
add-sqr-sqrt96.0%
Applied egg-rr96.0%
associate--l+96.0%
metadata-eval96.0%
+-rgt-identity96.0%
Simplified96.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
distribute-lft-in96.7%
div-inv96.7%
exp-prod81.5%
add-sqr-sqrt74.8%
fabs-sqr74.8%
add-sqr-sqrt81.5%
exp-prod96.7%
div-inv96.7%
Applied egg-rr96.7%
distribute-lft-in96.7%
+-commutative96.7%
Simplified96.7%
Final simplification96.1%
(FPCore (x s) :precision binary32 (if (<= x -2.9999998795923744e-13) (/ 1.0 (log1p (expm1 (* x (/ x s))))) (/ 1.0 (* s (+ (exp (/ x s)) 3.0)))))
float code(float x, float s) {
float tmp;
if (x <= -2.9999998795923744e-13f) {
tmp = 1.0f / log1pf(expm1f((x * (x / s))));
} else {
tmp = 1.0f / (s * (expf((x / s)) + 3.0f));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-2.9999998795923744e-13)) tmp = Float32(Float32(1.0) / log1p(expm1(Float32(x * Float32(x / s))))); else tmp = Float32(Float32(1.0) / Float32(s * Float32(exp(Float32(x / s)) + Float32(3.0)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.9999998795923744 \cdot 10^{-13}:\\
\;\;\;\;\frac{1}{\mathsf{log1p}\left(\mathsf{expm1}\left(x \cdot \frac{x}{s}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(e^{\frac{x}{s}} + 3\right)}\\
\end{array}
\end{array}
if x < -2.99999988e-13Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-/l*99.9%
distribute-frac-neg99.9%
exp-neg99.9%
associate-/r/99.9%
/-rgt-identity99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in s around inf 6.1%
associate-+r+6.1%
+-commutative6.1%
associate-+r+6.1%
Simplified6.1%
Taylor expanded in x around inf 59.6%
unpow259.6%
associate-/l*59.6%
Simplified59.6%
associate-/l*59.6%
add-sqr-sqrt59.6%
fabs-sqr59.6%
add-sqr-sqrt59.6%
associate-/l*59.6%
log1p-expm1-u93.9%
associate-/l*93.9%
add-sqr-sqrt93.9%
fabs-sqr93.9%
add-sqr-sqrt93.9%
associate-*r/93.9%
Applied egg-rr93.9%
if -2.99999988e-13 < x Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.7%
times-frac99.1%
associate-*r/99.2%
associate-/l*99.1%
distribute-frac-neg99.1%
exp-neg99.2%
Simplified99.3%
expm1-log1p-u99.3%
expm1-udef99.3%
log1p-udef99.3%
+-commutative99.3%
add-exp-log99.3%
add-sqr-sqrt74.7%
fabs-sqr74.7%
add-sqr-sqrt97.3%
add-sqr-sqrt-0.0%
sqrt-unprod92.8%
sqr-neg92.8%
sqrt-unprod96.7%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
associate--l+96.7%
metadata-eval96.7%
+-rgt-identity96.7%
Simplified96.7%
Taylor expanded in x around 0 96.4%
+-commutative96.4%
Simplified96.4%
distribute-lft-in96.4%
div-inv96.4%
exp-prod77.8%
add-sqr-sqrt60.4%
fabs-sqr60.4%
add-sqr-sqrt77.8%
exp-prod89.5%
div-inv89.5%
Applied egg-rr89.5%
distribute-lft-in89.5%
+-commutative89.5%
Simplified89.5%
Final simplification90.8%
(FPCore (x s) :precision binary32 (/ 1.0 (* s (+ (exp (/ (fabs x) s)) 3.0))))
float code(float x, float s) {
return 1.0f / (s * (expf((fabsf(x) / s)) + 3.0f));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * (exp((abs(x) / s)) + 3.0e0))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(exp(Float32(abs(x) / s)) + Float32(3.0)))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (exp((abs(x) / s)) + single(3.0))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(e^{\frac{\left|x\right|}{s}} + 3\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.8%
times-frac98.9%
associate-*r/99.0%
associate-/l*98.9%
distribute-frac-neg98.9%
exp-neg99.0%
Simplified99.1%
expm1-log1p-u99.1%
expm1-udef99.1%
log1p-udef99.1%
+-commutative99.1%
add-exp-log99.1%
add-sqr-sqrt53.1%
fabs-sqr53.1%
add-sqr-sqrt97.2%
add-sqr-sqrt-0.0%
sqrt-unprod94.5%
sqr-neg94.5%
sqrt-unprod97.2%
add-sqr-sqrt97.2%
Applied egg-rr97.2%
associate--l+97.2%
metadata-eval97.2%
+-rgt-identity97.2%
Simplified97.2%
Taylor expanded in x around 0 97.2%
+-commutative97.2%
Simplified97.2%
Final simplification97.2%
(FPCore (x s) :precision binary32 (if (<= x -5.000000156871975e-23) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s)))) (/ 1.0 (* s (+ (exp (/ x s)) 3.0)))))
float code(float x, float s) {
float tmp;
if (x <= -5.000000156871975e-23f) {
tmp = (1.0f / s) / (4.0f + ((x * x) / (s * s)));
} else {
tmp = 1.0f / (s * (expf((x / s)) + 3.0f));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-5.000000156871975e-23)) then
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
else
tmp = 1.0e0 / (s * (exp((x / s)) + 3.0e0))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.000000156871975e-23)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); else tmp = Float32(Float32(1.0) / Float32(s * Float32(exp(Float32(x / s)) + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.000000156871975e-23)) tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); else tmp = single(1.0) / (s * (exp((x / s)) + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.000000156871975 \cdot 10^{-23}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(e^{\frac{x}{s}} + 3\right)}\\
\end{array}
\end{array}
if x < -5.00000016e-23Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.8%
times-frac98.6%
associate-*r/98.7%
associate-/l*98.6%
distribute-frac-neg98.6%
exp-neg98.8%
Simplified98.9%
Taylor expanded in s around inf 51.4%
associate-+r+51.4%
distribute-lft1-in51.4%
metadata-eval51.4%
mul0-lft80.2%
associate-+r+80.2%
metadata-eval80.2%
unpow280.2%
sqr-abs80.2%
unpow280.2%
Simplified80.2%
if -5.00000016e-23 < x Initial program 99.8%
*-lft-identity99.8%
associate-*r/99.8%
associate-*l*99.8%
times-frac99.1%
associate-*r/99.2%
associate-/l*99.1%
distribute-frac-neg99.1%
exp-neg99.2%
Simplified99.2%
expm1-log1p-u99.2%
expm1-udef99.2%
log1p-udef99.2%
+-commutative99.2%
add-exp-log99.2%
add-sqr-sqrt85.5%
fabs-sqr85.5%
add-sqr-sqrt98.1%
add-sqr-sqrt-0.0%
sqrt-unprod91.8%
sqr-neg91.8%
sqrt-unprod96.2%
add-sqr-sqrt96.2%
Applied egg-rr96.2%
associate--l+96.2%
metadata-eval96.2%
+-rgt-identity96.2%
Simplified96.2%
Taylor expanded in x around 0 96.9%
+-commutative96.9%
Simplified96.9%
distribute-lft-in96.9%
div-inv96.9%
exp-prod79.3%
add-sqr-sqrt69.1%
fabs-sqr69.1%
add-sqr-sqrt79.3%
exp-prod93.3%
div-inv93.3%
Applied egg-rr93.3%
distribute-lft-in93.3%
+-commutative93.3%
Simplified93.3%
Final simplification88.4%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -1.000000023742228e-33)
(/ (/ t_0 s) 4.0)
(/ 1.0 (* s (+ t_0 3.0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -1.000000023742228e-33f) {
tmp = (t_0 / s) / 4.0f;
} else {
tmp = 1.0f / (s * (t_0 + 3.0f));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: tmp
t_0 = exp((x / s))
if (x <= (-1.000000023742228e-33)) then
tmp = (t_0 / s) / 4.0e0
else
tmp = 1.0e0 / (s * (t_0 + 3.0e0))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-1.000000023742228e-33)) tmp = Float32(Float32(t_0 / s) / Float32(4.0)); else tmp = Float32(Float32(1.0) / Float32(s * Float32(t_0 + Float32(3.0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-1.000000023742228e-33)) tmp = (t_0 / s) / single(4.0); else tmp = single(1.0) / (s * (t_0 + single(3.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -1.000000023742228 \cdot 10^{-33}:\\
\;\;\;\;\frac{\frac{t_0}{s}}{4}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(t_0 + 3\right)}\\
\end{array}
\end{array}
if x < -1.00000002e-33Initial program 99.6%
expm1-log1p-u98.7%
expm1-udef98.4%
Applied egg-rr98.4%
expm1-def98.7%
expm1-log1p99.7%
associate-/r*99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around 0 95.3%
if -1.00000002e-33 < x Initial program 99.9%
*-lft-identity99.9%
associate-*r/99.9%
associate-*l*99.8%
times-frac99.2%
associate-*r/99.2%
associate-/l*99.1%
distribute-frac-neg99.1%
exp-neg99.2%
Simplified99.3%
expm1-log1p-u99.3%
expm1-udef99.2%
log1p-udef99.3%
+-commutative99.3%
add-exp-log99.3%
add-sqr-sqrt92.5%
fabs-sqr92.5%
add-sqr-sqrt99.0%
add-sqr-sqrt-0.0%
sqrt-unprod91.3%
sqr-neg91.3%
sqrt-unprod96.0%
add-sqr-sqrt96.0%
Applied egg-rr96.0%
associate--l+96.0%
metadata-eval96.0%
+-rgt-identity96.0%
Simplified96.0%
Taylor expanded in x around 0 96.7%
+-commutative96.7%
Simplified96.7%
distribute-lft-in96.7%
div-inv96.7%
exp-prod81.5%
add-sqr-sqrt74.8%
fabs-sqr74.8%
add-sqr-sqrt81.5%
exp-prod96.7%
div-inv96.7%
Applied egg-rr96.7%
distribute-lft-in96.7%
+-commutative96.7%
Simplified96.7%
Final simplification96.1%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0005000000237487257) (not (<= x 9.999999974752427e-7))) (/ 1.0 (* (/ x s) (* x 2.0))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0005000000237487257f) || !(x <= 9.999999974752427e-7f)) {
tmp = 1.0f / ((x / s) * (x * 2.0f));
} else {
tmp = 0.25f / s;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x <= (-0.0005000000237487257e0)) .or. (.not. (x <= 9.999999974752427e-7))) then
tmp = 1.0e0 / ((x / s) * (x * 2.0e0))
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-0.0005000000237487257)) || !(x <= Float32(9.999999974752427e-7))) tmp = Float32(Float32(1.0) / Float32(Float32(x / s) * Float32(x * Float32(2.0)))); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-0.0005000000237487257)) || ~((x <= single(9.999999974752427e-7)))) tmp = single(1.0) / ((x / s) * (x * single(2.0))); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257 \lor \neg \left(x \leq 9.999999974752427 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{1}{\frac{x}{s} \cdot \left(x \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000024e-4 or 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.8%
associate-+r+4.8%
+-commutative4.8%
associate-+r+4.8%
Simplified4.8%
fma-udef4.8%
Applied egg-rr4.8%
add-sqr-sqrt4.8%
sqrt-unprod27.0%
pow227.0%
Applied egg-rr27.0%
unpow227.0%
rem-sqrt-square4.8%
associate-/l*4.8%
Simplified4.8%
Taylor expanded in x around inf 69.4%
*-commutative69.4%
unpow269.4%
associate-*l/69.4%
associate-*r*69.4%
Simplified69.4%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
Final simplification64.8%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s)))))
float code(float x, float s) {
return (1.0f / s) / (4.0f + ((x * x) / (s * s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-*l*99.8%
times-frac98.9%
associate-*r/99.0%
associate-/l*98.9%
distribute-frac-neg98.9%
exp-neg99.0%
Simplified99.1%
Taylor expanded in s around inf 52.6%
associate-+r+52.6%
distribute-lft1-in52.6%
metadata-eval52.6%
mul0-lft76.9%
associate-+r+76.9%
metadata-eval76.9%
unpow276.9%
sqr-abs76.9%
unpow276.9%
Simplified76.9%
Final simplification76.9%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0005000000237487257) (not (<= x 9.999999974752427e-7))) (* 0.5 (/ s (* x x))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0005000000237487257f) || !(x <= 9.999999974752427e-7f)) {
tmp = 0.5f * (s / (x * x));
} else {
tmp = 0.25f / s;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x <= (-0.0005000000237487257e0)) .or. (.not. (x <= 9.999999974752427e-7))) then
tmp = 0.5e0 * (s / (x * x))
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-0.0005000000237487257)) || !(x <= Float32(9.999999974752427e-7))) tmp = Float32(Float32(0.5) * Float32(s / Float32(x * x))); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-0.0005000000237487257)) || ~((x <= single(9.999999974752427e-7)))) tmp = single(0.5) * (s / (x * x)); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257 \lor \neg \left(x \leq 9.999999974752427 \cdot 10^{-7}\right):\\
\;\;\;\;0.5 \cdot \frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000024e-4 or 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.8%
associate-+r+4.8%
+-commutative4.8%
associate-+r+4.8%
Simplified4.8%
fma-udef4.8%
Applied egg-rr4.8%
add-sqr-sqrt4.8%
sqrt-unprod27.0%
pow227.0%
Applied egg-rr27.0%
unpow227.0%
rem-sqrt-square4.8%
associate-/l*4.8%
Simplified4.8%
Taylor expanded in x around inf 67.5%
unpow267.5%
Simplified67.5%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
Final simplification63.7%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0005000000237487257) (not (<= x 9.999999974752427e-7))) (/ 1.0 (/ x (/ s x))) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0005000000237487257f) || !(x <= 9.999999974752427e-7f)) {
tmp = 1.0f / (x / (s / x));
} else {
tmp = 0.25f / s;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x <= (-0.0005000000237487257e0)) .or. (.not. (x <= 9.999999974752427e-7))) then
tmp = 1.0e0 / (x / (s / x))
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-0.0005000000237487257)) || !(x <= Float32(9.999999974752427e-7))) tmp = Float32(Float32(1.0) / Float32(x / Float32(s / x))); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-0.0005000000237487257)) || ~((x <= single(9.999999974752427e-7)))) tmp = single(1.0) / (x / (s / x)); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257 \lor \neg \left(x \leq 9.999999974752427 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000024e-4 or 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.8%
associate-+r+4.8%
+-commutative4.8%
associate-+r+4.8%
Simplified4.8%
Taylor expanded in x around inf 69.3%
unpow269.3%
associate-/l*69.3%
Simplified69.3%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
Final simplification64.7%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (* 0.5 (/ s (* x x))) (if (<= x 9.999999974752427e-7) (/ 0.25 s) (* (/ s x) (/ 0.5 x)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
tmp = 0.5f * (s / (x * x));
} else if (x <= 9.999999974752427e-7f) {
tmp = 0.25f / s;
} else {
tmp = (s / x) * (0.5f / x);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= (-0.0005000000237487257e0)) then
tmp = 0.5e0 * (s / (x * x))
else if (x <= 9.999999974752427e-7) then
tmp = 0.25e0 / s
else
tmp = (s / x) * (0.5e0 / x)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.0005000000237487257)) tmp = Float32(Float32(0.5) * Float32(s / Float32(x * x))); elseif (x <= Float32(9.999999974752427e-7)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(s / x) * Float32(Float32(0.5) / x)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0005000000237487257)) tmp = single(0.5) * (s / (x * x)); elseif (x <= single(9.999999974752427e-7)) tmp = single(0.25) / s; else tmp = (s / x) * (single(0.5) / x); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;0.5 \cdot \frac{s}{x \cdot x}\\
\mathbf{elif}\;x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{x} \cdot \frac{0.5}{x}\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 5.1%
associate-+r+5.1%
+-commutative5.1%
associate-+r+5.1%
Simplified5.1%
fma-udef5.1%
Applied egg-rr5.1%
add-sqr-sqrt5.1%
sqrt-unprod31.1%
pow231.1%
Applied egg-rr31.1%
unpow231.1%
rem-sqrt-square5.1%
associate-/l*5.1%
Simplified5.1%
Taylor expanded in x around inf 63.3%
unpow263.3%
Simplified63.3%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
if 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.5%
associate-+r+4.5%
+-commutative4.5%
associate-+r+4.5%
Simplified4.5%
fma-udef4.5%
Applied egg-rr4.5%
add-sqr-sqrt4.5%
sqrt-unprod23.4%
pow223.4%
Applied egg-rr23.4%
unpow223.4%
rem-sqrt-square4.5%
associate-/l*4.5%
Simplified4.5%
Taylor expanded in x around inf 71.4%
associate-*r/71.4%
unpow271.4%
times-frac71.4%
Simplified71.4%
Final simplification63.7%
(FPCore (x s) :precision binary32 (if (<= x -0.0005000000237487257) (/ 1.0 (/ x (/ s x))) (if (<= x 9.999999974752427e-7) (/ 0.25 s) (/ 1.0 (/ (* x x) s)))))
float code(float x, float s) {
float tmp;
if (x <= -0.0005000000237487257f) {
tmp = 1.0f / (x / (s / x));
} else if (x <= 9.999999974752427e-7f) {
tmp = 0.25f / s;
} else {
tmp = 1.0f / ((x * 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 <= (-0.0005000000237487257e0)) then
tmp = 1.0e0 / (x / (s / x))
else if (x <= 9.999999974752427e-7) then
tmp = 0.25e0 / s
else
tmp = 1.0e0 / ((x * x) / s)
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-0.0005000000237487257)) tmp = Float32(Float32(1.0) / Float32(x / Float32(s / x))); elseif (x <= Float32(9.999999974752427e-7)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(1.0) / Float32(Float32(x * x) / s)); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-0.0005000000237487257)) tmp = single(1.0) / (x / (s / x)); elseif (x <= single(9.999999974752427e-7)) tmp = single(0.25) / s; else tmp = single(1.0) / ((x * x) / s); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257:\\
\;\;\;\;\frac{1}{\frac{x}{\frac{s}{x}}}\\
\mathbf{elif}\;x \leq 9.999999974752427 \cdot 10^{-7}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\frac{x \cdot x}{s}}\\
\end{array}
\end{array}
if x < -5.00000024e-4Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 5.1%
associate-+r+5.1%
+-commutative5.1%
associate-+r+5.1%
Simplified5.1%
Taylor expanded in x around inf 65.7%
unpow265.7%
associate-/l*65.7%
Simplified65.7%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
if 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.5%
associate-+r+4.5%
+-commutative4.5%
associate-+r+4.5%
Simplified4.5%
fma-udef4.5%
Applied egg-rr4.5%
Taylor expanded in x around inf 72.5%
unpow272.5%
Simplified72.5%
Final simplification64.7%
(FPCore (x s) :precision binary32 (if (or (<= x -0.0005000000237487257) (not (<= x 9.999999974752427e-7))) (/ s (* x x)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -0.0005000000237487257f) || !(x <= 9.999999974752427e-7f)) {
tmp = s / (x * x);
} else {
tmp = 0.25f / s;
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if ((x <= (-0.0005000000237487257e0)) .or. (.not. (x <= 9.999999974752427e-7))) then
tmp = s / (x * x)
else
tmp = 0.25e0 / s
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if ((x <= Float32(-0.0005000000237487257)) || !(x <= Float32(9.999999974752427e-7))) tmp = Float32(s / Float32(x * x)); else tmp = Float32(Float32(0.25) / s); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if ((x <= single(-0.0005000000237487257)) || ~((x <= single(9.999999974752427e-7)))) tmp = s / (x * x); else tmp = single(0.25) / s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.0005000000237487257 \lor \neg \left(x \leq 9.999999974752427 \cdot 10^{-7}\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -5.00000024e-4 or 9.99999997e-7 < x Initial program 100.0%
*-lft-identity100.0%
associate-*r/100.0%
associate-/l*100.0%
distribute-frac-neg100.0%
exp-neg100.0%
associate-/r/100.0%
/-rgt-identity100.0%
associate-*l*100.0%
Simplified100.0%
Taylor expanded in s around inf 4.8%
associate-+r+4.8%
+-commutative4.8%
associate-+r+4.8%
Simplified4.8%
Taylor expanded in x around inf 67.2%
unpow267.2%
Simplified67.2%
if -5.00000024e-4 < x < 9.99999997e-7Initial program 99.4%
Taylor expanded in s around inf 59.3%
Final simplification63.6%
(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.7%
Taylor expanded in s around inf 29.7%
Final simplification29.7%
herbie shell --seed 2023178
(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))))))