
(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.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* 6.28318530718 u2))) (t_1 (+ (/ 1.0 u1) -1.0)))
(if (<= t_0 0.999019980430603)
(* t_0 (sqrt (* u1 (+ u1 1.0))))
(sqrt (+ (* -39.47841760436263 (* u2 (/ u2 t_1))) (/ 1.0 t_1))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((6.28318530718f * u2));
float t_1 = (1.0f / u1) + -1.0f;
float tmp;
if (t_0 <= 0.999019980430603f) {
tmp = t_0 * sqrtf((u1 * (u1 + 1.0f)));
} else {
tmp = sqrtf(((-39.47841760436263f * (u2 * (u2 / t_1))) + (1.0f / t_1)));
}
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) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = cos((6.28318530718e0 * u2))
t_1 = (1.0e0 / u1) + (-1.0e0)
if (t_0 <= 0.999019980430603e0) then
tmp = t_0 * sqrt((u1 * (u1 + 1.0e0)))
else
tmp = sqrt((((-39.47841760436263e0) * (u2 * (u2 / t_1))) + (1.0e0 / t_1)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(Float32(6.28318530718) * u2)) t_1 = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) tmp = Float32(0.0) if (t_0 <= Float32(0.999019980430603)) tmp = Float32(t_0 * sqrt(Float32(u1 * Float32(u1 + Float32(1.0))))); else tmp = sqrt(Float32(Float32(Float32(-39.47841760436263) * Float32(u2 * Float32(u2 / t_1))) + Float32(Float32(1.0) / t_1))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((single(6.28318530718) * u2)); t_1 = (single(1.0) / u1) + single(-1.0); tmp = single(0.0); if (t_0 <= single(0.999019980430603)) tmp = t_0 * sqrt((u1 * (u1 + single(1.0)))); else tmp = sqrt(((single(-39.47841760436263) * (u2 * (u2 / t_1))) + (single(1.0) / t_1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(6.28318530718 \cdot u2\right)\\
t_1 := \frac{1}{u1} + -1\\
\mathbf{if}\;t\_0 \leq 0.999019980430603:\\
\;\;\;\;t\_0 \cdot \sqrt{u1 \cdot \left(u1 + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-39.47841760436263 \cdot \left(u2 \cdot \frac{u2}{t\_1}\right) + \frac{1}{t\_1}}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.99901998Initial program 98.2%
Taylor expanded in u1 around 0 86.9%
+-commutative34.4%
Simplified86.9%
if 0.99901998 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) Initial program 99.5%
add-sqr-sqrt98.2%
sqrt-unprod99.5%
swap-sqr99.4%
add-sqr-sqrt99.6%
pow299.6%
Applied egg-rr99.6%
*-lft-identity99.6%
associate-*l/99.3%
associate-/r/99.3%
associate-*l/99.3%
*-lft-identity99.3%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in u2 around 0 98.8%
unpow298.8%
associate-/l*98.8%
sub-neg98.8%
metadata-eval98.8%
Applied egg-rr98.8%
Final simplification95.8%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (+ (/ 1.0 u1) -1.0)) (t_1 (cos (* 6.28318530718 u2))))
(if (<= t_1 0.9869999885559082)
(* t_1 (sqrt u1))
(sqrt (+ (* -39.47841760436263 (* u2 (/ u2 t_0))) (/ 1.0 t_0))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = (1.0f / u1) + -1.0f;
float t_1 = cosf((6.28318530718f * u2));
float tmp;
if (t_1 <= 0.9869999885559082f) {
tmp = t_1 * sqrtf(u1);
} else {
tmp = sqrtf(((-39.47841760436263f * (u2 * (u2 / t_0))) + (1.0f / t_0)));
}
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) :: t_0
real(4) :: t_1
real(4) :: tmp
t_0 = (1.0e0 / u1) + (-1.0e0)
t_1 = cos((6.28318530718e0 * u2))
if (t_1 <= 0.9869999885559082e0) then
tmp = t_1 * sqrt(u1)
else
tmp = sqrt((((-39.47841760436263e0) * (u2 * (u2 / t_0))) + (1.0e0 / t_0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) t_1 = cos(Float32(Float32(6.28318530718) * u2)) tmp = Float32(0.0) if (t_1 <= Float32(0.9869999885559082)) tmp = Float32(t_1 * sqrt(u1)); else tmp = sqrt(Float32(Float32(Float32(-39.47841760436263) * Float32(u2 * Float32(u2 / t_0))) + Float32(Float32(1.0) / t_0))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = (single(1.0) / u1) + single(-1.0); t_1 = cos((single(6.28318530718) * u2)); tmp = single(0.0); if (t_1 <= single(0.9869999885559082)) tmp = t_1 * sqrt(u1); else tmp = sqrt(((single(-39.47841760436263) * (u2 * (u2 / t_0))) + (single(1.0) / t_0))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{u1} + -1\\
t_1 := \cos \left(6.28318530718 \cdot u2\right)\\
\mathbf{if}\;t\_1 \leq 0.9869999885559082:\\
\;\;\;\;t\_1 \cdot \sqrt{u1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{-39.47841760436263 \cdot \left(u2 \cdot \frac{u2}{t\_0}\right) + \frac{1}{t\_0}}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.986999989Initial program 97.9%
Taylor expanded in u1 around 0 76.8%
if 0.986999989 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) Initial program 99.4%
add-sqr-sqrt98.2%
sqrt-unprod99.4%
swap-sqr99.4%
add-sqr-sqrt99.6%
pow299.6%
Applied egg-rr99.6%
*-lft-identity99.6%
associate-*l/99.3%
associate-/r/99.2%
associate-*l/99.2%
*-lft-identity99.2%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
Taylor expanded in u2 around 0 97.4%
unpow297.4%
associate-/l*97.4%
sub-neg97.4%
metadata-eval97.4%
Applied egg-rr97.4%
Final simplification93.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (let* ((t_0 (+ (/ 1.0 u1) -1.0))) (sqrt (+ (* -39.47841760436263 (* u2 (/ u2 t_0))) (/ 1.0 t_0)))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = (1.0f / u1) + -1.0f;
return sqrtf(((-39.47841760436263f * (u2 * (u2 / t_0))) + (1.0f / t_0)));
}
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) :: t_0
t_0 = (1.0e0 / u1) + (-1.0e0)
code = sqrt((((-39.47841760436263e0) * (u2 * (u2 / t_0))) + (1.0e0 / t_0)))
end function
function code(cosTheta_i, u1, u2) t_0 = Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) return sqrt(Float32(Float32(Float32(-39.47841760436263) * Float32(u2 * Float32(u2 / t_0))) + Float32(Float32(1.0) / t_0))) end
function tmp = code(cosTheta_i, u1, u2) t_0 = (single(1.0) / u1) + single(-1.0); tmp = sqrt(((single(-39.47841760436263) * (u2 * (u2 / t_0))) + (single(1.0) / t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{u1} + -1\\
\sqrt{-39.47841760436263 \cdot \left(u2 \cdot \frac{u2}{t\_0}\right) + \frac{1}{t\_0}}
\end{array}
\end{array}
Initial program 99.1%
add-sqr-sqrt93.9%
sqrt-unprod95.2%
swap-sqr95.1%
add-sqr-sqrt95.2%
pow295.2%
Applied egg-rr95.2%
*-lft-identity95.2%
associate-*l/95.0%
associate-/r/95.0%
associate-*l/95.0%
*-lft-identity95.0%
div-sub94.9%
sub-neg94.9%
*-inverses94.9%
metadata-eval94.9%
Simplified94.9%
Taylor expanded in u2 around 0 85.0%
unpow285.0%
associate-/l*85.0%
sub-neg85.0%
metadata-eval85.0%
Applied egg-rr85.0%
Final simplification85.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* u1 (+ u1 1.0))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 * (u1 + 1.0f)));
}
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 * (u1 + 1.0e0)))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(u1 * Float32(u1 + Float32(1.0)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 * (u1 + single(1.0)))); end
\begin{array}{l}
\\
\sqrt{u1 \cdot \left(u1 + 1\right)}
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 77.9%
Taylor expanded in u1 around 0 68.8%
+-commutative68.8%
Simplified68.8%
Final simplification68.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 77.9%
Final simplification77.9%
(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 77.9%
Taylor expanded in u1 around 0 61.4%
Final simplification61.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (+ u1 0.5))
float code(float cosTheta_i, float u1, float u2) {
return 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 = u1 + 0.5e0
end function
function code(cosTheta_i, u1, u2) return Float32(u1 + Float32(0.5)) end
function tmp = code(cosTheta_i, u1, u2) tmp = u1 + single(0.5); end
\begin{array}{l}
\\
u1 + 0.5
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 77.9%
Taylor expanded in u1 around 0 68.8%
+-commutative68.8%
Simplified68.8%
Taylor expanded in u1 around inf 20.5%
distribute-lft-in20.5%
*-rgt-identity20.5%
*-commutative20.5%
associate-*r*20.5%
*-inverses20.5%
associate-/r*20.5%
unpow220.5%
associate-/l*20.5%
unpow220.5%
*-inverses20.5%
metadata-eval20.5%
Simplified20.5%
Final simplification20.5%
herbie shell --seed 2024067
(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))))