UniformSampleCone, x

Percentage Accurate: 57.2% → 99.1%
Time: 7.2s
Alternatives: 16
Speedup: 2.4×

Specification

?
\[\left(\left(\frac{2328306437}{10000000000000000000} \leq ux \land ux \leq 1\right) \land \left(\frac{2328306437}{10000000000000000000} \leq uy \land uy \leq 1\right)\right) \land \left(0 \leq maxCos \land maxCos \leq 1\right)\]
\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (+ (- 1 ux) (* ux maxCos))))
  (* (cos (* (* uy 2) PI)) (sqrt (- 1 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = (1.0f - ux) + (ux * maxCos);
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos))
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = (single(1.0) - ux) + (ux * maxCos);
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0)));
end
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}

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 16 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: 57.2% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \left(1 - ux\right) + ux \cdot maxCos\\ \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (+ (- 1 ux) (* ux maxCos))))
  (* (cos (* (* uy 2) PI)) (sqrt (- 1 (* t_0 t_0))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = (1.0f - ux) + (ux * maxCos);
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((1.0f - (t_0 * t_0)));
}
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos))
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(1.0) - Float32(t_0 * t_0))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = (single(1.0) - ux) + (ux * maxCos);
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((single(1.0) - (t_0 * t_0)));
end
\begin{array}{l}
t_0 := \left(1 - ux\right) + ux \cdot maxCos\\
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - t\_0 \cdot t\_0}
\end{array}

Alternative 1: 99.1% accurate, 0.5× speedup?

\[\begin{array}{l} t_0 := \frac{\pi}{uy} \cdot \frac{1}{2}\\ \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{t\_0}\right) \cdot t\_0\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (* (/ PI uy) 1/2)))
  (*
   (sin (* uy (* (+ 1 (/ (* PI -2) t_0)) t_0)))
   (sqrt
    (*
     ux
     (- (+ 2 (* -1 (* ux (pow (- maxCos 1) 2)))) (* 2 maxCos)))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = (((float) M_PI) / uy) * 0.5f;
	return sinf((uy * ((1.0f + ((((float) M_PI) * -2.0f) / t_0)) * t_0))) * sqrtf((ux * ((2.0f + (-1.0f * (ux * powf((maxCos - 1.0f), 2.0f)))) - (2.0f * maxCos))));
}
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(Float32(pi) / uy) * Float32(0.5))
	return Float32(sin(Float32(uy * Float32(Float32(Float32(1.0) + Float32(Float32(Float32(pi) * Float32(-2.0)) / t_0)) * t_0))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(Float32(-1.0) * Float32(ux * (Float32(maxCos - Float32(1.0)) ^ Float32(2.0))))) - Float32(Float32(2.0) * maxCos)))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = (single(pi) / uy) * single(0.5);
	tmp = sin((uy * ((single(1.0) + ((single(pi) * single(-2.0)) / t_0)) * t_0))) * sqrt((ux * ((single(2.0) + (single(-1.0) * (ux * ((maxCos - single(1.0)) ^ single(2.0))))) - (single(2.0) * maxCos))));
