Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.7%
Time: 24.6s
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: 93.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow293.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 \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th \]

Alternative 2: 59.1% accurate, 1.0× speedup?

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

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

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

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

\mathbf{elif}\;\sin ky \leq 10^{-49}:\\
\;\;\;\;t_1\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-154.1%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified54.1%

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

    if -1.00000000000000004e-10 < (sin.f64 ky) < -4.9999999999999998e-303 or 4.99999999999999994e-93 < (sin.f64 ky) < 9.99999999999999936e-50

    1. Initial program 87.7%

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

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

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

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

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

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

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

    if -4.9999999999999998e-303 < (sin.f64 ky) < 4.99999999999999994e-93

    1. Initial program 86.5%

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

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

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

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

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

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

    if 9.99999999999999936e-50 < (sin.f64 ky) < 1.99999999999999985e-24

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\sin kx} \cdot ky} \]
    6. Applied egg-rr35.8%

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

    if 1.99999999999999985e-24 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

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

Alternative 3: 53.9% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
t_1 := -\sin th\\
t_2 := \sin th \cdot \frac{ky}{\sin kx}\\
\mathbf{if}\;\sin ky \leq -1.6 \cdot 10^{-33}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-196}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-230}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-24}:\\
\;\;\;\;t_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 ky) < -1.59999999999999988e-33 or -5.0000000000000005e-196 < (sin.f64 ky) < -1.00000000000000005e-230

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-158.1%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified58.1%

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

    if -1.59999999999999988e-33 < (sin.f64 ky) < -5.0000000000000005e-196 or -1.00000000000000005e-230 < (sin.f64 ky) < 1.99999999999999985e-24

    1. Initial program 90.5%

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

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

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

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

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

    if 1.99999999999999985e-24 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1.6 \cdot 10^{-33}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-196}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-230}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 4: 53.9% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;\sin ky \leq -1.6 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-196}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= (sin ky) -1.6e-33)
     t_1
     (if (<= (sin ky) -5e-196)
       (* ky (/ (sin th) (sin kx)))
       (if (<= (sin ky) -1e-230)
         t_1
         (if (<= (sin ky) 2e-24) (* (sin th) (/ ky (sin kx))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (sin(ky) <= -1.6e-33) {
		tmp = t_1;
	} else if (sin(ky) <= -5e-196) {
		tmp = ky * (sin(th) / sin(kx));
	} else if (sin(ky) <= -1e-230) {
		tmp = t_1;
	} else if (sin(ky) <= 2e-24) {
		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) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (sin(ky) <= (-1.6d-33)) then
        tmp = t_1
    else if (sin(ky) <= (-5d-196)) then
        tmp = ky * (sin(th) / sin(kx))
    else if (sin(ky) <= (-1d-230)) then
        tmp = t_1
    else if (sin(ky) <= 2d-24) 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 t_1 = -Math.sin(th);
	double tmp;
	if (Math.sin(ky) <= -1.6e-33) {
		tmp = t_1;
	} else if (Math.sin(ky) <= -5e-196) {
		tmp = ky * (Math.sin(th) / Math.sin(kx));
	} else if (Math.sin(ky) <= -1e-230) {
		tmp = t_1;
	} else if (Math.sin(ky) <= 2e-24) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if math.sin(ky) <= -1.6e-33:
		tmp = t_1
	elif math.sin(ky) <= -5e-196:
		tmp = ky * (math.sin(th) / math.sin(kx))
	elif math.sin(ky) <= -1e-230:
		tmp = t_1
	elif math.sin(ky) <= 2e-24:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (sin(ky) <= -1.6e-33)
		tmp = t_1;
	elseif (sin(ky) <= -5e-196)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	elseif (sin(ky) <= -1e-230)
		tmp = t_1;
	elseif (sin(ky) <= 2e-24)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (sin(ky) <= -1.6e-33)
		tmp = t_1;
	elseif (sin(ky) <= -5e-196)
		tmp = ky * (sin(th) / sin(kx));
	elseif (sin(ky) <= -1e-230)
		tmp = t_1;
	elseif (sin(ky) <= 2e-24)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[N[Sin[ky], $MachinePrecision], -1.6e-33], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], -5e-196], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -1e-230], t$95$1, If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-24], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;\sin ky \leq -1.6 \cdot 10^{-33}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-230}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -1.59999999999999988e-33 or -5.0000000000000005e-196 < (sin.f64 ky) < -1.00000000000000005e-230

    1. Initial program 93.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-158.1%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified58.1%

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

    if -1.59999999999999988e-33 < (sin.f64 ky) < -5.0000000000000005e-196

    1. Initial program 95.9%

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000005e-230 < (sin.f64 ky) < 1.99999999999999985e-24

    1. Initial program 88.6%

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

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

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

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

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

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

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

    if 1.99999999999999985e-24 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -1.6 \cdot 10^{-33}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;\sin ky \leq -5 \cdot 10^{-196}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq -1 \cdot 10^{-230}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-24}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 5: 79.5% accurate, 1.2× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(1 + -0.5 \cdot \frac{{\sin kx}^{2}}{ky \cdot ky}\right)\\


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

    1. Initial program 99.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-154.7%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified54.7%

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < 5.0000000000000001e-4

    1. Initial program 88.4%

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

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

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

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

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

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

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

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

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

    if 5.0000000000000001e-4 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 79.5% accurate, 1.4× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(1 + -0.5 \cdot \frac{{\sin kx}^{2}}{ky \cdot ky}\right)\\


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

    1. Initial program 99.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-154.0%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified54.0%

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

    if -0.0100000000000000002 < (sin.f64 ky) < 5.0000000000000001e-4

    1. Initial program 88.5%

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

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

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

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

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

    if 5.0000000000000001e-4 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 79.5% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-154.0%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified54.0%

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

    if -0.0100000000000000002 < (sin.f64 ky) < 5.0000000000000001e-4

    1. Initial program 88.5%

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

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

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

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

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

    if 5.0000000000000001e-4 < (sin.f64 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. +-commutative99.7%

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

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

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

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

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

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

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

Alternative 8: 65.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    6. Applied egg-rr62.9%

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 9.99999999999999955e-7

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999955e-7 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

Alternative 9: 65.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    6. Applied egg-rr62.9%

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 9.99999999999999955e-7

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999955e-7 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

Alternative 10: 65.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    6. Applied egg-rr62.9%

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

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

    if -0.0400000000000000008 < (sin.f64 kx) < 9.99999999999999955e-7

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999955e-7 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

Alternative 11: 65.9% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sin kx\right|}} \cdot \sin th \]
    6. Applied egg-rr62.9%

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

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\left|\sin kx\right|}{ky}}} \]
    9. Simplified54.3%

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

    if -0.0400000000000000008 < (sin.f64 kx) < 9.99999999999999955e-7

    1. Initial program 87.4%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999955e-7 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

