Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.6% → 99.6%
Time: 14.2s
Alternatives: 12
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 12 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.6% 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.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 46.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.16:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-148}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-117} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-64}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.16)
   (* (sin ky) (fabs (/ (sin th) (sin ky))))
   (if (<= (sin ky) 2e-148)
     (* (sin th) (/ (sin ky) (sin kx)))
     (if (or (<= (sin ky) 2e-117) (not (<= (sin ky) 5e-64)))
       (sin th)
       (* ky (/ (sin th) (sin kx)))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.16) {
		tmp = sin(ky) * fabs((sin(th) / sin(ky)));
	} else if (sin(ky) <= 2e-148) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if ((sin(ky) <= 2e-117) || !(sin(ky) <= 5e-64)) {
		tmp = sin(th);
	} else {
		tmp = ky * (sin(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 (sin(ky) <= (-0.16d0)) then
        tmp = sin(ky) * abs((sin(th) / sin(ky)))
    else if (sin(ky) <= 2d-148) then
        tmp = sin(th) * (sin(ky) / sin(kx))
    else if ((sin(ky) <= 2d-117) .or. (.not. (sin(ky) <= 5d-64))) then
        tmp = sin(th)
    else
        tmp = ky * (sin(th) / sin(kx))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.16) {
		tmp = Math.sin(ky) * Math.abs((Math.sin(th) / Math.sin(ky)));
	} else if (Math.sin(ky) <= 2e-148) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	} else if ((Math.sin(ky) <= 2e-117) || !(Math.sin(ky) <= 5e-64)) {
		tmp = Math.sin(th);
	} else {
		tmp = ky * (Math.sin(th) / Math.sin(kx));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -0.16:
		tmp = math.sin(ky) * math.fabs((math.sin(th) / math.sin(ky)))
	elif math.sin(ky) <= 2e-148:
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	elif (math.sin(ky) <= 2e-117) or not (math.sin(ky) <= 5e-64):
		tmp = math.sin(th)
	else:
		tmp = ky * (math.sin(th) / math.sin(kx))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.16)
		tmp = Float64(sin(ky) * abs(Float64(sin(th) / sin(ky))));
	elseif (sin(ky) <= 2e-148)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif ((sin(ky) <= 2e-117) || !(sin(ky) <= 5e-64))
		tmp = sin(th);
	else
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -0.16)
		tmp = sin(ky) * abs((sin(th) / sin(ky)));
	elseif (sin(ky) <= 2e-148)
		tmp = sin(th) * (sin(ky) / sin(kx));
	elseif ((sin(ky) <= 2e-117) || ~((sin(ky) <= 5e-64)))
		tmp = sin(th);
	else
		tmp = ky * (sin(th) / sin(kx));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.16], N[(N[Sin[ky], $MachinePrecision] * N[Abs[N[(N[Sin[th], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 2e-148], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[N[Sin[ky], $MachinePrecision], 2e-117], N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 5e-64]], $MachinePrecision]], N[Sin[th], $MachinePrecision], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-117} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-64}\right):\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \color{blue}{\left|\frac{\sin th}{\sin ky}\right|} \]
    9. Simplified34.0%

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

    if -0.160000000000000003 < (sin.f64 ky) < 1.99999999999999987e-148

    1. Initial program 87.3%

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

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

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

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

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

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

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

    if 1.99999999999999987e-148 < (sin.f64 ky) < 2.00000000000000006e-117 or 5.00000000000000033e-64 < (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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000006e-117 < (sin.f64 ky) < 5.00000000000000033e-64

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.16:\\ \;\;\;\;\sin ky \cdot \left|\frac{\sin th}{\sin ky}\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-148}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-117} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-64}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 67.9% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 58.7% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 0.900000000000000022

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.900000000000000022 < 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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 31.5% accurate, 2.3× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 2.2 \cdot 10^{-68}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.20000000000000002e-68 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.2 \cdot 10^{-68}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 32.4% accurate, 3.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{if}\;ky \leq 5.8 \cdot 10^{-148}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;ky \leq 1.5 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 5.5 \cdot 10^{-64}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+37}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* ky (/ (sin th) (sin kx)))))
   (if (<= ky 5.8e-148)
     t_1
     (if (<= ky 1.5e-117)
       (sin th)
       (if (<= ky 5.5e-64)
         t_1
         (if (<= ky 2.1e+37) (sin th) (fabs (sin th))))))))
