Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.0% → 99.7%
Time: 9.5s
Alternatives: 17
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 17 alternatives:

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

Initial Program: 94.0% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.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 91.3%

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

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

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
    4. lift-pow.f64N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \cdot \sin th \]
    6. lift-pow.f64N/A

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

      \[\leadsto \frac{\sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \cdot \sin th \]
    8. lower-hypot.f6499.7

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

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

Alternative 2: 82.3% accurate, 0.2× speedup?

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

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

\mathbf{elif}\;t\_5 \leq -0.05:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_5 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\left(\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, -1\right) \cdot ky\right) \cdot t\_2\\

\mathbf{elif}\;t\_5 \leq 0.9:\\
\;\;\;\;t\_3\\

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

\mathbf{else}:\\
\;\;\;\;\left(-ky\right) \cdot t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.00000000000000024e-5

    1. Initial program 98.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
      4. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.900000000000000022 < (/.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.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 \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6493.3

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

      \[\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.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
      4. div-invN/A

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \cdot \sin th\right)} \]
    4. Applied rewrites99.9%

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

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

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

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

      \[\leadsto \color{blue}{\left(-ky\right)} \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th\right) \]
  3. Recombined 5 regimes into one program.
  4. Add Preprocessing

Alternative 3: 82.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \frac{\sin ky \cdot th}{t\_1}\\ t_3 := {\sin ky}^{2}\\ t_4 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + t\_3}}\\ \mathbf{if}\;t\_4 \leq -0.95:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + t\_3}} \cdot \sin th\\ \mathbf{elif}\;t\_4 \leq -0.05:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-1}}\\ \mathbf{elif}\;t\_4 \leq 0.9:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_4 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left(-ky\right) \cdot \left(\frac{-1}{t\_1} \cdot \sin th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (/ (* (sin ky) th) t_1))
        (t_3 (pow (sin ky) 2.0))
        (t_4 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) t_3)))))
   (if (<= t_4 -0.95)
     (* (/ (sin ky) (sqrt (+ (* kx kx) t_3))) (sin th))
     (if (<= t_4 -0.05)
       t_2
       (if (<= t_4 5e-5)
         (/ (/ (sin th) t_1) (pow ky -1.0))
         (if (<= t_4 0.9)
           t_2
           (if (<= t_4 2.0)
             (sin th)
             (* (- ky) (* (/ -1.0 t_1) (sin th))))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = (sin(ky) * th) / t_1;
	double t_3 = pow(sin(ky), 2.0);
	double t_4 = sin(ky) / sqrt((pow(sin(kx), 2.0) + t_3));
	double tmp;
	if (t_4 <= -0.95) {
		tmp = (sin(ky) / sqrt(((kx * kx) + t_3))) * sin(th);
	} else if (t_4 <= -0.05) {
		tmp = t_2;
	} else if (t_4 <= 5e-5) {
		tmp = (sin(th) / t_1) / pow(ky, -1.0);
	} else if (t_4 <= 0.9) {
		tmp = t_2;
	} else if (t_4 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = -ky * ((-1.0 / t_1) * sin(th));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double t_2 = (Math.sin(ky) * th) / t_1;
	double t_3 = Math.pow(Math.sin(ky), 2.0);
	double t_4 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + t_3));
	double tmp;
	if (t_4 <= -0.95) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + t_3))) * Math.sin(th);
	} else if (t_4 <= -0.05) {
		tmp = t_2;
	} else if (t_4 <= 5e-5) {
		tmp = (Math.sin(th) / t_1) / Math.pow(ky, -1.0);
	} else if (t_4 <= 0.9) {
		tmp = t_2;
	} else if (t_4 <= 2.0) {
		tmp = Math.sin(th);
	} else {
		tmp = -ky * ((-1.0 / t_1) * Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	t_2 = (math.sin(ky) * th) / t_1
	t_3 = math.pow(math.sin(ky), 2.0)
	t_4 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + t_3))
	tmp = 0
	if t_4 <= -0.95:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + t_3))) * math.sin(th)
	elif t_4 <= -0.05:
		tmp = t_2
	elif t_4 <= 5e-5:
		tmp = (math.sin(th) / t_1) / math.pow(ky, -1.0)
	elif t_4 <= 0.9:
		tmp = t_2
	elif t_4 <= 2.0:
		tmp = math.sin(th)
	else:
		tmp = -ky * ((-1.0 / t_1) * math.sin(th))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(Float64(sin(ky) * th) / t_1)
	t_3 = sin(ky) ^ 2.0
	t_4 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + t_3)))
	tmp = 0.0
	if (t_4 <= -0.95)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + t_3))) * sin(th));
	elseif (t_4 <= -0.05)
		tmp = t_2;
	elseif (t_4 <= 5e-5)
		tmp = Float64(Float64(sin(th) / t_1) / (ky ^ -1.0));
	elseif (t_4 <= 0.9)
		tmp = t_2;
	elseif (t_4 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(Float64(-ky) * Float64(Float64(-1.0 / t_1) * sin(th)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	t_2 = (sin(ky) * th) / t_1;
	t_3 = sin(ky) ^ 2.0;
	t_4 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + t_3));
	tmp = 0.0;
	if (t_4 <= -0.95)
		tmp = (sin(ky) / sqrt(((kx * kx) + t_3))) * sin(th);
	elseif (t_4 <= -0.05)
		tmp = t_2;
	elseif (t_4 <= 5e-5)
		tmp = (sin(th) / t_1) / (ky ^ -1.0);
	elseif (t_4 <= 0.9)
		tmp = t_2;
	elseif (t_4 <= 2.0)
		tmp = sin(th);
	else
		tmp = -ky * ((-1.0 / t_1) * sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$1), $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[(N[Power[N[Sin[kx], $MachinePrecision], 2.0], $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$4, -0.95], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + t$95$3), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, -0.05], t$95$2, If[LessEqual[t$95$4, 5e-5], N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[Power[ky, -1.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 0.9], t$95$2, If[LessEqual[t$95$4, 2.0], N[Sin[th], $MachinePrecision], N[((-ky) * N[(N[(-1.0 / t$95$1), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]
\begin{array}{l}

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

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

\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-1}}\\

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

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

\mathbf{else}:\\
\;\;\;\;\left(-ky\right) \cdot \left(\frac{-1}{t\_1} \cdot \sin th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.00000000000000024e-5

    1. Initial program 98.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

      \[\leadsto \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\color{blue}{\frac{1}{ky}}} \]
    6. Step-by-step derivation
      1. lower-/.f6498.6

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

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

    if 0.900000000000000022 < (/.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.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 \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6493.3

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

      \[\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.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
      4. div-invN/A

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \cdot \sin th\right)} \]
    4. Applied rewrites99.9%

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

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

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

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

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

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

Alternative 4: 78.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_3 := \frac{\sin ky \cdot th}{t\_1}\\ \mathbf{if}\;t\_2 \leq -0.95:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_2 \leq -0.05:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-1}}\\ \mathbf{elif}\;t\_2 \leq 0.9:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_2 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left(-ky\right) \cdot \left(\frac{-1}{t\_1} \cdot \sin th\right)\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_3 (/ (* (sin ky) th) t_1)))
   (if (<= t_2 -0.95)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_2 -0.05)
       t_3
       (if (<= t_2 5e-5)
         (/ (/ (sin th) t_1) (pow ky -1.0))
         (if (<= t_2 0.9)
           t_3
           (if (<= t_2 2.0)
             (sin th)
             (* (- ky) (* (/ -1.0 t_1) (sin th))))))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_3 = (sin(ky) * th) / t_1;
	double tmp;
	if (t_2 <= -0.95) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_2 <= -0.05) {
		tmp = t_3;
	} else if (t_2 <= 5e-5) {
		tmp = (sin(th) / t_1) / pow(ky, -1.0);
	} else if (t_2 <= 0.9) {
		tmp = t_3;
	} else if (t_2 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = -ky * ((-1.0 / t_1) * sin(th));
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double t_2 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double t_3 = (Math.sin(ky) * th) / t_1;
	double tmp;
	if (t_2 <= -0.95) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_2 <= -0.05) {
		tmp = t_3;
	} else if (t_2 <= 5e-5) {
		tmp = (Math.sin(th) / t_1) / Math.pow(ky, -1.0);
	} else if (t_2 <= 0.9) {
		tmp = t_3;
	} else if (t_2 <= 2.0) {
		tmp = Math.sin(th);
	} else {
		tmp = -ky * ((-1.0 / t_1) * Math.sin(th));
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	t_2 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	t_3 = (math.sin(ky) * th) / t_1
	tmp = 0
	if t_2 <= -0.95:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_2 <= -0.05:
		tmp = t_3
	elif t_2 <= 5e-5:
		tmp = (math.sin(th) / t_1) / math.pow(ky, -1.0)
	elif t_2 <= 0.9:
		tmp = t_3
	elif t_2 <= 2.0:
		tmp = math.sin(th)
	else:
		tmp = -ky * ((-1.0 / t_1) * math.sin(th))
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_3 = Float64(Float64(sin(ky) * th) / t_1)
	tmp = 0.0
	if (t_2 <= -0.95)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_2 <= -0.05)
		tmp = t_3;
	elseif (t_2 <= 5e-5)
		tmp = Float64(Float64(sin(th) / t_1) / (ky ^ -1.0));
	elseif (t_2 <= 0.9)
		tmp = t_3;
	elseif (t_2 <= 2.0)
		tmp = sin(th);
	else
		tmp = Float64(Float64(-ky) * Float64(Float64(-1.0 / t_1) * sin(th)));
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	t_2 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	t_3 = (sin(ky) * th) / t_1;
	tmp = 0.0;
	if (t_2 <= -0.95)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_2 <= -0.05)
		tmp = t_3;
	elseif (t_2 <= 5e-5)
		tmp = (sin(th) / t_1) / (ky ^ -1.0);
	elseif (t_2 <= 0.9)
		tmp = t_3;
	elseif (t_2 <= 2.0)
		tmp = sin(th);
	else
		tmp = -ky * ((-1.0 / t_1) * sin(th));
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = 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]}, Block[{t$95$3 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -0.95], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -0.05], t$95$3, If[LessEqual[t$95$2, 5e-5], N[(N[(N[Sin[th], $MachinePrecision] / t$95$1), $MachinePrecision] / N[Power[ky, -1.0], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 0.9], t$95$3, If[LessEqual[t$95$2, 2.0], N[Sin[th], $MachinePrecision], N[((-ky) * N[(N[(-1.0 / t$95$1), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_2 \leq -0.05:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;\frac{\frac{\sin th}{t\_1}}{{ky}^{-1}}\\

\mathbf{elif}\;t\_2 \leq 0.9:\\
\;\;\;\;t\_3\\

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

\mathbf{else}:\\
\;\;\;\;\left(-ky\right) \cdot \left(\frac{-1}{t\_1} \cdot \sin th\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 5 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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.00000000000000024e-5

    1. Initial program 98.9%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      6. div-invN/A

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

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

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

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

      \[\leadsto \frac{\frac{\sin th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}}{\color{blue}{\frac{1}{ky}}} \]
    6. Step-by-step derivation
      1. lower-/.f6498.6

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

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

    if 0.900000000000000022 < (/.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.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 \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6493.3

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

      \[\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.7%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
      4. div-invN/A

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

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

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

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

        \[\leadsto \left(-\sin ky\right) \cdot \color{blue}{\left(\frac{1}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)} \cdot \sin th\right)} \]
    4. Applied rewrites99.9%

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

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

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

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

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

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

Alternative 5: 78.0% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \frac{\sin ky \cdot th}{t\_1}\\ t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_4 := \left(-ky\right) \cdot \left(\frac{-1}{t\_1} \cdot \sin th\right)\\ \mathbf{if}\;t\_3 \leq -0.95:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.05:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 0.9:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 2:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;t\_4\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (/ (* (sin ky) th) t_1))
        (t_3 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_4 (* (- ky) (* (/ -1.0 t_1) (sin th)))))
   (if (<= t_3 -0.95)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_3 -0.05)
       t_2
       (if (<= t_3 5e-5)
         t_4
         (if (<= t_3 0.9) t_2 (if (<= t_3 2.0) (sin th) t_4)))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = (sin(ky) * th) / t_1;
	double t_3 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_4 = -ky * ((-1.0 / t_1) * sin(th));
	double tmp;
	if (t_3 <= -0.95) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_3 <= -0.05) {
		tmp = t_2;
	} else if (t_3 <= 5e-5) {
		tmp = t_4;
	} else if (t_3 <= 0.9) {
		tmp = t_2;
	} else if (t_3 <= 2.0) {
		tmp = sin(th);
	} else {
		tmp = t_4;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double t_2 = (Math.sin(ky) * th) / t_1;
	double t_3 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double t_4 = -ky * ((-1.0 / t_1) * Math.sin(th));
	double tmp;
	if (t_3 <= -0.95) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_3 <= -0.05) {
		tmp = t_2;
	} else if (t_3 <= 5e-5) {
		tmp = t_4;
	} else if (t_3 <= 0.9) {
		tmp = t_2;
	} else if (t_3 <= 2.0) {
		tmp = Math.sin(th);
	} else {
		tmp = t_4;
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	t_2 = (math.sin(ky) * th) / t_1
	t_3 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	t_4 = -ky * ((-1.0 / t_1) * math.sin(th))
	tmp = 0
	if t_3 <= -0.95:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_3 <= -0.05:
		tmp = t_2
	elif t_3 <= 5e-5:
		tmp = t_4
	elif t_3 <= 0.9:
		tmp = t_2
	elif t_3 <= 2.0:
		tmp = math.sin(th)
	else:
		tmp = t_4
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(Float64(sin(ky) * th) / t_1)
	t_3 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_4 = Float64(Float64(-ky) * Float64(Float64(-1.0 / t_1) * sin(th)))
	tmp = 0.0
	if (t_3 <= -0.95)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_3 <= -0.05)
		tmp = t_2;
	elseif (t_3 <= 5e-5)
		tmp = t_4;
	elseif (t_3 <= 0.9)
		tmp = t_2;
	elseif (t_3 <= 2.0)
		tmp = sin(th);
	else
		tmp = t_4;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	t_2 = (sin(ky) * th) / t_1;
	t_3 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	t_4 = -ky * ((-1.0 / t_1) * sin(th));
	tmp = 0.0;
	if (t_3 <= -0.95)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_3 <= -0.05)
		tmp = t_2;
	elseif (t_3 <= 5e-5)
		tmp = t_4;
	elseif (t_3 <= 0.9)
		tmp = t_2;
	elseif (t_3 <= 2.0)
		tmp = sin(th);
	else
		tmp = t_4;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = 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]}, Block[{t$95$4 = N[((-ky) * N[(N[(-1.0 / t$95$1), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$3, -0.95], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.05], t$95$2, If[LessEqual[t$95$3, 5e-5], t$95$4, If[LessEqual[t$95$3, 0.9], t$95$2, If[LessEqual[t$95$3, 2.0], N[Sin[th], $MachinePrecision], t$95$4]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_3 \leq -0.05:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 0.9:\\
\;\;\;\;t\_2\\

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

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


\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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.00000000000000024e-5 or 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 87.6%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

        \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
      4. div-invN/A

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

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

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

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

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

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

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

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

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

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

    if 0.900000000000000022 < (/.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.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 \color{blue}{\sin th} \]
    4. Step-by-step derivation
      1. lower-sin.f6493.3

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

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

Alternative 6: 76.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{hypot}\left(\sin ky, \sin kx\right)\\ t_2 := \frac{\sin ky \cdot th}{t\_1}\\ t_3 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_4 := \frac{\sin th \cdot ky}{t\_1}\\ \mathbf{if}\;t\_3 \leq -0.95:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_3 \leq -0.05:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;t\_4\\ \mathbf{elif}\;t\_3 \leq 0.9:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 1:\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;t\_4\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (let* ((t_1 (hypot (sin ky) (sin kx)))
        (t_2 (/ (* (sin ky) th) t_1))
        (t_3 (/ (sin ky) (sqrt (+ (pow (sin kx) 2.0) (pow (sin ky) 2.0)))))
        (t_4 (/ (* (sin th) ky) t_1)))
   (if (<= t_3 -0.95)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_3 -0.05)
       t_2
       (if (<= t_3 5e-5)
         t_4
         (if (<= t_3 0.9) t_2 (if (<= t_3 1.0) (sin th) t_4)))))))
double code(double kx, double ky, double th) {
	double t_1 = hypot(sin(ky), sin(kx));
	double t_2 = (sin(ky) * th) / t_1;
	double t_3 = sin(ky) / sqrt((pow(sin(kx), 2.0) + pow(sin(ky), 2.0)));
	double t_4 = (sin(th) * ky) / t_1;
	double tmp;
	if (t_3 <= -0.95) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_3 <= -0.05) {
		tmp = t_2;
	} else if (t_3 <= 5e-5) {
		tmp = t_4;
	} else if (t_3 <= 0.9) {
		tmp = t_2;
	} else if (t_3 <= 1.0) {
		tmp = sin(th);
	} else {
		tmp = t_4;
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.hypot(Math.sin(ky), Math.sin(kx));
	double t_2 = (Math.sin(ky) * th) / t_1;
	double t_3 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double t_4 = (Math.sin(th) * ky) / t_1;
	double tmp;
	if (t_3 <= -0.95) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_3 <= -0.05) {
		tmp = t_2;
	} else if (t_3 <= 5e-5) {
		tmp = t_4;
	} else if (t_3 <= 0.9) {
		tmp = t_2;
	} else if (t_3 <= 1.0) {
		tmp = Math.sin(th);
	} else {
		tmp = t_4;
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.hypot(math.sin(ky), math.sin(kx))
	t_2 = (math.sin(ky) * th) / t_1
	t_3 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	t_4 = (math.sin(th) * ky) / t_1
	tmp = 0
	if t_3 <= -0.95:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_3 <= -0.05:
		tmp = t_2
	elif t_3 <= 5e-5:
		tmp = t_4
	elif t_3 <= 0.9:
		tmp = t_2
	elif t_3 <= 1.0:
		tmp = math.sin(th)
	else:
		tmp = t_4
	return tmp
function code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx))
	t_2 = Float64(Float64(sin(ky) * th) / t_1)
	t_3 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_4 = Float64(Float64(sin(th) * ky) / t_1)
	tmp = 0.0
	if (t_3 <= -0.95)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_3 <= -0.05)
		tmp = t_2;
	elseif (t_3 <= 5e-5)
		tmp = t_4;
	elseif (t_3 <= 0.9)
		tmp = t_2;
	elseif (t_3 <= 1.0)
		tmp = sin(th);
	else
		tmp = t_4;
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = hypot(sin(ky), sin(kx));
	t_2 = (sin(ky) * th) / t_1;
	t_3 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	t_4 = (sin(th) * ky) / t_1;
	tmp = 0.0;
	if (t_3 <= -0.95)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_3 <= -0.05)
		tmp = t_2;
	elseif (t_3 <= 5e-5)
		tmp = t_4;
	elseif (t_3 <= 0.9)
		tmp = t_2;
	elseif (t_3 <= 1.0)
		tmp = sin(th);
	else
		tmp = t_4;
	end
	tmp_2 = tmp;
end
code[kx_, ky_, th_] := Block[{t$95$1 = N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / t$95$1), $MachinePrecision]}, Block[{t$95$3 = 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]}, Block[{t$95$4 = N[(N[(N[Sin[th], $MachinePrecision] * ky), $MachinePrecision] / t$95$1), $MachinePrecision]}, If[LessEqual[t$95$3, -0.95], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, -0.05], t$95$2, If[LessEqual[t$95$3, 5e-5], t$95$4, If[LessEqual[t$95$3, 0.9], t$95$2, If[LessEqual[t$95$3, 1.0], N[Sin[th], $MachinePrecision], t$95$4]]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_3 \leq -0.05:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{-5}:\\
\;\;\;\;t\_4\\

\mathbf{elif}\;t\_3 \leq 0.9:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq 1:\\
\;\;\;\;\sin th\\

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


\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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.00000000000000024e-5 or 1 < (/.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 87.3%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}} \]
      14. lower-hypot.f6494.7

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

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

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

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

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

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

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

    if 0.900000000000000022 < (/.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

    1. Initial program 99.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.f6493.2

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

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

Alternative 7: 67.2% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}\\ t_2 := \frac{\sin ky \cdot th}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}\\ \mathbf{if}\;t\_1 \leq -0.95:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq -0.05:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-5}:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \mathbf{elif}\;t\_1 \leq 0.9:\\ \;\;\;\;t\_2\\ \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)))))
        (t_2 (/ (* (sin ky) th) (hypot (sin ky) (sin kx)))))
   (if (<= t_1 -0.95)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_1 -0.05)
       t_2
       (if (<= t_1 2e-62)
         (*
          (/ (sin ky) (sqrt (+ (- 0.5 (* (cos (* 2.0 kx)) 0.5)) (* ky ky))))
          (sin th))
         (if (<= t_1 5e-5)
           (/ (sin th) (/ (sin kx) ky))
           (if (<= t_1 0.9) t_2 (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 t_2 = (sin(ky) * th) / hypot(sin(ky), sin(kx));
	double tmp;
	if (t_1 <= -0.95) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_1 <= -0.05) {
		tmp = t_2;
	} else if (t_1 <= 2e-62) {
		tmp = (sin(ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * sin(th);
	} else if (t_1 <= 5e-5) {
		tmp = sin(th) / (sin(kx) / ky);
	} else if (t_1 <= 0.9) {
		tmp = t_2;
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double t_2 = (Math.sin(ky) * th) / Math.hypot(Math.sin(ky), Math.sin(kx));
	double tmp;
	if (t_1 <= -0.95) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_1 <= -0.05) {
		tmp = t_2;
	} else if (t_1 <= 2e-62) {
		tmp = (Math.sin(ky) / Math.sqrt(((0.5 - (Math.cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * Math.sin(th);
	} else if (t_1 <= 5e-5) {
		tmp = Math.sin(th) / (Math.sin(kx) / ky);
	} else if (t_1 <= 0.9) {
		tmp = t_2;
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	t_2 = (math.sin(ky) * th) / math.hypot(math.sin(ky), math.sin(kx))
	tmp = 0
	if t_1 <= -0.95:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_1 <= -0.05:
		tmp = t_2
	elif t_1 <= 2e-62:
		tmp = (math.sin(ky) / math.sqrt(((0.5 - (math.cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * math.sin(th)
	elif t_1 <= 5e-5:
		tmp = math.sin(th) / (math.sin(kx) / ky)
	elif t_1 <= 0.9:
		tmp = t_2
	else:
		tmp = math.sin(th)
	return tmp
function code(kx, ky, th)
	t_1 = Float64(sin(ky) / sqrt(Float64((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0))))
	t_2 = Float64(Float64(sin(ky) * th) / hypot(sin(ky), sin(kx)))
	tmp = 0.0
	if (t_1 <= -0.95)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_1 <= -0.05)
		tmp = t_2;
	elseif (t_1 <= 2e-62)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * kx)) * 0.5)) + Float64(ky * ky)))) * sin(th));
	elseif (t_1 <= 5e-5)
		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
	elseif (t_1 <= 0.9)
		tmp = t_2;
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	t_2 = (sin(ky) * th) / hypot(sin(ky), sin(kx));
	tmp = 0.0;
	if (t_1 <= -0.95)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_1 <= -0.05)
		tmp = t_2;
	elseif (t_1 <= 2e-62)
		tmp = (sin(ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * sin(th);
	elseif (t_1 <= 5e-5)
		tmp = sin(th) / (sin(kx) / ky);
	elseif (t_1 <= 0.9)
		tmp = t_2;
	else
		tmp = sin(th);
	end
	tmp_2 = 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]}, Block[{t$95$2 = N[(N[(N[Sin[ky], $MachinePrecision] * th), $MachinePrecision] / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -0.95], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -0.05], t$95$2, If[LessEqual[t$95$1, 2e-62], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 5e-5], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.9], t$95$2, N[Sin[th], $MachinePrecision]]]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;t\_1 \leq -0.05:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-62}:\\
\;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + ky \cdot ky}} \cdot \sin th\\

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

\mathbf{elif}\;t\_1 \leq 0.9:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 5 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.94999999999999996

    1. Initial program 82.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-*.f6475.0

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.94999999999999996 < (/.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.050000000000000003 or 5.00000000000000024e-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))))) < 0.900000000000000022

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
      10. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
      12. lift-pow.f64N/A

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

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

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

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

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

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

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

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

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

    if -0.050000000000000003 < (/.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.0000000000000001e-62

    1. Initial program 98.9%

      \[\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 \sin th \]
    4. Step-by-step derivation
      1. unpow2N/A

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if 2.0000000000000001e-62 < (/.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.00000000000000024e-5

    1. Initial program 99.4%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      7. lower-/.f6499.8

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      8. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
      9. lift-+.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
      11. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
      13. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
      15. lower-hypot.f6499.8

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

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

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

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

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

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

    if 0.900000000000000022 < (/.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.f6484.0

        \[\leadsto \color{blue}{\sin th} \]
    5. Applied rewrites84.0%

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

Alternative 8: 59.1% 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.71:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-62}:\\ \;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + ky \cdot ky}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.5:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \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.71)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_1 2e-62)
       (*
        (/ (sin ky) (sqrt (+ (- 0.5 (* (cos (* 2.0 kx)) 0.5)) (* ky ky))))
        (sin th))
       (if (<= t_1 0.5) (* (/ (sin ky) (sin kx)) (sin th)) (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.71) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_1 <= 2e-62) {
		tmp = (sin(ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * sin(th);
	} else if (t_1 <= 0.5) {
		tmp = (sin(ky) / sin(kx)) * sin(th);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
    if (t_1 <= (-0.71d0)) then
        tmp = (sin(ky) / sqrt(((kx * kx) + (0.5d0 - (cos((2.0d0 * ky)) * 0.5d0))))) * sin(th)
    else if (t_1 <= 2d-62) then
        tmp = (sin(ky) / sqrt(((0.5d0 - (cos((2.0d0 * kx)) * 0.5d0)) + (ky * ky)))) * sin(th)
    else if (t_1 <= 0.5d0) then
        tmp = (sin(ky) / sin(kx)) * sin(th)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.71) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_1 <= 2e-62) {
		tmp = (Math.sin(ky) / Math.sqrt(((0.5 - (Math.cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * Math.sin(th);
	} else if (t_1 <= 0.5) {
		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_1 <= -0.71:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_1 <= 2e-62:
		tmp = (math.sin(ky) / math.sqrt(((0.5 - (math.cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * math.sin(th)
	elif t_1 <= 0.5:
		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
	else:
		tmp = math.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.71)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_1 <= 2e-62)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(0.5 - Float64(cos(Float64(2.0 * kx)) * 0.5)) + Float64(ky * ky)))) * sin(th));
	elseif (t_1 <= 0.5)
		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -0.71)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_1 <= 2e-62)
		tmp = (sin(ky) / sqrt(((0.5 - (cos((2.0 * kx)) * 0.5)) + (ky * ky)))) * sin(th);
	elseif (t_1 <= 0.5)
		tmp = (sin(ky) / sin(kx)) * sin(th);
	else
		tmp = sin(th);
	end
	tmp_2 = 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.71], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-62], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(0.5 - N[(N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision] + N[(ky * ky), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.5], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $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.71:\\
\;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\

\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{-62}:\\
\;\;\;\;\frac{\sin ky}{\sqrt{\left(0.5 - \cos \left(2 \cdot kx\right) \cdot 0.5\right) + ky \cdot ky}} \cdot \sin th\\

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

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


\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.70999999999999996

    1. Initial program 85.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 \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.8

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.70999999999999996 < (/.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.0000000000000001e-62

    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 ky around 0

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

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

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\sin kx \cdot \color{blue}{\sin kx} + ky \cdot ky}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{\left(\frac{1}{2} - \color{blue}{\cos \left(kx + kx\right)} \cdot \frac{1}{2}\right) + ky \cdot ky}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if 2.0000000000000001e-62 < (/.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.5%

      \[\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.f6423.3

        \[\leadsto \frac{\sin ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Applied rewrites23.3%

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

    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. Initial program 85.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.f6474.6

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

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

Alternative 9: 56.7% 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.9:\\ \;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\ \mathbf{elif}\;t\_1 \leq 0.5:\\ \;\;\;\;\frac{\sin ky}{\sin kx} \cdot \sin th\\ \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.9)
     (*
      (/ (sin ky) (sqrt (+ (* kx kx) (- 0.5 (* (cos (* 2.0 ky)) 0.5)))))
      (sin th))
     (if (<= t_1 0.5) (* (/ (sin ky) (sin kx)) (sin th)) (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.9) {
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	} else if (t_1 <= 0.5) {
		tmp = (sin(ky) / sin(kx)) * sin(th);
	} else {
		tmp = sin(th);
	}
	return tmp;
}
real(8) function code(kx, ky, th)
    real(8), intent (in) :: kx
    real(8), intent (in) :: ky
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = sin(ky) / sqrt(((sin(kx) ** 2.0d0) + (sin(ky) ** 2.0d0)))
    if (t_1 <= (-0.9d0)) then
        tmp = (sin(ky) / sqrt(((kx * kx) + (0.5d0 - (cos((2.0d0 * ky)) * 0.5d0))))) * sin(th)
    else if (t_1 <= 0.5d0) then
        tmp = (sin(ky) / sin(kx)) * sin(th)
    else
        tmp = sin(th)
    end if
    code = tmp
end function
public static double code(double kx, double ky, double th) {
	double t_1 = Math.sin(ky) / Math.sqrt((Math.pow(Math.sin(kx), 2.0) + Math.pow(Math.sin(ky), 2.0)));
	double tmp;
	if (t_1 <= -0.9) {
		tmp = (Math.sin(ky) / Math.sqrt(((kx * kx) + (0.5 - (Math.cos((2.0 * ky)) * 0.5))))) * Math.sin(th);
	} else if (t_1 <= 0.5) {
		tmp = (Math.sin(ky) / Math.sin(kx)) * Math.sin(th);
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
def code(kx, ky, th):
	t_1 = math.sin(ky) / math.sqrt((math.pow(math.sin(kx), 2.0) + math.pow(math.sin(ky), 2.0)))
	tmp = 0
	if t_1 <= -0.9:
		tmp = (math.sin(ky) / math.sqrt(((kx * kx) + (0.5 - (math.cos((2.0 * ky)) * 0.5))))) * math.sin(th)
	elif t_1 <= 0.5:
		tmp = (math.sin(ky) / math.sin(kx)) * math.sin(th)
	else:
		tmp = math.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.9)
		tmp = Float64(Float64(sin(ky) / sqrt(Float64(Float64(kx * kx) + Float64(0.5 - Float64(cos(Float64(2.0 * ky)) * 0.5))))) * sin(th));
	elseif (t_1 <= 0.5)
		tmp = Float64(Float64(sin(ky) / sin(kx)) * sin(th));
	else
		tmp = sin(th);
	end
	return tmp
end
function tmp_2 = code(kx, ky, th)
	t_1 = sin(ky) / sqrt(((sin(kx) ^ 2.0) + (sin(ky) ^ 2.0)));
	tmp = 0.0;
	if (t_1 <= -0.9)
		tmp = (sin(ky) / sqrt(((kx * kx) + (0.5 - (cos((2.0 * ky)) * 0.5))))) * sin(th);
	elseif (t_1 <= 0.5)
		tmp = (sin(ky) / sin(kx)) * sin(th);
	else
		tmp = sin(th);
	end
	tmp_2 = 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.9], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sqrt[N[(N[(kx * kx), $MachinePrecision] + N[(0.5 - N[(N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 0.5], N[(N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $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.9:\\
\;\;\;\;\frac{\sin ky}{\sqrt{kx \cdot kx + \left(0.5 - \cos \left(2 \cdot ky\right) \cdot 0.5\right)}} \cdot \sin th\\

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

\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.900000000000000022

    1. Initial program 82.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-*.f6473.6

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \sin ky \cdot \color{blue}{\sin ky}}} \cdot \sin th \]
      5. sqr-sin-aN/A

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

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

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

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

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

        \[\leadsto \frac{\sin ky}{\sqrt{kx \cdot kx + \left(\frac{1}{2} - \color{blue}{\cos \left(ky + ky\right)} \cdot \frac{1}{2}\right)}} \cdot \sin th \]
      11. count-2N/A

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

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

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

    if -0.900000000000000022 < (/.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.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.f6445.0

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

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

    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. Initial program 85.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.f6474.6

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

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

Alternative 10: 45.2% accurate, 0.7× speedup?

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

\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.5

    1. Initial program 94.3%

      \[\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.f6433.0

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

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

    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. Initial program 85.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.f6474.6

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

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

Alternative 11: 44.0% accurate, 0.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 0.01:\\ \;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\ \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.01)
   (/ (sin th) (/ (sin kx) ky))
   (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.01) {
		tmp = sin(th) / (sin(kx) / ky);
	} 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.01d0) then
        tmp = sin(th) / (sin(kx) / ky)
    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.01) {
		tmp = Math.sin(th) / (Math.sin(kx) / ky);
	} 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.01:
		tmp = math.sin(th) / (math.sin(kx) / ky)
	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.01)
		tmp = Float64(sin(th) / Float64(sin(kx) / ky));
	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.01)
		tmp = sin(th) / (sin(kx) / ky);
	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.01], N[(N[Sin[th], $MachinePrecision] / N[(N[Sin[kx], $MachinePrecision] / ky), $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.01:\\
\;\;\;\;\frac{\sin th}{\frac{\sin kx}{ky}}\\

\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.0100000000000000002

    1. Initial program 94.0%

      \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. lift-*.f64N/A

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

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

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

        \[\leadsto \sin th \cdot \color{blue}{\frac{1}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      5. un-div-invN/A

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

        \[\leadsto \color{blue}{\frac{\sin th}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      7. lower-/.f6494.0

        \[\leadsto \frac{\sin th}{\color{blue}{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{\sin ky}}} \]
      8. lift-sqrt.f64N/A

        \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}}{\sin ky}} \]
      9. lift-+.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}}{\sin ky}} \]
      11. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}}{\sin ky}} \]
      13. lift-pow.f64N/A

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

        \[\leadsto \frac{\sin th}{\frac{\sqrt{\sin ky \cdot \sin ky + \color{blue}{\sin kx \cdot \sin kx}}}{\sin ky}} \]
      15. lower-hypot.f6499.6

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

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

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

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

        \[\leadsto \frac{\sin th}{\frac{\color{blue}{\sin kx}}{ky}} \]
    7. Applied rewrites32.6%

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

    if 0.0100000000000000002 < (/.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 86.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.f6468.9

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

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

Alternative 12: 44.0% accurate, 0.8× speedup?

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

\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.0100000000000000002

    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 ky around 0

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

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

        \[\leadsto \frac{ky}{\color{blue}{\sin kx}} \cdot \sin th \]
    5. Applied rewrites32.6%

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

    if 0.0100000000000000002 < (/.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 86.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.f6468.9

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

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

Alternative 13: 30.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \leq 10^{-106}:\\ \;\;\;\;{th}^{3} \cdot -0.16666666666666666\\ \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)))) 1e-106)
   (* (pow th 3.0) -0.16666666666666666)
   (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)))) <= 1e-106) {
		tmp = pow(th, 3.0) * -0.16666666666666666;
	} 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)))) <= 1d-106) then
        tmp = (th ** 3.0d0) * (-0.16666666666666666d0)
    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)))) <= 1e-106) {
		tmp = Math.pow(th, 3.0) * -0.16666666666666666;
	} 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)))) <= 1e-106:
		tmp = math.pow(th, 3.0) * -0.16666666666666666
	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)))) <= 1e-106)
		tmp = Float64((th ^ 3.0) * -0.16666666666666666);
	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)))) <= 1e-106)
		tmp = (th ^ 3.0) * -0.16666666666666666;
	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], 1e-106], N[(N[Power[th, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision], N[Sin[th], $MachinePrecision]]
\begin{array}{l}

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

\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))))) < 9.99999999999999941e-107

    1. Initial program 93.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.f643.3

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

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

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

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

        \[\leadsto \frac{-1}{6} \cdot {th}^{\color{blue}{3}} \]
      3. Step-by-step derivation
        1. Applied rewrites15.4%

          \[\leadsto {th}^{3} \cdot -0.16666666666666666 \]

        if 9.99999999999999941e-107 < (/.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 88.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.f6458.8

            \[\leadsto \color{blue}{\sin th} \]
        5. Applied rewrites58.8%

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

      Alternative 14: 75.0% accurate, 1.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00125:\\ \;\;\;\;\left(\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, -1\right) \cdot ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin th \cdot \sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}\\ \end{array} \end{array} \]
      (FPCore (kx ky th)
       :precision binary64
       (if (<= ky 0.00125)
         (*
          (* (fma (* ky ky) 0.16666666666666666 -1.0) ky)
          (* (/ -1.0 (hypot (sin ky) (sin kx))) (sin th)))
         (/
          (* (sin th) (sin ky))
          (/
           (sqrt (fma (- 1.0 (cos (* 2.0 ky))) 2.0 (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
           2.0))))
      double code(double kx, double ky, double th) {
      	double tmp;
      	if (ky <= 0.00125) {
      		tmp = (fma((ky * ky), 0.16666666666666666, -1.0) * ky) * ((-1.0 / hypot(sin(ky), sin(kx))) * sin(th));
      	} else {
      		tmp = (sin(th) * sin(ky)) / (sqrt(fma((1.0 - cos((2.0 * ky))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0);
      	}
      	return tmp;
      }
      
      function code(kx, ky, th)
      	tmp = 0.0
      	if (ky <= 0.00125)
      		tmp = Float64(Float64(fma(Float64(ky * ky), 0.16666666666666666, -1.0) * ky) * Float64(Float64(-1.0 / hypot(sin(ky), sin(kx))) * sin(th)));
      	else
      		tmp = Float64(Float64(sin(th) * sin(ky)) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(2.0 * ky))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0));
      	end
      	return tmp
      end
      
      code[kx_, ky_, th_] := If[LessEqual[ky, 0.00125], N[(N[(N[(N[(ky * ky), $MachinePrecision] * 0.16666666666666666 + -1.0), $MachinePrecision] * ky), $MachinePrecision] * N[(N[(-1.0 / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[th], $MachinePrecision] * N[Sin[ky], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(2.0 * ky), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;ky \leq 0.00125:\\
      \;\;\;\;\left(\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, -1\right) \cdot ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\sin th \cdot \sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if ky < 0.00125000000000000003

        1. Initial program 88.9%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

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

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

            \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
          4. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 0.00125000000000000003 < ky

        1. Initial program 99.7%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \]
          10. lift-pow.f64N/A

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

            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\sin ky \cdot \sin ky} + {\sin kx}^{2}}} \]
          12. lift-pow.f64N/A

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

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

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

          \[\leadsto \color{blue}{\frac{\sin th \cdot \sin ky}{\mathsf{hypot}\left(\sin ky, \sin kx\right)}} \]
        5. Step-by-step derivation
          1. lift-hypot.f64N/A

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

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

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

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

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

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

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

            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \]
          9. metadata-evalN/A

            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \]
          10. metadata-evalN/A

            \[\leadsto \frac{\sin th \cdot \sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \]
          11. sqrt-divN/A

            \[\leadsto \frac{\sin th \cdot \sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{2 + 2}}}} \]
          12. metadata-evalN/A

            \[\leadsto \frac{\sin th \cdot \sin ky}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{\sqrt{\color{blue}{4}}}} \]
          13. metadata-evalN/A

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

            \[\leadsto \frac{\sin th \cdot \sin ky}{\color{blue}{\frac{\sqrt{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}}{2}}} \]
        6. Applied rewrites98.9%

          \[\leadsto \frac{\sin th \cdot \sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(2 \cdot ky\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 15: 75.0% accurate, 1.3× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;ky \leq 0.00125:\\ \;\;\;\;\left(\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, -1\right) \cdot ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \sin th\\ \end{array} \end{array} \]
      (FPCore (kx ky th)
       :precision binary64
       (if (<= ky 0.00125)
         (*
          (* (fma (* ky ky) 0.16666666666666666 -1.0) ky)
          (* (/ -1.0 (hypot (sin ky) (sin kx))) (sin th)))
         (*
          (/
           (sin ky)
           (/
            (sqrt
             (fma (- 1.0 (cos (* ky 2.0))) 2.0 (* 2.0 (- 1.0 (cos (* 2.0 kx))))))
            2.0))
          (sin th))))
      double code(double kx, double ky, double th) {
      	double tmp;
      	if (ky <= 0.00125) {
      		tmp = (fma((ky * ky), 0.16666666666666666, -1.0) * ky) * ((-1.0 / hypot(sin(ky), sin(kx))) * sin(th));
      	} else {
      		tmp = (sin(ky) / (sqrt(fma((1.0 - cos((ky * 2.0))), 2.0, (2.0 * (1.0 - cos((2.0 * kx)))))) / 2.0)) * sin(th);
      	}
      	return tmp;
      }
      
      function code(kx, ky, th)
      	tmp = 0.0
      	if (ky <= 0.00125)
      		tmp = Float64(Float64(fma(Float64(ky * ky), 0.16666666666666666, -1.0) * ky) * Float64(Float64(-1.0 / hypot(sin(ky), sin(kx))) * sin(th)));
      	else
      		tmp = Float64(Float64(sin(ky) / Float64(sqrt(fma(Float64(1.0 - cos(Float64(ky * 2.0))), 2.0, Float64(2.0 * Float64(1.0 - cos(Float64(2.0 * kx)))))) / 2.0)) * sin(th));
      	end
      	return tmp
      end
      
      code[kx_, ky_, th_] := If[LessEqual[ky, 0.00125], N[(N[(N[(N[(ky * ky), $MachinePrecision] * 0.16666666666666666 + -1.0), $MachinePrecision] * ky), $MachinePrecision] * N[(N[(-1.0 / N[Sqrt[N[Sin[ky], $MachinePrecision] ^ 2 + N[Sin[kx], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sin[ky], $MachinePrecision] / N[(N[Sqrt[N[(N[(1.0 - N[Cos[N[(ky * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * 2.0 + N[(2.0 * N[(1.0 - N[Cos[N[(2.0 * kx), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * N[Sin[th], $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;ky \leq 0.00125:\\
      \;\;\;\;\left(\mathsf{fma}\left(ky \cdot ky, 0.16666666666666666, -1\right) \cdot ky\right) \cdot \left(\frac{-1}{\mathsf{hypot}\left(\sin ky, \sin kx\right)} \cdot \sin th\right)\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{\sin ky}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}} \cdot \sin th\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if ky < 0.00125000000000000003

        1. Initial program 88.9%

          \[\frac{\sin ky}{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}} \cdot \sin th \]
        2. Add Preprocessing
        3. Step-by-step derivation
          1. lift-*.f64N/A

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

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

            \[\leadsto \color{blue}{\frac{\mathsf{neg}\left(\sin ky\right)}{\mathsf{neg}\left(\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}\right)}} \cdot \sin th \]
          4. div-invN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        if 0.00125000000000000003 < ky

        1. Initial program 99.7%

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

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

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

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{{\sin ky}^{2} + {\sin kx}^{2}}}} \cdot \sin th \]
          4. lift-pow.f64N/A

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

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

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

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

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

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

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

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

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \sin kx \cdot \color{blue}{\sin kx}}} \cdot \sin th \]
          13. sin-multN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\cos \left(ky - ky\right) - \cos \left(ky + ky\right)}{2} + \color{blue}{\frac{\cos \left(kx - kx\right) - \cos \left(kx + kx\right)}{2}}}} \cdot \sin th \]
          14. frac-addN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\color{blue}{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{2 \cdot 2}}}} \cdot \sin th \]
          15. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{4}}}} \cdot \sin th \]
          16. metadata-evalN/A

            \[\leadsto \frac{\sin ky}{\sqrt{\frac{\left(\cos \left(ky - ky\right) - \cos \left(ky + ky\right)\right) \cdot 2 + 2 \cdot \left(\cos \left(kx - kx\right) - \cos \left(kx + kx\right)\right)}{\color{blue}{2 + 2}}}} \cdot \sin th \]
          17. sqrt-divN/A

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

          \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\sqrt{\mathsf{fma}\left(1 - \cos \left(ky \cdot 2\right), 2, 2 \cdot \left(1 - \cos \left(2 \cdot kx\right)\right)\right)}}{2}}} \cdot \sin th \]
      3. Recombined 2 regimes into one program.
      4. Add Preprocessing

      Alternative 16: 23.4% accurate, 6.3× speedup?

      \[\begin{array}{l} \\ \sin th \end{array} \]
      (FPCore (kx ky th) :precision binary64 (sin th))
      double code(double kx, double ky, double th) {
      	return sin(th);
      }
      
      real(8) function code(kx, ky, th)
          real(8), intent (in) :: kx
          real(8), intent (in) :: ky
          real(8), intent (in) :: th
          code = sin(th)
      end function
      
      public static double code(double kx, double ky, double th) {
      	return Math.sin(th);
      }
      
      def code(kx, ky, th):
      	return math.sin(th)
      
      function code(kx, ky, th)
      	return sin(th)
      end
      
      function tmp = code(kx, ky, th)
      	tmp = sin(th);
      end
      
      code[kx_, ky_, th_] := N[Sin[th], $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \sin th
      \end{array}
      
      Derivation
      1. Initial program 91.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.f6426.9

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

        \[\leadsto \color{blue}{\sin th} \]
      6. Add Preprocessing

      Alternative 17: 13.1% accurate, 37.2× speedup?

      \[\begin{array}{l} \\ \mathsf{fma}\left(-0.16666666666666666 \cdot \left(th \cdot th\right), th, th\right) \end{array} \]
      (FPCore (kx ky th)
       :precision binary64
       (fma (* -0.16666666666666666 (* th th)) th th))
      double code(double kx, double ky, double th) {
      	return fma((-0.16666666666666666 * (th * th)), th, th);
      }
      
      function code(kx, ky, th)
      	return fma(Float64(-0.16666666666666666 * Float64(th * th)), th, th)
      end
      
      code[kx_, ky_, th_] := N[(N[(-0.16666666666666666 * N[(th * th), $MachinePrecision]), $MachinePrecision] * th + th), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \mathsf{fma}\left(-0.16666666666666666 \cdot \left(th \cdot th\right), th, th\right)
      \end{array}
      
      Derivation
      1. Initial program 91.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.f6426.9

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

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

        \[\leadsto th \cdot \color{blue}{\left(1 + \frac{-1}{6} \cdot {th}^{2}\right)} \]
      7. Step-by-step derivation
        1. Applied rewrites14.8%

          \[\leadsto \mathsf{fma}\left({th}^{3}, \color{blue}{-0.16666666666666666}, th\right) \]
        2. Step-by-step derivation
          1. Applied rewrites14.8%

            \[\leadsto \mathsf{fma}\left(-0.16666666666666666 \cdot \left(th \cdot th\right), th, th\right) \]
          2. Add Preprocessing

          Reproduce

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