Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.6%
Time: 21.3s
Alternatives: 16
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 16 alternatives:

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

Initial Program: 94.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.4× speedup?

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

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

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. associate-*l/89.9%

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

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

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

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

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

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

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

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

Alternative 2: 70.8% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky \cdot \sin th}{\left|\sin kx\right|}\\ \mathbf{if}\;\sin th \leq -0.8:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq -0.65:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq -0.01:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin th \leq 10^{-7}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin th \leq 0.87:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin kx}\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (* (sin ky) (sin th)) (fabs (sin kx)))))
   (if (<= (sin th) -0.8)
     t_1
     (if (<= (sin th) -0.65)
       (fabs (sin th))
       (if (<= (sin th) -0.01)
         t_1
         (if (<= (sin th) 1e-7)
           (* (sin ky) (/ th (hypot (sin ky) (sin kx))))
           (if (<= (sin th) 0.87)
             (/ (sin ky) (fabs (/ (sin ky) (sin th))))
             (* (sin ky) (fabs (/ (sin th) (sin kx)))))))))))
double code(double kx, double ky, double th) {
	double t_1 = (sin(ky) * sin(th)) / fabs(sin(kx));
	double tmp;
	if (sin(th) <= -0.8) {
		tmp = t_1;
	} else if (sin(th) <= -0.65) {
		tmp = fabs(sin(th));
	} else if (sin(th) <= -0.01) {
		tmp = t_1;
	} else if (sin(th) <= 1e-7) {
		tmp = sin(ky) * (th / hypot(sin(ky), sin(kx)));
	} else if (sin(th) <= 0.87) {
		tmp = sin(ky) / fabs((sin(ky) / sin(th)));
	} else {
		tmp = sin(ky) * fabs((sin(th) / sin(kx)));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = (Math.sin(ky) * Math.sin(th)) / Math.abs(Math.sin(kx));
	double tmp;
	if (Math.sin(th) <= -0.8) {
		tmp = t_1;
	} else if (Math.sin(th) <= -0.65) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(th) <= -0.01) {
		tmp = t_1;
	} else if (Math.sin(th) <= 1e-7) {
		tmp = Math.sin(ky) * (th / Math.hypot(Math.sin(ky), Math.sin(kx)));
	} else if (Math.sin(th) <= 0.87) {
		tmp = Math.sin(ky) / Math.abs((Math.sin(ky) / Math.sin(th)));
	} else {
		tmp = Math.sin(ky) * Math.abs((Math.sin(th) / Math.sin(kx)));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = (math.sin(ky) * math.sin(th)) / math.fabs(math.sin(kx))
	tmp = 0
	if math.sin(th) <= -0.8:
		tmp = t_1
	elif math.sin(th) <= -0.65:
		tmp = math.fabs(math.sin(th))
	elif math.sin(th) <= -0.01:
		tmp = t_1
	elif math.sin(th) <= 1e-7:
		tmp = math.sin(ky) * (th / math.hypot(math.sin(ky), math.sin(kx)))
	elif math.sin(th) <= 0.87:
		tmp = math.sin(ky) / math.fabs((math.sin(ky) / math.sin(th)))
	else:
		tmp = math.sin(ky) * math.fabs((math.sin(th) / math.sin(kx)))
	return tmp
function code(kx, ky, th)
	t_1 = Float64(Float64(sin(ky) * sin(th)) / abs(sin(kx)))
	tmp = 0.0
	if (sin(th) <= -0.8)
		tmp = t_1;
	elseif (sin(th) <= -0.65)
		tmp = abs(sin(th));
	elseif (sin(th) <= -0.01)
		tmp = t_1;
	elseif (sin(th) <= 1e-7)
		tmp = Float64(sin(ky) * Float64(th / hypot(sin(ky), sin(kx))));
	elseif (sin(th) <= 0.87)
		tmp = Float64(sin(ky) / abs(Float64(sin(ky) / sin(th))));
	else
		tmp = Float64(sin(ky) * abs(Float64(sin(th) / sin(kx))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = (sin(ky) * sin(th)) / abs(sin(kx));
	tmp = 0.0;
	if (sin(th) <= -0.8)
		tmp = t_1;
	elseif (sin(th) <= -0.65)
		tmp = abs(sin(th));
	elseif (sin(th) <= -0.01)
		tmp = t_1;
	elseif (sin(th) <= 1e-7)
		tmp = sin(ky) * (th / hypot(sin(ky), sin(kx)));
	elseif (sin(th) <= 0.87)
		tmp = sin(ky) / abs((sin(ky) / sin(th)));
	else
		tmp = sin(ky) * abs((sin(th) / sin(kx)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[(N[Sin[ky], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Abs[N[Sin[kx], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[th], $MachinePrecision], -0.8], t$95$1, If[LessEqual[N[Sin[th], $MachinePrecision], -0.65], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], -0.01], t$95$1, If[LessEqual[N[Sin[th], $MachinePrecision], 1e-7], N[(N[Sin[ky], $MachinePrecision] * N[(th / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], 0.87], N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[Abs[N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin th \leq -0.65:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin th \leq -0.01:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\sin th \leq 0.87:\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 regimes
  2. if (sin.f64 th) < -0.80000000000000004 or -0.650000000000000022 < (sin.f64 th) < -0.0100000000000000002

    1. Initial program 93.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/93.8%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt36.8%

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\left|\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}\right|}} \]
      3. sqr-sin-a44.6%

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\left|\color{blue}{\sqrt{\sin kx} \cdot \sqrt{\sin kx}}\right|} \]
      5. add-sqr-sqrt45.2%

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

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

    if -0.80000000000000004 < (sin.f64 th) < -0.650000000000000022

    1. Initial program 85.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/4.3%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses4.3%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity4.3%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt0.0%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow274.5%

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 th) < 9.9999999999999995e-8

    1. Initial program 91.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/87.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-udef23.1%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
    6. Applied egg-rr23.1%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
    7. Step-by-step derivation
      1. expm1-def91.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-log1p91.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      3. associate-*r/99.5%

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

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

    if 9.9999999999999995e-8 < (sin.f64 th) < 0.869999999999999996

    1. Initial program 87.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\frac{\sin ky}{\sin th}\right|}} \]
    8. Simplified58.9%

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

    if 0.869999999999999996 < (sin.f64 th)

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.5%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.8:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\left|\sin kx\right|}\\ \mathbf{elif}\;\sin th \leq -0.65:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin th \leq -0.01:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\left|\sin kx\right|}\\ \mathbf{elif}\;\sin th \leq 10^{-7}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin th \leq 0.87:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin kx}\right|\\ \end{array} \]

