Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.6% → 99.7%
Time: 22.3s
Alternatives: 18
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 18 alternatives:

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

Initial Program: 93.6% 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 92.9%

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

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

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

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

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

      \[\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. Step-by-step derivation
    1. associate-*r/95.0%

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

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

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

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

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

Alternative 2: 46.8% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.1:\\
\;\;\;\;\left|\sin th\right|\\

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

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

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


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

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

        \[\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. Step-by-step derivation
      1. associate-*r/99.6%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div2.7%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.4%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod16.8%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow216.8%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr16.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow216.8%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square22.5%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified22.5%

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

    if -0.10000000000000001 < (sin.f64 ky) < -1e-179

    1. Initial program 91.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{ky}} \]
    6. Step-by-step derivation
      1. mul-1-neg42.1%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{\frac{ky}{\sin ky}}} \]
      3. distribute-neg-frac63.2%

        \[\leadsto \color{blue}{\frac{-\sin th}{\frac{ky}{\sin ky}}} \]
    7. Simplified63.2%

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

    if -1e-179 < (sin.f64 ky) < 2.00000000000000006e-53

    1. Initial program 84.2%

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

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

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

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

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

        \[\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 ky around 0 56.2%

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

    if 2.00000000000000006e-53 < (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.6%

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

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

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

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

        \[\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 51.1%

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

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

Alternative 3: 46.8% accurate, 1.4× speedup?

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

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

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

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


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

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

        \[\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. Step-by-step derivation
      1. associate-*r/99.6%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div2.7%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.4%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod16.8%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow216.8%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr16.8%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow216.8%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square22.5%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified22.5%

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

    if -0.10000000000000001 < (sin.f64 ky) < -1e-179

    1. Initial program 91.8%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{ky}} \]
    6. Step-by-step derivation
      1. mul-1-neg42.1%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{\frac{ky}{\sin ky}}} \]
      3. distribute-neg-frac63.2%

        \[\leadsto \color{blue}{\frac{-\sin th}{\frac{ky}{\sin ky}}} \]
    7. Simplified63.2%

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

    if -1e-179 < (sin.f64 ky) < 2.00000000000000006e-53

    1. Initial program 84.2%

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

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

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

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

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

        \[\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 ky around 0 54.0%

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

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

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

    if 2.00000000000000006e-53 < (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.6%

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

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

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

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

        \[\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 51.1%

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

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

Alternative 4: 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 92.9%

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

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

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

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

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

      \[\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. Final simplification99.6%

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

Alternative 5: 82.1% accurate, 1.7× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{\frac{1}{\sin th}}\\


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

    1. Initial program 93.0%

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

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

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

        \[\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 ky around 0 54.7%

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

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

    if -1 < th < 1.8e5

    1. Initial program 93.3%

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

        \[\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.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. Step-by-step derivation
      1. associate-*r/90.8%

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

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

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

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

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

      \[\leadsto \frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\color{blue}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    7. Step-by-step derivation
      1. *-commutative23.6%

        \[\leadsto \frac{1}{\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}} \]
    8. Simplified96.9%

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

    if 1.8e5 < th

    1. Initial program 92.1%

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. associate-*r/99.6%

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

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

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

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

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

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

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

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

Alternative 6: 82.2% accurate, 1.7× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{\frac{1}{\sin th}}\\


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

    1. Initial program 93.0%

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

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

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

        \[\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 ky around 0 54.7%

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

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

    if -1 < th < 14.5

    1. Initial program 93.3%

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

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

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

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

        \[\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 th around 0 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 14.5 < th

    1. Initial program 92.2%

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. associate-*r/99.6%

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

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

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

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

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

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

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

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

Alternative 7: 82.2% accurate, 1.7× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{t_1}{\frac{1}{\sin th}}\\


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

    1. Initial program 93.0%

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

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

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

        \[\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 ky around 0 54.7%

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

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

    if -1 < th < 14.5

    1. Initial program 93.3%

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

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

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

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

        \[\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 th around 0 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 14.5 < th

    1. Initial program 92.2%

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

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

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

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

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

        \[\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. Step-by-step derivation
      1. associate-*r/99.6%

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

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

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

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

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

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

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

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

Alternative 8: 46.1% accurate, 1.7× speedup?

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-53}:\\
\;\;\;\;\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) < -4.0000000000000002e-123

    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/95.1%

        \[\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. Step-by-step derivation
      1. associate-*r/95.0%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div3.0%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.4%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod19.1%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow219.1%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr19.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow219.1%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square26.8%

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

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

    if -4.0000000000000002e-123 < (sin.f64 ky) < 2.00000000000000006e-53

    1. Initial program 83.5%

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

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

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

        \[\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 53.4%

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

    if 2.00000000000000006e-53 < (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.6%

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

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

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

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

        \[\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 51.1%

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

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

Alternative 9: 46.1% accurate, 1.7× speedup?

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

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

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

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


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

    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/95.1%

        \[\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. Step-by-step derivation
      1. associate-*r/95.0%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div3.0%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.4%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod19.1%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow219.1%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr19.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow219.1%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square26.8%

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

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

    if -4.0000000000000002e-123 < (sin.f64 ky) < 2.00000000000000006e-53

    1. Initial program 83.5%

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin th}} \]
      4. unpow283.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 ky around 0 53.5%

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

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

    if 2.00000000000000006e-53 < (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.6%

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

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

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

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

        \[\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 51.1%

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

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

Alternative 10: 46.1% accurate, 1.7× speedup?

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-53}:\\
\;\;\;\;\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) < -4.0000000000000002e-123

    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/95.1%

        \[\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. Step-by-step derivation
      1. associate-*r/95.0%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div3.0%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.4%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod19.1%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow219.1%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr19.1%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow219.1%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square26.8%

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

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

    if -4.0000000000000002e-123 < (sin.f64 ky) < 2.00000000000000006e-53

    1. Initial program 83.5%

      \[\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. associate-*r/83.6%

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      5. unpow283.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 ky around 0 51.7%

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

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

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

    if 2.00000000000000006e-53 < (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.6%

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

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

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

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

        \[\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 51.1%

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

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

Alternative 11: 72.1% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 90.8%

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

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

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

        \[\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 ky around 0 71.4%

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

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

    if 4.99999999999999999e-15 < (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.7%

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

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

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

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

        \[\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 52.1%

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

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

Alternative 12: 32.3% accurate, 3.5× speedup?

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

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

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

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


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

    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/95.6%

        \[\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. Step-by-step derivation
      1. associate-*r/95.6%

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Step-by-step derivation
      1. remove-double-div22.7%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt13.5%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod21.4%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow221.4%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr21.4%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow221.4%

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

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

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

    if -3.39999999999999995e-131 < ky < 1.29999999999999998e-53

    1. Initial program 83.2%

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

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

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

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

        \[\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 42.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.29999999999999998e-53 < 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. 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.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 30.5%

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

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

Alternative 13: 32.2% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.10000000000000009 or 1.29999999999999998e-53 < 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. associate-*r/99.5%

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

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

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

        \[\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 29.7%

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

    if -3.10000000000000009 < ky < 1.29999999999999998e-53

    1. Initial program 86.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin th}} \]
      4. unpow286.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 th around 0 41.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 32.1% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.10000000000000009 or 6.0999999999999999e-52 < 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. associate-*r/99.5%

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

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

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

        \[\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 29.7%

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

    if -3.10000000000000009 < ky < 6.0999999999999999e-52

    1. Initial program 86.0%

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin th}} \]
      4. unpow286.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 th around 0 41.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 28.6% accurate, 6.6× speedup?

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

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

\mathbf{elif}\;ky \leq 1.42 \cdot 10^{-259}:\\
\;\;\;\;\sqrt{th \cdot th}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.10000000000000009 or 1.42e-259 < ky

    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/93.5%

        \[\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.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 27.7%

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

    if -3.10000000000000009 < ky < 1.42e-259

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Taylor expanded in th around 0 4.2%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{th}}} \]
    8. Step-by-step derivation
      1. remove-double-div4.2%

        \[\leadsto \color{blue}{th} \]
      2. add-sqr-sqrt2.0%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      3. sqrt-unprod17.4%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    9. Applied egg-rr17.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.1:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.42 \cdot 10^{-259}:\\ \;\;\;\;\sqrt{th \cdot th}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 16: 24.3% accurate, 7.0× speedup?

\[\begin{array}{l} \\ \sin th \end{array} \]
(FPCore (kx ky th) :precision binary64 (sin th))
double code(double kx, double ky, double th) {
	return 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(th)
end function
public static double code(double kx, double ky, double th) {
	return Math.sin(th);
}
def code(kx, ky, th):
	return math.sin(th)
function code(kx, ky, th)
	return sin(th)
end
function tmp = code(kx, ky, th)
	tmp = sin(th);
end
code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

      \[\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 20.6%

    \[\leadsto \color{blue}{\sin th} \]
  5. Final simplification20.6%

    \[\leadsto \sin th \]

Alternative 17: 15.0% accurate, 78.8× speedup?

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

\\
\frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666}
\end{array}
Derivation
  1. Initial program 92.9%

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

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

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

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

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

      \[\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. Step-by-step derivation
    1. associate-*r/95.0%

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
  7. Taylor expanded in th around 0 14.4%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
  8. Step-by-step derivation
    1. *-commutative14.4%

      \[\leadsto \frac{1}{\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}} \]
  9. Simplified14.4%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{th} + th \cdot 0.16666666666666666}} \]
  10. Final simplification14.4%

    \[\leadsto \frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666} \]

Alternative 18: 14.4% 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 92.9%

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

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

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

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

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

      \[\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. Step-by-step derivation
    1. associate-*r/95.0%

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
  7. Taylor expanded in th around 0 13.8%

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

    \[\leadsto th \]

Reproduce

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