Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.7%
Time: 34.2s
Alternatives: 19
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 19 alternatives:

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

Initial Program: 94.1% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 53.6% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin ky \cdot \color{blue}{\frac{1}{\frac{\sin ky}{\sin th}}}\right)}^{2}} \]
      5. un-div-inv28.2%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin ky}{\sin th}}\right|} \]
      3. associate-/r/32.7%

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

        \[\leadsto \left|\color{blue}{1} \cdot \sin th\right| \]
      5. *-lft-identity32.7%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    8. Simplified32.7%

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

    if -9.99999999999999936e-50 < (sin.f64 ky) < -9.99999999999999971e-305

    1. Initial program 87.0%

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

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

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

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

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

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

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

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

    if -9.99999999999999971e-305 < (sin.f64 ky) < 1.99999999999999991e-57

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999991e-57 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

Alternative 3: 65.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

    if -0.0040000000000000001 < (sin.f64 th) < 9.9999999999999995e-8

    1. Initial program 94.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 94.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 48.3% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin ky \cdot \color{blue}{\frac{1}{\frac{\sin ky}{\sin th}}}\right)}^{2}} \]
      5. un-div-inv28.2%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin ky}{\sin th}}\right|} \]
      3. associate-/r/32.7%

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

        \[\leadsto \left|\color{blue}{1} \cdot \sin th\right| \]
      5. *-lft-identity32.7%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    8. Simplified32.7%

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

    if -9.99999999999999936e-50 < (sin.f64 ky) < 1.9999999999999999e-154

    1. Initial program 85.2%

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-154 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

Alternative 5: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 7: 74.1% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3e12 or 0.025000000000000001 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3e12 < ky < 0.025000000000000001

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 8: 74.1% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3e12 or 0.014800000000000001 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

    if -3e12 < ky < 0.014800000000000001

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 74.1% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -3e12 < ky < 0.0077000000000000002

    1. Initial program 88.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0077000000000000002 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 48.0% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin ky \cdot \color{blue}{\frac{1}{\frac{\sin ky}{\sin th}}}\right)}^{2}} \]
      5. un-div-inv28.2%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin ky}{\sin th}}\right|} \]
      3. associate-/r/32.7%

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

        \[\leadsto \left|\color{blue}{1} \cdot \sin th\right| \]
      5. *-lft-identity32.7%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    8. Simplified32.7%

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

    if -9.99999999999999936e-50 < (sin.f64 ky) < 1.9999999999999999e-154

    1. Initial program 85.2%

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

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

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

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

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

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

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

    if 1.9999999999999999e-154 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

Alternative 11: 48.0% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -1 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin ky \cdot \color{blue}{\frac{1}{\frac{\sin ky}{\sin th}}}\right)}^{2}} \]
      5. un-div-inv28.2%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin ky}{\sin th}}\right|} \]
      3. associate-/r/32.7%

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

        \[\leadsto \left|\color{blue}{1} \cdot \sin th\right| \]
      5. *-lft-identity32.7%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    8. Simplified32.7%

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

    if -9.99999999999999936e-50 < (sin.f64 ky) < 1.9999999999999999e-154

    1. Initial program 85.2%

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-154 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

