
(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 8 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%
Final simplification99.2%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (* 6.28318530718 u2) 0.07999999821186066)
(*
(+ 1.0 (* u2 (* u2 -19.739208802181317)))
(sqrt (/ 1.0 (+ -1.0 (/ 1.0 u1)))))
(* (cos (* 6.28318530718 u2)) (sqrt (+ u1 (* u1 u1))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.07999999821186066f) {
tmp = (1.0f + (u2 * (u2 * -19.739208802181317f))) * sqrtf((1.0f / (-1.0f + (1.0f / u1))));
} else {
tmp = cosf((6.28318530718f * u2)) * sqrtf((u1 + (u1 * u1)));
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: tmp
if ((6.28318530718e0 * u2) <= 0.07999999821186066e0) then
tmp = (1.0e0 + (u2 * (u2 * (-19.739208802181317e0)))) * sqrt((1.0e0 / ((-1.0e0) + (1.0e0 / u1))))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt((u1 + (u1 * u1)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.07999999821186066)) tmp = Float32(Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))) * sqrt(Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(1.0) / u1))))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(Float32(u1 + Float32(u1 * u1)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.07999999821186066)) tmp = (single(1.0) + (u2 * (u2 * single(-19.739208802181317)))) * sqrt((single(1.0) / (single(-1.0) + (single(1.0) / u1)))); else tmp = cos((single(6.28318530718) * u2)) * sqrt((u1 + (u1 * u1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.07999999821186066:\\
\;\;\;\;\left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right) \cdot \sqrt{\frac{1}{-1 + \frac{1}{u1}}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1 + u1 \cdot u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0799999982Initial program 99.4%
pow1/299.4%
clear-num99.4%
inv-pow99.4%
pow-pow99.5%
div-sub99.4%
pow199.4%
pow199.4%
pow-div99.4%
metadata-eval99.4%
metadata-eval99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in u2 around 0 99.2%
associate-*r*99.2%
distribute-lft1-in99.2%
*-commutative99.2%
unpow299.2%
associate-*l*99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
if 0.0799999982 < (*.f32 314159265359/50000000000 u2) Initial program 97.6%
Taylor expanded in u1 around 0 90.3%
unpow290.3%
unpow390.3%
unpow290.3%
distribute-lft1-in90.3%
distribute-rgt-in90.1%
associate-+l+90.1%
+-commutative90.1%
unpow290.1%
fma-udef90.1%
+-commutative90.1%
distribute-rgt-in90.3%
*-lft-identity90.3%
Simplified90.3%
Taylor expanded in u1 around 0 83.4%
unpow283.4%
Simplified83.4%
Final simplification96.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(if (<= (* 6.28318530718 u2) 0.0949999988079071)
(*
(+ 1.0 (* u2 (* u2 -19.739208802181317)))
(sqrt (/ 1.0 (+ -1.0 (/ 1.0 u1)))))
(* (cos (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.0949999988079071f) {
tmp = (1.0f + (u2 * (u2 * -19.739208802181317f))) * sqrtf((1.0f / (-1.0f + (1.0f / u1))));
} else {
tmp = cosf((6.28318530718f * u2)) * sqrtf(u1);
}
return tmp;
}
real(4) function code(costheta_i, u1, u2)
real(4), intent (in) :: costheta_i
real(4), intent (in) :: u1
real(4), intent (in) :: u2
real(4) :: tmp
if ((6.28318530718e0 * u2) <= 0.0949999988079071e0) then
tmp = (1.0e0 + (u2 * (u2 * (-19.739208802181317e0)))) * sqrt((1.0e0 / ((-1.0e0) + (1.0e0 / u1))))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.0949999988079071)) tmp = Float32(Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))) * sqrt(Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(1.0) / u1))))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.0949999988079071)) tmp = (single(1.0) + (u2 * (u2 * single(-19.739208802181317)))) * sqrt((single(1.0) / (single(-1.0) + (single(1.0) / u1)))); else tmp = cos((single(6.28318530718) * u2)) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.0949999988079071:\\
\;\;\;\;\left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right) \cdot \sqrt{\frac{1}{-1 + \frac{1}{u1}}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0949999988Initial program 99.5%
pow1/299.5%
clear-num99.4%
inv-pow99.4%
pow-pow99.5%
div-sub99.4%
pow199.4%
pow199.4%
pow-div99.4%
metadata-eval99.4%
metadata-eval99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Taylor expanded in u2 around 0 99.1%
associate-*r*99.1%
distribute-lft1-in99.1%
*-commutative99.1%
unpow299.1%
associate-*l*99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
if 0.0949999988 < (*.f32 314159265359/50000000000 u2) Initial program 97.5%
Taylor expanded in u1 around 0 68.9%
Final simplification94.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (+ 1.0 (* u2 (* u2 -19.739208802181317))) (sqrt (/ 1.0 (+ -1.0 (/ 1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
return (1.0f + (u2 * (u2 * -19.739208802181317f))) * sqrtf((1.0f / (-1.0f + (1.0f / u1))));
}
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 = (1.0e0 + (u2 * (u2 * (-19.739208802181317e0)))) * sqrt((1.0e0 / ((-1.0e0) + (1.0e0 / u1))))
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))) * sqrt(Float32(Float32(1.0) / Float32(Float32(-1.0) + Float32(Float32(1.0) / u1))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = (single(1.0) + (u2 * (u2 * single(-19.739208802181317)))) * sqrt((single(1.0) / (single(-1.0) + (single(1.0) / u1)))); end
\begin{array}{l}
\\
\left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right) \cdot \sqrt{\frac{1}{-1 + \frac{1}{u1}}}
\end{array}
Initial program 99.2%
pow1/299.2%
clear-num99.1%
inv-pow99.1%
pow-pow99.1%
div-sub99.1%
pow199.1%
pow199.1%
pow-div99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Taylor expanded in u2 around 0 90.2%
associate-*r*90.2%
distribute-lft1-in90.2%
*-commutative90.2%
unpow290.2%
associate-*l*90.2%
sub-neg90.2%
metadata-eval90.2%
+-commutative90.2%
Simplified90.2%
Final simplification90.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (+ -1.0 (/ 1.0 u1)) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return powf((-1.0f + (1.0f / u1)), -0.5f);
}
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 = ((-1.0e0) + (1.0e0 / u1)) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(-1.0) + Float32(Float32(1.0) / u1)) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = (single(-1.0) + (single(1.0) / u1)) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(-1 + \frac{1}{u1}\right)}^{-0.5}
\end{array}
Initial program 99.2%
pow1/299.2%
clear-num99.1%
inv-pow99.1%
pow-pow99.1%
div-sub99.1%
pow199.1%
pow199.1%
pow-div99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Taylor expanded in u2 around 0 84.0%
inv-pow84.0%
sqrt-pow184.0%
sub-neg84.0%
metadata-eval84.0%
metadata-eval84.0%
Applied egg-rr84.0%
Final simplification84.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (/ (- 1.0 u1) u1) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f - u1) / u1), -0.5f);
}
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 = ((1.0e0 - u1) / u1) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = ((single(1.0) - u1) / u1) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(\frac{1 - u1}{u1}\right)}^{-0.5}
\end{array}
Initial program 99.2%
pow1/299.2%
clear-num99.1%
inv-pow99.1%
pow-pow99.1%
div-sub99.1%
pow199.1%
pow199.1%
pow-div99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Taylor expanded in u2 around 0 84.0%
expm1-log1p-u83.9%
expm1-udef70.4%
inv-pow70.4%
sqrt-pow170.4%
sub-neg70.4%
metadata-eval70.4%
metadata-eval70.4%
Applied egg-rr70.4%
expm1-def83.9%
expm1-log1p84.0%
metadata-eval84.0%
*-inverses84.0%
sub-neg84.0%
div-sub84.0%
Simplified84.0%
Final simplification84.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (/ u1 (- 1.0 u1))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1)));
}
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)))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0 84.0%
Final simplification84.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt u1))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(u1);
}
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)
end function
function code(cosTheta_i, u1, u2) return sqrt(u1) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(u1); end
\begin{array}{l}
\\
\sqrt{u1}
\end{array}
Initial program 99.2%
pow1/299.2%
clear-num99.1%
inv-pow99.1%
pow-pow99.1%
div-sub99.1%
pow199.1%
pow199.1%
pow-div99.1%
metadata-eval99.1%
metadata-eval99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Taylor expanded in u1 around 0 72.9%
Taylor expanded in u2 around 0 65.2%
Final simplification65.2%
herbie shell --seed 2023187
(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))))