Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 19.9s
Alternatives: 15
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 15 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.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 2: 79.3% accurate, 1.2× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in6.0%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative6.0%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 57.9%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg57.9%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified57.9%

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

    if -0.0050000000000000001 < (sin.f64 ky) < 2.0000000000000001e-4

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 3: 79.4% accurate, 1.4× speedup?

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

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

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in6.0%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative6.0%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 57.9%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg57.9%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified57.9%

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

    if -0.0050000000000000001 < (sin.f64 ky) < 2.0000000000000001e-4

    1. Initial program 89.4%

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

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

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

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

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

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

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

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

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

    1. Initial program 99.7%

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

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

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

Alternative 4: 68.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -5 \cdot 10^{-36}:\\
\;\;\;\;-\sin th\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in8.6%

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

        \[\leadsto \frac{\color{blue}{\sin ky \cdot \left(-\sin th\right)}}{ky} \]
    7. Simplified8.6%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 58.4%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg58.4%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified58.4%

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

    if -5.00000000000000004e-36 < (sin.f64 ky) < 1.9999999999999999e-36

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-36 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 5: 68.0% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -5 \cdot 10^{-36}:\\
\;\;\;\;-\sin th\\

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

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


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

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in8.6%

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

        \[\leadsto \frac{\color{blue}{\sin ky \cdot \left(-\sin th\right)}}{ky} \]
    7. Simplified8.6%

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 58.4%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg58.4%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified58.4%

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

    if -5.00000000000000004e-36 < (sin.f64 ky) < 1.9999999999999999e-36

    1. Initial program 88.6%

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

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

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

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

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

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

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

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

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

    if 1.9999999999999999e-36 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

Alternative 6: 80.9% accurate, 1.7× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < -4.00000000000000033e-5 or 3.6999999999999997e-29 < th

    1. Initial program 95.1%

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

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

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

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

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

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

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

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

    if -4.00000000000000033e-5 < th < 3.6999999999999997e-29

    1. Initial program 94.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{\mathsf{hypot}\left(\sin kx, \sin ky\right)} \cdot \sqrt{\mathsf{hypot}\left(\sin kx, \sin ky\right)}}} \cdot th \]
      6. add-sqr-sqrt99.8%

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

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

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

