Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 7.9s
Alternatives: 22
Speedup: 1.2×

Specification

?
\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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 22 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.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))
double code(double kx, double ky, double th) {
	return (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

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

real(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)
end function
public static double code(double kx, double ky, double th) {
	return (Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th);
}
def code(kx, ky, th):
	return (math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)
function code(kx, ky, th)
	return Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th))
end
function tmp = code(kx, ky, th)
	tmp = (sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th);
end
code[kx_, ky_, th_] := N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.7% accurate, 1.2× speedup?

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

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

    \[\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. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{1 \cdot \sin th}{\frac{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}{\color{blue}{\sin ky}}} \]
    9. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

Alternative 2: 99.6% accurate, 1.2× speedup?

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

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

    \[\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 3: 66.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;th \leq 5.5 \cdot 10^{-12}:\\
\;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 5.5000000000000004e-12

    1. Initial program 94.3%

      \[\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 th around 0

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

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

      if 5.5000000000000004e-12 < th

      1. Initial program 94.3%

        \[\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-sin.f64N/A

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

          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
        4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
        6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
            4. associate-*l/N/A

              \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
            5. *-lft-identityN/A

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

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

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

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

        Alternative 4: 65.9% accurate, 1.4× speedup?

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

          1. Initial program 94.3%

            \[\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. Step-by-step derivation
            1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

              \[\leadsto \frac{1 \cdot \sin th}{\frac{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}{\color{blue}{\sin ky}}} \]
            9. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

            if 1.0799999999999999e-13 < th

            1. Initial program 94.3%

              \[\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-sin.f64N/A

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

                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
              4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
              6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                  4. associate-*l/N/A

                    \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                  5. *-lft-identityN/A

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

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

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

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

              Alternative 5: 65.8% accurate, 1.5× speedup?

              \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky\\ \mathbf{if}\;ky \leq 2.1:\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, t\_1\right)} \cdot t\_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(ky + ky\right) \cdot 0.5}} \cdot \sin th\\ \end{array} \end{array} \]
              (FPCore (kx ky th)
               :precision binary64
               (let* ((t_1 (* (fma (* ky ky) -0.16666666666666666 1.0) ky)))
                 (if (<= ky 2.1)
                   (* (/ (sin th) (hypot (sin kx) t_1)) t_1)
                   (* (/ (sin ky) (sqrt (- 0.5 (* (cos (+ ky ky)) 0.5)))) (sin th)))))
              double code(double kx, double ky, double th) {
              	double t_1 = fma((ky * ky), -0.16666666666666666, 1.0) * ky;
              	double tmp;
              	if (ky <= 2.1) {
              		tmp = (sin(th) / hypot(sin(kx), t_1)) * t_1;
              	} else {
              		tmp = (sin(ky) / sqrt((0.5 - (cos((ky + ky)) * 0.5)))) * sin(th);
              	}
              	return tmp;
              }
              
              function code(kx, ky, th)
              	t_1 = Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky)
              	tmp = 0.0
              	if (ky <= 2.1)
              		tmp = Float64(Float64(sin(th) / hypot(sin(kx), t_1)) * t_1);
              	else
              		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(cos(Float64(ky + ky)) * 0.5)))) * sin(th));
              	end
              	return tmp
              end
              
              code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision]}, If[LessEqual[ky, 2.1], N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]
              
              \begin{array}{l}
              
              \\
              \begin{array}{l}
              t_1 := \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky\\
              \mathbf{if}\;ky \leq 2.1:\\
              \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, t\_1\right)} \cdot t\_1\\
              
              \mathbf{else}:\\
              \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(ky + ky\right) \cdot 0.5}} \cdot \sin th\\
              
              
              \end{array}
              \end{array}
              
              Derivation
              1. Split input into 2 regimes
              2. if ky < 2.10000000000000009

                1. Initial program 94.3%

                  \[\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. Step-by-step derivation
                  1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    \[\leadsto \frac{1 \cdot \sin th}{\frac{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}{\color{blue}{\sin ky}}} \]
                  9. *-lft-identityN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                if 2.10000000000000009 < ky

                1. Initial program 94.3%

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

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \sin ky \cdot \sin ky\right)}} \cdot \sin th \]
                  4. sqr-sin-aN/A

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

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th \]
                4. Applied rewrites43.6%

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
                  2. sqr-sin-a-revN/A

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

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

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

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

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

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

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

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

              Alternative 6: 64.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.98:\\ \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(\mathsf{fma}\left(kx \cdot kx, -0.16666666666666666, 1\right) \cdot kx, \sin ky\right)}{\sin ky}}\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-264}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(kx + kx\right) \cdot 0.5}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\ \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.98)
                   (/
                    (* (fma (* th th) -0.16666666666666666 1.0) th)
                    (/
                     (hypot (* (fma (* kx kx) -0.16666666666666666 1.0) kx) (sin ky))
                     (sin ky)))
                   (if (<= t_1 5e-264)
                     (* (/ (sin ky) (sqrt (- 0.5 (* (cos (+ kx kx)) 0.5)))) (sin th))
                     (/ (sin th) (/ (hypot ky (sin kx)) ky))))))
              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.98) {
              		tmp = (fma((th * th), -0.16666666666666666, 1.0) * th) / (hypot((fma((kx * kx), -0.16666666666666666, 1.0) * kx), sin(ky)) / sin(ky));
              	} else if (t_1 <= 5e-264) {
              		tmp = (sin(ky) / sqrt((0.5 - (cos((kx + kx)) * 0.5)))) * sin(th);
              	} else {
              		tmp = sin(th) / (hypot(ky, sin(kx)) / ky);
              	}
              	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.98)
              		tmp = Float64(Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th) / Float64(hypot(Float64(fma(Float64(kx * kx), -0.16666666666666666, 1.0) * kx), sin(ky)) / sin(ky)));
              	elseif (t_1 <= 5e-264)
              		tmp = Float64(Float64(sin(ky) / sqrt(Float64(0.5 - Float64(cos(Float64(kx + kx)) * 0.5)))) * sin(th));
              	else
              		tmp = Float64(sin(th) / Float64(hypot(ky, sin(kx)) / ky));
              	end
              	return 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.98], N[(N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision] / N[(N[Sqrt[N[(N[(N[(kx * kx), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * kx), $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e-264], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / ky), $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.98:\\
              \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(\mathsf{fma}\left(kx \cdot kx, -0.16666666666666666, 1\right) \cdot kx, \sin ky\right)}{\sin ky}}\\
              
              \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-264}:\\
              \;\;\;\;\frac{\sin ky}{\sqrt{0.5 - \cos \left(kx + kx\right) \cdot 0.5}} \cdot \sin th\\
              
              \mathbf{else}:\\
              \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\
              
              
              \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.97999999999999998

                1. Initial program 94.3%

                  \[\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. Step-by-step derivation
                  1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                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))))) < 5.0000000000000001e-264

                1. Initial program 94.3%

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

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \sin ky \cdot \sin ky\right)}} \cdot \sin th \]
                  4. sqr-sin-aN/A

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

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th \]
                4. Applied rewrites43.6%

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

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

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

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

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

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

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

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

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

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

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

                if 5.0000000000000001e-264 < (/.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 94.3%

                  \[\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-sin.f64N/A

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

                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                  4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                  6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                      4. associate-*l/N/A

                        \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                      5. *-lft-identityN/A

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

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

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

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

                  Alternative 7: 64.7% accurate, 0.7× speedup?

                  \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\ \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\ \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.02)
                     (/
                      (* (fma (* th th) -0.16666666666666666 1.0) th)
                      (/ (hypot kx (sin ky)) (sin ky)))
                     (/ (sin th) (/ (hypot ky (sin kx)) ky))))
                  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.02) {
                  		tmp = (fma((th * th), -0.16666666666666666, 1.0) * th) / (hypot(kx, sin(ky)) / sin(ky));
                  	} else {
                  		tmp = sin(th) / (hypot(ky, sin(kx)) / ky);
                  	}
                  	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.02)
                  		tmp = Float64(Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th) / Float64(hypot(kx, sin(ky)) / sin(ky)));
                  	else
                  		tmp = Float64(sin(th) / Float64(hypot(ky, sin(kx)) / ky));
                  	end
                  	return tmp
                  end
                  
                  code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision] / N[(N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]
                  
                  \begin{array}{l}
                  
                  \\
                  \begin{array}{l}
                  \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\
                  \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(kx, \sin ky\right)}{\sin ky}}\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\
                  
                  
                  \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.0200000000000000004

                    1. Initial program 94.3%

                      \[\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. Step-by-step derivation
                      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                      if -0.0200000000000000004 < (/.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 94.3%

                        \[\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-sin.f64N/A

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

                          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                        4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                        6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                            4. associate-*l/N/A

                              \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                            5. *-lft-identityN/A

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

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

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

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

                        Alternative 8: 59.7% accurate, 0.8× speedup?

                        \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\ \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.02)
                           (* (/ (sin ky) (sqrt (fma kx kx (- 0.5 (* 0.5 (cos (* 2.0 ky))))))) th)
                           (/ (sin th) (/ (hypot ky (sin kx)) ky))))
                        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.02) {
                        		tmp = (sin(ky) / sqrt(fma(kx, kx, (0.5 - (0.5 * cos((2.0 * ky))))))) * th;
                        	} else {
                        		tmp = sin(th) / (hypot(ky, sin(kx)) / ky);
                        	}
                        	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.02)
                        		tmp = Float64(Float64(sin(ky) / sqrt(fma(kx, kx, Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * ky))))))) * th);
                        	else
                        		tmp = Float64(sin(th) / Float64(hypot(ky, sin(kx)) / ky));
                        	end
                        	return tmp
                        end
                        
                        code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(kx * kx + N[(0.5 - N[(0.5 * N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]
                        
                        \begin{array}{l}
                        
                        \\
                        \begin{array}{l}
                        \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\
                        \;\;\;\;\frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot th\\
                        
                        \mathbf{else}:\\
                        \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\
                        
                        
                        \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.0200000000000000004

                          1. Initial program 94.3%

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

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

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

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

                              \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \sin ky \cdot \sin ky\right)}} \cdot \sin th \]
                            4. sqr-sin-aN/A

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

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

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

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

                              \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th \]
                          4. Applied rewrites43.6%

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

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

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

                            if -0.0200000000000000004 < (/.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 94.3%

                              \[\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-sin.f64N/A

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

                                \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                              4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                              6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                                  4. associate-*l/N/A

                                    \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                                  5. *-lft-identityN/A

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

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

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

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

                              Alternative 9: 59.5% accurate, 0.8× speedup?

                              \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\ \;\;\;\;\frac{\sin ky \cdot th}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5\right) - \cos \left(ky + ky\right) \cdot 0.5}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\ \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.02)
                                 (/ (* (sin ky) th) (sqrt (- (fma kx kx 0.5) (* (cos (+ ky ky)) 0.5))))
                                 (/ (sin th) (/ (hypot ky (sin kx)) ky))))
                              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.02) {
                              		tmp = (sin(ky) * th) / sqrt((fma(kx, kx, 0.5) - (cos((ky + ky)) * 0.5)));
                              	} else {
                              		tmp = sin(th) / (hypot(ky, sin(kx)) / ky);
                              	}
                              	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.02)
                              		tmp = Float64(Float64(sin(ky) * th) / sqrt(Float64(fma(kx, kx, 0.5) - Float64(cos(Float64(ky + ky)) * 0.5))));
                              	else
                              		tmp = Float64(sin(th) / Float64(hypot(ky, sin(kx)) / ky));
                              	end
                              	return tmp
                              end
                              
                              code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.02], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / N[Sqrt[N[(N[(kx * kx + 0.5), $MachinePrecision] - N[(N[Cos[N[(ky + ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]
                              
                              \begin{array}{l}
                              
                              \\
                              \begin{array}{l}
                              \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.02:\\
                              \;\;\;\;\frac{\sin ky \cdot th}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5\right) - \cos \left(ky + ky\right) \cdot 0.5}}\\
                              
                              \mathbf{else}:\\
                              \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\
                              
                              
                              \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.0200000000000000004

                                1. Initial program 94.3%

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

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

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

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

                                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \sin ky \cdot \sin ky\right)}} \cdot \sin th \]
                                  4. sqr-sin-aN/A

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

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

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

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

                                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th \]
                                4. Applied rewrites43.6%

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}}} \cdot \sin th \]
                                5. Step-by-step derivation
                                  1. lift-*.f64N/A

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

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

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

                                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \color{blue}{\sin th} \]
                                  5. associate-*l/N/A

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

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

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

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

                                    \[\leadsto \frac{\color{blue}{\sin th} \cdot \sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}} \]
                                  10. lift-sin.f6442.5

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

                                    \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{kx \cdot kx + \color{blue}{\left(\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot ky\right)\right)}}} \]
                                6. Applied rewrites34.8%

                                  \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5\right) - \cos \left(ky + ky\right) \cdot 0.5}}} \]
                                7. Taylor expanded in th around 0

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

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

                                    \[\leadsto \frac{\sin ky \cdot \color{blue}{th}}{\sqrt{\mathsf{fma}\left(kx, kx, \frac{1}{2}\right) - \cos \left(ky + ky\right) \cdot \frac{1}{2}}} \]
                                  3. lift-sin.f6421.6

                                    \[\leadsto \frac{\sin ky \cdot th}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5\right) - \cos \left(ky + ky\right) \cdot 0.5}} \]
                                9. Applied rewrites21.6%

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

                                if -0.0200000000000000004 < (/.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 94.3%

                                  \[\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-sin.f64N/A

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

                                    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                  4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                                  6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                                      4. associate-*l/N/A

                                        \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                                      5. *-lft-identityN/A

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

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

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

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

                                  Alternative 10: 57.2% accurate, 1.4× speedup?

                                  \[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky\\ \mathbf{if}\;\sin ky \leq -0.3:\\ \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(\sin kx, t\_1\right)}{t\_1}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\ \end{array} \end{array} \]
                                  (FPCore (kx ky th)
                                   :precision binary64
                                   (let* ((t_1 (* (fma (* ky ky) -0.16666666666666666 1.0) ky)))
                                     (if (<= (sin ky) -0.3)
                                       (/
                                        (* (fma (* th th) -0.16666666666666666 1.0) th)
                                        (/ (hypot (sin kx) t_1) t_1))
                                       (/ (sin th) (/ (hypot ky (sin kx)) ky)))))
                                  double code(double kx, double ky, double th) {
                                  	double t_1 = fma((ky * ky), -0.16666666666666666, 1.0) * ky;
                                  	double tmp;
                                  	if (sin(ky) <= -0.3) {
                                  		tmp = (fma((th * th), -0.16666666666666666, 1.0) * th) / (hypot(sin(kx), t_1) / t_1);
                                  	} else {
                                  		tmp = sin(th) / (hypot(ky, sin(kx)) / ky);
                                  	}
                                  	return tmp;
                                  }
                                  
                                  function code(kx, ky, th)
                                  	t_1 = Float64(fma(Float64(ky * ky), -0.16666666666666666, 1.0) * ky)
                                  	tmp = 0.0
                                  	if (sin(ky) <= -0.3)
                                  		tmp = Float64(Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th) / Float64(hypot(sin(kx), t_1) / t_1));
                                  	else
                                  		tmp = Float64(sin(th) / Float64(hypot(ky, sin(kx)) / ky));
                                  	end
                                  	return tmp
                                  end
                                  
                                  code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[(ky * ky), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * ky), $MachinePrecision]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -0.3], N[(N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision] / N[(N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[ky ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]]]
                                  
                                  \begin{array}{l}
                                  
                                  \\
                                  \begin{array}{l}
                                  t_1 := \mathsf{fma}\left(ky \cdot ky, -0.16666666666666666, 1\right) \cdot ky\\
                                  \mathbf{if}\;\sin ky \leq -0.3:\\
                                  \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\mathsf{hypot}\left(\sin kx, t\_1\right)}{t\_1}}\\
                                  
                                  \mathbf{else}:\\
                                  \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{ky}}\\
                                  
                                  
                                  \end{array}
                                  \end{array}
                                  
                                  Derivation
                                  1. Split input into 2 regimes
                                  2. if (sin.f64 ky) < -0.299999999999999989

                                    1. Initial program 94.3%

                                      \[\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. Step-by-step derivation
                                      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if -0.299999999999999989 < (sin.f64 ky)

                                    1. Initial program 94.3%

                                      \[\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-sin.f64N/A

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

                                        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                      4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                                      6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                            \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                                          4. associate-*l/N/A

                                            \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                                          5. *-lft-identityN/A

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

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

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

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

                                      Alternative 11: 56.9% accurate, 2.0× speedup?

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

                                        \[\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-sin.f64N/A

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

                                          \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
                                        4. lift-+.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{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
                                        6. lift-sin.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                              \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}} \cdot \color{blue}{\sin th} \]
                                            4. associate-*l/N/A

                                              \[\leadsto \color{blue}{\frac{1 \cdot \sin th}{\frac{\mathsf{hypot}\left(\sin kx, ky\right)}{ky}}} \]
                                            5. *-lft-identityN/A

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

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

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

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

                                          Alternative 12: 56.1% accurate, 2.0× speedup?

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

                                            \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                          5. Step-by-step derivation
                                            1. Applied rewrites50.5%

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

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

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

                                              Alternative 13: 56.0% accurate, 1.2× speedup?

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

                                                1. Initial program 94.3%

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

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

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

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

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, \sin ky \cdot \sin ky\right)}} \cdot \sin th \]
                                                  4. sqr-sin-aN/A

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

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

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

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

                                                    \[\leadsto \frac{\sin ky}{\sqrt{\mathsf{fma}\left(kx, kx, 0.5 - 0.5 \cdot \cos \left(2 \cdot ky\right)\right)}} \cdot \sin th \]
                                                4. Applied rewrites43.6%

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{0.5 - \cos \left(kx + kx\right) \cdot 0.5}}} \cdot \sin th \]
                                                8. Taylor expanded in th around 0

                                                  \[\leadsto \frac{\sin ky}{\sqrt{\frac{1}{2} - \cos \left(kx + kx\right) \cdot \frac{1}{2}}} \cdot \color{blue}{th} \]
                                                9. Step-by-step derivation
                                                  1. Applied rewrites16.6%

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

                                                  if -0.10000000000000001 < (sin.f64 kx) < 0.170000000000000012

                                                  1. Initial program 94.3%

                                                    \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                  5. Step-by-step derivation
                                                    1. Applied rewrites50.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                      if 0.170000000000000012 < (sin.f64 kx)

                                                      1. Initial program 94.3%

                                                        \[\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.f6423.8

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

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

                                                    Alternative 14: 48.2% accurate, 1.2× speedup?

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

                                                      1. Initial program 94.3%

                                                        \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                      5. Step-by-step derivation
                                                        1. Applied rewrites50.5%

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

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

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

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

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

                                                            if 1.00000000000000003e-306 < (sin.f64 kx) < 0.170000000000000012

                                                            1. Initial program 94.3%

                                                              \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                            5. Step-by-step derivation
                                                              1. Applied rewrites50.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                if 0.170000000000000012 < (sin.f64 kx)

                                                                1. Initial program 94.3%

                                                                  \[\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.f6423.8

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

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

                                                              Alternative 15: 47.6% accurate, 1.2× speedup?

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

                                                                1. Initial program 94.3%

                                                                  \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                                5. Step-by-step derivation
                                                                  1. Applied rewrites50.5%

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

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

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

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

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

                                                                      if 1.00000000000000003e-306 < (sin.f64 kx) < 0.0100000000000000002

                                                                      1. Initial program 94.3%

                                                                        \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                                      5. Step-by-step derivation
                                                                        1. Applied rewrites50.5%

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

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

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

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

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

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

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

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

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

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

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

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

                                                                          if 0.0100000000000000002 < (sin.f64 kx)

                                                                          1. Initial program 94.3%

                                                                            \[\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.f6423.8

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

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

                                                                        Alternative 16: 46.9% accurate, 3.1× speedup?

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

                                                                          1. Initial program 94.3%

                                                                            \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                                          5. Step-by-step derivation
                                                                            1. Applied rewrites50.5%

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

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

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

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

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

                                                                                if 1.6999999999999999e-9 < th

                                                                                1. Initial program 94.3%

                                                                                  \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                                                5. Step-by-step derivation
                                                                                  1. Applied rewrites50.5%

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

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

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

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

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

                                                                                    Alternative 17: 42.8% accurate, 1.9× speedup?

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

                                                                                      1. Initial program 94.3%

                                                                                        \[\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{\color{blue}{ky}}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
                                                                                      5. Step-by-step derivation
                                                                                        1. Applied rewrites50.5%

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

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

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

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

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

                                                                                            if 0.19700000000000001 < (sin.f64 kx)

                                                                                            1. Initial program 94.3%

                                                                                              \[\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. Step-by-step derivation
                                                                                              1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                          Alternative 18: 35.7% accurate, 0.9× speedup?

                                                                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 2 \cdot 10^{-10}:\\ \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\sin kx}{ky}}\\ \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)))) 2e-10)
                                                                                             (/ (* (fma (* th th) -0.16666666666666666 1.0) th) (/ (sin kx) ky))
                                                                                             (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)))) <= 2e-10) {
                                                                                          		tmp = (fma((th * th), -0.16666666666666666, 1.0) * th) / (sin(kx) / ky);
                                                                                          	} else {
                                                                                          		tmp = sin(th);
                                                                                          	}
                                                                                          	return tmp;
                                                                                          }
                                                                                          
                                                                                          function code(kx, ky, th)
                                                                                          	tmp = 0.0
                                                                                          	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 2e-10)
                                                                                          		tmp = Float64(Float64(fma(Float64(th * th), -0.16666666666666666, 1.0) * th) / Float64(sin(kx) / ky));
                                                                                          	else
                                                                                          		tmp = sin(th);
                                                                                          	end
                                                                                          	return tmp
                                                                                          end
                                                                                          
                                                                                          code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2e-10], N[(N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666 + 1.0), $MachinePrecision] * th), $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $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 2 \cdot 10^{-10}:\\
                                                                                          \;\;\;\;\frac{\mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th}{\frac{\sin kx}{ky}}\\
                                                                                          
                                                                                          \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))))) < 2.00000000000000007e-10

                                                                                            1. Initial program 94.3%

                                                                                              \[\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. Step-by-step derivation
                                                                                              1. lift-*.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                                                            if 2.00000000000000007e-10 < (/.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 94.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.f6424.2

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

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

                                                                                          Alternative 19: 31.4% accurate, 1.0× speedup?

                                                                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 1.55 \cdot 10^{-23}:\\ \;\;\;\;\left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666\\ \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))))
                                                                                                1.55e-23)
                                                                                             (* (* (* th th) th) -0.16666666666666666)
                                                                                             (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)))) <= 1.55e-23) {
                                                                                          		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                          	} 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)))) <= 1.55d-23) then
                                                                                                  tmp = ((th * th) * th) * (-0.16666666666666666d0)
                                                                                              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)))) <= 1.55e-23) {
                                                                                          		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                          	} 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)))) <= 1.55e-23:
                                                                                          		tmp = ((th * th) * th) * -0.16666666666666666
                                                                                          	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)))) <= 1.55e-23)
                                                                                          		tmp = Float64(Float64(Float64(th * th) * th) * -0.16666666666666666);
                                                                                          	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)))) <= 1.55e-23)
                                                                                          		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                          	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], 1.55e-23], N[(N[(N[(th * th), $MachinePrecision] * th), $MachinePrecision] * -0.16666666666666666), $MachinePrecision], N[Sin[th], $MachinePrecision]]
                                                                                          
                                                                                          \begin{array}{l}
                                                                                          
                                                                                          \\
                                                                                          \begin{array}{l}
                                                                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 1.55 \cdot 10^{-23}:\\
                                                                                          \;\;\;\;\left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666\\
                                                                                          
                                                                                          \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))))) < 1.5499999999999999e-23

                                                                                            1. Initial program 94.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.f6424.2

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

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

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

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

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

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

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

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

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

                                                                                                \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th \]
                                                                                            7. Applied rewrites13.5%

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

                                                                                              \[\leadsto \frac{-1}{6} \cdot {th}^{\color{blue}{3}} \]
                                                                                            9. Step-by-step derivation
                                                                                              1. *-commutativeN/A

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

                                                                                                \[\leadsto {th}^{3} \cdot \frac{-1}{6} \]
                                                                                              3. unpow3N/A

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

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

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

                                                                                                \[\leadsto \left(\left(th \cdot th\right) \cdot th\right) \cdot \frac{-1}{6} \]
                                                                                              7. lift-*.f6410.9

                                                                                                \[\leadsto \left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666 \]
                                                                                            10. Applied rewrites10.9%

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

                                                                                            if 1.5499999999999999e-23 < (/.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 94.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.f6424.2

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

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

                                                                                          Alternative 20: 15.5% accurate, 0.9× speedup?

                                                                                          \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 10^{-299}:\\ \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
                                                                                          (FPCore (kx ky th)
                                                                                           :precision binary64
                                                                                           (if (<=
                                                                                                (*
                                                                                                 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))
                                                                                                 (sin th))
                                                                                                1e-299)
                                                                                             (* (* (* th th) -0.16666666666666666) th)
                                                                                             th))
                                                                                          double code(double kx, double ky, double th) {
                                                                                          	double tmp;
                                                                                          	if (((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th)) <= 1e-299) {
                                                                                          		tmp = ((th * th) * -0.16666666666666666) * th;
                                                                                          	} else {
                                                                                          		tmp = th;
                                                                                          	}
                                                                                          	return tmp;
                                                                                          }
                                                                                          
                                                                                          module fmin_fmax_functions
                                                                                              implicit none
                                                                                              private
                                                                                              public fmax
                                                                                              public fmin
                                                                                          
                                                                                              interface fmax
                                                                                                  module procedure fmax88
                                                                                                  module procedure fmax44
                                                                                                  module procedure fmax84
                                                                                                  module procedure fmax48
                                                                                              end interface
                                                                                              interface fmin
                                                                                                  module procedure fmin88
                                                                                                  module procedure fmin44
                                                                                                  module procedure fmin84
                                                                                                  module procedure fmin48
                                                                                              end interface
                                                                                          contains
                                                                                              real(8) function fmax88(x, y) result (res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(4) function fmax44(x, y) result (res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmax84(x, y) result(res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmax48(x, y) result(res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin88(x, y) result (res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(4) function fmin44(x, y) result (res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin84(x, y) result(res)
                                                                                                  real(8), intent (in) :: x
                                                                                                  real(4), intent (in) :: y
                                                                                                  res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                              end function
                                                                                              real(8) function fmin48(x, y) result(res)
                                                                                                  real(4), intent (in) :: x
                                                                                                  real(8), intent (in) :: y
                                                                                                  res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                              end function
                                                                                          end module
                                                                                          
                                                                                          real(8) function code(kx, ky, th)
                                                                                          use fmin_fmax_functions
                                                                                              real(8), intent (in) :: kx
                                                                                              real(8), intent (in) :: ky
                                                                                              real(8), intent (in) :: th
                                                                                              real(8) :: tmp
                                                                                              if (((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)) <= 1d-299) then
                                                                                                  tmp = ((th * th) * (-0.16666666666666666d0)) * th
                                                                                              else
                                                                                                  tmp = th
                                                                                              end if
                                                                                              code = tmp
                                                                                          end function
                                                                                          
                                                                                          public static double code(double kx, double ky, double th) {
                                                                                          	double tmp;
                                                                                          	if (((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th)) <= 1e-299) {
                                                                                          		tmp = ((th * th) * -0.16666666666666666) * th;
                                                                                          	} else {
                                                                                          		tmp = th;
                                                                                          	}
                                                                                          	return tmp;
                                                                                          }
                                                                                          
                                                                                          def code(kx, ky, th):
                                                                                          	tmp = 0
                                                                                          	if ((math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)) <= 1e-299:
                                                                                          		tmp = ((th * th) * -0.16666666666666666) * th
                                                                                          	else:
                                                                                          		tmp = th
                                                                                          	return tmp
                                                                                          
                                                                                          function code(kx, ky, th)
                                                                                          	tmp = 0.0
                                                                                          	if (Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 1e-299)
                                                                                          		tmp = Float64(Float64(Float64(th * th) * -0.16666666666666666) * th);
                                                                                          	else
                                                                                          		tmp = th;
                                                                                          	end
                                                                                          	return tmp
                                                                                          end
                                                                                          
                                                                                          function tmp_2 = code(kx, ky, th)
                                                                                          	tmp = 0.0;
                                                                                          	if (((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 1e-299)
                                                                                          		tmp = ((th * th) * -0.16666666666666666) * th;
                                                                                          	else
                                                                                          		tmp = th;
                                                                                          	end
                                                                                          	tmp_2 = tmp;
                                                                                          end
                                                                                          
                                                                                          code[kx_, ky_, th_] := If[LessEqual[N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], 1e-299], N[(N[(N[(th * th), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] * th), $MachinePrecision], th]
                                                                                          
                                                                                          \begin{array}{l}
                                                                                          
                                                                                          \\
                                                                                          \begin{array}{l}
                                                                                          \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 10^{-299}:\\
                                                                                          \;\;\;\;\left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th\\
                                                                                          
                                                                                          \mathbf{else}:\\
                                                                                          \;\;\;\;th\\
                                                                                          
                                                                                          
                                                                                          \end{array}
                                                                                          \end{array}
                                                                                          
                                                                                          Derivation
                                                                                          1. Split input into 2 regimes
                                                                                          2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 9.99999999999999992e-300

                                                                                            1. Initial program 94.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.f6424.2

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

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

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

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

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

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

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

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

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

                                                                                                \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th \]
                                                                                            7. Applied rewrites13.5%

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

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

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

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

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

                                                                                                \[\leadsto \left(\left(th \cdot th\right) \cdot -0.16666666666666666\right) \cdot th \]
                                                                                            10. Applied rewrites10.9%

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

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

                                                                                            1. Initial program 94.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.f6424.2

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

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

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

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

                                                                                            Alternative 21: 15.5% accurate, 0.9× speedup?

                                                                                            \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 10^{-299}:\\ \;\;\;\;\left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
                                                                                            (FPCore (kx ky th)
                                                                                             :precision binary64
                                                                                             (if (<=
                                                                                                  (*
                                                                                                   (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))
                                                                                                   (sin th))
                                                                                                  1e-299)
                                                                                               (* (* (* th th) th) -0.16666666666666666)
                                                                                               th))
                                                                                            double code(double kx, double ky, double th) {
                                                                                            	double tmp;
                                                                                            	if (((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) * sin(th)) <= 1e-299) {
                                                                                            		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                            	} else {
                                                                                            		tmp = th;
                                                                                            	}
                                                                                            	return tmp;
                                                                                            }
                                                                                            
                                                                                            module fmin_fmax_functions
                                                                                                implicit none
                                                                                                private
                                                                                                public fmax
                                                                                                public fmin
                                                                                            
                                                                                                interface fmax
                                                                                                    module procedure fmax88
                                                                                                    module procedure fmax44
                                                                                                    module procedure fmax84
                                                                                                    module procedure fmax48
                                                                                                end interface
                                                                                                interface fmin
                                                                                                    module procedure fmin88
                                                                                                    module procedure fmin44
                                                                                                    module procedure fmin84
                                                                                                    module procedure fmin48
                                                                                                end interface
                                                                                            contains
                                                                                                real(8) function fmax88(x, y) result (res)
                                                                                                    real(8), intent (in) :: x
                                                                                                    real(8), intent (in) :: y
                                                                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                end function
                                                                                                real(4) function fmax44(x, y) result (res)
                                                                                                    real(4), intent (in) :: x
                                                                                                    real(4), intent (in) :: y
                                                                                                    res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                end function
                                                                                                real(8) function fmax84(x, y) result(res)
                                                                                                    real(8), intent (in) :: x
                                                                                                    real(4), intent (in) :: y
                                                                                                    res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                                end function
                                                                                                real(8) function fmax48(x, y) result(res)
                                                                                                    real(4), intent (in) :: x
                                                                                                    real(8), intent (in) :: y
                                                                                                    res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                                end function
                                                                                                real(8) function fmin88(x, y) result (res)
                                                                                                    real(8), intent (in) :: x
                                                                                                    real(8), intent (in) :: y
                                                                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                end function
                                                                                                real(4) function fmin44(x, y) result (res)
                                                                                                    real(4), intent (in) :: x
                                                                                                    real(4), intent (in) :: y
                                                                                                    res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                end function
                                                                                                real(8) function fmin84(x, y) result(res)
                                                                                                    real(8), intent (in) :: x
                                                                                                    real(4), intent (in) :: y
                                                                                                    res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                                end function
                                                                                                real(8) function fmin48(x, y) result(res)
                                                                                                    real(4), intent (in) :: x
                                                                                                    real(8), intent (in) :: y
                                                                                                    res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                                end function
                                                                                            end module
                                                                                            
                                                                                            real(8) function code(kx, ky, th)
                                                                                            use fmin_fmax_functions
                                                                                                real(8), intent (in) :: kx
                                                                                                real(8), intent (in) :: ky
                                                                                                real(8), intent (in) :: th
                                                                                                real(8) :: tmp
                                                                                                if (((sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))) * sin(th)) <= 1d-299) then
                                                                                                    tmp = ((th * th) * th) * (-0.16666666666666666d0)
                                                                                                else
                                                                                                    tmp = th
                                                                                                end if
                                                                                                code = tmp
                                                                                            end function
                                                                                            
                                                                                            public static double code(double kx, double ky, double th) {
                                                                                            	double tmp;
                                                                                            	if (((Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)))) * Math.sin(th)) <= 1e-299) {
                                                                                            		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                            	} else {
                                                                                            		tmp = th;
                                                                                            	}
                                                                                            	return tmp;
                                                                                            }
                                                                                            
                                                                                            def code(kx, ky, th):
                                                                                            	tmp = 0
                                                                                            	if ((math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))) * math.sin(th)) <= 1e-299:
                                                                                            		tmp = ((th * th) * th) * -0.16666666666666666
                                                                                            	else:
                                                                                            		tmp = th
                                                                                            	return tmp
                                                                                            
                                                                                            function code(kx, ky, th)
                                                                                            	tmp = 0.0
                                                                                            	if (Float64(Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 1e-299)
                                                                                            		tmp = Float64(Float64(Float64(th * th) * th) * -0.16666666666666666);
                                                                                            	else
                                                                                            		tmp = th;
                                                                                            	end
                                                                                            	return tmp
                                                                                            end
                                                                                            
                                                                                            function tmp_2 = code(kx, ky, th)
                                                                                            	tmp = 0.0;
                                                                                            	if (((sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) * sin(th)) <= 1e-299)
                                                                                            		tmp = ((th * th) * th) * -0.16666666666666666;
                                                                                            	else
                                                                                            		tmp = th;
                                                                                            	end
                                                                                            	tmp_2 = tmp;
                                                                                            end
                                                                                            
                                                                                            code[kx_, ky_, th_] := If[LessEqual[N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], 1e-299], N[(N[(N[(th * th), $MachinePrecision] * th), $MachinePrecision] * -0.16666666666666666), $MachinePrecision], th]
                                                                                            
                                                                                            \begin{array}{l}
                                                                                            
                                                                                            \\
                                                                                            \begin{array}{l}
                                                                                            \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \leq 10^{-299}:\\
                                                                                            \;\;\;\;\left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666\\
                                                                                            
                                                                                            \mathbf{else}:\\
                                                                                            \;\;\;\;th\\
                                                                                            
                                                                                            
                                                                                            \end{array}
                                                                                            \end{array}
                                                                                            
                                                                                            Derivation
                                                                                            1. Split input into 2 regimes
                                                                                            2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 9.99999999999999992e-300

                                                                                              1. Initial program 94.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.f6424.2

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

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

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

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

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

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

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

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

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

                                                                                                  \[\leadsto \mathsf{fma}\left(th \cdot th, -0.16666666666666666, 1\right) \cdot th \]
                                                                                              7. Applied rewrites13.5%

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

                                                                                                \[\leadsto \frac{-1}{6} \cdot {th}^{\color{blue}{3}} \]
                                                                                              9. Step-by-step derivation
                                                                                                1. *-commutativeN/A

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

                                                                                                  \[\leadsto {th}^{3} \cdot \frac{-1}{6} \]
                                                                                                3. unpow3N/A

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

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

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

                                                                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot th\right) \cdot \frac{-1}{6} \]
                                                                                                7. lift-*.f6410.9

                                                                                                  \[\leadsto \left(\left(th \cdot th\right) \cdot th\right) \cdot -0.16666666666666666 \]
                                                                                              10. Applied rewrites10.9%

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

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

                                                                                              1. Initial program 94.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.f6424.2

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

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

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

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

                                                                                              Alternative 22: 13.8% accurate, 170.4× speedup?

                                                                                              \[\begin{array}{l} \\ th \end{array} \]
                                                                                              (FPCore (kx ky th) :precision binary64 th)
                                                                                              double code(double kx, double ky, double th) {
                                                                                              	return th;
                                                                                              }
                                                                                              
                                                                                              module fmin_fmax_functions
                                                                                                  implicit none
                                                                                                  private
                                                                                                  public fmax
                                                                                                  public fmin
                                                                                              
                                                                                                  interface fmax
                                                                                                      module procedure fmax88
                                                                                                      module procedure fmax44
                                                                                                      module procedure fmax84
                                                                                                      module procedure fmax48
                                                                                                  end interface
                                                                                                  interface fmin
                                                                                                      module procedure fmin88
                                                                                                      module procedure fmin44
                                                                                                      module procedure fmin84
                                                                                                      module procedure fmin48
                                                                                                  end interface
                                                                                              contains
                                                                                                  real(8) function fmax88(x, y) result (res)
                                                                                                      real(8), intent (in) :: x
                                                                                                      real(8), intent (in) :: y
                                                                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(4) function fmax44(x, y) result (res)
                                                                                                      real(4), intent (in) :: x
                                                                                                      real(4), intent (in) :: y
                                                                                                      res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(8) function fmax84(x, y) result(res)
                                                                                                      real(8), intent (in) :: x
                                                                                                      real(4), intent (in) :: y
                                                                                                      res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(8) function fmax48(x, y) result(res)
                                                                                                      real(4), intent (in) :: x
                                                                                                      real(8), intent (in) :: y
                                                                                                      res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(8) function fmin88(x, y) result (res)
                                                                                                      real(8), intent (in) :: x
                                                                                                      real(8), intent (in) :: y
                                                                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(4) function fmin44(x, y) result (res)
                                                                                                      real(4), intent (in) :: x
                                                                                                      real(4), intent (in) :: y
                                                                                                      res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(8) function fmin84(x, y) result(res)
                                                                                                      real(8), intent (in) :: x
                                                                                                      real(4), intent (in) :: y
                                                                                                      res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                                  end function
                                                                                                  real(8) function fmin48(x, y) result(res)
                                                                                                      real(4), intent (in) :: x
                                                                                                      real(8), intent (in) :: y
                                                                                                      res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                                  end function
                                                                                              end module
                                                                                              
                                                                                              real(8) function code(kx, ky, th)
                                                                                              use fmin_fmax_functions
                                                                                                  real(8), intent (in) :: kx
                                                                                                  real(8), intent (in) :: ky
                                                                                                  real(8), intent (in) :: th
                                                                                                  code = th
                                                                                              end function
                                                                                              
                                                                                              public static double code(double kx, double ky, double th) {
                                                                                              	return th;
                                                                                              }
                                                                                              
                                                                                              def code(kx, ky, th):
                                                                                              	return th
                                                                                              
                                                                                              function code(kx, ky, th)
                                                                                              	return th
                                                                                              end
                                                                                              
                                                                                              function tmp = code(kx, ky, th)
                                                                                              	tmp = th;
                                                                                              end
                                                                                              
                                                                                              code[kx_, ky_, th_] := th
                                                                                              
                                                                                              \begin{array}{l}
                                                                                              
                                                                                              \\
                                                                                              th
                                                                                              \end{array}
                                                                                              
                                                                                              Derivation
                                                                                              1. Initial program 94.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.f6424.2

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

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

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

                                                                                                  \[\leadsto th \]
                                                                                                2. Add Preprocessing

                                                                                                Reproduce

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