Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 96.8%
Time: 9.5s
Alternatives: 26
Speedup: 1.0×

Specification

?
\[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
(FPCore (kx ky th)
  :precision binary64
  (*
 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.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 26 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: 96.8% accurate, 1.0× speedup?

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

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


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 2.5500000000000001e-166

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\sin ky}{\left|\sin ky\right|} \]
      10. fabs-rhs-divN/A

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
      11. lower-copysign.f6444.4%

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
    6. Applied rewrites44.4%

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

    if 2.5500000000000001e-166 < kx

    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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 96.7% accurate, 1.0× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{\sin ky}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {\sin ky}^{2}}} \cdot \sin th\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 2.5500000000000001e-166

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\sin ky}{\left|\sin ky\right|} \]
      10. fabs-rhs-divN/A

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
      11. lower-copysign.f6444.4%

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
    6. Applied rewrites44.4%

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

    if 2.5500000000000001e-166 < kx

    1. Initial program 93.7%

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

Alternative 3: 96.5% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_4 \leq 0.9999999999999979:\\
\;\;\;\;\frac{t\_1}{\frac{1}{t\_2}}\\

\mathbf{else}:\\
\;\;\;\;\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))))) < 4e-296

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4e-296 < (/.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))))) < 1e-3

    1. Initial program 93.7%

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

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

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

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

    if 1e-3 < (/.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.99999999999999789

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 4: 96.4% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_3 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{elif}\;t\_3 \leq 0.9999999999999979:\\
\;\;\;\;\frac{t\_1}{\frac{1}{t\_2}}\\

\mathbf{else}:\\
\;\;\;\;\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.050000000000000003

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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.99999999999999789

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 5: 96.1% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_3 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

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

\mathbf{else}:\\
\;\;\;\;\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.050000000000000003

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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.99999999999999789

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{\sin ky} \cdot \sqrt{\frac{1}{2} - \color{blue}{\left(\cos \left(ky + ky\right) - \left(1 - \cos \left(kx + kx\right)\right)\right) \cdot \frac{1}{2}}}} \cdot \sin th \]
      8. fp-cancel-sub-sign-invN/A

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

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

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

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

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 6: 95.9% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_3 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{elif}\;t\_3 \leq 0.9999999999999979:\\
\;\;\;\;\frac{\sin th \cdot t\_2}{t\_1}\\

\mathbf{else}:\\
\;\;\;\;\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.050000000000000003

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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.99999999999999789

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 7: 95.9% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{elif}\;t\_2 \leq 0.9999999999999979:\\
\;\;\;\;\frac{t\_1}{\sqrt{0.5 - \left(t\_4 - t\_3\right) \cdot 0.5}} \cdot \sin th\\

\mathbf{else}:\\
\;\;\;\;\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.050000000000000003

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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.99999999999999789

    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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} + \left(\mathsf{neg}\left(\cos \left(kx + kx\right)\right)\right) \cdot \frac{1}{2}\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      16. distribute-rgt1-inN/A

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

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

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

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

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 8: 95.9% accurate, 0.3× speedup?

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

