Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.6% → 99.6%
Time: 21.7s
Alternatives: 22
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 22 alternatives:

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

Initial Program: 93.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
    3. neg-mul-194.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
    11. neg-mul-194.0%

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
    12. associate-/r*94.0%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
    13. associate-/r/94.1%

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

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

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

      \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    3. un-div-inv99.7%

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
    4. hypot-udef94.1%

      \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
    5. unpow294.1%

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

      \[\leadsto \frac{\sin th}{\frac{\sqrt{{\sin ky}^{2} + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
    7. +-commutative94.1%

      \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
    8. unpow294.1%

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

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

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

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

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

Alternative 2: 43.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (* (sin th) (/ ky (sin kx))))))
   (if (<= (sin kx) -0.92)
     t_1
     (if (<= (sin kx) -0.885)
       (/ (* ky (fabs (sin th))) (sin kx))
       (if (<= (sin kx) -0.02)
         t_1
         (if (<= (sin kx) 2e-38)
           (sin th)
           (* (sin ky) (/ (sin th) (sin kx)))))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs((sin(th) * (ky / sin(kx))));
	double tmp;
	if (sin(kx) <= -0.92) {
		tmp = t_1;
	} else if (sin(kx) <= -0.885) {
		tmp = (ky * fabs(sin(th))) / sin(kx);
	} else if (sin(kx) <= -0.02) {
		tmp = t_1;
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) * (sin(th) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = abs((sin(th) * (ky / sin(kx))))
    if (sin(kx) <= (-0.92d0)) then
        tmp = t_1
    else if (sin(kx) <= (-0.885d0)) then
        tmp = (ky * abs(sin(th))) / sin(kx)
    else if (sin(kx) <= (-0.02d0)) then
        tmp = t_1
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = sin(ky) * (sin(th) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.abs((Math.sin(th) * (ky / Math.sin(kx))));
	double tmp;
	if (Math.sin(kx) <= -0.92) {
		tmp = t_1;
	} else if (Math.sin(kx) <= -0.885) {
		tmp = (ky * Math.abs(Math.sin(th))) / Math.sin(kx);
	} else if (Math.sin(kx) <= -0.02) {
		tmp = t_1;
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs((math.sin(th) * (ky / math.sin(kx))))
	tmp = 0
	if math.sin(kx) <= -0.92:
		tmp = t_1
	elif math.sin(kx) <= -0.885:
		tmp = (ky * math.fabs(math.sin(th))) / math.sin(kx)
	elif math.sin(kx) <= -0.02:
		tmp = t_1
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	t_1 = abs(Float64(sin(th) * Float64(ky / sin(kx))))
	tmp = 0.0
	if (sin(kx) <= -0.92)
		tmp = t_1;
	elseif (sin(kx) <= -0.885)
		tmp = Float64(Float64(ky * abs(sin(th))) / sin(kx));
	elseif (sin(kx) <= -0.02)
		tmp = t_1;
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs((sin(th) * (ky / sin(kx))));
	tmp = 0.0;
	if (sin(kx) <= -0.92)
		tmp = t_1;
	elseif (sin(kx) <= -0.885)
		tmp = (ky * abs(sin(th))) / sin(kx);
	elseif (sin(kx) <= -0.02)
		tmp = t_1;
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = sin(ky) * (sin(th) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.92], t$95$1, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.885], N[(N[(ky * N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], t$95$1, If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th \cdot \frac{ky}{\sin kx}\right|\\
\mathbf{if}\;\sin kx \leq -0.92:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\sin kx \leq -0.885:\\
\;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq -0.02:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 kx) < -0.92000000000000004 or -0.88500000000000001 < (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.3%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.3%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt17.4%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx}} \cdot \sqrt{\frac{ky \cdot \sin th}{\sin kx}}} \]
      2. sqrt-unprod27.5%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      3. pow227.5%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}^{2}}} \]
      4. *-commutative27.5%

        \[\leadsto \sqrt{{\left(\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}\right)}^{2}} \]
      5. *-un-lft-identity27.5%

        \[\leadsto \sqrt{{\left(\frac{\sin th \cdot ky}{\color{blue}{1 \cdot \sin kx}}\right)}^{2}} \]
      6. times-frac27.4%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{1} \cdot \frac{ky}{\sin kx}\right)}}^{2}} \]
      7. /-rgt-identity27.4%

        \[\leadsto \sqrt{{\left(\color{blue}{\sin th} \cdot \frac{ky}{\sin kx}\right)}^{2}} \]
    7. Applied egg-rr27.4%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin th \cdot \frac{ky}{\sin kx}\right)}^{2}}} \]
    8. Step-by-step derivation
      1. *-commutative27.4%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      3. unpow227.5%

        \[\leadsto \sqrt{\color{blue}{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      4. rem-sqrt-square34.0%

        \[\leadsto \color{blue}{\left|\frac{ky \cdot \sin th}{\sin kx}\right|} \]
      5. associate-*l/33.9%

        \[\leadsto \left|\color{blue}{\frac{ky}{\sin kx} \cdot \sin th}\right| \]
      6. *-commutative33.9%

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

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

    if -0.92000000000000004 < (sin.f64 kx) < -0.88500000000000001

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod5.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow25.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr53.3%

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

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square3.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified75.6%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Taylor expanded in ky around inf 57.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
    5. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sin kx} \]
      2. associate-*l/57.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    6. Simplified57.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 44.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (* (sin th) (/ (sin ky) (sin kx))))))
   (if (<= (sin kx) -0.92)
     t_1
     (if (<= (sin kx) -0.885)
       (/ (* ky (fabs (sin th))) (sin kx))
       (if (<= (sin kx) -0.02)
         t_1
         (if (<= (sin kx) 2e-38)
           (sin th)
           (* (sin ky) (/ (sin th) (sin kx)))))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs((sin(th) * (sin(ky) / sin(kx))));
	double tmp;
	if (sin(kx) <= -0.92) {
		tmp = t_1;
	} else if (sin(kx) <= -0.885) {
		tmp = (ky * fabs(sin(th))) / sin(kx);
	} else if (sin(kx) <= -0.02) {
		tmp = t_1;
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) * (sin(th) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = abs((sin(th) * (sin(ky) / sin(kx))))
    if (sin(kx) <= (-0.92d0)) then
        tmp = t_1
    else if (sin(kx) <= (-0.885d0)) then
        tmp = (ky * abs(sin(th))) / sin(kx)
    else if (sin(kx) <= (-0.02d0)) then
        tmp = t_1
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = sin(ky) * (sin(th) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.abs((Math.sin(th) * (Math.sin(ky) / Math.sin(kx))));
	double tmp;
	if (Math.sin(kx) <= -0.92) {
		tmp = t_1;
	} else if (Math.sin(kx) <= -0.885) {
		tmp = (ky * Math.abs(Math.sin(th))) / Math.sin(kx);
	} else if (Math.sin(kx) <= -0.02) {
		tmp = t_1;
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs((math.sin(th) * (math.sin(ky) / math.sin(kx))))
	tmp = 0
	if math.sin(kx) <= -0.92:
		tmp = t_1
	elif math.sin(kx) <= -0.885:
		tmp = (ky * math.fabs(math.sin(th))) / math.sin(kx)
	elif math.sin(kx) <= -0.02:
		tmp = t_1
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	t_1 = abs(Float64(sin(th) * Float64(sin(ky) / sin(kx))))
	tmp = 0.0
	if (sin(kx) <= -0.92)
		tmp = t_1;
	elseif (sin(kx) <= -0.885)
		tmp = Float64(Float64(ky * abs(sin(th))) / sin(kx));
	elseif (sin(kx) <= -0.02)
		tmp = t_1;
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs((sin(th) * (sin(ky) / sin(kx))));
	tmp = 0.0;
	if (sin(kx) <= -0.92)
		tmp = t_1;
	elseif (sin(kx) <= -0.885)
		tmp = (ky * abs(sin(th))) / sin(kx);
	elseif (sin(kx) <= -0.02)
		tmp = t_1;
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = sin(ky) * (sin(th) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.92], t$95$1, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.885], N[(N[(ky * N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], t$95$1, If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\
\mathbf{if}\;\sin kx \leq -0.92:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\sin kx \leq -0.885:\\
\;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq -0.02:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 kx) < -0.92000000000000004 or -0.88500000000000001 < (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.3%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. clear-num18.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky}}} \cdot \sin th \]
      2. associate-/r/18.1%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin kx} \cdot \sin ky\right)} \cdot \sin th \]
    5. Applied egg-rr18.1%

      \[\leadsto \color{blue}{\left(\frac{1}{\sin kx} \cdot \sin ky\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt17.1%

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

        \[\leadsto \color{blue}{\sqrt{\left(\left(\frac{1}{\sin kx} \cdot \sin ky\right) \cdot \sin th\right) \cdot \left(\left(\frac{1}{\sin kx} \cdot \sin ky\right) \cdot \sin th\right)}} \]
      3. pow229.6%

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

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

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\frac{1 \cdot \sin ky}{\sin kx}}\right)}^{2}} \]
      6. *-un-lft-identity29.6%

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

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

        \[\leadsto \sqrt{\color{blue}{\left(\sin th \cdot \frac{\sin ky}{\sin kx}\right) \cdot \left(\sin th \cdot \frac{\sin ky}{\sin kx}\right)}} \]
      2. rem-sqrt-square36.9%

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

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

    if -0.92000000000000004 < (sin.f64 kx) < -0.88500000000000001

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod5.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow25.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr53.3%

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

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square3.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified75.6%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Taylor expanded in ky around inf 57.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
    5. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sin kx} \]
      2. associate-*l/57.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    6. Simplified57.0%

      \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
  3. Recombined 4 regimes into one program.
  4. Final simplification45.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 44.6% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;\left|t\_1\right|\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* (sin ky) (/ (sin th) (sin kx)))))
   (if (<= (sin kx) -0.92)
     (fabs t_1)
     (if (<= (sin kx) -0.885)
       (/ (* ky (fabs (sin th))) (sin kx))
       (if (<= (sin kx) -0.02)
         (fabs (* (sin th) (/ (sin ky) (sin kx))))
         (if (<= (sin kx) 2e-38) (sin th) t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) * (sin(th) / sin(kx));
	double tmp;
	if (sin(kx) <= -0.92) {
		tmp = fabs(t_1);
	} else if (sin(kx) <= -0.885) {
		tmp = (ky * fabs(sin(th))) / sin(kx);
	} else if (sin(kx) <= -0.02) {
		tmp = fabs((sin(th) * (sin(ky) / sin(kx))));
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = t_1;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = sin(ky) * (sin(th) / sin(kx))
    if (sin(kx) <= (-0.92d0)) then
        tmp = abs(t_1)
    else if (sin(kx) <= (-0.885d0)) then
        tmp = (ky * abs(sin(th))) / sin(kx)
    else if (sin(kx) <= (-0.02d0)) then
        tmp = abs((sin(th) * (sin(ky) / sin(kx))))
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	double tmp;
	if (Math.sin(kx) <= -0.92) {
		tmp = Math.abs(t_1);
	} else if (Math.sin(kx) <= -0.885) {
		tmp = (ky * Math.abs(Math.sin(th))) / Math.sin(kx);
	} else if (Math.sin(kx) <= -0.02) {
		tmp = Math.abs((Math.sin(th) * (Math.sin(ky) / Math.sin(kx))));
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) * (math.sin(th) / math.sin(kx))
	tmp = 0
	if math.sin(kx) <= -0.92:
		tmp = math.fabs(t_1)
	elif math.sin(kx) <= -0.885:
		tmp = (ky * math.fabs(math.sin(th))) / math.sin(kx)
	elif math.sin(kx) <= -0.02:
		tmp = math.fabs((math.sin(th) * (math.sin(ky) / math.sin(kx))))
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = t_1
	return tmp
function code(kx, ky, th)
	t_1 = Float64(sin(ky) * Float64(sin(th) / sin(kx)))
	tmp = 0.0
	if (sin(kx) <= -0.92)
		tmp = abs(t_1);
	elseif (sin(kx) <= -0.885)
		tmp = Float64(Float64(ky * abs(sin(th))) / sin(kx));
	elseif (sin(kx) <= -0.02)
		tmp = abs(Float64(sin(th) * Float64(sin(ky) / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) * (sin(th) / sin(kx));
	tmp = 0.0;
	if (sin(kx) <= -0.92)
		tmp = abs(t_1);
	elseif (sin(kx) <= -0.885)
		tmp = (ky * abs(sin(th))) / sin(kx);
	elseif (sin(kx) <= -0.02)
		tmp = abs((sin(th) * (sin(ky) / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[kx], $MachinePrecision], -0.92], N[Abs[t$95$1], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], -0.885], N[(N[(ky * N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], t$95$1]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \sin ky \cdot \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin kx \leq -0.92:\\
\;\;\;\;\left|t\_1\right|\\

\mathbf{elif}\;\sin kx \leq -0.885:\\
\;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 kx) < -0.92000000000000004

    1. Initial program 99.1%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. add-sqr-sqrt15.0%

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \sin th} \cdot \sqrt{\frac{\sin ky}{\sin kx} \cdot \sin th}} \]
      2. sqrt-unprod25.7%

        \[\leadsto \color{blue}{\sqrt{\left(\frac{\sin ky}{\sin kx} \cdot \sin th\right) \cdot \left(\frac{\sin ky}{\sin kx} \cdot \sin th\right)}} \]
      3. pow225.7%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin ky}{\sin kx} \cdot \sin th\right)}^{2}}} \]
      4. associate-*l/25.8%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin ky}{\frac{\sin kx}{\sin th}}\right)}}^{2}} \]
    5. Applied egg-rr25.7%

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin ky}{\frac{\sin kx}{\sin th}}\right)}^{2}}} \]
    6. Step-by-step derivation
      1. unpow225.7%

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}} \cdot \frac{\sin ky}{\frac{\sin kx}{\sin th}}}} \]
      2. rem-sqrt-square32.6%

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin kx}{\sin th}}\right|} \]
      3. associate-/l*32.7%

        \[\leadsto \left|\color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}}\right| \]
      4. *-commutative32.7%

        \[\leadsto \left|\frac{\color{blue}{\sin th \cdot \sin ky}}{\sin kx}\right| \]
      5. associate-*l/32.6%

        \[\leadsto \left|\color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky}\right| \]
    7. Simplified32.6%

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

    if -0.92000000000000004 < (sin.f64 kx) < -0.88500000000000001

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt0.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod5.0%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow25.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr53.3%

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

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square3.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified75.6%

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

    if -0.88500000000000001 < (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.4%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. clear-num18.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky}}} \cdot \sin th \]
      2. associate-/r/18.9%

        \[\leadsto \color{blue}{\left(\frac{1}{\sin kx} \cdot \sin ky\right)} \cdot \sin th \]
    5. Applied egg-rr18.9%

      \[\leadsto \color{blue}{\left(\frac{1}{\sin kx} \cdot \sin ky\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt17.8%

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

        \[\leadsto \color{blue}{\sqrt{\left(\left(\frac{1}{\sin kx} \cdot \sin ky\right) \cdot \sin th\right) \cdot \left(\left(\frac{1}{\sin kx} \cdot \sin ky\right) \cdot \sin th\right)}} \]
      3. pow231.0%

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

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

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{\frac{1 \cdot \sin ky}{\sin kx}}\right)}^{2}} \]
      6. *-un-lft-identity31.0%

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

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

        \[\leadsto \sqrt{\color{blue}{\left(\sin th \cdot \frac{\sin ky}{\sin kx}\right) \cdot \left(\sin th \cdot \frac{\sin ky}{\sin kx}\right)}} \]
      2. rem-sqrt-square38.5%

        \[\leadsto \color{blue}{\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|} \]
    9. Simplified38.5%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Taylor expanded in ky around inf 57.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
    5. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sin kx} \]
      2. associate-*l/57.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    6. Simplified57.0%

      \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
  3. Recombined 5 regimes into one program.
  4. Final simplification45.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.92:\\ \;\;\;\;\left|\sin ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq -0.885:\\ \;\;\;\;\frac{ky \cdot \left|\sin th\right|}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 45.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.01:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-17}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.01)
   (fabs (sin th))
   (if (<= (sin ky) 5e-17)
     (* (sin th) (fabs (/ (sin ky) (sin kx))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.01) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 5e-17) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.01d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 5d-17) then
        tmp = sin(th) * abs((sin(ky) / sin(kx)))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.01) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 5e-17) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.01:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 5e-17:
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.01)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-17)
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.01)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-17)
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.01], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-17], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.01:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-17}:\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.0100000000000000002

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod29.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow229.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr29.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow229.7%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square34.7%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified34.7%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.0100000000000000002 < (sin.f64 ky) < 4.9999999999999999e-17

    1. Initial program 87.9%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. add-sqr-sqrt23.1%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}\right)} \cdot \sin th \]
      2. sqrt-unprod36.4%

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow236.4%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin ky}{\sin kx}\right)}^{2}}} \cdot \sin th \]
    6. Step-by-step derivation
      1. unpow236.4%

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      2. rem-sqrt-square44.5%

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    7. Simplified44.5%

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

    if 4.9999999999999999e-17 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification47.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.01:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-17}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 43.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.02)
   (fabs (* (sin th) (/ ky (sin kx))))
   (if (<= (sin kx) 2e-38) (sin th) (* (sin th) (/ (sin ky) (sin kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.02) {
		tmp = fabs((sin(th) * (ky / sin(kx))));
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (sin(ky) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.02d0)) then
        tmp = abs((sin(th) * (ky / sin(kx))))
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = sin(th) * (sin(ky) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.02) {
		tmp = Math.abs((Math.sin(th) * (ky / Math.sin(kx))));
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.02:
		tmp = math.fabs((math.sin(th) * (ky / math.sin(kx))))
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.02)
		tmp = abs(Float64(sin(th) * Float64(ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.02)
		tmp = abs((sin(th) * (ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = sin(th) * (sin(ky) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.3%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.3%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt16.4%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx}} \cdot \sqrt{\frac{ky \cdot \sin th}{\sin kx}}} \]
      2. sqrt-unprod27.6%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      3. pow227.6%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}^{2}}} \]
      4. *-commutative27.6%

        \[\leadsto \sqrt{{\left(\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}\right)}^{2}} \]
      5. *-un-lft-identity27.6%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{1} \cdot \frac{ky}{\sin kx}\right)}}^{2}} \]
      7. /-rgt-identity27.5%

        \[\leadsto \sqrt{{\left(\color{blue}{\sin th} \cdot \frac{ky}{\sin kx}\right)}^{2}} \]
    7. Applied egg-rr27.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin th \cdot \frac{ky}{\sin kx}\right)}^{2}}} \]
    8. Step-by-step derivation
      1. *-commutative27.5%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      3. unpow227.6%

        \[\leadsto \sqrt{\color{blue}{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      4. rem-sqrt-square33.6%

        \[\leadsto \color{blue}{\left|\frac{ky \cdot \sin th}{\sin kx}\right|} \]
      5. associate-*l/33.5%

        \[\leadsto \left|\color{blue}{\frac{ky}{\sin kx} \cdot \sin th}\right| \]
      6. *-commutative33.5%

        \[\leadsto \left|\color{blue}{\sin th \cdot \frac{ky}{\sin kx}}\right| \]
    9. Simplified33.5%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
  3. Recombined 3 regimes into one program.
  4. Final simplification43.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 43.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.02)
   (fabs (* (sin th) (/ ky (sin kx))))
   (if (<= (sin kx) 2e-38) (sin th) (* (sin ky) (/ (sin th) (sin kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.02) {
		tmp = fabs((sin(th) * (ky / sin(kx))));
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = sin(ky) * (sin(th) / sin(kx));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.02d0)) then
        tmp = abs((sin(th) * (ky / sin(kx))))
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = sin(ky) * (sin(th) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.02) {
		tmp = Math.abs((Math.sin(th) * (ky / Math.sin(kx))));
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.02:
		tmp = math.fabs((math.sin(th) * (ky / math.sin(kx))))
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.02)
		tmp = abs(Float64(sin(th) * Float64(ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.02)
		tmp = abs((sin(th) * (ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = sin(ky) * (sin(th) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.3%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.3%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt16.4%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx}} \cdot \sqrt{\frac{ky \cdot \sin th}{\sin kx}}} \]
      2. sqrt-unprod27.6%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      3. pow227.6%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}^{2}}} \]
      4. *-commutative27.6%

        \[\leadsto \sqrt{{\left(\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}\right)}^{2}} \]
      5. *-un-lft-identity27.6%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{1} \cdot \frac{ky}{\sin kx}\right)}}^{2}} \]
      7. /-rgt-identity27.5%

        \[\leadsto \sqrt{{\left(\color{blue}{\sin th} \cdot \frac{ky}{\sin kx}\right)}^{2}} \]
    7. Applied egg-rr27.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin th \cdot \frac{ky}{\sin kx}\right)}^{2}}} \]
    8. Step-by-step derivation
      1. *-commutative27.5%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      3. unpow227.6%

        \[\leadsto \sqrt{\color{blue}{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      4. rem-sqrt-square33.6%

        \[\leadsto \color{blue}{\left|\frac{ky \cdot \sin th}{\sin kx}\right|} \]
      5. associate-*l/33.5%

        \[\leadsto \left|\color{blue}{\frac{ky}{\sin kx} \cdot \sin th}\right| \]
      6. *-commutative33.5%

        \[\leadsto \left|\color{blue}{\sin th \cdot \frac{ky}{\sin kx}}\right| \]
    9. Simplified33.5%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Taylor expanded in ky around inf 57.0%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
    5. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\color{blue}{\sin th \cdot \sin ky}}{\sin kx} \]
      2. associate-*l/57.0%

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
    6. Simplified57.0%

      \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot \sin ky} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification43.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 99.7% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
    3. neg-mul-194.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
    11. neg-mul-194.0%

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
    12. associate-/r*94.0%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
    13. associate-/r/94.1%

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

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

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

