Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.1% → 99.7%
Time: 12.0s
Alternatives: 20
Speedup: 1.2×

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 20 alternatives:

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

Initial Program: 94.1% 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.2× speedup?

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

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

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

    \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    2. unpow2N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    4. lower-hypot.f64N/A

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
    5. lower-sin.f64N/A

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

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

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

Alternative 2: 85.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ t_3 := {\sin kx}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_4 \leq -0.99975:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq -0.5:\\ \;\;\;\;t\_2 \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \mathbf{elif}\;t\_4 \leq 10^{-9}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{t\_3}}\right)\\ \mathbf{elif}\;t\_4 \leq 0.9995:\\ \;\;\;\;t\_2 \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* (sin th) (/ (sin ky) (hypot kx (sin ky)))))
        (t_2 (/ (sin ky) (hypot (sin ky) (sin kx))))
        (t_3 (pow (sin kx) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ t_3 (pow (sin ky) 2.0))))))
   (if (<= t_4 -0.99975)
     t_1
     (if (<= t_4 -0.5)
       (* t_2 (fma th (* -0.16666666666666666 (* th th)) th))
       (if (<= t_4 1e-9)
         (* (sin th) (* (sin ky) (sqrt (/ 1.0 t_3))))
         (if (<= t_4 0.9995)
           (*
            t_2
            (fma
             th
             (*
              (* th th)
              (fma 0.008333333333333333 (* th th) -0.16666666666666666))
             th))
           t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(th) * (sin(ky) / hypot(kx, sin(ky)));
	double t_2 = sin(ky) / hypot(sin(ky), sin(kx));
	double t_3 = pow(sin(kx), 2.0);
	double t_4 = sin(ky) / sqrt((t_3 + pow(sin(ky), 2.0)));
	double tmp;
	if (t_4 <= -0.99975) {
		tmp = t_1;
	} else if (t_4 <= -0.5) {
		tmp = t_2 * fma(th, (-0.16666666666666666 * (th * th)), th);
	} else if (t_4 <= 1e-9) {
		tmp = sin(th) * (sin(ky) * sqrt((1.0 / t_3)));
	} else if (t_4 <= 0.9995) {
		tmp = t_2 * fma(th, ((th * th) * fma(0.008333333333333333, (th * th), -0.16666666666666666)), th);
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(th) * Float64(sin(ky) / hypot(kx, sin(ky))))
	t_2 = Float64(sin(ky) / hypot(sin(ky), sin(kx)))
	t_3 = sin(kx) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64(t_3 + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_4 <= -0.99975)
		tmp = t_1;
	elseif (t_4 <= -0.5)
		tmp = Float64(t_2 * fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th));
	elseif (t_4 <= 1e-9)
		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(1.0 / t_3))));
	elseif (t_4 <= 0.9995)
		tmp = Float64(t_2 * fma(th, Float64(Float64(th * th) * fma(0.008333333333333333, Float64(th * th), -0.16666666666666666)), th));
	else
		tmp = t_1;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$3 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.99975], t$95$1, If[LessEqual[t$95$4, -0.5], N[(t$95$2 * N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 1e-9], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(1.0 / t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.9995], N[(t$95$2 * N[(th * N[(N[(th * th), $MachinePrecision] * N[(0.008333333333333333 * N[(th * th), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\
t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\
t_3 := {\sin kx}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_4 \leq -0.99975:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_4 \leq -0.5:\\
\;\;\;\;t\_2 \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\

\mathbf{elif}\;t\_4 \leq 10^{-9}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{t\_3}}\right)\\

\mathbf{elif}\;t\_4 \leq 0.9995:\\
\;\;\;\;t\_2 \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.999750000000000028 or 0.99950000000000006 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 75.2%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

    if -0.999750000000000028 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.5

    1. Initial program 99.7%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

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

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

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

    if -0.5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.00000000000000006e-9

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      2. lower-sin.f64N/A

        \[\leadsto \left(\color{blue}{\sin ky} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\sin ky \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      4. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      5. lower-+.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      7. lower-sin.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      8. lower-pow.f64N/A

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

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

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

      \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
      2. lower-pow.f64N/A

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

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

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

    if 1.00000000000000006e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.99950000000000006

    1. Initial program 99.2%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \color{blue}{\left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right) + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\mathsf{fma}\left(th, {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \color{blue}{{th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      7. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      8. sub-negN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {th}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, th\right) \]
      9. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \left(\frac{1}{120} \cdot {th}^{2} + \color{blue}{\frac{-1}{6}}\right), th\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {th}^{2}, \frac{-1}{6}\right)}, th\right) \]
      11. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{th \cdot th}, \frac{-1}{6}\right), th\right) \]
      12. lower-*.f6448.0

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{th \cdot th}, -0.16666666666666666\right), th\right) \]
    8. Simplified48.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.99975:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.5:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-9}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2}}}\right)\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.9995:\\ \;\;\;\;\frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 85.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ t_3 := {\sin kx}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_4 \leq -0.99975:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq -0.5:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_4 \leq 10^{-9}:\\ \;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{t\_3}}\right)\\ \mathbf{elif}\;t\_4 \leq 0.9995:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* (sin th) (/ (sin ky) (hypot kx (sin ky)))))
        (t_2
         (*
          (/ (sin ky) (hypot (sin ky) (sin kx)))
          (fma th (* -0.16666666666666666 (* th th)) th)))
        (t_3 (pow (sin kx) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ t_3 (pow (sin ky) 2.0))))))
   (if (<= t_4 -0.99975)
     t_1
     (if (<= t_4 -0.5)
       t_2
       (if (<= t_4 1e-9)
         (* (sin th) (* (sin ky) (sqrt (/ 1.0 t_3))))
         (if (<= t_4 0.9995) t_2 t_1))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(th) * (sin(ky) / hypot(kx, sin(ky)));
	double t_2 = (sin(ky) / hypot(sin(ky), sin(kx))) * fma(th, (-0.16666666666666666 * (th * th)), th);
	double t_3 = pow(sin(kx), 2.0);
	double t_4 = sin(ky) / sqrt((t_3 + pow(sin(ky), 2.0)));
	double tmp;
	if (t_4 <= -0.99975) {
		tmp = t_1;
	} else if (t_4 <= -0.5) {
		tmp = t_2;
	} else if (t_4 <= 1e-9) {
		tmp = sin(th) * (sin(ky) * sqrt((1.0 / t_3)));
	} else if (t_4 <= 0.9995) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(th) * Float64(sin(ky) / hypot(kx, sin(ky))))
	t_2 = Float64(Float64(sin(ky) / hypot(sin(ky), sin(kx))) * fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th))
	t_3 = sin(kx) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64(t_3 + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_4 <= -0.99975)
		tmp = t_1;
	elseif (t_4 <= -0.5)
		tmp = t_2;
	elseif (t_4 <= 1e-9)
		tmp = Float64(sin(th) * Float64(sin(ky) * sqrt(Float64(1.0 / t_3))));
	elseif (t_4 <= 0.9995)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$3 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.99975], t$95$1, If[LessEqual[t$95$4, -0.5], t$95$2, If[LessEqual[t$95$4, 1e-9], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[Sqrt[N[(1.0 / t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.9995], t$95$2, t$95$1]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\
t_2 := \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\
t_3 := {\sin kx}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{t\_3 + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_4 \leq -0.99975:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_4 \leq -0.5:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_4 \leq 10^{-9}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{t\_3}}\right)\\

\mathbf{elif}\;t\_4 \leq 0.9995:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.999750000000000028 or 0.99950000000000006 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 75.2%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

    if -0.999750000000000028 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.5 or 1.00000000000000006e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.99950000000000006

    1. Initial program 99.5%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

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

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

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

    if -0.5 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.00000000000000006e-9

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      2. lower-sin.f64N/A

        \[\leadsto \left(\color{blue}{\sin ky} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\sin ky \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      4. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      5. lower-+.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      7. lower-sin.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      8. lower-pow.f64N/A

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

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

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

      \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
      2. lower-pow.f64N/A

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

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

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

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

Alternative 4: 76.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ t_2 := {\sin kx}^{2}\\ t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_3 \leq -0.2:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_3 \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\sqrt{t\_2 + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}\\ \mathbf{elif}\;t\_3 \leq 0.9995:\\ \;\;\;\;\left(\sin ky \cdot \sin th\right) \cdot \frac{1}{\sin ky}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (* (sin th) (/ (sin ky) (hypot kx (sin ky)))))
        (t_2 (pow (sin kx) 2.0))
        (t_3 (/ (sin ky) (sqrt (+ t_2 (pow (sin ky) 2.0))))))
   (if (<= t_3 -0.2)
     t_1
     (if (<= t_3 0.001)
       (*
        (sin th)
        (/
         (fma ky (* -0.16666666666666666 (* ky ky)) ky)
         (sqrt (+ t_2 (* ky (fma ky (* (* ky ky) -0.3333333333333333) ky))))))
       (if (<= t_3 0.9995) (* (* (sin ky) (sin th)) (/ 1.0 (sin ky))) t_1)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(th) * (sin(ky) / hypot(kx, sin(ky)));
	double t_2 = pow(sin(kx), 2.0);
	double t_3 = sin(ky) / sqrt((t_2 + pow(sin(ky), 2.0)));
	double tmp;
	if (t_3 <= -0.2) {
		tmp = t_1;
	} else if (t_3 <= 0.001) {
		tmp = sin(th) * (fma(ky, (-0.16666666666666666 * (ky * ky)), ky) / sqrt((t_2 + (ky * fma(ky, ((ky * ky) * -0.3333333333333333), ky)))));
	} else if (t_3 <= 0.9995) {
		tmp = (sin(ky) * sin(th)) * (1.0 / sin(ky));
	} else {
		tmp = t_1;
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(th) * Float64(sin(ky) / hypot(kx, sin(ky))))
	t_2 = sin(kx) ^ 2.0
	t_3 = Float64(sin(ky) / sqrt(Float64(t_2 + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_3 <= -0.2)
		tmp = t_1;
	elseif (t_3 <= 0.001)
		tmp = Float64(sin(th) * Float64(fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky) / sqrt(Float64(t_2 + Float64(ky * fma(ky, Float64(Float64(ky * ky) * -0.3333333333333333), ky))))));
	elseif (t_3 <= 0.9995)
		tmp = Float64(Float64(sin(ky) * sin(th)) * Float64(1.0 / sin(ky)));
	else
		tmp = t_1;
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.2], t$95$1, If[LessEqual[t$95$3, 0.001], N[(N[Sin[th], $MachinePrecision] * N[(N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision] / N[Sqrt[N[(t$95$2 + N[(ky * N[(ky * N[(N[(ky * ky), $MachinePrecision] * -0.3333333333333333), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 0.9995], N[(N[(N[Sin[ky], $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sin[ky], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\
t_2 := {\sin kx}^{2}\\
t_3 := \frac{\sin ky}{\sqrt{t\_2 + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_3 \leq -0.2:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_3 \leq 0.001:\\
\;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\sqrt{t\_2 + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}\\

\mathbf{elif}\;t\_3 \leq 0.9995:\\
\;\;\;\;\left(\sin ky \cdot \sin th\right) \cdot \frac{1}{\sin ky}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001 or 0.99950000000000006 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 80.7%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

    if -0.20000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2} \cdot \left(1 + \frac{-1}{3} \cdot {ky}^{2}\right)}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot \left(ky \cdot \left(1 + \frac{-1}{3} \cdot {ky}^{2}\right)\right)}}} \cdot \sin th \]
      3. lower-*.f64N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \left(ky \cdot \color{blue}{\left(\frac{-1}{3} \cdot {ky}^{2} + 1\right)}\right)}} \cdot \sin th \]
      5. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \color{blue}{\left(ky \cdot \left(\frac{-1}{3} \cdot {ky}^{2}\right) + ky \cdot 1\right)}}} \cdot \sin th \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \left(ky \cdot \left(\frac{-1}{3} \cdot {ky}^{2}\right) + \color{blue}{ky}\right)}} \cdot \sin th \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \color{blue}{\mathsf{fma}\left(ky, \frac{-1}{3} \cdot {ky}^{2}, ky\right)}}} \cdot \sin th \]
      8. *-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{3}}, ky\right)}} \cdot \sin th \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{3}}, ky\right)}} \cdot \sin th \]
      10. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      11. lower-*.f6499.6

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}} \cdot \sin th \]
    6. Taylor expanded in ky around 0

      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      8. lower-*.f6499.6

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot -0.16666666666666666, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}} \cdot \sin th \]
    8. Simplified99.6%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.16666666666666666, ky\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}} \cdot \sin th \]

    if 1e-3 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.99950000000000006

    1. Initial program 99.2%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \left(\color{blue}{\sin th} \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      5. lower-sin.f64N/A

        \[\leadsto \left(\sin th \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      6. lower-sqrt.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      7. lower-/.f64N/A

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

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      9. lower-pow.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
      10. lower-sin.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \]
      11. lower-pow.f64N/A

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

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

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

      \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \color{blue}{\frac{1}{\sin ky}} \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq -0.2:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}\\ \mathbf{elif}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.9995:\\ \;\;\;\;\left(\sin ky \cdot \sin th\right) \cdot \frac{1}{\sin ky}\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 66.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\\ t_2 := {\sin kx}^{2}\\ t_3 := {\sin ky}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{t\_2 + t\_3}}\\ \mathbf{if}\;t\_4 \leq -0.2:\\ \;\;\;\;th \cdot \left(\sqrt{\frac{1}{t\_3}} \cdot \left(\sin ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)\right)\right)\\ \mathbf{elif}\;t\_4 \leq 0.001:\\ \;\;\;\;\sin th \cdot \frac{t\_1}{\sqrt{t\_2 + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}\\ \mathbf{elif}\;t\_4 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{t\_1}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (fma ky (* -0.16666666666666666 (* ky ky)) ky))
        (t_2 (pow (sin kx) 2.0))
        (t_3 (pow (sin ky) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ t_2 t_3)))))
   (if (<= t_4 -0.2)
     (*
      th
      (*
       (sqrt (/ 1.0 t_3))
       (* (sin ky) (fma -0.16666666666666666 (* th th) 1.0))))
     (if (<= t_4 0.001)
       (*
        (sin th)
        (/
         t_1
         (sqrt (+ t_2 (* ky (fma ky (* (* ky ky) -0.3333333333333333) ky))))))
       (if (<= t_4 2.0) (sin th) (* (sin th) (/ t_1 (hypot kx (sin ky)))))))))
