| Alternative 1 | |
|---|---|
| Error | 4.54% |
| Cost | 30984 |
(FPCore (ux uy maxCos) :precision binary32 (* (sin (* (* uy 2.0) PI)) (sqrt (- 1.0 (* (+ (- 1.0 ux) (* ux maxCos)) (+ (- 1.0 ux) (* ux maxCos)))))))
(FPCore (ux uy maxCos)
:precision binary32
(*
(sin (* uy (* 2.0 PI)))
(cbrt
(pow
(* ux (- (fma -2.0 maxCos 2.0) (* (- 1.0 maxCos) (* ux (- 1.0 maxCos)))))
1.5))))float code(float ux, float uy, float maxCos) {
return sinf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (((1.0f - ux) + (ux * maxCos)) * ((1.0f - ux) + (ux * maxCos)))));
}
float code(float ux, float uy, float maxCos) {
return sinf((uy * (2.0f * ((float) M_PI)))) * cbrtf(powf((ux * (fmaf(-2.0f, maxCos, 2.0f) - ((1.0f - maxCos) * (ux * (1.0f - maxCos))))), 1.5f));
}
function code(ux, uy, maxCos) return Float32(sin(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) * Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)))))) end
function code(ux, uy, maxCos) return Float32(sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))) * cbrt((Float32(ux * Float32(fma(Float32(-2.0), maxCos, Float32(2.0)) - Float32(Float32(Float32(1.0) - maxCos) * Float32(ux * Float32(Float32(1.0) - maxCos))))) ^ Float32(1.5)))) end
\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}
\sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) - \left(1 - maxCos\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
Initial program 42.73
Simplified42.74
[Start]42.73 | \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}
\] |
|---|---|
associate-*l* [=>]42.73 | \[ \sin \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}
\] |
cancel-sign-sub-inv [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{1 + \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)}}
\] |
+-commutative [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right) + 1}}
\] |
*-commutative [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(-\left(\left(1 - ux\right) + ux \cdot maxCos\right)\right)} + 1}
\] |
fma-def [=>]42.61 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(\left(1 - ux\right) + ux \cdot maxCos, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}}
\] |
+-commutative [=>]42.61 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\color{blue}{ux \cdot maxCos + \left(1 - ux\right)}, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}
\] |
associate-+r- [=>]42.58 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\left(ux \cdot maxCos + 1\right) - ux}, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}
\] |
fma-def [=>]42.58 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)} - ux, -\left(\left(1 - ux\right) + ux \cdot maxCos\right), 1\right)}
\] |
neg-sub0 [=>]42.58 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, \color{blue}{0 - \left(\left(1 - ux\right) + ux \cdot maxCos\right)}, 1\right)}
\] |
+-commutative [=>]42.58 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, 0 - \color{blue}{\left(ux \cdot maxCos + \left(1 - ux\right)\right)}, 1\right)}
\] |
associate-+r- [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, 0 - \color{blue}{\left(\left(ux \cdot maxCos + 1\right) - ux\right)}, 1\right)}
\] |
associate--r- [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, \color{blue}{\left(0 - \left(ux \cdot maxCos + 1\right)\right) + ux}, 1\right)}
\] |
+-commutative [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, \color{blue}{ux + \left(0 - \left(ux \cdot maxCos + 1\right)\right)}, 1\right)}
\] |
sub0-neg [=>]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux + \color{blue}{\left(-\left(ux \cdot maxCos + 1\right)\right)}, 1\right)}
\] |
sub-neg [<=]42.73 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, \color{blue}{ux - \left(ux \cdot maxCos + 1\right)}, 1\right)}
\] |
fma-def [=>]42.74 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux - \color{blue}{\mathsf{fma}\left(ux, maxCos, 1\right)}, 1\right)}
\] |
Taylor expanded in ux around 0 1.71
Simplified1.68
[Start]1.71 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right) + ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right)}
\] |
|---|---|
+-commutative [=>]1.71 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos\right) + \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)}}
\] |
fma-def [=>]1.7 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{\mathsf{fma}\left(ux, \left(1 + -1 \cdot \left(maxCos - 1\right)\right) - maxCos, \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}}
\] |
associate--l+ [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, \color{blue}{1 + \left(-1 \cdot \left(maxCos - 1\right) - maxCos\right)}, \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
sub-neg [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(-1 \cdot \color{blue}{\left(maxCos + \left(-1\right)\right)} - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
metadata-eval [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(-1 \cdot \left(maxCos + \color{blue}{-1}\right) - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
distribute-lft-in [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(-1 \cdot maxCos + -1 \cdot -1\right)} - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
metadata-eval [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(-1 \cdot maxCos + \color{blue}{1}\right) - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
+-commutative [<=]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 + -1 \cdot maxCos\right)} - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
mul-1-neg [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 + \color{blue}{\left(-maxCos\right)}\right) - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
sub-neg [<=]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\color{blue}{\left(1 - maxCos\right)} - maxCos\right), \left(maxCos - 1\right) \cdot \left(\left(1 - maxCos\right) \cdot {ux}^{2}\right)\right)}
\] |
associate-*r* [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{\left(\left(maxCos - 1\right) \cdot \left(1 - maxCos\right)\right) \cdot {ux}^{2}}\right)}
\] |
*-commutative [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{\left(\left(1 - maxCos\right) \cdot \left(maxCos - 1\right)\right)} \cdot {ux}^{2}\right)}
\] |
associate-*l* [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \color{blue}{\left(1 - maxCos\right) \cdot \left(\left(maxCos - 1\right) \cdot {ux}^{2}\right)}\right)}
\] |
sub-neg [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \left(1 - maxCos\right) \cdot \left(\color{blue}{\left(maxCos + \left(-1\right)\right)} \cdot {ux}^{2}\right)\right)}
\] |
metadata-eval [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \left(1 - maxCos\right) \cdot \left(\left(maxCos + \color{blue}{-1}\right) \cdot {ux}^{2}\right)\right)}
\] |
+-commutative [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \left(1 - maxCos\right) \cdot \left(\color{blue}{\left(-1 + maxCos\right)} \cdot {ux}^{2}\right)\right)}
\] |
unpow2 [=>]1.68 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(ux, 1 + \left(\left(1 - maxCos\right) - maxCos\right), \left(1 - maxCos\right) \cdot \left(\left(-1 + maxCos\right) \cdot \color{blue}{\left(ux \cdot ux\right)}\right)\right)}
\] |
Applied egg-rr3.97
Simplified1.71
[Start]3.97 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot {\left({\left(\mathsf{fma}\left(ux, 2 - \left(maxCos + maxCos\right), \left(1 - maxCos\right) \cdot \left(ux \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)\right)\right)}^{1.5}\right)}^{0.3333333333333333}
\] |
|---|---|
unpow1/3 [=>]1.71 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \color{blue}{\sqrt[3]{{\left(\mathsf{fma}\left(ux, 2 - \left(maxCos + maxCos\right), \left(1 - maxCos\right) \cdot \left(ux \cdot \left(ux \cdot \left(maxCos + -1\right)\right)\right)\right)\right)}^{1.5}}}
\] |
Applied egg-rr57.81
Simplified1.72
[Start]57.81 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left({\left(ux \cdot \left(\mathsf{fma}\left(maxCos, -2, 2\right) + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}\right)} - 1}
\] |
|---|---|
expm1-def [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({\left(ux \cdot \left(\mathsf{fma}\left(maxCos, -2, 2\right) + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}\right)\right)}}
\] |
expm1-log1p [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{\color{blue}{{\left(ux \cdot \left(\mathsf{fma}\left(maxCos, -2, 2\right) + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}}
\] |
fma-udef [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\color{blue}{\left(maxCos \cdot -2 + 2\right)} + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
\] |
*-commutative [<=]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\left(\color{blue}{-2 \cdot maxCos} + 2\right) + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
\] |
fma-def [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\color{blue}{\mathsf{fma}\left(-2, maxCos, 2\right)} + ux \cdot \left(\left(maxCos + -1\right) \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
\] |
associate-*r* [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \color{blue}{\left(ux \cdot \left(maxCos + -1\right)\right) \cdot \left(1 - maxCos\right)}\right)\right)}^{1.5}}
\] |
metadata-eval [<=]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \left(ux \cdot \left(maxCos + \color{blue}{\left(-1\right)}\right)\right) \cdot \left(1 - maxCos\right)\right)\right)}^{1.5}}
\] |
sub-neg [<=]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \left(ux \cdot \color{blue}{\left(maxCos - 1\right)}\right) \cdot \left(1 - maxCos\right)\right)\right)}^{1.5}}
\] |
*-commutative [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \color{blue}{\left(\left(maxCos - 1\right) \cdot ux\right)} \cdot \left(1 - maxCos\right)\right)\right)}^{1.5}}
\] |
associate-*r* [<=]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \color{blue}{\left(maxCos - 1\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)}\right)\right)}^{1.5}}
\] |
sub-neg [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \color{blue}{\left(maxCos + \left(-1\right)\right)} \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
\] |
metadata-eval [=>]1.72 | \[ \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt[3]{{\left(ux \cdot \left(\mathsf{fma}\left(-2, maxCos, 2\right) + \left(maxCos + \color{blue}{-1}\right) \cdot \left(ux \cdot \left(1 - maxCos\right)\right)\right)\right)}^{1.5}}
\] |
Final simplification1.72
| Alternative 1 | |
|---|---|
| Error | 4.54% |
| Cost | 30984 |
| Alternative 2 | |
|---|---|
| Error | 1.72% |
| Cost | 16416 |
| Alternative 3 | |
|---|---|
| Error | 1.68% |
| Cost | 13568 |
| Alternative 4 | |
|---|---|
| Error | 1.69% |
| Cost | 10304 |
| Alternative 5 | |
|---|---|
| Error | 4.35% |
| Cost | 10052 |
| Alternative 6 | |
|---|---|
| Error | 10.5% |
| Cost | 9988 |
| Alternative 7 | |
|---|---|
| Error | 4.35% |
| Cost | 9988 |
| Alternative 8 | |
|---|---|
| Error | 23.72% |
| Cost | 7172 |
| Alternative 9 | |
|---|---|
| Error | 18.9% |
| Cost | 7104 |
| Alternative 10 | |
|---|---|
| Error | 24.79% |
| Cost | 6916 |
| Alternative 11 | |
|---|---|
| Error | 34.26% |
| Cost | 6784 |
| Alternative 12 | |
|---|---|
| Error | 34.25% |
| Cost | 6784 |
| Alternative 13 | |
|---|---|
| Error | 36.81% |
| Cost | 6656 |
herbie shell --seed 2023115
(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)))))))