Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 7.1s
Alternatives: 17
Speedup: 1.2×

Specification

?
\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
(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]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th

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 17 alternatives:

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

Initial Program: 93.7% accurate, 1.0× speedup?

\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
(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]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th

Alternative 1: 99.7% accurate, 1.2× speedup?

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

    \[\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. div-flipN/A

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

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
    4. lower-unsound-/.f6493.7

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

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

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

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

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
    11. lower-hypot.f6499.6

      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
    1. lift-*.f64N/A

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

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

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

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

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

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

      \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
    8. lower-hypot.f6499.7

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

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

Alternative 2: 99.7% accurate, 1.2× speedup?

\[\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
(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]
\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th
Derivation
  1. Initial program 93.7%

    \[\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. +-commutativeN/A

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
    8. lower-hypot.f6499.7

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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: 86.4% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_3 \leq -0.2:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 10^{-5}:\\
\;\;\;\;\frac{t\_1}{\sqrt{t\_2 + {\left(\left|ky\right|\right)}^{2}}} \cdot \sin th\\

\mathbf{elif}\;t\_3 \leq 0.998:\\
\;\;\;\;t\_4\\

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


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

    1. Initial program 93.7%

      \[\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. +-commutativeN/A

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
      8. lower-hypot.f6499.7

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

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

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

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

      if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001 or 1.00000000000000008e-5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

      1. Initial program 93.7%

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

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

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

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

        1. Initial program 93.7%

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

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

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

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

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

        1. Initial program 93.7%

          \[\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. div-flipN/A

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

            \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
          4. lower-unsound-/.f6493.7

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

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

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

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

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

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

            \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
          11. lower-hypot.f6499.6

            \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
          1. lift-*.f64N/A

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

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

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

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

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

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

            \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
          8. lower-hypot.f6499.7

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

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

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

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

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

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

          Alternative 4: 86.4% accurate, 0.2× speedup?

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

            1. Initial program 93.7%

              \[\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. +-commutativeN/A

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

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

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
              8. lower-hypot.f6499.7

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

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

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

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

              if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001 or 1.00000000000000008e-5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

              1. Initial program 93.7%

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

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

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

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

                1. Initial program 93.7%

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

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

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

                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                  3. lower-sin.f6441.9

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

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

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

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

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

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

                    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
                  6. lower-/.f6441.9

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

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

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

                    \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \]
                  10. rem-sqrt-square-revN/A

                    \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                  11. lower-fabs.f6445.0

                    \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                6. Applied rewrites45.0%

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

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

                1. Initial program 93.7%

                  \[\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. div-flipN/A

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

                    \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                  4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                    \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                  11. lower-hypot.f6499.6

                    \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                  1. lift-*.f64N/A

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

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

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

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

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

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

                    \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                  8. lower-hypot.f6499.7

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

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

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

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

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

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

                  Alternative 5: 86.4% accurate, 0.2× speedup?

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

                    1. Initial program 93.7%

                      \[\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. +-commutativeN/A

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

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

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

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

                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                      8. lower-hypot.f6499.7

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

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

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

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

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

                      1. Initial program 93.7%

                        \[\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. +-commutativeN/A

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

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

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

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

                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                        8. lower-hypot.f6499.7

                          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

                        1. Initial program 93.7%

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

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

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

                            \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                          3. lower-sin.f6441.9

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

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

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

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

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

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

                            \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
                          6. lower-/.f6441.9

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

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

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

                            \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \]
                          10. rem-sqrt-square-revN/A

                            \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                          11. lower-fabs.f6445.0

                            \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                        6. Applied rewrites45.0%

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

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

                        1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                              \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                            8. lower-*.f6447.1

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

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

                              \[\leadsto \frac{\sin ky \cdot th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \]
                            11. lower-hypot.f6447.1

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

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

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

                          1. Initial program 93.7%

                            \[\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. div-flipN/A

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

                              \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                            4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                              \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                            11. lower-hypot.f6499.6

                              \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                            1. lift-*.f64N/A

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

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

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

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

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

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

                              \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                            8. lower-hypot.f6499.7

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

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

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

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

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

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

                            Alternative 6: 86.0% accurate, 0.2× speedup?

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

                              1. Initial program 93.7%

                                \[\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. +-commutativeN/A

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

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

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

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

                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                8. lower-hypot.f6499.7

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

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

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

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

                                if -1 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001 or 1.00000000000000008e-5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.998

                                1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                                    8. lower-*.f6447.1

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

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

                                      \[\leadsto \frac{\sin ky \cdot th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \]
                                    11. lower-hypot.f6447.1

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

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

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

                                  1. Initial program 93.7%

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

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

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

                                      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                    3. lower-sin.f6441.9

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

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

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

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

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

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

                                      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
                                    6. lower-/.f6441.9

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

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

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

                                      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \]
                                    10. rem-sqrt-square-revN/A

                                      \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                                    11. lower-fabs.f6445.0

                                      \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                                  6. Applied rewrites45.0%

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

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

                                  1. Initial program 93.7%

                                    \[\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. div-flipN/A

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

                                      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                    4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                      \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                    11. lower-hypot.f6499.6

                                      \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                    1. lift-*.f64N/A

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

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

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

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

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

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

                                      \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                    8. lower-hypot.f6499.7

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

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

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

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

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

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

                                    Alternative 7: 81.8% accurate, 1.3× speedup?

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

                                      1. Initial program 93.7%

                                        \[\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. +-commutativeN/A

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

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

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

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

                                          \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                        8. lower-hypot.f6499.7

                                          \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        if 7.5000000000000004e-13 < th

                                        1. Initial program 93.7%

                                          \[\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. div-flipN/A

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

                                            \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                          4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                            \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                          11. lower-hypot.f6499.6

                                            \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                          1. lift-*.f64N/A

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

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

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

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

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

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

                                            \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                          8. lower-hypot.f6499.7

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

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

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

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

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

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

                                          Alternative 8: 80.6% accurate, 0.3× speedup?

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

                                            1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                  \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \]
                                                8. lower-*.f6447.1

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

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

                                                  \[\leadsto \frac{\sin ky \cdot th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}} \]
                                                11. lower-hypot.f6447.1

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

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

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

                                              1. Initial program 93.7%

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

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

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

                                                  \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                3. lower-sin.f6441.9

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

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

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

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

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

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

                                                  \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
                                                6. lower-/.f6441.9

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

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

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

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \]
                                                10. rem-sqrt-square-revN/A

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                                                11. lower-fabs.f6445.0

                                                  \[\leadsto \sin ky \cdot \frac{\sin th}{\left|\sin kx\right|} \]
                                              6. Applied rewrites45.0%

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

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

                                              1. Initial program 93.7%

                                                \[\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. div-flipN/A

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

                                                  \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                                4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                                  \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                                11. lower-hypot.f6499.6

                                                  \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                                1. lift-*.f64N/A

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

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

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

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

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

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

                                                  \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                8. lower-hypot.f6499.7

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

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

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

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

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

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

                                                Alternative 9: 72.5% accurate, 0.7× speedup?

                                                \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := {t\_1}^{2}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + t\_2}} \leq -0.2:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_2}} \cdot th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\ \end{array} \end{array} \]
                                                (FPCore (kx ky th)
                                                 :precision binary64
                                                 (let* ((t_1 (sin (fabs ky))) (t_2 (pow t_1 2.0)))
                                                   (*
                                                    (copysign 1.0 ky)
                                                    (if (<= (/ t_1 (sqrt (+ (pow (sin kx) 2.0) t_2))) -0.2)
                                                      (* (/ t_1 (sqrt t_2)) th)
                                                      (/ (sin th) (/ (hypot (fabs ky) (sin kx)) (fabs ky)))))))
                                                double code(double kx, double ky, double th) {
                                                	double t_1 = sin(fabs(ky));
                                                	double t_2 = pow(t_1, 2.0);
                                                	double tmp;
                                                	if ((t_1 / sqrt((pow(sin(kx), 2.0) + t_2))) <= -0.2) {
                                                		tmp = (t_1 / sqrt(t_2)) * th;
                                                	} else {
                                                		tmp = sin(th) / (hypot(fabs(ky), sin(kx)) / fabs(ky));
                                                	}
                                                	return copysign(1.0, ky) * tmp;
                                                }
                                                
                                                public static double code(double kx, double ky, double th) {
                                                	double t_1 = Math.sin(Math.abs(ky));
                                                	double t_2 = Math.pow(t_1, 2.0);
                                                	double tmp;
                                                	if ((t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + t_2))) <= -0.2) {
                                                		tmp = (t_1 / Math.sqrt(t_2)) * th;
                                                	} else {
                                                		tmp = Math.sin(th) / (Math.hypot(Math.abs(ky), Math.sin(kx)) / Math.abs(ky));
                                                	}
                                                	return Math.copySign(1.0, ky) * tmp;
                                                }
                                                
                                                def code(kx, ky, th):
                                                	t_1 = math.sin(math.fabs(ky))
                                                	t_2 = math.pow(t_1, 2.0)
                                                	tmp = 0
                                                	if (t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + t_2))) <= -0.2:
                                                		tmp = (t_1 / math.sqrt(t_2)) * th
                                                	else:
                                                		tmp = math.sin(th) / (math.hypot(math.fabs(ky), math.sin(kx)) / math.fabs(ky))
                                                	return math.copysign(1.0, ky) * tmp
                                                
                                                function code(kx, ky, th)
                                                	t_1 = sin(abs(ky))
                                                	t_2 = t_1 ^ 2.0
                                                	tmp = 0.0
                                                	if (Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + t_2))) <= -0.2)
                                                		tmp = Float64(Float64(t_1 / sqrt(t_2)) * th);
                                                	else
                                                		tmp = Float64(sin(th) / Float64(hypot(abs(ky), sin(kx)) / abs(ky)));
                                                	end
                                                	return Float64(copysign(1.0, ky) * tmp)
                                                end
                                                
                                                function tmp_2 = code(kx, ky, th)
                                                	t_1 = sin(abs(ky));
                                                	t_2 = t_1 ^ 2.0;
                                                	tmp = 0.0;
                                                	if ((t_1 / sqrt(((sin(kx) ^ 2.0) + t_2))) <= -0.2)
                                                		tmp = (t_1 / sqrt(t_2)) * th;
                                                	else
                                                		tmp = sin(th) / (hypot(abs(ky), sin(kx)) / abs(ky));
                                                	end
                                                	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
                                                end
                                                
                                                code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 2.0], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.2], N[(N[(t$95$1 / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * th), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Abs[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[Abs[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]]
                                                
                                                \begin{array}{l}
                                                t_1 := \sin \left(\left|ky\right|\right)\\
                                                t_2 := {t\_1}^{2}\\
                                                \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
                                                \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + t\_2}} \leq -0.2:\\
                                                \;\;\;\;\frac{t\_1}{\sqrt{t\_2}} \cdot th\\
                                                
                                                \mathbf{else}:\\
                                                \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\
                                                
                                                
                                                \end{array}
                                                \end{array}
                                                
                                                Derivation
                                                1. Split input into 2 regimes
                                                2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001

                                                  1. Initial program 93.7%

                                                    \[\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. +-commutativeN/A

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

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

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

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

                                                      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                    8. lower-hypot.f6499.7

                                                      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

                                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot th \]
                                                      2. lower-pow.f64N/A

                                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{2}}} \cdot th \]
                                                      3. lower-sin.f6421.0

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

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

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

                                                    1. Initial program 93.7%

                                                      \[\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. div-flipN/A

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

                                                        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                                      4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                                        \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                                      11. lower-hypot.f6499.6

                                                        \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                                      1. lift-*.f64N/A

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

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

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

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

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

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

                                                        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                      8. lower-hypot.f6499.7

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

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

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

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

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

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

                                                      Alternative 10: 71.8% accurate, 0.7× speedup?

                                                      \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \leq -0.2:\\ \;\;\;\;\frac{1}{\mathsf{hypot}\left(kx, t\_1\right)} \cdot \left(th \cdot t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\ \end{array} \end{array} \]
                                                      (FPCore (kx ky th)
                                                       :precision binary64
                                                       (let* ((t_1 (sin (fabs ky))))
                                                         (*
                                                          (copysign 1.0 ky)
                                                          (if (<= (/ t_1 (sqrt (+ (pow (sin kx) 2.0) (pow t_1 2.0)))) -0.2)
                                                            (* (/ 1.0 (hypot kx t_1)) (* th t_1))
                                                            (/ (sin th) (/ (hypot (fabs ky) (sin kx)) (fabs ky)))))))
                                                      double code(double kx, double ky, double th) {
                                                      	double t_1 = sin(fabs(ky));
                                                      	double tmp;
                                                      	if ((t_1 / sqrt((pow(sin(kx), 2.0) + pow(t_1, 2.0)))) <= -0.2) {
                                                      		tmp = (1.0 / hypot(kx, t_1)) * (th * t_1);
                                                      	} else {
                                                      		tmp = sin(th) / (hypot(fabs(ky), sin(kx)) / fabs(ky));
                                                      	}
                                                      	return copysign(1.0, ky) * tmp;
                                                      }
                                                      
                                                      public static double code(double kx, double ky, double th) {
                                                      	double t_1 = Math.sin(Math.abs(ky));
                                                      	double tmp;
                                                      	if ((t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(t_1, 2.0)))) <= -0.2) {
                                                      		tmp = (1.0 / Math.hypot(kx, t_1)) * (th * t_1);
                                                      	} else {
                                                      		tmp = Math.sin(th) / (Math.hypot(Math.abs(ky), Math.sin(kx)) / Math.abs(ky));
                                                      	}
                                                      	return Math.copySign(1.0, ky) * tmp;
                                                      }
                                                      
                                                      def code(kx, ky, th):
                                                      	t_1 = math.sin(math.fabs(ky))
                                                      	tmp = 0
                                                      	if (t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(t_1, 2.0)))) <= -0.2:
                                                      		tmp = (1.0 / math.hypot(kx, t_1)) * (th * t_1)
                                                      	else:
                                                      		tmp = math.sin(th) / (math.hypot(math.fabs(ky), math.sin(kx)) / math.fabs(ky))
                                                      	return math.copysign(1.0, ky) * tmp
                                                      
                                                      function code(kx, ky, th)
                                                      	t_1 = sin(abs(ky))
                                                      	tmp = 0.0
                                                      	if (Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) <= -0.2)
                                                      		tmp = Float64(Float64(1.0 / hypot(kx, t_1)) * Float64(th * t_1));
                                                      	else
                                                      		tmp = Float64(sin(th) / Float64(hypot(abs(ky), sin(kx)) / abs(ky)));
                                                      	end
                                                      	return Float64(copysign(1.0, ky) * tmp)
                                                      end
                                                      
                                                      function tmp_2 = code(kx, ky, th)
                                                      	t_1 = sin(abs(ky));
                                                      	tmp = 0.0;
                                                      	if ((t_1 / sqrt(((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) <= -0.2)
                                                      		tmp = (1.0 / hypot(kx, t_1)) * (th * t_1);
                                                      	else
                                                      		tmp = sin(th) / (hypot(abs(ky), sin(kx)) / abs(ky));
                                                      	end
                                                      	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
                                                      end
                                                      
                                                      code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.2], N[(N[(1.0 / N[Sqrt[kx ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision] * N[(th * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Abs[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[Abs[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
                                                      
                                                      \begin{array}{l}
                                                      t_1 := \sin \left(\left|ky\right|\right)\\
                                                      \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
                                                      \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \leq -0.2:\\
                                                      \;\;\;\;\frac{1}{\mathsf{hypot}\left(kx, t\_1\right)} \cdot \left(th \cdot t\_1\right)\\
                                                      
                                                      \mathbf{else}:\\
                                                      \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\
                                                      
                                                      
                                                      \end{array}
                                                      \end{array}
                                                      
                                                      Derivation
                                                      1. Split input into 2 regimes
                                                      2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001

                                                        1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                                            1. Initial program 93.7%

                                                              \[\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. div-flipN/A

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

                                                                \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                                              4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                                                \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                                              11. lower-hypot.f6499.6

                                                                \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                                              1. lift-*.f64N/A

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

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

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

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

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

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

                                                                \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                              8. lower-hypot.f6499.7

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

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

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

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

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

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

                                                              Alternative 11: 67.0% accurate, 1.3× speedup?

                                                              \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -0.05:\\ \;\;\;\;\left(th \cdot t\_1\right) \cdot \frac{1}{\left|\sin kx\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\ \end{array} \end{array} \]
                                                              (FPCore (kx ky th)
                                                               :precision binary64
                                                               (let* ((t_1 (sin (fabs ky))))
                                                                 (*
                                                                  (copysign 1.0 ky)
                                                                  (if (<= t_1 -0.05)
                                                                    (* (* th t_1) (/ 1.0 (fabs (sin kx))))
                                                                    (/ (sin th) (/ (hypot (fabs ky) (sin kx)) (fabs ky)))))))
                                                              double code(double kx, double ky, double th) {
                                                              	double t_1 = sin(fabs(ky));
                                                              	double tmp;
                                                              	if (t_1 <= -0.05) {
                                                              		tmp = (th * t_1) * (1.0 / fabs(sin(kx)));
                                                              	} else {
                                                              		tmp = sin(th) / (hypot(fabs(ky), sin(kx)) / fabs(ky));
                                                              	}
                                                              	return copysign(1.0, ky) * tmp;
                                                              }
                                                              
                                                              public static double code(double kx, double ky, double th) {
                                                              	double t_1 = Math.sin(Math.abs(ky));
                                                              	double tmp;
                                                              	if (t_1 <= -0.05) {
                                                              		tmp = (th * t_1) * (1.0 / Math.abs(Math.sin(kx)));
                                                              	} else {
                                                              		tmp = Math.sin(th) / (Math.hypot(Math.abs(ky), Math.sin(kx)) / Math.abs(ky));
                                                              	}
                                                              	return Math.copySign(1.0, ky) * tmp;
                                                              }
                                                              
                                                              def code(kx, ky, th):
                                                              	t_1 = math.sin(math.fabs(ky))
                                                              	tmp = 0
                                                              	if t_1 <= -0.05:
                                                              		tmp = (th * t_1) * (1.0 / math.fabs(math.sin(kx)))
                                                              	else:
                                                              		tmp = math.sin(th) / (math.hypot(math.fabs(ky), math.sin(kx)) / math.fabs(ky))
                                                              	return math.copysign(1.0, ky) * tmp
                                                              
                                                              function code(kx, ky, th)
                                                              	t_1 = sin(abs(ky))
                                                              	tmp = 0.0
                                                              	if (t_1 <= -0.05)
                                                              		tmp = Float64(Float64(th * t_1) * Float64(1.0 / abs(sin(kx))));
                                                              	else
                                                              		tmp = Float64(sin(th) / Float64(hypot(abs(ky), sin(kx)) / abs(ky)));
                                                              	end
                                                              	return Float64(copysign(1.0, ky) * tmp)
                                                              end
                                                              
                                                              function tmp_2 = code(kx, ky, th)
                                                              	t_1 = sin(abs(ky));
                                                              	tmp = 0.0;
                                                              	if (t_1 <= -0.05)
                                                              		tmp = (th * t_1) * (1.0 / abs(sin(kx)));
                                                              	else
                                                              		tmp = sin(th) / (hypot(abs(ky), sin(kx)) / abs(ky));
                                                              	end
                                                              	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
                                                              end
                                                              
                                                              code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, -0.05], N[(N[(th * t$95$1), $MachinePrecision] * N[(1.0 / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Abs[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[Abs[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
                                                              
                                                              \begin{array}{l}
                                                              t_1 := \sin \left(\left|ky\right|\right)\\
                                                              \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
                                                              \mathbf{if}\;t\_1 \leq -0.05:\\
                                                              \;\;\;\;\left(th \cdot t\_1\right) \cdot \frac{1}{\left|\sin kx\right|}\\
                                                              
                                                              \mathbf{else}:\\
                                                              \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)}{\left|ky\right|}}\\
                                                              
                                                              
                                                              \end{array}
                                                              \end{array}
                                                              
                                                              Derivation
                                                              1. Split input into 2 regimes
                                                              2. if (sin.f64 ky) < -0.050000000000000003

                                                                1. Initial program 93.7%

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

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

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

                                                                    \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                  3. lower-sin.f6441.9

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

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

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

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

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

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

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

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

                                                                    \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\sqrt{{\sin kx}^{2}}}} \]
                                                                  8. lower-/.f6440.9

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

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

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

                                                                    \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\sqrt{\sin kx \cdot \sin kx}} \]
                                                                  12. rem-sqrt-square-revN/A

                                                                    \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                6. Applied rewrites43.2%

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

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

                                                                    \[\leadsto \left(th \cdot \color{blue}{\sin ky}\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                  2. lower-sin.f6422.1

                                                                    \[\leadsto \left(th \cdot \sin ky\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                9. Applied rewrites22.1%

                                                                  \[\leadsto \color{blue}{\left(th \cdot \sin ky\right)} \cdot \frac{1}{\left|\sin kx\right|} \]

                                                                if -0.050000000000000003 < (sin.f64 ky)

                                                                1. Initial program 93.7%

                                                                  \[\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. div-flipN/A

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

                                                                    \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \cdot \sin th \]
                                                                  4. lower-unsound-/.f6493.7

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

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

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

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

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

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

                                                                    \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \cdot \sin th \]
                                                                  11. lower-hypot.f6499.6

                                                                    \[\leadsto \frac{1}{\frac{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{\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. Step-by-step derivation
                                                                  1. lift-*.f64N/A

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

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

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

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

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

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

                                                                    \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
                                                                  8. lower-hypot.f6499.7

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

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

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

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

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

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

                                                                  Alternative 12: 67.0% accurate, 1.3× speedup?

                                                                  \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_1 \leq -0.05:\\ \;\;\;\;\left(th \cdot t\_1\right) \cdot \frac{1}{\left|\sin kx\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left|ky\right|}{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)} \cdot \sin th\\ \end{array} \end{array} \]
                                                                  (FPCore (kx ky th)
                                                                   :precision binary64
                                                                   (let* ((t_1 (sin (fabs ky))))
                                                                     (*
                                                                      (copysign 1.0 ky)
                                                                      (if (<= t_1 -0.05)
                                                                        (* (* th t_1) (/ 1.0 (fabs (sin kx))))
                                                                        (* (/ (fabs ky) (hypot (fabs ky) (sin kx))) (sin th))))))
                                                                  double code(double kx, double ky, double th) {
                                                                  	double t_1 = sin(fabs(ky));
                                                                  	double tmp;
                                                                  	if (t_1 <= -0.05) {
                                                                  		tmp = (th * t_1) * (1.0 / fabs(sin(kx)));
                                                                  	} else {
                                                                  		tmp = (fabs(ky) / hypot(fabs(ky), sin(kx))) * sin(th);
                                                                  	}
                                                                  	return copysign(1.0, ky) * tmp;
                                                                  }
                                                                  
                                                                  public static double code(double kx, double ky, double th) {
                                                                  	double t_1 = Math.sin(Math.abs(ky));
                                                                  	double tmp;
                                                                  	if (t_1 <= -0.05) {
                                                                  		tmp = (th * t_1) * (1.0 / Math.abs(Math.sin(kx)));
                                                                  	} else {
                                                                  		tmp = (Math.abs(ky) / Math.hypot(Math.abs(ky), Math.sin(kx))) * Math.sin(th);
                                                                  	}
                                                                  	return Math.copySign(1.0, ky) * tmp;
                                                                  }
                                                                  
                                                                  def code(kx, ky, th):
                                                                  	t_1 = math.sin(math.fabs(ky))
                                                                  	tmp = 0
                                                                  	if t_1 <= -0.05:
                                                                  		tmp = (th * t_1) * (1.0 / math.fabs(math.sin(kx)))
                                                                  	else:
                                                                  		tmp = (math.fabs(ky) / math.hypot(math.fabs(ky), math.sin(kx))) * math.sin(th)
                                                                  	return math.copysign(1.0, ky) * tmp
                                                                  
                                                                  function code(kx, ky, th)
                                                                  	t_1 = sin(abs(ky))
                                                                  	tmp = 0.0
                                                                  	if (t_1 <= -0.05)
                                                                  		tmp = Float64(Float64(th * t_1) * Float64(1.0 / abs(sin(kx))));
                                                                  	else
                                                                  		tmp = Float64(Float64(abs(ky) / hypot(abs(ky), sin(kx))) * sin(th));
                                                                  	end
                                                                  	return Float64(copysign(1.0, ky) * tmp)
                                                                  end
                                                                  
                                                                  function tmp_2 = code(kx, ky, th)
                                                                  	t_1 = sin(abs(ky));
                                                                  	tmp = 0.0;
                                                                  	if (t_1 <= -0.05)
                                                                  		tmp = (th * t_1) * (1.0 / abs(sin(kx)));
                                                                  	else
                                                                  		tmp = (abs(ky) / hypot(abs(ky), sin(kx))) * sin(th);
                                                                  	end
                                                                  	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
                                                                  end
                                                                  
                                                                  code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$1, -0.05], N[(N[(th * t$95$1), $MachinePrecision] * N[(1.0 / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Abs[ky], $MachinePrecision] / N[Sqrt[N[Abs[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]
                                                                  
                                                                  \begin{array}{l}
                                                                  t_1 := \sin \left(\left|ky\right|\right)\\
                                                                  \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
                                                                  \mathbf{if}\;t\_1 \leq -0.05:\\
                                                                  \;\;\;\;\left(th \cdot t\_1\right) \cdot \frac{1}{\left|\sin kx\right|}\\
                                                                  
                                                                  \mathbf{else}:\\
                                                                  \;\;\;\;\frac{\left|ky\right|}{\mathsf{hypot}\left(\left|ky\right|, \sin kx\right)} \cdot \sin th\\
                                                                  
                                                                  
                                                                  \end{array}
                                                                  \end{array}
                                                                  
                                                                  Derivation
                                                                  1. Split input into 2 regimes
                                                                  2. if (sin.f64 ky) < -0.050000000000000003

                                                                    1. Initial program 93.7%

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

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

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

                                                                        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                      3. lower-sin.f6441.9

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

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

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

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

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

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

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

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

                                                                        \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\sqrt{{\sin kx}^{2}}}} \]
                                                                      8. lower-/.f6440.9

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

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

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

                                                                        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\sqrt{\sin kx \cdot \sin kx}} \]
                                                                      12. rem-sqrt-square-revN/A

                                                                        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                    6. Applied rewrites43.2%

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

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

                                                                        \[\leadsto \left(th \cdot \color{blue}{\sin ky}\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                      2. lower-sin.f6422.1

                                                                        \[\leadsto \left(th \cdot \sin ky\right) \cdot \frac{1}{\left|\sin kx\right|} \]
                                                                    9. Applied rewrites22.1%

                                                                      \[\leadsto \color{blue}{\left(th \cdot \sin ky\right)} \cdot \frac{1}{\left|\sin kx\right|} \]

                                                                    if -0.050000000000000003 < (sin.f64 ky)

                                                                    1. Initial program 93.7%

                                                                      \[\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. +-commutativeN/A

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

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

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

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

                                                                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                                      8. lower-hypot.f6499.7

                                                                        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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 rewrites51.9%

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

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

                                                                      Alternative 13: 52.5% accurate, 2.0× speedup?

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

                                                                        1. Initial program 93.7%

                                                                          \[\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. +-commutativeN/A

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

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

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

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

                                                                            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                                          8. lower-hypot.f6499.7

                                                                            \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

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

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

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

                                                                              if 5.99999999999999996e-9 < th

                                                                              1. Initial program 93.7%

                                                                                \[\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}{\sqrt{{\sin kx}^{2}}}} \cdot \sin th \]
                                                                              3. Step-by-step derivation
                                                                                1. lower-/.f64N/A

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

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

                                                                                  \[\leadsto \frac{ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                                4. lower-sin.f6436.9

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

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

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

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

                                                                                  \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{{\sin kx}^{2}}}{ky}}} \cdot \sin th \]
                                                                                4. lower-unsound-/.f6436.9

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

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

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

                                                                                  \[\leadsto \frac{1}{\frac{\sqrt{\sin kx \cdot \sin kx}}{ky}} \cdot \sin th \]
                                                                                8. rem-sqrt-square-revN/A

                                                                                  \[\leadsto \frac{1}{\frac{\left|\sin kx\right|}{ky}} \cdot \sin th \]
                                                                                9. lower-fabs.f6439.9

                                                                                  \[\leadsto \frac{1}{\frac{\left|\sin kx\right|}{ky}} \cdot \sin th \]
                                                                              6. Applied rewrites39.9%

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

                                                                            Alternative 14: 52.5% accurate, 2.0× speedup?

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

                                                                              1. Initial program 93.7%

                                                                                \[\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. +-commutativeN/A

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

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

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

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

                                                                                  \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                                                8. lower-hypot.f6499.7

                                                                                  \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

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

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

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

                                                                                    if 5.99999999999999996e-9 < th

                                                                                    1. Initial program 93.7%

                                                                                      \[\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}{\sqrt{{\sin kx}^{2}}}} \cdot \sin th \]
                                                                                    3. Step-by-step derivation
                                                                                      1. lower-/.f64N/A

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

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

                                                                                        \[\leadsto \frac{ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                                      4. lower-sin.f6436.9

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

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

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

                                                                                        \[\leadsto \color{blue}{\sin th \cdot \frac{ky}{\sqrt{{\sin kx}^{2}}}} \]
                                                                                      3. lower-*.f6436.9

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

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

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

                                                                                        \[\leadsto \sin th \cdot \frac{ky}{\sqrt{\sin kx \cdot \sin kx}} \]
                                                                                      7. rem-sqrt-square-revN/A

                                                                                        \[\leadsto \sin th \cdot \frac{ky}{\left|\sin kx\right|} \]
                                                                                      8. lower-fabs.f6439.9

                                                                                        \[\leadsto \sin th \cdot \frac{ky}{\left|\sin kx\right|} \]
                                                                                    6. Applied rewrites39.9%

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

                                                                                  Alternative 15: 40.7% accurate, 2.6× speedup?

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

                                                                                    1. Initial program 93.7%

                                                                                      \[\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. +-commutativeN/A

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

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

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

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

                                                                                        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + \sin kx \cdot \sin kx}} \cdot \sin th \]
                                                                                      8. lower-hypot.f6499.7

                                                                                        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \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.7%

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

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

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

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

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

                                                                                          if 620 < th

                                                                                          1. Initial program 93.7%

                                                                                            \[\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}{\sqrt{{\sin kx}^{2}}}} \cdot \sin th \]
                                                                                          3. Step-by-step derivation
                                                                                            1. lower-/.f64N/A

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

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

                                                                                              \[\leadsto \frac{ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                                            4. lower-sin.f6436.9

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

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

                                                                                            \[\leadsto \frac{ky}{\color{blue}{kx}} \cdot \sin th \]
                                                                                          6. Step-by-step derivation
                                                                                            1. lower-/.f6417.0

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

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

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

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

                                                                                              \[\leadsto \frac{1}{\frac{kx}{\color{blue}{ky}}} \cdot \sin th \]
                                                                                            4. lower-unsound-/.f6417.0

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

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

                                                                                        Alternative 16: 22.5% accurate, 4.2× speedup?

                                                                                        \[\frac{ky}{\left|kx\right|} \cdot \sin th \]
                                                                                        (FPCore (kx ky th) :precision binary64 (* (/ ky (fabs kx)) (sin th)))
                                                                                        double code(double kx, double ky, double th) {
                                                                                        	return (ky / fabs(kx)) * 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 = (ky / abs(kx)) * sin(th)
                                                                                        end function
                                                                                        
                                                                                        public static double code(double kx, double ky, double th) {
                                                                                        	return (ky / Math.abs(kx)) * Math.sin(th);
                                                                                        }
                                                                                        
                                                                                        def code(kx, ky, th):
                                                                                        	return (ky / math.fabs(kx)) * math.sin(th)
                                                                                        
                                                                                        function code(kx, ky, th)
                                                                                        	return Float64(Float64(ky / abs(kx)) * sin(th))
                                                                                        end
                                                                                        
                                                                                        function tmp = code(kx, ky, th)
                                                                                        	tmp = (ky / abs(kx)) * sin(th);
                                                                                        end
                                                                                        
                                                                                        code[kx_, ky_, th_] := N[(N[(ky / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
                                                                                        
                                                                                        \frac{ky}{\left|kx\right|} \cdot \sin th
                                                                                        
                                                                                        Derivation
                                                                                        1. Initial program 93.7%

                                                                                          \[\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}{\sqrt{{\sin kx}^{2}}}} \cdot \sin th \]
                                                                                        3. Step-by-step derivation
                                                                                          1. lower-/.f64N/A

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

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

                                                                                            \[\leadsto \frac{ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                                          4. lower-sin.f6436.9

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

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

                                                                                          \[\leadsto \frac{ky}{\color{blue}{kx}} \cdot \sin th \]
                                                                                        6. Step-by-step derivation
                                                                                          1. lower-/.f6417.0

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

                                                                                          \[\leadsto \frac{ky}{\color{blue}{kx}} \cdot \sin th \]
                                                                                        8. Add Preprocessing

                                                                                        Alternative 17: 16.0% accurate, 14.9× speedup?

                                                                                        \[\frac{ky}{\left|kx\right|} \cdot \left(th \cdot 1\right) \]
                                                                                        (FPCore (kx ky th) :precision binary64 (* (/ ky (fabs kx)) (* th 1.0)))
                                                                                        double code(double kx, double ky, double th) {
                                                                                        	return (ky / fabs(kx)) * (th * 1.0);
                                                                                        }
                                                                                        
                                                                                        module fmin_fmax_functions
                                                                                            implicit none
                                                                                            private
                                                                                            public fmax
                                                                                            public fmin
                                                                                        
                                                                                            interface fmax
                                                                                                module procedure fmax88
                                                                                                module procedure fmax44
                                                                                                module procedure fmax84
                                                                                                module procedure fmax48
                                                                                            end interface
                                                                                            interface fmin
                                                                                                module procedure fmin88
                                                                                                module procedure fmin44
                                                                                                module procedure fmin84
                                                                                                module procedure fmin48
                                                                                            end interface
                                                                                        contains
                                                                                            real(8) function fmax88(x, y) result (res)
                                                                                                real(8), intent (in) :: x
                                                                                                real(8), intent (in) :: y
                                                                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                            end function
                                                                                            real(4) function fmax44(x, y) result (res)
                                                                                                real(4), intent (in) :: x
                                                                                                real(4), intent (in) :: y
                                                                                                res = merge(y, merge(x, max(x, y), y /= y), x /= x)
                                                                                            end function
                                                                                            real(8) function fmax84(x, y) result(res)
                                                                                                real(8), intent (in) :: x
                                                                                                real(4), intent (in) :: y
                                                                                                res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
                                                                                            end function
                                                                                            real(8) function fmax48(x, y) result(res)
                                                                                                real(4), intent (in) :: x
                                                                                                real(8), intent (in) :: y
                                                                                                res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
                                                                                            end function
                                                                                            real(8) function fmin88(x, y) result (res)
                                                                                                real(8), intent (in) :: x
                                                                                                real(8), intent (in) :: y
                                                                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                            end function
                                                                                            real(4) function fmin44(x, y) result (res)
                                                                                                real(4), intent (in) :: x
                                                                                                real(4), intent (in) :: y
                                                                                                res = merge(y, merge(x, min(x, y), y /= y), x /= x)
                                                                                            end function
                                                                                            real(8) function fmin84(x, y) result(res)
                                                                                                real(8), intent (in) :: x
                                                                                                real(4), intent (in) :: y
                                                                                                res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
                                                                                            end function
                                                                                            real(8) function fmin48(x, y) result(res)
                                                                                                real(4), intent (in) :: x
                                                                                                real(8), intent (in) :: y
                                                                                                res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
                                                                                            end function
                                                                                        end module
                                                                                        
                                                                                        real(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 = (ky / abs(kx)) * (th * 1.0d0)
                                                                                        end function
                                                                                        
                                                                                        public static double code(double kx, double ky, double th) {
                                                                                        	return (ky / Math.abs(kx)) * (th * 1.0);
                                                                                        }
                                                                                        
                                                                                        def code(kx, ky, th):
                                                                                        	return (ky / math.fabs(kx)) * (th * 1.0)
                                                                                        
                                                                                        function code(kx, ky, th)
                                                                                        	return Float64(Float64(ky / abs(kx)) * Float64(th * 1.0))
                                                                                        end
                                                                                        
                                                                                        function tmp = code(kx, ky, th)
                                                                                        	tmp = (ky / abs(kx)) * (th * 1.0);
                                                                                        end
                                                                                        
                                                                                        code[kx_, ky_, th_] := N[(N[(ky / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * N[(th * 1.0), $MachinePrecision]), $MachinePrecision]
                                                                                        
                                                                                        \frac{ky}{\left|kx\right|} \cdot \left(th \cdot 1\right)
                                                                                        
                                                                                        Derivation
                                                                                        1. Initial program 93.7%

                                                                                          \[\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}{\sqrt{{\sin kx}^{2}}}} \cdot \sin th \]
                                                                                        3. Step-by-step derivation
                                                                                          1. lower-/.f64N/A

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

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

                                                                                            \[\leadsto \frac{ky}{\sqrt{{\sin kx}^{2}}} \cdot \sin th \]
                                                                                          4. lower-sin.f6436.9

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

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

                                                                                          \[\leadsto \frac{ky}{\color{blue}{kx}} \cdot \sin th \]
                                                                                        6. Step-by-step derivation
                                                                                          1. lower-/.f6417.0

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

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

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

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

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

                                                                                            \[\leadsto \frac{ky}{kx} \cdot \left(th \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{th}^{2}}\right)\right) \]
                                                                                          4. lower-pow.f6413.2

                                                                                            \[\leadsto \frac{ky}{kx} \cdot \left(th \cdot \left(1 + -0.16666666666666666 \cdot {th}^{\color{blue}{2}}\right)\right) \]
                                                                                        10. Applied rewrites13.2%

                                                                                          \[\leadsto \frac{ky}{kx} \cdot \color{blue}{\left(th \cdot \left(1 + -0.16666666666666666 \cdot {th}^{2}\right)\right)} \]
                                                                                        11. Taylor expanded in th around 0

                                                                                          \[\leadsto \frac{ky}{kx} \cdot \left(th \cdot 1\right) \]
                                                                                        12. Step-by-step derivation
                                                                                          1. Applied rewrites13.8%

                                                                                            \[\leadsto \frac{ky}{kx} \cdot \left(th \cdot 1\right) \]
                                                                                          2. Add Preprocessing

                                                                                          Reproduce

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