
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
double code(double x, double y) {
return ((x * x) + y) + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
def code(x, y): return ((x * x) + y) + y
function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
function tmp = code(x, y) tmp = ((x * x) + y) + y; end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + y\right) + y
\end{array}
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (+ (+ (* x x) y) y))
x = abs(x);
double code(double x, double y) {
return ((x * x) + y) + y;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + y) + y
end function
x = Math.abs(x);
public static double code(double x, double y) {
return ((x * x) + y) + y;
}
x = abs(x) def code(x, y): return ((x * x) + y) + y
x = abs(x) function code(x, y) return Float64(Float64(Float64(x * x) + y) + y) end
x = abs(x) function tmp = code(x, y) tmp = ((x * x) + y) + y; end
NOTE: x should be positive before calling this function code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + y), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\left(x \cdot x + y\right) + y
\end{array}
Initial program 100.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (+ y (fma x x y)))
x = abs(x);
double code(double x, double y) {
return y + fma(x, x, y);
}
x = abs(x) function code(x, y) return Float64(y + fma(x, x, y)) end
NOTE: x should be positive before calling this function code[x_, y_] := N[(y + N[(x * x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
y + \mathsf{fma}\left(x, x, y\right)
\end{array}
Initial program 100.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (fma x x (+ y y)))
x = abs(x);
double code(double x, double y) {
return fma(x, x, (y + y));
}
x = abs(x) function code(x, y) return fma(x, x, Float64(y + y)) end
NOTE: x should be positive before calling this function code[x_, y_] := N[(x * x + N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\mathsf{fma}\left(x, x, y + y\right)
\end{array}
Initial program 100.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (fma 2.0 y (* x x)))
x = abs(x);
double code(double x, double y) {
return fma(2.0, y, (x * x));
}
x = abs(x) function code(x, y) return fma(2.0, y, Float64(x * x)) end
NOTE: x should be positive before calling this function code[x_, y_] := N[(2.0 * y + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\mathsf{fma}\left(2, y, x \cdot x\right)
\end{array}
Initial program 100.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (fma y 2.0 (* x x)))
x = abs(x);
double code(double x, double y) {
return fma(y, 2.0, (x * x));
}
x = abs(x) function code(x, y) return fma(y, 2.0, Float64(x * x)) end
NOTE: x should be positive before calling this function code[x_, y_] := N[(y * 2.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
\mathsf{fma}\left(y, 2, x \cdot x\right)
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (+ (+ y y) (* x x)))
double code(double x, double y) {
return (y + y) + (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + y) + (x * x)
end function
public static double code(double x, double y) {
return (y + y) + (x * x);
}
def code(x, y): return (y + y) + (x * x)
function code(x, y) return Float64(Float64(y + y) + Float64(x * x)) end
function tmp = code(x, y) tmp = (y + y) + (x * x); end
code[x_, y_] := N[(N[(y + y), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y\right) + x \cdot x
\end{array}
herbie shell --seed 2023276
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalTail from random-fu-0.2.6.2"
:precision binary64
:herbie-target
(+ (+ y y) (* x x))
(+ (+ (* x x) y) y))