Toniolo and Linder, Equation (3b), real

Percentage Accurate: 93.8% → 99.7%
Time: 15.5s
Alternatives: 21
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 21 alternatives:

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

Initial Program: 93.8% 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 th}{\frac{\mathsf{hypot}\left(\sin ky, \sin kx\right)}{\sin ky}} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (/ (sin th) (/ (hypot (sin ky) (sin kx)) (sin ky))))
double code(double kx, double ky, double th) {
	return sin(th) / (hypot(sin(ky), sin(kx)) / sin(ky));
}
public static double code(double kx, double ky, double th) {
	return Math.sin(th) / (Math.hypot(Math.sin(ky), Math.sin(kx)) / Math.sin(ky));
}
def code(kx, ky, th):
	return math.sin(th) / (math.hypot(math.sin(ky), math.sin(kx)) / math.sin(ky))
function code(kx, ky, th)
	return Float64(sin(th) / Float64(hypot(sin(ky), sin(kx)) / sin(ky)))
end
function tmp = code(kx, ky, th)
	tmp = sin(th) / (hypot(sin(ky), sin(kx)) / sin(ky));
end
code[kx_, ky_, th_] := N[(N[Sin[th], $MachinePrecision] / N[(N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision] / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 2: 48.8% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
t_1 := \sin th \cdot ky\\
\mathbf{if}\;\sin kx \leq -0.005:\\
\;\;\;\;t\_1 \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\

\mathbf{elif}\;\sin kx \leq 2.5 \cdot 10^{-119}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 10^{-98} \lor \neg \left(\sin kx \leq 2 \cdot 10^{-60}\right):\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \frac{\cos \color{blue}{\left(2 \cdot kx\right)}}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
      6. *-commutative98.0%

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    8. Taylor expanded in ky around 0 57.7%

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

    if -0.0050000000000000001 < (sin.f64 kx) < 2.49999999999999996e-119

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

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

    if 2.49999999999999996e-119 < (sin.f64 kx) < 9.99999999999999939e-99 or 1.9999999999999999e-60 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

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

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

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

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

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

    if 9.99999999999999939e-99 < (sin.f64 kx) < 1.9999999999999999e-60

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/24.4%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr24.4%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out43.1%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define43.1%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-143.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified43.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2.5 \cdot 10^{-119}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-98} \lor \neg \left(\sin kx \leq 2 \cdot 10^{-60}\right):\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{ky}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 48.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2.5 \cdot 10^{-119}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-98} \lor \neg \left(\sin kx \leq 2 \cdot 10^{-60}\right):\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{ky}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin kx) -0.005)
   (* (sin th) (/ ky (sqrt (- 0.5 (* 0.5 (cos (* kx 2.0)))))))
   (if (<= (sin kx) 2.5e-119)
     (sin th)
     (if (or (<= (sin kx) 1e-98) (not (<= (sin kx) 2e-60)))
       (* (sin th) (/ (sin ky) (sin kx)))
       (/ (* (sin th) ky) ky)))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.005) {
		tmp = sin(th) * (ky / sqrt((0.5 - (0.5 * cos((kx * 2.0))))));
	} else if (sin(kx) <= 2.5e-119) {
		tmp = sin(th);
	} else if ((sin(kx) <= 1e-98) || !(sin(kx) <= 2e-60)) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else {
		tmp = (sin(th) * ky) / ky;
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (sin(kx) <= (-0.005d0)) then
        tmp = sin(th) * (ky / sqrt((0.5d0 - (0.5d0 * cos((kx * 2.0d0))))))
    else if (sin(kx) <= 2.5d-119) then
        tmp = sin(th)
    else if ((sin(kx) <= 1d-98) .or. (.not. (sin(kx) <= 2d-60))) then
        tmp = sin(th) * (sin(ky) / sin(kx))
    else
        tmp = (sin(th) * ky) / 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 = Math.sin(th) * (ky / Math.sqrt((0.5 - (0.5 * Math.cos((kx * 2.0))))));
	} else if (Math.sin(kx) <= 2.5e-119) {
		tmp = Math.sin(th);
	} else if ((Math.sin(kx) <= 1e-98) || !(Math.sin(kx) <= 2e-60)) {
		tmp = Math.sin(th) * (Math.sin(ky) / Math.sin(kx));
	} else {
		tmp = (Math.sin(th) * ky) / ky;
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if math.sin(kx) <= -0.005:
		tmp = math.sin(th) * (ky / math.sqrt((0.5 - (0.5 * math.cos((kx * 2.0))))))
	elif math.sin(kx) <= 2.5e-119:
		tmp = math.sin(th)
	elif (math.sin(kx) <= 1e-98) or not (math.sin(kx) <= 2e-60):
		tmp = math.sin(th) * (math.sin(ky) / math.sin(kx))
	else:
		tmp = (math.sin(th) * ky) / ky
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (sin(kx) <= -0.005)
		tmp = Float64(sin(th) * Float64(ky / sqrt(Float64(0.5 - Float64(0.5 * cos(Float64(kx * 2.0)))))));
	elseif (sin(kx) <= 2.5e-119)
		tmp = sin(th);
	elseif ((sin(kx) <= 1e-98) || !(sin(kx) <= 2e-60))
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	else
		tmp = Float64(Float64(sin(th) * ky) / ky);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (sin(kx) <= -0.005)
		tmp = sin(th) * (ky / sqrt((0.5 - (0.5 * cos((kx * 2.0))))));
	elseif (sin(kx) <= 2.5e-119)
		tmp = sin(th);
	elseif ((sin(kx) <= 1e-98) || ~((sin(kx) <= 2e-60)))
		tmp = sin(th) * (sin(ky) / sin(kx));
	else
		tmp = (sin(th) * ky) / ky;
	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[Sqrt[N[(0.5 - N[(0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2.5e-119], N[Sin[th], $MachinePrecision], If[Or[LessEqual[N[Sin[kx], $MachinePrecision], 1e-98], N[Not[LessEqual[N[Sin[kx], $MachinePrecision], 2e-60]], $MachinePrecision]], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / ky), $MachinePrecision]]]]
\begin{array}{l}

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

\mathbf{elif}\;\sin kx \leq 2.5 \cdot 10^{-119}:\\
\;\;\;\;\sin th\\

\mathbf{elif}\;\sin kx \leq 10^{-98} \lor \neg \left(\sin kx \leq 2 \cdot 10^{-60}\right):\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \frac{\cos \color{blue}{\left(2 \cdot kx\right)}}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
      6. *-commutative98.0%

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    8. Taylor expanded in ky around 0 57.6%

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

    if -0.0050000000000000001 < (sin.f64 kx) < 2.49999999999999996e-119

    1. Initial program 82.0%

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

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

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

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

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

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

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

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

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

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

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

    if 2.49999999999999996e-119 < (sin.f64 kx) < 9.99999999999999939e-99 or 1.9999999999999999e-60 < (sin.f64 kx)

    1. Initial program 99.5%

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

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

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

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

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

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

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

    if 9.99999999999999939e-99 < (sin.f64 kx) < 1.9999999999999999e-60

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/24.4%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr24.4%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out43.1%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define43.1%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-143.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses43.1%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified43.1%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 43.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\sin th \cdot \frac{ky}{\sqrt{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2.5 \cdot 10^{-119}:\\ \;\;\;\;\sin th\\ \mathbf{elif}\;\sin kx \leq 10^{-98} \lor \neg \left(\sin kx \leq 2 \cdot 10^{-60}\right):\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot ky}{ky}\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 65.0% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-73}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\ \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)
   (* (* (sin th) ky) (sqrt (/ 1.0 (- 0.5 (* 0.5 (cos (* kx 2.0)))))))
   (if (<= (sin kx) 2e-73)
     (* (sin ky) (/ (sin th) (fabs (sin ky))))
     (* (sin th) (/ (sin ky) (sin kx))))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(kx) <= -0.005) {
		tmp = (sin(th) * ky) * sqrt((1.0 / (0.5 - (0.5 * cos((kx * 2.0))))));
	} else if (sin(kx) <= 2e-73) {
		tmp = sin(ky) * (sin(th) / fabs(sin(ky)));
	} 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 = (sin(th) * ky) * sqrt((1.0d0 / (0.5d0 - (0.5d0 * cos((kx * 2.0d0))))))
    else if (sin(kx) <= 2d-73) then
        tmp = sin(ky) * (sin(th) / abs(sin(ky)))
    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 = (Math.sin(th) * ky) * Math.sqrt((1.0 / (0.5 - (0.5 * Math.cos((kx * 2.0))))));
	} else if (Math.sin(kx) <= 2e-73) {
		tmp = Math.sin(ky) * (Math.sin(th) / Math.abs(Math.sin(ky)));
	} 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 = (math.sin(th) * ky) * math.sqrt((1.0 / (0.5 - (0.5 * math.cos((kx * 2.0))))))
	elif math.sin(kx) <= 2e-73:
		tmp = math.sin(ky) * (math.sin(th) / math.fabs(math.sin(ky)))
	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(sin(th) * ky) * sqrt(Float64(1.0 / Float64(0.5 - Float64(0.5 * cos(Float64(kx * 2.0)))))));
	elseif (sin(kx) <= 2e-73)
		tmp = Float64(sin(ky) * Float64(sin(th) / abs(sin(ky))));
	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 = (sin(th) * ky) * sqrt((1.0 / (0.5 - (0.5 * cos((kx * 2.0))))));
	elseif (sin(kx) <= 2e-73)
		tmp = sin(ky) * (sin(th) / abs(sin(ky)));
	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[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] * N[Sqrt[N[(1.0 / N[(0.5 - N[(0.5 * N[Cos[N[(kx * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Sin[kx], $MachinePrecision], 2e-73], N[(N[Sin[ky], $MachinePrecision] * N[(N[Sin[th], $MachinePrecision] / N[Abs[N[Sin[ky], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $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:\\
\;\;\;\;\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\left(0.5 - \frac{\cos \color{blue}{\left(2 \cdot kx\right)}}{2}\right) + {\sin ky}^{2}}} \cdot \sin th \]
      6. *-commutative98.0%

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    8. Taylor expanded in ky around 0 57.7%

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

    if -0.0050000000000000001 < (sin.f64 kx) < 1.99999999999999999e-73

    1. Initial program 83.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.99999999999999999e-73 < (sin.f64 kx)

    1. Initial program 99.4%

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin kx \leq -0.005:\\ \;\;\;\;\left(\sin th \cdot ky\right) \cdot \sqrt{\frac{1}{0.5 - 0.5 \cdot \cos \left(kx \cdot 2\right)}}\\ \mathbf{elif}\;\sin kx \leq 2 \cdot 10^{-73}:\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

Alternative 6: 99.6% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 65.4% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;ky \leq 1.3 \cdot 10^{+38} \lor \neg \left(ky \leq 2.2 \cdot 10^{+148}\right):\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.00350000000000000007 < ky < 1.3e38 or 2.1999999999999999e148 < ky

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\left|\sin ky\right|}} \]
    7. Applied egg-rr68.4%

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

    if 1.3e38 < ky < 2.1999999999999999e148

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 0.0035:\\ \;\;\;\;\frac{\sin th}{\frac{\mathsf{hypot}\left(ky, \sin kx\right)}{\sin ky}}\\ \mathbf{elif}\;ky \leq 1.3 \cdot 10^{+38} \lor \neg \left(ky \leq 2.2 \cdot 10^{+148}\right):\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 65.5% accurate, 1.7× speedup?

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

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

\mathbf{elif}\;ky \leq 9.2 \cdot 10^{+43} \lor \neg \left(ky \leq 7.7 \cdot 10^{+146}\right):\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

    if 0.0115 < ky < 9.200000000000001e43 or 7.7000000000000002e146 < ky

    1. Initial program 99.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\left|\sin ky\right|}} \]
    7. Applied egg-rr68.4%

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

    if 9.200000000000001e43 < ky < 7.7000000000000002e146

    1. Initial program 99.6%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 0.0115:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(ky, \sin kx\right)}\\ \mathbf{elif}\;ky \leq 9.2 \cdot 10^{+43} \lor \neg \left(ky \leq 7.7 \cdot 10^{+146}\right):\\ \;\;\;\;\sin ky \cdot \frac{\sin th}{\left|\sin ky\right|}\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\frac{\mathsf{hypot}\left(\sin kx, \sin ky\right)}{th}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 46.1% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
      4. associate-*r/21.8%

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

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

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

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

        \[\leadsto \sqrt{{\left(\sin th \cdot \color{blue}{1}\right)}^{2}} \]
      2. *-commutative21.8%

        \[\leadsto \sqrt{{\color{blue}{\left(1 \cdot \sin th\right)}}^{2}} \]
    9. Simplified21.8%

      \[\leadsto \color{blue}{\sqrt{{\left(1 \cdot \sin th\right)}^{2}}} \]

    if -0.0100000000000000002 < (sin.f64 ky) < 9.99999999999999927e-105

    1. Initial program 85.8%

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

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

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

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

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

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

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

    if 9.99999999999999927e-105 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/6.7%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr6.7%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out61.9%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define61.9%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-161.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified61.9%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 61.9%

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

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

Alternative 10: 47.8% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
      4. associate-*r/21.8%

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

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

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 ky) < 9.99999999999999927e-105

    1. Initial program 85.8%

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

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

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

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

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

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

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

    if 9.99999999999999927e-105 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/6.7%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr6.7%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out61.9%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define61.9%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-161.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified61.9%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 61.9%

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

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

Alternative 11: 47.8% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sqrt{\color{blue}{{\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)}^{2}}} \]
      4. associate-*r/21.8%

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

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

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

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

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

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

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

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

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

    if -0.0100000000000000002 < (sin.f64 ky) < 9.99999999999999927e-105

    1. Initial program 85.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 9.99999999999999927e-105 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/6.7%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr6.7%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out61.9%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define61.9%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-161.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified61.9%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 61.9%

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

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

Alternative 12: 66.4% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

    if 0.00700000000000000015 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\left|\sin ky\right|}} \]
    7. Applied egg-rr58.3%

      \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\left|\sin ky\right|}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification73.8%

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

