Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.9% → 99.7%
Time: 22.9s
Alternatives: 23
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 23 alternatives:

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

Initial Program: 93.9% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 46.4% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179} \lor \neg \left(\sin ky \leq 4 \cdot 10^{-156}\right) \land \left(\sin ky \leq 5 \cdot 10^{-61} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-48}\right) \land \sin ky \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -2e-49)
   (fabs (sin th))
   (if (or (<= (sin ky) 2e-179)
           (and (not (<= (sin ky) 4e-156))
                (or (<= (sin ky) 5e-61)
                    (and (not (<= (sin ky) 5e-48)) (<= (sin ky) 2e-10)))))
     (* (sin th) (/ ky (sin kx)))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -2e-49) {
		tmp = fabs(sin(th));
	} else if ((sin(ky) <= 2e-179) || (!(sin(ky) <= 4e-156) && ((sin(ky) <= 5e-61) || (!(sin(ky) <= 5e-48) && (sin(ky) <= 2e-10))))) {
		tmp = sin(th) * (ky / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(ky) <= (-2d-49)) then
        tmp = abs(sin(th))
    else if ((sin(ky) <= 2d-179) .or. (.not. (sin(ky) <= 4d-156)) .and. (sin(ky) <= 5d-61) .or. (.not. (sin(ky) <= 5d-48)) .and. (sin(ky) <= 2d-10)) then
        tmp = sin(th) * (ky / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -2e-49) {
		tmp = Math.abs(Math.sin(th));
	} else if ((Math.sin(ky) <= 2e-179) || (!(Math.sin(ky) <= 4e-156) && ((Math.sin(ky) <= 5e-61) || (!(Math.sin(ky) <= 5e-48) && (Math.sin(ky) <= 2e-10))))) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(ky) <= -2e-49:
		tmp = math.fabs(math.sin(th))
	elif (math.sin(ky) <= 2e-179) or (not (math.sin(ky) <= 4e-156) and ((math.sin(ky) <= 5e-61) or (not (math.sin(ky) <= 5e-48) and (math.sin(ky) <= 2e-10)))):
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -2e-49)
		tmp = abs(sin(th));
	elseif ((sin(ky) <= 2e-179) || (!(sin(ky) <= 4e-156) && ((sin(ky) <= 5e-61) || (!(sin(ky) <= 5e-48) && (sin(ky) <= 2e-10)))))
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(ky) <= -2e-49)
		tmp = abs(sin(th));
	elseif ((sin(ky) <= 2e-179) || (~((sin(ky) <= 4e-156)) && ((sin(ky) <= 5e-61) || (~((sin(ky) <= 5e-48)) && (sin(ky) <= 2e-10)))))
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -2e-49], N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision], If[Or[LessEqual[N[Sin[ky], $MachinePrecision], 2e-179], And[N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 4e-156]], $MachinePrecision], Or[LessEqual[N[Sin[ky], $MachinePrecision], 5e-61], And[N[Not[LessEqual[N[Sin[ky], $MachinePrecision], 5e-48]], $MachinePrecision], LessEqual[N[Sin[ky], $MachinePrecision], 2e-10]]]]], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179} \lor \neg \left(\sin ky \leq 4 \cdot 10^{-156}\right) \land \left(\sin ky \leq 5 \cdot 10^{-61} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-48}\right) \land \sin ky \leq 2 \cdot 10^{-10}\right):\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod27.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow227.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr27.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow227.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified35.3%

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

    if -1.99999999999999987e-49 < (sin.f64 ky) < 2e-179 or 4.00000000000000016e-156 < (sin.f64 ky) < 4.9999999999999999e-61 or 4.9999999999999999e-48 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.0%

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

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

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

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

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

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

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

    if 2e-179 < (sin.f64 ky) < 4.00000000000000016e-156 or 4.9999999999999999e-61 < (sin.f64 ky) < 4.9999999999999999e-48 or 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 95.9%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179} \lor \neg \left(\sin ky \leq 4 \cdot 10^{-156}\right) \land \left(\sin ky \leq 5 \cdot 10^{-61} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-48}\right) \land \sin ky \leq 2 \cdot 10^{-10}\right):\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 3: 46.4% accurate, 0.9× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-156}:\\
