?

Average Error: 13.6 → 0.3
Time: 34.6s
Precision: binary32
Cost: 13472

?

\[\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)\]
\[\cos \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 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(\pi \cdot \left(0.5 - uy \cdot 2\right)\right) \]
(FPCore (ux uy maxCos)
 :precision binary32
 (*
  (cos (* (* 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 (* 2.0 maxCos)) ux) (pow (* ux (+ maxCos -1.0)) 2.0)))
  (sin (* PI (- 0.5 (* uy 2.0))))))
float code(float ux, float uy, float maxCos) {
	return cosf(((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 - (2.0f * maxCos)) * ux) - powf((ux * (maxCos + -1.0f)), 2.0f))) * sinf((((float) M_PI) * (0.5f - (uy * 2.0f))));
}
function code(ux, uy, maxCos)
	return Float32(cos(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(Float32(2.0) * maxCos)) * ux) - (Float32(ux * Float32(maxCos + Float32(-1.0))) ^ Float32(2.0)))) * sin(Float32(Float32(pi) * Float32(Float32(0.5) - Float32(uy * Float32(2.0))))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((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) - (single(2.0) * maxCos)) * ux) - ((ux * (maxCos + single(-1.0))) ^ single(2.0)))) * sin((single(pi) * (single(0.5) - (uy * single(2.0)))));
end
\cos \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 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \sin \left(\pi \cdot \left(0.5 - uy \cdot 2\right)\right)

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 13.6

    \[\cos \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.3

    \[\leadsto \cos \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.3

    \[\leadsto \cos \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.3

    \[ \cos \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.3

    \[ \cos \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.3

    \[ \cos \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.3

    \[ \cos \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.3

    \[ \cos \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.3

    \[ \cos \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. Applied egg-rr0.3

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

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

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

    [Start]0.3

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

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

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

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

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

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

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

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

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

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

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

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

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

    rational.json-simplify-43 [=>]0.3

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

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

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

    rational.json-simplify-48 [=>]0.3

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

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

Alternatives

Alternative 1
Error0.3
Cost13408
\[\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \cos \left(\left(uy \cdot \pi\right) \cdot -2\right) \]
Alternative 2
Error1.1
Cost13348
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00019799999427050352:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\pi \cdot \left(0.5 - uy \cdot 2\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\ \end{array} \]
Alternative 3
Error0.8
Cost13344
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {ux}^{2}} \cdot \sin \left(\pi \cdot \left(0.5 - uy \cdot 2\right)\right) \]
Alternative 4
Error1.1
Cost13284
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00019799999427050352:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot \pi\right) \cdot -2\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\ \end{array} \]
Alternative 5
Error2.8
Cost10564
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \mathbf{if}\;ux \leq 0.00014000000373926014:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \sin \left(\pi \cdot \left(0.5 - 2 \cdot uy\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot uy\right) \cdot \left(\left(2 \cdot \pi\right) \cdot \frac{1}{uy}\right)\right) \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 6
Error2.8
Cost10500
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \mathbf{if}\;ux \leq 0.00014000000373926014:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \sin \left(\pi \cdot \left(0.5 - 2 \cdot uy\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(2 + \pi \cdot \left(uy + uy\right)\right) + -2\right) \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 7
Error2.7
Cost10372
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \mathbf{if}\;ux \leq 0.00014000000373926014:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \sin \left(\pi \cdot \left(0.5 - 2 \cdot uy\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 8
Error3.0
Cost10180
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0031999999191612005:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - 2 \cdot maxCos\right)} \cdot \sin \left(\pi \cdot \left(0.5 - 2 \cdot uy\right)\right)\\ \end{array} \]
Alternative 9
Error3.0
Cost10116
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0031999999191612005:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\pi \cdot \left(uy + uy\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}\\ \end{array} \]
Alternative 10
Error3.3
Cost10052
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.007499999832361937:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\pi \cdot \left(0.5 - 2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot 2}\\ \end{array} \]
Alternative 11
Error3.4
Cost9988
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.007499999832361937:\\ \;\;\;\;\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \]
Alternative 12
Error6.4
Cost6848
\[\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \]
Alternative 13
Error7.9
Cost6788
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.00014000000373926014:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 + \left(maxCos \cdot ux - ux\right)\right)}^{2}}\\ \end{array} \]
Alternative 14
Error8.4
Cost6660
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.0002500000118743628:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 - ux\right)}^{2}}\\ \end{array} \]
Alternative 15
Error11.3
Cost3424
\[\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)} \]
Alternative 16
Error11.3
Cost3424
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 17
Error12.2
Cost3296
\[\sqrt{ux \cdot 2} \]

Error

Reproduce?

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