Migdal et al, Equation (64)

Percentage Accurate: 99.6% → 99.6%
Time: 15.6s
Alternatives: 18
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 18 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, 2.0× speedup?

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

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

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

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
  4. Step-by-step derivation
    1. fma-udef99.3%

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

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

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

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

Alternative 2: 80.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos th \leq 0.65:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= (cos th) 0.65)
   (* (cos th) (* (+ a2 a1) (+ a2 a1)))
   (* (+ (* a2 a2) (* a1 a1)) (sqrt 0.5))))
double code(double a1, double a2, double th) {
	double tmp;
	if (cos(th) <= 0.65) {
		tmp = cos(th) * ((a2 + a1) * (a2 + a1));
	} else {
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	}
	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 (cos(th) <= 0.65d0) then
        tmp = cos(th) * ((a2 + a1) * (a2 + a1))
    else
        tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5d0)
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= 0.65) {
		tmp = Math.cos(th) * ((a2 + a1) * (a2 + a1));
	} else {
		tmp = ((a2 * a2) + (a1 * a1)) * Math.sqrt(0.5);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if math.cos(th) <= 0.65:
		tmp = math.cos(th) * ((a2 + a1) * (a2 + a1))
	else:
		tmp = ((a2 * a2) + (a1 * a1)) * math.sqrt(0.5)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (cos(th) <= 0.65)
		tmp = Float64(cos(th) * Float64(Float64(a2 + a1) * Float64(a2 + a1)));
	else
		tmp = Float64(Float64(Float64(a2 * a2) + Float64(a1 * a1)) * sqrt(0.5));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (cos(th) <= 0.65)
		tmp = cos(th) * ((a2 + a1) * (a2 + a1));
	else
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], 0.65], N[(N[Cos[th], $MachinePrecision] * N[(N[(a2 + a1), $MachinePrecision] * N[(a2 + a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a2 * a2), $MachinePrecision] + N[(a1 * a1), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq 0.65:\\
\;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 th) < 0.650000000000000022

    1. Initial program 98.8%

      \[\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. +-commutative98.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out98.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sqrt{0.5} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right) \cdot \cos th} \]
    9. Applied egg-rr49.1%

      \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot a1 + \left(a2 + a1\right) \cdot a2\right)} \cdot \cos th \]
    10. Step-by-step derivation
      1. +-commutative49.1%

        \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot a2 + \left(a2 + a1\right) \cdot a1\right)} \cdot \cos th \]
      2. distribute-lft-in57.7%

        \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)} \cdot \cos th \]
    11. Simplified57.7%

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

    if 0.650000000000000022 < (cos.f64 th)

    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. +-commutative99.6%

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

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

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

      \[\leadsto \color{blue}{\frac{1}{\sqrt{2}}} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
    5. Step-by-step derivation
      1. expm1-log1p-u93.8%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{2}}\right)\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      2. expm1-udef93.8%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{2}}\right)} - 1\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      3. add-sqr-sqrt93.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      4. sqrt-unprod93.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      5. frac-times93.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      6. metadata-eval93.8%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      7. add-sqr-sqrt93.3%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\frac{1}{\color{blue}{2}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      8. metadata-eval93.3%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{0.5}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
    6. Applied egg-rr93.3%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{0.5}\right)} - 1\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
    7. Step-by-step derivation
      1. expm1-def93.3%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{0.5}\right)\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      2. expm1-log1p93.8%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos th \leq 0.65:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \end{array} \]

Alternative 3: 80.0% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos th \leq 0.65:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= (cos th) 0.65)
   (* (cos th) (* (+ a2 a1) (+ a2 a1)))
   (/ (+ (* a2 a2) (* a1 a1)) (sqrt 2.0))))
