PiMath API
    Preparing search index...

    Class LogicalSet

    Represents a logical set expression (e.g. A & B | !C), stored internally as a Reverse Polish Notation sequence. Supports LaTeX and AsciiMath rendering, boolean evaluation, and Venn diagram zone computation.

    Operator precedence (set by the piexpression parser, not by this class): ! binds first, then & and | at the same level, applied from left to right, then - (set difference, also left to right). So A|B&C is (A|B)&C, not A|(B&C), and A-B&C is A-(B&C). Use parentheses to write any other grouping.

    Implements

    Index
    • get variables(): string[]

      The names of the sets used in the expression, without duplicates, in order of appearance.

      Returns string[]

    • Copy the mathematical state of another instance into this (display state is NOT transferred — the receiver keeps its own formatting). Entry point used when constructing/parsing from a same-type input. Distinct from clone. Classes without a real implementation throw NotImplementedError.

      Parameters

      Returns this

    • Evaluates the expression as a predicate: given boolean membership values for each variable, returns whether the set expression holds. Missing keys default to false (not a member). The values argument is not mutated. The - operator (set difference) is supported: A - B is true iff the element is in A and not in B. Malformed RPN (underflowed stack) returns false rather than throwing.

      Parameters

      • values: Record<string, boolean>

      Returns boolean

    • Replace the expression with a string.

      Parameters

      • value: string

      Returns this

      if the expression is malformed.

    • Returns the Venn diagram zones for n sets that satisfy the expression. Each variable must be a single character; zone names are sorted concatenations of those characters (e.g. 'AB' = A∩B only). The exterior zone is labelled by withUniverse() (default 'E'). Variables in the expression but absent from variables are treated as ∅.

      Parameters

      • ...variables: string[]

      Returns string[]

      if no variables are provided or any is not a single character.

    • Shortcut for venn('A', 'B'). Zone names: 'A', 'B', 'AB', plus the exterior label (default 'E', configurable via withUniverse()).

      Returns string[]

    • Shortcut for venn('A', 'B', 'C'). Zone names: 'A', 'B', 'C', 'AB', 'AC', 'BC', 'ABC', plus the exterior label (default 'E', configurable via withUniverse()).

      Returns string[]

    • Sets the label used for the exterior (universal complement) zone in Venn output. Default: 'E'.

      Parameters

      • name: string

      Returns this

    • Build a set expression from a string such as "A&B|!C" (& intersection, | union, ! complement, - difference).

      Parameters

      • value: string

      Returns LogicalSet

      if the expression is malformed.