
(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 (+ x y) x) y))
assert(x < y && y < z);
double code(double x, double y, double z) {
return fma(z, (x + y), x) + y;
}
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(fma(z, Float64(x + y), 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[(x + y), $MachinePrecision] + x), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\mathsf{fma}\left(z, x + y, 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%
Final simplification100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function.
(FPCore (x y z)
:precision binary64
(if (<= (+ 1.0 z) -2e+217)
(* y z)
(if (<= (+ 1.0 z) -5e+154)
(* x z)
(if (<= (+ 1.0 z) -200.0)
(* y z)
(if (<= (+ 1.0 z) 2.0)
(+ x y)
(if (<= (+ 1.0 z) 2e+65) (* y z) (* x z)))))))assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((1.0 + z) <= -2e+217) {
tmp = y * z;
} else if ((1.0 + z) <= -5e+154) {
tmp = x * z;
} else if ((1.0 + z) <= -200.0) {
tmp = y * z;
} else if ((1.0 + z) <= 2.0) {
tmp = x + y;
} else if ((1.0 + z) <= 2e+65) {
tmp = y * z;
} else {
tmp = x * z;
}
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 ((1.0d0 + z) <= (-2d+217)) then
tmp = y * z
else if ((1.0d0 + z) <= (-5d+154)) then
tmp = x * z
else if ((1.0d0 + z) <= (-200.0d0)) then
tmp = y * z
else if ((1.0d0 + z) <= 2.0d0) then
tmp = x + y
else if ((1.0d0 + z) <= 2d+65) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 + z) <= -2e+217) {
tmp = y * z;
} else if ((1.0 + z) <= -5e+154) {
tmp = x * z;
} else if ((1.0 + z) <= -200.0) {
tmp = y * z;
} else if ((1.0 + z) <= 2.0) {
tmp = x + y;
} else if ((1.0 + z) <= 2e+65) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (1.0 + z) <= -2e+217: tmp = y * z elif (1.0 + z) <= -5e+154: tmp = x * z elif (1.0 + z) <= -200.0: tmp = y * z elif (1.0 + z) <= 2.0: tmp = x + y elif (1.0 + z) <= 2e+65: tmp = y * z else: tmp = x * z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(1.0 + z) <= -2e+217) tmp = Float64(y * z); elseif (Float64(1.0 + z) <= -5e+154) tmp = Float64(x * z); elseif (Float64(1.0 + z) <= -200.0) tmp = Float64(y * z); elseif (Float64(1.0 + z) <= 2.0) tmp = Float64(x + y); elseif (Float64(1.0 + z) <= 2e+65) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((1.0 + z) <= -2e+217)
tmp = y * z;
elseif ((1.0 + z) <= -5e+154)
tmp = x * z;
elseif ((1.0 + z) <= -200.0)
tmp = y * z;
elseif ((1.0 + z) <= 2.0)
tmp = x + y;
elseif ((1.0 + z) <= 2e+65)
tmp = y * z;
else
tmp = x * z;
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[LessEqual[N[(1.0 + z), $MachinePrecision], -2e+217], N[(y * z), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], -5e+154], N[(x * z), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], -200.0], N[(y * z), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], 2.0], N[(x + y), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], 2e+65], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 + z \leq -2 \cdot 10^{+217}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;1 + z \leq -5 \cdot 10^{+154}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;1 + z \leq -200:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;1 + z \leq 2:\\
\;\;\;\;x + y\\
\mathbf{elif}\;1 + z \leq 2 \cdot 10^{+65}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -1.99999999999999992e217 or -5.00000000000000004e154 < (+.f64 z #s(literal 1 binary64)) < -200 or 2 < (+.f64 z #s(literal 1 binary64)) < 2e65Initial program 99.9%
Taylor expanded in y around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6454.9
Applied rewrites54.9%
Taylor expanded in z around inf
Applied rewrites53.3%
if -1.99999999999999992e217 < (+.f64 z #s(literal 1 binary64)) < -5.00000000000000004e154 or 2e65 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6453.3
Applied rewrites53.3%
Taylor expanded in z around inf
Applied rewrites53.3%
if -200 < (+.f64 z #s(literal 1 binary64)) < 2Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6498.4
Applied rewrites98.4%
Final simplification73.4%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-258) (fma z x x) (if (<= (+ x y) 2e+32) (+ x y) (* y z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((x + y) <= -1e-258) {
tmp = fma(z, x, x);
} else if ((x + y) <= 2e+32) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(x + y) <= -1e-258) tmp = fma(z, x, x); elseif (Float64(x + y) <= 2e+32) tmp = Float64(x + y); else tmp = Float64(y * z); 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], -1e-258], N[(z * x + x), $MachinePrecision], If[LessEqual[N[(x + y), $MachinePrecision], 2e+32], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;x + y \leq -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{elif}\;x + y \leq 2 \cdot 10^{+32}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999954e-259Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6448.7
Applied rewrites48.7%
if -9.99999999999999954e-259 < (+.f64 x y) < 2.00000000000000011e32Initial program 99.9%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6464.9
Applied rewrites64.9%
if 2.00000000000000011e32 < (+.f64 x y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6456.0
Applied rewrites56.0%
Taylor expanded in z around inf
Applied rewrites38.3%
Final simplification47.6%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ 1.0 z) -200.0) (* x z) (if (<= (+ 1.0 z) 500000000.0) (+ x y) (* x z))))
assert(x < y && y < z);
double code(double x, double y, double z) {
double tmp;
if ((1.0 + z) <= -200.0) {
tmp = x * z;
} else if ((1.0 + z) <= 500000000.0) {
tmp = x + y;
} else {
tmp = x * z;
}
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 ((1.0d0 + z) <= (-200.0d0)) then
tmp = x * z
else if ((1.0d0 + z) <= 500000000.0d0) then
tmp = x + y
else
tmp = x * z
end if
code = tmp
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
double tmp;
if ((1.0 + z) <= -200.0) {
tmp = x * z;
} else if ((1.0 + z) <= 500000000.0) {
tmp = x + y;
} else {
tmp = x * z;
}
return tmp;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): tmp = 0 if (1.0 + z) <= -200.0: tmp = x * z elif (1.0 + z) <= 500000000.0: tmp = x + y else: tmp = x * z return tmp
x, y, z = sort([x, y, z]) function code(x, y, z) tmp = 0.0 if (Float64(1.0 + z) <= -200.0) tmp = Float64(x * z); elseif (Float64(1.0 + z) <= 500000000.0) tmp = Float64(x + y); else tmp = Float64(x * z); end return tmp end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp_2 = code(x, y, z)
tmp = 0.0;
if ((1.0 + z) <= -200.0)
tmp = x * z;
elseif ((1.0 + z) <= 500000000.0)
tmp = x + y;
else
tmp = x * z;
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[LessEqual[N[(1.0 + z), $MachinePrecision], -200.0], N[(x * z), $MachinePrecision], If[LessEqual[N[(1.0 + z), $MachinePrecision], 500000000.0], N[(x + y), $MachinePrecision], N[(x * z), $MachinePrecision]]]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\begin{array}{l}
\mathbf{if}\;1 + z \leq -200:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;1 + z \leq 500000000:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if (+.f64 z #s(literal 1 binary64)) < -200 or 5e8 < (+.f64 z #s(literal 1 binary64)) Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6451.1
Applied rewrites51.1%
Taylor expanded in z around inf
Applied rewrites50.4%
if -200 < (+.f64 z #s(literal 1 binary64)) < 5e8Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6496.9
Applied rewrites96.9%
Final simplification71.5%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (if (<= (+ x y) -1e-258) (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) <= -1e-258) {
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) <= -1e-258) 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], -1e-258], 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 -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(1 + z\right) \cdot y\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999954e-259Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6448.7
Applied rewrites48.7%
if -9.99999999999999954e-259 < (+.f64 x y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6449.3
Applied rewrites49.3%
Applied rewrites49.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) -1e-258) (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) <= -1e-258) {
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) <= -1e-258) 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], -1e-258], 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 -1 \cdot 10^{-258}:\\
\;\;\;\;\mathsf{fma}\left(z, x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(z, y, y\right)\\
\end{array}
\end{array}
if (+.f64 x y) < -9.99999999999999954e-259Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6448.7
Applied rewrites48.7%
if -9.99999999999999954e-259 < (+.f64 x y) Initial program 100.0%
Taylor expanded in y around inf
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
lower-fma.f6449.3
Applied rewrites49.3%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (* (+ 1.0 z) (+ x y)))
assert(x < y && y < z);
double code(double x, double y, double z) {
return (1.0 + z) * (x + y);
}
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 = (1.0d0 + z) * (x + y)
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return (1.0 + z) * (x + y);
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return (1.0 + z) * (x + y)
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(Float64(1.0 + z) * Float64(x + y)) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = (1.0 + z) * (x + y);
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(N[(1.0 + z), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
\left(1 + z\right) \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
Final simplification100.0%
NOTE: x, y, and z should be sorted in increasing order before calling this function. (FPCore (x y z) :precision binary64 (+ x y))
assert(x < y && y < z);
double code(double x, double y, double z) {
return x + y;
}
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
end function
assert x < y && y < z;
public static double code(double x, double y, double z) {
return x + y;
}
[x, y, z] = sort([x, y, z]) def code(x, y, z): return x + y
x, y, z = sort([x, y, z]) function code(x, y, z) return Float64(x + y) end
x, y, z = num2cell(sort([x, y, z])){:}
function tmp = code(x, y, z)
tmp = x + y;
end
NOTE: x, y, and z should be sorted in increasing order before calling this function. code[x_, y_, z_] := N[(x + y), $MachinePrecision]
\begin{array}{l}
[x, y, z] = \mathsf{sort}([x, y, z])\\
\\
x + y
\end{array}
Initial program 100.0%
Taylor expanded in z around 0
+-commutativeN/A
lower-+.f6445.7
Applied rewrites45.7%
Final simplification45.7%
herbie shell --seed 2024277
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))