
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 21 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
real(4), intent (in) :: alphax
real(4), intent (in) :: alphay
real(4), intent (in) :: u0
real(4), intent (in) :: cos2phi
real(4), intent (in) :: sin2phi
code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (log1p (- u0)) (- (/ (- cos2phi) (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return log1pf(-u0) / ((-cos2phi / (alphax * alphax)) - (sin2phi / (alphay * alphay)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(log1p(Float32(-u0)) / Float32(Float32(Float32(-cos2phi) / Float32(alphax * alphax)) - Float32(sin2phi / Float32(alphay * alphay)))) end
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-u0\right)}{\frac{-cos2phi}{alphax \cdot alphax} - \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 61.9%
sub-negN/A
lower-log1p.f32N/A
lower-neg.f3298.7
Applied egg-rr98.7%
Final simplification98.7%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* u0 (fma u0 (fma u0 (fma u0 -0.25 -0.3333333333333333) -0.5) -1.0)) (- (/ (- cos2phi) (* alphax alphax)) (/ (/ sin2phi alphay) alphay))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (u0 * fmaf(u0, fmaf(u0, fmaf(u0, -0.25f, -0.3333333333333333f), -0.5f), -1.0f)) / ((-cos2phi / (alphax * alphax)) - ((sin2phi / alphay) / alphay));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(u0 * fma(u0, fma(u0, fma(u0, Float32(-0.25), Float32(-0.3333333333333333)), Float32(-0.5)), Float32(-1.0))) / Float32(Float32(Float32(-cos2phi) / Float32(alphax * alphax)) - Float32(Float32(sin2phi / alphay) / alphay))) end
\begin{array}{l}
\\
\frac{u0 \cdot \mathsf{fma}\left(u0, \mathsf{fma}\left(u0, \mathsf{fma}\left(u0, -0.25, -0.3333333333333333\right), -0.5\right), -1\right)}{\frac{-cos2phi}{alphax \cdot alphax} - \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Initial program 60.8%
Taylor expanded in u0 around 0
lower-*.f32N/A
sub-negN/A
metadata-evalN/A
lower-fma.f32N/A
sub-negN/A
metadata-evalN/A
lower-fma.f32N/A
sub-negN/A
*-commutativeN/A
metadata-evalN/A
lower-fma.f3293.0
Simplified93.0%
associate-/r*N/A
lower-/.f32N/A
lower-/.f3293.0
Applied egg-rr93.0%
Final simplification93.0%
herbie shell --seed 2024218
(FPCore (alphax alphay u0 cos2phi sin2phi)
:name "Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5"
:precision binary32
:pre (and (and (and (and (and (<= 0.0001 alphax) (<= alphax 1.0)) (and (<= 0.0001 alphay) (<= alphay 1.0))) (and (<= 2.328306437e-10 u0) (<= u0 1.0))) (and (<= 0.0 cos2phi) (<= cos2phi 1.0))) (<= 0.0 sin2phi))
(/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))