Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.6% → 99.6%
Time: 23.5s
Alternatives: 21
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 21 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.6% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 73.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin th \leq -0.04 \lor \neg \left(\sin th \leq 5 \cdot 10^{-31}\right):\\ \;\;\;\;\frac{\sin th}{t_1 \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{th}{\frac{t_1}{\sin ky}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (or (<= (sin th) -0.04) (not (<= (sin th) 5e-31)))
     (/ (sin th) (* t_1 (+ (* ky 0.16666666666666666) (/ 1.0 ky))))
     (/ th (/ t_1 (sin ky))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if ((sin(th) <= -0.04) || !(sin(th) <= 5e-31)) {
		tmp = sin(th) / (t_1 * ((ky * 0.16666666666666666) + (1.0 / ky)));
	} else {
		tmp = th / (t_1 / sin(ky));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if ((Math.sin(th) <= -0.04) || !(Math.sin(th) <= 5e-31)) {
		tmp = Math.sin(th) / (t_1 * ((ky * 0.16666666666666666) + (1.0 / ky)));
	} else {
		tmp = th / (t_1 / Math.sin(ky));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if (math.sin(th) <= -0.04) or not (math.sin(th) <= 5e-31):
		tmp = math.sin(th) / (t_1 * ((ky * 0.16666666666666666) + (1.0 / ky)))
	else:
		tmp = th / (t_1 / math.sin(ky))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if ((sin(th) <= -0.04) || !(sin(th) <= 5e-31))
		tmp = Float64(sin(th) / Float64(t_1 * Float64(Float64(ky * 0.16666666666666666) + Float64(1.0 / ky))));
	else
		tmp = Float64(th / Float64(t_1 / sin(ky)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if ((sin(th) <= -0.04) || ~((sin(th) <= 5e-31)))
		tmp = sin(th) / (t_1 * ((ky * 0.16666666666666666) + (1.0 / ky)));
	else
		tmp = th / (t_1 / sin(ky));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, If[Or[LessEqual[N[Sin[th], $MachinePrecision], -0.04], N[Not[LessEqual[N[Sin[th], $MachinePrecision], 5e-31]], $MachinePrecision]], N[(N[Sin[th], $MachinePrecision] / N[(t$95$1 * N[(N[(ky * 0.16666666666666666), $MachinePrecision] + N[(1.0 / ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th / N[(t$95$1 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
\mathbf{if}\;\sin th \leq -0.04 \lor \neg \left(\sin th \leq 5 \cdot 10^{-31}\right):\\
\;\;\;\;\frac{\sin th}{t_1 \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 th) < -0.0400000000000000008 or 5e-31 < (sin.f64 th)

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0400000000000000008 < (sin.f64 th) < 5e-31

    1. Initial program 94.3%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 90.5%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\right)} - 1} \]
      3. *-commutative21.4%

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

        \[\leadsto e^{\mathsf{log1p}\left(th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}}\right)} - 1 \]
      5. un-div-inv21.4%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \leq -0.04 \lor \neg \left(\sin th \leq 5 \cdot 10^{-31}\right):\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}\\ \end{array} \]

Alternative 3: 73.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-6} \lor \neg \left(\sin ky \leq 10^{-12}\right):\\ \;\;\;\;\frac{\frac{\sin ky}{t_1}}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{t_1}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (or (<= (sin ky) -2e-6) (not (<= (sin ky) 1e-12)))
     (/ (/ (sin ky) t_1) (+ (/ 1.0 th) (* th 0.16666666666666666)))
     (* (sin th) (/ ky t_1)))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if ((sin(ky) <= -2e-6) || !(sin(ky) <= 1e-12)) {
		tmp = (sin(ky) / t_1) / ((1.0 / th) + (th * 0.16666666666666666));
	} else {
		tmp = sin(th) * (ky / t_1);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if ((Math.sin(ky) <= -2e-6) || !(Math.sin(ky) <= 1e-12)) {
		tmp = (Math.sin(ky) / t_1) / ((1.0 / th) + (th * 0.16666666666666666));
	} else {
		tmp = Math.sin(th) * (ky / t_1);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if (math.sin(ky) <= -2e-6) or not (math.sin(ky) <= 1e-12):
		tmp = (math.sin(ky) / t_1) / ((1.0 / th) + (th * 0.16666666666666666))
	else:
		tmp = math.sin(th) * (ky / t_1)
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if ((sin(ky) <= -2e-6) || !(sin(ky) <= 1e-12))
		tmp = Float64(Float64(sin(ky) / t_1) / Float64(Float64(1.0 / th) + Float64(th * 0.16666666666666666)));
	else
		tmp = Float64(sin(th) * Float64(ky / t_1));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if ((sin(ky) <= -2e-6) || ~((sin(ky) <= 1e-12)))
		tmp = (sin(ky) / t_1) / ((1.0 / th) + (th * 0.16666666666666666));
	else
		tmp = sin(th) * (ky / t_1);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, If[Or[LessEqual[N[Sin[ky], $MachinePrecision], -2e-6], N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 1e-12]], $MachinePrecision]], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] / N[(N[(1.0 / th), $MachinePrecision] + N[(th * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
\mathbf{if}\;\sin ky \leq -2 \cdot 10^{-6} \lor \neg \left(\sin ky \leq 10^{-12}\right):\\
\;\;\;\;\frac{\frac{\sin ky}{t_1}}{\frac{1}{th} + th \cdot 0.16666666666666666}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (sin.f64 ky) < -1.99999999999999991e-6 or 9.9999999999999998e-13 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

    if -1.99999999999999991e-6 < (sin.f64 ky) < 9.9999999999999998e-13

    1. Initial program 83.5%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sin th \cdot ky\right) \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      4. *-commutative33.2%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-6} \lor \neg \left(\sin ky \leq 10^{-12}\right):\\ \;\;\;\;\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{th} + th \cdot 0.16666666666666666}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \end{array} \]

Alternative 4: 73.3% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 49.8%

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\right)} - 1} \]
      3. *-commutative3.4%

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

        \[\leadsto e^{\mathsf{log1p}\left(th \cdot \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}}}\right)} - 1 \]
      5. un-div-inv3.4%

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

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

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

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

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

    if -1.99999999999999991e-6 < (sin.f64 ky) < 9.99999999999999924e-25

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sin th \cdot ky\right) \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      4. *-commutative33.7%

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999924e-25 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 62.4%

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

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

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

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

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

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

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

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

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