double code(double a1, double a2, double th) {
	double tmp;
	if (cos(th) <= 0.65) {
		tmp = cos(th) * ((a2 + a1) * (a2 + a1));
	} else {
		tmp = ((a2 * a2) + (a1 * a1)) / 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 (cos(th) <= 0.65d0) then
        tmp = cos(th) * ((a2 + a1) * (a2 + a1))
    else
        tmp = ((a2 * a2) + (a1 * a1)) / sqrt(2.0d0)
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (Math.cos(th) <= 0.65) {
		tmp = Math.cos(th) * ((a2 + a1) * (a2 + a1));
	} else {
		tmp = ((a2 * a2) + (a1 * a1)) / Math.sqrt(2.0);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if math.cos(th) <= 0.65:
		tmp = math.cos(th) * ((a2 + a1) * (a2 + a1))
	else:
		tmp = ((a2 * a2) + (a1 * a1)) / math.sqrt(2.0)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (cos(th) <= 0.65)
		tmp = Float64(cos(th) * Float64(Float64(a2 + a1) * Float64(a2 + a1)));
	else
		tmp = Float64(Float64(Float64(a2 * a2) + Float64(a1 * a1)) / sqrt(2.0));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (cos(th) <= 0.65)
		tmp = cos(th) * ((a2 + a1) * (a2 + a1));
	else
		tmp = ((a2 * a2) + (a1 * a1)) / sqrt(2.0);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[N[Cos[th], $MachinePrecision], 0.65], N[(N[Cos[th], $MachinePrecision] * N[(N[(a2 + a1), $MachinePrecision] * N[(a2 + a1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a2 * a2), $MachinePrecision] + N[(a1 * a1), $MachinePrecision]), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos th \leq 0.65:\\
\;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 th) < 0.650000000000000022

    1. Initial program 98.8%

      \[\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. +-commutative98.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out98.8%

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(\sqrt{0.5} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)\right) \cdot \cos th} \]
    9. Applied egg-rr49.1%

      \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot a1 + \left(a2 + a1\right) \cdot a2\right)} \cdot \cos th \]
    10. Step-by-step derivation
      1. +-commutative49.1%

        \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot a2 + \left(a2 + a1\right) \cdot a1\right)} \cdot \cos th \]
      2. distribute-lft-in57.7%

        \[\leadsto \color{blue}{\left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)} \cdot \cos th \]
    11. Simplified57.7%

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

    if 0.650000000000000022 < (cos.f64 th)

    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. cos-neg99.6%

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

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

        \[\leadsto \frac{\color{blue}{\cos th} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)}{\sqrt{2}} \]
      5. fma-def99.8%

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

      \[\leadsto \color{blue}{\frac{\cos th \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}}} \]
    4. Step-by-step derivation
      1. fma-udef99.8%

        \[\leadsto \frac{\cos th \cdot \color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right)}}{\sqrt{2}} \]
      2. +-commutative99.8%

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

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

      \[\leadsto \color{blue}{\frac{{a1}^{2} + {a2}^{2}}{\sqrt{2}}} \]
    7. Step-by-step derivation
      1. unpow293.9%

        \[\leadsto \frac{\color{blue}{a1 \cdot a1} + {a2}^{2}}{\sqrt{2}} \]
      2. unpow293.9%

        \[\leadsto \frac{a1 \cdot a1 + \color{blue}{a2 \cdot a2}}{\sqrt{2}} \]
      3. +-commutative93.9%

        \[\leadsto \frac{\color{blue}{a2 \cdot a2 + a1 \cdot a1}}{\sqrt{2}} \]
    8. Simplified93.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos th \leq 0.65:\\ \;\;\;\;\cos th \cdot \left(\left(a2 + a1\right) \cdot \left(a2 + a1\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \end{array} \]

Alternative 4: 99.6% accurate, 2.0× speedup?

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

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

    \[\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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alternative 5: 57.5% accurate, 2.0× speedup?

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

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

    \[\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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

Alternative 6: 57.5% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \left(\cos th \cdot a2\right) \cdot \left(a2 \cdot \sqrt{0.5}\right) \end{array} \]
(FPCore (a1 a2 th) :precision binary64 (* (* (cos th) a2) (* a2 (sqrt 0.5))))
double code(double a1, double a2, double th) {
	return (cos(th) * 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 = (cos(th) * a2) * (a2 * sqrt(0.5d0))
end function
public static double code(double a1, double a2, double th) {
	return (Math.cos(th) * a2) * (a2 * Math.sqrt(0.5));
}
def code(a1, a2, th):
	return (math.cos(th) * a2) * (a2 * math.sqrt(0.5))
function code(a1, a2, th)
	return Float64(Float64(cos(th) * a2) * Float64(a2 * sqrt(0.5)))
end
function tmp = code(a1, a2, th)
	tmp = (cos(th) * a2) * (a2 * sqrt(0.5));
end
code[a1_, a2_, th_] := N[(N[(N[Cos[th], $MachinePrecision] * a2), $MachinePrecision] * N[(a2 * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \frac{\color{blue}{\cos th \cdot \left(a2 \cdot a2\right)}}{\sqrt{2}} \]
  7. Step-by-step derivation
    1. div-inv57.4%

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

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

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

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

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

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

      \[\leadsto \left(\cos th \cdot a2\right) \cdot \left(a2 \cdot \sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}}\right) \]
    8. add-sqr-sqrt57.8%

      \[\leadsto \left(\cos th \cdot a2\right) \cdot \left(a2 \cdot \sqrt{\frac{1}{\color{blue}{2}}}\right) \]
    9. metadata-eval57.8%

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

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

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

Alternative 7: 39.8% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (/ (* a2 a2) (sqrt 2.0))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (* (* a2 a2) (/ 1.0 (sqrt 2.0))))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = (a2 * a2) * (1.0 / 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 (th <= 1.55d0) then
        tmp = (a2 * a2) / sqrt(2.0d0)
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = (a2 * a2) * (1.0d0 / sqrt(2.0d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / Math.sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = (a2 * a2) * (1.0 / Math.sqrt(2.0));
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = (a2 * a2) / math.sqrt(2.0)
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = (a2 * a2) * (1.0 / math.sqrt(2.0))
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(Float64(a2 * a2) / sqrt(2.0));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(Float64(a2 * a2) * Float64(1.0 / sqrt(2.0)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = (a2 * a2) / sqrt(2.0);
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = (a2 * a2) * (1.0 / sqrt(2.0));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(N[(a2 * a2), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(a2 * a2), $MachinePrecision] * N[(1.0 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

\mathbf{else}:\\
\;\;\;\;\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}\\


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

        \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(a2 \cdot a2\right)} \]
    7. Simplified40.9%

      \[\leadsto \frac{1}{\sqrt{2}} \cdot \color{blue}{\left(a2 \cdot a2\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification41.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}\\ \end{array} \]

Alternative 8: 39.8% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (/ (* a2 a2) (sqrt 2.0))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (/ 1.0 (/ (sqrt 2.0) (* a2 a2))))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = 1.0 / (sqrt(2.0) / (a2 * 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 <= 1.55d0) then
        tmp = (a2 * a2) / sqrt(2.0d0)
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = 1.0d0 / (sqrt(2.0d0) / (a2 * a2))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / Math.sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = 1.0 / (Math.sqrt(2.0) / (a2 * a2));
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = (a2 * a2) / math.sqrt(2.0)
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = 1.0 / (math.sqrt(2.0) / (a2 * a2))
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(Float64(a2 * a2) / sqrt(2.0));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(1.0 / Float64(sqrt(2.0) / Float64(a2 * a2)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = (a2 * a2) / sqrt(2.0);
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = 1.0 / (sqrt(2.0) / (a2 * a2));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(N[(a2 * a2), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Sqrt[2.0], $MachinePrecision] / N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

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


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
    8. Step-by-step derivation
      1. associate-*r/40.9%

        \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
      2. clear-num40.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]

Alternative 9: 63.6% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (* (+ (* a2 a2) (* a1 a1)) (sqrt 0.5))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (/ 1.0 (/ (sqrt 2.0) (* a2 a2))))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = 1.0 / (sqrt(2.0) / (a2 * 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 <= 1.55d0) then
        tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5d0)
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = 1.0d0 / (sqrt(2.0d0) / (a2 * a2))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = ((a2 * a2) + (a1 * a1)) * Math.sqrt(0.5);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = 1.0 / (Math.sqrt(2.0) / (a2 * a2));
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = ((a2 * a2) + (a1 * a1)) * math.sqrt(0.5)
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = 1.0 / (math.sqrt(2.0) / (a2 * a2))
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(Float64(Float64(a2 * a2) + Float64(a1 * a1)) * sqrt(0.5));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(1.0 / Float64(sqrt(2.0) / Float64(a2 * a2)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = ((a2 * a2) + (a1 * a1)) * sqrt(0.5);
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = 1.0 / (sqrt(2.0) / (a2 * a2));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(N[(N[(a2 * a2), $MachinePrecision] + N[(a1 * a1), $MachinePrecision]), $MachinePrecision] * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(N[Sqrt[2.0], $MachinePrecision] / N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

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


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\sqrt{2}}\right)\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      2. expm1-udef73.4%

        \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\frac{1}{\sqrt{2}}\right)} - 1\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      3. add-sqr-sqrt73.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{\frac{1}{\sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      4. sqrt-unprod73.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\frac{1}{\sqrt{2}} \cdot \frac{1}{\sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      5. frac-times73.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{\frac{1 \cdot 1}{\sqrt{2} \cdot \sqrt{2}}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      6. metadata-eval73.4%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\frac{\color{blue}{1}}{\sqrt{2} \cdot \sqrt{2}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      7. add-sqr-sqrt73.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\frac{1}{\color{blue}{2}}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
      8. metadata-eval73.0%

        \[\leadsto \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{0.5}}\right)} - 1\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
    6. Applied egg-rr73.0%

      \[\leadsto \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{0.5}\right)} - 1\right)} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
    7. Step-by-step derivation
      1. expm1-def73.0%

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

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

      \[\leadsto \color{blue}{a2 \cdot \frac{a2}{\sqrt{2}}} \]
    8. Step-by-step derivation
      1. associate-*r/40.9%

        \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
      2. clear-num40.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a2 \cdot a2}}\\ \end{array} \]

Alternative 10: 39.7% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 1.25 \cdot 10^{+76}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (or (<= th 1.55) (and (not (<= th 7.5e+18)) (<= th 1.25e+76)))
   (* a2 (/ a2 (sqrt 2.0)))
   (* a2 (* a2 -0.5))))
double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 1.25e+76))) {
		tmp = a2 * (a2 / sqrt(2.0));
	} else {
		tmp = a2 * (a2 * -0.5);
	}
	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 <= 1.55d0) .or. (.not. (th <= 7.5d+18)) .and. (th <= 1.25d+76)) then
        tmp = a2 * (a2 / sqrt(2.0d0))
    else
        tmp = a2 * (a2 * (-0.5d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 1.25e+76))) {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	} else {
		tmp = a2 * (a2 * -0.5);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if (th <= 1.55) or (not (th <= 7.5e+18) and (th <= 1.25e+76)):
		tmp = a2 * (a2 / math.sqrt(2.0))
	else:
		tmp = a2 * (a2 * -0.5)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 1.25e+76)))
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	else
		tmp = Float64(a2 * Float64(a2 * -0.5));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if ((th <= 1.55) || (~((th <= 7.5e+18)) && (th <= 1.25e+76)))
		tmp = a2 * (a2 / sqrt(2.0));
	else
		tmp = a2 * (a2 * -0.5);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[Or[LessEqual[th, 1.55], And[N[Not[LessEqual[th, 7.5e+18]], $MachinePrecision], LessEqual[th, 1.25e+76]]], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 1.25 \cdot 10^{+76}:\\
\;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 1.55000000000000004 or 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 1.25 \cdot 10^{+76}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \end{array} \]