Alternative 3: 49.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.85:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.005:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.85)
   (fabs (sin th))
   (if (<= (sin ky) -0.005)
     (/ (sin ky) (fabs (/ (sin ky) (sin th))))
     (if (<= (sin ky) -2e-158)
       (/ (* ky (sin th)) (sqrt (- 0.5 (* 0.5 (cos (* kx 2.0))))))
       (if (<= (sin ky) 5e-128)
         (fabs (* (sin th) (/ (sin ky) (sin kx))))
         (if (<= (sin ky) 5e-6)
           (/ (* ky th) (hypot (sin ky) (sin kx)))
           (sin th)))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.85) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -0.005) {
		tmp = sin(ky) / fabs((sin(ky) / sin(th)));
	} else if (sin(ky) <= -2e-158) {
		tmp = (ky * sin(th)) / sqrt((0.5 - (0.5 * cos((kx * 2.0)))));
	} else if (sin(ky) <= 5e-128) {
		tmp = fabs((sin(th) * (sin(ky) / sin(kx))));
	} else if (sin(ky) <= 5e-6) {
		tmp = (ky * th) / hypot(sin(ky), sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.85) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -0.005) {
		tmp = Math.sin(ky) / Math.abs((Math.sin(ky) / Math.sin(th)));
	} else if (Math.sin(ky) <= -2e-158) {
		tmp = (ky * Math.sin(th)) / Math.sqrt((0.5 - (0.5 * Math.cos((kx * 2.0)))));
	} else if (Math.sin(ky) <= 5e-128) {
		tmp = Math.abs((Math.sin(th) * (Math.sin(ky) / Math.sin(kx))));
	} else if (Math.sin(ky) <= 5e-6) {
		tmp = (ky * th) / Math.hypot(Math.sin(ky), Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.85:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -0.005:
		tmp = math.sin(ky) / math.fabs((math.sin(ky) / math.sin(th)))
	elif math.sin(ky) <= -2e-158:
		tmp = (ky * math.sin(th)) / math.sqrt((0.5 - (0.5 * math.cos((kx * 2.0)))))
	elif math.sin(ky) <= 5e-128:
		tmp = math.fabs((math.sin(th) * (math.sin(ky) / math.sin(kx))))
	elif math.sin(ky) <= 5e-6:
		tmp = (ky * th) / math.hypot(math.sin(ky), math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.85)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -0.005)
		tmp = Float64(sin(ky) / abs(Float64(sin(ky) / sin(th))));
	elseif (sin(ky) <= -2e-158)
		tmp = Float64(Float64(ky * sin(th)) / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx * 2.0))))));
	elseif (sin(ky) <= 5e-128)
		tmp = abs(Float64(sin(th) * Float64(sin(ky) / sin(kx))));
	elseif (sin(ky) <= 5e-6)
		tmp = Float64(Float64(ky * th) / hypot(sin(ky), sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.85)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -0.005)
		tmp = sin(ky) / abs((sin(ky) / sin(th)));
	elseif (sin(ky) <= -2e-158)
		tmp = (ky * sin(th)) / sqrt((0.5 - (0.5 * cos((kx * 2.0)))));
	elseif (sin(ky) <= 5e-128)
		tmp = abs((sin(th) * (sin(ky) / sin(kx))));
	elseif (sin(ky) <= 5e-6)
		tmp = (ky * th) / hypot(sin(ky), sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.85], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -0.005], N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-158], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-128], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-6], N[(N[(ky * th), $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.6%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.6%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.6%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.3%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow239.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr39.0%

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

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

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

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

    if -0.849999999999999978 < (sin.f64 ky) < -0.0050000000000000001

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\sin ky}{\sin th} \cdot \frac{\sin ky}{\sin th}}}} \]
      2. rem-sqrt-square36.0%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\frac{\sin ky}{\sin th}\right|}} \]
    8. Simplified36.0%

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

    if -0.0050000000000000001 < (sin.f64 ky) < -2.00000000000000013e-158

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000013e-158 < (sin.f64 ky) < 5.0000000000000001e-128

    1. Initial program 72.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/69.3%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-128 < (sin.f64 ky) < 5.00000000000000041e-6

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/95.5%

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

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

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

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

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

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

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

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

    if 5.00000000000000041e-6 < (sin.f64 ky)

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.85:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.005:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 4: 58.6% accurate, 0.9× speedup?

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

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

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

