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

Percentage Accurate: 61.0% → 98.4%
Time: 14.9s
Alternatives: 9
Speedup: 12.7×

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 9 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.0% 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} \\ alphay \cdot \frac{\mathsf{log1p}\left(-u0\right) \cdot \left(alphax \cdot \left(-alphax\right)\right)}{\mathsf{fma}\left(cos2phi, alphay, \left(alphax \cdot alphax\right) \cdot \frac{sin2phi}{alphay}\right)} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (*
  alphay
  (/
   (* (log1p (- u0)) (* alphax (- alphax)))
   (fma cos2phi alphay (* (* alphax alphax) (/ sin2phi alphay))))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return alphay * ((log1pf(-u0) * (alphax * -alphax)) / fmaf(cos2phi, alphay, ((alphax * alphax) * (sin2phi / alphay))));
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(alphay * Float32(Float32(log1p(Float32(-u0)) * Float32(alphax * Float32(-alphax))) / fma(cos2phi, alphay, Float32(Float32(alphax * alphax) * Float32(sin2phi / alphay)))))
end
\begin{array}{l}

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \color{blue}{\frac{\frac{sin2phi}{alphay}}{alphay}}} \]
  8. Step-by-step derivation
    1. associate-/r*98.4%

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

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

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

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

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

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

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

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

      \[\leadsto \left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{1}{\frac{\color{blue}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, alphay \cdot cos2phi\right)}}{alphay \cdot \left(alphax \cdot alphax\right)}} \]
    3. *-commutative97.9%

      \[\leadsto \left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, \color{blue}{cos2phi \cdot alphay}\right)}{alphay \cdot \left(alphax \cdot alphax\right)}} \]
    4. *-commutative97.9%

      \[\leadsto \left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}{\color{blue}{\left(alphax \cdot alphax\right) \cdot alphay}}} \]
  11. Applied egg-rr97.9%

    \[\leadsto \color{blue}{\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot \frac{1}{\frac{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}{\left(alphax \cdot alphax\right) \cdot alphay}}} \]
  12. Step-by-step derivation
    1. associate-*r/98.1%

      \[\leadsto \color{blue}{\frac{\left(-\mathsf{log1p}\left(-u0\right)\right) \cdot 1}{\frac{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}{\left(alphax \cdot alphax\right) \cdot alphay}}} \]
    2. *-rgt-identity98.1%

      \[\leadsto \frac{\color{blue}{-\mathsf{log1p}\left(-u0\right)}}{\frac{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}{\left(alphax \cdot alphax\right) \cdot alphay}} \]
    3. distribute-neg-frac98.1%

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

      \[\leadsto -\color{blue}{\frac{\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)} \cdot \left(\left(alphax \cdot alphax\right) \cdot alphay\right)} \]
    5. distribute-lft-neg-in98.5%

      \[\leadsto \color{blue}{\left(-\frac{\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}\right) \cdot \left(\left(alphax \cdot alphax\right) \cdot alphay\right)} \]
    6. distribute-frac-neg98.5%

      \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)}} \cdot \left(\left(alphax \cdot alphax\right) \cdot alphay\right) \]
    7. unpow298.5%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)} \cdot \left(\color{blue}{{alphax}^{2}} \cdot alphay\right) \]
    8. associate-*r*98.4%

      \[\leadsto \color{blue}{\left(\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)} \cdot {alphax}^{2}\right) \cdot alphay} \]
    9. *-commutative98.4%

      \[\leadsto \color{blue}{alphay \cdot \left(\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax \cdot alphax, cos2phi \cdot alphay\right)} \cdot {alphax}^{2}\right)} \]
  13. Simplified98.3%

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

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

