Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 21.6s
Alternatives: 17
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 17 alternatives:

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

Initial Program: 93.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 61.2% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
t_2 := \sin ky \cdot t\_1\\
\mathbf{if}\;\sin th \leq -0.001:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;\sin th \leq 0.75:\\
\;\;\;\;\left|ky \cdot t\_1\right|\\

\mathbf{elif}\;\sin th \leq 0.93:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1e-3 < (sin.f64 th) < 2.0000000000000001e-4

    1. Initial program 95.0%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
    4. Applied egg-rr22.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin th}\right)}^{-1}} \]
    9. Step-by-step derivation
      1. unpow-199.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{1}{\frac{1 \cdot \color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{th}} \]
      6. *-lft-identity99.0%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-4 < (sin.f64 th) < 0.75

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.75 < (sin.f64 th) < 0.930000000000000049

    1. Initial program 99.4%

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

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

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

Alternative 3: 77.2% accurate, 1.1× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1 \cdot \color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}{th \cdot \sin ky}} \]
      5. *-lft-identity47.2%

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

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

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 ky) < 1e-13

    1. Initial program 87.5%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
    4. Applied egg-rr33.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1e-13 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 4: 49.4% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{\sin kx}{ky}}\right)}^{2}}} \]
    6. Taylor expanded in ky around -inf 57.1%

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

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

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

        \[\leadsto -\color{blue}{\sin th \cdot \frac{ky}{\sin kx}} \]
      4. distribute-lft-neg-in57.3%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.00000000000000026e-102

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

    if 5.00000000000000026e-102 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
    4. Applied egg-rr39.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-102}:\\ \;\;\;\;\frac{1}{\frac{\sin ky}{\sin ky \cdot \sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 49.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 10^{-130}:\\
\;\;\;\;\frac{1}{\frac{1}{\sin th}}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{\sin kx}{ky}}\right)}^{2}}} \]
    6. Taylor expanded in ky around -inf 57.1%

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

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

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

        \[\leadsto -\color{blue}{\sin th \cdot \frac{ky}{\sin kx}} \]
      4. distribute-lft-neg-in57.3%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 1.0000000000000001e-130

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-130 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
    4. Applied egg-rr39.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 10^{-130}:\\ \;\;\;\;\frac{1}{\frac{1}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 99.6% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
  4. Applied egg-rr44.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 63.2% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin kx, \sin ky\right)\\ \mathbf{if}\;th \leq 0.00046:\\ \;\;\;\;\sin ky \cdot \frac{1}{\frac{t\_1}{th}}\\ \mathbf{elif}\;th \leq 5.3 \cdot 10^{+39} \lor \neg \left(th \leq 3.1 \cdot 10^{+73}\right):\\ \;\;\;\;\frac{1}{\frac{t\_1}{ky \cdot \sin th}}\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin kx) (sin ky))))
   (if (<= th 0.00046)
     (* (sin ky) (/ 1.0 (/ t_1 th)))
     (if (or (<= th 5.3e+39) (not (<= th 3.1e+73)))
       (/ 1.0 (/ t_1 (* ky (sin th))))
       (fabs (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(kx), sin(ky));
	double tmp;
	if (th <= 0.00046) {
		tmp = sin(ky) * (1.0 / (t_1 / th));
	} else if ((th <= 5.3e+39) || !(th <= 3.1e+73)) {
		tmp = 1.0 / (t_1 / (ky * sin(th)));
	} else {
		tmp = fabs(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 (th <= 0.00046) {
		tmp = Math.sin(ky) * (1.0 / (t_1 / th));
	} else if ((th <= 5.3e+39) || !(th <= 3.1e+73)) {
		tmp = 1.0 / (t_1 / (ky * Math.sin(th)));
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(kx), math.sin(ky))
	tmp = 0
	if th <= 0.00046:
		tmp = math.sin(ky) * (1.0 / (t_1 / th))
	elif (th <= 5.3e+39) or not (th <= 3.1e+73):
		tmp = 1.0 / (t_1 / (ky * math.sin(th)))
	else:
		tmp = math.fabs(math.sin(th))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky))
	tmp = 0.0
	if (th <= 0.00046)
		tmp = Float64(sin(ky) * Float64(1.0 / Float64(t_1 / th)));
	elseif ((th <= 5.3e+39) || !(th <= 3.1e+73))
		tmp = Float64(1.0 / Float64(t_1 / Float64(ky * sin(th))));
	else
		tmp = abs(sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(kx), sin(ky));
	tmp = 0.0;
	if (th <= 0.00046)
		tmp = sin(ky) * (1.0 / (t_1 / th));
	elseif ((th <= 5.3e+39) || ~((th <= 3.1e+73)))
		tmp = 1.0 / (t_1 / (ky * sin(th)));
	else
		tmp = abs(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[th, 0.00046], N[(N[Sin[ky], $MachinePrecision] * N[(1.0 / N[(t$95$1 / th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 5.3e+39], N[Not[LessEqual[th, 3.1e+73]], $MachinePrecision]], N[(1.0 / N[(t$95$1 / N[(ky * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;th \leq 5.3 \cdot 10^{+39} \lor \neg \left(th \leq 3.1 \cdot 10^{+73}\right):\\
\;\;\;\;\frac{1}{\frac{t\_1}{ky \cdot \sin th}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < 4.6000000000000001e-4

    1. Initial program 93.8%

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th\right)} - 1} \]
    4. Applied egg-rr37.6%

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}} \]
      8. unpow293.7%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{{\left(\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{\sin th}\right)}^{-1}} \]
    9. Step-by-step derivation
      1. unpow-199.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{1}{\frac{1 \cdot \color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{th}} \]
      6. *-lft-identity61.5%

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

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

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

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

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

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

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

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

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

    if 4.6000000000000001e-4 < th < 5.29999999999999979e39 or 3.1e73 < th

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

    if 5.29999999999999979e39 < th < 3.1e73

    1. Initial program 99.7%

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

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\sin th}}} \]
    6. Step-by-step derivation
      1. remove-double-div37.2%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt12.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow223.1%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 0.00046:\\ \;\;\;\;\sin ky \cdot \frac{1}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \mathbf{elif}\;th \leq 5.3 \cdot 10^{+39} \lor \neg \left(th \leq 3.1 \cdot 10^{+73}\right):\\ \;\;\;\;\frac{1}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{ky \cdot \sin th}}\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 46.2% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{\sin kx}{ky}}\right)}^{2}}} \]
    6. Taylor expanded in ky around -inf 57.1%

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

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

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

        \[\leadsto -\color{blue}{\sin th \cdot \frac{ky}{\sin kx}} \]
      4. distribute-lft-neg-in57.3%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.00000000000000003e-42

    1. Initial program 85.8%

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

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

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

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

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

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

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

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

    if 5.00000000000000003e-42 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-42}:\\ \;\;\;\;\frac{1}{\frac{1}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 26.6% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 6.5 \cdot 10^{-80}:\\
\;\;\;\;\frac{\frac{\sin th}{kx}}{\frac{1}{ky}}\\

\mathbf{elif}\;ky \leq 8.5 \cdot 10^{+15}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 90.8%

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

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

        \[\leadsto \color{blue}{\log \left(e^{\frac{ky \cdot \sin th}{\sin kx}}\right)} \]
      2. *-commutative14.7%

        \[\leadsto \log \left(e^{\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}}\right) \]
      3. associate-/l*14.7%

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\sin th}{\frac{\sin kx}{ky}}}\right)} \]
    6. Step-by-step derivation
      1. rem-log-exp31.1%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
      2. div-inv31.1%

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

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

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

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

    if 6.49999999999999984e-80 < ky < 8.5e15

    1. Initial program 99.8%

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

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

    if 8.5e15 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\sin th}}} \]
    6. Step-by-step derivation
      1. remove-double-div28.4%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt15.8%

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

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

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

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

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

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

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

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

