Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 97.2%
Time: 4.8s
Alternatives: 21
Speedup: 1.0×

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) (pow (sin ky) 2)))) (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], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2], $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 21 alternatives:

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

Initial Program: 94.3% accurate, 1.0× speedup?

\[\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) (pow (sin ky) 2)))) (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], $MachinePrecision] + N[Power[N[Sin[ky], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]
\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th

Alternative 1: 97.2% accurate, 0.4× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := {t\_1}^{2}\\ t_3 := {\sin kx}^{2}\\ t_4 := \sin \left(\left(-\left|ky\right|\right) + \pi\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{t\_3 + t\_2}} \leq 2:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{{\sin kx}^{1}}{{\sin kx}^{-1}} + t\_2}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_4}{\sqrt{t\_3 + {t\_4}^{2}}} \cdot \sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (pow t_1 2))
       (t_3 (pow (sin kx) 2))
       (t_4 (sin (+ (- (fabs ky)) PI))))
  (*
   (copysign 1 ky)
   (if (<= (/ t_1 (sqrt (+ t_3 t_2))) 2)
     (*
      (/ t_1 (sqrt (+ (/ (pow (sin kx) 1) (pow (sin kx) -1)) t_2)))
      (sin th))
     (* (/ t_4 (sqrt (+ t_3 (pow t_4 2)))) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = pow(t_1, 2.0);
	double t_3 = pow(sin(kx), 2.0);
	double t_4 = sin((-fabs(ky) + ((double) M_PI)));
	double tmp;
	if ((t_1 / sqrt((t_3 + t_2))) <= 2.0) {
		tmp = (t_1 / sqrt(((pow(sin(kx), 1.0) / pow(sin(kx), -1.0)) + t_2))) * sin(th);
	} else {
		tmp = (t_4 / sqrt((t_3 + pow(t_4, 2.0)))) * 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 t_2 = Math.pow(t_1, 2.0);
	double t_3 = Math.pow(Math.sin(kx), 2.0);
	double t_4 = Math.sin((-Math.abs(ky) + Math.PI));
	double tmp;
	if ((t_1 / Math.sqrt((t_3 + t_2))) <= 2.0) {
		tmp = (t_1 / Math.sqrt(((Math.pow(Math.sin(kx), 1.0) / Math.pow(Math.sin(kx), -1.0)) + t_2))) * Math.sin(th);
	} else {
		tmp = (t_4 / Math.sqrt((t_3 + Math.pow(t_4, 2.0)))) * Math.sin(th);
	}
	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)
	t_3 = math.pow(math.sin(kx), 2.0)
	t_4 = math.sin((-math.fabs(ky) + math.pi))
	tmp = 0
	if (t_1 / math.sqrt((t_3 + t_2))) <= 2.0:
		tmp = (t_1 / math.sqrt(((math.pow(math.sin(kx), 1.0) / math.pow(math.sin(kx), -1.0)) + t_2))) * math.sin(th)
	else:
		tmp = (t_4 / math.sqrt((t_3 + math.pow(t_4, 2.0)))) * math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = t_1 ^ 2.0
	t_3 = sin(kx) ^ 2.0
	t_4 = sin(Float64(Float64(-abs(ky)) + pi))
	tmp = 0.0
	if (Float64(t_1 / sqrt(Float64(t_3 + t_2))) <= 2.0)
		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64((sin(kx) ^ 1.0) / (sin(kx) ^ -1.0)) + t_2))) * sin(th));
	else
		tmp = Float64(Float64(t_4 / sqrt(Float64(t_3 + (t_4 ^ 2.0)))) * sin(th));
	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;
	t_3 = sin(kx) ^ 2.0;
	t_4 = sin((-abs(ky) + pi));
	tmp = 0.0;
	if ((t_1 / sqrt((t_3 + t_2))) <= 2.0)
		tmp = (t_1 / sqrt((((sin(kx) ^ 1.0) / (sin(kx) ^ -1.0)) + t_2))) * sin(th);
	else
		tmp = (t_4 / sqrt((t_3 + (t_4 ^ 2.0)))) * 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]}, Block[{t$95$2 = N[Power[t$95$1, 2], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[kx], $MachinePrecision], 2], $MachinePrecision]}, Block[{t$95$4 = N[Sin[N[((-N[Abs[ky], $MachinePrecision]) + Pi), $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(t$95$3 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Power[N[Sin[kx], $MachinePrecision], 1], $MachinePrecision] / N[Power[N[Sin[kx], $MachinePrecision], -1], $MachinePrecision]), $MachinePrecision] + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$4 / N[Sqrt[N[(t$95$3 + N[Power[t$95$4, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]]]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := {t\_1}^{2}\\
t_3 := {\sin kx}^{2}\\
t_4 := \sin \left(\left(-\left|ky\right|\right) + \pi\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_1}{\sqrt{t\_3 + t\_2}} \leq 2:\\
\;\;\;\;\frac{t\_1}{\sqrt{\frac{{\sin kx}^{1}}{{\sin kx}^{-1}} + t\_2}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_4}{\sqrt{t\_3 + {t\_4}^{2}}} \cdot \sin th\\


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

    1. Initial program 94.3%

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\frac{\color{blue}{{\sin kx}^{1}}}{{\sin kx}^{-1}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. lower-unsound-pow.f6494.3%

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

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

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

    1. Initial program 94.3%

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\sin \left(\mathsf{neg}\left(ky\right)\right)}\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-+PI-revN/A

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

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

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

        \[\leadsto \frac{\sin \left(\color{blue}{\left(-ky\right)} + \mathsf{PI}\left(\right)\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      8. lower-PI.f646.8%

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \color{blue}{\pi}\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Applied rewrites6.8%

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

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

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

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\left(\mathsf{neg}\left(\color{blue}{\sin \left(\mathsf{neg}\left(ky\right)\right)}\right)\right)}^{2}}} \cdot \sin th \]
      4. sin-+PI-revN/A

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

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

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

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\sin \left(\color{blue}{\left(-ky\right)} + \mathsf{PI}\left(\right)\right)}^{2}}} \cdot \sin th \]
      8. lower-PI.f6412.8%

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\sin \left(\left(-ky\right) + \color{blue}{\pi}\right)}^{2}}} \cdot \sin th \]
    5. Applied rewrites12.8%

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

Alternative 2: 97.2% accurate, 0.5× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\sqrt{t\_3 + {t\_1}^{2}}} \cdot \sin th\\


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

    1. Initial program 94.3%

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

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

    1. Initial program 94.3%

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

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

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

        \[\leadsto \frac{\mathsf{neg}\left(\color{blue}{\sin \left(\mathsf{neg}\left(ky\right)\right)}\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-+PI-revN/A

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

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

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

        \[\leadsto \frac{\sin \left(\color{blue}{\left(-ky\right)} + \mathsf{PI}\left(\right)\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
      8. lower-PI.f646.8%

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \color{blue}{\pi}\right)}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Applied rewrites6.8%

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

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

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

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\left(\mathsf{neg}\left(\color{blue}{\sin \left(\mathsf{neg}\left(ky\right)\right)}\right)\right)}^{2}}} \cdot \sin th \]
      4. sin-+PI-revN/A

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

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

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

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\sin \left(\color{blue}{\left(-ky\right)} + \mathsf{PI}\left(\right)\right)}^{2}}} \cdot \sin th \]
      8. lower-PI.f6412.8%

        \[\leadsto \frac{\sin \left(\left(-ky\right) + \pi\right)}{\sqrt{{\sin kx}^{2} + {\sin \left(\left(-ky\right) + \color{blue}{\pi}\right)}^{2}}} \cdot \sin th \]
    5. Applied rewrites12.8%

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

