?

Average Error: 25.6 → 0.0
Time: 15.1s
Precision: binary64
Cost: 6784

?

$\left(\left(\left(-1.79 \cdot 10^{+308} \leq px \land px \leq 1.79 \cdot 10^{+308}\right) \land \left(-1.79 \cdot 10^{+308} \leq qx \land qx \leq 1.79 \cdot 10^{+308}\right)\right) \land \left(-1.79 \cdot 10^{+308} \leq py \land py \leq 1.79 \cdot 10^{+308}\right)\right) \land \left(-1.79 \cdot 10^{+308} \leq qy \land qy \leq 1.79 \cdot 10^{+308}\right)$
$\sqrt{{\left(\frac{px}{qx}\right)}^{2} + {\left(\frac{py}{qy}\right)}^{2}}$
$\mathsf{hypot}\left(\frac{px}{qx}, \frac{py}{qy}\right)$
(FPCore (px qx py qy)
:precision binary64
(sqrt (+ (pow (/ px qx) 2.0) (pow (/ py qy) 2.0))))
(FPCore (px qx py qy) :precision binary64 (hypot (/ px qx) (/ py qy)))
double code(double px, double qx, double py, double qy) {
return sqrt((pow((px / qx), 2.0) + pow((py / qy), 2.0)));
}

double code(double px, double qx, double py, double qy) {
return hypot((px / qx), (py / qy));
}

public static double code(double px, double qx, double py, double qy) {
return Math.sqrt((Math.pow((px / qx), 2.0) + Math.pow((py / qy), 2.0)));
}

public static double code(double px, double qx, double py, double qy) {
return Math.hypot((px / qx), (py / qy));
}

def code(px, qx, py, qy):
return math.sqrt((math.pow((px / qx), 2.0) + math.pow((py / qy), 2.0)))

def code(px, qx, py, qy):
return math.hypot((px / qx), (py / qy))

function code(px, qx, py, qy)
return sqrt(Float64((Float64(px / qx) ^ 2.0) + (Float64(py / qy) ^ 2.0)))
end

function code(px, qx, py, qy)
return hypot(Float64(px / qx), Float64(py / qy))
end

function tmp = code(px, qx, py, qy)
tmp = sqrt((((px / qx) ^ 2.0) + ((py / qy) ^ 2.0)));
end

function tmp = code(px, qx, py, qy)
tmp = hypot((px / qx), (py / qy));
end

code[px_, qx_, py_, qy_] := N[Sqrt[N[(N[Power[N[(px / qx), $MachinePrecision], 2.0],$MachinePrecision] + N[Power[N[(py / qy), $MachinePrecision], 2.0],$MachinePrecision]), $MachinePrecision]],$MachinePrecision]

code[px_, qx_, py_, qy_] := N[Sqrt[N[(px / qx), $MachinePrecision] ^ 2 + N[(py / qy),$MachinePrecision] ^ 2], \$MachinePrecision]

\sqrt{{\left(\frac{px}{qx}\right)}^{2} + {\left(\frac{py}{qy}\right)}^{2}}

\mathsf{hypot}\left(\frac{px}{qx}, \frac{py}{qy}\right)


Try it out?

Results

 In Out
Enter valid numbers for all inputs

Derivation?

1. Initial program 25.6

$\sqrt{{\left(\frac{px}{qx}\right)}^{2} + {\left(\frac{py}{qy}\right)}^{2}}$
2. Simplified0.0

$\leadsto \color{blue}{\mathsf{hypot}\left(\frac{px}{qx}, \frac{py}{qy}\right)}$
Proof
[Start]25.6 $\sqrt{{\left(\frac{px}{qx}\right)}^{2} + {\left(\frac{py}{qy}\right)}^{2}}$ $\sqrt{\color{blue}{\frac{px}{qx} \cdot \frac{px}{qx}} + {\left(\frac{py}{qy}\right)}^{2}}$ $\sqrt{\frac{px}{qx} \cdot \frac{px}{qx} + \color{blue}{\frac{py}{qy} \cdot \frac{py}{qy}}}$ $\color{blue}{\mathsf{hypot}\left(\frac{px}{qx}, \frac{py}{qy}\right)}$
3. Final simplification0.0

$\leadsto \mathsf{hypot}\left(\frac{px}{qx}, \frac{py}{qy}\right)$

Alternatives

Alternative 1
Error25.6
Cost712
$\begin{array}{l} \mathbf{if}\;\frac{px}{qx} \leq -1 \cdot 10^{-105}:\\ \;\;\;\;\frac{-px}{qx}\\ \mathbf{elif}\;\frac{px}{qx} \leq 2 \cdot 10^{-99}:\\ \;\;\;\;\frac{py}{qy}\\ \mathbf{else}:\\ \;\;\;\;\frac{px}{qx}\\ \end{array}$
Alternative 2
Error24.5
Cost712
$\begin{array}{l} \mathbf{if}\;\frac{py}{qy} \leq -2 \cdot 10^{-115}:\\ \;\;\;\;\frac{-py}{qy}\\ \mathbf{elif}\;\frac{py}{qy} \leq 5 \cdot 10^{-139}:\\ \;\;\;\;\frac{px}{qx}\\ \mathbf{else}:\\ \;\;\;\;\frac{py}{qy}\\ \end{array}$
Alternative 3
Error35.4
Cost452
$\begin{array}{l} \mathbf{if}\;\frac{py}{qy} \leq 1.7 \cdot 10^{-136}:\\ \;\;\;\;\frac{px}{qx}\\ \mathbf{else}:\\ \;\;\;\;\frac{py}{qy}\\ \end{array}$
Alternative 4
Error46.4
Cost192
$\frac{px}{qx}$

Reproduce?

herbie shell --seed 1
(FPCore (px qx py qy)
:name "sqrt((px/qx)^2 + (py/qy)^2)"
:precision binary64
:pre (and (and (and (and (<= -1.79e+308 px) (<= px 1.79e+308)) (and (<= -1.79e+308 qx) (<= qx 1.79e+308))) (and (<= -1.79e+308 py) (<= py 1.79e+308))) (and (<= -1.79e+308 qy) (<= qy 1.79e+308)))
(sqrt (+ (pow (/ px qx) 2.0) (pow (/ py qy) 2.0))))