
(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 6 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 (* (* (log (- 1.0 (/ (- u 0.25) 0.75))) (- 3.0)) s))
float code(float s, float u) {
return (logf((1.0f - ((u - 0.25f) / 0.75f))) * -3.0f) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (log((1.0e0 - ((u - 0.25e0) / 0.75e0))) * -3.0e0) * s
end function
function code(s, u) return Float32(Float32(log(Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75)))) * Float32(-Float32(3.0))) * s) end
function tmp = code(s, u) tmp = (log((single(1.0) - ((u - single(0.25)) / single(0.75)))) * -single(3.0)) * s; end
\begin{array}{l}
\\
\left(\log \left(1 - \frac{u - 0.25}{0.75}\right) \cdot \left(-3\right)\right) \cdot s
\end{array}
Initial program 95.4%
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
flip--N/A
associate-/r/N/A
flip-+N/A
lift--.f32N/A
frac-timesN/A
log-divN/A
lower--.f32N/A
Applied rewrites95.9%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites96.5%
Final simplification96.5%
(FPCore (s u) :precision binary32 (* (* (- s) 3.0) (log (- 1.0 (/ (- u 0.25) 0.75)))))
float code(float s, float u) {
return (-s * 3.0f) * logf((1.0f - ((u - 0.25f) / 0.75f)));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (-s * 3.0e0) * log((1.0e0 - ((u - 0.25e0) / 0.75e0)))
end function
function code(s, u) return Float32(Float32(Float32(-s) * Float32(3.0)) * log(Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75))))) end
function tmp = code(s, u) tmp = (-s * single(3.0)) * log((single(1.0) - ((u - single(0.25)) / single(0.75)))); end
\begin{array}{l}
\\
\left(\left(-s\right) \cdot 3\right) \cdot \log \left(1 - \frac{u - 0.25}{0.75}\right)
\end{array}
Initial program 95.4%
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
flip--N/A
associate-/r/N/A
flip-+N/A
lift--.f32N/A
frac-timesN/A
log-divN/A
lower--.f32N/A
Applied rewrites95.9%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3295.9
lift--.f32N/A
lift-log.f32N/A
lift-log.f32N/A
diff-logN/A
lift-*.f32N/A
lift-*.f32N/A
times-fracN/A
Applied rewrites96.5%
Final simplification96.5%
(FPCore (s u) :precision binary32 (* (* (log (- 1.3333333333333333 (/ u 0.75))) -3.0) s))
float code(float s, float u) {
return (logf((1.3333333333333333f - (u / 0.75f))) * -3.0f) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (log((1.3333333333333333e0 - (u / 0.75e0))) * (-3.0e0)) * s
end function
function code(s, u) return Float32(Float32(log(Float32(Float32(1.3333333333333333) - Float32(u / Float32(0.75)))) * Float32(-3.0)) * s) end
function tmp = code(s, u) tmp = (log((single(1.3333333333333333) - (u / single(0.75)))) * single(-3.0)) * s; end
\begin{array}{l}
\\
\left(\log \left(1.3333333333333333 - \frac{u}{0.75}\right) \cdot -3\right) \cdot s
\end{array}
Initial program 95.4%
lift-log.f32N/A
lift-/.f32N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
log-powN/A
lower-*.f32N/A
metadata-evalN/A
lower-log.f32N/A
pow2N/A
lower-pow.f3296.0
Applied rewrites96.0%
Applied rewrites94.5%
lift-*.f32N/A
lift-neg.f32N/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
lower-*.f32N/A
metadata-eval94.5
Applied rewrites94.5%
(FPCore (s u) :precision binary32 (* (* (+ (log 0.75) u) s) 3.0))
float code(float s, float u) {
return ((logf(0.75f) + u) * s) * 3.0f;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((log(0.75e0) + u) * s) * 3.0e0
end function
function code(s, u) return Float32(Float32(Float32(log(Float32(0.75)) + u) * s) * Float32(3.0)) end
function tmp = code(s, u) tmp = ((log(single(0.75)) + u) * s) * single(3.0); end
\begin{array}{l}
\\
\left(\left(\log 0.75 + u\right) \cdot s\right) \cdot 3
\end{array}
Initial program 95.4%
Taylor expanded in u around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f32N/A
distribute-lft-outN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-log.f3225.0
Applied rewrites25.0%
(FPCore (s u) :precision binary32 (* s (log (fma 1.265625 u 0.421875))))
float code(float s, float u) {
return s * logf(fmaf(1.265625f, u, 0.421875f));
}
function code(s, u) return Float32(s * log(fma(Float32(1.265625), u, Float32(0.421875)))) end
\begin{array}{l}
\\
s \cdot \log \left(\mathsf{fma}\left(1.265625, u, 0.421875\right)\right)
\end{array}
Initial program 95.4%
lift-log.f32N/A
lift-/.f32N/A
inv-powN/A
sqr-powN/A
pow-prod-downN/A
log-powN/A
lower-*.f32N/A
metadata-evalN/A
lower-log.f32N/A
pow2N/A
lower-pow.f3296.0
Applied rewrites96.0%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
associate-*r/N/A
metadata-evalN/A
lower-/.f3293.9
Applied rewrites93.9%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f32N/A
lift-*.f32N/A
lift-log.f32N/A
log-pow-revN/A
log-pow-revN/A
lower-log.f32N/A
lower-pow.f32N/A
Applied rewrites94.1%
Taylor expanded in u around 0
+-commutativeN/A
lower-fma.f327.0
Applied rewrites7.5%
(FPCore (s u) :precision binary32 (* (log 0.421875) s))
float code(float s, float u) {
return logf(0.421875f) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = log(0.421875e0) * s
end function
function code(s, u) return Float32(log(Float32(0.421875)) * s) end
function tmp = code(s, u) tmp = log(single(0.421875)) * s; end
\begin{array}{l}
\\
\log 0.421875 \cdot s
\end{array}
Initial program 95.4%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f327.6
Applied rewrites7.6%
Applied rewrites7.6%
herbie shell --seed 2024339
(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))))))