
(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 3 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 (+ (+ x (/ -0.125 x)) -0.5))
double code(double x) {
return (x + (-0.125 / x)) + -0.5;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (x + ((-0.125d0) / x)) + (-0.5d0)
end function
public static double code(double x) {
return (x + (-0.125 / x)) + -0.5;
}
def code(x): return (x + (-0.125 / x)) + -0.5
function code(x) return Float64(Float64(x + Float64(-0.125 / x)) + -0.5) end
function tmp = code(x) tmp = (x + (-0.125 / x)) + -0.5; end
code[x_] := N[(N[(x + N[(-0.125 / x), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]
\begin{array}{l}
\\
\left(x + \frac{-0.125}{x}\right) + -0.5
\end{array}
Initial program 99.2%
expm1-log1p-u90.9%
expm1-udef90.9%
log1p-udef90.9%
rem-exp-log99.2%
*-commutative99.2%
sqrt-unprod50.9%
sub-neg50.9%
metadata-eval50.9%
Applied egg-rr50.9%
Taylor expanded in x around inf 99.4%
associate-*r/99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around 0 99.4%
associate-*r/99.4%
metadata-eval99.4%
metadata-eval99.4%
associate-+r+99.4%
+-commutative99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-frac99.4%
metadata-eval99.4%
+-commutative99.4%
associate-+l+99.4%
metadata-eval99.4%
Simplified99.4%
associate-+r+99.4%
+-commutative99.4%
associate--l+99.4%
metadata-eval99.4%
Applied egg-rr99.4%
Final simplification99.4%
(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 99.1%
Final simplification99.1%
(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 98.2%
Final simplification98.2%
herbie shell --seed 2023334
(FPCore (x)
:name "sqrt times"
:precision binary64
(* (sqrt (- x 1.0)) (sqrt x)))