Module Set

Manipulates key->value Sets.

All functions in this module also work on PseudoSets. For further info read Wikipadia on Sets and List of logic symbols. In unions and intersections of PseudoSets the values of Set B take precedence.

Note: This module inherits all Table module methods.

Module Status: Stable.

Usage:

    local Set = require('__eradicators-library__/erlib/lua/Set')()
    

Module

Set(set) Attaches this Set module as metatable to a table.

Conversion

of_values(tbl) Creates a set that maps all values from the input table to true.
of_keys(tbl) Creates a set that maps all keys from the input table to true.

Metamethods

__add() Addition with + is Set.union().
__sub() Substraction with - is Set.complement().

Creation

union(A, B, keep_meta) →∀x (Ax ∨ Bx)
intersection(A, B, keep_meta) →∀x (Ax ∧ Bx)
complement(A, B, keep_meta) →∀x (Ax ∧ ¬Bx)
difference(A, B, keep_meta) →∀x (¬(Ax ∧ Bx))

Comparison

contains(A, e) →∃e (Ae)
is_superset(A, B) A⊃B, ∀xBx (Ax) ∧ ∃xAx (¬Bx)
is_subset(A, B) A⊂B, ∀xAx (Bx) ∧ ∃xBx (¬Ax)
is_equal(A, B) A⇔B, ∀xAx (Bx) ∧ ∀xBx (Ax)
is_disjoint(A, B) A∩B==∅, ¬∃xAx (Bx) ∧ ¬∃xBx (Ax), ∀xAx (¬Bx) ∧ ∀xBx (¬Ax).


Module

Set(set)
Attaches this Set module as metatable to a table.
Alias for setmetatable(set, {__index = Set}).

Parameters:

Returns:

    PseudoSet The unchanged input table, now with metatable attached.

Conversion

of_values(tbl)
Creates a set that maps all values from the input table to true.

Parameters:

Returns:

    set
of_keys(tbl)
Creates a set that maps all keys from the input table to true.

Parameters:

Returns:

    set

Metamethods

__add()
Addition with + is Set.union().
__sub()
Substraction with - is Set.complement().

Creation

For all of these functions: If the input set A had the module metatable attached by calling Set(A) then the resulting set will automatically inherit the metatable. This behavior can be disabled by passing false as a third parameter. Any metatable not created by Set() will never be inherited.
union(A, B, keep_meta)
→∀x (Ax ∨ Bx)

Parameters:

  • A
  • B
  • keep_meta

Returns:

    set
intersection(A, B, keep_meta)
→∀x (Ax ∧ Bx)

Parameters:

  • A
  • B
  • keep_meta

Returns:

    set
complement(A, B, keep_meta)
→∀x (Ax ∧ ¬Bx)

Parameters:

  • A
  • B
  • keep_meta

Returns:

    set
difference(A, B, keep_meta)
→∀x (¬(Ax ∧ Bx))

Parameters:

  • A
  • B
  • keep_meta

Returns:

    set

Comparison

contains(A, e)
→∃e (Ae)

Parameters:

  • A
  • e

Returns:

    boolean
is_superset(A, B)
A⊃B, ∀xBx (Ax) ∧ ∃xAx (¬Bx)

Parameters:

  • A
  • B

Returns:

    boolean
is_subset(A, B)
A⊂B, ∀xAx (Bx) ∧ ∃xBx (¬Ax)

Parameters:

  • A
  • B

Returns:

    boolean
is_equal(A, B)
A⇔B, ∀xAx (Bx) ∧ ∀xBx (Ax)

Parameters:

  • A
  • B

Returns:

    boolean
is_disjoint(A, B)
A∩B==∅, ¬∃xAx (Bx) ∧ ¬∃xBx (Ax), ∀xAx (¬Bx) ∧ ∀xBx (¬Ax).
The empty set is disjoint from every set, including from itself.

Parameters:

  • A
  • B

Returns:

    boolean
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19