
(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 16 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 (- (+ 1.0 (- 1.0 maxCos)) maxCos))
(* (pow ux 2.0) (* (- 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 + (1.0f - maxCos)) - maxCos)) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) + Float32((ux ^ Float32(2.0)) * 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) + (single(1.0) - maxCos)) - maxCos)) + ((ux ^ single(2.0)) * ((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(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right)}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in ux around 0 99.3%
Final simplification99.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* PI (* uy 2.0))) 0.9999998807907104)
(* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0))))
(sqrt
(fma
ux
(+ (- 1.0 maxCos) (- 1.0 maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf((((float) M_PI) * (uy * 2.0f))) <= 0.9999998807907104f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
} else {
tmp = sqrtf(fmaf(ux, ((1.0f - maxCos) + (1.0f - maxCos)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) <= Float32(0.9999998807907104)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); else tmp = sqrt(fma(ux, Float32(Float32(Float32(1.0) - maxCos) + Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \leq 0.9999998807907104:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(ux, \left(1 - maxCos\right) + \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999881Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.4%
Simplified59.5%
Taylor expanded in ux around 0 98.8%
Taylor expanded in maxCos around 0 93.6%
metadata-eval93.6%
cancel-sign-sub-inv93.6%
associate-*r*93.6%
*-commutative93.6%
associate-*r*93.6%
cancel-sign-sub-inv93.6%
metadata-eval93.6%
+-commutative93.6%
mul-1-neg93.6%
unsub-neg93.6%
*-commutative93.6%
Simplified93.6%
if 0.999999881 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 57.9%
associate-*l*57.9%
sub-neg57.9%
+-commutative57.9%
distribute-rgt-neg-in57.9%
fma-def58.2%
Simplified58.3%
Taylor expanded in ux around 0 99.6%
Taylor expanded in uy around 0 99.6%
fma-def99.6%
associate--l+99.7%
sub-neg99.7%
+-commutative99.7%
associate-+r+99.7%
sub-neg99.7%
mul-1-neg99.7%
sub-neg99.7%
metadata-eval99.7%
+-commutative99.7%
distribute-neg-in99.7%
metadata-eval99.7%
sub-neg99.7%
*-commutative99.7%
sub-neg99.7%
metadata-eval99.7%
+-commutative99.7%
Simplified99.7%
Final simplification97.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* PI (* uy 2.0))) 0.9999998807907104)
(* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0))))
(sqrt
(+
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf((((float) M_PI) * (uy * 2.0f))) <= 0.9999998807907104f) {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
} else {
tmp = sqrtf(((ux * ((1.0f + (1.0f - maxCos)) - maxCos)) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) <= Float32(0.9999998807907104)) tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); else tmp = sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) + Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (cos((single(pi) * (uy * single(2.0)))) <= single(0.9999998807907104)) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); else tmp = sqrt(((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)) + ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \leq 0.9999998807907104:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999881Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.4%
Simplified59.5%
Taylor expanded in ux around 0 98.8%
Taylor expanded in maxCos around 0 93.6%
metadata-eval93.6%
cancel-sign-sub-inv93.6%
associate-*r*93.6%
*-commutative93.6%
associate-*r*93.6%
cancel-sign-sub-inv93.6%
metadata-eval93.6%
+-commutative93.6%
mul-1-neg93.6%
unsub-neg93.6%
*-commutative93.6%
Simplified93.6%
if 0.999999881 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 57.9%
associate-*l*57.9%
sub-neg57.9%
+-commutative57.9%
distribute-rgt-neg-in57.9%
fma-def58.2%
Simplified58.3%
Taylor expanded in ux around 0 99.6%
Taylor expanded in uy around 0 99.6%
Final simplification97.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* PI (* uy 2.0))) 0.9999998807907104)
(* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- (- ux) -2.0))))
(sqrt
(+
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf((((float) M_PI) * (uy * 2.0f))) <= 0.9999998807907104f) {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (-ux - -2.0f)));
} else {
tmp = sqrtf(((ux * ((1.0f + (1.0f - maxCos)) - maxCos)) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) <= Float32(0.9999998807907104)) tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(-ux) - Float32(-2.0))))); else tmp = sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) + Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (cos((single(pi) * (uy * single(2.0)))) <= single(0.9999998807907104)) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (-ux - single(-2.0)))); else tmp = sqrt(((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)) + ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \leq 0.9999998807907104:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(-ux\right) - -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999881Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.4%
Simplified59.5%
Taylor expanded in ux around -inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
associate-*r*98.7%
sub-neg98.7%
metadata-eval98.7%
mul-1-neg98.7%
sub-neg98.7%
+-commutative98.7%
sub-neg98.7%
mul-1-neg98.7%
unsub-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
metadata-eval98.7%
Simplified98.7%
Taylor expanded in uy around inf 98.7%
Taylor expanded in maxCos around 0 93.6%
sub-neg93.6%
mul-1-neg93.6%
distribute-neg-out93.6%
unpow293.6%
distribute-rgt-out93.6%
Simplified93.6%
if 0.999999881 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 57.9%
associate-*l*57.9%
sub-neg57.9%
+-commutative57.9%
distribute-rgt-neg-in57.9%
fma-def58.2%
Simplified58.3%
Taylor expanded in ux around 0 99.6%
Taylor expanded in uy around 0 99.6%
Final simplification97.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (cos (* PI (* uy 2.0))) 0.9999998807907104)
(* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- (- ux) -2.0))))
(sqrt
(+
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (cosf((((float) M_PI) * (uy * 2.0f))) <= 0.9999998807907104f) {
tmp = cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (-ux - -2.0f)));
} else {
tmp = sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) + (ux * (2.0f - (2.0f * maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) <= Float32(0.9999998807907104)) tmp = Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(-ux) - Float32(-2.0))))); else tmp = sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) + 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 (cos((single(pi) * (uy * single(2.0)))) <= single(0.9999998807907104)) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (-ux - single(-2.0)))); else tmp = sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \leq 0.9999998807907104:\\
\;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(-ux\right) - -2\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999999881Initial program 58.9%
associate-*l*58.9%
sub-neg58.9%
+-commutative58.9%
distribute-rgt-neg-in58.9%
fma-def59.4%
Simplified59.5%
Taylor expanded in ux around -inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
unsub-neg98.7%
associate-*r*98.7%
sub-neg98.7%
metadata-eval98.7%
mul-1-neg98.7%
sub-neg98.7%
+-commutative98.7%
sub-neg98.7%
mul-1-neg98.7%
unsub-neg98.7%
mul-1-neg98.7%
sub-neg98.7%
metadata-eval98.7%
Simplified98.7%
Taylor expanded in uy around inf 98.7%
Taylor expanded in maxCos around 0 93.6%
sub-neg93.6%
mul-1-neg93.6%
distribute-neg-out93.6%
unpow293.6%
distribute-rgt-out93.6%
Simplified93.6%
if 0.999999881 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 57.9%
associate-*l*57.9%
sub-neg57.9%
+-commutative57.9%
distribute-rgt-neg-in57.9%
fma-def58.2%
Simplified58.3%
Taylor expanded in ux around -inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
associate-*r*99.6%
sub-neg99.6%
metadata-eval99.6%
mul-1-neg99.6%
sub-neg99.6%
+-commutative99.6%
sub-neg99.6%
mul-1-neg99.6%
unsub-neg99.6%
mul-1-neg99.6%
sub-neg99.6%
metadata-eval99.6%
Simplified99.6%
Taylor expanded in uy around 0 99.6%
Final simplification97.3%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) + (ux * (2.0f - (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in ux around -inf 99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
associate-*r*99.3%
sub-neg99.3%
metadata-eval99.3%
mul-1-neg99.3%
sub-neg99.3%
+-commutative99.3%
sub-neg99.3%
mul-1-neg99.3%
unsub-neg99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in uy around inf 99.3%
Final simplification99.3%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (- (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)) (pow ux 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((ux * ((1.0f + (1.0f - maxCos)) - maxCos)) - powf(ux, 2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)) - (ux ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos)) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right) - {ux}^{2}}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in ux around 0 99.3%
Taylor expanded in maxCos around 0 97.7%
Final simplification97.7%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0002699999895412475)
(* (cos (* PI (* uy 2.0))) (sqrt (* 2.0 ux)))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ -1.0 maxCos))) (+ ux (- -1.0 (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0002699999895412475f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf((2.0f * ux));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (-1.0f + maxCos))) * (ux + (-1.0f - (ux * maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0002699999895412475)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(2.0) * ux))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + Float32(ux * Float32(Float32(-1.0) + maxCos))) * Float32(ux + Float32(Float32(-1.0) - Float32(ux * maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0002699999895412475)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt((single(2.0) * ux)); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (single(-1.0) + maxCos))) * (ux + (single(-1.0) - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002699999895412475:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(-1 + maxCos\right)\right) \cdot \left(ux + \left(-1 - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 2.6999999e-4Initial program 35.8%
Taylor expanded in ux around 0 39.6%
Taylor expanded in maxCos around 0 87.8%
*-commutative87.8%
Simplified87.8%
if 2.6999999e-4 < ux Initial program 90.6%
associate-*l*90.6%
sub-neg90.6%
+-commutative90.6%
distribute-rgt-neg-in90.6%
fma-def91.5%
Simplified91.5%
Taylor expanded in uy around 0 76.1%
Simplified76.1%
Final simplification83.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (* ux (- (- ux) -2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((ux * (-ux - -2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(-ux) - Float32(-2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((ux * (-ux - single(-2.0)))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(-ux\right) - -2\right)}
\end{array}
Initial program 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in ux around -inf 99.3%
+-commutative99.3%
mul-1-neg99.3%
unsub-neg99.3%
associate-*r*99.3%
sub-neg99.3%
metadata-eval99.3%
mul-1-neg99.3%
sub-neg99.3%
+-commutative99.3%
sub-neg99.3%
mul-1-neg99.3%
unsub-neg99.3%
mul-1-neg99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
Taylor expanded in uy around inf 99.3%
Taylor expanded in maxCos around 0 93.7%
sub-neg93.7%
mul-1-neg93.7%
distribute-neg-out93.7%
unpow293.7%
distribute-rgt-out93.6%
Simplified93.6%
Final simplification93.6%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019999999494757503)
(sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ -1.0 maxCos))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (-1.0f + maxCos))) * (-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(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * ((-1.0e0) + maxcos))) * ((-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(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(ux * Float32(Float32(-1.0) + maxCos))) * 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(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (single(-1.0) + maxCos))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(-1 + maxCos\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 35.0%
associate-*l*35.0%
sub-neg35.0%
+-commutative35.0%
distribute-rgt-neg-in35.0%
fma-def35.1%
Simplified35.3%
Taylor expanded in uy around 0 32.7%
Simplified32.7%
Taylor expanded in ux around 0 77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in maxCos around 0 77.3%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def91.0%
Simplified91.0%
Taylor expanded in uy around 0 75.3%
Simplified75.3%
associate--l+75.2%
Applied egg-rr75.2%
Final simplification76.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019999999494757503)
(sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ -1.0 maxCos))) (+ ux (- -1.0 (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019999999494757503f) {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (-1.0f + maxCos))) * (ux + (-1.0f - (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(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * ((-1.0e0) + maxcos))) * (ux + ((-1.0e0) - (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(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(ux * Float32(Float32(-1.0) + maxCos))) * Float32(ux + Float32(Float32(-1.0) - 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(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (single(-1.0) + maxCos))) * (ux + (single(-1.0) - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019999999494757503:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(-1 + maxCos\right)\right) \cdot \left(ux + \left(-1 - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.99999995e-4Initial program 35.0%
associate-*l*35.0%
sub-neg35.0%
+-commutative35.0%
distribute-rgt-neg-in35.0%
fma-def35.1%
Simplified35.3%
Taylor expanded in uy around 0 32.7%
Simplified32.7%
Taylor expanded in ux around 0 77.3%
*-commutative77.3%
Simplified77.3%
Taylor expanded in maxCos around 0 77.3%
if 1.99999995e-4 < ux Initial program 90.2%
associate-*l*90.2%
sub-neg90.2%
+-commutative90.2%
distribute-rgt-neg-in90.2%
fma-def91.0%
Simplified91.0%
Taylor expanded in uy around 0 75.3%
Simplified75.3%
Final simplification76.4%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0003000000142492354) (sqrt (+ (* 2.0 ux) (* -2.0 (* ux maxCos)))) (sqrt (+ 1.0 (* (+ 1.0 (* ux (+ -1.0 maxCos))) (+ ux -1.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0003000000142492354f) {
tmp = sqrtf(((2.0f * ux) + (-2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (-1.0f + maxCos))) * (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.0003000000142492354e0) then
tmp = sqrt(((2.0e0 * ux) + ((-2.0e0) * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * ((-1.0e0) + maxcos))) * (ux + (-1.0e0)))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0003000000142492354)) 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(ux * Float32(Float32(-1.0) + maxCos))) * Float32(ux + Float32(-1.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0003000000142492354)) tmp = sqrt(((single(2.0) * ux) + (single(-2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (single(-1.0) + maxCos))) * (ux + single(-1.0))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0003000000142492354:\\
\;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(-1 + maxCos\right)\right) \cdot \left(ux + -1\right)}\\
\end{array}
\end{array}
if ux < 3.00000014e-4Initial program 36.4%
associate-*l*36.4%
sub-neg36.4%
+-commutative36.4%
distribute-rgt-neg-in36.4%
fma-def36.4%
Simplified36.6%
Taylor expanded in uy around 0 33.7%
Simplified33.7%
Taylor expanded in ux around 0 76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in maxCos around 0 76.6%
if 3.00000014e-4 < ux Initial program 90.8%
associate-*l*90.8%
sub-neg90.8%
+-commutative90.8%
distribute-rgt-neg-in90.8%
fma-def91.8%
Simplified91.8%
Taylor expanded in uy around 0 76.0%
Simplified76.0%
Taylor expanded in maxCos around 0 73.9%
Final simplification75.5%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.0003000000142492354) (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.0003000000142492354f) {
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.0003000000142492354e0) 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.0003000000142492354)) 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.0003000000142492354)) 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.0003000000142492354:\\
\;\;\;\;\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.00000014e-4Initial program 36.4%
associate-*l*36.4%
sub-neg36.4%
+-commutative36.4%
distribute-rgt-neg-in36.4%
fma-def36.4%
Simplified36.6%
Taylor expanded in uy around 0 33.7%
Simplified33.7%
Taylor expanded in ux around 0 76.6%
*-commutative76.6%
Simplified76.6%
Taylor expanded in maxCos around 0 76.6%
if 3.00000014e-4 < ux Initial program 90.8%
associate-*l*90.8%
sub-neg90.8%
+-commutative90.8%
distribute-rgt-neg-in90.8%
fma-def91.8%
Simplified91.8%
Taylor expanded in uy around 0 76.0%
Simplified76.0%
Taylor expanded in maxCos around 0 73.6%
Final simplification75.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 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in uy around 0 50.7%
Simplified50.7%
Taylor expanded in ux around 0 64.7%
*-commutative64.7%
Simplified64.7%
Taylor expanded in maxCos around 0 64.7%
Final simplification64.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 58.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in uy around 0 50.7%
Simplified50.7%
Taylor expanded in ux around 0 64.7%
*-commutative64.7%
Simplified64.7%
Final simplification64.7%
(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.3%
associate-*l*58.3%
sub-neg58.3%
+-commutative58.3%
distribute-rgt-neg-in58.3%
fma-def58.7%
Simplified58.8%
Taylor expanded in uy around 0 50.7%
Simplified50.7%
Taylor expanded in ux around 0 64.7%
*-commutative64.7%
Simplified64.7%
Taylor expanded in maxCos around 0 62.0%
*-commutative62.0%
Simplified62.0%
Final simplification62.0%
herbie shell --seed 2024021
(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)))))))