
(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 7 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 78000.0) (sqrt (* x (+ x -1.0))) (- (+ x -0.5) (/ 0.125 x))))
double code(double x) {
double tmp;
if (x <= 78000.0) {
tmp = sqrt((x * (x + -1.0)));
} else {
tmp = (x + -0.5) - (0.125 / x);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 78000.0d0) then
tmp = sqrt((x * (x + (-1.0d0))))
else
tmp = (x + (-0.5d0)) - (0.125d0 / x)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 78000.0) {
tmp = Math.sqrt((x * (x + -1.0)));
} else {
tmp = (x + -0.5) - (0.125 / x);
}
return tmp;
}
def code(x): tmp = 0 if x <= 78000.0: tmp = math.sqrt((x * (x + -1.0))) else: tmp = (x + -0.5) - (0.125 / x) return tmp
function code(x) tmp = 0.0 if (x <= 78000.0) tmp = sqrt(Float64(x * Float64(x + -1.0))); else tmp = Float64(Float64(x + -0.5) - Float64(0.125 / x)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 78000.0) tmp = sqrt((x * (x + -1.0))); else tmp = (x + -0.5) - (0.125 / x); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 78000.0], N[Sqrt[N[(x * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[(N[(x + -0.5), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 78000:\\
\;\;\;\;\sqrt{x \cdot \left(x + -1\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(x + -0.5\right) - \frac{0.125}{x}\\
\end{array}
\end{array}
if x < 78000Initial program 99.6%
*-commutative99.6%
sqrt-unprod99.8%
sub-neg99.8%
metadata-eval99.8%
Applied egg-rr99.8%
if 78000 < x Initial program 99.2%
Taylor expanded in x around inf 100.0%
associate--r+100.0%
sub-neg100.0%
metadata-eval100.0%
associate-*r/100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.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%
Final simplification99.2%
(FPCore (x) :precision binary64 (+ x (- (/ -0.125 x) (+ (/ 0.0625 (* x x)) 0.5))))
double code(double x) {
return x + ((-0.125 / x) - ((0.0625 / (x * x)) + 0.5));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x + (((-0.125d0) / x) - ((0.0625d0 / (x * x)) + 0.5d0))
end function
public static double code(double x) {
return x + ((-0.125 / x) - ((0.0625 / (x * x)) + 0.5));
}
def code(x): return x + ((-0.125 / x) - ((0.0625 / (x * x)) + 0.5))
function code(x) return Float64(x + Float64(Float64(-0.125 / x) - Float64(Float64(0.0625 / Float64(x * x)) + 0.5))) end
function tmp = code(x) tmp = x + ((-0.125 / x) - ((0.0625 / (x * x)) + 0.5)); end
code[x_] := N[(x + N[(N[(-0.125 / x), $MachinePrecision] - N[(N[(0.0625 / N[(x * x), $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(\frac{-0.125}{x} - \left(\frac{0.0625}{x \cdot x} + 0.5\right)\right)
\end{array}
Initial program 99.2%
Taylor expanded in x around inf 98.2%
sub-neg98.2%
neg-sub098.2%
associate-+r+98.2%
+-commutative98.2%
associate--r+98.2%
neg-sub098.2%
associate-*r/98.2%
metadata-eval98.2%
distribute-neg-frac98.2%
metadata-eval98.2%
associate-*r/98.2%
metadata-eval98.2%
unpow298.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (- (+ x -0.5) (+ (/ 0.125 x) (/ 0.0625 (* x x)))))
double code(double x) {
return (x + -0.5) - ((0.125 / x) + (0.0625 / (x * x)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (-0.5d0)) - ((0.125d0 / x) + (0.0625d0 / (x * x)))
end function
public static double code(double x) {
return (x + -0.5) - ((0.125 / x) + (0.0625 / (x * x)));
}
def code(x): return (x + -0.5) - ((0.125 / x) + (0.0625 / (x * x)))
function code(x) return Float64(Float64(x + -0.5) - Float64(Float64(0.125 / x) + Float64(0.0625 / Float64(x * x)))) end
function tmp = code(x) tmp = (x + -0.5) - ((0.125 / x) + (0.0625 / (x * x))); end
code[x_] := N[(N[(x + -0.5), $MachinePrecision] - N[(N[(0.125 / x), $MachinePrecision] + N[(0.0625 / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + -0.5\right) - \left(\frac{0.125}{x} + \frac{0.0625}{x \cdot x}\right)
\end{array}
Initial program 99.2%
Taylor expanded in x around inf 98.2%
associate--r+98.2%
sub-neg98.2%
metadata-eval98.2%
+-commutative98.2%
associate-*r/98.2%
metadata-eval98.2%
associate-*r/98.2%
metadata-eval98.2%
unpow298.2%
Simplified98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (- (+ x -0.5) (/ 0.125 x)))
double code(double x) {
return (x + -0.5) - (0.125 / x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + (-0.5d0)) - (0.125d0 / x)
end function
public static double code(double x) {
return (x + -0.5) - (0.125 / x);
}
def code(x): return (x + -0.5) - (0.125 / x)
function code(x) return Float64(Float64(x + -0.5) - Float64(0.125 / x)) end
function tmp = code(x) tmp = (x + -0.5) - (0.125 / x); end
code[x_] := N[(N[(x + -0.5), $MachinePrecision] - N[(0.125 / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + -0.5\right) - \frac{0.125}{x}
\end{array}
Initial program 99.2%
Taylor expanded in x around inf 98.0%
associate--r+98.0%
sub-neg98.0%
metadata-eval98.0%
associate-*r/98.0%
metadata-eval98.0%
Simplified98.0%
Final simplification98.0%
(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 97.7%
Final simplification97.7%
(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 97.0%
Final simplification97.0%
herbie shell --seed 2023283
(FPCore (x)
:name "sqrt times"
:precision binary64
(* (sqrt (- x 1.0)) (sqrt x)))