\[ \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)
Alternatives
| Alternative 1 |
|---|
| Error | 0.5 |
|---|
| Cost | 26112 |
|---|
\[\cos th \cdot \left({2}^{-0.5} \cdot {\left(\mathsf{hypot}\left(a2, a1\right)\right)}^{2}\right)
\]
| Alternative 2 |
|---|
| Error | 0.5 |
|---|
| Cost | 19840 |
|---|
\[\left(\cos th \cdot {2}^{-0.5}\right) \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right)
\]
| Alternative 3 |
|---|
| Error | 15.0 |
|---|
| Cost | 19780 |
|---|
\[\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 |
|---|
| Error | 15.0 |
|---|
| Cost | 19780 |
|---|
\[\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 |
|---|
| Error | 8.1 |
|---|
| Cost | 13644 |
|---|
\[\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 |
|---|
| Error | 8.1 |
|---|
| Cost | 13644 |
|---|
\[\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 |
|---|
| Error | 0.5 |
|---|
| Cost | 13568 |
|---|
\[\left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)
\]
| Alternative 8 |
|---|
| Error | 0.5 |
|---|
| Cost | 13504 |
|---|
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)
\]
| Alternative 9 |
|---|
| Error | 30.7 |
|---|
| Cost | 7244 |
|---|
\[\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 |
|---|
| Error | 30.8 |
|---|
| Cost | 7180 |
|---|
\[\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 |
|---|
| Error | 30.8 |
|---|
| Cost | 7116 |
|---|
\[\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 |
|---|
| Error | 30.8 |
|---|
| Cost | 7116 |
|---|
\[\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 |
|---|
| Error | 26.0 |
|---|
| Cost | 6976 |
|---|
\[\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{0.5}
\]
| Alternative 14 |
|---|
| Error | 40.3 |
|---|
| Cost | 6720 |
|---|
\[\frac{a1}{\frac{\sqrt{2}}{a1}}
\]