Trowbridge-Reitz Sample, near normal, slope_x

Percentage Accurate: 99.0% → 99.0%
Time: 11.2s
Alternatives: 11
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 \cos \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \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 11 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: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* 6.28318530718 u2))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((6.28318530718e0 * u2))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(Float32(6.28318530718) * u2)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((single(6.28318530718) * u2));
end
\begin{array}{l}

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

Alternative 1: 99.0% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (sqrt (* (* u2 u2) 39.47841760436263)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf(sqrtf(((u2 * u2) * 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 = sqrt((u1 / (1.0e0 - u1))) * cos(sqrt(((u2 * u2) * 39.47841760436263e0)))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(sqrt(Float32(Float32(u2 * u2) * Float32(39.47841760436263)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos(sqrt(((u2 * u2) * single(39.47841760436263))));
end
\begin{array}{l}

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

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. add-sqr-sqrt98.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
    2. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
    3. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
    4. pow-prod-down98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)\right)}^{0.5}\right)} \]
    5. swap-sqr98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
    6. metadata-eval98.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]
  3. Applied egg-rr98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
  4. Step-by-step derivation
    1. unpow1/298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
    2. unpow298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
    3. *-commutative98.8%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
  5. Simplified98.8%

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

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

Alternative 2: 96.3% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\ \mathbf{if}\;t_0 \leq 0.9984999895095825:\\ \;\;\;\;t_0 \cdot \sqrt{u1 + u1 \cdot u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* u2 6.28318530718))))
   (if (<= t_0 0.9984999895095825)
     (* t_0 (sqrt (+ u1 (* u1 u1))))
     (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* u2 (* u2 -19.739208802181317)))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf((u2 * 6.28318530718f));
	float tmp;
	if (t_0 <= 0.9984999895095825f) {
		tmp = t_0 * sqrtf((u1 + (u1 * u1)));
	} else {
		tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (u2 * (u2 * -19.739208802181317f)));
	}
	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) :: t_0
    real(4) :: tmp
    t_0 = cos((u2 * 6.28318530718e0))
    if (t_0 <= 0.9984999895095825e0) then
        tmp = t_0 * sqrt((u1 + (u1 * u1)))
    else
        tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + (u2 * (u2 * (-19.739208802181317e0))))
    end if
    code = tmp
end function
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(u2 * Float32(6.28318530718)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9984999895095825))
		tmp = Float32(t_0 * sqrt(Float32(u1 + Float32(u1 * u1))));
	else
		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))));
	end
	return tmp
