
(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 10 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}
(FPCore (x y z)
:precision binary64
(if (<= z -1.95e-5)
(* x z)
(if (<= z -1.2e-276)
x
(if (<= z 3.9e-106)
y
(if (<= z 1500000.0) x (if (<= z 1.2e+214) (* y z) (* x z)))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e-5) {
tmp = x * z;
} else if (z <= -1.2e-276) {
tmp = x;
} else if (z <= 3.9e-106) {
tmp = y;
} else if (z <= 1500000.0) {
tmp = x;
} else if (z <= 1.2e+214) {
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.95d-5)) then
tmp = x * z
else if (z <= (-1.2d-276)) then
tmp = x
else if (z <= 3.9d-106) then
tmp = y
else if (z <= 1500000.0d0) then
tmp = x
else if (z <= 1.2d+214) 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.95e-5) {
tmp = x * z;
} else if (z <= -1.2e-276) {
tmp = x;
} else if (z <= 3.9e-106) {
tmp = y;
} else if (z <= 1500000.0) {
tmp = x;
} else if (z <= 1.2e+214) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e-5: tmp = x * z elif z <= -1.2e-276: tmp = x elif z <= 3.9e-106: tmp = y elif z <= 1500000.0: tmp = x elif z <= 1.2e+214: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e-5) tmp = Float64(x * z); elseif (z <= -1.2e-276) tmp = x; elseif (z <= 3.9e-106) tmp = y; elseif (z <= 1500000.0) tmp = x; elseif (z <= 1.2e+214) 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.95e-5) tmp = x * z; elseif (z <= -1.2e-276) tmp = x; elseif (z <= 3.9e-106) tmp = y; elseif (z <= 1500000.0) tmp = x; elseif (z <= 1.2e+214) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e-5], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.2e-276], x, If[LessEqual[z, 3.9e-106], y, If[LessEqual[z, 1500000.0], x, If[LessEqual[z, 1.2e+214], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-5}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1.2 \cdot 10^{-276}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{-106}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1500000:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.2 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -1.95e-5) (* x z) (if (<= z -1.3e-275) x (if (<= z 6.2e-106) y (if (<= z 1.0) x (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.95e-5) {
tmp = x * z;
} else if (z <= -1.3e-275) {
tmp = x;
} else if (z <= 6.2e-106) {
tmp = y;
} else if (z <= 1.0) {
tmp = x;
} 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.95d-5)) then
tmp = x * z
else if (z <= (-1.3d-275)) then
tmp = x
else if (z <= 6.2d-106) then
tmp = y
else if (z <= 1.0d0) then
tmp = x
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.95e-5) {
tmp = x * z;
} else if (z <= -1.3e-275) {
tmp = x;
} else if (z <= 6.2e-106) {
tmp = y;
} else if (z <= 1.0) {
tmp = x;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.95e-5: tmp = x * z elif z <= -1.3e-275: tmp = x elif z <= 6.2e-106: tmp = y elif z <= 1.0: tmp = x else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.95e-5) tmp = Float64(x * z); elseif (z <= -1.3e-275) tmp = x; elseif (z <= 6.2e-106) tmp = y; elseif (z <= 1.0) tmp = x; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.95e-5) tmp = x * z; elseif (z <= -1.3e-275) tmp = x; elseif (z <= 6.2e-106) tmp = y; elseif (z <= 1.0) tmp = x; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.95e-5], N[(x * z), $MachinePrecision], If[LessEqual[z, -1.3e-275], x, If[LessEqual[z, 6.2e-106], y, If[LessEqual[z, 1.0], x, N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-5}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -1.3 \cdot 10^{-275}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-106}:\\
\;\;\;\;y\\
\mathbf{elif}\;z \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (+ z 1.0))))
(if (<= z -0.00082)
t_0
(if (<= z 8.5e-9)
(+ x y)
(if (<= z 2.5e+150) t_0 (if (<= z 3.9e+214) (* y z) (* x z)))))))
double code(double x, double y, double z) {
double t_0 = x * (z + 1.0);
double tmp;
if (z <= -0.00082) {
tmp = t_0;
} else if (z <= 8.5e-9) {
tmp = x + y;
} else if (z <= 2.5e+150) {
tmp = t_0;
} else if (z <= 3.9e+214) {
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) :: t_0
real(8) :: tmp
t_0 = x * (z + 1.0d0)
if (z <= (-0.00082d0)) then
tmp = t_0
else if (z <= 8.5d-9) then
tmp = x + y
else if (z <= 2.5d+150) then
tmp = t_0
else if (z <= 3.9d+214) 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 t_0 = x * (z + 1.0);
double tmp;
if (z <= -0.00082) {
tmp = t_0;
} else if (z <= 8.5e-9) {
tmp = x + y;
} else if (z <= 2.5e+150) {
tmp = t_0;
} else if (z <= 3.9e+214) {
tmp = y * z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): t_0 = x * (z + 1.0) tmp = 0 if z <= -0.00082: tmp = t_0 elif z <= 8.5e-9: tmp = x + y elif z <= 2.5e+150: tmp = t_0 elif z <= 3.9e+214: tmp = y * z else: tmp = x * z return tmp
function code(x, y, z) t_0 = Float64(x * Float64(z + 1.0)) tmp = 0.0 if (z <= -0.00082) tmp = t_0; elseif (z <= 8.5e-9) tmp = Float64(x + y); elseif (z <= 2.5e+150) tmp = t_0; elseif (z <= 3.9e+214) tmp = Float64(y * z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * (z + 1.0); tmp = 0.0; if (z <= -0.00082) tmp = t_0; elseif (z <= 8.5e-9) tmp = x + y; elseif (z <= 2.5e+150) tmp = t_0; elseif (z <= 3.9e+214) tmp = y * z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -0.00082], t$95$0, If[LessEqual[z, 8.5e-9], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.5e+150], t$95$0, If[LessEqual[z, 3.9e+214], N[(y * z), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -0.00082:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 8.5 \cdot 10^{-9}:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+150}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.9 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* x z) (if (<= z 1500000.0) (+ x y) (if (<= z 1.4e+214) (* y z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.0) {
tmp = x * z;
} else if (z <= 1500000.0) {
tmp = x + y;
} else if (z <= 1.4e+214) {
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 <= 1500000.0d0) then
tmp = x + y
else if (z <= 1.4d+214) 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 <= 1500000.0) {
tmp = x + y;
} else if (z <= 1.4e+214) {
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 <= 1500000.0: tmp = x + y elif z <= 1.4e+214: 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 <= 1500000.0) tmp = Float64(x + y); elseif (z <= 1.4e+214) 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 <= 1500000.0) tmp = x + y; elseif (z <= 1.4e+214) 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, 1500000.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 1.4e+214], 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 1500000:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{+214}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
(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}
(FPCore (x y z) :precision binary64 (if (<= x -4.5e-145) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.5e-145) {
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 <= (-4.5d-145)) 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 <= -4.5e-145) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.5e-145: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.5e-145) 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 <= -4.5e-145) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.5e-145], 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.5 \cdot 10^{-145}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\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}
(FPCore (x y z) :precision binary64 (if (<= y 2.5e-12) x y))
double code(double x, double y, double z) {
double tmp;
if (y <= 2.5e-12) {
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 <= 2.5d-12) 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 <= 2.5e-12) {
tmp = x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= 2.5e-12: tmp = x else: tmp = y return tmp
function code(x, y, z) tmp = 0.0 if (y <= 2.5e-12) tmp = x; else tmp = y; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2.5e-12) tmp = x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, 2.5e-12], x, y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.5 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
(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}
herbie shell --seed 2023343
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))