
(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 4 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 (* (log (- 1.3333333333333333 (* u 1.3333333333333333))) -3.0)))
float code(float s, float u) {
return s * (logf((1.3333333333333333f - (u * 1.3333333333333333f))) * -3.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (log((1.3333333333333333e0 - (u * 1.3333333333333333e0))) * (-3.0e0))
end function
function code(s, u) return Float32(s * Float32(log(Float32(Float32(1.3333333333333333) - Float32(u * Float32(1.3333333333333333)))) * Float32(-3.0))) end
function tmp = code(s, u) tmp = s * (log((single(1.3333333333333333) - (u * single(1.3333333333333333)))) * single(-3.0)); end
\begin{array}{l}
\\
s \cdot \left(\log \left(1.3333333333333333 - u \cdot 1.3333333333333333\right) \cdot -3\right)
\end{array}
Initial program 95.9%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites34.1%
Applied rewrites9.9%
Applied rewrites96.6%
Final simplification96.6%
(FPCore (s u) :precision binary32 (* (* (* (+ (/ 3.0 u) 1.5) s) u) u))
float code(float s, float u) {
return ((((3.0f / u) + 1.5f) * s) * u) * u;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((((3.0e0 / u) + 1.5e0) * s) * u) * u
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(Float32(3.0) / u) + Float32(1.5)) * s) * u) * u) end
function tmp = code(s, u) tmp = ((((single(3.0) / u) + single(1.5)) * s) * u) * u; end
\begin{array}{l}
\\
\left(\left(\left(\frac{3}{u} + 1.5\right) \cdot s\right) \cdot u\right) \cdot u
\end{array}
Initial program 95.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f327.4
Applied rewrites7.4%
Taylor expanded in u around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-fma.f32N/A
Applied rewrites15.0%
Taylor expanded in u around inf
Applied rewrites29.9%
Final simplification29.9%
(FPCore (s u) :precision binary32 (* (* u u) (* (+ (/ 3.0 u) 1.5) s)))
float code(float s, float u) {
return (u * u) * (((3.0f / u) + 1.5f) * s);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (u * u) * (((3.0e0 / u) + 1.5e0) * s)
end function
function code(s, u) return Float32(Float32(u * u) * Float32(Float32(Float32(Float32(3.0) / u) + Float32(1.5)) * s)) end
function tmp = code(s, u) tmp = (u * u) * (((single(3.0) / u) + single(1.5)) * s); end
\begin{array}{l}
\\
\left(u \cdot u\right) \cdot \left(\left(\frac{3}{u} + 1.5\right) \cdot s\right)
\end{array}
Initial program 95.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f327.4
Applied rewrites7.4%
Taylor expanded in u around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-fma.f32N/A
Applied rewrites14.9%
Taylor expanded in u around inf
Applied rewrites26.6%
Taylor expanded in u around inf
Applied rewrites29.9%
Final simplification29.9%
(FPCore (s u) :precision binary32 (* (* 3.0 u) s))
float code(float s, float u) {
return (3.0f * u) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (3.0e0 * u) * s
end function
function code(s, u) return Float32(Float32(Float32(3.0) * u) * s) end
function tmp = code(s, u) tmp = (single(3.0) * u) * s; end
\begin{array}{l}
\\
\left(3 \cdot u\right) \cdot s
\end{array}
Initial program 95.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f327.4
Applied rewrites7.4%
Taylor expanded in u around 0
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
associate-+r+N/A
*-commutativeN/A
associate-*r*N/A
+-commutativeN/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
associate-*l*N/A
distribute-lft-outN/A
lower-*.f32N/A
lower-fma.f32N/A
Applied rewrites14.9%
Taylor expanded in u around 0
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-+.f32N/A
lower-log.f3226.0
Applied rewrites26.0%
Taylor expanded in u around inf
Applied rewrites29.8%
herbie shell --seed 2024268
(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))))))