
(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 4 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 60.4%
unpow260.4%
unpow260.4%
hypot-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (+ x -2.0))
double code(double x) {
return x + -2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (-2.0d0)
end function
public static double code(double x) {
return x + -2.0;
}
def code(x): return x + -2.0
function code(x) return Float64(x + -2.0) end
function tmp = code(x) tmp = x + -2.0; end
code[x_] := N[(x + -2.0), $MachinePrecision]
\begin{array}{l}
\\
x + -2
\end{array}
Initial program 60.4%
unpow260.4%
unpow260.4%
hypot-def100.0%
Simplified100.0%
add-cube-cbrt97.8%
pow397.8%
Applied egg-rr97.8%
unpow397.8%
add-cube-cbrt100.0%
hypot-udef60.4%
count-260.4%
add-sqr-sqrt59.9%
swap-sqr60.1%
*-commutative60.1%
*-commutative60.1%
sqrt-unprod52.6%
add-sqr-sqrt53.8%
*-commutative53.8%
add-sqr-sqrt53.7%
associate-*l*53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
Applied egg-rr53.8%
associate-*r*53.7%
add-sqr-sqrt52.5%
associate-*r*52.6%
pow-prod-up52.7%
metadata-eval52.7%
pow1/252.7%
sqrt-prod52.9%
count-252.9%
sqrt-prod60.4%
*-commutative60.4%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
distribute-lft-out--0.0%
Applied egg-rr11.8%
Simplified6.7%
Final simplification6.7%
(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 60.4%
unpow260.4%
unpow260.4%
hypot-def100.0%
Simplified100.0%
add-cube-cbrt97.8%
pow397.8%
Applied egg-rr97.8%
unpow397.8%
add-cube-cbrt100.0%
hypot-udef60.4%
count-260.4%
add-sqr-sqrt59.9%
swap-sqr60.1%
*-commutative60.1%
*-commutative60.1%
sqrt-unprod52.6%
add-sqr-sqrt53.8%
*-commutative53.8%
add-sqr-sqrt53.7%
associate-*l*53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
Applied egg-rr53.8%
associate-*r*53.7%
add-sqr-sqrt52.5%
associate-*r*52.6%
pow-prod-up52.7%
metadata-eval52.7%
pow1/252.7%
sqrt-prod52.9%
count-252.9%
sqrt-prod60.4%
*-commutative60.4%
flip-+0.0%
+-inverses0.0%
+-inverses0.0%
associate-*r/0.0%
distribute-lft-out--0.0%
Applied egg-rr11.8%
Final simplification11.8%
(FPCore (x) :precision binary64 -2.0)
double code(double x) {
return -2.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = -2.0d0
end function
public static double code(double x) {
return -2.0;
}
def code(x): return -2.0
function code(x) return -2.0 end
function tmp = code(x) tmp = -2.0; end
code[x_] := -2.0
\begin{array}{l}
\\
-2
\end{array}
Initial program 60.4%
unpow260.4%
unpow260.4%
hypot-def100.0%
Simplified100.0%
add-cube-cbrt97.8%
pow397.8%
Applied egg-rr97.8%
unpow397.8%
add-cube-cbrt100.0%
hypot-udef60.4%
count-260.4%
add-sqr-sqrt59.9%
swap-sqr60.1%
*-commutative60.1%
*-commutative60.1%
sqrt-unprod52.6%
add-sqr-sqrt53.8%
*-commutative53.8%
add-sqr-sqrt53.7%
associate-*l*53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
pow1/253.8%
sqrt-pow153.8%
metadata-eval53.8%
Applied egg-rr53.8%
Taylor expanded in x around 0 53.8%
Simplified1.6%
Final simplification1.6%
herbie shell --seed 2023293
(FPCore (x)
:name "sqrt E (should all be same)"
:precision binary64
(sqrt (+ (pow x 2.0) (pow x 2.0))))