
(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 8 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)))
(*
(* (- (* (- (* (- (* -64.0 u) 21.333333333333332) u) 8.0) u) 4.0) u)
(- s)))))
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 = (((((((-64.0f * u) - 21.333333333333332f) * u) - 8.0f) * u) - 4.0f) * u) * -s;
}
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 = ((((((((-64.0e0) * u) - 21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0) * u) * -s
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(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(-64.0) * u) - Float32(21.333333333333332)) * u) - Float32(8.0)) * u) - Float32(4.0)) * u) * Float32(-s)); 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 = (((((((single(-64.0) * u) - single(21.333333333333332)) * u) - single(8.0)) * u) - single(4.0)) * u) * -s; 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}:\\
\;\;\;\;\left(\left(\left(\left(-64 \cdot u - 21.333333333333332\right) \cdot u - 8\right) \cdot u - 4\right) \cdot u\right) \cdot \left(-s\right)\\
\end{array}
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.959999979Initial program 95.6%
if 0.959999979 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 54.9%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-/.f3254.2
Applied rewrites54.2%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3254.2
lift-log.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lower-log.f3255.7
Applied rewrites55.7%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites99.0%
Final simplification98.5%
(FPCore (s u) :precision binary32 (* (* (- (* (- (* (- (* -64.0 u) 21.333333333333332) u) 8.0) u) 4.0) u) (- s)))
float code(float s, float u) {
return (((((((-64.0f * u) - 21.333333333333332f) * u) - 8.0f) * u) - 4.0f) * u) * -s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((((((((-64.0e0) * u) - 21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0) * u) * -s
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(Float32(-64.0) * u) - Float32(21.333333333333332)) * u) - Float32(8.0)) * u) - Float32(4.0)) * u) * Float32(-s)) end
function tmp = code(s, u) tmp = (((((((single(-64.0) * u) - single(21.333333333333332)) * u) - single(8.0)) * u) - single(4.0)) * u) * -s; end
\begin{array}{l}
\\
\left(\left(\left(\left(-64 \cdot u - 21.333333333333332\right) \cdot u - 8\right) \cdot u - 4\right) \cdot u\right) \cdot \left(-s\right)
\end{array}
Initial program 61.3%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-/.f3260.4
Applied rewrites60.4%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3260.4
lift-log.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lower-log.f3261.8
Applied rewrites61.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites93.3%
Final simplification93.3%
(FPCore (s u) :precision binary32 (* (* (- (* (- (* -21.333333333333332 u) 8.0) u) 4.0) u) (- s)))
float code(float s, float u) {
return (((((-21.333333333333332f * u) - 8.0f) * u) - 4.0f) * u) * -s;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = ((((((-21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0) * u) * -s
end function
function code(s, u) return Float32(Float32(Float32(Float32(Float32(Float32(Float32(-21.333333333333332) * u) - Float32(8.0)) * u) - Float32(4.0)) * u) * Float32(-s)) end
function tmp = code(s, u) tmp = (((((single(-21.333333333333332) * u) - single(8.0)) * u) - single(4.0)) * u) * -s; end
\begin{array}{l}
\\
\left(\left(\left(-21.333333333333332 \cdot u - 8\right) \cdot u - 4\right) \cdot u\right) \cdot \left(-s\right)
\end{array}
Initial program 61.3%
Taylor expanded in u around inf
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-/.f3260.4
Applied rewrites60.4%
lift-*.f32N/A
*-commutativeN/A
lower-*.f3260.4
lift-log.f32N/A
lift-/.f32N/A
log-recN/A
lower-neg.f32N/A
lower-log.f3261.8
Applied rewrites61.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f3291.2
Applied rewrites91.2%
Final simplification91.2%
(FPCore (s u) :precision binary32 (* (* (- s) (- (* (- (* -21.333333333333332 u) 8.0) u) 4.0)) u))
float code(float s, float u) {
return (-s * ((((-21.333333333333332f * u) - 8.0f) * u) - 4.0f)) * u;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (-s * (((((-21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0)) * u
end function
function code(s, u) return Float32(Float32(Float32(-s) * Float32(Float32(Float32(Float32(Float32(-21.333333333333332) * u) - Float32(8.0)) * u) - Float32(4.0))) * u) end
function tmp = code(s, u) tmp = (-s * ((((single(-21.333333333333332) * u) - single(8.0)) * u) - single(4.0))) * u; end
\begin{array}{l}
\\
\left(\left(-s\right) \cdot \left(\left(-21.333333333333332 \cdot u - 8\right) \cdot u - 4\right)\right) \cdot u
\end{array}
Initial program 61.3%
lift-log.f32N/A
lift-/.f32N/A
log-divN/A
metadata-evalN/A
flip--N/A
+-lft-identityN/A
lower-/.f32N/A
Applied rewrites42.0%
Taylor expanded in u around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f3273.2
Applied rewrites73.2%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3273.1
Applied rewrites72.9%
Taylor expanded in s around -inf
Applied rewrites91.2%
(FPCore (s u) :precision binary32 (* (* (- s) u) (- (* (- (* -21.333333333333332 u) 8.0) u) 4.0)))
float code(float s, float u) {
return (-s * u) * ((((-21.333333333333332f * u) - 8.0f) * u) - 4.0f);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (-s * u) * (((((-21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0)
end function
function code(s, u) return Float32(Float32(Float32(-s) * u) * Float32(Float32(Float32(Float32(Float32(-21.333333333333332) * u) - Float32(8.0)) * u) - Float32(4.0))) end
function tmp = code(s, u) tmp = (-s * u) * ((((single(-21.333333333333332) * u) - single(8.0)) * u) - single(4.0)); end
\begin{array}{l}
\\
\left(\left(-s\right) \cdot u\right) \cdot \left(\left(-21.333333333333332 \cdot u - 8\right) \cdot u - 4\right)
\end{array}
Initial program 61.3%
lift-log.f32N/A
lift-/.f32N/A
log-divN/A
metadata-evalN/A
flip--N/A
+-lft-identityN/A
lower-/.f32N/A
Applied rewrites43.2%
Taylor expanded in u around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f3273.2
Applied rewrites73.2%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3273.1
Applied rewrites73.1%
Taylor expanded in s around -inf
Applied rewrites90.9%
(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 61.3%
lift-log.f32N/A
lift-/.f32N/A
log-divN/A
metadata-evalN/A
flip--N/A
+-lft-identityN/A
lower-/.f32N/A
Applied rewrites42.5%
Taylor expanded in u around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f3273.2
Applied rewrites73.4%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.9%
Applied rewrites86.7%
(FPCore (s u) :precision binary32 (* s (* (- 4.0 (* -8.0 u)) u)))
float code(float s, float u) {
return s * ((4.0f - (-8.0f * u)) * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * ((4.0e0 - ((-8.0e0) * u)) * u)
end function
function code(s, u) return Float32(s * Float32(Float32(Float32(4.0) - Float32(Float32(-8.0) * u)) * u)) end
function tmp = code(s, u) tmp = s * ((single(4.0) - (single(-8.0) * u)) * u); end
\begin{array}{l}
\\
s \cdot \left(\left(4 - -8 \cdot u\right) \cdot u\right)
\end{array}
Initial program 61.3%
lift-log.f32N/A
lift-/.f32N/A
log-divN/A
metadata-evalN/A
flip--N/A
+-lft-identityN/A
lower-/.f32N/A
Applied rewrites40.6%
Taylor expanded in u around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f32N/A
lower-*.f32N/A
lower--.f32N/A
lower-*.f3273.4
Applied rewrites73.2%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.9%
Applied rewrites86.6%
(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 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
herbie shell --seed 2024337
(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))))))