\mathbf{elif}\;t\_3 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

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

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.050000000000000003 or 1e-3 < (/.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.99999999999999789

    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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(\frac{1}{2} + \left(\mathsf{neg}\left(\cos \left(kx + kx\right)\right)\right) \cdot \frac{1}{2}\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      16. distribute-rgt1-inN/A

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 0.99999999999999789 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 95.9% accurate, 0.9× speedup?

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

\mathbf{elif}\;\left|ky\right| \leq 5.8 \cdot 10^{-7}:\\
\;\;\;\;\frac{t\_1}{\sqrt{{\left(\frac{1}{\sin kx}\right)}^{-2} + {\left(\left|ky\right|\right)}^{2}}} \cdot \sin th\\

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


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

    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.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5999999999999999e-162 < ky < 5.7999999999999995e-7

    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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\left(\frac{1}{\sin kx}\right)}^{-2} + \color{blue}{{ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. lower-pow.f6447.0%

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

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

    if 5.7999999999999995e-7 < ky

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 95.9% accurate, 0.9× speedup?

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

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

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


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

    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.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.5999999999999999e-162 < ky < 4.9999999999999996e-41

    1. Initial program 93.7%

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

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

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

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

    if 4.9999999999999996e-41 < ky

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 83.0% accurate, 0.2× speedup?

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

\mathbf{elif}\;t\_4 \leq -0.05:\\
\;\;\;\;\frac{t\_2}{\sqrt{\left(0.5 + t\_3\right) - 0.5 \cdot t\_5}}\\

\mathbf{elif}\;t\_4 \leq 0.1:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{elif}\;t\_4 \leq 0.995:\\
\;\;\;\;\frac{t\_2}{\sqrt{0.5 - 0.5 \cdot \left(\left(t\_5 + \cos \left(2 \cdot \left|ky\right|\right)\right) - 1\right)}}\\

\mathbf{else}:\\
\;\;\;\;\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.84999999999999998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\sin ky}{\left|\sin ky\right|} \]
      10. fabs-rhs-divN/A

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
      11. lower-copysign.f6444.4%

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
    6. Applied rewrites44.4%

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

    if -0.84999999999999998 < (/.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.050000000000000003

    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-pow.f64N/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.10000000000000001

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 0.10000000000000001 < (/.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.995

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.995 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 5 regimes into one program.
  4. Add Preprocessing

Alternative 12: 83.0% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 0.1:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

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

\mathbf{else}:\\
\;\;\;\;\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.84999999999999998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\sin ky}{\left|\sin ky\right|} \]
      10. fabs-rhs-divN/A

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
      11. lower-copysign.f6444.4%

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
    6. Applied rewrites44.4%

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

    if -0.84999999999999998 < (/.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.050000000000000003 or 0.10000000000000001 < (/.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.995

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.10000000000000001

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 0.995 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 13: 76.6% accurate, 0.5× speedup?

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

\mathbf{elif}\;t\_1 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\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.050000000000000003

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \frac{\sin ky}{\left|\sin ky\right|} \]
      10. fabs-rhs-divN/A

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
      11. lower-copysign.f6444.4%

        \[\leadsto \sin th \cdot \mathsf{copysign}\left(1, \color{blue}{\sin ky}\right) \]
    6. Applied rewrites44.4%

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 14: 69.9% accurate, 0.5× speedup?

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

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\sin th \cdot \left(\left|ky\right| \cdot \left|\frac{1}{\sin kx}\right|\right)\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
      11. lower-fabs.f6444.3%

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
    6. Applied rewrites44.3%

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

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

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      2. lower-fabs.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      3. lower-sin.f6423.7%

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
    9. Applied rewrites23.7%

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

      \[\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{\left|1\right|}{\sqrt{\color{blue}{{\sin kx}^{2}}}}\right) \]
      9. lift-sqrt.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \left(ky \cdot \frac{\left|1\right|}{\left|\sin kx\right|}\right) \]
      13. div-fabsN/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      14. unpow-1N/A

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      16. lower-fabs.f6439.5%

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

        \[\leadsto \sin th \cdot \left(ky \cdot \left|{\sin kx}^{-1}\right|\right) \]
      18. unpow-1N/A

        \[\leadsto \sin th \cdot \left(ky \cdot \left|\frac{1}{\sin kx}\right|\right) \]
      19. lower-/.f6439.5%

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

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

    if 1e-3 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 15: 69.9% accurate, 0.5× speedup?

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

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\frac{\sin th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
      11. lower-fabs.f6444.3%

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
    6. Applied rewrites44.3%

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

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

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      2. lower-fabs.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      3. lower-sin.f6423.7%

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
    9. Applied rewrites23.7%

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

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

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

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

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

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

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

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

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

    if 1e-3 < (/.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 kx around 0

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 16: 69.8% accurate, 0.5× speedup?

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

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|\sin kx\right|}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin ky}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      6. lower-/.f6440.6%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin \color{blue}{ky} \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      9. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky}} \cdot \sin ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
      11. lower-fabs.f6444.3%

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
    6. Applied rewrites44.3%

      \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \color{blue}{\sin ky} \]
    7. Taylor expanded in th around 0

      \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin \color{blue}{ky} \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      2. lower-fabs.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      3. lower-sin.f6423.7%

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
    9. Applied rewrites23.7%

      \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin \color{blue}{ky} \]

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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. *-commutativeN/A

        \[\leadsto \frac{\sin th \cdot ky}{\sqrt{\color{blue}{{\sin kx}^{2}}}} \]
      4. associate-/l*N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\sqrt{{\sin kx}^{2}}}} \]
      5. lower-*.f64N/A

        \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\sqrt{{\sin kx}^{2}}}} \]
      6. lower-/.f6436.4%

        \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{\sqrt{{\sin kx}^{2}}}} \]
      7. lift-sqrt.f64N/A

        \[\leadsto \sin th \cdot \frac{ky}{\sqrt{{\sin kx}^{2}}} \]
      8. lift-pow.f64N/A

        \[\leadsto \sin th \cdot \frac{ky}{\sqrt{{\sin kx}^{2}}} \]
      9. unpow2N/A

        \[\leadsto \sin th \cdot \frac{ky}{\sqrt{\sin kx \cdot \sin kx}} \]
      10. rem-sqrt-squareN/A

        \[\leadsto \sin th \cdot \frac{ky}{\left|\sin kx\right|} \]
      11. lower-fabs.f6439.6%

        \[\leadsto \sin th \cdot \frac{ky}{\left|\sin kx\right|} \]
    6. Applied rewrites39.6%

      \[\leadsto \sin th \cdot \color{blue}{\frac{ky}{\left|\sin kx\right|}} \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 17: 53.5% accurate, 0.5× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := \frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_2 \leq -0.05:\\ \;\;\;\;\frac{th}{\left|t\_1\right|} \cdot t\_1\\ \mathbf{elif}\;t\_2 \leq 0.001:\\ \;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (/ t_1 (sqrt (+ (pow (sin kx) 2.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_2 -0.05)
     (* (/ th (fabs t_1)) t_1)
     (if (<= t_2 0.001)
       (* (/ th (fabs (sin kx))) (fabs ky))
       (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = t_1 / sqrt((pow(sin(kx), 2.0) + pow(t_1, 2.0)));
	double tmp;
	if (t_2 <= -0.05) {
		tmp = (th / fabs(t_1)) * t_1;
	} else if (t_2 <= 0.001) {
		tmp = (th / fabs(sin(kx))) * fabs(ky);
	} else {
		tmp = 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 = t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(t_1, 2.0)));
	double tmp;
	if (t_2 <= -0.05) {
		tmp = (th / Math.abs(t_1)) * t_1;
	} else if (t_2 <= 0.001) {
		tmp = (th / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	t_2 = t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(t_1, 2.0)))
	tmp = 0
	if t_2 <= -0.05:
		tmp = (th / math.fabs(t_1)) * t_1
	elif t_2 <= 0.001:
		tmp = (th / math.fabs(math.sin(kx))) * math.fabs(ky)
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (t_1 ^ 2.0))))
	tmp = 0.0
	if (t_2 <= -0.05)
		tmp = Float64(Float64(th / abs(t_1)) * t_1);
	elseif (t_2 <= 0.001)
		tmp = Float64(Float64(th / abs(sin(kx))) * abs(ky));
	else
		tmp = 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 / sqrt(((sin(kx) ^ 2.0) + (t_1 ^ 2.0)));
	tmp = 0.0;
	if (t_2 <= -0.05)
		tmp = (th / abs(t_1)) * t_1;
	elseif (t_2 <= 0.001)
		tmp = (th / abs(sin(kx))) * abs(ky);
	else
		tmp = 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[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$2, -0.05], N[(N[(th / N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[t$95$2, 0.001], N[(N[(th / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := \frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -0.05:\\
\;\;\;\;\frac{th}{\left|t\_1\right|} \cdot t\_1\\

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.050000000000000003

    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 \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin ky}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      6. lower-/.f6440.6%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin \color{blue}{ky} \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      9. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky}} \cdot \sin ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
      11. lower-fabs.f6444.3%

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
    6. Applied rewrites44.3%

      \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \color{blue}{\sin ky} \]
    7. Taylor expanded in th around 0

      \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin \color{blue}{ky} \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      2. lower-fabs.f64N/A

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
      3. lower-sin.f6423.7%

        \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin ky \]
    9. Applied rewrites23.7%

      \[\leadsto \frac{th}{\left|\sin ky\right|} \cdot \sin \color{blue}{ky} \]

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.5%

        \[\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. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6439.6%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites39.6%

      \[\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.4%

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
    9. Applied rewrites21.4%

      \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 18: 53.5% accurate, 0.5× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ t_2 := \frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}}\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;t\_2 \leq -0.05:\\ \;\;\;\;\frac{th \cdot t\_1}{\left|t\_1\right|}\\ \mathbf{elif}\;t\_2 \leq 0.001:\\ \;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky)))
       (t_2 (/ t_1 (sqrt (+ (pow (sin kx) 2.0) (pow t_1 2.0))))))
  (*
   (copysign 1.0 ky)
   (if (<= t_2 -0.05)
     (/ (* th t_1) (fabs t_1))
     (if (<= t_2 0.001)
       (* (/ th (fabs (sin kx))) (fabs ky))
       (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double t_2 = t_1 / sqrt((pow(sin(kx), 2.0) + pow(t_1, 2.0)));
	double tmp;
	if (t_2 <= -0.05) {
		tmp = (th * t_1) / fabs(t_1);
	} else if (t_2 <= 0.001) {
		tmp = (th / fabs(sin(kx))) * fabs(ky);
	} else {
		tmp = 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 = t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(t_1, 2.0)));
	double tmp;
	if (t_2 <= -0.05) {
		tmp = (th * t_1) / Math.abs(t_1);
	} else if (t_2 <= 0.001) {
		tmp = (th / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	t_2 = t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(t_1, 2.0)))
	tmp = 0
	if t_2 <= -0.05:
		tmp = (th * t_1) / math.fabs(t_1)
	elif t_2 <= 0.001:
		tmp = (th / math.fabs(math.sin(kx))) * math.fabs(ky)
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	t_2 = Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (t_1 ^ 2.0))))
	tmp = 0.0
	if (t_2 <= -0.05)
		tmp = Float64(Float64(th * t_1) / abs(t_1));
	elseif (t_2 <= 0.001)
		tmp = Float64(Float64(th / abs(sin(kx))) * abs(ky));
	else
		tmp = 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 / sqrt(((sin(kx) ^ 2.0) + (t_1 ^ 2.0)));
	tmp = 0.0;
	if (t_2 <= -0.05)
		tmp = (th * t_1) / abs(t_1);
	elseif (t_2 <= 0.001)
		tmp = (th / abs(sin(kx))) * abs(ky);
	else
		tmp = 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[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[t$95$2, -0.05], N[(N[(th * t$95$1), $MachinePrecision] / N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.001], N[(N[(th / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
t_2 := \frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}}\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;t\_2 \leq -0.05:\\
\;\;\;\;\frac{th \cdot t\_1}{\left|t\_1\right|}\\

\mathbf{elif}\;t\_2 \leq 0.001:\\
\;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.050000000000000003

    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 \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lift-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. associate-/l*N/A

        \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sqrt{{\sin ky}^{2}}}} \]
      4. *-commutativeN/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \color{blue}{\sin ky} \]
      6. lower-/.f6440.6%

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin \color{blue}{ky} \]
      7. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      8. lift-pow.f64N/A

        \[\leadsto \frac{\sin th}{\sqrt{{\sin ky}^{2}}} \cdot \sin ky \]
      9. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin ky \cdot \sin ky}} \cdot \sin ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
      11. lower-fabs.f6444.3%

        \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \sin ky \]
    6. Applied rewrites44.3%

      \[\leadsto \frac{\sin th}{\left|\sin ky\right|} \cdot \color{blue}{\sin ky} \]
    7. Taylor expanded in th around 0

      \[\leadsto \frac{th \cdot \sin ky}{\color{blue}{\left|\sin ky\right|}} \]
    8. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{th \cdot \sin ky}{\left|\sin ky\right|} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{th \cdot \sin ky}{\left|\sin ky\right|} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{th \cdot \sin ky}{\left|\sin ky\right|} \]
      4. lower-fabs.f64N/A

        \[\leadsto \frac{th \cdot \sin ky}{\left|\sin ky\right|} \]
      5. lower-sin.f6429.2%

        \[\leadsto \frac{th \cdot \sin ky}{\left|\sin ky\right|} \]
    9. Applied rewrites29.2%

      \[\leadsto \frac{th \cdot \sin ky}{\color{blue}{\left|\sin ky\right|}} \]

    if -0.050000000000000003 < (/.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))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.5%

        \[\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. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6439.6%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites39.6%

      \[\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.4%

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
    9. Applied rewrites21.4%

      \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 19: 46.4% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \leq 0.001:\\ \;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1.0 ky)
   (if (<= (/ t_1 (sqrt (+ (pow (sin kx) 2.0) (pow t_1 2.0)))) 0.001)
     (* (/ th (fabs (sin kx))) (fabs ky))
     (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if ((t_1 / sqrt((pow(sin(kx), 2.0) + pow(t_1, 2.0)))) <= 0.001) {
		tmp = (th / fabs(sin(kx))) * fabs(ky);
	} else {
		tmp = sin(th);
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(Math.abs(ky));
	double tmp;
	if ((t_1 / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(t_1, 2.0)))) <= 0.001) {
		tmp = (th / Math.abs(Math.sin(kx))) * Math.abs(ky);
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if (t_1 / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(t_1, 2.0)))) <= 0.001:
		tmp = (th / math.fabs(math.sin(kx))) * math.fabs(ky)
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (Float64(t_1 / sqrt(Float64((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = Float64(Float64(th / abs(sin(kx))) * abs(ky));
	else
		tmp = sin(th);
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	tmp = 0.0;
	if ((t_1 / sqrt(((sin(kx) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = (th / abs(sin(kx))) * abs(ky);
	else
		tmp = sin(th);
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(th / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_1}{\sqrt{{\sin kx}^{2} + {t\_1}^{2}}} \leq 0.001:\\
\;\;\;\;\frac{th}{\left|\sin kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.5%

        \[\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. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6439.6%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites39.6%

      \[\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.4%

        \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]
    9. Applied rewrites21.4%

      \[\leadsto \frac{th}{\left|\sin kx\right|} \cdot ky \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 20: 45.7% 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 5 \cdot 10^{-73}:\\ \;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot \left|ky\right|\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\left|ky\right| \cdot th}{\left|t\_2\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \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 5e-73)
     (* (/ (sin th) (fabs kx)) (fabs ky))
     (if (<= t_3 5e-5) (/ (* (fabs ky) th) (fabs t_2)) (sin th))))))
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 <= 5e-73) {
		tmp = (sin(th) / fabs(kx)) * fabs(ky);
	} else if (t_3 <= 5e-5) {
		tmp = (fabs(ky) * th) / fabs(t_2);
	} else {
		tmp = 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.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 <= 5e-73) {
		tmp = (Math.sin(th) / Math.abs(kx)) * Math.abs(ky);
	} else if (t_3 <= 5e-5) {
		tmp = (Math.abs(ky) * th) / Math.abs(t_2);
	} else {
		tmp = 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.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 <= 5e-73:
		tmp = (math.sin(th) / math.fabs(kx)) * math.fabs(ky)
	elif t_3 <= 5e-5:
		tmp = (math.fabs(ky) * th) / math.fabs(t_2)
	else:
		tmp = math.sin(th)
	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 <= 5e-73)
		tmp = Float64(Float64(sin(th) / abs(kx)) * abs(ky));
	elseif (t_3 <= 5e-5)
		tmp = Float64(Float64(abs(ky) * th) / abs(t_2));
	else
		tmp = 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 = sin(abs(kx));
	t_3 = t_1 / sqrt(((t_2 ^ 2.0) + (t_1 ^ 2.0)));
	tmp = 0.0;
	if (t_3 <= 5e-73)
		tmp = (sin(th) / abs(kx)) * abs(ky);
	elseif (t_3 <= 5e-5)
		tmp = (abs(ky) * th) / abs(t_2);
	else
		tmp = 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[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, 5e-73], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 5e-5], N[(N[(N[Abs[ky], $MachinePrecision] * th), $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $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 5 \cdot 10^{-73}:\\
\;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot \left|ky\right|\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{\left|ky\right| \cdot th}{\left|t\_2\right|}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 4.9999999999999998e-73

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.7%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.7%

      \[\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.5%

        \[\leadsto \frac{\sin th}{kx} \cdot ky \]
    9. Applied rewrites16.5%

      \[\leadsto \frac{\sin th}{kx} \cdot ky \]

    if 4.9999999999999998e-73 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000002e-5

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.5%

        \[\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. unpow2N/A

        \[\leadsto \frac{\sin th}{\sqrt{\sin kx \cdot \sin kx}} \cdot ky \]
      10. rem-sqrt-squareN/A

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
      11. lower-fabs.f6439.6%

        \[\leadsto \frac{\sin th}{\left|\sin kx\right|} \cdot ky \]
    6. Applied rewrites39.6%

      \[\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.8%

        \[\leadsto \frac{ky \cdot th}{\left|\sin kx\right|} \]
    9. Applied rewrites19.8%

      \[\leadsto \frac{ky \cdot th}{\color{blue}{\left|\sin kx\right|}} \]

    if 5.0000000000000002e-5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    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 \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 21: 44.8% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 0.001:\\ \;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot \left|ky\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1.0 ky)
   (if (<=
        (/ t_1 (sqrt (+ (pow (sin (fabs kx)) 2.0) (pow t_1 2.0))))
        0.001)
     (* (/ (sin th) (fabs kx)) (fabs ky))
     (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if ((t_1 / sqrt((pow(sin(fabs(kx)), 2.0) + pow(t_1, 2.0)))) <= 0.001) {
		tmp = (sin(th) / fabs(kx)) * fabs(ky);
	} else {
		tmp = sin(th);
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(Math.abs(ky));
	double tmp;
	if ((t_1 / Math.sqrt((Math.pow(Math.sin(Math.abs(kx)), 2.0) + Math.pow(t_1, 2.0)))) <= 0.001) {
		tmp = (Math.sin(th) / Math.abs(kx)) * Math.abs(ky);
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if (t_1 / math.sqrt((math.pow(math.sin(math.fabs(kx)), 2.0) + math.pow(t_1, 2.0)))) <= 0.001:
		tmp = (math.sin(th) / math.fabs(kx)) * math.fabs(ky)
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (Float64(t_1 / sqrt(Float64((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = Float64(Float64(sin(th) / abs(kx)) * abs(ky));
	else
		tmp = sin(th);
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	tmp = 0.0;
	if ((t_1 / sqrt(((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = (sin(th) / abs(kx)) * abs(ky);
	else
		tmp = sin(th);
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[(N[Sin[th], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * N[Abs[ky], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 0.001:\\
\;\;\;\;\frac{\sin th}{\left|kx\right|} \cdot \left|ky\right|\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.7%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.7%

      \[\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.5%

        \[\leadsto \frac{\sin th}{kx} \cdot ky \]
    9. Applied rewrites16.5%

      \[\leadsto \frac{\sin th}{kx} \cdot ky \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 22: 44.7% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1.0 ky)
   (if (<=
        (/ t_1 (sqrt (+ (pow (sin (fabs kx)) 2.0) (pow t_1 2.0))))
        0.001)
     (* (sin th) (/ (fabs ky) (fabs kx)))
     (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if ((t_1 / sqrt((pow(sin(fabs(kx)), 2.0) + pow(t_1, 2.0)))) <= 0.001) {
		tmp = sin(th) * (fabs(ky) / fabs(kx));
	} else {
		tmp = sin(th);
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(Math.abs(ky));
	double tmp;
	if ((t_1 / Math.sqrt((Math.pow(Math.sin(Math.abs(kx)), 2.0) + Math.pow(t_1, 2.0)))) <= 0.001) {
		tmp = Math.sin(th) * (Math.abs(ky) / Math.abs(kx));
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if (t_1 / math.sqrt((math.pow(math.sin(math.fabs(kx)), 2.0) + math.pow(t_1, 2.0)))) <= 0.001:
		tmp = math.sin(th) * (math.fabs(ky) / math.fabs(kx))
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (Float64(t_1 / sqrt(Float64((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = Float64(sin(th) * Float64(abs(ky) / abs(kx)));
	else
		tmp = sin(th);
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	tmp = 0.0;
	if ((t_1 / sqrt(((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 0.001)
		tmp = sin(th) * (abs(ky) / abs(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 0.001], N[(N[Sin[th], $MachinePrecision] * N[(N[Abs[ky], $MachinePrecision] / N[Abs[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 0.001:\\
\;\;\;\;\sin th \cdot \frac{\left|ky\right|}{\left|kx\right|}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.7%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.7%

      \[\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.5%

        \[\leadsto \sin th \cdot \frac{ky}{kx} \]
    9. Applied rewrites16.5%

      \[\leadsto \sin th \cdot \frac{ky}{\color{blue}{kx}} \]

    if 1e-3 < (/.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 kx around 0

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 23: 39.8% accurate, 0.8× speedup?

\[\begin{array}{l} t_1 := \sin \left(\left|ky\right|\right)\\ \mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l} \mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{1}{\frac{\left|kx\right|}{th \cdot \left|ky\right|}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
  :precision binary64
  (let* ((t_1 (sin (fabs ky))))
  (*
   (copysign 1.0 ky)
   (if (<=
        (/ t_1 (sqrt (+ (pow (sin (fabs kx)) 2.0) (pow t_1 2.0))))
        5e-5)
     (/ 1.0 (/ (fabs kx) (* th (fabs ky))))
     (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(fabs(ky));
	double tmp;
	if ((t_1 / sqrt((pow(sin(fabs(kx)), 2.0) + pow(t_1, 2.0)))) <= 5e-5) {
		tmp = 1.0 / (fabs(kx) / (th * fabs(ky)));
	} else {
		tmp = sin(th);
	}
	return copysign(1.0, ky) * tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(Math.abs(ky));
	double tmp;
	if ((t_1 / Math.sqrt((Math.pow(Math.sin(Math.abs(kx)), 2.0) + Math.pow(t_1, 2.0)))) <= 5e-5) {
		tmp = 1.0 / (Math.abs(kx) / (th * Math.abs(ky)));
	} else {
		tmp = Math.sin(th);
	}
	return Math.copySign(1.0, ky) * tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(math.fabs(ky))
	tmp = 0
	if (t_1 / math.sqrt((math.pow(math.sin(math.fabs(kx)), 2.0) + math.pow(t_1, 2.0)))) <= 5e-5:
		tmp = 1.0 / (math.fabs(kx) / (th * math.fabs(ky)))
	else:
		tmp = math.sin(th)
	return math.copysign(1.0, ky) * tmp
function code(kx, ky, th)
	t_1 = sin(abs(ky))
	tmp = 0.0
	if (Float64(t_1 / sqrt(Float64((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 5e-5)
		tmp = Float64(1.0 / Float64(abs(kx) / Float64(th * abs(ky))));
	else
		tmp = sin(th);
	end
	return Float64(copysign(1.0, ky) * tmp)
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(abs(ky));
	tmp = 0.0;
	if ((t_1 / sqrt(((sin(abs(kx)) ^ 2.0) + (t_1 ^ 2.0)))) <= 5e-5)
		tmp = 1.0 / (abs(kx) / (th * abs(ky)));
	else
		tmp = sin(th);
	end
	tmp_2 = (sign(ky) * abs(1.0)) * tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sin[N[Abs[ky], $MachinePrecision]], $MachinePrecision]}, N[(N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] * If[LessEqual[N[(t$95$1 / N[Sqrt[N[(N[Power[N[Sin[N[Abs[kx], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 5e-5], N[(1.0 / N[(N[Abs[kx], $MachinePrecision] / N[(th * N[Abs[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]), $MachinePrecision]]
\begin{array}{l}
t_1 := \sin \left(\left|ky\right|\right)\\
\mathsf{copysign}\left(1, ky\right) \cdot \begin{array}{l}
\mathbf{if}\;\frac{t\_1}{\sqrt{{\sin \left(\left|kx\right|\right)}^{2} + {t\_1}^{2}}} \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{1}{\frac{\left|kx\right|}{th \cdot \left|ky\right|}}\\

\mathbf{else}:\\
\;\;\;\;\sin th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000002e-5

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Taylor expanded in ky around 0

      \[\leadsto \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.6%

        \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
    4. Applied rewrites35.6%

      \[\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.7%

        \[\leadsto \frac{ky \cdot \sin th}{kx} \]
    7. Applied rewrites15.7%

      \[\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.8%

        \[\leadsto \frac{ky \cdot th}{kx} \]
    10. Applied rewrites12.8%

      \[\leadsto \frac{ky \cdot th}{kx} \]
    11. Step-by-step derivation
      1. lift-/.f64N/A

        \[\leadsto \frac{ky \cdot th}{kx} \]
      2. div-flipN/A

        \[\leadsto \frac{1}{\frac{kx}{\color{blue}{ky \cdot th}}} \]
      3. lower-unsound-/.f64N/A

        \[\leadsto \frac{1}{\frac{kx}{\color{blue}{ky \cdot th}}} \]
      4. lower-unsound-/.f6412.8%

        \[\leadsto \frac{1}{\frac{kx}{ky \cdot \color{blue}{th}}} \]
      5. lift-*.f64N/A

        \[\leadsto \frac{1}{\frac{kx}{ky \cdot th}} \]
      6. *-commutativeN/A

        \[\leadsto \frac{1}{\frac{kx}{th \cdot ky}} \]
      7. lower-*.f6412.8%

        \[\leadsto \frac{1}{\frac{kx}{th \cdot ky}} \]
    12. Applied rewrites12.8%

      \[\leadsto \frac{1}{\frac{kx}{\color{blue}{th \cdot ky}}} \]

    if 5.0000000000000002e-5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    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 \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{{\sin ky}^{2}}}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\color{blue}{{\sin ky}^{2}}}} \]
      3. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\color{blue}{\sin ky}}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{\color{blue}{2}}}} \]
      5. lower-sqrt.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      6. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
      7. lower-sin.f6441.0%

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}} \]
    4. Applied rewrites41.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin ky}^{2}}}} \]
    5. Taylor expanded in ky around 0

      \[\leadsto \sin th \]
    6. Step-by-step derivation
      1. lower-sin.f6423.7%

        \[\leadsto \sin th \]
    7. Applied rewrites23.7%

      \[\leadsto \sin th \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 24: 14.0% accurate, 21.1× speedup?

\[\frac{1}{\frac{\left|kx\right|}{th \cdot ky}} \]
(FPCore (kx ky th)
  :precision binary64
  (/ 1.0 (/ (fabs kx) (* th ky))))
double code(double kx, double ky, double th) {
	return 1.0 / (fabs(kx) / (th * 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 = 1.0d0 / (abs(kx) / (th * ky))
end function
public static double code(double kx, double ky, double th) {
	return 1.0 / (Math.abs(kx) / (th * ky));
}
def code(kx, ky, th):
	return 1.0 / (math.fabs(kx) / (th * ky))
function code(kx, ky, th)
	return Float64(1.0 / Float64(abs(kx) / Float64(th * ky)))
end
function tmp = code(kx, ky, th)
	tmp = 1.0 / (abs(kx) / (th * ky));
end
code[kx_, ky_, th_] := N[(1.0 / N[(N[Abs[kx], $MachinePrecision] / N[(th * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\frac{\left|kx\right|}{th \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.6%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.6%

    \[\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.7%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.7%

    \[\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.8%

      \[\leadsto \frac{ky \cdot th}{kx} \]
  10. Applied rewrites12.8%

    \[\leadsto \frac{ky \cdot th}{kx} \]
  11. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \frac{ky \cdot th}{kx} \]
    2. div-flipN/A

      \[\leadsto \frac{1}{\frac{kx}{\color{blue}{ky \cdot th}}} \]
    3. lower-unsound-/.f64N/A

      \[\leadsto \frac{1}{\frac{kx}{\color{blue}{ky \cdot th}}} \]
    4. lower-unsound-/.f6412.8%

      \[\leadsto \frac{1}{\frac{kx}{ky \cdot \color{blue}{th}}} \]
    5. lift-*.f64N/A

      \[\leadsto \frac{1}{\frac{kx}{ky \cdot th}} \]
    6. *-commutativeN/A

      \[\leadsto \frac{1}{\frac{kx}{th \cdot ky}} \]
    7. lower-*.f6412.8%

      \[\leadsto \frac{1}{\frac{kx}{th \cdot ky}} \]
  12. Applied rewrites12.8%

    \[\leadsto \frac{1}{\frac{kx}{\color{blue}{th \cdot ky}}} \]
  13. Add Preprocessing

Alternative 25: 14.0% accurate, 26.3× speedup?

\[\frac{1}{\left|kx\right|} \cdot \left(th \cdot ky\right) \]
(FPCore (kx ky th)
  :precision binary64
  (* (/ 1.0 (fabs kx)) (* th ky)))
double code(double kx, double ky, double th) {
	return (1.0 / fabs(kx)) * (th * 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 = (1.0d0 / abs(kx)) * (th * ky)
end function
public static double code(double kx, double ky, double th) {
	return (1.0 / Math.abs(kx)) * (th * ky);
}
def code(kx, ky, th):
	return (1.0 / math.fabs(kx)) * (th * ky)
function code(kx, ky, th)
	return Float64(Float64(1.0 / abs(kx)) * Float64(th * ky))
end
function tmp = code(kx, ky, th)
	tmp = (1.0 / abs(kx)) * (th * ky);
end
code[kx_, ky_, th_] := N[(N[(1.0 / N[Abs[kx], $MachinePrecision]), $MachinePrecision] * N[(th * ky), $MachinePrecision]), $MachinePrecision]
\frac{1}{\left|kx\right|} \cdot \left(th \cdot ky\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.6%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.6%

    \[\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.7%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.7%

    \[\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.8%

      \[\leadsto \frac{ky \cdot th}{kx} \]
  10. Applied rewrites12.8%

    \[\leadsto \frac{ky \cdot th}{kx} \]
  11. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \frac{ky \cdot th}{kx} \]
    2. mult-flipN/A

      \[\leadsto \left(ky \cdot th\right) \cdot \frac{1}{\color{blue}{kx}} \]
    3. *-commutativeN/A

      \[\leadsto \frac{1}{kx} \cdot \left(ky \cdot \color{blue}{th}\right) \]
    4. lower-*.f64N/A

      \[\leadsto \frac{1}{kx} \cdot \left(ky \cdot \color{blue}{th}\right) \]
    5. lower-/.f6412.8%

      \[\leadsto \frac{1}{kx} \cdot \left(ky \cdot th\right) \]
    6. lift-*.f64N/A

      \[\leadsto \frac{1}{kx} \cdot \left(ky \cdot th\right) \]
    7. *-commutativeN/A

      \[\leadsto \frac{1}{kx} \cdot \left(th \cdot ky\right) \]
    8. lower-*.f6412.8%

      \[\leadsto \frac{1}{kx} \cdot \left(th \cdot ky\right) \]
  12. Applied rewrites12.8%

    \[\leadsto \frac{1}{kx} \cdot \left(th \cdot \color{blue}{ky}\right) \]
  13. Add Preprocessing

Alternative 26: 14.0% accurate, 33.3× 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.6%

      \[\leadsto \frac{ky \cdot \sin th}{\sqrt{{\sin kx}^{2}}} \]
  4. Applied rewrites35.6%

    \[\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.7%

      \[\leadsto \frac{ky \cdot \sin th}{kx} \]
  7. Applied rewrites15.7%

    \[\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.8%

      \[\leadsto \frac{ky \cdot th}{kx} \]
  10. Applied rewrites12.8%

    \[\leadsto \frac{ky \cdot th}{kx} \]
  11. Add Preprocessing

Reproduce

?
herbie shell --seed 2025258 
(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)))