
(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 9 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 y 2.0 (* x x)))
double code(double x, double y) {
return fma(y, 2.0, (x * x));
}
function code(x, y) return fma(y, 2.0, Float64(x * x)) end
code[x_, y_] := N[(y * 2.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 2, x \cdot x\right)
\end{array}
Initial program 100.0%
associate-+l+100.0%
+-commutative100.0%
count-2100.0%
*-commutative100.0%
fma-define100.0%
Simplified100.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(y + Float64(y + Float64(x * x))) end
function tmp = code(x, y) tmp = y + (y + (x * x)); end
code[x_, y_] := N[(y + N[(y + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(y + x \cdot x\right)
\end{array}
Initial program 100.0%
Final simplification100.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 50.0%
(FPCore (x y) :precision binary64 4.0)
double code(double x, double y) {
return 4.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 4.0d0
end function
public static double code(double x, double y) {
return 4.0;
}
def code(x, y): return 4.0
function code(x, y) return 4.0 end
function tmp = code(x, y) tmp = 4.0; end
code[x_, y_] := 4.0
\begin{array}{l}
\\
4
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr3.9%
(FPCore (x y) :precision binary64 0.3333333333333333)
double code(double x, double y) {
return 0.3333333333333333;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.3333333333333333d0
end function
public static double code(double x, double y) {
return 0.3333333333333333;
}
def code(x, y): return 0.3333333333333333
function code(x, y) return 0.3333333333333333 end
function tmp = code(x, y) tmp = 0.3333333333333333; end
code[x_, y_] := 0.3333333333333333
\begin{array}{l}
\\
0.3333333333333333
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr3.9%
(FPCore (x y) :precision binary64 0.1111111111111111)
double code(double x, double y) {
return 0.1111111111111111;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.1111111111111111d0
end function
public static double code(double x, double y) {
return 0.1111111111111111;
}
def code(x, y): return 0.1111111111111111
function code(x, y) return 0.1111111111111111 end
function tmp = code(x, y) tmp = 0.1111111111111111; end
code[x_, y_] := 0.1111111111111111
\begin{array}{l}
\\
0.1111111111111111
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr3.9%
(FPCore (x y) :precision binary64 0.0)
double code(double x, double y) {
return 0.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 0.0d0
end function
public static double code(double x, double y) {
return 0.0;
}
def code(x, y): return 0.0
function code(x, y) return 0.0 end
function tmp = code(x, y) tmp = 0.0; end
code[x_, y_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr2.7%
(FPCore (x y) :precision binary64 -0.3333333333333333)
double code(double x, double y) {
return -0.3333333333333333;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -0.3333333333333333d0
end function
public static double code(double x, double y) {
return -0.3333333333333333;
}
def code(x, y): return -0.3333333333333333
function code(x, y) return -0.3333333333333333 end
function tmp = code(x, y) tmp = -0.3333333333333333; end
code[x_, y_] := -0.3333333333333333
\begin{array}{l}
\\
-0.3333333333333333
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr2.2%
(FPCore (x y) :precision binary64 -3.0)
double code(double x, double y) {
return -3.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -3.0d0
end function
public static double code(double x, double y) {
return -3.0;
}
def code(x, y): return -3.0
function code(x, y) return -3.0 end
function tmp = code(x, y) tmp = -3.0; end
code[x_, y_] := -3.0
\begin{array}{l}
\\
-3
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 50.0%
Applied egg-rr2.2%
(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 2024110
(FPCore (x y)
:name "Data.Random.Distribution.Normal:normalTail from random-fu-0.2.6.2"
:precision binary64
:alt
(+ (+ y y) (* x x))
(+ (+ (* x x) y) y))