double code(double kx, double ky, double th) {
	double t_1 = fma(ky, (-0.16666666666666666 * (ky * ky)), ky);
	double t_2 = pow(sin(kx), 2.0);
	double t_3 = pow(sin(ky), 2.0);
	double t_4 = sin(ky) / sqrt((t_2 + t_3));
	double tmp;
	if (t_4 <= -0.2) {
		tmp = th * (sqrt((1.0 / t_3)) * (sin(ky) * fma(-0.16666666666666666, (th * th), 1.0)));
	} else if (t_4 <= 0.001) {
		tmp = sin(th) * (t_1 / sqrt((t_2 + (ky * fma(ky, ((ky * ky) * -0.3333333333333333), ky)))));
	} else if (t_4 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (t_1 / hypot(kx, sin(ky)));
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky)
	t_2 = sin(kx) ^ 2.0
	t_3 = sin(ky) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64(t_2 + t_3)))
	tmp = 0.0
	if (t_4 <= -0.2)
		tmp = Float64(th * Float64(sqrt(Float64(1.0 / t_3)) * Float64(sin(ky) * fma(-0.16666666666666666, Float64(th * th), 1.0))));
	elseif (t_4 <= 0.001)
		tmp = Float64(sin(th) * Float64(t_1 / sqrt(Float64(t_2 + Float64(ky * fma(ky, Float64(Float64(ky * ky) * -0.3333333333333333), ky))))));
	elseif (t_4 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(t_1 / hypot(kx, sin(ky))));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision]}, Block[{t$95$2 = N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$3 = N[Power[N[Sin[ky], $MachinePrecision], 2.0], $MachinePrecision]}, Block[{t$95$4 = N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(t$95$2 + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.2], N[(th * N[(N[Sqrt[N[(1.0 / t$95$3), $MachinePrecision]], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.001], N[(N[Sin[th], $MachinePrecision] * N[(t$95$1 / N[Sqrt[N[(t$95$2 + N[(ky * N[(ky * N[(N[(ky * ky), $MachinePrecision] * -0.3333333333333333), $MachinePrecision] + ky), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(t$95$1 / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)\\
t_2 := {\sin kx}^{2}\\
t_3 := {\sin ky}^{2}\\
t_4 := \frac{\sin ky}{\sqrt{t\_2 + t\_3}}\\
\mathbf{if}\;t\_4 \leq -0.2:\\
\;\;\;\;th \cdot \left(\sqrt{\frac{1}{t\_3}} \cdot \left(\sin ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right)\right)\right)\\

\mathbf{elif}\;t\_4 \leq 0.001:\\
\;\;\;\;\sin th \cdot \frac{t\_1}{\sqrt{t\_2 + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}\\

\mathbf{elif}\;t\_4 \leq 2:\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.20000000000000001

    1. Initial program 87.0%

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

      \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot \left(\left({th}^{2} \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right) + \sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} + \frac{-1}{6} \cdot \left(\left({th}^{2} \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)\right)} \]
      2. *-commutativeN/A

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

        \[\leadsto th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} + \color{blue}{\left({th}^{2} \cdot \left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)\right)} \cdot \frac{-1}{6}\right) \]
      4. associate-*r*N/A

        \[\leadsto th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} + \color{blue}{{th}^{2} \cdot \left(\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right) \cdot \frac{-1}{6}\right)}\right) \]
      5. *-commutativeN/A

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

      \[\leadsto \color{blue}{th \cdot \left(\sqrt{\frac{1}{{\sin ky}^{2} + {\sin kx}^{2}}} \cdot \left(\mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right) \cdot \sin ky\right)\right)} \]
    6. Taylor expanded in kx around 0

      \[\leadsto th \cdot \left(\sqrt{\color{blue}{\frac{1}{{\sin ky}^{2}}}} \cdot \left(\mathsf{fma}\left(\frac{-1}{6}, th \cdot th, 1\right) \cdot \sin ky\right)\right) \]
    7. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto th \cdot \left(\sqrt{\color{blue}{\frac{1}{{\sin ky}^{2}}}} \cdot \left(\mathsf{fma}\left(\frac{-1}{6}, th \cdot th, 1\right) \cdot \sin ky\right)\right) \]
      2. lower-pow.f64N/A

        \[\leadsto th \cdot \left(\sqrt{\frac{1}{\color{blue}{{\sin ky}^{2}}}} \cdot \left(\mathsf{fma}\left(\frac{-1}{6}, th \cdot th, 1\right) \cdot \sin ky\right)\right) \]
      3. lower-sin.f6431.2

        \[\leadsto th \cdot \left(\sqrt{\frac{1}{{\color{blue}{\sin ky}}^{2}}} \cdot \left(\mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right) \cdot \sin ky\right)\right) \]
    8. Simplified31.2%

      \[\leadsto th \cdot \left(\sqrt{\color{blue}{\frac{1}{{\sin ky}^{2}}}} \cdot \left(\mathsf{fma}\left(-0.16666666666666666, th \cdot th, 1\right) \cdot \sin ky\right)\right) \]

    if -0.20000000000000001 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{{ky}^{2} \cdot \left(1 + \frac{-1}{3} \cdot {ky}^{2}\right)}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot \left(ky \cdot \left(1 + \frac{-1}{3} \cdot {ky}^{2}\right)\right)}}} \cdot \sin th \]
      3. lower-*.f64N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \left(ky \cdot \color{blue}{\left(\frac{-1}{3} \cdot {ky}^{2} + 1\right)}\right)}} \cdot \sin th \]
      5. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \color{blue}{\left(ky \cdot \left(\frac{-1}{3} \cdot {ky}^{2}\right) + ky \cdot 1\right)}}} \cdot \sin th \]
      6. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \left(ky \cdot \left(\frac{-1}{3} \cdot {ky}^{2}\right) + \color{blue}{ky}\right)}} \cdot \sin th \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \color{blue}{\mathsf{fma}\left(ky, \frac{-1}{3} \cdot {ky}^{2}, ky\right)}}} \cdot \sin th \]
      8. *-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{3}}, ky\right)}} \cdot \sin th \]
      9. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{3}}, ky\right)}} \cdot \sin th \]
      10. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      11. lower-*.f6499.6

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

      \[\leadsto \frac{\sin ky}{\sqrt{{\sin kx}^{2} + \color{blue}{ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}}} \cdot \sin th \]
    6. Taylor expanded in ky around 0

      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot \frac{-1}{3}, ky\right)}} \cdot \sin th \]
      8. lower-*.f6499.6

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot -0.16666666666666666, ky\right)}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}} \cdot \sin th \]
    8. Simplified99.6%

      \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.16666666666666666, ky\right)}}{\sqrt{{\sin kx}^{2} + ky \cdot \mathsf{fma}\left(ky, \left(ky \cdot ky\right) \cdot -0.3333333333333333, ky\right)}} \cdot \sin th \]

    if 1e-3 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

    1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6465.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified65.4%

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

    if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 2.4%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      8. lower-*.f64100.0

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

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

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