Alternative 9: 45.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky} + \left(0.25 \cdot \left(kx \cdot ky\right) + 0.5 \cdot \frac{ky}{kx}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.25)
   (fabs (sin th))
   (if (<= (sin ky) 2e-140)
     (/ (sin th) (+ (/ (sin kx) ky) (+ (* 0.25 (* kx ky)) (* 0.5 (/ ky kx)))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.25) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 2e-140) {
		tmp = sin(th) / ((sin(kx) / ky) + ((0.25 * (kx * ky)) + (0.5 * (ky / kx))));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.25d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 2d-140) then
        tmp = sin(th) / ((sin(kx) / ky) + ((0.25d0 * (kx * ky)) + (0.5d0 * (ky / kx))))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.25) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 2e-140) {
		tmp = Math.sin(th) / ((Math.sin(kx) / ky) + ((0.25 * (kx * ky)) + (0.5 * (ky / kx))));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.25:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 2e-140:
		tmp = math.sin(th) / ((math.sin(kx) / ky) + ((0.25 * (kx * ky)) + (0.5 * (ky / kx))))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = Float64(sin(th) / Float64(Float64(sin(kx) / ky) + Float64(Float64(0.25 * Float64(kx * ky)) + Float64(0.5 * Float64(ky / kx)))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = sin(th) / ((sin(kx) / ky) + ((0.25 * (kx * ky)) + (0.5 * (ky / kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.25], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-140], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision] + N[(N[(0.25 * N[(kx * ky), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(ky / kx), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.25:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\
\;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky} + \left(0.25 \cdot \left(kx \cdot ky\right) + 0.5 \cdot \frac{ky}{kx}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.25

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod28.8%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow228.8%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr28.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow228.8%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square34.4%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified34.4%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.25 < (sin.f64 ky) < 2e-140

    1. Initial program 86.4%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-186.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-186.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*86.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/86.4%

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      3. un-div-inv99.7%

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

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

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

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

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

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

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

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

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

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

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

    if 2e-140 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification45.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky} + \left(0.25 \cdot \left(kx \cdot ky\right) + 0.5 \cdot \frac{ky}{kx}\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 46.6% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.25)
   (fabs (sin th))
   (if (<= (sin ky) 2e-140)
     (/ (sin th) (+ (/ (* ky 0.5) kx) (/ (sin kx) ky)))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.25) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 2e-140) {
		tmp = sin(th) / (((ky * 0.5) / kx) + (sin(kx) / ky));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.25d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 2d-140) then
        tmp = sin(th) / (((ky * 0.5d0) / kx) + (sin(kx) / ky))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.25) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 2e-140) {
		tmp = Math.sin(th) / (((ky * 0.5) / kx) + (Math.sin(kx) / ky));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.25:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 2e-140:
		tmp = math.sin(th) / (((ky * 0.5) / kx) + (math.sin(kx) / ky))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = Float64(sin(th) / Float64(Float64(Float64(ky * 0.5) / kx) + Float64(sin(kx) / ky)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = sin(th) / (((ky * 0.5) / kx) + (sin(kx) / ky));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.25], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-140], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(ky * 0.5), $MachinePrecision] / kx), $MachinePrecision] + N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.25:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\
\;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.25

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod28.8%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow228.8%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr28.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow228.8%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square34.4%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified34.4%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.25 < (sin.f64 ky) < 2e-140

    1. Initial program 86.4%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-186.4%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-186.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*86.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/86.4%

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      3. un-div-inv99.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin th}{\color{blue}{0.5 \cdot \frac{ky}{kx}} + \frac{\sin kx}{ky}} \]
    9. Step-by-step derivation
      1. associate-*r/43.5%

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{0.5 \cdot ky}{kx}} + \frac{\sin kx}{ky}} \]
    10. Simplified43.5%

      \[\leadsto \frac{\sin th}{\color{blue}{\frac{0.5 \cdot ky}{kx}} + \frac{\sin kx}{ky}} \]

    if 2e-140 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification47.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 41.7% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.02)
   (fabs (* (sin th) (/ ky (sin kx))))
   (if (<= (sin kx) 2e-38)
     (sin th)
     (/ (sin th) (+ (/ (* ky 0.5) kx) (/ (sin kx) ky))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.02) {
		tmp = fabs((sin(th) * (ky / sin(kx))));
	} else if (sin(kx) <= 2e-38) {
		tmp = sin(th);
	} else {
		tmp = sin(th) / (((ky * 0.5) / kx) + (sin(kx) / ky));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.02d0)) then
        tmp = abs((sin(th) * (ky / sin(kx))))
    else if (sin(kx) <= 2d-38) then
        tmp = sin(th)
    else
        tmp = sin(th) / (((ky * 0.5d0) / kx) + (sin(kx) / ky))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(kx) <= -0.02) {
		tmp = Math.abs((Math.sin(th) * (ky / Math.sin(kx))));
	} else if (Math.sin(kx) <= 2e-38) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(th) / (((ky * 0.5) / kx) + (Math.sin(kx) / ky));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.02:
		tmp = math.fabs((math.sin(th) * (ky / math.sin(kx))))
	elif math.sin(kx) <= 2e-38:
		tmp = math.sin(th)
	else:
		tmp = math.sin(th) / (((ky * 0.5) / kx) + (math.sin(kx) / ky))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.02)
		tmp = abs(Float64(sin(th) * Float64(ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) / Float64(Float64(Float64(ky * 0.5) / kx) + Float64(sin(kx) / ky)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.02)
		tmp = abs((sin(th) * (ky / sin(kx))));
	elseif (sin(kx) <= 2e-38)
		tmp = sin(th);
	else
		tmp = sin(th) / (((ky * 0.5) / kx) + (sin(kx) / ky));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[kx], $MachinePrecision], -0.02], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-38], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] / N[(N[(N[(ky * 0.5), $MachinePrecision] / kx), $MachinePrecision] + N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.02:\\
\;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -0.0200000000000000004

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.3%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.3%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.3%

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt16.4%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx}} \cdot \sqrt{\frac{ky \cdot \sin th}{\sin kx}}} \]
      2. sqrt-unprod27.6%

        \[\leadsto \color{blue}{\sqrt{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      3. pow227.6%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}^{2}}} \]
      4. *-commutative27.6%

        \[\leadsto \sqrt{{\left(\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}\right)}^{2}} \]
      5. *-un-lft-identity27.6%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin th}{1} \cdot \frac{ky}{\sin kx}\right)}}^{2}} \]
      7. /-rgt-identity27.5%

        \[\leadsto \sqrt{{\left(\color{blue}{\sin th} \cdot \frac{ky}{\sin kx}\right)}^{2}} \]
    7. Applied egg-rr27.5%

      \[\leadsto \color{blue}{\sqrt{{\left(\sin th \cdot \frac{ky}{\sin kx}\right)}^{2}}} \]
    8. Step-by-step derivation
      1. *-commutative27.5%

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

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      3. unpow227.6%

        \[\leadsto \sqrt{\color{blue}{\frac{ky \cdot \sin th}{\sin kx} \cdot \frac{ky \cdot \sin th}{\sin kx}}} \]
      4. rem-sqrt-square33.6%

        \[\leadsto \color{blue}{\left|\frac{ky \cdot \sin th}{\sin kx}\right|} \]
      5. associate-*l/33.5%

        \[\leadsto \left|\color{blue}{\frac{ky}{\sin kx} \cdot \sin th}\right| \]
      6. *-commutative33.5%

        \[\leadsto \left|\color{blue}{\sin th \cdot \frac{ky}{\sin kx}}\right| \]
    9. Simplified33.5%

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

    if -0.0200000000000000004 < (sin.f64 kx) < 1.9999999999999999e-38

    1. Initial program 88.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-188.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-188.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*88.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/88.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]

    if 1.9999999999999999e-38 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.5%

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      3. un-div-inv99.6%

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

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

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{{\sin ky}^{2} + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
      7. +-commutative99.6%

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
      8. unpow299.6%

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}{\sin ky}} \]
      10. hypot-def99.6%

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

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

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

      \[\leadsto \frac{\sin th}{\color{blue}{0.5 \cdot \frac{ky}{kx}} + \frac{\sin kx}{ky}} \]
    9. Step-by-step derivation
      1. associate-*r/48.9%

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{0.5 \cdot ky}{kx}} + \frac{\sin kx}{ky}} \]
    10. Simplified48.9%

      \[\leadsto \frac{\sin th}{\color{blue}{\frac{0.5 \cdot ky}{kx}} + \frac{\sin kx}{ky}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.02:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-38}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{\frac{ky \cdot 0.5}{kx} + \frac{\sin kx}{ky}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 56.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 0.024:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;th \leq 5.5 \cdot 10^{+92} \lor \neg \left(th \leq 1.05 \cdot 10^{+99}\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= th 0.024)
   (* th (/ (sin ky) (hypot (sin ky) (sin kx))))
   (if (or (<= th 5.5e+92) (not (<= th 1.05e+99)))
     (* (sin th) (fabs (/ (sin ky) (sin kx))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 0.024) {
		tmp = th * (sin(ky) / hypot(sin(ky), sin(kx)));
	} else if ((th <= 5.5e+92) || !(th <= 1.05e+99)) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 0.024) {
		tmp = th * (Math.sin(ky) / Math.hypot(Math.sin(ky), Math.sin(kx)));
	} else if ((th <= 5.5e+92) || !(th <= 1.05e+99)) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if th <= 0.024:
		tmp = th * (math.sin(ky) / math.hypot(math.sin(ky), math.sin(kx)))
	elif (th <= 5.5e+92) or not (th <= 1.05e+99):
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (th <= 0.024)
		tmp = Float64(th * Float64(sin(ky) / hypot(sin(ky), sin(kx))));
	elseif ((th <= 5.5e+92) || !(th <= 1.05e+99))
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (th <= 0.024)
		tmp = th * (sin(ky) / hypot(sin(ky), sin(kx)));
	elseif ((th <= 5.5e+92) || ~((th <= 1.05e+99)))
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[th, 0.024], N[(th * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 5.5e+92], N[Not[LessEqual[th, 1.05e+99]], $MachinePrecision]], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;th \leq 5.5 \cdot 10^{+92} \lor \neg \left(th \leq 1.05 \cdot 10^{+99}\right):\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


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

    1. Initial program 94.1%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-194.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-194.0%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*94.0%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/94.1%

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

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

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

    if 0.024 < th < 5.50000000000000053e92 or 1.05000000000000005e99 < th

    1. Initial program 93.9%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. add-sqr-sqrt13.0%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}\right)} \cdot \sin th \]
      2. sqrt-unprod14.5%

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow214.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      2. rem-sqrt-square19.9%

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    7. Simplified19.9%

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

    if 5.50000000000000053e92 < th < 1.05000000000000005e99

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-1100.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.2%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/100.0%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 0.024:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;th \leq 5.5 \cdot 10^{+92} \lor \neg \left(th \leq 1.05 \cdot 10^{+99}\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 56.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 0.023:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\ \mathbf{elif}\;th \leq 7.3 \cdot 10^{+93} \lor \neg \left(th \leq 1.1 \cdot 10^{+99}\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= th 0.023)
   (/ th (/ (hypot (sin kx) (sin ky)) (sin ky)))
   (if (or (<= th 7.3e+93) (not (<= th 1.1e+99)))
     (* (sin th) (fabs (/ (sin ky) (sin kx))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 0.023) {
		tmp = th / (hypot(sin(kx), sin(ky)) / sin(ky));
	} else if ((th <= 7.3e+93) || !(th <= 1.1e+99)) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 0.023) {
		tmp = th / (Math.hypot(Math.sin(kx), Math.sin(ky)) / Math.sin(ky));
	} else if ((th <= 7.3e+93) || !(th <= 1.1e+99)) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if th <= 0.023:
		tmp = th / (math.hypot(math.sin(kx), math.sin(ky)) / math.sin(ky))
	elif (th <= 7.3e+93) or not (th <= 1.1e+99):
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (th <= 0.023)
		tmp = Float64(th / Float64(hypot(sin(kx), sin(ky)) / sin(ky)));
	elseif ((th <= 7.3e+93) || !(th <= 1.1e+99))
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (th <= 0.023)
		tmp = th / (hypot(sin(kx), sin(ky)) / sin(ky));
	elseif ((th <= 7.3e+93) || ~((th <= 1.1e+99)))
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[th, 0.023], N[(th / N[(N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.3e+93], N[Not[LessEqual[th, 1.1e+99]], $MachinePrecision]], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 0.023:\\
\;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\

\mathbf{elif}\;th \leq 7.3 \cdot 10^{+93} \lor \neg \left(th \leq 1.1 \cdot 10^{+99}\right):\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


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

    1. Initial program 94.1%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-194.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-194.0%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*94.0%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/94.1%

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      3. un-div-inv99.7%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      4. hypot-udef94.1%

        \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
      5. unpow294.1%

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{{\sin ky}^{2} + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
      7. +-commutative94.1%

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
      8. unpow294.1%

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

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

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

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

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

    if 0.023 < th < 7.30000000000000026e93 or 1.09999999999999989e99 < th

    1. Initial program 93.9%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. add-sqr-sqrt13.0%

        \[\leadsto \color{blue}{\left(\sqrt{\frac{\sin ky}{\sin kx}} \cdot \sqrt{\frac{\sin ky}{\sin kx}}\right)} \cdot \sin th \]
      2. sqrt-unprod14.5%

        \[\leadsto \color{blue}{\sqrt{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      3. pow214.5%

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

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

        \[\leadsto \sqrt{\color{blue}{\frac{\sin ky}{\sin kx} \cdot \frac{\sin ky}{\sin kx}}} \cdot \sin th \]
      2. rem-sqrt-square19.9%

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    7. Simplified19.9%

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

    if 7.30000000000000026e93 < th < 1.09999999999999989e99

    1. Initial program 100.0%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-1100.0%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.2%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/100.0%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification59.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 0.023:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\ \mathbf{elif}\;th \leq 7.3 \cdot 10^{+93} \lor \neg \left(th \leq 1.1 \cdot 10^{+99}\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 40.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-161}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.25)
   (fabs (sin th))
   (if (<= (sin ky) 1e-161) (* (sin ky) (/ (sin th) kx)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.25) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 1e-161) {
		tmp = sin(ky) * (sin(th) / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.25d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 1d-161) then
        tmp = sin(ky) * (sin(th) / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.25) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 1e-161) {
		tmp = Math.sin(ky) * (Math.sin(th) / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.25:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 1e-161:
		tmp = math.sin(ky) * (math.sin(th) / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-161)
		tmp = Float64(sin(ky) * Float64(sin(th) / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.25)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-161)
		tmp = sin(ky) * (sin(th) / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.25], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-161], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.25:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 10^{-161}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.25

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod28.8%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow228.8%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr28.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow228.8%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square34.4%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified34.4%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.25 < (sin.f64 ky) < 1.00000000000000003e-161

    1. Initial program 85.6%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{kx}} \]
    5. Step-by-step derivation
      1. expm1-log1p-u28.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot \sin th}{kx}\right)\right)} \]
      2. expm1-udef18.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot \sin th}{kx}\right)} - 1} \]
      3. associate-/l*18.2%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}}\right)} - 1 \]
    6. Applied egg-rr18.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\frac{kx}{\sin th}}\right)} - 1} \]
    7. Step-by-step derivation
      1. expm1-def29.0%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky}{\frac{kx}{\sin th}}\right)\right)} \]
      2. expm1-log1p29.3%

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}} \]
      3. associate-/r/29.3%

        \[\leadsto \color{blue}{\frac{\sin ky}{kx} \cdot \sin th} \]
      4. *-commutative29.3%

        \[\leadsto \color{blue}{\sin th \cdot \frac{\sin ky}{kx}} \]
      5. associate-*r/28.6%

        \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{kx}} \]
      6. *-commutative28.6%

        \[\leadsto \frac{\color{blue}{\sin ky \cdot \sin th}}{kx} \]
      7. associate-*r/29.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
    8. Simplified29.3%

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

    if 1.00000000000000003e-161 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.25:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-161}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 47.4% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.05)
   (fabs (sin th))
   (if (<= (sin ky) 2e-140) (* (sin th) (/ ky (sin kx))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.05) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 2e-140) {
		tmp = sin(th) * (ky / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.05d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 2d-140) then
        tmp = sin(th) * (ky / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.05) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 2e-140) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.05:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 2e-140:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.05)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.05)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 2e-140)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.05], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-140], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.05:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.050000000000000003

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod30.1%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow230.1%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr30.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow230.1%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square35.2%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified35.2%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.050000000000000003 < (sin.f64 ky) < 2e-140

    1. Initial program 85.7%

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

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

    if 2e-140 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification47.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.05:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-140}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 16: 63.2% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\