end
\begin{array}{l}
t_0 := \frac{\pi}{uy} \cdot \frac{1}{2}\\
\sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{t\_0}\right) \cdot t\_0\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}
\end{array}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift-cos.f32N/A

      \[\leadsto \color{blue}{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. cos-neg-revN/A

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(\left(uy \cdot 2\right) \cdot \pi\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(2 \cdot uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. count-2N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lift-+.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right) \cdot \pi}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    9. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    10. sin-+PI/2-revN/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    11. lower-sin.f32N/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    12. lift-PI.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\color{blue}{\pi}}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    13. mult-flip-revN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    14. metadata-evalN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    15. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    16. lower-+.f32N/A

      \[\leadsto \sin \color{blue}{\left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \frac{1}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    17. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    20. lower-neg.f3299.0%

      \[\leadsto \sin \left(\color{blue}{\left(-\pi\right)} \cdot \left(uy + uy\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    21. lift-*.f32N/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    22. *-commutativeN/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    23. lower-*.f3299.0%

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \color{blue}{\sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \frac{1}{2} \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  7. Taylor expanded in uy around inf

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \color{blue}{\left(-2 \cdot \mathsf{PI}\left(\right) + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. lower-+.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2}} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. lower-PI.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-PI.f3299.0%

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  9. Applied rewrites99.0%

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  10. Step-by-step derivation
    1. lift-+.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \color{blue}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. +-commutativeN/A

      \[\leadsto \sin \left(uy \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy} + \color{blue}{-2 \cdot \pi}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. sum-to-multN/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{-2 \cdot \pi}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. lower-unsound-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{-2 \cdot \pi}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-unsound-+.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{-2 \cdot \pi}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\color{blue}{\frac{1}{2}} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-unsound-/.f3299.1%

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{-2 \cdot \pi}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lift-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{-2 \cdot \pi}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. *-commutativeN/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    9. lower-*.f3299.1%

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    10. lift-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{1}{2} \cdot \frac{\pi}{uy}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    11. *-commutativeN/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    12. lower-*.f3299.1%

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \left(\frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \left(\frac{1}{2} \cdot \color{blue}{\frac{\pi}{uy}}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    14. *-commutativeN/A

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \left(\frac{\pi}{uy} \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    15. lower-*.f3299.1%

      \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \left(\frac{\pi}{uy} \cdot \color{blue}{\frac{1}{2}}\right)\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  11. Applied rewrites99.1%

    \[\leadsto \sin \left(uy \cdot \left(\left(1 + \frac{\pi \cdot -2}{\frac{\pi}{uy} \cdot \frac{1}{2}}\right) \cdot \color{blue}{\left(\frac{\pi}{uy} \cdot \frac{1}{2}\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  12. Add Preprocessing

Alternative 2: 99.0% accurate, 0.6× speedup?

\[\sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \frac{\frac{1}{2}}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (sin (* uy (+ (* -2 PI) (* PI (/ 1/2 uy)))))
 (sqrt
  (* ux (- (+ 2 (* -1 (* ux (pow (- maxCos 1) 2)))) (* 2 maxCos))))))
float code(float ux, float uy, float maxCos) {
	return sinf((uy * ((-2.0f * ((float) M_PI)) + (((float) M_PI) * (0.5f / uy))))) * sqrtf((ux * ((2.0f + (-1.0f * (ux * powf((maxCos - 1.0f), 2.0f)))) - (2.0f * maxCos))));
}
function code(ux, uy, maxCos)
	return Float32(sin(Float32(uy * Float32(Float32(Float32(-2.0) * Float32(pi)) + Float32(Float32(pi) * Float32(Float32(0.5) / uy))))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(Float32(-1.0) * Float32(ux * (Float32(maxCos - Float32(1.0)) ^ Float32(2.0))))) - Float32(Float32(2.0) * maxCos)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sin((uy * ((single(-2.0) * single(pi)) + (single(pi) * (single(0.5) / uy))))) * sqrt((ux * ((single(2.0) + (single(-1.0) * (ux * ((maxCos - single(1.0)) ^ single(2.0))))) - (single(2.0) * maxCos))));
end
\sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \frac{\frac{1}{2}}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift-cos.f32N/A

      \[\leadsto \color{blue}{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. cos-neg-revN/A

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(\left(uy \cdot 2\right) \cdot \pi\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(2 \cdot uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. count-2N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lift-+.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right) \cdot \pi}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    9. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    10. sin-+PI/2-revN/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    11. lower-sin.f32N/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    12. lift-PI.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\color{blue}{\pi}}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    13. mult-flip-revN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    14. metadata-evalN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    15. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    16. lower-+.f32N/A

      \[\leadsto \sin \color{blue}{\left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \frac{1}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    17. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    20. lower-neg.f3299.0%

      \[\leadsto \sin \left(\color{blue}{\left(-\pi\right)} \cdot \left(uy + uy\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    21. lift-*.f32N/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    22. *-commutativeN/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    23. lower-*.f3299.0%

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \color{blue}{\sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \frac{1}{2} \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  7. Taylor expanded in uy around inf

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \color{blue}{\left(-2 \cdot \mathsf{PI}\left(\right) + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. lower-+.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2}} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. lower-PI.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-PI.f3299.0%

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  9. Applied rewrites99.0%

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  10. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \color{blue}{\frac{\pi}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. lift-/.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. associate-*r/N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{\frac{1}{2} \cdot \pi}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. *-commutativeN/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{\pi \cdot \frac{1}{2}}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. associate-/l*N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \color{blue}{\frac{\frac{1}{2}}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \color{blue}{\frac{\frac{1}{2}}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-/.f3299.0%

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \frac{\frac{1}{2}}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  11. Applied rewrites99.0%

    \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \pi \cdot \color{blue}{\frac{\frac{1}{2}}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  12. Add Preprocessing

Alternative 3: 99.0% accurate, 0.6× speedup?

\[\sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (sin (* uy (+ (* -2 PI) (* 1/2 (/ PI uy)))))
 (sqrt
  (* ux (- (+ 2 (* -1 (* ux (pow (- maxCos 1) 2)))) (* 2 maxCos))))))
float code(float ux, float uy, float maxCos) {
	return sinf((uy * ((-2.0f * ((float) M_PI)) + (0.5f * (((float) M_PI) / uy))))) * sqrtf((ux * ((2.0f + (-1.0f * (ux * powf((maxCos - 1.0f), 2.0f)))) - (2.0f * maxCos))));
}
function code(ux, uy, maxCos)
	return Float32(sin(Float32(uy * Float32(Float32(Float32(-2.0) * Float32(pi)) + Float32(Float32(0.5) * Float32(Float32(pi) / uy))))) * sqrt(Float32(ux * Float32(Float32(Float32(2.0) + Float32(Float32(-1.0) * Float32(ux * (Float32(maxCos - Float32(1.0)) ^ Float32(2.0))))) - Float32(Float32(2.0) * maxCos)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sin((uy * ((single(-2.0) * single(pi)) + (single(0.5) * (single(pi) / uy))))) * sqrt((ux * ((single(2.0) + (single(-1.0) * (ux * ((maxCos - single(1.0)) ^ single(2.0))))) - (single(2.0) * maxCos))));
end
\sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift-cos.f32N/A

      \[\leadsto \color{blue}{\cos \left(\left(uy \cdot 2\right) \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. cos-neg-revN/A

      \[\leadsto \color{blue}{\cos \left(\mathsf{neg}\left(\left(uy \cdot 2\right) \cdot \pi\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(2 \cdot uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. count-2N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lift-+.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right)} \cdot \pi\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\left(uy + uy\right) \cdot \pi}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. *-commutativeN/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    9. lift-*.f32N/A

      \[\leadsto \cos \left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    10. sin-+PI/2-revN/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    11. lower-sin.f32N/A

      \[\leadsto \color{blue}{\sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    12. lift-PI.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \frac{\color{blue}{\pi}}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    13. mult-flip-revN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    14. metadata-evalN/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \color{blue}{\frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    15. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    16. lower-+.f32N/A

      \[\leadsto \sin \color{blue}{\left(\left(\mathsf{neg}\left(\pi \cdot \left(uy + uy\right)\right)\right) + \pi \cdot \frac{1}{2}\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    17. lift-*.f32N/A

      \[\leadsto \sin \left(\left(\mathsf{neg}\left(\color{blue}{\pi \cdot \left(uy + uy\right)}\right)\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    18. distribute-lft-neg-outN/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sin \left(\color{blue}{\left(\mathsf{neg}\left(\pi\right)\right) \cdot \left(uy + uy\right)} + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    20. lower-neg.f3299.0%

      \[\leadsto \sin \left(\color{blue}{\left(-\pi\right)} \cdot \left(uy + uy\right) + \pi \cdot \frac{1}{2}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    21. lift-*.f32N/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\pi \cdot \frac{1}{2}}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    22. *-commutativeN/A

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    23. lower-*.f3299.0%

      \[\leadsto \sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \color{blue}{\frac{1}{2} \cdot \pi}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \color{blue}{\sin \left(\left(-\pi\right) \cdot \left(uy + uy\right) + \frac{1}{2} \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  7. Taylor expanded in uy around inf

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \color{blue}{\left(-2 \cdot \mathsf{PI}\left(\right) + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)}\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    2. lower-+.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    3. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \mathsf{PI}\left(\right) + \color{blue}{\frac{1}{2}} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    4. lower-PI.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \color{blue}{\frac{\mathsf{PI}\left(\right)}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-/.f32N/A

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\mathsf{PI}\left(\right)}{\color{blue}{uy}}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower-PI.f3299.0%

      \[\leadsto \sin \left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  9. Applied rewrites99.0%

    \[\leadsto \sin \color{blue}{\left(uy \cdot \left(-2 \cdot \pi + \frac{1}{2} \cdot \frac{\pi}{uy}\right)\right)} \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
  10. Add Preprocessing

Alternative 4: 99.0% accurate, 1.0× speedup?

\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \left(\left(maxCos + maxCos\right) - \left(\left(1 - maxCos\right) \cdot ux\right) \cdot \left(maxCos - 1\right)\right) \cdot ux} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (cos (* (* uy 2) PI))
 (sqrt
  (-
   (+ ux ux)
   (*
    (- (+ maxCos maxCos) (* (* (- 1 maxCos) ux) (- maxCos 1)))
    ux)))))
float code(float ux, float uy, float maxCos) {
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf(((ux + ux) - (((maxCos + maxCos) - (((1.0f - maxCos) * ux) * (maxCos - 1.0f))) * ux)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(Float32(ux + ux) - Float32(Float32(Float32(maxCos + maxCos) - Float32(Float32(Float32(Float32(1.0) - maxCos) * ux) * Float32(maxCos - Float32(1.0)))) * ux))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt(((ux + ux) - (((maxCos + maxCos) - (((single(1.0) - maxCos) * ux) * (maxCos - single(1.0)))) * ux)));
end
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \left(\left(maxCos + maxCos\right) - \left(\left(1 - maxCos\right) \cdot ux\right) \cdot \left(maxCos - 1\right)\right) \cdot ux}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. associate--l+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 + \color{blue}{\left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - 2 \cdot maxCos\right)}\right)} \]
    5. distribute-lft-inN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + \color{blue}{ux \cdot \left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - 2 \cdot maxCos\right)}} \]
    6. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + \color{blue}{ux \cdot \left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - 2 \cdot maxCos\right)}} \]
    7. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + \color{blue}{ux} \cdot \left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + ux \cdot \color{blue}{\left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - 2 \cdot maxCos\right)}} \]
    9. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + ux \cdot \left(-1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right) - \color{blue}{2 \cdot maxCos}\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + \color{blue}{ux \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)}} \]
  7. Step-by-step derivation
    1. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + \color{blue}{ux \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)}} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 + ux \cdot \color{blue}{\left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)}} \]
    3. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right) \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)}} \]
    4. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right) \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)}} \]
    5. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot 2 - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right)} \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)} \]
    6. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{2 \cdot ux - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right)} \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)} \]
    7. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right)} \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)} \]
    8. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \color{blue}{\left(\mathsf{neg}\left(ux\right)\right)} \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)} \]
    9. distribute-lft-neg-outN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \left(\mathsf{neg}\left(ux \cdot \left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)\right)\right)} \]
    10. *-commutativeN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \left(\mathsf{neg}\left(\left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right) \cdot ux\right)\right)} \]
    11. distribute-lft-neg-inN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \left(\mathsf{neg}\left(\left(\left(-ux\right) \cdot \left(\left(1 - maxCos\right) \cdot \left(1 - maxCos\right)\right) - \left(maxCos + maxCos\right)\right)\right)\right) \cdot \color{blue}{ux}} \]
  8. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\left(ux + ux\right) - \color{blue}{\left(\left(maxCos + maxCos\right) - \left(\left(1 - maxCos\right) \cdot ux\right) \cdot \left(maxCos - 1\right)\right) \cdot ux}} \]
  9. Add Preprocessing

