Toniolo and Linder, Equation (3b), real

Percentage Accurate: 94.3% → 99.7%
Time: 14.8s
Alternatives: 9
Speedup: 1.4×

Specification

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

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

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 9 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.3% accurate, 1.0× speedup?

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

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

Alternative 1: 99.7% accurate, 1.4× speedup?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \frac{\sin ky}{\color{blue}{\frac{\frac{\frac{\sqrt{{\sin kx}^{2} + {\sin ky}^{2}}}{-1}}{-1}}{\sin th}}} \]
    13. associate-/r/92.8%

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

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

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

Alternative 2: 44.5% accurate, 1.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.0002:\\ \;\;\;\;\sqrt[3]{\sqrt{{\sin th}^{6}}}\\ \mathbf{elif}\;\sin ky \leq 0.002:\\ \;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.0002)
   (cbrt (sqrt (pow (sin th) 6.0)))
   (if (<= (sin ky) 0.002)
     (* (sin th) (fabs (/ (sin ky) (sin kx))))
     (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.0002) {
		tmp = cbrt(sqrt(pow(sin(th), 6.0)));
	} else if (sin(ky) <= 0.002) {
		tmp = sin(th) * fabs((sin(ky) / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.0002) {
		tmp = Math.cbrt(Math.sqrt(Math.pow(Math.sin(th), 6.0)));
	} else if (Math.sin(ky) <= 0.002) {
		tmp = Math.sin(th) * Math.abs((Math.sin(ky) / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.0002)
		tmp = cbrt(sqrt((sin(th) ^ 6.0)));
	elseif (sin(ky) <= 0.002)
		tmp = Float64(sin(th) * abs(Float64(sin(ky) / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.0002], N[Power[N[Sqrt[N[Power[N[Sin[th], $MachinePrecision], 6.0], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.002], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(N[Sin[ky], $MachinePrecision] / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.0002:\\
\;\;\;\;\sqrt[3]{\sqrt{{\sin th}^{6}}}\\

\mathbf{elif}\;\sin ky \leq 0.002:\\
\;\;\;\;\sin th \cdot \left|\frac{\sin ky}{\sin kx}\right|\\

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt2.7%

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

        \[\leadsto \sqrt[3]{\color{blue}{\sqrt{{\sin th}^{3} \cdot {\sin th}^{3}}}} \]
      3. pow-prod-up16.5%

        \[\leadsto \sqrt[3]{\sqrt{\color{blue}{{\sin th}^{\left(3 + 3\right)}}}} \]
      4. metadata-eval16.5%

        \[\leadsto \sqrt[3]{\sqrt{{\sin th}^{\color{blue}{6}}}} \]
    7. Applied egg-rr16.5%

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

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

    1. Initial program 86.2%

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{\sin ky}{\sin kx}\right|} \cdot \sin th \]
    7. Simplified39.0%

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

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

    1. Initial program 99.5%

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

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

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

Alternative 3: 47.4% accurate, 1.4× speedup?

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

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

\mathbf{elif}\;\sin ky \leq 0.002:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube2.7%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.3%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow222.5%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr22.5%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow222.5%

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

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

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

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

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{ky}{\sin kx}\right|} \cdot \sin th \]
    9. Simplified39.0%

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

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

    1. Initial program 99.5%

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

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

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

Alternative 4: 44.5% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\sin ky \leq -0.0002:\\ \;\;\;\;\sqrt[3]{\sqrt{{\sin th}^{6}}}\\ \mathbf{elif}\;\sin ky \leq 0.002:\\ \;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\ \mathbf{else}:\\ \;\;\;\;\sin th\\ \end{array} \end{array} \]
(FPCore (kx ky th)
 :precision binary64
 (if (<= (sin ky) -0.0002)
   (cbrt (sqrt (pow (sin th) 6.0)))
   (if (<= (sin ky) 0.002) (* (sin th) (fabs (/ ky (sin kx)))) (sin th))))
double code(double kx, double ky, double th) {
	double tmp;
	if (sin(ky) <= -0.0002) {
		tmp = cbrt(sqrt(pow(sin(th), 6.0)));
	} else if (sin(ky) <= 0.002) {
		tmp = sin(th) * fabs((ky / sin(kx)));
	} else {
		tmp = sin(th);
	}
	return tmp;
}
public static double code(double kx, double ky, double th) {
	double tmp;
	if (Math.sin(ky) <= -0.0002) {
		tmp = Math.cbrt(Math.sqrt(Math.pow(Math.sin(th), 6.0)));
	} else if (Math.sin(ky) <= 0.002) {
		tmp = Math.sin(th) * Math.abs((ky / Math.sin(kx)));
	} else {
		tmp = Math.sin(th);
	}
	return tmp;
}
function code(kx, ky, th)
	tmp = 0.0
	if (sin(ky) <= -0.0002)
		tmp = cbrt(sqrt((sin(th) ^ 6.0)));
	elseif (sin(ky) <= 0.002)
		tmp = Float64(sin(th) * abs(Float64(ky / sin(kx))));
	else
		tmp = sin(th);
	end
	return tmp
end
code[kx_, ky_, th_] := If[LessEqual[N[Sin[ky], $MachinePrecision], -0.0002], N[Power[N[Sqrt[N[Power[N[Sin[th], $MachinePrecision], 6.0], $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], If[LessEqual[N[Sin[ky], $MachinePrecision], 0.002], N[(N[Sin[th], $MachinePrecision] * N[Abs[N[(ky / N[Sin[kx], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sin[th], $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\sin ky \leq -0.0002:\\
\;\;\;\;\sqrt[3]{\sqrt{{\sin th}^{6}}}\\

\mathbf{elif}\;\sin ky \leq 0.002:\\
\;\;\;\;\sin th \cdot \left|\frac{ky}{\sin kx}\right|\\

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
    6. Step-by-step derivation
      1. add-sqr-sqrt2.7%

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

        \[\leadsto \sqrt[3]{\color{blue}{\sqrt{{\sin th}^{3} \cdot {\sin th}^{3}}}} \]
      3. pow-prod-up16.5%

        \[\leadsto \sqrt[3]{\sqrt{\color{blue}{{\sin th}^{\left(3 + 3\right)}}}} \]
      4. metadata-eval16.5%

        \[\leadsto \sqrt[3]{\sqrt{{\sin th}^{\color{blue}{6}}}} \]
    7. Applied egg-rr16.5%

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

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

    1. Initial program 86.2%

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left|\frac{ky}{\sin kx}\right|} \cdot \sin th \]
    9. Simplified39.0%

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

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

    1. Initial program 99.5%

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

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

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

Alternative 5: 48.3% accurate, 1.7× speedup?

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

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

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

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


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

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube2.7%

        \[\leadsto \color{blue}{\sin th} \]
      2. add-sqr-sqrt1.3%

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

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow222.5%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr22.5%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow222.5%

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

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

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

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

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

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

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

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

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

    if 4.99999999999999992e-46 < (sin.f64 ky)

    1. Initial program 99.6%

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

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

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

Alternative 6: 26.3% accurate, 3.3× speedup?

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

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

\mathbf{elif}\;ky \leq 8.5 \cdot 10^{+118} \lor \neg \left(ky \leq 2.95 \cdot 10^{+206}\right):\\
\;\;\;\;\sin th\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if ky < 7.39999999999999961e-109

    1. Initial program 89.6%

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

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

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

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

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

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

    if 7.39999999999999961e-109 < ky < 8.50000000000000033e118 or 2.95e206 < ky

    1. Initial program 99.7%

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

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

    if 8.50000000000000033e118 < ky < 2.95e206

    1. Initial program 99.5%

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

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

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

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

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

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

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

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

      \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
    6. Step-by-step derivation
      1. rem-cbrt-cube21.2%

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

        \[\leadsto \color{blue}{\sqrt{\sin th} \cdot \sqrt{\sin th}} \]
      3. sqrt-unprod17.3%

        \[\leadsto \color{blue}{\sqrt{\sin th \cdot \sin th}} \]
      4. pow217.3%

        \[\leadsto \sqrt{\color{blue}{{\sin th}^{2}}} \]
    7. Applied egg-rr17.3%

      \[\leadsto \color{blue}{\sqrt{{\sin th}^{2}}} \]
    8. Step-by-step derivation
      1. unpow217.3%

        \[\leadsto \sqrt{\color{blue}{\sin th \cdot \sin th}} \]
      2. rem-sqrt-square25.8%

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

      \[\leadsto \color{blue}{\left|\sin th\right|} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification24.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;ky \leq 7.4 \cdot 10^{-109}:\\ \;\;\;\;\sin th \cdot \frac{ky}{kx}\\ \mathbf{elif}\;ky \leq 8.5 \cdot 10^{+118} \lor \neg \left(ky \leq 2.95 \cdot 10^{+206}\right):\\ \;\;\;\;\sin th\\ \mathbf{else}:\\ \;\;\;\;\left|\sin th\right|\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 26.3% accurate, 6.4× speedup?

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

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

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


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

    1. Initial program 89.6%

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

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

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

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

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

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

    if 2.59999999999999984e-108 < ky

    1. Initial program 99.7%

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

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

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

Alternative 8: 24.2% accurate, 7.0× speedup?

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

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

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

    \[\leadsto \color{blue}{\sin th} \]
  4. Final simplification19.6%

    \[\leadsto \sin th \]
  5. Add Preprocessing

Alternative 9: 13.9% accurate, 709.0× speedup?

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \sqrt[3]{\color{blue}{{\sin th}^{3}}} \]
  6. Taylor expanded in th around 0 11.7%

    \[\leadsto \color{blue}{th} \]
  7. Final simplification11.7%

    \[\leadsto th \]
  8. Add Preprocessing

Reproduce

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