Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.7% → 99.6%
Time: 23.1s
Alternatives: 17
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 17 alternatives:

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

Initial Program: 93.7% accurate, 1.0× speedup?

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

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

Alternative 1: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 54.4% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -5 \cdot 10^{-52}:\\
\;\;\;\;\sin ky \cdot \left(th \cdot \left|\frac{1}{\sin ky}\right|\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -5e-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-*l/96.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt0.0%

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

        \[\leadsto \left(\color{blue}{\sqrt{\frac{1}{\sin ky} \cdot \frac{1}{\sin ky}}} \cdot th\right) \cdot \sin ky \]
      3. inv-pow31.2%

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

        \[\leadsto \left(\sqrt{{\sin ky}^{-1} \cdot \color{blue}{{\sin ky}^{-1}}} \cdot th\right) \cdot \sin ky \]
      5. pow-prod-up31.2%

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

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

      \[\leadsto \left(\color{blue}{\sqrt{{\sin ky}^{-2}}} \cdot th\right) \cdot \sin ky \]
    10. Step-by-step derivation
      1. metadata-eval31.2%

        \[\leadsto \left(\sqrt{{\sin ky}^{\color{blue}{\left(2 \cdot -1\right)}}} \cdot th\right) \cdot \sin ky \]
      2. pow-sqr31.2%

        \[\leadsto \left(\sqrt{\color{blue}{{\sin ky}^{-1} \cdot {\sin ky}^{-1}}} \cdot th\right) \cdot \sin ky \]
      3. unpow-131.2%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{1}{\sin ky}} \cdot {\sin ky}^{-1}} \cdot th\right) \cdot \sin ky \]
      4. unpow-131.2%

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

        \[\leadsto \left(\color{blue}{\left|\frac{1}{\sin ky}\right|} \cdot th\right) \cdot \sin ky \]
    11. Simplified31.2%

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

    if -5e-52 < (sin.f64 ky) < 2.00000000000000013e-301

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{1 \cdot \sin kx}} \]
      2. times-frac64.7%

        \[\leadsto \color{blue}{\frac{ky}{1} \cdot \frac{\sin th}{\sin kx}} \]
      3. /-rgt-identity64.7%

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

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

    if 2.00000000000000013e-301 < (sin.f64 ky) < 4.0000000000000001e-8

    1. Initial program 93.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    6. Simplified73.2%

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

    if 4.0000000000000001e-8 < (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 63.3%

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

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

Alternative 3: 50.8% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt1.2%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin ky \cdot \frac{th}{\sin ky}\right|} \]
    11. Simplified23.2%

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

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

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000013e-301 < (sin.f64 ky) < 4.0000000000000001e-8

    1. Initial program 93.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    6. Simplified73.2%

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

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

    if 4.0000000000000001e-8 < (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 63.3%

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

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

Alternative 4: 50.6% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt1.2%

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\left(\frac{1}{\sin ky} \cdot th\right) \cdot \sin ky\right)}^{2}}} \]
      4. *-commutative17.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin ky \cdot \frac{th}{\sin ky}\right|} \]
    11. Simplified24.1%

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

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

    1. Initial program 87.9%

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

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

    if -1.00000000000000004e-297 < (sin.f64 ky) < 4.0000000000000001e-8

    1. Initial program 90.9%

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

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

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

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

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

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

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

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

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

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

    if 4.0000000000000001e-8 < (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 63.3%

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

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

Alternative 5: 50.7% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt1.2%

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\left(\frac{1}{\sin ky} \cdot th\right) \cdot \sin ky\right)}^{2}}} \]
      4. *-commutative17.9%

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin ky \cdot \frac{th}{\sin ky}\right|} \]
    11. Simplified24.1%

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

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

    1. Initial program 86.7%

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000013e-301 < (sin.f64 ky) < 4.0000000000000001e-8

    1. Initial program 93.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    6. Simplified73.2%

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

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

    if 4.0000000000000001e-8 < (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 63.3%

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

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

Alternative 6: 54.4% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -5 \cdot 10^{-52}:\\
\;\;\;\;\sin ky \cdot \left(th \cdot \left|\frac{1}{\sin ky}\right|\right)\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (sin.f64 ky) < -5e-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-*l/96.1%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt0.0%

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

        \[\leadsto \left(\color{blue}{\sqrt{\frac{1}{\sin ky} \cdot \frac{1}{\sin ky}}} \cdot th\right) \cdot \sin ky \]
      3. inv-pow31.2%

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

        \[\leadsto \left(\sqrt{{\sin ky}^{-1} \cdot \color{blue}{{\sin ky}^{-1}}} \cdot th\right) \cdot \sin ky \]
      5. pow-prod-up31.2%

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

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

      \[\leadsto \left(\color{blue}{\sqrt{{\sin ky}^{-2}}} \cdot th\right) \cdot \sin ky \]
    10. Step-by-step derivation
      1. metadata-eval31.2%

        \[\leadsto \left(\sqrt{{\sin ky}^{\color{blue}{\left(2 \cdot -1\right)}}} \cdot th\right) \cdot \sin ky \]
      2. pow-sqr31.2%

        \[\leadsto \left(\sqrt{\color{blue}{{\sin ky}^{-1} \cdot {\sin ky}^{-1}}} \cdot th\right) \cdot \sin ky \]
      3. unpow-131.2%

        \[\leadsto \left(\sqrt{\color{blue}{\frac{1}{\sin ky}} \cdot {\sin ky}^{-1}} \cdot th\right) \cdot \sin ky \]
      4. unpow-131.2%

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

        \[\leadsto \left(\color{blue}{\left|\frac{1}{\sin ky}\right|} \cdot th\right) \cdot \sin ky \]
    11. Simplified31.2%

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

    if -5e-52 < (sin.f64 ky) < 2.00000000000000013e-301

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{ky \cdot \sin th}{\color{blue}{1 \cdot \sin kx}} \]
      2. times-frac64.7%

        \[\leadsto \color{blue}{\frac{ky}{1} \cdot \frac{\sin th}{\sin kx}} \]
      3. /-rgt-identity64.7%

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

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

    if 2.00000000000000013e-301 < (sin.f64 ky) < 4.0000000000000001e-8

    1. Initial program 93.1%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    6. Simplified73.2%

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

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

    if 4.0000000000000001e-8 < (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 63.3%

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

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

Alternative 7: 66.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 th) < 1.0000000000000001e-15

    1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 th)

    1. Initial program 95.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}}} \]
    4. Applied egg-rr23.0%

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

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

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

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

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

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

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

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

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