Alternative 5: 99.0% accurate, 1.0× speedup?

\[\cos \left(\left(\pi + \pi\right) \cdot uy\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (cos (* (+ PI PI) uy))
 (sqrt
  (*
   ux
   (- (- (- 2 (* (* ux (- maxCos 1)) (- maxCos 1))) maxCos) maxCos)))))
float code(float ux, float uy, float maxCos) {
	return cosf(((((float) M_PI) + ((float) M_PI)) * uy)) * sqrtf((ux * (((2.0f - ((ux * (maxCos - 1.0f)) * (maxCos - 1.0f))) - maxCos) - maxCos)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(Float32(Float32(pi) + Float32(pi)) * uy)) * sqrt(Float32(ux * Float32(Float32(Float32(Float32(2.0) - Float32(Float32(ux * Float32(maxCos - Float32(1.0))) * Float32(maxCos - Float32(1.0)))) - maxCos) - maxCos))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((single(pi) + single(pi)) * uy)) * sqrt((ux * (((single(2.0) - ((ux * (maxCos - single(1.0))) * (maxCos - single(1.0)))) - maxCos) - maxCos)));
end
\cos \left(\left(\pi + \pi\right) \cdot uy\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
    3. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \left(maxCos + \color{blue}{maxCos}\right)\right)} \]
    4. associate--r+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    5. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    6. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    8. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - 1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    12. *-lft-identity99.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    14. lift-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    15. unpow2N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    16. associate-*r*N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    17. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    18. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
  7. Step-by-step derivation
    1. lift-*.f32N/A

      \[\leadsto \cos \color{blue}{\left(\left(uy \cdot 2\right) \cdot \pi\right)} \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\color{blue}{\left(uy \cdot 2\right)} \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    3. associate-*l*N/A

      \[\leadsto \cos \color{blue}{\left(uy \cdot \left(2 \cdot \pi\right)\right)} \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    4. *-commutativeN/A

      \[\leadsto \cos \color{blue}{\left(\left(2 \cdot \pi\right) \cdot uy\right)} \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \color{blue}{\left(\left(2 \cdot \pi\right) \cdot uy\right)} \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    6. count-2-revN/A

      \[\leadsto \cos \left(\color{blue}{\left(\pi + \pi\right)} \cdot uy\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lower-+.f3299.0%

      \[\leadsto \cos \left(\color{blue}{\left(\pi + \pi\right)} \cdot uy\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  8. Applied rewrites99.0%

    \[\leadsto \cos \color{blue}{\left(\left(\pi + \pi\right) \cdot uy\right)} \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  9. Add Preprocessing

Alternative 6: 98.3% accurate, 1.0× speedup?

\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (cos (* (* uy 2) PI))
 (sqrt
  (* ux (- (- (- 2 (+ ux (* -2 (* maxCos ux)))) maxCos) maxCos)))))
float code(float ux, float uy, float maxCos) {
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (((2.0f - (ux + (-2.0f * (maxCos * ux)))) - maxCos) - maxCos)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(Float32(Float32(2.0) - Float32(ux + Float32(Float32(-2.0) * Float32(maxCos * ux)))) - maxCos) - maxCos))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (((single(2.0) - (ux + (single(-2.0) * (maxCos * ux)))) - maxCos) - maxCos)));
end
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
    3. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \left(maxCos + \color{blue}{maxCos}\right)\right)} \]
    4. associate--r+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    5. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    6. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    8. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - 1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    12. *-lft-identity99.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    14. lift-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    15. unpow2N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    16. associate-*r*N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    17. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    18. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
  7. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    3. lower-*.f3298.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  9. Applied rewrites98.3%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  10. Add Preprocessing

