Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.9% → 99.7%
Time: 25.3s
Alternatives: 20
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 20 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.9% 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 96.0%

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

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

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

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

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

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

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

Alternative 2: 42.4% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot ky}{\sin kx}}\right| \]
      4. associate-*l/35.4%

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

        \[\leadsto \left|\color{blue}{ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    10. Simplified35.4%

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

    if -1.00000000000000005e-4 < (sin.f64 kx) < -1.00000000000000004e-153

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin th \cdot \sin ky}{kx}\right)}^{2}}} \]
      4. associate-/l*12.7%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{kx}{\sin ky}}\right)}^{2}}} \]
    8. Taylor expanded in kx around -inf 44.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{kx}} \]
    9. Step-by-step derivation
      1. mul-1-neg44.0%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{kx} \cdot \sin ky} \]
      3. *-commutative47.9%

        \[\leadsto -\color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      4. distribute-rgt-neg-in47.9%

        \[\leadsto \color{blue}{\sin ky \cdot \left(-\frac{\sin th}{kx}\right)} \]
      5. *-lft-identity47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{1 \cdot \frac{\sin th}{kx}}\right) \]
      6. metadata-eval47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1}{-1}} \cdot \frac{\sin th}{kx}\right) \]
      7. times-frac47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1 \cdot \sin th}{-1 \cdot kx}}\right) \]
      8. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{\color{blue}{-\sin th}}{-1 \cdot kx}\right) \]
      9. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{-\sin th}{\color{blue}{-kx}}\right) \]
      10. distribute-frac-neg47.9%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{-\left(-\sin th\right)}{-kx}} \]
      11. remove-double-neg47.9%

        \[\leadsto \sin ky \cdot \frac{\color{blue}{\sin th}}{-kx} \]
    10. Simplified47.9%

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

    if -1.00000000000000004e-153 < (sin.f64 kx) < 1.99999999999999991e-44

    1. Initial program 89.7%

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

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

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

        \[\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 kx around 0 44.0%

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

    if 1.99999999999999991e-44 < (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. Step-by-step derivation
      1. log1p-expm1-u99.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.0001:\\ \;\;\;\;\left|ky \cdot \frac{\sin th}{\sin kx}\right|\\ \mathbf{elif}\;\sin kx \leq -1 \cdot 10^{-153}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{-kx}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-44}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \mathsf{log1p}\left(\frac{ky}{\sin kx}\right)\\ \end{array} \]

Alternative 3: 44.7% accurate, 1.2× speedup?

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

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

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

\mathbf{elif}\;\sin kx \leq 10^{-150}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot ky}{\sin kx}}\right| \]
      4. associate-*l/35.4%

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

        \[\leadsto \left|\color{blue}{ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    10. Simplified35.4%

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

    if -1.00000000000000005e-4 < (sin.f64 kx) < -1.00000000000000004e-153

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin th \cdot \sin ky}{kx}\right)}^{2}}} \]
      4. associate-/l*12.7%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{kx}{\sin ky}}\right)}^{2}}} \]
    8. Taylor expanded in kx around -inf 44.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{kx}} \]
    9. Step-by-step derivation
      1. mul-1-neg44.0%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{kx} \cdot \sin ky} \]
      3. *-commutative47.9%

        \[\leadsto -\color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      4. distribute-rgt-neg-in47.9%

        \[\leadsto \color{blue}{\sin ky \cdot \left(-\frac{\sin th}{kx}\right)} \]
      5. *-lft-identity47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{1 \cdot \frac{\sin th}{kx}}\right) \]
      6. metadata-eval47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1}{-1}} \cdot \frac{\sin th}{kx}\right) \]
      7. times-frac47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1 \cdot \sin th}{-1 \cdot kx}}\right) \]
      8. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{\color{blue}{-\sin th}}{-1 \cdot kx}\right) \]
      9. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{-\sin th}{\color{blue}{-kx}}\right) \]
      10. distribute-frac-neg47.9%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{-\left(-\sin th\right)}{-kx}} \]
      11. remove-double-neg47.9%

        \[\leadsto \sin ky \cdot \frac{\color{blue}{\sin th}}{-kx} \]
    10. Simplified47.9%

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

    if -1.00000000000000004e-153 < (sin.f64 kx) < 1.00000000000000001e-150

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

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

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

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

    if 1.00000000000000001e-150 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

