
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
(FPCore (s u) :precision binary32 (cast (! :precision binary64 (* s (- (log1p (* u -4.0)))))))
float code(float s, float u) {
double tmp = ((double) s) * -log1p((((double) u) * -4.0));
return (float) tmp;
}
function code(s, u) tmp = Float64(Float64(s) * Float64(-log1p(Float64(Float64(u) * -4.0)))) return Float32(tmp) end
\begin{array}{l}
\\
\langle \left( s \cdot \left(-\mathsf{log1p}\left(u \cdot -4\right)\right) \right)_{\text{binary64}} \rangle_{\text{binary32}}
\end{array}
Initial program 100.0%
Final simplification100.0%
(FPCore (s u) :precision binary32 (* s (- (log1p (* u -4.0)))))
float code(float s, float u) {
return s * -log1pf((u * -4.0f));
}
function code(s, u) return Float32(s * Float32(-log1p(Float32(u * Float32(-4.0))))) end
\begin{array}{l}
\\
s \cdot \left(-\mathsf{log1p}\left(u \cdot -4\right)\right)
\end{array}
Initial program 57.0%
log-rec59.7%
sub-neg59.7%
distribute-rgt-neg-out59.7%
log1p-def99.4%
distribute-rgt-neg-out99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (s u) :precision binary32 (/ s (- (+ (* u -0.3333333333333333) (* 0.25 (/ 1.0 u))) 0.5)))
float code(float s, float u) {
return s / (((u * -0.3333333333333333f) + (0.25f * (1.0f / u))) - 0.5f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s / (((u * (-0.3333333333333333e0)) + (0.25e0 * (1.0e0 / u))) - 0.5e0)
end function
function code(s, u) return Float32(s / Float32(Float32(Float32(u * Float32(-0.3333333333333333)) + Float32(Float32(0.25) * Float32(Float32(1.0) / u))) - Float32(0.5))) end
function tmp = code(s, u) tmp = s / (((u * single(-0.3333333333333333)) + (single(0.25) * (single(1.0) / u))) - single(0.5)); end
\begin{array}{l}
\\
\frac{s}{\left(u \cdot -0.3333333333333333 + 0.25 \cdot \frac{1}{u}\right) - 0.5}
\end{array}
Initial program 57.0%
log-rec59.7%
cancel-sign-sub-inv59.7%
metadata-eval59.7%
*-commutative59.7%
log1p-udef99.4%
neg-sub099.4%
flip--99.2%
+-lft-identity99.2%
div-inv99.1%
metadata-eval99.1%
sub0-neg99.1%
pow299.1%
Applied egg-rr99.1%
Applied egg-rr98.8%
Taylor expanded in u around 0 94.0%
Final simplification94.0%
(FPCore (s u) :precision binary32 (/ s (+ (/ 0.25 u) -0.5)))
float code(float s, float u) {
return s / ((0.25f / u) + -0.5f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s / ((0.25e0 / u) + (-0.5e0))
end function
function code(s, u) return Float32(s / Float32(Float32(Float32(0.25) / u) + Float32(-0.5))) end
function tmp = code(s, u) tmp = s / ((single(0.25) / u) + single(-0.5)); end
\begin{array}{l}
\\
\frac{s}{\frac{0.25}{u} + -0.5}
\end{array}
Initial program 57.0%
log-rec59.7%
cancel-sign-sub-inv59.7%
metadata-eval59.7%
*-commutative59.7%
log1p-udef99.4%
neg-sub099.4%
flip--99.2%
+-lft-identity99.2%
div-inv99.1%
metadata-eval99.1%
sub0-neg99.1%
pow299.1%
Applied egg-rr99.1%
Applied egg-rr98.8%
Taylor expanded in u around 0 90.4%
sub-neg90.4%
associate-*r/90.4%
metadata-eval90.4%
metadata-eval90.4%
Simplified90.4%
Final simplification90.4%
(FPCore (s u) :precision binary32 (* 4.0 (* s u)))
float code(float s, float u) {
return 4.0f * (s * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = 4.0e0 * (s * u)
end function
function code(s, u) return Float32(Float32(4.0) * Float32(s * u)) end
function tmp = code(s, u) tmp = single(4.0) * (s * u); end
\begin{array}{l}
\\
4 \cdot \left(s \cdot u\right)
\end{array}
Initial program 57.0%
Taylor expanded in u around 0 75.9%
Final simplification75.9%
(FPCore (s u) :precision binary32 (* s (* u 4.0)))
float code(float s, float u) {
return s * (u * 4.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (u * 4.0e0)
end function
function code(s, u) return Float32(s * Float32(u * Float32(4.0))) end
function tmp = code(s, u) tmp = s * (u * single(4.0)); end
\begin{array}{l}
\\
s \cdot \left(u \cdot 4\right)
\end{array}
Initial program 57.0%
Taylor expanded in u around 0 76.1%
*-commutative76.1%
Simplified76.1%
Final simplification76.1%
(FPCore (s u) :precision binary32 (/ s -0.5))
float code(float s, float u) {
return s / -0.5f;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s / (-0.5e0)
end function
function code(s, u) return Float32(s / Float32(-0.5)) end
function tmp = code(s, u) tmp = s / single(-0.5); end
\begin{array}{l}
\\
\frac{s}{-0.5}
\end{array}
Initial program 57.0%
log-rec59.7%
cancel-sign-sub-inv59.7%
metadata-eval59.7%
*-commutative59.7%
log1p-udef99.4%
neg-sub099.4%
flip--99.2%
+-lft-identity99.2%
div-inv99.1%
metadata-eval99.1%
sub0-neg99.1%
pow299.1%
Applied egg-rr99.1%
Applied egg-rr98.8%
Taylor expanded in u around 0 90.3%
Taylor expanded in u around inf 7.8%
Final simplification7.8%
herbie shell --seed 2023297
(FPCore (s u)
:name "Disney BSSRDF, sample scattering profile, lower"
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
(* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))