?

Average Error: 13.5 → 0.5
Time: 34.4s
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.5

    \[\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-47 [<=]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
Cost32200
\[\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 := \left(ux + -1\right) - ux \cdot maxCos\\ t_4 := 1 - t_3 \cdot t_3\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;t_0 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{elif}\;t_2 \leq 0.00031999999191612005:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{\frac{1}{t_4} \cdot \left(t_4 \cdot t_4\right)}\\ \end{array} \]
Alternative 2
Error2.6
Cost30984
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ t_1 := \sin \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ t_2 := t_1 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \mathbf{if}\;t_2 \leq 0:\\ \;\;\;\;t_1 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{elif}\;t_2 \leq 0.00031999999191612005:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error1.3
Cost13284
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00019799999427050352:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux - \left({ux}^{2} - ux\right)} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\\ \end{array} \]
Alternative 4
Error1.3
Cost13284
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00019799999427050352:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot \sin \left(2 \cdot \left(uy \cdot \pi\right)\right)\\ \end{array} \]
Alternative 5
Error3.0
Cost10340
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.007499999832361937:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \end{array} \]
Alternative 6
Error3.3
Cost10212
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0031999999191612005:\\ \;\;\;\;2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {ux}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \end{array} \]
Alternative 7
Error4.3
Cost10052
\[\begin{array}{l} \mathbf{if}\;ux \leq 7.000000186963007 \cdot 10^{-5}:\\ \;\;\;\;\sin \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;uy \cdot \left(\sqrt{ux \cdot 2 - {ux}^{2}} \cdot \left(2 \cdot \pi\right)\right)\\ \end{array} \]
Alternative 8
Error7.4
Cost9952
\[2 \cdot \left(\pi \cdot \left(\sqrt{ux \cdot 2 - {ux}^{2}} \cdot uy\right)\right) \]
Alternative 9
Error7.4
Cost9952
\[uy \cdot \left(\sqrt{ux \cdot 2 - {ux}^{2}} \cdot \left(2 \cdot \pi\right)\right) \]
Alternative 10
Error10.9
Cost6784
\[2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{ux \cdot \left(2 - \left(maxCos + maxCos\right)\right)}\right)\right) \]
Alternative 11
Error10.9
Cost6784
\[2 \cdot \left(\left(uy \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\right) \]
Alternative 12
Error11.8
Cost6656
\[2 \cdot \left(uy \cdot \left(\pi \cdot \sqrt{ux + ux}\right)\right) \]
Alternative 13
Error11.8
Cost6656
\[2 \cdot \left(\left(\pi \cdot uy\right) \cdot \sqrt{ux + ux}\right) \]

Error

Reproduce?

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