Alternative 4: 44.7% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin kx \leq 10^{-150}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot ky}{\sin kx}}\right| \]
      4. associate-*l/35.4%

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

        \[\leadsto \left|\color{blue}{ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    10. Simplified35.4%

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

    if -1.00000000000000005e-4 < (sin.f64 kx) < -1.00000000000000004e-153

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin th \cdot \sin ky}{kx}\right)}^{2}}} \]
      4. associate-/l*12.7%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{kx}{\sin ky}}\right)}^{2}}} \]
    8. Taylor expanded in kx around -inf 44.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{kx}} \]
    9. Step-by-step derivation
      1. mul-1-neg44.0%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{kx} \cdot \sin ky} \]
      3. *-commutative47.9%

        \[\leadsto -\color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      4. distribute-rgt-neg-in47.9%

        \[\leadsto \color{blue}{\sin ky \cdot \left(-\frac{\sin th}{kx}\right)} \]
      5. *-lft-identity47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{1 \cdot \frac{\sin th}{kx}}\right) \]
      6. metadata-eval47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1}{-1}} \cdot \frac{\sin th}{kx}\right) \]
      7. times-frac47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1 \cdot \sin th}{-1 \cdot kx}}\right) \]
      8. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{\color{blue}{-\sin th}}{-1 \cdot kx}\right) \]
      9. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{-\sin th}{\color{blue}{-kx}}\right) \]
      10. distribute-frac-neg47.9%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{-\left(-\sin th\right)}{-kx}} \]
      11. remove-double-neg47.9%

        \[\leadsto \sin ky \cdot \frac{\color{blue}{\sin th}}{-kx} \]
    10. Simplified47.9%

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

    if -1.00000000000000004e-153 < (sin.f64 kx) < 1.00000000000000001e-150

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

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

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

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

    if 1.00000000000000001e-150 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

Alternative 5: 45.9% accurate, 1.2× speedup?

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

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

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

\mathbf{elif}\;\sin kx \leq 10^{-150}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.0200000000000000004 < (sin.f64 kx) < -1.00000000000000004e-153

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin th \cdot \sin ky}{kx}\right)}^{2}}} \]
      4. associate-/l*14.9%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{kx}{\sin ky}}\right)}^{2}}} \]
    8. Taylor expanded in kx around -inf 44.8%

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

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

        \[\leadsto -\color{blue}{\frac{\sin th}{kx} \cdot \sin ky} \]
      3. *-commutative48.6%

        \[\leadsto -\color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      4. distribute-rgt-neg-in48.6%

        \[\leadsto \color{blue}{\sin ky \cdot \left(-\frac{\sin th}{kx}\right)} \]
      5. *-lft-identity48.6%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{1 \cdot \frac{\sin th}{kx}}\right) \]
      6. metadata-eval48.6%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1}{-1}} \cdot \frac{\sin th}{kx}\right) \]
      7. times-frac48.6%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1 \cdot \sin th}{-1 \cdot kx}}\right) \]
      8. neg-mul-148.6%

        \[\leadsto \sin ky \cdot \left(-\frac{\color{blue}{-\sin th}}{-1 \cdot kx}\right) \]
      9. neg-mul-148.6%

        \[\leadsto \sin ky \cdot \left(-\frac{-\sin th}{\color{blue}{-kx}}\right) \]
      10. distribute-frac-neg48.6%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{-\left(-\sin th\right)}{-kx}} \]
      11. remove-double-neg48.6%

        \[\leadsto \sin ky \cdot \frac{\color{blue}{\sin th}}{-kx} \]
    10. Simplified48.6%

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

    if -1.00000000000000004e-153 < (sin.f64 kx) < 1.00000000000000001e-150

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

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

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

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

    if 1.00000000000000001e-150 < (sin.f64 kx)

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

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

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

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

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

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

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

Alternative 6: 60.3% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 97.5%

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

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

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

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

    if -0.050000000000000003 < (sin.f64 th) < 0.050000000000000003

    1. Initial program 95.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.050000000000000003 < (sin.f64 th)

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin ky}{\sin kx} \cdot \sin th\right)}^{2}}} \]
      4. associate-*l/17.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      5. *-un-lft-identity17.2%

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

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

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

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

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

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

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

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

Alternative 7: 60.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 97.5%

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

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

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

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

    if -0.050000000000000003 < (sin.f64 th) < 0.050000000000000003

    1. Initial program 95.2%

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

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

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

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

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

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

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

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

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

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

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

    if 0.050000000000000003 < (sin.f64 th)

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin ky}{\sin kx} \cdot \sin th\right)}^{2}}} \]
      4. associate-*l/17.2%

        \[\leadsto \sqrt{{\color{blue}{\left(\frac{\sin ky \cdot \sin th}{\sin kx}\right)}}^{2}} \]
      5. *-un-lft-identity17.2%

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

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

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

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

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

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

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

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