Alternative 10: 33.8% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 3.4 \cdot 10^{-73}:\\
\;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\

\mathbf{elif}\;ky \leq 8.5 \cdot 10^{+15}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 90.8%

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

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

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

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

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

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

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

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

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

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

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

    if 3.40000000000000021e-73 < ky < 8.5e15

    1. Initial program 99.8%

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

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

    if 8.5e15 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{\sin th}}} \]
    6. Step-by-step derivation
      1. remove-double-div28.4%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt15.8%

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

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

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

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

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

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

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

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

Alternative 11: 26.4% accurate, 6.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 2.5 \cdot 10^{-87}:\\
\;\;\;\;\frac{\frac{\sin th}{kx}}{\frac{1}{ky}}\\

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


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

    1. Initial program 90.8%

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

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

        \[\leadsto \color{blue}{\log \left(e^{\frac{ky \cdot \sin th}{\sin kx}}\right)} \]
      2. *-commutative14.7%

        \[\leadsto \log \left(e^{\frac{\color{blue}{\sin th \cdot ky}}{\sin kx}}\right) \]
      3. associate-/l*14.7%

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

      \[\leadsto \color{blue}{\log \left(e^{\frac{\sin th}{\frac{\sin kx}{ky}}}\right)} \]
    6. Step-by-step derivation
      1. rem-log-exp31.1%

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
      2. div-inv31.1%

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

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

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

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

    if 2.50000000000000021e-87 < ky

    1. Initial program 99.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 2.5 \cdot 10^{-87}:\\ \;\;\;\;\frac{\frac{\sin th}{kx}}{\frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 26.4% accurate, 6.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 2.1 \cdot 10^{-85}:\\
\;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\

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


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

    1. Initial program 90.8%

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

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

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

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

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

    if 2.1e-85 < ky

    1. Initial program 99.7%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 2.1 \cdot 10^{-85}:\\ \;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 23.8% accurate, 6.8× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{1}{\sin th}} \end{array} \]
