Beckmann Sample, near normal, slope_y

?

Percentage Accurate: 58.0% → 98.4%
Time: 13.0s
Precision: binary32
Cost: 19520

?

\[\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) \]
\[\begin{array}{l} \\ \sqrt[3]{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3} \cdot {\left(-\mathsf{log1p}\left(-u1\right)\right)}^{1.5}} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (- (log (- 1.0 u1)))) (sin (* (* 2.0 PI) u2))))
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (cbrt (* (pow (sin (* 2.0 (* PI u2))) 3.0) (pow (- (log1p (- u1))) 1.5))))
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 cbrtf((powf(sinf((2.0f * (((float) M_PI) * u2))), 3.0f) * powf(-log1pf(-u1), 1.5f)));
}
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 cbrt(Float32((sin(Float32(Float32(2.0) * Float32(Float32(pi) * u2))) ^ Float32(3.0)) * (Float32(-log1p(Float32(-u1))) ^ Float32(1.5))))
end
\sqrt{-\log \left(1 - u1\right)} \cdot \sin \left(\left(2 \cdot \pi\right) \cdot u2\right)
\begin{array}{l}

\\
\sqrt[3]{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3} \cdot {\left(-\mathsf{log1p}\left(-u1\right)\right)}^{1.5}}
\end{array}

Local Percentage Accuracy vs ?

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 9 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 60.4%

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

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

    [Start]60.4%

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

    sub-neg [=>]60.4%

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

    log1p-def [=>]98.4%

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

    associate-*l* [=>]98.4%

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

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

    [Start]98.4%

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

    log1p-expm1-u [=>]98.4%

    \[ \sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot \sin \left(2 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\pi \cdot u2\right)\right)}\right) \]
  4. Applied egg-rr98.6%

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

    [Start]98.4%

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

    *-commutative [=>]98.4%

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

    log1p-expm1-u [<=]98.4%

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

    add-cbrt-cube [=>]98.4%

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

    add-cbrt-cube [=>]98.3%

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

    cbrt-unprod [=>]98.4%

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

    pow3 [=>]98.4%

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

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

Alternatives

Alternative 1
Accuracy98.4%
Cost19520
\[\sqrt[3]{{\sin \left(2 \cdot \left(\pi \cdot u2\right)\right)}^{3} \cdot {\left(-\mathsf{log1p}\left(-u1\right)\right)}^{1.5}} \]
Alternative 2
Accuracy98.3%
Cost19456
\[\mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)}\right)\right) \]
Alternative 3
Accuracy94.2%
Cost13348
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.0024999999441206455:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sin t_0 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\\ \end{array} \]
Alternative 4
Accuracy90.3%
Cost13220
\[\begin{array}{l} t_0 := u2 \cdot \left(2 \cdot \pi\right)\\ \mathbf{if}\;t_0 \leq 0.02500000037252903:\\ \;\;\;\;\sqrt{-\mathsf{log1p}\left(-u1\right)} \cdot t_0\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\pi \cdot \left(2 \cdot u2\right)\right) \cdot \sqrt{u1}\\ \end{array} \]
Alternative 5
Accuracy98.3%
Cost13056
\[\sin \left(2 \cdot \left(\pi \cdot u2\right)\right) \cdot \sqrt{-\mathsf{log1p}\left(-u1\right)} \]
Alternative 6
Accuracy83.6%
Cost9860
\[\begin{array}{l} \mathbf{if}\;u2 \leq 0.0010000000474974513:\\ \;\;\;\;2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\pi \cdot \left(2 \cdot u2\right)\right) \cdot \sqrt{u1}\\ \end{array} \]
Alternative 7
Accuracy74.0%
Cost6784
\[2 \cdot \left(\pi \cdot \left(u2 \cdot \sqrt{u1 - u1 \cdot \left(u1 \cdot -0.5\right)}\right)\right) \]
Alternative 8
Accuracy66.0%
Cost6592
\[u2 \cdot \left(\left(2 \cdot \pi\right) \cdot \sqrt{u1}\right) \]
Alternative 9
Accuracy7.1%
Cost32
\[0 \]

Reproduce?

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