X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/b94e701ff210085f73dbcd6f85f41914f4d696f4..2bb4741bb4c5a97ebadf1eceafe0d5e2dae1fd29:/helpers.lua diff --git a/helpers.lua b/helpers.lua index ab87f76..ce65576 100644 --- a/helpers.lua +++ b/helpers.lua @@ -170,6 +170,29 @@ function helpers.spairs(t) end end +-- create trivial partition of a set. The trivial partition set is the simplest +-- partition of a set. For e.g., the trivial partition set of {a, b, c}, is +-- simply {{a}, {b}, {c}}. +function helpers.trivial_partition_set(set) + local ss = {} + for _,e in pairs(set) do + ss[#ss+1] = {e} + end + return ss +end + +-- creates the powerset of a given set +function helpers.powerset(s) + if not s then return {} end + local t = {{}} + for i = 1, #s do + for j = 1, #t do + t[#t+1] = {s[i],unpack(t[j])} + end + end + return t +end + -- }}} return helpers