
(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 6 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(Float32(-log1p(Float32(-u0))) / Float32(Float32(Float32(cos2phi / alphax) / alphax) + Float32(Float32(sin2phi / alphay) / alphay))) end
\begin{array}{l}
\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{\frac{cos2phi}{alphax}}{alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Initial program 57.6%
sqr-neg57.6%
sub-neg57.6%
log1p-def98.2%
associate-/r*98.2%
sqr-neg98.2%
Simplified98.2%
add-cube-cbrt97.3%
times-frac97.4%
pow297.4%
Applied egg-rr97.4%
frac-times97.3%
unpow297.3%
add-cube-cbrt98.2%
associate-/r*98.3%
Applied egg-rr98.3%
Final simplification98.3%
(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(Float32(-log1p(Float32(-u0))) / 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 57.6%
sub-neg57.6%
log1p-def98.2%
Simplified98.2%
Final simplification98.2%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* alphax (* (- u0) alphay)) (- (/ (* alphax (- sin2phi)) alphay) (/ (* cos2phi alphay) alphax))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (alphax * (-u0 * alphay)) / (((alphax * -sin2phi) / alphay) - ((cos2phi * alphay) / alphax));
}
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 = (alphax * (-u0 * alphay)) / (((alphax * -sin2phi) / alphay) - ((cos2phi * alphay) / alphax))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(alphax * Float32(Float32(-u0) * alphay)) / Float32(Float32(Float32(alphax * Float32(-sin2phi)) / alphay) - Float32(Float32(cos2phi * alphay) / alphax))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (alphax * (-u0 * alphay)) / (((alphax * -sin2phi) / alphay) - ((cos2phi * alphay) / alphax)); end
\begin{array}{l}
\\
\frac{alphax \cdot \left(\left(-u0\right) \cdot alphay\right)}{\frac{alphax \cdot \left(-sin2phi\right)}{alphay} - \frac{cos2phi \cdot alphay}{alphax}}
\end{array}
Initial program 57.6%
sub-neg57.6%
log1p-def98.2%
Simplified98.2%
associate-/r*98.2%
associate-/r*98.3%
frac-2neg98.3%
frac-add98.0%
distribute-neg-frac98.0%
Applied egg-rr98.0%
+-commutative98.0%
*-commutative98.0%
*-commutative98.0%
fma-def98.0%
associate-*r/98.1%
*-commutative98.1%
Simplified98.1%
Taylor expanded in u0 around 0 77.3%
Final simplification77.3%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (* (/ u0 (+ (/ (* alphax sin2phi) alphay) (* (/ cos2phi alphax) alphay))) (* alphax alphay)))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (u0 / (((alphax * sin2phi) / alphay) + ((cos2phi / alphax) * alphay))) * (alphax * 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 / (((alphax * sin2phi) / alphay) + ((cos2phi / alphax) * alphay))) * (alphax * alphay)
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(u0 / Float32(Float32(Float32(alphax * sin2phi) / alphay) + Float32(Float32(cos2phi / alphax) * alphay))) * Float32(alphax * alphay)) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (u0 / (((alphax * sin2phi) / alphay) + ((cos2phi / alphax) * alphay))) * (alphax * alphay); end
\begin{array}{l}
\\
\frac{u0}{\frac{alphax \cdot sin2phi}{alphay} + \frac{cos2phi}{alphax} \cdot alphay} \cdot \left(alphax \cdot alphay\right)
\end{array}
Initial program 57.6%
Taylor expanded in u0 around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
associate-/r*77.0%
div-inv77.0%
Applied egg-rr77.0%
div-inv77.0%
associate-/r*77.0%
frac-add76.9%
associate-/r/77.1%
add-sqr-sqrt77.0%
sqrt-unprod77.1%
sqr-neg77.1%
sqrt-unprod-0.0%
add-sqr-sqrt13.3%
Applied egg-rr77.1%
Final simplification77.1%
(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 57.6%
Taylor expanded in u0 around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
Final simplification77.0%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ u0 (+ (/ (/ sin2phi alphay) alphay) (/ cos2phi (* alphax alphax)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return u0 / (((sin2phi / alphay) / alphay) + (cos2phi / (alphax * alphax)));
}
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 / (((sin2phi / alphay) / alphay) + (cos2phi / (alphax * alphax)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(u0 / Float32(Float32(Float32(sin2phi / alphay) / alphay) + Float32(cos2phi / Float32(alphax * alphax)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = u0 / (((sin2phi / alphay) / alphay) + (cos2phi / (alphax * alphax))); end
\begin{array}{l}
\\
\frac{u0}{\frac{\frac{sin2phi}{alphay}}{alphay} + \frac{cos2phi}{alphax \cdot alphax}}
\end{array}
Initial program 57.6%
Taylor expanded in u0 around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
add-sqr-sqrt76.9%
times-frac76.9%
Applied egg-rr76.9%
unpow276.9%
Simplified76.9%
unpow276.9%
times-frac76.9%
add-sqr-sqrt77.0%
associate-/r*77.0%
Applied egg-rr77.0%
Final simplification77.0%
herbie shell --seed 2023301
(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)))))