
(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 5 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.1%
Taylor expanded in x around 0 99.1%
unpow299.1%
rem-exp-log95.2%
log-rec95.2%
unpow295.2%
log-pow49.5%
*-commutative49.5%
distribute-rgt-neg-in49.5%
exp-to-pow100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification100.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.1%
Final simplification99.1%
(FPCore (x) :precision binary64 (if (<= x 1.6e+77) 0.125 0.0))
double code(double x) {
double tmp;
if (x <= 1.6e+77) {
tmp = 0.125;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.6d+77) then
tmp = 0.125d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.6e+77) {
tmp = 0.125;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.6e+77: tmp = 0.125 else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.6e+77) tmp = 0.125; else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.6e+77) tmp = 0.125; else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.6e+77], 0.125, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.6 \cdot 10^{+77}:\\
\;\;\;\;0.125\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.6000000000000001e77Initial program 99.3%
Applied egg-rr4.6%
if 1.6000000000000001e77 < x Initial program 98.6%
Applied egg-rr70.3%
Final simplification18.0%
(FPCore (x) :precision binary64 (if (<= x 1.2e+77) 0.5 0.0))
double code(double x) {
double tmp;
if (x <= 1.2e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.2d+77) then
tmp = 0.5d0
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.2e+77) {
tmp = 0.5;
} else {
tmp = 0.0;
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.2e+77: tmp = 0.5 else: tmp = 0.0 return tmp
function code(x) tmp = 0.0 if (x <= 1.2e+77) tmp = 0.5; else tmp = 0.0; end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.2e+77) tmp = 0.5; else tmp = 0.0; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.2e+77], 0.5, 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.2 \cdot 10^{+77}:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if x < 1.1999999999999999e77Initial program 99.3%
Applied egg-rr4.7%
if 1.1999999999999999e77 < x Initial program 98.6%
Applied egg-rr70.3%
Final simplification18.0%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 99.1%
Applied egg-rr28.9%
Final simplification28.9%
(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 2023297
(FPCore (x)
:name "Numeric.SpecFunctions:$slogFactorial from math-functions-0.1.5.2, A"
:precision binary64
:herbie-target
(/ (/ 1.0 x) x)
(/ 1.0 (* x x)))