Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.7%
Time: 17.8s
Alternatives: 16
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 94.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 77.5% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 0.00027:\\
\;\;\;\;\frac{\sin th}{t_1 \cdot \left(ky \cdot 0.16666666666666666 + \frac{1}{ky}\right)}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right) + \left(0.16666666666666666 \cdot th\right) \cdot \color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
      9. distribute-rgt-out52.9%

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

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

    if -0.0050000000000000001 < (sin.f64 ky) < 2.70000000000000003e-4

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

    if 2.70000000000000003e-4 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 3: 77.3% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 0.00027:\\
\;\;\;\;\frac{\sin th}{t_1 \cdot \frac{1}{ky}}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

    if -0.0040000000000000001 < (sin.f64 ky) < 2.70000000000000003e-4

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

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

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

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

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

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

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

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

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

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

    if 2.70000000000000003e-4 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 4: 77.4% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 0.00027:\\
\;\;\;\;\frac{\sin th}{t_1 \cdot \frac{1}{ky}}\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right) + \left(0.16666666666666666 \cdot th\right) \cdot \color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
      9. distribute-rgt-out52.1%

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

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

    if -0.0040000000000000001 < (sin.f64 ky) < 2.70000000000000003e-4

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

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

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

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

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

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

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

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

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

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

    if 2.70000000000000003e-4 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.004:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \left(\frac{1}{th} + th \cdot 0.16666666666666666\right)}\\ \mathbf{elif}\;\sin ky \leq 0.00027:\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right) \cdot \frac{1}{ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 5: 44.3% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-83}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 4.0000000000000001e-83

    1. Initial program 86.7%

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

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

    if 4.0000000000000001e-83 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

Alternative 6: 45.3% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-83}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 4.0000000000000001e-83

    1. Initial program 86.7%

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

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

    if 4.0000000000000001e-83 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

Alternative 7: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 55.6% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.02 \cdot 10^{-8}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \mathbf{elif}\;th \leq 1.4 \cdot 10^{+83} \lor \neg \left(th \leq 2.5 \cdot 10^{+178}\right) \land \left(th \leq 1.55 \cdot 10^{+259} \lor \neg \left(th \leq 5.8 \cdot 10^{+281}\right)\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= th 1.02e-8)
   (/ (sin ky) (/ (hypot (sin kx) (sin ky)) th))
   (if (or (<= th 1.4e+83)
           (and (not (<= th 2.5e+178))
                (or (<= th 1.55e+259) (not (<= th 5.8e+281)))))
     (* (sin th) (fabs (/ (sin ky) (sin kx))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 1.02e-8) {
		tmp = sin(ky) / (hypot(sin(kx), sin(ky)) / th);
	} else if ((th <= 1.4e+83) || (!(th <= 2.5e+178) && ((th <= 1.55e+259) || !(th <= 5.8e+281)))) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (th <= 1.02e-8) {
		tmp = Math.sin(ky) / (Math.hypot(Math.sin(kx), Math.sin(ky)) / th);
	} else if ((th <= 1.4e+83) || (!(th <= 2.5e+178) && ((th <= 1.55e+259) || !(th <= 5.8e+281)))) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if th <= 1.02e-8:
		tmp = math.sin(ky) / (math.hypot(math.sin(kx), math.sin(ky)) / th)
	elif (th <= 1.4e+83) or (not (th <= 2.5e+178) and ((th <= 1.55e+259) or not (th <= 5.8e+281))):
		tmp = math.sin(th) * math.fabs((math.sin(ky) / math.sin(kx)))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (th <= 1.02e-8)
		tmp = Float64(sin(ky) / Float64(hypot(sin(kx), sin(ky)) / th));
	elseif ((th <= 1.4e+83) || (!(th <= 2.5e+178) && ((th <= 1.55e+259) || !(th <= 5.8e+281))))
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (th <= 1.02e-8)
		tmp = sin(ky) / (hypot(sin(kx), sin(ky)) / th);
	elseif ((th <= 1.4e+83) || (~((th <= 2.5e+178)) && ((th <= 1.55e+259) || ~((th <= 5.8e+281)))))
		tmp = sin(th) * abs((sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[th, 1.02e-8], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[Sin[kx], $MachinePrecision] ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 1.4e+83], And[N[Not[LessEqual[th, 2.5e+178]], $MachinePrecision], Or[LessEqual[th, 1.55e+259], N[Not[LessEqual[th, 5.8e+281]], $MachinePrecision]]]], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

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

\mathbf{elif}\;th \leq 1.4 \cdot 10^{+83} \lor \neg \left(th \leq 2.5 \cdot 10^{+178}\right) \land \left(th \leq 1.55 \cdot 10^{+259} \lor \neg \left(th \leq 5.8 \cdot 10^{+281}\right)\right):\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


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

    1. Initial program 95.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02000000000000003e-8 < th < 1.4e83 or 2.49999999999999995e178 < th < 1.5500000000000002e259 or 5.80000000000000019e281 < th

    1. Initial program 89.2%

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

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

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

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

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

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

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

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

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

    if 1.4e83 < th < 2.49999999999999995e178 or 1.5500000000000002e259 < th < 5.80000000000000019e281

    1. Initial program 91.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.02 \cdot 10^{-8}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \mathbf{elif}\;th \leq 1.4 \cdot 10^{+83} \lor \neg \left(th \leq 2.5 \cdot 10^{+178}\right) \land \left(th \leq 1.55 \cdot 10^{+259} \lor \neg \left(th \leq 5.8 \cdot 10^{+281}\right)\right):\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 9: 42.1% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;\sin kx \leq 4 \cdot 10^{-83}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 4.0000000000000001e-83

    1. Initial program 86.7%

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

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

    if 4.0000000000000001e-83 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot \sin th} \]
    4. Simplified51.8%

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

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

Alternative 10: 63.0% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 3.1e-8

    1. Initial program 95.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.1e-8 < th

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 30.6% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 91.3%

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

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

    if 3.79999999999999977e-83 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 12: 33.4% accurate, 3.4× speedup?

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.2000000000000002e-80 < ky

    1. Initial program 99.7%

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

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

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

Alternative 13: 33.4% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 6.4 \cdot 10^{-80}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 6.4e-80) (* (sin th) (/ ky (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 6.4e-80) {
		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 (ky <= 6.4d-80) 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 (ky <= 6.4e-80) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 6.4e-80:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 6.4e-80)
		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 (ky <= 6.4e-80)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 6.4e-80], 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}\;ky \leq 6.4 \cdot 10^{-80}:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

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


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

    1. Initial program 91.8%

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot \sin th} \]
    4. Simplified32.8%

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

    if 6.3999999999999998e-80 < ky

    1. Initial program 99.7%

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

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

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

Alternative 14: 27.7% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 91.1%

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot \sin th} \]
    4. Simplified32.6%

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

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

    if 6.20000000000000012e-134 < ky

    1. Initial program 99.7%

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

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

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

Alternative 15: 26.4% accurate, 6.9× speedup?

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

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

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


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

    1. Initial program 91.9%

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

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

    if 9.60000000000000063e-39 < kx

    1. Initial program 99.4%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    8. Simplified19.9%

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

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

Alternative 16: 13.7% accurate, 141.8× speedup?

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

\\
\frac{ky}{\frac{kx}{th}}
\end{array}
Derivation
  1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{ky}{\frac{kx}{th}} \]

Reproduce

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