
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
def code(x, y, z): return (x + y) * (z + 1.0)
function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
function tmp = code(x, y, z) tmp = (x + y) * (z + 1.0); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ (fma z (+ y x) y) x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, (y + x), y) + x;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(fma(z, Float64(y + x), y) + x) end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(z * N[(y + x), $MachinePrecision] + y), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, y + x, y\right) + x
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lift-+.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-fma.f64100.0
lift-+.f64N/A
+-commutativeN/A
lower-+.f64100.0
Applied rewrites100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-254) (fma z x x) (if (or (<= (+ x y) 2e-28) (not (<= (+ x y) 4e+137))) (* y z) (+ y x))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-254) {
tmp = fma(z, x, x);
} else if (((x + y) <= 2e-28) || !((x + y) <= 4e+137)) {
tmp = y * z;
} else {
tmp = y + x;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-254) tmp = fma(z, x, x); elseif ((Float64(x + y) <= 2e-28) || !(Float64(x + y) <= 4e+137)) tmp = Float64(y * z); else tmp = Float64(y + x); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-254], N[(z * x + x), $MachinePrecision], If[Or[LessEqual[N[(x + y), $MachinePrecision], 2e-28], N[Not[LessEqual[N[(x + y), $MachinePrecision], 4e+137]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{-28} \lor \neg \left(x + y \leq 4 \cdot 10^{+137}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (+.f64 x y) < -1.9999999999999998e-254Initial program 99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6448.3
Applied rewrites48.3%
if -1.9999999999999998e-254 < (+.f64 x y) < 1.99999999999999994e-28 or 4.0000000000000001e137 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6461.5
Applied rewrites61.5%
Taylor expanded in x around 0
Applied rewrites29.4%
if 1.99999999999999994e-28 < (+.f64 x y) < 4.0000000000000001e137Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6427.3
Applied rewrites27.3%
Taylor expanded in x around 0
Applied rewrites17.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6473.0
Applied rewrites73.0%
Final simplification45.8%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 12.0))) (* z x) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 12.0)) {
tmp = z * x;
} else {
tmp = y + x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 12.0d0))) then
tmp = z * x
else
tmp = y + x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 12.0)) {
tmp = z * x;
} else {
tmp = y + x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 12.0): tmp = z * x else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 12.0)) tmp = Float64(z * x); else tmp = Float64(y + x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.0) || ~((z <= 12.0)))
tmp = z * x;
else
tmp = y + x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 12.0]], $MachinePrecision]], N[(z * x), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 12\right):\\
\;\;\;\;z \cdot x\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -1 or 12 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
Applied rewrites52.0%
Taylor expanded in x around inf
Applied rewrites54.5%
if -1 < z < 12Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f643.1
Applied rewrites3.1%
Taylor expanded in x around 0
Applied rewrites3.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.6
Applied rewrites97.6%
Final simplification75.9%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 600000000000.0))) (* y z) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 600000000000.0)) {
tmp = y * z;
} else {
tmp = y + x;
}
return tmp;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if ((z <= (-1.0d0)) .or. (.not. (z <= 600000000000.0d0))) then
tmp = y * z
else
tmp = y + x
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 600000000000.0)) {
tmp = y * z;
} else {
tmp = y + x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 600000000000.0): tmp = y * z else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 600000000000.0)) tmp = Float64(y * z); else tmp = Float64(y + x); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((z <= -1.0) || ~((z <= 600000000000.0)))
tmp = y * z;
else
tmp = y + x;
end
tmp_2 = tmp;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 600000000000.0]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 600000000000\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -1 or 6e11 < z Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6498.5
Applied rewrites98.5%
Taylor expanded in x around 0
Applied rewrites51.7%
if -1 < z < 6e11Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f643.7
Applied rewrites3.7%
Taylor expanded in x around 0
Applied rewrites3.6%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6496.9
Applied rewrites96.9%
Final simplification74.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -2e-254) (fma z x x) (fma z y y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-254) {
tmp = fma(z, x, x);
} else {
tmp = fma(z, y, y);
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-254) tmp = fma(z, x, x); else tmp = fma(z, y, y); end return tmp end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := If[LessEqual[N[(x + y), $MachinePrecision], -2e-254], N[(z * x + x), $MachinePrecision], N[(z * y + y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-254}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -1.9999999999999998e-254Initial program 99.9%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6448.3
Applied rewrites48.3%
if -1.9999999999999998e-254 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6450.2
Applied rewrites50.2%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (+ x y) (+ z 1.0)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x + y) * (z + 1.0d0)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (x + y) * (z + 1.0);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (x + y) * (z + 1.0)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(x + y) * Float64(z + 1.0)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (x + y) * (z + 1.0);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(x + y\right) \cdot \left(z + 1\right)
\end{array}
Initial program 100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ y x))
assert(x < y && y < z);
double code(double x, double y, double z) {
return y + x;
}
NOTE: x, y, and z should be sorted in increasing order before calling this function.
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y + x
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return y + x;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return y + x
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(y + x) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = y + x;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
y + x
\end{array}
Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6451.1
Applied rewrites51.1%
Taylor expanded in x around 0
Applied rewrites27.7%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6450.1
Applied rewrites50.1%
herbie shell --seed 2024339
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))