Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.7%
Time: 23.6s
Alternatives: 18
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 18 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.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 54.2% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

    if -0.0100000000000000002 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 83.2%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 3: 46.6% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999931e-304 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 4: 45.7% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 88.4%

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

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

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

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

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

    if 9.9999999999999998e-267 < (sin.f64 ky) < 4.99999999999999964e-35

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 5: 55.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 89.2%

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 6: 66.5% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;kx \leq 3.3 \cdot 10^{+102}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;kx \leq 5.4 \cdot 10^{+141}:\\
\;\;\;\;\frac{\sin ky}{\frac{t_2}{\sin th}}\\

\mathbf{elif}\;kx \leq 9.5 \cdot 10^{+235}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if kx < 7e4

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7e4 < kx < 3.29999999999999999e102 or 5.4000000000000002e141 < kx < 9.49999999999999966e235

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.29999999999999999e102 < kx < 5.4000000000000002e141

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}}} \]
    4. Applied egg-rr38.6%

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

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

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

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

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

    if 9.49999999999999966e235 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 70000:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;kx \leq 3.3 \cdot 10^{+102}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{elif}\;kx \leq 5.4 \cdot 10^{+141}:\\ \;\;\;\;\frac{\sin ky}{\frac{\left|\sin kx\right|}{\sin th}}\\ \mathbf{elif}\;kx \leq 9.5 \cdot 10^{+235}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]

Alternative 7: 66.5% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;kx \leq 6.6 \cdot 10^{+101}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;kx \leq 2.5 \cdot 10^{+144}:\\
\;\;\;\;\frac{1}{\frac{t_2}{\sin ky \cdot \sin th}}\\

\mathbf{elif}\;kx \leq 4.4 \cdot 10^{+235}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if kx < 7e4

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 7e4 < kx < 6.60000000000000022e101 or 2.5e144 < kx < 4.4e235

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 6.60000000000000022e101 < kx < 2.5e144

    1. Initial program 99.6%

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

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

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sin kx}} \]
      2. clear-num38.3%

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

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

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

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

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

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

    if 4.4e235 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 70000:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;kx \leq 6.6 \cdot 10^{+101}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{elif}\;kx \leq 2.5 \cdot 10^{+144}:\\ \;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{\sin ky \cdot \sin th}}\\ \mathbf{elif}\;kx \leq 4.4 \cdot 10^{+235}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\left|\sin kx\right|}\\ \end{array} \]

Alternative 8: 68.2% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0145000000000000007 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

Alternative 9: 32.0% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 89.0%

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

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

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

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

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

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

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

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

    if 1e-51 < (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 60.9%

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

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

Alternative 10: 46.3% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 88.9%

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

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

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

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

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

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

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

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

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

    if 6.9999999999999997e-32 < ky

    1. Initial program 99.8%

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

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

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

Alternative 11: 32.7% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 88.8%

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

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

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

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

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

    if 3.10000000000000012e-35 < 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 32.3%

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

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

Alternative 12: 32.7% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 88.8%

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

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

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

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

    if 7.9999999999999995e-36 < 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 32.3%

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

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

Alternative 13: 32.7% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

    if 8.6000000000000004e-36 < 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 32.3%

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

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

Alternative 14: 25.1% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 88.7%

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

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

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

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

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

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

    if 9.50000000000000007e-52 < 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 31.4%

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

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

Alternative 15: 25.1% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 88.7%

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

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

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

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

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{kx}{ky}}} \]
      3. un-div-inv28.8%

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

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

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

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

    if 6.80000000000000035e-52 < 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 31.4%

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

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

Alternative 16: 25.1% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 88.7%

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

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

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

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

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

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

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

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

    if 6.80000000000000035e-52 < 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 31.4%

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

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

Alternative 17: 22.9% accurate, 6.9× speedup?

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

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

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


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

    1. Initial program 87.6%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    8. Simplified23.5%

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

    if 4.50000000000000016e-107 < 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 29.6%

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

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

Alternative 18: 13.2% accurate, 141.8× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
  8. Simplified17.1%

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

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

Reproduce

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