
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
float t_0 = (1.0f - ux) + (ux * maxCos);
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos) t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0)))) end
function tmp = code(ux, uy, maxCos) t_0 = (single(1.0) - ux) + (ux * maxCos); tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}
\end{array}
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- (- 2.0 (* 2.0 maxCos)) (* ux (pow (+ -1.0 maxCos) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * ((2.0f - (2.0f * maxCos)) - (ux * powf((-1.0f + maxCos), 2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * ((single(2.0) - (single(2.0) * maxCos)) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 - 2 \cdot maxCos\right) - ux \cdot {\left(-1 + maxCos\right)}^{2}\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in ux around 0 99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* PI (* uy 2.0))) (sqrt (* ux (+ (- 2.0 (* ux (pow (+ -1.0 maxCos) 2.0))) (* maxCos -2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) + (maxCos * -2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * (Float32(Float32(-1.0) + maxCos) ^ Float32(2.0)))) + Float32(maxCos * Float32(-2.0)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((ux * ((single(2.0) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))) + (maxCos * single(-2.0))))); end
\begin{array}{l}
\\
\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) + maxCos \cdot -2\right)}
\end{array}
Initial program 58.1%
Taylor expanded in ux around 0 98.9%
cancel-sign-sub-inv98.9%
associate-*r*98.9%
mul-1-neg98.9%
sub-neg98.9%
metadata-eval98.9%
+-commutative98.9%
metadata-eval98.9%
*-commutative98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (+ (* maxCos (* ux (- (* 2.0 ux) 2.0))) (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((maxCos * (ux * ((2.0f * ux) - 2.0f))) + (ux * (2.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(maxCos * Float32(ux * Float32(Float32(Float32(2.0) * ux) - Float32(2.0)))) + Float32(ux * Float32(Float32(2.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((maxCos * (ux * ((single(2.0) * ux) - single(2.0)))) + (ux * (single(2.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{maxCos \cdot \left(ux \cdot \left(2 \cdot ux - 2\right)\right) + ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in ux around 0 99.0%
Taylor expanded in maxCos around 0 98.4%
Final simplification98.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= maxCos 2.499999936844688e-6) (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 ux)))) (* (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))) (cos (* 2.0 (* uy PI))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 2.499999936844688e-6f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos)))) * cosf((2.0f * (uy * ((float) M_PI))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(2.499999936844688e-6)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = Float32(sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))) * cos(Float32(Float32(2.0) * Float32(uy * Float32(pi))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(2.499999936844688e-6)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - ux))); else tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))) * cos((single(2.0) * (uy * single(pi)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.499999936844688 \cdot 10^{-6}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)\\
\end{array}
\end{array}
if maxCos < 2.49999994e-6Initial program 60.4%
associate-*l*60.4%
sub-neg60.4%
+-commutative60.4%
distribute-rgt-neg-in60.4%
fma-define60.6%
Simplified60.6%
Taylor expanded in ux around 0 99.0%
Taylor expanded in maxCos around 0 98.7%
neg-mul-198.7%
unsub-neg98.7%
Simplified98.7%
if 2.49999994e-6 < maxCos Initial program 47.1%
Taylor expanded in ux around 0 82.0%
Taylor expanded in maxCos around 0 82.0%
Final simplification95.9%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0005000000237487257)
(sqrt
(* ux (- (- 2.0 (* ux (+ 1.0 (* maxCos (- maxCos 2.0))))) (* 2.0 maxCos))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0005000000237487257f) {
tmp = sqrtf((ux * ((2.0f - (ux * (1.0f + (maxCos * (maxCos - 2.0f))))) - (2.0f * maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0005000000237487257)) tmp = sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * Float32(Float32(1.0) + Float32(maxCos * Float32(maxCos - Float32(2.0)))))) - Float32(Float32(2.0) * maxCos)))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.0005000000237487257)) tmp = sqrt((ux * ((single(2.0) - (ux * (single(1.0) + (maxCos * (maxCos - single(2.0)))))) - (single(2.0) * maxCos)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - ux))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0005000000237487257:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(2 - ux \cdot \left(1 + maxCos \cdot \left(maxCos - 2\right)\right)\right) - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if (*.f32 uy #s(literal 2 binary32)) < 5.00000024e-4Initial program 57.1%
associate-*l*57.1%
sub-neg57.1%
+-commutative57.1%
distribute-rgt-neg-in57.1%
fma-define57.3%
Simplified57.4%
Taylor expanded in uy around 0 57.0%
Simplified57.1%
Taylor expanded in ux around 0 98.9%
Taylor expanded in maxCos around 0 98.9%
if 5.00000024e-4 < (*.f32 uy #s(literal 2 binary32)) Initial program 59.9%
associate-*l*59.9%
sub-neg59.9%
+-commutative59.9%
distribute-rgt-neg-in59.9%
fma-define60.1%
Simplified60.3%
Taylor expanded in ux around 0 97.9%
Taylor expanded in maxCos around 0 90.1%
neg-mul-190.1%
unsub-neg90.1%
Simplified90.1%
Final simplification95.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= maxCos 2.499999936844688e-6) (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 ux)))) (* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 2.499999936844688e-6f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - ux)));
} else {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(2.499999936844688e-6)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); else tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(2.499999936844688e-6)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - ux))); else tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.499999936844688 \cdot 10^{-6}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 2.49999994e-6Initial program 60.4%
associate-*l*60.4%
sub-neg60.4%
+-commutative60.4%
distribute-rgt-neg-in60.4%
fma-define60.6%
Simplified60.6%
Taylor expanded in ux around 0 99.0%
Taylor expanded in maxCos around 0 98.7%
neg-mul-198.7%
unsub-neg98.7%
Simplified98.7%
if 2.49999994e-6 < maxCos Initial program 47.1%
Taylor expanded in ux around 0 82.0%
Final simplification95.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (- 2.0 (* ux (+ 1.0 (* maxCos (- maxCos 2.0))))) (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f - (ux * (1.0f + (maxCos * (maxCos - 2.0f))))) - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * ((2.0e0 - (ux * (1.0e0 + (maxcos * (maxcos - 2.0e0))))) - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * Float32(Float32(1.0) + Float32(maxCos * Float32(maxCos - Float32(2.0)))))) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) - (ux * (single(1.0) + (maxCos * (maxCos - single(2.0)))))) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - ux \cdot \left(1 + maxCos \cdot \left(maxCos - 2\right)\right)\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 79.6%
Final simplification79.6%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (+ 2.0 (* ux (- -1.0 (* maxCos -2.0)))) (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f + (ux * (-1.0f - (maxCos * -2.0f)))) - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * ((2.0e0 + (ux * ((-1.0e0) - (maxcos * (-2.0e0))))) - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0))))) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) + (ux * (single(-1.0) - (maxCos * single(-2.0))))) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 + ux \cdot \left(-1 - maxCos \cdot -2\right)\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 79.4%
*-commutative79.4%
Simplified79.4%
Final simplification79.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (- (* maxCos (- (* 2.0 ux) 2.0)) ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + ((maxCos * ((2.0f * ux) - 2.0f)) - ux))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * (2.0e0 + ((maxcos * ((2.0e0 * ux) - 2.0e0)) - ux))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(Float32(Float32(2.0) * ux) - Float32(2.0))) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + ((maxCos * ((single(2.0) * ux) - single(2.0))) - ux)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + \left(maxCos \cdot \left(2 \cdot ux - 2\right) - ux\right)\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 79.4%
Final simplification79.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (- 2.0 ux) (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f - ux) - (2.0f * maxCos))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * ((2.0e0 - ux) - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) - ux) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) - ux) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - ux\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 78.8%
Final simplification78.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f - ux)));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((ux * (2.0e0 - ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 75.2%
neg-mul-175.2%
unsub-neg75.2%
Simplified75.2%
Final simplification75.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((2.0f * ux));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((2.0e0 * ux))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(2.0) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux}
\end{array}
Initial program 58.1%
associate-*l*58.1%
sub-neg58.1%
+-commutative58.1%
distribute-rgt-neg-in58.1%
fma-define58.4%
Simplified58.5%
Taylor expanded in uy around 0 49.7%
Simplified49.8%
Taylor expanded in ux around 0 79.6%
Taylor expanded in maxCos around 0 75.2%
neg-mul-175.2%
unsub-neg75.2%
Simplified75.2%
Taylor expanded in ux around 0 60.5%
*-commutative60.5%
Simplified60.5%
Final simplification60.5%
herbie shell --seed 2024085
(FPCore (ux uy maxCos)
:name "UniformSampleCone, x"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(* (cos (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))