
(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 9 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}
(FPCore (x y z) :precision binary64 (+ (+ x y) (* z (+ x y))))
double code(double x, double y, double z) {
return (x + y) + (z * (x + y));
}
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 * (x + y))
end function
public static double code(double x, double y, double z) {
return (x + y) + (z * (x + y));
}
def code(x, y, z): return (x + y) + (z * (x + y))
function code(x, y, z) return Float64(Float64(x + y) + Float64(z * Float64(x + y))) end
function tmp = code(x, y, z) tmp = (x + y) + (z * (x + y)); end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] + N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) + z \cdot \left(x + y\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z 8.6e-73)
y
(if (<= z 1.0)
x
(if (<= z 3e+191) (* x z) (if (<= z 7e+216) (* y z) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 8.6e-73) {
tmp = y;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 3e+191) {
tmp = x * z;
} else if (z <= 7e+216) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
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)) then
tmp = x * z
else if (z <= 8.6d-73) then
tmp = y
else if (z <= 1.0d0) then
tmp = x
else if (z <= 3d+191) then
tmp = x * z
else if (z <= 7d+216) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 8.6e-73) {
tmp = y;
} else if (z <= 1.0) {
tmp = x;
} else if (z <= 3e+191) {
tmp = x * z;
} else if (z <= 7e+216) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 8.6e-73: tmp = y elif z <= 1.0: tmp = x elif z <= 3e+191: tmp = x * z elif z <= 7e+216: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 8.6e-73) tmp = y; elseif (z <= 1.0) tmp = x; elseif (z <= 3e+191) tmp = Float64(x * z); elseif (z <= 7e+216) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= 8.6e-73) tmp = y; elseif (z <= 1.0) tmp = x; elseif (z <= 3e+191) tmp = x * z; elseif (z <= 7e+216) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 8.6e-73], y, If[LessEqual[z, 1.0], x, If[LessEqual[z, 3e+191], N[(x * z), $MachinePrecision], If[LessEqual[z, 7e+216], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 8.6 \cdot 10^{-73}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3 \cdot 10^{+191}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+216}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z < 2.9999999999999997e191 or 6.99999999999999984e216 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 52.0%
Taylor expanded in z around inf 50.7%
if -1 < z < 8.5999999999999998e-73Initial program 100.0%
Taylor expanded in x around 0 55.8%
Taylor expanded in z around 0 54.7%
if 8.5999999999999998e-73 < z < 1Initial program 99.9%
Taylor expanded in x around inf 38.2%
Taylor expanded in z around 0 38.2%
if 2.9999999999999997e191 < z < 6.99999999999999984e216Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 50.2%
Taylor expanded in z around inf 50.2%
Final simplification51.4%
(FPCore (x y z)
:precision binary64
(if (<= z -1.0)
(* x z)
(if (<= z 31.0)
(+ x y)
(if (<= z 2e+193) (* x z) (if (<= z 1.7e+217) (* y z) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 31.0) {
tmp = x + y;
} else if (z <= 2e+193) {
tmp = x * z;
} else if (z <= 1.7e+217) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
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)) then
tmp = x * z
else if (z <= 31.0d0) then
tmp = x + y
else if (z <= 2d+193) then
tmp = x * z
else if (z <= 1.7d+217) then
tmp = y * z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 31.0) {
tmp = x + y;
} else if (z <= 2e+193) {
tmp = x * z;
} else if (z <= 1.7e+217) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = x * z elif z <= 31.0: tmp = x + y elif z <= 2e+193: tmp = x * z elif z <= 1.7e+217: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(x * z); elseif (z <= 31.0) tmp = Float64(x + y); elseif (z <= 2e+193) tmp = Float64(x * z); elseif (z <= 1.7e+217) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = x * z; elseif (z <= 31.0) tmp = x + y; elseif (z <= 2e+193) tmp = x * z; elseif (z <= 1.7e+217) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(x * z), $MachinePrecision], If[LessEqual[z, 31.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 2e+193], N[(x * z), $MachinePrecision], If[LessEqual[z, 1.7e+217], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 31:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2 \cdot 10^{+193}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{+217}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1 or 31 < z < 2.00000000000000013e193 or 1.6999999999999999e217 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 52.0%
Taylor expanded in z around inf 50.7%
if -1 < z < 31Initial program 100.0%
Taylor expanded in z around 0 97.9%
if 2.00000000000000013e193 < z < 1.6999999999999999e217Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 50.2%
Taylor expanded in z around inf 50.2%
Final simplification74.7%
(FPCore (x y z) :precision binary64 (if (<= z -180.0) (* y z) (if (<= z 1.4e-73) y (if (<= z 12000000.0) x (* y z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -180.0) {
tmp = y * z;
} else if (z <= 1.4e-73) {
tmp = y;
} else if (z <= 12000000.0) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
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 <= (-180.0d0)) then
tmp = y * z
else if (z <= 1.4d-73) then
tmp = y
else if (z <= 12000000.0d0) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -180.0) {
tmp = y * z;
} else if (z <= 1.4e-73) {
tmp = y;
} else if (z <= 12000000.0) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -180.0: tmp = y * z elif z <= 1.4e-73: tmp = y elif z <= 12000000.0: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -180.0) tmp = Float64(y * z); elseif (z <= 1.4e-73) tmp = y; elseif (z <= 12000000.0) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -180.0) tmp = y * z; elseif (z <= 1.4e-73) tmp = y; elseif (z <= 12000000.0) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -180.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.4e-73], y, If[LessEqual[z, 12000000.0], x, N[(y * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -180:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-73}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 12000000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -180 or 1.2e7 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 53.3%
Taylor expanded in z around inf 52.4%
if -180 < z < 1.40000000000000006e-73Initial program 100.0%
Taylor expanded in x around 0 55.7%
Taylor expanded in z around 0 53.7%
if 1.40000000000000006e-73 < z < 1.2e7Initial program 99.9%
Taylor expanded in x around inf 41.2%
Taylor expanded in z around 0 37.0%
Final simplification51.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.0) (not (<= z 1.0))) (* z (+ x y)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
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 <= 1.0d0))) then
tmp = z * (x + y)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.0) || !(z <= 1.0)) {
tmp = z * (x + y);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.0) or not (z <= 1.0): tmp = z * (x + y) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.0) || !(z <= 1.0)) tmp = Float64(z * Float64(x + y)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.0) || ~((z <= 1.0))) tmp = z * (x + y); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.0], N[Not[LessEqual[z, 1.0]], $MachinePrecision]], N[(z * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \lor \neg \left(z \leq 1\right):\\
\;\;\;\;z \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
Taylor expanded in z around inf 97.4%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.9%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.6e-94) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.6e-94) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
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 (y <= 1.6d-94) then
tmp = x * (z + 1.0d0)
else
tmp = y * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.6e-94) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.6e-94: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.6e-94) tmp = Float64(x * Float64(z + 1.0)); else tmp = Float64(y * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.6e-94) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.6e-94], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.6 \cdot 10^{-94}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 1.59999999999999998e-94Initial program 100.0%
Taylor expanded in x around inf 56.7%
if 1.59999999999999998e-94 < y Initial program 100.0%
Taylor expanded in x around 0 76.5%
Final simplification62.9%
(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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= y 3.1e-170) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 3.1e-170) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
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 (y <= 3.1d-170) then
tmp = x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 3.1e-170) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 3.1e-170: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 3.1e-170) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 3.1e-170) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 3.1e-170], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 3.1 \cdot 10^{-170}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 3.09999999999999986e-170Initial program 100.0%
Taylor expanded in x around inf 54.9%
Taylor expanded in z around 0 28.1%
if 3.09999999999999986e-170 < y Initial program 100.0%
Taylor expanded in x around 0 68.1%
Taylor expanded in z around 0 39.6%
Final simplification32.4%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in x around inf 48.0%
Taylor expanded in z around 0 23.8%
Final simplification23.8%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))