
(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 -310.0)
(* y z)
(if (<= z -9.7e-195)
y
(if (<= z -2.75e-260)
x
(if (<= z 3.9e-231)
y
(if (<= z 3.6e-172)
x
(if (<= z 1.2e-130) y (if (<= z 64.0) x (* y z)))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -310.0) {
tmp = y * z;
} else if (z <= -9.7e-195) {
tmp = y;
} else if (z <= -2.75e-260) {
tmp = x;
} else if (z <= 3.9e-231) {
tmp = y;
} else if (z <= 3.6e-172) {
tmp = x;
} else if (z <= 1.2e-130) {
tmp = y;
} else if (z <= 64.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 <= (-310.0d0)) then
tmp = y * z
else if (z <= (-9.7d-195)) then
tmp = y
else if (z <= (-2.75d-260)) then
tmp = x
else if (z <= 3.9d-231) then
tmp = y
else if (z <= 3.6d-172) then
tmp = x
else if (z <= 1.2d-130) then
tmp = y
else if (z <= 64.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 <= -310.0) {
tmp = y * z;
} else if (z <= -9.7e-195) {
tmp = y;
} else if (z <= -2.75e-260) {
tmp = x;
} else if (z <= 3.9e-231) {
tmp = y;
} else if (z <= 3.6e-172) {
tmp = x;
} else if (z <= 1.2e-130) {
tmp = y;
} else if (z <= 64.0) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -310.0: tmp = y * z elif z <= -9.7e-195: tmp = y elif z <= -2.75e-260: tmp = x elif z <= 3.9e-231: tmp = y elif z <= 3.6e-172: tmp = x elif z <= 1.2e-130: tmp = y elif z <= 64.0: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -310.0) tmp = Float64(y * z); elseif (z <= -9.7e-195) tmp = y; elseif (z <= -2.75e-260) tmp = x; elseif (z <= 3.9e-231) tmp = y; elseif (z <= 3.6e-172) tmp = x; elseif (z <= 1.2e-130) tmp = y; elseif (z <= 64.0) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -310.0) tmp = y * z; elseif (z <= -9.7e-195) tmp = y; elseif (z <= -2.75e-260) tmp = x; elseif (z <= 3.9e-231) tmp = y; elseif (z <= 3.6e-172) tmp = x; elseif (z <= 1.2e-130) tmp = y; elseif (z <= 64.0) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -310.0], N[(y * z), $MachinePrecision], If[LessEqual[z, -9.7e-195], y, If[LessEqual[z, -2.75e-260], x, If[LessEqual[z, 3.9e-231], y, If[LessEqual[z, 3.6e-172], x, If[LessEqual[z, 1.2e-130], y, If[LessEqual[z, 64.0], x, N[(y * z), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -310:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq -9.7 \cdot 10^{-195}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq -2.75 \cdot 10^{-260}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{-231}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{-172}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{-130}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 64:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -310 or 64 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 48.4%
Taylor expanded in z around inf 46.7%
if -310 < z < -9.70000000000000019e-195 or -2.75000000000000012e-260 < z < 3.8999999999999998e-231 or 3.60000000000000015e-172 < z < 1.19999999999999998e-130Initial program 100.0%
Taylor expanded in x around 0 50.0%
Taylor expanded in z around 0 50.0%
if -9.70000000000000019e-195 < z < -2.75000000000000012e-260 or 3.8999999999999998e-231 < z < 3.60000000000000015e-172 or 1.19999999999999998e-130 < z < 64Initial program 100.0%
Taylor expanded in x around inf 54.4%
Taylor expanded in z around 0 54.1%
Final simplification49.4%
(FPCore (x y z) :precision binary64 (if (<= y 1.3e-138) (* x (+ z 1.0)) (if (or (<= y 8.2e-58) (not (<= y 4.5e+23))) (* y (+ z 1.0)) (+ x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 1.3e-138) {
tmp = x * (z + 1.0);
} else if ((y <= 8.2e-58) || !(y <= 4.5e+23)) {
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 (y <= 1.3d-138) then
tmp = x * (z + 1.0d0)
else if ((y <= 8.2d-58) .or. (.not. (y <= 4.5d+23))) 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 (y <= 1.3e-138) {
tmp = x * (z + 1.0);
} else if ((y <= 8.2e-58) || !(y <= 4.5e+23)) {
tmp = y * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 1.3e-138: tmp = x * (z + 1.0) elif (y <= 8.2e-58) or not (y <= 4.5e+23): tmp = y * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 1.3e-138) tmp = Float64(x * Float64(z + 1.0)); elseif ((y <= 8.2e-58) || !(y <= 4.5e+23)) 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 (y <= 1.3e-138) tmp = x * (z + 1.0); elseif ((y <= 8.2e-58) || ~((y <= 4.5e+23))) tmp = y * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 1.3e-138], N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 8.2e-58], N[Not[LessEqual[y, 4.5e+23]], $MachinePrecision]], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.3 \cdot 10^{-138}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{elif}\;y \leq 8.2 \cdot 10^{-58} \lor \neg \left(y \leq 4.5 \cdot 10^{+23}\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < 1.3e-138Initial program 100.0%
Taylor expanded in x around inf 59.5%
if 1.3e-138 < y < 8.20000000000000056e-58 or 4.49999999999999979e23 < y Initial program 100.0%
Taylor expanded in x around 0 66.0%
if 8.20000000000000056e-58 < y < 4.49999999999999979e23Initial program 100.0%
Taylor expanded in z around 0 70.9%
Final simplification62.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.4e-16) (not (<= z 36.0))) (* y (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.4e-16) || !(z <= 36.0)) {
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 <= (-2.4d-16)) .or. (.not. (z <= 36.0d0))) 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 <= -2.4e-16) || !(z <= 36.0)) {
tmp = y * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.4e-16) or not (z <= 36.0): tmp = y * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.4e-16) || !(z <= 36.0)) 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 <= -2.4e-16) || ~((z <= 36.0))) tmp = y * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.4e-16], N[Not[LessEqual[z, 36.0]], $MachinePrecision]], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-16} \lor \neg \left(z \leq 36\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.40000000000000005e-16 or 36 < z Initial program 100.0%
Taylor expanded in x around 0 48.5%
if -2.40000000000000005e-16 < z < 36Initial program 100.0%
Taylor expanded in z around 0 99.2%
Final simplification76.4%
(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 95.5%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 99.8%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (<= y 6.5e-52) x (if (<= y 3500000.0) y (if (<= y 6.8e+52) x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= 6.5e-52) {
tmp = x;
} else if (y <= 3500000.0) {
tmp = y;
} else if (y <= 6.8e+52) {
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 <= 6.5d-52) then
tmp = x
else if (y <= 3500000.0d0) then
tmp = y
else if (y <= 6.8d+52) 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 <= 6.5e-52) {
tmp = x;
} else if (y <= 3500000.0) {
tmp = y;
} else if (y <= 6.8e+52) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 6.5e-52: tmp = x elif y <= 3500000.0: tmp = y elif y <= 6.8e+52: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 6.5e-52) tmp = x; elseif (y <= 3500000.0) tmp = y; elseif (y <= 6.8e+52) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 6.5e-52) tmp = x; elseif (y <= 3500000.0) tmp = y; elseif (y <= 6.8e+52) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 6.5e-52], x, If[LessEqual[y, 3500000.0], y, If[LessEqual[y, 6.8e+52], x, y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 6.5 \cdot 10^{-52}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3500000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{+52}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < 6.5e-52 or 3.5e6 < y < 6.8e52Initial program 100.0%
Taylor expanded in x around inf 60.5%
Taylor expanded in z around 0 32.7%
if 6.5e-52 < y < 3.5e6 or 6.8e52 < y Initial program 100.0%
Taylor expanded in x around 0 68.7%
Taylor expanded in z around 0 42.3%
Final simplification35.3%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 115.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 <= 115.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 <= 115.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 <= 115.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 <= 115.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 <= 115.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 <= 115.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, 115.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 115:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 115 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 48.0%
Taylor expanded in z around inf 46.3%
if -1 < z < 115Initial program 100.0%
Taylor expanded in z around 0 99.2%
Final simplification75.7%
(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 54.6%
Taylor expanded in z around 0 30.2%
Final simplification30.2%
herbie shell --seed 2023238
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))