
(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 10 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 (* (pow (+ (/ 1.0 u1) -1.0) -0.5) (cos (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f / u1) + -1.0f), -0.5f) * cosf((u2 * 6.28318530718f));
}
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) + (-1.0e0)) ** (-0.5e0)) * cos((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2) return Float32((Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5)) * cos(Float32(u2 * Float32(6.28318530718)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = (((single(1.0) / u1) + single(-1.0)) ^ single(-0.5)) * cos((u2 * single(6.28318530718))); end
\begin{array}{l}
\\
{\left(\frac{1}{u1} + -1\right)}^{-0.5} \cdot \cos \left(u2 \cdot 6.28318530718\right)
\end{array}
Initial program 99.1%
add-sqr-sqrt95.3%
sqrt-unprod96.5%
swap-sqr96.5%
add-sqr-sqrt96.6%
pow296.6%
Applied egg-rr96.6%
*-lft-identity96.6%
associate-*l/96.4%
associate-/r/96.5%
associate-*l/96.4%
*-lft-identity96.4%
div-sub96.4%
sub-neg96.4%
*-inverses96.4%
metadata-eval96.4%
Simplified96.4%
Taylor expanded in u2 around inf 99.0%
*-commutative99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
inv-pow99.0%
sqrt-pow199.1%
metadata-eval99.1%
Applied egg-rr99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.0012000000569969416) (pow (+ (/ 1.0 u1) -1.0) -0.5) (* (cos (* u2 6.28318530718)) (sqrt (* u1 (+ 1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.0012000000569969416f) {
tmp = powf(((1.0f / u1) + -1.0f), -0.5f);
} else {
tmp = cosf((u2 * 6.28318530718f)) * sqrtf((u1 * (1.0f + 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 ((u2 * 6.28318530718e0) <= 0.0012000000569969416e0) then
tmp = ((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0)
else
tmp = cos((u2 * 6.28318530718e0)) * sqrt((u1 * (1.0e0 + u1)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.0012000000569969416)) tmp = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5); else tmp = Float32(cos(Float32(u2 * Float32(6.28318530718))) * sqrt(Float32(u1 * Float32(Float32(1.0) + u1)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((u2 * single(6.28318530718)) <= single(0.0012000000569969416)) tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); else tmp = cos((u2 * single(6.28318530718))) * sqrt((u1 * (single(1.0) + u1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.0012000000569969416:\\
\;\;\;\;{\left(\frac{1}{u1} + -1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.00120000006Initial program 99.5%
add-sqr-sqrt98.1%
sqrt-unprod99.5%
swap-sqr99.4%
add-sqr-sqrt99.5%
pow299.5%
Applied egg-rr99.5%
*-lft-identity99.5%
associate-*l/99.3%
associate-/r/99.4%
associate-*l/99.4%
*-lft-identity99.4%
div-sub99.3%
sub-neg99.3%
*-inverses99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in u2 around inf 99.4%
*-commutative99.4%
*-commutative99.4%
sub-neg99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in u2 around 0 98.9%
sub-neg98.9%
metadata-eval98.9%
unpow-198.9%
metadata-eval98.9%
pow-sqr99.1%
rem-sqrt-square99.1%
rem-square-sqrt97.7%
fabs-sqr97.7%
rem-square-sqrt99.1%
+-commutative99.1%
Simplified99.1%
if 0.00120000006 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 98.4%
Taylor expanded in u1 around 0 85.3%
+-commutative85.3%
Simplified85.3%
Final simplification94.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.019999999552965164) (pow (+ (/ 1.0 u1) -1.0) -0.5) (* (cos (* u2 6.28318530718)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.019999999552965164f) {
tmp = powf(((1.0f / u1) + -1.0f), -0.5f);
} else {
tmp = cosf((u2 * 6.28318530718f)) * 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 ((u2 * 6.28318530718e0) <= 0.019999999552965164e0) then
tmp = ((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0)
else
tmp = cos((u2 * 6.28318530718e0)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.019999999552965164)) tmp = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5); else tmp = Float32(cos(Float32(u2 * Float32(6.28318530718))) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((u2 * single(6.28318530718)) <= single(0.019999999552965164)) tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); else tmp = cos((u2 * single(6.28318530718))) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.019999999552965164:\\
\;\;\;\;{\left(\frac{1}{u1} + -1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.0199999996Initial program 99.4%
add-sqr-sqrt98.1%
sqrt-unprod99.4%
swap-sqr99.4%
add-sqr-sqrt99.4%
pow299.4%
Applied egg-rr99.4%
*-lft-identity99.4%
associate-*l/99.3%
associate-/r/99.3%
associate-*l/99.2%
*-lft-identity99.2%
div-sub99.2%
sub-neg99.2%
*-inverses99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in u2 around inf 99.3%
*-commutative99.3%
*-commutative99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in u2 around 0 95.8%
sub-neg95.8%
metadata-eval95.8%
unpow-195.8%
metadata-eval95.8%
pow-sqr95.9%
rem-sqrt-square95.9%
rem-square-sqrt94.8%
fabs-sqr94.8%
rem-square-sqrt95.9%
+-commutative95.9%
Simplified95.9%
if 0.0199999996 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 97.9%
Taylor expanded in u1 around 0 73.8%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((u2 * 6.28318530718f));
}
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((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * Float32(6.28318530718)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * single(6.28318530718))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot 6.28318530718\right)
\end{array}
Initial program 99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (+ (/ 1.0 u1) -1.0) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f / u1) + -1.0f), -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) + (-1.0e0)) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Initial program 99.1%
add-sqr-sqrt95.3%
sqrt-unprod96.5%
swap-sqr96.5%
add-sqr-sqrt96.6%
pow296.6%
Applied egg-rr96.6%
*-lft-identity96.6%
associate-*l/96.4%
associate-/r/96.5%
associate-*l/96.4%
*-lft-identity96.4%
div-sub96.4%
sub-neg96.4%
*-inverses96.4%
metadata-eval96.4%
Simplified96.4%
Taylor expanded in u2 around inf 99.0%
*-commutative99.0%
*-commutative99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Taylor expanded in u2 around 0 82.7%
sub-neg82.7%
metadata-eval82.7%
unpow-182.7%
metadata-eval82.7%
pow-sqr82.8%
rem-sqrt-square82.8%
rem-square-sqrt81.9%
fabs-sqr81.9%
rem-square-sqrt82.8%
+-commutative82.8%
Simplified82.8%
Final simplification82.8%
(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.1%
Taylor expanded in u2 around 0 82.7%
(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{u1 \cdot \left(1 + u1\right)}
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 82.7%
Taylor expanded in u1 around 0 72.3%
+-commutative84.7%
Simplified72.3%
Final simplification72.3%
(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.1%
Taylor expanded in u2 around 0 82.7%
Taylor expanded in u1 around 0 63.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u1 (+ 1.0 (/ 0.5 u1))))
float code(float cosTheta_i, float u1, float u2) {
return u1 * (1.0f + (0.5f / 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 = u1 * (1.0e0 + (0.5e0 / u1))
end function
function code(cosTheta_i, u1, u2) return Float32(u1 * Float32(Float32(1.0) + Float32(Float32(0.5) / u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = u1 * (single(1.0) + (single(0.5) / u1)); end
\begin{array}{l}
\\
u1 \cdot \left(1 + \frac{0.5}{u1}\right)
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 82.7%
Taylor expanded in u1 around 0 72.3%
distribute-lft-in72.4%
*-rgt-identity72.4%
unpow272.4%
Simplified72.4%
Taylor expanded in u1 around inf 21.1%
associate-*r/21.1%
metadata-eval21.1%
Simplified21.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 u1)
float code(float cosTheta_i, float u1, float u2) {
return 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 = u1
end function
function code(cosTheta_i, u1, u2) return u1 end
function tmp = code(cosTheta_i, u1, u2) tmp = u1; end
\begin{array}{l}
\\
u1
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 82.7%
Taylor expanded in u1 around 0 72.3%
distribute-lft-in72.4%
*-rgt-identity72.4%
unpow272.4%
Simplified72.4%
Taylor expanded in u1 around inf 5.4%
associate-*r/5.4%
metadata-eval5.4%
Simplified5.4%
Taylor expanded in u1 around inf 19.8%
herbie shell --seed 2024106
(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))))