\;\;\;\;\sin th\\

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod27.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow227.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr27.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow227.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified35.3%

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

    if -1.99999999999999987e-49 < (sin.f64 ky) < 2e-179 or 4.00000000000000016e-156 < (sin.f64 ky) < 4.9999999999999999e-61

    1. Initial program 85.9%

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

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

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

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

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

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

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

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

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

    if 2e-179 < (sin.f64 ky) < 4.00000000000000016e-156 or 4.9999999999999999e-61 < (sin.f64 ky) < 4.9999999999999999e-48 or 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 95.9%

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

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

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

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

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

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

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

    if 4.9999999999999999e-48 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 99.8%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-179}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-156}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-61}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;\sin ky \leq 5 \cdot 10^{-48}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin ky \leq 2 \cdot 10^{-10}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 4: 54.4% accurate, 1.0× speedup?

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

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

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow229.9%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr29.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow229.9%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square36.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified36.8%

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

    if -0.0050000000000000001 < (sin.f64 ky) < -3.99999999999999993e-170

    1. Initial program 98.8%

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

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

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

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

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

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

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

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

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

    if -3.99999999999999993e-170 < (sin.f64 ky) < 2.0000000000000001e-293

    1. Initial program 79.5%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-293 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 5: 54.7% accurate, 1.0× speedup?

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

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

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow229.9%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr29.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow229.9%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square36.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified36.8%

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

    if -0.0050000000000000001 < (sin.f64 ky) < -2.00000000000000002e-125

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

    if -2.00000000000000002e-125 < (sin.f64 ky) < 2.0000000000000001e-293

    1. Initial program 82.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-293 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 6: 52.5% accurate, 1.2× speedup?

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

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod27.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow227.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr27.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow227.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified35.3%

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

    if -1.99999999999999987e-49 < (sin.f64 ky) < -1.50000000000000001e-255

    1. Initial program 88.1%

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

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

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

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

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

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

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

    if -1.50000000000000001e-255 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 7: 53.4% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod27.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow227.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr27.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow227.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified35.3%

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

    if -1.99999999999999987e-49 < (sin.f64 ky) < 2.0000000000000001e-293

    1. Initial program 88.3%

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

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

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

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

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

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

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

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

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

    if 2.0000000000000001e-293 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 8: 52.5% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -2 \cdot 10^{-49}:\\
\;\;\;\;\left|\sin th\right|\\

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod27.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow227.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr27.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow227.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified35.3%

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

    if -1.99999999999999987e-49 < (sin.f64 ky) < -1.50000000000000001e-255

    1. Initial program 88.1%

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

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

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

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

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

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

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

    if -1.50000000000000001e-255 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 84.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 9: 72.9% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow229.9%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr29.9%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow229.9%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square36.8%

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified36.8%

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

    if -0.0050000000000000001 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.8%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 10: 78.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 11: 78.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 12: 78.0% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 13: 78.1% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}} \]
    8. Simplified47.6%

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

    if -1.00000000000000008e-5 < (sin.f64 ky) < 2.00000000000000007e-10

    1. Initial program 87.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.00000000000000007e-10 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

Alternative 14: 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.1%

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

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

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

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

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

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

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

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

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

