Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 23.5s
Alternatives: 20
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 20 alternatives:

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

Initial Program: 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 91.3%

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow291.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. Final simplification99.7%

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

Alternative 2: 74.9% accurate, 0.9× speedup?

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

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

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

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

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

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


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

    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 \color{blue}{\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. clear-num99.7%

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

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

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

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

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

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

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

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

    if -0.63500000000000001 < (sin.f64 ky) < -0.17999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 3: 74.9% accurate, 0.9× speedup?

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

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

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

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

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

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


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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

    if -0.63500000000000001 < (sin.f64 ky) < -0.17999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

    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-*l/99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 4: 74.9% accurate, 0.9× speedup?

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

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

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

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

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

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


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

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

    if -0.63500000000000001 < (sin.f64 ky) < -0.17999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

    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-*l/99.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 5: 74.9% accurate, 0.9× speedup?

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

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

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

\mathbf{elif}\;\sin ky \leq -0.005:\\
\;\;\;\;t_2\\

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot 1}{th}} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      8. *-rgt-identity56.9%

        \[\leadsto \frac{\sin ky}{\frac{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{th} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      9. *-lft-identity56.9%

        \[\leadsto \frac{\sin ky}{\frac{\color{blue}{1 \cdot \mathsf{hypot}\left(\sin ky, \sin kx\right)}}{th} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      10. associate-*l/56.9%

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin ky, \sin kx\right)} + 0.16666666666666666 \cdot \left(th \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \]
      11. associate-*r*56.9%

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin ky, \sin kx\right) + \color{blue}{\left(0.16666666666666666 \cdot th\right) \cdot \sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    10. Simplified56.9%

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

    if -0.658000000000000029 < (sin.f64 ky) < -0.17999999999999999

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.2%

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.658:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;\sin ky \leq -0.18:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -0.005:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;\sin ky \leq 10^{-15}:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 72.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.3%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow281.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 99.2%

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 7: 72.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.5%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow281.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 98.6%

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 8: 72.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 1.0000000000000001e-15

    1. Initial program 81.5%

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 9: 60.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -9.99999999999999939e-12 < (sin.f64 ky) < 1.00000000000000001e-35

    1. Initial program 80.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    8. Applied egg-rr72.0%

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

    if 1.00000000000000001e-35 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 10: 49.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-11}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -4 \cdot 10^{-163}:\\ \;\;\;\;ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{0.5 + -0.5 \cdot \cos \left(kx \cdot 2\right)}}\right)\\ \mathbf{elif}\;\sin ky \leq 10^{-35}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -1e-11)
   (fabs (sin th))
   (if (<= (sin ky) -4e-163)
     (* ky (* (sin th) (sqrt (/ 1.0 (+ 0.5 (* -0.5 (cos (* kx 2.0))))))))
     (if (<= (sin ky) 1e-35) (* ky (/ (sin th) (sin kx))) (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -1e-11) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -4e-163) {
		tmp = ky * (sin(th) * sqrt((1.0 / (0.5 + (-0.5 * cos((kx * 2.0)))))));
	} else if (sin(ky) <= 1e-35) {
		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-11)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= (-4d-163)) then
        tmp = ky * (sin(th) * sqrt((1.0d0 / (0.5d0 + ((-0.5d0) * cos((kx * 2.0d0)))))))
    else if (sin(ky) <= 1d-35) 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-11) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -4e-163) {
		tmp = ky * (Math.sin(th) * Math.sqrt((1.0 / (0.5 + (-0.5 * Math.cos((kx * 2.0)))))));
	} else if (Math.sin(ky) <= 1e-35) {
		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-11:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -4e-163:
		tmp = ky * (math.sin(th) * math.sqrt((1.0 / (0.5 + (-0.5 * math.cos((kx * 2.0)))))))
	elif math.sin(ky) <= 1e-35:
		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-11)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -4e-163)
		tmp = Float64(ky * Float64(sin(th) * sqrt(Float64(1.0 / Float64(0.5 + Float64(-0.5 * cos(Float64(kx * 2.0))))))));
	elseif (sin(ky) <= 1e-35)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -1e-11)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -4e-163)
		tmp = ky * (sin(th) * sqrt((1.0 / (0.5 + (-0.5 * cos((kx * 2.0)))))));
	elseif (sin(ky) <= 1e-35)
		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-11], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -4e-163], N[(ky * N[(N[Sin[th], $MachinePrecision] * N[Sqrt[N[(1.0 / N[(0.5 + N[(-0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-35], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -9.99999999999999939e-12 < (sin.f64 ky) < -3.99999999999999969e-163

    1. Initial program 96.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \]
    7. Step-by-step derivation
      1. associate-*l*48.8%

        \[\leadsto \color{blue}{ky \cdot \left(\sin th \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}\right)} \]
      2. cancel-sign-sub-inv48.8%

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

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

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

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

    if -3.99999999999999969e-163 < (sin.f64 ky) < 1.00000000000000001e-35

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-35 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 11: 49.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -1 \cdot 10^{-11}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq -4 \cdot 10^{-163}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin ky \leq 10^{-35}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -1e-11)
   (fabs (sin th))
   (if (<= (sin ky) -4e-163)
     (* (sin th) (/ ky (sqrt (- 0.5 (* 0.5 (cos (* kx 2.0)))))))
     (if (<= (sin ky) 1e-35) (* ky (/ (sin th) (sin kx))) (sin th)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -1e-11) {
		tmp = fabs(sin(th));
	} else if (sin(ky) <= -4e-163) {
		tmp = sin(th) * (ky / sqrt((0.5 - (0.5 * cos((kx * 2.0))))));
	} else if (sin(ky) <= 1e-35) {
		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-11)) then
        tmp = abs(sin(th))
    else if (sin(ky) <= (-4d-163)) then
        tmp = sin(th) * (ky / sqrt((0.5d0 - (0.5d0 * cos((kx * 2.0d0))))))
    else if (sin(ky) <= 1d-35) 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-11) {
		tmp = Math.abs(Math.sin(th));
	} else if (Math.sin(ky) <= -4e-163) {
		tmp = Math.sin(th) * (ky / Math.sqrt((0.5 - (0.5 * Math.cos((kx * 2.0))))));
	} else if (Math.sin(ky) <= 1e-35) {
		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-11:
		tmp = math.fabs(math.sin(th))
	elif math.sin(ky) <= -4e-163:
		tmp = math.sin(th) * (ky / math.sqrt((0.5 - (0.5 * math.cos((kx * 2.0))))))
	elif math.sin(ky) <= 1e-35:
		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-11)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -4e-163)
		tmp = Float64(sin(th) * Float64(ky / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx * 2.0)))))));
	elseif (sin(ky) <= 1e-35)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -1e-11)
		tmp = abs(sin(th));
	elseif (sin(ky) <= -4e-163)
		tmp = sin(th) * (ky / sqrt((0.5 - (0.5 * cos((kx * 2.0))))));
	elseif (sin(ky) <= 1e-35)
		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-11], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -4e-163], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 1e-35], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -9.99999999999999939e-12 < (sin.f64 ky) < -3.99999999999999969e-163

    1. Initial program 96.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.99999999999999969e-163 < (sin.f64 ky) < 1.00000000000000001e-35

    1. Initial program 73.7%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-35 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 12: 47.0% accurate, 1.7× speedup?

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

