Average Error: 13.6 → 0.3
Time: 20.8s
Precision: binary32
Cost: 26208
\[\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 \log \left({\left({\left(e^{2}\right)}^{\pi}\right)}^{uy}\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right) - ux \cdot \left(ux \cdot {\left(1 - maxCos\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 (log (pow (pow (exp 2.0) PI) uy)))
  (sqrt
   (- (* ux (* 2.0 (- 1.0 maxCos))) (* ux (* ux (pow (- 1.0 maxCos) 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(logf(powf(powf(expf(2.0f), ((float) M_PI)), uy))) * sqrtf(((ux * (2.0f * (1.0f - maxCos))) - (ux * (ux * powf((1.0f - maxCos), 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(log(((exp(Float32(2.0)) ^ Float32(pi)) ^ uy))) * sqrt(Float32(Float32(ux * Float32(Float32(2.0) * Float32(Float32(1.0) - maxCos))) - Float32(ux * Float32(ux * (Float32(Float32(1.0) - maxCos) ^ 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(log(((exp(single(2.0)) ^ single(pi)) ^ uy))) * sqrt(((ux * (single(2.0) * (single(1.0) - maxCos))) - (ux * (ux * ((single(1.0) - maxCos) ^ 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 \log \left({\left({\left(e^{2}\right)}^{\pi}\right)}^{uy}\right) \cdot \sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right) - ux \cdot \left(ux \cdot {\left(1 - maxCos\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(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)}} \]
    Proof
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (fma.f32 (-.f32 (fma.f32 ux maxCos 1) ux) (-.f32 ux (fma.f32 ux maxCos 1)) 1))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (Rewrite<= associate-*l*_binary32 (*.f32 (*.f32 uy 2) (PI.f32)))) (sqrt.f32 (fma.f32 (-.f32 (fma.f32 ux maxCos 1) ux) (-.f32 ux (fma.f32 ux maxCos 1)) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (-.f32 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 ux maxCos) 1)) ux) (-.f32 ux (fma.f32 ux maxCos 1)) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (Rewrite<= associate-+r-_binary32 (+.f32 (*.f32 ux maxCos) (-.f32 1 ux))) (-.f32 ux (fma.f32 ux maxCos 1)) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (Rewrite<= +-commutative_binary32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))) (-.f32 ux (fma.f32 ux maxCos 1)) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (-.f32 ux (Rewrite<= fma-def_binary32 (+.f32 (*.f32 ux maxCos) 1))) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (Rewrite=> sub-neg_binary32 (+.f32 ux (neg.f32 (+.f32 (*.f32 ux maxCos) 1)))) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (Rewrite<= remove-double-neg_binary32 (neg.f32 (neg.f32 ux))) (neg.f32 (+.f32 (*.f32 ux maxCos) 1))) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (Rewrite<= distribute-neg-in_binary32 (neg.f32 (+.f32 (neg.f32 ux) (+.f32 (*.f32 ux maxCos) 1)))) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (neg.f32 (Rewrite<= +-commutative_binary32 (+.f32 (+.f32 (*.f32 ux maxCos) 1) (neg.f32 ux)))) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (neg.f32 (Rewrite<= associate-+r+_binary32 (+.f32 (*.f32 ux maxCos) (+.f32 1 (neg.f32 ux))))) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (neg.f32 (+.f32 (*.f32 ux maxCos) (Rewrite<= sub-neg_binary32 (-.f32 1 ux)))) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (fma.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (neg.f32 (Rewrite<= +-commutative_binary32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) 1))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (Rewrite<= fma-def_binary32 (+.f32 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (neg.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) 1)))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (+.f32 (Rewrite<= *-commutative_binary32 (*.f32 (neg.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)))) 1))): 17 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 1 (*.f32 (neg.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))))))): 0 points increase in error, 17 points decrease in error
    (*.f32 (cos.f32 (*.f32 (*.f32 uy 2) (PI.f32))) (sqrt.f32 (Rewrite<= cancel-sign-sub-inv_binary32 (-.f32 1 (*.f32 (+.f32 (-.f32 1 ux) (*.f32 ux maxCos)) (+.f32 (-.f32 1 ux) (*.f32 ux maxCos))))))): 0 points increase in error, 17 points decrease in error
  3. Taylor expanded in ux around -inf 0.3

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

    \[\leadsto \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(1 - maxCos\right) \cdot 2\right) - ux \cdot \left(ux \cdot {\left(1 - maxCos\right)}^{2}\right)}} \]
    Proof
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 ux (*.f32 (-.f32 1 maxCos) 2)) (*.f32 ux (*.f32 ux (pow.f32 (-.f32 1 maxCos) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (Rewrite<= associate-*l*_binary32 (*.f32 (*.f32 ux (-.f32 1 maxCos)) 2)) (*.f32 ux (*.f32 ux (pow.f32 (-.f32 1 maxCos) 2)))))): 0 points increase in error, 12 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 (*.f32 ux (Rewrite=> sub-neg_binary32 (+.f32 1 (neg.f32 maxCos)))) 2) (*.f32 ux (*.f32 ux (pow.f32 (-.f32 1 maxCos) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 (*.f32 ux (+.f32 1 (Rewrite<= mul-1-neg_binary32 (*.f32 -1 maxCos)))) 2) (*.f32 ux (*.f32 ux (pow.f32 (-.f32 1 maxCos) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (Rewrite<= *-commutative_binary32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos))))) (*.f32 ux (*.f32 ux (pow.f32 (-.f32 1 maxCos) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (*.f32 ux (*.f32 ux (pow.f32 (Rewrite=> sub-neg_binary32 (+.f32 1 (neg.f32 maxCos))) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (*.f32 ux (*.f32 ux (pow.f32 (+.f32 1 (Rewrite<= mul-1-neg_binary32 (*.f32 -1 maxCos))) 2)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (Rewrite<= associate-*l*_binary32 (*.f32 (*.f32 ux ux) (pow.f32 (+.f32 1 (*.f32 -1 maxCos)) 2)))))): 12 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (-.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (*.f32 (Rewrite<= unpow2_binary32 (pow.f32 ux 2)) (pow.f32 (+.f32 1 (*.f32 -1 maxCos)) 2))))): 0 points increase in error, 12 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (Rewrite<= unsub-neg_binary32 (+.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (neg.f32 (*.f32 (pow.f32 ux 2) (pow.f32 (+.f32 1 (*.f32 -1 maxCos)) 2))))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (+.f32 (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))) (Rewrite<= mul-1-neg_binary32 (*.f32 -1 (*.f32 (pow.f32 ux 2) (pow.f32 (+.f32 1 (*.f32 -1 maxCos)) 2))))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (cos.f32 (*.f32 uy (*.f32 2 (PI.f32)))) (sqrt.f32 (Rewrite<= +-commutative_binary32 (+.f32 (*.f32 -1 (*.f32 (pow.f32 ux 2) (pow.f32 (+.f32 1 (*.f32 -1 maxCos)) 2))) (*.f32 2 (*.f32 ux (+.f32 1 (*.f32 -1 maxCos)))))))): 0 points increase in error, 0 points decrease in error
  5. Applied egg-rr0.3

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

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

Alternatives

Alternative 1
Error3.3
Cost16420
\[\begin{array}{l} t_0 := ux \cdot \left(1 - maxCos\right)\\ \mathbf{if}\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \leq 0.9997400045394897:\\ \;\;\;\;\cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \cdot \sqrt{ux + ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{2 \cdot t_0 - {t_0}^{2}}\\ \end{array} \]
Alternative 2
Error0.3
Cost13472
\[\sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right)\right) - ux \cdot \left(ux \cdot {\left(1 - maxCos\right)}^{2}\right)} \cdot \cos \left(uy \cdot \left(2 \cdot \pi\right)\right) \]
Alternative 3
Error0.3
Cost13408
\[\sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right) - ux \cdot {\left(1 - maxCos\right)}^{2}\right)} \cdot \cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \]
Alternative 4
Error0.3
Cost10176
\[\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{\left(ux \cdot \left(1 - maxCos\right)\right) \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)} \]
Alternative 5
Error1.2
Cost10116
\[\begin{array}{l} t_0 := ux \cdot \left(1 - maxCos\right)\\ \mathbf{if}\;2 \cdot uy \leq 0.0005799999926239252:\\ \;\;\;\;\sqrt{2 \cdot t_0 - {t_0}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(2 \cdot \left(\pi \cdot uy\right)\right) \cdot \sqrt{2 \cdot ux - ux \cdot ux}\\ \end{array} \]
Alternative 6
Error1.2
Cost10052
\[\begin{array}{l} t_0 := ux \cdot \left(1 - maxCos\right)\\ \mathbf{if}\;2 \cdot uy \leq 0.0005799999926239252:\\ \;\;\;\;\sqrt{2 \cdot t_0 - {t_0}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\pi \cdot \left(2 \cdot uy\right)\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}\\ \end{array} \]
Alternative 7
Error6.3
Cost6848
\[\sqrt{ux \cdot \left(2 \cdot \left(1 - maxCos\right) - ux \cdot {\left(1 - maxCos\right)}^{2}\right)} \]
Alternative 8
Error6.3
Cost6848
\[\begin{array}{l} t_0 := ux \cdot \left(1 - maxCos\right)\\ \sqrt{2 \cdot t_0 - {t_0}^{2}} \end{array} \]
Alternative 9
Error6.4
Cost3616
\[\sqrt{\left(ux \cdot \left(1 - maxCos\right)\right) \cdot \left(2 + ux \cdot \left(maxCos + -1\right)\right)} \]
Alternative 10
Error8.4
Cost3556
\[\begin{array}{l} \mathbf{if}\;ux \leq 9.999999747378752 \cdot 10^{-5}:\\ \;\;\;\;\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + \left(ux + -1\right) \cdot \left(1 - ux\right)}\\ \end{array} \]
Alternative 11
Error11.4
Cost3424
\[\sqrt{ux \cdot \left(\left(2 - maxCos\right) - maxCos\right)} \]
Alternative 12
Error12.2
Cost3296
\[\sqrt{ux + ux} \]
Alternative 13
Error29.9
Cost3232
\[\sqrt{0} \]

Error

Reproduce

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