
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \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))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
(FPCore (cosTheta_i u1 u2) :precision binary32 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((u1 / (1.0f - u1))) * sinf((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))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2) return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2)); end
\begin{array}{l}
\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}
Initial program 98.4%
Final simplification98.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (if (<= (* 6.28318530718 u2) 0.010999999940395355) (sqrt (* 39.47841760436263 (* u1 (/ (* u2 u2) (- 1.0 u1))))) (* (sin (* 6.28318530718 u2)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
float tmp;
if ((6.28318530718f * u2) <= 0.010999999940395355f) {
tmp = sqrtf((39.47841760436263f * (u1 * ((u2 * u2) / (1.0f - u1)))));
} else {
tmp = sinf((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.010999999940395355e0) then
tmp = sqrt((39.47841760436263e0 * (u1 * ((u2 * u2) / (1.0e0 - u1)))))
else
tmp = sin((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.010999999940395355)) tmp = sqrt(Float32(Float32(39.47841760436263) * Float32(u1 * Float32(Float32(u2 * u2) / Float32(Float32(1.0) - u1))))); else tmp = Float32(sin(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.010999999940395355)) tmp = sqrt((single(39.47841760436263) * (u1 * ((u2 * u2) / (single(1.0) - u1))))); else tmp = sin((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.010999999940395355:\\
\;\;\;\;\sqrt{39.47841760436263 \cdot \left(u1 \cdot \frac{u2 \cdot u2}{1 - u1}\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}\\
\end{array}
\end{array}
if (*.f32 314159265359/50000000000 u2) < 0.0109999999Initial program 98.7%
Taylor expanded in u2 around 0 96.2%
add-sqr-sqrt95.8%
sqrt-unprod96.2%
swap-sqr96.0%
metadata-eval96.4%
*-commutative96.4%
*-commutative96.4%
swap-sqr96.5%
add-sqr-sqrt96.7%
Applied egg-rr96.7%
Taylor expanded in u2 around 0 96.7%
*-commutative96.7%
associate-*r/96.7%
unpow296.7%
Simplified96.7%
if 0.0109999999 < (*.f32 314159265359/50000000000 u2) Initial program 97.6%
Taylor expanded in u1 around 0 71.4%
Final simplification90.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* 39.47841760436263 (* u1 (/ (* u2 u2) (- 1.0 u1))))))
float code(float cosTheta_i, float u1, float u2) {
return sqrtf((39.47841760436263f * (u1 * ((u2 * u2) / (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((39.47841760436263e0 * (u1 * ((u2 * u2) / (1.0e0 - u1)))))
end function
function code(cosTheta_i, u1, u2) return sqrt(Float32(Float32(39.47841760436263) * Float32(u1 * Float32(Float32(u2 * u2) / Float32(Float32(1.0) - u1))))) end
function tmp = code(cosTheta_i, u1, u2) tmp = sqrt((single(39.47841760436263) * (u1 * ((u2 * u2) / (single(1.0) - u1))))); end
\begin{array}{l}
\\
\sqrt{39.47841760436263 \cdot \left(u1 \cdot \frac{u2 \cdot u2}{1 - u1}\right)}
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 83.1%
add-sqr-sqrt82.9%
sqrt-unprod83.1%
swap-sqr83.0%
metadata-eval83.4%
*-commutative83.4%
*-commutative83.4%
swap-sqr83.4%
add-sqr-sqrt83.5%
Applied egg-rr83.5%
Taylor expanded in u2 around 0 83.6%
*-commutative83.6%
associate-*r/83.6%
unpow283.6%
Simplified83.6%
Final simplification83.6%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* (sqrt (/ u1 (- 1.0 u1))) u2)))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (sqrtf((u1 / (1.0f - u1))) * 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 = 6.28318530718e0 * (sqrt((u1 / (1.0e0 - u1))) * u2)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * u2)) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (sqrt((u1 / (single(1.0) - u1))) * u2); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 83.1%
Final simplification83.1%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u2 (sqrt (/ (* u1 39.47841760436263) (- 1.0 u1)))))
float code(float cosTheta_i, float u1, float u2) {
return u2 * sqrtf(((u1 * 39.47841760436263f) / (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 = u2 * sqrt(((u1 * 39.47841760436263e0) / (1.0e0 - u1)))
end function
function code(cosTheta_i, u1, u2) return Float32(u2 * sqrt(Float32(Float32(u1 * Float32(39.47841760436263)) / Float32(Float32(1.0) - u1)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = u2 * sqrt(((u1 * single(39.47841760436263)) / (single(1.0) - u1))); end
\begin{array}{l}
\\
u2 \cdot \sqrt{\frac{u1 \cdot 39.47841760436263}{1 - u1}}
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 83.1%
add-sqr-sqrt82.9%
sqrt-unprod83.1%
swap-sqr83.0%
metadata-eval83.4%
*-commutative83.4%
*-commutative83.4%
swap-sqr83.4%
add-sqr-sqrt83.5%
Applied egg-rr83.5%
associate-*r*83.5%
sqrt-prod83.4%
sqrt-prod82.9%
add-sqr-sqrt83.4%
Applied egg-rr83.4%
unpow1/283.4%
*-commutative83.4%
unpow1/283.4%
associate-*r/83.3%
Simplified83.3%
Final simplification83.3%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* u2 (sqrt (* (/ u1 (- 1.0 u1)) 39.47841760436263))))
float code(float cosTheta_i, float u1, float u2) {
return u2 * sqrtf(((u1 / (1.0f - u1)) * 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 = u2 * sqrt(((u1 / (1.0e0 - u1)) * 39.47841760436263e0))
end function
function code(cosTheta_i, u1, u2) return Float32(u2 * sqrt(Float32(Float32(u1 / Float32(Float32(1.0) - u1)) * Float32(39.47841760436263)))) end
function tmp = code(cosTheta_i, u1, u2) tmp = u2 * sqrt(((u1 / (single(1.0) - u1)) * single(39.47841760436263))); end
\begin{array}{l}
\\
u2 \cdot \sqrt{\frac{u1}{1 - u1} \cdot 39.47841760436263}
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 83.1%
add-sqr-sqrt82.9%
sqrt-unprod83.1%
swap-sqr83.0%
metadata-eval83.4%
*-commutative83.4%
*-commutative83.4%
swap-sqr83.4%
add-sqr-sqrt83.5%
Applied egg-rr83.5%
associate-*r*83.5%
sqrt-prod83.4%
sqrt-prod82.9%
add-sqr-sqrt83.4%
Applied egg-rr83.4%
Final simplification83.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* u2 (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (u2 * 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 = 6.28318530718e0 * (u2 * sqrt(u1))
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(u1))) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (u2 * sqrt(u1)); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)
\end{array}
Initial program 98.4%
Taylor expanded in u2 around 0 83.1%
Taylor expanded in u1 around 0 65.4%
Final simplification65.4%
(FPCore (cosTheta_i u1 u2) :precision binary32 (* 6.28318530718 (* u1 u2)))
float code(float cosTheta_i, float u1, float u2) {
return 6.28318530718f * (u1 * 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 = 6.28318530718e0 * (u1 * u2)
end function
function code(cosTheta_i, u1, u2) return Float32(Float32(6.28318530718) * Float32(u1 * u2)) end
function tmp = code(cosTheta_i, u1, u2) tmp = single(6.28318530718) * (u1 * u2); end
\begin{array}{l}
\\
6.28318530718 \cdot \left(u1 \cdot u2\right)
\end{array}
Initial program 98.4%
Taylor expanded in u1 around 0 86.7%
unpow286.7%
fma-udef86.7%
Simplified86.7%
Taylor expanded in u1 around inf 19.8%
Taylor expanded in u2 around 0 19.6%
Final simplification19.6%
herbie shell --seed 2023229
(FPCore (cosTheta_i u1 u2)
:name "Trowbridge-Reitz Sample, near normal, slope_y"
: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))) (sin (* 6.28318530718 u2))))