Toniolo and Linder, Equation (3b), real

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

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

Initial Program: 94.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \frac{\sin 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 97.0%

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow297.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: 49.6% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{ky}{\sin kx}\\ \mathbf{if}\;\sin ky \leq -4 \cdot 10^{-28}:\\ \;\;\;\;\frac{1}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}\\ \mathbf{elif}\;\sin ky \leq -2 \cdot 10^{-301}:\\ \;\;\;\;t_1 \cdot \frac{-1}{\frac{-1}{\sin th}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-26}:\\ \;\;\;\;\sin th \cdot \left|t_1\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ ky (sin kx))))
   (if (<= (sin ky) -4e-28)
     (/ 1.0 (fabs (fma th 0.16666666666666666 (/ 1.0 th))))
     (if (<= (sin ky) -2e-301)
       (* t_1 (/ -1.0 (/ -1.0 (sin th))))
       (if (<= (sin ky) 5e-26) (* (sin th) (fabs t_1)) (sin th))))))
double code(double kx, double ky, double th) {
	double t_1 = ky / sin(kx);
	double tmp;
	if (sin(ky) <= -4e-28) {
		tmp = 1.0 / fabs(fma(th, 0.16666666666666666, (1.0 / th)));
	} else if (sin(ky) <= -2e-301) {
		tmp = t_1 * (-1.0 / (-1.0 / sin(th)));
	} else if (sin(ky) <= 5e-26) {
		tmp = sin(th) * fabs(t_1);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(ky / sin(kx))
	tmp = 0.0
	if (sin(ky) <= -4e-28)
		tmp = Float64(1.0 / abs(fma(th, 0.16666666666666666, Float64(1.0 / th))));
	elseif (sin(ky) <= -2e-301)
		tmp = Float64(t_1 * Float64(-1.0 / Float64(-1.0 / sin(th))));
	elseif (sin(ky) <= 5e-26)
		tmp = Float64(sin(th) * abs(t_1));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sin[ky], $MachinePrecision], -4e-28], N[(1.0 / N[Abs[N[(th * 0.16666666666666666 + N[(1.0 / th), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-301], N[(t$95$1 * N[(-1.0 / N[(-1.0 / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-26], N[(N[Sin[th], $MachinePrecision] * N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-26}:\\
\;\;\;\;\sin th \cdot \left|t_1\right|\\

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th} \cdot \sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th}}} \]
      2. sqrt-unprod10.0%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right) \cdot \left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}}} \]
      3. pow210.0%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}^{2}}}} \]
      4. +-commutative10.0%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(0.16666666666666666 \cdot th + \frac{1}{th}\right)}}^{2}}} \]
      5. *-commutative10.0%

        \[\leadsto \frac{1}{\sqrt{{\left(\color{blue}{th \cdot 0.16666666666666666} + \frac{1}{th}\right)}^{2}}} \]
      6. fma-def10.0%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}}^{2}}} \]
    11. Applied egg-rr10.0%

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}^{2}}}} \]
    12. Step-by-step derivation
      1. unpow210.0%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right) \cdot \mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)}}} \]
      2. rem-sqrt-square20.6%

        \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]
    13. Simplified20.6%

      \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]

    if -3.99999999999999988e-28 < (sin.f64 ky) < -2.00000000000000013e-301

    1. Initial program 90.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left|\frac{ky}{\sin kx}\right|}}{\frac{1}{\sin th}} \]
    10. Simplified19.2%

      \[\leadsto \frac{\color{blue}{\left|\frac{ky}{\sin kx}\right|}}{\frac{1}{\sin th}} \]
    11. Step-by-step derivation
      1. frac-2neg19.2%

        \[\leadsto \color{blue}{\frac{-\left|\frac{ky}{\sin kx}\right|}{-\frac{1}{\sin th}}} \]
      2. div-inv19.2%

        \[\leadsto \color{blue}{\left(-\left|\frac{ky}{\sin kx}\right|\right) \cdot \frac{1}{-\frac{1}{\sin th}}} \]
      3. add-sqr-sqrt9.5%

        \[\leadsto \left(-\left|\color{blue}{\sqrt{\frac{ky}{\sin kx}} \cdot \sqrt{\frac{ky}{\sin kx}}}\right|\right) \cdot \frac{1}{-\frac{1}{\sin th}} \]
      4. fabs-sqr9.5%

        \[\leadsto \left(-\color{blue}{\sqrt{\frac{ky}{\sin kx}} \cdot \sqrt{\frac{ky}{\sin kx}}}\right) \cdot \frac{1}{-\frac{1}{\sin th}} \]
      5. add-sqr-sqrt40.9%

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

        \[\leadsto \color{blue}{\frac{-ky}{\sin kx}} \cdot \frac{1}{-\frac{1}{\sin th}} \]
      7. distribute-neg-frac40.9%

        \[\leadsto \frac{-ky}{\sin kx} \cdot \frac{1}{\color{blue}{\frac{-1}{\sin th}}} \]
      8. metadata-eval40.9%

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

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

    if -2.00000000000000013e-301 < (sin.f64 ky) < 5.00000000000000019e-26

    1. Initial program 98.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\left|\frac{ky}{\sin kx}\right|}}{\frac{1}{\sin th}} \]
    10. Simplified80.0%

      \[\leadsto \frac{\color{blue}{\left|\frac{ky}{\sin kx}\right|}}{\frac{1}{\sin th}} \]
    11. Taylor expanded in ky around 0 80.1%

      \[\leadsto \color{blue}{\left|\frac{ky}{\sin kx}\right| \cdot \sin th} \]
    12. Step-by-step derivation
      1. *-commutative80.1%

        \[\leadsto \color{blue}{\sin th \cdot \left|\frac{ky}{\sin kx}\right|} \]
    13. Simplified80.1%

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

    if 5.00000000000000019e-26 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 59.8%

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

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

