?

Average Accuracy: 99.1% → 99.3%
Time: 19.3s
Precision: binary64
Cost: 26176

?

\[\frac{\cos th}{\sqrt{2}} \cdot \left(a1 \cdot a1\right) + \frac{\cos th}{\sqrt{2}} \cdot \left(a2 \cdot a2\right) \]
\[\frac{\mathsf{hypot}\left(a1, a2\right) \cdot \cos th}{\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
 (/ (* (hypot a1 a2) (cos th)) (/ (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 (hypot(a1, a2) * cos(th)) / (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.hypot(a1, a2) * Math.cos(th)) / (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.hypot(a1, a2) * math.cos(th)) / (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(hypot(a1, a2) * cos(th)) / 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 = (hypot(a1, a2) * cos(th)) / (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[Sqrt[a1 ^ 2 + a2 ^ 2], $MachinePrecision] * N[Cos[th], $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{\mathsf{hypot}\left(a1, a2\right) \cdot \cos th}{\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 99.1%

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

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

    [Start]99.1

    \[ \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 [=>]99.2

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

    associate-*l/ [=>]99.2

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

    associate-*r/ [<=]99.2

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

    fma-def [=>]99.2

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

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

    [Start]99.2

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

    *-commutative [=>]99.2

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

    add-sqr-sqrt [=>]99.2

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

    associate-/l* [=>]99.2

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

    associate-*l/ [=>]99.2

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

    fma-udef [=>]99.2

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

    hypot-def [=>]99.2

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

    fma-udef [=>]99.2

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

    hypot-def [=>]99.3

    \[ \frac{\mathsf{hypot}\left(a1, a2\right) \cdot \cos th}{\frac{\sqrt{2}}{\color{blue}{\mathsf{hypot}\left(a1, a2\right)}}} \]
  4. Final simplification99.3%

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

Alternatives

Alternative 1
Accuracy99.2%
Cost19776
\[\cos th \cdot \frac{\mathsf{fma}\left(a1, a1, a2 \cdot a2\right)}{\sqrt{2}} \]
Alternative 2
Accuracy67.3%
Cost13777
\[\begin{array}{l} \mathbf{if}\;a2 \leq 3.05 \cdot 10^{-158}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{elif}\;a2 \leq 1.45 \cdot 10^{-81} \lor \neg \left(a2 \leq 1.9 \cdot 10^{-54}\right) \land a2 \leq 1.12 \cdot 10^{-14}:\\ \;\;\;\;\frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \left(\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\right)\\ \end{array} \]
Alternative 3
Accuracy67.3%
Cost13777
\[\begin{array}{l} \mathbf{if}\;a2 \leq 1.5 \cdot 10^{-155}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{elif}\;a2 \leq 1.45 \cdot 10^{-81} \lor \neg \left(a2 \leq 1.12 \cdot 10^{-54}\right) \land a2 \leq 3.4 \cdot 10^{-14}:\\ \;\;\;\;\frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 4
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 8.2 \cdot 10^{-157}:\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{elif}\;a2 \leq 1.36 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 10^{-51}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a2 \cdot \left(a2 \cdot \cos th\right)\right)\\ \mathbf{elif}\;a2 \leq 3.3 \cdot 10^{-13}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 5
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 1.7 \cdot 10^{-155}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1\right)\right)\\ \mathbf{elif}\;a2 \leq 1.36 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 1.75 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a2 \cdot \left(a2 \cdot \cos th\right)\right)\\ \mathbf{elif}\;a2 \leq 9.2 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 6
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 1.05 \cdot 10^{-155}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\cos th \cdot \left(a1 \cdot a1\right)\right)\\ \mathbf{elif}\;a2 \leq 9 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 9.2 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\cos th \cdot \left(a2 \cdot a2\right)\right)\\ \mathbf{elif}\;a2 \leq 1.1 \cdot 10^{-14}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 7
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 3.8 \cdot 10^{-156}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a1 \cdot \left(a1 \cdot \cos th\right)\right)\\ \mathbf{elif}\;a2 \leq 1.45 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 4.3 \cdot 10^{-54}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(\cos th \cdot \left(a2 \cdot a2\right)\right)\\ \mathbf{elif}\;a2 \leq 9 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 8
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 2.1 \cdot 10^{-155}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a1 \cdot \left(a1 \cdot \cos th\right)\right)\\ \mathbf{elif}\;a2 \leq 9 \cdot 10^{-82}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 1.18 \cdot 10^{-54}:\\ \;\;\;\;\left(a2 \cdot a2\right) \cdot \frac{\cos th}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 7.2 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 9
Accuracy67.3%
Cost13776
\[\begin{array}{l} t_1 := \frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}}\\ \mathbf{if}\;a2 \leq 1.22 \cdot 10^{-155}:\\ \;\;\;\;\sqrt{0.5} \cdot \left(a1 \cdot \left(a1 \cdot \cos th\right)\right)\\ \mathbf{elif}\;a2 \leq 1.45 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;a2 \leq 1.25 \cdot 10^{-54}:\\ \;\;\;\;\frac{a2 \cdot \left(a2 \cdot \cos th\right)}{\sqrt{2}}\\ \mathbf{elif}\;a2 \leq 8.5 \cdot 10^{-15}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;\cos th \cdot \frac{a2}{\frac{\sqrt{2}}{a2}}\\ \end{array} \]
Alternative 10
Accuracy99.2%
Cost13568
\[\left(\cos th \cdot {2}^{-0.5}\right) \cdot \left(a2 \cdot a2 + a1 \cdot a1\right) \]
Alternative 11
Accuracy76.5%
Cost13513
\[\begin{array}{l} \mathbf{if}\;th \leq -0.0115 \lor \neg \left(th \leq 15\right):\\ \;\;\;\;a1 \cdot \left(a1 \cdot \left(\cos th \cdot \sqrt{0.5}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \left(\sqrt{0.5} \cdot \left(-0.5 \cdot \left(th \cdot th\right) + 1\right)\right)\\ \end{array} \]
Alternative 12
Accuracy99.2%
Cost13504
\[\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \frac{\cos th}{\sqrt{2}} \]
Alternative 13
Accuracy99.2%
Cost13504
\[\frac{a2 \cdot a2 + a1 \cdot a1}{\frac{\sqrt{2}}{\cos th}} \]
Alternative 14
Accuracy59.2%
Cost6976
\[\left(a2 \cdot a2 + a1 \cdot a1\right) \cdot \sqrt{0.5} \]
Alternative 15
Accuracy59.2%
Cost6976
\[\frac{a2 \cdot a2 + a1 \cdot a1}{\sqrt{2}} \]
Alternative 16
Accuracy42.3%
Cost6852
\[\begin{array}{l} \mathbf{if}\;a1 \leq -1.4 \cdot 10^{-145}:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;\left(a2 \cdot a2\right) \cdot \sqrt{0.5}\\ \end{array} \]
Alternative 17
Accuracy42.3%
Cost6852
\[\begin{array}{l} \mathbf{if}\;a1 \leq -1.4 \cdot 10^{-145}:\\ \;\;\;\;\left(a1 \cdot a1\right) \cdot \sqrt{0.5}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \]
Alternative 18
Accuracy42.3%
Cost6852
\[\begin{array}{l} \mathbf{if}\;a1 \leq -1.4 \cdot 10^{-145}:\\ \;\;\;\;\frac{a1}{\frac{\sqrt{2}}{a1}}\\ \mathbf{else}:\\ \;\;\;\;a2 \cdot \frac{a2}{\sqrt{2}}\\ \end{array} \]
Alternative 19
Accuracy37.1%
Cost6720
\[a1 \cdot \left(a1 \cdot \sqrt{0.5}\right) \]
Alternative 20
Accuracy37.1%
Cost6720
\[a1 \cdot \frac{a1}{\sqrt{2}} \]
Alternative 21
Accuracy37.1%
Cost6720
\[\left(a1 \cdot a1\right) \cdot \sqrt{0.5} \]

Error

Reproduce?

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