double code(double kx, double ky, double th) {
	double t_1 = ky * (sin(th) / sin(kx));
	double tmp;
	if (ky <= 5.8e-148) {
		tmp = t_1;
	} else if (ky <= 1.5e-117) {
		tmp = sin(th);
	} else if (ky <= 5.5e-64) {
		tmp = t_1;
	} else if (ky <= 2.1e+37) {
		tmp = sin(th);
	} else {
		tmp = fabs(sin(th));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = ky * (sin(th) / sin(kx))
    if (ky <= 5.8d-148) then
        tmp = t_1
    else if (ky <= 1.5d-117) then
        tmp = sin(th)
    else if (ky <= 5.5d-64) then
        tmp = t_1
    else if (ky <= 2.1d+37) then
        tmp = sin(th)
    else
        tmp = abs(sin(th))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = ky * (Math.sin(th) / Math.sin(kx));
	double tmp;
	if (ky <= 5.8e-148) {
		tmp = t_1;
	} else if (ky <= 1.5e-117) {
		tmp = Math.sin(th);
	} else if (ky <= 5.5e-64) {
		tmp = t_1;
	} else if (ky <= 2.1e+37) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.abs(Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = ky * (math.sin(th) / math.sin(kx))
	tmp = 0
	if ky <= 5.8e-148:
		tmp = t_1
	elif ky <= 1.5e-117:
		tmp = math.sin(th)
	elif ky <= 5.5e-64:
		tmp = t_1
	elif ky <= 2.1e+37:
		tmp = math.sin(th)
	else:
		tmp = math.fabs(math.sin(th))
	return tmp
function code(kx, ky, th)
	t_1 = Float64(ky * Float64(sin(th) / sin(kx)))
	tmp = 0.0
	if (ky <= 5.8e-148)
		tmp = t_1;
	elseif (ky <= 1.5e-117)
		tmp = sin(th);
	elseif (ky <= 5.5e-64)
		tmp = t_1;
	elseif (ky <= 2.1e+37)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = ky * (sin(th) / sin(kx));
	tmp = 0.0;
	if (ky <= 5.8e-148)
		tmp = t_1;
	elseif (ky <= 1.5e-117)
		tmp = sin(th);
	elseif (ky <= 5.5e-64)
		tmp = t_1;
	elseif (ky <= 2.1e+37)
		tmp = sin(th);
	else
		tmp = abs(sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[ky, 5.8e-148], t$95$1, If[LessEqual[ky, 1.5e-117], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 5.5e-64], t$95$1, If[LessEqual[ky, 2.1e+37], N[Sin[th], $MachinePrecision], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := ky \cdot \frac{\sin th}{\sin kx}\\
\mathbf{if}\;ky \leq 5.8 \cdot 10^{-148}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;ky \leq 1.5 \cdot 10^{-117}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 5.5 \cdot 10^{-64}:\\
\;\;\;\;t\_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.7999999999999997e-148 or 1.49999999999999996e-117 < ky < 5.4999999999999999e-64

    1. Initial program 92.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.7999999999999997e-148 < ky < 1.49999999999999996e-117 or 5.4999999999999999e-64 < ky < 2.1000000000000001e37

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1000000000000001e37 < 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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky \cdot 1}}\right| \]
      5. times-frac22.4%

        \[\leadsto \left|\color{blue}{\frac{\sin ky}{\sin ky} \cdot \frac{\sin th}{1}}\right| \]
      6. *-inverses22.4%

        \[\leadsto \left|\color{blue}{1} \cdot \frac{\sin th}{1}\right| \]
      7. /-rgt-identity22.4%

        \[\leadsto \left|1 \cdot \color{blue}{\sin th}\right| \]
      8. *-lft-identity22.4%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    9. Simplified22.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 5.8 \cdot 10^{-148}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;ky \leq 1.5 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 5.5 \cdot 10^{-64}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+37}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 32.4% accurate, 3.2× speedup?

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

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

\mathbf{elif}\;ky \leq 1.42 \cdot 10^{-117}:\\
\;\;\;\;\sin th\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < 5.5000000000000003e-148

    1. Initial program 91.7%

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

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

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

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

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

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

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

    if 5.5000000000000003e-148 < ky < 1.42000000000000001e-117 or 4.6999999999999998e-64 < ky < 2.1000000000000001e37

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.42000000000000001e-117 < ky < 4.6999999999999998e-64

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1000000000000001e37 < 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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky \cdot 1}}\right| \]
      5. times-frac22.4%

        \[\leadsto \left|\color{blue}{\frac{\sin ky}{\sin ky} \cdot \frac{\sin th}{1}}\right| \]
      6. *-inverses22.4%

        \[\leadsto \left|\color{blue}{1} \cdot \frac{\sin th}{1}\right| \]
      7. /-rgt-identity22.4%

        \[\leadsto \left|1 \cdot \color{blue}{\sin th}\right| \]
      8. *-lft-identity22.4%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    9. Simplified22.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 5.5 \cdot 10^{-148}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{elif}\;ky \leq 1.42 \cdot 10^{-117}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.7 \cdot 10^{-64}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+37}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 25.9% accurate, 3.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 4.4 \cdot 10^{-98}:\\
