| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6528 |
\[\mathsf{hypot}\left(x, x\right)
\]

(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)
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
Initial program 50.2%
Applied egg-rr46.2%
[Start]50.2% | \[ \sqrt{\left(2 \cdot x\right) \cdot x}
\] |
|---|---|
sqrt-prod [=>]46.2% | \[ \color{blue}{\sqrt{2 \cdot x} \cdot \sqrt{x}}
\] |
Taylor expanded in x around 0 47.4%
Simplified100.0%
[Start]47.4% | \[ \sqrt{2} \cdot x
\] |
|---|---|
rem-square-sqrt [<=]45.9% | \[ \color{blue}{\sqrt{\sqrt{2} \cdot x} \cdot \sqrt{\sqrt{2} \cdot x}}
\] |
fabs-sqr [<=]45.9% | \[ \color{blue}{\left|\sqrt{\sqrt{2} \cdot x} \cdot \sqrt{\sqrt{2} \cdot x}\right|}
\] |
rem-square-sqrt [=>]99.3% | \[ \left|\color{blue}{\sqrt{2} \cdot x}\right|
\] |
rem-sqrt-square [<=]50.0% | \[ \color{blue}{\sqrt{\left(\sqrt{2} \cdot x\right) \cdot \left(\sqrt{2} \cdot x\right)}}
\] |
swap-sqr [=>]49.8% | \[ \sqrt{\color{blue}{\left(\sqrt{2} \cdot \sqrt{2}\right) \cdot \left(x \cdot x\right)}}
\] |
rem-square-sqrt [=>]50.2% | \[ \sqrt{\color{blue}{2} \cdot \left(x \cdot x\right)}
\] |
count-2 [<=]50.2% | \[ \sqrt{\color{blue}{x \cdot x + x \cdot x}}
\] |
hypot-def [=>]100.0% | \[ \color{blue}{\mathsf{hypot}\left(x, x\right)}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6528 |
| Alternative 2 | |
|---|---|
| Accuracy | 13.6% |
| Cost | 452 |
| Alternative 3 | |
|---|---|
| Accuracy | 6.4% |
| Cost | 192 |
| Alternative 4 | |
|---|---|
| Accuracy | 11.2% |
| Cost | 192 |
| Alternative 5 | |
|---|---|
| Accuracy | 1.7% |
| Cost | 64 |
herbie shell --seed 2023256
(FPCore (x)
:name "sqrt B (should all be same)"
:precision binary64
(sqrt (* (* 2.0 x) x)))