Alternative 15: 28.5% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ \mathbf{if}\;th \leq -4 \cdot 10^{+189}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;th \leq -9.5 \cdot 10^{-126}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;th \leq -1.8 \cdot 10^{-204} \lor \neg \left(th \leq 2 \cdot 10^{+154}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{ky \cdot ky}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))))
   (if (<= th -4e+189)
     t_1
     (if (<= th -9.5e-126)
       (sin th)
       (if (or (<= th -1.8e-204) (not (<= th 2e+154)))
         t_1
         (/ (sin th) (+ 1.0 (/ (* 0.5 (* kx kx)) (* ky ky)))))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double tmp;
	if (th <= -4e+189) {
		tmp = t_1;
	} else if (th <= -9.5e-126) {
		tmp = sin(th);
	} else if ((th <= -1.8e-204) || !(th <= 2e+154)) {
		tmp = t_1;
	} else {
		tmp = sin(th) / (1.0 + ((0.5 * (kx * kx)) / (ky * ky)));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = abs(sin(th))
    if (th <= (-4d+189)) then
        tmp = t_1
    else if (th <= (-9.5d-126)) then
        tmp = sin(th)
    else if ((th <= (-1.8d-204)) .or. (.not. (th <= 2d+154))) then
        tmp = t_1
    else
        tmp = sin(th) / (1.0d0 + ((0.5d0 * (kx * kx)) / (ky * ky)))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.abs(Math.sin(th));
	double tmp;
	if (th <= -4e+189) {
		tmp = t_1;
	} else if (th <= -9.5e-126) {
		tmp = Math.sin(th);
	} else if ((th <= -1.8e-204) || !(th <= 2e+154)) {
		tmp = t_1;
	} else {
		tmp = Math.sin(th) / (1.0 + ((0.5 * (kx * kx)) / (ky * ky)));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	tmp = 0
	if th <= -4e+189:
		tmp = t_1
	elif th <= -9.5e-126:
		tmp = math.sin(th)
	elif (th <= -1.8e-204) or not (th <= 2e+154):
		tmp = t_1
	else:
		tmp = math.sin(th) / (1.0 + ((0.5 * (kx * kx)) / (ky * ky)))
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	tmp = 0.0
	if (th <= -4e+189)
		tmp = t_1;
	elseif (th <= -9.5e-126)
		tmp = sin(th);
	elseif ((th <= -1.8e-204) || !(th <= 2e+154))
		tmp = t_1;
	else
		tmp = Float64(sin(th) / Float64(1.0 + Float64(Float64(0.5 * Float64(kx * kx)) / Float64(ky * ky))));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	tmp = 0.0;
	if (th <= -4e+189)
		tmp = t_1;
	elseif (th <= -9.5e-126)
		tmp = sin(th);
	elseif ((th <= -1.8e-204) || ~((th <= 2e+154)))
		tmp = t_1;
	else
		tmp = sin(th) / (1.0 + ((0.5 * (kx * kx)) / (ky * ky)));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, If[LessEqual[th, -4e+189], t$95$1, If[LessEqual[th, -9.5e-126], N[Sin[th], $MachinePrecision], If[Or[LessEqual[th, -1.8e-204], N[Not[LessEqual[th, 2e+154]], $MachinePrecision]], t$95$1, N[(N[Sin[th], $MachinePrecision] / N[(1.0 + N[(N[(0.5 * N[(kx * kx), $MachinePrecision]), $MachinePrecision] / N[(ky * ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \left|\sin th\right|\\
\mathbf{if}\;th \leq -4 \cdot 10^{+189}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;th \leq -9.5 \cdot 10^{-126}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;th \leq -1.8 \cdot 10^{-204} \lor \neg \left(th \leq 2 \cdot 10^{+154}\right):\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < -4.0000000000000001e189 or -9.5000000000000003e-126 < th < -1.79999999999999982e-204 or 2.00000000000000007e154 < th

    1. Initial program 96.2%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt6.0%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod28.7%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow228.7%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    8. Applied egg-rr28.7%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    9. Step-by-step derivation
      1. unpow228.7%

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

        \[\leadsto \color{blue}{\left|\sin th\right|} \]
    10. Simplified34.8%

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

    if -4.0000000000000001e189 < th < -9.5000000000000003e-126

    1. Initial program 89.5%

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

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

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

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

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

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

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

    if -1.79999999999999982e-204 < th < 2.00000000000000007e154

    1. Initial program 95.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{\color{blue}{ky \cdot ky}}} \]
    13. Simplified31.4%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq -4 \cdot 10^{+189}:\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{elif}\;th \leq -9.5 \cdot 10^{-126}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;th \leq -1.8 \cdot 10^{-204} \lor \neg \left(th \leq 2 \cdot 10^{+154}\right):\\ \;\;\;\;\left|\sin th\right|\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{ky \cdot ky}}\\ \end{array} \]

Alternative 16: 29.0% accurate, 6.2× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.047 or 1.92000000000000002e-227 < ky

    1. Initial program 95.3%

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

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

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

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

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

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

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

    if -0.047 < ky < 1.92000000000000002e-227

    1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 17: 29.5% accurate, 6.2× speedup?

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

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

\mathbf{elif}\;ky \leq 2.3 \cdot 10^{-223}:\\
\;\;\;\;\frac{2}{kx} \cdot \frac{\sin th \cdot \left(ky \cdot ky\right)}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -0.00121999999999999995 or 2.3e-223 < ky

    1. Initial program 95.3%

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

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

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

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

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

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

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

    if -0.00121999999999999995 < ky < 2.3e-223

    1. Initial program 91.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -0.00122:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 2.3 \cdot 10^{-223}:\\ \;\;\;\;\frac{2}{kx} \cdot \frac{\sin th \cdot \left(ky \cdot ky\right)}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 18: 28.5% accurate, 6.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 4 \cdot 10^{-221}:\\
\;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{ky \cdot ky}}\\

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


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

    1. Initial program 95.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{\color{blue}{ky \cdot ky}}} \]
    13. Simplified25.7%

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

    if 4.00000000000000007e-221 < ky

    1. Initial program 92.1%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 4 \cdot 10^{-221}:\\ \;\;\;\;\frac{\sin th}{1 + \frac{0.5 \cdot \left(kx \cdot kx\right)}{ky \cdot ky}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 19: 29.0% accurate, 6.5× speedup?

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

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -4.9999999999999998e-24 or 1.15000000000000004e-193 < ky

    1. Initial program 96.9%

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

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

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

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

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

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

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

    if -4.9999999999999998e-24 < ky < 1.15000000000000004e-193

    1. Initial program 86.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -5 \cdot 10^{-24}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.15 \cdot 10^{-193}:\\ \;\;\;\;\frac{ky \cdot th}{\sin ky}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 20: 27.4% accurate, 6.6× speedup?

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

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

\mathbf{elif}\;ky \leq 1.55 \cdot 10^{-294}:\\
\;\;\;\;\sqrt{th \cdot th}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -8e9 or 1.55000000000000002e-294 < ky

    1. Initial program 94.6%

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

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

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

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

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

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

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

    if -8e9 < ky < 1.55000000000000002e-294

    1. Initial program 92.7%

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
    7. Taylor expanded in th around 0 3.8%

      \[\leadsto \frac{1}{\color{blue}{\frac{1}{th}}} \]
    8. Step-by-step derivation
      1. remove-double-div3.8%

        \[\leadsto \color{blue}{th} \]
      2. add-sqr-sqrt1.5%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      3. sqrt-unprod19.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
    9. Applied egg-rr19.1%

      \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification28.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -8000000000:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.55 \cdot 10^{-294}:\\ \;\;\;\;\sqrt{th \cdot th}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 21: 23.5% 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.1%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. +-commutative94.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    2. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    4. hypot-def99.7%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
  4. Taylor expanded in kx around 0 24.6%

    \[\leadsto \color{blue}{\sin th} \]
  5. Final simplification24.6%

    \[\leadsto \sin th \]

Alternative 22: 13.7% accurate, 78.8× speedup?

\[\begin{array}{l} \\ \frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (/ 1.0 (+ (/ 1.0 th) (* th 0.16666666666666666))))
double code(double kx, double ky, double th) {
	return 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = 1.0d0 / ((1.0d0 / th) + (th * 0.16666666666666666d0))
end function
public static double code(double kx, double ky, double th) {
	return 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
}
def code(kx, ky, th):
	return 1.0 / ((1.0 / th) + (th * 0.16666666666666666))
function code(kx, ky, th)
	return Float64(1.0 / Float64(Float64(1.0 / th) + Float64(th * 0.16666666666666666)))
end
function tmp = code(kx, ky, th)
	tmp = 1.0 / ((1.0 / th) + (th * 0.16666666666666666));
end
code[kx_, ky_, th_] := N[(1.0 / N[(N[(1.0 / th), $MachinePrecision] + N[(th * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666}
\end{array}
Derivation
  1. Initial program 94.1%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. +-commutative94.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    2. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    4. hypot-def99.7%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
  4. Step-by-step derivation
    1. associate-/r/99.5%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    2. div-inv99.4%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
    3. associate-/r*99.5%

      \[\leadsto \color{blue}{\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{\sin th}}} \]
  5. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{\sin th}}} \]
  6. Taylor expanded in kx around 0 24.5%

    \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
  7. Taylor expanded in th around 0 15.0%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{th} + 0.16666666666666666 \cdot th}} \]
  8. Step-by-step derivation
    1. *-commutative15.0%

      \[\leadsto \frac{1}{\frac{1}{th} + \color{blue}{th \cdot 0.16666666666666666}} \]
  9. Simplified15.0%

    \[\leadsto \frac{1}{\color{blue}{\frac{1}{th} + th \cdot 0.16666666666666666}} \]
  10. Final simplification15.0%

    \[\leadsto \frac{1}{\frac{1}{th} + th \cdot 0.16666666666666666} \]

Alternative 23: 13.1% 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.1%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. +-commutative94.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    2. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    3. unpow294.1%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    4. hypot-def99.7%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th} \]
  4. Step-by-step derivation
    1. associate-/r/99.5%

      \[\leadsto \color{blue}{\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th}}} \]
    2. div-inv99.4%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{\sin th}}} \]
    3. associate-/r*99.5%

      \[\leadsto \color{blue}{\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{\sin th}}} \]
  5. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\frac{1}{\sin th}}} \]
  6. Taylor expanded in kx around 0 24.5%

    \[\leadsto \frac{\color{blue}{1}}{\frac{1}{\sin th}} \]
  7. Taylor expanded in th around 0 14.6%

    \[\leadsto \color{blue}{th} \]
  8. Final simplification14.6%

    \[\leadsto th \]

Reproduce

?
herbie shell --seed 2023187 
(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)))