
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \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 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos) :precision binary32 (let* ((t_0 (+ (- 1.0 ux) (* ux maxCos)))) (* (sin (* (* 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 sinf(((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(sin(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 = sin(((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\\
\sin \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
(*
(sin (* uy (* 2.0 PI)))
(sqrt
(fma
(+ maxCos -1.0)
(* (* ux ux) (- 1.0 maxCos))
(* ux (- 1.0 (+ maxCos (+ maxCos -1.0))))))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf((maxCos + -1.0f), ((ux * ux) * (1.0f - maxCos)), (ux * (1.0f - (maxCos + (maxCos + -1.0f))))));
}
function code(ux, uy, maxCos) return Float32(sin(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(1.0) - Float32(maxCos + Float32(maxCos + Float32(-1.0)))))))) end
\begin{array}{l}
\\
\sin \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(1 - \left(maxCos + \left(maxCos + -1\right)\right)\right)\right)}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
Final simplification98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* uy (* 2.0 PI))) (sqrt (fma ux (+ 2.0 (* maxCos -2.0)) (* (* ux ux) (+ -1.0 (* 2.0 maxCos)))))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, (2.0f + (maxCos * -2.0f)), ((ux * ux) * (-1.0f + (2.0f * maxCos)))));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))), Float32(Float32(ux * ux) * Float32(Float32(-1.0) + Float32(Float32(2.0) * maxCos)))))) end
\begin{array}{l}
\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, \left(ux \cdot ux\right) \cdot \left(-1 + 2 \cdot maxCos\right)\right)}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
associate-*r*98.3%
add-log-exp57.0%
exp-prod52.6%
exp-prod50.2%
Applied egg-rr50.2%
log-pow50.2%
log-pow50.2%
Simplified50.2%
Taylor expanded in uy around inf 98.3%
*-commutative98.3%
*-commutative98.3%
associate-*r*98.3%
+-commutative98.3%
fma-def98.3%
sub-neg98.3%
*-commutative98.3%
distribute-rgt-neg-in98.3%
metadata-eval98.3%
associate-*r*98.3%
*-commutative98.3%
unpow298.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in maxCos around 0 97.6%
Final simplification97.6%
(FPCore (ux uy maxCos) :precision binary32 (* (sqrt (* ux (+ (fma -2.0 maxCos 2.0) (* (+ maxCos -1.0) (* ux (- 1.0 maxCos)))))) (sin (* 2.0 (* uy PI)))))
float code(float ux, float uy, float maxCos) {
return sqrtf((ux * (fmaf(-2.0f, maxCos, 2.0f) + ((maxCos + -1.0f) * (ux * (1.0f - maxCos)))))) * sinf((2.0f * (uy * ((float) M_PI))));
}
function code(ux, uy, maxCos) return Float32(sqrt(Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(Float32(1.0) - maxCos)))))) * sin(Float32(Float32(2.0) * Float32(uy * Float32(pi))))) end
\begin{array}{l}
\\
\sqrt{ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
associate-*r*98.3%
add-log-exp57.0%
exp-prod52.6%
exp-prod50.2%
Applied egg-rr50.2%
log-pow50.2%
log-pow50.2%
Simplified50.2%
Taylor expanded in uy around inf 98.3%
*-commutative98.3%
*-commutative98.3%
associate-*r*98.3%
+-commutative98.3%
fma-def98.3%
sub-neg98.3%
*-commutative98.3%
distribute-rgt-neg-in98.3%
metadata-eval98.3%
associate-*r*98.3%
*-commutative98.3%
unpow298.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in uy around inf 98.3%
Simplified98.3%
Final simplification98.3%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* uy (* 2.0 PI))) (sqrt (fma ux (+ 2.0 (* maxCos -2.0)) (* ux (- ux))))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(fmaf(ux, (2.0f + (maxCos * -2.0f)), (ux * -ux)));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(fma(ux, Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))), Float32(ux * Float32(-ux))))) end
\begin{array}{l}
\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 2 + maxCos \cdot -2, ux \cdot \left(-ux\right)\right)}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
associate-*r*98.3%
add-log-exp57.0%
exp-prod52.6%
exp-prod50.2%
Applied egg-rr50.2%
log-pow50.2%
log-pow50.2%
Simplified50.2%
Taylor expanded in uy around inf 98.3%
*-commutative98.3%
*-commutative98.3%
associate-*r*98.3%
+-commutative98.3%
fma-def98.3%
sub-neg98.3%
*-commutative98.3%
distribute-rgt-neg-in98.3%
metadata-eval98.3%
associate-*r*98.3%
*-commutative98.3%
unpow298.3%
sub-neg98.3%
metadata-eval98.3%
+-commutative98.3%
Simplified98.3%
Taylor expanded in maxCos around 0 96.2%
Final simplification96.2%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0018500000005587935)
(*
(* 2.0 (* uy PI))
(sqrt
(fma
(- 1.0 maxCos)
(* (+ maxCos -1.0) (* ux ux))
(* ux (+ 2.0 (* maxCos -2.0))))))
(* (sin (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0018500000005587935f) {
tmp = (2.0f * (uy * ((float) M_PI))) * sqrtf(fmaf((1.0f - maxCos), ((maxCos + -1.0f) * (ux * ux)), (ux * (2.0f + (maxCos * -2.0f)))));
} else {
tmp = sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0018500000005587935)) tmp = Float32(Float32(Float32(2.0) * Float32(uy * Float32(pi))) * sqrt(fma(Float32(Float32(1.0) - maxCos), Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * ux)), Float32(ux * Float32(Float32(2.0) + Float32(maxCos * Float32(-2.0))))))); else tmp = Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0018500000005587935:\\
\;\;\;\;\left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(1 - maxCos, \left(maxCos + -1\right) \cdot \left(ux \cdot ux\right), ux \cdot \left(2 + maxCos \cdot -2\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00185Initial program 53.7%
associate-*l*53.7%
sub-neg53.7%
+-commutative53.7%
distribute-rgt-neg-in53.7%
fma-def53.8%
+-commutative53.8%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.8%
associate--r-53.8%
neg-sub053.8%
+-commutative53.8%
sub-neg53.8%
fma-def53.8%
Simplified53.8%
Taylor expanded in ux around 0 98.5%
fma-def98.5%
sub-neg98.5%
metadata-eval98.5%
*-commutative98.5%
unpow298.5%
associate--l+98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in uy around inf 98.5%
Taylor expanded in uy around 0 97.6%
associate-*r*97.6%
fma-def97.6%
*-commutative97.6%
unpow297.6%
sub-neg97.6%
metadata-eval97.6%
+-commutative97.6%
cancel-sign-sub-inv97.6%
metadata-eval97.6%
Simplified97.6%
if 0.00185 < (*.f32 uy 2) Initial program 54.3%
associate-*l*54.3%
sub-neg54.3%
+-commutative54.3%
distribute-rgt-neg-in54.3%
fma-def54.8%
+-commutative54.8%
associate-+r-54.5%
fma-def54.5%
neg-sub054.5%
+-commutative54.5%
associate-+r-54.4%
associate--r-54.4%
neg-sub054.4%
+-commutative54.4%
sub-neg54.4%
fma-def54.4%
Simplified54.4%
Taylor expanded in ux around 0 98.0%
fma-def98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
unpow298.0%
associate--l+98.0%
mul-1-neg98.0%
sub-neg98.0%
metadata-eval98.0%
Simplified98.0%
Taylor expanded in maxCos around 0 93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
unpow293.2%
Simplified93.2%
Final simplification96.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= (* uy 2.0) 0.0018500000005587935)
(*
2.0
(*
(sqrt
(*
ux
(+ (fma -2.0 maxCos 2.0) (* (+ maxCos -1.0) (* ux (- 1.0 maxCos))))))
(* uy PI)))
(* (sin (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if ((uy * 2.0f) <= 0.0018500000005587935f) {
tmp = 2.0f * (sqrtf((ux * (fmaf(-2.0f, maxCos, 2.0f) + ((maxCos + -1.0f) * (ux * (1.0f - maxCos)))))) * (uy * ((float) M_PI)));
} else {
tmp = sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (Float32(uy * Float32(2.0)) <= Float32(0.0018500000005587935)) tmp = Float32(Float32(2.0) * Float32(sqrt(Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) + Float32(Float32(maxCos + Float32(-1.0)) * Float32(ux * Float32(Float32(1.0) - maxCos)))))) * Float32(uy * Float32(pi)))); else tmp = Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); end return tmp end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;uy \cdot 2 \leq 0.0018500000005587935:\\
\;\;\;\;2 \cdot \left(\sqrt{ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \left(maxCos + -1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)} \cdot \left(uy \cdot \pi\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\end{array}
\end{array}
if (*.f32 uy 2) < 0.00185Initial program 53.7%
associate-*l*53.7%
sub-neg53.7%
+-commutative53.7%
distribute-rgt-neg-in53.7%
fma-def53.8%
+-commutative53.8%
associate-+r-54.0%
fma-def54.0%
neg-sub054.0%
+-commutative54.0%
associate-+r-53.8%
associate--r-53.8%
neg-sub053.8%
+-commutative53.8%
sub-neg53.8%
fma-def53.8%
Simplified53.8%
Taylor expanded in ux around 0 98.5%
fma-def98.5%
sub-neg98.5%
metadata-eval98.5%
*-commutative98.5%
unpow298.5%
associate--l+98.5%
mul-1-neg98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
associate-*r*98.5%
add-log-exp41.3%
exp-prod36.4%
exp-prod34.1%
Applied egg-rr34.1%
log-pow34.2%
log-pow34.1%
Simplified34.1%
Taylor expanded in uy around inf 98.5%
*-commutative98.5%
*-commutative98.5%
associate-*r*98.5%
+-commutative98.5%
fma-def98.4%
sub-neg98.4%
*-commutative98.4%
distribute-rgt-neg-in98.4%
metadata-eval98.4%
associate-*r*98.4%
*-commutative98.4%
unpow298.4%
sub-neg98.4%
metadata-eval98.4%
+-commutative98.4%
Simplified98.4%
Taylor expanded in uy around 0 97.6%
*-commutative97.6%
+-commutative97.6%
metadata-eval97.6%
cancel-sign-sub-inv97.6%
associate-*r*97.6%
*-commutative97.6%
Simplified97.6%
if 0.00185 < (*.f32 uy 2) Initial program 54.3%
associate-*l*54.3%
sub-neg54.3%
+-commutative54.3%
distribute-rgt-neg-in54.3%
fma-def54.8%
+-commutative54.8%
associate-+r-54.5%
fma-def54.5%
neg-sub054.5%
+-commutative54.5%
associate-+r-54.4%
associate--r-54.4%
neg-sub054.4%
+-commutative54.4%
sub-neg54.4%
fma-def54.4%
Simplified54.4%
Taylor expanded in ux around 0 98.0%
fma-def98.0%
sub-neg98.0%
metadata-eval98.0%
*-commutative98.0%
unpow298.0%
associate--l+98.0%
mul-1-neg98.0%
sub-neg98.0%
metadata-eval98.0%
Simplified98.0%
Taylor expanded in maxCos around 0 93.2%
+-commutative93.2%
mul-1-neg93.2%
unsub-neg93.2%
unpow293.2%
Simplified93.2%
Final simplification96.3%
(FPCore (ux uy maxCos)
:precision binary32
(if (<= ux 0.0002300000051036477)
(* (sin (* uy (* 2.0 PI))) (sqrt (* ux (- 2.0 (* 2.0 maxCos)))))
(*
2.0
(*
(* uy PI)
(sqrt
(+
1.0
(* (+ ux (- -1.0 (* maxCos ux))) (+ 1.0 (- (* maxCos ux) ux)))))))))
float code(float ux, float uy, float maxCos) {
float tmp;
if (ux <= 0.0002300000051036477f) {
tmp = sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf((ux * (2.0f - (2.0f * maxCos))));
} else {
tmp = 2.0f * ((uy * ((float) M_PI)) * sqrtf((1.0f + ((ux + (-1.0f - (maxCos * ux))) * (1.0f + ((maxCos * ux) - ux))))));
}
return tmp;
}
function code(ux, uy, maxCos) tmp = Float32(0.0) if (ux <= Float32(0.0002300000051036477)) tmp = Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(ux * Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos))))); else tmp = Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(Float32(1.0) + Float32(Float32(ux + Float32(Float32(-1.0) - Float32(maxCos * ux))) * Float32(Float32(1.0) + Float32(Float32(maxCos * ux) - ux))))))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) tmp = single(0.0); if (ux <= single(0.0002300000051036477)) tmp = sin((uy * (single(2.0) * single(pi)))) * sqrt((ux * (single(2.0) - (single(2.0) * maxCos)))); else tmp = single(2.0) * ((uy * single(pi)) * sqrt((single(1.0) + ((ux + (single(-1.0) - (maxCos * ux))) * (single(1.0) + ((maxCos * ux) - ux)))))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;ux \leq 0.0002300000051036477:\\
\;\;\;\;\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{1 + \left(ux + \left(-1 - maxCos \cdot ux\right)\right) \cdot \left(1 + \left(maxCos \cdot ux - ux\right)\right)}\right)\\
\end{array}
\end{array}
if ux < 2.30000005e-4Initial program 32.5%
associate-*l*32.5%
+-commutative32.5%
associate-+r-32.6%
fma-def32.6%
+-commutative32.6%
associate-+r-32.5%
fma-def32.5%
Simplified32.5%
Taylor expanded in ux around 0 92.4%
if 2.30000005e-4 < ux Initial program 90.6%
associate-*l*90.6%
sub-neg90.6%
+-commutative90.6%
distribute-rgt-neg-in90.6%
fma-def91.1%
+-commutative91.1%
associate-+r-91.1%
fma-def91.1%
neg-sub091.1%
+-commutative91.1%
associate-+r-90.7%
associate--r-90.7%
neg-sub090.7%
+-commutative90.7%
sub-neg90.7%
fma-def90.7%
Simplified90.7%
Taylor expanded in uy around 0 78.7%
pow178.7%
associate--l+79.1%
Applied egg-rr79.1%
unpow179.1%
*-commutative79.1%
Simplified79.1%
Final simplification87.5%
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* uy (* 2.0 PI))) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = sin((uy * (single(2.0) * single(pi)))) * sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in ux around 0 98.3%
fma-def98.3%
sub-neg98.3%
metadata-eval98.3%
*-commutative98.3%
unpow298.3%
associate--l+98.3%
mul-1-neg98.3%
sub-neg98.3%
metadata-eval98.3%
Simplified98.3%
Taylor expanded in maxCos around 0 91.3%
+-commutative91.3%
mul-1-neg91.3%
unsub-neg91.3%
unpow291.3%
Simplified91.3%
Final simplification91.3%
(FPCore (ux uy maxCos)
:precision binary32
(let* ((t_0 (* uy (* 2.0 PI))))
(if (<= uy 0.00279999990016222)
(* t_0 (sqrt (- (* 2.0 ux) (* ux ux))))
(* (sin t_0) (sqrt (* 2.0 ux))))))
float code(float ux, float uy, float maxCos) {
float t_0 = uy * (2.0f * ((float) M_PI));
float tmp;
if (uy <= 0.00279999990016222f) {
tmp = t_0 * sqrtf(((2.0f * ux) - (ux * ux)));
} else {
tmp = sinf(t_0) * sqrtf((2.0f * ux));
}
return tmp;
}
function code(ux, uy, maxCos) t_0 = Float32(uy * Float32(Float32(2.0) * Float32(pi))) tmp = Float32(0.0) if (uy <= Float32(0.00279999990016222)) tmp = Float32(t_0 * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))); else tmp = Float32(sin(t_0) * sqrt(Float32(Float32(2.0) * ux))); end return tmp end
function tmp_2 = code(ux, uy, maxCos) t_0 = uy * (single(2.0) * single(pi)); tmp = single(0.0); if (uy <= single(0.00279999990016222)) tmp = t_0 * sqrt(((single(2.0) * ux) - (ux * ux))); else tmp = sin(t_0) * sqrt((single(2.0) * ux)); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := uy \cdot \left(2 \cdot \pi\right)\\
\mathbf{if}\;uy \leq 0.00279999990016222:\\
\;\;\;\;t_0 \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\
\mathbf{else}:\\
\;\;\;\;\sin t_0 \cdot \sqrt{2 \cdot ux}\\
\end{array}
\end{array}
if uy < 0.0027999999Initial program 54.6%
associate-*l*54.6%
sub-neg54.6%
+-commutative54.6%
distribute-rgt-neg-in54.6%
fma-def54.8%
+-commutative54.8%
associate-+r-54.9%
fma-def54.9%
neg-sub054.9%
+-commutative54.9%
associate-+r-54.7%
associate--r-54.7%
neg-sub054.7%
+-commutative54.7%
sub-neg54.7%
fma-def54.7%
Simplified54.7%
Taylor expanded in maxCos around 0 51.2%
Taylor expanded in uy around 0 50.7%
*-commutative50.7%
associate-*r*50.7%
Simplified50.7%
Taylor expanded in ux around 0 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
unpow289.2%
Simplified89.2%
if 0.0027999999 < uy Initial program 51.6%
associate-*l*51.6%
+-commutative51.6%
associate-+r-51.5%
fma-def51.5%
+-commutative51.5%
associate-+r-51.3%
fma-def51.3%
Simplified51.3%
Taylor expanded in ux around 0 39.6%
Taylor expanded in maxCos around 0 74.4%
Final simplification85.4%
(FPCore (ux uy maxCos) :precision binary32 (* (* uy (* 2.0 PI)) (sqrt (- (* 2.0 ux) (* ux ux)))))
float code(float ux, float uy, float maxCos) {
return (uy * (2.0f * ((float) M_PI))) * sqrtf(((2.0f * ux) - (ux * ux)));
}
function code(ux, uy, maxCos) return Float32(Float32(uy * Float32(Float32(2.0) * Float32(pi))) * sqrt(Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))) end
function tmp = code(ux, uy, maxCos) tmp = (uy * (single(2.0) * single(pi))) * sqrt(((single(2.0) * ux) - (ux * ux))); end
\begin{array}{l}
\\
\left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in maxCos around 0 51.0%
Taylor expanded in uy around 0 45.4%
*-commutative45.4%
associate-*r*45.4%
Simplified45.4%
Taylor expanded in ux around 0 77.2%
+-commutative77.2%
mul-1-neg77.2%
unsub-neg77.2%
unpow277.2%
Simplified77.2%
Final simplification77.2%
(FPCore (ux uy maxCos) :precision binary32 (* (* uy (* 2.0 PI)) (sqrt (* 2.0 ux))))
float code(float ux, float uy, float maxCos) {
return (uy * (2.0f * ((float) M_PI))) * sqrtf((2.0f * ux));
}
function code(ux, uy, maxCos) return Float32(Float32(uy * Float32(Float32(2.0) * Float32(pi))) * sqrt(Float32(Float32(2.0) * ux))) end
function tmp = code(ux, uy, maxCos) tmp = (uy * (single(2.0) * single(pi))) * sqrt((single(2.0) * ux)); end
\begin{array}{l}
\\
\left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in maxCos around 0 51.0%
Taylor expanded in uy around 0 45.4%
*-commutative45.4%
associate-*r*45.4%
Simplified45.4%
Taylor expanded in ux around 0 64.2%
Final simplification64.2%
(FPCore (ux uy maxCos) :precision binary32 (* 2.0 (* (* uy PI) (sqrt 0.0))))
float code(float ux, float uy, float maxCos) {
return 2.0f * ((uy * ((float) M_PI)) * sqrtf(0.0f));
}
function code(ux, uy, maxCos) return Float32(Float32(2.0) * Float32(Float32(uy * Float32(pi)) * sqrt(Float32(0.0)))) end
function tmp = code(ux, uy, maxCos) tmp = single(2.0) * ((uy * single(pi)) * sqrt(single(0.0))); end
\begin{array}{l}
\\
2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{0}\right)
\end{array}
Initial program 53.9%
associate-*l*53.9%
sub-neg53.9%
+-commutative53.9%
distribute-rgt-neg-in53.9%
fma-def54.1%
+-commutative54.1%
associate-+r-54.1%
fma-def54.1%
neg-sub054.1%
+-commutative54.1%
associate-+r-54.0%
associate--r-54.0%
neg-sub054.0%
+-commutative54.0%
sub-neg54.0%
fma-def54.0%
Simplified54.0%
Taylor expanded in uy around 0 48.0%
Taylor expanded in ux around 0 7.2%
Final simplification7.2%
herbie shell --seed 2023175
(FPCore (ux uy maxCos)
:name "UniformSampleCone, y"
: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)))
(* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))