Trowbridge-Reitz Sample, near normal, slope_y

Percentage Accurate: 98.3% → 98.5%
Time: 13.1s
Alternatives: 14
Speedup: 1.0×

Specification

?
\[\left(\left(cosTheta_i > 0.9999 \land cosTheta_i \leq 1\right) \land \left(2.328306437 \cdot 10^{-10} \leq u1 \land u1 \leq 1\right)\right) \land \left(2.328306437 \cdot 10^{-10} \leq u2 \land u2 \leq 1\right)\]
\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\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 14 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: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((6.28318530718f * u2));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((single(6.28318530718) * u2));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)
\end{array}

Alternative 1: 98.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{39.47841760436263 \cdot {u2}^{2}}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (sin (sqrt (* 39.47841760436263 (pow u2 2.0))))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf(sqrtf((39.47841760436263f * powf(u2, 2.0f))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin(sqrt((39.47841760436263e0 * (u2 ** 2.0e0))))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(sqrt(Float32(Float32(39.47841760436263) * (u2 ^ Float32(2.0))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin(sqrt((single(39.47841760436263) * (u2 ^ single(2.0)))));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{39.47841760436263 \cdot {u2}^{2}}\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. add-log-exp63.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\log \left(e^{6.28318530718 \cdot u2}\right)} \]
    2. exp-prod63.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \log \color{blue}{\left({\left(e^{6.28318530718}\right)}^{u2}\right)} \]
  3. Applied egg-rr63.4%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\log \left({\left(e^{6.28318530718}\right)}^{u2}\right)} \]
  4. Step-by-step derivation
    1. pow-exp63.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \log \color{blue}{\left(e^{6.28318530718 \cdot u2}\right)} \]
    2. add-log-exp98.2%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
    3. add-sqr-sqrt97.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
    4. sqrt-unprod98.2%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\left(\sqrt{\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)}\right)} \]
    5. rem-log-exp98.2%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\left(\color{blue}{\log \left(e^{6.28318530718}\right)} \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)}\right) \]
    6. rem-log-exp98.2%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\left(\log \left(e^{6.28318530718}\right) \cdot u2\right) \cdot \left(\color{blue}{\log \left(e^{6.28318530718}\right)} \cdot u2\right)}\right) \]
    7. swap-sqr98.0%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\color{blue}{\left(\log \left(e^{6.28318530718}\right) \cdot \log \left(e^{6.28318530718}\right)\right) \cdot \left(u2 \cdot u2\right)}}\right) \]
    8. rem-log-exp98.0%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\left(\color{blue}{6.28318530718} \cdot \log \left(e^{6.28318530718}\right)\right) \cdot \left(u2 \cdot u2\right)}\right) \]
    9. rem-log-exp98.0%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\left(6.28318530718 \cdot \color{blue}{6.28318530718}\right) \cdot \left(u2 \cdot u2\right)}\right) \]
    10. metadata-eval98.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)}\right) \]
    11. unpow298.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
  5. Applied egg-rr98.4%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \color{blue}{\left(\sqrt{39.47841760436263 \cdot {u2}^{2}}\right)} \]
  6. Final simplification98.4%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(\sqrt{39.47841760436263 \cdot {u2}^{2}}\right) \]