Alternative 12: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 79.7% accurate, 1.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if th < -8.1999999999999996e-10

    1. Initial program 92.4%

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

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

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

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

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

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

    if -8.1999999999999996e-10 < th < 1.35e15

    1. Initial program 93.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e15 < th < 4.2000000000000001e151

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.2000000000000001e151 < th

    1. Initial program 96.5%

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

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

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

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

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

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

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

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

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

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

Alternative 14: 79.8% accurate, 1.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if th < -7.7999999999999999e-5

    1. Initial program 92.2%

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

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

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

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

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

    if -7.7999999999999999e-5 < th < 1.35e15

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e15 < th < 1.9e151

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.9e151 < th

    1. Initial program 96.5%

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

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

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

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

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

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

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

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

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

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

Alternative 15: 79.8% accurate, 1.7× speedup?

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

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if th < -2.3e-5

    1. Initial program 92.2%

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

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

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

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

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

    if -2.3e-5 < th < 1.35e15

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.35e15 < th < 4.0999999999999998e151

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.0999999999999998e151 < th

    1. Initial program 96.5%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 68.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

    if 1e-3 < kx

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 57.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

    if 9.99999999999999955e-7 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

Alternative 18: 36.2% accurate, 6.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -2.5 \cdot 10^{-139}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.25 \cdot 10^{-203}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{elif}\;ky \leq -1.85 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 8 \cdot 10^{-105}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -2.5e-139)
     t_1
     (if (<= ky -2.25e-203)
       (/ ky (/ (sin kx) th))
       (if (<= ky -1.85e-230)
         t_1
         (if (<= ky 8e-105)
           (* (sin th) (/ ky kx))
           (if (<= ky 2.1e+29) (sin th) (if (<= ky 6e+175) t_1 (sin th)))))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -2.5e-139) {
		tmp = t_1;
	} else if (ky <= -2.25e-203) {
		tmp = ky / (sin(kx) / th);
	} else if (ky <= -1.85e-230) {
		tmp = t_1;
	} else if (ky <= 8e-105) {
		tmp = sin(th) * (ky / kx);
	} else if (ky <= 2.1e+29) {
		tmp = sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-2.5d-139)) then
        tmp = t_1
    else if (ky <= (-2.25d-203)) then
        tmp = ky / (sin(kx) / th)
    else if (ky <= (-1.85d-230)) then
        tmp = t_1
    else if (ky <= 8d-105) then
        tmp = sin(th) * (ky / kx)
    else if (ky <= 2.1d+29) then
        tmp = sin(th)
    else if (ky <= 6d+175) then
        tmp = t_1
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -2.5e-139) {
		tmp = t_1;
	} else if (ky <= -2.25e-203) {
		tmp = ky / (Math.sin(kx) / th);
	} else if (ky <= -1.85e-230) {
		tmp = t_1;
	} else if (ky <= 8e-105) {
		tmp = Math.sin(th) * (ky / kx);
	} else if (ky <= 2.1e+29) {
		tmp = Math.sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -2.5e-139:
		tmp = t_1
	elif ky <= -2.25e-203:
		tmp = ky / (math.sin(kx) / th)
	elif ky <= -1.85e-230:
		tmp = t_1
	elif ky <= 8e-105:
		tmp = math.sin(th) * (ky / kx)
	elif ky <= 2.1e+29:
		tmp = math.sin(th)
	elif ky <= 6e+175:
		tmp = t_1
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -2.5e-139)
		tmp = t_1;
	elseif (ky <= -2.25e-203)
		tmp = Float64(ky / Float64(sin(kx) / th));
	elseif (ky <= -1.85e-230)
		tmp = t_1;
	elseif (ky <= 8e-105)
		tmp = Float64(sin(th) * Float64(ky / kx));
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -2.5e-139)
		tmp = t_1;
	elseif (ky <= -2.25e-203)
		tmp = ky / (sin(kx) / th);
	elseif (ky <= -1.85e-230)
		tmp = t_1;
	elseif (ky <= 8e-105)
		tmp = sin(th) * (ky / kx);
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -2.5e-139], t$95$1, If[LessEqual[ky, -2.25e-203], N[(ky / N[(N[Sin[kx], $MachinePrecision] / th), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, -1.85e-230], t$95$1, If[LessEqual[ky, 8e-105], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 2.1e+29], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 6e+175], t$95$1, N[Sin[th], $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -2.5 \cdot 10^{-139}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;ky \leq -1.85 \cdot 10^{-230}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < -2.50000000000000017e-139 or -2.2500000000000001e-203 < ky < -1.84999999999999991e-230 or 2.1000000000000002e29 < ky < 6.0000000000000003e175

    1. Initial program 95.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-140.5%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified40.5%

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

    if -2.50000000000000017e-139 < ky < -2.2500000000000001e-203

    1. Initial program 92.0%

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

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

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

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

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

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

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

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

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

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

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

    if -1.84999999999999991e-230 < ky < 7.99999999999999972e-105

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

    if 7.99999999999999972e-105 < ky < 2.1000000000000002e29 or 6.0000000000000003e175 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -2.5 \cdot 10^{-139}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.25 \cdot 10^{-203}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{th}}\\ \mathbf{elif}\;ky \leq -1.85 \cdot 10^{-230}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq 8 \cdot 10^{-105}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 19: 30.3% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -1.62 \cdot 10^{-305}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 1.95 \cdot 10^{-105}:\\ \;\;\;\;\sqrt{th \cdot th}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -1.62e-305)
     t_1
     (if (<= ky 1.95e-105)
       (sqrt (* th th))
       (if (<= ky 2.1e+29) (sin th) (if (<= ky 6e+175) t_1 (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -1.62e-305) {
		tmp = t_1;
	} else if (ky <= 1.95e-105) {
		tmp = sqrt((th * th));
	} else if (ky <= 2.1e+29) {
		tmp = sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-1.62d-305)) then
        tmp = t_1
    else if (ky <= 1.95d-105) then
        tmp = sqrt((th * th))
    else if (ky <= 2.1d+29) then
        tmp = sin(th)
    else if (ky <= 6d+175) then
        tmp = t_1
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -1.62e-305) {
		tmp = t_1;
	} else if (ky <= 1.95e-105) {
		tmp = Math.sqrt((th * th));
	} else if (ky <= 2.1e+29) {
		tmp = Math.sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -1.62e-305:
		tmp = t_1
	elif ky <= 1.95e-105:
		tmp = math.sqrt((th * th))
	elif ky <= 2.1e+29:
		tmp = math.sin(th)
	elif ky <= 6e+175:
		tmp = t_1
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -1.62e-305)
		tmp = t_1;
	elseif (ky <= 1.95e-105)
		tmp = sqrt(Float64(th * th));
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -1.62e-305)
		tmp = t_1;
	elseif (ky <= 1.95e-105)
		tmp = sqrt((th * th));
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -1.62e-305], t$95$1, If[LessEqual[ky, 1.95e-105], N[Sqrt[N[(th * th), $MachinePrecision]], $MachinePrecision], If[LessEqual[ky, 2.1e+29], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 6e+175], t$95$1, N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -1.62 \cdot 10^{-305}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq 1.95 \cdot 10^{-105}:\\
\;\;\;\;\sqrt{th \cdot th}\\

\mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -1.61999999999999999e-305 or 2.1000000000000002e29 < ky < 6.0000000000000003e175

    1. Initial program 94.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-135.7%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified35.7%

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

    if -1.61999999999999999e-305 < ky < 1.95e-105

    1. Initial program 85.2%

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. hypot-def99.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. Step-by-step derivation
      1. associate-/r/99.7%

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

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

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

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

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

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

        \[\leadsto \color{blue}{th} \]
      2. add-sqr-sqrt4.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      3. sqrt-unprod29.6%

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

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

    if 1.95e-105 < ky < 2.1000000000000002e29 or 6.0000000000000003e175 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.62 \cdot 10^{-305}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq 1.95 \cdot 10^{-105}:\\ \;\;\;\;\sqrt{th \cdot th}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 20: 36.1% accurate, 6.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -1.85 \cdot 10^{-230}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 1.8 \cdot 10^{-104}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -1.85e-230)
     t_1
     (if (<= ky 1.8e-104)
       (* (sin th) (/ ky kx))
       (if (<= ky 2.1e+29) (sin th) (if (<= ky 6e+175) t_1 (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -1.85e-230) {
		tmp = t_1;
	} else if (ky <= 1.8e-104) {
		tmp = sin(th) * (ky / kx);
	} else if (ky <= 2.1e+29) {
		tmp = sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-1.85d-230)) then
        tmp = t_1
    else if (ky <= 1.8d-104) then
        tmp = sin(th) * (ky / kx)
    else if (ky <= 2.1d+29) then
        tmp = sin(th)
    else if (ky <= 6d+175) then
        tmp = t_1
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -1.85e-230) {
		tmp = t_1;
	} else if (ky <= 1.8e-104) {
		tmp = Math.sin(th) * (ky / kx);
	} else if (ky <= 2.1e+29) {
		tmp = Math.sin(th);
	} else if (ky <= 6e+175) {
		tmp = t_1;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -1.85e-230:
		tmp = t_1
	elif ky <= 1.8e-104:
		tmp = math.sin(th) * (ky / kx)
	elif ky <= 2.1e+29:
		tmp = math.sin(th)
	elif ky <= 6e+175:
		tmp = t_1
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -1.85e-230)
		tmp = t_1;
	elseif (ky <= 1.8e-104)
		tmp = Float64(sin(th) * Float64(ky / kx));
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -1.85e-230)
		tmp = t_1;
	elseif (ky <= 1.8e-104)
		tmp = sin(th) * (ky / kx);
	elseif (ky <= 2.1e+29)
		tmp = sin(th);
	elseif (ky <= 6e+175)
		tmp = t_1;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -1.85e-230], t$95$1, If[LessEqual[ky, 1.8e-104], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], If[LessEqual[ky, 2.1e+29], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 6e+175], t$95$1, N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -1.85 \cdot 10^{-230}:\\
