?

Average Accuracy: 57.5% → 99.0%
Time: 15.1s
Precision: binary32
Cost: 30112

?

\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
\[\begin{array}{l} t_0 := \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\\ t_1 := 1.5 + -2 \cdot \left(0.5 \cdot t_0\right)\\ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\frac{0.25}{t_1} + \left(0.5 - \frac{{\left(-2 \cdot \left(-0.5 \cdot t_0\right) + -1\right)}^{2}}{t_1}\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* 2.0 (* PI u2)))) (t_1 (+ 1.5 (* -2.0 (* 0.5 t_0)))))
   (*
    (sqrt (- (log1p (- u1))))
    (+
     (/ 0.25 t_1)
     (- 0.5 (/ (pow (+ (* -2.0 (* -0.5 t_0)) -1.0) 2.0) t_1))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf((2.0f * (((float) M_PI) * u2)));
	float t_1 = 1.5f + (-2.0f * (0.5f * t_0));
	return sqrtf(-log1pf(-u1)) * ((0.25f / t_1) + (0.5f - (powf(((-2.0f * (-0.5f * t_0)) + -1.0f), 2.0f) / t_1)));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(Float32(2.0) * Float32(Float32(pi) * u2)))
	t_1 = Float32(Float32(1.5) + Float32(Float32(-2.0) * Float32(Float32(0.5) * t_0)))
	return Float32(sqrt(Float32(-log1p(Float32(-u1)))) * Float32(Float32(Float32(0.25) / t_1) + Float32(Float32(0.5) - Float32((Float32(Float32(Float32(-2.0) * Float32(Float32(-0.5) * t_0)) + Float32(-1.0)) ^ Float32(2.0)) / t_1))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\begin{array}{l}
t_0 := \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\\
t_1 := 1.5 + -2 \cdot \left(0.5 \cdot t_0\right)\\
\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\frac{0.25}{t_1} + \left(0.5 - \frac{{\left(-2 \cdot \left(-0.5 \cdot t_0\right) + -1\right)}^{2}}{t_1}\right)\right)
\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 57.5%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Simplified99.0%

    \[\leadsto \color{blue}{\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
    Proof

    [Start]57.5

    \[ \sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    sub-neg [=>]57.5

    \[ \sqrt{-\log \color{blue}{\left(1 + \left(-u1\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    log1p-def [=>]99.0

    \[ \sqrt{-\color{blue}{\mathsf{log1p}\left(-u1\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    associate-*l* [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  3. Applied egg-rr99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(0.5 + \left(0.5 \cdot \cos \left(\pi \cdot \left(u2 + u2\right)\right) - {\sin \left(\pi \cdot u2\right)}^{2}\right)\right)} \]
  4. Applied egg-rr98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \color{blue}{\left(\mathsf{fma}\left(0.5, \cos 0, -0.5 + 0.5 \cdot \cos 0\right) + \left(\mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right)}\right) \]
  5. Simplified98.9%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \color{blue}{\left(0.5 + {\sin \left(u2 \cdot \pi\right)}^{2} \cdot -2\right)}\right) \]
    Proof

    [Start]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(\mathsf{fma}\left(0.5, \cos 0, -0.5 + 0.5 \cdot \cos 0\right) + \left(\mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right)\right) \]

    associate-+r+ [=>]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \color{blue}{\left(\left(\mathsf{fma}\left(0.5, \cos 0, -0.5 + 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)}\right) \]

    cos-0 [=>]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(\left(\mathsf{fma}\left(0.5, \color{blue}{1}, -0.5 + 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right) \]

    fma-def [<=]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(\left(\color{blue}{\left(0.5 \cdot 1 + \left(-0.5 + 0.5 \cdot \cos 0\right)\right)} + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right) \]

    cos-0 [<=]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(\left(\left(0.5 \cdot \color{blue}{\cos 0} + \left(-0.5 + 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right) \]

    associate-+r+ [<=]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(\color{blue}{\left(0.5 \cdot \cos 0 + \left(\left(-0.5 + 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right)} + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right) \]

    associate-+l+ [=>]98.9

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \color{blue}{\left(0.5 \cdot \cos 0 + \left(\left(\left(-0.5 + 0.5 \cdot \cos 0\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right) + \mathsf{fma}\left(-\sin \left(\pi \cdot u2\right), \sin \left(\pi \cdot u2\right), 0.5 - 0.5 \cdot \cos 0\right)\right)\right)}\right) \]
  6. Applied egg-rr99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \color{blue}{\frac{\cos \left(u2 \cdot \pi - u2 \cdot \pi\right) - \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2}} \cdot -2\right)\right) \]
  7. Simplified99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \color{blue}{\left(0.5 - \frac{\cos \left(\left(2 \cdot \pi\right) \cdot u2\right)}{2}\right)} \cdot -2\right)\right) \]
    Proof

    [Start]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \frac{\cos \left(u2 \cdot \pi - u2 \cdot \pi\right) - \cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2} \cdot -2\right)\right) \]

    div-sub [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \color{blue}{\left(\frac{\cos \left(u2 \cdot \pi - u2 \cdot \pi\right)}{2} - \frac{\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2}\right)} \cdot -2\right)\right) \]

    +-inverses [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \left(\frac{\cos \color{blue}{0}}{2} - \frac{\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2}\right) \cdot -2\right)\right) \]

    cos-0 [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \left(\frac{\color{blue}{1}}{2} - \frac{\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2}\right) \cdot -2\right)\right) \]

    metadata-eval [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \left(\color{blue}{0.5} - \frac{\cos \left(2 \cdot \left(u2 \cdot \pi\right)\right)}{2}\right) \cdot -2\right)\right) \]

    *-commutative [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \left(0.5 - \frac{\cos \left(2 \cdot \color{blue}{\left(\pi \cdot u2\right)}\right)}{2}\right) \cdot -2\right)\right) \]

    associate-*r* [=>]99.0

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(0.5 + \left(0.5 + \left(0.5 - \frac{\cos \color{blue}{\left(\left(2 \cdot \pi\right) \cdot u2\right)}}{2}\right) \cdot -2\right)\right) \]
  8. Applied egg-rr99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \color{blue}{\left(\frac{0.25}{1.5 - -2 \cdot \left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot -0.5\right)} - \left(\frac{{\left(-1 + -2 \cdot \left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot -0.5\right)\right)}^{2}}{1.5 - -2 \cdot \left(\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot -0.5\right)} - 0.5\right)\right)} \]
  9. Final simplification99.0%

    \[\leadsto \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\frac{0.25}{1.5 + -2 \cdot \left(0.5 \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\right)} + \left(0.5 - \frac{{\left(-2 \cdot \left(-0.5 \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\right) + -1\right)}^{2}}{1.5 + -2 \cdot \left(0.5 \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right)\right)}\right)\right) \]

