
(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 10 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
(+
(* (+ maxCos -1.0) (* (pow ux 2.0) (- 1.0 maxCos)))
(* ux (+ 2.0 (* maxCos -2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf((((maxCos + -1.0f) * (powf(ux, 2.0f) * (1.0f - maxCos))) + (ux * (2.0f + (maxCos * -2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(Float32(maxCos + Float32(-1.0)) * Float32((ux ^ Float32(2.0)) * Float32(Float32(1.0) - maxCos))) + Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt((((maxCos + single(-1.0)) * ((ux ^ single(2.0)) * (single(1.0) - maxCos))) + (ux * (single(2.0) + (maxCos * single(-2.0)))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(maxCos + -1\right) \cdot \left({ux}^{2} \cdot \left(1 - maxCos\right)\right) + ux \cdot \left(2 + maxCos \cdot -2\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in ux around 0 99.1%
fma-def99.1%
sub-neg99.1%
metadata-eval99.1%
*-commutative99.1%
unpow299.1%
associate--l+99.1%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 99.1%
Taylor expanded in uy around inf 99.0%
Taylor expanded in ux around inf 99.1%
Final simplification99.1%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(+
(* maxCos (* 2.0 (- (* ux ux) ux)))
(- (* ux (- 2.0 ux)) (* (* maxCos ux) (* maxCos ux)))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(((maxCos * (2.0f * ((ux * ux) - ux))) + ((ux * (2.0f - ux)) - ((maxCos * ux) * (maxCos * ux)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(maxCos * Float32(Float32(2.0) * Float32(Float32(ux * ux) - ux))) + Float32(Float32(ux * Float32(Float32(2.0) - ux)) - Float32(Float32(maxCos * ux) * Float32(maxCos * ux)))))) end
function tmp = code(ux, uy, maxCos) tmp = cos((single(2.0) * (uy * single(pi)))) * sqrt(((maxCos * (single(2.0) * ((ux * ux) - ux))) + ((ux * (single(2.0) - ux)) - ((maxCos * ux) * (maxCos * ux))))); end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{maxCos \cdot \left(2 \cdot \left(ux \cdot ux - ux\right)\right) + \left(ux \cdot \left(2 - ux\right) - \left(maxCos \cdot ux\right) \cdot \left(maxCos \cdot ux\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in ux around 0 99.1%
fma-def99.1%
sub-neg99.1%
metadata-eval99.1%
*-commutative99.1%
unpow299.1%
associate--l+99.1%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 99.1%
Taylor expanded in uy around inf 99.0%
Taylor expanded in maxCos around -inf 99.1%
Simplified99.0%
Final simplification99.0%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* 2.0 uy) 0.0001049999991664663)
(sqrt
(fma
(- 1.0 maxCos)
(* (* ux ux) (+ maxCos -1.0))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))
(* (cos (* PI (* 2.0 uy))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((2.0f * uy) <= 0.0001049999991664663f) {
tmp = sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos + -1.0f)), (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(Float32(2.0) * uy) <= Float32(0.0001049999991664663)) tmp = sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos + Float32(-1.0))), Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;2 \cdot uy \leq 0.0001049999991664663:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos + -1\right), ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 1.04999999e-4Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def58.7%
+-commutative58.7%
associate-+r-58.9%
fma-def58.9%
neg-sub058.9%
+-commutative58.9%
associate-+r-58.7%
associate--r-58.7%
neg-sub058.7%
+-commutative58.7%
sub-neg58.7%
fma-def58.7%
Simplified58.7%
Taylor expanded in uy around 0 58.8%
Taylor expanded in ux around 0 99.7%
fma-def99.7%
sub-neg99.7%
metadata-eval99.7%
unpow299.7%
mul-1-neg99.7%
sub-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 1.04999999e-4 < (*.f32 uy 2) Initial program 56.4%
associate-*l*56.4%
sub-neg56.4%
+-commutative56.4%
distribute-rgt-neg-in56.4%
fma-def56.4%
+-commutative56.4%
associate-+r-56.4%
fma-def56.4%
neg-sub056.4%
+-commutative56.4%
associate-+r-56.4%
associate--r-56.4%
neg-sub056.4%
+-commutative56.4%
sub-neg56.4%
fma-def56.4%
Simplified56.4%
Taylor expanded in ux around 0 98.4%
fma-def98.4%
sub-neg98.4%
metadata-eval98.4%
*-commutative98.4%
unpow298.4%
associate--l+98.5%
distribute-rgt-in98.5%
*-lft-identity98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
distribute-neg-in98.5%
metadata-eval98.5%
+-commutative98.5%
sub-neg98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 94.7%
associate-*r*94.7%
+-commutative94.7%
mul-1-neg94.7%
unsub-neg94.7%
*-commutative94.7%
unpow294.7%
Simplified94.7%
Final simplification97.4%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 5.199999941396527e-5)
(sqrt
(fma
(- 1.0 maxCos)
(* (* ux ux) (+ maxCos -1.0))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))
(* (cos (* PI (* 2.0 uy))) (sqrt (* ux (- 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 5.199999941396527e-5f) {
tmp = sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos + -1.0f)), (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
} else {
tmp = cosf((((float) M_PI) * (2.0f * uy))) * sqrtf((ux * (2.0f - ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(5.199999941396527e-5)) tmp = sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos + Float32(-1.0))), Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)))); else tmp = Float32(cos(Float32(Float32(pi) * Float32(Float32(2.0) * uy))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 5.199999941396527 \cdot 10^{-5}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos + -1\right), ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\
\end{array}
\end{array}
if uy < 5.19999994e-5Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def58.7%
+-commutative58.7%
associate-+r-58.9%
fma-def58.9%
neg-sub058.9%
+-commutative58.9%
associate-+r-58.7%
associate--r-58.7%
neg-sub058.7%
+-commutative58.7%
sub-neg58.7%
fma-def58.7%
Simplified58.7%
Taylor expanded in uy around 0 58.8%
Taylor expanded in ux around 0 99.7%
fma-def99.7%
sub-neg99.7%
metadata-eval99.7%
unpow299.7%
mul-1-neg99.7%
sub-neg99.7%
metadata-eval99.7%
Simplified99.7%
if 5.19999994e-5 < uy Initial program 56.4%
associate-*l*56.4%
sub-neg56.4%
+-commutative56.4%
distribute-rgt-neg-in56.4%
fma-def56.4%
+-commutative56.4%
associate-+r-56.4%
fma-def56.4%
neg-sub056.4%
+-commutative56.4%
associate-+r-56.4%
associate--r-56.4%
neg-sub056.4%
+-commutative56.4%
sub-neg56.4%
fma-def56.4%
Simplified56.4%
Taylor expanded in ux around 0 98.4%
fma-def98.4%
sub-neg98.4%
metadata-eval98.4%
*-commutative98.4%
unpow298.4%
associate--l+98.5%
distribute-rgt-in98.5%
*-lft-identity98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
distribute-neg-in98.5%
metadata-eval98.5%
+-commutative98.5%
sub-neg98.5%
Simplified98.5%
Taylor expanded in maxCos around 0 98.5%
Taylor expanded in uy around inf 98.5%
Taylor expanded in maxCos around 0 94.7%
+-commutative94.7%
mul-1-neg94.7%
sub-neg94.7%
associate-*r*94.7%
sub-neg94.7%
*-commutative94.7%
unpow294.7%
distribute-rgt-neg-in94.7%
distribute-lft-in94.6%
sub-neg94.6%
Simplified94.6%
Final simplification97.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.002420000033453107)
(sqrt
(fma
(- 1.0 maxCos)
(* (* ux ux) (+ maxCos -1.0))
(* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* 2.0 ux)))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.002420000033453107f) {
tmp = sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos + -1.0f)), (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
} 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 (uy <= Float32(0.002420000033453107)) tmp = sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos + Float32(-1.0))), Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.002420000033453107:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos + -1\right), ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.00242000003Initial program 60.0%
associate-*l*60.0%
sub-neg60.0%
+-commutative60.0%
distribute-rgt-neg-in60.0%
fma-def60.0%
+-commutative60.0%
associate-+r-60.2%
fma-def60.2%
neg-sub060.2%
+-commutative60.2%
associate-+r-60.0%
associate--r-60.0%
neg-sub060.0%
+-commutative60.0%
sub-neg60.0%
fma-def60.0%
Simplified60.0%
Taylor expanded in uy around 0 58.8%
Taylor expanded in ux around 0 95.8%
fma-def95.8%
sub-neg95.8%
metadata-eval95.8%
unpow295.8%
mul-1-neg95.8%
sub-neg95.8%
metadata-eval95.8%
Simplified95.8%
if 0.00242000003 < uy Initial program 51.7%
associate-*l*51.7%
sub-neg51.7%
+-commutative51.7%
distribute-rgt-neg-in51.7%
fma-def51.5%
+-commutative51.5%
associate-+r-51.5%
fma-def51.5%
neg-sub051.5%
+-commutative51.5%
associate-+r-51.5%
associate--r-51.5%
neg-sub051.5%
+-commutative51.5%
sub-neg51.5%
fma-def51.5%
Simplified51.5%
Taylor expanded in maxCos around 0 51.4%
+-commutative51.4%
*-commutative51.4%
fma-def51.3%
sub-neg51.3%
metadata-eval51.3%
Simplified51.3%
Taylor expanded in ux around 0 78.4%
*-commutative37.1%
Simplified78.4%
Final simplification91.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 1.0 (* 2.0 maxCos))) (+ ux (* (+ maxCos -1.0) (* (pow ux 2.0) (- 1.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (1.0f - (2.0f * maxCos))) + (ux + ((maxCos + -1.0f) * (powf(ux, 2.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 * (1.0e0 - (2.0e0 * maxcos))) + (ux + ((maxcos + (-1.0e0)) * ((ux ** 2.0e0) * (1.0e0 - maxcos))))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(1.0) - Float32(Float32(2.0) * maxCos))) + Float32(ux + Float32(Float32(maxCos + Float32(-1.0)) * Float32((ux ^ Float32(2.0)) * Float32(Float32(1.0) - maxCos)))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(1.0) - (single(2.0) * maxCos))) + (ux + ((maxCos + single(-1.0)) * ((ux ^ single(2.0)) * (single(1.0) - maxCos)))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(1 - 2 \cdot maxCos\right) + \left(ux + \left(maxCos + -1\right) \cdot \left({ux}^{2} \cdot \left(1 - maxCos\right)\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in ux around 0 99.1%
fma-def99.1%
sub-neg99.1%
metadata-eval99.1%
*-commutative99.1%
unpow299.1%
associate--l+99.1%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in uy around 0 79.9%
Final simplification79.9%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (- 1.0 maxCos) (* (* ux ux) (+ maxCos -1.0)) (* ux (- (+ 1.0 (- 1.0 maxCos)) maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos + -1.0f)), (ux * ((1.0f + (1.0f - maxCos)) - maxCos))));
}
function code(ux, uy, maxCos) return sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos + Float32(-1.0))), Float32(ux * Float32(Float32(Float32(1.0) + Float32(Float32(1.0) - maxCos)) - maxCos)))) end
\begin{array}{l}
\\
\sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos + -1\right), ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in uy around 0 50.7%
Taylor expanded in ux around 0 80.0%
fma-def80.0%
sub-neg80.0%
metadata-eval80.0%
unpow280.0%
mul-1-neg80.0%
sub-neg80.0%
metadata-eval80.0%
Simplified80.0%
Final simplification80.0%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (- (* 2.0 ux) (* ux ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((2.0f * ux) - (ux * 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) - (ux * ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in uy around 0 50.7%
Taylor expanded in ux around -inf 80.0%
+-commutative80.0%
metadata-eval80.0%
cancel-sign-sub-inv80.0%
*-commutative80.0%
fma-def80.0%
cancel-sign-sub-inv80.0%
metadata-eval80.0%
+-commutative80.0%
fma-def80.0%
associate-*r*80.0%
mul-1-neg80.0%
unpow280.0%
neg-mul-180.0%
sub-neg80.0%
Simplified80.0%
Taylor expanded in maxCos around 0 76.1%
+-commutative76.1%
mul-1-neg76.1%
unsub-neg76.1%
*-commutative76.1%
unpow276.1%
Simplified76.1%
Final simplification76.1%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* ux (- 2.0 ux))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (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((ux * (2.0e0 - ux)))
end function
function code(ux, uy, maxCos) return sqrt(Float32(ux * Float32(Float32(2.0) - ux))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((ux * (single(2.0) - ux))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - ux\right)}
\end{array}
Initial program 57.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in ux around 0 99.1%
fma-def99.1%
sub-neg99.1%
metadata-eval99.1%
*-commutative99.1%
unpow299.1%
associate--l+99.1%
distribute-rgt-in99.1%
*-lft-identity99.1%
mul-1-neg99.1%
sub-neg99.1%
metadata-eval99.1%
distribute-neg-in99.1%
metadata-eval99.1%
+-commutative99.1%
sub-neg99.1%
Simplified99.1%
Taylor expanded in maxCos around 0 93.9%
associate-*r*93.9%
+-commutative93.9%
mul-1-neg93.9%
unsub-neg93.9%
*-commutative93.9%
unpow293.9%
Simplified93.9%
Taylor expanded in uy around 0 76.1%
sub-neg76.1%
*-commutative76.1%
unpow276.1%
distribute-rgt-neg-in76.1%
distribute-lft-in76.1%
sub-neg76.1%
Simplified76.1%
Final simplification76.1%
(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.7%
associate-*l*57.7%
sub-neg57.7%
+-commutative57.7%
distribute-rgt-neg-in57.7%
fma-def57.7%
+-commutative57.7%
associate-+r-57.8%
fma-def57.8%
neg-sub057.8%
+-commutative57.8%
associate-+r-57.7%
associate--r-57.7%
neg-sub057.7%
+-commutative57.7%
sub-neg57.7%
fma-def57.7%
Simplified57.7%
Taylor expanded in uy around 0 50.7%
Taylor expanded in maxCos around 0 49.5%
+-commutative49.5%
*-commutative49.5%
fma-def49.5%
sub-neg49.5%
metadata-eval49.5%
Simplified49.5%
Taylor expanded in ux around 0 61.3%
*-commutative61.3%
Simplified61.3%
Final simplification61.3%
herbie shell --seed 2023199
(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)))))))