end
function tmp_2 = code(cosTheta_i, u1, u2)
	t_0 = cos((u2 * single(6.28318530718)));
	tmp = single(0.0);
	if (t_0 <= single(0.9984999895095825))
		tmp = t_0 * sqrt((u1 + (u1 * u1)));
	else
		tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (u2 * (u2 * single(-19.739208802181317))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t_0 \leq 0.9984999895095825:\\
\;\;\;\;t_0 \cdot \sqrt{u1 + u1 \cdot u1}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)\\


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

    1. Initial program 97.2%

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

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

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{1}{u1} - \frac{u1}{u1}\right)}}^{-1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
      4. pow196.9%

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

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

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

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

        \[\leadsto \sqrt{{\left(\frac{1}{u1} - \color{blue}{1}\right)}^{-1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    3. Applied egg-rr96.9%

      \[\leadsto \sqrt{\color{blue}{{\left(\frac{1}{u1} - 1\right)}^{-1}}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    4. Step-by-step derivation
      1. unpow-196.9%

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

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

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

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

      \[\leadsto \sqrt{\color{blue}{{u1}^{2} + u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    7. Step-by-step derivation
      1. +-commutative88.5%

        \[\leadsto \sqrt{\color{blue}{u1 + {u1}^{2}}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
      2. unpow288.5%

        \[\leadsto \sqrt{u1 + \color{blue}{u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    8. Simplified88.5%

      \[\leadsto \sqrt{\color{blue}{u1 + u1 \cdot u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]

    if 0.99849999 < (cos.f32 (*.f32 314159265359/50000000000 u2))

    1. Initial program 99.3%

      \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    2. Step-by-step derivation
      1. add-sqr-sqrt99.3%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
      2. pow1/299.3%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
      3. pow1/299.3%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
      4. pow-prod-down99.3%

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

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
      6. metadata-eval99.3%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
    4. Step-by-step derivation
      1. unpow1/299.3%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
      2. unpow299.3%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
      3. *-commutative99.3%

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

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
    5. Simplified99.3%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)} \]
    6. Step-by-step derivation
      1. clear-num93.0%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \]
      2. associate-/r/93.0%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
    7. Applied egg-rr99.1%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right) \]
    8. Taylor expanded in u2 around 0 99.2%

      \[\leadsto \color{blue}{-19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) + \sqrt{\frac{u1}{1 - u1}}} \]
    9. Step-by-step derivation
      1. +-commutative99.2%

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right)} \]
      2. *-lft-identity99.2%

        \[\leadsto \color{blue}{1 \cdot \sqrt{\frac{u1}{1 - u1}}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
      3. associate-*r*99.2%

        \[\leadsto 1 \cdot \sqrt{\frac{u1}{1 - u1}} + \color{blue}{\left(-19.739208802181317 \cdot {u2}^{2}\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
      4. distribute-rgt-out99.1%

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

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \color{blue}{\left(u2 \cdot u2\right)}\right) \]
      6. associate-*r*99.1%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{\left(-19.739208802181317 \cdot u2\right) \cdot u2}\right) \]
      7. *-commutative99.1%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{u2 \cdot \left(-19.739208802181317 \cdot u2\right)}\right) \]
      8. *-commutative99.1%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \color{blue}{\left(u2 \cdot -19.739208802181317\right)}\right) \]
    10. Simplified99.1%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification96.4%

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

Alternative 3: 98.9% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot {39.47841760436263}^{0.5}\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 (pow 39.47841760436263 0.5)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((u2 * powf(39.47841760436263f, 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 = sqrt((u1 / (1.0e0 - u1))) * cos((u2 * (39.47841760436263e0 ** 0.5e0)))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * (Float32(39.47841760436263) ^ Float32(0.5)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * (single(39.47841760436263) ^ single(0.5))));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot {39.47841760436263}^{0.5}\right)
\end{array}
Derivation
  1. Initial program 98.7%

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. add-sqr-sqrt98.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
    2. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
    3. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
    4. pow-prod-down98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)\right)}^{0.5}\right)} \]
    5. swap-sqr98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
    6. metadata-eval98.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]
  3. Applied egg-rr98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
  4. Step-by-step derivation
    1. unpow1/298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
    2. unpow298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
    3. *-commutative98.8%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
  5. Simplified98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)} \]
  6. Step-by-step derivation
    1. pow1/298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(u2 \cdot u2\right) \cdot 39.47841760436263\right)}^{0.5}\right)} \]
    2. *-commutative98.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
    3. unpow-prod-down98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({39.47841760436263}^{0.5} \cdot {\left(u2 \cdot u2\right)}^{0.5}\right)} \]
    4. pow1/298.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({39.47841760436263}^{0.5} \cdot \color{blue}{\sqrt{u2 \cdot u2}}\right) \]
    5. sqrt-prod98.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({39.47841760436263}^{0.5} \cdot \color{blue}{\left(\sqrt{u2} \cdot \sqrt{u2}\right)}\right) \]
    6. add-sqr-sqrt98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({39.47841760436263}^{0.5} \cdot \color{blue}{u2}\right) \]
  7. Applied egg-rr98.7%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({39.47841760436263}^{0.5} \cdot u2\right)} \]
  8. Final simplification98.7%

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

Alternative 4: 94.1% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\ \mathbf{if}\;t_0 \leq 0.9955000281333923:\\ \;\;\;\;t_0 \cdot \sqrt{u1}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)\\ \end{array} \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (let* ((t_0 (cos (* u2 6.28318530718))))
   (if (<= t_0 0.9955000281333923)
     (* t_0 (sqrt u1))
     (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* u2 (* u2 -19.739208802181317)))))))
float code(float cosTheta_i, float u1, float u2) {
	float t_0 = cosf((u2 * 6.28318530718f));
	float tmp;
	if (t_0 <= 0.9955000281333923f) {
		tmp = t_0 * sqrtf(u1);
	} else {
		tmp = sqrtf((u1 / (1.0f - u1))) * (1.0f + (u2 * (u2 * -19.739208802181317f)));
	}
	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) :: t_0
    real(4) :: tmp
    t_0 = cos((u2 * 6.28318530718e0))
    if (t_0 <= 0.9955000281333923e0) then
        tmp = t_0 * sqrt(u1)
    else
        tmp = sqrt((u1 / (1.0e0 - u1))) * (1.0e0 + (u2 * (u2 * (-19.739208802181317e0))))
    end if
    code = tmp
end function
function code(cosTheta_i, u1, u2)
	t_0 = cos(Float32(u2 * Float32(6.28318530718)))
	tmp = Float32(0.0)
	if (t_0 <= Float32(0.9955000281333923))
		tmp = Float32(t_0 * sqrt(u1));
	else
		tmp = Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))));
	end
	return tmp
