Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 25.1s
Alternatives: 23
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 23 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.3% 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.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 48.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ t_2 := \frac{t_1}{\frac{\sin kx}{ky}}\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-288}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;\sin ky \leq 10^{-104}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 10^{-98}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))) (t_2 (/ t_1 (/ (sin kx) ky))))
   (if (<= (sin ky) -1e-37)
     t_1
     (if (<= (sin ky) 2e-288)
       t_2
       (if (<= (sin ky) 1e-104)
         (/ (* ky (sin th)) (sin kx))
         (if (<= (sin ky) 1e-98) t_2 (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double t_2 = t_1 / (sin(kx) / ky);
	double tmp;
	if (sin(ky) <= -1e-37) {
		tmp = t_1;
	} else if (sin(ky) <= 2e-288) {
		tmp = t_2;
	} else if (sin(ky) <= 1e-104) {
		tmp = (ky * sin(th)) / sin(kx);
	} else if (sin(ky) <= 1e-98) {
		tmp = t_2;
	} 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) :: t_2
    real(8) :: tmp
    t_1 = abs(sin(th))
    t_2 = t_1 / (sin(kx) / ky)
    if (sin(ky) <= (-1d-37)) then
        tmp = t_1
    else if (sin(ky) <= 2d-288) then
        tmp = t_2
    else if (sin(ky) <= 1d-104) then
        tmp = (ky * sin(th)) / sin(kx)
    else if (sin(ky) <= 1d-98) then
        tmp = t_2
    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 t_2 = t_1 / (Math.sin(kx) / ky);
	double tmp;
	if (Math.sin(ky) <= -1e-37) {
		tmp = t_1;
	} else if (Math.sin(ky) <= 2e-288) {
		tmp = t_2;
	} else if (Math.sin(ky) <= 1e-104) {
		tmp = (ky * Math.sin(th)) / Math.sin(kx);
	} else if (Math.sin(ky) <= 1e-98) {
		tmp = t_2;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	t_2 = t_1 / (math.sin(kx) / ky)
	tmp = 0
	if math.sin(ky) <= -1e-37:
		tmp = t_1
	elif math.sin(ky) <= 2e-288:
		tmp = t_2
	elif math.sin(ky) <= 1e-104:
		tmp = (ky * math.sin(th)) / math.sin(kx)
	elif math.sin(ky) <= 1e-98:
		tmp = t_2
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	t_2 = Float64(t_1 / Float64(sin(kx) / ky))
	tmp = 0.0
	if (sin(ky) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= 2e-288)
		tmp = t_2;
	elseif (sin(ky) <= 1e-104)
		tmp = Float64(Float64(ky * sin(th)) / sin(kx));
	elseif (sin(ky) <= 1e-98)
		tmp = t_2;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	t_2 = t_1 / (sin(kx) / ky);
	tmp = 0.0;
	if (sin(ky) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= 2e-288)
		tmp = t_2;
	elseif (sin(ky) <= 1e-104)
		tmp = (ky * sin(th)) / sin(kx);
	elseif (sin(ky) <= 1e-98)
		tmp = t_2;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(t$95$1 / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -1e-37], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-288], t$95$2, If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-104], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-98], t$95$2, N[Sin[th], $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
t_2 := \frac{t_1}{\frac{\sin kx}{ky}}\\
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-288}:\\
\;\;\;\;t_2\\

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

\mathbf{elif}\;\sin ky \leq 10^{-98}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.00000000000000007e-37

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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 -1.00000000000000007e-37 < (sin.f64 ky) < 2.00000000000000012e-288 or 9.99999999999999927e-105 < (sin.f64 ky) < 9.99999999999999939e-99

    1. Initial program 79.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000012e-288 < (sin.f64 ky) < 9.99999999999999927e-105

    1. Initial program 92.8%

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

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

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

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

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

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

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

    if 9.99999999999999939e-99 < (sin.f64 ky)

    1. Initial program 99.5%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-288}:\\ \;\;\;\;\frac{\left|\sin th\right|}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;\sin ky \leq 10^{-104}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 10^{-98}:\\ \;\;\;\;\frac{\left|\sin th\right|}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 3: 66.0% accurate, 1.0× speedup?

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

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

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

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.78000000000000003 < (sin.f64 th) < -0.0200000000000000004

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 th) < 9.9999999999999998e-17

    1. Initial program 94.4%

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow294.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 th around 0 99.7%

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

    if 9.9999999999999998e-17 < (sin.f64 th)

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 66.1% accurate, 1.0× speedup?

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

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

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

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.78000000000000003 < (sin.f64 th) < -0.0200000000000000004

    1. Initial program 86.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 th) < 9.9999999999999998e-17

    1. Initial program 94.4%

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

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

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

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

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

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

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

    if 9.9999999999999998e-17 < (sin.f64 th)

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 53.7% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ t_2 := \frac{\sin kx}{ky}\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\ \;\;\;\;\frac{t_1}{t_2}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-16}:\\ \;\;\;\;\frac{\sin th}{\left|t_2\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))) (t_2 (/ (sin kx) ky)))
   (if (<= (sin ky) -1e-37)
     t_1
     (if (<= (sin ky) -5e-301)
       (/ t_1 t_2)
       (if (<= (sin ky) 2e-16) (/ (sin th) (fabs t_2)) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double t_2 = sin(kx) / ky;
	double tmp;
	if (sin(ky) <= -1e-37) {
		tmp = t_1;
	} else if (sin(ky) <= -5e-301) {
		tmp = t_1 / t_2;
	} else if (sin(ky) <= 2e-16) {
		tmp = sin(th) / fabs(t_2);
	} 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) :: t_2
    real(8) :: tmp
    t_1 = abs(sin(th))
    t_2 = sin(kx) / ky
    if (sin(ky) <= (-1d-37)) then
        tmp = t_1
    else if (sin(ky) <= (-5d-301)) then
        tmp = t_1 / t_2
    else if (sin(ky) <= 2d-16) then
        tmp = sin(th) / abs(t_2)
    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 t_2 = Math.sin(kx) / ky;
	double tmp;
	if (Math.sin(ky) <= -1e-37) {
		tmp = t_1;
	} else if (Math.sin(ky) <= -5e-301) {
		tmp = t_1 / t_2;
	} else if (Math.sin(ky) <= 2e-16) {
		tmp = Math.sin(th) / Math.abs(t_2);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	t_2 = math.sin(kx) / ky
	tmp = 0
	if math.sin(ky) <= -1e-37:
		tmp = t_1
	elif math.sin(ky) <= -5e-301:
		tmp = t_1 / t_2
	elif math.sin(ky) <= 2e-16:
		tmp = math.sin(th) / math.fabs(t_2)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	t_2 = Float64(sin(kx) / ky)
	tmp = 0.0
	if (sin(ky) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= -5e-301)
		tmp = Float64(t_1 / t_2);
	elseif (sin(ky) <= 2e-16)
		tmp = Float64(sin(th) / abs(t_2));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	t_2 = sin(kx) / ky;
	tmp = 0.0;
	if (sin(ky) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= -5e-301)
		tmp = t_1 / t_2;
	elseif (sin(ky) <= 2e-16)
		tmp = sin(th) / abs(t_2);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -1e-37], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], -5e-301], N[(t$95$1 / t$95$2), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-16], N[(N[Sin[th], $MachinePrecision] / N[Abs[t$95$2], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
t_2 := \frac{\sin kx}{ky}\\
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-301}:\\
\;\;\;\;\frac{t_1}{t_2}\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-16}:\\
\;\;\;\;\frac{\sin th}{\left|t_2\right|}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.00000000000000007e-37

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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 -1.00000000000000007e-37 < (sin.f64 ky) < -5.00000000000000013e-301

    1. Initial program 79.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000013e-301 < (sin.f64 ky) < 2e-16

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\left|\frac{\sin kx}{ky}\right|}} \]
    10. Simplified80.2%

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 6: 53.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-304}:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot t_1\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-16}:\\ \;\;\;\;\frac{\sin th}{\left|\frac{\sin kx}{ky}\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))))
   (if (<= (sin ky) -1e-37)
     t_1
     (if (<= (sin ky) 5e-304)
       (* (/ (sin ky) (sin kx)) t_1)
       (if (<= (sin ky) 2e-16)
         (/ (sin th) (fabs (/ (sin kx) ky)))
         (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double tmp;
	if (sin(ky) <= -1e-37) {
		tmp = t_1;
	} else if (sin(ky) <= 5e-304) {
		tmp = (sin(ky) / sin(kx)) * t_1;
	} else if (sin(ky) <= 2e-16) {
		tmp = sin(th) / fabs((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) :: t_1
    real(8) :: tmp
    t_1 = abs(sin(th))
    if (sin(ky) <= (-1d-37)) then
        tmp = t_1
    else if (sin(ky) <= 5d-304) then
        tmp = (sin(ky) / sin(kx)) * t_1
    else if (sin(ky) <= 2d-16) then
        tmp = sin(th) / abs((sin(kx) / ky))
    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) <= -1e-37) {
		tmp = t_1;
	} else if (Math.sin(ky) <= 5e-304) {
		tmp = (Math.sin(ky) / Math.sin(kx)) * t_1;
	} else if (Math.sin(ky) <= 2e-16) {
		tmp = Math.sin(th) / Math.abs((Math.sin(kx) / ky));
	} 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) <= -1e-37:
		tmp = t_1
	elif math.sin(ky) <= 5e-304:
		tmp = (math.sin(ky) / math.sin(kx)) * t_1
	elif math.sin(ky) <= 2e-16:
		tmp = math.sin(th) / math.fabs((math.sin(kx) / ky))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	tmp = 0.0
	if (sin(ky) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= 5e-304)
		tmp = Float64(Float64(sin(ky) / sin(kx)) * t_1);
	elseif (sin(ky) <= 2e-16)
		tmp = Float64(sin(th) / abs(Float64(sin(kx) / ky)));
	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) <= -1e-37)
		tmp = t_1;
	elseif (sin(ky) <= 5e-304)
		tmp = (sin(ky) / sin(kx)) * t_1;
	elseif (sin(ky) <= 2e-16)
		tmp = sin(th) / abs((sin(kx) / ky));
	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], -1e-37], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-304], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-16], N[(N[Sin[th], $MachinePrecision] / N[Abs[N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-37}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-304}:\\
\;\;\;\;\frac{\sin ky}{\sin kx} \cdot t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.00000000000000007e-37

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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 -1.00000000000000007e-37 < (sin.f64 ky) < 4.99999999999999965e-304

    1. Initial program 79.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999965e-304 < (sin.f64 ky) < 2e-16

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 7: 47.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-42}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-281}:\\ \;\;\;\;\left|\sin th \cdot \frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-99}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -1e-42)
   (fabs (sin th))
   (if (<= (sin ky) -2e-281)
     (fabs (* (sin th) (/ ky (sin kx))))
     (if (<= (sin ky) 5e-99) (/ (* ky (sin th)) (sin kx)) (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -1e-42) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -2e-281) {
		tmp = fabs((sin(th) * (ky / sin(kx))));
	} else if (sin(ky) <= 5e-99) {
		tmp = (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) <= (-1d-42)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= (-2d-281)) then
        tmp = abs((sin(th) * (ky / sin(kx))))
    else if (sin(ky) <= 5d-99) then
        tmp = (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) <= -1e-42) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -2e-281) {
		tmp = Math.abs((Math.sin(th) * (ky / Math.sin(kx))));
	} else if (Math.sin(ky) <= 5e-99) {
		tmp = (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) <= -1e-42:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -2e-281:
		tmp = math.fabs((math.sin(th) * (ky / math.sin(kx))))
	elif math.sin(ky) <= 5e-99:
		tmp = (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) <= -1e-42)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -2e-281)
		tmp = abs(Float64(sin(th) * Float64(ky / sin(kx))));
	elseif (sin(ky) <= 5e-99)
		tmp = Float64(Float64(ky * 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) <= -1e-42)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -2e-281)
		tmp = abs((sin(th) * (ky / sin(kx))));
	elseif (sin(ky) <= 5e-99)
		tmp = (ky * sin(th)) / sin(kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -1e-42], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-281], N[Abs[N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-99], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.00000000000000004e-42

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -2e-281 < (sin.f64 ky) < 4.99999999999999969e-99

    1. Initial program 89.8%

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

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

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

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

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

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

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

    if 4.99999999999999969e-99 < (sin.f64 ky)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 8: 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 93.4%

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

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

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

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

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

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

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

Alternative 9: 75.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;th \leq -2.55 \lor \neg \left(th \leq 9.5\right):\\ \;\;\;\;\frac{ky \cdot \sin th}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{t_1} \cdot th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (or (<= th -2.55) (not (<= th 9.5)))
     (/ (* ky (sin th)) t_1)
     (* (/ (sin ky) t_1) th))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if ((th <= -2.55) || !(th <= 9.5)) {
		tmp = (ky * sin(th)) / t_1;
	} else {
		tmp = (sin(ky) / t_1) * th;
	}
	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 ((th <= -2.55) || !(th <= 9.5)) {
		tmp = (ky * Math.sin(th)) / t_1;
	} else {
		tmp = (Math.sin(ky) / t_1) * th;
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if (th <= -2.55) or not (th <= 9.5):
		tmp = (ky * math.sin(th)) / t_1
	else:
		tmp = (math.sin(ky) / t_1) * th
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if ((th <= -2.55) || !(th <= 9.5))
		tmp = Float64(Float64(ky * sin(th)) / t_1);
	else
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if ((th <= -2.55) || ~((th <= 9.5)))
		tmp = (ky * sin(th)) / t_1;
	else
		tmp = (sin(ky) / t_1) * th;
	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[Or[LessEqual[th, -2.55], N[Not[LessEqual[th, 9.5]], $MachinePrecision]], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision]]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < -2.5499999999999998 or 9.5 < th

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

    if -2.5499999999999998 < th < 9.5

    1. Initial program 94.5%

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{th} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification76.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq -2.55 \lor \neg \left(th \leq 9.5\right):\\ \;\;\;\;\frac{ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \end{array} \]