Alternative 7: 98.3% accurate, 1.0× speedup?

\[\sqrt{\left(2 - \left(\left(ux - \left(maxCos + maxCos\right) \cdot ux\right) + \left(maxCos + maxCos\right)\right)\right) \cdot ux} \cdot \cos \left(\left(\pi + \pi\right) \cdot uy\right) \]
(FPCore (ux uy maxCos)
  :precision binary32
  (*
 (sqrt
  (* (- 2 (+ (- ux (* (+ maxCos maxCos) ux)) (+ maxCos maxCos))) ux))
 (cos (* (+ PI PI) uy))))
float code(float ux, float uy, float maxCos) {
	return sqrtf(((2.0f - ((ux - ((maxCos + maxCos) * ux)) + (maxCos + maxCos))) * ux)) * cosf(((((float) M_PI) + ((float) M_PI)) * uy));
}
function code(ux, uy, maxCos)
	return Float32(sqrt(Float32(Float32(Float32(2.0) - Float32(Float32(ux - Float32(Float32(maxCos + maxCos) * ux)) + Float32(maxCos + maxCos))) * ux)) * cos(Float32(Float32(Float32(pi) + Float32(pi)) * uy)))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt(((single(2.0) - ((ux - ((maxCos + maxCos) * ux)) + (maxCos + maxCos))) * ux)) * cos(((single(pi) + single(pi)) * uy));
end
\sqrt{\left(2 - \left(\left(ux - \left(maxCos + maxCos\right) \cdot ux\right) + \left(maxCos + maxCos\right)\right)\right) \cdot ux} \cdot \cos \left(\left(\pi + \pi\right) \cdot uy\right)
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
    3. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \left(maxCos + \color{blue}{maxCos}\right)\right)} \]
    4. associate--r+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    5. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    6. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    8. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - 1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    12. *-lft-identity99.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    14. lift-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    15. unpow2N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    16. associate-*r*N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    17. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    18. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
  7. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    3. lower-*.f3298.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  9. Applied rewrites98.3%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  10. Applied rewrites98.3%

    \[\leadsto \color{blue}{\sqrt{\left(2 - \left(\left(ux - \left(maxCos + maxCos\right) \cdot ux\right) + \left(maxCos + maxCos\right)\right)\right) \cdot ux} \cdot \cos \left(\left(\pi + \pi\right) \cdot uy\right)} \]
  11. Add Preprocessing

Alternative 8: 97.5% accurate, 1.1× speedup?

\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux\right) - maxCos\right) - maxCos\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (* (cos (* (* uy 2) PI)) (sqrt (* ux (- (- (- 2 ux) maxCos) maxCos)))))
float code(float ux, float uy, float maxCos) {
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (((2.0f - ux) - maxCos) - maxCos)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(Float32(Float32(2.0) - ux) - maxCos) - maxCos))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (((single(2.0) - ux) - maxCos) - maxCos)));
end
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux\right) - maxCos\right) - maxCos\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
    3. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \left(maxCos + \color{blue}{maxCos}\right)\right)} \]
    4. associate--r+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    5. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    6. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    8. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - 1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    12. *-lft-identity99.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    14. lift-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    15. unpow2N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    16. associate-*r*N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    17. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    18. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
  7. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    3. lower-*.f3298.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  9. Applied rewrites98.3%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  10. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux\right) - maxCos\right) - maxCos\right)} \]
  11. Step-by-step derivation
    1. lower--.f3297.5%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux\right) - maxCos\right) - maxCos\right)} \]
  12. Applied rewrites97.5%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux\right) - maxCos\right) - maxCos\right)} \]
  13. Add Preprocessing

