Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.7%
Time: 23.1s
Alternatives: 24
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 24 alternatives:

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

Initial Program: 94.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 68.6% accurate, 1.2× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.1%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.1%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.1%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.1%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod10.4%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow210.4%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr10.4%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square19.9%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified19.9%

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

    if -0.209999999999999992 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 85.5%

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
      3. unpow285.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 90.4%

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 3: 77.0% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.0%

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 4: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 5: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 6: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 7: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 8: 76.9% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 9: 77.1% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.044999999999999998 < (sin.f64 ky) < 2.00000000000000016e-5

    1. Initial program 84.2%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000016e-5 < (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 65.1%

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

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

Alternative 10: 44.3% accurate, 1.4× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.2%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.2%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.2%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.2%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod10.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow210.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr10.1%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square18.7%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified18.7%

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

    if -0.13 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.4%

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 11: 44.3% accurate, 1.4× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.2%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.2%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.2%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.2%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod10.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow210.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr10.1%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square19.0%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified19.0%

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.7%

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 12: 44.3% accurate, 1.4× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.2%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.2%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.2%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.2%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod10.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow210.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr10.1%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square19.0%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified19.0%

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 13: 44.3% accurate, 1.4× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.7%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.2%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.2%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.2%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.2%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod10.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow210.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr10.1%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square19.0%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified19.0%

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

    if -0.149999999999999994 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.7%

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 14: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

      \[\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 \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \]

Alternative 15: 44.2% accurate, 1.7× speedup?

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.1%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.1%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.1%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.1%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod9.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow29.8%

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

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square18.1%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified18.1%

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

    if -0.089999999999999997 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.1%

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

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

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

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 16: 44.2% accurate, 1.7× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.1%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.1%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.1%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.1%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod9.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow29.8%

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

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square18.1%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified18.1%

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

    if -0.089999999999999997 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.1%

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 17: 44.2% accurate, 1.7× speedup?

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

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

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

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


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

    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{\color{blue}{\sin th \cdot \sin ky}}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. associate-*l/99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 3.1%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*3.1%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse3.1%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity3.1%

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

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod9.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow29.8%

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

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square18.1%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified18.1%

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

    if -0.089999999999999997 < (sin.f64 ky) < 1.99999999999999989e-67

    1. Initial program 82.1%

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999989e-67 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 18: 32.6% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 2.9 \cdot 10^{-97}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.4e15 or 2.8999999999999999e-97 < 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 37.4%

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

    if -3.4e15 < ky < 2.8999999999999999e-97

    1. Initial program 80.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 36.2%

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\sin kx} \cdot th} \]
    11. Applied egg-rr40.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 2.9 \cdot 10^{-97}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;th \cdot \frac{ky}{\sin kx}\\ \end{array} \]

Alternative 19: 32.6% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 2.65 \cdot 10^{-97}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.4e15 or 2.64999999999999996e-97 < 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 37.4%

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

    if -3.4e15 < ky < 2.64999999999999996e-97

    1. Initial program 80.4%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 36.2%

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{th}}} \]
    10. Step-by-step derivation
      1. clear-num40.1%

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

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

        \[\leadsto \color{blue}{\frac{th}{\sin kx}} \cdot ky \]
    11. Applied egg-rr40.2%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 2.65 \cdot 10^{-97}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \end{array} \]

Alternative 20: 31.2% accurate, 6.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 3.4 \cdot 10^{-154}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.4e15 or 3.3999999999999998e-154 < 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 36.8%

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

    if -3.4e15 < ky < 3.3999999999999998e-154

    1. Initial program 78.6%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 37.2%

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified36.1%

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    13. Step-by-step derivation
      1. div-inv36.1%

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

        \[\leadsto ky \cdot \color{blue}{\frac{th}{kx}} \]
      3. *-commutative36.1%

        \[\leadsto \color{blue}{\frac{th}{kx} \cdot ky} \]
    14. Applied egg-rr36.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3.4 \cdot 10^{+15} \lor \neg \left(ky \leq 3.4 \cdot 10^{-154}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{th}{kx}\\ \end{array} \]

Alternative 21: 21.8% accurate, 6.9× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 11.1%

      \[\leadsto \left(th \cdot \color{blue}{\frac{1}{\sin ky}}\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. associate-*l*11.2%

        \[\leadsto \color{blue}{th \cdot \left(\frac{1}{\sin ky} \cdot \sin ky\right)} \]
      2. lft-mult-inverse11.2%

        \[\leadsto th \cdot \color{blue}{1} \]
      3. *-rgt-identity11.2%

        \[\leadsto \color{blue}{th} \]
      4. add-sqr-sqrt4.9%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      5. sqrt-unprod7.9%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      6. pow27.9%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    9. Applied egg-rr7.9%

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

        \[\leadsto \sqrt{\color{blue}{th \cdot th}} \]
      2. rem-sqrt-square15.0%

        \[\leadsto \color{blue}{\left|th\right|} \]
    11. Simplified15.0%

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

    if -1.54999999999999994e-149 < ky < 4.5000000000000002e-93

    1. Initial program 74.3%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 44.3%

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    12. Simplified44.0%

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    14. Applied egg-rr44.1%

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

    if 4.5000000000000002e-93 < 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/97.0%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 23.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.55 \cdot 10^{-149}:\\ \;\;\;\;\left|th\right|\\ \mathbf{elif}\;ky \leq 4.5 \cdot 10^{-93}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 22: 21.6% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.3000000000000001e-50 or 1.8e-94 < 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/98.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 19.3%

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

    if -1.3000000000000001e-50 < ky < 1.8e-94

    1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 39.0%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    14. Applied egg-rr37.1%

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

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

Alternative 23: 21.6% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.3000000000000001e-50 or 1.09999999999999998e-93 < 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/98.1%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in kx around 0 19.3%

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

    if -1.3000000000000001e-50 < ky < 1.09999999999999998e-93

    1. Initial program 78.8%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
    7. Taylor expanded in ky around 0 39.0%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{kx}{th}}} \]
    13. Step-by-step derivation
      1. div-inv37.0%

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

        \[\leadsto ky \cdot \color{blue}{\frac{th}{kx}} \]
      3. *-commutative37.0%

        \[\leadsto \color{blue}{\frac{th}{kx} \cdot ky} \]
    14. Applied egg-rr37.0%

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

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

Alternative 24: 13.2% 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 91.9%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\left(th \cdot \sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}}\right)} \cdot \sin ky \]
  7. Taylor expanded in kx around 0 14.1%

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

    \[\leadsto th \]

Reproduce

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