
(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 (* ux (- (/ (- 2.0 (* 2.0 maxCos)) ux) (pow (+ maxCos -1.0) 2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (ux * (((2.0f - (2.0f * maxCos)) / ux) - powf((maxCos + -1.0f), 2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(ux * Float32(Float32(Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)) / ux) - (Float32(maxCos + Float32(-1.0)) ^ Float32(2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (ux * (((single(2.0) - (single(2.0) * maxCos)) / ux) - ((maxCos + single(-1.0)) ^ single(2.0)))))); end
\begin{array}{l}
\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(ux \cdot \left(\frac{2 - 2 \cdot maxCos}{ux} - {\left(maxCos + -1\right)}^{2}\right)\right)}
\end{array}
Initial program 57.3%
Taylor expanded in ux around 0 99.1%
associate--l+99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in ux around inf 99.1%
associate--l+99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
associate-*r/99.1%
metadata-eval99.1%
associate-*r/99.1%
div-sub99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* (* uy 2.0) PI))))
(if (<= t_0 0.999983012676239)
(* t_0 (sqrt (* 2.0 ux)))
(sqrt
(*
ux
(-
(- 2.0 (* ux (* (+ maxCos -1.0) (+ maxCos -1.0))))
(* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf(((uy * 2.0f) * ((float) M_PI)));
float tmp;
if (t_0 <= 0.999983012676239f) {
tmp = t_0 * sqrtf((2.0f * ux));
} else {
tmp = sqrtf((ux * ((2.0f - (ux * ((maxCos + -1.0f) * (maxCos + -1.0f)))) - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) tmp = Float32(0.0) if (t_0 <= Float32(0.999983012676239)) tmp = Float32(t_0 * sqrt(Float32(Float32(2.0) * ux))); else tmp = sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0))))) - Float32(Float32(2.0) * maxCos)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos(((uy * single(2.0)) * single(pi))); tmp = single(0.0); if (t_0 <= single(0.999983012676239)) tmp = t_0 * sqrt((single(2.0) * ux)); else tmp = sqrt((ux * ((single(2.0) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.0))))) - (single(2.0) * maxCos)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\
\mathbf{if}\;t\_0 \leq 0.999983012676239:\\
\;\;\;\;t\_0 \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(2 - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)\right) - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) < 0.999983013Initial program 61.2%
Taylor expanded in ux around 0 47.2%
Taylor expanded in maxCos around 0 72.5%
if 0.999983013 < (cos.f32 (*.f32 (*.f32 uy #s(literal 2 binary32)) (PI.f32))) Initial program 55.4%
associate-*l*55.4%
sub-neg55.4%
+-commutative55.4%
distribute-rgt-neg-in55.4%
fma-define55.4%
Simplified55.5%
Taylor expanded in ux around inf 99.3%
associate--l+99.3%
associate-*r/99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
sub-neg99.3%
fma-define99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in ux around 0 99.3%
Taylor expanded in uy around 0 97.7%
Final simplification89.2%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(*
ux
(- (- 2.0 (* ux (* (+ maxCos -1.0) (+ maxCos -1.0)))) (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * ((2.0f - (ux * ((maxCos + -1.0f) * (maxCos + -1.0f)))) - (2.0f * maxCos))));
}
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(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0))))) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * ((single(2.0) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.0))))) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in ux around inf 98.9%
associate--l+99.0%
associate-*r/99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-neg-in99.0%
metadata-eval99.0%
sub-neg99.0%
fma-define99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in ux around 0 99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
ux
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+ (/ (- 2.0 (* 2.0 maxCos)) ux) (* (+ maxCos -1.0) (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return ux * (cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((((2.0f - (2.0f * maxCos)) / ux) + ((maxCos + -1.0f) * (1.0f - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(ux * Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)) / ux) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = ux * (cos((single(2.0) * (uy * single(pi)))) * sqrt((((single(2.0) - (single(2.0) * maxCos)) / ux) + ((maxCos + single(-1.0)) * (single(1.0) - maxCos))))); end
\begin{array}{l}
\\
ux \cdot \left(\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\frac{2 - 2 \cdot maxCos}{ux} + \left(maxCos + -1\right) \cdot \left(1 - maxCos\right)}\right)
\end{array}
Initial program 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in ux around inf 98.9%
associate--l+99.0%
associate-*r/99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-neg-in99.0%
metadata-eval99.0%
sub-neg99.0%
fma-define99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in uy around inf 98.7%
associate-*l*98.6%
+-commutative98.6%
associate--l+98.6%
*-commutative98.6%
sub-neg98.6%
metadata-eval98.6%
associate-*r/98.6%
metadata-eval98.6%
associate-*r/98.6%
div-sub98.6%
Simplified98.6%
Final simplification98.6%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* (* uy 2.0) PI)) (sqrt (* ux (- 2.0 (+ 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 * (2.0f - (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(2.0) - Float32(ux + Float32(maxCos * Float32(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 * (single(2.0) - (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(2 - \left(ux + maxCos \cdot \left(2 - 2 \cdot ux\right)\right)\right)}
\end{array}
Initial program 57.3%
Taylor expanded in ux around 0 99.1%
associate--l+99.1%
associate-*r*99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 98.2%
Final simplification98.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.00011000000085914508)
(sqrt
(*
ux
(- (- 2.0 (* ux (* (+ maxCos -1.0) (+ maxCos -1.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.00011000000085914508f) {
tmp = sqrtf((ux * ((2.0f - (ux * ((maxCos + -1.0f) * (maxCos + -1.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.00011000000085914508)) tmp = sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.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.00011000000085914508)) tmp = sqrt((ux * ((single(2.0) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.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.00011000000085914508:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(2 - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\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)) < 1.10000001e-4Initial program 55.7%
associate-*l*55.7%
sub-neg55.7%
+-commutative55.7%
distribute-rgt-neg-in55.7%
fma-define55.5%
Simplified55.7%
Taylor expanded in ux around inf 99.3%
associate--l+99.3%
associate-*r/99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
distribute-neg-in99.3%
metadata-eval99.3%
sub-neg99.3%
fma-define99.3%
sub-neg99.3%
metadata-eval99.3%
+-commutative99.3%
Simplified99.3%
Taylor expanded in ux around 0 99.4%
Taylor expanded in uy around 0 99.3%
if 1.10000001e-4 < (*.f32 uy #s(literal 2 binary32)) Initial program 59.5%
associate-*l*59.5%
sub-neg59.5%
+-commutative59.5%
distribute-rgt-neg-in59.5%
fma-define59.8%
Simplified59.9%
Taylor expanded in maxCos around 0 58.8%
Taylor expanded in ux around 0 95.1%
neg-mul-195.1%
unsub-neg95.1%
Simplified95.1%
Final simplification97.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019999999494757503) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f + (ux - (ux * maxCos))))));
}
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.00019999999494757503e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) + (ux - (ux * maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019999999494757503)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) + Float32(ux - Float32(ux * maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019999999494757503)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.8%
associate-*l*38.8%
sub-neg38.8%
+-commutative38.8%
distribute-rgt-neg-in38.8%
fma-define38.8%
Simplified39.0%
Taylor expanded in uy around 0 34.4%
mul-1-neg34.4%
unsub-neg34.4%
sub-neg34.4%
metadata-eval34.4%
distribute-lft-in34.4%
*-commutative34.4%
mul-1-neg34.4%
sub-neg34.4%
*-commutative34.4%
associate--l+34.3%
unpow234.3%
sub-neg34.3%
Simplified34.4%
Taylor expanded in maxCos around 0 34.4%
Taylor expanded in ux around 0 75.3%
if 1.99999995e-4 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-define89.5%
Simplified89.6%
Taylor expanded in uy around 0 68.8%
mul-1-neg68.8%
unsub-neg68.8%
sub-neg68.8%
metadata-eval68.8%
distribute-lft-in68.8%
*-commutative68.8%
mul-1-neg68.8%
sub-neg68.8%
*-commutative68.8%
associate--l+68.7%
unpow268.7%
sub-neg68.7%
Simplified68.8%
Taylor expanded in maxCos around inf 69.0%
Taylor expanded in maxCos around 0 65.6%
neg-mul-165.6%
sub-neg65.6%
Simplified65.6%
Final simplification71.8%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- (- 2.0 (* ux (* (+ maxCos -1.0) (+ maxCos -1.0)))) (* 2.0 maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * ((2.0f - (ux * ((maxCos + -1.0f) * (maxCos + -1.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 * ((maxcos + (-1.0e0)) * (maxcos + (-1.0e0))))) - (2.0e0 * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(Float32(2.0) - Float32(ux * Float32(Float32(maxCos + Float32(-1.0)) * Float32(maxCos + Float32(-1.0))))) - Float32(Float32(2.0) * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * ((single(2.0) - (ux * ((maxCos + single(-1.0)) * (maxCos + single(-1.0))))) - (single(2.0) * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\left(2 - ux \cdot \left(\left(maxCos + -1\right) \cdot \left(maxCos + -1\right)\right)\right) - 2 \cdot maxCos\right)}
\end{array}
Initial program 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in ux around inf 98.9%
associate--l+99.0%
associate-*r/99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
distribute-neg-in99.0%
metadata-eval99.0%
sub-neg99.0%
fma-define99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
Simplified99.0%
Taylor expanded in ux around 0 99.1%
Taylor expanded in uy around 0 78.0%
Final simplification78.0%
(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(2.0) + Float32(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(2 + \left(ux \cdot \left(-1 - maxCos \cdot -2\right) - 2 \cdot maxCos\right)\right)}
\end{array}
Initial program 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in uy around 0 47.0%
mul-1-neg47.0%
unsub-neg47.0%
sub-neg47.0%
metadata-eval47.0%
distribute-lft-in47.0%
*-commutative47.0%
mul-1-neg47.0%
sub-neg47.0%
*-commutative47.0%
associate--l+47.0%
unpow247.0%
sub-neg47.0%
Simplified47.0%
Taylor expanded in maxCos around 0 46.5%
Taylor expanded in ux around 0 77.2%
associate--l+77.2%
associate-*r*77.2%
neg-mul-177.2%
*-commutative77.2%
*-commutative77.2%
Simplified77.2%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019999999494757503) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf((ux * (2.0f - (2.0f * 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.00019999999494757503e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * 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.00019999999494757503)) tmp = sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * 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.00019999999494757503)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * 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.00019999999494757503:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 38.8%
associate-*l*38.8%
sub-neg38.8%
+-commutative38.8%
distribute-rgt-neg-in38.8%
fma-define38.8%
Simplified39.0%
Taylor expanded in uy around 0 34.4%
mul-1-neg34.4%
unsub-neg34.4%
sub-neg34.4%
metadata-eval34.4%
distribute-lft-in34.4%
*-commutative34.4%
mul-1-neg34.4%
sub-neg34.4%
*-commutative34.4%
associate--l+34.3%
unpow234.3%
sub-neg34.3%
Simplified34.4%
Taylor expanded in maxCos around 0 34.4%
Taylor expanded in ux around 0 75.3%
if 1.99999995e-4 < ux Initial program 89.3%
associate-*l*89.3%
sub-neg89.3%
+-commutative89.3%
distribute-rgt-neg-in89.3%
fma-define89.5%
Simplified89.6%
Taylor expanded in uy around 0 68.8%
mul-1-neg68.8%
unsub-neg68.8%
sub-neg68.8%
metadata-eval68.8%
distribute-lft-in68.8%
*-commutative68.8%
mul-1-neg68.8%
sub-neg68.8%
*-commutative68.8%
associate--l+68.7%
unpow268.7%
sub-neg68.7%
Simplified68.8%
Taylor expanded in maxCos around inf 69.0%
Taylor expanded in maxCos around 0 65.4%
neg-mul-165.4%
sub-neg65.4%
Simplified65.4%
Final simplification71.7%
(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 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in uy around 0 47.0%
mul-1-neg47.0%
unsub-neg47.0%
sub-neg47.0%
metadata-eval47.0%
distribute-lft-in47.0%
*-commutative47.0%
mul-1-neg47.0%
sub-neg47.0%
*-commutative47.0%
associate--l+47.0%
unpow247.0%
sub-neg47.0%
Simplified47.0%
Taylor expanded in maxCos around 0 46.5%
Taylor expanded in ux around 0 64.1%
(FPCore (ux uy maxCos) :precision binary32 0.0)
float code(float ux, float uy, float maxCos) {
return 0.0f;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 0.0e0
end function
function code(ux, uy, maxCos) return Float32(0.0) end
function tmp = code(ux, uy, maxCos) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 57.3%
associate-*l*57.3%
sub-neg57.3%
+-commutative57.3%
distribute-rgt-neg-in57.3%
fma-define57.4%
Simplified57.5%
Taylor expanded in uy around 0 47.0%
mul-1-neg47.0%
unsub-neg47.0%
sub-neg47.0%
metadata-eval47.0%
distribute-lft-in47.0%
*-commutative47.0%
mul-1-neg47.0%
sub-neg47.0%
*-commutative47.0%
associate--l+47.0%
unpow247.0%
sub-neg47.0%
Simplified47.0%
Taylor expanded in maxCos around 0 46.5%
Taylor expanded in ux around 0 6.6%
pow1/26.6%
metadata-eval6.6%
metadata-eval6.6%
Applied egg-rr6.6%
herbie shell --seed 2024170
(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)))))))