
(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 15 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
(*
(+ 1.0 (+ (cos (* 2.0 (* uy PI))) -1.0))
(sqrt
(-
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))
(* ux (+ maxCos (- -1.0 (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
return (1.0f + (cosf((2.0f * (uy * ((float) M_PI)))) + -1.0f)) * sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) - (ux * (maxCos + (-1.0f - (1.0f - maxCos))))));
}
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) + Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) + Float32(-1.0))) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) - Float32(ux * Float32(maxCos + Float32(Float32(-1.0) - Float32(Float32(1.0) - maxCos))))))) end
function tmp = code(ux, uy, maxCos) tmp = (single(1.0) + (cos((single(2.0) * (uy * single(pi)))) + single(-1.0))) * sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) - (ux * (maxCos + (single(-1.0) - (single(1.0) - maxCos)))))); end
\begin{array}{l}
\\
\left(1 + \left(\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) + -1\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) - ux \cdot \left(maxCos + \left(-1 - \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around 0 99.0%
expm1-log1p-u98.8%
expm1-udef98.8%
*-commutative98.8%
associate-*l*98.8%
Applied egg-rr98.8%
sub-neg98.8%
log1p-udef98.8%
rem-exp-log98.8%
metadata-eval98.8%
Applied egg-rr98.8%
associate-+l+99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* PI (* 2.0 uy)))))
(if (<= t_0 0.9999799728393555)
(* t_0 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(sqrt
(-
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))
(* ux (+ maxCos (- -1.0 (- 1.0 maxCos)))))))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf((((float) M_PI) * (2.0f * uy)));
float tmp;
if (t_0 <= 0.9999799728393555f) {
tmp = t_0 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) - (ux * (maxCos + (-1.0f - (1.0f - maxCos))))));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) tmp = Float32(0.0) if (t_0 <= Float32(0.9999799728393555)) tmp = Float32(t_0 * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) - Float32(ux * Float32(maxCos + Float32(Float32(-1.0) - Float32(Float32(1.0) - maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos((single(pi) * (single(2.0) * uy))); tmp = single(0.0); if (t_0 <= single(0.9999799728393555)) tmp = t_0 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) - (ux * (maxCos + (single(-1.0) - (single(1.0) - maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{if}\;t_0 \leq 0.9999799728393555:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) - ux \cdot \left(maxCos + \left(-1 - \left(1 - maxCos\right)\right)\right)}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.99997997Initial program 50.9%
Taylor expanded in ux around 0 79.2%
if 0.99997997 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 58.4%
associate-*l*58.4%
sub-neg58.4%
+-commutative58.4%
distribute-rgt-neg-in58.4%
fma-def58.4%
Simplified58.5%
Taylor expanded in ux around 0 99.5%
Taylor expanded in uy around 0 97.5%
Final simplification92.4%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(+
(* (- 1.0 maxCos) (* (pow ux 2.0) (+ -1.0 maxCos)))
(* ux (+ 1.0 (- (- 1.0 maxCos) maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((((1.0f - maxCos) * (powf(ux, 2.0f) * (-1.0f + maxCos))) + (ux * (1.0f + ((1.0f - maxCos) - maxCos)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32((ux ^ Float32(2.0)) * Float32(Float32(-1.0) + maxCos))) + Float32(ux * Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) - maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((((single(1.0) - maxCos) * ((ux ^ single(2.0)) * (single(-1.0) + maxCos))) + (ux * (single(1.0) + ((single(1.0) - maxCos) - maxCos))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left({ux}^{2} \cdot \left(-1 + maxCos\right)\right) + ux \cdot \left(1 + \left(\left(1 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around -inf 99.0%
+-commutative99.0%
mul-1-neg99.0%
unsub-neg99.0%
associate-*r*99.0%
mul-1-neg99.0%
sub-neg99.0%
sub-neg99.0%
metadata-eval99.0%
+-commutative99.0%
sub-neg99.0%
mul-1-neg99.0%
unsub-neg99.0%
mul-1-neg99.0%
sub-neg99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(sqrt
(-
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos)))
(* ux (+ maxCos (- -1.0 (- 1.0 maxCos))))))
(cos (* uy (* 2.0 PI)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) - (ux * (maxCos + (-1.0f - (1.0f - maxCos)))))) * cosf((uy * (2.0f * ((float) M_PI))));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) - Float32(ux * Float32(maxCos + Float32(Float32(-1.0) - Float32(Float32(1.0) - maxCos)))))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) - (ux * (maxCos + (single(-1.0) - (single(1.0) - maxCos)))))) * cos((uy * (single(2.0) * single(pi)))); end
\begin{array}{l}
\\
\sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) - ux \cdot \left(maxCos + \left(-1 - \left(1 - maxCos\right)\right)\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right)
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around 0 99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(-
(* (pow ux 2.0) (+ -1.0 (* 2.0 maxCos)))
(* ux (+ maxCos (- -1.0 (- 1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((powf(ux, 2.0f) * (-1.0f + (2.0f * maxCos))) - (ux * (maxCos + (-1.0f - (1.0f - maxCos))))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(-1.0) + Float32(Float32(2.0) * maxCos))) - Float32(ux * Float32(maxCos + Float32(Float32(-1.0) - Float32(Float32(1.0) - maxCos))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((((ux ^ single(2.0)) * (single(-1.0) + (single(2.0) * maxCos))) - (ux * (maxCos + (single(-1.0) - (single(1.0) - maxCos)))))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{{ux}^{2} \cdot \left(-1 + 2 \cdot maxCos\right) - ux \cdot \left(maxCos + \left(-1 - \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around 0 99.0%
Taylor expanded in maxCos around 0 97.9%
Final simplification97.9%
(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 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around 0 99.0%
Taylor expanded in maxCos around 0 97.2%
Final simplification97.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 2.499999936844688e-5)
(* (sqrt (- (* 2.0 ux) (pow ux 2.0))) (cos (* PI (* 2.0 uy))))
(*
(cos (* uy (* 2.0 PI)))
(sqrt (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 2.499999936844688e-5f) {
tmp = sqrtf(((2.0f * ux) - powf(ux, 2.0f))) * cosf((((float) M_PI) * (2.0f * uy)));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * ((1.0f + (1.0f - maxCos)) - maxCos)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(2.499999936844688e-5)) tmp = Float32(sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) * cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy)))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(2.499999936844688e-5)) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))) * cos((single(pi) * (single(2.0) * uy))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * ((single(1.0) + (single(1.0) - maxCos)) - maxCos))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 2.499999936844688 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 2.49999994e-5Initial program 58.0%
associate-*l*58.0%
sub-neg58.0%
+-commutative58.0%
distribute-rgt-neg-in58.0%
fma-def58.1%
Simplified58.2%
Taylor expanded in ux around 0 98.9%
Taylor expanded in maxCos around 0 98.3%
*-commutative98.3%
*-commutative98.3%
associate-*r*98.3%
*-commutative98.3%
+-commutative98.3%
mul-1-neg98.3%
unsub-neg98.3%
*-commutative98.3%
Simplified98.3%
if 2.49999994e-5 < maxCos Initial program 47.0%
associate-*l*47.0%
sub-neg47.0%
+-commutative47.0%
distribute-rgt-neg-in47.0%
fma-def46.6%
Simplified46.8%
Taylor expanded in ux around 0 83.8%
Final simplification96.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* (pow ux 2.0) (* (- 1.0 maxCos) (+ -1.0 maxCos))) (* ux (+ maxCos (- -1.0 (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((powf(ux, 2.0f) * ((1.0f - maxCos) * (-1.0f + maxCos))) - (ux * (maxCos + (-1.0f - (1.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) * ((1.0e0 - maxcos) * ((-1.0e0) + maxcos))) - (ux * (maxcos + ((-1.0e0) - (1.0e0 - maxcos))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(-1.0) + maxCos))) - Float32(ux * Float32(maxCos + Float32(Float32(-1.0) - Float32(Float32(1.0) - maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (single(-1.0) + maxCos))) - (ux * (maxCos + (single(-1.0) - (single(1.0) - maxCos)))))); end
\begin{array}{l}
\\
\sqrt{{ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(-1 + maxCos\right)\right) - ux \cdot \left(maxCos + \left(-1 - \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in ux around 0 99.0%
Taylor expanded in uy around 0 81.0%
Final simplification81.0%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* ux (+ -1.0 maxCos))))
(if (<= ux 0.00019500000053085387)
(sqrt (- (* ux (- -2.0)) (* 2.0 (* ux maxCos))))
(sqrt (+ 1.0 (* (+ 1.0 t_0) (- -1.0 t_0)))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (-1.0f + maxCos);
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sqrtf(((ux * -(-2.0f)) - (2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + t_0) * (-1.0f - t_0))));
}
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) :: t_0
real(4) :: tmp
t_0 = ux * ((-1.0e0) + maxcos)
if (ux <= 0.00019500000053085387e0) then
tmp = sqrt(((ux * -(-2.0e0)) - (2.0e0 * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + t_0) * ((-1.0e0) - t_0))))
end if
code = tmp
end function
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(Float32(-1.0) + maxCos)) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(Float32(2.0) * Float32(ux * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) + t_0) * Float32(Float32(-1.0) - t_0)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = ux * (single(-1.0) + maxCos); tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sqrt(((ux * -single(-2.0)) - (single(2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + t_0) * (single(-1.0) - t_0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(-1 + maxCos\right)\\
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + t_0\right) \cdot \left(-1 - t_0\right)}\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.1%
associate-*l*36.1%
sub-neg36.1%
+-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
Simplified36.1%
Taylor expanded in uy around 0 33.3%
Taylor expanded in ux around 0 74.7%
Taylor expanded in maxCos around 0 74.7%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.0%
Simplified89.2%
Taylor expanded in uy around 0 77.2%
Taylor expanded in ux around -inf 77.2%
mul-1-neg77.2%
unsub-neg77.2%
mul-1-neg77.2%
sub-neg77.2%
Simplified77.2%
Final simplification75.7%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00019500000053085387)
(sqrt (- (* ux (- -2.0)) (* 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.00019500000053085387f) {
tmp = sqrtf(((ux * -(-2.0f)) - (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.00019500000053085387e0) then
tmp = sqrt(((ux * -(-2.0e0)) - (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.00019500000053085387)) tmp = sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - 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.00019500000053085387)) tmp = sqrt(((ux * -single(-2.0)) - (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.00019500000053085387:\\
\;\;\;\;\sqrt{ux \cdot \left(--2\right) - 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.95000001e-4Initial program 36.1%
associate-*l*36.1%
sub-neg36.1%
+-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
Simplified36.1%
Taylor expanded in uy around 0 33.3%
Taylor expanded in ux around 0 74.7%
Taylor expanded in maxCos around 0 74.7%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.0%
Simplified89.2%
Taylor expanded in uy around 0 77.2%
Final simplification75.7%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019500000053085387) (sqrt (- (* ux (- -2.0)) (* 2.0 (* ux maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (- -1.0 (* ux (+ -1.0 maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sqrtf(((ux * -(-2.0f)) - (2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f - (ux * (-1.0f + 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.00019500000053085387e0) then
tmp = sqrt(((ux * -(-2.0e0)) - (2.0e0 * (ux * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) - (ux * ((-1.0e0) + maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(Float32(2.0) * Float32(ux * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - ux) * Float32(Float32(-1.0) - Float32(ux * Float32(Float32(-1.0) + maxCos)))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sqrt(((ux * -single(-2.0)) - (single(2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) - (ux * (single(-1.0) + maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 - ux \cdot \left(-1 + maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.1%
associate-*l*36.1%
sub-neg36.1%
+-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
Simplified36.1%
Taylor expanded in uy around 0 33.3%
Taylor expanded in ux around 0 74.7%
Taylor expanded in maxCos around 0 74.7%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.0%
Simplified89.2%
Taylor expanded in uy around 0 77.2%
Taylor expanded in maxCos around 0 73.6%
Final simplification74.3%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00019500000053085387) (sqrt (- (* ux (- -2.0)) (* 2.0 (* ux maxCos)))) (sqrt (- 1.0 (* (- 1.0 ux) (- 1.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00019500000053085387f) {
tmp = sqrtf(((ux * -(-2.0f)) - (2.0f * (ux * maxCos))));
} else {
tmp = sqrtf((1.0f - ((1.0f - ux) * (1.0f - ux))));
}
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.00019500000053085387e0) then
tmp = sqrt(((ux * -(-2.0e0)) - (2.0e0 * (ux * maxcos))))
else
tmp = sqrt((1.0e0 - ((1.0e0 - ux) * (1.0e0 - ux))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00019500000053085387)) tmp = sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(Float32(2.0) * Float32(ux * maxCos)))); else tmp = sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(1.0) - ux) * Float32(Float32(1.0) - ux)))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00019500000053085387)) tmp = sqrt(((ux * -single(-2.0)) - (single(2.0) * (ux * maxCos)))); else tmp = sqrt((single(1.0) - ((single(1.0) - ux) * (single(1.0) - ux)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00019500000053085387:\\
\;\;\;\;\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 - \left(1 - ux\right) \cdot \left(1 - ux\right)}\\
\end{array}
\end{array}
if ux < 1.95000001e-4Initial program 36.1%
associate-*l*36.1%
sub-neg36.1%
+-commutative36.1%
distribute-rgt-neg-in36.1%
fma-def36.1%
Simplified36.1%
Taylor expanded in uy around 0 33.3%
Taylor expanded in ux around 0 74.7%
Taylor expanded in maxCos around 0 74.7%
if 1.95000001e-4 < ux Initial program 89.0%
associate-*l*89.0%
sub-neg89.0%
+-commutative89.0%
distribute-rgt-neg-in89.0%
fma-def89.0%
Simplified89.2%
Taylor expanded in uy around 0 77.2%
Taylor expanded in maxCos around 0 73.3%
Final simplification74.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- -2.0)) (* 2.0 (* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * -(-2.0f)) - (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(((ux * -(-2.0e0)) - (2.0e0 * (ux * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(-Float32(-2.0))) - Float32(Float32(2.0) * Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * -single(-2.0)) - (single(2.0) * (ux * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(--2\right) - 2 \cdot \left(ux \cdot maxCos\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in uy around 0 50.1%
Taylor expanded in ux around 0 64.9%
Taylor expanded in maxCos around 0 64.9%
Final simplification64.9%
(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.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in uy around 0 50.1%
Taylor expanded in ux around 0 64.9%
Final simplification64.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- -2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * -(-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)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(-Float32(-2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * -single(-2.0))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(--2\right)}
\end{array}
Initial program 56.3%
associate-*l*56.3%
sub-neg56.3%
+-commutative56.3%
distribute-rgt-neg-in56.3%
fma-def56.3%
Simplified56.4%
Taylor expanded in uy around 0 50.1%
Taylor expanded in ux around 0 64.9%
Taylor expanded in maxCos around 0 61.3%
*-commutative61.3%
Simplified61.3%
Final simplification61.3%
herbie shell --seed 2023333
(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)))))))