
(FPCore (x) :precision binary64 (* (sqrt (- x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x - 1.0)) * sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x - 1.0d0)) * sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x - 1.0)) * Math.sqrt(x);
}
def code(x): return math.sqrt((x - 1.0)) * math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x - 1.0)) * sqrt(x)) end
function tmp = code(x) tmp = sqrt((x - 1.0)) * sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x - 1} \cdot \sqrt{x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (sqrt (- x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x - 1.0)) * sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x - 1.0d0)) * sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x - 1.0)) * Math.sqrt(x);
}
def code(x): return math.sqrt((x - 1.0)) * math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x - 1.0)) * sqrt(x)) end
function tmp = code(x) tmp = sqrt((x - 1.0)) * sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x - 1} \cdot \sqrt{x}
\end{array}
(FPCore (x) :precision binary64 (if (<= x 1e+15) (sqrt (* (- x 1.0) x)) x))
double code(double x) {
double tmp;
if (x <= 1e+15) {
tmp = sqrt(((x - 1.0) * x));
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1d+15) then
tmp = sqrt(((x - 1.0d0) * x))
else
tmp = x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1e+15) {
tmp = Math.sqrt(((x - 1.0) * x));
} else {
tmp = x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1e+15: tmp = math.sqrt(((x - 1.0) * x)) else: tmp = x return tmp
function code(x) tmp = 0.0 if (x <= 1e+15) tmp = sqrt(Float64(Float64(x - 1.0) * x)); else tmp = x; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1e+15) tmp = sqrt(((x - 1.0) * x)); else tmp = x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1e+15], N[Sqrt[N[(N[(x - 1.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{+15}:\\
\;\;\;\;\sqrt{\left(x - 1\right) \cdot x}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < 1e15Initial program 99.6%
lift--.f64N/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
rem-exp-logN/A
lower-expm1.f64N/A
lower-log.f6499.2
Applied rewrites99.2%
lift-*.f64N/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
sqrt-unprodN/A
lower-sqrt.f64N/A
lower-*.f6499.1
lift-expm1.f64N/A
lift-log.f64N/A
rem-exp-logN/A
lower--.f64100.0
Applied rewrites100.0%
if 1e15 < x Initial program 99.2%
Taylor expanded in x around -inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identity100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (* (sqrt (- x 1.0)) (sqrt x)))
double code(double x) {
return sqrt((x - 1.0)) * sqrt(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = sqrt((x - 1.0d0)) * sqrt(x)
end function
public static double code(double x) {
return Math.sqrt((x - 1.0)) * Math.sqrt(x);
}
def code(x): return math.sqrt((x - 1.0)) * math.sqrt(x)
function code(x) return Float64(sqrt(Float64(x - 1.0)) * sqrt(x)) end
function tmp = code(x) tmp = sqrt((x - 1.0)) * sqrt(x); end
code[x_] := N[(N[Sqrt[N[(x - 1.0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{x - 1} \cdot \sqrt{x}
\end{array}
Initial program 99.2%
(FPCore (x) :precision binary64 (- x 0.5))
double code(double x) {
return x - 0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = x - 0.5d0
end function
public static double code(double x) {
return x - 0.5;
}
def code(x): return x - 0.5
function code(x) return Float64(x - 0.5) end
function tmp = code(x) tmp = x - 0.5; end
code[x_] := N[(x - 0.5), $MachinePrecision]
\begin{array}{l}
\\
x - 0.5
\end{array}
Initial program 99.2%
Taylor expanded in x around inf
fp-cancel-sub-sign-invN/A
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f64N/A
metadata-evalN/A
associate-*r/N/A
metadata-evalN/A
lower-/.f6498.3
Applied rewrites98.3%
Applied rewrites98.3%
(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 99.2%
Taylor expanded in x around -inf
*-commutativeN/A
unpow2N/A
rem-square-sqrtN/A
associate-*r*N/A
metadata-evalN/A
*-lft-identity97.9
Applied rewrites97.9%
herbie shell --seed 2024343
(FPCore (x)
:name "sqrt times"
:precision binary64
(* (sqrt (- x 1.0)) (sqrt x)))