
(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}
(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 (<= z -4.6e+268)
(* y z)
(if (<= z -1.15e+184)
(* x z)
(if (<= z -7.5e+114)
(* y z)
(if (<= z -9e+89)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 5600.0)
(+ x y)
(if (or (<= z 2.7e+140) (not (<= z 4.9e+204)))
(* y z)
(* x (+ z 1.0))))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+268) {
tmp = y * z;
} else if (z <= -1.15e+184) {
tmp = x * z;
} else if (z <= -7.5e+114) {
tmp = y * z;
} else if (z <= -9e+89) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 5600.0) {
tmp = x + y;
} else if ((z <= 2.7e+140) || !(z <= 4.9e+204)) {
tmp = y * z;
} else {
tmp = x * (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 (z <= (-4.6d+268)) then
tmp = y * z
else if (z <= (-1.15d+184)) then
tmp = x * z
else if (z <= (-7.5d+114)) then
tmp = y * z
else if (z <= (-9d+89)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 5600.0d0) then
tmp = x + y
else if ((z <= 2.7d+140) .or. (.not. (z <= 4.9d+204))) then
tmp = y * z
else
tmp = x * (z + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -4.6e+268) {
tmp = y * z;
} else if (z <= -1.15e+184) {
tmp = x * z;
} else if (z <= -7.5e+114) {
tmp = y * z;
} else if (z <= -9e+89) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 5600.0) {
tmp = x + y;
} else if ((z <= 2.7e+140) || !(z <= 4.9e+204)) {
tmp = y * z;
} else {
tmp = x * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4.6e+268: tmp = y * z elif z <= -1.15e+184: tmp = x * z elif z <= -7.5e+114: tmp = y * z elif z <= -9e+89: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 5600.0: tmp = x + y elif (z <= 2.7e+140) or not (z <= 4.9e+204): tmp = y * z else: tmp = x * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4.6e+268) tmp = Float64(y * z); elseif (z <= -1.15e+184) tmp = Float64(x * z); elseif (z <= -7.5e+114) tmp = Float64(y * z); elseif (z <= -9e+89) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 5600.0) tmp = Float64(x + y); elseif ((z <= 2.7e+140) || !(z <= 4.9e+204)) tmp = Float64(y * z); else tmp = Float64(x * Float64(z + 1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -4.6e+268) tmp = y * z; elseif (z <= -1.15e+184) tmp = x * z; elseif (z <= -7.5e+114) tmp = y * z; elseif (z <= -9e+89) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 5600.0) tmp = x + y; elseif ((z <= 2.7e+140) || ~((z <= 4.9e+204))) tmp = y * z; else tmp = x * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4.6e+268], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.15e+184], N[(x * z), $MachinePrecision], If[LessEqual[z, -7.5e+114], N[(y * z), $MachinePrecision], If[LessEqual[z, -9e+89], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 5600.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 2.7e+140], N[Not[LessEqual[z, 4.9e+204]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.6 \cdot 10^{+268}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.15 \cdot 10^{+184}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -7.5 \cdot 10^{+114}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -9 \cdot 10^{+89}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5600:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.7 \cdot 10^{+140} \lor \neg \left(z \leq 4.9 \cdot 10^{+204}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if z < -4.60000000000000024e268 or -1.15e184 < z < -7.5000000000000001e114 or -9e89 < z < -1 or 5600 < z < 2.70000000000000018e140 or 4.8999999999999997e204 < z Initial program 100.0%
Taylor expanded in z around inf 97.0%
+-commutative97.0%
Simplified97.0%
distribute-lft-in94.4%
Applied egg-rr94.4%
Taylor expanded in y around inf 48.2%
*-commutative48.2%
Simplified48.2%
if -4.60000000000000024e268 < z < -1.15e184 or -7.5000000000000001e114 < z < -9e89Initial program 99.9%
Taylor expanded in z around inf 99.9%
+-commutative99.9%
Simplified99.9%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 46.8%
*-commutative46.8%
Simplified46.8%
if -1 < z < 5600Initial program 100.0%
Taylor expanded in z around 0 96.8%
+-commutative96.8%
Simplified96.8%
if 2.70000000000000018e140 < z < 4.8999999999999997e204Initial program 100.0%
Taylor expanded in x around inf 59.3%
Final simplification74.2%
(FPCore (x y z)
:precision binary64
(if (<= z -4e+270)
(* y z)
(if (<= z -6.7e+182)
(* x z)
(if (<= z -5.9e+113)
(* y z)
(if (<= z -1.4e+89)
(* x z)
(if (<= z -1.0)
(* y z)
(if (<= z 5600.0)
(+ x y)
(if (or (<= z 1.2e+138) (not (<= z 1.16e+207)))
(* y z)
(* x z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -4e+270) {
tmp = y * z;
} else if (z <= -6.7e+182) {
tmp = x * z;
} else if (z <= -5.9e+113) {
tmp = y * z;
} else if (z <= -1.4e+89) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 5600.0) {
tmp = x + y;
} else if ((z <= 1.2e+138) || !(z <= 1.16e+207)) {
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 <= (-4d+270)) then
tmp = y * z
else if (z <= (-6.7d+182)) then
tmp = x * z
else if (z <= (-5.9d+113)) then
tmp = y * z
else if (z <= (-1.4d+89)) then
tmp = x * z
else if (z <= (-1.0d0)) then
tmp = y * z
else if (z <= 5600.0d0) then
tmp = x + y
else if ((z <= 1.2d+138) .or. (.not. (z <= 1.16d+207))) 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 <= -4e+270) {
tmp = y * z;
} else if (z <= -6.7e+182) {
tmp = x * z;
} else if (z <= -5.9e+113) {
tmp = y * z;
} else if (z <= -1.4e+89) {
tmp = x * z;
} else if (z <= -1.0) {
tmp = y * z;
} else if (z <= 5600.0) {
tmp = x + y;
} else if ((z <= 1.2e+138) || !(z <= 1.16e+207)) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -4e+270: tmp = y * z elif z <= -6.7e+182: tmp = x * z elif z <= -5.9e+113: tmp = y * z elif z <= -1.4e+89: tmp = x * z elif z <= -1.0: tmp = y * z elif z <= 5600.0: tmp = x + y elif (z <= 1.2e+138) or not (z <= 1.16e+207): tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -4e+270) tmp = Float64(y * z); elseif (z <= -6.7e+182) tmp = Float64(x * z); elseif (z <= -5.9e+113) tmp = Float64(y * z); elseif (z <= -1.4e+89) tmp = Float64(x * z); elseif (z <= -1.0) tmp = Float64(y * z); elseif (z <= 5600.0) tmp = Float64(x + y); elseif ((z <= 1.2e+138) || !(z <= 1.16e+207)) 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 <= -4e+270) tmp = y * z; elseif (z <= -6.7e+182) tmp = x * z; elseif (z <= -5.9e+113) tmp = y * z; elseif (z <= -1.4e+89) tmp = x * z; elseif (z <= -1.0) tmp = y * z; elseif (z <= 5600.0) tmp = x + y; elseif ((z <= 1.2e+138) || ~((z <= 1.16e+207))) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -4e+270], N[(y * z), $MachinePrecision], If[LessEqual[z, -6.7e+182], N[(x * z), $MachinePrecision], If[LessEqual[z, -5.9e+113], N[(y * z), $MachinePrecision], If[LessEqual[z, -1.4e+89], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 5600.0], N[(x + y), $MachinePrecision], If[Or[LessEqual[z, 1.2e+138], N[Not[LessEqual[z, 1.16e+207]], $MachinePrecision]], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4 \cdot 10^{+270}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -6.7 \cdot 10^{+182}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -5.9 \cdot 10^{+113}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -1.4 \cdot 10^{+89}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 5600:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+138} \lor \neg \left(z \leq 1.16 \cdot 10^{+207}\right):\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -4.0000000000000002e270 or -6.7000000000000006e182 < z < -5.90000000000000023e113 or -1.3999999999999999e89 < z < -1 or 5600 < z < 1.2e138 or 1.16e207 < z Initial program 100.0%
Taylor expanded in z around inf 97.0%
+-commutative97.0%
Simplified97.0%
distribute-lft-in94.4%
Applied egg-rr94.4%
Taylor expanded in y around inf 48.2%
*-commutative48.2%
Simplified48.2%
if -4.0000000000000002e270 < z < -6.7000000000000006e182 or -5.90000000000000023e113 < z < -1.3999999999999999e89 or 1.2e138 < z < 1.16e207Initial program 100.0%
Taylor expanded in z around inf 100.0%
+-commutative100.0%
Simplified100.0%
distribute-lft-in100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 53.2%
*-commutative53.2%
Simplified53.2%
if -1 < z < 5600Initial program 100.0%
Taylor expanded in z around 0 96.8%
+-commutative96.8%
Simplified96.8%
Final simplification74.2%
(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.6%
+-commutative97.6%
Simplified97.6%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 97.5%
+-commutative97.5%
Simplified97.5%
Final simplification97.6%
(FPCore (x y z) :precision binary64 (if (<= y 1.45e-127) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.45e-127) {
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.45d-127) 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.45e-127) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.45e-127: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.45e-127) 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.45e-127) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.45e-127], 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.45 \cdot 10^{-127}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if y < 1.45e-127Initial program 100.0%
Taylor expanded in x around inf 60.2%
if 1.45e-127 < y Initial program 100.0%
Taylor expanded in x around 0 72.9%
Final simplification64.8%
(FPCore (x y z) :precision binary64 (if (<= y 1.65e-165) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.65e-165) {
tmp = x * z;
} 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 (y <= 1.65d-165) then
tmp = x * z
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= 1.65e-165) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.65e-165: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.65e-165) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 1.65e-165) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.65e-165], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.65 \cdot 10^{-165}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if y < 1.6499999999999999e-165Initial program 100.0%
Taylor expanded in z around inf 48.0%
+-commutative48.0%
Simplified48.0%
distribute-lft-in46.7%
Applied egg-rr46.7%
Taylor expanded in y around 0 32.6%
*-commutative32.6%
Simplified32.6%
if 1.6499999999999999e-165 < y Initial program 100.0%
Taylor expanded in z around inf 52.0%
+-commutative52.0%
Simplified52.0%
distribute-lft-in52.0%
Applied egg-rr52.0%
Taylor expanded in y around inf 35.9%
*-commutative35.9%
Simplified35.9%
Final simplification34.0%
(FPCore (x y z) :precision binary64 (* x z))
double code(double x, double y, double z) {
return x * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x * z
end function
public static double code(double x, double y, double z) {
return x * z;
}
def code(x, y, z): return x * z
function code(x, y, z) return Float64(x * z) end
function tmp = code(x, y, z) tmp = x * z; end
code[x_, y_, z_] := N[(x * z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 49.6%
+-commutative49.6%
Simplified49.6%
distribute-lft-in48.9%
Applied egg-rr48.9%
Taylor expanded in y around 0 28.4%
*-commutative28.4%
Simplified28.4%
Final simplification28.4%
herbie shell --seed 2023322
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))