Alternative 13: 66.4% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

    if 0.012500000000000001 < ky

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \sin ky \cdot \frac{\sin th}{\color{blue}{\left|\sin ky\right|}} \]
    7. Applied egg-rr58.3%

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

Alternative 14: 55.3% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 2.9e-73 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}}} \cdot \sin th \]
    8. Step-by-step derivation
      1. add-sqr-sqrt56.8%

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\left|\sqrt{0.5 - 0.5 \cdot \cos \left(2 \cdot kx\right)}\right|}} \cdot \sin th \]
      3. sqr-sin-a66.2%

        \[\leadsto \frac{\sin ky}{\left|\sqrt{\color{blue}{\sin kx \cdot \sin kx}}\right|} \cdot \sin th \]
      4. sqrt-unprod35.5%

        \[\leadsto \frac{\sin ky}{\left|\color{blue}{\sqrt{\sin kx} \cdot \sqrt{\sin kx}}\right|} \cdot \sin th \]
      5. add-sqr-sqrt66.2%

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

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

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

Alternative 15: 41.9% accurate, 1.7× speedup?

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

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

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


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

    1. Initial program 89.4%

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

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

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

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

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

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

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

    if 9.99999999999999927e-105 < (sin.f64 ky)

    1. Initial program 99.7%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/6.7%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr6.7%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out61.9%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define61.9%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-161.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses61.9%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified61.9%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 61.9%

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

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

