
(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 3 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 52.5%
unpow2N/A
unpow2N/A
accelerator-lowering-hypot.f64100.0
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (fma x (sqrt 2.0) 0.0))
double code(double x) {
return fma(x, sqrt(2.0), 0.0);
}
function code(x) return fma(x, sqrt(2.0), 0.0) end
code[x_] := N[(x * N[Sqrt[2.0], $MachinePrecision] + 0.0), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sqrt{2}, 0\right)
\end{array}
Initial program 52.5%
Taylor expanded in x around 0
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
sqrt-lowering-sqrt.f6446.4
Simplified46.4%
(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 52.5%
unpow2N/A
unpow2N/A
distribute-lft-outN/A
*-lowering-*.f64N/A
+-lowering-+.f6452.6
Applied egg-rr52.6%
distribute-lft-inN/A
pow1/2N/A
flip-+N/A
+-inversesN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
+-inversesN/A
metadata-evalN/A
flip-+N/A
metadata-evalN/A
metadata-eval3.6
Applied egg-rr3.6%
herbie shell --seed 2024198
(FPCore (x)
:name "sqrt E (should all be same)"
:precision binary64
(sqrt (+ (pow x 2.0) (pow x 2.0))))