Migdal et al, Equation (64)

Percentage Accurate: 99.6% → 99.6%
Time: 12.4s
Alternatives: 14
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 14 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.6% 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| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \frac{\cos th}{\sqrt{2}} \cdot \left(a1\_m \cdot a1\_m\right) + \left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a2 \cdot a2\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th)
 :precision binary64
 (+
  (* (/ (cos th) (sqrt 2.0)) (* a1_m a1_m))
  (* (* (cos th) (pow 2.0 -0.5)) (* a2 a2))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return ((cos(th) / sqrt(2.0)) * (a1_m * a1_m)) + ((cos(th) * pow(2.0, -0.5)) * (a2 * a2));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = ((cos(th) / sqrt(2.0d0)) * (a1_m * a1_m)) + ((cos(th) * (2.0d0 ** (-0.5d0))) * (a2 * a2))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return ((Math.cos(th) / Math.sqrt(2.0)) * (a1_m * a1_m)) + ((Math.cos(th) * Math.pow(2.0, -0.5)) * (a2 * a2));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return ((math.cos(th) / math.sqrt(2.0)) * (a1_m * a1_m)) + ((math.cos(th) * math.pow(2.0, -0.5)) * (a2 * a2))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(Float64(Float64(cos(th) / sqrt(2.0)) * Float64(a1_m * a1_m)) + Float64(Float64(cos(th) * (2.0 ^ -0.5)) * Float64(a2 * a2)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = ((cos(th) / sqrt(2.0)) * (a1_m * a1_m)) + ((cos(th) * (2.0 ^ -0.5)) * (a2 * a2));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(a1$95$m * a1$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[th], $MachinePrecision] * N[Power[2.0, -0.5], $MachinePrecision]), $MachinePrecision] * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\frac{\cos th}{\sqrt{2}} \cdot \left(a1\_m \cdot a1\_m\right) + \left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a2 \cdot a2\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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
  4. Applied egg-rr99.6%

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

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

Alternative 2: 99.6% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. associate-*r/N/A

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

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

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

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

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

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

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

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

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

Alternative 3: 99.6% accurate, 2.0× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
  3. Simplified99.5%

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

Alternative 4: 78.5% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ a2 \cdot \left(\left(\cos th \cdot a2\right) \cdot \sqrt{0.5}\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (* a2 (* (* (cos th) a2) (sqrt 0.5))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return a2 * ((cos(th) * a2) * sqrt(0.5));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 * ((cos(th) * a2) * sqrt(0.5d0))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return a2 * ((Math.cos(th) * a2) * Math.sqrt(0.5));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return a2 * ((math.cos(th) * a2) * math.sqrt(0.5))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(a2 * Float64(Float64(cos(th) * a2) * sqrt(0.5)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = a2 * ((cos(th) * a2) * sqrt(0.5));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(a2 * N[(N[(N[Cos[th], $MachinePrecision] * a2), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
a2 \cdot \left(\left(\cos th \cdot a2\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. Step-by-step derivation
    1. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{*.f64}\left(\mathsf{*.f64}\left(a2, \mathsf{cos.f64}\left(th\right)\right), \mathsf{sqrt.f64}\left(\frac{1}{2}\right)\right), a2\right) \]
  9. Applied egg-rr55.0%

    \[\leadsto \color{blue}{\left(\left(a2 \cdot \cos th\right) \cdot \sqrt{0.5}\right) \cdot a2} \]
  10. Final simplification55.0%

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

Alternative 5: 78.5% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \left(a2 \cdot a2\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (* (* a2 a2) (* (cos th) (sqrt 0.5))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return (a2 * a2) * (cos(th) * sqrt(0.5));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = (a2 * a2) * (cos(th) * sqrt(0.5d0))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return (a2 * a2) * (Math.cos(th) * Math.sqrt(0.5));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return (a2 * a2) * (math.cos(th) * math.sqrt(0.5))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(Float64(a2 * a2) * Float64(cos(th) * sqrt(0.5)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = (a2 * a2) * (cos(th) * sqrt(0.5));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[(a2 * a2), $MachinePrecision] * N[(N[Cos[th], $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\left(a2 \cdot a2\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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\right)} \]
  8. Final simplification55.0%

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

Alternative 6: 78.5% accurate, 2.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ \cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (* (cos th) (* (* a2 a2) (sqrt 0.5))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return cos(th) * ((a2 * a2) * sqrt(0.5));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = cos(th) * ((a2 * a2) * sqrt(0.5d0))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return Math.cos(th) * ((a2 * a2) * Math.sqrt(0.5));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return math.cos(th) * ((a2 * a2) * math.sqrt(0.5))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(cos(th) * Float64(Float64(a2 * a2) * sqrt(0.5)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = cos(th) * ((a2 * a2) * sqrt(0.5));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(N[Cos[th], $MachinePrecision] * N[(N[(a2 * a2), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
\cos th \cdot \left(\left(a2 \cdot a2\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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. clear-numN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \mathsf{*.f64}\left(\mathsf{sqrt.f64}\left(\frac{1}{2}\right), \mathsf{*.f64}\left(a2, \color{blue}{a2}\right)\right)\right) \]
  9. Simplified55.0%

    \[\leadsto \cos th \cdot \color{blue}{\left(\sqrt{0.5} \cdot \left(a2 \cdot a2\right)\right)} \]
  10. Final simplification55.0%

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

Alternative 7: 64.3% accurate, 3.1× speedup?

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

\mathbf{elif}\;th \leq 4.8 \cdot 10^{+141}:\\
\;\;\;\;\frac{-1}{\frac{0 - \sqrt{2}}{t\_1}}\\

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


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

    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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

      \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(\left(th \cdot th\right) \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(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-*l*N/A

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) + \frac{-1}{2}\right)\right)\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(2\right)\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{-1}{2} + {th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\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(2\right)\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      15. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      18. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      19. *-lowering-*.f6469.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
    7. Simplified69.5%

      \[\leadsto \color{blue}{\left(1 + th \cdot \left(th \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)} \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}} \]
    8. Step-by-step derivation
      1. associate-*r/N/A

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

        \[\leadsto \mathsf{/.f64}\left(\left(\left(1 + th \cdot \left(th \cdot \left(\frac{-1}{2} + \left(th \cdot th\right) \cdot \left(\frac{1}{24} + \left(th \cdot th\right) \cdot \frac{-1}{720}\right)\right)\right)\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right), \color{blue}{\left(\sqrt{2}\right)}\right) \]
    9. Applied egg-rr69.5%

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

    if 910 < th < 4.79999999999999995e141

    1. Initial program 99.4%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right) \]
      6. *-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{2}\right)\right) \]
      7. sqrt-lowering-sqrt.f6417.4%

        \[\leadsto \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) \]
    7. Simplified17.4%

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a1 \cdot a1 + 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(a1 \cdot a1 + 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}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}} \]

    if 4.79999999999999995e141 < th

    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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6418.7%

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

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification53.8%

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

Alternative 8: 64.3% accurate, 3.1× speedup?

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

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


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

    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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

      \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(\left(th \cdot th\right) \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(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-*l*N/A

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) + \frac{-1}{2}\right)\right)\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(2\right)\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{-1}{2} + {th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\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(2\right)\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      15. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      18. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      19. *-lowering-*.f6469.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
    7. Simplified69.5%

      \[\leadsto \color{blue}{\left(1 + th \cdot \left(th \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)} \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}} \]

    if 910 < th < 4.79999999999999995e141

    1. Initial program 99.4%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right) \]
      6. *-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{2}\right)\right) \]
      7. sqrt-lowering-sqrt.f6417.4%

        \[\leadsto \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) \]
    7. Simplified17.4%

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a1 \cdot a1 + 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(a1 \cdot a1 + 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}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}} \]

    if 4.79999999999999995e141 < th

    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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6418.7%

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

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification53.8%

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

Alternative 9: 53.0% accurate, 3.2× speedup?

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

\mathbf{elif}\;th \leq 4.8 \cdot 10^{+141}:\\
\;\;\;\;\frac{-1}{\frac{0 - \sqrt{2}}{a1\_m \cdot a1\_m + a2 \cdot a2}}\\

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


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

    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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

      \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

        \[\leadsto \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(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(a2, a2\right)\right)}, \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \left(\left(th \cdot th\right) \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(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
      3. associate-*l*N/A

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      9. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left({th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right) + \frac{-1}{2}\right)\right)\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(2\right)\right)\right) \]
      10. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{-1}{2} + {th}^{2} \cdot \left(\frac{1}{24} + \frac{-1}{720} \cdot {th}^{2}\right)\right)\right)\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(2\right)\right)\right) \]
      11. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      12. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      13. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      14. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      15. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      16. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      17. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      18. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
      19. *-lowering-*.f6469.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \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)\right) \]
    7. Simplified69.5%

      \[\leadsto \color{blue}{\left(1 + th \cdot \left(th \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)} \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}} \]
    8. Taylor expanded in a1 around 0

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \mathsf{/.f64}\left(\left({a2}^{2}\right), \color{blue}{\left(\sqrt{2}\right)}\right)\right) \]
      2. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \mathsf{/.f64}\left(\left(a2 \cdot a2\right), \left(\sqrt{\color{blue}{2}}\right)\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \left(\sqrt{\color{blue}{2}}\right)\right)\right) \]
      4. sqrt-lowering-sqrt.f6443.5%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \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)\right), \mathsf{/.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{sqrt.f64}\left(2\right)\right)\right) \]
    10. Simplified43.5%

      \[\leadsto \left(1 + th \cdot \left(th \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) \cdot \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]

    if 910 < th < 4.79999999999999995e141

    1. Initial program 99.4%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.4%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right) \]
      6. *-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{2}\right)\right) \]
      7. sqrt-lowering-sqrt.f6417.4%

        \[\leadsto \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) \]
    7. Simplified17.4%

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a1 \cdot a1 + 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(a1 \cdot a1 + 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}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}} \]

    if 4.79999999999999995e141 < th

    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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6418.7%

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

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification35.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 910:\\ \;\;\;\;\left(1 + th \cdot \left(th \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) \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 4.8 \cdot 10^{+141}:\\ \;\;\;\;\frac{-1}{\frac{0 - \sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 64.0% accurate, 3.2× speedup?

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

\mathbf{elif}\;th \leq 4.8 \cdot 10^{+141}:\\
\;\;\;\;\frac{-1}{\frac{0 - \sqrt{2}}{t\_1}}\\

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


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

    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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

      \[\leadsto \mathsf{*.f64}\left(\color{blue}{\left(1 + {th}^{2} \cdot \left(\frac{1}{24} \cdot {th}^{2} - \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(2\right)\right)\right) \]
    6. Step-by-step derivation
      1. +-lowering-+.f64N/A

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{1}{24} \cdot {th}^{2} + \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right)\right)\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(2\right)\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{1}{24} \cdot {th}^{2} + \frac{-1}{2}\right)\right)\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(2\right)\right)\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \left(\frac{-1}{2} + \frac{1}{24} \cdot {th}^{2}\right)\right)\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(2\right)\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \mathsf{+.f64}\left(\frac{-1}{2}, \left(\frac{1}{24} \cdot {th}^{2}\right)\right)\right)\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(2\right)\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \mathsf{+.f64}\left(\frac{-1}{2}, \left({th}^{2} \cdot \frac{1}{24}\right)\right)\right)\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(2\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left({th}^{2}\right), \frac{1}{24}\right)\right)\right)\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(2\right)\right)\right) \]
      12. unpow2N/A

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\left(th \cdot th\right), \frac{1}{24}\right)\right)\right)\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(2\right)\right)\right) \]
      13. *-lowering-*.f6471.1%

        \[\leadsto \mathsf{*.f64}\left(\mathsf{+.f64}\left(1, \mathsf{*.f64}\left(th, \mathsf{*.f64}\left(th, \mathsf{+.f64}\left(\frac{-1}{2}, \mathsf{*.f64}\left(\mathsf{*.f64}\left(th, th\right), \frac{1}{24}\right)\right)\right)\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(2\right)\right)\right) \]
    7. Simplified71.1%

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

    if 196 < th < 4.79999999999999995e141

    1. Initial program 99.4%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.3%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right) \]
      6. *-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{2}\right)\right) \]
      7. sqrt-lowering-sqrt.f6417.2%

        \[\leadsto \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) \]
    7. Simplified17.2%

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

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

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

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

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

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

        \[\leadsto \mathsf{/.f64}\left(-1, \mathsf{\_.f64}\left(0, \color{blue}{\left(\frac{\sqrt{2}}{a1 \cdot a1 + 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(a1 \cdot a1 + 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}{a1 \cdot a1} + a2 \cdot a2\right)\right)\right)\right) \]
      9. +-lowering-+.f64N/A

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

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

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

      \[\leadsto \color{blue}{\frac{-1}{0 - \frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}} \]

    if 4.79999999999999995e141 < th

    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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6418.7%

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

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification54.7%

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

Alternative 11: 64.3% accurate, 3.4× speedup?

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

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


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

    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. 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. associate-*l/N/A

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. Add Preprocessing
    5. Taylor expanded in th around 0

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \left(\frac{-1}{2} \cdot {th}^{2}\right) \cdot \left(\frac{{a1}^{2}}{\sqrt{2}} + \frac{1 \cdot {a2}^{2}}{\sqrt{2}}\right) + \left(\frac{{a1}^{2}}{\sqrt{2}} + \frac{{a2}^{2}}{\sqrt{2}}\right) \]
      11. *-lft-identityN/A

        \[\leadsto \left(\frac{-1}{2} \cdot {th}^{2}\right) \cdot \left(\frac{{a1}^{2}}{\sqrt{2}} + \frac{{a2}^{2}}{\sqrt{2}}\right) + \left(\frac{{a1}^{2}}{\sqrt{2}} + \frac{{a2}^{2}}{\sqrt{2}}\right) \]
    7. Simplified62.5%

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

    if 4.79999999999999995e141 < th

    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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
      4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
      8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    4. Applied egg-rr99.6%

      \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6418.7%

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

      \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification56.0%

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

