Average Error: 0.5 → 0.5
Time: 17.2s
Precision: binary64
Cost: 26560
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
\[\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} \]
(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
 (let* ((t_1 (/ (cos th) (sqrt 2.0))))
   (+ (* t_1 (* a1 a1)) (* t_1 (* a2 a2)))))
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) {
	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
    code = ((cos(th) / sqrt(2.0d0)) * (a1 * a1)) + ((cos(th) / sqrt(2.0d0)) * (a2 * a2))
end function
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) {
	return ((Math.cos(th) / Math.sqrt(2.0)) * (a1 * a1)) + ((Math.cos(th) / Math.sqrt(2.0)) * (a2 * a2));
}
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):
	return ((math.cos(th) / math.sqrt(2.0)) * (a1 * a1)) + ((math.cos(th) / math.sqrt(2.0)) * (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)
	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)
	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)
	tmp = ((cos(th) / sqrt(2.0)) * (a1 * a1)) + ((cos(th) / sqrt(2.0)) * (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_] := 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_] := 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]]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\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}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

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. Final simplification0.5

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

Alternatives

Alternative 1
Error0.5
Cost19776
\[\mathsf{fma}\left(a1, a1, a2 \cdot a2\right) \cdot \left(\cos th \cdot \sqrt{0.5}\right) \]
Alternative 2
Error0.5
Cost19776
\[\frac{\cos th}{\sqrt{2}} \cdot \mathsf{fma}\left(a1, a1, a2 \cdot a2\right) \]
Alternative 3
Error0.8
Cost13632
\[\frac{1}{\frac{\sqrt{2}}{\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)}} \]
Alternative 4
Error30.7
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;\frac{a1 \cdot \left(\cos th \cdot a1\right)}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 5
Error30.7
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(\cos th \cdot \left(a1 \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 6
Error20.9
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(\cos th \cdot \left(a1 \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\cos th \cdot a2\right) \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \end{array} \]
Alternative 7
Error20.9
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(\cos th \cdot \left(a1 \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{\cos th \cdot a2}{\sqrt{2}}\\ \end{array} \]
Alternative 8
Error20.9
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(\cos th \cdot \left(a1 \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 9
Error20.9
Cost13380
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(\cos th \cdot \left(a1 \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2 \cdot \left(\cos th \cdot a2\right)}{\sqrt{2}}\\ \end{array} \]
Alternative 10
Error37.2
Cost6852
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 11
Error37.2
Cost6852
\[\begin{array}{l} \mathbf{if}\;a1 \leq -3.8590418092419056 \cdot 10^{-143}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 12
Error40.6
Cost6720
\[\frac{a1 \cdot a1}{\sqrt{2}} \]

Error

Reproduce

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