\mathbf{elif}\;\sin ky \leq -0.15:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -0.849999999999999978 or -0.40000000000000002 < (sin.f64 ky) < -0.149999999999999994

    1. Initial program 99.8%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.7%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.7%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.7%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.3%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow240.1%

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

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified48.3%

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

    if -0.849999999999999978 < (sin.f64 ky) < -0.40000000000000002

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\frac{\sin ky}{\sin th}\right|}} \]
    8. Simplified37.7%

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.00000000000000004e-42

    1. Initial program 83.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/80.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \]
    9. Step-by-step derivation
      1. add-sqr-sqrt50.1%

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\color{blue}{\left|\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}\right|}} \]
      3. sqr-sin-a66.8%

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\left|\color{blue}{\sqrt{\sin kx} \cdot \sqrt{\sin kx}}\right|} \]
      5. add-sqr-sqrt71.6%

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

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

    if 1.00000000000000004e-42 < (sin.f64 ky)

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.85:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.4:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{elif}\;\sin ky \leq -0.15:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-42}:\\ \;\;\;\;\frac{\sin ky \cdot \sin th}{\left|\sin kx\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 5: 49.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.15:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.15)
   (fabs (sin th))
   (if (<= (sin ky) -2e-158)
     (/ (* ky (sin th)) (sqrt (- 0.5 (* 0.5 (cos (* kx 2.0))))))
     (if (<= (sin ky) 5e-128)
       (fabs (* (sin th) (/ (sin ky) (sin kx))))
       (if (<= (sin ky) 5e-6)
         (/ (* ky th) (hypot (sin ky) (sin kx)))
         (sin th))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.15) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -2e-158) {
		tmp = (ky * sin(th)) / sqrt((0.5 - (0.5 * cos((kx * 2.0)))));
	} else if (sin(ky) <= 5e-128) {
		tmp = fabs((sin(th) * (sin(ky) / sin(kx))));
	} else if (sin(ky) <= 5e-6) {
		tmp = (ky * th) / hypot(sin(ky), sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.15) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -2e-158) {
		tmp = (ky * Math.sin(th)) / Math.sqrt((0.5 - (0.5 * Math.cos((kx * 2.0)))));
	} else if (Math.sin(ky) <= 5e-128) {
		tmp = Math.abs((Math.sin(th) * (Math.sin(ky) / Math.sin(kx))));
	} else if (Math.sin(ky) <= 5e-6) {
		tmp = (ky * th) / Math.hypot(Math.sin(ky), Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.15:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -2e-158:
		tmp = (ky * math.sin(th)) / math.sqrt((0.5 - (0.5 * math.cos((kx * 2.0)))))
	elif math.sin(ky) <= 5e-128:
		tmp = math.fabs((math.sin(th) * (math.sin(ky) / math.sin(kx))))
	elif math.sin(ky) <= 5e-6:
		tmp = (ky * th) / math.hypot(math.sin(ky), math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.15)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -2e-158)
		tmp = Float64(Float64(ky * sin(th)) / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx * 2.0))))));
	elseif (sin(ky) <= 5e-128)
		tmp = abs(Float64(sin(th) * Float64(sin(ky) / sin(kx))));
	elseif (sin(ky) <= 5e-6)
		tmp = Float64(Float64(ky * th) / hypot(sin(ky), sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.15)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -2e-158)
		tmp = (ky * sin(th)) / sqrt((0.5 - (0.5 * cos((kx * 2.0)))));
	elseif (sin(ky) <= 5e-128)
		tmp = abs((sin(th) * (sin(ky) / sin(kx))));
	elseif (sin(ky) <= 5e-6)
		tmp = (ky * th) / hypot(sin(ky), sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.15], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-158], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-128], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-6], N[(N[(ky * th), $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.8%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.5%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow229.2%

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

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

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

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

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

    if -0.149999999999999994 < (sin.f64 ky) < -2.00000000000000013e-158

    1. Initial program 99.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if -2.00000000000000013e-158 < (sin.f64 ky) < 5.0000000000000001e-128

    1. Initial program 72.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/69.3%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-128 < (sin.f64 ky) < 5.00000000000000041e-6

    1. Initial program 99.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/95.5%

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

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

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

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

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

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

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

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

    if 5.00000000000000041e-6 < (sin.f64 ky)

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.15:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-128}:\\ \;\;\;\;\left|\sin th \cdot \frac{\sin ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\frac{ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 73.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin th \leq -0.01:\\ \;\;\;\;\frac{ky \cdot \sin th}{t_1}\\ \mathbf{elif}\;\sin th \leq 10^{-7}:\\ \;\;\;\;\sin ky \cdot \frac{th}{t_1}\\ \mathbf{elif}\;\sin th \leq 0.87:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin kx}\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin th) -0.01)
     (/ (* ky (sin th)) t_1)
     (if (<= (sin th) 1e-7)
       (* (sin ky) (/ th t_1))
       (if (<= (sin th) 0.87)
         (/ (sin ky) (fabs (/ (sin ky) (sin th))))
         (* (sin ky) (fabs (/ (sin th) (sin kx)))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(th) <= -0.01) {
		tmp = (ky * sin(th)) / t_1;
	} else if (sin(th) <= 1e-7) {
		tmp = sin(ky) * (th / t_1);
	} else if (sin(th) <= 0.87) {
		tmp = sin(ky) / fabs((sin(ky) / sin(th)));
	} else {
		tmp = sin(ky) * fabs((sin(th) / sin(kx)));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (Math.sin(th) <= -0.01) {
		tmp = (ky * Math.sin(th)) / t_1;
	} else if (Math.sin(th) <= 1e-7) {
		tmp = Math.sin(ky) * (th / t_1);
	} else if (Math.sin(th) <= 0.87) {
		tmp = Math.sin(ky) / Math.abs((Math.sin(ky) / Math.sin(th)));
	} else {
		tmp = Math.sin(ky) * Math.abs((Math.sin(th) / Math.sin(kx)));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if math.sin(th) <= -0.01:
		tmp = (ky * math.sin(th)) / t_1
	elif math.sin(th) <= 1e-7:
		tmp = math.sin(ky) * (th / t_1)
	elif math.sin(th) <= 0.87:
		tmp = math.sin(ky) / math.fabs((math.sin(ky) / math.sin(th)))
	else:
		tmp = math.sin(ky) * math.fabs((math.sin(th) / math.sin(kx)))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(th) <= -0.01)
		tmp = Float64(Float64(ky * sin(th)) / t_1);
	elseif (sin(th) <= 1e-7)
		tmp = Float64(sin(ky) * Float64(th / t_1));
	elseif (sin(th) <= 0.87)
		tmp = Float64(sin(ky) / abs(Float64(sin(ky) / sin(th))));
	else
		tmp = Float64(sin(ky) * abs(Float64(sin(th) / sin(kx))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (sin(th) <= -0.01)
		tmp = (ky * sin(th)) / t_1;
	elseif (sin(th) <= 1e-7)
		tmp = sin(ky) * (th / t_1);
	elseif (sin(th) <= 0.87)
		tmp = sin(ky) / abs((sin(ky) / sin(th)));
	else
		tmp = sin(ky) * abs((sin(th) / sin(kx)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, If[LessEqual[N[Sin[th], $MachinePrecision], -0.01], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], 1e-7], N[(N[Sin[ky], $MachinePrecision] * N[(th / t$95$1), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[th], $MachinePrecision], 0.87], N[(N[Sin[ky], $MachinePrecision] / N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] * N[Abs[N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin th \leq 10^{-7}:\\
\;\;\;\;\sin ky \cdot \frac{th}{t_1}\\

\mathbf{elif}\;\sin th \leq 0.87:\\
\;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\

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


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

    1. Initial program 92.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/92.9%

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 th) < 9.9999999999999995e-8

    1. Initial program 91.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/87.9%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-udef23.1%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
    6. Applied egg-rr23.1%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)} - 1} \]
    7. Step-by-step derivation
      1. expm1-def91.1%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)\right)} \]
      2. expm1-log1p91.1%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      3. associate-*r/99.5%

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

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

    if 9.9999999999999995e-8 < (sin.f64 th) < 0.869999999999999996

    1. Initial program 87.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\frac{\sin ky}{\sin th}\right|}} \]
    8. Simplified58.9%

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

    if 0.869999999999999996 < (sin.f64 th)

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.6%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.5%

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.01:\\ \;\;\;\;\frac{ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin th \leq 10^{-7}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;\sin th \leq 0.87:\\ \;\;\;\;\frac{\sin ky}{\left|\frac{\sin ky}{\sin th}\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin kx}\right|\\ \end{array} \]