Alternative 6: 55.6% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.98:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;t\_1 \leq 0.15:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{elif}\;t\_1 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)}\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.98)
     (*
      (fma th (* -0.16666666666666666 (* th th)) th)
      (/ (sin ky) (hypot (sin ky) kx)))
     (if (<= t_1 0.15)
       (* (sin th) (/ (sin ky) (sin kx)))
       (if (<= t_1 2.0)
         (sin th)
         (*
          (sin th)
          (/
           (fma ky (* -0.16666666666666666 (* ky ky)) ky)
           (hypot kx (sin ky)))))))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.98) {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th) * (sin(ky) / hypot(sin(ky), kx));
	} else if (t_1 <= 0.15) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else if (t_1 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = sin(th) * (fma(ky, (-0.16666666666666666 * (ky * ky)), ky) / hypot(kx, sin(ky)));
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= -0.98)
		tmp = Float64(fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	elseif (t_1 <= 0.15)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	elseif (t_1 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(sin(th) * Float64(fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky) / hypot(kx, sin(ky))));
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, -0.98], N[(N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.15], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2.0], N[Sin[th], $MachinePrecision], N[(N[Sin[th], $MachinePrecision] * N[(N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision] / N[Sqrt[kx ^ 2 + N[Sin[ky], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_1 \leq -0.98:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.97999999999999998

    1. Initial program 79.7%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in th around 0

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6442.0

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified42.0%

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {kx}^{2}}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {kx}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      3. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{kx \cdot kx}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      5. lower-sin.f6452.4

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

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

    if -0.97999999999999998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.149999999999999994

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. lower-sin.f6448.0

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Simplified48.0%

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

    if 0.149999999999999994 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 2

    1. Initial program 99.0%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6466.1

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified66.1%

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

    if 2 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 2.4%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right)}{\mathsf{hypot}\left(kx, \sin ky\right)} \cdot \sin th \]
      8. lower-*.f64100.0

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

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

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

Alternative 7: 54.4% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ \mathbf{if}\;t\_1 \leq -0.98:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\ \mathbf{elif}\;t\_1 \leq 0.15:\\ \;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0))))))
   (if (<= t_1 -0.98)
     (*
      (fma th (* -0.16666666666666666 (* th th)) th)
      (/ (sin ky) (hypot (sin ky) kx)))
     (if (<= t_1 0.15) (* (sin th) (/ (sin ky) (sin kx))) (sin th)))))