\mathbf{elif}\;\sin ky \leq 10^{-35}:\\
\;\;\;\;\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) < -4.9999999999999995e-94

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -4.9999999999999995e-94 < (sin.f64 ky) < 1.00000000000000001e-35

    1. Initial program 76.8%

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

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

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

        \[\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.5%

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

    if 1.00000000000000001e-35 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 13: 47.0% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

    if -4.9999999999999995e-94 < (sin.f64 ky) < 1.00000000000000001e-35

    1. Initial program 76.8%

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000001e-35 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 14: 38.8% accurate, 2.3× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 5.2 \cdot 10^{-204}:\\
\;\;\;\;0\\

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


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

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

    if -2.3499999999999999e-222 < (sin.f64 ky) < 5.19999999999999965e-204

    1. Initial program 71.1%

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

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

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

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

      \[\leadsto \log \color{blue}{1} \]

    if 5.19999999999999965e-204 < (sin.f64 ky)

    1. Initial program 96.2%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2.35 \cdot 10^{-222}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 5.2 \cdot 10^{-204}:\\ \;\;\;\;0\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 15: 28.4% accurate, 3.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq 4.4 \cdot 10^{-202}:\\
\;\;\;\;th \cdot \left(\sin ky \cdot \left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right)\right)\\

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


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

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot \left(kx \cdot \sin th\right) + \frac{\sin th}{kx}\right)} \cdot \sin ky \]
    6. Taylor expanded in th around 0 9.5%

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

    if 4.40000000000000016e-202 < (sin.f64 ky)

    1. Initial program 97.1%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq 4.4 \cdot 10^{-202}:\\ \;\;\;\;th \cdot \left(\sin ky \cdot \left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 16: 26.9% accurate, 6.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.35 \cdot 10^{+14}:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 1.35e14

    1. Initial program 88.6%

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

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

    if 1.35e14 < kx

    1. Initial program 99.5%

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

      \[\leadsto \color{blue}{\sin th} \]
    3. Step-by-step derivation
      1. expm1-log1p-u9.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    4. Applied egg-rr9.2%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-udef18.6%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-udef18.6%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log18.6%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative18.6%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    6. Applied egg-rr18.6%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.35 \cdot 10^{+14}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\sin th + 1\right) + -1\\ \end{array} \]

