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

Percentage Accurate: 60.0% → 98.5%
Time: 19.1s
Alternatives: 10
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 10 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: 60.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.5% accurate, 1.0× speedup?

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

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

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. associate-/r*98.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 87.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 0.012000000104308128:\\
\;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} - \frac{sin2phi}{alphay} \cdot \frac{-1}{alphay}}\\

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


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

    1. Initial program 60.2%

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

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

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

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

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

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

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

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

    1. Initial program 66.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax, \frac{alphay \cdot cos2phi}{alphax}\right)} \cdot \left(alphax \cdot alphay\right)} \]
    11. Taylor expanded in sin2phi around inf 66.9%

      \[\leadsto \color{blue}{\left(-1 \cdot \frac{alphay \cdot \log \left(1 - u0\right)}{alphax \cdot sin2phi}\right)} \cdot \left(alphax \cdot alphay\right) \]
    12. Step-by-step derivation
      1. mul-1-neg66.9%

        \[\leadsto \color{blue}{\left(-\frac{alphay \cdot \log \left(1 - u0\right)}{alphax \cdot sin2phi}\right)} \cdot \left(alphax \cdot alphay\right) \]
      2. times-frac67.0%

        \[\leadsto \left(-\color{blue}{\frac{alphay}{alphax} \cdot \frac{\log \left(1 - u0\right)}{sin2phi}}\right) \cdot \left(alphax \cdot alphay\right) \]
      3. distribute-rgt-neg-in67.0%

        \[\leadsto \color{blue}{\left(\frac{alphay}{alphax} \cdot \left(-\frac{\log \left(1 - u0\right)}{sin2phi}\right)\right)} \cdot \left(alphax \cdot alphay\right) \]
      4. sub-neg67.0%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{sin2phi}{alphay \cdot alphay} \leq 0.012000000104308128:\\ \;\;\;\;\frac{u0}{\frac{cos2phi}{alphax \cdot alphax} - \frac{sin2phi}{alphay} \cdot \frac{-1}{alphay}}\\ \mathbf{else}:\\ \;\;\;\;\left(alphax \cdot alphay\right) \cdot \left(\frac{\mathsf{log1p}\left(-u0\right)}{sin2phi} \cdot \frac{-alphay}{alphax}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 98.5% accurate, 1.0× speedup?

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

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

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. associate-/r*98.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax, \frac{alphay \cdot cos2phi}{alphax}\right)} \cdot \left(alphax \cdot alphay\right)} \]
  11. Step-by-step derivation
    1. fma-udef98.3%

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

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

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

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

Alternative 4: 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 64.2%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Final simplification98.1%

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

Alternative 5: 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 64.2%

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. clear-num75.7%

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

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

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

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

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

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

      \[\leadsto \frac{-\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \color{blue}{sin2phi \cdot {alphay}^{-2}}} \]
    2. metadata-eval75.7%

      \[\leadsto \frac{-\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + sin2phi \cdot {alphay}^{\color{blue}{\left(-2\right)}}} \]
    3. pow-flip75.6%

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

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

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

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

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

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

Alternative 6: 76.3% accurate, 6.8× speedup?

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

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

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. associate-/r*98.1%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{u0}{\frac{alphax \cdot sin2phi}{alphay} + \frac{alphay \cdot cos2phi}{alphax}}} \cdot \left(alphax \cdot alphay\right) \]
  12. Final simplification76.1%

    \[\leadsto \left(alphax \cdot alphay\right) \cdot \frac{u0}{\frac{alphax \cdot sin2phi}{alphay} + \frac{alphay \cdot cos2phi}{alphax}} \]
  13. Add Preprocessing

Alternative 7: 76.2% 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 64.2%

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

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

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

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

    \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  7. Add Preprocessing

Alternative 8: 76.2% accurate, 8.9× speedup?

\[\begin{array}{l} \\ \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{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(Float32(sin2phi / 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{\frac{sin2phi}{alphay}}{alphay}}
\end{array}
Derivation
  1. Initial program 64.2%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{-\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \color{blue}{sin2phi \cdot {alphay}^{-2}}} \]
    2. metadata-eval75.7%

      \[\leadsto \frac{-\left(-u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + sin2phi \cdot {alphay}^{\color{blue}{\left(-2\right)}}} \]
    3. pow-flip75.6%

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

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

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

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

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

    \[\leadsto \frac{u0}{\frac{cos2phi}{alphax \cdot alphax} + \frac{\frac{sin2phi}{alphay}}{alphay}} \]
  11. Add Preprocessing

Alternative 9: 59.2% accurate, 10.5× speedup?

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

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

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. associate-/r*98.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax, \frac{alphay \cdot cos2phi}{alphax}\right)} \cdot \left(alphax \cdot alphay\right)} \]
  11. Taylor expanded in sin2phi around inf 75.0%

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

    \[\leadsto \color{blue}{\frac{alphay \cdot u0}{alphax \cdot sin2phi}} \cdot \left(alphax \cdot alphay\right) \]
  13. Step-by-step derivation
    1. times-frac60.7%

      \[\leadsto \color{blue}{\left(\frac{alphay}{alphax} \cdot \frac{u0}{sin2phi}\right)} \cdot \left(alphax \cdot alphay\right) \]
  14. Simplified60.7%

    \[\leadsto \color{blue}{\left(\frac{alphay}{alphax} \cdot \frac{u0}{sin2phi}\right)} \cdot \left(alphax \cdot alphay\right) \]
  15. Final simplification60.7%

    \[\leadsto \left(alphax \cdot alphay\right) \cdot \left(\frac{alphay}{alphax} \cdot \frac{u0}{sin2phi}\right) \]
  16. Add Preprocessing

Alternative 10: 59.2% accurate, 10.5× speedup?

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

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

    \[\frac{-\log \left(1 - u0\right)}{\frac{cos2phi}{alphax \cdot alphax} + \frac{sin2phi}{alphay \cdot alphay}} \]
  2. Step-by-step derivation
    1. sub-neg64.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.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. Add Preprocessing
  5. Step-by-step derivation
    1. associate-/r*98.1%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{-\mathsf{log1p}\left(-u0\right)}{\mathsf{fma}\left(\frac{sin2phi}{alphay}, alphax, \frac{alphay \cdot cos2phi}{alphax}\right)} \cdot \left(alphax \cdot alphay\right)} \]
  11. Taylor expanded in sin2phi around inf 75.0%

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

    \[\leadsto \color{blue}{\frac{alphay \cdot u0}{alphax \cdot sin2phi}} \cdot \left(alphax \cdot alphay\right) \]
  13. Step-by-step derivation
    1. *-commutative60.7%

      \[\leadsto \frac{alphay \cdot u0}{\color{blue}{sin2phi \cdot alphax}} \cdot \left(alphax \cdot alphay\right) \]
    2. times-frac60.7%

      \[\leadsto \color{blue}{\left(\frac{alphay}{sin2phi} \cdot \frac{u0}{alphax}\right)} \cdot \left(alphax \cdot alphay\right) \]
  14. Simplified60.7%

    \[\leadsto \color{blue}{\left(\frac{alphay}{sin2phi} \cdot \frac{u0}{alphax}\right)} \cdot \left(alphax \cdot alphay\right) \]
  15. Final simplification60.7%

    \[\leadsto \left(alphax \cdot alphay\right) \cdot \left(\frac{alphay}{sin2phi} \cdot \frac{u0}{alphax}\right) \]
  16. Add Preprocessing

Reproduce

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