Alternative 12: 66.6% accurate, 3.8× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
  4. Add Preprocessing
  5. Taylor expanded in th around 0

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

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

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

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

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

      \[\leadsto \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(a2 \cdot a2\right)\right), \left(\sqrt{2}\right)\right) \]
    6. *-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{2}\right)\right) \]
    7. sqrt-lowering-sqrt.f6460.4%

      \[\leadsto \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) \]
  7. Simplified60.4%

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

Alternative 13: 66.6% accurate, 3.8× speedup?

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{cos.f64}\left(th\right), \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)\right) \]
  3. Simplified99.5%

    \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
  4. Add Preprocessing
  5. Step-by-step derivation
    1. associate-*r/N/A

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

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

      \[\leadsto \frac{1}{\frac{\sqrt{2}}{\cos th}} \cdot \left(\color{blue}{a1 \cdot a1} + a2 \cdot a2\right) \]
    4. 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) \]
    5. 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)} \]
    6. *-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) \]
    7. 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) \]
    8. 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) \]
    9. 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) \]
    10. 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) \]
    11. *-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) \]
    12. 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) \]
    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(\left(a1 \cdot a1\right), \color{blue}{\left(a2 \cdot 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{cos.f64}\left(th\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a1, a1\right), \left(\color{blue}{a2} \cdot a2\right)\right)\right)\right) \]
    15. *-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) \]
  6. Applied egg-rr99.5%

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{*.f64}\left(\mathsf{sqrt.f64}\left(\frac{1}{2}\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(a2, a2\right), \mathsf{*.f64}\left(a1, \color{blue}{a1}\right)\right)\right) \]
  9. Simplified60.4%

    \[\leadsto \color{blue}{\sqrt{0.5} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right)} \]
  10. Final simplification60.4%

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

