
(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 -195000000000.0)
(* y z)
(if (<= z 7.5e-263)
y
(if (<= z 1.6e-189)
x
(if (<= z 2.3e-158)
y
(if (<= z 1.15e-104) x (if (<= z 1.12e-7) y (* y z))))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -195000000000.0) {
tmp = y * z;
} else if (z <= 7.5e-263) {
tmp = y;
} else if (z <= 1.6e-189) {
tmp = x;
} else if (z <= 2.3e-158) {
tmp = y;
} else if (z <= 1.15e-104) {
tmp = x;
} else if (z <= 1.12e-7) {
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 <= (-195000000000.0d0)) then
tmp = y * z
else if (z <= 7.5d-263) then
tmp = y
else if (z <= 1.6d-189) then
tmp = x
else if (z <= 2.3d-158) then
tmp = y
else if (z <= 1.15d-104) then
tmp = x
else if (z <= 1.12d-7) 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 <= -195000000000.0) {
tmp = y * z;
} else if (z <= 7.5e-263) {
tmp = y;
} else if (z <= 1.6e-189) {
tmp = x;
} else if (z <= 2.3e-158) {
tmp = y;
} else if (z <= 1.15e-104) {
tmp = x;
} else if (z <= 1.12e-7) {
tmp = y;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -195000000000.0: tmp = y * z elif z <= 7.5e-263: tmp = y elif z <= 1.6e-189: tmp = x elif z <= 2.3e-158: tmp = y elif z <= 1.15e-104: tmp = x elif z <= 1.12e-7: tmp = y else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -195000000000.0) tmp = Float64(y * z); elseif (z <= 7.5e-263) tmp = y; elseif (z <= 1.6e-189) tmp = x; elseif (z <= 2.3e-158) tmp = y; elseif (z <= 1.15e-104) tmp = x; elseif (z <= 1.12e-7) tmp = y; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -195000000000.0) tmp = y * z; elseif (z <= 7.5e-263) tmp = y; elseif (z <= 1.6e-189) tmp = x; elseif (z <= 2.3e-158) tmp = y; elseif (z <= 1.15e-104) tmp = x; elseif (z <= 1.12e-7) tmp = y; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -195000000000.0], N[(y * z), $MachinePrecision], If[LessEqual[z, 7.5e-263], y, If[LessEqual[z, 1.6e-189], x, If[LessEqual[z, 2.3e-158], y, If[LessEqual[z, 1.15e-104], x, If[LessEqual[z, 1.12e-7], y, N[(y * z), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -195000000000:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 7.5 \cdot 10^{-263}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1.6 \cdot 10^{-189}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-158}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{-104}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.12 \cdot 10^{-7}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1.95e11 or 1.12e-7 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 54.2%
Taylor expanded in z around inf 53.1%
if -1.95e11 < z < 7.50000000000000044e-263 or 1.6e-189 < z < 2.2999999999999999e-158 or 1.15e-104 < z < 1.12e-7Initial program 100.0%
Taylor expanded in x around 0 55.7%
Taylor expanded in z around 0 53.1%
if 7.50000000000000044e-263 < z < 1.6e-189 or 2.2999999999999999e-158 < z < 1.15e-104Initial program 100.0%
Taylor expanded in x around inf 42.2%
Taylor expanded in z around 0 42.2%
Final simplification51.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-11) (not (<= z 2.5e+24))) (* y (+ z 1.0)) (+ x y)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-11) || !(z <= 2.5e+24)) {
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.6d-11)) .or. (.not. (z <= 2.5d+24))) 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.6e-11) || !(z <= 2.5e+24)) {
tmp = y * (z + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-11) or not (z <= 2.5e+24): tmp = y * (z + 1.0) else: tmp = x + y return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-11) || !(z <= 2.5e+24)) 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.6e-11) || ~((z <= 2.5e+24))) tmp = y * (z + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-11], N[Not[LessEqual[z, 2.5e+24]], $MachinePrecision]], N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{-11} \lor \neg \left(z \leq 2.5 \cdot 10^{+24}\right):\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if z < -2.6000000000000001e-11 or 2.50000000000000023e24 < z Initial program 100.0%
Taylor expanded in x around 0 54.8%
if -2.6000000000000001e-11 < z < 2.50000000000000023e24Initial program 100.0%
Taylor expanded in z around 0 95.8%
Final simplification76.6%
(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 99.1%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 98.2%
Final simplification98.6%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 2.5e+24) (+ x y) (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = y * z;
} else if (z <= 2.5e+24) {
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 <= 2.5d+24) 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 <= 2.5e+24) {
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 <= 2.5e+24: 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 <= 2.5e+24) 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 <= 2.5e+24) 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, 2.5e+24], 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 2.5 \cdot 10^{+24}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 2.50000000000000023e24 < z Initial program 100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 54.4%
Taylor expanded in z around inf 53.9%
if -1 < z < 2.50000000000000023e24Initial program 100.0%
Taylor expanded in z around 0 95.6%
Final simplification76.2%
(FPCore (x y z) :precision binary64 (if (<= x -3.2e-34) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.2e-34) {
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 <= (-3.2d-34)) 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 <= -3.2e-34) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.2e-34: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.2e-34) 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 <= -3.2e-34) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.2e-34], 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 -3.2 \cdot 10^{-34}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -3.20000000000000003e-34Initial program 100.0%
Taylor expanded in x around inf 74.1%
if -3.20000000000000003e-34 < x Initial program 100.0%
Taylor expanded in x around 0 64.2%
Final simplification67.0%
(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 (<= x -4.6e-40) x y))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.6e-40) {
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 <= (-4.6d-40)) 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 <= -4.6e-40) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.6e-40: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.6e-40) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.6e-40) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.6e-40], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.6 \cdot 10^{-40}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.6e-40Initial program 100.0%
Taylor expanded in x around inf 73.1%
Taylor expanded in z around 0 39.8%
if -4.6e-40 < x Initial program 100.0%
Taylor expanded in x around 0 64.0%
Taylor expanded in z around 0 34.5%
Final simplification36.0%
(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 49.4%
Taylor expanded in z around 0 24.6%
Final simplification24.6%
herbie shell --seed 2023278
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))