
(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 4 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}
(FPCore (x y) :precision binary64 (fma x x (+ y y)))
double code(double x, double y) {
return fma(x, x, (y + y));
}
function code(x, y) return fma(x, x, Float64(y + y)) end
code[x_, y_] := N[(x * x + N[(y + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y + y\right)
\end{array}
Initial program 100.0%
lift-+.f64N/A
lift-+.f64N/A
associate-+l+N/A
lift-*.f64N/A
lower-fma.f64N/A
lower-+.f64100.0
Applied rewrites100.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 1.75e-44) (+ y y) (+ y (* x x))))
double code(double x, double y) {
double tmp;
if ((x * x) <= 1.75e-44) {
tmp = y + y;
} else {
tmp = y + (x * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 1.75d-44) then
tmp = y + y
else
tmp = y + (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 1.75e-44) {
tmp = y + y;
} else {
tmp = y + (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 1.75e-44: tmp = y + y else: tmp = y + (x * x) return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 1.75e-44) tmp = Float64(y + y); else tmp = Float64(y + Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 1.75e-44) tmp = y + y; else tmp = y + (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.75e-44], N[(y + y), $MachinePrecision], N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.75 \cdot 10^{-44}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.7499999999999999e-44Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6494.2
Applied rewrites94.2%
Applied rewrites94.2%
if 1.7499999999999999e-44 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
Final simplification90.3%
(FPCore (x y) :precision binary64 (if (<= (* x x) 1.95e-28) (+ y y) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 1.95e-28) {
tmp = y + y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 1.95d-28) then
tmp = y + y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 1.95e-28) {
tmp = y + y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 1.95e-28: tmp = y + y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 1.95e-28) tmp = Float64(y + y); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 1.95e-28) tmp = y + y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.95e-28], N[(y + y), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.95 \cdot 10^{-28}:\\
\;\;\;\;y + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.94999999999999999e-28Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6492.8
Applied rewrites92.8%
Applied rewrites92.8%
if 1.94999999999999999e-28 < (*.f64 x x) Initial program 100.0%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6486.0
Applied rewrites86.0%
(FPCore (x y) :precision binary64 (+ y y))
double code(double x, double y) {
return y + y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + y
end function
public static double code(double x, double y) {
return y + y;
}
def code(x, y): return y + y
function code(x, y) return Float64(y + y) end
function tmp = code(x, y) tmp = y + y; end
code[x_, y_] := N[(y + y), $MachinePrecision]
\begin{array}{l}
\\
y + y
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6450.6
Applied rewrites50.6%
Applied rewrites50.6%
(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 2024220
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalTail from random-fu-0.2.6.2"
:precision binary64
:alt
(! :herbie-platform default (+ (+ y y) (* x x)))
(+ (+ (* x x) y) y))