
(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 15 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 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) / Float32(-s))) + Float32(exp(Float32(abs(x) / 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%
Simplified99.8%
Final simplification99.8%
(FPCore (x s) :precision binary32 (let* ((t_0 (exp (/ x s)))) (/ 1.0 (* (+ 1.0 (/ 1.0 t_0)) (* s (+ 1.0 t_0))))))
float code(float x, float s) {
float t_0 = expf((x / s));
return 1.0f / ((1.0f + (1.0f / t_0)) * (s * (1.0f + t_0)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
t_0 = exp((x / s))
code = 1.0e0 / ((1.0e0 + (1.0e0 / t_0)) * (s * (1.0e0 + t_0)))
end function
function code(x, s) t_0 = exp(Float32(x / s)) return Float32(Float32(1.0) / Float32(Float32(Float32(1.0) + Float32(Float32(1.0) / t_0)) * Float32(s * Float32(Float32(1.0) + t_0)))) end
function tmp = code(x, s) t_0 = exp((x / s)); tmp = single(1.0) / ((single(1.0) + (single(1.0) / t_0)) * (s * (single(1.0) + t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{\frac{x}{s}}\\
\frac{1}{\left(1 + \frac{1}{t_0}\right) \cdot \left(s \cdot \left(1 + t_0\right)\right)}
\end{array}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.6%
Simplified99.7%
fma-udef99.7%
add-exp-log98.6%
prod-exp98.5%
frac-2neg98.5%
add-sqr-sqrt-0.0%
sqrt-unprod19.8%
sqr-neg19.8%
sqrt-unprod21.7%
add-sqr-sqrt21.7%
prod-exp21.7%
add-exp-log22.3%
*-rgt-identity22.3%
distribute-lft-in22.3%
+-commutative22.3%
*-commutative22.3%
Applied egg-rr62.1%
remove-double-neg27.1%
distribute-frac-neg27.1%
frac-2neg27.1%
exp-neg27.1%
div-inv27.1%
exp-prod26.2%
add-sqr-sqrt26.2%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod19.2%
add-sqr-sqrt82.1%
exp-prod95.3%
div-inv95.3%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt60.9%
add-sqr-sqrt-0.0%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod61.5%
add-sqr-sqrt61.5%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* (* s (+ 1.0 (exp (/ x s)))) (+ 1.0 (exp (- (/ x s)))))))
float code(float x, float s) {
return 1.0f / ((s * (1.0f + expf((x / s)))) * (1.0f + expf(-(x / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((s * (1.0e0 + exp((x / s)))) * (1.0e0 + exp(-(x / s))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s * Float32(Float32(1.0) + exp(Float32(x / s)))) * Float32(Float32(1.0) + exp(Float32(-Float32(x / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / ((s * (single(1.0) + exp((x / s)))) * (single(1.0) + exp(-(x / s)))); end
\begin{array}{l}
\\
\frac{1}{\left(s \cdot \left(1 + e^{\frac{x}{s}}\right)\right) \cdot \left(1 + e^{-\frac{x}{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.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.6%
Simplified99.7%
fma-udef99.7%
add-exp-log98.6%
prod-exp98.5%
frac-2neg98.5%
add-sqr-sqrt-0.0%
sqrt-unprod19.8%
sqr-neg19.8%
sqrt-unprod21.7%
add-sqr-sqrt21.7%
prod-exp21.7%
add-exp-log22.3%
*-rgt-identity22.3%
distribute-lft-in22.3%
+-commutative22.3%
*-commutative22.3%
Applied egg-rr62.1%
remove-double-neg27.1%
distribute-frac-neg27.1%
frac-2neg27.1%
exp-neg27.1%
div-inv27.1%
exp-prod26.2%
add-sqr-sqrt26.2%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod19.2%
add-sqr-sqrt82.1%
exp-prod95.3%
div-inv95.3%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt60.9%
add-sqr-sqrt-0.0%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod61.5%
add-sqr-sqrt61.5%
Applied egg-rr99.7%
rec-exp61.5%
distribute-neg-frac61.5%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (/ 1.0 (* (* s (+ 1.0 (exp (/ x s)))) (+ 1.0 (/ 1.0 (+ 1.0 (/ x s)))))))
float code(float x, float s) {
return 1.0f / ((s * (1.0f + expf((x / s)))) * (1.0f + (1.0f / (1.0f + (x / s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((s * (1.0e0 + exp((x / s)))) * (1.0e0 + (1.0e0 / (1.0e0 + (x / s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(s * Float32(Float32(1.0) + exp(Float32(x / s)))) * Float32(Float32(1.0) + Float32(Float32(1.0) / Float32(Float32(1.0) + Float32(x / s)))))) end
function tmp = code(x, s) tmp = single(1.0) / ((s * (single(1.0) + exp((x / s)))) * (single(1.0) + (single(1.0) / (single(1.0) + (x / s))))); end
\begin{array}{l}
\\
\frac{1}{\left(s \cdot \left(1 + e^{\frac{x}{s}}\right)\right) \cdot \left(1 + \frac{1}{1 + \frac{x}{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.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.6%
Simplified99.7%
fma-udef99.7%
add-exp-log98.6%
prod-exp98.5%
frac-2neg98.5%
add-sqr-sqrt-0.0%
sqrt-unprod19.8%
sqr-neg19.8%
sqrt-unprod21.7%
add-sqr-sqrt21.7%
prod-exp21.7%
add-exp-log22.3%
*-rgt-identity22.3%
distribute-lft-in22.3%
+-commutative22.3%
*-commutative22.3%
Applied egg-rr62.1%
remove-double-neg27.1%
distribute-frac-neg27.1%
frac-2neg27.1%
exp-neg27.1%
div-inv27.1%
exp-prod26.2%
add-sqr-sqrt26.2%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod19.2%
add-sqr-sqrt82.1%
exp-prod95.3%
div-inv95.3%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt60.9%
add-sqr-sqrt-0.0%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod61.5%
add-sqr-sqrt61.5%
Applied egg-rr99.7%
Taylor expanded in x around 0 61.5%
Final simplification61.5%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 2.0 (* 2.0 (exp (/ x s))))))
float code(float x, float s) {
return (1.0f / s) / (2.0f + (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) / (2.0e0 + (2.0e0 * exp((x / s))))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(2.0) + Float32(Float32(2.0) * exp(Float32(x / s))))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (single(2.0) + (single(2.0) * exp((x / s)))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{2 + 2 \cdot e^{\frac{x}{s}}}
\end{array}
Initial program 99.7%
Simplified99.8%
expm1-log1p-u98.0%
expm1-udef97.6%
Applied egg-rr58.8%
expm1-def58.8%
expm1-log1p59.7%
associate-+r+59.7%
count-259.7%
Simplified59.7%
Final simplification59.7%
(FPCore (x s)
:precision binary32
(let* ((t_0 (+ 1.0 (+ (/ x s) (* 0.5 (/ (* x x) (* s s)))))))
(if (<= x 1.5000000786160286e-23)
(/ 0.25 s)
(if (<= x 200000.0)
(/
1.0
(* (- (- 2.0 (/ x s)) (/ (* x (* x -0.5)) (* s s))) (* s (+ 1.0 t_0))))
(/ (/ 1.0 s) (+ 2.0 (* 2.0 t_0)))))))
float code(float x, float s) {
float t_0 = 1.0f + ((x / s) + (0.5f * ((x * x) / (s * s))));
float tmp;
if (x <= 1.5000000786160286e-23f) {
tmp = 0.25f / s;
} else if (x <= 200000.0f) {
tmp = 1.0f / (((2.0f - (x / s)) - ((x * (x * -0.5f)) / (s * s))) * (s * (1.0f + t_0)));
} else {
tmp = (1.0f / s) / (2.0f + (2.0f * t_0));
}
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 = 1.0e0 + ((x / s) + (0.5e0 * ((x * x) / (s * s))))
if (x <= 1.5000000786160286e-23) then
tmp = 0.25e0 / s
else if (x <= 200000.0e0) then
tmp = 1.0e0 / (((2.0e0 - (x / s)) - ((x * (x * (-0.5e0))) / (s * s))) * (s * (1.0e0 + t_0)))
else
tmp = (1.0e0 / s) / (2.0e0 + (2.0e0 * t_0))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(1.0) + Float32(Float32(x / s) + Float32(Float32(0.5) * Float32(Float32(x * x) / Float32(s * s))))) tmp = Float32(0.0) if (x <= Float32(1.5000000786160286e-23)) tmp = Float32(Float32(0.25) / s); elseif (x <= Float32(200000.0)) tmp = Float32(Float32(1.0) / Float32(Float32(Float32(Float32(2.0) - Float32(x / s)) - Float32(Float32(x * Float32(x * Float32(-0.5))) / Float32(s * s))) * Float32(s * Float32(Float32(1.0) + t_0)))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(2.0) + Float32(Float32(2.0) * t_0))); end return tmp end
function tmp_2 = code(x, s) t_0 = single(1.0) + ((x / s) + (single(0.5) * ((x * x) / (s * s)))); tmp = single(0.0); if (x <= single(1.5000000786160286e-23)) tmp = single(0.25) / s; elseif (x <= single(200000.0)) tmp = single(1.0) / (((single(2.0) - (x / s)) - ((x * (x * single(-0.5))) / (s * s))) * (s * (single(1.0) + t_0))); else tmp = (single(1.0) / s) / (single(2.0) + (single(2.0) * t_0)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \left(\frac{x}{s} + 0.5 \cdot \frac{x \cdot x}{s \cdot s}\right)\\
\mathbf{if}\;x \leq 1.5000000786160286 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{elif}\;x \leq 200000:\\
\;\;\;\;\frac{1}{\left(\left(2 - \frac{x}{s}\right) - \frac{x \cdot \left(x \cdot -0.5\right)}{s \cdot s}\right) \cdot \left(s \cdot \left(1 + t_0\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{2 + 2 \cdot t_0}\\
\end{array}
\end{array}
if x < 1.50000008e-23Initial program 99.7%
Taylor expanded in s around inf 34.1%
if 1.50000008e-23 < x < 2e5Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.3%
Simplified99.4%
fma-udef99.4%
add-exp-log98.3%
prod-exp98.1%
frac-2neg98.1%
add-sqr-sqrt-0.0%
sqrt-unprod17.8%
sqr-neg17.8%
sqrt-unprod17.8%
add-sqr-sqrt17.8%
prod-exp17.8%
add-exp-log17.8%
*-rgt-identity17.8%
distribute-lft-in17.8%
+-commutative17.8%
*-commutative17.8%
Applied egg-rr99.3%
remove-double-neg22.7%
distribute-frac-neg22.7%
frac-2neg22.7%
exp-neg22.7%
div-inv22.7%
exp-prod19.7%
add-sqr-sqrt19.7%
sqrt-unprod19.7%
sqr-neg19.7%
sqrt-unprod16.1%
add-sqr-sqrt73.2%
exp-prod89.0%
div-inv89.0%
add-sqr-sqrt89.0%
fabs-sqr89.0%
add-sqr-sqrt89.0%
add-sqr-sqrt-0.0%
sqrt-unprod22.7%
sqr-neg22.7%
sqrt-unprod22.7%
add-sqr-sqrt22.7%
Applied egg-rr99.3%
Taylor expanded in s around inf 91.0%
+-commutative91.0%
mul-1-neg91.0%
unsub-neg91.0%
neg-mul-191.0%
unsub-neg91.0%
distribute-rgt-out91.0%
unpow291.0%
metadata-eval91.0%
associate-*l*91.0%
unpow291.0%
Simplified91.0%
Taylor expanded in x around 0 68.4%
unpow262.5%
unpow262.5%
Simplified68.4%
if 2e5 < x Initial program 100.0%
Simplified100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
associate-+r+100.0%
count-2100.0%
Simplified100.0%
Taylor expanded in x around 0 97.3%
unpow297.3%
unpow297.3%
Simplified97.3%
Final simplification56.0%
(FPCore (x s)
:precision binary32
(let* ((t_0 (- 2.0 (/ x s))) (t_1 (+ x (* s 2.0))))
(if (<= x 1.5000000786160286e-23)
(/ 0.25 s)
(if (<= x 199999995904.0)
(/ 1.0 (* (- t_0 (/ (* x (* x -0.5)) (* s s))) t_1))
(/ 1.0 (* t_0 t_1))))))
float code(float x, float s) {
float t_0 = 2.0f - (x / s);
float t_1 = x + (s * 2.0f);
float tmp;
if (x <= 1.5000000786160286e-23f) {
tmp = 0.25f / s;
} else if (x <= 199999995904.0f) {
tmp = 1.0f / ((t_0 - ((x * (x * -0.5f)) / (s * s))) * t_1);
} else {
tmp = 1.0f / (t_0 * t_1);
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = 2.0e0 - (x / s)
t_1 = x + (s * 2.0e0)
if (x <= 1.5000000786160286e-23) then
tmp = 0.25e0 / s
else if (x <= 199999995904.0e0) then
tmp = 1.0e0 / ((t_0 - ((x * (x * (-0.5e0))) / (s * s))) * t_1)
else
tmp = 1.0e0 / (t_0 * t_1)
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(2.0) - Float32(x / s)) t_1 = Float32(x + Float32(s * Float32(2.0))) tmp = Float32(0.0) if (x <= Float32(1.5000000786160286e-23)) tmp = Float32(Float32(0.25) / s); elseif (x <= Float32(199999995904.0)) tmp = Float32(Float32(1.0) / Float32(Float32(t_0 - Float32(Float32(x * Float32(x * Float32(-0.5))) / Float32(s * s))) * t_1)); else tmp = Float32(Float32(1.0) / Float32(t_0 * t_1)); end return tmp end
function tmp_2 = code(x, s) t_0 = single(2.0) - (x / s); t_1 = x + (s * single(2.0)); tmp = single(0.0); if (x <= single(1.5000000786160286e-23)) tmp = single(0.25) / s; elseif (x <= single(199999995904.0)) tmp = single(1.0) / ((t_0 - ((x * (x * single(-0.5))) / (s * s))) * t_1); else tmp = single(1.0) / (t_0 * t_1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 - \frac{x}{s}\\
t_1 := x + s \cdot 2\\
\mathbf{if}\;x \leq 1.5000000786160286 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{elif}\;x \leq 199999995904:\\
\;\;\;\;\frac{1}{\left(t_0 - \frac{x \cdot \left(x \cdot -0.5\right)}{s \cdot s}\right) \cdot t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0 \cdot t_1}\\
\end{array}
\end{array}
if x < 1.50000008e-23Initial program 99.7%
Taylor expanded in s around inf 34.1%
if 1.50000008e-23 < x < 199999996000Initial program 99.5%
*-lft-identity99.5%
associate-*r/99.5%
associate-/l*99.5%
distribute-frac-neg99.5%
exp-neg99.5%
associate-/r/99.5%
/-rgt-identity99.5%
associate-*l*99.4%
Simplified99.5%
fma-udef99.5%
add-exp-log98.6%
prod-exp98.4%
frac-2neg98.4%
add-sqr-sqrt-0.0%
sqrt-unprod15.6%
sqr-neg15.6%
sqrt-unprod15.6%
add-sqr-sqrt15.6%
prod-exp15.6%
add-exp-log15.6%
*-rgt-identity15.6%
distribute-lft-in15.6%
+-commutative15.6%
*-commutative15.6%
Applied egg-rr99.4%
remove-double-neg20.3%
distribute-frac-neg20.3%
frac-2neg20.3%
exp-neg20.3%
div-inv20.3%
exp-prod17.7%
add-sqr-sqrt17.7%
sqrt-unprod17.7%
sqr-neg17.7%
sqrt-unprod13.5%
add-sqr-sqrt77.5%
exp-prod90.8%
div-inv90.8%
add-sqr-sqrt90.8%
fabs-sqr90.8%
add-sqr-sqrt90.8%
add-sqr-sqrt-0.0%
sqrt-unprod20.3%
sqr-neg20.3%
sqrt-unprod20.3%
add-sqr-sqrt20.3%
Applied egg-rr99.4%
Taylor expanded in s around inf 86.4%
+-commutative86.4%
mul-1-neg86.4%
unsub-neg86.4%
neg-mul-186.4%
unsub-neg86.4%
distribute-rgt-out86.4%
unpow286.4%
metadata-eval86.4%
associate-*l*86.4%
unpow286.4%
Simplified86.4%
Taylor expanded in x around 0 63.6%
if 199999996000 < 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%
fma-udef100.0%
add-exp-log100.0%
prod-exp100.0%
frac-2neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod4.4%
sqr-neg4.4%
sqrt-unprod4.4%
add-sqr-sqrt4.4%
prod-exp4.4%
add-exp-log4.4%
*-rgt-identity4.4%
distribute-lft-in4.4%
+-commutative4.4%
*-commutative4.4%
Applied egg-rr100.0%
Taylor expanded in x around 0 12.3%
remove-double-neg12.3%
distribute-frac-neg12.3%
frac-2neg12.3%
exp-neg12.3%
div-inv12.3%
exp-prod12.3%
add-sqr-sqrt12.3%
sqrt-unprod12.3%
sqr-neg12.3%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
exp-prod100.0%
div-inv100.0%
add-sqr-sqrt100.0%
fabs-sqr100.0%
add-sqr-sqrt100.0%
add-sqr-sqrt-0.0%
sqrt-unprod12.3%
sqr-neg12.3%
sqrt-unprod12.3%
add-sqr-sqrt12.3%
Applied egg-rr12.3%
rec-exp12.3%
distribute-neg-frac12.3%
Simplified12.3%
Taylor expanded in x around 0 98.5%
mul-1-neg98.5%
sub-neg98.5%
Simplified98.5%
Final simplification54.5%
(FPCore (x s)
:precision binary32
(let* ((t_0 (- 2.0 (/ x s))))
(if (<= x 1.5000000786160286e-23)
(/ 0.25 s)
(if (<= x 4000000.0)
(/ 1.0 (* (- t_0 (/ (* x (* x -0.5)) (* s s))) (* s 2.0)))
(/ 1.0 (* t_0 (+ x (* s 2.0))))))))
float code(float x, float s) {
float t_0 = 2.0f - (x / s);
float tmp;
if (x <= 1.5000000786160286e-23f) {
tmp = 0.25f / s;
} else if (x <= 4000000.0f) {
tmp = 1.0f / ((t_0 - ((x * (x * -0.5f)) / (s * s))) * (s * 2.0f));
} else {
tmp = 1.0f / (t_0 * (x + (s * 2.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 = 2.0e0 - (x / s)
if (x <= 1.5000000786160286e-23) then
tmp = 0.25e0 / s
else if (x <= 4000000.0e0) then
tmp = 1.0e0 / ((t_0 - ((x * (x * (-0.5e0))) / (s * s))) * (s * 2.0e0))
else
tmp = 1.0e0 / (t_0 * (x + (s * 2.0e0)))
end if
code = tmp
end function
function code(x, s) t_0 = Float32(Float32(2.0) - Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(1.5000000786160286e-23)) tmp = Float32(Float32(0.25) / s); elseif (x <= Float32(4000000.0)) tmp = Float32(Float32(1.0) / Float32(Float32(t_0 - Float32(Float32(x * Float32(x * Float32(-0.5))) / Float32(s * s))) * Float32(s * Float32(2.0)))); else tmp = Float32(Float32(1.0) / Float32(t_0 * Float32(x + Float32(s * Float32(2.0))))); end return tmp end
function tmp_2 = code(x, s) t_0 = single(2.0) - (x / s); tmp = single(0.0); if (x <= single(1.5000000786160286e-23)) tmp = single(0.25) / s; elseif (x <= single(4000000.0)) tmp = single(1.0) / ((t_0 - ((x * (x * single(-0.5))) / (s * s))) * (s * single(2.0))); else tmp = single(1.0) / (t_0 * (x + (s * single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 - \frac{x}{s}\\
\mathbf{if}\;x \leq 1.5000000786160286 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{elif}\;x \leq 4000000:\\
\;\;\;\;\frac{1}{\left(t_0 - \frac{x \cdot \left(x \cdot -0.5\right)}{s \cdot s}\right) \cdot \left(s \cdot 2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_0 \cdot \left(x + s \cdot 2\right)}\\
\end{array}
\end{array}
if x < 1.50000008e-23Initial program 99.7%
Taylor expanded in s around inf 34.1%
if 1.50000008e-23 < x < 4e6Initial program 99.4%
*-lft-identity99.4%
associate-*r/99.4%
associate-/l*99.4%
distribute-frac-neg99.4%
exp-neg99.4%
associate-/r/99.4%
/-rgt-identity99.4%
associate-*l*99.4%
Simplified99.4%
fma-udef99.4%
add-exp-log98.4%
prod-exp98.1%
frac-2neg98.1%
add-sqr-sqrt-0.0%
sqrt-unprod17.2%
sqr-neg17.2%
sqrt-unprod17.2%
add-sqr-sqrt17.2%
prod-exp17.2%
add-exp-log17.2%
*-rgt-identity17.2%
distribute-lft-in17.2%
+-commutative17.2%
*-commutative17.2%
Applied egg-rr99.4%
remove-double-neg22.0%
distribute-frac-neg22.0%
frac-2neg22.0%
exp-neg22.0%
div-inv22.0%
exp-prod19.1%
add-sqr-sqrt19.1%
sqrt-unprod19.1%
sqr-neg19.1%
sqrt-unprod15.3%
add-sqr-sqrt74.4%
exp-prod89.5%
div-inv89.5%
add-sqr-sqrt89.5%
fabs-sqr89.5%
add-sqr-sqrt89.5%
add-sqr-sqrt-0.0%
sqrt-unprod22.0%
sqr-neg22.0%
sqrt-unprod22.0%
add-sqr-sqrt22.0%
Applied egg-rr99.4%
Taylor expanded in s around inf 89.1%
+-commutative89.1%
mul-1-neg89.1%
unsub-neg89.1%
neg-mul-189.1%
unsub-neg89.1%
distribute-rgt-out89.1%
unpow289.1%
metadata-eval89.1%
associate-*l*89.1%
unpow289.1%
Simplified89.1%
Taylor expanded in x around 0 59.6%
*-commutative59.6%
Simplified59.6%
if 4e6 < 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%
fma-udef100.0%
add-exp-log100.0%
prod-exp100.0%
frac-2neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod4.4%
sqr-neg4.4%
sqrt-unprod4.4%
add-sqr-sqrt4.4%
prod-exp4.4%
add-exp-log4.4%
*-rgt-identity4.4%
distribute-lft-in4.4%
+-commutative4.4%
*-commutative4.4%
Applied egg-rr100.0%
Taylor expanded in x around 0 11.9%
remove-double-neg11.9%
distribute-frac-neg11.9%
frac-2neg11.9%
exp-neg11.9%
div-inv11.9%
exp-prod11.9%
add-sqr-sqrt11.9%
sqrt-unprod11.9%
sqr-neg11.9%
sqrt-unprod-0.0%
add-sqr-sqrt100.0%
exp-prod100.0%
div-inv100.0%
add-sqr-sqrt100.0%
fabs-sqr100.0%
add-sqr-sqrt100.0%
add-sqr-sqrt-0.0%
sqrt-unprod11.9%
sqr-neg11.9%
sqrt-unprod11.9%
add-sqr-sqrt11.9%
Applied egg-rr11.9%
rec-exp11.9%
distribute-neg-frac11.9%
Simplified11.9%
Taylor expanded in x around 0 96.0%
mul-1-neg96.0%
sub-neg96.0%
Simplified96.0%
Final simplification54.0%
(FPCore (x s)
:precision binary32
(if (<= x 1.5000000786160286e-23)
(/ 0.25 s)
(/
(/ 1.0 s)
(+ 2.0 (* 2.0 (+ 1.0 (+ (/ x s) (* 0.5 (/ (* x x) (* s s))))))))))
float code(float x, float s) {
float tmp;
if (x <= 1.5000000786160286e-23f) {
tmp = 0.25f / s;
} else {
tmp = (1.0f / s) / (2.0f + (2.0f * (1.0f + ((x / s) + (0.5f * ((x * x) / (s * s)))))));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 1.5000000786160286e-23) then
tmp = 0.25e0 / s
else
tmp = (1.0e0 / s) / (2.0e0 + (2.0e0 * (1.0e0 + ((x / s) + (0.5e0 * ((x * x) / (s * s)))))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(1.5000000786160286e-23)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(2.0) + Float32(Float32(2.0) * Float32(Float32(1.0) + Float32(Float32(x / s) + Float32(Float32(0.5) * Float32(Float32(x * x) / Float32(s * s)))))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(1.5000000786160286e-23)) tmp = single(0.25) / s; else tmp = (single(1.0) / s) / (single(2.0) + (single(2.0) * (single(1.0) + ((x / s) + (single(0.5) * ((x * x) / (s * s))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.5000000786160286 \cdot 10^{-23}:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{2 + 2 \cdot \left(1 + \left(\frac{x}{s} + 0.5 \cdot \frac{x \cdot x}{s \cdot s}\right)\right)}\\
\end{array}
\end{array}
if x < 1.50000008e-23Initial program 99.7%
Taylor expanded in s around inf 34.1%
if 1.50000008e-23 < x Initial program 99.8%
Simplified99.8%
expm1-log1p-u99.4%
expm1-udef99.3%
Applied egg-rr96.0%
expm1-def96.0%
expm1-log1p96.0%
associate-+r+96.0%
count-296.0%
Simplified96.0%
Taylor expanded in x around 0 83.8%
unpow283.8%
unpow283.8%
Simplified83.8%
Final simplification55.1%
(FPCore (x s) :precision binary32 (/ 1.0 (* (- 2.0 (/ x s)) (+ x (* s 2.0)))))
float code(float x, float s) {
return 1.0f / ((2.0f - (x / s)) * (x + (s * 2.0f)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / ((2.0e0 - (x / s)) * (x + (s * 2.0e0)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(Float32(2.0) - Float32(x / s)) * Float32(x + Float32(s * Float32(2.0))))) end
function tmp = code(x, s) tmp = single(1.0) / ((single(2.0) - (x / s)) * (x + (s * single(2.0)))); end
\begin{array}{l}
\\
\frac{1}{\left(2 - \frac{x}{s}\right) \cdot \left(x + s \cdot 2\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.6%
Simplified99.7%
fma-udef99.7%
add-exp-log98.6%
prod-exp98.5%
frac-2neg98.5%
add-sqr-sqrt-0.0%
sqrt-unprod19.8%
sqr-neg19.8%
sqrt-unprod21.7%
add-sqr-sqrt21.7%
prod-exp21.7%
add-exp-log22.3%
*-rgt-identity22.3%
distribute-lft-in22.3%
+-commutative22.3%
*-commutative22.3%
Applied egg-rr62.1%
Taylor expanded in x around 0 27.1%
remove-double-neg27.1%
distribute-frac-neg27.1%
frac-2neg27.1%
exp-neg27.1%
div-inv27.1%
exp-prod26.2%
add-sqr-sqrt26.2%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod19.2%
add-sqr-sqrt82.1%
exp-prod95.3%
div-inv95.3%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt60.9%
add-sqr-sqrt-0.0%
sqrt-unprod58.3%
sqr-neg58.3%
sqrt-unprod61.5%
add-sqr-sqrt61.5%
Applied egg-rr61.5%
rec-exp61.5%
distribute-neg-frac61.5%
Simplified61.5%
Taylor expanded in x around 0 63.6%
mul-1-neg63.6%
sub-neg63.6%
Simplified63.6%
Final simplification63.6%
(FPCore (x s) :precision binary32 (if (<= x 0.003000000026077032) (/ 0.25 s) (- (/ 0.5 x) (/ s (* x x)))))
float code(float x, float s) {
float tmp;
if (x <= 0.003000000026077032f) {
tmp = 0.25f / s;
} else {
tmp = (0.5f / x) - (s / (x * x));
}
return tmp;
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
real(4) :: tmp
if (x <= 0.003000000026077032e0) then
tmp = 0.25e0 / s
else
tmp = (0.5e0 / x) - (s / (x * x))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.003000000026077032)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(Float32(0.5) / x) - Float32(s / Float32(x * x))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.003000000026077032)) tmp = single(0.25) / s; else tmp = (single(0.5) / x) - (s / (x * x)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.003000000026077032:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x} - \frac{s}{x \cdot x}\\
\end{array}
\end{array}
if x < 0.00300000003Initial program 99.6%
Taylor expanded in s around inf 33.8%
if 0.00300000003 < 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%
fma-udef100.0%
add-exp-log100.0%
prod-exp100.0%
frac-2neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod4.4%
sqr-neg4.4%
sqrt-unprod4.4%
add-sqr-sqrt4.4%
prod-exp4.4%
add-exp-log4.4%
*-rgt-identity4.4%
distribute-lft-in4.4%
+-commutative4.4%
*-commutative4.4%
Applied egg-rr100.0%
Taylor expanded in x around 0 10.7%
Taylor expanded in s around inf 10.9%
Taylor expanded in s around 0 10.9%
+-commutative10.9%
mul-1-neg10.9%
unsub-neg10.9%
associate-*r/10.9%
metadata-eval10.9%
unpow210.9%
Simplified10.9%
Final simplification26.5%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ (* 2.0 (/ x s)) 4.0)))
float code(float x, float s) {
return (1.0f / s) / ((2.0f * (x / s)) + 4.0f);
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / ((2.0e0 * (x / s)) + 4.0e0)
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(Float32(2.0) * Float32(x / s)) + Float32(4.0))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / ((single(2.0) * (x / s)) + single(4.0)); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{2 \cdot \frac{x}{s} + 4}
\end{array}
Initial program 99.7%
Simplified99.8%
expm1-log1p-u98.0%
expm1-udef97.6%
Applied egg-rr58.8%
expm1-def58.8%
expm1-log1p59.7%
associate-+r+59.7%
count-259.7%
Simplified59.7%
Taylor expanded in x around 0 51.3%
Final simplification51.3%
(FPCore (x s) :precision binary32 (/ 1.0 (* 2.0 (+ x (* s 2.0)))))
float code(float x, float s) {
return 1.0f / (2.0f * (x + (s * 2.0f)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (2.0e0 * (x + (s * 2.0e0)))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(Float32(2.0) * Float32(x + Float32(s * Float32(2.0))))) end
function tmp = code(x, s) tmp = single(1.0) / (single(2.0) * (x + (s * single(2.0)))); end
\begin{array}{l}
\\
\frac{1}{2 \cdot \left(x + s \cdot 2\right)}
\end{array}
Initial program 99.7%
*-lft-identity99.7%
associate-*r/99.7%
associate-/l*99.7%
distribute-frac-neg99.7%
exp-neg99.7%
associate-/r/99.7%
/-rgt-identity99.7%
associate-*l*99.6%
Simplified99.7%
fma-udef99.7%
add-exp-log98.6%
prod-exp98.5%
frac-2neg98.5%
add-sqr-sqrt-0.0%
sqrt-unprod19.8%
sqr-neg19.8%
sqrt-unprod21.7%
add-sqr-sqrt21.7%
prod-exp21.7%
add-exp-log22.3%
*-rgt-identity22.3%
distribute-lft-in22.3%
+-commutative22.3%
*-commutative22.3%
Applied egg-rr62.1%
Taylor expanded in x around 0 27.1%
Taylor expanded in s around inf 26.3%
Final simplification26.3%
(FPCore (x s) :precision binary32 (if (<= x 0.003000000026077032) (/ 0.25 s) (/ 0.5 x)))
float code(float x, float s) {
float tmp;
if (x <= 0.003000000026077032f) {
tmp = 0.25f / s;
} else {
tmp = 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.003000000026077032e0) then
tmp = 0.25e0 / s
else
tmp = 0.5e0 / x
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(0.003000000026077032)) tmp = Float32(Float32(0.25) / s); else tmp = Float32(Float32(0.5) / x); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(0.003000000026077032)) tmp = single(0.25) / s; else tmp = single(0.5) / x; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.003000000026077032:\\
\;\;\;\;\frac{0.25}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{x}\\
\end{array}
\end{array}
if x < 0.00300000003Initial program 99.6%
Taylor expanded in s around inf 33.8%
if 0.00300000003 < 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%
fma-udef100.0%
add-exp-log100.0%
prod-exp100.0%
frac-2neg100.0%
add-sqr-sqrt-0.0%
sqrt-unprod4.4%
sqr-neg4.4%
sqrt-unprod4.4%
add-sqr-sqrt4.4%
prod-exp4.4%
add-exp-log4.4%
*-rgt-identity4.4%
distribute-lft-in4.4%
+-commutative4.4%
*-commutative4.4%
Applied egg-rr100.0%
Taylor expanded in x around 0 10.7%
Taylor expanded in s around inf 10.9%
Taylor expanded in s around 0 10.9%
Final simplification26.5%
(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 24.4%
Final simplification24.4%
herbie shell --seed 2023240
(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))))))