end
function tmp_2 = code(cosTheta_i, u1, u2)
	t_0 = cos((u2 * single(6.28318530718)));
	tmp = single(0.0);
	if (t_0 <= single(0.9955000281333923))
		tmp = t_0 * sqrt(u1);
	else
		tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (u2 * (u2 * single(-19.739208802181317))));
	end
	tmp_2 = tmp;
end
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \cos \left(u2 \cdot 6.28318530718\right)\\
\mathbf{if}\;t_0 \leq 0.9955000281333923:\\
\;\;\;\;t_0 \cdot \sqrt{u1}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)\\


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

    1. Initial program 96.9%

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

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

    if 0.995500028 < (cos.f32 (*.f32 314159265359/50000000000 u2))

    1. Initial program 99.2%

      \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
    2. Step-by-step derivation
      1. add-sqr-sqrt99.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
      2. pow1/299.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
      3. pow1/299.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
      4. pow-prod-down99.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)\right)}^{0.5}\right)} \]
      5. swap-sqr99.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
      6. metadata-eval99.2%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
    4. Step-by-step derivation
      1. unpow1/299.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
      2. unpow299.2%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
      3. *-commutative99.2%

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

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
    5. Simplified99.2%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)} \]
    6. Step-by-step derivation
      1. clear-num90.8%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \]
      2. associate-/r/90.8%

        \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
    7. Applied egg-rr99.1%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right) \]
    8. Taylor expanded in u2 around 0 98.5%

      \[\leadsto \color{blue}{-19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) + \sqrt{\frac{u1}{1 - u1}}} \]
    9. Step-by-step derivation
      1. +-commutative98.5%

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right)} \]
      2. *-lft-identity98.5%

        \[\leadsto \color{blue}{1 \cdot \sqrt{\frac{u1}{1 - u1}}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
      3. associate-*r*98.5%

        \[\leadsto 1 \cdot \sqrt{\frac{u1}{1 - u1}} + \color{blue}{\left(-19.739208802181317 \cdot {u2}^{2}\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
      4. distribute-rgt-out98.4%

        \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\right)} \]
      5. unpow298.4%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \color{blue}{\left(u2 \cdot u2\right)}\right) \]
      6. associate-*r*98.4%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{\left(-19.739208802181317 \cdot u2\right) \cdot u2}\right) \]
      7. *-commutative98.4%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{u2 \cdot \left(-19.739208802181317 \cdot u2\right)}\right) \]
      8. *-commutative98.4%

        \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \color{blue}{\left(u2 \cdot -19.739208802181317\right)}\right) \]
    10. Simplified98.4%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification93.9%

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

Alternative 5: 99.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(u2 \cdot 6.28318530718\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (cos (* u2 6.28318530718))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * cosf((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))) * cos((u2 * 6.28318530718e0))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * cos(Float32(u2 * Float32(6.28318530718))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * cos((u2 * single(6.28318530718)));
end
\begin{array}{l}

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

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

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

Alternative 6: 88.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* u2 (* u2 -19.739208802181317)))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * (1.0f + (u2 * (u2 * -19.739208802181317f)));
}
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))) * (1.0e0 + (u2 * (u2 * (-19.739208802181317e0))))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(u2 * Float32(u2 * Float32(-19.739208802181317)))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + (u2 * (u2 * single(-19.739208802181317))));
end
\begin{array}{l}

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

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. add-sqr-sqrt98.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
    2. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
    3. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
    4. pow-prod-down98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)\right)}^{0.5}\right)} \]
    5. swap-sqr98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
    6. metadata-eval98.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]
  3. Applied egg-rr98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
  4. Step-by-step derivation
    1. unpow1/298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
    2. unpow298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
    3. *-commutative98.8%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
  5. Simplified98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right)} \]
  6. Step-by-step derivation
    1. clear-num77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \]
    2. associate-/r/77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
  7. Applied egg-rr98.7%

    \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \cdot \cos \left(\sqrt{\left(u2 \cdot u2\right) \cdot 39.47841760436263}\right) \]
  8. Taylor expanded in u2 around 0 86.4%

    \[\leadsto \color{blue}{-19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) + \sqrt{\frac{u1}{1 - u1}}} \]
  9. Step-by-step derivation
    1. +-commutative86.4%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right)} \]
    2. *-lft-identity86.4%

      \[\leadsto \color{blue}{1 \cdot \sqrt{\frac{u1}{1 - u1}}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
    3. associate-*r*86.4%

      \[\leadsto 1 \cdot \sqrt{\frac{u1}{1 - u1}} + \color{blue}{\left(-19.739208802181317 \cdot {u2}^{2}\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
    4. distribute-rgt-out86.4%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\right)} \]
    5. unpow286.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot \color{blue}{\left(u2 \cdot u2\right)}\right) \]
    6. associate-*r*86.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{\left(-19.739208802181317 \cdot u2\right) \cdot u2}\right) \]
    7. *-commutative86.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{u2 \cdot \left(-19.739208802181317 \cdot u2\right)}\right) \]
    8. *-commutative86.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \color{blue}{\left(u2 \cdot -19.739208802181317\right)}\right) \]
  10. Simplified86.4%

    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + u2 \cdot \left(u2 \cdot -19.739208802181317\right)\right)} \]
  11. Final simplification86.4%

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