Alternative 2: 98.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - {u1}^{2}} \cdot \left(u1 + 1\right)} \cdot \sin \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (*
  (sqrt (* (/ u1 (- 1.0 (pow u1 2.0))) (+ u1 1.0)))
  (sin (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf(((u1 / (1.0f - powf(u1, 2.0f))) * (u1 + 1.0f))) * sinf((u2 * 6.28318530718f));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt(((u1 / (1.0e0 - (u1 ** 2.0e0))) * (u1 + 1.0e0))) * sin((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(Float32(u1 / Float32(Float32(1.0) - (u1 ^ Float32(2.0)))) * Float32(u1 + Float32(1.0)))) * sin(Float32(u2 * Float32(6.28318530718))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(((u1 / (single(1.0) - (u1 ^ single(2.0)))) * (u1 + single(1.0)))) * sin((u2 * single(6.28318530718)));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - {u1}^{2}} \cdot \left(u1 + 1\right)} \cdot \sin \left(u2 \cdot 6.28318530718\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. flip--98.3%

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{\frac{1 \cdot 1 - u1 \cdot u1}{1 + u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. associate-/r/98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 \cdot 1 - u1 \cdot u1} \cdot \left(1 + u1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    3. metadata-eval98.3%

      \[\leadsto \sqrt{\frac{u1}{\color{blue}{1} - u1 \cdot u1} \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. pow298.3%

      \[\leadsto \sqrt{\frac{u1}{1 - \color{blue}{{u1}^{2}}} \cdot \left(1 + u1\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    5. +-commutative98.3%

      \[\leadsto \sqrt{\frac{u1}{1 - {u1}^{2}} \cdot \color{blue}{\left(u1 + 1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  3. Applied egg-rr98.3%

    \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - {u1}^{2}} \cdot \left(u1 + 1\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  4. Final simplification98.3%

    \[\leadsto \sqrt{\frac{u1}{1 - {u1}^{2}} \cdot \left(u1 + 1\right)} \cdot \sin \left(u2 \cdot 6.28318530718\right) \]

Alternative 3: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sin \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sin (* u2 6.28318530718)) (pow (+ (/ 1.0 u1) -1.0) -0.5)))
float code(float cosTheta_i, float u1, float u2) {
	return sinf((u2 * 6.28318530718f)) * powf(((1.0f / u1) + -1.0f), -0.5f);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sin((u2 * 6.28318530718e0)) * (((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sin(Float32(u2 * Float32(6.28318530718))) * (Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sin((u2 * single(6.28318530718))) * (((single(1.0) / u1) + single(-1.0)) ^ single(-0.5));
end
\begin{array}{l}

\\
\sin \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-udef41.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  3. Applied egg-rr41.8%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  4. Step-by-step derivation
    1. expm1-def97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-log1p-u98.2%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
    3. clear-num98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. inv-pow98.3%

      \[\leadsto \sqrt{\color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{-1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    5. sqrt-pow198.3%

      \[\leadsto \color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{\left(\frac{-1}{2}\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    6. div-sub98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} - \frac{u1}{u1}\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    7. *-inverses98.3%

      \[\leadsto {\left(\frac{1}{u1} - \color{blue}{1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    8. sub-neg98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} + \left(-1\right)\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    9. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + \color{blue}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    10. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + -1\right)}^{\color{blue}{-0.5}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Applied egg-rr98.3%

    \[\leadsto \color{blue}{{\left(\frac{1}{u1} + -1\right)}^{-0.5} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
  6. Final simplification98.3%

    \[\leadsto \sin \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5} \]

Alternative 4: 90.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.017999999225139618:\\ \;\;\;\;\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (if (<= (* u2 6.28318530718) 0.017999999225139618)
   (* (* u2 6.28318530718) (sqrt (/ 1.0 (/ (- 1.0 u1) u1))))
   (* (sin (* u2 6.28318530718)) (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
	float tmp;
	if ((u2 * 6.28318530718f) <= 0.017999999225139618f) {
		tmp = (u2 * 6.28318530718f) * sqrtf((1.0f / ((1.0f - u1) / u1)));
	} else {
		tmp = sinf((u2 * 6.28318530718f)) * sqrtf(u1);
	}
	return tmp;
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    real(4) :: tmp
    if ((u2 * 6.28318530718e0) <= 0.017999999225139618e0) then
        tmp = (u2 * 6.28318530718e0) * sqrt((1.0e0 / ((1.0e0 - u1) / u1)))
    else
        tmp = sin((u2 * 6.28318530718e0)) * sqrt(u1)
    end if
    code = tmp
end function
function code(cosTheta_i, u1, u2)
	tmp = Float32(0.0)
	if (Float32(u2 * Float32(6.28318530718)) <= Float32(0.017999999225139618))
		tmp = Float32(Float32(u2 * Float32(6.28318530718)) * sqrt(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) - u1) / u1))));
	else
		tmp = Float32(sin(Float32(u2 * Float32(6.28318530718))) * sqrt(u1));
	end
	return tmp
end
function tmp_2 = code(cosTheta_i, u1, u2)
	tmp = single(0.0);
	if ((u2 * single(6.28318530718)) <= single(0.017999999225139618))
		tmp = (u2 * single(6.28318530718)) * sqrt((single(1.0) / ((single(1.0) - u1) / u1)));
	else
		tmp = sin((u2 * single(6.28318530718))) * sqrt(u1);
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.017999999225139618:\\
\;\;\;\;\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}}\\

\mathbf{else}:\\
\;\;\;\;\sin \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f32 314159265359/50000000000 u2) < 0.0179999992

    1. Initial program 98.7%

      \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. Step-by-step derivation
      1. expm1-log1p-u98.7%

        \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    3. Applied egg-rr98.7%

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. Step-by-step derivation
      1. expm1-log1p-u98.7%

        \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
      2. clear-num98.7%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    5. Applied egg-rr98.7%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    6. Taylor expanded in u2 around 0 95.1%

      \[\leadsto \sqrt{\frac{1}{\frac{1 - u1}{u1}}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]

    if 0.0179999992 < (*.f32 314159265359/50000000000 u2)

    1. Initial program 97.1%

      \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. Taylor expanded in u1 around 0 73.3%

      \[\leadsto \sqrt{\color{blue}{u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification88.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;u2 \cdot 6.28318530718 \leq 0.017999999225139618:\\ \;\;\;\;\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}}\\ \mathbf{else}:\\ \;\;\;\;\sin \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{u1}\\ \end{array} \]

Alternative 5: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (sin (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * sinf((u2 * 6.28318530718f));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * sin((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * sin(Float32(u2 * Float32(6.28318530718))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * sin((u2 * single(6.28318530718)));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(u2 \cdot 6.28318530718\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Final simplification98.2%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(u2 \cdot 6.28318530718\right) \]

Alternative 6: 98.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1}{u1} + -1}} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (/ (sin (* u2 6.28318530718)) (sqrt (+ (/ 1.0 u1) -1.0))))
float code(float cosTheta_i, float u1, float u2) {
	return sinf((u2 * 6.28318530718f)) / sqrtf(((1.0f / u1) + -1.0f));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sin((u2 * 6.28318530718e0)) / sqrt(((1.0e0 / u1) + (-1.0e0)))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sin(Float32(u2 * Float32(6.28318530718))) / sqrt(Float32(Float32(Float32(1.0) / u1) + Float32(-1.0))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sin((u2 * single(6.28318530718))) / sqrt(((single(1.0) / u1) + single(-1.0)));
end
\begin{array}{l}

\\
\frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1}{u1} + -1}}
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u98.2%

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  3. Applied egg-rr98.2%

    \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  4. Step-by-step derivation
    1. expm1-log1p-u98.2%

      \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. clear-num98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Applied egg-rr98.3%

    \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  6. Step-by-step derivation
    1. *-commutative98.3%

      \[\leadsto \color{blue}{\sin \left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}}} \]
    2. sqrt-div98.1%

      \[\leadsto \sin \left(6.28318530718 \cdot u2\right) \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\frac{1 - u1}{u1}}}} \]
    3. metadata-eval98.1%

      \[\leadsto \sin \left(6.28318530718 \cdot u2\right) \cdot \frac{\color{blue}{1}}{\sqrt{\frac{1 - u1}{u1}}} \]
    4. un-div-inv98.3%

      \[\leadsto \color{blue}{\frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\frac{1 - u1}{u1}}}} \]
    5. div-sub98.2%

      \[\leadsto \frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\color{blue}{\frac{1}{u1} - \frac{u1}{u1}}}} \]
    6. *-inverses98.2%

      \[\leadsto \frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\frac{1}{u1} - \color{blue}{1}}} \]
    7. sub-neg98.2%

      \[\leadsto \frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\color{blue}{\frac{1}{u1} + \left(-1\right)}}} \]
    8. metadata-eval98.2%

      \[\leadsto \frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\frac{1}{u1} + \color{blue}{-1}}} \]
  7. Applied egg-rr98.2%

    \[\leadsto \color{blue}{\frac{\sin \left(6.28318530718 \cdot u2\right)}{\sqrt{\frac{1}{u1} + -1}}} \]
  8. Final simplification98.2%

    \[\leadsto \frac{\sin \left(u2 \cdot 6.28318530718\right)}{\sqrt{\frac{1}{u1} + -1}} \]

Alternative 7: 81.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\frac{1}{u1} + -1}}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* u2 (* 6.28318530718 (sqrt (/ 1.0 (+ (/ 1.0 u1) -1.0))))))
float code(float cosTheta_i, float u1, float u2) {
	return u2 * (6.28318530718f * sqrtf((1.0f / ((1.0f / u1) + -1.0f))));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = u2 * (6.28318530718e0 * sqrt((1.0e0 / ((1.0e0 / u1) + (-1.0e0)))))
end function
function code(cosTheta_i, u1, u2)
	return Float32(u2 * Float32(Float32(6.28318530718) * sqrt(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) / u1) + Float32(-1.0))))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = u2 * (single(6.28318530718) * sqrt((single(1.0) / ((single(1.0) / u1) + single(-1.0)))));
end
\begin{array}{l}

\\
u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\frac{1}{u1} + -1}}\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-udef41.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  3. Applied egg-rr41.8%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  4. Step-by-step derivation
    1. expm1-def97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-log1p-u98.2%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
    3. clear-num98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. inv-pow98.3%

      \[\leadsto \sqrt{\color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{-1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    5. sqrt-pow198.3%

      \[\leadsto \color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{\left(\frac{-1}{2}\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    6. div-sub98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} - \frac{u1}{u1}\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    7. *-inverses98.3%

      \[\leadsto {\left(\frac{1}{u1} - \color{blue}{1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    8. sub-neg98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} + \left(-1\right)\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    9. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + \color{blue}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    10. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + -1\right)}^{\color{blue}{-0.5}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Applied egg-rr98.3%

    \[\leadsto \color{blue}{{\left(\frac{1}{u1} + -1\right)}^{-0.5} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
  6. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(u2 \cdot \sqrt{\frac{1}{\frac{1}{u1} - 1}}\right)} \]
  7. Step-by-step derivation
    1. associate-*r*80.0%

      \[\leadsto \color{blue}{\left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{1}{\frac{1}{u1} - 1}}} \]
    2. *-commutative80.0%

      \[\leadsto \color{blue}{\left(u2 \cdot 6.28318530718\right)} \cdot \sqrt{\frac{1}{\frac{1}{u1} - 1}} \]
    3. associate-*l*80.0%

      \[\leadsto \color{blue}{u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\frac{1}{u1} - 1}}\right)} \]
    4. sub-neg80.0%

      \[\leadsto u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\color{blue}{\frac{1}{u1} + \left(-1\right)}}}\right) \]
    5. metadata-eval80.0%

      \[\leadsto u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\frac{1}{u1} + \color{blue}{-1}}}\right) \]
    6. +-commutative80.0%

      \[\leadsto u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\color{blue}{-1 + \frac{1}{u1}}}}\right) \]
  8. Simplified80.0%

    \[\leadsto \color{blue}{u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{-1 + \frac{1}{u1}}}\right)} \]
  9. Final simplification80.0%

    \[\leadsto u2 \cdot \left(6.28318530718 \cdot \sqrt{\frac{1}{\frac{1}{u1} + -1}}\right) \]

