Average Error: 0.5 → 0.4
Time: 5.4min
Precision: binary64
Cost: 39808
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\]
\[\cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot {2}^{-0.25}\right)}{\sqrt{\sqrt{2}}}\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot {2}^{-0.25}\right)}{\sqrt{\sqrt{2}}}
(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)
  (/
   (*
    (sqrt (+ (* a1 a1) (* a2 a2)))
    (* (sqrt (+ (* a1 a1) (* a2 a2))) (pow 2.0 -0.25)))
   (sqrt (sqrt 2.0)))))
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) * ((sqrt((a1 * a1) + (a2 * a2)) * (sqrt((a1 * a1) + (a2 * a2)) * pow(2.0, -0.25))) / sqrt(sqrt(2.0)));
}

Error

Bits error versus a1

Bits error versus a2

Bits error versus th

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Alternatives

Alternative 1
Error0.4
Cost26496
\[\cos th \cdot \frac{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot {2}^{-0.25}}{\sqrt{\sqrt{2}}}\]
Alternative 2
Error0.5
Cost13504
\[\frac{\cos th \cdot \left(a1 \cdot a1 + a2 \cdot a2\right)}{\sqrt{2}}\]
Alternative 3
Error0.5
Cost13504
\[\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\]
Alternative 4
Error13.5
Cost15493
\[\begin{array}{l} \mathbf{if}\;a1 \cdot a1 \leq 5.5406682379231035 \cdot 10^{-232}:\\ \;\;\;\;\frac{\cos th \cdot \left(a2 \cdot a2\right)}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.3445454856326036 \cdot 10^{-140}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.444579836623024 \cdot 10^{-88}:\\ \;\;\;\;\frac{\cos th \cdot \left(a2 \cdot a2\right)}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 2.4993126033898824 \cdot 10^{-71}:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 4.419534811911095 \cdot 10^{-37}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos th \cdot \left(a1 \cdot a1\right)}{\sqrt{2}}\\ \end{array}\]
Alternative 5
Error13.5
Cost15493
\[\begin{array}{l} \mathbf{if}\;a1 \cdot a1 \leq 5.5406682379231035 \cdot 10^{-232}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.3445454856326036 \cdot 10^{-140}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.444579836623024 \cdot 10^{-88}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 2.4993126033898824 \cdot 10^{-71}:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 4.419534811911095 \cdot 10^{-37}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\cos th \cdot \left(a1 \cdot a1\right)}{\sqrt{2}}\\ \end{array}\]
Alternative 6
Error13.5
Cost15493
\[\begin{array}{l} \mathbf{if}\;a1 \cdot a1 \leq 5.5406682379231035 \cdot 10^{-232}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.3445454856326036 \cdot 10^{-140}:\\ \;\;\;\;\frac{1}{\frac{\sqrt{2}}{a1 \cdot a1 + a2 \cdot a2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 3.444579836623024 \cdot 10^{-88}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 2.4993126033898824 \cdot 10^{-71}:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{elif}\;a1 \cdot a1 \leq 4.419534811911095 \cdot 10^{-37}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a1 \cdot a1}{\sqrt{2}}\\ \end{array}\]
Alternative 7
Error14.6
Cost19969
\[\begin{array}{l} \mathbf{if}\;\cos th \leq 0.9988849504208668:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\\ \end{array}\]
Alternative 8
Error26.0
Cost6976
\[\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\]
Alternative 9
Error33.6
Cost7048
\[\begin{array}{l} \mathbf{if}\;a2 \leq -1.6684151299955752 \cdot 10^{-158} \lor \neg \left(a2 \leq 1.7098555952575793 \cdot 10^{-146}\right):\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \end{array}\]
Alternative 10
Error33.6
Cost7048
\[\begin{array}{l} \mathbf{if}\;a2 \leq -1.6684151299955752 \cdot 10^{-158} \lor \neg \left(a2 \leq 2.0146837817686424 \cdot 10^{-146}\right):\\ \;\;\;\;\frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{a1 \cdot a1}{\sqrt{2}}\\ \end{array}\]
Alternative 11
Error40.4
Cost6720
\[\frac{a1 \cdot a1}{\sqrt{2}}\]
Alternative 12
Error40.4
Cost6720
\[a1 \cdot \frac{a1}{\sqrt{2}}\]
Alternative 13
Error55.6
Cost64
\[0\]
Alternative 14
Error62.4
Cost64
\[-1\]

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

    \[\leadsto \color{blue}{\cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}}\]
  3. Using strategy rm
  4. Applied add-sqr-sqrt_binary64_4410.5

    \[\leadsto \cos th \cdot \frac{a1 \cdot a1 + a2 \cdot a2}{\color{blue}{\sqrt{\sqrt{2}} \cdot \sqrt{\sqrt{2}}}}\]
  5. Applied associate-/r*_binary64_3630.5

    \[\leadsto \cos th \cdot \color{blue}{\frac{\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{\sqrt{2}}}}{\sqrt{\sqrt{2}}}}\]
  6. Taylor expanded around 0 0.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{{a2}^{2} \cdot \sqrt{\frac{1}{\sqrt{2}}} + {a1}^{2} \cdot \sqrt{\frac{1}{\sqrt{2}}}}}{\sqrt{\sqrt{2}}}\]
  7. Simplified0.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \sqrt{\frac{1}{\sqrt{2}}}}}{\sqrt{\sqrt{2}}}\]
  8. Using strategy rm
  9. Applied add-sqr-sqrt_binary64_4410.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{\left(\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)} \cdot \sqrt{\frac{1}{\sqrt{2}}}}{\sqrt{\sqrt{2}}}\]
  10. Applied associate-*l*_binary64_3600.4

    \[\leadsto \cos th \cdot \frac{\color{blue}{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \sqrt{\frac{1}{\sqrt{2}}}\right)}}{\sqrt{\sqrt{2}}}\]
  11. Simplified0.4

    \[\leadsto \cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \color{blue}{\left(\sqrt{\frac{1}{\sqrt{2}}} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}}{\sqrt{\sqrt{2}}}\]
  12. Using strategy rm
  13. Applied pow1/2_binary64_4990.4

    \[\leadsto \cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\sqrt{\frac{1}{\color{blue}{{2}^{0.5}}}} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}{\sqrt{\sqrt{2}}}\]
  14. Applied pow-flip_binary64_4930.7

    \[\leadsto \cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\sqrt{\color{blue}{{2}^{\left(-0.5\right)}}} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}{\sqrt{\sqrt{2}}}\]
  15. Applied sqrt-pow1_binary64_4370.4

    \[\leadsto \cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left(\color{blue}{{2}^{\left(\frac{-0.5}{2}\right)}} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}{\sqrt{\sqrt{2}}}\]
  16. Simplified0.4

    \[\leadsto \cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left({2}^{\color{blue}{-0.25}} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}{\sqrt{\sqrt{2}}}\]
  17. Simplified0.4

    \[\leadsto \color{blue}{\cos th \cdot \frac{\sqrt{a1 \cdot a1 + a2 \cdot a2} \cdot \left({2}^{-0.25} \cdot \sqrt{a1 \cdot a1 + a2 \cdot a2}\right)}{\sqrt{\sqrt{2}}}}\]
  18. Final simplification0.4

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

Reproduce

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