Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.6%
Time: 21.5s
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.6% accurate, 1.4× speedup?

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

\\
\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}
\end{array}
Derivation
  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-/r/94.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 72.9% accurate, 1.2× speedup?

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

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

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

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


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

    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-/r/99.5%

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

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

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

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

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

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

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

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

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

      \[\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/46.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 89.3%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \sin th}}{\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. Taylor expanded in kx around 0 64.7%

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

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

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

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

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

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


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

    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-/r/99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    4. Taylor expanded in th around 0 47.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. +-commutative47.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. unpow247.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. unpow247.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-def47.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*47.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. unpow247.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. unpow247.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-def47.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-out47.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. Simplified47.1%

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

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

    1. Initial program 89.3%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \sin th}}{\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. Taylor expanded in kx around 0 64.7%

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

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

Alternative 4: 73.0% accurate, 1.2× speedup?

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

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

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

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


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

    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. +-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-udef99.6%

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

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

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

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

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

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

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

    1. Initial program 89.3%

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \sin th}}{\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. Taylor expanded in kx around 0 64.7%

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

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

Alternative 5: 45.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-302}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\ \;\;\;\;\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) 2e-302)
   (* ky (/ (sin th) (sin kx)))
   (if (<= (sin ky) 4e-49) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= 2e-302) {
		tmp = ky * (sin(th) / sin(kx));
	} else if (sin(ky) <= 4e-49) {
		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) <= 2d-302) then
        tmp = ky * (sin(th) / sin(kx))
    else if (sin(ky) <= 4d-49) 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) <= 2e-302) {
		tmp = ky * (Math.sin(th) / Math.sin(kx));
	} else if (Math.sin(ky) <= 4e-49) {
		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) <= 2e-302:
		tmp = ky * (math.sin(th) / math.sin(kx))
	elif math.sin(ky) <= 4e-49:
		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) <= 2e-302)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	elseif (sin(ky) <= 4e-49)
		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) <= 2e-302)
		tmp = ky * (sin(th) / sin(kx));
	elseif (sin(ky) <= 4e-49)
		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], 2e-302], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-49], 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 2 \cdot 10^{-302}:\\
\;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\
\;\;\;\;\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) < 1.9999999999999999e-302

    1. Initial program 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-302 < (sin.f64 ky) < 3.99999999999999975e-49

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

    if 3.99999999999999975e-49 < (sin.f64 ky)

    1. Initial program 99.7%

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

      \[\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 2 \cdot 10^{-302}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 6: 46.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-290}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\ \;\;\;\;\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) -2e-290)
   (* (sin th) (/ (sin ky) (sin kx)))
   (if (<= (sin ky) 4e-49) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -2e-290) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (sin(ky) <= 4e-49) {
		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) <= (-2d-290)) then
        tmp = sin(th) * (sin(ky) / sin(kx))
    else if (sin(ky) <= 4d-49) 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) <= -2e-290) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	} else if (Math.sin(ky) <= 4e-49) {
		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) <= -2e-290:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	elif math.sin(ky) <= 4e-49:
		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) <= -2e-290)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (sin(ky) <= 4e-49)
		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) <= -2e-290)
		tmp = sin(th) * (sin(ky) / sin(kx));
	elseif (sin(ky) <= 4e-49)
		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], -2e-290], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-49], 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 -2 \cdot 10^{-290}:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\
\;\;\;\;\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) < -2.0000000000000001e-290

    1. Initial program 95.5%

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

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

    if -2.0000000000000001e-290 < (sin.f64 ky) < 3.99999999999999975e-49

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

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

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

    if 3.99999999999999975e-49 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 7: 46.8% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 2 \cdot 10^{-302}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\ \;\;\;\;\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) 2e-302)
   (* (sin ky) (/ (sin th) (sin kx)))
   (if (<= (sin ky) 4e-49) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= 2e-302) {
		tmp = sin(ky) * (sin(th) / sin(kx));
	} else if (sin(ky) <= 4e-49) {
		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) <= 2d-302) then
        tmp = sin(ky) * (sin(th) / sin(kx))
    else if (sin(ky) <= 4d-49) 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) <= 2e-302) {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.sin(kx));
	} else if (Math.sin(ky) <= 4e-49) {
		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) <= 2e-302:
		tmp = math.sin(ky) * (math.sin(th) / math.sin(kx))
	elif math.sin(ky) <= 4e-49:
		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) <= 2e-302)
		tmp = Float64(sin(ky) * Float64(sin(th) / sin(kx)));
	elseif (sin(ky) <= 4e-49)
		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) <= 2e-302)
		tmp = sin(ky) * (sin(th) / sin(kx));
	elseif (sin(ky) <= 4e-49)
		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], 2e-302], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-49], 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 2 \cdot 10^{-302}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-49}:\\
\;\;\;\;\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) < 1.9999999999999999e-302

    1. Initial program 94.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-302 < (sin.f64 ky) < 3.99999999999999975e-49

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

    if 3.99999999999999975e-49 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 61.0% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

    if -0.0140000000000000003 < th < 1.35e12

    1. Initial program 96.8%

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

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

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

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

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

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

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

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

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

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

      \[\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/93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e12 < th

    1. Initial program 91.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{\color{blue}{\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 24.7%

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

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

Alternative 10: 39.6% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 91.9%

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

        \[\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. +-commutative91.8%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 11: 32.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6e11 or 2.40000000000000015e-105 < 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 37.3%

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

    if -6e11 < ky < 2.40000000000000015e-105

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

      \[\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/52.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    10. Step-by-step derivation
      1. div-inv29.0%

        \[\leadsto \color{blue}{ky \cdot \frac{1}{\frac{\sin kx}{th}}} \]
      2. clear-num29.0%

        \[\leadsto ky \cdot \color{blue}{\frac{th}{\sin kx}} \]
    11. Applied egg-rr29.0%

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

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

Alternative 12: 32.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6e11 or 7e-105 < 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 37.3%

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

    if -6e11 < ky < 7e-105

    1. Initial program 87.9%

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

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

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

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

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

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

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

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

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

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

      \[\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/52.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 32.8% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6e11 or 1.15000000000000005e-126 < 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 36.4%

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

    if -6e11 < ky < 1.15000000000000005e-126

    1. Initial program 87.5%

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

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

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

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

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

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

Alternative 14: 30.3% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6e11 or 9.4000000000000003e-129 < 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 36.4%

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

    if -6e11 < ky < 9.4000000000000003e-129

    1. Initial program 87.5%

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

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

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

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

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

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

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

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

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

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

      \[\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/53.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified26.9%

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    14. Applied egg-rr27.0%

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

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

Alternative 15: 21.6% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.3e11 or 2.7e-77 < 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-/r/99.6%

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

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

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

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

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

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

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

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

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

      \[\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/50.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3.3e11 < ky < 2.7e-77

    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-/r/88.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    4. Taylor expanded in th around 0 51.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/51.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified25.6%

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    14. Applied egg-rr25.7%

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

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

Alternative 16: 13.3% 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 94.3%

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

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

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

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

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

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

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

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

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

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

    \[\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/51.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  8. Final simplification13.2%

    \[\leadsto th \]

Reproduce

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