Alternative 2: 92.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{sin2phi}{alphay \cdot alphay}\\ \mathbf{if}\;t_0 \leq 50:\\ \;\;\;\;\frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\mathsf{log1p}\left(-u0\right)}{t_0}\\ \end{array} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (let* ((t_0 (/ sin2phi (* alphay alphay))))
   (if (<= t_0 50.0)
     (/
      (- u0 (* (* u0 u0) -0.5))
      (+ (/ cos2phi (* alphax alphax)) (/ 1.0 (/ (* alphay alphay) sin2phi))))
     (/ (- (log1p (- u0))) t_0))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	float t_0 = sin2phi / (alphay * alphay);
	float tmp;
	if (t_0 <= 50.0f) {
		tmp = (u0 - ((u0 * u0) * -0.5f)) / ((cos2phi / (alphax * alphax)) + (1.0f / ((alphay * alphay) / sin2phi)));
	} else {
		tmp = -log1pf(-u0) / t_0;
	}
	return tmp;
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	t_0 = Float32(sin2phi / Float32(alphay * alphay))
	tmp = Float32(0.0)
	if (t_0 <= Float32(50.0))
		tmp = Float32(Float32(u0 - Float32(Float32(u0 * u0) * Float32(-0.5))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(Float32(1.0) / Float32(Float32(alphay * alphay) / sin2phi))));
	else
		tmp = Float32(Float32(-log1p(Float32(-u0))) / t_0);
	end
	return tmp
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{sin2phi}{alphay \cdot alphay}\\
\mathbf{if}\;t_0 \leq 50:\\
\;\;\;\;\frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{-\mathsf{log1p}\left(-u0\right)}{t_0}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f32 sin2phi (*.f32 alphay alphay)) < 50

    1. Initial program 53.7%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot u0 + -0.5 \cdot {u0}^{2}\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    9. Step-by-step derivation
      1. +-commutative89.2%

        \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} + -1 \cdot u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      2. neg-mul-189.2%

        \[\leadsto \frac{-\left(-0.5 \cdot {u0}^{2} + \color{blue}{\left(-u0\right)}\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      3. unsub-neg89.2%

        \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      4. *-commutative89.2%

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

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

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

    if 50 < (/.f32 sin2phi (*.f32 alphay alphay))

    1. Initial program 65.2%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
    8. Simplified97.7%

      \[\leadsto \frac{-\mathsf{log1p}\left(-u0\right)}{\color{blue}{\frac{sin2phi}{alphay \cdot alphay}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 50:\\ \;\;\;\;\frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{-\mathsf{log1p}\left(-u0\right)}{\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 59.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 91.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;1 - u0 \leq 0.9945999979972839:\\ \;\;\;\;\frac{alphay \cdot \left(-alphay\right)}{\frac{sin2phi}{\mathsf{log1p}\left(-u0\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\ \end{array} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (if (<= (- 1.0 u0) 0.9945999979972839)
   (/ (* alphay (- alphay)) (/ sin2phi (log1p (- u0))))
   (/
    (- u0 (* (* u0 u0) -0.5))
    (+ (/ cos2phi (* alphax alphax)) (/ 1.0 (/ (* alphay alphay) sin2phi))))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	float tmp;
	if ((1.0f - u0) <= 0.9945999979972839f) {
		tmp = (alphay * -alphay) / (sin2phi / log1pf(-u0));
	} else {
		tmp = (u0 - ((u0 * u0) * -0.5f)) / ((cos2phi / (alphax * alphax)) + (1.0f / ((alphay * alphay) / sin2phi)));
	}
	return tmp;
}
function code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = Float32(0.0)
	if (Float32(Float32(1.0) - u0) <= Float32(0.9945999979972839))
		tmp = Float32(Float32(alphay * Float32(-alphay)) / Float32(sin2phi / log1p(Float32(-u0))));
	else
		tmp = Float32(Float32(u0 - Float32(Float32(u0 * u0) * Float32(-0.5))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(Float32(1.0) / Float32(Float32(alphay * alphay) / sin2phi))));
	end
	return tmp
end
\begin{array}{l}

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

\mathbf{else}:\\
\;\;\;\;\frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}}\\


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

    1. Initial program 91.6%

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

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

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

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

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

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

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

        \[\leadsto -\color{blue}{\frac{alphay \cdot alphay}{\frac{sin2phi}{\log \left(1 - u0\right)}}} \]
      4. distribute-neg-frac78.7%

        \[\leadsto \color{blue}{\frac{-alphay \cdot alphay}{\frac{sin2phi}{\log \left(1 - u0\right)}}} \]
      5. distribute-rgt-neg-out78.7%

        \[\leadsto \frac{\color{blue}{alphay \cdot \left(-alphay\right)}}{\frac{sin2phi}{\log \left(1 - u0\right)}} \]
      6. sub-neg78.7%

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

        \[\leadsto \frac{alphay \cdot \left(-alphay\right)}{\frac{sin2phi}{\color{blue}{\mathsf{log1p}\left(-u0\right)}}} \]
    6. Simplified82.3%

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

    if 0.994599998 < (-.f32 1 u0)

    1. Initial program 49.2%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-\color{blue}{\left(-1 \cdot u0 + -0.5 \cdot {u0}^{2}\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    9. Step-by-step derivation
      1. +-commutative97.5%

        \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} + -1 \cdot u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      2. neg-mul-197.5%

        \[\leadsto \frac{-\left(-0.5 \cdot {u0}^{2} + \color{blue}{\left(-u0\right)}\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      3. unsub-neg97.5%

        \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
      4. *-commutative97.5%

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

        \[\leadsto \frac{-\left(\color{blue}{\left(u0 \cdot u0\right)} \cdot -0.5 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    10. Simplified97.5%

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

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

Alternative 6: 87.0% accurate, 5.5× speedup?

\[\begin{array}{l} \\ \frac{u0 - \left(u0 \cdot u0\right) \cdot -0.5}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (/
  (- u0 (* (* u0 u0) -0.5))
  (+ (/ cos2phi (* alphax alphax)) (/ 1.0 (/ (* alphay alphay) sin2phi)))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return (u0 - ((u0 * u0) * -0.5f)) / ((cos2phi / (alphax * alphax)) + (1.0f / ((alphay * 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 = (u0 - ((u0 * u0) * (-0.5e0))) / ((cos2phi / (alphax * alphax)) + (1.0e0 / ((alphay * alphay) / sin2phi)))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(Float32(u0 - Float32(Float32(u0 * u0) * Float32(-0.5))) / Float32(Float32(cos2phi / Float32(alphax * alphax)) + Float32(Float32(1.0) / Float32(Float32(alphay * alphay) / sin2phi))))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = (u0 - ((u0 * u0) * single(-0.5))) / ((cos2phi / (alphax * alphax)) + (single(1.0) / ((alphay * alphay) / sin2phi)));
end
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{-\color{blue}{\left(-1 \cdot u0 + -0.5 \cdot {u0}^{2}\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
  9. Step-by-step derivation
    1. +-commutative87.8%

      \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} + -1 \cdot u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    2. neg-mul-187.8%

      \[\leadsto \frac{-\left(-0.5 \cdot {u0}^{2} + \color{blue}{\left(-u0\right)}\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    3. unsub-neg87.8%

      \[\leadsto \frac{-\color{blue}{\left(-0.5 \cdot {u0}^{2} - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    4. *-commutative87.8%

      \[\leadsto \frac{-\left(\color{blue}{{u0}^{2} \cdot -0.5} - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
    5. unpow287.8%

      \[\leadsto \frac{-\left(\color{blue}{\left(u0 \cdot u0\right)} \cdot -0.5 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
  10. Simplified87.8%

    \[\leadsto \frac{-\color{blue}{\left(\left(u0 \cdot u0\right) \cdot -0.5 - u0\right)}}{\frac{cos2phi}{alphax \cdot alphax} + \frac{1}{\frac{alphay \cdot alphay}{sin2phi}}} \]
  11. Final simplification87.8%

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

Alternative 7: 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 59.3%

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

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

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

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

    \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{{alphax}^{2}} + \frac{sin2phi}{{alphay}^{2}}}} \]
  5. Step-by-step derivation
    1. unpow276.1%

      \[\leadsto \frac{u0}{\frac{cos2phi}{\color{blue}{alphax \cdot alphax}} + \frac{sin2phi}{{alphay}^{2}}} \]
    2. unpow276.1%

      \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
  6. Simplified76.1%

    \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
  7. Final simplification76.1%

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

Alternative 8: 66.7% accurate, 12.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;sin2phi \leq 4.999999841327613 \cdot 10^{-22}:\\ \;\;\;\;alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (if (<= sin2phi 4.999999841327613e-22)
   (* alphax (* alphax (/ u0 cos2phi)))
   (* (* alphay alphay) (/ u0 sin2phi))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	float tmp;
	if (sin2phi <= 4.999999841327613e-22f) {
		tmp = alphax * (alphax * (u0 / cos2phi));
	} else {
		tmp = (alphay * alphay) * (u0 / sin2phi);
	}
	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 (sin2phi <= 4.999999841327613e-22) then
        tmp = alphax * (alphax * (u0 / cos2phi))
    else
        tmp = (alphay * alphay) * (u0 / sin2phi)
    end if
    code = tmp
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = Float32(0.0)
	if (sin2phi <= Float32(4.999999841327613e-22))
		tmp = Float32(alphax * Float32(alphax * Float32(u0 / cos2phi)));
	else
		tmp = Float32(Float32(alphay * alphay) * Float32(u0 / sin2phi));
	end
	return tmp
end
function tmp_2 = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = single(0.0);
	if (sin2phi <= single(4.999999841327613e-22))
		tmp = alphax * (alphax * (u0 / cos2phi));
	else
		tmp = (alphay * alphay) * (u0 / sin2phi);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;sin2phi \leq 4.999999841327613 \cdot 10^{-22}:\\
\;\;\;\;alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if sin2phi < 4.9999998e-22

    1. Initial program 57.7%

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

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

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

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

      \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{{alphax}^{2}} + \frac{sin2phi}{{alphay}^{2}}}} \]
    5. Step-by-step derivation
      1. unpow273.7%

        \[\leadsto \frac{u0}{\frac{cos2phi}{\color{blue}{alphax \cdot alphax}} + \frac{sin2phi}{{alphay}^{2}}} \]
      2. unpow273.7%

        \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
    6. Simplified73.7%

      \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
    7. Taylor expanded in cos2phi around inf 59.1%

      \[\leadsto \color{blue}{\frac{{alphax}^{2} \cdot u0}{cos2phi}} \]
    8. Step-by-step derivation
      1. *-lft-identity59.1%

        \[\leadsto \frac{{alphax}^{2} \cdot u0}{\color{blue}{1 \cdot cos2phi}} \]
      2. times-frac59.0%

        \[\leadsto \color{blue}{\frac{{alphax}^{2}}{1} \cdot \frac{u0}{cos2phi}} \]
      3. /-rgt-identity59.0%

        \[\leadsto \color{blue}{{alphax}^{2}} \cdot \frac{u0}{cos2phi} \]
      4. unpow259.0%

        \[\leadsto \color{blue}{\left(alphax \cdot alphax\right)} \cdot \frac{u0}{cos2phi} \]
    9. Simplified59.0%

      \[\leadsto \color{blue}{\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}} \]
    10. Taylor expanded in alphax around 0 59.1%

      \[\leadsto \color{blue}{\frac{{alphax}^{2} \cdot u0}{cos2phi}} \]
    11. Step-by-step derivation
      1. unpow259.1%

        \[\leadsto \frac{\color{blue}{\left(alphax \cdot alphax\right)} \cdot u0}{cos2phi} \]
      2. associate-*r/59.0%

        \[\leadsto \color{blue}{\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}} \]
      3. associate-*l*59.2%

        \[\leadsto \color{blue}{alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)} \]
    12. Simplified59.2%

      \[\leadsto \color{blue}{alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)} \]

    if 4.9999998e-22 < sin2phi

    1. Initial program 59.9%

      \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
    2. Step-by-step derivation
      1. sub-neg59.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. Taylor expanded in u0 around 0 76.9%

      \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{{alphax}^{2}} + \frac{sin2phi}{{alphay}^{2}}}} \]
    5. Step-by-step derivation
      1. unpow276.9%

        \[\leadsto \frac{u0}{\frac{cos2phi}{\color{blue}{alphax \cdot alphax}} + \frac{sin2phi}{{alphay}^{2}}} \]
      2. unpow276.9%

        \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
    6. Simplified76.9%

      \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
    7. Taylor expanded in cos2phi around 0 71.4%

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

        \[\leadsto \frac{\color{blue}{\left(alphay \cdot alphay\right)} \cdot u0}{sin2phi} \]
      2. *-lft-identity71.4%

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

        \[\leadsto \color{blue}{\frac{alphay \cdot alphay}{1} \cdot \frac{u0}{sin2phi}} \]
      4. /-rgt-identity71.4%

        \[\leadsto \color{blue}{\left(alphay \cdot alphay\right)} \cdot \frac{u0}{sin2phi} \]
    9. Simplified71.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;sin2phi \leq 4.999999841327613 \cdot 10^{-22}:\\ \;\;\;\;alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(alphay \cdot alphay\right) \cdot \frac{u0}{sin2phi}\\ \end{array} \]

Alternative 9: 23.5% accurate, 16.6× speedup?

\[\begin{array}{l} \\ alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right) \end{array} \]
(FPCore (alphax alphay u0 cos2phi sin2phi)
 :precision binary32
 (* alphax (* alphax (/ u0 cos2phi))))
float code(float alphax, float alphay, float u0, float cos2phi, float sin2phi) {
	return alphax * (alphax * (u0 / cos2phi));
}
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 = alphax * (alphax * (u0 / cos2phi))
end function
function code(alphax, alphay, u0, cos2phi, sin2phi)
	return Float32(alphax * Float32(alphax * Float32(u0 / cos2phi)))
end
function tmp = code(alphax, alphay, u0, cos2phi, sin2phi)
	tmp = alphax * (alphax * (u0 / cos2phi));
end
\begin{array}{l}

\\
alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)
\end{array}
Derivation
  1. Initial program 59.3%

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

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

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

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

    \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{{alphax}^{2}} + \frac{sin2phi}{{alphay}^{2}}}} \]
  5. Step-by-step derivation
    1. unpow276.1%

      \[\leadsto \frac{u0}{\frac{cos2phi}{\color{blue}{alphax \cdot alphax}} + \frac{sin2phi}{{alphay}^{2}}} \]
    2. unpow276.1%

      \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{\color{blue}{alphay \cdot alphay}}} \]
  6. Simplified76.1%

    \[\leadsto \color{blue}{\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}}} \]
  7. Taylor expanded in cos2phi around inf 24.1%

    \[\leadsto \color{blue}{\frac{{alphax}^{2} \cdot u0}{cos2phi}} \]
  8. Step-by-step derivation
    1. *-lft-identity24.1%

      \[\leadsto \frac{{alphax}^{2} \cdot u0}{\color{blue}{1 \cdot cos2phi}} \]
    2. times-frac24.1%

      \[\leadsto \color{blue}{\frac{{alphax}^{2}}{1} \cdot \frac{u0}{cos2phi}} \]
    3. /-rgt-identity24.1%

      \[\leadsto \color{blue}{{alphax}^{2}} \cdot \frac{u0}{cos2phi} \]
    4. unpow224.1%

      \[\leadsto \color{blue}{\left(alphax \cdot alphax\right)} \cdot \frac{u0}{cos2phi} \]
  9. Simplified24.1%

    \[\leadsto \color{blue}{\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}} \]
  10. Taylor expanded in alphax around 0 24.1%

    \[\leadsto \color{blue}{\frac{{alphax}^{2} \cdot u0}{cos2phi}} \]
  11. Step-by-step derivation
    1. unpow224.1%

      \[\leadsto \frac{\color{blue}{\left(alphax \cdot alphax\right)} \cdot u0}{cos2phi} \]
    2. associate-*r/24.1%

      \[\leadsto \color{blue}{\left(alphax \cdot alphax\right) \cdot \frac{u0}{cos2phi}} \]
    3. associate-*l*24.1%

      \[\leadsto \color{blue}{alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)} \]
  12. Simplified24.1%

    \[\leadsto \color{blue}{alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right)} \]
  13. Final simplification24.1%

    \[\leadsto alphax \cdot \left(alphax \cdot \frac{u0}{cos2phi}\right) \]

Reproduce

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