
(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
(let* ((t_0 (* y (+ z 1.0))))
(if (<= z -6.1e-9)
t_0
(if (<= z 27.0)
(+ x y)
(if (<= z 2.5e+142)
t_0
(if (<= z 3.5e+197)
(* x z)
(if (<= z 9e+234) (* y z) (if (<= z 1.8e+264) (* x z) t_0))))))))
double code(double x, double y, double z) {
double t_0 = y * (z + 1.0);
double tmp;
if (z <= -6.1e-9) {
tmp = t_0;
} else if (z <= 27.0) {
tmp = x + y;
} else if (z <= 2.5e+142) {
tmp = t_0;
} else if (z <= 3.5e+197) {
tmp = x * z;
} else if (z <= 9e+234) {
tmp = y * z;
} else if (z <= 1.8e+264) {
tmp = x * z;
} else {
tmp = t_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) :: t_0
real(8) :: tmp
t_0 = y * (z + 1.0d0)
if (z <= (-6.1d-9)) then
tmp = t_0
else if (z <= 27.0d0) then
tmp = x + y
else if (z <= 2.5d+142) then
tmp = t_0
else if (z <= 3.5d+197) then
tmp = x * z
else if (z <= 9d+234) then
tmp = y * z
else if (z <= 1.8d+264) then
tmp = x * z
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y * (z + 1.0);
double tmp;
if (z <= -6.1e-9) {
tmp = t_0;
} else if (z <= 27.0) {
tmp = x + y;
} else if (z <= 2.5e+142) {
tmp = t_0;
} else if (z <= 3.5e+197) {
tmp = x * z;
} else if (z <= 9e+234) {
tmp = y * z;
} else if (z <= 1.8e+264) {
tmp = x * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = y * (z + 1.0) tmp = 0 if z <= -6.1e-9: tmp = t_0 elif z <= 27.0: tmp = x + y elif z <= 2.5e+142: tmp = t_0 elif z <= 3.5e+197: tmp = x * z elif z <= 9e+234: tmp = y * z elif z <= 1.8e+264: tmp = x * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(y * Float64(z + 1.0)) tmp = 0.0 if (z <= -6.1e-9) tmp = t_0; elseif (z <= 27.0) tmp = Float64(x + y); elseif (z <= 2.5e+142) tmp = t_0; elseif (z <= 3.5e+197) tmp = Float64(x * z); elseif (z <= 9e+234) tmp = Float64(y * z); elseif (z <= 1.8e+264) tmp = Float64(x * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y * (z + 1.0); tmp = 0.0; if (z <= -6.1e-9) tmp = t_0; elseif (z <= 27.0) tmp = x + y; elseif (z <= 2.5e+142) tmp = t_0; elseif (z <= 3.5e+197) tmp = x * z; elseif (z <= 9e+234) tmp = y * z; elseif (z <= 1.8e+264) tmp = x * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y * N[(z + 1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.1e-9], t$95$0, If[LessEqual[z, 27.0], N[(x + y), $MachinePrecision], If[LessEqual[z, 2.5e+142], t$95$0, If[LessEqual[z, 3.5e+197], N[(x * z), $MachinePrecision], If[LessEqual[z, 9e+234], N[(y * z), $MachinePrecision], If[LessEqual[z, 1.8e+264], N[(x * z), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := y \cdot \left(z + 1\right)\\
\mathbf{if}\;z \leq -6.1 \cdot 10^{-9}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 27:\\
\;\;\;\;x + y\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{+142}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{+197}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq 9 \cdot 10^{+234}:\\
\;\;\;\;y \cdot z\\
\mathbf{elif}\;z \leq 1.8 \cdot 10^{+264}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -6.1e-9 or 27 < z < 2.5000000000000001e142 or 1.80000000000000006e264 < z Initial program 100.0%
Taylor expanded in x around 0 45.3%
if -6.1e-9 < z < 27Initial program 100.0%
Taylor expanded in z around 0 98.3%
if 2.5000000000000001e142 < z < 3.49999999999999999e197 or 8.99999999999999963e234 < z < 1.80000000000000006e264Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around 0 39.4%
if 3.49999999999999999e197 < z < 8.99999999999999963e234Initial program 100.0%
Taylor expanded in z around inf 100.0%
Taylor expanded in y around inf 51.4%
Final simplification71.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 96.9%
if -1 < z < 1Initial program 100.0%
Taylor expanded in z around 0 99.0%
Final simplification97.9%
(FPCore (x y z) :precision binary64 (if (<= z -1.0) (* y z) (if (<= z 45.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 <= 45.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 <= 45.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 <= 45.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 <= 45.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 <= 45.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 <= 45.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, 45.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 45:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < -1 or 45 < z Initial program 100.0%
Taylor expanded in z around inf 97.4%
Taylor expanded in y around inf 47.3%
if -1 < z < 45Initial program 100.0%
Taylor expanded in z around 0 98.3%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.15e-71) (* x (+ z 1.0)) (* y (+ z 1.0))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.15e-71) {
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 <= (-1.15d-71)) 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 <= -1.15e-71) {
tmp = x * (z + 1.0);
} else {
tmp = y * (z + 1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.15e-71: tmp = x * (z + 1.0) else: tmp = y * (z + 1.0) return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.15e-71) 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 <= -1.15e-71) tmp = x * (z + 1.0); else tmp = y * (z + 1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.15e-71], 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 -1.15 \cdot 10^{-71}:\\
\;\;\;\;x \cdot \left(z + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(z + 1\right)\\
\end{array}
\end{array}
if x < -1.1499999999999999e-71Initial program 100.0%
Taylor expanded in x around inf 65.2%
if -1.1499999999999999e-71 < x Initial program 100.0%
Taylor expanded in x around 0 57.8%
Final simplification60.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.06e-57) (* x z) (* y z)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.06e-57) {
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 (x <= (-1.06d-57)) 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 (x <= -1.06e-57) {
tmp = x * z;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.06e-57: tmp = x * z else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.06e-57) tmp = Float64(x * z); else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.06e-57) tmp = x * z; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.06e-57], N[(x * z), $MachinePrecision], N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.06 \cdot 10^{-57}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if x < -1.0600000000000001e-57Initial program 100.0%
Taylor expanded in z around inf 52.1%
Taylor expanded in y around 0 40.2%
if -1.0600000000000001e-57 < x Initial program 100.0%
Taylor expanded in z around inf 50.0%
Taylor expanded in y around inf 29.4%
Final simplification32.6%
(FPCore (x y z) :precision binary64 (* y z))
double code(double x, double y, double z) {
return y * z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = y * z
end function
public static double code(double x, double y, double z) {
return y * z;
}
def code(x, y, z): return y * z
function code(x, y, z) return Float64(y * z) end
function tmp = code(x, y, z) tmp = y * z; end
code[x_, y_, z_] := N[(y * z), $MachinePrecision]
\begin{array}{l}
\\
y \cdot z
\end{array}
Initial program 100.0%
Taylor expanded in z around inf 50.6%
Taylor expanded in y around inf 25.4%
Final simplification25.4%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, G"
:precision binary64
(* (+ x y) (+ z 1.0)))