Alternative 8: 81.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (* u2 6.28318530718) (sqrt (/ 1.0 (/ (- 1.0 u1) u1)))))
float code(float cosTheta_i, float u1, float u2) {
	return (u2 * 6.28318530718f) * sqrtf((1.0f / ((1.0f - u1) / u1)));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = (u2 * 6.28318530718e0) * sqrt((1.0e0 / ((1.0e0 - u1) / u1)))
end function
function code(cosTheta_i, u1, u2)
	return Float32(Float32(u2 * Float32(6.28318530718)) * sqrt(Float32(Float32(1.0) / Float32(Float32(Float32(1.0) - u1) / u1))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = (u2 * single(6.28318530718)) * sqrt((single(1.0) / ((single(1.0) - u1) / u1)));
end
\begin{array}{l}

\\
\left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}}
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u98.2%

      \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  3. Applied egg-rr98.2%

    \[\leadsto \sqrt{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{u1}{1 - u1}\right)\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  4. Step-by-step derivation
    1. expm1-log1p-u98.2%

      \[\leadsto \sqrt{\color{blue}{\frac{u1}{1 - u1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    2. clear-num98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Applied egg-rr98.3%

    \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  6. Taylor expanded in u2 around 0 80.1%

    \[\leadsto \sqrt{\frac{1}{\frac{1 - u1}{u1}}} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
  7. Final simplification80.1%

    \[\leadsto \left(u2 \cdot 6.28318530718\right) \cdot \sqrt{\frac{1}{\frac{1 - u1}{u1}}} \]

Alternative 9: 81.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (* u2 6.28318530718) (pow (+ (/ 1.0 u1) -1.0) -0.5)))
float code(float cosTheta_i, float u1, float u2) {
	return (u2 * 6.28318530718f) * powf(((1.0f / u1) + -1.0f), -0.5f);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = (u2 * 6.28318530718e0) * (((1.0e0 / u1) + (-1.0e0)) ** (-0.5e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(Float32(u2 * Float32(6.28318530718)) * (Float32(Float32(Float32(1.0) / u1) + Float32(-1.0)) ^ Float32(-0.5)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = (u2 * single(6.28318530718)) * (((single(1.0) / u1) + single(-1.0)) ^ single(-0.5));
end
\begin{array}{l}

\\
\left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5}
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. expm1-log1p-u97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-udef41.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  3. Applied egg-rr41.8%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)} - 1} \]
  4. Step-by-step derivation
    1. expm1-def97.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)\right)\right)} \]
    2. expm1-log1p-u98.2%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
    3. clear-num98.3%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    4. inv-pow98.3%

      \[\leadsto \sqrt{\color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{-1}}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    5. sqrt-pow198.3%

      \[\leadsto \color{blue}{{\left(\frac{1 - u1}{u1}\right)}^{\left(\frac{-1}{2}\right)}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    6. div-sub98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} - \frac{u1}{u1}\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    7. *-inverses98.3%

      \[\leadsto {\left(\frac{1}{u1} - \color{blue}{1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    8. sub-neg98.3%

      \[\leadsto {\color{blue}{\left(\frac{1}{u1} + \left(-1\right)\right)}}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    9. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + \color{blue}{-1}\right)}^{\left(\frac{-1}{2}\right)} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
    10. metadata-eval98.3%

      \[\leadsto {\left(\frac{1}{u1} + -1\right)}^{\color{blue}{-0.5}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  5. Applied egg-rr98.3%

    \[\leadsto \color{blue}{{\left(\frac{1}{u1} + -1\right)}^{-0.5} \cdot \sin \left(6.28318530718 \cdot u2\right)} \]
  6. Taylor expanded in u2 around 0 80.0%

    \[\leadsto {\left(\frac{1}{u1} + -1\right)}^{-0.5} \cdot \color{blue}{\left(6.28318530718 \cdot u2\right)} \]
  7. Final simplification80.0%

    \[\leadsto \left(u2 \cdot 6.28318530718\right) \cdot {\left(\frac{1}{u1} + -1\right)}^{-0.5} \]

Alternative 10: 81.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ 6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* 6.28318530718 (* (sqrt (/ u1 (- 1.0 u1))) u2)))
float code(float cosTheta_i, float u1, float u2) {
	return 6.28318530718f * (sqrtf((u1 / (1.0f - u1))) * u2);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = 6.28318530718e0 * (sqrt((u1 / (1.0e0 - u1))) * u2)
end function
function code(cosTheta_i, u1, u2)
	return Float32(Float32(6.28318530718) * Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * u2))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = single(6.28318530718) * (sqrt((u1 / (single(1.0) - u1))) * u2);
end
\begin{array}{l}

\\
6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
  3. Final simplification80.0%

    \[\leadsto 6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \]

Alternative 11: 81.5% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (* u2 6.28318530718)))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * (u2 * 6.28318530718f);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = sqrt((u1 / (1.0e0 - u1))) * (u2 * 6.28318530718e0)
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(u2 * Float32(6.28318530718)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * (u2 * single(6.28318530718));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot 6.28318530718\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
  3. Step-by-step derivation
    1. *-commutative80.0%

      \[\leadsto 6.28318530718 \cdot \color{blue}{\left(u2 \cdot \sqrt{\frac{u1}{1 - u1}}\right)} \]
    2. associate-*r*80.0%

      \[\leadsto \color{blue}{\left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
  4. Simplified80.0%

    \[\leadsto \color{blue}{\left(6.28318530718 \cdot u2\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
  5. Final simplification80.0%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot 6.28318530718\right) \]

Alternative 12: 64.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* 6.28318530718 (* u2 (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
	return 6.28318530718f * (u2 * sqrtf(u1));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = 6.28318530718e0 * (u2 * sqrt(u1))
end function
function code(cosTheta_i, u1, u2)
	return Float32(Float32(6.28318530718) * Float32(u2 * sqrt(u1)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = single(6.28318530718) * (u2 * sqrt(u1));
end
\begin{array}{l}

\\
6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
  3. Taylor expanded in u1 around 0 63.8%

    \[\leadsto 6.28318530718 \cdot \left(\sqrt{\color{blue}{u1}} \cdot u2\right) \]
  4. Final simplification63.8%

    \[\leadsto 6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right) \]

Alternative 13: 64.6% accurate, 2.0× speedup?

\[\begin{array}{l} \\ u2 \cdot \left(6.28318530718 \cdot \sqrt{u1}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* u2 (* 6.28318530718 (sqrt u1))))
float code(float cosTheta_i, float u1, float u2) {
	return u2 * (6.28318530718f * sqrtf(u1));
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = u2 * (6.28318530718e0 * sqrt(u1))
end function
function code(cosTheta_i, u1, u2)
	return Float32(u2 * Float32(Float32(6.28318530718) * sqrt(u1)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = u2 * (single(6.28318530718) * sqrt(u1));
end
\begin{array}{l}

\\
u2 \cdot \left(6.28318530718 \cdot \sqrt{u1}\right)
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
  3. Taylor expanded in u1 around 0 63.8%

    \[\leadsto 6.28318530718 \cdot \left(\sqrt{\color{blue}{u1}} \cdot u2\right) \]
  4. Step-by-step derivation
    1. expm1-log1p-u63.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(6.28318530718 \cdot \left(\sqrt{u1} \cdot u2\right)\right)\right)} \]
    2. expm1-udef29.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(6.28318530718 \cdot \left(\sqrt{u1} \cdot u2\right)\right)} - 1} \]
    3. *-commutative29.3%

      \[\leadsto e^{\mathsf{log1p}\left(6.28318530718 \cdot \color{blue}{\left(u2 \cdot \sqrt{u1}\right)}\right)} - 1 \]
  5. Applied egg-rr29.3%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)\right)} - 1} \]
  6. Step-by-step derivation
    1. expm1-def63.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)\right)\right)} \]
    2. expm1-log1p63.8%

      \[\leadsto \color{blue}{6.28318530718 \cdot \left(u2 \cdot \sqrt{u1}\right)} \]
    3. associate-*r*63.8%

      \[\leadsto \color{blue}{\left(6.28318530718 \cdot u2\right) \cdot \sqrt{u1}} \]
    4. *-commutative63.8%

      \[\leadsto \color{blue}{\left(u2 \cdot 6.28318530718\right)} \cdot \sqrt{u1} \]
    5. associate-*l*63.8%

      \[\leadsto \color{blue}{u2 \cdot \left(6.28318530718 \cdot \sqrt{u1}\right)} \]
  7. Simplified63.8%

    \[\leadsto \color{blue}{u2 \cdot \left(6.28318530718 \cdot \sqrt{u1}\right)} \]
  8. Final simplification63.8%

    \[\leadsto u2 \cdot \left(6.28318530718 \cdot \sqrt{u1}\right) \]