Alternative 16: 27.1% accurate, 6.4× speedup?

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

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

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


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

    1. Initial program 89.6%

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

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

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

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

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

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

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

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

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

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

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

    if 4.6999999999999999e-101 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/18.6%

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

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

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out23.0%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define23.0%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-123.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses23.0%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified23.0%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in ky around 0 23.0%

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

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

Alternative 17: 26.2% accurate, 6.4× speedup?

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

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

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


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

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

    if 6.49999999999999943e-5 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\sin ky \cdot \frac{\sin th}{\sin ky}\right)} - 1} \]
      3. associate-*r/22.5%

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

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{\sin th \cdot \sin ky}}{\sin ky}\right)} - 1 \]
      5. associate-/l*22.5%

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 18: 25.6% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;kx \leq 980:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\log \left(th + 1\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= kx 980.0) (sin th) (log (+ th 1.0))))
double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 980.0) {
		tmp = sin(th);
	} else {
		tmp = log((th + 1.0));
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: tmp
    if (kx <= 980.0d0) then
        tmp = sin(th)
    else
        tmp = log((th + 1.0d0))
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double tmp;
	if (kx <= 980.0) {
		tmp = Math.sin(th);
	} else {
		tmp = Math.log((th + 1.0));
	}
	return tmp;
}
def code(kx, ky, th):
	tmp = 0
	if kx <= 980.0:
		tmp = math.sin(th)
	else:
		tmp = math.log((th + 1.0))
	return tmp
