Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 18.3s
Alternatives: 16
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 16 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 91.0%

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 48.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191} \lor \neg \left(\sin kx \leq 10^{-182}\right) \land \sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-ky \cdot \sin th}}{\sin kx} \]
      3. *-commutative61.0%

        \[\leadsto \frac{-\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      4. distribute-rgt-neg-in61.0%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182 or 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 94.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191} \lor \neg \left(\sin kx \leq 10^{-182}\right) \land \sin kx \leq 5 \cdot 10^{-92}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \end{array} \]

Alternative 3: 48.1% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\
\;\;\;\;\sin th\\

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-ky \cdot \sin th}}{\sin kx} \]
      3. *-commutative61.0%

        \[\leadsto \frac{-\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      4. distribute-rgt-neg-in61.0%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182

    1. Initial program 2.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-182}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]

Alternative 4: 45.8% accurate, 1.1× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\
\;\;\;\;\sin th\\

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-ky \cdot \sin th}}{\sin kx} \]
      3. *-commutative61.0%

        \[\leadsto \frac{-\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      4. distribute-rgt-neg-in61.0%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182

    1. Initial program 2.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}} \]
      2. div-inv99.6%

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

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

    if 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 70.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.02:\\
\;\;\;\;\sqrt{{\sin th}^{2}}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod36.2%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow236.2%

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

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]

    if -0.0200000000000000004 < (sin.f64 ky) < 0.0400000000000000008

    1. Initial program 84.1%

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0400000000000000008 < (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 68.0%

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

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

Alternative 6: 45.6% accurate, 1.2× speedup?

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

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\
\;\;\;\;\sin th\\

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{-1 \cdot ky}{\sin kx}} \cdot \sin th \]
      2. neg-mul-161.1%

        \[\leadsto \frac{\color{blue}{-ky}}{\sin kx} \cdot \sin th \]
    9. Simplified61.1%

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182

    1. Initial program 2.2%

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

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

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

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

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

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

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

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

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

    if 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{-ky}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-182}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]

Alternative 7: 45.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\
\;\;\;\;\sin th\\

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-ky \cdot \sin th}}{\sin kx} \]
      3. *-commutative61.0%

        \[\leadsto \frac{-\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      4. distribute-rgt-neg-in61.0%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182

    1. Initial program 2.2%

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

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

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

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

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

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

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

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

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

    if 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-182}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\ \end{array} \]

Alternative 8: 45.6% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;\frac{ky \cdot \left(-\sin th\right)}{\sin kx}\\

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-191}:\\
\;\;\;\;\sin th\\

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

\mathbf{elif}\;\sin kx \leq 5 \cdot 10^{-92}:\\
\;\;\;\;\sin th\\

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


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

    1. Initial program 99.4%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{-ky \cdot \sin th}}{\sin kx} \]
      3. *-commutative61.0%

        \[\leadsto \frac{-\color{blue}{\sin th \cdot ky}}{\sin kx} \]
      4. distribute-rgt-neg-in61.0%

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

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

    if -0.0050000000000000001 < (sin.f64 kx) < 5.0000000000000001e-191 or 1e-182 < (sin.f64 kx) < 5.00000000000000011e-92

    1. Initial program 84.1%

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

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

    if 5.0000000000000001e-191 < (sin.f64 kx) < 1e-182

    1. Initial program 2.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\frac{kx}{\sin th}}} \]
      2. div-inv99.6%

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

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

    if 5.00000000000000011e-92 < (sin.f64 kx)

    1. Initial program 99.6%

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

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

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

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

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

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

Alternative 9: 70.7% accurate, 1.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.002:\\
\;\;\;\;\sqrt{{\sin th}^{2}}\\

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{\sin ky}{\sin ky} \cdot \sin th} \]
      2. *-inverses2.8%

        \[\leadsto \color{blue}{1} \cdot \sin th \]
      3. *-un-lft-identity2.8%

        \[\leadsto \color{blue}{\sin th} \]
      4. add-sqr-sqrt0.7%

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      5. sqrt-unprod35.2%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      6. pow235.2%

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

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]

    if -2e-3 < (sin.f64 ky) < 4.99999999999999977e-7

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if 4.99999999999999977e-7 < (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 66.3%

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

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

Alternative 10: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 11: 33.1% accurate, 3.4× speedup?

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

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

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


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

    1. Initial program 87.8%

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

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

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

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

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

    if 3.89999999999999998e-22 < 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 40.2%

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

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

Alternative 12: 27.3% accurate, 6.6× speedup?

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

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

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


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

    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 31.4%

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

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

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

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

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

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

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

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

    if 5.99999999999999967e-141 < 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.1%

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

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

Alternative 13: 27.3% accurate, 6.6× speedup?

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

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

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


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

    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 31.4%

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

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

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

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

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

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

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

    if 2.80000000000000004e-142 < 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.1%

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

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

Alternative 14: 24.4% accurate, 6.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 3.15 \cdot 10^{-143}:\\
\;\;\;\;th \cdot \frac{ky}{kx}\\

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


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

    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 31.4%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    10. Simplified19.1%

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

    if 3.15000000000000019e-143 < 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.1%

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

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

Alternative 15: 18.1% accurate, 100.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;ky \leq 3.6 \cdot 10^{-52}:\\
\;\;\;\;th \cdot \frac{ky}{kx}\\

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


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

    1. Initial program 87.3%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\frac{ky}{kx} \cdot th} \]
    10. Simplified20.3%

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

    if 3.59999999999999988e-52 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
    7. Taylor expanded in th around 0 16.3%

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

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

Alternative 16: 14.3% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sin ky}{\sin th}}} \]
  7. Taylor expanded in th around 0 13.1%

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

    \[\leadsto th \]

Reproduce

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