
(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 (/ 1.0 (* s (+ 2.0 (+ (exp (/ (fabs x) s)) (exp (/ (fabs x) (- s))))))))
float code(float x, float s) {
return 1.0f / (s * (2.0f + (expf((fabsf(x) / s)) + expf((fabsf(x) / -s)))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 1.0e0 / (s * (2.0e0 + (exp((abs(x) / s)) + exp((abs(x) / -s)))))
end function
function code(x, s) return Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(exp(Float32(abs(x) / s)) + exp(Float32(abs(x) / Float32(-s))))))) end
function tmp = code(x, s) tmp = single(1.0) / (s * (single(2.0) + (exp((abs(x) / s)) + exp((abs(x) / -s))))); end
\begin{array}{l}
\\
\frac{1}{s \cdot \left(2 + \left(e^{\frac{\left|x\right|}{s}} + e^{\frac{\left|x\right|}{-s}}\right)\right)}
\end{array}
Initial program 99.6%
Simplified99.7%
expm1-log1p-u97.9%
expm1-udef96.9%
associate-+r+96.9%
Applied egg-rr96.9%
expm1-def97.9%
expm1-log1p99.7%
associate-/l/99.7%
*-commutative99.7%
+-commutative99.7%
Simplified99.7%
Final simplification99.7%
(FPCore (x s) :precision binary32 (if (<= (fabs x) 1.0000000116860974e-7) (/ (exp (+ (/ x s) (* (log1p (exp (/ x s))) -2.0))) s) (exp (log (/ (/ 1.0 s) (+ (exp (/ (fabs x) s)) 3.0))))))
float code(float x, float s) {
float tmp;
if (fabsf(x) <= 1.0000000116860974e-7f) {
tmp = expf(((x / s) + (log1pf(expf((x / s))) * -2.0f))) / s;
} else {
tmp = expf(logf(((1.0f / s) / (expf((fabsf(x) / s)) + 3.0f))));
}
return tmp;
}
function code(x, s) tmp = Float32(0.0) if (abs(x) <= Float32(1.0000000116860974e-7)) tmp = Float32(exp(Float32(Float32(x / s) + Float32(log1p(exp(Float32(x / s))) * Float32(-2.0)))) / s); else tmp = exp(log(Float32(Float32(Float32(1.0) / s) / Float32(exp(Float32(abs(x) / s)) + Float32(3.0))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1.0000000116860974 \cdot 10^{-7}:\\
\;\;\;\;\frac{e^{\frac{x}{s} + \mathsf{log1p}\left(e^{\frac{x}{s}}\right) \cdot -2}}{s}\\
\mathbf{else}:\\
\;\;\;\;e^{\log \left(\frac{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}\right)}\\
\end{array}
\end{array}
if (fabs.f32 x) < 1.00000001e-7Initial program 99.1%
associate-*l*99.1%
+-commutative99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in x around 0 99.1%
associate-/r*99.3%
mul-1-neg99.3%
distribute-frac-neg99.3%
+-commutative99.3%
mul-1-neg99.3%
distribute-frac-neg99.3%
Simplified99.3%
associate-/l/99.1%
*-un-lft-identity99.1%
times-frac99.3%
Applied egg-rr76.3%
Taylor expanded in x around inf 76.4%
+-commutative76.4%
exp-to-pow76.3%
log1p-def76.4%
*-commutative76.4%
rem-exp-log71.7%
exp-sum71.5%
exp-diff94.2%
associate--r+94.2%
exp-diff94.5%
cancel-sign-sub-inv94.5%
metadata-eval94.5%
*-commutative94.5%
rem-exp-log99.2%
Simplified99.2%
if 1.00000001e-7 < (fabs.f32 x) Initial program 99.9%
Simplified99.9%
expm1-log1p-u99.9%
expm1-udef99.1%
associate-+r+99.1%
Applied egg-rr99.1%
expm1-def99.9%
expm1-log1p99.9%
associate-/l/99.9%
*-commutative99.9%
+-commutative99.9%
Simplified99.9%
Taylor expanded in s around 0 99.9%
associate-/r*99.9%
associate-*r/99.9%
mul-1-neg99.9%
Simplified99.9%
Taylor expanded in s around inf 99.9%
add-exp-log99.9%
associate-+r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.6%
(FPCore (x s) :precision binary32 (/ 0.5 (+ s (* s (exp (/ (fabs x) s))))))
float code(float x, float s) {
return 0.5f / (s + (s * expf((fabsf(x) / s))));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = 0.5e0 / (s + (s * exp((abs(x) / s))))
end function
function code(x, s) return Float32(Float32(0.5) / Float32(s + Float32(s * exp(Float32(abs(x) / s))))) end
function tmp = code(x, s) tmp = single(0.5) / (s + (s * exp((abs(x) / s)))); end
\begin{array}{l}
\\
\frac{0.5}{s + s \cdot e^{\frac{\left|x\right|}{s}}}
\end{array}
Initial program 99.6%
*-lft-identity99.6%
associate-*r/99.6%
associate-/l*99.6%
distribute-frac-neg99.6%
exp-neg99.5%
associate-/r/99.5%
/-rgt-identity99.5%
associate-*l*99.5%
Simplified99.7%
Taylor expanded in s around inf 94.9%
Taylor expanded in x around 0 95.0%
Final simplification95.0%
(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(Float32(1.0) / 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{\frac{1}{s}}{e^{\frac{\left|x\right|}{s}} + 3}
\end{array}
Initial program 99.6%
Simplified99.7%
expm1-log1p-u97.9%
expm1-udef96.9%
associate-+r+96.9%
Applied egg-rr96.9%
expm1-def97.9%
expm1-log1p99.7%
associate-/l/99.7%
*-commutative99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in s around 0 99.6%
associate-/r*99.6%
associate-*r/99.6%
mul-1-neg99.6%
Simplified99.6%
Taylor expanded in s around inf 96.5%
Taylor expanded in s around 0 96.5%
associate-/r*96.5%
Simplified96.5%
Final simplification96.5%
(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.6%
Taylor expanded in s around inf 94.6%
*-commutative94.6%
Simplified94.6%
Final simplification94.6%
(FPCore (x s)
:precision binary32
(let* ((t_0 (exp (/ x s))))
(if (<= x -5.000000015855384e-31)
(* 0.25 (/ t_0 s))
(/ 1.0 (* s (+ 2.0 (* 2.0 t_0)))))))
float code(float x, float s) {
float t_0 = expf((x / s));
float tmp;
if (x <= -5.000000015855384e-31f) {
tmp = 0.25f * (t_0 / s);
} 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 = exp((x / s))
if (x <= (-5.000000015855384e-31)) then
tmp = 0.25e0 * (t_0 / s)
else
tmp = 1.0e0 / (s * (2.0e0 + (2.0e0 * t_0)))
end if
code = tmp
end function
function code(x, s) t_0 = exp(Float32(x / s)) tmp = Float32(0.0) if (x <= Float32(-5.000000015855384e-31)) tmp = Float32(Float32(0.25) * Float32(t_0 / s)); else tmp = Float32(Float32(1.0) / Float32(s * Float32(Float32(2.0) + Float32(Float32(2.0) * t_0)))); end return tmp end
function tmp_2 = code(x, s) t_0 = exp((x / s)); tmp = single(0.0); if (x <= single(-5.000000015855384e-31)) tmp = single(0.25) * (t_0 / s); 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 := e^{\frac{x}{s}}\\
\mathbf{if}\;x \leq -5.000000015855384 \cdot 10^{-31}:\\
\;\;\;\;0.25 \cdot \frac{t_0}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{s \cdot \left(2 + 2 \cdot t_0\right)}\\
\end{array}
\end{array}
if x < -5e-31Initial program 99.6%
associate-*l*99.7%
+-commutative99.7%
+-commutative99.7%
Simplified99.7%
Taylor expanded in x around 0 99.7%
associate-/r*99.7%
mul-1-neg99.7%
distribute-frac-neg99.7%
+-commutative99.7%
mul-1-neg99.7%
distribute-frac-neg99.7%
Simplified99.7%
associate-/l/99.7%
*-un-lft-identity99.7%
times-frac99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 95.8%
if -5e-31 < x Initial program 99.5%
Simplified99.6%
expm1-log1p-u97.5%
expm1-udef96.1%
associate-+r+96.1%
Applied egg-rr96.1%
expm1-def97.5%
expm1-log1p99.6%
associate-/l/99.7%
*-commutative99.7%
+-commutative99.7%
Simplified99.7%
distribute-lft-in99.7%
Applied egg-rr93.9%
distribute-lft-in93.9%
count-293.9%
Simplified93.9%
Final simplification94.8%
(FPCore (x s) :precision binary32 (if (<= x 4.0000000781659255e-24) (* 0.25 (/ (exp (/ x s)) s)) (/ (/ 1.0 s) (+ 4.0 (* (* x x) (/ 1.0 (* s s)))))))
float code(float x, float s) {
float tmp;
if (x <= 4.0000000781659255e-24f) {
tmp = 0.25f * (expf((x / s)) / s);
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) * (1.0f / (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 <= 4.0000000781659255e-24) then
tmp = 0.25e0 * (exp((x / s)) / s)
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) * (1.0e0 / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.0000000781659255e-24)) tmp = Float32(Float32(0.25) * Float32(exp(Float32(x / s)) / s)); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) * Float32(Float32(1.0) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(4.0000000781659255e-24)) tmp = single(0.25) * (exp((x / s)) / s); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) * (single(1.0) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.0000000781659255 \cdot 10^{-24}:\\
\;\;\;\;0.25 \cdot \frac{e^{\frac{x}{s}}}{s}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \left(x \cdot x\right) \cdot \frac{1}{s \cdot s}}\\
\end{array}
\end{array}
if x < 4.00000008e-24Initial program 99.6%
associate-*l*99.6%
+-commutative99.6%
+-commutative99.6%
Simplified99.6%
Taylor expanded in x around 0 99.6%
associate-/r*99.7%
mul-1-neg99.7%
distribute-frac-neg99.7%
+-commutative99.7%
mul-1-neg99.7%
distribute-frac-neg99.7%
Simplified99.7%
associate-/l/99.6%
*-un-lft-identity99.6%
times-frac99.7%
Applied egg-rr94.5%
Taylor expanded in x around 0 89.4%
if 4.00000008e-24 < x Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 48.7%
associate-+r+48.7%
distribute-lft1-in48.7%
metadata-eval48.7%
mul0-lft82.0%
associate-+r+82.0%
unpow282.0%
sqr-abs82.0%
unpow282.0%
metadata-eval82.0%
Simplified82.0%
div-inv84.9%
Applied egg-rr84.9%
Final simplification87.7%
(FPCore (x s)
:precision binary32
(if (<= x -5.0000000843119176e-17)
(exp (/ x s))
(if (<= x 4.0000000781659255e-24)
(* (/ 1.0 s) (/ 1.0 (+ 4.0 (* (/ x s) (/ x s)))))
(/ (/ 1.0 s) (+ 4.0 (* (* x x) (/ 1.0 (* s s))))))))
float code(float x, float s) {
float tmp;
if (x <= -5.0000000843119176e-17f) {
tmp = expf((x / s));
} else if (x <= 4.0000000781659255e-24f) {
tmp = (1.0f / s) * (1.0f / (4.0f + ((x / s) * (x / s))));
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) * (1.0f / (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 <= (-5.0000000843119176e-17)) then
tmp = exp((x / s))
else if (x <= 4.0000000781659255e-24) then
tmp = (1.0e0 / s) * (1.0e0 / (4.0e0 + ((x / s) * (x / s))))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) * (1.0e0 / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(-5.0000000843119176e-17)) tmp = exp(Float32(x / s)); elseif (x <= Float32(4.0000000781659255e-24)) tmp = Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s))))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) * Float32(Float32(1.0) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(-5.0000000843119176e-17)) tmp = exp((x / s)); elseif (x <= single(4.0000000781659255e-24)) tmp = (single(1.0) / s) * (single(1.0) / (single(4.0) + ((x / s) * (x / s)))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) * (single(1.0) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.0000000843119176 \cdot 10^{-17}:\\
\;\;\;\;e^{\frac{x}{s}}\\
\mathbf{elif}\;x \leq 4.0000000781659255 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{s} \cdot \frac{1}{4 + \frac{x}{s} \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \left(x \cdot x\right) \cdot \frac{1}{s \cdot s}}\\
\end{array}
\end{array}
if x < -5.00000008e-17Initial program 99.8%
associate-*l*99.8%
+-commutative99.8%
+-commutative99.8%
Simplified99.8%
Taylor expanded in x around 0 99.8%
associate-/r*99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
+-commutative99.8%
mul-1-neg99.8%
distribute-frac-neg99.8%
Simplified99.8%
add-exp-log99.6%
log-div99.6%
log-div99.5%
add-log-exp99.5%
add-sqr-sqrt-0.0%
sqrt-unprod4.6%
sqr-neg4.6%
sqrt-unprod4.6%
add-sqr-sqrt4.6%
add-sqr-sqrt-0.0%
fabs-sqr-0.0%
add-sqr-sqrt99.5%
log-pow99.5%
log1p-udef99.5%
Applied egg-rr99.5%
Taylor expanded in x around inf 96.2%
if -5.00000008e-17 < x < 4.00000008e-24Initial program 99.3%
Simplified99.5%
Taylor expanded in s around inf 54.7%
associate-+r+54.7%
distribute-lft1-in54.7%
metadata-eval54.7%
mul0-lft54.7%
associate-+r+54.7%
unpow254.7%
sqr-abs54.7%
unpow254.7%
metadata-eval54.7%
Simplified54.7%
div-inv54.7%
times-frac74.3%
Applied egg-rr74.3%
if 4.00000008e-24 < x Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 48.7%
associate-+r+48.7%
distribute-lft1-in48.7%
metadata-eval48.7%
mul0-lft82.0%
associate-+r+82.0%
unpow282.0%
sqr-abs82.0%
unpow282.0%
metadata-eval82.0%
Simplified82.0%
div-inv84.9%
Applied egg-rr84.9%
Final simplification86.3%
(FPCore (x s) :precision binary32 (if (<= x 4.0000000781659255e-24) (* (/ 1.0 s) (/ 1.0 (+ 4.0 (* (/ x s) (/ x s))))) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s))))))
float code(float x, float s) {
float tmp;
if (x <= 4.0000000781659255e-24f) {
tmp = (1.0f / s) * (1.0f / (4.0f + ((x / s) * (x / s))));
} else {
tmp = (1.0f / s) / (4.0f + ((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 <= 4.0000000781659255e-24) then
tmp = (1.0e0 / s) * (1.0e0 / (4.0e0 + ((x / s) * (x / s))))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.0000000781659255e-24)) tmp = Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s))))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(4.0000000781659255e-24)) tmp = (single(1.0) / s) * (single(1.0) / (single(4.0) + ((x / s) * (x / s)))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.0000000781659255 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{s} \cdot \frac{1}{4 + \frac{x}{s} \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 4.00000008e-24Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 51.2%
associate-+r+51.2%
distribute-lft1-in51.2%
metadata-eval51.2%
mul0-lft69.7%
associate-+r+69.7%
unpow269.7%
sqr-abs69.7%
unpow269.7%
metadata-eval69.7%
Simplified69.7%
div-inv69.7%
times-frac74.8%
Applied egg-rr74.8%
if 4.00000008e-24 < x Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 48.7%
associate-+r+48.7%
distribute-lft1-in48.7%
metadata-eval48.7%
mul0-lft82.0%
associate-+r+82.0%
unpow282.0%
sqr-abs82.0%
unpow282.0%
metadata-eval82.0%
Simplified82.0%
Final simplification77.6%
(FPCore (x s) :precision binary32 (if (<= x 4.0000000781659255e-24) (* (/ 1.0 s) (/ 1.0 (+ 4.0 (* (/ x s) (/ x s))))) (/ (/ 1.0 s) (+ 4.0 (* (* x x) (/ 1.0 (* s s)))))))
float code(float x, float s) {
float tmp;
if (x <= 4.0000000781659255e-24f) {
tmp = (1.0f / s) * (1.0f / (4.0f + ((x / s) * (x / s))));
} else {
tmp = (1.0f / s) / (4.0f + ((x * x) * (1.0f / (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 <= 4.0000000781659255e-24) then
tmp = (1.0e0 / s) * (1.0e0 / (4.0e0 + ((x / s) * (x / s))))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) * (1.0e0 / (s * s))))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.0000000781659255e-24)) tmp = Float32(Float32(Float32(1.0) / s) * Float32(Float32(1.0) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s))))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) * Float32(Float32(1.0) / Float32(s * s))))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(4.0000000781659255e-24)) tmp = (single(1.0) / s) * (single(1.0) / (single(4.0) + ((x / s) * (x / s)))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) * (single(1.0) / (s * s)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.0000000781659255 \cdot 10^{-24}:\\
\;\;\;\;\frac{1}{s} \cdot \frac{1}{4 + \frac{x}{s} \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \left(x \cdot x\right) \cdot \frac{1}{s \cdot s}}\\
\end{array}
\end{array}
if x < 4.00000008e-24Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 51.2%
associate-+r+51.2%
distribute-lft1-in51.2%
metadata-eval51.2%
mul0-lft69.7%
associate-+r+69.7%
unpow269.7%
sqr-abs69.7%
unpow269.7%
metadata-eval69.7%
Simplified69.7%
div-inv69.7%
times-frac74.8%
Applied egg-rr74.8%
if 4.00000008e-24 < x Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 48.7%
associate-+r+48.7%
distribute-lft1-in48.7%
metadata-eval48.7%
mul0-lft82.0%
associate-+r+82.0%
unpow282.0%
sqr-abs82.0%
unpow282.0%
metadata-eval82.0%
Simplified82.0%
div-inv84.9%
Applied egg-rr84.9%
Final simplification78.7%
(FPCore (x s) :precision binary32 (if (<= x 4.0000000781659255e-24) (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (/ x s)))) (/ (/ 1.0 s) (+ 4.0 (/ (* x x) (* s s))))))
float code(float x, float s) {
float tmp;
if (x <= 4.0000000781659255e-24f) {
tmp = (1.0f / s) / (4.0f + ((x / s) * (x / s)));
} else {
tmp = (1.0f / s) / (4.0f + ((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 <= 4.0000000781659255e-24) then
tmp = (1.0e0 / s) / (4.0e0 + ((x / s) * (x / s)))
else
tmp = (1.0e0 / s) / (4.0e0 + ((x * x) / (s * s)))
end if
code = tmp
end function
function code(x, s) tmp = Float32(0.0) if (x <= Float32(4.0000000781659255e-24)) tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s)))); else tmp = Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x * x) / Float32(s * s)))); end return tmp end
function tmp_2 = code(x, s) tmp = single(0.0); if (x <= single(4.0000000781659255e-24)) tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (x / s))); else tmp = (single(1.0) / s) / (single(4.0) + ((x * x) / (s * s))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.0000000781659255 \cdot 10^{-24}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{s}}{4 + \frac{x \cdot x}{s \cdot s}}\\
\end{array}
\end{array}
if x < 4.00000008e-24Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 51.2%
associate-+r+51.2%
distribute-lft1-in51.2%
metadata-eval51.2%
mul0-lft69.7%
associate-+r+69.7%
unpow269.7%
sqr-abs69.7%
unpow269.7%
metadata-eval69.7%
Simplified69.7%
Taylor expanded in x around 0 69.7%
unpow269.7%
unpow269.7%
times-frac74.8%
Simplified74.8%
if 4.00000008e-24 < x Initial program 99.6%
Simplified99.6%
Taylor expanded in s around inf 48.7%
associate-+r+48.7%
distribute-lft1-in48.7%
metadata-eval48.7%
mul0-lft82.0%
associate-+r+82.0%
unpow282.0%
sqr-abs82.0%
unpow282.0%
metadata-eval82.0%
Simplified82.0%
Final simplification77.6%
(FPCore (x s) :precision binary32 (/ (/ 1.0 s) (+ 4.0 (* (/ x s) (/ x s)))))
float code(float x, float s) {
return (1.0f / s) / (4.0f + ((x / s) * (x / s)));
}
real(4) function code(x, s)
real(4), intent (in) :: x
real(4), intent (in) :: s
code = (1.0e0 / s) / (4.0e0 + ((x / s) * (x / s)))
end function
function code(x, s) return Float32(Float32(Float32(1.0) / s) / Float32(Float32(4.0) + Float32(Float32(x / s) * Float32(x / s)))) end
function tmp = code(x, s) tmp = (single(1.0) / s) / (single(4.0) + ((x / s) * (x / s))); end
\begin{array}{l}
\\
\frac{\frac{1}{s}}{4 + \frac{x}{s} \cdot \frac{x}{s}}
\end{array}
Initial program 99.6%
Simplified99.7%
Taylor expanded in s around inf 50.2%
associate-+r+50.2%
distribute-lft1-in50.2%
metadata-eval50.2%
mul0-lft74.5%
associate-+r+74.5%
unpow274.5%
sqr-abs74.5%
unpow274.5%
metadata-eval74.5%
Simplified74.5%
Taylor expanded in x around 0 74.5%
unpow274.5%
unpow274.5%
times-frac74.0%
Simplified74.0%
Final simplification74.0%
(FPCore (x s) :precision binary32 (if (or (<= x -3.99999992980668e-14) (not (<= x 2.2000000043931323e-8))) (/ s (* x x)) (/ 0.25 s)))
float code(float x, float s) {
float tmp;
if ((x <= -3.99999992980668e-14f) || !(x <= 2.2000000043931323e-8f)) {
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 <= (-3.99999992980668e-14)) .or. (.not. (x <= 2.2000000043931323e-8))) 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(-3.99999992980668e-14)) || !(x <= Float32(2.2000000043931323e-8))) 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(-3.99999992980668e-14)) || ~((x <= single(2.2000000043931323e-8)))) 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 -3.99999992980668 \cdot 10^{-14} \lor \neg \left(x \leq 2.2000000043931323 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{s}{x \cdot x}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.25}{s}\\
\end{array}
\end{array}
if x < -3.99999993e-14 or 2.2e-8 < x Initial program 99.8%
Simplified99.8%
Taylor expanded in s around inf 42.9%
associate-+r+42.9%
distribute-lft1-in42.9%
metadata-eval42.9%
mul0-lft81.6%
associate-+r+81.6%
unpow281.6%
sqr-abs81.6%
unpow281.6%
metadata-eval81.6%
Simplified81.6%
Taylor expanded in s around 0 63.4%
unpow263.4%
Simplified63.4%
if -3.99999993e-14 < x < 2.2e-8Initial program 99.3%
/-rgt-identity99.3%
associate-/l/99.3%
*-lft-identity99.3%
+-commutative99.3%
distribute-rgt-in99.4%
*-lft-identity99.4%
+-commutative99.4%
distribute-rgt-in99.4%
*-lft-identity99.4%
Simplified99.5%
Taylor expanded in s around inf 59.2%
Final simplification61.8%
(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.6%
/-rgt-identity99.6%
associate-/l/99.6%
*-lft-identity99.6%
+-commutative99.6%
distribute-rgt-in99.6%
*-lft-identity99.6%
+-commutative99.6%
distribute-rgt-in99.6%
*-lft-identity99.6%
Simplified99.7%
Taylor expanded in s around inf 25.3%
Final simplification25.3%
herbie shell --seed 2023182
(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))))))