Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 21.1s
Alternatives: 19
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 19 alternatives:

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

Initial Program: 93.8% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000024e-5 < (sin.f64 ky) < 4.9999999999999998e-8

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

Alternative 3: 77.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000024e-5 < (sin.f64 ky) < 4.9999999999999998e-8

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

Alternative 4: 77.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -5.00000000000000024e-5 < (sin.f64 ky) < 4.9999999999999998e-8

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

Alternative 5: 77.1% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}}{\sin th}} \]
    3. Simplified99.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 56.4%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\frac{1}{th} \cdot \mathsf{hypot}\left(\sin kx, \sin ky\right) + \left(0.16666666666666666 \cdot th\right) \cdot \color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}} \]
      9. distribute-rgt-out56.4%

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

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

    if -5.00000000000000024e-5 < (sin.f64 ky) < 4.9999999999999998e-8

    1. Initial program 88.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

Alternative 6: 46.2% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 92.1%

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

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

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

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

    if -1.9999999999999998e-308 < (sin.f64 ky) < 9.9999999999999996e-70

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e-70 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 7: 47.4% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 92.1%

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

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

    if -1.9999999999999998e-308 < (sin.f64 ky) < 9.9999999999999996e-70

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e-70 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 8: 46.4% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 91.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-270 < (sin.f64 ky) < 9.9999999999999996e-70

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e-70 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 9: 47.4% accurate, 1.4× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

    if -1.9999999999999998e-308 < (sin.f64 ky) < 9.9999999999999996e-70

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e-70 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 10: 46.4% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 91.9%

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

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

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

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

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

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

    if 2.0000000000000001e-270 < (sin.f64 ky) < 9.9999999999999996e-70

    1. Initial program 90.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999996e-70 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 11: 65.8% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.6%

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

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

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

Alternative 12: 33.9% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 91.5%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}} \]
      2. div-inv23.1%

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

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

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

    if 9.99999999999999997e-74 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 13: 40.9% accurate, 2.3× speedup?

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

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


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

    1. Initial program 91.5%

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

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

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

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

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

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

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

    if 9.99999999999999997e-74 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 14: 40.9% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999997e-74 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 15: 30.8% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 91.5%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}} \]
      2. div-inv23.1%

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

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

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

    if 9.99999999999999997e-74 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 16: 33.7% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

    if 9.99999999999999997e-74 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 17: 30.4% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1e3 or 8.9999999999999998e-74 < ky

    1. Initial program 99.7%

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

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

    if -1e3 < ky < 8.9999999999999998e-74

    1. Initial program 86.1%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 18: 21.6% accurate, 77.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -6 \cdot 10^{+34}:\\
\;\;\;\;th\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6.00000000000000037e34 or 1.85e-73 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

    if -6.00000000000000037e34 < ky < 1.85e-73

    1. Initial program 87.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6 \cdot 10^{+34}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 1.85 \cdot 10^{-73}:\\ \;\;\;\;\frac{ky}{\frac{kx}{th}}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 19: 13.8% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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