Alternative 14: -0.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ u2 \cdot \sqrt{-39.47841760436263} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* u2 (sqrt -39.47841760436263)))
float code(float cosTheta_i, float u1, float u2) {
	return u2 * sqrtf(-39.47841760436263f);
}
real(4) function code(costheta_i, u1, u2)
    real(4), intent (in) :: costheta_i
    real(4), intent (in) :: u1
    real(4), intent (in) :: u2
    code = u2 * sqrt((-39.47841760436263e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(u2 * sqrt(Float32(-39.47841760436263)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = u2 * sqrt(single(-39.47841760436263));
end
\begin{array}{l}

\\
u2 \cdot \sqrt{-39.47841760436263}
\end{array}
Derivation
  1. Initial program 98.2%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \sin \left(6.28318530718 \cdot u2\right) \]
  2. Taylor expanded in u2 around 0 80.0%

    \[\leadsto \color{blue}{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \]
  3. Step-by-step derivation
    1. add-sqr-sqrt79.7%

      \[\leadsto \color{blue}{\sqrt{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)} \cdot \sqrt{6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)}} \]
    2. sqrt-unprod80.0%

      \[\leadsto \color{blue}{\sqrt{\left(6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)\right) \cdot \left(6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)\right)}} \]
    3. *-commutative80.0%

      \[\leadsto \sqrt{\color{blue}{\left(\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot 6.28318530718\right)} \cdot \left(6.28318530718 \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)\right)} \]
    4. *-commutative80.0%

      \[\leadsto \sqrt{\left(\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot 6.28318530718\right) \cdot \color{blue}{\left(\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot 6.28318530718\right)}} \]
    5. swap-sqr79.9%

      \[\leadsto \sqrt{\color{blue}{\left(\left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right) \cdot \left(\sqrt{\frac{u1}{1 - u1}} \cdot u2\right)\right) \cdot \left(6.28318530718 \cdot 6.28318530718\right)}} \]
    6. swap-sqr79.9%

      \[\leadsto \sqrt{\color{blue}{\left(\left(\sqrt{\frac{u1}{1 - u1}} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \cdot \left(u2 \cdot u2\right)\right)} \cdot \left(6.28318530718 \cdot 6.28318530718\right)} \]
    7. add-sqr-sqrt79.9%

      \[\leadsto \sqrt{\left(\color{blue}{\frac{u1}{1 - u1}} \cdot \left(u2 \cdot u2\right)\right) \cdot \left(6.28318530718 \cdot 6.28318530718\right)} \]
    8. pow279.9%

      \[\leadsto \sqrt{\left(\frac{u1}{1 - u1} \cdot \color{blue}{{u2}^{2}}\right) \cdot \left(6.28318530718 \cdot 6.28318530718\right)} \]
    9. metadata-eval80.3%

      \[\leadsto \sqrt{\left(\frac{u1}{1 - u1} \cdot {u2}^{2}\right) \cdot \color{blue}{39.47841760436263}} \]
  4. Applied egg-rr80.3%

    \[\leadsto \color{blue}{\sqrt{\left(\frac{u1}{1 - u1} \cdot {u2}^{2}\right) \cdot 39.47841760436263}} \]
  5. Step-by-step derivation
    1. *-commutative80.3%

      \[\leadsto \sqrt{\color{blue}{39.47841760436263 \cdot \left(\frac{u1}{1 - u1} \cdot {u2}^{2}\right)}} \]
    2. associate-*l/80.2%

      \[\leadsto \sqrt{39.47841760436263 \cdot \color{blue}{\frac{u1 \cdot {u2}^{2}}{1 - u1}}} \]
  6. Simplified80.2%

    \[\leadsto \color{blue}{\sqrt{39.47841760436263 \cdot \frac{u1 \cdot {u2}^{2}}{1 - u1}}} \]
  7. Taylor expanded in u1 around -inf -0.0%

    \[\leadsto \color{blue}{u2 \cdot \sqrt{-39.47841760436263}} \]
  8. Final simplification-0.0%

    \[\leadsto u2 \cdot \sqrt{-39.47841760436263} \]

Reproduce

?
herbie shell --seed 2023326 
(FPCore (cosTheta_i u1 u2)
  :name "Trowbridge-Reitz Sample, near normal, slope_y"
  :precision binary32
  :pre (and (and (and (> cosTheta_i 0.9999) (<= cosTheta_i 1.0)) (and (<= 2.328306437e-10 u1) (<= u1 1.0))) (and (<= 2.328306437e-10 u2) (<= u2 1.0)))
  (* (sqrt (/ u1 (- 1.0 u1))) (sin (* 6.28318530718 u2))))