
(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 (sqrt (* (* u2 u2) 39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(sqrtf(((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))) * cos(sqrt(((u2 * u2) * 39.47841760436263e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(sqrt(Float32(Float32(u2 * u2) * Float32(39.47841760436263))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt(((u2 * u2) * single(39.47841760436263)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)
\end{array}
Initial program 99.0%
add-sqr-sqrt98.9%
pow1/298.9%
pow1/298.9%
pow-prod-down99.0%
swap-sqr98.9%
metadata-eval99.1%
Applied egg-rr99.1%
unpow1/299.1%
unpow299.1%
*-commutative99.1%
unpow299.1%
Simplified99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (sqrt (* u2 (* u2 39.47841760436263))))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf(sqrtf((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))) * cos(sqrt((u2 * (u2 * 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(u2 * Float32(39.47841760436263)))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt((u2 * (u2 * single(39.47841760436263))))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{u2 \cdot \left(u2 \cdot 39.47841760436263\right)}\right)
\end{array}
Initial program 99.0%
add-sqr-sqrt98.9%
pow1/298.9%
pow1/298.9%
pow-prod-down99.0%
swap-sqr98.9%
metadata-eval99.1%
Applied egg-rr99.1%
unpow1/299.1%
associate-*r*99.1%
*-commutative99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 (pow 39.47841760436263 0.5)))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * cosf((u2 * powf(39.47841760436263f, 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 = sqrt((u1 / (1.0e0 - u1))) * cos((u2 * (39.47841760436263e0 ** 0.5e0)))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * (Float32(39.47841760436263) ^ Float32(0.5))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * (single(39.47841760436263) ^ single(0.5)))); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot {39.47841760436263}^{0.5}\right)
\end{array}
Initial program 99.0%
add-sqr-sqrt98.9%
pow1/298.9%
pow1/298.9%
pow-prod-down99.0%
swap-sqr98.9%
metadata-eval99.1%
Applied egg-rr99.1%
unpow1/299.1%
unpow299.1%
*-commutative99.1%
unpow299.1%
Simplified99.1%
pow1/299.1%
*-commutative99.1%
unpow-prod-down99.1%
pow1/299.1%
sqrt-prod99.0%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* u2 6.28318530718) 0.10000000149011612) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))) (* (cos (* u2 6.28318530718)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((u2 * 6.28318530718f) <= 0.10000000149011612f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
} else {
tmp = cosf((u2 * 6.28318530718f)) * 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 * 6.28318530718e0) <= 0.10000000149011612e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
else
tmp = cos((u2 * 6.28318530718e0)) * sqrt(u1)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.10000000149011612)) 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(u2 * Float32(6.28318530718))) * sqrt(u1)); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((u2 * single(6.28318530718)) <= single(0.10000000149011612)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317))); else tmp = cos((u2 * single(6.28318530718))) * sqrt(u1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.10000000149011612:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.100000001Initial program 99.4%
add-sqr-sqrt99.4%
pow1/299.4%
pow1/299.4%
pow-prod-down99.4%
clear-num99.3%
clear-num99.3%
inv-pow99.3%
inv-pow99.3%
pow-prod-up99.3%
div-sub99.2%
inv-pow99.2%
pow199.2%
pow199.2%
pow-div99.2%
metadata-eval99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
exp-to-pow96.4%
*-commutative96.4%
log-pow96.4%
associate-*r*96.4%
metadata-eval96.4%
*-commutative96.4%
exp-to-pow99.2%
unpow-199.2%
unpow-199.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
Simplified99.2%
Taylor expanded in u2 around 0 98.8%
associate-*r*98.8%
distribute-lft1-in98.8%
unpow298.8%
*-inverses98.8%
div-sub98.8%
*-lft-identity98.8%
*-lft-identity98.8%
associate-/l*99.0%
*-lft-identity99.0%
Simplified99.0%
if 0.100000001 < (*.f32 314159265359/50000000000 u2) Initial program 97.1%
Taylor expanded in u1 around 0 74.3%
Final simplification94.8%
(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 (* (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 99.0%
add-sqr-sqrt99.0%
pow1/299.0%
pow1/299.0%
pow-prod-down99.0%
clear-num99.0%
clear-num99.0%
inv-pow99.0%
inv-pow99.0%
pow-prod-up99.0%
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%
exp-to-pow96.1%
*-commutative96.1%
log-pow96.1%
associate-*r*96.1%
metadata-eval96.1%
*-commutative96.1%
exp-to-pow98.9%
unpow-198.9%
unpow-198.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
Simplified98.9%
Taylor expanded in u2 around 0 89.7%
associate-*r*89.7%
distribute-lft1-in89.6%
unpow289.6%
*-inverses89.6%
div-sub89.7%
*-lft-identity89.7%
*-lft-identity89.7%
associate-/l*89.8%
*-lft-identity89.8%
Simplified89.8%
Final simplification89.8%
(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 82.3%
Final simplification82.3%
(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 82.3%
Taylor expanded in u1 around 0 64.8%
Final simplification64.8%
(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 86.0%
unpow286.0%
fma-udef86.0%
Simplified86.0%
Taylor expanded in u2 around 0 73.0%
unpow273.0%
unpow173.0%
sqr-pow72.8%
hypot-def72.8%
metadata-eval72.8%
unpow1/272.8%
Simplified72.8%
Taylor expanded in u1 around inf 19.0%
Final simplification19.0%
herbie shell --seed 2023230
(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))))