double code(double kx, double ky, double th) {
	double t_1 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.98) {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th) * (sin(ky) / hypot(sin(ky), kx));
	} else if (t_1 <= 0.15) {
		tmp = sin(th) * (sin(ky) / sin(kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	tmp = 0.0
	if (t_1 <= -0.98)
		tmp = Float64(fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th) * Float64(sin(ky) / hypot(sin(ky), kx)));
	elseif (t_1 <= 0.15)
		tmp = Float64(sin(th) * Float64(sin(ky) / sin(kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := Block[{t$95$1 = 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]}, If[LessEqual[t$95$1, -0.98], N[(N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + kx ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.15], N[(N[Sin[th], $MachinePrecision] * N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\
\mathbf{if}\;t\_1 \leq -0.98:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \cdot \frac{\sin ky}{\mathsf{hypot}\left(\sin ky, kx\right)}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < -0.97999999999999998

    1. Initial program 79.7%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in th around 0

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6442.0

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified42.0%

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {kx}^{2}}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {kx}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      3. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{kx \cdot kx}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, kx\right)}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      5. lower-sin.f6452.4

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

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

    if -0.97999999999999998 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.149999999999999994

    1. Initial program 99.6%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. lower-sin.f6448.0

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Simplified48.0%

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

    if 0.149999999999999994 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.3%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6462.6

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified62.6%

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

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

Alternative 8: 45.7% accurate, 0.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.15:\\
\;\;\;\;\sin th \cdot \frac{\sin ky}{\sin kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 0.149999999999999994

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    4. Step-by-step derivation
      1. lower-sin.f6436.9

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

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

    if 0.149999999999999994 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.3%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6462.6

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified62.6%

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

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

Alternative 9: 44.5% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.001:\\
\;\;\;\;\sin th \cdot \frac{ky}{\sin kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1e-3

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
    7. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{ky}{\sin kx}} \cdot \sin th \]
      2. lower-sin.f6435.2

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

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

    if 1e-3 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.5%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6462.1

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified62.1%

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

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

Alternative 10: 36.4% accurate, 0.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\sin ky \cdot \frac{\sin th}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\color{blue}{kx + \frac{1}{2} \cdot \frac{{ky}^{2}}{kx}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{2} \cdot \frac{{ky}^{2}}{kx} + kx}} \cdot \sin th \]
      2. *-commutativeN/A

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{{ky}^{2} \cdot \frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      4. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{{ky}^{2} \cdot \frac{\frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      5. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \frac{\color{blue}{\frac{1}{2} \cdot 1}}{kx} + kx} \cdot \sin th \]
      6. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{kx}\right)} + kx} \cdot \sin th \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)}} \cdot \sin th \]
      8. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)} \cdot \sin th \]
      9. lower-*.f64N/A

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

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \color{blue}{\frac{\frac{1}{2} \cdot 1}{kx}}, kx\right)} \cdot \sin th \]
      11. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \frac{\color{blue}{\frac{1}{2}}}{kx}, kx\right)} \cdot \sin th \]
      12. lower-/.f6425.0

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left(ky \cdot ky, \frac{0.5}{kx}, kx\right)}} \cdot \sin th \]
    9. Taylor expanded in kx around inf

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

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      2. lower-*.f64N/A

        \[\leadsto \color{blue}{\sin ky \cdot \frac{\sin th}{kx}} \]
      3. lower-sin.f64N/A

        \[\leadsto \color{blue}{\sin ky} \cdot \frac{\sin th}{kx} \]
      4. lower-/.f64N/A

        \[\leadsto \sin ky \cdot \color{blue}{\frac{\sin th}{kx}} \]
      5. lower-sin.f6425.2

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

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

    if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.7%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6461.5

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified61.5%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 35.9% accurate, 0.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{0.5}{kx}, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-9)
   (*
    (sin th)
    (/
     (fma ky (* -0.16666666666666666 (* ky ky)) ky)
     (fma (* ky ky) (/ 0.5 kx) kx)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-9) {
		tmp = sin(th) * (fma(ky, (-0.16666666666666666 * (ky * ky)), ky) / fma((ky * ky), (0.5 / kx), kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
		tmp = Float64(sin(th) * Float64(fma(ky, Float64(-0.16666666666666666 * Float64(ky * ky)), ky) / fma(Float64(ky * ky), Float64(0.5 / kx), kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[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], 5e-9], N[(N[Sin[th], $MachinePrecision] * N[(N[(ky * N[(-0.16666666666666666 * N[(ky * ky), $MachinePrecision]), $MachinePrecision] + ky), $MachinePrecision] / N[(N[(ky * ky), $MachinePrecision] * N[(0.5 / kx), $MachinePrecision] + kx), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{0.5}{kx}, kx\right)}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\color{blue}{kx + \frac{1}{2} \cdot \frac{{ky}^{2}}{kx}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{2} \cdot \frac{{ky}^{2}}{kx} + kx}} \cdot \sin th \]
      2. *-commutativeN/A

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{{ky}^{2} \cdot \frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      4. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{{ky}^{2} \cdot \frac{\frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      5. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \frac{\color{blue}{\frac{1}{2} \cdot 1}}{kx} + kx} \cdot \sin th \]
      6. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{kx}\right)} + kx} \cdot \sin th \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)}} \cdot \sin th \]
      8. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)} \cdot \sin th \]
      9. lower-*.f64N/A

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

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \color{blue}{\frac{\frac{1}{2} \cdot 1}{kx}}, kx\right)} \cdot \sin th \]
      11. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \frac{\color{blue}{\frac{1}{2}}}{kx}, kx\right)} \cdot \sin th \]
      12. lower-/.f6425.0

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

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

      \[\leadsto \frac{\color{blue}{ky \cdot \left(1 + \frac{-1}{6} \cdot {ky}^{2}\right)}}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {ky}^{2} + 1\right)}}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + ky \cdot 1}}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{ky \cdot \left(\frac{-1}{6} \cdot {ky}^{2}\right) + \color{blue}{ky}}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\color{blue}{\mathsf{fma}\left(ky, \frac{-1}{6} \cdot {ky}^{2}, ky\right)}}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      5. *-commutativeN/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{{ky}^{2} \cdot \frac{-1}{6}}, ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      7. unpow2N/A

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot \frac{-1}{6}, ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{\frac{1}{2}}{kx}, kx\right)} \cdot \sin th \]
      8. lower-*.f6424.3

        \[\leadsto \frac{\mathsf{fma}\left(ky, \color{blue}{\left(ky \cdot ky\right)} \cdot -0.16666666666666666, ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{0.5}{kx}, kx\right)} \cdot \sin th \]
    11. Simplified24.3%

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

    if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.7%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6461.5

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified61.5%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;\sin th \cdot \frac{\mathsf{fma}\left(ky, -0.16666666666666666 \cdot \left(ky \cdot ky\right), ky\right)}{\mathsf{fma}\left(ky \cdot ky, \frac{0.5}{kx}, kx\right)}\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 15.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-317}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<=
      (*
       (sin th)
       (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
      1e-317)
   (* -0.16666666666666666 (* th (* th th)))
   (fma
    th
    (* (* th th) (fma 0.008333333333333333 (* th th) -0.16666666666666666))
    th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(th) * (sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0))))) <= 1e-317) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = fma(th, ((th * th) * fma(0.008333333333333333, (th * th), -0.16666666666666666)), th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(th) * Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))) <= 1e-317)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = fma(th, Float64(Float64(th * th) * fma(0.008333333333333333, Float64(th * th), -0.16666666666666666)), th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[(N[Sin[th], $MachinePrecision] * 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]), $MachinePrecision], 1e-317], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th * N[(N[(th * th), $MachinePrecision] * N[(0.008333333333333333 * N[(th * th), $MachinePrecision] + -0.16666666666666666), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-317}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th)) < 1.00000023e-317

    1. Initial program 92.8%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6418.3

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified18.3%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6411.5

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified11.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in th around inf

      \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
      2. cube-multN/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot \left(th \cdot th\right)\right)} \]
      3. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{{th}^{2}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot {th}^{2}\right)} \]
      5. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      6. lower-*.f6418.0

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified18.0%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

    if 1.00000023e-317 < (*.f64 (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) (sin.f64 th))

    1. Initial program 85.8%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6429.4

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified29.4%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right) + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left({th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, {th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{{th}^{2} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right)}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      7. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\left(th \cdot th\right)} \cdot \left(\frac{1}{120} \cdot {th}^{2} - \frac{1}{6}\right), th\right) \]
      8. sub-negN/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\left(\frac{1}{120} \cdot {th}^{2} + \left(\mathsf{neg}\left(\frac{1}{6}\right)\right)\right)}, th\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \left(\frac{1}{120} \cdot {th}^{2} + \color{blue}{\frac{-1}{6}}\right), th\right) \]
      10. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \color{blue}{\mathsf{fma}\left(\frac{1}{120}, {th}^{2}, \frac{-1}{6}\right)}, th\right) \]
      11. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(\frac{1}{120}, \color{blue}{th \cdot th}, \frac{-1}{6}\right), th\right) \]
      12. lower-*.f6420.6

        \[\leadsto \mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, \color{blue}{th \cdot th}, -0.16666666666666666\right), th\right) \]
    8. Simplified20.6%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification19.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\sin th \cdot \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-317}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, \left(th \cdot th\right) \cdot \mathsf{fma}\left(0.008333333333333333, th \cdot th, -0.16666666666666666\right), th\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 36.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;\sin th \cdot \frac{ky}{kx}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around 0

      \[\leadsto \frac{\sin ky}{\color{blue}{kx + \frac{1}{2} \cdot \frac{{ky}^{2}}{kx}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{1}{2} \cdot \frac{{ky}^{2}}{kx} + kx}} \cdot \sin th \]
      2. *-commutativeN/A

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

        \[\leadsto \frac{\sin ky}{\color{blue}{\frac{{ky}^{2} \cdot \frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      4. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{{ky}^{2} \cdot \frac{\frac{1}{2}}{kx}} + kx} \cdot \sin th \]
      5. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \frac{\color{blue}{\frac{1}{2} \cdot 1}}{kx} + kx} \cdot \sin th \]
      6. associate-*r/N/A

        \[\leadsto \frac{\sin ky}{{ky}^{2} \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{1}{kx}\right)} + kx} \cdot \sin th \]
      7. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left({ky}^{2}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)}} \cdot \sin th \]
      8. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(\color{blue}{ky \cdot ky}, \frac{1}{2} \cdot \frac{1}{kx}, kx\right)} \cdot \sin th \]
      9. lower-*.f64N/A

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

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \color{blue}{\frac{\frac{1}{2} \cdot 1}{kx}}, kx\right)} \cdot \sin th \]
      11. metadata-evalN/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(ky \cdot ky, \frac{\color{blue}{\frac{1}{2}}}{kx}, kx\right)} \cdot \sin th \]
      12. lower-/.f6425.0

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

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

      \[\leadsto \color{blue}{\frac{ky}{kx}} \cdot \sin th \]
    10. Step-by-step derivation
      1. lower-/.f6424.6

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

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

    if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.7%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6461.5

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified61.5%

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

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

