
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (sqrt (* (pow u2 2.0) 39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf(sqrtf((powf(u2, 2.0f) * 39.47841760436263f)));
}
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))) * sin(sqrt(((u2 ** 2.0e0) * 39.47841760436263e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(sqrt(Float32((u2 ^ Float32(2.0)) * Float32(39.47841760436263))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin(sqrt(((u2 ^ single(2.0)) * single(39.47841760436263)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{{u2}^{2} \cdot 39.47841760436263}\right)
\end{array}
Initial program 98.4%
add-sqr-sqrt97.9%
sqrt-unprod98.4%
*-commutative98.4%
*-commutative98.4%
swap-sqr98.2%
pow298.2%
metadata-eval98.4%
Applied egg-rr98.4%
Final simplification98.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.010999999940395355) (* u2 (* (sqrt (/ u1 (- 1.0 u1))) 6.28318530718)) (/ (sin (* u2 6.28318530718)) (sqrt (/ 1.0 u1)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.010999999940395355f) {
tmp = u2 * (sqrtf((u1 / (1.0f - u1))) * 6.28318530718f);
} else {
tmp = sinf((u2 * 6.28318530718f)) / sqrtf((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.010999999940395355e0) then
tmp = u2 * (sqrt((u1 / (1.0e0 - u1))) * 6.28318530718e0)
else
tmp = sin((u2 * 6.28318530718e0)) / sqrt((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.010999999940395355)) tmp = Float32(u2 * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(6.28318530718))); else tmp = Float32(sin(Float32(u2 * Float32(6.28318530718))) / sqrt(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.010999999940395355)) tmp = u2 * (sqrt((u1 / (single(1.0) - u1))) * single(6.28318530718)); else tmp = sin((u2 * single(6.28318530718))) / sqrt((single(1.0) / u1)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.010999999940395355:\\
\;\;\;\;u2 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot 6.28318530718\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1}{u1}}}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0109999999Initial program 98.6%
Taylor expanded in u2 around 0 96.7%
associate-*r*96.7%
Simplified96.7%
if 0.0109999999 < (*.f32 314159265359/50000000000 u2) Initial program 97.8%
add-sqr-sqrt97.4%
sqrt-unprod97.8%
*-commutative97.8%
*-commutative97.8%
swap-sqr97.6%
pow297.6%
metadata-eval97.7%
Applied egg-rr97.7%
*-commutative97.7%
sqrt-div97.4%
clear-num97.3%
un-div-inv97.7%
*-commutative97.7%
sqrt-prod97.1%
metadata-eval97.6%
unpow297.6%
sqrt-prod97.1%
add-sqr-sqrt97.6%
*-commutative97.6%
sqrt-undiv97.8%
Applied egg-rr97.8%
Taylor expanded in u1 around 0 73.7%
Final simplification89.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.010999999940395355) (* u2 (* (sqrt (/ u1 (- 1.0 u1))) 6.28318530718)) (/ (sqrt u1) (/ 1.0 (sin (* u2 6.28318530718))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.010999999940395355f) {
tmp = u2 * (sqrtf((u1 / (1.0f - u1))) * 6.28318530718f);
} else {
tmp = sqrtf(u1) / (1.0f / sinf((u2 * 6.28318530718f)));
}
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.010999999940395355e0) then
tmp = u2 * (sqrt((u1 / (1.0e0 - u1))) * 6.28318530718e0)
else
tmp = sqrt(u1) / (1.0e0 / sin((u2 * 6.28318530718e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.010999999940395355)) tmp = Float32(u2 * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(6.28318530718))); else tmp = Float32(sqrt(u1) / Float32(Float32(1.0) / sin(Float32(u2 * Float32(6.28318530718))))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((u2 * single(6.28318530718)) <= single(0.010999999940395355)) tmp = u2 * (sqrt((u1 / (single(1.0) - u1))) * single(6.28318530718)); else tmp = sqrt(u1) / (single(1.0) / sin((u2 * single(6.28318530718)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.010999999940395355:\\
\;\;\;\;u2 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot 6.28318530718\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{u1}}{\frac{1}{\sin \left(u2 \cdot 6.28318530718\right)}}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0109999999Initial program 98.6%
Taylor expanded in u2 around 0 96.7%
associate-*r*96.7%
Simplified96.7%
if 0.0109999999 < (*.f32 314159265359/50000000000 u2) Initial program 97.8%
add-sqr-sqrt97.4%
sqrt-unprod97.8%
*-commutative97.8%
*-commutative97.8%
swap-sqr97.6%
pow297.6%
metadata-eval97.7%
Applied egg-rr97.7%
*-commutative97.7%
sqrt-div97.4%
clear-num97.3%
un-div-inv97.7%
*-commutative97.7%
sqrt-prod97.1%
metadata-eval97.6%
unpow297.6%
sqrt-prod97.1%
add-sqr-sqrt97.6%
*-commutative97.6%
sqrt-undiv97.8%
Applied egg-rr97.8%
div-sub97.8%
sub-neg97.8%
*-inverses97.8%
metadata-eval97.8%
Simplified97.8%
add-sqr-sqrt88.7%
sqrt-unprod89.6%
frac-times89.6%
add-sqr-sqrt89.9%
metadata-eval89.9%
sub-neg89.9%
*-inverses89.9%
div-sub89.9%
add-sqr-sqrt89.5%
frac-times89.6%
sqrt-unprod88.6%
add-sqr-sqrt97.8%
clear-num97.6%
sqrt-div97.5%
Applied egg-rr97.6%
*-lft-identity97.6%
associate-*l/97.3%
associate-/r/97.3%
associate-*r/97.7%
*-rgt-identity97.7%
*-commutative97.7%
Simplified97.7%
Taylor expanded in u1 around 0 73.7%
Final simplification89.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.010999999940395355) (* u2 (* (sqrt (/ u1 (- 1.0 u1))) 6.28318530718)) (* (sin (* u2 6.28318530718)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.010999999940395355f) {
tmp = u2 * (sqrtf((u1 / (1.0f - u1))) * 6.28318530718f);
} else {
tmp = sinf((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.010999999940395355e0) then
tmp = u2 * (sqrt((u1 / (1.0e0 - u1))) * 6.28318530718e0)
else
tmp = sin((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.010999999940395355)) tmp = Float32(u2 * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(6.28318530718))); else tmp = Float32(sin(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.010999999940395355)) tmp = u2 * (sqrt((u1 / (single(1.0) - u1))) * single(6.28318530718)); else tmp = sin((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.010999999940395355:\\
\;\;\;\;u2 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot 6.28318530718\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0109999999Initial program 98.6%
Taylor expanded in u2 around 0 96.7%
associate-*r*96.7%
Simplified96.7%
if 0.0109999999 < (*.f32 314159265359/50000000000 u2) Initial program 97.8%
Taylor expanded in u1 around 0 73.7%
Final simplification89.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(u2 * Float32(6.28318530718)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((u2 * single(6.28318530718))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(u2 \cdot 6.28318530718\right)
\end{array}
Initial program 98.4%
Final simplification98.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* (sqrt (/ u1 (- 1.0 u1))) u2)))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (sqrtf((u1 / (1.0f - u1))) * 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 = 6.28318530718e0 * (sqrt((u1 / (1.0e0 - u1))) * u2)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * u2)) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (sqrt((u1 / (single(1.0) - u1))) * u2); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 80.2%
Final simplification80.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u2 (* (sqrt (/ u1 (- 1.0 u1))) 6.28318530718)))
float code(float cosTheta_i, float u1, float u2) {
return u2 * (sqrtf((u1 / (1.0f - u1))) * 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 = u2 * (sqrt((u1 / (1.0e0 - u1))) * 6.28318530718e0)
end function
function code(cosTheta_i, u1, u2) return Float32(u2 * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(6.28318530718))) end
function tmp = code(cosTheta_i, u1, u2) tmp = u2 * (sqrt((u1 / (single(1.0) - u1))) * single(6.28318530718)); end
\begin{array}{l}
\\
u2 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot 6.28318530718\right)
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 80.2%
associate-*r*80.2%
Simplified80.2%
Final simplification80.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (* u2 (sqrt u1)) -6.28318530718))
float code(float cosTheta_i, float u1, float u2) {
return (u2 * sqrtf(u1)) * -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 = (u2 * sqrt(u1)) * (-6.28318530718e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(u2 * sqrt(u1)) * Float32(-6.28318530718)) end
function tmp = code(cosTheta_i, u1, u2) tmp = (u2 * sqrt(u1)) * single(-6.28318530718); end
\begin{array}{l}
\\
\left(u2 \cdot \sqrt{u1}\right) \cdot -6.28318530718
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 80.2%
Taylor expanded in u1 around 0 65.6%
add-sqr-sqrt65.4%
sqrt-unprod65.6%
*-commutative65.6%
*-commutative65.6%
swap-sqr65.5%
swap-sqr65.5%
add-sqr-sqrt65.6%
pow265.6%
metadata-eval65.5%
Applied egg-rr65.5%
Taylor expanded in u2 around -inf 4.6%
Final simplification4.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* u2 (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (u2 * 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 = 6.28318530718e0 * (u2 * sqrt(u1))
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (u2 * sqrt(u1)); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 80.2%
Taylor expanded in u1 around 0 65.6%
Final simplification65.6%
herbie shell --seed 2024039
(FPCore (cosTheta_i u1 u2)
:name "Trowbridge-Reitz Sample, near normal, slope_y"
: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))) (sin (* 6.28318530718 u2))))