Average Error: 13.8 → 0.3
Time: 12.0s
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(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(2 + \left(ux \cdot maxCos - ux\right)\right) \cdot \left(ux - ux \cdot maxCos\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 (- (* ux maxCos) ux)) (- ux (* ux maxCos))))))
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 + ((ux * maxCos) - ux)) * (ux - (ux * maxCos))));
}
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(uy * Float32(Float32(2.0) * Float32(pi)))) * sqrt(Float32(Float32(Float32(2.0) + Float32(Float32(ux * maxCos) - ux)) * Float32(ux - Float32(ux * maxCos)))))
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) + ((ux * maxCos) - ux)) * (ux - (ux * maxCos))));
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(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\left(2 + \left(ux \cdot maxCos - ux\right)\right) \cdot \left(ux - ux \cdot maxCos\right)}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Initial program 13.8

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

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

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

Alternatives

Alternative 1
Error1.2
Cost10116
\[\begin{array}{l} t_0 := ux - ux \cdot maxCos\\ \mathbf{if}\;uy \cdot 2 \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{2 \cdot t_0 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux + \left(ux - ux \cdot ux\right)} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\right)\\ \end{array} \]
Alternative 2
Error0.8
Cost10112
\[\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot \left(ux - ux \cdot maxCos\right) - ux \cdot ux} \]
Alternative 3
Error1.2
Cost9988
\[\begin{array}{l} t_0 := ux - ux \cdot maxCos\\ \mathbf{if}\;uy \leq 4.999999873689376 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{2 \cdot t_0 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(2 \cdot \left(uy \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \end{array} \]
Alternative 4
Error3.4
Cost9924
\[\begin{array}{l} t_0 := ux - ux \cdot maxCos\\ \mathbf{if}\;uy \leq 0.0005000000237487257:\\ \;\;\;\;\sqrt{2 \cdot t_0 - t_0 \cdot t_0}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{2 \cdot ux}\\ \end{array} \]
Alternative 5
Error6.5
Cost3808
\[\begin{array}{l} t_0 := ux - ux \cdot maxCos\\ \sqrt{2 \cdot t_0 - t_0 \cdot t_0} \end{array} \]
Alternative 6
Error6.5
Cost3616
\[\sqrt{\left(ux - ux \cdot maxCos\right) \cdot \left(\left(2 + ux \cdot maxCos\right) - ux\right)} \]
Alternative 7
Error7.3
Cost3556
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 2.4000000848900527 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux + \left(ux - ux \cdot ux\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(1 + \left(1 - maxCos\right)\right) - maxCos\right)}\\ \end{array} \]
Alternative 8
Error7.3
Cost3492
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 2.4000000848900527 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 - ux\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \]
Alternative 9
Error7.3
Cost3492
\[\begin{array}{l} \mathbf{if}\;maxCos \leq 2.4000000848900527 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux + \left(ux - ux \cdot ux\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right)}\\ \end{array} \]
Alternative 10
Error7.9
Cost3360
\[\sqrt{ux \cdot \left(2 - ux\right)} \]
Alternative 11
Error12.2
Cost3296
\[\sqrt{2 \cdot ux} \]
Alternative 12
Error25.6
Cost32
\[1 \]

Error

Reproduce

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