Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 8.4s
Alternatives: 24
Speedup: 1.2×

Specification

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

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

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

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 24 alternatives:

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

Initial Program: 93.7% accurate, 1.0× speedup?

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

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

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

Alternative 1: 99.7% accurate, 1.2× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 85.8% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_6 \leq -0.3:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_6 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_5}} \cdot \sin th\\

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

\mathbf{elif}\;t\_6 \leq 1:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_4}} \cdot \sin th\\

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


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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{th}^{2}}\right)\right) \]
      4. lower-pow.f6450.8%

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right)}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6451.3%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right), \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6454.8%

        \[\leadsto \frac{ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{\color{blue}{2}}\right), \sin kx\right)} \cdot \sin th \]
    9. Applied rewrites54.8%

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

Alternative 3: 85.8% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;t\_3\\


\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.99980000000000002 or 0.99903774085637154 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
      12. lower-hypot.f6499.5%

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

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

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

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

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

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(kx \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{kx}^{2}}\right), \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
      4. lower-pow.f6457.8%

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(kx \cdot \left(1 + -0.16666666666666666 \cdot {kx}^{\color{blue}{2}}\right), \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
    6. Applied rewrites57.8%

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \left(th \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{th}^{2}}\right)\right)\right) \]
      4. lower-pow.f6450.7%

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \left(th \cdot \left(1 + -0.16666666666666666 \cdot {th}^{\color{blue}{2}}\right)\right)\right) \]
    6. Applied rewrites50.7%

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

Alternative 4: 85.8% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;t\_3\\


\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.99980000000000002 or 0.99903774085637154 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{1}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + \sin ky \cdot \sin ky}} \cdot \sin ky\right) \cdot \sin th \]
      12. lower-hypot.f6499.5%

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

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

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

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

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

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(kx \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{kx}^{2}}\right), \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
      4. lower-pow.f6457.8%

        \[\leadsto \left(\frac{1}{\mathsf{hypot}\left(kx \cdot \left(1 + -0.16666666666666666 \cdot {kx}^{\color{blue}{2}}\right), \sin ky\right)} \cdot \sin ky\right) \cdot \sin th \]
    6. Applied rewrites57.8%

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{th}^{2}}\right)\right) \]
      4. lower-pow.f6450.8%

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

Alternative 5: 85.8% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_5 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_4}} \cdot \sin th\\

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_5 \leq 1:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_3}} \cdot \sin th\\

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


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

    1. Initial program 93.7%

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

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{th}^{2}}\right)\right) \]
      4. lower-pow.f6450.8%

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right)}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6451.3%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right), \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6454.8%

        \[\leadsto \frac{ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{\color{blue}{2}}\right), \sin kx\right)} \cdot \sin th \]
    9. Applied rewrites54.8%

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

Alternative 6: 85.7% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_5 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_4}} \cdot \sin th\\

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_6\\

\mathbf{elif}\;t\_5 \leq 1:\\
\;\;\;\;\frac{t\_2}{\sqrt{t\_3}} \cdot \sin th\\

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


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

    1. Initial program 93.7%

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

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right)}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6451.3%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right), \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6454.8%

        \[\leadsto \frac{ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{\color{blue}{2}}\right), \sin kx\right)} \cdot \sin th \]
    9. Applied rewrites54.8%

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