function code(kx, ky, th)
	tmp = 0.0
	if (kx <= 980.0)
		tmp = sin(th);
	else
		tmp = log(Float64(th + 1.0));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	tmp = 0.0;
	if (kx <= 980.0)
		tmp = sin(th);
	else
		tmp = log((th + 1.0));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := If[LessEqual[kx, 980.0], N[Sin[th], $MachinePrecision], N[Log[N[(th + 1.0), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 980:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if kx < 980

    1. Initial program 90.2%

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

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

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

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

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

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

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

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

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

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

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

    if 980 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\sin ky \cdot \frac{\sin th}{\sin ky}}\right)} \]
      2. associate-*r/22.0%

        \[\leadsto \log \left(e^{\color{blue}{\frac{\sin ky \cdot \sin th}{\sin ky}}}\right) \]
      3. *-commutative22.0%

        \[\leadsto \log \left(e^{\frac{\color{blue}{\sin th \cdot \sin ky}}{\sin ky}}\right) \]
      4. associate-/l*22.0%

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

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

      \[\leadsto \log \color{blue}{\left(1 + th\right)} \]
    9. Step-by-step derivation
      1. +-commutative19.3%

        \[\leadsto \log \color{blue}{\left(th + 1\right)} \]
    10. Simplified19.3%

      \[\leadsto \log \color{blue}{\left(th + 1\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 19: 25.7% accurate, 6.7× speedup?

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

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

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


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

    1. Initial program 89.8%

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

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

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

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

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

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

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

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

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

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

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

    if 2.1000000000000002e-67 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/19.4%

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

        \[\leadsto \frac{\cos \left(ky - th\right) - \cos \color{blue}{\left(th + ky\right)}}{\sin ky \cdot 2} \]
    7. Applied egg-rr19.4%

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out22.7%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define22.7%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-122.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses22.7%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified22.7%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in th around 0 19.5%

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

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

Alternative 20: 16.6% accurate, 70.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;kx \leq 10^{-86}:\\
\;\;\;\;th\\

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


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

    1. Initial program 89.7%

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.00000000000000008e-86 < kx

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\color{blue}{\frac{\cos \left(ky - th\right) - \cos \left(ky + th\right)}{2}}}{\sin ky} \]
      3. associate-/l/19.0%

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

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

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

      \[\leadsto \color{blue}{\frac{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right)\right) + 0.5 \cdot \left(\cos \left(-th\right) - \cos th\right)}{ky}} \]
    9. Step-by-step derivation
      1. distribute-lft-out22.2%

        \[\leadsto \frac{\color{blue}{0.5 \cdot \left(ky \cdot \left(\sin th - \sin \left(-th\right)\right) + \left(\cos \left(-th\right) - \cos th\right)\right)}}{ky} \]
      2. fma-define22.2%

        \[\leadsto \frac{0.5 \cdot \color{blue}{\mathsf{fma}\left(ky, \sin th - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}}{ky} \]
      3. *-lft-identity22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{1 \cdot \sin th} - \sin \left(-th\right), \cos \left(-th\right) - \cos th\right)}{ky} \]
      4. sin-neg22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{\left(-\sin th\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      5. neg-mul-122.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, 1 \cdot \sin th - \color{blue}{-1 \cdot \sin th}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      6. distribute-rgt-out--22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \color{blue}{\sin th \cdot \left(1 - -1\right)}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      7. metadata-eval22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot \color{blue}{2}, \cos \left(-th\right) - \cos th\right)}{ky} \]
      8. cos-neg22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{\cos th} - \cos th\right)}{ky} \]
      9. +-inverses22.2%

        \[\leadsto \frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, \color{blue}{0}\right)}{ky} \]
    10. Simplified22.2%

      \[\leadsto \color{blue}{\frac{0.5 \cdot \mathsf{fma}\left(ky, \sin th \cdot 2, 0\right)}{ky}} \]
    11. Taylor expanded in th around 0 19.1%

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

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

Alternative 21: 13.7% 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 92.3%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{th} \]
  7. Add Preprocessing

Reproduce

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