
(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 5 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 (/ (- u 0.25) -0.75)) -3.0)))
float code(float s, float u) {
return s * (log1pf(((u - 0.25f) / -0.75f)) * -3.0f);
}
function code(s, u) return Float32(s * Float32(log1p(Float32(Float32(u - Float32(0.25)) / Float32(-0.75))) * Float32(-3.0))) end
\begin{array}{l}
\\
s \cdot \left(\mathsf{log1p}\left(\frac{u - 0.25}{-0.75}\right) \cdot -3\right)
\end{array}
Initial program 96.1%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites98.0%
lift-*.f32N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
div-invN/A
distribute-neg-frac2N/A
lower-/.f32N/A
metadata-eval98.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (s u) :precision binary32 (* (* (log1p (fma u -1.3333333333333333 0.3333333333333333)) -3.0) s))
float code(float s, float u) {
return (log1pf(fmaf(u, -1.3333333333333333f, 0.3333333333333333f)) * -3.0f) * s;
}
function code(s, u) return Float32(Float32(log1p(fma(u, Float32(-1.3333333333333333), Float32(0.3333333333333333))) * Float32(-3.0)) * s) end
\begin{array}{l}
\\
\left(\mathsf{log1p}\left(\mathsf{fma}\left(u, -1.3333333333333333, 0.3333333333333333\right)\right) \cdot -3\right) \cdot s
\end{array}
Initial program 95.8%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites97.9%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3297.9
lift-*.f32N/A
lift--.f32N/A
sub-negN/A
distribute-rgt-inN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
lower-fma.f32N/A
metadata-eval97.9
Applied rewrites97.9%
herbie shell --seed 2024230
(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))))))