\mathbf{if}\;th \leq 3.8 \cdot 10^{-5}:\\
\;\;\;\;\frac{th}{\frac{t\_1}{\sin ky}}\\

\mathbf{else}:\\
\;\;\;\;\frac{\sin th \cdot ky}{t\_1}\\


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

    1. Initial program 94.1%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-194.1%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-194.0%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*94.0%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/94.1%

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      3. un-div-inv99.7%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}} \]
      4. hypot-udef94.1%

        \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{\sin ky \cdot \sin ky + \sin kx \cdot \sin kx}}}{\sin ky}} \]
      5. unpow294.1%

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{{\sin ky}^{2} + \color{blue}{{\sin kx}^{2}}}}{\sin ky}} \]
      7. +-commutative94.1%

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
      8. unpow294.1%

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

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

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

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

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

    if 3.8000000000000002e-5 < th

    1. Initial program 94.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-194.3%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-194.2%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*94.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/94.3%

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 3.8 \cdot 10^{-5}:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin ky}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 40.9% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.075:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-161}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.075)
   (fabs (sin th))
   (if (<= (sin ky) 1e-161) (* (sin th) (/ ky kx)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.075) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 1e-161) {
		tmp = sin(th) * (ky / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-0.075d0)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 1d-161) then
        tmp = sin(th) * (ky / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.075) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 1e-161) {
		tmp = Math.sin(th) * (ky / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.075:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 1e-161:
		tmp = math.sin(th) * (ky / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.075)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-161)
		tmp = Float64(sin(th) * Float64(ky / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.075)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 1e-161)
		tmp = sin(th) * (ky / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.075], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-161], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.075:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 10^{-161}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -0.0749999999999999972

    1. Initial program 99.6%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.6%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.6%

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      2. sqrt-unprod30.4%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow230.4%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr30.4%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow230.4%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square35.6%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    9. Simplified35.6%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]

    if -0.0749999999999999972 < (sin.f64 ky) < 1.00000000000000003e-161

    1. Initial program 85.0%

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    6. Step-by-step derivation
      1. associate-/l*30.3%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    7. Simplified30.3%

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    8. Step-by-step derivation
      1. associate-/r/30.3%

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot \sin th} \]
    9. Applied egg-rr30.3%

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

    if 1.00000000000000003e-161 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.7%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.6%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.6%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.7%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification42.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.075:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-161}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 27.0% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.2 \cdot 10^{-160}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.2e-160) (* (sin th) (/ ky kx)) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.2e-160) {
		tmp = sin(th) * (ky / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.2d-160) then
        tmp = sin(th) * (ky / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.2e-160) {
		tmp = Math.sin(th) * (ky / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.2e-160:
		tmp = math.sin(th) * (ky / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.2e-160)
		tmp = Float64(sin(th) * Float64(ky / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.2e-160)
		tmp = sin(th) * (ky / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.2e-160], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.2 \cdot 10^{-160}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

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


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

    1. Initial program 91.3%

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    6. Step-by-step derivation
      1. associate-/l*18.6%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    7. Simplified18.6%

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    8. Step-by-step derivation
      1. associate-/r/18.5%

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot \sin th} \]
    9. Applied egg-rr18.5%

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

    if 1.19999999999999995e-160 < ky

    1. Initial program 99.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification24.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.2 \cdot 10^{-160}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 24.8% accurate, 6.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8.6 \cdot 10^{-161}:\\ \;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 8.6e-161)
   (/ ky (+ (* 0.16666666666666666 (* th kx)) (/ kx th)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8.6e-161) {
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 8.6d-161) then
        tmp = ky / ((0.16666666666666666d0 * (th * kx)) + (kx / th))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8.6e-161) {
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 8.6e-161:
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 8.6e-161)
		tmp = Float64(ky / Float64(Float64(0.16666666666666666 * Float64(th * kx)) + Float64(kx / th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 8.6e-161)
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 8.6e-161], N[(ky / N[(N[(0.16666666666666666 * N[(th * kx), $MachinePrecision]), $MachinePrecision] + N[(kx / th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 8.6 \cdot 10^{-161}:\\
\;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\

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


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

    1. Initial program 91.3%

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    6. Step-by-step derivation
      1. associate-/l*18.6%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    7. Simplified18.6%

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

      \[\leadsto \frac{ky}{\color{blue}{0.16666666666666666 \cdot \left(kx \cdot th\right) + \frac{kx}{th}}} \]

    if 8.59999999999999933e-161 < ky

    1. Initial program 99.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.8%

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

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

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification21.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 8.6 \cdot 10^{-161}:\\ \;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 18.7% accurate, 44.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\ \;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 2.6e-76)
   (/ ky (+ (* 0.16666666666666666 (* th kx)) (/ kx th)))
   th))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-76) {
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	} else {
		tmp = th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 2.6d-76) then
        tmp = ky / ((0.16666666666666666d0 * (th * kx)) + (kx / th))
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-76) {
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 2.6e-76:
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th))
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 2.6e-76)
		tmp = Float64(ky / Float64(Float64(0.16666666666666666 * Float64(th * kx)) + Float64(kx / th)));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 2.6e-76)
		tmp = ky / ((0.16666666666666666 * (th * kx)) + (kx / th));
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 2.6e-76], N[(ky / N[(N[(0.16666666666666666 * N[(th * kx), $MachinePrecision]), $MachinePrecision] + N[(kx / th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], th]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\
\;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\

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


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

    1. Initial program 92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    6. Step-by-step derivation
      1. associate-/l*18.9%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    7. Simplified18.9%

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

      \[\leadsto \frac{ky}{\color{blue}{0.16666666666666666 \cdot \left(kx \cdot th\right) + \frac{kx}{th}}} \]

    if 2.6e-76 < ky

    1. Initial program 99.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.8%

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

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

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

      \[\leadsto \color{blue}{th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\ \;\;\;\;\frac{ky}{0.16666666666666666 \cdot \left(th \cdot kx\right) + \frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 18.4% accurate, 70.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 2.6e-76) (/ ky (/ kx th)) th))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-76) {
		tmp = ky / (kx / th);
	} else {
		tmp = th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 2.6d-76) then
        tmp = ky / (kx / th)
    else
        tmp = th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 2.6e-76) {
		tmp = ky / (kx / th);
	} else {
		tmp = th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 2.6e-76:
		tmp = ky / (kx / th)
	else:
		tmp = th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 2.6e-76)
		tmp = Float64(ky / Float64(kx / th));
	else
		tmp = th;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 2.6e-76)
		tmp = ky / (kx / th);
	else
		tmp = th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 2.6e-76], N[(ky / N[(kx / th), $MachinePrecision]), $MachinePrecision], th]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\
