Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.2% → 99.7%
Time: 20.3s
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: 94.2% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

Alternative 2: 47.1% accurate, 1.0× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-93} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-30}\right) \land \sin ky \leq 10^{-11}:\\
\;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 4.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log3.2%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define3.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define2.4%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt1.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u1.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod10.4%

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

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr10.4%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 35.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-135.6%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified35.6%

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

    if -0.160000000000000003 < (sin.f64 ky) < 3.9999999999999996e-93 or 4.99999999999999972e-30 < (sin.f64 ky) < 9.99999999999999939e-12

    1. Initial program 84.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.9999999999999996e-93 < (sin.f64 ky) < 4.99999999999999972e-30 or 9.99999999999999939e-12 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.16:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-93} \lor \neg \left(\sin ky \leq 5 \cdot 10^{-30}\right) \land \sin ky \leq 10^{-11}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sin kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 77.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin kx \leq -0.0638:\\ \;\;\;\;\frac{\sin ky}{t\_1} \cdot th\\ \mathbf{elif}\;\sin kx \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;\sin kx \leq 0.42:\\ \;\;\;\;\frac{\sin ky \cdot th}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx \cdot \frac{1}{\sin th}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin kx) -0.0638)
     (* (/ (sin ky) t_1) th)
     (if (<= (sin kx) 1e-7)
       (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
       (if (<= (sin kx) 0.42)
         (/ (* (sin ky) th) t_1)
         (/ (sin ky) (* (sin kx) (/ 1.0 (sin th)))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(kx) <= -0.0638) {
		tmp = (sin(ky) / t_1) * th;
	} else if (sin(kx) <= 1e-7) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	} else if (sin(kx) <= 0.42) {
		tmp = (sin(ky) * th) / t_1;
	} else {
		tmp = sin(ky) / (sin(kx) * (1.0 / 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(kx) <= -0.0638) {
		tmp = (Math.sin(ky) / t_1) * th;
	} else if (Math.sin(kx) <= 1e-7) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.hypot(Math.sin(ky), kx));
	} else if (Math.sin(kx) <= 0.42) {
		tmp = (Math.sin(ky) * th) / t_1;
	} else {
		tmp = Math.sin(ky) / (Math.sin(kx) * (1.0 / 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(kx) <= -0.0638:
		tmp = (math.sin(ky) / t_1) * th
	elif math.sin(kx) <= 1e-7:
		tmp = math.sin(th) * (math.sin(ky) / math.hypot(math.sin(ky), kx))
	elif math.sin(kx) <= 0.42:
		tmp = (math.sin(ky) * th) / t_1
	else:
		tmp = math.sin(ky) / (math.sin(kx) * (1.0 / math.sin(th)))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(kx) <= -0.0638)
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	elseif (sin(kx) <= 1e-7)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	elseif (sin(kx) <= 0.42)
		tmp = Float64(Float64(sin(ky) * th) / t_1);
	else
		tmp = Float64(sin(ky) / Float64(sin(kx) * Float64(1.0 / 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(kx) <= -0.0638)
		tmp = (sin(ky) / t_1) * th;
	elseif (sin(kx) <= 1e-7)
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	elseif (sin(kx) <= 0.42)
		tmp = (sin(ky) * th) / t_1;
	else
		tmp = sin(ky) / (sin(kx) * (1.0 / 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[kx], $MachinePrecision], -0.0638], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 0.42], N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$1), $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] * N[(1.0 / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin kx \leq 0.42:\\
\;\;\;\;\frac{\sin ky \cdot th}{t\_1}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.063799999999999996 < (sin.f64 kx) < 9.9999999999999995e-8

    1. Initial program 86.5%

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

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

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

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

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

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

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

    if 9.9999999999999995e-8 < (sin.f64 kx) < 0.419999999999999984

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.419999999999999984 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 4: 77.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ \mathbf{if}\;\sin kx \leq -0.0638:\\ \;\;\;\;\frac{\sin ky}{t\_1} \cdot th\\ \mathbf{elif}\;\sin kx \leq 10^{-7}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;\sin kx \leq 0.42:\\ \;\;\;\;\sin ky \cdot \frac{th}{t\_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\sin kx \cdot \frac{1}{\sin th}}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx))))
   (if (<= (sin kx) -0.0638)
     (* (/ (sin ky) t_1) th)
     (if (<= (sin kx) 1e-7)
       (* (sin th) (/ (sin ky) (hypot (sin ky) kx)))
       (if (<= (sin kx) 0.42)
         (* (sin ky) (/ th t_1))
         (/ (sin ky) (* (sin kx) (/ 1.0 (sin th)))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double tmp;
	if (sin(kx) <= -0.0638) {
		tmp = (sin(ky) / t_1) * th;
	} else if (sin(kx) <= 1e-7) {
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	} else if (sin(kx) <= 0.42) {
		tmp = sin(ky) * (th / t_1);
	} else {
		tmp = sin(ky) / (sin(kx) * (1.0 / 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(kx) <= -0.0638) {
		tmp = (Math.sin(ky) / t_1) * th;
	} else if (Math.sin(kx) <= 1e-7) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.hypot(Math.sin(ky), kx));
	} else if (Math.sin(kx) <= 0.42) {
		tmp = Math.sin(ky) * (th / t_1);
	} else {
		tmp = Math.sin(ky) / (Math.sin(kx) * (1.0 / 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(kx) <= -0.0638:
		tmp = (math.sin(ky) / t_1) * th
	elif math.sin(kx) <= 1e-7:
		tmp = math.sin(th) * (math.sin(ky) / math.hypot(math.sin(ky), kx))
	elif math.sin(kx) <= 0.42:
		tmp = math.sin(ky) * (th / t_1)
	else:
		tmp = math.sin(ky) / (math.sin(kx) * (1.0 / math.sin(th)))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	tmp = 0.0
	if (sin(kx) <= -0.0638)
		tmp = Float64(Float64(sin(ky) / t_1) * th);
	elseif (sin(kx) <= 1e-7)
		tmp = Float64(sin(th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	elseif (sin(kx) <= 0.42)
		tmp = Float64(sin(ky) * Float64(th / t_1));
	else
		tmp = Float64(sin(ky) / Float64(sin(kx) * Float64(1.0 / 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(kx) <= -0.0638)
		tmp = (sin(ky) / t_1) * th;
	elseif (sin(kx) <= 1e-7)
		tmp = sin(th) * (sin(ky) / hypot(sin(ky), kx));
	elseif (sin(kx) <= 0.42)
		tmp = sin(ky) * (th / t_1);
	else
		tmp = sin(ky) / (sin(kx) * (1.0 / 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[kx], $MachinePrecision], -0.0638], N[(N[(N[Sin[ky], $MachinePrecision] / t$95$1), $MachinePrecision] * th), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 1e-7], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 0.42], N[(N[Sin[ky], $MachinePrecision] * N[(th / t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[Sin[ky], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] * N[(1.0 / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;\sin kx \leq 0.42:\\
\;\;\;\;\sin ky \cdot \frac{th}{t\_1}\\

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.063799999999999996 < (sin.f64 kx) < 9.9999999999999995e-8

    1. Initial program 86.5%

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

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

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

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

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

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

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

    if 9.9999999999999995e-8 < (sin.f64 kx) < 0.419999999999999984

    1. Initial program 99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.419999999999999984 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 77.4% accurate, 1.0× speedup?

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

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

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

\mathbf{elif}\;\sin kx \leq 0.42:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -0.063799999999999996 or 9.9999999999999995e-8 < (sin.f64 kx) < 0.419999999999999984

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.063799999999999996 < (sin.f64 kx) < 9.9999999999999995e-8

    1. Initial program 86.5%

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

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

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

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

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

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

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

    if 0.419999999999999984 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 6: 77.3% accurate, 1.0× speedup?

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

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

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

\mathbf{elif}\;\sin kx \leq 0.42:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (sin.f64 kx) < -0.063799999999999996 or 9.9999999999999995e-8 < (sin.f64 kx) < 0.419999999999999984

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if -0.063799999999999996 < (sin.f64 kx) < 9.9999999999999995e-8

    1. Initial program 86.5%

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

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

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

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

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

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

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

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

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

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

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

    if 0.419999999999999984 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx} \cdot \frac{1}{\sin th}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 7: 65.9% accurate, 1.0× speedup?

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

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

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

\mathbf{elif}\;\sin th \leq 0.77:\\
\;\;\;\;t\_1\\

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


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

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\left|\sin kx\right|}}{ky \cdot \sin th}} \]
    9. Applied egg-rr41.3%

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

    if -0.54000000000000004 < (sin.f64 th) < 1.00000000000000006e-9

    1. Initial program 93.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.77000000000000002 < (sin.f64 th)

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{\left|\frac{\sin th}{\sin ky}\right|} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 8: 47.6% accurate, 1.1× speedup?

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

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 4.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log3.2%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define3.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define2.4%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt1.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u1.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod10.4%

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

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr10.4%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 35.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-135.6%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified35.6%

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

    if -0.160000000000000003 < (sin.f64 ky) < 3.9999999999999996e-93

    1. Initial program 84.0%

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

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

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

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

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

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

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

    if 3.9999999999999996e-93 < (sin.f64 ky) < 4.99999999999999972e-30 or 1.99999999999999989e-29 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999972e-30 < (sin.f64 ky) < 1.99999999999999989e-29

    1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 9: 47.6% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
t_1 := \frac{\sin th}{\sin kx}\\
\mathbf{if}\;\sin ky \leq -0.16:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-93}:\\
\;\;\;\;\sin ky \cdot t\_1\\

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

\mathbf{else}:\\
\;\;\;\;ky \cdot t\_1\\


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 4.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log3.2%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define3.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define2.4%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt1.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u1.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod10.4%

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

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr10.4%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 35.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-135.6%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified35.6%

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

    if -0.160000000000000003 < (sin.f64 ky) < 3.9999999999999996e-93

    1. Initial program 84.0%

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

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

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

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

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

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

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

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

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

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

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

    if 3.9999999999999996e-93 < (sin.f64 ky) < 4.99999999999999972e-30 or 1.99999999999999989e-29 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999972e-30 < (sin.f64 ky) < 1.99999999999999989e-29

    1. Initial program 93.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 10: 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 93.4%

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

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

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

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

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

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

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

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

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

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

Alternative 11: 63.7% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;ky \leq 1.02 \cdot 10^{+111}:\\
\;\;\;\;\sin ky \cdot \frac{th}{t\_1}\\

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

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


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

    1. Initial program 91.1%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.3e-4 < ky < 1.02e111

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.02e111 < ky < 2.7e188

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. 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-undefine99.9%

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

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

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

    if 2.7e188 < ky

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 0.00033:\\ \;\;\;\;\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right) \cdot \frac{1}{ky}}\\ \mathbf{elif}\;ky \leq 1.02 \cdot 10^{+111}:\\ \;\;\;\;\sin ky \cdot \frac{th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{+188}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot th\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 42.8% accurate, 1.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.2 \cdot 10^{-84}:\\
\;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{ky \cdot \sin th}}\\

\mathbf{elif}\;ky \leq 1.6 \cdot 10^{-35}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 90.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\left|\sin kx\right|}}{ky \cdot \sin th}} \]
    9. Applied egg-rr43.6%

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

    if 1.20000000000000009e-84 < ky < 1.5999999999999999e-35

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

    if 1.5999999999999999e-35 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \sin ky \cdot \color{blue}{\left|\frac{\sin th}{\sin ky}\right|} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 13: 47.5% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.116:\\ \;\;\;\;-th\\ \mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-93}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.116)
   (- th)
   (if (<= (sin ky) 4e-93) (* (sin th) (/ ky (sin kx))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.116) {
		tmp = -th;
	} else if (sin(ky) <= 4e-93) {
		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) <= (-0.116d0)) then
        tmp = -th
    else if (sin(ky) <= 4d-93) 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) <= -0.116) {
		tmp = -th;
	} else if (Math.sin(ky) <= 4e-93) {
		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) <= -0.116:
		tmp = -th
	elif math.sin(ky) <= 4e-93:
		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) <= -0.116)
		tmp = Float64(-th);
	elseif (sin(ky) <= 4e-93)
		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) <= -0.116)
		tmp = -th;
	elseif (sin(ky) <= 4e-93)
		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], -0.116], (-th), If[LessEqual[N[Sin[ky], $MachinePrecision], 4e-93], 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 -0.116:\\
\;\;\;\;-th\\

\mathbf{elif}\;\sin ky \leq 4 \cdot 10^{-93}:\\
\;\;\;\;\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) < -0.116000000000000006

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 4.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log3.2%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define3.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define2.4%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt1.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u1.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod10.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow210.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr10.1%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 36.1%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-136.1%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified36.1%

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

    if -0.116000000000000006 < (sin.f64 ky) < 3.9999999999999996e-93

    1. Initial program 83.7%

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

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

    if 3.9999999999999996e-93 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 14: 41.2% accurate, 2.2× speedup?

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

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

