Average Error: 13.7 → 0.3
Time: 15.7s
Precision: binary32
Cost: 10176
\[\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(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(ux - ux \cdot maxCos\right) \cdot \left(\left(2 + ux \cdot maxCos\right) - ux\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)))
  (sqrt (* (- ux (* ux maxCos)) (- (+ 2.0 (* ux maxCos)) ux)))))
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)))) * sqrtf(((ux - (ux * maxCos)) * ((2.0f + (ux * maxCos)) - ux)));
}
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(2.0) * Float32(uy * Float32(pi)))) * sqrt(Float32(Float32(ux - Float32(ux * maxCos)) * Float32(Float32(Float32(2.0) + Float32(ux * maxCos)) - ux))))
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)))) * sqrt(((ux - (ux * maxCos)) * ((single(2.0) + (ux * maxCos)) - ux)));
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(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(ux - ux \cdot maxCos\right) \cdot \left(\left(2 + ux \cdot maxCos\right) - ux\right)}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 13.7

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

    \[\leadsto \color{blue}{\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{fma}\left(\mathsf{fma}\left(ux, maxCos, 1\right) - ux, ux - \mathsf{fma}\left(ux, maxCos, 1\right), 1\right)}} \]
  3. Taylor expanded in ux around 0 0.3

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

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

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

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

Alternatives

Alternative 1
Error0.3
Cost10176
\[\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(\left(2 + ux \cdot maxCos\right) - ux\right)\right)} \]
Alternative 2
Error1.5
Cost10052
\[\begin{array}{l} t_0 := \cos \left(\pi \cdot \left(2 \cdot uy\right)\right)\\ \mathbf{if}\;maxCos \leq 0.0006000000284984708:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}\\ \end{array} \]
Alternative 3
Error1.4
Cost10052
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 0.0006000000284984708:\\ \;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \]
Alternative 4
Error0.7
Cost10048
\[\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(1 - maxCos\right) \cdot \left(ux \cdot \left(2 - ux\right)\right)} \]
Alternative 5
Error3.2
Cost9988
\[\begin{array}{l} \mathbf{if}\;2 \cdot uy \leq 0.002520000096410513:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(2 + maxCos \cdot -2\right) - ux \cdot {\left(1 - maxCos\right)}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \]
Alternative 6
Error2.3
Cost9920
\[\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)} \]
Alternative 7
Error6.3
Cost6848
\[\sqrt{ux \cdot \left(\left(2 + maxCos \cdot -2\right) - ux \cdot {\left(1 - maxCos\right)}^{2}\right)} \]
Alternative 8
Error6.3
Cost3616
\[\sqrt{\left(ux - ux \cdot maxCos\right) \cdot \left(\left(2 + ux \cdot maxCos\right) - ux\right)} \]
Alternative 9
Error8.3
Cost3556
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.0002500000118743628:\\ \;\;\;\;\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(ux + -1\right) \cdot \left(1 - ux\right)}\\ \end{array} \]
Alternative 10
Error11.3
Cost3424
\[\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)} \]
Alternative 11
Error11.3
Cost3424
\[\sqrt{ux \cdot \left(2 + maxCos \cdot -2\right)} \]
Alternative 12
Error12.1
Cost3296
\[\sqrt{2 \cdot ux} \]

Error

Reproduce

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