Alternative 5: 45.5% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

    if -4.99999999999999955e-308 < (sin.f64 ky) < 4.9999999999999998e-70

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Taylor expanded in ky around 0 82.8%

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

    if 4.9999999999999998e-70 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 6: 46.8% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

    if -4.99999999999999955e-308 < (sin.f64 ky) < 4.9999999999999998e-70

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Taylor expanded in ky around 0 82.8%

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

    if 4.9999999999999998e-70 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 7: 46.7% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

    if -4.99999999999999955e-308 < (sin.f64 ky) < 4.9999999999999998e-70

    1. Initial program 78.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    9. Taylor expanded in ky around 0 82.8%

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

    if 4.9999999999999998e-70 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

Alternative 8: 64.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sin th \cdot ky\right) \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      4. *-commutative23.5%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 9: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 11: 73.3% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;ky \leq -2.2 \cdot 10^{-6} \lor \neg \left(ky \leq 5 \cdot 10^{-24}\right):\\ \;\;\;\;th \cdot \frac{\sin ky}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{t_1}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (or (<= ky -2.2e-6) (not (<= ky 5e-24)))
     (* th (/ (sin ky) t_1))
     (* (sin th) (/ ky t_1)))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if ((ky <= -2.2e-6) || !(ky <= 5e-24)) {
		tmp = th * (sin(ky) / t_1);
	} else {
		tmp = sin(th) * (ky / t_1);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if ((ky <= -2.2e-6) || !(ky <= 5e-24)) {
		tmp = th * (Math.sin(ky) / t_1);
	} else {
		tmp = Math.sin(th) * (ky / t_1);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if (ky <= -2.2e-6) or not (ky <= 5e-24):
		tmp = th * (math.sin(ky) / t_1)
	else:
		tmp = math.sin(th) * (ky / t_1)
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if ((ky <= -2.2e-6) || !(ky <= 5e-24))
		tmp = Float64(th * Float64(sin(ky) / t_1));
	else
		tmp = Float64(sin(th) * Float64(ky / t_1));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if ((ky <= -2.2e-6) || ~((ky <= 5e-24)))
		tmp = th * (sin(ky) / t_1);
	else
		tmp = sin(th) * (ky / t_1);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, If[Or[LessEqual[ky, -2.2e-6], N[Not[LessEqual[ky, 5e-24]], $MachinePrecision]], N[(th * N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(ky / t$95$1), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\
\mathbf{if}\;ky \leq -2.2 \cdot 10^{-6} \lor \neg \left(ky \leq 5 \cdot 10^{-24}\right):\\
\;\;\;\;th \cdot \frac{\sin ky}{t_1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.2000000000000001e-6 or 4.9999999999999998e-24 < ky

    1. Initial program 99.7%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 56.9%

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

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

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

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

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

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

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

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

    if -2.2000000000000001e-6 < ky < 4.9999999999999998e-24

    1. Initial program 83.3%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\left(\sin th \cdot ky\right) \cdot \frac{1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}\right)} - 1 \]
      4. *-commutative33.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 31.6% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.4%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 62.4%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 14.6%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{th}{\color{blue}{\left|\frac{\sin kx}{ky}\right|}} \]
    12. Step-by-step derivation
      1. add-sqr-sqrt17.3%

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

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

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

        \[\leadsto \sqrt{{\color{blue}{\left(th \cdot \frac{1}{\left|\frac{\sin kx}{ky}\right|}\right)}}^{2}} \]
      5. add-sqr-sqrt8.3%

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

        \[\leadsto \sqrt{{\left(th \cdot \frac{1}{\color{blue}{\sqrt{\frac{\sin kx}{ky}} \cdot \sqrt{\frac{\sin kx}{ky}}}}\right)}^{2}} \]
      7. add-sqr-sqrt14.6%

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{ky}{\frac{\sin kx}{th}}}\right| \]
    15. Simplified25.0%

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

    if -0.0100000000000000002 < (sin.f64 kx) < 1.99999999999999989e-20

    1. Initial program 82.3%

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

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

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

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

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

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

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

    if 1.99999999999999989e-20 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 59.6%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 33.0%

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

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

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

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

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

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

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