Alternative 3: 68.3% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.03:\\
\;\;\;\;\frac{1}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}\\

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th} \cdot \sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th}}} \]
      2. sqrt-unprod10.4%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right) \cdot \left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}}} \]
      3. pow210.4%

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

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(0.16666666666666666 \cdot th + \frac{1}{th}\right)}}^{2}}} \]
      5. *-commutative10.4%

        \[\leadsto \frac{1}{\sqrt{{\left(\color{blue}{th \cdot 0.16666666666666666} + \frac{1}{th}\right)}^{2}}} \]
      6. fma-def10.4%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}}^{2}}} \]
    11. Applied egg-rr10.4%

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}^{2}}}} \]
    12. Step-by-step derivation
      1. unpow210.4%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right) \cdot \mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)}}} \]
      2. rem-sqrt-square20.2%

        \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]
    13. Simplified20.2%

      \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]

    if -0.029999999999999999 < (sin.f64 ky) < 9.9999999999999998e-13

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999998e-13 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 60.1%

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

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

Alternative 4: 68.3% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.03:\\
\;\;\;\;\frac{1}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}\\

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th} \cdot \sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th}}} \]
      2. sqrt-unprod10.4%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right) \cdot \left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}}} \]
      3. pow210.4%

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

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(0.16666666666666666 \cdot th + \frac{1}{th}\right)}}^{2}}} \]
      5. *-commutative10.4%

        \[\leadsto \frac{1}{\sqrt{{\left(\color{blue}{th \cdot 0.16666666666666666} + \frac{1}{th}\right)}^{2}}} \]
      6. fma-def10.4%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}}^{2}}} \]
    11. Applied egg-rr10.4%

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}^{2}}}} \]
    12. Step-by-step derivation
      1. unpow210.4%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right) \cdot \mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)}}} \]
      2. rem-sqrt-square20.2%

        \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]
    13. Simplified20.2%

      \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]

    if -0.029999999999999999 < (sin.f64 ky) < 9.9999999999999998e-13

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999998e-13 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 60.1%

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

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

Alternative 5: 76.6% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.029999999999999999 < (sin.f64 ky) < 9.9999999999999998e-13

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999998e-13 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 60.1%

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

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

Alternative 6: 76.8% accurate, 1.2× speedup?

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.029999999999999999 < (sin.f64 ky) < 9.9999999999999998e-13

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999998e-13 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 60.1%

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

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

