Migdal et al, Equation (64)

Percentage Accurate: 99.5% → 99.6%
Time: 12.8s
Alternatives: 15
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 15 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, 1.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \left(\left(\frac{\cos th}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{a2}\right)\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\left(\frac{\cos th}{\sqrt{2}} \cdot a2\right), \color{blue}{a2}\right)\right) \]
    3. associate-*l/N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\left(\frac{\cos th \cdot a2}{\sqrt{2}}\right), a2\right)\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(\cos th \cdot a2\right), \left(\sqrt{2}\right)\right), a2\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\cos th, a2\right), \left(\sqrt{2}\right)\right), a2\right)\right) \]
    6. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right), \left(\sqrt{2}\right)\right), a2\right)\right) \]
    7. sqrt-lowering-sqrt.f6499.6%

      \[\leadsto \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{*.f64}\left(a1, a1\right)\right), \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right), \mathsf{sqrt.f64}\left(2\right)\right), a2\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\frac{\cos th \cdot a2}{\sqrt{2}} \cdot a2} \]
  5. Final simplification99.6%

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + a2 \cdot \frac{\cos th \cdot a2}{\sqrt{2}} \]
  6. Add Preprocessing

Alternative 2: 99.6% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-outN/A

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    2. *-commutativeN/A

      \[\leadsto \left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \color{blue}{\frac{\cos th}{\sqrt{2}}} \]
    3. clear-numN/A

      \[\leadsto \left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \frac{1}{\color{blue}{\frac{\sqrt{2}}{\cos th}}} \]
    4. un-div-invN/A

      \[\leadsto \frac{a1 \cdot a1 + a2 \cdot a2}{\color{blue}{\frac{\sqrt{2}}{\cos th}}} \]
    5. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left(a1 \cdot a1 + a2 \cdot a2\right), \color{blue}{\left(\frac{\sqrt{2}}{\cos th}\right)}\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(a1 \cdot a1\right), \left(a2 \cdot a2\right)\right), \left(\frac{\color{blue}{\sqrt{2}}}{\cos th}\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\frac{\sqrt{\color{blue}{2}}}{\cos th}\right)\right) \]
    8. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \left(\frac{\sqrt{2}}{\cos th}\right)\right) \]
    9. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\cos th}\right)\right) \]
    10. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \cos \color{blue}{th}\right)\right) \]
    11. cos-lowering-cos.f6499.6%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{cos.f64}\left(th\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{a1 \cdot a1 + a2 \cdot a2}{\frac{\sqrt{2}}{\cos th}}} \]
  5. Add Preprocessing

Alternative 3: 99.6% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-outN/A

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    2. div-invN/A

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

      \[\leadsto \cos th \cdot \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    4. *-commutativeN/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right) \cdot \color{blue}{\cos th} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right), \color{blue}{\cos th}\right) \]
    6. associate-*l/N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1 \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)}{\sqrt{2}}\right), \cos \color{blue}{th}\right) \]
    7. *-lft-identityN/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\right), \cos th\right) \]
    8. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\left(a1 \cdot a1 + a2 \cdot a2\right), \left(\sqrt{2}\right)\right), \cos \color{blue}{th}\right) \]
    9. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(a1 \cdot a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right), \cos th\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right), \cos th\right) \]
    11. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \left(\sqrt{2}\right)\right), \cos th\right) \]
    12. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right), \cos th\right) \]
    13. cos-lowering-cos.f6499.6%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{cos.f64}\left(th\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}} \cdot \cos th} \]
  5. Final simplification99.6%

    \[\leadsto \cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}} \]
  6. Add Preprocessing

Alternative 4: 99.5% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-outN/A

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{\cos th}{\sqrt{2}}\right), \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\cos th, \left(\sqrt{2}\right)\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right) \]
    4. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\sqrt{2}\right)\right), \left(\color{blue}{a1} \cdot a1 + a2 \cdot a2\right)\right) \]
    5. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \left(a1 \cdot \color{blue}{a1} + a2 \cdot a2\right)\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right) \]
    8. *-lowering-*.f6499.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(2\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right) \]
  4. Applied egg-rr99.5%

    \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
  5. Add Preprocessing