Alternative 7: 47.3% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 10^{-42}:\\
\;\;\;\;\sin ky \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.149999999999999994

    1. Initial program 99.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.8%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.5%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow229.2%

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

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

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

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

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.00000000000000004e-42

    1. Initial program 83.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/80.6%

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

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

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

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

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

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

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

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

    if 1.00000000000000004e-42 < (sin.f64 ky)

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.15:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-42}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 8: 49.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.01:\\
\;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\

\mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-89}:\\
\;\;\;\;\left|\sin th\right|\\

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


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

    1. Initial program 99.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/99.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 kx) < 2.00000000000000008e-89

    1. Initial program 81.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/42.1%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses42.1%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity42.1%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt24.9%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow244.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr44.0%

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified49.3%

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

    if 2.00000000000000008e-89 < (sin.f64 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. associate-*l/99.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.01:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-89}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]

Alternative 9: 40.4% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -5 \cdot 10^{-137}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.9%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.9%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.9%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.4%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow227.7%

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

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified33.0%

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

    if -5.00000000000000001e-137 < (sin.f64 ky) < 2e-191

    1. Initial program 70.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/67.1%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.4%

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

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

      \[\leadsto \sin ky \cdot \left(\color{blue}{\frac{1}{\sin kx}} \cdot \sin th\right) \]
    7. Taylor expanded in th around 0 41.5%

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

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

    1. Initial program 97.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/96.6%

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

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

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

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

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

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

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

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

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

