
(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}
(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 -1.0)
(* y z)
(if (<= z -2.05e-82)
x
(if (<= z -1.8e-178)
y
(if (<= z 4.3e-266)
x
(if (<= z 1.2e-248)
y
(if (<= z 2.3e-96) x (if (<= z 1.0) y (* y z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= -2.05e-82) {
tmp = x;
} else if (z <= -1.8e-178) {
tmp = y;
} else if (z <= 4.3e-266) {
tmp = x;
} else if (z <= 1.2e-248) {
tmp = y;
} else if (z <= 2.3e-96) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} 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 <= (-1.0d0)) then
tmp = y * z
else if (z <= (-2.05d-82)) then
tmp = x
else if (z <= (-1.8d-178)) then
tmp = y
else if (z <= 4.3d-266) then
tmp = x
else if (z <= 1.2d-248) then
tmp = y
else if (z <= 2.3d-96) then
tmp = x
else if (z <= 1.0d0) then
tmp = y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= -2.05e-82) {
tmp = x;
} else if (z <= -1.8e-178) {
tmp = y;
} else if (z <= 4.3e-266) {
tmp = x;
} else if (z <= 1.2e-248) {
tmp = y;
} else if (z <= 2.3e-96) {
tmp = x;
} else if (z <= 1.0) {
tmp = y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= -2.05e-82: tmp = x elif z <= -1.8e-178: tmp = y elif z <= 4.3e-266: tmp = x elif z <= 1.2e-248: tmp = y elif z <= 2.3e-96: tmp = x elif z <= 1.0: tmp = y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= -2.05e-82) tmp = x; elseif (z <= -1.8e-178) tmp = y; elseif (z <= 4.3e-266) tmp = x; elseif (z <= 1.2e-248) tmp = y; elseif (z <= 2.3e-96) tmp = x; elseif (z <= 1.0) tmp = y; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = y * z; elseif (z <= -2.05e-82) tmp = x; elseif (z <= -1.8e-178) tmp = y; elseif (z <= 4.3e-266) tmp = x; elseif (z <= 1.2e-248) tmp = y; elseif (z <= 2.3e-96) tmp = x; elseif (z <= 1.0) tmp = y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -2.05e-82], x, If[LessEqual[z, -1.8e-178], y, If[LessEqual[z, 4.3e-266], x, If[LessEqual[z, 1.2e-248], y, If[LessEqual[z, 2.3e-96], x, If[LessEqual[z, 1.0], y, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -2.05 \cdot 10^{-82}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq -1.8 \cdot 10^{-178}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 4.3 \cdot 10^{-266}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-248}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-96}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 49.2%
Taylor expanded in z around inf 48.0%
if -1 < z < -2.04999999999999998e-82 or -1.79999999999999997e-178 < z < 4.30000000000000028e-266 or 1.20000000000000002e-248 < z < 2.3e-96Initial program 100.0%
Taylor expanded in x around inf 48.9%
Taylor expanded in z around 0 48.8%
if -2.04999999999999998e-82 < z < -1.79999999999999997e-178 or 4.30000000000000028e-266 < z < 1.20000000000000002e-248 or 2.3e-96 < z < 1Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 54.7%
Taylor expanded in z around 0 54.0%
Final simplification49.5%
(FPCore (x y z) :precision binary64 (if (or (<= x -4e+28) (and (not (<= x -11.8)) (<= x -4.5e-38))) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4e+28) || (!(x <= -11.8) && (x <= -4.5e-38))) {
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 ((x <= (-4d+28)) .or. (.not. (x <= (-11.8d0))) .and. (x <= (-4.5d-38))) 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 ((x <= -4e+28) || (!(x <= -11.8) && (x <= -4.5e-38))) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4e+28) or (not (x <= -11.8) and (x <= -4.5e-38)): tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4e+28) || (!(x <= -11.8) && (x <= -4.5e-38))) 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 ((x <= -4e+28) || (~((x <= -11.8)) && (x <= -4.5e-38))) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4e+28], And[N[Not[LessEqual[x, -11.8]], $MachinePrecision], LessEqual[x, -4.5e-38]]], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4 \cdot 10^{+28} \lor \neg \left(x \leq -11.8\right) \land x \leq -4.5 \cdot 10^{-38}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -3.99999999999999983e28 or -11.800000000000001 < x < -4.50000000000000009e-38Initial program 100.0%
Taylor expanded in x around inf 79.6%
if -3.99999999999999983e28 < x < -11.800000000000001 or -4.50000000000000009e-38 < x Initial program 100.0%
Taylor expanded in x around 0 58.8%
Final simplification64.0%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.45e-5) (not (<= z 2.45e-5))) (* y (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e-5) || !(z <= 2.45e-5)) {
tmp = y * (z + 1.0);
} 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.45d-5)) .or. (.not. (z <= 2.45d-5))) then
tmp = y * (z + 1.0d0)
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.45e-5) || !(z <= 2.45e-5)) {
tmp = y * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.45e-5) or not (z <= 2.45e-5): tmp = y * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e-5) || !(z <= 2.45e-5)) tmp = Float64(y * Float64(z + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.45e-5) || ~((z <= 2.45e-5))) tmp = y * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e-5], N[Not[LessEqual[z, 2.45e-5]], $MachinePrecision]], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{-5} \lor \neg \left(z \leq 2.45 \cdot 10^{-5}\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -1.45e-5 or 2.45e-5 < z Initial program 100.0%
Taylor expanded in x around 0 48.8%
if -1.45e-5 < z < 2.45e-5Initial program 100.0%
Taylor expanded in z around 0 99.2%
Final simplification75.0%
(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%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.6%
Final simplification98.2%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 1750.0) (+ x y) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1750.0) {
tmp = x + y;
} 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 <= (-1.0d0)) then
tmp = y * z
else if (z <= 1750.0d0) then
tmp = x + y
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 1750.0) {
tmp = x + y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.0: tmp = y * z elif z <= 1750.0: tmp = x + y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.0) tmp = Float64(y * z); elseif (z <= 1750.0) tmp = Float64(x + y); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.0) tmp = y * z; elseif (z <= 1750.0) tmp = x + y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 1750.0], N[(x + y), $MachinePrecision], N[(y * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1750:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 1750 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 49.5%
Taylor expanded in z around inf 48.8%
if -1 < z < 1750Initial program 100.0%
Taylor expanded in z around 0 96.8%
Final simplification74.5%
(FPCore (x y z) :precision binary64 (if (<= x -9.2e-97) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -9.2e-97) {
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 (x <= (-9.2d-97)) 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 (x <= -9.2e-97) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -9.2e-97: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -9.2e-97) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -9.2e-97) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -9.2e-97], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.2 \cdot 10^{-97}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.19999999999999976e-97Initial program 100.0%
Taylor expanded in x around inf 68.2%
Taylor expanded in z around 0 35.5%
if -9.19999999999999976e-97 < x Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 57.0%
Taylor expanded in z around 0 33.5%
Final simplification34.1%
(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 52.3%
Taylor expanded in z around 0 26.0%
Final simplification26.0%
herbie shell --seed 2023230
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))