?

Average Accuracy: 57.5% → 98.9%
Time: 14.4s
Precision: binary32
Cost: 22784

?

\[\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) \]
\[\sqrt{\mathsf{log1p}\left(\mathsf{fma}\left(u1, u1, u1\right)\right) - \mathsf{log1p}\left(-{u1}^{3}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (cos (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (*
  (sqrt (- (log1p (fma u1 u1 u1)) (log1p (- (pow u1 3.0)))))
  (cos (* (* 2.0 PI) u2))))
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) {
	return sqrtf((log1pf(fmaf(u1, u1, u1)) - log1pf(-powf(u1, 3.0f)))) * cosf(((2.0f * ((float) M_PI)) * u2));
}
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)
	return Float32(sqrt(Float32(log1p(fma(u1, u1, u1)) - log1p(Float32(-(u1 ^ Float32(3.0)))))) * cos(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\sqrt{\mathsf{log1p}\left(\mathsf{fma}\left(u1, u1, u1\right)\right) - \mathsf{log1p}\left(-{u1}^{3}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)

Error?

Derivation?

  1. Initial program 57.5%

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Applied egg-rr54.6%

    \[\leadsto \sqrt{-\color{blue}{\left(\log \left(1 - {u1}^{3}\right) - \log \left(1 + \mathsf{fma}\left(u1, u1, u1\right)\right)\right)}} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
    Proof
  3. No proof available- proof too large to flatten.
  4. Simplified98.9%

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

    [Start]54.6

    \[ \sqrt{-\left(\log \left(1 - {u1}^{3}\right) - \log \left(1 + \mathsf{fma}\left(u1, u1, u1\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    sub-neg [=>]54.6

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

    log1p-def [=>]56.2

    \[ \sqrt{-\left(\color{blue}{\mathsf{log1p}\left(-{u1}^{3}\right)} - \log \left(1 + \mathsf{fma}\left(u1, u1, u1\right)\right)\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

    log1p-def [=>]98.9

    \[ \sqrt{-\left(\mathsf{log1p}\left(-{u1}^{3}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{fma}\left(u1, u1, u1\right)\right)}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  5. Final simplification98.9%

    \[\leadsto \sqrt{\mathsf{log1p}\left(\mathsf{fma}\left(u1, u1, u1\right)\right) - \mathsf{log1p}\left(-{u1}^{3}\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \]

Alternatives

Alternative 1
Accuracy94.8%
Cost16548
\[\begin{array}{l} t_0 := \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)\\ \mathbf{if}\;t_0 \leq 0.999997615814209:\\ \;\;\;\;t_0 \cdot \sqrt{u1 + \left(u1 \cdot u1\right) \cdot 0.5}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 2
Accuracy90.7%
Cost16356
\[\begin{array}{l} \mathbf{if}\;\cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \leq 0.999966025352478:\\ \;\;\;\;\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 3
Accuracy98.9%
Cost16352
\[\cos \left(\left(2 \cdot \pi\right) \cdot u2\right) \cdot \sqrt{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(u1 \cdot \left(-u1\right)\right)} \]
Alternative 4
Accuracy96.1%
Cost13476
\[\begin{array}{l} t_0 := \left(2 \cdot \pi\right) \cdot u2\\ \mathbf{if}\;t_0 \leq 0.002199999988079071:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t_0 \cdot \sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)}\\ \end{array} \]
Alternative 5
Accuracy99.0%
Cost13056
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \]
Alternative 6
Accuracy79.9%
Cost6496
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Alternative 7
Accuracy76.5%
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.3%
Cost3552
\[\sqrt{u1 - u1 \cdot \left(u1 \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)\right)} \]
Alternative 9
Accuracy72.8%
Cost3424
\[\sqrt{u1 + \left(u1 \cdot u1\right) \cdot 0.5} \]
Alternative 10
Accuracy64.9%
Cost3232
\[\sqrt{u1} \]

Error

Reproduce?

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