Alternative 14: 32.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-9)
   (* ky (fma -0.16666666666666666 (/ (* th (* th th)) kx) (/ th kx)))
   (sin th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-9) {
		tmp = ky * fma(-0.16666666666666666, ((th * (th * th)) / kx), (th / kx));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
		tmp = Float64(ky * fma(-0.16666666666666666, Float64(Float64(th * Float64(th * th)) / kx), Float64(th / kx)));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[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], 5e-9], N[(ky * N[(-0.16666666666666666 * N[(N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision] / kx), $MachinePrecision] + N[(th / kx), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in th around 0

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6435.8

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

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{ky \cdot \left(\frac{-1}{6} \cdot \frac{{th}^{3}}{kx} + \frac{th}{kx}\right)} \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{ky \cdot \left(\frac{-1}{6} \cdot \frac{{th}^{3}}{kx} + \frac{th}{kx}\right)} \]
      2. lower-fma.f64N/A

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, \frac{{th}^{3}}{kx}, \frac{th}{kx}\right)} \]
      3. lower-/.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{\frac{{th}^{3}}{kx}}, \frac{th}{kx}\right) \]
      4. cube-multN/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{\color{blue}{th \cdot \left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      5. unpow2N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{{th}^{2}}}{kx}, \frac{th}{kx}\right) \]
      6. lower-*.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{\color{blue}{th \cdot {th}^{2}}}{kx}, \frac{th}{kx}\right) \]
      7. unpow2N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{\left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      8. lower-*.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{\left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      9. lower-/.f6422.2

        \[\leadsto ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \color{blue}{\frac{th}{kx}}\right) \]
    11. Simplified22.2%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)} \]

    if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.7%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6461.5

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified61.5%

      \[\leadsto \color{blue}{\sin th} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 22.8% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\ \;\;\;\;ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 5e-9)
   (* ky (fma -0.16666666666666666 (/ (* th (* th th)) kx) (/ th kx)))
   (fma th (* -0.16666666666666666 (* th th)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 5e-9) {
		tmp = ky * fma(-0.16666666666666666, ((th * (th * th)) / kx), (th / kx));
	} else {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 5e-9)
		tmp = Float64(ky * fma(-0.16666666666666666, Float64(Float64(th * Float64(th * th)) / kx), Float64(th / kx)));
	else
		tmp = fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[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], 5e-9], N[(ky * N[(-0.16666666666666666 * N[(N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision] / kx), $MachinePrecision] + N[(th / kx), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 5 \cdot 10^{-9}:\\
\;\;\;\;ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 5.0000000000000001e-9

    1. Initial program 94.1%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in th around 0

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6435.8

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

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{ky \cdot \left(\frac{-1}{6} \cdot \frac{{th}^{3}}{kx} + \frac{th}{kx}\right)} \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{ky \cdot \left(\frac{-1}{6} \cdot \frac{{th}^{3}}{kx} + \frac{th}{kx}\right)} \]
      2. lower-fma.f64N/A

        \[\leadsto ky \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, \frac{{th}^{3}}{kx}, \frac{th}{kx}\right)} \]
      3. lower-/.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{\frac{{th}^{3}}{kx}}, \frac{th}{kx}\right) \]
      4. cube-multN/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{\color{blue}{th \cdot \left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      5. unpow2N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{{th}^{2}}}{kx}, \frac{th}{kx}\right) \]
      6. lower-*.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{\color{blue}{th \cdot {th}^{2}}}{kx}, \frac{th}{kx}\right) \]
      7. unpow2N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{\left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      8. lower-*.f64N/A

        \[\leadsto ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \frac{th \cdot \color{blue}{\left(th \cdot th\right)}}{kx}, \frac{th}{kx}\right) \]
      9. lower-/.f6422.2

        \[\leadsto ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \color{blue}{\frac{th}{kx}}\right) \]
    11. Simplified22.2%

      \[\leadsto \color{blue}{ky \cdot \mathsf{fma}\left(-0.16666666666666666, \frac{th \cdot \left(th \cdot th\right)}{kx}, \frac{th}{kx}\right)} \]

    if 5.0000000000000001e-9 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.7%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6461.5

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified61.5%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6438.7

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified38.7%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 16: 22.2% accurate, 1.1× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-15}:\\ \;\;\;\;\frac{ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot \left(th \cdot th\right), th\right)}{kx}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 1e-15)
   (/ (* ky (fma -0.16666666666666666 (* th (* th th)) th)) kx)
   (fma th (* -0.16666666666666666 (* th th)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 1e-15) {
		tmp = (ky * fma(-0.16666666666666666, (th * (th * th)), th)) / kx;
	} else {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 1e-15)
		tmp = Float64(Float64(ky * fma(-0.16666666666666666, Float64(th * Float64(th * th)), th)) / kx);
	else
		tmp = fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[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], 1e-15], N[(N[(ky * N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]), $MachinePrecision] / kx), $MachinePrecision], N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-15}:\\