Alternative 7: 43.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -4 \cdot 10^{-28}:\\ \;\;\;\;\frac{1}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-26}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -4e-28)
   (/ 1.0 (fabs (fma th 0.16666666666666666 (/ 1.0 th))))
   (if (<= (sin ky) 5e-26) (* (sin th) (/ ky (sin kx))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -4e-28) {
		tmp = 1.0 / fabs(fma(th, 0.16666666666666666, (1.0 / th)));
	} else if (sin(ky) <= 5e-26) {
		tmp = sin(th) * (ky / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -4e-28)
		tmp = Float64(1.0 / abs(fma(th, 0.16666666666666666, Float64(1.0 / th))));
	elseif (sin(ky) <= 5e-26)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -4e-28], N[(1.0 / N[Abs[N[(th * 0.16666666666666666 + N[(1.0 / th), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 5e-26], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -4 \cdot 10^{-28}:\\
\;\;\;\;\frac{1}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}\\

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
    10. Step-by-step derivation
      1. add-sqr-sqrt1.8%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th} \cdot \sqrt{\frac{1}{th} + 0.16666666666666666 \cdot th}}} \]
      2. sqrt-unprod10.0%

        \[\leadsto \frac{1}{\color{blue}{\sqrt{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right) \cdot \left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}}} \]
      3. pow210.0%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{{\left(\frac{1}{th} + 0.16666666666666666 \cdot th\right)}^{2}}}} \]
      4. +-commutative10.0%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(0.16666666666666666 \cdot th + \frac{1}{th}\right)}}^{2}}} \]
      5. *-commutative10.0%

        \[\leadsto \frac{1}{\sqrt{{\left(\color{blue}{th \cdot 0.16666666666666666} + \frac{1}{th}\right)}^{2}}} \]
      6. fma-def10.0%

        \[\leadsto \frac{1}{\sqrt{{\color{blue}{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}}^{2}}} \]
    11. Applied egg-rr10.0%

      \[\leadsto \frac{1}{\color{blue}{\sqrt{{\left(\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right)}^{2}}}} \]
    12. Step-by-step derivation
      1. unpow210.0%

        \[\leadsto \frac{1}{\sqrt{\color{blue}{\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right) \cdot \mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)}}} \]
      2. rem-sqrt-square20.6%

        \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]
    13. Simplified20.6%

      \[\leadsto \frac{1}{\color{blue}{\left|\mathsf{fma}\left(th, 0.16666666666666666, \frac{1}{th}\right)\right|}} \]

    if -3.99999999999999988e-28 < (sin.f64 ky) < 5.00000000000000019e-26

    1. Initial program 94.0%

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

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

    if 5.00000000000000019e-26 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 59.8%

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

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

Alternative 8: 34.9% accurate, 2.3× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin ky \cdot \frac{th}{\sin kx}} \]
    10. Simplified9.7%

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

    if -2e-52 < (sin.f64 ky) < 9.9999999999999995e-144

    1. Initial program 91.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-144 < (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 54.3%

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

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

Alternative 9: 34.1% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1 \cdot \sin ky}{\color{blue}{\sin kx \cdot \frac{1}{\sin th}}} \]
      3. times-frac31.6%

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

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

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

        \[\leadsto \frac{\color{blue}{\sin ky \cdot \sin th}}{kx} \]
      2. *-lft-identity21.0%

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

        \[\leadsto \color{blue}{\frac{\sin ky}{1} \cdot \frac{\sin th}{kx}} \]
      4. /-rgt-identity21.8%

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

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

    if 9.9999999999999995e-144 < (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 54.3%

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

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

Alternative 10: 39.8% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq 5 \cdot 10^{-26}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) 5e-26) (* (sin th) (/ ky (sin kx))) (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= 5e-26) {
		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) <= 5d-26) 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) <= 5e-26) {
		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) <= 5e-26:
		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) <= 5e-26)
		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) <= 5e-26)
		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], 5e-26], 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 5 \cdot 10^{-26}:\\
\;\;\;\;\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) < 5.00000000000000019e-26

    1. Initial program 95.9%

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

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

    if 5.00000000000000019e-26 < (sin.f64 ky)

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. +-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 kx around 0 59.8%

      \[\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 5 \cdot 10^{-26}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 33.9% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-144 < (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 54.3%

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

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

Alternative 12: 33.0% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-144 < (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 54.3%

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

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

Alternative 13: 33.9% accurate, 3.4× speedup?

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

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.9999999999999995e-144 < (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 54.3%

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

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

Alternative 14: 24.1% accurate, 7.0× speedup?

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

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

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

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

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

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

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

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

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

    \[\leadsto \sin th \]

Alternative 15: 14.5% accurate, 78.8× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 16: 13.8% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
  10. Taylor expanded in th around 0 13.6%

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

    \[\leadsto th \]

Reproduce

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