?

Average Error: 13.8 → 0.3
Time: 25.4s
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 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \cos \left(2 \cdot \left(uy \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 (+ maxCos maxCos)) ux) (pow (* ux (+ maxCos -1.0)) 2.0)))
  (cos (* 2.0 (* uy 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 - (maxCos + maxCos)) * ux) - powf((ux * (maxCos + -1.0f)), 2.0f))) * cosf((2.0f * (uy * ((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(maxCos + maxCos)) * ux) - (Float32(ux * Float32(maxCos + Float32(-1.0))) ^ Float32(2.0)))) * cos(Float32(Float32(2.0) * Float32(uy * 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) - (maxCos + maxCos)) * ux) - ((ux * (maxCos + single(-1.0))) ^ single(2.0)))) * cos((single(2.0) * (uy * 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 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \cos \left(2 \cdot \left(uy \cdot \pi\right)\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. 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.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.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 + \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(\left(maxCos - 1\right) \cdot ux\right)}^{2}}\right)} \]

    rational.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 + \left(-{\color{blue}{\left(ux \cdot \left(maxCos - 1\right)\right)}}^{2}\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 + \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 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \cdot \cos \left(2 \cdot \left(uy \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.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)} \]

    rational.json-simplify-2 [=>]0.3

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

    metadata-eval [<=]0.3

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

    rational.json-simplify-51 [<=]0.3

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

    rational.json-simplify-2 [<=]0.3

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

    rational.json-simplify-6 [=>]0.3

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

    rational.json-simplify-6 [=>]0.3

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

    rational.json-simplify-15 [<=]0.3

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

    rational.json-simplify-2 [<=]0.3

    \[ \sqrt{\left(2 - \left(maxCos + maxCos\right)\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) \]
  6. Final simplification0.3

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

Alternatives

Alternative 1
Error2.9
Cost16676
\[\begin{array}{l} \mathbf{if}\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \leq 0.9999899864196777:\\ \;\;\;\;\cos \left(\left(1 + uy \cdot \left(2 \cdot \pi\right)\right) - 1\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\left(2 \cdot ux + maxCos \cdot \left(ux \cdot -2\right)\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \end{array} \]
Alternative 2
Error1.3
Cost13220
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 0.00011999999696854502:\\ \;\;\;\;t_0 \cdot \sqrt{ux + \left(ux - {ux}^{2}\right)}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 3
Error1.3
Cost13220
\[\begin{array}{l} t_0 := \cos \left(\left(uy \cdot 2\right) \cdot \pi\right)\\ \mathbf{if}\;maxCos \leq 0.00011999999696854502:\\ \;\;\;\;t_0 \cdot \sqrt{\left(ux + ux\right) - {ux}^{2}}\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \end{array} \]
Alternative 4
Error2.7
Cost10884
\[\begin{array}{l} t_0 := 1 + \left(maxCos \cdot ux - ux\right)\\ t_1 := \left(1 - ux\right) + ux \cdot maxCos\\ \mathbf{if}\;1 - t_1 \cdot t_1 \leq 0.0004199999966658652:\\ \;\;\;\;\cos \left(\left(1 + uy \cdot \left(2 \cdot \pi\right)\right) - 1\right) \cdot \sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t_0 \cdot t_0}\\ \end{array} \]
Alternative 5
Error2.9
Cost10116
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0010000000474974513:\\ \;\;\;\;\sqrt{\left(2 \cdot ux + maxCos \cdot \left(ux \cdot -2\right)\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{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 6
Error3.3
Cost9988
\[\begin{array}{l} \mathbf{if}\;uy \cdot 2 \leq 0.0010000000474974513:\\ \;\;\;\;\sqrt{\left(2 \cdot ux + maxCos \cdot \left(ux \cdot -2\right)\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux + ux}\\ \end{array} \]
Alternative 7
Error6.4
Cost6912
\[\sqrt{\left(2 \cdot ux + maxCos \cdot \left(ux \cdot -2\right)\right) - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \]
Alternative 8
Error6.4
Cost6848
\[\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {\left(ux \cdot \left(maxCos + -1\right)\right)}^{2}} \]
Alternative 9
Error6.7
Cost6720
\[\sqrt{\left(2 - \left(maxCos + maxCos\right)\right) \cdot ux - {ux}^{2}} \]
Alternative 10
Error8.3
Cost6660
\[\begin{array}{l} \mathbf{if}\;ux \leq 0.00022000000171829015:\\ \;\;\;\;\sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 - {\left(1 - ux\right)}^{2}}\\ \end{array} \]
Alternative 11
Error7.7
Cost6592
\[\sqrt{2 \cdot ux - {ux}^{2}} \]
Alternative 12
Error11.3
Cost3488
\[\sqrt{2 \cdot ux + ux \cdot \left(maxCos \cdot -2\right)} \]
Alternative 13
Error11.3
Cost3424
\[\sqrt{\left(2 - 2 \cdot maxCos\right) \cdot ux} \]
Alternative 14
Error12.1
Cost3296
\[\sqrt{ux + ux} \]

Error

Reproduce?

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