Alternative 5: 99.1% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  5. Simplified56.3%

    \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. associate-*l*N/A

      \[\leadsto \frac{a2 \cdot \left(a2 \cdot \cos th\right)}{\sqrt{\color{blue}{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{a2 \cdot \left(\cos th \cdot a2\right)}{\sqrt{2}} \]
    3. associate-*r/N/A

      \[\leadsto a2 \cdot \color{blue}{\frac{\cos th \cdot a2}{\sqrt{2}}} \]
    4. clear-numN/A

      \[\leadsto a2 \cdot \frac{1}{\color{blue}{\frac{\sqrt{2}}{\cos th \cdot a2}}} \]
    5. un-div-invN/A

      \[\leadsto \frac{a2}{\color{blue}{\frac{\sqrt{2}}{\cos th \cdot a2}}} \]
    6. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(a2, \color{blue}{\left(\frac{\sqrt{2}}{\cos th \cdot a2}\right)}\right) \]
    7. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(\cos th \cdot a2\right)}\right)\right) \]
    8. sqrt-lowering-sqrt.f64N/A

      \[\leadsto \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right)\right) \]
    9. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right)\right) \]
    10. cos-lowering-cos.f6456.2%

      \[\leadsto \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right)\right) \]
  7. Applied egg-rr56.2%

    \[\leadsto \color{blue}{\frac{a2}{\frac{\sqrt{2}}{\cos th \cdot a2}}} \]
  8. Add Preprocessing

Alternative 6: 99.0% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  5. Simplified56.3%

    \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
    2. associate-/r/N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
    3. associate-*r*N/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\right) \cdot \color{blue}{\cos th} \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\right), \color{blue}{\cos th}\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \left(a2 \cdot a2\right)\right), \cos \color{blue}{th}\right) \]
    6. pow1/2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(a2 \cdot a2\right)\right), \cos th\right) \]
    7. pow-flipN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(a2 \cdot a2\right)\right), \cos th\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), \left(a2 \cdot a2\right)\right), \cos th\right) \]
    9. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(a2 \cdot a2\right)\right), \cos th\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(a2, a2\right)\right), \cos th\right) \]
    11. cos-lowering-cos.f6456.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{cos.f64}\left(th\right)\right) \]
  7. Applied egg-rr56.2%

    \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot \left(a2 \cdot a2\right)\right) \cdot \cos th} \]
  8. Taylor expanded in a2 around 0

    \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left({a2}^{2} \cdot \sqrt{\frac{1}{2}}\right)}, \mathsf{cos.f64}\left(th\right)\right) \]
  9. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \left(\sqrt{\frac{1}{2}}\right)\right), \mathsf{cos.f64}\left(\color{blue}{th}\right)\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\frac{1}{2}}\right)\right), \mathsf{cos.f64}\left(th\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\frac{1}{2}}\right)\right), \mathsf{cos.f64}\left(th\right)\right) \]
    4. sqrt-lowering-sqrt.f6456.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right), \mathsf{cos.f64}\left(th\right)\right) \]
  10. Simplified56.2%

    \[\leadsto \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right)} \cdot \cos th \]
  11. Final simplification56.2%

    \[\leadsto \cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right) \]
  12. Add Preprocessing

Alternative 7: 99.0% accurate, 2.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-outN/A

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    2. clear-numN/A

      \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
    3. associate-/r/N/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \cos th\right) \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
    4. associate-*l*N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)}\right) \]
    6. pow1/2N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    7. pow-flipN/A

      \[\leadsto \mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    8. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right)\right) \]
    11. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right) \]
    12. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
    14. *-lowering-*.f6499.6%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{{2}^{-0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
  5. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{{a2}^{2} \cdot \left(\cos th \cdot \sqrt{\frac{1}{2}}\right)} \]
  6. Step-by-step derivation
    1. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\cos th \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\left(a2 \cdot a2\right), \left(\color{blue}{\cos th} \cdot \sqrt{\frac{1}{2}}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\color{blue}{\cos th} \cdot \sqrt{\frac{1}{2}}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\sqrt{\color{blue}{\frac{1}{2}}}\right)\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
  7. Simplified56.2%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right)} \]
  8. Add Preprocessing

Alternative 8: 63.4% accurate, 3.1× speedup?

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

\mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\
\;\;\;\;a2\_m \cdot \left(a2\_m \cdot \sqrt{0.5}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2\_m \cdot a2\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < 2.99999999999999984e33

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
      2. clear-numN/A

        \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      3. associate-/r/N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \cos th\right) \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      4. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)}\right) \]
      6. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      7. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      8. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right)\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      14. *-lowering-*.f6499.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    4. Applied egg-rr99.5%

      \[\leadsto \color{blue}{{2}^{-0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    5. Taylor expanded in th around 0

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\color{blue}{\left(1 + {th}^{2} \cdot \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) - \frac{1}{2}\right)\right)}, \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left({th}^{2} \cdot \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{+.f64}\left(\color{blue}{\mathsf{*.f64}\left(a1, a1\right)}, \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({th}^{2}\right), \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, \color{blue}{a1}\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(th \cdot th\right), \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) - \frac{1}{2}\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      6. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) + \frac{-1}{2}\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      7. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \left(\frac{-1}{2} + {th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left({th}^{2}\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      10. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left(th \cdot th\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{1}{24}, \left(\frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      13. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{1}{24}, \left({th}^{2} \cdot \frac{-1}{720}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left({th}^{2}\right), \frac{-1}{720}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\left(th \cdot th\right), \frac{-1}{720}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
      16. *-lowering-*.f6467.0%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \mathsf{+.f64}\left(\frac{1}{24}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{720}\right)\right)\right)\right)\right)\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right)\right) \]
    7. Simplified67.0%

      \[\leadsto {2}^{-0.5} \cdot \left(\color{blue}{\left(1 + \left(th \cdot th\right) \cdot \left(-0.5 + \left(th \cdot th\right) \cdot \left(0.041666666666666664 + \left(th \cdot th\right) \cdot -0.001388888888888889\right)\right)\right)} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right) \]

    if 2.99999999999999984e33 < th < 2.00000000000000003e141

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6444.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified44.3%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
      2. associate-/r/N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
      3. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \color{blue}{\left(a2 \cdot \cos th\right)}\right) \]
      4. *-commutativeN/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \left(\cos th \cdot \color{blue}{a2}\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{\left(\cos th \cdot a2\right)} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot a2\right), \color{blue}{\left(\cos th \cdot a2\right)}\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), a2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right) \]
      8. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      9. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      11. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right) \]
      13. cos-lowering-cos.f6444.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right) \]
    7. Applied egg-rr44.3%

      \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot a2\right) \cdot \left(\cos th \cdot a2\right)} \]
    8. Taylor expanded in th around 0

      \[\leadsto \color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{2}}} \]
    9. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1}{2}}} \]
      2. associate-*l*N/A

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
      5. sqrt-lowering-sqrt.f6412.8%

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
    10. Simplified12.8%

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]

    if 2.00000000000000003e141 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6439.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified39.4%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      4. sqrt-lowering-sqrt.f6413.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    8. Simplified13.0%

      \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
    9. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}} \]
      2. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \color{blue}{\left(\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)\right)}\right) \]
      5. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(0 - \color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      9. *-lowering-*.f6417.2%

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    10. Applied egg-rr17.2%

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a2 \cdot a2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification56.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 3 \cdot 10^{+33}:\\ \;\;\;\;{2}^{-0.5} \cdot \left(\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \left(1 + \left(th \cdot th\right) \cdot \left(-0.5 + \left(th \cdot th\right) \cdot \left(0.041666666666666664 + \left(th \cdot th\right) \cdot -0.001388888888888889\right)\right)\right)\right)\\ \mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 64.0% accurate, 3.4× speedup?

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

\mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\
\;\;\;\;a2\_m \cdot \left(a2\_m \cdot \sqrt{0.5}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2\_m \cdot a2\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < 2.99999999999999984e33

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
      2. clear-numN/A

        \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      3. associate-/r/N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \cos th\right) \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      4. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)}\right) \]
      6. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      7. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      8. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right)\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      14. *-lowering-*.f6499.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    4. Applied egg-rr99.5%

      \[\leadsto \color{blue}{{2}^{-0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    5. Taylor expanded in th around 0

      \[\leadsto \color{blue}{\frac{-1}{2} \cdot \left({th}^{2} \cdot \left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) + \sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)} \]
    6. Step-by-step derivation
      1. associate-*r*N/A

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

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

        \[\leadsto \left(1 + \frac{-1}{2} \cdot {th}^{2}\right) \cdot \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(1 + \frac{-1}{2} \cdot {th}^{2}\right), \color{blue}{\left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)}\right) \]
      5. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(\frac{-1}{2} \cdot {th}^{2}\right)\right), \left(\color{blue}{\sqrt{\frac{1}{2}}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) \]
      6. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left({th}^{2} \cdot \frac{-1}{2}\right)\right), \left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({th}^{2}\right), \frac{-1}{2}\right)\right), \left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) \]
      8. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(th \cdot th\right), \frac{-1}{2}\right)\right), \left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \left(\sqrt{\frac{1}{2}} \cdot \left({a1}^{2} + {a2}^{2}\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \left(\left({a1}^{2} + {a2}^{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}}\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\left({a1}^{2} + {a2}^{2}\right), \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left({a1}^{2}\right), \left({a2}^{2}\right)\right), \left(\sqrt{\color{blue}{\frac{1}{2}}}\right)\right)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left(a1 \cdot a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right)\right) \]
      15. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right)\right) \]
      16. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right)\right) \]
      17. sqrt-lowering-sqrt.f6469.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right), \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
    7. Simplified69.3%

      \[\leadsto \color{blue}{\left(1 + \left(th \cdot th\right) \cdot -0.5\right) \cdot \left(\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}\right)} \]

    if 2.99999999999999984e33 < th < 2.00000000000000003e141

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6444.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified44.3%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
      2. associate-/r/N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
      3. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \color{blue}{\left(a2 \cdot \cos th\right)}\right) \]
      4. *-commutativeN/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \left(\cos th \cdot \color{blue}{a2}\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{\left(\cos th \cdot a2\right)} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot a2\right), \color{blue}{\left(\cos th \cdot a2\right)}\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), a2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right) \]
      8. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      9. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      11. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right) \]
      13. cos-lowering-cos.f6444.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right) \]
    7. Applied egg-rr44.3%

      \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot a2\right) \cdot \left(\cos th \cdot a2\right)} \]
    8. Taylor expanded in th around 0

      \[\leadsto \color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{2}}} \]
    9. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1}{2}}} \]
      2. associate-*l*N/A

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
      5. sqrt-lowering-sqrt.f6412.8%

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
    10. Simplified12.8%

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]

    if 2.00000000000000003e141 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6439.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified39.4%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      4. sqrt-lowering-sqrt.f6413.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    8. Simplified13.0%

      \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
    9. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}} \]
      2. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \color{blue}{\left(\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)\right)}\right) \]
      5. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(0 - \color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      9. *-lowering-*.f6417.2%

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    10. Applied egg-rr17.2%

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a2 \cdot a2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification58.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 3 \cdot 10^{+33}:\\ \;\;\;\;\left(1 + -0.5 \cdot \left(th \cdot th\right)\right) \cdot \left(\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}\right)\\ \mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 63.1% accurate, 3.5× speedup?

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

\mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\
\;\;\;\;a2\_m \cdot \left(a2\_m \cdot \sqrt{0.5}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2\_m \cdot a2\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if th < 2.99999999999999984e33

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6459.7%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified59.7%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Taylor expanded in th around 0

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \color{blue}{\left(1 + \frac{-1}{2} \cdot {th}^{2}\right)}\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    7. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{+.f64}\left(1, \left(\frac{-1}{2} \cdot {th}^{2}\right)\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
      2. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{+.f64}\left(1, \left({th}^{2} \cdot \frac{-1}{2}\right)\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left({th}^{2}\right), \frac{-1}{2}\right)\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(th \cdot th\right), \frac{-1}{2}\right)\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
      5. *-lowering-*.f6443.5%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    8. Simplified43.5%

      \[\leadsto \frac{\left(a2 \cdot a2\right) \cdot \color{blue}{\left(1 + \left(th \cdot th\right) \cdot -0.5\right)}}{\sqrt{2}} \]
    9. Step-by-step derivation
      1. associate-/l*N/A

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

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \frac{1 + \left(th \cdot th\right) \cdot \frac{-1}{2}}{\sqrt{2}}\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \frac{1 + \left(th \cdot th\right) \cdot \frac{-1}{2}}{\sqrt{2}}\right)}\right) \]
      4. clear-numN/A

        \[\leadsto \mathsf{*.f64}\left(a2, \left(a2 \cdot \frac{1}{\color{blue}{\frac{\sqrt{2}}{1 + \left(th \cdot th\right) \cdot \frac{-1}{2}}}}\right)\right) \]
      5. un-div-invN/A

        \[\leadsto \mathsf{*.f64}\left(a2, \left(\frac{a2}{\color{blue}{\frac{\sqrt{2}}{1 + \left(th \cdot th\right) \cdot \frac{-1}{2}}}}\right)\right) \]
      6. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \color{blue}{\left(\frac{\sqrt{2}}{1 + \left(th \cdot th\right) \cdot \frac{-1}{2}}\right)}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(1 + \left(th \cdot th\right) \cdot \frac{-1}{2}\right)}\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{1} + \left(th \cdot th\right) \cdot \frac{-1}{2}\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{+.f64}\left(1, \color{blue}{\left(\left(th \cdot th\right) \cdot \frac{-1}{2}\right)}\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\left(th \cdot th\right), \color{blue}{\frac{-1}{2}}\right)\right)\right)\right)\right) \]
      11. *-lowering-*.f6442.7%

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{/.f64}\left(a2, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{+.f64}\left(1, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{-1}{2}\right)\right)\right)\right)\right) \]
    10. Applied egg-rr42.7%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\frac{\sqrt{2}}{1 + \left(th \cdot th\right) \cdot -0.5}}} \]

    if 2.99999999999999984e33 < th < 2.00000000000000003e141

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6444.3%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified44.3%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
      2. associate-/r/N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
      3. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \color{blue}{\left(a2 \cdot \cos th\right)}\right) \]
      4. *-commutativeN/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \left(\cos th \cdot \color{blue}{a2}\right)\right) \]
      5. associate-*r*N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{\left(\cos th \cdot a2\right)} \]
      6. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot a2\right), \color{blue}{\left(\cos th \cdot a2\right)}\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), a2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right) \]
      8. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      9. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      10. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
      11. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right) \]
      13. cos-lowering-cos.f6444.3%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right) \]
    7. Applied egg-rr44.3%

      \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot a2\right) \cdot \left(\cos th \cdot a2\right)} \]
    8. Taylor expanded in th around 0

      \[\leadsto \color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{2}}} \]
    9. Step-by-step derivation
      1. unpow2N/A

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1}{2}}} \]
      2. associate-*l*N/A

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)} \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
      5. sqrt-lowering-sqrt.f6412.8%

        \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
    10. Simplified12.8%

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]

    if 2.00000000000000003e141 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6439.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified39.4%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      4. sqrt-lowering-sqrt.f6413.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    8. Simplified13.0%

      \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
    9. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}} \]
      2. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \color{blue}{\left(\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)\right)}\right) \]
      5. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(0 - \color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      9. *-lowering-*.f6417.2%

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    10. Applied egg-rr17.2%

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a2 \cdot a2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification36.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 3 \cdot 10^{+33}:\\ \;\;\;\;a2 \cdot \frac{a2}{\frac{\sqrt{2}}{1 + -0.5 \cdot \left(th \cdot th\right)}}\\ \mathbf{elif}\;th \leq 2 \cdot 10^{+141}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 66.1% accurate, 3.6× speedup?

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

\mathbf{else}:\\
\;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2\_m \cdot a2\_m}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 2.00000000000000003e141

    1. Initial program 99.5%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. distribute-lft-outN/A

        \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
      2. clear-numN/A

        \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      3. associate-/r/N/A

        \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \cos th\right) \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
      4. associate-*l*N/A

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)}\right) \]
      6. pow1/2N/A

        \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      7. pow-flipN/A

        \[\leadsto \mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      8. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right)\right) \]
      11. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      14. *-lowering-*.f6499.6%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \color{blue}{{2}^{-0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    5. Taylor expanded in th around 0

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

        \[\leadsto \left({a1}^{2} + {a2}^{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}} \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\left({a1}^{2} + {a2}^{2}\right), \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left({a1}^{2}\right), \left({a2}^{2}\right)\right), \left(\sqrt{\color{blue}{\frac{1}{2}}}\right)\right) \]
      4. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left(a1 \cdot a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
      6. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
      8. sqrt-lowering-sqrt.f6468.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right) \]
    7. Simplified68.1%

      \[\leadsto \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}} \]

    if 2.00000000000000003e141 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Add Preprocessing
    3. Taylor expanded in a1 around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      4. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
      5. cos-lowering-cos.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
      6. sqrt-lowering-sqrt.f6439.4%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    5. Simplified39.4%

      \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
    6. Taylor expanded in th around 0

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    7. Step-by-step derivation
      1. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
      4. sqrt-lowering-sqrt.f6413.0%

        \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
    8. Simplified13.0%

      \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
    9. Step-by-step derivation
      1. clear-numN/A

        \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}} \]
      2. frac-2negN/A

        \[\leadsto \frac{\mathsf{neg}\left(1\right)}{\color{blue}{\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}} \]
      3. metadata-evalN/A

        \[\leadsto \frac{-1}{\mathsf{neg}\left(\color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)} \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \color{blue}{\left(\mathsf{neg}\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)\right)}\right) \]
      5. neg-sub0N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \left(0 - \color{blue}{\frac{\sqrt{2}}{a2 \cdot a2}}\right)\right) \]
      6. --lowering--.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a2 \cdot a2}\right)}\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\left(\sqrt{2}\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
      8. sqrt-lowering-sqrt.f64N/A

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
      9. *-lowering-*.f6417.2%

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \mathsf{/.f64}\left(\mathsf{sqrt.f64}\left(2\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
    10. Applied egg-rr17.2%

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a2 \cdot a2}}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification62.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 2 \cdot 10^{+141}:\\ \;\;\;\;\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;\frac{0 - -1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 66.1% accurate, 3.8× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. distribute-lft-outN/A

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    2. clear-numN/A

      \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
    3. associate-/r/N/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot \cos th\right) \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
    4. associate-*l*N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), \color{blue}{\left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)}\right) \]
    6. pow1/2N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    7. pow-flipN/A

      \[\leadsto \mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    8. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \left(\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    9. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)\right) \]
    10. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\cos th, \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}\right)\right) \]
    11. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right) \]
    12. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot a2\right)}\right)\right)\right) \]
    13. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
    14. *-lowering-*.f6499.6%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \color{blue}{{2}^{-0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right)} \]
  5. Taylor expanded in th around 0

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

      \[\leadsto \left({a1}^{2} + {a2}^{2}\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left({a1}^{2} + {a2}^{2}\right), \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right) \]
    3. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left({a1}^{2}\right), \left({a2}^{2}\right)\right), \left(\sqrt{\color{blue}{\frac{1}{2}}}\right)\right) \]
    4. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\left(a1 \cdot a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
    5. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left({a2}^{2}\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
    6. unpow2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \left(\sqrt{\frac{1}{2}}\right)\right) \]
    8. sqrt-lowering-sqrt.f6463.3%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right) \]
  7. Simplified63.3%

    \[\leadsto \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  8. Add Preprocessing

Alternative 13: 65.8% accurate, 4.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  5. Simplified56.3%

    \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
  6. Taylor expanded in th around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  7. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    4. sqrt-lowering-sqrt.f6439.2%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  8. Simplified39.2%

    \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
  9. Step-by-step derivation
    1. associate-/l*N/A

      \[\leadsto a2 \cdot \color{blue}{\frac{a2}{\sqrt{2}}} \]
    2. *-commutativeN/A

      \[\leadsto \frac{a2}{\sqrt{2}} \cdot \color{blue}{a2} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{a2}{\sqrt{2}}\right), \color{blue}{a2}\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a2, \left(\sqrt{2}\right)\right), a2\right) \]
    5. sqrt-lowering-sqrt.f6439.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(a2, \mathsf{sqrt.f64}\left(2\right)\right), a2\right) \]
  10. Applied egg-rr39.2%

    \[\leadsto \color{blue}{\frac{a2}{\sqrt{2}} \cdot a2} \]
  11. Final simplification39.2%

    \[\leadsto a2 \cdot \frac{a2}{\sqrt{2}} \]
  12. Add Preprocessing

