
(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 20 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
(fma
ux
(* 2.0 (- 1.0 maxCos))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, (2.0f * (1.0f - maxCos)), (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(2.0) * Float32(Float32(1.0) - maxCos)), Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 2 \cdot \left(1 - maxCos\right), {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in ux around 0 99.0%
fma-def99.0%
+-commutative99.0%
associate--l+99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-lft-in99.1%
metadata-eval99.1%
+-commutative99.1%
mul-1-neg99.1%
sub-neg99.1%
count-299.1%
*-commutative99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(*
ux
(+ 1.0 (fma (- 1.0 maxCos) (+ 1.0 (* ux (+ maxCos -1.0))) (- maxCos)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (1.0f + fmaf((1.0f - maxCos), (1.0f + (ux * (maxCos + -1.0f))), -maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(1.0) + fma(Float32(Float32(1.0) - maxCos), Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))), Float32(-maxCos)))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(1 + \mathsf{fma}\left(1 - maxCos, 1 + ux \cdot \left(maxCos + -1\right), -maxCos\right)\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
pow199.1%
Applied egg-rr99.0%
unpow199.0%
*-commutative99.0%
distribute-rgt1-in99.1%
fma-neg99.1%
*-commutative99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* ux (- 1.0 maxCos))))
(*
(cos (* 2.0 (* uy PI)))
(sqrt (- (+ ux (+ t_0 (* t_0 (* ux (+ maxCos -1.0))))) (* ux maxCos))))))
float code(float ux, float uy, float maxCos) {
float t_0 = ux * (1.0f - maxCos);
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((ux + (t_0 + (t_0 * (ux * (maxCos + -1.0f))))) - (ux * maxCos)));
}
function code(ux, uy, maxCos) t_0 = Float32(ux * Float32(Float32(1.0) - maxCos)) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux + Float32(t_0 + Float32(t_0 * Float32(ux * Float32(maxCos + Float32(-1.0)))))) - Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) t_0 = ux * (single(1.0) - maxCos); tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((ux + (t_0 + (t_0 * (ux * (maxCos + single(-1.0)))))) - (ux * maxCos))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := ux \cdot \left(1 - maxCos\right)\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(ux + \left(t_0 + t_0 \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)\right) - ux \cdot maxCos}
\end{array}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
associate-*r*99.1%
associate--l+99.1%
distribute-rgt-in99.1%
*-un-lft-identity99.1%
*-un-lft-identity99.1%
distribute-rgt-out--99.1%
sub-neg99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(-
(* ux (+ 1.0 (* (- 1.0 maxCos) (+ 1.0 (* ux (+ maxCos -1.0))))))
(* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((ux * (1.0f + ((1.0f - maxCos) * (1.0f + (ux * (maxCos + -1.0f)))))) - (ux * maxCos)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(1.0) + Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))))) - Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((ux * (single(1.0) + ((single(1.0) - maxCos) * (single(1.0) + (ux * (maxCos + single(-1.0))))))) - (ux * maxCos))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(1 + \left(1 - maxCos\right) \cdot \left(1 + ux \cdot \left(maxCos + -1\right)\right)\right) - ux \cdot maxCos}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
*-commutative99.1%
distribute-rgt1-in99.1%
associate--l+99.1%
*-un-lft-identity99.1%
distribute-rgt-out--99.1%
sub-neg99.1%
metadata-eval99.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* uy (* 2.0 PI)))
(sqrt
(+
ux
(* ux (- (* (- 1.0 maxCos) (+ 1.0 (* ux (+ maxCos -1.0)))) maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux + (ux * (((1.0f - maxCos) * (1.0f + (ux * (maxCos + -1.0f)))) - maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux + Float32(ux * Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0))))) - maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux + (ux * (((single(1.0) - maxCos) * (single(1.0) + (ux * (maxCos + single(-1.0))))) - maxCos)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + ux \cdot \left(\left(1 - maxCos\right) \cdot \left(1 + ux \cdot \left(maxCos + -1\right)\right) - maxCos\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
pow199.1%
Applied egg-rr99.0%
unpow199.0%
*-commutative99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* 2.0 (* uy PI))) (sqrt (- (* ux (+ 1.0 (- 1.0 ux))) (* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((ux * (1.0f + (1.0f - ux))) - (ux * maxCos)));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux * Float32(Float32(1.0) + Float32(Float32(1.0) - ux))) - Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((ux * (single(1.0) + (single(1.0) - ux))) - (ux * maxCos))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(1 + \left(1 - ux\right)\right) - ux \cdot maxCos}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
Taylor expanded in maxCos around 0 95.0%
*-commutative95.0%
distribute-rgt1-in95.0%
Simplified95.0%
Final simplification95.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0012000000569969416)
(sqrt
(+
ux
(+
(* ux (- 1.0 (* 2.0 maxCos)))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0))))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0012000000569969416f) {
tmp = sqrtf((ux + ((ux * (1.0f - (2.0f * maxCos))) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.0f))))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0012000000569969416)) tmp = sqrt(Float32(ux + Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if ((uy * single(2.0)) <= single(0.0012000000569969416)) tmp = sqrt((ux + ((ux * (single(1.0) - (single(2.0) * maxCos))) + ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (maxCos + single(-1.0))))))); else tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0012000000569969416:\\
\;\;\;\;\sqrt{ux + \left(ux \cdot \left(1 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00120000006Initial program 60.4%
associate-*l*60.4%
cancel-sign-sub-inv60.4%
+-commutative60.4%
*-commutative60.4%
fma-def60.6%
+-commutative60.6%
associate-+r-60.7%
fma-def60.7%
neg-sub060.7%
associate-+l-60.6%
associate--r-60.6%
metadata-eval60.6%
+-commutative60.6%
*-lft-identity60.6%
*-commutative60.6%
distribute-lft-out--60.6%
Simplified60.6%
fma-udef60.4%
+-commutative60.4%
fma-udef60.4%
associate-+r-60.4%
+-commutative60.4%
+-commutative60.4%
distribute-rgt-in61.2%
neg-mul-161.2%
associate-+r+67.9%
+-commutative67.9%
associate-+r-67.8%
fma-udef67.8%
+-commutative67.8%
associate-+r-67.8%
fma-udef67.8%
Applied egg-rr67.8%
Taylor expanded in uy around 0 97.9%
*-commutative97.9%
associate--l+97.9%
associate-*r*97.9%
sub-neg97.9%
*-commutative97.9%
associate-+r+97.9%
mul-1-neg97.9%
*-commutative97.9%
distribute-lft-in97.9%
+-commutative97.9%
fma-def97.9%
Simplified97.9%
Taylor expanded in ux around 0 98.0%
if 0.00120000006 < (*.f32 uy 2) Initial program 50.6%
associate-*l*50.6%
cancel-sign-sub-inv50.6%
+-commutative50.6%
*-commutative50.6%
fma-def51.0%
+-commutative51.0%
associate-+r-50.9%
fma-def50.9%
neg-sub050.9%
associate-+l-51.0%
associate--r-51.0%
metadata-eval51.0%
+-commutative51.0%
*-lft-identity51.0%
*-commutative51.0%
distribute-lft-out--50.9%
Simplified50.9%
Taylor expanded in ux around 0 80.9%
Taylor expanded in maxCos around 0 79.4%
Final simplification91.8%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (* ux (+ 1.0 (- 1.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (1.0f + (1.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(1.0) + Float32(Float32(1.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(1.0) + (single(1.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(1 + \left(1 - ux\right)\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
Taylor expanded in maxCos around 0 94.6%
*-commutative94.6%
associate-*r*94.6%
*-commutative94.6%
*-commutative94.6%
distribute-rgt1-in94.6%
Simplified94.6%
Final simplification94.6%
(FPCore (ux uy maxCos) :precision binary32 (* (cos (* uy (* 2.0 PI))) (sqrt (+ ux (* ux (- 1.0 ux))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux + (ux * (1.0f - ux))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - ux))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((uy * (single(2.0) * single(pi)))) * sqrt((ux + (ux * (single(1.0) - ux)))); end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + ux \cdot \left(1 - ux\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in maxCos around 0 94.6%
Final simplification94.6%
(FPCore (ux uy maxCos)
:precision binary32
(sqrt
(+
ux
(+
(* ux (- 1.0 (* 2.0 maxCos)))
(* (pow ux 2.0) (* (- 1.0 maxCos) (+ maxCos -1.0)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux + ((ux * (1.0f - (2.0f * maxCos))) + (powf(ux, 2.0f) * ((1.0f - maxCos) * (maxCos + -1.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 + ((ux * (1.0e0 - (2.0e0 * maxcos))) + ((ux ** 2.0e0) * ((1.0e0 - maxcos) * (maxcos + (-1.0e0)))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux + Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32((ux ^ Float32(2.0)) * Float32(Float32(Float32(1.0) - maxCos) * Float32(maxCos + Float32(-1.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux + ((ux * (single(1.0) - (single(2.0) * maxCos))) + ((ux ^ single(2.0)) * ((single(1.0) - maxCos) * (maxCos + single(-1.0))))))); end
\begin{array}{l}
\\
\sqrt{ux + \left(ux \cdot \left(1 - 2 \cdot maxCos\right) + {ux}^{2} \cdot \left(\left(1 - maxCos\right) \cdot \left(maxCos + -1\right)\right)\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around 0 80.4%
*-commutative80.4%
associate--l+80.4%
associate-*r*80.4%
sub-neg80.4%
*-commutative80.4%
associate-+r+80.4%
mul-1-neg80.4%
*-commutative80.4%
distribute-lft-in80.4%
+-commutative80.4%
fma-def80.4%
Simplified80.4%
Taylor expanded in ux around 0 80.4%
Final simplification80.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (+ 1.0 (fma (- 1.0 maxCos) (+ 1.0 (* ux (+ maxCos -1.0))) (- maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (1.0f + fmaf((1.0f - maxCos), (1.0f + (ux * (maxCos + -1.0f))), -maxCos))));
}
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(1.0) + fma(Float32(Float32(1.0) - maxCos), Float32(Float32(1.0) + Float32(ux * Float32(maxCos + Float32(-1.0)))), Float32(-maxCos))))) end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 + \mathsf{fma}\left(1 - maxCos, 1 + ux \cdot \left(maxCos + -1\right), -maxCos\right)\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around inf 99.1%
Taylor expanded in uy around 0 80.4%
sub-neg80.4%
mul-1-neg80.4%
associate-+l+80.4%
associate-*r*80.4%
sub-neg80.4%
associate-+r+80.4%
mul-1-neg80.4%
distribute-rgt-in80.4%
associate-*r*80.4%
*-commutative80.4%
associate-*r*80.4%
distribute-rgt-in80.4%
mul-1-neg80.4%
sub-neg80.4%
Simplified80.4%
Final simplification80.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (+ ux (* ux (* (- 1.0 maxCos) (- (+ 1.0 (* ux maxCos)) ux)))) (* ux maxCos))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux + (ux * ((1.0f - maxCos) * ((1.0f + (ux * maxCos)) - ux)))) - (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 + (ux * ((1.0e0 - maxcos) * ((1.0e0 + (ux * maxcos)) - ux)))) - (ux * maxcos)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux + Float32(ux * Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(Float32(1.0) + Float32(ux * maxCos)) - ux)))) - Float32(ux * maxCos))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux + (ux * ((single(1.0) - maxCos) * ((single(1.0) + (ux * maxCos)) - ux)))) - (ux * maxCos))); end
\begin{array}{l}
\\
\sqrt{\left(ux + ux \cdot \left(\left(1 - maxCos\right) \cdot \left(\left(1 + ux \cdot maxCos\right) - ux\right)\right)\right) - ux \cdot maxCos}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around 0 80.4%
Final simplification80.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ ux (- (* ux (- 1.0 ux)) (* ux maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux + ((ux * (1.0f - ux)) - (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 + ((ux * (1.0e0 - ux)) - (ux * maxcos))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux + Float32(Float32(ux * Float32(Float32(1.0) - ux)) - Float32(ux * maxCos)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux + ((ux * (single(1.0) - ux)) - (ux * maxCos)))); end
\begin{array}{l}
\\
\sqrt{ux + \left(ux \cdot \left(1 - ux\right) - ux \cdot maxCos\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around 0 80.4%
*-commutative80.4%
associate--l+80.4%
associate-*r*80.4%
sub-neg80.4%
*-commutative80.4%
associate-+r+80.4%
mul-1-neg80.4%
*-commutative80.4%
distribute-lft-in80.4%
+-commutative80.4%
fma-def80.4%
Simplified80.4%
Taylor expanded in maxCos around 0 77.5%
mul-1-neg77.5%
sub-neg77.5%
Simplified77.5%
Final simplification77.5%
(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.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around 0 80.4%
*-commutative80.4%
associate--l+80.4%
associate-*r*80.4%
sub-neg80.4%
*-commutative80.4%
associate-+r+80.4%
mul-1-neg80.4%
*-commutative80.4%
distribute-lft-in80.4%
+-commutative80.4%
fma-def80.4%
Simplified80.4%
Taylor expanded in ux around 0 63.5%
Final simplification63.5%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ ux (* ux (- 1.0 ux)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux + (ux * (1.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((ux + (ux * (1.0e0 - ux))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux + Float32(ux * Float32(Float32(1.0) - ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux + (ux * (single(1.0) - ux)))); end
\begin{array}{l}
\\
\sqrt{ux + ux \cdot \left(1 - ux\right)}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
fma-udef57.2%
+-commutative57.2%
fma-udef57.2%
associate-+r-57.2%
+-commutative57.2%
+-commutative57.2%
distribute-rgt-in57.9%
neg-mul-157.9%
associate-+r+65.4%
+-commutative65.4%
associate-+r-65.3%
fma-udef65.3%
+-commutative65.3%
associate-+r-65.3%
fma-udef65.3%
Applied egg-rr65.3%
Taylor expanded in uy around 0 80.4%
*-commutative80.4%
associate--l+80.4%
associate-*r*80.4%
sub-neg80.4%
*-commutative80.4%
associate-+r+80.4%
mul-1-neg80.4%
*-commutative80.4%
distribute-lft-in80.4%
+-commutative80.4%
fma-def80.4%
Simplified80.4%
Taylor expanded in maxCos around 0 77.2%
mul-1-neg77.2%
sub-neg77.2%
Simplified77.2%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((2.0f * ux));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((2.0e0 * ux))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(2.0) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux}
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in uy around 0 50.7%
Taylor expanded in maxCos around 0 49.5%
Taylor expanded in ux around 0 61.8%
Final simplification61.8%
(FPCore (ux uy maxCos) :precision binary32 (* ux (- (- maxCos) -1.0)))
float code(float ux, float uy, float maxCos) {
return ux * (-maxCos - -1.0f);
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = ux * (-maxcos - (-1.0e0))
end function
function code(ux, uy, maxCos) return Float32(ux * Float32(Float32(-maxCos) - Float32(-1.0))) end
function tmp = code(ux, uy, maxCos) tmp = ux * (-maxCos - single(-1.0)); end
\begin{array}{l}
\\
ux \cdot \left(\left(-maxCos\right) - -1\right)
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in uy around 0 50.7%
Applied egg-rr13.3%
Taylor expanded in ux around -inf 19.1%
Final simplification19.1%
(FPCore (ux uy maxCos) :precision binary32 (- ux (* ux maxCos)))
float code(float ux, float uy, float maxCos) {
return ux - (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 = ux - (ux * maxcos)
end function
function code(ux, uy, maxCos) return Float32(ux - Float32(ux * maxCos)) end
function tmp = code(ux, uy, maxCos) tmp = ux - (ux * maxCos); end
\begin{array}{l}
\\
ux - ux \cdot maxCos
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in uy around 0 50.7%
Applied egg-rr13.3%
Taylor expanded in maxCos around -inf 19.1%
Final simplification19.1%
(FPCore (ux uy maxCos) :precision binary32 (* ux maxCos))
float code(float ux, float uy, float maxCos) {
return 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 = ux * maxcos
end function
function code(ux, uy, maxCos) return Float32(ux * maxCos) end
function tmp = code(ux, uy, maxCos) tmp = ux * maxCos; end
\begin{array}{l}
\\
ux \cdot maxCos
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in uy around 0 50.7%
Applied egg-rr13.3%
Taylor expanded in maxCos around inf 9.4%
*-commutative9.4%
Simplified9.4%
Final simplification9.4%
(FPCore (ux uy maxCos) :precision binary32 (- ux))
float code(float ux, float uy, float maxCos) {
return -ux;
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = -ux
end function
function code(ux, uy, maxCos) return Float32(-ux) end
function tmp = code(ux, uy, maxCos) tmp = -ux; end
\begin{array}{l}
\\
-ux
\end{array}
Initial program 57.1%
associate-*l*57.1%
cancel-sign-sub-inv57.1%
+-commutative57.1%
*-commutative57.1%
fma-def57.4%
+-commutative57.4%
associate-+r-57.4%
fma-def57.4%
neg-sub057.4%
associate-+l-57.4%
associate--r-57.4%
metadata-eval57.4%
+-commutative57.4%
*-lft-identity57.4%
*-commutative57.4%
distribute-lft-out--57.4%
Simplified57.4%
Taylor expanded in uy around 0 50.7%
Applied egg-rr13.3%
Taylor expanded in maxCos around 0 4.3%
mul-1-neg4.3%
Simplified4.3%
Final simplification4.3%
herbie shell --seed 2023326
(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)))))))