Alternative 1 | |
---|---|
Error | 30.3 |
Cost | 576 |
\[y + 0.5 \cdot \left(x \cdot \frac{x}{y}\right)
\]
(FPCore (x y) :precision binary64 (sqrt (+ (pow x 2.0) (pow y 2.0))))
(FPCore (x y) :precision binary64 (hypot x y))
double code(double x, double y) { return sqrt((pow(x, 2.0) + pow(y, 2.0))); }
double code(double x, double y) { return hypot(x, y); }
public static double code(double x, double y) { return Math.sqrt((Math.pow(x, 2.0) + Math.pow(y, 2.0))); }
public static double code(double x, double y) { return Math.hypot(x, y); }
def code(x, y): return math.sqrt((math.pow(x, 2.0) + math.pow(y, 2.0)))
def code(x, y): return math.hypot(x, y)
function code(x, y) return sqrt(Float64((x ^ 2.0) + (y ^ 2.0))) end
function code(x, y) return hypot(x, y) end
function tmp = code(x, y) tmp = sqrt(((x ^ 2.0) + (y ^ 2.0))); end
function tmp = code(x, y) tmp = hypot(x, y); end
code[x_, y_] := N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_, y_] := N[Sqrt[x ^ 2 + y ^ 2], $MachinePrecision]
\sqrt{{x}^{2} + {y}^{2}}
\mathsf{hypot}\left(x, y\right)
Results
Initial program 12.7
Simplified0.0
[Start]12.7 | \[ \sqrt{{x}^{2} + {y}^{2}}
\] |
---|---|
unpow2 [=>]12.7 | \[ \sqrt{\color{blue}{x \cdot x} + {y}^{2}}
\] |
unpow2 [=>]12.7 | \[ \sqrt{x \cdot x + \color{blue}{y \cdot y}}
\] |
hypot-def [=>]0.0 | \[ \color{blue}{\mathsf{hypot}\left(x, y\right)}
\] |
Final simplification0.0
Alternative 1 | |
---|---|
Error | 30.3 |
Cost | 576 |
Alternative 2 | |
---|---|
Error | 30.6 |
Cost | 64 |
herbie shell --seed 1
(FPCore (x y)
:name "sqrt(x^2+y^2)"
:precision binary64
:pre (and (and (<= 0.0 x) (<= x 1e+18)) (and (<= 0.0 y) (<= y 1e+18)))
(sqrt (+ (pow x 2.0) (pow y 2.0))))