Alternative 9: 93.0% accurate, 1.2× speedup?

\[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (* (cos (* (* uy 2) PI)) (sqrt (* ux (- 2 ux)))))
float code(float ux, float uy, float maxCos) {
	return cosf(((uy * 2.0f) * ((float) M_PI))) * sqrtf((ux * (2.0f - ux)));
}
function code(ux, uy, maxCos)
	return Float32(cos(Float32(Float32(uy * Float32(2.0)) * Float32(pi))) * sqrt(Float32(ux * Float32(Float32(2.0) - ux))))
end
function tmp = code(ux, uy, maxCos)
	tmp = cos(((uy * single(2.0)) * single(pi))) * sqrt((ux * (single(2.0) - ux)));
end
\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in ux around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  3. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
    2. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    3. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2} \cdot maxCos\right)} \]
    4. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    5. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    6. lower-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    7. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)} \]
    8. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
  4. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{\color{blue}{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot maxCos\right)}} \]
  5. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \color{blue}{2 \cdot maxCos}\right)} \]
    2. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - 2 \cdot \color{blue}{maxCos}\right)} \]
    3. count-2-revN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - \left(maxCos + \color{blue}{maxCos}\right)\right)} \]
    4. associate--r+N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    5. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
    6. lower--.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    7. lift-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    8. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 + -1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    9. fp-cancel-sign-sub-invN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    10. lower--.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(\mathsf{neg}\left(-1\right)\right) \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    11. metadata-evalN/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - 1 \cdot \left(ux \cdot {\left(maxCos - 1\right)}^{2}\right)\right) - maxCos\right) - maxCos\right)} \]
    12. *-lft-identity99.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    14. lift-pow.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot {\left(maxCos - 1\right)}^{2}\right) - maxCos\right) - maxCos\right)} \]
    15. unpow2N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - ux \cdot \left(\left(maxCos - 1\right) \cdot \left(maxCos - 1\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    16. associate-*r*N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    17. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
    18. lower-*.f3299.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - maxCos\right)} \]
  6. Applied rewrites99.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux \cdot \left(maxCos - 1\right)\right) \cdot \left(maxCos - 1\right)\right) - maxCos\right) - \color{blue}{maxCos}\right)} \]
  7. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  8. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
    3. lower-*.f3298.3%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  9. Applied rewrites98.3%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(\left(\left(2 - \left(ux + -2 \cdot \left(maxCos \cdot ux\right)\right)\right) - maxCos\right) - maxCos\right)} \]
  10. Taylor expanded in maxCos around 0

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 - ux\right)}} \]
  11. Step-by-step derivation
    1. lower-*.f32N/A

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - \color{blue}{ux}\right)} \]
    2. lower--.f3293.0%

      \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \left(2 - ux\right)} \]
  12. Applied rewrites93.0%

    \[\leadsto \cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{ux \cdot \color{blue}{\left(2 - ux\right)}} \]
  13. Add Preprocessing

Alternative 10: 77.3% accurate, 2.4× speedup?

\[\begin{array}{l} t_0 := -1 - maxCos \cdot ux\\ \sqrt{\left(1 - t\_0 \cdot t\_0\right) - \left(ux \cdot ux - \left(2 \cdot ux\right) \cdot \left(maxCos \cdot ux - -1\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (- -1 (* maxCos ux))))
  (sqrt
   (-
    (- 1 (* t_0 t_0))
    (- (* ux ux) (* (* 2 ux) (- (* maxCos ux) -1)))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = -1.0f - (maxCos * ux);
	return sqrtf(((1.0f - (t_0 * t_0)) - ((ux * ux) - ((2.0f * ux) * ((maxCos * ux) - -1.0f)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: t_0
    t_0 = (-1.0e0) - (maxcos * ux)
    code = sqrt(((1.0e0 - (t_0 * t_0)) - ((ux * ux) - ((2.0e0 * ux) * ((maxcos * ux) - (-1.0e0))))))
end function
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(-1.0) - Float32(maxCos * ux))
	return sqrt(Float32(Float32(Float32(1.0) - Float32(t_0 * t_0)) - Float32(Float32(ux * ux) - Float32(Float32(Float32(2.0) * ux) * Float32(Float32(maxCos * ux) - Float32(-1.0))))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = single(-1.0) - (maxCos * ux);
	tmp = sqrt(((single(1.0) - (t_0 * t_0)) - ((ux * ux) - ((single(2.0) * ux) * ((maxCos * ux) - single(-1.0))))));
end
\begin{array}{l}
t_0 := -1 - maxCos \cdot ux\\
\sqrt{\left(1 - t\_0 \cdot t\_0\right) - \left(ux \cdot ux - \left(2 \cdot ux\right) \cdot \left(maxCos \cdot ux - -1\right)\right)}
\end{array}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Step-by-step derivation
    1. lift-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lift--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. sub-square-powN/A

      \[\leadsto \sqrt{1 - \left(\left({\left(1 + maxCos \cdot ux\right)}^{2} - 2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right)\right) + {ux}^{2}\right)} \]
    4. associate-+l-N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    5. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    6. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    8. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    9. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux + 1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    10. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    12. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    13. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    14. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux + 1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    15. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    16. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    17. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    18. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    20. lower-unsound-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    21. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
  6. Applied rewrites51.1%

    \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)} \]
  7. Step-by-step derivation
    1. lift--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)} \]
    2. lift--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)} \]
    3. associate--r-N/A

      \[\leadsto \sqrt{\left(1 - \left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right)\right) + \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)} \]
    4. add-flipN/A

      \[\leadsto \sqrt{\left(1 - \left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right)\right) - \left(\mathsf{neg}\left(\left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)\right)} \]
    5. lower--.f32N/A

      \[\leadsto \sqrt{\left(1 - \left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right)\right) - \left(\mathsf{neg}\left(\left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)\right)} \]
  8. Applied rewrites77.3%

    \[\leadsto \sqrt{\left(1 - \left(-1 - maxCos \cdot ux\right) \cdot \left(-1 - maxCos \cdot ux\right)\right) - \left(ux \cdot ux - \left(2 \cdot ux\right) \cdot \left(maxCos \cdot ux - -1\right)\right)} \]
  9. Add Preprocessing

