
(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 10 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 / alphay) / Float32(-alphay)) - Float32(cos2phi / Float32(alphax * alphax)))) end
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-u0\right)}{\frac{\frac{sin2phi}{alphay}}{-alphay} - \frac{cos2phi}{alphax \cdot alphax}}
\end{array}
Initial program 60.6%
distribute-frac-neg60.6%
distribute-neg-frac260.6%
neg-mul-160.6%
associate-/r*60.6%
metadata-eval60.6%
distribute-neg-frac260.6%
/-rgt-identity60.6%
sub-neg60.6%
log1p-define98.7%
Simplified98.7%
associate-/r*98.7%
div-inv98.7%
Applied egg-rr98.7%
associate-*r/98.7%
*-rgt-identity98.7%
Simplified98.7%
Final simplification98.7%
(FPCore (alphax alphay u0 cos2phi sin2phi)
:precision binary32
(let* ((t_0 (/ sin2phi (* alphay alphay))))
(if (<= t_0 10000.0)
(/
(* u0 (+ (* u0 (+ 0.5 (* u0 (+ 0.3333333333333333 (* u0 0.25))))) 1.0))
(+ (/ cos2phi (* alphax alphax)) t_0))
(/
(log1p (- u0))
(- (/ (/ cos2phi alphax) alphax) (/ (/ sin2phi alphay) alphay))))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
float t_0 = sin2phi / (alphay * alphay);
float tmp;
if (t_0 <= 10000.0f) {
tmp = (u0 * ((u0 * (0.5f + (u0 * (0.3333333333333333f + (u0 * 0.25f))))) + 1.0f)) / ((cos2phi / (alphax * alphax)) + t_0);
} else {
tmp = log1pf(-u0) / (((cos2phi / alphax) / alphax) - ((sin2phi / alphay) / alphay));
}
return tmp;
}
function code(alphax, alphay, u0, cos2phi, sin2phi) t_0 = Float32(sin2phi / Float32(alphay * alphay)) tmp = Float32(0.0) if (t_0 <= Float32(10000.0)) tmp = Float32(Float32(u0 * Float32(Float32(u0 * Float32(Float32(0.5) + Float32(u0 * Float32(Float32(0.3333333333333333) + Float32(u0 * Float32(0.25)))))) + Float32(1.0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + t_0)); else tmp = Float32(log1p(Float32(-u0)) / Float32(Float32(Float32(cos2phi / alphax) / alphax) - Float32(Float32(sin2phi / alphay) / alphay))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{sin2phi}{alphay \cdot alphay}\\
\mathbf{if}\;t\_0 \leq 10000:\\
\;\;\;\;\frac{u0 \cdot \left(u0 \cdot \left(0.5 + u0 \cdot \left(0.3333333333333333 + u0 \cdot 0.25\right)\right) + 1\right)}{\frac{cos2phi}{alphax \cdot alphax} + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(-u0\right)}{\frac{\frac{cos2phi}{alphax}}{alphax} - \frac{\frac{sin2phi}{alphay}}{alphay}}\\
\end{array}
\end{array}
if (/.f32 sin2phi (*.f32 alphay alphay)) < 1e4Initial program 54.0%
Taylor expanded in u0 around 0 94.8%
*-commutative94.8%
Simplified94.8%
if 1e4 < (/.f32 sin2phi (*.f32 alphay alphay)) Initial program 66.8%
distribute-frac-neg66.8%
distribute-neg-frac266.8%
sub-neg66.8%
log1p-define98.7%
neg-sub098.7%
associate--r+98.7%
neg-sub098.7%
associate-/r*98.7%
distribute-neg-frac298.7%
Simplified98.7%
add-sqr-sqrt-0.0%
sqrt-unprod98.7%
sqr-neg98.7%
sqrt-prod98.7%
add-sqr-sqrt98.7%
div-inv98.7%
Applied egg-rr98.7%
associate-*r/98.7%
*-rgt-identity98.7%
Simplified98.7%
associate-/r*98.9%
div-inv98.7%
Applied egg-rr98.7%
associate-*r/98.9%
*-rgt-identity98.9%
Simplified98.9%
Final simplification96.9%
(FPCore (alphax alphay u0 cos2phi sin2phi)
:precision binary32
(let* ((t_0 (/ sin2phi (* alphay alphay))))
(if (<= t_0 10000.0)
(/
(* u0 (+ (* u0 (+ 0.5 (* u0 (+ 0.3333333333333333 (* u0 0.25))))) 1.0))
(+ (/ cos2phi (* alphax alphax)) t_0))
(/ (log1p (- u0)) (- (/ (/ cos2phi alphax) alphax) t_0)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
float t_0 = sin2phi / (alphay * alphay);
float tmp;
if (t_0 <= 10000.0f) {
tmp = (u0 * ((u0 * (0.5f + (u0 * (0.3333333333333333f + (u0 * 0.25f))))) + 1.0f)) / ((cos2phi / (alphax * alphax)) + t_0);
} else {
tmp = log1pf(-u0) / (((cos2phi / alphax) / alphax) - t_0);
}
return tmp;
}
function code(alphax, alphay, u0, cos2phi, sin2phi) t_0 = Float32(sin2phi / Float32(alphay * alphay)) tmp = Float32(0.0) if (t_0 <= Float32(10000.0)) tmp = Float32(Float32(u0 * Float32(Float32(u0 * Float32(Float32(0.5) + Float32(u0 * Float32(Float32(0.3333333333333333) + Float32(u0 * Float32(0.25)))))) + Float32(1.0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + t_0)); else tmp = Float32(log1p(Float32(-u0)) / Float32(Float32(Float32(cos2phi / alphax) / alphax) - t_0)); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{sin2phi}{alphay \cdot alphay}\\
\mathbf{if}\;t\_0 \leq 10000:\\
\;\;\;\;\frac{u0 \cdot \left(u0 \cdot \left(0.5 + u0 \cdot \left(0.3333333333333333 + u0 \cdot 0.25\right)\right) + 1\right)}{\frac{cos2phi}{alphax \cdot alphax} + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{log1p}\left(-u0\right)}{\frac{\frac{cos2phi}{alphax}}{alphax} - t\_0}\\
\end{array}
\end{array}
if (/.f32 sin2phi (*.f32 alphay alphay)) < 1e4Initial program 54.0%
Taylor expanded in u0 around 0 94.8%
*-commutative94.8%
Simplified94.8%
if 1e4 < (/.f32 sin2phi (*.f32 alphay alphay)) Initial program 66.8%
distribute-frac-neg66.8%
distribute-neg-frac266.8%
sub-neg66.8%
log1p-define98.7%
neg-sub098.7%
associate--r+98.7%
neg-sub098.7%
associate-/r*98.7%
distribute-neg-frac298.7%
Simplified98.7%
add-sqr-sqrt-0.0%
sqrt-unprod98.7%
sqr-neg98.7%
sqrt-prod98.7%
add-sqr-sqrt98.7%
div-inv98.7%
Applied egg-rr98.7%
associate-*r/98.7%
*-rgt-identity98.7%
Simplified98.7%
Final simplification96.8%
(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(sin2phi / Float32(alphay * Float32(-alphay))) - Float32(cos2phi / Float32(alphax * alphax)))) end
\begin{array}{l}
\\
\frac{\mathsf{log1p}\left(-u0\right)}{\frac{sin2phi}{alphay \cdot \left(-alphay\right)} - \frac{cos2phi}{alphax \cdot alphax}}
\end{array}
Initial program 60.6%
distribute-frac-neg60.6%
distribute-neg-frac260.6%
neg-mul-160.6%
associate-/r*60.6%
metadata-eval60.6%
distribute-neg-frac260.6%
/-rgt-identity60.6%
sub-neg60.6%
log1p-define98.7%
Simplified98.7%
Final simplification98.7%
(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 / alphax) / Float32(-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 60.6%
distribute-frac-neg60.6%
distribute-neg-frac260.6%
sub-neg60.6%
log1p-define98.7%
neg-sub098.7%
associate--r+98.7%
neg-sub098.7%
associate-/r*98.7%
distribute-neg-frac298.7%
Simplified98.7%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* u0 (+ (* u0 (+ 0.5 (* u0 (+ 0.3333333333333333 (* u0 0.25))))) 1.0)) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (u0 * ((u0 * (0.5f + (u0 * (0.3333333333333333f + (u0 * 0.25f))))) + 1.0f)) / ((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 * ((u0 * (0.5e0 + (u0 * (0.3333333333333333e0 + (u0 * 0.25e0))))) + 1.0e0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(u0 * Float32(Float32(u0 * Float32(Float32(0.5) + Float32(u0 * Float32(Float32(0.3333333333333333) + Float32(u0 * Float32(0.25)))))) + Float32(1.0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (u0 * ((u0 * (single(0.5) + (u0 * (single(0.3333333333333333) + (u0 * single(0.25)))))) + single(1.0))) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{u0 \cdot \left(u0 \cdot \left(0.5 + u0 \cdot \left(0.3333333333333333 + u0 \cdot 0.25\right)\right) + 1\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 60.6%
Taylor expanded in u0 around 0 93.3%
*-commutative93.3%
Simplified93.3%
Final simplification93.3%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* u0 (+ (* u0 (+ 0.5 (* u0 0.3333333333333333))) 1.0)) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (u0 * ((u0 * (0.5f + (u0 * 0.3333333333333333f))) + 1.0f)) / ((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 * ((u0 * (0.5e0 + (u0 * 0.3333333333333333e0))) + 1.0e0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(u0 * Float32(Float32(u0 * Float32(Float32(0.5) + Float32(u0 * Float32(0.3333333333333333)))) + Float32(1.0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (u0 * ((u0 * (single(0.5) + (u0 * single(0.3333333333333333)))) + single(1.0))) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{u0 \cdot \left(u0 \cdot \left(0.5 + u0 \cdot 0.3333333333333333\right) + 1\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 60.6%
Taylor expanded in u0 around 0 91.8%
*-commutative91.8%
Simplified91.8%
Final simplification91.8%
(FPCore (alphax alphay u0 cos2phi sin2phi) :precision binary32 (/ (* u0 (+ (* u0 0.5) 1.0)) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
return (u0 * ((u0 * 0.5f) + 1.0f)) / ((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 * ((u0 * 0.5e0) + 1.0e0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi) return Float32(Float32(u0 * Float32(Float32(u0 * Float32(0.5)) + Float32(1.0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay)))) end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi) tmp = (u0 * ((u0 * single(0.5)) + single(1.0))) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay))); end
\begin{array}{l}
\\
\frac{u0 \cdot \left(u0 \cdot 0.5 + 1\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Initial program 60.6%
Taylor expanded in u0 around 0 88.0%
*-commutative88.0%
Simplified88.0%
Final simplification88.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(sin2phi / Float32(alphay * alphay)) + Float32(Float32(cos2phi / 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{sin2phi}{alphay \cdot alphay} + \frac{\frac{cos2phi}{alphax}}{alphax}}
\end{array}
Initial program 60.6%
distribute-frac-neg60.6%
distribute-neg-frac260.6%
sub-neg60.6%
log1p-define98.7%
neg-sub098.7%
associate--r+98.7%
neg-sub098.7%
associate-/r*98.7%
distribute-neg-frac298.7%
Simplified98.7%
Taylor expanded in u0 around 0 77.1%
mul-1-neg77.1%
Simplified77.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 60.6%
Taylor expanded in u0 around 0 77.1%
herbie shell --seed 2024170
(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)))))