Migdal et al, Equation (64)

Percentage Accurate: 99.6% → 99.6%
Time: 12.0s
Alternatives: 21
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 21 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.3× speedup?

\[\begin{array}{l} \\ \cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (* (cos th) (/ (fma a1 a1 (* a2 a2)) (sqrt 2.0))))
double code(double a1, double a2, double th) {
	return cos(th) * (fma(a1, a1, (a2 * a2)) / sqrt(2.0));
}
function code(a1, a2, th)
	return Float64(cos(th) * Float64(fma(a1, a1, Float64(a2 * a2)) / sqrt(2.0)))
end
code[a1_, a2_, th_] := N[(N[Cos[th], $MachinePrecision] * N[(N[(a1 * a1 + N[(a2 * a2), $MachinePrecision]), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Final simplification99.7%

    \[\leadsto \cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}} \]

Alternative 2: 99.6% accurate, 2.0× speedup?

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

\\
\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

    \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
  4. Step-by-step derivation
    1. clear-num99.6%

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

      \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \cos th\right)} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    3. pow1/299.6%

      \[\leadsto \left(\frac{1}{\color{blue}{{2}^{0.5}}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    4. pow-flip99.6%

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

      \[\leadsto \left({2}^{\color{blue}{-0.5}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Applied egg-rr99.6%

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

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

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

Alternative 3: 99.6% accurate, 2.0× speedup?

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

\\
\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

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

Alternative 4: 58.1% accurate, 2.0× speedup?

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

\\
\cos th \cdot \left(a2 \cdot \frac{a2}{\sqrt{2}}\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \cos th \cdot \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \cos th \cdot \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    2. associate-/l*60.6%

      \[\leadsto \cos th \cdot \color{blue}{\frac{a2}{\frac{\sqrt{2}}{a2}}} \]
    3. associate-/r/60.6%

      \[\leadsto \cos th \cdot \color{blue}{\left(\frac{a2}{\sqrt{2}} \cdot a2\right)} \]
  6. Simplified60.6%

    \[\leadsto \cos th \cdot \color{blue}{\left(\frac{a2}{\sqrt{2}} \cdot a2\right)} \]
  7. Final simplification60.6%

    \[\leadsto \cos th \cdot \left(a2 \cdot \frac{a2}{\sqrt{2}}\right) \]

Alternative 5: 58.1% accurate, 2.0× speedup?

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

\\
\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \cos th \cdot \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \cos th \cdot \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  6. Simplified60.6%

    \[\leadsto \cos th \cdot \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
  7. Final simplification60.6%

    \[\leadsto \cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}} \]

Alternative 6: 66.2% accurate, 3.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;a2 \leq 8 \cdot 10^{+171}:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{elif}\;a2 \leq 7.6 \cdot 10^{+261} \lor \neg \left(a2 \leq 2 \cdot 10^{+279}\right) \land a2 \leq 10^{+297}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\left(a2 \cdot a2\right) \cdot \left(-0.5 \cdot \left(th \cdot th\right) + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= a2 8e+171)
   (* (+ (* a2 a2) (* a1 a1)) (sqrt 0.5))
   (if (or (<= a2 7.6e+261) (and (not (<= a2 2e+279)) (<= a2 1e+297)))
     (* (sqrt 0.5) (* (* a2 a2) (+ (* -0.5 (* th th)) 1.0)))
     (* a2 (/ a2 (sqrt 2.0))))))
double code(double a1, double a2, double th) {
	double tmp;
	if (a2 <= 8e+171) {
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	} else if ((a2 <= 7.6e+261) || (!(a2 <= 2e+279) && (a2 <= 1e+297))) {
		tmp = sqrt(0.5) * ((a2 * a2) * ((-0.5 * (th * th)) + 1.0));
	} else {
		tmp = a2 * (a2 / sqrt(2.0));
	}
	return tmp;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (a2 <= 8d+171) then
        tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5d0)
    else if ((a2 <= 7.6d+261) .or. (.not. (a2 <= 2d+279)) .and. (a2 <= 1d+297)) then
        tmp = sqrt(0.5d0) * ((a2 * a2) * (((-0.5d0) * (th * th)) + 1.0d0))
    else
        tmp = a2 * (a2 / sqrt(2.0d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (a2 <= 8e+171) {
		tmp = ((a2 * a2) + (a1 * a1)) * Math.sqrt(0.5);
	} else if ((a2 <= 7.6e+261) || (!(a2 <= 2e+279) && (a2 <= 1e+297))) {
		tmp = Math.sqrt(0.5) * ((a2 * a2) * ((-0.5 * (th * th)) + 1.0));
	} else {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if a2 <= 8e+171:
		tmp = ((a2 * a2) + (a1 * a1)) * math.sqrt(0.5)
	elif (a2 <= 7.6e+261) or (not (a2 <= 2e+279) and (a2 <= 1e+297)):
		tmp = math.sqrt(0.5) * ((a2 * a2) * ((-0.5 * (th * th)) + 1.0))
	else:
		tmp = a2 * (a2 / math.sqrt(2.0))
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (a2 <= 8e+171)
		tmp = Float64(Float64(Float64(a2 * a2) + Float64(a1 * a1)) * sqrt(0.5));
	elseif ((a2 <= 7.6e+261) || (!(a2 <= 2e+279) && (a2 <= 1e+297)))
		tmp = Float64(sqrt(0.5) * Float64(Float64(a2 * a2) * Float64(Float64(-0.5 * Float64(th * th)) + 1.0)));
	else
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (a2 <= 8e+171)
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	elseif ((a2 <= 7.6e+261) || (~((a2 <= 2e+279)) && (a2 <= 1e+297)))
		tmp = sqrt(0.5) * ((a2 * a2) * ((-0.5 * (th * th)) + 1.0));
	else
		tmp = a2 * (a2 / sqrt(2.0));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[a2, 8e+171], N[(N[(N[(a2 * a2), $MachinePrecision] + N[(a1 * a1), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[a2, 7.6e+261], And[N[Not[LessEqual[a2, 2e+279]], $MachinePrecision], LessEqual[a2, 1e+297]]], N[(N[Sqrt[0.5], $MachinePrecision] * N[(N[(a2 * a2), $MachinePrecision] * N[(N[(-0.5 * N[(th * th), $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;a2 \leq 8 \cdot 10^{+171}:\\
\;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\

\mathbf{elif}\;a2 \leq 7.6 \cdot 10^{+261} \lor \neg \left(a2 \leq 2 \cdot 10^{+279}\right) \land a2 \leq 10^{+297}:\\
\;\;\;\;\sqrt{0.5} \cdot \left(\left(a2 \cdot a2\right) \cdot \left(-0.5 \cdot \left(th \cdot th\right) + 1\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if a2 < 7.99999999999999963e171

    1. Initial program 99.6%

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

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

      \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    4. Step-by-step derivation
      1. clear-num99.5%

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

        \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \cos th\right)} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
      3. pow1/299.5%

        \[\leadsto \left(\frac{1}{\color{blue}{{2}^{0.5}}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
      4. pow-flip99.6%

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

        \[\leadsto \left({2}^{\color{blue}{-0.5}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Applied egg-rr99.6%

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

      \[\leadsto \color{blue}{\sqrt{0.5} \cdot \left({a2}^{2} + {a1}^{2}\right)} \]
    7. Step-by-step derivation
      1. *-commutative64.0%

        \[\leadsto \color{blue}{\left({a2}^{2} + {a1}^{2}\right) \cdot \sqrt{0.5}} \]
      2. unpow264.0%

        \[\leadsto \left(\color{blue}{a2 \cdot a2} + {a1}^{2}\right) \cdot \sqrt{0.5} \]
      3. unpow264.0%

        \[\leadsto \left(a2 \cdot a2 + \color{blue}{a1 \cdot a1}\right) \cdot \sqrt{0.5} \]
      4. +-commutative64.0%

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

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

    if 7.99999999999999963e171 < a2 < 7.6000000000000003e261 or 2.00000000000000012e279 < a2 < 1e297

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    4. Step-by-step derivation
      1. clear-num100.0%

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

        \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \cos th\right)} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
      3. pow1/2100.0%

        \[\leadsto \left(\frac{1}{\color{blue}{{2}^{0.5}}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
      4. pow-flip100.0%

        \[\leadsto \left(\color{blue}{{2}^{\left(-0.5\right)}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
      5. metadata-eval100.0%

        \[\leadsto \left({2}^{\color{blue}{-0.5}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Applied egg-rr100.0%

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

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

      \[\leadsto \color{blue}{\sqrt{0.5} \cdot \left({a2}^{2} \cdot \cos th\right)} \]
    8. Step-by-step derivation
      1. unpow2100.0%

        \[\leadsto \sqrt{0.5} \cdot \left(\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th\right) \]
      2. *-commutative100.0%

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

      \[\leadsto \color{blue}{\sqrt{0.5} \cdot \left(\cos th \cdot \left(a2 \cdot a2\right)\right)} \]
    10. Taylor expanded in th around 0 0.0%

      \[\leadsto \sqrt{0.5} \cdot \color{blue}{\left({a2}^{2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)\right)} \]
    11. Step-by-step derivation
      1. unpow20.0%

        \[\leadsto \frac{\color{blue}{a2 \cdot a2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow20.0%

        \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
      3. associate-*r*0.0%

        \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      4. distribute-rgt1-in90.9%

        \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot {th}^{2} + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      5. unpow290.9%

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

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

    if 7.6000000000000003e261 < a2 < 2.00000000000000012e279 or 1e297 < a2

    1. Initial program 100.0%

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

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
    3. Simplified100.0%

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Taylor expanded in a1 around 0 83.3%

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. unpow283.3%

        \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
      2. associate-*r/83.3%

        \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
    7. Simplified83.3%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification66.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;a2 \leq 8 \cdot 10^{+171}:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{elif}\;a2 \leq 7.6 \cdot 10^{+261} \lor \neg \left(a2 \leq 2 \cdot 10^{+279}\right) \land a2 \leq 10^{+297}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\left(a2 \cdot a2\right) \cdot \left(-0.5 \cdot \left(th \cdot th\right) + 1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \]

Alternative 7: 65.7% accurate, 3.8× speedup?

\[\begin{array}{l} \\ \left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5} \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* (+ (* a2 a2) (* a1 a1)) (sqrt 0.5)))
double code(double a1, double a2, double th) {
	return ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = ((a2 * a2) + (a1 * a1)) * sqrt(0.5d0)
end function
public static double code(double a1, double a2, double th) {
	return ((a2 * a2) + (a1 * a1)) * Math.sqrt(0.5);
}
def code(a1, a2, th):
	return ((a2 * a2) + (a1 * a1)) * math.sqrt(0.5)
function code(a1, a2, th)
	return Float64(Float64(Float64(a2 * a2) + Float64(a1 * a1)) * sqrt(0.5))
end
function tmp = code(a1, a2, th)
	tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
end
code[a1_, a2_, th_] := N[(N[(N[(a2 * a2), $MachinePrecision] + N[(a1 * a1), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

    \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)} \]
  4. Step-by-step derivation
    1. clear-num99.6%

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

      \[\leadsto \color{blue}{\left(\frac{1}{\sqrt{2}} \cdot \cos th\right)} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    3. pow1/299.6%

      \[\leadsto \left(\frac{1}{\color{blue}{{2}^{0.5}}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    4. pow-flip99.6%

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

      \[\leadsto \left({2}^{\color{blue}{-0.5}} \cdot \cos th\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Applied egg-rr99.6%

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

    \[\leadsto \color{blue}{\sqrt{0.5} \cdot \left({a2}^{2} + {a1}^{2}\right)} \]
  7. Step-by-step derivation
    1. *-commutative65.2%

      \[\leadsto \color{blue}{\left({a2}^{2} + {a1}^{2}\right) \cdot \sqrt{0.5}} \]
    2. unpow265.2%

      \[\leadsto \left(\color{blue}{a2 \cdot a2} + {a1}^{2}\right) \cdot \sqrt{0.5} \]
    3. unpow265.2%

      \[\leadsto \left(a2 \cdot a2 + \color{blue}{a1 \cdot a1}\right) \cdot \sqrt{0.5} \]
    4. +-commutative65.2%

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

    \[\leadsto \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  9. Final simplification65.2%

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

Alternative 8: 39.6% accurate, 4.0× speedup?

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

\\
a2 \cdot \frac{a2}{\sqrt{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Taylor expanded in a1 around 0 40.4%

    \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    2. associate-*r/40.3%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  7. Simplified40.3%

    \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  8. Final simplification40.3%

    \[\leadsto a2 \cdot \frac{a2}{\sqrt{2}} \]

Alternative 9: 39.6% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \left(a2 \cdot a2\right) \cdot \sqrt{0.5} \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* (* a2 a2) (sqrt 0.5)))
double code(double a1, double a2, double th) {
	return (a2 * a2) * sqrt(0.5);
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = (a2 * a2) * sqrt(0.5d0)
end function
public static double code(double a1, double a2, double th) {
	return (a2 * a2) * Math.sqrt(0.5);
}
def code(a1, a2, th):
	return (a2 * a2) * math.sqrt(0.5)
function code(a1, a2, th)
	return Float64(Float64(a2 * a2) * sqrt(0.5))
end
function tmp = code(a1, a2, th)
	tmp = (a2 * a2) * sqrt(0.5);
end
code[a1_, a2_, th_] := N[(N[(a2 * a2), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\left(a2 \cdot a2\right) \cdot \sqrt{0.5}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
    2. *-commutative60.6%

      \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  6. Simplified60.6%

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

    \[\leadsto \frac{\color{blue}{{a2}^{2}}}{\sqrt{2}} \]
  8. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  9. Simplified40.4%

    \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  10. Step-by-step derivation
    1. div-inv40.3%

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
    2. add-sqr-sqrt40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)} \]
    3. sqrt-unprod40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}} \]
    4. frac-times40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}} \]
    5. metadata-eval40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}} \]
    6. add-sqr-sqrt40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\color{blue}{2}}} \]
    7. metadata-eval40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
  11. Applied egg-rr40.4%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  12. Final simplification40.4%

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

Alternative 10: 39.6% accurate, 4.0× speedup?

\[\begin{array}{l} \\ \frac{a2}{\frac{\sqrt{2}}{a2}} \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (/ a2 (/ (sqrt 2.0) a2)))
double code(double a1, double a2, double th) {
	return a2 / (sqrt(2.0) / a2);
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 / (sqrt(2.0d0) / a2)
end function
public static double code(double a1, double a2, double th) {
	return a2 / (Math.sqrt(2.0) / a2);
}
def code(a1, a2, th):
	return a2 / (math.sqrt(2.0) / a2)
function code(a1, a2, th)
	return Float64(a2 / Float64(sqrt(2.0) / a2))
end
function tmp = code(a1, a2, th)
	tmp = a2 / (sqrt(2.0) / a2);
end
code[a1_, a2_, th_] := N[(a2 / N[(N[Sqrt[2.0], $MachinePrecision] / a2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{a2}{\frac{\sqrt{2}}{a2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Taylor expanded in a1 around 0 40.4%

    \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    2. associate-*r/40.3%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  7. Simplified40.3%

    \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  8. Step-by-step derivation
    1. clear-num40.3%

      \[\leadsto a2 \cdot \color{blue}{\frac{1}{\frac{\sqrt{2}}{a2}}} \]
    2. un-div-inv40.4%

      \[\leadsto \color{blue}{\frac{a2}{\frac{\sqrt{2}}{a2}}} \]
  9. Applied egg-rr40.4%

    \[\leadsto \color{blue}{\frac{a2}{\frac{\sqrt{2}}{a2}}} \]
  10. Final simplification40.4%

    \[\leadsto \frac{a2}{\frac{\sqrt{2}}{a2}} \]

Alternative 11: 39.6% accurate, 4.0× speedup?

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

\\
\frac{a2 \cdot a2}{\sqrt{2}}
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
    2. *-commutative60.6%

      \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  6. Simplified60.6%

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

    \[\leadsto \frac{\color{blue}{{a2}^{2}}}{\sqrt{2}} \]
  8. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  9. Simplified40.4%

    \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  10. Final simplification40.4%

    \[\leadsto \frac{a2 \cdot a2}{\sqrt{2}} \]

Alternative 12: 27.3% accurate, 33.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;a1 \cdot a1\\ \mathbf{elif}\;th \leq 1.3 \cdot 10^{+110} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\ \;\;\;\;th \cdot a2\\ \mathbf{else}:\\ \;\;\;\;th \cdot \left(-a2\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 4.8e+24)
   (* a1 a1)
   (if (or (<= th 1.3e+110) (and (not (<= th 3.2e+155)) (<= th 3.6e+212)))
     (* th a2)
     (* th (- a2)))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 4.8e+24) {
		tmp = a1 * a1;
	} else if ((th <= 1.3e+110) || (!(th <= 3.2e+155) && (th <= 3.6e+212))) {
		tmp = th * a2;
	} else {
		tmp = th * -a2;
	}
	return tmp;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (th <= 4.8d+24) then
        tmp = a1 * a1
    else if ((th <= 1.3d+110) .or. (.not. (th <= 3.2d+155)) .and. (th <= 3.6d+212)) then
        tmp = th * a2
    else
        tmp = th * -a2
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 4.8e+24) {
		tmp = a1 * a1;
	} else if ((th <= 1.3e+110) || (!(th <= 3.2e+155) && (th <= 3.6e+212))) {
		tmp = th * a2;
	} else {
		tmp = th * -a2;
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 4.8e+24:
		tmp = a1 * a1
	elif (th <= 1.3e+110) or (not (th <= 3.2e+155) and (th <= 3.6e+212)):
		tmp = th * a2
	else:
		tmp = th * -a2
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 4.8e+24)
		tmp = Float64(a1 * a1);
	elseif ((th <= 1.3e+110) || (!(th <= 3.2e+155) && (th <= 3.6e+212)))
		tmp = Float64(th * a2);
	else
		tmp = Float64(th * Float64(-a2));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 4.8e+24)
		tmp = a1 * a1;
	elseif ((th <= 1.3e+110) || (~((th <= 3.2e+155)) && (th <= 3.6e+212)))
		tmp = th * a2;
	else
		tmp = th * -a2;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 4.8e+24], N[(a1 * a1), $MachinePrecision], If[Or[LessEqual[th, 1.3e+110], And[N[Not[LessEqual[th, 3.2e+155]], $MachinePrecision], LessEqual[th, 3.6e+212]]], N[(th * a2), $MachinePrecision], N[(th * (-a2)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 4.8 \cdot 10^{+24}:\\
\;\;\;\;a1 \cdot a1\\

\mathbf{elif}\;th \leq 1.3 \cdot 10^{+110} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\
\;\;\;\;th \cdot a2\\

\mathbf{else}:\\
\;\;\;\;th \cdot \left(-a2\right)\\


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

    1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Taylor expanded in a1 around inf 42.1%

      \[\leadsto \color{blue}{\frac{{a1}^{2}}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. unpow242.1%

        \[\leadsto \frac{\color{blue}{a1 \cdot a1}}{\sqrt{2}} \]
    7. Simplified42.1%

      \[\leadsto \color{blue}{\frac{a1 \cdot a1}{\sqrt{2}}} \]
    8. Applied egg-rr34.5%

      \[\leadsto \color{blue}{a1 \cdot a1} \]

    if 4.8000000000000001e24 < th < 1.3e110 or 3.20000000000000012e155 < th < 3.6e212

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out99.6%

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.5%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.5%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 69.2%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow269.2%

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

        \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    6. Simplified69.2%

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

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

        \[\leadsto \frac{\color{blue}{a2 \cdot a2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow21.7%

        \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
      3. associate-*r*1.7%

        \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      4. distribute-rgt1-in10.4%

        \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot {th}^{2} + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      5. unpow210.4%

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

      \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot \left(th \cdot th\right) + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    10. Taylor expanded in th around inf 10.4%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
    11. Step-by-step derivation
      1. unpow210.4%

        \[\leadsto \frac{-0.5 \cdot \left(\color{blue}{\left(th \cdot th\right)} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow210.4%

        \[\leadsto \frac{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
    12. Simplified10.4%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \left(a2 \cdot a2\right)\right)}}{\sqrt{2}} \]
    13. Applied egg-rr3.8%

      \[\leadsto \color{blue}{th \cdot a2} \]

    if 1.3e110 < th < 3.20000000000000012e155 or 3.6e212 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out99.7%

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.7%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 49.5%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow249.5%

        \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
      2. *-commutative49.5%

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

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

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

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

        \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
      3. associate-*r*14.6%

        \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      4. distribute-rgt1-in32.0%

        \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot {th}^{2} + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      5. unpow232.0%

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

      \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot \left(th \cdot th\right) + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    10. Taylor expanded in th around inf 32.0%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
    11. Step-by-step derivation
      1. unpow232.0%

        \[\leadsto \frac{-0.5 \cdot \left(\color{blue}{\left(th \cdot th\right)} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow232.0%

        \[\leadsto \frac{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
    12. Simplified32.0%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \left(a2 \cdot a2\right)\right)}}{\sqrt{2}} \]
    13. Applied egg-rr11.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 4.8 \cdot 10^{+24}:\\ \;\;\;\;a1 \cdot a1\\ \mathbf{elif}\;th \leq 1.3 \cdot 10^{+110} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\ \;\;\;\;th \cdot a2\\ \mathbf{else}:\\ \;\;\;\;th \cdot \left(-a2\right)\\ \end{array} \]

Alternative 13: 30.1% accurate, 37.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 7.8 \cdot 10^{+76} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{-2}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (or (<= th 7.8e+76) (and (not (<= th 3.2e+155)) (<= th 3.6e+212)))
   (* a2 a2)
   (* a2 (/ a2 -2.0))))
double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 7.8e+76) || (!(th <= 3.2e+155) && (th <= 3.6e+212))) {
		tmp = a2 * a2;
	} else {
		tmp = a2 * (a2 / -2.0);
	}
	return tmp;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if ((th <= 7.8d+76) .or. (.not. (th <= 3.2d+155)) .and. (th <= 3.6d+212)) then
        tmp = a2 * a2
    else
        tmp = a2 * (a2 / (-2.0d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 7.8e+76) || (!(th <= 3.2e+155) && (th <= 3.6e+212))) {
		tmp = a2 * a2;
	} else {
		tmp = a2 * (a2 / -2.0);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if (th <= 7.8e+76) or (not (th <= 3.2e+155) and (th <= 3.6e+212)):
		tmp = a2 * a2
	else:
		tmp = a2 * (a2 / -2.0)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if ((th <= 7.8e+76) || (!(th <= 3.2e+155) && (th <= 3.6e+212)))
		tmp = Float64(a2 * a2);
	else
		tmp = Float64(a2 * Float64(a2 / -2.0));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if ((th <= 7.8e+76) || (~((th <= 3.2e+155)) && (th <= 3.6e+212)))
		tmp = a2 * a2;
	else
		tmp = a2 * (a2 / -2.0);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[Or[LessEqual[th, 7.8e+76], And[N[Not[LessEqual[th, 3.2e+155]], $MachinePrecision], LessEqual[th, 3.6e+212]]], N[(a2 * a2), $MachinePrecision], N[(a2 * N[(a2 / -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 7.8 \cdot 10^{+76} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\
\;\;\;\;a2 \cdot a2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 7.79999999999999979e76 or 3.20000000000000012e155 < th < 3.6e212

    1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Taylor expanded in a1 around 0 43.2%

      \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. unpow243.2%

        \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
      2. associate-*r/43.2%

        \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
    7. Simplified43.2%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
    8. Step-by-step derivation
      1. frac-2neg43.2%

        \[\leadsto a2 \cdot \color{blue}{\frac{-a2}{-\sqrt{2}}} \]
      2. div-inv43.1%

        \[\leadsto a2 \cdot \color{blue}{\left(\left(-a2\right) \cdot \frac{1}{-\sqrt{2}}\right)} \]
    9. Applied egg-rr43.1%

      \[\leadsto a2 \cdot \color{blue}{\left(\left(-a2\right) \cdot \frac{1}{-\sqrt{2}}\right)} \]
    10. Applied egg-rr29.1%

      \[\leadsto a2 \cdot \left(\left(-a2\right) \cdot \color{blue}{-1}\right) \]

    if 7.79999999999999979e76 < th < 3.20000000000000012e155 or 3.6e212 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out99.7%

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.7%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 53.4%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow253.4%

        \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
      2. *-commutative53.4%

        \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    6. Simplified53.4%

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

      \[\leadsto \frac{\color{blue}{{a2}^{2}}}{\sqrt{2}} \]
    8. Step-by-step derivation
      1. unpow216.5%

        \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    9. Simplified16.5%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    10. Step-by-step derivation
      1. div-inv16.5%

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)} \]
      3. sqrt-unprod16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}} \]
      4. frac-times16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}} \]
      5. metadata-eval16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}} \]
      6. add-sqr-sqrt16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\color{blue}{2}}} \]
      7. metadata-eval16.5%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
    11. Applied egg-rr16.5%

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    12. Applied egg-rr26.8%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    13. Step-by-step derivation
      1. associate-/r/26.8%

        \[\leadsto \color{blue}{\frac{a2}{-2} \cdot a2} \]
    14. Simplified26.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 7.8 \cdot 10^{+76} \lor \neg \left(th \leq 3.2 \cdot 10^{+155}\right) \land th \leq 3.6 \cdot 10^{+212}:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{-2}\\ \end{array} \]

Alternative 14: 18.1% accurate, 58.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 7.8 \cdot 10^{+76}:\\ \;\;\;\;a2 \cdot \left(th \cdot a2\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{-2}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 7.8e+76) (* a2 (* th a2)) (* a2 (/ a2 -2.0))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 7.8e+76) {
		tmp = a2 * (th * a2);
	} else {
		tmp = a2 * (a2 / -2.0);
	}
	return tmp;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (th <= 7.8d+76) then
        tmp = a2 * (th * a2)
    else
        tmp = a2 * (a2 / (-2.0d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 7.8e+76) {
		tmp = a2 * (th * a2);
	} else {
		tmp = a2 * (a2 / -2.0);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 7.8e+76:
		tmp = a2 * (th * a2)
	else:
		tmp = a2 * (a2 / -2.0)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 7.8e+76)
		tmp = Float64(a2 * Float64(th * a2));
	else
		tmp = Float64(a2 * Float64(a2 / -2.0));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 7.8e+76)
		tmp = a2 * (th * a2);
	else
		tmp = a2 * (a2 / -2.0);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 7.8e+76], N[(a2 * N[(th * a2), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 / -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 7.8 \cdot 10^{+76}:\\
\;\;\;\;a2 \cdot \left(th \cdot a2\right)\\

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


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

    1. Initial program 99.6%

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

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.7%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.7%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 61.5%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow261.5%

        \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
      2. *-commutative61.5%

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

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

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

        \[\leadsto \frac{\color{blue}{a2 \cdot a2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow225.7%

        \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
      3. associate-*r*25.7%

        \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      4. distribute-rgt1-in47.6%

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

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

      \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot \left(th \cdot th\right) + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    10. Taylor expanded in th around inf 14.6%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
    11. Step-by-step derivation
      1. unpow214.6%

        \[\leadsto \frac{-0.5 \cdot \left(\color{blue}{\left(th \cdot th\right)} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow214.6%

        \[\leadsto \frac{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
    12. Simplified14.6%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \left(a2 \cdot a2\right)\right)}}{\sqrt{2}} \]
    13. Applied egg-rr18.3%

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

    if 7.79999999999999979e76 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out99.7%

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.6%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 54.6%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow254.6%

        \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
      2. *-commutative54.6%

        \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    6. Simplified54.6%

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

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

        \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    9. Simplified17.3%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    10. Step-by-step derivation
      1. div-inv17.3%

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)} \]
      3. sqrt-unprod17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}} \]
      4. frac-times17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}} \]
      5. metadata-eval17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}} \]
      6. add-sqr-sqrt17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\color{blue}{2}}} \]
      7. metadata-eval17.3%

        \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
    11. Applied egg-rr17.3%

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    12. Applied egg-rr27.0%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    13. Step-by-step derivation
      1. associate-/r/27.0%

        \[\leadsto \color{blue}{\frac{a2}{-2} \cdot a2} \]
    14. Simplified27.0%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 7.8 \cdot 10^{+76}:\\ \;\;\;\;a2 \cdot \left(th \cdot a2\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{-2}\\ \end{array} \]

Alternative 15: 29.7% accurate, 69.2× speedup?

\[\begin{array}{l} \\ a2 \cdot \left(a2 \cdot \left(--0.5\right)\right) \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* a2 (* a2 (- -0.5))))
double code(double a1, double a2, double th) {
	return a2 * (a2 * -(-0.5));
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 * (a2 * -(-0.5d0))
end function
public static double code(double a1, double a2, double th) {
	return a2 * (a2 * -(-0.5));
}
def code(a1, a2, th):
	return a2 * (a2 * -(-0.5))
function code(a1, a2, th)
	return Float64(a2 * Float64(a2 * Float64(-(-0.5))))
end
function tmp = code(a1, a2, th)
	tmp = a2 * (a2 * -(-0.5));
end
code[a1_, a2_, th_] := N[(a2 * N[(a2 * (--0.5)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a2 \cdot \left(a2 \cdot \left(--0.5\right)\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Taylor expanded in a1 around 0 40.4%

    \[\leadsto \color{blue}{\frac{{a2}^{2}}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
    2. associate-*r/40.3%

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  7. Simplified40.3%

    \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
  8. Step-by-step derivation
    1. frac-2neg40.3%

      \[\leadsto a2 \cdot \color{blue}{\frac{-a2}{-\sqrt{2}}} \]
    2. div-inv40.3%

      \[\leadsto a2 \cdot \color{blue}{\left(\left(-a2\right) \cdot \frac{1}{-\sqrt{2}}\right)} \]
  9. Applied egg-rr40.3%

    \[\leadsto a2 \cdot \color{blue}{\left(\left(-a2\right) \cdot \frac{1}{-\sqrt{2}}\right)} \]
  10. Applied egg-rr28.0%

    \[\leadsto a2 \cdot \left(\left(-a2\right) \cdot \color{blue}{-0.5}\right) \]
  11. Final simplification28.0%

    \[\leadsto a2 \cdot \left(a2 \cdot \left(--0.5\right)\right) \]

Alternative 16: 27.4% accurate, 82.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 3.2 \cdot 10^{+24}:\\ \;\;\;\;a1 \cdot a1\\ \mathbf{else}:\\ \;\;\;\;th \cdot a2\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 3.2e+24) (* a1 a1) (* th a2)))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 3.2e+24) {
		tmp = a1 * a1;
	} else {
		tmp = th * a2;
	}
	return tmp;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    real(8) :: tmp
    if (th <= 3.2d+24) then
        tmp = a1 * a1
    else
        tmp = th * a2
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 3.2e+24) {
		tmp = a1 * a1;
	} else {
		tmp = th * a2;
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 3.2e+24:
		tmp = a1 * a1
	else:
		tmp = th * a2
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 3.2e+24)
		tmp = Float64(a1 * a1);
	else
		tmp = Float64(th * a2);
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 3.2e+24)
		tmp = a1 * a1;
	else
		tmp = th * a2;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 3.2e+24], N[(a1 * a1), $MachinePrecision], N[(th * a2), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 3.2 \cdot 10^{+24}:\\
\;\;\;\;a1 \cdot a1\\

\mathbf{else}:\\
\;\;\;\;th \cdot a2\\


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

    1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
    5. Taylor expanded in a1 around inf 42.1%

      \[\leadsto \color{blue}{\frac{{a1}^{2}}{\sqrt{2}}} \]
    6. Step-by-step derivation
      1. unpow242.1%

        \[\leadsto \frac{\color{blue}{a1 \cdot a1}}{\sqrt{2}} \]
    7. Simplified42.1%

      \[\leadsto \color{blue}{\frac{a1 \cdot a1}{\sqrt{2}}} \]
    8. Applied egg-rr34.5%

      \[\leadsto \color{blue}{a1 \cdot a1} \]

    if 3.1999999999999997e24 < th

    1. Initial program 99.7%

      \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
    2. Step-by-step derivation
      1. distribute-lft-out99.6%

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

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

        \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
      4. fma-def99.6%

        \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
    3. Simplified99.6%

      \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Taylor expanded in a1 around 0 59.3%

      \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
    5. Step-by-step derivation
      1. unpow259.3%

        \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
      2. *-commutative59.3%

        \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    6. Simplified59.3%

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

      \[\leadsto \frac{\color{blue}{{a2}^{2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
    8. Step-by-step derivation
      1. unpow28.1%

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

        \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
      3. associate-*r*8.1%

        \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
      4. distribute-rgt1-in21.2%

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

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

      \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot \left(th \cdot th\right) + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    10. Taylor expanded in th around inf 21.2%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
    11. Step-by-step derivation
      1. unpow221.2%

        \[\leadsto \frac{-0.5 \cdot \left(\color{blue}{\left(th \cdot th\right)} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
      2. unpow221.2%

        \[\leadsto \frac{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
    12. Simplified21.2%

      \[\leadsto \frac{\color{blue}{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \left(a2 \cdot a2\right)\right)}}{\sqrt{2}} \]
    13. Applied egg-rr13.5%

      \[\leadsto \color{blue}{th \cdot a2} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification30.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 3.2 \cdot 10^{+24}:\\ \;\;\;\;a1 \cdot a1\\ \mathbf{else}:\\ \;\;\;\;th \cdot a2\\ \end{array} \]

Alternative 17: 17.0% accurate, 83.0× speedup?

\[\begin{array}{l} \\ a2 \cdot \left(th \cdot a2\right) \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* a2 (* th a2)))
double code(double a1, double a2, double th) {
	return a2 * (th * a2);
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a2 * (th * a2)
end function
public static double code(double a1, double a2, double th) {
	return a2 * (th * a2);
}
def code(a1, a2, th):
	return a2 * (th * a2)
function code(a1, a2, th)
	return Float64(a2 * Float64(th * a2))
end
function tmp = code(a1, a2, th)
	tmp = a2 * (th * a2);
end
code[a1_, a2_, th_] := N[(a2 * N[(th * a2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a2 \cdot \left(th \cdot a2\right)
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
    2. *-commutative60.6%

      \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  6. Simplified60.6%

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

    \[\leadsto \frac{\color{blue}{{a2}^{2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
  8. Step-by-step derivation
    1. unpow223.9%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2} + -0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}{\sqrt{2}} \]
    2. unpow223.9%

      \[\leadsto \frac{a2 \cdot a2 + -0.5 \cdot \left({th}^{2} \cdot \color{blue}{\left(a2 \cdot a2\right)}\right)}{\sqrt{2}} \]
    3. associate-*r*23.9%

      \[\leadsto \frac{a2 \cdot a2 + \color{blue}{\left(-0.5 \cdot {th}^{2}\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    4. distribute-rgt1-in45.0%

      \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot {th}^{2} + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
    5. unpow245.0%

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

    \[\leadsto \frac{\color{blue}{\left(-0.5 \cdot \left(th \cdot th\right) + 1\right) \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  10. Taylor expanded in th around inf 16.1%

    \[\leadsto \frac{\color{blue}{-0.5 \cdot \left({th}^{2} \cdot {a2}^{2}\right)}}{\sqrt{2}} \]
  11. Step-by-step derivation
    1. unpow216.1%

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

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

    \[\leadsto \frac{\color{blue}{-0.5 \cdot \left(\left(th \cdot th\right) \cdot \left(a2 \cdot a2\right)\right)}}{\sqrt{2}} \]
  13. Applied egg-rr17.7%

    \[\leadsto \color{blue}{\left(a2 \cdot th\right) \cdot a2} \]
  14. Final simplification17.7%

    \[\leadsto a2 \cdot \left(th \cdot a2\right) \]

Alternative 18: 29.4% accurate, 138.3× speedup?

\[\begin{array}{l} \\ a1 \cdot a1 \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* a1 a1))
double code(double a1, double a2, double th) {
	return a1 * a1;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = a1 * a1
end function
public static double code(double a1, double a2, double th) {
	return a1 * a1;
}
def code(a1, a2, th):
	return a1 * a1
function code(a1, a2, th)
	return Float64(a1 * a1)
end
function tmp = code(a1, a2, th)
	tmp = a1 * a1;
end
code[a1_, a2_, th_] := N[(a1 * a1), $MachinePrecision]
\begin{array}{l}

\\
a1 \cdot a1
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Taylor expanded in a1 around inf 38.0%

    \[\leadsto \color{blue}{\frac{{a1}^{2}}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. unpow238.0%

      \[\leadsto \frac{\color{blue}{a1 \cdot a1}}{\sqrt{2}} \]
  7. Simplified38.0%

    \[\leadsto \color{blue}{\frac{a1 \cdot a1}{\sqrt{2}}} \]
  8. Applied egg-rr31.7%

    \[\leadsto \color{blue}{a1 \cdot a1} \]
  9. Final simplification31.7%

    \[\leadsto a1 \cdot a1 \]

Alternative 19: 3.5% accurate, 415.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (a1 a2 th) :precision binary64 1.0)
double code(double a1, double a2, double th) {
	return 1.0;
}
real(8) function code(a1, a2, th)
    real(8), intent (in) :: a1
    real(8), intent (in) :: a2
    real(8), intent (in) :: th
    code = 1.0d0
end function
public static double code(double a1, double a2, double th) {
	return 1.0;
}
def code(a1, a2, th):
	return 1.0
function code(a1, a2, th)
	return 1.0
end
function tmp = code(a1, a2, th)
	tmp = 1.0;
end
code[a1_, a2_, th_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
    2. *-commutative60.6%

      \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  6. Simplified60.6%

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

    \[\leadsto \frac{\color{blue}{{a2}^{2}}}{\sqrt{2}} \]
  8. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  9. Simplified40.4%

    \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  10. Step-by-step derivation
    1. div-inv40.3%

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
    2. add-sqr-sqrt40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)} \]
    3. sqrt-unprod40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}} \]
    4. frac-times40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}} \]
    5. metadata-eval40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}} \]
    6. add-sqr-sqrt40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\color{blue}{2}}} \]
    7. metadata-eval40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
  11. Applied egg-rr40.4%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  12. Applied egg-rr3.4%

    \[\leadsto \color{blue}{\frac{a2}{a2}} \]
  13. Step-by-step derivation
    1. *-inverses3.4%

      \[\leadsto \color{blue}{1} \]
  14. Simplified3.4%

    \[\leadsto \color{blue}{1} \]
  15. Final simplification3.4%

    \[\leadsto 1 \]

Alternative 20: 3.6% accurate, 415.0× speedup?

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

\\
a1
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
  5. Taylor expanded in a1 around inf 38.0%

    \[\leadsto \color{blue}{\frac{{a1}^{2}}{\sqrt{2}}} \]
  6. Step-by-step derivation
    1. unpow238.0%

      \[\leadsto \frac{\color{blue}{a1 \cdot a1}}{\sqrt{2}} \]
  7. Simplified38.0%

    \[\leadsto \color{blue}{\frac{a1 \cdot a1}{\sqrt{2}}} \]
  8. Applied egg-rr4.7%

    \[\leadsto \color{blue}{\left|a1\right|} \]
  9. Step-by-step derivation
    1. unpow14.7%

      \[\leadsto \left|\color{blue}{{a1}^{1}}\right| \]
    2. *-inverses4.7%

      \[\leadsto \left|{a1}^{\color{blue}{\left(\frac{a2}{a2}\right)}}\right| \]
    3. sqr-pow2.3%

      \[\leadsto \left|\color{blue}{{a1}^{\left(\frac{\frac{a2}{a2}}{2}\right)} \cdot {a1}^{\left(\frac{\frac{a2}{a2}}{2}\right)}}\right| \]
    4. fabs-sqr2.3%

      \[\leadsto \color{blue}{{a1}^{\left(\frac{\frac{a2}{a2}}{2}\right)} \cdot {a1}^{\left(\frac{\frac{a2}{a2}}{2}\right)}} \]
    5. sqr-pow3.5%

      \[\leadsto \color{blue}{{a1}^{\left(\frac{a2}{a2}\right)}} \]
    6. *-inverses3.5%

      \[\leadsto {a1}^{\color{blue}{1}} \]
    7. unpow13.5%

      \[\leadsto \color{blue}{a1} \]
  10. Simplified3.5%

    \[\leadsto \color{blue}{a1} \]
  11. Final simplification3.5%

    \[\leadsto a1 \]

Alternative 21: 3.6% accurate, 415.0× speedup?

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

\\
a2
\end{array}
Derivation
  1. Initial program 99.6%

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

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

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

      \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]
    4. fma-def99.7%

      \[\leadsto \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Simplified99.7%

    \[\leadsto \color{blue}{\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Taylor expanded in a1 around 0 60.6%

    \[\leadsto \color{blue}{\frac{{a2}^{2} \cdot \cos th}{\sqrt{2}}} \]
  5. Step-by-step derivation
    1. unpow260.6%

      \[\leadsto \frac{\color{blue}{\left(a2 \cdot a2\right)} \cdot \cos th}{\sqrt{2}} \]
    2. *-commutative60.6%

      \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  6. Simplified60.6%

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

    \[\leadsto \frac{\color{blue}{{a2}^{2}}}{\sqrt{2}} \]
  8. Step-by-step derivation
    1. unpow240.4%

      \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  9. Simplified40.4%

    \[\leadsto \frac{\color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
  10. Step-by-step derivation
    1. div-inv40.3%

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
    2. add-sqr-sqrt40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)} \]
    3. sqrt-unprod40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}} \]
    4. frac-times40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}} \]
    5. metadata-eval40.3%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}} \]
    6. add-sqr-sqrt40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\color{blue}{2}}} \]
    7. metadata-eval40.4%

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
  11. Applied egg-rr40.4%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  12. Applied egg-rr3.5%

    \[\leadsto \color{blue}{0 + a2} \]
  13. Step-by-step derivation
    1. +-lft-identity3.5%

      \[\leadsto \color{blue}{a2} \]
  14. Simplified3.5%

    \[\leadsto \color{blue}{a2} \]
  15. Final simplification3.5%

    \[\leadsto a2 \]

Reproduce

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