
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
(FPCore (s u)
:precision binary32
(let* ((t_0 (- 1.0 (* 4.0 u))))
(if (<= t_0 0.9599999785423279)
(* s (log (/ 1.0 t_0)))
(*
s
(*
(*
(+
(+ (+ (/ 4.0 (pow u 3.0)) (/ 8.0 (* u u))) (/ 21.333333333333332 u))
64.0)
(pow u 3.0))
u)))))
float code(float s, float u) {
float t_0 = 1.0f - (4.0f * u);
float tmp;
if (t_0 <= 0.9599999785423279f) {
tmp = s * logf((1.0f / t_0));
} else {
tmp = s * ((((((4.0f / powf(u, 3.0f)) + (8.0f / (u * u))) + (21.333333333333332f / u)) + 64.0f) * powf(u, 3.0f)) * u);
}
return tmp;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: t_0
real(4) :: tmp
t_0 = 1.0e0 - (4.0e0 * u)
if (t_0 <= 0.9599999785423279e0) then
tmp = s * log((1.0e0 / t_0))
else
tmp = s * ((((((4.0e0 / (u ** 3.0e0)) + (8.0e0 / (u * u))) + (21.333333333333332e0 / u)) + 64.0e0) * (u ** 3.0e0)) * u)
end if
code = tmp
end function
function code(s, u) t_0 = Float32(Float32(1.0) - Float32(Float32(4.0) * u)) tmp = Float32(0.0) if (t_0 <= Float32(0.9599999785423279)) tmp = Float32(s * log(Float32(Float32(1.0) / t_0))); else tmp = Float32(s * Float32(Float32(Float32(Float32(Float32(Float32(Float32(4.0) / (u ^ Float32(3.0))) + Float32(Float32(8.0) / Float32(u * u))) + Float32(Float32(21.333333333333332) / u)) + Float32(64.0)) * (u ^ Float32(3.0))) * u)); end return tmp end
function tmp_2 = code(s, u) t_0 = single(1.0) - (single(4.0) * u); tmp = single(0.0); if (t_0 <= single(0.9599999785423279)) tmp = s * log((single(1.0) / t_0)); else tmp = s * ((((((single(4.0) / (u ^ single(3.0))) + (single(8.0) / (u * u))) + (single(21.333333333333332) / u)) + single(64.0)) * (u ^ single(3.0))) * u); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - 4 \cdot u\\
\mathbf{if}\;t\_0 \leq 0.9599999785423279:\\
\;\;\;\;s \cdot \log \left(\frac{1}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;s \cdot \left(\left(\left(\left(\left(\frac{4}{{u}^{3}} + \frac{8}{u \cdot u}\right) + \frac{21.333333333333332}{u}\right) + 64\right) \cdot {u}^{3}\right) \cdot u\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.959999979Initial program 96.3%
if 0.959999979 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 53.6%
Taylor expanded in u around 0
lower-*.f3281.2
Applied rewrites81.2%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3281.2
Applied rewrites80.7%
Taylor expanded in u around inf
Applied rewrites98.7%
(FPCore (s u)
:precision binary32
(let* ((t_0 (- 1.0 (* 4.0 u))))
(if (<= t_0 0.9599999785423279)
(* s (log (/ 1.0 t_0)))
(*
s
(*
(- 64.0 (/ (- -21.333333333333332 (/ (+ (/ 4.0 u) 8.0) u)) u))
(pow u 4.0))))))
float code(float s, float u) {
float t_0 = 1.0f - (4.0f * u);
float tmp;
if (t_0 <= 0.9599999785423279f) {
tmp = s * logf((1.0f / t_0));
} else {
tmp = s * ((64.0f - ((-21.333333333333332f - (((4.0f / u) + 8.0f) / u)) / u)) * powf(u, 4.0f));
}
return tmp;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: t_0
real(4) :: tmp
t_0 = 1.0e0 - (4.0e0 * u)
if (t_0 <= 0.9599999785423279e0) then
tmp = s * log((1.0e0 / t_0))
else
tmp = s * ((64.0e0 - (((-21.333333333333332e0) - (((4.0e0 / u) + 8.0e0) / u)) / u)) * (u ** 4.0e0))
end if
code = tmp
end function
function code(s, u) t_0 = Float32(Float32(1.0) - Float32(Float32(4.0) * u)) tmp = Float32(0.0) if (t_0 <= Float32(0.9599999785423279)) tmp = Float32(s * log(Float32(Float32(1.0) / t_0))); else tmp = Float32(s * Float32(Float32(Float32(64.0) - Float32(Float32(Float32(-21.333333333333332) - Float32(Float32(Float32(Float32(4.0) / u) + Float32(8.0)) / u)) / u)) * (u ^ Float32(4.0)))); end return tmp end
function tmp_2 = code(s, u) t_0 = single(1.0) - (single(4.0) * u); tmp = single(0.0); if (t_0 <= single(0.9599999785423279)) tmp = s * log((single(1.0) / t_0)); else tmp = s * ((single(64.0) - ((single(-21.333333333333332) - (((single(4.0) / u) + single(8.0)) / u)) / u)) * (u ^ single(4.0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - 4 \cdot u\\
\mathbf{if}\;t\_0 \leq 0.9599999785423279:\\
\;\;\;\;s \cdot \log \left(\frac{1}{t\_0}\right)\\
\mathbf{else}:\\
\;\;\;\;s \cdot \left(\left(64 - \frac{-21.333333333333332 - \frac{\frac{4}{u} + 8}{u}}{u}\right) \cdot {u}^{4}\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.959999979Initial program 96.3%
if 0.959999979 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 53.6%
Taylor expanded in u around 0
lower-*.f3281.2
Applied rewrites81.2%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3281.2
Applied rewrites80.7%
Taylor expanded in u around inf
Applied rewrites98.7%
Taylor expanded in u around -inf
Applied rewrites98.7%
(FPCore (s u)
:precision binary32
(if (<= (* 4.0 u) 0.009999999776482582)
(*
s
(+ (* (* (+ (* (fma 64.0 u 21.333333333333332) u) 8.0) u) u) (* u 4.0)))
(* s (log (/ 1.0 (- 1.0 (* 4.0 u)))))))
float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.009999999776482582f) {
tmp = s * (((((fmaf(64.0f, u, 21.333333333333332f) * u) + 8.0f) * u) * u) + (u * 4.0f));
} else {
tmp = s * logf((1.0f / (1.0f - (4.0f * u))));
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.009999999776482582)) tmp = Float32(s * Float32(Float32(Float32(Float32(Float32(fma(Float32(64.0), u, Float32(21.333333333333332)) * u) + Float32(8.0)) * u) * u) + Float32(u * Float32(4.0)))); else tmp = Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.009999999776482582:\\
\;\;\;\;s \cdot \left(\left(\left(\mathsf{fma}\left(64, u, 21.333333333333332\right) \cdot u + 8\right) \cdot u\right) \cdot u + u \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\
\end{array}
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.00999999978Initial program 50.6%
Taylor expanded in u around 0
lower-*.f3284.1
Applied rewrites84.1%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3284.1
Applied rewrites83.6%
Applied rewrites97.3%
Applied rewrites98.5%
if 0.00999999978 < (*.f32 #s(literal 4 binary32) u) Initial program 93.1%
(FPCore (s u) :precision binary32 (* s (+ (* (* (+ (* (fma 64.0 u 21.333333333333332) u) 8.0) u) u) (* u 4.0))))
float code(float s, float u) {
return s * (((((fmaf(64.0f, u, 21.333333333333332f) * u) + 8.0f) * u) * u) + (u * 4.0f));
}
function code(s, u) return Float32(s * Float32(Float32(Float32(Float32(Float32(fma(Float32(64.0), u, Float32(21.333333333333332)) * u) + Float32(8.0)) * u) * u) + Float32(u * Float32(4.0)))) end
\begin{array}{l}
\\
s \cdot \left(\left(\left(\mathsf{fma}\left(64, u, 21.333333333333332\right) \cdot u + 8\right) \cdot u\right) \cdot u + u \cdot 4\right)
\end{array}
Initial program 60.4%
Taylor expanded in u around 0
lower-*.f3273.9
Applied rewrites73.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3273.9
Applied rewrites73.9%
Applied rewrites86.8%
Applied rewrites90.3%
(FPCore (s u) :precision binary32 (* s (+ (* (* 8.0 u) u) (* u 4.0))))
float code(float s, float u) {
return s * (((8.0f * u) * u) + (u * 4.0f));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (((8.0e0 * u) * u) + (u * 4.0e0))
end function
function code(s, u) return Float32(s * Float32(Float32(Float32(Float32(8.0) * u) * u) + Float32(u * Float32(4.0)))) end
function tmp = code(s, u) tmp = s * (((single(8.0) * u) * u) + (u * single(4.0))); end
\begin{array}{l}
\\
s \cdot \left(\left(8 \cdot u\right) \cdot u + u \cdot 4\right)
\end{array}
Initial program 60.4%
Taylor expanded in u around 0
lower-*.f3273.9
Applied rewrites73.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3273.9
Applied rewrites73.9%
Applied rewrites86.8%
Taylor expanded in u around 0
Applied rewrites86.8%
(FPCore (s u) :precision binary32 (* s (* 4.0 u)))
float code(float s, float u) {
return s * (4.0f * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (4.0e0 * u)
end function
function code(s, u) return Float32(s * Float32(Float32(4.0) * u)) end
function tmp = code(s, u) tmp = s * (single(4.0) * u); end
\begin{array}{l}
\\
s \cdot \left(4 \cdot u\right)
\end{array}
Initial program 60.4%
Taylor expanded in u around 0
lower-*.f3273.9
Applied rewrites73.9%
herbie shell --seed 2024298
(FPCore (s u)
:name "Disney BSSRDF, sample scattering profile, lower"
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
(* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))