
(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) u1) -0.5) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f - u1) / u1), -0.5f) * 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 = (((1.0e0 - u1) / u1) ** (-0.5e0)) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32((Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5)) * cos(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = (((single(1.0) - u1) / u1) ^ single(-0.5)) * cos((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
{\left(\frac{1 - u1}{u1}\right)}^{-0.5} \cdot \cos \left(6.28318530718 \cdot u2\right)
\end{array}
Initial program 98.8%
clear-num98.8%
sqrt-div98.5%
metadata-eval98.5%
div-sub98.4%
inv-pow98.4%
pow198.4%
pow198.4%
pow-div98.4%
metadata-eval98.4%
metadata-eval98.4%
Applied egg-rr98.4%
unpow-198.4%
sub-neg98.4%
metadata-eval98.4%
Simplified98.4%
expm1-log1p-u98.4%
expm1-udef80.6%
inv-pow80.6%
sqrt-pow280.6%
metadata-eval80.6%
Applied egg-rr80.6%
expm1-def98.8%
expm1-log1p98.8%
metadata-eval98.8%
sub-neg98.8%
*-inverses98.8%
div-sub98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* 6.28318530718 u2))))
(if (<= t_0 0.9932000041007996)
(* t_0 (sqrt (* u1 (+ 1.0 u1))))
(* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((6.28318530718f * u2));
float tmp;
if (t_0 <= 0.9932000041007996f) {
tmp = t_0 * sqrtf((u1 * (1.0f + u1)));
} else {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
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.9932000041007996e0) then
tmp = t_0 * sqrt((u1 * (1.0e0 + u1)))
else
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
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.9932000041007996)) tmp = Float32(t_0 * sqrt(Float32(u1 * Float32(Float32(1.0) + u1)))); else tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); 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.9932000041007996)) tmp = t_0 * sqrt((u1 * (single(1.0) + u1))); else tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); 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.9932000041007996:\\
\;\;\;\;t_0 \cdot \sqrt{u1 \cdot \left(1 + u1\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\end{array}
\end{array}
if (cos.f32 (*.f32 314159265359/50000000000 u2)) < 0.993200004Initial program 97.1%
clear-num97.2%
associate-/r/97.2%
Applied egg-rr97.2%
Taylor expanded in u1 around 0 87.0%
if 0.993200004 < (cos.f32 (*.f32 314159265359/50000000000 u2)) Initial program 99.1%
Taylor expanded in u2 around 0 98.6%
*-rgt-identity98.6%
*-commutative98.6%
associate-*l*98.6%
distribute-lft-out98.5%
unpow298.5%
Simplified98.5%
Final simplification96.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.3050000071525574) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))) (/ (cos (* 6.28318530718 u2)) (sqrt (/ 1.0 u1)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.3050000071525574f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
} else {
tmp = cosf((6.28318530718f * u2)) / 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 ((6.28318530718e0 * u2) <= 0.3050000071525574e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
else
tmp = cos((6.28318530718e0 * u2)) / sqrt((1.0e0 / u1))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.3050000071525574)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) / sqrt(Float32(Float32(1.0) / u1))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.3050000071525574)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); else tmp = cos((single(6.28318530718) * u2)) / sqrt((single(1.0) / u1)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.3050000071525574:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\cos \left(6.28318530718 \cdot u2\right)}{\sqrt{\frac{1}{u1}}}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.305000007Initial program 99.1%
Taylor expanded in u2 around 0 97.5%
*-rgt-identity97.5%
*-commutative97.5%
associate-*l*97.5%
distribute-lft-out97.4%
unpow297.4%
Simplified97.4%
if 0.305000007 < (*.f32 314159265359/50000000000 u2) Initial program 96.6%
clear-num96.6%
sqrt-div96.7%
metadata-eval96.7%
div-sub96.7%
inv-pow96.7%
pow196.7%
pow196.7%
pow-div96.7%
metadata-eval96.7%
metadata-eval96.7%
Applied egg-rr96.7%
unpow-196.7%
sub-neg96.7%
metadata-eval96.7%
Simplified96.7%
associate-*l/96.9%
*-un-lft-identity96.9%
add-sqr-sqrt73.9%
add-sqr-sqrt96.9%
*-commutative96.9%
Applied egg-rr96.9%
Taylor expanded in u1 around 0 74.8%
Final simplification94.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (cos (* 6.28318530718 u2)) (pow (+ (/ 1.0 u1) -1.0) -0.5)))
float code(float cosTheta_i, float u1, float u2) {
return cosf((6.28318530718f * u2)) * 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 = cos((6.28318530718e0 * u2)) * (((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0))
end function
function code(cosTheta_i, u1, u2) return Float32(cos(Float32(Float32(6.28318530718) * u2)) * (Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5))) end
function tmp = code(cosTheta_i, u1, u2) tmp = cos((single(6.28318530718) * u2)) * (((single(1.0) / u1) + single(-1.0)) ^ single(-0.5)); end
\begin{array}{l}
\\
\cos \left(6.28318530718 \cdot u2\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Initial program 98.8%
pow1/298.8%
clear-num98.8%
inv-pow98.8%
pow-pow98.9%
div-sub98.8%
inv-pow98.8%
pow198.8%
pow198.8%
pow-div98.8%
metadata-eval98.8%
metadata-eval98.8%
metadata-eval98.8%
Applied egg-rr98.8%
unpow-198.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.3050000071525574) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))) (* (cos (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.3050000071525574f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
} else {
tmp = cosf((6.28318530718f * u2)) * 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 ((6.28318530718e0 * u2) <= 0.3050000071525574e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.3050000071525574)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.3050000071525574)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); else tmp = cos((single(6.28318530718) * u2)) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.3050000071525574:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.305000007Initial program 99.1%
Taylor expanded in u2 around 0 97.5%
*-rgt-identity97.5%
*-commutative97.5%
associate-*l*97.5%
distribute-lft-out97.4%
unpow297.4%
Simplified97.4%
if 0.305000007 < (*.f32 314159265359/50000000000 u2) Initial program 96.6%
Taylor expanded in u1 around 0 74.8%
Final simplification94.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (cos (* 6.28318530718 u2)) (sqrt (/ u1 (- 1.0 u1)))))
float code(float cosTheta_i, float u1, float u2) {
return cosf((6.28318530718f * u2)) * 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 = cos((6.28318530718e0 * u2)) * sqrt((u1 / (1.0e0 - u1)))
end function
function code(cosTheta_i, u1, u2) return Float32(cos(Float32(Float32(6.28318530718) * u2)) * sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = cos((single(6.28318530718) * u2)) * sqrt((u1 / (single(1.0) - u1))); end
\begin{array}{l}
\\
\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{u1}{1 - u1}}
\end{array}
Initial program 98.8%
Final simplification98.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* (/ u1 (- 1.0 u1)) (+ 1.0 (* (* u2 u2) -39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf(((u1 / (1.0f - u1)) * (1.0f + ((u2 * u2) * -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)) * (1.0e0 + ((u2 * u2) * (-39.47841760436263e0)))))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(Float32(u1 / Float32(Float32(1.0) - u1)) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-39.47841760436263))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt(((u1 / (single(1.0) - u1)) * (single(1.0) + ((u2 * u2) * single(-39.47841760436263))))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -39.47841760436263\right)}
\end{array}
Initial program 98.8%
add-sqr-sqrt95.1%
pow1/295.1%
pow1/295.1%
pow-prod-down96.2%
swap-sqr96.2%
add-sqr-sqrt96.3%
pow296.3%
Applied egg-rr96.3%
unpow1/296.3%
Simplified96.3%
Taylor expanded in u2 around 0 87.8%
*-commutative87.8%
unpow287.8%
Simplified87.8%
Final simplification87.8%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
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))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)
\end{array}
Initial program 98.8%
Taylor expanded in u2 around 0 90.0%
*-rgt-identity90.0%
*-commutative90.0%
associate-*l*90.0%
distribute-lft-out89.9%
unpow289.9%
Simplified89.9%
Final simplification89.9%
(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 98.8%
Taylor expanded in u2 around 0 81.8%
Final simplification81.8%
(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 98.8%
Taylor expanded in u2 around 0 81.8%
Taylor expanded in u1 around 0 65.1%
Final simplification65.1%
herbie shell --seed 2023285
(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))))