Alternative 11: 51.4% accurate, 2.9× speedup?

\[\begin{array}{l} t_0 := maxCos \cdot ux - ux\\ \sqrt{1 - \left(1 - \left(\left(ux - maxCos \cdot ux\right) \cdot 2 - t\_0 \cdot t\_0\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (- (* maxCos ux) ux)))
  (sqrt (- 1 (- 1 (- (* (- ux (* maxCos ux)) 2) (* t_0 t_0)))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = (maxCos * ux) - ux;
	return sqrtf((1.0f - (1.0f - (((ux - (maxCos * ux)) * 2.0f) - (t_0 * t_0)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: t_0
    t_0 = (maxcos * ux) - ux
    code = sqrt((1.0e0 - (1.0e0 - (((ux - (maxcos * ux)) * 2.0e0) - (t_0 * t_0)))))
end function
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(maxCos * ux) - ux)
	return sqrt(Float32(Float32(1.0) - Float32(Float32(1.0) - Float32(Float32(Float32(ux - Float32(maxCos * ux)) * Float32(2.0)) - Float32(t_0 * t_0)))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = (maxCos * ux) - ux;
	tmp = sqrt((single(1.0) - (single(1.0) - (((ux - (maxCos * ux)) * single(2.0)) - (t_0 * t_0)))));
end
\begin{array}{l}
t_0 := maxCos \cdot ux - ux\\
\sqrt{1 - \left(1 - \left(\left(ux - maxCos \cdot ux\right) \cdot 2 - t\_0 \cdot t\_0\right)\right)}
\end{array}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Step-by-step derivation
    1. lift-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lift--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lift-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. associate--l+N/A

      \[\leadsto \sqrt{1 - {\left(1 + \left(maxCos \cdot ux - ux\right)\right)}^{2}} \]
    5. add-flip-revN/A

      \[\leadsto \sqrt{1 - {\left(1 - \left(\mathsf{neg}\left(\left(maxCos \cdot ux - ux\right)\right)\right)\right)}^{2}} \]
    6. sub-negate-revN/A

      \[\leadsto \sqrt{1 - {\left(1 - \left(ux - maxCos \cdot ux\right)\right)}^{2}} \]
    7. lift--.f32N/A

      \[\leadsto \sqrt{1 - {\left(1 - \left(ux - maxCos \cdot ux\right)\right)}^{2}} \]
    8. sub-square-pow-revN/A

      \[\leadsto \sqrt{1 - \left(\left({1}^{2} - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + {\left(ux - maxCos \cdot ux\right)}^{2}\right)} \]
    9. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(1 - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + {\left(ux - maxCos \cdot ux\right)}^{2}\right)} \]
    10. lift-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + {\left(ux - maxCos \cdot ux\right)}^{2}\right)} \]
    11. lift-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + {\left(ux - maxCos \cdot ux\right)}^{2}\right)} \]
    12. pow2N/A

      \[\leadsto \sqrt{1 - \left(\left(1 - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + \left(ux - maxCos \cdot ux\right) \cdot \left(ux - maxCos \cdot ux\right)\right)} \]
    13. lift-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 - 2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right)\right) + \left(ux - maxCos \cdot ux\right) \cdot \left(ux - maxCos \cdot ux\right)\right)} \]
    14. associate-+l-N/A

      \[\leadsto \sqrt{1 - \left(1 - \left(2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right) - \left(ux - maxCos \cdot ux\right) \cdot \left(ux - maxCos \cdot ux\right)\right)\right)} \]
    15. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(1 - \left(2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right) - \left(ux - maxCos \cdot ux\right) \cdot \left(ux - maxCos \cdot ux\right)\right)\right)} \]
    16. lower--.f3251.4%

      \[\leadsto \sqrt{1 - \left(1 - \left(2 \cdot \left(1 \cdot \left(ux - maxCos \cdot ux\right)\right) - \left(ux - maxCos \cdot ux\right) \cdot \left(ux - maxCos \cdot ux\right)\right)\right)} \]
  6. Applied rewrites51.4%

    \[\leadsto \sqrt{1 - \left(1 - \left(\left(ux - maxCos \cdot ux\right) \cdot 2 - \left(maxCos \cdot ux - ux\right) \cdot \left(maxCos \cdot ux - ux\right)\right)\right)} \]
  7. Add Preprocessing

Alternative 12: 50.5% accurate, 3.1× speedup?

\[\begin{array}{l} t_0 := maxCos \cdot ux - -1\\ \sqrt{1 - \left(t\_0 \cdot t\_0 - \left(2 \cdot ux - ux \cdot ux\right)\right)} \end{array} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (let* ((t_0 (- (* maxCos ux) -1)))
  (sqrt (- 1 (- (* t_0 t_0) (- (* 2 ux) (* ux ux)))))))