Alternative 10: 47.4% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999992e-72 < (sin.f64 ky) < 4.99999999999999969e-99

    1. Initial program 82.8%

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

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

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

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

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

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

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

    if 4.99999999999999969e-99 < (sin.f64 ky)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 11: 47.4% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-71}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-99}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -1e-71)
   (fabs (sin th))
   (if (<= (sin ky) 5e-99) (/ (sin th) (/ (sin kx) ky)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -1e-71) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 5e-99) {
		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) <= (-1d-71)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 5d-99) 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) <= -1e-71) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 5e-99) {
		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) <= -1e-71:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 5e-99:
		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) <= -1e-71)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-99)
		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) <= -1e-71)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-99)
		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], -1e-71], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-99], 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 -1 \cdot 10^{-71}:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-99}:\\
\;\;\;\;\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) < -9.9999999999999992e-72

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -9.9999999999999992e-72 < (sin.f64 ky) < 4.99999999999999969e-99

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

    if 4.99999999999999969e-99 < (sin.f64 ky)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 12: 46.8% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-57}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-99}:\\ \;\;\;\;\frac{ky \cdot \sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -1e-57)
   (fabs (sin th))
   (if (<= (sin ky) 5e-99) (/ (* ky (sin th)) (sin kx)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -1e-57) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= 5e-99) {
		tmp = (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) <= (-1d-57)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= 5d-99) then
        tmp = (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) <= -1e-57) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= 5e-99) {
		tmp = (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) <= -1e-57:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= 5e-99:
		tmp = (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) <= -1e-57)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-99)
		tmp = Float64(Float64(ky * 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) <= -1e-57)
		tmp = abs(sin(th));
	elseif (sin(ky) <= 5e-99)
		tmp = (ky * sin(th)) / sin(kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -1e-57], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-99], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

        \[\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 -9.99999999999999955e-58 < (sin.f64 ky) < 4.99999999999999969e-99

    1. Initial program 83.1%

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

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

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

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

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

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

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

    if 4.99999999999999969e-99 < (sin.f64 ky)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

Alternative 13: 33.0% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;ky \leq -1.6 \cdot 10^{-103}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -6.9 \cdot 10^{-152}:\\
\;\;\;\;\frac{ky}{\sin kx \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\

\mathbf{elif}\;ky \leq -1 \cdot 10^{-228}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;ky \leq 940000000000:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < -1.59999999999999988e-103 or -6.90000000000000039e-152 < ky < -1.00000000000000003e-228 or 9.4e11 < ky

    1. Initial program 94.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.59999999999999988e-103 < ky < -6.90000000000000039e-152

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \color{blue}{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}} \]
    7. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}\right)} \]
    8. Simplified57.0%

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

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

    if -1.00000000000000003e-228 < ky < 4.9999999999999995e-97

    1. Initial program 87.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.9999999999999995e-97 < ky < 9.4e11

    1. Initial program 99.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.6 \cdot 10^{-103}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -6.9 \cdot 10^{-152}:\\ \;\;\;\;\frac{ky}{\sin kx \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;ky \leq -1 \cdot 10^{-228}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq 5 \cdot 10^{-97}:\\ \;\;\;\;th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{elif}\;ky \leq 940000000000:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]