\;\;\;\;\left(\sin th + 1\right) + -1\\

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

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


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

    1. Initial program 92.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u21.4%

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

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

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define21.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/31.1%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. *-rgt-identity31.1%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky \cdot 1}}\right)\right) \]
      4. times-frac21.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \frac{\sin th}{1}}\right)\right) \]
      5. *-inverses21.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{\sin th}{1}\right)\right) \]
      6. /-rgt-identity21.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(1 \cdot \color{blue}{\sin th}\right)\right) \]
      7. *-lft-identity21.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified21.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine26.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine26.3%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log26.3%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative26.3%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr26.3%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]

    if 4.39999999999999993e-98 < ky < 2.1000000000000001e37

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.1000000000000001e37 < 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. unpow299.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left|\frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky \cdot 1}}\right| \]
      5. times-frac22.4%

        \[\leadsto \left|\color{blue}{\frac{\sin ky}{\sin ky} \cdot \frac{\sin th}{1}}\right| \]
      6. *-inverses22.4%

        \[\leadsto \left|\color{blue}{1} \cdot \frac{\sin th}{1}\right| \]
      7. /-rgt-identity22.4%

        \[\leadsto \left|1 \cdot \color{blue}{\sin th}\right| \]
      8. *-lft-identity22.4%

        \[\leadsto \left|\color{blue}{\sin th}\right| \]
    9. Simplified22.4%

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 4.4 \cdot 10^{-98}:\\ \;\;\;\;\left(\sin th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 2.1 \cdot 10^{+37}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 25.7% accurate, 6.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 2.5 \cdot 10^{-67}:\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;\left(\sin th + 1\right) + -1\\


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

    1. Initial program 92.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.4999999999999999e-67 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u10.0%

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/19.9%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. *-rgt-identity19.9%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\sin ky \cdot \sin th}{\color{blue}{\sin ky \cdot 1}}\right)\right) \]
      4. times-frac10.0%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \frac{\sin th}{1}}\right)\right) \]
      5. *-inverses10.0%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{\sin th}{1}\right)\right) \]
      6. /-rgt-identity10.0%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(1 \cdot \color{blue}{\sin th}\right)\right) \]
      7. *-lft-identity10.0%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified10.0%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine18.7%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine18.7%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log18.7%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative18.7%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr18.7%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification25.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;kx \leq 2.5 \cdot 10^{-67}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left(\sin th + 1\right) + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 21.7% accurate, 6.5× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 5.99999999999999972e-208

    1. Initial program 94.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{th \cdot \left(1 + {th}^{2} \cdot \left({th}^{2} \cdot \left(0.008333333333333333 + -0.0001984126984126984 \cdot {th}^{2}\right) - 0.16666666666666666\right)\right)} \]
    7. Taylor expanded in th around inf 15.1%

      \[\leadsto \color{blue}{-0.0001984126984126984 \cdot {th}^{7}} \]

    if 5.99999999999999972e-208 < ky

    1. Initial program 95.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 6 \cdot 10^{-208}:\\ \;\;\;\;-0.0001984126984126984 \cdot {th}^{7}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 23.4% accurate, 7.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\sin th} \]
  6. Final simplification23.3%

    \[\leadsto \sin th \]
  7. Add Preprocessing

Alternative 12: 13.3% 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.9%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto th \]
  8. Add Preprocessing

Reproduce

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