
(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.2%
Final simplification99.2%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.05999999865889549) (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* -19.739208802181317 (* u2 u2)))) (* (cos (* 6.28318530718 u2)) (sqrt (* u1 (+ u1 1.0))))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.05999999865889549f) {
tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (-19.739208802181317f * (u2 * u2)));
} else {
tmp = cosf((6.28318530718f * u2)) * 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 ((6.28318530718e0 * u2) <= 0.05999999865889549e0) then
tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + ((-19.739208802181317e0) * (u2 * u2)))
else
tmp = cos((6.28318530718e0 * u2)) * sqrt((u1 * (u1 + 1.0e0)))
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) tmp = Float32(0.0) if (Float32(Float32(6.28318530718) * u2) <= Float32(0.05999999865889549)) 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(u1 * Float32(u1 + Float32(1.0))))); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) tmp = single(0.0); if ((single(6.28318530718) * u2) <= single(0.05999999865889549)) tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (single(-19.739208802181317) * (u2 * u2))); else tmp = cos((single(6.28318530718) * u2)) * sqrt((u1 * (u1 + single(1.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;6.28318530718 \cdot u2 \leq 0.05999999865889549:\\
\;\;\;\;\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 \cdot \left(u1 + 1\right)}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0599999987Initial program 99.5%
Taylor expanded in u2 around 0 99.4%
+-commutative99.4%
*-lft-identity99.4%
associate-*r*99.4%
distribute-rgt-out99.4%
unpow299.4%
Simplified99.4%
if 0.0599999987 < (*.f32 314159265359/50000000000 u2) Initial program 98.2%
clear-num52.0%
associate-/r/52.1%
Applied egg-rr98.0%
Taylor expanded in u1 around 0 88.2%
+-commutative51.1%
Simplified88.2%
Final simplification97.0%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.15000000596046448) (* (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.15000000596046448f) {
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.15000000596046448e0) 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.15000000596046448)) 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.15000000596046448)) 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.15000000596046448:\\
\;\;\;\;\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.150000006Initial program 99.5%
Taylor expanded in u2 around 0 98.2%
+-commutative98.2%
*-lft-identity98.2%
associate-*r*98.2%
distribute-rgt-out98.3%
unpow298.3%
Simplified98.3%
if 0.150000006 < (*.f32 314159265359/50000000000 u2) Initial program 97.8%
Taylor expanded in u1 around 0 75.3%
Final simplification94.7%
(FPCore (cosTheta_i u1 u2)
:precision binary32
(let* ((t_0 (* u1 (+ u1 1.0))))
(if (<= (/ u1 (- 1.0 u1)) 0.005200000014156103)
(* (+ 1.0 (* -19.739208802181317 (* u2 u2))) (sqrt t_0))
(pow (/ (- 1.0 (* u1 u1)) t_0) -0.5))))
float code(float cosTheta_i, float u1, float u2) {
float t_0 = u1 * (u1 + 1.0f);
float tmp;
if ((u1 / (1.0f - u1)) <= 0.005200000014156103f) {
tmp = (1.0f + (-19.739208802181317f * (u2 * u2))) * sqrtf(t_0);
} else {
tmp = powf(((1.0f - (u1 * u1)) / t_0), -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 = u1 * (u1 + 1.0e0)
if ((u1 / (1.0e0 - u1)) <= 0.005200000014156103e0) then
tmp = (1.0e0 + ((-19.739208802181317e0) * (u2 * u2))) * sqrt(t_0)
else
tmp = ((1.0e0 - (u1 * u1)) / t_0) ** (-0.5e0)
end if
code = tmp
end function
function code(cosTheta_i, u1, u2) t_0 = Float32(u1 * Float32(u1 + Float32(1.0))) tmp = Float32(0.0) if (Float32(u1 / Float32(Float32(1.0) - u1)) <= Float32(0.005200000014156103)) tmp = Float32(Float32(Float32(1.0) + Float32(Float32(-19.739208802181317) * Float32(u2 * u2))) * sqrt(t_0)); else tmp = Float32(Float32(Float32(1.0) - Float32(u1 * u1)) / t_0) ^ Float32(-0.5); end return tmp end
function tmp_2 = code(cosTheta_i, u1, u2) t_0 = u1 * (u1 + single(1.0)); tmp = single(0.0); if ((u1 / (single(1.0) - u1)) <= single(0.005200000014156103)) tmp = (single(1.0) + (single(-19.739208802181317) * (u2 * u2))) * sqrt(t_0); else tmp = ((single(1.0) - (u1 * u1)) / t_0) ^ single(-0.5); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := u1 \cdot \left(u1 + 1\right)\\
\mathbf{if}\;\frac{u1}{1 - u1} \leq 0.005200000014156103:\\
\;\;\;\;\left(1 + -19.739208802181317 \cdot \left(u2 \cdot u2\right)\right) \cdot \sqrt{t_0}\\
\mathbf{else}:\\
\;\;\;\;{\left(\frac{1 - u1 \cdot u1}{t_0}\right)}^{-0.5}\\
\end{array}
\end{array}
if (/.f32 u1 (-.f32 1 u1)) < 0.00520000001Initial program 99.2%
Taylor expanded in u2 around 0 89.1%
+-commutative89.1%
*-lft-identity89.1%
associate-*r*89.1%
distribute-rgt-out89.1%
unpow289.1%
Simplified89.1%
clear-num89.0%
associate-/r/89.1%
Applied egg-rr89.1%
Taylor expanded in u1 around 0 87.9%
+-commutative87.9%
Simplified87.9%
if 0.00520000001 < (/.f32 u1 (-.f32 1 u1)) Initial program 99.2%
Taylor expanded in u2 around 0 79.1%
pow1/279.1%
clear-num79.0%
inv-pow79.0%
pow-pow79.1%
div-sub79.0%
inv-pow79.0%
pow179.0%
pow179.0%
pow-div79.0%
metadata-eval79.0%
metadata-eval79.0%
metadata-eval79.0%
Applied egg-rr79.0%
unpow-179.0%
sub-neg79.0%
metadata-eval79.0%
Simplified79.0%
metadata-eval79.0%
sub-neg79.0%
*-inverses79.0%
div-sub79.1%
div-inv79.1%
flip--79.0%
frac-times79.1%
metadata-eval79.1%
Applied egg-rr79.1%
*-rgt-identity79.1%
*-commutative79.1%
Simplified79.1%
Final simplification85.9%
(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.2%
Taylor expanded in u2 around 0 89.4%
+-commutative89.4%
*-lft-identity89.4%
associate-*r*89.4%
distribute-rgt-out89.4%
unpow289.4%
Simplified89.4%
Final simplification89.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= u2 0.008999999612569809) (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.008999999612569809f) {
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.008999999612569809e0) 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.008999999612569809)) 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.008999999612569809)) 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.008999999612569809:\\
\;\;\;\;\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 < 0.00899999961Initial program 99.5%
Taylor expanded in u2 around 0 93.8%
if 0.00899999961 < u2 Initial program 98.2%
Taylor expanded in u2 around 0 52.1%
+-commutative52.1%
*-lft-identity52.1%
associate-*r*52.1%
distribute-rgt-out52.1%
unpow252.1%
Simplified52.1%
Taylor expanded in u1 around 0 47.8%
Final simplification84.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.2%
Taylor expanded in u2 around 0 80.6%
Final simplification80.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.2%
Taylor expanded in u2 around 0 80.6%
Taylor expanded in u1 around 0 64.3%
Final simplification64.3%
herbie shell --seed 2023207
(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))))