
(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 9 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 (if (<= (* 6.28318530718 u2) 0.0003499999875202775) (sqrt (/ u1 (- 1.0 u1))) (* (sqrt (* u1 (- u1 -1.0))) (cos (* 6.28318530718 u2)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.0003499999875202775f) {
tmp = sqrtf((u1 / (1.0f - u1)));
} else {
tmp = sqrtf((u1 * (u1 - -1.0f))) * cosf((6.28318530718f * u2));
}
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.0003499999875202775e0) then
tmp = sqrt((u1 / (1.0e0 - u1)))
else
tmp = sqrt((u1 * (u1 - (-1.0e0)))) * cos((6.28318530718e0 * u2))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.0003499999875202775)) tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); else tmp = Float32(sqrt(Float32(u1 * Float32(u1 - Float32(-1.0)))) * cos(Float32(Float32(6.28318530718) * u2))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.0003499999875202775)) tmp = sqrt((u1 / (single(1.0) - u1))); else tmp = sqrt((u1 * (u1 - single(-1.0)))) * cos((single(6.28318530718) * u2)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.0003499999875202775:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1 \cdot \left(u1 - -1\right)} \cdot \cos \left(6.28318530718 \cdot u2\right)\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 3.49999988e-4Initial program 99.6%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3299.6
Applied rewrites99.6%
if 3.49999988e-4 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 98.5%
Taylor expanded in u1 around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
lower-fma.f3235.1
Applied rewrites32.6%
Applied rewrites87.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.004999999888241291) (sqrt (/ u1 (- 1.0 u1))) (* (sqrt u1) (cos (* 6.28318530718 u2)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.004999999888241291f) {
tmp = sqrtf((u1 / (1.0f - u1)));
} else {
tmp = sqrtf(u1) * cosf((6.28318530718f * u2));
}
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.004999999888241291e0) then
tmp = sqrt((u1 / (1.0e0 - u1)))
else
tmp = sqrt(u1) * cos((6.28318530718e0 * u2))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.004999999888241291)) tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); else tmp = Float32(sqrt(u1) * cos(Float32(Float32(6.28318530718) * u2))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.004999999888241291)) tmp = sqrt((u1 / (single(1.0) - u1))); else tmp = sqrt(u1) * cos((single(6.28318530718) * u2)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.004999999888241291:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{u1} \cdot \cos \left(6.28318530718 \cdot u2\right)\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.00499999989Initial program 99.5%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3297.7
Applied rewrites97.7%
if 0.00499999989 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 98.3%
Taylor expanded in u1 around 0
lower-sqrt.f3275.0
Applied rewrites75.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
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (fma (- u1 1.0) u1 1.0) u1)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((fmaf((u1 - 1.0f), u1, 1.0f) * u1));
}
function code(cosTheta_i, u1, u2) return sqrt(Float32(fma(Float32(u1 - Float32(1.0)), u1, Float32(1.0)) * u1)) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(u1 - 1, u1, 1\right) \cdot u1}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
Applied rewrites66.1%
Taylor expanded in u1 around 0
Applied rewrites67.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (- 1.0 u1) u1)))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(((1.0f - u1) * 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(((1.0e0 - u1) * u1))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(Float32(Float32(1.0) - u1) * u1)) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(((single(1.0) - u1) * u1)); end
\begin{array}{l}
\\
\sqrt{\left(1 - u1\right) \cdot u1}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
Applied rewrites66.1%
Taylor expanded in u1 around 0
Applied rewrites66.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (- (/ 0.5 u1) 1.0))
float code(float cosTheta_i, float u1, float u2) {
return (0.5f / 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 = (0.5e0 / u1) - 1.0e0
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(0.5) / u1) - Float32(1.0)) end
function tmp = code(cosTheta_i, u1, u2) tmp = (single(0.5) / u1) - single(1.0); end
\begin{array}{l}
\\
\frac{0.5}{u1} - 1
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
Applied rewrites66.1%
Taylor expanded in u1 around -inf
Applied rewrites13.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (- 1.0 (/ 0.5 u1)))
float code(float cosTheta_i, float u1, float u2) {
return 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 = 1.0e0 - (0.5e0 / u1)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(1.0) - Float32(Float32(0.5) / u1)) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(1.0) - (single(0.5) / u1); end
\begin{array}{l}
\\
1 - \frac{0.5}{u1}
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
Applied rewrites66.1%
Taylor expanded in u1 around inf
Applied rewrites3.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 -1.0)
float code(float cosTheta_i, float u1, float u2) {
return -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 = -1.0e0
end function
function code(cosTheta_i, u1, u2) return Float32(-1.0) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(-1.0); end
\begin{array}{l}
\\
-1
\end{array}
Initial program 99.2%
Taylor expanded in u2 around 0
lower-sqrt.f32N/A
lower-/.f32N/A
lower--.f3281.4
Applied rewrites81.4%
Applied rewrites66.1%
Taylor expanded in u1 around -inf
Applied rewrites3.7%
herbie shell --seed 2024326
(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))))