\;\;\;\;t_1\\

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

\mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -1.84999999999999991e-230 or 2.1000000000000002e29 < ky < 6.0000000000000003e175

    1. Initial program 95.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-138.5%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified38.5%

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

    if -1.84999999999999991e-230 < ky < 1.7999999999999999e-104

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

    if 1.7999999999999999e-104 < ky < 2.1000000000000002e29 or 6.0000000000000003e175 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.85 \cdot 10^{-230}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq 1.8 \cdot 10^{-104}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+29}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 21: 30.1% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -3 \cdot 10^{-308} \lor \neg \left(ky \leq 2.1 \cdot 10^{+29}\right) \land ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= ky -3e-308) (and (not (<= ky 2.1e+29)) (<= ky 6e+175)))
   (- (sin th))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -3e-308) || (!(ky <= 2.1e+29) && (ky <= 6e+175))) {
		tmp = -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 ((ky <= (-3d-308)) .or. (.not. (ky <= 2.1d+29)) .and. (ky <= 6d+175)) then
        tmp = -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 ((ky <= -3e-308) || (!(ky <= 2.1e+29) && (ky <= 6e+175))) {
		tmp = -Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (ky <= -3e-308) or (not (ky <= 2.1e+29) and (ky <= 6e+175)):
		tmp = -math.sin(th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((ky <= -3e-308) || (!(ky <= 2.1e+29) && (ky <= 6e+175)))
		tmp = Float64(-sin(th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((ky <= -3e-308) || (~((ky <= 2.1e+29)) && (ky <= 6e+175)))
		tmp = -sin(th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[ky, -3e-308], And[N[Not[LessEqual[ky, 2.1e+29]], $MachinePrecision], LessEqual[ky, 6e+175]]], (-N[Sin[th], $MachinePrecision]), N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -3 \cdot 10^{-308} \lor \neg \left(ky \leq 2.1 \cdot 10^{+29}\right) \land ky \leq 6 \cdot 10^{+175}:\\
\;\;\;\;-\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -3.00000000000000022e-308 or 2.1000000000000002e29 < ky < 6.0000000000000003e175

    1. Initial program 94.4%

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

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

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

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

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

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

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    7. Step-by-step derivation
      1. neg-mul-135.7%

        \[\leadsto \color{blue}{-\sin th} \]
    8. Simplified35.7%

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

    if -3.00000000000000022e-308 < ky < 2.1000000000000002e29 or 6.0000000000000003e175 < ky

    1. Initial program 93.2%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -3 \cdot 10^{-308} \lor \neg \left(ky \leq 2.1 \cdot 10^{+29}\right) \land ky \leq 6 \cdot 10^{+175}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 22: 23.6% accurate, 7.0× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow293.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. Taylor expanded in kx around 0 21.0%

    \[\leadsto \color{blue}{\sin th} \]
  5. Final simplification21.0%

    \[\leadsto \sin th \]

Alternative 23: 14.6% accurate, 78.8× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow293.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. Step-by-step derivation
    1. associate-/r/99.6%

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

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

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

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

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

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

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

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

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

Alternative 24: 13.9% accurate, 709.0× speedup?

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

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow293.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. Step-by-step derivation
    1. associate-/r/99.6%

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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