
(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 12 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 (sqrt (* (pow u2 2.0) 39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(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))) * cos(sqrt(((u2 ** 2.0e0) * 39.47841760436263e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(sqrt(Float32((u2 ^ Float32(2.0)) * Float32(39.47841760436263))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt(((u2 ^ single(2.0)) * single(39.47841760436263)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{{u2}^{2} \cdot 39.47841760436263}\right)
\end{array}
Initial program 99.0%
add-sqr-sqrt98.8%
sqrt-unprod99.0%
pow299.0%
*-commutative99.0%
unpow-prod-down99.0%
metadata-eval99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (cos (* u2 6.28318530718))))
(if (<= t_0 0.9999300241470337)
(* t_0 (sqrt u1))
(pow (/ (- 1.0 u1) u1) -0.5))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = cosf((u2 * 6.28318530718f));
float tmp;
if (t_0 <= 0.9999300241470337f) {
tmp = t_0 * sqrtf(u1);
} else {
tmp = powf(((1.0f - u1) / u1), -0.5f);
}
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((u2 * 6.28318530718e0))
if (t_0 <= 0.9999300241470337e0) then
tmp = t_0 * sqrt(u1)
else
tmp = ((1.0e0 - u1) / u1) ** (-0.5e0)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = cos(Float32(u2 * Float32(6.28318530718))) tmp = Float32(0.0) if (t_0 <= Float32(0.9999300241470337)) tmp = Float32(t_0 * sqrt(u1)); else tmp = Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = cos((u2 * single(6.28318530718))); tmp = single(0.0); if (t_0 <= single(0.9999300241470337)) tmp = t_0 * sqrt(u1); else tmp = ((single(1.0) - u1) / u1) ^ single(-0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t\_0 \leq 0.9999300241470337:\\
\;\;\;\;t\_0 \cdot \sqrt{u1}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{1 - u1}{u1}\right)}^{-0.5}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) < 0.999930024Initial program 98.0%
Taylor expanded in u1 around 0 75.2%
if 0.999930024 < (cos.f32 (*.f32 #s(literal 314159265359/50000000000 binary32) u2)) Initial program 99.5%
Taylor expanded in u2 around 0 96.8%
pow1/296.8%
clear-num96.6%
inv-pow96.6%
pow-pow96.8%
metadata-eval96.8%
Applied egg-rr96.8%
Final simplification90.7%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.012000000104308128) (pow (/ (- 1.0 u1) u1) -0.5) (* (cos (* u2 6.28318530718)) (sqrt (* u1 (+ u1 1.0))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.012000000104308128f) {
tmp = powf(((1.0f - u1) / u1), -0.5f);
} else {
tmp = cosf((u2 * 6.28318530718f)) * sqrtf((u1 * (u1 + 1.0f)));
}
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.012000000104308128e0) then
tmp = ((1.0e0 - u1) / u1) ** (-0.5e0)
else
tmp = cos((u2 * 6.28318530718e0)) * sqrt((u1 * (u1 + 1.0e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.012000000104308128)) tmp = Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5); else tmp = Float32(cos(Float32(u2 * Float32(6.28318530718))) * sqrt(Float32(u1 * Float32(u1 + Float32(1.0))))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((u2 * single(6.28318530718)) <= single(0.012000000104308128)) tmp = ((single(1.0) - u1) / u1) ^ single(-0.5); else tmp = cos((u2 * single(6.28318530718))) * sqrt((u1 * (u1 + single(1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.012000000104308128:\\
\;\;\;\;{\left(\frac{1 - u1}{u1}\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1 \cdot \left(u1 + 1\right)}\\
\end{array}
\end{array}
if (*.f32 #s(literal 314159265359/50000000000 binary32) u2) < 0.0120000001Initial program 99.5%
Taylor expanded in u2 around 0 96.8%
pow1/296.8%
clear-num96.6%
inv-pow96.6%
pow-pow96.8%
metadata-eval96.8%
Applied egg-rr96.8%
if 0.0120000001 < (*.f32 #s(literal 314159265359/50000000000 binary32) u2) Initial program 98.0%
Taylor expanded in u1 around 0 86.7%
+-commutative40.9%
Simplified86.7%
Final simplification93.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (cos (* u2 6.28318530718)) (pow (/ (- 1.0 u1) u1) -0.5)))
float code(float cosTheta_i, float u1, float u2) {
return cosf((u2 * 6.28318530718f)) * powf(((1.0f - u1) / 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 = cos((u2 * 6.28318530718e0)) * (((1.0e0 - u1) / u1) ** (-0.5e0))
end function
function code(cosTheta_i, u1, u2) return Float32(cos(Float32(u2 * Float32(6.28318530718))) * (Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5))) end
function tmp = code(cosTheta_i, u1, u2) tmp = cos((u2 * single(6.28318530718))) * (((single(1.0) - u1) / u1) ^ single(-0.5)); end
\begin{array}{l}
\\
\cos \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1 - u1}{u1}\right)}^{-0.5}
\end{array}
Initial program 99.0%
pow1/280.8%
clear-num80.7%
inv-pow80.7%
pow-pow80.9%
metadata-eval80.9%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * Float32(6.28318530718)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * single(6.28318530718))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot 6.28318530718\right)
\end{array}
Initial program 99.0%
Final simplification99.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (+ (/ 1.0 u1) -1.0) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return 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 = ((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = ((single(1.0) / u1) + single(-1.0)) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Initial program 99.0%
Taylor expanded in u2 around 0 80.8%
pow1/280.8%
clear-num80.7%
inv-pow80.7%
pow-pow80.9%
metadata-eval80.9%
Applied egg-rr80.9%
div-sub80.9%
*-inverses80.9%
sub-neg80.9%
metadata-eval80.9%
Simplified80.9%
Final simplification80.9%
(FPCore (cosTheta_i u1 u2) :precision binary32 (pow (/ (- 1.0 u1) u1) -0.5))
float code(float cosTheta_i, float u1, float u2) {
return powf(((1.0f - u1) / 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 = ((1.0e0 - u1) / u1) ** (-0.5e0)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(Float32(1.0) - u1) / u1) ^ Float32(-0.5) end
function tmp = code(cosTheta_i, u1, u2) tmp = ((single(1.0) - u1) / u1) ^ single(-0.5); end
\begin{array}{l}
\\
{\left(\frac{1 - u1}{u1}\right)}^{-0.5}
\end{array}
Initial program 99.0%
Taylor expanded in u2 around 0 80.8%
pow1/280.8%
clear-num80.7%
inv-pow80.7%
pow-pow80.9%
metadata-eval80.9%
Applied egg-rr80.9%
Final simplification80.9%
(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.0%
Taylor expanded in u2 around 0 80.8%
Taylor expanded in u1 around 0 70.9%
+-commutative70.9%
Simplified70.9%
Final simplification70.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 99.0%
Taylor expanded in u2 around 0 80.8%
Final simplification80.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 99.0%
Taylor expanded in u2 around 0 80.8%
Taylor expanded in u1 around 0 62.2%
Final simplification62.2%
(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.0%
Taylor expanded in u1 around 0 84.8%
distribute-lft-in85.0%
*-rgt-identity85.0%
unpow285.0%
Simplified85.0%
Taylor expanded in u2 around 0 71.0%
+-commutative71.0%
unpow271.0%
fma-undefine71.0%
rem-square-sqrt70.8%
fma-define70.8%
hypot-undefine70.9%
Simplified70.9%
Taylor expanded in u1 around inf 20.4%
distribute-rgt-in20.4%
*-lft-identity20.4%
associate-*l*20.4%
lft-mult-inverse20.4%
metadata-eval20.4%
Simplified20.4%
Final simplification20.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 u1)
float code(float cosTheta_i, float u1, float u2) {
return 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
end function
function code(cosTheta_i, u1, u2) return u1 end
function tmp = code(cosTheta_i, u1, u2) tmp = u1; end
\begin{array}{l}
\\
u1
\end{array}
Initial program 99.0%
Taylor expanded in u1 around 0 84.8%
distribute-lft-in85.0%
*-rgt-identity85.0%
unpow285.0%
Simplified85.0%
Taylor expanded in u2 around 0 71.0%
+-commutative71.0%
unpow271.0%
fma-undefine71.0%
rem-square-sqrt70.8%
fma-define70.8%
hypot-undefine70.9%
Simplified70.9%
Taylor expanded in u1 around inf 19.4%
Final simplification19.4%
herbie shell --seed 2024069
(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))))