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

Percentage Accurate: 61.1% → 98.4%
Time: 19.9s
Alternatives: 8
Speedup: 8.9×

Specification

?
\[\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\]
\[\begin{array}{l} \\ \frac{-\log \left(1 - 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)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
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 tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
end
\begin{array}{l}

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

Sampling outcomes in binary32 precision:

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.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
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.

Initial Program: 61.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{-\log \left(1 - 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)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -logf((1.0f - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = -log((1.0e0 - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
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 tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = -log((single(1.0) - u0)) / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
end
\begin{array}{l}

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

Alternative 1: 98.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \frac{-\mathsf{log1p}\left(-u0\right)}{{alphax}^{-2} \cdot cos2phi + \frac{\frac{sin2phi}{alphay}}{alphay}} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log1p (- u0)))
  (+ (* (pow alphax -2.0) cos2phi) (/ (/ sin2phi alphay) alphay))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -log1pf(-u0) / ((powf(alphax, -2.0f) * cos2phi) + ((sin2phi / alphay) / alphay));
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log1p(Float32(-u0))) / Float32(Float32((alphax ^ Float32(-2.0)) * cos2phi) + Float32(Float32(sin2phi / alphay) / alphay)))
end
\begin{array}{l}

\\
\frac{-\mathsf{log1p}\left(-u0\right)}{{alphax}^{-2} \cdot cos2phi + \frac{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sqr-neg58.9%

      \[\leadsto \frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{\left(-alphay\right) \cdot \left(-alphay\right)}}} \]
    2. sub-neg58.9%

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

      \[\leadsto \frac{-\color{blue}{\mathsf{log1p}\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\left(-alphay\right) \cdot \left(-alphay\right)}} \]
    4. sqr-neg98.1%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
    5. associate-/r*98.0%

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

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}} \]
  4. Step-by-step derivation
    1. div-inv98.0%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{cos2phi \cdot \frac{1}{alphax \cdot alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    2. *-commutative98.0%

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

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{1}{\color{blue}{{alphax}^{2}}} \cdot cos2phi + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    4. pow-flip98.1%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{{alphax}^{\left(-2\right)}} \cdot cos2phi + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    5. metadata-eval98.1%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{{alphax}^{\color{blue}{-2}} \cdot cos2phi + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  5. Applied egg-rr98.1%

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

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

Alternative 2: 83.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9990000128746033:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{\frac{sin2phi}{\log \left(1 - u0\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \end{array} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (if (<= (- 1.0 u0) 0.9990000128746033)
   (/ (* alphay (- alphay)) (/ sin2phi (log (- 1.0 u0))))
   (/ u0 (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay))))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	float tmp;
	if ((1.0f - u0) <= 0.9990000128746033f) {
		tmp = (alphay * -alphay) / (sin2phi / logf((1.0f - u0)));
	} else {
		tmp = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
	}
	return tmp;
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    real(4) :: tmp
    if ((1.0e0 - u0) <= 0.9990000128746033e0) then
        tmp = (alphay * -alphay) / (sin2phi / log((1.0e0 - u0)))
    else
        tmp = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
    end if
    code = tmp
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = Float32(0.0)
	if (Float32(Float32(1.0) - u0) <= Float32(0.9990000128746033))
		tmp = Float32(Float32(alphay * Float32(-alphay)) / Float32(sin2phi / log(Float32(Float32(1.0) - u0))));
	else
		tmp = Float32(u0 / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))));
	end
	return tmp
end
function tmp_2 = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = single(0.0);
	if ((single(1.0) - u0) <= single(0.9990000128746033))
		tmp = (alphay * -alphay) / (sin2phi / log((single(1.0) - u0)));
	else
		tmp = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;1 - u0 \leq 0.9990000128746033:\\
\;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{\frac{sin2phi}{\log \left(1 - u0\right)}}\\

\mathbf{else}:\\
\;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f32 1 u0) < 0.999000013

    1. Initial program 89.9%

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. Taylor expanded in cos2phi around 0 72.1%

      \[\leadsto \color{blue}{-1 \cdot \frac{{alphay}^{2} \cdot \log \left(1 - u0\right)}{sin2phi}} \]
    3. Step-by-step derivation
      1. associate-/l*72.3%

        \[\leadsto -1 \cdot \color{blue}{\frac{{alphay}^{2}}{\frac{sin2phi}{\log \left(1 - u0\right)}}} \]
      2. associate-*r/72.3%

        \[\leadsto \color{blue}{\frac{-1 \cdot {alphay}^{2}}{\frac{sin2phi}{\log \left(1 - u0\right)}}} \]
      3. neg-mul-172.3%

        \[\leadsto \frac{\color{blue}{-{alphay}^{2}}}{\frac{sin2phi}{\log \left(1 - u0\right)}} \]
    4. Simplified72.3%

      \[\leadsto \color{blue}{\frac{-{alphay}^{2}}{\frac{sin2phi}{\log \left(1 - u0\right)}}} \]
    5. Step-by-step derivation
      1. unpow272.3%

        \[\leadsto \frac{-\color{blue}{alphay \cdot alphay}}{\frac{sin2phi}{\log \left(1 - u0\right)}} \]
    6. Applied egg-rr72.3%

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

    if 0.999000013 < (-.f32 1 u0)

    1. Initial program 44.3%

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. Taylor expanded in u0 around 0 89.0%

      \[\leadsto \frac{-\color{blue}{-1 \cdot u0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    3. Step-by-step derivation
      1. mul-1-neg89.0%

        \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    4. Simplified89.0%

      \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification83.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9990000128746033:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{\frac{sin2phi}{\log \left(1 - u0\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}\\ \end{array} \]

Alternative 3: 98.4% accurate, 1.0× speedup?

\[\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
 (/
  (- (log1p (- 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(-log1p(Float32(-u0))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
\begin{array}{l}

\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg58.9%

      \[\leadsto \frac{-\log \color{blue}{\left(1 + \left(-u0\right)\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. log1p-def98.1%

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

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

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

Alternative 4: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{\frac{sin2phi}{alphay}}{alphay} + \frac{\frac{cos2phi}{alphax}}{alphax}} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- (log1p (- u0)))
  (+ (/ (/ sin2phi alphay) alphay) (/ (/ cos2phi alphax) alphax))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return -log1pf(-u0) / (((sin2phi / alphay) / alphay) + ((cos2phi / alphax) / alphax));
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(-log1p(Float32(-u0))) / Float32(Float32(Float32(sin2phi / alphay) / alphay) + Float32(Float32(cos2phi / alphax) / alphax)))
end
\begin{array}{l}

\\
\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{\frac{sin2phi}{alphay}}{alphay} + \frac{\frac{cos2phi}{alphax}}{alphax}}
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sqr-neg58.9%

      \[\leadsto \frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{\left(-alphay\right) \cdot \left(-alphay\right)}}} \]
    2. sub-neg58.9%

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

      \[\leadsto \frac{-\color{blue}{\mathsf{log1p}\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\left(-alphay\right) \cdot \left(-alphay\right)}} \]
    4. sqr-neg98.1%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
    5. associate-/r*98.0%

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

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}}} \]
  4. Step-by-step derivation
    1. add-sqr-sqrt97.9%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{\color{blue}{\sqrt{cos2phi} \cdot \sqrt{cos2phi}}}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    2. times-frac97.8%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{\sqrt{cos2phi}}{alphax} \cdot \frac{\sqrt{cos2phi}}{alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  5. Applied egg-rr97.8%

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{\sqrt{cos2phi}}{alphax} \cdot \frac{\sqrt{cos2phi}}{alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  6. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{{\left(\frac{\sqrt{cos2phi}}{alphax}\right)}^{2}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  7. Simplified97.8%

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{{\left(\frac{\sqrt{cos2phi}}{alphax}\right)}^{2}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  8. Step-by-step derivation
    1. unpow297.8%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{\sqrt{cos2phi}}{alphax} \cdot \frac{\sqrt{cos2phi}}{alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    2. times-frac97.9%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{\sqrt{cos2phi} \cdot \sqrt{cos2phi}}{alphax \cdot alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    3. add-sqr-sqrt98.0%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{\color{blue}{cos2phi}}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
    4. associate-/r*98.1%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{\frac{cos2phi}{alphax}}{alphax}} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  9. Applied egg-rr98.1%

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

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

Alternative 5: 75.6% accurate, 8.9× speedup?

\[\begin{array}{l} \\ \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/ u0 (+ (/ cos2phi (* alphax alphax)) (/ sin2phi (* alphay alphay)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(u0 / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(sin2phi / Float32(alphay * alphay))))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = u0 / ((cos2phi / (alphax * alphax)) + (sin2phi / (alphay * alphay)));
end
\begin{array}{l}

\\
\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Taylor expanded in u0 around 0 75.0%

    \[\leadsto \frac{-\color{blue}{-1 \cdot u0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Step-by-step derivation
    1. mul-1-neg75.0%

      \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  4. Simplified75.0%

    \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  5. Final simplification75.0%

    \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]

Alternative 6: 59.0% accurate, 12.9× speedup?

\[\begin{array}{l} \\ \frac{1}{sin2phi} \cdot \left(alphay \cdot \left(u0 \cdot alphay\right)\right) \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (* (/ 1.0 sin2phi) (* alphay (* u0 alphay))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return (1.0f / sin2phi) * (alphay * (u0 * alphay));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = (1.0e0 / sin2phi) * (alphay * (u0 * alphay))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(Float32(1.0) / sin2phi) * Float32(alphay * Float32(u0 * alphay)))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = (single(1.0) / sin2phi) * (alphay * (u0 * alphay));
end
\begin{array}{l}

\\
\frac{1}{sin2phi} \cdot \left(alphay \cdot \left(u0 \cdot alphay\right)\right)
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Taylor expanded in u0 around 0 75.0%

    \[\leadsto \frac{-\color{blue}{-1 \cdot u0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Step-by-step derivation
    1. mul-1-neg75.0%

      \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  4. Simplified75.0%

    \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  5. Taylor expanded in cos2phi around 0 57.3%

    \[\leadsto \color{blue}{\frac{{alphay}^{2} \cdot u0}{sin2phi}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{\frac{{alphay}^{2}}{\frac{sin2phi}{u0}}} \]
    2. *-un-lft-identity56.9%

      \[\leadsto \frac{\color{blue}{1 \cdot {alphay}^{2}}}{\frac{sin2phi}{u0}} \]
    3. div-inv56.8%

      \[\leadsto \frac{1 \cdot {alphay}^{2}}{\color{blue}{sin2phi \cdot \frac{1}{u0}}} \]
    4. times-frac57.2%

      \[\leadsto \color{blue}{\frac{1}{sin2phi} \cdot \frac{{alphay}^{2}}{\frac{1}{u0}}} \]
  7. Applied egg-rr57.2%

    \[\leadsto \color{blue}{\frac{1}{sin2phi} \cdot \frac{{alphay}^{2}}{\frac{1}{u0}}} \]
  8. Step-by-step derivation
    1. div-inv57.2%

      \[\leadsto \frac{1}{sin2phi} \cdot \color{blue}{\left({alphay}^{2} \cdot \frac{1}{\frac{1}{u0}}\right)} \]
    2. unpow257.2%

      \[\leadsto \frac{1}{sin2phi} \cdot \left(\color{blue}{\left(alphay \cdot alphay\right)} \cdot \frac{1}{\frac{1}{u0}}\right) \]
    3. associate-*l*57.3%

      \[\leadsto \frac{1}{sin2phi} \cdot \color{blue}{\left(alphay \cdot \left(alphay \cdot \frac{1}{\frac{1}{u0}}\right)\right)} \]
    4. remove-double-div57.4%

      \[\leadsto \frac{1}{sin2phi} \cdot \left(alphay \cdot \left(alphay \cdot \color{blue}{u0}\right)\right) \]
  9. Applied egg-rr57.4%

    \[\leadsto \frac{1}{sin2phi} \cdot \color{blue}{\left(alphay \cdot \left(alphay \cdot u0\right)\right)} \]
  10. Final simplification57.4%

    \[\leadsto \frac{1}{sin2phi} \cdot \left(alphay \cdot \left(u0 \cdot alphay\right)\right) \]

Alternative 7: 59.0% accurate, 16.6× speedup?

\[\begin{array}{l} \\ alphay \cdot \left(u0 \cdot \frac{alphay}{sin2phi}\right) \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (* alphay (* u0 (/ alphay sin2phi))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return alphay * (u0 * (alphay / sin2phi));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = alphay * (u0 * (alphay / sin2phi))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(alphay * Float32(u0 * Float32(alphay / sin2phi)))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = alphay * (u0 * (alphay / sin2phi));
end
\begin{array}{l}

\\
alphay \cdot \left(u0 \cdot \frac{alphay}{sin2phi}\right)
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Taylor expanded in u0 around 0 75.0%

    \[\leadsto \frac{-\color{blue}{-1 \cdot u0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Step-by-step derivation
    1. mul-1-neg75.0%

      \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  4. Simplified75.0%

    \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  5. Taylor expanded in cos2phi around 0 57.3%

    \[\leadsto \color{blue}{\frac{{alphay}^{2} \cdot u0}{sin2phi}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{\frac{{alphay}^{2}}{\frac{sin2phi}{u0}}} \]
    2. unpow256.9%

      \[\leadsto \frac{\color{blue}{alphay \cdot alphay}}{\frac{sin2phi}{u0}} \]
    3. *-un-lft-identity56.9%

      \[\leadsto \frac{alphay \cdot alphay}{\color{blue}{1 \cdot \frac{sin2phi}{u0}}} \]
    4. times-frac56.9%

      \[\leadsto \color{blue}{\frac{alphay}{1} \cdot \frac{alphay}{\frac{sin2phi}{u0}}} \]
    5. /-rgt-identity56.9%

      \[\leadsto \color{blue}{alphay} \cdot \frac{alphay}{\frac{sin2phi}{u0}} \]
  7. Applied egg-rr56.9%

    \[\leadsto \color{blue}{alphay \cdot \frac{alphay}{\frac{sin2phi}{u0}}} \]
  8. Step-by-step derivation
    1. associate-/r/57.2%

      \[\leadsto alphay \cdot \color{blue}{\left(\frac{alphay}{sin2phi} \cdot u0\right)} \]
  9. Applied egg-rr57.2%

    \[\leadsto alphay \cdot \color{blue}{\left(\frac{alphay}{sin2phi} \cdot u0\right)} \]
  10. Final simplification57.2%

    \[\leadsto alphay \cdot \left(u0 \cdot \frac{alphay}{sin2phi}\right) \]

Alternative 8: 59.0% accurate, 16.6× speedup?

\[\begin{array}{l} \\ alphay \cdot \left(alphay \cdot \frac{u0}{sin2phi}\right) \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (* alphay (* alphay (/ u0 sin2phi))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return alphay * (alphay * (u0 / sin2phi));
}
real(4) function code(alphax, alphay, u0, cos2phi, sin2phi)
    real(4), intent (in) :: alphax
    real(4), intent (in) :: alphay
    real(4), intent (in) :: u0
    real(4), intent (in) :: cos2phi
    real(4), intent (in) :: sin2phi
    code = alphay * (alphay * (u0 / sin2phi))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(alphay * Float32(alphay * Float32(u0 / sin2phi)))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = alphay * (alphay * (u0 / sin2phi));
end
\begin{array}{l}

\\
alphay \cdot \left(alphay \cdot \frac{u0}{sin2phi}\right)
\end{array}
Derivation
  1. Initial program 58.9%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Taylor expanded in u0 around 0 75.0%

    \[\leadsto \frac{-\color{blue}{-1 \cdot u0}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  3. Step-by-step derivation
    1. mul-1-neg75.0%

      \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  4. Simplified75.0%

    \[\leadsto \frac{-\color{blue}{\left(-u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  5. Taylor expanded in cos2phi around 0 57.3%

    \[\leadsto \color{blue}{\frac{{alphay}^{2} \cdot u0}{sin2phi}} \]
  6. Step-by-step derivation
    1. associate-/l*56.9%

      \[\leadsto \color{blue}{\frac{{alphay}^{2}}{\frac{sin2phi}{u0}}} \]
    2. unpow256.9%

      \[\leadsto \frac{\color{blue}{alphay \cdot alphay}}{\frac{sin2phi}{u0}} \]
    3. *-un-lft-identity56.9%

      \[\leadsto \frac{alphay \cdot alphay}{\color{blue}{1 \cdot \frac{sin2phi}{u0}}} \]
    4. times-frac56.9%

      \[\leadsto \color{blue}{\frac{alphay}{1} \cdot \frac{alphay}{\frac{sin2phi}{u0}}} \]
    5. /-rgt-identity56.9%

      \[\leadsto \color{blue}{alphay} \cdot \frac{alphay}{\frac{sin2phi}{u0}} \]
  7. Applied egg-rr56.9%

    \[\leadsto \color{blue}{alphay \cdot \frac{alphay}{\frac{sin2phi}{u0}}} \]
  8. Step-by-step derivation
    1. div-inv56.8%

      \[\leadsto alphay \cdot \color{blue}{\left(alphay \cdot \frac{1}{\frac{sin2phi}{u0}}\right)} \]
    2. *-commutative56.8%

      \[\leadsto alphay \cdot \color{blue}{\left(\frac{1}{\frac{sin2phi}{u0}} \cdot alphay\right)} \]
    3. clear-num57.3%

      \[\leadsto alphay \cdot \left(\color{blue}{\frac{u0}{sin2phi}} \cdot alphay\right) \]
  9. Applied egg-rr57.3%

    \[\leadsto alphay \cdot \color{blue}{\left(\frac{u0}{sin2phi} \cdot alphay\right)} \]
  10. Final simplification57.3%

    \[\leadsto alphay \cdot \left(alphay \cdot \frac{u0}{sin2phi}\right) \]

Reproduce

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