Alternative 7: 40.7% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.75 \cdot 10^{-153}:\\ \;\;\;\;\frac{ky \cdot t_1}{ky}\\ \mathbf{elif}\;ky \leq 1.15 \cdot 10^{-38}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -1.75e-153)
         (/ (* ky t_1) ky)
         (if (<= ky 1.15e-38) (* (sin th) (/ ky (sin kx))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -1.75e-153) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 1.15e-38) {
		tmp = sin(th) * (ky / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-1.75d-153)) then
        tmp = (ky * t_1) / ky
    else if (ky <= 1.15d-38) then
        tmp = sin(th) * (ky / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -1.75e-153) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 1.15e-38) {
		tmp = Math.sin(th) * (ky / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -1.75e-153:
		tmp = (ky * t_1) / ky
	elif ky <= 1.15e-38:
		tmp = math.sin(th) * (ky / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.75e-153)
		tmp = Float64(Float64(ky * t_1) / ky);
	elseif (ky <= 1.15e-38)
		tmp = Float64(sin(th) * Float64(ky / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.75e-153)
		tmp = (ky * t_1) / ky;
	elseif (ky <= 1.15e-38)
		tmp = sin(th) * (ky / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -1.75e-153], N[(N[(ky * t$95$1), $MachinePrecision] / ky), $MachinePrecision], If[LessEqual[ky, 1.15e-38], N[(N[Sin[th], $MachinePrecision] * N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -1.75 \cdot 10^{-153}:\\
\;\;\;\;\frac{ky \cdot t_1}{ky}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in4.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative4.5%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 38.0%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg38.0%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified38.0%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 1.15000000000000001e-38 < ky

    1. Initial program 99.7%

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

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

    if -2.1999999999999999e136 < ky < -1.7499999999999999e-153

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in25.2%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 43.5%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin th \cdot ky\right)}}{ky} \]
    9. Step-by-step derivation
      1. neg-mul-143.5%

        \[\leadsto \frac{\color{blue}{-\sin th \cdot ky}}{ky} \]
      2. distribute-rgt-neg-in43.5%

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

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

    if -1.7499999999999999e-153 < ky < 1.15000000000000001e-38

    1. Initial program 85.7%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.75 \cdot 10^{-153}:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{ky}\\ \mathbf{elif}\;ky \leq 1.15 \cdot 10^{-38}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 8: 40.7% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.2 \cdot 10^{-152}:\\ \;\;\;\;\frac{ky \cdot t_1}{ky}\\ \mathbf{elif}\;ky \leq 3.8 \cdot 10^{-38}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -1.2e-152)
         (/ (* ky t_1) ky)
         (if (<= ky 3.8e-38) (* ky (/ (sin th) (sin kx))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -1.2e-152) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 3.8e-38) {
		tmp = ky * (sin(th) / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-1.2d-152)) then
        tmp = (ky * t_1) / ky
    else if (ky <= 3.8d-38) then
        tmp = ky * (sin(th) / sin(kx))
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -1.2e-152) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 3.8e-38) {
		tmp = ky * (Math.sin(th) / Math.sin(kx));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -1.2e-152:
		tmp = (ky * t_1) / ky
	elif ky <= 3.8e-38:
		tmp = ky * (math.sin(th) / math.sin(kx))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.2e-152)
		tmp = Float64(Float64(ky * t_1) / ky);
	elseif (ky <= 3.8e-38)
		tmp = Float64(ky * Float64(sin(th) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.2e-152)
		tmp = (ky * t_1) / ky;
	elseif (ky <= 3.8e-38)
		tmp = ky * (sin(th) / sin(kx));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -1.2e-152], N[(N[(ky * t$95$1), $MachinePrecision] / ky), $MachinePrecision], If[LessEqual[ky, 3.8e-38], N[(ky * N[(N[Sin[th], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -1.2 \cdot 10^{-152}:\\
\;\;\;\;\frac{ky \cdot t_1}{ky}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in4.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative4.5%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 38.0%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg38.0%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified38.0%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 3.8e-38 < ky

    1. Initial program 99.7%

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

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

    if -2.1999999999999999e136 < ky < -1.2e-152

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in25.2%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 43.5%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin th \cdot ky\right)}}{ky} \]
    9. Step-by-step derivation
      1. neg-mul-143.5%

        \[\leadsto \frac{\color{blue}{-\sin th \cdot ky}}{ky} \]
      2. distribute-rgt-neg-in43.5%

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

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

    if -1.2e-152 < ky < 3.8e-38

    1. Initial program 85.7%

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

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\frac{\sin kx}{\sin th}}} \]
    5. Step-by-step derivation
      1. clear-num54.1%

        \[\leadsto \color{blue}{\frac{1}{\frac{\frac{\sin kx}{\sin th}}{ky}}} \]
      2. associate-/r/54.3%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.2 \cdot 10^{-152}:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{ky}\\ \mathbf{elif}\;ky \leq 3.8 \cdot 10^{-38}:\\ \;\;\;\;ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 9: 40.7% accurate, 3.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -7.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{ky \cdot t_1}{ky}\\ \mathbf{elif}\;ky \leq 7.5 \cdot 10^{-38}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -7.2e-153)
         (/ (* ky t_1) ky)
         (if (<= ky 7.5e-38) (/ ky (/ (sin kx) (sin th))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -7.2e-153) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 7.5e-38) {
		tmp = 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) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-7.2d-153)) then
        tmp = (ky * t_1) / ky
    else if (ky <= 7.5d-38) then
        tmp = 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 t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -7.2e-153) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 7.5e-38) {
		tmp = ky / (Math.sin(kx) / Math.sin(th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -7.2e-153:
		tmp = (ky * t_1) / ky
	elif ky <= 7.5e-38:
		tmp = ky / (math.sin(kx) / math.sin(th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -7.2e-153)
		tmp = Float64(Float64(ky * t_1) / ky);
	elseif (ky <= 7.5e-38)
		tmp = Float64(ky / Float64(sin(kx) / sin(th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -7.2e-153)
		tmp = (ky * t_1) / ky;
	elseif (ky <= 7.5e-38)
		tmp = ky / (sin(kx) / sin(th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -7.2e-153], N[(N[(ky * t$95$1), $MachinePrecision] / ky), $MachinePrecision], If[LessEqual[ky, 7.5e-38], N[(ky / N[(N[Sin[kx], $MachinePrecision] / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -7.2 \cdot 10^{-153}:\\
\;\;\;\;\frac{ky \cdot t_1}{ky}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in4.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative4.5%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 38.0%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg38.0%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified38.0%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 7.5e-38 < ky

    1. Initial program 99.7%

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

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

    if -2.1999999999999999e136 < ky < -7.1999999999999995e-153

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in25.2%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 43.5%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin th \cdot ky\right)}}{ky} \]
    9. Step-by-step derivation
      1. neg-mul-143.5%

        \[\leadsto \frac{\color{blue}{-\sin th \cdot ky}}{ky} \]
      2. distribute-rgt-neg-in43.5%

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

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

    if -7.1999999999999995e-153 < ky < 7.5e-38

    1. Initial program 85.7%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -7.2 \cdot 10^{-153}:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{ky}\\ \mathbf{elif}\;ky \leq 7.5 \cdot 10^{-38}:\\ \;\;\;\;\frac{ky}{\frac{\sin kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 10: 36.1% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -5.4 \cdot 10^{-180}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 6.6 \cdot 10^{-97}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -5.4e-180)
         t_1
         (if (<= ky 6.6e-97) (* (sin th) (/ ky kx)) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -5.4e-180) {
		tmp = t_1;
	} else if (ky <= 6.6e-97) {
		tmp = sin(th) * (ky / kx);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-5.4d-180)) then
        tmp = t_1
    else if (ky <= 6.6d-97) then
        tmp = sin(th) * (ky / kx)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = -Math.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -5.4e-180) {
		tmp = t_1;
	} else if (ky <= 6.6e-97) {
		tmp = Math.sin(th) * (ky / kx);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -5.4e-180:
		tmp = t_1
	elif ky <= 6.6e-97:
		tmp = math.sin(th) * (ky / kx)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -5.4e-180)
		tmp = t_1;
	elseif (ky <= 6.6e-97)
		tmp = Float64(sin(th) * Float64(ky / kx));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -5.4e-180)
		tmp = t_1;
	elseif (ky <= 6.6e-97)
		tmp = sin(th) * (ky / kx);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -5.4e-180], t$95$1, If[LessEqual[ky, 6.6e-97], N[(N[Sin[th], $MachinePrecision] * N[(ky / kx), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -5.4 \cdot 10^{-180}:\\
\;\;\;\;t_1\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -6.5000000000000006e222 or -2.1999999999999999e136 < ky < -5.40000000000000028e-180

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in22.2%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 41.4%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg41.4%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified41.4%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 6.6000000000000002e-97 < ky

    1. Initial program 99.7%

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

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

    if -5.40000000000000028e-180 < ky < 6.6000000000000002e-97

    1. Initial program 85.3%

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -5.4 \cdot 10^{-180}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq 6.6 \cdot 10^{-97}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 11: 36.0% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -9 \cdot 10^{-179}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{-96}:\\ \;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -9e-179)
         t_1
         (if (<= ky 2.7e-96) (/ ky (/ kx (sin th))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -9e-179) {
		tmp = t_1;
	} else if (ky <= 2.7e-96) {
		tmp = ky / (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) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-9d-179)) then
        tmp = t_1
    else if (ky <= 2.7d-96) then
        tmp = ky / (kx / sin(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.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -9e-179) {
		tmp = t_1;
	} else if (ky <= 2.7e-96) {
		tmp = ky / (kx / Math.sin(th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -9e-179:
		tmp = t_1
	elif ky <= 2.7e-96:
		tmp = ky / (kx / math.sin(th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -9e-179)
		tmp = t_1;
	elseif (ky <= 2.7e-96)
		tmp = Float64(ky / Float64(kx / sin(th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -9e-179)
		tmp = t_1;
	elseif (ky <= 2.7e-96)
		tmp = ky / (kx / sin(th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -9e-179], t$95$1, If[LessEqual[ky, 2.7e-96], N[(ky / N[(kx / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < -6.5000000000000006e222 or -2.1999999999999999e136 < ky < -8.99999999999999984e-179

    1. Initial program 96.4%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in22.2%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 41.4%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg41.4%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified41.4%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 2.7e-96 < ky

    1. Initial program 99.7%

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

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

    if -8.99999999999999984e-179 < ky < 2.7e-96

    1. Initial program 85.3%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -9 \cdot 10^{-179}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq 2.7 \cdot 10^{-96}:\\ \;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 12: 36.4% accurate, 6.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := -\sin th\\ \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.9 \cdot 10^{-197}:\\ \;\;\;\;\frac{ky \cdot t_1}{ky}\\ \mathbf{elif}\;ky \leq 7 \cdot 10^{-97}:\\ \;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (- (sin th))))
   (if (<= ky -6.5e+222)
     t_1
     (if (<= ky -2.2e+136)
       (sin th)
       (if (<= ky -1.9e-197)
         (/ (* ky t_1) ky)
         (if (<= ky 7e-97) (/ ky (/ kx (sin th))) (sin th)))))))
double code(double kx, double ky, double th) {
	double t_1 = -sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = sin(th);
	} else if (ky <= -1.9e-197) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 7e-97) {
		tmp = ky / (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) :: t_1
    real(8) :: tmp
    t_1 = -sin(th)
    if (ky <= (-6.5d+222)) then
        tmp = t_1
    else if (ky <= (-2.2d+136)) then
        tmp = sin(th)
    else if (ky <= (-1.9d-197)) then
        tmp = (ky * t_1) / ky
    else if (ky <= 7d-97) then
        tmp = ky / (kx / sin(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.sin(th);
	double tmp;
	if (ky <= -6.5e+222) {
		tmp = t_1;
	} else if (ky <= -2.2e+136) {
		tmp = Math.sin(th);
	} else if (ky <= -1.9e-197) {
		tmp = (ky * t_1) / ky;
	} else if (ky <= 7e-97) {
		tmp = ky / (kx / Math.sin(th));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = -math.sin(th)
	tmp = 0
	if ky <= -6.5e+222:
		tmp = t_1
	elif ky <= -2.2e+136:
		tmp = math.sin(th)
	elif ky <= -1.9e-197:
		tmp = (ky * t_1) / ky
	elif ky <= 7e-97:
		tmp = ky / (kx / math.sin(th))
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(-sin(th))
	tmp = 0.0
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.9e-197)
		tmp = Float64(Float64(ky * t_1) / ky);
	elseif (ky <= 7e-97)
		tmp = Float64(ky / Float64(kx / sin(th)));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = -sin(th);
	tmp = 0.0;
	if (ky <= -6.5e+222)
		tmp = t_1;
	elseif (ky <= -2.2e+136)
		tmp = sin(th);
	elseif (ky <= -1.9e-197)
		tmp = (ky * t_1) / ky;
	elseif (ky <= 7e-97)
		tmp = ky / (kx / sin(th));
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = (-N[Sin[th], $MachinePrecision])}, If[LessEqual[ky, -6.5e+222], t$95$1, If[LessEqual[ky, -2.2e+136], N[Sin[th], $MachinePrecision], If[LessEqual[ky, -1.9e-197], N[(N[(ky * t$95$1), $MachinePrecision] / ky), $MachinePrecision], If[LessEqual[ky, 7e-97], N[(ky / N[(kx / N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := -\sin th\\
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;ky \leq -1.9 \cdot 10^{-197}:\\
\;\;\;\;\frac{ky \cdot t_1}{ky}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in4.5%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative4.5%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 38.0%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg38.0%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified38.0%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or 7.00000000000000038e-97 < ky

    1. Initial program 99.7%

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

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

    if -2.1999999999999999e136 < ky < -1.8999999999999999e-197

    1. Initial program 93.2%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in29.1%

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

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 44.3%

      \[\leadsto \frac{\color{blue}{-1 \cdot \left(\sin th \cdot ky\right)}}{ky} \]
    9. Step-by-step derivation
      1. neg-mul-144.3%

        \[\leadsto \frac{\color{blue}{-\sin th \cdot ky}}{ky} \]
      2. distribute-rgt-neg-in44.3%

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

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

    if -1.8999999999999999e-197 < ky < 7.00000000000000038e-97

    1. Initial program 87.1%

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222}:\\ \;\;\;\;-\sin th\\ \mathbf{elif}\;ky \leq -2.2 \cdot 10^{+136}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;ky \leq -1.9 \cdot 10^{-197}:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{ky}\\ \mathbf{elif}\;ky \leq 7 \cdot 10^{-97}:\\ \;\;\;\;\frac{ky}{\frac{kx}{\sin th}}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 13: 29.4% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222} \lor \neg \left(ky \leq -2.2 \cdot 10^{+136}\right) \land ky \leq -2 \cdot 10^{-310}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (or (<= ky -6.5e+222) (and (not (<= ky -2.2e+136)) (<= ky -2e-310)))
   (- (sin th))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((ky <= -6.5e+222) || (!(ky <= -2.2e+136) && (ky <= -2e-310))) {
		tmp = -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 ((ky <= (-6.5d+222)) .or. (.not. (ky <= (-2.2d+136))) .and. (ky <= (-2d-310))) then
        tmp = -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 ((ky <= -6.5e+222) || (!(ky <= -2.2e+136) && (ky <= -2e-310))) {
		tmp = -Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if (ky <= -6.5e+222) or (not (ky <= -2.2e+136) and (ky <= -2e-310)):
		tmp = -math.sin(th)
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if ((ky <= -6.5e+222) || (!(ky <= -2.2e+136) && (ky <= -2e-310)))
		tmp = Float64(-sin(th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if ((ky <= -6.5e+222) || (~((ky <= -2.2e+136)) && (ky <= -2e-310)))
		tmp = -sin(th);
	else
		tmp = sin(th);
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[Or[LessEqual[ky, -6.5e+222], And[N[Not[LessEqual[ky, -2.2e+136]], $MachinePrecision], LessEqual[ky, -2e-310]]], (-N[Sin[th], $MachinePrecision]), N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;ky \leq -6.5 \cdot 10^{+222} \lor \neg \left(ky \leq -2.2 \cdot 10^{+136}\right) \land ky \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if ky < -6.5000000000000006e222 or -2.1999999999999999e136 < ky < -1.999999999999994e-310

    1. Initial program 92.1%

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-\sin th \cdot \sin ky}}{ky} \]
      3. distribute-lft-neg-in27.3%

        \[\leadsto \frac{\color{blue}{\left(-\sin th\right) \cdot \sin ky}}{ky} \]
      4. *-commutative27.3%

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

      \[\leadsto \color{blue}{\frac{\sin ky \cdot \left(-\sin th\right)}{ky}} \]
    8. Taylor expanded in ky around 0 35.1%

      \[\leadsto \color{blue}{-1 \cdot \sin th} \]
    9. Step-by-step derivation
      1. mul-1-neg35.1%

        \[\leadsto \color{blue}{-\sin th} \]
    10. Simplified35.1%

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

    if -6.5000000000000006e222 < ky < -2.1999999999999999e136 or -1.999999999999994e-310 < ky

    1. Initial program 97.4%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq -6.5 \cdot 10^{+222} \lor \neg \left(ky \leq -2.2 \cdot 10^{+136}\right) \land ky \leq -2 \cdot 10^{-310}:\\ \;\;\;\;-\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]

Alternative 14: 23.3% accurate, 7.0× speedup?

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

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

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

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

    \[\leadsto \sin th \]

Alternative 15: 13.6% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  8. Final simplification10.5%

    \[\leadsto th \]

Reproduce

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