\;\;\;\;\frac{ky}{\frac{kx}{th}}\\

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


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

    1. Initial program 92.1%

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    6. Step-by-step derivation
      1. associate-/l*18.9%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{\sin th}}} \]
    7. Simplified18.9%

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

      \[\leadsto \color{blue}{\frac{ky \cdot th}{kx}} \]
    9. Step-by-step derivation
      1. associate-/l*14.0%

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified14.0%

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]

    if 2.6e-76 < ky

    1. Initial program 99.8%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
      3. neg-mul-199.8%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
      11. neg-mul-199.5%

        \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
      12. associate-/r*99.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/99.8%

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

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

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

      \[\leadsto \color{blue}{th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 2.6 \cdot 10^{-76}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]
  5. Add Preprocessing

Alternative 22: 14.4% accurate, 709.0× speedup?

\[\begin{array}{l} \\ th \end{array} \]
(FPCore (kx ky th) :precision binary64 th)
double code(double kx, double ky, double th) {
	return th;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = th
end function
public static double code(double kx, double ky, double th) {
	return th;
}
def code(kx, ky, th):
	return th
function code(kx, ky, th)
	return th
end
function tmp = code(kx, ky, th)
	tmp = th;
end
code[kx_, ky_, th_] := th
\begin{array}{l}

\\
th
\end{array}
Derivation
  1. Initial program 94.1%

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \left(-\color{blue}{\sin \left(-th\right)}\right) \]
    3. neg-mul-194.1%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-\sin th}}} \]
    11. neg-mul-194.0%

      \[\leadsto \frac{\sin ky}{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{\color{blue}{-1 \cdot \sin th}}} \]
    12. associate-/r*94.0%

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
    13. associate-/r/94.1%

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

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

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

    \[\leadsto \color{blue}{th} \]
  7. Final simplification17.5%

    \[\leadsto th \]
  8. Add Preprocessing

Reproduce

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