Average Error: 0.5 → 0.5
Time: 12.2s
Precision: binary64
Cost: 13504
\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)\]
\[\frac{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}\]
\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right)
\frac{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \cos th}{\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
 (/ (* (+ (* a1 a1) (* a2 a2)) (cos th)) (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 (((a1 * a1) + (a2 * a2)) * cos(th)) / 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.5
Cost13504
\[\frac{a1 \cdot a1 + a2 \cdot a2}{\frac{\sqrt{2}}{\cos th}}\]
Alternative 2
Error13.5
Cost14860
\[\begin{array}{l} \mathbf{if}\;a2 \leq -0.00013996848613896063:\\ \;\;\;\;\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 1.4957781138824434 \cdot 10^{-90}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 3.658565851425877 \cdot 10^{-37}:\\ \;\;\;\;\left(a2 \cdot a2\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 14.067337249671915:\\ \;\;\;\;\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 8.559570785050661 \cdot 10^{+32} \lor \neg \left(a2 \leq 1.0013825153403935 \cdot 10^{+40}\right):\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \end{array}\]
Alternative 3
Error13.4
Cost14860
\[\begin{array}{l} \mathbf{if}\;a2 \leq -2.8656778876668223 \cdot 10^{-08}:\\ \;\;\;\;\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 2.0024369545087612 \cdot 10^{-89}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 3.6712194853085634 \cdot 10^{-36}:\\ \;\;\;\;\frac{\left(a2 \cdot a2\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 1.6161391151093947:\\ \;\;\;\;\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 8.559570785050661 \cdot 10^{+32} \lor \neg \left(a2 \leq 1.0013825153403935 \cdot 10^{+40}\right):\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \end{array}\]
Alternative 4
Error13.4
Cost14860
\[\begin{array}{l} \mathbf{if}\;a2 \leq -2.8656778876668223 \cdot 10^{-08}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 7.41520578192646 \cdot 10^{-89}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 3.21862941055769 \cdot 10^{-37}:\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 0.6566216709852691:\\ \;\;\;\;\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 8.559570785050661 \cdot 10^{+32} \lor \neg \left(a2 \leq 1.0013825153403935 \cdot 10^{+40}\right):\\ \;\;\;\;\cos th \cdot \frac{a2 \cdot a2}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \end{array}\]
Alternative 5
Error13.5
Cost13576
\[\begin{array}{l} \mathbf{if}\;th \leq -0.005518748015215943 \lor \neg \left(th \leq 0.013518404392208106\right):\\ \;\;\;\;\frac{\left(a1 \cdot a1\right) \cdot \cos th}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\left(a1 \cdot a1 + a2 \cdot a2\right) \cdot \left(1 - 0.5 \cdot \left(th \cdot th\right)\right)}{\sqrt{2}}\\ \end{array}\]
Alternative 6
Error25.0
Cost6976
\[\frac{a1 \cdot a1 + a2 \cdot a2}{\sqrt{2}}\]
Alternative 7
Error55.1
Cost64
\[0\]
Alternative 8
Error61.2
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 associate-*r/_binary64_3610.5

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

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

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

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

Reproduce

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