Alternative 7: 88.5% accurate, 1.8× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \left(u2 \cdot u2\right) \cdot -19.739208802181317\right) \end{array} \]
(FPCore (cosTheta_i u1 u2)
 :precision binary32
 (* (sqrt (/ u1 (- 1.0 u1))) (+ 1.0 (* (* u2 u2) -19.739208802181317))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - u1))) * (1.0f + ((u2 * u2) * -19.739208802181317f));
}
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))) * (1.0e0 + ((u2 * u2) * (-19.739208802181317e0)))
end function
function code(cosTheta_i, u1, u2)
	return Float32(sqrt(Float32(u1 / Float32(Float32(1.0) - u1))) * Float32(Float32(1.0) + Float32(Float32(u2 * u2) * Float32(-19.739208802181317))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1))) * (single(1.0) + ((u2 * u2) * single(-19.739208802181317)));
end
\begin{array}{l}

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

    \[\sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(6.28318530718 \cdot u2\right) \]
  2. Step-by-step derivation
    1. add-sqr-sqrt98.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{6.28318530718 \cdot u2} \cdot \sqrt{6.28318530718 \cdot u2}\right)} \]
    2. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}} \cdot \sqrt{6.28318530718 \cdot u2}\right) \]
    3. pow1/298.6%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(6.28318530718 \cdot u2\right)}^{0.5} \cdot \color{blue}{{\left(6.28318530718 \cdot u2\right)}^{0.5}}\right) \]
    4. pow-prod-down98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(\left(6.28318530718 \cdot u2\right) \cdot \left(6.28318530718 \cdot u2\right)\right)}^{0.5}\right)} \]
    5. swap-sqr98.7%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\color{blue}{\left(\left(6.28318530718 \cdot 6.28318530718\right) \cdot \left(u2 \cdot u2\right)\right)}}^{0.5}\right) \]
    6. metadata-eval98.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left({\left(\color{blue}{39.47841760436263} \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right) \]
  3. Applied egg-rr98.8%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left({\left(39.47841760436263 \cdot \left(u2 \cdot u2\right)\right)}^{0.5}\right)} \]
  4. Step-by-step derivation
    1. unpow1/298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \color{blue}{\left(\sqrt{39.47841760436263 \cdot \left(u2 \cdot u2\right)}\right)} \]
    2. unpow298.8%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{39.47841760436263 \cdot \color{blue}{{u2}^{2}}}\right) \]
    3. *-commutative98.8%

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

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \cos \left(\sqrt{\color{blue}{\left(u2 \cdot u2\right)} \cdot 39.47841760436263}\right) \]
  5. Simplified98.8%

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

    \[\leadsto \color{blue}{-19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) + \sqrt{\frac{u1}{1 - u1}}} \]
  7. Step-by-step derivation
    1. +-commutative86.4%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right)} \]
    2. *-lft-identity86.4%

      \[\leadsto \color{blue}{1 \cdot \sqrt{\frac{u1}{1 - u1}}} + -19.739208802181317 \cdot \left({u2}^{2} \cdot \sqrt{\frac{u1}{1 - u1}}\right) \]
    3. associate-*r*86.4%

      \[\leadsto 1 \cdot \sqrt{\frac{u1}{1 - u1}} + \color{blue}{\left(-19.739208802181317 \cdot {u2}^{2}\right) \cdot \sqrt{\frac{u1}{1 - u1}}} \]
    4. distribute-rgt-out86.4%

      \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + -19.739208802181317 \cdot {u2}^{2}\right)} \]
    5. *-commutative86.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{{u2}^{2} \cdot -19.739208802181317}\right) \]
    6. unpow286.4%

      \[\leadsto \sqrt{\frac{u1}{1 - u1}} \cdot \left(1 + \color{blue}{\left(u2 \cdot u2\right)} \cdot -19.739208802181317\right) \]
  8. Simplified86.4%

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

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