Alternative 10: 42.4% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -4 \cdot 10^{-97}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.8%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.4%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow226.0%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr26.0%

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified33.0%

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

    if -4.00000000000000014e-97 < (sin.f64 ky) < 1.00000000000000004e-134

    1. Initial program 75.5%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/71.8%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
      2. associate-/r/99.4%

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

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

      \[\leadsto \sin ky \cdot \left(\color{blue}{\frac{1}{\sin kx}} \cdot \sin th\right) \]
    7. Taylor expanded in kx around 0 43.7%

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

    if 1.00000000000000004e-134 < (sin.f64 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. associate-*l/98.7%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -4 \cdot 10^{-97}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-134}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 47.8% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/2.8%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt1.5%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow227.9%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    6. Applied egg-rr27.9%

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.00000000000000004e-42

    1. Initial program 82.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/80.1%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
    6. Simplified49.8%

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

    if 1.00000000000000004e-42 < (sin.f64 ky)

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/98.4%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 10^{-42}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 12: 31.1% accurate, 3.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -1.1 \cdot 10^{-137} \lor \neg \left(ky \leq 3.7 \cdot 10^{-6}\right):\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= ky -1.1e-137) (not (<= ky 3.7e-6)))
   (fabs (sin th))
   (/ ky (/ (sin kx) th))))
