
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
\end{array}
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= y 9.5e+233) (+ (* x (+ x (* y 2.0))) (* y y)) (* y (+ y (* x 2.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (y <= 9.5e+233) {
tmp = (x * (x + (y * 2.0))) + (y * y);
} else {
tmp = y * (y + (x * 2.0));
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= 9.5d+233) then
tmp = (x * (x + (y * 2.0d0))) + (y * y)
else
tmp = y * (y + (x * 2.0d0))
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (y <= 9.5e+233) {
tmp = (x * (x + (y * 2.0))) + (y * y);
} else {
tmp = y * (y + (x * 2.0));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if y <= 9.5e+233: tmp = (x * (x + (y * 2.0))) + (y * y) else: tmp = y * (y + (x * 2.0)) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (y <= 9.5e+233) tmp = Float64(Float64(x * Float64(x + Float64(y * 2.0))) + Float64(y * y)); else tmp = Float64(y * Float64(y + Float64(x * 2.0))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (y <= 9.5e+233)
tmp = (x * (x + (y * 2.0))) + (y * y);
else
tmp = y * (y + (x * 2.0));
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[y, 9.5e+233], N[(N[(x * N[(x + N[(y * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], N[(y * N[(y + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{+233}:\\
\;\;\;\;x \cdot \left(x + y \cdot 2\right) + y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot 2\right)\\
\end{array}
\end{array}
if y < 9.5000000000000001e233Initial program 94.6%
+-commutative94.6%
associate-*r*94.6%
distribute-lft-out97.9%
*-commutative97.9%
Applied egg-rr97.9%
if 9.5000000000000001e233 < y Initial program 73.3%
+-commutative73.3%
associate-*r*73.3%
distribute-lft-out73.3%
*-commutative73.3%
Applied egg-rr73.3%
Taylor expanded in x around 0 73.3%
+-commutative73.3%
unpow273.3%
associate-*r*73.3%
*-commutative73.3%
distribute-rgt-out100.0%
*-commutative100.0%
Simplified100.0%
Final simplification98.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ (* x x) (pow y 2.0)))
assert(x < y);
double code(double x, double y) {
return (x * x) + pow(y, 2.0);
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + (y ** 2.0d0)
end function
assert x < y;
public static double code(double x, double y) {
return (x * x) + Math.pow(y, 2.0);
}
[x, y] = sort([x, y]) def code(x, y): return (x * x) + math.pow(y, 2.0)
x, y = sort([x, y]) function code(x, y) return Float64(Float64(x * x) + (y ^ 2.0)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = (x * x) + (y ^ 2.0);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot x + {y}^{2}
\end{array}
Initial program 93.3%
associate-+l+93.3%
+-commutative93.3%
fma-def93.4%
associate-*l*93.4%
Simplified93.4%
Taylor expanded in y around inf 99.0%
Final simplification99.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (or (<= x -2.3e-16) (and (not (<= x -1.45e-24)) (<= x -1.26e-107))) (* x x) (* y (+ y (* x 2.0)))))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((x <= -2.3e-16) || (!(x <= -1.45e-24) && (x <= -1.26e-107))) {
tmp = x * x;
} else {
tmp = y * (y + (x * 2.0));
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.3d-16)) .or. (.not. (x <= (-1.45d-24))) .and. (x <= (-1.26d-107))) then
tmp = x * x
else
tmp = y * (y + (x * 2.0d0))
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((x <= -2.3e-16) || (!(x <= -1.45e-24) && (x <= -1.26e-107))) {
tmp = x * x;
} else {
tmp = y * (y + (x * 2.0));
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (x <= -2.3e-16) or (not (x <= -1.45e-24) and (x <= -1.26e-107)): tmp = x * x else: tmp = y * (y + (x * 2.0)) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if ((x <= -2.3e-16) || (!(x <= -1.45e-24) && (x <= -1.26e-107))) tmp = Float64(x * x); else tmp = Float64(y * Float64(y + Float64(x * 2.0))); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((x <= -2.3e-16) || (~((x <= -1.45e-24)) && (x <= -1.26e-107)))
tmp = x * x;
else
tmp = y * (y + (x * 2.0));
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[Or[LessEqual[x, -2.3e-16], And[N[Not[LessEqual[x, -1.45e-24]], $MachinePrecision], LessEqual[x, -1.26e-107]]], N[(x * x), $MachinePrecision], N[(y * N[(y + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.3 \cdot 10^{-16} \lor \neg \left(x \leq -1.45 \cdot 10^{-24}\right) \land x \leq -1.26 \cdot 10^{-107}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(y + x \cdot 2\right)\\
\end{array}
\end{array}
if x < -2.2999999999999999e-16 or -1.4499999999999999e-24 < x < -1.2599999999999999e-107Initial program 90.5%
associate-+l+90.5%
+-commutative90.5%
fma-def90.5%
associate-*l*90.5%
Simplified90.5%
Taylor expanded in x around inf 73.2%
pow273.2%
Applied egg-rr73.2%
if -2.2999999999999999e-16 < x < -1.4499999999999999e-24 or -1.2599999999999999e-107 < x Initial program 94.5%
+-commutative94.5%
associate-*r*94.5%
distribute-lft-out97.2%
*-commutative97.2%
Applied egg-rr97.2%
Taylor expanded in x around 0 67.9%
+-commutative67.9%
unpow267.9%
associate-*r*67.9%
*-commutative67.9%
distribute-rgt-out70.7%
*-commutative70.7%
Simplified70.7%
Final simplification71.4%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -2.35e-306) (* x x) (* y (* x 2.0))))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -2.35e-306) {
tmp = x * x;
} else {
tmp = y * (x * 2.0);
}
return tmp;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-2.35d-306)) then
tmp = x * x
else
tmp = y * (x * 2.0d0)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -2.35e-306) {
tmp = x * x;
} else {
tmp = y * (x * 2.0);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -2.35e-306: tmp = x * x else: tmp = y * (x * 2.0) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -2.35e-306) tmp = Float64(x * x); else tmp = Float64(y * Float64(x * 2.0)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -2.35e-306)
tmp = x * x;
else
tmp = y * (x * 2.0);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[x, -2.35e-306], N[(x * x), $MachinePrecision], N[(y * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.35 \cdot 10^{-306}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x \cdot 2\right)\\
\end{array}
\end{array}
if x < -2.3500000000000001e-306Initial program 93.8%
associate-+l+93.8%
+-commutative93.8%
fma-def93.9%
associate-*l*93.9%
Simplified93.9%
Taylor expanded in x around inf 55.5%
pow255.5%
Applied egg-rr55.5%
if -2.3500000000000001e-306 < x Initial program 92.9%
associate-+l+92.9%
+-commutative92.9%
fma-def92.9%
associate-*l*92.9%
Simplified92.9%
Taylor expanded in y around 0 48.8%
Taylor expanded in x around 0 16.1%
associate-*r*16.1%
*-commutative16.1%
*-commutative16.1%
*-commutative16.1%
Simplified16.1%
Final simplification33.6%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (* x x))
assert(x < y);
double code(double x, double y) {
return x * x;
}
NOTE: x and y should be sorted in increasing order before calling this function.
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
assert x < y;
public static double code(double x, double y) {
return x * x;
}
[x, y] = sort([x, y]) def code(x, y): return x * x
x, y = sort([x, y]) function code(x, y) return Float64(x * x) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = x * x;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot x
\end{array}
Initial program 93.3%
associate-+l+93.3%
+-commutative93.3%
fma-def93.4%
associate-*l*93.4%
Simplified93.4%
Taylor expanded in x around inf 54.4%
pow254.4%
Applied egg-rr54.4%
Final simplification54.4%
(FPCore (x y) :precision binary64 (+ (* x x) (+ (* y y) (* (* x y) 2.0))))
double code(double x, double y) {
return (x * x) + ((y * y) + ((x * y) * 2.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) + ((y * y) + ((x * y) * 2.0d0))
end function
public static double code(double x, double y) {
return (x * x) + ((y * y) + ((x * y) * 2.0));
}
def code(x, y): return (x * x) + ((y * y) + ((x * y) * 2.0))
function code(x, y) return Float64(Float64(x * x) + Float64(Float64(y * y) + Float64(Float64(x * y) * 2.0))) end
function tmp = code(x, y) tmp = (x * x) + ((y * y) + ((x * y) * 2.0)); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(N[(y * y), $MachinePrecision] + N[(N[(x * y), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + \left(y \cdot y + \left(x \cdot y\right) \cdot 2\right)
\end{array}
herbie shell --seed 2023308
(FPCore (x y)
:name "Examples.Basics.ProofTests:f4 from sbv-4.4"
:precision binary64
:herbie-target
(+ (* x x) (+ (* y y) (* (* x y) 2.0)))
(+ (+ (* x x) (* (* x 2.0) y)) (* y y)))