Alternative 14: 53.3% accurate, 4.0× speedup?

\[\begin{array}{l} a1_m = \left|a1\right| \\ [a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\ \\ a2 \cdot \left(a2 \cdot \sqrt{0.5}\right) \end{array} \]
a1_m = (fabs.f64 a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
(FPCore (a1_m a2 th) :precision binary64 (* a2 (* a2 (sqrt 0.5))))
a1_m = fabs(a1);
assert(a1_m < a2 && a2 < th);
double code(double a1_m, double a2, double th) {
	return a2 * (a2 * sqrt(0.5));
}
a1_m = abs(a1)
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
real(8) function code(a1_m, a2, th)
    real(8), intent (in) :: a1_m
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 * (a2 * sqrt(0.5d0))
end function
a1_m = Math.abs(a1);
assert a1_m < a2 && a2 < th;
public static double code(double a1_m, double a2, double th) {
	return a2 * (a2 * Math.sqrt(0.5));
}
a1_m = math.fabs(a1)
[a1_m, a2, th] = sort([a1_m, a2, th])
def code(a1_m, a2, th):
	return a2 * (a2 * math.sqrt(0.5))
a1_m = abs(a1)
a1_m, a2, th = sort([a1_m, a2, th])
function code(a1_m, a2, th)
	return Float64(a2 * Float64(a2 * sqrt(0.5)))
end
a1_m = abs(a1);
a1_m, a2, th = num2cell(sort([a1_m, a2, th])){:}
function tmp = code(a1_m, a2, th)
	tmp = a2 * (a2 * sqrt(0.5));
end
a1_m = N[Abs[a1], $MachinePrecision]
NOTE: a1_m, a2, and th should be sorted in increasing order before calling this function.
code[a1$95$m_, a2_, th_] := N[(a2 * N[(a2 * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a1_m = \left|a1\right|
\\
[a1_m, a2, th] = \mathsf{sort}([a1_m, a2, th])\\
\\
a2 \cdot \left(a2 \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. clear-numN/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{1}{\frac{\sqrt{2}}{\cos th}}\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    2. 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), \mathsf{*.f64}\left(\left(\frac{1}{\sqrt{2}} \cdot \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    3. *-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(\frac{1}{\sqrt{2}}\right), \cos th\right), \mathsf{*.f64}\left(\color{blue}{a2}, a2\right)\right)\right) \]
    4. pow1/2N/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(\frac{1}{{2}^{\frac{1}{2}}}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    5. pow-flipN/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({2}^{\left(\mathsf{neg}\left(\frac{1}{2}\right)\right)}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    6. pow-lowering-pow.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{pow.f64}\left(2, \left(\mathsf{neg}\left(\frac{1}{2}\right)\right)\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    7. metadata-evalN/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{pow.f64}\left(2, \frac{-1}{2}\right), \cos th\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
    8. cos-lowering-cos.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{pow.f64}\left(2, \frac{-1}{2}\right), \mathsf{cos.f64}\left(th\right)\right), \mathsf{*.f64}\left(a2, a2\right)\right)\right) \]
  4. Applied egg-rr99.6%

    \[\leadsto \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \color{blue}{\left({2}^{-0.5} \cdot \cos th\right)} \cdot \left(a2 \cdot a2\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. *-commutativeN/A

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

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

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

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

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \left(\sqrt{0.5} \cdot \cos th\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.f6437.4%

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

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

Reproduce

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