\mathbf{elif}\;th \leq 3.8 \cdot 10^{+161}:\\
\;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{ky \cdot \sin th}}\\

\mathbf{elif}\;th \leq 2.7 \cdot 10^{+218}:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if th < 135000

    1. Initial program 93.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 135000 < th < 3.8000000000000002e161

    1. Initial program 93.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{1}{\frac{\color{blue}{\left|\sin kx\right|}}{ky \cdot \sin th}} \]
    9. Applied egg-rr50.4%

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

    if 3.8000000000000002e161 < th < 2.70000000000000013e218

    1. Initial program 92.2%

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

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

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

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

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

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

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

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

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

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

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

    if 2.70000000000000013e218 < th

    1. Initial program 90.0%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 135000:\\ \;\;\;\;th \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;th \leq 3.8 \cdot 10^{+161}:\\ \;\;\;\;\frac{1}{\frac{\left|\sin kx\right|}{ky \cdot \sin th}}\\ \mathbf{elif}\;th \leq 2.7 \cdot 10^{+218}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 15: 31.8% accurate, 2.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \left|\sin th\right|\\ t_2 := ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{if}\;ky \leq 2 \cdot 10^{-85}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;ky \leq 4.9 \cdot 10^{-30}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 1.75 \cdot 10^{-8}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;ky \leq 9 \cdot 10^{+98}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;ky \leq 6.1 \cdot 10^{+134}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq 4.8 \cdot 10^{+166}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{+205}:\\ \;\;\;\;-th\\ \mathbf{elif}\;ky \leq 4.4 \cdot 10^{+223}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;ky \leq 9.8 \cdot 10^{+275}:\\ \;\;\;\;-th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fabs (sin th))) (t_2 (* ky (/ (sin th) (sin kx)))))
   (if (<= ky 2e-85)
     t_2
     (if (<= ky 4.9e-30)
       (sin th)
       (if (<= ky 1.75e-8)
         t_2
         (if (<= ky 9e+98)
           t_1
           (if (<= ky 6.1e+134)
             (sin th)
             (if (<= ky 4.8e+166)
               t_1
               (if (<= ky 2.7e+205)
                 (- th)
                 (if (<= ky 4.4e+223)
                   t_1
                   (if (<= ky 9.8e+275) (- th) (sin th))))))))))))
