
(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 10 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 (- 1.0 (/ (- u 0.25) 0.75)))) (* s 3.0)))
float code(float s, float u) {
return logf((1.0f / (1.0f - ((u - 0.25f) / 0.75f)))) * (s * 3.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = log((1.0e0 / (1.0e0 - ((u - 0.25e0) / 0.75e0)))) * (s * 3.0e0)
end function
function code(s, u) return Float32(log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(u - Float32(0.25)) / Float32(0.75))))) * Float32(s * Float32(3.0))) end
function tmp = code(s, u) tmp = log((single(1.0) / (single(1.0) - ((u - single(0.25)) / single(0.75))))) * (s * single(3.0)); end
\begin{array}{l}
\\
\log \left(\frac{1}{1 - \frac{u - 0.25}{0.75}}\right) \cdot \left(s \cdot 3\right)
\end{array}
Initial program 96.0%
Final simplification96.0%
(FPCore (s u) :precision binary32 (* (log (/ 1.0 (+ (* -1.3333333333333333 (- u 0.25)) 1.0))) (* s 3.0)))
float code(float s, float u) {
return logf((1.0f / ((-1.3333333333333333f * (u - 0.25f)) + 1.0f))) * (s * 3.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = log((1.0e0 / (((-1.3333333333333333e0) * (u - 0.25e0)) + 1.0e0))) * (s * 3.0e0)
end function
function code(s, u) return Float32(log(Float32(Float32(1.0) / Float32(Float32(Float32(-1.3333333333333333) * Float32(u - Float32(0.25))) + Float32(1.0)))) * Float32(s * Float32(3.0))) end
function tmp = code(s, u) tmp = log((single(1.0) / ((single(-1.3333333333333333) * (u - single(0.25))) + single(1.0)))) * (s * single(3.0)); end
\begin{array}{l}
\\
\log \left(\frac{1}{-1.3333333333333333 \cdot \left(u - 0.25\right) + 1}\right) \cdot \left(s \cdot 3\right)
\end{array}
Initial program 96.0%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lower-+.f32N/A
lift-/.f32N/A
distribute-neg-frac2N/A
div-invN/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
metadata-eval95.8
Applied rewrites95.8%
Final simplification95.8%
(FPCore (s u) :precision binary32 (* (log (/ 1.0 (- 1.3333333333333333 (* 1.3333333333333333 u)))) (* s 3.0)))
float code(float s, float u) {
return logf((1.0f / (1.3333333333333333f - (1.3333333333333333f * u)))) * (s * 3.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = log((1.0e0 / (1.3333333333333333e0 - (1.3333333333333333e0 * u)))) * (s * 3.0e0)
end function
function code(s, u) return Float32(log(Float32(Float32(1.0) / Float32(Float32(1.3333333333333333) - Float32(Float32(1.3333333333333333) * u)))) * Float32(s * Float32(3.0))) end
function tmp = code(s, u) tmp = log((single(1.0) / (single(1.3333333333333333) - (single(1.3333333333333333) * u)))) * (s * single(3.0)); end
\begin{array}{l}
\\
\log \left(\frac{1}{1.3333333333333333 - 1.3333333333333333 \cdot u}\right) \cdot \left(s \cdot 3\right)
\end{array}
Initial program 96.0%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lower-+.f32N/A
lift-/.f32N/A
distribute-neg-frac2N/A
div-invN/A
*-commutativeN/A
lower-*.f32N/A
metadata-evalN/A
metadata-eval95.8
Applied rewrites95.8%
lift-*.f32N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
distribute-lft-neg-inN/A
metadata-evalN/A
div-invN/A
clear-numN/A
lower-/.f32N/A
lower-/.f32N/A
lift--.f32N/A
sub-negN/A
distribute-neg-inN/A
metadata-evalN/A
metadata-evalN/A
+-commutativeN/A
sub-negN/A
lift--.f3295.7
Applied rewrites95.7%
lift-+.f32N/A
+-commutativeN/A
lift-/.f32N/A
lift-/.f32N/A
associate-/r/N/A
metadata-evalN/A
lift--.f32N/A
sub-negN/A
distribute-rgt-inN/A
metadata-evalN/A
metadata-evalN/A
distribute-lft-neg-inN/A
distribute-neg-inN/A
+-commutativeN/A
lift-fma.f32N/A
unsub-negN/A
lift-fma.f32N/A
+-commutativeN/A
associate--r+N/A
metadata-evalN/A
lower--.f32N/A
*-commutativeN/A
lower-*.f3295.5
Applied rewrites95.5%
Final simplification95.5%
(FPCore (s u) :precision binary32 (* (+ (* (* (+ 1.5 u) u) u) (* (+ (log 0.75) u) 3.0)) s))
float code(float s, float u) {
return ((((1.5f + u) * u) * u) + ((logf(0.75f) + u) * 3.0f)) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((((1.5e0 + u) * u) * u) + ((log(0.75e0) + u) * 3.0e0)) * s
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(Float32(1.5) + u) * u) * u) + Float32(Float32(log(Float32(0.75)) + u) * Float32(3.0))) * s) end
function tmp = code(s, u) tmp = ((((single(1.5) + u) * u) * u) + ((log(single(0.75)) + u) * single(3.0))) * s; end
\begin{array}{l}
\\
\left(\left(\left(1.5 + u\right) \cdot u\right) \cdot u + \left(\log 0.75 + u\right) \cdot 3\right) \cdot s
\end{array}
Initial program 96.0%
Taylor expanded in u around 0
distribute-rgt-inN/A
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Applied rewrites14.6%
Applied rewrites36.7%
Final simplification36.7%
(FPCore (s u) :precision binary32 (* (* (log1p (/ (- 0.25 u) 0.75)) -3.0) s))
float code(float s, float u) {
return (log1pf(((0.25f - u) / 0.75f)) * -3.0f) * s;
}
function code(s, u) return Float32(Float32(log1p(Float32(Float32(Float32(0.25) - u) / Float32(0.75))) * Float32(-3.0)) * s) end
\begin{array}{l}
\\
\left(\mathsf{log1p}\left(\frac{0.25 - u}{0.75}\right) \cdot -3\right) \cdot s
\end{array}
Initial program 96.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites34.1%
lift-*.f32N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
div-invN/A
lift--.f32N/A
lower-neg.f32N/A
div-subN/A
sub-negN/A
div-invN/A
metadata-evalN/A
lower-fma.f32N/A
metadata-evalN/A
metadata-eval7.1
Applied rewrites7.2%
lift-neg.f32N/A
neg-sub0N/A
metadata-evalN/A
lift-fma.f32N/A
+-commutativeN/A
associate--r+N/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
div-invN/A
div-subN/A
lift--.f32N/A
lower-/.f3234.1
Applied rewrites34.2%
Final simplification34.1%
(FPCore (s u) :precision binary32 (* (* (fma (fma -2.0 u 2.0) u (log 0.6666666666666666)) -3.0) s))
float code(float s, float u) {
return (fmaf(fmaf(-2.0f, u, 2.0f), u, logf(0.6666666666666666f)) * -3.0f) * s;
}
function code(s, u) return Float32(Float32(fma(fma(Float32(-2.0), u, Float32(2.0)), u, log(Float32(0.6666666666666666))) * Float32(-3.0)) * s) end
\begin{array}{l}
\\
\left(\mathsf{fma}\left(\mathsf{fma}\left(-2, u, 2\right), u, \log 0.6666666666666666\right) \cdot -3\right) \cdot s
\end{array}
Initial program 96.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites34.1%
lift-*.f32N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
div-invN/A
lift--.f32N/A
lower-neg.f32N/A
div-subN/A
sub-negN/A
div-invN/A
metadata-evalN/A
lower-fma.f32N/A
metadata-evalN/A
metadata-eval7.1
Applied rewrites7.2%
Applied rewrites27.8%
Taylor expanded in u around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-log.f328.9
Applied rewrites8.9%
Final simplification9.0%
(FPCore (s u) :precision binary32 (* (* (log 0.6666666666666666) s) -3.0))
float code(float s, float u) {
return (logf(0.6666666666666666f) * s) * -3.0f;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (log(0.6666666666666666e0) * s) * (-3.0e0)
end function
function code(s, u) return Float32(Float32(log(Float32(0.6666666666666666)) * s) * Float32(-3.0)) end
function tmp = code(s, u) tmp = (log(single(0.6666666666666666)) * s) * single(-3.0); end
\begin{array}{l}
\\
\left(\log 0.6666666666666666 \cdot s\right) \cdot -3
\end{array}
Initial program 96.0%
lift-*.f32N/A
lift-*.f32N/A
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f32N/A
Applied rewrites34.1%
lift-*.f32N/A
*-commutativeN/A
metadata-evalN/A
distribute-rgt-neg-inN/A
metadata-evalN/A
div-invN/A
lift--.f32N/A
lower-neg.f32N/A
div-subN/A
sub-negN/A
div-invN/A
metadata-evalN/A
lower-fma.f32N/A
metadata-evalN/A
metadata-eval7.1
Applied rewrites7.2%
Applied rewrites27.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f3228.2
Applied rewrites28.2%
(FPCore (s u) :precision binary32 (* (* (* (+ 1.5 u) u) u) s))
float code(float s, float u) {
return (((1.5f + u) * u) * u) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (((1.5e0 + u) * u) * u) * s
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(1.5) + u) * u) * u) * s) end
function tmp = code(s, u) tmp = (((single(1.5) + u) * u) * u) * s; end
\begin{array}{l}
\\
\left(\left(\left(1.5 + u\right) \cdot u\right) \cdot u\right) \cdot s
\end{array}
Initial program 96.0%
Taylor expanded in u around 0
distribute-rgt-inN/A
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Applied rewrites14.5%
Taylor expanded in u around inf
Applied rewrites23.2%
Taylor expanded in u around inf
Applied rewrites27.8%
Final simplification27.8%
(FPCore (s u) :precision binary32 (* (* (* (+ 1.5 u) s) u) u))
float code(float s, float u) {
return (((1.5f + u) * s) * u) * u;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (((1.5e0 + u) * s) * u) * u
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(1.5) + u) * s) * u) * u) end
function tmp = code(s, u) tmp = (((single(1.5) + u) * s) * u) * u; end
\begin{array}{l}
\\
\left(\left(\left(1.5 + u\right) \cdot s\right) \cdot u\right) \cdot u
\end{array}
Initial program 96.0%
Taylor expanded in u around 0
distribute-rgt-inN/A
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Applied rewrites14.5%
Taylor expanded in u around inf
Applied rewrites23.2%
Taylor expanded in u around inf
Applied rewrites27.8%
Final simplification27.8%
(FPCore (s u) :precision binary32 (* (* (* u u) u) s))
float code(float s, float u) {
return ((u * u) * u) * s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((u * u) * u) * s
end function
function code(s, u) return Float32(Float32(Float32(u * u) * u) * s) end
function tmp = code(s, u) tmp = ((u * u) * u) * s; end
\begin{array}{l}
\\
\left(\left(u \cdot u\right) \cdot u\right) \cdot s
\end{array}
Initial program 96.0%
Taylor expanded in u around 0
distribute-rgt-inN/A
associate-+r+N/A
+-commutativeN/A
associate-*r*N/A
distribute-lft-outN/A
*-commutativeN/A
distribute-lft-outN/A
associate-*l*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Applied rewrites14.6%
Taylor expanded in u around inf
Applied rewrites23.2%
Applied rewrites23.2%
Final simplification23.2%
herbie shell --seed 2024277
(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))))))