Average Error: 0.5 → 0.5
Time: 18.7s
Precision: binary64
Cost: 32832
\[ \begin{array}{c}[a1, a2] = \mathsf{sort}([a1, a2])\\ \end{array} \]
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
\[\mathsf{fma}\left(\frac{\cos th}{\sqrt{2}} \cdot a2, a2, \frac{a1 \cdot a1}{\frac{\sqrt{2}}{\cos th}}\right) \]
(FPCore (a1 a2 th)
 :precision binary64
 (+
  (* (/ (cos th) (sqrt 2.0)) (* a1 a1))
  (* (/ (cos th) (sqrt 2.0)) (* a2 a2))))
(FPCore (a1 a2 th)
 :precision binary64
 (fma (* (/ (cos th) (sqrt 2.0)) a2) a2 (/ (* a1 a1) (/ (sqrt 2.0) (cos th)))))
double code(double a1, double a2, double th) {
	return ((cos(th) / sqrt(2.0)) * (a1 * a1)) + ((cos(th) / sqrt(2.0)) * (a2 * a2));
}
double code(double a1, double a2, double th) {
	return fma(((cos(th) / sqrt(2.0)) * a2), a2, ((a1 * a1) / (sqrt(2.0) / cos(th))));
}
function code(a1, a2, th)
	return Float64(Float64(Float64(cos(th) / sqrt(2.0)) * Float64(a1 * a1)) + Float64(Float64(cos(th) / sqrt(2.0)) * Float64(a2 * a2)))
end
function code(a1, a2, th)
	return fma(Float64(Float64(cos(th) / sqrt(2.0)) * a2), a2, Float64(Float64(a1 * a1) / Float64(sqrt(2.0) / cos(th))))
end
code[a1_, a2_, th_] := N[(N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(a1 * a1), $MachinePrecision]), $MachinePrecision] + N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[(a2 * a2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a1_, a2_, th_] := N[(N[(N[(N[Cos[th], $MachinePrecision] / N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * a2), $MachinePrecision] * a2 + N[(N[(a1 * a1), $MachinePrecision] / N[(N[Sqrt[2.0], $MachinePrecision] / N[Cos[th], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\mathsf{fma}\left(\frac{\cos th}{\sqrt{2}} \cdot a2, a2, \frac{a1 \cdot a1}{\frac{\sqrt{2}}{\cos th}}\right)

Error

Derivation

  1. Initial program 0.5

    \[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
  2. Applied egg-rr0.5

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

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

Alternatives

Alternative 1
Error0.5
Cost26112
\[\cos th \cdot \left({2}^{-0.5} \cdot {\left(\mathsf{hypot}\left(a2, a1\right)\right)}^{2}\right) \]
Alternative 2
Error0.5
Cost19840
\[\left(\cos th \cdot {2}^{-0.5}\right) \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right) \]
Alternative 3
Error15.0
Cost19780
\[\begin{array}{l} \mathbf{if}\;\cos th \leq 0.995:\\ \;\;\;\;a1 \cdot \frac{\cos th}{\frac{\sqrt{2}}{a1}}\\ \mathbf{else}:\\ \;\;\;\;\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}\\ \end{array} \]
Alternative 4
Error15.0
Cost19780
\[\begin{array}{l} \mathbf{if}\;\cos th \leq 0.995:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}\\ \end{array} \]
Alternative 5
Error8.1
Cost13644
\[\begin{array}{l} t_1 := \cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right)\\ t_2 := \left(a1 \cdot a1\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right)\\ \mathbf{if}\;a1 \leq -4.5640751827832244 \cdot 10^{-95}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;a1 \leq -7.751057501607333 \cdot 10^{-115}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \leq -5.32141684441546 \cdot 10^{-142}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error8.1
Cost13644
\[\begin{array}{l} t_1 := \left(a1 \cdot a1\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right)\\ \mathbf{if}\;a1 \leq -9.579056287019564 \cdot 10^{-92}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \leq -7.751057501607333 \cdot 10^{-115}:\\ \;\;\;\;a2 \cdot \left(\frac{\cos th}{\sqrt{2}} \cdot a2\right)\\ \mathbf{elif}\;a1 \leq -5.32141684441546 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right)\\ \end{array} \]
Alternative 7
Error0.5
Cost13568
\[\left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
Alternative 8
Error0.5
Cost13504
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right) \]
Alternative 9
Error30.7
Cost7244
\[\begin{array}{l} t_1 := a2 \cdot \sqrt{\frac{a2 \cdot a2}{2}}\\ \mathbf{if}\;a1 \leq -6.727296152610243 \cdot 10^{-48}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \mathbf{elif}\;a1 \leq -5.057685158200246 \cdot 10^{-113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \leq -1.698603008135742 \cdot 10^{-136}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error30.8
Cost7180
\[\begin{array}{l} \mathbf{if}\;a1 \leq -6.727296152610243 \cdot 10^{-48}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \mathbf{elif}\;a1 \leq -5.057685158200246 \cdot 10^{-113}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \leq -1.698603008135742 \cdot 10^{-136}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot {2}^{-0.5}\right)\\ \end{array} \]
Alternative 11
Error30.8
Cost7116
\[\begin{array}{l} t_1 := \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \mathbf{if}\;a1 \leq -6.727296152610243 \cdot 10^{-48}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \mathbf{elif}\;a1 \leq -5.057685158200246 \cdot 10^{-113}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a1 \leq -1.698603008135742 \cdot 10^{-136}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error30.8
Cost7116
\[\begin{array}{l} \mathbf{if}\;a1 \leq -6.727296152610243 \cdot 10^{-48}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \mathbf{elif}\;a1 \leq -5.057685158200246 \cdot 10^{-113}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \leq -1.698603008135742 \cdot 10^{-136}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 13
Error26.0
Cost6976
\[\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5} \]
Alternative 14
Error40.3
Cost6720
\[\frac{a1}{\frac{\sqrt{2}}{a1}} \]

Error

Reproduce

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