Alternative 17: 30.1% accurate, 6.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -8500000000 \lor \neg \left(ky \leq 1.35 \cdot 10^{-204}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8.5e9 or 1.34999999999999996e-204 < ky

    1. Initial program 97.5%

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

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

    if -8.5e9 < ky < 1.34999999999999996e-204

    1. Initial program 78.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -8500000000 \lor \neg \left(ky \leq 1.35 \cdot 10^{-204}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 18: 16.5% accurate, 6.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 1.26 \cdot 10^{+86}:\\ \;\;\;\;\mathsf{expm1}\left(th\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= kx 1.26e+86) (expm1 th) 0.0))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.26e+86) {
		tmp = expm1(th);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 1.26e+86) {
		tmp = Math.expm1(th);
	} else {
		tmp = 0.0;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 1.26e+86:
		tmp = math.expm1(th)
	else:
		tmp = 0.0
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 1.26e+86)
		tmp = expm1(th);
	else
		tmp = 0.0;
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[kx, 1.26e+86], N[(Exp[th] - 1), $MachinePrecision], 0.0]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 1.26 \cdot 10^{+86}:\\
\;\;\;\;\mathsf{expm1}\left(th\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 1.25999999999999999e86

    1. Initial program 89.4%

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

      \[\leadsto \color{blue}{\sin th} \]
    3. Step-by-step derivation
      1. expm1-log1p-u30.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    4. Applied egg-rr30.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    5. Taylor expanded in th around 0 19.2%

      \[\leadsto \mathsf{expm1}\left(\color{blue}{th}\right) \]

    if 1.25999999999999999e86 < kx

    1. Initial program 99.5%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 1.26 \cdot 10^{+86}:\\ \;\;\;\;\mathsf{expm1}\left(th\right)\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array} \]

Alternative 19: 14.6% accurate, 7.0× speedup?

\[\begin{array}{l} \\ \mathsf{expm1}\left(th\right) \end{array} \]
(FPCore (kx ky th) :precision binary64 (expm1 th))
double code(double kx, double ky, double th) {
	return expm1(th);
}
public static double code(double kx, double ky, double th) {
	return Math.expm1(th);
}
def code(kx, ky, th):
	return math.expm1(th)
function code(kx, ky, th)
	return expm1(th)
end
code[kx_, ky_, th_] := N[(Exp[th] - 1), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{expm1}\left(th\right)
\end{array}
Derivation
  1. Initial program 91.3%

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

    \[\leadsto \color{blue}{\sin th} \]
  3. Step-by-step derivation
    1. expm1-log1p-u26.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
  4. Applied egg-rr26.4%

    \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
  5. Taylor expanded in th around 0 16.6%

    \[\leadsto \mathsf{expm1}\left(\color{blue}{th}\right) \]
  6. Final simplification16.6%

    \[\leadsto \mathsf{expm1}\left(th\right) \]

Alternative 20: 13.6% accurate, 709.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  4. Final simplification15.9%

    \[\leadsto th \]

Reproduce

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