?

Average Error: 13.6 → 0.3
Time: 44.0s
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)\]
\[\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 \cos \left(uy \cdot \left(2 \cdot \pi\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)))
  (cos (* uy (* 2.0 PI)))))
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))) * cosf((uy * (2.0f * ((float) M_PI))));
}
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)))) * cos(Float32(uy * Float32(Float32(2.0) * Float32(pi)))))
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)))) * cos((uy * (single(2.0) * single(pi))));
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 \cos \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.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_best.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_best.json-simplify-12 [=>]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(ux \cdot \left(maxCos - 1\right)\right)}^{2}}\right)} \]

    rational_best.json-simplify-19 [=>]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. Taylor expanded in uy around inf 0.3

    \[\leadsto \color{blue}{\cos \left(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}}} \]
  5. Simplified0.3

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

    [Start]0.3

    \[ \cos \left(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_best.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 \cos \left(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(ux \cdot \left(maxCos - 1\right)\right)}^{2}}} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \]

    rational_best.json-simplify-18 [<=]0.3

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

    rational_best.json-simplify-44 [=>]0.3

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

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

Alternatives

Alternative 1
Error3.2
Cost16420
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.9999750256538391:\\ \;\;\;\;t_0 \cdot \sqrt{2 \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \end{array} \]
Alternative 2
Error0.8
Cost13280
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {ux}^{2}} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \]
Alternative 3
Error1.3
Cost13220
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 9.999999974752427 \cdot 10^{-7}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux - {ux}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \end{array} \]
Alternative 4
Error2.8
Cost10916
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ t_1 := -\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux\\ t_2 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.9998599886894226:\\ \;\;\;\;t_2 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \sqrt{\left(t_1 \cdot \frac{1}{t_1}\right) \cdot t_1}\\ \end{array} \]
Alternative 5
Error2.8
Cost10564
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ t_1 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.9998599886894226:\\ \;\;\;\;t_1 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \end{array} \]
Alternative 6
Error2.9
Cost10116
\[\begin{array}{l} t_0 := \left(2 - 2 \cdot maxCos\right) \cdot ux\\ \mathbf{if}\;uy \cdot 2 \leq 0.0008999999845400453:\\ \;\;\;\;\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
Error6.5
Cost6848
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \]
Alternative 8
Error6.8
Cost6752
\[\sqrt{-\left({ux}^{2} + ux \cdot \left(maxCos + \left(maxCos + -2\right)\right)\right)} \]
Alternative 9
Error7.2
Cost6692
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 4.999999873689376 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{-\left({ux}^{2} + ux \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(maxCos \cdot ux\right)}\\ \end{array} \]
Alternative 10
Error8.5
Cost6660
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.00033000000985339284:\\ \;\;\;\;\sqrt{2 \cdot ux + -2 \cdot \left(maxCos \cdot ux\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 - ux\right)}^{2}}\\ \end{array} \]
Alternative 11
Error11.5
Cost3488
\[\sqrt{2 \cdot ux + -2 \cdot \left(maxCos \cdot ux\right)} \]
Alternative 12
Error11.5
Cost3424
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 13
Error12.3
Cost3296
\[\sqrt{ux \cdot 2} \]

Error

Reproduce?

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