float code(float ux, float uy, float maxCos) {
	float t_0 = (maxCos * ux) - -1.0f;
	return sqrtf((1.0f - ((t_0 * t_0) - ((2.0f * ux) - (ux * ux)))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    real(4) :: t_0
    t_0 = (maxcos * ux) - (-1.0e0)
    code = sqrt((1.0e0 - ((t_0 * t_0) - ((2.0e0 * ux) - (ux * ux)))))
end function
function code(ux, uy, maxCos)
	t_0 = Float32(Float32(maxCos * ux) - Float32(-1.0))
	return sqrt(Float32(Float32(1.0) - Float32(Float32(t_0 * t_0) - Float32(Float32(Float32(2.0) * ux) - Float32(ux * ux)))))
end
function tmp = code(ux, uy, maxCos)
	t_0 = (maxCos * ux) - single(-1.0);
	tmp = sqrt((single(1.0) - ((t_0 * t_0) - ((single(2.0) * ux) - (ux * ux)))));
end
\begin{array}{l}
t_0 := maxCos \cdot ux - -1\\
\sqrt{1 - \left(t\_0 \cdot t\_0 - \left(2 \cdot ux - ux \cdot ux\right)\right)}
\end{array}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Step-by-step derivation
    1. lift-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lift--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. sub-square-powN/A

      \[\leadsto \sqrt{1 - \left(\left({\left(1 + maxCos \cdot ux\right)}^{2} - 2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right)\right) + {ux}^{2}\right)} \]
    4. associate-+l-N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    5. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    6. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    8. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    9. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux + 1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    10. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    12. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    13. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    14. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux + 1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    15. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    16. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    17. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    18. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    20. lower-unsound-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    21. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
  6. Applied rewrites51.1%

    \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)} \]
  7. Taylor expanded in ux around 0

    \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot ux - ux \cdot ux\right)\right)} \]
  8. Step-by-step derivation
    1. lower-*.f3250.5%

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot ux - ux \cdot ux\right)\right)} \]
  9. Applied rewrites50.5%

    \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot ux - ux \cdot ux\right)\right)} \]
  10. Add Preprocessing

Alternative 13: 49.2% accurate, 3.8× speedup?

\[\sqrt{\left(\left(ux - maxCos \cdot ux\right) - 1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (sqrt
 (+ (* (- (- ux (* maxCos ux)) 1) (- (* maxCos ux) (+ -1 ux))) 1)))
float code(float ux, float uy, float maxCos) {
	return sqrtf(((((ux - (maxCos * ux)) - 1.0f) * ((maxCos * ux) - (-1.0f + ux))) + 1.0f));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt(((((ux - (maxcos * ux)) - 1.0e0) * ((maxcos * ux) - ((-1.0e0) + ux))) + 1.0e0))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(Float32(Float32(ux - Float32(maxCos * ux)) - Float32(1.0)) * Float32(Float32(maxCos * ux) - Float32(Float32(-1.0) + ux))) + Float32(1.0)))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt(((((ux - (maxCos * ux)) - single(1.0)) * ((maxCos * ux) - (single(-1.0) + ux))) + single(1.0)));
end
\sqrt{\left(\left(ux - maxCos \cdot ux\right) - 1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Step-by-step derivation
    1. lift-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lift--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. sub-square-powN/A

      \[\leadsto \sqrt{1 - \left(\left({\left(1 + maxCos \cdot ux\right)}^{2} - 2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right)\right) + {ux}^{2}\right)} \]
    4. associate-+l-N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    5. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left({\left(1 + maxCos \cdot ux\right)}^{2} - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    6. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    7. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    8. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(1 + maxCos \cdot ux\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    9. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux + 1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    10. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    11. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    12. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    13. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(1 + maxCos \cdot ux\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    14. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux + 1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    15. add-flipN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - \left(\mathsf{neg}\left(1\right)\right)\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    16. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    17. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - {ux}^{2}\right)\right)} \]
    18. unpow2N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    19. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    20. lower-unsound-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
    21. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(2 \cdot \left(\left(1 + maxCos \cdot ux\right) \cdot ux\right) - ux \cdot ux\right)\right)} \]
  6. Applied rewrites51.1%

    \[\leadsto \sqrt{1 - \left(\left(maxCos \cdot ux - -1\right) \cdot \left(maxCos \cdot ux - -1\right) - \left(\left(\left(maxCos \cdot ux - -1\right) \cdot ux\right) \cdot 2 - ux \cdot ux\right)\right)} \]
  7. Applied rewrites49.2%

    \[\leadsto \sqrt{\left(\left(ux - maxCos \cdot ux\right) - 1\right) \cdot \left(maxCos \cdot ux - \left(-1 + ux\right)\right) + 1} \]
  8. Add Preprocessing

Alternative 14: 40.0% accurate, 5.6× speedup?

