?

Average Error: 13.6 → 0.3
Time: 1.2min
Precision: binary32
Cost: 26624

?

\[\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)} \]
\[\left(\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) - \cos \left(\frac{\pi}{2}\right) \cdot \cos \left(\frac{\pi \cdot \left(1 - uy \cdot 4\right)}{2}\right)\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-{\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}\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
 (*
  (-
   (cos (* 2.0 (* uy PI)))
   (* (cos (/ PI 2.0)) (cos (/ (* PI (- 1.0 (* uy 4.0))) 2.0))))
  (sqrt
   (+ (* (- 2.0 (* 2.0 maxCos)) ux) (- (pow (* ux (+ maxCos -1.0)) 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 (cosf((2.0f * (uy * ((float) M_PI)))) - (cosf((((float) M_PI) / 2.0f)) * cosf(((((float) M_PI) * (1.0f - (uy * 4.0f))) / 2.0f)))) * sqrtf((((2.0f - (2.0f * maxCos)) * ux) + -powf((ux * (maxCos + -1.0f)), 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(Float32(cos(Float32(Float32(2.0) * Float32(uy * Float32(pi)))) - Float32(cos(Float32(Float32(pi) / Float32(2.0))) * cos(Float32(Float32(Float32(pi) * Float32(Float32(1.0) - Float32(uy * Float32(4.0)))) / Float32(2.0))))) * sqrt(Float32(Float32(Float32(Float32(2.0) - Float32(Float32(2.0) * maxCos)) * ux) + Float32(-(Float32(ux * Float32(maxCos + Float32(-1.0))) ^ 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 = (cos((single(2.0) * (uy * single(pi)))) - (cos((single(pi) / single(2.0))) * cos(((single(pi) * (single(1.0) - (uy * single(4.0)))) / single(2.0))))) * sqrt((((single(2.0) - (single(2.0) * maxCos)) * ux) + -((ux * (maxCos + single(-1.0))) ^ 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)}
\left(\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) - \cos \left(\frac{\pi}{2}\right) \cdot \cos \left(\frac{\pi \cdot \left(1 - uy \cdot 4\right)}{2}\right)\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-{\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}\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. Simplified13.6

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

    [Start]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)} \]

    rational_best-simplify-59 [=>]13.6

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

    rational_best-simplify-59 [=>]13.6

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

    rational_best-simplify-14 [=>]13.6

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

    rational_best-simplify-51 [=>]13.6

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

    metadata-eval [=>]13.6

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

    rational_best-simplify-18 [=>]13.6

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

    rational_best-simplify-57 [=>]13.6

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

    metadata-eval [=>]13.6

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

    rational_best-simplify-3 [=>]13.6

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

    rational_best-simplify-14 [=>]13.6

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

    rational_best-simplify-51 [=>]13.6

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

    metadata-eval [=>]13.6

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

    rational_best-simplify-18 [=>]13.6

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

    rational_best-simplify-57 [=>]13.6

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

    metadata-eval [=>]13.6

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

    rational_best-simplify-3 [=>]13.6

    \[ \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(1 + \left(ux \cdot maxCos - ux\right)\right) \cdot \color{blue}{\left(1 + \left(ux \cdot maxCos - ux\right)\right)}} \]
  3. 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)}} \]
  4. 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_best-simplify-1 [=>]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_best-simplify-10 [=>]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-simplify-28 [=>]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_best-simplify-1 [=>]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_best-simplify-18 [=>]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)} \]
  5. Applied egg-rr0.3

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

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

    [Start]0.3

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

    rational_best-simplify-67 [=>]0.3

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

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

Alternatives

Alternative 1
Error0.3
Cost13408
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \]
Alternative 2
Error1.1
Cost13284
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00011000000085914508:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)\\ \end{array} \]
Alternative 3
Error0.8
Cost13280
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {ux}^{2}} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \]
Alternative 4
Error2.8
Cost10628
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;t_0 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{\frac{\left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(ux - \left(\left(\left(ux \cdot maxCos - ux\right) + ux \cdot maxCos\right) - -2\right)\right)}{2} + 1}\\ \end{array} \]
Alternative 5
Error2.8
Cost10372
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;t_0 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{\left(1 + ux \cdot \left(maxCos - 1\right)\right) \cdot \left(\left(ux + -1\right) - ux \cdot maxCos\right) + 1}\\ \end{array} \]
Alternative 6
Error2.8
Cost10116
\[\begin{array}{l} t_0 := \left(2 - 2 \cdot maxCos\right) \cdot ux\\ \mathbf{if}\;uy \cdot 2 \leq 0.0012000000569969416:\\ \;\;\;\;\sqrt{t_0 - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{t_0}\\ \end{array} \]
Alternative 7
Error3.2
Cost9988
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.001550000044517219:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\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 8
Error6.2
Cost6848
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \]
Alternative 9
Error7.6
Cost6592
\[\sqrt{ux \cdot 2 - {ux}^{2}} \]
Alternative 10
Error7.8
Cost3812
\[\begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(1 - \left(ux - ux \cdot maxCos\right)\right) \cdot \left(-1 - ux \cdot \left(-1 + maxCos\right)\right)}\\ \end{array} \]
Alternative 11
Error11.2
Cost3488
\[\sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)} \]
Alternative 12
Error11.2
Cost3424
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 13
Error12.0
Cost3296
\[\sqrt{2 \cdot ux} \]

Error

Reproduce?

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