Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.5% → 99.6%
Time: 12.6s
Alternatives: 20
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 20 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.5% 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.0× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky\_m}{\mathsf{hypot}\left(\sin ky\_m, \sin kx\right)}\right)\right) \cdot \sin th\right) \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (* (expm1 (log1p (/ (sin ky_m) (hypot (sin ky_m) (sin kx))))) (sin th))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * (expm1(log1p((sin(ky_m) / hypot(sin(ky_m), sin(kx))))) * sin(th));
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * (Math.expm1(Math.log1p((Math.sin(ky_m) / Math.hypot(Math.sin(ky_m), Math.sin(kx))))) * Math.sin(th));
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	return ky_s * (math.expm1(math.log1p((math.sin(ky_m) / math.hypot(math.sin(ky_m), math.sin(kx))))) * math.sin(th))
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	return Float64(ky_s * Float64(expm1(log1p(Float64(sin(ky_m) / hypot(sin(ky_m), sin(kx))))) * sin(th)))
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * N[(N[(Exp[N[Log[1 + N[(N[Sin[ky$95$m], $MachinePrecision] / N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. expm1-log1p-u91.4%

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}\right)\right) \cdot \sin th \]
    3. unpow291.4%

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

      \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}\right)\right) \cdot \sin th \]
    5. hypot-undefine99.7%

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

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

Alternative 2: 76.3% accurate, 1.2× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\sin ky\_m \cdot \frac{th}{\mathsf{hypot}\left(\sin ky\_m, \sin kx\right)}\\ \mathbf{elif}\;\sin ky\_m \leq 2 \cdot 10^{-7}:\\ \;\;\;\;\sin ky\_m \cdot \frac{\sin th}{\mathsf{hypot}\left(ky\_m, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (* (sin ky_m) (/ th (hypot (sin ky_m) (sin kx))))
    (if (<= (sin ky_m) 2e-7)
      (* (sin ky_m) (/ (sin th) (hypot ky_m (sin kx))))
      (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = sin(ky_m) * (th / hypot(sin(ky_m), sin(kx)));
	} else if (sin(ky_m) <= 2e-7) {
		tmp = sin(ky_m) * (sin(th) / hypot(ky_m, sin(kx)));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.sin(ky_m) * (th / Math.hypot(Math.sin(ky_m), Math.sin(kx)));
	} else if (Math.sin(ky_m) <= 2e-7) {
		tmp = Math.sin(ky_m) * (Math.sin(th) / Math.hypot(ky_m, Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.sin(ky_m) * (th / math.hypot(math.sin(ky_m), math.sin(kx)))
	elif math.sin(ky_m) <= 2e-7:
		tmp = math.sin(ky_m) * (math.sin(th) / math.hypot(ky_m, math.sin(kx)))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = Float64(sin(ky_m) * Float64(th / hypot(sin(ky_m), sin(kx))));
	elseif (sin(ky_m) <= 2e-7)
		tmp = Float64(sin(ky_m) * Float64(sin(th) / hypot(ky_m, sin(kx))));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = sin(ky_m) * (th / hypot(sin(ky_m), sin(kx)));
	elseif (sin(ky_m) <= 2e-7)
		tmp = sin(ky_m) * (sin(th) / hypot(ky_m, sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[(N[Sin[ky$95$m], $MachinePrecision] * N[(th / N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 2e-7], N[(N[Sin[ky$95$m], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[ky$95$m ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

\mathbf{elif}\;\sin ky\_m \leq 2 \cdot 10^{-7}:\\
\;\;\;\;\sin ky\_m \cdot \frac{\sin th}{\mathsf{hypot}\left(ky\_m, \sin kx\right)}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.9999999999999999e-7

    1. Initial program 84.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-7 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 3: 57.2% accurate, 1.2× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\frac{\sin ky\_m}{\frac{\mathsf{hypot}\left(\sin ky\_m, kx\right)}{th}}\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\left|\sin kx\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (/ (sin ky_m) (/ (hypot (sin ky_m) kx) th))
    (if (<= (sin ky_m) 1e-94)
      (* (sin th) (/ (sin ky_m) (fabs (sin kx))))
      (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	} else if (sin(ky_m) <= 1e-94) {
		tmp = sin(th) * (sin(ky_m) / fabs(sin(kx)));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.sin(ky_m) / (Math.hypot(Math.sin(ky_m), kx) / th);
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = Math.sin(th) * (Math.sin(ky_m) / Math.abs(Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.sin(ky_m) / (math.hypot(math.sin(ky_m), kx) / th)
	elif math.sin(ky_m) <= 1e-94:
		tmp = math.sin(th) * (math.sin(ky_m) / math.fabs(math.sin(kx)))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = Float64(sin(ky_m) / Float64(hypot(sin(ky_m), kx) / th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = Float64(sin(th) * Float64(sin(ky_m) / abs(sin(kx))));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	elseif (sin(ky_m) <= 1e-94)
		tmp = sin(th) * (sin(ky_m) / abs(sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[(N[Sin[ky$95$m], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky$95$m], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 82.6%

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      3. rem-sqrt-square74.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr74.3%

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 56.9% accurate, 1.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\frac{\sin ky\_m}{\frac{\mathsf{hypot}\left(\sin ky\_m, kx\right)}{th}}\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;\frac{1}{\frac{\frac{\left|\sin kx\right|}{\sin th}}{ky\_m}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (/ (sin ky_m) (/ (hypot (sin ky_m) kx) th))
    (if (<= (sin ky_m) 1e-94)
      (/ 1.0 (/ (/ (fabs (sin kx)) (sin th)) ky_m))
      (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	} else if (sin(ky_m) <= 1e-94) {
		tmp = 1.0 / ((fabs(sin(kx)) / sin(th)) / ky_m);
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.sin(ky_m) / (Math.hypot(Math.sin(ky_m), kx) / th);
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = 1.0 / ((Math.abs(Math.sin(kx)) / Math.sin(th)) / ky_m);
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.sin(ky_m) / (math.hypot(math.sin(ky_m), kx) / th)
	elif math.sin(ky_m) <= 1e-94:
		tmp = 1.0 / ((math.fabs(math.sin(kx)) / math.sin(th)) / ky_m)
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = Float64(sin(ky_m) / Float64(hypot(sin(ky_m), kx) / th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = Float64(1.0 / Float64(Float64(abs(sin(kx)) / sin(th)) / ky_m));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	elseif (sin(ky_m) <= 1e-94)
		tmp = 1.0 / ((abs(sin(kx)) / sin(th)) / ky_m);
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[(N[Sin[ky$95$m], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[(1.0 / N[(N[(N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision] / ky$95$m), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

\mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\
\;\;\;\;\frac{1}{\frac{\frac{\left|\sin kx\right|}{\sin th}}{ky\_m}}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 82.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/42.2%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr41.7%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified43.9%

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      3. rem-sqrt-square74.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    10. Applied egg-rr73.3%

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 46.9% accurate, 1.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq 5 \cdot 10^{-308}:\\ \;\;\;\;\frac{\sin ky\_m}{\frac{\mathsf{hypot}\left(\sin ky\_m, kx\right)}{th}}\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;\left|ky\_m \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) 5e-308)
    (/ (sin ky_m) (/ (hypot (sin ky_m) kx) th))
    (if (<= (sin ky_m) 1e-94)
      (fabs (* ky_m (/ (sin th) (sin kx))))
      (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= 5e-308) {
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	} else if (sin(ky_m) <= 1e-94) {
		tmp = fabs((ky_m * (sin(th) / sin(kx))));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= 5e-308) {
		tmp = Math.sin(ky_m) / (Math.hypot(Math.sin(ky_m), kx) / th);
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = Math.abs((ky_m * (Math.sin(th) / Math.sin(kx))));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= 5e-308:
		tmp = math.sin(ky_m) / (math.hypot(math.sin(ky_m), kx) / th)
	elif math.sin(ky_m) <= 1e-94:
		tmp = math.fabs((ky_m * (math.sin(th) / math.sin(kx))))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= 5e-308)
		tmp = Float64(sin(ky_m) / Float64(hypot(sin(ky_m), kx) / th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = abs(Float64(ky_m * Float64(sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= 5e-308)
		tmp = sin(ky_m) / (hypot(sin(ky_m), kx) / th);
	elseif (sin(ky_m) <= 1e-94)
		tmp = abs((ky_m * (sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 5e-308], N[(N[Sin[ky$95$m], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[Abs[N[(ky$95$m * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;\sin ky\_m \leq 5 \cdot 10^{-308}:\\
\;\;\;\;\frac{\sin ky\_m}{\frac{\mathsf{hypot}\left(\sin ky\_m, kx\right)}{th}}\\

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

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


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

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999955e-308 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 79.3%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/51.6%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr50.5%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified50.4%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt29.7%

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

        \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}} \cdot \frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}}}} \]
      3. pow237.8%

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}}\right)}^{2}}} \]
      4. clear-num37.9%

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{ky \cdot \sin th}{\sin kx}}\right| \]
      4. associate-*r/50.8%

        \[\leadsto \left|\color{blue}{ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    12. Simplified50.8%

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 48.0% accurate, 1.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;\left|ky\_m \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (fabs (sin th))
    (if (<= (sin ky_m) 1e-94)
      (fabs (* ky_m (/ (sin th) (sin kx))))
      (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = fabs(sin(th));
	} else if (sin(ky_m) <= 1e-94) {
		tmp = fabs((ky_m * (sin(th) / sin(kx))));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky_m) <= (-0.02d0)) then
        tmp = abs(sin(th))
    else if (sin(ky_m) <= 1d-94) then
        tmp = abs((ky_m * (sin(th) / sin(kx))))
    else
        tmp = sin(th)
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = Math.abs((ky_m * (Math.sin(th) / Math.sin(kx))));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky_m) <= 1e-94:
		tmp = math.fabs((ky_m * (math.sin(th) / math.sin(kx))))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = abs(Float64(ky_m * Float64(sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = abs((ky_m * (sin(th) / sin(kx))));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[Abs[N[(ky$95$m * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow225.1%

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 82.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/42.2%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr41.7%

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

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

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified43.9%

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

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

        \[\leadsto \color{blue}{\sqrt{\frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}} \cdot \frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}}}} \]
      3. pow229.0%

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{ky \cdot \sin th}{\sin kx}}\right| \]
      4. associate-*r/40.6%

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

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 99.7% accurate, 1.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \left(\frac{\sin ky\_m}{\mathsf{hypot}\left(\sin ky\_m, \sin kx\right)} \cdot \sin th\right) \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (* (/ (sin ky_m) (hypot (sin ky_m) (sin kx))) (sin th))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * ((sin(ky_m) / hypot(sin(ky_m), sin(kx))) * sin(th));
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * ((Math.sin(ky_m) / Math.hypot(Math.sin(ky_m), Math.sin(kx))) * Math.sin(th));
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	return ky_s * ((math.sin(ky_m) / math.hypot(math.sin(ky_m), math.sin(kx))) * math.sin(th))
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	return Float64(ky_s * Float64(Float64(sin(ky_m) / hypot(sin(ky_m), sin(kx))) * sin(th)))
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp = code(ky_s, kx, ky_m, th)
	tmp = ky_s * ((sin(ky_m) / hypot(sin(ky_m), sin(kx))) * sin(th));
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * N[(N[(N[Sin[ky$95$m], $MachinePrecision] / N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. +-commutative91.5%

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

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

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

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

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

Alternative 8: 99.6% accurate, 1.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \left(\sin ky\_m \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky\_m, \sin kx\right)}\right) \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (* (sin ky_m) (/ (sin th) (hypot (sin ky_m) (sin kx))))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * (sin(ky_m) * (sin(th) / hypot(sin(ky_m), sin(kx))));
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * (Math.sin(ky_m) * (Math.sin(th) / Math.hypot(Math.sin(ky_m), Math.sin(kx))));
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	return ky_s * (math.sin(ky_m) * (math.sin(th) / math.hypot(math.sin(ky_m), math.sin(kx))))
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	return Float64(ky_s * Float64(sin(ky_m) * Float64(sin(th) / hypot(sin(ky_m), sin(kx)))))
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp = code(ky_s, kx, ky_m, th)
	tmp = ky_s * (sin(ky_m) * (sin(th) / hypot(sin(ky_m), sin(kx))));
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * N[(N[Sin[ky$95$m], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 59.8% accurate, 1.7× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;th \leq 0.0077:\\ \;\;\;\;\sin ky\_m \cdot \frac{th}{\mathsf{hypot}\left(\sin ky\_m, \sin kx\right)}\\ \mathbf{elif}\;th \leq 3 \cdot 10^{+84}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\left|\sin kx\right|}\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= th 0.0077)
    (* (sin ky_m) (/ th (hypot (sin ky_m) (sin kx))))
    (if (<= th 3e+84) (sin th) (* (sin th) (/ (sin ky_m) (fabs (sin kx))))))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (th <= 0.0077) {
		tmp = sin(ky_m) * (th / hypot(sin(ky_m), sin(kx)));
	} else if (th <= 3e+84) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (sin(ky_m) / fabs(sin(kx)));
	}
	return ky_s * tmp;
}
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (th <= 0.0077) {
		tmp = Math.sin(ky_m) * (th / Math.hypot(Math.sin(ky_m), Math.sin(kx)));
	} else if (th <= 3e+84) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.sin(th) * (Math.sin(ky_m) / Math.abs(Math.sin(kx)));
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if th <= 0.0077:
		tmp = math.sin(ky_m) * (th / math.hypot(math.sin(ky_m), math.sin(kx)))
	elif th <= 3e+84:
		tmp = math.sin(th)
	else:
		tmp = math.sin(th) * (math.sin(ky_m) / math.fabs(math.sin(kx)))
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (th <= 0.0077)
		tmp = Float64(sin(ky_m) * Float64(th / hypot(sin(ky_m), sin(kx))));
	elseif (th <= 3e+84)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(sin(ky_m) / abs(sin(kx))));
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (th <= 0.0077)
		tmp = sin(ky_m) * (th / hypot(sin(ky_m), sin(kx)));
	elseif (th <= 3e+84)
		tmp = sin(th);
	else
		tmp = sin(th) * (sin(ky_m) / abs(sin(kx)));
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[th, 0.0077], N[(N[Sin[ky$95$m], $MachinePrecision] * N[(th / N[Sqrt[N[Sin[ky$95$m], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[th, 3e+84], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky$95$m], $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

\mathbf{elif}\;th \leq 3 \cdot 10^{+84}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\left|\sin kx\right|}\\


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

    1. Initial program 91.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0077000000000000002 < th < 2.99999999999999996e84

    1. Initial program 99.8%

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.99999999999999996e84 < th

    1. Initial program 91.2%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 0.0077:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;th \leq 3 \cdot 10^{+84}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 48.0% accurate, 1.7× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;\sin th \cdot \frac{ky\_m}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (fabs (sin th))
    (if (<= (sin ky_m) 1e-94) (* (sin th) (/ ky_m (sin kx))) (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = fabs(sin(th));
	} else if (sin(ky_m) <= 1e-94) {
		tmp = sin(th) * (ky_m / sin(kx));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky_m) <= (-0.02d0)) then
        tmp = abs(sin(th))
    else if (sin(ky_m) <= 1d-94) then
        tmp = sin(th) * (ky_m / sin(kx))
    else
        tmp = sin(th)
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = Math.sin(th) * (ky_m / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky_m) <= 1e-94:
		tmp = math.sin(th) * (ky_m / math.sin(kx))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = Float64(sin(th) * Float64(ky_m / sin(kx)));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = sin(th) * (ky_m / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[(N[Sin[th], $MachinePrecision] * N[(ky$95$m / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

\mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\
\;\;\;\;\sin th \cdot \frac{ky\_m}{\sin kx}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow225.1%

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 82.6%

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

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 48.0% accurate, 1.7× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;\sin ky\_m \leq -0.02:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\ \;\;\;\;ky\_m \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= (sin ky_m) -0.02)
    (fabs (sin th))
    (if (<= (sin ky_m) 1e-94) (* ky_m (/ (sin th) (sin kx))) (sin th)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (sin(ky_m) <= -0.02) {
		tmp = fabs(sin(th));
	} else if (sin(ky_m) <= 1e-94) {
		tmp = ky_m * (sin(th) / sin(kx));
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky_m) <= (-0.02d0)) then
        tmp = abs(sin(th))
    else if (sin(ky_m) <= 1d-94) then
        tmp = ky_m * (sin(th) / sin(kx))
    else
        tmp = sin(th)
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (Math.sin(ky_m) <= -0.02) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky_m) <= 1e-94) {
		tmp = ky_m * (Math.sin(th) / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if math.sin(ky_m) <= -0.02:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky_m) <= 1e-94:
		tmp = ky_m * (math.sin(th) / math.sin(kx))
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = Float64(ky_m * Float64(sin(th) / sin(kx)));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (sin(ky_m) <= -0.02)
		tmp = abs(sin(th));
	elseif (sin(ky_m) <= 1e-94)
		tmp = ky_m * (sin(th) / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], -0.02], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky$95$m], $MachinePrecision], 1e-94], N[(ky$95$m * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

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

\mathbf{elif}\;\sin ky\_m \leq 10^{-94}:\\
\;\;\;\;ky\_m \cdot \frac{\sin th}{\sin kx}\\

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow225.1%

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 9.9999999999999996e-95

    1. Initial program 82.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{\sin kx}} \]
    6. Step-by-step derivation
      1. associate-/l*44.6%

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

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

    if 9.9999999999999996e-95 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 68.5% accurate, 1.7× speedup?

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

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;kx \leq 2.1 \cdot 10^{-6}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\mathsf{hypot}\left(\sin ky\_m, kx\right)}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\left|\sin kx\right|}\\


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

    1. Initial program 89.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. +-commutative89.5%

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

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

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

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

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

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

    if 2.0999999999999998e-6 < kx

    1. Initial program 99.6%

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      3. rem-sqrt-square61.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr61.3%

      \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.1 \cdot 10^{-6}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 68.4% accurate, 1.7× speedup?

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

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;kx \leq 2.1 \cdot 10^{-6}:\\
\;\;\;\;\sin ky\_m \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky\_m, kx\right)}\\

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky\_m}{\left|\sin kx\right|}\\


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0999999999999998e-6 < kx

    1. Initial program 99.6%

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      3. rem-sqrt-square61.3%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    5. Applied egg-rr61.3%

      \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Final simplification71.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.1 \cdot 10^{-6}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]
  5. Add Preprocessing

Alternative 14: 36.6% accurate, 3.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;ky\_m \leq 4.5 \cdot 10^{-146}:\\ \;\;\;\;ky\_m \cdot \frac{\sin th}{kx}\\ \mathbf{elif}\;ky\_m \leq 2.5 \cdot 10^{+107}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (*
  ky_s
  (if (<= ky_m 4.5e-146)
    (* ky_m (/ (sin th) kx))
    (if (<= ky_m 2.5e+107) (sin th) (fabs (sin th))))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 4.5e-146) {
		tmp = ky_m * (sin(th) / kx);
	} else if (ky_m <= 2.5e+107) {
		tmp = sin(th);
	} else {
		tmp = fabs(sin(th));
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky_m <= 4.5d-146) then
        tmp = ky_m * (sin(th) / kx)
    else if (ky_m <= 2.5d+107) then
        tmp = sin(th)
    else
        tmp = abs(sin(th))
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 4.5e-146) {
		tmp = ky_m * (Math.sin(th) / kx);
	} else if (ky_m <= 2.5e+107) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if ky_m <= 4.5e-146:
		tmp = ky_m * (math.sin(th) / kx)
	elif ky_m <= 2.5e+107:
		tmp = math.sin(th)
	else:
		tmp = math.fabs(math.sin(th))
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (ky_m <= 4.5e-146)
		tmp = Float64(ky_m * Float64(sin(th) / kx));
	elseif (ky_m <= 2.5e+107)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (ky_m <= 4.5e-146)
		tmp = ky_m * (sin(th) / kx);
	elseif (ky_m <= 2.5e+107)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[ky$95$m, 4.5e-146], N[(ky$95$m * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky$95$m, 2.5e+107], N[Sin[th], $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;ky\_m \leq 4.5 \cdot 10^{-146}:\\
\;\;\;\;ky\_m \cdot \frac{\sin th}{kx}\\

\mathbf{elif}\;ky\_m \leq 2.5 \cdot 10^{+107}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\left|\sin th\right|\\


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

    1. Initial program 87.7%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/28.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
      2. clear-num28.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr28.3%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky \cdot \sin th}}} \]
    7. Step-by-step derivation
      1. *-commutative26.9%

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified28.4%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    9. Taylor expanded in kx around 0 20.7%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    10. Step-by-step derivation
      1. associate-/l*22.5%

        \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]
    11. Simplified22.5%

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

    if 4.5000000000000001e-146 < ky < 2.5000000000000001e107

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.5000000000000001e107 < 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. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      3. pow218.5%

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

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

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

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

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 15: 36.7% accurate, 6.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;ky\_m \leq 3.85 \cdot 10^{-146}:\\ \;\;\;\;ky\_m \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (if (<= ky_m 3.85e-146) (* ky_m (/ (sin th) kx)) (sin th))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 3.85e-146) {
		tmp = ky_m * (sin(th) / kx);
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky_m <= 3.85d-146) then
        tmp = ky_m * (sin(th) / kx)
    else
        tmp = sin(th)
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 3.85e-146) {
		tmp = ky_m * (Math.sin(th) / kx);
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if ky_m <= 3.85e-146:
		tmp = ky_m * (math.sin(th) / kx)
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (ky_m <= 3.85e-146)
		tmp = Float64(ky_m * Float64(sin(th) / kx));
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (ky_m <= 3.85e-146)
		tmp = ky_m * (sin(th) / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[ky$95$m, 3.85e-146], N[(ky$95$m * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;ky\_m \leq 3.85 \cdot 10^{-146}:\\
\;\;\;\;ky\_m \cdot \frac{\sin th}{kx}\\

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


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

    1. Initial program 87.7%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/28.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
      2. clear-num28.3%

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr28.3%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky \cdot \sin th}}} \]
    7. Step-by-step derivation
      1. *-commutative26.9%

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified28.4%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    9. Taylor expanded in kx around 0 20.7%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    10. Step-by-step derivation
      1. associate-/l*22.5%

        \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]
    11. Simplified22.5%

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

    if 3.84999999999999998e-146 < 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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 33.1% accurate, 6.4× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;kx \leq 1.95 \cdot 10^{-7}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky\_m \cdot \frac{th}{\sin kx}\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (if (<= kx 1.95e-7) (sin th) (* ky_m (/ th (sin kx))))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (kx <= 1.95e-7) {
		tmp = sin(th);
	} else {
		tmp = ky_m * (th / sin(kx));
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.95d-7) then
        tmp = sin(th)
    else
        tmp = ky_m * (th / sin(kx))
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (kx <= 1.95e-7) {
		tmp = Math.sin(th);
	} else {
		tmp = ky_m * (th / Math.sin(kx));
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if kx <= 1.95e-7:
		tmp = math.sin(th)
	else:
		tmp = ky_m * (th / math.sin(kx))
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (kx <= 1.95e-7)
		tmp = sin(th);
	else
		tmp = Float64(ky_m * Float64(th / sin(kx)));
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (kx <= 1.95e-7)
		tmp = sin(th);
	else
		tmp = ky_m * (th / sin(kx));
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[kx, 1.95e-7], N[Sin[th], $MachinePrecision], N[(ky$95$m * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;kx \leq 1.95 \cdot 10^{-7}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.95000000000000012e-7 < kx

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. associate-*l/33.6%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{\sin ky \cdot \sin th}}} \]
    5. Applied egg-rr32.6%

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

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky \cdot \sin th}}} \]
    7. Step-by-step derivation
      1. *-commutative29.2%

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

        \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    8. Simplified29.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
    9. Taylor expanded in th around 0 22.2%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    10. Step-by-step derivation
      1. associate-/l*22.2%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    11. Simplified22.2%

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

Alternative 17: 31.8% accurate, 6.6× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;kx \leq 1.2 \cdot 10^{-7}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\log \left(th + 1\right)\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (if (<= kx 1.2e-7) (sin th) (log (+ th 1.0)))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (kx <= 1.2e-7) {
		tmp = sin(th);
	} else {
		tmp = log((th + 1.0));
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.2d-7) then
        tmp = sin(th)
    else
        tmp = log((th + 1.0d0))
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (kx <= 1.2e-7) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.log((th + 1.0));
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if kx <= 1.2e-7:
		tmp = math.sin(th)
	else:
		tmp = math.log((th + 1.0))
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (kx <= 1.2e-7)
		tmp = sin(th);
	else
		tmp = log(Float64(th + 1.0));
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (kx <= 1.2e-7)
		tmp = sin(th);
	else
		tmp = log((th + 1.0));
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[kx, 1.2e-7], N[Sin[th], $MachinePrecision], N[Log[N[(th + 1.0), $MachinePrecision]], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;kx \leq 1.2 \cdot 10^{-7}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\log \left(th + 1\right)\\


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.19999999999999989e-7 < kx

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-log-exp19.7%

        \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    7. Applied egg-rr19.7%

      \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    8. Taylor expanded in th around 0 18.0%

      \[\leadsto \log \color{blue}{\left(1 + th\right)} \]
    9. Step-by-step derivation
      1. +-commutative18.0%

        \[\leadsto \log \color{blue}{\left(th + 1\right)} \]
    10. Simplified18.0%

      \[\leadsto \log \color{blue}{\left(th + 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 18: 32.8% accurate, 6.7× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;ky\_m \leq 1.95 \cdot 10^{-234}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (if (<= ky_m 1.95e-234) 0.0 (sin th))))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 1.95e-234) {
		tmp = 0.0;
	} else {
		tmp = sin(th);
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky_m <= 1.95d-234) then
        tmp = 0.0d0
    else
        tmp = sin(th)
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 1.95e-234) {
		tmp = 0.0;
	} else {
		tmp = Math.sin(th);
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if ky_m <= 1.95e-234:
		tmp = 0.0
	else:
		tmp = math.sin(th)
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (ky_m <= 1.95e-234)
		tmp = 0.0;
	else
		tmp = sin(th);
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (ky_m <= 1.95e-234)
		tmp = 0.0;
	else
		tmp = sin(th);
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[ky$95$m, 1.95e-234], 0.0, N[Sin[th], $MachinePrecision]]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;ky\_m \leq 1.95 \cdot 10^{-234}:\\
\;\;\;\;0\\

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


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

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    7. Applied egg-rr20.1%

      \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    8. Taylor expanded in th around 0 15.3%

      \[\leadsto \log \color{blue}{1} \]
    9. Step-by-step derivation
      1. metadata-eval15.3%

        \[\leadsto \color{blue}{0} \]
    10. Applied egg-rr15.3%

      \[\leadsto \color{blue}{0} \]

    if 1.9500000000000001e-234 < ky

    1. Initial program 93.8%

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg93.8%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 19: 21.4% accurate, 117.9× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot \begin{array}{l} \mathbf{if}\;ky\_m \leq 4.6 \cdot 10^{-183}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th)
 :precision binary64
 (* ky_s (if (<= ky_m 4.6e-183) 0.0 th)))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 4.6e-183) {
		tmp = 0.0;
	} else {
		tmp = th;
	}
	return ky_s * tmp;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky_m <= 4.6d-183) then
        tmp = 0.0d0
    else
        tmp = th
    end if
    code = ky_s * tmp
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	double tmp;
	if (ky_m <= 4.6e-183) {
		tmp = 0.0;
	} else {
		tmp = th;
	}
	return ky_s * tmp;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	tmp = 0
	if ky_m <= 4.6e-183:
		tmp = 0.0
	else:
		tmp = th
	return ky_s * tmp
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	tmp = 0.0
	if (ky_m <= 4.6e-183)
		tmp = 0.0;
	else
		tmp = th;
	end
	return Float64(ky_s * tmp)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp_2 = code(ky_s, kx, ky_m, th)
	tmp = 0.0;
	if (ky_m <= 4.6e-183)
		tmp = 0.0;
	else
		tmp = th;
	end
	tmp_2 = ky_s * tmp;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * If[LessEqual[ky$95$m, 4.6e-183], 0.0, th]), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot \begin{array}{l}
\mathbf{if}\;ky\_m \leq 4.6 \cdot 10^{-183}:\\
\;\;\;\;0\\

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


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

    1. Initial program 88.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Step-by-step derivation
      1. add-log-exp20.3%

        \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    7. Applied egg-rr20.3%

      \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
    8. Taylor expanded in th around 0 14.7%

      \[\leadsto \log \color{blue}{1} \]
    9. Step-by-step derivation
      1. metadata-eval14.7%

        \[\leadsto \color{blue}{0} \]
    10. Applied egg-rr14.7%

      \[\leadsto \color{blue}{0} \]

    if 4.60000000000000032e-183 < ky

    1. Initial program 97.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0 21.1%

      \[\leadsto \color{blue}{th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 20: 12.4% accurate, 709.0× speedup?

\[\begin{array}{l} ky\_m = \left|ky\right| \\ ky\_s = \mathsf{copysign}\left(1, ky\right) \\ ky\_s \cdot 0 \end{array} \]
ky\_m = (fabs.f64 ky)
ky\_s = (copysign.f64 #s(literal 1 binary64) ky)
(FPCore (ky_s kx ky_m th) :precision binary64 (* ky_s 0.0))
ky\_m = fabs(ky);
ky\_s = copysign(1.0, ky);
double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * 0.0;
}
ky\_m = abs(ky)
ky\_s = copysign(1.0d0, ky)
real(8) function code(ky_s, kx, ky_m, th)
    real(8), intent (in) :: ky_s
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky_m
    real(8), intent (in) :: th
    code = ky_s * 0.0d0
end function
ky\_m = Math.abs(ky);
ky\_s = Math.copySign(1.0, ky);
public static double code(double ky_s, double kx, double ky_m, double th) {
	return ky_s * 0.0;
}
ky\_m = math.fabs(ky)
ky\_s = math.copysign(1.0, ky)
def code(ky_s, kx, ky_m, th):
	return ky_s * 0.0
ky\_m = abs(ky)
ky\_s = copysign(1.0, ky)
function code(ky_s, kx, ky_m, th)
	return Float64(ky_s * 0.0)
end
ky\_m = abs(ky);
ky\_s = sign(ky) * abs(1.0);
function tmp = code(ky_s, kx, ky_m, th)
	tmp = ky_s * 0.0;
end
ky\_m = N[Abs[ky], $MachinePrecision]
ky\_s = N[With[{TMP1 = Abs[1.0], TMP2 = Sign[ky]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision]
code[ky$95$s_, kx_, ky$95$m_, th_] := N[(ky$95$s * 0.0), $MachinePrecision]
\begin{array}{l}
ky\_m = \left|ky\right|
\\
ky\_s = \mathsf{copysign}\left(1, ky\right)

\\
ky\_s \cdot 0
\end{array}
Derivation
  1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sin th} \]
  6. Step-by-step derivation
    1. add-log-exp20.9%

      \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
  7. Applied egg-rr20.9%

    \[\leadsto \color{blue}{\log \left(e^{\sin th}\right)} \]
  8. Taylor expanded in th around 0 11.3%

    \[\leadsto \log \color{blue}{1} \]
  9. Step-by-step derivation
    1. metadata-eval11.3%

      \[\leadsto \color{blue}{0} \]
  10. Applied egg-rr11.3%

    \[\leadsto \color{blue}{0} \]
  11. Add Preprocessing

Reproduce

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