(FPCore (x) :precision binary64 (sqrt (* (* 2.0 x) x)))
(FPCore (x) :precision binary64 (hypot x x))
double code(double x) {
return sqrt(((2.0 * x) * x));
}
double code(double x) {
return hypot(x, x);
}
public static double code(double x) {
return Math.sqrt(((2.0 * x) * x));
}
public static double code(double x) {
return Math.hypot(x, x);
}
def code(x): return math.sqrt(((2.0 * x) * x))
def code(x): return math.hypot(x, x)
function code(x) return sqrt(Float64(Float64(2.0 * x) * x)) end
function code(x) return hypot(x, x) end
function tmp = code(x) tmp = sqrt(((2.0 * x) * x)); end
function tmp = code(x) tmp = hypot(x, x); end
code[x_] := N[Sqrt[N[(N[(2.0 * x), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision]
\sqrt{\left(2 \cdot x\right) \cdot x}
\mathsf{hypot}\left(x, x\right)
Results
Initial program 52.7%
Applied egg-rr49.8%
[Start]52.7 | \[ \sqrt{\left(2 \cdot x\right) \cdot x}
\] |
|---|---|
add-sqr-sqrt [=>]52.4 | \[ \color{blue}{\sqrt{\sqrt{\left(2 \cdot x\right) \cdot x}} \cdot \sqrt{\sqrt{\left(2 \cdot x\right) \cdot x}}}
\] |
pow2 [=>]52.4 | \[ \color{blue}{{\left(\sqrt{\sqrt{\left(2 \cdot x\right) \cdot x}}\right)}^{2}}
\] |
associate-*l* [=>]52.4 | \[ {\left(\sqrt{\sqrt{\color{blue}{2 \cdot \left(x \cdot x\right)}}}\right)}^{2}
\] |
sqrt-prod [=>]52.3 | \[ {\left(\sqrt{\color{blue}{\sqrt{2} \cdot \sqrt{x \cdot x}}}\right)}^{2}
\] |
sqrt-unprod [<=]49.7 | \[ {\left(\sqrt{\sqrt{2} \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}}\right)}^{2}
\] |
add-sqr-sqrt [<=]49.8 | \[ {\left(\sqrt{\sqrt{2} \cdot \color{blue}{x}}\right)}^{2}
\] |
Applied egg-rr52.4%
[Start]49.8 | \[ {\left(\sqrt{\sqrt{2} \cdot x}\right)}^{2}
\] |
|---|---|
add-sqr-sqrt [=>]49.8 | \[ {\left(\sqrt{\color{blue}{\sqrt{\sqrt{2} \cdot x} \cdot \sqrt{\sqrt{2} \cdot x}}}\right)}^{2}
\] |
sqrt-unprod [=>]52.3 | \[ {\left(\sqrt{\color{blue}{\sqrt{\left(\sqrt{2} \cdot x\right) \cdot \left(\sqrt{2} \cdot x\right)}}}\right)}^{2}
\] |
swap-sqr [=>]52.2 | \[ {\left(\sqrt{\sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \left(x \cdot x\right)}}}\right)}^{2}
\] |
add-sqr-sqrt [<=]52.4 | \[ {\left(\sqrt{\sqrt{\color{blue}{2} \cdot \left(x \cdot x\right)}}\right)}^{2}
\] |
Taylor expanded in x around 0 49.8%
Simplified99.2%
[Start]49.8 | \[ {\left(\sqrt{\sqrt{2} \cdot x}\right)}^{2}
\] |
|---|---|
*-commutative [<=]49.8 | \[ {\left(\sqrt{\color{blue}{x \cdot \sqrt{2}}}\right)}^{2}
\] |
rem-square-sqrt [<=]49.8 | \[ {\left(\sqrt{\color{blue}{\sqrt{x \cdot \sqrt{2}} \cdot \sqrt{x \cdot \sqrt{2}}}}\right)}^{2}
\] |
fabs-sqr [<=]49.8 | \[ {\left(\sqrt{\color{blue}{\left|\sqrt{x \cdot \sqrt{2}} \cdot \sqrt{x \cdot \sqrt{2}}\right|}}\right)}^{2}
\] |
rem-square-sqrt [=>]99.0 | \[ {\left(\sqrt{\left|\color{blue}{x \cdot \sqrt{2}}\right|}\right)}^{2}
\] |
rem-sqrt-square [<=]52.3 | \[ {\left(\sqrt{\color{blue}{\sqrt{\left(x \cdot \sqrt{2}\right) \cdot \left(x \cdot \sqrt{2}\right)}}}\right)}^{2}
\] |
swap-sqr [=>]52.2 | \[ {\left(\sqrt{\sqrt{\color{blue}{\left(x \cdot x\right) \cdot \left(\sqrt{2} \cdot \sqrt{2}\right)}}}\right)}^{2}
\] |
rem-square-sqrt [=>]52.4 | \[ {\left(\sqrt{\sqrt{\left(x \cdot x\right) \cdot \color{blue}{2}}}\right)}^{2}
\] |
*-commutative [<=]52.4 | \[ {\left(\sqrt{\sqrt{\color{blue}{2 \cdot \left(x \cdot x\right)}}}\right)}^{2}
\] |
unpow2 [<=]52.4 | \[ {\left(\sqrt{\sqrt{2 \cdot \color{blue}{{x}^{2}}}}\right)}^{2}
\] |
count-2 [<=]52.4 | \[ {\left(\sqrt{\sqrt{\color{blue}{{x}^{2} + {x}^{2}}}}\right)}^{2}
\] |
unpow2 [=>]52.4 | \[ {\left(\sqrt{\sqrt{\color{blue}{x \cdot x} + {x}^{2}}}\right)}^{2}
\] |
unpow2 [=>]52.4 | \[ {\left(\sqrt{\sqrt{x \cdot x + \color{blue}{x \cdot x}}}\right)}^{2}
\] |
hypot-def [=>]99.2 | \[ {\left(\sqrt{\color{blue}{\mathsf{hypot}\left(x, x\right)}}\right)}^{2}
\] |
Applied egg-rr54.4%
[Start]99.2 | \[ {\left(\sqrt{\mathsf{hypot}\left(x, x\right)}\right)}^{2}
\] |
|---|---|
unpow2 [=>]99.2 | \[ \color{blue}{\sqrt{\mathsf{hypot}\left(x, x\right)} \cdot \sqrt{\mathsf{hypot}\left(x, x\right)}}
\] |
add-sqr-sqrt [<=]100.0 | \[ \color{blue}{\mathsf{hypot}\left(x, x\right)}
\] |
expm1-log1p-u [=>]95.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{hypot}\left(x, x\right)\right)\right)}
\] |
expm1-udef [=>]50.0 | \[ \color{blue}{e^{\mathsf{log1p}\left(\mathsf{hypot}\left(x, x\right)\right)} - 1}
\] |
log1p-udef [=>]50.0 | \[ e^{\color{blue}{\log \left(1 + \mathsf{hypot}\left(x, x\right)\right)}} - 1
\] |
add-exp-log [<=]54.4 | \[ \color{blue}{\left(1 + \mathsf{hypot}\left(x, x\right)\right)} - 1
\] |
Simplified100.0%
[Start]54.4 | \[ \left(1 + \mathsf{hypot}\left(x, x\right)\right) - 1
\] |
|---|---|
+-commutative [=>]54.4 | \[ \color{blue}{\left(\mathsf{hypot}\left(x, x\right) + 1\right)} - 1
\] |
associate--l+ [=>]100.0 | \[ \color{blue}{\mathsf{hypot}\left(x, x\right) + \left(1 - 1\right)}
\] |
metadata-eval [=>]100.0 | \[ \mathsf{hypot}\left(x, x\right) + \color{blue}{0}
\] |
+-rgt-identity [=>]100.0 | \[ \color{blue}{\mathsf{hypot}\left(x, x\right)}
\] |
Final simplification100.0%
herbie shell --seed 2023135
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))