Alternative 14: 33.4% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;ky \leq -4.5 \cdot 10^{-104}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -1.05 \cdot 10^{-150}:\\
\;\;\;\;\frac{ky}{\sin kx \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\

\mathbf{elif}\;ky \leq -3 \cdot 10^{-205}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;ky \leq 940000000000:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < -4.4999999999999997e-104 or -1.0500000000000001e-150 < ky < -3e-205 or 9.4e11 < ky

    1. Initial program 95.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -4.4999999999999997e-104 < ky < -1.0500000000000001e-150

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \color{blue}{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}} \]
    7. Step-by-step derivation
      1. *-commutative57.0%

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}\right)} \]
    8. Simplified57.0%

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

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

    if -3e-205 < ky < 3.6000000000000001e-166

    1. Initial program 82.3%

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

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

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

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

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

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

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

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

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

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

    if 3.6000000000000001e-166 < ky < 9.4e11

    1. Initial program 95.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -4.5 \cdot 10^{-104}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq -1.05 \cdot 10^{-150}:\\ \;\;\;\;\frac{ky}{\sin kx \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;ky \leq -3 \cdot 10^{-205}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq 3.6 \cdot 10^{-166}:\\ \;\;\;\;\frac{ky \cdot \sin th}{kx}\\ \mathbf{elif}\;ky \leq 940000000000:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]