Alternative 11: 39.7% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (* a2 (/ a2 (sqrt 2.0)))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (* a2 (* a2 (sqrt 0.5))))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * (a2 / sqrt(2.0));
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 * (a2 * sqrt(0.5));
	}
	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 <= 1.55d0) then
        tmp = a2 * (a2 / sqrt(2.0d0))
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = a2 * (a2 * sqrt(0.5d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 * (a2 * Math.sqrt(0.5));
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = a2 * (a2 / math.sqrt(2.0))
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = a2 * (a2 * math.sqrt(0.5))
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(a2 * Float64(a2 * sqrt(0.5)));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = a2 * (a2 / sqrt(2.0));
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = a2 * (a2 * sqrt(0.5));
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(a2 * N[(a2 * N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

\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 < 1.55000000000000004

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a2 \cdot a2}{\sqrt{2}}} \]
    8. Step-by-step derivation
      1. *-un-lft-identity40.9%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \end{array} \]

Alternative 12: 39.7% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (* a2 (/ a2 (sqrt 2.0)))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (/ a2 (/ (sqrt 2.0) a2)))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * (a2 / sqrt(2.0));
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 / (sqrt(2.0) / 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 <= 1.55d0) then
        tmp = a2 * (a2 / sqrt(2.0d0))
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = a2 / (sqrt(2.0d0) / a2)
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * (a2 / Math.sqrt(2.0));
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 / (Math.sqrt(2.0) / a2);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = a2 * (a2 / math.sqrt(2.0))
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = a2 / (math.sqrt(2.0) / a2)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(a2 * Float64(a2 / sqrt(2.0)));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(a2 / Float64(sqrt(2.0) / a2));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = a2 * (a2 / sqrt(2.0));
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = a2 / (sqrt(2.0) / a2);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(a2 * N[(a2 / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(a2 / N[(N[Sqrt[2.0], $MachinePrecision] / a2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

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


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]

Alternative 13: 39.8% accurate, 3.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (/ (* a2 a2) (sqrt 2.0))
   (if (or (<= th 7.5e+18) (not (<= th 1.25e+76)))
     (* a2 (* a2 -0.5))
     (/ a2 (/ (sqrt 2.0) a2)))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 / (sqrt(2.0) / 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 <= 1.55d0) then
        tmp = (a2 * a2) / sqrt(2.0d0)
    else if ((th <= 7.5d+18) .or. (.not. (th <= 1.25d+76))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = a2 / (sqrt(2.0d0) / a2)
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = (a2 * a2) / Math.sqrt(2.0);
	} else if ((th <= 7.5e+18) || !(th <= 1.25e+76)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = a2 / (Math.sqrt(2.0) / a2);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = (a2 * a2) / math.sqrt(2.0)
	elif (th <= 7.5e+18) or not (th <= 1.25e+76):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = a2 / (math.sqrt(2.0) / a2)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(Float64(a2 * a2) / sqrt(2.0));
	elseif ((th <= 7.5e+18) || !(th <= 1.25e+76))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(a2 / Float64(sqrt(2.0) / a2));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = (a2 * a2) / sqrt(2.0);
	elseif ((th <= 7.5e+18) || ~((th <= 1.25e+76)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = a2 / (sqrt(2.0) / a2);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(N[(a2 * a2), $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 1.25e+76]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(a2 / N[(N[Sqrt[2.0], $MachinePrecision] / a2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

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


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 1.24999999999999998e76 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt10.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-unprod10.5%

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

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

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

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

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

      \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
    10. Applied egg-rr20.7%

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.7%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.7%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.7%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.7%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.7%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.7%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.7%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.7%

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

    if 7.5e18 < th < 1.24999999999999998e76

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 1.25 \cdot 10^{+76}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]

Alternative 14: 30.3% accurate, 34.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 4.4 \cdot 10^{+73}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot -0.5\right) \cdot \left(-a2\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (<= th 1.55)
   (* a2 a2)
   (if (or (<= th 7.5e+18) (not (<= th 4.4e+73)))
     (* a2 (* a2 -0.5))
     (* (* a2 -0.5) (- a2)))))
double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * a2;
	} else if ((th <= 7.5e+18) || !(th <= 4.4e+73)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = (a2 * -0.5) * -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 <= 1.55d0) then
        tmp = a2 * a2
    else if ((th <= 7.5d+18) .or. (.not. (th <= 4.4d+73))) then
        tmp = a2 * (a2 * (-0.5d0))
    else
        tmp = (a2 * (-0.5d0)) * -a2
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if (th <= 1.55) {
		tmp = a2 * a2;
	} else if ((th <= 7.5e+18) || !(th <= 4.4e+73)) {
		tmp = a2 * (a2 * -0.5);
	} else {
		tmp = (a2 * -0.5) * -a2;
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if th <= 1.55:
		tmp = a2 * a2
	elif (th <= 7.5e+18) or not (th <= 4.4e+73):
		tmp = a2 * (a2 * -0.5)
	else:
		tmp = (a2 * -0.5) * -a2
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if (th <= 1.55)
		tmp = Float64(a2 * a2);
	elseif ((th <= 7.5e+18) || !(th <= 4.4e+73))
		tmp = Float64(a2 * Float64(a2 * -0.5));
	else
		tmp = Float64(Float64(a2 * -0.5) * Float64(-a2));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if (th <= 1.55)
		tmp = a2 * a2;
	elseif ((th <= 7.5e+18) || ~((th <= 4.4e+73)))
		tmp = a2 * (a2 * -0.5);
	else
		tmp = (a2 * -0.5) * -a2;
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[LessEqual[th, 1.55], N[(a2 * a2), $MachinePrecision], If[Or[LessEqual[th, 7.5e+18], N[Not[LessEqual[th, 4.4e+73]], $MachinePrecision]], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision], N[(N[(a2 * -0.5), $MachinePrecision] * (-a2)), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55:\\
\;\;\;\;a2 \cdot a2\\

\mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 4.4 \cdot 10^{+73}\right):\\
\;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\

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


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

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 4.4e73 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt12.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-unprod12.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.3%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.3%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.3%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.3%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.3%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.3%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.3%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.3%

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

    if 7.5e18 < th < 4.4e73

    1. Initial program 99.8%

      \[\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. +-commutative99.8%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.8%

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{elif}\;th \leq 7.5 \cdot 10^{+18} \lor \neg \left(th \leq 4.4 \cdot 10^{+73}\right):\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot -0.5\right) \cdot \left(-a2\right)\\ \end{array} \]

Alternative 15: 30.3% accurate, 37.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 4.4 \cdot 10^{+73}:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \end{array} \end{array} \]
(FPCore (a1 a2 th)
 :precision binary64
 (if (or (<= th 1.55) (and (not (<= th 7.5e+18)) (<= th 4.4e+73)))
   (* a2 a2)
   (* a2 (* a2 -0.5))))
double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 4.4e+73))) {
		tmp = a2 * a2;
	} else {
		tmp = a2 * (a2 * -0.5);
	}
	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 <= 1.55d0) .or. (.not. (th <= 7.5d+18)) .and. (th <= 4.4d+73)) then
        tmp = a2 * a2
    else
        tmp = a2 * (a2 * (-0.5d0))
    end if
    code = tmp
end function
public static double code(double a1, double a2, double th) {
	double tmp;
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 4.4e+73))) {
		tmp = a2 * a2;
	} else {
		tmp = a2 * (a2 * -0.5);
	}
	return tmp;
}
def code(a1, a2, th):
	tmp = 0
	if (th <= 1.55) or (not (th <= 7.5e+18) and (th <= 4.4e+73)):
		tmp = a2 * a2
	else:
		tmp = a2 * (a2 * -0.5)
	return tmp
