
(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 4 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)) (- (/ (- sin2phi) (* alphay alphay)) (/ cos2phi (* alphax alphax)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return log1pf(-u0) / ((-sin2phi / (alphay * alphay)) - (cos2phi / (alphax * alphax)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(log1p(Float32(-u0)) / Float32(Float32(Float32(-sin2phi) / Float32(alphay * alphay)) - Float32(cos2phi / Float32(alphax * alphax)))) end
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-u0\right)}{\frac{-sin2phi}{alphay \cdot alphay} - \frac{cos2phi}{alphax \cdot alphax}}
\end{array}
Initial program 61.0%
distribute-frac-neg61.0%
distribute-neg-frac261.0%
neg-mul-161.0%
associate-/r*61.0%
remove-double-neg61.0%
distribute-frac-neg61.0%
distribute-neg-frac261.0%
metadata-eval61.0%
/-rgt-identity61.0%
sub-neg61.0%
log1p-define98.5%
Simplified98.5%
Final simplification98.5%
(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(Float32(-cos2phi) / alphax) / alphax) - Float32(sin2phi / Float32(alphay * alphay)))) end
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-u0\right)}{\frac{\frac{-cos2phi}{alphax}}{alphax} - \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 61.0%
distribute-frac-neg61.0%
distribute-neg-frac261.0%
sub-neg61.0%
log1p-define98.5%
neg-sub098.5%
associate--r+98.5%
neg-sub098.5%
associate-/r*98.4%
distribute-neg-frac298.4%
Simplified98.4%
Final simplification98.4%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ u0 (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return 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 = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 61.0%
Taylor expanded in u0 around 0 73.3%
mul-1-neg73.3%
Simplified73.3%
Final simplification73.3%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ 1.0 (/ (/ (/ sin2phi alphay) alphay) u0)))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return 1.0f / (((sin2phi / alphay) / alphay) / u0);
}
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 = 1.0e0 / (((sin2phi / alphay) / alphay) / u0)
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(1.0) / Float32(Float32(Float32(sin2phi / alphay) / alphay) / u0)) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = single(1.0) / (((sin2phi / alphay) / alphay) / u0); end
\begin{array}{l}
\\
\frac{1}{\frac{\frac{\frac{sin2phi}{alphay}}{alphay}}{u0}}
\end{array}
Initial program 61.0%
distribute-frac-neg61.0%
distribute-neg-frac261.0%
sub-neg61.0%
log1p-define98.5%
neg-sub098.5%
associate--r+98.5%
neg-sub098.5%
associate-/r*98.4%
distribute-neg-frac298.4%
Simplified98.4%
sub-neg98.4%
distribute-frac-neg298.4%
associate-/r*98.5%
distribute-neg-in98.5%
distribute-frac-neg298.5%
distribute-frac-neg98.5%
clear-num96.7%
inv-pow96.7%
Applied egg-rr69.8%
unpow-169.8%
fma-define69.8%
+-commutative69.8%
fma-define69.8%
Simplified69.8%
Taylor expanded in cos2phi around 0 34.2%
log1p-define54.3%
associate-/r*54.2%
Simplified54.2%
Taylor expanded in u0 around 0 55.5%
unpow255.5%
associate-/l/55.4%
div-inv55.4%
Applied egg-rr55.4%
associate-*r/55.4%
*-rgt-identity55.4%
Simplified55.4%
Final simplification55.4%
herbie shell --seed 2024043
(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)))))