
(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 5 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 (if (<= (* u 4.0) 0.006200000178068876) (* (/ -1.0 (- 0.5 (/ 0.25 u))) s) (* (log (/ 1.0 (- 1.0 (exp (log (* u 4.0)))))) s)))
float code(float s, float u) {
float tmp;
if ((u * 4.0f) <= 0.006200000178068876f) {
tmp = (-1.0f / (0.5f - (0.25f / u))) * s;
} else {
tmp = logf((1.0f / (1.0f - expf(logf((u * 4.0f)))))) * s;
}
return tmp;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: tmp
if ((u * 4.0e0) <= 0.006200000178068876e0) then
tmp = ((-1.0e0) / (0.5e0 - (0.25e0 / u))) * s
else
tmp = log((1.0e0 / (1.0e0 - exp(log((u * 4.0e0)))))) * s
end if
code = tmp
end function
function code(s, u) tmp = Float32(0.0) if (Float32(u * Float32(4.0)) <= Float32(0.006200000178068876)) tmp = Float32(Float32(Float32(-1.0) / Float32(Float32(0.5) - Float32(Float32(0.25) / u))) * s); else tmp = Float32(log(Float32(Float32(1.0) / Float32(Float32(1.0) - exp(log(Float32(u * Float32(4.0))))))) * s); end return tmp end
function tmp_2 = code(s, u) tmp = single(0.0); if ((u * single(4.0)) <= single(0.006200000178068876)) tmp = (single(-1.0) / (single(0.5) - (single(0.25) / u))) * s; else tmp = log((single(1.0) / (single(1.0) - exp(log((u * single(4.0))))))) * s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u \cdot 4 \leq 0.006200000178068876:\\
\;\;\;\;\frac{-1}{0.5 - \frac{0.25}{u}} \cdot s\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{1}{1 - e^{\log \left(u \cdot 4\right)}}\right) \cdot s\\
\end{array}
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.00620000018Initial program 47.9%
Applied rewrites70.1%
lift-*.f32N/A
lift-/.f32N/A
un-div-invN/A
frac-2negN/A
lift-/.f32N/A
distribute-neg-fracN/A
lift-neg.f32N/A
remove-double-negN/A
lift-pow.f32N/A
lift-pow.f32N/A
pow-divN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f32N/A
Applied rewrites84.3%
Taylor expanded in u around 0
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
metadata-evalN/A
associate-*r/N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f3298.2
Applied rewrites98.2%
lift-/.f32N/A
frac-2negN/A
div-invN/A
lift-neg.f32N/A
remove-double-negN/A
lower-*.f32N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f3298.2
Applied rewrites98.2%
if 0.00620000018 < (*.f32 #s(literal 4 binary32) u) Initial program 93.2%
rem-exp-logN/A
lower-exp.f32N/A
lower-log.f3293.3
lift-*.f32N/A
*-commutativeN/A
lower-*.f3293.3
Applied rewrites93.3%
Final simplification97.1%
(FPCore (s u)
:precision binary32
(let* ((t_0 (- 1.0 (* u 4.0))))
(if (<= t_0 0.9936000108718872)
(* (log (/ 1.0 t_0)) s)
(* (/ -1.0 (- 0.5 (/ 0.25 u))) s))))
float code(float s, float u) {
float t_0 = 1.0f - (u * 4.0f);
float tmp;
if (t_0 <= 0.9936000108718872f) {
tmp = logf((1.0f / t_0)) * s;
} else {
tmp = (-1.0f / (0.5f - (0.25f / u))) * s;
}
return tmp;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: t_0
real(4) :: tmp
t_0 = 1.0e0 - (u * 4.0e0)
if (t_0 <= 0.9936000108718872e0) then
tmp = log((1.0e0 / t_0)) * s
else
tmp = ((-1.0e0) / (0.5e0 - (0.25e0 / u))) * s
end if
code = tmp
end function
function code(s, u) t_0 = Float32(Float32(1.0) - Float32(u * Float32(4.0))) tmp = Float32(0.0) if (t_0 <= Float32(0.9936000108718872)) tmp = Float32(log(Float32(Float32(1.0) / t_0)) * s); else tmp = Float32(Float32(Float32(-1.0) / Float32(Float32(0.5) - Float32(Float32(0.25) / u))) * s); end return tmp end
function tmp_2 = code(s, u) t_0 = single(1.0) - (u * single(4.0)); tmp = single(0.0); if (t_0 <= single(0.9936000108718872)) tmp = log((single(1.0) / t_0)) * s; else tmp = (single(-1.0) / (single(0.5) - (single(0.25) / u))) * s; end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - u \cdot 4\\
\mathbf{if}\;t\_0 \leq 0.9936000108718872:\\
\;\;\;\;\log \left(\frac{1}{t\_0}\right) \cdot s\\
\mathbf{else}:\\
\;\;\;\;\frac{-1}{0.5 - \frac{0.25}{u}} \cdot s\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.993600011Initial program 93.2%
if 0.993600011 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 47.9%
Applied rewrites71.0%
lift-*.f32N/A
lift-/.f32N/A
un-div-invN/A
frac-2negN/A
lift-/.f32N/A
distribute-neg-fracN/A
lift-neg.f32N/A
remove-double-negN/A
lift-pow.f32N/A
lift-pow.f32N/A
pow-divN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f32N/A
Applied rewrites84.3%
Taylor expanded in u around 0
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
metadata-evalN/A
associate-*r/N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f3298.2
Applied rewrites98.2%
lift-/.f32N/A
frac-2negN/A
div-invN/A
lift-neg.f32N/A
remove-double-negN/A
lower-*.f32N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f3298.2
Applied rewrites98.2%
Final simplification97.1%
(FPCore (s u) :precision binary32 (* (/ -1.0 (- 0.5 (/ 0.25 u))) s))
float code(float s, float u) {
return (-1.0f / (0.5f - (0.25f / u))) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((-1.0e0) / (0.5e0 - (0.25e0 / u))) * s
end function
function code(s, u) return Float32(Float32(Float32(-1.0) / Float32(Float32(0.5) - Float32(Float32(0.25) / u))) * s) end
function tmp = code(s, u) tmp = (single(-1.0) / (single(0.5) - (single(0.25) / u))) * s; end
\begin{array}{l}
\\
\frac{-1}{0.5 - \frac{0.25}{u}} \cdot s
\end{array}
Initial program 58.4%
Applied rewrites53.0%
lift-*.f32N/A
lift-/.f32N/A
un-div-invN/A
frac-2negN/A
lift-/.f32N/A
distribute-neg-fracN/A
lift-neg.f32N/A
remove-double-negN/A
lift-pow.f32N/A
lift-pow.f32N/A
pow-divN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f32N/A
Applied rewrites74.2%
Taylor expanded in u around 0
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
metadata-evalN/A
associate-*r/N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f3288.8
Applied rewrites88.8%
lift-/.f32N/A
frac-2negN/A
div-invN/A
lift-neg.f32N/A
remove-double-negN/A
lower-*.f32N/A
frac-2negN/A
metadata-evalN/A
remove-double-negN/A
lower-/.f3288.8
Applied rewrites88.8%
Final simplification88.8%
(FPCore (s u) :precision binary32 (/ (- s) (- 0.5 (/ 0.25 u))))
float code(float s, float u) {
return -s / (0.5f - (0.25f / u));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = -s / (0.5e0 - (0.25e0 / u))
end function
function code(s, u) return Float32(Float32(-s) / Float32(Float32(0.5) - Float32(Float32(0.25) / u))) end
function tmp = code(s, u) tmp = -s / (single(0.5) - (single(0.25) / u)); end
\begin{array}{l}
\\
\frac{-s}{0.5 - \frac{0.25}{u}}
\end{array}
Initial program 58.4%
Applied rewrites52.8%
lift-*.f32N/A
lift-/.f32N/A
un-div-invN/A
frac-2negN/A
lift-/.f32N/A
distribute-neg-fracN/A
lift-neg.f32N/A
remove-double-negN/A
lift-pow.f32N/A
lift-pow.f32N/A
pow-divN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f32N/A
Applied rewrites74.0%
Taylor expanded in u around 0
div-subN/A
associate-/l*N/A
*-inversesN/A
metadata-evalN/A
metadata-evalN/A
associate-*r/N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f3288.8
Applied rewrites88.8%
(FPCore (s u) :precision binary32 (* (* u 4.0) s))
float code(float s, float u) {
return (u * 4.0f) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (u * 4.0e0) * s
end function
function code(s, u) return Float32(Float32(u * Float32(4.0)) * s) end
function tmp = code(s, u) tmp = (u * single(4.0)) * s; end
\begin{array}{l}
\\
\left(u \cdot 4\right) \cdot s
\end{array}
Initial program 58.4%
Taylor expanded in u around 0
lower-*.f3274.4
Applied rewrites74.4%
Final simplification74.4%
herbie shell --seed 2024308
(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))))))