
(FPCore (x) :precision binary64 (sqrt (+ (pow x 2.0) (pow x 2.0))))
double code(double x) {
return sqrt((pow(x, 2.0) + pow(x, 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((x ** 2.0d0) + (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((Math.pow(x, 2.0) + Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((math.pow(x, 2.0) + math.pow(x, 2.0)))
function code(x) return sqrt(Float64((x ^ 2.0) + (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt(((x ^ 2.0) + (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{x}^{2} + {x}^{2}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (sqrt (+ (pow x 2.0) (pow x 2.0))))
double code(double x) {
return sqrt((pow(x, 2.0) + pow(x, 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt(((x ** 2.0d0) + (x ** 2.0d0)))
end function
public static double code(double x) {
return Math.sqrt((Math.pow(x, 2.0) + Math.pow(x, 2.0)));
}
def code(x): return math.sqrt((math.pow(x, 2.0) + math.pow(x, 2.0)))
function code(x) return sqrt(Float64((x ^ 2.0) + (x ^ 2.0))) end
function tmp = code(x) tmp = sqrt(((x ^ 2.0) + (x ^ 2.0))); end
code[x_] := N[Sqrt[N[(N[Power[x, 2.0], $MachinePrecision] + N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{{x}^{2} + {x}^{2}}
\end{array}
(FPCore (x) :precision binary64 (hypot x x))
double code(double x) {
return hypot(x, x);
}
public static double code(double x) {
return Math.hypot(x, x);
}
def code(x): return math.hypot(x, x)
function code(x) return hypot(x, x) end
function tmp = code(x) tmp = hypot(x, x); end
code[x_] := N[Sqrt[x ^ 2 + x ^ 2], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{hypot}\left(x, x\right)
\end{array}
Initial program 53.7%
unpow253.7%
unpow253.7%
hypot-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (if (<= x -5e-310) (- (- x) x) (+ x x)))
double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = -x - x;
} else {
tmp = x + x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-5d-310)) then
tmp = -x - x
else
tmp = x + x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= -5e-310) {
tmp = -x - x;
} else {
tmp = x + x;
}
return tmp;
}
def code(x): tmp = 0 if x <= -5e-310: tmp = -x - x else: tmp = x + x return tmp
function code(x) tmp = 0.0 if (x <= -5e-310) tmp = Float64(Float64(-x) - x); else tmp = Float64(x + x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= -5e-310) tmp = -x - x; else tmp = x + x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, -5e-310], N[((-x) - x), $MachinePrecision], N[(x + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\left(-x\right) - x\\
\mathbf{else}:\\
\;\;\;\;x + x\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 52.6%
unpow252.6%
unpow252.6%
hypot-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 99.3%
mul-1-neg99.3%
unpow1/299.3%
*-commutative99.3%
distribute-rgt-neg-in99.3%
unpow1/299.3%
Simplified99.3%
Applied egg-rr20.3%
if -4.999999999999985e-310 < x Initial program 55.2%
unpow255.2%
unpow255.2%
hypot-def99.9%
Simplified99.9%
Taylor expanded in x around -inf 2.3%
mul-1-neg2.3%
unpow1/22.3%
*-commutative2.3%
distribute-rgt-neg-in2.3%
unpow1/22.3%
Simplified2.3%
Applied egg-rr21.0%
Final simplification20.6%
(FPCore (x) :precision binary64 (+ x x))
double code(double x) {
return x + x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + x
end function
public static double code(double x) {
return x + x;
}
def code(x): return x + x
function code(x) return Float64(x + x) end
function tmp = code(x) tmp = x + x; end
code[x_] := N[(x + x), $MachinePrecision]
\begin{array}{l}
\\
x + x
\end{array}
Initial program 53.7%
unpow253.7%
unpow253.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 58.4%
mul-1-neg58.4%
unpow1/258.4%
*-commutative58.4%
distribute-rgt-neg-in58.4%
unpow1/258.4%
Simplified58.4%
Applied egg-rr10.1%
Final simplification10.1%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 53.7%
unpow253.7%
unpow253.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 58.4%
mul-1-neg58.4%
unpow1/258.4%
*-commutative58.4%
distribute-rgt-neg-in58.4%
unpow1/258.4%
Simplified58.4%
Applied egg-rr10.1%
Simplified3.8%
Final simplification3.8%
(FPCore (x) :precision binary64 x)
double code(double x) {
return x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x
end function
public static double code(double x) {
return x;
}
def code(x): return x
function code(x) return x end
function tmp = code(x) tmp = x; end
code[x_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 53.7%
unpow253.7%
unpow253.7%
hypot-def100.0%
Simplified100.0%
Taylor expanded in x around -inf 58.4%
mul-1-neg58.4%
unpow1/258.4%
*-commutative58.4%
distribute-rgt-neg-in58.4%
unpow1/258.4%
Simplified58.4%
Applied egg-rr10.1%
Simplified9.8%
Final simplification9.8%
herbie shell --seed 2023193
(FPCore (x)
:name "sqrt E (should all be same)"
:precision binary64
(sqrt (+ (pow x 2.0) (pow x 2.0))))