function code(a1, a2, th)
	tmp = 0.0
	if ((th <= 1.55) || (!(th <= 7.5e+18) && (th <= 4.4e+73)))
		tmp = Float64(a2 * a2);
	else
		tmp = Float64(a2 * Float64(a2 * -0.5));
	end
	return tmp
end
function tmp_2 = code(a1, a2, th)
	tmp = 0.0;
	if ((th <= 1.55) || (~((th <= 7.5e+18)) && (th <= 4.4e+73)))
		tmp = a2 * a2;
	else
		tmp = a2 * (a2 * -0.5);
	end
	tmp_2 = tmp;
end
code[a1_, a2_, th_] := If[Or[LessEqual[th, 1.55], And[N[Not[LessEqual[th, 7.5e+18]], $MachinePrecision], LessEqual[th, 4.4e+73]]], N[(a2 * a2), $MachinePrecision], N[(a2 * N[(a2 * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 4.4 \cdot 10^{+73}:\\
\;\;\;\;a2 \cdot a2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if th < 1.55000000000000004 or 7.5e18 < th < 4.4e73

    1. Initial program 99.2%

      \[\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. +-commutative99.2%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.2%

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

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

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

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

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

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

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

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

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

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

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

    if 1.55000000000000004 < th < 7.5e18 or 4.4e73 < 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. Step-by-step derivation
      1. +-commutative99.5%

        \[\leadsto \color{blue}{\frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right)} \]
      2. distribute-lft-out99.5%

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

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

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

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

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

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

        \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \frac{1}{\sqrt{2}}} \]
      2. add-sqr-sqrt12.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-unprod12.3%

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

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

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

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

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

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

      \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
    11. Step-by-step derivation
      1. *-lft-identity20.3%

        \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
      2. *-inverses20.3%

        \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
      3. associate-*l/20.3%

        \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
      4. associate-/r/20.3%

        \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
      5. *-inverses20.3%

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

        \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
      7. *-commutative20.3%

        \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
      8. *-commutative20.3%

        \[\leadsto a2 \cdot \color{blue}{\left(a2 \cdot -0.5\right)} \]
    12. Simplified20.3%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;th \leq 1.55 \lor \neg \left(th \leq 7.5 \cdot 10^{+18}\right) \land th \leq 4.4 \cdot 10^{+73}:\\ \;\;\;\;a2 \cdot a2\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot -0.5\right)\\ \end{array} \]

Alternative 16: 15.2% accurate, 83.0× speedup?

\[\begin{array}{l} \\ a2 \cdot \left(a2 \cdot -0.5\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 * -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 -0.5\right)
\end{array}
Derivation
  1. Initial program 99.3%

    \[\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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
  9. Applied egg-rr39.6%

    \[\leadsto \color{blue}{\left(a2 \cdot a2\right) \cdot \sqrt{0.5}} \]
  10. Applied egg-rr14.6%

    \[\leadsto \color{blue}{\frac{a2}{\frac{-2}{a2}}} \]
  11. Step-by-step derivation
    1. *-lft-identity14.6%

      \[\leadsto \frac{\color{blue}{1 \cdot a2}}{\frac{-2}{a2}} \]
    2. *-inverses14.6%

      \[\leadsto \frac{\color{blue}{\frac{a2 + a1}{a2 + a1}} \cdot a2}{\frac{-2}{a2}} \]
    3. associate-*l/14.6%

      \[\leadsto \color{blue}{\frac{\frac{a2 + a1}{a2 + a1}}{\frac{-2}{a2}} \cdot a2} \]
    4. associate-/r/14.6%

      \[\leadsto \color{blue}{\left(\frac{\frac{a2 + a1}{a2 + a1}}{-2} \cdot a2\right)} \cdot a2 \]
    5. *-inverses14.6%

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

      \[\leadsto \left(\color{blue}{-0.5} \cdot a2\right) \cdot a2 \]
    7. *-commutative14.6%

      \[\leadsto \color{blue}{a2 \cdot \left(-0.5 \cdot a2\right)} \]
    8. *-commutative14.6%

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

    \[\leadsto \color{blue}{a2 \cdot \left(a2 \cdot -0.5\right)} \]
  13. Final simplification14.6%

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

Alternative 17: 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.3%

    \[\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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    \[\leadsto a1 \]

Alternative 18: 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.3%

    \[\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. +-commutative99.3%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \left(a2 \cdot a2\right) \cdot \sqrt{\color{blue}{0.5}} \]
  9. Applied egg-rr39.6%

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

    \[\leadsto \color{blue}{0 + a2} \]
  11. Final simplification3.7%

    \[\leadsto a2 \]

Reproduce

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