Alternative 3: 96.7% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \cdot \sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (* (/ t_1 (sqrt (+ (pow (sin kx) 2) (pow t_1 2)))) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if (fabs(ky) <= 5.8e-170) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else {
		tmp = (t_1 / sqrt((pow(sin(kx), 2.0) + pow(t_1, 2.0)))) * 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 (Math.abs(ky) <= 5.8e-170) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else {
		tmp = (t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(t_1, 2.0)))) * 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 math.fabs(ky) <= 5.8e-170:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	else:
		tmp = (t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(t_1, 2.0)))) * math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (abs(ky) <= 5.8e-170)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	else
		tmp = Float64(Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) * 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 (abs(ky) <= 5.8e-170)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	else
		tmp = (t_1 / sqrt(((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) * 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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2], $MachinePrecision] + N[Power[t$95$1, 2], $MachinePrecision]), $MachinePrecision]], $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}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \cdot \sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 5.8000000000000001e-170

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.8000000000000001e-170 < ky

    1. Initial program 94.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 4: 96.7% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := {\sin kx}^{2}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{7136238463529799}{1427247692705959881058285969449495136382746624}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_2 + {\left(\left|ky\right|\right)}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1 \cdot \sin th}{\sqrt{t\_2 + {t\_1}^{2}}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))) (t_2 (pow (sin kx) 2)))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (if (<=
          (fabs ky)
          7136238463529799/1427247692705959881058285969449495136382746624)
       (* (/ t_1 (sqrt (+ t_2 (pow (fabs ky) 2)))) (sin th))
       (/ (* t_1 (sin th)) (sqrt (+ t_2 (pow t_1 2)))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = pow(sin(kx), 2.0);
	double tmp;
	if (fabs(ky) <= 5.8e-170) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else if (fabs(ky) <= 5e-30) {
		tmp = (t_1 / sqrt((t_2 + pow(fabs(ky), 2.0)))) * sin(th);
	} else {
		tmp = (t_1 * sin(th)) / sqrt((t_2 + pow(t_1, 2.0)));
	}
	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 tmp;
	if (Math.abs(ky) <= 5.8e-170) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else if (Math.abs(ky) <= 5e-30) {
		tmp = (t_1 / Math.sqrt((t_2 + Math.pow(Math.abs(ky), 2.0)))) * Math.sin(th);
	} else {
		tmp = (t_1 * Math.sin(th)) / Math.sqrt((t_2 + Math.pow(t_1, 2.0)));
	}
	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)
	tmp = 0
	if math.fabs(ky) <= 5.8e-170:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	elif math.fabs(ky) <= 5e-30:
		tmp = (t_1 / math.sqrt((t_2 + math.pow(math.fabs(ky), 2.0)))) * math.sin(th)
	else:
		tmp = (t_1 * math.sin(th)) / math.sqrt((t_2 + math.pow(t_1, 2.0)))
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = sin(kx) ^ 2.0
	tmp = 0.0
	if (abs(ky) <= 5.8e-170)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	elseif (abs(ky) <= 5e-30)
		tmp = Float64(Float64(t_1 / sqrt(Float64(t_2 + (abs(ky) ^ 2.0)))) * sin(th));
	else
		tmp = Float64(Float64(t_1 * sin(th)) / sqrt(Float64(t_2 + (t_1 ^ 2.0))));
	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;
	tmp = 0.0;
	if (abs(ky) <= 5.8e-170)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	elseif (abs(ky) <= 5e-30)
		tmp = (t_1 / sqrt((t_2 + (abs(ky) ^ 2.0)))) * sin(th);
	else
		tmp = (t_1 * sin(th)) / sqrt((t_2 + (t_1 ^ 2.0)));
	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], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 7136238463529799/1427247692705959881058285969449495136382746624], N[(N[(t$95$1 / N[Sqrt[N[(t$95$2 + N[Power[N[Abs[ky], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[Power[t$95$1, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := {\sin kx}^{2}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

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

\mathbf{else}:\\
\;\;\;\;\frac{t\_1 \cdot \sin th}{\sqrt{t\_2 + {t\_1}^{2}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.8000000000000001e-170

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.8000000000000001e-170 < ky < 4.9999999999999997e-30

    1. Initial program 94.3%

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

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

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

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

    if 4.9999999999999997e-30 < ky

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      10. lower-sin.f6492.5%

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

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

Alternative 5: 96.7% accurate, 1.0× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\ \;\;\;\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {\left(\left|ky\right|\right)}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(\cos \left(kx + kx\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (if (<= (fabs ky) 6800207735332289/151115727451828646838272)
       (*
        (/ t_1 (sqrt (+ (pow (sin kx) 2) (pow (fabs ky) 2))))
        (sin th))
       (*
        (/
         (sin th)
         (sqrt
          (-
           1/2
           (*
            (- (cos (+ kx kx)) (- 1 (cos (+ (fabs ky) (fabs ky)))))
            1/2))))
        t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if (fabs(ky) <= 5.8e-170) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else if (fabs(ky) <= 4.5e-8) {
		tmp = (t_1 / sqrt((pow(sin(kx), 2.0) + pow(fabs(ky), 2.0)))) * sin(th);
	} else {
		tmp = (sin(th) / sqrt((0.5 - ((cos((kx + kx)) - (1.0 - cos((fabs(ky) + fabs(ky))))) * 0.5)))) * t_1;
	}
	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 (Math.abs(ky) <= 5.8e-170) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else if (Math.abs(ky) <= 4.5e-8) {
		tmp = (t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.abs(ky), 2.0)))) * Math.sin(th);
	} else {
		tmp = (Math.sin(th) / Math.sqrt((0.5 - ((Math.cos((kx + kx)) - (1.0 - Math.cos((Math.abs(ky) + Math.abs(ky))))) * 0.5)))) * t_1;
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if math.fabs(ky) <= 5.8e-170:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	elif math.fabs(ky) <= 4.5e-8:
		tmp = (t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.fabs(ky), 2.0)))) * math.sin(th)
	else:
		tmp = (math.sin(th) / math.sqrt((0.5 - ((math.cos((kx + kx)) - (1.0 - math.cos((math.fabs(ky) + math.fabs(ky))))) * 0.5)))) * t_1
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (abs(ky) <= 5.8e-170)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	elseif (abs(ky) <= 4.5e-8)
		tmp = Float64(Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (abs(ky) ^ 2.0)))) * sin(th));
	else
		tmp = Float64(Float64(sin(th) / sqrt(Float64(0.5 - Float64(Float64(cos(Float64(kx + kx)) - Float64(1.0 - cos(Float64(abs(ky) + abs(ky))))) * 0.5)))) * t_1);
	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 (abs(ky) <= 5.8e-170)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	elseif (abs(ky) <= 4.5e-8)
		tmp = (t_1 / sqrt(((sin(kx) ^ 2.0) + (abs(ky) ^ 2.0)))) * sin(th);
	else
		tmp = (sin(th) / sqrt((0.5 - ((cos((kx + kx)) - (1.0 - cos((abs(ky) + abs(ky))))) * 0.5)))) * t_1;
	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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 3943168458671679/67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 6800207735332289/151115727451828646838272], N[(N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2], $MachinePrecision] + N[Power[N[Abs[ky], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(1/2 - N[(N[(N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision] - N[(1 - N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$1), $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}\;\left|ky\right| \leq \frac{3943168458671679}{67985663080546188632267290438715984298187919069060086169528849689651655662189087070612800289949348565617834174239552129964362155219546526644418557282123181048810402666930332036061200384}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\
\;\;\;\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {\left(\left|ky\right|\right)}^{2}}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(\cos \left(kx + kx\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.8000000000000001e-170

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.8000000000000001e-170 < ky < 4.4999999999999999e-8

    1. Initial program 94.3%

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

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

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

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

    if 4.4999999999999999e-8 < ky

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      10. lower-sin.f6492.5%

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

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

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

Alternative 6: 95.5% accurate, 1.0× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\ \;\;\;\;\frac{t\_1 \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\left(\left|ky\right|\right)}^{2}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(\cos \left(kx + kx\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (if (<= (fabs ky) 6800207735332289/151115727451828646838272)
       (/
        (* t_1 (sin th))
        (sqrt (+ (pow (sin kx) 2) (pow (fabs ky) 2))))
       (*
        (/
         (sin th)
         (sqrt
          (-
           1/2
           (*
            (- (cos (+ kx kx)) (- 1 (cos (+ (fabs ky) (fabs ky)))))
            1/2))))
        t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if (fabs(ky) <= 5.7e-157) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else if (fabs(ky) <= 4.5e-8) {
		tmp = (t_1 * sin(th)) / sqrt((pow(sin(kx), 2.0) + pow(fabs(ky), 2.0)));
	} else {
		tmp = (sin(th) / sqrt((0.5 - ((cos((kx + kx)) - (1.0 - cos((fabs(ky) + fabs(ky))))) * 0.5)))) * t_1;
	}
	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 (Math.abs(ky) <= 5.7e-157) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else if (Math.abs(ky) <= 4.5e-8) {
		tmp = (t_1 * Math.sin(th)) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.abs(ky), 2.0)));
	} else {
		tmp = (Math.sin(th) / Math.sqrt((0.5 - ((Math.cos((kx + kx)) - (1.0 - Math.cos((Math.abs(ky) + Math.abs(ky))))) * 0.5)))) * t_1;
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if math.fabs(ky) <= 5.7e-157:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	elif math.fabs(ky) <= 4.5e-8:
		tmp = (t_1 * math.sin(th)) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.fabs(ky), 2.0)))
	else:
		tmp = (math.sin(th) / math.sqrt((0.5 - ((math.cos((kx + kx)) - (1.0 - math.cos((math.fabs(ky) + math.fabs(ky))))) * 0.5)))) * t_1
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (abs(ky) <= 5.7e-157)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	elseif (abs(ky) <= 4.5e-8)
		tmp = Float64(Float64(t_1 * sin(th)) / sqrt(Float64((sin(kx) ^ 2.0) + (abs(ky) ^ 2.0))));
	else
		tmp = Float64(Float64(sin(th) / sqrt(Float64(0.5 - Float64(Float64(cos(Float64(kx + kx)) - Float64(1.0 - cos(Float64(abs(ky) + abs(ky))))) * 0.5)))) * t_1);
	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 (abs(ky) <= 5.7e-157)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	elseif (abs(ky) <= 4.5e-8)
		tmp = (t_1 * sin(th)) / sqrt(((sin(kx) ^ 2.0) + (abs(ky) ^ 2.0)));
	else
		tmp = (sin(th) / sqrt((0.5 - ((cos((kx + kx)) - (1.0 - cos((abs(ky) + abs(ky))))) * 0.5)))) * t_1;
	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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 6800207735332289/151115727451828646838272], N[(N[(t$95$1 * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2], $MachinePrecision] + N[Power[N[Abs[ky], $MachinePrecision], 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(1/2 - N[(N[(N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision] - N[(1 - N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$1), $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}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\
\;\;\;\;\frac{t\_1 \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\left(\left|ky\right|\right)}^{2}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(\cos \left(kx + kx\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.7e-157

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.7e-157 < ky < 4.4999999999999999e-8

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      10. lower-sin.f6492.5%

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

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

      \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {ky}^{2}}} \]
    6. Step-by-step derivation
      1. lower-pow.f6444.7%

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

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

    if 4.4999999999999999e-8 < ky

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      10. lower-sin.f6492.5%

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

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

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

Alternative 7: 94.1% accurate, 1.1× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := \cos \left(kx + kx\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{7526271582073497}{147573952589676412928}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(t\_2 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(t\_2 - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))) (t_2 (cos (+ kx kx))))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (if (<= (fabs ky) 7526271582073497/147573952589676412928)
       (*
        (/ t_1 (sqrt (- (* (fabs ky) (fabs ky)) (* (- t_2 1) 1/2))))
        (sin th))
       (*
        (/
         (sin th)
         (sqrt
          (-
           1/2
           (* (- t_2 (- 1 (cos (+ (fabs ky) (fabs ky))))) 1/2))))
        t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = cos((kx + kx));
	double tmp;
	if (fabs(ky) <= 5.7e-157) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else if (fabs(ky) <= 5.1e-5) {
		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - ((t_2 - 1.0) * 0.5)))) * sin(th);
	} else {
		tmp = (sin(th) / sqrt((0.5 - ((t_2 - (1.0 - cos((fabs(ky) + fabs(ky))))) * 0.5)))) * t_1;
	}
	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.cos((kx + kx));
	double tmp;
	if (Math.abs(ky) <= 5.7e-157) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else if (Math.abs(ky) <= 5.1e-5) {
		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - ((t_2 - 1.0) * 0.5)))) * Math.sin(th);
	} else {
		tmp = (Math.sin(th) / Math.sqrt((0.5 - ((t_2 - (1.0 - Math.cos((Math.abs(ky) + Math.abs(ky))))) * 0.5)))) * t_1;
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	t_2 = math.cos((kx + kx))
	tmp = 0
	if math.fabs(ky) <= 5.7e-157:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	elif math.fabs(ky) <= 5.1e-5:
		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - ((t_2 - 1.0) * 0.5)))) * math.sin(th)
	else:
		tmp = (math.sin(th) / math.sqrt((0.5 - ((t_2 - (1.0 - math.cos((math.fabs(ky) + math.fabs(ky))))) * 0.5)))) * t_1
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = cos(Float64(kx + kx))
	tmp = 0.0
	if (abs(ky) <= 5.7e-157)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	elseif (abs(ky) <= 5.1e-5)
		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(Float64(t_2 - 1.0) * 0.5)))) * sin(th));
	else
		tmp = Float64(Float64(sin(th) / sqrt(Float64(0.5 - Float64(Float64(t_2 - Float64(1.0 - cos(Float64(abs(ky) + abs(ky))))) * 0.5)))) * t_1);
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	t_2 = cos((kx + kx));
	tmp = 0.0;
	if (abs(ky) <= 5.7e-157)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	elseif (abs(ky) <= 5.1e-5)
		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - ((t_2 - 1.0) * 0.5)))) * sin(th);
	else
		tmp = (sin(th) / sqrt((0.5 - ((t_2 - (1.0 - cos((abs(ky) + abs(ky))))) * 0.5)))) * t_1;
	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[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 7526271582073497/147573952589676412928], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(N[(t$95$2 - 1), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(1/2 - N[(N[(t$95$2 - N[(1 - N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := \cos \left(kx + kx\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{elif}\;\left|ky\right| \leq \frac{7526271582073497}{147573952589676412928}:\\
\;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(t\_2 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th}{\sqrt{\frac{1}{2} - \left(t\_2 - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}}} \cdot t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.7e-157

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.7e-157 < ky < 5.1e-5

    1. Initial program 94.3%

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

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

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

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

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

    if 5.1e-5 < ky

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      10. lower-sin.f6492.5%

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

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

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

Alternative 8: 83.6% accurate, 0.2× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := {t\_1}^{2}\\ t_3 := \frac{t\_1}{\sqrt{t\_2}} \cdot \sin th\\ t_4 := {\sin \left(\left|kx\right|\right)}^{2}\\ t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\ t_6 := th \cdot t\_1\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_5 \leq \frac{-4494592428115755}{4503599627370496}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_5 \leq \frac{-3332663724254167}{9007199254740992}:\\ \;\;\;\;{\left(\frac{1}{2} - \left(\cos \left(\left|kx\right| + \left|kx\right|\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}\right)}^{\frac{-1}{2}} \cdot t\_6\\ \mathbf{elif}\;t\_5 \leq \frac{944473296573929}{9444732965739290427392}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_4}} \cdot \sin th\\ \mathbf{elif}\;t\_5 \leq \frac{4458563631096791}{4503599627370496}:\\ \;\;\;\;\frac{t\_6}{\sqrt{t\_2 - \frac{1}{2} \cdot \left(\cos \left(2 \cdot \left|kx\right|\right) - 1\right)}}\\ \mathbf{elif}\;t\_5 \leq 2:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (pow t_1 2))
       (t_3 (* (/ t_1 (sqrt t_2)) (sin th)))
       (t_4 (pow (sin (fabs kx)) 2))
       (t_5 (/ t_1 (sqrt (+ t_4 t_2))))
       (t_6 (* th t_1)))
  (*
   (copysign 1 ky)
   (if (<= t_5 -4494592428115755/4503599627370496)
     t_3
     (if (<= t_5 -3332663724254167/9007199254740992)
       (*
        (pow
         (-
          1/2
          (*
           (-
            (cos (+ (fabs kx) (fabs kx)))
            (- 1 (cos (+ (fabs ky) (fabs ky)))))
           1/2))
         -1/2)
        t_6)
       (if (<= t_5 944473296573929/9444732965739290427392)
         (* (/ t_1 (sqrt t_4)) (sin th))
         (if (<= t_5 4458563631096791/4503599627370496)
           (/ t_6 (sqrt (- t_2 (* 1/2 (- (cos (* 2 (fabs kx))) 1)))))
           (if (<= t_5 2)
             t_3
             (* (sin th) (/ (fabs ky) (fabs kx)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = pow(t_1, 2.0);
	double t_3 = (t_1 / sqrt(t_2)) * sin(th);
	double t_4 = pow(sin(fabs(kx)), 2.0);
	double t_5 = t_1 / sqrt((t_4 + t_2));
	double t_6 = th * t_1;
	double tmp;
	if (t_5 <= -0.998) {
		tmp = t_3;
	} else if (t_5 <= -0.37) {
		tmp = pow((0.5 - ((cos((fabs(kx) + fabs(kx))) - (1.0 - cos((fabs(ky) + fabs(ky))))) * 0.5)), -0.5) * t_6;
	} else if (t_5 <= 1e-7) {
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	} else if (t_5 <= 0.99) {
		tmp = t_6 / sqrt((t_2 - (0.5 * (cos((2.0 * fabs(kx))) - 1.0))));
	} else if (t_5 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = sin(th) * (fabs(ky) / fabs(kx));
	}
	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 t_3 = (t_1 / Math.sqrt(t_2)) * Math.sin(th);
	double t_4 = Math.pow(Math.sin(Math.abs(kx)), 2.0);
	double t_5 = t_1 / Math.sqrt((t_4 + t_2));
	double t_6 = th * t_1;
	double tmp;
	if (t_5 <= -0.998) {
		tmp = t_3;
	} else if (t_5 <= -0.37) {
		tmp = Math.pow((0.5 - ((Math.cos((Math.abs(kx) + Math.abs(kx))) - (1.0 - Math.cos((Math.abs(ky) + Math.abs(ky))))) * 0.5)), -0.5) * t_6;
	} else if (t_5 <= 1e-7) {
		tmp = (t_1 / Math.sqrt(t_4)) * Math.sin(th);
	} else if (t_5 <= 0.99) {
		tmp = t_6 / Math.sqrt((t_2 - (0.5 * (Math.cos((2.0 * Math.abs(kx))) - 1.0))));
	} else if (t_5 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
	}
	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)
	t_3 = (t_1 / math.sqrt(t_2)) * math.sin(th)
	t_4 = math.pow(math.sin(math.fabs(kx)), 2.0)
	t_5 = t_1 / math.sqrt((t_4 + t_2))
	t_6 = th * t_1
	tmp = 0
	if t_5 <= -0.998:
		tmp = t_3
	elif t_5 <= -0.37:
		tmp = math.pow((0.5 - ((math.cos((math.fabs(kx) + math.fabs(kx))) - (1.0 - math.cos((math.fabs(ky) + math.fabs(ky))))) * 0.5)), -0.5) * t_6
	elif t_5 <= 1e-7:
		tmp = (t_1 / math.sqrt(t_4)) * math.sin(th)
	elif t_5 <= 0.99:
		tmp = t_6 / math.sqrt((t_2 - (0.5 * (math.cos((2.0 * math.fabs(kx))) - 1.0))))
	elif t_5 <= 2.0:
		tmp = t_3
	else:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = t_1 ^ 2.0
	t_3 = Float64(Float64(t_1 / sqrt(t_2)) * sin(th))
	t_4 = sin(abs(kx)) ^ 2.0
	t_5 = Float64(t_1 / sqrt(Float64(t_4 + t_2)))
	t_6 = Float64(th * t_1)
	tmp = 0.0
	if (t_5 <= -0.998)
		tmp = t_3;
	elseif (t_5 <= -0.37)
		tmp = Float64((Float64(0.5 - Float64(Float64(cos(Float64(abs(kx) + abs(kx))) - Float64(1.0 - cos(Float64(abs(ky) + abs(ky))))) * 0.5)) ^ -0.5) * t_6);
	elseif (t_5 <= 1e-7)
		tmp = Float64(Float64(t_1 / sqrt(t_4)) * sin(th));
	elseif (t_5 <= 0.99)
		tmp = Float64(t_6 / sqrt(Float64(t_2 - Float64(0.5 * Float64(cos(Float64(2.0 * abs(kx))) - 1.0)))));
	elseif (t_5 <= 2.0)
		tmp = t_3;
	else
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
	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;
	t_3 = (t_1 / sqrt(t_2)) * sin(th);
	t_4 = sin(abs(kx)) ^ 2.0;
	t_5 = t_1 / sqrt((t_4 + t_2));
	t_6 = th * t_1;
	tmp = 0.0;
	if (t_5 <= -0.998)
		tmp = t_3;
	elseif (t_5 <= -0.37)
		tmp = ((0.5 - ((cos((abs(kx) + abs(kx))) - (1.0 - cos((abs(ky) + abs(ky))))) * 0.5)) ^ -0.5) * t_6;
	elseif (t_5 <= 1e-7)
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	elseif (t_5 <= 0.99)
		tmp = t_6 / sqrt((t_2 - (0.5 * (cos((2.0 * abs(kx))) - 1.0))));
	elseif (t_5 <= 2.0)
		tmp = t_3;
	else
		tmp = sin(th) * (abs(ky) / abs(kx));
	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], $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$1 / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2], $MachinePrecision]}, Block[{t$95$5 = N[(t$95$1 / N[Sqrt[N[(t$95$4 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[(th * t$95$1), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$5, -4494592428115755/4503599627370496], t$95$3, If[LessEqual[t$95$5, -3332663724254167/9007199254740992], N[(N[Power[N[(1/2 - N[(N[(N[Cos[N[(N[Abs[kx], $MachinePrecision] + N[Abs[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(1 - N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision], -1/2], $MachinePrecision] * t$95$6), $MachinePrecision], If[LessEqual[t$95$5, 944473296573929/9444732965739290427392], N[(N[(t$95$1 / N[Sqrt[t$95$4], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$5, 4458563631096791/4503599627370496], N[(t$95$6 / N[Sqrt[N[(t$95$2 - N[(1/2 * N[(N[Cos[N[(2 * N[Abs[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$5, 2], t$95$3, N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]]]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := {t\_1}^{2}\\
t_3 := \frac{t\_1}{\sqrt{t\_2}} \cdot \sin th\\
t_4 := {\sin \left(\left|kx\right|\right)}^{2}\\
t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\
t_6 := th \cdot t\_1\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_5 \leq \frac{-4494592428115755}{4503599627370496}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_5 \leq \frac{-3332663724254167}{9007199254740992}:\\
\;\;\;\;{\left(\frac{1}{2} - \left(\cos \left(\left|kx\right| + \left|kx\right|\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}\right)}^{\frac{-1}{2}} \cdot t\_6\\

\mathbf{elif}\;t\_5 \leq \frac{944473296573929}{9444732965739290427392}:\\
\;\;\;\;\frac{t\_1}{\sqrt{t\_4}} \cdot \sin th\\

\mathbf{elif}\;t\_5 \leq \frac{4458563631096791}{4503599627370496}:\\
\;\;\;\;\frac{t\_6}{\sqrt{t\_2 - \frac{1}{2} \cdot \left(\cos \left(2 \cdot \left|kx\right|\right) - 1\right)}}\\

\mathbf{elif}\;t\_5 \leq 2:\\
\;\;\;\;t\_3\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\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))))) < -0.998 or 0.98999999999999999 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

    1. Initial program 94.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \cdot \sin th \]
      2. lower-sin.f6441.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin 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))))) < -0.37

    1. Initial program 94.3%

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
      2. lift-/.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)} \]
    3. Applied rewrites76.2%

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

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

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

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

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

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

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

    1. Initial program 94.3%

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

      \[\leadsto \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.1%

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

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

    if 9.9999999999999995e-8 < (/.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.98999999999999999

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{th \cdot \sin ky}{\sqrt{{\sin ky}^{2} - \frac{1}{2} \cdot \left(\cos \left(2 \cdot kx\right) - 1\right)}} \]
      11. lower-*.f6444.0%

        \[\leadsto \frac{th \cdot \sin ky}{\sqrt{{\sin ky}^{2} - \frac{1}{2} \cdot \left(\cos \left(2 \cdot kx\right) - 1\right)}} \]
    8. Applied rewrites44.0%

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

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

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
      3. lower-sin.f6415.6%

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
      6. lower-/.f6416.6%

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

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

Alternative 9: 83.6% accurate, 0.2× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := {t\_1}^{2}\\ t_3 := \frac{t\_1}{\sqrt{t\_2}} \cdot \sin th\\ t_4 := {\left(\frac{1}{2} - \left(\cos \left(\left|kx\right| + \left|kx\right|\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}\right)}^{\frac{-1}{2}} \cdot \left(th \cdot t\_1\right)\\ t_5 := {\sin \left(\left|kx\right|\right)}^{2}\\ t_6 := \frac{t\_1}{\sqrt{t\_5 + t\_2}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_6 \leq \frac{-4494592428115755}{4503599627370496}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_6 \leq \frac{-3332663724254167}{9007199254740992}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_6 \leq \frac{944473296573929}{9444732965739290427392}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_5}} \cdot \sin th\\ \mathbf{elif}\;t\_6 \leq \frac{4458563631096791}{4503599627370496}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_6 \leq 2:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (pow t_1 2))
       (t_3 (* (/ t_1 (sqrt t_2)) (sin th)))
       (t_4
        (*
         (pow
          (-
           1/2
           (*
            (-
             (cos (+ (fabs kx) (fabs kx)))
             (- 1 (cos (+ (fabs ky) (fabs ky)))))
            1/2))
          -1/2)
         (* th t_1)))
       (t_5 (pow (sin (fabs kx)) 2))
       (t_6 (/ t_1 (sqrt (+ t_5 t_2)))))
  (*
   (copysign 1 ky)
   (if (<= t_6 -4494592428115755/4503599627370496)
     t_3
     (if (<= t_6 -3332663724254167/9007199254740992)
       t_4
       (if (<= t_6 944473296573929/9444732965739290427392)
         (* (/ t_1 (sqrt t_5)) (sin th))
         (if (<= t_6 4458563631096791/4503599627370496)
           t_4
           (if (<= t_6 2)
             t_3
             (* (sin th) (/ (fabs ky) (fabs kx)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = pow(t_1, 2.0);
	double t_3 = (t_1 / sqrt(t_2)) * sin(th);
	double t_4 = pow((0.5 - ((cos((fabs(kx) + fabs(kx))) - (1.0 - cos((fabs(ky) + fabs(ky))))) * 0.5)), -0.5) * (th * t_1);
	double t_5 = pow(sin(fabs(kx)), 2.0);
	double t_6 = t_1 / sqrt((t_5 + t_2));
	double tmp;
	if (t_6 <= -0.998) {
		tmp = t_3;
	} else if (t_6 <= -0.37) {
		tmp = t_4;
	} else if (t_6 <= 1e-7) {
		tmp = (t_1 / sqrt(t_5)) * sin(th);
	} else if (t_6 <= 0.99) {
		tmp = t_4;
	} else if (t_6 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = sin(th) * (fabs(ky) / fabs(kx));
	}
	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 t_3 = (t_1 / Math.sqrt(t_2)) * Math.sin(th);
	double t_4 = Math.pow((0.5 - ((Math.cos((Math.abs(kx) + Math.abs(kx))) - (1.0 - Math.cos((Math.abs(ky) + Math.abs(ky))))) * 0.5)), -0.5) * (th * t_1);
	double t_5 = Math.pow(Math.sin(Math.abs(kx)), 2.0);
	double t_6 = t_1 / Math.sqrt((t_5 + t_2));
	double tmp;
	if (t_6 <= -0.998) {
		tmp = t_3;
	} else if (t_6 <= -0.37) {
		tmp = t_4;
	} else if (t_6 <= 1e-7) {
		tmp = (t_1 / Math.sqrt(t_5)) * Math.sin(th);
	} else if (t_6 <= 0.99) {
		tmp = t_4;
	} else if (t_6 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
	}
	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)
	t_3 = (t_1 / math.sqrt(t_2)) * math.sin(th)
	t_4 = math.pow((0.5 - ((math.cos((math.fabs(kx) + math.fabs(kx))) - (1.0 - math.cos((math.fabs(ky) + math.fabs(ky))))) * 0.5)), -0.5) * (th * t_1)
	t_5 = math.pow(math.sin(math.fabs(kx)), 2.0)
	t_6 = t_1 / math.sqrt((t_5 + t_2))
	tmp = 0
	if t_6 <= -0.998:
		tmp = t_3
	elif t_6 <= -0.37:
		tmp = t_4
	elif t_6 <= 1e-7:
		tmp = (t_1 / math.sqrt(t_5)) * math.sin(th)
	elif t_6 <= 0.99:
		tmp = t_4
	elif t_6 <= 2.0:
		tmp = t_3
	else:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = t_1 ^ 2.0
	t_3 = Float64(Float64(t_1 / sqrt(t_2)) * sin(th))
	t_4 = Float64((Float64(0.5 - Float64(Float64(cos(Float64(abs(kx) + abs(kx))) - Float64(1.0 - cos(Float64(abs(ky) + abs(ky))))) * 0.5)) ^ -0.5) * Float64(th * t_1))
	t_5 = sin(abs(kx)) ^ 2.0
	t_6 = Float64(t_1 / sqrt(Float64(t_5 + t_2)))
	tmp = 0.0
	if (t_6 <= -0.998)
		tmp = t_3;
	elseif (t_6 <= -0.37)
		tmp = t_4;
	elseif (t_6 <= 1e-7)
		tmp = Float64(Float64(t_1 / sqrt(t_5)) * sin(th));
	elseif (t_6 <= 0.99)
		tmp = t_4;
	elseif (t_6 <= 2.0)
		tmp = t_3;
	else
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
	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;
	t_3 = (t_1 / sqrt(t_2)) * sin(th);
	t_4 = ((0.5 - ((cos((abs(kx) + abs(kx))) - (1.0 - cos((abs(ky) + abs(ky))))) * 0.5)) ^ -0.5) * (th * t_1);
	t_5 = sin(abs(kx)) ^ 2.0;
	t_6 = t_1 / sqrt((t_5 + t_2));
	tmp = 0.0;
	if (t_6 <= -0.998)
		tmp = t_3;
	elseif (t_6 <= -0.37)
		tmp = t_4;
	elseif (t_6 <= 1e-7)
		tmp = (t_1 / sqrt(t_5)) * sin(th);
	elseif (t_6 <= 0.99)
		tmp = t_4;
	elseif (t_6 <= 2.0)
		tmp = t_3;
	else
		tmp = sin(th) * (abs(ky) / abs(kx));
	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], $MachinePrecision]}, Block[{t$95$3 = N[(N[(t$95$1 / N[Sqrt[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$4 = N[(N[Power[N[(1/2 - N[(N[(N[Cos[N[(N[Abs[kx], $MachinePrecision] + N[Abs[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - N[(1 - N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision], -1/2], $MachinePrecision] * N[(th * t$95$1), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2], $MachinePrecision]}, Block[{t$95$6 = N[(t$95$1 / N[Sqrt[N[(t$95$5 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$6, -4494592428115755/4503599627370496], t$95$3, If[LessEqual[t$95$6, -3332663724254167/9007199254740992], t$95$4, If[LessEqual[t$95$6, 944473296573929/9444732965739290427392], N[(N[(t$95$1 / N[Sqrt[t$95$5], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$6, 4458563631096791/4503599627370496], t$95$4, If[LessEqual[t$95$6, 2], t$95$3, N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]]]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := {t\_1}^{2}\\
t_3 := \frac{t\_1}{\sqrt{t\_2}} \cdot \sin th\\
t_4 := {\left(\frac{1}{2} - \left(\cos \left(\left|kx\right| + \left|kx\right|\right) - \left(1 - \cos \left(\left|ky\right| + \left|ky\right|\right)\right)\right) \cdot \frac{1}{2}\right)}^{\frac{-1}{2}} \cdot \left(th \cdot t\_1\right)\\
t_5 := {\sin \left(\left|kx\right|\right)}^{2}\\
t_6 := \frac{t\_1}{\sqrt{t\_5 + t\_2}}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_6 \leq \frac{-4494592428115755}{4503599627370496}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_6 \leq \frac{-3332663724254167}{9007199254740992}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_6 \leq \frac{944473296573929}{9444732965739290427392}:\\
\;\;\;\;\frac{t\_1}{\sqrt{t\_5}} \cdot \sin th\\

\mathbf{elif}\;t\_6 \leq \frac{4458563631096791}{4503599627370496}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_6 \leq 2:\\
\;\;\;\;t\_3\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\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))))) < -0.998 or 0.98999999999999999 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

    1. Initial program 94.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \cdot \sin th \]
      2. lower-sin.f6441.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin 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))))) < -0.37 or 9.9999999999999995e-8 < (/.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.98999999999999999

    1. Initial program 94.3%

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
      2. lift-/.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)} \]
    3. Applied rewrites76.2%

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

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

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

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

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

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

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

    1. Initial program 94.3%

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

      \[\leadsto \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.1%

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

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

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

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
      3. lower-sin.f6415.6%

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
      6. lower-/.f6416.6%

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

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

Alternative 10: 83.6% accurate, 0.2× speedup?

\[\begin{array}{l} t_1 := \cos \left(\left|kx\right| + \left|kx\right|\right)\\ t_2 := \cos \left(\left|ky\right| + \left|ky\right|\right)\\ t_3 := \sin \left(\left|ky\right|\right)\\ t_4 := {t\_3}^{2}\\ t_5 := \frac{t\_3}{\sqrt{t\_4}} \cdot \sin th\\ t_6 := {\sin \left(\left|kx\right|\right)}^{2}\\ t_7 := \frac{t\_3}{\sqrt{t\_6 + t\_4}}\\ t_8 := th \cdot t\_3\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_7 \leq \frac{-4494592428115755}{4503599627370496}:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_7 \leq \frac{-3332663724254167}{9007199254740992}:\\ \;\;\;\;\frac{t\_8}{\sqrt{\frac{1}{2} - \left(t\_1 - \left(1 - t\_2\right)\right) \cdot \frac{1}{2}}}\\ \mathbf{elif}\;t\_7 \leq \frac{944473296573929}{9444732965739290427392}:\\ \;\;\;\;\frac{t\_3}{\sqrt{t\_6}} \cdot \sin th\\ \mathbf{elif}\;t\_7 \leq \frac{4458563631096791}{4503599627370496}:\\ \;\;\;\;\frac{1}{\sqrt{\frac{1}{2} - \left(t\_2 - \left(1 - t\_1\right)\right) \cdot \frac{1}{2}}} \cdot t\_8\\ \mathbf{elif}\;t\_7 \leq 2:\\ \;\;\;\;t\_5\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (cos (+ (fabs kx) (fabs kx))))
       (t_2 (cos (+ (fabs ky) (fabs ky))))
       (t_3 (sin (fabs ky)))
       (t_4 (pow t_3 2))
       (t_5 (* (/ t_3 (sqrt t_4)) (sin th)))
       (t_6 (pow (sin (fabs kx)) 2))
       (t_7 (/ t_3 (sqrt (+ t_6 t_4))))
       (t_8 (* th t_3)))
  (*
   (copysign 1 ky)
   (if (<= t_7 -4494592428115755/4503599627370496)
     t_5
     (if (<= t_7 -3332663724254167/9007199254740992)
       (/ t_8 (sqrt (- 1/2 (* (- t_1 (- 1 t_2)) 1/2))))
       (if (<= t_7 944473296573929/9444732965739290427392)
         (* (/ t_3 (sqrt t_6)) (sin th))
         (if (<= t_7 4458563631096791/4503599627370496)
           (* (/ 1 (sqrt (- 1/2 (* (- t_2 (- 1 t_1)) 1/2)))) t_8)
           (if (<= t_7 2)
             t_5
             (* (sin th) (/ (fabs ky) (fabs kx)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = cos((fabs(kx) + fabs(kx)));
	double t_2 = cos((fabs(ky) + fabs(ky)));
	double t_3 = sin(fabs(ky));
	double t_4 = pow(t_3, 2.0);
	double t_5 = (t_3 / sqrt(t_4)) * sin(th);
	double t_6 = pow(sin(fabs(kx)), 2.0);
	double t_7 = t_3 / sqrt((t_6 + t_4));
	double t_8 = th * t_3;
	double tmp;
	if (t_7 <= -0.998) {
		tmp = t_5;
	} else if (t_7 <= -0.37) {
		tmp = t_8 / sqrt((0.5 - ((t_1 - (1.0 - t_2)) * 0.5)));
	} else if (t_7 <= 1e-7) {
		tmp = (t_3 / sqrt(t_6)) * sin(th);
	} else if (t_7 <= 0.99) {
		tmp = (1.0 / sqrt((0.5 - ((t_2 - (1.0 - t_1)) * 0.5)))) * t_8;
	} else if (t_7 <= 2.0) {
		tmp = t_5;
	} else {
		tmp = sin(th) * (fabs(ky) / fabs(kx));
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.cos((Math.abs(kx) + Math.abs(kx)));
	double t_2 = Math.cos((Math.abs(ky) + Math.abs(ky)));
	double t_3 = Math.sin(Math.abs(ky));
	double t_4 = Math.pow(t_3, 2.0);
	double t_5 = (t_3 / Math.sqrt(t_4)) * Math.sin(th);
	double t_6 = Math.pow(Math.sin(Math.abs(kx)), 2.0);
	double t_7 = t_3 / Math.sqrt((t_6 + t_4));
	double t_8 = th * t_3;
	double tmp;
	if (t_7 <= -0.998) {
		tmp = t_5;
	} else if (t_7 <= -0.37) {
		tmp = t_8 / Math.sqrt((0.5 - ((t_1 - (1.0 - t_2)) * 0.5)));
	} else if (t_7 <= 1e-7) {
		tmp = (t_3 / Math.sqrt(t_6)) * Math.sin(th);
	} else if (t_7 <= 0.99) {
		tmp = (1.0 / Math.sqrt((0.5 - ((t_2 - (1.0 - t_1)) * 0.5)))) * t_8;
	} else if (t_7 <= 2.0) {
		tmp = t_5;
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.cos((math.fabs(kx) + math.fabs(kx)))
	t_2 = math.cos((math.fabs(ky) + math.fabs(ky)))
	t_3 = math.sin(math.fabs(ky))
	t_4 = math.pow(t_3, 2.0)
	t_5 = (t_3 / math.sqrt(t_4)) * math.sin(th)
	t_6 = math.pow(math.sin(math.fabs(kx)), 2.0)
	t_7 = t_3 / math.sqrt((t_6 + t_4))
	t_8 = th * t_3
	tmp = 0
	if t_7 <= -0.998:
		tmp = t_5
	elif t_7 <= -0.37:
		tmp = t_8 / math.sqrt((0.5 - ((t_1 - (1.0 - t_2)) * 0.5)))
	elif t_7 <= 1e-7:
		tmp = (t_3 / math.sqrt(t_6)) * math.sin(th)
	elif t_7 <= 0.99:
		tmp = (1.0 / math.sqrt((0.5 - ((t_2 - (1.0 - t_1)) * 0.5)))) * t_8
	elif t_7 <= 2.0:
		tmp = t_5
	else:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = cos(Float64(abs(kx) + abs(kx)))
	t_2 = cos(Float64(abs(ky) + abs(ky)))
	t_3 = sin(abs(ky))
	t_4 = t_3 ^ 2.0
	t_5 = Float64(Float64(t_3 / sqrt(t_4)) * sin(th))
	t_6 = sin(abs(kx)) ^ 2.0
	t_7 = Float64(t_3 / sqrt(Float64(t_6 + t_4)))
	t_8 = Float64(th * t_3)
	tmp = 0.0
	if (t_7 <= -0.998)
		tmp = t_5;
	elseif (t_7 <= -0.37)
		tmp = Float64(t_8 / sqrt(Float64(0.5 - Float64(Float64(t_1 - Float64(1.0 - t_2)) * 0.5))));
	elseif (t_7 <= 1e-7)
		tmp = Float64(Float64(t_3 / sqrt(t_6)) * sin(th));
	elseif (t_7 <= 0.99)
		tmp = Float64(Float64(1.0 / sqrt(Float64(0.5 - Float64(Float64(t_2 - Float64(1.0 - t_1)) * 0.5)))) * t_8);
	elseif (t_7 <= 2.0)
		tmp = t_5;
	else
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = cos((abs(kx) + abs(kx)));
	t_2 = cos((abs(ky) + abs(ky)));
	t_3 = sin(abs(ky));
	t_4 = t_3 ^ 2.0;
	t_5 = (t_3 / sqrt(t_4)) * sin(th);
	t_6 = sin(abs(kx)) ^ 2.0;
	t_7 = t_3 / sqrt((t_6 + t_4));
	t_8 = th * t_3;
	tmp = 0.0;
	if (t_7 <= -0.998)
		tmp = t_5;
	elseif (t_7 <= -0.37)
		tmp = t_8 / sqrt((0.5 - ((t_1 - (1.0 - t_2)) * 0.5)));
	elseif (t_7 <= 1e-7)
		tmp = (t_3 / sqrt(t_6)) * sin(th);
	elseif (t_7 <= 0.99)
		tmp = (1.0 / sqrt((0.5 - ((t_2 - (1.0 - t_1)) * 0.5)))) * t_8;
	elseif (t_7 <= 2.0)
		tmp = t_5;
	else
		tmp = sin(th) * (abs(ky) / abs(kx));
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Cos[N[(N[Abs[kx], $MachinePrecision] + N[Abs[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$4 = N[Power[t$95$3, 2], $MachinePrecision]}, Block[{t$95$5 = N[(N[(t$95$3 / N[Sqrt[t$95$4], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2], $MachinePrecision]}, Block[{t$95$7 = N[(t$95$3 / N[Sqrt[N[(t$95$6 + t$95$4), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$8 = N[(th * t$95$3), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$7, -4494592428115755/4503599627370496], t$95$5, If[LessEqual[t$95$7, -3332663724254167/9007199254740992], N[(t$95$8 / N[Sqrt[N[(1/2 - N[(N[(t$95$1 - N[(1 - t$95$2), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$7, 944473296573929/9444732965739290427392], N[(N[(t$95$3 / N[Sqrt[t$95$6], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$7, 4458563631096791/4503599627370496], N[(N[(1 / N[Sqrt[N[(1/2 - N[(N[(t$95$2 - N[(1 - t$95$1), $MachinePrecision]), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * t$95$8), $MachinePrecision], If[LessEqual[t$95$7, 2], t$95$5, N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]]]]]]]
\begin{array}{l}
t_1 := \cos \left(\left|kx\right| + \left|kx\right|\right)\\
t_2 := \cos \left(\left|ky\right| + \left|ky\right|\right)\\
t_3 := \sin \left(\left|ky\right|\right)\\
t_4 := {t\_3}^{2}\\
t_5 := \frac{t\_3}{\sqrt{t\_4}} \cdot \sin th\\
t_6 := {\sin \left(\left|kx\right|\right)}^{2}\\
t_7 := \frac{t\_3}{\sqrt{t\_6 + t\_4}}\\
t_8 := th \cdot t\_3\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_7 \leq \frac{-4494592428115755}{4503599627370496}:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_7 \leq \frac{-3332663724254167}{9007199254740992}:\\
\;\;\;\;\frac{t\_8}{\sqrt{\frac{1}{2} - \left(t\_1 - \left(1 - t\_2\right)\right) \cdot \frac{1}{2}}}\\

\mathbf{elif}\;t\_7 \leq \frac{944473296573929}{9444732965739290427392}:\\
\;\;\;\;\frac{t\_3}{\sqrt{t\_6}} \cdot \sin th\\

\mathbf{elif}\;t\_7 \leq \frac{4458563631096791}{4503599627370496}:\\
\;\;\;\;\frac{1}{\sqrt{\frac{1}{2} - \left(t\_2 - \left(1 - t\_1\right)\right) \cdot \frac{1}{2}}} \cdot t\_8\\

\mathbf{elif}\;t\_7 \leq 2:\\
\;\;\;\;t\_5\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\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))))) < -0.998 or 0.98999999999999999 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

    1. Initial program 94.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \cdot \sin th \]
      2. lower-sin.f6441.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin 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))))) < -0.37

    1. Initial program 94.3%

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
      2. lift-/.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)} \]
    3. Applied rewrites76.2%

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

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

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

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

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

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

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

    1. Initial program 94.3%

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

      \[\leadsto \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.1%

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

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

    if 9.9999999999999995e-8 < (/.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.98999999999999999

    1. Initial program 94.3%

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
      2. lift-/.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)} \]
    3. Applied rewrites76.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\sqrt{\frac{1}{2} - \color{blue}{\left(\cos \left(ky + ky\right) - \left(1 - \cos \left(kx + kx\right)\right)\right) \cdot \frac{1}{2}}}} \cdot \left(th \cdot \sin ky\right) \]
      7. lower--.f6440.1%

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

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

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

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
      3. lower-sin.f6415.6%

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
      6. lower-/.f6416.6%

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

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

Alternative 11: 73.5% 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}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{6530219459687219}{4503599627370496}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(\cos \left(kx + kx\right) - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1 ky)
   (if (<=
        (fabs ky)
        8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696)
     (* (/ (sin th) (fabs (sin kx))) (fabs ky))
     (if (<= (fabs ky) 6530219459687219/4503599627370496)
       (*
        (/
         t_1
         (sqrt
          (- (* (fabs ky) (fabs ky)) (* (- (cos (+ kx kx)) 1) 1/2))))
        (sin th))
       (*
        (/ t_1 (sqrt (- 1/2 (* (cos (+ (fabs ky) (fabs ky))) 1/2))))
        (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if (fabs(ky) <= 5.7e-157) {
		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
	} else if (fabs(ky) <= 1.45) {
		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - ((cos((kx + kx)) - 1.0) * 0.5)))) * sin(th);
	} else {
		tmp = (t_1 / sqrt((0.5 - (cos((fabs(ky) + fabs(ky))) * 0.5)))) * 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 (Math.abs(ky) <= 5.7e-157) {
		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else if (Math.abs(ky) <= 1.45) {
		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - ((Math.cos((kx + kx)) - 1.0) * 0.5)))) * Math.sin(th);
	} else {
		tmp = (t_1 / Math.sqrt((0.5 - (Math.cos((Math.abs(ky) + Math.abs(ky))) * 0.5)))) * 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 math.fabs(ky) <= 5.7e-157:
		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
	elif math.fabs(ky) <= 1.45:
		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - ((math.cos((kx + kx)) - 1.0) * 0.5)))) * math.sin(th)
	else:
		tmp = (t_1 / math.sqrt((0.5 - (math.cos((math.fabs(ky) + math.fabs(ky))) * 0.5)))) * math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (abs(ky) <= 5.7e-157)
		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
	elseif (abs(ky) <= 1.45)
		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(Float64(cos(Float64(kx + kx)) - 1.0) * 0.5)))) * sin(th));
	else
		tmp = Float64(Float64(t_1 / sqrt(Float64(0.5 - Float64(cos(Float64(abs(ky) + abs(ky))) * 0.5)))) * 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 (abs(ky) <= 5.7e-157)
		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
	elseif (abs(ky) <= 1.45)
		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - ((cos((kx + kx)) - 1.0) * 0.5)))) * sin(th);
	else
		tmp = (t_1 / sqrt((0.5 - (cos((abs(ky) + abs(ky))) * 0.5)))) * 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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 8811145552479349/15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 6530219459687219/4503599627370496], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(N[(N[Cos[N[(kx + kx), $MachinePrecision]], $MachinePrecision] - 1), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[Sqrt[N[(1/2 - N[(N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $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}\;\left|ky\right| \leq \frac{8811145552479349}{15458150092069033378781407563727949377195709318825739994628941005806076569158241698144775066327690311849854464126008708709460314644171950622971634693868322994787923259293696}:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{elif}\;\left|ky\right| \leq \frac{6530219459687219}{4503599627370496}:\\
\;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(\cos \left(kx + kx\right) - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.7e-157

    1. Initial program 94.3%

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
      6. lower-sin.f6435.1%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
      5. pow-negN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      6. lower-unsound-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      7. lower-pow.f32N/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
      8. pow-flipN/A

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
      12. lower-/.f6435.0%

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
      16. rem-sqrt-squareN/A

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
      17. lower-fabs.f6437.2%

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
      4. remove-double-divN/A

        \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
      5. lift-*.f64N/A

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      9. lower-/.f6439.0%

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

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

    if 5.7e-157 < ky < 1.45

    1. Initial program 94.3%

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

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

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

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

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

    if 1.45 < ky

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

    Alternative 12: 66.4% 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}\;\left|ky\right| \leq \frac{6575919231766733}{2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - -1 \cdot {kx}^{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \end{array} \end{array} \]
    (FPCore (kx ky th)
      :precision binary64
      (let* ((t_1 (sin (fabs ky))))
      (*
       (copysign 1 ky)
       (if (<=
            (fabs ky)
            6575919231766733/2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976)
         (* (/ (sin th) (fabs (sin kx))) (fabs ky))
         (if (<= (fabs ky) 6800207735332289/151115727451828646838272)
           (*
            (/ t_1 (sqrt (- (* (fabs ky) (fabs ky)) (* -1 (pow kx 2)))))
            (sin th))
           (*
            (/ t_1 (sqrt (- 1/2 (* (cos (+ (fabs ky) (fabs ky))) 1/2))))
            (sin th)))))))
    double code(double kx, double ky, double th) {
    	double t_1 = sin(fabs(ky));
    	double tmp;
    	if (fabs(ky) <= 2.8e-93) {
    		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
    	} else if (fabs(ky) <= 4.5e-8) {
    		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - (-1.0 * pow(kx, 2.0))))) * sin(th);
    	} else {
    		tmp = (t_1 / sqrt((0.5 - (cos((fabs(ky) + fabs(ky))) * 0.5)))) * 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 (Math.abs(ky) <= 2.8e-93) {
    		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
    	} else if (Math.abs(ky) <= 4.5e-8) {
    		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - (-1.0 * Math.pow(kx, 2.0))))) * Math.sin(th);
    	} else {
    		tmp = (t_1 / Math.sqrt((0.5 - (Math.cos((Math.abs(ky) + Math.abs(ky))) * 0.5)))) * 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 math.fabs(ky) <= 2.8e-93:
    		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
    	elif math.fabs(ky) <= 4.5e-8:
    		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - (-1.0 * math.pow(kx, 2.0))))) * math.sin(th)
    	else:
    		tmp = (t_1 / math.sqrt((0.5 - (math.cos((math.fabs(ky) + math.fabs(ky))) * 0.5)))) * math.sin(th)
    	return math.copysign(1.0, ky) * tmp
    
    function code(kx, ky, th)
    	t_1 = sin(abs(ky))
    	tmp = 0.0
    	if (abs(ky) <= 2.8e-93)
    		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
    	elseif (abs(ky) <= 4.5e-8)
    		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(-1.0 * (kx ^ 2.0))))) * sin(th));
    	else
    		tmp = Float64(Float64(t_1 / sqrt(Float64(0.5 - Float64(cos(Float64(abs(ky) + abs(ky))) * 0.5)))) * 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 (abs(ky) <= 2.8e-93)
    		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
    	elseif (abs(ky) <= 4.5e-8)
    		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - (-1.0 * (kx ^ 2.0))))) * sin(th);
    	else
    		tmp = (t_1 / sqrt((0.5 - (cos((abs(ky) + abs(ky))) * 0.5)))) * 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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 6575919231766733/2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 6800207735332289/151115727451828646838272], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(-1 * N[Power[kx, 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[Sqrt[N[(1/2 - N[(N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $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}\;\left|ky\right| \leq \frac{6575919231766733}{2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976}:\\
    \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\
    
    \mathbf{elif}\;\left|ky\right| \leq \frac{6800207735332289}{151115727451828646838272}:\\
    \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - -1 \cdot {kx}^{2}}} \cdot \sin th\\
    
    \mathbf{else}:\\
    \;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 3 regimes
    2. if ky < 2.8e-93

      1. Initial program 94.3%

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

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

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

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

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

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

          \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
        6. lower-sin.f6435.1%

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

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

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

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

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

          \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
        5. pow-negN/A

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
        6. lower-unsound-pow.f32N/A

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
        7. lower-pow.f32N/A

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
        8. pow-flipN/A

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

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

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

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
        12. lower-/.f6435.0%

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

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

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

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
        16. rem-sqrt-squareN/A

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
        17. lower-fabs.f6437.2%

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

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

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

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

          \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
        4. remove-double-divN/A

          \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
        5. lift-*.f64N/A

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

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

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

          \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
        9. lower-/.f6439.0%

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

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

      if 2.8e-93 < ky < 4.4999999999999999e-8

      1. Initial program 94.3%

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

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

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

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

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

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

          \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - -1 \cdot \color{blue}{{kx}^{2}}}} \cdot \sin th \]
        2. lower-pow.f6428.2%

          \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - -1 \cdot {kx}^{\color{blue}{2}}}} \cdot \sin th \]
      8. Applied rewrites28.2%

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

      if 4.4999999999999999e-8 < ky

      1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

      Alternative 13: 65.1% accurate, 1.4× speedup?

      \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\left|ky\right| \leq \frac{6575919231766733}{2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976}:\\ \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;\left|ky\right| \leq \frac{6530219459687219}{4503599627370496}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \end{array} \end{array} \]
      (FPCore (kx ky th)
        :precision binary64
        (let* ((t_1 (sin (fabs ky))))
        (*
         (copysign 1 ky)
         (if (<=
              (fabs ky)
              6575919231766733/2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976)
           (* (/ (sin th) (fabs (sin kx))) (fabs ky))
           (if (<= (fabs ky) 6530219459687219/4503599627370496)
             (*
              (/ t_1 (sqrt (- (* (fabs ky) (fabs ky)) (* (- 1 1) 1/2))))
              (sin th))
             (*
              (/ t_1 (sqrt (- 1/2 (* (cos (+ (fabs ky) (fabs ky))) 1/2))))
              (sin th)))))))
      double code(double kx, double ky, double th) {
      	double t_1 = sin(fabs(ky));
      	double tmp;
      	if (fabs(ky) <= 2.8e-93) {
      		tmp = (sin(th) / fabs(sin(kx))) * fabs(ky);
      	} else if (fabs(ky) <= 1.45) {
      		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
      	} else {
      		tmp = (t_1 / sqrt((0.5 - (cos((fabs(ky) + fabs(ky))) * 0.5)))) * 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 (Math.abs(ky) <= 2.8e-93) {
      		tmp = (Math.sin(th) / Math.abs(Math.sin(kx))) * Math.abs(ky);
      	} else if (Math.abs(ky) <= 1.45) {
      		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - ((1.0 - 1.0) * 0.5)))) * Math.sin(th);
      	} else {
      		tmp = (t_1 / Math.sqrt((0.5 - (Math.cos((Math.abs(ky) + Math.abs(ky))) * 0.5)))) * 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 math.fabs(ky) <= 2.8e-93:
      		tmp = (math.sin(th) / math.fabs(math.sin(kx))) * math.fabs(ky)
      	elif math.fabs(ky) <= 1.45:
      		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * math.sin(th)
      	else:
      		tmp = (t_1 / math.sqrt((0.5 - (math.cos((math.fabs(ky) + math.fabs(ky))) * 0.5)))) * math.sin(th)
      	return math.copysign(1.0, ky) * tmp
      
      function code(kx, ky, th)
      	t_1 = sin(abs(ky))
      	tmp = 0.0
      	if (abs(ky) <= 2.8e-93)
      		tmp = Float64(Float64(sin(th) / abs(sin(kx))) * abs(ky));
      	elseif (abs(ky) <= 1.45)
      		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(Float64(1.0 - 1.0) * 0.5)))) * sin(th));
      	else
      		tmp = Float64(Float64(t_1 / sqrt(Float64(0.5 - Float64(cos(Float64(abs(ky) + abs(ky))) * 0.5)))) * 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 (abs(ky) <= 2.8e-93)
      		tmp = (sin(th) / abs(sin(kx))) * abs(ky);
      	elseif (abs(ky) <= 1.45)
      		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
      	else
      		tmp = (t_1 / sqrt((0.5 - (cos((abs(ky) + abs(ky))) * 0.5)))) * 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], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[ky], $MachinePrecision], 6575919231766733/2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Abs[ky], $MachinePrecision], 6530219459687219/4503599627370496], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(N[(1 - 1), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 / N[Sqrt[N[(1/2 - N[(N[Cos[N[(N[Abs[ky], $MachinePrecision] + N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $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}\;\left|ky\right| \leq \frac{6575919231766733}{2348542582773833227889480596789337027375682548908319870707290971532209025114608443463698998384768703031934976}:\\
      \;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\
      
      \mathbf{elif}\;\left|ky\right| \leq \frac{6530219459687219}{4503599627370496}:\\
      \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{t\_1}{\sqrt{\frac{1}{2} - \cos \left(\left|ky\right| + \left|ky\right|\right) \cdot \frac{1}{2}}} \cdot \sin th\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 3 regimes
      2. if ky < 2.8e-93

        1. Initial program 94.3%

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

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

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

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

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

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

            \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
          6. lower-sin.f6435.1%

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

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

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

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

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

            \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
          5. pow-negN/A

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
          6. lower-unsound-pow.f32N/A

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
          7. lower-pow.f32N/A

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
          8. pow-flipN/A

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

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

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

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
          12. lower-/.f6435.0%

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

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

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

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
          16. rem-sqrt-squareN/A

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
          17. lower-fabs.f6437.2%

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

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

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

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

            \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
          4. remove-double-divN/A

            \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
          5. lift-*.f64N/A

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

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

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

            \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
          9. lower-/.f6439.0%

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

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

        if 2.8e-93 < ky < 1.45

        1. Initial program 94.3%

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

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

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

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

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

          \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]
        7. Step-by-step derivation
          1. Applied rewrites13.8%

            \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]

          if 1.45 < ky

          1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

          Alternative 14: 55.4% accurate, 0.3× speedup?

          \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := \sin \left(\left|kx\right|\right)\\ t_3 := \frac{t\_1}{\sqrt{{t\_2}^{2} + {t\_1}^{2}}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_3 \leq \frac{-5404319552844595}{36028797018963968}:\\ \;\;\;\;\frac{1}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot \left|ky\right|\right)}} \cdot \left(th \cdot t\_1\right)\\ \mathbf{elif}\;t\_3 \leq \frac{3249347131147813}{4503599627370496}:\\ \;\;\;\;\frac{\sin th}{\left|t\_2\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \end{array} \end{array} \]
          (FPCore (kx ky th)
            :precision binary64
            (let* ((t_1 (sin (fabs ky)))
                 (t_2 (sin (fabs kx)))
                 (t_3 (/ t_1 (sqrt (+ (pow t_2 2) (pow t_1 2))))))
            (*
             (copysign 1 ky)
             (if (<= t_3 -5404319552844595/36028797018963968)
               (* (/ 1 (sqrt (- 1/2 (* 1/2 (cos (* 2 (fabs ky))))))) (* th t_1))
               (if (<= t_3 3249347131147813/4503599627370496)
                 (* (/ (sin th) (fabs t_2)) (fabs ky))
                 (if (<= t_3 2)
                   (*
                    (/ t_1 (sqrt (- (* (fabs ky) (fabs ky)) (* (- 1 1) 1/2))))
                    (sin th))
                   (* (sin th) (/ (fabs ky) (fabs kx)))))))))
          double code(double kx, double ky, double th) {
          	double t_1 = sin(fabs(ky));
          	double t_2 = sin(fabs(kx));
          	double t_3 = t_1 / sqrt((pow(t_2, 2.0) + pow(t_1, 2.0)));
          	double tmp;
          	if (t_3 <= -0.15) {
          		tmp = (1.0 / sqrt((0.5 - (0.5 * cos((2.0 * fabs(ky))))))) * (th * t_1);
          	} else if (t_3 <= 0.7215) {
          		tmp = (sin(th) / fabs(t_2)) * fabs(ky);
          	} else if (t_3 <= 2.0) {
          		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
          	} else {
          		tmp = sin(th) * (fabs(ky) / fabs(kx));
          	}
          	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.sin(Math.abs(kx));
          	double t_3 = t_1 / Math.sqrt((Math.pow(t_2, 2.0) + Math.pow(t_1, 2.0)));
          	double tmp;
          	if (t_3 <= -0.15) {
          		tmp = (1.0 / Math.sqrt((0.5 - (0.5 * Math.cos((2.0 * Math.abs(ky))))))) * (th * t_1);
          	} else if (t_3 <= 0.7215) {
          		tmp = (Math.sin(th) / Math.abs(t_2)) * Math.abs(ky);
          	} else if (t_3 <= 2.0) {
          		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - ((1.0 - 1.0) * 0.5)))) * Math.sin(th);
          	} else {
          		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
          	}
          	return Math.copySign(1.0, ky) * tmp;
          }
          
          def code(kx, ky, th):
          	t_1 = math.sin(math.fabs(ky))
          	t_2 = math.sin(math.fabs(kx))
          	t_3 = t_1 / math.sqrt((math.pow(t_2, 2.0) + math.pow(t_1, 2.0)))
          	tmp = 0
          	if t_3 <= -0.15:
          		tmp = (1.0 / math.sqrt((0.5 - (0.5 * math.cos((2.0 * math.fabs(ky))))))) * (th * t_1)
          	elif t_3 <= 0.7215:
          		tmp = (math.sin(th) / math.fabs(t_2)) * math.fabs(ky)
          	elif t_3 <= 2.0:
          		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * math.sin(th)
          	else:
          		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
          	return math.copysign(1.0, ky) * tmp
          
          function code(kx, ky, th)
          	t_1 = sin(abs(ky))
          	t_2 = sin(abs(kx))
          	t_3 = Float64(t_1 / sqrt(Float64((t_2 ^ 2.0) + (t_1 ^ 2.0))))
          	tmp = 0.0
          	if (t_3 <= -0.15)
          		tmp = Float64(Float64(1.0 / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(2.0 * abs(ky))))))) * Float64(th * t_1));
          	elseif (t_3 <= 0.7215)
          		tmp = Float64(Float64(sin(th) / abs(t_2)) * abs(ky));
          	elseif (t_3 <= 2.0)
          		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(Float64(1.0 - 1.0) * 0.5)))) * sin(th));
          	else
          		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
          	end
          	return Float64(copysign(1.0, ky) * tmp)
          end
          
          function tmp_2 = code(kx, ky, th)
          	t_1 = sin(abs(ky));
          	t_2 = sin(abs(kx));
          	t_3 = t_1 / sqrt(((t_2 ^ 2.0) + (t_1 ^ 2.0)));
          	tmp = 0.0;
          	if (t_3 <= -0.15)
          		tmp = (1.0 / sqrt((0.5 - (0.5 * cos((2.0 * abs(ky))))))) * (th * t_1);
          	elseif (t_3 <= 0.7215)
          		tmp = (sin(th) / abs(t_2)) * abs(ky);
          	elseif (t_3 <= 2.0)
          		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
          	else
          		tmp = sin(th) * (abs(ky) / abs(kx));
          	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[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 / N[Sqrt[N[(N[Power[t$95$2, 2], $MachinePrecision] + N[Power[t$95$1, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, -5404319552844595/36028797018963968], N[(N[(1 / N[Sqrt[N[(1/2 - N[(1/2 * N[Cos[N[(2 * N[Abs[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(th * t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 3249347131147813/4503599627370496], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(N[(1 - 1), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]), $MachinePrecision]]]]
          
          \begin{array}{l}
          t_1 := \sin \left(\left|ky\right|\right)\\
          t_2 := \sin \left(\left|kx\right|\right)\\
          t_3 := \frac{t\_1}{\sqrt{{t\_2}^{2} + {t\_1}^{2}}}\\
          \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
          \mathbf{if}\;t\_3 \leq \frac{-5404319552844595}{36028797018963968}:\\
          \;\;\;\;\frac{1}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot \left|ky\right|\right)}} \cdot \left(th \cdot t\_1\right)\\
          
          \mathbf{elif}\;t\_3 \leq \frac{3249347131147813}{4503599627370496}:\\
          \;\;\;\;\frac{\sin th}{\left|t\_2\right|} \cdot \left|ky\right|\\
          
          \mathbf{elif}\;t\_3 \leq 2:\\
          \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\
          
          \mathbf{else}:\\
          \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\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))))) < -0.14999999999999999

            1. Initial program 94.3%

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

                \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th} \]
              2. lift-/.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)} \]
            3. Applied rewrites76.2%

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

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

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

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

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

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

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

                \[\leadsto \frac{1}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot ky\right)}} \cdot \left(th \cdot \sin ky\right) \]
              3. lower-*.f6416.7%

                \[\leadsto \frac{1}{\sqrt{\frac{1}{2} - \frac{1}{2} \cdot \cos \left(2 \cdot ky\right)}} \cdot \left(th \cdot \sin ky\right) \]
            9. Applied rewrites16.7%

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

            if -0.14999999999999999 < (/.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.72150000000000003

            1. Initial program 94.3%

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

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

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

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

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

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

                \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
              6. lower-sin.f6435.1%

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

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

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

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

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

                \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
              5. pow-negN/A

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
              6. lower-unsound-pow.f32N/A

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
              7. lower-pow.f32N/A

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
              8. pow-flipN/A

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

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

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

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
              12. lower-/.f6435.0%

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

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

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

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
              16. rem-sqrt-squareN/A

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
              17. lower-fabs.f6437.2%

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

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

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

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

                \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
              4. remove-double-divN/A

                \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
              5. lift-*.f64N/A

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

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

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

                \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
              9. lower-/.f6439.0%

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

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

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

            1. Initial program 94.3%

              \[\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.f6446.5%

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

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

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

              \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]
            7. Step-by-step derivation
              1. Applied rewrites13.8%

                \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]

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

              1. Initial program 94.3%

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                3. lower-sin.f6415.6%

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

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

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

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

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

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

                  \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
                6. lower-/.f6416.6%

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

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

            Alternative 15: 47.9% accurate, 0.4× speedup?

            \[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := \sin \left(\left|kx\right|\right)\\ t_3 := \frac{t\_1}{\sqrt{{t\_2}^{2} + {t\_1}^{2}}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_3 \leq \frac{3249347131147813}{4503599627370496}:\\ \;\;\;\;\frac{\sin th}{\left|t\_2\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \end{array} \end{array} \]
            (FPCore (kx ky th)
              :precision binary64
              (let* ((t_1 (sin (fabs ky)))
                   (t_2 (sin (fabs kx)))
                   (t_3 (/ t_1 (sqrt (+ (pow t_2 2) (pow t_1 2))))))
              (*
               (copysign 1 ky)
               (if (<= t_3 3249347131147813/4503599627370496)
                 (* (/ (sin th) (fabs t_2)) (fabs ky))
                 (if (<= t_3 2)
                   (*
                    (/ t_1 (sqrt (- (* (fabs ky) (fabs ky)) (* (- 1 1) 1/2))))
                    (sin th))
                   (* (sin th) (/ (fabs ky) (fabs kx))))))))
            double code(double kx, double ky, double th) {
            	double t_1 = sin(fabs(ky));
            	double t_2 = sin(fabs(kx));
            	double t_3 = t_1 / sqrt((pow(t_2, 2.0) + pow(t_1, 2.0)));
            	double tmp;
            	if (t_3 <= 0.7215) {
            		tmp = (sin(th) / fabs(t_2)) * fabs(ky);
            	} else if (t_3 <= 2.0) {
            		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
            	} else {
            		tmp = sin(th) * (fabs(ky) / fabs(kx));
            	}
            	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.sin(Math.abs(kx));
            	double t_3 = t_1 / Math.sqrt((Math.pow(t_2, 2.0) + Math.pow(t_1, 2.0)));
            	double tmp;
            	if (t_3 <= 0.7215) {
            		tmp = (Math.sin(th) / Math.abs(t_2)) * Math.abs(ky);
            	} else if (t_3 <= 2.0) {
            		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) - ((1.0 - 1.0) * 0.5)))) * Math.sin(th);
            	} else {
            		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
            	}
            	return Math.copySign(1.0, ky) * tmp;
            }
            
            def code(kx, ky, th):
            	t_1 = math.sin(math.fabs(ky))
            	t_2 = math.sin(math.fabs(kx))
            	t_3 = t_1 / math.sqrt((math.pow(t_2, 2.0) + math.pow(t_1, 2.0)))
            	tmp = 0
            	if t_3 <= 0.7215:
            		tmp = (math.sin(th) / math.fabs(t_2)) * math.fabs(ky)
            	elif t_3 <= 2.0:
            		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) - ((1.0 - 1.0) * 0.5)))) * math.sin(th)
            	else:
            		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
            	return math.copysign(1.0, ky) * tmp
            
            function code(kx, ky, th)
            	t_1 = sin(abs(ky))
            	t_2 = sin(abs(kx))
            	t_3 = Float64(t_1 / sqrt(Float64((t_2 ^ 2.0) + (t_1 ^ 2.0))))
            	tmp = 0.0
            	if (t_3 <= 0.7215)
            		tmp = Float64(Float64(sin(th) / abs(t_2)) * abs(ky));
            	elseif (t_3 <= 2.0)
            		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) - Float64(Float64(1.0 - 1.0) * 0.5)))) * sin(th));
            	else
            		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
            	end
            	return Float64(copysign(1.0, ky) * tmp)
            end
            
            function tmp_2 = code(kx, ky, th)
            	t_1 = sin(abs(ky));
            	t_2 = sin(abs(kx));
            	t_3 = t_1 / sqrt(((t_2 ^ 2.0) + (t_1 ^ 2.0)));
            	tmp = 0.0;
            	if (t_3 <= 0.7215)
            		tmp = (sin(th) / abs(t_2)) * abs(ky);
            	elseif (t_3 <= 2.0)
            		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) - ((1.0 - 1.0) * 0.5)))) * sin(th);
            	else
            		tmp = sin(th) * (abs(ky) / abs(kx));
            	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[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 / N[Sqrt[N[(N[Power[t$95$2, 2], $MachinePrecision] + N[Power[t$95$1, 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 3249347131147813/4503599627370496], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] - N[(N[(1 - 1), $MachinePrecision] * 1/2), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]]]]
            
            \begin{array}{l}
            t_1 := \sin \left(\left|ky\right|\right)\\
            t_2 := \sin \left(\left|kx\right|\right)\\
            t_3 := \frac{t\_1}{\sqrt{{t\_2}^{2} + {t\_1}^{2}}}\\
            \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
            \mathbf{if}\;t\_3 \leq \frac{3249347131147813}{4503599627370496}:\\
            \;\;\;\;\frac{\sin th}{\left|t\_2\right|} \cdot \left|ky\right|\\
            
            \mathbf{elif}\;t\_3 \leq 2:\\
            \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| - \left(1 - 1\right) \cdot \frac{1}{2}}} \cdot \sin th\\
            
            \mathbf{else}:\\
            \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\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.72150000000000003

              1. Initial program 94.3%

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
                5. pow-negN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                6. lower-unsound-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                7. lower-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                8. pow-flipN/A

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
                12. lower-/.f6435.0%

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
                16. rem-sqrt-squareN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
                17. lower-fabs.f6437.2%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
                4. remove-double-divN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
                5. lift-*.f64N/A

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

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

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

                  \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
                9. lower-/.f6439.0%

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

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

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

              1. Initial program 94.3%

                \[\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.f6446.5%

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

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

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

                \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]
              7. Step-by-step derivation
                1. Applied rewrites13.8%

                  \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot ky - \left(\color{blue}{1} - 1\right) \cdot \frac{1}{2}}} \cdot \sin th \]

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

                1. Initial program 94.3%

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

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

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                  6. lower-sin.f6435.1%

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                  3. lower-sin.f6415.6%

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

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

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

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

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

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

                    \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
                  6. lower-/.f6416.6%

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

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

              Alternative 16: 39.0% accurate, 2.9× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
                5. pow-negN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                6. lower-unsound-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                7. lower-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                8. pow-flipN/A

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
                12. lower-/.f6435.0%

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
                16. rem-sqrt-squareN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
                17. lower-fabs.f6437.2%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
                4. remove-double-divN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
                5. lift-*.f64N/A

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

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

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

                  \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
                9. lower-/.f6439.0%

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

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

              Alternative 17: 39.0% accurate, 2.9× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
                5. pow-negN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                6. lower-unsound-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                7. lower-pow.f32N/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                8. pow-flipN/A

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
                12. lower-/.f6435.0%

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
                16. rem-sqrt-squareN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
                17. lower-fabs.f6437.2%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\color{blue}{\left|\sin kx\right|}}}} \]
                4. remove-double-divN/A

                  \[\leadsto \frac{ky \cdot \sin th}{\left|\sin kx\right|} \]
                5. lift-*.f64N/A

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

                  \[\leadsto \frac{\sin th \cdot ky}{\left|\color{blue}{\sin kx}\right|} \]
                7. associate-/l*N/A

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

                  \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]
                9. lower-/.f6439.0%

                  \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{\left|\sin kx\right|}} \]
              8. Applied rewrites39.0%

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

              Alternative 18: 26.5% accurate, 1.9× speedup?

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

                1. Initial program 94.3%

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

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

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                  6. lower-sin.f6435.1%

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                  3. lower-sin.f6415.6%

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

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

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

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

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

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

                    \[\leadsto \frac{\sin th}{kx} \cdot ky \]
                  6. lower-/.f6416.6%

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

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

                if 2.0000000000000002e-31 < (pow.f64 (sin.f64 kx) #s(literal 2 binary64))

                1. Initial program 94.3%

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

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

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                  6. lower-sin.f6435.1%

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

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

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)}} \]
                  5. pow-negN/A

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{{\left({\sin kx}^{2}\right)}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                  6. lower-unsound-pow.f32N/A

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                  7. lower-pow.f32N/A

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{{\left({\sin kx}^{2}\right)}^{\color{blue}{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}}}} \]
                  8. pow-flipN/A

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\color{blue}{\frac{1}{\sqrt{{\sin kx}^{2}}}}}} \]
                  12. lower-/.f6435.0%

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

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

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

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\sqrt{\sin kx \cdot \sin kx}}}} \]
                  16. rem-sqrt-squareN/A

                    \[\leadsto \frac{ky \cdot \sin th}{\frac{1}{\frac{1}{\left|\sin kx\right|}}} \]
                  17. lower-fabs.f6437.2%

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

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

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

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

                    \[\leadsto \frac{ky \cdot th}{\left|\sin kx\right|} \]
                  3. lower-fabs.f64N/A

                    \[\leadsto \frac{ky \cdot th}{\left|\sin kx\right|} \]
                  4. lower-sin.f6419.2%

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

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

              Alternative 19: 21.5% accurate, 5.3× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                3. lower-sin.f6415.6%

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

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

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

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

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

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

                  \[\leadsto \frac{\sin th}{kx} \cdot ky \]
                6. lower-/.f6416.6%

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

                \[\leadsto \frac{\sin th}{kx} \cdot ky \]
              10. Add Preprocessing

              Alternative 20: 21.5% accurate, 5.3× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                3. lower-sin.f6415.6%

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

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

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

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

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

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

                  \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
                6. lower-/.f6416.6%

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

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

              Alternative 21: 15.2% accurate, 33.3× speedup?

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

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

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

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
                6. lower-sin.f6435.1%

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

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

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

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

                  \[\leadsto \frac{ky \cdot \sin th}{kx} \]
                3. lower-sin.f6415.6%

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

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

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

                  \[\leadsto \frac{ky \cdot th}{kx} \]
                2. lower-*.f6412.4%

                  \[\leadsto \frac{ky \cdot th}{kx} \]
              10. Applied rewrites12.4%

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

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

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

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

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

                  \[\leadsto th \cdot \frac{ky}{kx} \]
                6. lower-/.f6413.4%

                  \[\leadsto th \cdot \frac{ky}{kx} \]
              12. Applied rewrites13.4%

                \[\leadsto th \cdot \frac{ky}{kx} \]
              13. Add Preprocessing

              Reproduce

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