
(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 3 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 (* (* -3.0 s) (log (+ 1.3333333333333333 (* -1.3333333333333333 u)))))
float code(float s, float u) {
return (-3.0f * s) * logf((1.3333333333333333f + (-1.3333333333333333f * u)));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((-3.0e0) * s) * log((1.3333333333333333e0 + ((-1.3333333333333333e0) * u)))
end function
function code(s, u) return Float32(Float32(Float32(-3.0) * s) * log(Float32(Float32(1.3333333333333333) + Float32(Float32(-1.3333333333333333) * u)))) end
function tmp = code(s, u) tmp = (single(-3.0) * s) * log((single(1.3333333333333333) + (single(-1.3333333333333333) * u))); end
\begin{array}{l}
\\
\left(-3 \cdot s\right) \cdot \log \left(1.3333333333333333 + -1.3333333333333333 \cdot u\right)
\end{array}
Initial program 95.8%
Taylor expanded in s around 0
associate-*r*N/A
*-commutativeN/A
log-recN/A
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
lower-*.f32N/A
Applied rewrites7.2%
Applied rewrites96.3%
Final simplification96.3%
(FPCore (s u) :precision binary32 (* (* (* (* u u) 0.5) 3.0) s))
float code(float s, float u) {
return (((u * u) * 0.5f) * 3.0f) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (((u * u) * 0.5e0) * 3.0e0) * s
end function
function code(s, u) return Float32(Float32(Float32(Float32(u * u) * Float32(0.5)) * Float32(3.0)) * s) end
function tmp = code(s, u) tmp = (((u * u) * single(0.5)) * single(3.0)) * s; end
\begin{array}{l}
\\
\left(\left(\left(u \cdot u\right) \cdot 0.5\right) \cdot 3\right) \cdot s
\end{array}
Initial program 95.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-log.f3210.8
Applied rewrites10.8%
Taylor expanded in u around inf
Applied rewrites26.5%
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f3226.5
Applied rewrites26.5%
(FPCore (s u) :precision binary32 (* (* s 3.0) (* (* u u) 0.5)))
float code(float s, float u) {
return (s * 3.0f) * ((u * u) * 0.5f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (s * 3.0e0) * ((u * u) * 0.5e0)
end function
function code(s, u) return Float32(Float32(s * Float32(3.0)) * Float32(Float32(u * u) * Float32(0.5))) end
function tmp = code(s, u) tmp = (s * single(3.0)) * ((u * u) * single(0.5)); end
\begin{array}{l}
\\
\left(s \cdot 3\right) \cdot \left(\left(u \cdot u\right) \cdot 0.5\right)
\end{array}
Initial program 95.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-log.f3210.8
Applied rewrites10.8%
Taylor expanded in u around inf
Applied rewrites26.5%
Final simplification26.5%
herbie shell --seed 2024255
(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))))))