Alternative 14: 65.8% accurate, 4.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  5. Simplified56.3%

    \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
    2. associate-/r/N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
    3. associate-*l*N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \color{blue}{\left(a2 \cdot \cos th\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \left(\cos th \cdot \color{blue}{a2}\right)\right) \]
    5. associate-*r*N/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{\left(\cos th \cdot a2\right)} \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot a2\right), \color{blue}{\left(\cos th \cdot a2\right)}\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), a2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right) \]
    8. pow1/2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
    9. pow-flipN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
    11. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right) \]
    13. cos-lowering-cos.f6456.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right) \]
  7. Applied egg-rr56.2%

    \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot a2\right) \cdot \left(\cos th \cdot a2\right)} \]
  8. Taylor expanded in th around 0

    \[\leadsto \color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{2}}} \]
  9. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1}{2}}} \]
    2. associate-*l*N/A

      \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
    5. sqrt-lowering-sqrt.f6439.2%

      \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
  10. Simplified39.2%

    \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  11. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{2}}} \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(a2 \cdot a2\right), \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right) \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{\frac{1}{2}}}\right)\right) \]
    4. sqrt-lowering-sqrt.f6439.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right) \]
  12. Applied egg-rr39.2%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  13. Add Preprocessing

Alternative 15: 65.8% accurate, 4.0× speedup?

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

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Add Preprocessing
  3. Taylor expanded in a1 around 0

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\left({a2}^{2} \cdot \cos th\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    2. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left({a2}^{2}\right), \cos th\right), \left(\sqrt{\color{blue}{2}}\right)\right) \]
    3. unpow2N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\left(a2 \cdot a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \cos th\right), \left(\sqrt{2}\right)\right) \]
    5. cos-lowering-cos.f64N/A

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \left(\sqrt{2}\right)\right) \]
    6. sqrt-lowering-sqrt.f6456.3%

      \[\leadsto \mathsf{/.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(2\right)\right) \]
  5. Simplified56.3%

    \[\leadsto \color{blue}{\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\sqrt{2}}{\left(a2 \cdot a2\right) \cdot \cos th}}} \]
    2. associate-/r/N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(\left(a2 \cdot a2\right) \cdot \cos th\right)} \]
    3. associate-*l*N/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \color{blue}{\left(a2 \cdot \cos th\right)}\right) \]
    4. *-commutativeN/A

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \left(a2 \cdot \left(\cos th \cdot \color{blue}{a2}\right)\right) \]
    5. associate-*r*N/A

      \[\leadsto \left(\frac{1}{\sqrt{2}} \cdot a2\right) \cdot \color{blue}{\left(\cos th \cdot a2\right)} \]
    6. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot a2\right), \color{blue}{\left(\cos th \cdot a2\right)}\right) \]
    7. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}}\right), a2\right), \left(\color{blue}{\cos th} \cdot a2\right)\right) \]
    8. pow1/2N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left(\frac{1}{{2}^{\frac{1}{2}}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
    9. pow-flipN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
    10. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\left({2}^{\frac{-1}{2}}\right), a2\right), \left(\cos th \cdot a2\right)\right) \]
    11. pow-lowering-pow.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \left(\cos \color{blue}{th} \cdot a2\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\cos th, \color{blue}{a2}\right)\right) \]
    13. cos-lowering-cos.f6456.2%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{pow.f64}\left(2, \frac{-1}{2}\right), a2\right), \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), a2\right)\right) \]
  7. Applied egg-rr56.2%

    \[\leadsto \color{blue}{\left({2}^{-0.5} \cdot a2\right) \cdot \left(\cos th \cdot a2\right)} \]
  8. Taylor expanded in th around 0

    \[\leadsto \color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{2}}} \]
  9. Step-by-step derivation
    1. unpow2N/A

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1}{2}}} \]
    2. associate-*l*N/A

      \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(a2, \color{blue}{\left(a2 \cdot \sqrt{\frac{1}{2}}\right)}\right) \]
    4. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \color{blue}{\left(\sqrt{\frac{1}{2}}\right)}\right)\right) \]
    5. sqrt-lowering-sqrt.f6439.2%

      \[\leadsto \mathsf{*.f64}\left(a2, \mathsf{*.f64}\left(a2, \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right)\right) \]
  10. Simplified39.2%

    \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  11. Add Preprocessing

Reproduce

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