Alternative 13: 32.9% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999913e-215 < (sin.f64 ky)

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

Alternative 14: 39.8% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 15: 32.1% accurate, 6.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\
\;\;\;\;\sin th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.25e-13 or 4.60000000000000022e-214 < ky

    1. Initial program 97.1%

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

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

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

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

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

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

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

    if -2.25e-13 < ky < 4.60000000000000022e-214

    1. Initial program 81.1%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 44.9%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 37.2%

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

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

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

      \[\leadsto \color{blue}{\frac{th}{\frac{\sin kx}{ky}}} \]
    8. Step-by-step derivation
      1. clear-num37.4%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-214}:\\ \;\;\;\;\frac{th}{\sin kx \cdot \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 16: 32.1% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\
\;\;\;\;\sin th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.25e-13 or 4.60000000000000022e-214 < ky

    1. Initial program 97.1%

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

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

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

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

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

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

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

    if -2.25e-13 < ky < 4.60000000000000022e-214

    1. Initial program 81.1%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 44.9%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 37.2%

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

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

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

      \[\leadsto \color{blue}{\frac{th}{\frac{\sin kx}{ky}}} \]
    8. Step-by-step derivation
      1. clear-num36.7%

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

        \[\leadsto \color{blue}{\frac{1}{\frac{\sin kx}{ky}} \cdot th} \]
      3. clear-num37.4%

        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot th \]
    9. Applied egg-rr37.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-214}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 17: 32.1% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\
\;\;\;\;\sin th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.25e-13 or 4.60000000000000022e-214 < ky

    1. Initial program 97.1%

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

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

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

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

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

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

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

    if -2.25e-13 < ky < 4.60000000000000022e-214

    1. Initial program 81.1%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 44.9%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 37.2%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.25 \cdot 10^{-13}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.6 \cdot 10^{-214}:\\ \;\;\;\;\frac{th}{\frac{\sin kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 18: 30.8% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.2000000000000002 or 4.60000000000000022e-214 < ky

    1. Initial program 97.1%

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

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

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

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

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

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

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

    if -3.2000000000000002 < ky < 4.60000000000000022e-214

    1. Initial program 81.5%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 45.0%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 37.2%

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

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

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

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

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

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

Alternative 19: 21.8% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8e7 or 1.75e-119 < ky

    1. Initial program 99.7%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 59.2%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in kx around 0 24.2%

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

    if -8e7 < ky < 1.75e-119

    1. Initial program 80.6%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 43.0%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 35.0%

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified28.0%

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    11. Step-by-step derivation
      1. associate-/r/28.3%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -80000000:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.75 \cdot 10^{-119}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 20: 21.8% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6.5e7 or 2.10000000000000002e-115 < ky

    1. Initial program 99.7%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 59.2%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in kx around 0 24.2%

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

    if -6.5e7 < ky < 2.10000000000000002e-115

    1. Initial program 80.6%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    4. Taylor expanded in th around 0 43.0%

      \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
    5. Taylor expanded in ky around 0 35.0%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -65000000:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{-115}:\\ \;\;\;\;\frac{th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 21: 13.5% accurate, 709.0× speedup?

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

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

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

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

    \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
  4. Taylor expanded in th around 0 52.5%

    \[\leadsto \frac{\color{blue}{\sin ky \cdot th}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
  5. Taylor expanded in kx around 0 17.1%

    \[\leadsto \color{blue}{th} \]
  6. Final simplification17.1%

    \[\leadsto th \]

Reproduce

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