Alternative 15: 31.4% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.05e10 or 4.20000000000000021e-174 < ky

    1. Initial program 98.7%

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

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

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

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

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

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

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

    if -1.05e10 < ky < 4.20000000000000021e-174

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|th \cdot \frac{ky}{kx}\right|} \]
    10. Simplified29.5%

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

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

Alternative 16: 32.8% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6.2e9 or 1.90000000000000015e-173 < ky

    1. Initial program 98.7%

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

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

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

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

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

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

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

    if -6.2e9 < ky < 1.90000000000000015e-173

    1. Initial program 82.6%

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

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

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

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

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

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

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

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

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

Alternative 17: 33.8% accurate, 6.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -10500000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 3.2 \cdot 10^{-166}:\\ \;\;\;\;\frac{\sin th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -10500000000.0)
   (sin th)
   (if (<= ky 3.2e-166) (/ (sin th) (/ kx ky)) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -10500000000.0) {
		tmp = sin(th);
	} else if (ky <= 3.2e-166) {
		tmp = sin(th) / (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 (ky <= (-10500000000.0d0)) then
        tmp = sin(th)
    else if (ky <= 3.2d-166) then
        tmp = sin(th) / (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 (ky <= -10500000000.0) {
		tmp = Math.sin(th);
	} else if (ky <= 3.2e-166) {
		tmp = Math.sin(th) / (kx / ky);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -10500000000.0:
		tmp = math.sin(th)
	elif ky <= 3.2e-166:
		tmp = math.sin(th) / (kx / ky)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 3.2e-166)
		tmp = Float64(sin(th) / Float64(kx / ky));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 3.2e-166)
		tmp = sin(th) / (kx / ky);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -10500000000.0], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 3.2e-166], N[(N[Sin[th], $MachinePrecision] / N[(kx / ky), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.05e10 or 3.20000000000000001e-166 < ky

    1. Initial program 98.7%

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

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

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

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

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

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

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

    if -1.05e10 < ky < 3.20000000000000001e-166

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 18: 33.1% accurate, 6.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -10500000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 3.8 \cdot 10^{-166}:\\ \;\;\;\;\frac{ky \cdot \sin th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -10500000000.0)
   (sin th)
   (if (<= ky 3.8e-166) (/ (* ky (sin th)) kx) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -10500000000.0) {
		tmp = sin(th);
	} else if (ky <= 3.8e-166) {
		tmp = (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 (ky <= (-10500000000.0d0)) then
        tmp = sin(th)
    else if (ky <= 3.8d-166) then
        tmp = (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 (ky <= -10500000000.0) {
		tmp = Math.sin(th);
	} else if (ky <= 3.8e-166) {
		tmp = (ky * Math.sin(th)) / kx;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -10500000000.0:
		tmp = math.sin(th)
	elif ky <= 3.8e-166:
		tmp = (ky * math.sin(th)) / kx
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 3.8e-166)
		tmp = Float64(Float64(ky * sin(th)) / kx);
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 3.8e-166)
		tmp = (ky * sin(th)) / kx;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -10500000000.0], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 3.8e-166], N[(N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision] / kx), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.05e10 or 3.79999999999999982e-166 < ky

    1. Initial program 98.7%

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

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

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

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

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

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

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

    if -1.05e10 < ky < 3.79999999999999982e-166

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

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

Alternative 19: 30.6% accurate, 6.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -10500000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 2.8 \cdot 10^{-166}:\\ \;\;\;\;\frac{ky \cdot th}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky -10500000000.0)
   (sin th)
   (if (<= ky 2.8e-166) (/ (* ky th) kx) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= -10500000000.0) {
		tmp = sin(th);
	} else if (ky <= 2.8e-166) {
		tmp = (ky * 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 (ky <= (-10500000000.0d0)) then
        tmp = sin(th)
    else if (ky <= 2.8d-166) then
        tmp = (ky * 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 (ky <= -10500000000.0) {
		tmp = Math.sin(th);
	} else if (ky <= 2.8e-166) {
		tmp = (ky * th) / kx;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= -10500000000.0:
		tmp = math.sin(th)
	elif ky <= 2.8e-166:
		tmp = (ky * th) / kx
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 2.8e-166)
		tmp = Float64(Float64(ky * th) / kx);
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= -10500000000.0)
		tmp = sin(th);
	elseif (ky <= 2.8e-166)
		tmp = (ky * th) / kx;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, -10500000000.0], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 2.8e-166], N[(N[(ky * th), $MachinePrecision] / kx), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.05e10 or 2.7999999999999999e-166 < ky

    1. Initial program 98.7%

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

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

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

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

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

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

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

    if -1.05e10 < ky < 2.7999999999999999e-166

    1. Initial program 82.8%

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

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

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

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

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

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

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

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

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

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

Alternative 20: 21.6% accurate, 54.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -1.3 \cdot 10^{-8} \lor \neg \left(ky \leq 1.8 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;\frac{ky \cdot th}{kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= ky -1.3e-8) (not (<= ky 1.8e-160)))
   (/ 1.0 (+ (/ 1.0 th) (* th 0.16666666666666666)))
   (/ (* ky th) kx)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -1.3e-8) || !(ky <= 1.8e-160)) {
		tmp = 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
	} else {
		tmp = (ky * th) / 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 ((ky <= (-1.3d-8)) .or. (.not. (ky <= 1.8d-160))) then
        tmp = 1.0d0 / ((1.0d0 / th) + (th * 0.16666666666666666d0))
    else
        tmp = (ky * th) / kx
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -1.3e-8) || !(ky <= 1.8e-160)) {
		tmp = 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
	} else {
		tmp = (ky * th) / kx;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (ky <= -1.3e-8) or not (ky <= 1.8e-160):
		tmp = 1.0 / ((1.0 / th) + (th * 0.16666666666666666))
	else:
		tmp = (ky * th) / kx
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((ky <= -1.3e-8) || !(ky <= 1.8e-160))
		tmp = Float64(1.0 / Float64(Float64(1.0 / th) + Float64(th * 0.16666666666666666)));
	else
		tmp = Float64(Float64(ky * th) / kx);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((ky <= -1.3e-8) || ~((ky <= 1.8e-160)))
		tmp = 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
	else
		tmp = (ky * th) / kx;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[ky, -1.3e-8], N[Not[LessEqual[ky, 1.8e-160]], $MachinePrecision]], N[(1.0 / N[(N[(1.0 / th), $MachinePrecision] + N[(th * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(ky * th), $MachinePrecision] / kx), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.3 \cdot 10^{-8} \lor \neg \left(ky \leq 1.8 \cdot 10^{-160}\right):\\
\;\;\;\;\frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.3000000000000001e-8 or 1.7999999999999999e-160 < ky

    1. Initial program 99.3%

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

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

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

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

        \[\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. Step-by-step derivation
      1. div-inv99.4%

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \color{blue}{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}} \]
    7. Step-by-step derivation
      1. *-commutative55.3%

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]

    if -1.3000000000000001e-8 < ky < 1.7999999999999999e-160

    1. Initial program 81.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.3 \cdot 10^{-8} \lor \neg \left(ky \leq 1.8 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;\frac{ky \cdot th}{kx}\\ \end{array} \]

Alternative 21: 22.0% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.1 \cdot 10^{-6}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.1000000000000001e-6 or 1.70000000000000011e-160 < ky

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

    if -1.1000000000000001e-6 < ky < 1.70000000000000011e-160

    1. Initial program 81.9%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.1 \cdot 10^{-6}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.7 \cdot 10^{-160}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 22: 21.3% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -5.5 \cdot 10^{-7}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -5.5000000000000003e-7 or 1.7999999999999999e-160 < ky

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

    if -5.5000000000000003e-7 < ky < 1.7999999999999999e-160

    1. Initial program 81.9%

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

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

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

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

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

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

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

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

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

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

Alternative 23: 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 93.4%

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  6. Final simplification13.4%

    \[\leadsto th \]

Reproduce

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