Alternative 8: 71.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \sqrt{u1 \cdot \left(u1 + 1\right)} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (* u1 (+ u1 1.0))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 * (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 = sqrt((u1 * (u1 + 1.0e0)))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 * Float32(u1 + Float32(1.0))))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 * (u1 + single(1.0))));
end
\begin{array}{l}

\\
\sqrt{u1 \cdot \left(u1 + 1\right)}
\end{array}
Derivation
  1. Initial program 98.7%

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

    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \]
  3. Step-by-step derivation
    1. clear-num77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \]
    2. associate-/r/77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
  4. Applied egg-rr77.4%

    \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
  5. Taylor expanded in u1 around 0 69.9%

    \[\leadsto \sqrt{\color{blue}{\left(1 + u1\right)} \cdot u1} \]
  6. Step-by-step derivation
    1. +-commutative69.9%

      \[\leadsto \sqrt{\color{blue}{\left(u1 + 1\right)} \cdot u1} \]
  7. Simplified69.9%

    \[\leadsto \sqrt{\color{blue}{\left(u1 + 1\right)} \cdot u1} \]
  8. Final simplification69.9%

    \[\leadsto \sqrt{u1 \cdot \left(u1 + 1\right)} \]

Alternative 9: 71.9% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \sqrt{u1 + u1 \cdot u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (+ u1 (* u1 u1))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 + (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 = sqrt((u1 + (u1 * u1)))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 + Float32(u1 * u1)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 + (u1 * u1)));
end
\begin{array}{l}

\\
\sqrt{u1 + u1 \cdot u1}
\end{array}
Derivation
  1. Initial program 98.7%

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

    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \]
  3. Step-by-step derivation
    1. clear-num77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{\frac{1 - u1}{u1}}}} \]
    2. associate-/r/77.4%

      \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
  4. Applied egg-rr77.4%

    \[\leadsto \sqrt{\color{blue}{\frac{1}{1 - u1} \cdot u1}} \]
  5. Taylor expanded in u1 around 0 69.9%

    \[\leadsto \sqrt{\color{blue}{{u1}^{2} + u1}} \]
  6. Step-by-step derivation
    1. +-commutative69.9%

      \[\leadsto \sqrt{\color{blue}{u1 + {u1}^{2}}} \]
    2. unpow269.9%

      \[\leadsto \sqrt{u1 + \color{blue}{u1 \cdot u1}} \]
  7. Simplified69.9%

    \[\leadsto \sqrt{\color{blue}{u1 + u1 \cdot u1}} \]
  8. Final simplification69.9%

    \[\leadsto \sqrt{u1 + u1 \cdot u1} \]

Alternative 10: 80.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \sqrt{\frac{u1}{1 - u1}} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt (/ u1 (- 1.0 u1))))
float code(float cosTheta_i, float u1, float u2) {
	return sqrtf((u1 / (1.0f - 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 = sqrt((u1 / (1.0e0 - u1)))
end function
function code(cosTheta_i, u1, u2)
	return sqrt(Float32(u1 / Float32(Float32(1.0) - u1)))
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt((u1 / (single(1.0) - u1)));
end
\begin{array}{l}

\\
\sqrt{\frac{u1}{1 - u1}}
\end{array}
Derivation
  1. Initial program 98.7%

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

    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \]
  3. Final simplification77.6%

    \[\leadsto \sqrt{\frac{u1}{1 - u1}} \]

Alternative 11: 63.4% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \sqrt{u1} \end{array} \]
(FPCore (cosTheta_i u1 u2) :precision binary32 (sqrt u1))
float code(float cosTheta_i, float u1, float u2) {
	return 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 = sqrt(u1)
end function
function code(cosTheta_i, u1, u2)
	return sqrt(u1)
end
function tmp = code(cosTheta_i, u1, u2)
	tmp = sqrt(u1);
end
\begin{array}{l}

\\
\sqrt{u1}
\end{array}
Derivation
  1. Initial program 98.7%

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

    \[\leadsto \color{blue}{\sqrt{\frac{u1}{1 - u1}}} \]
  3. Taylor expanded in u1 around 0 62.0%

    \[\leadsto \sqrt{\color{blue}{u1}} \]
  4. Final simplification62.0%

    \[\leadsto \sqrt{u1} \]

Reproduce

?
herbie shell --seed 2023188 
(FPCore (cosTheta_i u1 u2)
  :name "Trowbridge-Reitz Sample, near normal, slope_x"
  :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))) (cos (* 6.28318530718 u2))))