
(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 8 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) x) y))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, (y + x), x) + y;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(fma(z, Float64(y + x), x) + y) 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] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, y + x, x\right) + y
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-+.f64N/A
distribute-rgt-inN/A
*-lft-identityN/A
lift-+.f64N/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 (or (<= (+ z 1.0) -5000000.0) (not (<= (+ z 1.0) 200.0))) (* z y) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((z + 1.0) <= -5000000.0) || !((z + 1.0) <= 200.0)) {
tmp = z * y;
} 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) <= (-5000000.0d0)) .or. (.not. ((z + 1.0d0) <= 200.0d0))) then
tmp = z * y
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) <= -5000000.0) || !((z + 1.0) <= 200.0)) {
tmp = z * y;
} else {
tmp = y + x;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if ((z + 1.0) <= -5000000.0) or not ((z + 1.0) <= 200.0): tmp = z * y else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(z + 1.0) <= -5000000.0) || !(Float64(z + 1.0) <= 200.0)) tmp = Float64(z * y); 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) <= -5000000.0) || ~(((z + 1.0) <= 200.0)))
tmp = z * y;
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[N[(z + 1.0), $MachinePrecision], -5000000.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 200.0]], $MachinePrecision]], N[(z * y), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 200\right):\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -5e6 or 200 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.1
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites54.3%
Taylor expanded in x around 0
Applied rewrites49.0%
if -5e6 < (+.f64 z #s(literal 1 binary64)) < 200Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f643.6
Applied rewrites3.6%
Taylor expanded in x around inf
Applied rewrites3.4%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6497.5
Applied rewrites97.5%
Final simplification73.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) -5000000.0) (not (<= (+ z 1.0) 1e+39))) (* x z) (+ y x)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if (((z + 1.0) <= -5000000.0) || !((z + 1.0) <= 1e+39)) {
tmp = x * 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) <= (-5000000.0d0)) .or. (.not. ((z + 1.0d0) <= 1d+39))) then
tmp = x * 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) <= -5000000.0) || !((z + 1.0) <= 1e+39)) {
tmp = x * 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) <= -5000000.0) or not ((z + 1.0) <= 1e+39): tmp = x * z else: tmp = y + x return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if ((Float64(z + 1.0) <= -5000000.0) || !(Float64(z + 1.0) <= 1e+39)) tmp = Float64(x * 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) <= -5000000.0) || ~(((z + 1.0) <= 1e+39)))
tmp = x * 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[N[(z + 1.0), $MachinePrecision], -5000000.0], N[Not[LessEqual[N[(z + 1.0), $MachinePrecision], 1e+39]], $MachinePrecision]], N[(x * z), $MachinePrecision], N[(y + x), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;z + 1 \leq -5000000 \lor \neg \left(z + 1 \leq 10^{+39}\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -5e6 or 9.9999999999999994e38 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6499.6
Applied rewrites99.6%
Taylor expanded in x around inf
Applied rewrites53.3%
if -5e6 < (+.f64 z #s(literal 1 binary64)) < 9.9999999999999994e38Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f647.4
Applied rewrites7.4%
Taylor expanded in x around inf
Applied rewrites6.5%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6493.6
Applied rewrites93.6%
Final simplification74.9%
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-220) (fma z x x) (if (<= (+ x y) 2e+76) (+ y x) (* z y))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-220) {
tmp = fma(z, x, x);
} else if ((x + y) <= 2e+76) {
tmp = y + x;
} else {
tmp = z * y;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-220) tmp = fma(z, x, x); elseif (Float64(x + y) <= 2e+76) tmp = Float64(y + x); else tmp = Float64(z * 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-220], N[(z * x + x), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e+76], N[(y + x), $MachinePrecision], N[(z * y), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{+76}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;z \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999998e-220Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6454.9
Applied rewrites54.9%
if -1.99999999999999998e-220 < (+.f64 x y) < 2.0000000000000001e76Initial program 99.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6443.1
Applied rewrites43.1%
Taylor expanded in x around inf
Applied rewrites25.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6457.9
Applied rewrites57.9%
if 2.0000000000000001e76 < (+.f64 x y) Initial program 100.0%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f6457.4
Applied rewrites57.4%
Taylor expanded in x around inf
Applied rewrites30.4%
Taylor expanded in x around 0
Applied rewrites30.9%
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-220) (fma z x x) (* (+ 1.0 z) y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -2e-220) {
tmp = fma(z, x, x);
} else {
tmp = (1.0 + z) * y;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -2e-220) tmp = fma(z, x, x); else tmp = Float64(Float64(1.0 + z) * 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-220], N[(z * x + x), $MachinePrecision], N[(N[(1.0 + z), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -2 \cdot 10^{-220}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + z\right) \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < -1.99999999999999998e-220Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6454.9
Applied rewrites54.9%
if -1.99999999999999998e-220 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6451.8
Applied rewrites51.8%
Applied rewrites51.8%
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-220) (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-220) {
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-220) 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-220], 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^{-220}:\\
\;\;\;\;\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.99999999999999998e-220Initial program 100.0%
Taylor expanded in x around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6454.9
Applied rewrites54.9%
if -1.99999999999999998e-220 < (+.f64 x y) Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6451.8
Applied rewrites51.8%
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-+.f6450.3
Applied rewrites50.3%
Taylor expanded in x around inf
Applied rewrites28.3%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6451.5
Applied rewrites51.5%
herbie shell --seed 2024326
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))