
(FPCore (x) :precision binary64 (/ 1.0 (* x x)))
double code(double x) {
return 1.0 / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * x)
end function
public static double code(double x) {
return 1.0 / (x * x);
}
def code(x): return 1.0 / (x * x)
function code(x) return Float64(1.0 / Float64(x * x)) end
function tmp = code(x) tmp = 1.0 / (x * x); end
code[x_] := N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot x}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (/ 1.0 (* x x)))
double code(double x) {
return 1.0 / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * x)
end function
public static double code(double x) {
return 1.0 / (x * x);
}
def code(x): return 1.0 / (x * x)
function code(x) return Float64(1.0 / Float64(x * x)) end
function tmp = code(x) tmp = 1.0 / (x * x); end
code[x_] := N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot x}
\end{array}
(FPCore (x) :precision binary64 (pow x -2.0))
double code(double x) {
return pow(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 Math.pow(x, -2.0);
}
def code(x): return math.pow(x, -2.0)
function code(x) return x ^ -2.0 end
function tmp = code(x) tmp = x ^ -2.0; end
code[x_] := N[Power[x, -2.0], $MachinePrecision]
\begin{array}{l}
\\
{x}^{-2}
\end{array}
Initial program 99.7%
pow299.7%
pow-flip100.0%
metadata-eval100.0%
Applied egg-rr100.0%
(FPCore (x) :precision binary64 (/ 1.0 (* x x)))
double code(double x) {
return 1.0 / (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x * x)
end function
public static double code(double x) {
return 1.0 / (x * x);
}
def code(x): return 1.0 / (x * x)
function code(x) return Float64(1.0 / Float64(x * x)) end
function tmp = code(x) tmp = 1.0 / (x * x); end
code[x_] := N[(1.0 / N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x \cdot x}
\end{array}
Initial program 99.7%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 99.7%
add-sqr-sqrt99.5%
sqrt-div99.6%
metadata-eval99.6%
sqrt-prod46.6%
add-sqr-sqrt60.6%
frac-2neg60.6%
metadata-eval60.6%
associate-/r*60.5%
metadata-eval60.5%
add-sqr-sqrt46.7%
sqrt-prod59.9%
sqrt-div59.9%
sqrt-div46.7%
frac-times46.7%
Applied egg-rr21.0%
times-frac3.3%
neg-mul-13.3%
associate-/r*3.3%
metadata-eval3.3%
*-inverses4.8%
*-rgt-identity4.8%
Simplified4.8%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.7%
Applied egg-rr3.5%
times-frac3.5%
unpow1/33.5%
unpow23.5%
exp-to-pow1.6%
*-commutative1.6%
exp-prod2.0%
associate-*r*2.0%
*-commutative2.0%
*-commutative2.0%
exp-lft-sqr2.0%
unpow1/32.0%
exp-to-pow2.0%
*-commutative2.0%
unpow32.0%
exp-prod2.0%
*-commutative2.0%
associate-*l*2.0%
metadata-eval2.0%
exp-to-pow4.3%
unpow14.3%
*-rgt-identity4.3%
Simplified4.3%
(FPCore (x) :precision binary64 (/ (/ 1.0 x) x))
double code(double x) {
return (1.0 / x) / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / x) / x
end function
public static double code(double x) {
return (1.0 / x) / x;
}
def code(x): return (1.0 / x) / x
function code(x) return Float64(Float64(1.0 / x) / x) end
function tmp = code(x) tmp = (1.0 / x) / x; end
code[x_] := N[(N[(1.0 / x), $MachinePrecision] / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1}{x}}{x}
\end{array}
herbie shell --seed 2024097
(FPCore (x)
:name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, A"
:precision binary64
:alt
(/ (/ 1.0 x) x)
(/ 1.0 (* x x)))