
(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 (<= (+ (+ (* x x) (* (* x 2.0) y)) (* y y)) 4e+276) (fma x x (* y (+ (* x 2.0) y))) (+ (* x x) (* y y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
tmp = fma(x, x, (y * ((x * 2.0) + y)));
} else {
tmp = (x * x) + (y * y);
}
return tmp;
}
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) <= 4e+276) tmp = fma(x, x, Float64(y * Float64(Float64(x * 2.0) + y))); else tmp = Float64(Float64(x * x) + Float64(y * y)); end return tmp end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 4e+276], N[(x * x + N[(y * N[(N[(x * 2.0), $MachinePrecision] + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(x \cdot 2 + y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 4.0000000000000002e276Initial program 99.9%
associate-+l+99.9%
fma-def100.0%
distribute-rgt-out100.0%
Simplified100.0%
if 4.0000000000000002e276 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) Initial program 83.9%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= (+ (+ (* x x) (* (* x 2.0) y)) (* y y)) 4e+276) (+ (* y y) (* x (+ x (* 2.0 y)))) (+ (* x x) (* y y))))
assert(x < y);
double code(double x, double y) {
double tmp;
if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
tmp = (y * y) + (x * (x + (2.0 * y)));
} else {
tmp = (x * x) + (y * y);
}
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 * x) + ((x * 2.0d0) * y)) + (y * y)) <= 4d+276) then
tmp = (y * y) + (x * (x + (2.0d0 * y)))
else
tmp = (x * x) + (y * y)
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276) {
tmp = (y * y) + (x * (x + (2.0 * y)));
} else {
tmp = (x * x) + (y * y);
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if (((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276: tmp = (y * y) + (x * (x + (2.0 * y))) else: tmp = (x * x) + (y * y) return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) <= 4e+276) tmp = Float64(Float64(y * y) + Float64(x * Float64(x + Float64(2.0 * y)))); else tmp = Float64(Float64(x * x) + Float64(y * y)); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if ((((x * x) + ((x * 2.0) * y)) + (y * y)) <= 4e+276)
tmp = (y * y) + (x * (x + (2.0 * y)));
else
tmp = (x * x) + (y * y);
end
tmp_2 = tmp;
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := If[LessEqual[N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision], 4e+276], N[(N[(y * y), $MachinePrecision] + N[(x * N[(x + N[(2.0 * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y \leq 4 \cdot 10^{+276}:\\
\;\;\;\;y \cdot y + x \cdot \left(x + 2 \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + y \cdot y\\
\end{array}
\end{array}
if (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) < 4.0000000000000002e276Initial program 99.9%
associate-+l+99.9%
fma-def100.0%
distribute-rgt-out100.0%
Simplified100.0%
fma-udef99.9%
distribute-rgt-in99.9%
associate-+l+99.9%
+-commutative99.9%
associate-*l*99.9%
distribute-lft-out100.0%
Applied egg-rr100.0%
if 4.0000000000000002e276 < (+.f64 (+.f64 (*.f64 x x) (*.f64 (*.f64 x 2) y)) (*.f64 y y)) Initial program 83.9%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification100.0%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (+ (* x x) (* y y)))
assert(x < y);
double code(double x, double y) {
return (x * x) + (y * y);
}
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 * y)
end function
assert x < y;
public static double code(double x, double y) {
return (x * x) + (y * y);
}
[x, y] = sort([x, y]) def code(x, y): return (x * x) + (y * y)
x, y = sort([x, y]) function code(x, y) return Float64(Float64(x * x) + Float64(y * y)) end
x, y = num2cell(sort([x, y])){:}
function tmp = code(x, y)
tmp = (x * x) + (y * y);
end
NOTE: x and y should be sorted in increasing order before calling this function. code[x_, y_] := N[(N[(x * x), $MachinePrecision] + N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
x \cdot x + y \cdot y
\end{array}
Initial program 92.1%
Taylor expanded in x around inf 97.8%
unpow297.8%
Simplified97.8%
Final simplification97.8%
NOTE: x and y should be sorted in increasing order before calling this function. (FPCore (x y) :precision binary64 (if (<= x -4e-132) (* x x) (* y y)))
assert(x < y);
double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
tmp = x * x;
} else {
tmp = y * y;
}
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 <= (-4d-132)) then
tmp = x * x
else
tmp = y * y
end if
code = tmp
end function
assert x < y;
public static double code(double x, double y) {
double tmp;
if (x <= -4e-132) {
tmp = x * x;
} else {
tmp = y * y;
}
return tmp;
}
[x, y] = sort([x, y]) def code(x, y): tmp = 0 if x <= -4e-132: tmp = x * x else: tmp = y * y return tmp
x, y = sort([x, y]) function code(x, y) tmp = 0.0 if (x <= -4e-132) tmp = Float64(x * x); else tmp = Float64(y * y); end return tmp end
x, y = num2cell(sort([x, y])){:}
function tmp_2 = code(x, y)
tmp = 0.0;
if (x <= -4e-132)
tmp = x * x;
else
tmp = y * y;
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, -4e-132], N[(x * x), $MachinePrecision], N[(y * y), $MachinePrecision]]
\begin{array}{l}
[x, y] = \mathsf{sort}([x, y])\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{-132}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot y\\
\end{array}
\end{array}
if x < -3.9999999999999999e-132Initial program 91.5%
Taylor expanded in x around inf 95.8%
unpow295.8%
Simplified95.8%
Taylor expanded in x around inf 69.6%
unpow269.6%
Simplified69.6%
if -3.9999999999999999e-132 < x Initial program 92.6%
Taylor expanded in x around 0 69.8%
unpow269.8%
Simplified69.8%
Final simplification69.7%
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 92.1%
Taylor expanded in x around inf 97.8%
unpow297.8%
Simplified97.8%
Taylor expanded in x around inf 56.7%
unpow256.7%
Simplified56.7%
Final simplification56.7%
(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 2023173
(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)))