Migdal et al, Equation (64)

Percentage Accurate: 99.5% → 99.6%
Time: 11.3s
Alternatives: 16
Speedup: 2.0×

Specification

?
\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\cos th}{\sqrt{2}}\\ t_1 \cdot \left(a1 \cdot a1\right) + t_1 \cdot \left(a2 \cdot a2\right) \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (let* ((t_1 (/ (cos th) (sqrt 2.0))))
   (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
double code(double a1, double a2, double th) {
	double t_1 = cos(th) / sqrt(2.0);
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: t_1
    t_1 = cos(th) / sqrt(2.0d0)
    code = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
end function
public static double code(double a1, double a2, double th) {
	double t_1 = Math.cos(th) / Math.sqrt(2.0);
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
def code(a1, a2, th):
	t_1 = math.cos(th) / math.sqrt(2.0)
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
function code(a1, a2, th)
	t_1 = Float64(cos(th) / sqrt(2.0))
	return Float64(Float64(t_1 * Float64(a1 * a1)) + Float64(t_1 * Float64(a2 * a2)))
end
function tmp = code(a1, a2, th)
	t_1 = cos(th) / sqrt(2.0);
	tmp = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
t_1 \cdot \left(a1 \cdot a1\right) + t_1 \cdot \left(a2 \cdot a2\right)
\end{array}
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

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

Accuracy vs Speed?

Herbie found 16 alternatives:

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

Initial Program: 99.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_1 := \frac{\cos th}{\sqrt{2}}\\ t_1 \cdot \left(a1 \cdot a1\right) + t_1 \cdot \left(a2 \cdot a2\right) \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (let* ((t_1 (/ (cos th) (sqrt 2.0))))
   (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
double code(double a1, double a2, double th) {
	double t_1 = cos(th) / sqrt(2.0);
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: t_1
    t_1 = cos(th) / sqrt(2.0d0)
    code = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
end function
public static double code(double a1, double a2, double th) {
	double t_1 = Math.cos(th) / Math.sqrt(2.0);
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
}
def code(a1, a2, th):
	t_1 = math.cos(th) / math.sqrt(2.0)
	return (t_1 * (a1 * a1)) + (t_1 * (a2 * a2))
function code(a1, a2, th)
	t_1 = Float64(cos(th) / sqrt(2.0))
	return Float64(Float64(t_1 * Float64(a1 * a1)) + Float64(t_1 * Float64(a2 * a2)))
end
function tmp = code(a1, a2, th)
	t_1 = cos(th) / sqrt(2.0);
	tmp = (t_1 * (a1 * a1)) + (t_1 * (a2 * a2));
end
code[a1_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(t$95$1 * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
t_1 \cdot \left(a1 \cdot a1\right) + t_1 \cdot \left(a2 \cdot a2\right)
\end{array}
\end{array}

Alternative 1: 99.6% accurate, 0.7× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} t_1 := \frac{\cos th}{\sqrt{2}}\\ \mathsf{fma}\left(t_1 \cdot a2, a2, t_1 \cdot {a1_m}^{2}\right) \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (let* ((t_1 (/ (cos th) (sqrt 2.0))))
   (fma (* t_1 a2) a2 (* t_1 (pow a1_m 2.0)))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double t_1 = cos(th) / sqrt(2.0);
	return fma((t_1 * a2), a2, (t_1 * pow(a1_m, 2.0)));
}
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	t_1 = Float64(cos(th) / sqrt(2.0))
	return fma(Float64(t_1 * a2), a2, Float64(t_1 * (a1_m ^ 2.0)))
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := Block[{t$95$1 = N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]}, N[(N[(t$95$1 * a2), $MachinePrecision] * a2 + N[(t$95$1 * N[Power[a1$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
t_1 := \frac{\cos th}{\sqrt{2}}\\
\mathsf{fma}\left(t_1 \cdot a2, a2, t_1 \cdot {a1_m}^{2}\right)
\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 2: 99.6% accurate, 1.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \cos th \cdot \frac{{\left(\mathsf{hypot}\left(a1_m, a2\right)\right)}^{2}}{\sqrt{2}} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (* (cos th) (/ (pow (hypot a1_m a2) 2.0) (sqrt 2.0))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return cos(th) * (pow(hypot(a1_m, a2), 2.0) / sqrt(2.0));
}
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return Math.cos(th) * (Math.pow(Math.hypot(a1_m, a2), 2.0) / Math.sqrt(2.0));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return math.cos(th) * (math.pow(math.hypot(a1_m, a2), 2.0) / math.sqrt(2.0))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(cos(th) * Float64((hypot(a1_m, a2) ^ 2.0) / sqrt(2.0)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = cos(th) * ((hypot(a1_m, a2) ^ 2.0) / sqrt(2.0));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[Cos[th], $MachinePrecision] * N[(N[Power[N[Sqrt[a1$95$m ^ 2 + a2 ^ 2], $MachinePrecision], 2.0], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\cos th \cdot \frac{{\left(\mathsf{hypot}\left(a1_m, a2\right)\right)}^{2}}{\sqrt{2}}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 3: 99.4% accurate, 1.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \frac{\cos th}{\sqrt{2} \cdot {\left(\mathsf{hypot}\left(a1_m, a2\right)\right)}^{-2}} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (/ (cos th) (* (sqrt 2.0) (pow (hypot a1_m a2) -2.0))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return cos(th) / (sqrt(2.0) * pow(hypot(a1_m, a2), -2.0));
}
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return Math.cos(th) / (Math.sqrt(2.0) * Math.pow(Math.hypot(a1_m, a2), -2.0));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return math.cos(th) / (math.sqrt(2.0) * math.pow(math.hypot(a1_m, a2), -2.0))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(cos(th) / Float64(sqrt(2.0) * (hypot(a1_m, a2) ^ -2.0)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = cos(th) / (sqrt(2.0) * (hypot(a1_m, a2) ^ -2.0));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[Cos[th], $MachinePrecision] / N[(N[Sqrt[2.0], $MachinePrecision] * N[Power[N[Sqrt[a1$95$m ^ 2 + a2 ^ 2], $MachinePrecision], -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\frac{\cos th}{\sqrt{2} \cdot {\left(\mathsf{hypot}\left(a1_m, a2\right)\right)}^{-2}}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 4: 79.9% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;\cos th \leq 0.7:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a1_m \cdot a1_m + a2 \cdot a2\right) \cdot {0.25}^{0.25}\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= (cos th) 0.7)
   (* (cos th) (* (+ a2 a1_m) (+ a2 a1_m)))
   (* (+ (* a1_m a1_m) (* a2 a2)) (pow 0.25 0.25))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (cos(th) <= 0.7) {
		tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	} else {
		tmp = ((a1_m * a1_m) + (a2 * a2)) * pow(0.25, 0.25);
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (cos(th) <= 0.7d0) then
        tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m))
    else
        tmp = ((a1_m * a1_m) + (a2 * a2)) * (0.25d0 ** 0.25d0)
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= 0.7) {
		tmp = Math.cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	} else {
		tmp = ((a1_m * a1_m) + (a2 * a2)) * Math.pow(0.25, 0.25);
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if math.cos(th) <= 0.7:
		tmp = math.cos(th) * ((a2 + a1_m) * (a2 + a1_m))
	else:
		tmp = ((a1_m * a1_m) + (a2 * a2)) * math.pow(0.25, 0.25)
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (cos(th) <= 0.7)
		tmp = Float64(cos(th) * Float64(Float64(a2 + a1_m) * Float64(a2 + a1_m)));
	else
		tmp = Float64(Float64(Float64(a1_m * a1_m) + Float64(a2 * a2)) * (0.25 ^ 0.25));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (cos(th) <= 0.7)
		tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	else
		tmp = ((a1_m * a1_m) + (a2 * a2)) * (0.25 ^ 0.25);
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], 0.7], N[(N[Cos[th], $MachinePrecision] * N[(N[(a2 + a1$95$m), $MachinePrecision] * N[(a2 + a1$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision] * N[Power[0.25, 0.25], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq 0.7:\\
\;\;\;\;\cos th \cdot \left(\left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right)\right)\\

\mathbf{else}:\\
\;\;\;\;\left(a1_m \cdot a1_m + a2 \cdot a2\right) \cdot {0.25}^{0.25}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 5: 79.9% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} t_1 := a1_m \cdot a1_m + a2 \cdot a2\\ \mathbf{if}\;\cos th \leq 0.7:\\ \;\;\;\;\cos th \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot {0.25}^{0.25}\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (let* ((t_1 (+ (* a1_m a1_m) (* a2 a2))))
   (if (<= (cos th) 0.7) (* (cos th) t_1) (* t_1 (pow 0.25 0.25)))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double t_1 = (a1_m * a1_m) + (a2 * a2);
	double tmp;
	if (cos(th) <= 0.7) {
		tmp = cos(th) * t_1;
	} else {
		tmp = t_1 * pow(0.25, 0.25);
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (a1_m * a1_m) + (a2 * a2)
    if (cos(th) <= 0.7d0) then
        tmp = cos(th) * t_1
    else
        tmp = t_1 * (0.25d0 ** 0.25d0)
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double t_1 = (a1_m * a1_m) + (a2 * a2);
	double tmp;
	if (Math.cos(th) <= 0.7) {
		tmp = Math.cos(th) * t_1;
	} else {
		tmp = t_1 * Math.pow(0.25, 0.25);
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	t_1 = (a1_m * a1_m) + (a2 * a2)
	tmp = 0
	if math.cos(th) <= 0.7:
		tmp = math.cos(th) * t_1
	else:
		tmp = t_1 * math.pow(0.25, 0.25)
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	t_1 = Float64(Float64(a1_m * a1_m) + Float64(a2 * a2))
	tmp = 0.0
	if (cos(th) <= 0.7)
		tmp = Float64(cos(th) * t_1);
	else
		tmp = Float64(t_1 * (0.25 ^ 0.25));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	t_1 = (a1_m * a1_m) + (a2 * a2);
	tmp = 0.0;
	if (cos(th) <= 0.7)
		tmp = cos(th) * t_1;
	else
		tmp = t_1 * (0.25 ^ 0.25);
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := Block[{t$95$1 = N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[th], $MachinePrecision], 0.7], N[(N[Cos[th], $MachinePrecision] * t$95$1), $MachinePrecision], N[(t$95$1 * N[Power[0.25, 0.25], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
t_1 := a1_m \cdot a1_m + a2 \cdot a2\\
\mathbf{if}\;\cos th \leq 0.7:\\
\;\;\;\;\cos th \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot {0.25}^{0.25}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 6: 99.6% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a1_m \cdot a1_m + a2 \cdot a2\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (* (* (cos th) (pow 2.0 -0.5)) (+ (* a1_m a1_m) (* a2 a2))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return (cos(th) * pow(2.0, -0.5)) * ((a1_m * a1_m) + (a2 * a2));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = (cos(th) * (2.0d0 ** (-0.5d0))) * ((a1_m * a1_m) + (a2 * a2))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return (Math.cos(th) * Math.pow(2.0, -0.5)) * ((a1_m * a1_m) + (a2 * a2));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return (math.cos(th) * math.pow(2.0, -0.5)) * ((a1_m * a1_m) + (a2 * a2))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(Float64(cos(th) * (2.0 ^ -0.5)) * Float64(Float64(a1_m * a1_m) + Float64(a2 * a2)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = (cos(th) * (2.0 ^ -0.5)) * ((a1_m * a1_m) + (a2 * a2));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[(N[Cos[th], $MachinePrecision] * N[Power[2.0, -0.5], $MachinePrecision]), $MachinePrecision] * N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a1_m \cdot a1_m + a2 \cdot a2\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 7: 67.4% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;\cos th \leq 0.7:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= (cos th) 0.7)
   (* (cos th) (* (+ a2 a1_m) (+ a2 a1_m)))
   (* a2 (/ a2 (sqrt 2.0)))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (cos(th) <= 0.7) {
		tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	} else {
		tmp = a2 * (a2 / sqrt(2.0));
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (cos(th) <= 0.7d0) then
        tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m))
    else
        tmp = a2 * (a2 / sqrt(2.0d0))
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= 0.7) {
		tmp = Math.cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	} else {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if math.cos(th) <= 0.7:
		tmp = math.cos(th) * ((a2 + a1_m) * (a2 + a1_m))
	else:
		tmp = a2 * (a2 / math.sqrt(2.0))
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (cos(th) <= 0.7)
		tmp = Float64(cos(th) * Float64(Float64(a2 + a1_m) * Float64(a2 + a1_m)));
	else
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (cos(th) <= 0.7)
		tmp = cos(th) * ((a2 + a1_m) * (a2 + a1_m));
	else
		tmp = a2 * (a2 / sqrt(2.0));
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], 0.7], N[(N[Cos[th], $MachinePrecision] * N[(N[(a2 + a1$95$m), $MachinePrecision] * N[(a2 + a1$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq 0.7:\\
\;\;\;\;\cos th \cdot \left(\left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right)\right)\\

\mathbf{else}:\\
\;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 8: 99.5% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \frac{\cos th}{\sqrt{2}} \cdot \left(a1_m \cdot a1_m + a2 \cdot a2\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (* (/ (cos th) (sqrt 2.0)) (+ (* a1_m a1_m) (* a2 a2))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return (cos(th) / sqrt(2.0)) * ((a1_m * a1_m) + (a2 * a2));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = (cos(th) / sqrt(2.0d0)) * ((a1_m * a1_m) + (a2 * a2))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return (Math.cos(th) / Math.sqrt(2.0)) * ((a1_m * a1_m) + (a2 * a2));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return (math.cos(th) / math.sqrt(2.0)) * ((a1_m * a1_m) + (a2 * a2))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(Float64(cos(th) / sqrt(2.0)) * Float64(Float64(a1_m * a1_m) + Float64(a2 * a2)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = (cos(th) / sqrt(2.0)) * ((a1_m * a1_m) + (a2 * a2));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\frac{\cos th}{\sqrt{2}} \cdot \left(a1_m \cdot a1_m + a2 \cdot a2\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 9: 63.1% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-0.5 \cdot {a2}^{2}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot {2}^{-0.5}\right)\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= (cos th) -1e-310) (* -0.5 (pow a2 2.0)) (* a2 (* a2 (pow 2.0 -0.5)))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (cos(th) <= -1e-310) {
		tmp = -0.5 * pow(a2, 2.0);
	} else {
		tmp = a2 * (a2 * pow(2.0, -0.5));
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (cos(th) <= (-1d-310)) then
        tmp = (-0.5d0) * (a2 ** 2.0d0)
    else
        tmp = a2 * (a2 * (2.0d0 ** (-0.5d0)))
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= -1e-310) {
		tmp = -0.5 * Math.pow(a2, 2.0);
	} else {
		tmp = a2 * (a2 * Math.pow(2.0, -0.5));
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if math.cos(th) <= -1e-310:
		tmp = -0.5 * math.pow(a2, 2.0)
	else:
		tmp = a2 * (a2 * math.pow(2.0, -0.5))
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (cos(th) <= -1e-310)
		tmp = Float64(-0.5 * (a2 ^ 2.0));
	else
		tmp = Float64(a2 * Float64(a2 * (2.0 ^ -0.5)));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (cos(th) <= -1e-310)
		tmp = -0.5 * (a2 ^ 2.0);
	else
		tmp = a2 * (a2 * (2.0 ^ -0.5));
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], -1e-310], N[(-0.5 * N[Power[a2, 2.0], $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 * N[Power[2.0, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot {a2}^{2}\\

\mathbf{else}:\\
\;\;\;\;a2 \cdot \left(a2 \cdot {2}^{-0.5}\right)\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 10: 63.1% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-0.5 \cdot {a2}^{2}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= (cos th) -1e-310) (* -0.5 (pow a2 2.0)) (* a2 (/ a2 (sqrt 2.0)))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (cos(th) <= -1e-310) {
		tmp = -0.5 * pow(a2, 2.0);
	} else {
		tmp = a2 * (a2 / sqrt(2.0));
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (cos(th) <= (-1d-310)) then
        tmp = (-0.5d0) * (a2 ** 2.0d0)
    else
        tmp = a2 * (a2 / sqrt(2.0d0))
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= -1e-310) {
		tmp = -0.5 * Math.pow(a2, 2.0);
	} else {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if math.cos(th) <= -1e-310:
		tmp = -0.5 * math.pow(a2, 2.0)
	else:
		tmp = a2 * (a2 / math.sqrt(2.0))
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (cos(th) <= -1e-310)
		tmp = Float64(-0.5 * (a2 ^ 2.0));
	else
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (cos(th) <= -1e-310)
		tmp = -0.5 * (a2 ^ 2.0);
	else
		tmp = a2 * (a2 / sqrt(2.0));
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], -1e-310], N[(-0.5 * N[Power[a2, 2.0], $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot {a2}^{2}\\

\mathbf{else}:\\
\;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 11: 57.0% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-0.5 \cdot {a2}^{2}\\ \mathbf{else}:\\ \;\;\;\;\left(a1_m \cdot a1_m + a2 \cdot a2\right) \cdot 0.5\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= (cos th) -1e-310)
   (* -0.5 (pow a2 2.0))
   (* (+ (* a1_m a1_m) (* a2 a2)) 0.5)))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (cos(th) <= -1e-310) {
		tmp = -0.5 * pow(a2, 2.0);
	} else {
		tmp = ((a1_m * a1_m) + (a2 * a2)) * 0.5;
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (cos(th) <= (-1d-310)) then
        tmp = (-0.5d0) * (a2 ** 2.0d0)
    else
        tmp = ((a1_m * a1_m) + (a2 * a2)) * 0.5d0
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= -1e-310) {
		tmp = -0.5 * Math.pow(a2, 2.0);
	} else {
		tmp = ((a1_m * a1_m) + (a2 * a2)) * 0.5;
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if math.cos(th) <= -1e-310:
		tmp = -0.5 * math.pow(a2, 2.0)
	else:
		tmp = ((a1_m * a1_m) + (a2 * a2)) * 0.5
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (cos(th) <= -1e-310)
		tmp = Float64(-0.5 * (a2 ^ 2.0));
	else
		tmp = Float64(Float64(Float64(a1_m * a1_m) + Float64(a2 * a2)) * 0.5);
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (cos(th) <= -1e-310)
		tmp = -0.5 * (a2 ^ 2.0);
	else
		tmp = ((a1_m * a1_m) + (a2 * a2)) * 0.5;
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], -1e-310], N[(-0.5 * N[Power[a2, 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot {a2}^{2}\\

\mathbf{else}:\\
\;\;\;\;\left(a1_m \cdot a1_m + a2 \cdot a2\right) \cdot 0.5\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 12: 59.9% accurate, 3.7× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} t_1 := a1_m \cdot a1_m + a2 \cdot a2\\ \mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\ \;\;\;\;-0.5 \cdot t_1\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot 0.5\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (let* ((t_1 (+ (* a1_m a1_m) (* a2 a2))))
   (if (<= (cos th) -1e-310) (* -0.5 t_1) (* t_1 0.5))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double t_1 = (a1_m * a1_m) + (a2 * a2);
	double tmp;
	if (cos(th) <= -1e-310) {
		tmp = -0.5 * t_1;
	} else {
		tmp = t_1 * 0.5;
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: t_1
    real(8) :: tmp
    t_1 = (a1_m * a1_m) + (a2 * a2)
    if (cos(th) <= (-1d-310)) then
        tmp = (-0.5d0) * t_1
    else
        tmp = t_1 * 0.5d0
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double t_1 = (a1_m * a1_m) + (a2 * a2);
	double tmp;
	if (Math.cos(th) <= -1e-310) {
		tmp = -0.5 * t_1;
	} else {
		tmp = t_1 * 0.5;
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	t_1 = (a1_m * a1_m) + (a2 * a2)
	tmp = 0
	if math.cos(th) <= -1e-310:
		tmp = -0.5 * t_1
	else:
		tmp = t_1 * 0.5
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	t_1 = Float64(Float64(a1_m * a1_m) + Float64(a2 * a2))
	tmp = 0.0
	if (cos(th) <= -1e-310)
		tmp = Float64(-0.5 * t_1);
	else
		tmp = Float64(t_1 * 0.5);
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	t_1 = (a1_m * a1_m) + (a2 * a2);
	tmp = 0.0;
	if (cos(th) <= -1e-310)
		tmp = -0.5 * t_1;
	else
		tmp = t_1 * 0.5;
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := Block[{t$95$1 = N[(N[(a1$95$m * a1$95$m), $MachinePrecision] + N[(a2 * a2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Cos[th], $MachinePrecision], -1e-310], N[(-0.5 * t$95$1), $MachinePrecision], N[(t$95$1 * 0.5), $MachinePrecision]]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
t_1 := a1_m \cdot a1_m + a2 \cdot a2\\
\mathbf{if}\;\cos th \leq -1 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot t_1\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot 0.5\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 13: 9.2% accurate, 58.8× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \begin{array}{l} \mathbf{if}\;th \leq 26.5:\\ \;\;\;\;a2 + a1_m\\ \mathbf{else}:\\ \;\;\;\;a1_m - a2 \cdot a2\\ \end{array} \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (if (<= th 26.5) (+ a2 a1_m) (- a1_m (* a2 a2))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	double tmp;
	if (th <= 26.5) {
		tmp = a2 + a1_m;
	} else {
		tmp = a1_m - (a2 * a2);
	}
	return tmp;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (th <= 26.5d0) then
        tmp = a2 + a1_m
    else
        tmp = a1_m - (a2 * a2)
    end if
    code = tmp
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	double tmp;
	if (th <= 26.5) {
		tmp = a2 + a1_m;
	} else {
		tmp = a1_m - (a2 * a2);
	}
	return tmp;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	tmp = 0
	if th <= 26.5:
		tmp = a2 + a1_m
	else:
		tmp = a1_m - (a2 * a2)
	return tmp
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	tmp = 0.0
	if (th <= 26.5)
		tmp = Float64(a2 + a1_m);
	else
		tmp = Float64(a1_m - Float64(a2 * a2));
	end
	return tmp
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp_2 = code(a1_m, a2, th)
	tmp = 0.0;
	if (th <= 26.5)
		tmp = a2 + a1_m;
	else
		tmp = a1_m - (a2 * a2);
	end
	tmp_2 = tmp;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := If[LessEqual[th, 26.5], N[(a2 + a1$95$m), $MachinePrecision], N[(a1$95$m - N[(a2 * a2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\begin{array}{l}
\mathbf{if}\;th \leq 26.5:\\
\;\;\;\;a2 + a1_m\\

\mathbf{else}:\\
\;\;\;\;a1_m - a2 \cdot a2\\


\end{array}
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 14: 46.3% accurate, 59.3× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (* (+ a2 a1_m) (+ a2 a1_m)))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return (a2 + a1_m) * (a2 + a1_m);
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = (a2 + a1_m) * (a2 + a1_m)
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return (a2 + a1_m) * (a2 + a1_m);
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return (a2 + a1_m) * (a2 + a1_m)
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(Float64(a2 + a1_m) * Float64(a2 + a1_m))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = (a2 + a1_m) * (a2 + a1_m);
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[(a2 + a1$95$m), $MachinePrecision] * N[(a2 + a1$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\left(a2 + a1_m\right) \cdot \left(a2 + a1_m\right)
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 15: 4.7% accurate, 138.3× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ a2 + a1_m \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (+ a2 a1_m))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return a2 + a1_m;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 + a1_m
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return a2 + a1_m;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return a2 + a1_m
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(a2 + a1_m)
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = a2 + a1_m;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(a2 + a1$95$m), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
a2 + a1_m
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Alternative 16: 3.5% accurate, 415.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ 1 \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 1.0)
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return 1.0;
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = 1.0d0
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return 1.0;
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return 1.0
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return 1.0
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = 1.0;
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := 1.0
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
1
\end{array}
Derivation
    &prev;&pcontext;&pcontext2;&ctx;
  1. Add Preprocessing

Reproduce

?
herbie shell --seed 2023347 
(FPCore (a1 a2 th)
  :name "Migdal et al, Equation (64)"
  :precision binary64
  (+ (* (/ (cos th) (sqrt 2.0)) (* a1 a1)) (* (/ (cos th) (sqrt 2.0)) (* a2 a2))))