Alternative 7: 85.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 kx}^{2}\\ t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\ t_6 := \frac{th \cdot t\_1}{\mathsf{hypot}\left(\sin kx, t\_1\right)}\\ t_7 := \left|ky\right| \cdot \left(1 + -0.16666666666666666 \cdot {\left(\left|ky\right|\right)}^{2}\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_5 \leq -0.9948:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_5 \leq -0.3:\\ \;\;\;\;t\_6\\ \mathbf{elif}\;t\_5 \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_4}} \cdot \sin th\\ \mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\ \;\;\;\;t\_6\\ \mathbf{elif}\;t\_5 \leq 1:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\frac{t\_7}{\mathsf{hypot}\left(t\_7, \sin kx\right)} \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.0))
       (t_3 (* (/ t_1 (sqrt t_2)) (sin th)))
       (t_4 (pow (sin kx) 2.0))
       (t_5 (/ t_1 (sqrt (+ t_4 t_2))))
       (t_6 (/ (* th t_1) (hypot (sin kx) t_1)))
       (t_7
        (*
         (fabs ky)
         (+ 1.0 (* -0.16666666666666666 (pow (fabs ky) 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_5 -0.9948)
     t_3
     (if (<= t_5 -0.3)
       t_6
       (if (<= t_5 5e-15)
         (* (/ t_1 (sqrt t_4)) (sin th))
         (if (<= t_5 0.9990377408563715)
           t_6
           (if (<= t_5 1.0)
             t_3
             (* (/ t_7 (hypot t_7 (sin kx))) (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 = (t_1 / sqrt(t_2)) * sin(th);
	double t_4 = pow(sin(kx), 2.0);
	double t_5 = t_1 / sqrt((t_4 + t_2));
	double t_6 = (th * t_1) / hypot(sin(kx), t_1);
	double t_7 = fabs(ky) * (1.0 + (-0.16666666666666666 * pow(fabs(ky), 2.0)));
	double tmp;
	if (t_5 <= -0.9948) {
		tmp = t_3;
	} else if (t_5 <= -0.3) {
		tmp = t_6;
	} else if (t_5 <= 5e-15) {
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	} else if (t_5 <= 0.9990377408563715) {
		tmp = t_6;
	} else if (t_5 <= 1.0) {
		tmp = t_3;
	} else {
		tmp = (t_7 / hypot(t_7, sin(kx))) * sin(th);
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(Math.abs(ky));
	double 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(kx), 2.0);
	double t_5 = t_1 / Math.sqrt((t_4 + t_2));
	double t_6 = (th * t_1) / Math.hypot(Math.sin(kx), t_1);
	double t_7 = Math.abs(ky) * (1.0 + (-0.16666666666666666 * Math.pow(Math.abs(ky), 2.0)));
	double tmp;
	if (t_5 <= -0.9948) {
		tmp = t_3;
	} else if (t_5 <= -0.3) {
		tmp = t_6;
	} else if (t_5 <= 5e-15) {
		tmp = (t_1 / Math.sqrt(t_4)) * Math.sin(th);
	} else if (t_5 <= 0.9990377408563715) {
		tmp = t_6;
	} else if (t_5 <= 1.0) {
		tmp = t_3;
	} else {
		tmp = (t_7 / Math.hypot(t_7, Math.sin(kx))) * Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	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(kx), 2.0)
	t_5 = t_1 / math.sqrt((t_4 + t_2))
	t_6 = (th * t_1) / math.hypot(math.sin(kx), t_1)
	t_7 = math.fabs(ky) * (1.0 + (-0.16666666666666666 * math.pow(math.fabs(ky), 2.0)))
	tmp = 0
	if t_5 <= -0.9948:
		tmp = t_3
	elif t_5 <= -0.3:
		tmp = t_6
	elif t_5 <= 5e-15:
		tmp = (t_1 / math.sqrt(t_4)) * math.sin(th)
	elif t_5 <= 0.9990377408563715:
		tmp = t_6
	elif t_5 <= 1.0:
		tmp = t_3
	else:
		tmp = (t_7 / math.hypot(t_7, math.sin(kx))) * 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 = Float64(Float64(t_1 / sqrt(t_2)) * sin(th))
	t_4 = sin(kx) ^ 2.0
	t_5 = Float64(t_1 / sqrt(Float64(t_4 + t_2)))
	t_6 = Float64(Float64(th * t_1) / hypot(sin(kx), t_1))
	t_7 = Float64(abs(ky) * Float64(1.0 + Float64(-0.16666666666666666 * (abs(ky) ^ 2.0))))
	tmp = 0.0
	if (t_5 <= -0.9948)
		tmp = t_3;
	elseif (t_5 <= -0.3)
		tmp = t_6;
	elseif (t_5 <= 5e-15)
		tmp = Float64(Float64(t_1 / sqrt(t_4)) * sin(th));
	elseif (t_5 <= 0.9990377408563715)
		tmp = t_6;
	elseif (t_5 <= 1.0)
		tmp = t_3;
	else
		tmp = Float64(Float64(t_7 / hypot(t_7, sin(kx))) * sin(th));
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	t_2 = t_1 ^ 2.0;
	t_3 = (t_1 / sqrt(t_2)) * sin(th);
	t_4 = sin(kx) ^ 2.0;
	t_5 = t_1 / sqrt((t_4 + t_2));
	t_6 = (th * t_1) / hypot(sin(kx), t_1);
	t_7 = abs(ky) * (1.0 + (-0.16666666666666666 * (abs(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_5 <= -0.9948)
		tmp = t_3;
	elseif (t_5 <= -0.3)
		tmp = t_6;
	elseif (t_5 <= 5e-15)
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	elseif (t_5 <= 0.9990377408563715)
		tmp = t_6;
	elseif (t_5 <= 1.0)
		tmp = t_3;
	else
		tmp = (t_7 / hypot(t_7, sin(kx))) * sin(th);
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, 2.0], $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[kx], $MachinePrecision], 2.0], $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[(N[(th * t$95$1), $MachinePrecision] / N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$7 = N[(N[Abs[ky], $MachinePrecision] * N[(1.0 + N[(-0.16666666666666666 * N[Power[N[Abs[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$5, -0.9948], t$95$3, If[LessEqual[t$95$5, -0.3], t$95$6, If[LessEqual[t$95$5, 5e-15], N[(N[(t$95$1 / N[Sqrt[t$95$4], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$5, 0.9990377408563715], t$95$6, If[LessEqual[t$95$5, 1.0], t$95$3, N[(N[(t$95$7 / N[Sqrt[t$95$7 ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]]]]]), $MachinePrecision]]]]]]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := {t\_1}^{2}\\
t_3 := \frac{t\_1}{\sqrt{t\_2}} \cdot \sin th\\
t_4 := {\sin kx}^{2}\\
t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\
t_6 := \frac{th \cdot t\_1}{\mathsf{hypot}\left(\sin kx, t\_1\right)}\\
t_7 := \left|ky\right| \cdot \left(1 + -0.16666666666666666 \cdot {\left(\left|ky\right|\right)}^{2}\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_5 \leq -0.9948:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_6\\

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

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_6\\

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

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


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

    1. Initial program 93.7%

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

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

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

    if -0.99480000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right)}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6451.3%

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right), \sin kx\right)} \cdot \sin th \]
      4. lower-pow.f6454.8%

        \[\leadsto \frac{ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{2}\right)}{\mathsf{hypot}\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{\color{blue}{2}}\right), \sin kx\right)} \cdot \sin th \]
    9. Applied rewrites54.8%

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

Alternative 8: 85.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 kx}^{2}\\ t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\ t_6 := \mathsf{hypot}\left(\sin kx, t\_1\right)\\ t_7 := \frac{th \cdot t\_1}{t\_6}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_5 \leq -0.9948:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_5 \leq -0.3:\\ \;\;\;\;t\_7\\ \mathbf{elif}\;t\_5 \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_4}} \cdot \sin th\\ \mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\ \;\;\;\;t\_7\\ \mathbf{elif}\;t\_5 \leq 1:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\left(-1 \cdot \left|ky\right|\right) \cdot \left(\frac{-1}{t\_6} \cdot \sin th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (pow t_1 2.0))
       (t_3 (* (/ t_1 (sqrt t_2)) (sin th)))
       (t_4 (pow (sin kx) 2.0))
       (t_5 (/ t_1 (sqrt (+ t_4 t_2))))
       (t_6 (hypot (sin kx) t_1))
       (t_7 (/ (* th t_1) t_6)))
  (*
   (copysign 1.0 ky)
   (if (<= t_5 -0.9948)
     t_3
     (if (<= t_5 -0.3)
       t_7
       (if (<= t_5 5e-15)
         (* (/ t_1 (sqrt t_4)) (sin th))
         (if (<= t_5 0.9990377408563715)
           t_7
           (if (<= t_5 1.0)
             t_3
             (* (* -1.0 (fabs ky)) (* (/ -1.0 t_6) (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 = (t_1 / sqrt(t_2)) * sin(th);
	double t_4 = pow(sin(kx), 2.0);
	double t_5 = t_1 / sqrt((t_4 + t_2));
	double t_6 = hypot(sin(kx), t_1);
	double t_7 = (th * t_1) / t_6;
	double tmp;
	if (t_5 <= -0.9948) {
		tmp = t_3;
	} else if (t_5 <= -0.3) {
		tmp = t_7;
	} else if (t_5 <= 5e-15) {
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	} else if (t_5 <= 0.9990377408563715) {
		tmp = t_7;
	} else if (t_5 <= 1.0) {
		tmp = t_3;
	} else {
		tmp = (-1.0 * fabs(ky)) * ((-1.0 / t_6) * 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 = (t_1 / Math.sqrt(t_2)) * Math.sin(th);
	double t_4 = Math.pow(Math.sin(kx), 2.0);
	double t_5 = t_1 / Math.sqrt((t_4 + t_2));
	double t_6 = Math.hypot(Math.sin(kx), t_1);
	double t_7 = (th * t_1) / t_6;
	double tmp;
	if (t_5 <= -0.9948) {
		tmp = t_3;
	} else if (t_5 <= -0.3) {
		tmp = t_7;
	} else if (t_5 <= 5e-15) {
		tmp = (t_1 / Math.sqrt(t_4)) * Math.sin(th);
	} else if (t_5 <= 0.9990377408563715) {
		tmp = t_7;
	} else if (t_5 <= 1.0) {
		tmp = t_3;
	} else {
		tmp = (-1.0 * Math.abs(ky)) * ((-1.0 / t_6) * 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 = (t_1 / math.sqrt(t_2)) * math.sin(th)
	t_4 = math.pow(math.sin(kx), 2.0)
	t_5 = t_1 / math.sqrt((t_4 + t_2))
	t_6 = math.hypot(math.sin(kx), t_1)
	t_7 = (th * t_1) / t_6
	tmp = 0
	if t_5 <= -0.9948:
		tmp = t_3
	elif t_5 <= -0.3:
		tmp = t_7
	elif t_5 <= 5e-15:
		tmp = (t_1 / math.sqrt(t_4)) * math.sin(th)
	elif t_5 <= 0.9990377408563715:
		tmp = t_7
	elif t_5 <= 1.0:
		tmp = t_3
	else:
		tmp = (-1.0 * math.fabs(ky)) * ((-1.0 / t_6) * 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 = Float64(Float64(t_1 / sqrt(t_2)) * sin(th))
	t_4 = sin(kx) ^ 2.0
	t_5 = Float64(t_1 / sqrt(Float64(t_4 + t_2)))
	t_6 = hypot(sin(kx), t_1)
	t_7 = Float64(Float64(th * t_1) / t_6)
	tmp = 0.0
	if (t_5 <= -0.9948)
		tmp = t_3;
	elseif (t_5 <= -0.3)
		tmp = t_7;
	elseif (t_5 <= 5e-15)
		tmp = Float64(Float64(t_1 / sqrt(t_4)) * sin(th));
	elseif (t_5 <= 0.9990377408563715)
		tmp = t_7;
	elseif (t_5 <= 1.0)
		tmp = t_3;
	else
		tmp = Float64(Float64(-1.0 * abs(ky)) * Float64(Float64(-1.0 / t_6) * 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 = (t_1 / sqrt(t_2)) * sin(th);
	t_4 = sin(kx) ^ 2.0;
	t_5 = t_1 / sqrt((t_4 + t_2));
	t_6 = hypot(sin(kx), t_1);
	t_7 = (th * t_1) / t_6;
	tmp = 0.0;
	if (t_5 <= -0.9948)
		tmp = t_3;
	elseif (t_5 <= -0.3)
		tmp = t_7;
	elseif (t_5 <= 5e-15)
		tmp = (t_1 / sqrt(t_4)) * sin(th);
	elseif (t_5 <= 0.9990377408563715)
		tmp = t_7;
	elseif (t_5 <= 1.0)
		tmp = t_3;
	else
		tmp = (-1.0 * abs(ky)) * ((-1.0 / t_6) * 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.0], $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[kx], $MachinePrecision], 2.0], $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[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + t$95$1 ^ 2], $MachinePrecision]}, Block[{t$95$7 = N[(N[(th * t$95$1), $MachinePrecision] / t$95$6), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$5, -0.9948], t$95$3, If[LessEqual[t$95$5, -0.3], t$95$7, If[LessEqual[t$95$5, 5e-15], N[(N[(t$95$1 / N[Sqrt[t$95$4], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$5, 0.9990377408563715], t$95$7, If[LessEqual[t$95$5, 1.0], t$95$3, N[(N[(-1.0 * N[Abs[ky], $MachinePrecision]), $MachinePrecision] * N[(N[(-1.0 / t$95$6), $MachinePrecision] * N[Sin[th], $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 kx}^{2}\\
t_5 := \frac{t\_1}{\sqrt{t\_4 + t\_2}}\\
t_6 := \mathsf{hypot}\left(\sin kx, t\_1\right)\\
t_7 := \frac{th \cdot t\_1}{t\_6}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_5 \leq -0.9948:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_7\\

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

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

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

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

    1. Initial program 93.7%

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

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

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

    if -0.99480000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 82.8% 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)\\ t_5 := \frac{th \cdot t\_1}{\mathsf{hypot}\left(t\_4, t\_1\right)}\\ t_6 := {t\_4}^{2}\\ t_7 := \frac{t\_1}{\sqrt{t\_6 + t\_2}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_7 \leq -0.9948:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_7 \leq -0.3:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_7 \leq 5 \cdot 10^{-15}:\\ \;\;\;\;\frac{t\_1}{\sqrt{t\_6}} \cdot \sin th\\ \mathbf{elif}\;t\_7 \leq 0.9990377408563715:\\ \;\;\;\;t\_5\\ \mathbf{elif}\;t\_7 \leq 2:\\ \;\;\;\;t\_3\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (pow t_1 2.0))
       (t_3 (* (/ t_1 (sqrt t_2)) (sin th)))
       (t_4 (sin (fabs kx)))
       (t_5 (/ (* th t_1) (hypot t_4 t_1)))
       (t_6 (pow t_4 2.0))
       (t_7 (/ t_1 (sqrt (+ t_6 t_2)))))
  (*
   (copysign 1.0 ky)
   (if (<= t_7 -0.9948)
     t_3
     (if (<= t_7 -0.3)
       t_5
       (if (<= t_7 5e-15)
         (* (/ t_1 (sqrt t_6)) (sin th))
         (if (<= t_7 0.9990377408563715)
           t_5
           (if (<= t_7 2.0)
             t_3
             (* (sin th) (* (fabs ky) (/ 1.0 (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 = sin(fabs(kx));
	double t_5 = (th * t_1) / hypot(t_4, t_1);
	double t_6 = pow(t_4, 2.0);
	double t_7 = t_1 / sqrt((t_6 + t_2));
	double tmp;
	if (t_7 <= -0.9948) {
		tmp = t_3;
	} else if (t_7 <= -0.3) {
		tmp = t_5;
	} else if (t_7 <= 5e-15) {
		tmp = (t_1 / sqrt(t_6)) * sin(th);
	} else if (t_7 <= 0.9990377408563715) {
		tmp = t_5;
	} else if (t_7 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.sin(Math.abs(kx));
	double t_5 = (th * t_1) / Math.hypot(t_4, t_1);
	double t_6 = Math.pow(t_4, 2.0);
	double t_7 = t_1 / Math.sqrt((t_6 + t_2));
	double tmp;
	if (t_7 <= -0.9948) {
		tmp = t_3;
	} else if (t_7 <= -0.3) {
		tmp = t_5;
	} else if (t_7 <= 5e-15) {
		tmp = (t_1 / Math.sqrt(t_6)) * Math.sin(th);
	} else if (t_7 <= 0.9990377408563715) {
		tmp = t_5;
	} else if (t_7 <= 2.0) {
		tmp = t_3;
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.sin(math.fabs(kx))
	t_5 = (th * t_1) / math.hypot(t_4, t_1)
	t_6 = math.pow(t_4, 2.0)
	t_7 = t_1 / math.sqrt((t_6 + t_2))
	tmp = 0
	if t_7 <= -0.9948:
		tmp = t_3
	elif t_7 <= -0.3:
		tmp = t_5
	elif t_7 <= 5e-15:
		tmp = (t_1 / math.sqrt(t_6)) * math.sin(th)
	elif t_7 <= 0.9990377408563715:
		tmp = t_5
	elif t_7 <= 2.0:
		tmp = t_3
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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))
	t_5 = Float64(Float64(th * t_1) / hypot(t_4, t_1))
	t_6 = t_4 ^ 2.0
	t_7 = Float64(t_1 / sqrt(Float64(t_6 + t_2)))
	tmp = 0.0
	if (t_7 <= -0.9948)
		tmp = t_3;
	elseif (t_7 <= -0.3)
		tmp = t_5;
	elseif (t_7 <= 5e-15)
		tmp = Float64(Float64(t_1 / sqrt(t_6)) * sin(th));
	elseif (t_7 <= 0.9990377408563715)
		tmp = t_5;
	elseif (t_7 <= 2.0)
		tmp = t_3;
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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));
	t_5 = (th * t_1) / hypot(t_4, t_1);
	t_6 = t_4 ^ 2.0;
	t_7 = t_1 / sqrt((t_6 + t_2));
	tmp = 0.0;
	if (t_7 <= -0.9948)
		tmp = t_3;
	elseif (t_7 <= -0.3)
		tmp = t_5;
	elseif (t_7 <= 5e-15)
		tmp = (t_1 / sqrt(t_6)) * sin(th);
	elseif (t_7 <= 0.9990377408563715)
		tmp = t_5;
	elseif (t_7 <= 2.0)
		tmp = t_3;
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $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[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$5 = N[(N[(th * t$95$1), $MachinePrecision] / N[Sqrt[t$95$4 ^ 2 + t$95$1 ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$6 = N[Power[t$95$4, 2.0], $MachinePrecision]}, Block[{t$95$7 = N[(t$95$1 / N[Sqrt[N[(t$95$6 + t$95$2), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$7, -0.9948], t$95$3, If[LessEqual[t$95$7, -0.3], t$95$5, If[LessEqual[t$95$7, 5e-15], N[(N[(t$95$1 / N[Sqrt[t$95$6], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$7, 0.9990377408563715], t$95$5, If[LessEqual[t$95$7, 2.0], t$95$3, N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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)\\
t_5 := \frac{th \cdot t\_1}{\mathsf{hypot}\left(t\_4, t\_1\right)}\\
t_6 := {t\_4}^{2}\\
t_7 := \frac{t\_1}{\sqrt{t\_6 + t\_2}}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_7 \leq -0.9948:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_7 \leq -0.3:\\
\;\;\;\;t\_5\\

\mathbf{elif}\;t\_7 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\frac{t\_1}{\sqrt{t\_6}} \cdot \sin th\\

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.99480000000000002 or 0.99903774085637154 < (/.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 93.7%

      \[\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.f6440.6%

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

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

    if -0.99480000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

      \[\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 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

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

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

Alternative 10: 74.4% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_5 \leq -0.3:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;t\_5 \leq 0.9990377408563715:\\
\;\;\;\;t\_2\\

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\mathsf{neg}\left(-1\right)}{\color{blue}{\sqrt{{\sin kx}^{2}}}}\right) \]
      10. metadata-eval36.7%

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

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

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

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

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

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

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

Alternative 11: 74.4% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_4 \leq -0.3:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\left(\frac{-1}{t\_5} \cdot \left(-t\_1\right)\right) \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq 0.9990377408563715:\\
\;\;\;\;t\_2\\

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\sqrt{{\sin kx}^{2}}} \cdot \sin th\right) \]
      4. lower-sin.f6441.7%

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

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\mathsf{neg}\left(-1\right)}{\color{blue}{\sqrt{{\sin kx}^{2}}}}\right) \]
      10. metadata-eval36.7%

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

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

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

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

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

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

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

Alternative 12: 74.4% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_4 \leq -0.3:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-15}:\\
\;\;\;\;\left(\frac{-1}{t\_5} \cdot \left(-t\_1\right)\right) \cdot \sin th\\

\mathbf{elif}\;t\_4 \leq 0.9990377408563715:\\
\;\;\;\;t\_2\\

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

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

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2}} + {kx}^{2}}} \]
      14. mult-flipN/A

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

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

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

    if -0.99980000000000002 < (/.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.29999999999999999 or 5e-15 < (/.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.99903774085637154

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.29999999999999999 < (/.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))))) < 5e-15

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\sqrt{{\sin kx}^{2}}} \cdot \sin th\right) \]
      4. lower-sin.f6441.7%

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

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

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

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

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

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

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

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

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\mathsf{neg}\left(-1\right)}{\color{blue}{\sqrt{{\sin kx}^{2}}}}\right) \]
      10. metadata-eval36.7%

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

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

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

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

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

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

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

Alternative 13: 68.3% accurate, 1.3× speedup?

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

\mathbf{else}:\\
\;\;\;\;\left(\frac{-1}{\left|\sin kx\right|} \cdot \left(-\sin ky\right)\right) \cdot \sin \left(\left|th\right|\right)\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 31

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 31 < th

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\sqrt{{\sin kx}^{2}}} \cdot \sin th\right) \]
      4. lower-sin.f6441.7%

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

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

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

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

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

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

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

Alternative 14: 53.3% accurate, 0.5× 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 0.99:\\ \;\;\;\;\left(\frac{-1}{\left|t\_2\right|} \cdot \left(-t\_1\right)\right) \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_3 0.99)
     (* (* (/ -1.0 (fabs t_2)) (- t_1)) (sin th))
     (if (<= t_3 2.0)
       (*
        (/
         t_1
         (sqrt (+ (* (fabs ky) (fabs ky)) (* (fabs kx) (fabs kx)))))
        (sin th))
       (* (sin th) (* (fabs ky) (/ 1.0 (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.99) {
		tmp = ((-1.0 / fabs(t_2)) * -t_1) * sin(th);
	} else if (t_3 <= 2.0) {
		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) + (fabs(kx) * fabs(kx))))) * sin(th);
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.99) {
		tmp = ((-1.0 / Math.abs(t_2)) * -t_1) * Math.sin(th);
	} else if (t_3 <= 2.0) {
		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) + (Math.abs(kx) * Math.abs(kx))))) * Math.sin(th);
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.99:
		tmp = ((-1.0 / math.fabs(t_2)) * -t_1) * math.sin(th)
	elif t_3 <= 2.0:
		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) + (math.fabs(kx) * math.fabs(kx))))) * math.sin(th)
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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.99)
		tmp = Float64(Float64(Float64(-1.0 / abs(t_2)) * Float64(-t_1)) * sin(th));
	elseif (t_3 <= 2.0)
		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) + Float64(abs(kx) * abs(kx))))) * sin(th));
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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.99)
		tmp = ((-1.0 / abs(t_2)) * -t_1) * sin(th);
	elseif (t_3 <= 2.0)
		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) + (abs(kx) * abs(kx))))) * sin(th);
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 0.99], N[(N[(N[(-1.0 / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision] * (-t$95$1)), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[kx], $MachinePrecision] * N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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 0.99:\\
\;\;\;\;\left(\frac{-1}{\left|t\_2\right|} \cdot \left(-t\_1\right)\right) \cdot \sin th\\

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.98999999999999999

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \left(\frac{-1}{\sqrt{{\sin kx}^{2}}} \cdot \sin th\right) \]
      4. lower-sin.f6441.7%

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

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

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

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

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

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

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

    if 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 93.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + {kx}^{2}}} \cdot \sin th \]
      6. lower-*.f6428.4%

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

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(lift-pow.f64, \left({kx}^{2}\right)\right)}} \cdot \sin th \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(unpow2, \left(kx \cdot kx\right)\right)}} \cdot \sin th \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(lower-*.f64, \left(kx \cdot kx\right)\right)}} \cdot \sin th \]
    9. Applied rewrites28.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{ky \cdot ky + kx \cdot kx}}} \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 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

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

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

Alternative 15: 48.6% accurate, 0.5× 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 0.965:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}} \cdot \sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_3 0.965)
     (* (sin th) (/ (fabs ky) (fabs t_2)))
     (if (<= t_3 2.0)
       (*
        (/
         t_1
         (sqrt (+ (* (fabs ky) (fabs ky)) (* (fabs kx) (fabs kx)))))
        (sin th))
       (* (sin th) (* (fabs ky) (/ 1.0 (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.965) {
		tmp = sin(th) * (fabs(ky) / fabs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = (t_1 / sqrt(((fabs(ky) * fabs(ky)) + (fabs(kx) * fabs(kx))))) * sin(th);
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.965) {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = (t_1 / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) + (Math.abs(kx) * Math.abs(kx))))) * Math.sin(th);
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.965:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(t_2))
	elif t_3 <= 2.0:
		tmp = (t_1 / math.sqrt(((math.fabs(ky) * math.fabs(ky)) + (math.fabs(kx) * math.fabs(kx))))) * math.sin(th)
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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.965)
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(t_2)));
	elseif (t_3 <= 2.0)
		tmp = Float64(Float64(t_1 / sqrt(Float64(Float64(abs(ky) * abs(ky)) + Float64(abs(kx) * abs(kx))))) * sin(th));
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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.965)
		tmp = sin(th) * (abs(ky) / abs(t_2));
	elseif (t_3 <= 2.0)
		tmp = (t_1 / sqrt(((abs(ky) * abs(ky)) + (abs(kx) * abs(kx))))) * sin(th);
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 0.965], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(N[(t$95$1 / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[kx], $MachinePrecision] * N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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 0.965:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;\frac{t\_1}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.96499999999999997

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.96499999999999997 < (/.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 93.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + {kx}^{2}}} \cdot \sin th \]
      6. lower-*.f6428.4%

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

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(lift-pow.f64, \left({kx}^{2}\right)\right)}} \cdot \sin th \]
      8. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(unpow2, \left(kx \cdot kx\right)\right)}} \cdot \sin th \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{ky \cdot \color{blue}{ky} + \mathsf{Rewrite=>}\left(lower-*.f64, \left(kx \cdot kx\right)\right)}} \cdot \sin th \]
    9. Applied rewrites28.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{ky \cdot ky + kx \cdot kx}}} \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 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

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

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

