Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 6.8s
Alternatives: 19
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
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(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 19 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: 93.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
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(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th
\end{array}

Alternative 1: 99.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (hypot (sin ky) (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
}
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
\end{array}
Derivation
  1. Initial program 93.8%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-sqrt.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    2. lift-+.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    3. lift-pow.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    5. lift-pow.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
    6. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
    7. +-commutativeN/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    8. unpow2N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    9. unpow2N/A

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    10. lower-hypot.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    11. lift-sin.f64N/A

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
    12. lift-sin.f6499.6

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
  4. Applied rewrites99.6%

    \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  5. Add Preprocessing

Alternative 2: 83.4% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ t_3 := {\sin ky}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_1 + t\_3}}\\ \mathbf{if}\;t\_4 \leq -0.995:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_3}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq -0.0005:\\ \;\;\;\;\left(\frac{1}{t\_2} \cdot \sin ky\right) \cdot th\\ \mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{t\_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (pow (sin kx) 2.0))
        (t_2 (hypot (sin kx) (sin ky)))
        (t_3 (pow (sin ky) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ t_1 t_3)))))
   (if (<= t_4 -0.995)
     (* (/ (sin ky) (sqrt t_3)) (sin th))
     (if (<= t_4 -0.0005)
       (* (* (/ 1.0 t_2) (sin ky)) th)
       (if (<= t_4 5e-9)
         (* (/ ky (sqrt t_1)) (sin th))
         (if (<= t_4 0.998)
           (/ (* th (sin ky)) t_2)
           (* (/ (sin ky) (hypot (sin ky) kx)) (sin th))))))))