\;\;\;\;\frac{ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot \left(th \cdot th\right), th\right)}{kx}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 1.0000000000000001e-15

    1. Initial program 94.0%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in th around 0

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)}\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1\right)} \]
      3. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \left(th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th}\right) \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6435.4

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

      \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + {\sin ky}^{2}}} \cdot \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in kx around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{kx \cdot \left(1 + \frac{1}{2} \cdot \frac{{\sin ky}^{2}}{{kx}^{2}}\right)}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
    10. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{kx \cdot \color{blue}{\left(\frac{1}{2} \cdot \frac{{\sin ky}^{2}}{{kx}^{2}} + 1\right)}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      2. distribute-lft-inN/A

        \[\leadsto \frac{\sin ky}{\color{blue}{kx \cdot \left(\frac{1}{2} \cdot \frac{{\sin ky}^{2}}{{kx}^{2}}\right) + kx \cdot 1}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      3. associate-*r*N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\left(kx \cdot \frac{1}{2}\right) \cdot \frac{{\sin ky}^{2}}{{kx}^{2}}} + kx \cdot 1} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      4. *-rgt-identityN/A

        \[\leadsto \frac{\sin ky}{\left(kx \cdot \frac{1}{2}\right) \cdot \frac{{\sin ky}^{2}}{{kx}^{2}} + \color{blue}{kx}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      5. lower-fma.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left(kx \cdot \frac{1}{2}, \frac{{\sin ky}^{2}}{{kx}^{2}}, kx\right)}} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      6. lower-*.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(\color{blue}{kx \cdot \frac{1}{2}}, \frac{{\sin ky}^{2}}{{kx}^{2}}, kx\right)} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      7. lower-/.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(kx \cdot \frac{1}{2}, \color{blue}{\frac{{\sin ky}^{2}}{{kx}^{2}}}, kx\right)} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      8. lower-pow.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(kx \cdot \frac{1}{2}, \frac{\color{blue}{{\sin ky}^{2}}}{{kx}^{2}}, kx\right)} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      9. lower-sin.f64N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(kx \cdot \frac{1}{2}, \frac{{\color{blue}{\sin ky}}^{2}}{{kx}^{2}}, kx\right)} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      10. unpow2N/A

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(kx \cdot \frac{1}{2}, \frac{{\sin ky}^{2}}{\color{blue}{kx \cdot kx}}, kx\right)} \cdot \mathsf{fma}\left(th, \frac{-1}{6} \cdot \left(th \cdot th\right), th\right) \]
      11. lower-*.f6421.7

        \[\leadsto \frac{\sin ky}{\mathsf{fma}\left(kx \cdot 0.5, \frac{{\sin ky}^{2}}{\color{blue}{kx \cdot kx}}, kx\right)} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \]
    11. Simplified21.7%

      \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{fma}\left(kx \cdot 0.5, \frac{{\sin ky}^{2}}{kx \cdot kx}, kx\right)}} \cdot \mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right) \]
    12. Taylor expanded in ky around 0

      \[\leadsto \color{blue}{\frac{ky \cdot \left(th + \frac{-1}{6} \cdot {th}^{3}\right)}{kx}} \]
    13. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \color{blue}{\frac{ky \cdot \left(th + \frac{-1}{6} \cdot {th}^{3}\right)}{kx}} \]
      2. lower-*.f64N/A

        \[\leadsto \frac{\color{blue}{ky \cdot \left(th + \frac{-1}{6} \cdot {th}^{3}\right)}}{kx} \]
      3. +-commutativeN/A

        \[\leadsto \frac{ky \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{3} + th\right)}}{kx} \]
      4. lower-fma.f64N/A

        \[\leadsto \frac{ky \cdot \color{blue}{\mathsf{fma}\left(\frac{-1}{6}, {th}^{3}, th\right)}}{kx} \]
      5. cube-multN/A

        \[\leadsto \frac{ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot \left(th \cdot th\right)}, th\right)}{kx} \]
      6. unpow2N/A

        \[\leadsto \frac{ky \cdot \mathsf{fma}\left(\frac{-1}{6}, th \cdot \color{blue}{{th}^{2}}, th\right)}{kx} \]
      7. lower-*.f64N/A

        \[\leadsto \frac{ky \cdot \mathsf{fma}\left(\frac{-1}{6}, \color{blue}{th \cdot {th}^{2}}, th\right)}{kx} \]
      8. unpow2N/A

        \[\leadsto \frac{ky \cdot \mathsf{fma}\left(\frac{-1}{6}, th \cdot \color{blue}{\left(th \cdot th\right)}, th\right)}{kx} \]
      9. lower-*.f6420.1

        \[\leadsto \frac{ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot \color{blue}{\left(th \cdot th\right)}, th\right)}{kx} \]
    14. Simplified20.1%

      \[\leadsto \color{blue}{\frac{ky \cdot \mathsf{fma}\left(-0.16666666666666666, th \cdot \left(th \cdot th\right), th\right)}{kx}} \]

    if 1.0000000000000001e-15 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 81.9%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6460.9

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified60.9%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6438.4

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified38.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 17: 20.8% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 7.5 \cdot 10^{-33}:\\ \;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))) 7.5e-33)
   (* -0.16666666666666666 (* th (* th th)))
   (fma th (* -0.16666666666666666 (* th th)) th)))