\[\sqrt{1 - \left(\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux - -1\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (sqrt (- 1 (- (* (- (+ maxCos maxCos) 2) ux) -1))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((1.0f - ((((maxCos + maxCos) - 2.0f) * ux) - -1.0f)));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((1.0e0 - ((((maxcos + maxcos) - 2.0e0) * ux) - (-1.0e0))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(1.0) - Float32(Float32(Float32(Float32(maxCos + maxCos) - Float32(2.0)) * ux) - Float32(-1.0))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((single(1.0) - ((((maxCos + maxCos) - single(2.0)) * ux) - single(-1.0))));
end
\sqrt{1 - \left(\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux - -1\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Taylor expanded in ux around 0

    \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  6. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    3. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    4. lower-*.f3240.0%

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  7. Applied rewrites40.0%

    \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  8. Step-by-step derivation
    1. lift-+.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    2. +-commutativeN/A

      \[\leadsto \sqrt{1 - \left(ux \cdot \left(2 \cdot maxCos - 2\right) + 1\right)} \]
    3. add-flipN/A

      \[\leadsto \sqrt{1 - \left(ux \cdot \left(2 \cdot maxCos - 2\right) - \left(\mathsf{neg}\left(1\right)\right)\right)} \]
    4. metadata-evalN/A

      \[\leadsto \sqrt{1 - \left(ux \cdot \left(2 \cdot maxCos - 2\right) - -1\right)} \]
    5. lower--.f3240.0%

      \[\leadsto \sqrt{1 - \left(ux \cdot \left(2 \cdot maxCos - 2\right) - -1\right)} \]
    6. lift-*.f32N/A

      \[\leadsto \sqrt{1 - \left(ux \cdot \left(2 \cdot maxCos - 2\right) - -1\right)} \]
    7. *-commutativeN/A

      \[\leadsto \sqrt{1 - \left(\left(2 \cdot maxCos - 2\right) \cdot ux - -1\right)} \]
    8. lower-*.f3240.0%

      \[\leadsto \sqrt{1 - \left(\left(2 \cdot maxCos - 2\right) \cdot ux - -1\right)} \]
    9. lift-*.f32N/A

      \[\leadsto \sqrt{1 - \left(\left(2 \cdot maxCos - 2\right) \cdot ux - -1\right)} \]
    10. count-2-revN/A

      \[\leadsto \sqrt{1 - \left(\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux - -1\right)} \]
    11. lift-+.f3240.0%

      \[\leadsto \sqrt{1 - \left(\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux - -1\right)} \]
  9. Applied rewrites40.0%

    \[\leadsto \sqrt{1 - \left(\left(\left(maxCos + maxCos\right) - 2\right) \cdot ux - -1\right)} \]
  10. Add Preprocessing

Alternative 15: 39.4% accurate, 7.1× speedup?

\[\sqrt{1 - \left(1 + ux \cdot -2\right)} \]
(FPCore (ux uy maxCos)
  :precision binary32
  (sqrt (- 1 (+ 1 (* ux -2)))))
float code(float ux, float uy, float maxCos) {
	return sqrtf((1.0f - (1.0f + (ux * -2.0f))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
    real(4), intent (in) :: ux
    real(4), intent (in) :: uy
    real(4), intent (in) :: maxcos
    code = sqrt((1.0e0 - (1.0e0 + (ux * (-2.0e0)))))
end function
function code(ux, uy, maxCos)
	return sqrt(Float32(Float32(1.0) - Float32(Float32(1.0) + Float32(ux * Float32(-2.0)))))
end
function tmp = code(ux, uy, maxCos)
	tmp = sqrt((single(1.0) - (single(1.0) + (ux * single(-2.0)))));
end
\sqrt{1 - \left(1 + ux \cdot -2\right)}
Derivation
  1. Initial program 57.2%

    \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
  2. Taylor expanded in uy around 0

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  3. Step-by-step derivation
    1. lower-sqrt.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    2. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    3. lower-pow.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. lower--.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    5. lower-+.f32N/A

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    6. lower-*.f3249.0%

      \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
  4. Applied rewrites49.0%

    \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
  5. Taylor expanded in ux around 0

    \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  6. Step-by-step derivation
    1. lower-+.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    2. lower-*.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    3. lower--.f32N/A

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    4. lower-*.f3240.0%

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  7. Applied rewrites40.0%

    \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
  8. Taylor expanded in maxCos around 0

    \[\leadsto \sqrt{1 - \left(1 + ux \cdot -2\right)} \]
  9. Step-by-step derivation
    1. Applied rewrites39.4%

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot -2\right)} \]
    2. Add Preprocessing

    Alternative 16: 6.6% accurate, 11.1× speedup?

    \[\sqrt{1 - 1} \]
    (FPCore (ux uy maxCos)
      :precision binary32
      (sqrt (- 1 1)))
    float code(float ux, float uy, float maxCos) {
    	return sqrtf((1.0f - 1.0f));
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(4) function code(ux, uy, maxcos)
    use fmin_fmax_functions
        real(4), intent (in) :: ux
        real(4), intent (in) :: uy
        real(4), intent (in) :: maxcos
        code = sqrt((1.0e0 - 1.0e0))
    end function
    
    function code(ux, uy, maxCos)
    	return sqrt(Float32(Float32(1.0) - Float32(1.0)))
    end
    
    function tmp = code(ux, uy, maxCos)
    	tmp = sqrt((single(1.0) - single(1.0)));
    end
    
    \sqrt{1 - 1}
    
    Derivation
    1. Initial program 57.2%

      \[\cos \left(\left(uy \cdot 2\right) \cdot \pi\right) \cdot \sqrt{1 - \left(\left(1 - ux\right) + ux \cdot maxCos\right) \cdot \left(\left(1 - ux\right) + ux \cdot maxCos\right)} \]
    2. Taylor expanded in uy around 0

      \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
    3. Step-by-step derivation
      1. lower-sqrt.f32N/A

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
      2. lower--.f32N/A

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
      3. lower-pow.f32N/A

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
      4. lower--.f32N/A

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
      5. lower-+.f32N/A

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
      6. lower-*.f3249.0%

        \[\leadsto \sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}} \]
    4. Applied rewrites49.0%

      \[\leadsto \color{blue}{\sqrt{1 - {\left(\left(1 + maxCos \cdot ux\right) - ux\right)}^{2}}} \]
    5. Taylor expanded in ux around 0

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    6. Step-by-step derivation
      1. lower-+.f32N/A

        \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
      2. lower-*.f32N/A

        \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
      3. lower--.f32N/A

        \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
      4. lower-*.f3240.0%

        \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    7. Applied rewrites40.0%

      \[\leadsto \sqrt{1 - \left(1 + ux \cdot \left(2 \cdot maxCos - 2\right)\right)} \]
    8. Taylor expanded in ux around 0

      \[\leadsto \sqrt{1 - 1} \]
    9. Step-by-step derivation
      1. Applied rewrites6.6%

        \[\leadsto \sqrt{1 - 1} \]
      2. Add Preprocessing

      Reproduce

      ?
      herbie shell --seed 2025271 -o generate:evaluate
      (FPCore (ux uy maxCos)
        :name "UniformSampleCone, x"
        :precision binary32
        :pre (and (and (and (<= 2328306437/10000000000000000000 ux) (<= ux 1)) (and (<= 2328306437/10000000000000000000 uy) (<= uy 1))) (and (<= 0 maxCos) (<= maxCos 1)))
        (* (cos (* (* uy 2) PI)) (sqrt (- 1 (* (+ (- 1 ux) (* ux maxCos)) (+ (- 1 ux) (* ux maxCos)))))))