double code(double kx, double ky, double th) {
	double t_1 = pow(sin(kx), 2.0);
	double t_2 = hypot(sin(kx), sin(ky));
	double t_3 = pow(sin(ky), 2.0);
	double t_4 = sin(ky) / sqrt((t_1 + t_3));
	double tmp;
	if (t_4 <= -0.995) {
		tmp = (sin(ky) / sqrt(t_3)) * sin(th);
	} else if (t_4 <= -0.0005) {
		tmp = ((1.0 / t_2) * sin(ky)) * th;
	} else if (t_4 <= 5e-9) {
		tmp = (ky / sqrt(t_1)) * sin(th);
	} else if (t_4 <= 0.998) {
		tmp = (th * sin(ky)) / t_2;
	} else {
		tmp = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.pow(Math.sin(kx), 2.0);
	double t_2 = Math.hypot(Math.sin(kx), Math.sin(ky));
	double t_3 = Math.pow(Math.sin(ky), 2.0);
	double t_4 = Math.sin(ky) / Math.sqrt((t_1 + t_3));
	double tmp;
	if (t_4 <= -0.995) {
		tmp = (Math.sin(ky) / Math.sqrt(t_3)) * Math.sin(th);
	} else if (t_4 <= -0.0005) {
		tmp = ((1.0 / t_2) * Math.sin(ky)) * th;
	} else if (t_4 <= 5e-9) {
		tmp = (ky / Math.sqrt(t_1)) * Math.sin(th);
	} else if (t_4 <= 0.998) {
		tmp = (th * Math.sin(ky)) / t_2;
	} else {
		tmp = (Math.sin(ky) / Math.hypot(Math.sin(ky), kx)) * Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.pow(math.sin(kx), 2.0)
	t_2 = math.hypot(math.sin(kx), math.sin(ky))
	t_3 = math.pow(math.sin(ky), 2.0)
	t_4 = math.sin(ky) / math.sqrt((t_1 + t_3))
	tmp = 0
	if t_4 <= -0.995:
		tmp = (math.sin(ky) / math.sqrt(t_3)) * math.sin(th)
	elif t_4 <= -0.0005:
		tmp = ((1.0 / t_2) * math.sin(ky)) * th
	elif t_4 <= 5e-9:
		tmp = (ky / math.sqrt(t_1)) * math.sin(th)
	elif t_4 <= 0.998:
		tmp = (th * math.sin(ky)) / t_2
	else:
		tmp = (math.sin(ky) / math.hypot(math.sin(ky), kx)) * math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = sin(kx) ^ 2.0
	t_2 = hypot(sin(kx), sin(ky))
	t_3 = sin(ky) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64(t_1 + t_3)))
	tmp = 0.0
	if (t_4 <= -0.995)
		tmp = Float64(Float64(sin(ky) / sqrt(t_3)) * sin(th));
	elseif (t_4 <= -0.0005)
		tmp = Float64(Float64(Float64(1.0 / t_2) * sin(ky)) * th);
	elseif (t_4 <= 5e-9)
		tmp = Float64(Float64(ky / sqrt(t_1)) * sin(th));
	elseif (t_4 <= 0.998)
		tmp = Float64(Float64(th * sin(ky)) / t_2);
	else
		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), kx)) * sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(kx) ^ 2.0;
	t_2 = hypot(sin(kx), sin(ky));
	t_3 = sin(ky) ^ 2.0;
	t_4 = sin(ky) / sqrt((t_1 + t_3));
	tmp = 0.0;
	if (t_4 <= -0.995)
		tmp = (sin(ky) / sqrt(t_3)) * sin(th);
	elseif (t_4 <= -0.0005)
		tmp = ((1.0 / t_2) * sin(ky)) * th;
	elseif (t_4 <= 5e-9)
		tmp = (ky / sqrt(t_1)) * sin(th);
	elseif (t_4 <= 0.998)
		tmp = (th * sin(ky)) / t_2;
	else
		tmp = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.995], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$3], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, -0.0005], N[(N[(N[(1.0 / t$95$2), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$4, 5e-9], N[(N[(ky / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / t$95$2), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := {\sin kx}^{2}\\
t_2 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
t_3 := {\sin ky}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{t\_1 + t\_3}}\\
\mathbf{if}\;t\_4 \leq -0.995:\\
\;\;\;\;\frac{\sin ky}{\sqrt{t\_3}} \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq -0.0005:\\
\;\;\;\;\left(\frac{1}{t\_2} \cdot \sin ky\right) \cdot th\\

\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq 0.998:\\
\;\;\;\;\frac{th \cdot \sin ky}{t\_2}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.994999999999999996

    1. Initial program 90.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. lift-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot \sin th \]
      2. lift-pow.f6487.6

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \cdot \sin th \]
    5. Applied rewrites87.6%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]

    if -0.994999999999999996 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Taylor expanded in kx around inf

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
    4. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin ky}\right) \cdot \sin th \]
      2. lower-*.f64N/A

        \[\leadsto \left(\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin ky}\right) \cdot \sin th \]
      3. sqrt-divN/A

        \[\leadsto \left(\frac{\sqrt{1}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      4. metadata-evalN/A

        \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
      5. inv-powN/A

        \[\leadsto \left({\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      6. lower-pow.f64N/A

        \[\leadsto \left({\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + {\sin ky}^{2}}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      8. unpow2N/A

        \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      9. lower-hypot.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      10. lift-sin.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      11. lift-sin.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      12. lift-sin.f6499.3

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
    5. Applied rewrites99.3%

      \[\leadsto \color{blue}{\left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. lift-pow.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      2. lift-sin.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      3. lift-sin.f64N/A

        \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      4. lift-hypot.f64N/A

        \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
      5. unpow-1N/A

        \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      6. pow2N/A

        \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
      7. pow2N/A

        \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
      8. lower-/.f64N/A

        \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
      9. pow2N/A

        \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
      10. pow2N/A

        \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
      11. lift-hypot.f64N/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
      12. lift-sin.f64N/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
      13. lift-sin.f6499.3

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
    7. Applied rewrites99.3%

      \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
    8. Taylor expanded in th around 0

      \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
    9. Step-by-step derivation
      1. *-commutativeN/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \color{blue}{th}\right) \]
      2. lower-*.f64N/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \color{blue}{th}\right) \]
      3. +-commutativeN/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot th\right) \]
      4. *-commutativeN/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left({th}^{2} \cdot \frac{-1}{6} + 1\right) \cdot th\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right) \cdot th\right) \]
      6. unpow2N/A

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
      7. lower-*.f6454.1

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]
    10. Applied rewrites54.1%

      \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
    11. Taylor expanded in th around 0

      \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot th \]
    12. Step-by-step derivation
      1. Applied rewrites54.6%

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot th \]

      if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

      1. Initial program 99.6%

        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      2. Add Preprocessing
      3. Taylor expanded in ky around 0

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      4. Step-by-step derivation
        1. lift-sin.f64N/A

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
        2. lift-pow.f6499.6

          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
      5. Applied rewrites99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
      6. Taylor expanded in ky around 0

        \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
      7. Step-by-step derivation
        1. Applied rewrites99.6%

          \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

        if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

        1. Initial program 99.1%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

            \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
          2. lift-/.f64N/A

            \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          3. lift-sin.f64N/A

            \[\leadsto \frac{\color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          4. lift-sqrt.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          5. lift-+.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          6. lift-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
          7. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          8. lift-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
          9. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
          10. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin th} \]
          11. associate-*l/N/A

            \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          12. lower-/.f64N/A

            \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
          13. *-commutativeN/A

            \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
          14. lower-*.f64N/A

            \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
          15. lift-sin.f64N/A

            \[\leadsto \frac{\color{blue}{\sin th} \cdot \sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
          16. lift-sin.f64N/A

            \[\leadsto \frac{\sin th \cdot \color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
        4. Applied rewrites99.2%

          \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
        5. Taylor expanded in th around 0

          \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
        6. Step-by-step derivation
          1. lower-*.f64N/A

            \[\leadsto \frac{th \cdot \color{blue}{\sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
          2. lift-sin.f6453.6

            \[\leadsto \frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
        7. Applied rewrites53.6%

          \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]

        if 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

        1. Initial program 82.8%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-sqrt.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          2. lift-+.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
          3. lift-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
          4. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          5. lift-pow.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
          6. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
          7. +-commutativeN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
          8. unpow2N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
          9. unpow2N/A

            \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
          10. lower-hypot.f64N/A

            \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
          11. lift-sin.f64N/A

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
          12. lift-sin.f6499.9

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
        4. Applied rewrites99.9%

          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
        5. Taylor expanded in kx around 0

          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
        6. Step-by-step derivation
          1. Applied rewrites96.7%

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
        7. Recombined 5 regimes into one program.
        8. Add Preprocessing

        Alternative 3: 86.4% accurate, 0.2× speedup?

        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\ t_2 := {\sin kx}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\ t_4 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ \mathbf{if}\;t\_3 \leq -0.995:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_3 \leq -0.0005:\\ \;\;\;\;\left(\frac{1}{t\_4} \cdot \sin ky\right) \cdot th\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{t\_4}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
        (FPCore (kx ky th)
         :precision binary64
         (let* ((t_1 (* (/ (sin ky) (hypot (sin ky) kx)) (sin th)))
                (t_2 (pow (sin kx) 2.0))
                (t_3 (/ (sin ky) (sqrt (+ t_2 (pow (sin ky) 2.0)))))
                (t_4 (hypot (sin kx) (sin ky))))
           (if (<= t_3 -0.995)
             t_1
             (if (<= t_3 -0.0005)
               (* (* (/ 1.0 t_4) (sin ky)) th)
               (if (<= t_3 5e-9)
                 (* (/ ky (sqrt t_2)) (sin th))
                 (if (<= t_3 0.998) (/ (* th (sin ky)) t_4) t_1))))))
        double code(double kx, double ky, double th) {
        	double t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
        	double t_2 = pow(sin(kx), 2.0);
        	double t_3 = sin(ky) / sqrt((t_2 + pow(sin(ky), 2.0)));
        	double t_4 = hypot(sin(kx), sin(ky));
        	double tmp;
        	if (t_3 <= -0.995) {
        		tmp = t_1;
        	} else if (t_3 <= -0.0005) {
        		tmp = ((1.0 / t_4) * sin(ky)) * th;
        	} else if (t_3 <= 5e-9) {
        		tmp = (ky / sqrt(t_2)) * sin(th);
        	} else if (t_3 <= 0.998) {
        		tmp = (th * sin(ky)) / t_4;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        public static double code(double kx, double ky, double th) {
        	double t_1 = (Math.sin(ky) / Math.hypot(Math.sin(ky), kx)) * Math.sin(th);
        	double t_2 = Math.pow(Math.sin(kx), 2.0);
        	double t_3 = Math.sin(ky) / Math.sqrt((t_2 + Math.pow(Math.sin(ky), 2.0)));
        	double t_4 = Math.hypot(Math.sin(kx), Math.sin(ky));
        	double tmp;
        	if (t_3 <= -0.995) {
        		tmp = t_1;
        	} else if (t_3 <= -0.0005) {
        		tmp = ((1.0 / t_4) * Math.sin(ky)) * th;
        	} else if (t_3 <= 5e-9) {
        		tmp = (ky / Math.sqrt(t_2)) * Math.sin(th);
        	} else if (t_3 <= 0.998) {
        		tmp = (th * Math.sin(ky)) / t_4;
        	} else {
        		tmp = t_1;
        	}
        	return tmp;
        }
        
        def code(kx, ky, th):
        	t_1 = (math.sin(ky) / math.hypot(math.sin(ky), kx)) * math.sin(th)
        	t_2 = math.pow(math.sin(kx), 2.0)
        	t_3 = math.sin(ky) / math.sqrt((t_2 + math.pow(math.sin(ky), 2.0)))
        	t_4 = math.hypot(math.sin(kx), math.sin(ky))
        	tmp = 0
        	if t_3 <= -0.995:
        		tmp = t_1
        	elif t_3 <= -0.0005:
        		tmp = ((1.0 / t_4) * math.sin(ky)) * th
        	elif t_3 <= 5e-9:
        		tmp = (ky / math.sqrt(t_2)) * math.sin(th)
        	elif t_3 <= 0.998:
        		tmp = (th * math.sin(ky)) / t_4
        	else:
        		tmp = t_1
        	return tmp
        
        function code(kx, ky, th)
        	t_1 = Float64(Float64(sin(ky) / hypot(sin(ky), kx)) * sin(th))
        	t_2 = sin(kx) ^ 2.0
        	t_3 = Float64(sin(ky) / sqrt(Float64(t_2 + (sin(ky) ^ 2.0))))
        	t_4 = hypot(sin(kx), sin(ky))
        	tmp = 0.0
        	if (t_3 <= -0.995)
        		tmp = t_1;
        	elseif (t_3 <= -0.0005)
        		tmp = Float64(Float64(Float64(1.0 / t_4) * sin(ky)) * th);
        	elseif (t_3 <= 5e-9)
        		tmp = Float64(Float64(ky / sqrt(t_2)) * sin(th));
        	elseif (t_3 <= 0.998)
        		tmp = Float64(Float64(th * sin(ky)) / t_4);
        	else
        		tmp = t_1;
        	end
        	return tmp
        end
        
        function tmp_2 = code(kx, ky, th)
        	t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
        	t_2 = sin(kx) ^ 2.0;
        	t_3 = sin(ky) / sqrt((t_2 + (sin(ky) ^ 2.0)));
        	t_4 = hypot(sin(kx), sin(ky));
        	tmp = 0.0;
        	if (t_3 <= -0.995)
        		tmp = t_1;
        	elseif (t_3 <= -0.0005)
        		tmp = ((1.0 / t_4) * sin(ky)) * th;
        	elseif (t_3 <= 5e-9)
        		tmp = (ky / sqrt(t_2)) * sin(th);
        	elseif (t_3 <= 0.998)
        		tmp = (th * sin(ky)) / t_4;
        	else
        		tmp = t_1;
        	end
        	tmp_2 = tmp;
        end
        
        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[t$95$3, -0.995], t$95$1, If[LessEqual[t$95$3, -0.0005], N[(N[(N[(1.0 / t$95$4), $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$3, 5e-9], N[(N[(ky / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision], t$95$1]]]]]]]]
        
        \begin{array}{l}
        
        \\
        \begin{array}{l}
        t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\
        t_2 := {\sin kx}^{2}\\
        t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\
        t_4 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
        \mathbf{if}\;t\_3 \leq -0.995:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;t\_3 \leq -0.0005:\\
        \;\;\;\;\left(\frac{1}{t\_4} \cdot \sin ky\right) \cdot th\\
        
        \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\
        \;\;\;\;\frac{ky}{\sqrt{t\_2}} \cdot \sin th\\
        
        \mathbf{elif}\;t\_3 \leq 0.998:\\
        \;\;\;\;\frac{th \cdot \sin ky}{t\_4}\\
        
        \mathbf{else}:\\
        \;\;\;\;t\_1\\
        
        
        \end{array}
        \end{array}
        
        Derivation
        1. Split input into 4 regimes
        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.994999999999999996 or 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

          1. Initial program 86.2%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. Add Preprocessing
          3. Step-by-step derivation
            1. lift-sqrt.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
            2. lift-+.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
            3. lift-pow.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
            4. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            5. lift-pow.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
            6. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
            7. +-commutativeN/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
            8. unpow2N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
            9. unpow2N/A

              \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
            10. lower-hypot.f64N/A

              \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
            11. lift-sin.f64N/A

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
            12. lift-sin.f6499.9

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
          4. Applied rewrites99.9%

            \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
          5. Taylor expanded in kx around 0

            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
          6. Step-by-step derivation
            1. Applied rewrites97.3%

              \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]

            if -0.994999999999999996 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

            1. Initial program 99.5%

              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
            2. Add Preprocessing
            3. Taylor expanded in kx around inf

              \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
            4. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \left(\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin ky}\right) \cdot \sin th \]
              2. lower-*.f64N/A

                \[\leadsto \left(\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin ky}\right) \cdot \sin th \]
              3. sqrt-divN/A

                \[\leadsto \left(\frac{\sqrt{1}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              4. metadata-evalN/A

                \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
              5. inv-powN/A

                \[\leadsto \left({\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              6. lower-pow.f64N/A

                \[\leadsto \left({\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              7. unpow2N/A

                \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + {\sin ky}^{2}}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              8. unpow2N/A

                \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              9. lower-hypot.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              10. lift-sin.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              11. lift-sin.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              12. lift-sin.f6499.3

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
            5. Applied rewrites99.3%

              \[\leadsto \color{blue}{\left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right)} \cdot \sin th \]
            6. Step-by-step derivation
              1. lift-pow.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              2. lift-sin.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              3. lift-sin.f64N/A

                \[\leadsto \left({\left(\mathsf{hypot}\left(\sin kx, \sin ky\right)\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              4. lift-hypot.f64N/A

                \[\leadsto \left({\left(\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}\right)}^{-1} \cdot \sin ky\right) \cdot \sin th \]
              5. unpow-1N/A

                \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              6. pow2N/A

                \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
              7. pow2N/A

                \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
              8. lower-/.f64N/A

                \[\leadsto \left(\frac{1}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
              9. pow2N/A

                \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + {\sin ky}^{2}}} \cdot \sin ky\right) \cdot \sin th \]
              10. pow2N/A

                \[\leadsto \left(\frac{1}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
              11. lift-hypot.f64N/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
              12. lift-sin.f64N/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
              13. lift-sin.f6499.3

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
            7. Applied rewrites99.3%

              \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin \color{blue}{ky}\right) \cdot \sin th \]
            8. Taylor expanded in th around 0

              \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
            9. Step-by-step derivation
              1. *-commutativeN/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \color{blue}{th}\right) \]
              2. lower-*.f64N/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot \color{blue}{th}\right) \]
              3. +-commutativeN/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot th\right) \]
              4. *-commutativeN/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\left({th}^{2} \cdot \frac{-1}{6} + 1\right) \cdot th\right) \]
              5. lower-fma.f64N/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right) \cdot th\right) \]
              6. unpow2N/A

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th\right) \]
              7. lower-*.f6454.1

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right) \]
            10. Applied rewrites54.1%

              \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot \color{blue}{\left(\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th\right)} \]
            11. Taylor expanded in th around 0

              \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot th \]
            12. Step-by-step derivation
              1. Applied rewrites54.6%

                \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sin ky\right) \cdot th \]

              if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

              1. Initial program 99.6%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. Add Preprocessing
              3. Taylor expanded in ky around 0

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
              4. Step-by-step derivation
                1. lift-sin.f64N/A

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                2. lift-pow.f6499.6

                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
              5. Applied rewrites99.6%

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
              6. Taylor expanded in ky around 0

                \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
              7. Step-by-step derivation
                1. Applied rewrites99.6%

                  \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

                if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                1. Initial program 99.1%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. Add Preprocessing
                3. Step-by-step derivation
                  1. lift-*.f64N/A

                    \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                  2. lift-/.f64N/A

                    \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  3. lift-sin.f64N/A

                    \[\leadsto \frac{\color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  4. lift-sqrt.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  5. lift-+.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  6. lift-pow.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                  7. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  8. lift-pow.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                  9. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                  10. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin th} \]
                  11. associate-*l/N/A

                    \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  12. lower-/.f64N/A

                    \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                  13. *-commutativeN/A

                    \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                  14. lower-*.f64N/A

                    \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                  15. lift-sin.f64N/A

                    \[\leadsto \frac{\color{blue}{\sin th} \cdot \sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                  16. lift-sin.f64N/A

                    \[\leadsto \frac{\sin th \cdot \color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                4. Applied rewrites99.2%

                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                5. Taylor expanded in th around 0

                  \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                6. Step-by-step derivation
                  1. lower-*.f64N/A

                    \[\leadsto \frac{th \cdot \color{blue}{\sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                  2. lift-sin.f6453.6

                    \[\leadsto \frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                7. Applied rewrites53.6%

                  \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
              8. Recombined 4 regimes into one program.
              9. Add Preprocessing

              Alternative 4: 86.4% accurate, 0.2× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\ t_2 := {\sin kx}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_3 \leq -0.995:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_3 \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_2}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 0.998:\\ \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
              (FPCore (kx ky th)
               :precision binary64
               (let* ((t_1 (* (/ (sin ky) (hypot (sin ky) kx)) (sin th)))
                      (t_2 (pow (sin kx) 2.0))
                      (t_3 (/ (sin ky) (sqrt (+ t_2 (pow (sin ky) 2.0))))))
                 (if (<= t_3 -0.995)
                   t_1
                   (if (<= t_3 -0.0005)
                     (* (/ (sin ky) (hypot (sin ky) (sin kx))) th)
                     (if (<= t_3 5e-9)
                       (* (/ ky (sqrt t_2)) (sin th))
                       (if (<= t_3 0.998)
                         (/ (* th (sin ky)) (hypot (sin kx) (sin ky)))
                         t_1))))))
              double code(double kx, double ky, double th) {
              	double t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
              	double t_2 = pow(sin(kx), 2.0);
              	double t_3 = sin(ky) / sqrt((t_2 + pow(sin(ky), 2.0)));
              	double tmp;
              	if (t_3 <= -0.995) {
              		tmp = t_1;
              	} else if (t_3 <= -0.0005) {
              		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
              	} else if (t_3 <= 5e-9) {
              		tmp = (ky / sqrt(t_2)) * sin(th);
              	} else if (t_3 <= 0.998) {
              		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              public static double code(double kx, double ky, double th) {
              	double t_1 = (Math.sin(ky) / Math.hypot(Math.sin(ky), kx)) * Math.sin(th);
              	double t_2 = Math.pow(Math.sin(kx), 2.0);
              	double t_3 = Math.sin(ky) / Math.sqrt((t_2 + Math.pow(Math.sin(ky), 2.0)));
              	double tmp;
              	if (t_3 <= -0.995) {
              		tmp = t_1;
              	} else if (t_3 <= -0.0005) {
              		tmp = (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * th;
              	} else if (t_3 <= 5e-9) {
              		tmp = (ky / Math.sqrt(t_2)) * Math.sin(th);
              	} else if (t_3 <= 0.998) {
              		tmp = (th * Math.sin(ky)) / Math.hypot(Math.sin(kx), Math.sin(ky));
              	} else {
              		tmp = t_1;
              	}
              	return tmp;
              }
              
              def code(kx, ky, th):
              	t_1 = (math.sin(ky) / math.hypot(math.sin(ky), kx)) * math.sin(th)
              	t_2 = math.pow(math.sin(kx), 2.0)
              	t_3 = math.sin(ky) / math.sqrt((t_2 + math.pow(math.sin(ky), 2.0)))
              	tmp = 0
              	if t_3 <= -0.995:
              		tmp = t_1
              	elif t_3 <= -0.0005:
              		tmp = (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * th
              	elif t_3 <= 5e-9:
              		tmp = (ky / math.sqrt(t_2)) * math.sin(th)
              	elif t_3 <= 0.998:
              		tmp = (th * math.sin(ky)) / math.hypot(math.sin(kx), math.sin(ky))
              	else:
              		tmp = t_1
              	return tmp
              
              function code(kx, ky, th)
              	t_1 = Float64(Float64(sin(ky) / hypot(sin(ky), kx)) * sin(th))
              	t_2 = sin(kx) ^ 2.0
              	t_3 = Float64(sin(ky) / sqrt(Float64(t_2 + (sin(ky) ^ 2.0))))
              	tmp = 0.0
              	if (t_3 <= -0.995)
              		tmp = t_1;
              	elseif (t_3 <= -0.0005)
              		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * th);
              	elseif (t_3 <= 5e-9)
              		tmp = Float64(Float64(ky / sqrt(t_2)) * sin(th));
              	elseif (t_3 <= 0.998)
              		tmp = Float64(Float64(th * sin(ky)) / hypot(sin(kx), sin(ky)));
              	else
              		tmp = t_1;
              	end
              	return tmp
              end
              
              function tmp_2 = code(kx, ky, th)
              	t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
              	t_2 = sin(kx) ^ 2.0;
              	t_3 = sin(ky) / sqrt((t_2 + (sin(ky) ^ 2.0)));
              	tmp = 0.0;
              	if (t_3 <= -0.995)
              		tmp = t_1;
              	elseif (t_3 <= -0.0005)
              		tmp = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
              	elseif (t_3 <= 5e-9)
              		tmp = (ky / sqrt(t_2)) * sin(th);
              	elseif (t_3 <= 0.998)
              		tmp = (th * sin(ky)) / hypot(sin(kx), sin(ky));
              	else
              		tmp = t_1;
              	end
              	tmp_2 = tmp;
              end
              
              code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.995], t$95$1, If[LessEqual[t$95$3, -0.0005], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$3, 5e-9], N[(N[(ky / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.998], N[(N[(th * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\
              t_2 := {\sin kx}^{2}\\
              t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\
              \mathbf{if}\;t\_3 \leq -0.995:\\
              \;\;\;\;t\_1\\
              
              \mathbf{elif}\;t\_3 \leq -0.0005:\\
              \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\
              
              \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\
              \;\;\;\;\frac{ky}{\sqrt{t\_2}} \cdot \sin th\\
              
              \mathbf{elif}\;t\_3 \leq 0.998:\\
              \;\;\;\;\frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
              
              \mathbf{else}:\\
              \;\;\;\;t\_1\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 4 regimes
              2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.994999999999999996 or 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                1. Initial program 86.2%

                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                2. Add Preprocessing
                3. Step-by-step derivation
                  1. lift-sqrt.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  2. lift-+.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  3. lift-pow.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                  4. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  5. lift-pow.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                  6. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                  7. +-commutativeN/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                  8. unpow2N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                  9. unpow2N/A

                    \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                  10. lower-hypot.f64N/A

                    \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                  11. lift-sin.f64N/A

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
                  12. lift-sin.f6499.9

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
                4. Applied rewrites99.9%

                  \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                5. Taylor expanded in kx around 0

                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
                6. Step-by-step derivation
                  1. Applied rewrites97.3%

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]

                  if -0.994999999999999996 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

                  1. Initial program 99.5%

                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  2. Add Preprocessing
                  3. Step-by-step derivation
                    1. lift-sqrt.f64N/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                    2. lift-+.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                    3. lift-pow.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                    4. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    5. lift-pow.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                    6. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                    7. +-commutativeN/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                    8. unpow2N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                    9. unpow2N/A

                      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                    10. lower-hypot.f64N/A

                      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                    11. lift-sin.f64N/A

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
                    12. lift-sin.f6499.4

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
                  4. Applied rewrites99.4%

                    \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                  5. Taylor expanded in th around 0

                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{th} \]
                  6. Step-by-step derivation
                    1. Applied rewrites54.6%

                      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{th} \]

                    if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                    1. Initial program 99.6%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. Add Preprocessing
                    3. Taylor expanded in ky around 0

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                    4. Step-by-step derivation
                      1. lift-sin.f64N/A

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                      2. lift-pow.f6499.6

                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                    5. Applied rewrites99.6%

                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                    6. Taylor expanded in ky around 0

                      \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                    7. Step-by-step derivation
                      1. Applied rewrites99.6%

                        \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

                      if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                      1. Initial program 99.1%

                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift-*.f64N/A

                          \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
                        2. lift-/.f64N/A

                          \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        3. lift-sin.f64N/A

                          \[\leadsto \frac{\color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        4. lift-sqrt.f64N/A

                          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        5. lift-+.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        6. lift-pow.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                        7. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        8. lift-pow.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                        9. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                        10. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\sin th} \]
                        11. associate-*l/N/A

                          \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                        12. lower-/.f64N/A

                          \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
                        13. *-commutativeN/A

                          \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                        14. lower-*.f64N/A

                          \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                        15. lift-sin.f64N/A

                          \[\leadsto \frac{\color{blue}{\sin th} \cdot \sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                        16. lift-sin.f64N/A

                          \[\leadsto \frac{\sin th \cdot \color{blue}{\sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
                      4. Applied rewrites99.2%

                        \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
                      5. Taylor expanded in th around 0

                        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                      6. Step-by-step derivation
                        1. lower-*.f64N/A

                          \[\leadsto \frac{th \cdot \color{blue}{\sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                        2. lift-sin.f6453.6

                          \[\leadsto \frac{th \cdot \sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                      7. Applied rewrites53.6%

                        \[\leadsto \frac{\color{blue}{th \cdot \sin ky}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                    8. Recombined 4 regimes into one program.
                    9. Add Preprocessing

                    Alternative 5: 86.4% accurate, 0.2× speedup?

                    \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\ t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ t_3 := {\sin kx}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_4 \leq -0.995:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq -0.0005:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_3}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq 0.998:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
                    (FPCore (kx ky th)
                     :precision binary64
                     (let* ((t_1 (* (/ (sin ky) (hypot (sin ky) kx)) (sin th)))
                            (t_2 (* (/ (sin ky) (hypot (sin ky) (sin kx))) th))
                            (t_3 (pow (sin kx) 2.0))
                            (t_4 (/ (sin ky) (sqrt (+ t_3 (pow (sin ky) 2.0))))))
                       (if (<= t_4 -0.995)
                         t_1
                         (if (<= t_4 -0.0005)
                           t_2
                           (if (<= t_4 5e-9)
                             (* (/ ky (sqrt t_3)) (sin th))
                             (if (<= t_4 0.998) t_2 t_1))))))
                    double code(double kx, double ky, double th) {
                    	double t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
                    	double t_2 = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
                    	double t_3 = pow(sin(kx), 2.0);
                    	double t_4 = sin(ky) / sqrt((t_3 + pow(sin(ky), 2.0)));
                    	double tmp;
                    	if (t_4 <= -0.995) {
                    		tmp = t_1;
                    	} else if (t_4 <= -0.0005) {
                    		tmp = t_2;
                    	} else if (t_4 <= 5e-9) {
                    		tmp = (ky / sqrt(t_3)) * sin(th);
                    	} else if (t_4 <= 0.998) {
                    		tmp = t_2;
                    	} else {
                    		tmp = t_1;
                    	}
                    	return tmp;
                    }
                    
                    public static double code(double kx, double ky, double th) {
                    	double t_1 = (Math.sin(ky) / Math.hypot(Math.sin(ky), kx)) * Math.sin(th);
                    	double t_2 = (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx))) * th;
                    	double t_3 = Math.pow(Math.sin(kx), 2.0);
                    	double t_4 = Math.sin(ky) / Math.sqrt((t_3 + Math.pow(Math.sin(ky), 2.0)));
                    	double tmp;
                    	if (t_4 <= -0.995) {
                    		tmp = t_1;
                    	} else if (t_4 <= -0.0005) {
                    		tmp = t_2;
                    	} else if (t_4 <= 5e-9) {
                    		tmp = (ky / Math.sqrt(t_3)) * Math.sin(th);
                    	} else if (t_4 <= 0.998) {
                    		tmp = t_2;
                    	} else {
                    		tmp = t_1;
                    	}
                    	return tmp;
                    }
                    
                    def code(kx, ky, th):
                    	t_1 = (math.sin(ky) / math.hypot(math.sin(ky), kx)) * math.sin(th)
                    	t_2 = (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx))) * th
                    	t_3 = math.pow(math.sin(kx), 2.0)
                    	t_4 = math.sin(ky) / math.sqrt((t_3 + math.pow(math.sin(ky), 2.0)))
                    	tmp = 0
                    	if t_4 <= -0.995:
                    		tmp = t_1
                    	elif t_4 <= -0.0005:
                    		tmp = t_2
                    	elif t_4 <= 5e-9:
                    		tmp = (ky / math.sqrt(t_3)) * math.sin(th)
                    	elif t_4 <= 0.998:
                    		tmp = t_2
                    	else:
                    		tmp = t_1
                    	return tmp
                    
                    function code(kx, ky, th)
                    	t_1 = Float64(Float64(sin(ky) / hypot(sin(ky), kx)) * sin(th))
                    	t_2 = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * th)
                    	t_3 = sin(kx) ^ 2.0
                    	t_4 = Float64(sin(ky) / sqrt(Float64(t_3 + (sin(ky) ^ 2.0))))
                    	tmp = 0.0
                    	if (t_4 <= -0.995)
                    		tmp = t_1;
                    	elseif (t_4 <= -0.0005)
                    		tmp = t_2;
                    	elseif (t_4 <= 5e-9)
                    		tmp = Float64(Float64(ky / sqrt(t_3)) * sin(th));
                    	elseif (t_4 <= 0.998)
                    		tmp = t_2;
                    	else
                    		tmp = t_1;
                    	end
                    	return tmp
                    end
                    
                    function tmp_2 = code(kx, ky, th)
                    	t_1 = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
                    	t_2 = (sin(ky) / hypot(sin(ky), sin(kx))) * th;
                    	t_3 = sin(kx) ^ 2.0;
                    	t_4 = sin(ky) / sqrt((t_3 + (sin(ky) ^ 2.0)));
                    	tmp = 0.0;
                    	if (t_4 <= -0.995)
                    		tmp = t_1;
                    	elseif (t_4 <= -0.0005)
                    		tmp = t_2;
                    	elseif (t_4 <= 5e-9)
                    		tmp = (ky / sqrt(t_3)) * sin(th);
                    	elseif (t_4 <= 0.998)
                    		tmp = t_2;
                    	else
                    		tmp = t_1;
                    	end
                    	tmp_2 = tmp;
                    end
                    
                    code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$3 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.995], t$95$1, If[LessEqual[t$95$4, -0.0005], t$95$2, If[LessEqual[t$95$4, 5e-9], N[(N[(ky / N[Sqrt[t$95$3], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.998], t$95$2, t$95$1]]]]]]]]
                    
                    \begin{array}{l}
                    
                    \\
                    \begin{array}{l}
                    t_1 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\
                    t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\
                    t_3 := {\sin kx}^{2}\\
                    t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\
                    \mathbf{if}\;t\_4 \leq -0.995:\\
                    \;\;\;\;t\_1\\
                    
                    \mathbf{elif}\;t\_4 \leq -0.0005:\\
                    \;\;\;\;t\_2\\
                    
                    \mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-9}:\\
                    \;\;\;\;\frac{ky}{\sqrt{t\_3}} \cdot \sin th\\
                    
                    \mathbf{elif}\;t\_4 \leq 0.998:\\
                    \;\;\;\;t\_2\\
                    
                    \mathbf{else}:\\
                    \;\;\;\;t\_1\\
                    
                    
                    \end{array}
                    \end{array}
                    
                    Derivation
                    1. Split input into 3 regimes
                    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.994999999999999996 or 0.998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                      1. Initial program 86.2%

                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                      2. Add Preprocessing
                      3. Step-by-step derivation
                        1. lift-sqrt.f64N/A

                          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        2. lift-+.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        3. lift-pow.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                        4. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        5. lift-pow.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                        6. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                        7. +-commutativeN/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                        8. unpow2N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                        9. unpow2N/A

                          \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                        10. lower-hypot.f64N/A

                          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                        11. lift-sin.f64N/A

                          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
                        12. lift-sin.f6499.9

                          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
                      4. Applied rewrites99.9%

                        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                      5. Taylor expanded in kx around 0

                        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
                      6. Step-by-step derivation
                        1. Applied rewrites97.3%

                          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]

                        if -0.994999999999999996 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4 or 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                        1. Initial program 99.3%

                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        2. Add Preprocessing
                        3. Step-by-step derivation
                          1. lift-sqrt.f64N/A

                            \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                          2. lift-+.f64N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                          3. lift-pow.f64N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                          4. lift-sin.f64N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                          5. lift-pow.f64N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                          6. lift-sin.f64N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                          7. +-commutativeN/A

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                          8. unpow2N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                          9. unpow2N/A

                            \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                          10. lower-hypot.f64N/A

                            \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                          11. lift-sin.f64N/A

                            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
                          12. lift-sin.f6499.3

                            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
                        4. Applied rewrites99.3%

                          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                        5. Taylor expanded in th around 0

                          \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{th} \]
                        6. Step-by-step derivation
                          1. Applied rewrites54.0%

                            \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{th} \]

                          if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                          1. Initial program 99.6%

                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                          2. Add Preprocessing
                          3. Taylor expanded in ky around 0

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                          4. Step-by-step derivation
                            1. lift-sin.f64N/A

                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                            2. lift-pow.f6499.6

                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                          5. Applied rewrites99.6%

                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                          6. Taylor expanded in ky around 0

                            \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                          7. Step-by-step derivation
                            1. Applied rewrites99.6%

                              \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                          8. Recombined 3 regimes into one program.
                          9. Add Preprocessing

                          Alternative 6: 44.2% accurate, 0.3× speedup?

                          \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                          (FPCore (kx ky th)
                           :precision binary64
                           (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                             (if (<= t_1 -0.0005)
                               (* (/ (sin ky) (sqrt (- 0.5 (* 0.5 (cos (+ kx kx)))))) th)
                               (if (or (<= t_1 5e-9) (not (<= t_1 2.0)))
                                 (* (/ ky (sin kx)) (sin th))
                                 (sin th)))))
                          double code(double kx, double ky, double th) {
                          	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                          	double tmp;
                          	if (t_1 <= -0.0005) {
                          		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * th;
                          	} else if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                          		tmp = (ky / sin(kx)) * sin(th);
                          	} else {
                          		tmp = sin(th);
                          	}
                          	return tmp;
                          }
                          
                          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(8) function code(kx, ky, th)
                          use fmin_fmax_functions
                              real(8), intent (in) :: kx
                              real(8), intent (in) :: ky
                              real(8), intent (in) :: th
                              real(8) :: t_1
                              real(8) :: tmp
                              t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                              if (t_1 <= (-0.0005d0)) then
                                  tmp = (sin(ky) / sqrt((0.5d0 - (0.5d0 * cos((kx + kx)))))) * th
                              else if ((t_1 <= 5d-9) .or. (.not. (t_1 <= 2.0d0))) then
                                  tmp = (ky / sin(kx)) * sin(th)
                              else
                                  tmp = sin(th)
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double kx, double ky, double th) {
                          	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                          	double tmp;
                          	if (t_1 <= -0.0005) {
                          		tmp = (Math.sin(ky) / Math.sqrt((0.5 - (0.5 * Math.cos((kx + kx)))))) * th;
                          	} else if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                          		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                          	} else {
                          		tmp = Math.sin(th);
                          	}
                          	return tmp;
                          }
                          
                          def code(kx, ky, th):
                          	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                          	tmp = 0
                          	if t_1 <= -0.0005:
                          		tmp = (math.sin(ky) / math.sqrt((0.5 - (0.5 * math.cos((kx + kx)))))) * th
                          	elif (t_1 <= 5e-9) or not (t_1 <= 2.0):
                          		tmp = (ky / math.sin(kx)) * math.sin(th)
                          	else:
                          		tmp = math.sin(th)
                          	return tmp
                          
                          function code(kx, ky, th)
                          	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                          	tmp = 0.0
                          	if (t_1 <= -0.0005)
                          		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx + kx)))))) * th);
                          	elseif ((t_1 <= 5e-9) || !(t_1 <= 2.0))
                          		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                          	else
                          		tmp = sin(th);
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(kx, ky, th)
                          	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                          	tmp = 0.0;
                          	if (t_1 <= -0.0005)
                          		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * th;
                          	elseif ((t_1 <= 5e-9) || ~((t_1 <= 2.0)))
                          		tmp = (ky / sin(kx)) * sin(th);
                          	else
                          		tmp = sin(th);
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.0005], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[Or[LessEqual[t$95$1, 5e-9], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
                          
                          \begin{array}{l}
                          
                          \\
                          \begin{array}{l}
                          t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                          \mathbf{if}\;t\_1 \leq -0.0005:\\
                          \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th\\
                          
                          \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\
                          \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\sin th\\
                          
                          
                          \end{array}
                          \end{array}
                          
                          Derivation
                          1. Split input into 3 regimes
                          2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

                            1. Initial program 93.8%

                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                            2. Add Preprocessing
                            3. Taylor expanded in ky around 0

                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                            4. Step-by-step derivation
                              1. lift-sin.f64N/A

                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                              2. lift-pow.f6411.7

                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                            5. Applied rewrites11.7%

                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                            6. Taylor expanded in th around 0

                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                            7. Step-by-step derivation
                              1. Applied rewrites7.7%

                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                              2. Step-by-step derivation
                                1. lift-pow.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot th \]
                                2. lift-sin.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot th \]
                                3. pow2N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx}}} \cdot th \]
                                4. sqr-sin-aN/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot th \]
                                5. lower--.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot th \]
                                6. lower-*.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot kx\right)}}} \cdot th \]
                                7. cos-2N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \left(\cos kx \cdot \cos kx - \color{blue}{\sin kx \cdot \sin kx}\right)}} \cdot th \]
                                8. cos-sumN/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot th \]
                                9. lower-cos.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot th \]
                                10. lower-+.f646.8

                                  \[\leadsto \frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th \]
                              3. Applied rewrites6.8%

                                \[\leadsto \frac{\sin ky}{\sqrt{0.5 - \color{blue}{0.5 \cdot \cos \left(kx + kx\right)}}} \cdot th \]

                              if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                              1. Initial program 88.9%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. Add Preprocessing
                              3. Taylor expanded in ky around 0

                                \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                              4. Step-by-step derivation
                                1. lower-/.f64N/A

                                  \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                2. lift-sin.f6463.3

                                  \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                              5. Applied rewrites63.3%

                                \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

                              if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                              1. Initial program 99.0%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. Add Preprocessing
                              3. Taylor expanded in kx around 0

                                \[\leadsto \color{blue}{\sin th} \]
                              4. Step-by-step derivation
                                1. lift-sin.f6467.3

                                  \[\leadsto \sin th \]
                              5. Applied rewrites67.3%

                                \[\leadsto \color{blue}{\sin th} \]
                            8. Recombined 3 regimes into one program.
                            9. Final simplification46.5%

                              \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9} \lor \neg \left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2\right):\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                            10. Add Preprocessing

                            Alternative 7: 64.5% accurate, 0.3× speedup?

                            \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := {\sin ky}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\ \mathbf{if}\;t\_3 \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot th\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \end{array} \end{array} \]
                            (FPCore (kx ky th)
                             :precision binary64
                             (let* ((t_1 (pow (sin kx) 2.0))
                                    (t_2 (pow (sin ky) 2.0))
                                    (t_3 (/ (sin ky) (sqrt (+ t_1 t_2)))))
                               (if (<= t_3 -0.0005)
                                 (* (/ (sin ky) (sqrt t_2)) th)
                                 (if (<= t_3 5e-9)
                                   (* (/ ky (sqrt t_1)) (sin th))
                                   (if (<= t_3 2.0) (sin th) (* (/ ky (sin kx)) (sin th)))))))
                            double code(double kx, double ky, double th) {
                            	double t_1 = pow(sin(kx), 2.0);
                            	double t_2 = pow(sin(ky), 2.0);
                            	double t_3 = sin(ky) / sqrt((t_1 + t_2));
                            	double tmp;
                            	if (t_3 <= -0.0005) {
                            		tmp = (sin(ky) / sqrt(t_2)) * th;
                            	} else if (t_3 <= 5e-9) {
                            		tmp = (ky / sqrt(t_1)) * sin(th);
                            	} else if (t_3 <= 2.0) {
                            		tmp = sin(th);
                            	} else {
                            		tmp = (ky / sin(kx)) * sin(th);
                            	}
                            	return tmp;
                            }
                            
                            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(8) function code(kx, ky, th)
                            use fmin_fmax_functions
                                real(8), intent (in) :: kx
                                real(8), intent (in) :: ky
                                real(8), intent (in) :: th
                                real(8) :: t_1
                                real(8) :: t_2
                                real(8) :: t_3
                                real(8) :: tmp
                                t_1 = sin(kx) ** 2.0d0
                                t_2 = sin(ky) ** 2.0d0
                                t_3 = sin(ky) / sqrt((t_1 + t_2))
                                if (t_3 <= (-0.0005d0)) then
                                    tmp = (sin(ky) / sqrt(t_2)) * th
                                else if (t_3 <= 5d-9) then
                                    tmp = (ky / sqrt(t_1)) * sin(th)
                                else if (t_3 <= 2.0d0) then
                                    tmp = sin(th)
                                else
                                    tmp = (ky / sin(kx)) * sin(th)
                                end if
                                code = tmp
                            end function
                            
                            public static double code(double kx, double ky, double th) {
                            	double t_1 = Math.pow(Math.sin(kx), 2.0);
                            	double t_2 = Math.pow(Math.sin(ky), 2.0);
                            	double t_3 = Math.sin(ky) / Math.sqrt((t_1 + t_2));
                            	double tmp;
                            	if (t_3 <= -0.0005) {
                            		tmp = (Math.sin(ky) / Math.sqrt(t_2)) * th;
                            	} else if (t_3 <= 5e-9) {
                            		tmp = (ky / Math.sqrt(t_1)) * Math.sin(th);
                            	} else if (t_3 <= 2.0) {
                            		tmp = Math.sin(th);
                            	} else {
                            		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                            	}
                            	return tmp;
                            }
                            
                            def code(kx, ky, th):
                            	t_1 = math.pow(math.sin(kx), 2.0)
                            	t_2 = math.pow(math.sin(ky), 2.0)
                            	t_3 = math.sin(ky) / math.sqrt((t_1 + t_2))
                            	tmp = 0
                            	if t_3 <= -0.0005:
                            		tmp = (math.sin(ky) / math.sqrt(t_2)) * th
                            	elif t_3 <= 5e-9:
                            		tmp = (ky / math.sqrt(t_1)) * math.sin(th)
                            	elif t_3 <= 2.0:
                            		tmp = math.sin(th)
                            	else:
                            		tmp = (ky / math.sin(kx)) * math.sin(th)
                            	return tmp
                            
                            function code(kx, ky, th)
                            	t_1 = sin(kx) ^ 2.0
                            	t_2 = sin(ky) ^ 2.0
                            	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + t_2)))
                            	tmp = 0.0
                            	if (t_3 <= -0.0005)
                            		tmp = Float64(Float64(sin(ky) / sqrt(t_2)) * th);
                            	elseif (t_3 <= 5e-9)
                            		tmp = Float64(Float64(ky / sqrt(t_1)) * sin(th));
                            	elseif (t_3 <= 2.0)
                            		tmp = sin(th);
                            	else
                            		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                            	end
                            	return tmp
                            end
                            
                            function tmp_2 = code(kx, ky, th)
                            	t_1 = sin(kx) ^ 2.0;
                            	t_2 = sin(ky) ^ 2.0;
                            	t_3 = sin(ky) / sqrt((t_1 + t_2));
                            	tmp = 0.0;
                            	if (t_3 <= -0.0005)
                            		tmp = (sin(ky) / sqrt(t_2)) * th;
                            	elseif (t_3 <= 5e-9)
                            		tmp = (ky / sqrt(t_1)) * sin(th);
                            	elseif (t_3 <= 2.0)
                            		tmp = sin(th);
                            	else
                            		tmp = (ky / sin(kx)) * sin(th);
                            	end
                            	tmp_2 = tmp;
                            end
                            
                            code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.0005], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$3, 5e-9], N[(N[(ky / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[Sin[th], $MachinePrecision], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]
                            
                            \begin{array}{l}
                            
                            \\
                            \begin{array}{l}
                            t_1 := {\sin kx}^{2}\\
                            t_2 := {\sin ky}^{2}\\
                            t_3 := \frac{\sin ky}{\sqrt{t\_1 + t\_2}}\\
                            \mathbf{if}\;t\_3 \leq -0.0005:\\
                            \;\;\;\;\frac{\sin ky}{\sqrt{t\_2}} \cdot th\\
                            
                            \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\
                            \;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\
                            
                            \mathbf{elif}\;t\_3 \leq 2:\\
                            \;\;\;\;\sin th\\
                            
                            \mathbf{else}:\\
                            \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                            
                            
                            \end{array}
                            \end{array}
                            
                            Derivation
                            1. Split input into 4 regimes
                            2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

                              1. Initial program 93.8%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. Add Preprocessing
                              3. Taylor expanded in ky around 0

                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                              4. Step-by-step derivation
                                1. lift-sin.f64N/A

                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                2. lift-pow.f6411.7

                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                              5. Applied rewrites11.7%

                                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                              6. Taylor expanded in th around 0

                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                              7. Step-by-step derivation
                                1. Applied rewrites7.7%

                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                2. Taylor expanded in kx around 0

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot th \]
                                3. Step-by-step derivation
                                  1. lower-pow.f64N/A

                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \cdot th \]
                                  2. lift-sin.f6431.2

                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot th \]
                                4. Applied rewrites31.2%

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \cdot th \]

                                if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                1. Initial program 99.6%

                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                2. Add Preprocessing
                                3. Taylor expanded in ky around 0

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                4. Step-by-step derivation
                                  1. lift-sin.f64N/A

                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                  2. lift-pow.f6499.6

                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                5. Applied rewrites99.6%

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                6. Taylor expanded in ky around 0

                                  \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                7. Step-by-step derivation
                                  1. Applied rewrites99.6%

                                    \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

                                  if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                  1. Initial program 99.0%

                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in kx around 0

                                    \[\leadsto \color{blue}{\sin th} \]
                                  4. Step-by-step derivation
                                    1. lift-sin.f6467.3

                                      \[\leadsto \sin th \]
                                  5. Applied rewrites67.3%

                                    \[\leadsto \color{blue}{\sin th} \]

                                  if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                  1. Initial program 2.6%

                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in ky around 0

                                    \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                  4. Step-by-step derivation
                                    1. lower-/.f64N/A

                                      \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                    2. lift-sin.f6431.9

                                      \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                                  5. Applied rewrites31.9%

                                    \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                8. Recombined 4 regimes into one program.
                                9. Add Preprocessing

                                Alternative 8: 56.7% accurate, 0.3× speedup?

                                \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \sqrt{t\_1}\\ t_3 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_3 \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{t\_2} \cdot th\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{t\_2} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \end{array} \end{array} \]
                                (FPCore (kx ky th)
                                 :precision binary64
                                 (let* ((t_1 (pow (sin kx) 2.0))
                                        (t_2 (sqrt t_1))
                                        (t_3 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                                   (if (<= t_3 -0.0005)
                                     (* (/ (sin ky) t_2) th)
                                     (if (<= t_3 5e-9)
                                       (* (/ ky t_2) (sin th))
                                       (if (<= t_3 2.0) (sin th) (* (/ ky (sin kx)) (sin th)))))))
                                double code(double kx, double ky, double th) {
                                	double t_1 = pow(sin(kx), 2.0);
                                	double t_2 = sqrt(t_1);
                                	double t_3 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
                                	double tmp;
                                	if (t_3 <= -0.0005) {
                                		tmp = (sin(ky) / t_2) * th;
                                	} else if (t_3 <= 5e-9) {
                                		tmp = (ky / t_2) * sin(th);
                                	} else if (t_3 <= 2.0) {
                                		tmp = sin(th);
                                	} else {
                                		tmp = (ky / sin(kx)) * sin(th);
                                	}
                                	return tmp;
                                }
                                
                                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(8) function code(kx, ky, th)
                                use fmin_fmax_functions
                                    real(8), intent (in) :: kx
                                    real(8), intent (in) :: ky
                                    real(8), intent (in) :: th
                                    real(8) :: t_1
                                    real(8) :: t_2
                                    real(8) :: t_3
                                    real(8) :: tmp
                                    t_1 = sin(kx) ** 2.0d0
                                    t_2 = sqrt(t_1)
                                    t_3 = sin(ky) / sqrt((t_1 + (sin(ky) ** 2.0d0)))
                                    if (t_3 <= (-0.0005d0)) then
                                        tmp = (sin(ky) / t_2) * th
                                    else if (t_3 <= 5d-9) then
                                        tmp = (ky / t_2) * sin(th)
                                    else if (t_3 <= 2.0d0) then
                                        tmp = sin(th)
                                    else
                                        tmp = (ky / sin(kx)) * sin(th)
                                    end if
                                    code = tmp
                                end function
                                
                                public static double code(double kx, double ky, double th) {
                                	double t_1 = Math.pow(Math.sin(kx), 2.0);
                                	double t_2 = Math.sqrt(t_1);
                                	double t_3 = Math.sin(ky) / Math.sqrt((t_1 + Math.pow(Math.sin(ky), 2.0)));
                                	double tmp;
                                	if (t_3 <= -0.0005) {
                                		tmp = (Math.sin(ky) / t_2) * th;
                                	} else if (t_3 <= 5e-9) {
                                		tmp = (ky / t_2) * Math.sin(th);
                                	} else if (t_3 <= 2.0) {
                                		tmp = Math.sin(th);
                                	} else {
                                		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                                	}
                                	return tmp;
                                }
                                
                                def code(kx, ky, th):
                                	t_1 = math.pow(math.sin(kx), 2.0)
                                	t_2 = math.sqrt(t_1)
                                	t_3 = math.sin(ky) / math.sqrt((t_1 + math.pow(math.sin(ky), 2.0)))
                                	tmp = 0
                                	if t_3 <= -0.0005:
                                		tmp = (math.sin(ky) / t_2) * th
                                	elif t_3 <= 5e-9:
                                		tmp = (ky / t_2) * math.sin(th)
                                	elif t_3 <= 2.0:
                                		tmp = math.sin(th)
                                	else:
                                		tmp = (ky / math.sin(kx)) * math.sin(th)
                                	return tmp
                                
                                function code(kx, ky, th)
                                	t_1 = sin(kx) ^ 2.0
                                	t_2 = sqrt(t_1)
                                	t_3 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
                                	tmp = 0.0
                                	if (t_3 <= -0.0005)
                                		tmp = Float64(Float64(sin(ky) / t_2) * th);
                                	elseif (t_3 <= 5e-9)
                                		tmp = Float64(Float64(ky / t_2) * sin(th));
                                	elseif (t_3 <= 2.0)
                                		tmp = sin(th);
                                	else
                                		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(kx, ky, th)
                                	t_1 = sin(kx) ^ 2.0;
                                	t_2 = sqrt(t_1);
                                	t_3 = sin(ky) / sqrt((t_1 + (sin(ky) ^ 2.0)));
                                	tmp = 0.0;
                                	if (t_3 <= -0.0005)
                                		tmp = (sin(ky) / t_2) * th;
                                	elseif (t_3 <= 5e-9)
                                		tmp = (ky / t_2) * sin(th);
                                	elseif (t_3 <= 2.0)
                                		tmp = sin(th);
                                	else
                                		tmp = (ky / sin(kx)) * sin(th);
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.0005], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$2), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$3, 5e-9], N[(N[(ky / t$95$2), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[Sin[th], $MachinePrecision], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]]
                                
                                \begin{array}{l}
                                
                                \\
                                \begin{array}{l}
                                t_1 := {\sin kx}^{2}\\
                                t_2 := \sqrt{t\_1}\\
                                t_3 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
                                \mathbf{if}\;t\_3 \leq -0.0005:\\
                                \;\;\;\;\frac{\sin ky}{t\_2} \cdot th\\
                                
                                \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-9}:\\
                                \;\;\;\;\frac{ky}{t\_2} \cdot \sin th\\
                                
                                \mathbf{elif}\;t\_3 \leq 2:\\
                                \;\;\;\;\sin th\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                                
                                
                                \end{array}
                                \end{array}
                                
                                Derivation
                                1. Split input into 4 regimes
                                2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

                                  1. Initial program 93.8%

                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                  2. Add Preprocessing
                                  3. Taylor expanded in ky around 0

                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                  4. Step-by-step derivation
                                    1. lift-sin.f64N/A

                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                    2. lift-pow.f6411.7

                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                  5. Applied rewrites11.7%

                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                  6. Taylor expanded in th around 0

                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                  7. Step-by-step derivation
                                    1. Applied rewrites7.7%

                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]

                                    if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                    1. Initial program 99.6%

                                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                    2. Add Preprocessing
                                    3. Taylor expanded in ky around 0

                                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                    4. Step-by-step derivation
                                      1. lift-sin.f64N/A

                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                      2. lift-pow.f6499.6

                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                    5. Applied rewrites99.6%

                                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                    6. Taylor expanded in ky around 0

                                      \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                    7. Step-by-step derivation
                                      1. Applied rewrites99.6%

                                        \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

                                      if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                      1. Initial program 99.0%

                                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in kx around 0

                                        \[\leadsto \color{blue}{\sin th} \]
                                      4. Step-by-step derivation
                                        1. lift-sin.f6467.3

                                          \[\leadsto \sin th \]
                                      5. Applied rewrites67.3%

                                        \[\leadsto \color{blue}{\sin th} \]

                                      if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                      1. Initial program 2.6%

                                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in ky around 0

                                        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                      4. Step-by-step derivation
                                        1. lower-/.f64N/A

                                          \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                        2. lift-sin.f6431.9

                                          \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                                      5. Applied rewrites31.9%

                                        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                    8. Recombined 4 regimes into one program.
                                    9. Add Preprocessing

                                    Alternative 9: 56.5% accurate, 0.3× speedup?

                                    \[\begin{array}{l} \\ \begin{array}{l} t_1 := {\sin kx}^{2}\\ t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -0.0005:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th\\ \mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \end{array} \end{array} \]
                                    (FPCore (kx ky th)
                                     :precision binary64
                                     (let* ((t_1 (pow (sin kx) 2.0))
                                            (t_2 (/ (sin ky) (sqrt (+ t_1 (pow (sin ky) 2.0))))))
                                       (if (<= t_2 -0.0005)
                                         (* (/ (sin ky) (sqrt (- 0.5 (* 0.5 (cos (+ kx kx)))))) th)
                                         (if (<= t_2 5e-9)
                                           (* (/ ky (sqrt t_1)) (sin th))
                                           (if (<= t_2 2.0) (sin th) (* (/ ky (sin kx)) (sin th)))))))
                                    double code(double kx, double ky, double th) {
                                    	double t_1 = pow(sin(kx), 2.0);
                                    	double t_2 = sin(ky) / sqrt((t_1 + pow(sin(ky), 2.0)));
                                    	double tmp;
                                    	if (t_2 <= -0.0005) {
                                    		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * th;
                                    	} else if (t_2 <= 5e-9) {
                                    		tmp = (ky / sqrt(t_1)) * sin(th);
                                    	} else if (t_2 <= 2.0) {
                                    		tmp = sin(th);
                                    	} else {
                                    		tmp = (ky / sin(kx)) * sin(th);
                                    	}
                                    	return tmp;
                                    }
                                    
                                    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(8) function code(kx, ky, th)
                                    use fmin_fmax_functions
                                        real(8), intent (in) :: kx
                                        real(8), intent (in) :: ky
                                        real(8), intent (in) :: th
                                        real(8) :: t_1
                                        real(8) :: t_2
                                        real(8) :: tmp
                                        t_1 = sin(kx) ** 2.0d0
                                        t_2 = sin(ky) / sqrt((t_1 + (sin(ky) ** 2.0d0)))
                                        if (t_2 <= (-0.0005d0)) then
                                            tmp = (sin(ky) / sqrt((0.5d0 - (0.5d0 * cos((kx + kx)))))) * th
                                        else if (t_2 <= 5d-9) then
                                            tmp = (ky / sqrt(t_1)) * sin(th)
                                        else if (t_2 <= 2.0d0) then
                                            tmp = sin(th)
                                        else
                                            tmp = (ky / sin(kx)) * sin(th)
                                        end if
                                        code = tmp
                                    end function
                                    
                                    public static double code(double kx, double ky, double th) {
                                    	double t_1 = Math.pow(Math.sin(kx), 2.0);
                                    	double t_2 = Math.sin(ky) / Math.sqrt((t_1 + Math.pow(Math.sin(ky), 2.0)));
                                    	double tmp;
                                    	if (t_2 <= -0.0005) {
                                    		tmp = (Math.sin(ky) / Math.sqrt((0.5 - (0.5 * Math.cos((kx + kx)))))) * th;
                                    	} else if (t_2 <= 5e-9) {
                                    		tmp = (ky / Math.sqrt(t_1)) * Math.sin(th);
                                    	} else if (t_2 <= 2.0) {
                                    		tmp = Math.sin(th);
                                    	} else {
                                    		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                                    	}
                                    	return tmp;
                                    }
                                    
                                    def code(kx, ky, th):
                                    	t_1 = math.pow(math.sin(kx), 2.0)
                                    	t_2 = math.sin(ky) / math.sqrt((t_1 + math.pow(math.sin(ky), 2.0)))
                                    	tmp = 0
                                    	if t_2 <= -0.0005:
                                    		tmp = (math.sin(ky) / math.sqrt((0.5 - (0.5 * math.cos((kx + kx)))))) * th
                                    	elif t_2 <= 5e-9:
                                    		tmp = (ky / math.sqrt(t_1)) * math.sin(th)
                                    	elif t_2 <= 2.0:
                                    		tmp = math.sin(th)
                                    	else:
                                    		tmp = (ky / math.sin(kx)) * math.sin(th)
                                    	return tmp
                                    
                                    function code(kx, ky, th)
                                    	t_1 = sin(kx) ^ 2.0
                                    	t_2 = Float64(sin(ky) / sqrt(Float64(t_1 + (sin(ky) ^ 2.0))))
                                    	tmp = 0.0
                                    	if (t_2 <= -0.0005)
                                    		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx + kx)))))) * th);
                                    	elseif (t_2 <= 5e-9)
                                    		tmp = Float64(Float64(ky / sqrt(t_1)) * sin(th));
                                    	elseif (t_2 <= 2.0)
                                    		tmp = sin(th);
                                    	else
                                    		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                                    	end
                                    	return tmp
                                    end
                                    
                                    function tmp_2 = code(kx, ky, th)
                                    	t_1 = sin(kx) ^ 2.0;
                                    	t_2 = sin(ky) / sqrt((t_1 + (sin(ky) ^ 2.0)));
                                    	tmp = 0.0;
                                    	if (t_2 <= -0.0005)
                                    		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * th;
                                    	elseif (t_2 <= 5e-9)
                                    		tmp = (ky / sqrt(t_1)) * sin(th);
                                    	elseif (t_2 <= 2.0)
                                    		tmp = sin(th);
                                    	else
                                    		tmp = (ky / sin(kx)) * sin(th);
                                    	end
                                    	tmp_2 = tmp;
                                    end
                                    
                                    code[kx_, ky_, th_] := Block[{t$95$1 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$1 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.0005], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$2, 5e-9], N[(N[(ky / N[Sqrt[t$95$1], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[Sin[th], $MachinePrecision], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]
                                    
                                    \begin{array}{l}
                                    
                                    \\
                                    \begin{array}{l}
                                    t_1 := {\sin kx}^{2}\\
                                    t_2 := \frac{\sin ky}{\sqrt{t\_1 + {\sin ky}^{2}}}\\
                                    \mathbf{if}\;t\_2 \leq -0.0005:\\
                                    \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th\\
                                    
                                    \mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-9}:\\
                                    \;\;\;\;\frac{ky}{\sqrt{t\_1}} \cdot \sin th\\
                                    
                                    \mathbf{elif}\;t\_2 \leq 2:\\
                                    \;\;\;\;\sin th\\
                                    
                                    \mathbf{else}:\\
                                    \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                                    
                                    
                                    \end{array}
                                    \end{array}
                                    
                                    Derivation
                                    1. Split input into 4 regimes
                                    2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -5.0000000000000001e-4

                                      1. Initial program 93.8%

                                        \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                      2. Add Preprocessing
                                      3. Taylor expanded in ky around 0

                                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                      4. Step-by-step derivation
                                        1. lift-sin.f64N/A

                                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                        2. lift-pow.f6411.7

                                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                      5. Applied rewrites11.7%

                                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                      6. Taylor expanded in th around 0

                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                      7. Step-by-step derivation
                                        1. Applied rewrites7.7%

                                          \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                        2. Step-by-step derivation
                                          1. lift-pow.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot th \]
                                          2. lift-sin.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot th \]
                                          3. pow2N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx}}} \cdot th \]
                                          4. sqr-sin-aN/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot th \]
                                          5. lower--.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot th \]
                                          6. lower-*.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot kx\right)}}} \cdot th \]
                                          7. cos-2N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \left(\cos kx \cdot \cos kx - \color{blue}{\sin kx \cdot \sin kx}\right)}} \cdot th \]
                                          8. cos-sumN/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot th \]
                                          9. lower-cos.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot th \]
                                          10. lower-+.f646.8

                                            \[\leadsto \frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot th \]
                                        3. Applied rewrites6.8%

                                          \[\leadsto \frac{\sin ky}{\sqrt{0.5 - \color{blue}{0.5 \cdot \cos \left(kx + kx\right)}}} \cdot th \]

                                        if -5.0000000000000001e-4 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                        1. Initial program 99.6%

                                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                        2. Add Preprocessing
                                        3. Taylor expanded in ky around 0

                                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                        4. Step-by-step derivation
                                          1. lift-sin.f64N/A

                                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                          2. lift-pow.f6499.6

                                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                        5. Applied rewrites99.6%

                                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                        6. Taylor expanded in ky around 0

                                          \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                        7. Step-by-step derivation
                                          1. Applied rewrites99.6%

                                            \[\leadsto \frac{\color{blue}{ky}}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]

                                          if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                          1. Initial program 99.0%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in kx around 0

                                            \[\leadsto \color{blue}{\sin th} \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f6467.3

                                              \[\leadsto \sin th \]
                                          5. Applied rewrites67.3%

                                            \[\leadsto \color{blue}{\sin th} \]

                                          if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                          1. Initial program 2.6%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. lower-/.f64N/A

                                              \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                            2. lift-sin.f6431.9

                                              \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                                          5. Applied rewrites31.9%

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                        8. Recombined 4 regimes into one program.
                                        9. Add Preprocessing

                                        Alternative 10: 44.2% accurate, 0.5× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                                           (if (or (<= t_1 5e-9) (not (<= t_1 2.0)))
                                             (* (/ ky (sin kx)) (sin th))
                                             (sin th))))
                                        double code(double kx, double ky, double th) {
                                        	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                                        	double tmp;
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                                        		tmp = (ky / sin(kx)) * sin(th);
                                        	} else {
                                        		tmp = sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        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(8) function code(kx, ky, th)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: kx
                                            real(8), intent (in) :: ky
                                            real(8), intent (in) :: th
                                            real(8) :: t_1
                                            real(8) :: tmp
                                            t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                                            if ((t_1 <= 5d-9) .or. (.not. (t_1 <= 2.0d0))) then
                                                tmp = (ky / sin(kx)) * sin(th)
                                            else
                                                tmp = sin(th)
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double kx, double ky, double th) {
                                        	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                                        	double tmp;
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                                        		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                                        	} else {
                                        		tmp = Math.sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(kx, ky, th):
                                        	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                                        	tmp = 0
                                        	if (t_1 <= 5e-9) or not (t_1 <= 2.0):
                                        		tmp = (ky / math.sin(kx)) * math.sin(th)
                                        	else:
                                        		tmp = math.sin(th)
                                        	return tmp
                                        
                                        function code(kx, ky, th)
                                        	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                                        	tmp = 0.0
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0))
                                        		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(kx, ky, th)
                                        	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                                        	tmp = 0.0;
                                        	if ((t_1 <= 5e-9) || ~((t_1 <= 2.0)))
                                        		tmp = (ky / sin(kx)) * sin(th);
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 5e-9], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                                        \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\
                                        \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                          1. Initial program 91.2%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. lower-/.f64N/A

                                              \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                            2. lift-sin.f6436.1

                                              \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                                          5. Applied rewrites36.1%

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]

                                          if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                          1. Initial program 99.0%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in kx around 0

                                            \[\leadsto \color{blue}{\sin th} \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f6467.3

                                              \[\leadsto \sin th \]
                                          5. Applied rewrites67.3%

                                            \[\leadsto \color{blue}{\sin th} \]
                                        3. Recombined 2 regimes into one program.
                                        4. Final simplification46.2%

                                          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9} \lor \neg \left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2\right):\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                        5. Add Preprocessing

                                        Alternative 11: 43.2% accurate, 0.5× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                                           (if (or (<= t_1 5e-9) (not (<= t_1 2.0)))
                                             (/ (* (sin th) ky) (sin kx))
                                             (sin th))))
                                        double code(double kx, double ky, double th) {
                                        	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                                        	double tmp;
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                                        		tmp = (sin(th) * ky) / sin(kx);
                                        	} else {
                                        		tmp = sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        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(8) function code(kx, ky, th)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: kx
                                            real(8), intent (in) :: ky
                                            real(8), intent (in) :: th
                                            real(8) :: t_1
                                            real(8) :: tmp
                                            t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                                            if ((t_1 <= 5d-9) .or. (.not. (t_1 <= 2.0d0))) then
                                                tmp = (sin(th) * ky) / sin(kx)
                                            else
                                                tmp = sin(th)
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double kx, double ky, double th) {
                                        	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                                        	double tmp;
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0)) {
                                        		tmp = (Math.sin(th) * ky) / Math.sin(kx);
                                        	} else {
                                        		tmp = Math.sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(kx, ky, th):
                                        	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                                        	tmp = 0
                                        	if (t_1 <= 5e-9) or not (t_1 <= 2.0):
                                        		tmp = (math.sin(th) * ky) / math.sin(kx)
                                        	else:
                                        		tmp = math.sin(th)
                                        	return tmp
                                        
                                        function code(kx, ky, th)
                                        	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                                        	tmp = 0.0
                                        	if ((t_1 <= 5e-9) || !(t_1 <= 2.0))
                                        		tmp = Float64(Float64(sin(th) * ky) / sin(kx));
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(kx, ky, th)
                                        	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                                        	tmp = 0.0;
                                        	if ((t_1 <= 5e-9) || ~((t_1 <= 2.0)))
                                        		tmp = (sin(th) * ky) / sin(kx);
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$1, 5e-9], N[Not[LessEqual[t$95$1, 2.0]], $MachinePrecision]], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                                        \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9} \lor \neg \left(t\_1 \leq 2\right):\\
                                        \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9 or 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                          1. Initial program 91.2%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                          4. Step-by-step derivation
                                            1. lower-/.f64N/A

                                              \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{\sin kx}} \]
                                            2. *-commutativeN/A

                                              \[\leadsto \frac{\sin th \cdot ky}{\sin \color{blue}{kx}} \]
                                            3. lower-*.f64N/A

                                              \[\leadsto \frac{\sin th \cdot ky}{\sin \color{blue}{kx}} \]
                                            4. lift-sin.f64N/A

                                              \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            5. lift-sin.f6435.2

                                              \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                          5. Applied rewrites35.2%

                                            \[\leadsto \color{blue}{\frac{\sin th \cdot ky}{\sin kx}} \]

                                          if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                          1. Initial program 99.0%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in kx around 0

                                            \[\leadsto \color{blue}{\sin th} \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f6467.3

                                              \[\leadsto \sin th \]
                                          5. Applied rewrites67.3%

                                            \[\leadsto \color{blue}{\sin th} \]
                                        3. Recombined 2 regimes into one program.
                                        4. Final simplification45.6%

                                          \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9} \lor \neg \left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2\right):\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
                                        5. Add Preprocessing

                                        Alternative 12: 45.4% accurate, 0.5× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                                           (if (<= t_1 5e-9)
                                             (* (/ (sin ky) (sin kx)) (sin th))
                                             (if (<= t_1 2.0) (sin th) (* (/ ky (sin kx)) (sin th))))))
                                        double code(double kx, double ky, double th) {
                                        	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                                        	double tmp;
                                        	if (t_1 <= 5e-9) {
                                        		tmp = (sin(ky) / sin(kx)) * sin(th);
                                        	} else if (t_1 <= 2.0) {
                                        		tmp = sin(th);
                                        	} else {
                                        		tmp = (ky / sin(kx)) * sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        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(8) function code(kx, ky, th)
                                        use fmin_fmax_functions
                                            real(8), intent (in) :: kx
                                            real(8), intent (in) :: ky
                                            real(8), intent (in) :: th
                                            real(8) :: t_1
                                            real(8) :: tmp
                                            t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
                                            if (t_1 <= 5d-9) then
                                                tmp = (sin(ky) / sin(kx)) * sin(th)
                                            else if (t_1 <= 2.0d0) then
                                                tmp = sin(th)
                                            else
                                                tmp = (ky / sin(kx)) * sin(th)
                                            end if
                                            code = tmp
                                        end function
                                        
                                        public static double code(double kx, double ky, double th) {
                                        	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                                        	double tmp;
                                        	if (t_1 <= 5e-9) {
                                        		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
                                        	} else if (t_1 <= 2.0) {
                                        		tmp = Math.sin(th);
                                        	} else {
                                        		tmp = (ky / Math.sin(kx)) * Math.sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        def code(kx, ky, th):
                                        	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                                        	tmp = 0
                                        	if t_1 <= 5e-9:
                                        		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
                                        	elif t_1 <= 2.0:
                                        		tmp = math.sin(th)
                                        	else:
                                        		tmp = (ky / math.sin(kx)) * math.sin(th)
                                        	return tmp
                                        
                                        function code(kx, ky, th)
                                        	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                                        	tmp = 0.0
                                        	if (t_1 <= 5e-9)
                                        		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                                        	elseif (t_1 <= 2.0)
                                        		tmp = sin(th);
                                        	else
                                        		tmp = Float64(Float64(ky / sin(kx)) * sin(th));
                                        	end
                                        	return tmp
                                        end
                                        
                                        function tmp_2 = code(kx, ky, th)
                                        	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                                        	tmp = 0.0;
                                        	if (t_1 <= 5e-9)
                                        		tmp = (sin(ky) / sin(kx)) * sin(th);
                                        	elseif (t_1 <= 2.0)
                                        		tmp = sin(th);
                                        	else
                                        		tmp = (ky / sin(kx)) * sin(th);
                                        	end
                                        	tmp_2 = tmp;
                                        end
                                        
                                        code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, 5e-9], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                                        \mathbf{if}\;t\_1 \leq 5 \cdot 10^{-9}:\\
                                        \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                                        
                                        \mathbf{elif}\;t\_1 \leq 2:\\
                                        \;\;\;\;\sin th\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\frac{ky}{\sin kx} \cdot \sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 3 regimes
                                        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                          1. Initial program 96.7%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f6438.4

                                              \[\leadsto \frac{\sin ky}{\sin kx} \cdot \sin th \]
                                          5. Applied rewrites38.4%

                                            \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

                                          if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

                                          1. Initial program 99.0%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in kx around 0

                                            \[\leadsto \color{blue}{\sin th} \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f6467.3

                                              \[\leadsto \sin th \]
                                          5. Applied rewrites67.3%

                                            \[\leadsto \color{blue}{\sin th} \]

                                          if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                          1. Initial program 2.6%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. lower-/.f64N/A

                                              \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                            2. lift-sin.f6431.9

                                              \[\leadsto \frac{ky}{\sin kx} \cdot \sin th \]
                                          5. Applied rewrites31.9%

                                            \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
                                        3. Recombined 3 regimes into one program.
                                        4. Add Preprocessing

                                        Alternative 13: 36.7% accurate, 0.9× speedup?

                                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, kx \cdot kx\right)}} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                        (FPCore (kx ky th)
                                         :precision binary64
                                         (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-9)
                                           (* (/ (sin ky) (sqrt (fma ky ky (* kx kx)))) th)
                                           (sin th)))
                                        double code(double kx, double ky, double th) {
                                        	double tmp;
                                        	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-9) {
                                        		tmp = (sin(ky) / sqrt(fma(ky, ky, (kx * kx)))) * th;
                                        	} else {
                                        		tmp = sin(th);
                                        	}
                                        	return tmp;
                                        }
                                        
                                        function code(kx, ky, th)
                                        	tmp = 0.0
                                        	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
                                        		tmp = Float64(Float64(sin(ky) / sqrt(fma(ky, ky, Float64(kx * kx)))) * th);
                                        	else
                                        		tmp = sin(th);
                                        	end
                                        	return tmp
                                        end
                                        
                                        code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-9], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(ky * ky + N[(kx * kx), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                        
                                        \begin{array}{l}
                                        
                                        \\
                                        \begin{array}{l}
                                        \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
                                        \;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, kx \cdot kx\right)}} \cdot th\\
                                        
                                        \mathbf{else}:\\
                                        \;\;\;\;\sin th\\
                                        
                                        
                                        \end{array}
                                        \end{array}
                                        
                                        Derivation
                                        1. Split input into 2 regimes
                                        2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                          1. Initial program 96.7%

                                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                          2. Add Preprocessing
                                          3. Taylor expanded in ky around 0

                                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                          4. Step-by-step derivation
                                            1. lift-sin.f64N/A

                                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                            2. lift-pow.f6455.4

                                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                          5. Applied rewrites55.4%

                                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                          6. Taylor expanded in th around 0

                                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                          7. Step-by-step derivation
                                            1. Applied rewrites27.1%

                                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                            2. Taylor expanded in ky around 0

                                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{ky}^{2} + {\sin kx}^{2}}}} \cdot th \]
                                            3. Step-by-step derivation
                                              1. pow2N/A

                                                \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky + {\color{blue}{\sin kx}}^{2}}} \cdot th \]
                                              2. lower-fma.f64N/A

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, \color{blue}{ky}, {\sin kx}^{2}\right)}} \cdot th \]
                                              3. lift-sin.f64N/A

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, {\sin kx}^{2}\right)}} \cdot th \]
                                              4. lift-pow.f6429.0

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, {\sin kx}^{2}\right)}} \cdot th \]
                                            4. Applied rewrites29.0%

                                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\mathsf{fma}\left(ky, ky, {\sin kx}^{2}\right)}}} \cdot th \]
                                            5. Taylor expanded in kx around 0

                                              \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, {kx}^{2}\right)}} \cdot th \]
                                            6. Step-by-step derivation
                                              1. unpow2N/A

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, kx \cdot kx\right)}} \cdot th \]
                                              2. lower-*.f6424.6

                                                \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, kx \cdot kx\right)}} \cdot th \]
                                            7. Applied rewrites24.6%

                                              \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(ky, ky, kx \cdot kx\right)}} \cdot th \]

                                            if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                            1. Initial program 88.6%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in kx around 0

                                              \[\leadsto \color{blue}{\sin th} \]
                                            4. Step-by-step derivation
                                              1. lift-sin.f6463.9

                                                \[\leadsto \sin th \]
                                            5. Applied rewrites63.9%

                                              \[\leadsto \color{blue}{\sin th} \]
                                          8. Recombined 2 regimes into one program.
                                          9. Add Preprocessing

                                          Alternative 14: 34.4% accurate, 1.0× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx}} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                          (FPCore (kx ky th)
                                           :precision binary64
                                           (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-9)
                                             (* (/ (sin ky) (sqrt (* kx kx))) th)
                                             (sin th)))
                                          double code(double kx, double ky, double th) {
                                          	double tmp;
                                          	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-9) {
                                          		tmp = (sin(ky) / sqrt((kx * kx))) * th;
                                          	} else {
                                          		tmp = sin(th);
                                          	}
                                          	return tmp;
                                          }
                                          
                                          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(8) function code(kx, ky, th)
                                          use fmin_fmax_functions
                                              real(8), intent (in) :: kx
                                              real(8), intent (in) :: ky
                                              real(8), intent (in) :: th
                                              real(8) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 5d-9) then
                                                  tmp = (sin(ky) / sqrt((kx * kx))) * th
                                              else
                                                  tmp = sin(th)
                                              end if
                                              code = tmp
                                          end function
                                          
                                          public static double code(double kx, double ky, double th) {
                                          	double tmp;
                                          	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 5e-9) {
                                          		tmp = (Math.sin(ky) / Math.sqrt((kx * kx))) * th;
                                          	} else {
                                          		tmp = Math.sin(th);
                                          	}
                                          	return tmp;
                                          }
                                          
                                          def code(kx, ky, th):
                                          	tmp = 0
                                          	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 5e-9:
                                          		tmp = (math.sin(ky) / math.sqrt((kx * kx))) * th
                                          	else:
                                          		tmp = math.sin(th)
                                          	return tmp
                                          
                                          function code(kx, ky, th)
                                          	tmp = 0.0
                                          	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
                                          		tmp = Float64(Float64(sin(ky) / sqrt(Float64(kx * kx))) * th);
                                          	else
                                          		tmp = sin(th);
                                          	end
                                          	return tmp
                                          end
                                          
                                          function tmp_2 = code(kx, ky, th)
                                          	tmp = 0.0;
                                          	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
                                          		tmp = (sin(ky) / sqrt((kx * kx))) * th;
                                          	else
                                          		tmp = sin(th);
                                          	end
                                          	tmp_2 = tmp;
                                          end
                                          
                                          code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-9], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(kx * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
                                          \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx}} \cdot th\\
                                          
                                          \mathbf{else}:\\
                                          \;\;\;\;\sin th\\
                                          
                                          
                                          \end{array}
                                          \end{array}
                                          
                                          Derivation
                                          1. Split input into 2 regimes
                                          2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

                                            1. Initial program 96.7%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. Add Preprocessing
                                            3. Taylor expanded in ky around 0

                                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                            4. Step-by-step derivation
                                              1. lift-sin.f64N/A

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                              2. lift-pow.f6455.4

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                            5. Applied rewrites55.4%

                                              \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                            6. Taylor expanded in th around 0

                                              \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                            7. Step-by-step derivation
                                              1. Applied rewrites27.1%

                                                \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{th} \]
                                              2. Taylor expanded in kx around 0

                                                \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{\color{blue}{2}}}} \cdot th \]
                                              3. Step-by-step derivation
                                                1. unpow2N/A

                                                  \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx}} \cdot th \]
                                                2. lower-*.f6420.9

                                                  \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx}} \cdot th \]
                                              4. Applied rewrites20.9%

                                                \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot \color{blue}{kx}}} \cdot th \]

                                              if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                              1. Initial program 88.6%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in kx around 0

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lift-sin.f6463.9

                                                  \[\leadsto \sin th \]
                                              5. Applied rewrites63.9%

                                                \[\leadsto \color{blue}{\sin th} \]
                                            8. Recombined 2 regimes into one program.
                                            9. Add Preprocessing

                                            Alternative 15: 15.4% accurate, 1.0× speedup?

                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 2 \cdot 10^{-300}:\\ \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
                                            (FPCore (kx ky th)
                                             :precision binary64
                                             (if (<=
                                                  (*
                                                   (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))
                                                   (sin th))
                                                  2e-300)
                                               (* (* (* th th) -0.16666666666666666) th)
                                               th))
                                            double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th)) <= 2e-300) {
                                            		tmp = ((th * th) * -0.16666666666666666) * th;
                                            	} else {
                                            		tmp = th;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            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(8) function code(kx, ky, th)
                                            use fmin_fmax_functions
                                                real(8), intent (in) :: kx
                                                real(8), intent (in) :: ky
                                                real(8), intent (in) :: th
                                                real(8) :: tmp
                                                if (((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)) <= 2d-300) then
                                                    tmp = ((th * th) * (-0.16666666666666666d0)) * th
                                                else
                                                    tmp = th
                                                end if
                                                code = tmp
                                            end function
                                            
                                            public static double code(double kx, double ky, double th) {
                                            	double tmp;
                                            	if (((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th)) <= 2e-300) {
                                            		tmp = ((th * th) * -0.16666666666666666) * th;
                                            	} else {
                                            		tmp = th;
                                            	}
                                            	return tmp;
                                            }
                                            
                                            def code(kx, ky, th):
                                            	tmp = 0
                                            	if ((math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)) <= 2e-300:
                                            		tmp = ((th * th) * -0.16666666666666666) * th
                                            	else:
                                            		tmp = th
                                            	return tmp
                                            
                                            function code(kx, ky, th)
                                            	tmp = 0.0
                                            	if (Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 2e-300)
                                            		tmp = Float64(Float64(Float64(th * th) * -0.16666666666666666) * th);
                                            	else
                                            		tmp = th;
                                            	end
                                            	return tmp
                                            end
                                            
                                            function tmp_2 = code(kx, ky, th)
                                            	tmp = 0.0;
                                            	if (((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 2e-300)
                                            		tmp = ((th * th) * -0.16666666666666666) * th;
                                            	else
                                            		tmp = th;
                                            	end
                                            	tmp_2 = tmp;
                                            end
                                            
                                            code[kx_, ky_, th_] := If[LessEqual[N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], 2e-300], N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * th), $MachinePrecision], th]
                                            
                                            \begin{array}{l}
                                            
                                            \\
                                            \begin{array}{l}
                                            \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 2 \cdot 10^{-300}:\\
                                            \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\
                                            
                                            \mathbf{else}:\\
                                            \;\;\;\;th\\
                                            
                                            
                                            \end{array}
                                            \end{array}
                                            
                                            Derivation
                                            1. Split input into 2 regimes
                                            2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 2.00000000000000005e-300

                                              1. Initial program 93.0%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in kx around 0

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lift-sin.f6427.0

                                                  \[\leadsto \sin th \]
                                              5. Applied rewrites27.0%

                                                \[\leadsto \color{blue}{\sin th} \]
                                              6. Taylor expanded in th around 0

                                                \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                                              7. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                                3. +-commutativeN/A

                                                  \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot th \]
                                                4. *-commutativeN/A

                                                  \[\leadsto \left({th}^{2} \cdot \frac{-1}{6} + 1\right) \cdot th \]
                                                5. lower-fma.f64N/A

                                                  \[\leadsto \mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right) \cdot th \]
                                                6. unpow2N/A

                                                  \[\leadsto \mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th \]
                                                7. lower-*.f6414.0

                                                  \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th \]
                                              8. Applied rewrites14.0%

                                                \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                              9. Taylor expanded in th around inf

                                                \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                              10. Step-by-step derivation
                                                1. *-commutativeN/A

                                                  \[\leadsto \left({th}^{2} \cdot \frac{-1}{6}\right) \cdot th \]
                                                2. lower-*.f64N/A

                                                  \[\leadsto \left({th}^{2} \cdot \frac{-1}{6}\right) \cdot th \]
                                                3. pow2N/A

                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot \frac{-1}{6}\right) \cdot th \]
                                                4. lift-*.f6414.8

                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                              11. Applied rewrites14.8%

                                                \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]

                                              if 2.00000000000000005e-300 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th))

                                              1. Initial program 94.6%

                                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                              2. Add Preprocessing
                                              3. Taylor expanded in kx around 0

                                                \[\leadsto \color{blue}{\sin th} \]
                                              4. Step-by-step derivation
                                                1. lift-sin.f6424.2

                                                  \[\leadsto \sin th \]
                                              5. Applied rewrites24.2%

                                                \[\leadsto \color{blue}{\sin th} \]
                                              6. Taylor expanded in th around 0

                                                \[\leadsto th \]
                                              7. Step-by-step derivation
                                                1. Applied rewrites13.1%

                                                  \[\leadsto th \]
                                              8. Recombined 2 regimes into one program.
                                              9. Add Preprocessing

                                              Alternative 16: 30.7% accurate, 1.0× speedup?

                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-36}:\\ \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                              (FPCore (kx ky th)
                                               :precision binary64
                                               (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-36)
                                                 (* (* (* th th) -0.16666666666666666) th)
                                                 (sin th)))
                                              double code(double kx, double ky, double th) {
                                              	double tmp;
                                              	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-36) {
                                              		tmp = ((th * th) * -0.16666666666666666) * th;
                                              	} else {
                                              		tmp = sin(th);
                                              	}
                                              	return tmp;
                                              }
                                              
                                              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(8) function code(kx, ky, th)
                                              use fmin_fmax_functions
                                                  real(8), intent (in) :: kx
                                                  real(8), intent (in) :: ky
                                                  real(8), intent (in) :: th
                                                  real(8) :: tmp
                                                  if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 5d-36) then
                                                      tmp = ((th * th) * (-0.16666666666666666d0)) * th
                                                  else
                                                      tmp = sin(th)
                                                  end if
                                                  code = tmp
                                              end function
                                              
                                              public static double code(double kx, double ky, double th) {
                                              	double tmp;
                                              	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 5e-36) {
                                              		tmp = ((th * th) * -0.16666666666666666) * th;
                                              	} else {
                                              		tmp = Math.sin(th);
                                              	}
                                              	return tmp;
                                              }
                                              
                                              def code(kx, ky, th):
                                              	tmp = 0
                                              	if (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) <= 5e-36:
                                              		tmp = ((th * th) * -0.16666666666666666) * th
                                              	else:
                                              		tmp = math.sin(th)
                                              	return tmp
                                              
                                              function code(kx, ky, th)
                                              	tmp = 0.0
                                              	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-36)
                                              		tmp = Float64(Float64(Float64(th * th) * -0.16666666666666666) * th);
                                              	else
                                              		tmp = sin(th);
                                              	end
                                              	return tmp
                                              end
                                              
                                              function tmp_2 = code(kx, ky, th)
                                              	tmp = 0.0;
                                              	if ((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-36)
                                              		tmp = ((th * th) * -0.16666666666666666) * th;
                                              	else
                                              		tmp = sin(th);
                                              	end
                                              	tmp_2 = tmp;
                                              end
                                              
                                              code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-36], N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * th), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \begin{array}{l}
                                              \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-36}:\\
                                              \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;\sin th\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 2 regimes
                                              2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.00000000000000004e-36

                                                1. Initial program 96.5%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in kx around 0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                4. Step-by-step derivation
                                                  1. lift-sin.f643.6

                                                    \[\leadsto \sin th \]
                                                5. Applied rewrites3.6%

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                6. Taylor expanded in th around 0

                                                  \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
                                                7. Step-by-step derivation
                                                  1. *-commutativeN/A

                                                    \[\leadsto \left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                                  2. lower-*.f64N/A

                                                    \[\leadsto \left(1 + \frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                                  3. +-commutativeN/A

                                                    \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2} + 1\right) \cdot th \]
                                                  4. *-commutativeN/A

                                                    \[\leadsto \left({th}^{2} \cdot \frac{-1}{6} + 1\right) \cdot th \]
                                                  5. lower-fma.f64N/A

                                                    \[\leadsto \mathsf{fma}\left({th}^{2}, \frac{-1}{6}, 1\right) \cdot th \]
                                                  6. unpow2N/A

                                                    \[\leadsto \mathsf{fma}\left(th \cdot th, \frac{-1}{6}, 1\right) \cdot th \]
                                                  7. lower-*.f643.6

                                                    \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th \]
                                                8. Applied rewrites3.6%

                                                  \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot \color{blue}{th} \]
                                                9. Taylor expanded in th around inf

                                                  \[\leadsto \left(\frac{-1}{6} \cdot {th}^{2}\right) \cdot th \]
                                                10. Step-by-step derivation
                                                  1. *-commutativeN/A

                                                    \[\leadsto \left({th}^{2} \cdot \frac{-1}{6}\right) \cdot th \]
                                                  2. lower-*.f64N/A

                                                    \[\leadsto \left({th}^{2} \cdot \frac{-1}{6}\right) \cdot th \]
                                                  3. pow2N/A

                                                    \[\leadsto \left(\left(th \cdot th\right) \cdot \frac{-1}{6}\right) \cdot th \]
                                                  4. lift-*.f6413.8

                                                    \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                                11. Applied rewrites13.8%

                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]

                                                if 5.00000000000000004e-36 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

                                                1. Initial program 89.7%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in kx around 0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                4. Step-by-step derivation
                                                  1. lift-sin.f6458.6

                                                    \[\leadsto \sin th \]
                                                5. Applied rewrites58.6%

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              3. Recombined 2 regimes into one program.
                                              4. Add Preprocessing

                                              Alternative 17: 46.9% accurate, 1.2× speedup?

                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 4 \cdot 10^{-150}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-10}:\\ \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0001984126984126984, 0.008333333333333333\right) \cdot \left(ky \cdot ky\right) - 0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(0.5 - 0.5 \cdot \cos \left(kx + kx\right)\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
                                              (FPCore (kx ky th)
                                               :precision binary64
                                               (if (<= (sin ky) 4e-150)
                                                 (* (/ (sin ky) (sin kx)) (sin th))
                                                 (if (<= (sin ky) 5e-10)
                                                   (*
                                                    (/
                                                     (*
                                                      (fma
                                                       (-
                                                        (*
                                                         (fma (* ky ky) -0.0001984126984126984 0.008333333333333333)
                                                         (* ky ky))
                                                        0.16666666666666666)
                                                       (* ky ky)
                                                       1.0)
                                                      ky)
                                                     (sqrt
                                                      (+
                                                       (- 0.5 (* 0.5 (cos (+ kx kx))))
                                                       (*
                                                        (fma
                                                         (-
                                                          (*
                                                           (fma (* ky ky) -0.0031746031746031746 0.044444444444444446)
                                                           (* ky ky))
                                                          0.3333333333333333)
                                                         (* ky ky)
                                                         1.0)
                                                        (* ky ky)))))
                                                    (sin th))
                                                   (sin th))))
                                              double code(double kx, double ky, double th) {
                                              	double tmp;
                                              	if (sin(ky) <= 4e-150) {
                                              		tmp = (sin(ky) / sin(kx)) * sin(th);
                                              	} else if (sin(ky) <= 5e-10) {
                                              		tmp = ((fma(((fma((ky * ky), -0.0001984126984126984, 0.008333333333333333) * (ky * ky)) - 0.16666666666666666), (ky * ky), 1.0) * ky) / sqrt(((0.5 - (0.5 * cos((kx + kx)))) + (fma(((fma((ky * ky), -0.0031746031746031746, 0.044444444444444446) * (ky * ky)) - 0.3333333333333333), (ky * ky), 1.0) * (ky * ky))))) * sin(th);
                                              	} else {
                                              		tmp = sin(th);
                                              	}
                                              	return tmp;
                                              }
                                              
                                              function code(kx, ky, th)
                                              	tmp = 0.0
                                              	if (sin(ky) <= 4e-150)
                                              		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                                              	elseif (sin(ky) <= 5e-10)
                                              		tmp = Float64(Float64(Float64(fma(Float64(Float64(fma(Float64(ky * ky), -0.0001984126984126984, 0.008333333333333333) * Float64(ky * ky)) - 0.16666666666666666), Float64(ky * ky), 1.0) * ky) / sqrt(Float64(Float64(0.5 - Float64(0.5 * cos(Float64(kx + kx)))) + Float64(fma(Float64(Float64(fma(Float64(ky * ky), -0.0031746031746031746, 0.044444444444444446) * Float64(ky * ky)) - 0.3333333333333333), Float64(ky * ky), 1.0) * Float64(ky * ky))))) * sin(th));
                                              	else
                                              		tmp = sin(th);
                                              	end
                                              	return tmp
                                              end
                                              
                                              code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-150], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-10], N[(N[(N[(N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.0001984126984126984 + 0.008333333333333333), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision] - 0.16666666666666666), $MachinePrecision] * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * ky), $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(0.5 * N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(N[(ky * ky), $MachinePrecision] * -0.0031746031746031746 + 0.044444444444444446), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision] - 0.3333333333333333), $MachinePrecision] * N[(ky * ky), $MachinePrecision] + 1.0), $MachinePrecision] * N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \begin{array}{l}
                                              \mathbf{if}\;\sin ky \leq 4 \cdot 10^{-150}:\\
                                              \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                                              
                                              \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-10}:\\
                                              \;\;\;\;\frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0001984126984126984, 0.008333333333333333\right) \cdot \left(ky \cdot ky\right) - 0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(0.5 - 0.5 \cdot \cos \left(kx + kx\right)\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;\sin th\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 3 regimes
                                              2. if (sin.f64 ky) < 4.00000000000000003e-150

                                                1. Initial program 89.9%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in ky around 0

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
                                                4. Step-by-step derivation
                                                  1. lift-sin.f6434.9

                                                    \[\leadsto \frac{\sin ky}{\sin kx} \cdot \sin th \]
                                                5. Applied rewrites34.9%

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]

                                                if 4.00000000000000003e-150 < (sin.f64 ky) < 5.00000000000000031e-10

                                                1. Initial program 99.7%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in ky around 0

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2} \cdot \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right)}}} \cdot \sin th \]
                                                4. Step-by-step derivation
                                                  1. *-commutativeN/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                                  2. lower-*.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{2}{45} + \frac{-1}{315} \cdot {ky}^{2}\right) - \frac{1}{3}\right)\right) \cdot \color{blue}{{ky}^{2}}}} \cdot \sin th \]
                                                5. Applied rewrites99.7%

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}}} \cdot \sin th \]
                                                6. Taylor expanded in ky around 0

                                                  \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {ky}^{2}\right) - \frac{1}{6}\right)\right)}}{\sqrt{{\sin kx}^{2} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                7. Step-by-step derivation
                                                  1. *-commutativeN/A

                                                    \[\leadsto \frac{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {ky}^{2}\right) - \frac{1}{6}\right)\right) \cdot \color{blue}{ky}}{\sqrt{{\sin kx}^{2} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  2. lower-*.f64N/A

                                                    \[\leadsto \frac{\left(1 + {ky}^{2} \cdot \left({ky}^{2} \cdot \left(\frac{1}{120} + \frac{-1}{5040} \cdot {ky}^{2}\right) - \frac{1}{6}\right)\right) \cdot \color{blue}{ky}}{\sqrt{{\sin kx}^{2} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                8. Applied rewrites99.7%

                                                  \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0001984126984126984, 0.008333333333333333\right) \cdot \left(ky \cdot ky\right) - 0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}}{\sqrt{{\sin kx}^{2} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                9. Step-by-step derivation
                                                  1. lift-pow.f64N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  2. lift-sin.f64N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  3. pow2N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  4. sqr-sin-aN/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  5. lower--.f64N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot kx\right)\right)} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  6. lower-*.f64N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  7. cos-2N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\left(\cos kx \cdot \cos kx - \sin kx \cdot \sin kx\right)}\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  8. cos-sumN/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(kx + kx\right)}\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  9. lower-cos.f64N/A

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{5040}, \frac{1}{120}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{6}, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(kx + kx\right)}\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, \frac{-1}{315}, \frac{2}{45}\right) \cdot \left(ky \cdot ky\right) - \frac{1}{3}, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                  10. lower-+.f6489.6

                                                    \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0001984126984126984, 0.008333333333333333\right) \cdot \left(ky \cdot ky\right) - 0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\left(0.5 - 0.5 \cdot \cos \color{blue}{\left(kx + kx\right)}\right) + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]
                                                10. Applied rewrites89.6%

                                                  \[\leadsto \frac{\mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0001984126984126984, 0.008333333333333333\right) \cdot \left(ky \cdot ky\right) - 0.16666666666666666, ky \cdot ky, 1\right) \cdot ky}{\sqrt{\color{blue}{\left(0.5 - 0.5 \cdot \cos \left(kx + kx\right)\right)} + \mathsf{fma}\left(\mathsf{fma}\left(ky \cdot ky, -0.0031746031746031746, 0.044444444444444446\right) \cdot \left(ky \cdot ky\right) - 0.3333333333333333, ky \cdot ky, 1\right) \cdot \left(ky \cdot ky\right)}} \cdot \sin th \]

                                                if 5.00000000000000031e-10 < (sin.f64 ky)

                                                1. Initial program 99.6%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in kx around 0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                4. Step-by-step derivation
                                                  1. lift-sin.f6463.3

                                                    \[\leadsto \sin th \]
                                                5. Applied rewrites63.3%

                                                  \[\leadsto \color{blue}{\sin th} \]
                                              3. Recombined 3 regimes into one program.
                                              4. Add Preprocessing

                                              Alternative 18: 68.6% accurate, 1.5× speedup?

                                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 0.058:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot \sin th\\ \end{array} \end{array} \]
                                              (FPCore (kx ky th)
                                               :precision binary64
                                               (if (<= kx 0.058)
                                                 (* (/ (sin ky) (hypot (sin ky) kx)) (sin th))
                                                 (* (/ (sin ky) (sqrt (- 0.5 (* 0.5 (cos (+ kx kx)))))) (sin th))))
                                              double code(double kx, double ky, double th) {
                                              	double tmp;
                                              	if (kx <= 0.058) {
                                              		tmp = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
                                              	} else {
                                              		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * sin(th);
                                              	}
                                              	return tmp;
                                              }
                                              
                                              public static double code(double kx, double ky, double th) {
                                              	double tmp;
                                              	if (kx <= 0.058) {
                                              		tmp = (Math.sin(ky) / Math.hypot(Math.sin(ky), kx)) * Math.sin(th);
                                              	} else {
                                              		tmp = (Math.sin(ky) / Math.sqrt((0.5 - (0.5 * Math.cos((kx + kx)))))) * Math.sin(th);
                                              	}
                                              	return tmp;
                                              }
                                              
                                              def code(kx, ky, th):
                                              	tmp = 0
                                              	if kx <= 0.058:
                                              		tmp = (math.sin(ky) / math.hypot(math.sin(ky), kx)) * math.sin(th)
                                              	else:
                                              		tmp = (math.sin(ky) / math.sqrt((0.5 - (0.5 * math.cos((kx + kx)))))) * math.sin(th)
                                              	return tmp
                                              
                                              function code(kx, ky, th)
                                              	tmp = 0.0
                                              	if (kx <= 0.058)
                                              		tmp = Float64(Float64(sin(ky) / hypot(sin(ky), kx)) * sin(th));
                                              	else
                                              		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx + kx)))))) * sin(th));
                                              	end
                                              	return tmp
                                              end
                                              
                                              function tmp_2 = code(kx, ky, th)
                                              	tmp = 0.0;
                                              	if (kx <= 0.058)
                                              		tmp = (sin(ky) / hypot(sin(ky), kx)) * sin(th);
                                              	else
                                              		tmp = (sin(ky) / sqrt((0.5 - (0.5 * cos((kx + kx)))))) * sin(th);
                                              	end
                                              	tmp_2 = tmp;
                                              end
                                              
                                              code[kx_, ky_, th_] := If[LessEqual[kx, 0.058], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
                                              
                                              \begin{array}{l}
                                              
                                              \\
                                              \begin{array}{l}
                                              \mathbf{if}\;kx \leq 0.058:\\
                                              \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \cdot \sin th\\
                                              
                                              \mathbf{else}:\\
                                              \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot \sin th\\
                                              
                                              
                                              \end{array}
                                              \end{array}
                                              
                                              Derivation
                                              1. Split input into 2 regimes
                                              2. if kx < 0.0580000000000000029

                                                1. Initial program 91.6%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Step-by-step derivation
                                                  1. lift-sqrt.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                  2. lift-+.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                                  3. lift-pow.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                                                  4. lift-sin.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                  5. lift-pow.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{\sin ky}^{2}}}} \cdot \sin th \]
                                                  6. lift-sin.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\color{blue}{\sin ky}}^{2}}} \cdot \sin th \]
                                                  7. +-commutativeN/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
                                                  8. unpow2N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
                                                  9. unpow2N/A

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
                                                  10. lower-hypot.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                                                  11. lift-sin.f64N/A

                                                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\color{blue}{\sin ky}, \sin kx\right)} \cdot \sin th \]
                                                  12. lift-sin.f6499.7

                                                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{\sin kx}\right)} \cdot \sin th \]
                                                4. Applied rewrites99.7%

                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
                                                5. Taylor expanded in kx around 0

                                                  \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]
                                                6. Step-by-step derivation
                                                  1. Applied rewrites76.6%

                                                    \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \color{blue}{kx}\right)} \cdot \sin th \]

                                                  if 0.0580000000000000029 < kx

                                                  1. Initial program 99.5%

                                                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                  2. Add Preprocessing
                                                  3. Taylor expanded in ky around 0

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                  4. Step-by-step derivation
                                                    1. lift-sin.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                    2. lift-pow.f6458.9

                                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                                  5. Applied rewrites58.9%

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \cdot \sin th \]
                                                  6. Step-by-step derivation
                                                    1. lift-pow.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{\color{blue}{2}}}} \cdot \sin th \]
                                                    2. lift-sin.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                    3. pow2N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin th \]
                                                    4. sqr-sin-aN/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                                    5. lower--.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \color{blue}{\frac{1}{2} \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                                    6. lower-*.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \color{blue}{\cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
                                                    7. cos-2N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \left(\cos kx \cdot \cos kx - \color{blue}{\sin kx \cdot \sin kx}\right)}} \cdot \sin th \]
                                                    8. cos-sumN/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot \sin th \]
                                                    9. lower-cos.f64N/A

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(kx + kx\right)}} \cdot \sin th \]
                                                    10. lower-+.f6458.8

                                                      \[\leadsto \frac{\sin ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx + kx\right)}} \cdot \sin th \]
                                                  7. Applied rewrites58.8%

                                                    \[\leadsto \frac{\sin ky}{\sqrt{0.5 - \color{blue}{0.5 \cdot \cos \left(kx + kx\right)}}} \cdot \sin th \]
                                                7. Recombined 2 regimes into one program.
                                                8. Add Preprocessing

                                                Alternative 19: 13.7% accurate, 632.0× speedup?

                                                \[\begin{array}{l} \\ th \end{array} \]
                                                (FPCore (kx ky th) :precision binary64 th)
                                                double code(double kx, double ky, double th) {
                                                	return th;
                                                }
                                                
                                                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(8) function code(kx, ky, th)
                                                use fmin_fmax_functions
                                                    real(8), intent (in) :: kx
                                                    real(8), intent (in) :: ky
                                                    real(8), intent (in) :: th
                                                    code = th
                                                end function
                                                
                                                public static double code(double kx, double ky, double th) {
                                                	return th;
                                                }
                                                
                                                def code(kx, ky, th):
                                                	return th
                                                
                                                function code(kx, ky, th)
                                                	return th
                                                end
                                                
                                                function tmp = code(kx, ky, th)
                                                	tmp = th;
                                                end
                                                
                                                code[kx_, ky_, th_] := th
                                                
                                                \begin{array}{l}
                                                
                                                \\
                                                th
                                                \end{array}
                                                
                                                Derivation
                                                1. Initial program 93.8%

                                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                                2. Add Preprocessing
                                                3. Taylor expanded in kx around 0

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                4. Step-by-step derivation
                                                  1. lift-sin.f6425.7

                                                    \[\leadsto \sin th \]
                                                5. Applied rewrites25.7%

                                                  \[\leadsto \color{blue}{\sin th} \]
                                                6. Taylor expanded in th around 0

                                                  \[\leadsto th \]
                                                7. Step-by-step derivation
                                                  1. Applied rewrites13.6%

                                                    \[\leadsto th \]
                                                  2. Add Preprocessing

                                                  Reproduce

                                                  ?
                                                  herbie shell --seed 2025037 
                                                  (FPCore (kx ky th)
                                                    :name "Toniolo and Linder, Equation (3b), real"
                                                    :precision binary64
                                                    (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))