double code(double kx, double ky, double th) {
	double tmp;
	if ((sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)))) <= 7.5e-33) {
		tmp = -0.16666666666666666 * (th * (th * th));
	} else {
		tmp = fma(th, (-0.16666666666666666 * (th * th)), th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)))) <= 7.5e-33)
		tmp = Float64(-0.16666666666666666 * Float64(th * Float64(th * th)));
	else
		tmp = fma(th, Float64(-0.16666666666666666 * Float64(th * th)), th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[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], 7.5e-33], N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(th * N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] + th), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 7.5 \cdot 10^{-33}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64))))) < 7.5000000000000001e-33

    1. Initial program 93.9%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f643.6

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified3.6%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f643.5

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified3.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
    9. Taylor expanded in th around inf

      \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
    10. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
      2. cube-multN/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot \left(th \cdot th\right)\right)} \]
      3. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{{th}^{2}}\right) \]
      4. lower-*.f64N/A

        \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot {th}^{2}\right)} \]
      5. unpow2N/A

        \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
      6. lower-*.f6416.9

        \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    11. Simplified16.9%

      \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]

    if 7.5000000000000001e-33 < (/.f64 (sin.f64 ky) (sqrt.f64 (+.f64 (pow.f64 (sin.f64 kx) #s(literal 2 binary64)) (pow.f64 (sin.f64 ky) #s(literal 2 binary64)))))

    1. Initial program 82.6%

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

      \[\leadsto \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6459.2

        \[\leadsto \color{blue}{\sin th} \]
    5. Simplified59.2%

      \[\leadsto \color{blue}{\sin th} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
    7. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
      2. distribute-lft-inN/A

        \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
      3. *-rgt-identityN/A

        \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
      4. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
      5. lower-*.f64N/A

        \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
      7. lower-*.f6437.4

        \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    8. Simplified37.4%

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 18: 68.5% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{1}{{\sin kx}^{2}}} \cdot \left(\sin ky \cdot \sin th\right)\\


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

    1. Initial program 86.6%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

    if 0.0254999999999999984 < kx

    1. Initial program 99.4%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot \sin th\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      2. *-commutativeN/A

        \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      3. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin th \cdot \sin ky\right)} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      4. lower-sin.f64N/A

        \[\leadsto \left(\color{blue}{\sin th} \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      5. lower-sin.f64N/A

        \[\leadsto \left(\sin th \cdot \color{blue}{\sin ky}\right) \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}} \]
      6. lower-sqrt.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      7. lower-/.f64N/A

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

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}} \]
      9. lower-pow.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}} \]
      10. lower-sin.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}} \]
      11. lower-pow.f64N/A

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

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

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

      \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}} \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}} \]
      2. lower-pow.f64N/A

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

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

      \[\leadsto \left(\sin th \cdot \sin ky\right) \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.0%

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

Alternative 19: 68.5% accurate, 1.4× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\sin th \cdot \left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2}}}\right)\\


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

    1. Initial program 86.6%

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{kx}^{2}} + {\sin ky}^{2}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
    6. Taylor expanded in ky around inf

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    7. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{kx \cdot kx} + {\sin ky}^{2}}} \cdot \sin th \]
      2. unpow2N/A

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \color{blue}{\sin ky \cdot \sin ky}}} \cdot \sin th \]
      3. lower-hypot.f64N/A

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

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

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

    if 0.0254999999999999984 < kx

    1. Initial program 99.4%

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}} \cdot \sin th \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
      2. unpow2N/A

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
      4. lower-hypot.f64N/A

        \[\leadsto \frac{\sin ky}{\color{blue}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \cdot \sin th \]
      5. lower-sin.f64N/A

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

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

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

      \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
    7. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \color{blue}{\left(\sin ky \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right)} \cdot \sin th \]
      2. lower-sin.f64N/A

        \[\leadsto \left(\color{blue}{\sin ky} \cdot \sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      3. lower-sqrt.f64N/A

        \[\leadsto \left(\sin ky \cdot \color{blue}{\sqrt{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      4. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      5. lower-+.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2} + {\sin ky}^{2}}}}\right) \cdot \sin th \]
      6. lower-pow.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      7. lower-sin.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2} + {\sin ky}^{2}}}\right) \cdot \sin th \]
      8. lower-pow.f64N/A

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

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

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

      \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
    10. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
      2. lower-pow.f64N/A

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{\color{blue}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
      3. lower-sin.f6459.9

        \[\leadsto \left(\sin ky \cdot \sqrt{\frac{1}{{\color{blue}{\sin kx}}^{2}}}\right) \cdot \sin th \]
    11. Simplified59.9%

      \[\leadsto \left(\sin ky \cdot \sqrt{\color{blue}{\frac{1}{{\sin kx}^{2}}}}\right) \cdot \sin th \]
  3. Recombined 2 regimes into one program.
  4. Final simplification70.0%

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

Alternative 20: 10.9% accurate, 39.5× speedup?

\[\begin{array}{l} \\ -0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right) \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (* -0.16666666666666666 (* th (* th th))))
double code(double kx, double ky, double th) {
	return -0.16666666666666666 * (th * (th * th));
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    code = (-0.16666666666666666d0) * (th * (th * th))
end function
public static double code(double kx, double ky, double th) {
	return -0.16666666666666666 * (th * (th * th));
}
def code(kx, ky, th):
	return -0.16666666666666666 * (th * (th * th))
function code(kx, ky, th)
	return Float64(-0.16666666666666666 * Float64(th * Float64(th * th)))
end
function tmp = code(kx, ky, th)
	tmp = -0.16666666666666666 * (th * (th * th));
end
code[kx_, ky_, th_] := N[(-0.16666666666666666 * N[(th * N[(th * th), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)
\end{array}
Derivation
  1. Initial program 90.0%

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

    \[\leadsto \color{blue}{\sin th} \]
  4. Step-by-step derivation
    1. lower-sin.f6422.7

      \[\leadsto \color{blue}{\sin th} \]
  5. Simplified22.7%

    \[\leadsto \color{blue}{\sin th} \]
  6. Taylor expanded in th around 0

    \[\leadsto \color{blue}{th \cdot \left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
  7. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto th \cdot \color{blue}{\left(\frac{-1}{6} \cdot {th}^{2} + 1\right)} \]
    2. distribute-lft-inN/A

      \[\leadsto \color{blue}{th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + th \cdot 1} \]
    3. *-rgt-identityN/A

      \[\leadsto th \cdot \left(\frac{-1}{6} \cdot {th}^{2}\right) + \color{blue}{th} \]
    4. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(th, \frac{-1}{6} \cdot {th}^{2}, th\right)} \]
    5. lower-*.f64N/A

      \[\leadsto \mathsf{fma}\left(th, \color{blue}{\frac{-1}{6} \cdot {th}^{2}}, th\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{fma}\left(th, \frac{-1}{6} \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
    7. lower-*.f6415.2

      \[\leadsto \mathsf{fma}\left(th, -0.16666666666666666 \cdot \color{blue}{\left(th \cdot th\right)}, th\right) \]
  8. Simplified15.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(th, -0.16666666666666666 \cdot \left(th \cdot th\right), th\right)} \]
  9. Taylor expanded in th around inf

    \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
  10. Step-by-step derivation
    1. lower-*.f64N/A

      \[\leadsto \color{blue}{\frac{-1}{6} \cdot {th}^{3}} \]
    2. cube-multN/A

      \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot \left(th \cdot th\right)\right)} \]
    3. unpow2N/A

      \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{{th}^{2}}\right) \]
    4. lower-*.f64N/A

      \[\leadsto \frac{-1}{6} \cdot \color{blue}{\left(th \cdot {th}^{2}\right)} \]
    5. unpow2N/A

      \[\leadsto \frac{-1}{6} \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
    6. lower-*.f6412.9

      \[\leadsto -0.16666666666666666 \cdot \left(th \cdot \color{blue}{\left(th \cdot th\right)}\right) \]
  11. Simplified12.9%

    \[\leadsto \color{blue}{-0.16666666666666666 \cdot \left(th \cdot \left(th \cdot th\right)\right)} \]
  12. Add Preprocessing

Reproduce

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