
(FPCore (s u) :precision binary32 (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))
float code(float s, float u) {
return (3.0f * s) * logf((1.0f / (1.0f - ((u - 0.25f) / 0.75f))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (3.0e0 * s) * log((1.0e0 / (1.0e0 - ((u - 0.25e0) / 0.75e0))))
end function
function code(s, u) return Float32(Float32(Float32(3.0) * s) * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75)))))) end
function tmp = code(s, u) tmp = (single(3.0) * s) * log((single(1.0) / (single(1.0) - ((u - single(0.25)) / single(0.75))))); end
\begin{array}{l}
\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (s u) :precision binary32 (* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))
float code(float s, float u) {
return (3.0f * s) * logf((1.0f / (1.0f - ((u - 0.25f) / 0.75f))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (3.0e0 * s) * log((1.0e0 / (1.0e0 - ((u - 0.25e0) / 0.75e0))))
end function
function code(s, u) return Float32(Float32(Float32(3.0) * s) * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75)))))) end
function tmp = code(s, u) tmp = (single(3.0) * s) * log((single(1.0) / (single(1.0) - ((u - single(0.25)) / single(0.75))))); end
\begin{array}{l}
\\
\left(3 \cdot s\right) \cdot \log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right)
\end{array}
(FPCore (s u) :precision binary32 (* s (- (* (log1p (* (pow (+ u -0.25) 2.0) -1.7777777777777777)) -3.0) (* -3.0 (log1p (fma 1.3333333333333333 u -0.3333333333333333))))))
float code(float s, float u) {
return s * ((log1pf((powf((u + -0.25f), 2.0f) * -1.7777777777777777f)) * -3.0f) - (-3.0f * log1pf(fmaf(1.3333333333333333f, u, -0.3333333333333333f))));
}
function code(s, u) return Float32(s * Float32(Float32(log1p(Float32((Float32(u + Float32(-0.25)) ^ Float32(2.0)) * Float32(-1.7777777777777777))) * Float32(-3.0)) - Float32(Float32(-3.0) * log1p(fma(Float32(1.3333333333333333), u, Float32(-0.3333333333333333)))))) end
\begin{array}{l}
\\
s \cdot \left(\mathsf{log1p}\left({\left(u + -0.25\right)}^{2} \cdot -1.7777777777777777\right) \cdot -3 - -3 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(1.3333333333333333, u, -0.3333333333333333\right)\right)\right)
\end{array}
Initial program 95.5%
associate-*l*95.5%
*-commutative95.5%
associate-*l*95.5%
log-rec96.4%
distribute-lft-neg-out96.4%
distribute-rgt-neg-in96.4%
Simplified96.4%
fma-udef95.8%
*-commutative95.8%
+-commutative95.8%
metadata-eval95.8%
associate-+r+95.3%
+-commutative95.3%
log1p-udef96.9%
*-commutative96.9%
fma-def98.1%
Applied egg-rr98.1%
fma-udef96.9%
metadata-eval96.9%
metadata-eval96.9%
distribute-rgt-in98.1%
metadata-eval98.1%
sub-neg98.1%
log1p-def96.3%
cancel-sign-sub-inv96.3%
flip--95.7%
log-div95.6%
metadata-eval95.6%
swap-sqr95.4%
metadata-eval95.8%
pow295.8%
sub-neg95.8%
metadata-eval95.8%
log1p-udef96.9%
sub-neg96.9%
Applied egg-rr96.7%
sub-neg96.7%
log1p-def97.7%
*-commutative97.7%
distribute-rgt-neg-in97.7%
metadata-eval97.7%
fma-def98.4%
Simplified98.4%
*-commutative98.4%
sub-neg98.4%
distribute-rgt-in98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (s u) :precision binary32 (* (* s 3.0) (- (log1p (/ (- (- -0.25) u) 0.75)))))
float code(float s, float u) {
return (s * 3.0f) * -log1pf(((-(-0.25f) - u) / 0.75f));
}
function code(s, u) return Float32(Float32(s * Float32(3.0)) * Float32(-log1p(Float32(Float32(Float32(-Float32(-0.25)) - u) / Float32(0.75))))) end
\begin{array}{l}
\\
\left(s \cdot 3\right) \cdot \left(-\mathsf{log1p}\left(\frac{\left(--0.25\right) - u}{0.75}\right)\right)
\end{array}
Initial program 95.5%
log-rec96.5%
sub-neg96.5%
log1p-def98.4%
distribute-neg-frac98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (s u) :precision binary32 (* -3.0 (* s (log (- 1.3333333333333333 (* u 1.3333333333333333))))))
float code(float s, float u) {
return -3.0f * (s * logf((1.3333333333333333f - (u * 1.3333333333333333f))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (-3.0e0) * (s * log((1.3333333333333333e0 - (u * 1.3333333333333333e0))))
end function
function code(s, u) return Float32(Float32(-3.0) * Float32(s * log(Float32(Float32(1.3333333333333333) - Float32(u * Float32(1.3333333333333333)))))) end
function tmp = code(s, u) tmp = single(-3.0) * (s * log((single(1.3333333333333333) - (u * single(1.3333333333333333))))); end
\begin{array}{l}
\\
-3 \cdot \left(s \cdot \log \left(1.3333333333333333 - u \cdot 1.3333333333333333\right)\right)
\end{array}
Initial program 95.5%
associate-*l*95.5%
log-rec96.5%
div-sub95.5%
metadata-eval95.5%
Simplified95.5%
Taylor expanded in s around 0 95.9%
Final simplification95.9%
(FPCore (s u) :precision binary32 (* -3.0 (* s (log1p (* 1.3333333333333333 (- 0.25 u))))))
float code(float s, float u) {
return -3.0f * (s * log1pf((1.3333333333333333f * (0.25f - u))));
}
function code(s, u) return Float32(Float32(-3.0) * Float32(s * log1p(Float32(Float32(1.3333333333333333) * Float32(Float32(0.25) - u))))) end
\begin{array}{l}
\\
-3 \cdot \left(s \cdot \mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\right)\right)\right)
\end{array}
Initial program 95.5%
log-rec96.5%
sub-neg96.5%
log1p-def98.4%
distribute-neg-frac98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in s around 0 96.3%
log1p-def98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (s u) :precision binary32 (* s (* -3.0 (log1p (* (+ u -0.25) -1.3333333333333333)))))
float code(float s, float u) {
return s * (-3.0f * log1pf(((u + -0.25f) * -1.3333333333333333f)));
}
function code(s, u) return Float32(s * Float32(Float32(-3.0) * log1p(Float32(Float32(u + Float32(-0.25)) * Float32(-1.3333333333333333))))) end
\begin{array}{l}
\\
s \cdot \left(-3 \cdot \mathsf{log1p}\left(\left(u + -0.25\right) \cdot -1.3333333333333333\right)\right)
\end{array}
Initial program 95.5%
associate-*l*95.5%
*-commutative95.5%
associate-*l*95.5%
log-rec96.4%
distribute-lft-neg-out96.4%
distribute-rgt-neg-in96.4%
Simplified96.4%
fma-udef95.8%
*-commutative95.8%
+-commutative95.8%
metadata-eval95.8%
associate-+r+95.3%
+-commutative95.3%
log1p-udef96.9%
*-commutative96.9%
fma-def98.1%
Applied egg-rr98.1%
fma-udef96.9%
metadata-eval96.9%
metadata-eval96.9%
distribute-rgt-in98.1%
sub-neg98.1%
*-commutative98.1%
sub-neg98.1%
metadata-eval98.1%
Applied egg-rr98.1%
Final simplification98.1%
(FPCore (s u) :precision binary32 (* 3.0 (* s u)))
float code(float s, float u) {
return 3.0f * (s * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = 3.0e0 * (s * u)
end function
function code(s, u) return Float32(Float32(3.0) * Float32(s * u)) end
function tmp = code(s, u) tmp = single(3.0) * (s * u); end
\begin{array}{l}
\\
3 \cdot \left(s \cdot u\right)
\end{array}
Initial program 95.5%
Taylor expanded in u around 0 25.3%
Taylor expanded in u around inf 29.7%
Final simplification29.7%
(FPCore (s u) :precision binary32 (* s (* u 3.0)))
float code(float s, float u) {
return s * (u * 3.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (u * 3.0e0)
end function
function code(s, u) return Float32(s * Float32(u * Float32(3.0))) end
function tmp = code(s, u) tmp = s * (u * single(3.0)); end
\begin{array}{l}
\\
s \cdot \left(u \cdot 3\right)
\end{array}
Initial program 95.5%
Taylor expanded in u around 0 25.3%
Taylor expanded in u around inf 29.7%
expm1-log1p-u29.7%
expm1-udef15.8%
associate-*r*15.8%
*-commutative15.8%
Applied egg-rr15.8%
expm1-def29.7%
expm1-log1p29.7%
associate-*r*29.7%
Simplified29.7%
Final simplification29.7%
herbie shell --seed 2023336
(FPCore (s u)
:name "Disney BSSRDF, sample scattering profile, upper"
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 0.25 u) (<= u 1.0)))
(* (* 3.0 s) (log (/ 1.0 (- 1.0 (/ (- u 0.25) 0.75))))))