Average Error: 13.8 → 0.5
Time: 16.0s
Precision: binary32
Cost: 16352
\[\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 \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
\[\sqrt{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(u1 \cdot \left(-u1\right)\right)} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log1p u1) (log1p (* u1 (- u1))))) (sin (* 2.0 (* u2 PI)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(-logf((1.0f - u1))) * sinf(((2.0f * ((float) M_PI)) * u2));
}
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((log1pf(u1) - log1pf((u1 * -u1)))) * sinf((2.0f * (u2 * ((float) M_PI))));
}
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(-log(Float32(Float32(1.0) - u1)))) * sin(Float32(Float32(Float32(2.0) * Float32(pi)) * u2)))
end
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(log1p(u1) - log1p(Float32(u1 * Float32(-u1))))) * sin(Float32(Float32(2.0) * Float32(u2 * Float32(pi)))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\sqrt{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(u1 \cdot \left(-u1\right)\right)} \cdot \sin \left(2 \cdot \left(u2 \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

    \[\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  2. Applied egg-rr0.5

    \[\leadsto \sqrt{-\color{blue}{\left(\mathsf{log1p}\left(-u1 \cdot u1\right) - \mathsf{log1p}\left(u1\right)\right)}} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right) \]
  3. Taylor expanded in u2 around inf 14.7

    \[\leadsto \color{blue}{\sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot \sqrt{\log \left(1 + u1\right) - \log \left(1 - {u1}^{2}\right)}} \]
  4. Simplified0.5

    \[\leadsto \color{blue}{\sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot \sqrt{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(u1 \cdot \left(-u1\right)\right)}} \]
    Proof
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (log1p.f32 u1) (log1p.f32 (*.f32 u1 (neg.f32 u1)))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (Rewrite<= log1p-def_binary32 (log.f32 (+.f32 1 u1))) (log1p.f32 (*.f32 u1 (neg.f32 u1)))))): 232 points increase in error, 3 points decrease in error
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (log.f32 (+.f32 1 u1)) (log1p.f32 (Rewrite<= distribute-rgt-neg-in_binary32 (neg.f32 (*.f32 u1 u1))))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (log.f32 (+.f32 1 u1)) (log1p.f32 (neg.f32 (Rewrite<= unpow2_binary32 (pow.f32 u1 2))))))): 0 points increase in error, 0 points decrease in error
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (log.f32 (+.f32 1 u1)) (Rewrite<= log1p-def_binary32 (log.f32 (+.f32 1 (neg.f32 (pow.f32 u1 2)))))))): 149 points increase in error, 69 points decrease in error
    (*.f32 (sin.f32 (*.f32 2 (*.f32 u2 (PI.f32)))) (sqrt.f32 (-.f32 (log.f32 (+.f32 1 u1)) (log.f32 (Rewrite<= sub-neg_binary32 (-.f32 1 (pow.f32 u1 2))))))): 0 points increase in error, 0 points decrease in error
  5. Final simplification0.5

    \[\leadsto \sqrt{\mathsf{log1p}\left(u1\right) - \mathsf{log1p}\left(u1 \cdot \left(-u1\right)\right)} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \]

Alternatives

Alternative 1
Error1.8
Cost23112
\[\begin{array}{l} t_0 := \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right)\\ \mathbf{if}\;t_0 \leq -0.05000000074505806:\\ \;\;\;\;t_0 \cdot \sqrt{u1 \cdot \left(1 - u1 \cdot -0.5\right)}\\ \mathbf{elif}\;t_0 \leq 0.003000000026077032:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_0 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\\ \end{array} \]
Alternative 2
Error1.8
Cost13348
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.003000000026077032:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin t_0 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\\ \end{array} \]
Alternative 3
Error3.0
Cost13220
\[\begin{array}{l} \mathbf{if}\;u2 \cdot \left(2 \cdot \pi\right) \leq 0.014999999664723873:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot \sqrt{u1}\\ \end{array} \]
Alternative 4
Error0.5
Cost13056
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \]
Alternative 5
Error1.5
Cost10180
\[\begin{array}{l} \mathbf{if}\;u1 \leq 0.05000000074505806:\\ \;\;\;\;\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 - u1 \cdot 0.3333333333333333\right)} \cdot \sin \left(u2 \cdot \left(2 \cdot \pi\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \end{array} \]
Alternative 6
Error4.4
Cost9860
\[\begin{array}{l} \mathbf{if}\;u2 \leq 0.000699999975040555:\\ \;\;\;\;\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 - u1 \cdot 0.3333333333333333\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(2 \cdot \left(u2 \cdot \pi\right)\right) \cdot \sqrt{u1}\\ \end{array} \]
Alternative 7
Error7.4
Cost6912
\[\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 - u1 \cdot 0.3333333333333333\right)} \cdot \left(\pi \cdot \left(2 \cdot u2\right)\right) \]
Alternative 8
Error8.2
Cost6784
\[\left(\pi \cdot \left(2 \cdot u2\right)\right) \cdot \sqrt{u1 + \left(u1 \cdot u1\right) \cdot 0.5} \]
Alternative 9
Error10.7
Cost6592
\[u2 \cdot \left(\pi \cdot \left(2 \cdot \sqrt{u1}\right)\right) \]

Error

Reproduce

herbie shell --seed 2022300 
(FPCore (cosTheta_i u1 u2)
  :name "Beckmann Sample, near normal, slope_y"
  :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)))) (sin (* (* 2.0 PI) u2))))