Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 17.3s
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.3% 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 95.1%

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

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

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

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

      \[\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*95.1%

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 40.3% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.005:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\log \left(e^{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)}} \cdot \sin th \]
      6. hypot-udef99.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right)} \cdot \sin th \]
      10. unpow299.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      11. unpow299.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def99.0%

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

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Taylor expanded in ky around 0 6.2%

      \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(1 + ky\right)}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutative6.2%

        \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(ky + 1\right)}} \cdot \sin th \]
    8. Simplified6.2%

      \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(ky + 1\right)}} \cdot \sin th \]

    if -0.0050000000000000001 < (sin.f64 ky) < 9.9999999999999995e-8

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-8 < (sin.f64 ky)

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\ \mathbf{elif}\;\sin ky \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 44.2% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.070000000000000007 < (sin.f64 kx) < 4.99999999999999971e-68

    1. Initial program 89.9%

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

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

    if 4.99999999999999971e-68 < (sin.f64 kx)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. 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-udef46.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 44.2% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.070000000000000007 < (sin.f64 kx) < 4.99999999999999971e-68

    1. Initial program 89.9%

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

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

    if 4.99999999999999971e-68 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}}} \]
    5. Applied egg-rr62.5%

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

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

Alternative 5: 40.6% accurate, 1.4× speedup?

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

\mathbf{elif}\;\sin ky \leq 10^{-7}:\\
\;\;\;\;\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) < -0.0050000000000000001

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{th \cdot \left|\frac{\sin ky}{\sin kx}\right|} \]
    9. Step-by-step derivation
      1. fabs-div2.9%

        \[\leadsto th \cdot \color{blue}{\frac{\left|\sin ky\right|}{\left|\sin kx\right|}} \]
      2. rem-square-sqrt0.0%

        \[\leadsto th \cdot \frac{\left|\color{blue}{\sqrt{\sin ky} \cdot \sqrt{\sin ky}}\right|}{\left|\sin kx\right|} \]
      3. fabs-sqr0.0%

        \[\leadsto th \cdot \frac{\color{blue}{\sqrt{\sin ky} \cdot \sqrt{\sin ky}}}{\left|\sin kx\right|} \]
      4. rem-square-sqrt8.4%

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

        \[\leadsto \color{blue}{\frac{th \cdot \sin ky}{\left|\sin kx\right|}} \]
    10. Simplified8.4%

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

    if -0.0050000000000000001 < (sin.f64 ky) < 9.9999999999999995e-8

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-8 < (sin.f64 ky)

    1. Initial program 99.8%

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

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

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

Alternative 6: 40.3% accurate, 1.4× speedup?

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

\mathbf{elif}\;\sin ky \leq 10^{-7}:\\
\;\;\;\;\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) < -0.0050000000000000001

    1. Initial program 99.7%

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\log \left(e^{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)}} \cdot \sin th \]
      6. hypot-udef99.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right)} \cdot \sin th \]
      10. unpow299.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      11. unpow299.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def99.0%

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

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Taylor expanded in ky around 0 6.2%

      \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(1 + ky\right)}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutative6.2%

        \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(ky + 1\right)}} \cdot \sin th \]
    8. Simplified6.2%

      \[\leadsto \frac{\sin ky}{\log \color{blue}{\left(ky + 1\right)}} \cdot \sin th \]

    if -0.0050000000000000001 < (sin.f64 ky) < 9.9999999999999995e-8

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-8 < (sin.f64 ky)

    1. Initial program 99.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\log \left(ky + 1\right)}\\ \mathbf{elif}\;\sin ky \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 62.3% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;th \leq 2.65 \cdot 10^{+199}:\\
\;\;\;\;\frac{ky \cdot \sin th}{t_1}\\

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


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

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\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}}}} \]
    10. Step-by-step derivation
      1. +-commutative66.3%

        \[\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. +-commutative66.3%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin ky, \sin kx\right) + \left(0.16666666666666666 \cdot th\right) \cdot \color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      11. distribute-rgt-out69.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)}} \]
    11. Simplified69.1%

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

    if 1250 < th < 2.6499999999999998e199

    1. Initial program 92.4%

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

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

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

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

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

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

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

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

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

    if 2.6499999999999998e199 < th

    1. Initial program 86.4%

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\log \left(e^{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)}} \cdot \sin th \]
      6. hypot-udef77.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right)} \cdot \sin th \]
      10. unpow277.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      11. unpow277.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def77.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}\right)} \cdot \sin th \]
    4. Applied egg-rr77.0%

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt17.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}}} \cdot \sin th \]
      2. fabs-sqr17.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}\right|}} \cdot \sin th \]
      3. add-sqr-sqrt38.2%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\log \left(e^{\sin ky}\right)}\right|} \cdot \sin th \]
      4. rem-log-exp52.5%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\sin ky}\right|} \cdot \sin th \]
    7. Applied egg-rr52.5%

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

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

