
(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 (* (* s -3.0) (log1p (/ (- (- u) -0.25) 0.75))))
float code(float s, float u) {
return (s * -3.0f) * log1pf(((-u - -0.25f) / 0.75f));
}
function code(s, u) return Float32(Float32(s * Float32(-3.0)) * log1p(Float32(Float32(Float32(-u) - Float32(-0.25)) / Float32(0.75)))) end
\begin{array}{l}
\\
\left(s \cdot -3\right) \cdot \mathsf{log1p}\left(\frac{\left(-u\right) - -0.25}{0.75}\right)
\end{array}
Initial program 95.8%
log-rec97.0%
distribute-rgt-neg-out97.0%
distribute-lft-neg-out97.0%
*-commutative97.0%
distribute-rgt-neg-in97.0%
metadata-eval97.0%
sub-neg97.0%
log1p-define98.4%
distribute-neg-frac98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (s u) :precision binary32 (* -3.0 (* s (log (- 1.3333333333333333 (* u 1.3333333333333333))))))
float code(float s, float u) {
return -3.0f * (s * logf((1.3333333333333333f - (u * 1.3333333333333333f))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (-3.0e0) * (s * log((1.3333333333333333e0 - (u * 1.3333333333333333e0))))
end function
function code(s, u) return Float32(Float32(-3.0) * Float32(s * log(Float32(Float32(1.3333333333333333) - Float32(u * Float32(1.3333333333333333)))))) end
function tmp = code(s, u) tmp = single(-3.0) * (s * log((single(1.3333333333333333) - (u * single(1.3333333333333333))))); end
\begin{array}{l}
\\
-3 \cdot \left(s \cdot \log \left(1.3333333333333333 - u \cdot 1.3333333333333333\right)\right)
\end{array}
Initial program 95.8%
log-rec97.0%
div-sub95.9%
metadata-eval95.9%
Simplified95.9%
Taylor expanded in s around 0 96.4%
Final simplification96.4%
(FPCore (s u) :precision binary32 (* -3.0 (* s (log1p (* 1.3333333333333333 (- 0.25 u))))))
float code(float s, float u) {
return -3.0f * (s * log1pf((1.3333333333333333f * (0.25f - u))));
}
function code(s, u) return Float32(Float32(-3.0) * Float32(s * log1p(Float32(Float32(1.3333333333333333) * Float32(Float32(0.25) - u))))) end
\begin{array}{l}
\\
-3 \cdot \left(s \cdot \mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\right)\right)\right)
\end{array}
Initial program 95.8%
log-rec97.0%
distribute-rgt-neg-out97.0%
distribute-lft-neg-out97.0%
*-commutative97.0%
distribute-rgt-neg-in97.0%
metadata-eval97.0%
sub-neg97.0%
log1p-define98.4%
distribute-neg-frac98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in s around 0 96.6%
log1p-define97.8%
Simplified97.8%
Final simplification97.8%
(FPCore (s u) :precision binary32 (* (* s -3.0) (log1p (* 1.3333333333333333 (- 0.25 u)))))
float code(float s, float u) {
return (s * -3.0f) * log1pf((1.3333333333333333f * (0.25f - u)));
}
function code(s, u) return Float32(Float32(s * Float32(-3.0)) * log1p(Float32(Float32(1.3333333333333333) * Float32(Float32(0.25) - u)))) end
\begin{array}{l}
\\
\left(s \cdot -3\right) \cdot \mathsf{log1p}\left(1.3333333333333333 \cdot \left(0.25 - u\right)\right)
\end{array}
Initial program 95.8%
log-rec97.0%
distribute-rgt-neg-out97.0%
distribute-lft-neg-out97.0%
*-commutative97.0%
distribute-rgt-neg-in97.0%
metadata-eval97.0%
sub-neg97.0%
log1p-define98.4%
distribute-neg-frac98.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
Taylor expanded in s around 0 96.6%
log1p-define97.8%
Simplified97.8%
Taylor expanded in s around 0 96.6%
*-commutative96.6%
log1p-define97.8%
*-commutative97.8%
associate-*r*98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (s u) :precision binary32 (* 3.0 (* s (log 1.3333333333333333))))
float code(float s, float u) {
return 3.0f * (s * logf(1.3333333333333333f));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = 3.0e0 * (s * log(1.3333333333333333e0))
end function
function code(s, u) return Float32(Float32(3.0) * Float32(s * log(Float32(1.3333333333333333)))) end
function tmp = code(s, u) tmp = single(3.0) * (s * log(single(1.3333333333333333))); end
\begin{array}{l}
\\
3 \cdot \left(s \cdot \log 1.3333333333333333\right)
\end{array}
Initial program 95.8%
*-commutative95.8%
associate-*l*95.8%
*-commutative95.8%
log-rec96.9%
distribute-lft-neg-out96.9%
distribute-rgt-neg-in96.9%
Simplified97.1%
fma-undefine96.4%
*-commutative96.4%
+-commutative96.4%
metadata-eval96.4%
associate-+r+95.8%
+-commutative95.8%
log1p-undefine97.0%
*-commutative97.0%
pow197.0%
Applied egg-rr96.8%
unpow196.8%
log-pow97.1%
fma-define96.4%
*-commutative96.4%
+-commutative96.4%
metadata-eval96.4%
*-commutative96.4%
associate-+r+95.9%
+-commutative95.9%
associate-+l+95.8%
fma-undefine96.7%
log1p-undefine97.9%
Simplified97.9%
add-sqr-sqrt97.4%
sqrt-unprod97.9%
*-commutative97.9%
*-commutative97.9%
swap-sqr97.8%
pow297.8%
metadata-eval97.8%
Applied egg-rr97.8%
Taylor expanded in u around 0 28.2%
*-commutative28.2%
Simplified28.2%
Final simplification28.2%
(FPCore (s u) :precision binary32 (* s (log 0.421875)))
float code(float s, float u) {
return s * logf(0.421875f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log(0.421875e0)
end function
function code(s, u) return Float32(s * log(Float32(0.421875))) end
function tmp = code(s, u) tmp = s * log(single(0.421875)); end
\begin{array}{l}
\\
s \cdot \log 0.421875
\end{array}
Initial program 95.8%
*-commutative95.8%
associate-*l*95.8%
*-commutative95.8%
log-rec96.9%
distribute-lft-neg-out96.9%
distribute-rgt-neg-in96.9%
Simplified97.1%
fma-undefine96.4%
*-commutative96.4%
+-commutative96.4%
metadata-eval96.4%
associate-+r+95.8%
+-commutative95.8%
log1p-undefine97.0%
*-commutative97.0%
pow197.0%
Applied egg-rr96.8%
unpow196.8%
Simplified96.8%
Taylor expanded in u around 0 7.4%
Final simplification7.4%
herbie shell --seed 2024039
(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))))))