Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5

?

Percentage Accurate: 60.3% → 98.4%
Time: 12.3s
Precision: binary32
Cost: 3680

?

\[\left(\left(\left(\left(0.0001 \leq alphax \land alphax \leq 1\right) \land \left(0.0001 \leq alphay \land alphay \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u0 \land u0 \leq 1\right)\right) \land \left(0 \leq cos2phi \land cos2phi \leq 1\right)\right) \land 0 \leq sin2phi\]
\[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
\[\begin{array}{l} \\ \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log (- 1.0 u0)))
  (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log1p (- u0)))
  (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -log1pf(-u0) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log(Float32(Float32(1.0) - u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log1p(Float32(-u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\begin{array}{l}

\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\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 12 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 59.1%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Simplified98.1%

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
    Step-by-step derivation

    [Start]59.1%

    \[ \frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    neg-sub0 [=>]59.1%

    \[ \frac{\color{blue}{0 - \log \left(1 - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    div-sub [=>]59.1%

    \[ \color{blue}{\frac{0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} - \frac{\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]

    --rgt-identity [<=]59.1%

    \[ \frac{0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} - \frac{\color{blue}{\log \left(1 - u0\right) - 0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    div-sub [<=]59.1%

    \[ \color{blue}{\frac{0 - \left(\log \left(1 - u0\right) - 0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]

    --rgt-identity [=>]59.1%

    \[ \frac{0 - \color{blue}{\log \left(1 - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    neg-sub0 [<=]59.1%

    \[ \frac{\color{blue}{-\log \left(1 - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    sub-neg [=>]59.1%

    \[ \frac{-\log \color{blue}{\left(1 + \left(-u0\right)\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

    log1p-def [=>]98.1%

    \[ \frac{-\color{blue}{\mathsf{log1p}\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Final simplification98.1%

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

Alternatives

Alternative 1
Accuracy98.4%
Cost3680
\[\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 2
Accuracy87.6%
Cost3684
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 5.60000010807471 \cdot 10^{-8}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{log1p}\left(-u0\right) \cdot \left(alphay \cdot \frac{-alphay}{sin2phi}\right)\\ \end{array} \]
Alternative 3
Accuracy87.5%
Cost3684
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 5.000000058430487 \cdot 10^{-8}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(\mathsf{log1p}\left(-u0\right) \cdot \left(-alphay\right)\right)}{sin2phi}\\ \end{array} \]
Alternative 4
Accuracy87.5%
Cost3684
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 5.000000058430487 \cdot 10^{-8}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(-u0\right) \cdot \left(alphay \cdot \left(-alphay\right)\right)}{sin2phi}\\ \end{array} \]
Alternative 5
Accuracy81.6%
Cost612
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 50:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot \frac{alphay}{sin2phi}\right) \cdot \left(u0 - \left(u0 \cdot u0\right) \cdot -0.5\right)\\ \end{array} \]
Alternative 6
Accuracy81.6%
Cost612
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 50:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{alphay \cdot \left(alphay \cdot \left(u0 - \left(u0 \cdot u0\right) \cdot -0.5\right)\right)}{sin2phi}\\ \end{array} \]
Alternative 7
Accuracy81.6%
Cost612
\[\begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 50:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + t_0}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(alphay \cdot alphay\right) \cdot \left(u0 - \left(u0 \cdot u0\right) \cdot -0.5\right)}{sin2phi}\\ \end{array} \]
Alternative 8
Accuracy66.4%
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax}}\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]
Alternative 9
Accuracy66.4%
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;\frac{u0 \cdot \left(alphax \cdot alphax\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]
Alternative 10
Accuracy66.4%
Cost420
\[\begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 4.9999998413276127 \cdot 10^{-20}:\\ \;\;\;\;\frac{u0 \cdot \left(alphax \cdot alphax\right)}{cos2phi}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0 \cdot \left(alphay \cdot alphay\right)}{sin2phi}\\ \end{array} \]
Alternative 11
Accuracy76.1%
Cost416
\[\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
Alternative 12
Accuracy58.8%
Cost224
\[\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi} \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (alphax alphay u0 cos2phi sin2phi)
  :name "Beckmann Distribution sample, tan2theta, alphax != alphay, u1 <= 0.5"
  :precision binary32
  :pre (and (and (and (and (and (<= 0.0001 alphax) (<= alphax 1.0)) (and (<= 0.0001 alphay) (<= alphay 1.0))) (and (<= 2.328306437e-10 u0) (<= u0 1.0))) (and (<= 0.0 cos2phi) (<= cos2phi 1.0))) (<= 0.0 sin2phi))
  (/ (- (log (- 1.0 u0))) (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))