
(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 8 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.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.17759999632835388) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* -19.739208802181317 (* u2 u2)))) (* (cos (* 6.28318530718 u2)) (/ 1.0 (pow u1 -0.5)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.17759999632835388f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * (u2 * u2)));
} else {
tmp = cosf((6.28318530718f * u2)) * (1.0f / powf(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) :: tmp
if ((6.28318530718e0 * u2) <= 0.17759999632835388e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((-19.739208802181317e0) * (u2 * u2)))
else
tmp = cos((6.28318530718e0 * u2)) * (1.0e0 / (u1 ** (-0.5e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.17759999632835388)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2)))); else tmp = Float32(cos(Float32(Float32(6.28318530718) * u2)) * Float32(Float32(1.0) / (u1 ^ Float32(-0.5)))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.17759999632835388)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 * u2))); else tmp = cos((single(6.28318530718) * u2)) * (single(1.0) / (u1 ^ single(-0.5))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.17759999632835388:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \frac{1}{{u1}^{-0.5}}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.177599996Initial program 99.4%
Taylor expanded in u2 around 0 97.8%
+-commutative97.8%
*-lft-identity97.8%
associate-*r*97.8%
distribute-rgt-out97.7%
unpow297.7%
Simplified97.7%
if 0.177599996 < (*.f32 314159265359/50000000000 u2) Initial program 97.9%
clear-num98.2%
sqrt-div98.1%
metadata-eval98.1%
div-sub98.1%
pow198.1%
pow198.1%
pow-div98.1%
metadata-eval98.1%
metadata-eval98.1%
Applied egg-rr98.1%
expm1-log1p-u98.1%
expm1-udef78.9%
pow1/278.9%
pow-flip78.9%
sub-neg78.9%
metadata-eval78.9%
metadata-eval78.9%
Applied egg-rr78.9%
expm1-def97.9%
expm1-log1p97.9%
metadata-eval97.9%
*-inverses97.9%
sub-neg97.9%
div-sub98.0%
Simplified98.0%
Taylor expanded in u1 around 0 74.1%
add-sqr-sqrt74.2%
unpow-prod-down74.3%
inv-pow74.3%
sqrt-pow174.3%
metadata-eval74.3%
inv-pow74.3%
sqrt-pow174.3%
metadata-eval74.3%
Applied egg-rr74.3%
pow-sqr74.5%
metadata-eval74.5%
unpow-174.5%
Simplified74.5%
Final simplification94.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.17759999632835388) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* -19.739208802181317 (* u2 u2)))) (/ (cos (* 6.28318530718 u2)) (sqrt (/ 1.0 u1)))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.17759999632835388f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * (u2 * u2)));
} 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.17759999632835388e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((-19.739208802181317e0) * (u2 * u2)))
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.17759999632835388)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2)))); 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.17759999632835388)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 * u2))); 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.17759999632835388:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\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.177599996Initial program 99.4%
Taylor expanded in u2 around 0 97.8%
+-commutative97.8%
*-lft-identity97.8%
associate-*r*97.8%
distribute-rgt-out97.7%
unpow297.7%
Simplified97.7%
if 0.177599996 < (*.f32 314159265359/50000000000 u2) Initial program 97.9%
clear-num98.2%
sqrt-div98.1%
metadata-eval98.1%
div-sub98.1%
pow198.1%
pow198.1%
pow-div98.1%
metadata-eval98.1%
metadata-eval98.1%
Applied egg-rr98.1%
expm1-log1p-u98.0%
expm1-udef78.4%
associate-*l/78.4%
*-un-lft-identity78.4%
*-commutative78.4%
sub-neg78.4%
metadata-eval78.4%
Applied egg-rr78.4%
expm1-def98.2%
expm1-log1p98.2%
metadata-eval98.2%
*-inverses98.2%
sub-neg98.2%
div-sub98.3%
Simplified98.3%
Taylor expanded in u1 around 0 74.5%
Final simplification94.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.17759999632835388) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* -19.739208802181317 (* u2 u2)))) (* (cos (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.17759999632835388f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * (u2 * u2)));
} 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.17759999632835388e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((-19.739208802181317e0) * (u2 * u2)))
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.17759999632835388)) tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2)))); 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.17759999632835388)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 * u2))); 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.17759999632835388:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.177599996Initial program 99.4%
Taylor expanded in u2 around 0 97.8%
+-commutative97.8%
*-lft-identity97.8%
associate-*r*97.8%
distribute-rgt-out97.7%
unpow297.7%
Simplified97.7%
if 0.177599996 < (*.f32 314159265359/50000000000 u2) Initial program 97.9%
Taylor expanded in u1 around 0 74.3%
Final simplification94.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* -19.739208802181317 (* u2 u2)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * (u2 * 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))) * (1.0e0 + ((-19.739208802181317e0) * (u2 * u2)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 * u2))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right)
\end{array}
Initial program 99.1%
Taylor expanded in u2 around 0 88.6%
+-commutative88.6%
*-lft-identity88.6%
associate-*r*88.6%
distribute-rgt-out88.5%
unpow288.5%
Simplified88.5%
Final simplification88.5%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 0.0006799999973736703) (sqrt (/ u1 (- 1.0 u1))) (* (+ 1.0 (* -19.739208802181317 (* u2 u2))) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if (u2 <= 0.0006799999973736703f) {
tmp = sqrtf((u1 / (1.0f - u1)));
} else {
tmp = (1.0f + (-19.739208802181317f * (u2 * 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 (u2 <= 0.0006799999973736703e0) then
tmp = sqrt((u1 / (1.0e0 - u1)))
else
tmp = (1.0e0 + ((-19.739208802181317e0) * (u2 * u2))) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (u2 <= Float32(0.0006799999973736703)) tmp = sqrt(Float32(u1 / Float32(Float32(1.0) - u1))); else tmp = Float32(Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2))) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if (u2 <= single(0.0006799999973736703)) tmp = sqrt((u1 / (single(1.0) - u1))); else tmp = (single(1.0) + (single(-19.739208802181317) * (u2 * u2))) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \leq 0.0006799999973736703:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if u2 < 6.79999997e-4Initial program 99.4%
Taylor expanded in u2 around 0 98.1%
if 6.79999997e-4 < u2 Initial program 98.6%
clear-num98.6%
sqrt-div98.4%
metadata-eval98.4%
div-sub98.4%
pow198.4%
pow198.4%
pow-div98.4%
metadata-eval98.4%
metadata-eval98.4%
Applied egg-rr98.4%
Taylor expanded in u2 around 0 69.0%
associate-*r*69.0%
distribute-lft1-in69.1%
*-commutative69.1%
unpow269.1%
*-inverses69.1%
div-sub69.1%
Simplified69.1%
Taylor expanded in u1 around 0 59.3%
Final simplification84.2%
(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 79.6%
Final simplification79.6%
(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 79.6%
Taylor expanded in u1 around 0 64.4%
Final simplification64.4%
herbie shell --seed 2023258
(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))))