Пример #1
0
def bddvar(name, index=None):
    r"""Return a unique BDD variable.

    A Boolean *variable* is an abstract numerical quantity that may assume any
    value in the set :math:`B = \{0, 1\}`.
    The ``bddvar`` function returns a unique Boolean variable instance
    represented by a binary decision diagram.
    Variable instances may be used to symbolically construct larger BDDs.

    A variable is defined by one or more *names*,
    and zero or more *indices*.
    Multiple names establish hierarchical namespaces,
    and multiple indices group several related variables.
    If the ``name`` parameter is a single ``str``,
    it will be converted to ``(name, )``.
    The ``index`` parameter is optional;
    when empty, it will be converted to an empty tuple ``()``.
    If the ``index`` parameter is a single ``int``,
    it will be converted to ``(index, )``.

    Given identical names and indices, the ``bddvar`` function will always
    return the same variable:

    >>> bddvar('a', 0) is bddvar('a', 0)
    True

    To create several single-letter variables:

    >>> a, b, c, d = map(bddvar, 'abcd')

    To create variables with multiple names (inner-most first):

    >>> fifo_push = bddvar(('push', 'fifo'))
    >>> fifo_pop = bddvar(('pop', 'fifo'))

    .. seealso::
       For creating arrays of variables with incremental indices,
       use the :func:`pyeda.boolalg.bfarray.bddvars` function.
    """
    bvar = boolfunc.var(name, index)
    try:
        var = _VARS[bvar.uniqid]
    except KeyError:
        var = _VARS[bvar.uniqid] = BDDVariable(bvar)
        _BDDS[var.node] = var
    return var
Пример #2
0
def ttvar(name, index=None):
    """Return a TruthTable variable.

    Parameters
    ----------
    name : str
        The variable's identifier string.
    index : int or tuple[int], optional
        One or more integer suffixes for variables that are part of a
        multi-dimensional bit-vector, eg x[1], x[1][2][3]
    """
    bvar = boolfunc.var(name, index)
    try:
        var = _TTVARIABLES[bvar.uniqid]
    except KeyError:
        var = _TTVARIABLES[bvar.uniqid] = TTVariable(bvar)
    return var
Пример #3
0
def bddvar(name, index=None):
    r"""Return a unique BDD variable.

    A Boolean *variable* is an abstract numerical quantity that may assume any
    value in the set :math:`B = \{0, 1\}`.
    The ``bddvar`` function returns a unique Boolean variable instance
    represented by a binary decision diagram.
    Variable instances may be used to symbolically construct larger BDDs.

    A variable is defined by one or more *names*,
    and zero or more *indices*.
    Multiple names establish hierarchical namespaces,
    and multiple indices group several related variables.
    If the ``name`` parameter is a single ``str``,
    it will be converted to ``(name, )``.
    The ``index`` parameter is optional;
    when empty, it will be converted to an empty tuple ``()``.
    If the ``index`` parameter is a single ``int``,
    it will be converted to ``(index, )``.

    Given identical names and indices, the ``bddvar`` function will always
    return the same variable:

    >>> bddvar('a', 0) is bddvar('a', 0)
    True

    To create several single-letter variables:

    >>> a, b, c, d = map(bddvar, 'abcd')

    To create variables with multiple names (inner-most first):

    >>> fifo_push = bddvar(('push', 'fifo'))
    >>> fifo_pop = bddvar(('pop', 'fifo'))

    .. seealso::
       For creating arrays of variables with incremental indices,
       use the :func:`pyeda.boolalg.bfarray.bddvars` function.
    """
    bvar = boolfunc.var(name, index)
    try:
        var = _VARS[bvar.uniqid]
    except KeyError:
        var = _VARS[bvar.uniqid] = BDDVariable(bvar)
        _BDDS[var.node] = var
    return var