double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -1.1e-137) || !(ky <= 3.7e-6)) {
		tmp = fabs(sin(th));
	} else {
		tmp = ky / (sin(kx) / th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((ky <= (-1.1d-137)) .or. (.not. (ky <= 3.7d-6))) then
        tmp = abs(sin(th))
    else
        tmp = ky / (sin(kx) / th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -1.1e-137) || !(ky <= 3.7e-6)) {
		tmp = Math.abs(Math.sin(th));
	} else {
		tmp = ky / (Math.sin(kx) / th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (ky <= -1.1e-137) or not (ky <= 3.7e-6):
		tmp = math.fabs(math.sin(th))
	else:
		tmp = ky / (math.sin(kx) / th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((ky <= -1.1e-137) || !(ky <= 3.7e-6))
		tmp = abs(sin(th));
	else
		tmp = Float64(ky / Float64(sin(kx) / th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((ky <= -1.1e-137) || ~((ky <= 3.7e-6)))
		tmp = abs(sin(th));
	else
		tmp = ky / (sin(kx) / th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[ky, -1.1e-137], N[Not[LessEqual[ky, 3.7e-6]], $MachinePrecision]], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], N[(ky / N[(N[Sin[kx], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.1 \cdot 10^{-137} \lor \neg \left(ky \leq 3.7 \cdot 10^{-6}\right):\\
\;\;\;\;\left|\sin th\right|\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.1000000000000001e-137 or 3.7000000000000002e-6 < 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. associate-/r/99.6%

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/29.5%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses29.5%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity29.5%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt18.9%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow232.1%

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

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

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    8. Simplified38.1%

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

    if -1.1000000000000001e-137 < ky < 3.7000000000000002e-6

    1. Initial program 79.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/76.0%

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def90.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.1 \cdot 10^{-137} \lor \neg \left(ky \leq 3.7 \cdot 10^{-6}\right):\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \end{array} \]

Alternative 13: 32.7% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -22:\\
\;\;\;\;\sin th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -22 or 1.80000000000000008e-189 < ky

    1. Initial program 98.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/97.8%

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

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

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

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

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

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

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

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

    if -22 < ky < 1.80000000000000008e-189

    1. Initial program 79.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/75.4%

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

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

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

        \[\leadsto \frac{\sin ky \cdot \sin th}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      5. hypot-def88.9%

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    7. Simplified35.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -22:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.8 \cdot 10^{-189}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 14: 25.8% accurate, 6.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.65 \cdot 10^{-12}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= kx 1.65e-12) (sin th) 0.0))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.65e-12) {
		tmp = sin(th);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.65d-12) then
        tmp = sin(th)
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.65e-12) {
		tmp = Math.sin(th);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 1.65e-12:
		tmp = math.sin(th)
	else:
		tmp = 0.0
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 1.65e-12)
		tmp = sin(th);
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 1.65e-12)
		tmp = sin(th);
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 1.65e-12], N[Sin[th], $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.65 \cdot 10^{-12}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 88.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. associate-*l/86.6%

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

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

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

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

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

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

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

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

    if 1.65e-12 < kx

    1. Initial program 99.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/7.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses7.2%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity7.2%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-log-exp19.5%

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

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

      \[\leadsto \log \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification27.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.65 \cdot 10^{-12}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 15: 16.3% accurate, 231.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.45 \cdot 10^{-13}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= kx 1.45e-13) th 0.0))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.45e-13) {
		tmp = th;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 1.45d-13) then
        tmp = th
    else
        tmp = 0.0d0
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.45e-13) {
		tmp = th;
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 1.45e-13:
		tmp = th
	else:
		tmp = 0.0
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 1.45e-13)
		tmp = th;
	else
		tmp = 0.0;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 1.45e-13)
		tmp = th;
	else
		tmp = 0.0;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 1.45e-13], th, 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.45 \cdot 10^{-13}:\\
