?

Average Error: 0.5 → 0.5
Time: 16.4s
Precision: binary64
Cost: 26304

?

\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
\[\frac{\frac{\cos th}{\frac{1}{\mathsf{hypot}\left(a1, a2\right)}}}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\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
 (/ (/ (cos th) (/ 1.0 (hypot a1 a2))) (/ (sqrt 2.0) (hypot a1 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) {
	return (cos(th) / (1.0 / hypot(a1, a2))) / (sqrt(2.0) / hypot(a1, a2));
}
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) {
	return (Math.cos(th) / (1.0 / Math.hypot(a1, a2))) / (Math.sqrt(2.0) / Math.hypot(a1, 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):
	return (math.cos(th) / (1.0 / math.hypot(a1, a2))) / (math.sqrt(2.0) / math.hypot(a1, 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)
	return Float64(Float64(cos(th) / Float64(1.0 / hypot(a1, a2))) / Float64(sqrt(2.0) / hypot(a1, 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)
	tmp = (cos(th) / (1.0 / hypot(a1, a2))) / (sqrt(2.0) / hypot(a1, 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_] := N[(N[(N[Cos[th], $MachinePrecision] / N[(1.0 / N[Sqrt[a1 ^ 2 + a2 ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[2.0], $MachinePrecision] / N[Sqrt[a1 ^ 2 + a2 ^ 2], $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)
\frac{\frac{\cos th}{\frac{1}{\mathsf{hypot}\left(a1, a2\right)}}}{\frac{\sqrt{2}}{\mathsf{hypot}\left(a1, a2\right)}}

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. Simplified0.5

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

    [Start]0.5

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

    distribute-lft-out [=>]0.5

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

    associate-*l/ [=>]0.5

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

    associate-*r/ [<=]0.5

    \[ \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}} \]

    fma-def [=>]0.5

    \[ \cos th \cdot \frac{\color{blue}{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}}{\sqrt{2}} \]
  3. Applied egg-rr0.5

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

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

Alternatives

Alternative 1
Error0.5
Cost26240
\[\cos th \cdot \left(\mathsf{hypot}\left(a1, a2\right) \cdot \left(\mathsf{hypot}\left(a1, a2\right) \cdot {2}^{-0.5}\right)\right) \]
Alternative 2
Error0.5
Cost20160
\[\cos th \cdot \left({2}^{-0.5} \cdot \left(a2 \cdot a2\right) + {2}^{-0.5} \cdot \left(a1 \cdot a1\right)\right) \]
Alternative 3
Error20.7
Cost13645
\[\begin{array}{l} \mathbf{if}\;a2 \leq 2.6 \cdot 10^{-148} \lor \neg \left(a2 \leq 3.8 \cdot 10^{-135}\right) \land a2 \leq 3.7 \cdot 10^{-109}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right)\\ \end{array} \]
Alternative 4
Error14.7
Cost13513
\[\begin{array}{l} \mathbf{if}\;th \leq -1400000000 \lor \neg \left(th \leq 0.0023\right):\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right)\\ \end{array} \]
Alternative 5
Error0.5
Cost13504
\[\cos th \cdot \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}} \]
Alternative 6
Error0.5
Cost13504
\[\sqrt{0.5} \cdot \left(\cos th \cdot \left(a2 \cdot a2 + a1 \cdot a1\right)\right) \]
Alternative 7
Error26.3
Cost6976
\[\sqrt{0.5} \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
Alternative 8
Error37.0
Cost6852
\[\begin{array}{l} \mathbf{if}\;a2 \leq 2.45 \cdot 10^{-147}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \sqrt{0.5}\right)\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \left(a2 \cdot \sqrt{0.5}\right)\\ \end{array} \]
Alternative 9
Error41.1
Cost6720
\[a1 \cdot \left(a1 \cdot \sqrt{0.5}\right) \]

Error

Reproduce?

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