Beckmann Sample, near normal, slope_x

?

Percentage Accurate: 58.0% → 99.0%
Time: 15.9s
Precision: binary32
Cost: 13056

?

\[\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) \]
\[\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\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
 (* (cos (* 2.0 (* PI u2))) (sqrt (- (log1p (- u1))))))
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 cosf((2.0f * (((float) M_PI) * u2))) * sqrtf(-log1pf(-u1));
}
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(cos(Float32(Float32(2.0) * Float32(Float32(pi) * u2))) * sqrt(Float32(-log1p(Float32(-u1)))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \cos \left(\left(2 \cdot \pi\right) \cdot u2\right)
\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 8 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 61.1%

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

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

    [Start]61.1

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

    sub-neg [=>]61.1

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

    log1p-def [=>]99.1

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

    associate-*l* [=>]99.1

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \cos \color{blue}{\left(2 \cdot \left(\pi \cdot u2\right)\right)} \]
  3. Final simplification99.1%

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

Alternatives

Alternative 1
Accuracy90.5%
Cost16356
\[\begin{array}{l} \mathbf{if}\;\cos \left(u2 \cdot \left(2 \cdot \pi\right)\right) \leq 0.9999840259552002:\\ \;\;\;\;\cos \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \end{array} \]
Alternative 2
Accuracy96.3%
Cost13476
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.0007099999929778278:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)} \cdot \cos t_0\\ \end{array} \]
Alternative 3
Accuracy94.8%
Cost13348
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.0010000000474974513:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)}\\ \mathbf{else}:\\ \;\;\;\;\cos t_0 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\\ \end{array} \]
Alternative 4
Accuracy79.3%
Cost6496
\[\sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Alternative 5
Accuracy74.8%
Cost3552
\[\sqrt{u1 - \left(u1 \cdot u1\right) \cdot \left(-0.5 + u1 \cdot -0.3333333333333333\right)} \]
Alternative 6
Accuracy72.3%
Cost3424
\[\sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)} \]
Alternative 7
Accuracy64.3%
Cost3232
\[\sqrt{u1} \]

Reproduce?

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