Alternative 8: 42.4% accurate, 1.4× speedup?

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

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\color{blue}{\frac{\sin th \cdot ky}{\sin kx}}\right| \]
      4. associate-*l/35.4%

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

        \[\leadsto \left|\color{blue}{ky \cdot \frac{\sin th}{\sin kx}}\right| \]
    10. Simplified35.4%

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

    if -1.00000000000000005e-4 < (sin.f64 kx) < -1.00000000000000004e-153

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\frac{\sin th \cdot \sin ky}{kx}\right)}^{2}}} \]
      4. associate-/l*12.7%

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

      \[\leadsto \color{blue}{\sqrt{{\left(\frac{\sin th}{\frac{kx}{\sin ky}}\right)}^{2}}} \]
    8. Taylor expanded in kx around -inf 44.0%

      \[\leadsto \color{blue}{-1 \cdot \frac{\sin th \cdot \sin ky}{kx}} \]
    9. Step-by-step derivation
      1. mul-1-neg44.0%

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

        \[\leadsto -\color{blue}{\frac{\sin th}{kx} \cdot \sin ky} \]
      3. *-commutative47.9%

        \[\leadsto -\color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      4. distribute-rgt-neg-in47.9%

        \[\leadsto \color{blue}{\sin ky \cdot \left(-\frac{\sin th}{kx}\right)} \]
      5. *-lft-identity47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{1 \cdot \frac{\sin th}{kx}}\right) \]
      6. metadata-eval47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1}{-1}} \cdot \frac{\sin th}{kx}\right) \]
      7. times-frac47.9%

        \[\leadsto \sin ky \cdot \left(-\color{blue}{\frac{-1 \cdot \sin th}{-1 \cdot kx}}\right) \]
      8. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{\color{blue}{-\sin th}}{-1 \cdot kx}\right) \]
      9. neg-mul-147.9%

        \[\leadsto \sin ky \cdot \left(-\frac{-\sin th}{\color{blue}{-kx}}\right) \]
      10. distribute-frac-neg47.9%

        \[\leadsto \sin ky \cdot \color{blue}{\frac{-\left(-\sin th\right)}{-kx}} \]
      11. remove-double-neg47.9%

        \[\leadsto \sin ky \cdot \frac{\color{blue}{\sin th}}{-kx} \]
    10. Simplified47.9%

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

    if -1.00000000000000004e-153 < (sin.f64 kx) < 1.99999999999999991e-44

    1. Initial program 89.7%

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

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

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

        \[\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 kx around 0 44.0%

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

    if 1.99999999999999991e-44 < (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 52.2%

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

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

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

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

Alternative 9: 47.7% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 95.8%

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

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

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

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

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

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

    if -1.00000000000000004e-297 < (sin.f64 ky) < 4.00000000000000015e-25

    1. Initial program 92.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt36.4%

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

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

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

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

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

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

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

    if 4.00000000000000015e-25 < (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.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 56.5%

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

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

Alternative 10: 47.7% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 95.8%

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000004e-297 < (sin.f64 ky) < 4.00000000000000015e-25

    1. Initial program 92.6%

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sin kx}{ky}}} \]
    7. Step-by-step derivation
      1. add-sqr-sqrt36.4%

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

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

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

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

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

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

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

    if 4.00000000000000015e-25 < (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.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 56.5%

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

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

Alternative 11: 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 96.0%

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

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

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

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

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

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

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

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

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

Alternative 12: 74.3% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < -3.59999999999999984e-6 or 1.25e12 < th

    1. Initial program 96.9%

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

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

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

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

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

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

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

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

    if -3.59999999999999984e-6 < th < 1.25e12

    1. Initial program 95.2%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 13: 40.4% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 94.2%

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

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

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

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

    if 9.99999999999999979e-121 < (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.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 53.0%

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

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

Alternative 14: 40.4% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 94.2%

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

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

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

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

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

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

    if 9.99999999999999979e-121 < (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.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 53.0%

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

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

Alternative 15: 34.0% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 94.1%

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000011e-128 < (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.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 53.0%

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

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

Alternative 16: 32.6% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -4.7e5 or 1.39999999999999995e-173 < ky

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

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

    if -4.7e5 < ky < 1.39999999999999995e-173

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 32.6% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -4.7e5 or 1.80000000000000007e-172 < ky

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

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

    if -4.7e5 < ky < 1.80000000000000007e-172

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 18: 31.1% accurate, 6.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -2.9e6 or 2.4500000000000001e-163 < ky

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

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

    if -2.9e6 < ky < 2.4500000000000001e-163

    1. Initial program 89.9%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    10. Applied egg-rr32.9%

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

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

Alternative 19: 21.9% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -125000 or 1.99999999999999996e-120 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

    if -125000 < ky < 1.99999999999999996e-120

    1. Initial program 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    10. Applied egg-rr32.4%

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

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

Alternative 20: 13.5% 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 96.0%

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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