
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 16 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
code = sqrt((u1 / (1.0e0 - u1))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
Initial program 99.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (sqrt (/ u1 (- 1.0 u1)))))
(if (<= (* t_0 (cos (* 6.28318530718 u2))) 0.0005000000237487257)
(* (sqrt u1) (fma -19.739208802181317 (* u2 u2) 1.0))
t_0)))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = sqrtf((u1 / (1.0f - u1)));
float tmp;
if ((t_0 * cosf((6.28318530718f * u2))) <= 0.0005000000237487257f) {
tmp = sqrtf(u1) * fmaf(-19.739208802181317f, (u2 * u2), 1.0f);
} else {
tmp = t_0;
}
return tmp;
}
function code(cosTheta_i, u1, u2) t_0 = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) tmp = Float32(0.0) if (Float32(t_0 * cos(Float32(Float32(6.28318530718) * u2))) <= Float32(0.0005000000237487257)) tmp = Float32(sqrt(u1) * fma(Float32(-19.739208802181317), Float32(u2 * u2), Float32(1.0))); else tmp = t_0; end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\frac{u1}{1 - u1}}\\
\mathbf{if}\;t\_0 \cdot \cos \left(6.28318530718 \cdot u2\right) \leq 0.0005000000237487257:\\
\;\;\;\;\sqrt{u1} \cdot \mathsf{fma}\left(-19.739208802181317, u2 \cdot u2, 1\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (*.f32 (sqrt.f32 (/.f32 u1 (-.f32 #s(literal 1 binary32) u1))) (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))) < 5.00000024e-4Initial program 98.7%
Taylor expanded in u2 around 0
*-rgt-identityN/A
sub-negN/A
rgt-mult-inverseN/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
sub-negN/A
associate-*r*N/A
lower-sqrt.f32N/A
*-rgt-identityN/A
lower-/.f32N/A
associate-*r*N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites72.3%
Taylor expanded in u2 around 0
associate-*r*N/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f32N/A
lower-sqrt.f32N/A
sub-negN/A
mul-1-negN/A
lower-/.f32N/A
mul-1-negN/A
sub-negN/A
lower--.f32N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
lower-sqrt.f32N/A
sub-negN/A
mul-1-negN/A
lower-/.f32N/A
Applied rewrites81.9%
Taylor expanded in u1 around 0
Applied rewrites81.6%
if 5.00000024e-4 < (*.f32 (sqrt.f32 (/.f32 u1 (-.f32 #s(literal 1 binary32) u1))) (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2))) Initial program 99.1%
Taylor expanded in u2 around 0
*-rgt-identityN/A
sub-negN/A
rgt-mult-inverseN/A
mul-1-negN/A
distribute-neg-frac2N/A
mul-1-negN/A
*-rgt-identityN/A
distribute-lft-inN/A
+-commutativeN/A
sub-negN/A
associate-*r*N/A
lower-sqrt.f32N/A
*-rgt-identityN/A
lower-/.f32N/A
associate-*r*N/A
sub-negN/A
+-commutativeN/A
distribute-lft-inN/A
Applied rewrites84.1%
herbie shell --seed 2024230
(FPCore (cosTheta_i u1 u2)
:name "Trowbridge-Reitz Sample, near normal, slope_x"
:precision binary32
:pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
(* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))