
(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 (* (sqrt (/ u1 (- 1.0 u1))) (cos (exp (log (* 6.28318530718 u2))))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(expf(logf((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(exp(log((6.28318530718e0 * u2))))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(exp(log(Float32(Float32(6.28318530718) * u2))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(exp(log((single(6.28318530718) * u2)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(e^{\log \left(6.28318530718 \cdot u2\right)}\right)
\end{array}
Initial program 99.1%
add-exp-log99.1%
Applied egg-rr99.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* 6.28318530718 u2))))
(if (<= t_0 0.9999399781227112)
(/ t_0 (sqrt (/ 1.0 u1)))
(sqrt (/ u1 (- 1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((6.28318530718f * u2));
float tmp;
if (t_0 <= 0.9999399781227112f) {
tmp = t_0 / sqrtf((1.0f / u1));
} else {
tmp = 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) :: t_0
real(4) :: tmp
t_0 = cos((6.28318530718e0 * u2))
if (t_0 <= 0.9999399781227112e0) then
tmp = t_0 / sqrt((1.0e0 / u1))
else
tmp = sqrt((u1 / (1.0e0 - u1)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(Float32(6.28318530718) * u2)) tmp = Float32(0.0) if (t_0 <= Float32(0.9999399781227112)) tmp = Float32(t_0 / sqrt(Float32(Float32(1.0) / u1))); else tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((single(6.28318530718) * u2)); tmp = single(0.0); if (t_0 <= single(0.9999399781227112)) tmp = t_0 / sqrt((single(1.0) / u1)); else tmp = sqrt((u1 / (single(1.0) - u1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(6.28318530718 \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.9999399781227112:\\
\;\;\;\;\frac{t\_0}{\sqrt{\frac{1}{u1}}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.999939978Initial program 98.2%
add-exp-log98.3%
Applied egg-rr98.3%
rem-exp-log98.2%
clear-num98.1%
sqrt-div98.2%
metadata-eval98.2%
associate-*l/98.4%
*-un-lft-identity98.4%
clear-num98.3%
div-sub98.2%
*-inverses98.2%
sub-neg98.2%
metadata-eval98.2%
Applied egg-rr98.2%
associate-/r/98.2%
associate-*l/98.3%
*-lft-identity98.3%
Simplified98.3%
Taylor expanded in u1 around 0 81.8%
if 0.999939978 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) Initial program 99.4%
Taylor expanded in u2 around 0 96.4%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* 6.28318530718 u2))))
(if (<= t_0 0.9999399781227112)
(* t_0 (sqrt u1))
(sqrt (/ u1 (- 1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((6.28318530718f * u2));
float tmp;
if (t_0 <= 0.9999399781227112f) {
tmp = t_0 * sqrtf(u1);
} else {
tmp = 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) :: t_0
real(4) :: tmp
t_0 = cos((6.28318530718e0 * u2))
if (t_0 <= 0.9999399781227112e0) then
tmp = t_0 * sqrt(u1)
else
tmp = sqrt((u1 / (1.0e0 - u1)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(Float32(6.28318530718) * u2)) tmp = Float32(0.0) if (t_0 <= Float32(0.9999399781227112)) tmp = Float32(t_0 * sqrt(u1)); else tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((single(6.28318530718) * u2)); tmp = single(0.0); if (t_0 <= single(0.9999399781227112)) tmp = t_0 * sqrt(u1); else tmp = sqrt((u1 / (single(1.0) - u1))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(6.28318530718 \cdot u2\right)\\
\mathbf{if}\;t\_0 \leq 0.9999399781227112:\\
\;\;\;\;t\_0 \cdot \sqrt{u1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.999939978Initial program 98.2%
Taylor expanded in u1 around 0 81.6%
if 0.999939978 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) Initial program 99.4%
Taylor expanded in u2 around 0 96.4%
Final simplification92.3%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (/ u1 (- 1.0 u1))))
(if (<= t_0 0.0015999999595806003)
(* (cos (* 6.28318530718 u2)) (sqrt (* u1 (+ u1 1.0))))
(sqrt t_0))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = u1 / (1.0f - u1);
float tmp;
if (t_0 <= 0.0015999999595806003f) {
tmp = cosf((6.28318530718f * u2)) * sqrtf((u1 * (u1 + 1.0f)));
} else {
tmp = sqrtf(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) :: tmp
t_0 = u1 / (1.0e0 - u1)
if (t_0 <= 0.0015999999595806003e0) then
tmp = cos((6.28318530718e0 * u2)) * sqrt((u1 * (u1 + 1.0e0)))
else
tmp = sqrt(t_0)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = Float32(u1 / Float32(Float32(1.0) - u1)) tmp = Float32(0.0) if (t_0 <= Float32(0.0015999999595806003)) tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(Float32(u1 * Float32(u1 + Float32(1.0))))); else tmp = sqrt(t_0); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = u1 / (single(1.0) - u1); tmp = single(0.0); if (t_0 <= single(0.0015999999595806003)) tmp = cos((single(6.28318530718) * u2)) * sqrt((u1 * (u1 + single(1.0)))); else tmp = sqrt(t_0); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{u1}{1 - u1}\\
\mathbf{if}\;t\_0 \leq 0.0015999999595806003:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1 \cdot \left(u1 + 1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{t\_0}\\
\end{array}
\end{array}
if (/.f32 u1 (-.f32 #s(literal 1 binary32) u1)) < 0.00159999996Initial program 99.1%
Taylor expanded in u1 around 0 98.4%
+-commutative98.4%
Simplified98.4%
if 0.00159999996 < (/.f32 u1 (-.f32 #s(literal 1 binary32) u1)) Initial program 99.2%
Taylor expanded in u2 around 0 87.4%
Final simplification95.8%
(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%
(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.4%
(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 82.4%
Taylor expanded in u1 around 0 74.5%
+-commutative88.3%
Simplified74.5%
(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.4%
Taylor expanded in u1 around 0 66.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u1 u1))
float code(float cosTheta_i, float u1, float u2) {
return 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 = u1 * u1
end function
function code(cosTheta_i, u1, u2) return Float32(u1 * u1) end
function tmp = code(cosTheta_i, u1, u2) tmp = u1 * u1; end
\begin{array}{l}
\\
u1 \cdot u1
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 82.4%
Taylor expanded in u1 around 0 78.1%
Taylor expanded in u1 around inf 14.4%
unpow214.4%
Applied egg-rr14.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 -0.375)
float code(float cosTheta_i, float u1, float u2) {
return -0.375f;
}
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.375e0
end function
function code(cosTheta_i, u1, u2) return Float32(-0.375) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(-0.375); end
\begin{array}{l}
\\
-0.375
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 82.4%
Taylor expanded in u1 around 0 78.1%
Taylor expanded in u1 around -inf -0.0%
+-commutative-0.0%
unpow2-0.0%
rem-square-sqrt-0.0%
mul-1-neg-0.0%
unsub-neg-0.0%
Simplified3.5%
Taylor expanded in u1 around 0 3.5%
herbie shell --seed 2024165
(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))))