
(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
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 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) * ((maxCos + -1.0f) * (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(maxCos + Float32(-1.0)) * 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)) * ((maxCos + single(-1.0)) * (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(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around inf 99.2%
Final simplification99.2%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* PI (* 2.0 uy)))) (t_1 (* ux (- 2.0 (* 2.0 maxCos)))))
(if (<= t_0 0.999987006187439)
(* t_0 (sqrt t_1))
(sqrt (+ (* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos))) t_1)))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf((((float) M_PI) * (2.0f * uy)));
float t_1 = ux * (2.0f - (2.0f * maxCos));
float tmp;
if (t_0 <= 0.999987006187439f) {
tmp = t_0 * sqrtf(t_1);
} else {
tmp = sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + t_1));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) t_1 = Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) tmp = Float32(0.0) if (t_0 <= Float32(0.999987006187439)) tmp = Float32(t_0 * sqrt(t_1)); else tmp = sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + t_1)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos((single(pi) * (single(2.0) * uy))); t_1 = ux * (single(2.0) - (single(2.0) * maxCos)); tmp = single(0.0); if (t_0 <= single(0.999987006187439)) tmp = t_0 * sqrt(t_1); else tmp = sqrt((((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (single(1.0) - maxCos))) + t_1)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
t_1 := ux \cdot \left(2 - 2 \cdot maxCos\right)\\
\mathbf{if}\;t_0 \leq 0.999987006187439:\\
\;\;\;\;t_0 \cdot \sqrt{t_1}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + t_1}\\
\end{array}
\end{array}
if (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) < 0.999987006Initial program 57.1%
Taylor expanded in ux around 0 76.1%
if 0.999987006 < (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) Initial program 60.4%
associate-*l*60.4%
sub-neg60.4%
+-commutative60.4%
distribute-rgt-neg-in60.4%
fma-def60.7%
Simplified60.5%
Taylor expanded in ux around -inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
*-commutative99.6%
mul-1-neg99.6%
sub-neg99.6%
sub-neg99.6%
metadata-eval99.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 98.0%
Final simplification90.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+
(* (pow ux 2.0) (+ (* 2.0 maxCos) -1.0))
(* 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) * ((2.0f * maxCos) + -1.0f)) + (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(2.0) * maxCos) + Float32(-1.0))) + 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(2.0) * maxCos) + single(-1.0))) + (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(2 \cdot maxCos + -1\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around inf 99.2%
Taylor expanded in maxCos around 0 98.2%
Final simplification98.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 9.7999996796716e-5)
(sqrt
(+
(* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos)))
(* ux (- 2.0 (* 2.0 maxCos)))))
(* (cos (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (pow ux 2.0))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 9.7999996796716e-5f) {
tmp = sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (ux * (2.0f - (2.0f * maxCos)))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - powf(ux, 2.0f)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(9.7999996796716e-5)) tmp = sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((single(2.0) * uy) <= single(9.7999996796716e-5)) tmp = sqrt((((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 9.7999996796716 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 9.79999968e-5Initial program 61.0%
associate-*l*61.0%
sub-neg61.0%
+-commutative61.0%
distribute-rgt-neg-in61.0%
fma-def61.3%
Simplified61.1%
Taylor expanded in ux around -inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
*-commutative99.6%
mul-1-neg99.6%
sub-neg99.6%
sub-neg99.6%
metadata-eval99.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.7%
if 9.79999968e-5 < (*.f32 uy 2) Initial program 57.1%
associate-*l*57.1%
sub-neg57.1%
+-commutative57.1%
distribute-rgt-neg-in57.1%
fma-def57.4%
Simplified57.2%
Taylor expanded in ux around -inf 98.6%
+-commutative98.6%
mul-1-neg98.6%
unsub-neg98.6%
*-commutative98.6%
mul-1-neg98.6%
sub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
sub-neg98.6%
mul-1-neg98.6%
unsub-neg98.6%
mul-1-neg98.6%
sub-neg98.6%
metadata-eval98.6%
Simplified98.6%
Taylor expanded in maxCos around 0 93.0%
cancel-sign-sub-inv93.0%
mul-1-neg93.0%
metadata-eval93.0%
*-commutative93.0%
Simplified93.0%
Final simplification96.7%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (pow ux 2.0)))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((ux * (2.0f - (2.0f * maxCos))) - powf(ux, 2.0f)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - (ux ^ Float32(2.0))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around inf 99.2%
Taylor expanded in maxCos around 0 97.4%
Final simplification97.4%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (cos (* PI (* 2.0 uy))))
(t_1
(+
1.0
(* (+ (- 1.0 ux) (* ux maxCos)) (- (+ ux -1.0) (* ux maxCos))))))
(if (<= t_1 0.0004079999926034361)
(* t_0 (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(* t_0 (sqrt t_1)))))
float code(float ux, float uy, float maxCos) {
float t_0 = cosf((((float) M_PI) * (2.0f * uy)));
float t_1 = 1.0f + (((1.0f - ux) + (ux * maxCos)) * ((ux + -1.0f) - (ux * maxCos)));
float tmp;
if (t_1 <= 0.0004079999926034361f) {
tmp = t_0 * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = t_0 * sqrtf(t_1);
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) t_1 = Float32(Float32(1.0) + Float32(Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) * Float32(Float32(ux + Float32(-1.0)) - Float32(ux * maxCos)))) tmp = Float32(0.0) if (t_1 <= Float32(0.0004079999926034361)) tmp = Float32(t_0 * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(t_0 * sqrt(t_1)); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = cos((single(pi) * (single(2.0) * uy))); t_1 = single(1.0) + (((single(1.0) - ux) + (ux * maxCos)) * ((ux + single(-1.0)) - (ux * maxCos))); tmp = single(0.0); if (t_1 <= single(0.0004079999926034361)) tmp = t_0 * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = t_0 * sqrt(t_1); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\
t_1 := 1 + \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(ux + -1\right) - ux \cdot maxCos\right)\\
\mathbf{if}\;t_1 \leq 0.0004079999926034361:\\
\;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \sqrt{t_1}\\
\end{array}
\end{array}
if (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) < 4.07999993e-4Initial program 37.7%
Taylor expanded in ux around 0 92.3%
if 4.07999993e-4 < (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) Initial program 90.4%
Final simplification91.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (pow ux 2.0) (* (+ maxCos -1.0) (- 1.0 maxCos))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((powf(ux, 2.0f) * ((maxCos + -1.0f) * (1.0f - maxCos))) + (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) * ((maxcos + (-1.0e0)) * (1.0e0 - maxcos))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(maxCos + Float32(-1.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((ux ^ single(2.0)) * ((maxCos + single(-1.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{{ux}^{2} \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around 0 80.2%
Final simplification80.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (pow ux 2.0) (+ (* 2.0 maxCos) -1.0)) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((powf(ux, 2.0f) * ((2.0f * maxCos) + -1.0f)) + (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) + (-1.0e0))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(2.0) * maxCos) + Float32(-1.0))) + 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) + single(-1.0))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{{ux}^{2} \cdot \left(2 \cdot maxCos + -1\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around 0 80.2%
Taylor expanded in maxCos around 0 79.6%
Final simplification79.6%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* ux (- 2.0 (* 2.0 maxCos))) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) - powf(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 - (2.0e0 * maxcos))) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) - {ux}^{2}}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around 0 80.2%
Taylor expanded in maxCos around 0 79.1%
mul-1-neg79.1%
Simplified79.1%
Final simplification79.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (pow ux 2.0))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) - powf(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(((2.0e0 * ux) - (ux ** 2.0e0)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - (ux ^ Float32(2.0)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux ^ single(2.0)))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - {ux}^{2}}
\end{array}
Initial program 59.3%
associate-*l*59.3%
sub-neg59.3%
+-commutative59.3%
distribute-rgt-neg-in59.3%
fma-def59.6%
Simplified59.4%
Taylor expanded in ux around -inf 99.2%
+-commutative99.2%
mul-1-neg99.2%
unsub-neg99.2%
*-commutative99.2%
mul-1-neg99.2%
sub-neg99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
sub-neg99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Taylor expanded in uy around 0 80.2%
Taylor expanded in maxCos around 0 76.2%
cancel-sign-sub-inv76.2%
neg-mul-176.2%
metadata-eval76.2%
*-commutative76.2%
Simplified76.2%
Final simplification76.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.00020399999630171806)
(sqrt (* ux (- 2.0 (* 2.0 maxCos))))
(sqrt
(+ 1.0 (* (+ 1.0 (* ux (+ maxCos -1.0))) (+ -1.0 (- ux (* ux maxCos))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00020399999630171806f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f + (ux * (maxCos + -1.0f))) * (-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.00020399999630171806e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 + (ux * (maxcos + (-1.0e0)))) * ((-1.0e0) + (ux - (ux * maxcos))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00020399999630171806)) 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) + Float32(ux * Float32(maxCos + Float32(-1.0)))) * 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.00020399999630171806)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) + (ux * (maxCos + single(-1.0)))) * (single(-1.0) + (ux - (ux * maxCos)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00020399999630171806:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 + ux \cdot \left(maxCos + -1\right)\right) \cdot \left(-1 + \left(ux - ux \cdot maxCos\right)\right)}\\
\end{array}
\end{array}
if ux < 2.03999996e-4Initial program 37.7%
Taylor expanded in ux around 0 92.3%
Taylor expanded in uy around 0 74.6%
if 2.03999996e-4 < ux Initial program 90.4%
associate-*l*90.4%
sub-neg90.4%
+-commutative90.4%
distribute-rgt-neg-in90.4%
fma-def90.9%
Simplified90.5%
Taylor expanded in uy around 0 75.4%
associate--l+75.6%
*-commutative75.6%
Applied egg-rr75.6%
Final simplification75.0%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00020399999630171806) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))) (sqrt (+ 1.0 (* (- 1.0 ux) (- -1.0 (* ux (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.00020399999630171806f) {
tmp = sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = sqrtf((1.0f + ((1.0f - ux) * (-1.0f - (ux * (maxCos + -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.00020399999630171806e0) then
tmp = sqrt((ux * (2.0e0 - (2.0e0 * maxcos))))
else
tmp = sqrt((1.0e0 + ((1.0e0 - ux) * ((-1.0e0) - (ux * (maxcos + (-1.0e0)))))))
end if
code = tmp
end function
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.00020399999630171806)) 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(maxCos + Float32(-1.0))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.00020399999630171806)) tmp = sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = sqrt((single(1.0) + ((single(1.0) - ux) * (single(-1.0) - (ux * (maxCos + single(-1.0))))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.00020399999630171806:\\
\;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{1 + \left(1 - ux\right) \cdot \left(-1 - ux \cdot \left(maxCos + -1\right)\right)}\\
\end{array}
\end{array}
if ux < 2.03999996e-4Initial program 37.7%
Taylor expanded in ux around 0 92.3%
Taylor expanded in uy around 0 74.6%
if 2.03999996e-4 < ux Initial program 90.4%
associate-*l*90.4%
sub-neg90.4%
+-commutative90.4%
distribute-rgt-neg-in90.4%
fma-def90.9%
Simplified90.5%
Taylor expanded in uy around 0 75.4%
Taylor expanded in maxCos around 0 72.7%
Final simplification73.8%
(FPCore (ux uy maxCos) :precision binary32 (if (<= ux 0.00020399999630171806) (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.00020399999630171806f) {
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.00020399999630171806e0) 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.00020399999630171806)) 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.00020399999630171806)) 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.00020399999630171806:\\
\;\;\;\;\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 < 2.03999996e-4Initial program 37.7%
Taylor expanded in ux around 0 92.3%
Taylor expanded in uy around 0 74.6%
if 2.03999996e-4 < ux Initial program 90.4%
associate-*l*90.4%
sub-neg90.4%
+-commutative90.4%
distribute-rgt-neg-in90.4%
fma-def90.9%
Simplified90.5%
Taylor expanded in uy around 0 75.4%
pow1/275.4%
metadata-eval75.4%
pow-to-exp75.4%
log1p-udef75.5%
Applied egg-rr75.4%
Taylor expanded in maxCos around 0 72.3%
neg-mul-172.3%
sub-neg72.3%
Simplified72.3%
Final simplification73.6%
(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 59.3%
Taylor expanded in ux around 0 75.3%
Taylor expanded in uy around 0 63.4%
Final simplification63.4%
(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 59.3%
Taylor expanded in ux around 0 75.3%
Taylor expanded in uy around 0 63.4%
Taylor expanded in maxCos around 0 61.0%
Final simplification61.0%
herbie shell --seed 2023315
(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)))))))