Alternative 16: 48.5% accurate, 0.5× 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 0.965:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;t\_1 \cdot \frac{\sin th}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_3 0.965)
     (* (sin th) (/ (fabs ky) (fabs t_2)))
     (if (<= t_3 2.0)
       (*
        t_1
        (/
         (sin th)
         (sqrt (+ (* (fabs ky) (fabs ky)) (* (fabs kx) (fabs kx))))))
       (* (sin th) (* (fabs ky) (/ 1.0 (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.965) {
		tmp = sin(th) * (fabs(ky) / fabs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = t_1 * (sin(th) / sqrt(((fabs(ky) * fabs(ky)) + (fabs(kx) * fabs(kx)))));
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.965) {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = t_1 * (Math.sin(th) / Math.sqrt(((Math.abs(ky) * Math.abs(ky)) + (Math.abs(kx) * Math.abs(kx)))));
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.965:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(t_2))
	elif t_3 <= 2.0:
		tmp = t_1 * (math.sin(th) / math.sqrt(((math.fabs(ky) * math.fabs(ky)) + (math.fabs(kx) * math.fabs(kx)))))
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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.965)
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(t_2)));
	elseif (t_3 <= 2.0)
		tmp = Float64(t_1 * Float64(sin(th) / sqrt(Float64(Float64(abs(ky) * abs(ky)) + Float64(abs(kx) * abs(kx))))));
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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.965)
		tmp = sin(th) * (abs(ky) / abs(t_2));
	elseif (t_3 <= 2.0)
		tmp = t_1 * (sin(th) / sqrt(((abs(ky) * abs(ky)) + (abs(kx) * abs(kx)))));
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 0.965], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(t$95$1 * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[kx], $MachinePrecision] * N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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 0.965:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;t\_1 \cdot \frac{\sin th}{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.96499999999999997

    1. Initial program 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.96499999999999997 < (/.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 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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 93.7%

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

      \[\leadsto \color{blue}{\frac{ky \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.9%

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

      \[\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.9%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.9%

      \[\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. mult-flipN/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{\color{blue}{kx}} \]
      3. lift-*.f64N/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{kx} \]
      4. *-commutativeN/A

        \[\leadsto \left(\sin th \cdot ky\right) \cdot \frac{1}{kx} \]
      5. associate-*l*N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      6. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      7. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{kx}\right) \]
    9. Applied rewrites16.8%

      \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 17: 47.1% accurate, 0.5× 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 0.99:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}{\left(\left|ky\right| \cdot \left(1 + -0.16666666666666666 \cdot {\left(\left|ky\right|\right)}^{2}\right)\right) \cdot \sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_3 0.99)
     (* (sin th) (/ (fabs ky) (fabs t_2)))
     (if (<= t_3 2.0)
       (/
        1.0
        (/
         (sqrt (+ (* (fabs ky) (fabs ky)) (* (fabs kx) (fabs kx))))
         (*
          (*
           (fabs ky)
           (+ 1.0 (* -0.16666666666666666 (pow (fabs ky) 2.0))))
          (sin th))))
       (* (sin th) (* (fabs ky) (/ 1.0 (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.99) {
		tmp = sin(th) * (fabs(ky) / fabs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = 1.0 / (sqrt(((fabs(ky) * fabs(ky)) + (fabs(kx) * fabs(kx)))) / ((fabs(ky) * (1.0 + (-0.16666666666666666 * pow(fabs(ky), 2.0)))) * sin(th)));
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.99) {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = 1.0 / (Math.sqrt(((Math.abs(ky) * Math.abs(ky)) + (Math.abs(kx) * Math.abs(kx)))) / ((Math.abs(ky) * (1.0 + (-0.16666666666666666 * Math.pow(Math.abs(ky), 2.0)))) * Math.sin(th)));
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.99:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(t_2))
	elif t_3 <= 2.0:
		tmp = 1.0 / (math.sqrt(((math.fabs(ky) * math.fabs(ky)) + (math.fabs(kx) * math.fabs(kx)))) / ((math.fabs(ky) * (1.0 + (-0.16666666666666666 * math.pow(math.fabs(ky), 2.0)))) * math.sin(th)))
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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.99)
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(t_2)));
	elseif (t_3 <= 2.0)
		tmp = Float64(1.0 / Float64(sqrt(Float64(Float64(abs(ky) * abs(ky)) + Float64(abs(kx) * abs(kx)))) / Float64(Float64(abs(ky) * Float64(1.0 + Float64(-0.16666666666666666 * (abs(ky) ^ 2.0)))) * sin(th))));
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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.99)
		tmp = sin(th) * (abs(ky) / abs(t_2));
	elseif (t_3 <= 2.0)
		tmp = 1.0 / (sqrt(((abs(ky) * abs(ky)) + (abs(kx) * abs(kx)))) / ((abs(ky) * (1.0 + (-0.16666666666666666 * (abs(ky) ^ 2.0)))) * sin(th)));
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 0.99], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(1.0 / N[(N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[kx], $MachinePrecision] * N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(N[(N[Abs[ky], $MachinePrecision] * N[(1.0 + N[(-0.16666666666666666 * N[Power[N[Abs[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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 0.99:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;\frac{1}{\frac{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}{\left(\left|ky\right| \cdot \left(1 + -0.16666666666666666 \cdot {\left(\left|ky\right|\right)}^{2}\right)\right) \cdot \sin th}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.98999999999999999

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{\sqrt{{\sin kx}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      6. lower-/.f6436.7%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      9. pow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-square-revN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6440.0%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites40.0%

      \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      3. associate-*l/N/A

        \[\leadsto \frac{\sin th \cdot ky}{\color{blue}{\left|\sin kx\right|}} \]
      4. associate-/l*N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]
      5. lower-*.f64N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]
      6. lower-/.f6439.9%

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{\left|\sin kx\right|}} \]
    8. Applied rewrites39.9%

      \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]

    if 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 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Step-by-step derivation
      1. lower-pow.f6452.2%

        \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{\color{blue}{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Applied rewrites52.2%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-pow.f6428.4%

        \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{\color{blue}{2}}}} \cdot \sin th \]
    7. Applied rewrites28.4%

      \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{2}}} \cdot \sin th} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{2}}}} \cdot \sin th \]
      3. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{kx}^{2} + {ky}^{2}}}} \]
      4. div-flipN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
      5. lower-unsound-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
      6. lower-unsound-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
    9. Applied rewrites26.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\sin ky \cdot \sin th}}} \]
    10. Taylor expanded in ky around 0

      \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\color{blue}{\left(ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)\right)} \cdot \sin th}} \]
    11. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\left(ky \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}\right) \cdot \sin th}} \]
      2. lower-+.f64N/A

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\left(ky \cdot \left(1 + \color{blue}{\frac{-1}{6} \cdot {ky}^{2}}\right)\right) \cdot \sin th}} \]
      3. lower-*.f64N/A

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\left(ky \cdot \left(1 + \frac{-1}{6} \cdot \color{blue}{{ky}^{2}}\right)\right) \cdot \sin th}} \]
      4. lower-pow.f6424.9%

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{\color{blue}{2}}\right)\right) \cdot \sin th}} \]
    12. Applied rewrites24.9%

      \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\color{blue}{\left(ky \cdot \left(1 + -0.16666666666666666 \cdot {ky}^{2}\right)\right)} \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 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\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.9%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.9%

      \[\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. mult-flipN/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{\color{blue}{kx}} \]
      3. lift-*.f64N/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{kx} \]
      4. *-commutativeN/A

        \[\leadsto \left(\sin th \cdot ky\right) \cdot \frac{1}{kx} \]
      5. associate-*l*N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      6. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      7. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{kx}\right) \]
    9. Applied rewrites16.8%

      \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 18: 43.2% accurate, 0.5× 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 0.99:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\frac{1}{\frac{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}{th \cdot t\_1}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_3 0.99)
     (* (sin th) (/ (fabs ky) (fabs t_2)))
     (if (<= t_3 2.0)
       (/
        1.0
        (/
         (sqrt (+ (* (fabs ky) (fabs ky)) (* (fabs kx) (fabs kx))))
         (* th t_1)))
       (* (sin th) (* (fabs ky) (/ 1.0 (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.99) {
		tmp = sin(th) * (fabs(ky) / fabs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = 1.0 / (sqrt(((fabs(ky) * fabs(ky)) + (fabs(kx) * fabs(kx)))) / (th * t_1));
	} else {
		tmp = sin(th) * (fabs(ky) * (1.0 / 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.99) {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(t_2));
	} else if (t_3 <= 2.0) {
		tmp = 1.0 / (Math.sqrt(((Math.abs(ky) * Math.abs(ky)) + (Math.abs(kx) * Math.abs(kx)))) / (th * t_1));
	} else {
		tmp = Math.sin(th) * (Math.abs(ky) * (1.0 / 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.99:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(t_2))
	elif t_3 <= 2.0:
		tmp = 1.0 / (math.sqrt(((math.fabs(ky) * math.fabs(ky)) + (math.fabs(kx) * math.fabs(kx)))) / (th * t_1))
	else:
		tmp = math.sin(th) * (math.fabs(ky) * (1.0 / 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.99)
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(t_2)));
	elseif (t_3 <= 2.0)
		tmp = Float64(1.0 / Float64(sqrt(Float64(Float64(abs(ky) * abs(ky)) + Float64(abs(kx) * abs(kx)))) / Float64(th * t_1)));
	else
		tmp = Float64(sin(th) * Float64(abs(ky) * Float64(1.0 / 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.99)
		tmp = sin(th) * (abs(ky) / abs(t_2));
	elseif (t_3 <= 2.0)
		tmp = 1.0 / (sqrt(((abs(ky) * abs(ky)) + (abs(kx) * abs(kx)))) / (th * t_1));
	else
		tmp = sin(th) * (abs(ky) * (1.0 / 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.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$3, 0.99], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2.0], N[(1.0 / N[(N[Sqrt[N[(N[(N[Abs[ky], $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision] + N[(N[Abs[kx], $MachinePrecision] * N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(th * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] * N[(1.0 / N[Abs[kx], $MachinePrecision]), $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 0.99:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|t\_2\right|}\\

\mathbf{elif}\;t\_3 \leq 2:\\
\;\;\;\;\frac{1}{\frac{\sqrt{\left|ky\right| \cdot \left|ky\right| + \left|kx\right| \cdot \left|kx\right|}}{th \cdot t\_1}}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \frac{1}{\left|kx\right|}\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.98999999999999999

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{\sqrt{{\sin kx}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      6. lower-/.f6436.7%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      9. pow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-square-revN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6440.0%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites40.0%

      \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
    7. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
      2. lift-/.f64N/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      3. associate-*l/N/A

        \[\leadsto \frac{\sin th \cdot ky}{\color{blue}{\left|\sin kx\right|}} \]
      4. associate-/l*N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]
      5. lower-*.f64N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]
      6. lower-/.f6439.9%

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{\left|\sin kx\right|}} \]
    8. Applied rewrites39.9%

      \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]

    if 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 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in kx around 0

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    3. Step-by-step derivation
      1. lower-pow.f6452.2%

        \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{\color{blue}{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Applied rewrites52.2%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    5. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. lower-pow.f6428.4%

        \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{\color{blue}{2}}}} \cdot \sin th \]
    7. Applied rewrites28.4%

      \[\leadsto \frac{\sin ky}{\sqrt{{kx}^{2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    8. Step-by-step derivation
      1. lift-*.f64N/A

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{2}}} \cdot \sin th} \]
      2. lift-/.f64N/A

        \[\leadsto \color{blue}{\frac{\sin ky}{\sqrt{{kx}^{2} + {ky}^{2}}}} \cdot \sin th \]
      3. associate-*l/N/A

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{kx}^{2} + {ky}^{2}}}} \]
      4. div-flipN/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
      5. lower-unsound-/.f64N/A

        \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
      6. lower-unsound-/.f64N/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{{kx}^{2} + {ky}^{2}}}{\sin ky \cdot \sin th}}} \]
    9. Applied rewrites26.7%

      \[\leadsto \color{blue}{\frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\sin ky \cdot \sin th}}} \]
    10. Taylor expanded in th around 0

      \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\color{blue}{th \cdot \sin ky}}} \]
    11. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{th \cdot \color{blue}{\sin ky}}} \]
      2. lower-sin.f6417.4%

        \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{th \cdot \sin ky}} \]
    12. Applied rewrites17.4%

      \[\leadsto \frac{1}{\frac{\sqrt{ky \cdot ky + kx \cdot kx}}{\color{blue}{th \cdot \sin ky}}} \]

    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 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\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.9%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.9%

      \[\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. mult-flipN/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{\color{blue}{kx}} \]
      3. lift-*.f64N/A

        \[\leadsto \left(ky \cdot \sin th\right) \cdot \frac{1}{kx} \]
      4. *-commutativeN/A

        \[\leadsto \left(\sin th \cdot ky\right) \cdot \frac{1}{kx} \]
      5. associate-*l*N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      6. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
      7. lower-*.f64N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{\color{blue}{kx}}\right) \]
      8. lower-/.f6416.8%

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{1}{kx}\right) \]
    9. Applied rewrites16.8%

      \[\leadsto \sin th \cdot \left(ky \cdot \color{blue}{\frac{1}{kx}}\right) \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 19: 27.7% accurate, 3.3× speedup?

\[\mathsf{copysign}\left(1, th\right) \cdot \begin{array}{l} \mathbf{if}\;\left|th\right| \leq 420:\\ \;\;\;\;\frac{\left|th\right|}{\left|\sin \left(\left|kx\right|\right)\right|} \cdot ky\\ \mathbf{else}:\\ \;\;\;\;\sin \left(\left|th\right|\right) \cdot \frac{ky}{\left|kx\right|}\\ \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (*
 (copysign 1.0 th)
 (if (<= (fabs th) 420.0)
   (* (/ (fabs th) (fabs (sin (fabs kx)))) ky)
   (* (sin (fabs th)) (/ ky (fabs kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (fabs(th) <= 420.0) {
		tmp = (fabs(th) / fabs(sin(fabs(kx)))) * ky;
	} else {
		tmp = sin(fabs(th)) * (ky / fabs(kx));
	}
	return copysign(1.0, th) * tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.abs(th) <= 420.0) {
		tmp = (Math.abs(th) / Math.abs(Math.sin(Math.abs(kx)))) * ky;
	} else {
		tmp = Math.sin(Math.abs(th)) * (ky / Math.abs(kx));
	}
	return Math.copySign(1.0, th) * tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.fabs(th) <= 420.0:
		tmp = (math.fabs(th) / math.fabs(math.sin(math.fabs(kx)))) * ky
	else:
		tmp = math.sin(math.fabs(th)) * (ky / math.fabs(kx))
	return math.copysign(1.0, th) * tmp
function code(kx, ky, th)
	tmp = 0.0
	if (abs(th) <= 420.0)
		tmp = Float64(Float64(abs(th) / abs(sin(abs(kx)))) * ky);
	else
		tmp = Float64(sin(abs(th)) * Float64(ky / abs(kx)));
	end
	return Float64(copysign(1.0, th) * tmp)
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (abs(th) <= 420.0)
		tmp = (abs(th) / abs(sin(abs(kx)))) * ky;
	else
		tmp = sin(abs(th)) * (ky / abs(kx));
	end
	tmp_2 = (sign(th) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[th]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[Abs[th], $MachinePrecision], 420.0], N[(N[(N[Abs[th], $MachinePrecision] / N[Abs[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * ky), $MachinePrecision], N[(N[Sin[N[Abs[th], $MachinePrecision]], $MachinePrecision] * N[(ky / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\mathsf{copysign}\left(1, th\right) \cdot \begin{array}{l}
\mathbf{if}\;\left|th\right| \leq 420:\\
\;\;\;\;\frac{\left|th\right|}{\left|\sin \left(\left|kx\right|\right)\right|} \cdot ky\\

\mathbf{else}:\\
\;\;\;\;\sin \left(\left|th\right|\right) \cdot \frac{ky}{\left|kx\right|}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 420

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{\sqrt{{\sin kx}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      6. lower-/.f6436.7%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      9. pow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-square-revN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6440.0%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites40.0%

      \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
    7. Taylor expanded in th around 0

      \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
      2. lower-fabs.f64N/A

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
      3. lower-sin.f6421.2%

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
    9. Applied rewrites21.2%

      \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]

    if 420 < th

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\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.9%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.9%

      \[\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.8%

        \[\leadsto \sin th \cdot \frac{ky}{kx} \]
    9. Applied rewrites16.8%

      \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 20: 26.9% accurate, 3.8× speedup?

\[\begin{array}{l} \mathbf{if}\;\left|kx\right| \leq 3 \cdot 10^{+28}:\\ \;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot ky\\ \mathbf{else}:\\ \;\;\;\;\frac{ky \cdot th}{\left|\sin \left(\left|kx\right|\right)\right|}\\ \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (if (<= (fabs kx) 3e+28)
  (* (/ (sin th) (fabs kx)) ky)
  (/ (* ky th) (fabs (sin (fabs kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (fabs(kx) <= 3e+28) {
		tmp = (sin(th) / fabs(kx)) * ky;
	} else {
		tmp = (ky * th) / fabs(sin(fabs(kx)));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(kx, ky, th)
use fmin_fmax_functions
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (abs(kx) <= 3d+28) then
        tmp = (sin(th) / abs(kx)) * ky
    else
        tmp = (ky * th) / abs(sin(abs(kx)))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.abs(kx) <= 3e+28) {
		tmp = (Math.sin(th) / Math.abs(kx)) * ky;
	} else {
		tmp = (ky * th) / Math.abs(Math.sin(Math.abs(kx)));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.fabs(kx) <= 3e+28:
		tmp = (math.sin(th) / math.fabs(kx)) * ky
	else:
		tmp = (ky * th) / math.fabs(math.sin(math.fabs(kx)))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (abs(kx) <= 3e+28)
		tmp = Float64(Float64(sin(th) / abs(kx)) * ky);
	else
		tmp = Float64(Float64(ky * th) / abs(sin(abs(kx))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (abs(kx) <= 3e+28)
		tmp = (sin(th) / abs(kx)) * ky;
	else
		tmp = (ky * th) / abs(sin(abs(kx)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Abs[kx], $MachinePrecision], 3e+28], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * ky), $MachinePrecision], N[(N[(ky * th), $MachinePrecision] / N[Abs[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\mathbf{if}\;\left|kx\right| \leq 3 \cdot 10^{+28}:\\
\;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot ky\\

\mathbf{else}:\\
\;\;\;\;\frac{ky \cdot th}{\left|\sin \left(\left|kx\right|\right)\right|}\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 3.0000000000000001e28

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\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.9%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.9%

      \[\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.8%

        \[\leadsto \frac{\sin th}{kx} \cdot ky \]
    9. Applied rewrites16.8%

      \[\leadsto \frac{\sin th}{kx} \cdot ky \]

    if 3.0000000000000001e28 < kx

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \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.9%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.9%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{\sqrt{{\sin kx}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin kx}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot \color{blue}{ky} \]
      6. lower-/.f6436.7%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin kx}^{2}}} \cdot ky \]
      9. pow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-square-revN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6440.0%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites40.0%

      \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot \color{blue}{ky} \]
    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.5%

        \[\leadsto \frac{ky \cdot th}{\left|\sin kx\right|} \]
    9. Applied rewrites19.5%

      \[\leadsto \frac{ky \cdot th}{\color{blue}{\left|\sin kx\right|}} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 21: 22.1% accurate, 4.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 93.7%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Taylor expanded in ky around 0

    \[\leadsto \color{blue}{\frac{ky \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.9%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.9%

    \[\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.9%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.9%

    \[\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.8%

      \[\leadsto \frac{\sin th}{kx} \cdot ky \]
  9. Applied rewrites16.8%

    \[\leadsto \frac{\sin th}{kx} \cdot ky \]
  10. Add Preprocessing

Alternative 22: 22.1% accurate, 4.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 93.7%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Taylor expanded in ky around 0

    \[\leadsto \color{blue}{\frac{ky \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.9%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.9%

    \[\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.9%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.9%

    \[\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.8%

      \[\leadsto \sin th \cdot \frac{ky}{kx} \]
  9. Applied rewrites16.8%

    \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]
  10. Add Preprocessing

Alternative 23: 15.1% accurate, 4.7× speedup?

\[th \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{ky \cdot {th}^{2}}{\left|kx\right|}, \frac{ky}{\left|kx\right|}\right) \]
(FPCore (kx ky th)
  :precision binary64
  (*
 th
 (fma
  -0.16666666666666666
  (/ (* ky (pow th 2.0)) (fabs kx))
  (/ ky (fabs kx)))))
double code(double kx, double ky, double th) {
	return th * fma(-0.16666666666666666, ((ky * pow(th, 2.0)) / fabs(kx)), (ky / fabs(kx)));
}
function code(kx, ky, th)
	return Float64(th * fma(-0.16666666666666666, Float64(Float64(ky * (th ^ 2.0)) / abs(kx)), Float64(ky / abs(kx))))
end
code[kx_, ky_, th_] := N[(th * N[(-0.16666666666666666 * N[(N[(ky * N[Power[th, 2.0], $MachinePrecision]), $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision] + N[(ky / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
th \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{ky \cdot {th}^{2}}{\left|kx\right|}, \frac{ky}{\left|kx\right|}\right)
Derivation
  1. Initial program 93.7%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Taylor expanded in ky around 0

    \[\leadsto \color{blue}{\frac{ky \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.9%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.9%

    \[\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.9%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.9%

    \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{kx}} \]
  8. Taylor expanded in th around 0

    \[\leadsto th \cdot \left(\frac{-1}{6} \cdot \frac{ky \cdot {th}^{2}}{kx} + \color{blue}{\frac{ky}{kx}}\right) \]
  9. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto th \cdot \left(\frac{-1}{6} \cdot \frac{ky \cdot {th}^{2}}{kx} + \frac{ky}{\color{blue}{kx}}\right) \]
    2. lower-fma.f64N/A

      \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{ky \cdot {th}^{2}}{kx}, \frac{ky}{kx}\right) \]
    3. lower-/.f64N/A

      \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{ky \cdot {th}^{2}}{kx}, \frac{ky}{kx}\right) \]
    4. lower-*.f64N/A

      \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{ky \cdot {th}^{2}}{kx}, \frac{ky}{kx}\right) \]
    5. lower-pow.f64N/A

      \[\leadsto th \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{ky \cdot {th}^{2}}{kx}, \frac{ky}{kx}\right) \]
    6. lower-/.f6413.2%

      \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{ky \cdot {th}^{2}}{kx}, \frac{ky}{kx}\right) \]
  10. Applied rewrites13.2%

    \[\leadsto th \cdot \mathsf{fma}\left(-0.16666666666666666, \color{blue}{\frac{ky \cdot {th}^{2}}{kx}}, \frac{ky}{kx}\right) \]
  11. Add Preprocessing

Alternative 24: 14.0% accurate, 20.5× speedup?

\[\frac{ky \cdot th}{\left|kx\right|} \]
(FPCore (kx ky th)
  :precision binary64
  (/ (* ky th) (fabs kx)))
double code(double kx, double ky, double th) {
	return (ky * th) / 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 = (ky * th) / abs(kx)
end function
public static double code(double kx, double ky, double th) {
	return (ky * th) / Math.abs(kx);
}
def code(kx, ky, th):
	return (ky * th) / math.fabs(kx)
function code(kx, ky, th)
	return Float64(Float64(ky * th) / abs(kx))
end
function tmp = code(kx, ky, th)
	tmp = (ky * th) / abs(kx);
end
code[kx_, ky_, th_] := N[(N[(ky * th), $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]
\frac{ky \cdot th}{\left|kx\right|}
Derivation
  1. Initial program 93.7%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Taylor expanded in ky around 0

    \[\leadsto \color{blue}{\frac{ky \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.9%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.9%

    \[\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.9%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.9%

    \[\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-*.f6412.9%

      \[\leadsto \frac{ky \cdot th}{kx} \]
  10. Applied rewrites12.9%

    \[\leadsto \frac{ky \cdot th}{kx} \]
  11. Add Preprocessing

Reproduce

?
herbie shell --seed 2025212 
(FPCore (kx ky th)
  :name "Toniolo and Linder, Equation (3b), real"
  :precision binary64
  (* (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) (sin th)))