\;\;\;\;th\\

\mathbf{else}:\\
\;\;\;\;0\\


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

    1. Initial program 88.8%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Taylor expanded in th around 0 17.3%

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

    if 1.4499999999999999e-13 < kx

    1. Initial program 99.4%

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
    5. Step-by-step derivation
      1. associate-/r/7.2%

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses7.2%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity7.2%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-log-exp19.5%

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

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

      \[\leadsto \log \color{blue}{1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification17.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.45 \cdot 10^{-13}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 16: 13.7% accurate, 709.0× speedup?

\[\begin{array}{l} \\ th \end{array} \]
(FPCore (kx ky th) :precision binary64 th)
double code(double kx, double ky, double th) {
	return th;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = th
end function
public static double code(double kx, double ky, double th) {
	return th;
}
def code(kx, ky, th):
	return th
function code(kx, ky, th)
	return th
end
function tmp = code(kx, ky, th)
	tmp = th;
end
code[kx_, ky_, th_] := th
\begin{array}{l}

\\
th
\end{array}
Derivation
  1. Initial program 91.6%

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

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

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

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

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

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

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

    \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\sin ky}}{\sin th}} \]
  5. Taylor expanded in th around 0 14.2%

    \[\leadsto \color{blue}{th} \]
  6. Final simplification14.2%

    \[\leadsto th \]

Reproduce

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