?

Average Error: 13.6 → 0.3
Time: 28.5s
Precision: binary32
Cost: 16672

?

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

    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 + {\left(maxCos + -1\right)}^{2} \cdot \color{blue}{\left(-{ux}^{2}\right)}} \]
  4. Final simplification0.3

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

Alternatives

Alternative 1
Error4.6
Cost16420
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.9999799728393555:\\ \;\;\;\;t_0 \cdot \sqrt{ux + ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}}\\ \end{array} \]
Alternative 2
Error0.5
Cost13504
\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + \left(-2 \cdot maxCos + 1\right) \cdot \left(-{ux}^{2}\right)} \]
Alternative 3
Error0.8
Cost13376
\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux + 1 \cdot \left(-{ux}^{2}\right)} \]
Alternative 4
Error1.2
Cost13284
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.00023499999952036887:\\ \;\;\;\;\sqrt{{\left(1 - maxCos\right)}^{2} \cdot \left(-{ux}^{2}\right) + ux \cdot \left(2 + maxCos \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}} \cdot \cos \left(\pi \cdot \left(uy \cdot 2\right)\right)\\ \end{array} \]
Alternative 5
Error2.9
Cost11588
\[\begin{array}{l} t_0 := ux - \left(1 + maxCos \cdot ux\right)\\ t_1 := 1 + \left(maxCos \cdot ux - ux\right)\\ t_2 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;\left(1 - ux\right) + ux \cdot maxCos \leq 0.9997000098228455:\\ \;\;\;\;t_2 \cdot \sqrt{1 - \left(t_0 \cdot \left(t_1 \cdot t_1\right)\right) \cdot \frac{t_1}{t_1 \cdot t_0}}\\ \mathbf{else}:\\ \;\;\;\;t_2 \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 6
Error2.8
Cost10756
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \mathbf{if}\;t_0 \leq 0.9998499751091003:\\ \;\;\;\;\cos \left(-2 - \left(\left(\pi \cdot \left(uy \cdot -2\right) + -1\right) - 1\right)\right) \cdot \sqrt{1 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 7
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.9998499751091003:\\ \;\;\;\;t_1 \cdot \sqrt{1 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 8
Error3.3
Cost10308
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;\left(1 - ux\right) + ux \cdot maxCos \leq 0.9998499751091003:\\ \;\;\;\;t_0 \cdot \sqrt{1 - \left(ux + -1\right) \cdot \left(ux + -1\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 9
Error2.9
Cost10244
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0020000000949949026:\\ \;\;\;\;\sqrt{{\left(1 - maxCos\right)}^{2} \cdot \left(-{ux}^{2}\right) + ux \cdot \left(2 + maxCos \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 10
Error4.2
Cost10180
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0020000000949949026:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 11
Error4.2
Cost10116
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0020000000949949026:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}\\ \end{array} \]
Alternative 12
Error4.2
Cost10116
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0020000000949949026:\\ \;\;\;\;\sqrt{2 \cdot ux - {ux}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \end{array} \]
Alternative 13
Error8.2
Cost6660
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.0002099999983329326:\\ \;\;\;\;\sqrt{2 \cdot ux + ux \cdot \left(-2 \cdot maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 - ux\right)}^{2}}\\ \end{array} \]
Alternative 14
Error7.7
Cost6592
\[\sqrt{2 \cdot ux - {ux}^{2}} \]
Alternative 15
Error11.3
Cost3488
\[\sqrt{2 \cdot ux + ux \cdot \left(-2 \cdot maxCos\right)} \]
Alternative 16
Error11.3
Cost3424
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 17
Error12.1
Cost3296
\[\sqrt{ux + ux} \]

Error

Reproduce?

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