(FPCore (kx ky th) :precision binary64 (/ 1.0 (/ 1.0 (sin th))))
double code(double kx, double ky, double th) {
	return 1.0 / (1.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 = 1.0d0 / (1.0d0 / sin(th))
end function
public static double code(double kx, double ky, double th) {
	return 1.0 / (1.0 / Math.sin(th));
}
def code(kx, ky, th):
	return 1.0 / (1.0 / math.sin(th))
function code(kx, ky, th)
	return Float64(1.0 / Float64(1.0 / sin(th)))
end
function tmp = code(kx, ky, th)
	tmp = 1.0 / (1.0 / sin(th));
end
code[kx_, ky_, th_] := N[(1.0 / N[(1.0 / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\frac{1}{\sin th}}
\end{array}
Derivation
  1. Initial program 93.4%

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{\sin th}}} \]
  6. Final simplification20.0%

    \[\leadsto \frac{1}{\frac{1}{\sin th}} \]
  7. Add Preprocessing

Alternative 14: 23.9% accurate, 7.0× speedup?

\[\begin{array}{l} \\ \sin th \end{array} \]
(FPCore (kx ky th) :precision binary64 (sin th))
double code(double kx, double ky, double th) {
	return 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(th)
end function
public static double code(double kx, double ky, double th) {
	return Math.sin(th);
}
def code(kx, ky, th):
	return math.sin(th)
function code(kx, ky, th)
	return sin(th)
end
function tmp = code(kx, ky, th)
	tmp = sin(th);
end
code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
\begin{array}{l}

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

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

    \[\leadsto \color{blue}{\sin th} \]
  4. Final simplification19.7%

    \[\leadsto \sin th \]
  5. Add Preprocessing

Alternative 15: 14.5% accurate, 78.8× speedup?

\[\begin{array}{l} \\ \frac{1}{th \cdot 0.16666666666666666 + \frac{1}{th}} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (/ 1.0 (+ (* th 0.16666666666666666) (/ 1.0 th))))
double code(double kx, double ky, double th) {
	return 1.0 / ((th * 0.16666666666666666) + (1.0 / th));
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = 1.0d0 / ((th * 0.16666666666666666d0) + (1.0d0 / th))
end function
public static double code(double kx, double ky, double th) {
	return 1.0 / ((th * 0.16666666666666666) + (1.0 / th));
}
def code(kx, ky, th):
	return 1.0 / ((th * 0.16666666666666666) + (1.0 / th))
function code(kx, ky, th)
	return Float64(1.0 / Float64(Float64(th * 0.16666666666666666) + Float64(1.0 / th)))
end
function tmp = code(kx, ky, th)
	tmp = 1.0 / ((th * 0.16666666666666666) + (1.0 / th));
end
code[kx_, ky_, th_] := N[(1.0 / N[(N[(th * 0.16666666666666666), $MachinePrecision] + N[(1.0 / th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{th \cdot 0.16666666666666666 + \frac{1}{th}}
\end{array}
Derivation
  1. Initial program 93.4%

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{0.16666666666666666 \cdot th + \frac{1}{th}}} \]
  7. Final simplification13.0%

    \[\leadsto \frac{1}{th \cdot 0.16666666666666666 + \frac{1}{th}} \]
  8. Add Preprocessing

Alternative 16: 13.8% accurate, 141.8× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{th}}} \]
  7. Final simplification12.3%

    \[\leadsto \frac{1}{\frac{1}{th}} \]
  8. Add Preprocessing

Alternative 17: 13.8% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  7. Final simplification12.0%

    \[\leadsto th \]
  8. Add Preprocessing

Reproduce

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