Alternative 9: 61.9% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;th \leq 1.06 \cdot 10^{+200}:\\
\;\;\;\;\frac{ky \cdot \sin th}{t_1}\\

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


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

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1250 < th < 1.0599999999999999e200

    1. Initial program 92.4%

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

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

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

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

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

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

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

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

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

    if 1.0599999999999999e200 < th

    1. Initial program 86.4%

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\log \left(e^{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\right)}} \cdot \sin th \]
      6. hypot-udef77.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right)} \cdot \sin th \]
      10. unpow277.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      11. unpow277.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def77.0%

        \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}\right)} \cdot \sin th \]
    4. Applied egg-rr77.0%

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt17.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}}} \cdot \sin th \]
      2. fabs-sqr17.5%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}\right|}} \cdot \sin th \]
      3. add-sqr-sqrt38.2%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\log \left(e^{\sin ky}\right)}\right|} \cdot \sin th \]
      4. rem-log-exp52.5%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\sin ky}\right|} \cdot \sin th \]
    7. Applied egg-rr52.5%

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

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

Alternative 10: 61.0% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.9000000000000002e-6 < th

    1. Initial program 90.1%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def74.3%

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

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt13.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}}} \cdot \sin th \]
      2. fabs-sqr13.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}\right|}} \cdot \sin th \]
      3. add-sqr-sqrt31.4%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\log \left(e^{\sin ky}\right)}\right|} \cdot \sin th \]
      4. rem-log-exp42.5%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\sin ky}\right|} \cdot \sin th \]
    7. Applied egg-rr42.5%

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

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

Alternative 11: 49.6% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 93.3%

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \color{blue}{\left(-1 \cdot \sin \left(-th\right)\right)} \]
      4. *-commutative93.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*93.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/91.7%

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
      13. associate-/r/93.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. Add Preprocessing
    5. Step-by-step derivation
      1. expm1-log1p-u99.7%

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000003e-53 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 12: 39.5% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 93.5%

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

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

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

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

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

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

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

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

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

    if 8.99999999999999986e-8 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\log \left(e^{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)} \cdot \sin th \]
      12. hypot-def98.6%

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

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

      \[\leadsto \frac{\sin ky}{\log \left(e^{\color{blue}{\sin ky}}\right)} \cdot \sin th \]
    6. Step-by-step derivation
      1. add-sqr-sqrt39.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}}} \cdot \sin th \]
      2. fabs-sqr39.2%

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sqrt{\log \left(e^{\sin ky}\right)} \cdot \sqrt{\log \left(e^{\sin ky}\right)}\right|}} \cdot \sin th \]
      3. add-sqr-sqrt64.3%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\log \left(e^{\sin ky}\right)}\right|} \cdot \sin th \]
      4. rem-log-exp65.3%

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

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

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

Alternative 13: 31.9% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8.4 \cdot 10^{-7}:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 8.4e-7) (* (sin th) (fabs (/ ky (sin kx)))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8.4e-7) {
		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 (ky <= 8.4d-7) 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 (ky <= 8.4e-7) {
		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 ky <= 8.4e-7:
		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 (ky <= 8.4e-7)
		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 (ky <= 8.4e-7)
		tmp = sin(th) * abs((ky / sin(kx)));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 8.4e-7], 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}\;ky \leq 8.4 \cdot 10^{-7}:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

    1. Initial program 93.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 8.4e-7 < ky

    1. Initial program 99.7%

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

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

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

Alternative 14: 33.1% accurate, 3.4× speedup?

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

    1. Initial program 93.3%

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

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

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

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

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

    if 3.00000000000000002e-51 < ky

    1. Initial program 99.7%

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

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

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

Alternative 15: 26.8% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 92.6%

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

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

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

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

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

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

    if 1.24999999999999992e-149 < ky

    1. Initial program 99.7%

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

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

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

Alternative 16: 26.9% accurate, 6.6× speedup?

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

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

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


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

    1. Initial program 92.6%

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

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

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

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

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

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

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

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

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

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

    if 2.5999999999999998e-150 < ky

    1. Initial program 99.7%

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

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

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

Alternative 17: 24.1% accurate, 6.9× speedup?

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

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

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


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

    1. Initial program 92.5%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    9. Simplified21.5%

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

    if 4.2000000000000001e-160 < ky

    1. Initial program 99.7%

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

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

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

Alternative 18: 13.5% 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 95.1%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
  9. Simplified16.5%

    \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
  10. Final simplification16.5%

    \[\leadsto \frac{ky}{\frac{kx}{th}} \]
  11. Add Preprocessing

Reproduce

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