Alternative 8: 66.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 th) < 1.0000000000000001e-15

    1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\left(\sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}} \cdot th\right) \cdot \sin ky}\right)} \]
      2. *-commutative25.4%

        \[\leadsto \log \left(e^{\color{blue}{\sin ky \cdot \left(\sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}} \cdot th\right)}}\right) \]
      3. exp-prod25.4%

        \[\leadsto \log \color{blue}{\left({\left(e^{\sin ky}\right)}^{\left(\sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}} \cdot th\right)}\right)} \]
      4. *-commutative25.4%

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

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

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

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

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

        \[\leadsto \log \left({\left(e^{\sin ky}\right)}^{\left(th \cdot \frac{1}{\sqrt{\sin kx \cdot \sin kx + \color{blue}{\sin ky \cdot \sin ky}}}\right)}\right) \]
      10. hypot-udef25.4%

        \[\leadsto \log \left({\left(e^{\sin ky}\right)}^{\left(th \cdot \frac{1}{\color{blue}{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}\right)}\right) \]
      11. un-div-inv25.4%

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

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

        \[\leadsto \color{blue}{\frac{th}{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \log \left(e^{\sin ky}\right)} \]
      2. hypot-def68.5%

        \[\leadsto \frac{th}{\color{blue}{\sqrt{\sin kx \cdot \sin kx + \sin ky \cdot \sin ky}}} \cdot \log \left(e^{\sin ky}\right) \]
      3. unpow268.5%

        \[\leadsto \frac{th}{\sqrt{\color{blue}{{\sin kx}^{2}} + \sin ky \cdot \sin ky}} \cdot \log \left(e^{\sin ky}\right) \]
      4. unpow268.5%

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

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

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

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

        \[\leadsto \frac{th}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \log \left(e^{\sin ky}\right) \]
      9. rem-log-exp99.7%

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

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

    if 1.0000000000000001e-15 < (sin.f64 th)

    1. Initial program 95.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}}} \]
    4. Applied egg-rr23.0%

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

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

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

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

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

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

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

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

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

Alternative 9: 66.4% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

    if -2e-3 < (sin.f64 th) < 1.0000000000000001e-15

    1. Initial program 96.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.0000000000000001e-15 < (sin.f64 th)

    1. Initial program 95.0%

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\sin kx}{\sin th}}} \]
    4. Applied egg-rr23.0%

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

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

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

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

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

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

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

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

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

Alternative 10: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 11: 44.4% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(\color{blue}{\frac{1}{\sin ky}} \cdot th\right) \cdot \sin ky \]
    8. Step-by-step derivation
      1. add-sqr-sqrt1.2%

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\sin ky \cdot \frac{th}{\sin ky}\right|} \]
    11. Simplified23.2%

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

    if -0.0189999999999999995 < (sin.f64 ky) < 1.99999999999999996e-149

    1. Initial program 86.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999996e-149 < (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 57.7%

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

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

Alternative 12: 40.7% accurate, 2.3× speedup?

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

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

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


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

    1. Initial program 91.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999996e-149 < (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 57.7%

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

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

Alternative 13: 32.9% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -0.018 \lor \neg \left(ky \leq 3.7 \cdot 10^{-149}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.0179999999999999986 or 3.6999999999999999e-149 < 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 34.7%

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

    if -0.0179999999999999986 < ky < 3.6999999999999999e-149

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    12. Simplified39.6%

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

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

Alternative 14: 33.0% accurate, 6.5× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -0.018 \lor \neg \left(ky \leq 5.6 \cdot 10^{-149}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.0179999999999999986 or 5.5999999999999997e-149 < 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 34.7%

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

    if -0.0179999999999999986 < ky < 5.5999999999999997e-149

    1. Initial program 85.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 15: 31.1% accurate, 6.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -1.56 \cdot 10^{-19} \lor \neg \left(ky \leq 2.1 \cdot 10^{-149}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -1.56000000000000003e-19 or 2.10000000000000011e-149 < 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 34.3%

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

    if -1.56000000000000003e-19 < ky < 2.10000000000000011e-149

    1. Initial program 85.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -1.56 \cdot 10^{-19} \lor \neg \left(ky \leq 2.1 \cdot 10^{-149}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \end{array} \]

Alternative 16: 21.8% accurate, 77.7× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -7.00000000000000007e-20 or 9.50000000000000028e-89 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -7.00000000000000007e-20 < ky < 9.50000000000000028e-89

    1. Initial program 86.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -7 \cdot 10^{-20}:\\ \;\;\;\;th\\ \mathbf{elif}\;ky \leq 9.5 \cdot 10^{-89}:\\ \;\;\;\;th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;th\\ \end{array} \]

Alternative 17: 13.4% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]

Reproduce

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