?

Average Error: 13.8 → 0.5
Time: 27.6s
Precision: binary32
Cost: 13408

?

\[\left(\left(2.328306437 \cdot 10^{-10} \leq ux \land ux \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq uy \land uy \leq 1\right)\right) \land \left(0 \leq maxCos \land maxCos \leq 1\right)\]
\[\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)} \]
\[\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \]
(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
 (*
  (sqrt (- (* (- 2.0 (+ maxCos maxCos)) ux) (pow (* ux (+ maxCos -1.0)) 2.0)))
  (sin (* uy (* 2.0 PI)))))
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 sqrtf((((2.0f - (maxCos + maxCos)) * ux) - powf((ux * (maxCos + -1.0f)), 2.0f))) * sinf((uy * (2.0f * ((float) M_PI))));
}
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(sqrt(Float32(Float32(Float32(Float32(2.0) - Float32(maxCos + maxCos)) * ux) - (Float32(ux * Float32(maxCos + Float32(-1.0))) ^ Float32(2.0)))) * sin(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sin(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (((single(1.0) - ux) + (ux * maxCos)) * ((single(1.0) - ux) + (ux * maxCos)))));
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((((single(2.0) - (maxCos + maxCos)) * ux) - ((ux * (maxCos + single(-1.0))) ^ single(2.0)))) * sin((uy * (single(2.0) * single(pi))));
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)}
\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 13.8

    \[\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)} \]
  2. Taylor expanded in ux around 0 0.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{\left(2 - 2 \cdot maxCos\right) \cdot ux + -1 \cdot \left({\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}\right)}} \]
  3. Simplified0.5

    \[\leadsto \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-{\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}\right)}} \]
    Proof

    [Start]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + -1 \cdot \left({\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}\right)} \]

    rational.json-simplify-2 [=>]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \color{blue}{\left({\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}\right) \cdot -1}} \]

    rational.json-simplify-9 [=>]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \color{blue}{\left(-{\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}\right)}} \]

    exponential.json-simplify-27 [=>]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-\color{blue}{{\left(\left(maxCos - 1\right) \cdot ux\right)}^{2}}\right)} \]

    rational.json-simplify-2 [=>]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-{\color{blue}{\left(ux \cdot \left(maxCos - 1\right)\right)}}^{2}\right)} \]

    rational.json-simplify-16 [=>]0.5

    \[ \sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-{\left(ux \cdot \color{blue}{\left(maxCos + -1\right)}\right)}^{2}\right)} \]
  4. Taylor expanded in uy around inf 0.5

    \[\leadsto \color{blue}{\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)} \]
  5. Simplified0.5

    \[\leadsto \color{blue}{\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\right)} \]
    Proof

    [Start]0.5

    \[ \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-2 [=>]0.5

    \[ \sqrt{\left(2 - \color{blue}{maxCos \cdot 2}\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    metadata-eval [<=]0.5

    \[ \sqrt{\left(2 - maxCos \cdot \color{blue}{\left(1 + 1\right)}\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-51 [<=]0.5

    \[ \sqrt{\left(2 - \color{blue}{\left(maxCos \cdot 1 + 1 \cdot maxCos\right)}\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-2 [<=]0.5

    \[ \sqrt{\left(2 - \left(\color{blue}{1 \cdot maxCos} + 1 \cdot maxCos\right)\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-6 [=>]0.5

    \[ \sqrt{\left(2 - \left(\color{blue}{maxCos} + 1 \cdot maxCos\right)\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-6 [=>]0.5

    \[ \sqrt{\left(2 - \left(maxCos + \color{blue}{maxCos}\right)\right) \cdot ux - {\left(maxCos - 1\right)}^{2} \cdot {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    exponential.json-simplify-27 [=>]0.5

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - \color{blue}{{\left(\left(maxCos - 1\right) \cdot ux\right)}^{2}}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-15 [<=]0.5

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(\color{blue}{\left(maxCos + -1\right)} \cdot ux\right)}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-2 [<=]0.5

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\color{blue}{\left(ux \cdot \left(maxCos + -1\right)\right)}}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational.json-simplify-2 [=>]0.5

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(2 \cdot \color{blue}{\left(\pi \cdot uy\right)}\right) \]

    rational.json-simplify-43 [<=]0.5

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \]
  6. Final simplification0.5

    \[\leadsto \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(uy \cdot \left(2 \cdot \pi\right)\right) \]

Alternatives

Alternative 1
Error2.6
Cost30984
\[\begin{array}{l} t_0 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ t_1 := \left(1 - ux\right) + ux \cdot maxCos\\ t_2 := t_0 \cdot \sqrt{1 - t_1 \cdot t_1}\\ t_3 := 1 + \left(maxCos \cdot ux - ux\right)\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(-\left(maxCos + \left(maxCos + -2\right)\right)\right)}\\ \mathbf{elif}\;t_2 \leq 0.0002500000118743628:\\ \;\;\;\;\left(uy \cdot \pi\right) \cdot \left(\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{1 - t_3 \cdot t_3}\\ \end{array} \]
Alternative 2
Error2.9
Cost23336
\[\begin{array}{l} t_0 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ t_1 := \left(2 - 2 \cdot maxCos\right) \cdot ux\\ \mathbf{if}\;t_0 \leq -0.10000000149011612:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(-\left(maxCos + \left(maxCos + -2\right)\right)\right)}\\ \mathbf{elif}\;t_0 \leq 0.006500000134110451:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{t_1 - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{t_1}\\ \end{array} \]
Alternative 3
Error2.9
Cost23336
\[\begin{array}{l} t_0 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ t_1 := \left(2 - 2 \cdot maxCos\right) \cdot ux\\ \mathbf{if}\;t_0 \leq -0.10000000149011612:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(-\left(maxCos + \left(maxCos + -2\right)\right)\right)}\\ \mathbf{elif}\;t_0 \leq 0.006500000134110451:\\ \;\;\;\;\left(uy \cdot \pi\right) \cdot \left(\sqrt{t_1 - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{t_1}\\ \end{array} \]
Alternative 4
Error0.9
Cost13376
\[\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{-\left({ux}^{2} + \left(-2 \cdot ux + ux \cdot \left(2 \cdot maxCos\right)\right)\right)} \]
Alternative 5
Error1.5
Cost13220
\[\begin{array}{l} t_0 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 0.00011999999696854502:\\ \;\;\;\;t_0 \cdot \sqrt{ux + \left(ux - {ux}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \end{array} \]
Alternative 6
Error4.4
Cost10148
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.00022000000171829015:\\ \;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 + \left(maxCos \cdot ux - ux\right)\right)}^{2}} \cdot \left(2 \cdot \left(uy \cdot \pi\right)\right)\\ \end{array} \]
Alternative 7
Error7.4
Cost9984
\[\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 8
Error8.6
Cost9856
\[\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux + ux} \]
Alternative 9
Error10.9
Cost6784
\[2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\right)\right) \]
Alternative 10
Error29.7
Cost6592
\[\left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{0} \]

Error

Reproduce?

herbie shell --seed 2023075 
(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)))))))