
(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 13 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 (* ux (pow (+ -1.0 maxCos) 2.0))) (* maxCos -2.0))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * ((2.0f - (ux * powf((-1.0f + maxCos), 2.0f))) + (maxCos * -2.0f))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * 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(((uy * single(2.0)) * single(pi))) * sqrt((ux * ((single(2.0) - (ux * ((single(-1.0) + maxCos) ^ single(2.0)))) + (maxCos * single(-2.0))))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 - ux \cdot {\left(-1 + maxCos\right)}^{2}\right) + maxCos \cdot -2\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.1%
cancel-sign-sub-inv99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(*
ux
(-
1.0
(+
maxCos
(- (+ -1.0 maxCos) (* ux (* (+ -1.0 maxCos) (- 1.0 maxCos))))))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (1.0f - (maxCos + ((-1.0f + maxCos) - (ux * ((-1.0f + maxCos) * (1.0f - maxCos))))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(1.0) - Float32(maxCos + Float32(Float32(Float32(-1.0) + maxCos) - Float32(ux * Float32(Float32(Float32(-1.0) + maxCos) * Float32(Float32(1.0) - maxCos))))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(1.0) - (maxCos + ((single(-1.0) + maxCos) - (ux * ((single(-1.0) + maxCos) * (single(1.0) - maxCos)))))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(1 - \left(maxCos + \left(\left(-1 + maxCos\right) - ux \cdot \left(\left(-1 + maxCos\right) \cdot \left(1 - maxCos\right)\right)\right)\right)\right)}
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.7%
Taylor expanded in ux around inf 98.9%
Taylor expanded in ux around 0 98.9%
associate--l+98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
*-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
sub-neg98.9%
metadata-eval98.9%
Simplified98.9%
Final simplification98.9%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (+ (* maxCos -2.0) (+ 2.0 (* ux (- -1.0 (* maxCos -2.0)))))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * ((maxCos * -2.0f) + (2.0f + (ux * (-1.0f - (maxCos * -2.0f)))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(maxCos * Float32(-2.0)) + Float32(Float32(2.0) + Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0))))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * ((maxCos * single(-2.0)) + (single(2.0) + (ux * (single(-1.0) - (maxCos * single(-2.0)))))))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(maxCos \cdot -2 + \left(2 + ux \cdot \left(-1 - maxCos \cdot -2\right)\right)\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.1%
cancel-sign-sub-inv99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 98.6%
+-commutative98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (+ (* maxCos -2.0) (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * ((maxCos * -2.0f) + (2.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(maxCos * Float32(-2.0)) + Float32(Float32(2.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * ((maxCos * single(-2.0)) + (single(2.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(maxCos \cdot -2 + \left(2 - ux\right)\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.1%
cancel-sign-sub-inv99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 97.8%
Final simplification97.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.000295000005280599)
(*
ux
(sqrt
(-
(+ (* (+ -1.0 maxCos) (- 1.0 maxCos)) (* 2.0 (/ 1.0 ux)))
(* 2.0 (/ maxCos ux)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.000295000005280599f) {
tmp = ux * sqrtf(((((-1.0f + maxCos) * (1.0f - maxCos)) + (2.0f * (1.0f / ux))) - (2.0f * (maxCos / ux))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.000295000005280599)) tmp = Float32(ux * sqrt(Float32(Float32(Float32(Float32(Float32(-1.0) + maxCos) * Float32(Float32(1.0) - maxCos)) + Float32(Float32(2.0) * Float32(Float32(1.0) / ux))) - Float32(Float32(2.0) * Float32(maxCos / ux))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (uy <= single(0.000295000005280599)) tmp = ux * sqrt(((((single(-1.0) + maxCos) * (single(1.0) - maxCos)) + (single(2.0) * (single(1.0) / ux))) - (single(2.0) * (maxCos / ux)))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.000295000005280599:\\
\;\;\;\;ux \cdot \sqrt{\left(\left(-1 + maxCos\right) \cdot \left(1 - maxCos\right) + 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 2.95000005e-4Initial program 61.4%
associate-*l*61.4%
sub-neg61.4%
+-commutative61.4%
distribute-rgt-neg-in61.4%
fma-define61.3%
Simplified61.5%
Taylor expanded in ux around inf 99.1%
Taylor expanded in ux around -inf 99.1%
+-commutative99.1%
mul-1-neg99.1%
unsub-neg99.1%
*-commutative99.1%
sub-neg99.1%
metadata-eval99.1%
mul-1-neg99.1%
unsub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 98.1%
if 2.95000005e-4 < uy Initial program 48.3%
associate-*l*48.3%
sub-neg48.3%
+-commutative48.3%
distribute-rgt-neg-in48.3%
fma-define48.7%
Simplified48.8%
Taylor expanded in maxCos around 0 47.8%
Taylor expanded in ux around 0 80.2%
Final simplification91.3%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (- 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (2.0f - ux)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.1%
cancel-sign-sub-inv99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 94.6%
neg-mul-194.6%
unsub-neg94.6%
Simplified94.6%
(FPCore (ux uy maxCos)
:precision binary32
(*
ux
(sqrt
(-
(+ (* (+ -1.0 maxCos) (- 1.0 maxCos)) (* 2.0 (/ 1.0 ux)))
(* 2.0 (/ maxCos ux))))))
float code(float ux, float uy, float maxCos) {
return ux * sqrtf(((((-1.0f + maxCos) * (1.0f - maxCos)) + (2.0f * (1.0f / ux))) - (2.0f * (maxCos / ux))));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = ux * sqrt((((((-1.0e0) + maxcos) * (1.0e0 - maxcos)) + (2.0e0 * (1.0e0 / ux))) - (2.0e0 * (maxcos / ux))))
end function
function code(ux, uy, maxCos) return Float32(ux * sqrt(Float32(Float32(Float32(Float32(Float32(-1.0) + maxCos) * Float32(Float32(1.0) - maxCos)) + Float32(Float32(2.0) * Float32(Float32(1.0) / ux))) - Float32(Float32(2.0) * Float32(maxCos / ux))))) end
function tmp = code(ux, uy, maxCos) tmp = ux * sqrt(((((single(-1.0) + maxCos) * (single(1.0) - maxCos)) + (single(2.0) * (single(1.0) / ux))) - (single(2.0) * (maxCos / ux)))); end
\begin{array}{l}
\\
ux \cdot \sqrt{\left(\left(-1 + maxCos\right) \cdot \left(1 - maxCos\right) + 2 \cdot \frac{1}{ux}\right) - 2 \cdot \frac{maxCos}{ux}}
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.7%
Taylor expanded in ux around inf 98.9%
Taylor expanded in ux around -inf 98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
*-commutative98.9%
sub-neg98.9%
metadata-eval98.9%
mul-1-neg98.9%
unsub-neg98.9%
Simplified98.9%
Taylor expanded in uy around 0 79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00033999999868683517) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))) (sqrt (+ 1.0 (* (+ 1.0 (- (* ux maxCos) ux)) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00033999999868683517f) {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + ((ux * maxCos) - ux)) * (ux + -1.0f))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.00033999999868683517e0) then
tmp = sqrt(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + ((ux * maxcos) - ux)) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00033999999868683517)) tmp = sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(Float32(ux * maxCos) - ux)) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00033999999868683517)) tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + ((ux * maxCos) - ux)) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00033999999868683517:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + \left(ux \cdot maxCos - ux\right)\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 3.39999999e-4Initial program 39.8%
associate-*l*39.8%
sub-neg39.8%
+-commutative39.8%
distribute-rgt-neg-in39.8%
fma-define39.9%
Simplified39.9%
Taylor expanded in uy around 0 34.6%
Simplified34.7%
Taylor expanded in ux around 0 71.7%
Taylor expanded in maxCos around 0 71.7%
if 3.39999999e-4 < ux Initial program 89.5%
associate-*l*89.5%
sub-neg89.5%
+-commutative89.5%
distribute-rgt-neg-in89.5%
fma-define89.4%
Simplified89.8%
Taylor expanded in uy around 0 79.9%
Simplified79.8%
Taylor expanded in maxCos around 0 77.2%
neg-mul-177.2%
Simplified77.2%
Final simplification73.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 2.0 (+ (* maxCos -2.0) (* ux (- -1.0 (* maxCos -2.0))))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (2.0f + ((maxCos * -2.0f) + (ux * (-1.0f - (maxCos * -2.0f)))))));
}
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 * ((-1.0e0) - (maxcos * (-2.0e0))))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) + Float32(Float32(maxCos * Float32(-2.0)) + Float32(ux * Float32(Float32(-1.0) - Float32(maxCos * Float32(-2.0)))))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) + ((maxCos * single(-2.0)) + (ux * (single(-1.0) - (maxCos * single(-2.0)))))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 + \left(maxCos \cdot -2 + ux \cdot \left(-1 - maxCos \cdot -2\right)\right)\right)}
\end{array}
Initial program 56.5%
Taylor expanded in ux around 0 99.1%
cancel-sign-sub-inv99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
metadata-eval99.1%
*-commutative99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in uy around 0 79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00033999999868683517) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00033999999868683517f) {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (ux + -1.0f))));
}
return tmp;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
real(4) :: tmp
if (ux <= 0.00033999999868683517e0) then
tmp = sqrt(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00033999999868683517)) tmp = sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00033999999868683517)) tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00033999999868683517:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 3.39999999e-4Initial program 39.8%
associate-*l*39.8%
sub-neg39.8%
+-commutative39.8%
distribute-rgt-neg-in39.8%
fma-define39.9%
Simplified39.9%
Taylor expanded in uy around 0 34.6%
Simplified34.7%
Taylor expanded in ux around 0 71.7%
Taylor expanded in maxCos around 0 71.7%
if 3.39999999e-4 < ux Initial program 89.5%
associate-*l*89.5%
sub-neg89.5%
+-commutative89.5%
distribute-rgt-neg-in89.5%
fma-define89.4%
Simplified89.8%
Taylor expanded in uy around 0 79.9%
Simplified79.8%
add-log-exp80.0%
unsub-neg80.0%
+-commutative80.0%
+-commutative80.0%
metadata-eval80.0%
sub-neg80.0%
fma-define80.0%
sub-neg80.0%
metadata-eval80.0%
+-commutative80.0%
Applied egg-rr80.0%
Taylor expanded in maxCos around 0 76.8%
neg-mul-176.8%
sub-neg76.8%
Simplified76.8%
Final simplification73.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) + (-2.0f * (ux * 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(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) + Float32(Float32(-2.0) * Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.7%
Taylor expanded in uy around 0 49.8%
Simplified49.9%
Taylor expanded in ux around 0 64.2%
Taylor expanded in maxCos around 0 64.2%
Final simplification64.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (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 - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.7%
Taylor expanded in uy around 0 49.8%
Simplified49.9%
Taylor expanded in ux around 0 64.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 56.5%
associate-*l*56.5%
sub-neg56.5%
+-commutative56.5%
distribute-rgt-neg-in56.5%
fma-define56.5%
Simplified56.7%
Taylor expanded in uy around 0 49.8%
Simplified49.9%
Taylor expanded in ux around 0 64.2%
Taylor expanded in maxCos around 0 62.8%
*-commutative62.8%
Simplified62.8%
Final simplification62.8%
herbie shell --seed 2024086
(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)))))))