
(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 11 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
(- maxCos 1.0)
(* (* ux ux) (- 1.0 maxCos))
(* ux (+ 2.0 (* maxCos -2.0)))))))
float code(float ux, float uy, float maxCos) {
return cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos - 1.0f), ((ux * ux) * (1.0f - maxCos)), (ux * (2.0f + (maxCos * -2.0f)))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(Float32(maxCos - Float32(1.0)), Float32(Float32(ux * ux) * Float32(Float32(1.0) - maxCos)), Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))))))) end
\begin{array}{l}
\\
\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(maxCos - 1, \left(ux \cdot ux\right) \cdot \left(1 - maxCos\right), ux \cdot \left(2 + maxCos \cdot -2\right)\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in maxCos around 0 98.9%
Final simplification98.9%
(FPCore (ux uy maxCos)
:precision binary32
(*
(cos (* 2.0 (* uy PI)))
(sqrt
(fma
(- 1.0 maxCos)
(* (* ux ux) (- maxCos 1.0))
(* ux (- (- 2.0 maxCos) maxCos))))))
float code(float ux, float uy, float maxCos) {
return cosf((2.0f * (uy * ((float) M_PI)))) * sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos - 1.0f)), (ux * ((2.0f - maxCos) - maxCos))));
}
function code(ux, uy, maxCos) return Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) * sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos - Float32(1.0))), Float32(ux * Float32(Float32(Float32(2.0) - maxCos) - maxCos))))) end
\begin{array}{l}
\\
\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos - 1\right), ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
expm1-log1p-u98.7%
expm1-udef98.7%
Applied egg-rr98.7%
pow198.7%
expm1-def98.7%
expm1-log1p-u98.8%
unsub-neg98.8%
Applied egg-rr98.8%
Simplified98.8%
Final simplification98.8%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= uy 0.001500000013038516)
(sqrt
(fma
(- 1.0 maxCos)
(* (* ux ux) (- maxCos 1.0))
(* ux (- (- 2.0 maxCos) maxCos))))
(* (cos (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (uy <= 0.001500000013038516f) {
tmp = sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos - 1.0f)), (ux * ((2.0f - maxCos) - maxCos))));
} else {
tmp = cosf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (uy <= Float32(0.001500000013038516)) tmp = sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(ux * ux) * Float32(maxCos - Float32(1.0))), Float32(ux * Float32(Float32(Float32(2.0) - maxCos) - maxCos)))); else tmp = Float32(cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \leq 0.001500000013038516:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(1 - maxCos, \left(ux \cdot ux\right) \cdot \left(maxCos - 1\right), ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if uy < 0.00150000001Initial program 58.8%
associate-*l*58.8%
sub-neg58.8%
+-commutative58.8%
distribute-rgt-neg-in58.8%
fma-def58.9%
+-commutative58.9%
associate-+r-59.0%
fma-def59.0%
neg-sub059.0%
+-commutative59.0%
associate-+r-58.9%
associate--r-58.9%
neg-sub058.9%
+-commutative58.9%
sub-neg58.9%
fma-def58.9%
Simplified58.9%
Taylor expanded in ux around 0 99.4%
fma-def99.4%
sub-neg99.4%
metadata-eval99.4%
*-commutative99.4%
unpow299.4%
mul-1-neg99.4%
sub-neg99.4%
metadata-eval99.4%
Simplified99.4%
expm1-log1p-u99.4%
expm1-udef99.4%
Applied egg-rr99.4%
pow199.4%
expm1-def99.4%
expm1-log1p-u99.4%
unsub-neg99.4%
Applied egg-rr99.4%
Simplified99.5%
Taylor expanded in uy around 0 95.8%
if 0.00150000001 < uy Initial program 51.9%
associate-*l*51.9%
+-commutative51.9%
associate-+r-52.1%
fma-def52.1%
+-commutative52.1%
associate-+r-51.8%
fma-def51.8%
Simplified51.8%
Taylor expanded in ux around 0 78.4%
Final simplification90.6%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= maxCos 0.0002899999963119626)
(* (cos (* PI (* uy 2.0))) (sqrt (- (* 2.0 ux) (* ux ux))))
(sqrt
(+
(* (- 1.0 maxCos) (* (* ux ux) (- maxCos 1.0)))
(* ux (- 2.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (maxCos <= 0.0002899999963119626f) {
tmp = cosf((((float) M_PI) * (uy * 2.0f))) * sqrtf(((2.0f * ux) - (ux * ux)));
} else {
tmp = sqrtf((((1.0f - maxCos) * ((ux * ux) * (maxCos - 1.0f))) + (ux * (2.0f - (2.0f * maxCos)))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (maxCos <= Float32(0.0002899999963119626)) tmp = Float32(cos(Float32(Float32(pi) * Float32(uy * Float32(2.0)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); else tmp = sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(ux * ux) * Float32(maxCos - Float32(1.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (maxCos <= single(0.0002899999963119626)) tmp = cos((single(pi) * (uy * single(2.0)))) * sqrt(((single(2.0) * ux) - (ux * ux))); else tmp = sqrt((((single(1.0) - maxCos) * ((ux * ux) * (maxCos - single(1.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;maxCos \leq 0.0002899999963119626:\\
\;\;\;\;\cos \left(\pi \cdot \left(uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\left(1 - maxCos\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(maxCos - 1\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\end{array}
\end{array}
if maxCos < 2.89999996e-4Initial program 56.1%
associate-*l*56.1%
+-commutative56.1%
associate-+r-56.1%
fma-def56.1%
+-commutative56.1%
associate-+r-56.1%
fma-def56.1%
Simplified56.1%
Taylor expanded in ux around -inf 98.8%
metadata-eval98.8%
cancel-sign-sub-inv98.8%
*-commutative98.8%
fma-def98.8%
cancel-sign-sub-inv98.8%
metadata-eval98.8%
+-commutative98.8%
*-commutative98.8%
fma-def98.8%
mul-1-neg98.8%
*-commutative98.8%
distribute-rgt-neg-in98.8%
mul-1-neg98.8%
sub-neg98.8%
unpow298.8%
distribute-rgt-neg-in98.8%
Simplified98.8%
Taylor expanded in maxCos around 0 97.3%
associate-*r*97.3%
+-commutative97.3%
neg-mul-197.3%
unsub-neg97.3%
unpow297.3%
Simplified97.3%
if 2.89999996e-4 < maxCos Initial program 62.0%
associate-*l*62.0%
sub-neg62.0%
+-commutative62.0%
distribute-rgt-neg-in62.0%
fma-def61.9%
+-commutative61.9%
associate-+r-62.9%
fma-def62.9%
neg-sub062.9%
+-commutative62.9%
associate-+r-61.9%
associate--r-61.9%
neg-sub061.9%
+-commutative61.9%
sub-neg61.9%
fma-def61.9%
Simplified61.9%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 80.6%
Taylor expanded in maxCos around 0 80.6%
distribute-rgt-out80.6%
metadata-eval80.6%
sub-neg80.6%
*-commutative80.6%
sub-neg80.6%
metadata-eval80.6%
unpow280.6%
Simplified80.6%
Final simplification95.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (fma (- 1.0 maxCos) (* (* ux ux) (- maxCos 1.0)) (* ux (- (- 2.0 maxCos) maxCos)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(fmaf((1.0f - maxCos), ((ux * ux) * (maxCos - 1.0f)), (ux * ((2.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(2.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(2 - maxCos\right) - maxCos\right)\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
expm1-log1p-u98.7%
expm1-udef98.7%
Applied egg-rr98.7%
pow198.7%
expm1-def98.7%
expm1-log1p-u98.8%
unsub-neg98.8%
Applied egg-rr98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* (- 1.0 maxCos) (* (* ux ux) (- maxCos 1.0))) (* ux (- 2.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf((((1.0f - maxCos) * ((ux * ux) * (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((((1.0e0 - maxcos) * ((ux * ux) * (maxcos - 1.0e0))) + (ux * (2.0e0 - (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(Float32(Float32(1.0) - maxCos) * Float32(Float32(ux * ux) * Float32(maxCos - Float32(1.0)))) + Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((((single(1.0) - maxCos) * ((ux * ux) * (maxCos - single(1.0)))) + (ux * (single(2.0) - (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{\left(1 - maxCos\right) \cdot \left(\left(ux \cdot ux\right) \cdot \left(maxCos - 1\right)\right) + ux \cdot \left(2 - 2 \cdot maxCos\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 79.3%
distribute-rgt-out79.3%
metadata-eval79.3%
sub-neg79.3%
*-commutative79.3%
sub-neg79.3%
metadata-eval79.3%
unpow279.3%
Simplified79.3%
Final simplification79.3%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 2.0 (* 2.0 maxCos))) (* (* ux ux) (+ -1.0 (* 2.0 maxCos))))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) + ((ux * ux) * (-1.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))) + ((ux * ux) * ((-1.0e0) + (2.0e0 * maxcos)))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) + Float32(Float32(ux * ux) * Float32(Float32(-1.0) + Float32(Float32(2.0) * maxCos))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) + ((ux * ux) * (single(-1.0) + (single(2.0) * maxCos))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \left(ux \cdot ux\right) \cdot \left(-1 + 2 \cdot maxCos\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 78.4%
+-commutative78.4%
associate-*r*78.4%
distribute-rgt-out78.4%
unpow278.4%
*-commutative78.4%
Simplified78.4%
Final simplification78.4%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (+ (* ux (- 2.0 (* 2.0 maxCos))) (* (* ux ux) (- maxCos 1.0)))))
float code(float ux, float uy, float maxCos) {
return sqrtf(((ux * (2.0f - (2.0f * maxCos))) + ((ux * 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 = sqrt(((ux * (2.0e0 - (2.0e0 * maxcos))) + ((ux * ux) * (maxcos - 1.0e0))))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))) + Float32(Float32(ux * ux) * Float32(maxCos - Float32(1.0))))) end
function tmp = code(ux, uy, maxCos) tmp = sqrt(((ux * (single(2.0) - (single(2.0) * maxCos))) + ((ux * ux) * (maxCos - single(1.0))))); end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right) + \left(ux \cdot ux\right) \cdot \left(maxCos - 1\right)}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 78.0%
mul-1-neg78.0%
unpow278.0%
distribute-rgt-neg-in78.0%
Simplified78.0%
Final simplification78.0%
(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.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in ux around 0 64.2%
Final simplification64.2%
(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 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in maxCos around 0 74.7%
+-commutative74.7%
mul-1-neg74.7%
unsub-neg74.7%
*-commutative74.7%
unpow274.7%
Simplified74.7%
Final simplification74.7%
(FPCore (ux uy maxCos) :precision binary32 (sqrt (* 2.0 ux)))
float code(float ux, float uy, float maxCos) {
return sqrtf((2.0f * ux));
}
real(4) function code(ux, uy, maxcos)
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = sqrt((2.0e0 * ux))
end function
function code(ux, uy, maxCos) return sqrt(Float32(Float32(2.0) * ux)) end
function tmp = code(ux, uy, maxCos) tmp = sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\sqrt{2 \cdot ux}
\end{array}
Initial program 56.8%
associate-*l*56.8%
sub-neg56.8%
+-commutative56.8%
distribute-rgt-neg-in56.8%
fma-def56.8%
+-commutative56.8%
associate-+r-56.9%
fma-def56.9%
neg-sub056.9%
+-commutative56.9%
associate-+r-56.8%
associate--r-56.8%
neg-sub056.8%
+-commutative56.8%
sub-neg56.8%
fma-def56.8%
Simplified56.8%
Taylor expanded in ux around 0 98.8%
fma-def98.8%
sub-neg98.8%
metadata-eval98.8%
*-commutative98.8%
unpow298.8%
mul-1-neg98.8%
sub-neg98.8%
metadata-eval98.8%
Simplified98.8%
Taylor expanded in uy around 0 79.3%
Taylor expanded in ux around 0 64.2%
Taylor expanded in maxCos around 0 61.8%
*-commutative61.8%
Simplified61.8%
Final simplification61.8%
herbie shell --seed 2023194
(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)))))))