Alternatives

Alternative 1
Accuracy94.4%
Cost16548
\[\begin{array}{l} \mathbf{if}\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \leq 0.9999939799308777:\\ \;\;\;\;\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{u1 + 0.5 \cdot \left(u1 \cdot u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 2
Accuracy90.4%
Cost16356
\[\begin{array}{l} t_0 := \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right)\\ \mathbf{if}\;t_0 \leq 0.9999359846115112:\\ \;\;\;\;t_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 3
Accuracy99.0%
Cost13312
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(1 + -2 \cdot \left(-0.5 \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) + 0.5\right)\right) \]
Alternative 4
Accuracy99.0%
Cost13056
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \]
Alternative 5
Accuracy92.2%
Cost10112
\[\sqrt{u1 + \left(u1 \cdot u1\right) \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)} \cdot \cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \]
Alternative 6
Accuracy79.6%
Cost6496
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Alternative 7
Accuracy76.4%
Cost3680
\[\sqrt{u1 + \left(u1 \cdot u1\right) \cdot \left(0.5 + u1 \cdot \left(u1 \cdot 0.25 + 0.3333333333333333\right)\right)} \]
Alternative 8
Accuracy75.1%
Cost3552
\[\sqrt{u1 + u1 \cdot \left(u1 \cdot \left(0.5 + u1 \cdot 0.3333333333333333\right)\right)} \]
Alternative 9
Accuracy72.7%
Cost3424
\[\sqrt{u1 + 0.5 \cdot \left(u1 \cdot u1\right)} \]
Alternative 10
Accuracy64.8%
Cost3232
\[\sqrt{u1} \]

Error

Reproduce?

herbie shell --seed 2023129 
(FPCore (cosTheta_i u1 u2)
  :name "Beckmann Sample, near normal, slope_x"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))