Alternative 12: 33.6% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 3.6 \cdot 10^{-152}:\\ \;\;\;\;\left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right) \cdot \left(\sin th \cdot ky\right)\\ \mathbf{elif}\;ky \leq 22000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 2.35 \cdot 10^{+272}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))))
   (if (<= ky -2e-158)
     t_1
     (if (<= ky 3.6e-152)
       (* (+ (* kx 0.16666666666666666) (/ 1.0 kx)) (* (sin th) ky))
       (if (<= ky 22000.0) (sin th) (if (<= ky 2.35e+272) t_1 (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double tmp;
	if (ky <= -2e-158) {
		tmp = t_1;
	} else if (ky <= 3.6e-152) {
		tmp = ((kx * 0.16666666666666666) + (1.0 / kx)) * (sin(th) * ky);
	} else if (ky <= 22000.0) {
		tmp = sin(th);
	} else if (ky <= 2.35e+272) {
		tmp = t_1;
	} 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) :: t_1
    real(8) :: tmp
    t_1 = abs(sin(th))
    if (ky <= (-2d-158)) then
        tmp = t_1
    else if (ky <= 3.6d-152) then
        tmp = ((kx * 0.16666666666666666d0) + (1.0d0 / kx)) * (sin(th) * ky)
    else if (ky <= 22000.0d0) then
        tmp = sin(th)
    else if (ky <= 2.35d+272) then
        tmp = t_1
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.abs(Math.sin(th));
	double tmp;
	if (ky <= -2e-158) {
		tmp = t_1;
	} else if (ky <= 3.6e-152) {
		tmp = ((kx * 0.16666666666666666) + (1.0 / kx)) * (Math.sin(th) * ky);
	} else if (ky <= 22000.0) {
		tmp = Math.sin(th);
	} else if (ky <= 2.35e+272) {
		tmp = t_1;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	tmp = 0
	if ky <= -2e-158:
		tmp = t_1
	elif ky <= 3.6e-152:
		tmp = ((kx * 0.16666666666666666) + (1.0 / kx)) * (math.sin(th) * ky)
	elif ky <= 22000.0:
		tmp = math.sin(th)
	elif ky <= 2.35e+272:
		tmp = t_1
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	tmp = 0.0
	if (ky <= -2e-158)
		tmp = t_1;
	elseif (ky <= 3.6e-152)
		tmp = Float64(Float64(Float64(kx * 0.16666666666666666) + Float64(1.0 / kx)) * Float64(sin(th) * ky));
	elseif (ky <= 22000.0)
		tmp = sin(th);
	elseif (ky <= 2.35e+272)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	tmp = 0.0;
	if (ky <= -2e-158)
		tmp = t_1;
	elseif (ky <= 3.6e-152)
		tmp = ((kx * 0.16666666666666666) + (1.0 / kx)) * (sin(th) * ky);
	elseif (ky <= 22000.0)
		tmp = sin(th);
	elseif (ky <= 2.35e+272)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[ky, -2e-158], t$95$1, If[LessEqual[ky, 3.6e-152], N[(N[(N[(kx * 0.16666666666666666), $MachinePrecision] + N[(1.0 / kx), $MachinePrecision]), $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 22000.0], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 2.35e+272], t$95$1, N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;ky \leq -2 \cdot 10^{-158}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq 3.6 \cdot 10^{-152}:\\
\;\;\;\;\left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right) \cdot \left(\sin th \cdot ky\right)\\

\mathbf{elif}\;ky \leq 22000:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 2.35 \cdot 10^{+272}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -2.00000000000000013e-158 or 22000 < ky < 2.35e272

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin ky \cdot \color{blue}{\frac{1}{\frac{\sin ky}{\sin th}}}\right)}^{2}} \]
      5. un-div-inv24.3%

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\frac{\sin ky}{\sin th}}\right|} \]
      3. associate-/r/28.0%

        \[\leadsto \left|\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right| \]
      4. *-inverses28.0%

        \[\leadsto \left|\color{blue}{1} \cdot \sin th\right| \]
      5. *-lft-identity28.0%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    8. Simplified28.0%

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

    if -2.00000000000000013e-158 < ky < 3.6e-152

    1. Initial program 79.6%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot \left(\sin ky \cdot kx\right) + \frac{\sin ky}{kx}\right)} \cdot \sin th \]
    6. Taylor expanded in ky around 0 27.2%

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

    if 3.6e-152 < ky < 22000 or 2.35e272 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2 \cdot 10^{-158}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;ky \leq 3.6 \cdot 10^{-152}:\\ \;\;\;\;\left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right) \cdot \left(\sin th \cdot ky\right)\\ \mathbf{elif}\;ky \leq 22000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 2.35 \cdot 10^{+272}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 13: 32.9% accurate, 6.2× speedup?

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

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

\mathbf{elif}\;ky \leq 4.7 \cdot 10^{-151}:\\
\;\;\;\;\left(kx \cdot 0.16666666666666666 + \frac{1}{kx}\right) \cdot \left(\sin th \cdot ky\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -180 or 4.70000000000000029e-151 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

    if -180 < ky < 4.70000000000000029e-151

    1. Initial program 85.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.16666666666666666 \cdot \left(\sin ky \cdot kx\right) + \frac{\sin ky}{kx}\right)} \cdot \sin th \]
    6. Taylor expanded in ky around 0 22.6%

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

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

Alternative 14: 32.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.65e-49 or 4.6e-248 < ky

    1. Initial program 96.7%

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

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

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

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

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

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

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

    if -1.65e-49 < ky < 4.6e-248

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 32.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.65e-49 or 4.6e-248 < ky

    1. Initial program 96.7%

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

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

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

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

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

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

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

    if -1.65e-49 < ky < 4.6e-248

    1. Initial program 86.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 31.0% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -4.1999999999999998e-19 or 3.3999999999999998e-248 < ky

    1. Initial program 96.6%

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

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

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

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

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

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

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

    if -4.1999999999999998e-19 < ky < 3.3999999999999998e-248

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 21.9% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.65 \cdot 10^{-49}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.65e-49 or 1.05999999999999991e-81 < ky

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

    if -1.65e-49 < ky < 1.05999999999999991e-81

    1. Initial program 86.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    10. Simplified20.1%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.65 \cdot 10^{-49}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.06 \cdot 10^{-81}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 18: 21.9% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.65 \cdot 10^{-49}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.65e-49 or 1.9000000000000001e-79 < ky

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

    if -1.65e-49 < ky < 1.9000000000000001e-79

    1. Initial program 86.6%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{th}{\frac{kx}{ky}}} \]
    10. Simplified20.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.65 \cdot 10^{-49}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.9 \cdot 10^{-79}:\\ \;\;\;\;\frac{th}{\frac{kx}{ky}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 19: 13.9% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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