double code(double kx, double ky, double th) {
	double t_1 = fabs(sin(th));
	double t_2 = ky * (sin(th) / sin(kx));
	double tmp;
	if (ky <= 2e-85) {
		tmp = t_2;
	} else if (ky <= 4.9e-30) {
		tmp = sin(th);
	} else if (ky <= 1.75e-8) {
		tmp = t_2;
	} else if (ky <= 9e+98) {
		tmp = t_1;
	} else if (ky <= 6.1e+134) {
		tmp = sin(th);
	} else if (ky <= 4.8e+166) {
		tmp = t_1;
	} else if (ky <= 2.7e+205) {
		tmp = -th;
	} else if (ky <= 4.4e+223) {
		tmp = t_1;
	} else if (ky <= 9.8e+275) {
		tmp = -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) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = abs(sin(th))
    t_2 = ky * (sin(th) / sin(kx))
    if (ky <= 2d-85) then
        tmp = t_2
    else if (ky <= 4.9d-30) then
        tmp = sin(th)
    else if (ky <= 1.75d-8) then
        tmp = t_2
    else if (ky <= 9d+98) then
        tmp = t_1
    else if (ky <= 6.1d+134) then
        tmp = sin(th)
    else if (ky <= 4.8d+166) then
        tmp = t_1
    else if (ky <= 2.7d+205) then
        tmp = -th
    else if (ky <= 4.4d+223) then
        tmp = t_1
    else if (ky <= 9.8d+275) then
        tmp = -th
    else
        tmp = sin(th)
    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 t_2 = ky * (Math.sin(th) / Math.sin(kx));
	double tmp;
	if (ky <= 2e-85) {
		tmp = t_2;
	} else if (ky <= 4.9e-30) {
		tmp = Math.sin(th);
	} else if (ky <= 1.75e-8) {
		tmp = t_2;
	} else if (ky <= 9e+98) {
		tmp = t_1;
	} else if (ky <= 6.1e+134) {
		tmp = Math.sin(th);
	} else if (ky <= 4.8e+166) {
		tmp = t_1;
	} else if (ky <= 2.7e+205) {
		tmp = -th;
	} else if (ky <= 4.4e+223) {
		tmp = t_1;
	} else if (ky <= 9.8e+275) {
		tmp = -th;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.fabs(math.sin(th))
	t_2 = ky * (math.sin(th) / math.sin(kx))
	tmp = 0
	if ky <= 2e-85:
		tmp = t_2
	elif ky <= 4.9e-30:
		tmp = math.sin(th)
	elif ky <= 1.75e-8:
		tmp = t_2
	elif ky <= 9e+98:
		tmp = t_1
	elif ky <= 6.1e+134:
		tmp = math.sin(th)
	elif ky <= 4.8e+166:
		tmp = t_1
	elif ky <= 2.7e+205:
		tmp = -th
	elif ky <= 4.4e+223:
		tmp = t_1
	elif ky <= 9.8e+275:
		tmp = -th
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = abs(sin(th))
	t_2 = Float64(ky * Float64(sin(th) / sin(kx)))
	tmp = 0.0
	if (ky <= 2e-85)
		tmp = t_2;
	elseif (ky <= 4.9e-30)
		tmp = sin(th);
	elseif (ky <= 1.75e-8)
		tmp = t_2;
	elseif (ky <= 9e+98)
		tmp = t_1;
	elseif (ky <= 6.1e+134)
		tmp = sin(th);
	elseif (ky <= 4.8e+166)
		tmp = t_1;
	elseif (ky <= 2.7e+205)
		tmp = Float64(-th);
	elseif (ky <= 4.4e+223)
		tmp = t_1;
	elseif (ky <= 9.8e+275)
		tmp = Float64(-th);
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = abs(sin(th));
	t_2 = ky * (sin(th) / sin(kx));
	tmp = 0.0;
	if (ky <= 2e-85)
		tmp = t_2;
	elseif (ky <= 4.9e-30)
		tmp = sin(th);
	elseif (ky <= 1.75e-8)
		tmp = t_2;
	elseif (ky <= 9e+98)
		tmp = t_1;
	elseif (ky <= 6.1e+134)
		tmp = sin(th);
	elseif (ky <= 4.8e+166)
		tmp = t_1;
	elseif (ky <= 2.7e+205)
		tmp = -th;
	elseif (ky <= 4.4e+223)
		tmp = t_1;
	elseif (ky <= 9.8e+275)
		tmp = -th;
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Abs[N[Sin[th], $MachinePrecision]], $MachinePrecision]}, Block[{t$95$2 = N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[ky, 2e-85], t$95$2, If[LessEqual[ky, 4.9e-30], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 1.75e-8], t$95$2, If[LessEqual[ky, 9e+98], t$95$1, If[LessEqual[ky, 6.1e+134], N[Sin[th], $MachinePrecision], If[LessEqual[ky, 4.8e+166], t$95$1, If[LessEqual[ky, 2.7e+205], (-th), If[LessEqual[ky, 4.4e+223], t$95$1, If[LessEqual[ky, 9.8e+275], (-th), N[Sin[th], $MachinePrecision]]]]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;ky \leq 4.9 \cdot 10^{-30}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 1.75 \cdot 10^{-8}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;ky \leq 9 \cdot 10^{+98}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;ky \leq 6.1 \cdot 10^{+134}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq 4.8 \cdot 10^{+166}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;ky \leq 2.7 \cdot 10^{+205}:\\
\;\;\;\;-th\\

\mathbf{elif}\;ky \leq 4.4 \cdot 10^{+223}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;ky \leq 9.8 \cdot 10^{+275}:\\
\;\;\;\;-th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if ky < 2e-85 or 4.89999999999999971e-30 < ky < 1.75000000000000012e-8

    1. Initial program 90.5%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2e-85 < ky < 4.89999999999999971e-30 or 9.0000000000000004e98 < ky < 6.09999999999999978e134 or 9.7999999999999996e275 < ky

    1. Initial program 99.9%

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

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

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

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

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

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

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

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

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

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

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

    if 1.75000000000000012e-8 < ky < 9.0000000000000004e98 or 6.09999999999999978e134 < ky < 4.79999999999999984e166 or 2.70000000000000012e205 < ky < 4.3999999999999999e223

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.79999999999999984e166 < ky < 2.70000000000000012e205 or 4.3999999999999999e223 < ky < 9.7999999999999996e275

    1. Initial program 99.4%

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.4%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.4%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.4%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.3%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 13.8%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u13.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine12.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr12.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define13.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/13.7%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/13.7%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses13.7%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity13.7%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified13.7%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine12.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine12.2%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log12.2%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative12.2%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr12.2%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 4.9%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log4.4%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define4.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define5.8%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt3.8%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u3.8%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod11.5%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow211.5%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr11.5%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 39.7%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-139.7%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified39.7%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 16: 27.1% accurate, 6.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 7 \cdot 10^{-153}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 4.8 \cdot 10^{+201}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 7e-153)
   (* ky (/ (sin th) kx))
   (if (or (<= ky 8.2e+158) (not (<= ky 4.8e+201))) (sin th) (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 7e-153) {
		tmp = ky * (sin(th) / kx);
	} else if ((ky <= 8.2e+158) || !(ky <= 4.8e+201)) {
		tmp = sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 7d-153) then
        tmp = ky * (sin(th) / kx)
    else if ((ky <= 8.2d+158) .or. (.not. (ky <= 4.8d+201))) then
        tmp = sin(th)
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 7e-153) {
		tmp = ky * (Math.sin(th) / kx);
	} else if ((ky <= 8.2e+158) || !(ky <= 4.8e+201)) {
		tmp = Math.sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 7e-153:
		tmp = ky * (math.sin(th) / kx)
	elif (ky <= 8.2e+158) or not (ky <= 4.8e+201):
		tmp = math.sin(th)
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 7e-153)
		tmp = Float64(ky * Float64(sin(th) / kx));
	elseif ((ky <= 8.2e+158) || !(ky <= 4.8e+201))
		tmp = sin(th);
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 7e-153)
		tmp = ky * (sin(th) / kx);
	elseif ((ky <= 8.2e+158) || ~((ky <= 4.8e+201)))
		tmp = sin(th);
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 7e-153], N[(ky * N[(N[Sin[th], $MachinePrecision] / kx), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[ky, 8.2e+158], N[Not[LessEqual[ky, 4.8e+201]], $MachinePrecision]], N[Sin[th], $MachinePrecision], (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 7 \cdot 10^{-153}:\\
\;\;\;\;ky \cdot \frac{\sin th}{kx}\\

\mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 4.8 \cdot 10^{+201}\right):\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 6.99999999999999961e-153

    1. Initial program 90.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/88.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*90.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow290.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*r/93.8%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      2. clear-num92.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky \cdot \sin th}}} \]
      3. *-commutative92.9%

        \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\sin th \cdot \sin ky}}} \]
    6. Applied egg-rr92.9%

      \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th \cdot \sin ky}}} \]
    7. Taylor expanded in ky around 0 26.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky \cdot \sin th}}} \]
    8. Taylor expanded in kx around 0 18.2%

      \[\leadsto \color{blue}{\frac{ky \cdot \sin th}{kx}} \]
    9. Step-by-step derivation
      1. associate-/l*21.0%

        \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]
    10. Simplified21.0%

      \[\leadsto \color{blue}{ky \cdot \frac{\sin th}{kx}} \]

    if 6.99999999999999961e-153 < ky < 8.20000000000000008e158 or 4.79999999999999985e201 < ky

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/98.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 40.3%

      \[\leadsto \color{blue}{\sin th} \]

    if 8.20000000000000008e158 < ky < 4.79999999999999985e201

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.5%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.5%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 24.2%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u24.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine24.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr24.2%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define24.2%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/23.8%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/24.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses24.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity24.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified24.2%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine24.2%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine24.2%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log24.2%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative24.2%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr24.2%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 6.7%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.7%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define5.7%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt5.1%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u5.1%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod5.5%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow25.5%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr5.5%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 36.1%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-136.1%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified36.1%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification27.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 7 \cdot 10^{-153}:\\ \;\;\;\;ky \cdot \frac{\sin th}{kx}\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 4.8 \cdot 10^{+201}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 17: 26.1% accurate, 6.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 6 \cdot 10^{-160}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 6e-160)
   (* ky (/ th (sin kx)))
   (if (or (<= ky 8.2e+158) (not (<= ky 2.7e+205))) (sin th) (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 6e-160) {
		tmp = ky * (th / sin(kx));
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 6d-160) then
        tmp = ky * (th / sin(kx))
    else if ((ky <= 8.2d+158) .or. (.not. (ky <= 2.7d+205))) then
        tmp = sin(th)
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 6e-160) {
		tmp = ky * (th / Math.sin(kx));
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = Math.sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 6e-160:
		tmp = ky * (th / math.sin(kx))
	elif (ky <= 8.2e+158) or not (ky <= 2.7e+205):
		tmp = math.sin(th)
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 6e-160)
		tmp = Float64(ky * Float64(th / sin(kx)));
	elseif ((ky <= 8.2e+158) || !(ky <= 2.7e+205))
		tmp = sin(th);
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 6e-160)
		tmp = ky * (th / sin(kx));
	elseif ((ky <= 8.2e+158) || ~((ky <= 2.7e+205)))
		tmp = sin(th);
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 6e-160], N[(ky * N[(th / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[ky, 8.2e+158], N[Not[LessEqual[ky, 2.7e+205]], $MachinePrecision]], N[Sin[th], $MachinePrecision], (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 6 \cdot 10^{-160}:\\
\;\;\;\;ky \cdot \frac{th}{\sin kx}\\

\mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.99999999999999993e-160

    1. Initial program 90.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/88.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*90.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow290.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Step-by-step derivation
      1. associate-*r/93.8%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
      2. clear-num92.9%

        \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky \cdot \sin th}}} \]
      3. *-commutative92.9%

        \[\leadsto \frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\color{blue}{\sin th \cdot \sin ky}}} \]
    6. Applied egg-rr92.9%

      \[\leadsto \color{blue}{\frac{1}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin th \cdot \sin ky}}} \]
    7. Taylor expanded in ky around 0 26.5%

      \[\leadsto \frac{1}{\color{blue}{\frac{\sin kx}{ky \cdot \sin th}}} \]
    8. Taylor expanded in th around 0 16.0%

      \[\leadsto \color{blue}{\frac{ky \cdot th}{\sin kx}} \]
    9. Step-by-step derivation
      1. associate-/l*18.8%

        \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]
    10. Simplified18.8%

      \[\leadsto \color{blue}{ky \cdot \frac{th}{\sin kx}} \]

    if 5.99999999999999993e-160 < ky < 8.20000000000000008e158 or 2.70000000000000012e205 < ky

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/98.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 40.7%

      \[\leadsto \color{blue}{\sin th} \]

    if 8.20000000000000008e158 < ky < 2.70000000000000012e205

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 21.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr21.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/21.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified21.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine21.8%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log21.8%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative21.8%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 6.8%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.9%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define5.7%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt5.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u5.2%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod5.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow25.8%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr5.8%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 45.2%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-145.2%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified45.2%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification26.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 6 \cdot 10^{-160}:\\ \;\;\;\;ky \cdot \frac{th}{\sin kx}\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 18: 23.4% accurate, 6.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 4.25 \cdot 10^{-178}:\\ \;\;\;\;\mathsf{log1p}\left(0\right)\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 4.25e-178)
   (log1p 0.0)
   (if (or (<= ky 8.2e+158) (not (<= ky 2.7e+205))) (sin th) (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 4.25e-178) {
		tmp = log1p(0.0);
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 4.25e-178) {
		tmp = Math.log1p(0.0);
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = Math.sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 4.25e-178:
		tmp = math.log1p(0.0)
	elif (ky <= 8.2e+158) or not (ky <= 2.7e+205):
		tmp = math.sin(th)
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 4.25e-178)
		tmp = log1p(0.0);
	elseif ((ky <= 8.2e+158) || !(ky <= 2.7e+205))
		tmp = sin(th);
	else
		tmp = Float64(-th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[ky, 4.25e-178], N[Log[1 + 0.0], $MachinePrecision], If[Or[LessEqual[ky, 8.2e+158], N[Not[LessEqual[ky, 2.7e+205]], $MachinePrecision]], N[Sin[th], $MachinePrecision], (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 4.25 \cdot 10^{-178}:\\
\;\;\;\;\mathsf{log1p}\left(0\right)\\

\mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 4.2500000000000001e-178

    1. Initial program 91.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow291.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow291.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/89.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*91.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 17.4%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine18.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr18.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/24.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified17.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-log1p-u17.4%

        \[\leadsto \color{blue}{\sin th} \]
      2. log1p-expm1-u17.3%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sin th\right)\right)} \]
    11. Applied egg-rr17.3%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\sin th\right)\right)} \]
    12. Taylor expanded in th around inf 18.8%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{e^{\sin th} - 1}\right) \]
    13. Taylor expanded in th around 0 13.3%

      \[\leadsto \mathsf{log1p}\left(\color{blue}{1} - 1\right) \]

    if 4.2500000000000001e-178 < ky < 8.20000000000000008e158 or 2.70000000000000012e205 < 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. unpow296.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg96.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg96.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg96.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow296.9%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/94.8%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*96.9%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow296.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 38.4%

      \[\leadsto \color{blue}{\sin th} \]

    if 8.20000000000000008e158 < ky < 2.70000000000000012e205

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 21.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr21.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/21.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified21.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine21.8%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log21.8%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative21.8%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 6.8%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.9%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define5.7%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt5.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u5.2%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod5.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow25.8%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr5.8%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 45.2%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-145.2%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified45.2%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification23.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 4.25 \cdot 10^{-178}:\\ \;\;\;\;\mathsf{log1p}\left(0\right)\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 19: 23.1% accurate, 6.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.15 \cdot 10^{-160}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.15e-160)
   (+ (+ th 1.0) -1.0)
   (if (or (<= ky 8.2e+158) (not (<= ky 2.7e+205))) (sin th) (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.15e-160) {
		tmp = (th + 1.0) + -1.0;
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.15d-160) then
        tmp = (th + 1.0d0) + (-1.0d0)
    else if ((ky <= 8.2d+158) .or. (.not. (ky <= 2.7d+205))) then
        tmp = sin(th)
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.15e-160) {
		tmp = (th + 1.0) + -1.0;
	} else if ((ky <= 8.2e+158) || !(ky <= 2.7e+205)) {
		tmp = Math.sin(th);
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.15e-160:
		tmp = (th + 1.0) + -1.0
	elif (ky <= 8.2e+158) or not (ky <= 2.7e+205):
		tmp = math.sin(th)
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.15e-160)
		tmp = Float64(Float64(th + 1.0) + -1.0);
	elseif ((ky <= 8.2e+158) || !(ky <= 2.7e+205))
		tmp = sin(th);
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.15e-160)
		tmp = (th + 1.0) + -1.0;
	elseif ((ky <= 8.2e+158) || ~((ky <= 2.7e+205)))
		tmp = sin(th);
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.15e-160], N[(N[(th + 1.0), $MachinePrecision] + -1.0), $MachinePrecision], If[Or[LessEqual[ky, 8.2e+158], N[Not[LessEqual[ky, 2.7e+205]], $MachinePrecision]], N[Sin[th], $MachinePrecision], (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.15 \cdot 10^{-160}:\\
\;\;\;\;\left(th + 1\right) + -1\\

\mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\
\;\;\;\;\sin th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 1.14999999999999992e-160

    1. Initial program 90.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg90.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow290.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/88.0%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*90.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow290.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 17.4%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine19.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr19.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/25.3%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified17.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine19.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine19.3%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log19.3%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative19.3%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr19.3%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 13.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]

    if 1.14999999999999992e-160 < ky < 8.20000000000000008e158 or 2.70000000000000012e205 < ky

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/98.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 40.7%

      \[\leadsto \color{blue}{\sin th} \]

    if 8.20000000000000008e158 < ky < 2.70000000000000012e205

    1. Initial program 99.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 21.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr21.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define21.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/21.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity21.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified21.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine21.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine21.8%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log21.8%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative21.8%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr21.8%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 6.8%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.9%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define5.7%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt5.2%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u5.2%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod5.8%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow25.8%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr5.8%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 45.2%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-145.2%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified45.2%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification22.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.15 \cdot 10^{-160}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 8.2 \cdot 10^{+158} \lor \neg \left(ky \leq 2.7 \cdot 10^{+205}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 20: 18.0% accurate, 37.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 5.1 \cdot 10^{-184}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 6.4 \cdot 10^{+151}:\\ \;\;\;\;\left(th \cdot 2\right) \cdot \frac{1}{th + 2}\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 5.1e-184)
   (+ (+ th 1.0) -1.0)
   (if (<= ky 6.4e+151) (* (* th 2.0) (/ 1.0 (+ th 2.0))) (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 5.1e-184) {
		tmp = (th + 1.0) + -1.0;
	} else if (ky <= 6.4e+151) {
		tmp = (th * 2.0) * (1.0 / (th + 2.0));
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 5.1d-184) then
        tmp = (th + 1.0d0) + (-1.0d0)
    else if (ky <= 6.4d+151) then
        tmp = (th * 2.0d0) * (1.0d0 / (th + 2.0d0))
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 5.1e-184) {
		tmp = (th + 1.0) + -1.0;
	} else if (ky <= 6.4e+151) {
		tmp = (th * 2.0) * (1.0 / (th + 2.0));
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 5.1e-184:
		tmp = (th + 1.0) + -1.0
	elif ky <= 6.4e+151:
		tmp = (th * 2.0) * (1.0 / (th + 2.0))
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 5.1e-184)
		tmp = Float64(Float64(th + 1.0) + -1.0);
	elseif (ky <= 6.4e+151)
		tmp = Float64(Float64(th * 2.0) * Float64(1.0 / Float64(th + 2.0)));
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 5.1e-184)
		tmp = (th + 1.0) + -1.0;
	elseif (ky <= 6.4e+151)
		tmp = (th * 2.0) * (1.0 / (th + 2.0));
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 5.1e-184], N[(N[(th + 1.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[ky, 6.4e+151], N[(N[(th * 2.0), $MachinePrecision] * N[(1.0 / N[(th + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 5.1 \cdot 10^{-184}:\\
\;\;\;\;\left(th + 1\right) + -1\\

\mathbf{elif}\;ky \leq 6.4 \cdot 10^{+151}:\\
\;\;\;\;\left(th \cdot 2\right) \cdot \frac{1}{th + 2}\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 5.0999999999999998e-184

    1. Initial program 91.1%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow291.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg91.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow291.1%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/89.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*91.0%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow291.0%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 17.4%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine18.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr18.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define17.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/24.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity17.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified17.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine18.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine18.8%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log18.8%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative18.8%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr18.8%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 12.6%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]

    if 5.0999999999999998e-184 < ky < 6.39999999999999988e151

    1. Initial program 95.8%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow295.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg95.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg95.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg95.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow295.8%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/92.9%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*95.7%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow295.7%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 37.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u37.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine19.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr19.5%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define37.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/40.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/37.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses37.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity37.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified37.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine19.5%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine19.5%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log19.5%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative19.5%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr19.5%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 10.3%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. flip--10.2%

        \[\leadsto \color{blue}{\frac{\left(1 + th\right) \cdot \left(1 + th\right) - 1 \cdot 1}{\left(1 + th\right) + 1}} \]
      2. div-inv10.2%

        \[\leadsto \color{blue}{\left(\left(1 + th\right) \cdot \left(1 + th\right) - 1 \cdot 1\right) \cdot \frac{1}{\left(1 + th\right) + 1}} \]
      3. metadata-eval10.2%

        \[\leadsto \left(\left(1 + th\right) \cdot \left(1 + th\right) - \color{blue}{1}\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      4. difference-of-sqr-110.2%

        \[\leadsto \color{blue}{\left(\left(\left(1 + th\right) + 1\right) \cdot \left(\left(1 + th\right) - 1\right)\right)} \cdot \frac{1}{\left(1 + th\right) + 1} \]
      5. +-commutative10.2%

        \[\leadsto \left(\left(\color{blue}{\left(th + 1\right)} + 1\right) \cdot \left(\left(1 + th\right) - 1\right)\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      6. associate-+l+10.2%

        \[\leadsto \left(\color{blue}{\left(th + \left(1 + 1\right)\right)} \cdot \left(\left(1 + th\right) - 1\right)\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      7. metadata-eval10.2%

        \[\leadsto \left(\left(th + \color{blue}{2}\right) \cdot \left(\left(1 + th\right) - 1\right)\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      8. add-exp-log9.8%

        \[\leadsto \left(\left(th + 2\right) \cdot \left(\color{blue}{e^{\log \left(1 + th\right)}} - 1\right)\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      9. expm1-define9.8%

        \[\leadsto \left(\left(th + 2\right) \cdot \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)}\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      10. log1p-define27.8%

        \[\leadsto \left(\left(th + 2\right) \cdot \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right)\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      11. expm1-log1p-u28.2%

        \[\leadsto \left(\left(th + 2\right) \cdot \color{blue}{th}\right) \cdot \frac{1}{\left(1 + th\right) + 1} \]
      12. +-commutative28.2%

        \[\leadsto \left(\left(th + 2\right) \cdot th\right) \cdot \frac{1}{\color{blue}{\left(th + 1\right)} + 1} \]
      13. associate-+l+28.2%

        \[\leadsto \left(\left(th + 2\right) \cdot th\right) \cdot \frac{1}{\color{blue}{th + \left(1 + 1\right)}} \]
      14. metadata-eval28.2%

        \[\leadsto \left(\left(th + 2\right) \cdot th\right) \cdot \frac{1}{th + \color{blue}{2}} \]
    14. Applied egg-rr28.2%

      \[\leadsto \color{blue}{\left(\left(th + 2\right) \cdot th\right) \cdot \frac{1}{th + 2}} \]
    15. Taylor expanded in th around 0 29.5%

      \[\leadsto \color{blue}{\left(2 \cdot th\right)} \cdot \frac{1}{th + 2} \]
    16. Step-by-step derivation
      1. *-commutative29.5%

        \[\leadsto \color{blue}{\left(th \cdot 2\right)} \cdot \frac{1}{th + 2} \]
    17. Simplified29.5%

      \[\leadsto \color{blue}{\left(th \cdot 2\right)} \cdot \frac{1}{th + 2} \]

    if 6.39999999999999988e151 < ky

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 36.4%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u36.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine23.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr23.3%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define36.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/36.3%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/36.3%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses36.3%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity36.3%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified36.3%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine23.3%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine23.3%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log23.3%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative23.3%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr23.3%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 5.1%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log4.5%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define4.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define17.5%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt12.7%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u12.7%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod11.1%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow211.1%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr11.1%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 28.9%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-128.9%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified28.9%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification18.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 5.1 \cdot 10^{-184}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 6.4 \cdot 10^{+151}:\\ \;\;\;\;\left(th \cdot 2\right) \cdot \frac{1}{th + 2}\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 21: 16.9% accurate, 58.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 1.4 \cdot 10^{-99}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{-20}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= ky 1.4e-99) (+ (+ th 1.0) -1.0) (if (<= ky 2.7e-20) th (- th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.4e-99) {
		tmp = (th + 1.0) + -1.0;
	} else if (ky <= 2.7e-20) {
		tmp = th;
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 1.4d-99) then
        tmp = (th + 1.0d0) + (-1.0d0)
    else if (ky <= 2.7d-20) then
        tmp = th
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 1.4e-99) {
		tmp = (th + 1.0) + -1.0;
	} else if (ky <= 2.7e-20) {
		tmp = th;
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 1.4e-99:
		tmp = (th + 1.0) + -1.0
	elif ky <= 2.7e-20:
		tmp = th
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 1.4e-99)
		tmp = Float64(Float64(th + 1.0) + -1.0);
	elseif (ky <= 2.7e-20)
		tmp = th;
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 1.4e-99)
		tmp = (th + 1.0) + -1.0;
	elseif (ky <= 2.7e-20)
		tmp = th;
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 1.4e-99], N[(N[(th + 1.0), $MachinePrecision] + -1.0), $MachinePrecision], If[LessEqual[ky, 2.7e-20], th, (-th)]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 1.4 \cdot 10^{-99}:\\
\;\;\;\;\left(th + 1\right) + -1\\

\mathbf{elif}\;ky \leq 2.7 \cdot 10^{-20}:\\
\;\;\;\;th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 1.4e-99

    1. Initial program 90.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow290.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg90.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg90.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg90.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow290.3%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/88.3%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*90.3%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow290.3%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 17.6%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u17.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine20.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr20.0%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define17.6%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/25.8%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/17.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses17.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity17.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified17.6%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine20.0%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine20.0%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log20.0%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative20.0%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr20.0%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 13.7%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]

    if 1.4e-99 < ky < 2.7e-20

    1. Initial program 100.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg100.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg100.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg100.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow2100.0%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/91.6%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.9%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.9%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.9%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 83.1%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Taylor expanded in th around 0 55.6%

      \[\leadsto \color{blue}{th} \]

    if 2.7e-20 < ky

    1. Initial program 99.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.7%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.5%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 33.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u33.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine16.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr16.8%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define33.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/33.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/33.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses33.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity33.5%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified33.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine16.8%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine16.8%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log16.8%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative16.8%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr16.8%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 5.9%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.3%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define21.8%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt12.6%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u12.6%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod13.7%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow213.7%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr13.7%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 21.6%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-121.6%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified21.6%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification17.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 1.4 \cdot 10^{-99}:\\ \;\;\;\;\left(th + 1\right) + -1\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{-20}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \]
  5. Add Preprocessing

Alternative 22: 13.8% accurate, 101.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 8 \cdot 10^{+110}:\\ \;\;\;\;th\\ \mathbf{else}:\\ \;\;\;\;-th\\ \end{array} \end{array} \]
(FPCore (kx ky th) :precision binary64 (if (<= ky 8e+110) th (- th)))
double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8e+110) {
		tmp = th;
	} else {
		tmp = -th;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (ky <= 8d+110) then
        tmp = th
    else
        tmp = -th
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (ky <= 8e+110) {
		tmp = th;
	} else {
		tmp = -th;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if ky <= 8e+110:
		tmp = th
	else:
		tmp = -th
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (ky <= 8e+110)
		tmp = th;
	else
		tmp = Float64(-th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (ky <= 8e+110)
		tmp = th;
	else
		tmp = -th;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[ky, 8e+110], th, (-th)]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 8 \cdot 10^{+110}:\\
\;\;\;\;th\\

\mathbf{else}:\\
\;\;\;\;-th\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < 8.0000000000000002e110

    1. Initial program 92.2%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow292.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg92.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg92.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg92.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow292.2%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/90.2%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*92.2%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow292.2%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 23.1%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Taylor expanded in th around 0 15.9%

      \[\leadsto \color{blue}{th} \]

    if 8.0000000000000002e110 < ky

    1. Initial program 99.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Step-by-step derivation
      1. unpow299.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. sqr-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      3. sin-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
      4. sin-neg99.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
      5. unpow299.6%

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
      6. associate-*l/99.4%

        \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      7. associate-/l*99.6%

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
      8. unpow299.6%

        \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
    4. Add Preprocessing
    5. Taylor expanded in kx around 0 34.5%

      \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
    6. Step-by-step derivation
      1. expm1-log1p-u34.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. expm1-undefine22.4%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    7. Applied egg-rr22.4%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
    8. Step-by-step derivation
      1. expm1-define34.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)\right)} \]
      2. associate-*r/34.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}\right)\right) \]
      3. associate-*l/34.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th}\right)\right) \]
      4. *-inverses34.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{1} \cdot \sin th\right)\right) \]
      5. *-lft-identity34.4%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sin th}\right)\right) \]
    9. Simplified34.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sin th\right)\right)} \]
    10. Step-by-step derivation
      1. expm1-undefine22.4%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin th\right)} - 1} \]
      2. log1p-undefine22.4%

        \[\leadsto e^{\color{blue}{\log \left(1 + \sin th\right)}} - 1 \]
      3. rem-exp-log22.4%

        \[\leadsto \color{blue}{\left(1 + \sin th\right)} - 1 \]
      4. +-commutative22.4%

        \[\leadsto \color{blue}{\left(\sin th + 1\right)} - 1 \]
    11. Applied egg-rr22.4%

      \[\leadsto \color{blue}{\left(\sin th + 1\right) - 1} \]
    12. Taylor expanded in th around 0 6.7%

      \[\leadsto \color{blue}{\left(1 + th\right)} - 1 \]
    13. Step-by-step derivation
      1. add-exp-log5.9%

        \[\leadsto \color{blue}{e^{\log \left(1 + th\right)}} - 1 \]
      2. expm1-define5.9%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\log \left(1 + th\right)\right)} \]
      3. log1p-define17.7%

        \[\leadsto \mathsf{expm1}\left(\color{blue}{\mathsf{log1p}\left(th\right)}\right) \]
      4. add-sqr-sqrt10.8%

        \[\leadsto \mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{\sqrt{th} \cdot \sqrt{th}}\right)\right) \]
      5. expm1-log1p-u10.8%

        \[\leadsto \color{blue}{\sqrt{th} \cdot \sqrt{th}} \]
      6. sqrt-unprod9.7%

        \[\leadsto \color{blue}{\sqrt{th \cdot th}} \]
      7. pow29.7%

        \[\leadsto \sqrt{\color{blue}{{th}^{2}}} \]
    14. Applied egg-rr9.7%

      \[\leadsto \color{blue}{\sqrt{{th}^{2}}} \]
    15. Taylor expanded in th around -inf 24.9%

      \[\leadsto \color{blue}{-1 \cdot th} \]
    16. Step-by-step derivation
      1. neg-mul-124.9%

        \[\leadsto \color{blue}{-th} \]
    17. Simplified24.9%

      \[\leadsto \color{blue}{-th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 23: 13.8% accurate, 709.0× speedup?

\[\begin{array}{l} \\ th \end{array} \]
(FPCore (kx ky th) :precision binary64 th)
double code(double kx, double ky, double th) {
	return th;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = th
end function
public static double code(double kx, double ky, double th) {
	return th;
}
def code(kx, ky, th):
	return th
function code(kx, ky, th)
	return th
end
function tmp = code(kx, ky, th)
	tmp = th;
end
code[kx_, ky_, th_] := th
\begin{array}{l}

\\
th
\end{array}
Derivation
  1. Initial program 93.4%

    \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
  2. Step-by-step derivation
    1. unpow293.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin kx \cdot \sin kx} + {\sin ky}^{2}}} \cdot \sin th \]
    2. sqr-neg93.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\left(-\sin kx\right) \cdot \left(-\sin kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
    3. sin-neg93.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin \left(-kx\right)} \cdot \left(-\sin kx\right) + {\sin ky}^{2}}} \cdot \sin th \]
    4. sin-neg93.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\sin \left(-kx\right) \cdot \color{blue}{\sin \left(-kx\right)} + {\sin ky}^{2}}} \cdot \sin th \]
    5. unpow293.4%

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin \left(-kx\right)}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    6. associate-*l/91.6%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
    7. associate-/l*93.3%

      \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\sqrt{{\sin \left(-kx\right)}^{2} + {\sin ky}^{2}}}} \]
    8. unpow293.3%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\sqrt{\color{blue}{\sin \left(-kx\right) \cdot \sin \left(-kx\right)} + {\sin ky}^{2}}} \]
  3. Simplified99.6%

    \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
  4. Add Preprocessing
  5. Taylor expanded in kx around 0 24.9%

    \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{\sin ky}} \]
  6. Taylor expanded in th around 0 16.3%

    \[\leadsto \color{blue}{th} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024107 
(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)))