Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 6.6s
Alternatives: 16
Speedup: 1.5×

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}

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 94.0% 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.5× 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 94.0%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. 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 \]
  3. Applied rewrites99.7%

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

Alternative 2: 84.8% 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}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_3 := \frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \mathbf{if}\;t\_2 \leq -0.95:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.13:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 10^{-11}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(ky, \sin kx\right)} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.92:\\ \;\;\;\;t\_3\\ \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) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_3 (/ (* (sin ky) th) (hypot (sin kx) (sin ky)))))
   (if (<= t_2 -0.95)
     t_1
     (if (<= t_2 -0.13)
       t_3
       (if (<= t_2 1e-11)
         (* (/ (sin ky) (hypot ky (sin kx))) (sin th))
         (if (<= t_2 0.92) t_3 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) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_3 = (sin(ky) * th) / hypot(sin(kx), sin(ky));
	double tmp;
	if (t_2 <= -0.95) {
		tmp = t_1;
	} else if (t_2 <= -0.13) {
		tmp = t_3;
	} else if (t_2 <= 1e-11) {
		tmp = (sin(ky) / hypot(ky, sin(kx))) * sin(th);
	} else if (t_2 <= 0.92) {
		tmp = t_3;
	} 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.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double t_3 = (Math.sin(ky) * th) / Math.hypot(Math.sin(kx), Math.sin(ky));
	double tmp;
	if (t_2 <= -0.95) {
		tmp = t_1;
	} else if (t_2 <= -0.13) {
		tmp = t_3;
	} else if (t_2 <= 1e-11) {
		tmp = (Math.sin(ky) / Math.hypot(ky, Math.sin(kx))) * Math.sin(th);
	} else if (t_2 <= 0.92) {
		tmp = t_3;
	} 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.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	t_3 = (math.sin(ky) * th) / math.hypot(math.sin(kx), math.sin(ky))
	tmp = 0
	if t_2 <= -0.95:
		tmp = t_1
	elif t_2 <= -0.13:
		tmp = t_3
	elif t_2 <= 1e-11:
		tmp = (math.sin(ky) / math.hypot(ky, math.sin(kx))) * math.sin(th)
	elif t_2 <= 0.92:
		tmp = t_3
	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(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_3 = Float64(Float64(sin(ky) * th) / hypot(sin(kx), sin(ky)))
	tmp = 0.0
	if (t_2 <= -0.95)
		tmp = t_1;
	elseif (t_2 <= -0.13)
		tmp = t_3;
	elseif (t_2 <= 1e-11)
		tmp = Float64(Float64(sin(ky) / hypot(ky, sin(kx))) * sin(th));
	elseif (t_2 <= 0.92)
		tmp = t_3;
	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) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	t_3 = (sin(ky) * th) / hypot(sin(kx), sin(ky));
	tmp = 0.0;
	if (t_2 <= -0.95)
		tmp = t_1;
	elseif (t_2 <= -0.13)
		tmp = t_3;
	elseif (t_2 <= 1e-11)
		tmp = (sin(ky) / hypot(ky, sin(kx))) * sin(th);
	elseif (t_2 <= 0.92)
		tmp = t_3;
	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[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]}, Block[{t$95$3 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -0.95], t$95$1, If[LessEqual[t$95$2, -0.13], t$95$3, If[LessEqual[t$95$2, 1e-11], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.92], t$95$3, 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}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
t_3 := \frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\
\mathbf{if}\;t\_2 \leq -0.95:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_2 \leq -0.13:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_2 \leq 10^{-11}:\\
\;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(ky, \sin kx\right)} \cdot \sin th\\

\mathbf{elif}\;t\_2 \leq 0.92:\\
\;\;\;\;t\_3\\

\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.94999999999999996 or 0.92000000000000004 < (/.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 87.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. 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 \]
    3. Applied rewrites99.9%

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

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

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

      if -0.94999999999999996 < (/.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.13 or 9.99999999999999939e-12 < (/.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.92000000000000004

      1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if -0.13 < (/.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))))) < 9.99999999999999939e-12

        1. Initial program 99.2%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. 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 \]
        3. Applied rewrites99.6%

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

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

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

        Alternative 3: 84.7% 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}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_3 := \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot th\\ \mathbf{if}\;t\_2 \leq -0.95:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -0.13:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-17}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(ky, \sin kx\right)} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 0.92:\\ \;\;\;\;t\_3\\ \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) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
                (t_3 (* (/ (sin ky) (hypot (sin kx) (sin ky))) th)))
           (if (<= t_2 -0.95)
             t_1
             (if (<= t_2 -0.13)
               t_3
               (if (<= t_2 2e-17)
                 (* (/ (sin ky) (hypot ky (sin kx))) (sin th))
                 (if (<= t_2 0.92) t_3 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) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
        	double t_3 = (sin(ky) / hypot(sin(kx), sin(ky))) * th;
        	double tmp;
        	if (t_2 <= -0.95) {
        		tmp = t_1;
        	} else if (t_2 <= -0.13) {
        		tmp = t_3;
        	} else if (t_2 <= 2e-17) {
        		tmp = (sin(ky) / hypot(ky, sin(kx))) * sin(th);
        	} else if (t_2 <= 0.92) {
        		tmp = t_3;
        	} 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.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
        	double t_3 = (Math.sin(ky) / Math.hypot(Math.sin(kx), Math.sin(ky))) * th;
        	double tmp;
        	if (t_2 <= -0.95) {
        		tmp = t_1;
        	} else if (t_2 <= -0.13) {
        		tmp = t_3;
        	} else if (t_2 <= 2e-17) {
        		tmp = (Math.sin(ky) / Math.hypot(ky, Math.sin(kx))) * Math.sin(th);
        	} else if (t_2 <= 0.92) {
        		tmp = t_3;
        	} 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.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
        	t_3 = (math.sin(ky) / math.hypot(math.sin(kx), math.sin(ky))) * th
        	tmp = 0
        	if t_2 <= -0.95:
        		tmp = t_1
        	elif t_2 <= -0.13:
        		tmp = t_3
        	elif t_2 <= 2e-17:
        		tmp = (math.sin(ky) / math.hypot(ky, math.sin(kx))) * math.sin(th)
        	elif t_2 <= 0.92:
        		tmp = t_3
        	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(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
        	t_3 = Float64(Float64(sin(ky) / hypot(sin(kx), sin(ky))) * th)
        	tmp = 0.0
        	if (t_2 <= -0.95)
        		tmp = t_1;
        	elseif (t_2 <= -0.13)
        		tmp = t_3;
        	elseif (t_2 <= 2e-17)
        		tmp = Float64(Float64(sin(ky) / hypot(ky, sin(kx))) * sin(th));
        	elseif (t_2 <= 0.92)
        		tmp = t_3;
        	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) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
        	t_3 = (sin(ky) / hypot(sin(kx), sin(ky))) * th;
        	tmp = 0.0;
        	if (t_2 <= -0.95)
        		tmp = t_1;
        	elseif (t_2 <= -0.13)
        		tmp = t_3;
        	elseif (t_2 <= 2e-17)
        		tmp = (sin(ky) / hypot(ky, sin(kx))) * sin(th);
        	elseif (t_2 <= 0.92)
        		tmp = t_3;
        	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[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]}, Block[{t$95$3 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision]}, If[LessEqual[t$95$2, -0.95], t$95$1, If[LessEqual[t$95$2, -0.13], t$95$3, If[LessEqual[t$95$2, 2e-17], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.92], t$95$3, 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}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
        t_3 := \frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot th\\
        \mathbf{if}\;t\_2 \leq -0.95:\\
        \;\;\;\;t\_1\\
        
        \mathbf{elif}\;t\_2 \leq -0.13:\\
        \;\;\;\;t\_3\\
        
        \mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-17}:\\
        \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(ky, \sin kx\right)} \cdot \sin th\\
        
        \mathbf{elif}\;t\_2 \leq 0.92:\\
        \;\;\;\;t\_3\\
        
        \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.94999999999999996 or 0.92000000000000004 < (/.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 87.5%

            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
          2. 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 \]
          3. Applied rewrites99.9%

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

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

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

            if -0.94999999999999996 < (/.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.13 or 2.00000000000000014e-17 < (/.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.92000000000000004

            1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              if -0.13 < (/.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.00000000000000014e-17

              1. Initial program 99.2%

                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
              2. 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 \]
              3. Applied rewrites99.6%

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

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

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

              Alternative 4: 71.1% accurate, 1.1× speedup?

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

                1. Initial program 94.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                  if 0.00165 < th

                  1. Initial program 93.5%

                    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                  2. 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}}} \]
                  3. Applied rewrites99.5%

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

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

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

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

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

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

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

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

                  Alternative 5: 66.6% accurate, 0.8× speedup?

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

                    1. Initial program 99.6%

                      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                    2. 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 \]
                    3. Applied rewrites99.7%

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

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

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

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

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

                        if -0.0050000000000000001 < (sin.f64 ky) < 2.00000000000000014e-17

                        1. Initial program 87.9%

                          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                        2. 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 \]
                        3. Applied rewrites99.7%

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

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

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

                          if 2.00000000000000014e-17 < (sin.f64 ky)

                          1. Initial program 99.7%

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

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

                              \[\leadsto \sin th \]
                          4. Applied rewrites60.4%

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

                        Alternative 6: 56.2% accurate, 1.1× speedup?

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

                          1. Initial program 93.9%

                            \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                          2. 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 \]
                          3. Applied rewrites99.7%

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

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

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

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

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

                              if 9.99999999999999971e-305 < (sin.f64 ky)

                              1. Initial program 94.0%

                                \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                              2. 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}}} \]
                              3. Applied rewrites96.4%

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

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

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

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

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

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

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

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

                              Alternative 7: 47.8% accurate, 0.3× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, kx\right)\\ t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_2 \leq -0.98:\\ \;\;\;\;\frac{\sin ky}{t\_1} \cdot th\\ \mathbf{elif}\;t\_2 \leq 0.2:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{t\_1} \cdot \sin th\\ \end{array} \end{array} \]
                              (FPCore (kx ky th)
                               :precision binary64
                               (let* ((t_1 (hypot (sin ky) kx))
                                      (t_2 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
                                 (if (<= t_2 -0.98)
                                   (* (/ (sin ky) t_1) th)
                                   (if (<= t_2 0.2)
                                     (* (/ (sin ky) (sin kx)) (sin th))
                                     (if (<= t_2 2.0) (sin th) (* (/ ky t_1) (sin th)))))))
                              double code(double kx, double ky, double th) {
                              	double t_1 = hypot(sin(ky), kx);
                              	double t_2 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
                              	double tmp;
                              	if (t_2 <= -0.98) {
                              		tmp = (sin(ky) / t_1) * th;
                              	} else if (t_2 <= 0.2) {
                              		tmp = (sin(ky) / sin(kx)) * sin(th);
                              	} else if (t_2 <= 2.0) {
                              		tmp = sin(th);
                              	} else {
                              		tmp = (ky / t_1) * sin(th);
                              	}
                              	return tmp;
                              }
                              
                              public static double code(double kx, double ky, double th) {
                              	double t_1 = Math.hypot(Math.sin(ky), kx);
                              	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
                              	double tmp;
                              	if (t_2 <= -0.98) {
                              		tmp = (Math.sin(ky) / t_1) * th;
                              	} else if (t_2 <= 0.2) {
                              		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
                              	} else if (t_2 <= 2.0) {
                              		tmp = Math.sin(th);
                              	} else {
                              		tmp = (ky / t_1) * Math.sin(th);
                              	}
                              	return tmp;
                              }
                              
                              def code(kx, ky, th):
                              	t_1 = math.hypot(math.sin(ky), kx)
                              	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
                              	tmp = 0
                              	if t_2 <= -0.98:
                              		tmp = (math.sin(ky) / t_1) * th
                              	elif t_2 <= 0.2:
                              		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
                              	elif t_2 <= 2.0:
                              		tmp = math.sin(th)
                              	else:
                              		tmp = (ky / t_1) * math.sin(th)
                              	return tmp
                              
                              function code(kx, ky, th)
                              	t_1 = hypot(sin(ky), kx)
                              	t_2 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
                              	tmp = 0.0
                              	if (t_2 <= -0.98)
                              		tmp = Float64(Float64(sin(ky) / t_1) * th);
                              	elseif (t_2 <= 0.2)
                              		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                              	elseif (t_2 <= 2.0)
                              		tmp = sin(th);
                              	else
                              		tmp = Float64(Float64(ky / t_1) * sin(th));
                              	end
                              	return tmp
                              end
                              
                              function tmp_2 = code(kx, ky, th)
                              	t_1 = hypot(sin(ky), kx);
                              	t_2 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
                              	tmp = 0.0;
                              	if (t_2 <= -0.98)
                              		tmp = (sin(ky) / t_1) * th;
                              	elseif (t_2 <= 0.2)
                              		tmp = (sin(ky) / sin(kx)) * sin(th);
                              	elseif (t_2 <= 2.0)
                              		tmp = sin(th);
                              	else
                              		tmp = (ky / t_1) * sin(th);
                              	end
                              	tmp_2 = tmp;
                              end
                              
                              code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]}, Block[{t$95$2 = 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$2, -0.98], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[t$95$2, 0.2], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 2.0], N[Sin[th], $MachinePrecision], N[(N[(ky / t$95$1), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              t_1 := \mathsf{hypot}\left(\sin ky, kx\right)\\
                              t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
                              \mathbf{if}\;t\_2 \leq -0.98:\\
                              \;\;\;\;\frac{\sin ky}{t\_1} \cdot th\\
                              
                              \mathbf{elif}\;t\_2 \leq 0.2:\\
                              \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                              
                              \mathbf{elif}\;t\_2 \leq 2:\\
                              \;\;\;\;\sin th\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\frac{ky}{t\_1} \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))))) < -0.97999999999999998

                                1. Initial program 87.1%

                                  \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                2. 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 \]
                                3. Applied rewrites99.9%

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

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

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

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

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

                                    if -0.97999999999999998 < (/.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.20000000000000001

                                    1. Initial program 99.2%

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

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

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

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

                                    if 0.20000000000000001 < (/.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.5%

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

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

                                        \[\leadsto \sin th \]
                                    4. Applied rewrites68.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. 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.8

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

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

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

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

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

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

                                      Alternative 8: 47.7% accurate, 0.4× 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.2:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \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 0.2)
                                           (* (/ (sin ky) (sin kx)) (sin th))
                                           (if (<= t_1 2.0) (sin th) (* (/ ky (hypot (sin ky) 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 <= 0.2) {
                                      		tmp = (sin(ky) / sin(kx)) * sin(th);
                                      	} else if (t_1 <= 2.0) {
                                      		tmp = sin(th);
                                      	} else {
                                      		tmp = (ky / hypot(sin(ky), kx)) * sin(th);
                                      	}
                                      	return tmp;
                                      }
                                      
                                      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.2) {
                                      		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
                                      	} else if (t_1 <= 2.0) {
                                      		tmp = Math.sin(th);
                                      	} else {
                                      		tmp = (ky / Math.hypot(Math.sin(ky), 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 <= 0.2:
                                      		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
                                      	elif t_1 <= 2.0:
                                      		tmp = math.sin(th)
                                      	else:
                                      		tmp = (ky / math.hypot(math.sin(ky), 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 <= 0.2)
                                      		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
                                      	elseif (t_1 <= 2.0)
                                      		tmp = sin(th);
                                      	else
                                      		tmp = Float64(Float64(ky / hypot(sin(ky), 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 <= 0.2)
                                      		tmp = (sin(ky) / sin(kx)) * sin(th);
                                      	elseif (t_1 <= 2.0)
                                      		tmp = sin(th);
                                      	else
                                      		tmp = (ky / hypot(sin(ky), 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, 0.2], 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[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $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 0.2:\\
                                      \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\
                                      
                                      \mathbf{elif}\;t\_1 \leq 2:\\
                                      \;\;\;\;\sin th\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\frac{ky}{\mathsf{hypot}\left(\sin ky, kx\right)} \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))))) < 0.20000000000000001

                                        1. Initial program 95.5%

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

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

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

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

                                        if 0.20000000000000001 < (/.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.5%

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

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

                                            \[\leadsto \sin th \]
                                        4. Applied rewrites68.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. 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.8

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

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

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

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

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

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

                                          Alternative 9: 46.3% accurate, 0.7× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.2:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin 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)))) 0.2)
                                             (* (/ (sin ky) (sin kx)) (sin 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)))) <= 0.2) {
                                          		tmp = (sin(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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 0.2d0) then
                                                  tmp = (sin(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 tmp;
                                          	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 0.2) {
                                          		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(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)))) <= 0.2:
                                          		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(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)))) <= 0.2)
                                          		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(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)))) <= 0.2)
                                          		tmp = (sin(ky) / sin(kx)) * sin(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], 0.2], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.2:\\
                                          \;\;\;\;\frac{\sin 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))))) < 0.20000000000000001

                                            1. Initial program 95.5%

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

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

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

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

                                            if 0.20000000000000001 < (/.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 90.9%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites66.8%

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

                                          Alternative 10: 45.0% accurate, 0.7× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \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)))) 1e-11)
                                             (* ky (/ (sin th) (sin kx)))
                                             (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)))) <= 1e-11) {
                                          		tmp = ky * (sin(th) / 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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) then
                                                  tmp = ky * (sin(th) / sin(kx))
                                              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)))) <= 1e-11) {
                                          		tmp = ky * (Math.sin(th) / Math.sin(kx));
                                          	} 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)))) <= 1e-11:
                                          		tmp = ky * (math.sin(th) / math.sin(kx))
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
                                          	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)))) <= 1e-11)
                                          		tmp = ky * (sin(th) / sin(kx));
                                          	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], 1e-11], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;ky \cdot \frac{\sin th}{\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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. 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 \]
                                            3. Applied rewrites99.7%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            5. Step-by-step derivation
                                              1. associate-*l/N/A

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

                                                \[\leadsto \frac{\color{blue}{ky} \cdot \sin th}{\sin kx} \]
                                              3. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              4. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              5. +-commutativeN/A

                                                \[\leadsto \frac{ky \cdot \sin \color{blue}{th}}{\sin kx} \]
                                              6. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              7. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              8. lower-/.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                              12. lift-sin.f6433.7

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            6. Applied rewrites33.7%

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

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

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

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

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

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              6. associate-/l*N/A

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

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

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

                                                \[\leadsto ky \cdot \frac{\sin th}{\sin \color{blue}{kx}} \]
                                              10. lift-sin.f6434.7

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

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

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 11: 44.3% accurate, 0.7× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\sin kx}\\ \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)))) 1e-11)
                                             (/ (* (sin th) ky) (sin kx))
                                             (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)))) <= 1e-11) {
                                          		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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) 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 tmp;
                                          	if ((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) <= 1e-11) {
                                          		tmp = (Math.sin(th) * ky) / Math.sin(kx);
                                          	} 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)))) <= 1e-11:
                                          		tmp = (math.sin(th) * ky) / math.sin(kx)
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(Float64(sin(th) * ky) / sin(kx));
                                          	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)))) <= 1e-11)
                                          		tmp = (sin(th) * ky) / sin(kx);
                                          	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], 1e-11], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;\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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            3. 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.f6433.7

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

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

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 12: 36.3% accurate, 0.7× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;\frac{\sin th \cdot ky}{kx}\\ \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)))) 1e-11)
                                             (/ (* (sin th) ky) kx)
                                             (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)))) <= 1e-11) {
                                          		tmp = (sin(th) * ky) / 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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) then
                                                  tmp = (sin(th) * ky) / kx
                                              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)))) <= 1e-11) {
                                          		tmp = (Math.sin(th) * ky) / kx;
                                          	} 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)))) <= 1e-11:
                                          		tmp = (math.sin(th) * ky) / kx
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(Float64(sin(th) * ky) / kx);
                                          	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)))) <= 1e-11)
                                          		tmp = (sin(th) * ky) / kx;
                                          	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], 1e-11], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / kx), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;\frac{\sin th \cdot ky}{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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. 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 \]
                                            3. Applied rewrites99.7%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            5. Step-by-step derivation
                                              1. associate-*l/N/A

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

                                                \[\leadsto \frac{\color{blue}{ky} \cdot \sin th}{\sin kx} \]
                                              3. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              4. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              5. +-commutativeN/A

                                                \[\leadsto \frac{ky \cdot \sin \color{blue}{th}}{\sin kx} \]
                                              6. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              7. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              8. lower-/.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                              12. lift-sin.f6433.7

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            6. Applied rewrites33.7%

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

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{kx} \]
                                              4. lift-*.f6421.2

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

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

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 13: 36.1% accurate, 0.7× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \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)))) 1e-11)
                                             (* ky (/ th (sin kx)))
                                             (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)))) <= 1e-11) {
                                          		tmp = ky * (th / 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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) then
                                                  tmp = ky * (th / sin(kx))
                                              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)))) <= 1e-11) {
                                          		tmp = ky * (th / Math.sin(kx));
                                          	} 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)))) <= 1e-11:
                                          		tmp = ky * (th / math.sin(kx))
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(ky * Float64(th / sin(kx)));
                                          	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)))) <= 1e-11)
                                          		tmp = ky * (th / sin(kx));
                                          	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], 1e-11], N[(ky * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;ky \cdot \frac{th}{\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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. 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 \]
                                            3. Applied rewrites99.7%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            5. Step-by-step derivation
                                              1. associate-*l/N/A

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

                                                \[\leadsto \frac{\color{blue}{ky} \cdot \sin th}{\sin kx} \]
                                              3. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              4. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              5. +-commutativeN/A

                                                \[\leadsto \frac{ky \cdot \sin \color{blue}{th}}{\sin kx} \]
                                              6. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              7. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              8. lower-/.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                              12. lift-sin.f6433.7

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            6. Applied rewrites33.7%

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

                                              \[\leadsto \frac{ky \cdot th}{\color{blue}{\sin kx}} \]
                                            8. Step-by-step derivation
                                              1. associate-/l*N/A

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

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

                                                \[\leadsto ky \cdot \frac{th}{\sin kx} \]
                                              4. lift-sin.f6421.3

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

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

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 14: 34.1% accurate, 0.8× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \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)))) 1e-11)
                                             (* ky (/ th kx))
                                             (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)))) <= 1e-11) {
                                          		tmp = ky * (th / 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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) then
                                                  tmp = ky * (th / kx)
                                              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)))) <= 1e-11) {
                                          		tmp = ky * (th / kx);
                                          	} 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)))) <= 1e-11:
                                          		tmp = ky * (th / kx)
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(ky * Float64(th / kx));
                                          	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)))) <= 1e-11)
                                          		tmp = ky * (th / kx);
                                          	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], 1e-11], N[(ky * N[(th / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;ky \cdot \frac{th}{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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. 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 \]
                                            3. Applied rewrites99.7%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            5. Step-by-step derivation
                                              1. associate-*l/N/A

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

                                                \[\leadsto \frac{\color{blue}{ky} \cdot \sin th}{\sin kx} \]
                                              3. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              4. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              5. +-commutativeN/A

                                                \[\leadsto \frac{ky \cdot \sin \color{blue}{th}}{\sin kx} \]
                                              6. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              7. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              8. lower-/.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                              12. lift-sin.f6433.7

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            6. Applied rewrites33.7%

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

                                              \[\leadsto \frac{ky \cdot th}{\color{blue}{\sin kx}} \]
                                            8. Step-by-step derivation
                                              1. associate-/l*N/A

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

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

                                                \[\leadsto ky \cdot \frac{th}{\sin kx} \]
                                              4. lift-sin.f6421.3

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

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

                                              \[\leadsto ky \cdot \frac{th}{kx} \]
                                            11. Step-by-step derivation
                                              1. lower-/.f6418.1

                                                \[\leadsto ky \cdot \frac{th}{kx} \]
                                            12. Applied rewrites18.1%

                                              \[\leadsto ky \cdot \frac{th}{kx} \]

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 15: 33.5% accurate, 0.8× speedup?

                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\ \;\;\;\;\frac{th \cdot ky}{kx}\\ \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)))) 1e-11)
                                             (/ (* th ky) kx)
                                             (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)))) <= 1e-11) {
                                          		tmp = (th * ky) / 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) :: tmp
                                              if ((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) <= 1d-11) then
                                                  tmp = (th * ky) / kx
                                              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)))) <= 1e-11) {
                                          		tmp = (th * ky) / kx;
                                          	} 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)))) <= 1e-11:
                                          		tmp = (th * ky) / kx
                                          	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)))) <= 1e-11)
                                          		tmp = Float64(Float64(th * ky) / kx);
                                          	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)))) <= 1e-11)
                                          		tmp = (th * ky) / kx;
                                          	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], 1e-11], N[(N[(th * ky), $MachinePrecision] / kx), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \begin{array}{l}
                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-11}:\\
                                          \;\;\;\;\frac{th \cdot ky}{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))))) < 9.99999999999999939e-12

                                            1. Initial program 95.4%

                                              \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
                                            2. 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 \]
                                            3. Applied rewrites99.7%

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

                                              \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
                                            5. Step-by-step derivation
                                              1. associate-*l/N/A

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

                                                \[\leadsto \frac{\color{blue}{ky} \cdot \sin th}{\sin kx} \]
                                              3. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              4. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              5. +-commutativeN/A

                                                \[\leadsto \frac{ky \cdot \sin \color{blue}{th}}{\sin kx} \]
                                              6. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              7. pow2N/A

                                                \[\leadsto \frac{ky \cdot \sin th}{\sin kx} \]
                                              8. lower-/.f64N/A

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

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

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

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                              12. lift-sin.f6433.7

                                                \[\leadsto \frac{\sin th \cdot ky}{\sin kx} \]
                                            6. Applied rewrites33.7%

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

                                              \[\leadsto \frac{ky \cdot th}{\color{blue}{\sin kx}} \]
                                            8. Step-by-step derivation
                                              1. associate-/l*N/A

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

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

                                                \[\leadsto ky \cdot \frac{th}{\sin kx} \]
                                              4. lift-sin.f6421.3

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

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

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

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

                                                \[\leadsto \frac{th \cdot ky}{kx} \]
                                              3. lower-*.f6417.1

                                                \[\leadsto \frac{th \cdot ky}{kx} \]
                                            12. Applied rewrites17.1%

                                              \[\leadsto \frac{th \cdot ky}{kx} \]

                                            if 9.99999999999999939e-12 < (/.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.3%

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

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

                                                \[\leadsto \sin th \]
                                            4. Applied rewrites64.5%

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

                                          Alternative 16: 24.7% accurate, 8.0× speedup?

                                          \[\begin{array}{l} \\ \sin th \end{array} \]
                                          (FPCore (kx ky th) :precision binary64 (sin th))
                                          double code(double kx, double ky, double th) {
                                          	return 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(th)
                                          end function
                                          
                                          public static double code(double kx, double ky, double th) {
                                          	return Math.sin(th);
                                          }
                                          
                                          def code(kx, ky, th):
                                          	return math.sin(th)
                                          
                                          function code(kx, ky, th)
                                          	return sin(th)
                                          end
                                          
                                          function tmp = code(kx, ky, th)
                                          	tmp = sin(th);
                                          end
                                          
                                          code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
                                          
                                          \begin{array}{l}
                                          
                                          \\
                                          \sin th
                                          \end{array}
                                          
                                          Derivation
                                          1. Initial program 94.0%

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

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

                                              \[\leadsto \sin th \]
                                          4. Applied rewrites24.7%

                                            \[\leadsto \color{blue}{\sin th} \]
                                          5. Add Preprocessing

                                          Reproduce

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